ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_tburst.c
Revision: 442
Committed: Sat Feb 11 23:14:21 2006 UTC (20 years, 6 months ago) by adx
Content type: text/x-csrc
File size: 5801 byte(s)
Log Message:
+ massive rewrite of module init/deinit/version headers,
  we are introducing a new module manager which deals with static
  and dynamic modules exactly the same way. (New possibilities
  include loading/unloading statically compiled modules and
  mixing static/dynamic ones in one build.)

File Contents

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

Properties

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