Ejemplo n.º 1
0
int get_inputs_from_server(unsigned char *buf)
{
  if (prot && base->input_state!=INPUT_PROCESSING)      // if input is not here, wait on it
  {
    time_marker start;

    int total_retry=0;
    Jwindow *abort=NULL;

    while (base->input_state!=INPUT_PROCESSING)
    {
      if (!prot)
      {
    base->input_state=INPUT_PROCESSING;
    return 1;
      }
      service_net_request();

      time_marker now;                   // if this is taking to long, the packet was probably lost, ask for it to be resent

      if (now.diff_time(&start)>0.05)
      {
    if (prot->debug_level(net_protocol::DB_IMPORTANT_EVENT))
      fprintf(stderr,"(missed packet)");


    game_face->input_missing();
    start.get_time();

    total_retry++;
    if (total_retry==12000)    // 2 minutes and nothing
    {
      abort=wm->CreateWindow(ivec2(0, yres / 2), ivec2(-1, wm->font()->Size().y*4),
                   new info_field(0, 0, 0, symbol_str("waiting"),
                          new button(0, wm->font()->Size().y + 5, ID_NET_DISCONNECT,
                             symbol_str("slack"),NULL)),symbol_str("Error"));
      wm->flush_screen();
    }
      }
      if (abort)
      {
    if (wm->IsPending())
    {
      Event ev;
      do
      {
        wm->get_event(ev);
        if (ev.type==EV_MESSAGE && ev.message.id==ID_NET_DISCONNECT)
        {
          kill_slackers();
          base->input_state=INPUT_PROCESSING;
        }
      } while (wm->IsPending());

      wm->flush_screen();
    }
      }
    }

    if (abort)
    {
      wm->close_window(abort);
      the_game->reset_keymap();

    }
  }


  memcpy(base->last_packet.data,base->packet.data,base->packet.packet_size()+base->packet.packet_prefix_size());

  int size=base->packet.packet_size();
  memcpy(buf,base->packet.packet_data(),size);

  base->packet.packet_reset();
  base->mem_lock=0;

  return size;
}
Ejemplo n.º 2
0
int get_inputs_from_server(unsigned char *buf)
{
  if (idle_man)
    idle_man->idle_reset();

  if (prot && base->input_state!=INPUT_PROCESSING)      // if input is not here, wait on it
  {
    time_marker start;

    int total_retry=0;
    jwindow *abort=NULL;

    while (base->input_state!=INPUT_PROCESSING)
    { 
      if (!prot)
      { 
        base->input_state=INPUT_PROCESSING; 
        return 1; 
      }
      service_net_request();

      time_marker now;                   // if this is taking to long, the packet was probably lost, ask for it to be resent

      if (now.diff_time(&start)>0.05)
      {
        if (idle_man)
          idle_man->idle();
        if (prot->debug_level(net_protocol::DB_IMPORTANT_EVENT))
          dprintf("(missed packet)");
			
        if (game_face)
          game_face->input_missing();
        start.get_time();
			
        total_retry++;
        if (total_retry==12000)    // 2 minutes and nothing
        {
          abort=eh->new_window(0,yres/2,-1,eh->font()->height()*4,
              new info_field(WINDOW_FRAME_LEFT,
                  WINDOW_FRAME_TOP,
                  0,symbol_str("waiting"),
                  new button(WINDOW_FRAME_LEFT,
                      WINDOW_FRAME_TOP+eh->font()->height()+5,ID_NET_DISCONNECT,
                      symbol_str("slack"),NULL)),symbol_str("Error"));	  
          eh->flush_screen();
        }
      }
      if (abort)
      {
        if (eh->event_waiting())
        {
          event ev;
          do
          {
            eh->get_event(ev);
            if (ev.type==EV_MESSAGE && ev.message.id==ID_NET_DISCONNECT)
            {
              kill_slackers();
              base->input_state=INPUT_PROCESSING; 
            }
          } while (eh->event_waiting());
			
          eh->flush_screen();
        }
      }
    }

    if (abort)
    {
      eh->close_window(abort);
      the_game->reset_keymap();

    }
  }


  memcpy(base->last_packet.data,base->packet.data,base->packet.packet_size()+base->packet.packet_prefix_size());
  
  int size=base->packet.packet_size();  
  memcpy(buf,base->packet.packet_data(),size);

  base->packet.packet_reset();
  base->mem_lock=0;

  return size;
}