(close_files, finish_server, panic):
Rename close_files() to ef_close_srv() and move to fileinit.c. Replace calls to close_files() with ef_fin_srv(). Call ef_close_srv() from ef_fin_srv(). (ef_close_srv, ef_fin_srv): New. (init_files, init_server, ef_init_srv): Rename init_files() to ef_open_srv() and move to fileinit.c. Remove call to init_files() from init_server() and replace with a call to ef_open_srv() from ef_init_srv(). (ef_open_srv): New. (ef_load, init_server, ef_init_srv): Move the call to ef_load() from init_server() to ef_init_srv(). (global_init, init_server, ef_init_srv): Move the call to global_init() from init_server() to ef_init_srv(). (nullify_objects, global_init, init_server): Split nullify_objects() into init_lchr() and init_dchr(). Locate init_lchr() and init_dchr() in init.c. Add calls to init_lchr() and to init_dchr() from global_init(). (init_lchr(), init_dchr()): New.
This commit is contained in:
parent
803009d0ce
commit
e89fb0bb17
4 changed files with 81 additions and 70 deletions
|
@ -476,6 +476,7 @@ extern int disloan(int, register struct lonstr *);
|
||||||
extern int distrea(int, register struct trtstr *);
|
extern int distrea(int, register struct trtstr *);
|
||||||
/* fileinit.c */
|
/* fileinit.c */
|
||||||
extern void ef_init_srv(void);
|
extern void ef_init_srv(void);
|
||||||
|
extern void ef_fin_srv(void);
|
||||||
/* fortdef.c */
|
/* fortdef.c */
|
||||||
extern int sd(natid, natid, coord, coord, int, int, int);
|
extern int sd(natid, natid, coord, coord, int, int, int);
|
||||||
extern int dd(natid, natid, coord, coord, int, int);
|
extern int dd(natid, natid, coord, coord, int, int);
|
||||||
|
|
|
@ -42,6 +42,8 @@
|
||||||
static void init_mchr(void);
|
static void init_mchr(void);
|
||||||
static void init_pchr(void);
|
static void init_pchr(void);
|
||||||
static void init_plchr(void);
|
static void init_plchr(void);
|
||||||
|
static void init_dchr(void);
|
||||||
|
static void init_lchr(void);
|
||||||
|
|
||||||
void
|
void
|
||||||
global_init(void)
|
global_init(void)
|
||||||
|
@ -49,6 +51,8 @@ global_init(void)
|
||||||
init_pchr();
|
init_pchr();
|
||||||
init_mchr();
|
init_mchr();
|
||||||
init_plchr();
|
init_plchr();
|
||||||
|
init_dchr();
|
||||||
|
init_lchr();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -89,3 +93,21 @@ init_pchr(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
init_dchr()
|
||||||
|
{
|
||||||
|
if (opt_BIG_CITY)
|
||||||
|
dchr[SCT_CAPIT] = bigcity_dchr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
init_lchr()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; lchr[i].l_name; i++) {
|
||||||
|
/* Fix up the military values */
|
||||||
|
lchr[i].l_mil = lchr[i].l_item[I_MILIT];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -35,6 +35,31 @@
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
|
|
||||||
|
static void
|
||||||
|
ef_open_srv(void)
|
||||||
|
{
|
||||||
|
int failed = 0;
|
||||||
|
failed |= !ef_open(EF_NATION, EFF_MEM);
|
||||||
|
failed |= !ef_open(EF_SECTOR, EFF_MEM);
|
||||||
|
failed |= !ef_open(EF_SHIP, EFF_MEM);
|
||||||
|
failed |= !ef_open(EF_PLANE, EFF_MEM);
|
||||||
|
failed |= !ef_open(EF_LAND, EFF_MEM);
|
||||||
|
failed |= !ef_open(EF_NEWS, 0);
|
||||||
|
failed |= !ef_open(EF_LOAN, 0);
|
||||||
|
failed |= !ef_open(EF_TREATY, 0);
|
||||||
|
failed |= !ef_open(EF_NUKE, EFF_MEM);
|
||||||
|
failed |= !ef_open(EF_POWER, 0);
|
||||||
|
failed |= !ef_open(EF_TRADE, 0);
|
||||||
|
failed |= !ef_open(EF_MAP, EFF_MEM);
|
||||||
|
failed |= !ef_open(EF_BMAP, EFF_MEM);
|
||||||
|
failed |= !ef_open(EF_COMM, 0);
|
||||||
|
failed |= !ef_open(EF_LOST, 0);
|
||||||
|
if (failed) {
|
||||||
|
logerror("Missing files, giving up");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct fileinit {
|
struct fileinit {
|
||||||
int ef_type;
|
int ef_type;
|
||||||
void (*init) (int, char *);
|
void (*init) (int, char *);
|
||||||
|
@ -61,11 +86,41 @@ ef_init_srv(void)
|
||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
|
||||||
|
if (ef_load() < 0)
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
|
||||||
for (i = 0; i < sizeof(fileinit) / sizeof(fileinit[0]); i++) {
|
for (i = 0; i < sizeof(fileinit) / sizeof(fileinit[0]); i++) {
|
||||||
empfile[fileinit[i].ef_type].init = fileinit[i].init;
|
empfile[fileinit[i].ef_type].init = fileinit[i].init;
|
||||||
empfile[fileinit[i].ef_type].postread = fileinit[i].postread;
|
empfile[fileinit[i].ef_type].postread = fileinit[i].postread;
|
||||||
empfile[fileinit[i].ef_type].prewrite = fileinit[i].prewrite;
|
empfile[fileinit[i].ef_type].prewrite = fileinit[i].prewrite;
|
||||||
}
|
}
|
||||||
|
|
||||||
ef_init();
|
ef_init();
|
||||||
|
ef_open_srv();
|
||||||
|
global_init();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ef_close_srv(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);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ef_fin_srv(void)
|
||||||
|
{
|
||||||
|
ef_close_srv();
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,9 +67,6 @@
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
|
|
||||||
static void nullify_objects(void);
|
|
||||||
static void init_files(void);
|
|
||||||
static void close_files(void);
|
|
||||||
static void create_pidfile(char *, pid_t);
|
static void create_pidfile(char *, pid_t);
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
|
@ -263,14 +260,9 @@ init_server(void)
|
||||||
loc_NTInit();
|
loc_NTInit();
|
||||||
#endif
|
#endif
|
||||||
update_policy_check();
|
update_policy_check();
|
||||||
if (ef_load() < 0)
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
nullify_objects();
|
|
||||||
global_init();
|
|
||||||
shutdown_init();
|
shutdown_init();
|
||||||
player_init();
|
player_init();
|
||||||
ef_init_srv();
|
ef_init_srv();
|
||||||
init_files();
|
|
||||||
io_init();
|
io_init();
|
||||||
init_nreport();
|
init_nreport();
|
||||||
|
|
||||||
|
@ -343,7 +335,7 @@ start_server(int flags)
|
||||||
void
|
void
|
||||||
finish_server(void)
|
finish_server(void)
|
||||||
{
|
{
|
||||||
close_files();
|
ef_fin_srv();
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
loc_NTTerm();
|
loc_NTTerm();
|
||||||
#endif
|
#endif
|
||||||
|
@ -362,51 +354,6 @@ create_pidfile(char *fname, pid_t pid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
init_files(void)
|
|
||||||
{
|
|
||||||
int failed = 0;
|
|
||||||
failed |= !ef_open(EF_NATION, EFF_MEM);
|
|
||||||
failed |= !ef_open(EF_SECTOR, EFF_MEM);
|
|
||||||
failed |= !ef_open(EF_SHIP, EFF_MEM);
|
|
||||||
failed |= !ef_open(EF_PLANE, EFF_MEM);
|
|
||||||
failed |= !ef_open(EF_LAND, EFF_MEM);
|
|
||||||
failed |= !ef_open(EF_NEWS, 0);
|
|
||||||
failed |= !ef_open(EF_LOAN, 0);
|
|
||||||
failed |= !ef_open(EF_TREATY, 0);
|
|
||||||
failed |= !ef_open(EF_NUKE, EFF_MEM);
|
|
||||||
failed |= !ef_open(EF_POWER, 0);
|
|
||||||
failed |= !ef_open(EF_TRADE, 0);
|
|
||||||
failed |= !ef_open(EF_MAP, EFF_MEM);
|
|
||||||
failed |= !ef_open(EF_BMAP, EFF_MEM);
|
|
||||||
failed |= !ef_open(EF_COMM, 0);
|
|
||||||
failed |= !ef_open(EF_LOST, 0);
|
|
||||||
if (failed) {
|
|
||||||
logerror("Missing files, giving up");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static 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 */
|
/* we're going down. try to close the files at least */
|
||||||
#if !defined(_WIN32)
|
#if !defined(_WIN32)
|
||||||
void
|
void
|
||||||
|
@ -423,7 +370,7 @@ panic(int sig)
|
||||||
sigaction(SIGFPE, &act, NULL);
|
sigaction(SIGFPE, &act, NULL);
|
||||||
logerror("server received fatal signal %d", sig);
|
logerror("server received fatal signal %d", sig);
|
||||||
log_last_commands();
|
log_last_commands();
|
||||||
close_files();
|
ef_fin_srv();
|
||||||
if (CANT_HAPPEN(sig != SIGBUS && sig != SIGSEGV
|
if (CANT_HAPPEN(sig != SIGBUS && sig != SIGSEGV
|
||||||
&& sig != SIGILL && sig != SIGFPE))
|
&& sig != SIGILL && sig != SIGFPE))
|
||||||
_exit(1);
|
_exit(1);
|
||||||
|
@ -482,20 +429,6 @@ shutdwn(int sig)
|
||||||
_exit(0);
|
_exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
nullify_objects(void)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (opt_BIG_CITY)
|
|
||||||
dchr[SCT_CAPIT] = bigcity_dchr;
|
|
||||||
for (i = 0; lchr[i].l_name; i++) {
|
|
||||||
/* Fix up the military values */
|
|
||||||
lchr[i].l_mil = lchr[i].l_item[I_MILIT];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
static void
|
static void
|
||||||
loc_NTInit(void)
|
loc_NTInit(void)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue