WIP Reliable message
This commit is contained in:
@@ -30,11 +30,9 @@ public:
|
||||
void Start(World* world, EventBroker* eventBroker) override;
|
||||
void Update() override;
|
||||
protected:
|
||||
// Assio UDP logic
|
||||
boost::asio::ip::udp::endpoint m_ReceiverEndpoint;
|
||||
boost::asio::io_service m_IOService;
|
||||
boost::asio::ip::udp::socket m_Socket;
|
||||
|
||||
// Save for children
|
||||
std::string address;
|
||||
int port = 0;
|
||||
// Sending message to server logic
|
||||
int bytesRead = -1;
|
||||
char readBuf[INPUTSIZE] = { 0 };
|
||||
@@ -68,9 +66,8 @@ protected:
|
||||
std::vector<Events::InputCommand> m_InputCommandBuffer;
|
||||
|
||||
// Private member functions
|
||||
void readFromServer();
|
||||
int receive(char* data);
|
||||
void send(Packet& packet);
|
||||
virtual void send(Packet& packet) = 0;
|
||||
virtual void readFromServer() = 0;
|
||||
void connect();
|
||||
void disconnect();
|
||||
void parseMessageType(Packet& packet);
|
||||
|
||||
@@ -9,6 +9,16 @@ class HybridClient : public Client
|
||||
public:
|
||||
HybridClient(ConfigFile* config);
|
||||
~HybridClient();
|
||||
void Start(World* world, EventBroker* eventBroker);
|
||||
private:
|
||||
// Assio UDP logic
|
||||
boost::asio::ip::udp::endpoint m_ReceiverEndpoint;
|
||||
boost::asio::io_service m_IOService;
|
||||
boost::asio::ip::udp::socket m_Socket;
|
||||
|
||||
void readFromServer();
|
||||
int receive(char * data);
|
||||
void send(Packet & packet);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef HybridServer_h__
|
||||
#define HybridServer_h__
|
||||
|
||||
#include "Server.h"
|
||||
#include <boost/asio/ip/udp.hpp>
|
||||
|
||||
class HybridServer : public Server
|
||||
{
|
||||
public:
|
||||
HybridServer();
|
||||
~HybridServer();
|
||||
private:
|
||||
// UDP logic
|
||||
boost::asio::io_service m_IOService;
|
||||
std::unique_ptr<boost::asio::ip::udp::socket> m_Socket;
|
||||
|
||||
void readFromClients();
|
||||
void parseClientPing();
|
||||
void parsePing();
|
||||
void parseDisconnect();
|
||||
void parseConnect(Packet & packet);
|
||||
void parseOnInputCommand(Packet & packet);
|
||||
void parsePlayerTransform(Packet & packet);
|
||||
void send(Packet & packet, PlayerDefinition & playerDefinition);
|
||||
void send(Packet & packet);
|
||||
int receive(char * data);
|
||||
PlayerID GetPlayerIDFromEndpoint(boost::asio::ip::udp::endpoint endpoint);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -2,6 +2,7 @@
|
||||
#define PlayerDefinition_h__
|
||||
#include <string>
|
||||
#include "../Core/Entity.h"
|
||||
#include <boost/asio.hpp>
|
||||
|
||||
struct PlayerDefinition {
|
||||
::EntityID EntityID = EntityID_Invalid;
|
||||
@@ -9,6 +10,8 @@ struct PlayerDefinition {
|
||||
boost::asio::ip::udp::endpoint Endpoint;
|
||||
unsigned int PacketID;
|
||||
std::clock_t StopTime;
|
||||
// use for tcp connections
|
||||
boost::shared_ptr<boost::asio::ip::tcp::socket> TCPSocket;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include <ctime>
|
||||
|
||||
#include <glm/common.hpp>
|
||||
#include <boost/asio/ip/udp.hpp>
|
||||
|
||||
#include "Network/MessageType.h"
|
||||
#include "Network/PlayerDefinition.h"
|
||||
@@ -18,7 +17,6 @@
|
||||
#include "Core/EPlayerSpawned.h"
|
||||
#include "Core/EEntityDeleted.h"
|
||||
#include "Core/EComponentDeleted.h"
|
||||
|
||||
class Server : public Network
|
||||
{
|
||||
public:
|
||||
@@ -26,12 +24,9 @@ public:
|
||||
~Server();
|
||||
void Start(World* m_world, EventBroker *eventBroker) override;
|
||||
void Update() override;
|
||||
private:
|
||||
// UDP logic
|
||||
boost::asio::ip::udp::endpoint m_ReceiverEndpoint;
|
||||
boost::asio::io_service m_IOService;
|
||||
boost::asio::ip::udp::socket m_Socket;
|
||||
|
||||
protected:
|
||||
template<class T>
|
||||
T m_ReceiverEndpoint;
|
||||
// Sending messages to client logic
|
||||
std::map<PlayerID, PlayerDefinition> m_ConnectedPlayers;
|
||||
// HACK: Fix INPUTSIZE
|
||||
@@ -41,12 +36,12 @@ private:
|
||||
std::clock_t previousePingMessage = std::clock();
|
||||
std::clock_t previousSnapshotMessage = std::clock();
|
||||
std::clock_t timOutTimer = std::clock();
|
||||
|
||||
// How often we send messages (milliseconds)
|
||||
int pingIntervalMs;
|
||||
int snapshotInterval;
|
||||
int checkTimeOutInterval = 100;
|
||||
int m_NextPlayerID = 0;
|
||||
|
||||
//Timers
|
||||
std::clock_t m_StartPingTime;
|
||||
|
||||
@@ -59,10 +54,7 @@ private:
|
||||
PacketID m_PreviousPacketID = 0;
|
||||
|
||||
// Private member functions
|
||||
int receive(char* data);
|
||||
void readFromClients();
|
||||
void send(PlayerID player, Packet& packet);
|
||||
void send(Packet& packet);
|
||||
//int receive(char* data);
|
||||
void broadcast(Packet& packet);
|
||||
void sendSnapshot();
|
||||
void addChildrenToPacket(Packet& packet, EntityID entityID);
|
||||
@@ -70,15 +62,18 @@ private:
|
||||
void checkForTimeOuts();
|
||||
void disconnect(PlayerID playerID);
|
||||
void parseMessageType(Packet& packet);
|
||||
void parseOnInputCommand(Packet& packet);
|
||||
void parseOnPlayerDamage(Packet& packet);
|
||||
void parseConnect(Packet& packet);
|
||||
void parseDisconnect();
|
||||
void parseClientPing();
|
||||
void parsePing();
|
||||
void identifyPacketLoss();
|
||||
void kick(PlayerID player);
|
||||
PlayerID GetPlayerIDFromEndpoint(boost::asio::ip::udp::endpoint endpoint);
|
||||
// Pure virtual functions
|
||||
virtual void parseOnInputCommand(Packet& packet) = 0;
|
||||
virtual void readFromClients() = 0;
|
||||
virtual void send(Packet& packet, PlayerDefinition & playerDefinition) = 0;
|
||||
virtual void send(Packet& packet) = 0;
|
||||
virtual void parseConnect(Packet& packet) = 0;
|
||||
virtual void parseDisconnect() = 0;
|
||||
virtual void parseClientPing() = 0;
|
||||
virtual void parsePing() = 0;
|
||||
// Debug event
|
||||
EventRelay<Server, Events::InputCommand> m_EInputCommand;
|
||||
bool OnInputCommand(const Events::InputCommand& e);
|
||||
@@ -88,7 +83,7 @@ private:
|
||||
bool OnEntityDeleted(const Events::EntityDeleted& e);
|
||||
EventRelay<Server, Events::ComponentDeleted> m_EComponentDeleted;
|
||||
bool OnComponentDeleted(const Events::ComponentDeleted& e);
|
||||
void parsePlayerTransform(Packet& packet);
|
||||
virtual void parsePlayerTransform(Packet& packet) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,7 +1,23 @@
|
||||
#ifndef TCPClient_h__
|
||||
#define TCPClient_h__
|
||||
|
||||
#include "Client.h"
|
||||
|
||||
class TCPClient : public Client
|
||||
{
|
||||
public:
|
||||
TCPClient(ConfigFile* config);
|
||||
~TCPClient();
|
||||
void Start(World* world, EventBroker* eventBroker);
|
||||
private:
|
||||
// Assio TCP logic
|
||||
boost::asio::ip::tcp::endpoint m_Endpoint;
|
||||
boost::asio::io_service m_IOService;
|
||||
boost::shared_ptr<boost::asio::ip::tcp::socket> m_Socket;
|
||||
|
||||
void readFromServer();
|
||||
int receive(char * data);
|
||||
void send(Packet & packet);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,37 @@
|
||||
#ifndef TCPServer_h__
|
||||
#define TCPServer_h__
|
||||
|
||||
#include "Server.h"
|
||||
|
||||
class TCPServer : public Server
|
||||
{
|
||||
public:
|
||||
TCPServer();
|
||||
~TCPServer();
|
||||
|
||||
private:
|
||||
// TCP logic
|
||||
boost::asio::ip::udp::endpoint m_ReceiverEndpoint;
|
||||
boost::asio::io_service m_IOService;
|
||||
std::unique_ptr<boost::asio::ip::tcp::acceptor> acceptor;
|
||||
boost::shared_ptr<boost::asio::ip::tcp::socket> lastReceivedSocket;
|
||||
|
||||
void Start(World* world, EventBroker* eventBroker);
|
||||
void readFromClients();
|
||||
void acceptNewConnections();
|
||||
void handle_accept(boost::shared_ptr<boost::asio::ip::tcp::socket> socket, const boost::system::error_code & error);
|
||||
void parseDisconnect();
|
||||
void parseConnect(Packet & packet);
|
||||
///// Implement method to get which player it was
|
||||
void parseClientPing();
|
||||
void parsePing();
|
||||
void parseOnInputCommand(Packet & packet);
|
||||
void parsePlayerTransform(Packet & packet);
|
||||
/////////////////////////
|
||||
void send(Packet & packet, PlayerDefinition & playerDefinition);
|
||||
void send(Packet & packet);
|
||||
int receive(char * data, boost::asio::ip::tcp::socket& socket);
|
||||
PlayerID GetPlayerIDFromEndpoint(boost::asio::ip::udp::endpoint endpoint);
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user