-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Structs.h
304 lines (281 loc) · 8.8 KB
/
Structs.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
// Copyright DarkNeutrino 2021
#ifndef STRUCTS_H
#define STRUCTS_H
#include "../Extern/libmapvxl/libmapvxl.h"
#include "Util/Enums.h"
#include "Util/Queue.h"
#include "Util/Types.h"
#include "Util/Uthash.h"
#include "Util/Utlist.h"
#include <enet/enet.h>
#include <signal.h>
#include <sys/types.h>
#include <time.h>
#define VERSION \
"Beta 1.0" \
" Compiled on " __DATE__ " " __TIME__
// #define DEBUG
typedef struct
{
union
{
uint8_t ip[4];
uint32_t ip32;
};
uint8_t cidr;
} ip_t;
typedef struct permissions
{
char access_level[32];
const char** access_password;
uint8_t perm_level_offset;
} permissions_t;
typedef struct grenade
{
uint8_t sent;
float fuse;
uint8_t exploded;
vector3f_t position;
vector3f_t velocity;
uint64_t time_since_sent;
struct grenade *next, *prev;
} grenade_t;
typedef struct movement
{ // Seriously what the F. Thank voxlap motion for this mess.
vector3f_t position;
vector3f_t prev_position;
vector3f_t prev_legit_pos;
vector3f_t eye_pos;
vector3f_t velocity;
vector3f_t strafe_orientation;
vector3f_t height_orientation;
vector3f_t forward_orientation;
vector3f_t previous_orientation;
} movement_t;
typedef struct orientation
{ // Yet again thanks voxlap.
vector3f_t forward;
vector3f_t strafe;
vector3f_t height;
} orientation_t;
typedef struct string_node
{
char* string;
struct string_node *next, *prev;
} string_node_t;
typedef struct map
{
uint8_t map_count;
string_node_t* current_map;
// compressed map
queue_t* compressed_map;
uint32_t compressed_size;
vector3i_t result_line[50];
size_t map_size;
mapvxl_t map;
string_node_t* map_list;
} map_t;
typedef struct gamemode_vars
{
uint8_t score[2];
uint8_t score_limit;
intel_flag_t intel_flags;
vector3f_t intel[2];
vector3f_t base[2];
uint8_t player_intel_team[2];
uint8_t intel_held[2];
} gamemode_vars_t;
typedef struct protocol
{
uint8_t num_users;
uint8_t num_team_users[2];
//
uint8_t num_players;
uint8_t max_players;
//
color_t color_fog;
color_t color_team[2];
char name_team[2][11];
gamemode_t current_gamemode;
gamemode_vars_t gamemode;
// respawn area
quad3d_t spawns[2];
uint32_t input_flags;
} protocol_t;
typedef struct timers
{
uint64_t time_since_last_wu;
uint64_t since_last_base_enter;
uint64_t since_last_base_enter_restock;
uint64_t start_of_respawn_wait;
uint64_t since_last_shot;
uint64_t since_last_block_dest_with_gun;
uint64_t since_last_block_dest;
uint64_t since_last_block_plac;
uint64_t since_last_3block_dest;
uint64_t since_last_grenade_thrown;
uint64_t since_last_weapon_input;
uint64_t since_reload_start;
uint64_t since_last_primary_weapon_input;
uint64_t since_last_message_from_spam;
uint64_t since_last_message;
uint64_t since_possible_spade_nade;
uint64_t since_periodic_message;
uint64_t during_noclip_period;
} timers_t;
typedef struct global_timers
{
uint64_t update_time;
uint64_t last_update_time;
uint64_t time_since_start;
float time_since_start_simulated;
} global_timers_t;
typedef struct block_node
{
struct block_node* next;
vector3i_t position;
vector3i_t position_end;
color_t color;
uint8_t type;
uint8_t sender_id;
} block_node_t;
typedef struct player
{
queue_t* queues;
ENetPeer* peer;
grenade_t* grenade;
uint64_t permissions;
string_node_t* current_periodic_message;
block_node_t* blockBuffer;
timers_t timers;
permissions_t role_list[5]; // Change me based on the number of access levels you require
state_t state;
weapon_t weapon;
team_t team;
tool_t item;
weapon_default_clip_t default_clip;
weapon_default_reserve_t default_reserve;
uint32_t kills;
uint32_t deaths;
color_t color;
int version_minor;
int version_major;
int version_revision;
color_t tool_color;
int hp;
float lastclimb;
ip_t ip;
vector3f_t locAtClick;
movement_t movement;
vector3i_t result_line[50];
uint16_t ups;
char client;
uint8_t respawn_time;
uint8_t grenades;
uint8_t blocks;
uint8_t weapon_reserve;
uint8_t weapon_clip;
uint8_t alive;
uint8_t input;
uint8_t allow_killing;
uint8_t allow_team_killing;
uint8_t muted;
uint8_t admin_muted;
uint8_t can_build;
uint8_t told_to_master;
uint8_t has_intel;
uint8_t is_invisible;
uint8_t welcome_sent;
uint8_t reloading;
uint8_t spamCounter;
uint8_t periodic_delay_index;
uint8_t invalidPosCount;
uint8_t move_forward;
uint8_t move_backwards;
uint8_t move_left;
uint8_t move_right;
uint8_t jumping;
uint8_t crouching;
uint8_t sneaking;
uint8_t sprinting;
uint8_t primary_fire;
uint8_t secondary_fire;
uint8_t airborne;
uint8_t wade;
char name[17];
char os_info[255];
} player_t;
typedef struct master
{
// Master
ENetHost* client;
ENetPeer* peer;
ENetEvent event;
uint8_t enable_master_connection;
uint64_t time_since_last_send;
} master_t;
typedef struct command_args
{
uint8_t player_id;
uint8_t console;
uint32_t permissions;
uint32_t argc;
char* argv[32]; // 32 roles^W commands should be more than enough for anyone
} command_args_t;
typedef struct command
{
char id[30];
uint8_t parse_args; // Should we even bother parsing it? Would be useful for commands whose one and only
// argument is a message, or which don't even have any arguments
void (*execute)(void* p_server, command_args_t arguments);
uint32_t permissions; // 32 roles should be more then enough for anyone
char description[1024];
UT_hash_handle hh;
struct command* next;
} command_t;
// Command but with removed hash map and linked list stuff for easy managment
typedef struct command_manager
{
char id[30];
uint8_t parse_args; // Should we even bother parsing it? Would be useful for commands whose one and only
// argument is a message, or which don't even have any arguments
void (*execute)(void* p_server, command_args_t arguments);
uint32_t permissions; // 32 roles should be more then enough for anyone
char description[1024];
} command_manager_t;
typedef struct map_node
{
int id;
vector3i_t pos;
uint8_t visited;
UT_hash_handle hh;
} map_node_t;
typedef struct server
{
ENetHost* host;
player_t player[32];
protocol_t protocol;
master_t master;
uint16_t port;
map_t s_map;
global_timers_t global_timers;
command_t* cmds_map;
command_t* cmds_list;
string_node_t* welcome_messages;
uint8_t welcome_messages_count;
string_node_t* periodic_messages;
uint8_t periodic_message_count;
uint8_t* periodic_delays;
uint8_t global_ak;
uint8_t global_ab;
const char* manager_passwd;
const char* admin_passwd;
const char* mod_passwd;
const char* guard_passwd;
const char* trusted_passwd;
char map_name[20];
char server_name[31];
char gamemode_name[7];
volatile sig_atomic_t running; // volatile keyword is required to have an access to this variable in any thread
} server_t;
#endif