… | |
… | |
86 | client::handle_command () |
86 | client::handle_command () |
87 | { |
87 | { |
88 | bool skipping = false; |
88 | bool skipping = false; |
89 | |
89 | |
90 | while (!cmd_queue.empty () |
90 | while (!cmd_queue.empty () |
91 | && !(pl && pl->state == ST_PLAYING && pl->ob && pl->ob->speed_left < 0)) |
91 | && !(state == ST_PLAYING && pl->ob && pl->ob->speed_left < 0)) |
92 | { |
92 | { |
93 | command &cmd = cmd_queue.front (); |
93 | command &cmd = cmd_queue.front (); |
94 | |
94 | |
95 | if (cmd.stamp + MAX_QUEUE_BACKLOG < now ()) |
95 | if (cmd.stamp + MAX_QUEUE_BACKLOG < now ()) |
96 | { |
96 | { |
… | |
… | |
116 | |
116 | |
117 | void |
117 | void |
118 | flush_sockets (void) |
118 | flush_sockets (void) |
119 | { |
119 | { |
120 | for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) |
120 | for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) |
121 | if (!(*i)->destroyed) |
|
|
122 | (*i)->flush (); |
121 | (*i)->flush (); |
123 | } |
122 | } |
124 | |
123 | |
125 | /** |
124 | /** |
126 | * This checks the sockets for input, does the right thing. |
125 | * This checks the sockets for input, does the right thing. |
127 | * |
126 | * |
… | |
… | |
135 | #ifdef CS_LOGSTATS |
134 | #ifdef CS_LOGSTATS |
136 | if ((time (NULL) - cst_lst.time_start) >= CS_LOGTIME) |
135 | if ((time (NULL) - cst_lst.time_start) >= CS_LOGTIME) |
137 | write_cs_stats (); |
136 | write_cs_stats (); |
138 | #endif |
137 | #endif |
139 | |
138 | |
140 | /* Go through the players. Let the loop set the next pl value, |
139 | //TODO: should not be done here, either |
141 | * since we may remove some |
|
|
142 | */ |
|
|
143 | //TODO: must be handled cleanly elsewhere |
|
|
144 | for (player *pl = first_player; pl; ) |
|
|
145 | { |
|
|
146 | player *npl = pl->next; |
|
|
147 | |
|
|
148 | //TODO: must be handled cleanly elsewhere |
|
|
149 | if (!pl->socket || pl->socket->destroyed) |
|
|
150 | { |
|
|
151 | save_player (pl->ob, 0); |
|
|
152 | |
|
|
153 | if (!QUERY_FLAG (pl->ob, FLAG_REMOVED)) |
|
|
154 | { |
|
|
155 | terminate_all_pets (pl->ob); |
|
|
156 | pl->ob->remove (); |
|
|
157 | } |
|
|
158 | |
|
|
159 | leave (pl, 1); |
|
|
160 | final_free_player (pl); |
|
|
161 | } |
|
|
162 | |
|
|
163 | pl = npl; |
|
|
164 | } |
|
|
165 | |
|
|
166 | for (sockvec::iterator i = clients.begin (); i != clients.end (); ) |
140 | for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) |
167 | { |
141 | { |
168 | client *s = *i; |
142 | client *s = *i; |
169 | |
143 | |
170 | if (s->destroyed) |
|
|
171 | { |
|
|
172 | clients.erase (i); |
|
|
173 | delete s; |
|
|
174 | } |
|
|
175 | else |
|
|
176 | ++i; |
|
|
177 | } |
|
|
178 | |
|
|
179 | /* We need to do some of the processing below regardless */ |
|
|
180 | |
|
|
181 | /* Check for any input on the sockets */ |
|
|
182 | for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) |
|
|
183 | { |
|
|
184 | client *s = *i; |
|
|
185 | player *pl = s->pl; |
144 | if (player *pl = s->pl) |
186 | |
|
|
187 | //TODO: should not be done here, either |
|
|
188 | if (!s->destroyed && pl) |
|
|
189 | { |
145 | { |
190 | /* Update the players stats once per tick. More efficient than |
146 | /* Update the players stats once per tick. More efficient than |
191 | * sending them whenever they change, and probably just as useful |
147 | * sending them whenever they change, and probably just as useful |
192 | */ |
148 | */ |
193 | esrv_update_stats (pl); |
149 | esrv_update_stats (pl); |
… | |
… | |
203 | draw_client_map (pl->ob); |
159 | draw_client_map (pl->ob); |
204 | |
160 | |
205 | if (s->update_look) |
161 | if (s->update_look) |
206 | esrv_draw_look (pl->ob); |
162 | esrv_draw_look (pl->ob); |
207 | } |
163 | } |
|
|
164 | |
|
|
165 | s->refcnt_chk (); |
208 | } |
166 | } |
209 | } |
167 | } |
210 | |
168 | |