Legacy add-ons server. More...
#include <server.hpp>
Classes | |
struct | request |
Client request information object. More... | |
Public Member Functions | |
server (const std::string &cfg_file, unsigned short port=0) | |
server (const config &server)=delete | |
~server () | |
server & | operator= (const config &server)=delete |
Public Member Functions inherited from server_base | |
server_base (unsigned short port, bool keep_alive) | |
virtual | ~server_base () |
int | run () |
template<class SocketPtr > | |
void | coro_send_doc (SocketPtr socket, simple_wml::document &doc, boost::asio::yield_context yield) |
Send a WML document from within a coroutine. More... | |
void | coro_send_file (socket_ptr socket, const std::string &filename, boost::asio::yield_context yield) |
Send contents of entire file directly to socket from within a coroutine. More... | |
void | coro_send_file (tls_socket_ptr socket, const std::string &filename, boost::asio::yield_context yield) |
template<class SocketPtr > | |
std::unique_ptr< simple_wml::document > | coro_receive_doc (SocketPtr socket, boost::asio::yield_context yield) |
Receive WML document from a coroutine. More... | |
template<class SocketPtr > | |
void | async_send_doc_queued (SocketPtr socket, simple_wml::document &doc) |
High level wrapper for sending a WML document. More... | |
template<class SocketPtr > | |
void | async_send_error (SocketPtr socket, const std::string &msg, const char *error_code="", const info_table &info={}) |
template<class SocketPtr > | |
void | async_send_warning (SocketPtr socket, const std::string &msg, const char *warning_code="", const info_table &info={}) |
std::string | create_unsecure_nonce (int length=8) |
Create the poor security nonce for use with passwords still hashed with MD5. More... | |
std::string | create_secure_nonce () |
Create a good security nonce for use with bcrypt/crypt_blowfish hashing. More... | |
std::string | hash_password (const std::string &pw, const std::string &salt, const std::string &username) |
Handles hashing the password provided by the player before comparing it to the hashed password in the forum database. 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 | |
void | handle_new_client (socket_ptr socket) |
void | handle_new_client (tls_socket_ptr socket) |
template<class Socket > | |
void | serve_requests (Socket socket, boost::asio::yield_context yield) |
void | handle_read_from_fifo (const boost::system::error_code &error, std::size_t bytes_transferred) |
void | handle_sighup (const boost::system::error_code &error, int signal_number) |
void | flush_cfg () |
Starts timer to write config to disk every ten minutes. More... | |
void | handle_flush (const boost::system::error_code &error) |
void | 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... | |
optional_config | get_addon (const std::string &id) |
Retrieves an addon by id if found, or a null config otherwise. More... | |
void | delete_addon (const std::string &id) |
void | mark_dirty (const std::string &addon) |
ADDON_CHECK_STATUS | validate_addon (const server::request &req, config *&existing_addon, std::string &error_data) |
Performs validation on an incoming add-on. More... | |
const config & | server_info () const |
Retrieves the contents of the [server_info] WML node. More... | |
bool | ignore_address_stats (const std::string &addr) const |
Checks if the specified address should never bump download counts. More... | |
void | register_handlers () |
Registers client request handlers. More... | |
void | handle_server_id (const request &) |
void | handle_request_campaign_list (const request &) |
void | handle_request_campaign (const request &) |
void | handle_request_campaign_hash (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, const any_socket_ptr &sock) |
Send a client an informational message. More... | |
void | send_error (const std::string &msg, const any_socket_ptr &sock) |
Send a client an error message. More... | |
void | send_error (const std::string &msg, const std::string &extra_data, unsigned int status_code, const any_socket_ptr &sock) |
Send a client an error message. More... | |
bool | authenticate_forum (const config &addon, const std::string &passphrase, bool is_delete) |
Check whether the provided passphrase matches the add-on and its author by checked against the forum database. More... | |
Private Attributes | |
std::unique_ptr< user_handler > | user_handler_ |
std::set< std::string > | capabilities_ |
std::unordered_map< std::string, config > | addons_ |
The hash map of addons metadata. More... | |
std::unordered_set< std::string > | dirty_addons_ |
The set of unique addon names with pending metadata updates. More... | |
config | cfg_ |
Server config. More... | |
const std::string | cfg_file_ |
bool | read_only_ |
int | compress_level_ |
Used for add-on archives. More... | |
std::chrono::seconds | update_pack_lifespan_ |
bool | strict_versions_ |
std::map< std::string, std::string > | hooks_ |
request_handlers_table | handlers_ |
std::string | server_id_ |
std::string | feedback_url_format_ |
std::string | web_url_ |
std::string | license_notice_ |
blacklist | blacklist_ |
std::string | blacklist_file_ |
std::vector< std::string > | stats_exempt_ips_ |
boost::asio::basic_waitable_timer< std::chrono::steady_clock > | flush_timer_ |
Static Private Attributes | |
static const std::size_t | default_document_size_limit = 100 * 1024 * 1024 |
Default upload size limit in bytes. More... | |
Friends | |
std::ostream & | operator<< (std::ostream &o, const request &r) |
Additional Inherited Members | |
Public Types inherited from server_base | |
typedef std::map< std::string, std::string > | info_table |
Protected Member Functions inherited from server_base | |
void | load_tls_config (const config &cfg) |
void | start_server () |
void | serve (boost::asio::yield_context yield, boost::asio::ip::tcp::acceptor &acceptor, boost::asio::ip::tcp::endpoint endpoint) |
virtual bool | accepting_connections () const |
virtual std::string | is_ip_banned (const std::string &) |
virtual bool | ip_exceeds_connection_limit (const std::string &) const |
void | read_from_fifo () |
Protected Attributes inherited from server_base | |
unsigned short | port_ |
bool | keep_alive_ |
boost::asio::io_service | io_service_ |
boost::asio::ssl::context | tls_context_ { boost::asio::ssl::context::sslv23 } |
bool | tls_enabled_ { false } |
boost::asio::ip::tcp::acceptor | acceptor_v6_ |
boost::asio::ip::tcp::acceptor | acceptor_v4_ |
uint32_t | handshake_response_ |
boost::asio::posix::stream_descriptor | input_ |
std::string | fifo_path_ |
boost::asio::streambuf | admin_cmd_ |
boost::asio::signal_set | sighup_ |
Legacy add-ons server.
Definition at line 39 of file server.hpp.
|
private |
Definition at line 102 of file server.hpp.
|
private |
Definition at line 103 of file server.hpp.
|
explicit |
Definition at line 276 of file server.cpp.
References addons_, flush_cfg(), load_config(), LOG_CS, game_config::path, server_base::port_, register_handlers(), and server_base::start_server().
|
delete |
campaignd::server::~server | ( | ) |
Definition at line 325 of file server.cpp.
References write_config().
|
private |
Check whether the provided passphrase matches the add-on and its author by checked against the forum database.
addon | The add-on uploaded, which contains the username to use. |
passphrase | The passphrase to use for authentication. |
is_delete | Whether the authentication is being requested for an add-on upload or an add-on deletion. |
Definition at line 1932 of file server.cpp.
References server_base::hash_password(), server_id_, and user_handler_.
Referenced by handle_delete(), and validate_addon().
|
private |
Definition at line 900 of file server.cpp.
References addons_, filesystem::delete_directory(), ERR_CS, fire(), get_addon(), LOG_CS, server_id_, user_handler_, and write_config().
Referenced by handle_delete(), and handle_read_from_fifo().
|
private |
Fires a hook script.
Definition at line 797 of file server.cpp.
References ERR_CS, hooks_, and PLAIN_LOG.
Referenced by delete_addon(), and handle_upload().
|
private |
Starts timer to write config to disk every ten minutes.
Definition at line 738 of file server.cpp.
References flush_timer_, and handle_flush().
Referenced by handle_flush(), and server().
|
private |
Retrieves an addon by id if found, or a null config otherwise.
Definition at line 890 of file server.cpp.
References addons_.
Referenced by delete_addon(), handle_change_passphrase(), handle_delete(), handle_read_from_fifo(), handle_request_campaign(), handle_request_campaign_hash(), load_config(), and write_config().
|
private |
Definition at line 1901 of file server.cpp.
References campaignd::server::request::cfg, dirty_addons_, get_addon(), LOG_CS, read_only_, send_error(), send_message(), campaignd::server::request::sock, and write_config().
|
private |
Definition at line 1850 of file server.cpp.
References authenticate_forum(), campaignd::server::request::cfg, delete_addon(), config_attribute_value::empty(), utf8::erase(), get_addon(), LOG_CS, PLAIN_LOG, read_only_, send_error(), send_message(), and campaignd::server::request::sock.
|
private |
Definition at line 744 of file server.cpp.
References ERR_CS, flush_cfg(), and write_config().
Referenced by flush_cfg().
|
privatevirtual |
Implements server_base.
Definition at line 491 of file server.cpp.
References e, server_base::io_service_, and serve_requests().
|
privatevirtual |
Implements server_base.
|
privatevirtual |
Implements server_base.
Definition at line 547 of file server.cpp.
References server_base::admin_cmd_, campaignd::control_line::args_count(), cfg_, campaignd::control_line::cmd(), lg::debug(), delete_addon(), lg::err(), ERR_CS, campaignd::control_line::full(), get_addon(), lg::logger::get_severity(), i, lg::info(), lg::LG_NONE, load_blacklist(), load_config(), LOG_CS, mark_dirty(), lg::precise_timestamps(), server_base::read_from_fifo(), read_only_, lg::set_log_domain_severity(), utils::split(), utils::string_bool(), lg::warn(), and write_config().
|
private |
Definition at line 1075 of file server.cpp.
References campaignd::server::request::addr, config::append(), campaignd::server::request::cfg, config::child_range(), simple_wml::document::compress(), server_base::coro_send_doc(), server_base::coro_send_file(), config::empty(), ERR_CS, filesystem::file_size(), get_addon(), campaignd::get_version_map(), ignore_address_stats(), in, simple_wml::INIT_STATIC, filesystem::istream_file(), LOG_CS, mark_dirty(), read_gz(), send_error(), server_id_, campaignd::server::request::sock, user_handler_, write(), and campaignd::server::request::yield.
|
private |
Definition at line 1219 of file server.cpp.
References campaignd::server::request::cfg, server_base::coro_send_file(), filesystem::file_size(), get_addon(), campaignd::get_version_map(), LOG_CS, game_config::path, send_error(), campaignd::server::request::sock, and campaignd::server::request::yield.
|
private |
Definition at line 968 of file server.cpp.
References config::add_child(), addons_, server_base::async_send_doc_queued(), campaignd::server::request::cfg, config::child_or_empty(), config::child_range(), simple_wml::document::compress(), config::empty(), feedback_url_format_, campaignd::format_addon_feedback_url(), i, simple_wml::INIT_STATIC, LOG_CS, chrono::parse_timestamp(), chrono::serialize_timestamp(), campaignd::server::request::sock, and write().
|
private |
Definition at line 1265 of file server.cpp.
References license_notice_, LOG_CS, read_only_, send_error(), send_message(), and campaignd::server::request::sock.
|
private |
Definition at line 948 of file server.cpp.
References server_base::async_send_doc_queued(), capabilities_, simple_wml::document::compress(), DBG_CS, simple_wml::INIT_STATIC, utils::join(), license_notice_, game_config::revision, server_id_, campaignd::server::request::sock, web_url_, and write().
|
privatevirtual |
Implements server_base.
Definition at line 725 of file server.cpp.
References load_config(), LOG_CS, and server_base::sighup_.
|
private |
Definition at line 1482 of file server.cpp.
References config::add_child(), campaignd::add_license(), addon_check_status_desc(), addons_, campaignd::server::request::addr, campaignd::server::request::cfg, config::child_range(), config::clear(), config::clear_children(), compress_level_, config::copy_or_remove_attributes(), campaignd::data_apply_addlist(), campaignd::data_apply_removelist(), filesystem::delete_file(), ERR_CS, filesystem::file_size(), campaignd::find_translations(), fire(), campaignd::get_version_map(), in, filesystem::istream_file(), LOG_CS, make_updatepack(), mark_dirty(), wfl::msg(), config::optional_child(), p, chrono::parse_timestamp(), read_gz(), config::remove_children(), send_error(), send_message(), chrono::serialize_timestamp(), SERVER_DELTA_NO_VERSIONS, server_id_, SERVER_UNSPECIFIED, campaignd::server::request::sock, utils::split(), version_info::str(), SUCCESS, update_pack_lifespan_, user_handler_, validate_addon(), write_config(), and write_hashlist().
|
private |
Checks if the specified address should never bump download counts.
Definition at line 836 of file server.cpp.
References stats_exempt_ips_, and utils::wildcard_string_match().
Referenced by handle_request_campaign().
|
private |
Reads the add-ons upload blacklist from WML.
Definition at line 754 of file server.cpp.
References blacklist_, blacklist_file_, campaignd::blacklist::clear(), ERR_CS, in, filesystem::istream_file(), LOG_CS, read(), and campaignd::blacklist::read().
Referenced by handle_read_from_fifo(), and load_config().
|
private |
Reads the server configuration from WML.
Definition at line 330 of file server.cpp.
References addons_, blacklist_file_, cfg_, cfg_file_, config::child_count(), config::child_range(), config::clear_children(), filesystem::atomic_commit::commit(), compress_level_, data, default_campaignd_port, default_document_size_limit, filesystem::delete_file(), simple_wml::document::document_size_limit, config::empty(), ERR_CS, feedback_url_format_, server_base::fifo_path_, get_addon(), filesystem::get_files_in_dir(), config::has_child(), hooks_, in, server_base::input_, filesystem::istream_file(), license_notice_, load_blacklist(), server_base::load_tls_config(), LOG_CS, config::mandatory_child(), mark_dirty(), filesystem::normalize_path(), config::optional_child(), filesystem::atomic_commit::ostream(), chrono::parse_duration(), game_config::path, server_base::port_, read(), server_base::read_from_fifo(), read_gz(), read_only_, server_id_, server_info(), utils::split(), stats_exempt_ips_, strict_versions_, update_pack_lifespan_, user_handler_, web_url_, config_writer::write(), write_config(), write_hashlist(), and WRN_CS.
Referenced by handle_read_from_fifo(), handle_sighup(), and server().
|
inlineprivate |
Definition at line 185 of file server.hpp.
References dirty_addons_.
Referenced by handle_read_from_fifo(), handle_request_campaign(), handle_upload(), and load_config().
|
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 936 of file server.cpp.
References REGISTER_CAMPAIGND_HANDLER.
Referenced by server().
|
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 860 of file server.cpp.
References simple_wml::node::add_child(), server_base::async_send_doc_queued(), campaignd::client_address(), ERR_CS, wfl::msg(), simple_wml::document::root(), and simple_wml::node::set_attr_dup().
Referenced by handle_change_passphrase(), handle_delete(), handle_request_campaign(), handle_request_campaign_hash(), handle_request_terms(), handle_upload(), and serve_requests().
|
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, an extra_data attribute holding the value of extra_data, and a status_code attribute holding the value of status_code. 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 869 of file server.cpp.
References simple_wml::node::add_child(), server_base::async_send_doc_queued(), campaignd::client_address(), ERR_CS, wfl::msg(), simple_wml::document::root(), and simple_wml::node::set_attr_dup().
|
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 848 of file server.cpp.
References simple_wml::node::add_child(), server_base::async_send_doc_queued(), wfl::msg(), simple_wml::document::root(), and simple_wml::node::set_attr_dup().
Referenced by handle_change_passphrase(), handle_delete(), handle_request_terms(), and handle_upload().
|
private |
Definition at line 512 of file server.cpp.
References c, server_base::coro_receive_doc(), data, handlers_, i, read(), and send_error().
Referenced by handle_new_client().
|
inlineprivate |
Retrieves the contents of the [server_info] WML node.
Definition at line 210 of file server.hpp.
References cfg_, and config::child_or_empty().
Referenced by load_config().
|
private |
Performs validation on an incoming add-on.
req | Server request info, containing either a full WML pack, or a delta update pack. |
existing_addon | Used to store a pointer to the existing add-on WML on the server if the add-on already exists. nullptr is stored otherwise. |
error_data | Used to store extra error data for status codes other than ADDON_CHECK_STATUS::SUCCESS. Cleared otherwise. |
Definition at line 1279 of file server.cpp.
References addon_name_legal(), ADDON_UNKNOWN, addons_, campaignd::server::request::addr, AUTH_TYPE_MISMATCH, authenticate_forum(), BAD_FEEDBACK_TOPIC_ID, BAD_NAME, BAD_TYPE, blacklist_, c, campaignd::server::request::cfg, config::clear(), data, DENIED, EMPTY_PACK, ERR_CS, FEEDBACK_TOPIC_ID_NOT_FOUND, FILENAME_CASE_CONFLICT, get_addon_type(), ILLEGAL_FILENAME, INVALID_UTF8_ATTRIBUTE, INVALID_UTF8_NAME, campaignd::blacklist::is_blacklisted(), campaignd::is_text_markup_char(), utils::join(), LOG_CS, utf8::lowercase(), NAME_HAS_MARKUP, NO_AUTHOR, NO_DESCRIPTION, NO_EMAIL, NO_PASSPHRASE, NO_TITLE, NO_VERSION, config::optional_child(), read_only_, SERVER_ADDONS_LIST, SERVER_FORUM_AUTH_DISABLED, SERVER_READ_ONLY, utils::split(), version_info::str(), strict_versions_, SUCCESS, TITLE_HAS_MARKUP, UNAUTHORIZED, UNEXPECTED_DELTA, USER_DOES_NOT_EXIST, user_handler_, and VERSION_NOT_INCREMENTED.
Referenced by handle_upload().
|
private |
Writes the server configuration WML back to disk.
Definition at line 777 of file server.cpp.
References cfg_, cfg_file_, filesystem::atomic_commit::commit(), DBG_CS, dirty_addons_, get_addon(), filesystem::normalize_path(), filesystem::atomic_commit::ostream(), and write().
Referenced by delete_addon(), handle_change_passphrase(), handle_flush(), handle_read_from_fifo(), handle_upload(), load_config(), and ~server().
|
friend |
Definition at line 485 of file server.cpp.
|
private |
The hash map of addons metadata.
Definition at line 108 of file server.hpp.
Referenced by delete_addon(), get_addon(), handle_request_campaign_list(), handle_upload(), load_config(), server(), and validate_addon().
|
private |
Definition at line 135 of file server.hpp.
Referenced by load_blacklist(), and validate_addon().
|
private |
Definition at line 136 of file server.hpp.
Referenced by load_blacklist(), and load_config().
|
private |
Definition at line 105 of file server.hpp.
Referenced by handle_server_id().
|
private |
Server config.
Definition at line 113 of file server.hpp.
Referenced by handle_read_from_fifo(), load_config(), server_info(), and write_config().
|
private |
Definition at line 114 of file server.hpp.
Referenced by load_config(), and write_config().
|
private |
Used for add-on archives.
Definition at line 117 of file server.hpp.
Referenced by handle_upload(), and load_config().
|
staticprivate |
Default upload size limit in bytes.
Definition at line 123 of file server.hpp.
Referenced by load_config().
|
private |
The set of unique addon names with pending metadata updates.
Definition at line 110 of file server.hpp.
Referenced by handle_change_passphrase(), mark_dirty(), and write_config().
|
private |
Definition at line 130 of file server.hpp.
Referenced by handle_request_campaign_list(), and load_config().
|
private |
Definition at line 140 of file server.hpp.
Referenced by flush_cfg().
|
private |
Definition at line 126 of file server.hpp.
Referenced by serve_requests().
|
private |
Definition at line 125 of file server.hpp.
Referenced by fire(), and load_config().
|
private |
Definition at line 133 of file server.hpp.
Referenced by handle_request_terms(), handle_server_id(), and load_config().
|
private |
Definition at line 116 of file server.hpp.
Referenced by handle_change_passphrase(), handle_delete(), handle_read_from_fifo(), handle_request_terms(), load_config(), and validate_addon().
|
private |
Definition at line 128 of file server.hpp.
Referenced by authenticate_forum(), delete_addon(), handle_request_campaign(), handle_server_id(), handle_upload(), and load_config().
|
private |
Definition at line 138 of file server.hpp.
Referenced by ignore_address_stats(), and load_config().
|
private |
Definition at line 120 of file server.hpp.
Referenced by load_config(), and validate_addon().
|
private |
Definition at line 118 of file server.hpp.
Referenced by handle_upload(), and load_config().
|
private |
Definition at line 101 of file server.hpp.
Referenced by authenticate_forum(), delete_addon(), handle_request_campaign(), handle_upload(), load_config(), and validate_addon().
|
private |
Definition at line 132 of file server.hpp.
Referenced by handle_server_id(), and load_config().