Skip to content

Commit 74d9b60

Browse files
authoredMay 1, 2020
Give the online lua mainmenu also the client_list and mods (#8691)
1 parent 3f275d7 commit 74d9b60

File tree

2 files changed

+70
-36
lines changed

2 files changed

+70
-36
lines changed
 

Diff for: ‎doc/menu_lua_api.txt

+14-11
Original file line numberDiff line numberDiff line change
@@ -156,18 +156,21 @@ core.get_favorites(location) -> list of favorites (possible in async calls)
156156
^ location: "local" or "online"
157157
^ returns {
158158
[1] = {
159-
clients = <number of clients/nil>,
160-
clients_max = <maximum number of clients/nil>,
161-
version = <server version/nil>,
162-
password = <true/nil>,
163-
creative = <true/nil>,
164-
damage = <true/nil>,
165-
pvp = <true/nil>,
166-
description = <server description/nil>,
167-
name = <server name/nil>,
168-
address = <address of server/nil>,
169-
port = <port>
159+
clients = <number of clients/nil>,
160+
clients_max = <maximum number of clients/nil>,
161+
version = <server version/nil>,
162+
password = <true/nil>,
163+
creative = <true/nil>,
164+
damage = <true/nil>,
165+
pvp = <true/nil>,
166+
description = <server description/nil>,
167+
name = <server name/nil>,
168+
address = <address of server/nil>,
169+
port = <port>
170+
clients_list = <array of clients/nil>
171+
mods = <array of mods/nil>
170172
},
173+
...
171174
}
172175
core.delete_favorite(id, location) -> success
173176

Diff for: ‎src/script/lua_api/l_mainmenu.cpp

+56-25
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,8 @@ int ModApiMainMenu::l_get_favorites(lua_State *L)
280280
{
281281
std::string listtype = "local";
282282

283-
if (!lua_isnone(L,1)) {
284-
listtype = luaL_checkstring(L,1);
283+
if (!lua_isnone(L, 1)) {
284+
listtype = luaL_checkstring(L, 1);
285285
}
286286

287287
std::vector<ServerListSpec> servers;
@@ -298,19 +298,19 @@ int ModApiMainMenu::l_get_favorites(lua_State *L)
298298

299299
for (const Json::Value &server : servers) {
300300

301-
lua_pushnumber(L,index);
301+
lua_pushnumber(L, index);
302302

303303
lua_newtable(L);
304304
int top_lvl2 = lua_gettop(L);
305305

306306
if (!server["clients"].asString().empty()) {
307307
std::string clients_raw = server["clients"].asString();
308308
char* endptr = 0;
309-
int numbervalue = strtol(clients_raw.c_str(),&endptr,10);
309+
int numbervalue = strtol(clients_raw.c_str(), &endptr,10);
310310

311311
if ((!clients_raw.empty()) && (*endptr == 0)) {
312-
lua_pushstring(L,"clients");
313-
lua_pushnumber(L,numbervalue);
312+
lua_pushstring(L, "clients");
313+
lua_pushnumber(L, numbervalue);
314314
lua_settable(L, top_lvl2);
315315
}
316316
}
@@ -319,83 +319,83 @@ int ModApiMainMenu::l_get_favorites(lua_State *L)
319319

320320
std::string clients_max_raw = server["clients_max"].asString();
321321
char* endptr = 0;
322-
int numbervalue = strtol(clients_max_raw.c_str(),&endptr,10);
322+
int numbervalue = strtol(clients_max_raw.c_str(), &endptr,10);
323323

324324
if ((!clients_max_raw.empty()) && (*endptr == 0)) {
325-
lua_pushstring(L,"clients_max");
326-
lua_pushnumber(L,numbervalue);
325+
lua_pushstring(L, "clients_max");
326+
lua_pushnumber(L, numbervalue);
327327
lua_settable(L, top_lvl2);
328328
}
329329
}
330330

331331
if (!server["version"].asString().empty()) {
332-
lua_pushstring(L,"version");
332+
lua_pushstring(L, "version");
333333
std::string topush = server["version"].asString();
334-
lua_pushstring(L,topush.c_str());
334+
lua_pushstring(L, topush.c_str());
335335
lua_settable(L, top_lvl2);
336336
}
337337

338338
if (!server["proto_min"].asString().empty()) {
339-
lua_pushstring(L,"proto_min");
339+
lua_pushstring(L, "proto_min");
340340
lua_pushinteger(L, server["proto_min"].asInt());
341341
lua_settable(L, top_lvl2);
342342
}
343343

344344
if (!server["proto_max"].asString().empty()) {
345-
lua_pushstring(L,"proto_max");
345+
lua_pushstring(L, "proto_max");
346346
lua_pushinteger(L, server["proto_max"].asInt());
347347
lua_settable(L, top_lvl2);
348348
}
349349

350350
if (!server["password"].asString().empty()) {
351-
lua_pushstring(L,"password");
351+
lua_pushstring(L, "password");
352352
lua_pushboolean(L, server["password"].asBool());
353353
lua_settable(L, top_lvl2);
354354
}
355355

356356
if (!server["creative"].asString().empty()) {
357-
lua_pushstring(L,"creative");
357+
lua_pushstring(L, "creative");
358358
lua_pushboolean(L, server["creative"].asBool());
359359
lua_settable(L, top_lvl2);
360360
}
361361

362362
if (!server["damage"].asString().empty()) {
363-
lua_pushstring(L,"damage");
363+
lua_pushstring(L, "damage");
364364
lua_pushboolean(L, server["damage"].asBool());
365365
lua_settable(L, top_lvl2);
366366
}
367367

368368
if (!server["pvp"].asString().empty()) {
369-
lua_pushstring(L,"pvp");
369+
lua_pushstring(L, "pvp");
370370
lua_pushboolean(L, server["pvp"].asBool());
371371
lua_settable(L, top_lvl2);
372372
}
373373

374374
if (!server["description"].asString().empty()) {
375-
lua_pushstring(L,"description");
375+
lua_pushstring(L, "description");
376376
std::string topush = server["description"].asString();
377-
lua_pushstring(L,topush.c_str());
377+
lua_pushstring(L, topush.c_str());
378378
lua_settable(L, top_lvl2);
379379
}
380380

381381
if (!server["name"].asString().empty()) {
382-
lua_pushstring(L,"name");
382+
lua_pushstring(L, "name");
383383
std::string topush = server["name"].asString();
384-
lua_pushstring(L,topush.c_str());
384+
lua_pushstring(L, topush.c_str());
385385
lua_settable(L, top_lvl2);
386386
}
387387

388388
if (!server["address"].asString().empty()) {
389-
lua_pushstring(L,"address");
389+
lua_pushstring(L, "address");
390390
std::string topush = server["address"].asString();
391-
lua_pushstring(L,topush.c_str());
391+
lua_pushstring(L, topush.c_str());
392392
lua_settable(L, top_lvl2);
393393
}
394394

395395
if (!server["port"].asString().empty()) {
396-
lua_pushstring(L,"port");
396+
lua_pushstring(L, "port");
397397
std::string topush = server["port"].asString();
398-
lua_pushstring(L,topush.c_str());
398+
lua_pushstring(L, topush.c_str());
399399
lua_settable(L, top_lvl2);
400400
}
401401

@@ -406,6 +406,37 @@ int ModApiMainMenu::l_get_favorites(lua_State *L)
406406
lua_settable(L, top_lvl2);
407407
}
408408

409+
if (server["clients_list"].isArray()) {
410+
unsigned int index_lvl2 = 1;
411+
lua_pushstring(L, "clients_list");
412+
lua_newtable(L);
413+
int top_lvl3 = lua_gettop(L);
414+
for (const Json::Value &client : server["clients_list"]) {
415+
lua_pushnumber(L, index_lvl2);
416+
std::string topush = client.asString();
417+
lua_pushstring(L, topush.c_str());
418+
lua_settable(L, top_lvl3);
419+
index_lvl2++;
420+
}
421+
lua_settable(L, top_lvl2);
422+
}
423+
424+
if (server["mods"].isArray()) {
425+
unsigned int index_lvl2 = 1;
426+
lua_pushstring(L, "mods");
427+
lua_newtable(L);
428+
int top_lvl3 = lua_gettop(L);
429+
for (const Json::Value &mod : server["mods"]) {
430+
431+
lua_pushnumber(L, index_lvl2);
432+
std::string topush = mod.asString();
433+
lua_pushstring(L, topush.c_str());
434+
lua_settable(L, top_lvl3);
435+
index_lvl2++;
436+
}
437+
lua_settable(L, top_lvl2);
438+
}
439+
409440
lua_settable(L, top);
410441
index++;
411442
}

0 commit comments

Comments
 (0)
Please sign in to comment.