source: Daodan/MSVC/Flatline.h@ 573

Last change on this file since 573 was 573, checked in by gumby, 14 years ago
File size: 5.3 KB
Line 
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
45typedef struct {
46 short ss_family;
47 char pad1[pad1_size];
48 uint64_t pad64;
49 char pad2[pad2_size];
50} sockaddr_storage;
51
52typedef struct sockaddr sockaddr;
53typedef struct sockaddr_in sockaddr_in;
54typedef sockaddr_storage sockaddr_in6;
55
56bool NetUDPServer_Listen(uint16_t port, bool (*packet_callback)(char* data, int datalen, int from));
57bool NetUDPServer_Send(sockaddr* address, char* data, int datalen);
58
59int NetUDPSocket_Create(uint16_t port);
60int NetUDPSocket_Send(int socket, const sockaddr* address, const char* data, int datalen);
61void NetUDPSocket_Close(int sock);
62bool NetUDPSocket_Recieve(int socket, sockaddr_storage* address, char* data, uint16_t* datalen);
63
64DWORD WINAPI StartServer(void* lol);
65DWORD WINAPI StartClient(void* lol);
66
67
68//initial connection
69typedef 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
77typedef struct {
78 bool goodtogo;
79 int player_slot;
80 char message[256];
81} connect_reply;
82
83//um, status of the server? :/
84typedef struct {
85 char name[256];
86 uint32_t numplayers; //signature="STATUS\0\0"
87} server_status;
88
89typedef struct {
90 uint16_t Playernumber;
91 CharacterObject Character;
92} new_player;
93
94//extern int update_rate;
95
96typedef 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
109typedef struct {
110 uint16_t throwing;
111 uint16_t throwFrame;
112 char throwName[32];
113} td;
114typedef 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...
133typedef struct {
134 short unsigned int PlayerNum;
135 unsigned int index;
136 Inventory Inventory;
137 char Class[32];
138} rare_sync_data;
139
140typedef struct {
141 unsigned int event_index;
142 int intArray[];
143} flatline_event;
144
145//used for storing data about each player
146typedef 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
168bool FLrServer_PacketCallback(char* data, int datalen, int from);
169bool FLrServer_Run();
170bool FLrClient_Run(flatline_packet* packet);
171extern int sock;
172
173enum {
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
189enum FlatlineEvent {
190 EV_RESPAWN,
191 EV_DISCONNECT,
192 EV_DOOR_OPEN,
193 EV_MAX,
194};
195
196
197
198
199enum {
200 STATE_ALIVE,
201 STATE_DEAD,
202};
203enum {
204 PF_HOST,
205 PF_BOT,
206 PF_SCRIPTEDAI,
207};
208typedef 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
229player_info * FLr_FindEmptySlot();
230uint16_t FLr_FindEmptyListSlot();
231void * ONICALL FLrInput_Update_Keys(void);
232
233void 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
239extern int client_sock;
240//these two could probably be combined
241extern sockaddr_in client_address;
242extern sockaddr_in address;
243extern player_info Players[];
244extern player_info * PlayerList[];
245int UDPServer_SendToAll(void* packet, int size);
246extern bool client_connected;
247extern bool server_started;
248extern char player_name[];
249void FLrRun_Scores();
250void PlayerDisconnect( int Player );
251int FLrEvent_GetNumArgs( int eventIndex );
252#endif
Note: See TracBrowser for help on using the repository browser.