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

File Contents

# User Rev Content
1 pippijn 1.7 /**
2     * mark.C: Marking for channels.
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
10 pippijn 1.2 * Rights to this code are as documented in doc/pod/license.pod.
11 pippijn 1.1 *
12 pippijn 1.7 * $Id: mark.C,v 1.6 2007-08-30 19:56:22 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/mychan.h>
18    
19 pippijn 1.7 static char const rcsid[] = "$Id: mark.C,v 1.6 2007-08-30 19:56:22 pippijn Exp $";
20 pippijn 1.1
21 pippijn 1.5 REGISTER_MODULE ("chanserv/mark", false, "The Ermyth Team <http://ermyth.schmorp.de>");
22 pippijn 1.1
23     static void cs_cmd_mark (sourceinfo_t *si, int parc, char *parv[]);
24    
25 pippijn 1.5 command_t const cs_mark = { "MARK", N_("Adds a note to a channel."), PRIV_MARK, 3, cs_cmd_mark };
26 pippijn 1.1
27 pippijn 1.5 E cmdvec cs_cmdtree;
28     E helpvec cs_helptree;
29 pippijn 1.1
30 pippijn 1.5 bool
31     _modinit (module *m)
32 pippijn 1.1 {
33     cs_cmdtree << cs_mark;
34 pippijn 1.4 help_addentry (cs_helptree, "MARK", "help/chanserv/mark", NULL);
35 pippijn 1.5
36     return true;
37 pippijn 1.1 }
38    
39     void
40     _moddeinit ()
41     {
42     cs_cmdtree >> cs_mark;
43     help_delentry (cs_helptree, "MARK");
44     }
45    
46     static void
47     cs_cmd_mark (sourceinfo_t *si, int parc, char *parv[])
48     {
49     char *target = parv[0];
50     char *action = parv[1];
51     char *info = parv[2];
52     mychan_t *mc;
53    
54     if (!target || !action)
55     {
56 pippijn 1.6 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "MARK");
57     command_fail (si, fault::needmoreparams, _("Usage: MARK <#channel> <ON|OFF> [note]"));
58 pippijn 1.1 return;
59     }
60    
61     if (target[0] != '#')
62     {
63 pippijn 1.6 command_fail (si, fault::badparams, STR_INVALID_PARAMS, "MARK");
64 pippijn 1.1 return;
65     }
66    
67 pippijn 1.6 if (!(mc = mychan_t::find (target)))
68 pippijn 1.1 {
69 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), target);
70 pippijn 1.1 return;
71     }
72    
73     if (!strcasecmp (action, "ON"))
74     {
75     if (!info)
76     {
77 pippijn 1.6 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "MARK");
78     command_fail (si, fault::needmoreparams, _("Usage: MARK <#channel> ON <note>"));
79 pippijn 1.1 return;
80     }
81    
82     if (mc->find_metadata ("private:mark:setter"))
83     {
84 pippijn 1.6 command_fail (si, fault::nochange, _("\2%s\2 is already marked."), target);
85 pippijn 1.1 return;
86     }
87    
88     mc->add_metadata ("private:mark:setter", get_oper_name (si));
89     mc->add_metadata ("private:mark:reason", info);
90     mc->add_metadata ("private:mark:timestamp", itoa (NOW));
91    
92     wallops ("%s marked the channel \2%s\2.", get_oper_name (si), target);
93     logcommand (si, CMDLOG_ADMIN, "%s MARK ON", mc->name);
94     command_success_nodata (si, _("\2%s\2 is now marked."), target);
95     }
96     else if (!strcasecmp (action, "OFF"))
97     {
98     if (!mc->find_metadata ("private:mark:setter"))
99     {
100 pippijn 1.6 command_fail (si, fault::nochange, _("\2%s\2 is not marked."), target);
101 pippijn 1.1 return;
102     }
103    
104     mc->del_metadata ("private:mark:setter");
105     mc->del_metadata ("private:mark:reason");
106     mc->del_metadata ("private:mark:timestamp");
107    
108     wallops ("%s unmarked the channel \2%s\2.", get_oper_name (si), target);
109     logcommand (si, CMDLOG_ADMIN, "%s MARK OFF", mc->name);
110     command_success_nodata (si, _("\2%s\2 is now unmarked."), target);
111     }
112     else
113     {
114 pippijn 1.6 command_fail (si, fault::badparams, STR_INVALID_PARAMS, "MARK");
115     command_fail (si, fault::badparams, _("Usage: MARK <#channel> <ON|OFF> [note]"));
116 pippijn 1.1 }
117     }
118    
119     /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
120     * vim:ts=8
121     * vim:sw=8
122     * vim:noexpandtab
123     */