Exemplo n.º 1
0
static bool netplay_get_cmd(netplay_t *netplay)
{
   uint32_t cmd, flip_frame;
   size_t cmd_size;

   if (!socket_receive_all_blocking(netplay->fd, &cmd, sizeof(cmd)))
      return false;

   cmd = ntohl(cmd);

   cmd_size = cmd & 0xffff;
   cmd      = cmd >> 16;

   switch (cmd)
   {
      case NETPLAY_CMD_FLIP_PLAYERS:
         if (cmd_size != sizeof(uint32_t))
         {
            RARCH_ERR("CMD_FLIP_PLAYERS has unexpected command size.\n");
            return netplay_cmd_nak(netplay);
         }

         if (!socket_receive_all_blocking(netplay->fd, &flip_frame, sizeof(flip_frame)))
         {
            RARCH_ERR("Failed to receive CMD_FLIP_PLAYERS argument.\n");
            return netplay_cmd_nak(netplay);
         }

         flip_frame = ntohl(flip_frame);

         if (flip_frame < netplay->flip_frame)
         {
            RARCH_ERR("Host asked us to flip users in the past. Not possible ...\n");
            return netplay_cmd_nak(netplay);
         }

         netplay->flip ^= true;
         netplay->flip_frame = flip_frame;

         RARCH_LOG("Netplay users are flipped.\n");
         rarch_main_msg_queue_push("Netplay users are flipped.", 1, 180, false);

         return netplay_cmd_ack(netplay);

      default:
         break;
   }

   RARCH_ERR("Unknown netplay command received.\n");
   return netplay_cmd_nak(netplay);
}
Exemplo n.º 2
0
static bool netplay_get_cmd(netplay_t *handle)
{
   uint32_t cmd;
   if (!recv_all(handle->fd, &cmd, sizeof(cmd)))
      return false;

   cmd = ntohl(cmd);

   size_t cmd_size = cmd & 0xffff;
   cmd = cmd >> 16;

   switch (cmd)
   {
      case NETPLAY_CMD_FLIP_PLAYERS:
      {
         if (cmd_size != sizeof(uint32_t))
         {
            RARCH_ERR("CMD_FLIP_PLAYERS has unexpected command size.\n");
            return netplay_cmd_nak(handle);
         }

         uint32_t flip_frame;
         if (!recv_all(handle->fd, &flip_frame, sizeof(flip_frame)))
         {
            RARCH_ERR("Failed to receive CMD_FLIP_PLAYERS argument.\n");
            return netplay_cmd_nak(handle);
         }

         flip_frame = ntohl(flip_frame);
         if (flip_frame < handle->flip_frame)
         {
            RARCH_ERR("Host asked us to flip players in the past. Not possible ...\n");
            return netplay_cmd_nak(handle);
         }

         handle->flip ^= true;
         handle->flip_frame = flip_frame;

         RARCH_LOG("Netplay players are flipped.\n");
         msg_queue_push(g_extern.msg_queue, "Netplay players are flipped.", 1, 180);

         return netplay_cmd_ack(handle);
      }

      default:
         RARCH_ERR("Unknown netplay command received.\n");
         return netplay_cmd_nak(handle);
   }
}
Exemplo n.º 3
0
static bool netplay_get_cmd(netplay_t *netplay)
{
    uint32_t cmd;
    uint32_t flip_frame;
    size_t cmd_size;

    if (!socket_receive_all_blocking(netplay->fd, &cmd, sizeof(cmd)))
        return false;

    cmd      = ntohl(cmd);

    cmd_size = cmd & 0xffff;
    cmd      = cmd >> 16;

    switch (cmd)
    {
    case NETPLAY_CMD_FLIP_PLAYERS:
        if (cmd_size != sizeof(uint32_t))
        {
            RARCH_ERR("CMD_FLIP_PLAYERS recieved an unexpected command size.\n");
            return netplay_cmd_nak(netplay);
        }

        if (!socket_receive_all_blocking(
                    netplay->fd, &flip_frame, sizeof(flip_frame)))
        {
            RARCH_ERR("Failed to receive CMD_FLIP_PLAYERS argument.\n");
            return netplay_cmd_nak(netplay);
        }

        flip_frame = ntohl(flip_frame);

        if (flip_frame < netplay->flip_frame)
        {
            RARCH_ERR("Host asked us to flip users in the past. Not possible ...\n");
            return netplay_cmd_nak(netplay);
        }

        netplay->flip ^= true;
        netplay->flip_frame = flip_frame;

        RARCH_LOG("Netplay users are flipped.\n");
        runloop_msg_queue_push("Netplay users are flipped.", 1, 180, false);

        return netplay_cmd_ack(netplay);

    case NETPLAY_CMD_SPECTATE:
        RARCH_ERR("NETPLAY_CMD_SPECTATE unimplemented.\n");
        return netplay_cmd_nak(netplay);

    case NETPLAY_CMD_DISCONNECT:
        warn_hangup();
        return netplay_cmd_ack(netplay);

    case NETPLAY_CMD_LOAD_SAVESTATE:
        RARCH_ERR("NETPLAY_CMD_LOAD_SAVESTATE unimplemented.\n");
        return netplay_cmd_nak(netplay);

    case NETPLAY_CMD_PAUSE:
        event_cmd_ctl(EVENT_CMD_PAUSE, NULL);
        return netplay_cmd_ack(netplay);

    case NETPLAY_CMD_RESUME:
        event_cmd_ctl(EVENT_CMD_UNPAUSE, NULL);
        return netplay_cmd_ack(netplay);

    default:
        break;
    }

    RARCH_ERR("Unknown netplay command received.\n");
    return netplay_cmd_nak(netplay);
}