Crossfire Server, Trunk  1.75.0
global.h
Go to the documentation of this file.
1 
6 #ifndef GLOBAL_H
7 #define GLOBAL_H
8 
14 #ifndef EXTERN
15 #define EXTERN extern
16 #endif
17 
18 /* Include this first, because it lets us know what we are missing */
19 #if defined(WIN32) || defined(_WIN32) || defined(WIN64)
20 #include "win32.h"
21 #else
22 #include "autoconf.h"
23 /* socklen_t is defined in this file on some systems, and that type is
24  * used in newserver.h, which is used in all other files
25  */
26 #include <sys/socket.h>
30 #include <sys/time.h>
31 #endif
32 
33 #ifdef HAVE_LIBDMALLOC
34 #include <dmalloc.h>
35 #endif
36 
37 #include <inttypes.h>
38 #include <stdbool.h>
39 #include <stdio.h>
40 #include <unistd.h>
41 #include "compat.h"
42 #include <time.h>
43 #include <vector>
44 #include <stdarg.h>
45 #include <algorithm>
46 #include <functional>
47 #include <string>
48 
50 #define PRINTF_ARGS(x, y) __attribute__ ((format (printf, x, y)))
51 
53 #include "sstring.h"
54 
55 #include "config.h"
56 #include "define.h"
57 #include "logger.h"
58 #include "shared/newclient.h"
59 
60 /* This blob, in this order, is needed to actually define maps */
61 #include "face.h"
62 /* Include the basic defines from spells.h */
63 #include "attack.h" /* needs to be before material.h */
64 #include "material.h"
65 #include "living.h"
66 #include "object.h"
67 #include "map.h"
68 #include "tod.h"
69 
70 #include "skills.h"
71 
72 /* Opaque handle to a player-selectable language */
73 typedef void *language_t;
74 
75 /* This defines the Account_Char structure which is used in the socket */
76 #include "account_char.h"
77 
78 /* Pull in the socket structure - used in the player structure */
79 #include "newserver.h"
80 
81 #include "party.h"
82 
83 /* Pull in the player structure */
84 #include "player.h"
85 
86 /* pull in treasure structure */
87 #include "treasure.h"
88 
89 #include "commands.h"
90 
91 /* pull in book structures */
92 #include "book.h"
93 
94 /* ob_methods and ob_types subsystem */
95 #include "ob_methods.h"
96 #include "ob_types.h"
97 
98 /*
99  * So far only used when dealing with artifacts.
100  * (now used by alchemy and other code too. Nov 95 b.t).
101  */
102 struct linked_char {
103  const char *name;
104  struct linked_char *next;
105 };
106 
107 
108 /* Pull in artifacts */
109 #include "artifact.h"
110 
111 /* Now for gods */
112 #include "god.h"
113 
114 /* Now for recipe/alchemy */
115 #include "recipe.h"
116 
117 /* Now for spells */
118 #include "spells.h"
119 
120 /*****************************************************************************
121  * GLOBAL VARIABLES: *
122  *****************************************************************************/
123 
130 EXTERN std::vector<region *> all_regions;
133 
134 /*
135  * Variables set by different flags (see init.c):
136  */
137 
141 extern uint32_t pticks;
148 extern int reopen_logfile;
158 #define SPELL_MAPPINGS 206
159 extern const char *const spell_mapping[SPELL_MAPPINGS];
162 EXTERN const char *undead_name;
165 /* Rotate right from bsd sum. This is used in various places for checksumming */
166 #define ROTATE_RIGHT(c) if ((c)&01) (c) = ((c)>>1)+0x80000000; else (c) >>= 1;
167 
168 #define SET_ANIMATION(ob, newanim) { ob->face = (ob->temp_animation ? ob->temp_animation : ob->animation)->faces[newanim]; }
169 #define GET_ANIMATION(ob, anim) ((ob->temp_animation ? ob->temp_animation : ob->animation)->faces[anim])
170 #define GET_ANIM(ob) (ob->temp_animation ? ob->temp_animation : ob->animation)
171 #define GET_ANIM_ID(ob) (ob->temp_animation ? ob->temp_animation->num : (ob->animation ? ob->animation->num : 0))
172 /* NUM_ANIMATIONS returns the number of animations allocated. The last
173  * usuable animation will be NUM_ANIMATIONS-1 (for example, if an object
174  * has 8 animations, NUM_ANIMATIONS will return 8, but the values will
175  * range from 0 through 7.
176  */
177 #define NUM_ANIMATIONS(ob) ((ob->temp_animation ? ob->temp_animation : ob->animation)->num_animations)
178 #define NUM_FACINGS(ob) ((ob->temp_animation ? ob->temp_animation : ob->animation)->facings)
179 
182 
183 extern const Face *blank_face, *empty_face;
184 extern const Face *smooth_face;
185 
186 extern uint32_t tick_duration; /* loop time */
188 
189 #include "stringbuffer.h"
190 #include "libproto.h"
191 #include "sockproto.h"
192 #include "typesproto.h"
193 
199 #define FREE_AND_CLEAR(xyz) { free(xyz); xyz = NULL; }
200 
204 #define FREE_AND_CLEAR_STR(xyz) { free_string(xyz); xyz = NULL; }
205 
206 #define FREE_AND_CLEAR_STR_IF(xyz) { if (xyz) { free_string(xyz); xyz = NULL; } }
207 
210 #define FREE_AND_COPY(sv, nv) { if (sv) free_string(sv); sv = add_string(nv); }
211 
212 #define FREE_AND_COPY_IF(sv, nv) { if (sv) free_string(sv); sv = nv ? add_string(nv) : NULL; }
213 
214 #ifndef WIN32 /* ---win32 we define this stuff in win32.h */
215 #if HAVE_DIRENT_H
216 # include <dirent.h>
217 # define NAMLEN(dirent) strlen((dirent)->d_name)
218 #else
219 # define dirent direct
220 # define NAMLEN(dirent) (dirent)->d_namlen
221 # if HAVE_SYS_NDIR_H
222 # include <sys/ndir.h>
223 # endif
224 # if HAVE_SYS_DIR_H
225 # include <sys/dir.h>
226 # endif
227 # if HAVE_NDIR_H
228 # include <ndir.h>
229 # endif
230 #endif
231 #endif
232 
236 #define PERM_EXP(exptotal) (exptotal * settings.permanent_exp_ratio / 100 )
237 #define MAX_TOTAL_EXPERIENCE (settings.permanent_exp_ratio ? (MAX_EXPERIENCE * 100 / settings.permanent_exp_ratio) : 0)
238 
239 typedef std::function<void(enum fatal_error err)> fatalHook;
240 typedef std::function<void(LogLevel, const char *, va_list)> logHook;
241 
245 struct Settings {
246  const char *logfilename;
247  uint16_t csport;
250  uint8_t dumpvalues;
251  const char *dumparg;
252  const char *confdir;
253  const char *datadir;
254  const char *localdir;
255  const char *playerdir;
256  const char *mapdir;
257  const char *regions;
258  const char *uniquedir;
259  const char *templatedir;
260  const char *tmpdir;
262  int16_t pk_luck_penalty;
267  uint8_t not_permadeth;
268  uint8_t simple_exp;
270  uint8_t set_title;
271  uint8_t resurrection;
272  uint8_t search_items;
275  uint8_t casting_time;
276  uint8_t real_wiz;
278  uint8_t always_show_hp;
280  uint16_t set_friendly_fire;
283  const char *motd;
284  const char *rules;
285  const char *news;
287  /* The meta_ is information for the metaserver. These are set in
288  * the lib/settings file.
289  */
290  unsigned int meta_on:1;
293  uint16_t meta_port;
296  uint32_t worldmapstartx;
297  uint32_t worldmapstarty;
298  uint32_t worldmaptilesx;
299  uint32_t worldmaptilesy;
300  uint8_t fastclock;
305  int16_t max_level;
327  uint8_t max_stat;
332  uint8_t crypt_mode;
333  uint8_t min_name;
337  char* stat_file;
338 };
339 
343 extern Settings settings;
344 
355 struct Statistics {
356  uint64_t spell_merges;
357  uint64_t spell_hash_full;
359 };
360 
364 extern Statistics statistics;
365 
366 #define PROFILE_BEGIN(expr) { \
367  struct timespec _begin, _end; \
368  clock_gettime(CLOCK_MONOTONIC, &_begin); \
369  expr;
370 
371 #define PROFILE_END(var, expr) \
372  clock_gettime(CLOCK_MONOTONIC, &_end); \
373  long var = timespec_diff(&_end, &_begin); \
374  expr; }
375 
381 #define SCRIPT_FIX_ACTIVATOR 2
382 #define SCRIPT_FIX_ALL 1
383 #define SCRIPT_FIX_NOTHING 0
384 
386 #include "events.h"
387 
388 #endif /* GLOBAL_H */
Settings::casting_time
uint8_t casting_time
It takes awhile to cast a spell.
Definition: global.h:275
Face
New face structure - this enforces the notion that data is face by face only - you can not change the...
Definition: face.h:14
Settings::special_break_map
uint8_t special_break_map
If set, then submaps in random maps can break the walls.
Definition: global.h:328
Settings::meta_comment
char meta_comment[MAX_BUF]
Comment we send to the metaserver.
Definition: global.h:294
SPELL_MAPPINGS
#define SPELL_MAPPINGS
Definition: global.h:158
Settings::mapdir
const char * mapdir
Where the map files are.
Definition: global.h:256
Settings::meta_server
char meta_server[MAX_BUF]
Hostname/ip addr of the metaserver.
Definition: global.h:291
Settings::simple_exp
uint8_t simple_exp
If true, use the simple experience system.
Definition: global.h:268
empty_face
const Face * empty_face
Definition: global.h:183
Settings::max_level
int16_t max_level
This is read out of exp_table.
Definition: global.h:305
Settings::recycle_tmp_maps
uint8_t recycle_tmp_maps
Re-use tmp maps.
Definition: global.h:277
Settings::emergency_y
uint16_t emergency_y
Coordinates to use on that map.
Definition: global.h:303
Settings::regions
const char * regions
Name of the regions file - libdir is prepended.
Definition: global.h:257
Settings::allow_broken_converters
int allow_broken_converters
If set, converters will work even if price of generated item is higher than the price of converted it...
Definition: global.h:319
init_sockets
socket_struct * init_sockets
Established connections for clients not yet playing.
Definition: init.cpp:66
Settings::log_timestamp_format
char * log_timestamp_format
Format for timestap, if log_timestamp is set.
Definition: global.h:322
language_t
void * language_t
Strings that should be manipulated through add_string() and free_string().
Definition: global.h:73
Settings::armor_speed_linear
uint8_t armor_speed_linear
If 1, speed improvement is linear, else exponantiel.
Definition: global.h:312
player
One player.
Definition: player.h:107
settings
Settings settings
Global settings.
Definition: init.cpp:139
Settings::resurrection
uint8_t resurrection
Ressurection possible w/ permadeth on.
Definition: global.h:271
Statistics::spell_merges
uint64_t spell_merges
Number of spell merges done.
Definition: global.h:356
logfile
EXTERN FILE * logfile
Used by server/daemon.c.
Definition: global.h:147
win32.h
sockproto.h
Settings::set_title
uint8_t set_title
Players can set thier title.
Definition: global.h:270
face.h
Settings::ignore_plugin_compatibility
uint8_t ignore_plugin_compatibility
If set, don't check plugin version.
Definition: global.h:329
socket_struct
Socket structure, represents a client-server connection.
Definition: newserver.h:93
logger.h
Settings::not_permadeth
uint8_t not_permadeth
If true, death is non-permament.
Definition: global.h:267
smooth_face
const Face * smooth_face
Definition: image.cpp:36
Settings::permanent_exp_ratio
uint8_t permanent_exp_ratio
How much exp should be 'permenant' and unable to be lost.
Definition: global.h:263
Settings::crypt_mode
uint8_t crypt_mode
0 for legacy behavior, 1 for always Traditional
Definition: global.h:332
Settings::dumpvalues
uint8_t dumpvalues
Set to dump various values/tables.
Definition: global.h:250
Settings::datadir
const char * datadir
Read only data files.
Definition: global.h:253
first_map_path
EXTERN char first_map_path[MAX_BUF]
The start-level.
Definition: global.h:154
exiting
EXTERN int exiting
True if the game is about to exit.
Definition: global.h:149
recipe.h
god.h
Settings::worldmaptilesy
uint32_t worldmaptilesy
Number of tiles high the worldmap is.
Definition: global.h:299
Settings::min_name
uint8_t min_name
Minimum characters for an account or player name.
Definition: global.h:333
Settings::worldmapstartx
uint32_t worldmapstartx
Starting x tile for the worldmap.
Definition: global.h:296
typesproto.h
first_artifactlist
EXTERN artifactlist * first_artifactlist
First artifact.
Definition: global.h:131
Settings::starting_stat_min
uint8_t starting_stat_min
Minimum value of a starting stat.
Definition: global.h:323
artifact.h
Settings::assets_tracker
class AssetsTracker * assets_tracker
If not NULL, called each time an asset is defined.
Definition: global.h:335
Settings::roll_stat_points
uint8_t roll_stat_points
How many stat points legacy (rolled) chars start with.
Definition: global.h:326
Settings::pk_luck_penalty
int16_t pk_luck_penalty
Amount by which player luck is reduced if they PK.
Definition: global.h:262
Settings::stat_file
char * stat_file
Definition: global.h:337
Settings::emergency_x
uint16_t emergency_x
Definition: global.h:303
skills.h
empty_archetype
EXTERN archetype * empty_archetype
Nice to have fast access to it.
Definition: global.h:153
first_map
EXTERN mapstruct * first_map
First map.
Definition: global.h:129
Settings::csport
uint16_t csport
Port for new client/server.
Definition: global.h:247
Statistics
This is used for various performance tracking statistics, or just how often certain events are done.
Definition: global.h:355
Statistics::spell_hash_full
uint64_t spell_hash_full
Number of times spell hash was full.
Definition: global.h:357
Settings::ignore_assets_errors
int ignore_assets_errors
If set then go on running even if there are errors in assets.
Definition: global.h:334
sstring.h
Settings::fatal_hook
fatalHook fatal_hook
If not NULL then called when fatal() is called.
Definition: global.h:336
all_regions
EXTERN std::vector< region * > all_regions
All regions.
Definition: global.h:130
maxfree
int maxfree[SIZEOFFREE]
Number of spots around a location, including that location (except for 0)
Definition: object.cpp:311
Settings::meta_host
char meta_host[MAX_BUF]
Hostname of this host.
Definition: global.h:292
linked_char
Definition: global.h:102
ob_count
EXTERN long ob_count
Definition: global.h:157
Settings::worldmaptilesx
uint32_t worldmaptilesx
Number of tiles wide the worldmap is.
Definition: global.h:298
Settings::pk_max_experience
int64_t pk_max_experience
Maximum experience one can get for PKing.
Definition: global.h:316
undead_name
const EXTERN char * undead_name
Used in hit_player() in main.c.
Definition: global.h:162
Settings::log_callback
logHook log_callback
Log hook, to intercept log messages.
Definition: global.h:249
Settings::spell_encumbrance
uint8_t spell_encumbrance
Encumbrance effects spells.
Definition: global.h:273
stringbuffer.h
Settings::meta_port
uint16_t meta_port
Port number to use for updates.
Definition: global.h:293
nrofartifacts
EXTERN long nrofartifacts
Only used in malloc_info().
Definition: global.h:150
Settings::balanced_stat_loss
uint8_t balanced_stat_loss
If true, Death stat depletion based on level etc.
Definition: global.h:266
Settings::debug
LogLevel debug
Default debugging level.
Definition: global.h:248
AssetsTracker
Base class to be informed of where an asset is defined.
Definition: AssetsTracker.h:24
events.h
Settings::pk_max_experience_percent
int pk_max_experience_percent
Percentage of experience of victim the killer gets.
Definition: global.h:317
linked_char::name
const char * name
Definition: global.h:103
blank_face
const Face * blank_face
Following can just as easily be pointers, but it is easier to keep them like this.
Definition: image.cpp:36
attack.h
Settings::death_penalty_ratio
uint8_t death_penalty_ratio
Hhow much exp should be lost at death.
Definition: global.h:264
statistics
Statistics statistics
Merged spell statistics.
Definition: init.cpp:227
Settings::set_friendly_fire
uint16_t set_friendly_fire
Percent of damage done by peaceful player vs player damage.
Definition: global.h:280
Settings::account_block_create
uint8_t account_block_create
Definition: global.h:330
Settings::motd
const char * motd
Name of the motd file.
Definition: global.h:283
Settings::logfilename
const char * logfilename
Logfile to use.
Definition: global.h:246
Settings::worldmapstarty
uint32_t worldmapstarty
Starting y tile for the worldmap.
Definition: global.h:297
party.h
compat.h
material.h
Settings::rules
const char * rules
Name of rules file.
Definition: global.h:284
Settings::armor_weight_reduction
int armor_weight_reduction
Weight reduction per enchantment.
Definition: global.h:309
Settings::news
const char * news
Name of news file.
Definition: global.h:285
first_player
EXTERN player * first_player
First player.
Definition: global.h:128
Settings::stat_loss_on_death
uint8_t stat_loss_on_death
If true, chars lose a random stat when they die.
Definition: global.h:261
book.h
linked_char::next
struct linked_char * next
Definition: global.h:104
artifactlist
This represents all archetypes for one particular object type.
Definition: artifact.h:24
Settings::item_power_factor
float item_power_factor
See note in setings file.
Definition: global.h:306
freearr_y
short freearr_y[SIZEOFFREE]
Definition: global.h:180
Settings::dumparg
const char * dumparg
Additional argument for some dump functions.
Definition: global.h:251
archetype
The archetype structure is a set of rules on how to generate and manipulate objects which point to ar...
Definition: object.h:483
Settings::confdir
const char * confdir
Configuration files.
Definition: global.h:252
nroferrors
EXTERN long nroferrors
If it exceeds MAX_ERRORS, call fatal()
Definition: global.h:139
blocks_prayer
EXTERN sstring blocks_prayer
For update_position() mostly.
Definition: global.h:163
Settings::death_penalty_level
uint8_t death_penalty_level
How many levels worth of exp may be lost on one death.
Definition: global.h:265
map.h
Settings::reset_loc_time
int reset_loc_time
Number of seconds to put player back at home.
Definition: global.h:269
SIZEOFFREE
#define SIZEOFFREE
Definition: define.h:155
treasure.h
MAX_BUF
#define MAX_BUF
Used for all kinds of things.
Definition: define.h:35
Statistics::spell_suppressions
uint64_t spell_suppressions
Number of times ok_to_put_more() returned FALSE.
Definition: global.h:358
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 th...
Definition: object.cpp:74
Settings::playerdir
const char * playerdir
Where the player files are.
Definition: global.h:255
Settings::spell_failure_effects
uint8_t spell_failure_effects
Nasty backlash to spell failures.
Definition: global.h:274
Settings::starting_stat_points
uint8_t starting_stat_points
How many stat points character starts with.
Definition: global.h:325
freearr_x
short freearr_x[SIZEOFFREE]
X offset when searching around a spot.
Definition: object.cpp:299
Settings
Server settings.
Definition: global.h:245
ob_types.h
Settings::meta_on
unsigned int meta_on
True if we should send updates.
Definition: global.h:290
Settings::allow_denied_spells_writing
int allow_denied_spells_writing
If set, players can write spells they can't cast.
Definition: global.h:318
Settings::emergency_mapname
char * emergency_mapname
Map to return players to in emergency.
Definition: global.h:302
spells.h
Settings::who_wiz_format
char who_wiz_format[MAX_BUF]
The format that the who command should use when called by a dm.
Definition: global.h:282
EXTERN
#define EXTERN
Define external variables.
Definition: global.h:15
nrofallowedstr
EXTERN long nrofallowedstr
Only used in malloc_info().
Definition: global.h:151
Settings::spellpoint_level_depend
uint8_t spellpoint_level_depend
Spell costs go up with level.
Definition: global.h:279
Settings::fastclock
uint8_t fastclock
If true, clock goes warp 9.
Definition: global.h:300
player.h
newserver.h
mapstruct
This is a game-map.
Definition: map.h:320
sstring
const typedef char * sstring
Definition: sstring.h:2
Settings::personalized_blessings
uint8_t personalized_blessings
If 1, blessed weapons get an owner and a willpower value.
Definition: global.h:315
define.h
Settings::max_stat
uint8_t max_stat
Maximum stat value - 255 should be sufficient.
Definition: global.h:327
Settings::armor_max_enchant
int armor_max_enchant
Maximum number of times an armor can be enchanted.
Definition: global.h:308
Settings::armor_weight_linear
uint8_t armor_weight_linear
If 1, weight reduction is linear, else exponantiel.
Definition: global.h:310
first_map_ext_path
EXTERN char first_map_ext_path[MAX_BUF]
Path used for per-race start maps.
Definition: global.h:155
fatalHook
std::function< void(enum fatal_error err)> fatalHook
Definition: global.h:239
newclient.h
Settings::real_wiz
uint8_t real_wiz
Use mud-like wizards.
Definition: global.h:276
account_char.h
config.h
Settings::templatedir
const char * templatedir
Directory for the template map.
Definition: global.h:259
trying_emergency_save
EXTERN long trying_emergency_save
True when emergency_save() is reached.
Definition: global.h:138
fatal_error
fatal_error
Fatal variables; used as arguments to fatal().
Definition: define.h:47
logHook
std::function< void(LogLevel, const char *, va_list)> logHook
Definition: global.h:240
reopen_logfile
int reopen_logfile
Definition: logger.cpp:27
freedir
int freedir[SIZEOFFREE]
Definition: global.h:181
commands.h
pticks
uint32_t pticks
Used by various function to determine how often to save the character.
Definition: time.cpp:47
ob_methods.h
Settings::no_player_stealing
uint8_t no_player_stealing
If 1, can not steal from other players.
Definition: global.h:313
Settings::account_trusted_host
char * account_trusted_host
Block account creation for untrusted hosts.
Definition: global.h:331
Settings::search_items
uint8_t search_items
Search_items command.
Definition: global.h:272
LogLevel
LogLevel
Log levels for the LOG() function.
Definition: logger.h:10
Settings::tmpdir
const char * tmpdir
Directory to use for temporary files.
Definition: global.h:260
tod.h
tick_duration
uint32_t tick_duration
Gloabal variables:
Definition: time.cpp:35
Settings::always_show_hp
uint8_t always_show_hp
'probe' spell HP bars for all living things (0, 1, or 2)
Definition: global.h:278
Settings::create_home_portals
uint8_t create_home_portals
If 1, can create portals in unique maps (apartments)
Definition: global.h:314
living.h
Settings::armor_speed_improvement
int armor_speed_improvement
Speed improvement.
Definition: global.h:311
Settings::log_timestamp
int log_timestamp
If set, log will comport a timestamp.
Definition: global.h:321
Settings::who_format
char who_format[MAX_BUF]
The format that the who command should use.
Definition: global.h:281
object.h
libproto.h
autoconf.h
Settings::starting_stat_max
uint8_t starting_stat_max
Maximum value of a starting stat.
Definition: global.h:324
Settings::uniquedir
const char * uniquedir
Directory for the unique items.
Definition: global.h:258
Settings::localdir
const char * localdir
Read/write data files.
Definition: global.h:254