1 |
/* |
2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
* |
4 |
* Copyright (c) 1997-2014 ircd-hybrid development team |
5 |
* |
6 |
* 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 |
* |
11 |
* 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 |
* |
16 |
* 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 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
19 |
* USA |
20 |
*/ |
21 |
|
22 |
/*! \file m_topic.c |
23 |
* \brief Includes required functions for processing the TOPIC command. |
24 |
* \version $Id$ |
25 |
*/ |
26 |
|
27 |
#include "stdinc.h" |
28 |
#include "list.h" |
29 |
#include "channel.h" |
30 |
#include "channel_mode.h" |
31 |
#include "client.h" |
32 |
#include "hash.h" |
33 |
#include "irc_string.h" |
34 |
#include "ircd.h" |
35 |
#include "numeric.h" |
36 |
#include "send.h" |
37 |
#include "parse.h" |
38 |
#include "modules.h" |
39 |
#include "packet.h" |
40 |
|
41 |
|
42 |
/*! \brief TOPIC command handler |
43 |
* |
44 |
* \param source_p Pointer to allocated Client struct from which the message |
45 |
* originally comes from. This can be a local or remote client. |
46 |
* \param parc Integer holding the number of supplied arguments. |
47 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
48 |
* pointers. |
49 |
* \note Valid arguments for this command are: |
50 |
* - parv[0] = command |
51 |
* - parv[1] = channel name |
52 |
* - parv[2] = topic text, if setting topic |
53 |
*/ |
54 |
static int |
55 |
m_topic(struct Client *source_p, int parc, char *parv[]) |
56 |
{ |
57 |
struct Channel *chptr = NULL; |
58 |
|
59 |
if (EmptyString(parv[1])) |
60 |
{ |
61 |
sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "TOPIC"); |
62 |
return 0; |
63 |
} |
64 |
|
65 |
if (!IsFloodDone(source_p)) |
66 |
flood_endgrace(source_p); |
67 |
|
68 |
if ((chptr = hash_find_channel(parv[1])) == NULL) |
69 |
{ |
70 |
sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, parv[1]); |
71 |
return 0; |
72 |
} |
73 |
|
74 |
/* setting topic */ |
75 |
if (parc > 2) |
76 |
{ |
77 |
const struct Membership *member = NULL; |
78 |
|
79 |
if ((member = find_channel_link(source_p, chptr)) == NULL) |
80 |
{ |
81 |
sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, chptr->name); |
82 |
return 0; |
83 |
} |
84 |
|
85 |
if (!(chptr->mode.mode & MODE_TOPICLIMIT) || |
86 |
has_member_flags(member, CHFL_CHANOP|CHFL_HALFOP)) |
87 |
{ |
88 |
char topic_info[USERHOST_REPLYLEN]; |
89 |
|
90 |
snprintf(topic_info, sizeof(topic_info), "%s!%s@%s", source_p->name, |
91 |
source_p->username, source_p->host); |
92 |
channel_set_topic(chptr, parv[2], topic_info, CurrentTime, 1); |
93 |
|
94 |
sendto_server(source_p, 0, 0, ":%s TOPIC %s :%s", |
95 |
source_p->id, chptr->name, |
96 |
chptr->topic); |
97 |
sendto_channel_local(0, chptr, ":%s!%s@%s TOPIC %s :%s", |
98 |
source_p->name, |
99 |
source_p->username, |
100 |
source_p->host, |
101 |
chptr->name, chptr->topic); |
102 |
} |
103 |
else |
104 |
sendto_one_numeric(source_p, &me, ERR_CHANOPRIVSNEEDED, chptr->name); |
105 |
} |
106 |
else /* only asking for topic */ |
107 |
{ |
108 |
if (!SecretChannel(chptr) || IsMember(source_p, chptr)) |
109 |
{ |
110 |
if (chptr->topic[0] == '\0') |
111 |
sendto_one_numeric(source_p, &me, RPL_NOTOPIC, chptr->name); |
112 |
else |
113 |
{ |
114 |
sendto_one_numeric(source_p, &me, RPL_TOPIC, |
115 |
chptr->name, chptr->topic); |
116 |
sendto_one_numeric(source_p, &me, RPL_TOPICWHOTIME, chptr->name, |
117 |
chptr->topic_info, |
118 |
chptr->topic_time); |
119 |
} |
120 |
} |
121 |
else |
122 |
sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, chptr->name); |
123 |
} |
124 |
|
125 |
return 0; |
126 |
} |
127 |
|
128 |
|
129 |
/*! \brief TOPIC command handler |
130 |
* |
131 |
* \param source_p Pointer to allocated Client struct from which the message |
132 |
* originally comes from. This can be a local or remote client. |
133 |
* \param parc Integer holding the number of supplied arguments. |
134 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
135 |
* pointers. |
136 |
* \note Valid arguments for this command are: |
137 |
* - parv[0] = command |
138 |
* - parv[1] = channel name |
139 |
* - parv[2] = topic text |
140 |
*/ |
141 |
static int |
142 |
ms_topic(struct Client *source_p, int parc, char *parv[]) |
143 |
{ |
144 |
struct Channel *chptr = NULL; |
145 |
char topic_info[USERHOST_REPLYLEN]; |
146 |
|
147 |
if (EmptyString(parv[1])) |
148 |
{ |
149 |
sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "TOPIC"); |
150 |
return 0; |
151 |
} |
152 |
|
153 |
if ((chptr = hash_find_channel(parv[1])) == NULL) |
154 |
{ |
155 |
sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, parv[1]); |
156 |
return 0; |
157 |
} |
158 |
|
159 |
if (!IsClient(source_p)) |
160 |
strlcpy(topic_info, source_p->name, sizeof(topic_info)); |
161 |
else |
162 |
snprintf(topic_info, sizeof(topic_info), "%s!%s@%s", source_p->name, |
163 |
source_p->username, source_p->host); |
164 |
channel_set_topic(chptr, parv[2], topic_info, CurrentTime, 0); |
165 |
|
166 |
sendto_server(source_p, 0, 0, ":%s TOPIC %s :%s", |
167 |
source_p->id, chptr->name, |
168 |
chptr->topic); |
169 |
|
170 |
if (!IsClient(source_p)) |
171 |
sendto_channel_local(0, chptr, ":%s TOPIC %s :%s", |
172 |
source_p->name, |
173 |
chptr->name, chptr->topic); |
174 |
|
175 |
else |
176 |
sendto_channel_local(0, chptr, ":%s!%s@%s TOPIC %s :%s", |
177 |
source_p->name, |
178 |
source_p->username, |
179 |
source_p->host, |
180 |
chptr->name, chptr->topic); |
181 |
return 0; |
182 |
} |
183 |
|
184 |
|
185 |
static struct Message topic_msgtab = |
186 |
{ |
187 |
"TOPIC", NULL, 0, 0, 2, MAXPARA, MFLG_SLOW, 0, |
188 |
{ m_unregistered, m_topic, ms_topic, m_ignore, m_topic, m_ignore } |
189 |
}; |
190 |
|
191 |
static void |
192 |
module_init(void) |
193 |
{ |
194 |
mod_add_cmd(&topic_msgtab); |
195 |
} |
196 |
|
197 |
static void |
198 |
module_exit(void) |
199 |
{ |
200 |
mod_del_cmd(&topic_msgtab); |
201 |
} |
202 |
|
203 |
struct module module_entry = |
204 |
{ |
205 |
.node = { NULL, NULL, NULL }, |
206 |
.name = NULL, |
207 |
.version = "$Revision$", |
208 |
.handle = NULL, |
209 |
.modinit = module_init, |
210 |
.modexit = module_exit, |
211 |
.flags = 0 |
212 |
}; |