Crossfire Server, Trunk
global.h File Reference
#include "autoconf.h"
#include <sys/socket.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
#include <unistd.h>
#include "compat.h"
#include "config.h"
#include "define.h"
#include "logger.h"
#include "shared/newclient.h"
#include "face.h"
#include "attack.h"
#include "material.h"
#include "living.h"
#include "object.h"
#include "map.h"
#include "tod.h"
#include "skills.h"
#include "account_char.h"
#include "newserver.h"
#include "party.h"
#include "player.h"
#include "treasure.h"
#include "commands.h"
#include "book.h"
#include "ob_methods.h"
#include "ob_types.h"
#include "artifact.h"
#include "god.h"
#include "race.h"
#include "recipe.h"
#include "spells.h"
#include "stringbuffer.h"
#include "libproto.h"
#include "sockproto.h"
#include "typesproto.h"
#include <dirent.h>
#include "plugin.h"
+ Include dependency graph for global.h:

Go to the source code of this file.

Data Structures

struct  linked_char
 
struct  Settings
 
struct  Statistics
 

Macros

#define EXTERN   extern
 
#define FREE_AND_CLEAR(xyz)   { free(xyz); xyz = NULL; }
 
#define FREE_AND_CLEAR_STR(xyz)   { free_string(xyz); xyz = NULL; }
 
#define FREE_AND_CLEAR_STR_IF(xyz)   { if (xyz) { free_string(xyz); xyz = NULL; } }
 
#define FREE_AND_COPY(sv, nv)   { if (sv) free_string(sv); sv = add_string(nv); }
 
#define FREE_AND_COPY_IF(sv, nv)   { if (sv) free_string(sv); sv = nv ? add_string(nv) : NULL; }
 
#define GET_ANIM(ob)   (ob->temp_animation ? ob->temp_animation : ob->animation)
 
#define GET_ANIM_ID(ob)   (ob->temp_animation ? ob->temp_animation->num : (ob->animation ? ob->animation->num : 0))
 
#define GET_ANIMATION(ob, anim)   ((ob->temp_animation ? ob->temp_animation : ob->animation)->faces[anim])
 
#define MAX_TOTAL_EXPERIENCE   (settings.permanent_exp_ratio ? (MAX_EXPERIENCE * 100 / settings.permanent_exp_ratio) : 0)
 
#define NAMLEN(dirent)   strlen((dirent)->d_name)
 
#define NUM_ANIMATIONS(ob)   ((ob->temp_animation ? ob->temp_animation : ob->animation)->num_animations)
 
#define NUM_FACINGS(ob)   ((ob->temp_animation ? ob->temp_animation : ob->animation)->facings)
 
#define PERM_EXP(exptotal)   (exptotal * settings.permanent_exp_ratio / 100 )
 
#define PRINTF_ARGS(x, y)   __attribute__ ((format (printf, x, y)))
 
#define PROFILE_BEGIN(expr)
 
#define PROFILE_END(var, expr)
 
#define ROTATE_RIGHT(c)   if ((c)&01) (c) = ((c)>>1)+0x80000000; else (c) >>= 1;
 
#define SCRIPT_FIX_ACTIVATOR   2
 
#define SCRIPT_FIX_ALL   1
 
#define SCRIPT_FIX_NOTHING   0
 
#define SET_ANIMATION(ob, newanim)   { ob->face = (ob->temp_animation ? ob->temp_animation : ob->animation)->faces[newanim]; }
 
#define SPELL_MAPPINGS   206
 

Typedefs

typedef void(* collectorHook) (BufferReader *, const char *)
 
typedef void(* fatalHook) (enum fatal_error err)
 
typedef struct linked_char linked_char
 
typedef void(* logHook) (LogLevel, const char *, va_list)
 
typedef struct Settings Settings
 
typedef struct Statistics Statistics
 

Variables

EXTERN archetypeamulet_arch
 
const Faceblank_face
 
EXTERN sstring blocks_prayer
 
EXTERN archetypecrown_arch
 
EXTERN archetypeempty_archetype
 
const Faceempty_face
 
EXTERN int exiting
 
EXTERN artifactlistfirst_artifactlist
 
EXTERN mapstructfirst_map
 
EXTERN char first_map_ext_path [MAX_BUF]
 
EXTERN char first_map_path [MAX_BUF]
 
EXTERN playerfirst_player
 
EXTERN regionfirst_region
 
short freearr_x [SIZEOFFREE]
 
short freearr_y [SIZEOFFREE]
 
int freedir [SIZEOFFREE]
 
socket_structinit_sockets
 
EXTERN FILE * logfile
 
int maxfree [SIZEOFFREE]
 
EXTERN long nrofallowedstr
 
EXTERN long nrofartifacts
 
EXTERN long nroferrors
 
EXTERN long ob_count
 
uint32_t pticks
 
int reopen_logfile
 
EXTERN archetypering_arch
 
Settings settings
 
const Facesmooth_face
 
const char *const spell_mapping [SPELL_MAPPINGS]
 
const typedef char * sstring
 
Statistics statistics
 
uint32_t tick_duration
 
EXTERN long trying_emergency_save
 
const EXTERN char * undead_name
 

Detailed Description

Global type definitions and header inclusions.

Definition in file global.h.

Macro Definition Documentation

◆ EXTERN

#define EXTERN   extern

Define external variables. This is used in an ugly hack where EXTERN is re-defined to "" in 'init.c' in order to resolve missing symbols. Do not use this macro in new code.

Definition at line 15 of file global.h.

◆ FREE_AND_CLEAR

#define FREE_AND_CLEAR (   xyz)    { free(xyz); xyz = NULL; }

Free the pointer and then set it to NULL. This is generally done as a safety, and having this macro makes the code a bit cleaner when doing so.

Definition at line 193 of file global.h.

◆ FREE_AND_CLEAR_STR

#define FREE_AND_CLEAR_STR (   xyz)    { free_string(xyz); xyz = NULL; }

Release the shared string, and set it to NULL. Must not be NULL.

Definition at line 198 of file global.h.

◆ FREE_AND_CLEAR_STR_IF

#define FREE_AND_CLEAR_STR_IF (   xyz)    { if (xyz) { free_string(xyz); xyz = NULL; } }

Definition at line 200 of file global.h.

◆ FREE_AND_COPY

#define FREE_AND_COPY (   sv,
  nv 
)    { if (sv) free_string(sv); sv = add_string(nv); }

Release the shared string if not NULL, and make it a reference to nv.

Definition at line 204 of file global.h.

◆ FREE_AND_COPY_IF

#define FREE_AND_COPY_IF (   sv,
  nv 
)    { if (sv) free_string(sv); sv = nv ? add_string(nv) : NULL; }

Definition at line 206 of file global.h.

◆ GET_ANIM

#define GET_ANIM (   ob)    (ob->temp_animation ? ob->temp_animation : ob->animation)

Definition at line 164 of file global.h.

◆ GET_ANIM_ID

#define GET_ANIM_ID (   ob)    (ob->temp_animation ? ob->temp_animation->num : (ob->animation ? ob->animation->num : 0))

Definition at line 165 of file global.h.

◆ GET_ANIMATION

#define GET_ANIMATION (   ob,
  anim 
)    ((ob->temp_animation ? ob->temp_animation : ob->animation)->faces[anim])

Definition at line 163 of file global.h.

◆ MAX_TOTAL_EXPERIENCE

#define MAX_TOTAL_EXPERIENCE   (settings.permanent_exp_ratio ? (MAX_EXPERIENCE * 100 / settings.permanent_exp_ratio) : 0)

Definition at line 231 of file global.h.

◆ NAMLEN

#define NAMLEN (   dirent)    strlen((dirent)->d_name)

Definition at line 211 of file global.h.

◆ NUM_ANIMATIONS

#define NUM_ANIMATIONS (   ob)    ((ob->temp_animation ? ob->temp_animation : ob->animation)->num_animations)

Definition at line 171 of file global.h.

◆ NUM_FACINGS

#define NUM_FACINGS (   ob)    ((ob->temp_animation ? ob->temp_animation : ob->animation)->facings)

Definition at line 172 of file global.h.

◆ PERM_EXP

#define PERM_EXP (   exptotal)    (exptotal * settings.permanent_exp_ratio / 100 )

Convert saved total experience into permanent experience

Definition at line 230 of file global.h.

◆ PRINTF_ARGS

#define PRINTF_ARGS (   x,
 
)    __attribute__ ((format (printf, x, y)))

Used for printf-like functions, mostly LOG and draw_ext_info_format

Definition at line 40 of file global.h.

◆ PROFILE_BEGIN

#define PROFILE_BEGIN (   expr)
Value:
{ \
struct timespec _begin, _end; \
clock_gettime(CLOCK_MONOTONIC, &_begin); \
expr;

Definition at line 366 of file global.h.

◆ PROFILE_END

#define PROFILE_END (   var,
  expr 
)
Value:
clock_gettime(CLOCK_MONOTONIC, &_end); \
long var = timespec_diff(&_end, &_begin); \
expr; }

Definition at line 371 of file global.h.

◆ ROTATE_RIGHT

#define ROTATE_RIGHT (   c)    if ((c)&01) (c) = ((c)>>1)+0x80000000; else (c) >>= 1;

Definition at line 160 of file global.h.

◆ SCRIPT_FIX_ACTIVATOR

#define SCRIPT_FIX_ACTIVATOR   2

Definition at line 381 of file global.h.

◆ SCRIPT_FIX_ALL

#define SCRIPT_FIX_ALL   1

Definition at line 382 of file global.h.

◆ SCRIPT_FIX_NOTHING

#define SCRIPT_FIX_NOTHING   0

Definition at line 383 of file global.h.

◆ SET_ANIMATION

#define SET_ANIMATION (   ob,
  newanim 
)    { ob->face = (ob->temp_animation ? ob->temp_animation : ob->animation)->faces[newanim]; }

Definition at line 162 of file global.h.

◆ SPELL_MAPPINGS

#define SPELL_MAPPINGS   206

Definition at line 148 of file global.h.

Typedef Documentation

◆ collectorHook

typedef void(* collectorHook) (BufferReader *, const char *)

Definition at line 233 of file global.h.

◆ fatalHook

typedef void(* fatalHook) (enum fatal_error err)

Definition at line 234 of file global.h.

◆ linked_char

typedef struct linked_char linked_char

◆ logHook

typedef void(* logHook) (LogLevel, const char *, va_list)

Definition at line 235 of file global.h.

◆ Settings

typedef struct Settings Settings

Server settings.

◆ Statistics

typedef struct Statistics Statistics

This is used for various performance tracking statistics, or just how often certain events are done. It is much better to use a common structure then variables about. Note that since these are often counters, I'm using uint64s - this may be overkill, but it is just a couple extra bytes. This is initialized/declared in common/init.c. Note that if it only contains integer values, very easy to initialize/clear it - just a memset.

Variable Documentation

◆ amulet_arch

EXTERN archetype * amulet_arch

Definition at line 155 of file global.h.

◆ blank_face

const Face* blank_face

Following can just as easily be pointers, but it is easier to keep them like this.

Definition at line 36 of file image.cpp.

Referenced by add_abilities(), animate_object(), artifact_get_face(), Faces::Faces(), knowledge_monster_face(), magic_mapping_mark(), magic_mapping_mark_recursive(), object_clear(), recipe_get_face(), tear_down_wall(), update_position(), and write_rune().

◆ blocks_prayer

EXTERN sstring blocks_prayer

For update_position() mostly.

Definition at line 157 of file global.h.

◆ crown_arch

EXTERN archetype * crown_arch

Definition at line 155 of file global.h.

◆ empty_archetype

EXTERN archetype* empty_archetype

Nice to have fast access to it.

Definition at line 143 of file global.h.

◆ empty_face

const Face * empty_face

Definition at line 177 of file global.h.

◆ exiting

EXTERN int exiting

True if the game is about to exit.

Definition at line 139 of file global.h.

◆ first_artifactlist

EXTERN artifactlist* first_artifactlist

First artifact.

Definition at line 121 of file global.h.

◆ first_map

EXTERN mapstruct* first_map

First map.

Definition at line 119 of file global.h.

◆ first_map_ext_path

EXTERN char first_map_ext_path[MAX_BUF]

Path used for per-race start maps.

Definition at line 145 of file global.h.

◆ first_map_path

EXTERN char first_map_path[MAX_BUF]

The start-level.

Definition at line 144 of file global.h.

◆ first_player

EXTERN player* first_player

First player.

Definition at line 118 of file global.h.

◆ first_region

