2021-07-05 02:31:23 +00:00
|
|
|
// SPDX-License-Identifier: CC0-1.0
|
2015-02-02 09:56:53 +00:00
|
|
|
|
|
|
|
#pragma once
|
2021-01-19 19:15:09 +00:00
|
|
|
|
2015-02-02 09:56:53 +00:00
|
|
|
#include <array>
|
2021-01-19 19:15:09 +00:00
|
|
|
#include <cstddef>
|
2015-02-02 09:56:53 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
|
|
|
|
2023-04-24 12:29:12 +00:00
|
|
|
namespace Common
|
|
|
|
{
|
2021-01-19 19:15:09 +00:00
|
|
|
constexpr size_t NETPLAY_CODE_SIZE = 8;
|
|
|
|
using TraversalHostId = std::array<char, NETPLAY_CODE_SIZE>;
|
|
|
|
using TraversalRequestId = u64;
|
2015-02-02 09:56:53 +00:00
|
|
|
|
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,
|
2023-01-12 16:45:49 +00:00
|
|
|
// [c->s] Perform a traveral test. This will send two acks:
|
|
|
|
// one via the server's alt port, and one to the address corresponding to
|
|
|
|
// the given host ID.
|
|
|
|
TestPlease = 8,
|
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;
|
2022-03-04 04:08:55 +00:00
|
|
|
TraversalInetAddress yourAddress;
|
2015-02-02 09:56:53 +00:00
|
|
|
} 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;
|
2023-01-12 16:45:49 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
TraversalHostId hostId;
|
|
|
|
} testPlease;
|
2015-02-02 09:56:53 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
2023-04-24 12:29:12 +00:00
|
|
|
} // namespace Common
|