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 |
|
---|
94 | //extern int update_rate;
|
---|
95 |
|
---|
96 | typedef struct {
|
---|
97 | float MouseDeltaX;
|
---|
98 | float MouseDeltaY;
|
---|
99 | uint32_t Actions1;
|
---|
100 | uint32_t Actions2;
|
---|
101 | unsigned int Time;
|
---|
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 throwing;
|
---|
111 | uint16_t throwFrame;
|
---|
112 | char throwName[32];
|
---|
113 | } td;
|
---|
114 | typedef struct {
|
---|
115 | uint16_t PlayerNum;
|
---|
116 | Vector3 Position;
|
---|
117 | float Facing;
|
---|
118 | float DesiredFacing;
|
---|
119 | uint32_t Health;
|
---|
120 | uint32_t MaxHealth;
|
---|
121 | input_struct Inputs;
|
---|
122 | int rare_sync_index;
|
---|
123 | char Animation[32];
|
---|
124 | uint16_t Frame;
|
---|
125 | td throw_data;
|
---|
126 | int Kills;
|
---|
127 | int Damage;
|
---|
128 | int Deaths;
|
---|
129 |
|
---|
130 | } player_data;
|
---|
131 |
|
---|
132 | //todo, move health in...
|
---|
133 | typedef struct {
|
---|
134 | short unsigned int PlayerNum;
|
---|
135 | unsigned int index;
|
---|
136 | Inventory Inventory;
|
---|
137 | char Class[32];
|
---|
138 | } rare_sync_data;
|
---|
139 |
|
---|
140 | typedef struct {
|
---|
141 | unsigned int event_index;
|
---|
142 | int intArray[];
|
---|
143 | } flatline_event;
|
---|
144 |
|
---|
145 | //used for storing data about each player
|
---|
146 | typedef struct {
|
---|
147 | int FLATLINE;
|
---|
148 | char id;
|
---|
149 | int packet_index;
|
---|
150 | union
|
---|
151 | {
|
---|
152 | char data[1080];
|
---|
153 | connect_reply connect_reply;
|
---|
154 | connect_send connect_send;
|
---|
155 | input_struct input_struct;
|
---|
156 | new_player new_player;
|
---|
157 | server_status server_status;
|
---|
158 | player_data player_data;
|
---|
159 | rare_sync_data rare_sync_data;
|
---|
160 | uint16_t sync_request;
|
---|
161 | flatline_event flatline_event;
|
---|
162 | };
|
---|
163 | } flatline_packet;
|
---|
164 | #define FLATLINE_HEADER (sizeof(flatline_packet)-sizeof(char)*1080)
|
---|
165 | //#define FLATLINE_PACKET_SIZE sizeof(flatline_packet)
|
---|
166 |
|
---|
167 |
|
---|
168 | bool FLrServer_PacketCallback(char* data, int datalen, int from);
|
---|
169 | bool FLrServer_Run();
|
---|
170 | bool FLrClient_Run(flatline_packet* packet);
|
---|
171 | extern int sock;
|
---|
172 |
|
---|
173 | enum {
|
---|
174 | NULL_PACKET, //
|
---|
175 | CONNECT_SEND,
|
---|
176 | CONNECT_REPLY,
|
---|
177 | STATUS,
|
---|
178 | MESSAGE,
|
---|
179 | CHANGE_NAME,
|
---|
180 | ECHO,
|
---|
181 | NEW_PLAYER,
|
---|
182 | PLAYER_INPUT,
|
---|
183 | PLAYER_DATA,
|
---|
184 | RARE_SYNC_DATA,
|
---|
185 | RARE_SYNC_DATA_REQUEST,
|
---|
186 | FLATLINE_EVENT,
|
---|
187 | };
|
---|
188 |
|
---|
189 | enum FlatlineEvent {
|
---|
190 | EV_RESPAWN,
|
---|
191 | EV_DISCONNECT,
|
---|
192 | EV_DOOR_OPEN,
|
---|
193 | EV_CONSOLE_USE,
|
---|
194 | EV_MAX,
|
---|
195 | };
|
---|
196 |
|
---|
197 |
|
---|
198 |
|
---|
199 |
|
---|
200 | enum {
|
---|
201 | STATE_ALIVE,
|
---|
202 | STATE_DEAD,
|
---|
203 | };
|
---|
204 | enum {
|
---|
205 | PF_HOST,
|
---|
206 | PF_BOT,
|
---|
207 | PF_SCRIPTEDAI,
|
---|
208 | };
|
---|
209 | typedef struct {
|
---|
210 | int ip;
|
---|
211 | char name[32];
|
---|
212 | char country[2];
|
---|
213 | Character* Chr;
|
---|
214 | uint16_t spawnnumber;
|
---|
215 | uint16_t list_slot;
|
---|
216 | float MouseDeltaX;
|
---|
217 | float MouseDeltaY;
|
---|
218 | uint32_t Actions1;
|
---|
219 | uint32_t Actions2;
|
---|
220 | unsigned int LastInputTime;
|
---|
221 | input_struct CacheInput;
|
---|
222 | player_data player_data;
|
---|
223 | unsigned int rare_sync_index;
|
---|
224 | void* OldClass;
|
---|
225 | Inventory Inventory;
|
---|
226 | uint16_t state;
|
---|
227 | int flags;
|
---|
228 | } player_info;
|
---|
229 |
|
---|
230 | player_info * FLr_FindEmptySlot();
|
---|
231 | uint16_t FLr_FindEmptyListSlot();
|
---|
232 | void * ONICALL FLrInput_Update_Keys(void);
|
---|
233 |
|
---|
234 | void NetCatchError();
|
---|
235 | #define MAX_PLAYERS 128
|
---|
236 | #define CONNECTION_TIMEOUT 15
|
---|
237 | #define MAX_CONNECTIONS 32
|
---|
238 | #define NetTCPSocket_Send NetUDPSocket_Send
|
---|
239 | #define NetTCPServer_Send NetUDPServer_Send
|
---|
240 | extern int client_sock;
|
---|
241 | //these two could probably be combined
|
---|
242 | extern sockaddr_in client_address;
|
---|
243 | extern sockaddr_in address;
|
---|
244 | extern player_info Players[];
|
---|
245 | extern player_info * PlayerList[];
|
---|
246 | int UDPServer_SendToAll(void* packet, int size);
|
---|
247 | extern bool client_connected;
|
---|
248 | extern bool server_started;
|
---|
249 | extern char player_name[];
|
---|
250 | void FLrRun_Scores();
|
---|
251 | void PlayerDisconnect( int Player );
|
---|
252 | int FLrEvent_GetNumArgs( int eventIndex );
|
---|
253 | #endif
|
---|