Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-1-2-2013-Decompilation
Path: blob/main/RSDKv4/Networking.hpp
817 views
1
#if RETRO_USE_NETWORKING
2
#ifndef NETWORKING_H
3
#define NETWORKING_H
4
#include <thread>
5
#include <memory>
6
7
#define PACKET_SIZE 0x1000
8
9
extern char networkHost[64];
10
extern char networkGame[7];
11
extern int networkPort;
12
13
extern float lastPing;
14
extern int dcError;
15
extern bool waitingForPing;
16
17
struct MultiplayerData {
18
int type;
19
int data[(PACKET_SIZE - 16) / sizeof(int) - 1];
20
};
21
22
struct ServerPacket {
23
byte header = 0;
24
char game[7] = { 0, 0, 0, 0, 0, 0, 0 };
25
uint player = 0;
26
uint room = 0;
27
28
union {
29
unsigned char bytes[PACKET_SIZE - 16];
30
MultiplayerData multiData;
31
} data;
32
};
33
34
enum ClientHeaders {
35
CL_REQUEST_CODE = 0x00,
36
CL_JOIN = 0x01,
37
38
CL_DATA = 0x10,
39
CL_DATA_VERIFIED = 0x11,
40
41
CL_QUERY_VERIFICATION = 0x20,
42
43
CL_LEAVE = 0xFF
44
};
45
enum ServerHeaders {
46
SV_CODES = 0x00,
47
SV_NEW_PLAYER = 0x01,
48
49
SV_DATA = 0x10,
50
SV_DATA_VERIFIED = 0x11,
51
52
SV_RECEIVED = 0x20,
53
SV_VERIFY_CLEAR = 0x21,
54
55
SV_INVALID_HEADER = 0x80,
56
SV_NO_ROOM = 0x81,
57
SV_UNKNOWN_PLAYER = 0x82,
58
59
SV_LEAVE = 0xFF
60
};
61
62
class NetworkSession;
63
64
extern std::shared_ptr<NetworkSession> session;
65
66
void InitNetwork();
67
void RunNetwork();
68
void SendData(bool verify = false);
69
void DisconnectNetwork(bool finalClose = false);
70
void SendServerPacket(ServerPacket &send, bool verify = false);
71
int GetRoomCode();
72
void SetRoomCode(int code);
73
74
void SetNetworkGameName(int *unused, const char *name);
75
76
#endif
77
#endif
78
79