ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_topic.c
Revision: 3274
Committed: Sun Apr 6 12:22:23 2014 UTC (12 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 5330 byte(s)
Error occurred while calculating annotation data.
Log Message:
- Clean up redundant/unused header includes

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

Properties

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