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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines