]> git.pond.sub.org Git - empserver/commitdiff
(add): Initialize nat_last_login and nat_last_logout to zero rather
authorMarkus Armbruster <armbru@pond.sub.org>
Mon, 3 Oct 2005 13:25:54 +0000 (13:25 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Mon, 3 Oct 2005 13:25:54 +0000 (13:25 +0000)
than current time.  Nation addition time is irrelevant.
(natstr): Document zero nat_last_login, nat_last_login mean never
logged in/out.
(player_main): Test nat_last_login zero instead of nat_hostaddr empty.

(player_main): Assign nat_userid, nat_hostname, nat_hostaddr straight
from player.  The last connection's host is now shown as dotted quads
instead of nowhere when the name isn't known.
(natstr): Document that nat_userid, nat_hostname may be empty.

(player_main): Simplify printing last connection address: nat_hostaddr
can't be empty here; don't bother to substitute "nobody" for empty
user.

include/nat.h
src/lib/commands/add.c
src/lib/player/player.c

index cd0aa6ebc8a04d426462164abacddb5c075875c8..7916f9f421faf2f0b7090817cfe9db1b40ce0155 100644 (file)
@@ -65,8 +65,8 @@ struct natstr {
     char nat_cnam[20];         /* country name */
     char nat_pnam[20];         /* representative */
     char nat_hostaddr[32];     /* host addr of last user */
-    char nat_hostname[512];    /* hostname of last user */
-    char nat_userid[32];       /* userid of last user */
+    char nat_hostname[512];    /* hostname of last user, may be empty */
+    char nat_userid[32];       /* userid of last user, may be empty */
     coord nat_xstart, nat_ystart;      /* cap location at start */
     coord nat_xcap, nat_ycap;  /* cap location in abs coords */
     coord nat_xorg, nat_yorg;  /* origin location in abs coords */
@@ -79,8 +79,8 @@ struct natstr {
     short nat_btu;             /* bureaucratic time units */
     long nat_reserve;          /* military reserves */
     long nat_money;            /* moola */
-    time_t nat_last_login;     /* time of last login */
-    time_t nat_last_logout;    /* time of last logout */
+    time_t nat_last_login;     /* time of last login, 0 menas never */
+    time_t nat_last_logout;    /* time of last logout, 0 means never */
     time_t nat_newstim;                /* date news last read */
     time_t nat_annotim;                /* date annos last read */
     float nat_level[4];                /* technology, etc */
index cbdceba67c6070f8d5ab19b8b4d71e74f1a94484..3d9fa859c0c345289dafc1c43ea5b5d50db0f8de 100644 (file)
@@ -214,8 +214,7 @@ add(void)
        natp->nat_dayno = 0;
        natp->nat_minused = 0;
        memset(natp->nat_b, 0, sizeof(natp->nat_b));
-       (void)time(&natp->nat_last_login);
-       (void)time(&natp->nat_last_logout);
+       natp->nat_last_login = natp->nat_last_login = 0;
        natp->nat_money = 0;
        natp->nat_level[NAT_TLEV] = start_technology;
        natp->nat_level[NAT_RLEV] = start_research;
index 9f10d5c8f1174b7b82f101da04e39083848dd4e0..00879d86cfe54d2a4a137d75c14d413006dcae20 100644 (file)
@@ -93,34 +93,21 @@ player_main(struct player *p)
        pr("Time exceeded today\n");
        return;
     }
-    if ((*natp->nat_hostaddr &&
-        *player->hostaddr &&
-        strcmp(natp->nat_hostaddr, player->hostaddr)) ||
-       (*natp->nat_userid &&
-        *player->userid && strcmp(natp->nat_userid, player->userid))) {
-       if (natp->nat_stat != VIS) {
-           pr("Last connection from: %s", ctime(&natp->nat_last_login));
-           pr("                  to: %s", natp->nat_last_login <
-              natp->nat_last_logout ? ctime(&natp->
-                                            nat_last_logout) : "?");
-           pr("                  by: %s@%s\n",
-              *natp->nat_userid ? natp->nat_userid : "nobody",
-              *natp->nat_hostname ? natp->nat_hostname
-              : *natp->nat_hostaddr ? natp->nat_hostaddr : "nowhere");
-       }
+    if (natp->nat_stat != VIS
+       && natp->nat_last_login
+       && (strcmp(natp->nat_hostaddr, player->hostaddr)
+           || strcmp(natp->nat_userid, player->userid))) {
+       pr("Last connection from: %s", ctime(&natp->nat_last_login));
+       pr("                  to: %s",
+          natp->nat_last_login <= natp->nat_last_logout
+          ? ctime(&natp->nat_last_logout) : "?");
+       pr("                  by: %s@%s\n",
+          natp->nat_userid,
+          *natp->nat_hostname ? natp->nat_hostname : natp->nat_hostaddr);
     }
-    if (*player->userid)
-       strcpy(natp->nat_userid, player->userid);
-    else
-       strcpy(natp->nat_userid, "nobody");
-
-    if (*player->hostname)
-       strcpy(natp->nat_hostname, player->hostname);
-    else
-       strcpy(natp->nat_hostname, "nowhere");
-
-    if (*player->hostaddr)
-       strcpy(natp->nat_hostaddr, player->hostaddr);
+    strcpy(natp->nat_userid, player->userid);
+    strcpy(natp->nat_hostname, player->hostname);
+    strcpy(natp->nat_hostaddr, player->hostaddr);
 
     time(&natp->nat_last_login);
     putnat(natp);