Crossfire Server, Branch 1.12  R12190
Defines | Functions | Variables
server.c File Reference

Main server functions. More...

#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.

Defines

#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)
 Check if 2 passwords match.
static char * clean_path (const char *file, char *newpath, int size)
 Takes a path and replaces all / with _ We do a strcpy so that we do not change the original string.
void clean_tmp_files (void)
 Remove temporary map files.
void cleanup (void)
 Clean up everything and exit.
char * crypt_string (char *str, char *salt)
 Encrypt a string.
static void do_specials (void)
 Collection of functions to call from time to time.
void enter_exit (object *op, object *exit_ob)
 Tries to move 'op' to exit_ob.
static void enter_fixed_template_map (object *pl, object *exit_ob)
 The player is trying to enter a non-randomly generated template map.
static void enter_map (object *op, mapstruct *newmap, int x, int y)
 Moves the player and pets from current map (if any) to new map.
void enter_player_savebed (object *op)
 This is a basic little function to put the player back to his savebed.
static void enter_random_map (object *pl, object *exit_ob)
 The player is trying to enter a randomly generated map.
static void enter_random_template_map (object *pl, object *exit_ob)
 The player is trying to enter a randomly generated template map.
static void enter_unique_map (object *op, object *exit_ob)
 Player is entering a unique map.
int forbid_play (void)
 Checks if server should be started.
void leave (player *pl, int draw_exit)
 Player logs out, or was disconnected.
void process_events (void)
 Process all active objects.
static void process_players1 (void)
 Do all player-related stuff before objects have been updated.
static void process_players2 (void)
 Do all player-related stuff after objects have been updated.
int server_main (int argc, char **argv)
 Server main function.
void set_map_timeout (mapstruct *oldmap)
 Applies the map timeout.
void start_info (object *op)
 Gives basic start information to player.
static char * unclean_path (const char *src, char *newpath, int size)
 Takes a path and replaces all _ with / This basically undoes clean_path().
void version (object *op)
 Displays basic game version information.

Variables

static const char days [7][4]
 Ingame days.
unsigned long todtick
 Ingame time.

Detailed Description

Main server functions.

Definition in file server.c.


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

Here is the call 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, 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, llevDebug, llevError, Settings::localdir, LOG(), MAP_ENTER_X, MAP_ENTER_Y, MAP_PLAYER_UNIQUE, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_FAILURE, NDI_UNIQUE, ob_apply(), path_combine_and_normalize(), PLAYER, PORTAL_DESTINATION_NAME, QUERY_FLAG, ready_map_name(), remove_ob(), save_player(), and settings.

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(), MAP_PLAYER_UNIQUE, MAX_BUF, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_FAILURE, NDI_UNIQUE, mapdef::path, path_combine_and_normalize(), ready_map_name(), replace(), and snprintf().

Referenced by enter_exit().

Here is the call graph for this function:

Here is the caller graph for this function:

static void enter_map ( object *  op,
mapstruct newmap,
int  x,
int  y 
) [static]
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(), 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(), mapdef::path, 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, MAP_ENTER_X, MAP_ENTER_Y, RMParms::origin_map, RMParms::origin_x, RMParms::origin_y, mapdef::path, RMParms::region, set_random_map_variable(), snprintf(), RMParms::Xsize, 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, MAP_ENTER_X, MAP_ENTER_Y, MAP_PLAYER_UNIQUE, MAX_BUF, RMParms::origin_map, RMParms::origin_x, RMParms::origin_y, path_combine_and_normalize(), ready_map_name(), RMParms::region, replace(), set_random_map_variable(), snprintf(), RMParms::Xsize, 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(), MAP_PLAYER_UNIQUE, MAX_BUF, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_FAILURE, NDI_UNIQUE, mapdef::path, path_combine_and_normalize(), Settings::playerdir, ready_map_name(), settings, snprintf(), unclean_path(), and mapdef::unique.

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(), DEAD_OBJECT, draw_ext_info_format(), FLAG_WIZ, pl::hidden, socket_struct::host, llevInfo, LOG(), MAP_IN_MEMORY, MAP_TIMEOUT, MAX_BUF, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_PLAYER, NDI_ALL, NDI_DK_ORANGE, NDI_UNIQUE, Ns_Dead, pl::ob, QUERY_FLAG, query_name(), pl::socket, ST_CONFIRM_PASSWORD, ST_GET_NAME, ST_GET_PASSWORD, pl::state, socket_struct::status, and pl::transport.

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:

void process_events ( void  )

Process all active objects.

Definition at line 1026 of file server.c.

References active_objects, animate_object(), Settings::casting_time, dump_object(), FABS, FLAG_FREED, FLAG_REMOVED, free_object(), llevError, LOG(), MAP, MAP_IN_MEMORY, MONSTER, PLAYER, process_object(), process_players1(), process_players2(), QUERY_FLAG, settings, stringbuffer_finish(), stringbuffer_new(), TRUE, and update_ob_speed().

Referenced by server_main(), and START_TEST().

Here is the call graph for this function:

Here is the caller graph for this function:

static void process_players1 ( void  ) [static]

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

See also:
process_players2().

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, 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(), 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, ST_PLAYING, pl::state, and TRUE.

Referenced by process_events().

Here is the call graph for this function:

Here is the caller graph for this function:

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, 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 draw_ext_info(), draw_ext_info_format(), MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_LOGIN, MSG_TYPE_ADMIN_PLAYER, 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.