ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-7.3/modules/m_tburst.c
Revision: 1121
Committed: Sun Jan 9 11:03:03 2011 UTC (15 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 7306 byte(s)
Log Message:
- removed all instances of STATIC_MODULES since we don't have
  static modules anymore
- removed m_mkpasswd module from contrib

File Contents

# Content
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 "handlers.h"
33 #include "client.h"
34 #include "common.h"
35 #include "ircd.h"
36 #include "send.h"
37 #include "msg.h"
38 #include "modules.h"
39 #include "hash.h"
40 #include "s_serv.h"
41 #include "s_conf.h"
42
43 static void ms_tb(struct Client *, struct Client *, int, char *[]);
44 static void ms_tburst(struct Client *, struct Client *, int, char *[]);
45 static void set_topic(struct Client *, struct Channel *, time_t,
46 const char *, const char *);
47
48 struct Message tburst_msgtab = {
49 "TBURST", 0, 0, 5, 0, MFLG_SLOW, 0,
50 { m_ignore, m_ignore, ms_tburst, m_ignore, m_ignore, m_ignore }
51 };
52
53 struct Message tb_msgtab = {
54 "TB", 0, 0, 4, 0, MFLG_SLOW, 0,
55 { m_ignore, m_ignore, ms_tb, m_ignore, m_ignore, m_ignore }
56 };
57
58 void
59 _modinit(void)
60 {
61 mod_add_cmd(&tb_msgtab);
62 add_capability("TB", CAP_TB, 1);
63
64 mod_add_cmd(&tburst_msgtab);
65 add_capability("TBURST", CAP_TBURST, 1);
66 }
67
68 void
69 _moddeinit(void)
70 {
71 mod_del_cmd(&tb_msgtab);
72 delete_capability("TB");
73
74 mod_del_cmd(&tburst_msgtab);
75 delete_capability("TBURST");
76 }
77
78 const char *_version = "$Revision$";
79
80 /* ms_tburst()
81 *
82 * parv[0] = sender prefix
83 * parv[1] = channel timestamp
84 * parv[2] = channel
85 * parv[3] = topic timestamp
86 * parv[4] = topic setter
87 * parv[5] = topic
88 */
89 static void
90 ms_tburst(struct Client *client_p, struct Client *source_p,
91 int parc, char *parv[])
92 {
93 struct Channel *chptr = NULL;
94 int accept_remote = 0;
95 time_t remote_channel_ts = atol(parv[1]);
96 time_t remote_topic_ts = atol(parv[3]);
97 const char *topic = "";
98 const char *setby = "";
99
100 /*
101 * Do NOT test parv[5] for an empty string and return if true!
102 * parv[5] CAN be an empty string, i.e. if the other side wants
103 * to unset our topic. Don't forget: an empty topic is also a
104 * valid topic.
105 */
106
107
108 if ((chptr = hash_find_channel(parv[2])) == NULL)
109 return;
110
111 if (parc == 6)
112 {
113 topic = parv[5];
114 setby = parv[4];
115 }
116
117 /*
118 * The logic for accepting and rejecting channel topics was
119 * always a bit hairy, so now we got exactly 2 cases where
120 * we would accept a bursted topic
121 *
122 * Case 1:
123 * The TS of the remote channel is older than ours
124 * Case 2:
125 * The TS of the remote channel is equal to ours AND
126 * the TS of the remote topic is newer than ours
127 */
128 if (remote_channel_ts < chptr->channelts)
129 accept_remote = 1;
130 else if (remote_channel_ts == chptr->channelts)
131 if (remote_topic_ts > chptr->topic_time)
132 accept_remote = 1;
133
134 if (accept_remote)
135 {
136 int topic_differs = strcmp(chptr->topic ? chptr->topic : "", topic);
137
138 set_channel_topic(chptr, topic, setby, remote_topic_ts);
139
140 if (topic_differs)
141 sendto_channel_local(ALL_MEMBERS, NO, chptr, ":%s TOPIC %s :%s",
142 ConfigServerHide.hide_servers ? me.name : source_p->name,
143 chptr->chname, chptr->topic == NULL ? "" : chptr->topic);
144 }
145
146 /*
147 * Always propagate what we have received, not only if we accept the topic.
148 * This will keep other servers in sync.
149 */
150 sendto_server(source_p, chptr, CAP_TBURST, NOCAPS,
151 ":%s TBURST %s %s %s %s :%s",
152 source_p->name, parv[1], parv[2], parv[3], setby, topic);
153 if (parc > 5 && *topic != '\0') /* unsetting a topic is not supported by TB */
154 sendto_server(source_p, chptr, CAP_TB, CAP_TBURST,
155 ":%s TB %s %s %s :%s",
156 source_p->name, parv[1], parv[2], setby, topic);
157 }
158
159 /* ms_tb()
160 *
161 * parv[0] = sender prefix
162 * parv[1] = channel name
163 * parv[2] = topic timestamp
164 * parv[3] = topic setter OR topic itself if parc == 4
165 * parv[4] = topic itself if parc == 5
166 */
167 #define tb_channel parv[1]
168 #define tb_topicts_str parv[2]
169
170 static void
171 ms_tb(struct Client *client_p, struct Client *source_p, int parc, char *parv[])
172 {
173 struct Channel *chptr;
174 time_t tb_topicts = atol(tb_topicts_str);
175 char *tb_whoset = NULL;
176 char *tb_topic = NULL;
177
178 if ((chptr = hash_find_channel(tb_channel)) == NULL)
179 return;
180
181 if (parc == 5)
182 {
183 tb_whoset = parv[3];
184 tb_topic = parv[4];
185 }
186 else
187 {
188 tb_whoset = source_p->name;
189 tb_topic = parv[3];
190 }
191
192 set_topic(source_p, chptr, tb_topicts, tb_whoset, tb_topic);
193 }
194
195 /*
196 * set_topic
197 *
198 * inputs - source_p pointer
199 * - channel pointer
200 * - topicts to set
201 * - who to set as who doing the topic
202 * - topic
203 * output - none
204 * Side effects - simply propagates topic as needed
205 * little helper function, could be removed
206 */
207 static void
208 set_topic(struct Client *source_p, struct Channel *chptr, time_t topicts,
209 const char *topicwho, const char *topic)
210 {
211 int new_topic = strcmp(chptr->topic ? chptr->topic : "", topic);
212
213 set_channel_topic(chptr, topic, topicwho, topicts);
214
215 /* Only send TOPIC to channel if it's different */
216 if (new_topic)
217 sendto_channel_local(ALL_MEMBERS, NO, chptr, ":%s TOPIC %s :%s",
218 ConfigServerHide.hide_servers ? me.name : source_p->name,
219 chptr->chname, chptr->topic == NULL ? "" : chptr->topic);
220
221 sendto_server(source_p, chptr, CAP_TBURST, NOCAPS,
222 ":%s TBURST %lu %s %lu %s :%s",
223 me.name, (unsigned long)chptr->channelts, chptr->chname,
224 (unsigned long)chptr->topic_time,
225 chptr->topic_info == NULL ? "" : chptr->topic_info,
226 chptr->topic == NULL ? "" : chptr->topic);
227 sendto_server(source_p, chptr, CAP_TB, CAP_TBURST,
228 ":%s TB %s %lu %s :%s",
229 me.name, chptr->chname,
230 (unsigned long)chptr->topic_time,
231 chptr->topic_info == NULL ? "" : chptr->topic_info,
232 chptr->topic == NULL ? "" : chptr->topic);
233 }

Properties

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