ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/modules/chanserv/info.C
Revision: 1.8
Committed: Sun Sep 16 18:54:42 2007 UTC (19 years, 2 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.7: +10 -5 lines
Log Message:
#defines to enum

File Contents

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