Atrinik Server  4.0
Macros | Functions | Variables
init.c File Reference
#include <global.h>
#include <toolkit/packet.h>
#include <toolkit/string.h>
#include <faction.h>
#include <arch.h>
#include <artifact.h>
#include <ban.h>
#include <loader.h>
#include <player.h>
#include <object_methods.h>
#include <toolkit/clioptions.h>
#include <toolkit/curl.h>
#include <server.h>
#include <toolkit/socket_crypto.h>
#include <toolkit/path.h>
#include <resources.h>
#include <http_server.h>
#include <toolkit/signals.h>
#include <toolkit/console.h>
#include <toolkit/datetime.h>
#include <cmake.h>

Go to the source code of this file.

Macros

#define ARCHETYPE_LEVEL_UP   "level_up"
 
#define STARTUP_SCRIPT   "./server.sh"
 

Functions

static void init_beforeplay (void)
 
static void init_dynamic (void)
 
static void init_clocks (void)
 
static void init_strings (void)
 
void free_strings (void)
 
static void free_settings (void)
 
static void console_command_shutdown (const char *params)
 
static void console_command_config (const char *params)
 
static void console_command_active_objects (const char *params)
 
void cleanup (void)
 
static bool clioptions_option_unit (const char *arg, char **errmsg)
 
static bool clioptions_option_plugin_unit (const char *arg, char **errmsg)
 
static bool clioptions_option_worldmaker (const char *arg, char **errmsg)
 
static bool clioptions_option_no_console (const char *arg, char **errmsg)
 
static bool clioptions_option_version (const char *arg, char **errmsg)
 
static bool clioptions_option_port (const char *arg, char **errmsg)
 
static bool clioptions_option_port_crypto (const char *arg, char **errmsg)
 
static bool clioptions_option_libpath (const char *arg, char **errmsg)
 
static bool clioptions_option_datapath (const char *arg, char **errmsg)
 
static bool clioptions_option_mapspath (const char *arg, char **errmsg)
 
static bool clioptions_option_httppath (const char *arg, char **errmsg)
 
static bool clioptions_option_resourcespath (const char *arg, char **errmsg)
 
static bool clioptions_option_metaserver_url (const char *arg, char **errmsg)
 
static bool clioptions_option_server_host (const char *arg, char **errmsg)
 
static bool clioptions_option_server_name (const char *arg, char **errmsg)
 
static bool clioptions_option_server_desc (const char *arg, char **errmsg)
 
static bool clioptions_option_server_cert (const char *arg, char **errmsg)
 
static bool clioptions_option_server_cert_sig (const char *arg, char **errmsg)
 
static bool clioptions_option_magic_devices_level (const char *arg, char **errmsg)
 
static bool clioptions_option_item_power_factor (const char *arg, char **errmsg)
 
static bool clioptions_option_python_reload_modules (const char *arg, char **errmsg)
 
static bool clioptions_option_default_permission_groups (const char *arg, char **errmsg)
 
static bool clioptions_option_allowed_chars (const char *arg, char **errmsg)
 
static bool clioptions_option_control_allowed_ips (const char *arg, char **errmsg)
 
static bool clioptions_option_control_player (const char *arg, char **errmsg)
 
static bool clioptions_option_recycle_tmp_maps (const char *arg, char **errmsg)
 
static bool clioptions_option_http_url (const char *arg, char **errmsg)
 
static bool clioptions_option_speed (const char *arg, char **errmsg)
 
static bool clioptions_option_speed_multiplier (const char *arg, char **errmsg)
 
static bool clioptions_option_network_stack (const char *arg, char **errmsg)
 
static bool clioptions_option_http_server (const char *arg, char **errmsg)
 
static void init_library (int argc, char *argv[])
 
void init_globals (void)
 
void write_todclock (void)
 
void init (int argc, char **argv)
 

Variables

struct settings_struct settings
 
shstr_constants shstr_cons
 
int world_darkness
 
unsigned long todtick
 
char first_map_path [MAX_BUF]
 
int first_map_x
 
int first_map_y
 
static const char * clioptions_option_unit_desc
 
static const char * clioptions_option_plugin_unit_desc
 
static const char * clioptions_option_worldmaker_desc
 
static const char * clioptions_option_no_console_desc
 
static const char * clioptions_option_version_desc
 
static const char * clioptions_option_port_desc
 
static const char * clioptions_option_port_crypto_desc
 
static const char * clioptions_option_libpath_desc
 
static const char * clioptions_option_datapath_desc
 
static const char * clioptions_option_mapspath_desc
 
static const char * clioptions_option_httppath_desc
 
static const char * clioptions_option_resourcespath_desc
 
static const char * clioptions_option_metaserver_url_desc
 
static const char * clioptions_option_server_host_desc
 
static const char * clioptions_option_server_name_desc
 
static const char * clioptions_option_server_desc_desc
 
static const char * clioptions_option_server_cert_desc
 
static const char * clioptions_option_server_cert_sig_desc
 
static const char * clioptions_option_magic_devices_level_desc
 
static const char * clioptions_option_item_power_factor_desc
 
static const char * clioptions_option_python_reload_modules_desc
 
static const char * clioptions_option_default_permission_groups_desc
 
static const char * clioptions_option_allowed_chars_desc
 
static const char * clioptions_option_control_allowed_ips_desc
 
static const char * clioptions_option_control_player_desc
 
static const char * clioptions_option_recycle_tmp_maps_desc
 
static const char * clioptions_option_http_url_desc
 
static const char * clioptions_option_speed_desc
 
static const char * clioptions_option_speed_multiplier_desc
 
static const char * clioptions_option_network_stack_desc
 
static const char * clioptions_option_http_server_desc
 

Detailed Description

Server initialization.

Definition in file init.c.

Macro Definition Documentation

#define ARCHETYPE_LEVEL_UP   "level_up"

Name of the archetype to use for the level up effect.

Definition at line 76 of file init.c.

Function Documentation

void cleanup ( void  )

Free all data before exiting.

Definition at line 194 of file init.c.

static bool clioptions_option_allowed_chars ( const char *  arg,
char **  errmsg 
)
static

Definition at line 645 of file init.c.

static bool clioptions_option_control_allowed_ips ( const char *  arg,
char **  errmsg 
)
static

Definition at line 747 of file init.c.

static bool clioptions_option_control_player ( const char *  arg,
char **  errmsg 
)
static

Definition at line 763 of file init.c.

static bool clioptions_option_datapath ( const char *  arg,
char **  errmsg 
)
static

Definition at line 375 of file init.c.

static bool clioptions_option_default_permission_groups ( const char *  arg,
char **  errmsg 
)
static

Definition at line 599 of file init.c.

static bool clioptions_option_http_server ( const char *  arg,
char **  errmsg 
)
static

Definition at line 866 of file init.c.

static bool clioptions_option_http_url ( const char *  arg,
char **  errmsg 
)
static

Definition at line 796 of file init.c.

static bool clioptions_option_httppath ( const char *  arg,
char **  errmsg 
)
static

Definition at line 405 of file init.c.

static bool clioptions_option_item_power_factor ( const char *  arg,
char **  errmsg 
)
static

Definition at line 558 of file init.c.

static bool clioptions_option_libpath ( const char *  arg,
char **  errmsg 
)
static

Definition at line 361 of file init.c.

static bool clioptions_option_magic_devices_level ( const char *  arg,
char **  errmsg 
)
static

Definition at line 531 of file init.c.

static bool clioptions_option_mapspath ( const char *  arg,
char **  errmsg 
)
static

Definition at line 389 of file init.c.

static bool clioptions_option_metaserver_url ( const char *  arg,
char **  errmsg 
)
static

Definition at line 435 of file init.c.

static bool clioptions_option_network_stack ( const char *  arg,
char **  errmsg 
)
static

Definition at line 849 of file init.c.

static bool clioptions_option_no_console ( const char *  arg,
char **  errmsg 
)
static

Definition at line 282 of file init.c.

static bool clioptions_option_plugin_unit ( const char *  arg,
char **  errmsg 
)
static

Definition at line 247 of file init.c.

static bool clioptions_option_port ( const char *  arg,
char **  errmsg 
)
static

Definition at line 313 of file init.c.

static bool clioptions_option_port_crypto ( const char *  arg,
char **  errmsg 
)
static

Definition at line 337 of file init.c.

static bool clioptions_option_python_reload_modules ( const char *  arg,
char **  errmsg 
)
static

Definition at line 575 of file init.c.

static bool clioptions_option_recycle_tmp_maps ( const char *  arg,
char **  errmsg 
)
static

Definition at line 779 of file init.c.

static bool clioptions_option_resourcespath ( const char *  arg,
char **  errmsg 
)
static

