Anope IRC Services  Version 1.8
bs_kick.c
Go to the documentation of this file.
1 /* BotServ 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_kickcmd(User * u);
18 
19 static void myBotServHelp(User * u);
20 
27 int AnopeInit(int argc, char **argv)
28 {
29  Command *c;
30 
31  moduleAddAuthor("Anope");
32  moduleAddVersion(VERSION_STRING);
34  c = createCommand("KICK", do_kickcmd, NULL, BOT_HELP_KICK, -1, -1, -1,
35  -1);
37  c = createCommand("KICK BADWORDS", NULL, NULL, BOT_HELP_KICK_BADWORDS,
38  -1, -1, -1, -1);
40  c = createCommand("KICK BOLDS", NULL, NULL, BOT_HELP_KICK_BOLDS, -1,
41  -1, -1, -1);
43  c = createCommand("KICK CAPS", NULL, NULL, BOT_HELP_KICK_CAPS, -1, -1,
44  -1, -1);
46  c = createCommand("KICK COLORS", NULL, NULL, BOT_HELP_KICK_COLORS, -1,
47  -1, -1, -1);
49  c = createCommand("KICK FLOOD", NULL, NULL, BOT_HELP_KICK_FLOOD, -1,
50  -1, -1, -1);
52  c = createCommand("KICK REPEAT", NULL, NULL, BOT_HELP_KICK_REPEAT, -1,
53  -1, -1, -1);
55  c = createCommand("KICK REVERSES", NULL, NULL, BOT_HELP_KICK_REVERSES,
56  -1, -1, -1, -1);
58  c = createCommand("KICK UNDERLINES", NULL, NULL,
59  BOT_HELP_KICK_UNDERLINES, -1, -1, -1, -1);
61 
62 
64 
65  return MOD_CONT;
66 }
67 
71 void AnopeFini(void)
72 {
73 
74 }
75 
76 
77 
82 static void myBotServHelp(User * u)
83 {
84  notice_lang(s_BotServ, u, BOT_HELP_CMD_KICK);
85 }
86 
92 static int do_kickcmd(User * u)
93 {
94  char *chan = strtok(NULL, " ");
95  char *option = strtok(NULL, " ");
96  char *value = strtok(NULL, " ");
97  char *ttb = strtok(NULL, " ");
98 
99  ChannelInfo *ci;
100 
101  if (readonly)
102  notice_lang(s_BotServ, u, BOT_KICK_DISABLED);
103  else if (!chan || !option || !value)
104  syntax_error(s_BotServ, u, "KICK", BOT_KICK_SYNTAX);
105  else if (stricmp(value, "ON") && stricmp(value, "OFF"))
106  syntax_error(s_BotServ, u, "KICK", BOT_KICK_SYNTAX);
107  else if (!(ci = cs_findchan(chan)))
108  notice_lang(s_BotServ, u, CHAN_X_NOT_REGISTERED, chan);
109  else if (ci->flags & CI_VERBOTEN)
110  notice_lang(s_BotServ, u, CHAN_X_FORBIDDEN, chan);
111  else if (!is_services_admin(u) && !check_access(u, ci, CA_SET))
112  notice_lang(s_BotServ, u, ACCESS_DENIED);
113  else if (!ci->bi)
114  notice_help(s_BotServ, u, BOT_NOT_ASSIGNED);
115  else {
116  if (!stricmp(option, "BADWORDS")) {
117  if (!stricmp(value, "ON")) {
118  if (ttb) {
119  errno = 0;
120  ci->ttb[TTB_BADWORDS] =
121  strtol(ttb, (char **) NULL, 10);
122  /* Only error if errno returns ERANGE or EINVAL or we are less then 0 - TSL */
123  if (errno == ERANGE || errno == EINVAL
124  || ci->ttb[TTB_BADWORDS] < 0) {
125  /* leaving the debug behind since we might want to know what these are */
126  if (debug) {
127  alog("debug: errno is %d ERANGE %d EINVAL %d ttb %d", errno, ERANGE, EINVAL, ci->ttb[TTB_BADWORDS]);
128  }
129  /* reset the value back to 0 - TSL */
130  ci->ttb[TTB_BADWORDS] = 0;
131  notice_lang(s_BotServ, u, BOT_KICK_BAD_TTB, ttb);
132  return MOD_CONT;
133  }
134  } else {
135  ci->ttb[TTB_BADWORDS] = 0;
136  }
137  ci->botflags |= BS_KICK_BADWORDS;
138  if (ci->ttb[TTB_BADWORDS]) {
139  alog("%s: %s!%s@%s enabled kicking for badwords on %s with time to ban of %d",
140  s_BotServ, u->nick, u->username, u->host, ci->name, ci->ttb[TTB_BADWORDS]);
141  notice_lang(s_BotServ, u, BOT_KICK_BADWORDS_ON_BAN,
142  ci->ttb[TTB_BADWORDS]);
143  } else {
144  alog("%s: %s!%s@%s enabled kicking for badwords on %s",
145  s_BotServ, u->nick, u->username, u->host, ci->name);
146  notice_lang(s_BotServ, u, BOT_KICK_BADWORDS_ON);
147  }
148  } else {
149  ci->botflags &= ~BS_KICK_BADWORDS;
150  alog("%s: %s!%s@%s disabled kicking for badwords on %s",
151  s_BotServ, u->nick, u->username, u->host, ci->name);
152  notice_lang(s_BotServ, u, BOT_KICK_BADWORDS_OFF);
153  }
154  } else if (!stricmp(option, "BOLDS")) {
155  if (!stricmp(value, "ON")) {
156  if (ttb) {
157  errno = 0;
158  ci->ttb[TTB_BOLDS] = strtol(ttb, (char **) NULL, 10);
159  if (errno == ERANGE || errno == EINVAL
160  || ci->ttb[TTB_BOLDS] < 0) {
161  if (debug) {
162  alog("debug: errno is %d ERANGE %d EINVAL %d ttb %d", errno, ERANGE, EINVAL, ci->ttb[TTB_BOLDS]);
163  }
164  ci->ttb[TTB_BOLDS] = 0;
165  notice_lang(s_BotServ, u, BOT_KICK_BAD_TTB, ttb);
166  return MOD_CONT;
167  }
168  } else
169  ci->ttb[TTB_BOLDS] = 0;
170  ci->botflags |= BS_KICK_BOLDS;
171  if (ci->ttb[TTB_BOLDS]) {
172  alog("%s: %s!%s@%s enabled kicking for bolds on %s with time to ban of %d",
173  s_BotServ, u->nick, u->username, u->host, ci->name, ci->ttb[TTB_BOLDS]);
174  notice_lang(s_BotServ, u, BOT_KICK_BOLDS_ON_BAN,
175  ci->ttb[TTB_BOLDS]);
176  } else {
177  alog("%s: %s!%s@%s enabled kicking for bolds on %s",
178  s_BotServ, u->nick, u->username, u->host, ci->name);
179  notice_lang(s_BotServ, u, BOT_KICK_BOLDS_ON);
180  }
181  } else {
182  ci->botflags &= ~BS_KICK_BOLDS;
183  alog("%s: %s!%s@%s disabled kicking for bolds on %s",
184  s_BotServ, u->nick, u->username, u->host, ci->name);
185  notice_lang(s_BotServ, u, BOT_KICK_BOLDS_OFF);
186  }
187  } else if (!stricmp(option, "CAPS")) {
188  if (!stricmp(value, "ON")) {
189  char *min = strtok(NULL, " ");
190  char *percent = strtok(NULL, " ");
191 
192  if (ttb) {
193  errno = 0;
194  ci->ttb[TTB_CAPS] = strtol(ttb, (char **) NULL, 10);
195  if (errno == ERANGE || errno == EINVAL
196  || ci->ttb[TTB_CAPS] < 0) {
197  if (debug) {
198  alog("debug: errno is %d ERANGE %d EINVAL %d ttb %d", errno, ERANGE, EINVAL, ci->ttb[TTB_CAPS]);
199  }
200  ci->ttb[TTB_CAPS] = 0;
201  notice_lang(s_BotServ, u, BOT_KICK_BAD_TTB, ttb);
202  return MOD_CONT;
203  }
204  } else
205  ci->ttb[TTB_CAPS] = 0;
206 
207  if (!min)
208  ci->capsmin = 10;
209  else
210  ci->capsmin = atol(min);
211  if (ci->capsmin < 1)
212  ci->capsmin = 10;
213 
214  if (!percent)
215  ci->capspercent = 25;
216  else
217  ci->capspercent = atol(percent);
218  if (ci->capspercent < 1 || ci->capspercent > 100)
219  ci->capspercent = 25;
220 
221  ci->botflags |= BS_KICK_CAPS;
222  if (ci->ttb[TTB_CAPS]) {
223  alog("%s: %s!%s@%s enabled kicking for caps on %s with time to ban of %d",
224  s_BotServ, u->nick, u->username, u->host, ci->name, ci->ttb[TTB_CAPS]);
225  notice_lang(s_BotServ, u, BOT_KICK_CAPS_ON_BAN,
226  ci->capsmin, ci->capspercent,
227  ci->ttb[TTB_CAPS]);
228  } else {
229  alog("%s: %s!%s@%s enabled kicking for caps on %s",
230  s_BotServ, u->nick, u->username, u->host, ci->name);
231  notice_lang(s_BotServ, u, BOT_KICK_CAPS_ON,
232  ci->capsmin, ci->capspercent);
233  }
234  } else {
235  alog("%s: %s!%s@%s disabled kicking for caps on %s",
236  s_BotServ, u->nick, u->username, u->host, ci->name);
237  ci->botflags &= ~BS_KICK_CAPS;
238  notice_lang(s_BotServ, u, BOT_KICK_CAPS_OFF);
239  }
240  } else if (!stricmp(option, "COLORS")) {
241  if (!stricmp(value, "ON")) {
242  if (ttb) {
243  errno = 0;
244  ci->ttb[TTB_COLORS] = strtol(ttb, (char **) NULL, 10);
245  if (errno == ERANGE || errno == EINVAL
246  || ci->ttb[TTB_COLORS] < 0) {
247  if (debug) {
248  alog("debug: errno is %d ERANGE %d EINVAL %d ttb %d", errno, ERANGE, EINVAL, ci->ttb[TTB_COLORS]);
249  }
250  ci->ttb[TTB_COLORS] = 0;
251  notice_lang(s_BotServ, u, BOT_KICK_BAD_TTB, ttb);
252  return MOD_CONT;
253  }
254  } else
255  ci->ttb[TTB_COLORS] = 0;
256  ci->botflags |= BS_KICK_COLORS;
257  if (ci->ttb[TTB_COLORS]) {
258  alog("%s: %s!%s@%s enabled kicking for colors on %s with time to ban of %d",
259  s_BotServ, u->nick, u->username, u->host, ci->name, ci->ttb[TTB_COLORS]);
260  notice_lang(s_BotServ, u, BOT_KICK_COLORS_ON_BAN,
261  ci->ttb[TTB_COLORS]);
262  } else {
263  alog("%s: %s!%s@%s enabled kicking for colors on %s",
264  s_BotServ, u->nick, u->username, u->host, ci->name);
265  notice_lang(s_BotServ, u, BOT_KICK_COLORS_ON);
266  }
267  } else {
268  alog("%s: %s!%s@%s disabled kicking for colors on %s",
269  s_BotServ, u->nick, u->username, u->host, ci->name);
270  ci->botflags &= ~BS_KICK_COLORS;
271  notice_lang(s_BotServ, u, BOT_KICK_COLORS_OFF);
272  }
273  } else if (!stricmp(option, "FLOOD")) {
274  if (!stricmp(value, "ON")) {
275  char *lines = strtok(NULL, " ");
276  char *secs = strtok(NULL, " ");
277 
278  if (ttb) {
279  errno = 0;
280  ci->ttb[TTB_FLOOD] = strtol(ttb, (char **) NULL, 10);
281  if (errno == ERANGE || errno == EINVAL
282  || ci->ttb[TTB_FLOOD] < 0) {
283  if (debug) {
284  alog("debug: errno is %d ERANGE %d EINVAL %d ttb %d", errno, ERANGE, EINVAL, ci->ttb[TTB_FLOOD]);
285  }
286  ci->ttb[TTB_FLOOD] = 0;
287  notice_lang(s_BotServ, u, BOT_KICK_BAD_TTB, ttb);
288  return MOD_CONT;
289  }
290  } else
291  ci->ttb[TTB_FLOOD] = 0;
292 
293  if (!lines)
294  ci->floodlines = 6;
295  else
296  ci->floodlines = atol(lines);
297  if (ci->floodlines < 2)
298  ci->floodlines = 6;
299 
300  if (!secs)
301  ci->floodsecs = 10;
302  else
303  ci->floodsecs = atol(secs);
304  if (ci->floodsecs < 1 || ci->floodsecs > BSKeepData)
305  ci->floodsecs = 10;
306 
307  ci->botflags |= BS_KICK_FLOOD;
308  if (ci->ttb[TTB_FLOOD]) {
309  alog("%s: %s!%s@%s enabled kicking for flood on %s with time to ban of %d",
310  s_BotServ, u->nick, u->username, u->host, ci->name, ci->ttb[TTB_FLOOD]);
311  notice_lang(s_BotServ, u, BOT_KICK_FLOOD_ON_BAN,
312  ci->floodlines, ci->floodsecs,
313  ci->ttb[TTB_FLOOD]);
314  } else {
315  alog("%s: %s!%s@%s enabled kicking for flood on %s",
316  s_BotServ, u->nick, u->username, u->host, ci->name);
317  notice_lang(s_BotServ, u, BOT_KICK_FLOOD_ON,
318  ci->floodlines, ci->floodsecs);
319  }
320  } else {
321  ci->botflags &= ~BS_KICK_FLOOD;
322  alog("%s: %s!%s@%s disabled kicking for flood on %s",
323  s_BotServ, u->nick, u->username, u->host, ci->name);
324  notice_lang(s_BotServ, u, BOT_KICK_FLOOD_OFF);
325  }
326  } else if (!stricmp(option, "REPEAT")) {
327  if (!stricmp(value, "ON")) {
328  char *times = strtok(NULL, " ");
329 
330  if (ttb) {
331  errno = 0;
332  ci->ttb[TTB_REPEAT] = strtol(ttb, (char **) NULL, 10);
333  if (errno == ERANGE || errno == EINVAL
334  || ci->ttb[TTB_REPEAT] < 0) {
335  if (debug) {
336  alog("debug: errno is %d ERANGE %d EINVAL %d ttb %d", errno, ERANGE, EINVAL, ci->ttb[TTB_REPEAT]);
337  }
338  ci->ttb[TTB_REPEAT] = 0;
339  notice_lang(s_BotServ, u, BOT_KICK_BAD_TTB, ttb);
340  return MOD_CONT;
341  }
342  } else
343  ci->ttb[TTB_REPEAT] = 0;
344 
345  if (!times)
346  ci->repeattimes = 3;
347  else
348  ci->repeattimes = atol(times);
349  if (ci->repeattimes < 2)
350  ci->repeattimes = 3;
351 
352  ci->botflags |= BS_KICK_REPEAT;
353  if (ci->ttb[TTB_REPEAT]) {
354  alog("%s: %s!%s@%s enabled kicking for repeating on %s with time to ban of %d",
355  s_BotServ, u->nick, u->username, u->host, ci->name, ci->ttb[TTB_REPEAT]);
356  notice_lang(s_BotServ, u, BOT_KICK_REPEAT_ON_BAN,
357  ci->repeattimes, ci->ttb[TTB_REPEAT]);
358  } else {
359  alog("%s: %s!%s@%s enabled kicking for repeating on %s",
360  s_BotServ, u->nick, u->username, u->host, ci->name);
361  notice_lang(s_BotServ, u, BOT_KICK_REPEAT_ON,
362  ci->repeattimes);
363  }
364  } else {
365  ci->botflags &= ~BS_KICK_REPEAT;
366  alog("%s: %s!%s@%s disabled kicking for repeating on %s",
367  s_BotServ, u->nick, u->username, u->host, ci->name);
368  notice_lang(s_BotServ, u, BOT_KICK_REPEAT_OFF);
369  }
370  } else if (!stricmp(option, "REVERSES")) {
371  if (!stricmp(value, "ON")) {
372  if (ttb) {
373  errno = 0;
374  ci->ttb[TTB_REVERSES] =
375  strtol(ttb, (char **) NULL, 10);
376  if (errno == ERANGE || errno == EINVAL
377  || ci->ttb[TTB_REVERSES] < 0) {
378  if (debug) {
379  alog("debug: errno is %d ERANGE %d EINVAL %d ttb %d", errno, ERANGE, EINVAL, ci->ttb[TTB_REVERSES]);
380  }
381  ci->ttb[TTB_REVERSES] = 0;
382  notice_lang(s_BotServ, u, BOT_KICK_BAD_TTB, ttb);
383  return MOD_CONT;
384  }
385  } else
386  ci->ttb[TTB_REVERSES] = 0;
387  ci->botflags |= BS_KICK_REVERSES;
388  if (ci->ttb[TTB_REVERSES]) {
389  alog("%s: %s!%s@%s enabled kicking for reversess on %s with time to ban of %d",
390  s_BotServ, u->nick, u->username, u->host, ci->name, ci->ttb[TTB_REVERSES]);
391  notice_lang(s_BotServ, u, BOT_KICK_REVERSES_ON_BAN,
392  ci->ttb[TTB_REVERSES]);
393  } else {
394  alog("%s: %s!%s@%s enabled kicking for reverses on %s",
395  s_BotServ, u->nick, u->username, u->host, ci->name);
396  notice_lang(s_BotServ, u, BOT_KICK_REVERSES_ON);
397  }
398  } else {
399  ci->botflags &= ~BS_KICK_REVERSES;
400  alog("%s: %s!%s@%s disabled kicking for reverses on %s",
401  s_BotServ, u->nick, u->username, u->host, ci->name);
402  notice_lang(s_BotServ, u, BOT_KICK_REVERSES_OFF);
403  }
404  } else if (!stricmp(option, "UNDERLINES")) {
405  if (!stricmp(value, "ON")) {
406  if (ttb) {
407  errno = 0;
408  ci->ttb[TTB_UNDERLINES] =
409  strtol(ttb, (char **) NULL, 10);
410  if (errno == ERANGE || errno == EINVAL
411  || ci->ttb[TTB_UNDERLINES] < 0) {
412  if (debug) {
413  alog("debug: errno is %d ERANGE %d EINVAL %d ttb %d", errno, ERANGE, EINVAL, ci->ttb[TTB_UNDERLINES]);
414  }
415  ci->ttb[TTB_UNDERLINES] = 0;
416  notice_lang(s_BotServ, u, BOT_KICK_BAD_TTB, ttb);
417  return MOD_CONT;
418  }
419  } else
420  ci->ttb[TTB_UNDERLINES] = 0;
422  if (ci->ttb[TTB_UNDERLINES]) {
423  alog("%s: %s!%s@%s enabled kicking for underlines on %s with time to ban of %d",
424  s_BotServ, u->nick, u->username, u->host, ci->name, ci->ttb[TTB_UNDERLINES]);
425  notice_lang(s_BotServ, u, BOT_KICK_UNDERLINES_ON_BAN,
426  ci->ttb[TTB_UNDERLINES]);
427  } else {
428  alog("%s: %s!%s@%s enabled kicking for underlines on %s",
429  s_BotServ, u->nick, u->username, u->host, ci->name);
430  notice_lang(s_BotServ, u, BOT_KICK_UNDERLINES_ON);
431  }
432  } else {
434  alog("%s: %s!%s@%s disabled kicking for underlines on %s",
435  s_BotServ, u->nick, u->username, u->host, ci->name);
436  notice_lang(s_BotServ, u, BOT_KICK_UNDERLINES_OFF);
437  }
438  } else
439  notice_help(s_BotServ, u, BOT_KICK_UNKNOWN, option);
440  }
441  return MOD_CONT;
442 }
#define BS_KICK_REPEAT
Definition: services.h:808
#define TTB_FLOOD
Definition: services.h:817
#define TTB_UNDERLINES
Definition: services.h:814
E int readonly
Definition: extern.h:776
char nick[NICKMAX]
Definition: services.h:875
uint32 botflags
Definition: services.h:700
int16 capspercent
Definition: services.h:705
E char * s_BotServ
Definition: extern.h:287
#define BS_KICK_CAPS
Definition: services.h:806
E int check_access(User *user, ChannelInfo *ci, int what)
Definition: chanserv.c:1974
int AnopeInit(int argc, char **argv)
Definition: bs_kick.c:27
#define TTB_REPEAT
Definition: services.h:818
E int stricmp(const char *s1, const char *s2)
Definition: compat.c:58
#define CI_VERBOTEN
Definition: services.h:725
char * host
Definition: services.h:878
#define TTB_BADWORDS
Definition: services.h:815
E int BSKeepData
Definition: extern.h:421
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 name[CHANMAX]
Definition: services.h:654
E void notice_lang(char *source, User *dest, int message,...)
Definition: send.c:169
MDE void moduleSetType(MODType type)
Definition: modules.c:818
#define BS_KICK_FLOOD
Definition: services.h:807
#define BS_KICK_BADWORDS
Definition: services.h:805
static int do_kickcmd(User *u)
Definition: bs_kick.c:92
#define TTB_COLORS
Definition: services.h:812
uint32 flags
Definition: services.h:669
#define TTB_CAPS
Definition: services.h:816
#define BS_KICK_BOLDS
Definition: services.h:801
#define BS_KICK_UNDERLINES
Definition: services.h:804
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
Command * c
Definition: ns_recover.c:17
#define BOTSERV
Definition: modules.h:57
E void notice_help(char *source, User *dest, int message,...)
Definition: send.c:220
E void alog(const char *fmt,...) FORMAT(printf
#define MOD_CONT
Definition: modules.h:54
static void myBotServHelp(User *u)
Definition: bs_kick.c:82
#define TTB_REVERSES
Definition: services.h:813
MDE void moduleSetBotHelp(void(*func)(User *u))
Definition: modules.c:2114
E int debug
Definition: extern.h:775
E int is_services_admin(User *u)
Definition: operserv.c:591
int16 floodlines
Definition: services.h:706
char * username
Definition: services.h:877
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
int16 floodsecs
Definition: services.h:706
int16 * ttb
Definition: services.h:701
E ChannelInfo * cs_findchan(const char *chan)
Definition: db-merger.c:2000
int16 capsmin
Definition: services.h:705
#define BS_KICK_REVERSES
Definition: services.h:803
int16 repeattimes
Definition: services.h:707
void AnopeFini(void)
Definition: bs_kick.c:71
BotInfo * bi
Definition: services.h:699
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
#define TTB_BOLDS
Definition: services.h:811
#define BS_KICK_COLORS
Definition: services.h:802
#define CA_SET
Definition: services.h:751
#define MOD_UNIQUE
Definition: module.h:11