]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sanick.cpp
cdefe4abb4b56d21a0f403c9ea6a86907c902a61
[user/henk/code/inspircd.git] / src / modules / m_sanick.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 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
34                 /* Do local sanity checks and bails */
35                 if (IS_LOCAL(user))
36                 {
37                         if (target && ServerInstance->ULine(target->server))
38                         {
39                                 user->WriteNumeric(ERR_NOPRIVILEGES, "%s :Cannot use an SA command on a u-lined client",user->nick.c_str());
40                                 return CMD_FAILURE;
41                         }
42
43                         if (!target)
44                         {
45                                 user->WriteServ("NOTICE %s :*** No such nickname: '%s'", user->nick.c_str(), parameters[0].c_str());
46                                 return CMD_FAILURE;
47                         }
48
49                         if (!ServerInstance->IsNick(parameters[1].c_str(), ServerInstance->Config->Limits.NickMax))
50                         {
51                                 user->WriteServ("NOTICE %s :*** Invalid nickname '%s'", user->nick.c_str(), parameters[1].c_str());
52                                 return CMD_FAILURE;
53                         }
54                 }
55
56                 /* Have we hit target's server yet? */
57                 if (target && IS_LOCAL(target))
58                 {
59                         std::string oldnick = user->nick;
60                         std::string newnick = target->nick;
61                         if (target->ForceNickChange(parameters[1].c_str()))
62                         {
63                                 ServerInstance->SNO->WriteToSnoMask('A', oldnick+" used SANICK to change "+newnick+" to "+parameters[1]);
64                                 ServerInstance->PI->SendSNONotice("A", oldnick+" used SANICK to change "+newnick+" to "+parameters[1]);
65                         }
66                         else
67                         {
68                                 ServerInstance->SNO->WriteToSnoMask('A', oldnick+" failed SANICK (from "+newnick+" to "+parameters[1]+")");
69                                 ServerInstance->PI->SendSNONotice("A", oldnick+" failed SANICK (from "+newnick+" to "+parameters[1]+")");
70                         }
71                         /* Yes, hit target and we have sent our NICK out, we can now bail */
72                         return CMD_LOCALONLY;
73                 }
74
75                 /* No, route it on */
76                 return CMD_SUCCESS;
77         }
78 };
79
80
81 class ModuleSanick : public Module
82 {
83         CommandSanick*  mycommand;
84  public:
85         ModuleSanick(InspIRCd* Me)
86                 : Module(Me)
87         {
88
89                 mycommand = new CommandSanick(ServerInstance);
90                 ServerInstance->AddCommand(mycommand);
91
92         }
93
94         virtual ~ModuleSanick()
95         {
96         }
97
98         virtual Version GetVersion()
99         {
100                 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
101         }
102
103 };
104
105 MODULE_INIT(ModuleSanick)