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

File Contents

# Content
1 /*
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 * $Id$
23 */
24
25 #include "stdinc.h"
26 #include "list.h"
27 #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 if (EmptyString(parv[1]))
69 {
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 if ((chptr = hash_find_channel(parv[1])) == NULL)
79 {
80 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 {
92 sendto_one(source_p, form_str(ERR_NOTONCHANNEL), from,
93 to, parv[1]);
94 return;
95 }
96
97 if (!(chptr->mode.mode & MODE_TOPICLIMIT) ||
98 has_member_flags(ms, CHFL_CHANOP|CHFL_HALFOP))
99 {
100 char topic_info[USERHOST_REPLYLEN];
101
102 snprintf(topic_info, sizeof(topic_info), "%s!%s@%s", source_p->name,
103 source_p->username, source_p->host);
104 set_channel_topic(chptr, parv[2], topic_info, CurrentTime);
105
106 sendto_server(client_p, chptr, CAP_TS6, NOCAPS,
107 ":%s TOPIC %s :%s",
108 ID(source_p), chptr->chname,
109 chptr->topic);
110 sendto_server(client_p, chptr, NOCAPS, CAP_TS6,
111 ":%s TOPIC %s :%s",
112 source_p->name, chptr->chname,
113 chptr->topic);
114 sendto_channel_local(ALL_MEMBERS, 0,
115 chptr, ":%s!%s@%s TOPIC %s :%s",
116 source_p->name,
117 source_p->username,
118 source_p->host,
119 chptr->chname, chptr->topic);
120 }
121 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 {
129 if (chptr->topic[0] == '\0')
130 sendto_one(source_p, form_str(RPL_NOTOPIC),
131 from, to, chptr->chname);
132 else
133 {
134 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 }
142 }
143 else
144 sendto_one(source_p, form_str(ERR_NOTONCHANNEL),
145 from, to, chptr->chname);
146 }
147 }
148
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