int nbt_read_tag(nbt_file *nbt, nbt_tag **parent) { nbt_type type = 0; /* Read the type */ gzread(nbt->fp, &type, 1); (*parent)->type = type; (*parent)->name = NULL; (*parent)->value = NULL; if (type != TAG_END) /* TAG_END has no name */ nbt_read_string(nbt, &((*parent)->name)); nbt_read(nbt, type, &((*parent)->value)); return type; }
int32_t nbt_read_list(nbt_file *nbt, char *type_out, void ***target) { char type; int32_t len; int i; gzread(nbt->fp, &type, 1); *type_out = type; gzread(nbt->fp, &len, sizeof(len)); if (get_endianness() == L_ENDIAN) swapi((uint32_t *)&len); *target = malloc(len * sizeof(void *)); for (i = 0; i < len; ++i) nbt_read(nbt, type, &((*target)[i])); return len; }
void packet_send_join_game(struct client *client) { bedrock_packet packet; int32_t dimension; uint8_t b; nbt_copy(client->data, TAG_INT, &dimension, sizeof(dimension), 1, "Dimension"); packet_init(&packet, SERVER_JOIN_GAME); packet_pack_int(&packet, &client->id, sizeof(client->id)); /* Entity ID */ b = client->gamemode; packet_pack_int(&packet, &b, sizeof(b)); b = dimension; packet_pack_int(&packet, &b, sizeof(b)); packet_pack_int(&packet, nbt_read(client->world->data, TAG_BYTE, 2, "Data", "hardcore"), sizeof(uint8_t)); /* hardcore */ b = server_maxusers; packet_pack_int(&packet, &b, sizeof(b)); /* Max players */ packet_pack_string(&packet, nbt_read_string(client->world->data, 2, "Data", "generatorName")); /* Level type */ client_send_packet(client, &packet); bedrock_assert(client->state == STATE_LOGGED_IN, ;);