]> git.pond.sub.org Git - empserver/blobdiff - src/lib/player/login.c
Update known contributors comments
[empserver] / src / lib / player / login.c
index 57fe67ba80b4955768ac6deaed5479d385ee1426..28b5311c09839bbdcdbe82097cdfa196c03bb59d 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-2009, 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-2006
+ *     Markus Armbruster, 2004-2008
+ *     Ron Koenderink, 2005-2009
  */
 
 #include <config.h>
@@ -79,16 +80,21 @@ 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) {
+    while (player->state != PS_SHUTDOWN) {
        io_output(player->iop, IO_WAIT);
        if (io_gets(player->iop, buf, sizeof(buf)) < 0) {
-           io_input(player->iop, IO_WAIT);
+           res = io_input(player->iop, IO_WAIT);
+           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);
@@ -207,7 +213,7 @@ pass_cmd(void)
 {
     if (!player->argp[1])
        return RET_SYN;
-    if (player->cnum == 255) {
+    if (player->cnum == NATID_BAD) {
        pr_id(player, C_CMDERR, "need country first\n");
        return RET_FAIL;
     }
@@ -280,7 +286,7 @@ may_play(void)
 {
     struct natstr *np;
 
-    if (player->cnum == 255 || !player->authenticated) {
+    if (player->cnum == NATID_BAD || !player->authenticated) {
        pr_id(player, C_CMDERR, "need country and password\n");
        return 0;
     }
@@ -307,6 +313,7 @@ play_cmd(void)
     natid cnum;
     struct natstr *natp;
     char **ap;
+    char buf[128];
 
     ap = player->argp;
     if (*++ap) {
@@ -342,6 +349,8 @@ play_cmd(void)
        }
        return RET_FAIL;
     }
+    snprintf(buf, sizeof(buf), "Play#%d", player->cnum);
+    empth_set_name(empth_self(), buf);
     logerror("%s logged in as country #%d", praddr(player), player->cnum);
     pr_id(player, C_INIT, "%d\n", CLIENTPROTO);
     player_main(player);