source: Daodan/MSVC/Flatline.h@ 582

Last change on this file since 582 was 582, checked in by gumby, 14 years ago

Hangs on death, but netcode is improved.

File size: 6.4 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#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
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
45typedef struct {
46 short ss_family;
47 char pad1[pad1_size];
48 uint64_t pad64;
49 char pad2[pad2_size];
50} sockaddr_storage;
51
52typedef struct sockaddr sockaddr;
53typedef struct sockaddr_in sockaddr_in;
54typedef sockaddr_storage sockaddr_in6;
55
56bool NetUDPServer_Listen(uint16_t port, bool (*packet_callback)(char* data, int datalen, int from));
57bool NetUDPServer_Send(sockaddr* address, char* data, int datalen);
58
59int NetUDPSocket_Create(uint16_t port);
60int NetUDPSocket_Send(int socket, const sockaddr* address, const char* data, int datalen);
61void NetUDPSocket_Close(int sock);
62bool NetUDPSocket_Recieve(int socket, sockaddr_storage* address, char* data, uint16_t* datalen);
63
64DWORD WINAPI StartServer(void* lol);
65DWORD WINAPI StartClient(void* lol);
66
67
68//initial connection
69typedef 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
77typedef 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
86typedef struct {
87 char name[256];
88 uint32_t numplayers; //signature="STATUS\0\0"
89} server_status;
90
91typedef struct {
92 uint16_t Playernumber;
93 CharacterObject Character;
94} new_player;
95
96//extern int update_rate;
97
98typedef 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
111typedef struct {
112 uint16_t throwing;
113 uint16_t throwFrame;
114 char throwName[32];
115} td;
116typedef struct {
117 uint16_t PlayerNum;
118 //Vector3 Position;
119
120 //float Facing;
121 //float DesiredFacing;
122
123 float UD;
124 float LR;
125
126 uint32_t Health;
127 uint32_t MaxHealth;
128 //input_struct Inputs;
129 int rare_sync_index;
130 char Animation[32];
131 uint16_t Frame;
132 td throw_data;
133 int Kills;
134 int Damage;
135 int Deaths;
136 uint16_t Ping;
137
138} player_data;
139
140//todo, move health in...
141typedef struct {
142 short unsigned int PlayerNum;
143 unsigned int index;
144 Inventory Inventory;
145 char Class[32];
146} rare_sync_data;
147
148typedef struct {
149 unsigned int event_index;
150 int intArray[];
151} flatline_event;
152
153typedef struct {
154 int16_t PlayerNum;
155 float MouseDeltaX;
156 float MouseDeltaY;
157 uint32_t Actions1;
158 uint32_t Actions2;
159 float Facing;
160 float DesiredFacing;
161 Vector3 Position;
162} player_input;
163
164//used for storing data about each player
165typedef struct {
166 int FLATLINE;
167 char id;
168 int packet_index;
169 union
170 {
171 char data[1080];
172 connect_reply connect_reply;
173 connect_send connect_send;
174 input_struct input_struct;
175 new_player new_player;
176 server_status server_status;
177 player_data player_data;
178 rare_sync_data rare_sync_data;
179 uint16_t sync_request;
180 flatline_event flatline_event;
181 uint32_t ping;
182 player_input all_input[32];
183 };
184} flatline_packet;
185#define FLATLINE_HEADER (sizeof(flatline_packet)-sizeof(char)*1080)
186//#define FLATLINE_PACKET_SIZE sizeof(flatline_packet)
187
188
189bool FLrServer_PacketCallback(char* data, int datalen, int from);
190bool FLrServer_Run();
191bool FLrClient_Run(flatline_packet* packet);
192extern int sock;
193
194enum {
195 NULL_PACKET, //Don't use. ;)
196 CONNECT_SEND,
197 CONNECT_REPLY,
198 STATUS,
199 MESSAGE,
200 CHANGE_NAME,
201 ECHO,
202 NEW_PLAYER,
203 PLAYER_INPUT,
204 PLAYER_DATA,
205 RARE_SYNC_DATA,
206 RARE_SYNC_DATA_REQUEST,
207 FLATLINE_EVENT,
208 PK_PING,
209 PK_PONG,
210 PK_ALL_INPUT,
211};
212
213enum FlatlineEvent {
214 EV_RESPAWN,
215 EV_DISCONNECT,
216 EV_DOOR_OPEN,
217 EV_CONSOLE_USE,
218 EV_MAX,
219};
220
221
222typedef struct {
223 //Server Only
224 bool PleaseUpdateAllPlayers;
225 //Client stuff (can be used by server "client")
226
227 //Move from random scattered bools to these, please.
228 bool ClientConnected;
229 unsigned int ClientSlot;
230 bool ServerStatus;
231} multiplayer_status;
232
233enum {
234 STATE_ALIVE,
235 STATE_DEAD,
236};
237enum {
238 PF_HOST,
239 PF_BOT,
240 PF_SCRIPTEDAI,
241};
242typedef struct {
243 int ip;
244 char name[32];
245 char country[2];
246 Character* Chr;
247 uint16_t spawnnumber;
248 uint16_t list_slot;
249
250 //Todo: move into struct for slightly faster copying
251 float MouseDeltaX;
252 float MouseDeltaY;
253 uint32_t Actions1;
254 uint32_t Actions2;
255 float Facing;
256 float DesiredFacing;
257 //float Height;
258 Vector3 Position;
259
260 unsigned int LastInputTime;
261 input_struct CacheInput;
262 player_data player_data;
263 unsigned int rare_sync_index;
264 void* OldClass;
265 Inventory Inventory;
266 uint16_t state;
267 int flags;
268 int DeathTime;
269 uint32_t Ping;
270 bool DataApplied;
271
272 uint32_t ShapeshiftCooldown;
273} player_info;
274
275player_info * FLr_FindEmptySlot();
276uint16_t FLr_FindEmptyListSlot();
277void * ONICALL FLrInput_Update_Keys(void);
278
279void 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
285extern int client_sock;
286//these two could probably be combined
287extern sockaddr_in client_address;
288extern sockaddr_in address;
289extern player_info Players[];
290extern player_info * PlayerList[];
291extern multiplayer_status MultiplayerStatus;
292int UDPServer_SendToAll(void* packet, int size);
293
294extern bool client_connected;
295extern bool server_started;
296extern char player_name[];
297
298void FLrRun_Scores();
299void FLrPlayerDisconnect( int Player );
300void FLrPlayerRespawn( int Player );
301int FLrEvent_GetNumArgs( int eventIndex );
302bool FlatlineInitialize();
303extern unsigned int lastPingTime;
304#endif
Note: See TracBrowser for help on using the repository browser.