]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sanick.cpp
55a6aae941b8598cff8f882be4f7438ea2a5e297
[user/henk/code/inspircd.git] / src / modules / m_sanick.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/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 (InspIRCd* Instance) : Command(Instance,"SANICK", "o", 2, false, 0)
24         {
25                 this->source = "m_sanick.so";
26                 syntax = "<nick> <new-nick>";
27                 TRANSLATE3(TR_NICK, TR_TEXT, TR_END);
28         }
29
30         CmdResult Handle (const std::vector<std::string>& parameters, User *user)
31         {
32                 User* target = ServerInstance->FindNick(parameters[0]);
33                 if (target)
34                 {
35                         if (ServerInstance->ULine(target->server))
36                         {
37                                 user->WriteNumeric(ERR_NOPRIVILEGES, "%s :Cannot use an SA command on a u-lined client",user->nick.c_str());
38                                 return CMD_FAILURE;
39                         }
40                         std::string oldnick = user->nick;
41                         if (IS_LOCAL(user) && !ServerInstance->IsNick(parameters[1].c_str(), ServerInstance->Config->Limits.NickMax))
42                         {
43                                 user->WriteServ("NOTICE %s :*** Invalid nickname '%s'", user->nick.c_str(), parameters[1].c_str());
44                         }
45                         else
46                         {
47                                 if (target->ForceNickChange(parameters[1].c_str()))
48                                 {
49                                         ServerInstance->SNO->WriteToSnoMask('A', oldnick+" used SANICK to change "+parameters[0]+" to "+parameters[1]);
50                                         return CMD_SUCCESS;
51                                 }
52                                 else
53                                 {
54                                         /* We couldnt change the nick */
55                                         ServerInstance->SNO->WriteToSnoMask('A', oldnick+" failed SANICK (from "+parameters[0]+" to "+parameters[1]+")");
56                                         return CMD_FAILURE;
57                                 }
58                         }
59
60                         return CMD_FAILURE;
61                 }
62                 else
63                 {
64                         user->WriteServ("NOTICE %s :*** No such nickname: '%s'", user->nick.c_str(), parameters[0].c_str());
65                 }
66
67                 return CMD_FAILURE;
68         }
69 };
70
71
72 class ModuleSanick : public Module
73 {
74         CommandSanick*  mycommand;
75  public:
76         ModuleSanick(InspIRCd* Me)
77                 : Module(Me)
78         {
79
80                 mycommand = new CommandSanick(ServerInstance);
81                 ServerInstance->AddCommand(mycommand);
82
83         }
84
85         virtual ~ModuleSanick()
86         {
87         }
88
89         virtual Version GetVersion()
90         {
91                 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
92         }
93
94 };
95
96 MODULE_INIT(ModuleSanick)