Commit current work
This is a temporary branch because I'm missing a USB drive, huehue
This commit is contained in:
121
include/Nazara/Network/ENetHost.hpp
Normal file
121
include/Nazara/Network/ENetHost.hpp
Normal file
@@ -0,0 +1,121 @@
|
||||
// Copyright (C) 2017 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Network module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_ENETHOST_HPP
|
||||
#define NAZARA_ENETHOST_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Bitset.hpp>
|
||||
#include <Nazara/Core/Clock.hpp>
|
||||
#include <Nazara/Core/MemoryPool.hpp>
|
||||
#include <Nazara/Network/ENetHost.hpp>
|
||||
#include <Nazara/Network/ENetProtocol.hpp>
|
||||
#include <Nazara/Network/IpAddress.hpp>
|
||||
#include <Nazara/Network/NetPacket.hpp>
|
||||
#include <Nazara/Network/SocketPoller.hpp>
|
||||
#include <Nazara/Network/UdpSocket.hpp>
|
||||
#include <deque>
|
||||
#include <queue>
|
||||
#include <random>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class ENetPeer;
|
||||
|
||||
class NAZARA_NETWORK_API ENetHost
|
||||
{
|
||||
friend ENetPeer;
|
||||
friend class Network;
|
||||
|
||||
public:
|
||||
inline ENetHost();
|
||||
ENetHost(const ENetHost&) = delete;
|
||||
ENetHost(ENetHost&&) = default;
|
||||
inline ~ENetHost();
|
||||
|
||||
void Broadcast(UInt8 channelId, ENetPacketFlags flags, NetPacket&& packet);
|
||||
|
||||
bool Connect(const IpAddress& remoteAddress, std::size_t channelCount = 0, UInt32 data = 0);
|
||||
bool Connect(const String& hostName, NetProtocol protocol = NetProtocol_Any, const String& service = "http", ResolveError* error = nullptr, std::size_t channelCount = 0, UInt32 data = 0);
|
||||
|
||||
inline bool Create(NetProtocol protocol, UInt16 port, std::size_t peerCount, std::size_t channelCount = 0);
|
||||
bool Create(const IpAddress& address, std::size_t peerCount, std::size_t channelCount = 0);
|
||||
bool Create(const IpAddress& address, std::size_t peerCount, std::size_t channelCount, UInt32 incomingBandwidth, UInt32 outgoingBandwidth);
|
||||
void Destroy();
|
||||
|
||||
void Flush();
|
||||
|
||||
int Service(ENetEvent* event, UInt32 timeout);
|
||||
|
||||
ENetHost& operator=(const ENetHost&) = delete;
|
||||
ENetHost& operator=(ENetHost&&) = default;
|
||||
|
||||
private:
|
||||
bool InitSocket(const IpAddress& address);
|
||||
|
||||
inline void AddToDispatchQueue(ENetPeer* peer);
|
||||
inline void RemoveFromDispatchQueue(ENetPeer* peer);
|
||||
|
||||
bool DispatchIncomingCommands(ENetEvent* event);
|
||||
|
||||
ENetPeer* HandleConnect(ENetProtocolHeader* header, ENetProtocol* command);
|
||||
bool HandleIncomingCommands(ENetEvent* event);
|
||||
bool HandleSendReliable(ENetPeer& peer, const ENetProtocol& command, UInt8** currentData);
|
||||
|
||||
int ReceiveIncomingCommands(ENetEvent* event);
|
||||
|
||||
void NotifyConnect(ENetPeer* peer, ENetEvent* event);
|
||||
void NotifyDisconnect(ENetPeer*, ENetEvent* event);
|
||||
|
||||
void ThrottleBandwidth();
|
||||
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
std::array<ENetProtocol, ENetConstants::ENetProtocol_MaximumPacketCommands> m_commands;
|
||||
std::array<UInt8, ENetConstants::ENetProtocol_MaximumMTU> m_packetData[2];
|
||||
std::bernoulli_distribution m_packetLossProbability;
|
||||
std::size_t m_bandwidthLimitedPeers;
|
||||
std::size_t m_bufferCount;
|
||||
std::size_t m_channelLimit;
|
||||
std::size_t m_commandCount;
|
||||
std::size_t m_duplicatePeers;
|
||||
std::size_t m_maximumPacketSize;
|
||||
std::size_t m_maximumWaitingData;
|
||||
std::size_t m_receivedDataLength;
|
||||
std::vector<ENetPeer> m_peers;
|
||||
Bitset<UInt64> m_dispatchQueue;
|
||||
MemoryPool m_packetPool;
|
||||
IpAddress m_address;
|
||||
IpAddress m_receivedAddress;
|
||||
SocketPoller m_poller;
|
||||
UdpSocket m_socket;
|
||||
UInt32 m_bandwidthThrottleEpoch;
|
||||
UInt32 m_connectedPeers;
|
||||
UInt32 m_mtu;
|
||||
UInt32 m_randomSeed;
|
||||
UInt32 m_incomingBandwidth;
|
||||
UInt32 m_outgoingBandwidth;
|
||||
UInt32 m_serviceTime;
|
||||
UInt32 m_totalSentData;
|
||||
UInt32 m_totalSentPackets;
|
||||
UInt32 m_totalReceivedData;
|
||||
UInt32 m_totalReceivedPackets;
|
||||
UInt8* m_receivedData;
|
||||
bool m_isSimulationEnabled;
|
||||
bool m_shouldAcceptConnections;
|
||||
bool m_recalculateBandwidthLimits;
|
||||
|
||||
static std::mt19937 s_randomGenerator;
|
||||
static std::mt19937_64 s_randomGenerator64;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Network/ENetHost.inl>
|
||||
|
||||
#endif // NAZARA_RUDPSERVER_HPP
|
||||
65
include/Nazara/Network/ENetHost.inl
Normal file
65
include/Nazara/Network/ENetHost.inl
Normal file
@@ -0,0 +1,65 @@
|
||||
// Copyright (C) 2017 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Network module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Network/ENetHost.hpp>
|
||||
#include <utility>
|
||||
#include <Nazara/Network/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline ENetHost::ENetHost() :
|
||||
m_packetPool(sizeof(ENetPacket))
|
||||
{
|
||||
}
|
||||
|
||||
inline ENetHost::~ENetHost()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
inline bool ENetHost::Create(NetProtocol protocol, UInt16 port, std::size_t peerCount, std::size_t channelCount)
|
||||
{
|
||||
NazaraAssert(protocol != NetProtocol_Any, "Any protocol not supported for Listen"); //< TODO
|
||||
NazaraAssert(protocol != NetProtocol_Unknown, "Invalid protocol");
|
||||
|
||||
IpAddress any;
|
||||
switch (protocol)
|
||||
{
|
||||
case NetProtocol_Any:
|
||||
case NetProtocol_Unknown:
|
||||
NazaraInternalError("Invalid protocol Any at this point");
|
||||
return false;
|
||||
|
||||
case NetProtocol_IPv4:
|
||||
any = IpAddress::AnyIpV4;
|
||||
break;
|
||||
|
||||
case NetProtocol_IPv6:
|
||||
any = IpAddress::AnyIpV6;
|
||||
break;
|
||||
}
|
||||
|
||||
any.SetPort(port);
|
||||
return Create(any, peerCount, channelCount);
|
||||
}
|
||||
|
||||
inline void ENetHost::Destroy()
|
||||
{
|
||||
m_poller.Clear();
|
||||
m_peers.clear();
|
||||
m_socket.Close();
|
||||
}
|
||||
|
||||
inline void ENetHost::AddToDispatchQueue(ENetPeer* peer)
|
||||
{
|
||||
m_dispatchQueue.UnboundedSet(peer->m_incomingPeerID);
|
||||
}
|
||||
|
||||
inline void ENetHost::RemoveFromDispatchQueue(ENetPeer* peer)
|
||||
{
|
||||
m_dispatchQueue.UnboundedReset(peer->m_incomingPeerID);
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Network/DebugOff.hpp>
|
||||
78
include/Nazara/Network/ENetPacket.hpp
Normal file
78
include/Nazara/Network/ENetPacket.hpp
Normal file
@@ -0,0 +1,78 @@
|
||||
// Copyright (C) 2017 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Network module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_ENETPACKET_HPP
|
||||
#define NAZARA_ENETPACKET_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Network/NetPacket.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
enum ENetPacketFlag
|
||||
{
|
||||
ENetPacketFlag_NoAllocate,
|
||||
ENetPacketFlag_Reliable,
|
||||
ENetPacketFlag_Unsequenced,
|
||||
ENetPacketFlag_UnreliableFragment,
|
||||
ENetPacketFlag_Sent
|
||||
};
|
||||
|
||||
template<>
|
||||
struct EnumAsFlags<ENetPacketFlag>
|
||||
{
|
||||
static constexpr bool value = true;
|
||||
static constexpr int max = ENetPacketFlag_Sent;
|
||||
};
|
||||
|
||||
using ENetPacketFlags = Flags<ENetPacketFlag>;
|
||||
|
||||
class MemoryPool;
|
||||
|
||||
struct ENetPacket
|
||||
{
|
||||
MemoryPool* owner;
|
||||
ENetPacketFlags flags;
|
||||
NetPacket data;
|
||||
std::size_t referenceCount = 0;
|
||||
};
|
||||
|
||||
struct ENetPacketRef
|
||||
{
|
||||
ENetPacketRef() = default;
|
||||
|
||||
ENetPacketRef(ENetPacket* packet)
|
||||
{
|
||||
Reset(packet);
|
||||
}
|
||||
|
||||
~ENetPacketRef()
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
void Reset(ENetPacket* packet = nullptr);
|
||||
|
||||
operator ENetPacket*() const
|
||||
{
|
||||
return m_packet;
|
||||
}
|
||||
|
||||
ENetPacket* operator->() const
|
||||
{
|
||||
return m_packet;
|
||||
}
|
||||
|
||||
ENetPacketRef& operator=(ENetPacket* packet)
|
||||
{
|
||||
Reset(packet);
|
||||
}
|
||||
|
||||
ENetPacket* m_packet = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_ENETPACKET_HPP
|
||||
205
include/Nazara/Network/ENetPeer.hpp
Normal file
205
include/Nazara/Network/ENetPeer.hpp
Normal file
@@ -0,0 +1,205 @@
|
||||
// Copyright (C) 2017 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Network module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_ENETPEER_HPP
|
||||
#define NAZARA_ENETPEER_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Bitset.hpp>
|
||||
#include <Nazara/Core/Clock.hpp>
|
||||
#include <Nazara/Core/MemoryPool.hpp>
|
||||
#include <Nazara/Network/ENetPacket.hpp>
|
||||
#include <Nazara/Network/ENetProtocol.hpp>
|
||||
#include <Nazara/Network/IpAddress.hpp>
|
||||
#include <Nazara/Network/NetPacket.hpp>
|
||||
#include <Nazara/Network/UdpSocket.hpp>
|
||||
#include <deque>
|
||||
#include <queue>
|
||||
#include <random>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class ENetHost;
|
||||
|
||||
class NAZARA_NETWORK_API ENetPeer
|
||||
{
|
||||
friend ENetHost;
|
||||
friend struct PacketRef;
|
||||
|
||||
public:
|
||||
ENetPeer(const ENetPeer&) = delete;
|
||||
ENetPeer(ENetPeer&&) = default;
|
||||
~ENetPeer() = default;
|
||||
|
||||
void Disconnect(UInt32 data);
|
||||
void DisconnectLater(UInt32 data);
|
||||
void DisconnectNow(UInt32 data);
|
||||
|
||||
void Ping();
|
||||
|
||||
bool Receive(ENetPacketRef* packet, UInt8* channelId);
|
||||
void Reset();
|
||||
|
||||
bool Send(UInt8 channelId, ENetPacketRef packetRef);
|
||||
bool Send(UInt8 channelId, ENetPacketFlags flags, NetPacket&& packet);
|
||||
|
||||
void ThrottleConfigure(UInt32 interval, UInt32 acceleration, UInt32 deceleration);
|
||||
|
||||
ENetPeer& operator=(const ENetPeer&) = delete;
|
||||
ENetPeer& operator=(ENetPeer&&) = default;
|
||||
|
||||
private:
|
||||
ENetPeer(ENetHost* host, UInt16 peerId);
|
||||
|
||||
void InitIncoming(std::size_t channelCount, const IpAddress& address, ENetProtocolConnect& incomingCommand);
|
||||
void InitOutgoing(std::size_t channelCount, const IpAddress& address, UInt32 connectId, UInt32 windowSize);
|
||||
|
||||
struct Acknowledgement;
|
||||
struct Channel;
|
||||
struct IncomingCommmand;
|
||||
struct OutgoingCommand;
|
||||
|
||||
// Protocol functions
|
||||
inline void ChangeState(ENetPeerState state);
|
||||
inline void DispatchState(ENetPeerState state);
|
||||
|
||||
void DispatchIncomingReliableCommands(Channel& channel);
|
||||
void DispatchIncomingUnreliableCommands(Channel& channel);
|
||||
|
||||
void OnConnect();
|
||||
void OnDisconnect();
|
||||
|
||||
ENetProtocolCommand RemoveSentReliableCommands(UInt16 reliableSequenceNumber, UInt8 channelId);
|
||||
void RemoveSentUnreliableCommands();
|
||||
|
||||
void ResetQueues();
|
||||
|
||||
bool QueueAcknowledgement(ENetProtocol& command, UInt16 sentTime);
|
||||
IncomingCommmand* QueueIncomingCommand(ENetProtocol& command, const void* data, std::size_t dataLength, UInt32 flags, UInt32 fragmentCount);
|
||||
void QueueOutgoingCommand(ENetProtocol& command, ENetPacketRef packet, UInt32 offset, UInt16 length);
|
||||
|
||||
void SetupOutgoingCommand(OutgoingCommand& outgoingCommand);
|
||||
|
||||
int Throttle(UInt32 rtt);
|
||||
|
||||
struct Acknowledgement
|
||||
{
|
||||
ENetProtocol command;
|
||||
UInt32 sentTime;
|
||||
};
|
||||
|
||||
struct Channel
|
||||
{
|
||||
Channel()
|
||||
{
|
||||
incomingReliableSequenceNumber = 0;
|
||||
incomingUnreliableSequenceNumber = 0;
|
||||
outgoingReliableSequenceNumber = 0;
|
||||
outgoingUnreliableSequenceNumber = 0;
|
||||
usedReliableWindows = 0;
|
||||
reliableWindows.fill(0);
|
||||
}
|
||||
|
||||
std::array<UInt16, ENetPeer_ReliableWindows> reliableWindows;
|
||||
std::list<IncomingCommmand> incomingReliableCommands;
|
||||
std::list<IncomingCommmand> incomingUnreliableCommands;
|
||||
UInt16 incomingReliableSequenceNumber;
|
||||
UInt16 incomingUnreliableSequenceNumber;
|
||||
UInt16 outgoingReliableSequenceNumber;
|
||||
UInt16 outgoingUnreliableSequenceNumber;
|
||||
UInt16 usedReliableWindows;
|
||||
};
|
||||
|
||||
struct IncomingCommmand
|
||||
{
|
||||
ENetProtocol command;
|
||||
UInt16 reliableSequenceNumber;
|
||||
UInt16 unreliableSequenceNumber;
|
||||
UInt32 fragmentsRemaining;
|
||||
std::vector<UInt32> fragments;
|
||||
ENetPacketRef packet;
|
||||
};
|
||||
|
||||
struct OutgoingCommand
|
||||
{
|
||||
ENetProtocol command;
|
||||
ENetPacketRef packet;
|
||||
UInt16 fragmentLength;
|
||||
UInt16 reliableSequenceNumber;
|
||||
UInt16 sendAttempts;
|
||||
UInt16 unreliableSequenceNumber;
|
||||
UInt32 fragmentOffset;
|
||||
UInt32 roundTripTimeout;
|
||||
UInt32 roundTripTimeoutLimit;
|
||||
UInt32 sentTime;
|
||||
};
|
||||
|
||||
ENetHost* m_host;
|
||||
IpAddress m_address; /**< Internet address of the peer */
|
||||
std::vector<Channel> m_channels;
|
||||
std::list<Acknowledgement> m_acknowledgements;
|
||||
std::list<IncomingCommmand> m_dispatchedCommands;
|
||||
std::list<OutgoingCommand> m_outgoingReliableCommands;
|
||||
std::list<OutgoingCommand> m_outgoingUnreliableCommands;
|
||||
std::list<OutgoingCommand> m_sentReliableCommands;
|
||||
std::list<OutgoingCommand> m_sentUnreliableCommands;
|
||||
MemoryPool m_packetPool;
|
||||
//ENetListNode m_dispatchList;
|
||||
ENetPeerState m_state;
|
||||
UInt8 m_incomingSessionID;
|
||||
UInt8 m_outgoingSessionID;
|
||||
UInt16 m_incomingPeerID;
|
||||
UInt16 m_incomingUnsequencedGroup;
|
||||
UInt16 m_outgoingPeerID;
|
||||
UInt16 m_outgoingReliableSequenceNumber;
|
||||
UInt16 m_outgoingUnsequencedGroup;
|
||||
UInt32 m_connectID;
|
||||
UInt32 m_earliestTimeout;
|
||||
UInt32 m_eventData;
|
||||
UInt32 m_highestRoundTripTimeVariance;
|
||||
UInt32 m_incomingBandwidth; /**< Downstream bandwidth of the client in bytes/second */
|
||||
UInt32 m_incomingBandwidthThrottleEpoch;
|
||||
UInt32 m_incomingDataTotal;
|
||||
UInt32 m_lastReceiveTime;
|
||||
UInt32 m_lastRoundTripTime;
|
||||
UInt32 m_lastRoundTripTimeVariance;
|
||||
UInt32 m_lastSendTime;
|
||||
UInt32 m_lowestRoundTripTime;
|
||||
UInt32 m_mtu;
|
||||
UInt32 m_nextTimeout;
|
||||
UInt32 m_outgoingBandwidth; /**< Upstream bandwidth of the client in bytes/second */
|
||||
UInt32 m_outgoingBandwidthThrottleEpoch;
|
||||
UInt32 m_outgoingDataTotal;
|
||||
UInt32 m_packetLoss; /**< mean packet loss of reliable packets as a ratio with respect to the constant ENET_PEER_PACKET_LOSS_SCALE */
|
||||
UInt32 m_packetLossEpoch;
|
||||
UInt32 m_packetLossVariance;
|
||||
UInt32 m_packetThrottle;
|
||||
UInt32 m_packetThrottleAcceleration;
|
||||
UInt32 m_packetThrottleCounter;
|
||||
UInt32 m_packetThrottleDeceleration;
|
||||
UInt32 m_packetThrottleEpoch;
|
||||
UInt32 m_packetThrottleInterval;
|
||||
UInt32 m_packetThrottleLimit;
|
||||
UInt32 m_packetsLost;
|
||||
UInt32 m_packetsSent;
|
||||
UInt32 m_pingInterval;
|
||||
UInt32 m_reliableDataInTransit;
|
||||
UInt32 m_roundTripTime; /**< mean round trip time (RTT), in milliseconds, between sending a reliable packet and receiving its acknowledgment */
|
||||
UInt32 m_roundTripTimeVariance;
|
||||
UInt32 m_timeoutLimit;
|
||||
UInt32 m_timeoutMaximum;
|
||||
UInt32 m_timeoutMinimum;
|
||||
UInt32 m_unsequencedWindow[ENetPeer_ReliableWindowSize / 32];
|
||||
UInt32 m_windowSize;
|
||||
std::size_t m_totalWaitingData;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Network/ENetPeer.inl>
|
||||
|
||||
#endif // NAZARA_ENETPEER_HPP
|
||||
29
include/Nazara/Network/ENetPeer.inl
Normal file
29
include/Nazara/Network/ENetPeer.inl
Normal file
@@ -0,0 +1,29 @@
|
||||
// Copyright (C) 2017 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Network module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Network/ENetPeer.hpp>
|
||||
#include <utility>
|
||||
#include <Nazara/Network/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline void ENetPeer::ChangeState(ENetPeerState state)
|
||||
{
|
||||
if (state == ENetPeerState::Connected || state == ENetPeerState::DisconnectLater)
|
||||
OnConnect();
|
||||
else
|
||||
OnDisconnect();
|
||||
|
||||
m_state = state;
|
||||
}
|
||||
|
||||
inline void ENetPeer::DispatchState(ENetPeerState state)
|
||||
{
|
||||
ChangeState(state);
|
||||
|
||||
m_host->AddToDispatchQueue(this);
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Network/DebugOff.hpp>
|
||||
272
include/Nazara/Network/ENetProtocol.hpp
Normal file
272
include/Nazara/Network/ENetProtocol.hpp
Normal file
@@ -0,0 +1,272 @@
|
||||
// Copyright (C) 2017 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Network module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_ENETPROTOCOL_HPP
|
||||
#define NAZARA_ENETPROTOCOL_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Network/ENetPacket.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
// Constants for the ENet implementation and protocol
|
||||
enum ENetConstants
|
||||
{
|
||||
ENetHost_BandwidthThrottleInterval = 1000,
|
||||
ENetHost_DefaultMaximumPacketSize = 32 * 1024 * 1024,
|
||||
ENetHost_DefaultMaximumWaitingData = 32 * 1024 * 1024,
|
||||
ENetHost_DefaultMTU = 1400,
|
||||
ENetHost_ReceiveBufferSize = 256 * 1024,
|
||||
ENetHost_SendBufferSize = 256 * 1024,
|
||||
|
||||
ENetPeer_DefaultPacketThrottle = 32,
|
||||
ENetPeer_DefaultRoundTripTime = 500,
|
||||
ENetPeer_FreeReliableWindows = 8,
|
||||
ENetPeer_FreeUnsequencedWindows = 32,
|
||||
ENetPeer_PacketLossInterval = 10000,
|
||||
ENetPeer_PacketLossScale = (1 << 16),
|
||||
ENetPeer_PacketThrottleAcceleration = 2,
|
||||
ENetPeer_PacketThrottleCounter = 7,
|
||||
ENetPeer_PacketThrottleDeceleration = 2,
|
||||
ENetPeer_PacketThrottleInterval = 5000,
|
||||
ENetPeer_PacketThrottleScale = 32,
|
||||
ENetPeer_PingInterval = 500,
|
||||
ENetPeer_ReliableWindows = 16,
|
||||
ENetPeer_ReliableWindowSize = 0x1000,
|
||||
ENetPeer_TimeoutLimit = 32,
|
||||
ENetPeer_TimeoutMaximum = 30000,
|
||||
ENetPeer_TimeoutMinimum = 5000,
|
||||
ENetPeer_UnsequencedWindows = 64,
|
||||
ENetPeer_UnsequencedWindowSize = 1024,
|
||||
ENetPeer_WindowSizeScale = 64 * 1024,
|
||||
|
||||
ENetProtocol_MaximumChannelCount = 255,
|
||||
ENetProtocol_MaximumFragmentCount = 1024 * 1024,
|
||||
ENetProtocol_MaximumMTU = 4096,
|
||||
ENetProtocol_MaximumPacketCommands = 32,
|
||||
ENetProtocol_MaximumPeerId = 0xFFF,
|
||||
ENetProtocol_MaximumWindowSize = 65536,
|
||||
ENetProtocol_MinimumChannelCount = 1,
|
||||
ENetProtocol_MinimumMTU = 576,
|
||||
ENetProtocol_MinimumWindowSize = 4096
|
||||
};
|
||||
|
||||
enum class ENetPeerState
|
||||
{
|
||||
AcknowledgingConnect = 2,
|
||||
AcknowledgingDisconnect = 8,
|
||||
Connecting = 1,
|
||||
ConnectionPending = 3,
|
||||
ConnectionSucceeded = 4,
|
||||
Connected = 5,
|
||||
Disconnected = 0,
|
||||
Disconnecting = 7,
|
||||
DisconnectLater = 6,
|
||||
Zombie = 9
|
||||
};
|
||||
|
||||
enum ENetProtocolCommand
|
||||
{
|
||||
// Keeping the values is important for compatibility with the native ENet protocol
|
||||
ENetProtocolCommand_Acknowledge = 1,
|
||||
ENetProtocolCommand_BandwidthLimit = 10,
|
||||
ENetProtocolCommand_Connect = 2,
|
||||
ENetProtocolCommand_Disconnect = 4,
|
||||
ENetProtocolCommand_None = 0,
|
||||
ENetProtocolCommand_Ping = 5,
|
||||
ENetProtocolCommand_SendFragment = 8,
|
||||
ENetProtocolCommand_SendReliable = 6,
|
||||
ENetProtocolCommand_SendUnreliable = 7,
|
||||
ENetProtocolCommand_SendUnreliableFragment = 12,
|
||||
ENetProtocolCommand_SendUnsequenced = 9,
|
||||
ENetProtocolCommand_ThrottleConfigure = 11,
|
||||
ENetProtocolCommand_VerifyConnect = 3,
|
||||
ENetProtocolCommand_Count = 13,
|
||||
|
||||
ENetProtocolCommand_Mask = 0x0F
|
||||
};
|
||||
|
||||
enum ENetProtocolFlag
|
||||
{
|
||||
ENetProtocolFlag_Acknowledge = (1 << 7),
|
||||
ENetProtocolFlag_Unsequenced = (1 << 6),
|
||||
|
||||
ENetProtocolHeaderFlag_Compressed = (1 << 14),
|
||||
ENetProtocolHeaderFlag_SentTime = (1 << 15),
|
||||
ENetProtocolHeaderFlag_Mask = ENetProtocolHeaderFlag_Compressed | ENetProtocolHeaderFlag_SentTime,
|
||||
|
||||
ENetProtocolHeaderSessionMask = (3 << 12),
|
||||
ENetProtocolHeaderSessionShift = 12
|
||||
};
|
||||
|
||||
enum class ENetEventType
|
||||
{
|
||||
/** no event occurred within the specified time limit */
|
||||
None,
|
||||
|
||||
/** a connection request initiated by enet_host_connect has completed.
|
||||
* The peer field contains the peer which successfully connected.
|
||||
*/
|
||||
Connect,
|
||||
|
||||
/** a peer has disconnected. This event is generated on a successful
|
||||
* completion of a disconnect initiated by enet_peer_disconnect, if
|
||||
* a peer has timed out, or if a connection request initialized by
|
||||
* enet_host_connect has timed out. The peer field contains the peer
|
||||
* which disconnected. The data field contains user supplied data
|
||||
* describing the disconnection, or 0, if none is available.
|
||||
*/
|
||||
Disconnect,
|
||||
|
||||
/** a packet has been received from a peer. The peer field specifies the
|
||||
* peer which sent the packet. The channelID field specifies the channel
|
||||
* number upon which the packet was received. The packet field contains
|
||||
* the packet that was received; this packet must be destroyed with
|
||||
* enet_packet_destroy after use.
|
||||
*/
|
||||
Receive
|
||||
};
|
||||
|
||||
struct ENetEvent
|
||||
{
|
||||
ENetEventType type;
|
||||
ENetPeer* peer;
|
||||
UInt8 channelId;
|
||||
UInt32 data;
|
||||
ENetPacketRef packet;
|
||||
};
|
||||
|
||||
struct ENetProtocolHeader
|
||||
{
|
||||
UInt16 peerID;
|
||||
UInt16 sentTime;
|
||||
};
|
||||
|
||||
struct ENetProtocolCommandHeader
|
||||
{
|
||||
UInt8 command;
|
||||
UInt8 channelID;
|
||||
UInt16 reliableSequenceNumber;
|
||||
};
|
||||
|
||||
struct ENetProtocolAcknowledge
|
||||
{
|
||||
ENetProtocolCommandHeader header;
|
||||
UInt16 receivedReliableSequenceNumber;
|
||||
UInt16 receivedSentTime;
|
||||
};
|
||||
|
||||
struct ENetProtocolConnect
|
||||
{
|
||||
ENetProtocolCommandHeader header;
|
||||
UInt16 outgoingPeerID;
|
||||
UInt8 incomingSessionID;
|
||||
UInt8 outgoingSessionID;
|
||||
UInt32 mtu;
|
||||
UInt32 windowSize;
|
||||
UInt32 channelCount;
|
||||
UInt32 incomingBandwidth;
|
||||
UInt32 outgoingBandwidth;
|
||||
UInt32 packetThrottleInterval;
|
||||
UInt32 packetThrottleAcceleration;
|
||||
UInt32 packetThrottleDeceleration;
|
||||
UInt32 connectID;
|
||||
UInt32 data;
|
||||
};
|
||||
|
||||
struct ENetProtocolBandwidthLimit
|
||||
{
|
||||
ENetProtocolCommandHeader header;
|
||||
UInt32 incomingBandwidth;
|
||||
UInt32 outgoingBandwidth;
|
||||
};
|
||||
|
||||
struct ENetProtocolDisconnect
|
||||
{
|
||||
ENetProtocolCommandHeader header;
|
||||
UInt32 data;
|
||||
};
|
||||
|
||||
struct ENetProtocolPing
|
||||
{
|
||||
ENetProtocolCommandHeader header;
|
||||
};
|
||||
|
||||
struct ENetProtocolSendFragment
|
||||
{
|
||||
ENetProtocolCommandHeader header;
|
||||
UInt16 startSequenceNumber;
|
||||
UInt16 dataLength;
|
||||
UInt32 fragmentCount;
|
||||
UInt32 fragmentNumber;
|
||||
UInt32 totalLength;
|
||||
UInt32 fragmentOffset;
|
||||
};
|
||||
|
||||
struct ENetProtocolSendReliable
|
||||
{
|
||||
ENetProtocolCommandHeader header;
|
||||
UInt16 dataLength;
|
||||
};
|
||||
|
||||
struct ENetProtocolSendUnreliable
|
||||
{
|
||||
ENetProtocolCommandHeader header;
|
||||
UInt16 unreliableSequenceNumber;
|
||||
UInt16 dataLength;
|
||||
};
|
||||
|
||||
struct ENetProtocolSendUnsequenced
|
||||
{
|
||||
ENetProtocolCommandHeader header;
|
||||
UInt16 unsequencedGroup;
|
||||
UInt16 dataLength;
|
||||
};
|
||||
|
||||
struct ENetProtocolThrottleConfigure
|
||||
{
|
||||
ENetProtocolCommandHeader header;
|
||||
UInt32 packetThrottleInterval;
|
||||
UInt32 packetThrottleAcceleration;
|
||||
UInt32 packetThrottleDeceleration;
|
||||
};
|
||||
|
||||
struct ENetProtocolVerifyConnect
|
||||
{
|
||||
ENetProtocolCommandHeader header;
|
||||
UInt16 outgoingPeerID;
|
||||
UInt8 incomingSessionID;
|
||||
UInt8 outgoingSessionID;
|
||||
UInt32 mtu;
|
||||
UInt32 windowSize;
|
||||
UInt32 channelCount;
|
||||
UInt32 incomingBandwidth;
|
||||
UInt32 outgoingBandwidth;
|
||||
UInt32 packetThrottleInterval;
|
||||
UInt32 packetThrottleAcceleration;
|
||||
UInt32 packetThrottleDeceleration;
|
||||
UInt32 connectID;
|
||||
};
|
||||
|
||||
union ENetProtocol
|
||||
{
|
||||
ENetProtocolCommandHeader header;
|
||||
ENetProtocolAcknowledge acknowledge;
|
||||
ENetProtocolBandwidthLimit bandwidthLimit;
|
||||
ENetProtocolConnect connect;
|
||||
ENetProtocolDisconnect disconnect;
|
||||
ENetProtocolPing ping;
|
||||
ENetProtocolSendReliable sendReliable;
|
||||
ENetProtocolSendUnreliable sendUnreliable;
|
||||
ENetProtocolSendUnsequenced sendUnsequenced;
|
||||
ENetProtocolSendFragment sendFragment;
|
||||
ENetProtocolThrottleConfigure throttleConfigure;
|
||||
ENetProtocolVerifyConnect verifyConnect;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_ENETPROTOCOL_HPP
|
||||
Reference in New Issue
Block a user