]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_chgname.cpp
Add Module* creator to Command and ModeHandler
[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 (InspIRCd* Instance, Module* Creator) : Command(Instance, Creator,"CHGNAME", "o", 2, 2)
24         {
25                 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                 /* route it! */
58                 return CMD_SUCCESS;
59         }
60 };
61
62
63 class ModuleChgName : public Module
64 {
65         CommandChgname cmd;
66
67 public:
68         ModuleChgName(InspIRCd* Me) : Module(Me), cmd(Me, this)
69         {
70                 ServerInstance->AddCommand(&cmd);
71         }
72
73         virtual ~ModuleChgName()
74         {
75         }
76
77         virtual Version GetVersion()
78         {
79                 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
80         }
81
82 };
83
84 MODULE_INIT(ModuleChgName)