| 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 |
|
| 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 |
//used for storing data about each player |
| 148 |
typedef 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 |
|
| 170 |
bool FLrServer_PacketCallback(char* data, int datalen, int from); |
| 171 |
bool FLrServer_Run(); |
| 172 |
bool FLrClient_Run(flatline_packet* packet); |
| 173 |
extern int sock; |
| 174 |
|
| 175 |
enum { |
| 176 |
NULL_PACKET, //Don't use. ;) |
| 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 |
|
| 191 |
enum FlatlineEvent { |
| 192 |
EV_RESPAWN, |
| 193 |
EV_DISCONNECT, |
| 194 |
EV_DOOR_OPEN, |
| 195 |
EV_CONSOLE_USE, |
| 196 |
EV_MAX, |
| 197 |
}; |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
enum { |
| 202 |
STATE_ALIVE, |
| 203 |
STATE_DEAD, |
| 204 |
}; |
| 205 |
enum { |
| 206 |
PF_HOST, |
| 207 |
PF_BOT, |
| 208 |
PF_SCRIPTEDAI, |
| 209 |
}; |
| 210 |
typedef 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 |
int DeathTime; |
| 230 |
} player_info; |
| 231 |
|
| 232 |
player_info * FLr_FindEmptySlot(); |
| 233 |
uint16_t FLr_FindEmptyListSlot(); |
| 234 |
void * ONICALL FLrInput_Update_Keys(void); |
| 235 |
|
| 236 |
void NetCatchError(); |
| 237 |
#define MAX_PLAYERS 128 |
| 238 |
#define CONNECTION_TIMEOUT 15 |
| 239 |
#define MAX_CONNECTIONS 32 |
| 240 |
#define NetTCPSocket_Send NetUDPSocket_Send |
| 241 |
#define NetTCPServer_Send NetUDPServer_Send |
| 242 |
extern int client_sock; |
| 243 |
//these two could probably be combined |
| 244 |
extern sockaddr_in client_address; |
| 245 |
extern sockaddr_in address; |
| 246 |
extern player_info Players[]; |
| 247 |
extern player_info * PlayerList[]; |
| 248 |
int UDPServer_SendToAll(void* packet, int size); |
| 249 |
extern bool client_connected; |
| 250 |
extern bool server_started; |
| 251 |
extern char player_name[]; |
| 252 |
void FLrRun_Scores(); |
| 253 |
void FLrPlayerDisconnect( int Player ); |
| 254 |
void FLrPlayerRespawn( int Player ); |
| 255 |
int FLrEvent_GetNumArgs( int eventIndex ); |
| 256 |
#endif |