ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_topic.c
Revision: 2820
Committed: Wed Jan 15 23:10:26 2014 UTC (12 years, 8 months ago) by michael
Content type: text/x-csrc
File size: 6283 byte(s)
Error occurred while calculating annotation data.
Log Message:
- Clean up all files in modules/ (fixed indentation, removed whitespaces/tabs)
- Fixed copyright years
- Made module handlers int type for later use

File Contents

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

Properties

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