summaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2013-08-04 00:45:49 +0300
committerPerttu Ahola <celeron55@gmail.com>2013-08-04 00:45:49 +0300
commit8831669505905dd9cd415711063f705d8e7ce02c (patch)
treee3732284d445a143909294265d4b2742e68cfc19 /src/script
parent742614180cbbe598694a48bd9eb6f7b97a762243 (diff)
downloadminetest-8831669505905dd9cd415711063f705d8e7ce02c.tar.gz
minetest-8831669505905dd9cd415711063f705d8e7ce02c.tar.bz2
minetest-8831669505905dd9cd415711063f705d8e7ce02c.zip
Allow mods to listen to cheat detections using minetest.register_on_cheat()
Diffstat (limited to 'src/script')
-rw-r--r--src/script/cpp_api/s_player.cpp16
-rw-r--r--src/script/cpp_api/s_player.h1
2 files changed, 17 insertions, 0 deletions
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<std::string, std::string> &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,