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