ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/chanserv/topic.C
Revision: 1.5
Committed: Tue Aug 28 17:08:09 2007 UTC (19 years, 1 month ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.4: +21 -39 lines
Log Message:
- changed name
- updated the example config to the new system
- added more documentation
- enhanced documentation generators
- added a link to the pdf to the website
- added an RSS feed generator
- transitioned hooks to c++ callbacks
- did various merges with upstream along the way
- added const where appropriate
- removed the old block allocator
- fixed most memory leaks
- transitioned some dictionaries to std::map
- transitioned some lists to std::vector
- made some free functions members where appropriate
- renamed string to dynstr and added a static string ststr
- use NOW instead of time (NULL) if possible
- completely reworked database backends, crypto handlers and protocol handlers
  to use an object factory
- removed the old module system. ermyth does not do any dynamic loading anymore
- fixed most of the build system
- reworked how protocol commands work

File Contents

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