3 #include <dragontype/number.h>
4 #include "client/client.h"
5 #include "client/client_map.h"
6 #include "client/client_player.h"
11 static bool disconnect_handler(unused Client *client, bool good)
14 client_disconnect(false, NULL);
18 static bool auth_handler(Client *client, bool good)
21 if (! read_u8(client->fd, &success))
28 printf("Authenticated successfully\n");
29 client->state = CS_ACTIVE;
31 printf("Authentication failed, please try again\n");
32 client->state = CS_CREATED;
38 static bool block_handler(Client *client, bool good)
42 if (! read_v3s32(client->fd, &pos))
47 if (! read_u64(client->fd, &size))
55 if (! read_u64(client->fd, &rawsize))
59 if (! read_full(client->fd, data, size))
65 block = map_get_block(client_map.map, pos, true);
67 block = map_allocate_block(pos);
69 bool ret = map_deserialize_block(block, data, size, rawsize);
72 client_map_block_received(block);
74 map_free_block(block);
79 static bool info_handler(Client *client, bool good)
81 u32 simulation_distance;
84 if (! (read_u32(client->fd, &simulation_distance) && read_s32(client->fd, &server_seed)))
88 client_map_set_simulation_distance(simulation_distance);
95 static bool setpos_handler(Client *client, bool good)
99 if (! read_v3f64(client->fd, &pos))
103 client_player_set_position(pos);
108 static bool timeofday_handler(Client *client, bool good)
112 if (! read_u64(client->fd, &time_of_day))
116 set_time_of_day(time_of_day);
121 CommandHandler command_handlers[CLIENT_COMMAND_COUNT] = {
123 {&disconnect_handler, "DISCONNECT", CS_CREATED | CS_AUTH | CS_ACTIVE},
124 {&auth_handler, "AUTH", CS_AUTH},
125 {&block_handler, "BLOCK", CS_ACTIVE},
126 {&info_handler, "INFO", CS_ACTIVE},
127 {&setpos_handler, "SETPOS", CS_ACTIVE},
128 {&timeofday_handler, "TIMEOFDAY", CS_ACTIVE},