Anope IRC Services  Version 1.8
cs_forbid.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_forbid(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("FORBID", do_forbid, is_services_admin, -1, -1, -1,
35  CHAN_SERVADMIN_HELP_FORBID,
36  CHAN_SERVADMIN_HELP_FORBID);
38 
40 
41  return MOD_CONT;
42 }
43 
47 void AnopeFini(void)
48 {
49 
50 }
51 
56 static void myChanServHelp(User * u)
57 {
58  if (is_services_admin(u)) {
59  notice_lang(s_ChanServ, u, CHAN_HELP_CMD_FORBID);
60  }
61 }
62 
68 static int do_forbid(User * u)
69 {
70  Channel *c;
71  ChannelInfo *ci;
72  char *chan = strtok(NULL, " ");
73  char *reason = strtok(NULL, "");
74  Entry *cur, *enext;
75 
76  /* Assumes that permission checking has already been done. */
77  if (!chan || (ForceForbidReason && !reason)) {
78  syntax_error(s_ChanServ, u, "FORBID",
79  (ForceForbidReason ? CHAN_FORBID_SYNTAX_REASON :
80  CHAN_FORBID_SYNTAX));
81  return MOD_CONT;
82  }
83  if (*chan != '#') {
84  notice_lang(s_ChanServ, u, CHAN_SYMBOL_REQUIRED);
85  return MOD_CONT;
86  } else if (!anope_valid_chan(chan)) {
87  notice_lang(s_ChanServ, u, CHAN_X_INVALID, chan);
88  return MOD_CONT;
89  }
90  if (readonly)
91  notice_lang(s_ChanServ, u, READ_ONLY_MODE);
92  if ((ci = cs_findchan(chan)) != NULL) {
93  delchan(ci);
94  send_event(EVENT_CHAN_DROP, 1, chan);
95  }
96  ci = makechan(chan);
97  if (ci) {
98  ci->flags |= CI_VERBOTEN;
99  ci->forbidby = sstrdup(u->nick);
100  if (reason)
101  ci->forbidreason = sstrdup(reason);
102 
103  if ((c = findchan(ci->name))) {
104  struct c_userlist *cu, *next;
105  char *av[3];
106 
107  /* Before banning everyone, it might be prudent to clear +e and +I lists..
108  * to prevent ppl from rejoining.. ~ Viper */
109  if (ircd->except && c->excepts && c->excepts->count) {
110  av[0] = sstrdup("-e");
111  for (cur = c->excepts->entries; cur; cur = enext) {
112  enext = cur->next;
113  av[1] = sstrdup(cur->mask);
114  anope_cmd_mode(whosends(ci), chan, "-e %s", cur->mask);
115  chan_set_modes(whosends(ci), c, 2, av, 0);
116  free(av[1]);
117  }
118  free(av[0]);
119  }
120  if (ircd->invitemode && c->invites && c->invites->count) {
121  av[0] = sstrdup("-I");
122  for (cur = c->invites->entries; cur; cur = enext) {
123  enext = cur->next;
124  av[1] = sstrdup(cur->mask);
125  anope_cmd_mode(whosends(ci), chan, "-I %s", cur->mask);
126  chan_set_modes(whosends(ci), c, 2, av, 0);
127  free(av[1]);
128  }
129  free(av[0]);
130  }
131 
132  for (cu = c->users; cu; cu = next) {
133  next = cu->next;
134 
135  if (is_oper(cu->user))
136  continue;
137 
138  av[0] = c->name;
139  av[1] = cu->user->nick;
140  av[2] = reason ? reason : getstring(cu->user->na, CHAN_FORBID_REASON);
141  anope_cmd_kick(s_ChanServ, av[0], av[1], av[2]);
142  do_kick(s_ChanServ, 3, av);
143  }
144  }
145 
146  if (WallForbid)
148  "\2%s\2 used FORBID on channel \2%s\2",
149  u->nick, ci->name);
150 
151  if (ircd->chansqline) {
152  anope_cmd_sqline(ci->name, ((reason) ? reason : "Forbidden"));
153  }
154 
155  alog("%s: %s set FORBID for channel %s", s_ChanServ, u->nick,
156  ci->name);
157  notice_lang(s_ChanServ, u, CHAN_FORBID_SUCCEEDED, chan);
159  } else {
160  alog("%s: Valid FORBID for %s by %s failed", s_ChanServ, ci->name,
161  u->nick);
162  notice_lang(s_ChanServ, u, CHAN_FORBID_FAILED, chan);
163  }
164  return MOD_CONT;
165 }
E int is_oper(User *user)
Definition: users.c:937
EList * invites
Definition: services.h:1014
E int readonly
Definition: extern.h:776
char nick[NICKMAX]
Definition: services.h:875
E IRCDVar * ircd
Definition: extern.h:39
E void do_kick(const char *source, int ac, char **av)
Definition: channels.c:638
E int anope_valid_chan(char *chan)
Definition: ircd.c:666
Entry * next
Definition: services.h:1038
E void send_event(const char *name, int argc,...)
Definition: events.c:37
E int WallForbid
Definition: extern.h:467
int32 count
Definition: services.h:1034
#define CI_VERBOTEN
Definition: services.h:725
#define getstring(na, index)
Definition: extern.h:731
E void chan_set_modes(const char *source, Channel *chan, int ac, char **av, int check)
Definition: channels.c:161
static void myChanServHelp(User *u)
Definition: cs_forbid.c:56
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
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 * forbidreason
Definition: services.h:671
E Channel * findchan(const char *chan)
Definition: channels.c:394
E char * sstrdup(const char *s)
Definition: memory.c:105
void AnopeFini(void)
Definition: cs_forbid.c:47
static int do_forbid(User *u)
Definition: cs_forbid.c:68
E void anope_cmd_kick(char *source, char *chan, char *user, const char *fmt,...)
Definition: ircd.c:230
uint32 flags
Definition: services.h:669
int invitemode
Definition: services.h:359
EList * excepts
Definition: services.h:1013
Definition: services.h:1037
int AnopeInit(int argc, char **argv)
Definition: cs_forbid.c:26
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
MDE void moduleSetChanHelp(void(*func)(User *u))
Definition: modules.c:2090
int chansqline
Definition: services.h:325
Command * c
Definition: ns_recover.c:17
#define CHANSERV
Definition: modules.h:60
E void anope_cmd_sqline(char *mask, char *reason)
Definition: ircd.c:524
E void alog(const char *fmt,...) FORMAT(printf
#define MOD_CONT
Definition: modules.h:54
E int delchan(ChannelInfo *ci)
Definition: chanserv.c:2063
E int is_services_admin(User *u)
Definition: operserv.c:591
#define whosends(ci)
Definition: extern.h:163
#define EVENT_CHAN_FORBIDDEN
Definition: events.h:34
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
Entry * entries
Definition: services.h:1033
char name[CHANMAX]
Definition: services.h:1000
E ChannelInfo * cs_findchan(const char *chan)
Definition: db-merger.c:2000
E int ForceForbidReason
Definition: extern.h:351
E char * s_ChanServ
Definition: extern.h:285
char * mask
Definition: services.h:1042
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
E ChannelInfo * makechan(const char *chan)
Definition: chanserv.c:2042
#define EVENT_CHAN_DROP
Definition: events.h:33
char * forbidby
Definition: services.h:670
#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