Lua API: Catch serialization error for chat messages (#13337)

Prevents server errors caused by too long chat messages from the Lua API.
This commit is contained in:
SmallJoker 2023-04-07 12:49:35 +02:00 committed by GitHub
parent d975ebdcb9
commit 9c9309cdbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 2 deletions

View File

@ -85,7 +85,14 @@ int ModApiServer::l_chat_send_all(lua_State *L)
// Get server from registry
Server *server = getServer(L);
// Send
server->notifyPlayers(utf8_to_wide(text));
try {
server->notifyPlayers(utf8_to_wide(text));
} catch (PacketError &e) {
warningstream << "Exception caught: " << e.what() << std::endl
<< script_get_backtrace(L) << std::endl;
server->notifyPlayers(utf8_to_wide(std::string("Internal error: ") + e.what()));
}
return 0;
}
@ -99,7 +106,13 @@ int ModApiServer::l_chat_send_player(lua_State *L)
// Get server from registry
Server *server = getServer(L);
// Send
server->notifyPlayer(name, utf8_to_wide(text));
try {
server->notifyPlayer(name, utf8_to_wide(text));
} catch (PacketError &e) {
warningstream << "Exception caught: " << e.what() << std::endl
<< script_get_backtrace(L) << std::endl;
server->notifyPlayer(name, utf8_to_wide(std::string("Internal error: ") + e.what()));
}
return 0;
}