Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Properly handle mod-errors in on_shutdown
- Loading branch information
Showing
with
23 additions
and
4 deletions.
-
+2
−1
src/client/game.cpp
-
+15
−2
src/server.cpp
-
+6
−1
src/server.h
|
@@ -1300,7 +1300,8 @@ bool Game::createSingleplayerServer(const std::string &map_dir, |
|
|
return false; |
|
|
} |
|
|
|
|
|
server = new Server(map_dir, gamespec, simple_singleplayer_mode, bind_addr, false); |
|
|
server = new Server(map_dir, gamespec, simple_singleplayer_mode, bind_addr, |
|
|
false, nullptr, error_message); |
|
|
server->start(); |
|
|
|
|
|
return true; |
|
|
|
@@ -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(); |
|
|
|
@@ -131,7 +131,8 @@ class Server : public con::PeerHandler, public MapEventReceiver, |
|
|
bool simple_singleplayer_mode, |
|
|
Address bind_addr, |
|
|
bool dedicated, |
|
|
ChatInterface *iface = nullptr |
|
|
ChatInterface *iface = nullptr, |
|
|
std::string *on_shutdown_errmsg = nullptr |
|
|
); |
|
|
~Server(); |
|
|
DISABLE_CLASS_COPY(Server); |
|
@@ -596,6 +597,10 @@ class Server : public con::PeerHandler, public MapEventReceiver, |
|
|
ChatInterface *m_admin_chat; |
|
|
std::string m_admin_nick; |
|
|
|
|
|
// if a mod-error occurs in the on_shutdown callback, the error message will |
|
|
// be written into this |
|
|
std::string *const m_on_shutdown_errmsg; |
|
|
|
|
|
/* |
|
|
Map edit event queue. Automatically receives all map edits. |
|
|
The constructor of this class registers us to receive them through |
|
|