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