EXTERN region* first_region

First region.

Definition at line 120 of file global.h.

◆ freearr_x

short freearr_x[SIZEOFFREE]

X offset when searching around a spot.

Definition at line 299 of file object.cpp.

Referenced by animate_bomb(), animate_weapon(), AnimationControl::AnimationControl(), apply_builder_floor(), apply_builder_remove(), apply_map_builder(), attempt_jump(), can_see_monsterP(), cast_cause_disease(), cast_cone(), cast_create_obj(), cast_light(), cast_polymorph(), cast_raise_dead_spell(), cast_spell(), cast_transfer(), cfapi_object_insert(), command_summon(), command_teleport(), common_process_projectile(), counterspell(), create_bomb(), dimension_door(), dispel_rune(), do_follow(), do_harvest(), do_skill_ident(), do_throw(), enter_map(), expand_sight(), explosion(), find_closest_monster(), find_doors_in_room_recursive(), find_enclosed_spot(), find_monster_in_room_recursive(), find_spot_in_room_recursive(), find_target_for_friendly_spell(), find_traps(), fix_summon_pet(), forklightning(), gate_type_process(), get_pointed_target(), hideability(), hit_map(), keyplace(), magic_wall(), mimic_type_apply(), monster_communicate(), monster_compute_path(), monster_find_nearest_enemy(), monster_use_bow(), move_ball_spell(), move_bolt(), move_cone(), move_ob(), move_player_attack(), move_player_mover(), move_swarm_spell(), object_find_first_free_spot(), object_find_free_spot(), object_insert_to_free_spot_or_free(), path_to_player(), pets_follow_owner(), pets_get_enemy(), pets_move(), pets_summon_golem(), pets_summon_object(), pick_arrow_target(), pick_lock(), place_chest(), place_exits(), place_fountain_with_specials(), place_monsters(), place_special_exit(), player_fire_bow(), polymorph_living(), probe(), push_ob(), put_a_monster(), remove_adjacent_doors(), remove_door(), remove_locked_door(), remove_trap(), roll_ob(), shop_mat_type_move_on(), singing(), skill_attack(), spell_find_dir(), stand_near_hostile(), steal(), surround_by_doors(), teleport(), transfer_ob(), turn_one_transport(), use_oratory(), and write_rune().

◆ freearr_y

short freearr_y[SIZEOFFREE]

Definition at line 174 of file global.h.

◆ freedir

int freedir[SIZEOFFREE]

Definition at line 175 of file global.h.

◆ init_sockets

socket_struct* init_sockets

Established connections for clients not yet playing. See the page on the login process for a description of its use. Socket at index 0 is the socket listening for connections, and must not be freed. If this socket becomes invalid, then the server will try to reopen it.

Definition at line 58 of file init.cpp.

Referenced by block_until_new_connection(), do_server(), free_all_newserver(), init_server(), and new_connection().

◆ logfile

EXTERN FILE* logfile

Used by server/daemon.c

Definition at line 137 of file global.h.

◆ maxfree

int maxfree[SIZEOFFREE]

Number of spots around a location, including that location (except for 0)

Definition at line 311 of file object.cpp.

Referenced by object_find_free_spot().

◆ nrofallowedstr

EXTERN long nrofallowedstr

Only used in malloc_info().

Definition at line 141 of file global.h.

◆ nrofartifacts

EXTERN long nrofartifacts

Only used in malloc_info().

Definition at line 140 of file global.h.

◆ nroferrors

EXTERN long nroferrors

If it exceeds MAX_ERRORS, call fatal()

Definition at line 129 of file global.h.

◆ ob_count

EXTERN long ob_count

Definition at line 147 of file global.h.

◆ pticks

uint32_t pticks

Used by various function to determine how often to save the character

Number of ticks since time reset

Definition at line 47 of file time.cpp.

Referenced by apply_race_and_class(), check_login(), do_specials(), get_tod(), handle_newcs_player(), key_change_class(), process_players1(), reset_sleep(), send_tick(), tick_game_time(), and time_info().

◆ reopen_logfile

int reopen_logfile

Definition at line 26 of file logger.cpp.

Referenced by LOG(), and rec_sighup().

◆ ring_arch

EXTERN archetype* ring_arch

Definition at line 155 of file global.h.

◆ settings

