Crossfire Server, Branches 1.12
R18729
|
#include <global.h>
#include <object.h>
#include <tod.h>
#include <version.h>
#include <sproto.h>
#include <unistd.h>
#include <sys/types.h>
#include <../random_maps/random_map.h>
#include <../random_maps/rproto.h>
#include "path.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 | |
int | check_password (char *typed, char *crypted) |
static char * | clean_path (const char *file, char *newpath, int size) |
void | clean_tmp_files (void) |
void | cleanup (void) |
char * | crypt_string (char *str, char *salt) |
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_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 | process_events (void) |
static void | process_players1 (void) |
static void | process_players2 (void) |
int | server_main (int argc, char **argv) |
void | set_map_timeout (mapstruct *oldmap) |
void | start_info (object *op) |
static char * | unclean_path (const char *src, char *newpath, int size) |
void | version (object *op) |
Variables | |
static const char | days [7][4] |
unsigned long | todtick |
Main server functions.
Definition in file server.c.
#define PORTAL_DESTINATION_NAME "Town portal destination" /* this one should really be in a header file */ |
Referenced by enter_exit().
int check_password | ( | char * | typed, |
char * | crypted | ||
) |
Check if 2 passwords match.
typed | entered password. Not crypted. |
crypted | password to check against. Must be crypted. |
Definition at line 162 of file server.c.
References crypt_string().
Referenced by check_login(), receive_player_password(), and verify_player().
|
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 366 of file server.c.
References snprintf().
Referenced by enter_unique_map().
void clean_tmp_files | ( | void | ) |
Remove temporary map files.
Definition at line 1164 of file server.c.
References clean_tmp_map(), first_map, mapdef::in_memory, llevInfo, LOG(), MAP_IN_MEMORY, mapdef::next, Settings::recycle_tmp_maps, save_map(), SAVE_MODE_NORMAL, settings, swap_map(), TRUE, and write_todclock().
Referenced by cleanup().
void cleanup | ( | void | ) |
Clean up everything and exit.
Definition at line 1196 of file server.c.
References clean_tmp_files(), cleanupPlugins(), free_all_anim(), free_all_archs(), free_all_god(), free_all_images(), free_all_maps(), free_all_newserver(), free_all_object_data(), free_all_readable(), free_all_recipes(), free_all_treasures(), free_globals(), free_loader(), free_server(), free_style_maps(), llevDebug, LOG(), and write_book_archive().
Referenced by command_shutdown(), init_beforeplay(), and server_main().
char* crypt_string | ( | char * | str, |
char * | salt | ||
) |
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 130 of file server.c.
Referenced by check_password(), and receive_player_password().
|
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 1357 of file server.c.
References clean_friendly_list(), fix_luck(), fix_weight(), flush_old_maps(), metaserver_update(), obsolete_parties(), pticks, PTICKS_PER_CLOCK, tick_the_clock(), watchdog(), and write_book_archive().
Referenced by server_main().
Tries to move 'op' to exit_ob.
This is used when loading the player.
Largely redone by MSW 2001-01-21 - this function was overly complex and had some obscure bugs.
op | character or monster that is using the exit. |
exit_ob | exit object (boat, door, teleporter, etc.). if null, then op->contr->maplevel contains that map to move the object to. |
Definition at line 740 of file server.c.
References AP_UNAPPLY, obj::attacktype, pl::bed_x, pl::bed_y, obj::below, obj::contr, liv::dam, draw_ext_info_format(), Settings::emergency_mapname, Settings::emergency_x, Settings::emergency_y, 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, flags, FORCE, free_object(), hit_player(), HUGE_BUF, obj::inv, llevDebug, llevError, Settings::localdir, LOG(), obj::map, MAP_ENTER_X, MAP_ENTER_Y, MAP_PLAYER_UNIQUE, pl::maplevel, obj::msg, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_FAILURE, obj::name, NDI_UNIQUE, ob_apply(), mapdef::path, path_combine_and_normalize(), PLAYER, PORTAL_DESTINATION_NAME, QUERY_FLAG, ready_map_name(), remove_ob(), save_player(), pl::savebed_map, settings, obj::slaying, obj::stats, pl::transport, obj::type, obj::x, and obj::y.
Referenced by check_login(), command_arrest(), command_goto(), command_reset(), command_summon(), command_teleport(), enter_player_savebed(), execute_word_of_recall(), exit_type_apply(), exit_type_move_on(), key_change_class(), move_teleporter(), player_changer_type_process(), and set_first_map().
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 489 of file server.c.
References create_pathname(), create_template_pathname(), draw_ext_info_format(), enter_map(), EXIT_PATH, EXIT_X, EXIT_Y, fix_auto_apply(), HUGE_BUF, mapdef::is_template, llevDebug, llevError, load_original_map(), LOG(), obj::map, MAP_PLAYER_UNIQUE, MAX_BUF, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_FAILURE, obj::name, mapdef::name, NDI_UNIQUE, mapdef::path, path_combine_and_normalize(), ready_map_name(), replace(), snprintf(), obj::x, and obj::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 215 of file server.c.
References obj::arch, mapdef::background_music, archt::clone, obj::contr, pl::count, obj::direction, draw_ext_info(), obj::enemy, EVENT_MAPENTER, EVENT_MAPLEAVE, execute_global_event(), find_dir_2(), find_free_spot(), FLAG_REMOVED, free_object(), freearr_x, freearr_y, pl::golem_count, INS_NO_WALK_ON, insert_ob_in_map(), llevError, llevInfo, LOG(), obj::map, MAP_ENTER_X, MAP_ENTER_Y, MAP_HEIGHT, map_newmap_cmd(), MAP_WIDTH, pl::maplevel, obj::more, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_FAILURE, NDI_UNIQUE, ob_blocked(), out_of_map(), mapdef::path, PLAYER, mapdef::players, QUERY_FLAG, range_golem, pl::ranges, remove_all_pets(), remove_friendly_object(), remove_ob(), send_background_music(), set_map_timeout(), SIZEOFFREE, SIZEOFFREE1, SIZEOFFREE2, pl::socket, swap_below_max(), mapdef::timeout, obj::type, obj::x, and obj::y.
Referenced by enter_exit(), enter_fixed_template_map(), enter_random_map(), enter_random_template_map(), and enter_unique_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 175 of file server.c.
References add_string(), pl::bed_x, pl::bed_y, obj::contr, Settings::emergency_mapname, Settings::emergency_x, Settings::emergency_y, enter_exit(), EXIT_PATH, EXIT_X, EXIT_Y, free_object(), free_string(), get_object(), llevDebug, LOG(), obj::map, obj::name, mapdef::path, pl::savebed_map, and settings.
Referenced by kill_player(), 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 420 of file server.c.
References add_string(), enter_map(), EXIT_PATH, EXIT_X, EXIT_Y, RMParms::final_map, generate_random_map(), get_region_by_map(), HUGE_BUF, obj::map, MAP_ENTER_X, MAP_ENTER_Y, obj::msg, RMParms::origin_map, RMParms::origin_x, RMParms::origin_y, mapdef::path, RMParms::region, set_random_map_variable(), snprintf(), obj::x, RMParms::Xsize, obj::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 586 of file server.c.
References create_template_pathname(), enter_map(), EXIT_PATH, EXIT_X, EXIT_Y, generate_random_map(), get_region_by_map(), HUGE_BUF, mapdef::is_template, obj::map, MAP_ENTER_X, MAP_ENTER_Y, MAP_PLAYER_UNIQUE, MAX_BUF, obj::msg, mapdef::name, RMParms::origin_map, RMParms::origin_x, RMParms::origin_y, mapdef::path, path_combine_and_normalize(), ready_map_name(), RMParms::region, replace(), set_random_map_variable(), snprintf(), obj::x, RMParms::Xsize, obj::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 654 of file server.c.
References clean_path(), create_pathname(), draw_ext_info_format(), enter_map(), EXIT_PATH, EXIT_X, EXIT_Y, fix_auto_apply(), HUGE_BUF, llevDebug, load_original_map(), Settings::localdir, LOG(), obj::map, MAP_PLAYER_UNIQUE, MAX_BUF, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_FAILURE, obj::name, NDI_UNIQUE, mapdef::path, path_combine_and_normalize(), Settings::playerdir, ready_map_name(), settings, snprintf(), unclean_path(), mapdef::unique, obj::x, and obj::y.
Referenced by enter_exit().
int forbid_play | ( | void | ) |
Checks if server should be started.
Definition at line 1296 of file server.c.
References close_and_delete(), Settings::confdir, days, llevDebug, LOG(), logfile, MAX_BUF, open_and_uncompress(), PERM_FILE, settings, and snprintf().
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 1234 of file server.c.
References check_score(), obj::contr, DEAD_OBJECT, draw_ext_info_format(), FLAG_WIZ, pl::hidden, socket_struct::host, mapdef::in_memory, obj::inv, llevInfo, LOG(), obj::map, MAP_IN_MEMORY, MAP_TIMEOUT, MAX_BUF, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_PLAYER, obj::name, NDI_ALL, NDI_DK_ORANGE, NDI_UNIQUE, Ns_Dead, pl::ob, mapdef::players, QUERY_FLAG, query_name(), pl::socket, ST_CONFIRM_PASSWORD, ST_GET_NAME, ST_GET_PASSWORD, pl::state, socket_struct::status, mapdef::timeout, pl::transport, and obj::type.
Referenced by attack_ob_simple(), check_login(), do_server(), receive_play_again(), and shop_mat_type_move_on().
void process_events | ( | void | ) |
Process all active objects.
Definition at line 1026 of file server.c.
References obj::active_next, active_objects, obj::active_prev, obj::anim_speed, animate_object(), obj::arch, obj::casting_time, Settings::casting_time, obj::count, obj::direction, dump_object(), obj::env, FABS, obj::facing, FLAG_FREED, FLAG_REMOVED, free_object(), mapdef::in_memory, obj::last_anim, llevError, LOG(), MAP, obj::map, MAP_IN_MEMORY, MONSTER, obj::name, archt::name, mapdef::path, PLAYER, process_object(), process_players1(), process_players2(), QUERY_FLAG, settings, obj::speed, obj::speed_left, obj::state, stringbuffer_finish(), stringbuffer_new(), obj::temp_anim_speed, obj::temp_animation_id, TRUE, obj::type, update_ob_speed(), and was_destroyed.
Referenced by server_main(), and START_TEST().
|
static |
Do all player-related stuff before objects have been updated.
Handle DM follow command
This is a DM, just teleport on the top of player.
End of follow
Definition at line 908 of file server.c.
References AUTOSAVE, obj::casting_time, Settings::casting_time, check_score(), rv_vector::distance, do_some_living(), draw_ext_info_format(), find_free_spot(), find_player_partial_name(), first_player, FLAG_REMOVED, pl::followed_player, FREE_AND_CLEAR_STR, freearr_x, freearr_y, get_map_flags(), get_rangevector(), handle_newcs_player(), insert_ob_in_map_at(), obj::map, map_newmap_cmd(), MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_DM, NDI_UNIQUE, pl::next, pl::ob, P_NO_CLERIC, pticks, QUERY_FLAG, remove_ob(), save_player(), settings, pl::socket, socket_struct::sounds_this_tick, obj::speed_left, ST_PLAYING, pl::state, TRUE, obj::x, and obj::y.
Referenced by process_events().
|
static |
Do all player-related stuff after objects have been updated.
Definition at line 996 of file server.c.
References first_player, pl::has_hit, pl::next, pl::ob, obj::speed, obj::speed_left, and pl::weapon_sp.
Referenced by process_events().
int server_main | ( | int | argc, |
char ** | argv | ||
) |
Server main function.
argc | length of argv. |
argv | command-line options. |
Definition at line 1399 of file server.c.
References Settings::argc, Settings::argv, bRunning, cftimer_process_timers(), check_active_maps(), cleanup(), do_server(), do_specials(), emergency_save(), EVENT_CLOCK, execute_global_event(), init(), initPlugins(), nroferrors, process_events(), settings, and sleep_delta().
Referenced by main().
void set_map_timeout | ( | mapstruct * | oldmap | ) |
Applies the map timeout.
oldmap | map to process. |
Definition at line 333 of file server.c.
References MAP_MAXTIMEOUT, MAP_MINTIMEOUT, MAP_TIMEOUT, swap_map(), and mapdef::timeout.
Referenced by enter_map(), flush_old_maps(), and place_exits().
void start_info | ( | object * | op | ) |
Gives basic start information to player.
op | player. |
Definition at line 97 of file server.c.
References obj::contr, draw_ext_info(), draw_ext_info_format(), MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_LOGIN, MSG_TYPE_ADMIN_PLAYER, obj::name, pl::name_changed, NDI_ALL, NDI_DK_ORANGE, NDI_UNIQUE, and VERSION.
Referenced by key_change_class().
|
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 394 of file server.c.
References snprintf().
Referenced by enter_unique_map().
void version | ( | object * | op | ) |
Displays basic game version information.
op | who is requesting the verison information. |
Definition at line 81 of file server.c.
References draw_ext_info(), draw_ext_info_format(), FULL_VERSION, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_VERSION, and NDI_UNIQUE.
Referenced by call_version(), and command_version().
|
static |
Ingame days.
Definition at line 65 of file server.c.
Referenced by forbid_play().