2015-02-02 09:56:53 +00:00
|
|
|
// This file is public domain, in case it's useful to anyone. -comex
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include <array>
|
|
|
|
#include "Common/CommonTypes.h"
|
|
|
|
|
2015-02-15 03:51:08 +00:00
|
|
|
#define NETPLAY_CODE_SIZE 8
|
|
|
|
typedef std::array<char, NETPLAY_CODE_SIZE> TraversalHostId;
|
2015-02-02 09:56:53 +00:00
|
|
|
typedef u64 TraversalRequestId;
|
|
|
|
|
2021-01-19 19:11:39 +00:00
|
|
|
enum class TraversalPacketType : u8
|
2015-02-02 09:56:53 +00:00
|
|
|
{
|
|
|
|
// [*->*]
|
2021-01-19 19:11:39 +00:00
|
|
|
Ack = 0,
|
2015-02-02 09:56:53 +00:00
|
|
|
// [c->s]
|
2021-01-19 19:11:39 +00:00
|
|
|
Ping = 1,
|
2015-02-02 09:56:53 +00:00
|
|
|
// [c->s]
|
2021-01-19 19:11:39 +00:00
|
|
|
HelloFromClient = 2,
|
2015-02-02 09:56:53 +00:00
|
|
|
// [s->c]
|
2021-01-19 19:11:39 +00:00
|
|
|
HelloFromServer = 3,
|
2015-02-02 09:56:53 +00:00
|
|
|
// [c->s] When connecting, first the client asks the central server...
|
2021-01-19 19:11:39 +00:00
|
|
|
ConnectPlease = 4,
|
2015-02-02 09:56:53 +00:00
|
|
|
// [s->c] ...who asks the game host to send a UDP packet to the
|
|
|
|
// client... (an ack implies success)
|
2021-01-19 19:11:39 +00:00
|
|
|
PleaseSendPacket = 5,
|
2015-02-02 09:56:53 +00:00
|
|
|
// [s->c] ...which the central server relays back to the client.
|
2021-01-19 19:11:39 +00:00
|
|
|
ConnectReady = 6,
|
2015-02-02 09:56:53 +00:00
|
|
|
// [s->c] Alternately, the server might not have heard of this host.
|
2021-01-19 19:11:39 +00:00
|
|
|
ConnectFailed = 7,
|
2015-02-02 09:56:53 +00:00
|
|
|
};
|
|
|
|
|
2021-01-19 19:13:08 +00:00
|
|
|
constexpr u8 TraversalProtoVersion = 0;
|
2015-02-02 09:56:53 +00:00
|
|
|
|
2021-01-19 19:05:16 +00:00
|
|
|
enum class TraversalConnectFailedReason : u8
|
2015-02-02 09:56:53 +00:00
|
|
|
{
|
2021-01-19 19:05:16 +00:00
|
|
|
ClientDidntRespond = 0,
|
|
|
|
ClientFailure,
|
|
|
|
NoSuchClient,
|
2015-02-02 09:56:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#pragma pack(push, 1)
|
|
|
|
struct TraversalInetAddress
|
|
|
|
{
|
|
|
|
u8 isIPV6;
|
|
|
|
u32 address[4];
|
|
|
|
u16 port;
|
|
|
|
};
|
|
|
|
struct TraversalPacket
|
|
|
|
{
|
2021-01-19 19:11:39 +00:00
|
|
|
TraversalPacketType type;
|
2015-02-02 09:56:53 +00:00
|
|
|
TraversalRequestId requestId;
|
2017-01-04 11:45:40 +00:00
|
|
|
union
|
|
|
|
{
|
2015-02-02 09:56:53 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
u8 ok;
|
|
|
|
} ack;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
TraversalHostId hostId;
|
|
|
|
} ping;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
u8 protoVersion;
|
|
|
|
} helloFromClient;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
u8 ok;
|
|
|
|
TraversalHostId yourHostId;
|
|
|
|
TraversalInetAddress yourAddress; // currently unused
|
|
|
|
} helloFromServer;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
TraversalHostId hostId;
|
|
|
|
} connectPlease;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
TraversalInetAddress address;
|
|
|
|
} pleaseSendPacket;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
TraversalRequestId requestId;
|
|
|
|
TraversalInetAddress address;
|
|
|
|
} connectReady;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
TraversalRequestId requestId;
|
2021-01-19 19:05:16 +00:00
|
|
|
TraversalConnectFailedReason reason;
|
2015-02-02 09:56:53 +00:00
|
|
|
} connectFailed;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
#pragma pack(pop)
|