ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-7.2/modules/m_topic.c
Revision: 885
Committed: Wed Oct 31 18:09:24 2007 UTC (17 years, 9 months ago) by michael
Content type: text/x-csrc
File size: 6264 byte(s)
Log Message:
- Removed LazyLinks in 7.2 to stop people from asking why we keep
  broken code for half a decade. LL will be implemented in a smarter
  fashion in due time

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * m_topic.c: Sets a channel topic.
4 *
5 * Copyright (C) 2002 by the past and present ircd coders, and others.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA
21 *
22 * $Id$
23 */
24
25 #include "stdinc.h"
26 #include "tools.h"
27 #include "handlers.h"
28 #include "channel.h"
29 #include "channel_mode.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 #include "common.h"
44
45 static void m_topic(struct Client *, struct Client *, int, char **);
46 static void ms_topic(struct Client *, struct Client *, int, char **);
47
48 struct Message topic_msgtab = {
49 "TOPIC", 0, 0, 2, 0, MFLG_SLOW, 0,
50 {m_unregistered, m_topic, ms_topic, m_ignore, m_topic, m_ignore}
51 };
52
53 #ifndef STATIC_MODULES
54 void
55 _modinit(void)
56 {
57 mod_add_cmd(&topic_msgtab);
58 }
59
60 void
61 _moddeinit(void)
62 {
63 mod_del_cmd(&topic_msgtab);
64 }
65
66 const char *_version = "$Revision$";
67 #endif
68
69 /* m_topic()
70 * parv[0] = sender prefix
71 * parv[1] = channel name
72 * parv[2] = new topic, if setting topic
73 */
74 static void
75 m_topic(struct Client *client_p, struct Client *source_p,
76 int parc, char *parv[])
77 {
78 struct Channel *chptr = NULL;
79 char *p;
80 struct Membership *ms;
81 const char *from, *to;
82
83 if (!MyClient(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
84 {
85 from = me.id;
86 to = source_p->id;
87 }
88 else
89 {
90 from = me.name;
91 to = source_p->name;
92 }
93
94 if ((p = strchr(parv[1], ',')) != NULL)
95 *p = '\0';
96
97 if (EmptyString(parv[1]))
98 {
99 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
100 from, to, "TOPIC");
101 return;
102 }
103
104 if (MyClient(source_p) && !IsFloodDone(source_p))
105 flood_endgrace(source_p);
106
107 if (IsChanPrefix(*parv[1]))
108 {
109 if ((chptr = hash_find_channel(parv[1])) == NULL)
110 {
111 sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL),
112 from, to, parv[1]);
113 return;
114 }
115
116 /* setting topic */
117 if (parc > 2)
118 {
119 if ((ms = find_channel_link(source_p, chptr)) == NULL)
120 {
121 sendto_one(source_p, form_str(ERR_NOTONCHANNEL), from,
122 to, parv[1]);
123 return;
124 }
125
126 if ((chptr->mode.mode & MODE_TOPICLIMIT) == 0 ||
127 has_member_flags(ms, CHFL_CHANOP|CHFL_HALFOP))
128 {
129 char topic_info[USERHOST_REPLYLEN];
130 ircsprintf(topic_info, "%s!%s@%s",
131 source_p->name, source_p->username, source_p->host);
132 set_channel_topic(chptr, parv[2], topic_info, CurrentTime);
133
134 sendto_server(client_p, chptr, CAP_TS6, NOCAPS,
135 ":%s TOPIC %s :%s",
136 ID(source_p), chptr->chname,
137 chptr->topic == NULL ? "" : chptr->topic);
138 sendto_server(client_p, chptr, NOCAPS, CAP_TS6,
139 ":%s TOPIC %s :%s",
140 source_p->name, chptr->chname,
141 chptr->topic == NULL ? "" : chptr->topic);
142 sendto_channel_local(ALL_MEMBERS, NO,
143 chptr, ":%s!%s@%s TOPIC %s :%s",
144 source_p->name,
145 source_p->username,
146 source_p->host,
147 chptr->chname, chptr->topic == NULL ?
148 "" : chptr->topic);
149 }
150 else
151 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
152 from, to, chptr->chname);
153 }
154 else /* only asking for topic */
155 {
156 if (!SecretChannel(chptr) || IsMember(source_p, chptr))
157 {
158 if (chptr->topic == NULL)
159 sendto_one(source_p, form_str(RPL_NOTOPIC),
160 from, to, chptr->chname);
161 else
162 {
163 sendto_one(source_p, form_str(RPL_TOPIC),
164 from, to,
165 chptr->chname, chptr->topic);
166
167 sendto_one(source_p, form_str(RPL_TOPICWHOTIME),
168 from, to, chptr->chname,
169 chptr->topic_info,
170 chptr->topic_time);
171 }
172 }
173 else
174 {
175 sendto_one(source_p, form_str(ERR_NOTONCHANNEL),
176 from, to, chptr->chname);
177 return;
178 }
179 }
180 }
181 else
182 {
183 sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL),
184 from, to, parv[1]);
185 }
186 }
187
188 /*
189 * ms_topic
190 * parv[0] = sender prefix
191 * parv[1] = channel name
192 * parv[2] = topic_info
193 * parv[3] = topic_info time
194 * parv[4] = new channel topic
195 *
196 * Let servers always set a topic
197 */
198 static void
199 ms_topic(struct Client *client_p, struct Client *source_p,
200 int parc, char *parv[])
201 {
202 struct Channel *chptr = NULL;
203
204 if (!IsServer(source_p))
205 {
206 m_topic(client_p, source_p, parc, parv);
207 return;
208 }
209
210 if (parc < 5)
211 return;
212
213 if (parv[1] && IsChanPrefix(*parv[1]))
214 {
215 if ((chptr = hash_find_channel(parv[1])) == NULL)
216 return;
217
218 set_channel_topic(chptr, parv[4], parv[2], atoi(parv[3]));
219
220 if (ConfigServerHide.hide_servers)
221 {
222 sendto_channel_local(ALL_MEMBERS, NO, chptr, ":%s TOPIC %s :%s",
223 me.name, chptr->chname,
224 chptr->topic == NULL ? "" : chptr->topic);
225
226 }
227 else
228 {
229 sendto_channel_local(ALL_MEMBERS, NO, chptr, ":%s TOPIC %s :%s",
230 source_p->name, chptr->chname,
231 chptr->topic == NULL ? "" : chptr->topic);
232 }
233 }
234 }

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision