source: Daodan/src/flatline/Flatline.h@ 891

Last change on this file since 891 was 881, checked in by alloc, 11 years ago

Daodan: Some flatline cleanups

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