forked from Mirrorlandia_minetest/minetest
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:
parent
d975ebdcb9
commit
9c9309cdbb
@ -85,7 +85,14 @@ int ModApiServer::l_chat_send_all(lua_State *L)
|
|||||||
// Get server from registry
|
// Get server from registry
|
||||||
Server *server = getServer(L);
|
Server *server = getServer(L);
|
||||||
// Send
|
// 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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,7 +106,13 @@ int ModApiServer::l_chat_send_player(lua_State *L)
|
|||||||
// Get server from registry
|
// Get server from registry
|
||||||
Server *server = getServer(L);
|
Server *server = getServer(L);
|
||||||
// Send
|
// 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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user