lua client API: Fix crash in get_server_info()
When running on a local machine in Docker, calling `minetest.get_server_info()` in lua can throw an exception, resulting in client shutdown. ERROR[Main]: ModError: Failed to load and run mod "tchat": ERROR[Main]: No address for peer found! ERROR[Main]: stack traceback: ERROR[Main]: [C]: in function 'get_server_info' ERROR[Main]: tchat:init.lua:118: in main chunk ERROR[Main]: Check debug.txt for details.
This commit is contained in:
parent
1c1eac07f3
commit
a4187aa951
@ -322,16 +322,33 @@ int ModApiClient::l_sound_fade(lua_State *L)
|
||||
int ModApiClient::l_get_server_info(lua_State *L)
|
||||
{
|
||||
Client *client = getClient(L);
|
||||
Address serverAddress = client->getServerAddress();
|
||||
lua_newtable(L);
|
||||
lua_pushstring(L, client->getAddressName().c_str());
|
||||
lua_setfield(L, -2, "address");
|
||||
lua_pushstring(L, serverAddress.serializeString().c_str());
|
||||
lua_setfield(L, -2, "ip");
|
||||
lua_pushinteger(L, serverAddress.getPort());
|
||||
lua_setfield(L, -2, "port");
|
||||
lua_pushinteger(L, client->getProtoVersion());
|
||||
lua_setfield(L, -2, "protocol_version");
|
||||
lua_newtable(L);
|
||||
try {
|
||||
Address serverAddress = client->getServerAddress();
|
||||
} catch (const con::PeerNotFoundException &) {
|
||||
// Local connection?
|
||||
lua_pushstring(L, "unknown");
|
||||
lua_setfield(L, -2, "address");
|
||||
lua_pushstring(L, "unknown");
|
||||
lua_setfield(L, -2, "ip");
|
||||
lua_pushinteger(L, 0);
|
||||
lua_setfield(L, -2, "port");
|
||||
lua_pushinteger(L, 0);
|
||||
lua_setfield(L, -2, "port");
|
||||
lua_pushinteger(L, 0);
|
||||
lua_setfield(L, -2, "protocol_version");
|
||||
return 1;
|
||||
}
|
||||
|
||||
lua_pushstring(L, client->getAddressName().c_str());
|
||||
lua_setfield(L, -2, "address");
|
||||
lua_pushstring(L, serverAddress.serializeString().c_str());
|
||||
lua_setfield(L, -2, "ip");
|
||||
lua_pushinteger(L, serverAddress.getPort());
|
||||
lua_setfield(L, -2, "port");
|
||||
lua_pushinteger(L, client->getProtoVersion());
|
||||
lua_setfield(L, -2, "protocol_version");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user