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 |
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 |
… | |
… | |
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 | |
106 | sfree<char> (cmd.data, cmd.datalen + 1); |
114 | sfree<char> (cmd.data, cmd.datalen + 1); |
… | |
… | |
114 | void |
122 | void |
115 | client::tick () |
123 | client::tick () |
116 | { |
124 | { |
117 | if (!pl || destroyed ()) |
125 | if (!pl || destroyed ()) |
118 | return; |
126 | return; |
|
|
127 | |
|
|
128 | pl->dirty = true; |
119 | |
129 | |
120 | /* Update the players stats once per tick. More efficient than |
130 | /* Update the players stats once per tick. More efficient than |
121 | * sending them whenever they change, and probably just as useful |
131 | * sending them whenever they change, and probably just as useful |
122 | */ |
132 | */ |
123 | esrv_update_stats (pl); |
133 | esrv_update_stats (pl); |
124 | |
134 | |
125 | if (last_weight != -1 && last_weight != WEIGHT (pl->ob)) |
135 | sint32 weight = pl->ob->client_weight (); |
|
|
136 | |
|
|
137 | if (last_weight != weight) |
126 | { |
138 | { |
|
|
139 | pl->ob->update_stats (); |
127 | esrv_update_item (UPD_WEIGHT, pl->ob, pl->ob); |
140 | 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 | } |
141 | } |
132 | |
142 | |
133 | draw_client_map (pl); |
143 | draw_client_map (pl); |
134 | |
144 | |
135 | if (update_look) |
145 | if (update_look) |
… | |
… | |
180 | #if HAVE_TCP_INFO |
190 | #if HAVE_TCP_INFO |
181 | // further restrict the available bandwidth by the excess bandwidth available |
191 | // 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); |
192 | max_send = min (max_send, (tcpi.tcpi_snd_cwnd - tcpi.tcpi_unacked + tcpi.tcpi_sacked) * mss); |
183 | #endif |
193 | #endif |
184 | |
194 | |
185 | // if we can split images, round to next-lowest mss |
195 | // round to next-lowest mss |
186 | if (fxix) max_send -= max_send % mss; |
196 | max_send -= max_send % mss; |
187 | |
197 | |
188 | if (ixface.empty ()) |
198 | if (ixface.empty ()) |
189 | { |
199 | { |
190 | // regularly send a new face when queue is empty |
200 | // regularly send a new face when queue is empty |
191 | if (bg_scrub && !--bg_scrub && enable_bg_scrub) |
201 | if (bg_scrub && !--bg_scrub) |
192 | while (scrub_idx < faces.size () - 1) |
202 | while (scrub_idx < faces.size () - 1) |
193 | { |
203 | { |
194 | ++scrub_idx; |
204 | ++scrub_idx; |
195 | |
205 | |
196 | if (!faces_sent [scrub_idx]) |
206 | if (!faces_sent [scrub_idx]) |
… | |
… | |
218 | |
228 | |
219 | ixsend &ix = ixface.back (); |
229 | ixsend &ix = ixface.back (); |
220 | |
230 | |
221 | if (facedata *d = face_data (ix.idx, faceset)) |
231 | if (facedata *d = face_data (ix.idx, faceset)) |
222 | { |
232 | { |
223 | if (fxix) |
|
|
224 | { |
|
|
225 | // estimate the packet header overhead "ix " + idx + (new)ofs |
233 | // estimate the packet header overhead "ix " + idx + (new)ofs |
226 | 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); |
227 | int chunk = min (avail - packet::hdrlen, MAXSOCKBUF) - pktlen; |
235 | int chunk = min (avail - packet::hdrlen, MAXSOCKBUF) - pktlen; |
228 | |
236 | |
229 | // only transfer something if the amount of data transferred |
237 | // only transfer something if the amount of data transferred |
230 | // has a healthy relation to the header overhead |
238 | // has a healthy relation to the header overhead |
231 | if (chunk < 64) |
239 | if (chunk < 64) |
232 | break; |
240 | break; |
233 | |
241 | |
234 | chunk = min (chunk, (int)ix.ofs); |
242 | chunk = min (chunk, (int)ix.ofs); |
235 | |
243 | |
236 | ix.ofs -= chunk; |
244 | ix.ofs -= chunk; |
237 | |
245 | |
238 | //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 |
239 | |
247 | |
240 | packet sl ("ix"); |
248 | packet sl ("ix"); |
241 | |
249 | |
242 | sl << ber32 (ix.idx) |
250 | sl << ber32 (ix.idx) |
243 | << ber32 (ix.ofs) |
251 | << ber32 (ix.ofs) |
244 | << data (d->data.data () + ix.ofs, chunk); |
252 | << data (d->data.data () + ix.ofs, chunk); |
245 | |
253 | |
246 | send_packet (sl); |
254 | send_packet (sl); |
247 | } |
|
|
248 | else |
|
|
249 | { |
|
|
250 | send_image (ix.idx); |
|
|
251 | ix.ofs = 0; |
|
|
252 | } |
|
|
253 | } |
255 | } |
254 | else |
256 | else |
255 | ix.ofs = 0; |
257 | ix.ofs = 0; |
256 | |
258 | |
257 | if (!ix.ofs) |
259 | if (!ix.ofs) |