ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/socket/loop.C
(Generate patch)

Comparing deliantra/server/socket/loop.C (file contents):
Revision 1.25 by root, Sat Dec 16 21:40:26 2006 UTC vs.
Revision 1.26 by root, Sat Dec 16 22:14:42 2006 UTC

26 * Main client/server loops. 26 * Main client/server loops.
27 * 27 *
28 * \date 2003-12-02 28 * \date 2003-12-02
29 * 29 *
30 * loop.c mainly deals with initialization and higher level socket 30 * loop.c mainly deals with initialization and higher level socket
31 * maintenance (checking for lost connections and if data has arrived.) 31 * maintanance (checking for lost connections and if data has arrived.)
32 * The reading of data is handled in ericserver.c
33 */ 32 */
34 33
35 34
36#include <global.h> 35#include <global.h>
37#include <sproto.h> 36#include <sproto.h>
69 if (cmd_queue.size () >= MAX_QUEUE_DEPTH) 68 if (cmd_queue.size () >= MAX_QUEUE_DEPTH)
70 { 69 {
71 //TODO: just disconnect here? 70 //TODO: just disconnect here?
72 reset_state (); 71 reset_state ();
73 send_packet_printf ("drawinfo %d command queue overflow, ignoring.", NDI_RED); 72 send_packet_printf ("drawinfo %d command queue overflow, ignoring.", NDI_RED);
74 }
75 else if (!cmd_queue.empty () && cmd_queue.front ().stamp + MAX_QUEUE_BACKLOG < stamp)
76 {
77 reset_state ();
78 send_packet_printf ("drawinfo %d too many commands in queue, ignoring.", NDI_RED);
79 } 73 }
80 else 74 else
81 { 75 {
82 cmd_queue.push_back (command ()); 76 cmd_queue.push_back (command ());
83 command &cmd = cmd_queue.back (); 77 command &cmd = cmd_queue.back ();
89} 83}
90 84
91bool 85bool
92client::handle_command () 86client::handle_command ()
93{ 87{
88 bool skipping = false;
89
90 while (!cmd_queue.empty ()
94 if (pl && pl->state == ST_PLAYING && pl->ob && pl->ob->speed_left < 0) 91 && !(pl && pl->state == ST_PLAYING && pl->ob && pl->ob->speed_left < 0))
95 return false; 92 {
96
97 if (cmd_queue.empty ())
98 return false;
99
100 command &cmd = cmd_queue.front (); 93 command &cmd = cmd_queue.front ();
101 94
102 if (cmd.stamp + MAX_QUEUE_BACKLOG < now ()) 95 if (cmd.stamp + MAX_QUEUE_BACKLOG < now ())
103 { 96 {
97 if (!skipping)
98 {
99 skipping = true;
104 reset_state (); 100 reset_state ();
105 send_packet_printf ("drawinfo %d ignoring delayed command.", NDI_RED); 101 send_packet_printf ("drawinfo %d ignoring delayed commands.", NDI_RED);
106 } 102 }
103
104 cmd_queue.pop_front ();
105 }
107 else 106 else
107 {
108 execute (cmd.handler, cmd.data, cmd.datalen); 108 execute (cmd.handler, cmd.data, cmd.datalen);
109
110 cmd_queue.pop_front (); 109 cmd_queue.pop_front ();
111
112 return true; 110 return true;
111 }
112 }
113
114 return false;
113} 115}
114 116
115void 117void
116flush_sockets (void) 118flush_sockets (void)
117{ 119{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines