]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sanick.cpp
43cb9e6daa1755e2909113bd59f2bed4f6e97bee
[user/henk/code/inspircd.git] / src / modules / m_sanick.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include <stdio.h>
15 #include <string>
16 #include "users.h"
17 #include "channels.h"
18 #include "modules.h"
19 #include "inspircd.h"
20
21 /* $ModDesc: Provides support for SANICK command */
22
23 /** Handle /SANICK
24  */
25 class cmd_sanick : public command_t
26 {
27  public:
28  cmd_sanick (InspIRCd* Instance) : command_t(Instance,"SANICK", 'o', 2)
29         {
30                 this->source = "m_sanick.so";
31                 syntax = "<nick> <new-nick>";
32         }
33
34         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
35         {
36                 userrec* source = ServerInstance->FindNick(parameters[0]);
37                 if (source)
38                 {
39                         if (ServerInstance->ULine(source->server))
40                         {
41                                 user->WriteServ("990 %s :Cannot use an SA command on a u-lined client",user->nick);
42                                 return CMD_FAILURE;
43                         }
44                         std::string oldnick = user->nick;
45                         if (ServerInstance->IsNick(parameters[1]))
46                         {
47                                 if (source->ForceNickChange(parameters[1]))
48                                 {
49                                         ServerInstance->WriteOpers("*** " + oldnick+" used SANICK to change "+std::string(parameters[0])+" to "+parameters[1]);
50                                         return CMD_SUCCESS;
51                                 }
52                                 else
53                                 {
54                                         /* We couldnt change the nick */
55                                         ServerInstance->WriteOpers("*** " + oldnick+" failed SANICK (from "+std::string(parameters[0])+" to "+parameters[1]+")");
56                                         return CMD_FAILURE;
57                                 }
58                         }
59                         else
60                         {
61                                 user->WriteServ("NOTICE %s :*** Invalid nickname '%s'", user->nick, parameters[1]);
62                         }
63
64                         return CMD_FAILURE;
65                 }
66                 else
67                 {
68                         user->WriteServ("NOTICE %s :*** No such nickname: '%s'", user->nick, parameters[0]);
69                 }
70
71                 return CMD_FAILURE;
72         }
73 };
74
75
76 class ModuleSanick : public Module
77 {
78         cmd_sanick*     mycommand;
79  public:
80         ModuleSanick(InspIRCd* Me)
81                 : Module::Module(Me)
82         {
83                 
84                 mycommand = new cmd_sanick(ServerInstance);
85                 ServerInstance->AddCommand(mycommand);
86         }
87         
88         virtual ~ModuleSanick()
89         {
90         }
91         
92         virtual Version GetVersion()
93         {
94                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
95         }
96         
97 };
98
99 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
100
101 class ModuleSanickFactory : public ModuleFactory
102 {
103  public:
104         ModuleSanickFactory()
105         {
106         }
107         
108         ~ModuleSanickFactory()
109         {
110         }
111         
112         virtual Module * CreateModule(InspIRCd* Me)
113         {
114                 return new ModuleSanick(Me);
115         }
116         
117 };
118
119
120 extern "C" void * init_module( void )
121 {
122         return new ModuleSanickFactory;
123 }
124