Crossfire Server, Trunk  R22047
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 "assets.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

void add_server_collect_hooks ()
 
static void call_version (void)
 
static void free_materials (void)
 
void free_server (void)
 
static materialtype_tget_empty_mat (void)
 
static void help (void)
 
void init (int argc, char **argv)
 
static void init_beforeplay (void)
 
static void init_signals (void)
 
static void init_startup (void)
 
static void load_materials (BufferReader *reader, const char *filename)
 
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 server_dump_faces (void)
 
static void server_pack_assets (const char *assets, const char *filename)
 
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_ignore_assets_errors ()
 
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 (int signum_unused)
 
static void unset_debug (void)
 

Variables

static struct Command_Line_Options options []
 
static int should_exit = 0
 

Detailed Description

Server initialization, settings, and command-line handling.

Definition in file init.c.

Typedef Documentation

◆ cmdlinefunc_args0

typedef void(* cmdlinefunc_args0) (void)

Typedefs used when calling option handlers.

Definition at line 274 of file init.c.

◆ cmdlinefunc_args1

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

Definition at line 275 of file init.c.

◆ cmdlinefunc_args2

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

Definition at line 276 of file init.c.

Function Documentation

◆ add_server_collect_hooks()

void add_server_collect_hooks ( )

Definition at line 1018 of file init.c.

References Settings::hooks, Settings::hooks_count, Settings::hooks_filename, load_materials(), load_races(), and settings.

Referenced by init(), and ResourcesManager::load().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ call_version()

static void call_version ( void  )
static

Command line option: show version.

Definition at line 54 of file init.c.

References FULL_VERSION.

◆ free_materials()

static void free_materials ( void  )
static

Frees all memory allocated to materials.

Definition at line 516 of file init.c.

References materialt, and _materialtype::next.

Referenced by free_server(), and server_pack_assets().

+ Here is the caller graph for this function:

◆ free_server()

void free_server ( void  )

Frees all memory allocated around here:

  • materials
  • races

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

◆ get_empty_mat()

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 424 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:

◆ help()

static void help ( void  )
static

Display the command line options and exits.

Definition at line 1089 of file init.c.

◆ init()

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

References accounts_load(), add_server_collect_hooks(), cftimer_init(), first_race, FULL_VERSION, hiscore_init(), init_beforeplay(), init_commands(), init_library(), init_ob_methods(), init_server(), init_signals(), init_skills(), init_startup(), llevInfo, 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:

◆ init_beforeplay()

static void init_beforeplay ( void  )
static

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

Definition at line 1143 of file init.c.

References assets_finish_archetypes_for_play(), 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, finish_races(), init_archetype_pointers(), init_gods(), init_readable(), init_regions(), print_monsters(), quest_load_definitions(), and settings.

Referenced by init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init_signals()

static void init_signals ( void  )
static

Setup our signal handlers.

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

◆ init_startup()

static void init_startup ( void  )
static

Checks if starting the server is allowed.

Todo:
describe forbid_play() and such restrictions.

Definition at line 1200 of file init.c.

References buf, 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:

◆ load_materials()

static void load_materials ( BufferReader reader,
const char *  filename 
)
static

Loads the materials.

Todo:
describe materials and such.

Definition at line 445 of file init.c.

References add_string(), buf, bufferreader_next_line(), _materialtype::description, get_empty_mat(), llevDebug, LOG(), _materialtype::material, materialt, _materialtype::mod, _materialtype::name, _materialtype::next, NROFATTACKS, and _materialtype::save.

Referenced by add_server_collect_hooks().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ load_settings()

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

References Settings::account_block_create, Settings::account_trusted_host, Settings::allow_broken_converters, Settings::allow_denied_spells_writing, Settings::always_show_hp, 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, buf, Settings::casting_time, Settings::confdir, Settings::create_home_portals, Settings::crypt_mode, 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, MAX_NAME, Settings::max_stat, Settings::meta_comment, Settings::meta_host, Settings::meta_on, Settings::meta_port, Settings::meta_server, Settings::min_name, 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:

