ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_topic.c
Revision: 3135
Committed: Mon Mar 10 21:11:25 2014 UTC (11 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 5411 byte(s)
Log Message:
- Server now no longer accepts TS5 links

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] = command
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_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "TOPIC");
57 return 0;
58 }
59
60 if (!IsFloodDone(source_p))
61 flood_endgrace(source_p);
62
63 if ((chptr = hash_find_channel(parv[1])) == NULL)
64 {
65 sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, parv[1]);
66 return 0;
67 }
68
69 /* setting topic */
70 if (parc > 2)
71 {
72 const struct Membership *ms = NULL;
73
74 if ((ms = find_channel_link(source_p, chptr)) == NULL)
75 {
76 sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, parv[1]);
77 return 0;
78 }
79
80 if (!(chptr->mode.mode & MODE_TOPICLIMIT) ||
81 has_member_flags(ms, CHFL_CHANOP|CHFL_HALFOP))
82 {
83 char topic_info[USERHOST_REPLYLEN];
84
85 snprintf(topic_info, sizeof(topic_info), "%s!%s@%s", source_p->name,
86 source_p->username, source_p->host);
87 set_channel_topic(chptr, parv[2], topic_info, CurrentTime, 1);
88
89 sendto_server(client_p, NOCAPS, NOCAPS, ":%s TOPIC %s :%s",
90 ID(source_p), chptr->chname,
91 chptr->topic);
92 sendto_channel_local(ALL_MEMBERS, 0,
93 chptr, ":%s!%s@%s TOPIC %s :%s",
94 source_p->name,
95 source_p->username,
96 source_p->host,
97 chptr->chname, chptr->topic);
98 }
99 else
100 sendto_one_numeric(source_p, &me, ERR_CHANOPRIVSNEEDED, chptr->chname);
101 }
102 else /* only asking for topic */
103 {
104 if (!SecretChannel(chptr) || IsMember(source_p, chptr))
105 {
106 if (chptr->topic[0] == '\0')
107 sendto_one_numeric(source_p, &me, RPL_NOTOPIC, chptr->chname);
108 else
109 {
110 sendto_one_numeric(source_p, &me, RPL_TOPIC,
111 chptr->chname, chptr->topic);
112 sendto_one_numeric(source_p, &me, RPL_TOPICWHOTIME, chptr->chname,
113 chptr->topic_info,
114 chptr->topic_time);
115 }
116 }
117 else
118 sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, chptr->chname);
119 }
120
121 return 0;
122 }
123
124 static int
125 ms_topic(struct Client *client_p, struct Client *source_p,
126 int parc, char *parv[])
127 {
128 struct Channel *chptr = NULL;
129 char topic_info[USERHOST_REPLYLEN];
130
131 if (EmptyString(parv[1]))
132 {
133 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "TOPIC");
134 return 0;
135 }
136
137 if ((chptr = hash_find_channel(parv[1])) == NULL)
138 {
139 sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, parv[1]);
140 return 0;
141 }
142
143 if (!IsClient(source_p))
144 strlcpy(topic_info, source_p->name, sizeof(topic_info));
145 else
146 snprintf(topic_info, sizeof(topic_info), "%s!%s@%s", source_p->name,
147 source_p->username, source_p->host);
148 set_channel_topic(chptr, parv[2], topic_info, CurrentTime, 0);
149
150 sendto_server(client_p, NOCAPS, NOCAPS, ":%s TOPIC %s :%s",
151 ID(source_p), chptr->chname,
152 chptr->topic);
153
154 if (!IsClient(source_p))
155 sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s TOPIC %s :%s",
156 source_p->name,
157 chptr->chname, chptr->topic);
158
159 else
160 sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s TOPIC %s :%s",
161 source_p->name,
162 source_p->username,
163 source_p->host,
164 chptr->chname, chptr->topic);
165 return 0;
166 }
167
168
169 static struct Message topic_msgtab =
170 {
171 "TOPIC", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
172 { m_unregistered, m_topic, ms_topic, m_ignore, m_topic, m_ignore }
173 };
174
175 static void
176 module_init(void)
177 {
178 mod_add_cmd(&topic_msgtab);
179 }
180
181 static void
182 module_exit(void)
183 {
184 mod_del_cmd(&topic_msgtab);
185 }
186
187 struct module module_entry =
188 {
189 .node = { NULL, NULL, NULL },
190 .name = NULL,
191 .version = "$Revision$",
192 .handle = NULL,
193 .modinit = module_init,
194 .modexit = module_exit,
195 .flags = 0
196 };

Properties

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