Legacy add-ons server. More...
#include <campaign_server.hpp>
Classes | |
struct | request |
Client request information object. More... | |
Public Member Functions | |
server (const std::string &cfg_file, size_t min_threads=10, size_t max_threads=0) | |
~server () | |
void | run () |
Runs the server request processing loop. More... | |
Private Types | |
typedef std::function< void(server *, const request &req)> | request_handler |
typedef std::map< std::string, request_handler > | request_handlers_table |
Private Member Functions | |
int | load_config () |
Reads the server configuration from WML. More... | |
void | write_config () |
Writes the server configuration WML back to disk. More... | |
void | load_blacklist () |
Reads the add-ons upload blacklist from WML. More... | |
void | fire (const std::string &hook, const std::string &addon) |
Fires a hook script. More... | |
const config & | campaigns () const |
Retrieves the contents of the [campaigns] WML node. More... | |
config & | campaigns () |
Retrieves the contents of the [campaigns] WML node. More... | |
config & | get_campaign (const std::string &id) |
Retrieves a campaign by id if found, or a null config otherwise. More... | |
const config & | server_info () const |
Retrieves the contents of the [server_info] WML node. More... | |
config & | server_info () |
Retrieves the contents of the [server_info] WML node. More... | |
void | register_handlers () |
Registers client request handlers. More... | |
void | register_handler (const std::string &cmd, const request_handler &func) |
Registers a single request handler. More... | |
void | handle_request_campaign_list (const request &) |
void | handle_request_campaign (const request &) |
void | handle_request_terms (const request &) |
void | handle_upload (const request &) |
void | handle_delete (const request &) |
void | handle_change_passphrase (const request &) |
void | send_message (const std::string &msg, network::connection sock) |
Send a client an informational message. More... | |
void | send_error (const std::string &msg, network::connection sock) |
Send a client an error message. More... | |
Private Attributes | |
config | cfg_ |
const std::string | cfg_file_ |
bool | read_only_ |
int | compress_level_ |
Used for add-on archives. More... | |
boost::scoped_ptr< input_stream > | input_ |
Server control socket. More... | |
std::map< std::string, std::string > | hooks_ |
request_handlers_table | handlers_ |
std::string | feedback_url_format_ |
blacklist | blacklist_ |
std::string | blacklist_file_ |
int | port_ |
const network::manager | net_manager_ |
const network::server_manager | server_manager_ |
Legacy add-ons server.
Definition at line 31 of file campaign_server.hpp.
|
private |
Definition at line 81 of file campaign_server.hpp.
|
private |
Definition at line 82 of file campaign_server.hpp.
|
explicit |
Definition at line 139 of file campaign_server.cpp.
References campaigns(), LOG_CS, port_, read_only_, register_handlers(), SIGHUP, and write_config().
campaignd::server::~server | ( | ) |
Definition at line 181 of file campaign_server.cpp.
References write_config().
|
inlineprivate |
Retrieves the contents of the [campaigns] WML node.
Definition at line 128 of file campaign_server.hpp.
References config::child().
Referenced by get_campaign(), handle_delete(), handle_request_campaign_list(), handle_upload(), and server().
|
inlineprivate |
Retrieves the contents of the [campaigns] WML node.
Definition at line 131 of file campaign_server.hpp.
References config::child().
|
private |
Fires a hook script.
Definition at line 271 of file campaign_server.cpp.
References ERR_CS, hooks_, and itor.
Referenced by handle_delete(), and handle_upload().
|
inlineprivate |
Retrieves a campaign by id if found, or a null config otherwise.
Definition at line 134 of file campaign_server.hpp.
References campaigns(), and config::find_child().
Referenced by handle_change_passphrase(), handle_delete(), handle_request_campaign(), and run().
Definition at line 846 of file campaign_server.cpp.
References campaignd::server::request::cfg, get_campaign(), LOG_CS, read_only_, send_error(), send_message(), campaignd::server::request::sock, and write_config().
Definition at line 794 of file campaign_server.cpp.
References campaignd::server::request::addr, campaigns(), campaignd::server::request::cfg, config::child_range(), preferences::erase(), ERR_CS, fire(), get_campaign(), LOG_CS, read_only_, config::remove_child(), send_error(), send_message(), campaignd::server::request::sock, write_config(), and filesystem::write_file().
Definition at line 576 of file campaign_server.cpp.
References campaignd::server::request::addr, campaignd::server::request::cfg, ERR_CS, filesystem::file_size(), get_campaign(), LOG_CS, send_error(), network::send_file(), and campaignd::server::request::sock.
Definition at line 487 of file campaign_server.cpp.
References config::add_child(), campaignd::server::request::addr, campaigns(), campaignd::server::request::cfg, config::child_or_empty(), config::child_range(), config::empty(), feedback_url_format_, campaignd::format_addon_feedback_url(), i, lexical_cast(), LOG_CS, network::send_data(), and campaignd::server::request::sock.
Definition at line 606 of file campaign_server.cpp.
References campaignd::server::request::addr, LOG_CS, read_only_, send_error(), send_message(), and campaignd::server::request::sock.
Definition at line 621 of file campaign_server.cpp.
References config::add_child(), campaignd::add_license(), addon_name_legal(), ADDON_UNKNOWN, campaignd::server::request::addr, blacklist_, c, campaigns(), campaignd::server::request::cfg, check_names_legal(), config::child(), config::clear_children(), compress_level_, filesystem::file_size(), campaignd::find_translations(), fire(), get_addon_type(), campaignd::blacklist::is_blacklisted(), campaignd::is_text_markup_char(), LOG_CS, utf8::lowercase(), filesystem::ostream_file(), read_only_, send_error(), send_message(), campaignd::server::request::sock, config_writer::write(), write_config(), and writer().
|
private |
Reads the add-ons upload blacklist from WML.
Definition at line 240 of file campaign_server.cpp.
References blacklist_, blacklist_file_, campaignd::blacklist::clear(), ERR_CS, filesystem::istream_file(), LOG_CS, campaignd::blacklist::read(), and read().
Referenced by load_config(), and run().
|
private |
Reads the server configuration from WML.
Definition at line 186 of file campaign_server.cpp.
References blacklist_file_, cfg_, cfg_file_, config::child_or_add(), compress_level_, default_campaignd_port, feedback_url_format_, hooks_, input_, filesystem::istream_file(), load_blacklist(), LOG_CS, read(), read_only_, server_info(), and network_worker_pool::set_use_system_sendfile().
Referenced by run().
|
private |
Registers a single request handler.
cmd | The request command, corresponding to the name of the [tag} with the request body (e.g. "handle_request_terms"). |
func | The request function. This should be a class method passed as a std::bind function object that takes a single parameter of type request. |
Definition at line 469 of file campaign_server.cpp.
References handlers_.
|
private |
Registers client request handlers.
This is called by the class constructor. Individual handlers must be methods of this class that take a single parameter of type request and they are registered using the register_handler method.
When adding new handlers, make sure to update the implementation of this method accordingly so they are recognized and invoked at runtime.
Definition at line 477 of file campaign_server.cpp.
References REGISTER_CAMPAIGND_HANDLER.
Referenced by server().
void campaignd::server::run | ( | ) |
Runs the server request processing loop.
Definition at line 327 of file campaign_server.cpp.
References network::accept_connection(), campaignd::control_line::args_count(), config::any_child::cfg, cfg_, network::error::disconnect(), network::disconnect(), e, ERR_CS, campaignd::control_line::full(), get_campaign(), handlers_, i, input_, network::ip_address(), config::any_child::key, load_blacklist(), load_config(), LOG_CS, game::error::message, network::null_connection, config::ordered_begin(), config::ordered_end(), network::process_send_queue(), read_only_, network::receive_data(), send_error(), network::error::socket, utils::string_bool(), game::error::what(), and write_config().
Referenced by main().
|
private |
Send a client an error message.
The WML sent consists of a document containing a single [error] child with a message attribute holding the value of msg. In addition to sending the error to the client, a line with the client IP and message is recorded to the server log.
Definition at line 319 of file campaign_server.cpp.
References config::add_child(), ERR_CS, network::ip_address(), game_logic::msg(), and network::send_data().
Referenced by handle_change_passphrase(), handle_delete(), handle_request_campaign(), handle_request_terms(), handle_upload(), and run().
|
private |
Send a client an informational message.
The WML sent consists of a document containing a single [message] child with a message attribute holding the value of msg.
Definition at line 312 of file campaign_server.cpp.
References config::add_child(), game_logic::msg(), and network::send_data().
Referenced by handle_change_passphrase(), handle_delete(), handle_request_terms(), and handle_upload().
|
inlineprivate |
Retrieves the contents of the [server_info] WML node.
Definition at line 137 of file campaign_server.hpp.
References config::child().
Referenced by load_config().
|
inlineprivate |
Retrieves the contents of the [server_info] WML node.
Definition at line 140 of file campaign_server.hpp.
References config::child().
|
private |
Writes the server configuration WML back to disk.
Definition at line 263 of file campaign_server.cpp.
References cfg_, cfg_file_, DBG_CS, filesystem::ostream_file(), and write().
Referenced by handle_change_passphrase(), handle_delete(), handle_upload(), run(), server(), and ~server().
|
private |
Definition at line 97 of file campaign_server.hpp.
Referenced by handle_upload(), and load_blacklist().
|
private |
Definition at line 98 of file campaign_server.hpp.
Referenced by load_blacklist(), and load_config().
|
private |
Definition at line 84 of file campaign_server.hpp.
Referenced by load_config(), run(), and write_config().
|
private |
Definition at line 85 of file campaign_server.hpp.
Referenced by load_config(), and write_config().
|
private |
Used for add-on archives.
Definition at line 88 of file campaign_server.hpp.
Referenced by handle_upload(), and load_config().
|
private |
Definition at line 95 of file campaign_server.hpp.
Referenced by handle_request_campaign_list(), and load_config().
|
private |
Definition at line 93 of file campaign_server.hpp.
Referenced by register_handler(), and run().
|
private |
Definition at line 92 of file campaign_server.hpp.
Referenced by fire(), and load_config().
|
private |
Server control socket.
Definition at line 90 of file campaign_server.hpp.
Referenced by load_config(), and run().
|
private |
Definition at line 102 of file campaign_server.hpp.
|
private |
Definition at line 100 of file campaign_server.hpp.
Referenced by server().
|
private |
Definition at line 87 of file campaign_server.hpp.
Referenced by handle_change_passphrase(), handle_delete(), handle_request_terms(), handle_upload(), load_config(), run(), and server().
|
private |
Definition at line 103 of file campaign_server.hpp.