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