ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/Daodan/MSVC/Flatline.h
Revision: 586
Committed: Wed Feb 2 08:17:19 2011 UTC (14 years, 8 months ago) by gumby
Content type: text/x-chdr
File size: 6955 byte(s)
Log Message:
stuff

File Contents

# Content
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 #include "Flatline_Packet.h"
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 float DesiredFacing;
104 //unsigned int Time;
105 } input_struct;
106
107 //TODO:
108 //Varient
109 //Figure out + fix overlays
110 //AC->HeadFacing
111 //AC->HeadPitch
112 typedef struct {
113 uint16_t throwing;
114 uint16_t throwFrame;
115 char throwName[32];
116 } td;
117 /*
118 typedef struct {
119 uint16_t PlayerNum;
120 //Vector3 Position;
121
122 //float Facing;
123 //float DesiredFacing;
124
125 float UD;
126 float LR;
127
128 uint32_t Health;
129 uint32_t MaxHealth;
130 //input_struct Inputs;
131 int rare_sync_index;
132 char Animation[32];
133 uint16_t Frame;
134 td throw_data;
135 int Kills;
136 int Damage;
137 int Deaths;
138 uint16_t Ping;
139
140 } player_data;
141
142 //todo, move health in...
143 /*typedef struct {
144 short unsigned int PlayerNum;
145 unsigned int index;
146 Inventory Inventory;
147 char Class[32];
148 } rare_sync_data;
149 */
150 typedef struct {
151 unsigned int event_index;
152 int intArray[];
153 } flatline_event;
154 /*
155 typedef struct {
156 int16_t PlayerNum;
157 float MouseDeltaX;
158 float MouseDeltaY;
159 uint32_t Actions1;
160 uint32_t Actions2;
161 float Facing;
162 float DesiredFacing;
163 Vector3 Position;
164 } player_input;
165 */
166 //used for storing data about each player
167 typedef struct {
168 //int FLATLINE;
169 int id;
170 int packet_index;
171 union
172 {
173 char data[1080];
174 connect_reply connect_reply;
175 connect_send connect_send;
176 input_struct input_struct;
177 new_player new_player;
178 server_status server_status;
179 //player_data player_data;
180 //rare_sync_data rare_sync_data;
181 uint16_t sync_request;
182 flatline_event flatline_event;
183 uint32_t ping;
184 //player_input all_input[33];
185 uint32_t integer; //generic integer ;)
186 };
187 } flatline_packet;
188 #define FLATLINE_HEADER (sizeof(flatline_packet)-sizeof(char)*1080)
189 //#define FLATLINE_PACKET_SIZE sizeof(flatline_packet)
190
191
192 bool FLrServer_PacketCallback(char* data, int datalen, int from);
193 bool FLrServer_Run();
194 bool FLrClient_Run(flatline_packet* packet);
195 extern int sock;
196
197 enum {
198 NULL_PACKET, //Don't use. ;)
199 CONNECT_SEND,
200 CONNECT_REPLY,
201 STATUS,
202 MESSAGE,
203 CHANGE_NAME,
204 ECHO,
205 NEW_PLAYER,
206 PLAYER_INPUT,
207 //PLAYER_DATA,
208 //RARE_SYNC_DATA,
209 //RARE_SYNC_DATA_REQUEST,
210 FLATLINE_EVENT,
211 PK_PING,
212 PK_PONG,
213 //PK_ALL_INPUT,
214 PK_PLAYER_DATA,
215 PK_MISSING_PLAYER,
216 };
217
218 enum FlatlineEvent {
219 EV_RESPAWN,
220 EV_KILLED,
221 EV_DISCONNECT,
222 EV_DOOR_OPEN,
223 EV_CONSOLE_USE,
224 EV_MAX,
225 };
226
227
228 typedef struct {
229 //Server Only
230 bool PleaseUpdateAllPlayers;
231 //Client stuff (can be used by server "client")
232
233 //Move from random scattered bools to these, please.
234 bool ClientConnected;
235 unsigned int ClientSlot;
236 bool ServerStatus;
237 } multiplayer_status;
238
239 enum {
240 STATE_ALIVE,
241 STATE_DEAD,
242 };
243 enum {
244 PF_HOST,
245 PF_BOT,
246 PF_SCRIPTEDAI,
247 };
248 typedef struct {
249 int ip;
250 char name[32];
251 char country[2];
252 Character* Chr;
253 uint16_t spawnnumber;
254 uint16_t list_slot;
255
256 PlayerInput InputFromClient;
257 float FacingFromClient;
258
259 ////////////////////////////
260 //Sync stuff
261 ////////////////////////////
262 uint16_t UpdateFlags;
263
264 PlayerInput Input;
265 PlayerHealth Health;
266 PlayerFacing Facings;
267 PlayerScore Score;
268 void* Animation;
269 char AnimationString[32];
270 uint16_t Frame;
271 PlayerThrowData ThrowData;
272 void* Class;
273 char ClassString[32];
274 PlayerInventory Inventory;
275 Vector3 Position;
276 ////////////////////////////
277 bool HasAppliedThrow;
278
279 unsigned int LastInputTime;
280
281
282 uint16_t state;
283 int flags;
284 int DeathTime;
285 uint32_t Ping;
286 bool DataApplied;
287 bool NeedToSetFP;
288 uint32_t ShapeshiftCooldown;
289 } player_info;
290
291 player_info * FLr_FindEmptySlot();
292 uint16_t FLr_FindEmptyListSlot();
293 void * ONICALL FLrInput_Update_Keys(void);
294
295 void NetCatchError();
296 #define MAX_PLAYERS 32
297 #define CONNECTION_TIMEOUT 15
298 #define MAX_CONNECTIONS 32
299 #define NetTCPSocket_Send NetUDPSocket_Send
300 #define NetTCPServer_Send NetUDPServer_Send
301 extern int client_sock;
302 //these two could probably be combined
303 extern sockaddr_in client_address;
304 extern sockaddr_in address;
305 extern player_info Players[];
306 extern player_info * PlayerList[];
307 extern multiplayer_status MultiplayerStatus;
308 int UDPServer_SendToAll(void* packet, int size);
309
310 extern bool client_connected;
311 extern bool server_started;
312 extern char player_name[];
313
314 void FLrRun_Scores();
315 void FLrPlayerDisconnect( int Player );
316 void FLrPlayerRespawn( int Player );
317 int FLrEvent_GetNumArgs( int eventIndex );
318 bool FlatlineInitialize();
319
320 bool DoWeUpdateThis( uint16_t BitSet, uint16_t Flag );
321
322 extern unsigned int lastPingTime;
323 #endif