summaryrefslogtreecommitdiff
path: root/src/server.cpp
diff options
context:
space:
mode:
authorDesour <vorunbekannt75@web.de>2020-08-23 19:44:25 +0200
committerceleron55 <celeron55@gmail.com>2020-08-24 19:55:25 +0300
commitf27cf4777933f06f85fa2f013d56ca0a2cf1d588 (patch)
tree0de39c63d30849cbf4e7409f00470493a2de5b15 /src/server.cpp
parent3e5bce2251deb8e5fcbaa266431f8c0f10078bf2 (diff)
downloadminetest-f27cf4777933f06f85fa2f013d56ca0a2cf1d588.tar.gz
minetest-f27cf4777933f06f85fa2f013d56ca0a2cf1d588.tar.bz2
minetest-f27cf4777933f06f85fa2f013d56ca0a2cf1d588.zip
Properly handle mod-errors in on_shutdown
Diffstat (limited to 'src/server.cpp')
-rw-r--r--src/server.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/server.cpp b/src/server.cpp
index ef36aedca..7b3978462 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -213,7 +213,8 @@ Server::Server(
bool simple_singleplayer_mode,
Address bind_addr,
bool dedicated,
- ChatInterface *iface
+ ChatInterface *iface,
+ std::string *on_shutdown_errmsg
):
m_bind_addr(bind_addr),
m_path_world(path_world),
@@ -232,6 +233,7 @@ Server::Server(
m_thread(new ServerThread(this)),
m_clients(m_con),
m_admin_chat(iface),
+ m_on_shutdown_errmsg(on_shutdown_errmsg),
m_modchannel_mgr(new ModChannelMgr())
{
if (m_path_world.empty())
@@ -314,7 +316,18 @@ Server::~Server()
// Execute script shutdown hooks
infostream << "Executing shutdown hooks" << std::endl;
- m_script->on_shutdown();
+ try {
+ m_script->on_shutdown();
+ } catch (ModError &e) {
+ errorstream << "ModError: " << e.what() << std::endl;
+ if (m_on_shutdown_errmsg) {
+ if (m_on_shutdown_errmsg->empty()) {
+ *m_on_shutdown_errmsg = std::string("ModError: ") + e.what();
+ } else {
+ *m_on_shutdown_errmsg += std::string("\nModError: ") + e.what();
+ }
+ }
+ }
infostream << "Server: Saving environment metadata" << std::endl;
m_env->saveMeta();