From af6e4d13ee931ff5a63a9ef3cae920a6b422fc50 Mon Sep 17 00:00:00 2001 From: danieldg Date: Wed, 2 Sep 2009 00:45:08 +0000 Subject: Update NICKLOCK to route using unicast git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11603 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modules/m_nicklock.cpp | 68 ++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/modules/m_nicklock.cpp b/src/modules/m_nicklock.cpp index cc6691717..b0f257cf9 100644 --- a/src/modules/m_nicklock.cpp +++ b/src/modules/m_nicklock.cpp @@ -47,12 +47,6 @@ class CommandNicklock : public Command return CMD_FAILURE; } - if (target->GetExt("nick_locked")) - { - user->WriteNumeric(946, "%s %s :This user's nickname is already locked.",user->nick.c_str(),target->nick.c_str()); - return CMD_FAILURE; - } - if (!ServerInstance->IsNick(parameters[1].c_str(), ServerInstance->Config->Limits.NickMax)) { user->WriteServ("NOTICE %s :*** Invalid nickname '%s'", user->nick.c_str(), parameters[1].c_str()); @@ -63,32 +57,34 @@ class CommandNicklock : public Command } /* If we made it this far, extend the user */ - if (target) + if (target && IS_LOCAL(target)) { // This has to be done *here*, because this metadata must be stored netwide. target->Extend("nick_locked", "ON"); /* Only send out nick from local server */ - if (IS_LOCAL(target)) + target->Extend("nick_locked"); + + std::string oldnick = target->nick; + if (target->ForceNickChange(parameters[1].c_str())) + ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used NICKLOCK to change and hold "+oldnick+" to "+parameters[1]); + else { - ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used NICKLOCK to change and hold "+target->nick+" to "+parameters[1]); - std::string oldnick = user->nick; std::string newnick = target->nick; - if (!target->ForceNickChange(parameters[1].c_str())) - { - /* XXX: We failed, this *should* not happen but if it does - * tell everybody. Note user is still nick locked on their old - * nick instead. - */ - ServerInstance->SNO->WriteToSnoMask('a', oldnick+" failed nickchange on NICKLOCK (from "+newnick+" to "+parameters[1]+") Locked to "+newnick+" instead"); - ServerInstance->PI->SendSNONotice("A", oldnick+" failed nickchange on NICKLOCK (from "+newnick+" to "+parameters[1]+") Locked to "+newnick+" instead"); - } + ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used NICKLOCK, but "+oldnick+" failed nick change to "+parameters[1]+" and was locked to "+newnick+" instead"); } } - /* Route it */ return CMD_SUCCESS; } + + RouteDescriptor GetRouting(User* user, const std::vector& parameters) + { + User* dest = ServerInstance->FindNick(parameters[0]); + if (dest) + return ROUTE_OPT_UCAST(dest->server); + return ROUTE_LOCALONLY; + } }; /** Handle /NICKUNLOCK @@ -100,6 +96,7 @@ class CommandNickunlock : public Command { this->source = "m_nicklock.so"; syntax = ""; + TRANSLATE2(TR_NICK, TR_END); } CmdResult Handle (const std::vector& parameters, User *user) @@ -120,26 +117,32 @@ class CommandNickunlock : public Command user->WriteServ("NOTICE %s :*** No such nickname: '%s'", user->nick.c_str(), parameters[0].c_str()); return CMD_FAILURE; } - - if (!target->GetExt("nick_locked")) - { - user->WriteNumeric(946, "%s %s :This user's nickname is not locked.",user->nick.c_str(),target->nick.c_str()); - return CMD_FAILURE; - } } - if (target) + if (target && IS_LOCAL(target)) { - target->Shrink("nick_locked"); - if (IS_LOCAL(target)) + if (target->Shrink("nick_locked")) + { ServerInstance->SNO->WriteGlobalSno('a', std::string(user->nick)+" used NICKUNLOCK on "+parameters[0]); - if (IS_LOCAL(user)) user->WriteNumeric(945, "%s %s :Nickname now unlocked.",user->nick.c_str(),target->nick.c_str()); + } + else + { + user->WriteNumeric(946, "%s %s :This user's nickname is not locked.",user->nick.c_str(),target->nick.c_str()); + return CMD_FAILURE; + } } - /* Route it */ return CMD_SUCCESS; } + + RouteDescriptor GetRouting(User* user, const std::vector& parameters) + { + User* dest = ServerInstance->FindNick(parameters[0]); + if (dest) + return ROUTE_OPT_UCAST(dest->server); + return ROUTE_LOCALONLY; + } }; @@ -147,7 +150,6 @@ class ModuleNickLock : public Module { CommandNicklock cmd1; CommandNickunlock cmd2; - char* n; public: ModuleNickLock(InspIRCd* Me) : Module(Me), cmd1(Me), cmd2(Me) @@ -179,7 +181,7 @@ class ModuleNickLock : public Module if (user->GetExt("NICKForced")) /* Allow forced nick changes */ return 0; - if (user->GetExt("nick_locked", n)) + if (user->GetExt("nick_locked")) { user->WriteNumeric(447, "%s :You cannot change your nickname (your nick is locked)",user->nick.c_str()); return 1; -- cgit v1.2.3