--- deliantra/server/socket/loop.C 2006/12/16 21:40:26 1.25 +++ deliantra/server/socket/loop.C 2006/12/25 11:25:50 1.33 @@ -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,11 +71,6 @@ 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 ()); @@ -91,33 +85,40 @@ 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 () + && !(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 flush_sockets (void) { for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) - if ((*i)->status != Ns_Dead) - (*i)->flush (); + (*i)->flush (); } /** @@ -135,58 +136,12 @@ write_cs_stats (); #endif - /* Go through the players. Let the loop set the next pl value, - * since we may remove some - */ - //TODO: must be handled cleanly elsewhere - for (player *pl = first_player; pl; ) - { - player *npl = pl->next; - - //TODO: must be handled cleanly elsewhere - if (!pl->socket || pl->socket->status == Ns_Dead) - { - save_player (pl->ob, 0); - - if (!QUERY_FLAG (pl->ob, FLAG_REMOVED)) - { - terminate_all_pets (pl->ob); - pl->ob->remove (); - } - - leave (pl, 1); - final_free_player (pl); - } - - pl = npl; - } - - for (sockvec::iterator i = clients.begin (); i != clients.end (); ) - { - client *s = *i; - - if (s->status == Ns_Dead) - { - clients.erase (i); - delete s; - } - else - ++i; - } - - /* We need to do some of the processing below regardless */ - - /* Check for any input on the sockets */ + //TODO: should not be done here, either for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) { 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) + if (player *pl = s->pl) { /* Update the players stats once per tick. More efficient than * sending them whenever they change, and probably just as useful @@ -206,6 +161,8 @@ if (s->update_look) esrv_draw_look (pl->ob); } + + s->refcnt_chk (); } }