Indented with src/scripts/indent-emp.

This commit is contained in:
Markus Armbruster 2003-09-02 20:48:48 +00:00
parent 5f263a7753
commit 9b7adfbecc
437 changed files with 52211 additions and 51052 deletions

View file

@ -41,43 +41,41 @@
/*ARGSUSED*/
void
player_kill_idle(argv)
void *argv;
void *argv;
{
extern int max_idle;
struct player *p;
time_t now;
extern int max_idle;
struct player *p;
time_t now;
time(&now);
while (1) {
empth_sleep(now + 60);
time(&now);
while (1) {
empth_sleep(now + 60);
time(&now);
/*if (update_pending)*/
/*continue;*/
for (p = player_next(0); p != 0; p = player_next(p)) {
if (p->state == PS_SHUTDOWN) {
/* no more mr. nice guy */
p->state = PS_KILL;
p->aborted++;
empth_terminate(p->proc);
p = player_delete(p);
continue;
}
if (p->curup + max_idle * 60 < now) {
p->state = PS_SHUTDOWN;
/* giving control to another thread while
* in the middle of walking player list is
* not a good idea at all. Sasha */
p->aborted++;
pr_flash(p,
"idle connection terminated\n");
empth_wakeup(p->proc);
/* go to sleep because player thread
could vandalize a player list */
break;
}
}
}
/*NOTREACHED*/
}
/*if (update_pending) */
/*continue; */
for (p = player_next(0); p != 0; p = player_next(p)) {
if (p->state == PS_SHUTDOWN) {
/* no more mr. nice guy */
p->state = PS_KILL;
p->aborted++;
empth_terminate(p->proc);
p = player_delete(p);
continue;
}
if (p->curup + max_idle * 60 < now) {
p->state = PS_SHUTDOWN;
/* giving control to another thread while
* in the middle of walking player list is
* not a good idea at all. Sasha */
p->aborted++;
pr_flash(p, "idle connection terminated\n");
empth_wakeup(p->proc);
/* go to sleep because player thread
could vandalize a player list */
break;
}
}
}
/*NOTREACHED*/
}

View file

@ -44,14 +44,14 @@
/*ARGSUSED*/
void
delete_lostitems(argv)
void *argv;
void *argv;
{
extern int lost_items_timeout;
time_t now;
struct loststr lost;
int n;
int ncnt;
time_t now;
struct loststr lost;
int n;
int ncnt;
while (1) {
time(&now);
/* logerror("Deleting lost items at %s", ctime(&now));*/
@ -67,9 +67,8 @@ void *argv;
ncnt++;
}
/* logerror("Deleted %d lost items", ncnt, ctime(&now));*/
now = now + 900; /* Every 15 minutes */
now = now + 900; /* Every 15 minutes */
empth_sleep(now);
}
/*NOTREACHED*/
}

View file

