WIP Clients are working properly, servers are not.
This commit is contained in:
@@ -13,6 +13,8 @@
|
||||
#include "Network/Network.h"
|
||||
#include "Network/MessageType.h"
|
||||
#include "Network/PlayerDefinition.h"
|
||||
#include "Network/UDPClient.h"
|
||||
#include "Network/TCPClient.h"
|
||||
#include "Network/SnapshotDefinitions.h"
|
||||
#include "Core/World.h"
|
||||
#include "Core/EventBroker.h"
|
||||
@@ -35,7 +37,6 @@ protected:
|
||||
int port = 0;
|
||||
// Sending message to server logic
|
||||
int bytesRead = -1;
|
||||
char readBuffer[BUFFERSIZE] = { 0 };
|
||||
|
||||
// Packet loss logic
|
||||
PacketID m_PacketID = 0;
|
||||
@@ -66,9 +67,6 @@ protected:
|
||||
std::vector<Events::InputCommand> m_InputCommandBuffer;
|
||||
|
||||
// Private member functions
|
||||
virtual void send(Packet& packet) = 0;
|
||||
virtual void readFromServer() = 0;
|
||||
virtual void connect() = 0;
|
||||
void disconnect();
|
||||
void parseMessageType(Packet& packet);
|
||||
void updateFields(Packet& packet, const ComponentInfo& componentInfo, const EntityID& entityID, const std::string& componentType);
|
||||
@@ -103,6 +101,11 @@ protected:
|
||||
bool OnPlayerDamage(const Events::PlayerDamage& e);
|
||||
EventRelay<Client, Events::PlayerSpawned> m_EPlayerSpawned;
|
||||
bool OnPlayerSpawned(const Events::PlayerSpawned& e);
|
||||
|
||||
private:
|
||||
//UDPClient m_UDPClient;
|
||||
//TCPClient m_TCPClient;
|
||||
TCPClient m_UDPClient;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -18,7 +18,8 @@ enum class MessageType
|
||||
OnPlayerSpawned,
|
||||
EntityDeleted,
|
||||
ComponentDeleted,
|
||||
PlayerTransform
|
||||
PlayerTransform,
|
||||
Invalid
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -30,6 +30,8 @@ protected:
|
||||
std::clock_t m_SaveDataTimer;
|
||||
unsigned int m_MaxConnections;
|
||||
unsigned int m_TimeoutMs;
|
||||
void logSentData(int bytesSent);
|
||||
void logReceivedData(int bytesReceived);
|
||||
void saveToFile();
|
||||
void updateNetworkData();
|
||||
void initialize();
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef NetworkClient_h__
|
||||
#define NetworkClient_h__
|
||||
|
||||
#include "Network/Packet.h"
|
||||
#define BUFFERSIZE 32000
|
||||
typedef unsigned int PlayerID;
|
||||
typedef unsigned int PacketID;
|
||||
|
||||
class NetworkClient
|
||||
{
|
||||
public:
|
||||
virtual void Connect(std::string playerName, std::string address, int port) = 0;
|
||||
virtual void Disconnect() = 0;
|
||||
virtual void Receive(Packet& packet) = 0;
|
||||
virtual void Send(Packet & packet) = 0;
|
||||
virtual bool IsSocketAvailable() = 0;
|
||||
protected:
|
||||
char m_ReadBuffer[BUFFERSIZE] = { 0 };
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef NetworkServer_h__
|
||||
#define NetworkServer_h__
|
||||
|
||||
#include "Network/Packet.h"
|
||||
#define BUFFERSIZE 32000
|
||||
typedef unsigned int PlayerID;
|
||||
typedef unsigned int PacketID;
|
||||
|
||||
class NetworkServer
|
||||
{
|
||||
//public:
|
||||
// virtual void Connect(std::string playerName, std::string address, int port) = 0;
|
||||
// virtual void Disconnect() = 0;
|
||||
// virtual Packet Receive() = 0;
|
||||
// virtual void Send(Packet & packet) = 0;
|
||||
//protected:
|
||||
// char m_ReadBuffer[BUFFERSIZE] = { 0 };
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -49,12 +49,15 @@ public:
|
||||
void WriteData(char* data, int sizeOfData);
|
||||
// Pops the first element as if it was a string.
|
||||
std::string ReadString();
|
||||
// Construct a packet
|
||||
void ReconstructFromData(char* data, int SizeOfData);
|
||||
// Update size of packet variable in header
|
||||
void UpdateSize();
|
||||
char* ReadData(int SizeOfData);
|
||||
void ChangePacketID(unsigned int& packetID);
|
||||
int Size() { return m_Offset; };
|
||||
char* Data() { return m_Data; };
|
||||
MessageType GetMessageType() { return m_MessageType; };
|
||||
unsigned int DataReadSize() { return m_ReturnDataOffset; }
|
||||
unsigned int MaxSize() { return m_MaxPacketSize; }
|
||||
unsigned int HeaderSize() { return m_HeaderSize; }
|
||||
@@ -65,7 +68,9 @@ private:
|
||||
int m_Offset = 0;
|
||||
unsigned int m_MaxPacketSize = 512;
|
||||
unsigned int m_HeaderSize = 0;
|
||||
MessageType m_MessageType = MessageType::Invalid;
|
||||
void resizeData();
|
||||
void resizeData(int size);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,23 +1,32 @@
|
||||
#ifndef TCPClient_h__
|
||||
#define TCPClient_h__
|
||||
|
||||
#include "Client.h"
|
||||
#include <boost/asio.hpp>
|
||||
#include "NetworkClient.h"
|
||||
|
||||
class TCPClient : public Client
|
||||
class TCPClient : public NetworkClient
|
||||
{
|
||||
public:
|
||||
TCPClient(ConfigFile* config);
|
||||
TCPClient();
|
||||
~TCPClient();
|
||||
|
||||
void Connect(std::string playerName, std::string address, int port);
|
||||
void Disconnect();
|
||||
void Receive(Packet& packet);
|
||||
void Send(Packet & packet);
|
||||
bool IsSocketAvailable();
|
||||
private:
|
||||
// Assio UDP logic
|
||||
//boost::asio::io_service m_IOService;
|
||||
//boost::asio::ip::udp::endpoint m_ReceiverEndpoint;
|
||||
//boost::shared_ptr<boost::asio::ip::udp::socket> m_Socket;
|
||||
// Assio TCP logic
|
||||
boost::asio::ip::tcp::endpoint m_Endpoint;
|
||||
boost::asio::io_service m_IOService;
|
||||
std::unique_ptr<boost::asio::ip::tcp::socket> m_Socket;
|
||||
|
||||
void connect();
|
||||
void readFromServer();
|
||||
int receive(char * data);
|
||||
void send(Packet & packet);
|
||||
int readBuffer(char* data);
|
||||
PacketID m_SendPacketID = 0;
|
||||
bool m_IsConnected = false;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,24 +1,31 @@
|
||||
#ifndef UDPClient_h__
|
||||
#define UDPClient_h__
|
||||
|
||||
#include "Client.h"
|
||||
#include <boost/asio.hpp>
|
||||
#include "Network/NetworkClient.h"
|
||||
//virtual void Connect(std::string address, int port) = 0;
|
||||
//virtual int Receive(char * data) = 0;
|
||||
//virtual void Send(Packet & packet) = 0;
|
||||
//virtual void Disconnect() = 0;
|
||||
|
||||
|
||||
class UDPClient : public Client
|
||||
class UDPClient : public NetworkClient
|
||||
{
|
||||
public:
|
||||
UDPClient(ConfigFile* config);
|
||||
UDPClient();
|
||||
~UDPClient();
|
||||
|
||||
void Connect(std::string playerName, std::string address, int port);
|
||||
void Disconnect();
|
||||
void Receive(Packet& packet);
|
||||
void Send(Packet & packet);
|
||||
bool IsSocketAvailable();
|
||||
private:
|
||||
// Assio UDP logic
|
||||
boost::asio::io_service m_IOService;
|
||||
boost::asio::ip::udp::endpoint m_ReceiverEndpoint;
|
||||
boost::asio::ip::udp::socket m_Socket;
|
||||
|
||||
void connect();
|
||||
void readFromServer();
|
||||
int receive(char * data);
|
||||
void send(Packet & packet);
|
||||
boost::shared_ptr<boost::asio::ip::udp::socket> m_Socket;
|
||||
int readBuffer(char* data);
|
||||
PacketID m_SendPacketID = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user