ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/modules/m_topic.c
Revision: 4564
Committed: Sun Aug 24 10:24:47 2014 UTC (11 years, 11 months ago) by michael
Content type: text/x-csrc
File size: 6277 byte(s)
Log Message:
- Update GPL 2 license headers

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2820 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 2820 * Copyright (c) 1997-2014 ircd-hybrid development team
5 adx 30 *
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 michael 4564 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 adx 30 * USA
20     */
21    
22 michael 2820 /*! \file m_topic.c
23     * \brief Includes required functions for processing the TOPIC command.
24     * \version $Id$
25     */
26    
27 adx 30 #include "stdinc.h"
28 michael 1011 #include "list.h"
29 adx 30 #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 michael 3332 /*! \brief TOPIC command handler
43     *
44     * \param source_p Pointer to allocated Client struct from which the message
45     * originally comes from. This can be a local or remote client.
46     * \param parc Integer holding the number of supplied arguments.
47     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
48     * pointers.
49     * \note Valid arguments for this command are:
50     * - parv[0] = command
51     * - parv[1] = channel name
52     * - parv[2] = topic text, if setting topic
53 adx 30 */
54 michael 2820 static int
55 michael 3156 m_topic(struct Client *source_p, int parc, char *parv[])
56 adx 30 {
57     struct Channel *chptr = NULL;
58    
59 michael 885 if (EmptyString(parv[1]))
60 adx 30 {
61 michael 3109 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "TOPIC");
62 michael 2820 return 0;
63 adx 30 }
64    
65 michael 1799 if (!IsFloodDone(source_p))
66 adx 30 flood_endgrace(source_p);
67    
68 michael 895 if ((chptr = hash_find_channel(parv[1])) == NULL)
69 adx 30 {
70 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, parv[1]);
71 michael 2820 return 0;
72 michael 895 }
73    
74     /* setting topic */
75     if (parc > 2)
76     {
77 michael 2520 const struct Membership *ms = NULL;
78 michael 895
79     if ((ms = find_channel_link(source_p, chptr)) == NULL)
80 adx 30 {
81 michael 3220 sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, chptr->chname);
82 michael 2820 return 0;
83 adx 30 }
84    
85 michael 895 if (!(chptr->mode.mode & MODE_TOPICLIMIT) ||
86     has_member_flags(ms, CHFL_CHANOP|CHFL_HALFOP))
87 adx 30 {
88 michael 2820 char topic_info[USERHOST_REPLYLEN];
89 michael 885
90 michael 1203 snprintf(topic_info, sizeof(topic_info), "%s!%s@%s", source_p->name,
91     source_p->username, source_p->host);
92 michael 3940 channel_set_topic(chptr, parv[2], topic_info, CurrentTime, 1);
93 adx 30
94 michael 3156 sendto_server(source_p, NOCAPS, NOCAPS, ":%s TOPIC %s :%s",
95 michael 3186 source_p->id, chptr->chname,
96 michael 1203 chptr->topic);
97 michael 1011 sendto_channel_local(ALL_MEMBERS, 0,
98 michael 895 chptr, ":%s!%s@%s TOPIC %s :%s",
99     source_p->name,
100     source_p->username,
101     source_p->host,
102 michael 1203 chptr->chname, chptr->topic);
103 adx 30 }
104 michael 895 else
105 michael 3109 sendto_one_numeric(source_p, &me, ERR_CHANOPRIVSNEEDED, chptr->chname);
106 michael 895 }
107     else /* only asking for topic */
108     {
109     if (!SecretChannel(chptr) || IsMember(source_p, chptr))
110 adx 30 {
111 michael 1203 if (chptr->topic[0] == '\0')
112 michael 3109 sendto_one_numeric(source_p, &me, RPL_NOTOPIC, chptr->chname);
113 adx 30 else
114     {
115 michael 3109 sendto_one_numeric(source_p, &me, RPL_TOPIC,
116     chptr->chname, chptr->topic);
117     sendto_one_numeric(source_p, &me, RPL_TOPICWHOTIME, chptr->chname,
118     chptr->topic_info,
119     chptr->topic_time);
120 adx 30 }
121     }
122     else
123 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, chptr->chname);
124 adx 30 }
125 michael 2820
126     return 0;
127 adx 30 }
128 michael 1230
129 michael 3332
130     /*! \brief TOPIC command handler
131     *
132     * \param source_p Pointer to allocated Client struct from which the message
133     * originally comes from. This can be a local or remote client.
134     * \param parc Integer holding the number of supplied arguments.
135     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
136     * pointers.
137     * \note Valid arguments for this command are:
138     * - parv[0] = command
139     * - parv[1] = channel name
140     * - parv[2] = topic text
141     */
142 michael 2820 static int
143 michael 3156 ms_topic(struct Client *source_p, int parc, char *parv[])
144 michael 1799 {
145     struct Channel *chptr = NULL;
146     char topic_info[USERHOST_REPLYLEN];
147    
148     if (EmptyString(parv[1]))
149     {
150 michael 3109 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "TOPIC");
151 michael 2820 return 0;
152 michael 1799 }
153    
154     if ((chptr = hash_find_channel(parv[1])) == NULL)
155     {
156 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, parv[1]);
157 michael 2820 return 0;
158 michael 1799 }
159    
160     if (!IsClient(source_p))
161     strlcpy(topic_info, source_p->name, sizeof(topic_info));
162     else
163     snprintf(topic_info, sizeof(topic_info), "%s!%s@%s", source_p->name,
164     source_p->username, source_p->host);
165 michael 3940 channel_set_topic(chptr, parv[2], topic_info, CurrentTime, 0);
166 michael 1799
167 michael 3156 sendto_server(source_p, NOCAPS, NOCAPS, ":%s TOPIC %s :%s",
168 michael 3186 source_p->id, chptr->chname,
169 michael 1799 chptr->topic);
170    
171     if (!IsClient(source_p))
172     sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s TOPIC %s :%s",
173     source_p->name,
174     chptr->chname, chptr->topic);
175    
176     else
177     sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s TOPIC %s :%s",
178     source_p->name,
179     source_p->username,
180     source_p->host,
181     chptr->chname, chptr->topic);
182 michael 2820 return 0;
183 michael 1799 }
184    
185    
186 michael 2820 static struct Message topic_msgtab =
187     {
188 michael 4546 "TOPIC", NULL, 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
189 michael 2820 { m_unregistered, m_topic, ms_topic, m_ignore, m_topic, m_ignore }
190 michael 1230 };
191    
192     static void
193     module_init(void)
194     {
195     mod_add_cmd(&topic_msgtab);
196     }
197    
198     static void
199     module_exit(void)
200     {
201     mod_del_cmd(&topic_msgtab);
202     }
203    
204 michael 2820 struct module module_entry =
205     {
206 michael 1230 .node = { NULL, NULL, NULL },
207     .name = NULL,
208     .version = "$Revision$",
209     .handle = NULL,
210     .modinit = module_init,
211     .modexit = module_exit,
212     .flags = 0
213     };

Properties

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