From 8831669505905dd9cd415711063f705d8e7ce02c Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sun, 4 Aug 2013 00:45:49 +0300 Subject: Allow mods to listen to cheat detections using minetest.register_on_cheat() --- src/script/cpp_api/s_player.cpp | 16 ++++++++++++++++ src/script/cpp_api/s_player.h | 1 + 2 files changed, 17 insertions(+) (limited to 'src/script/cpp_api') diff --git a/src/script/cpp_api/s_player.cpp b/src/script/cpp_api/s_player.cpp index e736d745d..0dbd52527 100644 --- a/src/script/cpp_api/s_player.cpp +++ b/src/script/cpp_api/s_player.cpp @@ -81,6 +81,22 @@ void ScriptApiPlayer::on_leaveplayer(ServerActiveObject *player) runCallbacks(1, RUN_CALLBACKS_MODE_FIRST); } +void ScriptApiPlayer::on_cheat(ServerActiveObject *player, + const std::string &cheat_type) +{ + SCRIPTAPI_PRECHECKHEADER + + // Get minetest.registered_on_cheats + lua_getglobal(L, "minetest"); + lua_getfield(L, -1, "registered_on_cheats"); + // Call callbacks + objectrefGetOrCreate(player); + lua_newtable(L); + lua_pushlstring(L, cheat_type.c_str(), cheat_type.size()); + lua_setfield(L, -2, "type"); + runCallbacks(2, RUN_CALLBACKS_MODE_FIRST); +} + void ScriptApiPlayer::on_playerReceiveFields(ServerActiveObject *player, const std::string &formname, const std::map &fields) diff --git a/src/script/cpp_api/s_player.h b/src/script/cpp_api/s_player.h index 663e3c2ab..c0409a481 100644 --- a/src/script/cpp_api/s_player.h +++ b/src/script/cpp_api/s_player.h @@ -34,6 +34,7 @@ public: bool on_respawnplayer(ServerActiveObject *player); void on_joinplayer(ServerActiveObject *player); void on_leaveplayer(ServerActiveObject *player); + void on_cheat(ServerActiveObject *player, const std::string &cheat_type); void on_playerReceiveFields(ServerActiveObject *player, const std::string &formname, -- cgit v1.2.3