ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_topic.c
Revision: 1230
Committed: Thu Sep 22 19:41:19 2011 UTC (13 years, 11 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/modules/m_topic.c
File size: 4690 byte(s)
Log Message:
- cleanup module loader. Make module api more flexible

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 "handlers.h"
28     #include "channel.h"
29     #include "channel_mode.h"
30     #include "client.h"
31     #include "hash.h"
32     #include "irc_string.h"
33     #include "sprintf_irc.h"
34     #include "ircd.h"
35     #include "numeric.h"
36     #include "send.h"
37     #include "s_conf.h"
38     #include "s_serv.h"
39     #include "msg.h"
40     #include "parse.h"
41     #include "modules.h"
42     #include "packet.h"
43    
44    
45     /* m_topic()
46     * parv[0] = sender prefix
47     * parv[1] = channel name
48     * parv[2] = new topic, if setting topic
49     */
50     static void
51     m_topic(struct Client *client_p, struct Client *source_p,
52     int parc, char *parv[])
53     {
54     struct Channel *chptr = NULL;
55     const char *from, *to;
56    
57     if (!MyClient(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
58     {
59     from = me.id;
60     to = source_p->id;
61     }
62     else
63     {
64     from = me.name;
65     to = source_p->name;
66     }
67    
68 michael 885 if (EmptyString(parv[1]))
69 adx 30 {
70     sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
71     from, to, "TOPIC");
72     return;
73     }
74    
75     if (MyClient(source_p) && !IsFloodDone(source_p))
76     flood_endgrace(source_p);
77    
78 michael 895 if ((chptr = hash_find_channel(parv[1])) == NULL)
79 adx 30 {
80 michael 895 sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL),
81     from, to, parv[1]);
82     return;
83     }
84    
85     /* setting topic */
86     if (parc > 2)
87     {
88     struct Membership *ms;
89    
90     if ((ms = find_channel_link(source_p, chptr)) == NULL)
91 adx 30 {
92 michael 895 sendto_one(source_p, form_str(ERR_NOTONCHANNEL), from,
93     to, parv[1]);
94 michael 885 return;
95 adx 30 }
96    
97 michael 895 if (!(chptr->mode.mode & MODE_TOPICLIMIT) ||
98     has_member_flags(ms, CHFL_CHANOP|CHFL_HALFOP))
99 adx 30 {
100 michael 895 char topic_info[USERHOST_REPLYLEN];
101 michael 885
102 michael 1203 snprintf(topic_info, sizeof(topic_info), "%s!%s@%s", source_p->name,
103     source_p->username, source_p->host);
104 michael 895 set_channel_topic(chptr, parv[2], topic_info, CurrentTime);
105 adx 30
106 michael 895 sendto_server(client_p, chptr, CAP_TS6, NOCAPS,
107     ":%s TOPIC %s :%s",
108     ID(source_p), chptr->chname,
109 michael 1203 chptr->topic);
110 michael 895 sendto_server(client_p, chptr, NOCAPS, CAP_TS6,
111     ":%s TOPIC %s :%s",
112     source_p->name, chptr->chname,
113 michael 1203 chptr->topic);
114 michael 1011 sendto_channel_local(ALL_MEMBERS, 0,
115 michael 895 chptr, ":%s!%s@%s TOPIC %s :%s",
116     source_p->name,
117     source_p->username,
118     source_p->host,
119 michael 1203 chptr->chname, chptr->topic);
120 adx 30 }
121 michael 895 else
122     sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
123     from, to, chptr->chname);
124     }
125     else /* only asking for topic */
126     {
127     if (!SecretChannel(chptr) || IsMember(source_p, chptr))
128 adx 30 {
129 michael 1203 if (chptr->topic[0] == '\0')
130 michael 895 sendto_one(source_p, form_str(RPL_NOTOPIC),
131     from, to, chptr->chname);
132 adx 30 else
133     {
134 michael 895 sendto_one(source_p, form_str(RPL_TOPIC),
135     from, to,
136     chptr->chname, chptr->topic);
137     sendto_one(source_p, form_str(RPL_TOPICWHOTIME),
138     from, to, chptr->chname,
139     chptr->topic_info,
140     chptr->topic_time);
141 adx 30 }
142     }
143     else
144 michael 895 sendto_one(source_p, form_str(ERR_NOTONCHANNEL),
145     from, to, chptr->chname);
146 adx 30 }
147     }
148 michael 1230
149     static struct Message topic_msgtab = {
150     "TOPIC", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
151     {m_unregistered, m_topic, m_topic, m_ignore, m_topic, m_ignore}
152     };
153    
154     static void
155     module_init(void)
156     {
157     mod_add_cmd(&topic_msgtab);
158     }
159    
160     static void
161     module_exit(void)
162     {
163     mod_del_cmd(&topic_msgtab);
164     }
165    
166     struct module module_entry = {
167     .node = { NULL, NULL, NULL },
168     .name = NULL,
169     .version = "$Revision$",
170     .handle = NULL,
171     .modinit = module_init,
172     .modexit = module_exit,
173     .flags = 0
174     };

Properties

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