]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sanick.cpp
561bca613be5c260a418f3da6e14fd28d3a4a83b
[user/henk/code/inspircd.git] / src / modules / m_sanick.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 /* $ModDesc: Provides support for SANICK command */
26
27 static Server *Srv;
28
29 class cmd_sanick : public command_t
30 {
31  public:
32         cmd_sanick () : command_t("SANICK", 'o', 2)
33         {
34                 this->source = "m_sanick.so";
35                 syntax = "<nick> <new-nick>";
36         }
37
38         void Handle (const char** parameters, int pcnt, userrec *user)
39         {
40                 userrec* source = Srv->FindNick(std::string(parameters[0]));
41                 if (source)
42                 {
43                         if (Srv->IsUlined(source->server))
44                         {
45                                 WriteServ(user->fd,"990 %s :Cannot use an SA command on a u-lined client",user->nick);
46                                 return;
47                         }
48                         if (Srv->IsNick(std::string(parameters[1])))
49                         {
50                                 // FIX by brain: Cant use source->nick here because if it traverses a server link then
51                                 // source->nick becomes invalid as the object data moves in memory.
52                                 Srv->SendOpers(std::string(user->nick)+" used SANICK to change "+std::string(parameters[0])+" to "+parameters[1]);
53                                 if (!source->ForceNickChange(parameters[1]))
54                                 {
55                                         /* We couldnt change the nick */
56                                         userrec::QuitUser(source, "Nickname collision");
57                                         return;
58                                 }
59                         }
60                 }
61         }
62 };
63
64
65 class ModuleSanick : public Module
66 {
67         cmd_sanick*     mycommand;
68  public:
69         ModuleSanick(Server* Me)
70                 : Module::Module(Me)
71         {
72                 Srv = Me;
73                 mycommand = new cmd_sanick();
74                 Srv->AddCommand(mycommand);
75         }
76         
77         virtual ~ModuleSanick()
78         {
79         }
80         
81         virtual Version GetVersion()
82         {
83                 return Version(1,0,0,1,VF_VENDOR);
84         }
85         
86 };
87
88 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
89
90 class ModuleSanickFactory : public ModuleFactory
91 {
92  public:
93         ModuleSanickFactory()
94         {
95         }
96         
97         ~ModuleSanickFactory()
98         {
99         }
100         
101         virtual Module * CreateModule(Server* Me)
102         {
103                 return new ModuleSanick(Me);
104         }
105         
106 };
107
108
109 extern "C" void * init_module( void )
110 {
111         return new ModuleSanickFactory;
112 }
113