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