Definition at line 420 of file init.c.

static bool clioptions_option_server_cert ( const char *  arg,
char **  errmsg 
)
static

Definition at line 495 of file init.c.

static bool clioptions_option_server_cert_sig ( const char *  arg,
char **  errmsg 
)
static

Definition at line 513 of file init.c.

static bool clioptions_option_server_desc ( const char *  arg,
char **  errmsg 
)
static

Definition at line 480 of file init.c.

static bool clioptions_option_server_host ( const char *  arg,
char **  errmsg 
)
static

Definition at line 451 of file init.c.

static bool clioptions_option_server_name ( const char *  arg,
char **  errmsg 
)
static

Definition at line 466 of file init.c.

static bool clioptions_option_speed ( const char *  arg,
char **  errmsg 
)
static

Definition at line 811 of file init.c.

static bool clioptions_option_speed_multiplier ( const char *  arg,
char **  errmsg 
)
static

Definition at line 830 of file init.c.

static bool clioptions_option_unit ( const char *  arg,
char **  errmsg 
)
static

Definition at line 232 of file init.c.

static bool clioptions_option_version ( const char *  arg,
char **  errmsg 
)
static

Definition at line 296 of file init.c.

static bool clioptions_option_worldmaker ( const char *  arg,
char **  errmsg 
)
static

Definition at line 267 of file init.c.

static void console_command_active_objects ( const char *  params)
static

Dump the active objects list, or just the number of objects on the list.

Parameters
paramsParameters from the console.

Definition at line 173 of file init.c.

static void free_settings ( void  )
static

Free the server settings.

Definition at line 119 of file init.c.

void free_strings ( void  )

Free the string constants.

Definition at line 104 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
argcLength of argv.
argvArguments.

Definition at line 1215 of file init.c.

static void init_beforeplay ( void  )
static

Initialize before playing.

Definition at line 1242 of file init.c.

static void init_clocks ( void  )
static

Initializes the gametime and TOD counters.

Called by init_library().

Definition at line 1179 of file init.c.

static void init_dynamic ( void  )
static

Initializes first_map_path from the archetype collection.

Definition at line 1137 of file init.c.

void init_globals ( void  )

Initializes all global variables. Might use environment variables as default for some of them.

Definition at line 1116 of file init.c.

static void init_library ( int  argc,
char *  argv[] 
)
static

It is vital that init_library() is called by any functions using this library.

If you want to lessen the size of the program using the library, you can replace the call to init_library() with init_globals() and init_function_pointers(). Good idea to also call init_vars() and init_hash_table() if you are doing any object loading.

Definition at line 890 of file init.c.

static void init_strings ( void  )
static

Initialize the shstr_cons structure.

Definition at line 85 of file init.c.

void write_todclock ( void  )

Write out the current time to a file so time does not reset every time the server reboots.

Definition at line 1158 of file init.c.

Variable Documentation

const char* clioptions_option_allowed_chars_desc
static
Initial value:
=
"Sets limits for allowed characters in account names/passwords, character "
"names, and their maximum length.\n\n"
"!!! DO NOT CHANGE FROM THE DEFAULTS UNLESS YOU ARE ABSOLUTELY SURE OF THE "
"CONSEQUENCES !!!\n\n"
"Removing characters from the sets will make players using the characters "
"unable to log in.\n\n"
"Adding special characters to account/character name limitations could pose "
"a security risk depending on the file-system you're using (eg, dots and "
"slashes or colons on Windows)."
"The syntax is:\n"
"<limit name>:<min>-<max> [characters] [characters2] ...\n\n"
"For example:\n"
"charname:4-20 [:alphaupper:] [:alphalower:] [:numeric:] [:space:] ['-]\n\n"
"The above sets the following rules for character names:\n"
" - Length must be at least four"
" - Length must be no more than twenty"
" - Characters may contain upper/lower-case letters, digits, spaces, "
"single-quotes and dashes.\n\n"
"The recognized values for the 'limit name' are: account, charname and "
"password\n"
"The special syntax allowed in the characters list expands to:\n"
" - :alphalower: All lower-case letters in ASCII\n"
" - :alphaupper: All upper-case letters in ASCII\n"
" - :numeric: All digits\n"
" - :print: All printable characters (does not include whitespace)\n"
" - :space: Space (you can't use a regular space in the list since spaces are "
"used to separate the entries)"

