commit 8be0048f2e6936a0def3706187a175a878deed4a parent a30eaf1d39d04a7d384b4acd36aaaf049bbc09a9 Author: Michael Savage <mikejsavage@gmail.com> Date: Sun Jun 25 13:58:01 +0300 Update server to use the new Pool Diffstat:
server/main.cc | | | 11 | ++++++----- |
diff --git a/server/main.cc b/server/main.cc @@ -185,28 +185,29 @@ int main() { WriteStream w( write_buf ); void * player_count_storage = reserve_u16( &w ); - u16 player_count = 0; - for( const PlayerState * state : states ) { + for( size_t i = 0; i < states.elems.n; i++ ) { + PlayerState * state = &states.elems[ i ]; write( &w, state->sid ); if( state->last_message_time + DISCONNECT_TIMEOUT <= now ) { printf( "%08lx disconnected\n", state->sid ); write_u8( &w, 1 ); states.release( state ); + i--; } else { write_u8( &w, 0 ); write( &w, state->pos ); } - player_count++; } // TODO: endianness + u16 player_count = states.elems.n; memcpy( player_count_storage, &player_count, sizeof( player_count ) ); if( w.ok ) { - for( const PlayerState * state : states ) { - send( server_fd_ipv4, state, w ); + for( const PlayerState & state : states.elems ) { + send( server_fd_ipv4, &state, w ); } }