]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sanick.cpp
Same again
[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 /** Handle /SANICK
29  */
30 class cmd_sanick : public command_t
31 {
32  public:
33  cmd_sanick (InspIRCd* Instance) : command_t(Instance,"SANICK", 'o', 2)
34         {
35                 this->source = "m_sanick.so";
36                 syntax = "<nick> <new-nick>";
37         }
38
39         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
40         {
41                 userrec* source = ServerInstance->FindNick(parameters[0]);
42                 if (source)
43                 {
44                         if (ServerInstance->ULine(source->server))
45                         {
46                                 user->WriteServ("990 %s :Cannot use an SA command on a u-lined client",user->nick);
47                                 return CMD_FAILURE;
48                         }
49                         std::string oldnick = user->nick;
50                         if (ServerInstance->IsNick(parameters[1]))
51                         {
52                                 if (source->ForceNickChange(parameters[1]))
53                                 {
54                                         ServerInstance->WriteOpers(oldnick+" used SANICK to change "+std::string(parameters[0])+" to "+parameters[1]);
55                                         return CMD_SUCCESS;
56                                 }
57                                 else
58                                 {
59                                         /* We couldnt change the nick */
60                                         ServerInstance->WriteOpers(oldnick+" failed SANICK (from "+std::string(parameters[0])+" to "+parameters[1]+")");
61                                         return CMD_FAILURE;
62                                 }
63                         }
64                         else
65                         {
66                                 user->WriteServ("NOTICE %s :*** Invalid nickname '%s'", user->nick, parameters[1]);
67                         }
68
69                         return CMD_FAILURE;
70                 }
71                 else
72                 {
73                         user->WriteServ("NOTICE %s :*** No such nickname: '%s'", user->nick, parameters[0]);
74                 }
75
76                 return CMD_FAILURE;
77         }
78 };
79
80
81 class ModuleSanick : public Module
82 {
83         cmd_sanick*     mycommand;
84  public:
85         ModuleSanick(InspIRCd* Me)
86                 : Module::Module(Me)
87         {
88                 
89                 mycommand = new cmd_sanick(ServerInstance);
90                 ServerInstance->AddCommand(mycommand);
91         }
92         
93         virtual ~ModuleSanick()
94         {
95         }
96         
97         virtual Version GetVersion()
98         {
99                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
100         }
101         
102 };
103
104 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
105
106 class ModuleSanickFactory : public ModuleFactory
107 {
108  public:
109         ModuleSanickFactory()
110         {
111         }
112         
113         ~ModuleSanickFactory()
114         {
115         }
116         
117         virtual Module * CreateModule(InspIRCd* Me)
118         {
119                 return new ModuleSanick(Me);
120         }
121         
122 };
123
124
125 extern "C" void * init_module( void )
126 {
127         return new ModuleSanickFactory;
128 }
129