aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2018-11-12 14:34:01 +0000
committerrubenwardy <rw@rubenwardy.com>2018-11-12 14:34:29 +0000
commit81d55338fa26cf26d43e1e632b9a089a787230dd (patch)
tree987819cb5d236d00ebcc7593644750a312b8628f /src
parentb78698240c4b0e4ac410e2aafe6d88b34b1618e2 (diff)
downloadminetest-81d55338fa26cf26d43e1e632b9a089a787230dd.tar.gz
minetest-81d55338fa26cf26d43e1e632b9a089a787230dd.tar.bz2
minetest-81d55338fa26cf26d43e1e632b9a089a787230dd.zip
Fix get_server_status() segfault due to uninitialized m_env
Fixes #7857
Diffstat (limited to 'src')
-rw-r--r--src/server.cpp52
1 files changed, 29 insertions, 23 deletions
diff --git a/src/server.cpp b/src/server.cpp
index 678ee387b..895e2bb80 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -260,7 +260,7 @@ Server::~Server()
m_env->kickAllPlayers(SERVER_ACCESSDENIED_SHUTDOWN,
kick_msg, reconnect);
}
-
+
actionstream << "Server: Shutting down" << std::endl;
// Do this before stopping the server in case mapgen callbacks need to access
@@ -2897,38 +2897,44 @@ PlayerSAO *Server::getPlayerSAO(session_t 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<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", 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())
- os<<std::endl<<L"# Server: "<<" WARNING: Map saving is disabled.";
+ 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"));
+ os << std::endl << L"# Server: " << narrow_to_wide(g_settings->get("motd"));
+
return os.str();
}