ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/modules/m_tburst.c
Revision: 325
Committed: Sun Dec 25 09:26:45 2005 UTC (18 years, 3 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-7.2/modules/m_tburst.c
File size: 5829 byte(s)
Log Message:
- Imported m_tburst.c from 7.3

File Contents

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

Properties

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