Import of Empire 4.2.12

This commit is contained in:
Markus Armbruster 2003-08-23 12:23:04 +00:00
commit d8b7fdfae1
817 changed files with 126589 additions and 0 deletions

118
src/server/Makefile Normal file
View file

@ -0,0 +1,118 @@
#
# Empire - A multi-player, client/server Internet based war game.
# Copyright (C) 1986-2000, 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 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.
#
# Makefile - Wolfpack, 1996
# Note that these could have been listed 1 per line, but I chose to just
# stick them all together this way to shorten the file.
include ../../build.conf
include ../make.src
include ../make.defs
OBJS = main.o idle.o lostitem.o marketup.o shutdown.o timestamp.o update.o
NTOBJS = main.obj idle.obj lostitem.obj marketup.obj shutdown.obj \
timestamp.obj update.obj
LIBDIR = $(SRCDIR)/lib
LIBS = $(LIBDIR)/libplayer.a \
$(LIBDIR)/libupdate.a \
$(LIBDIR)/libcommands.a \
$(LIBDIR)/libsubs.a \
$(LIBDIR)/libcommon.a \
$(LIBDIR)/libgen.a \
$(LIBDIR)/libglobal.a \
$(LIBDIR)/libas.a \
$(LIBDIR)/libempth.a \
$(LIBDIR)/liblwp.a
OSXLIBS = $(LIBDIR)/libplayer.a \
$(LIBDIR)/libupdate.a \
$(LIBDIR)/libcommands.a \
$(LIBDIR)/libsubs.a \
$(LIBDIR)/libcommon.a \
$(LIBDIR)/libgen.a \
$(LIBDIR)/libglobal.a \
$(LIBDIR)/libas.a \
$(LIBDIR)/libempth.a
NTLIBS = $(LIBDIR)\libplayer.lib \
$(LIBDIR)\libupdate.lib \
$(LIBDIR)\libcommands.lib \
$(LIBDIR)\libsubs.lib \
$(LIBDIR)\libcommon.lib \
$(LIBDIR)\libgen.lib \
$(LIBDIR)\libglobal.lib \
$(LIBDIR)\libas.lib \
$(LIBDIR)\libempth.lib
all: emp_server
osx: empX_server
nt: emp_server.exe
emp_server.exe: $(NTOBJS) $(NTLIBS)
link /OUT:emp_server.exe \
/PDB:emp_server.pdb /NOLOGO \
/NOD /DEBUG:full /DEBUGTYPE:cv /MACHINE:IX86 /NOLOGO \
$(NTOBJS) $(NTLIBS) \
kernel32.lib \
wsock32.lib \
libcmt.lib \
oldnames.lib
emp_server: $(OBJS) $(LIBS)
$(CC) -o emp_server $(OBJS) $(LIBS) $(LFLAGS) $(GLOBALPFLAGS) -lm -lc
empX_server: $(OBJS) $(OSXLIBS)
$(CC) -o emp_server $(OBJS) $(OSXLIBS) $(LFLAGS) $(GLOBALPFLAGS) -lm -lc
clean:
-(del /q $(NTOBJS))
-(del /q emp_server.exe)
-(del /q emp_server.ilk)
-(del /q emp_server.pdb)
-(rm -f $(OBJS))
-(rm -f emp_server)
-(rm -f $(OSXOBJS))
-(rm -f empX_server)
install:
-(mkdir $(EMPDIR)/bin)
-(cp emp_server $(EMPDIR)/bin)
OSXinstall:
-(mkdir $(EMPDIR)/bin)
-(cp empX_server $(EMPDIR)/bin)
ntinstall:
-(mkdir $(NTINSTDIR)\bin)
-(copy emp_server.exe $(NTINSTDIR)\bin)
include ../make.rules
include Makedepend

83
src/server/idle.c Normal file
View file

@ -0,0 +1,83 @@
/*
* Empire - A multi-player, client/server Internet based war game.
* Copyright (C) 1986-2000, 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 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.
*
* ---
*
* idle.c: Stamps out idle players. Runs at low priority
*
* Known contributors to this file:
* Dave Pare, 1994
*/
#include "misc.h"
#include "player.h"
#include "empio.h"
#include "empthread.h"
#include "proto.h"
#include "prototypes.h"
/*ARGSUSED*/
void
player_kill_idle(argv)
void *argv;
{
extern int max_idle;
struct player *p;
time_t now;
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*/
}

75
src/server/lostitem.c Normal file
View file

