]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_chgident.cpp
...because every now and again, i have to do a massive commit.
[user/henk/code/inspircd.git] / src / modules / m_chgident.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 the CHGIDENT command */
17
18 /** Handle /CHGIDENT
19  */
20 class CommandChgident : public Command
21 {
22  public:
23         CommandChgident(Module* Creator) : Command(Creator,"CHGIDENT", 2)
24         {
25                 flags_needed = 'o';
26                 syntax = "<nick> <newident>";
27                 TRANSLATE3(TR_NICK, TR_TEXT, TR_END);
28         }
29
30         CmdResult Handle(const std::vector<std::string> &parameters, User *user)
31         {
32                 User* dest = ServerInstance->FindNick(parameters[0]);
33
34                 if (!dest)
35                 {
36                         user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel", user->nick.c_str(), parameters[0].c_str());
37                         return CMD_FAILURE;
38                 }
39
40                 if (parameters[1].length() > ServerInstance->Config->Limits.IdentMax)
41                 {
42                         user->WriteServ("NOTICE %s :*** CHGIDENT: Ident is too long", user->nick.c_str());
43                         return CMD_FAILURE;
44                 }
45
46                 if (!ServerInstance->IsIdent(parameters[1].c_str()))
47                 {
48                         user->WriteServ("NOTICE %s :*** CHGIDENT: Invalid characters in ident", user->nick.c_str());
49                         return CMD_FAILURE;
50                 }
51
52                 if (IS_LOCAL(dest))
53                 {
54                         dest->ChangeIdent(parameters[1].c_str());
55
56                         if (!ServerInstance->ULine(user->server))
57                                 ServerInstance->SNO->WriteGlobalSno('a', "%s used CHGIDENT to change %s's ident to '%s'", user->nick.c_str(), dest->nick.c_str(), dest->ident.c_str());
58                 }
59
60                 return CMD_SUCCESS;
61         }
62
63         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
64         {
65                 User* dest = ServerInstance->FindNick(parameters[0]);
66                 if (dest)
67                         return ROUTE_OPT_UCAST(dest->server);
68                 return ROUTE_LOCALONLY;
69         }
70 };
71
72
73 class ModuleChgIdent : public Module
74 {
75         CommandChgident cmd;
76
77 public:
78         ModuleChgIdent() : cmd(this)
79         {
80                 ServerInstance->AddCommand(&cmd);
81         }
82
83         virtual ~ModuleChgIdent()
84         {
85         }
86
87         virtual Version GetVersion()
88         {
89                 return Version("Provides support for the CHGIDENT command", VF_OPTCOMMON | VF_VENDOR);
90         }
91
92 };
93
94 MODULE_INIT(ModuleChgIdent)
95