]> git.pond.sub.org Git - empserver/commitdiff
Set timestamp automatically on write
authorMarkus Armbruster <armbru@pond.sub.org>
Wed, 5 Mar 2008 21:43:10 +0000 (22:43 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Fri, 14 Mar 2008 19:25:43 +0000 (20:25 +0100)
Do it in do_write().  Remove the setting of timestamps elsewhere.

This fixes empdump to set timestamps to the current time instead of
zero on import.

man/empdump.6
src/lib/commands/real.c
src/lib/common/file.c
src/lib/subs/land.c
src/lib/subs/lostsub.c
src/lib/subs/natsub.c
src/lib/subs/nuke.c
src/lib/subs/plane.c
src/lib/subs/sect.c
src/lib/subs/ship.c
src/server/lostitem.c

index 3e16c93e71cf185369d59fa32a825982a25f5dae..6861062e4aa07e12555ffa4f7bdd659e69985448 100644 (file)
@@ -50,9 +50,6 @@ state may not result in identical data files; besides the loss of
 floating-point precision just mentioned, coordinates are normalized,
 and characters beyond a string's terminating zero in a character array
 are lost.
-.SH "BUGS"
-Importing resets timestamps to zero.  It should set them to the
-current time.
 .SH "SEE ALSO"
 \fIemp_server\fR(6).
 .SH AUTHOR
index 8aff1b437d8e7f7436a9730f8bf0a7882ad561a5..a5dcb4611347e16bf310302de3e54bebdd1a06cf 100644 (file)
@@ -89,7 +89,6 @@ real(void)
        realm.r_xh = abs.hx - 1;
        realm.r_yl = abs.ly;
        realm.r_yh = abs.hy - 1;
-       realm.r_timestamp = time(NULL);
        putrealm(&realm);
        list_realm(curr, natp);
     }
index f2e4353a22337cef4091cb21dfff88425d5a23f9..96b2df66249267a6985232be77fadd95a88aa45f 100644 (file)
@@ -48,7 +48,7 @@
 
 static int ef_realloc_cache(struct empfile *, int);
 static int fillcache(struct empfile *, int);
-static int do_write(struct empfile *, void *, int, int);
+static int do_write(struct empfile *, void *, int, int, time_t);
 static void do_blank(struct empfile *, void *, int, int);
 
 /*
@@ -230,8 +230,10 @@ ef_flush(int type)
      * allowed only with EFF_MEM.  Assume the whole cash is dirty
      * then.
      */
-    if (ep->flags & EFF_MEM)
-       return do_write(ep, ep->cache, ep->baseid, ep->cids) >= 0;
+    if (ep->flags & EFF_MEM) {
+       if (do_write(ep, ep->cache, ep->baseid, ep->cids, time(NULL)) < 0)
+           return 0;
+    }
 
     return 1;
 }
@@ -337,10 +339,11 @@ fillcache(struct empfile *ep, int start)
 
 /*
  * Write COUNT elements from BUF to EP, starting at ID.
+ * Set the timestamp to NOW if the table has those.
  * Return 0 on success, -1 on error.
  */
 static int
-do_write(struct empfile *ep, void *buf, int id, int count)
+do_write(struct empfile *ep, void *buf, int id, int count, time_t now)
 {
     int i, n, ret;
     char *p;
@@ -361,6 +364,7 @@ do_write(struct empfile *ep, void *buf, int id, int count)
                elt->ef_type = ep->uid;
            if (CANT_HAPPEN(elt->uid != id + i))
                elt->uid = id + i;
+           elt->timestamp = now;
        }
     }
 
@@ -413,7 +417,7 @@ ef_write(int type, int id, void *from)
     if (CANT_HAPPEN((ep->flags & EFF_MEM) ? id >= ep->fids : id > ep->fids))
        return 0;               /* not implemented */
     if (!(ep->flags & EFF_PRIVATE)) {
-       if (do_write(ep, from, id, 1) < 0)
+       if (do_write(ep, from, id, 1, time(NULL)) < 0)
            return 0;
     }
     if (id >= ep->baseid && id < ep->baseid + ep->cids) {
@@ -440,6 +444,7 @@ ef_extend(int type, int count)
     struct empfile *ep;
     char *p;
     int i, id;
+    time_t now = time(NULL);
 
     if (ef_check(type) < 0)
        return 0;
@@ -464,7 +469,7 @@ ef_extend(int type, int count)
        p = ep->cache + id * ep->size;
        do_blank(ep, p, id, count);
        if (ep->fd >= 0 && !(ep->flags & EFF_PRIVATE)) {
-           if (do_write(ep, p, id, count) < 0)
+           if (do_write(ep, p, id, count, now) < 0)
                return 0;
        }
        ep->cids += count;
@@ -475,7 +480,7 @@ ef_extend(int type, int count)
        p = ep->cache + ep->cids * ep->size;
        for (i = 0; i < count; i++) {
            do_blank(ep, p, id + i, 1);
-           if (do_write(ep, p, id + i, 1) < 0)
+           if (do_write(ep, p, id + i, 1, now) < 0)
                return 0;
        }
     }