@ -65,12 +65,12 @@
#include "global.h"
#include "prototypes.h"
s_char program[] = "server";
s_char program[] = "server";
extern void player_accept();
extern void player_kill_idle();
extern void update_sched();
extern void delete_lostitems();
extern void player_accept();
extern void player_kill_idle();
extern void update_sched();
extern void delete_lostitems();
void nullify_objects(void);
void init_files(void);
void close_files(void);
@ -90,14 +90,14 @@ static int mainpid = 0;
int
main(argc, argv)
int argc;
char *argv[];
int argc;
char *argv[];
{
time_t now;
int hour[2];
int flags = 0;
int debug = 0;
int op;
time_t now;
int hour[2];
int flags = 0;
int debug = 0;
int op;
char *config_file = NULL;
extern s_char *datadir;
extern char *optarg;
@ -105,54 +105,54 @@ char *argv[];
#ifdef POSIXSIGNALS
struct sigaction act;
#endif /* POSIXSIGNALS */
#if !defined(_WIN32)
mainpid = getpid();
mainpid = getpid();
while ((op = getopt(argc, argv, "D:de:psh")) != EOF) {
switch (op) {
case 'D':
datadir = optarg;
break;
case 'd':
debug++;
break;
case 'e':
config_file = optarg;
break;
case 'p':
flags |= EMPTH_PRINT;
break;
case 's':
flags |= EMPTH_PRINT|EMPTH_STACKCHECK;
break;
case 'h':
default:
printf("Usage: %s -d -p -s\n",argv[0]);
return 0;
}
switch (op) {
case 'D':
datadir = optarg;
break;
case 'd':
debug++;
break;
case 'e':
config_file = optarg;
break;
case 'p':
flags |= EMPTH_PRINT;
break;
case 's':
flags |= EMPTH_PRINT | EMPTH_STACKCHECK;
break;
case 'h':
default:
printf("Usage: %s -d -p -s\n", argv[0]);
return 0;
}
}
#endif
if (config_file == NULL) {
sprintf (tbuf, "%s/econfig", datadir);
config_file = tbuf;
sprintf(tbuf, "%s/econfig", datadir);
config_file = tbuf;
}
logerror("------------------------------------------------------");
#if !defined(_WIN32)
logerror("Empire server (pid %d) started", getpid());
#else
logerror("Empire server started");
#endif /* _WIN32 */
#if defined(_WIN32)
loc_NTInit();
#endif
emp_config (config_file);
emp_config(config_file);
update_policy_check();
nullify_objects();
#if !defined(_WIN32)
/* signal() should not be used with mit pthreads. Anyway if u
have a posix threads u definitly have posix signals -- Sasha */
@ -160,39 +160,39 @@ char *argv[];
#ifdef SA_SIGINFO
act.sa_flags = SA_SIGINFO;
#endif
sigemptyset (&act.sa_mask);
sigemptyset(&act.sa_mask);
if (debug == 0 && flags == 0) {
disassoc();
disassoc();
}
act.sa_handler = shutdwn;
/* pthreads on Linux use SIGUSR1 (*shrug*) so only catch it if not on
a Linux box running POSIX threads -- STM */
/* pthreads on Linux use SIGUSR1 (*shrug*) so only catch it if not on
a Linux box running POSIX threads -- STM */
#if !(defined(__linux__) && defined(_EMPTH_POSIX))
sigaction (SIGUSR1, &act, NULL);
sigaction(SIGUSR1, &act, NULL);
#endif
sigaction (SIGTERM, &act, NULL);
sigaction (SIGINT, &act, NULL);
sigaction(SIGTERM, &act, NULL);
sigaction(SIGINT, &act, NULL);
act.sa_handler = panic;
sigaction (SIGBUS, &act, NULL);
sigaction (SIGSEGV, &act, NULL);
sigaction (SIGILL, &act, NULL);
sigaction (SIGFPE, &act, NULL);
sigaction(SIGBUS, &act, NULL);
sigaction(SIGSEGV, &act, NULL);
sigaction(SIGILL, &act, NULL);
sigaction(SIGFPE, &act, NULL);
act.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &act, NULL);
#else
if (debug == 0 && flags == 0) {
disassoc();
disassoc();
/* pthreads on Linux use SIGUSR1 (*shrug*) so only catch it if not on
a Linux box running POSIX threads -- STM */
#if !(defined(__linux__) && defined(_EMPTH_POSIX))
signal(SIGUSR1, shutdwn);
signal(SIGUSR1, shutdwn);
#endif
signal(SIGTERM, shutdwn);
signal(SIGBUS, panic);
signal(SIGSEGV, panic);
signal(SIGILL, panic);
signal(SIGFPE, panic);
signal(SIGINT, shutdwn);
signal(SIGTERM, shutdwn);
signal(SIGBUS, panic);
signal(SIGSEGV, panic);
signal(SIGILL, panic);
signal(SIGFPE, panic);
signal(SIGINT, shutdwn);
}
signal(SIGPIPE, SIG_IGN);
#endif /* POSIXSIGNALS */
@ -212,47 +212,47 @@ char *argv[];
init_files();
io_init();
gamehours(now, hour);
if (opt_MOB_ACCESS) {
/* This fixes up mobility upon restart */
mobility_init();
}
empth_create(PP_ACCEPT, player_accept, (50*1024), flags, "AcceptPlayers",
"Accept network connections", 0);
empth_create(PP_KILLIDLE, player_kill_idle, (50*1024), flags, "KillIdle",
"Kills idle player connections", 0);
empth_create(PP_SCHED, update_sched, (50*1024), flags, "UpdateSched",
"Schedules updates to occur", 0);
empth_create(PP_TIMESTAMP, delete_lostitems, (50*1024), flags, "DeleteItems",
"Deletes old lost items", 0);
if (opt_MOB_ACCESS) {
/* Start the mobility access check thread */
empth_create(PP_TIMESTAMP, mobility_check, (50*1024), flags, "MobilityCheck",
"Writes the timestamp file", 0);
/* This fixes up mobility upon restart */
mobility_init();
}
empth_create(PP_ACCEPT, player_accept, (50 * 1024), flags,
"AcceptPlayers", "Accept network connections", 0);
empth_create(PP_KILLIDLE, player_kill_idle, (50 * 1024), flags,
"KillIdle", "Kills idle player connections", 0);
empth_create(PP_SCHED, update_sched, (50 * 1024), flags, "UpdateSched",
"Schedules updates to occur", 0);
empth_create(PP_TIMESTAMP, delete_lostitems, (50 * 1024), flags,
"DeleteItems", "Deletes old lost items", 0);
if (opt_MOB_ACCESS) {
/* Start the mobility access check thread */
empth_create(PP_TIMESTAMP, mobility_check, (50 * 1024), flags,
"MobilityCheck", "Writes the timestamp file", 0);
}
if (opt_MARKET) {
empth_create(PP_TIMESTAMP, market_update, (50*1024), flags, "MarketUpdate",
"Updates the market", 0);
empth_create(PP_TIMESTAMP, market_update, (50 * 1024), flags,
"MarketUpdate", "Updates the market", 0);
}
#if defined(__linux__) && defined(_EMPTH_POSIX)
strcpy(tbuf, argv[0]);
for (op = 1; op < argc; op++) {
strcat(tbuf, " ");
strcat(tbuf, argv[op]);
}
sprintf(argv[0], "%s (main pid: %d)", tbuf, getpid());
strcpy(tbuf, argv[0]);
for (op = 1; op < argc; op++) {
strcat(tbuf, " ");
strcat(tbuf, argv[op]);
}
sprintf(argv[0], "%s (main pid: %d)", tbuf, getpid());
#endif
empth_exit();
empth_exit();
/* We should never get here. But, just in case... */
close_files();
#if defined(_WIN32)
loc_NTTerm();
#endif
#endif
return 0;
}
@ -303,14 +303,14 @@ panic(int sig)
#if !defined(_WIN32)
#ifdef POSIXSIGNALS
struct sigaction act;
act.sa_flags = 0;
sigemptyset (&act.sa_mask);
sigemptyset(&act.sa_mask);
act.sa_handler = SIG_DFL;
sigaction (SIGBUS, &act, NULL);
sigaction (SIGSEGV, &act, NULL);
sigaction (SIGILL, &act, NULL);
sigaction (SIGFPE, &act, NULL);
sigaction(SIGBUS, &act, NULL);
sigaction(SIGSEGV, &act, NULL);
sigaction(SIGILL, &act, NULL);
sigaction(SIGFPE, &act, NULL);
#else
signal(SIGBUS, SIG_DFL);
signal(SIGSEGV, SIG_DFL);
@ -328,43 +328,43 @@ emp_sig_t
shutdwn(int sig)
{
struct player *p;
time_t now;
time_t now;
#if defined(__linux__) && defined(_EMPTH_POSIX)
/* This is a hack to get around the way pthreads work on Linux. This
may be useful on other platforms too where threads are turned into
processes. */
if (getpid() != mainpid) {
empth_t *me;
if (getpid() != mainpid) {
empth_t *me;
me = empth_self();
if (me && me->name) {
if (strlen(me->name) > 5) {
/* Player threads are cleaned up below, so just have
them return. This should work. */
if (!strncmp("Player", me->name, 6)) {
return;
}
}
me = empth_self();
if (me && me->name) {
if (strlen(me->name) > 5) {
/* Player threads are cleaned up below, so just have
them return. This should work. */
if (!strncmp("Player", me->name, 6)) {
return;
}
/* Not a player thread - must be server thread, so exit */
empth_exit();
return;
}
}
/* Not a player thread - must be server thread, so exit */
empth_exit();
return;
}
#endif
logerror("Shutdown commencing (cleaning up threads.)");
logerror("Shutdown commencing (cleaning up threads.)");
for (p = player_next(0); p != 0; p = player_next(p)) {
if (p->state != PS_PLAYING)
continue;
pr_flash(p, "Server shutting down...\n");
p->state = PS_SHUTDOWN;
p->aborted++;
if (p->command) {
pr_flash(p, "Shutdown aborting command\n");
}
empth_wakeup(p->proc);
if (p->state != PS_PLAYING)
continue;
pr_flash(p, "Server shutting down...\n");
p->state = PS_SHUTDOWN;
p->aborted++;
if (p->command) {
pr_flash(p, "Shutdown aborting command\n");
}
empth_wakeup(p->proc);
}
if (!sig) {
@ -377,15 +377,15 @@ shutdwn(int sig)
}
for (p = player_next(0); p != 0; p = player_next(p)) {
p->state = PS_KILL;
p->aborted++;
empth_terminate(p->proc);
p = player_delete(p);
p->state = PS_KILL;
p->aborted++;
empth_terminate(p->proc);
p = player_delete(p);
}
if (sig)
logerror("Server shutting down on signal %d", sig);
logerror("Server shutting down on signal %d", sig);
else
logerror("Server shutting down at Deity's request");
logerror("Server shutting down at Deity's request");
close_files();
_exit(0);
}
@ -395,67 +395,67 @@ void
nullify_objects(void)
{
int i, j;
if (opt_BIG_CITY) {
dchr[SCT_CAPIT].d_flg = bigcity_dchr.d_flg;
dchr[SCT_CAPIT].d_pkg = bigcity_dchr.d_pkg;
dchr[SCT_CAPIT].d_build = bigcity_dchr.d_build;
dchr[SCT_CAPIT].d_lcms = bigcity_dchr.d_lcms;
dchr[SCT_CAPIT].d_hcms = bigcity_dchr.d_hcms;
dchr[SCT_CAPIT].d_name = bigcity_dchr.d_name;
dchr[SCT_CAPIT].d_flg = bigcity_dchr.d_flg;
dchr[SCT_CAPIT].d_pkg = bigcity_dchr.d_pkg;
dchr[SCT_CAPIT].d_build = bigcity_dchr.d_build;
dchr[SCT_CAPIT].d_lcms = bigcity_dchr.d_lcms;
dchr[SCT_CAPIT].d_hcms = bigcity_dchr.d_hcms;
dchr[SCT_CAPIT].d_name = bigcity_dchr.d_name;
}
for (i = 0; i < pln_maxno; i++) {
if (opt_NO_HCMS)
plchr[i].pl_hcm = 0;
if (opt_NO_LCMS)
plchr[i].pl_lcm = 0;
if (opt_NO_OIL)
plchr[i].pl_fuel = 0;
if (opt_PLANENAMES)
plchr[i].pl_name = plchr[i].pl_planename;
if (opt_NO_HCMS)
plchr[i].pl_hcm = 0;
if (opt_NO_LCMS)
plchr[i].pl_lcm = 0;
if (opt_NO_OIL)
plchr[i].pl_fuel = 0;
if (opt_PLANENAMES)
plchr[i].pl_name = plchr[i].pl_planename;
}
for (i = 0; i < lnd_maxno; i++) {
if (opt_NO_HCMS)
lchr[i].l_hcm = 0;
if (opt_NO_LCMS)
lchr[i].l_lcm = 0;
/* Fix up the military values */
for (j = 0; j < lchr[i].l_nv; j++) {
if (lchr[i].l_vtype[j] == V_MILIT)
lchr[i].l_mil = lchr[i].l_vamt[j];
}
if (opt_NO_HCMS)
lchr[i].l_hcm = 0;
if (opt_NO_LCMS)
lchr[i].l_lcm = 0;
/* Fix up the military values */
for (j = 0; j < lchr[i].l_nv; j++) {
if (lchr[i].l_vtype[j] == V_MILIT)
lchr[i].l_mil = lchr[i].l_vamt[j];
}
}
for (i = 0; i < shp_maxno; i++) {
if (opt_NO_HCMS)
mchr[i].m_hcm = 0;
if (opt_NO_LCMS)
mchr[i].m_lcm = 0;
if (opt_NO_OIL) {
if (mchr[i].m_flags & M_OIL)
mchr[i].m_name = 0;
}
if (opt_NO_HCMS)
mchr[i].m_hcm = 0;
if (opt_NO_LCMS)
mchr[i].m_lcm = 0;
if (opt_NO_OIL) {
if (mchr[i].m_flags & M_OIL)
mchr[i].m_name = 0;
}
}
for (i = 0; i < nuk_maxno; i++) {
if (opt_NO_HCMS)
nchr[i].n_hcm = 0;
if (opt_NO_LCMS)
nchr[i].n_lcm = 0;
if (opt_NO_HCMS)
nchr[i].n_hcm = 0;
if (opt_NO_LCMS)
nchr[i].n_lcm = 0;
}
for (i = 0; i < sct_maxno; i++) {
if (opt_NO_HCMS)
dchr[i].d_hcms = 0;
if (opt_NO_LCMS)
dchr[i].d_lcms = 0;
if (opt_NO_HCMS)
dchr[i].d_hcms = 0;
if (opt_NO_LCMS)
dchr[i].d_lcms = 0;
}
for (i = 0; i < prd_maxno; i++) {
for (j = 0; j < pchr[i].p_nv; j++) {
if (opt_NO_HCMS && pchr[i].p_vtype[j] == V_HCM)
pchr[i].p_vamt[j] = 0;
if (opt_NO_LCMS && pchr[i].p_vtype[j] == V_LCM)
pchr[i].p_vamt[j] = 0;
if (opt_NO_OIL && pchr[i].p_vtype[j] == V_OIL)
pchr[i].p_vamt[j] = 0;
}
for (j = 0; j < pchr[i].p_nv; j++) {
if (opt_NO_HCMS && pchr[i].p_vtype[j] == V_HCM)
pchr[i].p_vamt[j] = 0;
if (opt_NO_LCMS && pchr[i].p_vtype[j] == V_LCM)
pchr[i].p_vamt[j] = 0;
if (opt_NO_OIL && pchr[i].p_vtype[j] == V_OIL)
pchr[i].p_vamt[j] = 0;
}
}
}
@ -466,12 +466,12 @@ loc_NTInit()
int rc;
WORD wVersionRequested;
WSADATA wsaData;
wVersionRequested = MAKEWORD(2, 0);
rc = WSAStartup(wVersionRequested, &wsaData);
if (rc != 0) {
logerror("WSAStartup failed. %d", rc);
_exit(1);
logerror("WSAStartup failed. %d", rc);
_exit(1);
}
}
#endif
@ -483,4 +483,3 @@ loc_NTTerm()
WSACleanup();
}
#endif

