Merge remote-tracking branch 'origin/Networking' into Networking
# Conflicts: # include/Engine/Network/Packet.h # src/Engine/Network/Packet.cpp
This commit is contained in:
@@ -25,7 +25,7 @@ public:
|
||||
void Update();
|
||||
void Close();
|
||||
private:
|
||||
// UDP logic
|
||||
// Assio UDP logic
|
||||
boost::asio::ip::udp::endpoint m_ReceiverEndpoint;
|
||||
boost::asio::io_service m_IOService;
|
||||
boost::asio::ip::udp::socket m_Socket;
|
||||
@@ -52,30 +52,29 @@ private:
|
||||
// if game is turned of by closing window.
|
||||
bool m_WasStarted = false;
|
||||
|
||||
// Private member functions
|
||||
void readFromServer();
|
||||
void sendSnapshotToServer();
|
||||
int receive(char* data, size_t length);
|
||||
void send(Packet& packet);
|
||||
void connect();
|
||||
void disconnect();
|
||||
void ping();
|
||||
void moveMessageHead(char*& data, size_t& length, size_t stepSize);
|
||||
void parseMessageType(Packet& packet);
|
||||
void parseEventMessage(Packet& packet);
|
||||
void parseConnect(Packet& packet);
|
||||
void parsePing();
|
||||
void parseServerPing();
|
||||
void parseSnapshot(Packet& packet);
|
||||
void createNewPlayer(int i);
|
||||
void identifyPacketLoss();
|
||||
bool isConnected();
|
||||
|
||||
// Events
|
||||
EventBroker* m_EventBroker;
|
||||
EventRelay<Client, Events::InputCommand> m_EInputCommand;
|
||||
bool OnInputCommand(const Events::InputCommand &e);
|
||||
|
||||
void ReadFromServer();
|
||||
void SendSnapshotToServer();
|
||||
|
||||
int Receive(char* data, size_t length);
|
||||
void Send(Package& message);
|
||||
void Connect();
|
||||
void Disconnect();
|
||||
void Ping();
|
||||
void MoveMessageHead(char*& data, size_t& length, size_t stepSize);
|
||||
void ParseMessageType(Package& package);
|
||||
void ParseEventMessage(Package& package);
|
||||
void ParseConnect(Package& package);
|
||||
void ParsePing();
|
||||
void ParseServerPing();
|
||||
void ParseSnapshot(Package& package);
|
||||
void CreateNewPlayer(int i);
|
||||
void IdentifyPacketLoss();
|
||||
bool IsConnected();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "Core/World.h"
|
||||
#include "Core/EventBroker.h"
|
||||
#include "Network/Package.h"
|
||||
#include "Network/Packet.h"
|
||||
|
||||
class Network
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <boost/asio/ip/udp.hpp>
|
||||
#include <queue>
|
||||
#include "Network/Package.h"
|
||||
#include "Network/Packet.h"
|
||||
|
||||
|
||||
#define BOARDSIZE 16
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
#ifndef Package_h__
|
||||
#define Package_h__
|
||||
#ifndef Packet_h__
|
||||
#define Packet_h__
|
||||
|
||||
#include <string>
|
||||
#include "Network/MessageType.h"
|
||||
#include "Core/Util/Logging.h"
|
||||
|
||||
// Defines the
|
||||
class Package
|
||||
class Packet
|
||||
{
|
||||
public:
|
||||
// arg1: Type of message (Connect, Disconnect...)
|
||||
// arg2: PackageID for identifying packet loss.
|
||||
Package(MessageType type, unsigned int& packageID);
|
||||
// Used to create package from already existing data buffer.
|
||||
Package(char* data, const int sizeOfPackage);
|
||||
// arg2: PacketID for identifying packet loss.
|
||||
Packet(MessageType type, unsigned int& packetID);
|
||||
// Used to create packet from already existing data buffer.
|
||||
Packet(char* data, const int sizeOfPacket);
|
||||
|
||||
~Package();
|
||||
~Packet();
|
||||
// Add primitive types like int, float, char...
|
||||
template<typename T>
|
||||
void AddPrimitive(T val)
|
||||
void WritePrimitive(T val)
|
||||
{
|
||||
// Check if we are trying to add more than the package can fit.
|
||||
if (m_MaxPacketSize < m_Offset + sizeof(T)) {
|
||||
@@ -29,10 +29,10 @@ public:
|
||||
}
|
||||
// Pops the first element as if it was a primitive.
|
||||
template<typename T>
|
||||
T PopFrontPrimitive()
|
||||
T ReadPrimitive()
|
||||
{
|
||||
if (m_Offset < m_ReturnDataOffset + sizeof(T)) {
|
||||
LOG_WARNING("Packet PopFrontPrimitive(): You are trying to remove more than what exists in this package!");
|
||||
LOG_WARNING("Packet PopFrontPrimitive(): You are trying to remove more than what exists in this packet!");
|
||||
return -1;
|
||||
}
|
||||
T returnValue;
|
||||
@@ -41,12 +41,12 @@ public:
|
||||
return returnValue;
|
||||
}
|
||||
// Add a string to the message
|
||||
void AddString(std::string str);
|
||||
void WriteString(std::string str);
|
||||
// Add data to the message
|
||||
void AddData(char* data, int sizeOfData);
|
||||
void WriteData(char* data, int sizeOfData);
|
||||
// Pops the first element as if it was a string.
|
||||
std::string PopFrontString();
|
||||
char* PopData(int SizeOfData);
|
||||
std::string ReadString();
|
||||
char* ReadData(int SizeOfData);
|
||||
|
||||
int Size() { return m_Offset; };
|
||||
char* Data() { return m_Data; };
|
||||
@@ -47,26 +47,26 @@ private:
|
||||
// Close logic
|
||||
bool m_ThreadIsRunning = true;
|
||||
|
||||
// Network functions
|
||||
int Receive(char* data, size_t length);
|
||||
void ReadFromClients();
|
||||
void Send(Package& package, int playerID);
|
||||
void Send(Package& package);
|
||||
void MoveMessageHead(char*& data, size_t& length, size_t stepSize);
|
||||
void Broadcast(std::string message);
|
||||
void Broadcast(Package& package);
|
||||
void SendSnapshot();
|
||||
void SendPing();
|
||||
void CheckForTimeOuts();
|
||||
void Disconnect(int i);
|
||||
void ParseMessageType(Package& package);
|
||||
void ParseEvent(Package& package);
|
||||
void ParseConnect(Package& package);
|
||||
void ParseDisconnect();
|
||||
void ParseClientPing();
|
||||
void ParseServerPing();
|
||||
void ParseSnapshot(Package& package);
|
||||
void IdentifyPacketLoss();
|
||||
// Private member functions
|
||||
int receive(char* data, size_t length);
|
||||
void readFromClients();
|
||||
void send(Packet& packet, int playerID);
|
||||
void send(Packet& packet);
|
||||
void moveMessageHead(char*& data, size_t& length, size_t stepSize);
|
||||
void broadcast(std::string message);
|
||||
void broadcast(Packet& packet);
|
||||
void sendSnapshot();
|
||||
void sendPing();
|
||||
void checkForTimeOuts();
|
||||
void disconnect(int i);
|
||||
void parseMessageType(Packet& packet);
|
||||
void parseEvent(Packet& packet);
|
||||
void parseConnect(Packet& packet);
|
||||
void parseDisconnect();
|
||||
void parseClientPing();
|
||||
void parseServerPing();
|
||||
void parseSnapshot(Packet& packet);
|
||||
void identifyPacketLoss();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ private:
|
||||
boost::thread m_NetworkThread;
|
||||
|
||||
// Network methods
|
||||
void NetworkFunction();
|
||||
void networkFunction();
|
||||
Network* m_ClientOrServer;
|
||||
bool m_IsClientOrServer = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user