1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | * CrossFire, A Multiplayer game for X-windows |
3 | |
3 | * |
|
|
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | Copyright (C) 2002-2003 Mark Wedel & The Crossfire Development Team |
5 | * Copyright (C) 2002-2003 Mark Wedel & The Crossfire Development Team |
5 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | |
7 | * |
7 | This program is free software; you can redistribute it and/or modify |
8 | * This program is free software; you can redistribute it and/or modify |
8 | 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 |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. |
11 | * (at your option) any later version. |
11 | |
12 | * |
12 | 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, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
16 | |
17 | * |
17 | 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 |
18 | along with this program; if not, write to the Free Software |
19 | * along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | |
21 | * |
21 | The author can be reached via e-mail to <crossfire@schmorp.de> |
22 | * The author can be reached via e-mail to <crossfire@schmorp.de> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | /** |
25 | /** |
25 | * \file |
26 | * \file |
26 | * Main client/server loops. |
27 | * Main client/server loops. |
27 | * |
28 | * |
… | |
… | |
46 | #include <arpa/inet.h> |
47 | #include <arpa/inet.h> |
47 | |
48 | |
48 | #include <loader.h> |
49 | #include <loader.h> |
49 | |
50 | |
50 | #define MAX_QUEUE_DEPTH 500 //TODO |
51 | #define MAX_QUEUE_DEPTH 500 //TODO |
51 | #define MAX_QUEUE_BACKLOG 5. //TODO |
52 | #define MAX_QUEUE_BACKLOG 3. //TODO |
52 | |
53 | |
53 | void |
54 | void |
54 | client::reset_state () |
55 | client::reset_state () |
55 | { |
56 | { |
56 | if (!pl) |
57 | if (!pl) |
… | |
… | |
86 | client::handle_command () |
87 | client::handle_command () |
87 | { |
88 | { |
88 | bool skipping = false; |
89 | bool skipping = false; |
89 | |
90 | |
90 | while (!cmd_queue.empty () |
91 | while (!cmd_queue.empty () |
91 | && !(state == ST_PLAYING && pl->ob && pl->ob->speed_left < 0)) |
92 | && !(state == ST_PLAYING && pl->ob && pl->ob->speed_left <= 0)) |
92 | { |
93 | { |
93 | command &cmd = cmd_queue.front (); |
94 | command &cmd = cmd_queue.front (); |
94 | |
95 | |
95 | if (cmd.stamp + MAX_QUEUE_BACKLOG < now ()) |
96 | if (cmd.stamp + MAX_QUEUE_BACKLOG < now ()) |
96 | { |
97 | { |
… | |
… | |
134 | #ifdef CS_LOGSTATS |
135 | #ifdef CS_LOGSTATS |
135 | if ((time (NULL) - cst_lst.time_start) >= CS_LOGTIME) |
136 | if ((time (NULL) - cst_lst.time_start) >= CS_LOGTIME) |
136 | write_cs_stats (); |
137 | write_cs_stats (); |
137 | #endif |
138 | #endif |
138 | |
139 | |
139 | for (sockvec::iterator i = clients.begin (); i != clients.end (); ) |
140 | //TODO: should not be done here, either |
|
|
141 | for (unsigned i = 0; i < clients.size (); ++i) |
140 | { |
142 | { |
141 | client *s = *i; |
143 | client *s = clients [i]; |
142 | |
|
|
143 | if (s->destroyed ()) |
|
|
144 | { |
|
|
145 | clients.erase (i); |
|
|
146 | delete s; |
|
|
147 | } |
|
|
148 | else |
|
|
149 | ++i; |
|
|
150 | } |
|
|
151 | |
|
|
152 | /* We need to do some of the processing below regardless */ |
|
|
153 | |
|
|
154 | /* Check for any input on the sockets */ |
|
|
155 | for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) |
|
|
156 | { |
|
|
157 | client *s = *i; |
|
|
158 | player *pl = s->pl; |
144 | player *pl = s->pl; |
159 | |
145 | |
160 | //TODO: should not be done here, either |
146 | if (pl && pl->ns && !pl->ns->destroyed ()) |
161 | if (!s->destroyed () && pl) |
|
|
162 | { |
147 | { |
|
|
148 | client *ns = pl->ns; |
|
|
149 | |
163 | /* Update the players stats once per tick. More efficient than |
150 | /* Update the players stats once per tick. More efficient than |
164 | * sending them whenever they change, and probably just as useful |
151 | * sending them whenever they change, and probably just as useful |
165 | */ |
152 | */ |
166 | esrv_update_stats (pl); |
153 | esrv_update_stats (pl); |
167 | |
154 | |
168 | if (pl->last_weight != -1 && pl->last_weight != WEIGHT (pl->ob)) |
155 | if (ns->last_weight != -1 && ns->last_weight != WEIGHT (pl->ob)) |
169 | { |
156 | { |
170 | esrv_update_item (UPD_WEIGHT, pl->ob, pl->ob); |
157 | esrv_update_item (UPD_WEIGHT, pl->ob, pl->ob); |
171 | if (pl->last_weight != WEIGHT (pl->ob)) |
158 | if (ns->last_weight != WEIGHT (pl->ob)) |
172 | LOG (llevError, "esrv_update_item(UPD_WEIGHT) did not set player weight: is %lu, should be %lu\n", |
159 | LOG (llevError, "esrv_update_item(UPD_WEIGHT) did not set player weight: is %lu, should be %lu\n", |
173 | (unsigned long) pl->last_weight, WEIGHT (pl->ob)); |
160 | (unsigned long) ns->last_weight, WEIGHT (pl->ob)); |
174 | } |
161 | } |
175 | |
162 | |
176 | draw_client_map (pl->ob); |
163 | draw_client_map (pl->ob); |
177 | |
164 | |
178 | if (s->update_look) |
165 | if (s->update_look) |
179 | esrv_draw_look (pl->ob); |
166 | esrv_draw_look (pl->ob); |
180 | } |
167 | } |
|
|
168 | |
|
|
169 | s->refcnt_chk (); |
181 | } |
170 | } |
182 | } |
171 | } |
183 | |
172 | |