Settings settings

Server settings.

Definition at line 139 of file init.cpp.

Referenced by CREFilterDialog::accept(), CREReportDialog::accept(), account_block_create(), account_char_load_from_file(), account_char_save(), account_new_cmd(), accounts_load(), accounts_save(), add_me_cmd(), add_player_exp(), add_server_collect_hooks(), apply_check_item_power(), apply_check_personalized_blessings(), apply_death_exp_penalty(), apply_race_and_class(), AssetOriginAndCreationDialog::AssetOriginAndCreationDialog(), assets_collect(), attack_ob_simple(), attempt_steal(), block_until_new_connection(), calc_perm_exp(), calc_skill_exp(), cast_create_town_portal(), cast_spell(), cctk_init_std_archetypes(), cctk_setdatadir(), cctk_setlog(), cfapi_system_directory(), cfcitybell_init(), change_abil(), check_exp_loss(), check_login(), check_pick(), check_probe(), check_race_and_class(), checkbanned(), checkdm(), citylife_init(), clean_tmp_files(), CREMapInformationManager::clearCache(), CREMainWindow::closeEvent(), command_abil(), command_addexp(), command_banish(), command_create(), command_debug(), command_help(), command_loadtest(), command_nowiz(), command_patch(), command_players(), command_purge_quest_definitions(), command_search_items(), command_settings(), command_title(), compute_price_variation_with_bargaining(), convert_item(), create_items_path(), create_overlay_pathname(), create_pathname(), create_player_cmd(), create_template_pathname(), CREMainWindow::createMenus(), CREExperienceWindow::CREExperienceWindow(), CREFilterDialog::CREFilterDialog(), CREMainWindow::CREMainWindow(), CREReportDialog::CREReportDialog(), CRESettingsDialog::CRESettingsDialog(), crypt_string(), dead_player(), delete_character(), display_motd(), do_symptoms(), do_throw(), dragon_eat_flesh(), dump_experience(), enter_exit(), enter_player_maplevel(), enter_player_savebed(), exp_level(), FaceMakerDialog::FaceMakerDialog(), fatal(), CREMainWindow::fillFacesets(), find_help_file_in(), find_maps(), find_spot_for_submap(), find_style(), MessageManager::findPrePost(), fix_object(), fix_player(), forbid_play(), free_globals(), free_server(), get_cha_bonus(), get_cleric_chance(), get_con_bonus(), get_dam_bonus(), get_dex_bonus(), get_fear_bonus(), get_grace_bonus(), get_learn_spell(), get_sp_bonus(), get_speed_bonus(), get_thaco_bonus(), get_turn_bonus(), get_weight_limit(), god_enchants_weapon(), help_topics(), ChangesDock::helpReady(), hiscore_init(), hit_player(), i18n_init(), improve_armour(), improve_weapon(), CREPixmap::init(), init_beforeplay(), init_book_archive(), init_clocks(), init_emergency_mappath(), init_environ(), init_experience(), init_globals(), init_library(), init_modules(), init_server(), init_startup(), init_stats(), initPlugins(), is_legal_2ways_exit(), key_change_class(), key_confirm_quit(), kill_object(), kill_player(), kill_player_not_permadeath(), kill_player_permadeath(), knowledge_read_player_data(), knowledge_write_player_data(), level_exp(), list_players(), ResourcesManager::load(), load_assets(), load_settings(), load_table_float(), load_table_int(), CREMapInformationManager::loadCache(), MessageManager::loadDirectory(), LOG(), main(), map_remove_unique_files(), mapfile_load(), metaserver2_init(), monsterFight(), object_clear(), CREMainWindow::onReportQuests(), CREMainWindow::onToolReloadAssets(), MessageFile::parseFile(), pay_for_item(), pick_up_object(), player_lvl_adj(), plugins_init_plugin(), process_events(), process_players1(), quest_read_player_data(), quest_write_player_data(), random_house_generator_init(), rangetostring(), read_map_log(), ready_map_name(), resurrect_player(), roll_stats(), MessageFile::save(), save_map(), save_player(), scroll_failure(), scroll_type_apply(), send_exp_table(), send_file(), send_new_char_info(), send_news(), send_rules(), set_abs_magic(), set_confdir(), set_csport(), set_datadir(), set_debug(), set_disable_plugin(), set_dumpmon1(), set_dumpmon2(), set_dumpmon3(), set_dumpmon4(), set_dumpmon5(), set_dumpmon6(), set_dumpmon7(), set_dumpmon8(), set_dumpmon9(), set_dumpmont(), set_ignore_assets_errors(), set_localdir(), set_logfile(), set_mapdir(), set_mondebug(), set_playerdir(), set_regions(), set_templatedir(), set_tmpdir(), set_uniquedir(), CREPixmap::setFaceset(), setup(), CREPixmap::setUseFacesetFallback(), show_skills(), SP_level_spellpoint_cost(), spell_failure(), spellbook_type_apply(), START_TEST(), CREMapInformationManager::storeCache(), swap_map(), town_portal_destroy_existing(), unset_debug(), CREResourcesWindow::updateFilters(), CREResourcesWindow::updateReports(), verify_player(), while(), write_book_archive(), write_map_log(), write_scroll(), and write_todclock().

