The Battle for Wesnoth  1.15.12+dev
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
server_base Class Referenceabstract

#include <server_base.hpp>

Inheritance diagram for server_base:

Public Types

typedef std::map< std::string, std::string > info_table
 

Public Member Functions

 server_base (unsigned short port, bool keep_alive)
 
virtual ~server_base ()
 
void run ()
 
void coro_send_doc (socket_ptr 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...
 
std::unique_ptr< simple_wml::documentcoro_receive_doc (socket_ptr socket, boost::asio::yield_context yield)
 Receive WML document from a coroutine. More...
 
void async_send_doc_queued (socket_ptr socket, simple_wml::document &doc)
 High level wrapper for sending a WML document. More...
 
void async_send_error (socket_ptr socket, const std::string &msg, const char *error_code="", const info_table &info={})
 
void async_send_warning (socket_ptr socket, const std::string &msg, const char *warning_code="", const info_table &info={})
 

Protected Member Functions

void start_server ()
 
void serve (boost::asio::yield_context yield, boost::asio::ip::tcp::acceptor &acceptor, boost::asio::ip::tcp::endpoint endpoint)
 
virtual void handle_new_client (socket_ptr socket)=0
 
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 ()
 
virtual void handle_read_from_fifo (const boost::system::error_code &error, std::size_t bytes_transferred)=0
 
virtual void handle_sighup (const boost::system::error_code &error, int signal_number)=0
 
void handle_termination (const boost::system::error_code &error, int signal_number)
 

Protected Attributes

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

Definition at line 50 of file server_base.hpp.

Member Typedef Documentation

◆ info_table

typedef std::map<std::string, std::string> server_base::info_table

Definition at line 88 of file server_base.hpp.

Constructor & Destructor Documentation

◆ server_base()

server_base::server_base ( unsigned short  port,
bool  keep_alive 
)

Definition at line 55 of file server_base.cpp.

◆ ~server_base()

virtual server_base::~server_base ( )
inlinevirtual

Definition at line 54 of file server_base.hpp.

Member Function Documentation

◆ accepting_connections()

virtual bool server_base::accepting_connections ( ) const
inlineprotectedvirtual

Reimplemented in wesnothd::server.

Definition at line 108 of file server_base.hpp.

Referenced by serve().

◆ async_send_doc_queued()

void server_base::async_send_doc_queued ( socket_ptr  socket,
simple_wml::document doc 
)

High level wrapper for sending a WML document.

This function returns before send is finished. This function can be called again on same socket before previous send was finished. WML documents are kept in internal queue and sent in FIFO order.

Parameters
socket
docDocument to send. A copy of it will be made so there is no need to keep the reference live after the function returns.

Definition at line 432 of file server_base.cpp.

References simple_wml::document::clone(), coro_send_doc(), io_service_, and utf8::size().

Referenced by wesnothd::game::add_player(), wesnothd::server::adminmsg_handler(), async_send_error(), async_send_warning(), wesnothd::game::change_controller(), wesnothd::server::delete_game(), wesnothd::game::handle_controller_choice(), wesnothd::server::handle_create_game(), wesnothd::server::handle_join_game(), wesnothd::server::handle_player(), wesnothd::server::handle_player_in_game(), campaignd::server::handle_request_campaign_list(), campaignd::server::handle_server_id(), wesnothd::server::handle_whisper(), wesnothd::game::load_next_scenario(), wesnothd::server::login_client(), wesnothd::game::notify_new_host(), wesnothd::server::pm_handler(), wesnothd::game::remove_player(), campaignd::server::send_error(), wesnothd::game::send_history(), wesnothd::game::send_leave_game(), campaignd::server::send_message(), wesnothd::game::send_observerjoins(), wesnothd::server::send_password_request(), wesnothd::server::send_server_message(), wesnothd::game::send_server_message(), wesnothd::game::send_taken_side(), wesnothd::server::send_to_lobby(), and wesnothd::game::send_to_players().

◆ async_send_error()

void server_base::async_send_error ( socket_ptr  socket,
const std::string &  msg,
const char *  error_code = "",
const info_table info = {} 
)

◆ async_send_warning()

void server_base::async_send_warning ( socket_ptr  socket,
const std::string &  msg,
const char *  warning_code = "",
const info_table info = {} 
)

◆ coro_receive_doc()

std::unique_ptr< simple_wml::document > server_base::coro_receive_doc ( socket_ptr  socket,
boost::asio::yield_context  yield 
)

Receive WML document from a coroutine.

Parameters
socket
yieldThe function will suspend on read operation using this yield context

Definition at line 393 of file server_base.cpp.

References async_send_error(), buf, client_address(), simple_wml::document::document_size_limit, e, ERR_SERVER, game::error::message, and utf8::size().

Referenced by campaignd::server::handle_new_client(), wesnothd::server::handle_player(), and wesnothd::server::login_client().

◆ coro_send_doc()

void server_base::coro_send_doc ( socket_ptr  socket,
simple_wml::document doc,
boost::asio::yield_context  yield 
)

◆ coro_send_file()

void server_base::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.

Parameters
socket
filename
yieldThe function will suspend on write operations using this yield context

Definition at line 385 of file server_base.cpp.

Referenced by coro_send_doc(), campaignd::server::handle_request_campaign(), and campaignd::server::handle_request_campaign_hash().

◆ handle_new_client()

virtual void server_base::handle_new_client ( socket_ptr  socket)
protectedpure virtual

Implemented in campaignd::server, and wesnothd::server.

Referenced by serve().

◆ handle_read_from_fifo()

virtual void server_base::handle_read_from_fifo ( const boost::system::error_code &  error,
std::size_t  bytes_transferred 
)
protectedpure virtual

Implemented in wesnothd::server, and campaignd::server.

Referenced by read_from_fifo().

◆ handle_sighup()

virtual void server_base::handle_sighup ( const boost::system::error_code &  error,
int  signal_number 
)
protectedpure virtual

Implemented in wesnothd::server, and campaignd::server.

Referenced by start_server().

◆ handle_termination()

void server_base::handle_termination ( const boost::system::error_code &  error,
int  signal_number 
)
protected

Definition at line 172 of file server_base.cpp.

References LOG_SERVER.

Referenced by start_server().

◆ ip_exceeds_connection_limit()

virtual bool server_base::ip_exceeds_connection_limit ( const std::string &  ) const
inlineprotectedvirtual

Reimplemented in wesnothd::server.

Definition at line 110 of file server_base.hpp.

Referenced by serve().

◆ is_ip_banned()

virtual std::string server_base::is_ip_banned ( const std::string &  )
inlineprotectedvirtual

Reimplemented in wesnothd::server.

Definition at line 109 of file server_base.hpp.

Referenced by serve().

◆ read_from_fifo()

void server_base::read_from_fifo ( )
protected

◆ run()

void server_base::run ( )

Definition at line 184 of file server_base.cpp.

References e, io_service_, LOG_SERVER, and game::error::what().

Referenced by main(), and run_campaignd().

◆ serve()

void server_base::serve ( boost::asio::yield_context  yield,
boost::asio::ip::tcp::acceptor &  acceptor,
boost::asio::ip::tcp::endpoint  endpoint 
)
protected

◆ start_server()

void server_base::start_server ( )
protected

Member Data Documentation

◆ acceptor_v4_

boost::asio::ip::tcp::acceptor server_base::acceptor_v4_
protected

◆ acceptor_v6_

boost::asio::ip::tcp::acceptor server_base::acceptor_v6_
protected

◆ admin_cmd_

boost::asio::streambuf server_base::admin_cmd_
protected

◆ buf

char server_base::buf[4]

Definition at line 103 of file server_base.hpp.

Referenced by coro_receive_doc(), and coro_send_doc().

◆ connection_num

uint32_t server_base::connection_num

Definition at line 102 of file server_base.hpp.

◆ fifo_path_

std::string server_base::fifo_path_
protected

Definition at line 114 of file server_base.hpp.

Referenced by campaignd::server::load_config().

◆ handshake_response_

union { ... } server_base::handshake_response_

Referenced by serve(), and start_server().

◆ input_

boost::asio::posix::stream_descriptor server_base::input_
protected

◆ io_service_

boost::asio::io_service server_base::io_service_
protected

◆ keep_alive_

bool server_base::keep_alive_
protected

Definition at line 94 of file server_base.hpp.

Referenced by serve().

◆ port_

unsigned short server_base::port_
protected

◆ sighup_

boost::asio::signal_set server_base::sighup_
protected

◆ sigs_

boost::asio::signal_set server_base::sigs_
protected

Definition at line 122 of file server_base.hpp.

Referenced by start_server().


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