◆ parse_args()

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

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

Referenced by init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rec_sighup()

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

References logfile, and reopen_logfile.

Referenced by init_signals().

+ Here is the caller graph for this function:

◆ server_dump_animations()

static void server_dump_animations ( void  )
static

Dump all animations, then exit.

Definition at line 259 of file init.c.

References cleanup(), and dump_animations().

+ Here is the call graph for this function:

◆ server_dump_faces()

static void server_dump_faces ( void  )
static

Dump all faces, then exit.

Definition at line 267 of file init.c.

References cleanup(), and dump_faces().

+ Here is the call graph for this function:

◆ server_pack_assets()

static void server_pack_assets ( const char *  assets,
const char *  filename 
)
static

Definition at line 223 of file init.c.

References assets_pack(), free_materials(), and should_exit.

+ Here is the call graph for this function:

◆ set_archetypes()

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.

◆ set_confdir()

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.

◆ set_csport()

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 236 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:

◆ set_datadir()

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.

◆ set_debug()

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.

◆ set_disable_plugin()

static void set_disable_plugin ( const char *  name)
static

Disable a plugin.

Parameters
nameplugin's name, without extension.

Definition at line 249 of file init.c.

References Settings::disabled_plugins, linked_char::name, linked_char::next, and settings.

◆ set_dumpmon1()

static void set_dumpmon1 ( void  )
static

Command line option: dump monsters.

Definition at line 75 of file init.c.

References Settings::dumpvalues, and settings.

◆ set_dumpmon2()

static void set_dumpmon2 ( void  )
static

Command line option: dump abilities.

Definition at line 80 of file init.c.

References Settings::dumpvalues, and settings.

◆ set_dumpmon3()

static void set_dumpmon3 ( void  )
static

Command line option: dump artifacts.

Definition at line 85 of file init.c.

References Settings::dumpvalues, and settings.

◆ set_dumpmon4()

static void set_dumpmon4 ( void  )
static

Command line option: dump spells.

Definition at line 90 of file init.c.

References Settings::dumpvalues, and settings.

◆ set_dumpmon5()

static void set_dumpmon5 ( void  )
static

Command line option: ?

Definition at line 95 of file init.c.

References Settings::dumpvalues, and settings.

◆ set_dumpmon6()

static void set_dumpmon6 ( void  )
static

Command line option: dump races.

Definition at line 100 of file init.c.

References Settings::dumpvalues, and settings.

◆ set_dumpmon7()

static void set_dumpmon7 ( void  )
static

Command line option: dump alchemy.

Definition at line 105 of file init.c.

References Settings::dumpvalues, and settings.

◆ set_dumpmon8()

static void set_dumpmon8 ( void  )
static

Command line option: dump gods.

Definition at line 110 of file init.c.

References Settings::dumpvalues, and settings.

◆ set_dumpmon9()

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.

◆ set_dumpmont()

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.

◆ set_ignore_assets_errors()

static void set_ignore_assets_errors ( )
static

Command line option: ignore assets errors.

Definition at line 219 of file init.c.

References Settings::ignore_assets_errors, and settings.

◆ set_localdir()

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.

◆ set_logfile()

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.

◆ set_mapdir()

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.

◆ set_mondebug()

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.

◆ set_playerdir()

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.

◆ set_regions()

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.

◆ set_templatedir()

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.

◆ set_tmpdir()

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.

◆ set_treasures()

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.

◆ set_uniquedir()

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.

◆ signal_shutdown()

static void signal_shutdown ( int  signum_unused)
static

Signal handler that begins a normal server shutdown.

Definition at line 1223 of file init.c.

References shutdown_flag.

Referenced by init_signals().

+ Here is the caller graph for this function:

◆ unset_debug()

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

◆ options

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

Referenced by parse_args().

◆ should_exit

int should_exit = 0
static

If set after command line argument parsing, then the server will exit.

Definition at line 43 of file init.c.

Referenced by parse_args(), and server_pack_assets().