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