3 #include "client/client.h"
4 #include "client/client_map.h"
8 static bool disconnect_handler(unused Client *client, bool good)
11 client_disconnect(false, NULL);
15 static bool auth_handler(Client *client, bool good)
18 if (! read_u8(client->fd, &success))
25 printf("Authenticated successfully\n");
26 client->state = CS_ACTIVE;
28 printf("Authentication failed, please try again\n");
29 client->state = CS_CREATED;
35 static bool block_handler(Client *client, bool good)
39 if (! read_v3s32(client->fd, &pos))
44 if (! read_u64(client->fd, &size))
47 if (size > sizeof(MapBlockData)) // guard to prevent malicious or malfunctioning packets from allocating huge unnecessary amounts of memory
51 if (! read_full(client->fd, data, size))
57 block = map_get_block(client_map.map, pos, true);
59 block = map_allocate_block(pos);
61 bool ret = map_deserialize_block(block, data, size);
64 client_map_block_received(block);
66 map_free_block(block);
71 static bool simulation_distance_handler(Client *client, bool good)
73 u32 simulation_distance;
75 if (! read_u32(client->fd, &simulation_distance))
79 client_map_set_simulation_distance(simulation_distance);
84 CommandHandler command_handlers[CLIENT_COMMAND_COUNT] = {
86 {&disconnect_handler, "DISCONNECT", CS_CREATED | CS_AUTH | CS_ACTIVE},
87 {&auth_handler, "AUTH", CS_AUTH},
88 {&block_handler, "BLOCK", CS_ACTIVE},
89 {&simulation_distance_handler, "SIMULATION_DISTANCE", CS_ACTIVE},