]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_chgname.cpp
667ddd928d1e80a2dd3290dd7ed2e7e64775f34e
[user/henk/code/inspircd.git] / src / modules / m_chgname.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
5  *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
6  *
7  * This file is part of InspIRCd.  InspIRCd is free software: you can
8  * redistribute it and/or modify it under the terms of the GNU General Public
9  * License as published by the Free Software Foundation, version 2.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20
21 #include "inspircd.h"
22
23 /* $ModDesc: Provides support for the CHGNAME command */
24
25 /** Handle /CHGNAME
26  */
27 class CommandChgname : public Command
28 {
29  public:
30         CommandChgname(Module* Creator) : Command(Creator,"CHGNAME", 2, 2)
31         {
32                 flags_needed = 'o';
33                 syntax = "<nick> <newname>";
34                 TRANSLATE3(TR_NICK, TR_TEXT, TR_END);
35         }
36
37         CmdResult Handle(const std::vector<std::string> &parameters, User *user)
38         {
39                 User* dest = ServerInstance->FindNick(parameters[0]);
40
41                 if (!dest)
42                 {
43                         user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel", user->nick.c_str(), parameters[0].c_str());
44                         return CMD_FAILURE;
45                 }
46
47                 if (parameters[1].empty())
48                 {
49                         user->WriteServ("NOTICE %s :*** CHGNAME: GECOS must be specified", user->nick.c_str());
50                         return CMD_FAILURE;
51                 }
52
53                 if (parameters[1].length() > ServerInstance->Config->Limits.MaxGecos)
54                 {
55                         user->WriteServ("NOTICE %s :*** GECOS too long", user->nick.c_str());
56                         return CMD_FAILURE;
57                 }
58
59                 if (IS_LOCAL(dest))
60                 {
61                         dest->ChangeName(parameters[1].c_str());
62                         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());
63                 }
64
65                 return CMD_SUCCESS;
66         }
67
68         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
69         {
70                 User* dest = ServerInstance->FindNick(parameters[0]);
71                 if (dest)
72                         return ROUTE_OPT_UCAST(dest->server);
73                 return ROUTE_LOCALONLY;
74         }
75 };
76
77
78 class ModuleChgName : public Module
79 {
80         CommandChgname cmd;
81
82 public:
83         ModuleChgName() : cmd(this)
84         {
85                 ServerInstance->AddCommand(&cmd);
86         }
87
88         virtual ~ModuleChgName()
89         {
90         }
91
92         virtual Version GetVersion()
93         {
94                 return Version("Provides support for the CHGNAME command", VF_OPTCOMMON | VF_VENDOR);
95         }
96
97 };
98
99 MODULE_INIT(ModuleChgName)