#pragma once #ifndef FLATLINE_H #define FLATLINE_H #include #include #include //#define DDrStartupMessage printf #include #include "bool.h" ////#include #define thread __thread #include "Flatline_Public.h" #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" #include "Flatline_Packet.h" //#define breakpoint asm("int3") #include "Flatline_Net.h" 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; float DesiredFacing; //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; short signature; short id; int size; //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[33]; uint32_t integer; //generic integer ;) }; } 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, PK_PLAYER_DATA, PK_MISSING_PLAYER, }; enum FlatlineEvent { EV_RESPAWN, EV_KILLED, 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; PlayerInput InputFromClient; float FacingFromClient; //////////////////////////// //Sync stuff //////////////////////////// uint16_t UpdateFlags; PlayerInput Input; PlayerHealth Health; PlayerFacing Facings; PlayerScore Score; void* Animation; char AnimationString[32]; uint16_t Frame; PlayerThrowData ThrowData; void* Class; char ClassString[32]; PlayerInventory Inventory; Vector3 Position; //////////////////////////// bool HasAppliedThrow; unsigned int LastInputTime; uint16_t state; int flags; int DeathTime; uint32_t Ping; bool DataApplied; bool NeedToSetFP; 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); void FLrRun_Scores(); void FLrPlayerDisconnect( int Player ); void FLrPlayerRespawn( int Player ); int FLrEvent_GetNumArgs( int eventIndex ); bool FlatlineInitialize(); bool DoWeUpdateThis( uint16_t BitSet, uint16_t Flag ); extern unsigned int lastPingTime; #endif