Crossfire Server, Branches 1.12  R18729
init.c File Reference
#include <global.h>
#include <loader.h>
#include <version.h>
#include <sproto.h>
#include <strings.h>
+ Include dependency graph for init.c:

Go to the source code of this file.

Data Structures

struct  Command_Line_Options
 

Typedefs

typedef void(* cmdlinefunc_args0 )(void)
 
typedef void(* cmdlinefunc_args1 )(const char *arg1)
 
typedef void(* cmdlinefunc_args2 )(const char *arg1, const char *arg2)
 

Functions

static void add_to_racelist (const char *race_name, object *op)
 
static void call_version (void)
 
static void compile_info (void)
 
static void dump_races (void)
 
static void fatal_signal (int make_core)
 
racelinkfind_racelink (const char *name)
 
static void free_materials (void)
 
static void free_races (void)
 
void free_server (void)
 
static materialtype_tget_empty_mat (void)
 
static racelinkget_racelist (void)
 
static void help (void)
 
void init (int argc, char **argv)
 
static void init_beforeplay (void)
 
static void init_races (void)
 
static void init_signals (void)
 
static void init_startup (void)
 
static void load_materials (void)
 
static void load_settings (void)
 
static void parse_args (int argc, char *argv[], int pass)
 
static void rec_sigbus (int i)
 
static void rec_sighup (int i)
 
static void rec_sigint (int i)
 
static void rec_sigpipe (int i)
 
static void rec_sigquit (int i)
 
static void rec_sigsegv (int i)
 
static void rec_sigterm (int i)
 
static void set_archetypes (const char *path)
 
static void set_confdir (const char *path)
 
static void set_csport (const char *val)
 
static void set_daemon (void)
 
static void set_datadir (const char *path)
 
static void set_debug (void)
 
static void set_dumpmon1 (void)
 
static void set_dumpmon2 (void)
 
static void set_dumpmon3 (void)
 
static void set_dumpmon4 (void)
 
static void set_dumpmon5 (void)
 
static void set_dumpmon6 (void)
 
static void set_dumpmon7 (void)
 
static void set_dumpmon8 (void)
 
static void set_dumpmon9 (void)
 
static void set_dumpmont (const char *name)
 
static void set_localdir (const char *path)
 
static void set_logfile (char *val)
 
static void set_mapdir (const char *path)
 
static void set_mondebug (void)
 
static void set_playerdir (const char *path)
 
static void set_regions (const char *path)
 
static void set_templatedir (const char *path)
 
static void set_tmpdir (const char *path)
 
static void set_treasures (const char *path)
 
static void set_uniquedir (const char *path)
 
static void showscores (void)
 
static void showscoresparm (const char *data)
 
static void unset_debug (void)
 
static void usage (void)
 

Variables

static char default_daemon_log [] = "logfile"
 
materialtype_tmaterialt
 
static struct Command_Line_Options options []
 

Detailed Description

Server initialisation, settings loading, command-line handling and such.

Definition in file init.c.

Typedef Documentation

typedef void(* cmdlinefunc_args0)(void)

Typedefs used when calling option handlers.

Definition at line 206 of file init.c.

typedef void(* cmdlinefunc_args1)(const char *arg1)

Definition at line 207 of file init.c.

typedef void(* cmdlinefunc_args2)(const char *arg1, const char *arg2)

Definition at line 208 of file init.c.

Function Documentation

static void add_to_racelist ( const char *  race_name,
object op 
)
static

Add an object to the racelist.

Parameters
race_namerace name.
opwhat object to add to the race.

Definition at line 1414 of file init.c.

References add_string(), find_racelink(), first_race, get_objectlink(), get_racelist(), ralnk::member, ralnk::name, ralnk::next, oblnk::next, ralnk::nrof, and oblnk::ob.

Referenced by init_races().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void call_version ( void  )
static

Definition at line 63 of file init.c.

References version().

+ Here is the call graph for this function:

static void compile_info ( void  )
static

Dump compilation information, activated with the -o flag.

It writes out information on how Imakefile and config.h was configured at compile time.

Definition at line 1091 of file init.c.

References Settings::datadir, llevError, Settings::localdir, LOG(), Settings::logfilename, MAP_MAXTIMEOUT, MAX_BUF, MAX_OBJECTS, MAX_TIME, PERM_FILE, Settings::playerdir, SAVE_MODE, settings, SHUTDOWN_FILE, strerror_local(), Settings::tmpdir, and Settings::uniquedir.

+ Here is the call graph for this function:

static void dump_races ( void  )
static

Dumps all race information to stderr.

