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