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.70 by root, Thu Nov 8 19:43:30 2007 UTC vs.
Revision 1.82 by root, Mon Oct 12 14:00:59 2009 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002-2003,2007 Mark Wedel & The Crossfire Development Team 5 * Copyright (©) 2002-2003,2007 Mark Wedel & The Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
10 * the Free Software Foundation, either version 3 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 11 * option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the Affero GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
20 * 21 *
21 * The authors can be reached via e-mail to <support@deliantra.net> 22 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 23 */
23 24
24/** 25/**
49#define BG_SCRUB_RATE 4 // how often to send a face in the background 50#define BG_SCRUB_RATE 4 // how often to send a face in the background
50 51
51#define MAX_QUEUE_DEPTH 50 52#define MAX_QUEUE_DEPTH 50
52#define MAX_QUEUE_BACKLOG 3. 53#define MAX_QUEUE_BACKLOG 3.
53 54
54// disconnect a socket after this many seconds without an ack
55#define SOCKET_TIMEOUT 8.
56
57void 55void
58client::reset_state () 56client::reset_state ()
59{ 57{
60 if (!pl) 58 if (!pl)
61 return; 59 return;
75 reset_state (); 73 reset_state ();
76 send_packet_printf ("drawinfo %d command queue overflow, ignoring.", NDI_RED); 74 send_packet_printf ("drawinfo %d command queue overflow, ignoring.", NDI_RED);
77 } 75 }
78 else 76 else
79 { 77 {
80 cmd_queue.push_back (command ()); 78 cmd_queue.resize (cmd_queue.size () + 1);
81 command &cmd = cmd_queue.back (); 79 command &cmd = cmd_queue.back ();
82 cmd.stamp = stamp; 80 cmd.stamp = stamp;
83 cmd.handler = handler; 81 cmd.handler = handler;
84 cmd.data = salloc<char> (datalen + 1, data); 82 cmd.data = salloc<char> (datalen + 1, data);
85 cmd.datalen = datalen; 83 cmd.datalen = datalen;
95 { 93 {
96 command &cmd = cmd_queue.front (); 94 command &cmd = cmd_queue.front ();
97 95
98 if (cmd.stamp + MAX_QUEUE_BACKLOG < NOW) 96 if (cmd.stamp + MAX_QUEUE_BACKLOG < NOW)
99 { 97 {
100 reset_state (); 98 reset_state (); // the command might actually reset some movement state etc.
101 send_packet_printf ("drawinfo %d ignoring delayed commands.", NDI_RED); 99
100 if (pl)
101 pl->failmsg (
102 "Cannot keep up with your commands, ignoring them! "
103 "H<Your character cannot keep up with the instructions you give G<him|her>. "
104 "Try issuing commands slower, or, if G<he|she> is incapacitated (paralyzed and so on), "
105 "wait till your character can act again.\n\nIf G<he|she> is permanently stuck, then "
106 "try the B<suicide> command (or use B<chat> to ask somebody to B<invite> you out).>"
107 );
102 } 108 }
103 else 109 else
104 execute (cmd.handler, cmd.data, cmd.datalen); 110 execute (cmd.handler, cmd.data, cmd.datalen);
105 111
112 sfree<char> (cmd.data, cmd.datalen + 1);
106 cmd_queue.pop_front (); 113 cmd_queue.pop_front ();
107 return true; 114 return true;
108 } 115 }
109 else 116 else
110 return false; 117 return false;
113void 120void
114client::tick () 121client::tick ()
115{ 122{
116 if (!pl || destroyed ()) 123 if (!pl || destroyed ())
117 return; 124 return;
125
126 pl->dirty = true;
118 127
119 /* Update the players stats once per tick. More efficient than 128 /* Update the players stats once per tick. More efficient than
120 * sending them whenever they change, and probably just as useful 129 * sending them whenever they change, and probably just as useful
121 */ 130 */
122 esrv_update_stats (pl); 131 esrv_update_stats (pl);
123 132
124 if (last_weight != -1 && last_weight != WEIGHT (pl->ob)) 133 sint32 weight = pl->ob->client_weight ();
134
135 if (last_weight != weight)
125 { 136 {
137 pl->ob->update_stats ();
126 esrv_update_item (UPD_WEIGHT, pl->ob, pl->ob); 138 esrv_update_item (UPD_WEIGHT, pl->ob, pl->ob);
127 if (last_weight != WEIGHT (pl->ob))
128 LOG (llevError, "esrv_update_item(UPD_WEIGHT) did not set player weight: is %lu, should be %lu\n",
129 (unsigned long) last_weight, WEIGHT (pl->ob));
130 } 139 }
131 140
132 draw_client_map (pl); 141 draw_client_map (pl);
133 142
134 if (update_look) 143 if (update_look)
155 tcpi.tcpi_snd_ssthresh, tcpi.tcpi_snd_cwnd, tcpi.tcpi_advmss, tcpi.tcpi_pmtu, tcpi.tcpi_advmss, 164 tcpi.tcpi_snd_ssthresh, tcpi.tcpi_snd_cwnd, tcpi.tcpi_advmss, tcpi.tcpi_pmtu, tcpi.tcpi_advmss,
156 165
157 tcpi.tcpi_snd_cwnd - (tcpi.tcpi_unacked - tcpi.tcpi_sacked)); 166 tcpi.tcpi_snd_cwnd - (tcpi.tcpi_unacked - tcpi.tcpi_sacked));
158#endif 167#endif
159 168
160 // fast-time-out a player by checking for missign acks 169 // fast-time-out a player by checking for missing acks
161 // do this only when player is active 170 // do this only when player is active
162 if (pl && pl->active 171 if (pl && pl->active
163 && tcpi.tcpi_last_ack_recv > int (SOCKET_TIMEOUT * 1000)) 172 && tcpi.tcpi_last_ack_recv > int (socket_timeout * 1000))
164 { 173 {
165 send_msg (NDI_RED | NDI_REPLY, "connection-timeout", "safety disconnect due to tcp/ip timeout (no packets received)"); 174 send_msg (NDI_RED | NDI_REPLY, "connection-timeout", "safety disconnect due to tcp/ip timeout (no packets received)");
166 write_outputbuffer (); 175 write_outputbuffer ();
167 176
168 LOG (llevDebug, "connection on fd %d closed due to ack timeout (%u/%u/%u)\n", fd, 177 LOG (llevDebug, "connection on fd %d closed due to ack timeout (%u/%u/%u)\n", fd,
179#if HAVE_TCP_INFO 188#if HAVE_TCP_INFO
180 // further restrict the available bandwidth by the excess bandwidth available 189 // further restrict the available bandwidth by the excess bandwidth available
181 max_send = min (max_send, (tcpi.tcpi_snd_cwnd - tcpi.tcpi_unacked + tcpi.tcpi_sacked) * mss); 190 max_send = min (max_send, (tcpi.tcpi_snd_cwnd - tcpi.tcpi_unacked + tcpi.tcpi_sacked) * mss);
182#endif 191#endif
183 192
184 // if we can split images, round to next-lowest mss 193 // round to next-lowest mss
185 if (fxix) max_send -= max_send % mss; 194 max_send -= max_send % mss;
186 195
187 if (ixface.empty ()) 196 if (ixface.empty ())
188 { 197 {
189 // regularly send a new face when queue is empty 198 // regularly send a new face when queue is empty
190 if (bg_scrub && !--bg_scrub && enable_bg_scrub) 199 if (bg_scrub && !--bg_scrub)
191 while (scrub_idx < faces.size () - 1) 200 while (scrub_idx < faces.size () - 1)
192 { 201 {
193 ++scrub_idx; 202 ++scrub_idx;
194 203
195 if (!faces_sent [scrub_idx]) 204 if (!faces_sent [scrub_idx])
217 226
218 ixsend &ix = ixface.back (); 227 ixsend &ix = ixface.back ();
219 228
220 if (facedata *d = face_data (ix.idx, faceset)) 229 if (facedata *d = face_data (ix.idx, faceset))
221 { 230 {
222 if (fxix)
223 {
224 // estimate the packet header overhead "ix " + idx + (new)ofs 231 // estimate the packet header overhead "ix " + idx + (new)ofs
225 int pktlen = 3 + ber32::encoded_size (ix.idx) + ber32::encoded_size (ix.ofs); 232 int pktlen = 3 + ber32::encoded_size (ix.idx) + ber32::encoded_size (ix.ofs);
226 int chunk = min (avail - packet::hdrlen, MAXSOCKBUF) - pktlen; 233 int chunk = min (avail - packet::hdrlen, MAXSOCKBUF) - pktlen;
227 234
228 // only transfer something if the amount of data transferred 235 // only transfer something if the amount of data transferred
229 // has a healthy relation to the header overhead 236 // has a healthy relation to the header overhead
230 if (chunk < 64) 237 if (chunk < 64)
231 break; 238 break;
232 239
233 chunk = min (chunk, (int)ix.ofs); 240 chunk = min (chunk, (int)ix.ofs);
234 241
235 ix.ofs -= chunk; 242 ix.ofs -= chunk;
236 243
237 //fprintf (stderr, "i%dx %6d: %5d+%4d (%4d)\n", fxix, ix.idx,ix.ofs,chunk, ixface.size());//D 244 //fprintf (stderr, "i%dx %6d: %5d+%4d (%4d)\n", fxix, ix.idx,ix.ofs,chunk, ixface.size());//D
238 245
239 packet sl ("ix"); 246 packet sl ("ix");
240 247
241 sl << ber32 (ix.idx) 248 sl << ber32 (ix.idx)
242 << ber32 (ix.ofs) 249 << ber32 (ix.ofs)
243 << data (d->data.data () + ix.ofs, chunk); 250 << data (d->data.data () + ix.ofs, chunk);
244 251
245 send_packet (sl); 252 send_packet (sl);
246 }
247 else
248 {
249 send_image (ix.idx);
250 ix.ofs = 0;
251 }
252 } 253 }
253 else 254 else
254 ix.ofs = 0; 255 ix.ofs = 0;
255 256
256 if (!ix.ofs) 257 if (!ix.ofs)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines