Added Handshake class

Fixed NetworkBuffer include
Fixed some data types
TcpClient: Added SendBytes, SetOnDisconnectCallback, SetOnConnectCallback, SetOnMessageCallback methods and made callback std::function's private and fixed some method implementations
Added AcceptConnection on TcpServer
Fixed TcpServer AddToClientsList
This commit is contained in:
xX-TheDoctor-Xx
2016-08-01 00:28:22 +01:00
parent e677fdeb59
commit 0ac8b4f6e8
18 changed files with 143 additions and 25 deletions

40
src/Handshake.cpp Normal file
View File

@ -0,0 +1,40 @@
#include "Handshake.hpp"
#include "Utility.hpp"
Handshake::Handshake()
{
id = -2;
}
Handshake::Handshake(uint16 id, byte con_code)
{
this->id = id;
this->con_code = con_code;
}
Handshake::~Handshake()
{
}
const std::vector<byte>& Handshake::EncodeHandshake(const Handshake & handshake)
{
std::vector<byte> handshake_bytes;
std::vector<byte> id = Utility::BitConverter::FromUint16(handshake.id);
std::vector<byte> con_mode = Utility::BitConverter::FromUint8(handshake.con_code);
handshake_bytes.insert(handshake_bytes.end(), id.begin(), id.end());
handshake_bytes.insert(handshake_bytes.end(), con_mode.begin(), con_mode.end());
return handshake_bytes;
}
Handshake & Handshake::DecodeHandshake(const std::vector<byte>& bytes)
{
Handshake handshake;
handshake.id = Utility::BitConverter::ToUint16(bytes);
handshake.con_code = Utility::BitConverter::ToUint8(bytes, 2);
return handshake;
}