]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_nicklock.cpp
6369e34d74d201e6d3e5dd1f22a3dae38d81384e
[user/henk/code/inspircd.git] / src / modules / m_nicklock.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 "helperfuncs.h"
25 #include "hashcomp.h"
26
27 /* $ModDesc: Provides the NICKLOCK command, allows an oper to chage a users nick and lock them to it until they quit */
28
29 static Server *Srv;
30
31 class cmd_nicklock : public command_t
32 {
33         char* dummy;
34  public:
35         cmd_nicklock () : command_t("NICKLOCK", 'o', 2)
36         {
37                 this->source = "m_nicklock.so";
38                 syntax = "<oldnick> <newnick>";
39         }
40
41         void Handle(const char** parameters, int pcnt, userrec *user)
42         {
43                 userrec* source = Srv->FindNick(std::string(parameters[0]));
44                 irc::string server;
45                 irc::string me;
46
47                 if (source)
48                 {
49                         if (source->GetExt("nick_locked", dummy))
50                         {
51                                 user->WriteServ("946 %s %s :This user's nickname is already locked.",user->nick,source->nick);
52                                 return;
53                         }
54                         if (Srv->IsNick(std::string(parameters[1])))
55                         {
56                                 // give them a lock flag
57                                 Srv->SendOpers(std::string(user->nick)+" used NICKLOCK to change and hold "+std::string(parameters[0])+" to "+parameters[1]);
58                                 if (!source->ForceNickChange(parameters[1]))
59                                 {
60                                         userrec::QuitUser(source, "Nickname collision");
61                                         return;
62                                 }
63                                 source->Extend("nick_locked", "ON");
64                         }
65                 }
66         }
67 };
68
69 class cmd_nickunlock : public command_t
70 {
71  public:
72         cmd_nickunlock () : command_t("NICKUNLOCK", 'o', 1)
73         {
74                 this->source = "m_nickunlock.so";
75                 syntax = "<locked-nick>";
76         }
77
78         void Handle (const char** parameters, int pcnt, userrec *user)
79         {
80                 userrec* source = Srv->FindNick(std::string(parameters[0]));
81                 if (source)
82                 {
83                         source->Shrink("nick_locked");
84                         user->WriteServ("945 %s %s :Nickname now unlocked.",user->nick,source->nick);
85                         Srv->SendOpers(std::string(user->nick)+" used NICKUNLOCK on "+std::string(parameters[0]));
86                 }
87         }
88 };
89
90
91 class ModuleNickLock : public Module
92 {
93         cmd_nicklock*   cmd1;
94         cmd_nickunlock* cmd2;
95         char* n;
96  public:
97         ModuleNickLock(Server* Me)
98                 : Module::Module(Me)
99         {
100                 Srv = Me;
101                 cmd1 = new cmd_nicklock();
102                 cmd2 = new cmd_nickunlock();
103                 Srv->AddCommand(cmd1);
104                 Srv->AddCommand(cmd2);
105         }
106         
107         virtual ~ModuleNickLock()
108         {
109         }
110         
111         virtual Version GetVersion()
112         {
113                 return Version(1,0,0,1,VF_VENDOR);
114         }
115
116         void Implements(char* List)
117         {
118                 List[I_OnUserPreNick] = List[I_OnUserQuit] = List[I_OnCleanup] = 1;
119         }
120
121         virtual int OnUserPreNick(userrec* user, const std::string &newnick)
122         {
123                 if (user->GetExt("nick_locked", n))
124                 {
125                         user->WriteServ("447 %s :You cannot change your nickname (your nick is locked)",user->nick);
126                         return 1;
127                 }
128                 return 0;
129         }
130
131         virtual void OnUserQuit(userrec* user, const std::string &reason)
132         {
133                 user->Shrink("nick_locked");
134         }
135
136         virtual void OnCleanup(int target_type, void* item)
137         {
138                 if(target_type == TYPE_USER)
139                 {
140                         userrec* user = (userrec*)item;
141                         user->Shrink("nick_locked");
142                 }
143         }
144 };
145
146 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
147
148 class ModuleNickLockFactory : public ModuleFactory
149 {
150  public:
151         ModuleNickLockFactory()
152         {
153         }
154         
155         ~ModuleNickLockFactory()
156         {
157         }
158         
159         virtual Module * CreateModule(Server* Me)
160         {
161                 return new ModuleNickLock(Me);
162         }
163         
164 };
165
166
167 extern "C" void * init_module( void )
168 {
169         return new ModuleNickLockFactory;
170 }
171