Anope IRC Services  Version 1.8
cs_kick.c
Go to the documentation of this file.
1 /* ChanServ 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_cs_kick(User * u);
18 static void myChanServHelp(User * u);
19 
26 int AnopeInit(int argc, char **argv)
27 {
28  Command *c;
29 
30  moduleAddAuthor("Anope");
31  moduleAddVersion(VERSION_STRING);
33 
34  c = createCommand("KICK", do_cs_kick, NULL, CHAN_HELP_KICK, -1, -1, -1,
35  -1);
37 
39 
40  return MOD_CONT;
41 }
42 
46 void AnopeFini(void)
47 {
48 
49 }
50 
55 static void myChanServHelp(User * u)
56 {
57  notice_lang(s_ChanServ, u, CHAN_HELP_CMD_KICK);
58 }
59 
65 static int do_cs_kick(User * u)
66 {
67  char *chan = strtok(NULL, " ");
68  char *params = strtok(NULL, " ");
69  char *reason = strtok(NULL, "");
70 
71  Channel *c;
72  ChannelInfo *ci;
73  User *u2;
74 
75  int is_same;
76 
77  if (!reason) {
78  reason = "Requested";
79  } else {
80  if (strlen(reason) > 200)
81  reason[200] = '\0';
82  }
83 
84  if (!chan) {
85  struct u_chanlist *uc, *next;
86 
87  /* Kicks the user on every channels he is on. */
88 
89  for (uc = u->chans; uc; uc = next) {
90  next = uc->next;
91  if ((ci = uc->chan->ci) && !(ci->flags & CI_VERBOTEN)
92  && check_access(u, ci, CA_KICKME)) {
93  char *av[3];
94 
95  if ((ci->flags & CI_SIGNKICK)
96  || ((ci->flags & CI_SIGNKICK_LEVEL)
97  && !check_access(u, ci, CA_SIGNKICK)))
98  anope_cmd_kick(whosends(ci), ci->name, u->nick,
99  "%s (%s)", reason, u->nick);
100  else
101  anope_cmd_kick(whosends(ci), ci->name, u->nick, "%s",
102  reason);
103  av[0] = ci->name;
104  av[1] = u->nick;
105  av[2] = reason;
106  do_kick(s_ChanServ, 3, av);
107  }
108  }
109 
110  return MOD_CONT;
111  } else if (!params) {
112  params = u->nick;
113  }
114 
115  is_same = (params == u->nick) ? 1 : (stricmp(params, u->nick) == 0);
116 
117  if (!(c = findchan(chan))) {
118  notice_lang(s_ChanServ, u, CHAN_X_NOT_IN_USE, chan);
119  } else if (!(ci = c->ci)) {
120  notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, chan);
121  } else if (ci->flags & CI_VERBOTEN) {
122  notice_lang(s_ChanServ, u, CHAN_X_FORBIDDEN, chan);
123  } else if (is_same ? !(u2 = u) : !(u2 = finduser(params))) {
124  notice_lang(s_ChanServ, u, NICK_X_NOT_IN_USE, params);
125  } else if (!is_same ? !check_access(u, ci, CA_KICK) :
126  !check_access(u, ci, CA_KICKME)) {
127  notice_lang(s_ChanServ, u, ACCESS_DENIED);
128  } else if (!is_same && (ci->flags & CI_PEACE)
129  && (get_access(u2, ci) >= get_access(u, ci))) {
130  notice_lang(s_ChanServ, u, PERMISSION_DENIED);
131  } else if (is_protected(u2)) {
132  notice_lang(s_ChanServ, u, PERMISSION_DENIED);
133  } else if (!is_on_chan(c, u2)) {
134  notice_lang(s_ChanServ, u, NICK_X_NOT_ON_CHAN, u2->nick, c->name);
135  } else {
136  char *av[3];
137 
138  if ((ci->flags & CI_SIGNKICK)
139  || ((ci->flags & CI_SIGNKICK_LEVEL)
140  && !check_access(u, ci, CA_SIGNKICK)))
141  anope_cmd_kick(whosends(ci), ci->name, params, "%s (%s)",
142  reason, u->nick);
143  else
144  anope_cmd_kick(whosends(ci), ci->name, params, "%s", reason);
145  av[0] = ci->name;
146  av[1] = params;
147  av[2] = reason;
148  do_kick(s_ChanServ, 3, av);
149  }
150  return MOD_CONT;
151 }
#define CA_KICKME
Definition: services.h:778
char nick[NICKMAX]
Definition: services.h:875
static void myChanServHelp(User *u)
Definition: cs_kick.c:55
E void do_kick(const char *source, int ac, char **av)
Definition: channels.c:638
E int check_access(User *user, ChannelInfo *ci, int what)
Definition: chanserv.c:1974
int AnopeInit(int argc, char **argv)
Definition: cs_kick.c:26
E int stricmp(const char *s1, const char *s2)
Definition: compat.c:58
#define CI_VERBOTEN
Definition: services.h:725
struct user_::u_chanlist * chans
#define CA_SIGNKICK
Definition: services.h:780
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
ChannelInfo * ci
Definition: services.h:1001
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
E Channel * findchan(const char *chan)
Definition: channels.c:394
#define CA_KICK
Definition: services.h:779
#define CI_PEACE
Definition: services.h:721
E void anope_cmd_kick(char *source, char *chan, char *user, const char *fmt,...)
Definition: ircd.c:230
uint32 flags
Definition: services.h:669
E User * finduser(const char *nick)
Definition: users.c:323
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
MDE void moduleSetChanHelp(void(*func)(User *u))
Definition: modules.c:2090
Command * c
Definition: ns_recover.c:17
#define CHANSERV
Definition: modules.h:60
User * next
Definition: services.h:873
#define MOD_CONT
Definition: modules.h:54
#define CI_SIGNKICK
Definition: services.h:737
#define CI_SIGNKICK_LEVEL
Definition: services.h:739
#define whosends(ci)
Definition: extern.h:163
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
char name[CHANMAX]
Definition: services.h:1000
void AnopeFini(void)
Definition: cs_kick.c:46
E char * s_ChanServ
Definition: extern.h:285
E int get_access(User *user, ChannelInfo *ci)
Definition: chanserv.c:2332
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
static int do_cs_kick(User *u)
Definition: cs_kick.c:65
#define MOD_UNIQUE
Definition: module.h:11