![]() |
Crossfire Server, Trunk
1.75.0
|
#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"
Go to the source code of this file.
Data Structures | |
struct | Command_Line_Options |
One command line option definition. More... | |
struct | module_information |
Typedefs | |
typedef void(* | cmdlinefunc_args0) (void) |
Typedefs used when calling option handlers. More... | |
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) |
Command line option: show version. More... | |
void | close_modules () |
Clean up all modules which are not disabled. More... | |
static void | do_module (const char *name, bool enabled) |
Change the 'enabled' flag of a module. More... | |
static void | free_materials (void) |
Frees all memory allocated to materials. More... | |
void | free_server (void) |
Frees all memory allocated around here: More... | |
static materialtype_t * | get_empty_mat (void) |
Creates an empty materialtype_t structure. More... | |
static void | help (void) |
Display the command line options and exits. More... | |
void | init (int argc, char **argv) |
This is the main server initialization function. More... | |
static void | init_beforeplay (void) |
Called before the server starts listening to connections, processes various dump-related options. More... | |
void | init_modules () |
Init all modules which are not disabled. More... | |
void | init_signals (void) |
Setup our signal handlers. More... | |
static void | init_startup (void) |
Checks if starting the server is allowed. More... | |
static void | list_modules () |
List all modules, then exit. More... | |
static void | load_materials (BufferReader *reader, const char *filename) |
Loads the materials. More... | |
static void | load_settings (void) |
This loads the settings file. More... | |
static void | parse_args (int argc, char *argv[], int pass) |
Parse command line arguments. More... | |
static void | rec_sighup (int i) |
SIGHUP handler. More... | |
static void | server_dump_animations (void) |
Dump all animations, then exit. More... | |
static void | server_dump_bonuses () |
Dump all bonuses (from the stat_bonus file) then exit. More... | |
static void | server_dump_faces (void) |
Dump all faces, then exit. More... | |
static void | server_pack_assets (const char *assets, const char *filename) |
static void | set_confdir (const char *path) |
Command line option: set configuration path. More... | |
static void | set_csport (const char *val) |
Change the server's port. More... | |
static void | set_datadir (const char *path) |
Command line option: set data path. More... | |
static void | set_debug (void) |
Command line option: debug flag. More... | |
static void | set_disable_module (const char *name) |
Disable a module. More... | |
static void | set_disable_plugin (const char *name) |
Disable a plugin. More... | |
static void | set_dumpmon1 (void) |
Command line option: dump monsters. More... | |
static void | set_dumpmon2 (void) |
Command line option: dump abilities. More... | |
static void | set_dumpmon3 (void) |
Command line option: dump artifacts. More... | |
static void | set_dumpmon4 (void) |
Command line option: dump spells. More... | |
static void | set_dumpmon5 (void) |
Command line option: ? More... | |
static void | set_dumpmon6 (void) |
Command line option: dump races. More... | |
static void | set_dumpmon7 (void) |
Command line option: dump alchemy. More... | |
static void | set_dumpmon8 (void) |
Command line option: dump gods. More... | |
static void | set_dumpmon9 (void) |
Command line option: dump alchemy costs. More... | |
static void | set_dumpmont (const char *name) |
Command line option: dump monster treasures. More... | |
static void | set_enable_module (const char *name) |
Enable a module. More... | |
static void | set_ignore_assets_errors () |
Command line option: ignore assets errors. More... | |
static void | set_localdir (const char *path) |
Command line option: set local path. More... | |
static void | set_logfile (char *val) |
Command line option: set logfile name. More... | |
static void | set_mapdir (const char *path) |
Command line option: set map path. More... | |
static void | set_mondebug (void) |
Command line option: monster debug flag. More... | |
static void | set_playerdir (const char *path) |
Command line option: set player path. More... | |
static void | set_regions (const char *path) |
Command line option: set regions file name. More... | |
static void | set_templatedir (const char *path) |
Command line option: set template path. More... | |
static void | set_tmpdir (const char *path) |
Command line option: set temporary file path. More... | |
static void | set_uniquedir (const char *path) |
Command line option: set unique path. More... | |
static void | signal_shutdown (int signum_unused) |
Signal handler that begins a normal server shutdown. More... | |
static void | unset_debug (void) |
Command line option: unset debug flag. More... | |
Variables | |
static module_information | modules [] |
All built modules. More... | |
static struct Command_Line_Options | options [] |
Actual valid command line options. More... | |
ServerSettings | serverSettings |
static int | should_exit = 0 |
If set after command line argument parsing, then the server will exit. More... | |
Server initialization, settings, and command-line handling.
Definition in file init.cpp.
typedef void(* cmdlinefunc_args0) (void) |
typedef void(* cmdlinefunc_args2) (const char *arg1, const char *arg2) |
void add_server_collect_hooks | ( | ) |
Definition at line 1086 of file init.cpp.
References assets_add_collector_hook(), load_materials(), and load_races().
Referenced by init().
|
static |
Command line option: show version.
Definition at line 113 of file init.cpp.
References FULL_VERSION.
void close_modules | ( | ) |
Clean up all modules which are not disabled.
Definition at line 82 of file init.cpp.
References module_information::close, module_information::description, module_information::enabled, llevInfo, LOG(), modules, and module_information::name.
Referenced by cleanup().
|
static |
Change the 'enabled' flag of a module.
name | module's name, or 'All'. |
enabled | new value of the 'enabled' flag. |
Definition at line 302 of file init.cpp.
References module_information::enabled, fatal(), llevError, LOG(), modules, name, module_information::name, and SEE_LAST_ERROR.
Referenced by set_disable_module(), and set_enable_module().
|
static |
Frees all memory allocated to materials.
Definition at line 585 of file init.cpp.
References materials.
Referenced by free_server().
void free_server | ( | void | ) |
Frees all memory allocated around here:
Definition at line 1138 of file init.cpp.
References ServerSettings::disabled_plugins, free_materials(), free_quest(), free_races(), and serverSettings.
Referenced by cleanup().
|
static |
Creates an empty materialtype_t structure.
Definition at line 510 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().
|
static |
void init | ( | int | argc, |
char ** | argv | ||
) |
This is the main server initialization function.
Called only once, when starting the program.
argc | argument count. |
argv | arguments on the command line. |
Definition at line 1098 of file init.cpp.
References accounts_load(), add_server_collect_hooks(), cftimer_init(), commands_init(), FULL_VERSION, hiscore_init(), init_beforeplay(), init_library(), init_modules(), 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(), SRANDOM, and time.
Referenced by server_main().
|
static |
Called before the server starts listening to connections, processes various dump-related options.
Definition at line 1209 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().
void init_modules | ( | ) |
Init all modules which are not disabled.
Definition at line 66 of file init.cpp.
References module_information::description, module_information::enabled, module_information::init, llevInfo, LOG(), modules, module_information::name, serverSettings, and settings.
Referenced by init().
void init_signals | ( | void | ) |
Setup our signal handlers.
Definition at line 1325 of file init.cpp.
References rec_sighup(), and signal_shutdown().
Referenced by command_unloadplugin(), and init().
|
static |
Checks if starting the server is allowed.
Definition at line 1273 of file init.cpp.
References buf, Settings::confdir, forbid_play(), llevError, LOG(), MAX_BUF, settings, and SHUTDOWN_FILE.
Referenced by init().
|
static |
List all modules, then exit.
Definition at line 96 of file init.cpp.
References description, llevInfo, LOG(), modules, name, module_information::name, and should_exit.
|
static |
Loads the materials.
Definition at line 530 of file init.cpp.
References add_refcount(), add_string(), buf, bufferreader_next_line(), materialtype_t::description, FREE_AND_COPY_IF, get_empty_mat(), llevDebug, LOG(), materialtype_t::material, materials, materialtype_t::mod, materialtype_t::name, NROFATTACKS, and materialtype_t::save.
Referenced by add_server_collect_hooks().
|
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 597 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, motd, 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, TRUE, Settings::who_format, Settings::who_wiz_format, Settings::worldmapstartx, Settings::worldmapstarty, Settings::worldmaptilesizex, Settings::worldmaptilesizey, Settings::worldmaptilesx, and Settings::worldmaptilesy.
Referenced by init().
|
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.
argc | length of argv. |
argv | arguments. |
pass | initialization pass arguments to use. |
Definition at line 458 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().
|
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.
i | unused. |
Definition at line 1313 of file init.cpp.
References logfile, and reopen_logfile.
Referenced by init_signals().
|
static |
Dump all animations, then exit.
Definition at line 335 of file init.cpp.
References cleanup(), and dump_animations().
|
static |
Dump all bonuses (from the stat_bonus file) then exit.
Definition at line 351 of file init.cpp.
References cleanup(), and dump_stat_bonuses().
|
static |
Dump all faces, then exit.
Definition at line 343 of file init.cpp.
References cleanup(), and dump_faces().
|
static |
Definition at line 266 of file init.cpp.
References assets_pack(), and should_exit.
|
static |
Command line option: set configuration path.
path | new path. |
Definition at line 199 of file init.cpp.
References Settings::confdir, and settings.
|
static |
Change the server's port.
Will exit() if invalid value.
val | port to use. Must be a valid one, between 1 and 65535 inclusive. |
Definition at line 279 of file init.cpp.
References Settings::csport, llevError, LOG(), and settings.
Referenced by load_settings().
|
static |
Command line option: set data path.
path | new path. |
Definition at line 191 of file init.cpp.
References Settings::datadir, and settings.
|
static |
Command line option: debug flag.
Definition at line 119 of file init.cpp.
References Settings::debug, llevDebug, and settings.
|
static |
Disable a module.
name | module's name, or 'All'. |
Definition at line 320 of file init.cpp.
References do_module(), and name.
|
static |
Disable a plugin.
name | plugin's name, without extension. |
Definition at line 292 of file init.cpp.
References ServerSettings::disabled_plugins, name, and serverSettings.
|
static |
Command line option: dump monsters.
Definition at line 134 of file init.cpp.
References Settings::dumpvalues, and settings.
|
static |
Command line option: dump abilities.
Definition at line 139 of file init.cpp.
References Settings::dumpvalues, and settings.
|
static |
Command line option: dump artifacts.
Definition at line 144 of file init.cpp.
References Settings::dumpvalues, and settings.
|
static |
Command line option: dump spells.
Definition at line 149 of file init.cpp.
References Settings::dumpvalues, and settings.
|
static |
Command line option: ?
Definition at line 154 of file init.cpp.
References Settings::dumpvalues, and settings.
|
static |
Command line option: dump races.
Definition at line 159 of file init.cpp.
References Settings::dumpvalues, and settings.
|
static |
Command line option: dump alchemy.
Definition at line 164 of file init.cpp.
References Settings::dumpvalues, and settings.
|
static |
Command line option: dump gods.
Definition at line 169 of file init.cpp.
References Settings::dumpvalues, and settings.
|
static |
Command line option: dump alchemy costs.
Definition at line 174 of file init.cpp.
References Settings::dumpvalues, and settings.
|
static |
Command line option: dump monster treasures.
name | monster's name to dump treasure for. |
Definition at line 182 of file init.cpp.
References Settings::dumparg, Settings::dumpvalues, name, and settings.
|
static |
Enable a module.
name | module's name, or 'All'. |
Definition at line 328 of file init.cpp.
References do_module(), and name.
|
static |
Command line option: ignore assets errors.
Definition at line 262 of file init.cpp.
References Settings::ignore_assets_errors, and settings.
|
static |
Command line option: set local path.
path | new path. |
Definition at line 207 of file init.cpp.
References Settings::localdir, and settings.
|
static |
Command line option: set logfile name.
val | new name. |
Definition at line 108 of file init.cpp.
References Settings::logfilename, and settings.
|
static |
Command line option: set map path.
path | new path. |
Definition at line 215 of file init.cpp.
References Settings::mapdir, and settings.
|
static |
Command line option: monster debug flag.
Definition at line 129 of file init.cpp.
References Settings::debug, llevMonster, and settings.
|
static |
Command line option: set player path.
path | new path. |
Definition at line 247 of file init.cpp.
References Settings::playerdir, and settings.
|
static |
Command line option: set regions file name.
path | new name. |
Definition at line 223 of file init.cpp.
References Settings::regions, and settings.
|
static |
Command line option: set template path.
path | new path. |
Definition at line 239 of file init.cpp.
References settings, and Settings::templatedir.
|
static |
Command line option: set temporary file path.
path | new path. |
Definition at line 255 of file init.cpp.
References settings, and Settings::tmpdir.
|
static |
Command line option: set unique path.
path | new path. |
Definition at line 231 of file init.cpp.
References settings, and Settings::uniquedir.
|
static |
Signal handler that begins a normal server shutdown.
Definition at line 1296 of file init.cpp.
References shutdown_flag.
Referenced by init_signals().
|
static |
Command line option: unset debug flag.
Definition at line 124 of file init.cpp.
References Settings::debug, llevInfo, and settings.
|
static |
All built modules.
Definition at line 56 of file init.cpp.
Referenced by close_modules(), do_module(), init_modules(), and list_modules().
|
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 386 of file init.cpp.
Referenced by find_player_options(), make_doors(), and parse_args().
ServerSettings serverSettings |
Definition at line 42 of file init.cpp.
Referenced by cfcitybell_init(), citylife_init(), free_server(), init_modules(), initPlugins(), and set_disable_plugin().
|
static |
If set after command line argument parsing, then the server will exit.
Definition at line 45 of file init.cpp.
Referenced by list_modules(), parse_args(), and server_pack_assets().