return block;
}
-static MapBlock *get_block(MapSector *sector, size_t idx)
-{
- return ((MapBlock **) sector->blocks.ptr)[idx];
-}
-
-static MapSector *get_sector(Map *map, size_t idx)
-{
- return ((MapSector **) map->sectors.ptr)[idx];
-}
-
Map *map_create()
{
Map *map = malloc(sizeof(Map));
void map_delete(Map *map)
{
for (size_t s = 0; s < map->sectors.siz; s++) {
- MapSector *sector = get_sector(map, s);
+ MapSector *sector = map_get_sector_raw(map, s);
for (size_t b = 0; b < sector->blocks.siz; b++)
- map_free_block(get_block(sector, b));
+ map_free_block(map_get_block_raw(sector, b));
if (sector->blocks.ptr)
free(sector->blocks.ptr);
free(sector);
free(map);
}
+MapSector *map_get_sector_raw(Map *map, size_t idx)
+{
+ return ((MapSector **) map->sectors.ptr)[idx];
+}
+
+MapBlock *map_get_block_raw(MapSector *sector, size_t idx)
+{
+ return ((MapBlock **) sector->blocks.ptr)[idx];
+}
+
MapSector *map_get_sector(Map *map, v2s32 pos, bool create)
{
u64 hash = ((u64) pos.x << 32) + (u64) pos.y;
ArraySearchResult res = array_search(&map->sectors, &hash);
if (res.success)
- return get_sector(map, res.index);
+ return map_get_sector_raw(map, res.index);
if (! create)
return NULL;
MapBlock *block = NULL;
if (res.success) {
- block = get_block(sector, res.index);
+ block = map_get_block_raw(sector, res.index);
} else if (create) {
block = allocate_block(pos);
array_insert(§or->blocks, &block, res.index);
if (dummy) {
block = allocate_block(pos);
} else if (res.success) {
- block = get_block(sector, res.index);
+ block = map_get_block_raw(sector, res.index);
} else {
block = allocate_block(pos);
array_insert(§or->blocks, &block, res.index);
bool map_serialize(int fd, Map *map)
{
for (size_t s = 0; s < map->sectors.siz; s++) {
- MapSector *sector = get_sector(map, s);
+ MapSector *sector = map_get_sector_raw(map, s);
for (size_t b = 0; b < sector->blocks.siz; b++)
- if (! map_serialize_block(fd, get_block(sector, b)))
+ if (! map_serialize_block(fd, map_get_block_raw(sector, b)))
return false;
}
return true;
return true;
}
+static bool send_map(Client *client)
+{
+ for (size_t s = 0; s < client->server->map->sectors.siz; s++) {
+ MapSector *sector = map_get_sector_raw(client->server->map, s);
+ for (size_t b = 0; b < sector->blocks.siz; b++)
+ if (! (write_u32(client->fd, CC_BLOCK) && map_serialize_block(client->fd, map_get_block_raw(sector, b))))
+ return false;
+ }
+ return true;
+}
+
static bool auth_handler(Client *client, bool good)
{
char *name = read_string(client->fd, NAME_MAX);
}
pthread_mutex_lock(&client->mtx);
- bool ret = write_u32(client->fd, CC_AUTH) && write_u8(client->fd, success);
+ bool ret = write_u32(client->fd, CC_AUTH) && write_u8(client->fd, success) && send_map(client);
pthread_mutex_unlock(&client->mtx);
return ret;