Definition at line 1373 of file init.c.

References obj::arch, first_race, obj::level, ralnk::member, ralnk::name, archt::name, ralnk::next, oblnk::next, and oblnk::ob.

Referenced by init_beforeplay().

+ Here is the caller graph for this function:

static void fatal_signal ( int  make_core)
static

General signal handling. Will exit() in any case.

Parameters
make_coreif set abort() instead of exit() to generate a core dump.

Definition at line 1258 of file init.c.

References clean_tmp_files(), emergency_save(), and init_done.

Referenced by rec_sigbus(), rec_sigint(), rec_sigpipe(), rec_sigquit(), rec_sigsegv(), and rec_sigterm().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

racelink* find_racelink ( const char *  name)

Find the race information for the specified name.

Parameters
namerace to search for.
Returns
race structure, NULL if not found.

Definition at line 1468 of file init.c.

References first_race, ralnk::name, and ralnk::next.

Referenced by add_to_racelist(), and choose_cult_monster().

+ Here is the caller graph for this function:

static void free_materials ( void  )
static

Frees all memory allocated to materials.

Definition at line 481 of file init.c.

References _materialtype::next.

Referenced by free_server().

+ Here is the caller graph for this function:

static void free_races ( void  )
static

Frees all race-related information.

Definition at line 1388 of file init.c.

References first_race, free_string(), llevDebug, LOG(), ralnk::member, ralnk::name, ralnk::next, and oblnk::next.

Referenced by free_server().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void free_server ( void  )

Frees all memory allocated around here:

  • materials
  • races

Definition at line 955 of file init.c.

References free_materials(), and free_races().

Referenced by cleanup().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static materialtype_t* get_empty_mat ( void  )
static

Creates an empty materialtype_t structure.

Returns
new blanked structure.
Note
will fatal() instead of returning NULL.

Definition at line 355 of file init.c.

References _materialtype::ac, _materialtype::chance, _materialtype::damage, _materialtype::description, _materialtype::difficulty, fatal(), _materialtype::magic, _materialtype::mod, _materialtype::name, _materialtype::next, NROFATTACKS, OUT_OF_MEMORY, _materialtype::save, _materialtype::sp, _materialtype::value, _materialtype::wc, and _materialtype::weight.

Referenced by load_materials().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static racelink * get_racelist ( void  )
static

Create a new racelink structure.

Note
will call fatal() in case of memory allocation failure.
Returns
empty structure.

Definition at line 1446 of file init.c.

References fatal(), get_objectlink(), ralnk::member, ralnk::name, ralnk::next, ralnk::nrof, and OUT_OF_MEMORY.

Referenced by add_to_racelist().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void help ( void  )
static

Definition at line 964 of file init.c.

void init ( int  argc,
char **  argv 
)

This is the main server initialisation function.

Called only once, when starting the program.

Definition at line 905 of file init.c.

References become_daemon(), cftimer_init(), Settings::daemonmode, Settings::dm_mail, FULL_VERSION, init_beforeplay(), init_commands(), init_done, init_library(), init_ob_methods(), init_server(), init_signals(), init_skills(), init_startup(), load_materials(), load_settings(), logfile, metaserver2_init(), metaserver_init(), parse_args(), read_map_log(), reset_sleep(), and settings.

Referenced by main(), and server_main().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void init_beforeplay ( void  )
static
static void init_races ( void  )
static

Reads the races file in the lib/ directory, then overwrites old 'race' entries. This routine allow us to quickly re-configure the 'alignment' of monsters, objects. Useful for putting together lists of creatures, etc that belong to gods.

Definition at line 1300 of file init.c.

References add_string(), add_to_racelist(), archt::clone, Settings::datadir, find_archetype(), first_race, FLAG_MONSTER, free_string(), init_done, llevDebug, llevError, LOG(), MAX_BUF, mon, archt::name, QUERY_FLAG, obj::race, settings, snprintf(), and strerror_local().

Referenced by init_beforeplay().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void init_signals ( void  )
static

Setup our signal handlers.

Definition at line 1271 of file init.c.

References llevInfo, LOG(), rec_sigbus(), rec_sighup(), rec_sigint(), rec_sigpipe(), rec_sigquit(), rec_sigsegv(), and rec_sigterm().

Referenced by init().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void init_startup ( void  )
static

Checks if starting the server is allowed.

Todo:
describe forbid_play() and such restrictions.

Definition at line 1064 of file init.c.

References close_and_delete(), Settings::confdir, forbid_play(), llevError, LOG(), MAX_BUF, open_and_uncompress(), settings, SHUTDOWN_FILE, and snprintf().

