Crossfire Server, Trunk  R20608
init.c File Reference
#include "global.h"
#include <errno.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "loader.h"
#include "version.h"
#include "server.h"
#include "sproto.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 dump_races (void)
 
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_sighup (int i)
 
static void server_dump_animations (void)
 
static void set_archetypes (const char *path)
 
static void set_confdir (const char *path)
 
static void set_csport (const char *val)
 
static void set_datadir (const char *path)
 
static void set_debug (void)
 
static void set_disable_plugin (const char *name)
 
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 signal_shutdown ()
 
static void unset_debug (void)
 

Variables

static struct Command_Line_Options options []
 

Detailed Description

Server initialization, settings, and command-line handling.

Definition in file init.c.

Typedef Documentation

typedef void(* cmdlinefunc_args0)(void)

Typedefs used when calling option handlers.

Definition at line 256 of file init.c.

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

Definition at line 257 of file init.c.

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

Definition at line 258 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 1326 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

Command line option: show version.

Definition at line 54 of file init.c.

References FULL_VERSION.

static void dump_races ( void  )
static

Dumps all race information to stderr.

Definition at line 1285 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:

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 1380 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 494 of file init.c.

References materialt, and _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 1300 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 1018 of file init.c.

References Settings::disabled_plugins, free_materials(), free_quest(), free_quest_definitions(), free_races(), linked_char::name, linked_char::next, and settings.

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 399 of file init.c.

References _materialtype::description, fatal(), _materialtype::mod, _materialtype::name, _materialtype::next, NROFATTACKS, OUT_OF_MEMORY, and _materialtype::save.

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 1358 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

Display the command line options and exits.

Definition at line 1034 of file init.c.

void init ( int  argc,
char **  argv 
)

This is the main server initialization function.

Called only once, when starting the program.

Parameters
argcargument count.
argvarguments on the command line.

Definition at line 978 of file init.c.

References accounts_load(), cftimer_init(), FULL_VERSION, hiscore_init(), init_beforeplay(), init_commands(), init_done, init_library(), init_ob_methods(), init_server(), init_signals(), init_skills(), init_startup(), llevInfo, load_materials(), load_settings(), LOG(), logfile, metaserver2_init(), parse_args(), read_map_log(), reset_sleep(), and SRANDOM.

Referenced by main(), server_main(), and START_TEST().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void init_beforeplay ( void  )
static

Called before the server starts listening to connections, processes various dump-related options.

Definition at line 1079 of file init.c.

References check_spells(), cleanup(), dump_abilities(), dump_alchemy(), dump_alchemy_costs(), dump_artifacts(), dump_gods(), dump_monster_treasure(), dump_races(), dump_spells(), Settings::dumparg, Settings::dumpvalues, init_archetype_pointers(), init_archetypes(), init_artifacts(), init_formulae(), init_gods(), init_races(), init_readable(), init_regions(), print_monsters(), and settings.

Referenced by init().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 1207 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, and snprintf.

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 1187 of file init.c.

References rec_sighup(), and signal_shutdown().

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 1137 of file init.c.

References Settings::confdir, forbid_play(), llevError, LOG(), MAX_BUF, 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

Loads the materials.

Todo:
describe materials and such.

Definition at line 420 of file init.c.

References add_string(), Settings::datadir, _materialtype::description, get_empty_mat(), llevDebug, llevError, LOG(), _materialtype::material, materialt, MAX_BUF, _materialtype::mod, _materialtype::name, _materialtype::next, NROFATTACKS, _materialtype::save, settings, and snprintf.

Referenced by init().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 510 of file init.c.

References Settings::account_block_create, Settings::account_trusted_host, 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, atoll, Settings::balanced_stat_loss, Settings::casting_time, Settings::confdir, Settings::create_home_portals, Settings::death_penalty_level, Settings::death_penalty_ratio, Settings::dm_mail, FALSE, Settings::fastclock, Settings::ignore_plugin_compatibility, Settings::item_power_factor, llevError, LOG(), Settings::log_timestamp, Settings::log_timestamp_format, MAX_BUF, Settings::max_stat, Settings::meta_comment, Settings::meta_host, Settings::meta_on, Settings::meta_port, Settings::meta_server, Settings::motd, Settings::no_player_stealing, Settings::not_permadeth, NUM_STATS, 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::roll_stat_points, safe_strncpy, Settings::search_items, set_csport(), Settings::set_friendly_fire, Settings::set_title, settings, Settings::simple_exp, snprintf, Settings::special_break_map, Settings::spell_encumbrance, Settings::spell_failure_effects, Settings::spellpoint_level_depend, Settings::starting_stat_max, Settings::starting_stat_min, Settings::starting_stat_points, 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 351 of file init.c.

References Command_Line_Options::cmd_option, Command_Line_Options::func, Command_Line_Options::num_args, and options.

Referenced by init().

+ 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 1176 of file init.c.

References logfile, and reopen_logfile.

Referenced by init_signals().

+ Here is the caller graph for this function:

