ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_topic.c
Revision: 3109
Committed: Thu Mar 6 19:25:12 2014 UTC (12 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 5747 byte(s)
Log Message:
- Applied Adam's sendto_one_numeric() changes

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     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19     * 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 "s_serv.h"
38     #include "parse.h"
39     #include "modules.h"
40     #include "packet.h"
41    
42    
43     /* m_topic()
44 michael 3096 * parv[0] = command
45 adx 30 * parv[1] = channel name
46     * parv[2] = new topic, if setting topic
47     */
48 michael 2820 static int
49 adx 30 m_topic(struct Client *client_p, struct Client *source_p,
50     int parc, char *parv[])
51     {
52     struct Channel *chptr = NULL;
53    
54 michael 885 if (EmptyString(parv[1]))
55 adx 30 {
56 michael 3109 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "TOPIC");
57 michael 2820 return 0;
58 adx 30 }
59    
60 michael 1799 if (!IsFloodDone(source_p))
61 adx 30 flood_endgrace(source_p);
62    
63 michael 895 if ((chptr = hash_find_channel(parv[1])) == NULL)
64 adx 30 {
65 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, parv[1]);
66 michael 2820 return 0;
67 michael 895 }
68    
69     /* setting topic */
70     if (parc > 2)
71     {
72 michael 2520 const struct Membership *ms = NULL;
73 michael 895
74     if ((ms = find_channel_link(source_p, chptr)) == NULL)
75 adx 30 {
76 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, parv[1]);
77 michael 2820 return 0;
78 adx 30 }
79    
80 michael 895 if (!(chptr->mode.mode & MODE_TOPICLIMIT) ||
81     has_member_flags(ms, CHFL_CHANOP|CHFL_HALFOP))
82 adx 30 {
83 michael 2820 char topic_info[USERHOST_REPLYLEN];
84 michael 885
85 michael 1203 snprintf(topic_info, sizeof(topic_info), "%s!%s@%s", source_p->name,
86     source_p->username, source_p->host);
87 michael 1799 set_channel_topic(chptr, parv[2], topic_info, CurrentTime, 1);
88 adx 30
89 michael 1474 sendto_server(client_p, CAP_TS6, NOCAPS,
90 michael 895 ":%s TOPIC %s :%s",
91     ID(source_p), chptr->chname,
92 michael 1203 chptr->topic);
93 michael 1474 sendto_server(client_p, NOCAPS, CAP_TS6,
94 michael 895 ":%s TOPIC %s :%s",
95     source_p->name, 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 2820 static int
130 michael 1799 ms_topic(struct Client *client_p, struct Client *source_p,
131     int parc, char *parv[])
132     {
133     struct Channel *chptr = NULL;
134     char topic_info[USERHOST_REPLYLEN];
135    
136     if (EmptyString(parv[1]))
137     {
138 michael 3109 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "TOPIC");
139 michael 2820 return 0;
140 michael 1799 }
141    
142     if ((chptr = hash_find_channel(parv[1])) == NULL)
143     {
144 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, parv[1]);
145 michael 2820 return 0;
146 michael 1799 }
147    
148     if (!IsClient(source_p))
149     strlcpy(topic_info, source_p->name, sizeof(topic_info));
150     else
151     snprintf(topic_info, sizeof(topic_info), "%s!%s@%s", source_p->name,
152     source_p->username, source_p->host);
153     set_channel_topic(chptr, parv[2], topic_info, CurrentTime, 0);
154    
155     sendto_server(client_p, CAP_TS6, NOCAPS, ":%s TOPIC %s :%s",
156     ID(source_p), chptr->chname,
157     chptr->topic);
158     sendto_server(client_p, NOCAPS, CAP_TS6, ":%s TOPIC %s :%s",
159     source_p->name, chptr->chname,
160     chptr->topic);
161    
162     if (!IsClient(source_p))
163     sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s TOPIC %s :%s",
164     source_p->name,
165     chptr->chname, chptr->topic);
166    
167     else
168     sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s TOPIC %s :%s",
169     source_p->name,
170     source_p->username,
171     source_p->host,
172     chptr->chname, chptr->topic);
173 michael 2820 return 0;
174 michael 1799 }
175    
176    
177 michael 2820 static struct Message topic_msgtab =
178     {
179 michael 1230 "TOPIC", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
180 michael 2820 { m_unregistered, m_topic, ms_topic, m_ignore, m_topic, m_ignore }
181 michael 1230 };
182    
183     static void
184     module_init(void)
185     {
186     mod_add_cmd(&topic_msgtab);
187     }
188    
189     static void
190     module_exit(void)
191     {
192     mod_del_cmd(&topic_msgtab);
193     }
194    
195 michael 2820 struct module module_entry =
196     {
197 michael 1230 .node = { NULL, NULL, NULL },
198     .name = NULL,
199     .version = "$Revision$",
200     .handle = NULL,
201     .modinit = module_init,
202     .modexit = module_exit,
203     .flags = 0
204     };

Properties

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