Crossfire Server  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;
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 
176 extern short freearr_x[SIZEOFFREE], freearr_y[SIZEOFFREE];
177 extern int maxfree[SIZEOFFREE], freedir[SIZEOFFREE];
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;
277  char who_format[MAX_BUF];
278  char who_wiz_format[MAX_BUF];
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;
287  char meta_server[MAX_BUF];
288  char meta_host[MAX_BUF];
289  uint16_t meta_port;
290  char meta_comment[MAX_BUF];
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;
301  uint16_t emergency_x, emergency_y;
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 */
EXTERN FILE * logfile
Used by server/daemon.c.
Definition: global.h:143
uint8_t not_permadeth
If true, death is non-permament.
Definition: global.h:263
const char * rules
Name of rules file.
Definition: global.h:280
int ignore_assets_errors
If set then go on running even if there are errors in assets.
Definition: global.h:332
fatalHook fatal_hook
If not NULL then called when fatal() is called.
Definition: global.h:334
uint8_t create_home_portals
If 1, can create portals in unique maps (apartments)
Definition: global.h:312
Spell-related defines: spellpath, subtypes, ...
uint8_t stat_loss_on_death
If true, chars lose a random stat when they die.
Definition: global.h:257
const Face * empty_face
Definition: image.cpp:36
EXTERN long ob_count
Definition: global.h:153
uint8_t max_stat
Maximum stat value - 255 should be sufficient.
Definition: global.h:325
uint32_t worldmaptilesx
Number of tiles wide the worldmap is.
Definition: global.h:294
Material structures and defines.
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
uint8_t spell_encumbrance
Encumbrance effects spells.
Definition: global.h:269
uint32_t worldmaptilesizey
Number of squares high in a wm tile.
Definition: global.h:297
uint8_t starting_stat_min
Minimum value of a starting stat.
Definition: global.h:321
unsigned int meta_on
True if we should send updates.
Definition: global.h:286
uint16_t meta_port
Port number to use for updates.
Definition: global.h:289
Defines for the ingame clock, ticks management and weather system.
uint8_t death_penalty_level
How many levels worth of exp may be lost on one death.
Definition: global.h:261
Defines various flags that both the new client and new server use.
Statistics statistics
Merged spell statistics.
Definition: init.cpp:229
uint64_t spell_merges
Number of spell merges done.
Definition: global.h:354
void * language_t
Strings that should be manipulated through add_string() and free_string().
Definition: global.h:69
uint8_t spellpoint_level_depend
Spell costs go up with level.
Definition: global.h:275
uint16_t csport
Port for new client/server.
Definition: global.h:243
New face structure - this enforces the notion that data is face by face only - you can not change the...
Definition: face.h:14
const char * playerdir
Where the player files are.
Definition: global.h:251
const char * motd
Name of the motd file.
Definition: global.h:279
int16_t max_level
This is read out of exp_table.
Definition: global.h:303
uint32_t worldmapstarty
Starting y tile for the worldmap.
Definition: global.h:293
int reopen_logfile
Definition: logger.cpp:27
Socket structure, represents a client-server connection.
Definition: newserver.h:93
const char * regions
Name of the regions file - libdir is prepended.
Definition: global.h:253
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
int armor_max_enchant
Maximum number of times an armor can be enchanted.
Definition: global.h:306
const Face * smooth_face
Definition: image.cpp:36
This file contains various #defines that select various options.
God-related flags.
uint8_t starting_stat_max
Maximum value of a starting stat.
Definition: global.h:322
LogLevel debug
Default debugging level.
Definition: global.h:244
Settings settings
Global settings.
Definition: init.cpp:139
uint8_t death_penalty_ratio
Hhow much exp should be lost at death.
Definition: global.h:260
EXTERN char first_map_ext_path[MAX_BUF]
Path used for per-race start maps.
Definition: global.h:151
uint32_t worldmaptilesy
Number of tiles high the worldmap is.
Definition: global.h:295
const char * logfilename
Logfile to use.
Definition: global.h:242
uint8_t casting_time
It takes awhile to cast a spell.
Definition: global.h:271
uint64_t spell_hash_full
Number of times spell hash was full.
Definition: global.h:355
uint8_t recycle_tmp_maps
Re-use tmp maps.
Definition: global.h:273
uint16_t emergency_y
Coordinates to use on that map.
Definition: global.h:301
Player-specific structures.
socket_struct * init_sockets
Established connections for clients not yet playing.
Definition: init.cpp:66
const char * news
Name of news file.
Definition: global.h:281
#define SPELL_MAPPINGS
Definition: global.h:154
EXTERN archetype * empty_archetype
Nice to have fast access to it.
Definition: global.h:149
char * log_timestamp_format
Format for timestap, if log_timestamp is set.
Definition: global.h:320
int armor_speed_improvement
Speed improvement.
Definition: global.h:309
const char * dumparg
Additional argument for some dump functions.
Definition: global.h:247
The archetype structure is a set of rules on how to generate and manipulate objects which point to ar...
Definition: object.h:483
EXTERN const char * undead_name
Used in hit_player() in main.c.
Definition: global.h:158
uint8_t search_items
Search_items command.
Definition: global.h:268
Defines and variables used by the artifact generation routines.
uint8_t min_name
Minimum characters for an account or player name.
Definition: global.h:331
This is used for various performance tracking statistics, or just how often certain events are done...
Definition: global.h:353
const char * tmpdir
Directory to use for temporary files.
Definition: global.h:256
int64_t pk_max_experience
Maximum experience one can get for PKing.
Definition: global.h:314
uint8_t always_show_hp
&#39;probe&#39; spell HP bars for all living things (0, 1, or 2)
Definition: global.h:274
const Face * blank_face
Following can just as easily be pointers, but it is easier to keep them like this.
Definition: image.cpp:36
struct linked_char * next
Definition: global.h:100
Party-specific structures.
uint8_t armor_weight_linear
If 1, weight reduction is linear, else exponantiel.
Definition: global.h:308
uint8_t balanced_stat_loss
If true, Death stat depletion based on level etc.
Definition: global.h:262
char * stat_file
Definition: global.h:335
This is a game-map.
Definition: map.h:320
Base class to be informed of where an asset is defined.
Definition: AssetsTracker.h:24
Characters associated with an account.n.
uint8_t armor_speed_linear
If 1, speed improvement is linear, else exponantiel.
Definition: global.h:310
Attack-related definitions.
int maxfree[SIZEOFFREE]
Number of spots around a location, including that location (except for 0)
Definition: object.cpp:311
This represents all archetypes for one particular object type.
Definition: artifact.h:24
EXTERN sstring blocks_prayer
For update_position() mostly.
Definition: global.h:159
Defines various structures and values that are used for the new client server communication method...
#define SIZEOFFREE
Definition: define.h:155
EXTERN long nroferrors
If it exceeds MAX_ERRORS, call fatal()
Definition: global.h:135
Face-related structures.
uint8_t real_wiz
Use mud-like wizards.
Definition: global.h:272
short freearr_y[SIZEOFFREE]
Y offset when searching around a spot.
Definition: object.cpp:305
Defines and structures related to commands the player can send.
uint8_t ignore_plugin_compatibility
If set, don&#39;t check plugin version.
Definition: global.h:327
const char * templatedir
Directory for the template map.
Definition: global.h:255
uint8_t simple_exp
If true, use the simple experience system.
Definition: global.h:264
Alchemy recipe structures.
Server settings.
Definition: global.h:241
EXTERN artifactlist * first_artifactlist
First artifact.
Definition: global.h:127
#define MAX_BUF
Used for all kinds of things.
Definition: define.h:35
Compatibility implementations of useful nonstandard types and functions.
LogLevel
Log levels for the LOG() function.
Definition: logger.h:10
logHook log_callback
Log hook, to intercept log messages.
Definition: global.h:245
Skill-related defines, including subtypes.
uint32_t tick_duration
Gloabal variables:
Definition: time.cpp:35
Object type variables.
const char * confdir
Configuration files.
Definition: global.h:248
Implements a general string buffer: it builds a string by concatenating.
uint8_t account_block_create
Definition: global.h:328
class AssetsTracker * assets_tracker
If not NULL, called each time an asset is defined.
Definition: global.h:333
const char * uniquedir
Directory for the unique items.
Definition: global.h:254
EXTERN long nrofartifacts
Only used in malloc_info().
Definition: global.h:146
uint8_t permanent_exp_ratio
How much exp should be &#39;permenant&#39; and unable to be lost.
Definition: global.h:259
int log_timestamp
If set, log will comport a timestamp.
Definition: global.h:319
EXTERN std::vector< region * > all_regions
All regions.
Definition: global.h:126
const char * datadir
Read only data files.
Definition: global.h:249
EXTERN long nrofallowedstr
Only used in malloc_info().
Definition: global.h:147
uint8_t special_break_map
If set, then submaps in random maps can break the walls.
Definition: global.h:326
int freedir[SIZEOFFREE]
Direction we&#39;re pointing on this spot.
Definition: object.cpp:317
const char * name
Definition: global.h:99
Object structure, the core of Crossfire.
uint16_t set_friendly_fire
Percent of damage done by peaceful player vs player damage.
Definition: global.h:276
int armor_weight_reduction
Weight reduction per enchantment.
Definition: global.h:307
#define EXTERN
Define external variables.
Definition: global.h:15
const char * localdir
Read/write data files.
Definition: global.h:250
Log levels.
uint8_t starting_stat_points
How many stat points character starts with.
Definition: global.h:323
uint8_t no_player_stealing
If 1, can not steal from other players.
Definition: global.h:311
const char * mapdir
Where the map files are.
Definition: global.h:252
EXTERN int exiting
True if the game is about to exit.
Definition: global.h:145
EXTERN long trying_emergency_save
True when emergency_save() is reached.
Definition: global.h:134
uint64_t spell_suppressions
Number of times ok_to_put_more() returned FALSE.
Definition: global.h:356
This file contains basic map-related structures and macros.
EXTERN char first_map_path[MAX_BUF]
The start-level.
Definition: global.h:150
uint32_t pticks
Used by various function to determine how often to save the character.
Definition: time.cpp:47
uint8_t fastclock
If true, clock goes warp 9.
Definition: global.h:298
uint8_t crypt_mode
0 for legacy behavior, 1 for always Traditional
Definition: global.h:330
uint8_t dumpvalues
Set to dump various values/tables.
Definition: global.h:246
EXTERN player * first_player
First player.
Definition: global.h:124
std::function< void(LogLevel, const char *, va_list)> logHook
Definition: global.h:236
int reset_loc_time
Number of seconds to put player back at home.
Definition: global.h:265
uint8_t set_title
Players can set thier title.
Definition: global.h:266
One player.
Definition: player.h:107
short freearr_x[SIZEOFFREE]
X offset when searching around a spot.
Definition: object.cpp:299
uint32_t worldmapstartx
Starting x tile for the worldmap.
Definition: global.h:292
Structure containing object statistics.
std::function< void(enum fatal_error err)> fatalHook
Definition: global.h:235
int allow_denied_spells_writing
If set, players can write spells they can&#39;t cast.
Definition: global.h:316
const char * sstring
Definition: sstring.h:2
char * emergency_mapname
Map to return players to in emergency.
Definition: global.h:300
uint8_t roll_stat_points
How many stat points legacy (rolled) chars start with.
Definition: global.h:324
uint32_t worldmaptilesizex
Number of squares wide in a wm tile.
Definition: global.h:296
int pk_max_experience_percent
Percentage of experience of victim the killer gets.
Definition: global.h:315
Object type functions and variables.
uint8_t spell_failure_effects
Nasty backlash to spell failures.
Definition: global.h:270
Describes fundental parameters of &#39;books&#39; - objects with type==BOOK.
EXTERN mapstruct * first_map
First map.
Definition: global.h:125
Artifact-related structures.
float item_power_factor
See note in setings file.
Definition: global.h:304
uint8_t resurrection
Ressurection possible w/ permadeth on.
Definition: global.h:267
int16_t pk_luck_penalty
Amount by which player luck is reduced if they PK.
Definition: global.h:258
uint8_t personalized_blessings
If 1, blessed weapons get an owner and a willpower value.
Definition: global.h:313
Core defines: object types, flags, etc.
char * account_trusted_host
Block account creation for untrusted hosts.
Definition: global.h:329