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.67 by root, Tue Jul 31 20:10:31 2007 UTC vs.
Revision 1.80 by root, Thu Jul 16 23:17:44 2009 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines