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
RevLine 
[567]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? :/
[578]84//probably obsolete. revive again once i do something crazy
85//like make a master server
[567]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
[568]96//extern int update_rate;
[567]97
98typedef struct {
99 float MouseDeltaX;
100 float MouseDeltaY;
101 uint32_t Actions1;
102 uint32_t Actions2;
[568]103 unsigned int Time;
[567]104} input_struct;
105
106//TODO:
107//Varient
108//Figure out + fix overlays
109//AC->HeadFacing
110//AC->HeadPitch
111typedef struct {
[573]112 uint16_t throwing;
113 uint16_t throwFrame;
114 char throwName[32];
115} td;
116typedef struct {
[567]117 uint16_t PlayerNum;
[582]118 //Vector3 Position;
119
120 //float Facing;
121 //float DesiredFacing;
122
123 float UD;
124 float LR;
125
[567]126 uint32_t Health;
127 uint32_t MaxHealth;
[581]128 //input_struct Inputs;
[568]129 int rare_sync_index;
[573]130 char Animation[32];
[567]131 uint16_t Frame;
[573]132 td throw_data;
133 int Kills;
134 int Damage;
135 int Deaths;
[580]136 uint16_t Ping;
[582]137
[567]138} player_data;
139
[568]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
[573]148typedef struct {
149 unsigned int event_index;
150 int intArray[];
151} flatline_event;
152
[581]153typedef struct {
[582]154 int16_t PlayerNum;
[581]155 float MouseDeltaX;
156 float MouseDeltaY;
157 uint32_t Actions1;
158 uint32_t Actions2;
[582]159 float Facing;
160 float DesiredFacing;
161 Vector3 Position;
[581]162} player_input;
163
[567]164//used for storing data about each player
165typedef struct {
166 int FLATLINE;
167 char id;
168 int packet_index;
[573]169 union
[567]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;
[568]178 rare_sync_data rare_sync_data;
179 uint16_t sync_request;
[573]180 flatline_event flatline_event;
[580]181 uint32_t ping;
[581]182 player_input all_input[32];
[567]183 };
184} flatline_packet;
[568]185#define FLATLINE_HEADER (sizeof(flatline_packet)-sizeof(char)*1080)
[567]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 {
[579]195 NULL_PACKET, //Don't use. ;)
[567]196 CONNECT_SEND,
197 CONNECT_REPLY,
198 STATUS,
199 MESSAGE,
200 CHANGE_NAME,
201 ECHO,
202 NEW_PLAYER,
203 PLAYER_INPUT,
204 PLAYER_DATA,
[568]205 RARE_SYNC_DATA,
206 RARE_SYNC_DATA_REQUEST,
[573]207 FLATLINE_EVENT,
[580]208 PK_PING,
209 PK_PONG,
[581]210 PK_ALL_INPUT,
[567]211};
212
[573]213enum FlatlineEvent {
214 EV_RESPAWN,
215 EV_DISCONNECT,
216 EV_DOOR_OPEN,
[574]217 EV_CONSOLE_USE,
[573]218 EV_MAX,
219};
[567]220
[573]221
[582]222typedef struct {
223 //Server Only
224 bool PleaseUpdateAllPlayers;
225 //Client stuff (can be used by server "client")
[573]226
[582]227 //Move from random scattered bools to these, please.
228 bool ClientConnected;
229 unsigned int ClientSlot;
230 bool ServerStatus;
231} multiplayer_status;
232
[573]233enum {
234 STATE_ALIVE,
235 STATE_DEAD,
236};
237enum {
238 PF_HOST,
239 PF_BOT,
240 PF_SCRIPTEDAI,
241};
[567]242typedef struct {
243 int ip;
[568]244 char name[32];
[567]245 char country[2];
246 Character* Chr;
247 uint16_t spawnnumber;
248 uint16_t list_slot;
[582]249
250 //Todo: move into struct for slightly faster copying
[568]251 float MouseDeltaX;
252 float MouseDeltaY;
[567]253 uint32_t Actions1;
254 uint32_t Actions2;
[582]255 float Facing;
256 float DesiredFacing;
257 //float Height;
258 Vector3 Position;
259
[568]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;
[573]266 uint16_t state;
267 int flags;
[579]268 int DeathTime;
[580]269 uint32_t Ping;
270 bool DataApplied;
[582]271
272 uint32_t ShapeshiftCooldown;
[567]273} player_info;
274
275player_info * FLr_FindEmptySlot();
276uint16_t FLr_FindEmptyListSlot();
277void * ONICALL FLrInput_Update_Keys(void);
278
279void NetCatchError();
[580]280#define MAX_PLAYERS 32
[567]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[];
[582]291extern multiplayer_status MultiplayerStatus;
[567]292int UDPServer_SendToAll(void* packet, int size);
[580]293
[567]294extern bool client_connected;
295extern bool server_started;
296extern char player_name[];
[580]297
[573]298void FLrRun_Scores();
[579]299void FLrPlayerDisconnect( int Player );
300void FLrPlayerRespawn( int Player );
[573]301int FLrEvent_GetNumArgs( int eventIndex );
[582]302bool FlatlineInitialize();
[580]303extern unsigned int lastPingTime;
[567]304#endif
Note: See TracBrowser for help on using the repository browser.