ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_tburst.c
Revision: 5536
Committed: Wed Feb 11 20:26:11 2015 UTC (10 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 4515 byte(s)
Log Message:
- m_tburst.c:ms_tburst(): TOPIC needs to be n!u@h prefixed if comming from a services client

File Contents

# User Rev Content
1 michael 2820 /*
2     * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 michael 325 *
4 michael 5347 * Copyright (c) 2002-2015 ircd-hybrid development team
5 michael 325 *
6 michael 2820 * This program is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10 michael 325 *
11 michael 2820 * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15 michael 325 *
16 michael 2820 * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18 michael 4565 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 michael 2820 * USA
20 michael 325 */
21    
22 michael 2820 /*! \file m_tburst.c
23     * \brief Includes required functions for processing the TBURST command.
24     * \version $Id$
25     */
26    
27 michael 325 #include "stdinc.h"
28     #include "client.h"
29     #include "ircd.h"
30     #include "send.h"
31     #include "modules.h"
32     #include "hash.h"
33 michael 3347 #include "server.h"
34 michael 1309 #include "conf.h"
35 michael 1243 #include "parse.h"
36 michael 325
37    
38 michael 3294 /*! \brief TBURST command handler
39 michael 325 *
40 michael 3294 * \param source_p Pointer to allocated Client struct from which the message
41     * originally comes from. This can be a local or remote client.
42     * \param parc Integer holding the number of supplied arguments.
43     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
44     * pointers.
45     * \note Valid arguments for this command are:
46     * - parv[0] = command
47     * - parv[1] = channel timestamp
48     * - parv[2] = channel name
49     * - parv[3] = topic timestamp
50     * - parv[4] = topic setter
51     * - parv[5] = topic
52 michael 325 */
53 michael 2820 static int
54 michael 3156 ms_tburst(struct Client *source_p, int parc, char *parv[])
55 michael 325 {
56     struct Channel *chptr = NULL;
57 michael 336 int accept_remote = 0;
58     time_t remote_channel_ts = atol(parv[1]);
59     time_t remote_topic_ts = atol(parv[3]);
60 michael 1486 const char *topic = parv[5];
61     const char *setby = parv[4];
62 michael 325
63 michael 336 /*
64     * Do NOT test parv[5] for an empty string and return if true!
65     * parv[5] CAN be an empty string, i.e. if the other side wants
66     * to unset our topic. Don't forget: an empty topic is also a
67     * valid topic.
68     */
69    
70    
71 michael 325 if ((chptr = hash_find_channel(parv[2])) == NULL)
72 michael 2820 return 0;
73 michael 325
74 michael 336 /*
75     * The logic for accepting and rejecting channel topics was
76 michael 3342 * always a bit hairy, so now we got exactly 3 cases where
77     * we would accept a topic
78 michael 336 *
79     * Case 1:
80 michael 3342 * A services client/server wants to set a topic
81     * Case 2:
82 michael 336 * The TS of the remote channel is older than ours
83 michael 3342 * Case 3:
84 michael 336 * The TS of the remote channel is equal to ours AND
85     * the TS of the remote topic is newer than ours
86 michael 325 */
87 michael 1485 if (HasFlag(source_p, FLAGS_SERVICE))
88 michael 336 accept_remote = 1;
89 michael 4818 else if (remote_channel_ts < chptr->creationtime)
90 michael 1485 accept_remote = 1;
91 michael 4818 else if (remote_channel_ts == chptr->creationtime)
92 michael 336 if (remote_topic_ts > chptr->topic_time)
93     accept_remote = 1;
94    
95     if (accept_remote)
96     {
97 michael 1487 int topic_differs = strncmp(chptr->topic, topic, sizeof(chptr->topic) - 1);
98 michael 1615 int hidden_server = (ConfigServerHide.hide_servers || IsHidden(source_p));
99 michael 1487
100 michael 3941 channel_set_topic(chptr, topic, setby, remote_topic_ts, 0);
101 michael 336
102 michael 5536 sendto_server(source_p, CAP_TBURST, 0, ":%s TBURST %s %s %s %s :%s",
103 michael 3186 source_p->id, parv[1], parv[2], parv[3], setby, topic);
104 michael 1615
105 michael 1487 if (topic_differs)
106 michael 5536 {
107     if (!IsClient(source_p))
108     sendto_channel_local(0, chptr, ":%s TOPIC %s :%s",
109     hidden_server ? me.name : source_p->name,
110     chptr->name, chptr->topic);
111     else
112     sendto_channel_local(0, chptr, ":%s!%s@%s TOPIC %s :%s",
113     source_p->name, source_p->username, source_p->host,
114     chptr->name, chptr->topic);
115     }
116 michael 336 }
117 michael 2820
118     return 0;
119 michael 325 }
120    
121 michael 2820 static struct Message tburst_msgtab =
122     {
123 michael 4545 "TBURST", NULL, 0, 0, 6, MAXPARA, MFLG_SLOW, 0,
124 michael 1230 { m_ignore, m_ignore, ms_tburst, m_ignore, m_ignore, m_ignore }
125     };
126    
127 michael 325 static void
128 michael 1230 module_init(void)
129 michael 325 {
130 michael 1230 mod_add_cmd(&tburst_msgtab);
131     add_capability("TBURST", CAP_TBURST, 1);
132     }
133 michael 325
134 michael 1230 static void
135     module_exit(void)
136     {
137     mod_del_cmd(&tburst_msgtab);
138     delete_capability("TBURST");
139 michael 325 }
140 michael 1230
141 michael 2820 struct module module_entry =
142     {
143 michael 1230 .node = { NULL, NULL, NULL },
144     .name = NULL,
145     .version = "$Revision$",
146     .handle = NULL,
147     .modinit = module_init,
148     .modexit = module_exit,
149     .flags = 0
150     };

Properties

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