The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
campaignd::server Class Reference

Legacy add-ons server. More...

#include <campaign_server.hpp>

Inheritance diagram for campaignd::server:
Inheritance graph

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 configcampaigns () const
 Retrieves the contents of the [campaigns] WML node. More...
 
configcampaigns ()
 Retrieves the contents of the [campaigns] WML node. More...
 
configget_campaign (const std::string &id)
 Retrieves a campaign by id if found, or a null config otherwise. More...
 
const configserver_info () const
 Retrieves the contents of the [server_info] WML node. More...
 
configserver_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_streaminput_
 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_
 

Detailed Description

Legacy add-ons server.

Definition at line 31 of file campaign_server.hpp.

Member Typedef Documentation

typedef std::function<void (server*, const request& req)> campaignd::server::request_handler
private

Definition at line 81 of file campaign_server.hpp.

Definition at line 82 of file campaign_server.hpp.

Constructor & Destructor Documentation

campaignd::server::server ( const std::string cfg_file,
size_t  min_threads = 10,
size_t  max_threads = 0 
)
explicit
campaignd::server::~server ( )

Definition at line 181 of file campaign_server.cpp.

References write_config().

Member Function Documentation

const config& campaignd::server::campaigns ( ) const
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().

config& campaignd::server::campaigns ( )
inlineprivate

Retrieves the contents of the [campaigns] WML node.

Definition at line 131 of file campaign_server.hpp.

References config::child().

void campaignd::server::fire ( const std::string hook,
const std::string addon 
)
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().

config& campaignd::server::get_campaign ( const std::string id)
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().

void campaignd::server::handle_change_passphrase ( const request req)
private
void campaignd::server::handle_delete ( const request req)
private
void campaignd::server::handle_request_campaign ( const request req)
private
void campaignd::server::handle_request_campaign_list ( const request req)
private
void campaignd::server::handle_request_terms ( const request req)
private
void campaignd::server::handle_upload ( const request req)
private
void campaignd::server::load_blacklist ( )
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().

int campaignd::server::load_config ( )
private

Reads the server configuration from WML.

Returns
The configured listening port number.

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().

void campaignd::server::register_handler ( const std::string cmd,
const request_handler func 
)
private

Registers a single request handler.

Parameters
cmdThe request command, corresponding to the name of the [tag} with the request body (e.g. "handle_request_terms").
funcThe 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_.

void campaignd::server::register_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 ( )
void campaignd::server::send_error ( const std::string msg,
network::connection  sock 
)
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().

void campaignd::server::send_message ( const std::string msg,
network::connection  sock 
)
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().

const config& campaignd::server::server_info ( ) const
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().

config& campaignd::server::server_info ( )
inlineprivate

Retrieves the contents of the [server_info] WML node.

Definition at line 140 of file campaign_server.hpp.

References config::child().

void campaignd::server::write_config ( )
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().

Member Data Documentation

blacklist campaignd::server::blacklist_
private

Definition at line 97 of file campaign_server.hpp.

Referenced by handle_upload(), and load_blacklist().

std::string campaignd::server::blacklist_file_
private

Definition at line 98 of file campaign_server.hpp.

Referenced by load_blacklist(), and load_config().

config campaignd::server::cfg_
private

Definition at line 84 of file campaign_server.hpp.

Referenced by load_config(), run(), and write_config().

const std::string campaignd::server::cfg_file_
private

Definition at line 85 of file campaign_server.hpp.

Referenced by load_config(), and write_config().

int campaignd::server::compress_level_
private

Used for add-on archives.

Definition at line 88 of file campaign_server.hpp.

Referenced by handle_upload(), and load_config().

std::string campaignd::server::feedback_url_format_
private

Definition at line 95 of file campaign_server.hpp.

Referenced by handle_request_campaign_list(), and load_config().

request_handlers_table campaignd::server::handlers_
private

Definition at line 93 of file campaign_server.hpp.

Referenced by register_handler(), and run().

std::map<std::string, std::string> campaignd::server::hooks_
private

Definition at line 92 of file campaign_server.hpp.

Referenced by fire(), and load_config().

boost::scoped_ptr<input_stream> campaignd::server::input_
private

Server control socket.

Definition at line 90 of file campaign_server.hpp.

Referenced by load_config(), and run().

const network::manager campaignd::server::net_manager_
private

Definition at line 102 of file campaign_server.hpp.

int campaignd::server::port_
private

Definition at line 100 of file campaign_server.hpp.

Referenced by server().

bool campaignd::server::read_only_
private
const network::server_manager campaignd::server::server_manager_
private

Definition at line 103 of file campaign_server.hpp.


The documentation for this class was generated from the following files: