source: Daodan/MSVC/Flatline.h@ 578

Last change on this file since 578 was 578, checked in by gumby, 14 years ago
File size: 5.4 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? :/
84//probably obsolete. revive again once i do something crazy
85//like make a master server
86typedef struct {
87 char name[256];
88 uint32_t numplayers; //signature="STATUS\0\0"
89} server_status;
90
91typedef struct {
92 uint16_t Playernumber;
93 CharacterObject Character;
94} new_player;
95
96//extern int update_rate;
97
98typedef 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
111typedef struct {
112 uint16_t throwing;
113 uint16_t throwFrame;
114 char throwName[32];
115} td;
116typedef 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
132} player_data;
133
134//todo, move health in...
135typedef struct {
136 short unsigned int PlayerNum;
137 unsigned int index;
138 Inventory Inventory;
139 char Class[32];
140} rare_sync_data;
141
142typedef struct {
143 unsigned int event_index;
144 int intArray[];
145} flatline_event;
146
147//used for storing data about each player
148typedef struct {
149 int FLATLINE;
150 char id;
151 int packet_index;
152 union
153 {
154 char data[1080];
155 connect_reply connect_reply;
156 connect_send connect_send;
157 input_struct input_struct;
158 new_player new_player;
159 server_status server_status;
160 player_data player_data;
161 rare_sync_data rare_sync_data;
162 uint16_t sync_request;
163 flatline_event flatline_event;
164 };
165} flatline_packet;
166#define FLATLINE_HEADER (sizeof(flatline_packet)-sizeof(char)*1080)
167//#define FLATLINE_PACKET_SIZE sizeof(flatline_packet)
168
169
170bool FLrServer_PacketCallback(char* data, int datalen, int from);
171bool FLrServer_Run();
172bool FLrClient_Run(flatline_packet* packet);
173extern int sock;
174
175enum {
176 NULL_PACKET, //
177 CONNECT_SEND,
178 CONNECT_REPLY,
179 STATUS,
180 MESSAGE,
181 CHANGE_NAME,
182 ECHO,
183 NEW_PLAYER,
184 PLAYER_INPUT,
185 PLAYER_DATA,
186 RARE_SYNC_DATA,
187 RARE_SYNC_DATA_REQUEST,
188 FLATLINE_EVENT,
189};
190
191enum FlatlineEvent {
192 EV_RESPAWN,
193 EV_DISCONNECT,
194 EV_DOOR_OPEN,
195 EV_CONSOLE_USE,
196 EV_MAX,
197};
198
199
200
201enum {
202 STATE_ALIVE,
203 STATE_DEAD,
204};
205enum {
206 PF_HOST,
207 PF_BOT,
208 PF_SCRIPTEDAI,
209};
210typedef struct {
211 int ip;
212 char name[32];
213 char country[2];
214 Character* Chr;
215 uint16_t spawnnumber;
216 uint16_t list_slot;
217 float MouseDeltaX;
218 float MouseDeltaY;
219 uint32_t Actions1;
220 uint32_t Actions2;
221 unsigned int LastInputTime;
222 input_struct CacheInput;
223 player_data player_data;
224 unsigned int rare_sync_index;
225 void* OldClass;
226 Inventory Inventory;
227 uint16_t state;
228 int flags;
229} player_info;
230
231player_info * FLr_FindEmptySlot();
232uint16_t FLr_FindEmptyListSlot();
233void * ONICALL FLrInput_Update_Keys(void);
234
235void NetCatchError();
236#define MAX_PLAYERS 128
237#define CONNECTION_TIMEOUT 15
238#define MAX_CONNECTIONS 32
239#define NetTCPSocket_Send NetUDPSocket_Send
240#define NetTCPServer_Send NetUDPServer_Send
241extern int client_sock;
242//these two could probably be combined
243extern sockaddr_in client_address;
244extern sockaddr_in address;
245extern player_info Players[];
246extern player_info * PlayerList[];
247int UDPServer_SendToAll(void* packet, int size);
248extern bool client_connected;
249extern bool server_started;
250extern char player_name[];
251void FLrRun_Scores();
252void PlayerDisconnect( int Player );
253int FLrEvent_GetNumArgs( int eventIndex );
254#endif
Note: See TracBrowser for help on using the repository browser.