1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 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 std::vector<std::string>& parameters, User *user)
33 User* target = ServerInstance->FindNick(parameters[0]);
43 // check if user is locked
44 if (target->GetExt("nick_locked", dummy))
46 user->WriteNumeric(946, "%s %s :This user's nickname is already locked.",user->nick.c_str(),target->nick.c_str());
50 // check nick is valid
51 if (IS_LOCAL(user) && !ServerInstance->IsNick(parameters[1].c_str(), ServerInstance->Config->Limits.NickMax))
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].c_str()))
61 // ugh, nickchange failed for some reason -- possibly existing nick?
62 if (!target->ForceNickChange(target->uuid.c_str()))
64 // Well shit, we cant even change them to their UID (this should not happen!)
65 ServerInstance->Users->QuitUser(target, "Nickname collision");
69 // give them a lock flag
70 target->Extend("nick_locked", "ON");
77 /** Handle /NICKUNLOCK
79 class CommandNickunlock : public Command
82 CommandNickunlock (InspIRCd* Instance) : Command(Instance,"NICKUNLOCK", "o", 1)
84 this->source = "m_nicklock.so";
85 syntax = "<locked-nick>";
88 CmdResult Handle (const std::vector<std::string>& parameters, User *user)
90 User* target = ServerInstance->FindNick(parameters[0]);
93 target->Shrink("nick_locked");
94 user->WriteNumeric(945, "%s %s :Nickname now unlocked.",user->nick.c_str(),target->nick.c_str());
95 ServerInstance->SNO->WriteToSnoMask('A', std::string(user->nick)+" used NICKUNLOCK on "+parameters[0]);
104 class ModuleNickLock : public Module
106 CommandNicklock* cmd1;
107 CommandNickunlock* cmd2;
110 ModuleNickLock(InspIRCd* Me)
114 cmd1 = new CommandNicklock(ServerInstance);
115 cmd2 = new CommandNickunlock(ServerInstance);
116 ServerInstance->AddCommand(cmd1);
117 ServerInstance->AddCommand(cmd2);
118 Implementation eventlist[] = { I_OnUserPreNick, I_OnUserQuit, I_OnCleanup };
119 ServerInstance->Modules->Attach(eventlist, this, 3);
122 virtual ~ModuleNickLock()
126 virtual Version GetVersion()
128 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
132 virtual int OnUserPreNick(User* user, const std::string &newnick)
134 if (isdigit(newnick[0])) /* allow a switch to a UID */
137 if (user->GetExt("nick_locked", n))
139 user->WriteNumeric(447, "%s :You cannot change your nickname (your nick is locked)",user->nick.c_str());
145 virtual void OnUserQuit(User* user, const std::string &reason, const std::string &oper_message)
147 user->Shrink("nick_locked");
152 Module *nflood = ServerInstance->Modules->Find("m_nickflood.so");
153 ServerInstance->Modules->SetPriority(this, I_OnUserPreJoin, PRIO_BEFORE, &nflood);
156 virtual void OnCleanup(int target_type, void* item)
158 if(target_type == TYPE_USER)
160 User* user = (User*)item;
161 user->Shrink("nick_locked");
166 MODULE_INIT(ModuleNickLock)