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