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