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