Fix get_server_status() segfault due to uninitialized m_env

Fixes #7857
This commit is contained in:
rubenwardy 2018-11-12 14:34:01 +00:00
parent b78698240c
commit 81d55338fa

@ -2903,32 +2903,38 @@ std::wstring Server::getStatusString()
// Uptime
os << L", uptime=" << m_uptime.get();
// Max lag estimate
os<<L", max_lag="<<m_env->getMaxLagEstimate();
os << L", max_lag=" << (m_env ? m_env->getMaxLagEstimate() : 0);
// Information about clients
bool first = true;
os << L", clients={";
if (m_env) {
std::vector<session_t> clients = m_clients.getClientIDs();
for (session_t client_id : clients) {
// Get player
RemotePlayer *player = m_env->getPlayer(client_id);
// Get name of player
std::wstring name = L"unknown";
if (player)
name = narrow_to_wide(player->getName());
// Add name to information string
if (!first)
os << L", ";
else
first = false;
os << name;
}
}
os << L"}";
if (!((ServerMap*)(&m_env->getMap()))->isSavingEnabled())
if (m_env && !((ServerMap*)(&m_env->getMap()))->isSavingEnabled())
os << std::endl << L"# Server: " << " WARNING: Map saving is disabled.";
if (!g_settings->get("motd").empty())
os << std::endl << L"# Server: " << narrow_to_wide(g_settings->get("motd"));
return os.str();
}