ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/Daodan/MSVC/Flatline.h
Revision: 573
Committed: Thu Sep 9 09:27:04 2010 UTC (15 years, 1 month ago) by gumby
Content type: text/x-chdr
File size: 5445 byte(s)
Log Message:

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 typedef struct {
85 char name[256];
86 uint32_t numplayers; //signature="STATUS\0\0"
87 } server_status;
88
89 typedef struct {
90 uint16_t Playernumber;
91 CharacterObject Character;
92 } new_player;
93
94 //extern int update_rate;
95
96 typedef struct {
97 float MouseDeltaX;
98 float MouseDeltaY;
99 uint32_t Actions1;
100 uint32_t Actions2;
101 unsigned int Time;
102 } input_struct;
103
104 //TODO:
105 //Varient
106 //Figure out + fix overlays
107 //AC->HeadFacing
108 //AC->HeadPitch
109 typedef struct {
110 uint16_t throwing;
111 uint16_t throwFrame;
112 char throwName[32];
113 } td;
114 typedef struct {
115 uint16_t PlayerNum;
116 Vector3 Position;
117 float Facing;
118 float DesiredFacing;
119 uint32_t Health;
120 uint32_t MaxHealth;
121 input_struct Inputs;
122 int rare_sync_index;
123 char Animation[32];
124 uint16_t Frame;
125 td throw_data;
126 int Kills;
127 int Damage;
128 int Deaths;
129
130 } player_data;
131
132 //todo, move health in...
133 typedef struct {
134 short unsigned int PlayerNum;
135 unsigned int index;
136 Inventory Inventory;
137 char Class[32];
138 } rare_sync_data;
139
140 typedef struct {
141 unsigned int event_index;
142 int intArray[];
143 } flatline_event;
144
145 //used for storing data about each player
146 typedef struct {
147 int FLATLINE;
148 char id;
149 int packet_index;
150 union
151 {
152 char data[1080];
153 connect_reply connect_reply;
154 connect_send connect_send;
155 input_struct input_struct;
156 new_player new_player;
157 server_status server_status;
158 player_data player_data;
159 rare_sync_data rare_sync_data;
160 uint16_t sync_request;
161 flatline_event flatline_event;
162 };
163 } flatline_packet;
164 #define FLATLINE_HEADER (sizeof(flatline_packet)-sizeof(char)*1080)
165 //#define FLATLINE_PACKET_SIZE sizeof(flatline_packet)
166
167
168 bool FLrServer_PacketCallback(char* data, int datalen, int from);
169 bool FLrServer_Run();
170 bool FLrClient_Run(flatline_packet* packet);
171 extern int sock;
172
173 enum {
174 NULL_PACKET, //
175 CONNECT_SEND,
176 CONNECT_REPLY,
177 STATUS,
178 MESSAGE,
179 CHANGE_NAME,
180 ECHO,
181 NEW_PLAYER,
182 PLAYER_INPUT,
183 PLAYER_DATA,
184 RARE_SYNC_DATA,
185 RARE_SYNC_DATA_REQUEST,
186 FLATLINE_EVENT,
187 };
188
189 enum FlatlineEvent {
190 EV_RESPAWN,
191 EV_DISCONNECT,
192 EV_DOOR_OPEN,
193 EV_MAX,
194 };
195
196
197
198
199 enum {
200 STATE_ALIVE,
201 STATE_DEAD,
202 };
203 enum {
204 PF_HOST,
205 PF_BOT,
206 PF_SCRIPTEDAI,
207 };
208 typedef struct {
209 int ip;
210 char name[32];
211 char country[2];
212 Character* Chr;
213 uint16_t spawnnumber;
214 uint16_t list_slot;
215 float MouseDeltaX;
216 float MouseDeltaY;
217 uint32_t Actions1;
218 uint32_t Actions2;
219 unsigned int LastInputTime;
220 input_struct CacheInput;
221 player_data player_data;
222 unsigned int rare_sync_index;
223 void* OldClass;
224 Inventory Inventory;
225 uint16_t state;
226 int flags;
227 } player_info;
228
229 player_info * FLr_FindEmptySlot();
230 uint16_t FLr_FindEmptyListSlot();
231 void * ONICALL FLrInput_Update_Keys(void);
232
233 void NetCatchError();
234 #define MAX_PLAYERS 128
235 #define CONNECTION_TIMEOUT 15
236 #define MAX_CONNECTIONS 32
237 #define NetTCPSocket_Send NetUDPSocket_Send
238 #define NetTCPServer_Send NetUDPServer_Send
239 extern int client_sock;
240 //these two could probably be combined
241 extern sockaddr_in client_address;
242 extern sockaddr_in address;
243 extern player_info Players[];
244 extern player_info * PlayerList[];
245 int UDPServer_SendToAll(void* packet, int size);
246 extern bool client_connected;
247 extern bool server_started;
248 extern char player_name[];
249 void FLrRun_Scores();
250 void PlayerDisconnect( int Player );
251 int FLrEvent_GetNumArgs( int eventIndex );
252 #endif