@ -0,0 +1,75 @@
/*
* Empire - A multi-player, client/server Internet based war game.
* Copyright (C) 1986-2000, 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 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.
*
* ---
*
* lostitem.c: This deletes the old lost items
*
* Known contributors to this file:
* Steve McClure, 1997
*/
#include "options.h"
#include "misc.h"
#include "player.h"
#include "keyword.h"
#include "empthread.h"
#include "file.h"
#include "lost.h"
#include <stdio.h>
#include "prototypes.h"
/*ARGSUSED*/
void
delete_lostitems(argv)
void *argv;
{
extern int lost_items_timeout;
time_t now;
struct loststr lost;
int n;
int ncnt;
while (1) {
time(&now);
/* logerror("Deleting lost items at %s", ctime(&now));*/
ncnt = 0;
for (n = 0; getlost(n, &lost); n++) {
if (!lost.lost_owner)
continue;
if (lost.lost_timestamp > (now - lost_items_timeout))
continue;
lost.lost_owner = 0;
lost.lost_timestamp = 0;
putlost(n, &lost);
ncnt++;
}
/* logerror("Deleted %d lost items", ncnt, ctime(&now));*/
now = now + 900; /* Every 15 minutes */
empth_sleep(now);
}
/*NOTREACHED*/
}

486
src/server/main.c Normal file
View file

@ -0,0 +1,486 @@
/*
* Empire - A multi-player, client/server Internet based war game.
* Copyright (C) 1986-2000, 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 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.
*
* ---
*
* main.c: Thread and signal initialization for Empire Server
*
* Known contributors to this file:
* Dave Pare, 1994
* Steve McClure, 1996, 1998
* Doug Hay, 1998
*/
#if defined(aix) || defined(linux)
#include <unistd.h>
#endif /* aix or linux */
#include <signal.h>
#include <errno.h>
#if !defined(_WIN32)
#include <sys/ioctl.h>
#endif
#include <fcntl.h>
#include <stdio.h>
#if defined(_WIN32)
#include <winsock.h>
#endif
#include "misc.h"
#include "nat.h"
#include "file.h"
#include "player.h"
#include "empthread.h"
#include "plane.h"
#include "nuke.h"
#include "land.h"
#include "ship.h"
#include "sect.h"
#include "var.h"
#include "product.h"
#include "optlist.h"
#include "global.h"
#include "prototypes.h"
s_char program[] = "server";
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);
#if defined(_WIN32)
static void loc_NTInit(void);
static void loc_NTTerm(void);
#endif
extern void mobility_init();
extern void mobility_check();
extern void market_update();
#if !defined(_WIN32)
static int mainpid = 0;
#endif
int
main(argc, argv)
int argc;
char *argv[];
{
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;
s_char tbuf[256];
#ifdef POSIXSIGNALS
struct sigaction act;
#endif /* POSIXSIGNALS */
#if !defined(_WIN32)
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;
}
}
#endif
if (config_file == NULL) {
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);
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 */
#if defined (POSIXSIGNALS) || defined (_EMPTH_POSIX)
#ifdef SA_SIGINFO
act.sa_flags = SA_SIGINFO;
#endif
sigemptyset (&act.sa_mask);
if (debug == 0 && flags == 0) {
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 */
#if !(defined(__linux__) && defined(_EMPTH_POSIX))
sigaction (SIGUSR1, &act, NULL);
#endif
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);
act.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &act, NULL);
#else
if (debug == 0 && flags == 0) {
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);
#endif
signal(SIGTERM, shutdwn);
signal(SIGBUS, panic);
signal(SIGSEGV, panic);
signal(SIGILL, panic);
signal(SIGFPE, panic);
signal(SIGINT, shutdwn);
}
signal(SIGPIPE, SIG_IGN);
#endif /* POSIXSIGNALS */
#endif /* _WIN32 */
empth_init((char **)&player, flags);
time(&now);
#if !defined(_WIN32)
srandom(now);
#else
srand(now);
#endif /* _WIN32 */
setfdtablesize(32, 256);
global_init();
shutdown_init();
player_init();
ef_init();
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);
}
if (opt_MARKET) {
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());
#endif
empth_exit();
/* We should never get here. But, just in case... */
close_files();
#if defined(_WIN32)
loc_NTTerm();
#endif
return 0;
}
void
init_files(void)
{
ef_open(EF_NATION, O_RDWR, EFF_MEM);
ef_open(EF_SECTOR, O_RDWR, EFF_MEM);
ef_open(EF_SHIP, O_RDWR, EFF_MEM);
ef_open(EF_PLANE, O_RDWR, EFF_MEM);
ef_open(EF_LAND, O_RDWR, EFF_MEM);
ef_open(EF_NEWS, O_RDWR, 0);
ef_open(EF_LOAN, O_RDWR, 0);
ef_open(EF_TREATY, O_RDWR, 0);
ef_open(EF_NUKE, O_RDWR, EFF_MEM);
ef_open(EF_POWER, O_RDWR, 0);
ef_open(EF_TRADE, O_RDWR, 0);
ef_open(EF_MAP, O_RDWR, EFF_MEM);
ef_open(EF_BMAP, O_RDWR, EFF_MEM);
ef_open(EF_COMM, O_RDWR, 0);
ef_open(EF_LOST, O_RDWR, 0);
}
void
close_files(void)
{
ef_close(EF_NATION);
ef_close(EF_SECTOR);
ef_close(EF_SHIP);
ef_close(EF_PLANE);
ef_close(EF_LAND);
ef_close(EF_NEWS);
ef_close(EF_LOAN);
ef_close(EF_TREATY);
ef_close(EF_NUKE);
ef_close(EF_POWER);
ef_close(EF_TRADE);
ef_close(EF_MAP);
ef_close(EF_COMM);
ef_close(EF_BMAP);
ef_close(EF_LOST);
}
/* we're going down. try to close the files at least */
emp_sig_t
panic(int sig)
{
#if !defined(_WIN32)
#ifdef POSIXSIGNALS
struct sigaction act;
act.sa_flags = 0;
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);
#else
signal(SIGBUS, SIG_DFL);
signal(SIGSEGV, SIG_DFL);
signal(SIGILL, SIG_DFL);
signal(SIGFPE, SIG_DFL);
#endif /* POSIXSIGNALS */
#endif /* _WIN32 */
logerror("server received fatal signal %d", sig);
log_last_commands();
close_files();
_exit(0);
}
emp_sig_t
shutdwn(int sig)
{
struct player *p;
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;
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;
}
#endif
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 (!sig) {
/* Sleep and let some cleanup happen - note this doesn't work
when called from a signal handler, since we may or may not
be in the right thread. So we just pass by and kill 'em
all. */
time(&now);
empth_sleep(now + 1);
}
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);
}
if (sig)
logerror("Server shutting down on signal %d", sig);
else
logerror("Server shutting down at Deity's request");
close_files();
_exit(0);
}
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;
}
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;
}
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];
}
}
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;
}
}
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;
}
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;
}
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;
}
}
}
#if defined(_WIN32)
static void
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);
}
}
#endif
#if defined(_WIN32)
static void
loc_NTTerm()
{
WSACleanup();
}
#endif

