Skip to content

Commit

Permalink
[CSM] Add function to get the server protocol version. (#5529)
Browse files Browse the repository at this point in the history
  • Loading branch information
red-001 authored and nerzhul committed Apr 6, 2017
1 parent be06636 commit 88b9b96
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions clientmods/preview/init.lua
Expand Up @@ -69,6 +69,7 @@ core.after(2, function()
print("[PREVIEW] loaded " .. modname .. " mod")
modstorage:set_string("current_mod", modname)
print(modstorage:get_string("current_mod"))
print("Server version:" .. core.get_protocol_version())
preview_minimap()
end)

Expand Down
3 changes: 3 additions & 0 deletions doc/client_lua_api.md
Expand Up @@ -696,6 +696,9 @@ Call these functions only at load time!
* `minetest.disconnect()`
* Disconnect from the server and exit to main menu.
* Returns `false` if the client is already disconnecting otherwise returns `true`.
* `minetest.get_protocol_version()`
* Returns the protocol version of the server.
* Might not be accurate at start up as the client might not be connected to the server yet, in that case it will return 0.

### Misc.
* `minetest.parse_json(string[, nullvalue])`: returns something
Expand Down
8 changes: 8 additions & 0 deletions src/script/lua_api/l_client.cpp
Expand Up @@ -234,6 +234,13 @@ int ModApiClient::l_sound_stop(lua_State *L)
return 0;
}

// get_protocol_version()
int ModApiClient::l_get_protocol_version(lua_State *L)
{
lua_pushinteger(L, getClient(L)->getProtoVersion());
return 1;
}

void ModApiClient::Initialize(lua_State *L, int top)
{
API_FCT(get_current_modname);
Expand All @@ -251,4 +258,5 @@ 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);
}
3 changes: 3 additions & 0 deletions src/script/lua_api/l_client.h
Expand Up @@ -69,6 +69,9 @@ class ModApiClient : public ModApiBase

static int l_sound_stop(lua_State *L);

// get_protocol_version()
static int l_get_protocol_version(lua_State *L);

public:
static void Initialize(lua_State *L, int top);
};
Expand Down

0 comments on commit 88b9b96

Please sign in to comment.