2012-12-25 12:20:51 +01:00
|
|
|
/*
|
2013-02-24 18:40:43 +01:00
|
|
|
Minetest
|
2013-02-24 19:38:45 +01:00
|
|
|
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
2012-12-25 12:20:51 +01:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
2013-09-25 04:29:07 +02:00
|
|
|
#include "version.h"
|
2012-12-25 12:20:51 +01:00
|
|
|
#include "settings.h"
|
|
|
|
#include "serverlist.h"
|
|
|
|
#include "filesys.h"
|
|
|
|
#include "log.h"
|
2015-02-17 01:37:14 +01:00
|
|
|
#include "network/networkprotocol.h"
|
2016-08-10 12:10:00 +02:00
|
|
|
#include <json/json.h>
|
2013-06-23 18:30:21 +02:00
|
|
|
#include "convert_json.h"
|
2013-08-29 05:58:13 +02:00
|
|
|
#include "httpfetch.h"
|
2012-12-25 12:20:51 +01:00
|
|
|
|
|
|
|
namespace ServerList
|
|
|
|
{
|
2013-02-21 23:00:44 +01:00
|
|
|
#if USE_CURL
|
2015-10-15 19:04:15 +02:00
|
|
|
void sendAnnounce(AnnounceAction action,
|
2015-01-21 20:32:12 +01:00
|
|
|
const u16 port,
|
2014-06-20 06:59:39 +02:00
|
|
|
const std::vector<std::string> &clients_names,
|
|
|
|
const double uptime,
|
|
|
|
const u32 game_time,
|
|
|
|
const float lag,
|
|
|
|
const std::string &gameid,
|
2014-11-10 22:06:24 +01:00
|
|
|
const std::string &mg_name,
|
2015-10-15 19:04:15 +02:00
|
|
|
const std::vector<ModSpec> &mods,
|
|
|
|
bool dedicated)
|
2014-06-20 02:21:02 +02:00
|
|
|
{
|
2015-10-15 19:04:15 +02:00
|
|
|
static const char *aa_names[] = {"start", "update", "delete"};
|
2013-02-21 23:00:44 +01:00
|
|
|
Json::Value server;
|
2015-10-15 19:04:15 +02:00
|
|
|
server["action"] = aa_names[action];
|
2015-01-21 20:32:12 +01:00
|
|
|
server["port"] = port;
|
2014-06-20 06:59:39 +02:00
|
|
|
if (g_settings->exists("server_address")) {
|
|
|
|
server["address"] = g_settings->get("server_address");
|
|
|
|
}
|
2015-10-15 19:04:15 +02:00
|
|
|
if (action != AA_DELETE) {
|
2015-02-17 01:37:14 +01:00
|
|
|
bool strict_checking = g_settings->getBool("strict_protocol_version_checking");
|
2014-06-20 02:21:02 +02:00
|
|
|
server["name"] = g_settings->get("server_name");
|
|
|
|
server["description"] = g_settings->get("server_description");
|
2015-02-28 00:05:29 +01:00
|
|
|
server["version"] = g_version_string;
|
2015-02-17 01:37:14 +01:00
|
|
|
server["proto_min"] = strict_checking ? LATEST_PROTOCOL_VERSION : SERVER_PROTOCOL_VERSION_MIN;
|
|
|
|
server["proto_max"] = strict_checking ? LATEST_PROTOCOL_VERSION : SERVER_PROTOCOL_VERSION_MAX;
|
2014-06-20 02:21:02 +02:00
|
|
|
server["url"] = g_settings->get("server_url");
|
|
|
|
server["creative"] = g_settings->getBool("creative_mode");
|
|
|
|
server["damage"] = g_settings->getBool("enable_damage");
|
|
|
|
server["password"] = g_settings->getBool("disallow_empty_password");
|
|
|
|
server["pvp"] = g_settings->getBool("enable_pvp");
|
|
|
|
server["uptime"] = (int) uptime;
|
|
|
|
server["game_time"] = game_time;
|
|
|
|
server["clients"] = (int) clients_names.size();
|
2014-06-20 06:59:39 +02:00
|
|
|
server["clients_max"] = g_settings->getU16("max_users");
|
2014-06-20 02:21:02 +02:00
|
|
|
server["clients_list"] = Json::Value(Json::arrayValue);
|
2017-08-19 14:25:35 +02:00
|
|
|
for (const std::string &clients_name : clients_names) {
|
|
|
|
server["clients_list"].append(clients_name);
|
2013-10-17 23:32:49 +02:00
|
|
|
}
|
2017-08-19 14:25:35 +02:00
|
|
|
if (!gameid.empty())
|
|
|
|
server["gameid"] = gameid;
|
2013-02-21 23:00:44 +01:00
|
|
|
}
|
2013-07-04 17:39:26 +02:00
|
|
|
|
2015-10-15 19:04:15 +02:00
|
|
|
if (action == AA_START) {
|
|
|
|
server["dedicated"] = dedicated;
|
2014-06-20 02:21:02 +02:00
|
|
|
server["rollback"] = g_settings->getBool("enable_rollback_recording");
|
2014-11-10 22:06:24 +01:00
|
|
|
server["mapgen"] = mg_name;
|
2014-06-20 02:21:02 +02:00
|
|
|
server["privs"] = g_settings->get("default_privs");
|
2014-11-08 14:35:55 +01:00
|
|
|
server["can_see_far_names"] = g_settings->getS16("player_transfer_distance") <= 0;
|
2014-06-20 02:21:02 +02:00
|
|
|
server["mods"] = Json::Value(Json::arrayValue);
|
2017-08-19 14:25:35 +02:00
|
|
|
for (const ModSpec &mod : mods) {
|
|
|
|
server["mods"].append(mod.name);
|
2013-07-04 17:39:26 +02:00
|
|
|
}
|
2015-10-15 19:04:15 +02:00
|
|
|
} else if (action == AA_UPDATE) {
|
2014-01-06 23:50:45 +01:00
|
|
|
if (lag)
|
2014-06-20 02:21:02 +02:00
|
|
|
server["lag"] = lag;
|
2013-07-04 17:39:26 +02:00
|
|
|
}
|
|
|
|
|
2020-09-26 18:41:16 +02:00
|
|
|
if (action == AA_START) {
|
|
|
|
actionstream << "Announcing " << aa_names[action] << " to " <<
|
|
|
|
g_settings->get("serverlist_url") << std::endl;
|
|
|
|
} else {
|
|
|
|
infostream << "Announcing " << aa_names[action] << " to " <<
|
|
|
|
g_settings->get("serverlist_url") << std::endl;
|
|
|
|
}
|
|
|
|
|
2014-09-15 02:46:45 +02:00
|
|
|
HTTPFetchRequest fetch_request;
|
2022-01-01 22:44:56 +01:00
|
|
|
fetch_request.caller = HTTPFETCH_PRINT_ERR;
|
2014-09-15 02:46:45 +02:00
|
|
|
fetch_request.url = g_settings->get("serverlist_url") + std::string("/announce");
|
2020-07-29 23:16:21 +02:00
|
|
|
fetch_request.method = HTTP_POST;
|
|
|
|
fetch_request.fields["json"] = fastWriteJson(server);
|
2014-09-15 02:46:45 +02:00
|
|
|
fetch_request.multipart = true;
|
|
|
|
httpfetch_async(fetch_request);
|
2013-02-21 23:00:44 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-10-15 19:04:15 +02:00
|
|
|
} // namespace ServerList
|