◆ smooth_face

const Face* smooth_face

Definition at line 36 of file image.cpp.

Referenced by Faces::Faces(), and send_smooth().

◆ spell_mapping

const char* const spell_mapping[SPELL_MAPPINGS]

This table is only necessary to convert objects that existed before the spell object conversion to the new object. It was not practical to go through every mapping looking for every potion, rod, wand, etc that had a sp set and update to the new value. So this maps the old spell numbers to the name of the new archs. If you are adding a new spell, you should not modify this - your new spell won't have been used, and thus won't have any legacy object. NULL entries in this table are valid - to denote objects that should not be updated for whatever reason.

Todo:
is this still required? it's used, but can it happen?

Definition at line 74 of file object.cpp.

Referenced by fix_generated_item(), and local_check_loaded_object().

◆ sstring

const typedef char* sstring

Strings that should be manipulated through add_string() and free_string().

Definition at line 43 of file global.h.

Referenced by add_abilities(), add_object_to_socklist(), add_one_item(), adjust_sign_msg(), append_spell(), apply_check_race_restrictions(), ResourcesManager::archetypeUse(), cf_add_string(), cf_archetype_get_name(), cf_find_string(), cf_map_get_sstring_property(), cf_object_get_msg(), cf_object_get_sstring_property(), cf_party_get_name(), cf_party_get_password(), cf_player_get_ip(), cf_query_name_pl(), cf_region_get_jail_path(), cf_region_get_longname(), cf_region_get_message(), cf_region_get_name(), cfapi_archetype_get_property(), cfapi_generate_random_map(), cfapi_map_get_map_property(), cfapi_object_get_property(), cfapi_party_get_property(), cfapi_player_quest(), cfapi_region_get_property(), cfapi_system_add_string(), cfapi_system_find_string(), cfapi_system_remove_string(), change_book(), command_cast_spell(), command_rename_item(), command_reset(), compilePython(), do_exit_map(), do_harvest(), esrv_add_spells(), esrv_update_item(), examine(), find_artifact(), initapplyobject(), initdropobject(), initpickupobject(), knowledge_read(), mon_info_msg(), monster_move_randomly(), move_aura(), object_give_identified_properties(), object_handle_death_animation(), object_matches_string(), CREMainWindow::onReportDuplicate(), play_sound_player_only(), Player_QuestGetState(), Player_QuestSetState(), Player_QuestStart(), Player_QuestWasCompleted(), process_object(), reportSummon(), runapplyobject(), rundropobject(), runpickupobject(), scroll_type_apply(), set_object_face_main(), set_object_face_other(), SP_level_wc_adjust(), spell_consume_items(), START_TEST(), stringbuffer_finish_shared(), and ArchetypeWrapper::uses().

◆ statistics

Statistics statistics

Merged spell statistics.

Definition at line 232 of file init.cpp.

Referenced by init_globals(), main(), object_merge_spell(), and ok_to_put_more().

◆ tick_duration

uint32_t tick_duration

◆ trying_emergency_save

EXTERN long trying_emergency_save

True when emergency_save() is reached.

Definition at line 128 of file global.h.

◆ undead_name

const EXTERN char* undead_name

Definition at line 156 of file global.h.

timespec_diff
long timespec_diff(struct timespec *end, struct timespec *start)
Definition: time.cpp:163