コード例 #1
0
ファイル: netplay.c プロジェクト: frangarcj/RetroArch
/**
 * netplay_new:
 * @server               : IP address of server.
 * @port                 : Port of server.
 * @frames               : Amount of lag frames.
 * @check_frames         : Frequency with which to check CRCs.
 * @cb                   : Libretro callbacks.
 * @spectate             : If true, enable spectator mode.
 * @nick                 : Nickname of user.
 * @quirks               : Netplay quirks required for this session.
 *
 * Creates a new netplay handle. A NULL host means we're 
 * hosting (user 1).
 *
 * Returns: new netplay handle.
 **/
netplay_t *netplay_new(const char *server, uint16_t port,
      unsigned frames, unsigned check_frames,
      const struct retro_callbacks *cb,
      bool spectate, const char *nick, uint64_t quirks)
{
   netplay_t *netplay = (netplay_t*)calloc(1, sizeof(*netplay));
   if (!netplay)
      return NULL;

   netplay->fd                = -1;
   netplay->tcp_port          = port;
   netplay->cbs               = *cb;
   netplay->port              = server ? 0 : 1;
   netplay->spectate.enabled  = spectate;
   netplay->is_server         = server == NULL;
   netplay->stall_frames      = frames;
   netplay->check_frames      = check_frames;
   netplay->quirks            = quirks;

   strlcpy(netplay->nick, nick, sizeof(netplay->nick));

   if (!netplay_init_buffers(netplay, frames))
   {
      free(netplay);
      return NULL;
   }

   if(spectate)
      netplay->net_cbs = netplay_get_cbs_spectate();
   else
      netplay->net_cbs = netplay_get_cbs_net();

   if (!init_socket(netplay, server, port))
   {
      free(netplay);
      return NULL;
   }

   if(!netplay_info_cb(netplay, frames))
      goto error;

   return netplay;

error:
   if (netplay->fd >= 0)
      socket_close(netplay->fd);

   free(netplay);
   return NULL;
}
コード例 #2
0
ファイル: netplay.c プロジェクト: carriercomm/RetroArch
/**
 * netplay_new:
 * @server               : IP address of server.
 * @port                 : Port of server.
 * @frames               : Amount of lag frames.
 * @cb                   : Libretro callbacks.
 * @spectate             : If true, enable spectator mode.
 * @nick                 : Nickname of user.
 *
 * Creates a new netplay handle. A NULL host means we're
 * hosting (user 1).
 *
 * Returns: new netplay handle.
 **/
netplay_t *netplay_new(const char *server, uint16_t port,
                       unsigned frames, const struct retro_callbacks *cb,
                       bool spectate,
                       const char *nick)
{
    netplay_t *netplay = NULL;

    if (frames > UDP_FRAME_PACKETS)
        frames = UDP_FRAME_PACKETS;

    netplay = (netplay_t*)calloc(1, sizeof(*netplay));
    if (!netplay)
        return NULL;

    netplay->fd                = -1;
    netplay->udp_fd            = -1;
    netplay->cbs               = *cb;
    netplay->port              = server ? 0 : 1;
    netplay->spectate.enabled  = spectate;
    netplay->is_server         = server == NULL;
    strlcpy(netplay->nick, nick, sizeof(netplay->nick));

    if(spectate)
        netplay->net_cbs = netplay_get_cbs_spectate();
    else
        netplay->net_cbs = netplay_get_cbs_net();

    if (!init_socket(netplay, server, port))
    {
        free(netplay);
        return NULL;
    }

    if(!netplay_info_cb(netplay, frames))
        goto error;

    return netplay;

error:
    if (netplay->fd >= 0)
        socket_close(netplay->fd);
    if (netplay->udp_fd >= 0)
        socket_close(netplay->udp_fd);

    free(netplay);
    return NULL;
}