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>
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 #include <functional>
43 #include <string>
44 
46 #define PRINTF_ARGS(x, y) __attribute__ ((format (printf, x, y)))
47 
49 #include "sstring.h"
50 
51 #include "config.h"
52 #include "define.h"
53 #include "logger.h"
54 #include "shared/newclient.h"
55 
56 /* This blob, in this order, is needed to actually define maps */
57 #include "face.h"
58 /* Include the basic defines from spells.h */
59 #include "attack.h" /* needs to be before material.h */
60 #include "material.h"
61 #include "living.h"
62 #include "object.h"
63 #include "map.h"
64 #include "tod.h"
65 
66 #include "skills.h"
67 
68 /* Opaque handle to a player-selectable language */
69 typedef void *language_t;
70 
71 /* This defines the Account_Char structure which is used in the socket */
72 #include "account_char.h"
73 
74 /* Pull in the socket structure - used in the player structure */
75 #include "newserver.h"
76 
77 #include "party.h"
78 
79 /* Pull in the player structure */
80 #include "player.h"
81 
82 /* pull in treasure structure */
83 #include "treasure.h"
84 
85 #include "commands.h"
86 
87 /* pull in book structures */
88 #include "book.h"
89 
90 /* ob_methods and ob_types subsystem */
91 #include "ob_methods.h"
92 #include "ob_types.h"
93 
94 /*
95  * So far only used when dealing with artifacts.
96  * (now used by alchemy and other code too. Nov 95 b.t).
97  */
98 struct linked_char {
99  const char *name;
100  struct linked_char *next;
101 };
102 
103 
104 /* Pull in artifacts */
105 #include "artifact.h"
106 
107 /* Now for gods */
108 #include "god.h"
109 
110 /* Now for recipe/alchemy */
111 #include "recipe.h"
112 
113 /* Now for spells */
114 #include "spells.h"
115 
116 /*****************************************************************************
117  * GLOBAL VARIABLES: *
118  *****************************************************************************/
119 
126 EXTERN std::vector<region *> all_regions;
129 
130 /*
131  * Variables set by different flags (see init.c):
132  */
133 
137 extern uint32_t pticks;
144 extern int reopen_logfile;
154 #define SPELL_MAPPINGS 206
155 extern const char *const spell_mapping[SPELL_MAPPINGS];
158 EXTERN const char *undead_name; /* Used in hit_player() in main.c */
161 /* Rotate right from bsd sum. This is used in various places for checksumming */
162 #define ROTATE_RIGHT(c) if ((c)&01) (c) = ((c)>>1)+0x80000000; else (c) >>= 1;
163 
164 #define SET_ANIMATION(ob, newanim) { ob->face = (ob->temp_animation ? ob->temp_animation : ob->animation)->faces[newanim]; }
165 #define GET_ANIMATION(ob, anim) ((ob->temp_animation ? ob->temp_animation : ob->animation)->faces[anim])
166 #define GET_ANIM(ob) (ob->temp_animation ? ob->temp_animation : ob->animation)
167 #define GET_ANIM_ID(ob) (ob->temp_animation ? ob->temp_animation->num : (ob->animation ? ob->animation->num : 0))
168 /* NUM_ANIMATIONS returns the number of animations allocated. The last
169  * usuable animation will be NUM_ANIMATIONS-1 (for example, if an object
170  * has 8 animations, NUM_ANIMATIONS will return 8, but the values will
171  * range from 0 through 7.
172  */
173 #define NUM_ANIMATIONS(ob) ((ob->temp_animation ? ob->temp_animation : ob->animation)->num_animations)
174 #define NUM_FACINGS(ob) ((ob->temp_animation ? ob->temp_animation : ob->animation)->facings)
175 
178 
179 extern const Face *blank_face, *empty_face;
180 extern const Face *smooth_face;
181 
182 extern uint32_t tick_duration; /* loop time */
184 
185 #include "stringbuffer.h"
186 #include "libproto.h"
187 #include "sockproto.h"
188 #include "typesproto.h"
189 
195 #define FREE_AND_CLEAR(xyz) { free(xyz); xyz = NULL; }
196 
200 #define FREE_AND_CLEAR_STR(xyz) { free_string(xyz); xyz = NULL; }
201 
202 #define FREE_AND_CLEAR_STR_IF(xyz) { if (xyz) { free_string(xyz); xyz = NULL; } }
203 
206 #define FREE_AND_COPY(sv, nv) { if (sv) free_string(sv); sv = add_string(nv); }
207 
208 #define FREE_AND_COPY_IF(sv, nv) { if (sv) free_string(sv); sv = nv ? add_string(nv) : NULL; }
209 
210 #ifndef WIN32 /* ---win32 we define this stuff in win32.h */
211 #if HAVE_DIRENT_H
212 # include <dirent.h>
213 # define NAMLEN(dirent) strlen((dirent)->d_name)
214 #else
215 # define dirent direct
216 # define NAMLEN(dirent) (dirent)->d_namlen
217 # if HAVE_SYS_NDIR_H
218 # include <sys/ndir.h>
219 # endif
220 # if HAVE_SYS_DIR_H
221 # include <sys/dir.h>
222 # endif
223 # if HAVE_NDIR_H
224 # include <ndir.h>
225 # endif
226 #endif
227 #endif
228 
232 #define PERM_EXP(exptotal) (exptotal * settings.permanent_exp_ratio / 100 )
233 #define MAX_TOTAL_EXPERIENCE (settings.permanent_exp_ratio ? (MAX_EXPERIENCE * 100 / settings.permanent_exp_ratio) : 0)
234 
235 typedef std::function<void(enum fatal_error err)> fatalHook;
236 typedef std::function<void(LogLevel, const char *, va_list)> logHook;
237 
241 struct Settings {
242  const char *logfilename;
243  uint16_t csport;
246  uint8_t dumpvalues;
247  const char *dumparg;
248  const char *confdir;
249  const char *datadir;
250  const char *localdir;
251  const char *playerdir;
252  const char *mapdir;
253  const char *regions;
254  const char *uniquedir;
255  const char *templatedir;
256  const char *tmpdir;
258  int16_t pk_luck_penalty;
263  uint8_t not_permadeth;
264  uint8_t simple_exp;
266  uint8_t set_title;
267  uint8_t resurrection;
268  uint8_t search_items;
271  uint8_t casting_time;
272  uint8_t real_wiz;
274  uint8_t always_show_hp;
276  uint16_t set_friendly_fire;
279  const char *motd;
280  const char *rules;
281  const char *news;
283  /* The meta_ is information for the metaserver. These are set in
284  * the lib/settings file.
285  */
286  unsigned int meta_on:1;
289  uint16_t meta_port;
292  uint32_t worldmapstartx;
293  uint32_t worldmapstarty;
294  uint32_t worldmaptilesx;
295  uint32_t worldmaptilesy;
296  uint32_t worldmaptilesizex;
297  uint32_t worldmaptilesizey;
298  uint8_t fastclock;
303  int16_t max_level;
325  uint8_t max_stat;
330  uint8_t crypt_mode;
331  uint8_t min_name;
335  char* stat_file;
336 };
337 
341 extern Settings settings;
342 
353 struct Statistics {
354  uint64_t spell_merges;
355  uint64_t spell_hash_full;
357 };
358 
362 extern Statistics statistics;
363 
364 #define PROFILE_BEGIN(expr) { \
365  struct timespec _begin, _end; \
366  clock_gettime(CLOCK_MONOTONIC, &_begin); \
367  expr;
368 
369 #define PROFILE_END(var, expr) \
370  clock_gettime(CLOCK_MONOTONIC, &_end); \
371  long var = timespec_diff(&_end, &_begin); \
372  expr; }
373 
379 #define SCRIPT_FIX_ACTIVATOR 2
380 #define SCRIPT_FIX_ALL 1
381 #define SCRIPT_FIX_NOTHING 0
382 
384 #include "events.h"
385 
386 #endif /* GLOBAL_H */
Settings::casting_time
uint8_t casting_time
It takes awhile to cast a spell.
Definition: global.h:271
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:326
Settings::meta_comment
char meta_comment[MAX_BUF]
Comment we send to the metaserver.
Definition: global.h:290
nrofallowedstr
EXTERN long nrofallowedstr
Only used in malloc_info().
Definition: global.h:147
empty_archetype
EXTERN archetype * empty_archetype
Nice to have fast access to it.
Definition: global.h:149
Settings::mapdir
const char * mapdir
Where the map files are.
Definition: global.h:252
Settings::meta_server
char meta_server[MAX_BUF]
Hostname/ip addr of the metaserver.
Definition: global.h:287
Settings::simple_exp
uint8_t simple_exp
If true, use the simple experience system.
Definition: global.h:264
empty_face
const Face * empty_face
Definition: global.h:179
Settings::max_level
int16_t max_level
This is read out of exp_table.
Definition: global.h:303
Settings::recycle_tmp_maps
uint8_t recycle_tmp_maps
Re-use tmp maps.
Definition: global.h:273
Settings::emergency_y
uint16_t emergency_y
Coordinates to use on that map.
Definition: global.h:301
Settings::regions
const char * regions
Name of the regions file - libdir is prepended.
Definition: global.h:253
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:317
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:320
language_t
void * language_t
Strings that should be manipulated through add_string() and free_string().
Definition: global.h:69
Settings::armor_speed_linear
uint8_t armor_speed_linear
If 1, speed improvement is linear, else exponantiel.
Definition: global.h:310
player
One player.
Definition: player.h:105
settings
Settings settings
Global settings.
Definition: init.cpp:139
Settings::resurrection
uint8_t resurrection
Ressurection possible w/ permadeth on.
Definition: global.h:267
Statistics::spell_merges
uint64_t spell_merges
Number of spell merges done.
Definition: global.h:354
win32.h
sockproto.h
Settings::set_title
uint8_t set_title
Players can set thier title.
Definition: global.h:266
ob_count
EXTERN long ob_count
Definition: global.h:153
face.h
Settings::ignore_plugin_compatibility
uint8_t ignore_plugin_compatibility
If set, don't check plugin version.
Definition: global.h:327
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:263
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:259
Settings::crypt_mode
uint8_t crypt_mode
0 for legacy behavior, 1 for always Traditional
Definition: global.h:330
Settings::dumpvalues
uint8_t dumpvalues
Set to dump various values/tables.
Definition: global.h:246
Settings::datadir
const char * datadir
Read only data files.
Definition: global.h:249
recipe.h
god.h
Settings::worldmaptilesy
uint32_t worldmaptilesy
Number of tiles high the worldmap is.
Definition: global.h:295
Settings::min_name
uint8_t min_name
Minimum characters for an account or player name.
Definition: global.h:331
Settings::worldmapstartx
uint32_t worldmapstartx
Starting x tile for the worldmap.
Definition: global.h:292
typesproto.h
first_artifactlist
EXTERN artifactlist * first_artifactlist
First artifact.
Definition: global.h:127
Settings::starting_stat_min
uint8_t starting_stat_min
Minimum value of a starting stat.
Definition: global.h:321
artifact.h
Settings::assets_tracker
class AssetsTracker * assets_tracker
If not NULL, called each time an asset is defined.
Definition: global.h:333
Settings::roll_stat_points
uint8_t roll_stat_points
How many stat points legacy (rolled) chars start with.
Definition: global.h:324
Settings::pk_luck_penalty
int16_t pk_luck_penalty
Amount by which player luck is reduced if they PK.
Definition: global.h:258
Settings::stat_file
char * stat_file
Definition: global.h:335
Settings::emergency_x
uint16_t emergency_x
Definition: global.h:301
first_map_path
EXTERN char first_map_path[MAX_BUF]
The start-level.
Definition: global.h:150
skills.h
first_map
EXTERN mapstruct * first_map
First map.
Definition: global.h:125
Settings::csport
uint16_t csport
Port for new client/server.
Definition: global.h:243
Statistics
This is used for various performance tracking statistics, or just how often certain events are done.
Definition: global.h:353
Statistics::spell_hash_full
uint64_t spell_hash_full
Number of times spell hash was full.
Definition: global.h:355
Settings::ignore_assets_errors
int ignore_assets_errors
If set then go on running even if there are errors in assets.
Definition: global.h:332
sstring.h
Settings::fatal_hook
fatalHook fatal_hook
If not NULL then called when fatal() is called.
Definition: global.h:334
all_regions
EXTERN std::vector< region * > all_regions
All regions.
Definition: global.h:126
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:288
linked_char
Definition: global.h:98
Settings::worldmaptilesx
uint32_t worldmaptilesx
Number of tiles wide the worldmap is.
Definition: global.h:294
Settings::pk_max_experience
int64_t pk_max_experience
Maximum experience one can get for PKing.
Definition: global.h:314
undead_name
const EXTERN char * undead_name
Definition: global.h:158
Settings::log_callback
logHook log_callback
Log hook, to intercept log messages.
Definition: global.h:245
Settings::spell_encumbrance
uint8_t spell_encumbrance
Encumbrance effects spells.
Definition: global.h:269
stringbuffer.h
Settings::meta_port
uint16_t meta_port
Port number to use for updates.
Definition: global.h:289
Settings::balanced_stat_loss
uint8_t balanced_stat_loss
If true, Death stat depletion based on level etc.
Definition: global.h:262
Settings::debug
LogLevel debug
Default debugging level.
Definition: global.h:244
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:315
linked_char::name
const char * name
Definition: global.h:99
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:260
statistics
Statistics statistics
Merged spell statistics.
Definition: init.cpp:229
Settings::set_friendly_fire
uint16_t set_friendly_fire
Percent of damage done by peaceful player vs player damage.
Definition: global.h:276
Settings::account_block_create
uint8_t account_block_create
Definition: global.h:328
Settings::motd
const char * motd
Name of the motd file.
Definition: global.h:279
Settings::logfilename
const char * logfilename
Logfile to use.
Definition: global.h:242
Settings::worldmapstarty
uint32_t worldmapstarty
Starting y tile for the worldmap.
Definition: global.h:293
party.h
compat.h
material.h
Settings::rules
const char * rules
Name of rules file.
Definition: global.h:280
Settings::armor_weight_reduction
int armor_weight_reduction
Weight reduction per enchantment.
Definition: global.h:307
Settings::news
const char * news
Name of news file.
Definition: global.h:281
first_player
EXTERN player * first_player
First player.
Definition: global.h:124
Settings::stat_loss_on_death
uint8_t stat_loss_on_death
If true, chars lose a random stat when they die.
Definition: global.h:257
book.h
linked_char::next
struct linked_char * next
Definition: global.h:100
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:304
freearr_y
short freearr_y[SIZEOFFREE]
Definition: global.h:176
Settings::dumparg
const char * dumparg
Additional argument for some dump functions.
Definition: global.h:247
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:248
nroferrors
EXTERN long nroferrors
If it exceeds MAX_ERRORS, call fatal()
Definition: global.h:135
logfile
EXTERN FILE * logfile
Used by server/daemon.c.
Definition: global.h:143
blocks_prayer
EXTERN sstring blocks_prayer
For update_position() mostly.
Definition: global.h:159
Settings::death_penalty_level
uint8_t death_penalty_level
How many levels worth of exp may be lost on one death.
Definition: global.h:261
map.h
Settings::reset_loc_time
int reset_loc_time
Number of seconds to put player back at home.
Definition: global.h:265
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:356
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:251
Settings::spell_failure_effects
uint8_t spell_failure_effects
Nasty backlash to spell failures.
Definition: global.h:270
Settings::starting_stat_points
uint8_t starting_stat_points
How many stat points character starts with.
Definition: global.h:323
freearr_x
short freearr_x[SIZEOFFREE]
X offset when searching around a spot.
Definition: object.cpp:299
Settings
Server settings.
Definition: global.h:241
ob_types.h
Settings::meta_on
unsigned int meta_on
True if we should send updates.
Definition: global.h:286
Settings::allow_denied_spells_writing
int allow_denied_spells_writing
If set, players can write spells they can't cast.
Definition: global.h:316
Settings::emergency_mapname
char * emergency_mapname
Map to return players to in emergency.
Definition: global.h:300
spells.h
SPELL_MAPPINGS
#define SPELL_MAPPINGS
Definition: global.h:154
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:278
reopen_logfile
int reopen_logfile
Definition: logger.cpp:27
EXTERN
#define EXTERN
Define external variables.
Definition: global.h:15
Settings::spellpoint_level_depend
uint8_t spellpoint_level_depend
Spell costs go up with level.
Definition: global.h:275
Settings::fastclock
uint8_t fastclock
If true, clock goes warp 9.
Definition: global.h:298
player.h
newserver.h
mapstruct
This is a game-map.
Definition: map.h:315
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:313
define.h
Settings::max_stat
uint8_t max_stat
Maximum stat value - 255 should be sufficient.
Definition: global.h:325
Settings::armor_max_enchant
int armor_max_enchant
Maximum number of times an armor can be enchanted.
Definition: global.h:306
Settings::armor_weight_linear
uint8_t armor_weight_linear
If 1, weight reduction is linear, else exponantiel.
Definition: global.h:308
Settings::worldmaptilesizex
uint32_t worldmaptilesizex
Number of squares wide in a wm tile.
Definition: global.h:296
fatalHook
std::function< void(enum fatal_error err)> fatalHook
Definition: global.h:235
newclient.h
Settings::real_wiz
uint8_t real_wiz
Use mud-like wizards.
Definition: global.h:272
account_char.h
config.h
first_map_ext_path
EXTERN char first_map_ext_path[MAX_BUF]
Path used for per-race start maps.
Definition: global.h:151
Settings::templatedir
const char * templatedir
Directory for the template map.
Definition: global.h:255
trying_emergency_save
EXTERN long trying_emergency_save
True when emergency_save() is reached.
Definition: global.h:134
Settings::worldmaptilesizey
uint32_t worldmaptilesizey
Number of squares high in a wm tile.
Definition: global.h:297
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:236
freedir
int freedir[SIZEOFFREE]
Definition: global.h:177
nrofartifacts
EXTERN long nrofartifacts
Only used in malloc_info().
Definition: global.h:146
commands.h
exiting
EXTERN int exiting
True if the game is about to exit.
Definition: global.h:145
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:311
Settings::account_trusted_host
char * account_trusted_host
Block account creation for untrusted hosts.
Definition: global.h:329
Settings::search_items
uint8_t search_items
Search_items command.
Definition: global.h:268
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:256
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:274
Settings::create_home_portals
uint8_t create_home_portals
If 1, can create portals in unique maps (apartments)
Definition: global.h:312
living.h
Settings::armor_speed_improvement
int armor_speed_improvement
Speed improvement.
Definition: global.h:309
Settings::log_timestamp
int log_timestamp
If set, log will comport a timestamp.
Definition: global.h:319
Settings::who_format
char who_format[MAX_BUF]
The format that the who command should use.
Definition: global.h:277
object.h
libproto.h
autoconf.h
Settings::starting_stat_max
uint8_t starting_stat_max
Maximum value of a starting stat.
Definition: global.h:322
Settings::uniquedir
const char * uniquedir
Directory for the unique items.
Definition: global.h:254
Settings::localdir
const char * localdir
Read/write data files.
Definition: global.h:250