static void server_dump_animations ( void  )
static

Dump all animations, then exit.

Definition at line 249 of file init.c.

References cleanup(), and dump_animations().

+ Here is the call graph for this function:

static void set_archetypes ( const char *  path)
static

Command line option: set archetypes file name.

Parameters
pathnew name.

Definition at line 164 of file init.c.

References Settings::archetypes, and settings.

static void set_confdir ( const char *  path)
static

Command line option: set configuration path.

Parameters
pathnew path.

Definition at line 140 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 65535 inclusive.

Definition at line 226 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_datadir ( const char *  path)
static

Command line option: set data path.

Parameters
pathnew path.

Definition at line 132 of file init.c.

References Settings::datadir, and settings.

static void set_debug ( void  )
static

Command line option: debug flag.

Definition at line 60 of file init.c.

References Settings::debug, llevDebug, and settings.

static void set_disable_plugin ( const char *  name)
static

Disable a plugin.

Parameters
nameplugin's name, without extension.

Definition at line 239 of file init.c.

References Settings::disabled_plugins, linked_char::name, linked_char::next, settings, and strdup().

+ Here is the call graph for this function:

static void set_dumpmon1 ( void  )
static

Command line option: dump monsters.

Definition at line 75 of file init.c.

References Settings::dumpvalues, and settings.

static void set_dumpmon2 ( void  )
static

Command line option: dump abilities.

Definition at line 80 of file init.c.

References Settings::dumpvalues, and settings.

static void set_dumpmon3 ( void  )
static

Command line option: dump artifacts.

Definition at line 85 of file init.c.

References Settings::dumpvalues, and settings.

static void set_dumpmon4 ( void  )
static

Command line option: dump spells.

Definition at line 90 of file init.c.

References Settings::dumpvalues, and settings.

static void set_dumpmon5 ( void  )
static

Command line option: ?

Definition at line 95 of file init.c.

References Settings::dumpvalues, and settings.

static void set_dumpmon6 ( void  )
static

Command line option: dump races.

Definition at line 100 of file init.c.

References Settings::dumpvalues, and settings.

static void set_dumpmon7 ( void  )
static

Command line option: dump alchemy.

Definition at line 105 of file init.c.

References Settings::dumpvalues, and settings.

static void set_dumpmon8 ( void  )
static

Command line option: dump gods.

Definition at line 110 of file init.c.

References Settings::dumpvalues, and settings.

static void set_dumpmon9 ( void  )
static

Command line option: dump alchemy costs.

Definition at line 115 of file init.c.

References Settings::dumpvalues, and settings.

static void set_dumpmont ( const char *  name)
static

Command line option: dump monster treasures.

Parameters
namemonster's name to dump treasure for.

Definition at line 123 of file init.c.

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

static void set_localdir ( const char *  path)
static

Command line option: set local path.

Parameters
pathnew path.

Definition at line 148 of file init.c.

References Settings::localdir, and settings.

static void set_logfile ( char *  val)
static

Command line option: set logfile name.

Parameters
valnew name.

Definition at line 49 of file init.c.

References Settings::logfilename, and settings.

static void set_mapdir ( const char *  path)
static

Command line option: set map path.

Parameters
pathnew path.

Definition at line 156 of file init.c.

References Settings::mapdir, and settings.

static void set_mondebug ( void  )
static

Command line option: monster debug flag.

Definition at line 70 of file init.c.

References Settings::debug, llevMonster, and settings.

static void set_playerdir ( const char *  path)
static

Command line option: set player path.

Parameters
pathnew path.

Definition at line 204 of file init.c.

References Settings::playerdir, and settings.

static void set_regions ( const char *  path)
static

Command line option: set regions file name.

Parameters
pathnew name.

Definition at line 172 of file init.c.

References Settings::regions, and settings.

static void set_templatedir ( const char *  path)
static

Command line option: set template path.

Parameters
pathnew path.

Definition at line 196 of file init.c.

References settings, and Settings::templatedir.

static void set_tmpdir ( const char *  path)
static

Command line option: set temporary file path.

Parameters
pathnew path.

Definition at line 212 of file init.c.

References settings, and Settings::tmpdir.

static void set_treasures ( const char *  path)
static

Command line option: set treasures file name.

Parameters
pathnew name.

Definition at line 180 of file init.c.

References settings, and Settings::treasures.

static void set_uniquedir ( const char *  path)
static

Command line option: set unique path.

Parameters
pathnew path.

Definition at line 188 of file init.c.

References settings, and Settings::uniquedir.

static void signal_shutdown ( )
static

Signal handler that begins a normal server shutdown.

Definition at line 1160 of file init.c.

References shutdown_flag.

Referenced by init_signals().

+ Here is the caller graph for this function:

static void unset_debug ( void  )
static

Command line option: unset debug flag.

Definition at line 65 of file init.c.

References Settings::debug, llevInfo, and settings.

Variable Documentation

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 284 of file init.c.

Referenced by parse_args().