aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_client.cpp
diff options
context:
space:
mode:
authorred-001 <red-001@outlook.ie>2017-04-19 14:16:54 +0100
committerparamat <mat.gregory@virginmedia.com>2017-05-04 04:25:45 +0100
commitae0d8f74d747fab2fbe5b4553818e0f938e3289d (patch)
treeddbb434b4a7c9b1300d6e0503b3fd70f391c6ff5 /src/script/lua_api/l_client.cpp
parent468eeb618e9abbff2f04f4635eb89a8f684d71ae (diff)
downloadminetest-ae0d8f74d747fab2fbe5b4553818e0f938e3289d.tar.gz
minetest-ae0d8f74d747fab2fbe5b4553818e0f938e3289d.tar.bz2
minetest-ae0d8f74d747fab2fbe5b4553818e0f938e3289d.zip
Add function to get server info.
Diffstat (limited to 'src/script/lua_api/l_client.cpp')
-rw-r--r--src/script/lua_api/l_client.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/script/lua_api/l_client.cpp b/src/script/lua_api/l_client.cpp
index c982a2f11..7f89a4d5d 100644
--- a/src/script/lua_api/l_client.cpp
+++ b/src/script/lua_api/l_client.cpp
@@ -234,10 +234,20 @@ int ModApiClient::l_sound_stop(lua_State *L)
return 0;
}
-// get_protocol_version()
-int ModApiClient::l_get_protocol_version(lua_State *L)
+// get_server_info()
+int ModApiClient::l_get_server_info(lua_State *L)
{
- lua_pushinteger(L, getClient(L)->getProtoVersion());
+ 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");
return 1;
}
@@ -265,6 +275,6 @@ void ModApiClient::Initialize(lua_State *L, int top)
API_FCT(get_meta);
API_FCT(sound_play);
API_FCT(sound_stop);
- API_FCT(get_protocol_version);
+ API_FCT(get_server_info);
API_FCT(take_screenshot);
}