Crossfire Server, Branches 1.12  R18729
server.c File Reference
#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"
+ Include dependency graph for server.c:

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
 

Detailed Description

Main server functions.

Definition in file server.c.

Macro Definition Documentation

#define PORTAL_DESTINATION_NAME   "Town portal destination" /* this one should really be in a header file */

Referenced by enter_exit().

#define SPEED_DEBUG

Definition at line 1021 of file server.c.

Function Documentation

int check_password ( char *  typed,
char *  crypted 
)

Check if 2 passwords match.

Parameters
typedentered password. Not crypted.
cryptedpassword to check against. Must be crypted.
Returns
1 if the passwords match, 0 else.

Definition at line 162 of file server.c.

References crypt_string().

Referenced by check_login(), receive_player_password(), and verify_player().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static char* clean_path ( const char *  file,
char *  newpath,
int  size 
)
static

Takes a path and replaces all / with _ We do a strcpy so that we do not change the original string.

Parameters
filepath to clean.
newpathbuffer that will contain the cleaned path. Should be at least as long as file.
sizelength of newpath.
Returns
newpath.

Definition at line 366 of file server.c.

References snprintf().

Referenced by enter_unique_map().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void clean_tmp_files ( void  )

Remove temporary map files.

Todo:
check logic, why is file only removed if map is in memory?

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().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void cleanup ( void  )
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.

Parameters
strstring to crypt.
saltsalt to crypt with.
Returns
crypted str.
Todo:
make thread-safe?

Definition at line 130 of file server.c.

Referenced by check_password(), and receive_player_password().

+ Here is the caller graph for this function:

static void do_specials ( void  )
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().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void enter_exit ( object op,
object exit_ob 
)

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.

Parameters
opcharacter or monster that is using the exit.
exit_obexit 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().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void enter_fixed_template_map ( object pl,
object exit_ob 
)
static

The player is trying to enter a non-randomly generated template map. In this case, use a map file for a template.

Parameters
plplayer.
exit_obexit 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().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.

Parameters
opplayer.

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().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void enter_random_map ( object pl,
object exit_ob 
)
static

The player is trying to enter a randomly generated map. In this case, generate the random map as needed.

Parameters
plplayer.
exit_obexit 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().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void enter_random_template_map ( object pl,
object exit_ob 
)
static

The player is trying to enter a randomly generated template map. In this case, generate the map as needed.

Parameters
plplayer.
exit_obexit 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().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void enter_unique_map ( object op,
object exit_ob 
)
static

Player is entering a unique map.

Parameters
opplayer.
exit_obexit 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().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int forbid_play ( void  )

Checks if server should be started.

Returns
1 if play is forbidden, 0 if ok.
Todo:
document forbidden stuff.

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().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void leave ( player pl,
int  draw_exit 
)

Player logs out, or was disconnected.

Parameters
plplayer.
draw_exitif set, display leaving message to other players.
Todo:
check for pl != NULL should include the 'left the game', just in case (or remove it?)

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().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void process_players1 ( void  )
static
static void process_players2 ( void  )
static

Do all player-related stuff after objects have been updated.

See Also
process_players1().
Todo:
explain why 2 passes for players.

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().

+ Here is the caller graph for this function:

int server_main ( int  argc,
char **  argv 
)

Server main function.

Parameters
argclength of argv.
argvcommand-line options.
Returns
0.

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().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void set_map_timeout ( mapstruct oldmap)

Applies the map timeout.

Parameters
oldmapmap 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().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void start_info ( object op)

Gives basic start information to player.

Parameters
opplayer.

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().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static char* unclean_path ( const char *  src,
char *  newpath,
int  size 
)
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.

Parameters
srcpath to unclean.
newpathbuffer that will contain the uncleaned path. Should be at least as long as file.
sizelength of newpath.
Returns
newpath.

Definition at line 394 of file server.c.

References snprintf().

Referenced by enter_unique_map().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void version ( object op)

Displays basic game version information.

Parameters
opwho 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().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

const char days[7][4]
static
Initial value:
= {
"Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat"
}

Ingame days.

Definition at line 65 of file server.c.

Referenced by forbid_play().

unsigned long todtick

Ingame time

Definition at line 418 of file init.c.