/************************************************************************** Split the attribute block into chunks and send them over pconn. **************************************************************************/ void send_attribute_block(const struct player *pplayer, struct connection *pconn) { struct packet_player_attribute_chunk packet; int current_chunk, chunks, bytes_left; if (!pplayer || !pplayer->attribute_block.data) { return; } fc_assert_ret(pplayer->attribute_block.length > 0 && pplayer->attribute_block.length < MAX_ATTRIBUTE_BLOCK); chunks = (pplayer->attribute_block.length - 1) / ATTRIBUTE_CHUNK_SIZE + 1; bytes_left = pplayer->attribute_block.length; connection_do_buffer(pconn); for (current_chunk = 0; current_chunk < chunks; current_chunk++) { int size_of_current_chunk = MIN(bytes_left, ATTRIBUTE_CHUNK_SIZE); packet.offset = ATTRIBUTE_CHUNK_SIZE * current_chunk; packet.total_length = pplayer->attribute_block.length; packet.chunk_length = size_of_current_chunk; memcpy(packet.data, (char *) (pplayer->attribute_block.data) + packet.offset, packet.chunk_length); bytes_left -= packet.chunk_length; if (packet.chunk_length < ATTRIBUTE_CHUNK_SIZE) { /* Last chunk is not full. Make sure that delta does * not use random data. */ memset(packet.data + packet.chunk_length, 0, ATTRIBUTE_CHUNK_SIZE - packet.chunk_length); } send_packet_player_attribute_chunk(pconn, &packet); } connection_do_unbuffer(pconn); }
void conn_list_do_unbuffer(struct conn_list *dest) { conn_list_iterate(dest, pconn) connection_do_unbuffer(pconn); conn_list_iterate_end; }