ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/modules/chanserv/info.C
Revision: 1.5
Committed: Tue Aug 28 17:08:07 2007 UTC (19 years, 3 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.4: +20 -36 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 INFO functions.
6 pippijn 1.1 *
7 pippijn 1.5 * $Id: info.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/myuser.h>
13     #include <account/mychan.h>
14    
15 pippijn 1.5 static char const rcsid[] = "$Id: info.C,v 1.4 2007-07-22 18:38:43 pippijn Exp $";
16 pippijn 1.1
17 pippijn 1.5 REGISTER_MODULE ("chanserv/info", false, "The Ermyth Team <http://ermyth.schmorp.de>");
18 pippijn 1.1
19     static void cs_cmd_info (sourceinfo_t *si, int parc, char *parv[]);
20    
21 pippijn 1.5 command_t const cs_info = { "INFO", N_("Displays information on registrations."), AC_NONE, 1, cs_cmd_info };
22 pippijn 1.1
23 pippijn 1.5 E cmdvec cs_cmdtree;
24     E helpvec cs_helptree;
25 pippijn 1.1
26 pippijn 1.5 bool
27     _modinit (module *m)
28 pippijn 1.1 {
29     cs_cmdtree << cs_info;
30 pippijn 1.4 help_addentry (cs_helptree, "INFO", "help/chanserv/info", NULL);
31 pippijn 1.5
32     return true;
33 pippijn 1.1 }
34    
35     void
36     _moddeinit ()
37     {
38     cs_cmdtree >> cs_info;
39     help_delentry (cs_helptree, "INFO");
40     }
41    
42     static void
43     cs_cmd_info (sourceinfo_t *si, int parc, char *parv[])
44     {
45     mychan_t *mc;
46     char *name = parv[0];
47     char buf[BUFSIZE], strfbuf[32];
48     struct tm tm;
49     metadata *md;
50     char *p, *q, *qq;
51     int dir;
52    
53     if (!name)
54     {
55     command_fail (si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "INFO");
56     command_fail (si, fault_needmoreparams, _("Syntax: INFO <#channel>"));
57     return;
58     }
59    
60     if (*name != '#')
61     {
62     command_fail (si, fault_badparams, STR_INVALID_PARAMS, "INFO");
63     command_fail (si, fault_badparams, _("Syntax: INFO <#channel>"));
64     return;
65     }
66    
67     if (!(mc = mychan_find (name)))
68     {
69     command_fail (si, fault_nosuch_target, _("\2%s\2 is not registered."), name);
70     return;
71     }
72    
73     if (!has_priv (si, PRIV_CHAN_AUSPEX) && (md = mc->find_metadata ("private:close:closer")))
74     {
75     command_fail (si, fault_noprivs, _("\2%s\2 has been closed down by the %s administration."), mc->name, me.netname);
76     return;
77     }
78    
79     tm = *localtime (&mc->registered);
80     strftime (strfbuf, sizeof (strfbuf) - 1, "%b %d %H:%M:%S %Y", &tm);
81    
82     command_success_nodata (si, _("Information on \2%s\2:"), mc->name);
83    
84 pippijn 1.5 command_success_nodata (si, _("Founder : %s"), mychan_founder_names(mc));
85 pippijn 1.1
86     command_success_nodata (si, _("Registered : %s (%s ago)"), strfbuf, time_ago (mc->registered));
87    
88     if (NOW - mc->used >= 86400)
89     {
90     tm = *localtime (&mc->used);
91     strftime (strfbuf, sizeof (strfbuf) - 1, "%b %d %H:%M:%S %Y", &tm);
92     command_success_nodata (si, _("Last used : %s (%s ago)"), strfbuf, time_ago (mc->used));
93     }
94    
95     md = mc->find_metadata ("private:mlockext");
96     if (mc->mlock_on || mc->mlock_off || mc->mlock_limit || mc->mlock_key || md)
97     {
98     char params[BUFSIZE];
99    
100     if (md != NULL && strlen (md->value) > 450)
101     {
102     /* Be safe */
103     command_success_nodata (si, _("Mode lock is too long, not entirely shown"));
104     md = NULL;
105     }
106    
107     *buf = 0;
108     *params = 0;
109     dir = MTYPE_NUL;
110    
111     if (mc->mlock_on)
112     {
113     if (dir != MTYPE_ADD)
114     dir = MTYPE_ADD, strcat (buf, "+");
115     strcat (buf, flags_to_string (mc->mlock_on));
116    
117     }
118    
119     if (mc->mlock_limit)
120     {
121     if (dir != MTYPE_ADD)
122     dir = MTYPE_ADD, strcat (buf, "+");
123     strcat (buf, "l");
124     strcat (params, " ");
125     strcat (params, itoa (mc->mlock_limit));
126     }
127    
128     if (mc->mlock_key)
129     {
130     if (dir != MTYPE_ADD)
131     dir = MTYPE_ADD, strcat (buf, "+");
132     strcat (buf, "k");
133     strcat (params, " *");
134     }
135    
136     if (md)
137     {
138     p = md->value;
139     q = buf + strlen (buf);
140     while (*p != '\0')
141     {
142     if (p[1] != ' ' && p[1] != '\0')
143     {
144     if (dir != MTYPE_ADD)
145     dir = MTYPE_ADD, *q++ = '+';
146     *q++ = *p++;
147     strcat (params, " ");
148     qq = params + strlen (params);
149     while (*p != '\0' && *p != ' ')
150     *qq++ = *p++;
151     *qq = '\0';
152     }
153     else
154     {
155     p++;
156     while (*p != '\0' && *p != ' ')
157     p++;
158     }
159     while (*p == ' ')
160     p++;
161     }
162     *q = '\0';
163     }
164    
165     if (mc->mlock_off)
166     {
167     if (dir != MTYPE_DEL)
168     dir = MTYPE_DEL, strcat (buf, "-");
169     strcat (buf, flags_to_string (mc->mlock_off));
170     if (mc->mlock_off & CMODE_LIMIT)
171     strcat (buf, "l");
172     if (mc->mlock_off & CMODE_KEY)
173     strcat (buf, "k");
174     }
175    
176     if (md)
177     {
178     p = md->value;
179     q = buf + strlen (buf);
180     while (*p != '\0')
181     {
182     if (p[1] == ' ' || p[1] == '\0')
183     {
184     if (dir != MTYPE_DEL)
185     dir = MTYPE_DEL, *q++ = '-';
186     *q++ = *p;
187     }
188     p++;
189     while (*p != '\0' && *p != ' ')
190     p++;
191     while (*p == ' ')
192     p++;
193     }
194     *q = '\0';
195     }
196    
197     if (*buf)
198 pippijn 1.5 command_success_nodata (si, _("Mode lock : %s%s"), buf, params);
199 pippijn 1.1 }
200    
201    
202     if ((md = mc->find_metadata ("url")))
203     command_success_nodata (si, "URL : %s", md->value);
204    
205     if ((md = mc->find_metadata ("email")))
206     command_success_nodata (si, "Email : %s", md->value);
207    
208     *buf = '\0';
209    
210     if (MC_HOLD & mc->flags)
211     strcat (buf, "HOLD");
212    
213     if (MC_SECURE & mc->flags)
214     {
215     if (*buf)
216     strcat (buf, " ");
217    
218     strcat (buf, "SECURE");
219     }
220    
221     if (MC_VERBOSE & mc->flags)
222     {
223     if (*buf)
224     strcat (buf, " ");
225    
226     strcat (buf, "VERBOSE");
227     }
228     if (MC_VERBOSE_OPS & mc->flags)
229     {
230     if (*buf)
231     strcat (buf, " ");
232    
233     strcat (buf, "VERBOSE_OPS");
234     }
235    
236     if (MC_STAFFONLY & mc->flags)
237     {
238     if (*buf)
239     strcat (buf, " ");
240    
241     strcat (buf, "STAFFONLY");
242     }
243    
244     if (MC_KEEPTOPIC & mc->flags)
245     {
246     if (*buf)
247     strcat (buf, " ");
248    
249     strcat (buf, "KEEPTOPIC");
250     }
251    
252     if (MC_TOPICLOCK & mc->flags)
253     {
254     if (*buf)
255     strcat (buf, " ");
256    
257     strcat (buf, "TOPICLOCK");
258     }
259    
260     if (MC_GUARD & mc->flags)
261     {
262     if (*buf)
263     strcat (buf, " ");
264    
265     strcat (buf, "GUARD");
266    
267     if (chansvs.fantasy && !mc->find_metadata ("disable_fantasy"))
268     strcat (buf, " FANTASY");
269     }
270    
271     if (*buf)
272     command_success_nodata (si, _("Flags : %s"), buf);
273    
274     if (has_priv (si, PRIV_CHAN_AUSPEX) && (md = mc->find_metadata ("private:mark:setter")))
275     {
276 pippijn 1.5 char const * const setter = md->value;
277 pippijn 1.1 time_t ts;
278    
279     md = mc->find_metadata ("private:mark:reason");
280 pippijn 1.5 char const * const reason = md != NULL ? md->value : "unknown";
281 pippijn 1.1
282     md = mc->find_metadata ("private:mark:timestamp");
283     ts = md != NULL ? atoi (md->value) : 0;
284    
285     tm = *localtime (&ts);
286     strftime (strfbuf, sizeof (strfbuf) - 1, "%b %d %H:%M:%S %Y", &tm);
287    
288     command_success_nodata (si, _("%s was \2MARKED\2 by %s on %s (%s)"), mc->name, setter, strfbuf, reason);
289     }
290    
291     if (has_priv (si, PRIV_CHAN_AUSPEX) && (MC_INHABIT & mc->flags))
292     command_success_nodata (si, _("%s is temporarily holding this channel."), chansvs.nick);
293    
294     if (has_priv (si, PRIV_CHAN_AUSPEX) && (md = mc->find_metadata ("private:close:closer")))
295     {
296 pippijn 1.5 char const * const setter = md->value;
297 pippijn 1.1 time_t ts;
298    
299     md = mc->find_metadata ("private:close:reason");
300 pippijn 1.5 char const * const reason = md != NULL ? md->value : "unknown";
301 pippijn 1.1
302     md = mc->find_metadata ("private:close:timestamp");
303     ts = md != NULL ? atoi (md->value) : 0;
304    
305     tm = *localtime (&ts);
306     strftime (strfbuf, sizeof (strfbuf) - 1, "%b %d %H:%M:%S %Y", &tm);
307    
308     command_success_nodata (si, _("%s was \2CLOSED\2 by %s on %s (%s)"), mc->name, setter, strfbuf, reason);
309     }
310    
311 pippijn 1.5 mc->callback.info (mc, si);
312 pippijn 1.1
313     command_success_nodata (si, _("\2*** End of Info ***\2"));
314     logcommand (si, CMDLOG_GET, "%s INFO", mc->name);
315     }