Anope IRC Services  Version 1.8
cs_modes.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 void myChanServHelp(User * u);
18 static int do_util(User * u, CSModeUtil * util);
19 static int do_op(User * u);
20 static int do_deop(User * u);
21 static int do_voice(User * u);
22 static int do_devoice(User * u);
23 static int do_halfop(User * u);
24 static int do_dehalfop(User * u);
25 static int do_protect(User * u);
26 static int do_deprotect(User * u);
27 static int do_owner(User * u);
28 static int do_deowner(User * u);
29 
36 int AnopeInit(int argc, char **argv)
37 {
38  Command *c;
39 
40  moduleAddAuthor("Anope");
41  moduleAddVersion(VERSION_STRING);
43 
44  c = createCommand("OP", do_op, NULL, CHAN_HELP_OP, -1, -1, -1, -1);
46  c = createCommand("DEOP", do_deop, NULL, CHAN_HELP_DEOP, -1, -1, -1,
47  -1);
49  c = createCommand("VOICE", do_voice, NULL, CHAN_HELP_VOICE, -1, -1, -1,
50  -1);
52  c = createCommand("DEVOICE", do_devoice, NULL, CHAN_HELP_DEVOICE, -1,
53  -1, -1, -1);
55  c = createCommand("HALFOP", do_halfop, NULL, CHAN_HELP_HALFOP, -1,
56  -1, -1, -1);
58  c = createCommand("DEHALFOP", do_dehalfop, NULL, CHAN_HELP_DEHALFOP, -1, -1, -1, -1);
60  c = createCommand("PROTECT", do_protect, NULL, CHAN_HELP_PROTECT, -1, -1, -1, -1);
62  c = createCommand("DEPROTECT", do_deprotect, NULL, CHAN_HELP_DEPROTECT, -1, -1, -1, -1);
64  c = createCommand("OWNER", do_owner, NULL, CHAN_HELP_OWNER, -1, -1, -1, -1);
66  c = createCommand("DEOWNER", do_deowner, NULL, CHAN_HELP_DEOWNER, -1, -1, -1, -1);
68  c = createCommand("ADMIN", do_protect, NULL, CHAN_HELP_PROTECT, -1, -1, -1, -1);
70  c = createCommand("DEADMIN", do_deprotect, NULL, CHAN_HELP_DEPROTECT, -1, -1, -1, -1);
72 
74 
75  return MOD_CONT;
76 }
77 
81 void AnopeFini(void)
82 {
83 
84 }
85 
90 static void myChanServHelp(User * u)
91 {
92  if (ircd->owner) {
93  notice_lang(s_ChanServ, u, CHAN_HELP_CMD_OWNER);
94  notice_lang(s_ChanServ, u, CHAN_HELP_CMD_DEOWNER);
95  }
96  if (ircd->protect) {
97  notice_lang(s_ChanServ, u, CHAN_HELP_CMD_PROTECT);
98  notice_lang(s_ChanServ, u, CHAN_HELP_CMD_DEPROTECT);
99  } else if (ircd->admin) {
100  notice_lang(s_ChanServ, u, CHAN_HELP_CMD_ADMIN);
101  notice_lang(s_ChanServ, u, CHAN_HELP_CMD_DEADMIN);
102  }
103 
104  notice_lang(s_ChanServ, u, CHAN_HELP_CMD_OP);
105  notice_lang(s_ChanServ, u, CHAN_HELP_CMD_DEOP);
106  if (ircd->halfop) {
107  notice_lang(s_ChanServ, u, CHAN_HELP_CMD_HALFOP);
108  notice_lang(s_ChanServ, u, CHAN_HELP_CMD_DEHALFOP);
109  }
110  notice_lang(s_ChanServ, u, CHAN_HELP_CMD_VOICE);
111  notice_lang(s_ChanServ, u, CHAN_HELP_CMD_DEVOICE);
112 }
113 
120 static int do_op(User * u)
121 {
122  return do_util(u, &csmodeutils[MUT_OP]);
123 }
124 
125 /*************************************************************************/
126 
127 static int do_deop(User * u)
128 {
129  return do_util(u, &csmodeutils[MUT_DEOP]);
130 }
131 
132 /*************************************************************************/
133 
134 static int do_voice(User * u)
135 {
136  return do_util(u, &csmodeutils[MUT_VOICE]);
137 }
138 
139 /*************************************************************************/
140 
141 static int do_devoice(User * u)
142 {
143  return do_util(u, &csmodeutils[MUT_DEVOICE]);
144 }
145 
146 /*************************************************************************/
147 
148 static int do_halfop(User * u)
149 {
150  if (ircd->halfop) {
151  return do_util(u, &csmodeutils[MUT_HALFOP]);
152  } else {
153  return MOD_CONT;
154  }
155 }
156 
157 /*************************************************************************/
158 
159 static int do_dehalfop(User * u)
160 {
161  if (ircd->halfop) {
162  return do_util(u, &csmodeutils[MUT_DEHALFOP]);
163  } else {
164  return MOD_CONT;
165  }
166 }
167 
168 /*************************************************************************/
169 
170 static int do_protect(User * u)
171 {
172  if (ircd->protect || ircd->admin) {
173  return do_util(u, &csmodeutils[MUT_PROTECT]);
174  } else {
175  return MOD_CONT;
176  }
177 }
178 
179 /*************************************************************************/
180 
181 static int do_deprotect(User * u)
182 {
183  if (ircd->protect || ircd->admin) {
184  return do_util(u, &csmodeutils[MUT_DEPROTECT]);
185  } else {
186  return MOD_CONT;
187  }
188 }
189 
190 /*************************************************************************/
191 
192 static int do_owner(User * u)
193 {
194  char *av[2];
195  char *chan = strtok(NULL, " ");
196 
197  Channel *c;
198  ChannelInfo *ci;
199  struct u_chanlist *uc;
200 
201  if (!ircd->owner) {
202  return MOD_CONT;
203  }
204 
205  if (!chan) {
206  av[0] = sstrdup(ircd->ownerset);
207  av[1] = GET_USER(u);
208 
209  /* Sets the mode to the user on every channels he is on. */
210 
211  for (uc = u->chans; uc; uc = uc->next) {
212  if ((ci = uc->chan->ci) && !(ci->flags & CI_VERBOTEN)
213  && is_founder(u, ci)) {
214  anope_cmd_mode(whosends(ci), uc->chan->name, "%s %s",
215  av[0], GET_USER(u));
216  chan_set_modes(s_ChanServ, uc->chan, 2, av, 1);
217  }
218  }
219 
220  free(av[0]);
221  return MOD_CONT;
222  }
223 
224  if (!(c = findchan(chan))) {
225  notice_lang(s_ChanServ, u, CHAN_X_NOT_IN_USE, chan);
226  } else if (!(ci = c->ci)) {
227  notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, c->name);
228  } else if (ci->flags & CI_VERBOTEN) {
229  notice_lang(s_ChanServ, u, CHAN_X_FORBIDDEN, ci->name);
230  } else if (!is_founder(u, ci)) {
231  notice_lang(s_ChanServ, u, ACCESS_DENIED);
232  } else if (!is_on_chan(c, u)) {
233  notice_lang(s_ChanServ, u, NICK_X_NOT_ON_CHAN, u->nick, c->name);
234  } else {
235  anope_cmd_mode(whosends(ci), c->name, "%s %s", ircd->ownerset,
236  GET_USER(u));
237 
238  av[0] = sstrdup(ircd->ownerset);
239  av[1] = GET_USER(u);
240  chan_set_modes(s_ChanServ, c, 2, av, 1);
241  free(av[0]);
242  }
243  return MOD_CONT;
244 }
245 
246 /*************************************************************************/
247 
248 static int do_deowner(User * u)
249 {
250  char *av[2];
251  char *chan = strtok(NULL, " ");
252 
253  Channel *c;
254  ChannelInfo *ci;
255  struct u_chanlist *uc;
256 
257  if (!ircd->owner) {
258  return MOD_CONT;
259  }
260 
261  if (!chan) {
262  av[0] = sstrdup(ircd->ownerunset);
263  av[1] = GET_USER(u);
264 
265  /* Sets the mode to the user on every channels he is on. */
266 
267  for (uc = u->chans; uc; uc = uc->next) {
268  if ((ci = uc->chan->ci) && !(ci->flags & CI_VERBOTEN)
269  && is_founder(u, ci)) {
270  anope_cmd_mode(whosends(ci), uc->chan->name, "%s %s",
271  av[0], GET_USER(u));
272  chan_set_modes(s_ChanServ, uc->chan, 2, av, 1);
273  }
274  }
275 
276  free(av[0]);
277  return MOD_CONT;
278  }
279 
280  if (!(c = findchan(chan))) {
281  notice_lang(s_ChanServ, u, CHAN_X_NOT_IN_USE, chan);
282  } else if (!(ci = c->ci)) {
283  notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, c->name);
284  } else if (ci->flags & CI_VERBOTEN) {
285  notice_lang(s_ChanServ, u, CHAN_X_FORBIDDEN, ci->name);
286  } else if (!is_founder(u, ci)) {
287  notice_lang(s_ChanServ, u, ACCESS_DENIED);
288  } else if (!is_on_chan(c, u)) {
289  notice_lang(s_ChanServ, u, NICK_X_NOT_ON_CHAN, u->nick, c->name);
290  } else {
291  anope_cmd_mode(whosends(ci), c->name, "%s %s", ircd->ownerunset,
292  GET_USER(u));
293 
294  av[0] = sstrdup(ircd->ownerunset);
295  av[1] = GET_USER(u);
296  chan_set_modes(s_ChanServ, c, 2, av, 1);
297  free(av[0]);
298  }
299  return MOD_CONT;
300 }
301 
302 /* do_util: not a command, but does the job of other */
303 
304 static int do_util(User * u, CSModeUtil * util)
305 {
306  char *av[2];
307  char *chan = strtok(NULL, " ");
308  char *nick = strtok(NULL, " ");
309 
310  Channel *c;
311  ChannelInfo *ci;
312  User *u2;
313 
314  int is_same;
315 
316  if (!chan) {
317  struct u_chanlist *uc;
318 
319  av[0] = util->mode;
320  av[1] = u->nick;
321 
322  /* Sets the mode to the user on every channels he is on. */
323 
324  for (uc = u->chans; uc; uc = uc->next) {
325  if ((ci = uc->chan->ci) && !(ci->flags & CI_VERBOTEN)
326  && check_access(u, ci, util->levelself)) {
327  anope_cmd_mode(whosends(ci), uc->chan->name, "%s %s",
328  util->mode, GET_USER(u));
329  chan_set_modes(s_ChanServ, uc->chan, 2, av, 2);
330 
331  if (util->notice && ci->flags & util->notice)
332  notice(whosends(ci), uc->chan->name,
333  "%s command used for %s by %s", util->name,
334  u->nick, u->nick);
335  }
336  }
337 
338  return MOD_CONT;
339  } else if (!nick) {
340  nick = u->nick;
341  }
342 
343  is_same = (nick == u->nick) ? 1 : (stricmp(nick, u->nick) == 0);
344 
345  if (!(c = findchan(chan))) {
346  notice_lang(s_ChanServ, u, CHAN_X_NOT_IN_USE, chan);
347  } else if (!(ci = c->ci)) {
348  notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, c->name);
349  } else if (ci->flags & CI_VERBOTEN) {
350  notice_lang(s_ChanServ, u, CHAN_X_FORBIDDEN, ci->name);
351  } else if (is_same ? !(u2 = u) : !(u2 = finduser(nick))) {
352  notice_lang(s_ChanServ, u, NICK_X_NOT_IN_USE, nick);
353  } else if (is_same ? !check_access(u, ci, util->levelself) :
354  !check_access(u, ci, util->level)) {
355  notice_lang(s_ChanServ, u, ACCESS_DENIED);
356  } else if (*util->mode == '-' && !is_same && (ci->flags & CI_PEACE)
357  && (get_access(u2, ci) >= get_access(u, ci))) {
358  notice_lang(s_ChanServ, u, PERMISSION_DENIED);
359  } else if (*util->mode == '-' && is_protected(u2) && !is_same) {
360  notice_lang(s_ChanServ, u, PERMISSION_DENIED);
361  } else if (!is_on_chan(c, u2)) {
362  notice_lang(s_ChanServ, u, NICK_X_NOT_ON_CHAN, u2->nick, c->name);
363  } else {
364  anope_cmd_mode(whosends(ci), c->name, "%s %s", util->mode,
365  GET_USER(u2));
366 
367  av[0] = util->mode;
368  av[1] = GET_USER(u2);
369  chan_set_modes(s_ChanServ, c, 2, av, 3);
370 
371  if (util->notice && ci->flags & util->notice)
372  notice(whosends(ci), c->name, "%s command used for %s by %s",
373  util->name, u2->nick, u->nick);
374  }
375  return MOD_CONT;
376 }
void AnopeFini(void)
Definition: cs_modes.c:81
char nick[NICKMAX]
Definition: services.h:875
char * ownerset
Definition: services.h:303
struct u_chanlist * next
Definition: services.h:899
E IRCDVar * ircd
Definition: extern.h:39
static int do_dehalfop(User *u)
Definition: cs_modes.c:159
E int check_access(User *user, ChannelInfo *ci, int what)
Definition: chanserv.c:1974
int levelself
Definition: services.h:831
E int stricmp(const char *s1, const char *s2)
Definition: compat.c:58
E void notice(char *source, char *dest, const char *fmt,...)
Definition: send.c:274
#define CI_VERBOTEN
Definition: services.h:725
E void chan_set_modes(const char *source, Channel *chan, int ac, char **av, int check)
Definition: channels.c:161
char * mode
Definition: services.h:828
static int do_owner(User *u)
Definition: cs_modes.c:192
#define MUT_VOICE
Definition: services.h:1351
static int do_deop(User *u)
Definition: cs_modes.c:127
struct user_::u_chanlist * chans
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
int AnopeInit(int argc, char **argv)
Definition: cs_modes.c:36
static int do_voice(User *u)
Definition: cs_modes.c:134
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
char * ownerunset
Definition: services.h:304
E Channel * findchan(const char *chan)
Definition: channels.c:394
E char * sstrdup(const char *s)
Definition: memory.c:105
#define CI_PEACE
Definition: services.h:721
uint32 flags
Definition: services.h:669
static int do_deowner(User *u)
Definition: cs_modes.c:248
static int do_util(User *u, CSModeUtil *util)
Definition: cs_modes.c:304
E User * finduser(const char *nick)
Definition: users.c:323
char * name
Definition: services.h:826
static int do_devoice(User *u)
Definition: cs_modes.c:141
static int do_deprotect(User *u)
Definition: cs_modes.c:181
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
int protect
Definition: services.h:333
static int do_op(User *u)
Definition: cs_modes.c:120
#define MOD_CONT
Definition: modules.h:54
#define MUT_HALFOP
Definition: services.h:1353
E int is_founder(User *user, ChannelInfo *ci)
Definition: chanserv.c:2255
static int do_protect(User *u)
Definition: cs_modes.c:170
#define whosends(ci)
Definition: extern.h:163
#define MUT_DEVOICE
Definition: services.h:1350
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
#define MUT_PROTECT
Definition: services.h:1355
static void myChanServHelp(User *u)
Definition: cs_modes.c:90
int admin
Definition: services.h:324
char name[CHANMAX]
Definition: services.h:1000
#define GET_USER(u)
Definition: services.h:270
int32 notice
Definition: services.h:829
int owner
Definition: services.h:302
#define MUT_DEPROTECT
Definition: services.h:1354
#define MUT_OP
Definition: services.h:1349
E char * s_ChanServ
Definition: extern.h:285
E int get_access(User *user, ChannelInfo *ci)
Definition: chanserv.c:2332
static int do_halfop(User *u)
Definition: cs_modes.c:148
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
int halfop
Definition: services.h:316
#define MUT_DEOP
Definition: services.h:1348
#define MUT_DEHALFOP
Definition: services.h:1352
#define MOD_UNIQUE
Definition: module.h:11
E CSModeUtil csmodeutils[]
Definition: extern.h:168