Commit current work
This is a temporary branch because I'm missing a USB drive, huehue
This commit is contained in:
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