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

Annotation of /ircd-hybrid-7.2/modules/m_tburst.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 335 - (hide annotations)
Mon Dec 26 10:36:42 2005 UTC (14 years, 1 month ago) by michael
File MIME type: text/x-chdr
File size: 5864 byte(s)
- Backported TBURST fix from HEAD

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

Properties

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

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