]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_chgident.cpp
7efe2e755120674898af354dadccd5fa81926da1
[user/henk/code/inspircd.git] / src / modules / m_chgident.cpp
1 #include <string>
2 #include "users.h"
3 #include "modules.h"
4 #include "helperfuncs.h"
5 #include "inspircd.h"
6
7 /* $ModDesc: Provides support for the CHGIDENT command */
8
9 extern InspIRCd* ServerInstance;
10
11 class cmd_chgident : public command_t
12 {
13         Server* Srv;
14  public:
15         cmd_chgident(Server* serv) : command_t("CHGIDENT", 'o', 2)
16         {
17                 this->source = "m_chgident.so";
18                 Srv = serv;
19                 syntax = "<nick> <newident>";
20         }
21         
22         void Handle(const char** parameters, int pcnt, userrec *user)
23         {
24                 userrec* dest = ServerInstance->FindNick(parameters[0]);
25
26                 if(dest)
27                 {
28                         if(!ServerInstance->IsIdent(parameters[1]))
29                         {
30                                 user->WriteServ("NOTICE %s :*** Invalid characters in ident", user->nick);
31                                 return;
32                         }
33                 
34                         ServerInstance->WriteOpers("%s used CHGIDENT to change %s's ident from '%s' to '%s'", user->nick, dest->nick, dest->ident, parameters[1]);
35                         strlcpy(dest->ident, parameters[1], IDENTMAX+2);
36                 }
37                 else
38                 {
39                         user->WriteServ("401 %s %s :No such nick/channel", user->nick, parameters[0]);
40                 }
41         }
42 };
43
44
45 class ModuleChgIdent : public Module
46 {
47         cmd_chgident* mycommand;
48         
49 public:
50         ModuleChgIdent(Server* Me) : Module::Module(Me)
51         {
52                 mycommand = new cmd_chgident(Me);
53                 Me->AddCommand(mycommand);
54         }
55         
56         virtual ~ModuleChgIdent()
57         {
58         }
59         
60         virtual Version GetVersion()
61         {
62                 return Version(1,0,0,0,VF_VENDOR);
63         }
64         
65 };
66
67 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
68
69 class ModuleChgIdentFactory : public ModuleFactory
70 {
71  public:
72         ModuleChgIdentFactory()
73         {
74         }
75         
76         ~ModuleChgIdentFactory()
77         {
78         }
79         
80         virtual Module * CreateModule(Server* Me)
81         {
82                 return new ModuleChgIdent(Me);
83         }
84         
85 };
86
87
88 extern "C" void * init_module( void )
89 {
90         return new ModuleChgIdentFactory;
91 }
92