#pragma once #ifndef FLATLINE_H #define FLATLINE_H #include #include #include //#define DDrStartupMessage printf #include #include "bool.h" ////#include #define thread __thread #ifdef WIN32 #include #include "Flatline_Win32.h" #else #include #include #include #include #include #include #include #define NetPlatform_Initalize() /* */ #define NetPlatform_Shutdown() /* */ #define closesocket close #define ioctlsocket ioctl #endif #include "Daodan.h" #include "BFW_Utility.h" #include "Daodan_Console.h" #include "Oni_Character.h" #define pad1_size (sizeof(int64_t) - sizeof(short)) #define pad2_size (128 - (sizeof(short) + pad1_size + sizeof(int64_t))) #define breakpoint asm("int3") typedef struct { short ss_family; char pad1[pad1_size]; uint64_t pad64; char pad2[pad2_size]; } sockaddr_storage; typedef struct sockaddr sockaddr; typedef struct sockaddr_in sockaddr_in; typedef sockaddr_storage sockaddr_in6; bool NetUDPServer_Listen(uint16_t port, bool (*packet_callback)(char* data, int datalen, int from)); bool NetUDPServer_Send(sockaddr* address, char* data, int datalen); int NetUDPSocket_Create(uint16_t port); int NetUDPSocket_Send(int socket, const sockaddr* address, const char* data, int datalen); void NetUDPSocket_Close(int sock); bool NetUDPSocket_Recieve(int socket, sockaddr_storage* address, char* data, uint16_t* datalen); DWORD WINAPI StartServer(void* lol); DWORD WINAPI StartClient(void* lol); //initial connection typedef struct { char country[2]; char name[256]; } connect_send; //signature="CONNECT\0" //reply to connection. //goodtogo is if it is going to let you in //message is optional, only used for denial message typedef struct { bool goodtogo; int player_slot; char message[256]; } connect_reply; //um, status of the server? :/ //probably obsolete. revive again once i do something crazy //like make a master server typedef struct { char name[256]; uint32_t numplayers; //signature="STATUS\0\0" } server_status; typedef struct { uint16_t Playernumber; CharacterObject Character; } new_player; //extern int update_rate; typedef struct { float MouseDeltaX; float MouseDeltaY; uint32_t Actions1; uint32_t Actions2; unsigned int Time; } input_struct; //TODO: //Varient //Figure out + fix overlays //AC->HeadFacing //AC->HeadPitch typedef struct { uint16_t throwing; uint16_t throwFrame; char throwName[32]; } td; typedef struct { uint16_t PlayerNum; //Vector3 Position; //float Facing; //float DesiredFacing; float UD; float LR; uint32_t Health; uint32_t MaxHealth; //input_struct Inputs; int rare_sync_index; char Animation[32]; uint16_t Frame; td throw_data; int Kills; int Damage; int Deaths; uint16_t Ping; } player_data; //todo, move health in... typedef struct { short unsigned int PlayerNum; unsigned int index; Inventory Inventory; char Class[32]; } rare_sync_data; typedef struct { unsigned int event_index; int intArray[]; } flatline_event; typedef struct { int16_t PlayerNum; float MouseDeltaX; float MouseDeltaY; uint32_t Actions1; uint32_t Actions2; float Facing; float DesiredFacing; Vector3 Position; } player_input; //used for storing data about each player typedef struct { int FLATLINE; char id; int packet_index; union { char data[1080]; connect_reply connect_reply; connect_send connect_send; input_struct input_struct; new_player new_player; server_status server_status; player_data player_data; rare_sync_data rare_sync_data; uint16_t sync_request; flatline_event flatline_event; uint32_t ping; player_input all_input[32]; }; } flatline_packet; #define FLATLINE_HEADER (sizeof(flatline_packet)-sizeof(char)*1080) //#define FLATLINE_PACKET_SIZE sizeof(flatline_packet) bool FLrServer_PacketCallback(char* data, int datalen, int from); bool FLrServer_Run(); bool FLrClient_Run(flatline_packet* packet); extern int sock; enum { NULL_PACKET, //Don't use. ;) CONNECT_SEND, CONNECT_REPLY, STATUS, MESSAGE, CHANGE_NAME, ECHO, NEW_PLAYER, PLAYER_INPUT, PLAYER_DATA, RARE_SYNC_DATA, RARE_SYNC_DATA_REQUEST, FLATLINE_EVENT, PK_PING, PK_PONG, PK_ALL_INPUT, }; enum FlatlineEvent { EV_RESPAWN, EV_DISCONNECT, EV_DOOR_OPEN, EV_CONSOLE_USE, EV_MAX, }; typedef struct { //Server Only bool PleaseUpdateAllPlayers; //Client stuff (can be used by server "client") //Move from random scattered bools to these, please. bool ClientConnected; unsigned int ClientSlot; bool ServerStatus; } multiplayer_status; enum { STATE_ALIVE, STATE_DEAD, }; enum { PF_HOST, PF_BOT, PF_SCRIPTEDAI, }; typedef struct { int ip; char name[32]; char country[2]; Character* Chr; uint16_t spawnnumber; uint16_t list_slot; //Todo: move into struct for slightly faster copying float MouseDeltaX; float MouseDeltaY; uint32_t Actions1; uint32_t Actions2; float Facing; float DesiredFacing; //float Height; Vector3 Position; unsigned int LastInputTime; input_struct CacheInput; player_data player_data; unsigned int rare_sync_index; void* OldClass; Inventory Inventory; uint16_t state; int flags; int DeathTime; uint32_t Ping; bool DataApplied; uint32_t ShapeshiftCooldown; } player_info; player_info * FLr_FindEmptySlot(); uint16_t FLr_FindEmptyListSlot(); void * ONICALL FLrInput_Update_Keys(void); void NetCatchError(); #define MAX_PLAYERS 32 #define CONNECTION_TIMEOUT 15 #define MAX_CONNECTIONS 32 #define NetTCPSocket_Send NetUDPSocket_Send #define NetTCPServer_Send NetUDPServer_Send extern int client_sock; //these two could probably be combined extern sockaddr_in client_address; extern sockaddr_in address; extern player_info Players[]; extern player_info * PlayerList[]; extern multiplayer_status MultiplayerStatus; int UDPServer_SendToAll(void* packet, int size); extern bool client_connected; extern bool server_started; extern char player_name[]; void FLrRun_Scores(); void FLrPlayerDisconnect( int Player ); void FLrPlayerRespawn( int Player ); int FLrEvent_GetNumArgs( int eventIndex ); bool FlatlineInitialize(); extern unsigned int lastPingTime; #endif