diff options
author | Loïc Blot <nerzhul@users.noreply.github.com> | 2017-08-19 14:25:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-19 14:25:35 +0200 |
commit | 7528986e4449febead9b18b6118f0b096f7cf800 (patch) | |
tree | 8e526c1403ba8d0689ab40a24165fc19d8a07e27 /src/serverlist.cpp | |
parent | 1992db1395d9c068327a7c08bac7a24ef7112274 (diff) | |
download | minetest-7528986e4449febead9b18b6118f0b096f7cf800.tar.gz minetest-7528986e4449febead9b18b6118f0b096f7cf800.tar.bz2 minetest-7528986e4449febead9b18b6118f0b096f7cf800.zip |
Code modernization: src/p*, src/q*, src/r*, src/s* (partial) (#6282)
* Code modernization: src/p*, src/q*, src/r*, src/s* (partial)
* empty function
* default constructor/destructor
* for range-based loops
* use emplace_back instead of push_back
* C++ STL header style
* Spelling: vertice -> vertex
Diffstat (limited to 'src/serverlist.cpp')
-rw-r--r-- | src/serverlist.cpp | 38 |
1 files changed, 16 insertions, 22 deletions
diff --git a/src/serverlist.cpp b/src/serverlist.cpp index cc38ec8ce..ae3bd98a4 100644 --- a/src/serverlist.cpp +++ b/src/serverlist.cpp @@ -89,9 +89,9 @@ std::vector<ServerListSpec> getOnline() return server_list; } - for (unsigned int i = 0; i < root.size(); i++) { - if (root[i].isObject()) { - server_list.push_back(root[i]); + for (const Json::Value &i : root) { + if (i.isObject()) { + server_list.push_back(i); } } @@ -167,14 +167,12 @@ std::vector<ServerListSpec> deSerialize(const std::string &liststring) const std::string serialize(const std::vector<ServerListSpec> &serverlist) { std::string liststring; - for (std::vector<ServerListSpec>::const_iterator it = serverlist.begin(); - it != serverlist.end(); - ++it) { + for (const ServerListSpec &it : serverlist) { liststring += "[server]\n"; - liststring += (*it)["name"].asString() + '\n'; - liststring += (*it)["address"].asString() + '\n'; - liststring += (*it)["port"].asString() + '\n'; - liststring += (*it)["description"].asString() + '\n'; + liststring += it["name"].asString() + '\n'; + liststring += it["address"].asString() + '\n'; + liststring += it["port"].asString() + '\n'; + liststring += it["description"].asString() + '\n'; liststring += '\n'; } return liststring; @@ -184,10 +182,8 @@ const std::string serializeJson(const std::vector<ServerListSpec> &serverlist) { Json::Value root; Json::Value list(Json::arrayValue); - for (std::vector<ServerListSpec>::const_iterator it = serverlist.begin(); - it != serverlist.end(); - ++it) { - list.append(*it); + for (const ServerListSpec &it : serverlist) { + list.append(it); } root["list"] = list; Json::FastWriter writer; @@ -231,12 +227,11 @@ void sendAnnounce(AnnounceAction action, server["clients"] = (int) clients_names.size(); server["clients_max"] = g_settings->getU16("max_users"); server["clients_list"] = Json::Value(Json::arrayValue); - for (std::vector<std::string>::const_iterator it = clients_names.begin(); - it != clients_names.end(); - ++it) { - server["clients_list"].append(*it); + for (const std::string &clients_name : clients_names) { + server["clients_list"].append(clients_name); } - if (gameid != "") server["gameid"] = gameid; + if (!gameid.empty()) + server["gameid"] = gameid; } if (action == AA_START) { @@ -246,9 +241,8 @@ void sendAnnounce(AnnounceAction action, server["privs"] = g_settings->get("default_privs"); server["can_see_far_names"] = g_settings->getS16("player_transfer_distance") <= 0; server["mods"] = Json::Value(Json::arrayValue); - for (std::vector<ModSpec>::const_iterator it = mods.begin(); - it != mods.end(); ++it) { - server["mods"].append(it->name); + for (const ModSpec &mod : mods) { + server["mods"].append(mod.name); } actionstream << "Announcing to " << g_settings->get("serverlist_url") << std::endl; } else if (action == AA_UPDATE) { |