ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/modules/contrib/cs_sync.C
Revision: 1.3
Committed: Tue Aug 28 17:08:09 2007 UTC (19 years, 2 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.2: +18 -16 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.3 * Copyright © 2006 Atheme Development Group
3 pippijn 1.2 * Rights to this code are as documented in doc/pod/license.pod.
4 pippijn 1.1 *
5 pippijn 1.3 * This file contains code for the ChanServ SYNC functions.
6 pippijn 1.1 *
7 pippijn 1.3 * $Id: cs_sync.C,v 1.2 2007-07-21 01:29:08 pippijn Exp $
8 pippijn 1.1 */
9    
10     #include "atheme.h"
11 pippijn 1.3 #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.3 static char const rcsid[] = "$Id$";
17    
18     REGISTER_MODULE ("chanserv/sync", false, "The Ermyth Team <http://ermyth.schmorp.de>");
19 pippijn 1.1
20     static void cs_cmd_sync (sourceinfo_t *si, int parc, char *parv[]);
21    
22 pippijn 1.3 command_t const cs_sync = { "SYNC", "Forces channel statuses to flags.", AC_NONE, 1, cs_cmd_sync };
23 pippijn 1.1
24 pippijn 1.3 E cmdvec cs_cmdtree;
25     E helpvec cs_helptree;
26 pippijn 1.1
27 pippijn 1.3 bool
28     _modinit (module *m)
29 pippijn 1.1 {
30 pippijn 1.3 cs_cmdtree << cs_sync;
31     help_addentry (cs_helptree, "SYNC", "help/chanserv/sync", NULL);
32 pippijn 1.1
33 pippijn 1.3 return true;
34 pippijn 1.1 }
35    
36     void
37     _moddeinit ()
38     {
39     cs_cmdtree >> cs_sync;
40     help_delentry (cs_helptree, "SYNC");
41     }
42    
43     static void
44     cs_cmd_sync (sourceinfo_t *si, int parc, char *parv[])
45     {
46     chanuser_t *cu;
47     mychan_t *mc;
48     node_t *n, *tn;
49     char *name = parv[0];
50     int fl;
51    
52     if (!name)
53     {
54     command_fail (si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "SYNC");
55     command_fail (si, fault_needmoreparams, "Syntax: SYNC <#channel>");
56     return;
57     }
58    
59     if (!(mc = mychan_find (name)))
60     {
61     command_fail (si, fault_nosuch_target, "\2%s\2 is not registered.", name);
62     return;
63     }
64    
65     if (mc->find_metadata ("private:close:closer"))
66     {
67     command_fail (si, fault_noprivs, "\2%s\2 is closed.", name);
68     return;
69     }
70    
71     if (!mc->chan)
72     {
73     command_fail (si, fault_nosuch_target, "\2%s\2 does not exist.", name);
74     return;
75     }
76    
77     if (!chanacs_source_has_flag (mc, si, CA_RECOVER))
78     {
79     command_fail (si, fault_noprivs, "You are not authorized to perform this operation.");
80     return;
81     }
82    
83     verbose (mc, "\2%s\2 used SYNC.", get_source_name (si));
84     logcommand (si, CMDLOG_SET, "%s SYNC", mc->name);
85    
86     LIST_FOREACH_SAFE (n, tn, mc->chan->members.head)
87     {
88     cu = (chanuser_t *) n->data;
89    
90     if (is_internal_client (cu->user))
91     continue;
92    
93     fl = chanacs_user_flags (mc, cu->user);
94     if (fl & CA_AKICK && !(fl & CA_REMOVE))
95     {
96     if (mc->chan->nummembers <= (mc->flags & MC_GUARD ? 2 : 1))
97     {
98     mc->flags |= MC_INHABIT;
99     if (!(mc->flags & MC_GUARD))
100     join (mc->name, chansvs.nick);
101     }
102     /* XXX duplicate the whole thing in cs_join()? */
103 pippijn 1.3 phandler->kick (chansvs.nick, mc->name, cu->user->nick, "User is banned from this channel");
104 pippijn 1.1 continue;
105     }
106     if (ircd->uses_owner)
107     {
108 pippijn 1.3 if (cu->user->myuser->should_owner (mc))
109 pippijn 1.1 {
110     if (!(ircd->owner_mode & cu->modes))
111     {
112     modestack_mode_param (chansvs.nick, mc->chan, MTYPE_ADD, ircd->owner_mchar[1], CLIENT_NAME (cu->user));
113     cu->modes |= ircd->owner_mode;
114     }
115     }
116     else if (ircd->owner_mode & cu->modes)
117     {
118     modestack_mode_param (chansvs.nick, mc->chan, MTYPE_DEL, ircd->owner_mchar[1], CLIENT_NAME (cu->user));
119     cu->modes &= ~ircd->owner_mode;
120     }
121     }
122     if (ircd->uses_protect)
123     {
124 pippijn 1.3 if (cu->user->myuser->should_protect (mc))
125 pippijn 1.1 {
126     if (!(ircd->protect_mode & cu->modes))
127     {
128     modestack_mode_param (chansvs.nick, mc->chan, MTYPE_ADD, ircd->protect_mchar[1], CLIENT_NAME (cu->user));
129     cu->modes |= ircd->protect_mode;
130     }
131     }
132     else if (ircd->protect_mode & cu->modes)
133     {
134     modestack_mode_param (chansvs.nick, mc->chan, MTYPE_DEL, ircd->protect_mchar[1], CLIENT_NAME (cu->user));
135     cu->modes &= ~ircd->protect_mode;
136     }
137     }
138     if (fl & (CA_AUTOOP | CA_OP))
139     {
140     if (fl & CA_AUTOOP && !(CMODE_OP & cu->modes))
141     {
142     modestack_mode_param (chansvs.nick, mc->chan, MTYPE_ADD, 'o', CLIENT_NAME (cu->user));
143     cu->modes |= CMODE_OP;
144     }
145     continue;
146     }
147     if ((CMODE_OP & cu->modes))
148     {
149     modestack_mode_param (chansvs.nick, mc->chan, MTYPE_DEL, 'o', CLIENT_NAME (cu->user));
150     cu->modes &= ~CMODE_OP;
151     }
152     if (ircd->uses_halfops)
153     {
154     if (fl & (CA_AUTOHALFOP | CA_HALFOP))
155     {
156     if (fl & CA_AUTOHALFOP && !(ircd->halfops_mode & cu->modes))
157     {
158     modestack_mode_param (chansvs.nick, mc->chan, MTYPE_ADD, ircd->halfops_mchar[1], CLIENT_NAME (cu->user));
159     cu->modes |= ircd->halfops_mode;
160     }
161     continue;
162     }
163     if (ircd->halfops_mode & cu->modes)
164     {
165     modestack_mode_param (chansvs.nick, mc->chan, MTYPE_DEL, ircd->halfops_mchar[1], CLIENT_NAME (cu->user));
166     cu->modes &= ~ircd->halfops_mode;
167     }
168     }
169     if (fl & (CA_AUTOVOICE | CA_VOICE))
170     {
171     if (fl & CA_AUTOVOICE && !(CMODE_VOICE & cu->modes))
172     {
173     modestack_mode_param (chansvs.nick, mc->chan, MTYPE_ADD, 'v', CLIENT_NAME (cu->user));
174     cu->modes |= CMODE_VOICE;
175     }
176     continue;
177     }
178     if ((CMODE_VOICE & cu->modes))
179     {
180     modestack_mode_param (chansvs.nick, mc->chan, MTYPE_DEL, 'v', CLIENT_NAME (cu->user));
181     cu->modes &= ~CMODE_VOICE;
182     }
183     }
184    
185     command_success_nodata (si, "Sync complete for \2%s\2.", mc->name);
186     }
187    
188     /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
189     * vim:ts=8
190     * vim:sw=8
191     * vim:noexpandtab
192     */