From bc71622d2121347ad6dbbe3c174ad485fe1a8f8c Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 5 Oct 2021 19:53:47 +0000 Subject: Fix crash when calling remove/kick/ban_player on start (#11672) --- src/script/lua_api/l_server.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/script') diff --git a/src/script/lua_api/l_server.cpp b/src/script/lua_api/l_server.cpp index 6438fa6fd..476f74c9c 100644 --- a/src/script/lua_api/l_server.cpp +++ b/src/script/lua_api/l_server.cpp @@ -293,8 +293,10 @@ int ModApiServer::l_ban_player(lua_State *L) { NO_MAP_LOCK_REQUIRED; - Server *server = getServer(L); + if (!getEnv(L)) + throw LuaError("Can't ban player before server has started up"); + Server *server = getServer(L); const char *name = luaL_checkstring(L, 1); RemotePlayer *player = server->getEnv().getPlayer(name); if (!player) { @@ -312,6 +314,10 @@ int ModApiServer::l_ban_player(lua_State *L) int ModApiServer::l_kick_player(lua_State *L) { NO_MAP_LOCK_REQUIRED; + + if (!getEnv(L)) + throw LuaError("Can't kick player before server has started up"); + const char *name = luaL_checkstring(L, 1); std::string message("Kicked"); if (lua_isstring(L, 2)) @@ -334,7 +340,8 @@ int ModApiServer::l_remove_player(lua_State *L) NO_MAP_LOCK_REQUIRED; std::string name = luaL_checkstring(L, 1); ServerEnvironment *s_env = dynamic_cast(getEnv(L)); - assert(s_env); + if (!s_env) + throw LuaError("Can't remove player before server has started up"); RemotePlayer *player = s_env->getPlayer(name.c_str()); if (!player) -- cgit v1.2.3