Referenced by init().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void load_materials ( void  )
static
static void load_settings ( void  )
static

This loads the settings file. There could be debate whether this should be here or in the common directory - but since only the server needs this information, having it here probably makes more sense.

Definition at line 497 of file init.c.

References Settings::allow_broken_converters, Settings::allow_denied_spells_writing, Settings::armor_max_enchant, Settings::armor_speed_improvement, Settings::armor_speed_linear, Settings::armor_weight_linear, Settings::armor_weight_reduction, Settings::balanced_stat_loss, Settings::casting_time, close_and_delete(), Settings::confdir, Settings::create_home_portals, Settings::death_penalty_level, Settings::death_penalty_ratio, Settings::dm_mail, Settings::explore_mode, FALSE, Settings::fastclock, Settings::item_power_factor, llevError, LOG(), Settings::log_timestamp, Settings::log_timestamp_format, MAX_BUF, Settings::meta_comment, Settings::meta_host, Settings::meta_on, Settings::meta_port, Settings::meta_server, Settings::motd, Settings::no_player_stealing, Settings::not_permadeth, open_and_uncompress(), Settings::permanent_exp_ratio, Settings::personalized_blessings, Settings::pk_luck_penalty, Settings::pk_max_experience, Settings::pk_max_experience_percent, Settings::real_wiz, Settings::recycle_tmp_maps, Settings::resurrection, Settings::search_items, set_csport(), Settings::set_friendly_fire, Settings::set_title, settings, Settings::simple_exp, snprintf(), Settings::spell_encumbrance, Settings::spell_failure_effects, Settings::spellpoint_level_depend, Settings::stat_loss_on_death, strcasecmp(), strdup_local(), TRUE, Settings::who_format, Settings::who_wiz_format, Settings::worldmapstartx, Settings::worldmapstarty, Settings::worldmaptilesizex, Settings::worldmaptilesizey, Settings::worldmaptilesx, and Settings::worldmaptilesy.

Referenced by init().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void parse_args ( int  argc,
char *  argv[],
int  pass 
)
static

Parse command line arguments.

Note since this may be called before the library has been set up, we don't use any of crossfires built in logging functions.

Parameters
argclength of argv.
argvarguments.
passinitialization pass arguments to use.
Todo:
describe pass.

Definition at line 304 of file init.c.

References Command_Line_Options::cmd_option, Command_Line_Options::func, Command_Line_Options::num_args, options, and usage().

Referenced by init().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void rec_sigbus ( int  i)
static

SIGBUS handler.

Parameters
iunused.

Definition at line 1234 of file init.c.

References fatal_signal(), llevError, and LOG().

Referenced by init_signals().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void rec_sighup ( int  i)
static

SIGHUP handler. SIGHUP handlers on daemons typically make them reread the config files and reinitialize itself. This behaviour is better left for an explicit shutdown and restart with Crossfire, as there is just too much persistent runtime state. However, another function of SIGHUP handlers is to reopen the log file for logrotate's benefit. We can do that here.

Parameters
iunused.

Definition at line 1185 of file init.c.

References logfile, and reopen_logfile.

Referenced by init_signals().

+ Here is the caller graph for this function:

static void rec_sigint ( int  i)
static

SIGINT handler.

Parameters
iunused.

Definition at line 1168 of file init.c.

References fatal_signal(), llevInfo, and LOG().

Referenced by init_signals().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void rec_sigpipe ( int  i)
static

SIGPIPE handler.

Keep running if we receive a sigpipe. Crossfire should really be able to handle this signal (at least at some point in the future if not right now). By causing a dump right when it is received, it is not doing much good. However, if it core dumps later on, at least it can be looked at later on, and maybe fix the problem that caused it to dump core. There is no reason that SIGPIPES should be fatal

Parameters
iunused.

Definition at line 1217 of file init.c.

References fatal_signal(), llevError, llevInfo, and LOG().

Referenced by init_signals().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void rec_sigquit ( int  i)
static

SIGQUIT handler.

Parameters
iunused.

Definition at line 1199 of file init.c.

References fatal_signal(), llevInfo, and LOG().

Referenced by init_signals().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void rec_sigsegv ( int  i)
static

SIGSERV handler.

Parameters
iunused.

Definition at line 1158 of file init.c.

References fatal_signal(), llevError, and LOG().

Referenced by init_signals().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void rec_sigterm ( int  i)
static

SIGTERM handler.

Parameters
iunused.

Definition at line 1247 of file init.c.

References fatal_signal(), llevInfo, and LOG().

