void packet_send_open_window(struct client *client, uint8_t type, const char *title, uint8_t slots) { bedrock_packet packet; uint8_t use_title = 1; if (!title) { title = ""; use_title = 0; } while (++window_id == 0); #if 0 packet_init(&packet, SERVER_OPEN_WINDOW); packet_pack_byte(&packet, window_id); packet_pack_byte(&packet, type); packet_pack_string(&packet, title); packet_pack_byte(&packet, slots); packet_pack_byte(&packet, use_title); client_send_packet(client, &packet); client->window_data.id = window_id; client->window_data.type = type; #endif }
void packet_send_destroy_entity_player(struct client *client, struct client *c) { bedrock_packet packet; uint8_t count = 1; packet_init(&packet, SERVER_DESTROY_ENTITY); packet_pack_int(&packet, &count, sizeof(count)); packet_pack_int(&packet, &c->id, sizeof(c->id)); client_send_packet(client, &packet); }
void packet_send_destroy_entity_dropped_item(struct client *client, struct dropped_item *di) { bedrock_packet packet; uint8_t count = 1; packet_init(&packet, SERVER_DESTROY_ENTITY); packet_pack_int(&packet, &count, sizeof(count)); packet_pack_int(&packet, &di->eid, sizeof(di->eid)); client_send_packet(client, &packet); }
void packet_send_update_window_property(struct client *client, int8_t window_id, int16_t property, int16_t value) { bedrock_packet packet; packet_init(&packet, SERVER_UPDATE_WINDOW_PROPERTY); packet_pack_int(&packet, &window_id, sizeof(window_id)); packet_pack_int(&packet, &property, sizeof(property)); packet_pack_int(&packet, &value, sizeof(value)); client_send_packet(client, &packet); }
void packet_send_player_list_item(struct client *client, struct client *c, uint8_t online) { bedrock_packet packet; #if 0 packet_init(&packet, SERVER_PLAYER_LIST); packet_pack_string(&packet, c->name); packet_pack_byte(&packet, online); packet_pack_short(&packet, c->ping); client_send_packet(client, &packet); #endif }
void packet_send_set_slot(struct client *client, uint8_t window_id, uint16_t slot, struct item *item, uint8_t count, int16_t damage) { bedrock_packet packet; struct item_stack slot_data; slot_data.id = item != NULL ? item->id : -1; slot_data.count = count; slot_data.metadata = damage; packet_init(&packet, SERVER_SET_SLOT); packet_pack_int(&packet, &window_id, sizeof(window_id)); packet_pack_int(&packet, &slot, sizeof(slot)); packet_pack_slot(&packet, &slot_data); client_send_packet(client, &packet); }
void packet_send_encryption_request(struct client *client) { int16_t pubkey_len = crypto_pubkey_len(); int16_t verify_token_length = BEDROCK_VERIFY_TOKEN_LEN; bedrock_packet packet; packet_init(&packet, LOGIN_SERVER_ENCRYPTION_REQUEST); packet_pack_string(&packet, "-"); // server ID packet_pack_int(&packet, &pubkey_len, sizeof(pubkey_len)); packet_pack(&packet, crypto_pubkey(), pubkey_len); packet_pack_int(&packet, &verify_token_length, sizeof(verify_token_length)); packet_pack(&packet, crypto_auth_token(), BEDROCK_VERIFY_TOKEN_LEN); client_send_packet(client, &packet); }
static void handle_card(struct sstate *ss) { unsigned char buf[2048]; int rd; struct rx_info *ri = (struct rx_info*) buf; struct client *c; rd = card_read(ss, ri + 1, sizeof(buf) - sizeof(*ri), ri); if (rd >= 0) rd += sizeof(*ri); #ifdef __MACH__ ri->ri_mactime = OSSwapHostToBigInt64(ri->ri_mactime); ri->ri_power = OSSwapHostToBigInt32(ri->ri_power); ri->ri_noise = OSSwapHostToBigInt32(ri->ri_noise); ri->ri_channel = OSSwapHostToBigInt32(ri->ri_channel); ri->ri_rate = OSSwapHostToBigInt32(ri->ri_rate); ri->ri_antenna = OSSwapHostToBigInt32(ri->ri_antenna); #elif defined(__FreeBSD__) #if BYTE_ORDER == BIG_ENDIAN # define __be32_to_cpu(x) (x) # define __be64_to_cpu(x) (x) #elif BYTE_ORDER == LITTLE_ENDIAN # define __be32_to_cpu(x) __bswap32(x) # define __be64_to_cpu(x) __bswap64(x) #endif #else ri->ri_mactime = __cpu_to_be64(ri->ri_mactime); ri->ri_power = __cpu_to_be32(ri->ri_power); ri->ri_noise = __cpu_to_be32(ri->ri_noise); ri->ri_channel = __cpu_to_be32(ri->ri_channel); ri->ri_rate = __cpu_to_be32(ri->ri_rate); ri->ri_antenna = __cpu_to_be32(ri->ri_antenna); #endif /* __MACH__ */ c = ss->ss_clients.c_next; while (c != &ss->ss_clients) { client_send_packet(ss, c, buf, rd); c = c->c_next; } }
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, ;);