]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* |
2 | * ircd-ratbox: A slightly useful ircd. | |
3 | * m_topic.c: Sets a channel topic. | |
4 | * | |
5 | * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center | |
6 | * Copyright (C) 1996-2002 Hybrid Development Team | |
7 | * Copyright (C) 2002-2005 ircd-ratbox development team | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
22 | * USA | |
23 | * | |
24 | * $Id: m_topic.c 254 2005-09-21 23:35:12Z nenolod $ | |
25 | */ | |
26 | ||
27 | #include "stdinc.h" | |
212380e3 AC |
28 | #include "channel.h" |
29 | #include "client.h" | |
30 | #include "hash.h" | |
4562c604 | 31 | #include "match.h" |
212380e3 AC |
32 | #include "ircd.h" |
33 | #include "numeric.h" | |
34 | #include "send.h" | |
41615da9 | 35 | #include "s_newconf.h" |
212380e3 AC |
36 | #include "s_conf.h" |
37 | #include "s_serv.h" | |
38 | #include "msg.h" | |
39 | #include "parse.h" | |
40 | #include "modules.h" | |
41 | #include "packet.h" | |
42 | ||
43 | static int m_topic(struct Client *, struct Client *, int, const char **); | |
44 | static int ms_topic(struct Client *, struct Client *, int, const char **); | |
45 | ||
46 | struct Message topic_msgtab = { | |
47 | "TOPIC", 0, 0, 0, MFLG_SLOW, | |
48 | {mg_unreg, {m_topic, 2}, {m_topic, 2}, {ms_topic, 5}, mg_ignore, {m_topic, 2}} | |
49 | }; | |
50 | ||
51 | mapi_clist_av1 topic_clist[] = { &topic_msgtab, NULL }; | |
52 | DECLARE_MODULE_AV1(topic, NULL, NULL, topic_clist, NULL, NULL, "$Revision: 254 $"); | |
53 | ||
54 | /* | |
55 | * m_topic | |
212380e3 AC |
56 | * parv[1] = channel name |
57 | * parv[2] = new topic, if setting topic | |
58 | */ | |
59 | static int | |
60 | m_topic(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
61 | { | |
62 | struct Channel *chptr = NULL; | |
63 | struct membership *msptr; | |
64 | char *p = NULL; | |
41615da9 JT |
65 | const char *name; |
66 | int operspy = 0; | |
212380e3 AC |
67 | |
68 | if((p = strchr(parv[1], ','))) | |
69 | *p = '\0'; | |
70 | ||
41615da9 JT |
71 | name = parv[1]; |
72 | ||
73 | if(IsOperSpy(source_p) && parv[1][0] == '!') | |
74 | { | |
75 | name++; | |
76 | operspy = 1; | |
77 | ||
78 | if(EmptyString(name)) | |
79 | { | |
80 | sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), | |
81 | me.name, source_p->name, "TOPIC"); | |
82 | return 0; | |
83 | } | |
84 | } | |
85 | ||
212380e3 AC |
86 | if(MyClient(source_p) && !IsFloodDone(source_p)) |
87 | flood_endgrace(source_p); | |
88 | ||
41615da9 | 89 | if(!IsChannelName(name)) |
212380e3 AC |
90 | { |
91 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
41615da9 | 92 | form_str(ERR_NOSUCHCHANNEL), name); |
212380e3 AC |
93 | return 0; |
94 | } | |
95 | ||
41615da9 | 96 | chptr = find_channel(name); |
212380e3 AC |
97 | |
98 | if(chptr == NULL) | |
99 | { | |
100 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
41615da9 | 101 | form_str(ERR_NOSUCHCHANNEL), name); |
212380e3 AC |
102 | return 0; |
103 | } | |
104 | ||
105 | /* setting topic */ | |
106 | if(parc > 2) | |
107 | { | |
108 | msptr = find_channel_membership(chptr, source_p); | |
109 | ||
110 | if(msptr == NULL) | |
111 | { | |
112 | sendto_one_numeric(source_p, ERR_NOTONCHANNEL, | |
41615da9 | 113 | form_str(ERR_NOTONCHANNEL), name); |
212380e3 AC |
114 | return 0; |
115 | } | |
116 | ||
406478d2 JT |
117 | if(((chptr->mode.mode & MODE_TOPICLIMIT) == 0 || |
118 | is_chanop(msptr)) && | |
119 | (!MyClient(source_p) || | |
120 | can_send(chptr, source_p, msptr))) | |
212380e3 AC |
121 | { |
122 | char topic_info[USERHOST_REPLYLEN]; | |
7cdb0a09 | 123 | rb_sprintf(topic_info, "%s!%s@%s", |
212380e3 | 124 | source_p->name, source_p->username, source_p->host); |
e3354945 | 125 | set_channel_topic(chptr, parv[2], topic_info, rb_current_time()); |
212380e3 AC |
126 | |
127 | sendto_server(client_p, chptr, CAP_TS6, NOCAPS, | |
128 | ":%s TOPIC %s :%s", | |
129 | use_id(source_p), chptr->chname, | |
130 | chptr->topic == NULL ? "" : chptr->topic); | |
212380e3 AC |
131 | sendto_channel_local(ALL_MEMBERS, |
132 | chptr, ":%s!%s@%s TOPIC %s :%s", | |
133 | source_p->name, source_p->username, | |
134 | source_p->host, chptr->chname, | |
135 | chptr->topic == NULL ? "" : chptr->topic); | |
136 | } | |
137 | else | |
138 | sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), | |
631b4a54 JT |
139 | get_id(&me, source_p), |
140 | get_id(source_p, source_p), name); | |
212380e3 AC |
141 | } |
142 | else if(MyClient(source_p)) | |
143 | { | |
41615da9 JT |
144 | if(operspy) |
145 | report_operspy(source_p, "TOPIC", chptr->chname); | |
146 | if(!IsMember(source_p, chptr) && SecretChannel(chptr) && | |
147 | !operspy) | |
212380e3 AC |
148 | { |
149 | sendto_one_numeric(source_p, ERR_NOTONCHANNEL, | |
41615da9 | 150 | form_str(ERR_NOTONCHANNEL), name); |
212380e3 AC |
151 | return 0; |
152 | } | |
153 | if(chptr->topic == NULL) | |
154 | sendto_one(source_p, form_str(RPL_NOTOPIC), | |
41615da9 | 155 | me.name, source_p->name, name); |
212380e3 AC |
156 | else |
157 | { | |
158 | sendto_one(source_p, form_str(RPL_TOPIC), | |
159 | me.name, source_p->name, chptr->chname, chptr->topic); | |
160 | ||
161 | sendto_one(source_p, form_str(RPL_TOPICWHOTIME), | |
162 | me.name, source_p->name, chptr->chname, | |
163 | chptr->topic_info, chptr->topic_time); | |
164 | } | |
165 | } | |
166 | ||
167 | return 0; | |
168 | } | |
169 | ||
170 | /* | |
171 | * ms_topic | |
212380e3 AC |
172 | * parv[1] = channel name |
173 | * parv[2] = topic_info | |
174 | * parv[3] = topic_info time | |
175 | * parv[4] = new channel topic | |
176 | * | |
177 | * Let servers always set a topic | |
178 | */ | |
179 | static int | |
180 | ms_topic(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
181 | { | |
182 | struct Channel *chptr = NULL; | |
183 | ||
184 | if(IsChannelName(parv[1])) | |
185 | { | |
186 | if((chptr = find_channel(parv[1])) == NULL) | |
187 | return 0; | |
188 | ||
189 | set_channel_topic(chptr, parv[4], parv[2], atoi(parv[3])); | |
190 | ||
191 | sendto_channel_local(ALL_MEMBERS, chptr, ":%s TOPIC %s :%s", | |
192 | source_p->name, parv[1], | |
193 | chptr->topic == NULL ? "" : chptr->topic); | |
194 | } | |
195 | ||
196 | return 0; | |
197 | } |