]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_nicklock.cpp
336a008c997b9af3857eef98d832bc2be532cab4
[user/henk/code/inspircd.git] / src / modules / m_nicklock.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  Inspire is copyright (C) 2002-2004 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 #include <stdio.h>
18 #include <string>
19 #include "users.h"
20 #include "channels.h"
21 #include "modules.h"
22 #include "helperfuncs.h"
23 #include "hashcomp.h"
24
25 /* $ModDesc: Provides the NICKLOCK command, allows an oper to chage a users nick and lock them to it until they quit */
26
27 Server *Srv;
28
29 char* dummy = "ON";
30          
31 void handle_nicklock(char **parameters, int pcnt, userrec *user)
32 {
33         userrec* source = Srv->FindNick(std::string(parameters[0]));
34         if (source)
35         {
36                 if (source->GetExt("nick_locked"))
37                 {
38                         WriteServ(user->fd,"946 %s %s :This user's nickname is already locked.",user->nick,source->nick);
39                         return;
40                 }
41                 if (Srv->IsNick(std::string(parameters[1])))
42                 {
43                         irc::string server = user->server;
44                         irc::string me = Srv->GetServerName().c_str();
45                         if (server == me)
46                         {
47                                 // give them a lock flag
48                                 Srv->SendOpers(std::string(user->nick)+" used NICKLOCK to change and hold "+std::string(parameters[0])+" to "+parameters[1]);
49                                 Srv->ChangeUserNick(source,std::string(parameters[1]));
50                                 // only attempt to set their lockflag after we know the change succeeded
51                                 userrec* s2 = Srv->FindNick(std::string(parameters[1]));
52                                 if (s2)
53                                         s2->Extend("nick_locked",dummy);
54                         }
55                         else
56                         {
57                                 WriteServ(user->fd,"947 %s %s :Can't lock the nickname of a non-local user",user->nick,source->nick);
58                         }
59                 }
60         }
61 }
62
63 void handle_nickunlock(char **parameters, int pcnt, userrec *user)
64 {
65         userrec* source = Srv->FindNick(std::string(parameters[0]));
66         if (source)
67         {
68                 source->Shrink("nick_locked");
69                 WriteServ(user->fd,"945 %s %s :Nickname now unlocked.",user->nick,source->nick);
70                 Srv->SendOpers(std::string(user->nick)+" used NICKUNLOCK on "+std::string(parameters[0]));
71         }
72 }
73
74
75 class ModuleNickLock : public Module
76 {
77  public:
78         ModuleNickLock()
79         {
80                 Srv = new Server;
81                 Srv->AddCommand("NICKLOCK",handle_nicklock,'o',2,"m_nicklock.so");
82                 Srv->AddCommand("NICKUNLOCK",handle_nickunlock,'o',1,"m_nicklock.so");
83         }
84         
85         virtual ~ModuleNickLock()
86         {
87         }
88         
89         virtual Version GetVersion()
90         {
91                 return Version(1,0,0,1,VF_VENDOR);
92         }
93
94         virtual int OnUserPreNick(userrec* user, std::string newnick)
95         {
96                 if (user->GetExt("nick_locked"))
97                 {
98                         WriteServ(user->fd,"447 %s :You cannot change your nickname (your nick is locked)",user->nick);
99                         return 1;
100                 }
101                 return 0;
102         }
103
104         virtual void OnUserQuit(userrec* user)
105         {
106                 user->Shrink("nick_locked");
107         }
108
109 };
110
111 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
112
113 class ModuleNickLockFactory : public ModuleFactory
114 {
115  public:
116         ModuleNickLockFactory()
117         {
118         }
119         
120         ~ModuleNickLockFactory()
121         {
122         }
123         
124         virtual Module * CreateModule()
125         {
126                 return new ModuleNickLock;
127         }
128         
129 };
130
131
132 extern "C" void * init_module( void )
133 {
134         return new ModuleNickLockFactory;
135 }
136