#pragma once #include "tcp_server.h" #include "servertalk_server_connection.h" #include #include #ifdef ENABLE_SECURITY #include #endif namespace EQ { namespace Net { struct ServertalkServerOptions { int port; bool ipv6; bool encrypted; bool allow_downgrade; std::string credentials; ServertalkServerOptions() { #ifdef ENABLE_SECURITY encrypted = true; allow_downgrade = true; #else encrypted = false; allow_downgrade = true; #endif ipv6 = false; } }; class ServertalkServer { public: ServertalkServer(); ~ServertalkServer(); void Listen(const ServertalkServerOptions& opts); void OnConnectionIdentified(const std::string &type, std::function)> cb); void OnConnectionRemoved(const std::string &type, std::function)> cb); private: void ConnectionDisconnected(ServertalkServerConnection *conn); void ConnectionIdentified(ServertalkServerConnection *conn); bool CheckCredentials(const std::string &credentials); std::unique_ptr m_server; std::vector> m_unident_connections; std::map>> m_ident_connections; std::map)>> m_on_ident; std::map)>> m_on_disc; bool m_encrypted; bool m_allow_downgrade; std::string m_credentials; friend class ServertalkServerConnection; }; } }