[876] | 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 <stdint.h>
|
---|
| 12 |
|
---|
| 13 | #define thread __thread
|
---|
| 14 |
|
---|
| 15 | #include "Flatline_Public.h"
|
---|
| 16 |
|
---|
| 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 | #include "Oni_Gamestate.h"
|
---|
| 39 | #include "Flatline_Packet.h"
|
---|
| 40 |
|
---|
| 41 | #include "Oni_Symbols.h"
|
---|
| 42 | //#define breakpoint asm("int3")
|
---|
| 43 |
|
---|
| 44 |
|
---|
| 45 | #include "Flatline_Net.h"
|
---|
| 46 |
|
---|
| 47 | DWORD WINAPI StartServer(void* lol);
|
---|
| 48 | DWORD WINAPI StartClient(void* lol);
|
---|
| 49 |
|
---|
| 50 |
|
---|
| 51 | //initial connection
|
---|
| 52 | typedef struct {
|
---|
| 53 | char country[2];
|
---|
| 54 | char name[256];
|
---|
| 55 | } connect_send; //signature="CONNECT\0"
|
---|
| 56 |
|
---|
| 57 | //reply to connection.
|
---|
| 58 | //goodtogo is if it is going to let you in
|
---|
| 59 | //message is optional, only used for denial message
|
---|
| 60 | typedef struct {
|
---|
| 61 | bool goodtogo;
|
---|
| 62 | int player_slot;
|
---|
| 63 | char message[256];
|
---|
| 64 | } connect_reply;
|
---|
| 65 |
|
---|
| 66 | //um, status of the server? :/
|
---|
| 67 | //probably obsolete. revive again once i do something crazy
|
---|
| 68 | //like make a master server
|
---|
| 69 | typedef struct {
|
---|
| 70 | char name[256];
|
---|
| 71 | uint32_t numplayers; //signature="STATUS\0\0"
|
---|
| 72 | } server_status;
|
---|
| 73 |
|
---|
| 74 | typedef struct {
|
---|
| 75 | uint16_t Playernumber;
|
---|
| 76 | CharacterObject Character;
|
---|
| 77 | } new_player;
|
---|
| 78 |
|
---|
| 79 | //extern int update_rate;
|
---|
| 80 |
|
---|
| 81 | typedef struct {
|
---|
| 82 | float MouseDeltaX;
|
---|
| 83 | float MouseDeltaY;
|
---|
| 84 | uint32_t Actions1;
|
---|
| 85 | uint32_t Actions2;
|
---|
| 86 | float DesiredFacing;
|
---|
| 87 | //unsigned int Time;
|
---|
| 88 | } input_struct;
|
---|
| 89 |
|
---|
| 90 | //TODO:
|
---|
| 91 | //Varient
|
---|
| 92 | //Figure out + fix overlays
|
---|
| 93 | //AC->HeadFacing
|
---|
| 94 | //AC->HeadPitch
|
---|
| 95 | typedef struct {
|
---|
| 96 | uint16_t throwing;
|
---|
| 97 | uint16_t throwFrame;
|
---|
| 98 | char throwName[32];
|
---|
| 99 | } td;
|
---|
| 100 | /*
|
---|
| 101 | typedef struct {
|
---|
| 102 | uint16_t PlayerNum;
|
---|
| 103 | //Vector3 Position;
|
---|
| 104 |
|
---|
| 105 | //float Facing;
|
---|
| 106 | //float DesiredFacing;
|
---|
| 107 |
|
---|
| 108 | float UD;
|
---|
| 109 | float LR;
|
---|
| 110 |
|
---|
| 111 | uint32_t Health;
|
---|
| 112 | uint32_t MaxHealth;
|
---|
| 113 | //input_struct Inputs;
|
---|
| 114 | int rare_sync_index;
|
---|
| 115 | char Animation[32];
|
---|
| 116 | uint16_t Frame;
|
---|
| 117 | td throw_data;
|
---|
| 118 | int Kills;
|
---|
| 119 | int Damage;
|
---|
| 120 | int Deaths;
|
---|
| 121 | uint16_t Ping;
|
---|
| 122 |
|
---|
| 123 | } player_data;
|
---|
| 124 | */
|
---|
| 125 | //todo, move health in...
|
---|
| 126 | /*typedef struct {
|
---|
| 127 | short unsigned int PlayerNum;
|
---|
| 128 | unsigned int index;
|
---|
| 129 | Inventory Inventory;
|
---|
| 130 | char Class[32];
|
---|
| 131 | } rare_sync_data;
|
---|
| 132 | */
|
---|
| 133 | typedef struct {
|
---|
| 134 | unsigned int event_index;
|
---|
| 135 | int intArray[];
|
---|
| 136 | } flatline_event;
|
---|
| 137 | /*
|
---|
| 138 | typedef struct {
|
---|
| 139 | int16_t PlayerNum;
|
---|
| 140 | float MouseDeltaX;
|
---|
| 141 | float MouseDeltaY;
|
---|
| 142 | uint32_t Actions1;
|
---|
| 143 | uint32_t Actions2;
|
---|
| 144 | float Facing;
|
---|
| 145 | float DesiredFacing;
|
---|
| 146 | Vector3 Position;
|
---|
| 147 | } player_input;
|
---|
| 148 | */
|
---|
| 149 | //used for storing data about each player
|
---|
| 150 | typedef struct {
|
---|
| 151 | //int FLATLINE;
|
---|
| 152 | short signature;
|
---|
| 153 | short id;
|
---|
| 154 | int size;
|
---|
| 155 | //int packet_index;
|
---|
| 156 | union
|
---|
| 157 | {
|
---|
| 158 | char data[1080];
|
---|
| 159 | connect_reply connect_reply;
|
---|
| 160 | connect_send connect_send;
|
---|
| 161 | input_struct input_struct;
|
---|
| 162 | new_player new_player;
|
---|
| 163 | server_status server_status;
|
---|
| 164 | //player_data player_data;
|
---|
| 165 | //rare_sync_data rare_sync_data;
|
---|
| 166 | uint16_t sync_request;
|
---|
| 167 | flatline_event flatline_event;
|
---|
| 168 | uint32_t ping;
|
---|
| 169 | //player_input all_input[33];
|
---|
| 170 | uint32_t integer; //generic integer ;)
|
---|
| 171 | };
|
---|
| 172 | } flatline_packet;
|
---|
| 173 | #define FLATLINE_HEADER (sizeof(flatline_packet)-sizeof(char)*1080)
|
---|
| 174 | //#define FLATLINE_PACKET_SIZE sizeof(flatline_packet)
|
---|
| 175 |
|
---|
| 176 |
|
---|
| 177 | bool FLrServer_PacketCallback(char* data, int datalen, int from);
|
---|
| 178 | bool FLrServer_Run();
|
---|
| 179 | bool FLrClient_Run(flatline_packet* packet);
|
---|
| 180 | extern int sock;
|
---|
| 181 |
|
---|
| 182 | enum {
|
---|
| 183 | NULL_PACKET, //Don't use. ;)
|
---|
| 184 | CONNECT_SEND,
|
---|
| 185 | CONNECT_REPLY,
|
---|
| 186 | STATUS,
|
---|
| 187 | MESSAGE,
|
---|
| 188 | CHANGE_NAME,
|
---|
| 189 | ECHO,
|
---|
| 190 | NEW_PLAYER,
|
---|
| 191 | PLAYER_INPUT,
|
---|
| 192 | //PLAYER_DATA,
|
---|
| 193 | //RARE_SYNC_DATA,
|
---|
| 194 | //RARE_SYNC_DATA_REQUEST,
|
---|
| 195 | FLATLINE_EVENT,
|
---|
| 196 | PK_PING,
|
---|
| 197 | PK_PONG,
|
---|
| 198 | //PK_ALL_INPUT,
|
---|
| 199 | PK_PLAYER_DATA,
|
---|
| 200 | PK_MISSING_PLAYER,
|
---|
| 201 | };
|
---|
| 202 |
|
---|
| 203 | enum FlatlineEvent {
|
---|
| 204 | EV_RESPAWN,
|
---|
| 205 | EV_KILLED,
|
---|
| 206 | EV_DISCONNECT,
|
---|
| 207 | EV_DOOR_OPEN,
|
---|
| 208 | EV_CONSOLE_USE,
|
---|
| 209 | EV_MAX,
|
---|
| 210 | };
|
---|
| 211 |
|
---|
| 212 |
|
---|
| 213 | typedef struct {
|
---|
| 214 | //Server Only
|
---|
| 215 | bool PleaseUpdateAllPlayers;
|
---|
| 216 | //Client stuff (can be used by server "client")
|
---|
| 217 |
|
---|
| 218 | //Move from random scattered bools to these, please.
|
---|
| 219 | bool ClientConnected;
|
---|
| 220 | unsigned int ClientSlot;
|
---|
| 221 | bool ServerStatus;
|
---|
| 222 | } multiplayer_status;
|
---|
| 223 |
|
---|
| 224 | enum {
|
---|
| 225 | STATE_ALIVE,
|
---|
| 226 | STATE_DEAD,
|
---|
| 227 | };
|
---|
| 228 | enum {
|
---|
| 229 | PF_HOST,
|
---|
| 230 | PF_BOT,
|
---|
| 231 | PF_SCRIPTEDAI,
|
---|
| 232 | };
|
---|
| 233 | typedef struct {
|
---|
| 234 | int ip;
|
---|
| 235 | char name[32];
|
---|
| 236 | char country[2];
|
---|
| 237 | Character* Chr;
|
---|
| 238 | uint16_t spawnnumber;
|
---|
| 239 | uint16_t list_slot;
|
---|
| 240 |
|
---|
| 241 | PlayerInput InputFromClient;
|
---|
| 242 | float FacingFromClient;
|
---|
| 243 |
|
---|
| 244 | ////////////////////////////
|
---|
| 245 | //Sync stuff
|
---|
| 246 | ////////////////////////////
|
---|
| 247 | uint16_t UpdateFlags;
|
---|
| 248 |
|
---|
| 249 | PlayerInput Input;
|
---|
| 250 | PlayerHealth Health;
|
---|
| 251 | PlayerFacing Facings;
|
---|
| 252 | PlayerScore Score;
|
---|
| 253 | void* Animation;
|
---|
| 254 | char AnimationString[32];
|
---|
| 255 | uint16_t Frame;
|
---|
| 256 | PlayerThrowData ThrowData;
|
---|
| 257 | void* Class;
|
---|
| 258 | char ClassString[32];
|
---|
| 259 | PlayerInventory Inventory;
|
---|
| 260 | Vector3 Position;
|
---|
| 261 | ////////////////////////////
|
---|
| 262 | bool HasAppliedThrow;
|
---|
| 263 |
|
---|
| 264 | unsigned int LastInputTime;
|
---|
| 265 |
|
---|
| 266 |
|
---|
| 267 | uint16_t state;
|
---|
| 268 | int flags;
|
---|
| 269 | int DeathTime;
|
---|
| 270 | uint32_t Ping;
|
---|
| 271 | bool DataApplied;
|
---|
| 272 | bool NeedToSetFP;
|
---|
| 273 | uint32_t ShapeshiftCooldown;
|
---|
| 274 | } player_info;
|
---|
| 275 |
|
---|
| 276 | player_info * FLr_FindEmptySlot();
|
---|
| 277 | uint16_t FLr_FindEmptyListSlot();
|
---|
| 278 | void * ONICALL FLrInput_Update_Keys(void);
|
---|
| 279 |
|
---|
| 280 | void NetCatchError();
|
---|
| 281 | #define MAX_PLAYERS 32
|
---|
| 282 | #define CONNECTION_TIMEOUT 15
|
---|
| 283 | #define MAX_CONNECTIONS 32
|
---|
| 284 | #define NetTCPSocket_Send NetUDPSocket_Send
|
---|
| 285 | #define NetTCPServer_Send NetUDPServer_Send
|
---|
| 286 | extern int client_sock;
|
---|
| 287 | //these two could probably be combined
|
---|
| 288 | extern sockaddr_in client_address;
|
---|
| 289 | extern sockaddr_in address;
|
---|
| 290 | extern player_info Players[];
|
---|
| 291 | extern player_info * PlayerList[];
|
---|
| 292 | extern multiplayer_status MultiplayerStatus;
|
---|
| 293 | int UDPServer_SendToAll(void* packet, int size);
|
---|
| 294 |
|
---|
| 295 |
|
---|
| 296 | void FLrRun_Scores();
|
---|
| 297 | void FLrPlayerDisconnect( int Player );
|
---|
| 298 | void FLrPlayerRespawn( int Player );
|
---|
| 299 | int FLrEvent_GetNumArgs( int eventIndex );
|
---|
| 300 | bool FlatlineInitialize();
|
---|
| 301 |
|
---|
| 302 | bool DoWeUpdateThis( uint16_t BitSet, uint16_t Flag );
|
---|
| 303 |
|
---|
| 304 | extern unsigned int lastPingTime;
|
---|
| 305 |
|
---|
| 306 | extern char player_name[32];
|
---|
| 307 |
|
---|
| 308 | #define FLATLINE_PORT 27778
|
---|