@@ -74,6 +74,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
7474#include " database/database-dummy.h"
7575#include " gameparams.h"
7676#include " particles.h"
77+ #include " gettext.h"
7778
7879class ClientNotFoundException : public BaseException
7980{
@@ -235,7 +236,7 @@ Server::Server(
235236 Address bind_addr,
236237 bool dedicated,
237238 ChatInterface *iface,
238- std::string *on_shutdown_errmsg
239+ std::string *shutdown_errmsg
239240 ):
240241 m_bind_addr(bind_addr),
241242 m_path_world(path_world),
@@ -254,7 +255,7 @@ Server::Server(
254255 m_thread(new ServerThread(this )),
255256 m_clients(m_con),
256257 m_admin_chat(iface),
257- m_on_shutdown_errmsg(on_shutdown_errmsg ),
258+ m_shutdown_errmsg(shutdown_errmsg ),
258259 m_modchannel_mgr(new ModChannelMgr())
259260{
260261 if (m_path_world.empty ())
@@ -353,14 +354,7 @@ Server::~Server()
353354 try {
354355 m_script->on_shutdown ();
355356 } catch (ModError &e) {
356- errorstream << " ModError: " << e.what () << std::endl;
357- if (m_on_shutdown_errmsg) {
358- if (m_on_shutdown_errmsg->empty ()) {
359- *m_on_shutdown_errmsg = std::string (" ModError: " ) + e.what ();
360- } else {
361- *m_on_shutdown_errmsg += std::string (" \n ModError: " ) + e.what ();
362- }
363- }
357+ addShutdownError (e);
364358 }
365359
366360 infostream << " Server: Saving environment metadata" << std::endl;
@@ -3759,6 +3753,23 @@ std::string Server::getBuiltinLuaPath()
37593753 return porting::path_share + DIR_DELIM + " builtin" ;
37603754}
37613755
3756+ // Not thread-safe.
3757+ void Server::addShutdownError (const ModError &e)
3758+ {
3759+ // DO NOT TRANSLATE the `ModError`, it's used by `ui.lua`
3760+ std::string msg = fmtgettext (" %s while shutting down: " , " ModError" ) +
3761+ e.what () + strgettext (" \n Check debug.txt for details." );
3762+ errorstream << msg << std::endl;
3763+
3764+ if (m_shutdown_errmsg) {
3765+ if (m_shutdown_errmsg->empty ()) {
3766+ *m_shutdown_errmsg = msg;
3767+ } else {
3768+ *m_shutdown_errmsg += " \n\n " + msg;
3769+ }
3770+ }
3771+ }
3772+
37623773v3f Server::findSpawnPos ()
37633774{
37643775 ServerMap &map = m_env->getServerMap ();
0 commit comments