]> git.pond.sub.org Git - empserver/blobdiff - src/lib/player/login.c
Update copyright notice
[empserver] / src / lib / player / login.c
index aa0033bee9d44e8024e382105112ac2673547b9c..893d1b6c3580bb4fafebf0e929cfc7a6a1742c6d 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2015, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                Ken Stevens, Steve McClure, Markus Armbruster
  *
  *  Empire is free software: you can redistribute it and/or modify
@@ -48,6 +48,7 @@
 #include "player.h"
 #include "proto.h"
 #include "prototypes.h"
+#include "server.h"
 
 static int client_cmd(void);
 static int coun_cmd(void);
@@ -79,9 +80,7 @@ player_login(void *ud)
     time_t deadline;
     char buf[128];
     char space[128];
-    int ac;
-    int cmd;
-    int res;
+    int res, ac, cmd, prev_state;
 
     player->proc = empth_self();
 
@@ -96,11 +95,8 @@ player_login(void *ud)
        }
        if (io_gets(player->iop, buf, sizeof(buf)) < 0) {
            res = io_input(player->iop, deadline);
-           if (res <= 0) {
-               if (res == 0 && !io_eof(player->iop))
-                   pr_id(player, C_DATA, "idle connection terminated\n");
+           if (res <= 0)
                break;
-           }
            continue;
        }
        journal_input(buf);
@@ -126,7 +122,10 @@ player_login(void *ud)
            break;
        }
     }
+    prev_state = player->state;
     player->state = PS_SHUTDOWN;
+    if (prev_state == PS_PLAYING)
+       empth_rwlock_unlock(shutdown_lock);
     pr_id(player, C_EXIT, "so long...\n");
     player_delete(player);
     empth_exit();
@@ -357,11 +356,14 @@ 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);
+    journal_login();
+    empth_set_name(empth_self(), buf);
     pr_id(player, C_INIT, "%d\n", CLIENTPROTO);
+    empth_rwlock_rdlock(shutdown_lock);
     player->state = PS_PLAYING;
     player_main(player);
+    journal_logout();
     logerror("%s logged out, country #%d", praddr(player), player->cnum);
     if (!io_eof(player->iop) && !io_error(player->iop))
        io_set_eof(player->iop);
@@ -381,8 +383,12 @@ kill_cmd(void)
        return RET_FAIL;
     }
     logerror("%s killed country #%d", praddr(player), player->cnum);
-    io_shutdown(other->iop, IO_READ | IO_WRITE);
-    pr_id(player, C_EXIT, "closed socket of offending job\n");
+    pr_flash(other, "Disconnected by %s\n", praddr(player));
+    io_set_eof(other->iop);
+    other->aborted = 1;
+    other->may_sleep = PLAYER_SLEEP_NEVER;
+    empth_wakeup(other->proc);
+    pr_id(player, C_EXIT, "terminated %s's connection\n", praddr(other));
     return RET_OK;
 }