87
src/server/marketup.c Normal file
View file

@ -0,0 +1,87 @@
/*
* Empire - A multi-player, client/server Internet based war game.
* Copyright (C) 1986-2000, 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 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.
*
* ---
*
* marketup.c: Market updater thread
*
* Known contributors to this file:
* Steve McClure, 1996
*/
#include "options.h"
#include "misc.h"
#include "player.h"
#include "keyword.h"
#include "empthread.h"
#include "file.h"
#include <stdio.h>
#include "prototypes.h"
/*ARGSUSED*/
void
check_all_markets(argv)
void *argv;
{
player->proc = empth_self();
player->cnum = 0;
player->god = 1;
check_market();
check_trade();
ef_flush(EF_NATION);
ef_flush(EF_SECTOR);
ef_flush(EF_PLANE);
ef_flush(EF_SHIP);
ef_flush(EF_LAND);
ef_flush(EF_COMM);
ef_flush(EF_TRADE);
player_delete(player);
empth_exit();
/*NOTREACHED*/
}
/*ARGSUSED*/
void
market_update(argv)
void *argv;
{
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_sleep(now);
}
/*NOTREACHED*/
}

96
src/server/shutdown.c Normal file
View file

@ -0,0 +1,96 @@
/*
* Empire - A multi-player, client/server Internet based war game.
* Copyright (C) 1986-2000, 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 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.
*
* ---
*
* shutdown.c: Shuts down server. Runs at low priority.
*
* Known contributors to this file:
* Ken Stevens, 1995
*/
#include "misc.h"
#include "player.h"
#include "empio.h"
#include "empthread.h"
#include "proto.h"
#include "nat.h"
#include "file.h"
#include <time.h>
#include "prototypes.h"
int shutdown_pending;
void
shutdown_init(void)
{
shutdown_pending = 0;
}
void
shutdown_sequence(argc, argv)
int argc;
s_char **argv;
{
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);
}
empth_exit();
}

141
src/server/timestamp.c Normal file
View file

@ -0,0 +1,141 @@
/*
* Empire - A multi-player, client/server Internet based war game.
* Copyright (C) 1986-2000, 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 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.
*
* ---
*
* timestamp.c: Timestamp writer/maintainer thread
*
* Known contributors to this file:
* Steve McClure, 1996
* Doug Hay, 1998
*/
#include "options.h"
#include "misc.h"
#include "player.h"
#include "keyword.h"
#include "empthread.h"
#include <stdio.h>
#include "prototypes.h"
/*ARGSUSED*/
void
mobility_check(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 */
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;
}
}

152
src/server/update.c Normal file
View file

@ -0,0 +1,152 @@
/*
* Empire - A multi-player, client/server Internet based war game.
* Copyright (C) 1986-2000, 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 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.
*
* ---
*
* update.c: Update scheduler
*
* Known contributors to this file:
* Dave Pare, 1994
* Steve McClure, 1996
*/
#include "misc.h"
#include "player.h"
#include "keyword.h"
#include "empthread.h"
#include "prototypes.h"
#include "optlist.h"
empth_sem_t *update_sem;
extern void update_main();
extern void update_wait();
time_t update_time;
/*ARGSUSED*/
void
update_sched(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;
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);
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);
}
/*NOTREACHED*/
}
/*ARGSUSED*/
void
update_wait(argv)
void *argv;
{
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);
}
/*NOTREACHED*/
}