-/******************************************************************************/
-int ModApiMainMenu::l_get_favorites(lua_State *L)
-{
- std::string listtype = "local";
-
- if (!lua_isnone(L,1)) {
- listtype = luaL_checkstring(L,1);
- }
-
- std::vector<ServerListSpec> servers;
-
- if(listtype == "online") {
- servers = ServerList::getOnline();
- } else {
- servers = ServerList::getLocal();
- }
-
- lua_newtable(L);
- int top = lua_gettop(L);
- unsigned int index = 1;
-
- for (const Json::Value &server : servers) {
-
- lua_pushnumber(L,index);
-
- lua_newtable(L);
- int top_lvl2 = lua_gettop(L);
-
- if (!server["clients"].asString().empty()) {
- std::string clients_raw = server["clients"].asString();
- char* endptr = 0;
- int numbervalue = strtol(clients_raw.c_str(),&endptr,10);
-
- if ((!clients_raw.empty()) && (*endptr == 0)) {
- lua_pushstring(L,"clients");
- lua_pushnumber(L,numbervalue);
- lua_settable(L, top_lvl2);
- }
- }
-
- if (!server["clients_max"].asString().empty()) {
-
- std::string clients_max_raw = server["clients_max"].asString();
- char* endptr = 0;
- int numbervalue = strtol(clients_max_raw.c_str(),&endptr,10);
-
- if ((!clients_max_raw.empty()) && (*endptr == 0)) {
- lua_pushstring(L,"clients_max");
- lua_pushnumber(L,numbervalue);
- lua_settable(L, top_lvl2);
- }
- }
-
- if (!server["version"].asString().empty()) {
- lua_pushstring(L,"version");
- std::string topush = server["version"].asString();
- lua_pushstring(L,topush.c_str());
- lua_settable(L, top_lvl2);
- }
-
- if (!server["proto_min"].asString().empty()) {
- lua_pushstring(L,"proto_min");
- lua_pushinteger(L, server["proto_min"].asInt());
- lua_settable(L, top_lvl2);
- }
-
- if (!server["proto_max"].asString().empty()) {
- lua_pushstring(L,"proto_max");
- lua_pushinteger(L, server["proto_max"].asInt());
- lua_settable(L, top_lvl2);
- }
-
- if (!server["password"].asString().empty()) {
- lua_pushstring(L,"password");
- lua_pushboolean(L, server["password"].asBool());
- lua_settable(L, top_lvl2);
- }
-
- if (!server["creative"].asString().empty()) {
- lua_pushstring(L,"creative");
- lua_pushboolean(L, server["creative"].asBool());
- lua_settable(L, top_lvl2);
- }
-
- if (!server["damage"].asString().empty()) {
- lua_pushstring(L,"damage");
- lua_pushboolean(L, server["damage"].asBool());
- lua_settable(L, top_lvl2);
- }
-
- if (!server["pvp"].asString().empty()) {
- lua_pushstring(L,"pvp");
- lua_pushboolean(L, server["pvp"].asBool());
- lua_settable(L, top_lvl2);
- }
-
- if (!server["description"].asString().empty()) {
- lua_pushstring(L,"description");
- std::string topush = server["description"].asString();
- lua_pushstring(L,topush.c_str());
- lua_settable(L, top_lvl2);
- }
-
- if (!server["name"].asString().empty()) {
- lua_pushstring(L,"name");
- std::string topush = server["name"].asString();
- lua_pushstring(L,topush.c_str());
- lua_settable(L, top_lvl2);
- }
-
- if (!server["address"].asString().empty()) {
- lua_pushstring(L,"address");
- std::string topush = server["address"].asString();
- lua_pushstring(L,topush.c_str());
- lua_settable(L, top_lvl2);
- }
-
- if (!server["port"].asString().empty()) {
- lua_pushstring(L,"port");
- std::string topush = server["port"].asString();
- lua_pushstring(L,topush.c_str());
- lua_settable(L, top_lvl2);
- }
-
- if (server.isMember("ping")) {
- float ping = server["ping"].asFloat();
- lua_pushstring(L, "ping");
- lua_pushnumber(L, ping);
- lua_settable(L, top_lvl2);
- }
-
- lua_settable(L, top);
- index++;
- }
- return 1;
-}
-
-/******************************************************************************/
-int ModApiMainMenu::l_delete_favorite(lua_State *L)
-{
- std::vector<ServerListSpec> servers;
-
- std::string listtype = "local";
-
- if (!lua_isnone(L,2)) {
- listtype = luaL_checkstring(L,2);
- }
-
- if ((listtype != "local") &&
- (listtype != "online"))
- return 0;
-
-
- if(listtype == "online") {
- servers = ServerList::getOnline();
- } else {
- servers = ServerList::getLocal();
- }
-
- int fav_idx = luaL_checkinteger(L,1) -1;
-
- if ((fav_idx >= 0) &&
- (fav_idx < (int) servers.size())) {
-
- ServerList::deleteEntry(servers[fav_idx]);
- }
-
- return 0;
-}
-