Use the new Empire clock for implementing MOB_ACCESS:

(lndstr, plnstr, sctstr, shpstr): Change timestamp members lnd_access,
pln_access, sct_access, shp_access from real time (time_t) to ETUs
within a turn (short).
(land_ca, plane_ca, sect_ca, ship_ca): Update accordingly.
(build_ship, build_land, build_bridge, build_plane, build_tower)
(explore, check_trade, bsanct, takeover, takeover_ship)
(takeover_land): Use game_tick_to_now() instead of time() to update
the timestamp.  Change check_trade(), takeover_ship(), takeover_land()
to do that only when MOB_ACCESS is enabled, for consistency.
(lupgr, supgr, pupgr, takeover_ship): Don't touch the timestamp where
mobility isn't touched either.
(sct_do_upd_mob, shp_do_upd_mob, lnd_do_upd_mob, pln_do_upd_mob): Use
game_tick_to_now() instead of increase_mob() to compute ETUs since
the timestamp and update the timestamp.  Closes #1012699.
(increase_mob): Remove.
(mob_sect, mob_ship, mob_land, mob_plane): sct_do_upd_mob() & friends
no longer do the right thing at the update.  Use game_reset_tick() and
pass its result directly to do_mob_sect() & friends.  This is only
correct when argument is etu_per_update, which it always is.  Remove
parameter.  Callers changed.
(do_mob_sect, do_mob_ship, do_mob_land, do_mob_plane): Oops on
negative argument.

(mob_acc_globals, timestampfil, mobupdate, updating_mob)
(update_all_mob, timestamp_fixing, update_timestamps, mobility_check):
The mobupdate command was important to let deities manually
synchronize mobility updating with updates.  That's no longer needed.
The code behind it is somewhat hairy and ugly, and updating it to work
with the Empire clock is just not worth it.  Remove.  Users changed.
(player_coms): Update accordingly.
(upda): Remove display of mobility updating state.

(mobility_init): No need to fix up mobility on startup, as the Empire
clock runs normally even when the server is down.  Remove.  Caller
changed.
This commit is contained in:
Markus Armbruster 2007-07-15 09:43:57 +00:00
parent aa34ef2b7b
commit 4bd19812af
25 changed files with 92 additions and 458 deletions

View file

@ -298,11 +298,6 @@ init_server(void)
init_nreport();
loginit("server");
if (opt_MOB_ACCESS) {
/* This fixes up mobility upon restart */
mobility_init();
}
}
/*
@ -329,10 +324,6 @@ start_server(int flags)
"KillIdle", 0);
empth_create(PP_TIMESTAMP, delete_lostitems, (50 * 1024), flags,
"DeleteItems", 0);
if (opt_MOB_ACCESS) {
empth_create(PP_TIMESTAMP, mobility_check, (50 * 1024), flags,
"MobilityCheck", 0);
}
market_init();
update_init();

View file

@ -1,128 +0,0 @@
/*
* Empire - A multi-player, client/server Internet based war game.
* Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* ---
*
* See files README, COPYING and CREDITS in the root of the source
* tree for related information and legal notices. It is expected
* that future projects/authors will amend these files as needed.
*
* ---
*
* timestamp.c: Timestamp writer/maintainer thread
*
* Known contributors to this file:
* Steve McClure, 1996
* Doug Hay, 1998
*/
#include <config.h>
#include <stdio.h>
#include <time.h>
#include "empthread.h"
#include "misc.h"
#include "optlist.h"
#include "prototypes.h"
#include "server.h"
/*ARGSUSED*/
void
mobility_check(void *unused)
{
struct mob_acc_globals timestamps;
time_t now;
FILE *fp;
while (1) {
time(&now);
/* logerror("Updating timestamp file at %s", ctime(&now));*/
if ((fp = fopen(timestampfil, "rb+")) == NULL) {
logerror("Unable to edit timestamp file.");
continue;
}
rewind(fp);
fread(&timestamps, sizeof(timestamps), 1, fp);
timestamps.timestamp = now;
rewind(fp);
fwrite(&timestamps, sizeof(timestamps), 1, fp);
fclose(fp);
if (!gamehours(now)) {
if (updating_mob == 1) {
update_all_mob();
logerror("Turning off mobility updating (gamehours).");
updating_mob = 0;
}
} else if (updating_mob == 1 && now < timestamps.starttime) {
logerror("Turning off mobility updating at %s", ctime(&now));
update_all_mob();
updating_mob = 0;
} else if (updating_mob == 0 && now >= timestamps.starttime) {
logerror("Turning on mobility updating at %s", ctime(&now));
update_all_mob();
updating_mob = 1;
}
now = now + 180; /* Every 3 minutes */
empth_sleep(now);
}
/*NOTREACHED*/
}
void
mobility_init(void)
{
struct mob_acc_globals timestamps;
time_t now;
time_t lastsavedtime;
FILE *fp;
/* During downtime, we don't want mobility to accrue. So, we look
at the timestamp file, and determine how far forward to push
mobility */
time(&now);
if ((fp = fopen(timestampfil, "rb+")) == NULL) {
logerror("Unable to edit timestamp file.");
/* FIXME safe to continue? */
} else {
rewind(fp);
fread(&timestamps, sizeof(timestamps), 1, fp);
lastsavedtime = timestamps.timestamp;
timestamps.timestamp = now;
rewind(fp);
fwrite(&timestamps, sizeof(timestamps), 1, fp);
fclose(fp);
}
time(&now);
logerror("Adjusting timestamps at %s", ctime(&now));
logerror("(was %s)", ctime(&lastsavedtime));
/* Update the timestamps to this point in time */
update_timestamps(lastsavedtime);
time(&now);
logerror("Done at %s", ctime(&now));
if (now >= timestamps.starttime && gamehours(now)) {
logerror("Turning on mobility updating.");
updating_mob = 1;
} else {
logerror("Turning off mobility updating.");
updating_mob = 0;
}
}