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