]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_chgname.cpp
506325eee19ceaaa51408bee732a8bdfdec3124a
[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'; syntax = "<nick> <newname>";
26                 TRANSLATE3(TR_NICK, TR_TEXT, TR_END);
27         }
28
29         CmdResult Handle(const std::vector<std::string> &parameters, User *user)
30         {
31                 User* dest = ServerInstance->FindNick(parameters[0]);
32
33                 if (!dest)
34                 {
35                         user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel", user->nick.c_str(), parameters[0].c_str());
36                         return CMD_FAILURE;
37                 }
38
39                 if (parameters[1].empty())
40                 {
41                         user->WriteServ("NOTICE %s :*** GECOS must be specified", user->nick.c_str());
42                         return CMD_FAILURE;
43                 }
44
45                 if (parameters[1].length() > ServerInstance->Config->Limits.MaxGecos)
46                 {
47                         user->WriteServ("NOTICE %s :*** GECOS too long", user->nick.c_str());
48                         return CMD_FAILURE;
49                 }
50
51                 if (IS_LOCAL(dest))
52                 {
53                         dest->ChangeName(parameters[1].c_str());
54                         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());
55                 }
56
57                 return CMD_SUCCESS;
58         }
59
60         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
61         {
62                 User* dest = ServerInstance->FindNick(parameters[0]);
63                 if (dest)
64                         return ROUTE_OPT_UCAST(dest->server);
65                 return ROUTE_LOCALONLY;
66         }
67 };
68
69
70 class ModuleChgName : public Module
71 {
72         CommandChgname cmd;
73
74 public:
75         ModuleChgName(InspIRCd* Me) : Module(Me), cmd(this)
76         {
77                 ServerInstance->AddCommand(&cmd);
78         }
79
80         virtual ~ModuleChgName()
81         {
82         }
83
84         virtual Version GetVersion()
85         {
86                 return Version("Provides support for the CHGNAME command", VF_OPTCOMMON | VF_VENDOR, API_VERSION);
87         }
88
89 };
90
91 MODULE_INIT(ModuleChgName)