Anope IRC Services  Version 1.8
os_svsnick.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_svsnick(User * u);
18 static void myOperServHelp(User * u);
19 
26 int AnopeInit(int argc, char **argv)
27 {
28  Command *c;
29 
30  moduleAddAuthor("Anope");
31  moduleAddVersion(VERSION_STRING);
33 
35  OPER_HELP_SVSNICK, -1, -1, -1, -1);
37 
39  if (!ircd->svsnick) {
40  return MOD_STOP;
41  }
42  return MOD_CONT;
43 }
44 
48 void AnopeFini(void)
49 {
50 
51 }
52 
53 
58 static void myOperServHelp(User * u)
59 {
60  if (is_services_admin(u) && u->isSuperAdmin) {
61  notice_lang(s_OperServ, u, OPER_HELP_CMD_SVSNICK);
62  }
63 }
64 
70 /* Forcefully change a user's nickname */
71 
72 static int do_svsnick(User * u)
73 {
74  char *nick = strtok(NULL, " ");
75  char *newnick = strtok(NULL, " ");
76 
77  NickAlias *na;
78  char *c;
79 
80  /* Only allow this if SuperAdmin is enabled */
81  if (!u->isSuperAdmin) {
82  notice_lang(s_OperServ, u, OPER_SUPER_ADMIN_ONLY);
83  return MOD_CONT;
84  }
85 
86  if (!nick || !newnick) {
87  syntax_error(s_OperServ, u, "SVSNICK", OPER_SVSNICK_SYNTAX);
88  return MOD_CONT;
89  }
90 
91  /* Truncate long nicknames to NICKMAX-2 characters */
92  if (strlen(newnick) > (NICKMAX - 2)) {
93  notice_lang(s_OperServ, u, NICK_X_TRUNCATED,
94  newnick, NICKMAX - 2, newnick);
95  newnick[NICKMAX - 2] = '\0';
96  }
97 
98  /* Check for valid characters */
99  if (*newnick == '-' || isdigit(*newnick)) {
100  notice_lang(s_OperServ, u, NICK_X_ILLEGAL, newnick);
101  return MOD_CONT;
102  }
103  for (c = newnick; *c && (c - newnick) < NICKMAX; c++) {
104  if (!isvalidnick(*c)) {
105  notice_lang(s_OperServ, u, NICK_X_ILLEGAL, newnick);
106  return MOD_CONT;
107  }
108  }
109 
110  /* Check for a nick in use or a forbidden/suspended nick */
111  if (!finduser(nick)) {
112  notice_lang(s_OperServ, u, NICK_X_NOT_IN_USE, nick);
113  } else if (stricmp(nick, newnick) && finduser(newnick)) {
114  notice_lang(s_OperServ, u, NICK_X_IN_USE, newnick);
115  } else if ((na = findnick(newnick)) && (na->status & NS_VERBOTEN)) {
116  notice_lang(s_OperServ, u, NICK_X_FORBIDDEN, newnick);
117  } else {
118  notice_lang(s_OperServ, u, OPER_SVSNICK_NEWNICK, nick, newnick);
119  anope_cmd_global(s_OperServ, "%s used SVSNICK to change %s to %s",
120  u->nick, nick, newnick);
121  anope_cmd_svsnick(nick, newnick, time(NULL));
122  }
123  return MOD_CONT;
124 }
char nick[NICKMAX]
Definition: services.h:875
E NickAlias * findnick(const char *nick)
Definition: db-merger.c:1857
E IRCDVar * ircd
Definition: extern.h:39
E int stricmp(const char *s1, const char *s2)
Definition: compat.c:58
int AnopeInit(int argc, char **argv)
Definition: os_svsnick.c:26
#define NS_VERBOTEN
Definition: services.h:1273
int isSuperAdmin
Definition: services.h:896
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
E void notice_lang(char *source, User *dest, int message,...)
Definition: send.c:169
MDE void moduleSetType(MODType type)
Definition: modules.c:818
E int is_services_root(User *u)
Definition: operserv.c:577
#define OPERSERV
Definition: modules.h:62
E char * s_OperServ
Definition: extern.h:289
#define MOD_STOP
Definition: modules.h:53
E User * finduser(const char *nick)
Definition: users.c:323
uint16 status
Definition: services.h:532
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
int svsnick
Definition: services.h:300
Command * c
Definition: ns_recover.c:17
MDE void moduleSetOperHelp(void(*func)(User *u))
Definition: modules.c:2126
#define MOD_CONT
Definition: modules.h:54
E int is_services_admin(User *u)
Definition: operserv.c:591
static void myOperServHelp(User *u)
Definition: os_svsnick.c:58
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
void AnopeFini(void)
Definition: os_svsnick.c:48
#define NICKMAX
Definition: config.h:62
static int do_svsnick(User *u)
Definition: os_svsnick.c:72
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
#define isvalidnick(c)
Definition: services.h:1407
#define MOD_UNIQUE
Definition: module.h:11
E void anope_cmd_global(char *source, const char *fmt,...)
Definition: ircd.c:506
E void anope_cmd_svsnick(char *nick, char *newnick, time_t when)
Definition: ircd.c:544