1 |
#pragma once |
2 |
#ifndef FLATLINE_H |
3 |
#define FLATLINE_H |
4 |
|
5 |
#include <stdlib.h> |
6 |
#include <stdio.h> |
7 |
#include <time.h> |
8 |
//#define DDrStartupMessage printf |
9 |
|
10 |
#include <string.h> |
11 |
#include "bool.h" |
12 |
////#include <stdint.h> |
13 |
|
14 |
#define thread __thread |
15 |
|
16 |
#ifdef WIN32 |
17 |
#include <winsock2.h> |
18 |
#include "Flatline_Win32.h" |
19 |
#else |
20 |
#include <sys/ioctl.h> |
21 |
#include <sys/types.h> |
22 |
#include <sys/socket.h> |
23 |
#include <unistd.h> |
24 |
#include <stropts.h> |
25 |
#include <arpa/inet.h> |
26 |
#include <netinet/in.h> |
27 |
|
28 |
#define NetPlatform_Initalize() /* */ |
29 |
#define NetPlatform_Shutdown() /* */ |
30 |
#define closesocket close |
31 |
#define ioctlsocket ioctl |
32 |
#endif |
33 |
|
34 |
#include "Daodan.h" |
35 |
#include "BFW_Utility.h" |
36 |
#include "Daodan_Console.h" |
37 |
#include "Oni_Character.h" |
38 |
#include "Flatline_Packet.h" |
39 |
|
40 |
#define pad1_size (sizeof(int64_t) - sizeof(short)) |
41 |
#define pad2_size (128 - (sizeof(short) + pad1_size + sizeof(int64_t))) |
42 |
|
43 |
#define breakpoint asm("int3") |
44 |
|
45 |
typedef struct { |
46 |
short ss_family; |
47 |
char pad1[pad1_size]; |
48 |
uint64_t pad64; |
49 |
char pad2[pad2_size]; |
50 |
} sockaddr_storage; |
51 |
|
52 |
typedef struct sockaddr sockaddr; |
53 |
typedef struct sockaddr_in sockaddr_in; |
54 |
typedef sockaddr_storage sockaddr_in6; |
55 |
|
56 |
bool NetUDPServer_Listen(uint16_t port, bool (*packet_callback)(char* data, int datalen, int from)); |
57 |
bool NetUDPServer_Send(sockaddr* address, char* data, int datalen); |
58 |
|
59 |
int NetUDPSocket_Create(uint16_t port); |
60 |
int NetUDPSocket_Send(int socket, const sockaddr* address, const char* data, int datalen); |
61 |
void NetUDPSocket_Close(int sock); |
62 |
bool NetUDPSocket_Recieve(int socket, sockaddr_storage* address, char* data, uint16_t* datalen); |
63 |
|
64 |
DWORD WINAPI StartServer(void* lol); |
65 |
DWORD WINAPI StartClient(void* lol); |
66 |
|
67 |
|
68 |
//initial connection |
69 |
typedef struct { |
70 |
char country[2]; |
71 |
char name[256]; |
72 |
} connect_send; //signature="CONNECT\0" |
73 |
|
74 |
//reply to connection. |
75 |
//goodtogo is if it is going to let you in |
76 |
//message is optional, only used for denial message |
77 |
typedef struct { |
78 |
bool goodtogo; |
79 |
int player_slot; |
80 |
char message[256]; |
81 |
} connect_reply; |
82 |
|
83 |
//um, status of the server? :/ |
84 |
//probably obsolete. revive again once i do something crazy |
85 |
//like make a master server |
86 |
typedef struct { |
87 |
char name[256]; |
88 |
uint32_t numplayers; //signature="STATUS\0\0" |
89 |
} server_status; |
90 |
|
91 |
typedef struct { |
92 |
uint16_t Playernumber; |
93 |
CharacterObject Character; |
94 |
} new_player; |
95 |
|
96 |
//extern int update_rate; |
97 |
|
98 |
typedef struct { |
99 |
float MouseDeltaX; |
100 |
float MouseDeltaY; |
101 |
uint32_t Actions1; |
102 |
uint32_t Actions2; |
103 |
unsigned int Time; |
104 |
} input_struct; |
105 |
|
106 |
//TODO: |
107 |
//Varient |
108 |
//Figure out + fix overlays |
109 |
//AC->HeadFacing |
110 |
//AC->HeadPitch |
111 |
typedef struct { |
112 |
uint16_t throwing; |
113 |
uint16_t throwFrame; |
114 |
char throwName[32]; |
115 |
} td; |
116 |
/* |
117 |
typedef struct { |
118 |
uint16_t PlayerNum; |
119 |
//Vector3 Position; |
120 |
|
121 |
//float Facing; |
122 |
//float DesiredFacing; |
123 |
|
124 |
float UD; |
125 |
float LR; |
126 |
|
127 |
uint32_t Health; |
128 |
uint32_t MaxHealth; |
129 |
//input_struct Inputs; |
130 |
int rare_sync_index; |
131 |
char Animation[32]; |
132 |
uint16_t Frame; |
133 |
td throw_data; |
134 |
int Kills; |
135 |
int Damage; |
136 |
int Deaths; |
137 |
uint16_t Ping; |
138 |
|
139 |
} player_data; |
140 |
|
141 |
//todo, move health in... |
142 |
/*typedef struct { |
143 |
short unsigned int PlayerNum; |
144 |
unsigned int index; |
145 |
Inventory Inventory; |
146 |
char Class[32]; |
147 |
} rare_sync_data; |
148 |
*/ |
149 |
typedef struct { |
150 |
unsigned int event_index; |
151 |
int intArray[]; |
152 |
} flatline_event; |
153 |
/* |
154 |
typedef struct { |
155 |
int16_t PlayerNum; |
156 |
float MouseDeltaX; |
157 |
float MouseDeltaY; |
158 |
uint32_t Actions1; |
159 |
uint32_t Actions2; |
160 |
float Facing; |
161 |
float DesiredFacing; |
162 |
Vector3 Position; |
163 |
} player_input; |
164 |
*/ |
165 |
//used for storing data about each player |
166 |
typedef struct { |
167 |
//int FLATLINE; |
168 |
int id; |
169 |
int packet_index; |
170 |
union |
171 |
{ |
172 |
char data[1080]; |
173 |
connect_reply connect_reply; |
174 |
connect_send connect_send; |
175 |
input_struct input_struct; |
176 |
new_player new_player; |
177 |
server_status server_status; |
178 |
//player_data player_data; |
179 |
//rare_sync_data rare_sync_data; |
180 |
uint16_t sync_request; |
181 |
flatline_event flatline_event; |
182 |
uint32_t ping; |
183 |
//player_input all_input[33]; |
184 |
}; |
185 |
} flatline_packet; |
186 |
#define FLATLINE_HEADER (sizeof(flatline_packet)-sizeof(char)*1080) |
187 |
//#define FLATLINE_PACKET_SIZE sizeof(flatline_packet) |
188 |
|
189 |
|
190 |
bool FLrServer_PacketCallback(char* data, int datalen, int from); |
191 |
bool FLrServer_Run(); |
192 |
bool FLrClient_Run(flatline_packet* packet); |
193 |
extern int sock; |
194 |
|
195 |
enum { |
196 |
NULL_PACKET, //Don't use. ;) |
197 |
CONNECT_SEND, |
198 |
CONNECT_REPLY, |
199 |
STATUS, |
200 |
MESSAGE, |
201 |
CHANGE_NAME, |
202 |
ECHO, |
203 |
NEW_PLAYER, |
204 |
PLAYER_INPUT, |
205 |
//PLAYER_DATA, |
206 |
//RARE_SYNC_DATA, |
207 |
//RARE_SYNC_DATA_REQUEST, |
208 |
FLATLINE_EVENT, |
209 |
PK_PING, |
210 |
PK_PONG, |
211 |
//PK_ALL_INPUT, |
212 |
PK_PLAYER_DATA, |
213 |
}; |
214 |
|
215 |
enum FlatlineEvent { |
216 |
EV_RESPAWN, |
217 |
EV_KILLED, |
218 |
EV_DISCONNECT, |
219 |
EV_DOOR_OPEN, |
220 |
EV_CONSOLE_USE, |
221 |
EV_MAX, |
222 |
}; |
223 |
|
224 |
|
225 |
typedef struct { |
226 |
//Server Only |
227 |
bool PleaseUpdateAllPlayers; |
228 |
//Client stuff (can be used by server "client") |
229 |
|
230 |
//Move from random scattered bools to these, please. |
231 |
bool ClientConnected; |
232 |
unsigned int ClientSlot; |
233 |
bool ServerStatus; |
234 |
} multiplayer_status; |
235 |
|
236 |
enum { |
237 |
STATE_ALIVE, |
238 |
STATE_DEAD, |
239 |
}; |
240 |
enum { |
241 |
PF_HOST, |
242 |
PF_BOT, |
243 |
PF_SCRIPTEDAI, |
244 |
}; |
245 |
typedef struct { |
246 |
int ip; |
247 |
char name[32]; |
248 |
char country[2]; |
249 |
Character* Chr; |
250 |
uint16_t spawnnumber; |
251 |
uint16_t list_slot; |
252 |
|
253 |
PlayerInput InputFromClient; |
254 |
|
255 |
//////////////////////////// |
256 |
//Sync stuff |
257 |
//////////////////////////// |
258 |
uint16_t UpdateFlags; |
259 |
|
260 |
PlayerInput Input; |
261 |
PlayerHealth Health; |
262 |
PlayerFacing Facings; |
263 |
PlayerScore Score; |
264 |
void* Animation; |
265 |
uint16_t Frame; |
266 |
PlayerThrowData ThrowData; |
267 |
void* Class; |
268 |
PlayerInventory Inventory; |
269 |
Vector3 Position; |
270 |
//////////////////////////// |
271 |
bool HasAppliedThrow; |
272 |
|
273 |
unsigned int LastInputTime; |
274 |
|
275 |
|
276 |
|
277 |
uint16_t state; |
278 |
int flags; |
279 |
int DeathTime; |
280 |
uint32_t Ping; |
281 |
bool DataApplied; |
282 |
bool NeedToSetFP; |
283 |
uint32_t ShapeshiftCooldown; |
284 |
} player_info; |
285 |
|
286 |
player_info * FLr_FindEmptySlot(); |
287 |
uint16_t FLr_FindEmptyListSlot(); |
288 |
void * ONICALL FLrInput_Update_Keys(void); |
289 |
|
290 |
void NetCatchError(); |
291 |
#define MAX_PLAYERS 32 |
292 |
#define CONNECTION_TIMEOUT 15 |
293 |
#define MAX_CONNECTIONS 32 |
294 |
#define NetTCPSocket_Send NetUDPSocket_Send |
295 |
#define NetTCPServer_Send NetUDPServer_Send |
296 |
extern int client_sock; |
297 |
//these two could probably be combined |
298 |
extern sockaddr_in client_address; |
299 |
extern sockaddr_in address; |
300 |
extern player_info Players[]; |
301 |
extern player_info * PlayerList[]; |
302 |
extern multiplayer_status MultiplayerStatus; |
303 |
int UDPServer_SendToAll(void* packet, int size); |
304 |
|
305 |
extern bool client_connected; |
306 |
extern bool server_started; |
307 |
extern char player_name[]; |
308 |
|
309 |
void FLrRun_Scores(); |
310 |
void FLrPlayerDisconnect( int Player ); |
311 |
void FLrPlayerRespawn( int Player ); |
312 |
int FLrEvent_GetNumArgs( int eventIndex ); |
313 |
bool FlatlineInitialize(); |
314 |
|
315 |
bool DoWeUpdateThis( uint16_t BitSet, uint16_t Flag ); |
316 |
|
317 |
extern unsigned int lastPingTime; |
318 |
#endif |