/[svn]/ircd-hybrid-8/modules/m_tburst.c
ViewVC logotype

Contents of /ircd-hybrid-8/modules/m_tburst.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1243 - (show annotations)
Fri Sep 30 10:47:53 2011 UTC (8 years, 9 months ago) by michael
File MIME type: text/x-chdr
File size: 7057 byte(s)
- move content of msg.h, ircd_handler.h and handlers.h into parse.h and
  remove headers accordingly
- killed common.h
- remove m_killhost.c and m_flags.c from contrib/
- sort out unused header includes here and there

1 /* modules/m_tburst.c
2 * Copyright (C) 2002, 2003, 2004, 2005 Hybrid Development Team
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * 1.Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2.Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3.The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 *
28 * $Id$
29 */
30
31 #include "stdinc.h"
32 #include "client.h"
33 #include "ircd.h"
34 #include "send.h"
35 #include "modules.h"
36 #include "hash.h"
37 #include "s_serv.h"
38 #include "s_conf.h"
39 #include "parse.h"
40
41
42 /*
43 * set_topic
44 *
45 * inputs - source_p pointer
46 * - channel pointer
47 * - topicts to set
48 * - who to set as who doing the topic
49 * - topic
50 * output - none
51 * Side effects - simply propagates topic as needed
52 * little helper function, could be removed
53 */
54 static void
55 set_topic(struct Client *source_p, struct Channel *chptr, time_t topicts,
56 const char *topicwho, const char *topic)
57 {
58 int new_topic = strcmp(chptr->topic, topic);
59
60 set_channel_topic(chptr, topic, topicwho, topicts);
61
62 /* Only send TOPIC to channel if it's different */
63 if (new_topic)
64 sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s TOPIC %s :%s",
65 ConfigServerHide.hide_servers ? me.name : source_p->name,
66 chptr->chname, chptr->topic);
67
68 sendto_server(source_p, chptr, CAP_TBURST, NOCAPS,
69 ":%s TBURST %lu %s %lu %s :%s",
70 me.name, (unsigned long)chptr->channelts, chptr->chname,
71 (unsigned long)chptr->topic_time,
72 chptr->topic_info,
73 chptr->topic);
74 sendto_server(source_p, chptr, CAP_TB, CAP_TBURST,
75 ":%s TB %s %lu %s :%s",
76 me.name, chptr->chname,
77 (unsigned long)chptr->topic_time,
78 chptr->topic_info,
79 chptr->topic);
80 }
81
82 /* ms_tburst()
83 *
84 * parv[0] = sender prefix
85 * parv[1] = channel timestamp
86 * parv[2] = channel
87 * parv[3] = topic timestamp
88 * parv[4] = topic setter
89 * parv[5] = topic
90 */
91 static void
92 ms_tburst(struct Client *client_p, struct Client *source_p,
93 int parc, char *parv[])
94 {
95 struct Channel *chptr = NULL;
96 int accept_remote = 0;
97 time_t remote_channel_ts = atol(parv[1]);
98 time_t remote_topic_ts = atol(parv[3]);
99 const char *topic = "";
100 const char *setby = "";
101
102 /*
103 * Do NOT test parv[5] for an empty string and return if true!
104 * parv[5] CAN be an empty string, i.e. if the other side wants
105 * to unset our topic. Don't forget: an empty topic is also a
106 * valid topic.
107 */
108
109
110 if ((chptr = hash_find_channel(parv[2])) == NULL)
111 return;
112
113 if (parc == 6)
114 {
115 topic = parv[5];
116 setby = parv[4];
117 }
118
119 /*
120 * The logic for accepting and rejecting channel topics was
121 * always a bit hairy, so now we got exactly 2 cases where
122 * we would accept a bursted topic
123 *
124 * Case 1:
125 * The TS of the remote channel is older than ours
126 * Case 2:
127 * The TS of the remote channel is equal to ours AND
128 * the TS of the remote topic is newer than ours
129 */
130 if (remote_channel_ts < chptr->channelts)
131 accept_remote = 1;
132 else if (remote_channel_ts == chptr->channelts)
133 if (remote_topic_ts > chptr->topic_time)
134 accept_remote = 1;
135
136 if (accept_remote)
137 {
138 int topic_differs = strcmp(chptr->topic, topic);
139
140 set_channel_topic(chptr, topic, setby, remote_topic_ts);
141
142 if (topic_differs)
143 sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s TOPIC %s :%s",
144 ConfigServerHide.hide_servers ? me.name : source_p->name,
145 chptr->chname, chptr->topic);
146 }
147
148 /*
149 * Always propagate what we have received, not only if we accept the topic.
150 * This will keep other servers in sync.
151 */
152 sendto_server(source_p, chptr, CAP_TBURST, NOCAPS,
153 ":%s TBURST %s %s %s %s :%s",
154 source_p->name, parv[1], parv[2], parv[3], setby, topic);
155 if (parc > 5 && *topic != '\0') /* unsetting a topic is not supported by TB */
156 sendto_server(source_p, chptr, CAP_TB, CAP_TBURST,
157 ":%s TB %s %s %s :%s",
158 source_p->name, parv[1], parv[2], setby, topic);
159 }
160
161 /* ms_tb()
162 *
163 * parv[0] = sender prefix
164 * parv[1] = channel name
165 * parv[2] = topic timestamp
166 * parv[3] = topic setter OR topic itself if parc == 4
167 * parv[4] = topic itself if parc == 5
168 */
169 #define tb_channel parv[1]
170 #define tb_topicts_str parv[2]
171
172 static void
173 ms_tb(struct Client *client_p, struct Client *source_p, int parc, char *parv[])
174 {
175 struct Channel *chptr;
176 time_t tb_topicts = atol(tb_topicts_str);
177 char *tb_whoset = NULL;
178 char *tb_topic = NULL;
179
180 if ((chptr = hash_find_channel(tb_channel)) == NULL)
181 return;
182
183 if (parc == 5)
184 {
185 tb_whoset = parv[3];
186 tb_topic = parv[4];
187 }
188 else
189 {
190 tb_whoset = source_p->name;
191 tb_topic = parv[3];
192 }
193
194 set_topic(source_p, chptr, tb_topicts, tb_whoset, tb_topic);
195 }
196
197 static struct Message tburst_msgtab = {
198 "TBURST", 0, 0, 5, MAXPARA, MFLG_SLOW, 0,
199 { m_ignore, m_ignore, ms_tburst, m_ignore, m_ignore, m_ignore }
200 };
201
202 static struct Message tb_msgtab = {
203 "TB", 0, 0, 4, MAXPARA, MFLG_SLOW, 0,
204 { m_ignore, m_ignore, ms_tb, m_ignore, m_ignore, m_ignore }
205 };
206
207 static void
208 module_init(void)
209 {
210 mod_add_cmd(&tb_msgtab);
211 add_capability("TB", CAP_TB, 1);
212
213 mod_add_cmd(&tburst_msgtab);
214 add_capability("TBURST", CAP_TBURST, 1);
215 }
216
217 static void
218 module_exit(void)
219 {
220 mod_del_cmd(&tb_msgtab);
221 delete_capability("TB");
222
223 mod_del_cmd(&tburst_msgtab);
224 delete_capability("TBURST");
225 }
226
227 struct module module_entry = {
228 .node = { NULL, NULL, NULL },
229 .name = NULL,
230 .version = "$Revision$",
231 .handle = NULL,
232 .modinit = module_init,
233 .modexit = module_exit,
234 .flags = 0
235 };

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28