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,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 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 | /** |
… | |
… | |
42 | #include <netdb.h> |
41 | #include <netdb.h> |
43 | |
42 | |
44 | #include <unistd.h> |
43 | #include <unistd.h> |
45 | #include <arpa/inet.h> |
44 | #include <arpa/inet.h> |
46 | |
45 | |
47 | #include <loader.h> |
|
|
48 | |
|
|
49 | #define BG_SCRUB_RATE 4 // how often to send a face in the background |
46 | #define BG_SCRUB_RATE 4 // how often to send a face in the background |
50 | |
47 | |
51 | #define MAX_QUEUE_DEPTH 50 |
48 | #define MAX_QUEUE_DEPTH 50 |
52 | #define MAX_QUEUE_BACKLOG 3. |
49 | #define MAX_QUEUE_BACKLOG 3. |
53 | |
50 | |
… | |
… | |
66 | { |
63 | { |
67 | tstamp stamp = NOW; |
64 | tstamp stamp = NOW; |
68 | |
65 | |
69 | if (cmd_queue.size () >= MAX_QUEUE_DEPTH) |
66 | if (cmd_queue.size () >= MAX_QUEUE_DEPTH) |
70 | { |
67 | { |
71 | //TODO: just disconnect here? |
|
|
72 | reset_state (); |
68 | reset_state (); |
73 | send_packet_printf ("drawinfo %d command queue overflow, ignoring.", NDI_RED); |
69 | send_packet_printf ("drawinfo %d command queue overflow, ignoring.", NDI_RED); |
74 | } |
70 | } |
75 | else |
71 | else |
76 | { |
72 | { |
… | |
… | |
125 | pl->dirty = true; |
121 | pl->dirty = true; |
126 | |
122 | |
127 | /* Update the players stats once per tick. More efficient than |
123 | /* Update the players stats once per tick. More efficient than |
128 | * sending them whenever they change, and probably just as useful |
124 | * sending them whenever they change, and probably just as useful |
129 | */ |
125 | */ |
|
|
126 | pl->need_updated_stats (); |
130 | esrv_update_stats (pl); |
127 | esrv_update_stats (pl); |
|
|
128 | |
|
|
129 | if (pl->ns->update_spells) |
|
|
130 | esrv_update_spells (pl); |
131 | |
131 | |
132 | sint32 weight = pl->ob->client_weight (); |
132 | sint32 weight = pl->ob->client_weight (); |
133 | |
133 | |
134 | if (last_weight != weight) |
134 | if (last_weight != weight) |
135 | { |
135 | { |
… | |
… | |
178 | destroy (); |
178 | destroy (); |
179 | } |
179 | } |
180 | } |
180 | } |
181 | #endif |
181 | #endif |
182 | |
182 | |
|
|
183 | // limit budget surplus/deficit by one mss, add per-tick budget |
183 | rate_avail = min (max_rate + mss, rate_avail + max_rate); |
184 | rate_avail = min (rate_avail, mss) + max_rate; |
184 | |
185 | |
185 | int max_send = rate_avail; |
186 | int max_send = rate_avail; |
186 | |
187 | |
187 | #if HAVE_TCP_INFO |
188 | #if HAVE_TCP_INFO |
188 | // further restrict the available bandwidth by the excess bandwidth available |
189 | // further restrict the available bandwidth by the excess bandwidth available |
189 | max_send = min (max_send, (tcpi.tcpi_snd_cwnd - tcpi.tcpi_unacked + tcpi.tcpi_sacked) * mss); |
190 | min_it (max_send, (tcpi.tcpi_snd_cwnd - tcpi.tcpi_unacked + tcpi.tcpi_sacked) * mss); |
190 | #endif |
191 | #endif |
191 | |
192 | |
192 | // round to next-lowest mss |
193 | // round to next-lowest mss |
193 | max_send -= max_send % mss; |
194 | max_send -= max_send % mss; |
194 | |
195 | |
… | |
… | |
244 | |
245 | |
245 | packet sl ("ix"); |
246 | packet sl ("ix"); |
246 | |
247 | |
247 | sl << ber32 (ix.idx) |
248 | sl << ber32 (ix.idx) |
248 | << ber32 (ix.ofs) |
249 | << ber32 (ix.ofs) |
249 | << data (d->data.data () + ix.ofs, chunk); |
250 | << data (d->data + ix.ofs, chunk); |
250 | |
251 | |
251 | send_packet (sl); |
252 | send_packet (sl); |
252 | } |
253 | } |
253 | else |
254 | else |
254 | ix.ofs = 0; |
255 | ix.ofs = 0; |
… | |
… | |
265 | |
266 | |
266 | rate_avail -= outputbuffer_len (); |
267 | rate_avail -= outputbuffer_len (); |
267 | } |
268 | } |
268 | |
269 | |
269 | void |
270 | void |
270 | client::flush_sockets (void) |
271 | client::flush_sockets () |
271 | { |
272 | { |
272 | for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) |
273 | for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) |
273 | (*i)->flush (); |
274 | (*i)->flush (); |
274 | } |
275 | } |
275 | |
276 | |
276 | void |
277 | void |
277 | client::clock (void) |
278 | client::clock () |
278 | { |
279 | { |
279 | for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) |
280 | for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) |
280 | (*i)->tick (); |
281 | (*i)->tick (); |
281 | |
282 | |
282 | // give them all the same chances |
283 | // give them all the same chances |