30 #define ERR_ADDONS LOG_STREAM(err , log_addons_client)
31 #define WRN_ADDONS LOG_STREAM(warn, log_addons_client)
32 #define LOG_ADDONS LOG_STREAM(info, log_addons_client)
33 #define DBG_ADDONS LOG_STREAM(debug, log_addons_client)
44 const std::vector<std::string>& address_components =
47 if(address_components.empty()) {
52 host_ = address_components[0];
53 port_ = address_components.size() == 2 ?
62 i18n_symbols[
"server_address"] =
addr_;
67 vgettext(
"Connecting to $server_address|...", i18n_symbols));
81 cfg = response_buf.
child(
"campaigns");
95 if(
const config& msg_cfg = response_buf.
child(
"message")) {
96 terms = msg_cfg[
"message"].str();
104 LOG_ADDONS <<
"preparing to upload " <<
id <<
'\n';
106 response_message.clear();
109 i18n_symbols[
"addon_title"] = cfg[
"title"];
110 if(i18n_symbols[
"addon_title"].empty()) {
117 if(passphrase.empty()) {
118 passphrase.resize(8);
119 for(
size_t n = 0;
n != 8; ++
n) {
120 passphrase[
n] =
'a' + (rand()%26);
122 cfg[
"passphrase"] = passphrase;
125 LOG_ADDONS <<
"automatically generated an initial passphrase for " <<
id <<
'\n';
133 config request_buf, response_buf;
142 if(
const config& message_cfg = response_buf.
child(
"message")) {
143 response_message = message_cfg[
"message"].str();
144 LOG_ADDONS <<
"server response: " << response_message <<
'\n';
153 response_message.clear();
159 i18n_symbols[
"addon_title"] = cfg[
"title"];
160 if(i18n_symbols[
"addon_title"].empty()) {
164 config request_buf, response_buf;
167 request_body[
"name"] =
id;
168 request_body[
"passphrase"] = cfg[
"passphrase"];
170 LOG_ADDONS <<
"requesting server to delete " <<
id <<
'\n';
176 if(
const config& message_cfg = response_buf.
child(
"message")) {
177 response_message = message_cfg[
"message"].str();
178 LOG_ADDONS <<
"server response: " << response_message <<
'\n';
191 request_body[
"name"] =
id;
192 request_body[
"increase_downloads"] = increase_downloads;
195 i18n_symbols[
"addon_title"] = title;
210 i18n_symbols[
"addon_title"] = info.
title;
214 vgettext(
"The add-on <i>$addon_title</i> has an invalid file or directory "
215 "name and cannot be installed.", i18n_symbols));
223 LOG_ADDONS <<
"downloaded add-on '" << info.
id <<
"' is missing its directory in the archive; creating it\n";
225 (*maindir)[
"name"] = info.
id;
228 LOG_ADDONS <<
"generating version info for add-on '" << info.
id <<
"'\n";
230 std::ostringstream info_contents;
235 "# File automatically generated by Wesnoth to keep track\n"
236 "# of version information on installed add-ons. DO NOT EDIT!\n"
240 write(info_contents, wml);
243 file[
"name"] =
"_info.cfg";
244 file[
"contents"] = info_contents.str();
252 WRN_ADDONS <<
"failed to uninstall previous version of " << info.
id <<
"; the add-on may not work properly!" << std::endl;
275 assert(
conn_ !=
nullptr);
276 if(
conn_ ==
nullptr) {
277 ERR_ADDONS <<
"not connected to server" << std::endl;
319 std::unique_ptr<gui2::tnetwork_transmission::connection_data> cd;
write_addon_connection_data(network_asio::connection &conn)
void show_error_message(CVideo &video, const std::string &message, bool message_use_markup)
Shows an error message to the user.
virtual bool finished() override
Dialog that tracks network transmissions.
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.
virtual void poll() override
bool show(CVideo &video, const unsigned auto_close_time=0)
Shows the window.
static l_noret error(LoadState *S, const char *why)
network_asio::connection * conn_
bool update_last_error(config &response_cfg)
addons_client(CVideo &v, const std::string &address)
Constructor.
virtual bool finished() override
bool install_addon(config &archive_cfg, const addon_info &info)
Installs the specified add-on using an archive received from the server.
std::size_t bytes_to_write() const
gui2::tnetwork_transmission * stat_
void write_minimal(config &cfg) const
Write only minimal WML used for state tracking (_info.cfg) files.
void send_request(const config &request, config &response)
Sends a request to the add-ons server.
std::size_t bytes_read() const
static lg::log_domain log_addons_client("addons-client")
virtual size_t current() override
virtual size_t current() override
virtual void poll() override
static UNUSEDNOWARN std::string _(const char *str)
std::map< std::string, t_string > string_map
virtual void cancel() override
void check_connected() const
Makes sure the add-ons server connection is working.
void set_connection_data(connection_data &connection)
void set_addon_pbl_info(const std::string &addon_name, const config &cfg)
config & add_child(const std::string &key)
A class that represents a TCP/IP connection.
network_asio::connection & conn_
std::size_t bytes_to_read() const
bool remove_local_addon(const std::string &addon)
void connect()
Try to establish a connection to the add-ons server.
read_addon_connection_data(network_asio::connection &conn)
GLuint GLuint64EXT address
void transfer(const config &request, config &response)
network_asio::connection & conn_
void wait_for_transfer_done(const std::string &status_message, bool track_upload=false)
Waits for a network transfer, displaying a status window.
void archive_addon(const std::string &addon_name, config &cfg)
Archives an add-on into a config object for campaignd transactions.
bool done() const
True if connected and no high-level operation is in progress.
std::string make_addon_title(const std::string &id)
Replaces underscores to dress up file or dirnames as add-on titles.
void get_addon_pbl_info(const std::string &addon_name, config &cfg)
Gets the publish information for an add-on.
const unsigned short default_campaignd_port
Default port number for the addon server.
void unarchive_addon(const config &cfg)
config & child(const std::string &key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
config & find_child(const std::string &key, const std::string &name, const std::string &value)
Returns the first child of tag key with a name attribute containing value.
bool upload_addon(const std::string &id, std::string &response_message, config &cfg)
Requests the specified add-on to be uploaded.
Standard logging facilities (interface).
void set_subtitle(const std::string &)
std::size_t poll()
Handle all pending asynchonous events and return.
std::vector< std::string > split(std::string const &val, const char c, const int flags)
Splits a (comma-)separated string into a vector of pieces.
bool check_names_legal(const config &dir)
Probes an add-on archive for illegal names.
A config object defines a single node in a WML file, with access to child nodes.
bool delete_remote_addon(const std::string &id, std::string &response_message)
Requests the specified add-on to be removed from the server.
bool request_distribution_terms(std::string &terms)
Request the add-ons server distribution terms message.
virtual void cancel() override
void write(std::ostream &out, configr_of const &cfg, unsigned int level)
std::size_t bytes_written() const
GLsizei const GLcharARB ** string
bool request_addons_list(config &cfg)
Request the add-ons list from the server.
void send_simple_request(const std::string &request_string, config &response)
Sends a simple request message to the add-ons server.