]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_chgname.cpp
86e01ad33cef16a9dbafca09aa8d78e32d28fed8
[user/henk/code/inspircd.git] / src / modules / m_chgname.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 CHGNAME command */
17
18 /** Handle /CHGNAME
19  */
20 class CommandChgname : public Command
21 {
22  public:
23         CommandChgname(Module* Creator) : Command(Creator,"CHGNAME", 2, 2)
24         {
25                 flags_needed = 'o';
26                 syntax = "<nick> <newname>";
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.MaxGecos)
41                 {
42                         user->WriteServ("NOTICE %s :*** GECOS too long", user->nick.c_str());
43                         return CMD_FAILURE;
44                 }
45
46                 if (IS_LOCAL(dest))
47                 {
48                         dest->ChangeName(parameters[1].c_str());
49                         ServerInstance->SNO->WriteGlobalSno('a', "%s used CHGNAME to change %s's real name to '%s'", user->nick.c_str(), dest->nick.c_str(), dest->fullname.c_str());
50                 }
51
52                 return CMD_SUCCESS;
53         }
54
55         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
56         {
57                 User* dest = ServerInstance->FindNick(parameters[0]);
58                 if (dest)
59                         return ROUTE_OPT_UCAST(dest->server);
60                 return ROUTE_LOCALONLY;
61         }
62 };
63
64
65 class ModuleChgName : public Module
66 {
67         CommandChgname cmd;
68
69 public:
70         ModuleChgName() : cmd(this)
71         {
72                 ServerInstance->AddCommand(&cmd);
73         }
74
75         virtual ~ModuleChgName()
76         {
77         }
78
79         virtual Version GetVersion()
80         {
81                 return Version("Provides support for the CHGNAME command", VF_OPTCOMMON | VF_VENDOR);
82         }
83
84 };
85
86 MODULE_INIT(ModuleChgName)