Added conversion from Handshake to NetworkMessage and vice versa
Added a new ConnectionCode - Close TcpServer: AddToClientsList and AllocateID are now called add_to_clients_list and allocate_id respectively and are now private, removed SendHandshake method - we now use SendMessage method and the HandshakeToNetworkMessage method in the Handshake class Added a new method to Utility::StringConverter - FromString Changed NetworkMessage conversions to allow Handshake conversions NetworkMessage: if subject is 1 then the NetworkMessage is a handshake I may be missing something but im going to check it I may be overcomplicating this but i want to make it as simple as possible xD
This commit is contained in:
@ -233,7 +233,8 @@ enum DistributionType
|
||||
enum ConnectionCode
|
||||
{
|
||||
Accept,
|
||||
Reject
|
||||
Reject,
|
||||
Close
|
||||
};
|
||||
|
||||
enum InternalTags
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
#endif
|
||||
|
||||
#include "Defs.hpp"
|
||||
#include "NetworkMessage.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
@ -17,6 +18,8 @@ struct Handshake
|
||||
|
||||
static const std::vector<byte> &EncodeHandshake(const Handshake &handshake);
|
||||
static Handshake &DecodeHandshake(const std::vector<byte> &bytes);
|
||||
static const NetworkMessage &HandshakeToNetworkMessage(const Handshake &handshake);
|
||||
static const Handshake &NetworkMessageToHandshake(const NetworkMessage &message);
|
||||
|
||||
uint16 id;
|
||||
byte con_code;
|
||||
|
||||
@ -19,13 +19,10 @@ struct TcpServer
|
||||
|
||||
void Shutdown();
|
||||
|
||||
uint16 AllocateID();
|
||||
void AddToClientsList(TcpClient &client);
|
||||
bool StartServer(bool accept_connections); // if accept_connections is false the user must call the funcion AcceptConnections()
|
||||
void AcceptConnections();
|
||||
|
||||
void SendMessage(const NetworkMessage &message);
|
||||
void SendHandshake(const Handshake &handshake);
|
||||
|
||||
void RejectConnection(TcpClient &client);
|
||||
void AcceptConnection(uint16 client);
|
||||
@ -44,6 +41,10 @@ private:
|
||||
static void process_client_messages(TcpServer *server, TcpClient &client);
|
||||
static void accept_connections(TcpServer *server);
|
||||
|
||||
void add_to_clients_list(TcpClient &client);
|
||||
|
||||
uint16 allocate_id();
|
||||
|
||||
void shutdown_internal();
|
||||
|
||||
bool initialize(uint16 port = default_server_port);
|
||||
|
||||
@ -56,6 +56,8 @@ struct Utility
|
||||
static const std::string &ToString(int64 value);
|
||||
static const std::string &ToString(const std::vector<byte> &bytes);
|
||||
|
||||
static const std::vector<byte> &FromString(const std::string &str);
|
||||
|
||||
static const std::string &ToString(const std::vector<byte> &bytes, uint16 start_index = 0, uint16 lenght = 0);
|
||||
|
||||
static const std::string &Trim(std::string &str, char ch);
|
||||
|
||||
@ -9,6 +9,8 @@
|
||||
|
||||
struct VoidNetServer
|
||||
{
|
||||
void StartServer(uint16 port);
|
||||
void StopServer();
|
||||
private:
|
||||
TcpServer server;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user