Add `on_auth_fail` callback (#7039)
authorred-001 <red-001@outlook.ie>
Thu, 15 Feb 2018 20:18:54 +0000 (20:18 +0000)
committerSmallJoker <SmallJoker@users.noreply.github.com>
Thu, 15 Feb 2018 20:18:54 +0000 (21:18 +0100)
Called when a client fails to supply the correct password for the account it's attempting to login as.

builtin/game/register.lua
doc/lua_api.txt
src/network/serverpackethandler.cpp
src/script/cpp_api/s_player.cpp
src/script/cpp_api/s_player.h

index f5d4ea216585e454d3a36ad3eb9fc9833265f191..15d9b42d0ea13d1af12f19c3be793a2594cb618d 100644 (file)
@@ -584,6 +584,7 @@ core.registered_on_priv_grant, core.register_on_priv_grant = make_registration()
 core.registered_on_priv_revoke, core.register_on_priv_revoke = make_registration()
 core.registered_can_bypass_userlimit, core.register_can_bypass_userlimit = make_registration()
 core.registered_on_modchannel_message, core.register_on_modchannel_message = make_registration()
+core.registered_on_auth_fail, core.register_on_auth_fail = make_registration()
 
 --
 -- Compatibility for on_mapgen_init()
index 5baa098e2eb3d9a39e7a84bb0bdccce6e2b1f2d4..522740d7786677d9d3eba489d32b82b0e7fcf413 100644 (file)
@@ -2615,6 +2615,10 @@ Call these functions only at load time!
 * `minetest.register_on_leaveplayer(func(ObjectRef, timed_out))`
     * Called when a player leaves the game
     * `timed_out`: True for timeout, false for other reasons.
+* `minetest.register_on_auth_fail(func(name, ip))`
+    * Called when a client attempts to log into an account but supplies the wrong password.
+    * `ip`: The IP address of the client.
+    * `name`: The account the client attempted to log into.
 * `minetest.register_on_cheat(func(ObjectRef, cheat))`
     * Called when a player cheats
     * `cheat`: `{type=<cheat_type>}`, where `<cheat_type>` is one of:
index 6ea58a7ecfd01af51d408e86bb184e50ebdcf627..98697d72f15ca4110f9a409c8410dbc326a57eb9 100644 (file)
@@ -1735,10 +1735,12 @@ void Server::handleCommand_SrpBytesM(NetworkPacket* pkt)
                        return;
                }
 
+               std::string ip = getPeerAddress(pkt->getPeerId()).serializeString();
                actionstream << "Server: User " << client->getName()
-                       << " at " << getPeerAddress(pkt->getPeerId()).serializeString()
+                       << " at " << ip
                        << " supplied wrong password (auth mechanism: SRP)."
                        << std::endl;
+               m_script->on_auth_failure(client->getName(), ip);
                DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_WRONG_PASSWORD);
                return;
        }
index f3c316650250294baf2db936512266668b21affa..578298e24817c6ed5f9e8f7ce8238bdd8b06ad0e 100644 (file)
@@ -206,3 +206,14 @@ void ScriptApiPlayer::on_playerReceiveFields(ServerActiveObject *player,
        runCallbacks(3, RUN_CALLBACKS_MODE_OR_SC);
 }
 
+void ScriptApiPlayer::on_auth_failure(const std::string &name, const std::string &ip)
+{
+       SCRIPTAPI_PRECHECKHEADER
+
+       // Get core.registered_on_auth_failure
+       lua_getglobal(L, "core");
+       lua_getfield(L, -1, "registered_on_auth_fail");
+       lua_pushstring(L, name.c_str());
+       lua_pushstring(L, ip.c_str());
+       runCallbacks(2, RUN_CALLBACKS_MODE_FIRST);
+}
index 6b752eb69d30a8d72b80067bdea37e4179ed1d37..562805695e7e2e17684d0f4cb80e43e995ce69f0 100644 (file)
@@ -45,4 +45,5 @@ public:
        s16 on_player_hpchange(ServerActiveObject *player, s16 hp_change);
        void on_playerReceiveFields(ServerActiveObject *player,
                        const std::string &formname, const StringMap &fields);
+       void on_auth_failure(const std::string &name, const std::string &ip);
 };