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