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 #include "sstring.h"
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 EXTERN const char *undead_name; /* Used in hit_player() in main.c */
159 /* Rotate right from bsd sum. This is used in various places for checksumming */
160 #define ROTATE_RIGHT(c) if ((c)&01) (c) = ((c)>>1)+0x80000000; else (c) >>= 1;
161 
162 #define SET_ANIMATION(ob, newanim) { ob->face = (ob->temp_animation ? ob->temp_animation : ob->animation)->faces[newanim]; }
163 #define GET_ANIMATION(ob, anim) ((ob->temp_animation ? ob->temp_animation : ob->animation)->faces[anim])
164 #define GET_ANIM(ob) (ob->temp_animation ? ob->temp_animation : ob->animation)
165 #define GET_ANIM_ID(ob) (ob->temp_animation ? ob->temp_animation->num : (ob->animation ? ob->animation->num : 0))
166 /* NUM_ANIMATIONS returns the number of animations allocated. The last
167  * usuable animation will be NUM_ANIMATIONS-1 (for example, if an object
168  * has 8 animations, NUM_ANIMATIONS will return 8, but the values will
169  * range from 0 through 7.
170  */
171 #define NUM_ANIMATIONS(ob) ((ob->temp_animation ? ob->temp_animation : ob->animation)->num_animations)
172 #define NUM_FACINGS(ob) ((ob->temp_animation ? ob->temp_animation : ob->animation)->facings)
173 
176 
177 extern const Face *blank_face, *empty_face;
178 extern const Face *smooth_face;
179 
180 extern uint32_t tick_duration; /* loop time */
182 
183 #include "stringbuffer.h"
184 #include "libproto.h"
185 #include "sockproto.h"
186 #include "typesproto.h"
187 
193 #define FREE_AND_CLEAR(xyz) { free(xyz); xyz = NULL; }
194 
198 #define FREE_AND_CLEAR_STR(xyz) { free_string(xyz); xyz = NULL; }
199 
200 #define FREE_AND_CLEAR_STR_IF(xyz) { if (xyz) { free_string(xyz); xyz = NULL; } }
201 
204 #define FREE_AND_COPY(sv, nv) { if (sv) free_string(sv); sv = add_string(nv); }
205 
206 #define FREE_AND_COPY_IF(sv, nv) { if (sv) free_string(sv); sv = nv ? add_string(nv) : NULL; }
207 
208 #ifndef WIN32 /* ---win32 we define this stuff in win32.h */
209 #if HAVE_DIRENT_H
210 # include <dirent.h>
211 # define NAMLEN(dirent) strlen((dirent)->d_name)
212 #else
213 # define dirent direct
214 # define NAMLEN(dirent) (dirent)->d_namlen
215 # if HAVE_SYS_NDIR_H
216 # include <sys/ndir.h>
217 # endif
218 # if HAVE_SYS_DIR_H
219 # include <sys/dir.h>
220 # endif
221 # if HAVE_NDIR_H
222 # include <ndir.h>
223 # endif
224 #endif
225 #endif
226 
230 #define PERM_EXP(exptotal) (exptotal * settings.permanent_exp_ratio / 100 )
231 #define MAX_TOTAL_EXPERIENCE (settings.permanent_exp_ratio ? (MAX_EXPERIENCE * 100 / settings.permanent_exp_ratio) : 0)
232 
233 typedef void(*collectorHook)(BufferReader *, const char *);
234 typedef void(*fatalHook)(enum fatal_error err);
235 typedef void(*logHook)(LogLevel, const char *, va_list);
236 
240 struct Settings {
241  const char *logfilename;
242  uint16_t csport;
245  uint8_t dumpvalues;
246  const char *dumparg;
247  const char *confdir;
248  const char *datadir;
249  const char *localdir;
250  const char *playerdir;
251  const char *mapdir;
252  const char *regions;
253  const char *uniquedir;
254  const char *templatedir;
255  const char *tmpdir;
257  int16_t pk_luck_penalty;
262  uint8_t not_permadeth;
263  uint8_t simple_exp;
265  uint8_t set_title;
266  uint8_t resurrection;
267  uint8_t search_items;
270  uint8_t casting_time;
271  uint8_t real_wiz;
273  uint8_t always_show_hp;
275  uint16_t set_friendly_fire;
278  const char *motd;
279  const char *rules;
280  const char *news;
282  /* The meta_ is information for the metaserver. These are set in
283  * the lib/settings file.
284  */
285  unsigned int meta_on:1;
288  uint16_t meta_port;
291  uint32_t worldmapstartx;
292  uint32_t worldmapstarty;
293  uint32_t worldmaptilesx;
294  uint32_t worldmaptilesy;
295  uint32_t worldmaptilesizex;
296  uint32_t worldmaptilesizey;
297  uint8_t fastclock;
302  int16_t max_level;
324  uint8_t max_stat;
326  std::vector<char *> disabled_plugins;
330  uint8_t crypt_mode;
331  uint8_t min_name;
332  uint8_t hooks_count;
333  const char *hooks_filename[20];
338  char* stat_file;
339 
340  void add_hook(const char *name, collectorHook hook) {
342  hooks [hooks_count] = hook;
343  ++hooks_count;
344  }
345 };
346 
350 extern Settings settings;
351 
362 struct Statistics {
363  uint64_t spell_merges;
364  uint64_t spell_hash_full;
366 };
367 
371 extern Statistics statistics;
372 
373 #define PROFILE_BEGIN(expr) { \
374  struct timespec _begin, _end; \
375  clock_gettime(CLOCK_MONOTONIC, &_begin); \
376  expr;
377 
378 #define PROFILE_END(var, expr) \
379  clock_gettime(CLOCK_MONOTONIC, &_end); \
380  long var = timespec_diff(&_end, &_begin); \
381  expr; }
382 
388 #define SCRIPT_FIX_ACTIVATOR 2
389 #define SCRIPT_FIX_ALL 1
390 #define SCRIPT_FIX_NOTHING 0
391 
393 #include "events.h"
394 
395 #endif /* GLOBAL_H */
Settings::casting_time
uint8_t casting_time
Definition: global.h:270
Face
Definition: face.h:14
Settings::special_break_map
uint8_t special_break_map
Definition: global.h:325
Settings::meta_comment
char meta_comment[MAX_BUF]
Definition: global.h:289
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:251
Settings::meta_server
char meta_server[MAX_BUF]
Definition: global.h:286
Settings::hooks_count
uint8_t hooks_count
Definition: global.h:332
Settings::simple_exp
uint8_t simple_exp
Definition: global.h:263
empty_face
const Face * empty_face
Definition: global.h:177
Settings::max_level
int16_t max_level
Definition: global.h:302
Settings::recycle_tmp_maps
uint8_t recycle_tmp_maps
Definition: global.h:272
Settings::emergency_y
uint16_t emergency_y
Definition: global.h:300
Settings::regions
const char * regions
Definition: global.h:252
Settings::allow_broken_converters
int allow_broken_converters
Definition: global.h:316
init_sockets
socket_struct * init_sockets
Definition: init.cpp:58
Settings::log_timestamp_format
char * log_timestamp_format
Definition: global.h:319
language_t
void * language_t
Definition: global.h:67
Settings::armor_speed_linear
uint8_t armor_speed_linear
Definition: global.h:309
player
Definition: player.h:105
settings
Settings settings
Definition: init.cpp:139
Settings::resurrection
uint8_t resurrection
Definition: global.h:266
Statistics::spell_merges
uint64_t spell_merges
Definition: global.h:363
win32.h
sockproto.h
Settings::set_title
uint8_t set_title
Definition: global.h:265
ob_count
EXTERN long ob_count
Definition: global.h:151
face.h
Settings::ignore_plugin_compatibility
uint8_t ignore_plugin_compatibility
Definition: global.h:327
socket_struct
Definition: newserver.h:89
logger.h
Settings::not_permadeth
uint8_t not_permadeth
Definition: global.h:262
smooth_face
const Face * smooth_face
Definition: image.cpp:36
Settings::permanent_exp_ratio
uint8_t permanent_exp_ratio
Definition: global.h:258
Settings::crypt_mode
uint8_t crypt_mode
Definition: global.h:330
Settings::dumpvalues
uint8_t dumpvalues
Definition: global.h:245
Settings::datadir
const char * datadir
Definition: global.h:248
recipe.h
god.h
Settings::worldmaptilesy
uint32_t worldmaptilesy
Definition: global.h:294
Settings::min_name
uint8_t min_name
Definition: global.h:331
Settings::worldmapstartx
uint32_t worldmapstartx
Definition: global.h:291
typesproto.h
first_artifactlist
EXTERN artifactlist * first_artifactlist
Definition: global.h:125
Settings::starting_stat_min
uint8_t starting_stat_min
Definition: global.h:320
artifact.h
Settings::assets_tracker
class AssetsTracker * assets_tracker
Definition: global.h:336
Settings::roll_stat_points
uint8_t roll_stat_points
Definition: global.h:323
Settings::pk_luck_penalty
int16_t pk_luck_penalty
Definition: global.h:257
Settings::stat_file
char * stat_file
Definition: global.h:338
Settings::emergency_x
uint16_t emergency_x
Definition: global.h:300
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:242
Statistics
Definition: global.h:362
Statistics::spell_hash_full
uint64_t spell_hash_full
Definition: global.h:364
Settings::ignore_assets_errors
int ignore_assets_errors
Definition: global.h:335
sstring.h
Settings::fatal_hook
fatalHook fatal_hook
Definition: global.h:337
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:287
linked_char
Definition: global.h:96
Settings::worldmaptilesx
uint32_t worldmaptilesx
Definition: global.h:293
Settings::pk_max_experience
int64_t pk_max_experience
Definition: global.h:313
undead_name
const EXTERN char * undead_name
Definition: global.h:156
Settings::log_callback
logHook log_callback
Definition: global.h:244
Settings::spell_encumbrance
uint8_t spell_encumbrance
Definition: global.h:268
stringbuffer.h
Settings::add_hook
void add_hook(const char *name, collectorHook hook)
Definition: global.h:340
Settings::meta_port
uint16_t meta_port
Definition: global.h:288
Settings::balanced_stat_loss
uint8_t balanced_stat_loss
Definition: global.h:261
Settings::debug
LogLevel debug
Definition: global.h:243
AssetsTracker
Definition: AssetsTracker.h:26
events.h
Settings::pk_max_experience_percent
int pk_max_experience_percent
Definition: global.h:314
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:259
statistics
Statistics statistics
Definition: init.cpp:233
Settings::set_friendly_fire
uint16_t set_friendly_fire
Definition: global.h:275
Settings::account_block_create
uint8_t account_block_create
Definition: global.h:328
Settings::motd
const char * motd
Definition: global.h:278
Settings::logfilename
const char * logfilename
Definition: global.h:241
Settings::worldmapstarty
uint32_t worldmapstarty
Definition: global.h:292
party.h
logHook
void(* logHook)(LogLevel, const char *, va_list)
Definition: global.h:235
compat.h
material.h
Settings::rules
const char * rules
Definition: global.h:279
Settings::armor_weight_reduction
int armor_weight_reduction
Definition: global.h:306
Settings::news
const char * news
Definition: global.h:280
first_player
EXTERN player * first_player
Definition: global.h:122
Settings::stat_loss_on_death
uint8_t stat_loss_on_death
Definition: global.h:256
Settings::disabled_plugins
std::vector< char * > disabled_plugins
Definition: global.h:326
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:303
freearr_y
short freearr_y[SIZEOFFREE]
Definition: global.h:174
Settings::dumparg
const char * dumparg
Definition: global.h:246
collectorHook
void(* collectorHook)(BufferReader *, const char *)
Definition: global.h:233
Settings::hooks_filename
const char * hooks_filename[20]
Definition: global.h:333
archetype
Definition: object.h:481
Settings::confdir
const char * confdir
Definition: global.h:247
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:157
Settings::death_penalty_level
uint8_t death_penalty_level
Definition: global.h:260
nlohmann::detail::void
j template void())
Definition: json.hpp:4099
map.h
Settings::reset_loc_time
int reset_loc_time
Definition: global.h:264
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:365
spell_mapping
const char *const spell_mapping[SPELL_MAPPINGS]
Definition: object.cpp:74
Settings::playerdir
const char * playerdir
Definition: global.h:250
Settings::spell_failure_effects
uint8_t spell_failure_effects
Definition: global.h:269
Settings::starting_stat_points
uint8_t starting_stat_points
Definition: global.h:322
freearr_x
short freearr_x[SIZEOFFREE]
Definition: object.cpp:299
Settings
Definition: global.h:240
ob_types.h
Settings::meta_on
unsigned int meta_on
Definition: global.h:285
Settings::allow_denied_spells_writing
int allow_denied_spells_writing
Definition: global.h:315
Settings::emergency_mapname
char * emergency_mapname
Definition: global.h:299
spells.h
SPELL_MAPPINGS
#define SPELL_MAPPINGS
Definition: global.h:152
Settings::who_wiz_format
char who_wiz_format[MAX_BUF]
Definition: global.h:277
reopen_logfile
int reopen_logfile
Definition: logger.cpp:27
EXTERN
#define EXTERN
Definition: global.h:15
Settings::spellpoint_level_depend
uint8_t spellpoint_level_depend
Definition: global.h:274
Settings::fastclock
uint8_t fastclock
Definition: global.h:297
player.h
newserver.h
mapstruct
Definition: map.h:313
sstring
const typedef char * sstring
Definition: sstring.h:2
Settings::personalized_blessings
uint8_t personalized_blessings
Definition: global.h:312
define.h
Settings::max_stat
uint8_t max_stat
Definition: global.h:324
Settings::armor_max_enchant
int armor_max_enchant
Definition: global.h:305
Settings::hooks
collectorHook hooks[20]
Definition: global.h:334
Settings::armor_weight_linear
uint8_t armor_weight_linear
Definition: global.h:307
Settings::worldmaptilesizex
uint32_t worldmaptilesizex
Definition: global.h:295
newclient.h
Settings::real_wiz
uint8_t real_wiz
Definition: global.h:271
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:254
trying_emergency_save
EXTERN long trying_emergency_save
Definition: global.h:132
Settings::worldmaptilesizey
uint32_t worldmaptilesizey
Definition: global.h:296
fatal_error
fatal_error
Definition: define.h:47
freedir
int freedir[SIZEOFFREE]
Definition: global.h:175
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:234
ob_methods.h
Settings::no_player_stealing
uint8_t no_player_stealing
Definition: global.h:310
Settings::account_trusted_host
char * account_trusted_host
Definition: global.h:329
Settings::search_items
uint8_t search_items
Definition: global.h:267
LogLevel
LogLevel
Definition: logger.h:10
Settings::tmpdir
const char * tmpdir
Definition: global.h:255
tod.h
tick_duration
uint32_t tick_duration
Definition: time.cpp:35
Settings::always_show_hp
uint8_t always_show_hp
Definition: global.h:273
Settings::create_home_portals
uint8_t create_home_portals
Definition: global.h:311
living.h
BufferReader
Definition: bufferreader.cpp:21
Settings::armor_speed_improvement
int armor_speed_improvement
Definition: global.h:308
Settings::log_timestamp
int log_timestamp
Definition: global.h:318
Settings::who_format
char who_format[MAX_BUF]
Definition: global.h:276
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:321
Settings::uniquedir
const char * uniquedir
Definition: global.h:253
Settings::localdir
const char * localdir
Definition: global.h:249