34 #include <boost/asio/io_context.hpp>
35 #include <boost/asio/ip/tcp.hpp>
37 #include <boost/asio/posix/stream_descriptor.hpp>
39 #include <boost/asio/signal_set.hpp>
40 #include <boost/asio/streambuf.hpp>
41 #include <boost/asio/ssl.hpp>
42 #include <boost/asio/spawn.hpp>
43 #include <boost/shared_array.hpp>
51 typedef std::shared_ptr<boost::asio::ip::tcp::socket>
socket_ptr;
52 typedef std::shared_ptr<boost::asio::ssl::stream<socket_ptr::element_type>>
tls_socket_ptr;
57 boost::system::error_code
ec;
82 template<
class SocketPtr>
void send_doc_queued(SocketPtr socket, std::unique_ptr<simple_wml::document>& doc_ptr, boost::asio::yield_context yield);
110 template<
class SocketPtr> std::unique_ptr<simple_wml::document>
coro_receive_doc(SocketPtr socket,
const boost::asio::yield_context& yield);
134 std::string
hash_password(
const std::string& pw,
const std::string& salt,
const std::string& username);
140 boost::asio::ssl::context
tls_context_ { boost::asio::ssl::context::sslv23 };
148 void serve(
const boost::asio::yield_context& yield, boost::asio::ip::tcp::acceptor& acceptor,
const boost::asio::ip::tcp::endpoint& endpoint);
165 virtual utils::optional<login_ban_info>
is_ip_banned(
const std::string&) {
return {}; }
168 boost::asio::posix::stream_descriptor
input_;
175 virtual void handle_sighup(
const boost::system::error_code& error,
int signal_number) = 0;
179 template<
class SocketPtr> std::string
client_address(SocketPtr socket);
181 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...
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
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
virtual utils::optional< login_ban_info > is_ip_banned(const std::string &)
void coro_send_doc(SocketPtr socket, simple_wml::document &doc, const boost::asio::yield_context &yield)
Send a WML document from within a coroutine.
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
boost::asio::io_context io_service_
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={})
void serve(const boost::asio::yield_context &yield, boost::asio::ip::tcp::acceptor &acceptor, const boost::asio::ip::tcp::endpoint &endpoint)
virtual bool ip_exceeds_connection_limit(const std::string &) const
virtual bool accepting_connections() const
server_base(unsigned short port, bool keep_alive)
std::unique_ptr< simple_wml::document > coro_receive_doc(SocketPtr socket, const boost::asio::yield_context &yield)
Receive WML document from a coroutine.
boost::asio::posix::stream_descriptor input_
void coro_send_file(const socket_ptr &socket, const std::string &filename, const boost::asio::yield_context &yield)
Send contents of entire file directly to socket from within a coroutine.
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.
utils::optional< std::chrono::seconds > time_remaining
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....