Crossfire Server, Trunk
|
#include "global.h"
#include <assert.h>
#include <ctype.h>
#include <fcntl.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "object.h"
#include "path.h"
#include "random_maps/random_map.h"
#include "random_maps/rproto.h"
#include "sproto.h"
#include "tod.h"
#include "version.h"
#include "server.h"
Go to the source code of this file.
Macros | |
#define | PORTAL_DESTINATION_NAME "Town portal destination" /* this one should really be in a header file */ |
#define | SPEED_DEBUG |
Functions | |
bool | check_password (const char *typed, const char *crypted) |
static bool | check_shutdown (void) |
static char * | clean_path (const char *file, char *newpath, int size) |
void | clean_tmp_files (void) |
void | cleanup (void) |
static char const * | crypt_string (char const *str, char const *salt) |
static void | do_follow (player *pl) |
static void | do_shutdown (void) |
static void | do_specials (void) |
void | enter_exit (object *op, object *exit_ob) |
static void | enter_fixed_template_map (object *pl, object *exit_ob) |
static void | enter_map (object *op, mapstruct *newmap, int x, int y) |
void | enter_player_maplevel (object *op) |
void | enter_player_savebed (object *op) |
static void | enter_random_map (object *pl, object *exit_ob) |
static void | enter_random_template_map (object *pl, object *exit_ob) |
static void | enter_unique_map (object *op, object *exit_ob) |
int | forbid_play (void) |
void | leave (player *pl, int draw_exit) |
void | login_check_shutdown (object *const op) |
static int | move_towards (object *ob, object *towards, unsigned int mindist) |
char const * | newhash (char const *password) |
static bool | object_in_icecube (object *op) |
static bool | object_on_exit (object *ob, object *exit) |
void | player_map_change_common (object *op, mapstruct *const oldmap, mapstruct *const newmap) |
void | process_events (void) |
static void | process_players1 (void) |
static void | process_players2 (void) |
static void | save_and_kick_all_players (void) |
void | server_main (int argc, char *argv[]) |
void | set_map_timeout (mapstruct *oldmap) |
static char * | unclean_path (const char *src, char *newpath, int size) |
Variables | |
static const char * | days [] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"} |
volatile sig_atomic_t | shutdown_flag |
static const int | shutdown_warn_times [] = {120, 90, 60, 45, 30, 15, 10, 5, 4, 3, 2, 1} |
Main server functions.
Definition in file server.cpp.
#define PORTAL_DESTINATION_NAME "Town portal destination" /* this one should really be in a header file */ |
#define SPEED_DEBUG |
Definition at line 1069 of file server.cpp.
bool check_password | ( | const char * | typed, |
const char * | crypted | ||
) |
Hash a password and compare it to the stored version.
typed | Password entered by the user (not hashed). |
crypted | Stored password to check against (hashed). |
Definition at line 114 of file server.cpp.
References crypt_string(), llevError, and LOG().
Referenced by account_change_password(), account_login(), check_login(), receive_player_password(), and verify_player().
|
static |
Check if we're ready to shut the server down.
Definition at line 1426 of file server.cpp.
References count_players(), draw_ext_info_format(), llevInfo, LOG(), MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM, NDI_ALL, NDI_UNIQUE, shutdown_s::next_warn, shutdown_flag, SHUTDOWN_IDLE, SHUTDOWN_NONE, shutdown_state, SHUTDOWN_TIME, shutdown_warn_times, shutdown_s::time, and shutdown_s::type.
Referenced by do_specials().
|
static |
Takes a path and replaces all / with _ We do a strcpy so that we do not change the original string.
file | path to clean. |
newpath | buffer that will contain the cleaned path. Should be at least as long as file. |
size | length of newpath. |
Definition at line 322 of file server.cpp.
References mad_mage_user::file, and strlcpy().
Referenced by enter_unique_map().
void clean_tmp_files | ( | void | ) |
Save unique maps and clean up temporary map files unless recycling temporary maps. The function name is somewhat misleading.
Definition at line 1226 of file server.cpp.
References clean_tmp_map(), first_map, m, MAP_IN_MEMORY, give::next, Settings::recycle_tmp_maps, save_map(), SAVE_MODE_NORMAL, settings, swap_map(), and write_todclock().
Referenced by cleanup().
void cleanup | ( | void | ) |
Clean up everything and exit.
Definition at line 1252 of file server.cpp.
References accounts_save(), clean_tmp_files(), cleanupPlugins(), close_modules(), commands_clear(), free_all_artifacts(), free_all_god(), free_all_maps(), free_all_newserver(), free_all_readable(), free_all_recipes(), free_globals(), free_knowledge(), free_loader(), free_quest(), free_quest_definitions(), free_server(), free_style_maps(), i18n_free(), llevInfo, LOG(), metaserver2_exit(), object_free_all_data(), and write_book_archive().
Referenced by CREMainWindow::closeEvent(), do_shutdown(), init_beforeplay(), make_doors(), parse_args(), server_dump_animations(), and server_dump_faces().
|
static |
Encrypt a string. Used for password storage on disk.
Really, there is no reason to crypt the passwords any system. But easier to just leave this enabled for backward compatibility. Put the simple case at top - no encryption - makes it easier to read.
str | string to crypt. |
salt | salt to crypt with. |
Definition at line 70 of file server.cpp.
References c, Settings::crypt_mode, make_face_from_files::int, RANDOM, settings, and make_face_from_files::str.
Referenced by check_password(), and newhash().
|
static |
Called from process_players1() to move a player who is following someone.
This is a DM, just teleport on the top of player.
Definition at line 910 of file server.cpp.
References can_follow(), object::contr, rv_vector::distance, draw_ext_info_format(), enter_exit(), find_player_partial_name(), FLAG_WIZ, FREE_AND_CLEAR_STR, freearr_x, freearr_y, get_rangevector(), player::last_exit, object::map, map_newmap_cmd(), move_towards(), MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_FAILURE, NDI_UNIQUE, player::ob, object_find_free_spot(), object_insert_in_map_at(), object_on_exit(), object_remove(), altar_valkyrie::pl, player_update_bg_music(), query_flag(), object::x, and object::y.
Referenced by process_players1().
|
static |
Definition at line 1414 of file server.cpp.
References cleanup(), draw_ext_info(), MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM, NDI_ALL, NDI_UNIQUE, and save_and_kick_all_players().
Referenced by do_specials().
|
static |
Collection of functions to call from time to time.
Modified 2000-1-14 MSW to use the global pticks count to determine how often to do things. This will allow us to spred them out more often. I use prime numbers for the factor count - in that way, it is less likely these actions will fall on the same tick (compared to say using 500/2500/15000 which would mean on that 15,000 tick count a whole bunch of stuff gets done). Of course, there can still be times where multiple specials are done on the same tick, but that will happen very infrequently
I also think this code makes it easier to see how often we really are doing the various things.
Definition at line 1519 of file server.cpp.
References accounts_save(), check_shutdown(), clean_friendly_list(), CS_LOGTIME, cst_lst, do_shutdown(), fix_luck(), fix_weight(), flush_old_maps(), knowledge_process_incremental(), metaserver_update(), party_obsolete_parties(), pticks, PTICKS_PER_CLOCK, tick_the_clock(), CS_Stats::time_start, watchdog(), write_book_archive(), and write_cs_stats().
Referenced by server_main().
Tries to move 'op' to exit_ob.
Largely redone by MSW 2001-01-21 - this function was overly complex and had some obscure bugs.
May call abort() in some situations.
op | character or monster that is using the exit. |
exit_ob | exit object (boat, door, teleporter, etc.) |
Definition at line 727 of file server.cpp.
References AP_UNAPPLY, object::attacktype, buf, living::dam, draw_ext_info_format(), enter_fixed_template_map(), enter_map(), enter_random_map(), enter_random_template_map(), enter_unique_map(), EXIT_PATH, EXIT_X, EXIT_Y, FLAG_DAMNED, FLAG_UNIQUE, FLAG_UNPAID, FOR_OB_AND_BELOW_FINISH, FOR_OB_AND_BELOW_PREPARE, FORCE, FREE_OBJ_NO_DESTROY_CALLBACK, hit_player(), HUGE_BUF, llevDebug, LOG(), object::map, MAP_ENTER_X, MAP_ENTER_Y, map_path_unique(), MAP_PLAYER_UNIQUE, MAX_BUF, object::msg, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_FAILURE, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, object::name, NDI_UNIQUE, ob_apply(), ob_describe(), object_copy(), object_find_by_type_and_slaying(), object_free(), object_new(), object_remove(), object_update_speed(), give::op, mapstruct::path, path_combine_and_normalize(), PLAYER, PORTAL_DESTINATION_NAME, QUERY_FLAG, ready_map_name(), save_player(), SP_WORD_OF_RECALL, object::speed, object::stats, object::subtype, Ice::tmp, diamondslots::x, and diamondslots::y.
Referenced by command_reset(), command_summon(), command_teleport(), create_player_cmd(), do_follow(), do_goto(), enter_player_savebed(), execute_word_of_recall(), exit_type_apply(), exit_type_move_on(), key_change_class(), move_teleporter(), player_arrest(), and player_changer_type_process().
The player is trying to enter a non-randomly generated template map. In this case, use a map file for a template.
pl | player. |
exit_ob | exit containing template map parameters. |
Definition at line 448 of file server.cpp.
References create_pathname(), create_template_pathname(), draw_ext_info_format(), enter_map(), EXIT_PATH, EXIT_X, EXIT_Y, HUGE_BUF, mapstruct::is_template, llevError, LOG(), object::map, MAP_PLAYER_UNIQUE, mapfile_load(), MAX_BUF, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_FAILURE, mapstruct::name, object::name, NDI_UNIQUE, python_init::path, mapstruct::path, path_combine_and_normalize(), altar_valkyrie::pl, ready_map_name(), replace(), strlcpy(), object::x, and object::y.
Referenced by enter_exit().
Moves the player and pets from current map (if any) to new map.
op | player to move. |
newmap | |
x | |
y | new location. If (x, y) point to an out of map point, will use default map coordinates. |
Definition at line 183 of file server.cpp.
References draw_ext_info(), find_dir_2(), FLAG_REMOVED, freearr_x, freearr_y, INS_NO_WALK_ON, llevError, llevInfo, LOG(), MAP_ENTER_X, MAP_ENTER_Y, MAP_HEIGHT, map_newmap_cmd(), MAP_WIDTH, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_FAILURE, NDI_UNIQUE, ob_blocked(), object_find_free_spot(), object_free_drop_inventory(), object_insert_in_map_at(), object_remove(), object_set_enemy(), give::op, out_of_map(), mapstruct::path, pets_attempt_follow(), PLAYER, player_map_change_common(), QUERY_FLAG, range_golem, remove_friendly_object(), safe_strncpy, SIZEOFFREE, SIZEOFFREE1, SIZEOFFREE2, diamondslots::x, and diamondslots::y.
Referenced by enter_exit(), enter_fixed_template_map(), enter_player_maplevel(), enter_random_map(), enter_random_template_map(), and enter_unique_map().
void enter_player_maplevel | ( | object * | op | ) |
Move a player to its stored map level. This function is used to place the player just after logging in. Since the map may no longer exist, dump the player to an alternative 'emergency' location if that's the case.
Definition at line 682 of file server.cpp.
References draw_ext_info_format(), Settings::emergency_mapname, Settings::emergency_x, Settings::emergency_y, enter_map(), flags, llevError, LOG(), MAP_ENTER_X, MAP_ENTER_Y, MSG_TYPE_MISC, NDI_UNIQUE, give::op, PLAYER, ready_map_name(), settings, diamondslots::x, and diamondslots::y.
Referenced by check_login(), and set_first_map().
void enter_player_savebed | ( | object * | op | ) |
This is a basic little function to put the player back to his savebed. We do some error checking - its possible that the savebed map may no longer exist, so we make sure the player goes someplace.
op | player. |
Definition at line 142 of file server.cpp.
References add_string(), Settings::emergency_mapname, Settings::emergency_x, Settings::emergency_y, enter_exit(), EXIT_PATH, EXIT_X, EXIT_Y, FREE_OBJ_NO_DESTROY_CALLBACK, free_string(), llevDebug, LOG(), MAX_BUF, object_free(), object_new(), give::op, mapstruct::path, safe_strncpy, settings, and Ice::tmp.
Referenced by kill_player_not_permadeath(), and save_life().
The player is trying to enter a randomly generated map. In this case, generate the random map as needed.
pl | player. |
exit_ob | exit containing random map parameters. |
Definition at line 375 of file server.cpp.
References add_string(), buf, enter_map(), EXIT_PATH, EXIT_X, EXIT_Y, RMParms::final_map, generate_random_map(), get_region_by_map(), HUGE_BUF, RMParms::link_source_map, object::map, MAP_ENTER_X, MAP_ENTER_Y, object::msg, RMParms::origin_map, RMParms::origin_x, RMParms::origin_y, mapstruct::path, altar_valkyrie::pl, RMParms::region, mapstruct::reset_group, safe_strncpy, set_random_map_variable(), strlcpy(), diamondslots::x, object::x, RMParms::Xsize, diamondslots::y, object::y, and RMParms::Ysize.
Referenced by enter_exit().
The player is trying to enter a randomly generated template map. In this case, generate the map as needed.
pl | player. |
exit_ob | exit containing random template map parameters. |
Definition at line 539 of file server.cpp.
References create_template_pathname(), enter_map(), EXIT_PATH, EXIT_X, EXIT_Y, generate_random_map(), get_region_by_map(), HUGE_BUF, mapstruct::is_template, object::map, MAP_ENTER_X, MAP_ENTER_Y, MAP_PLAYER_UNIQUE, MAX_BUF, object::msg, mapstruct::name, RMParms::origin_map, RMParms::origin_x, RMParms::origin_y, mapstruct::path, path_combine_and_normalize(), altar_valkyrie::pl, ready_map_name(), RMParms::region, replace(), mapstruct::reset_group, safe_strncpy, set_random_map_variable(), strlcpy(), diamondslots::x, object::x, RMParms::Xsize, diamondslots::y, object::y, and RMParms::Ysize.
Referenced by enter_exit().
Player is entering a unique map.
op | player. |
exit_ob | exit containing unique map information. |
Definition at line 607 of file server.cpp.
References apply_auto_fix(), clean_path(), draw_ext_info_format(), enter_map(), EXIT_PATH, EXIT_X, EXIT_Y, HUGE_BUF, llevDebug, LOG(), object::map, MAP_PLAYER_UNIQUE, mapfile_load(), MAX_BUF, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_FAILURE, object::name, NDI_UNIQUE, give::op, python_init::path, mapstruct::path, path_combine_and_normalize(), ready_map_name(), strlcpy(), unclean_path(), mapstruct::unique, object::x, and object::y.
Referenced by enter_exit().
int forbid_play | ( | void | ) |
Checks if server should be started.
Definition at line 1359 of file server.cpp.
References buf, Settings::confdir, days, llevDebug, LOG(), logfile, MAX_BUF, PERM_FILE, settings, and roll-o-matic::stop().
Referenced by init_startup().
void leave | ( | player * | pl, |
int | draw_exit | ||
) |
Player logs out, or was disconnected.
pl | player. |
draw_exit | if set, display leaving message to other players. |
Definition at line 1298 of file server.cpp.
References DEAD_OBJECT, draw_ext_info_format(), FLAG_REMOVED, FLAG_WIZ, hiscore_check(), llevInfo, LOG(), MAP_IN_MEMORY, MAP_TIMEOUT, MAX_BUF, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_PLAYER, give::name, NDI_ALL, NDI_DK_ORANGE, NDI_UNIQUE, Ns_Dead, object_remove(), party_leave(), pets_terminate_all(), altar_valkyrie::pl, QUERY_FLAG, query_name(), ST_CONFIRM_PASSWORD, ST_GET_NAME, and ST_GET_PASSWORD.
Referenced by check_login(), do_server(), receive_play_again(), save_and_kick_all_players(), and shop_mat_type_move_on().
void login_check_shutdown | ( | object *const | op | ) |
Warn op if a server shutdown is scheduled. Used to inform players about scheduled shutdowns when they log in.
Definition at line 1483 of file server.cpp.
References draw_ext_info_format(), MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM, NDI_UNIQUE, give::op, SHUTDOWN_IDLE, SHUTDOWN_NONE, shutdown_state, SHUTDOWN_TIME, shutdown_warn_times, shutdown_s::time, and shutdown_s::type.
Referenced by check_login().
Move 'ob' in the direction of 'towards' (without any pathfinding) if the two objects are farther than 'mindist' apart. Used to implement do_follow().
Definition at line 886 of file server.cpp.
References rv_vector::direction, rv_vector::distance, get_rangevector(), move_player(), and guildjoin::ob.
Referenced by do_follow().
char const* newhash | ( | char const * | password | ) |
Definition at line 101 of file server.cpp.
References crypt_string().
Referenced by account_change_password(), account_new(), create_player_cmd(), and receive_player_password().
|
static |
Definition at line 1071 of file server.cpp.
References give::op.
Referenced by process_events().
Return true if the player object is on the given exit. This is required because some multi-tile exits are unpassable from a certain direction.
Definition at line 899 of file server.cpp.
References guildjoin::ob, object_get_multi_size(), diamondslots::x, object::x, diamondslots::y, and object::y.
Referenced by do_follow().
Definition at line 282 of file server.cpp.
References EVENT_MAPENTER, EVENT_MAPLEAVE, events_execute_global_event(), give::op, player_update_bg_music(), mapstruct::players, set_map_timeout(), and mapstruct::timeout.
Referenced by enter_map(), and move_player_attack().
void process_events | ( | void | ) |
Process all active objects.
Definition at line 1078 of file server.cpp.
References object::active_next, active_objects, object::active_prev, animate_object(), Settings::casting_time, FABS, FLAG_FREED, FLAG_REMOVED, FREE_OBJ_NO_DESTROY_CALLBACK, llevError, LOG(), MAP, MAP_IN_MEMORY, MONSTER, object_dump(), object_free(), object_in_icecube(), object_update_speed(), object_was_destroyed, give::op, PLAYER, process_object(), process_players1(), process_players2(), QUERY_FLAG, settings, stringbuffer_finish(), stringbuffer_new(), CFweardisguise::tag, and TRUE.
Referenced by server_main(), and START_TEST().
|
static |
Do all player-related stuff before objects have been updated.
Definition at line 956 of file server.cpp.
References AUTOSAVE, Settings::casting_time, do_follow(), do_some_living(), first_player, FLAG_REMOVED, get_map_flags(), handle_newcs_player(), hiscore_check(), P_NO_CLERIC, altar_valkyrie::pl, pticks, QUERY_FLAG, save_player(), settings, ST_PLAYING, and TRUE.
Referenced by process_events().
|
static |
Do all player-related stuff after objects have been updated.
Definition at line 1048 of file server.cpp.
References first_player, and altar_valkyrie::pl.
Referenced by process_events().
|
static |
Definition at line 1404 of file server.cpp.
References final_free_player(), first_player, leave(), altar_valkyrie::pl, and save_player().
Referenced by do_shutdown().
void server_main | ( | int | argc, |
char * | argv[] | ||
) |
Server main function.
argc | length of argv. |
argv | command-line options. |
Definition at line 1574 of file server.cpp.
References bRunning, cftimer_process_timers(), check_active_maps(), do_server(), do_specials(), EVENT_CLOCK, events_execute_global_event(), init(), initPlugins(), llevInfo, LOG(), nroferrors, process_events(), PROFILE_BEGIN, PROFILE_END, tick_game_time(), TRUE, and update_players().
Referenced by main().
void set_map_timeout | ( | mapstruct * | oldmap | ) |
Enable swapping for the given map. Called when all players leave a map, because maps with players are marked as ineligible for swap.
oldmap | map to process. |
Definition at line 305 of file server.cpp.
References MAP_MINTIMEOUT, and mapstruct::timeout.
Referenced by flush_old_maps(), place_exits(), and player_map_change_common().
|
static |
Takes a path and replaces all _ with / This basically undoes clean_path(). We do a strcpy so that we do not change the original string. We are smart enough to start after the last / in case we are getting passed a string that points to a unique map path.
src | path to unclean. |
newpath | buffer that will contain the uncleaned path. Should be at least as long as file. |
size | length of newpath. |
Definition at line 350 of file server.cpp.
References strlcpy().
Referenced by enter_unique_map().
|
static |
volatile sig_atomic_t shutdown_flag |
Definition at line 53 of file server.cpp.
Referenced by check_shutdown(), and signal_shutdown().
|
static |
How many minutes before a shutdown to warn players, in reverse order.
Definition at line 48 of file server.cpp.
Referenced by check_shutdown(), and login_check_shutdown().