Fix get_server_status() segfault due to uninitialized m_env

* Fixes [#7857](https://github.com/minetest/minetest/issues/7857)
  minetest.get_server_status() causes a Segmentation fault
  tacken from 81d55338fa
* backported commit 13ad926546def65f01b5941ebb21493278189bea
This commit is contained in:
mckaygerhard 2023-01-05 16:41:15 -04:00
parent fa1d056316
commit 78d1c731e3

View File

@ -3013,36 +3013,39 @@ PlayerSAO* Server::getPlayerSAO(u16 peer_id)
std::wstring Server::getStatusString()
{
std::wostringstream os(std::ios_base::binary);
os<<L"# Server: ";
os << L"# Server: ";
// Version
os<<L"version="<<narrow_to_wide(g_version_string);
os << L"version=" << narrow_to_wide(g_version_string);
// Uptime
os<<L", uptime="<<m_uptime.get();
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={";
std::vector<u16> clients = m_clients.getClientIDs();
for (std::vector<u16>::iterator i = clients.begin(); i != clients.end(); ++i) {
// Get player
RemotePlayer *player = m_env->getPlayer(*i);
// Get name of player
std::wstring name = L"unknown";
if (player != NULL)
name = narrow_to_wide(player->getName());
// Add name to information string
if(!first)
os << L", ";
else
first = false;
os << name;
}
os << L", clients={";
if (m_env) {
std::vector<session_t> clients = m_clients.getClientIDs();
for (session_t client_id : clients) {
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() == false)
os<<std::endl<<L"# Server: "<<" WARNING: Map saving is disabled.";
if(g_settings->get("motd") != "")
os<<std::endl<<L"# Server: "<<narrow_to_wide(g_settings->get("motd"));
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();
}