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 |
//oh snap, I just realized this is rossy's version of flatline_packet. :| |
68 |
typedef struct { |
69 |
char signature[8]; |
70 |
uint16_t protocol_version; |
71 |
char data[0]; //data[0] doesn't work well with simple casts, btw. If you allocate enough space for a handshake_packet |
72 |
} handshake_packet; //there won't be enough room for data. You would have to manually manage the memory (ew) |
73 |
|
74 |
//initial connection |
75 |
typedef struct { |
76 |
char country[2]; |
77 |
char name[256]; |
78 |
} connect_send; //signature="CONNECT\0" |
79 |
|
80 |
//reply to connection. |
81 |
//goodtogo is if it is going to let you in |
82 |
//message is optional, only used for denial message |
83 |
typedef struct { |
84 |
bool goodtogo; |
85 |
int player_slot; |
86 |
char message[256]; |
87 |
} connect_reply; |
88 |
|
89 |
//um, status of the server? :/ |
90 |
typedef struct { |
91 |
char name[256]; |
92 |
uint32_t numplayers; //signature="STATUS\0\0" |
93 |
} server_status; |
94 |
|
95 |
typedef struct { |
96 |
uint16_t Playernumber; |
97 |
CharacterObject Character; |
98 |
} new_player; |
99 |
|
100 |
extern int update_rate; |
101 |
|
102 |
typedef struct { |
103 |
float MouseDeltaX; |
104 |
float MouseDeltaY; |
105 |
uint32_t Actions1; |
106 |
uint32_t Actions2; |
107 |
} input_struct; |
108 |
|
109 |
//TODO: |
110 |
//Varient |
111 |
//Figure out + fix overlays |
112 |
//AC->HeadFacing |
113 |
//AC->HeadPitch |
114 |
typedef struct { |
115 |
uint16_t PlayerNum; |
116 |
Vector3 Position; |
117 |
Vector3 LastPosition; |
118 |
Vector3 Location; |
119 |
float Facing; |
120 |
float DesiredFacing; |
121 |
float CosmeticFacing; |
122 |
uint32_t Health; |
123 |
uint32_t MaxHealth; |
124 |
input_struct Inputs; |
125 |
#if 0 |
126 |
uint16_t Frame; |
127 |
char Animation[32]; |
128 |
uint16_t AnimationToState; |
129 |
uint16_t AnimationFromState; |
130 |
uint16_t AnimationType; |
131 |
uint16_t NextAnimationType; |
132 |
uint16_t AnimationType2; |
133 |
__int16 InterpolationCurrentFrame; |
134 |
__int16 InterpolationFromState; |
135 |
__int16 InterpolationLength; |
136 |
Quaternion InterpolationStartRotations[19]; |
137 |
Vector3 StitchVelocity; |
138 |
int StitchHeight; |
139 |
char Stitch; |
140 |
Quaternion BoneMatrices[19]; |
141 |
int Overlay; |
142 |
Quaternion OverlayRotations[19]; |
143 |
#endif |
144 |
} player_data; |
145 |
|
146 |
//used for storing data about each player |
147 |
typedef struct { |
148 |
int FLATLINE; |
149 |
char id; |
150 |
int packet_index; |
151 |
union payload |
152 |
{ |
153 |
char data[1080]; |
154 |
connect_reply connect_reply; |
155 |
connect_send connect_send; |
156 |
input_struct input_struct; |
157 |
new_player new_player; |
158 |
server_status server_status; |
159 |
player_data player_data; |
160 |
}; |
161 |
} flatline_packet; |
162 |
#define FLATLINE_HEADER sizeof(flatline_packet)-sizeof(char)*1080 |
163 |
//#define FLATLINE_PACKET_SIZE sizeof(flatline_packet) |
164 |
|
165 |
|
166 |
bool FLrServer_PacketCallback(char* data, int datalen, int from); |
167 |
bool FLrServer_Run(); |
168 |
bool FLrClient_Run(flatline_packet* packet); |
169 |
extern int sock; |
170 |
|
171 |
enum { |
172 |
CONNECT_SEND, |
173 |
CONNECT_REPLY, |
174 |
STATUS, |
175 |
MESSAGE, |
176 |
CHANGE_NAME, |
177 |
ECHO, |
178 |
NEW_PLAYER, |
179 |
PLAYER_INPUT, |
180 |
PLAYER_DATA, |
181 |
}; |
182 |
|
183 |
|
184 |
typedef struct { |
185 |
int ip; |
186 |
char name[32]; |
187 |
char country[2]; |
188 |
Character* Chr; |
189 |
uint16_t spawnnumber; |
190 |
uint16_t list_slot; |
191 |
uint32_t Actions1; |
192 |
uint32_t Actions2; |
193 |
float MouseDeltaX; |
194 |
float MouseDeltaY; |
195 |
} player_info; |
196 |
|
197 |
player_info * FLr_FindEmptySlot(); |
198 |
uint16_t FLr_FindEmptyListSlot(); |
199 |
void * ONICALL FLrInput_Update_Keys(void); |
200 |
|
201 |
void NetCatchError(); |
202 |
#define MAX_PLAYERS 128 |
203 |
#define CONNECTION_TIMEOUT 15 |
204 |
#define MAX_CONNECTIONS 32 |
205 |
#define NetTCPSocket_Send NetUDPSocket_Send |
206 |
#define NetTCPServer_Send NetUDPServer_Send |
207 |
extern int client_sock; |
208 |
//these two could probably be combined |
209 |
extern sockaddr_in client_address; |
210 |
extern sockaddr_in address; |
211 |
extern player_info Players[]; |
212 |
extern player_info * PlayerList[]; |
213 |
int UDPServer_SendToAll(void* packet, int size); |
214 |
extern bool client_connected; |
215 |
extern bool server_started; |
216 |
extern char player_name[]; |
217 |
|
218 |
#endif |