mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-07-01 23:46:59 +00:00
TCP RUDP Proxy Complete
This commit is contained in:
parent
f37808e84f
commit
8f42e319f4
534
enet.h
534
enet.h
@ -63,81 +63,81 @@
|
||||
// =======================================================================//
|
||||
|
||||
#if defined(_WIN32)
|
||||
#if defined(_MSC_VER) && defined(ENET_IMPLEMENTATION)
|
||||
#pragma warning (disable: 4267) // size_t to int conversion
|
||||
#if defined(_MSC_VER) && defined(ENET_IMPLEMENTATION)
|
||||
#pragma warning (disable: 4267) // size_t to int conversion
|
||||
#pragma warning (disable: 4244) // 64bit to 32bit int
|
||||
#pragma warning (disable: 4018) // signed/unsigned mismatch
|
||||
#pragma warning (disable: 4146) // unary minus operator applied to unsigned type
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ENET_NO_PRAGMA_LINK
|
||||
#pragma comment(lib, "ws2_32.lib")
|
||||
#pragma comment(lib, "winmm.lib")
|
||||
#endif
|
||||
#ifndef ENET_NO_PRAGMA_LINK
|
||||
#pragma comment(lib, "ws2_32.lib")
|
||||
#pragma comment(lib, "winmm.lib")
|
||||
#endif
|
||||
|
||||
#if _MSC_VER >= 1910
|
||||
/* It looks like there were changes as of Visual Studio 2017 and there are no 32/64 bit
|
||||
#if _MSC_VER >= 1910
|
||||
/* It looks like there were changes as of Visual Studio 2017 and there are no 32/64 bit
|
||||
versions of _InterlockedExchange[operation], only InterlockedExchange[operation]
|
||||
(without leading underscore), so we have to distinguish between compiler versions */
|
||||
#define NOT_UNDERSCORED_INTERLOCKED_EXCHANGE
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
#if (_WIN32_WINNT < 0x0501)
|
||||
#undef _WIN32_WINNT
|
||||
#define _WIN32_WINNT 0x0501
|
||||
#endif
|
||||
#endif
|
||||
#ifdef __GNUC__
|
||||
#if (_WIN32_WINNT < 0x0501)
|
||||
#undef _WIN32_WINNT
|
||||
#define _WIN32_WINNT 0x0501
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <WinSock2.h>
|
||||
#include <WS2tcpip.h>
|
||||
#include <mmsystem.h>
|
||||
#include <WinSock2.h>
|
||||
#include <WS2tcpip.h>
|
||||
#include <mmsystem.h>
|
||||
#include <intrin.h>
|
||||
|
||||
|
||||
#if defined(_WIN32) && defined(_MSC_VER)
|
||||
#if _MSC_VER < 1900
|
||||
#if defined(_WIN32) && defined(_MSC_VER)
|
||||
#if _MSC_VER < 1900
|
||||
typedef struct timespec {
|
||||
long tv_sec;
|
||||
long tv_nsec;
|
||||
};
|
||||
#endif
|
||||
#define CLOCK_MONOTONIC 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef SOCKET ENetSocket;
|
||||
#define ENET_SOCKET_NULL INVALID_SOCKET
|
||||
typedef SOCKET ENetSocket;
|
||||
#define ENET_SOCKET_NULL INVALID_SOCKET
|
||||
|
||||
#define ENET_HOST_TO_NET_16(value) (htons(value))
|
||||
#define ENET_HOST_TO_NET_32(value) (htonl(value))
|
||||
#define ENET_HOST_TO_NET_16(value) (htons(value))
|
||||
#define ENET_HOST_TO_NET_32(value) (htonl(value))
|
||||
|
||||
#define ENET_NET_TO_HOST_16(value) (ntohs(value))
|
||||
#define ENET_NET_TO_HOST_32(value) (ntohl(value))
|
||||
#define ENET_NET_TO_HOST_16(value) (ntohs(value))
|
||||
#define ENET_NET_TO_HOST_32(value) (ntohl(value))
|
||||
|
||||
typedef struct {
|
||||
typedef struct {
|
||||
size_t dataLength;
|
||||
void * data;
|
||||
} ENetBuffer;
|
||||
} ENetBuffer;
|
||||
|
||||
#define ENET_CALLBACK __cdecl
|
||||
#define ENET_CALLBACK __cdecl
|
||||
|
||||
#ifdef ENET_DLL
|
||||
#ifdef ENET_IMPLEMENTATION
|
||||
#ifdef ENET_DLL
|
||||
#ifdef ENET_IMPLEMENTATION
|
||||
#define ENET_API __declspec( dllexport )
|
||||
#else
|
||||
#define ENET_API __declspec( dllimport )
|
||||
#endif // ENET_IMPLEMENTATION
|
||||
#else
|
||||
#define ENET_API extern
|
||||
#endif // ENET_DLL
|
||||
#else
|
||||
#define ENET_API extern
|
||||
#endif // ENET_DLL
|
||||
|
||||
typedef fd_set ENetSocketSet;
|
||||
typedef fd_set ENetSocketSet;
|
||||
|
||||
#define ENET_SOCKETSET_EMPTY(sockset) FD_ZERO(&(sockset))
|
||||
#define ENET_SOCKETSET_ADD(sockset, socket) FD_SET(socket, &(sockset))
|
||||
#define ENET_SOCKETSET_REMOVE(sockset, socket) FD_CLR(socket, &(sockset))
|
||||
#define ENET_SOCKETSET_CHECK(sockset, socket) FD_ISSET(socket, &(sockset))
|
||||
#define ENET_SOCKETSET_EMPTY(sockset) FD_ZERO(&(sockset))
|
||||
#define ENET_SOCKETSET_ADD(sockset, socket) FD_SET(socket, &(sockset))
|
||||
#define ENET_SOCKETSET_REMOVE(sockset, socket) FD_CLR(socket, &(sockset))
|
||||
#define ENET_SOCKETSET_CHECK(sockset, socket) FD_ISSET(socket, &(sockset))
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/socket.h>
|
||||
@ -213,21 +213,21 @@ extern "C" {
|
||||
// !
|
||||
// =======================================================================//
|
||||
|
||||
typedef uint8_t enet_uint8; /**< unsigned 8-bit type */
|
||||
typedef uint16_t enet_uint16; /**< unsigned 16-bit type */
|
||||
typedef uint32_t enet_uint32; /**< unsigned 32-bit type */
|
||||
typedef uint64_t enet_uint64; /**< unsigned 64-bit type */
|
||||
typedef uint8_t enet_uint8; /**< unsigned 8-bit type */
|
||||
typedef uint16_t enet_uint16; /**< unsigned 16-bit type */
|
||||
typedef uint32_t enet_uint32; /**< unsigned 32-bit type */
|
||||
typedef uint64_t enet_uint64; /**< unsigned 64-bit type */
|
||||
|
||||
typedef enet_uint32 ENetVersion;
|
||||
typedef enet_uint32 ENetVersion;
|
||||
|
||||
typedef struct _ENetCallbacks {
|
||||
typedef struct _ENetCallbacks {
|
||||
void *(ENET_CALLBACK *malloc) (size_t size);
|
||||
void (ENET_CALLBACK *free) (void *memory);
|
||||
void (ENET_CALLBACK *no_memory) (void);
|
||||
} ENetCallbacks;
|
||||
} ENetCallbacks;
|
||||
|
||||
extern void *enet_malloc(size_t);
|
||||
extern void enet_free(void *);
|
||||
extern void *enet_malloc(size_t);
|
||||
extern void enet_free(void *);
|
||||
|
||||
// =======================================================================//
|
||||
// !
|
||||
@ -235,31 +235,31 @@ extern void enet_free(void *);
|
||||
// !
|
||||
// =======================================================================//
|
||||
|
||||
typedef struct _ENetListNode {
|
||||
typedef struct _ENetListNode {
|
||||
struct _ENetListNode *next;
|
||||
struct _ENetListNode *previous;
|
||||
} ENetListNode;
|
||||
} ENetListNode;
|
||||
|
||||
typedef ENetListNode *ENetListIterator;
|
||||
typedef ENetListNode *ENetListIterator;
|
||||
|
||||
typedef struct _ENetList {
|
||||
typedef struct _ENetList {
|
||||
ENetListNode sentinel;
|
||||
} ENetList;
|
||||
} ENetList;
|
||||
|
||||
extern ENetListIterator enet_list_insert(ENetListIterator, void *);
|
||||
extern ENetListIterator enet_list_move(ENetListIterator, void *, void *);
|
||||
extern ENetListIterator enet_list_insert(ENetListIterator, void *);
|
||||
extern ENetListIterator enet_list_move(ENetListIterator, void *, void *);
|
||||
|
||||
extern void *enet_list_remove(ENetListIterator);
|
||||
extern void enet_list_clear(ENetList *);
|
||||
extern size_t enet_list_size(ENetList *);
|
||||
extern void *enet_list_remove(ENetListIterator);
|
||||
extern void enet_list_clear(ENetList *);
|
||||
extern size_t enet_list_size(ENetList *);
|
||||
|
||||
#define enet_list_begin(list) ((list)->sentinel.next)
|
||||
#define enet_list_end(list) (&(list)->sentinel)
|
||||
#define enet_list_empty(list) (enet_list_begin(list) == enet_list_end(list))
|
||||
#define enet_list_next(iterator) ((iterator)->next)
|
||||
#define enet_list_previous(iterator) ((iterator)->previous)
|
||||
#define enet_list_front(list) ((void *)(list)->sentinel.next)
|
||||
#define enet_list_back(list) ((void *)(list)->sentinel.previous)
|
||||
#define enet_list_begin(list) ((list)->sentinel.next)
|
||||
#define enet_list_end(list) (&(list)->sentinel)
|
||||
#define enet_list_empty(list) (enet_list_begin(list) == enet_list_end(list))
|
||||
#define enet_list_next(iterator) ((iterator)->next)
|
||||
#define enet_list_previous(iterator) ((iterator)->previous)
|
||||
#define enet_list_front(list) ((void *)(list)->sentinel.next)
|
||||
#define enet_list_back(list) ((void *)(list)->sentinel.previous)
|
||||
|
||||
|
||||
// =======================================================================//
|
||||
@ -268,7 +268,7 @@ extern size_t enet_list_size(ENetList *);
|
||||
// !
|
||||
// =======================================================================//
|
||||
|
||||
enum {
|
||||
enum {
|
||||
ENET_PROTOCOL_MINIMUM_MTU = 576,
|
||||
ENET_PROTOCOL_MAXIMUM_MTU = 4096,
|
||||
ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS = 32,
|
||||
@ -278,9 +278,9 @@ enum {
|
||||
ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT = 255,
|
||||
ENET_PROTOCOL_MAXIMUM_PEER_ID = 0xFFF,
|
||||
ENET_PROTOCOL_MAXIMUM_FRAGMENT_COUNT = 1024 * 1024
|
||||
};
|
||||
};
|
||||
|
||||
typedef enum _ENetProtocolCommand {
|
||||
typedef enum _ENetProtocolCommand {
|
||||
ENET_PROTOCOL_COMMAND_NONE = 0,
|
||||
ENET_PROTOCOL_COMMAND_ACKNOWLEDGE = 1,
|
||||
ENET_PROTOCOL_COMMAND_CONNECT = 2,
|
||||
@ -297,9 +297,9 @@ typedef enum _ENetProtocolCommand {
|
||||
ENET_PROTOCOL_COMMAND_COUNT = 13,
|
||||
|
||||
ENET_PROTOCOL_COMMAND_MASK = 0x0F
|
||||
} ENetProtocolCommand;
|
||||
} ENetProtocolCommand;
|
||||
|
||||
typedef enum _ENetProtocolFlag {
|
||||
typedef enum _ENetProtocolFlag {
|
||||
ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE = (1 << 7),
|
||||
ENET_PROTOCOL_COMMAND_FLAG_UNSEQUENCED = (1 << 6),
|
||||
|
||||
@ -309,35 +309,35 @@ typedef enum _ENetProtocolFlag {
|
||||
|
||||
ENET_PROTOCOL_HEADER_SESSION_MASK = (3 << 12),
|
||||
ENET_PROTOCOL_HEADER_SESSION_SHIFT = 12
|
||||
} ENetProtocolFlag;
|
||||
} ENetProtocolFlag;
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma pack(push, 1)
|
||||
#ifdef _MSC_VER
|
||||
#pragma pack(push, 1)
|
||||
#define ENET_PACKED
|
||||
#elif defined(__GNUC__) || defined(__clang__)
|
||||
#define ENET_PACKED __attribute__ ((packed))
|
||||
#else
|
||||
#define ENET_PACKED
|
||||
#endif
|
||||
#elif defined(__GNUC__) || defined(__clang__)
|
||||
#define ENET_PACKED __attribute__ ((packed))
|
||||
#else
|
||||
#define ENET_PACKED
|
||||
#endif
|
||||
|
||||
typedef struct _ENetProtocolHeader {
|
||||
typedef struct _ENetProtocolHeader {
|
||||
enet_uint16 peerID;
|
||||
enet_uint16 sentTime;
|
||||
} ENET_PACKED ENetProtocolHeader;
|
||||
} ENET_PACKED ENetProtocolHeader;
|
||||
|
||||
typedef struct _ENetProtocolCommandHeader {
|
||||
typedef struct _ENetProtocolCommandHeader {
|
||||
enet_uint8 command;
|
||||
enet_uint8 channelID;
|
||||
enet_uint16 reliableSequenceNumber;
|
||||
} ENET_PACKED ENetProtocolCommandHeader;
|
||||
} ENET_PACKED ENetProtocolCommandHeader;
|
||||
|
||||
typedef struct _ENetProtocolAcknowledge {
|
||||
typedef struct _ENetProtocolAcknowledge {
|
||||
ENetProtocolCommandHeader header;
|
||||
enet_uint16 receivedReliableSequenceNumber;
|
||||
enet_uint16 receivedSentTime;
|
||||
} ENET_PACKED ENetProtocolAcknowledge;
|
||||
} ENET_PACKED ENetProtocolAcknowledge;
|
||||
|
||||
typedef struct _ENetProtocolConnect {
|
||||
typedef struct _ENetProtocolConnect {
|
||||
ENetProtocolCommandHeader header;
|
||||
enet_uint16 outgoingPeerID;
|
||||
enet_uint8 incomingSessionID;
|
||||
@ -352,9 +352,9 @@ typedef struct _ENetProtocolConnect {
|
||||
enet_uint32 packetThrottleDeceleration;
|
||||
enet_uint32 connectID;
|
||||
enet_uint32 data;
|
||||
} ENET_PACKED ENetProtocolConnect;
|
||||
} ENET_PACKED ENetProtocolConnect;
|
||||
|
||||
typedef struct _ENetProtocolVerifyConnect {
|
||||
typedef struct _ENetProtocolVerifyConnect {
|
||||
ENetProtocolCommandHeader header;
|
||||
enet_uint16 outgoingPeerID;
|
||||
enet_uint8 incomingSessionID;
|
||||
@ -368,48 +368,48 @@ typedef struct _ENetProtocolVerifyConnect {
|
||||
enet_uint32 packetThrottleAcceleration;
|
||||
enet_uint32 packetThrottleDeceleration;
|
||||
enet_uint32 connectID;
|
||||
} ENET_PACKED ENetProtocolVerifyConnect;
|
||||
} ENET_PACKED ENetProtocolVerifyConnect;
|
||||
|
||||
typedef struct _ENetProtocolBandwidthLimit {
|
||||
typedef struct _ENetProtocolBandwidthLimit {
|
||||
ENetProtocolCommandHeader header;
|
||||
enet_uint32 incomingBandwidth;
|
||||
enet_uint32 outgoingBandwidth;
|
||||
} ENET_PACKED ENetProtocolBandwidthLimit;
|
||||
} ENET_PACKED ENetProtocolBandwidthLimit;
|
||||
|
||||
typedef struct _ENetProtocolThrottleConfigure {
|
||||
typedef struct _ENetProtocolThrottleConfigure {
|
||||
ENetProtocolCommandHeader header;
|
||||
enet_uint32 packetThrottleInterval;
|
||||
enet_uint32 packetThrottleAcceleration;
|
||||
enet_uint32 packetThrottleDeceleration;
|
||||
} ENET_PACKED ENetProtocolThrottleConfigure;
|
||||
} ENET_PACKED ENetProtocolThrottleConfigure;
|
||||
|
||||
typedef struct _ENetProtocolDisconnect {
|
||||
typedef struct _ENetProtocolDisconnect {
|
||||
ENetProtocolCommandHeader header;
|
||||
enet_uint32 data;
|
||||
} ENET_PACKED ENetProtocolDisconnect;
|
||||
} ENET_PACKED ENetProtocolDisconnect;
|
||||
|
||||
typedef struct _ENetProtocolPing {
|
||||
typedef struct _ENetProtocolPing {
|
||||
ENetProtocolCommandHeader header;
|
||||
} ENET_PACKED ENetProtocolPing;
|
||||
} ENET_PACKED ENetProtocolPing;
|
||||
|
||||
typedef struct _ENetProtocolSendReliable {
|
||||
typedef struct _ENetProtocolSendReliable {
|
||||
ENetProtocolCommandHeader header;
|
||||
enet_uint16 dataLength;
|
||||
} ENET_PACKED ENetProtocolSendReliable;
|
||||
} ENET_PACKED ENetProtocolSendReliable;
|
||||
|
||||
typedef struct _ENetProtocolSendUnreliable {
|
||||
typedef struct _ENetProtocolSendUnreliable {
|
||||
ENetProtocolCommandHeader header;
|
||||
enet_uint16 unreliableSequenceNumber;
|
||||
enet_uint16 dataLength;
|
||||
} ENET_PACKED ENetProtocolSendUnreliable;
|
||||
} ENET_PACKED ENetProtocolSendUnreliable;
|
||||
|
||||
typedef struct _ENetProtocolSendUnsequenced {
|
||||
typedef struct _ENetProtocolSendUnsequenced {
|
||||
ENetProtocolCommandHeader header;
|
||||
enet_uint16 unsequencedGroup;
|
||||
enet_uint16 dataLength;
|
||||
} ENET_PACKED ENetProtocolSendUnsequenced;
|
||||
} ENET_PACKED ENetProtocolSendUnsequenced;
|
||||
|
||||
typedef struct _ENetProtocolSendFragment {
|
||||
typedef struct _ENetProtocolSendFragment {
|
||||
ENetProtocolCommandHeader header;
|
||||
enet_uint16 startSequenceNumber;
|
||||
enet_uint16 dataLength;
|
||||
@ -417,9 +417,9 @@ typedef struct _ENetProtocolSendFragment {
|
||||
enet_uint32 fragmentNumber;
|
||||
enet_uint32 totalLength;
|
||||
enet_uint32 fragmentOffset;
|
||||
} ENET_PACKED ENetProtocolSendFragment;
|
||||
} ENET_PACKED ENetProtocolSendFragment;
|
||||
|
||||
typedef union _ENetProtocol {
|
||||
typedef union _ENetProtocol {
|
||||
ENetProtocolCommandHeader header;
|
||||
ENetProtocolAcknowledge acknowledge;
|
||||
ENetProtocolConnect connect;
|
||||
@ -432,11 +432,11 @@ typedef union _ENetProtocol {
|
||||
ENetProtocolSendFragment sendFragment;
|
||||
ENetProtocolBandwidthLimit bandwidthLimit;
|
||||
ENetProtocolThrottleConfigure throttleConfigure;
|
||||
} ENET_PACKED ENetProtocol;
|
||||
} ENET_PACKED ENetProtocol;
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma pack(pop)
|
||||
#endif
|
||||
#ifdef _MSC_VER
|
||||
#pragma pack(pop)
|
||||
#endif
|
||||
|
||||
// =======================================================================//
|
||||
// !
|
||||
@ -444,19 +444,19 @@ typedef union _ENetProtocol {
|
||||
// !
|
||||
// =======================================================================//
|
||||
|
||||
typedef enum _ENetSocketType {
|
||||
typedef enum _ENetSocketType {
|
||||
ENET_SOCKET_TYPE_STREAM = 1,
|
||||
ENET_SOCKET_TYPE_DATAGRAM = 2
|
||||
} ENetSocketType;
|
||||
} ENetSocketType;
|
||||
|
||||
typedef enum _ENetSocketWait {
|
||||
typedef enum _ENetSocketWait {
|
||||
ENET_SOCKET_WAIT_NONE = 0,
|
||||
ENET_SOCKET_WAIT_SEND = (1 << 0),
|
||||
ENET_SOCKET_WAIT_RECEIVE = (1 << 1),
|
||||
ENET_SOCKET_WAIT_INTERRUPT = (1 << 2)
|
||||
} ENetSocketWait;
|
||||
} ENetSocketWait;
|
||||
|
||||
typedef enum _ENetSocketOption {
|
||||
typedef enum _ENetSocketOption {
|
||||
ENET_SOCKOPT_NONBLOCK = 1,
|
||||
ENET_SOCKOPT_BROADCAST = 2,
|
||||
ENET_SOCKOPT_RCVBUF = 3,
|
||||
@ -467,15 +467,15 @@ typedef enum _ENetSocketOption {
|
||||
ENET_SOCKOPT_ERROR = 8,
|
||||
ENET_SOCKOPT_NODELAY = 9,
|
||||
ENET_SOCKOPT_IPV6_V6ONLY = 10,
|
||||
} ENetSocketOption;
|
||||
} ENetSocketOption;
|
||||
|
||||
typedef enum _ENetSocketShutdown {
|
||||
typedef enum _ENetSocketShutdown {
|
||||
ENET_SOCKET_SHUTDOWN_READ = 0,
|
||||
ENET_SOCKET_SHUTDOWN_WRITE = 1,
|
||||
ENET_SOCKET_SHUTDOWN_READ_WRITE = 2
|
||||
} ENetSocketShutdown;
|
||||
} ENetSocketShutdown;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Portable internet address structure.
|
||||
*
|
||||
* The host must be specified in network byte-order, and the port must be in host
|
||||
@ -485,15 +485,15 @@ typedef enum _ENetSocketShutdown {
|
||||
* but not for enet_host_create. Once a server responds to a broadcast, the
|
||||
* address is updated from ENET_HOST_BROADCAST to the server's actual IP address.
|
||||
*/
|
||||
typedef struct _ENetAddress {
|
||||
typedef struct _ENetAddress {
|
||||
struct in6_addr host;
|
||||
enet_uint16 port;
|
||||
enet_uint16 sin6_scope_id;
|
||||
} ENetAddress;
|
||||
} ENetAddress;
|
||||
|
||||
#define in6_equal(in6_addr_a, in6_addr_b) (memcmp(&in6_addr_a, &in6_addr_b, sizeof(struct in6_addr)) == 0)
|
||||
#define in6_equal(in6_addr_a, in6_addr_b) (memcmp(&in6_addr_a, &in6_addr_b, sizeof(struct in6_addr)) == 0)
|
||||
|
||||
/**
|
||||
/**
|
||||
* Packet flag bit constants.
|
||||
*
|
||||
* The host must be specified in network byte-order, and the port must be in
|
||||
@ -502,17 +502,17 @@ typedef struct _ENetAddress {
|
||||
*
|
||||
* @sa ENetPacket
|
||||
*/
|
||||
typedef enum _ENetPacketFlag {
|
||||
typedef enum _ENetPacketFlag {
|
||||
ENET_PACKET_FLAG_RELIABLE = (1 << 0), /** packet must be received by the target peer and resend attempts should be made until the packet is delivered */
|
||||
ENET_PACKET_FLAG_UNSEQUENCED = (1 << 1), /** packet will not be sequenced with other packets not supported for reliable packets */
|
||||
ENET_PACKET_FLAG_NO_ALLOCATE = (1 << 2), /** packet will not allocate data, and user must supply it instead */
|
||||
ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT = (1 << 3), /** packet will be fragmented using unreliable (instead of reliable) sends if it exceeds the MTU */
|
||||
ENET_PACKET_FLAG_SENT = (1 << 8), /** whether the packet has been sent from all queues it has been entered into */
|
||||
} ENetPacketFlag;
|
||||
} ENetPacketFlag;
|
||||
|
||||
typedef void (ENET_CALLBACK *ENetPacketFreeCallback)(void *);
|
||||
typedef void (ENET_CALLBACK *ENetPacketFreeCallback)(void *);
|
||||
|
||||
/**
|
||||
/**
|
||||
* ENet packet structure.
|
||||
*
|
||||
* An ENet data packet that may be sent to or received from a peer. The shown
|
||||
@ -528,22 +528,22 @@ typedef void (ENET_CALLBACK *ENetPacketFreeCallback)(void *);
|
||||
* ENET_PACKET_FLAG_SENT - whether the packet has been sent from all queues it has been entered into
|
||||
* @sa ENetPacketFlag
|
||||
*/
|
||||
typedef struct _ENetPacket {
|
||||
typedef struct _ENetPacket {
|
||||
size_t referenceCount; /**< internal use only */
|
||||
enet_uint32 flags; /**< bitwise-or of ENetPacketFlag constants */
|
||||
enet_uint8 * data; /**< allocated data for packet */
|
||||
size_t dataLength; /**< length of data */
|
||||
ENetPacketFreeCallback freeCallback; /**< function to be called when the packet is no longer in use */
|
||||
void * userData; /**< application private data, may be freely modified */
|
||||
} ENetPacket;
|
||||
} ENetPacket;
|
||||
|
||||
typedef struct _ENetAcknowledgement {
|
||||
typedef struct _ENetAcknowledgement {
|
||||
ENetListNode acknowledgementList;
|
||||
enet_uint32 sentTime;
|
||||
ENetProtocol command;
|
||||
} ENetAcknowledgement;
|
||||
} ENetAcknowledgement;
|
||||
|
||||
typedef struct _ENetOutgoingCommand {
|
||||
typedef struct _ENetOutgoingCommand {
|
||||
ENetListNode outgoingCommandList;
|
||||
enet_uint16 reliableSequenceNumber;
|
||||
enet_uint16 unreliableSequenceNumber;
|
||||
@ -555,9 +555,9 @@ typedef struct _ENetOutgoingCommand {
|
||||
enet_uint16 sendAttempts;
|
||||
ENetProtocol command;
|
||||
ENetPacket * packet;
|
||||
} ENetOutgoingCommand;
|
||||
} ENetOutgoingCommand;
|
||||
|
||||
typedef struct _ENetIncomingCommand {
|
||||
typedef struct _ENetIncomingCommand {
|
||||
ENetListNode incomingCommandList;
|
||||
enet_uint16 reliableSequenceNumber;
|
||||
enet_uint16 unreliableSequenceNumber;
|
||||
@ -566,9 +566,9 @@ typedef struct _ENetIncomingCommand {
|
||||
enet_uint32 fragmentsRemaining;
|
||||
enet_uint32 *fragments;
|
||||
ENetPacket * packet;
|
||||
} ENetIncomingCommand;
|
||||
} ENetIncomingCommand;
|
||||
|
||||
typedef enum _ENetPeerState {
|
||||
typedef enum _ENetPeerState {
|
||||
ENET_PEER_STATE_DISCONNECTED = 0,
|
||||
ENET_PEER_STATE_CONNECTING = 1,
|
||||
ENET_PEER_STATE_ACKNOWLEDGING_CONNECT = 2,
|
||||
@ -579,9 +579,9 @@ typedef enum _ENetPeerState {
|
||||
ENET_PEER_STATE_DISCONNECTING = 7,
|
||||
ENET_PEER_STATE_ACKNOWLEDGING_DISCONNECT = 8,
|
||||
ENET_PEER_STATE_ZOMBIE = 9
|
||||
} ENetPeerState;
|
||||
} ENetPeerState;
|
||||
|
||||
enum {
|
||||
enum {
|
||||
ENET_HOST_RECEIVE_BUFFER_SIZE = 256 * 1024,
|
||||
ENET_HOST_SEND_BUFFER_SIZE = 256 * 1024,
|
||||
ENET_HOST_BANDWIDTH_THROTTLE_INTERVAL = 1000,
|
||||
@ -609,9 +609,9 @@ enum {
|
||||
ENET_PEER_RELIABLE_WINDOWS = 16,
|
||||
ENET_PEER_RELIABLE_WINDOW_SIZE = 0x1000,
|
||||
ENET_PEER_FREE_RELIABLE_WINDOWS = 8
|
||||
};
|
||||
};
|
||||
|
||||
typedef struct _ENetChannel {
|
||||
typedef struct _ENetChannel {
|
||||
enet_uint16 outgoingReliableSequenceNumber;
|
||||
enet_uint16 outgoingUnreliableSequenceNumber;
|
||||
enet_uint16 usedReliableWindows;
|
||||
@ -620,14 +620,14 @@ typedef struct _ENetChannel {
|
||||
enet_uint16 incomingUnreliableSequenceNumber;
|
||||
ENetList incomingReliableCommands;
|
||||
ENetList incomingUnreliableCommands;
|
||||
} ENetChannel;
|
||||
} ENetChannel;
|
||||
|
||||
/**
|
||||
/**
|
||||
* An ENet peer which data packets may be sent or received from.
|
||||
*
|
||||
* No fields should be modified unless otherwise specified.
|
||||
*/
|
||||
typedef struct _ENetPeer {
|
||||
typedef struct _ENetPeer {
|
||||
ENetListNode dispatchList;
|
||||
struct _ENetHost *host;
|
||||
enet_uint16 outgoingPeerID;
|
||||
@ -636,9 +636,7 @@ typedef struct _ENetPeer {
|
||||
enet_uint8 outgoingSessionID;
|
||||
enet_uint8 incomingSessionID;
|
||||
ENetAddress address; /**< Internet address of the peer */
|
||||
void * Name; /**< Application private data, may be freely modified */
|
||||
int gameVehicleID[50]; //added By Anonymous275
|
||||
int serverVehicleID; //added By Anonymous275
|
||||
void * data; /**< Application private data, may be freely modified */
|
||||
ENetPeerState state;
|
||||
ENetChannel * channels;
|
||||
size_t channelCount; /**< Number of channels allocated for communication with peer */
|
||||
@ -694,10 +692,10 @@ typedef struct _ENetPeer {
|
||||
enet_uint32 unsequencedWindow[ENET_PEER_UNSEQUENCED_WINDOW_SIZE / 32];
|
||||
enet_uint32 eventData;
|
||||
size_t totalWaitingData;
|
||||
} ENetPeer;
|
||||
} ENetPeer;
|
||||
|
||||
/** An ENet packet compressor for compressing UDP packets before socket sends or receives. */
|
||||
typedef struct _ENetCompressor {
|
||||
/** An ENet packet compressor for compressing UDP packets before socket sends or receives. */
|
||||
typedef struct _ENetCompressor {
|
||||
/** Context data for the compressor. Must be non-NULL. */
|
||||
void *context;
|
||||
|
||||
@ -709,15 +707,15 @@ typedef struct _ENetCompressor {
|
||||
|
||||
/** Destroys the context when compression is disabled or the host is destroyed. May be NULL. */
|
||||
void (ENET_CALLBACK * destroy)(void *context);
|
||||
} ENetCompressor;
|
||||
} ENetCompressor;
|
||||
|
||||
/** Callback that computes the checksum of the data held in buffers[0:bufferCount-1] */
|
||||
typedef enet_uint32 (ENET_CALLBACK * ENetChecksumCallback)(const ENetBuffer *buffers, size_t bufferCount);
|
||||
/** Callback that computes the checksum of the data held in buffers[0:bufferCount-1] */
|
||||
typedef enet_uint32 (ENET_CALLBACK * ENetChecksumCallback)(const ENetBuffer *buffers, size_t bufferCount);
|
||||
|
||||
/** Callback for intercepting received raw UDP packets. Should return 1 to intercept, 0 to ignore, or -1 to propagate an error. */
|
||||
typedef int (ENET_CALLBACK * ENetInterceptCallback)(struct _ENetHost *host, void *event);
|
||||
/** Callback for intercepting received raw UDP packets. Should return 1 to intercept, 0 to ignore, or -1 to propagate an error. */
|
||||
typedef int (ENET_CALLBACK * ENetInterceptCallback)(struct _ENetHost *host, void *event);
|
||||
|
||||
/** An ENet host for communicating with peers.
|
||||
/** An ENet host for communicating with peers.
|
||||
*
|
||||
* No fields should be modified unless otherwise stated.
|
||||
*
|
||||
@ -732,7 +730,7 @@ typedef int (ENET_CALLBACK * ENetInterceptCallback)(struct _ENetHost *host, void
|
||||
* @sa enet_host_bandwidth_limit()
|
||||
* @sa enet_host_bandwidth_throttle()
|
||||
*/
|
||||
typedef struct _ENetHost {
|
||||
typedef struct _ENetHost {
|
||||
ENetSocket socket;
|
||||
ENetAddress address; /**< Internet address of the host */
|
||||
enet_uint32 incomingBandwidth; /**< downstream bandwidth of the host */
|
||||
@ -769,12 +767,12 @@ typedef struct _ENetHost {
|
||||
size_t duplicatePeers; /**< optional number of allowed peers from duplicate IPs, defaults to ENET_PROTOCOL_MAXIMUM_PEER_ID */
|
||||
size_t maximumPacketSize; /**< the maximum allowable packet size that may be sent or received on a peer */
|
||||
size_t maximumWaitingData; /**< the maximum aggregate amount of buffer space a peer may use waiting for packets to be delivered */
|
||||
} ENetHost;
|
||||
} ENetHost;
|
||||
|
||||
/**
|
||||
/**
|
||||
* An ENet event type, as specified in @ref ENetEvent.
|
||||
*/
|
||||
typedef enum _ENetEventType {
|
||||
typedef enum _ENetEventType {
|
||||
/** no event occurred within the specified time limit */
|
||||
ENET_EVENT_TYPE_NONE = 0,
|
||||
|
||||
@ -804,20 +802,20 @@ typedef enum _ENetEventType {
|
||||
* network connection or host crashed.
|
||||
*/
|
||||
ENET_EVENT_TYPE_DISCONNECT_TIMEOUT = 4,
|
||||
} ENetEventType;
|
||||
} ENetEventType;
|
||||
|
||||
/**
|
||||
/**
|
||||
* An ENet event as returned by enet_host_service().
|
||||
*
|
||||
* @sa enet_host_service
|
||||
*/
|
||||
typedef struct _ENetEvent {
|
||||
typedef struct _ENetEvent {
|
||||
ENetEventType type; /**< type of the event */
|
||||
ENetPeer * peer; /**< peer that generated a connect, disconnect or receive event */
|
||||
enet_uint8 channelID; /**< channel on the peer that generated the event, if appropriate */
|
||||
enet_uint32 data; /**< data associated with the event, if appropriate */
|
||||
ENetPacket * packet; /**< packet associated with the event, if appropriate */
|
||||
} ENetEvent;
|
||||
} ENetEvent;
|
||||
|
||||
// =======================================================================//
|
||||
// !
|
||||
@ -825,160 +823,160 @@ typedef struct _ENetEvent {
|
||||
// !
|
||||
// =======================================================================//
|
||||
|
||||
/**
|
||||
/**
|
||||
* Initializes ENet globally. Must be called prior to using any functions in ENet.
|
||||
* @returns 0 on success, < 0 on failure
|
||||
*/
|
||||
ENET_API int enet_initialize(void);
|
||||
ENET_API int enet_initialize(void);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Initializes ENet globally and supplies user-overridden callbacks. Must be called prior to using any functions in ENet. Do not use enet_initialize() if you use this variant. Make sure the ENetCallbacks structure is zeroed out so that any additional callbacks added in future versions will be properly ignored.
|
||||
*
|
||||
* @param version the constant ENET_VERSION should be supplied so ENet knows which version of ENetCallbacks struct to use
|
||||
* @param inits user-overridden callbacks where any NULL callbacks will use ENet's defaults
|
||||
* @returns 0 on success, < 0 on failure
|
||||
*/
|
||||
ENET_API int enet_initialize_with_callbacks(ENetVersion version, const ENetCallbacks * inits);
|
||||
ENET_API int enet_initialize_with_callbacks(ENetVersion version, const ENetCallbacks * inits);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Shuts down ENet globally. Should be called when a program that has initialized ENet exits.
|
||||
*/
|
||||
ENET_API void enet_deinitialize(void);
|
||||
ENET_API void enet_deinitialize(void);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Gives the linked version of the ENet library.
|
||||
* @returns the version number
|
||||
*/
|
||||
ENET_API ENetVersion enet_linked_version(void);
|
||||
ENET_API ENetVersion enet_linked_version(void);
|
||||
|
||||
/** Returns the monotonic time in milliseconds. Its initial value is unspecified unless otherwise set. */
|
||||
ENET_API enet_uint32 enet_time_get(void);
|
||||
/** Returns the monotonic time in milliseconds. Its initial value is unspecified unless otherwise set. */
|
||||
ENET_API enet_uint32 enet_time_get(void);
|
||||
|
||||
/** ENet socket functions */
|
||||
ENET_API ENetSocket enet_socket_create(ENetSocketType);
|
||||
ENET_API int enet_socket_bind(ENetSocket, const ENetAddress *);
|
||||
ENET_API int enet_socket_get_address(ENetSocket, ENetAddress *);
|
||||
ENET_API int enet_socket_listen(ENetSocket, int);
|
||||
ENET_API ENetSocket enet_socket_accept(ENetSocket, ENetAddress *);
|
||||
ENET_API int enet_socket_connect(ENetSocket, const ENetAddress *);
|
||||
ENET_API int enet_socket_send(ENetSocket, const ENetAddress *, const ENetBuffer *, size_t);
|
||||
ENET_API int enet_socket_receive(ENetSocket, ENetAddress *, ENetBuffer *, size_t);
|
||||
ENET_API int enet_socket_wait(ENetSocket, enet_uint32 *, enet_uint64);
|
||||
ENET_API int enet_socket_set_option(ENetSocket, ENetSocketOption, int);
|
||||
ENET_API int enet_socket_get_option(ENetSocket, ENetSocketOption, int *);
|
||||
ENET_API int enet_socket_shutdown(ENetSocket, ENetSocketShutdown);
|
||||
ENET_API void enet_socket_destroy(ENetSocket);
|
||||
ENET_API int enet_socketset_select(ENetSocket, ENetSocketSet *, ENetSocketSet *, enet_uint32);
|
||||
/** ENet socket functions */
|
||||
ENET_API ENetSocket enet_socket_create(ENetSocketType);
|
||||
ENET_API int enet_socket_bind(ENetSocket, const ENetAddress *);
|
||||
ENET_API int enet_socket_get_address(ENetSocket, ENetAddress *);
|
||||
ENET_API int enet_socket_listen(ENetSocket, int);
|
||||
ENET_API ENetSocket enet_socket_accept(ENetSocket, ENetAddress *);
|
||||
ENET_API int enet_socket_connect(ENetSocket, const ENetAddress *);
|
||||
ENET_API int enet_socket_send(ENetSocket, const ENetAddress *, const ENetBuffer *, size_t);
|
||||
ENET_API int enet_socket_receive(ENetSocket, ENetAddress *, ENetBuffer *, size_t);
|
||||
ENET_API int enet_socket_wait(ENetSocket, enet_uint32 *, enet_uint64);
|
||||
ENET_API int enet_socket_set_option(ENetSocket, ENetSocketOption, int);
|
||||
ENET_API int enet_socket_get_option(ENetSocket, ENetSocketOption, int *);
|
||||
ENET_API int enet_socket_shutdown(ENetSocket, ENetSocketShutdown);
|
||||
ENET_API void enet_socket_destroy(ENetSocket);
|
||||
ENET_API int enet_socketset_select(ENetSocket, ENetSocketSet *, ENetSocketSet *, enet_uint32);
|
||||
|
||||
/** Attempts to parse the printable form of the IP address in the parameter hostName
|
||||
/** Attempts to parse the printable form of the IP address in the parameter hostName
|
||||
and sets the host field in the address parameter if successful.
|
||||
@param address destination to store the parsed IP address
|
||||
@param hostName IP address to parse
|
||||
@retval 0 on success
|
||||
@retval < 0 on failure
|
||||
@returns the address of the given hostName in address on success
|
||||
*/
|
||||
ENET_API int enet_address_set_host_ip(ENetAddress * address, const char * hostName);
|
||||
*/
|
||||
ENET_API int enet_address_set_host_ip(ENetAddress * address, const char * hostName);
|
||||
|
||||
/** Attempts to resolve the host named by the parameter hostName and sets
|
||||
/** Attempts to resolve the host named by the parameter hostName and sets
|
||||
the host field in the address parameter if successful.
|
||||
@param address destination to store resolved address
|
||||
@param hostName host name to lookup
|
||||
@retval 0 on success
|
||||
@retval < 0 on failure
|
||||
@returns the address of the given hostName in address on success
|
||||
*/
|
||||
ENET_API int enet_address_set_host(ENetAddress * address, const char * hostName);
|
||||
*/
|
||||
ENET_API int enet_address_set_host(ENetAddress * address, const char * hostName);
|
||||
|
||||
/** Gives the printable form of the IP address specified in the address parameter.
|
||||
/** Gives the printable form of the IP address specified in the address parameter.
|
||||
@param address address printed
|
||||
@param hostName destination for name, must not be NULL
|
||||
@param nameLength maximum length of hostName.
|
||||
@returns the null-terminated name of the host in hostName on success
|
||||
@retval 0 on success
|
||||
@retval < 0 on failure
|
||||
*/
|
||||
ENET_API int enet_address_get_host_ip(const ENetAddress * address, char * hostName, size_t nameLength);
|
||||
*/
|
||||
ENET_API int enet_address_get_host_ip(const ENetAddress * address, char * hostName, size_t nameLength);
|
||||
|
||||
/** Attempts to do a reverse lookup of the host field in the address parameter.
|
||||
/** Attempts to do a reverse lookup of the host field in the address parameter.
|
||||
@param address address used for reverse lookup
|
||||
@param hostName destination for name, must not be NULL
|
||||
@param nameLength maximum length of hostName.
|
||||
@returns the null-terminated name of the host in hostName on success
|
||||
@retval 0 on success
|
||||
@retval < 0 on failure
|
||||
*/
|
||||
ENET_API int enet_address_get_host(const ENetAddress * address, char * hostName, size_t nameLength);
|
||||
*/
|
||||
ENET_API int enet_address_get_host(const ENetAddress * address, char * hostName, size_t nameLength);
|
||||
|
||||
ENET_API enet_uint32 enet_host_get_peers_count(ENetHost *);
|
||||
ENET_API enet_uint32 enet_host_get_packets_sent(ENetHost *);
|
||||
ENET_API enet_uint32 enet_host_get_packets_received(ENetHost *);
|
||||
ENET_API enet_uint32 enet_host_get_bytes_sent(ENetHost *);
|
||||
ENET_API enet_uint32 enet_host_get_bytes_received(ENetHost *);
|
||||
ENET_API enet_uint32 enet_host_get_received_data(ENetHost *, enet_uint8** data);
|
||||
ENET_API enet_uint32 enet_host_get_mtu(ENetHost *);
|
||||
ENET_API enet_uint32 enet_host_get_peers_count(ENetHost *);
|
||||
ENET_API enet_uint32 enet_host_get_packets_sent(ENetHost *);
|
||||
ENET_API enet_uint32 enet_host_get_packets_received(ENetHost *);
|
||||
ENET_API enet_uint32 enet_host_get_bytes_sent(ENetHost *);
|
||||
ENET_API enet_uint32 enet_host_get_bytes_received(ENetHost *);
|
||||
ENET_API enet_uint32 enet_host_get_received_data(ENetHost *, enet_uint8** data);
|
||||
ENET_API enet_uint32 enet_host_get_mtu(ENetHost *);
|
||||
|
||||
ENET_API enet_uint32 enet_peer_get_id(ENetPeer *);
|
||||
ENET_API enet_uint32 enet_peer_get_ip(ENetPeer *, char * ip, size_t ipLength);
|
||||
ENET_API enet_uint16 enet_peer_get_port(ENetPeer *);
|
||||
ENET_API enet_uint32 enet_peer_get_rtt(ENetPeer *);
|
||||
ENET_API enet_uint64 enet_peer_get_packets_sent(ENetPeer *);
|
||||
ENET_API enet_uint32 enet_peer_get_packets_lost(ENetPeer *);
|
||||
ENET_API enet_uint64 enet_peer_get_bytes_sent(ENetPeer *);
|
||||
ENET_API enet_uint64 enet_peer_get_bytes_received(ENetPeer *);
|
||||
ENET_API enet_uint32 enet_peer_get_id(ENetPeer *);
|
||||
ENET_API enet_uint32 enet_peer_get_ip(ENetPeer *, char * ip, size_t ipLength);
|
||||
ENET_API enet_uint16 enet_peer_get_port(ENetPeer *);
|
||||
ENET_API enet_uint32 enet_peer_get_rtt(ENetPeer *);
|
||||
ENET_API enet_uint64 enet_peer_get_packets_sent(ENetPeer *);
|
||||
ENET_API enet_uint32 enet_peer_get_packets_lost(ENetPeer *);
|
||||
ENET_API enet_uint64 enet_peer_get_bytes_sent(ENetPeer *);
|
||||
ENET_API enet_uint64 enet_peer_get_bytes_received(ENetPeer *);
|
||||
|
||||
ENET_API ENetPeerState enet_peer_get_state(ENetPeer *);
|
||||
ENET_API ENetPeerState enet_peer_get_state(ENetPeer *);
|
||||
|
||||
ENET_API void * enet_peer_get_data(ENetPeer *);
|
||||
ENET_API void enet_peer_set_data(ENetPeer *, const void *);
|
||||
ENET_API void * enet_peer_get_data(ENetPeer *);
|
||||
ENET_API void enet_peer_set_data(ENetPeer *, const void *);
|
||||
|
||||
ENET_API void * enet_packet_get_data(ENetPacket *);
|
||||
ENET_API enet_uint32 enet_packet_get_length(ENetPacket *);
|
||||
ENET_API void enet_packet_set_free_callback(ENetPacket *, void *);
|
||||
ENET_API void * enet_packet_get_data(ENetPacket *);
|
||||
ENET_API enet_uint32 enet_packet_get_length(ENetPacket *);
|
||||
ENET_API void enet_packet_set_free_callback(ENetPacket *, void *);
|
||||
|
||||
ENET_API ENetPacket * enet_packet_create(const void *, size_t, enet_uint32);
|
||||
ENET_API ENetPacket * enet_packet_create_offset(const void *, size_t, size_t, enet_uint32);
|
||||
ENET_API void enet_packet_destroy(ENetPacket *);
|
||||
ENET_API enet_uint32 enet_crc32(const ENetBuffer *, size_t);
|
||||
ENET_API ENetPacket * enet_packet_create(const void *, size_t, enet_uint32);
|
||||
ENET_API ENetPacket * enet_packet_create_offset(const void *, size_t, size_t, enet_uint32);
|
||||
ENET_API void enet_packet_destroy(ENetPacket *);
|
||||
ENET_API enet_uint32 enet_crc32(const ENetBuffer *, size_t);
|
||||
|
||||
ENET_API ENetHost * enet_host_create(const ENetAddress *, size_t, size_t, enet_uint32, enet_uint32);
|
||||
ENET_API void enet_host_destroy(ENetHost *);
|
||||
ENET_API ENetPeer * enet_host_connect(ENetHost *, const ENetAddress *, size_t, enet_uint32);
|
||||
ENET_API int enet_host_check_events(ENetHost *, ENetEvent *);
|
||||
ENET_API int enet_host_service(ENetHost *, ENetEvent *, enet_uint32);
|
||||
ENET_API int enet_host_send_raw(ENetHost *, const ENetAddress *, enet_uint8 *, size_t);
|
||||
ENET_API int enet_host_send_raw_ex(ENetHost *host, const ENetAddress* address, enet_uint8* data, size_t skipBytes, size_t bytesToSend);
|
||||
ENET_API void enet_host_set_intercept(ENetHost *, const ENetInterceptCallback);
|
||||
ENET_API void enet_host_flush(ENetHost *);
|
||||
ENET_API void enet_host_broadcast(ENetHost *, enet_uint8, ENetPacket *);
|
||||
ENET_API void enet_host_compress(ENetHost *, const ENetCompressor *);
|
||||
ENET_API void enet_host_channel_limit(ENetHost *, size_t);
|
||||
ENET_API void enet_host_bandwidth_limit(ENetHost *, enet_uint32, enet_uint32);
|
||||
extern void enet_host_bandwidth_throttle(ENetHost *);
|
||||
extern enet_uint64 enet_host_random_seed(void);
|
||||
ENET_API ENetHost * enet_host_create(const ENetAddress *, size_t, size_t, enet_uint32, enet_uint32);
|
||||
ENET_API void enet_host_destroy(ENetHost *);
|
||||
ENET_API ENetPeer * enet_host_connect(ENetHost *, const ENetAddress *, size_t, enet_uint32);
|
||||
ENET_API int enet_host_check_events(ENetHost *, ENetEvent *);
|
||||
ENET_API int enet_host_service(ENetHost *, ENetEvent *, enet_uint32);
|
||||
ENET_API int enet_host_send_raw(ENetHost *, const ENetAddress *, enet_uint8 *, size_t);
|
||||
ENET_API int enet_host_send_raw_ex(ENetHost *host, const ENetAddress* address, enet_uint8* data, size_t skipBytes, size_t bytesToSend);
|
||||
ENET_API void enet_host_set_intercept(ENetHost *, const ENetInterceptCallback);
|
||||
ENET_API void enet_host_flush(ENetHost *);
|
||||
ENET_API void enet_host_broadcast(ENetHost *, enet_uint8, ENetPacket *);
|
||||
ENET_API void enet_host_compress(ENetHost *, const ENetCompressor *);
|
||||
ENET_API void enet_host_channel_limit(ENetHost *, size_t);
|
||||
ENET_API void enet_host_bandwidth_limit(ENetHost *, enet_uint32, enet_uint32);
|
||||
extern void enet_host_bandwidth_throttle(ENetHost *);
|
||||
extern enet_uint64 enet_host_random_seed(void);
|
||||
|
||||
ENET_API int enet_peer_send(ENetPeer *, enet_uint8, ENetPacket *);
|
||||
ENET_API ENetPacket * enet_peer_receive(ENetPeer *, enet_uint8 * channelID);
|
||||
ENET_API void enet_peer_ping(ENetPeer *);
|
||||
ENET_API void enet_peer_ping_interval(ENetPeer *, enet_uint32);
|
||||
ENET_API void enet_peer_timeout(ENetPeer *, enet_uint32, enet_uint32, enet_uint32);
|
||||
ENET_API void enet_peer_reset(ENetPeer *);
|
||||
ENET_API void enet_peer_disconnect(ENetPeer *, enet_uint32);
|
||||
ENET_API void enet_peer_disconnect_now(ENetPeer *, enet_uint32);
|
||||
ENET_API void enet_peer_disconnect_later(ENetPeer *, enet_uint32);
|
||||
ENET_API void enet_peer_throttle_configure(ENetPeer *, enet_uint32, enet_uint32, enet_uint32);
|
||||
extern int enet_peer_throttle(ENetPeer *, enet_uint32);
|
||||
extern void enet_peer_reset_queues(ENetPeer *);
|
||||
extern void enet_peer_setup_outgoing_command(ENetPeer *, ENetOutgoingCommand *);
|
||||
extern ENetOutgoingCommand * enet_peer_queue_outgoing_command(ENetPeer *, const ENetProtocol *, ENetPacket *, enet_uint32, enet_uint16);
|
||||
extern ENetIncomingCommand * enet_peer_queue_incoming_command(ENetPeer *, const ENetProtocol *, const void *, size_t, enet_uint32, enet_uint32);
|
||||
extern ENetAcknowledgement * enet_peer_queue_acknowledgement(ENetPeer *, const ENetProtocol *, enet_uint16);
|
||||
extern void enet_peer_dispatch_incoming_unreliable_commands(ENetPeer *, ENetChannel *);
|
||||
extern void enet_peer_dispatch_incoming_reliable_commands(ENetPeer *, ENetChannel *);
|
||||
extern void enet_peer_on_connect(ENetPeer *);
|
||||
extern void enet_peer_on_disconnect(ENetPeer *);
|
||||
ENET_API int enet_peer_send(ENetPeer *, enet_uint8, ENetPacket *);
|
||||
ENET_API ENetPacket * enet_peer_receive(ENetPeer *, enet_uint8 * channelID);
|
||||
ENET_API void enet_peer_ping(ENetPeer *);
|
||||
ENET_API void enet_peer_ping_interval(ENetPeer *, enet_uint32);
|
||||
ENET_API void enet_peer_timeout(ENetPeer *, enet_uint32, enet_uint32, enet_uint32);
|
||||
ENET_API void enet_peer_reset(ENetPeer *);
|
||||
ENET_API void enet_peer_disconnect(ENetPeer *, enet_uint32);
|
||||
ENET_API void enet_peer_disconnect_now(ENetPeer *, enet_uint32);
|
||||
ENET_API void enet_peer_disconnect_later(ENetPeer *, enet_uint32);
|
||||
ENET_API void enet_peer_throttle_configure(ENetPeer *, enet_uint32, enet_uint32, enet_uint32);
|
||||
extern int enet_peer_throttle(ENetPeer *, enet_uint32);
|
||||
extern void enet_peer_reset_queues(ENetPeer *);
|
||||
extern void enet_peer_setup_outgoing_command(ENetPeer *, ENetOutgoingCommand *);
|
||||
extern ENetOutgoingCommand * enet_peer_queue_outgoing_command(ENetPeer *, const ENetProtocol *, ENetPacket *, enet_uint32, enet_uint16);
|
||||
extern ENetIncomingCommand * enet_peer_queue_incoming_command(ENetPeer *, const ENetProtocol *, const void *, size_t, enet_uint32, enet_uint32);
|
||||
extern ENetAcknowledgement * enet_peer_queue_acknowledgement(ENetPeer *, const ENetProtocol *, enet_uint16);
|
||||
extern void enet_peer_dispatch_incoming_unreliable_commands(ENetPeer *, ENetChannel *);
|
||||
extern void enet_peer_dispatch_incoming_reliable_commands(ENetPeer *, ENetChannel *);
|
||||
extern void enet_peer_on_connect(ENetPeer *);
|
||||
extern void enet_peer_on_disconnect(ENetPeer *);
|
||||
|
||||
extern size_t enet_protocol_command_size (enet_uint8);
|
||||
extern size_t enet_protocol_command_size (enet_uint8);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
@ -3439,11 +3437,11 @@ extern "C" {
|
||||
}
|
||||
|
||||
void * enet_peer_get_data(ENetPeer *peer) {
|
||||
return (void *) peer->Name;
|
||||
return (void *) peer->data;
|
||||
}
|
||||
|
||||
void enet_peer_set_data(ENetPeer *peer, const void *Name) {
|
||||
peer->Name = (enet_uint32 *) Name;
|
||||
void enet_peer_set_data(ENetPeer *peer, const void *data) {
|
||||
peer->data = (enet_uint32 *) data;
|
||||
}
|
||||
|
||||
void * enet_packet_get_data(ENetPacket *packet) {
|
||||
@ -4418,7 +4416,7 @@ extern "C" {
|
||||
currentPeer->host = host;
|
||||
currentPeer->incomingPeerID = currentPeer - host->peers;
|
||||
currentPeer->outgoingSessionID = currentPeer->incomingSessionID = 0xFF;
|
||||
currentPeer->Name = NULL;
|
||||
currentPeer->data = NULL;
|
||||
|
||||
enet_list_clear(¤tPeer->acknowledgements);
|
||||
enet_list_clear(¤tPeer->sentReliableCommands);
|
||||
|
72
proxy.cpp
72
proxy.cpp
@ -2,18 +2,22 @@
|
||||
//// Created by Anonymous275 on 3/3/2020.
|
||||
////
|
||||
|
||||
#define ENET_IMPLEMENTATION
|
||||
#include "enet.h"
|
||||
#include <WinSock2.h>
|
||||
#include <Windows.h>
|
||||
#include <WS2tcpip.h>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#define DEFAULT_BUFLEN 64000
|
||||
#define DEFAULT_PORT "4444"
|
||||
typedef struct {
|
||||
ENetHost *host;
|
||||
ENetPeer *peer;
|
||||
} Client;
|
||||
|
||||
std::string TCPData;
|
||||
std::string RUDPData;
|
||||
std::string TCPToSend;
|
||||
std::string RUDPToSend;
|
||||
|
||||
void TCPServerThread(){
|
||||
@ -122,13 +126,73 @@ void TCPServerThread(){
|
||||
closesocket(ClientSocket);
|
||||
WSACleanup();
|
||||
}
|
||||
void HandleEvent(ENetEvent event,Client client){
|
||||
switch (event.type){
|
||||
case ENET_EVENT_TYPE_CONNECT:
|
||||
printf("Client Connected port : %u.\n",event.peer->address.port);
|
||||
//Name Of the Server
|
||||
event.peer->data = (void *)"Connected Server";
|
||||
break;
|
||||
case ENET_EVENT_TYPE_RECEIVE:
|
||||
printf("Received: %s\n",event.packet->data);
|
||||
RUDPData = reinterpret_cast<const char *const>(event.packet->data);
|
||||
enet_packet_destroy (event.packet);
|
||||
break;
|
||||
case ENET_EVENT_TYPE_DISCONNECT:
|
||||
printf ("%s disconnected.\n", (char *)event.peer->data);
|
||||
// Reset the peer's client information.
|
||||
event.peer->data = NULL;
|
||||
break;
|
||||
|
||||
case ENET_EVENT_TYPE_DISCONNECT_TIMEOUT:
|
||||
printf ("%s timeout.\n", (char *)event.peer->data);
|
||||
event.peer->data = NULL;
|
||||
break;
|
||||
|
||||
case ENET_EVENT_TYPE_NONE: break;
|
||||
}
|
||||
}
|
||||
void RUDPClientThread(){
|
||||
if (enet_initialize() != 0) {
|
||||
printf("An error occurred while initializing ENet.\n");
|
||||
}
|
||||
|
||||
|
||||
Client client;
|
||||
ENetAddress address = {0};
|
||||
|
||||
address.host = ENET_HOST_ANY;
|
||||
address.port = 30814;
|
||||
|
||||
|
||||
printf("starting client...\n");
|
||||
|
||||
enet_address_set_host(&address, "localhost");
|
||||
client.host = enet_host_create(NULL, 1, 2, 0, 0);
|
||||
client.peer = enet_host_connect(client.host, &address, 2, 0);
|
||||
if (client.peer == NULL) {
|
||||
printf("could not connect\n");
|
||||
}
|
||||
|
||||
do {
|
||||
|
||||
ENetEvent event;
|
||||
enet_host_service(client.host, &event, 0);
|
||||
HandleEvent(event,client); //Handles the Events
|
||||
if(!RUDPToSend.empty()){
|
||||
ENetPacket* packet = enet_packet_create (RUDPToSend.c_str(),
|
||||
RUDPToSend.length()+1,
|
||||
ENET_PACKET_FLAG_RELIABLE); //Create A reliable packet using the data
|
||||
enet_peer_send(client.peer, 0, packet);
|
||||
RUDPToSend.clear();
|
||||
}
|
||||
Sleep(50);
|
||||
} while (true);
|
||||
}
|
||||
|
||||
|
||||
void Start(){
|
||||
TCPServerThread();
|
||||
RUDPClientThread();
|
||||
std::thread t1(TCPServerThread);
|
||||
std::thread t2(RUDPClientThread);
|
||||
t2.join();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user