]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sethost.cpp
cdb01de4dfeb811385bc2424fb8c2843dd41f1bd
[user/henk/code/inspircd.git] / src / modules / m_sethost.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  Inspire is copyright (C) 2002-2004 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 #include "helperfuncs.h"
25
26 /* $ModDesc: Provides support for the SETHOST command */
27
28 Server *Srv;
29          
30 void handle_sethost(char **parameters, int pcnt, userrec *user)
31 {
32         for (unsigned int x = 0; x < strlen(parameters[0]); x++)
33         {
34                 if (((tolower(parameters[0][x]) < 'a') || (tolower(parameters[0][x]) > 'z')) && (parameters[0][x] != '.'))
35                 {
36                         if (((parameters[0][x] < '0') || (parameters[0][x]> '9')) && (parameters[0][x] != '-'))
37                         {
38                                 Srv->SendTo(NULL,user,"NOTICE "+std::string(user->nick)+" :*** Invalid characters in hostname");
39                                 return;
40                         }
41                 }
42         }
43         Srv->ChangeHost(user,parameters[0]);
44         Srv->SendOpers(std::string(user->nick)+" used SETHOST to change their displayed host to "+std::string(parameters[0]));
45 }
46
47
48 class ModuleSetHost : public Module
49 {
50  public:
51         ModuleSetHost(Server* Me)
52                 : Module::Module(Me)
53         {
54                 Srv = Me;
55                 Srv->AddCommand("SETHOST",handle_sethost,'o',1,"m_sethost.so");
56         }
57         
58         virtual ~ModuleSetHost()
59         {
60         }
61         
62         virtual Version GetVersion()
63         {
64                 return Version(1,0,0,1,VF_VENDOR);
65         }
66         
67 };
68
69 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
70
71 class ModuleSetHostFactory : public ModuleFactory
72 {
73  public:
74         ModuleSetHostFactory()
75         {
76         }
77         
78         ~ModuleSetHostFactory()
79         {
80         }
81         
82         virtual Module * CreateModule(Server* Me)
83         {
84                 return new ModuleSetHost(Me);
85         }
86         
87 };
88
89
90 extern "C" void * init_module( void )
91 {
92         return new ModuleSetHostFactory;
93 }
94