Example #1
0
/**
 * netplay_flip_users:
 * @netplay              : pointer to netplay object
 *
 * On regular netplay, flip who controls user 1 and 2.
 **/
void netplay_flip_users(netplay_t *netplay)
{
   uint32_t flip_frame     = netplay->frame_count + 2 * UDP_FRAME_PACKETS;
   uint32_t flip_frame_net = htonl(flip_frame);
   const char *msg         = NULL;

   if (netplay->spectate)
   {
      msg = "Cannot flip users in spectate mode.";
      goto error;
   }

   if (netplay->port == 0)
   {
      msg = "Cannot flip users if you're not the host.";
      goto error;
   }

   /* Make sure both clients are definitely synced up. */
   if (netplay->frame_count < (netplay->flip_frame + 2 * UDP_FRAME_PACKETS))
   {
      msg = "Cannot flip users yet. Wait a second or two before attempting flip.";
      goto error;
   }

   if (netplay_send_cmd(netplay, NETPLAY_CMD_FLIP_PLAYERS,
            &flip_frame_net, sizeof(flip_frame_net))
         && netplay_get_response(netplay))
   {
      RARCH_LOG("Netplay users are flipped.\n");
      rarch_main_msg_queue_push("Netplay users are flipped.", 1, 180, false);

      /* Queue up a flip well enough in the future. */
      netplay->flip ^= true;
      netplay->flip_frame = flip_frame;
   }
   else
   {
      msg = "Failed to flip users.";
      goto error;
   }

   return;

error:
   RARCH_WARN("%s\n", msg);
   rarch_main_msg_queue_push(msg, 1, 180, false);
}
Example #2
0
void netplay_flip_players(netplay_t *handle)
{
   uint32_t flip_frame = handle->frame_count + 2 * UDP_FRAME_PACKETS;
   uint32_t flip_frame_net = htonl(flip_frame);
   const char *msg = NULL;

   if (handle->spectate)
   {
      msg = "Cannot flip players in spectate mode.";
      goto error;
   }

   if (handle->port == 0)
   {
      msg = "Cannot flip players if you're not the host.";
      goto error;
   }

   // Make sure both clients are definitely synced up.
   if (handle->frame_count < (handle->flip_frame + 2 * UDP_FRAME_PACKETS))
   {
      msg = "Cannot flip players yet. Wait a second or two before attempting flip.";
      goto error;
   }

   if (netplay_send_cmd(handle, NETPLAY_CMD_FLIP_PLAYERS, &flip_frame_net, sizeof(flip_frame_net))
         && netplay_get_response(handle))
   {
      RARCH_LOG("Netplay players are flipped.\n");
      msg_queue_push(g_extern.msg_queue, "Netplay players are flipped.", 1, 180);

      // Queue up a flip well enough in the future.
      handle->flip ^= true;
      handle->flip_frame = flip_frame;
   }
   else
   {
      msg = "Failed to flip players.";
      goto error;
   }

   return;

error:
   RARCH_WARN("%s\n", msg);
   msg_queue_push(g_extern.msg_queue, msg, 1, 180);
}