source: Daodan/MSVC/Flatline.h@ 576

Last change on this file since 576 was 574, 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_CONSOLE_USE,
194 EV_MAX,
195};
196
197
198
199
200enum {
201 STATE_ALIVE,
202 STATE_DEAD,
203};
204enum {
205 PF_HOST,
206 PF_BOT,
207 PF_SCRIPTEDAI,
208};
209typedef struct {
210 int ip;
211 char name[32];
212 char country[2];
213 Character* Chr;
214 uint16_t spawnnumber;
215 uint16_t list_slot;
216 float MouseDeltaX;
217 float MouseDeltaY;
218 uint32_t Actions1;
219 uint32_t Actions2;
220 unsigned int LastInputTime;
221 input_struct CacheInput;
222 player_data player_data;
223 unsigned int rare_sync_index;
224 void* OldClass;
225 Inventory Inventory;
226 uint16_t state;
227 int flags;
228} player_info;
229
230player_info * FLr_FindEmptySlot();
231uint16_t FLr_FindEmptyListSlot();
232void * ONICALL FLrInput_Update_Keys(void);
233
234void NetCatchError();
235#define MAX_PLAYERS 128
236#define CONNECTION_TIMEOUT 15
237#define MAX_CONNECTIONS 32
238#define NetTCPSocket_Send NetUDPSocket_Send
239#define NetTCPServer_Send NetUDPServer_Send
240extern int client_sock;
241//these two could probably be combined
242extern sockaddr_in client_address;
243extern sockaddr_in address;
244extern player_info Players[];
245extern player_info * PlayerList[];
246int UDPServer_SendToAll(void* packet, int size);
247extern bool client_connected;
248extern bool server_started;
249extern char player_name[];
250void FLrRun_Scores();
251void PlayerDisconnect( int Player );
252int FLrEvent_GetNumArgs( int eventIndex );
253#endif
Note: See TracBrowser for help on using the repository browser.