forked from Mirrorlandia_minetest/minetest
Give the online lua mainmenu also the client_list and mods (#8691)
This commit is contained in:
parent
3f275d799c
commit
74d9b6010f
@ -156,18 +156,21 @@ core.get_favorites(location) -> list of favorites (possible in async calls)
|
|||||||
^ location: "local" or "online"
|
^ location: "local" or "online"
|
||||||
^ returns {
|
^ returns {
|
||||||
[1] = {
|
[1] = {
|
||||||
clients = <number of clients/nil>,
|
clients = <number of clients/nil>,
|
||||||
clients_max = <maximum number of clients/nil>,
|
clients_max = <maximum number of clients/nil>,
|
||||||
version = <server version/nil>,
|
version = <server version/nil>,
|
||||||
password = <true/nil>,
|
password = <true/nil>,
|
||||||
creative = <true/nil>,
|
creative = <true/nil>,
|
||||||
damage = <true/nil>,
|
damage = <true/nil>,
|
||||||
pvp = <true/nil>,
|
pvp = <true/nil>,
|
||||||
description = <server description/nil>,
|
description = <server description/nil>,
|
||||||
name = <server name/nil>,
|
name = <server name/nil>,
|
||||||
address = <address of server/nil>,
|
address = <address of server/nil>,
|
||||||
port = <port>
|
port = <port>
|
||||||
|
clients_list = <array of clients/nil>
|
||||||
|
mods = <array of mods/nil>
|
||||||
},
|
},
|
||||||
|
...
|
||||||
}
|
}
|
||||||
core.delete_favorite(id, location) -> success
|
core.delete_favorite(id, location) -> success
|
||||||
|
|
||||||
|
@ -280,8 +280,8 @@ int ModApiMainMenu::l_get_favorites(lua_State *L)
|
|||||||
{
|
{
|
||||||
std::string listtype = "local";
|
std::string listtype = "local";
|
||||||
|
|
||||||
if (!lua_isnone(L,1)) {
|
if (!lua_isnone(L, 1)) {
|
||||||
listtype = luaL_checkstring(L,1);
|
listtype = luaL_checkstring(L, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<ServerListSpec> servers;
|
std::vector<ServerListSpec> servers;
|
||||||
@ -298,7 +298,7 @@ int ModApiMainMenu::l_get_favorites(lua_State *L)
|
|||||||
|
|
||||||
for (const Json::Value &server : servers) {
|
for (const Json::Value &server : servers) {
|
||||||
|
|
||||||
lua_pushnumber(L,index);
|
lua_pushnumber(L, index);
|
||||||
|
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
int top_lvl2 = lua_gettop(L);
|
int top_lvl2 = lua_gettop(L);
|
||||||
@ -306,11 +306,11 @@ int ModApiMainMenu::l_get_favorites(lua_State *L)
|
|||||||
if (!server["clients"].asString().empty()) {
|
if (!server["clients"].asString().empty()) {
|
||||||
std::string clients_raw = server["clients"].asString();
|
std::string clients_raw = server["clients"].asString();
|
||||||
char* endptr = 0;
|
char* endptr = 0;
|
||||||
int numbervalue = strtol(clients_raw.c_str(),&endptr,10);
|
int numbervalue = strtol(clients_raw.c_str(), &endptr,10);
|
||||||
|
|
||||||
if ((!clients_raw.empty()) && (*endptr == 0)) {
|
if ((!clients_raw.empty()) && (*endptr == 0)) {
|
||||||
lua_pushstring(L,"clients");
|
lua_pushstring(L, "clients");
|
||||||
lua_pushnumber(L,numbervalue);
|
lua_pushnumber(L, numbervalue);
|
||||||
lua_settable(L, top_lvl2);
|
lua_settable(L, top_lvl2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -319,83 +319,83 @@ int ModApiMainMenu::l_get_favorites(lua_State *L)
|
|||||||
|
|
||||||
std::string clients_max_raw = server["clients_max"].asString();
|
std::string clients_max_raw = server["clients_max"].asString();
|
||||||
char* endptr = 0;
|
char* endptr = 0;
|
||||||
int numbervalue = strtol(clients_max_raw.c_str(),&endptr,10);
|
int numbervalue = strtol(clients_max_raw.c_str(), &endptr,10);
|
||||||
|
|
||||||
if ((!clients_max_raw.empty()) && (*endptr == 0)) {
|
if ((!clients_max_raw.empty()) && (*endptr == 0)) {
|
||||||
lua_pushstring(L,"clients_max");
|
lua_pushstring(L, "clients_max");
|
||||||
lua_pushnumber(L,numbervalue);
|
lua_pushnumber(L, numbervalue);
|
||||||
lua_settable(L, top_lvl2);
|
lua_settable(L, top_lvl2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!server["version"].asString().empty()) {
|
if (!server["version"].asString().empty()) {
|
||||||
lua_pushstring(L,"version");
|
lua_pushstring(L, "version");
|
||||||
std::string topush = server["version"].asString();
|
std::string topush = server["version"].asString();
|
||||||
lua_pushstring(L,topush.c_str());
|
lua_pushstring(L, topush.c_str());
|
||||||
lua_settable(L, top_lvl2);
|
lua_settable(L, top_lvl2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!server["proto_min"].asString().empty()) {
|
if (!server["proto_min"].asString().empty()) {
|
||||||
lua_pushstring(L,"proto_min");
|
lua_pushstring(L, "proto_min");
|
||||||
lua_pushinteger(L, server["proto_min"].asInt());
|
lua_pushinteger(L, server["proto_min"].asInt());
|
||||||
lua_settable(L, top_lvl2);
|
lua_settable(L, top_lvl2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!server["proto_max"].asString().empty()) {
|
if (!server["proto_max"].asString().empty()) {
|
||||||
lua_pushstring(L,"proto_max");
|
lua_pushstring(L, "proto_max");
|
||||||
lua_pushinteger(L, server["proto_max"].asInt());
|
lua_pushinteger(L, server["proto_max"].asInt());
|
||||||
lua_settable(L, top_lvl2);
|
lua_settable(L, top_lvl2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!server["password"].asString().empty()) {
|
if (!server["password"].asString().empty()) {
|
||||||
lua_pushstring(L,"password");
|
lua_pushstring(L, "password");
|
||||||
lua_pushboolean(L, server["password"].asBool());
|
lua_pushboolean(L, server["password"].asBool());
|
||||||
lua_settable(L, top_lvl2);
|
lua_settable(L, top_lvl2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!server["creative"].asString().empty()) {
|
if (!server["creative"].asString().empty()) {
|
||||||
lua_pushstring(L,"creative");
|
lua_pushstring(L, "creative");
|
||||||
lua_pushboolean(L, server["creative"].asBool());
|
lua_pushboolean(L, server["creative"].asBool());
|
||||||
lua_settable(L, top_lvl2);
|
lua_settable(L, top_lvl2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!server["damage"].asString().empty()) {
|
if (!server["damage"].asString().empty()) {
|
||||||
lua_pushstring(L,"damage");
|
lua_pushstring(L, "damage");
|
||||||
lua_pushboolean(L, server["damage"].asBool());
|
lua_pushboolean(L, server["damage"].asBool());
|
||||||
lua_settable(L, top_lvl2);
|
lua_settable(L, top_lvl2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!server["pvp"].asString().empty()) {
|
if (!server["pvp"].asString().empty()) {
|
||||||
lua_pushstring(L,"pvp");
|
lua_pushstring(L, "pvp");
|
||||||
lua_pushboolean(L, server["pvp"].asBool());
|
lua_pushboolean(L, server["pvp"].asBool());
|
||||||
lua_settable(L, top_lvl2);
|
lua_settable(L, top_lvl2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!server["description"].asString().empty()) {
|
if (!server["description"].asString().empty()) {
|
||||||
lua_pushstring(L,"description");
|
lua_pushstring(L, "description");
|
||||||
std::string topush = server["description"].asString();
|
std::string topush = server["description"].asString();
|
||||||
lua_pushstring(L,topush.c_str());
|
lua_pushstring(L, topush.c_str());
|
||||||
lua_settable(L, top_lvl2);
|
lua_settable(L, top_lvl2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!server["name"].asString().empty()) {
|
if (!server["name"].asString().empty()) {
|
||||||
lua_pushstring(L,"name");
|
lua_pushstring(L, "name");
|
||||||
std::string topush = server["name"].asString();
|
std::string topush = server["name"].asString();
|
||||||
lua_pushstring(L,topush.c_str());
|
lua_pushstring(L, topush.c_str());
|
||||||
lua_settable(L, top_lvl2);
|
lua_settable(L, top_lvl2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!server["address"].asString().empty()) {
|
if (!server["address"].asString().empty()) {
|
||||||
lua_pushstring(L,"address");
|
lua_pushstring(L, "address");
|
||||||
std::string topush = server["address"].asString();
|
std::string topush = server["address"].asString();
|
||||||
lua_pushstring(L,topush.c_str());
|
lua_pushstring(L, topush.c_str());
|
||||||
lua_settable(L, top_lvl2);
|
lua_settable(L, top_lvl2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!server["port"].asString().empty()) {
|
if (!server["port"].asString().empty()) {
|
||||||
lua_pushstring(L,"port");
|
lua_pushstring(L, "port");
|
||||||
std::string topush = server["port"].asString();
|
std::string topush = server["port"].asString();
|
||||||
lua_pushstring(L,topush.c_str());
|
lua_pushstring(L, topush.c_str());
|
||||||
lua_settable(L, top_lvl2);
|
lua_settable(L, top_lvl2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -406,6 +406,37 @@ int ModApiMainMenu::l_get_favorites(lua_State *L)
|
|||||||
lua_settable(L, top_lvl2);
|
lua_settable(L, top_lvl2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (server["clients_list"].isArray()) {
|
||||||
|
unsigned int index_lvl2 = 1;
|
||||||
|
lua_pushstring(L, "clients_list");
|
||||||
|
lua_newtable(L);
|
||||||
|
int top_lvl3 = lua_gettop(L);
|
||||||
|
for (const Json::Value &client : server["clients_list"]) {
|
||||||
|
lua_pushnumber(L, index_lvl2);
|
||||||
|
std::string topush = client.asString();
|
||||||
|
lua_pushstring(L, topush.c_str());
|
||||||
|
lua_settable(L, top_lvl3);
|
||||||
|
index_lvl2++;
|
||||||
|
}
|
||||||
|
lua_settable(L, top_lvl2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (server["mods"].isArray()) {
|
||||||
|
unsigned int index_lvl2 = 1;
|
||||||
|
lua_pushstring(L, "mods");
|
||||||
|
lua_newtable(L);
|
||||||
|
int top_lvl3 = lua_gettop(L);
|
||||||
|
for (const Json::Value &mod : server["mods"]) {
|
||||||
|
|
||||||
|
lua_pushnumber(L, index_lvl2);
|
||||||
|
std::string topush = mod.asString();
|
||||||
|
lua_pushstring(L, topush.c_str());
|
||||||
|
lua_settable(L, top_lvl3);
|
||||||
|
index_lvl2++;
|
||||||
|
}
|
||||||
|
lua_settable(L, top_lvl2);
|
||||||
|
}
|
||||||
|
|
||||||
lua_settable(L, top);
|
lua_settable(L, top);
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user