The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download | Blog | Stats
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

m_chgname.cpp

Go to the documentation of this file.
00001 /*       +------------------------------------+
00002  *       | Inspire Internet Relay Chat Daemon |
00003  *       +------------------------------------+
00004  *
00005  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
00006  * See: http://www.inspircd.org/wiki/index.php/Credits
00007  *
00008  * This program is free but copyrighted software; see
00009  *            the file COPYING for details.
00010  *
00011  * ---------------------------------------------------
00012  */
00013 
00014 #include "inspircd.h"
00015 #include "users.h"
00016 #include "modules.h"
00017 
00018 /* $ModDesc: Provides support for the CHGNAME command */
00019 
00022 class cmd_chgname : public command_t
00023 {
00024  public:
00025         cmd_chgname (InspIRCd* Instance) : command_t(Instance,"CHGNAME", 'o', 2)
00026         {
00027                 this->source = "m_chgname.so";
00028                 syntax = "<nick> <newname>";
00029         }
00030         
00031         CmdResult Handle(const char** parameters, int pcnt, userrec *user)
00032         {
00033                 userrec* dest = ServerInstance->FindNick(parameters[0]);
00034 
00035                 if (!dest)
00036                 {
00037                         user->WriteServ("401 %s %s :No such nick/channel", user->nick, parameters[0]);
00038                         return CMD_FAILURE;
00039                 }
00040                 
00041                 if (!*parameters[1])
00042                 {
00043                         user->WriteServ("NOTICE %s :*** GECOS must be specified", user->nick);
00044                         return CMD_FAILURE;
00045                 }
00046                 
00047                 if (strlen(parameters[1]) > MAXGECOS)
00048                 {
00049                         user->WriteServ("NOTICE %s :*** GECOS too long", user->nick);
00050                         return CMD_FAILURE;
00051                 }
00052                 
00053                 if (IS_LOCAL(dest))
00054                 {
00055                         dest->ChangeName(parameters[1]);
00056                         ServerInstance->WriteOpers("%s used CHGNAME to change %s's real name to '%s'", user->nick, dest->nick, dest->fullname);
00057                         return CMD_LOCALONLY; /* name change routed by FNAME in spanningtree now */
00058                 }
00059 
00060                 /* route it! */
00061                 return CMD_SUCCESS;
00062         }
00063 };
00064 
00065 
00066 class ModuleChgName : public Module
00067 {
00068         cmd_chgname* mycommand;
00069         
00070         
00071 public:
00072         ModuleChgName(InspIRCd* Me) : Module(Me)
00073         {
00074                 mycommand = new cmd_chgname(ServerInstance);
00075                 ServerInstance->AddCommand(mycommand);
00076         }
00077         
00078         virtual ~ModuleChgName()
00079         {
00080         }
00081         
00082         virtual Version GetVersion()
00083         {
00084                 return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
00085         }
00086         
00087 };
00088 
00089 MODULE_INIT(ModuleChgName)