-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathnetwork.h
152 lines (123 loc) · 3.09 KB
/
network.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#pragma once
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <ws2def.h>
#include <ws2tcpip.h>
#define INVALID_TCP_SOCKET INVALID_SOCKET
typedef SOCKET TCP_SOCKET;
#else
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <netdb.h>
#include <pthread.h> // compile with -pthread
#define INVALID_TCP_SOCKET (-1)
typedef int TCP_SOCKET;
#endif
struct THREAD_HANDLE;
struct RWLOCK_HANDLE;
struct MUTEX_HANDLE;
int TCP_INIT();
int TCP_CLOSE(TCP_SOCKET s);
int TCP_CLEANUP();
int TCP_WRITE(TCP_SOCKET s, const uint8_t* buf, int size);
int TCP_READ(TCP_SOCKET s, uint8_t* buf, int size);
int HTTP_READ(TCP_SOCKET s, int(*cb)(const char* header, const char* value, void* param), void* param, char body_overread[2048]);
// type: 0x1-text 0x2-bin 0x8-close 0x9-ping 0xA-pong
int WS_WRITE(TCP_SOCKET s, const uint8_t* buf, int size, int split, int type);
int WS_READ(TCP_SOCKET s, uint8_t* buf, int size, int* type);
THREAD_HANDLE* THREAD_CREATE(void* (*entry)(void*), void* arg);
void* THREAD_JOIN(THREAD_HANDLE* thread);
bool THREAD_CREATE_DETACHED(void* (*entry)(void*), void* arg);
void THREAD_SLEEP(int ms);
MUTEX_HANDLE* MUTEX_CREATE();
void MUTEX_DELETE(MUTEX_HANDLE* mutex);
void MUTEX_LOCK(MUTEX_HANDLE* mutex);
void MUTEX_UNLOCK(MUTEX_HANDLE* mutex);
RWLOCK_HANDLE* RWLOCK_CREATE();
void RWLOCK_DELETE(RWLOCK_HANDLE* rwl);
void RWLOCK_READ_LOCK(RWLOCK_HANDLE* rwl);
void RWLOCK_READ_UNLOCK(RWLOCK_HANDLE* rwl);
void RWLOCK_WRITE_LOCK(RWLOCK_HANDLE* rwl);
void RWLOCK_WRITE_UNLOCK(RWLOCK_HANDLE* rwl);
unsigned int INTERLOCKED_DEC(volatile unsigned int* ptr);
unsigned int INTERLOCKED_INC(volatile unsigned int* ptr);
unsigned int INTERLOCKED_SUB(volatile unsigned int* ptr, unsigned int sub);
unsigned int INTERLOCKED_ADD(volatile unsigned int* ptr, unsigned int add);
////////////////////////////////////////////////////////////
#pragma pack(push,1)
struct STRUCT_REQ_JOIN
{
uint8_t token; // 'J'
char name[31];
};
struct STRUCT_RSP_JOIN
{
uint8_t token; // 'j'
uint8_t maxcli;
uint16_t id;
};
struct STRUCT_BRC_JOIN
{
uint8_t token; // 'j' -- (theres collision with STRUCT_RSP_JOIN, but RSP is sent in sync, only once prior to any broadcast)
uint8_t anim;
uint8_t frame;
uint8_t am; // action / mount
float pos[3];
float dir;
uint16_t id;
uint16_t sprite;
char name[32];
};
struct STRUCT_BRC_EXIT
{
uint8_t token; // 'e'
uint8_t pad;
uint16_t id;
};
struct STRUCT_REQ_POSE
{
uint8_t token; // 'P'
uint8_t anim;
uint8_t frame;
uint8_t am; // action / mount
float pos[3];
float dir;
uint16_t sprite;
};
struct STRUCT_BRC_POSE
{
uint8_t token; // 'p'
uint8_t anim;
uint8_t frame;
uint8_t am; // action / mount
float pos[3];
float dir;
uint16_t sprite;
uint16_t id;
};
struct STRUCT_REQ_TALK
{
uint8_t token; // 'T'
uint8_t len;
uint8_t str[256]; // trim to actual size!
};
struct STRUCT_BRC_TALK
{
uint8_t token; // 't'
uint8_t len;
uint16_t id;
uint8_t str[256]; // trim to actual size!
};
struct STRUCT_REQ_LAG
{
uint8_t token; // 'L'
uint8_t stamp[3];
};
struct STRUCT_RSP_LAG
{
uint8_t token; // 'l'
uint8_t stamp[3];
};
#pragma pack(pop)