]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Get rid of the OnRemoteKill hook, make use of GetRouting() and TR_CUSTOM to route...
authorattilamolnar <attilamolnar@hush.com>
Wed, 12 Jun 2013 19:22:37 +0000 (21:22 +0200)
committerattilamolnar <attilamolnar@hush.com>
Wed, 12 Jun 2013 19:22:37 +0000 (21:22 +0200)
include/modules.h
src/commands/cmd_kill.cpp
src/modules.cpp
src/modules/m_spanningtree/main.cpp
src/modules/m_spanningtree/main.h
src/modules/m_testnet.cpp

index a26b6e8570154f6d3913eebd1554928754f177be..0c521332aa90de7c05a71240f138710d587c09e4 100644 (file)
@@ -328,7 +328,7 @@ enum Implementation
        I_OnUserMessage, I_OnMode, I_OnGetServerDescription, I_OnSyncUser,
        I_OnSyncChannel, I_OnDecodeMetaData, I_OnAcceptConnection, I_OnUserInit,
        I_OnChangeHost, I_OnChangeName, I_OnAddLine, I_OnDelLine, I_OnExpireLine,
-       I_OnUserPostNick, I_OnPreMode, I_On005Numeric, I_OnKill, I_OnRemoteKill, I_OnLoadModule,
+       I_OnUserPostNick, I_OnPreMode, I_On005Numeric, I_OnKill, I_OnLoadModule,
        I_OnUnloadModule, I_OnBackgroundTimer, I_OnPreCommand, I_OnCheckReady, I_OnCheckInvite,
        I_OnRawMode, I_OnCheckKey, I_OnCheckLimit, I_OnCheckBan, I_OnCheckChannelBan, I_OnExtBanCheck,
        I_OnStats, I_OnChangeLocalUserHost, I_OnPreTopicChange,
@@ -861,14 +861,6 @@ class CoreExport Module : public classbase, public usecountbase
         */
        virtual ModResult OnKill(User* source, User* dest, const std::string &reason);
 
