source: Daodan/MSVC/Flatline.h@ 847

Last change on this file since 847 was 589, checked in by gumby, 13 years ago

stuff

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