 |
Crossfire Server, Trunk
1.75.0
|
Go to the documentation of this file.
48 static const int shutdown_warn_times[] = {120, 90, 60, 45, 30, 15, 10, 5, 4, 3, 2, 1};
51 static const char *
days[] = {
"Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat"};
70 static char const*
crypt_string(
char const *str,
char const* salt) {
75 #if (defined(__FreeBSD__))
87 static const char *
const c =
88 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
115 if (getenv(
"CF_DEBUG_BYPASS_LOGIN")) {
120 if (strlen(crypted) == 0) {
121 return strlen(typed) == 0 ? true :
false;
124 const char *typed_hashed =
crypt_string(typed, crypted);
125 if (typed_hashed != NULL) {
126 return strcmp(typed_hashed, crypted) == 0;
128 LOG(
llevError,
"Could not check password with stored hash %s\n", crypted);
158 LOG(
llevDebug,
"Player %s savebed location %s is invalid - going to emergency location (%s)\n",
189 if (x < 0 && y >= 0) x=0;
190 if (y < 0 && x >= 0) y=0;
193 if (x != -1 || y != -1) {
194 LOG(
llevError,
"enter_map: supplied coordinates are not within the map! (%s: %d, %d)\n", newmap->
path, x, y);
206 "The exit is closed");
230 LOG(
llevInfo,
"enter_map: Could not find free spot for player - will dump on top of object (%s: %d, %d)\n", newmap->
path, x, y);
275 if (oldmap != newmap) {
284 if (oldmap != NULL) {
322 static char *
clean_path(
const char *file,
char *newpath,
int size) {
326 for (cp = newpath; *cp !=
'\0'; cp++) {
353 cp =
const_cast<char *
>(strrchr(src,
'/'));
359 for (cp = newpath; *cp !=
'\0'; cp++) {
378 static int reference_number = 0;
381 memset(&rp, 0,
sizeof(
RMParms));
406 while (isdigit(
buf[strlen(
buf)-1]))
411 snprintf(newmap_name,
sizeof(newmap_name),
"/random/%s%04d", cp+1, reference_number++);
466 char* src = strdup(op->
map->
path);
467 char* slash = strrchr(src,
'/');
478 if ((cp = strrchr(tmpc,
'_')) != NULL)
481 snprintf(apartment,
sizeof(apartment),
"%s/%s_%s", src, tmpc,
clean_path(
EXIT_PATH(exit_ob), path,
sizeof(path)));
492 snprintf(apartment,
sizeof(apartment),
"~%s/%s",
player,
clean_path(reldir, path,
sizeof(path)));
518 LOG(
llevDebug,
"enter_unique_map: Exit %s (%d,%d) on map %s is leads no where.\n", exit_ob->
name, exit_ob->
x, exit_ob->
y, exit_ob->
map->
path);
524 int flags = 0, x = op->
x, y = op->
y;
536 LOG(
llevError,
"Fatal: Could not load emergency map!\n");
541 "You find yourself somewhere unexpected...");
546 if (x == -1 && y == -1) {
568 #define PORTAL_DESTINATION_NAME "Town portal destination"
576 assert(exit_ob != NULL);
582 object *item = op->
inv;
589 "You feel a force fizzling away. You feel a vibration from: %s",
buf);
617 if (!newmap && !strncmp(
EXIT_PATH(exit_ob),
"/random/", 8)) {
661 if (x == -1 && y == -1) {
694 exit_copy->
speed = 0;
696 exit_copy->
map = exit_ob->
map;
709 static int move_towards(
object *ob,
object *towards,
unsigned int mindist) {
725 int sx, sy, sx2, sy2;
727 return (ob->
x >= x+sx2) && (ob->
x <= x+sx) && (ob->
y >= y+sy2) && (ob->
y <= y+sy);
736 if (followed && followed->
ob && followed->
ob->
map) {
785 for (flag = 1; flag != 0; ) {
827 pl->last_save_tick += 100;
830 pl->last_save_tick =
pticks;
905 return op->
env != NULL && strcmp(op->
env->
arch->
name,
"icecube") == 0;
918 memset(&marker, 0,
sizeof(
object));
948 LOG(
llevError,
"BUG: process_events(): Free object on list\n");
971 LOG(
llevError,
"BUG: process_events(): Removed object on list\n");
982 LOG(
llevError,
"BUG: process_events(): Object %s has no speed, but is on active list\n", op->
arch->
name);
991 LOG(
llevError,
"BUG: process_events(): Object without map or inventory is on active list: %s (%d)\n", op->
name, op->
count);
1162 "%s has left. You are now the captain of %s",
1181 "%s left the game.",
1193 #if !defined(_IBMR2) && !defined(___IBMR2) && defined(PERM_FILE)
1198 int i, start, stop, forbit = 0;
1201 tm = (
struct tm *)localtime(&clock);
1204 if ((fp = fopen(
buf,
"r")) == NULL)
1207 while (fgets(
buf,
sizeof(
buf), fp)) {
1210 if (!strncmp(
buf,
"msg", 3)) {
1212 while (fgets(
buf,
sizeof(
buf), fp))
1215 }
else if (sscanf(
buf,
"%s %d%*c%d\n", day, &start, &stop) != 3) {
1216 LOG(
llevDebug,
"Warning: Incomplete line in permission file ignored.\n");
1220 for (i = 0; i < 7; i++) {
1222 && (tm->tm_wday == i)
1223 && (tm->tm_hour >= start)
1224 && (tm->tm_hour < stop))
1261 LOG(
llevInfo,
"Received SIGINT; shutting down...\n");
1278 LOG(
llevInfo,
"No active players in the last %ld seconds, shutting down...\n", diff);
1306 if (time_left <= 0) {
1324 "This server will shut down when all players leave.");
1334 "This server will shut down in %lu minutes.", time_left / 60);
1415 if (getuid() == 0 || geteuid() == 0) {
1417 "Running crossfire-server as root is a bad idea; aborting!\n"
1418 "Please run it again as a normal, unprivileged user.\n");
1423 #ifdef DEBUG_MALLOC_LEVEL
1424 malloc_debug(DEBUG_MALLOC_LEVEL);
1430 PROFILE_END(diff,
LOG(
llevInfo,
"Initialization complete (%ld ms). Waiting for connections.\n", diff/1000));
void write_book_archive(void)
Write out the updated book archive to bookarch file.
#define object_was_destroyed(op, old_tag)
Checks if an object still exists.
uint8_t casting_time
It takes awhile to cast a spell.
void fix_weight(void)
Check recursively the weight of all players, and fix what needs to be fixed.
static bool check_shutdown(void)
Check if we're ready to shut the server down.
int handle_newcs_player(object *op)
Handles commands the player can send us, and various checks on invisibility, golem and such.
int16_t bed_y
x,y - coordinates of respawn (savebed).
float weapon_speed_left
How much speed is left to spend this round.
player * next
Pointer to next player, NULL if this is last.
void i18n_free(void)
Clears all i18n-related data.
player * first_player
First player.
void clean_tmp_files(void)
Save unique maps and clean up temporary map files unless recycling temporary maps.
struct Settings settings
Global settings.
void tick_the_clock(void)
This performs the basic function of advancing the clock one tick forward.
void remove_friendly_object(object *op)
Removes the specified object from the linked list of friendly objects.
void pets_terminate_all(object *owner)
Removes all pets someone owns.
void enter_player_savebed(object *op)
This is a basic little function to put the player back to his savebed.
void send_delayed_buffers(player *pl)
Send all delayed buffers for a player.
@ MONSTER
A real, living creature.
uint8_t recycle_tmp_maps
Re-use tmp maps.
uint16_t emergency_y
Coordinates to use on that map.
@ llevError
Problems requiring server admin to fix.
char origin_map[RM_SIZE]
Path to the map this random map is generated from, to make an exit back.
#define FABS(x)
Decstations have trouble with fabs()...
#define ST_GET_PASSWORD
Name entered, now for password.
#define MSG_TYPE_ADMIN_PLAYER
Player coming/going/death.
void LOG(LogLevel logLevel, const char *format,...)
Logs a message to stderr, or to file.
#define PTICKS_PER_CLOCK
Number of ticks per in-game hour.
void free_all_readable(void)
Free all readable-related information.
#define ST_GET_NAME
Player just connected.
void object_free_all_data(void)
Destroys all allocated objects.
object * inv
Pointer to the first object in the inventory.
uint32_t golem_count
To track the golem.
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.
mapstruct * ready_map_name(const char *name, int flags)
Makes sure the given map is loaded and swapped in.
#define QUERY_FLAG(xyz, p)
same as sound ncom command like but with extra the client want tick commands so it knows animation timing the client wants to be informed of pickup mode changes Mode will be sent when the player successfully logs and afterward any time the value is but over time
#define ST_CONFIRM_PASSWORD
New character, confirm password.
void flush_old_maps(void)
Reset maps that need to, remove their swap file.
void set_map_timeout(mapstruct *oldmap)
Enable swapping for the given map.
uint8_t crypt_mode
0 for legacy behavior, 1 for always Traditional
static event_registration c
struct archetype * arch
Pointer to archetype.
#define P_NO_CLERIC
No clerical spells cast here.
StringBuffer * stringbuffer_new(void)
Create a new string buffer.
int16_t players
How many players are on this level right now.
float speed
Frequency of object 'moves' relative to server tick rate.
void object_set_enemy(object *op, object *enemy)
Sets the enemy of an object.
void accounts_save(void)
Save all the account information.
object * ob
The object representing the player.
void do_server(void)
This checks the sockets for input and exceptions, does the right thing.
static void do_follow(player *pl)
Called from process_players1() to move a player who is following someone.
object * transport
Transport the player is in.
float speed_left
How much speed is left to spend this round.
#define MAP_IN_MEMORY
Map is fully loaded.
struct mapstruct * map
Pointer to the map in which this object is present.
#define AP_UNAPPLY
Item is to be remvoed.
int set_random_map_variable(RMParms *rp, const char *buf)
static void enter_random_map(object *pl, object *exit_ob)
The player is trying to enter a randomly generated map.
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...) PRINTF_ARGS(6
#define FLAG_WIZ
Object has special privilegies.
int move_player(object *op, int dir)
Move player in the given direction.
void free_all_newserver(void)
Free's all the memory that ericserver allocates.
int8_t direction
Means the object is moving that way.
tag_t count
Unique object number for this object.
static const flag_definition flags[]
Flag mapping.
int16_t last_grace
As last_sp, except for grace.
void object_copy(const object *src_ob, object *dest_ob)
Copy object first frees everything allocated by the second object, and then copies the contents of th...
char savebed_map[MAX_BUF]
Map where player will respawn after death.
#define ST_PLAYING
Usual state.
#define PROFILE_BEGIN(expr)
void free_knowledge(void)
Free all knowledge data.
uint32_t hidden
If True, player (DM) is hidden from view.
mapstruct * generate_random_map(const char *OutFileName, RMParms *RP, char **use_layout, sstring reset_group)
Main random map routine.
void cleanupPlugins(void)
Call the crossfire_plugin::closefunc on the various plugins, used at server shutdown.
@ range_golem
Control golem.
void enter_player_maplevel(object *op)
Move a player to its stored map level.
char path[HUGE_BUF]
Filename of the map.
#define MSG_TYPE_MISC
Messages that don't go elsewhere.
void party_obsolete_parties(void)
Remove unused parties (no players).
void free_all_maps(void)
Frees all allocated maps.
uint32_t pticks
Number of ticks since time reset.
object * active_objects
List of active objects that need to be processed.
void initPlugins(void)
Plugins initialization.
void hiscore_check(object *op, int quiet)
Checks if player should enter the hiscore, and if so writes her into the list.
#define HUGE_BUF
Used for messages - some can be quite long.
static int query_flag(const object *op, int flag)
#define MSG_TYPE_COMMAND
Responses to commands, eg, who.
static int move_towards(object *ob, object *towards, unsigned int mindist)
Move 'ob' in the direction of 'towards' (without any pathfinding) if the two objects are farther than...
Plugin animator file specs[Config] name
#define FLAG_REMOVED
Object is not in any map or invenory.
#define MSG_TYPE_ADMIN_DM
DM related admin actions.
void free_loader(void)
Frees all memory allocated by the loader.
#define PROFILE_END(var, expr)
int16_t y
Position in the map for this object.
static event_registration m
char * stringbuffer_finish(StringBuffer *sb)
Deallocate the string buffer instance and return the string.
void apply_auto_fix(mapstruct *m)
Go through the entire map (only the first time when an original map is loaded) and performs special a...
void login_check_shutdown(object *const op)
Warn op if a server shutdown is scheduled.
#define FLAG_FREED
Object is in the list of free objects.
void object_free_drop_inventory(object *ob)
Frees everything allocated by an object, removes it from the list of used objects,...
time_t time
When using SHUTDOWN_TIME, time of shutdown.
struct player * contr
Pointer to the player which control this object.
int forbid_play(void)
Checks if server should be started.
uint8_t temp_anim_speed
Ticks between temporary animation-frames.
#define MAP_MINTIMEOUT
At least that many ticks before swapout.
void write_todclock(void)
Write out the current time to the file so time does not reset every time the server reboots.
void final_free_player(player *pl)
Sends the 'goodbye' command to the player, and closes connection.
char killer[BIG_NAME]
Who killed this player.
int32_t last_heal
Last healed.
uint8_t subtype
Subtype of object.
short freearr_y[SIZEOFFREE]
Y offset when searching around a spot.
uint8_t anim_speed
Ticks between animation-frames.
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.
#define FLAG_UNPAID
Object hasn't been paid for yet.
void query_name(const object *op, char *buf, size_t size)
Describes an item.
float weapon_speed
The overall speed of this object.
#define FREE_OBJ_NO_DESTROY_CALLBACK
Do not run the destroy callback.
sstring followed_player
Player the DM is following.
object * ranges[range_size]
Object for each range.
char * path_combine_and_normalize(const char *src, const char *dst, char *path, size_t size)
Combines the 2 paths.
void free_all_artifacts(void)
Free all artifact-related information.
void clean_friendly_list(void)
It traverses the friendly list removing objects that should not be here (ie, do not have friendly fla...
char final_map[RM_SIZE]
If not empty, the path of the final map this whole maze leads to.
void object_dump(const object *op, StringBuffer *sb)
Dumps an object.
void party_leave(object *op)
Makes a player leave his party.
sstring add_string(const char *str)
Share a string.
mapstruct * first_map
First map.
#define FOR_OB_AND_BELOW_FINISH()
Finishes FOR_OB_AND_BELOW_PREPARE().
void object_get_multi_size(const object *ob, int *sx, int *sy, int *hx, int *hy)
Computes the size of a multitile object.
void clean_tmp_map(mapstruct *m)
Removse the temporary file used by the map.
void free_quest(void)
Free all quest status structures.
int16_t casting_time
Time left before spell goes off.
void process_events(void)
Process all active objects.
void server_main(int argc, char *argv[])
Server main function.
int out_of_map(mapstruct *m, int x, int y)
Return 1 if coordinates X and Y are out of the map M, taking into account tiling.
char * host
Which host it is connected from (ip address).
static void do_specials(void)
Collection of functions to call from time to time.
#define PORTAL_DESTINATION_NAME
int32_t last_eat
How long since we last ate.
long nroferrors
If it exceeds MAX_ERRORS, call fatal()
char * ob_describe(const object *op, const object *observer, int use_media_tags, char *buf, size_t size)
Returns the description (short item name) of an object, as seen by the given observer.
void object_update_speed(object *op)
Updates the speed of an object.
uint8_t last_anim
Last sequence used to draw face.
static bool object_on_exit(object *ob, object *exit)
Return true if the player object is on the given exit.
uint8_t type
PLAYER, BULLET, etc.
void enter_exit(object *op, object *exit_ob)
Tries to move 'op' to exit_ob.
#define EVENT_CLOCK
Global time event.
char const * newhash(char const *password)
int16_t dam
How much damage this object does when hitting.
object * active_prev
Previous object in the 'active list This is used in process_events so that the entire object list doe...
void object_free(object *ob, int flags)
Frees everything allocated by an object, removes it from the list of used objects,...
uint32_t tag_t
Object tag, unique during the whole game.
sstring reset_group
For reset purpose, all maps in the same group reset at the same time.
const char * confdir
Configuration files.
FILE * logfile
Used by server/daemon.c.
#define FOR_OB_AND_BELOW_PREPARE(op_)
Constructs a loop iterating over an object and all objects below it in the same pile.
static void process_players1(void)
Do all player-related stuff before objects have been updated.
#define MSG_TYPE_SPELL
Spell related info.
void cftimer_process_timers(void)
Processes all timers.
static bool object_in_icecube(object *op)
int8_t facing
Object is oriented/facing that way.
char maplevel[MAX_BUF]
On which level is the player?
#define INS_NO_WALK_ON
Don't call check_walk_on against the originator.
int ob_blocked(const object *ob, mapstruct *m, int16_t x, int16_t y)
Returns true if the given object can't fit in the given spot.
object * object_insert_in_map_at(object *op, mapstruct *m, object *originator, int flag, int x, int y)
Same as object_insert_in_map() except it handle separate coordinates and do a clean job preparing mul...
#define SAVE_MODE_NORMAL
No special handling.
#define MAP_WIDTH(m)
Map width.
volatile sig_atomic_t shutdown_flag
#define MAX_BUF
Used for all kinds of things.
void free_all_recipes(void)
Frees all memory allocated to recipes and recipes lists.
size_t strlcpy(char *dst, const char *src, size_t size)
Portable implementation of strlcpy(3).
#define EVENT_MAPLEAVE
A player left a map.
object * object_new(void)
Grabs an object from the list of unused objects, makes sure it is initialised, and returns it.
void free_all_god(void)
Frees all god information.
#define PERM_FILE
You can restrict playing in certain times by creating a PERMIT_FILE in CONFDIR.
void free_string(sstring str)
This will reduce the refcount, and if it has reached 0, str will be freed.
void metaserver2_exit()
Stop metaserver updates.
A buffer that will be expanded as content is added to it.
#define FREE_AND_CLEAR_STR(xyz)
Release the shared string, and set it to NULL.
void free_quest_definitions(void)
#define FLAG_DAMNED
The object is very cursed.
static void enter_unique_map(object *op, object *exit_ob)
Player is entering a unique map.
#define MSG_TYPE_COMMAND_FAILURE
Failed result from command.
bool can_follow(object *, player *)
int8_t sounds_this_tick
Number of sounds sent this tick.
void player_map_change_common(object *op, mapstruct *const oldmap, mapstruct *const newmap)
int find_dir_2(int x, int y)
Computes a direction which you should travel to move of x and y.
void pets_attempt_follow(object *for_owner, int force)
Check pets so they try to follow their master around the world.
object * object_find_by_type_and_slaying(const object *who, int type, const char *slaying)
Find object in inventory by type and slaying.
int swap_map(mapstruct *map)
Swaps a map to disk.
char * emergency_mapname
Map to return players to in emergency.
#define NDI_UNIQUE
Print immediately, don't buffer.
sstring name
The name of the object, obviously...
uint32_t has_hit
If set, weapon_sp instead of speed will count.
#define MSG_TYPE_SPELL_FAILURE
Spell failure messages.
void free_style_maps(void)
Frees cached style maps.
bool check_password(const char *typed, const char *crypted)
Hash a password and compare it to the stored version.
static const int shutdown_warn_times[]
How many minutes before a shutdown to warn players, in reverse order.
void metaserver_update(void)
Updates our info in the metaserver Note that this is used for both metaserver1 and metaserver2 - for ...
int get_map_flags(mapstruct *oldmap, mapstruct **newmap, int16_t x, int16_t y, int16_t *nx, int16_t *ny)
This rolls up wall, blocks_magic, blocks_view, etc, all into one function that just returns a P_.
static void save_and_kick_all_players(void)
object * env
Pointer to the object which is the environment.
void write_cs_stats(void)
int32_t last_sp
As last_heal, but for spell points.
#define EVENT_MAPENTER
A player entered a map.
#define NDI_ALL
Inform all players of this message.
void animate_object(object *op, int dir)
Updates the face-variable of an object.
void update_players(void)
Send updates to players.
uint8_t state
Input state of the player (name, password, etc).
int object_find_free_spot(const object *ob, mapstruct *m, int x, int y, int start, int stop)
object_find_free_spot(object, map, x, y, start, stop) will search for a spot at the given map and coo...
uint32_t in_memory
Combination of IN_MEMORY_xxx flags.
sstring msg
If this is a book/sign/magic mouth/etc.
This is used by get_rangevector to determine where the other creature is.
void init(int argc, char **argv)
This is the main server initialization function.
int hit_player(object *op, int dam, object *hitter, uint32_t type, int full_hit)
Object is attacked by something.
void free_globals(void)
Cleans all memory allocated for global variables.
bool map_path_unique(const char *path)
Return true if the given map path leads to a unique map.
void free_server(void)
Frees all memory allocated around here:
method_ret ob_apply(object *op, object *applier, int aflags)
Apply an object by running an event hook or an object method.
int32_t timeout
Swapout is set to this.
#define MAP_HEIGHT(m)
Map height.
#define MAP_ENTER_Y(m)
Default Y coordinate for map enter.
#define NDI_DK_ORANGE
DarkOrange2.
player * find_player_partial_name(const char *plname)
Find a player by a partial name.
void map_newmap_cmd(socket_struct *ns)
Sound related function.
int get_rangevector(object *op1, const object *op2, rv_vector *retval, int flags)
From map.c This is used by get_player to determine where the other creature is.
uint32_t count
Any numbers typed before a command.
#define MAP_PLAYER_UNIQUE
This map is player-specific.
region * get_region_by_map(mapstruct *m)
Gets a region from a map.
int save_player(object *op, int flag)
Saves a player to disk.
void draw_ext_info(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *message)
Sends message to player(s).
#define MAP_ENTER_X(m)
Default X coordinate for map enter.
void process_object(object *op)
Main object move function.
object * active_next
Next object in the 'active' list This is used in process_events so that the entire object list does n...
void object_remove(object *op)
This function removes the object op from the linked list of objects which it is currently tied to.
struct shutdown_s shutdown_state
void cleanup(void)
Clean up everything and exit.
void leave(player *pl, int draw_exit)
Player logs out, or was disconnected.
void do_some_living(object *op)
Regenerate hp/sp/gr, decreases food.
uint8_t state
How the object was last drawn (animation)
uint32_t unique
If set, this is a per player unique map.
int save_map(mapstruct *m, int flag)
Saves a map to file.
sstring name
More definite name, like "generate_kobold".
socket_struct * socket
Socket information for this player.
void fix_luck(void)
Fixes luck of players, slowly move it towards 0.
void check_active_maps(void)
Finds maps in memory to swap.
living stats
Str, Con, Dex, etc.
void commands_clear()
Clear all registered commands.
void close_modules()
Clean up all modules which are not disabled.
short freearr_x[SIZEOFFREE]
X offset when searching around a spot.
object * last_exit
Last exit used by player or NULL.
static const char * days[]
Ingame days.
static void do_shutdown(void)
mapstruct * mapfile_load(const char *map, int flags)
Opens the file "filename" and reads information about the map from the given file,...
#define FLAG_UNIQUE
Item is really unique (UNIQUE_ITEMS)
uint32_t attacktype
Bitmask of attacks this object does.
int direction
General direction to the targer.
const Animations * temp_animation
A temporary animation.
unsigned int distance
Distance, in squares.
void knowledge_process_incremental(void)
Incrementally send knowledge information to players, and remove information for players who left.
uint32_t ticks_played
How many ticks this player has played.
void events_execute_global_event(int eventcode,...)
Execute a global event.
bool link_source_map
Whether to set the reset group (if not already defined) of the source map for this random map.
@ llevDebug
Only for debugging purposes.
#define SP_WORD_OF_RECALL
static void process_players2(void)
Do all player-related stuff after objects have been updated.
#define AUTOSAVE
How often (in seconds) the player is saved if he drops things.
void player_update_bg_music(object *player)
static char * unclean_path(const char *src, char *newpath, int size)
Takes a path and replaces all _ with / This basically undoes clean_path().
static char const * crypt_string(char const *str, char const *salt)
Encrypt a string.