ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_topic.c
Revision: 1793
Committed: Sun Mar 31 14:06:08 2013 UTC (11 years ago) by michael
Content type: text/x-csrc
File size: 4614 byte(s)
Log Message:
- Replaced all occurrences of ircsprintf with sprintf/snprintf
  and killed sprintf_irc.(c|h)

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 "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 const char *from, *to;
52
53 if (!MyClient(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
54 {
55 from = me.id;
56 to = source_p->id;
57 }
58 else
59 {
60 from = me.name;
61 to = source_p->name;
62 }
63
64 if (EmptyString(parv[1]))
65 {
66 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
67 from, to, "TOPIC");
68 return;
69 }
70
71 if (MyClient(source_p) && !IsFloodDone(source_p))
72 flood_endgrace(source_p);
73
74 if ((chptr = hash_find_channel(parv[1])) == NULL)
75 {
76 sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL),
77 from, to, parv[1]);
78 return;
79 }
80
81 /* setting topic */
82 if (parc > 2)
83 {
84 struct Membership *ms;
85
86 if ((ms = find_channel_link(source_p, chptr)) == NULL)
87 {
88 sendto_one(source_p, form_str(ERR_NOTONCHANNEL), from,
89 to, parv[1]);
90 return;
91 }
92
93 if (!(chptr->mode.mode & MODE_TOPICLIMIT) ||
94 has_member_flags(ms, CHFL_CHANOP|CHFL_HALFOP))
95 {
96 char topic_info[USERHOST_REPLYLEN];
97
98 snprintf(topic_info, sizeof(topic_info), "%s!%s@%s", source_p->name,
99 source_p->username, source_p->host);
100 set_channel_topic(chptr, parv[2], topic_info, CurrentTime, !!MyClient(source_p));
101
102 sendto_server(client_p, CAP_TS6, NOCAPS,
103 ":%s TOPIC %s :%s",
104 ID(source_p), chptr->chname,
105 chptr->topic);
106 sendto_server(client_p, NOCAPS, CAP_TS6,
107 ":%s TOPIC %s :%s",
108 source_p->name, chptr->chname,
109 chptr->topic);
110 sendto_channel_local(ALL_MEMBERS, 0,
111 chptr, ":%s!%s@%s TOPIC %s :%s",
112 source_p->name,
113 source_p->username,
114 source_p->host,
115 chptr->chname, chptr->topic);
116 }
117 else
118 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
119 from, to, chptr->chname);
120 }
121 else /* only asking for topic */
122 {
123 if (!SecretChannel(chptr) || IsMember(source_p, chptr))
124 {
125 if (chptr->topic[0] == '\0')
126 sendto_one(source_p, form_str(RPL_NOTOPIC),
127 from, to, chptr->chname);
128 else
129 {
130 sendto_one(source_p, form_str(RPL_TOPIC),
131 from, to,
132 chptr->chname, chptr->topic);
133 sendto_one(source_p, form_str(RPL_TOPICWHOTIME),
134 from, to, chptr->chname,
135 chptr->topic_info,
136 chptr->topic_time);
137 }
138 }
139 else
140 sendto_one(source_p, form_str(ERR_NOTONCHANNEL),
141 from, to, chptr->chname);
142 }
143 }
144
145 static struct Message topic_msgtab = {
146 "TOPIC", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
147 {m_unregistered, m_topic, m_topic, m_ignore, m_topic, m_ignore}
148 };
149
150 static void
151 module_init(void)
152 {
153 mod_add_cmd(&topic_msgtab);
154 }
155
156 static void
157 module_exit(void)
158 {
159 mod_del_cmd(&topic_msgtab);
160 }
161
162 struct module module_entry = {
163 .node = { NULL, NULL, NULL },
164 .name = NULL,
165 .version = "$Revision$",
166 .handle = NULL,
167 .modinit = module_init,
168 .modexit = module_exit,
169 .flags = 0
170 };

Properties

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