]> git.pond.sub.org Git - empserver/blobdiff - src/lib/player/login.c
Fix player_login() not to print null pointer
[empserver] / src / lib / player / login.c
index 2fe4442238e56a0ff4d3af9ecdb4f5a33a119340..7f66a23a0883e5d8d15caf420be4d954c7edc9dd 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2010, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
  *  ---
  *
  *  login.c: Allow the player to login
- * 
+ *
  *  Known contributors to this file:
  *     Dave Pare, 1994
  *     Steve McClure, 2000
- *     Markus Armbruster, 2004-2008
+ *     Markus Armbruster, 2004-2009
+ *     Ron Koenderink, 2005-2009
  */
 
 #include <config.h>
@@ -68,7 +69,7 @@ static struct cmndstr login_coms[] = {
     {"quit", 0, quit_cmd, 0, 0},
     {"sanc", 0, sanc_cmd, 0, 0},
     {"user name", 0, user_cmd, 0, 0},
-    {0, 0, 0, 0, 0}
+    {NULL, 0, NULL, 0, 0}
 };
 
 /*ARGSUSED*/
@@ -79,19 +80,28 @@ player_login(void *ud)
     char space[128];
     int ac;
     int cmd;
+    int res;
 
     player->proc = empth_self();
 
     pr_id(player, C_INIT, "Empire server ready\n");
 
-    while (!io_eof(player->iop) && !io_error(player->iop)
-          && player->state != PS_SHUTDOWN) {
-       io_output(player->iop, IO_WAIT);
+    while (player->state != PS_SHUTDOWN) {
+       io_output(player->iop, 1);
        if (io_gets(player->iop, buf, sizeof(buf)) < 0) {
-           io_input(player->iop, IO_WAIT);
+           res = io_input(player->iop, 1);
+           if (res <= 0) {
+               if (res == 0 && !io_eof(player->iop))
+                   pr_id(player, C_DATA, "idle connection terminated\n");
+               break;
+           }
            continue;
        }
        ac = parse(buf, space, player->argp, NULL, NULL, NULL);
+       if (ac <= 0) {
+           pr_id(player, C_BADCMD, "Can't parse command\n");
+           continue;
+       }
        cmd = comtch(player->argp[0], login_coms, 0);
        if (cmd < 0) {
            pr_id(player, C_BADCMD, "Command %s not found\n", player->argp[0]);
@@ -112,8 +122,7 @@ player_login(void *ud)
     player->state = PS_SHUTDOWN;
     if (!io_eof(player->iop)) {
        pr_id(player, C_EXIT, "so long...\n");
-       io_noblocking(player->iop, 0);
-       while (io_output(player->iop, IO_WAIT) > 0) ;
+       while (io_output(player->iop, 1) > 0) ;
     }
     player_delete(player);
     empth_exit();