]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sanick.cpp
Remove InspIRCd* parameters and fields
[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://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->ForceNickChange(parameters[1].c_str()))
61                         {
62                                 ServerInstance->SNO->WriteToSnoMask('a', oldnick+" used SANICK to change "+newnick+" to "+parameters[1]);
63                                 ServerInstance->PI->SendSNONotice("A", oldnick+" used SANICK to change "+newnick+" to "+parameters[1]);
64                         }
65                         else
66                         {
67                                 ServerInstance->SNO->WriteToSnoMask('a', oldnick+" failed SANICK (from "+newnick+" to "+parameters[1]+")");
68                                 ServerInstance->PI->SendSNONotice("A", oldnick+" failed SANICK (from "+newnick+" to "+parameters[1]+")");
69                         }
70                 }
71
72                 return CMD_SUCCESS;
73         }
74
75         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
76         {
77                 User* dest = ServerInstance->FindNick(parameters[0]);
78                 if (dest)
79                         return ROUTE_OPT_UCAST(dest->server);
80                 return ROUTE_LOCALONLY;
81         }
82 };
83
84
85 class ModuleSanick : public Module
86 {
87         CommandSanick cmd;
88  public:
89         ModuleSanick()
90                 : cmd(this)
91         {
92                 ServerInstance->AddCommand(&cmd);
93         }
94
95         virtual ~ModuleSanick()
96         {
97         }
98
99         virtual Version GetVersion()
100         {
101                 return Version("Provides support for SANICK command", VF_OPTCOMMON | VF_VENDOR, API_VERSION);
102         }
103
104 };
105
106 MODULE_INIT(ModuleSanick)