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 
40 #define PRINTF_ARGS(x, y) __attribute__ ((format (printf, x, y)))
41 
43 typedef const char *sstring;
44 
45 #include "config.h"
46 #include "define.h"
47 #include "logger.h"
48 #include "shared/newclient.h"
49 
50 /* This blob, in this order, is needed to actually define maps */
51 #include "face.h"
52 /* Include the basic defines from spells.h */
53 #include "attack.h" /* needs to be before material.h */
54 #include "material.h"
55 #include "living.h"
56 #include "object.h"
57 #include "map.h"
58 #include "tod.h"
59 
60 #include "skills.h"
61 
62 /* This defines the Account_Char structure which is used in the socket */
63 #include "account_char.h"
64 
65 /* Pull in the socket structure - used in the player structure */
66 #include "newserver.h"
67 
68 #include "party.h"
69 
70 /* Pull in the player structure */
71 #include "player.h"
72 
73 /* pull in treasure structure */
74 #include "treasure.h"
75 
76 #include "commands.h"
77 
78 /* pull in book structures */
79 #include "book.h"
80 
81 /* ob_methods and ob_types subsystem */
82 #include "ob_methods.h"
83 #include "ob_types.h"
84 
85 /*
86  * So far only used when dealing with artifacts.
87  * (now used by alchemy and other code too. Nov 95 b.t).
88  */
89 typedef struct linked_char {
90  const char *name;
91  struct linked_char *next;
92 } linked_char;
93 
94 
95 /* Pull in artifacts */
96 #include "artifact.h"
97 
98 /* Now for gods */
99 #include "god.h"
100 
101 /* Now for races */
102 #include "race.h"
103 
104 /* Now for recipe/alchemy */
105 #include "recipe.h"
106 
107 /* Now for spells */
108 #include "spells.h"
109 
110 /*****************************************************************************
111  * GLOBAL VARIABLES: *
112  *****************************************************************************/
113 
123 
124 /*
125  * Variables set by different flags (see init.c):
126  */
127 
131 extern uint32_t pticks;
138 extern int reopen_logfile;
148 #define SPELL_MAPPINGS 206
149 extern const char *const spell_mapping[SPELL_MAPPINGS];
152 /*
153  * Used in treasure.c
154  */
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 typedef 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  char motd[MAX_BUF];
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;
330  uint8_t crypt_mode;
331  uint8_t min_name;
332  uint8_t hooks_count;
333  const char *hooks_filename[20];
338 } Settings;
339 
343 extern Settings settings;
344 
355 typedef struct Statistics {
356  uint64_t spell_merges;
357  uint64_t spell_hash_full;
359 } Statistics;
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 "plugin.h"
387 
388 #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:141
empty_archetype
EXTERN archetype * empty_archetype
Definition: global.h:143
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::archetypes_tracker
void * archetypes_tracker
Definition: global.h:336
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
Settings::armor_speed_linear
uint8_t armor_speed_linear
Definition: global.h:309
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:356
win32.h
sockproto.h
Settings::set_title
uint8_t set_title
Definition: global.h:265
ob_count
EXTERN long ob_count
Definition: global.h:147
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
pl
Definition: player.h:105
recipe.h
god.h
Settings::worldmaptilesy
uint32_t worldmaptilesy
Definition: global.h:294
Settings::min_name
uint8_t min_name
Definition: global.h:331
linked_char
struct linked_char linked_char
Settings::worldmapstartx
uint32_t worldmapstartx
Definition: global.h:291
typesproto.h
first_artifactlist
EXTERN artifactlist * first_artifactlist
Definition: global.h:121
Settings::starting_stat_min
uint8_t starting_stat_min
Definition: global.h:320
artifact.h
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
plugin.h
Settings::emergency_x
uint16_t emergency_x
Definition: global.h:300
Settings
struct Settings Settings
first_map_path
EXTERN char first_map_path[MAX_BUF]
Definition: global.h:144
skills.h
first_map
EXTERN mapstruct * first_map
Definition: global.h:119
Settings::csport
uint16_t csport
Definition: global.h:242
Statistics
Definition: global.h:355
Statistics::spell_hash_full
uint64_t spell_hash_full
Definition: global.h:357
Settings::ignore_assets_errors
int ignore_assets_errors
Definition: global.h:335
Settings::fatal_hook
fatalHook fatal_hook
Definition: global.h:337
amulet_arch
EXTERN archetype * amulet_arch
Definition: global.h:155
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:89
Settings::worldmaptilesx
uint32_t worldmaptilesx
Definition: global.h:293
archt
Definition: object.h:472
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::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
Settings::pk_max_experience_percent
int pk_max_experience_percent
Definition: global.h:314
linked_char::name
const char * name
Definition: global.h:90
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:232
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::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
Settings::motd
char motd[MAX_BUF]
Definition: global.h:278
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:118
crown_arch
EXTERN archetype * crown_arch
Definition: global.h:155
Settings::stat_loss_on_death
uint8_t stat_loss_on_death
Definition: global.h:256
book.h
linked_char::next
struct linked_char * next
Definition: global.h:91
artifactliststruct
Definition: artifact.h:26
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
sstring
const typedef char * sstring
Definition: global.h:43
Settings::hooks_filename
const char * hooks_filename[20]
Definition: global.h:333
Settings::confdir
const char * confdir
Definition: global.h:247
nroferrors
EXTERN long nroferrors
Definition: global.h:129
mapdef
Definition: map.h:317
logfile
EXTERN FILE * logfile
Definition: global.h:137
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:358
race.h
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::disabled_plugins
linked_char * disabled_plugins
Definition: global.h:326
Settings::emergency_mapname
char * emergency_mapname
Definition: global.h:299
spells.h
SPELL_MAPPINGS
#define SPELL_MAPPINGS
Definition: global.h:148
Settings::who_wiz_format
char who_wiz_format[MAX_BUF]
Definition: global.h:277
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:274
Settings::fastclock
uint8_t fastclock
Definition: global.h:297
player.h
newserver.h
Settings::personalized_blessings
uint8_t personalized_blessings
Definition: global.h:312
define.h
Settings::max_stat
uint8_t max_stat
Definition: global.h:324
Statistics
struct Statistics Statistics
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:145
Settings::templatedir
const char * templatedir
Definition: global.h:254
trying_emergency_save
EXTERN long trying_emergency_save
Definition: global.h:128
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:140
commands.h
exiting
EXTERN int exiting
Definition: global.h:139
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
ring_arch
EXTERN archetype * ring_arch
Definition: global.h:155
Settings::create_home_portals
uint8_t create_home_portals
Definition: global.h:311
first_region
EXTERN region * first_region
Definition: global.h:120
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
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
regiondef
Definition: map.h:275