void net_send_state_and_sync(GameNetConnection& net, GameState* gs) { if (gs->game_settings().network_debug_mode) { // net.check_integrity(gs); return; } printf("Sent sync on frame %d\n", gs->frame()); SerializeBuffer& sb = net.grab_buffer(GameNetConnection::PACKET_FORCE_SYNC); if (!net.is_connected()) return; // Make sure we don't receive any stray actions after sync. // gs->local_player()->enqueue_io_actions(gs); // players_poll_for_actions(gs); // Make sure we are all sync'd with the same rng, even if we have to contrive a state. int mtwistseed = gs->rng().rand(); gs->rng().init_genrand(mtwistseed); sb.write_int(mtwistseed); gs->serialize(sb); net.send_packet(sb, NetConnection::ALL_RECEIVERS); // Wait for clients to receive the synch data before continuing net_sync_and_discard(net, GameNetConnection::PACKET_SYNC_ACK); post_sync(gs); net_send_sync_ack(net); }
bool GameNetConnection::consume_sync_messages(GameState* gs) { // printf("Delayed Messages: %d\n", _delayed_messages.size()); QueuedMessage qm; if (!extract_message(qm, _delayed_messages, PACKET_FORCE_SYNC)) { return false; } // Make sure we don't receive any stray actions after sync. // gs->local_player()->enqueue_io_actions(gs); // players_poll_for_actions(gs); printf("Found sync buffer!\n"); net_recv_sync_data(*qm.message, gs); delete qm.message; net_send_sync_ack(*this); post_sync(gs); // Wait for server to receive acks for all clients before continuing net_sync_and_discard(*this, PACKET_SYNC_ACK); return true; }