ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/Daodan/MSVC/Flatline.h
Revision: 581
Committed: Fri Jan 14 08:36:34 2011 UTC (14 years, 8 months ago) by gumby
Content type: text/x-chdr
File size: 5927 byte(s)
Log Message:
Wow new netcode

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
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 typedef struct {
148 float MouseDeltaX;
149 float MouseDeltaY;
150 uint32_t Actions1;
151 uint32_t Actions2;
152 } player_input;
153
154 //used for storing data about each player
155 typedef struct {
156 int FLATLINE;
157 char id;
158 int packet_index;
159 union
160 {
161 char data[1080];
162 connect_reply connect_reply;
163 connect_send connect_send;
164 input_struct input_struct;
165 new_player new_player;
166 server_status server_status;
167 player_data player_data;
168 rare_sync_data rare_sync_data;
169 uint16_t sync_request;
170 flatline_event flatline_event;
171 uint32_t ping;
172 player_input all_input[32];
173 };
174 } flatline_packet;
175 #define FLATLINE_HEADER (sizeof(flatline_packet)-sizeof(char)*1080)
176 //#define FLATLINE_PACKET_SIZE sizeof(flatline_packet)
177
178
179 bool FLrServer_PacketCallback(char* data, int datalen, int from);
180 bool FLrServer_Run();
181 bool FLrClient_Run(flatline_packet* packet);
182 extern int sock;
183
184 enum {
185 NULL_PACKET, //Don't use. ;)
186 CONNECT_SEND,
187 CONNECT_REPLY,
188 STATUS,
189 MESSAGE,
190 CHANGE_NAME,
191 ECHO,
192 NEW_PLAYER,
193 PLAYER_INPUT,
194 PLAYER_DATA,
195 RARE_SYNC_DATA,
196 RARE_SYNC_DATA_REQUEST,
197 FLATLINE_EVENT,
198 PK_PING,
199 PK_PONG,
200 PK_ALL_INPUT,
201 };
202
203 enum FlatlineEvent {
204 EV_RESPAWN,
205 EV_DISCONNECT,
206 EV_DOOR_OPEN,
207 EV_CONSOLE_USE,
208 EV_MAX,
209 };
210
211
212
213 enum {
214 STATE_ALIVE,
215 STATE_DEAD,
216 };
217 enum {
218 PF_HOST,
219 PF_BOT,
220 PF_SCRIPTEDAI,
221 };
222 typedef struct {
223 int ip;
224 char name[32];
225 char country[2];
226 Character* Chr;
227 uint16_t spawnnumber;
228 uint16_t list_slot;
229 float MouseDeltaX;
230 float MouseDeltaY;
231 uint32_t Actions1;
232 uint32_t Actions2;
233 unsigned int LastInputTime;
234 input_struct CacheInput;
235 player_data player_data;
236 unsigned int rare_sync_index;
237 void* OldClass;
238 Inventory Inventory;
239 uint16_t state;
240 int flags;
241 int DeathTime;
242 uint32_t Ping;
243 bool DataApplied;
244 } player_info;
245
246 player_info * FLr_FindEmptySlot();
247 uint16_t FLr_FindEmptyListSlot();
248 void * ONICALL FLrInput_Update_Keys(void);
249
250 void NetCatchError();
251 #define MAX_PLAYERS 32
252 #define CONNECTION_TIMEOUT 15
253 #define MAX_CONNECTIONS 32
254 #define NetTCPSocket_Send NetUDPSocket_Send
255 #define NetTCPServer_Send NetUDPServer_Send
256 extern int client_sock;
257 //these two could probably be combined
258 extern sockaddr_in client_address;
259 extern sockaddr_in address;
260 extern player_info Players[];
261 extern player_info * PlayerList[];
262
263 int UDPServer_SendToAll(void* packet, int size);
264
265 extern bool client_connected;
266 extern bool server_started;
267 extern char player_name[];
268
269 void FLrRun_Scores();
270 void FLrPlayerDisconnect( int Player );
271 void FLrPlayerRespawn( int Player );
272 int FLrEvent_GetNumArgs( int eventIndex );
273
274 extern unsigned int lastPingTime;
275 #endif