Description of the –allowed_chars command.

Definition at line 615 of file init.c.

const char* clioptions_option_control_allowed_ips_desc
static
Initial value:
=
"Comma-separated list of IPs that are allowed to send special control-related "
"commands to the server."

Description of the –control_allowed_ips command.

Definition at line 742 of file init.c.

const char* clioptions_option_control_player_desc
static
Initial value:
=
"Player name that will be used to perform specific control-related operations "
"if none is supplied in the control commands sent to the server.\n\n"
"The first player is used if this option is not specified."

Description of the –control_player command.

Definition at line 757 of file init.c.

const char* clioptions_option_datapath_desc
static
Initial value:
=
"Where to read and write player data, unique maps, etc."

Description of the –datapath command.

Definition at line 371 of file init.c.

const char* clioptions_option_default_permission_groups_desc
static
Initial value:
=
"Comma-delimited list of permission groups that every player will be "
"able to access, eg, '[MOD],[DEV]'. 'None' is the same as not using "
"the option in the first place, ie, no default permission groups."

Description of the –default_permission_groups command.

Definition at line 593 of file init.c.

const char* clioptions_option_http_server_desc
static
Initial value:
=
"Enables/disables the bundled HTTP server, which is required in order to "
"connect to the server (by most clients). Refer to the README file for "
"information related to running your own HTTP server instead of the bundled "
"one."

Description of the –http_server command.

Definition at line 859 of file init.c.

const char* clioptions_option_http_url_desc
static
Initial value:
=
"Specifies the URL to use for data HTTP requests. The files under the "
"directory specified by --httppath must be reachable using this URL.\n\n"
"If this URL is incorrect or inaccessible from the public network, clients "
"will be unable to connect to the server."

Description of the –http_url command.

Definition at line 789 of file init.c.

const char* clioptions_option_httppath_desc
static
Initial value:
=
"Where the HTTP server data files reside.\n\n"
"The server must have read/write access to this directory, as it will create "
"files inside it."

Description of the –httppath command.

Definition at line 399 of file init.c.

const char* clioptions_option_item_power_factor_desc
static
Initial value:
=
"Item power factor is the relation of how the player's equipped item_power "
"total relates to their overall level. If 1.0, then sum of the character's "
"equipped item's item_power can not be greater than their overall level. "
"If 2.0, then that sum can not exceed twice the character's overall level. "
"By setting this to a high enough value, you can effectively disable "
"the item_power code."

Description of the –item_power_factor command.

Definition at line 549 of file init.c.

const char* clioptions_option_libpath_desc
static
Initial value:
=
"Where the read-only files such as the collected treasures, artifacts,"
"archetypes etc reside."

Description of the –libpath command.

Definition at line 356 of file init.c.

const char* clioptions_option_magic_devices_level_desc
static
Initial value:
=
"Adjustment to maximum magical device level the player may use."

Description of the –magic_devices_level command.

Definition at line 527 of file init.c.

const char* clioptions_option_mapspath_desc
static
Initial value:
=
"Where the maps, Python scripts, etc reside."

Description of the –mapspath command.

Definition at line 385 of file init.c.

const char* clioptions_option_metaserver_url_desc
static
Initial value:
=
"URL of the metaserver. The server will send POST requests to this URL to "
"update the metaserver data."

Description of the –metaserver_url command.

Definition at line 430 of file init.c.

const char* clioptions_option_network_stack_desc
static
Initial value:
=
"Selects the network stack to use. This is a comma-separated list of address "
"families to listen on, for example: ipv4, ipv6\n\n"
"It is also possible to specify IP addresses to bind to, for example: "
"ipv4=127.0.0.1, ipv6=::1\n\n"
"A value of 'dual' can be used to enable dual-stack IPv6 system with IPv4 "
"tunneling (this may not be supported on all systems)."

Description of the –network_stack command.

Definition at line 840 of file init.c.

const char* clioptions_option_no_console_desc
static
Initial value:
=
"Disables the interactive console. Useful when debugging or "
"running the server non-interactively."

Description of the –no_console command.

Definition at line 277 of file init.c.

const char* clioptions_option_plugin_unit_desc
static
Initial value:
=
"Runs the plugin unit tests. Resulting XMLs will be stored in "
"'tests/unit/plugins/**/*.xml'."

Description of the –plugin_unit command.

Definition at line 242 of file init.c.

