]> git.pond.sub.org Git - empserver/commitdiff
Journal login before changing the player thread's name
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 29 Apr 2012 10:36:54 +0000 (12:36 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Tue, 1 May 2012 16:37:49 +0000 (18:37 +0200)
The journal logs a thread name for each event.  The player thread name
changes on entry to the playing phase.  Connecting old and new name
isn't as easy as it should be:

    Sun Apr 29 12:13:39 2012     Conn29 input coun POGO
    Sun Apr 29 12:13:39 2012     Conn29 input pass peter
    Sun Apr 29 12:13:39 2012     Conn29 input play
    Sun Apr 29 12:13:39 2012     Play#0 login 0 127.0.0.1 armbru
    Sun Apr 29 12:15:39 2012     Play#0 logout 0

To connect Conn29 with Play#0, you have to know that country#0 is
named POGO.

Fix that by logging login before the thread name change:

    Sun Apr 29 12:17:41 2012     Conn29 input coun POGO
    Sun Apr 29 12:17:41 2012     Conn29 input pass peter
    Sun Apr 29 12:17:41 2012     Conn29 input play
    Sun Apr 29 12:17:41 2012     Conn29 login 0 127.0.0.1 armbru
    Sun Apr 29 12:19:41 2012     Play#0 logout 0

Now "Conn29 login 0" makes the connection obvious.

This involves moving journal_login() from player_main() before
empth_set_name() in its caller play_cmd().  Move journal_logout() as
well, for symmetry.

If player_main() fails, we now log login/logout instead of nothing in
the journal.  That's okay.  Note that before commit c9f21c0e (v4.3.8),
we logged just login then.

src/lib/player/login.c
src/lib/player/player.c

index 04d7ab9177e6ff79b429a9e766c835986c110014..8b7439f94bc8364f280a5a8bb5fe46c12877d715 100644 (file)
@@ -356,12 +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);
index 98e642edda82565d1db53d795f43f5dca03fa657..00059368523d348e7a9ebfe3a24c7023da12ec0f 100644 (file)
@@ -37,7 +37,6 @@
 #include "empio.h"
 #include "empthread.h"
 #include "file.h"
-#include "journal.h"
 #include "misc.h"
 #include "nat.h"
 #include "optlist.h"
@@ -84,7 +83,6 @@ player_main(struct player *p)
     strcpy(natp->nat_hostaddr, player->hostaddr);
     natp->nat_last_login = player->curup;
     putnat(natp);
-    journal_login();
     if (natp->nat_flags & NF_INFORM && natp->nat_tgms > 0) {
        if (natp->nat_tgms == 1)
            pr("You have a new telegram waiting ...\n");
@@ -107,7 +105,6 @@ player_main(struct player *p)
     update_timeused(natp->nat_last_logout);
     enforce_minimum_session_time();
     pr("Bye-bye\n");
-    journal_logout();
 }
 
 static int