ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_topic.c
Revision: 69
Committed: Tue Oct 4 16:09:51 2005 UTC (20 years, 10 months ago) by adx
Content type: text/x-csrc
File size: 7225 byte(s)
Log Message:
- splitted ircd/libio, all headers connected with libio sources have been
  moved for internal use only. To use libio interface, include "libio.h"
  (which is already done in "stdinc.h")


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     #include "handlers.h"
27     #include "channel.h"
28     #include "channel_mode.h"
29     #include "client.h"
30     #include "hash.h"
31     #include "ircd.h"
32     #include "numeric.h"
33     #include "send.h"
34     #include "s_conf.h"
35     #include "s_serv.h"
36     #include "msg.h"
37     #include "parse.h"
38     #include "modules.h"
39     #include "packet.h"
40     #include "common.h"
41    
42     static void m_topic(struct Client *, struct Client *, int, char **);
43     static void ms_topic(struct Client *, struct Client *, int, char **);
44    
45     struct Message topic_msgtab = {
46     "TOPIC", 0, 0, 2, 0, MFLG_SLOW, 0,
47     {m_unregistered, m_topic, ms_topic, m_ignore, m_topic, m_ignore}
48     };
49    
50     #ifndef STATIC_MODULES
51     void
52     _modinit(void)
53     {
54     mod_add_cmd(&topic_msgtab);
55     }
56    
57     void
58     _moddeinit(void)
59     {
60     mod_del_cmd(&topic_msgtab);
61     }
62    
63 knight 31 const char *_version = "$Revision$";
64 adx 30 #endif
65    
66     /* m_topic()
67     * parv[0] = sender prefix
68     * parv[1] = channel name
69     * parv[2] = new topic, if setting topic
70     */
71     static void
72     m_topic(struct Client *client_p, struct Client *source_p,
73     int parc, char *parv[])
74     {
75     struct Channel *chptr = NULL;
76     char *p;
77     struct Membership *ms;
78     const char *from, *to;
79    
80     if (!MyClient(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
81     {
82     from = me.id;
83     to = source_p->id;
84     }
85     else
86     {
87     from = me.name;
88     to = source_p->name;
89     }
90    
91     if ((p = strchr(parv[1], ',')) != NULL)
92     *p = '\0';
93    
94     if (parv[1][0] == '\0')
95     {
96     sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
97     from, to, "TOPIC");
98     return;
99     }
100    
101     if (MyClient(source_p) && !IsFloodDone(source_p))
102     flood_endgrace(source_p);
103    
104     if (IsChanPrefix(*parv[1]))
105     {
106     if ((chptr = hash_find_channel(parv[1])) == NULL)
107     {
108     /* if chptr isn't found locally, it =could= exist
109     * on the uplink. so forward reqeuest
110     */
111     if (!ServerInfo.hub && uplink && IsCapable(uplink, CAP_LL))
112     {
113     sendto_one(uplink, ":%s TOPIC %s %s",
114     ID_or_name(source_p, uplink), chptr->chname,
115     ((parc > 2) ? parv[2] : ""));
116     return;
117     }
118     else
119     {
120     sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL),
121     from, to, parv[1]);
122     return;
123     }
124     }
125    
126     /* setting topic */
127     if (parc > 2)
128     {
129     if ((ms = find_channel_link(source_p, chptr)) == NULL)
130     {
131     sendto_one(source_p, form_str(ERR_NOTONCHANNEL), from,
132     to, parv[1]);
133     return;
134     }
135     if ((chptr->mode.mode & MODE_TOPICLIMIT) == 0 ||
136     has_member_flags(ms, CHFL_CHANOP|CHFL_HALFOP))
137     {
138     char topic_info[USERHOST_REPLYLEN];
139     ircsprintf(topic_info, "%s!%s@%s",
140     source_p->name, source_p->username, source_p->host);
141     set_channel_topic(chptr, parv[2], topic_info, CurrentTime);
142    
143     sendto_server(client_p, NULL, chptr, CAP_TS6, NOCAPS, NOFLAGS,
144     ":%s TOPIC %s :%s",
145     ID(source_p), chptr->chname,
146     chptr->topic == NULL ? "" : chptr->topic);
147     sendto_server(client_p, NULL, chptr, NOCAPS, CAP_TS6, NOFLAGS,
148     ":%s TOPIC %s :%s",
149     source_p->name, chptr->chname,
150     chptr->topic == NULL ? "" : chptr->topic);
151     sendto_channel_local(ALL_MEMBERS, NO,
152     chptr, ":%s!%s@%s TOPIC %s :%s",
153     source_p->name,
154     source_p->username,
155     source_p->host,
156     chptr->chname, chptr->topic == NULL ?
157     "" : chptr->topic);
158     }
159     else
160     sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
161     from, to, chptr->chname);
162     }
163     else /* only asking for topic */
164     {
165     if (!SecretChannel(chptr) || IsMember(source_p, chptr))
166     {
167     if (chptr->topic == NULL)
168     sendto_one(source_p, form_str(RPL_NOTOPIC),
169     from, to, chptr->chname);
170     else
171     {
172     sendto_one(source_p, form_str(RPL_TOPIC),
173     from, to,
174     chptr->chname, chptr->topic);
175    
176     /* client on LL needing the topic - if we have serverhide, say
177     * its the actual LL server that set the topic, not us the
178     * uplink -- fl_
179     */
180     if (ConfigServerHide.hide_servers && !MyClient(source_p)
181     && IsCapable(client_p, CAP_LL) && ServerInfo.hub)
182     {
183     sendto_one(source_p, form_str(RPL_TOPICWHOTIME),
184     from, to, chptr->chname,
185     client_p->name, chptr->topic_time);
186     }
187     else
188     {
189     sendto_one(source_p, form_str(RPL_TOPICWHOTIME),
190     from, to, chptr->chname,
191     chptr->topic_info,
192     chptr->topic_time);
193     }
194     }
195     }
196     else
197     {
198     sendto_one(source_p, form_str(ERR_NOTONCHANNEL),
199     from, to, chptr->chname);
200     return;
201     }
202     }
203     }
204     else
205     {
206     sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL),
207     from, to, parv[1]);
208     }
209     }
210    
211     /*
212     * ms_topic
213     * parv[0] = sender prefix
214     * parv[1] = channel name
215     * parv[2] = topic_info
216     * parv[3] = topic_info time
217     * parv[4] = new channel topic
218     *
219     * Let servers always set a topic
220     */
221     static void
222     ms_topic(struct Client *client_p, struct Client *source_p,
223     int parc, char *parv[])
224     {
225     struct Channel *chptr = NULL;
226    
227     if (!IsServer(source_p))
228     {
229     m_topic(client_p, source_p, parc, parv);
230     return;
231     }
232    
233     if (parc < 5)
234     return;
235    
236     if (parv[1] && IsChanPrefix(*parv[1]))
237     {
238     if ((chptr = hash_find_channel(parv[1])) == NULL)
239     return;
240    
241     set_channel_topic(chptr, parv[4], parv[2], atoi(parv[3]));
242    
243     if (ConfigServerHide.hide_servers)
244     {
245     sendto_channel_local(ALL_MEMBERS, NO,
246     chptr, ":%s TOPIC %s :%s",
247     me.name, chptr->chname,
248     chptr->topic == NULL ? "" : chptr->topic);
249    
250     }
251     else
252     {
253     sendto_channel_local(ALL_MEMBERS, NO,
254     chptr, ":%s TOPIC %s :%s",
255     source_p->name,
256     chptr->chname, chptr->topic == NULL ? "" : chptr->topic);
257     }
258     }
259     }

Properties

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