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 committed by luk3yx
parent 8fe5db2301
commit 15da50c815

View File

@ -3013,36 +3013,44 @@ PlayerSAO* Server::getPlayerSAO(u16 peer_id)
std::wstring Server::getStatusString() std::wstring Server::getStatusString()
{ {
std::wostringstream os(std::ios_base::binary); std::wostringstream os(std::ios_base::binary);
os<<L"# Server: "; os << L"# Server: ";
// Version // Version
os<<L"version="<<narrow_to_wide(g_version_string); os << L"version=" << narrow_to_wide(g_version_string);
// Uptime // Uptime
os<<L", uptime="<<m_uptime.get(); os << L", uptime=" << m_uptime.get();
// Max lag estimate // Max lag estimate
os<<L", max_lag="<<m_env->getMaxLagEstimate(); os << L", max_lag=" << (m_env ? m_env->getMaxLagEstimate() : 0);
// Information about clients // Information about clients
bool first = true; bool first = true;
os<<L", clients={"; os << L", clients={";
std::vector<u16> clients = m_clients.getClientIDs(); if (m_env) {
for (std::vector<u16>::iterator i = clients.begin(); i != clients.end(); ++i) { std::vector<session_t> clients = m_clients.getClientIDs();
// Get player for (session_t client_id : clients) {
RemotePlayer *player = m_env->getPlayer(*i); RemotePlayer *player = m_env->getPlayer(client_id);
// Get name of player // Get name of player
std::wstring name = L"unknown"; std::wstring name = L"unknown";
if (player != NULL) if (player)
name = narrow_to_wide(player->getName()); name = narrow_to_wide(player->getName());
// Add name to information string // Add name to information string
if(!first) if (!first)
os << L", "; os << L", ";
else else
first = false; first = false;
os << name; os << name;
} }
}
os << L"}"; os << L"}";
if(((ServerMap*)(&m_env->getMap()))->isSavingEnabled() == false)
os<<std::endl<<L"# Server: "<<" WARNING: Map saving is disabled."; if (m_env && !((ServerMap*)(&m_env->getMap()))->isSavingEnabled())
if(g_settings->get("motd") != "") os << std::endl << L"# Server: " << " WARNING: Map saving is disabled.";
os<<std::endl<<L"# Server: "<<narrow_to_wide(g_settings->get("motd"));
if (!g_settings->get("motd").empty())
os << std::endl << L"# Server: " << narrow_to_wide(g_settings->get("motd"));
return os.str(); return os.str();
} }