#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);
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;
#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 */
#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 */
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;
}
#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);
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;
-
- 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;
- }
- }
+ 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;
+ }
}
+ /* 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) {
}
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);
}
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;
+ }
}
}
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
WSACleanup();
}
#endif
-