ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/chanserv/topic.C
Revision: 1.1
Committed: Thu Jul 19 08:24:53 2007 UTC (19 years, 2 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Log Message:
initial import. the most important changes since Atheme are:
- fixed many memory leaks
- fixed many bugs
- converted to C++ and use more STL containers
- added a (not very enhanced yet) perl module
- greatly improved XML-RPC speed
- added a JSON-RPC module with code from json-cpp
- added a valgrind memcheck module to operserv
- added a more object oriented base64 implementation
- added a specialised unit test framework
- improved stability
- use gettimeofday() if available
- reworked adding/removing commands
- MemoServ IGNORE DEL can now remove indices

File Contents

# User Rev Content
1 pippijn 1.1 /*
2     * Copyright © 2005 William Pitcock, et al.
3     * Rights to this code are as documented in doc/LICENSE.
4     *
5     * This file contains code for the CService TOPIC functions.
6     *
7     * $Id: topic.c 8019 2007-04-02 09:27:15Z jilles $
8     */
9    
10     #include "atheme.h"
11     #include <account/mychan.h>
12     #include <account/myuser.h>
13     #include <account/chanacs.h>
14    
15     static char const rcsid[] = "$Id";
16    
17     struct cs_topic_listeners : callback::has_listeners
18     {
19     };
20    
21     cs_topic_listeners listeners;
22    
23     DECLARE_MODULE_V1 ("chanserv/topic", false, _modinit, _moddeinit, rcsid, "The Ermyth Team <http://ermyth.schmorp.de>");
24    
25     static void cs_cmd_topic (sourceinfo_t *si, int parc, char *parv[]);
26     static void cs_cmd_topicappend (sourceinfo_t *si, int parc, char *parv[]);
27     static void cs_cmd_topicprepend (sourceinfo_t *si, int parc, char *parv[]);
28    
29     command_t cs_topic = { "TOPIC", N_("Sets a topic on a channel."),
30     AC_NONE, 2, cs_cmd_topic
31     };
32     command_t cs_topicappend = { "TOPICAPPEND", N_("Appends a topic on a channel."),
33     AC_NONE, 2, cs_cmd_topicappend
34     };
35     command_t cs_topicprepend = { "TOPICPREPEND", N_("Prepends a topic on a channel."),
36     AC_NONE, 2, cs_cmd_topicprepend
37     };
38    
39     cmdvec *cs_cmdtree;
40     helpvec *cs_helptree;
41    
42     void
43     _modinit (module_t *m)
44     {
45     MODULE_USE_SYMBOL_T (cs_cmdtree, cmdvec, "chanserv/main", "cs_cmdtree");
46     MODULE_USE_SYMBOL_T (cs_helptree, helpvec, "chanserv/main", "cs_helptree");
47    
48     cs_cmdtree << cs_topic;
49     cs_cmdtree << cs_topicappend;
50     cs_cmdtree << cs_topicprepend;
51    
52     help_addentry (cs_helptree, "TOPIC", "help/cservice/topic", NULL);
53     help_addentry (cs_helptree, "TOPICAPPEND", "help/cservice/topicappend", NULL);
54     help_addentry (cs_helptree, "TOPICPREPEND", "help/cservice/topicprepend", NULL);
55     }
56    
57     void
58     _moddeinit ()
59     {
60     cs_cmdtree >> cs_topic;
61     cs_cmdtree >> cs_topicappend;
62     cs_cmdtree >> cs_topicprepend;
63    
64     help_delentry (cs_helptree, "TOPIC");
65     help_delentry (cs_helptree, "TOPICAPPEND");
66     help_delentry (cs_helptree, "TOPICPREPEND");
67     }
68    
69     static void
70     cs_cmd_topic (sourceinfo_t *si, int parc, char *parv[])
71     {
72     char *chan = parv[0];
73     char *topic = parv[1];
74     mychan_t *mc;
75     channel_t *c;
76     char *topicsetter;
77     time_t prevtopicts;
78    
79     if (!chan || !topic)
80     {
81     command_fail (si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "TOPIC");
82     command_fail (si, fault_needmoreparams, _("Syntax: TOPIC <#channel> <topic>"));
83     return;
84     }
85    
86     mc = mychan_find (chan);
87     if (!mc)
88     {
89     command_fail (si, fault_nosuch_target, _("\2%s\2 is not registered."), chan);
90     return;
91     }
92    
93     c = channel_find (chan);
94     if (!c)
95     {
96     command_fail (si, fault_nosuch_target, _("\2%s\2 is currently empty."), chan);
97     return;
98     }
99    
100     if (mc->find_metadata ("private:close:closer"))
101     {
102     command_fail (si, fault_noprivs, _("\2%s\2 is closed."), chan);
103     return;
104     }
105    
106     if (!chanacs_source_has_flag (mc, si, CA_TOPIC))
107     {
108     command_fail (si, fault_noprivs, _("You are not authorized to perform this operation."));
109     return;
110     }
111    
112     if (si->su != NULL)
113     topicsetter = si->su->nick;
114     else if (si->smu != NULL)
115     topicsetter = si->smu->name;
116     else
117     topicsetter = "unknown";
118     prevtopicts = c->topicts;
119     handle_topic (c, topicsetter, NOW, topic);
120     topic_sts (c, topicsetter, NOW, prevtopicts, topic);
121    
122     logcommand (si, CMDLOG_SET, "%s TOPIC", mc->name);
123     if (!chanuser_find (c, si->su))
124     command_success_nodata (si, _("Topic set to \2%s\2 on \2%s\2."), topic, chan);
125     }
126    
127     static void
128     cs_cmd_topicappend (sourceinfo_t *si, int parc, char *parv[])
129     {
130     char *chan = parv[0];
131     char *topic = parv[1];
132     mychan_t *mc;
133     char topicbuf[BUFSIZE];
134     channel_t *c;
135     char *topicsetter;
136     time_t prevtopicts;
137    
138     if (!chan || !topic)
139     {
140     command_fail (si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "TOPICAPPEND");
141     command_fail (si, fault_needmoreparams, _("Syntax: TOPICAPPEND <#channel> <topic>"));
142     return;
143     }
144    
145     mc = mychan_find (chan);
146     if (!mc)
147     {
148     command_fail (si, fault_nosuch_target, _("\2%s\2 is not registered."), chan);
149     return;
150     }
151    
152     c = channel_find (chan);
153     if (!c)
154     {
155     command_fail (si, fault_nosuch_target, _("\2%s\2 is currently empty."), chan);
156     return;
157     }
158    
159     if (!chanacs_source_has_flag (mc, si, CA_TOPIC))
160     {
161     command_fail (si, fault_noprivs, _("You are not authorized to perform this operation."));
162     return;
163     }
164    
165     if (mc->find_metadata ("private:close:closer"))
166     {
167     command_fail (si, fault_noprivs, _("\2%s\2 is closed."), chan);
168     return;
169     }
170    
171     topicbuf[0] = '\0';
172    
173     if (c->topic)
174     {
175     strlcpy (topicbuf, c->topic, BUFSIZE);
176     strlcat (topicbuf, " | ", BUFSIZE);
177     strlcat (topicbuf, topic, BUFSIZE);
178     }
179     else
180     strlcpy (topicbuf, topic, BUFSIZE);
181    
182     if (si->su != NULL)
183     topicsetter = si->su->nick;
184     else if (si->smu != NULL)
185     topicsetter = si->smu->name;
186     else
187     topicsetter = "unknown";
188     prevtopicts = c->topicts;
189     handle_topic (c, topicsetter, NOW, topicbuf);
190     topic_sts (c, topicsetter, NOW, prevtopicts, topicbuf);
191    
192     logcommand (si, CMDLOG_SET, "%s TOPICAPPEND", mc->name);
193     if (!chanuser_find (c, si->su))
194     command_success_nodata (si, _("Topic set to \2%s\2 on \2%s\2."), c->topic, chan);
195     }
196    
197     static void
198     cs_cmd_topicprepend (sourceinfo_t *si, int parc, char *parv[])
199     {
200     char *chan = parv[0];
201     char *topic = parv[1];
202     mychan_t *mc;
203     char topicbuf[BUFSIZE];
204     channel_t *c;
205     char *topicsetter;
206     time_t prevtopicts;
207    
208     if (!chan || !topic)
209     {
210     command_fail (si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "TOPICPREPEND");
211     command_fail (si, fault_needmoreparams, _("Syntax: TOPICPREPEND <#channel> <topic>"));
212     return;
213     }
214    
215     mc = mychan_find (chan);
216     if (!mc)
217     {
218     command_fail (si, fault_nosuch_target, _("\2%s\2 is not registered."), chan);
219     return;
220     }
221    
222     c = channel_find (chan);
223     if (!c)
224     {
225     command_fail (si, fault_nosuch_target, _("\2%s\2 is currently empty."), chan);
226     return;
227     }
228    
229     if (!chanacs_source_has_flag (mc, si, CA_TOPIC))
230     {
231     command_fail (si, fault_noprivs, _("You are not authorized to perform this operation."));
232     return;
233     }
234    
235     if (mc->find_metadata ("private:close:closer"))
236     {
237     command_fail (si, fault_noprivs, _("\2%s\2 is closed."), chan);
238     return;
239     }
240    
241     topicbuf[0] = '\0';
242    
243     if (c->topic)
244     {
245     strlcpy (topicbuf, topic, BUFSIZE);
246     strlcat (topicbuf, " | ", BUFSIZE);
247     strlcat (topicbuf, c->topic, BUFSIZE);
248     }
249     else
250     strlcpy (topicbuf, topic, BUFSIZE);
251    
252     if (si->su != NULL)
253     topicsetter = si->su->nick;
254     else if (si->smu != NULL)
255     topicsetter = si->smu->name;
256     else
257     topicsetter = "unknown";
258     prevtopicts = c->topicts;
259     handle_topic (c, topicsetter, NOW, topicbuf);
260     topic_sts (c, topicsetter, NOW, prevtopicts, topicbuf);
261    
262     logcommand (si, CMDLOG_SET, "%s TOPICPREPEND", mc->name);
263     if (!chanuser_find (c, si->su))
264     command_success_nodata (si, _("Topic set to \2%s\2 on \2%s\2."), c->topic, chan);
265     }
266    
267     /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
268     * vim:ts=8
269     * vim:sw=8
270     * vim:noexpandtab
271     */