View file

@ -68,20 +68,19 @@ void *argv;
/*ARGSUSED*/
void
market_update(argv)
void *argv;
void *argv;
{
time_t now;
time_t now;
struct player *dp;
while (1) {
time(&now);
/* logerror("Checking the world markets at %s", ctime(&now));*/
dp = player_new(0, 0);
empth_create(PP_UPDATE, check_all_markets, (50*1024), 0,
"MarketCheck", "Checks the world markets", dp);
now = now + 300; /* Every 5 minutes */
empth_create(PP_UPDATE, check_all_markets, (50 * 1024), 0,
"MarketCheck", "Checks the world markets", dp);
now = now + 300; /* Every 5 minutes */
empth_sleep(now);
}
/*NOTREACHED*/
}

View file

@ -46,51 +46,53 @@ int shutdown_pending;
void
shutdown_init(void)
{
shutdown_pending = 0;
shutdown_pending = 0;
}
void
shutdown_sequence(argc, argv)
int argc;
s_char **argv;
int argc;
s_char **argv;
{
struct natstr *god;
struct tm *tm;
time_t now;
s_char header[100];
struct natstr *god;
struct tm *tm;
time_t now;
s_char header[100];
if (shutdown_pending <= 0) {
shutdown_pending = 0;
logerror("shutdown called with 0 shutdown_pending");
empth_exit();
return;
}
god = getnatp(0);
while (shutdown_pending > 0) {
--shutdown_pending;
time(&now);
if (shutdown_pending <= 1440) { /* one day */
tm = localtime(&now);
sprintf(header, "BROADCAST from %s @ %02d:%02d: ",
god->nat_cnam, tm->tm_hour, tm->tm_min);
if (!shutdown_pending) {
pr_wall("%sServer shutting down NOW!\n", header);
shutdwn(0);
} else if (shutdown_pending == 1) {
pr_wall("%sServer shutting down in 1 minute!\n", header);
} else if (shutdown_pending <= 5) {
pr_wall("%sServer shutting down in %d minutes!\n", header, shutdown_pending);
} else if (shutdown_pending <= 60 &&
shutdown_pending%10 == 0) {
pr_wall("%sThe server will be shutting down in %d minutes!\n", header, shutdown_pending);
} else if (shutdown_pending%60 == 0) {
pr_wall("%sThe server will be shutting down %d hours from now.\n", header, (int)(shutdown_pending/60));
}
}
empth_sleep(now + 60);
}
if (shutdown_pending <= 0) {
shutdown_pending = 0;
logerror("shutdown called with 0 shutdown_pending");
empth_exit();
return;
}
god = getnatp(0);
while (shutdown_pending > 0) {
--shutdown_pending;
time(&now);
if (shutdown_pending <= 1440) { /* one day */
tm = localtime(&now);
sprintf(header, "BROADCAST from %s @ %02d:%02d: ",
god->nat_cnam, tm->tm_hour, tm->tm_min);
if (!shutdown_pending) {
pr_wall("%sServer shutting down NOW!\n", header);
shutdwn(0);
} else if (shutdown_pending == 1) {
pr_wall("%sServer shutting down in 1 minute!\n", header);
} else if (shutdown_pending <= 5) {
pr_wall("%sServer shutting down in %d minutes!\n", header,
shutdown_pending);
} else if (shutdown_pending <= 60
&& shutdown_pending % 10 == 0) {
pr_wall
("%sThe server will be shutting down in %d minutes!\n",
header, shutdown_pending);
} else if (shutdown_pending % 60 == 0) {
pr_wall
("%sThe server will be shutting down %d hours from now.\n",
header, (int)(shutdown_pending / 60));
}
}
empth_sleep(now + 60);
}
empth_exit();
}

