ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_topic.c
Revision: 2021
Committed: Sun May 12 16:56:37 2013 UTC (12 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 6173 byte(s)
Log Message:
- m_topic.c: fixed compile warning

File Contents

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

Properties

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