Skip to content

Commit 338d645

Browse files
red-001SmallJoker
authored andcommittedFeb 15, 2018
Add on_auth_fail callback (#7039)
Called when a client fails to supply the correct password for the account it's attempting to login as.
1 parent 861cfd8 commit 338d645

File tree

5 files changed

+20
-1
lines changed

5 files changed

+20
-1
lines changed
 

‎builtin/game/register.lua

+1
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,7 @@ core.registered_on_priv_grant, core.register_on_priv_grant = make_registration()
584584
core.registered_on_priv_revoke, core.register_on_priv_revoke = make_registration()
585585
core.registered_can_bypass_userlimit, core.register_can_bypass_userlimit = make_registration()
586586
core.registered_on_modchannel_message, core.register_on_modchannel_message = make_registration()
587+
core.registered_on_auth_fail, core.register_on_auth_fail = make_registration()
587588

588589
--
589590
-- Compatibility for on_mapgen_init()

‎doc/lua_api.txt

+4
Original file line numberDiff line numberDiff line change
@@ -2615,6 +2615,10 @@ Call these functions only at load time!
26152615
* `minetest.register_on_leaveplayer(func(ObjectRef, timed_out))`
26162616
* Called when a player leaves the game
26172617
* `timed_out`: True for timeout, false for other reasons.
2618+
* `minetest.register_on_auth_fail(func(name, ip))`
2619+
* Called when a client attempts to log into an account but supplies the wrong password.
2620+
* `ip`: The IP address of the client.
2621+
* `name`: The account the client attempted to log into.
26182622
* `minetest.register_on_cheat(func(ObjectRef, cheat))`
26192623
* Called when a player cheats
26202624
* `cheat`: `{type=<cheat_type>}`, where `<cheat_type>` is one of:

‎src/network/serverpackethandler.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1735,10 +1735,12 @@ void Server::handleCommand_SrpBytesM(NetworkPacket* pkt)
17351735
return;
17361736
}
17371737

1738+
std::string ip = getPeerAddress(pkt->getPeerId()).serializeString();
17381739
actionstream << "Server: User " << client->getName()
1739-
<< " at " << getPeerAddress(pkt->getPeerId()).serializeString()
1740+
<< " at " << ip
17401741
<< " supplied wrong password (auth mechanism: SRP)."
17411742
<< std::endl;
1743+
m_script->on_auth_failure(client->getName(), ip);
17421744
DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_WRONG_PASSWORD);
17431745
return;
17441746
}

‎src/script/cpp_api/s_player.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,14 @@ void ScriptApiPlayer::on_playerReceiveFields(ServerActiveObject *player,
206206
runCallbacks(3, RUN_CALLBACKS_MODE_OR_SC);
207207
}
208208

209+
void ScriptApiPlayer::on_auth_failure(const std::string &name, const std::string &ip)
210+
{
211+
SCRIPTAPI_PRECHECKHEADER
212+
213+
// Get core.registered_on_auth_failure
214+
lua_getglobal(L, "core");
215+
lua_getfield(L, -1, "registered_on_auth_fail");
216+
lua_pushstring(L, name.c_str());
217+
lua_pushstring(L, ip.c_str());
218+
runCallbacks(2, RUN_CALLBACKS_MODE_FIRST);
219+
}

‎src/script/cpp_api/s_player.h

+1
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@ class ScriptApiPlayer : virtual public ScriptApiBase
4545
s16 on_player_hpchange(ServerActiveObject *player, s16 hp_change);
4646
void on_playerReceiveFields(ServerActiveObject *player,
4747
const std::string &formname, const StringMap &fields);
48+
void on_auth_failure(const std::string &name, const std::string &ip);
4849
};

0 commit comments

Comments
 (0)
Please sign in to comment.