1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 /* $ModDesc: Provides the NICKLOCK command, allows an oper to chage a users nick and lock them to it until they quit */
20 class CommandNicklock : public Command
24 CommandNicklock (InspIRCd* Instance) : Command(Instance,"NICKLOCK", "o", 2)
26 this->source = "m_nicklock.so";
27 syntax = "<oldnick> <newnick>";
28 TRANSLATE3(TR_NICK, TR_TEXT, TR_END);
31 CmdResult Handle(const char* const* parameters, int pcnt, User *user)
33 User* target = ServerInstance->FindNick(parameters[0]);
43 // check if user is locked
44 if (target->GetExt("nick_locked", dummy))
46 user->WriteServ("946 %s %s :This user's nickname is already locked.",user->nick,target->nick);
50 // check nick is valid
51 if (!ServerInstance->IsNick(parameters[1]))
57 ServerInstance->SNO->WriteToSnoMask('A', std::string(user->nick)+" used NICKLOCK to change and hold "+parameters[0]+" to "+parameters[1]);
59 if (!target->ForceNickChange(parameters[1]))
61 // ugh, nickchange failed for some reason -- possibly existing nick?
62 User::QuitUser(ServerInstance, target, "Nickname collision");
65 // give them a lock flag
66 target->Extend("nick_locked", "ON");
73 /** Handle /NICKUNLOCK
75 class CommandNickunlock : public Command
78 CommandNickunlock (InspIRCd* Instance) : Command(Instance,"NICKUNLOCK", "o", 1)
80 this->source = "m_nicklock.so";
81 syntax = "<locked-nick>";
84 CmdResult Handle (const char* const* parameters, int pcnt, User *user)
86 User* target = ServerInstance->FindNick(parameters[0]);
89 target->Shrink("nick_locked");
90 user->WriteServ("945 %s %s :Nickname now unlocked.",user->nick,target->nick);
91 ServerInstance->SNO->WriteToSnoMask('A', std::string(user->nick)+" used NICKUNLOCK on "+parameters[0]);
100 class ModuleNickLock : public Module
102 CommandNicklock* cmd1;
103 CommandNickunlock* cmd2;
106 ModuleNickLock(InspIRCd* Me)
110 cmd1 = new CommandNicklock(ServerInstance);
111 cmd2 = new CommandNickunlock(ServerInstance);
112 ServerInstance->AddCommand(cmd1);
113 ServerInstance->AddCommand(cmd2);
114 Implementation eventlist[] = { I_OnUserPreNick, I_OnUserQuit, I_OnCleanup };
115 ServerInstance->Modules->Attach(eventlist, this, 3);
118 virtual ~ModuleNickLock()
122 virtual Version GetVersion()
124 return Version(1, 1, 0, 1, VF_COMMON | VF_VENDOR, API_VERSION);
128 virtual int OnUserPreNick(User* user, const std::string &newnick)
130 if (isdigit(newnick[0])) /* allow a switch to a UID */
133 if (user->GetExt("nick_locked", n))
135 user->WriteServ("447 %s :You cannot change your nickname (your nick is locked)",user->nick);
141 virtual void OnUserQuit(User* user, const std::string &reason, const std::string &oper_message)
143 user->Shrink("nick_locked");
146 virtual void OnCleanup(int target_type, void* item)
148 if(target_type == TYPE_USER)
150 User* user = (User*)item;
151 user->Shrink("nick_locked");
156 MODULE_INIT(ModuleNickLock)