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 it under |
6 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * the terms of the Affero GNU General Public License as published by the |
7 | * the terms of the Affero GNU General Public License as published by the |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
8 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * 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 Affero GNU General Public License |
16 | * You should have received a copy of the Affero GNU General Public License |
19 | * and the GNU General Public License along with this program. If not, see |
17 | * and the GNU General Public License along with this program. If not, see |
20 | * <http://www.gnu.org/licenses/>. |
18 | * <http://www.gnu.org/licenses/>. |
21 | * |
19 | * |
22 | * 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> |
23 | */ |
21 | */ |
24 | |
22 | |
25 | /** |
23 | /** |
26 | * \file |
24 | * \file |
… | |
… | |
43 | #include <netdb.h> |
41 | #include <netdb.h> |
44 | |
42 | |
45 | #include <unistd.h> |
43 | #include <unistd.h> |
46 | #include <arpa/inet.h> |
44 | #include <arpa/inet.h> |
47 | |
45 | |
48 | #include <loader.h> |
|
|
49 | |
|
|
50 | #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 |
51 | |
47 | |
52 | #define MAX_QUEUE_DEPTH 50 |
48 | #define MAX_QUEUE_DEPTH 50 |
53 | #define MAX_QUEUE_BACKLOG 3. |
49 | #define MAX_QUEUE_BACKLOG 3. |
54 | |
50 | |
… | |
… | |
67 | { |
63 | { |
68 | tstamp stamp = NOW; |
64 | tstamp stamp = NOW; |
69 | |
65 | |
70 | if (cmd_queue.size () >= MAX_QUEUE_DEPTH) |
66 | if (cmd_queue.size () >= MAX_QUEUE_DEPTH) |
71 | { |
67 | { |
72 | //TODO: just disconnect here? |
|
|
73 | reset_state (); |
68 | reset_state (); |
74 | send_packet_printf ("drawinfo %d command queue overflow, ignoring.", NDI_RED); |
69 | send_packet_printf ("drawinfo %d command queue overflow, ignoring.", NDI_RED); |
75 | } |
70 | } |
76 | else |
71 | else |
77 | { |
72 | { |
… | |
… | |
118 | } |
113 | } |
119 | |
114 | |
120 | void |
115 | void |
121 | client::tick () |
116 | client::tick () |
122 | { |
117 | { |
123 | if (!pl || destroyed ()) |
118 | if (destroyed ()) |
124 | return; |
119 | return; |
125 | |
120 | |
|
|
121 | if (pl) |
|
|
122 | { |
126 | pl->dirty = true; |
123 | pl->dirty = true; |
127 | |
124 | |
128 | /* Update the players stats once per tick. More efficient than |
125 | /* Update the players stats once per tick. More efficient than |
129 | * sending them whenever they change, and probably just as useful |
126 | * sending them whenever they change, and probably just as useful |
130 | */ |
127 | */ |
|
|
128 | pl->need_updated_stats (); |
131 | esrv_update_stats (pl); |
129 | esrv_update_stats (pl); |
132 | |
130 | |
|
|
131 | if (pl->ns->update_spells) |
|
|
132 | esrv_update_spells (pl); |
|
|
133 | |
133 | sint32 weight = pl->ob->client_weight (); |
134 | sint32 weight = pl->ob->client_weight (); |
134 | |
135 | |
135 | if (last_weight != weight) |
136 | if (last_weight != weight) |
136 | { |
137 | { |
137 | pl->ob->update_stats (); |
138 | pl->ob->update_stats (); |
138 | esrv_update_item (UPD_WEIGHT, pl->ob, pl->ob); |
139 | esrv_update_item (UPD_WEIGHT, pl->ob, pl->ob); |
139 | } |
140 | } |
140 | |
141 | |
141 | draw_client_map (pl); |
142 | draw_client_map (pl); |
142 | |
143 | |
143 | if (update_look) |
144 | if (update_look) |
144 | esrv_draw_look (pl); |
145 | esrv_draw_look (pl); |
145 | |
146 | |
146 | mapinfo_queue_run (); |
147 | mapinfo_queue_run (); |
|
|
148 | } |
147 | |
149 | |
148 | #if HAVE_TCP_INFO |
150 | #if HAVE_TCP_INFO |
149 | // check time of last ack, and, if too old, kill connection |
151 | // check time of last ack, and, if too old, kill connection |
150 | socklen_t len = sizeof (tcpi); |
152 | socklen_t len = sizeof (tcpi); |
151 | |
153 | |
… | |
… | |
179 | destroy (); |
181 | destroy (); |
180 | } |
182 | } |
181 | } |
183 | } |
182 | #endif |
184 | #endif |
183 | |
185 | |
|
|
186 | // limit budget surplus/deficit by one mss, add per-tick budget |
184 | rate_avail = min (max_rate + mss, rate_avail + max_rate); |
187 | rate_avail = min (rate_avail, mss) + max_rate; |
185 | |
188 | |
186 | int max_send = rate_avail; |
189 | int max_send = rate_avail; |
187 | |
190 | |
188 | #if HAVE_TCP_INFO |
191 | #if HAVE_TCP_INFO |
189 | // further restrict the available bandwidth by the excess bandwidth available |
192 | // further restrict the available bandwidth by the excess bandwidth available |
190 | max_send = min (max_send, (tcpi.tcpi_snd_cwnd - tcpi.tcpi_unacked + tcpi.tcpi_sacked) * mss); |
193 | min_it (max_send, (tcpi.tcpi_snd_cwnd - tcpi.tcpi_unacked + tcpi.tcpi_sacked) * mss); |
191 | #endif |
194 | #endif |
192 | |
195 | |
193 | // round to next-lowest mss |
196 | // round to next-lowest mss |
194 | max_send -= max_send % mss; |
197 | max_send -= max_send % mss; |
195 | |
198 | |
… | |
… | |
245 | |
248 | |
246 | packet sl ("ix"); |
249 | packet sl ("ix"); |
247 | |
250 | |
248 | sl << ber32 (ix.idx) |
251 | sl << ber32 (ix.idx) |
249 | << ber32 (ix.ofs) |
252 | << ber32 (ix.ofs) |
250 | << data (d->data.data () + ix.ofs, chunk); |
253 | << data (d->data + ix.ofs, chunk); |
251 | |
254 | |
252 | send_packet (sl); |
255 | send_packet (sl); |
253 | } |
256 | } |
254 | else |
257 | else |
255 | ix.ofs = 0; |
258 | ix.ofs = 0; |
… | |
… | |
266 | |
269 | |
267 | rate_avail -= outputbuffer_len (); |
270 | rate_avail -= outputbuffer_len (); |
268 | } |
271 | } |
269 | |
272 | |
270 | void |
273 | void |
271 | client::flush_sockets (void) |
274 | client::flush_sockets () |
272 | { |
275 | { |
273 | for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) |
276 | for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) |
274 | (*i)->flush (); |
277 | (*i)->flush (); |
275 | } |
278 | } |
276 | |
279 | |
277 | void |
280 | void |
278 | client::clock (void) |
281 | client::clock () |
279 | { |
282 | { |
280 | for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) |
283 | for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) |
281 | (*i)->tick (); |
284 | (*i)->tick (); |
282 | |
285 | |
283 | // give them all the same chances |
286 | // give them all the same chances |