]>
Commit | Line | Data |
---|---|---|
212380e3 | 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 | * | |
212380e3 | 24 | */ |
25 | ||
26 | #include "stdinc.h" | |
212380e3 | 27 | #include "channel.h" |
28 | #include "client.h" | |
29 | #include "hash.h" | |
13ae2f4b | 30 | #include "match.h" |
212380e3 | 31 | #include "ircd.h" |
32 | #include "numeric.h" | |
33 | #include "send.h" | |
73788f79 | 34 | #include "s_newconf.h" |
212380e3 | 35 | #include "s_conf.h" |
36 | #include "s_serv.h" | |
37 | #include "msg.h" | |
38 | #include "parse.h" | |
39 | #include "modules.h" | |
40 | #include "packet.h" | |
41 | ||
42 | static int m_topic(struct Client *, struct Client *, int, const char **); | |
43 | static int ms_topic(struct Client *, struct Client *, int, const char **); | |
44 | ||
45 | struct Message topic_msgtab = { | |
46 | "TOPIC", 0, 0, 0, MFLG_SLOW, | |
47 | {mg_unreg, {m_topic, 2}, {m_topic, 2}, {ms_topic, 5}, mg_ignore, {m_topic, 2}} | |
48 | }; | |
49 | ||
50 | mapi_clist_av1 topic_clist[] = { &topic_msgtab, NULL }; | |
51 | DECLARE_MODULE_AV1(topic, NULL, NULL, topic_clist, NULL, NULL, "$Revision: 254 $"); | |
52 | ||
53 | /* | |
54 | * m_topic | |
212380e3 | 55 | * parv[1] = channel name |
56 | * parv[2] = new topic, if setting topic | |
57 | */ | |
58 | static int | |
59 | m_topic(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
60 | { | |
61 | struct Channel *chptr = NULL; | |
62 | struct membership *msptr; | |
63 | char *p = NULL; | |
73788f79 JT |
64 | const char *name; |
65 | int operspy = 0; | |
212380e3 | 66 | |
67 | if((p = strchr(parv[1], ','))) | |
68 | *p = '\0'; | |
69 | ||
73788f79 JT |
70 | name = parv[1]; |
71 | ||
72 | if(IsOperSpy(source_p) && parv[1][0] == '!') | |
73 | { | |
74 | name++; | |
75 | operspy = 1; | |
76 | ||
77 | if(EmptyString(name)) | |
78 | { | |
79 | sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), | |
80 | me.name, source_p->name, "TOPIC"); | |
81 | return 0; | |
82 | } | |
83 | } | |
84 | ||
212380e3 | 85 | if(MyClient(source_p) && !IsFloodDone(source_p)) |
86 | flood_endgrace(source_p); | |
87 | ||
73788f79 | 88 | if(!IsChannelName(name)) |
212380e3 | 89 | { |
90 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
73788f79 | 91 | form_str(ERR_NOSUCHCHANNEL), name); |
212380e3 | 92 | return 0; |
93 | } | |
94 | ||
73788f79 | 95 | chptr = find_channel(name); |
212380e3 | 96 | |
97 | if(chptr == NULL) | |
98 | { | |
99 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
73788f79 | 100 | form_str(ERR_NOSUCHCHANNEL), name); |
212380e3 | 101 | return 0; |
102 | } | |
103 | ||
104 | /* setting topic */ | |
105 | if(parc > 2) | |
106 | { | |
c6fa5506 JH |
107 | char topic_info[USERHOST_REPLYLEN]; |
108 | ||
212380e3 | 109 | msptr = find_channel_membership(chptr, source_p); |
110 | ||
111 | if(msptr == NULL) | |
112 | { | |
113 | sendto_one_numeric(source_p, ERR_NOTONCHANNEL, | |
73788f79 | 114 | form_str(ERR_NOTONCHANNEL), name); |
212380e3 | 115 | return 0; |
116 | } | |
117 | ||
ba06b3db | 118 | if(MyClient(source_p) && (chptr->mode.mode & MODE_TOPICLIMIT) && !is_any_op(msptr)) |
212380e3 | 119 | { |
c6fa5506 | 120 | if(IsOverride(source_p)) |
34d8ef4d JH |
121 | { |
122 | sendto_wallops_flags(UMODE_WALLOP, &me, | |
c6fa5506 JH |
123 | "%s is overriding TOPIC on [%s]", |
124 | get_oper_name(source_p), chptr->chname); | |
34d8ef4d JH |
125 | sendto_server(NULL, chptr, NOCAPS, NOCAPS, |
126 | ":%s WALLOPS :%s is overriding TOPIC on [%s]", | |
71ea6069 | 127 | me.name, get_oper_name(source_p), chptr->chname); |
34d8ef4d | 128 | } |
c6fa5506 JH |
129 | else |
130 | { | |
131 | sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), | |
132 | me.name, source_p->name, parv[1]); | |
133 | return 0; | |
134 | } | |
135 | ||
136 | } | |
45b9f1cb JH |
137 | |
138 | if(ConfigChannel.host_in_topic) | |
139 | rb_sprintf(topic_info, "%s!%s@%s", | |
140 | source_p->name, source_p->username, source_p->host); | |
141 | else | |
142 | rb_strlcpy(topic_info, source_p->name, sizeof(topic_info)); | |
143 | ||
9f6bbe3c | 144 | set_channel_topic(chptr, parv[2], topic_info, rb_current_time()); |
212380e3 | 145 | |
146 | sendto_server(client_p, chptr, CAP_TS6, NOCAPS, | |
147 | ":%s TOPIC %s :%s", | |
148 | use_id(source_p), chptr->chname, | |
149 | chptr->topic == NULL ? "" : chptr->topic); | |
212380e3 | 150 | sendto_channel_local(ALL_MEMBERS, |
151 | chptr, ":%s!%s@%s TOPIC %s :%s", | |
152 | source_p->name, source_p->username, | |
153 | source_p->host, chptr->chname, | |
154 | chptr->topic == NULL ? "" : chptr->topic); | |
c6fa5506 | 155 | |
212380e3 | 156 | } |
157 | else if(MyClient(source_p)) | |
158 | { | |
73788f79 JT |
159 | if(operspy) |
160 | report_operspy(source_p, "TOPIC", chptr->chname); | |
161 | if(!IsMember(source_p, chptr) && SecretChannel(chptr) && | |
162 | !operspy) | |
212380e3 | 163 | { |
164 | sendto_one_numeric(source_p, ERR_NOTONCHANNEL, | |
73788f79 | 165 | form_str(ERR_NOTONCHANNEL), name); |
212380e3 | 166 | return 0; |
167 | } | |
168 | if(chptr->topic == NULL) | |
169 | sendto_one(source_p, form_str(RPL_NOTOPIC), | |
73788f79 | 170 | me.name, source_p->name, name); |
212380e3 | 171 | else |
172 | { | |
173 | sendto_one(source_p, form_str(RPL_TOPIC), | |
174 | me.name, source_p->name, chptr->chname, chptr->topic); | |
175 | ||
176 | sendto_one(source_p, form_str(RPL_TOPICWHOTIME), | |
177 | me.name, source_p->name, chptr->chname, | |
178 | chptr->topic_info, chptr->topic_time); | |
179 | } | |
180 | } | |
181 | ||
182 | return 0; | |
183 | } | |
184 | ||
185 | /* | |
186 | * ms_topic | |
212380e3 | 187 | * parv[1] = channel name |
188 | * parv[2] = topic_info | |
189 | * parv[3] = topic_info time | |
190 | * parv[4] = new channel topic | |
191 | * | |
192 | * Let servers always set a topic | |
193 | */ | |
194 | static int | |
195 | ms_topic(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
196 | { | |
197 | struct Channel *chptr = NULL; | |
198 | ||
199 | if(IsChannelName(parv[1])) | |
200 | { | |
201 | if((chptr = find_channel(parv[1])) == NULL) | |
202 | return 0; | |
203 | ||
204 | set_channel_topic(chptr, parv[4], parv[2], atoi(parv[3])); | |
205 | ||
206 | sendto_channel_local(ALL_MEMBERS, chptr, ":%s TOPIC %s :%s", | |
207 | source_p->name, parv[1], | |
208 | chptr->topic == NULL ? "" : chptr->topic); | |
209 | } | |
210 | ||
211 | return 0; | |
212 | } |