Anope IRC Services  Version 1.8
os_clearmodes.c
Go to the documentation of this file.
1 /* OperServ core functions
2  *
3  * (C) 2003-2014 Anope Team
4  * Contact us at team@anope.org
5  *
6  * Please read COPYING and README for further details.
7  *
8  * Based on the original code of Epona by Lara.
9  * Based on the original code of Services by Andy Church.
10  *
11  *
12  */
13 /*************************************************************************/
14 
15 #include "module.h"
16 
17 static int do_clearmodes(User * u);
18 static void myOperServHelp(User * u);
19 
26 int AnopeInit(int argc, char **argv)
27 {
28  Command *c;
29 
30  moduleAddAuthor("Anope");
32  (VERSION_STRING);
34 
35  c = createCommand("CLEARMODES", do_clearmodes, is_services_oper,
36  OPER_HELP_CLEARMODES, -1, -1, -1, -1);
38 
40 
41  return MOD_CONT;
42 }
43 
47 void AnopeFini(void)
48 {
49 
50 }
51 
52 
57 static void myOperServHelp(User * u)
58 {
59  if (is_services_oper(u)) {
60  notice_lang(s_OperServ, u, OPER_HELP_CMD_CLEARMODES);
61  }
62 }
63 
69 static int do_clearmodes(User * u)
70 {
71  char *s;
72  char *argv[2];
73  char *chan = strtok(NULL, " ");
74  Channel *c;
75  int all = 0;
76  struct c_userlist *cu, *next;
77  Entry *entry, *nexte;
78 
79  if (!chan) {
80  syntax_error(s_OperServ, u, "CLEARMODES", OPER_CLEARMODES_SYNTAX);
81  return MOD_CONT;
82  } else if (!(c = findchan(chan))) {
83  notice_lang(s_OperServ, u, CHAN_X_NOT_IN_USE, chan);
84  return MOD_CONT;
85  } else if (c->bouncy_modes) {
86  notice_lang(s_OperServ, u, OPER_BOUNCY_MODES_U_LINE);
87  return MOD_CONT;
88  } else {
89  s = strtok(NULL, " ");
90  if (s) {
91  if (stricmp(s, "ALL") == 0) {
92  all = 1;
93  } else {
94  syntax_error(s_OperServ, u, "CLEARMODES",
95  OPER_CLEARMODES_SYNTAX);
96  return MOD_CONT;
97  }
98  }
99 
100  if (WallOSClearmodes) {
101  anope_cmd_global(s_OperServ, "%s used CLEARMODES%s on %s",
102  u->nick, all ? " ALL" : "", chan);
103  }
104  if (all) {
105  /* Clear mode +o */
106  if (ircd->svsmode_ucmode) {
107  anope_cmd_svsmode_chan(c->name, "-o", NULL);
108  for (cu = c->users; cu; cu = next) {
109  next = cu->next;
110  if (!chan_has_user_status(c, cu->user, CUS_OP)) {
111  continue;
112  }
113  argv[0] = sstrdup("-o");
114  argv[1] = GET_USER(cu->user);
115  chan_set_modes(s_OperServ, c, 2, argv, 0);
116  free(argv[0]);
117  }
118  } else {
119  for (cu = c->users; cu; cu = next) {
120  next = cu->next;
121  if (!chan_has_user_status(c, cu->user, CUS_OP))
122  continue;
123  argv[0] = sstrdup("-o");
124  argv[1] = GET_USER(cu->user);
125  anope_cmd_mode(s_OperServ, c->name, "-o %s",
126  cu->user->nick);
127  chan_set_modes(s_OperServ, c, 2, argv, 0);
128  free(argv[0]);
129  }
130  }
131 
132  if (ircd->svsmode_ucmode) {
133  anope_cmd_svsmode_chan(c->name, "-v", NULL);
134  for (cu = c->users; cu; cu = next) {
135  next = cu->next;
136  if (!chan_has_user_status(c, cu->user, CUS_VOICE)) {
137  continue;
138  }
139  argv[0] = sstrdup("-v");
140  argv[1] = GET_USER(cu->user);
141  chan_set_modes(s_OperServ, c, 2, argv, 0);
142  free(argv[0]);
143  }
144  } else {
145  /* Clear mode +v */
146  for (cu = c->users; cu; cu = next) {
147  next = cu->next;
148  if (!chan_has_user_status(c, cu->user, CUS_VOICE))
149  continue;
150  argv[0] = sstrdup("-v");
151  argv[1] = GET_USER(cu->user);
152  anope_cmd_mode(s_OperServ, c->name, "-v %s",
153  cu->user->nick);
154  chan_set_modes(s_OperServ, c, 2, argv, 0);
155  free(argv[0]);
156  }
157  }
158 
159  /* Clear mode +h */
160  if (ircd->svsmode_ucmode && ircd->halfop) {
161  anope_cmd_svsmode_chan(c->name, "-h", NULL);
162  for (cu = c->users; cu; cu = next) {
163  next = cu->next;
164  if (!chan_has_user_status(c, cu->user, CUS_HALFOP)) {
165  continue;
166  }
167  argv[0] = sstrdup("-h");
168  argv[1] = GET_USER(cu->user);
169  chan_set_modes(s_OperServ, c, 2, argv, 0);
170  free(argv[0]);
171  }
172  } else {
173  for (cu = c->users; cu; cu = next) {
174  next = cu->next;
175  if (!chan_has_user_status(c, cu->user, CUS_HALFOP))
176  continue;
177  argv[0] = sstrdup("-h");
178  argv[1] = GET_USER(cu->user);
179  anope_cmd_mode(s_OperServ, c->name, "-h %s",
180  cu->user->nick);
181  chan_set_modes(s_OperServ, c, 2, argv, 0);
182  free(argv[0]);
183  }
184  }
185  /* Clear mode Owners */
186  if (ircd->svsmode_ucmode && ircd->owner) {
188  for (cu = c->users; cu; cu = next) {
189  next = cu->next;
190  if (!chan_has_user_status(c, cu->user, CUS_HALFOP)) {
191  continue;
192  }
193  argv[0] = sstrdup(ircd->ownerunset);
194  argv[1] = GET_USER(cu->user);
195  chan_set_modes(s_OperServ, c, 2, argv, 0);
196  free(argv[0]);
197  }
198  } else {
199  for (cu = c->users; cu; cu = next) {
200  next = cu->next;
201  if (!chan_has_user_status(c, cu->user, CUS_OWNER))
202  continue;
203  argv[0] = sstrdup(ircd->ownerunset);
204  argv[1] = GET_USER(cu->user);
205  anope_cmd_mode(s_OperServ, c->name, "%s %s",
206  ircd->ownerunset, cu->user->nick);
207  chan_set_modes(s_OperServ, c, 2, argv, 0);
208  free(argv[0]);
209  }
210  }
211  /* Clear mode protected or admins */
212  if (ircd->svsmode_ucmode && (ircd->protect || ircd->admin)) {
213 
215  for (cu = c->users; cu; cu = next) {
216  next = cu->next;
217  if (!chan_has_user_status(c, cu->user, CUS_HALFOP)) {
218  continue;
219  }
220  argv[0] = sstrdup(ircd->adminunset);
221  argv[1] = GET_USER(cu->user);
222  chan_set_modes(s_OperServ, c, 2, argv, 0);
223  free(argv[0]);
224  }
225  } else {
226  for (cu = c->users; cu; cu = next) {
227  next = cu->next;
228  if (!chan_has_user_status(c, cu->user, CUS_PROTECT))
229  continue;
230  argv[0] = sstrdup(ircd->adminunset);
231  argv[1] = GET_USER(cu->user);
232  anope_cmd_mode(s_OperServ, c->name, "%s %s",
233  ircd->adminunset, cu->user->nick);
234  chan_set_modes(s_OperServ, c, 2, argv, 0);
235  free(argv[0]);
236  }
237  }
238 
239 
240  }
241 
242  if (c->mode) {
243  /* Clear modes the bulk of the modes */
245  argv[0] = sstrdup(ircd->modestoremove);
246  chan_set_modes(s_OperServ, c, 1, argv, 0);
247  free(argv[0]);
248 
249  /* to prevent the internals from complaining send -k, -L, -f by themselves if we need
250  to send them - TSL */
251  if (c->key) {
252  anope_cmd_mode(s_OperServ, c->name, "-k %s", c->key);
253  argv[0] = sstrdup("-k");
254  argv[1] = c->key;
255  chan_set_modes(s_OperServ, c, 2, argv, 0);
256  free(argv[0]);
257  }
258  if (ircd->Lmode && c->redirect) {
259  anope_cmd_mode(s_OperServ, c->name, "-L %s", c->redirect);
260  argv[0] = sstrdup("-L");
261  argv[1] = c->redirect;
262  chan_set_modes(s_OperServ, c, 2, argv, 0);
263  free(argv[0]);
264  }
265  if (ircd->fmode && c->flood) {
267  anope_cmd_mode(s_OperServ, c->name, "%s %s",
269  argv[0] = sstrdup(flood_mode_char_remove);
270  argv[1] = c->flood;
271  chan_set_modes(s_OperServ, c, 2, argv, 0);
272  free(argv[0]);
273  } else {
274  if (debug) {
275  alog("debug: flood_mode_char_remove was not set unable to remove flood/throttle modes");
276  }
277  }
278  }
279  }
280 
281  /* Clear bans */
282  if (c->bans && c->bans->count) {
283  for (entry = c->bans->entries; entry; entry = nexte) {
284  nexte = entry->next;
285  argv[0] = sstrdup("-b");
286  argv[1] = sstrdup(entry->mask);
287  anope_cmd_mode(s_OperServ, c->name, "-b %s", entry->mask);
288  chan_set_modes(s_OperServ, c, 2, argv, 0);
289  free(argv[0]);
290  free(argv[1]);
291  }
292  }
293 
294  /* Clear excepts */
295  if (ircd->except && c->excepts && c->excepts->count) {
296  for (entry = c->excepts->entries; entry; entry = nexte) {
297  nexte = entry->next;
298  argv[0] = sstrdup("-e");
299  argv[1] = sstrdup(entry->mask);
300  anope_cmd_mode(s_OperServ, c->name, "-e %s", entry->mask);
301  chan_set_modes(s_OperServ, c, 2, argv, 0);
302  free(argv[0]);
303  free(argv[1]);
304  }
305  }
306 
307  /* Clear invites */
308  if (ircd->invitemode && c->invites && c->invites->count) {
309  for (entry = c->invites->entries; entry; entry = nexte) {
310  nexte = entry->next;
311  argv[0] = sstrdup("-I");
312  argv[1] = sstrdup(entry->mask);
313  anope_cmd_mode(s_OperServ, c->name, "-I %s", entry->mask);
314  chan_set_modes(s_OperServ, c, 2, argv, 0);
315  free(argv[0]);
316  free(argv[1]);
317  }
318  }
319  }
320 
321  if (all) {
322  notice_lang(s_OperServ, u, OPER_CLEARMODES_ALL_DONE, chan);
323  } else {
324  notice_lang(s_OperServ, u, OPER_CLEARMODES_DONE, chan);
325  }
326  return MOD_CONT;
327 }
EList * invites
Definition: services.h:1014
E int WallOSClearmodes
Definition: extern.h:452
char nick[NICKMAX]
Definition: services.h:875
E int chan_has_user_status(Channel *chan, User *user, int16 status)
Definition: channels.c:124
int Lmode
Definition: services.h:350
E IRCDVar * ircd
Definition: extern.h:39
Entry * next
Definition: services.h:1038
static void myOperServHelp(User *u)
Definition: os_clearmodes.c:57
E int stricmp(const char *s1, const char *s2)
Definition: compat.c:58
char * redirect
Definition: services.h:1009
void AnopeFini(void)
Definition: os_clearmodes.c:47
int32 count
Definition: services.h:1034
E void chan_set_modes(const char *source, Channel *chan, int ac, char **av, int check)
Definition: channels.c:161
#define CUS_VOICE
Definition: services.h:1342
MDE void moduleAddAuthor(const char *author)
Definition: modules.c:1772
E void syntax_error(char *service, User *u, const char *command, int msgnum)
Definition: language.c:295
char * modestoremove
Definition: services.h:298
int except
Definition: services.h:320
E void notice_lang(char *source, User *dest, int message,...)
Definition: send.c:169
MDE void moduleSetType(MODType type)
Definition: modules.c:818
char * ownerunset
Definition: services.h:304
E Channel * findchan(const char *chan)
Definition: channels.c:394
int16 bouncy_modes
Definition: services.h:1028
E char * sstrdup(const char *s)
Definition: memory.c:105
E void anope_cmd_svsmode_chan(char *name, char *mode, char *nick)
Definition: ircd.c:599
#define OPERSERV
Definition: modules.h:62
E char * s_OperServ
Definition: extern.h:289
int invitemode
Definition: services.h:359
EList * excepts
Definition: services.h:1013
Definition: services.h:1037
char * key
Definition: services.h:1008
uint32 mode
Definition: services.h:1006
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
static int do_clearmodes(User *u)
Definition: os_clearmodes.c:69
#define CUS_HALFOP
Definition: services.h:1343
E char * flood_mode_char_remove
Definition: extern.h:42
int svsmode_ucmode
Definition: services.h:363
#define CUS_PROTECT
Definition: services.h:1345
Command * c
Definition: ns_recover.c:17
int protect
Definition: services.h:333
E void alog(const char *fmt,...) FORMAT(printf
MDE void moduleSetOperHelp(void(*func)(User *u))
Definition: modules.c:2126
#define MOD_CONT
Definition: modules.h:54
E int debug
Definition: extern.h:775
char * adminunset
Definition: services.h:306
#define CUS_OWNER
Definition: services.h:1344
EList * bans
Definition: services.h:1012
E void anope_cmd_mode(char *source, char *dest, const char *fmt,...)
Definition: ircd.c:211
Definition: modules.h:99
MDE Command * createCommand(const char *name, int(*func)(User *u), int(*has_priv)(User *u), int help_all, int help_reg, int help_oper, int help_admin, int help_root)
Definition: modules.c:987
int AnopeInit(int argc, char **argv)
Definition: os_clearmodes.c:26
char * flood
Definition: services.h:1010
Entry * entries
Definition: services.h:1033
int admin
Definition: services.h:324
char name[CHANMAX]
Definition: services.h:1000
#define GET_USER(u)
Definition: services.h:270
E int is_services_oper(User *u)
Definition: operserv.c:606
int owner
Definition: services.h:302
char * mask
Definition: services.h:1042
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
int halfop
Definition: services.h:316
#define CUS_OP
Definition: services.h:1341
int fmode
Definition: services.h:349
#define MOD_UNIQUE
Definition: module.h:11
E void anope_cmd_global(char *source, const char *fmt,...)
Definition: ircd.c:506
struct channel_::c_userlist * users