]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sethost.cpp
Add extra parameter to OnUserPreNotice and OnUserPrePrivmsg, CUList &exempt_list...
[user/henk/code/inspircd.git] / src / modules / m_sethost.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 using namespace std;
18
19 #include <stdio.h>
20 #include <string>
21 #include "users.h"
22 #include "channels.h"
23 #include "modules.h"
24
25 #include "inspircd.h"
26
27 /* $ModDesc: Provides support for the SETHOST command */
28
29 /** Handle /SETHOST
30  */
31 class cmd_sethost : public command_t
32 {
33  public:
34         cmd_sethost (InspIRCd* Instance) : command_t(Instance,"SETHOST",'o',1)
35         {
36                 this->source = "m_sethost.so";
37                 syntax = "<new-hostname>";
38         }
39
40         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
41         {
42                 size_t len = 0;
43                 for (const char* x = parameters[0]; *x; x++, len++)
44                 {
45                         if (((tolower(*x) < 'a') || (tolower(*x) > 'z')) && (*x != '.'))
46                         {
47                                 if (((*x < '0') || (*x> '9')) && (*x != '-'))
48                                 {
49                                         user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Invalid characters in hostname");
50                                         return CMD_FAILURE;
51                                 }
52                         }
53                 }
54                 if (len > 64)
55                 {
56                         user->WriteServ("NOTICE %s :*** SETHOST: Host too long",user->nick);
57                         return CMD_FAILURE;
58                 }
59                 if (user->ChangeDisplayedHost(parameters[0]))
60                 {
61                         ServerInstance->WriteOpers(std::string(user->nick)+" used SETHOST to change their displayed host to "+user->dhost);
62                         return CMD_SUCCESS;
63                 }
64
65                 return CMD_FAILURE;
66         }
67 };
68
69
70 class ModuleSetHost : public Module
71 {
72         cmd_sethost*    mycommand;
73  public:
74         ModuleSetHost(InspIRCd* Me)
75                 : Module::Module(Me)
76         {
77                 
78                 mycommand = new cmd_sethost(ServerInstance);
79                 ServerInstance->AddCommand(mycommand);
80         }
81         
82         virtual ~ModuleSetHost()
83         {
84         }
85         
86         virtual Version GetVersion()
87         {
88                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
89         }
90         
91 };
92
93 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
94
95 class ModuleSetHostFactory : public ModuleFactory
96 {
97  public:
98         ModuleSetHostFactory()
99         {
100         }
101         
102         ~ModuleSetHostFactory()
103         {
104         }
105         
106         virtual Module * CreateModule(InspIRCd* Me)
107         {
108                 return new ModuleSetHost(Me);
109         }
110         
111 };
112
113
114 extern "C" void * init_module( void )
115 {
116         return new ModuleSetHostFactory;
117 }
118