24 #include <boost/asio/basic_waitable_timer.hpp> 30 #include <unordered_map> 31 #include <unordered_set> 41 explicit server(
const std::string& cfg_file,
42 unsigned short port = 0);
57 const std::string&
cmd;
67 boost::asio::yield_context
yield;
86 boost::asio::yield_context yield)
106 std::unordered_map<std::string, config>
addons_;
123 std::map<std::string, std::string>
hooks_;
138 boost::asio::basic_waitable_timer<std::chrono::steady_clock>
flush_timer_;
172 void fire(
const std::string& hook,
const std::string& addon);
181 dirty_addons_.emplace(addon);
201 std::string& error_data);
265 void send_error(
const std::string& msg,
const std::string& extra_data,
unsigned int status_code,
socket_ptr sock);
time_t update_pack_lifespan_
std::string feedback_url_format_
bool ignore_address_stats(const std::string &addr) const
Checks if the specified address should never bump download counts.
request(const std::string &reqcmd, config &reqcfg, socket_ptr reqsock, boost::asio::yield_context yield)
Constructor.
config & child(config_key_type key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
void handle_request_terms(const request &)
static const std::size_t default_document_size_limit
Default upload size limit in bytes.
void handle_flush(const boost::system::error_code &error)
config & get_addon(const std::string &id)
Retrieves an addon by id if found, or a null config otherwise.
std::unordered_set< std::string > dirty_addons_
The set of unique addon names with pending metadata updates.
static l_noret error(LoadState *S, const char *why)
void handle_delete(const request &)
Client request information object.
void load_config()
Reads the server configuration from WML.
server & operator=(const config &server)=delete
void fire(const std::string &hook, const std::string &addon)
Fires a hook script.
void handle_request_campaign_hash(const request &)
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
request_handlers_table handlers_
std::map< std::string, std::string > hooks_
void load_blacklist()
Reads the add-ons upload blacklist from WML.
void register_handlers()
Registers client request handlers.
const std::string cfg_file_
std::map< std::string, request_handler > request_handlers_table
void handle_sighup(const boost::system::error_code &error, int signal_number)
boost::asio::basic_waitable_timer< std::chrono::steady_clock > flush_timer_
std::string blacklist_file_
void handle_read_from_fifo(const boost::system::error_code &error, std::size_t bytes_transferred)
void delete_addon(const std::string &id)
void handle_change_passphrase(const request &)
boost::asio::yield_context yield
context of the coroutine the request is executed in async operations on sock can use it instead of a ...
void write_config()
Writes the server configuration WML back to disk.
config & server_info()
Retrieves the contents of the [server_info] WML node.
void handle_new_client(socket_ptr socket)
const config & server_info() const
Retrieves the contents of the [server_info] WML node.
void handle_request_campaign(const request &)
std::string client_address(const socket_ptr socket)
void handle_server_id(const request &)
std::vector< std::string > stats_exempt_ips_
friend std::ostream & operator<<(std::ostream &o, const request &r)
void handle_request_campaign_list(const request &)
std::function< void(server *, const request &req)> request_handler
ADDON_CHECK_STATUS validate_addon(const server::request &req, config *&existing_addon, std::string &error_data)
Performs validation on an incoming add-on.
void flush_cfg()
Starts timer to write config to disk every ten minutes.
std::shared_ptr< boost::asio::ip::tcp::socket > socket_ptr
config cfg_
Server config.
std::unordered_map< std::string, config > addons_
The hash map of addons metadata.
std::set< std::string > capabilities_
A config object defines a single node in a WML file, with access to child nodes.
void send_message(const std::string &msg, socket_ptr sock)
Send a client an informational message.
server(const std::string &cfg_file, unsigned short port=0)
void send_error(const std::string &msg, socket_ptr sock)
Send a client an error message.
void handle_upload(const request &)
void mark_dirty(const std::string &addon)
Base class for servers using Wesnoth's WML over TCP protocol.
std::string license_notice_
std::unique_ptr< user_handler > user_handler_
int compress_level_
Used for add-on archives.