Crossfire Server, Trunk
init.cpp 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 "modules.h"
+ Include dependency graph for init.cpp:

Go to the source code of this file.

Data Structures

struct  Command_Line_Options
 
struct  module_information
 

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)
 
void close_modules ()
 
static void do_module (const char *name, bool enabled)
 
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)
 
void init_modules ()
 
void init_signals (void)
 
static void init_startup (void)
 
static void list_modules ()
 
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_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_module (const char *name)
 
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_enable_module (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_uniquedir (const char *path)
 
static void signal_shutdown (int signum_unused)
 
static void unset_debug (void)
 

Variables

static module_information modules []
 
static struct Command_Line_Options options []
 
static int should_exit = 0
 

Detailed Description

Server initialization, settings, and command-line handling.

Definition in file init.cpp.

Typedef Documentation

◆ cmdlinefunc_args0

typedef void(* cmdlinefunc_args0) (void)

Typedefs used when calling option handlers.

Definition at line 348 of file init.cpp.

◆ cmdlinefunc_args1

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

Definition at line 349 of file init.cpp.

◆ cmdlinefunc_args2

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

Definition at line 350 of file init.cpp.

Function Documentation

◆ add_server_collect_hooks()

void add_server_collect_hooks ( )

Definition at line 1071 of file init.cpp.

References Settings::add_hook(), 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 111 of file init.cpp.

References FULL_VERSION.

◆ close_modules()

void close_modules ( )

Clean up all modules which are not disabled.

Definition at line 80 of file init.cpp.

References module_information::close, module_information::description, module_information::enabled, llevInfo, LOG(), modules, and module_information::name.

Referenced by cleanup().

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

◆ do_module()

static void do_module ( const char *  name,
bool  enabled 
)
static

Change the 'enabled' flag of a module.

Parameters
namemodule's name, or 'All'.
enablednew value of the 'enabled' flag.
Note
will fatal() if the module name is invalid.

Definition at line 300 of file init.cpp.

References module_information::enabled, fatal(), llevError, LOG(), modules, give::name, module_information::name, and SEE_LAST_ERROR.

Referenced by set_disable_module(), and set_enable_module().

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

◆ free_materials()

static void free_materials ( void  )
static

Frees all memory allocated to materials.

Definition at line 574 of file init.cpp.

References materials.

Referenced by free_server().

+ 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 1123 of file init.cpp.

References Settings::disabled_plugins, free_materials(), free_quest(), free_races(), 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 499 of file init.cpp.

References materialtype_t::description, fatal(), materialtype_t::mod, materialtype_t::name, NROFATTACKS, OUT_OF_MEMORY, and materialtype_t::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 1134 of file init.cpp.

Referenced by ChangesDock::ChangesDock(), CREMainWindow::createMenus(), and ChangesDock::helpReady().

+ Here is the caller graph for this function:

◆ init()

void init ( int  argc,
char **  argv 
)

◆ init_beforeplay()

static void init_beforeplay ( void  )
static

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

Definition at line 1194 of file init.cpp.

References assets_finish_archetypes_for_play(), 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(), print_monsters(), and settings.

Referenced by init().

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

◆ init_modules()

void init_modules ( )

Init all modules which are not disabled.

Definition at line 64 of file init.cpp.

References module_information::description, module_information::enabled, module_information::init, llevInfo, LOG(), modules, module_information::name, and settings.

Referenced by init().

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

◆ init_signals()

void init_signals ( void  )

Setup our signal handlers.

Definition at line 1310 of file init.cpp.

References rec_sighup(), and signal_shutdown().

Referenced by command_unloadplugin(), and 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 1258 of file init.cpp.

References buf, Settings::confdir, forbid_play(), llevError, LOG(), MAX_BUF, settings, and SHUTDOWN_FILE.

Referenced by init().

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

◆ list_modules()

static void list_modules ( )
static

List all modules, then exit.

Definition at line 94 of file init.cpp.

References llevInfo, LOG(), modules, give::name, module_information::name, and should_exit.

+ Here is the call 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 519 of file init.cpp.

References add_refcount(), add_string(), buf, bufferreader_next_line(), materialtype_t::description, npc_dialog::filename, FREE_AND_COPY_IF, get_empty_mat(), llevDebug, LOG(), materialtype_t::material, materials, materialtype_t::mod, materialtype_t::name, give::next, NROFATTACKS, materialtype_t::save, autojail::value, and nlohmann::detail::void().

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 586 of file init.cpp.

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, 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, 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, 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_file, Settings::stat_loss_on_death, strcasecmp(), strdup_local, Ice::tmp, 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 447 of file init.cpp.

References cleanup(), Command_Line_Options::cmd_option, Command_Line_Options::func, Command_Line_Options::num_args, options, Command_Line_Options::pass, 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 1298 of file init.cpp.

References logfile, reopen_logfile, and nlohmann::detail::void().

Referenced by init_signals().

+ Here is the call graph for this function:
+ 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 333 of file init.cpp.

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 341 of file init.cpp.

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 264 of file init.cpp.

References assets_pack(), npc_dialog::filename, and should_exit.

+ Here is the call graph for this function:

◆ set_confdir()

static void set_confdir ( const char *  path)
static

Command line option: set configuration path.

Parameters
pathnew path.

Definition at line 197 of file init.cpp.

References Settings::confdir, python_init::path, 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 277 of file init.cpp.

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 189 of file init.cpp.

References Settings::datadir, python_init::path, and settings.

◆ set_debug()

static void set_debug ( void  )
static

Command line option: debug flag.

Definition at line 117 of file init.cpp.

References Settings::debug, llevDebug, and settings.

◆ set_disable_module()

static void set_disable_module ( const char *  name)
static

Disable a module.

Parameters
namemodule's name, or 'All'.

Definition at line 318 of file init.cpp.

References do_module(), and give::name.

+ Here is the call graph for this function:

◆ set_disable_plugin()

static void set_disable_plugin ( const char *  name)
static

Disable a plugin.

Parameters
nameplugin's name, without extension.

Definition at line 290 of file init.cpp.

References Settings::disabled_plugins, give::name, and settings.

◆ set_dumpmon1()

static void set_dumpmon1 ( void  )
static

Command line option: dump monsters.

Definition at line 132 of file init.cpp.

References Settings::dumpvalues, and settings.

◆ set_dumpmon2()

static void set_dumpmon2 ( void  )
static

Command line option: dump abilities.

Definition at line 137 of file init.cpp.

References Settings::dumpvalues, and settings.

◆ set_dumpmon3()

static void set_dumpmon3 ( void  )
static

Command line option: dump artifacts.

Definition at line 142 of file init.cpp.

References Settings::dumpvalues, and settings.

◆ set_dumpmon4()

static void set_dumpmon4 ( void  )
static

Command line option: dump spells.

Definition at line 147 of file init.cpp.

References Settings::dumpvalues, and settings.

◆ set_dumpmon5()

static void set_dumpmon5 ( void  )
static

Command line option: ?

Definition at line 152 of file init.cpp.

References Settings::dumpvalues, and settings.

◆ set_dumpmon6()

static void set_dumpmon6 ( void  )
static

Command line option: dump races.

Definition at line 157 of file init.cpp.

References Settings::dumpvalues, and settings.

◆ set_dumpmon7()

static void set_dumpmon7 ( void  )
static

Command line option: dump alchemy.

Definition at line 162 of file init.cpp.

References Settings::dumpvalues, and settings.

◆ set_dumpmon8()

static void set_dumpmon8 ( void  )
static

Command line option: dump gods.

Definition at line 167 of file init.cpp.

References Settings::dumpvalues, and settings.

◆ set_dumpmon9()

static void set_dumpmon9 ( void  )
static

Command line option: dump alchemy costs.

Definition at line 172 of file init.cpp.

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 180 of file init.cpp.

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

◆ set_enable_module()

static void set_enable_module ( const char *  name)
static

Enable a module.

Parameters
namemodule's name, or 'All'.

Definition at line 326 of file init.cpp.

References do_module(), and give::name.

+ Here is the call graph for this function:

◆ set_ignore_assets_errors()

static void set_ignore_assets_errors ( )
static

Command line option: ignore assets errors.

Definition at line 260 of file init.cpp.

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 205 of file init.cpp.

References Settings::localdir, python_init::path, and settings.

◆ set_logfile()

static void set_logfile ( char *  val)
static

Command line option: set logfile name.

Parameters
valnew name.

Definition at line 106 of file init.cpp.

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 213 of file init.cpp.

References Settings::mapdir, python_init::path, and settings.

◆ set_mondebug()

static void set_mondebug ( void  )
static

Command line option: monster debug flag.

Definition at line 127 of file init.cpp.

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 245 of file init.cpp.

References python_init::path, 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 221 of file init.cpp.

References python_init::path, 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 237 of file init.cpp.

References python_init::path, 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 253 of file init.cpp.

References python_init::path, settings, and Settings::tmpdir.

◆ set_uniquedir()

static void set_uniquedir ( const char *  path)
static

Command line option: set unique path.

Parameters
pathnew path.

Definition at line 229 of file init.cpp.

References python_init::path, 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 1281 of file init.cpp.

References shutdown_flag, and nlohmann::detail::void().

Referenced by init_signals().

+ Here is the call graph for this function:
+ 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 122 of file init.cpp.

References Settings::debug, llevInfo, and settings.

Variable Documentation

◆ modules

module_information modules[]
static
Initial value:
= {
{ "citybell", "Ring bells every hour for defined temples", true, cfcitybell_init, cfcitybell_close },
{ "citylife", "Add NPCs in towns", true, citylife_init, citylife_close },
{ "rhg", "Add random maps to exits in towns", false, random_house_generator_init, random_house_generator_close },
{ NULL, NULL, false, NULL, NULL }
}

All built modules.

Definition at line 54 of file init.cpp.

Referenced by close_modules(), do_module(), init_modules(), and list_modules().

◆ 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 376 of file init.cpp.

Referenced by find_player_options(), make_doors(), and 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.cpp.

Referenced by list_modules(), parse_args(), and server_pack_assets().

random_house_generator_init
void random_house_generator_init(Settings *settings)
Definition: random_house_generator.cpp:210
citylife_init
void citylife_init(Settings *settings)
Definition: citylife.cpp:427
random_house_generator_close
void random_house_generator_close()
Definition: random_house_generator.cpp:220
cfcitybell_init
void cfcitybell_init(Settings *settings)
Definition: cfcitybell.cpp:152
cfcitybell_close
void cfcitybell_close()
Definition: cfcitybell.cpp:164
citylife_close
void citylife_close()
Definition: citylife.cpp:438