ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/chanserv/mark.C
Revision: 1.8
Committed: Sat Sep 22 14:27:27 2007 UTC (19 years, 2 months ago) by pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +5 -3 lines
Log Message:
split up ermyth into ermyth-modules, libermyth (currently just ermyth-util) and ermyth-core

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