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