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 |
|
---|
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...
|
---|
141 | typedef struct {
|
---|
142 | short unsigned int PlayerNum;
|
---|
143 | unsigned int index;
|
---|
144 | Inventory Inventory;
|
---|
145 | char Class[32];
|
---|
146 | } rare_sync_data;
|
---|
147 |
|
---|
148 | typedef struct {
|
---|
149 | unsigned int event_index;
|
---|
150 | int intArray[];
|
---|
151 | } flatline_event;
|
---|
152 |
|
---|
153 | typedef 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
|
---|
165 | typedef 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 |
|
---|
189 | bool FLrServer_PacketCallback(char* data, int datalen, int from);
|
---|
190 | bool FLrServer_Run();
|
---|
191 | bool FLrClient_Run(flatline_packet* packet);
|
---|
192 | extern int sock;
|
---|
193 |
|
---|
194 | enum {
|
---|
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 |
|
---|
213 | enum FlatlineEvent {
|
---|
214 | EV_RESPAWN,
|
---|
215 | EV_DISCONNECT,
|
---|
216 | EV_DOOR_OPEN,
|
---|
217 | EV_CONSOLE_USE,
|
---|
218 | EV_MAX,
|
---|
219 | };
|
---|
220 |
|
---|
221 |
|
---|
222 | typedef 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 |
|
---|
233 | enum {
|
---|
234 | STATE_ALIVE,
|
---|
235 | STATE_DEAD,
|
---|
236 | };
|
---|
237 | enum {
|
---|
238 | PF_HOST,
|
---|
239 | PF_BOT,
|
---|
240 | PF_SCRIPTEDAI,
|
---|
241 | };
|
---|
242 | typedef 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 |
|
---|
275 | player_info * FLr_FindEmptySlot();
|
---|
276 | uint16_t FLr_FindEmptyListSlot();
|
---|
277 | void * ONICALL FLrInput_Update_Keys(void);
|
---|
278 |
|
---|
279 | void 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
|
---|
285 | extern int client_sock;
|
---|
286 | //these two could probably be combined
|
---|
287 | extern sockaddr_in client_address;
|
---|
288 | extern sockaddr_in address;
|
---|
289 | extern player_info Players[];
|
---|
290 | extern player_info * PlayerList[];
|
---|
291 | extern multiplayer_status MultiplayerStatus;
|
---|
292 | int UDPServer_SendToAll(void* packet, int size);
|
---|
293 |
|
---|
294 | extern bool client_connected;
|
---|
295 | extern bool server_started;
|
---|
296 | extern char player_name[];
|
---|
297 |
|
---|
298 | void FLrRun_Scores();
|
---|
299 | void FLrPlayerDisconnect( int Player );
|
---|
300 | void FLrPlayerRespawn( int Player );
|
---|
301 | int FLrEvent_GetNumArgs( int eventIndex );
|
---|
302 | bool FlatlineInitialize();
|
---|
303 | extern unsigned int lastPingTime;
|
---|
304 | #endif
|
---|