25 #include <boost/asio/basic_waitable_timer.hpp>
31 #include <unordered_map>
32 #include <unordered_set>
42 explicit server(
const std::string& cfg_file,
43 unsigned short port = 0);
58 const std::string&
cmd;
68 boost::asio::yield_context
yield;
84 template<
class Socket>
88 boost::asio::yield_context
yield)
97 friend std::ostream&
operator<<(std::ostream& o,
const request& r);
108 std::unordered_map<std::string, config>
addons_;
125 std::map<std::string, std::string>
hooks_;
140 boost::asio::basic_waitable_timer<std::chrono::steady_clock>
flush_timer_;
145 template<
class Socket>
146 void serve_requests(Socket socket, boost::asio::yield_context yield);
151 void handle_sighup(
const boost::system::error_code& error,
int signal_number);
158 void handle_flush(
const boost::system::error_code& error);
178 void fire(
const std::string& hook,
const std::string& addon);
207 std::string& error_data);
request_handlers_table handlers_
std::map< std::string, request_handler > request_handlers_table
ADDON_CHECK_STATUS validate_addon(const server::request &req, config *&existing_addon, std::string &error_data)
Performs validation on an incoming add-on.
void handle_upload(const request &)
void delete_addon(const std::string &id)
std::set< std::string > capabilities_
config cfg_
Server config.
void handle_request_terms(const request &)
void send_error(const std::string &msg, const any_socket_ptr &sock)
Send a client an error message.
std::string license_notice_
void load_blacklist()
Reads the add-ons upload blacklist from WML.
std::map< std::string, std::string > hooks_
server & operator=(const config &server)=delete
void handle_new_client(socket_ptr socket)
const config & server_info() const
Retrieves the contents of the [server_info] WML node.
std::string blacklist_file_
std::unique_ptr< user_handler > user_handler_
void handle_server_id(const request &)
void handle_delete(const request &)
void write_config()
Writes the server configuration WML back to disk.
void mark_dirty(const std::string &addon)
void send_message(const std::string &msg, const any_socket_ptr &sock)
Send a client an informational message.
optional_config get_addon(const std::string &id)
Retrieves an addon by id if found, or a null config otherwise.
void handle_request_campaign_hash(const request &)
void handle_flush(const boost::system::error_code &error)
std::function< void(server *, const request &req)> request_handler
std::string feedback_url_format_
void flush_cfg()
Starts timer to write config to disk every ten minutes.
friend std::ostream & operator<<(std::ostream &o, const request &r)
std::unordered_map< std::string, config > addons_
The hash map of addons metadata.
server(const config &server)=delete
std::unordered_set< std::string > dirty_addons_
The set of unique addon names with pending metadata updates.
bool ignore_address_stats(const std::string &addr) const
Checks if the specified address should never bump download counts.
static const std::size_t default_document_size_limit
Default upload size limit in bytes.
int compress_level_
Used for add-on archives.
boost::asio::basic_waitable_timer< std::chrono::steady_clock > flush_timer_
void handle_read_from_fifo(const boost::system::error_code &error, std::size_t bytes_transferred)
const std::string cfg_file_
void serve_requests(Socket socket, boost::asio::yield_context yield)
void fire(const std::string &hook, const std::string &addon)
Fires a hook script.
void handle_new_client(tls_socket_ptr socket)
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 ...
void handle_change_passphrase(const request &)
std::vector< std::string > stats_exempt_ips_
void handle_request_campaign(const request &)
void load_config()
Reads the server configuration from WML.
server(const std::string &cfg_file, unsigned short port=0)
std::chrono::seconds update_pack_lifespan_
void handle_sighup(const boost::system::error_code &error, int signal_number)
void register_handlers()
Registers client request handlers.
void handle_request_campaign_list(const request &)
A config object defines a single node in a WML file, with access to child nodes.
const config & child_or_empty(config_key_type key) const
Returns the first child with the given key, or an empty config if there is none.
Base class for implementing servers that use gzipped-WML network protocol.
std::string client_address(const any_socket_ptr &sock)
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
Base class for servers using Wesnoth's WML over TCP protocol.
std::shared_ptr< boost::asio::ssl::stream< socket_ptr::element_type > > tls_socket_ptr
utils::variant< socket_ptr, tls_socket_ptr > any_socket_ptr
std::shared_ptr< boost::asio::ip::tcp::socket > socket_ptr
Client request information object.
request(const std::string &reqcmd, config &reqcfg, Socket reqsock, boost::asio::yield_context yield)
Constructor.
const any_socket_ptr sock
boost::asio::yield_context yield
context of the coroutine the request is executed in async operations on sock can use it instead of a ...