Add-ons (campaignd) client class. More...
#include <client.hpp>
Classes | |
struct | invalid_server_address |
struct | not_connected_to_server |
struct | user_exit |
Public Member Functions | |
addons_client (CVideo &v, const std::string &address) | |
Constructor. More... | |
~addons_client () | |
void | connect () |
Try to establish a connection to the add-ons server. More... | |
const std::string & | get_last_server_error () const |
Returns the last error message sent by the server, or an empty string. More... | |
bool | request_addons_list (config &cfg) |
Request the add-ons list from the server. More... | |
bool | request_distribution_terms (std::string &terms) |
Request the add-ons server distribution terms message. More... | |
bool | download_addon (config &archive_cfg, const std::string &id, const std::string &title, 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 | upload_addon (const std::string &id, std::string &response_message, config &cfg) |
Requests the specified add-on to be uploaded. 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... | |
Private Member Functions | |
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, bool track_upload=false) |
Waits for a network transfer, displaying a status window. More... | |
bool | update_last_error (config &response_cfg) |
Private Attributes | |
CVideo & | v_ |
std::string | addr_ |
std::string | host_ |
std::string | port_ |
network_asio::connection * | conn_ |
gui2::tnetwork_transmission * | stat_ |
std::string | last_error_ |
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 32 of file client.hpp.
addons_client::addons_client | ( | CVideo & | v, |
const std::string & | address | ||
) |
Constructor.
v | Target for UI rendering for the progress dialog. |
address | Add-ons server host address (i.e. localhost:15999). |
Definition at line 35 of file client.cpp.
References addr_, default_campaignd_port, host_, port_, and utils::split().
addons_client::~addons_client | ( | ) |
Definition at line 337 of file client.cpp.
|
private |
Makes sure the add-ons server connection is working.
Definition at line 273 of file client.cpp.
References conn_, and ERR_ADDONS.
Referenced by send_request(), and wait_for_transfer_done().
void addons_client::connect | ( | ) |
Try to establish a connection to the add-ons server.
Definition at line 57 of file client.cpp.
References addr_, conn_, host_, LOG_ADDONS, port_, vgettext(), and wait_for_transfer_done().
Referenced by ad_hoc_addon_fetch_session().
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 151 of file client.cpp.
References config::add_child(), config::child(), get_addon_pbl_info(), LOG_ADDONS, make_addon_title(), send_request(), update_last_error(), vgettext(), and wait_for_transfer_done().
bool addons_client::download_addon | ( | config & | archive_cfg, |
const std::string & | id, | ||
const std::string & | title, | ||
bool | increase_downloads = true |
||
) |
Downloads the specified add-on from the server.
id | Add-on id. |
title | Add-on title, used for status display. |
archive_cfg | Config object to hold the downloaded add-on archive data. |
increase_downloads | Whether to request the server to increase the add-on's download count or not (e.g. when upgrading). |
Definition at line 184 of file client.cpp.
References config::add_child(), config::clear(), LOG_ADDONS, send_request(), update_last_error(), vgettext(), and wait_for_transfer_done().
|
inline |
Returns the last error message sent by the server, or an empty string.
Definition at line 55 of file client.hpp.
References last_error_.
bool addons_client::install_addon | ( | config & | archive_cfg, |
const addon_info & | info | ||
) |
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 205 of file client.cpp.
References config::add_child(), check_names_legal(), config::find_child(), addon_info::id, LOG_ADDONS, remove_local_addon(), gui2::show_error_message(), addon_info::title, unarchive_addon(), v_, vgettext(), cursor::WAIT, write(), addon_info::write_minimal(), and WRN_ADDONS.
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 70 of file client.cpp.
References _(), config::child(), config::clear(), send_simple_request(), update_last_error(), and wait_for_transfer_done().
bool addons_client::request_distribution_terms | ( | std::string & | terms | ) |
Request the add-ons server distribution terms message.
Definition at line 86 of file client.cpp.
References _(), config::child(), send_simple_request(), update_last_error(), and wait_for_transfer_done().
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 282 of file client.cpp.
References check_connected(), config::clear(), conn_, and network_asio::connection::transfer().
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 290 of file client.cpp.
References config::add_child(), and send_request().
Referenced by request_addons_list(), and request_distribution_terms().
|
private |
Definition at line 261 of file client.cpp.
References config::child(), ERR_ADDONS, error(), and last_error_.
Referenced by 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 | ||
) |
Requests the specified add-on to be uploaded.
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. |
Definition at line 102 of file client.cpp.
References config::add_child(), archive_addon(), config::child(), LOG_ADDONS, make_addon_title(), send_request(), set_addon_pbl_info(), update_last_error(), vgettext(), and wait_for_transfer_done().
|
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 316 of file client.cpp.
References _(), check_connected(), conn_, gui2::tnetwork_transmission::set_connection_data(), gui2::tnetwork_transmission::set_subtitle(), gui2::tdialog::show(), stat_, and v_.
Referenced by connect(), delete_remote_addon(), download_addon(), request_addons_list(), request_distribution_terms(), and upload_addon().
|
private |
Definition at line 138 of file client.hpp.
Referenced by addons_client(), and connect().
|
private |
Definition at line 141 of file client.hpp.
Referenced by check_connected(), connect(), send_request(), wait_for_transfer_done(), and ~addons_client().
|
private |
Definition at line 139 of file client.hpp.
Referenced by addons_client(), and connect().
|
private |
Definition at line 143 of file client.hpp.
Referenced by get_last_server_error(), and update_last_error().
|
private |
Definition at line 140 of file client.hpp.
Referenced by addons_client(), and connect().
|
private |
Definition at line 142 of file client.hpp.
Referenced by wait_for_transfer_done(), and ~addons_client().
|
private |
Definition at line 137 of file client.hpp.
Referenced by install_addon(), and wait_for_transfer_done().