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