Simplify how typed_wu() counts telegrams
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 20 Nov 2011 19:14:00 +0000 (20:14 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Thu, 29 Dec 2011 10:47:06 +0000 (11:47 +0100)
typed_wu() counts telegrams to update nat_tgms and, since Empire 2,
send C_INFORM messages.  Adjacent telegrams are squashed together if
type and sender are the same, and the timestamp is within TEL_SECONDS.

typed_wu() increments nat_tgms when it sends a telegram that read
doesn't squash into the previous one.

Since Empire 2, it also sends a C_INFORM message then.  Inexplicably,
it fails to use the same condition: it tests just new_tele, not
new_tele || np->nat_tgms == 0.  C_INFORM messages got missed, until
4.0.18 made rea() call clear_telegram_is_new().  Convoluted.

Send C_INFORM exactly when incrementing nat_tgms, and back out
4.0.18's fix.

src/lib/commands/rea.c
src/lib/subs/wu.c

index 288cdecb7a6e85b916d9480995ba9a2e5ad842a4..b0cc7f416b9a22311eb203604cae43772170bb38 100644 (file)
@@ -99,7 +99,6 @@ rea(void)
            may_delete = 0;
        }
        mbox = mailbox(mbox_buf, num);
-       clear_telegram_is_new(player->cnum);
     }
 
     if (!(telfp = fopen(mbox, "rb+"))) {
index 9b4b08fa0f7c02aa733df581af3abd84097f0a82..f79a993f93905c93eb304ca14463a04e12e383dc 100644 (file)
@@ -120,7 +120,6 @@ typed_wu(natid from, natid to, char *message, int type)
     struct iovec iov[2];
     int fd;
     char box[1024];
-    int new_tele = 0;
     struct player *other;
 
     if (type == TEL_ANNOUNCE)
@@ -170,16 +169,17 @@ typed_wu(natid from, natid to, char *message, int type)
            putnat(np);
        }
     } else {
-       new_tele = telegram_is_new(to, &tel);
-       np->nat_tgms += new_tele || np->nat_tgms == 0;
-       putnat(np);
-
-       if (new_tele && np->nat_flags & NF_INFORM) {
-           if (NULL != (other = getplayer(to))) {
-               if (np->nat_tgms == 1)
-                   pr_inform(other, "[new tele]\n");
-               else
-                   pr_inform(other, "[%d new teles]\n", np->nat_tgms);
+       if (!np->nat_tgms || telegram_is_new(to, &tel)) {
+           np->nat_tgms++;
+           putnat(np);
+           if (np->nat_flags & NF_INFORM) {
+               other = getplayer(to);
+               if (other) {
+                   if (np->nat_tgms == 1)
+                       pr_inform(other, "[new tele]\n");
+                   else
+                       pr_inform(other, "[%d new teles]\n", np->nat_tgms);
+               }
            }
        }
     }