]>
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" | |
28 | #include "tools.h" | |
29 | #include "channel.h" | |
30 | #include "client.h" | |
31 | #include "hash.h" | |
32 | #include "irc_string.h" | |
33 | #include "sprintf_irc.h" | |
34 | #include "ircd.h" | |
35 | #include "numeric.h" | |
36 | #include "send.h" | |
37 | #include "s_conf.h" | |
38 | #include "s_serv.h" | |
39 | #include "msg.h" | |
40 | #include "parse.h" | |
41 | #include "modules.h" | |
42 | #include "packet.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[0] = sender prefix | |
58 | * parv[1] = channel name | |
59 | * parv[2] = new topic, if setting topic | |
60 | */ | |
61 | static int | |
62 | m_topic(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
63 | { | |
64 | struct Channel *chptr = NULL; | |
65 | struct membership *msptr; | |
66 | char *p = NULL; | |
67 | ||
68 | if((p = strchr(parv[1], ','))) | |
69 | *p = '\0'; | |
70 | ||
71 | if(MyClient(source_p) && !IsFloodDone(source_p)) | |
72 | flood_endgrace(source_p); | |
73 | ||
74 | if(!IsChannelName(parv[1])) | |
75 | { | |
76 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
77 | form_str(ERR_NOSUCHCHANNEL), parv[1]); | |
78 | return 0; | |
79 | } | |
80 | ||
81 | chptr = find_channel(parv[1]); | |
82 | ||
83 | if(chptr == NULL) | |
84 | { | |
85 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
86 | form_str(ERR_NOSUCHCHANNEL), parv[1]); | |
87 | return 0; | |
88 | } | |
89 | ||
90 | /* setting topic */ | |
91 | if(parc > 2) | |
92 | { | |
93 | msptr = find_channel_membership(chptr, source_p); | |
94 | ||
95 | if(msptr == NULL) | |
96 | { | |
97 | sendto_one_numeric(source_p, ERR_NOTONCHANNEL, | |
98 | form_str(ERR_NOTONCHANNEL), parv[1]); | |
99 | return 0; | |
100 | } | |
101 | ||
102 | if((chptr->mode.mode & MODE_TOPICLIMIT) == 0 || is_chanop(msptr)) | |
103 | { | |
104 | char topic_info[USERHOST_REPLYLEN]; | |
105 | ircsprintf(topic_info, "%s!%s@%s", | |
106 | source_p->name, source_p->username, source_p->host); | |
107 | set_channel_topic(chptr, parv[2], topic_info, CurrentTime); | |
108 | ||
109 | sendto_server(client_p, chptr, CAP_TS6, NOCAPS, | |
110 | ":%s TOPIC %s :%s", | |
111 | use_id(source_p), chptr->chname, | |
112 | chptr->topic == NULL ? "" : chptr->topic); | |
113 | sendto_server(client_p, chptr, NOCAPS, CAP_TS6, | |
114 | ":%s TOPIC %s :%s", | |
115 | source_p->name, chptr->chname, | |
116 | chptr->topic == NULL ? "" : chptr->topic); | |
117 | sendto_channel_local(ALL_MEMBERS, | |
118 | chptr, ":%s!%s@%s TOPIC %s :%s", | |
119 | source_p->name, source_p->username, | |
120 | source_p->host, chptr->chname, | |
121 | chptr->topic == NULL ? "" : chptr->topic); | |
122 | } | |
123 | else | |
124 | sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), | |
125 | me.name, source_p->name, parv[1]); | |
126 | } | |
127 | else if(MyClient(source_p)) | |
128 | { | |
129 | if(!IsMember(source_p, chptr) && SecretChannel(chptr)) | |
130 | { | |
131 | sendto_one_numeric(source_p, ERR_NOTONCHANNEL, | |
132 | form_str(ERR_NOTONCHANNEL), parv[1]); | |
133 | return 0; | |
134 | } | |
135 | if(chptr->topic == NULL) | |
136 | sendto_one(source_p, form_str(RPL_NOTOPIC), | |
137 | me.name, source_p->name, parv[1]); | |
138 | else | |
139 | { | |
140 | sendto_one(source_p, form_str(RPL_TOPIC), | |
141 | me.name, source_p->name, chptr->chname, chptr->topic); | |
142 | ||
143 | sendto_one(source_p, form_str(RPL_TOPICWHOTIME), | |
144 | me.name, source_p->name, chptr->chname, | |
145 | chptr->topic_info, chptr->topic_time); | |
146 | } | |
147 | } | |
148 | ||
149 | return 0; | |
150 | } | |
151 | ||
152 | /* | |
153 | * ms_topic | |
154 | * parv[0] = sender prefix | |
155 | * parv[1] = channel name | |
156 | * parv[2] = topic_info | |
157 | * parv[3] = topic_info time | |
158 | * parv[4] = new channel topic | |
159 | * | |
160 | * Let servers always set a topic | |
161 | */ | |
162 | static int | |
163 | ms_topic(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
164 | { | |
165 | struct Channel *chptr = NULL; | |
166 | ||
167 | if(IsChannelName(parv[1])) | |
168 | { | |
169 | if((chptr = find_channel(parv[1])) == NULL) | |
170 | return 0; | |
171 | ||
172 | set_channel_topic(chptr, parv[4], parv[2], atoi(parv[3])); | |
173 | ||
174 | sendto_channel_local(ALL_MEMBERS, chptr, ":%s TOPIC %s :%s", | |
175 | source_p->name, parv[1], | |
176 | chptr->topic == NULL ? "" : chptr->topic); | |
177 | } | |
178 | ||
179 | return 0; | |
180 | } |