minetest.registered_on_joinplayers, minetest.register_on_joinplayer = make_registration()
minetest.registered_on_leaveplayers, minetest.register_on_leaveplayer = make_registration()
minetest.registered_on_player_receive_fields, minetest.register_on_player_receive_fields = make_registration_reverse()
+minetest.registered_on_cheats, minetest.register_on_cheat = make_registration()
^ Called when a player joins the game
minetest.register_on_leaveplayer(func(ObjectRef))
^ Called when a player leaves the game
+minetest.register_on_cheat(func(ObjectRef, cheat))
+^ Called when a player cheats
+^ cheat: {type="moved_too_fast"/"interacted_too_far"/"finished_unknown_dig"/"dug_unbreakable"/"dug_too_fast"}
minetest.register_on_chat_message(func(name, message))
^ Called always when a player says something
minetest.register_on_player_receive_fields(func(player, formname, fields))
return gob_cmd_set_properties(m_prop);
}
-void PlayerSAO::checkMovementCheat()
+bool PlayerSAO::checkMovementCheat()
{
+ bool cheated = false;
if(isAttached() || m_is_singleplayer ||
g_settings->getBool("disable_anticheat"))
{
<<std::endl;
m_player->setPosition(m_last_good_position);
m_moved = true;
+ cheated = true;
}
}
+ return cheated;
}
bool PlayerSAO::getCollisionBox(aabb3f *toset) {
{
return m_dig_pool;
}
- void checkMovementCheat();
+ // Returns true if cheated
+ bool checkMovementCheat();
// Other
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)
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,
player->control.LMB = (bool)(keyPressed&128);
player->control.RMB = (bool)(keyPressed&256);
- playersao->checkMovementCheat();
+ bool cheated = playersao->checkMovementCheat();
+ if(cheated){
+ // Call callbacks
+ m_script->on_cheat(playersao, "moved_too_fast");
+ }
/*infostream<<"Server::ProcessData(): Moved player "<<peer_id<<" to "
<<"("<<position.X<<","<<position.Y<<","<<position.Z<<")"
RemoteClient *client = getClient(peer_id);
v3s16 blockpos = getNodeBlockPos(floatToInt(pointed_pos_under, BS));
client->SetBlockNotSent(blockpos);
+ // Call callbacks
+ m_script->on_cheat(playersao, "interacted_too_far");
// Do nothing else
return;
}
<<PP(nocheat_p)<<" and completed digging "
<<PP(p_under)<<"; not digging."<<std::endl;
is_valid_dig = false;
+ // Call callbacks
+ m_script->on_cheat(playersao, "finished_unknown_dig");
}
// Get player's wielded item
ItemStack playeritem;
<<", which is not diggable with tool. not digging."
<<std::endl;
is_valid_dig = false;
+ // Call callbacks
+ m_script->on_cheat(playersao, "dug_unbreakable");
}
// Check digging time
// If already invalidated, we don't have to
<<" completed digging "<<PP(p_under)
<<"too fast; not digging."<<std::endl;
is_valid_dig = false;
+ // Call callbacks
+ m_script->on_cheat(playersao, "dug_too_fast");
}
}