3 #include "client/client.h"
4 #include "client/client_map.h"
7 static bool disconnect_handler(__attribute__((unused)) Client *client, bool good)
10 client_disconnect(false, NULL);
14 static bool auth_handler(Client *client, bool good)
17 if (! read_u8(client->fd, &success))
24 printf("Authenticated successfully\n");
25 client->state = CS_ACTIVE;
27 printf("Authentication failed, please try again\n");
28 client->state = CS_CREATED;
34 static bool block_handler(Client *client, bool good)
38 if (! read_v3s32(client->fd, &pos))
43 if (! read_u64(client->fd, &size))
46 if (size > sizeof(MapBlockData)) // guard to prevent malicious or malfunctioning packets from allocating huge unnecessary amounts of memory
50 if (! read_full(client->fd, data, size))
56 block = map_get_block(client_map.map, pos, true);
58 block = map_allocate_block(pos);
60 map_clear_meta(block);
62 bool ret = map_deserialize_block(block, data, size);
65 client_map_block_received(block);
67 map_free_block(block);
72 static bool simulation_distance_handler(Client *client, bool good)
74 u32 simulation_distance;
76 if (! read_u32(client->fd, &simulation_distance))
80 client_map_set_simulation_distance(simulation_distance);
85 CommandHandler command_handlers[CLIENT_COMMAND_COUNT] = {
87 {&disconnect_handler, "DISCONNECT", CS_CREATED | CS_AUTH | CS_ACTIVE},
88 {&auth_handler, "AUTH", CS_AUTH},
89 {&block_handler, "BLOCK", CS_ACTIVE},
90 {&simulation_distance_handler, "SIMULATION_DISTANCE", CS_ACTIVE},