Crossfire Server, Trunk
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>
27 #endif
28 
29 #ifdef HAVE_LIBDMALLOC
30 #include <dmalloc.h>
31 #endif
32 
33 #include <inttypes.h>
34 #include <stdbool.h>
35 #include <stdio.h>
36 #include <unistd.h>
37 #include "compat.h"
38 #include <time.h>
39 #include <vector>
40 #include <stdarg.h>
41 #include <algorithm>
42 
44 #define PRINTF_ARGS(x, y) __attribute__ ((format (printf, x, y)))
45 
47 typedef const char *sstring;
48 
49 #include "config.h"
50 #include "define.h"
51 #include "logger.h"
52 #include "shared/newclient.h"
53 
54 /* This blob, in this order, is needed to actually define maps */
55 #include "face.h"
56 /* Include the basic defines from spells.h */
57 #include "attack.h" /* needs to be before material.h */
58 #include "material.h"
59 #include "living.h"
60 #include "object.h"
61 #include "map.h"
62 #include "tod.h"
63 
64 #include "skills.h"
65 
66 /* Opaque handle to a player-selectable language */
67 typedef void *language_t;
68 
69 /* This defines the Account_Char structure which is used in the socket */
70 #include "account_char.h"
71 
72 /* Pull in the socket structure - used in the player structure */
73 #include "newserver.h"
74 
75 #include "party.h"
76 
77 /* Pull in the player structure */
78 #include "player.h"
79 
80 /* pull in treasure structure */
81 #include "treasure.h"
82 
83 #include "commands.h"
84 
85 /* pull in book structures */
86 #include "book.h"
87 
88 /* ob_methods and ob_types subsystem */
89 #include "ob_methods.h"
90 #include "ob_types.h"
91 
92 /*
93  * So far only used when dealing with artifacts.
94  * (now used by alchemy and other code too. Nov 95 b.t).
95  */
96 struct linked_char {
97  const char *name;
98  struct linked_char *next;
99 };
100 
101 
102 /* Pull in artifacts */
103 #include "artifact.h"
104 
105 /* Now for gods */
106 #include "god.h"
107 
108 /* Now for recipe/alchemy */
109 #include "recipe.h"
110 
111 /* Now for spells */
112 #include "spells.h"
113 
114 /*****************************************************************************
115  * GLOBAL VARIABLES: *
116  *****************************************************************************/
117 
124 EXTERN std::vector<region *> all_regions;
127 
128 /*
129  * Variables set by different flags (see init.c):
130  */
131 
135 extern uint32_t pticks;
142 extern int reopen_logfile;
152 #define SPELL_MAPPINGS 206
153 extern const char *const spell_mapping[SPELL_MAPPINGS];
156 /*
157  * Used in treasure.c
158  */
160 EXTERN const char *undead_name; /* Used in hit_player() in main.c */
163 /* Rotate right from bsd sum. This is used in various places for checksumming */
164 #define ROTATE_RIGHT(c) if ((c)&01) (c) = ((c)>>1)+0x80000000; else (c) >>= 1;
165 
166 #define SET_ANIMATION(ob, newanim) { ob->face = (ob->temp_animation ? ob->temp_animation : ob->animation)->faces[newanim]; }
167 #define GET_ANIMATION(ob, anim) ((ob->temp_animation ? ob->temp_animation : ob->animation)->faces[anim])
168 #define GET_ANIM(ob) (ob->temp_animation ? ob->temp_animation : ob->animation)
169 #define GET_ANIM_ID(ob) (ob->temp_animation ? ob->temp_animation->num : (ob->animation ? ob->animation->num : 0))
170 /* NUM_ANIMATIONS returns the number of animations allocated. The last
171  * usuable animation will be NUM_ANIMATIONS-1 (for example, if an object
172  * has 8 animations, NUM_ANIMATIONS will return 8, but the values will
173  * range from 0 through 7.
174  */
175 #define NUM_ANIMATIONS(ob) ((ob->temp_animation ? ob->temp_animation : ob->animation)->num_animations)
176 #define NUM_FACINGS(ob) ((ob->temp_animation ? ob->temp_animation : ob->animation)->facings)
177 
180 
181 extern const Face *blank_face, *empty_face;
182 extern const Face *smooth_face;
183 
184 extern uint32_t tick_duration; /* loop time */
186 
187 #include "stringbuffer.h"
188 #include "libproto.h"
189 #include "sockproto.h"
190 #include "typesproto.h"
191 
197 #define FREE_AND_CLEAR(xyz) { free(xyz); xyz = NULL; }
198 
202 #define FREE_AND_CLEAR_STR(xyz) { free_string(xyz); xyz = NULL; }
203 
204 #define FREE_AND_CLEAR_STR_IF(xyz) { if (xyz) { free_string(xyz); xyz = NULL; } }
205 
208 #define FREE_AND_COPY(sv, nv) { if (sv) free_string(sv); sv = add_string(nv); }
209 
210 #define FREE_AND_COPY_IF(sv, nv) { if (sv) free_string(sv); sv = nv ? add_string(nv) : NULL; }
211 
212 #ifndef WIN32 /* ---win32 we define this stuff in win32.h */
213 #if HAVE_DIRENT_H
214 # include <dirent.h>
215 # define NAMLEN(dirent) strlen((dirent)->d_name)
216 #else
217 # define dirent direct
218 # define NAMLEN(dirent) (dirent)->d_namlen
219 # if HAVE_SYS_NDIR_H
220 # include <sys/ndir.h>
221 # endif
222 # if HAVE_SYS_DIR_H
223 # include <sys/dir.h>
224 # endif
225 # if HAVE_NDIR_H
226 # include <ndir.h>
227 # endif
228 #endif
229 #endif
230 
234 #define PERM_EXP(exptotal) (exptotal * settings.permanent_exp_ratio / 100 )
235 #define MAX_TOTAL_EXPERIENCE (settings.permanent_exp_ratio ? (MAX_EXPERIENCE * 100 / settings.permanent_exp_ratio) : 0)
236 
237 typedef void(*collectorHook)(BufferReader *, const char *);
238 typedef void(*fatalHook)(enum fatal_error err);
239 typedef void(*logHook)(LogLevel, const char *, va_list);
240 
244 struct Settings {
245  const char *logfilename;
246  uint16_t csport;
249  uint8_t dumpvalues;
250  const char *dumparg;
251  const char *confdir;
252  const char *datadir;
253  const char *localdir;
254  const char *playerdir;
255  const char *mapdir;
256  const char *regions;
257  const char *uniquedir;
258  const char *templatedir;
259  const char *tmpdir;
261  int16_t pk_luck_penalty;
266  uint8_t not_permadeth;
267  uint8_t simple_exp;
269  uint8_t set_title;
270  uint8_t resurrection;
271  uint8_t search_items;
274  uint8_t casting_time;
275  uint8_t real_wiz;
277  uint8_t always_show_hp;
279  uint16_t set_friendly_fire;
282  char motd[MAX_BUF];
283  const char *rules;
284  const char *news;
286  /* The meta_ is information for the metaserver. These are set in
287  * the lib/settings file.
288  */
289  unsigned int meta_on:1;
292  uint16_t meta_port;
295  uint32_t worldmapstartx;
296  uint32_t worldmapstarty;
297  uint32_t worldmaptilesx;
298  uint32_t worldmaptilesy;
299  uint32_t worldmaptilesizex;
300  uint32_t worldmaptilesizey;
301  uint8_t fastclock;
306  int16_t max_level;
328  uint8_t max_stat;
330  std::vector<char *> disabled_plugins;
334  uint8_t crypt_mode;
335  uint8_t min_name;
336  uint8_t hooks_count;
337  const char *hooks_filename[20];
343  void add_hook(const char *name, collectorHook hook) {
345  hooks [hooks_count] = hook;
346  ++hooks_count;
347  }
348 };
349 
353 extern Settings settings;
354 
365 struct Statistics {
366  uint64_t spell_merges;
367  uint64_t spell_hash_full;
369 };
370 
374 extern Statistics statistics;
375 
376 #define PROFILE_BEGIN(expr) { \
377  struct timespec _begin, _end; \
378  clock_gettime(CLOCK_MONOTONIC, &_begin); \
379  expr;
380 
381 #define PROFILE_END(var, expr) \
382  clock_gettime(CLOCK_MONOTONIC, &_end); \
383  long var = timespec_diff(&_end, &_begin); \
384  expr; }
385 
391 #define SCRIPT_FIX_ACTIVATOR 2
392 #define SCRIPT_FIX_ALL 1
393 #define SCRIPT_FIX_NOTHING 0
394 
396 #include "events.h"
397 
398 #endif /* GLOBAL_H */
Settings::casting_time
uint8_t casting_time
Definition: global.h:274
Face
Definition: face.h:14
Settings::special_break_map
uint8_t special_break_map
Definition: global.h:329
Settings::meta_comment
char meta_comment[MAX_BUF]
Definition: global.h:293
nrofallowedstr
EXTERN long nrofallowedstr
Definition: global.h:145
empty_archetype
EXTERN archetype * empty_archetype
Definition: global.h:147
Settings::mapdir
const char * mapdir
Definition: global.h:255
Settings::meta_server
char meta_server[MAX_BUF]
Definition: global.h:290
Settings::hooks_count
uint8_t hooks_count
Definition: global.h:336
Settings::simple_exp
uint8_t simple_exp
Definition: global.h:267
empty_face
const Face * empty_face
Definition: global.h:181
Settings::max_level
int16_t max_level
Definition: global.h:306
Settings::recycle_tmp_maps
uint8_t recycle_tmp_maps
Definition: global.h:276
Settings::emergency_y
uint16_t emergency_y
Definition: global.h:304
Settings::regions
const char * regions
Definition: global.h:256
Settings::allow_broken_converters
int allow_broken_converters
Definition: global.h:320
init_sockets
socket_struct * init_sockets
Definition: init.cpp:58
Settings::log_timestamp_format
char * log_timestamp_format
Definition: global.h:323
language_t
void * language_t
Definition: global.h:67
Settings::armor_speed_linear
uint8_t armor_speed_linear
Definition: global.h:313
player
Definition: player.h:105
settings
Settings settings
Definition: init.cpp:139
Settings::resurrection
uint8_t resurrection
Definition: global.h:270
Statistics::spell_merges
uint64_t spell_merges
Definition: global.h:366
win32.h
sockproto.h
Settings::set_title
uint8_t set_title
Definition: global.h:269
ob_count
EXTERN long ob_count
Definition: global.h:151
face.h
Settings::ignore_plugin_compatibility
uint8_t ignore_plugin_compatibility
Definition: global.h:331
socket_struct
Definition: newserver.h:89
logger.h
Settings::not_permadeth
uint8_t not_permadeth
Definition: global.h:266
smooth_face
const Face * smooth_face
Definition: image.cpp:36
Settings::permanent_exp_ratio
uint8_t permanent_exp_ratio
Definition: global.h:262
Settings::crypt_mode
uint8_t crypt_mode
Definition: global.h:334
Settings::dumpvalues
uint8_t dumpvalues
Definition: global.h:249
Settings::datadir
const char * datadir
Definition: global.h:252
recipe.h
god.h
Settings::worldmaptilesy
uint32_t worldmaptilesy
Definition: global.h:298
Settings::min_name
uint8_t min_name
Definition: global.h:335
Settings::worldmapstartx
uint32_t worldmapstartx
Definition: global.h:295
typesproto.h
first_artifactlist
EXTERN artifactlist * first_artifactlist
Definition: global.h:125
Settings::starting_stat_min
uint8_t starting_stat_min
Definition: global.h:324
artifact.h
Settings::assets_tracker
class AssetsTracker * assets_tracker
Definition: global.h:340
Settings::roll_stat_points
uint8_t roll_stat_points
Definition: global.h:327
Settings::pk_luck_penalty
int16_t pk_luck_penalty
Definition: global.h:261
Settings::emergency_x
uint16_t emergency_x
Definition: global.h:304
first_map_path
EXTERN char first_map_path[MAX_BUF]
Definition: global.h:148
skills.h
first_map
EXTERN mapstruct * first_map
Definition: global.h:123
Settings::csport
uint16_t csport
Definition: global.h:246
Statistics
Definition: global.h:365
Statistics::spell_hash_full
uint64_t spell_hash_full
Definition: global.h:367
Settings::ignore_assets_errors
int ignore_assets_errors
Definition: global.h:339
Settings::fatal_hook
fatalHook fatal_hook
Definition: global.h:341
amulet_arch
EXTERN archetype * amulet_arch
Definition: global.h:159
all_regions
EXTERN std::vector< region * > all_regions
Definition: global.h:124
maxfree
int maxfree[SIZEOFFREE]
Definition: object.cpp:311
Settings::meta_host
char meta_host[MAX_BUF]
Definition: global.h:291
linked_char
Definition: global.h:96
Settings::worldmaptilesx
uint32_t worldmaptilesx
Definition: global.h:297
Settings::pk_max_experience
int64_t pk_max_experience
Definition: global.h:317
undead_name
const EXTERN char * undead_name
Definition: global.h:160
Settings::log_callback
logHook log_callback
Definition: global.h:248
Settings::spell_encumbrance
uint8_t spell_encumbrance
Definition: global.h:272
stringbuffer.h
Settings::add_hook
void add_hook(const char *name, collectorHook hook)
Definition: global.h:343
Settings::meta_port
uint16_t meta_port
Definition: global.h:292
Settings::balanced_stat_loss
uint8_t balanced_stat_loss
Definition: global.h:265
Settings::debug
LogLevel debug
Definition: global.h:247
AssetsTracker
Definition: AssetsTracker.h:26
events.h
Settings::pk_max_experience_percent
int pk_max_experience_percent
Definition: global.h:318
linked_char::name
const char * name
Definition: global.h:97
blank_face
const Face * blank_face
Definition: image.cpp:36
attack.h
Settings::death_penalty_ratio
uint8_t death_penalty_ratio
Definition: global.h:263
statistics
Statistics statistics
Definition: init.cpp:232
Settings::set_friendly_fire
uint16_t set_friendly_fire
Definition: global.h:279
Settings::account_block_create
uint8_t account_block_create
Definition: global.h:332
Settings::logfilename
const char * logfilename
Definition: global.h:245
Settings::worldmapstarty
uint32_t worldmapstarty
Definition: global.h:296
party.h
logHook
void(* logHook)(LogLevel, const char *, va_list)
Definition: global.h:239
compat.h
Settings::motd
char motd[MAX_BUF]
Definition: global.h:282
material.h
Settings::rules
const char * rules
Definition: global.h:283
Settings::armor_weight_reduction
int armor_weight_reduction
Definition: global.h:310
Settings::news
const char * news
Definition: global.h:284
first_player
EXTERN player * first_player
Definition: global.h:122
crown_arch
EXTERN archetype * crown_arch
Definition: global.h:159
Settings::stat_loss_on_death
uint8_t stat_loss_on_death
Definition: global.h:260
Settings::disabled_plugins
std::vector< char * > disabled_plugins
Definition: global.h:330
book.h
linked_char::next
struct linked_char * next
Definition: global.h:98
artifactlist
Definition: artifact.h:24
Settings::item_power_factor
float item_power_factor
Definition: global.h:307
freearr_y
short freearr_y[SIZEOFFREE]
Definition: global.h:178
Settings::dumparg
const char * dumparg
Definition: global.h:250
collectorHook
void(* collectorHook)(BufferReader *, const char *)
Definition: global.h:237
sstring
const typedef char * sstring
Definition: global.h:47
Settings::hooks_filename
const char * hooks_filename[20]
Definition: global.h:337
archetype
Definition: object.h:472
Settings::confdir
const char * confdir
Definition: global.h:251
nroferrors
EXTERN long nroferrors
Definition: global.h:133
logfile
EXTERN FILE * logfile
Definition: global.h:141
blocks_prayer
EXTERN sstring blocks_prayer
Definition: global.h:161
Settings::death_penalty_level
uint8_t death_penalty_level
Definition: global.h:264
nlohmann::detail::void
j template void())
Definition: json.hpp:4099
map.h
Settings::reset_loc_time
int reset_loc_time
Definition: global.h:268
SIZEOFFREE
#define SIZEOFFREE
Definition: define.h:155
treasure.h
MAX_BUF
#define MAX_BUF
Definition: define.h:35
Statistics::spell_suppressions
uint64_t spell_suppressions
Definition: global.h:368
spell_mapping
const char *const spell_mapping[SPELL_MAPPINGS]
Definition: object.cpp:74
Settings::playerdir
const char * playerdir
Definition: global.h:254
Settings::spell_failure_effects
uint8_t spell_failure_effects
Definition: global.h:273
Settings::starting_stat_points
uint8_t starting_stat_points
Definition: global.h:326
freearr_x
short freearr_x[SIZEOFFREE]
Definition: object.cpp:299
Settings
Definition: global.h:244
ob_types.h
Settings::meta_on
unsigned int meta_on
Definition: global.h:289
Settings::allow_denied_spells_writing
int allow_denied_spells_writing
Definition: global.h:319
Settings::emergency_mapname
char * emergency_mapname
Definition: global.h:303
spells.h
SPELL_MAPPINGS
#define SPELL_MAPPINGS
Definition: global.h:152
Settings::who_wiz_format
char who_wiz_format[MAX_BUF]
Definition: global.h:281
reopen_logfile
int reopen_logfile
Definition: logger.cpp:26
EXTERN
#define EXTERN
Definition: global.h:15
Settings::spellpoint_level_depend
uint8_t spellpoint_level_depend
Definition: global.h:278
Settings::fastclock
uint8_t fastclock
Definition: global.h:301
player.h
newserver.h
mapstruct
Definition: map.h:316
Settings::personalized_blessings
uint8_t personalized_blessings
Definition: global.h:316
define.h
Settings::max_stat
uint8_t max_stat
Definition: global.h:328
Settings::armor_max_enchant
int armor_max_enchant
Definition: global.h:309
Settings::hooks
collectorHook hooks[20]
Definition: global.h:338
Settings::armor_weight_linear
uint8_t armor_weight_linear
Definition: global.h:311
Settings::worldmaptilesizex
uint32_t worldmaptilesizex
Definition: global.h:299
newclient.h
Settings::real_wiz
uint8_t real_wiz
Definition: global.h:275
account_char.h
config.h
first_map_ext_path
EXTERN char first_map_ext_path[MAX_BUF]
Definition: global.h:149
Settings::templatedir
const char * templatedir
Definition: global.h:258
trying_emergency_save
EXTERN long trying_emergency_save
Definition: global.h:132
Settings::worldmaptilesizey
uint32_t worldmaptilesizey
Definition: global.h:300
fatal_error
fatal_error
Definition: define.h:47
freedir
int freedir[SIZEOFFREE]
Definition: global.h:179
nrofartifacts
EXTERN long nrofartifacts
Definition: global.h:144
commands.h
exiting
EXTERN int exiting
Definition: global.h:143
pticks
uint32_t pticks
Definition: time.cpp:47
fatalHook
void(* fatalHook)(enum fatal_error err)
Definition: global.h:238
ob_methods.h
Settings::no_player_stealing
uint8_t no_player_stealing
Definition: global.h:314
Settings::account_trusted_host
char * account_trusted_host
Definition: global.h:333
Settings::search_items
uint8_t search_items
Definition: global.h:271
LogLevel
LogLevel
Definition: logger.h:10
Settings::tmpdir
const char * tmpdir
Definition: global.h:259
tod.h
tick_duration
uint32_t tick_duration
Definition: time.cpp:35
Settings::always_show_hp
uint8_t always_show_hp
Definition: global.h:277
ring_arch
EXTERN archetype * ring_arch
Definition: global.h:159
Settings::create_home_portals
uint8_t create_home_portals
Definition: global.h:315
living.h
BufferReader
Definition: bufferreader.cpp:21
Settings::armor_speed_improvement
int armor_speed_improvement
Definition: global.h:312
Settings::log_timestamp
int log_timestamp
Definition: global.h:322
Settings::who_format
char who_format[MAX_BUF]
Definition: global.h:280
object.h
libproto.h
autoconf.h
give.name
name
Definition: give.py:27
Settings::starting_stat_max
uint8_t starting_stat_max
Definition: global.h:325
Settings::uniquedir
const char * uniquedir
Definition: global.h:257
Settings::localdir
const char * localdir
Definition: global.h:253