The Battle for Wesnoth  1.15.2+dev
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static 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)
 
 server (const config &server)=delete
 
 ~server ()
 
serveroperator= (const config &server)=delete
 
- Public Member Functions inherited from server_base
 server_base (unsigned short port, bool keep_alive)
 
virtual ~server_base ()
 
void run ()
 

Private Types

typedef std::function< void(server *, const request &req)> request_handler
 
typedef std::map< std::string, request_handlerrequest_handlers_table
 

Private Member Functions

void handle_new_client (socket_ptr socket)
 
void handle_request (socket_ptr socket, std::shared_ptr< simple_wml::document > doc)
 
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...
 
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...
 
void delete_campaign (const std::string &id)
 
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...
 
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_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, socket_ptr sock)
 Send a client an informational message. More...
 
void send_error (const std::string &msg, socket_ptr sock)
 Send a client an error message. More...
 
void send_error (const std::string &msg, const std::string &extra_data, socket_ptr 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...
 
std::map< std::string, std::string > hooks_
 
request_handlers_table handlers_
 
std::string feedback_url_format_
 
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...
 

Additional Inherited Members

- Protected Member Functions inherited from server_base
void setup_acceptor (boost::asio::ip::tcp::acceptor &acceptor, boost::asio::ip::tcp::endpoint endpoint)
 
void start_server ()
 
void serve (boost::asio::ip::tcp::acceptor &acceptor)
 
void accept_connection (boost::asio::ip::tcp::acceptor &acceptor, const boost::system::error_code &error, socket_ptr socket)
 
void serverside_handshake (socket_ptr socket)
 
void handle_handshake (const boost::system::error_code &error, socket_ptr socket, boost::shared_array< char > buf)
 
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 ()
 
void handle_termination (const boost::system::error_code &error, int signal_number)
 
- Protected Attributes inherited from server_base
unsigned short port_
 
bool keep_alive_
 
boost::asio::io_service io_service_
 
boost::asio::ip::tcp::acceptor acceptor_v6_
 
boost::asio::ip::tcp::acceptor acceptor_v4_
 
union {
   uint32_t   connection_num
 
   char   buf [4]
 
handshake_response_
 
boost::asio::posix::stream_descriptor input_
 
std::string fifo_path_
 
boost::asio::streambuf admin_cmd_
 
boost::asio::signal_set sighup_
 
boost::asio::signal_set sigs_
 

Detailed Description

Legacy add-ons server.

Definition at line 32 of file campaign_server.hpp.

Member Typedef Documentation

◆ request_handler

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

Definition at line 78 of file campaign_server.hpp.

◆ request_handlers_table

typedef std::map<std::string, request_handler> campaignd::server::request_handlers_table
private

Definition at line 79 of file campaign_server.hpp.

Constructor & Destructor Documentation

◆ server() [1/2]

campaignd::server::server ( const std::string &  cfg_file)
explicit

◆ server() [2/2]

campaignd::server::server ( const config server)
delete

◆ ~server()

campaignd::server::~server ( )

Definition at line 152 of file campaign_server.cpp.

References write_config().

Member Function Documentation

◆ campaigns() [1/2]

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

Retrieves the contents of the [campaigns] WML node.

Definition at line 138 of file campaign_server.hpp.

References config::child().

Referenced by delete_campaign(), get_campaign(), handle_request_campaign_list(), handle_upload(), and server().

◆ campaigns() [2/2]

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

Retrieves the contents of the [campaigns] WML node.

Definition at line 141 of file campaign_server.hpp.

References config::child().

◆ delete_campaign()

void campaignd::server::delete_campaign ( const std::string &  id)
private

◆ fire()

void campaignd::server::fire ( const std::string &  hook,
const std::string &  addon 
)
private

Fires a hook script.

Definition at line 442 of file campaign_server.cpp.

References ERR_CS, hooks_, and UNUSED.

Referenced by delete_campaign(), and handle_upload().

◆ flush_cfg()

void campaignd::server::flush_cfg ( )
private

Starts timer to write config to disk every ten minutes.

Definition at line 394 of file campaign_server.cpp.

References flush_timer_, and handle_flush().

Referenced by handle_flush(), and server().

◆ get_campaign()

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 144 of file campaign_server.hpp.

References campaigns(), delete_campaign(), and config::find_child().

Referenced by handle_change_passphrase(), handle_delete(), handle_read_from_fifo(), and handle_request_campaign().

◆ handle_change_passphrase()

void campaignd::server::handle_change_passphrase ( const request req)
private

◆ handle_delete()

void campaignd::server::handle_delete ( const request req)
private

◆ handle_flush()

void campaignd::server::handle_flush ( const boost::system::error_code &  error)
private

Definition at line 400 of file campaign_server.cpp.

References ERR_CS, flush_cfg(), and write_config().

Referenced by flush_cfg().

◆ handle_new_client()

void campaignd::server::handle_new_client ( socket_ptr  socket)
privatevirtual

◆ handle_read_from_fifo()

void campaignd::server::handle_read_from_fifo ( const boost::system::error_code &  error,
std::size_t  bytes_transferred 
)
privatevirtual

◆ handle_request()

void campaignd::server::handle_request ( socket_ptr  socket,
std::shared_ptr< simple_wml::document doc 
)
private

◆ handle_request_campaign()

void campaignd::server::handle_request_campaign ( const request req)
private

◆ handle_request_campaign_list()

void campaignd::server::handle_request_campaign_list ( const request req)
private

◆ handle_request_terms()

void campaignd::server::handle_request_terms ( const request req)
private

◆ handle_sighup()

void campaignd::server::handle_sighup ( const boost::system::error_code &  error,
int  signal_number 
)
privatevirtual

Implements server_base.

Definition at line 381 of file campaign_server.cpp.

References load_config(), LOG_CS, and server_base::sighup_.

◆ handle_upload()

void campaignd::server::handle_upload ( const request req)
private

◆ ignore_address_stats()

bool campaignd::server::ignore_address_stats ( const std::string &  addr) const
private

Checks if the specified address should never bump download counts.

Definition at line 483 of file campaign_server.cpp.

References stats_exempt_ips_, and utils::wildcard_string_match().

Referenced by handle_request_campaign(), and server_info().

◆ load_blacklist()

void campaignd::server::load_blacklist ( )
private

Reads the add-ons upload blacklist from WML.

Definition at line 410 of file campaign_server.cpp.

References blacklist_, blacklist_file_, campaignd::blacklist::clear(), ERR_CS, in, filesystem::istream_file(), LOG_CS, campaignd::blacklist::read(), and read().

Referenced by handle_read_from_fifo(), and load_config().

◆ load_config()

void campaignd::server::load_config ( )
private

◆ operator=()

server& campaignd::server::operator= ( const config server)
delete

◆ register_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 565 of file campaign_server.cpp.

References REGISTER_CAMPAIGND_HANDLER.

Referenced by server(), and server_info().

◆ send_error() [1/2]

void campaignd::server::send_error ( const std::string &  msg,
socket_ptr  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 502 of file campaign_server.cpp.

References simple_wml::node::add_child(), async_send_doc(), client_address(), ERR_CS, handle_new_client(), null_handler(), simple_wml::document::root(), and simple_wml::node::set_attr_dup().

Referenced by handle_change_passphrase(), handle_delete(), handle_request(), handle_request_campaign(), handle_request_terms(), handle_upload(), and server_info().

◆ send_error() [2/2]

void campaignd::server::send_error ( const std::string &  msg,
const std::string &  extra_data,
socket_ptr  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, and an extra_data attribute holding the value of extra_data. 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 510 of file campaign_server.cpp.

References simple_wml::node::add_child(), async_send_doc(), client_address(), ERR_CS, handle_new_client(), null_handler(), simple_wml::document::root(), and simple_wml::node::set_attr_dup().

◆ send_message()

void campaignd::server::send_message ( const std::string &  msg,
socket_ptr  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 495 of file campaign_server.cpp.

References simple_wml::node::add_child(), async_send_doc(), handle_new_client(), null_handler(), simple_wml::document::root(), and simple_wml::node::set_attr_dup().

Referenced by handle_change_passphrase(), handle_delete(), handle_request_terms(), handle_upload(), and server_info().

◆ server_info() [1/2]

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

Retrieves the contents of the [server_info] WML node.

Definition at line 149 of file campaign_server.hpp.

References config::child().

Referenced by load_config().

◆ server_info() [2/2]

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

◆ write_config()

void campaignd::server::write_config ( )
private

Member Data Documentation

◆ blacklist_

blacklist campaignd::server::blacklist_
private

Definition at line 95 of file campaign_server.hpp.

Referenced by handle_upload(), and load_blacklist().

◆ blacklist_file_

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

Definition at line 96 of file campaign_server.hpp.

Referenced by load_blacklist(), and load_config().

◆ cfg_

config campaignd::server::cfg_
private

Definition at line 81 of file campaign_server.hpp.

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

◆ cfg_file_

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

Definition at line 82 of file campaign_server.hpp.

Referenced by load_config(), and write_config().

◆ compress_level_

int campaignd::server::compress_level_
private

Used for add-on archives.

Definition at line 85 of file campaign_server.hpp.

Referenced by handle_upload(), and load_config().

◆ default_document_size_limit

const std::size_t campaignd::server::default_document_size_limit = 100 * 1024 * 1024
staticprivate

Default upload size limit in bytes.

Definition at line 88 of file campaign_server.hpp.

Referenced by load_config().

◆ feedback_url_format_

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

Definition at line 93 of file campaign_server.hpp.

Referenced by handle_request_campaign_list(), and load_config().

◆ flush_timer_

boost::asio::basic_waitable_timer<std::chrono::steady_clock> campaignd::server::flush_timer_
private

Definition at line 100 of file campaign_server.hpp.

Referenced by flush_cfg().

◆ handlers_

request_handlers_table campaignd::server::handlers_
private

Definition at line 91 of file campaign_server.hpp.

Referenced by handle_request().

◆ hooks_

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

Definition at line 90 of file campaign_server.hpp.

Referenced by fire(), and load_config().

◆ read_only_

bool campaignd::server::read_only_
private

◆ stats_exempt_ips_

std::vector<std::string> campaignd::server::stats_exempt_ips_
private

Definition at line 98 of file campaign_server.hpp.

Referenced by ignore_address_stats(), and load_config().


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