Anope IRC Services  Version 1.8
cs_suspend.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_suspend(User * u);
18 static int do_unsuspend(User * u);
19 static void myChanServHelp(User * u);
20 
27 int AnopeInit(int argc, char **argv)
28 {
29  Command *c;
30 
31  moduleAddAuthor("Anope");
32  moduleAddVersion(VERSION_STRING);
34 
35  c = createCommand("SUSPEND", do_suspend, is_services_oper, -1, -1,
36  CHAN_SERVADMIN_HELP_SUSPEND,
37  CHAN_SERVADMIN_HELP_SUSPEND,
38  CHAN_SERVADMIN_HELP_SUSPEND);
40  c = createCommand("UNSUSPEND", do_unsuspend, is_services_oper, -1, -1,
41  CHAN_SERVADMIN_HELP_UNSUSPEND,
42  CHAN_SERVADMIN_HELP_UNSUSPEND,
43  CHAN_SERVADMIN_HELP_UNSUSPEND);
45 
47 
48  return MOD_CONT;
49 }
50 
54 void AnopeFini(void)
55 {
56 
57 }
58 
63 static void myChanServHelp(User * u)
64 {
65  if (is_services_oper(u)) {
66  notice_lang(s_ChanServ, u, CHAN_HELP_CMD_SUSPEND);
67  notice_lang(s_ChanServ, u, CHAN_HELP_CMD_UNSUSPEND);
68  }
69 }
70 
76 static int do_suspend(User * u)
77 {
78  ChannelInfo *ci;
79  char *chan = strtok(NULL, " ");
80  char *reason = strtok(NULL, "");
81 
82  Channel *c;
83 
84  /* Assumes that permission checking has already been done. */
85  if (!chan || (ForceForbidReason && !reason)) {
86  syntax_error(s_ChanServ, u, "SUSPEND",
87  (ForceForbidReason ? CHAN_SUSPEND_SYNTAX_REASON :
88  CHAN_SUSPEND_SYNTAX));
89  return MOD_CONT;
90  }
91 
92  if (chan[0] != '#') {
93  notice_lang(s_ChanServ, u, CHAN_UNSUSPEND_ERROR);
94  return MOD_CONT;
95  }
96 
97  /* Only SUSPEND existing channels, otherwise use FORBID (bug #54) */
98  if ((ci = cs_findchan(chan)) == NULL) {
99  notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, chan);
100  return MOD_CONT;
101  }
102 
103  /* You should not SUSPEND a FORBIDEN channel */
104  if (ci->flags & CI_VERBOTEN) {
105  notice_lang(s_ChanServ, u, CHAN_MAY_NOT_BE_REGISTERED, chan);
106  return MOD_CONT;
107  }
108 
109  if (readonly)
110  notice_lang(s_ChanServ, u, READ_ONLY_MODE);
111 
112  if (ci) {
113  ci->flags |= CI_SUSPENDED;
114  ci->forbidby = sstrdup(u->nick);
115  if (reason)
116  ci->forbidreason = sstrdup(reason);
117 
118  if ((c = findchan(ci->name))) {
119  struct c_userlist *cu, *next;
120  char *av[3];
121 
122  for (cu = c->users; cu; cu = next) {
123  next = cu->next;
124 
125  if (is_oper(cu->user))
126  continue;
127 
128  av[0] = c->name;
129  av[1] = cu->user->nick;
130  av[2] = reason ? reason : getstring(cu->user->na, CHAN_SUSPEND_REASON);
131  anope_cmd_kick(s_ChanServ, av[0], av[1], av[2]);
132  do_kick(s_ChanServ, 3, av);
133  }
134  }
135 
136  if (WallForbid)
138  "\2%s\2 used SUSPEND on channel \2%s\2",
139  u->nick, ci->name);
140 
141  alog("%s: %s set SUSPEND for channel %s", s_ChanServ, u->nick,
142  ci->name);
143  notice_lang(s_ChanServ, u, CHAN_SUSPEND_SUCCEEDED, chan);
145  } else {
146  alog("%s: Valid SUSPEND for %s by %s failed", s_ChanServ, ci->name,
147  u->nick);
148  notice_lang(s_ChanServ, u, CHAN_SUSPEND_FAILED, chan);
149  }
150  return MOD_CONT;
151 }
152 
153 /*************************************************************************/
154 
155 static int do_unsuspend(User * u)
156 {
157  ChannelInfo *ci;
158  char *chan = strtok(NULL, " ");
159 
160  /* Assumes that permission checking has already been done. */
161  if (!chan) {
162  syntax_error(s_ChanServ, u, "UNSUSPEND", CHAN_UNSUSPEND_SYNTAX);
163  return MOD_CONT;
164  }
165  if (chan[0] != '#') {
166  notice_lang(s_ChanServ, u, CHAN_UNSUSPEND_ERROR);
167  return MOD_CONT;
168  }
169  if (readonly)
170  notice_lang(s_ChanServ, u, READ_ONLY_MODE);
171 
172  /* Only UNSUSPEND already suspended channels */
173  if ((ci = cs_findchan(chan)) == NULL) {
174  notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, chan);
175  return MOD_CONT;
176  }
177 
178  if (!(ci->flags & CI_SUSPENDED))
179  {
180  notice_lang(s_ChanServ, u, CHAN_UNSUSPEND_FAILED, chan);
181  return MOD_CONT;
182  }
183 
184  if (ci) {
185  ci->flags &= ~CI_SUSPENDED;
186  if (ci->forbidreason)
187  {
188  free(ci->forbidreason);
189  ci->forbidreason = NULL;
190  }
191  if (ci->forbidby)
192  {
193  free(ci->forbidby);
194  ci->forbidby = NULL;
195  }
196 
197  if (WallForbid)
199  "\2%s\2 used UNSUSPEND on channel \2%s\2",
200  u->nick, ci->name);
201 
202  alog("%s: %s set UNSUSPEND for channel %s", s_ChanServ, u->nick,
203  ci->name);
204  notice_lang(s_ChanServ, u, CHAN_UNSUSPEND_SUCCEEDED, chan);
206  } else {
207  alog("%s: Valid UNSUSPEND for %s by %s failed", s_ChanServ,
208  chan, u->nick);
209  notice_lang(s_ChanServ, u, CHAN_UNSUSPEND_FAILED, chan);
210  }
211  return MOD_CONT;
212 }
E int is_oper(User *user)
Definition: users.c:937
#define CI_SUSPENDED
Definition: services.h:743
E int readonly
Definition: extern.h:776
char nick[NICKMAX]
Definition: services.h:875
E void do_kick(const char *source, int ac, char **av)
Definition: channels.c:638
E void send_event(const char *name, int argc,...)
Definition: events.c:37
E int WallForbid
Definition: extern.h:467
#define CI_VERBOTEN
Definition: services.h:725
#define getstring(na, index)
Definition: extern.h:731
static int do_suspend(User *u)
Definition: cs_suspend.c:76
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
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
E void anope_cmd_kick(char *source, char *chan, char *user, const char *fmt,...)
Definition: ircd.c:230
uint32 flags
Definition: services.h:669
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
void AnopeFini(void)
Definition: cs_suspend.c:54
int AnopeInit(int argc, char **argv)
Definition: cs_suspend.c:27
#define EVENT_CHAN_UNSUSPEND
Definition: events.h:36
MDE void moduleSetChanHelp(void(*func)(User *u))
Definition: modules.c:2090
#define EVENT_CHAN_SUSPENDED
Definition: events.h:35
Command * c
Definition: ns_recover.c:17
#define CHANSERV
Definition: modules.h:60
E void alog(const char *fmt,...) FORMAT(printf
#define MOD_CONT
Definition: modules.h:54
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
E ChannelInfo * cs_findchan(const char *chan)
Definition: db-merger.c:2000
E int is_services_oper(User *u)
Definition: operserv.c:606
E int ForceForbidReason
Definition: extern.h:351
E char * s_ChanServ
Definition: extern.h:285
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
static void myChanServHelp(User *u)
Definition: cs_suspend.c:63
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
static int do_unsuspend(User *u)
Definition: cs_suspend.c:155