index ff9f4de9839248d12fca195e554a6cdd5875f630..12f80c28c41d4c4f708a7be3bf5b150e3f814aa2 100644 (file)
@@ -118,11 +118,6 @@ lnd_prewrite(int n, void *ptr)
     struct plnstr *pp;
     int i;
 
-    llp->ef_type = EF_LAND;
-    llp->lnd_uid = n;
-
-    time(&llp->lnd_timestamp);
-
     if (llp->lnd_own && llp->lnd_effic < LAND_MINEFF) {
        makelost(EF_LAND, llp->lnd_own, llp->lnd_uid,
                 llp->lnd_x, llp->lnd_y);
index 07ae55448a06a93aed36239143694db1c2f9fde5..30a10fd02a1ba358305237ad2c925af24fa12847 100644 (file)
@@ -51,7 +51,6 @@ makelost(short type, natid owner, short id, coord x, coord y)
     lost.lost_id = id;
     lost.lost_x = x;
     lost.lost_y = y;
-    time(&lost.lost_timestamp);
     putlost(n, &lost);
 }
 
@@ -66,7 +65,6 @@ makenotlost(short type, natid owner, short id, coord x, coord y)
        return;
     getlost(n, &lost);
     lost.lost_owner = 0;
-    lost.lost_timestamp = 0;
     putlost(n, &lost);
 }
 
index 3d5ef1ca292a47bcf61f8653d6c6053d140e3a99..2249e22b819fc637460ae277e3ae01cd159ae0ca 100644 (file)
@@ -56,7 +56,6 @@ nat_reset(struct natstr *natp, enum nat_status stat, coord x, coord y)
     struct realmstr newrealm;
     struct range absrealm;
     char buf[1024];
-    time_t now = time(NULL);
     int i;
 
     natp->nat_stat = stat;
@@ -76,7 +75,6 @@ nat_reset(struct natstr *natp, enum nat_status stat, coord x, coord y)
        newrealm.r_xh = absrealm.hx;
        newrealm.r_yl = absrealm.ly;
        newrealm.r_yh = absrealm.hy;
-       newrealm.r_timestamp = now;
        putrealm(&newrealm);
     }
     if (players_at_00) {
index ec48b078b45139f038f7a0bbc429fad116d40f26..5226bf5dd1d351064e95931f7ef2ceb194e7d69d 100644 (file)
@@ -88,11 +88,6 @@ nuk_prewrite(int n, void *ptr)
        np->nuk_effic = 0;
     }
 
-    np->ef_type = EF_NUKE;
-    np->nuk_uid = n;
-
-    time(&np->nuk_timestamp);
-
     getnuke(n, &nuke);
 
     return 1;
index 5cf84a3eee9893826ec81da15734b83c24e07faf..aaaaf8453cb8eda9f71b4bd2647f63eabdf35719 100644 (file)
@@ -131,11 +131,6 @@ pln_prewrite(int n, void *ptr)
            }
        }
     }
-    pp->ef_type = EF_PLANE;
-    pp->pln_uid = n;
-
-    time(&pp->pln_timestamp);
-
     getplane(n, &plane);
 
     return 1;
index febaaae1e8df65d484ccdcfa351c92f02070114a..1b90c03c6f0cc6cb1c4475df84656047412d875c 100644 (file)
@@ -68,8 +68,6 @@ sct_prewrite(int id, void *ptr)
     struct sctstr *sp = ptr;
     struct sctstr sect;
 
-    time(&sp->sct_timestamp);
-
     bridge_damaged(sp, NULL);
     checksect(sp);
     getsect(sp->sct_x, sp->sct_y, &sect);
index 860c77e2fc4e3e92e3a71375135f85b98e58cd46..3d0c5bb7d5f6d08695e0038a492e3111245a016d 100644 (file)
@@ -71,11 +71,6 @@ shp_prewrite(int n, void *ptr)
     struct plnstr *pp;
     int i;
 
-    sp->ef_type = EF_SHIP;
-    sp->shp_uid = n;
-
-    time(&sp->shp_timestamp);
-
     if (sp->shp_own != 0 && sp->shp_effic < SHIP_MINEFF) {
        mpr(sp->shp_own, "\t%s sunk!\n", prship(sp));
        makelost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y);
index 837953b647f1935a3496e694c3ad6e93c74c1d70..b3667cc3f77b6eaa85da5cdac17b2c7409fd4819 100644 (file)
@@ -58,7 +58,6 @@ delete_lostitems(void *unused)
            if (lost.lost_timestamp > (now - lost_items_timeout))
                continue;
            lost.lost_owner = 0;
-           lost.lost_timestamp = 0;
            putlost(n, &lost);
            ncnt++;
        }