]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_setident.cpp
Optimize some more
[user/henk/code/inspircd.git] / src / modules / m_setident.cpp
1 #include "users.h"
2 #include "modules.h"
3 #include "inspircd.h"
4
5 /* $ModDesc: Provides support for the SETIDENT command */
6
7 class cmd_setident : public command_t
8 {
9  public:
10  cmd_setident (InspIRCd* Instance) : command_t(Instance,"SETIDENT", 'o', 1)
11         {
12                 this->source = "m_setident.so";
13                 syntax = "<new-ident>";
14         }
15
16         CmdResult Handle(const char** parameters, int pcnt, userrec *user)
17         {
18                 size_t len = 0;
19                 for(const char* x = parameters[0]; *x; x++, len++)
20                 {
21                         if(((*x >= 'A') && (*x <= '}')) || strchr(".-0123456789", *x))
22                                 continue;
23
24                         user->WriteServ("NOTICE %s :*** Invalid characters in ident", user->nick);
25                         return CMD_FAILURE;
26                 }
27                 if (len > IDENTMAX)
28                 {
29                         user->WriteServ("NOTICE %s :*** Ident is too long", user->nick);
30                         return CMD_FAILURE;
31                 }
32
33                 user->ChangeIdent(parameters[0]);
34                 ServerInstance->WriteOpers("%s used SETIDENT to change their ident to '%s'", user->nick, user->ident);
35
36                 return CMD_SUCCESS;
37         }
38 };
39
40
41 class ModuleSetIdent : public Module
42 {
43         cmd_setident*   mycommand;
44         
45  public:
46         ModuleSetIdent(InspIRCd* Me) : Module::Module(Me)
47         {
48                 
49                 mycommand = new cmd_setident(ServerInstance);
50                 ServerInstance->AddCommand(mycommand);
51         }
52         
53         virtual ~ModuleSetIdent()
54         {
55         }
56         
57         virtual Version GetVersion()
58         {
59                 return Version(1,0,0,0,VF_VENDOR,API_VERSION);
60         }
61         
62 };
63
64 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
65
66 class ModuleSetIdentFactory : public ModuleFactory
67 {
68  public:
69         ModuleSetIdentFactory()
70         {
71         }
72         
73         ~ModuleSetIdentFactory()
74         {
75         }
76         
77         virtual Module * CreateModule(InspIRCd* Me)
78         {
79                 return new ModuleSetIdent(Me);
80         }
81         
82 };
83
84
85 extern "C" void * init_module( void )
86 {
87         return new ModuleSetIdentFactory;
88 }
89