Referenced by init_signals().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void set_archetypes ( const char *  path)
static

Definition at line 149 of file init.c.

References Settings::archetypes, and settings.

static void set_confdir ( const char *  path)
static

Definition at line 137 of file init.c.

References Settings::confdir, and settings.

static void set_csport ( const char *  val)
static

Change the server's port. Will exit() if invalid value.

Parameters
valport to use. Must be a valid one, between 1 and 32765 inclusive.

Definition at line 192 of file init.c.

References Settings::csport, llevError, LOG(), and settings.

Referenced by load_settings().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void set_daemon ( void  )
static

Definition at line 126 of file init.c.

References Settings::daemonmode, default_daemon_log, Settings::logfilename, and settings.

static void set_datadir ( const char *  path)
static

Definition at line 133 of file init.c.

References Settings::datadir, and settings.

static void set_debug ( void  )
static

Definition at line 73 of file init.c.

References Settings::debug, llevDebug, and settings.

static void set_dumpmon1 ( void  )
static

Definition at line 85 of file init.c.

References Settings::dumpvalues, and settings.

static void set_dumpmon2 ( void  )
static

Definition at line 89 of file init.c.

References Settings::dumpvalues, and settings.

static void set_dumpmon3 ( void  )
static

Definition at line 93 of file init.c.

References Settings::dumpvalues, and settings.

static void set_dumpmon4 ( void  )
static

Definition at line 97 of file init.c.

References Settings::dumpvalues, and settings.

static void set_dumpmon5 ( void  )
static

Definition at line 101 of file init.c.

References Settings::dumpvalues, and settings.

static void set_dumpmon6 ( void  )
static

Definition at line 105 of file init.c.

References Settings::dumpvalues, and settings.

static void set_dumpmon7 ( void  )
static

Definition at line 109 of file init.c.

References Settings::dumpvalues, and settings.

static void set_dumpmon8 ( void  )
static

Definition at line 113 of file init.c.

References Settings::dumpvalues, and settings.

static void set_dumpmon9 ( void  )
static

Definition at line 117 of file init.c.

References Settings::dumpvalues, and settings.

static void set_dumpmont ( const char *  name)
static

Definition at line 121 of file init.c.

References Settings::dumparg, Settings::dumpvalues, and settings.

static void set_localdir ( const char *  path)
static

Definition at line 141 of file init.c.

References Settings::localdir, and settings.

static void set_logfile ( char *  val)
static

Definition at line 59 of file init.c.

References Settings::logfilename, and settings.

static void set_mapdir ( const char *  path)
static

Definition at line 145 of file init.c.

References Settings::mapdir, and settings.

static void set_mondebug ( void  )
static

Definition at line 81 of file init.c.

References Settings::debug, llevMonster, and settings.

static void set_playerdir ( const char *  path)
static

Definition at line 169 of file init.c.

References Settings::playerdir, and settings.

static void set_regions ( const char *  path)
static

Definition at line 153 of file init.c.

References Settings::regions, and settings.

static void set_templatedir ( const char *  path)
static

Definition at line 165 of file init.c.

References settings, and Settings::templatedir.

static void set_tmpdir ( const char *  path)
static

Definition at line 173 of file init.c.

References settings, and Settings::tmpdir.

static void set_treasures ( const char *  path)
static

Definition at line 157 of file init.c.

References settings, and Settings::treasures.

static void set_uniquedir ( const char *  path)
static

Definition at line 161 of file init.c.

References settings, and Settings::uniquedir.

static void showscores ( void  )
static

Definition at line 68 of file init.c.

References display_high_score().

+ Here is the call graph for this function:

static void showscoresparm ( const char *  data)
static

Definition at line 181 of file init.c.

References display_high_score().

+ Here is the call graph for this function:

static void unset_debug ( void  )
static

Definition at line 77 of file init.c.

References Settings::debug, llevInfo, and settings.

static void usage ( void  )
static

Definition at line 960 of file init.c.

References logfile.

Referenced by parse_args().

+ Here is the caller graph for this function:

Variable Documentation

char default_daemon_log[] = "logfile"
static

Filename when in daemon mode.

Definition at line 57 of file init.c.

Referenced by set_daemon().

materialtype_t* materialt

Material types.

Definition at line 345 of file init.c.

struct Command_Line_Options options[]
static

Actual valid command line options. The way this system works is pretty simple - parse_args takes the options passed to the program and a pass number. If an option matches both in name and in pass (and we have enough options), we call the associated function. This makes writing a multi pass system very easy, and it is very easy to add in new options.

Definition at line 234 of file init.c.

Referenced by parse_args().