diff options
author | Wuzzy <wuzzy2@mail.ru> | 2021-10-05 19:53:47 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-05 21:53:47 +0200 |
commit | bc71622d2121347ad6dbbe3c174ad485fe1a8f8c (patch) | |
tree | 93bcc1e3cb35c37c32c3260be7e220a7ceb6d445 /src/script/lua_api | |
parent | 5aa95fef102db02aa4b2f4a5c2b59ac985a54cef (diff) | |
download | minetest-bc71622d2121347ad6dbbe3c174ad485fe1a8f8c.tar.gz minetest-bc71622d2121347ad6dbbe3c174ad485fe1a8f8c.tar.bz2 minetest-bc71622d2121347ad6dbbe3c174ad485fe1a8f8c.zip |
Fix crash when calling remove/kick/ban_player on start (#11672)
Diffstat (limited to 'src/script/lua_api')
-rw-r--r-- | src/script/lua_api/l_server.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
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<ServerEnvironment *>(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) |