/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2004, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * 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
*
* ---
*
- * See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- * related information and legal notices. It is expected that any future
- * projects/authors will amend these files as needed.
+ * 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.
*
* ---
*
* Known contributors to this file:
* Dave Pare, 1994
* Steve McClure, 1996
+ * Ron Koenderink, 2005
*/
+#include <config.h>
+
+#include <errno.h>
+#ifndef _WIN32
+#include <sys/wait.h>
+#endif
+#include <time.h>
+#include "empthread.h"
#include "misc.h"
+#include "optlist.h"
#include "player.h"
-#include "empthread.h"
#include "prototypes.h"
-#include "optlist.h"
#include "server.h"
empth_sem_t *update_sem;
+time_t update_time;
static void update_wait(void *unused);
-time_t update_time;
+static int run_hook(char *cmd, char *name);
/*ARGSUSED*/
void
/*NOTREACHED*/
}
+void
+update_force(void *seconds)
+{
+ time_t now;
+
+ time(&now);
+ empth_sleep(now + *(int *)seconds);
+ empth_sem_signal(update_sem);
+ empth_exit();
+}
+
/*ARGSUSED*/
static void
update_wait(void *unused)
while (1) {
empth_sem_wait(update_sem);
+ update_pending = 1;
running = 0;
for (p = player_next(0); p != 0; p = player_next(p)) {
if (p->state != PS_PLAYING)
/* sleep a few, wait for aborts to take effect */
empth_sleep(now + 2);
}
+ if (*pre_update_hook) {
+ if (run_hook(pre_update_hook, "pre-update")) {
+ update_pending = 0;
+ continue;
+ }
+ }
/*
* 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);
+ dp = player_new(-1);
if (!dp) {
logerror("can't create dummy player for update");
+ update_pending = 0;
continue;
}
stacksize = 100000 +
/* finish_sects */ WORLD_X * WORLD_Y * (2 * sizeof(double) +
- sizeof(s_char *));
+ sizeof(char *));
empth_create(PP_UPDATE, update_main, stacksize, 0,
"UpdateRun", "Updates the world", dp);
}
/*NOTREACHED*/
}
+
+static int
+run_hook(char *cmd, char *name)
+{
+ int status;
+
+ fflush(NULL);
+
+ status = system(cmd);
+ if (status == 0)
+ ; /* successful exit */
+ else if (status == -1)
+ logerror("couldn't execute command processor for %s hook (%s)",
+ name, strerror(errno));
+#ifndef _WIN32
+ else if (WIFEXITED(status))
+ logerror("%s hook terminated unsuccessfully (exit status %d)",
+ name, WEXITSTATUS(status));
+ else if (WIFSIGNALED(status))
+ logerror("%s hook terminated abnormally (signal %d)",
+ name, WTERMSIG(status));
+#endif
+ else if (status)
+ logerror("%s hook terminated strangely (status %d)",
+ name, status);
+ return status;
+}