ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_tburst.c
Revision: 741
Committed: Sun Jul 23 13:49:20 2006 UTC (19 years, 1 month ago) by adx
Content type: text/x-csrc
File size: 5826 byte(s)
Log Message:
+ removed s_conf.h and superseded parts of s_conf.c

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: m_tb.c 122 2005-10-13 10:57:26Z adx $
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 "parse.h"
38 #include "msg.h"
39 #include "conf/modules.h"
40 #include "hash.h"
41 #include "s_serv.h"
42 #include "channel.h"
43
44 static void ms_tb(struct Client *, struct Client *, int, char *[]);
45 static void ms_tburst(struct Client *, struct Client *, int, char *[]);
46 static void set_topic(struct Client *, struct Channel *, time_t,
47 const char *, const char *);
48
49 struct Message tburst_msgtab = {
50 "TBURST", 0, 0, 6, 0, MFLG_SLOW, 0,
51 { m_ignore, m_ignore, ms_tburst, m_ignore, m_ignore, m_ignore }
52 };
53
54 struct Message tb_msgtab = {
55 "TB", 0, 0, 0, 0, MFLG_SLOW, 0,
56 { m_ignore, m_ignore, ms_tb, m_ignore, m_ignore, m_ignore }
57 };
58
59 INIT_MODULE(m_tburst, "$Revision: 122 $")
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 CLEANUP_MODULE
69 {
70 delete_capability("TBURST");
71 mod_del_cmd(&tburst_msgtab);
72
73 delete_capability("TB");
74 mod_del_cmd(&tb_msgtab);
75 }
76
77 /* ms_tburst()
78 *
79 * parv[0] = sender prefix
80 * parv[1] = channel timestamp
81 * parv[2] = channel
82 * parv[3] = topic timestamp
83 * parv[4] = topic setter
84 * parv[5] = topic
85 */
86 static void
87 ms_tburst(struct Client *client_p, struct Client *source_p,
88 int parc, char *parv[])
89 {
90 struct Channel *chptr = NULL;
91 time_t oldchannelts = atol(parv[1]);
92 time_t oldtopicts = atol(parv[3]);
93
94 if ((chptr = hash_find_channel(parv[2])) == NULL)
95 return;
96
97 /* Only allow topic change if we are the newer TS and server
98 * sending TBURST has older TS and topicTS on older TS is
99 * newer than current topicTS. -metalrock
100 * XXX - Incorrect logic here as discussed on IRC
101 */
102 if ((oldchannelts <= chptr->channelts) &&
103 ((chptr->topic == NULL) || (oldtopicts > chptr->topic_time)))
104 set_topic(source_p, chptr, oldtopicts, parv[4], parv[5]);
105 }
106
107 /* ms_tb()
108 *
109 * parv[0] = sender prefix
110 * parv[1] = channel name
111 * parv[2] = topic timestamp
112 * parv[3] = topic setter OR topic itself if parc == 4
113 * parv[4] = topic itself if parc == 5
114 */
115 #define tb_channel parv[1]
116 #define tb_topicts_str parv[2]
117
118 static void
119 ms_tb(struct Client *client_p, struct Client *source_p, int parc, char *parv[])
120 {
121 struct Channel *chptr;
122 time_t tb_topicts = atol(tb_topicts_str);
123 char *tb_whoset = NULL;
124 char *tb_topic = NULL;
125
126 if ((chptr = hash_find_channel(tb_channel)) == NULL)
127 return;
128
129 if (parc == 5)
130 {
131 tb_whoset = parv[3];
132 tb_topic = parv[4];
133 }
134 else
135 {
136 tb_whoset = source_p->name;
137 tb_topic = parv[3];
138 }
139
140 set_topic(source_p, chptr, tb_topicts, tb_whoset, tb_topic);
141 }
142
143 /*
144 * set_topic
145 *
146 * inputs - source_p pointer
147 * - channel pointer
148 * - topicts to set
149 * - who to set as who doing the topic
150 * - topic
151 * output - none
152 * Side effects - simply propagates topic as needed
153 * little helper function, could be removed
154 */
155 static void
156 set_topic(struct Client *source_p, struct Channel *chptr, time_t topicts,
157 const char *topicwho, const char *topic)
158 {
159 int new_topic = strcmp(chptr->topic ? chptr->topic : "", topic);
160
161 set_channel_topic(chptr, topic, topicwho, topicts);
162
163 /* Only send TOPIC to channel if it's different */
164 if (new_topic)
165 sendto_channel_local(ALL_MEMBERS, NO, chptr, ":%s TOPIC %s :%s",
166 ConfigServerHide.hide_servers ? me.name : source_p->name,
167 chptr->chname, chptr->topic == NULL ? "" : chptr->topic);
168
169 sendto_server(source_p, NULL, chptr, CAP_TBURST, NOCAPS,
170 ":%s TBURST %lu %s %lu %s :%s",
171 me.name, (unsigned long)chptr->channelts, chptr->chname,
172 (unsigned long)chptr->topic_time,
173 chptr->topic_info == NULL ? "" : chptr->topic_info,
174 chptr->topic == NULL ? "" : chptr->topic);
175 sendto_server(source_p, NULL, chptr, CAP_TB, CAP_TBURST,
176 ":%s TB %s %lu %s :%s",
177 me.name, chptr->chname,
178 (unsigned long)chptr->topic_time,
179 chptr->topic_info == NULL ? "" : chptr->topic_info,
180 chptr->topic == NULL ? "" : chptr->topic);
181 }

Properties

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