Debian Codegraph @

socket/loop.c

raw symbols SCIP
1 /*
2 * Crossfire -- cooperative multi-player graphical RPG and adventure game
3 *
4 * Copyright (c) 1999-2014 Mark Wedel and the Crossfire Development Team
5 * Copyright (c) 1992 Frank Tore Johansen
6 *
7 * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
8 * welcome to redistribute it under certain conditions. For details, please
9 * see COPYING and LICENSE.
10 *
11 * The authors can be reached via e-mail at <[email protected]>.
12 */
13
14 /**
15 * \file
16 * Main client/server loops.
17 *
18 * \date 2003-12-02
19 *
20 * Mainly deals with initialization and higher level socket
21 * maintenance (checking for lost connections and if data has arrived.)
22 * The reading of data is handled in lowlevel.c
23 */
24
25 #include "global.h"
26
27 #include <arpa/inet.h>
28 #include <assert.h>
29 #include <errno.h>
30 #include <fcntl.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <unistd.h>
34
35 #ifndef WIN32 /* ---win32 exclude unix headers */
36 #include <sys/types.h>
37 #include <sys/time.h>
38 #include <netinet/in.h>
39 #include <netdb.h>
40 #endif /* end win32 */
41
42 #include "image.h"
43 #include "newserver.h"
44 #include "sockproto.h"
45 #include "sproto.h"
46
47 /*****************************************************************************
48 * Start of command dispatch area.
49 * The commands here are protocol commands.
50 ****************************************************************************/
51
52 /* Either keep this near the start or end of the file so it is
53 * at least reasonablye easy to find.
54 * There are really 2 commands - those which are sent/received
55 * before player joins, and those happen after the player has joined.
56 * As such, we have function types that might be called, so
57 * we end up having 2 tables.
58 */
59
60 /** Prototype for functions the client sends without player interaction. */
61 typedef void (*func_uint8_int_ns)(char *, int, socket_struct *);
62
63 /** Definition of a function the client sends without player interaction. */
64 struct client_cmd_mapping {
65 const char *cmdname; /**< Command name. */
66 const func_uint8_int_ns cmdproc; /**< Function to call. */
67 };
68
69 /** Prototype for functions used to handle player actions. */
70 typedef void (*func_uint8_int_pl)(char *, int, player *);
71 /** Definition of a function called in reaction to player's action. */
72 struct player_cmd_mapping {
73 const char *cmdname; /**< Command name. */
74 const func_uint8_int_pl cmdproc; /**< Function to call. */
75 const uint8_t flag; /**< If set, the player must be in the ST_PLAYING state for this command to be available. */
76 };
77
78 /**
79 * Dispatch tables for the server.
80 *
81 * CmdMapping is the dispatch table for the server, used in handle_client,
82 * which gets called when the client has input. All commands called here
83 * use the same parameter form (char *data, int len, int clientnum.
84 * We do implicit casts, because the data that is being passed is
85 * unsigned (pretty much needs to be for binary data), however, most
86 * of these treat it only as strings, so it makes things easier
87 * to cast it here instead of a bunch of times in the function itself.
88 * flag is 1 if the player must be in the playing state to issue the
89 * command, 0 if they can issue it at any time.
90 */
91
92 /** Commands sent by the client reacting to player's actions. */
93 static const struct player_cmd_mapping player_commands[] = {
94 { "examine", examine_cmd, 1 },
95 { "apply", apply_cmd, 1 },
96 { "move", move_cmd, 1 },
97 { "reply", reply_cmd, 0 },
98 { "ncom", (func_uint8_int_pl)new_player_cmd, 1 },
99 { "lookat", look_at_cmd, 1 },
100 { "lock", (func_uint8_int_pl)lock_item_cmd, 1 },
101 { "mark", (func_uint8_int_pl)mark_item_cmd, 1 },
102 { "inscribe", inscribe_scroll_cmd, 0 },
103 { NULL, NULL, 0 } /* terminator */
104 };
105
106 /** Commands sent directly by client, when connecting or when needed. */
107 static const struct client_cmd_mapping client_commands[] = {
108 { "addme", add_me_cmd },
109 { "askface", send_face_cmd }, /* Added: phil */
110 { "beat", NULL },
111 { "requestinfo", request_info_cmd },
112 { "setup", set_up_cmd },
113 { "version", version_cmd },
114 { "asksmooth", ask_smooth_cmd }, /*Added: tchize (smoothing technologies)*/
115 { "accountlogin", account_login_cmd },
116 { "accountnew", account_new_cmd },
117 { "accountaddplayer", account_add_player_cmd },
118 { "accountplay", account_play_cmd },
119 { "accountpw", account_password },
120 { "createplayer", create_player_cmd },
121 { NULL, NULL } /* terminator (I, II & III)*/
122 };
123
124 /**
125 * request_info_cmd is sort of a meta command. There is some specific
126 * request of information, but we call other functions to provide
127 * that information.
128 * @param buf buffer containing the information requested.
129 * @param len length of buf, ignored.
130 * @param ns socket to write data to.
131 */
132 void request_info_cmd(char *buf, int len, socket_struct *ns) {
133 char *params = NULL, *cp;
134 /* No match */
135 SockList sl;
136
137 if (len <= 0 || !buf) {
138 LOG(llevDebug, "IP '%s' sent bogus request_info_cmd information\n", ns->host);
139 return;
140 }
141
142 /* Set up replyinfo before we modify any of the buffers - this is used
143 * if we don't find a match.
144 */
145 SockList_Init(&sl);
146 SockList_AddString(&sl, "replyinfo ");
147 SockList_AddString(&sl, buf);
148
149 /* find the first space, make it null, and update the
150 * params pointer.
151 */
152 for (cp = buf; *cp != '\0'; cp++)
153 if (*cp == ' ') {
154 *cp = '\0';
155 params = cp+1;
156 break;
157 }
158 if (!strcmp(buf, "image_info"))
159 send_image_info(ns);
160 else if (!strcmp(buf, "image_sums"))
161 send_image_sums(ns, params);
162 else if (!strcmp(buf, "skill_info"))
163 send_skill_info(ns, params);
164 else if (!strcmp(buf, "spell_paths"))
165 send_spell_paths(ns, params);
166 else if (!strcmp(buf, "exp_table"))
167 send_exp_table(ns, params);
168 else if (!strcmp(buf, "race_list"))
169 send_race_list(ns, params);
170 else if (!strcmp(buf, "race_info"))
171 send_race_info(ns, params);
172 else if (!strcmp(buf, "class_list"))
173 send_class_list(ns, params);
174 else if (!strcmp(buf, "class_info"))
175 send_class_info(ns, params);
176 else if (!strcmp(buf, "rules"))
177 send_file(ns, "rules");
178 else if (!strcmp(buf, "motd"))
179 send_file(ns, "motd");
180 else if (!strcmp(buf, "news"))
181 send_file(ns, "news");
182 else if (!strcmp(buf,"newcharinfo"))
183 send_new_char_info(ns);
184 else if (!strcmp(buf,"startingmap"))
185 send_map_info(ns);
186 else if (!strcmp(buf, "knowledge_info"))
187 knowledge_send_info(ns);
188 else
189 Send_With_Handling(ns, &sl);
190 SockList_Term(&sl);
191 }
192
193 static int
194 handle_cmd(socket_struct *ns, player *pl, char *cmd, char *data, int len) {
195 /* Fuzz testing indicated a way to get a null command here
196 * --> make an empty command, but have a length.
197 * So, if we get here with a null command, log it and exit the function.
198 * Daniel Hawkins 2020-01-16
199 */
200 if (cmd == NULL) {
201 LOG(llevDebug, "%s: missing command. Sending garbage?\n", ns->host);
202 return 0;
203 }
204 for (int i = 0; client_commands[i].cmdname != NULL; i++) {
205 if (strcmp(cmd, client_commands[i].cmdname) == 0) {
206 if (client_commands[i].cmdproc != NULL) {
207 client_commands[i].cmdproc(data, len, ns);
208 }
209 return 0;
210 }
211 }
212 /* Player must be in the playing state or the flag on the
213 * the command must be zero for the user to use the command -
214 * otherwise, a player cam save, be in the play_again state, and
215 * the map they were on getsswapped out, yet things that try to look
216 * at the map causes a crash. If the command is valid, but
217 * one they can't use, we still swallow it up.
218 */
219 if (pl) {
220 for (int i = 0; player_commands[i].cmdname != NULL; i++) {
221 if (strcmp(cmd, player_commands[i].cmdname) == 0) {
222 if (pl->state == ST_PLAYING || player_commands[i].flag == 0) {
223 player_commands[i].cmdproc(data, len, pl);
224 }
225 return 1;
226 }
227 }
228 }
229 LOG(llevDebug, "%s: invalid command '%s'\n", ns->host, cmd);
230 return 0;
231 }
232
233 /**
234 * Handle commands from a client. This function should only be called when
235 * the socket is readable. If an error occurs, the socket status will be set
236 * to Ns_Dead; it is up to the caller to clean it up.
237 *
238 * @param ns Socket sending the command
239 * @param pl Player associated with this socket, or NULL
240 * @return If the main loop should continue processing this client.
241 */
242 bool handle_client(socket_struct *ns, player *pl) {
243 /* Loop through this - maybe we have several complete packets here. */
244 /* Command_count is used to limit the number of requests from
245 * clients that have not logged in - we do not want an unauthenticated
246 * connection to spew us with hundreds of requests. As such,
247 * this counter is only increased in the case of socket level commands.
248 * Note that this also has the effect of throttling down face and other
249 * socket commands from the client. As such, if we have a player attached,
250 * we will process more of these, as getting a fair number when entering
251 * a map may not be uncommon.
252 */
253 int command_count = 0;
254 while (command_count < 5 || (pl && command_count < 25)) {
255 if (pl && pl->state == ST_PLAYING && pl->ob != NULL && pl->ob->speed_left < 0) {
256 // Skip processing players with no turns left.
257 return false;
258 }
259
260 int status = SockList_ReadPacket(ns->fd, &ns->inbuf, sizeof(ns->inbuf.buf)-1);
261 if (status != 1) {
262 if (status < 0) {
263 ns->status = Ns_Dead;
264 }
265 return false;
266 }
267
268 /* Since we have a full packet, reset last tick time. */
269 ns->last_tick = 0;
270
271 SockList_NullTerminate(&ns->inbuf);
272 assert(ns->inbuf.len >= 2);
273 char *data;
274 char *cmd = strtok_r((char *)ns->inbuf.buf + 2, " ", &data);
275
276 int got_player_cmd;
277 if (data != NULL) {
278 int rem = ns->inbuf.len - ((unsigned char *)data - ns->inbuf.buf);
279 got_player_cmd = handle_cmd(ns, pl, cmd, data, rem);
280 } else {
281 got_player_cmd = handle_cmd(ns, pl, cmd, NULL, 0);
282 }
283
284 SockList_ResetRead(&ns->inbuf);
285 if (got_player_cmd) {
286 return true;
287 }
288
289 command_count += 1;
290 /* Evil case, and not a nice workaround, but well...
291 * If we receive eg an accountplay command, the socket is copied
292 * to the player structure, and its faces_sent is set to NULL.
293 * This leads to issues when processing the next commands in the queue,
294 * especially if related to faces...
295 * So get out of here in this case, which we detect because faces_sent is NULL.
296 */
297 if (ns->faces_sent == NULL) {
298 command_count = 6;
299 }
300 }
301 return false;
302 }
303
304 /*****************************************************************************
305 *
306 * Low level socket looping - select calls and watchdog udp packet
307 * sending.
308 *
309 ******************************************************************************/
310
311 #ifdef WATCHDOG
312 /**
313 * Tell watchdog that we are still alive
314 *
315 * I put the function here since we should hopefully already be getting
316 * all the needed include files for socket support
317 */
318 void watchdog(void) {
319 static int fd = -1;
320 static struct sockaddr_in insock;
321
322 if (fd == -1) {
323 struct protoent *protoent;
324
325 if ((protoent = getprotobyname("udp")) == NULL
326 || (fd = socket(PF_INET, SOCK_DGRAM, protoent->p_proto)) == -1) {
327 return;
328 }
329 insock.sin_family = AF_INET;
330 insock.sin_port = htons((unsigned short)13325);
331 insock.sin_addr.s_addr = inet_addr("127.0.0.1");
332 }
333 sendto(fd, (void *)&fd, 1, 0, (struct sockaddr *)&insock, sizeof(insock));
334 }
335 #endif
336
337 extern unsigned long todtick;
338
339 /**
340 * Waits for new connection when there is no one connected.
341 */
342 static void block_until_new_connection(void) {
343 struct timeval Timeout;
344 fd_set readfs;
345 int cycles;
346 int i;
347
348 LOG(llevInfo, "Waiting for connections...\n");
349
350 cycles = 1;
351 do {
352 /* Every minutes is a bit often for updates - especially if nothing is going
353 * on. This slows it down to every 6 minutes.
354 */
355 cycles++;
356 if (cycles%2 == 0)
357 tick_the_clock();
358
359 FD_ZERO(&readfs);
360 for (i = 0; i < socket_info.allocated_sockets && init_sockets[i].listen; i++)
361 if (init_sockets[i].status == Ns_Add)
362 FD_SET((uint32_t)init_sockets[i].fd, &readfs);
363
364 /* If fastclock is set, we need to seriously slow down the updates
365 * to the metaserver as well as watchdog. Do same for flush_old_maps() -
366 * that is time sensitive, so there is no good reason to call it 2000 times
367 * a second.
368 */
369 if (settings.fastclock > 0) {
370 #ifdef WATCHDOG
371 if (cycles%120000 == 0) {
372 watchdog();
373 flush_old_maps();
374 }
375 #endif
376 if (cycles == 720000) {
377 metaserver_update();
378 cycles = 1;
379 }
380 Timeout.tv_sec = 0;
381 Timeout.tv_usec = 50;
382 } else {
383 Timeout.tv_sec = 60;
384 Timeout.tv_usec = 0;
385 if (cycles == 7) {
386 metaserver_update();
387 cycles = 1;
388 }
389 flush_old_maps();
390 }
391 } while (select(socket_info.max_filedescriptor, &readfs, NULL, NULL, &Timeout) == 0);
392
393 reset_sleep(); /* Or the game would go too fast */
394 }
395
396 /**
397 * Checks if file descriptor is valid.
398 *
399 * @param fd
400 * file descriptor to check.
401 * @return
402 * 1 if fd is valid, 0 else.
403 */
404 static int is_fd_valid(int fd) {
405 #ifndef WIN32
406 return fcntl(fd, F_GETFL) != -1 || errno != EBADF;
407 #else
408 return 1;
409 #endif
410 }
411
412 /**
413 * Handle a new connection from a client.
414 * @param listen_fd file descriptor the request came from.
415 */
416 static void new_connection(int listen_fd) {
417 int newsocknum = -1, j;
418 #ifdef HAVE_GETNAMEINFO
419 struct sockaddr_storage addr;
420 #else
421 struct sockaddr_in addr;
422 #endif
423 socklen_t addrlen = sizeof(addr);
424
425 #ifdef ESRV_DEBUG
426 LOG(llevDebug, "do_server: New Connection\n");
427 #endif
428
429 for (j = 0; j < socket_info.allocated_sockets; j++)
430 if (init_sockets[j].status == Ns_Avail) {
431 newsocknum = j;
432 break;
433 }
434
435 if (newsocknum == -1) {
436 /* If this is the case, all sockets currently in used */
437 init_sockets = realloc(init_sockets, sizeof(socket_struct)*(socket_info.allocated_sockets+1));
438 if (!init_sockets)
439 fatal(OUT_OF_MEMORY);
440 newsocknum = socket_info.allocated_sockets;
441 socket_info.allocated_sockets++;
442 init_sockets[newsocknum].listen = NULL;
443 init_sockets[newsocknum].faces_sent_len = get_faces_count();
444 init_sockets[newsocknum].faces_sent = calloc(get_faces_count(), sizeof(*init_sockets[newsocknum].faces_sent));
445 if (!init_sockets[newsocknum].faces_sent)
446 fatal(OUT_OF_MEMORY);
447 init_sockets[newsocknum].status = Ns_Avail;
448 }
449
450 if (newsocknum < 0) {
451 LOG(llevError, "FATAL: didn't allocate a newsocket?? alloc = %d, newsocknum = %d", socket_info.allocated_sockets, newsocknum);
452 fatal(SEE_LAST_ERROR);
453 }
454
455 init_sockets[newsocknum].fd = accept(listen_fd, (struct sockaddr *)&addr, &addrlen);
456 if (init_sockets[newsocknum].fd == -1) {
457 LOG(llevError, "accept failed: %s\n", strerror(errno));
458 } else {
459 char buf[MAX_BUF];
460 #ifndef HAVE_GETNAMEINFO
461 long ip;
462 #endif
463 socket_struct *ns;
464
465 ns = &init_sockets[newsocknum];
466
467 #ifdef HAVE_GETNAMEINFO
468 getnameinfo((struct sockaddr *) &addr, addrlen, buf, sizeof(buf), NULL, 0, NI_NUMERICHOST);
469 #else
470 ip = ntohl(addr.sin_addr.s_addr);
471 snprintf(buf, sizeof(buf), "%ld.%ld.%ld.%ld", (ip>>24)&255, (ip>>16)&255, (ip>>8)&255, ip&255);
472 #endif
473
474 if (checkbanned(NULL, buf)) {
475 LOG(llevInfo, "Banned host tried to connect: [%s]\n", buf);
476 close(init_sockets[newsocknum].fd);
477 init_sockets[newsocknum].fd = -1;
478 } else {
479 init_connection(ns, buf);
480 }
481 }
482 }
483
484 /**
485 * Check whether the given socket's connection is alive or not.
486 *
487 * @return True if connection is active, false if not.
488 */
489 bool connection_alive(socket_struct socket) {
490 // If the client doesn't send heartbeats, assume it's connected.
491 if (!socket.heartbeat) {
492 return true;
493 }
494
495 // If a client message was received recently, it's connected.
496 if (socket.last_tick < tick_length(BEAT_INTERVAL + 1)) {
497 return true;
498 }
499
500 return false;
501 }
502
503 /**
504 * Send updated stats, map, look, and inventory to the player.
505 */
506 static void send_updates(player *pl) {
507 /* Update the players stats once per tick. More efficient than
508 * sending them whenever they change, and probably just as useful
509 */
510 esrv_update_stats(pl);
511 if (pl->last_weight != -1 && pl->last_weight != WEIGHT(pl->ob)) {
512 esrv_update_item(UPD_WEIGHT, pl->ob, pl->ob);
513 if (pl->last_weight != WEIGHT(pl->ob))
514 LOG(llevError, "esrv_update_item(UPD_WEIGHT) did not set player weight: is %lu, should be %lu\n", (unsigned long)pl->last_weight, (unsigned long)WEIGHT(pl->ob));
515 }
516 /* draw_client_map does sanity checking that map is
517 * valid, so don't do it here.
518 */
519 draw_client_map(pl->ob);
520 if (pl->socket.update_look)
521 esrv_draw_look(pl->ob);
522 if (pl->socket.update_inventory) {
523 if (pl->ob->container != NULL)
524 esrv_send_inventory(pl->ob, pl->ob->container);
525 pl->socket.update_inventory = 0;
526 }
527 }
528
529 /**
530 * This checks the sockets for input and exceptions, does the right thing.
531 *
532 * A bit of this code is grabbed out of socket.c
533 * There are 2 lists we need to look through - init_sockets is a list
534 *
535 */
536 void do_server(void) {
537 fd_set tmp_read, tmp_exceptions;
538 int active = 0;
539 FD_ZERO(&tmp_read);
540 FD_ZERO(&tmp_exceptions);
541
542 for (int i = 0; i < socket_info.allocated_sockets; i++) {
543 if (init_sockets[i].status == Ns_Add && !is_fd_valid(init_sockets[i].fd)) {
544 LOG(llevError, "do_server: invalid waiting fd %d\n", i);
545 init_sockets[i].status = Ns_Dead;
546 }
547 if (init_sockets[i].status == Ns_Dead) {
548 LOG(llevInfo, "Disconnected from %s\n", init_sockets[i].host);
549 if (init_sockets[i].listen) {
550 /* try to reopen the listening socket */
551 init_listening_socket(&init_sockets[i]);
552 } else {
553 free_newsocket(&init_sockets[i]);
554 init_sockets[i].status = Ns_Avail;
555 }
556 } else if (init_sockets[i].status != Ns_Avail) {
557 FD_SET((uint32_t)init_sockets[i].fd, &tmp_read);
558 FD_SET((uint32_t)init_sockets[i].fd, &tmp_exceptions);
559 active++;
560 }
561 }
562
563 /* Go through the players. Let the loop set the next pl value,
564 * since we may remove some
565 */
566 player *pl, *next;
567 for (pl = first_player; pl != NULL; ) {
568 if (pl->socket.status != Ns_Dead && !is_fd_valid(pl->socket.fd)) {
569 LOG(llevError, "do_server: invalid file descriptor for player %s [%s]: %d\n", (pl->ob && pl->ob->name) ? pl->ob->name : "(unnamed player?)", (pl->socket.host) ? pl->socket.host : "(unknown ip?)", pl->socket.fd);
570 pl->socket.status = Ns_Dead;
571 }
572
573 if (pl->socket.status == Ns_Dead) {
574 player *npl = pl->next;
575
576 save_player(pl->ob, 0);
577 leave(pl, 1);
578 final_free_player(pl);
579 pl = npl;
580 } else {
581 FD_SET((uint32_t)pl->socket.fd, &tmp_read);
582 FD_SET((uint32_t)pl->socket.fd, &tmp_exceptions);
583 pl = pl->next;
584 }
585 }
586
587 if (active == 1 && first_player == NULL)
588 block_until_new_connection();
589
590 long sleep_time = get_sleep_remaining();
591 if (sleep_time < 0) {
592 LOG(llevInfo, "skipping time (over by %ld ms)\n", -sleep_time/1000);
593 jump_time();
594 }
595
596 while (sleep_time > 0) {
597 socket_info.timeout.tv_sec = 0;
598 socket_info.timeout.tv_usec = sleep_time;
599 int pollret = select(socket_info.max_filedescriptor, &tmp_read, NULL,
600 &tmp_exceptions, &socket_info.timeout);
601 if (pollret == -1) {
602 if (errno != EINTR) {
603 LOG(llevError, "select failed: %s\n", strerror(errno));
604 }
605 return;
606 } else if (!pollret) {
607 return;
608 }
609
610 /* Check for any exceptions/input on the sockets */
611 for (int i = 0; i < socket_info.allocated_sockets; i++) {
612 /* listen sockets can stay in status Ns_Dead */
613 if (init_sockets[i].status != Ns_Add) {
614 continue;
615 }
616 if (FD_ISSET(init_sockets[i].fd, &tmp_exceptions)) {
617 free_newsocket(&init_sockets[i]);
618 init_sockets[i].status = Ns_Avail;
619 continue;
620 }
621 if (FD_ISSET(init_sockets[i].fd, &tmp_read)) {
622 if (init_sockets[i].listen)
623 new_connection(init_sockets[i].fd);
624 else
625 handle_client(&init_sockets[i], NULL);
626 }
627 }
628
629 /* This does roughly the same thing, but for the players now */
630 for (pl = first_player; pl != NULL; pl = next) {
631 next = pl->next;
632 if (pl->socket.status == Ns_Dead)
633 continue;
634
635 if (FD_ISSET(pl->socket.fd, &tmp_exceptions)) {
636 save_player(pl->ob, 0);
637 leave(pl, 1);
638 final_free_player(pl);
639 } else {
640 bool keep_processing = handle_client(&pl->socket, pl);
641 if (!keep_processing) {
642 FD_CLR(pl->socket.fd, &tmp_read);
643 }
644
645 /* There seems to be rare cases where next points to a removed/freed player.
646 * My belief is that this player does something (shout, move, whatever)
647 * that causes data to be sent to the next player on the list, but
648 * that player is defunct, so the socket codes removes that player.
649 * End result is that next now points at the removed player, and
650 * that has garbage data so we crash. So update the next pointer
651 * while pl is still valid. MSW 2007-04-21
652 */
653 next = pl->next;
654
655
656 /* If the player has left the game, then the socket status
657 * will be set to this be the leave function. We don't
658 * need to call leave again, as it has already been called
659 * once.
660 */
661 if (pl->socket.status == Ns_Dead) {
662 save_player(pl->ob, 0);
663 leave(pl, 1);
664 final_free_player(pl);
665 } else {
666 send_updates(pl);
667 }
668 }
669 }
670 sleep_time = get_sleep_remaining();
671 }
672 }
673
674 /**
675 * Send updates to players. Called once per tick.
676 */
677 void update_players() {
678 player *pl, *next;
679 for (pl = first_player; pl != NULL; pl = next) {
680 next = pl->next;
681 send_updates(pl);
682 /* Increment time since last contact only if logged in. */
683 if (pl->state == ST_PLAYING) {
684 pl->socket.last_tick++;
685
686 if (!connection_alive(pl->socket)) {
687 // TODO: Handle a lost client connection.
688 LOG(llevDebug, "Lost client connection!\n");
689 }
690
691 if (pl->socket.tick)
692 send_tick(pl);
693 }
694 }
695 }