33 #include <boost/asio/io_service.hpp>
34 #include <boost/asio/ip/tcp.hpp>
36 #include <boost/asio/posix/stream_descriptor.hpp>
38 #include <boost/asio/signal_set.hpp>
39 #include <boost/asio/streambuf.hpp>
40 #include <boost/asio/ssl.hpp>
41 #include <boost/asio/spawn.hpp>
42 #include <boost/shared_array.hpp>
50 typedef std::shared_ptr<boost::asio::ip::tcp::socket>
socket_ptr;
51 typedef std::shared_ptr<boost::asio::ssl::stream<socket_ptr::element_type>>
tls_socket_ptr;
56 boost::system::error_code
ec;
81 template<
class SocketPtr>
void send_doc_queued(SocketPtr socket, std::unique_ptr<simple_wml::document>& doc_ptr, boost::asio::yield_context yield);
109 template<
class SocketPtr> std::unique_ptr<simple_wml::document>
coro_receive_doc(SocketPtr socket, boost::asio::yield_context yield);
148 std::string
hash_password(
const std::string& pw,
const std::string& salt,
const std::string& username);
154 boost::asio::ssl::context
tls_context_ { boost::asio::ssl::context::sslv23 };
162 void serve(boost::asio::yield_context yield, boost::asio::ip::tcp::acceptor& acceptor, boost::asio::ip::tcp::endpoint endpoint);
170 virtual std::string
is_ip_banned(
const std::string&) {
return std::string(); }
174 boost::asio::posix::stream_descriptor
input_;
181 virtual void handle_sighup(
const boost::system::error_code& error,
int signal_number) = 0;
185 template<
class SocketPtr> std::string
client_address(SocketPtr socket);
187 template<
class SocketPtr>
bool check_error(
const boost::system::error_code& error, SocketPtr socket);
A config object defines a single node in a WML file, with access to child nodes.
Base class for implementing servers that use gzipped-WML network protocol.
std::string hash_password(const std::string &pw, const std::string &salt, const std::string &username)
Handles hashing the password provided by the player before comparing it to the hashed password in the...
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.
virtual void handle_read_from_fifo(const boost::system::error_code &error, std::size_t bytes_transferred)=0
boost::asio::signal_set sighup_
uint32_t handshake_response_
boost::asio::streambuf admin_cmd_
void async_send_error(SocketPtr socket, const std::string &msg, const char *error_code="", const info_table &info={})
virtual void handle_new_client(socket_ptr socket)=0
std::unique_ptr< simple_wml::document > coro_receive_doc(SocketPtr socket, boost::asio::yield_context yield)
Receive WML document from a coroutine.
boost::asio::ip::tcp::acceptor acceptor_v4_
void async_send_doc_queued(SocketPtr socket, simple_wml::document &doc)
High level wrapper for sending a WML document.
std::map< std::string, std::string > info_table
std::string create_secure_nonce()
Create a good security nonce for use with bcrypt/crypt_blowfish hashing.
void send_doc_queued(SocketPtr socket, std::unique_ptr< simple_wml::document > &doc_ptr, boost::asio::yield_context yield)
virtual void handle_new_client(tls_socket_ptr socket)=0
void coro_send_doc(SocketPtr socket, simple_wml::document &doc, boost::asio::yield_context yield)
Send a WML document from within a coroutine.
void coro_send_file(tls_socket_ptr socket, const std::string &filename, boost::asio::yield_context yield)
virtual void handle_sighup(const boost::system::error_code &error, int signal_number)=0
void async_send_warning(SocketPtr socket, const std::string &msg, const char *warning_code="", const info_table &info={})
virtual bool ip_exceeds_connection_limit(const std::string &) const
boost::asio::io_service io_service_
virtual bool accepting_connections() const
virtual std::string is_ip_banned(const std::string &)
std::string create_unsecure_nonce(int length=8)
Create the poor security nonce for use with passwords still hashed with MD5.
server_base(unsigned short port, bool keep_alive)
boost::asio::posix::stream_descriptor input_
void serve(boost::asio::yield_context yield, boost::asio::ip::tcp::acceptor &acceptor, boost::asio::ip::tcp::endpoint endpoint)
void load_tls_config(const config &cfg)
boost::asio::ssl::context tls_context_
boost::asio::ip::tcp::acceptor acceptor_v6_
constexpr bool decayed_is_same
Equivalent to as std::is_same_v except both types are passed through std::decay first.
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
std::shared_ptr< boost::asio::ssl::stream< socket_ptr::element_type > > tls_socket_ptr
bool check_error(const boost::system::error_code &error, SocketPtr socket)
std::string client_address(SocketPtr socket)
std::string log_address(SocketPtr socket)
utils::variant< socket_ptr, tls_socket_ptr > any_socket_ptr
std::shared_ptr< boost::asio::ip::tcp::socket > socket_ptr
std::string filename
Filename.
Base class for all the errors encountered by the engine.
boost::system::error_code ec
server_shutdown(const std::string &msg, boost::system::error_code ec={})
MacOS doesn't support std::visit when targing MacOS < 10.14 (currently we target 10....