]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_chgident.cpp
Change allocation of commands/modes
[user/henk/code/inspircd.git] / src / modules / m_chgident.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 the CHGIDENT command */
17
18 /** Handle /CHGIDENT
19  */
20 class CommandChgident : public Command
21 {
22  public:
23         CommandChgident (InspIRCd* Instance) : Command(Instance,"CHGIDENT", "o", 2)
24         {
25                 this->source = "m_chgident.so";
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].empty())
41                 {
42                         user->WriteServ("NOTICE %s :*** CHGIDENT: Ident must be specified", user->nick.c_str());
43                         return CMD_FAILURE;
44                 }
45
46                 if (parameters[1].length() > ServerInstance->Config->Limits.IdentMax)
47                 {
48                         user->WriteServ("NOTICE %s :*** CHGIDENT: Ident is too long", user->nick.c_str());
49                         return CMD_FAILURE;
50                 }
51
52                 if (!ServerInstance->IsIdent(parameters[1].c_str()))
53                 {
54                         user->WriteServ("NOTICE %s :*** CHGIDENT: Invalid characters in ident", user->nick.c_str());
55                         return CMD_FAILURE;
56                 }
57
58                 dest->ChangeIdent(parameters[1].c_str());
59
60                 if (!ServerInstance->ULine(user->server))
61                         ServerInstance->SNO->WriteToSnoMask(IS_LOCAL(dest) ? 'a' : 'A', "%s used CHGIDENT to change %s's ident to '%s'", user->nick.c_str(), dest->nick.c_str(), dest->ident.c_str());
62
63                 /* route it! */
64                 return CMD_SUCCESS;
65         }
66 };
67
68
69 class ModuleChgIdent : public Module
70 {
71         CommandChgident cmd;
72
73 public:
74         ModuleChgIdent(InspIRCd* Me) : Module(Me), cmd(Me)
75         {
76                 ServerInstance->AddCommand(&cmd);
77         }
78
79         virtual ~ModuleChgIdent()
80         {
81         }
82
83         virtual Version GetVersion()
84         {
85                 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
86         }
87
88 };
89
90 MODULE_INIT(ModuleChgIdent)
91