1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-11 17:51:04 +00:00

Don't crash if a Lua error occurs inside get_staticdata

This commit is contained in:
Gregor Parzefall 2023-07-03 20:34:02 +02:00 committed by GitHub
parent d71872af23
commit 26453df2f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 17 deletions

View file

@ -74,6 +74,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "database/database-dummy.h"
#include "gameparams.h"
#include "particles.h"
#include "gettext.h"
class ClientNotFoundException : public BaseException
{
@ -235,7 +236,7 @@ Server::Server(
Address bind_addr,
bool dedicated,
ChatInterface *iface,
std::string *on_shutdown_errmsg
std::string *shutdown_errmsg
):
m_bind_addr(bind_addr),
m_path_world(path_world),
@ -254,7 +255,7 @@ Server::Server(
m_thread(new ServerThread(this)),
m_clients(m_con),
m_admin_chat(iface),
m_on_shutdown_errmsg(on_shutdown_errmsg),
m_shutdown_errmsg(shutdown_errmsg),
m_modchannel_mgr(new ModChannelMgr())
{
if (m_path_world.empty())
@ -353,14 +354,7 @@ Server::~Server()
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();
}
}
addShutdownError(e);
}
infostream << "Server: Saving environment metadata" << std::endl;
@ -3759,6 +3753,23 @@ std::string Server::getBuiltinLuaPath()
return porting::path_share + DIR_DELIM + "builtin";
}
// Not thread-safe.
void Server::addShutdownError(const ModError &e)
{
// DO NOT TRANSLATE the `ModError`, it's used by `ui.lua`
std::string msg = fmtgettext("%s while shutting down: ", "ModError") +
e.what() + strgettext("\nCheck debug.txt for details.");
errorstream << msg << std::endl;
if (m_shutdown_errmsg) {
if (m_shutdown_errmsg->empty()) {
*m_shutdown_errmsg = msg;
} else {
*m_shutdown_errmsg += "\n\n" + msg;
}
}
}
v3f Server::findSpawnPos()
{
ServerMap &map = m_env->getServerMap();