]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_chgname.cpp
8879401248e3290a42d4ada47be14eec8223b8e2
[user/henk/code/inspircd.git] / src / modules / m_chgname.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/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 #include "users.h"
16 #include "modules.h"
17
18 /* $ModDesc: Provides support for the CHGNAME command */
19
20 /** Handle /CHGNAME
21  */
22 class cmd_chgname : public command_t
23 {
24  public:
25         cmd_chgname (InspIRCd* Instance) : command_t(Instance,"CHGNAME", 'o', 2)
26         {
27                 this->source = "m_chgname.so";
28                 syntax = "<nick> <newname>";
29         }
30         
31         CmdResult Handle(const char** parameters, int pcnt, userrec *user)
32         {
33                 userrec* dest = ServerInstance->FindNick(parameters[0]);
34
35                 if (!dest)
36                 {
37                         user->WriteServ("401 %s %s :No such nick/channel", user->nick, parameters[0]);
38                         return CMD_FAILURE;
39                 }
40                 
41                 if (!*parameters[1])
42                 {
43                         user->WriteServ("NOTICE %s :*** GECOS must be specified", user->nick);
44                         return CMD_FAILURE;
45                 }
46                 
47                 if (strlen(parameters[1]) > MAXGECOS)
48                 {
49                         user->WriteServ("NOTICE %s :*** GECOS too long", user->nick);
50                         return CMD_FAILURE;
51                 }
52                 
53                 if (IS_LOCAL(dest))
54                 {
55                         dest->ChangeName(parameters[1]);
56                         ServerInstance->WriteOpers("%s used CHGNAME to change %s's real name to '%s'", user->nick, dest->nick, dest->fullname);
57                         return CMD_LOCALONLY; /* name change routed by FNAME in spanningtree now */
58                 }
59
60                 /* route it! */
61                 return CMD_SUCCESS;
62         }
63 };
64
65
66 class ModuleChgName : public Module
67 {
68         cmd_chgname* mycommand;
69         
70         
71 public:
72         ModuleChgName(InspIRCd* Me) : Module(Me)
73         {
74                 mycommand = new cmd_chgname(ServerInstance);
75                 ServerInstance->AddCommand(mycommand);
76         }
77         
78         virtual ~ModuleChgName()
79         {
80         }
81         
82         virtual Version GetVersion()
83         {
84                 return Version(1,1,0,0,VF_VENDOR,API_VERSION);
85         }
86         
87 };
88
89 MODULE_INIT(ModuleChgName);