Crossfire Server, Trunk  1.75.0
init.cpp
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 1999-2014 Mark Wedel and the Crossfire Development Team
5  * Copyright (c) 1992 Frank Tore Johansen
6  *
7  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
8  * welcome to redistribute it under certain conditions. For details, please
9  * see COPYING and LICENSE.
10  *
11  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
12  */
13 
19 #include "global.h"
20 
21 #include <errno.h>
22 #include <signal.h>
23 #include <stdlib.h>
24 #include <string.h>
25 
26 /* Needed for strcasecmp(). */
27 #ifndef WIN32
28 #include <strings.h>
29 #endif
30 
31 #include "loader.h"
32 #include "version.h"
33 #include "server.h"
34 #include "sproto.h"
35 #include "assets.h"
36 #include "modules.h"
37 
38 static void help(void);
39 static void init_beforeplay(void);
40 static void init_startup(void);
41 
43 
45 static int should_exit = 0;
46 
48  const char *name;
49  char const *description;
50  bool enabled;
51  void (*init)(Settings *, ServerSettings *);
52  void (*close)();
53 };
54 
57  { "citybell", "Ring bells every hour for defined temples", true, cfcitybell_init, cfcitybell_close },
58  { "citylife", "Add NPCs in towns", true, citylife_init, citylife_close },
59  { "rhg", "Add random maps to exits in towns", false, random_house_generator_init, random_house_generator_close },
60  { "weather", "Add weather effects to the world map.", false, cfweather_init, cfweather_close },
61  { NULL, NULL, false, NULL, NULL }
62 };
63 
67 void init_modules() {
68  LOG(llevInfo, "Initializing modules\n");
69  for (int module = 0; modules[module].name != NULL; module++) {
70  module_information *mod = &modules[module];
71  if (!mod->enabled) {
72  LOG(llevInfo, " %s (%s): disabled\n", mod->name, mod->description);
73  } else {
74  mod->init(&settings, &serverSettings);
75  LOG(llevInfo, " %s (%s): activated\n", mod->name, mod->description);
76  }
77  }
78 }
79 
83 void close_modules() {
84  LOG(llevInfo, "Cleaning modules\n");
85  for (int module = 0; modules[module].name != NULL; module++) {
86  module_information *mod = &modules[module];
87  if (mod->enabled) {
88  mod->close();
89  LOG(llevInfo, " %s (%s): closed\n", mod->name, mod->description);
90  }
91  }
92 }
93 
97 static void list_modules() {
98  LOG(llevInfo, "Built-in modules:\n");
99  for (int module = 0; modules[module].name != NULL; module++) {
100  LOG(llevInfo, " %s: %s -> %s\n", modules[module].name, modules[module].description, modules[module].enabled ? "enabled" : "disabled");
101  }
102  should_exit = 1;
103 }
104 
109 static void set_logfile(char *val) {
110  settings.logfilename = val;
111 }
112 
114 static void call_version(void) {
115  puts(FULL_VERSION);
116  exit(EXIT_SUCCESS);
117 }
118 
120 static void set_debug(void) {
122 }
123 
125 static void unset_debug(void) {
127 }
128 
130 static void set_mondebug(void) {
132 }
133 
135 static void set_dumpmon1(void) {
136  settings.dumpvalues = 1;
137 }
138 
140 static void set_dumpmon2(void) {
141  settings.dumpvalues = 2;
142 }
143 
145 static void set_dumpmon3(void) {
146  settings.dumpvalues = 3;
147 }
148 
150 static void set_dumpmon4(void) {
151  settings.dumpvalues = 4;
152 }
153 
155 static void set_dumpmon5(void) {
156  settings.dumpvalues = 5;
157 }
158 
160 static void set_dumpmon6(void) {
161  settings.dumpvalues = 6;
162 }
163 
165 static void set_dumpmon7(void) {
166  settings.dumpvalues = 7;
167 }
168 
170 static void set_dumpmon8(void) {
171  settings.dumpvalues = 8;
172 }
173 
175 static void set_dumpmon9(void) {
176  settings.dumpvalues = 9;
177 }
178 
183 static void set_dumpmont(const char *name) {
184  settings.dumpvalues = 10;
186 }
187 
192 static void set_datadir(const char *path) {
193  settings.datadir = path;
194 }
195 
200 static void set_confdir(const char *path) {
201  settings.confdir = path;
202 }
203 
208 static void set_localdir(const char *path) {
209  settings.localdir = path;
210 }
211 
216 static void set_mapdir(const char *path) {
217  settings.mapdir = path;
218 }
219 
224 static void set_regions(const char *path) {
225  settings.regions = path;
226 }
227 
232 static void set_uniquedir(const char *path) {
233  settings.uniquedir = path;
234 }
235 
240 static void set_templatedir(const char *path) {
241  settings.templatedir = path;
242 }
243 
248 static void set_playerdir(const char *path) {
249  settings.playerdir = path;
250 }
251 
256 static void set_tmpdir(const char *path) {
257  settings.tmpdir = path;
258 }
259 
265 }
266 
267 static void server_pack_assets(const char *assets, const char *filename) {
268  assets_pack(assets, filename);
269  should_exit = 1;
270 }
271 
272 static void free_materials(void);
273 
280 static void set_csport(const char *val) {
281  int port = atoi(val);
282  if (port <= 0 || port > 65535) {
283  LOG(llevError, "%d is an invalid csport number, must be between 1 and 65535.\n", port);
284  exit(1);
285  }
286  settings.csport = port;
287 }
288 
293 static void set_disable_plugin(const char *name) {
294  serverSettings.disabled_plugins.push_back(std::string(name ? name : ""));
295 }
296 
303 static void do_module(const char *name, bool enabled) {
304  bool one = false;
305  for (int module = 0; modules[module].name; module++) {
306  if (strcmp("All", name) == 0 || strcmp(modules[module].name, name) == 0) {
307  modules[module].enabled = enabled;
308  one = true;
309  }
310  }
311  if (!one) {
312  LOG(llevError, "Invalid module name %s\n", name);
314  }
315 }
316 
321 static void set_disable_module(const char *name) {
322  do_module(name, false);
323 }
324 
329 static void set_enable_module(const char *name) {
330  do_module(name, true);
331 }
332 
336 static void server_dump_animations(void) {
337  dump_animations();
338  cleanup();
339 }
340 
344 static void server_dump_faces(void) {
345  dump_faces();
346  cleanup();
347 }
348 
352 static void server_dump_bonuses() {
354  cleanup();
355 }
356 
359 typedef void (*cmdlinefunc_args0)(void);
360 typedef void (*cmdlinefunc_args1)(const char* arg1);
361 typedef void (*cmdlinefunc_args2)(const char* arg1, const char* arg2);
370  const char *cmd_option;
371  uint8_t num_args;
372  uint8_t pass;
373  void (*func)();
377 };
378 
387 static struct Command_Line_Options options[] = {
391  { "-conf", 1, 1, (cmdlinefunc_args0)set_confdir },
392  { "-d", 0, 1, (cmdlinefunc_args0)set_debug },
393  { "-data", 1, 1, (cmdlinefunc_args0)set_datadir },
394  { "-disable-plugin", 1, 1, (cmdlinefunc_args0)set_disable_plugin },
395  { "-disable-module", 1, 1, (cmdlinefunc_args0)set_disable_module },
396  { "-enable-module", 1, 1, (cmdlinefunc_args0)set_enable_module },
397  { "-list-modules", 0, 1, (cmdlinefunc_args0)list_modules },
398  { "-h", 0, 1, (cmdlinefunc_args0)help },
399  { "-ignore-assets-errors", 0, 1, (cmdlinefunc_args0)set_ignore_assets_errors },
400  { "-local", 1, 1, (cmdlinefunc_args0)set_localdir },
401  { "-log", 1, 1, (cmdlinefunc_args0)set_logfile },
402  { "-maps", 1, 1, (cmdlinefunc_args0)set_mapdir },
403  { "-mon", 0, 1, (cmdlinefunc_args0)set_mondebug },
404  { "-n", 0, 1, (cmdlinefunc_args0)unset_debug },
405  { "-playerdir", 1, 1, (cmdlinefunc_args0)set_playerdir },
406  { "-regions", 1, 1, (cmdlinefunc_args0)set_regions },
407  { "-templatedir", 1, 1, (cmdlinefunc_args0)set_templatedir },
408  { "-tmpdir", 1, 1, (cmdlinefunc_args0)set_tmpdir },
409  { "-uniquedir", 1, 1, (cmdlinefunc_args0)set_uniquedir },
410  { "-v", 0, 1, (cmdlinefunc_args0)call_version },
411 
412 #ifdef WIN32
413  /* Windows service stuff */
414  { "-regsrv", 0, 1, service_register },
415  { "-unregsrv", 0, 1, service_unregister },
416  { "-srv", 0, 1, service_handle },
417 #endif
418 
422  { "-p", 1, 2, (cmdlinefunc_args0)set_csport },
423 
427  { "-m", 0, 3, (cmdlinefunc_args0)set_dumpmon1 },
428  { "-m2", 0, 3, (cmdlinefunc_args0)set_dumpmon2 },
429  { "-m3", 0, 3, (cmdlinefunc_args0)set_dumpmon3 },
430  { "-m4", 0, 3, (cmdlinefunc_args0)set_dumpmon4 },
431  { "-m5", 0, 3, (cmdlinefunc_args0)set_dumpmon5 },
432  { "-m6", 0, 3, (cmdlinefunc_args0)set_dumpmon6 },
433  { "-m7", 0, 3, (cmdlinefunc_args0)set_dumpmon7 },
434  { "-m8", 0, 3, (cmdlinefunc_args0)set_dumpmon8 },
435  { "-m9", 0, 3, (cmdlinefunc_args0)set_dumpmon9 },
436  { "-mt", 1, 3, (cmdlinefunc_args0)set_dumpmont },
437  { "-mexp", 0, 3, (cmdlinefunc_args0)dump_experience },
438  { "-mq", 0, 3, (cmdlinefunc_args0)dump_quests },
439  { "-dump-anims", 0, 3, (cmdlinefunc_args0)server_dump_animations },
440  { "-dump-faces", 0, 3, (cmdlinefunc_args0)server_dump_faces },
441  { "-pack-assets", 2, 3, (cmdlinefunc_args0)server_pack_assets },
442  { "-dump-stat-bonuses", 0, 3, (cmdlinefunc_args0)server_dump_bonuses },
443 };
444 
459 static void parse_args(int argc, char *argv[], int pass) {
460  size_t i;
461  int on_arg = 1;
462 
463  while (on_arg < argc) {
464  for (i = 0; i < sizeof(options)/sizeof(struct Command_Line_Options); i++) {
465  if (!strcmp(options[i].cmd_option, argv[on_arg])) {
466  /* Found a matching option, but should not be processed on
467  * this pass. Just skip over it
468  */
469  if (options[i].pass != pass) {
470  on_arg += options[i].num_args+1;
471  break;
472  }
473  if (options[i].num_args) {
474  if ((on_arg+options[i].num_args) >= argc) {
475  fprintf(stderr, "%s requires an argument.\n", options[i].cmd_option);
476  exit(1);
477  }
478 
479  if (options[i].num_args == 1)
480  ((cmdlinefunc_args1)options[i].func)(argv[on_arg+1]);
481  if (options[i].num_args == 2)
482  ((cmdlinefunc_args2)options[i].func)(argv[on_arg+1], argv[on_arg+2]);
483  on_arg += options[i].num_args+1;
484  } else { /* takes no args */
486  on_arg++;
487  }
488  break;
489  }
490  }
491  if (i == sizeof(options)/sizeof(struct Command_Line_Options)) {
492  fprintf(stderr, "Unknown option: %s\n", argv[on_arg]);
493  fprintf(stderr, "Type '%s -h' for usage.\n", argv[0]);
494  exit(1);
495  }
496  }
497 
498  if (should_exit) {
499  cleanup();
500  }
501 }
502 
512  materialtype_t *mt;
513  int i;
514 
515  mt = (materialtype_t *)malloc(sizeof(materialtype_t));
516  if (mt == NULL)
518  mt->name = NULL;
519  mt->description = NULL;
520  for (i = 0; i < NROFATTACKS; i++) {
521  mt->save[i] = 0;
522  mt->mod[i] = 0;
523  }
524  return mt;
525 }
526 
531 static void load_materials(BufferReader *reader, const char *filename) {
532  char *buf, *cp, *next;
533  materialtype_t *mt = NULL;
534  int i, value;
535  (void)filename;
536  int line = 0;
537 
538  while ((buf = bufferreader_next_line(reader)) != NULL) {
539  line++;
540  if (*buf == '#')
541  continue;
542  cp = buf;
543  while (*cp == ' ') /* Skip blanks */
544  cp++;
545  if (!strncmp(cp, "name", 4)) {
546  mt = get_empty_mat();
547  materials.push_back(mt);
548  mt->name = add_string(strchr(cp, ' ')+1);
549  mt->description = add_refcount(mt->name);
550  }
551 
552  if (mt == NULL) {
553  LOG(llevError, "%s:%d: fields must come after a name line\n", filename, line);
555  }
556 
557  if (!strncmp(cp, "description", 11)) {
558  FREE_AND_COPY_IF(mt->description, strchr(cp, ' ')+1);
559  } else if (sscanf(cp, "material %d", &value)) {
560  mt->material = value;
561  } else if (!strncmp(cp, "saves", 5)) {
562  cp = strchr(cp, ' ')+1;
563  for (i = 0; i < NROFATTACKS; i++) {
564  if (cp == NULL) {
565  mt->save[i] = 0;
566  continue;
567  }
568  if ((next = strchr(cp, ',')) != NULL)
569  *(next++) = '\0';
570  sscanf(cp, "%d", &value);
571  mt->save[i] = (int8_t)value;
572  cp = next;
573  }
574  } else if (!strncmp(cp, "mods", 4)) {
575  cp = strchr(cp, ' ')+1;
576  for (i = 0; i < NROFATTACKS; i++) {
577  if (cp == NULL) {
578  mt->save[i] = 0;
579  continue;
580  }
581  if ((next = strchr(cp, ',')) != NULL)
582  *(next++) = '\0';
583  sscanf(cp, "%d", &value);
584  mt->mod[i] = (int8_t)value;
585  cp = next;
586  }
587  }
588  }
589  LOG(llevDebug, "loaded %d material type data\n", static_cast<int>(materials.size()));
590 }
591 
595 static void free_materials(void) {
596  for (auto material : materials) {
597  free(material);
598  }
599  materials.clear();
600 }
601 
607 void load_settings(void) {
608  static char motd[MAX_BUF] = { 0 };
609  char buf[MAX_BUF], *cp, dummy[1];
610  int has_val;
611  FILE *fp;
612 
613  dummy[0] = '\0';
614  snprintf(buf, sizeof(buf), "%s/settings", settings.confdir);
615 
616  /* We don't require a settings file at current time, but down the road,
617  * there will probably be so many values that not having a settings file
618  * will not be a good thing.
619  */
620  if ((fp = fopen(buf, "r")) == NULL) {
621  LOG(llevError, "Warning: No settings file found\n");
622  return;
623  }
624  while (fgets(buf, MAX_BUF-1, fp) != NULL) {
625  if (buf[0] == '#')
626  continue;
627  /* eliminate newline */
628  if ((cp = strrchr(buf, '\n')) != NULL)
629  *cp = '\0';
630 
631  /* Skip over empty lines */
632  if (buf[0] == 0)
633  continue;
634 
635  /* Skip all the spaces and set them to nulls. If not space,
636  * set cp to "" to make strcpy's and the like easier down below.
637  */
638  if ((cp = strchr(buf, ' ')) != NULL) {
639  while (*cp == ' ')
640  *cp++ = 0;
641  has_val = 1;
642  } else {
643  cp = dummy;
644  has_val = 0;
645  }
646 
647  if (!strcasecmp(buf, "metaserver_notification")) {
648  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
650  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
652  } else {
653  LOG(llevError, "load_settings: Unknown value for metaserver_notification: %s\n", cp);
654  }
655  } else if (!strcasecmp(buf, "metaserver_server")) {
656  if (has_val)
658  else
659  LOG(llevError, "load_settings: metaserver_server must have a value.\n");
660  } else if (!strcasecmp(buf, "motd")) {
661  if (has_val) {
662  safe_strncpy(motd, cp, sizeof(motd));
663  settings.motd = motd;
664  } else
665  LOG(llevError, "load_settings: motd must have a value.\n");
666  } else if (!strcasecmp(buf, "metaserver_host")) {
667  if (has_val)
669  else
670  LOG(llevError, "load_settings: metaserver_host must have a value.\n");
671  } else if (!strcasecmp(buf, "port")) {
672  set_csport(cp);
673  } else if (!strcasecmp(buf, "metaserver_port")) {
674  int port = atoi(cp);
675 
676  if (port < 1 || port > 65535)
677  LOG(llevError, "load_settings: metaserver_port must be between 1 and 65535, %d is invalid\n", port);
678  else
679  settings.meta_port = port;
680  } else if (!strcasecmp(buf, "metaserver_comment")) {
682  } else if (!strcasecmp(buf, "worldmapstartx")) {
683  int size = atoi(cp);
684 
685  if (size < 0)
686  LOG(llevError, "load_settings: worldmapstartx must be at least 0, %d is invalid\n", size);
687  else
688  settings.worldmapstartx = size;
689  } else if (!strcasecmp(buf, "worldmapstarty")) {
690  int size = atoi(cp);
691 
692  if (size < 0)
693  LOG(llevError, "load_settings: worldmapstarty must be at least 0, %d is invalid\n", size);
694  else
695  settings.worldmapstarty = size;
696  } else if (!strcasecmp(buf, "worldmaptilesx")) {
697  int size = atoi(cp);
698 
699  if (size < 1)
700  LOG(llevError, "load_settings: worldmaptilesx must be greater than 1, %d is invalid\n", size);
701  else
702  settings.worldmaptilesx = size;
703  } else if (!strcasecmp(buf, "worldmaptilesy")) {
704  int size = atoi(cp);
705 
706  if (size < 1)
707  LOG(llevError, "load_settings: worldmaptilesy must be greater than 1, %d is invalid\n", size);
708  else
709  settings.worldmaptilesy = size;
710  } else if (!strcasecmp(buf, "fastclock")) {
711  int lev = atoi(cp);
712 
713  if (lev < 0)
714  LOG(llevError, "load_settings: fastclock must be at least 0, %d is invalid\n", lev);
715  else
716  settings.fastclock = lev;
717  } else if (!strcasecmp(buf, "not_permadeth")) {
718  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
720  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
722  } else {
723  LOG(llevError, "load_settings: Unknown value for not_permadeth: %s\n", cp);
724  }
725  } else if (!strcasecmp(buf, "resurrection")) {
726  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
728  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
730  } else {
731  LOG(llevError, "load_settings: Unknown value for resurrection: %s\n", cp);
732  }
733  } else if (!strcasecmp(buf, "set_title")) {
734  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
736  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
738  } else {
739  LOG(llevError, "load_settings: Unknown value for set_title: %s\n", cp);
740  }
741  } else if (!strcasecmp(buf, "search_items")) {
742  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
744  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
746  } else {
747  LOG(llevError, "load_settings: Unknown value for search_items: %s\n", cp);
748  }
749  } else if (!strcasecmp(buf, "spell_encumbrance")) {
750  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
752  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
754  } else {
755  LOG(llevError, "load_settings: Unknown value for spell_encumbrance: %s\n", cp);
756  }
757  } else if (!strcasecmp(buf, "spell_failure_effects")) {
758  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
760  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
762  } else {
763  LOG(llevError, "load_settings: Unknown value for spell_failure_effects: %s\n", cp);
764  }
765  } else if (!strcasecmp(buf, "casting_time")) {
766  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
768  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
770  } else {
771  LOG(llevError, "load_settings: Unknown value for casting_time: %s\n", cp);
772  }
773  } else if (!strcasecmp(buf, "real_wiz")) {
774  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
776  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
778  } else {
779  LOG(llevError, "load_settings: Unknown value for real_wiz: %s\n", cp);
780  }
781  } else if (!strcasecmp(buf, "recycle_tmp_maps")) {
782  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
784  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
786  } else {
787  LOG(llevError, "load_settings: Unknown value for recycle_tmp_maps: %s\n", cp);
788  }
789  } else if (!strcasecmp(buf, "always_show_hp")) {
790  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
792  } else if (!strcasecmp(cp, "damaged")) {
794  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
796  } else {
797  LOG(llevError, "load_settings: Unknown value for always_show_hp: %s\n", cp);
798  }
799  } else if (!strcasecmp(buf, "who_format")) {
800  if (has_val)
802  sizeof(settings.who_format));
803  } else if (!strcasecmp(buf, "who_wiz_format")) {
804  if (has_val) {
806  sizeof(settings.who_wiz_format));
807  }
808  } else if (!strcasecmp(buf, "spellpoint_level_depend")) {
809  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
811  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
813  } else {
814  LOG(llevError, "load_settings: Unknown value for spellpoint_level_depend: %s\n", cp);
815  }
816  } else if (!strcasecmp(buf, "stat_loss_on_death")) {
817  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
819  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
821  } else {
822  LOG(llevError, "load_settings: Unknown value for stat_loss_on_death: %s\n", cp);
823  }
824  } else if (!strcasecmp(buf, "use_permanent_experience")) {
825  LOG(llevError, "use_permanent_experience is deprecated, usepermenent_experience_percentage instead\n");
826  } else if (!strcasecmp(buf, "permanent_experience_percentage")) {
827  int val = atoi(cp);
828  if (val < 0 || val > 100)
829  LOG(llevError, "load_settings: permenent_experience_percentage must be between 0 and 100, %d is invalid\n", val);
830  else
832  } else if (!strcasecmp(buf, "death_penalty_percentage")) {
833  int val = atoi(cp);
834  if (val < 0 || val > 100)
835  LOG(llevError, "load_settings: death_penalty_percentage must be between 0 and 100, %d is invalid\n", val);
836  else
838  } else if (!strcasecmp(buf, "death_penalty_levels")) {
839  int val = atoi(cp);
840  if (val < 0 || val > 255)
841  LOG(llevError, "load_settings: death_penalty_levels can not be negative, %d is invalid\n", val);
842  else
844  } else if (!strcasecmp(buf, "balanced_stat_loss")) {
845  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
847  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
849  } else {
850  LOG(llevError, "load_settings: Unknown value for balanced_stat_loss: %s\n", cp);
851  }
852  } else if (!strcasecmp(buf, "simple_exp")) {
853  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
855  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
857  } else {
858  LOG(llevError, "load_settings: Unknown value for simple_exp: %s\n", cp);
859  }
860  } else if (!strcasecmp(buf, "item_power_factor")) {
861  float tmp = atof(cp);
862  if (tmp < 0)
863  LOG(llevError, "load_settings: item_power_factor must be a positive number (%f < 0)\n", tmp);
864  else
866  } else if (!strcasecmp(buf, "pk_luck_penalty")) {
867  int16_t val = atoi(cp);
868 
869  if (val < -100 || val > 100)
870  LOG(llevError, "load_settings: pk_luck_penalty must be between -100 and 100, %d is invalid\n", val);
871  else
873  } else if (!strcasecmp(buf, "set_friendly_fire")) {
874  int val = atoi(cp);
875 
876  if (val < 1 || val > 100)
877  LOG(llevError, "load_settings: set_friendly_fire must be between 1 an 100, %d is invalid\n", val);
878  else
880  } else if (!strcasecmp(buf, "armor_max_enchant")) {
881  int max_e = atoi(cp);
882  if (max_e <= 0)
883  LOG(llevError, "load_settings: armor_max_enchant is %d\n", max_e);
884  else
885  settings.armor_max_enchant = max_e;
886  } else if (!strcasecmp(buf, "armor_weight_reduction")) {
887  int wr = atoi(cp);
888  if (wr < 0)
889  LOG(llevError, "load_settings: armor_weight_reduction is %d\n", wr);
890  else
892  } else if (!strcasecmp(buf, "armor_weight_linear")) {
893  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
895  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
897  } else {
898  LOG(llevError, "load_settings: unknown value for armor_weight_linear: %s\n", cp);
899  }
900  } else if (!strcasecmp(buf, "armor_speed_improvement")) {
901  int wr = atoi(cp);
902  if (wr < 0)
903  LOG(llevError, "load_settings: armor_speed_improvement is %d\n", wr);
904  else
906  } else if (!strcasecmp(buf, "armor_speed_linear")) {
907  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
909  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
911  } else {
912  LOG(llevError, "load_settings: unknown value for armor_speed_linear: %s\n", cp);
913  }
914  } else if (!strcasecmp(buf, "no_player_stealing")) {
915  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
917  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
919  } else {
920  LOG(llevError, "load_settings: unknown value for no_player_stealing: %s\n", cp);
921  }
922  } else if (!strcasecmp(buf, "create_home_portals")) {
923  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
924 #ifdef TRY_BROKEN_TOWN_PORTALS
926 #else
927  LOG(llevError, "load_settings: create_home_portals is currently broken. It results in town portals that prematurely reset when the apartment is swapped.\n");
928 #endif
929  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
931  } else {
932  LOG(llevError, "load_settings: unknown value for create_home_portals: %s\n", cp);
933  }
934  } else if (!strcasecmp(buf, "personalized_blessings")) {
935  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
937  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
939  } else {
940  LOG(llevError, "load_settings: unknown value for personalized_blessings: %s\n", cp);
941  }
942  } else if (!strcasecmp(buf, "pk_max_experience")) {
943  int64_t pkme = atoll(cp);
944  if (pkme < 0)
945  pkme = -1;
947  } else if (!strcasecmp(buf, "pk_max_experience_percent")) {
948  int pkmep = atoi(cp);
949  if (pkmep < 0) {
950  LOG(llevError, "load_settings: pk_max_experience_percent should be positive or zero (was \"%s\")\n", cp);
951  } else
953  } else if (!strcasecmp(buf, "allow_denied_spells_writing")) {
954  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
956  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
958  } else {
959  LOG(llevError, "load_settings: unknown value for allow_denied_spells_writing: %s\n", cp);
960  }
961  } else if (!strcasecmp(buf, "allow_broken_converters")) {
962  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
964  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
966  } else {
967  LOG(llevError, "load_settings: unknown value for allow_broken_converters: %s\n", cp);
968  }
969  } else if (!strcasecmp(buf, "log_timestamp")) {
970  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
972  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
974  } else {
975  LOG(llevError, "load_settings: unknown value for log_timestamp: %s\n", cp);
976  }
977  } else if (!strcasecmp(buf, "log_timestamp_format")) {
980  } else if (!strcasecmp(buf, "starting_stat_min")) {
981  int val = atoi(cp);
982 
983  if (val < 1 || val > settings.max_stat || val > settings.starting_stat_max)
984  LOG(llevError, "load_settings: starting_stat_min (%d) need to be within %d-%d (%d)\n",
986  else
988  } else if (!strcasecmp(buf, "starting_stat_max")) {
989  int val = atoi(cp);
990 
991  if (val < 1 || val > settings.max_stat || val<settings.starting_stat_min)
992  LOG(llevError, "load_settings: starting_stat_max (%d) need to be within %d-%d (%d)\n",
994  else
996  } else if (!strcasecmp(buf, "starting_stat_points")) {
997  int val = atoi(cp);
998 
999  if (val < NUM_STATS * settings.starting_stat_min ||
1001  LOG(llevError, "load_settings: starting_stat_points (%d) need to be within %d-%d\n",
1003  else
1005  } else if (!strcasecmp(buf, "roll_stat_points")) {
1006  int val = atoi(cp);
1007 
1008  /* The 3 and 18 values are hard coded in because we know that
1009  * roll_stat() generates a value between 3 and 18 - if that ever
1010  * changed, this code should change also, but that code will eventually
1011  * go away.
1012  */
1013  if (val < NUM_STATS * 3 || val > NUM_STATS * 18)
1014  LOG(llevError, "load_settings: roll_stat_points need to be within %d-%d\n",
1015  NUM_STATS * 3, NUM_STATS * 18);
1016  else
1017  settings.roll_stat_points = val;
1018  } else if (!strcasecmp(buf, "special_break_map")) {
1019  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
1021  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
1023  } else {
1024  LOG(llevError, "load_settings: unknown value for special_break_map: %s\n", cp);
1025  }
1026  } else if (!strcasecmp(buf, "ignore_plugin_compatibility")) {
1027  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
1029  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
1031  } else {
1032  LOG(llevError, "load_settings: unknown value for ignore_plugin_compatibility: %s\n", cp);
1033  }
1034  } else if (!strcasecmp(buf, "account_block_create")) {
1035  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
1037  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
1039  } else {
1040  LOG(llevError, "load_settings: unknown value for account_block_create: %s\n", cp);
1041  }
1042  } else if (!strcasecmp(buf, "account_trusted_host")) {
1045  } else if (!strcasecmp(buf, "crypt_mode")) {
1046  int val = atoi(cp);
1047  if (val != 0 && val != 1) {
1048  LOG(llevError, "load_settings: crypt_mode must be 0 or 1\n");
1049  } else {
1050  settings.crypt_mode = val;
1051  }
1052  } else if (!strcasecmp(buf, "min_name")) {
1053  int val = atoi(cp);
1054 
1055  if (val < 1 || val > MAX_NAME )
1056  LOG(llevError, "load_settings: min_name (%d) need to be within %d-%d\n",
1057  val, 1, MAX_NAME);
1058  else
1059  settings.min_name = val;
1060  } else if (!strcasecmp(buf, "stat_file")) {
1062  } else {
1063  LOG(llevError, "Unknown value in settings file: %s\n", buf);
1064  }
1065  }
1066  fclose(fp);
1067  if (settings.log_timestamp_format == NULL)
1068  settings.log_timestamp_format = strdup_local("%y/%m/%d %H:%M:%S");
1069 
1070  /*
1071  * The who formats are defined in config to be blank. They should have been
1072  * overridden by the settings file, if there are no entries however, it will
1073  * have stayed blank. Since this probably isn't what is wanted, we will check if
1074  * new formats have been specified, and if not we will use the old defaults.
1075  */
1076  if (!strcmp(settings.who_format, ""))
1077  strcpy(settings.who_format, "%N_%t%h%d%b%n<%M>");
1078  if (!strcmp(settings.who_wiz_format, ""))
1079  strcpy(settings.who_wiz_format, "%N_%t%h%d%b%nLevel %l <%M>(@%i)(%c)");
1080 }
1081 
1085 }
1086 
1094 void init(int argc, char **argv) {
1095  logfile = stderr;
1096 
1097  /* First argument pass - right now it does nothing, but in the future specifying
1098  * the LibDir in this pass would be reasonable. */
1099  parse_args(argc, argv, 1);
1100 
1102 
1103  init_library(); /* Must be called early */
1104  load_settings(); /* Load the settings file */
1105  parse_args(argc, argv, 2);
1106 
1107  LOG(llevInfo, "Crossfire %s\n", FULL_VERSION);
1108  SRANDOM(time(NULL));
1109 
1110  init_startup(); /* Check shutdown/forbid files */
1111  init_signals(); /* Sets up signal interceptions */
1112  commands_init(); /* Sort command tables */
1113  read_map_log(); /* Load up the old temp map files */
1114  init_skills();
1115  init_ob_methods();
1116  cftimer_init();
1117  hiscore_init();
1118 
1119  parse_args(argc, argv, 3);
1120 
1121  init_beforeplay();
1122  init_modules();
1123  if (argc != 0) {
1124  // Invocations from the command-line (e.g. crossfire-server) have the
1125  // binary name in argv[0]. If that is not there, assume we are running
1126  // as a test and don't create sockets.
1127  init_server();
1128  } else {
1129  LOG(llevInfo, "Running server in test mode (no sockets).\n");
1130  }
1131  metaserver2_init();
1132  accounts_load();
1133  reset_sleep();
1134 }
1135 
1141 void free_server(void) {
1142  free_materials();
1143  free_races();
1144  free_quest();
1146 }
1147 
1151 static void help(void) {
1152  printf("Usage: crossfire-server [options]\n\n");
1153 
1154  printf("Options:\n");
1155  printf(" -conf Set the directory to find configuration files.\n");
1156  printf(" -d Turn on extra debugging messages.\n");
1157  printf(" -data Set the data (share/) directory (archetypes, treasures, etc).\n");
1158  printf(" -disable-module\n"
1159  " Disable specified module, by its name\n"
1160  " Can be specified multiple times. 'All' disables all modules.\n");
1161  printf(" -enable-module\n"
1162  " Enable specified module, by its name\n"
1163  " Can be specified multiple times. 'All' enables all modules.\n");
1164  printf(" -disable-plugin\n"
1165  " Disables specified plugin. Use the name without the extension.\n"
1166  " Can be specified multiple times. 'All' disables all plugins.\n");
1167  printf(" -dump-anims Dump animations.\n");
1168  printf(" -h Print this help message.\n");
1169  printf(" -ignore-assets-errors\n");
1170  printf(" Allow going on even if there are errors in assets.\n");
1171  printf(" Warning: this may lead to strange behaviour.\n");
1172  printf(" -list-modules\n"
1173  " List built-in modules and exit.\n");
1174  printf(" -local Set the local data (var/) directory.\n");
1175  printf(" -log <file> Write logging information to the given file.\n");
1176  printf(" -m List suggested experience for all monsters.\n");
1177  printf(" -m2 Dump monster abilities.\n");
1178  printf(" -m3 Dump artifact information.\n");
1179  printf(" -m4 Dump spell information.\n");
1180  printf(" -m5 Dump skill information.\n");
1181  printf(" -m6 Dump race information.\n");
1182  printf(" -m7 Dump alchemy information.\n");
1183  printf(" -m8 Dump gods information.\n");
1184  printf(" -m9 Dump more alchemy information (formula checking).\n");
1185  printf(" -maps Set the map directory.\n");
1186  printf(" -mexp Dump the experience table.\n");
1187  printf(" -mon Turn on monster debugging.\n");
1188  printf(" -mq Dump the quest list.\n");
1189  printf(" -mt <name> Dump a list of treasures for a monster.\n");
1190  printf(" -n Turn off debugging messages if on by default.\n");
1191  printf(" -p <port> Specifies the port to listen on for incoming connections.\n");
1192  printf(" -pack-assets <type> <filename>\n");
1193  printf(" Packs specified assets type to the specified filename.\n");
1194  printf(" Valid assets type are: archs, treasures, faces, messages, facesets, artifacts, formulae, images, quests.\n");
1195  printf(" The file format will be tar ('images') or text (everything else).\n");
1196  printf(" It is possible to combine multiple assets by using '+', for instance 'faces+messages+artifacts'.\n");
1197  printf(" In this case the file will be in tar format.\n");
1198  printf(" -playerdir Set the player files directory.\n");
1199  printf(" -regions Set the region file.\n");
1200  printf(" -templatedir Set the template map directory.\n");
1201  printf(" -tmpdir Set the directory for temporary files (mostly maps.)\n");
1202  printf(" -uniquedir Set the unique items/maps directory.\n");
1203  printf(" -v Print version information.\n");
1204  exit(EXIT_SUCCESS);
1205 }
1206 
1211 static void init_beforeplay(void) {
1212  init_archetype_pointers(); /* Setup global pointers to archetypes */
1213  finish_races(); /* overwrite race designations using entries in lib/races file */
1215  init_gods(); /* init linked list of gods from archs*/
1216  init_readable(); /* inits useful arrays for readable texts */
1217 
1218  switch (settings.dumpvalues) {
1219  case 1:
1220  print_monsters();
1221  cleanup();
1222  break;
1223 
1224  case 2:
1225  dump_abilities();
1226  cleanup();
1227  break;
1228 
1229  case 3:
1230  dump_artifacts();
1231  cleanup();
1232  break;
1233 
1234  case 4:
1235  dump_spells();
1236  cleanup();
1237  break;
1238 
1239  case 5:
1240  cleanup();
1241  break;
1242 
1243  case 6:
1244  dump_races();
1245  cleanup();
1246  break;
1247 
1248  case 7:
1249  dump_alchemy();
1250  cleanup();
1251  break;
1252 
1253  case 8:
1254  dump_gods();
1255  cleanup();
1256  break;
1257 
1258  case 9:
1260  cleanup();
1261  break;
1262 
1263  case 10:
1265  cleanup();
1266  break;
1267  }
1268 }
1269 
1275 static void init_startup(void) {
1276 #ifdef SHUTDOWN_FILE
1277  char buf[MAX_BUF];
1278  FILE *fp;
1279 
1280  snprintf(buf, sizeof(buf), "%s/%s", settings.confdir, SHUTDOWN_FILE);
1281  if ((fp = fopen(buf, "r")) != NULL) {
1282  while (fgets(buf, MAX_BUF-1, fp) != NULL)
1283  printf("%s", buf);
1284  fclose(fp);
1285  exit(1);
1286  }
1287 #endif
1288 
1289  if (forbid_play()) { /* Maybe showing highscore should be allowed? */
1290  LOG(llevError, "CrossFire: Playing not allowed.\n");
1291  exit(-1);
1292  }
1293 }
1294 
1298 static void signal_shutdown(int signum_unused) {
1299  (void) signum_unused; /* avoid unused warning if enambled */
1300  shutdown_flag += 1;
1301 }
1302 
1315 static void rec_sighup(int i) {
1316  (void)i;
1317  /* Don't call LOG(). It calls non-reentrant functions. The other
1318  * signal handlers shouldn't really call LOG() either. */
1319  if (logfile != stderr) {
1320  reopen_logfile = 1;
1321  }
1322 }
1323 
1327 void init_signals(void) {
1328 #ifndef WIN32 /* init_signals() remove signals */
1329  struct sigaction sa;
1330 
1331  sa.sa_sigaction = NULL;
1332  sigemptyset(&sa.sa_mask);
1333  sa.sa_flags = 0;
1334  sa.sa_handler = rec_sighup;
1335  sigaction(SIGHUP, &sa, NULL);
1336  signal(SIGINT, signal_shutdown);
1337  signal(SIGPIPE, SIG_IGN);
1338 #endif /* win32 */
1339 }
Settings::casting_time
uint8_t casting_time
It takes awhile to cast a spell.
Definition: global.h:275
Settings::special_break_map
uint8_t special_break_map
If set, then submaps in random maps can break the walls.
Definition: global.h:328
Settings::meta_comment
char meta_comment[MAX_BUF]
Comment we send to the metaserver.
Definition: global.h:294
Command_Line_Options
One command line option definition.
Definition: init.cpp:369
module_information::name
const char * name
Module name, without space.
Definition: init.cpp:48
Settings::mapdir
const char * mapdir
Where the map files are.
Definition: global.h:256
global.h
Settings::meta_server
char meta_server[MAX_BUF]
Hostname/ip addr of the metaserver.
Definition: global.h:291
settings
struct Settings settings
Global settings.
Definition: init.cpp:139
Settings::simple_exp
uint8_t simple_exp
If true, use the simple experience system.
Definition: global.h:268
citylife_init
void citylife_init(Settings *settings, ServerSettings *serverSettings)
Definition: citylife.cpp:426
safe_strncpy
#define safe_strncpy
Definition: compat.h:27
options
static struct Command_Line_Options options[]
Actual valid command line options.
Definition: init.cpp:387
Settings::recycle_tmp_maps
uint8_t recycle_tmp_maps
Re-use tmp maps.
Definition: global.h:277
init
void init(int argc, char **argv)
This is the main server initialization function.
Definition: init.cpp:1094
llevError
@ llevError
Error, serious thing.
Definition: logger.h:11
init_beforeplay
static void init_beforeplay(void)
Called before the server starts listening to connections, processes various dump-related options.
Definition: init.cpp:1211
Settings::regions
const char * regions
Name of the regions file - libdir is prepended.
Definition: global.h:257
LOG
void LOG(LogLevel logLevel, const char *format,...)
Logs a message to stderr, or to file.
Definition: logger.cpp:58
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:319
Settings::log_timestamp_format
char * log_timestamp_format
Format for timestap, if log_timestamp is set.
Definition: global.h:322
Settings::armor_speed_linear
uint8_t armor_speed_linear
If 1, speed improvement is linear, else exponantiel.
Definition: global.h:312
module_information::close
void(* close)()
Cleanup function.
Definition: init.cpp:52
strdup_local
#define strdup_local
Definition: compat.h:29
materialtype_t::mod
int8_t mod[NROFATTACKS]
Modification to resistances.
Definition: material.h:37
Settings::resurrection
uint8_t resurrection
Ressurection possible w/ permadeth on.
Definition: global.h:271
serverSettings
ServerSettings serverSettings
Definition: init.cpp:42
service_handle
void service_handle()
Settings::set_title
uint8_t set_title
Players can set thier title.
Definition: global.h:270
dump_alchemy_costs
void dump_alchemy_costs(void)
Dumps to output all costs of recipes.
Definition: recipe.cpp:591
ServerSettings::disabled_plugins
std::vector< std::string > disabled_plugins
List of disabled plugins, 'All' means all.
Definition: server.h:16
Settings::ignore_plugin_compatibility
uint8_t ignore_plugin_compatibility
If set, don't check plugin version.
Definition: global.h:329
FALSE
#define FALSE
Definition: compat.h:14
Settings::not_permadeth
uint8_t not_permadeth
If true, death is non-permament.
Definition: global.h:267
Settings::permanent_exp_ratio
uint8_t permanent_exp_ratio
How much exp should be 'permenant' and unable to be lost.
Definition: global.h:263
Settings::crypt_mode
uint8_t crypt_mode
0 for legacy behavior, 1 for always Traditional
Definition: global.h:332
set_datadir
static void set_datadir(const char *path)
Command line option: set data path.
Definition: init.cpp:192
module_information::description
const char * description
Module long description.
Definition: init.cpp:49
Settings::dumpvalues
uint8_t dumpvalues
Set to dump various values/tables.
Definition: global.h:250
Settings::datadir
const char * datadir
Read only data files.
Definition: global.h:253
load_materials
static void load_materials(BufferReader *reader, const char *filename)
Loads the materials.
Definition: init.cpp:531
FULL_VERSION
#define FULL_VERSION
Definition: version.h:4
set_mapdir
static void set_mapdir(const char *path)
Command line option: set map path.
Definition: init.cpp:216
cleanup
void cleanup(void)
Clean up everything and exit.
Definition: server.cpp:1262
set_dumpmon7
static void set_dumpmon7(void)
Command line option: dump alchemy.
Definition: init.cpp:165
dump_faces
void dump_faces(void)
Dump all faces to stderr, for debugging purposes.
Definition: image.cpp:159
Settings::worldmaptilesy
uint32_t worldmaptilesy
Number of tiles high the worldmap is.
Definition: global.h:299
SHUTDOWN_FILE
#define SHUTDOWN_FILE
If you want to take the game down while installing new versions, or for other reasons,...
Definition: config.h:463
rec_sighup
static void rec_sighup(int i)
SIGHUP handler.
Definition: init.cpp:1315
Settings::min_name
uint8_t min_name
Minimum characters for an account or player name.
Definition: global.h:333
SRANDOM
#define SRANDOM(seed)
Definition: define.h:629
Settings::worldmapstartx
uint32_t worldmapstartx
Starting x tile for the worldmap.
Definition: global.h:296
list_modules
static void list_modules()
List all modules, then exit.
Definition: init.cpp:97
time
non standard information is not specified or uptime this means how long since the executable has been started A particular host may have been running a server for quite a long time
Definition: arch-handbook.txt:206
get_empty_mat
static materialtype_t * get_empty_mat(void)
Creates an empty materialtype_t structure.
Definition: init.cpp:511
set_dumpmont
static void set_dumpmont(const char *name)
Command line option: dump monster treasures.
Definition: init.cpp:183
init_ob_methods
void init_ob_methods(void)
Initializes the ob_method system.
Definition: ob_methods.cpp:35
set_dumpmon6
static void set_dumpmon6(void)
Command line option: dump races.
Definition: init.cpp:160
Settings::starting_stat_min
uint8_t starting_stat_min
Minimum value of a starting stat.
Definition: global.h:323
read_map_log
void read_map_log(void)
Reads temporary maps information from disk.
Definition: swap.cpp:71
Settings::roll_stat_points
uint8_t roll_stat_points
How many stat points legacy (rolled) chars start with.
Definition: global.h:326
Settings::pk_luck_penalty
int16_t pk_luck_penalty
Amount by which player luck is reduced if they PK.
Definition: global.h:262
FREE_AND_COPY_IF
#define FREE_AND_COPY_IF(sv, nv)
Definition: global.h:212
Settings::stat_file
char * stat_file
Definition: global.h:337
set_mondebug
static void set_mondebug(void)
Command line option: monster debug flag.
Definition: init.cpp:130
llevMonster
@ llevMonster
Many many details.
Definition: logger.h:14
server_dump_animations
static void server_dump_animations(void)
Dump all animations, then exit.
Definition: init.cpp:336
SEE_LAST_ERROR
@ SEE_LAST_ERROR
Definition: define.h:52
set_playerdir
static void set_playerdir(const char *path)
Command line option: set player path.
Definition: init.cpp:248
NROFATTACKS
#define NROFATTACKS
Definition: attack.h:15
motd
**Media tags please refer to the protocol file in doc Developers protocol Quick for your pleasure an example[/b][i] This is an old full of dirt and partially destroyed[hand] My dear as you two years i had to leave quickly Words have come to me of powerful magic scrolls discovered in an old temple by my uncle I have moved to study them I not forgot your knowledge in ancient languages I need your help for[print][b] Some parts of document are to damaged to be readable[/b][arcane] Arghis[color=Red] k h[color=dark slate blue] ark[color=#004000] fido[/color][hand] please come as fast as possible my friend[print][b] The bottom of letter seems deliberatly shredded What is but not limited book signs motd
Definition: media-tags.txt:31
dump_gods
void dump_gods(void)
Prints all gods to stderr.
Definition: holy.cpp:367
Settings::csport
uint16_t csport
Port for new client/server.
Definition: global.h:247
materials
std::vector< materialtype_t * > materials
Definition: init.cpp:128
Settings::ignore_assets_errors
int ignore_assets_errors
If set then go on running even if there are errors in assets.
Definition: global.h:334
load_races
void load_races(BufferReader *reader, const char *filename)
Reads the races file in the lib/ directory, then overwrites old 'race' entries.
Definition: races.cpp:47
buf
StringBuffer * buf
Definition: readable.cpp:1564
init_server
void init_server(void)
This sets up the listening socket.
Definition: init.cpp:283
version.h
service_register
void service_register()
set_dumpmon2
static void set_dumpmon2(void)
Command line option: dump abilities.
Definition: init.cpp:140
Command_Line_Options::num_args
uint8_t num_args
Number or args it takes.
Definition: init.cpp:371
Settings::meta_host
char meta_host[MAX_BUF]
Hostname of this host.
Definition: global.h:292
set_dumpmon4
static void set_dumpmon4(void)
Command line option: dump spells.
Definition: init.cpp:150
forbid_play
int forbid_play(void)
Checks if server should be started.
Definition: server.cpp:1369
name
Plugin animator file specs[Config] name
Definition: animfiles.txt:4
Settings::worldmaptilesx
uint32_t worldmaptilesx
Number of tiles wide the worldmap is.
Definition: global.h:298
dump_races
void dump_races(void)
Dumps all race information to stderr.
Definition: races.cpp:81
Settings::pk_max_experience
int64_t pk_max_experience
Maximum experience one can get for PKing.
Definition: global.h:316
Command_Line_Options::cmd_option
const char * cmd_option
How it is called on the command line.
Definition: init.cpp:370
server_dump_faces
static void server_dump_faces(void)
Dump all faces, then exit.
Definition: init.cpp:344
init_signals
void init_signals(void)
Setup our signal handlers.
Definition: init.cpp:1327
cfweather_init
void cfweather_init(Settings *settings, ServerSettings *servserSettings)
Weather module initialisation.
Definition: cfweather.cpp:4824
parse_args
static void parse_args(int argc, char *argv[], int pass)
Parse command line arguments.
Definition: init.cpp:459
Settings::spell_encumbrance
uint8_t spell_encumbrance
Encumbrance effects spells.
Definition: global.h:273
init_gods
void init_gods(void)
This takes a look at all of the archetypes to find the objects which correspond to the GODS (type GOD...
Definition: holy.cpp:59
materialtype_t::material
int material
What basic type(s) it is linked to.
Definition: material.h:35
dump_experience
void dump_experience(void)
Dump the experience table, then calls exit() - useful in terms of debugging to make sure the format o...
Definition: exp.cpp:251
is_valid_types_gen.line
line
Definition: is_valid_types_gen.py:34
Settings::meta_port
uint16_t meta_port
Port number to use for updates.
Definition: global.h:293
modules
static module_information modules[]
All built modules.
Definition: init.cpp:56
Settings::balanced_stat_loss
uint8_t balanced_stat_loss
If true, Death stat depletion based on level etc.
Definition: global.h:266
dump_stat_bonuses
void dump_stat_bonuses()
Definition: living.cpp:2651
Settings::debug
LogLevel debug
Default debugging level.
Definition: global.h:248
init_archetype_pointers
void init_archetype_pointers(void)
Initialize global archtype pointers:
Definition: treasure.cpp:62
Settings::pk_max_experience_percent
int pk_max_experience_percent
Percentage of experience of victim the killer gets.
Definition: global.h:317
add_refcount
sstring add_refcount(sstring str)
Like add_string(), but the string is already a shared string.
Definition: shstr.cpp:224
Settings::death_penalty_ratio
uint8_t death_penalty_ratio
Hhow much exp should be lost at death.
Definition: global.h:264
set_dumpmon3
static void set_dumpmon3(void)
Command line option: dump artifacts.
Definition: init.cpp:145
random_house_generator_init
void random_house_generator_init(Settings *settings, ServerSettings *serverSettings)
Module initialisation.
Definition: random_house_generator.cpp:211
assets_add_collector_hook
void assets_add_collector_hook(const char *name, collectorHook hook)
Definition: assets.cpp:556
cftimer_init
void cftimer_init(void)
Initialize timers.
Definition: timers.cpp:157
random_house_generator_close
void random_house_generator_close()
Close the module.
Definition: random_house_generator.cpp:221
free_races
void free_races(void)
Frees all race-related information.
Definition: races.cpp:93
Settings::set_friendly_fire
uint16_t set_friendly_fire
Percent of damage done by peaceful player vs player damage.
Definition: global.h:280
Settings::account_block_create
uint8_t account_block_create
Definition: global.h:330
Settings::motd
const char * motd
Name of the motd file.
Definition: global.h:283
Settings::logfilename
const char * logfilename
Logfile to use.
Definition: global.h:246
Settings::worldmapstarty
uint32_t worldmapstarty
Starting y tile for the worldmap.
Definition: global.h:297
cfcitybell_init
void cfcitybell_init(Settings *settings, ServerSettings *serverSettings)
Citybells module initialisation.
Definition: cfcitybell.cpp:153
add_string
sstring add_string(const char *str)
Share a string.
Definition: shstr.cpp:137
free_quest
void free_quest(void)
Free all quest status structures.
Definition: quest.cpp:893
init_readable
void init_readable(void)
Initialize linked lists utilized by message functions in tailor_readable_ob()
Definition: readable.cpp:904
set_enable_module
static void set_enable_module(const char *name)
Enable a module.
Definition: init.cpp:329
materialtype_t::name
const char * name
Name of the material.
Definition: material.h:33
set_dumpmon1
static void set_dumpmon1(void)
Command line option: dump monsters.
Definition: init.cpp:135
metaserver2_init
int metaserver2_init(void)
This initializes the metaserver2 logic - it reads the metaserver2 file, storing the values away.
Definition: metaserver.cpp:331
description
spell prayer lvl t sp speed range duration short description
Definition: spell-summary.txt:2
Settings::armor_weight_reduction
int armor_weight_reduction
Weight reduction per enchantment.
Definition: global.h:309
Settings::stat_loss_on_death
uint8_t stat_loss_on_death
If true, chars lose a random stat when they die.
Definition: global.h:261
signal_shutdown
static void signal_shutdown(int signum_unused)
Signal handler that begins a normal server shutdown.
Definition: init.cpp:1298
Settings::item_power_factor
float item_power_factor
See note in setings file.
Definition: global.h:306
MAX_NAME
#define MAX_NAME
Definition: define.h:41
set_logfile
static void set_logfile(char *val)
Command line option: set logfile name.
Definition: init.cpp:109
service_unregister
void service_unregister()
Settings::dumparg
const char * dumparg
Additional argument for some dump functions.
Definition: global.h:251
assets_finish_archetypes_for_play
void assets_finish_archetypes_for_play()
Definition: assets.cpp:513
dump_spells
void dump_spells(void)
Dumps all the spells - now also dumps skill associated with the spell.
Definition: spell_util.cpp:108
Settings::confdir
const char * confdir
Configuration files.
Definition: global.h:252
sproto.h
logfile
FILE * logfile
Used by server/daemon.c.
Definition: init.cpp:114
set_tmpdir
static void set_tmpdir(const char *path)
Command line option: set temporary file path.
Definition: init.cpp:256
dump_abilities
void dump_abilities(void)
Dump to standard out the abilities of all monsters.
Definition: info.cpp:52
set_uniquedir
static void set_uniquedir(const char *path)
Command line option: set unique path.
Definition: init.cpp:232
materialtype_t::save
int8_t save[NROFATTACKS]
Save chances for the attacks.
Definition: material.h:36
Settings::death_penalty_level
uint8_t death_penalty_level
How many levels worth of exp may be lost on one death.
Definition: global.h:265
modules.h
fatal
void fatal(enum fatal_error err)
fatal() is meant to be called whenever a fatal signal is intercepted.
Definition: utils.cpp:595
accounts_load
void accounts_load(void)
This loads all the account entries into memory.
Definition: account.cpp:161
set_dumpmon9
static void set_dumpmon9(void)
Command line option: dump alchemy costs.
Definition: init.cpp:175
MAX_BUF
#define MAX_BUF
Used for all kinds of things.
Definition: define.h:35
set_confdir
static void set_confdir(const char *path)
Command line option: set configuration path.
Definition: init.cpp:200
cmdlinefunc_args2
void(* cmdlinefunc_args2)(const char *arg1, const char *arg2)
Definition: init.cpp:361
set_dumpmon8
static void set_dumpmon8(void)
Command line option: dump gods.
Definition: init.cpp:170
Settings::playerdir
const char * playerdir
Where the player files are.
Definition: global.h:255
cfweather_close
void cfweather_close()
Definition: cfweather.cpp:4930
init_skills
void init_skills(void)
This just sets up the skill_names table above.
Definition: skill_util.cpp:97
Settings::spell_failure_effects
uint8_t spell_failure_effects
Nasty backlash to spell failures.
Definition: global.h:274
Settings::starting_stat_points
uint8_t starting_stat_points
How many stat points character starts with.
Definition: global.h:325
Settings
Server settings.
Definition: global.h:245
module_information::init
void(* init)(Settings *, ServerSettings *)
Initialisation function.
Definition: init.cpp:51
Settings::meta_on
unsigned int meta_on
True if we should send updates.
Definition: global.h:290
Settings::allow_denied_spells_writing
int allow_denied_spells_writing
If set, players can write spells they can't cast.
Definition: global.h:318
llevInfo
@ llevInfo
Information.
Definition: logger.h:12
hiscore_init
void hiscore_init(void)
Initializes the module.
Definition: hiscore.cpp:296
set_regions
static void set_regions(const char *path)
Command line option: set regions file name.
Definition: init.cpp:224
should_exit
static int should_exit
If set after command line argument parsing, then the server will exit.
Definition: init.cpp:45
init_library
void init_library(void)
It is vital that init_library() is called by any functions using this library.
Definition: init.cpp:313
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:282
commands_init
void commands_init(void)
Init standard commands.
Definition: commands.cpp:108
Settings::spellpoint_level_depend
uint8_t spellpoint_level_depend
Spell costs go up with level.
Definition: global.h:279
dump_quests
void dump_quests(void)
Dump all of the quests, then calls exit() - useful in terms of debugging to make sure that quests are...
Definition: quest.cpp:884
Settings::fastclock
uint8_t fastclock
If true, clock goes warp 9.
Definition: global.h:300
cmdlinefunc_args1
void(* cmdlinefunc_args1)(const char *arg1)
Definition: init.cpp:360
ServerSettings
Definition: server.h:15
free_materials
static void free_materials(void)
Frees all memory allocated to materials.
Definition: init.cpp:595
Settings::personalized_blessings
uint8_t personalized_blessings
If 1, blessed weapons get an owner and a willpower value.
Definition: global.h:315
print_monsters
void print_monsters(void)
As dump_abilities(), but with an alternative way of output.
Definition: info.cpp:87
unset_debug
static void unset_debug(void)
Command line option: unset debug flag.
Definition: init.cpp:125
dump_alchemy
void dump_alchemy(void)
Dumps alchemy recipes to output.
Definition: recipe.cpp:352
help
static void help(void)
Display the command line options and exits.
Definition: init.cpp:1151
Settings::max_stat
uint8_t max_stat
Maximum stat value - 255 should be sufficient.
Definition: global.h:327
cmdlinefunc_args0
void(* cmdlinefunc_args0)(void)
Typedefs used when calling option handlers.
Definition: init.cpp:359
materialtype_t::description
const char * description
Description, unused.
Definition: material.h:34
set_debug
static void set_debug(void)
Command line option: debug flag.
Definition: init.cpp:120
load_settings
void load_settings(void)
This loads the settings file.
Definition: init.cpp:607
close_modules
void close_modules()
Clean up all modules which are not disabled.
Definition: init.cpp:83
reset_sleep
void reset_sleep(void)
Initialise all variables used in the timing routines.
Definition: time.cpp:134
assets.h
Settings::armor_max_enchant
int armor_max_enchant
Maximum number of times an armor can be enchanted.
Definition: global.h:308
cfcitybell_close
void cfcitybell_close()
Definition: cfcitybell.cpp:165
set_ignore_assets_errors
static void set_ignore_assets_errors()
Command line option: ignore assets errors.
Definition: init.cpp:263
dump_monster_treasure
void dump_monster_treasure(const char *name)
For debugging purposes.
Definition: treasure.cpp:1284
dump_animations
void dump_animations(void)
Dump all animations to stderr, for debugging purposes.
Definition: anim.cpp:180
add_server_collect_hooks
void add_server_collect_hooks()
Definition: init.cpp:1082
Settings::armor_weight_linear
uint8_t armor_weight_linear
If 1, weight reduction is linear, else exponantiel.
Definition: global.h:310
set_dumpmon5
static void set_dumpmon5(void)
Command line option: ?
Definition: init.cpp:155
strcasecmp
int strcasecmp(const char *s1, const char *s2)
init_modules
void init_modules()
Init all modules which are not disabled.
Definition: init.cpp:67
call_version
static void call_version(void)
Command line option: show version.
Definition: init.cpp:114
set_csport
static void set_csport(const char *val)
Change the server's port.
Definition: init.cpp:280
loader.h
Settings::real_wiz
uint8_t real_wiz
Use mud-like wizards.
Definition: global.h:276
init_startup
static void init_startup(void)
Checks if starting the server is allowed.
Definition: init.cpp:1275
Settings::templatedir
const char * templatedir
Directory for the template map.
Definition: global.h:259
set_disable_plugin
static void set_disable_plugin(const char *name)
Disable a plugin.
Definition: init.cpp:293
set_localdir
static void set_localdir(const char *path)
Command line option: set local path.
Definition: init.cpp:208
reopen_logfile
int reopen_logfile
Definition: logger.cpp:27
assets_pack
void assets_pack(const char *what, const char *filename)
Pack the specified assets in a file.
Definition: assets.cpp:422
set_disable_module
static void set_disable_module(const char *name)
Disable a module.
Definition: init.cpp:321
free_server
void free_server(void)
Frees all memory allocated around here:
Definition: init.cpp:1141
citylife_close
void citylife_close()
Definition: citylife.cpp:437
finish_races
void finish_races()
Definition: races.cpp:98
materialtype_t
One material type.
Definition: material.h:32
Settings::no_player_stealing
uint8_t no_player_stealing
If 1, can not steal from other players.
Definition: global.h:313
Settings::account_trusted_host
char * account_trusted_host
Block account creation for untrusted hosts.
Definition: global.h:331
Settings::search_items
uint8_t search_items
Search_items command.
Definition: global.h:272
module_information
Definition: init.cpp:47
server.h
Settings::tmpdir
const char * tmpdir
Directory to use for temporary files.
Definition: global.h:260
dump_artifacts
void dump_artifacts(void)
For debugging purposes.
Definition: artifact.cpp:610
Settings::always_show_hp
uint8_t always_show_hp
'probe' spell HP bars for all living things (0, 1, or 2)
Definition: global.h:278
TRUE
#define TRUE
Definition: compat.h:11
set_templatedir
static void set_templatedir(const char *path)
Command line option: set template path.
Definition: init.cpp:240
Settings::create_home_portals
uint8_t create_home_portals
If 1, can create portals in unique maps (apartments)
Definition: global.h:314
server_dump_bonuses
static void server_dump_bonuses()
Dump all bonuses (from the stat_bonus file) then exit.
Definition: init.cpp:352
Command_Line_Options::pass
uint8_t pass
What pass this should be processed on.
Definition: init.cpp:372
OUT_OF_MEMORY
@ OUT_OF_MEMORY
Definition: define.h:48
BufferReader
Definition: bufferreader.cpp:21
Settings::armor_speed_improvement
int armor_speed_improvement
Speed improvement.
Definition: global.h:311
NUM_STATS
@ NUM_STATS
Number of statistics.
Definition: living.h:18
Settings::log_timestamp
int log_timestamp
If set, log will comport a timestamp.
Definition: global.h:321
Settings::who_format
char who_format[MAX_BUF]
The format that the who command should use.
Definition: global.h:281
server_pack_assets
static void server_pack_assets(const char *assets, const char *filename)
Definition: init.cpp:267
Command_Line_Options::func
void(* func)()
function to call when we match this.
Definition: init.cpp:373
shutdown_flag
volatile sig_atomic_t shutdown_flag
Definition: server.cpp:53
module_information::enabled
bool enabled
Whether the module is enabled or not.
Definition: init.cpp:50
llevDebug
@ llevDebug
Only for debugging purposes.
Definition: logger.h:13
do_module
static void do_module(const char *name, bool enabled)
Change the 'enabled' flag of a module.
Definition: init.cpp:303
Settings::starting_stat_max
uint8_t starting_stat_max
Maximum value of a starting stat.
Definition: global.h:324
Settings::uniquedir
const char * uniquedir
Directory for the unique items.
Definition: global.h:258
bufferreader_next_line
char * bufferreader_next_line(BufferReader *br)
Return the next line in the buffer, as separated by a newline.
Definition: bufferreader.cpp:102
Settings::localdir
const char * localdir
Read/write data files.
Definition: global.h:254