]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sanick.cpp
Fix unsafe iteration in m_timedbans
[user/henk/code/inspircd.git] / src / modules / m_sanick.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15
16 /* $ModDesc: Provides support for SANICK command */
17
18 /** Handle /SANICK
19  */
20 class CommandSanick : public Command
21 {
22  public:
23         CommandSanick(Module* Creator) : Command(Creator,"SANICK", 2)
24         {
25                 flags_needed = 'o'; Penalty = 0; syntax = "<nick> <new-nick>";
26                 TRANSLATE3(TR_NICK, TR_TEXT, TR_END);
27         }
28
29         CmdResult Handle (const std::vector<std::string>& parameters, User *user)
30         {
31                 User* target = ServerInstance->FindNick(parameters[0]);
32
33                 /* Do local sanity checks and bails */
34                 if (IS_LOCAL(user))
35                 {
36                         if (target && ServerInstance->ULine(target->server))
37                         {
38                                 user->WriteNumeric(ERR_NOPRIVILEGES, "%s :Cannot use an SA command on a u-lined client",user->nick.c_str());
39                                 return CMD_FAILURE;
40                         }
41
42                         if (!target)
43                         {
44                                 user->WriteServ("NOTICE %s :*** No such nickname: '%s'", user->nick.c_str(), parameters[0].c_str());
45                                 return CMD_FAILURE;
46                         }
47
48                         if (!ServerInstance->IsNick(parameters[1].c_str(), ServerInstance->Config->Limits.NickMax))
49                         {
50                                 user->WriteServ("NOTICE %s :*** Invalid nickname '%s'", user->nick.c_str(), parameters[1].c_str());
51                                 return CMD_FAILURE;
52                         }
53                 }
54
55                 /* Have we hit target's server yet? */
56                 if (target && IS_LOCAL(target))
57                 {
58                         std::string oldnick = user->nick;
59                         std::string newnick = target->nick;
60                         if (target->ChangeNick(parameters[1], true))
61                         {
62                                 ServerInstance->SNO->WriteGlobalSno('a', oldnick+" used SANICK to change "+newnick+" to "+parameters[1]);
63                         }
64                         else
65                         {
66                                 ServerInstance->SNO->WriteGlobalSno('a', oldnick+" failed SANICK (from "+newnick+" to "+parameters[1]+")");
67                         }
68                 }
69
70                 return CMD_SUCCESS;
71         }
72
73         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
74         {
75                 User* dest = ServerInstance->FindNick(parameters[0]);
76                 if (dest)
77                         return ROUTE_OPT_UCAST(dest->server);
78                 return ROUTE_LOCALONLY;
79         }
80 };
81
82
83 class ModuleSanick : public Module
84 {
85         CommandSanick cmd;
86  public:
87         ModuleSanick()
88                 : cmd(this)
89         {
90                 ServerInstance->AddCommand(&cmd);
91         }
92
93         virtual ~ModuleSanick()
94         {
95         }
96
97         virtual Version GetVersion()
98         {
99                 return Version("Provides support for SANICK command", VF_OPTCOMMON | VF_VENDOR);
100         }
101
102 };
103
104 MODULE_INIT(ModuleSanick)