const char* clioptions_option_port_crypto_desc
static
Initial value:
=
"Sets the port to use for crypto server/client communication. Set to zero to "
"disable."

Description of the –port_crypto command.

Definition at line 332 of file init.c.

const char* clioptions_option_port_desc
static
Initial value:
=
"Sets the port to use for server/client communication. Set to zero to disable."

Description of the –port command.

Definition at line 309 of file init.c.

const char* clioptions_option_python_reload_modules_desc
static
Initial value:
=
"Whether to reload Python user modules (eg Interface.py and the like) "
"each time a Python script executes. If enabled, executing scripts will "
"be slower, but allows for easy development of modules. This should not "
"be enabled on production servers."

Description of the –python_reload_modules command.

Definition at line 568 of file init.c.

const char* clioptions_option_recycle_tmp_maps_desc
static
Initial value:
=
"If set, will preserve temporary maps across restarts.\n\n"
"This effectively means the state of maps (eg, items dropped on the ground) is "
"preserved across server restarts."

Description of the –recycle_tmp_maps command.

Definition at line 773 of file init.c.

const char* clioptions_option_resourcespath_desc
static
Initial value:
=
"Where the resource data files reside.\n\n"
"The server must have read access to this directory."

Description of the –resourcespath command.

Definition at line 415 of file init.c.

const char* clioptions_option_server_cert_desc
static
Initial value:
=
"Server certificate, in the format specified by ADS-7. Void unless signed by "
"the Atrinik staff."

Description of the –server_cert command.

Definition at line 490 of file init.c.

const char* clioptions_option_server_cert_sig_desc
static
Initial value:
=
"Signature of the server certificate, as provided by the Atrinik staff."

Description of the –server_cert_sig command.

Definition at line 509 of file init.c.

const char* clioptions_option_server_desc_desc
static
Initial value:
=
"Description of the server. This should describe the server to players."

Description of the –server_desc command.

Definition at line 476 of file init.c.

const char* clioptions_option_server_host_desc
static
Initial value:
=
"Hostname of the server. If set, the server will send regular updates to the "
"metaserver (using the URL specified with --metaserver_url).\n\n"
"Updates will be refused if the hostname does not resolve to the incoming IP."

Description of the –server_host command.

Definition at line 445 of file init.c.

const char* clioptions_option_server_name_desc
static
Initial value:
=
"Name of the server. This is how the server will be named in the list of "
"servers (the metaserver)"

Description of the –server_name command.

Definition at line 461 of file init.c.

const char* clioptions_option_speed_desc
static
Initial value:
=
"Specifies the number of microseconds each tick lasts for, eg, a value of "
"125000 results in an effective server tick rate of 8 ticks per second."

Description of the –speed command.

Definition at line 806 of file init.c.

const char* clioptions_option_speed_multiplier_desc
static
Initial value:
=
"This command is used to increase the server processing speed, without "
"affecting the effective game tick-rate. This means the server will be able "
"to send out priority packets with slightly less delay, possibly improving "
"network latency.\n\n"
"For example, a value of two doubles the amount of processing, three triples "
"it and so on."

Description of the –speed_multiplier command.

Definition at line 821 of file init.c.

const char* clioptions_option_unit_desc
static
Initial value:
=
"Runs the unit tests. Resulting logs will be stored in 'tests/**/*.out', with "
"XML results in 'tests/**/*.xml'."

Description of the –unit command.

Definition at line 227 of file init.c.

const char* clioptions_option_version_desc
static
Initial value:
=
"Displays the server version and exits."

Description of the –version command.

Definition at line 292 of file init.c.

const char* clioptions_option_worldmaker_desc
static
Initial value:
=
"Generates the region maps using the world maker module.\n\n"
"This should be done before starting up production servers."

Description of the –worldmaker command.

Definition at line 262 of file init.c.

char first_map_path[MAX_BUF]

The starting map.

Definition at line 67 of file init.c.

int first_map_x

Enter X coordinate on the starting map.

Definition at line 70 of file init.c.

int first_map_y

Enter Y coordinate on the starting map.

Definition at line 73 of file init.c.

struct settings_struct settings

The server's settings.

Definition at line 55 of file init.c.

shstr_constants shstr_cons

The shared constants.

Definition at line 58 of file init.c.

unsigned long todtick

Time of day tick.

Definition at line 64 of file init.c.

int world_darkness

World's darkness value.

Definition at line 61 of file init.c.