Skip to content

Commit

Permalink
Fix crash when calling remove/kick/ban_player on start (#11672)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wuzzy2 committed Oct 5, 2021
1 parent 5aa95fe commit bc71622
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/script/lua_api/l_server.cpp
Expand Up @@ -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) {
Expand All @@ -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))
Expand All @@ -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)
Expand Down

0 comments on commit bc71622

Please sign in to comment.