Crossfire Server, Trunk
|
#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 |
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_t * | get_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 |
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 1075 of file init.cpp.
References Settings::add_hook(), load_materials(), load_races(), and settings.
Referenced by init(), and ResourcesManager::load().
|
static |
Command line option: show version.
Definition at line 111 of file init.cpp.
References FULL_VERSION.
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().
|
static |
Change the 'enabled' flag of a module.
name | module's name, or 'All'. |
enabled | new value of the 'enabled' flag. |
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().
|
static |
Frees all memory allocated to materials.
Definition at line 574 of file init.cpp.
References materials.
Referenced by free_server().
void free_server | ( | void | ) |
Frees all memory allocated around here:
Definition at line 1127 of file init.cpp.
References Settings::disabled_plugins, free_materials(), free_quest(), free_races(), and settings.
Referenced by cleanup().
|
static |
Creates an empty materialtype_t structure.
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().
|
static |
Display the command line options and exits.
Definition at line 1138 of file init.cpp.
Referenced by ChangesDock::ChangesDock(), CREMainWindow::createMenus(), and ChangesDock::helpReady().
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 1087 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(), and SRANDOM.
Referenced by nlohmann::basic_json::basic_json(), nlohmann::basic_json::binary(), main(), nlohmann::basic_json::operator+=(), nlohmann::ordered_map< Key, T, IgnoredLess, Allocator >::ordered_map(), nlohmann::basic_json::push_back(), server_main(), setup(), and START_TEST().
|
static |
Called before the server starts listening to connections, processes various dump-related options.
Definition at line 1198 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 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().
void init_signals | ( | void | ) |
Setup our signal handlers.
Definition at line 1314 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 1262 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 94 of file init.cpp.
References llevInfo, LOG(), modules, give::name, module_information::name, and should_exit.
|
static |
Loads the materials.
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().
|
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().
|
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 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().
|
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 1302 of file init.cpp.
References logfile, reopen_logfile, and nlohmann::detail::void().
Referenced by init_signals().
|
static |
Dump all animations, then exit.
Definition at line 333 of file init.cpp.
References cleanup(), and dump_animations().
|
static |
Dump all faces, then exit.
Definition at line 341 of file init.cpp.
References cleanup(), and dump_faces().
|
static |
Definition at line 264 of file init.cpp.
References assets_pack(), npc_dialog::filename, and should_exit.
|
static |
Command line option: set configuration path.
path | new path. |
Definition at line 197 of file init.cpp.
References Settings::confdir, python_init::path, 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 277 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 189 of file init.cpp.
References Settings::datadir, python_init::path, and settings.
|
static |
Command line option: debug flag.
Definition at line 117 of file init.cpp.
References Settings::debug, llevDebug, and settings.
|
static |
Disable a module.
name | module's name, or 'All'. |
Definition at line 318 of file init.cpp.
References do_module(), and give::name.
|
static |
Disable a plugin.
name | plugin's name, without extension. |
Definition at line 290 of file init.cpp.
References Settings::disabled_plugins, give::name, and settings.
|
static |
Command line option: dump monsters.
Definition at line 132 of file init.cpp.
References Settings::dumpvalues, and settings.
|
static |
Command line option: dump abilities.
Definition at line 137 of file init.cpp.
References Settings::dumpvalues, and settings.
|
static |
Command line option: dump artifacts.
Definition at line 142 of file init.cpp.
References Settings::dumpvalues, and settings.
|
static |
Command line option: dump spells.
Definition at line 147 of file init.cpp.
References Settings::dumpvalues, and settings.
|
static |
Command line option: ?
Definition at line 152 of file init.cpp.
References Settings::dumpvalues, and settings.
|
static |
Command line option: dump races.
Definition at line 157 of file init.cpp.
References Settings::dumpvalues, and settings.
|
static |
Command line option: dump alchemy.
Definition at line 162 of file init.cpp.
References Settings::dumpvalues, and settings.
|
static |
Command line option: dump gods.
Definition at line 167 of file init.cpp.
References Settings::dumpvalues, and settings.
|
static |
Command line option: dump alchemy costs.
Definition at line 172 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 180 of file init.cpp.
References Settings::dumparg, Settings::dumpvalues, give::name, and settings.
|
static |
Enable a module.
name | module's name, or 'All'. |
Definition at line 326 of file init.cpp.
References do_module(), and give::name.
|
static |
Command line option: ignore assets errors.
Definition at line 260 of file init.cpp.
References Settings::ignore_assets_errors, and settings.
|
static |
Command line option: set local path.
path | new path. |
Definition at line 205 of file init.cpp.
References Settings::localdir, python_init::path, and settings.
|
static |
Command line option: set logfile name.
val | new name. |
Definition at line 106 of file init.cpp.
References Settings::logfilename, and settings.
|
static |
Command line option: set map path.
path | new path. |
Definition at line 213 of file init.cpp.
References Settings::mapdir, python_init::path, and settings.
|
static |
Command line option: monster debug flag.
Definition at line 127 of file init.cpp.
References Settings::debug, llevMonster, and settings.
|
static |
Command line option: set player path.
path | new path. |
Definition at line 245 of file init.cpp.
References python_init::path, Settings::playerdir, and settings.
|
static |
Command line option: set regions file name.
path | new name. |
Definition at line 221 of file init.cpp.
References python_init::path, Settings::regions, and settings.
|
static |
Command line option: set template path.
path | new path. |
Definition at line 237 of file init.cpp.
References python_init::path, settings, and Settings::templatedir.
|
static |
Command line option: set temporary file path.
path | new path. |
Definition at line 253 of file init.cpp.
References python_init::path, settings, and Settings::tmpdir.
|
static |
Command line option: set unique path.
path | new path. |
Definition at line 229 of file init.cpp.
References python_init::path, settings, and Settings::uniquedir.
|
static |
Signal handler that begins a normal server shutdown.
Definition at line 1285 of file init.cpp.
References shutdown_flag, and nlohmann::detail::void().
Referenced by init_signals().
|
static |
Command line option: unset debug flag.
Definition at line 122 of file init.cpp.
References Settings::debug, llevInfo, and settings.
|
static |
All built modules.
Definition at line 54 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 376 of file init.cpp.
Referenced by find_player_options(), make_doors(), and parse_args().
|
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().