Anope IRC Services  Version 1.8
os_chankill.c
Go to the documentation of this file.
1 /* OperServ 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_chankill(User * u);
18 static void myOperServHelp(User * u);
19 
26 int AnopeInit(int argc, char **argv)
27 {
28  Command *c;
29 
30  moduleAddAuthor("Anope");
32  (VERSION_STRING);
34 
36  OPER_HELP_CHANKILL, -1, -1, -1, -1);
38 
40 
41  return MOD_CONT;
42 }
43 
47 void AnopeFini(void)
48 {
49 
50 }
51 
52 
53 
58 static void myOperServHelp(User * u)
59 {
60  if (is_services_admin(u)) {
61  notice_lang(s_OperServ, u, OPER_HELP_CMD_CHANKILL);
62  }
63 }
64 
73 static int do_chankill(User * u)
74 {
75  char *expiry, *channel, *reason;
76  time_t expires;
77  char breason[BUFSIZE];
78  char mask[USERMAX + HOSTMAX + 2];
79  struct c_userlist *cu, *next;
80  Channel *c;
81 
82  channel = strtok(NULL, " ");
83  if (channel && *channel == '+') {
84  expiry = channel;
85  channel = strtok(NULL, " ");
86  } else {
87  expiry = NULL;
88  }
89 
90  expires = expiry ? dotime(expiry) : ChankillExpiry;
91  if (expiry && isdigit(expiry[strlen(expiry) - 1]))
92  expires *= 86400;
93  if (expires != 0 && expires < 60) {
94  notice_lang(s_OperServ, u, BAD_EXPIRY_TIME);
95  return MOD_CONT;
96  } else if (expires > 0) {
97  expires += time(NULL);
98  }
99 
100  if (channel && (reason = strtok(NULL, ""))) {
101 
102  if (AddAkiller) {
103  snprintf(breason, sizeof(breason), "[%s] %s", u->nick, reason);
104  reason = sstrdup(breason);
105  }
106 
107  if ((c = findchan(channel))) {
108  for (cu = c->users; cu; cu = next) {
109  next = cu->next;
110  if (is_oper(cu->user)) {
111  continue;
112  }
113  (void) strncpy(mask, "*@", 3); /* Use *@" for the akill's, */
114  strncat(mask, cu->user->host, HOSTMAX);
115  add_akill(NULL, mask, s_OperServ, expires, reason);
116  check_akill(cu->user->nick, cu->user->username,
117  cu->user->host, NULL, NULL);
118  }
119  if (WallOSAkill) {
120  anope_cmd_global(s_OperServ, "%s used CHANKILL on %s (%s)",
121  u->nick, channel, reason);
122  }
123  } else {
124  notice_lang(s_OperServ, u, CHAN_X_NOT_IN_USE, channel);
125  }
126  if (AddAkiller) {
127  free(reason);
128  }
129  } else {
130  syntax_error(s_OperServ, u, "CHANKILL", OPER_CHANKILL_SYNTAX);
131  }
132  return MOD_CONT;
133 }
E int is_oper(User *user)
Definition: users.c:937
E int WallOSAkill
Definition: extern.h:454
char nick[NICKMAX]
Definition: services.h:875
E int snprintf(char *buf, size_t size, const char *fmt,...)
Definition: compat.c:37
E int dotime(const char *s)
Definition: misc.c:364
MDE void moduleAddAuthor(const char *author)
Definition: modules.c:1772
E int add_akill(User *u, char *mask, const char *by, const time_t expires, const char *reason)
Definition: operserv.c:722
E void syntax_error(char *service, User *u, const char *command, int msgnum)
Definition: language.c:295
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
E char * sstrdup(const char *s)
Definition: memory.c:105
#define OPERSERV
Definition: modules.h:62
E char * s_OperServ
Definition: extern.h:289
E int check_akill(char *nick, const char *username, const char *host, const char *vhost, const char *ip)
Definition: operserv.c:847
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
Command * c
Definition: ns_recover.c:17
MDE void moduleSetOperHelp(void(*func)(User *u))
Definition: modules.c:2126
static void myOperServHelp(User *u)
Definition: os_chankill.c:58
#define MOD_CONT
Definition: modules.h:54
E int is_services_admin(User *u)
Definition: operserv.c:591
void AnopeFini(void)
Definition: os_chankill.c:47
static int do_chankill(User *u)
Definition: os_chankill.c:73
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
E int ChankillExpiry
Definition: extern.h:440
#define USERMAX
Definition: config.h:68
int AnopeInit(int argc, char **argv)
Definition: os_chankill.c:26
E int AddAkiller
Definition: extern.h:470
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
#define BUFSIZE
Definition: config.h:47
#define HOSTMAX
Definition: config.h:71
#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