Anope IRC Services  Version 1.8
bs_fantasy_kickban.c
Go to the documentation of this file.
1 /* BotServ core fantasy 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_fantasy(int argc, char **argv);
18 
25 int AnopeInit(int argc, char **argv)
26 {
27  EvtHook *hook;
28 
29  moduleAddAuthor("Anope");
31  (VERSION_STRING);
33 
35  moduleAddEventHook(hook);
36 
37  return MOD_CONT;
38 }
39 
43 void AnopeFini(void)
44 {
45 
46 }
47 
54 static int do_fantasy(int argc, char **argv)
55 {
56  User *u, *u2;
57  ChannelInfo *ci;
58  char *target = NULL;
59  char *reason = NULL;
60 
61  if (argc < 3)
62  return MOD_CONT;
63 
64  if ((stricmp(argv[0], "kickban") == 0)
65  || (stricmp(argv[0], "kb") == 0)) {
66  u = finduser(argv[1]);
67  ci = cs_findchan(argv[2]);
68  if (!u || !ci)
69  return MOD_CONT;
70 
71  if (argc >= 4) {
72  target = myStrGetToken(argv[3], ' ', 0);
73  reason = myStrGetTokenRemainder(argv[3], ' ', 1);
74  }
75  if (!target && check_access(u, ci, CA_BANME)) {
76  bot_raw_ban(u, ci, u->nick, "Requested");
77  } else if (target && check_access(u, ci, CA_BAN)) {
78  if (stricmp(target, ci->bi->nick) == 0) {
79  bot_raw_ban(u, ci, u->nick, "Oops!");
80  } else {
81  u2 = finduser(target);
82  if (u2 && ci->c && is_on_chan(ci->c, u2)) {
83  if (!reason && !is_protected(u2))
84  bot_raw_ban(u, ci, target, "Requested");
85  else if (!is_protected(u2))
86  bot_raw_ban(u, ci, target, reason);
87  }
88  }
89  }
90  }
91 
92  if (target)
93  free(target);
94  if (reason)
95  free(reason);
96 
97  return MOD_CONT;
98 }
void AnopeFini(void)
char nick[NICKMAX]
Definition: services.h:875
static int do_fantasy(int argc, char **argv)
E int check_access(User *user, ChannelInfo *ci, int what)
Definition: chanserv.c:1974
E int stricmp(const char *s1, const char *s2)
Definition: compat.c:58
#define CA_BAN
Definition: services.h:786
E char * myStrGetTokenRemainder(const char *str, const char dilim, int token_number)
Definition: misc.c:720
E int is_on_chan(Channel *c, User *u)
Definition: channels.c:517
E int is_protected(User *user)
Definition: users.c:924
MDE void moduleAddAuthor(const char *author)
Definition: modules.c:1772
MDE void moduleSetType(MODType type)
Definition: modules.c:818
E User * finduser(const char *nick)
Definition: users.c:323
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
struct channel_ * c
Definition: services.h:692
MDE EvtHook * createEventHook(char *name, int(*func)(int argc, char **argv))
Definition: events.c:305
#define MOD_CONT
Definition: modules.h:54
#define EVENT_BOT_FANTASY
Definition: events.h:24
Definition: modules.h:99
E void bot_raw_ban(User *requester, ChannelInfo *ci, char *nick, char *reason)
Definition: botserv.c:916
E char * myStrGetToken(const char *str, const char dilim, int token_number)
Definition: misc.c:654
char * nick
Definition: services.h:573
E ChannelInfo * cs_findchan(const char *chan)
Definition: db-merger.c:2000
int AnopeInit(int argc, char **argv)
#define CA_BANME
Definition: services.h:785
BotInfo * bi
Definition: services.h:699
MDE int moduleAddEventHook(EvtHook *evh)
Definition: events.c:528