ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/modules/contrib/cs_sync.C
Revision: 1.1
Committed: Thu Jul 19 08:24:53 2007 UTC (19 years, 3 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Log Message:
initial import. the most important changes since Atheme are:
- fixed many memory leaks
- fixed many bugs
- converted to C++ and use more STL containers
- added a (not very enhanced yet) perl module
- greatly improved XML-RPC speed
- added a JSON-RPC module with code from json-cpp
- added a valgrind memcheck module to operserv
- added a more object oriented base64 implementation
- added a specialised unit test framework
- improved stability
- use gettimeofday() if available
- reworked adding/removing commands
- MemoServ IGNORE DEL can now remove indices

File Contents

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