Add-ons (campaignd) client class. More...
#include <client.hpp>
Classes | |
struct | install_result |
Contains the outcome of an add-on install operation. More... | |
struct | invalid_server_address |
struct | not_connected_to_server |
struct | user_disconnect |
struct | user_exit |
Public Types | |
enum class | install_outcome { success , failure , abort } |
Installation outcome values. More... | |
Public Member Functions | |
addons_client (const addons_client &)=delete | |
addons_client & | operator= (const addons_client &)=delete |
addons_client (const std::string &address) | |
Constructor. More... | |
void | connect () |
Tries to establish a connection to the add-ons server. More... | |
void | disconnect () |
Disconnects from the add-on server. More... | |
const std::string & | addr () const |
Returns the current hostname:port used for this connection. More... | |
const std::string & | get_last_server_error () const |
Returns the last error message sent by the server, or an empty string. More... | |
const std::string & | get_last_server_error_data () const |
Returns the last error message extra data sent by the server, or an empty string. More... | |
bool | is_connected () |
Returns true if the client is connected to the server. More... | |
bool | request_addons_list (config &cfg) |
Request the add-ons list from the server. More... | |
const std::string & | server_url () const |
Retrieves the add-ons server web URL if available. More... | |
bool | request_distribution_terms (std::string &terms) |
Request the add-ons server distribution terms message. More... | |
install_result | install_addon_with_checks (const addons_list &addons, const addon_info &addon) |
Performs an add-on download and install cycle. More... | |
bool | upload_addon (const std::string &id, std::string &response_message, config &cfg, bool local_only) |
Uploads an add-on to the server. More... | |
bool | delete_remote_addon (const std::string &id, std::string &response_message) |
Requests the specified add-on to be removed from the server. More... | |
bool | server_supports (const std::string &cap_id) const |
Returns whether the server supports the given named capability. More... | |
bool | server_supports_delta () const |
Returns whether the server supports incremental (delta) downloads and uploads. More... | |
bool | server_supports_legacy_auth () const |
Returns whether the server supports passphrase authentication on an add-on basis. More... | |
bool | using_tls () const |
Returns whether the current connection uses TLS. More... | |
const std::string & | server_id () const |
const std::string & | server_version () const |
Private Types | |
enum class | transfer_mode { download , connect , upload } |
Private Member Functions | |
bool | download_addon (config &archive_cfg, const std::string &id, const std::string &title, const version_info &version, bool increase_downloads=true) |
Downloads the specified add-on from the server. More... | |
bool | install_addon (config &archive_cfg, const addon_info &info) |
Installs the specified add-on using an archive received from the server. More... | |
bool | try_fetch_addon (const addon_info &addon) |
install_result | do_resolve_addon_dependencies (const addons_list &addons, const addon_info &addon) |
Warns the user about unresolved dependencies and installs them if they choose to do so. More... | |
bool | do_check_before_overwriting_addon (const addon_info &addon) |
Checks whether the given add-on has local .pbl or VCS information and asks before overwriting it. More... | |
void | check_connected () const |
Makes sure the add-ons server connection is working. More... | |
void | send_request (const config &request, config &response) |
Sends a request to the add-ons server. More... | |
void | send_simple_request (const std::string &request_string, config &response) |
Sends a simple request message to the add-ons server. More... | |
void | wait_for_transfer_done (const std::string &status_message, transfer_mode mode=transfer_mode::download) |
Waits for a network transfer, displaying a status window. More... | |
bool | update_last_error (config &response_cfg) |
void | clear_last_error () |
void | clear_server_info () |
Private Attributes | |
std::string | addr_ |
std::string | host_ |
std::string | port_ |
std::unique_ptr< network_asio::connection > | conn_ |
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_ |
std::string | license_notice_ |
Add-ons (campaignd) client class.
This class encapsulates much of the logic behind the campaignd add-ons server interaction for the client-side. Most networking operations with it are implemented here.
Definition at line 40 of file client.hpp.
|
strong |
Installation outcome values.
Definition at line 111 of file client.hpp.
|
strongprivate |
Enumerator | |
---|---|
download | |
connect | |
upload |
Definition at line 232 of file client.hpp.
|
delete |
|
explicit |
Constructor.
address | Server address (e.g. "localhost:15999"). |
Definition at line 49 of file client.cpp.
References addr_, default_campaignd_port, host_, parse_network_address(), and port_.
|
inline |
Returns the current hostname:port used for this connection.
Definition at line 74 of file client.hpp.
References addr_.
Referenced by gui2::dialogs::addon_manager::pre_show().
|
private |
Makes sure the add-ons server connection is working.
Definition at line 631 of file client.cpp.
References conn_, and ERR_ADDONS.
Referenced by send_request(), and wait_for_transfer_done().
|
private |
Definition at line 616 of file client.cpp.
References last_error_, and last_error_data_.
Referenced by connect(), and disconnect().
|
private |
Definition at line 622 of file client.cpp.
References license_notice_, server_capabilities_, server_id_, server_url_, and server_version_.
Referenced by disconnect().
void addons_client::connect | ( | ) |
Tries to establish a connection to the add-ons server.
Definition at line 69 of file client.cpp.
References addr_, clear_last_error(), conn_, connect, host_, lg::info(), utils::join(), license_notice_, LOG_ADDONS, wfl::msg(), config::optional_child(), port_, send_simple_request(), server_capabilities_, server_id_, server_url_, server_version_, utils::split(), update_last_error(), VGETTEXT, and wait_for_transfer_done().
Referenced by ad_hoc_addon_fetch_session(), read_addon_connection_data::cancel(), and write_addon_connection_data::cancel().
bool addons_client::delete_remote_addon | ( | const std::string & | id, |
std::string & | response_message | ||
) |
Requests the specified add-on to be removed from the server.
This method reads the add-on upload passphrase from the associated .pbl file.
id | Id. of the add-on to take down. |
response_message | The server response message on success, such as "add-on accepted". |
Definition at line 270 of file client.cpp.
References config::add_child(), dummy, font::escape_text(), prefs::get(), get_addon_pbl_info(), id, LOG_ADDONS, make_addon_title(), config::optional_child(), prefs::password(), send_request(), prefs::set_password(), update_last_error(), VGETTEXT, and wait_for_transfer_done().
Referenced by gui2::dialogs::addon_manager::delete_addon().
|
inline |
Disconnects from the add-on server.
Definition at line 66 of file client.hpp.
References clear_last_error(), clear_server_info(), and conn_.
Referenced by connect_connection_data::cancel().
|
private |
Checks whether the given add-on has local .pbl or VCS information and asks before overwriting it.
Definition at line 538 of file client.cpp.
References _(), utils::bullet_list(), font::escape_text(), have_addon_in_vcs_tree(), have_addon_pbl_info(), addon_info::id, gui2::OK, gui2::show_message(), addon_info::title, VGETTEXT, and gui2::dialogs::message::yes_no_buttons.
Referenced by install_addon_with_checks().
|
private |
Warns the user about unresolved dependencies and installs them if they choose to do so.
Returns: outcome: abort in case the user chose to abort because of an issue success otherwise wml_change: indicates if new wml content was installed
Definition at line 431 of file client.cpp.
References _(), _n(), abort, ADDON_INSTALLED_UPGRADABLE, ADDON_NONE, utils::bullet_list(), get_addon_tracking_info(), lg::info(), is_addon_installed(), make_addon_title(), gui2::OK, addons_client::install_result::outcome, addon_info::resolve_dependencies(), gui2::show_message(), success, addon_info::title, try_fetch_addon(), font::unicode_bullet, cursor::WAIT, addons_client::install_result::wml_changed, and gui2::dialogs::message::yes_no_buttons.
Referenced by install_addon_with_checks().
|
private |
Downloads the specified add-on from the server.
archive_cfg | Config object to hold the downloaded add-on archive data. |
id | Add-on id. |
title | Add-on title, used for status display. |
version | Specifies an add-on version to download. |
increase_downloads | Whether to request the server to increase the add-on's download count or not (e.g. when upgrading). |
Definition at line 317 of file client.cpp.
References config::add_child(), config::clear(), font::escape_text(), get_addon_version_info(), id, LOG_ADDONS, send_request(), version_info::str(), update_last_error(), VGETTEXT, and wait_for_transfer_done().
Referenced by try_fetch_addon().
|
inline |
Returns the last error message sent by the server, or an empty string.
Definition at line 77 of file client.hpp.
References last_error_.
Referenced by gui2::dialogs::addon_manager::delete_addon(), gui2::dialogs::addon_manager::publish_addon(), and try_fetch_addon().
|
inline |
Returns the last error message extra data sent by the server, or an empty string.
Definition at line 80 of file client.hpp.
References last_error_data_.
Referenced by gui2::dialogs::addon_manager::publish_addon().
|
private |
Installs the specified add-on using an archive received from the server.
An _info.cfg file will be added to the local directory for the add-on to keep track of version and dependency information.
Definition at line 340 of file client.cpp.
References _(), config::all_children_view(), check_case_insensitive_duplicates(), check_names_legal(), gui2::dialogs::file_progress::display(), font::escape_text(), config::has_child(), lg::info(), LOG_ADDONS, purge_addon(), remove_local_addon(), gui2::show_error_message(), unarchive_addon(), VGETTEXT, cursor::WAIT, write_addon_install_info(), and WRN_ADDONS.
Referenced by try_fetch_addon().
addons_client::install_result addons_client::install_addon_with_checks | ( | const addons_list & | addons, |
const addon_info & | addon | ||
) |
Performs an add-on download and install cycle.
This checks and prompts the user through the UI before overwriting an existing add-on with a .pbl file or version control system files (.git/, .svn/, etc.). It also resolves add-on dependencies and downloads them using the same system before downloading the original target add-on.
addons | Add-ons list used for resolving dependencies. |
addon | Identity of the singular add-on that will be downloaded. |
Definition at line 571 of file client.cpp.
References abort, do_check_before_overwriting_addon(), do_resolve_addon_dependencies(), failure, addons_client::install_result::outcome, success, try_fetch_addon(), and addons_client::install_result::wml_changed.
Referenced by ad_hoc_addon_fetch_session(), gui2::dialogs::addon_manager::install_addon(), and gui2::dialogs::addon_manager::update_all_addons().
|
inline |
Returns true if the client is connected to the server.
Definition at line 83 of file client.hpp.
References conn_.
|
delete |
bool addons_client::request_addons_list | ( | config & | cfg | ) |
Request the add-ons list from the server.
cfg | A config object whose contents are replaced with the server's list if available, cleared otherwise. |
Definition at line 115 of file client.cpp.
References _(), config::clear(), config::mandatory_child(), send_simple_request(), swap(), update_last_error(), and wait_for_transfer_done().
Referenced by gui2::dialogs::addon_manager::fetch_addons_list().
bool addons_client::request_distribution_terms | ( | std::string & | terms | ) |
Request the add-ons server distribution terms message.
Definition at line 132 of file client.cpp.
References _(), license_notice_, config::optional_child(), send_simple_request(), update_last_error(), and wait_for_transfer_done().
Referenced by gui2::dialogs::addon_manager::publish_addon().
Sends a request to the add-ons server.
request | The client request WML. |
response | A config object whose contents are replaced with the server response WML. |
Definition at line 640 of file client.cpp.
References check_connected(), config::clear(), and conn_.
Referenced by delete_remote_addon(), download_addon(), send_simple_request(), and upload_addon().
|
private |
Sends a simple request message to the add-ons server.
The real request sent consists of a WML object with an empty child node whose name corresponds to request_string
request_string | The client request string. |
response | A config object whose contents are replaced with the server response WML. |
Definition at line 648 of file client.cpp.
References config::add_child(), and send_request().
Referenced by connect(), request_addons_list(), and request_distribution_terms().
|
inline |
Definition at line 221 of file client.hpp.
References server_id_.
Referenced by gui2::dialogs::addon_manager::pre_show().
|
inline |
Returns whether the server supports the given named capability.
Definition at line 192 of file client.hpp.
References server_capabilities_.
Referenced by server_supports_delta(), and server_supports_legacy_auth().
|
inline |
Returns whether the server supports incremental (delta) downloads and uploads.
Definition at line 200 of file client.hpp.
References server_supports().
|
inline |
Returns whether the server supports passphrase authentication on an add-on basis.
Definition at line 208 of file client.hpp.
References server_supports().
|
inline |
Retrieves the add-ons server web URL if available.
Definition at line 98 of file client.hpp.
References server_url_.
|
inline |
Definition at line 226 of file client.hpp.
References server_version_.
Referenced by gui2::dialogs::addon_manager::pre_show().
|
private |
Definition at line 412 of file client.cpp.
References _(), addon_info::current_version, addon_info::display_title_full(), download_addon(), get_last_server_error(), addon_info::id, install_addon(), is_addon_installed(), and gui2::show_error_message().
Referenced by do_resolve_addon_dependencies(), and install_addon_with_checks().
|
private |
Definition at line 597 of file client.cpp.
References ERR_ADDONS, font::escape_text(), last_error_, last_error_data_, config::optional_child(), and translated_addon_check_status().
Referenced by connect(), delete_remote_addon(), download_addon(), request_addons_list(), request_distribution_terms(), and upload_addon().
bool addons_client::upload_addon | ( | const std::string & | id, |
std::string & | response_message, | ||
config & | cfg, | ||
bool | local_only | ||
) |
Uploads an add-on to the server.
This method reads the add-on upload passphrase and other data from the associated .pbl file. If the .pbl file doesn't have a passphrase, a new, random one will be automatically generated and written to the file for the user.
id | Id. of the add-on to upload. |
response_message | The server response message on success, such as "add-on accepted". |
cfg | The pbl config of the add-on with the specified id. |
local_only | Whether the addon is not present on the server. |
Definition at line 155 of file client.cpp.
References _(), config::add_child(), addon_name_legal(), game_config::allow_insecure, config::append(), archive_addon(), check_case_insensitive_duplicates(), check_names_legal(), conn_, contains_hashlist(), font::escape_text(), config::has_child(), id, utils::join(), last_error_, last_error_data_, LOG_ADDONS, make_addon_title(), make_updatepack(), config::optional_child(), send_request(), update_last_error(), upload, VGETTEXT, and wait_for_transfer_done().
Referenced by gui2::dialogs::addon_manager::publish_addon().
|
inline |
Returns whether the current connection uses TLS.
Definition at line 216 of file client.hpp.
References conn_.
Referenced by gui2::dialogs::addon_manager::pre_show().
|
private |
Waits for a network transfer, displaying a status window.
The window is displayed with the specified contents. This method doesn't return until the network transfer is complete. It will throw a user_exit exception if the user cancels the transfer by canceling the status window.
Definition at line 690 of file client.cpp.
References _(), check_connected(), conn_, connect, download, gui2::dialogs::modal_dialog::show(), and upload.
Referenced by connect(), delete_remote_addon(), download_addon(), request_addons_list(), request_distribution_terms(), and upload_addon().
|
private |
Definition at line 234 of file client.hpp.
Referenced by addons_client(), addr(), and connect().
|
private |
Definition at line 237 of file client.hpp.
Referenced by check_connected(), connect(), disconnect(), is_connected(), send_request(), upload_addon(), using_tls(), and wait_for_transfer_done().
|
private |
Definition at line 235 of file client.hpp.
Referenced by addons_client(), and connect().
|
private |
Definition at line 238 of file client.hpp.
Referenced by clear_last_error(), get_last_server_error(), update_last_error(), and upload_addon().
|
private |
Definition at line 239 of file client.hpp.
Referenced by clear_last_error(), get_last_server_error_data(), update_last_error(), and upload_addon().
|
private |
Definition at line 245 of file client.hpp.
Referenced by clear_server_info(), connect(), and request_distribution_terms().
|
private |
Definition at line 236 of file client.hpp.
Referenced by addons_client(), and connect().
|
private |
Definition at line 243 of file client.hpp.
Referenced by clear_server_info(), connect(), and server_supports().
|
private |
Definition at line 241 of file client.hpp.
Referenced by clear_server_info(), connect(), and server_id().
|
private |
Definition at line 244 of file client.hpp.
Referenced by clear_server_info(), connect(), and server_url().
|
private |
Definition at line 242 of file client.hpp.
Referenced by clear_server_info(), connect(), and server_version().