View file

@ -43,99 +43,99 @@
/*ARGSUSED*/
void
mobility_check(argv)
void *argv;
void *argv;
{
extern s_char *timestampfil;
extern int updating_mob;
struct mob_acc_globals timestamps;
time_t now;
FILE *fp;
int hour[2];
while (1) {
time(&now);
/* logerror("Updating timestamp file at %s", ctime(&now));*/
#if !defined(_WIN32)
if ((fp = fopen(timestampfil, "r+")) == NULL) {
#else
if ((fp = fopen(timestampfil, "r+b")) == NULL) {
#endif
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, hour)) {
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()
{
extern s_char *timestampfil;
extern int updating_mob;
struct mob_acc_globals timestamps;
time_t now;
time_t lastsavedtime;
FILE *fp;
int hour[2];
/* During downtime, we don't want mobility to accrue. So, we look
at the timestamp file, and determine how far forward to push
mobility */
extern s_char *timestampfil;
extern int updating_mob;
struct mob_acc_globals timestamps;
time_t now;
FILE *fp;
int hour[2];
while (1) {
time(&now);
/* logerror("Updating timestamp file at %s", ctime(&now));*/
#if !defined(_WIN32)
if ((fp = fopen(timestampfil, "r+")) == NULL) {
#else
if ((fp = fopen(timestampfil, "r+b")) == NULL) {
#endif
logerror("Unable to edit timestamp file.");
} 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);
logerror("Unable to edit timestamp file.");
continue;
}
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, hour)) {
logerror("Turning on mobility updating.");
updating_mob = 1;
} else {
logerror("Turning off mobility updating.");
rewind(fp);
fread(&timestamps, sizeof(timestamps), 1, fp);
timestamps.timestamp = now;
rewind(fp);
fwrite(&timestamps, sizeof(timestamps), 1, fp);
fclose(fp);
if (!gamehours(now, hour)) {
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()
{
extern s_char *timestampfil;
extern int updating_mob;
struct mob_acc_globals timestamps;
time_t now;
time_t lastsavedtime;
FILE *fp;
int hour[2];
/* 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 !defined(_WIN32)
if ((fp = fopen(timestampfil, "r+")) == NULL) {
#else
if ((fp = fopen(timestampfil, "r+b")) == NULL) {
#endif
logerror("Unable to edit timestamp file.");
} 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, hour)) {
logerror("Turning on mobility updating.");
updating_mob = 1;
} else {
logerror("Turning off mobility updating.");
updating_mob = 0;
}
}

View file

@ -39,114 +39,115 @@
#include "prototypes.h"
#include "optlist.h"
empth_sem_t *update_sem;
empth_sem_t *update_sem;
extern void update_main();
extern void update_wait();
time_t update_time;
extern void update_main();
extern void update_wait();
time_t update_time;
/*ARGSUSED*/
void
update_sched(argv)
void *argv;
void *argv;
{
extern int s_p_etu;
extern int etu_per_update;
extern int adj_update;
extern int update_window;
s_char *kw;
int hour[2];
int wind;
time_t now, delta;
extern int s_p_etu;
extern int etu_per_update;
extern int adj_update;
extern int update_window;
s_char *kw;
int hour[2];
int wind;
time_t now, delta;
update_sem = empth_sem_create("Update", 0);
empth_create(PP_SCHED, update_wait, (50*1024), 0, "UpdateWait",
"Waits until players idle", 0);
update_sem = empth_sem_create("Update", 0);
empth_create(PP_SCHED, update_wait, (50 * 1024), 0, "UpdateWait",
"Waits until players idle", 0);
time(&now);
(void)gamehours(now, hour);
if (NULL != (kw = kw_find("s_p_etu")))
kw_parse(CF_VALUE, kw, &s_p_etu);
if (NULL != (kw = kw_find("etu_per_update")))
kw_parse(CF_VALUE, kw, &etu_per_update);
if (NULL != (kw = kw_find("adj_update")))
kw_parse(CF_VALUE, kw, &adj_update);
if (NULL != (kw = kw_find("update_window")))
kw_parse(CF_VALUE, kw, &update_window);
if (s_p_etu <= 0) {
logerror("bad value for s_p_etu (%d)", s_p_etu);
s_p_etu = 2 * 60;
logerror("setting s_p_etu to %d", s_p_etu);
}
while (1) {
time(&now);
(void) gamehours(now, hour);
if (NULL != (kw = kw_find("s_p_etu")))
kw_parse(CF_VALUE, kw, &s_p_etu);
if (NULL != (kw = kw_find("etu_per_update")))
kw_parse(CF_VALUE, kw, &etu_per_update);
if (NULL != (kw = kw_find("adj_update")))
kw_parse(CF_VALUE, kw, &adj_update);
if (NULL != (kw = kw_find("update_window")))
kw_parse(CF_VALUE, kw, &update_window);
if (s_p_etu <= 0) {
logerror("bad value for s_p_etu (%d)", s_p_etu);
s_p_etu = 2 * 60;
logerror("setting s_p_etu to %d", s_p_etu);
next_update_time(&now, &update_time, &delta);
if (update_window > 0) {
wind = (random() % update_window);
update_time += wind;
delta += wind;
}
while (1) {
time(&now);
next_update_time(&now, &update_time, &delta);
if (update_window > 0) {
wind = (random() % update_window);
update_time += wind;
delta += wind;
}
logerror("Next update at %s", ctime(&update_time));
logerror("Next update in %d seconds", delta);
/* sleep until update is scheduled to go off */
empth_sleep(update_time);
time(&now);
now += adj_update;
if (!gamehours(now, hour)) {
logerror("No update permitted (hours restriction)");
continue;
}
if (!updatetime(&now)) {
logerror("No update wanted");
continue;
}
if (updates_disabled()) {
logerror("Updates disabled...skipping update");
continue;
}
empth_sem_signal(update_sem);
logerror("Next update at %s", ctime(&update_time));
logerror("Next update in %d seconds", delta);
/* sleep until update is scheduled to go off */
empth_sleep(update_time);
time(&now);
now += adj_update;
if (!gamehours(now, hour)) {
logerror("No update permitted (hours restriction)");
continue;
}
/*NOTREACHED*/
if (!updatetime(&now)) {
logerror("No update wanted");
continue;
}
if (updates_disabled()) {
logerror("Updates disabled...skipping update");
continue;
}
empth_sem_signal(update_sem);
}
/*NOTREACHED*/
}
/*ARGSUSED*/
void
update_wait(argv)
void *argv;
void *argv;
{
struct player *p;
int running;
time_t now;
int stacksize;
struct player *dp;
struct player *p;
int running;
time_t now;
int stacksize;
struct player *dp;
while (1) {
empth_sem_wait(update_sem);
running = 0;
for (p = player_next(0); p != 0; p = player_next(p)) {
if (p->state != PS_PLAYING)
continue;
if (p->command) {
pr_flash(p, "Update aborting command\n");
p->aborted = 1;
empth_wakeup(p->proc);
running++;
}
}
time(&now);
if (running) {
/* sleep a few, wait for aborts to take effect */
empth_sleep(now + 2);
}
/*
* we rely on the fact that update's priority is the highest
* in the land so it can finish before it yields.
*/
dp = player_new(0, 0);
stacksize= 100000 +
/* finish_sects */ WORLD_X*WORLD_Y*(2*sizeof(double)+sizeof(s_char *));
empth_create(PP_UPDATE, update_main, stacksize, 0,
"UpdateRun", "Updates the world", dp);
while (1) {
empth_sem_wait(update_sem);
running = 0;
for (p = player_next(0); p != 0; p = player_next(p)) {
if (p->state != PS_PLAYING)
continue;
if (p->command) {
pr_flash(p, "Update aborting command\n");
p->aborted = 1;
empth_wakeup(p->proc);
running++;
}
}
/*NOTREACHED*/
time(&now);
if (running) {
/* sleep a few, wait for aborts to take effect */
empth_sleep(now + 2);
}
/*
* we rely on the fact that update's priority is the highest
* in the land so it can finish before it yields.
*/
dp = player_new(0, 0);
stacksize = 100000 +
/* finish_sects */ WORLD_X * WORLD_Y * (2 * sizeof(double) +
sizeof(s_char *));
empth_create(PP_UPDATE, update_main, stacksize, 0,
"UpdateRun", "Updates the world", dp);
}
/*NOTREACHED*/
}