--- deliantra/server/socket/loop.C 2006/12/16 18:39:26 1.24 +++ deliantra/server/socket/loop.C 2006/12/19 04:58:05 1.29 @@ -28,8 +28,7 @@ * \date 2003-12-02 * * loop.c mainly deals with initialization and higher level socket - * maintenance (checking for lost connections and if data has arrived.) - * The reading of data is handled in ericserver.c + * maintanance (checking for lost connections and if data has arrived.) */ @@ -72,18 +71,13 @@ reset_state (); send_packet_printf ("drawinfo %d command queue overflow, ignoring.", NDI_RED); } - else if (!cmd_queue.empty () && cmd_queue.front ().stamp + MAX_QUEUE_BACKLOG < stamp) - { - reset_state (); - send_packet_printf ("drawinfo %d too many commands in queue, ignoring.", NDI_RED); - } else { cmd_queue.push_back (command ()); command &cmd = cmd_queue.back (); cmd.stamp = stamp; cmd.handler = handler; - cmd.data = (char *)salloc (datalen + 1, data); + cmd.data = salloc (datalen + 1, data); cmd.datalen = datalen; } } @@ -91,25 +85,33 @@ bool client::handle_command () { - if (pl && pl->state == ST_PLAYING && pl->ob && pl->ob->speed_left < 0) - return false; + bool skipping = false; - if (cmd_queue.empty ()) - return false; + while (!cmd_queue.empty () + && !(pl && pl->state == ST_PLAYING && pl->ob && pl->ob->speed_left < 0)) + { + command &cmd = cmd_queue.front (); - command &cmd = cmd_queue.front (); + if (cmd.stamp + MAX_QUEUE_BACKLOG < now ()) + { + if (!skipping) + { + skipping = true; + reset_state (); + send_packet_printf ("drawinfo %d ignoring delayed commands.", NDI_RED); + } - if (cmd.stamp + MAX_QUEUE_BACKLOG < now ()) - { - reset_state (); - send_packet_printf ("drawinfo %d ignoring delayed command.", NDI_RED); + cmd_queue.pop_front (); + } + else + { + execute (cmd.handler, cmd.data, cmd.datalen); + cmd_queue.pop_front (); + return true; + } } - else - execute (cmd.handler, cmd.data, cmd.datalen); - cmd_queue.pop_front (); - - return true; + return false; } void @@ -182,9 +184,6 @@ client *s = *i; player *pl = s->pl; - s->handle_packet (); - s->handle_command (); - //TODO: should not be done here, either if (s->status != Ns_Dead && pl) {