[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"
|
---|
| 38 |
|
---|
| 39 |
|
---|
| 40 | #define pad1_size (sizeof(int64_t) - sizeof(short))
|
---|
| 41 | #define pad2_size (128 - (sizeof(short) + pad1_size + sizeof(int64_t)))
|
---|
| 42 |
|
---|
| 43 | #define breakpoint asm("int3")
|
---|
| 44 |
|
---|
| 45 | typedef struct {
|
---|
| 46 | short ss_family;
|
---|
| 47 | char pad1[pad1_size];
|
---|
| 48 | uint64_t pad64;
|
---|
| 49 | char pad2[pad2_size];
|
---|
| 50 | } sockaddr_storage;
|
---|
| 51 |
|
---|
| 52 | typedef struct sockaddr sockaddr;
|
---|
| 53 | typedef struct sockaddr_in sockaddr_in;
|
---|
| 54 | typedef sockaddr_storage sockaddr_in6;
|
---|
| 55 |
|
---|
| 56 | bool NetUDPServer_Listen(uint16_t port, bool (*packet_callback)(char* data, int datalen, int from));
|
---|
| 57 | bool NetUDPServer_Send(sockaddr* address, char* data, int datalen);
|
---|
| 58 |
|
---|
| 59 | int NetUDPSocket_Create(uint16_t port);
|
---|
| 60 | int NetUDPSocket_Send(int socket, const sockaddr* address, const char* data, int datalen);
|
---|
| 61 | void NetUDPSocket_Close(int sock);
|
---|
| 62 | bool NetUDPSocket_Recieve(int socket, sockaddr_storage* address, char* data, uint16_t* datalen);
|
---|
| 63 |
|
---|
| 64 | DWORD WINAPI StartServer(void* lol);
|
---|
| 65 | DWORD WINAPI StartClient(void* lol);
|
---|
| 66 |
|
---|
| 67 |
|
---|
| 68 | //initial connection
|
---|
| 69 | typedef struct {
|
---|
| 70 | char country[2];
|
---|
| 71 | char name[256];
|
---|
| 72 | } connect_send; //signature="CONNECT\0"
|
---|
| 73 |
|
---|
| 74 | //reply to connection.
|
---|
| 75 | //goodtogo is if it is going to let you in
|
---|
| 76 | //message is optional, only used for denial message
|
---|
| 77 | typedef struct {
|
---|
| 78 | bool goodtogo;
|
---|
| 79 | int player_slot;
|
---|
| 80 | char message[256];
|
---|
| 81 | } connect_reply;
|
---|
| 82 |
|
---|
| 83 | //um, status of the server? :/
|
---|
| 84 | typedef struct {
|
---|
| 85 | char name[256];
|
---|
| 86 | uint32_t numplayers; //signature="STATUS\0\0"
|
---|
| 87 | } server_status;
|
---|
| 88 |
|
---|
| 89 | typedef struct {
|
---|
| 90 | uint16_t Playernumber;
|
---|
| 91 | CharacterObject Character;
|
---|
| 92 | } new_player;
|
---|
| 93 |
|
---|
[568] | 94 | //extern int update_rate;
|
---|
[567] | 95 |
|
---|
| 96 | typedef struct {
|
---|
| 97 | float MouseDeltaX;
|
---|
| 98 | float MouseDeltaY;
|
---|
| 99 | uint32_t Actions1;
|
---|
| 100 | uint32_t Actions2;
|
---|
[568] | 101 | unsigned int Time;
|
---|
[567] | 102 | } input_struct;
|
---|
| 103 |
|
---|
| 104 | //TODO:
|
---|
| 105 | //Varient
|
---|
| 106 | //Figure out + fix overlays
|
---|
| 107 | //AC->HeadFacing
|
---|
| 108 | //AC->HeadPitch
|
---|
| 109 | typedef struct {
|
---|
| 110 | uint16_t PlayerNum;
|
---|
| 111 | Vector3 Position;
|
---|
| 112 | Vector3 LastPosition;
|
---|
| 113 | Vector3 Location;
|
---|
| 114 | float Facing;
|
---|
| 115 | float DesiredFacing;
|
---|
| 116 | float CosmeticFacing;
|
---|
| 117 | uint32_t Health;
|
---|
| 118 | uint32_t MaxHealth;
|
---|
| 119 | input_struct Inputs;
|
---|
[568] | 120 | int rare_sync_index;
|
---|
| 121 | //__int16 Varient;
|
---|
[567] | 122 | #if 0
|
---|
| 123 | uint16_t Frame;
|
---|
| 124 | char Animation[32];
|
---|
| 125 | uint16_t AnimationToState;
|
---|
| 126 | uint16_t AnimationFromState;
|
---|
| 127 | uint16_t AnimationType;
|
---|
| 128 | uint16_t NextAnimationType;
|
---|
| 129 | uint16_t AnimationType2;
|
---|
| 130 | __int16 InterpolationCurrentFrame;
|
---|
| 131 | __int16 InterpolationFromState;
|
---|
| 132 | __int16 InterpolationLength;
|
---|
| 133 | Quaternion InterpolationStartRotations[19];
|
---|
| 134 | Vector3 StitchVelocity;
|
---|
| 135 | int StitchHeight;
|
---|
| 136 | char Stitch;
|
---|
| 137 | Quaternion BoneMatrices[19];
|
---|
| 138 | int Overlay;
|
---|
| 139 | Quaternion OverlayRotations[19];
|
---|
| 140 | #endif
|
---|
| 141 | } player_data;
|
---|
| 142 |
|
---|
[568] | 143 | //todo, move health in...
|
---|
| 144 | typedef struct {
|
---|
| 145 | short unsigned int PlayerNum;
|
---|
| 146 | unsigned int index;
|
---|
| 147 | Inventory Inventory;
|
---|
| 148 | char Class[32];
|
---|
| 149 | } rare_sync_data;
|
---|
| 150 |
|
---|
[567] | 151 | //used for storing data about each player
|
---|
| 152 | typedef struct {
|
---|
| 153 | int FLATLINE;
|
---|
| 154 | char id;
|
---|
| 155 | int packet_index;
|
---|
| 156 | union payload
|
---|
| 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;
|
---|
[568] | 165 | rare_sync_data rare_sync_data;
|
---|
| 166 | uint16_t sync_request;
|
---|
[567] | 167 | };
|
---|
| 168 | } flatline_packet;
|
---|
[568] | 169 | #define FLATLINE_HEADER (sizeof(flatline_packet)-sizeof(char)*1080)
|
---|
[567] | 170 | //#define FLATLINE_PACKET_SIZE sizeof(flatline_packet)
|
---|
| 171 |
|
---|
| 172 |
|
---|
| 173 | bool FLrServer_PacketCallback(char* data, int datalen, int from);
|
---|
| 174 | bool FLrServer_Run();
|
---|
| 175 | bool FLrClient_Run(flatline_packet* packet);
|
---|
| 176 | extern int sock;
|
---|
| 177 |
|
---|
| 178 | enum {
|
---|
| 179 | CONNECT_SEND,
|
---|
| 180 | CONNECT_REPLY,
|
---|
| 181 | STATUS,
|
---|
| 182 | MESSAGE,
|
---|
| 183 | CHANGE_NAME,
|
---|
| 184 | ECHO,
|
---|
| 185 | NEW_PLAYER,
|
---|
| 186 | PLAYER_INPUT,
|
---|
| 187 | PLAYER_DATA,
|
---|
[568] | 188 | RARE_SYNC_DATA,
|
---|
| 189 | RARE_SYNC_DATA_REQUEST,
|
---|
[567] | 190 | };
|
---|
| 191 |
|
---|
| 192 |
|
---|
| 193 | typedef struct {
|
---|
| 194 | int ip;
|
---|
[568] | 195 | char name[32];
|
---|
[567] | 196 | char country[2];
|
---|
| 197 | Character* Chr;
|
---|
| 198 | uint16_t spawnnumber;
|
---|
| 199 | uint16_t list_slot;
|
---|
[568] | 200 |
|
---|
| 201 | float MouseDeltaX;
|
---|
| 202 | float MouseDeltaY;
|
---|
[567] | 203 | uint32_t Actions1;
|
---|
| 204 | uint32_t Actions2;
|
---|
[568] | 205 | unsigned int LastInputTime;
|
---|
| 206 | input_struct CacheInput;
|
---|
| 207 |
|
---|
| 208 | player_data player_data;
|
---|
| 209 |
|
---|
| 210 | unsigned int rare_sync_index;
|
---|
| 211 | void* OldClass;
|
---|
| 212 | Inventory Inventory;
|
---|
[567] | 213 | } player_info;
|
---|
| 214 |
|
---|
| 215 | player_info * FLr_FindEmptySlot();
|
---|
| 216 | uint16_t FLr_FindEmptyListSlot();
|
---|
| 217 | void * ONICALL FLrInput_Update_Keys(void);
|
---|
| 218 |
|
---|
| 219 | void NetCatchError();
|
---|
| 220 | #define MAX_PLAYERS 128
|
---|
| 221 | #define CONNECTION_TIMEOUT 15
|
---|
| 222 | #define MAX_CONNECTIONS 32
|
---|
| 223 | #define NetTCPSocket_Send NetUDPSocket_Send
|
---|
| 224 | #define NetTCPServer_Send NetUDPServer_Send
|
---|
| 225 | extern int client_sock;
|
---|
| 226 | //these two could probably be combined
|
---|
| 227 | extern sockaddr_in client_address;
|
---|
| 228 | extern sockaddr_in address;
|
---|
| 229 | extern player_info Players[];
|
---|
| 230 | extern player_info * PlayerList[];
|
---|
| 231 | int UDPServer_SendToAll(void* packet, int size);
|
---|
| 232 | extern bool client_connected;
|
---|
| 233 | extern bool server_started;
|
---|
| 234 | extern char player_name[];
|
---|
| 235 |
|
---|
| 236 | #endif
|
---|