-       /** Called when an oper wants to disconnect a remote user via KILL
-        * @param source The user sending the KILL
-        * @param dest The user being killed
-        * @param reason The kill reason
-        * @param operreason The oper kill reason
-        */
-       virtual void OnRemoteKill(User* source, User* dest, const std::string &reason, const std::string &operreason);
-
        /** Called whenever a module is loaded.
         * mod will contain a pointer to the module, and string will contain its name,
         * for example m_widgets.so. This function is primary for dependency checking,
index 04a59f60aa23f04165d113043475d92f29516858..74024f84e3bfcaccd4249f08791a889271663028 100644 (file)
  */
 class CommandKill : public Command
 {
+       std::string lastuuid;
+       std::string killreason;
+
  public:
        /** Constructor for kill.
         */
        CommandKill ( Module* parent) : Command(parent,"KILL",2,2) {
                flags_needed = 'o';
                syntax = "<nickname> <reason>";
-               TRANSLATE3(TR_NICK, TR_TEXT, TR_END);
+               TRANSLATE3(TR_CUSTOM, TR_CUSTOM, TR_END);
        }
        /** Handle command.
         * @param parameters The parameters to the comamnd
@@ -45,11 +48,21 @@ class CommandKill : public Command
        CmdResult Handle(const std::vector<std::string>& parameters, User *user);
        RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
        {
-               // local kills of remote users are routed via the OnRemoteKill hook
-               if (IS_LOCAL(user))
+               // FindNick() doesn't work here because we quit the target user in Handle() which
+               // removes it from the nicklist, so we check lastuuid: if it's empty then this KILL
+               // was for a local user, otherwise it contains the uuid of the user who was killed.
+               if (lastuuid.empty())
                        return ROUTE_LOCALONLY;
                return ROUTE_BROADCAST;
        }
+
+       void EncodeParameter(std::string& param, int index)
+       {
+               // Manually translate the nick -> uuid (see above), and also the reason (params[1])
+               // because we decorate it if the oper is local and want remote servers to see the
+               // decorated reason not the original.
+               param = ((index == 0) ? lastuuid : killreason);
+       }
 };
 
 /** Handle /KILL
@@ -58,7 +71,11 @@ CmdResult CommandKill::Handle (const std::vector<std::string>& parameters, User
 {
        /* Allow comma seperated lists of users for /KILL (thanks w00t) */
        if (CommandParser::LoopCall(user, this, parameters, 0))
-               return CMD_SUCCESS;
+       {
+               // If we got a colon delimited list of nicks then the handler ran for each nick,
+               // and KILL commands were broadcast for remote targets.
+               return CMD_FAILURE;
+       }
 
        User *u = ServerInstance->FindNick(parameters[0]);
        if ((u) && (!IS_SERVER(u)))
@@ -71,7 +88,6 @@ CmdResult CommandKill::Handle (const std::vector<std::string>& parameters, User
                 * just gets processed and passed on, otherwise, if they are local, it gets prefixed. Makes sense :-) -- w00t
                 */
 
-               std::string killreason;
                if (IS_LOCAL(user))
                {
                        /*
@@ -112,7 +128,7 @@ CmdResult CommandKill::Handle (const std::vector<std::string>& parameters, User
                {
                        // remote kill
                        ServerInstance->SNO->WriteToSnoMask('K', "Remote kill by %s: %s (%s)", user->nick.c_str(), u->GetFullRealHost().c_str(), parameters[1].c_str());
-                       FOREACH_MOD(I_OnRemoteKill, OnRemoteKill(user, u, killreason, killreason));
+                       this->lastuuid = u->uuid;
                }
                else
                {
@@ -138,6 +154,8 @@ CmdResult CommandKill::Handle (const std::vector<std::string>& parameters, User
                                                ServerInstance->Config->HideKillsServer.empty() ? user->nick.c_str() : ServerInstance->Config->HideKillsServer.c_str(),
                                                parameters[1].c_str());
                        }
+
+                       this->lastuuid.clear();
                }
 
                // send the quit out
index 7f3695adeddb3f4e425a6cf6f01fa114c5db2c80..8bd44ff686691fe1b3a6060fead37b12a6bd1ea3 100644 (file)
@@ -125,7 +125,6 @@ ModResult   Module::OnPassCompare(Extensible* ex, const std::string &password, con
 void           Module::OnGlobalOper(User*) { }
 void           Module::OnPostConnect(User*) { }
 void           Module::OnUserMessage(User*, void*, int, const std::string&, char, const CUList&, MessageType) { }
-void           Module::OnRemoteKill(User*, User*, const std::string&, const std::string&) { }
 void           Module::OnUserInvite(User*, User*, Channel*, time_t) { }
 void           Module::OnPostTopicChange(User*, Channel*, const std::string&) { }
 void           Module::OnGetServerDescription(const std::string&, std::string&) { }
index 7c698a83e5679e63356cc015d5a7bc9de04a0c8c..9af4bfd0cdfc3ec5f5c4a36f23032f85a96b15c2 100644 (file)
@@ -76,7 +76,7 @@ void ModuleSpanningTree::init()
                I_OnPreCommand, I_OnGetServerDescription, I_OnUserInvite, I_OnPostTopicChange,
                I_OnUserMessage, I_OnBackgroundTimer, I_OnUserJoin,
                I_OnChangeHost, I_OnChangeName, I_OnChangeIdent, I_OnUserPart, I_OnUnloadModule,
-               I_OnUserQuit, I_OnUserPostNick, I_OnUserKick, I_OnRemoteKill, I_OnRehash, I_OnPreRehash,
+               I_OnUserQuit, I_OnUserPostNick, I_OnUserKick, I_OnRehash, I_OnPreRehash,
                I_OnOper, I_OnAddLine, I_OnDelLine, I_OnMode, I_OnLoadModule, I_OnStats,
                I_OnSetAway, I_OnPostCommand, I_OnUserConnect, I_OnAcceptConnection
        };
@@ -667,21 +667,6 @@ void ModuleSpanningTree::OnUserKick(User* source, Membership* memb, const std::s
        }
 }
 
-void ModuleSpanningTree::OnRemoteKill(User* source, User* dest, const std::string &reason, const std::string &operreason)
-{
-       if (!IS_LOCAL(source))
-               return; // Only start routing if we're origin.
-
-       ServerInstance->OperQuit.set(dest, operreason);
-       parameterlist params;
-       params.push_back(":"+operreason);
-       Utils->DoOneToMany(dest->uuid,"OPERQUIT",params);
-       params.clear();
-       params.push_back(dest->uuid);
-       params.push_back(":"+reason);
-       Utils->DoOneToMany(source->uuid,"KILL",params);
-}
-
 void ModuleSpanningTree::OnPreRehash(User* user, const std::string &parameter)
 {
        if (loopCall)
index 9b827a6efad27ce57c640f8f4d9a24a5e4523115..22357aed434ef6a25aec211bebe3b22ef415e7e5 100644 (file)
@@ -157,7 +157,6 @@ class ModuleSpanningTree : public Module
        void OnUserQuit(User* user, const std::string &reason, const std::string &oper_message) CXX11_OVERRIDE;
        void OnUserPostNick(User* user, const std::string &oldnick) CXX11_OVERRIDE;
        void OnUserKick(User* source, Membership* memb, const std::string &reason, CUList& excepts) CXX11_OVERRIDE;
-       void OnRemoteKill(User* source, User* dest, const std::string &reason, const std::string &operreason) CXX11_OVERRIDE;
        void OnPreRehash(User* user, const std::string &parameter) CXX11_OVERRIDE;
        void OnRehash(User* user) CXX11_OVERRIDE;
        void OnOper(User* user, const std::string &opertype) CXX11_OVERRIDE;
index d32f26a4bdd3bed04269fd1bcb9e3e060136d880..4bff4b71118e9b48cc112592648ca0e12506cbc6 100644 (file)
@@ -129,7 +129,6 @@ static void checkall(Module* noimpl)
        CHK(OnPreMode);
        CHK(On005Numeric);
        CHK(OnKill);
-       CHK(OnRemoteKill);
        CHK(OnLoadModule);
        CHK(OnUnloadModule);
        CHK(OnBackgroundTimer);