campaignd: Add server id to server id request

[server_info] id= defines a free-form string that can be used to
identify the server instance independently from the campaignd version
used for it.

Meant for PR #5588, which requires an unchanging identification for
campaignd instances in lieu of game_config::wesnoth_version.
This commit is contained in:
Iris Morelle 2021-03-08 11:49:56 -03:00
parent cb5f45cae6
commit 64e68ca0b2
4 changed files with 14 additions and 4 deletions

View file

@ -50,6 +50,7 @@ addons_client::addons_client(const std::string& address)
, conn_(nullptr)
, last_error_()
, last_error_data_()
, server_id_()
, server_version_()
, server_capabilities_()
, server_url_()
@ -82,6 +83,7 @@ void addons_client::connect()
if(!update_last_error(response_buf)) {
if(const auto& info = response_buf.child("server_id")) {
server_id_ = info["id"].str();
server_version_ = info["version"].str();
for(const auto& cap : utils::split(info["cap"].str())) {
@ -96,14 +98,15 @@ void addons_client::connect()
}
if(server_version_.empty()) {
LOG_ADDONS << "Server version 1.15.7 or earlier\n";
// An educated guess
server_capabilities_ = { "auth:legacy" };
} else {
LOG_ADDONS << "Server version " << server_version_ << '\n';
}
LOG_ADDONS << "Server supports: " << utils::join(server_capabilities_, " ") << '\n';
const std::string version_desc = server_version_.empty() ? "<1.15.7 or earlier>" : server_version_;
const std::string id_desc = server_id_.empty() ? "<id not provided>" : server_id_;
LOG_ADDONS << "Server " << id_desc << " version " << version_desc
<< " supports: " << utils::join(server_capabilities_, " ") << '\n';
}
bool addons_client::request_addons_list(config& cfg)
@ -599,6 +602,7 @@ void addons_client::clear_last_error()
void addons_client::clear_server_info()
{
server_id_.clear();
server_version_.clear();
server_capabilities_.clear();
server_url_.clear();

View file

@ -216,6 +216,7 @@ private:
std::string last_error_;
std::string last_error_data_;
std::string server_id_;
std::string server_version_;
std::set<std::string> server_capabilities_;
std::string server_url_;

View file

@ -271,6 +271,7 @@ server::server(const std::string& cfg_file, unsigned short port)
, strict_versions_(true)
, hooks_()
, handlers_()
, server_id_()
, feedback_url_format_()
, web_url_()
, license_notice_()
@ -331,6 +332,7 @@ void server::load_config()
update_pack_lifespan_ = cfg_["update_pack_lifespan"].to_time_t(30 * 24 * 60 * 60);
if(const auto& svinfo_cfg = server_info()) {
server_id_ = svinfo_cfg["id"].str();
feedback_url_format_ = svinfo_cfg["feedback_url_format"].str();
web_url_ = svinfo_cfg["web_url"].str(default_web_url);
license_notice_ = svinfo_cfg["license_notice"].str(default_license_notice);
@ -884,6 +886,7 @@ void server::handle_server_id(const server::request& req)
std::ostringstream ostr;
write(ostr, config{"server_id", config{
"id", server_id_,
"cap", utils::join(capabilities_),
"version", game_config::revision,
"url", web_url_,

View file

@ -121,6 +121,8 @@ private:
std::map<std::string, std::string> hooks_;
request_handlers_table handlers_;
std::string server_id_;
std::string feedback_url_format_;
std::string web_url_;