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  { NULL, NULL, false, NULL, NULL }
61 };
62 
66 void init_modules() {
67  LOG(llevInfo, "Initializing modules\n");
68  for (int module = 0; modules[module].name != NULL; module++) {
69  module_information *mod = &modules[module];
70  if (!mod->enabled) {
71  LOG(llevInfo, " %s (%s): disabled\n", mod->name, mod->description);
72  } else {
73  mod->init(&settings, &serverSettings);
74  LOG(llevInfo, " %s (%s): activated\n", mod->name, mod->description);
75  }
76  }
77 }
78 
82 void close_modules() {
83  LOG(llevInfo, "Cleaning modules\n");
84  for (int module = 0; modules[module].name != NULL; module++) {
85  module_information *mod = &modules[module];
86  if (mod->enabled) {
87  mod->close();
88  LOG(llevInfo, " %s (%s): closed\n", mod->name, mod->description);
89  }
90  }
91 }
92 
96 static void list_modules() {
97  LOG(llevInfo, "Built-in modules:\n");
98  for (int module = 0; modules[module].name != NULL; module++) {
99  LOG(llevInfo, " %s: %s -> %s\n", modules[module].name, modules[module].description, modules[module].enabled ? "enabled" : "disabled");
100  }
101  should_exit = 1;
102 }
103 
108 static void set_logfile(char *val) {
109  settings.logfilename = val;
110 }
111 
113 static void call_version(void) {
114  puts(FULL_VERSION);
115  exit(EXIT_SUCCESS);
116 }
117 
119 static void set_debug(void) {
121 }
122 
124 static void unset_debug(void) {
126 }
127 
129 static void set_mondebug(void) {
131 }
132 
134 static void set_dumpmon1(void) {
135  settings.dumpvalues = 1;
136 }
137 
139 static void set_dumpmon2(void) {
140  settings.dumpvalues = 2;
141 }
142 
144 static void set_dumpmon3(void) {
145  settings.dumpvalues = 3;
146 }
147 
149 static void set_dumpmon4(void) {
150  settings.dumpvalues = 4;
151 }
152 
154 static void set_dumpmon5(void) {
155  settings.dumpvalues = 5;
156 }
157 
159 static void set_dumpmon6(void) {
160  settings.dumpvalues = 6;
161 }
162 
164 static void set_dumpmon7(void) {
165  settings.dumpvalues = 7;
166 }
167 
169 static void set_dumpmon8(void) {
170  settings.dumpvalues = 8;
171 }
172 
174 static void set_dumpmon9(void) {
175  settings.dumpvalues = 9;
176 }
177 
182 static void set_dumpmont(const char *name) {
183  settings.dumpvalues = 10;
185 }
186 
191 static void set_datadir(const char *path) {
192  settings.datadir = path;
193 }
194 
199 static void set_confdir(const char *path) {
200  settings.confdir = path;
201 }
202 
207 static void set_localdir(const char *path) {
208  settings.localdir = path;
209 }
210 
215 static void set_mapdir(const char *path) {
216  settings.mapdir = path;
217 }
218 
223 static void set_regions(const char *path) {
224  settings.regions = path;
225 }
226 
231 static void set_uniquedir(const char *path) {
232  settings.uniquedir = path;
233 }
234 
239 static void set_templatedir(const char *path) {
240  settings.templatedir = path;
241 }
242 
247 static void set_playerdir(const char *path) {
248  settings.playerdir = path;
249 }
250 
255 static void set_tmpdir(const char *path) {
256  settings.tmpdir = path;
257 }
258 
264 }
265 
266 static void server_pack_assets(const char *assets, const char *filename) {
267  assets_pack(assets, filename);
268  should_exit = 1;
269 }
270 
271 static void free_materials(void);
272 
279 static void set_csport(const char *val) {
280  int port = atoi(val);
281  if (port <= 0 || port > 65535) {
282  LOG(llevError, "%d is an invalid csport number, must be between 1 and 65535.\n", port);
283  exit(1);
284  }
285  settings.csport = port;
286 }
287 
292 static void set_disable_plugin(const char *name) {
293  serverSettings.disabled_plugins.push_back(std::string(name ? name : ""));
294 }
295 
302 static void do_module(const char *name, bool enabled) {
303  bool one = false;
304  for (int module = 0; modules[module].name; module++) {
305  if (strcmp("All", name) == 0 || strcmp(modules[module].name, name) == 0) {
306  modules[module].enabled = enabled;
307  one = true;
308  }
309  }
310  if (!one) {
311  LOG(llevError, "Invalid module name %s\n", name);
313  }
314 }
315 
320 static void set_disable_module(const char *name) {
321  do_module(name, false);
322 }
323 
328 static void set_enable_module(const char *name) {
329  do_module(name, true);
330 }
331 
335 static void server_dump_animations(void) {
336  dump_animations();
337  cleanup();
338 }
339 
343 static void server_dump_faces(void) {
344  dump_faces();
345  cleanup();
346 }
347 
351 static void server_dump_bonuses() {
353  cleanup();
354 }
355 
358 typedef void (*cmdlinefunc_args0)(void);
359 typedef void (*cmdlinefunc_args1)(const char* arg1);
360 typedef void (*cmdlinefunc_args2)(const char* arg1, const char* arg2);
369  const char *cmd_option;
370  uint8_t num_args;
371  uint8_t pass;
372  void (*func)();
376 };
377 
386 static struct Command_Line_Options options[] = {
390  { "-conf", 1, 1, (cmdlinefunc_args0)set_confdir },
391  { "-d", 0, 1, (cmdlinefunc_args0)set_debug },
392  { "-data", 1, 1, (cmdlinefunc_args0)set_datadir },
393  { "-disable-plugin", 1, 1, (cmdlinefunc_args0)set_disable_plugin },
394  { "-disable-module", 1, 1, (cmdlinefunc_args0)set_disable_module },
395  { "-enable-module", 1, 1, (cmdlinefunc_args0)set_enable_module },
396  { "-list-modules", 0, 1, (cmdlinefunc_args0)list_modules },
397  { "-h", 0, 1, (cmdlinefunc_args0)help },
398  { "-ignore-assets-errors", 0, 1, (cmdlinefunc_args0)set_ignore_assets_errors },
399  { "-local", 1, 1, (cmdlinefunc_args0)set_localdir },
400  { "-log", 1, 1, (cmdlinefunc_args0)set_logfile },
401  { "-maps", 1, 1, (cmdlinefunc_args0)set_mapdir },
402  { "-mon", 0, 1, (cmdlinefunc_args0)set_mondebug },
403  { "-n", 0, 1, (cmdlinefunc_args0)unset_debug },
404  { "-playerdir", 1, 1, (cmdlinefunc_args0)set_playerdir },
405  { "-regions", 1, 1, (cmdlinefunc_args0)set_regions },
406  { "-templatedir", 1, 1, (cmdlinefunc_args0)set_templatedir },
407  { "-tmpdir", 1, 1, (cmdlinefunc_args0)set_tmpdir },
408  { "-uniquedir", 1, 1, (cmdlinefunc_args0)set_uniquedir },
409  { "-v", 0, 1, (cmdlinefunc_args0)call_version },
410 
411 #ifdef WIN32
412  /* Windows service stuff */
413  { "-regsrv", 0, 1, service_register },
414  { "-unregsrv", 0, 1, service_unregister },
415  { "-srv", 0, 1, service_handle },
416 #endif
417 
421  { "-p", 1, 2, (cmdlinefunc_args0)set_csport },
422 
426  { "-m", 0, 3, (cmdlinefunc_args0)set_dumpmon1 },
427  { "-m2", 0, 3, (cmdlinefunc_args0)set_dumpmon2 },
428  { "-m3", 0, 3, (cmdlinefunc_args0)set_dumpmon3 },
429  { "-m4", 0, 3, (cmdlinefunc_args0)set_dumpmon4 },
430  { "-m5", 0, 3, (cmdlinefunc_args0)set_dumpmon5 },
431  { "-m6", 0, 3, (cmdlinefunc_args0)set_dumpmon6 },
432  { "-m7", 0, 3, (cmdlinefunc_args0)set_dumpmon7 },
433  { "-m8", 0, 3, (cmdlinefunc_args0)set_dumpmon8 },
434  { "-m9", 0, 3, (cmdlinefunc_args0)set_dumpmon9 },
435  { "-mt", 1, 3, (cmdlinefunc_args0)set_dumpmont },
436  { "-mexp", 0, 3, (cmdlinefunc_args0)dump_experience },
437  { "-mq", 0, 3, (cmdlinefunc_args0)dump_quests },
438  { "-dump-anims", 0, 3, (cmdlinefunc_args0)server_dump_animations },
439  { "-dump-faces", 0, 3, (cmdlinefunc_args0)server_dump_faces },
440  { "-pack-assets", 2, 3, (cmdlinefunc_args0)server_pack_assets },
441  { "-dump-stat-bonuses", 0, 3, (cmdlinefunc_args0)server_dump_bonuses },
442 };
443 
458 static void parse_args(int argc, char *argv[], int pass) {
459  size_t i;
460  int on_arg = 1;
461 
462  while (on_arg < argc) {
463  for (i = 0; i < sizeof(options)/sizeof(struct Command_Line_Options); i++) {
464  if (!strcmp(options[i].cmd_option, argv[on_arg])) {
465  /* Found a matching option, but should not be processed on
466  * this pass. Just skip over it
467  */
468  if (options[i].pass != pass) {
469  on_arg += options[i].num_args+1;
470  break;
471  }
472  if (options[i].num_args) {
473  if ((on_arg+options[i].num_args) >= argc) {
474  fprintf(stderr, "%s requires an argument.\n", options[i].cmd_option);
475  exit(1);
476  }
477 
478  if (options[i].num_args == 1)
479  ((cmdlinefunc_args1)options[i].func)(argv[on_arg+1]);
480  if (options[i].num_args == 2)
481  ((cmdlinefunc_args2)options[i].func)(argv[on_arg+1], argv[on_arg+2]);
482  on_arg += options[i].num_args+1;
483  } else { /* takes no args */
485  on_arg++;
486  }
487  break;
488  }
489  }
490  if (i == sizeof(options)/sizeof(struct Command_Line_Options)) {
491  fprintf(stderr, "Unknown option: %s\n", argv[on_arg]);
492  fprintf(stderr, "Type '%s -h' for usage.\n", argv[0]);
493  exit(1);
494  }
495  }
496 
497  if (should_exit) {
498  cleanup();
499  }
500 }
501 
511  materialtype_t *mt;
512  int i;
513 
514  mt = (materialtype_t *)malloc(sizeof(materialtype_t));
515  if (mt == NULL)
517  mt->name = NULL;
518  mt->description = NULL;
519  for (i = 0; i < NROFATTACKS; i++) {
520  mt->save[i] = 0;
521  mt->mod[i] = 0;
522  }
523  return mt;
524 }
525 
530 static void load_materials(BufferReader *reader, const char *filename) {
531  char *buf, *cp, *next;
532  materialtype_t *mt = NULL;
533  int i, value;
534  (void)filename;
535  int line = 0;
536 
537  while ((buf = bufferreader_next_line(reader)) != NULL) {
538  line++;
539  if (*buf == '#')
540  continue;
541  cp = buf;
542  while (*cp == ' ') /* Skip blanks */
543  cp++;
544  if (!strncmp(cp, "name", 4)) {
545  mt = get_empty_mat();
546  materials.push_back(mt);
547  mt->name = add_string(strchr(cp, ' ')+1);
548  mt->description = add_refcount(mt->name);
549  }
550 
551  if (mt == NULL) {
552  LOG(llevError, "%s:%d: fields must come after a name line\n", filename, line);
554  }
555 
556  if (!strncmp(cp, "description", 11)) {
557  FREE_AND_COPY_IF(mt->description, strchr(cp, ' ')+1);
558  } else if (sscanf(cp, "material %d", &value)) {
559  mt->material = value;
560  } else if (!strncmp(cp, "saves", 5)) {
561  cp = strchr(cp, ' ')+1;
562  for (i = 0; i < NROFATTACKS; i++) {
563  if (cp == NULL) {
564  mt->save[i] = 0;
565  continue;
566  }
567  if ((next = strchr(cp, ',')) != NULL)
568  *(next++) = '\0';
569  sscanf(cp, "%d", &value);
570  mt->save[i] = (int8_t)value;
571  cp = next;
572  }
573  } else if (!strncmp(cp, "mods", 4)) {
574  cp = strchr(cp, ' ')+1;
575  for (i = 0; i < NROFATTACKS; i++) {
576  if (cp == NULL) {
577  mt->save[i] = 0;
578  continue;
579  }
580  if ((next = strchr(cp, ',')) != NULL)
581  *(next++) = '\0';
582  sscanf(cp, "%d", &value);
583  mt->mod[i] = (int8_t)value;
584  cp = next;
585  }
586  }
587  }
588  LOG(llevDebug, "loaded %d material type data\n", static_cast<int>(materials.size()));
589 }
590 
594 static void free_materials(void) {
595  for (auto material : materials) {
596  free(material);
597  }
598  materials.clear();
599 }
600 
606 static void load_settings(void) {
607  static char motd[MAX_BUF] = { 0 };
608  char buf[MAX_BUF], *cp, dummy[1];
609  int has_val;
610  FILE *fp;
611 
612  dummy[0] = '\0';
613  snprintf(buf, sizeof(buf), "%s/settings", settings.confdir);
614 
615  /* We don't require a settings file at current time, but down the road,
616  * there will probably be so many values that not having a settings file
617  * will not be a good thing.
618  */
619  if ((fp = fopen(buf, "r")) == NULL) {
620  LOG(llevError, "Warning: No settings file found\n");
621  return;
622  }
623  while (fgets(buf, MAX_BUF-1, fp) != NULL) {
624  if (buf[0] == '#')
625  continue;
626  /* eliminate newline */
627  if ((cp = strrchr(buf, '\n')) != NULL)
628  *cp = '\0';
629 
630  /* Skip over empty lines */
631  if (buf[0] == 0)
632  continue;
633 
634  /* Skip all the spaces and set them to nulls. If not space,
635  * set cp to "" to make strcpy's and the like easier down below.
636  */
637  if ((cp = strchr(buf, ' ')) != NULL) {
638  while (*cp == ' ')
639  *cp++ = 0;
640  has_val = 1;
641  } else {
642  cp = dummy;
643  has_val = 0;
644  }
645 
646  if (!strcasecmp(buf, "metaserver_notification")) {
647  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
649  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
651  } else {
652  LOG(llevError, "load_settings: Unknown value for metaserver_notification: %s\n", cp);
653  }
654  } else if (!strcasecmp(buf, "metaserver_server")) {
655  if (has_val)
657  else
658  LOG(llevError, "load_settings: metaserver_server must have a value.\n");
659  } else if (!strcasecmp(buf, "motd")) {
660  if (has_val) {
661  safe_strncpy(motd, cp, sizeof(motd));
662  settings.motd = motd;
663  } else
664  LOG(llevError, "load_settings: motd must have a value.\n");
665  } else if (!strcasecmp(buf, "metaserver_host")) {
666  if (has_val)
668  else
669  LOG(llevError, "load_settings: metaserver_host must have a value.\n");
670  } else if (!strcasecmp(buf, "port")) {
671  set_csport(cp);
672  } else if (!strcasecmp(buf, "metaserver_port")) {
673  int port = atoi(cp);
674 
675  if (port < 1 || port > 65535)
676  LOG(llevError, "load_settings: metaserver_port must be between 1 and 65535, %d is invalid\n", port);
677  else
678  settings.meta_port = port;
679  } else if (!strcasecmp(buf, "metaserver_comment")) {
681  } else if (!strcasecmp(buf, "worldmapstartx")) {
682  int size = atoi(cp);
683 
684  if (size < 0)
685  LOG(llevError, "load_settings: worldmapstartx must be at least 0, %d is invalid\n", size);
686  else
687  settings.worldmapstartx = size;
688  } else if (!strcasecmp(buf, "worldmapstarty")) {
689  int size = atoi(cp);
690 
691  if (size < 0)
692  LOG(llevError, "load_settings: worldmapstarty must be at least 0, %d is invalid\n", size);
693  else
694  settings.worldmapstarty = size;
695  } else if (!strcasecmp(buf, "worldmaptilesx")) {
696  int size = atoi(cp);
697 
698  if (size < 1)
699  LOG(llevError, "load_settings: worldmaptilesx must be greater than 1, %d is invalid\n", size);
700  else
701  settings.worldmaptilesx = size;
702  } else if (!strcasecmp(buf, "worldmaptilesy")) {
703  int size = atoi(cp);
704 
705  if (size < 1)
706  LOG(llevError, "load_settings: worldmaptilesy must be greater than 1, %d is invalid\n", size);
707  else
708  settings.worldmaptilesy = size;
709  } else if (!strcasecmp(buf, "worldmaptilesizex")) {
710  int size = atoi(cp);
711 
712  if (size < 1)
713  LOG(llevError, "load_settings: worldmaptilesizex must be greater than 1, %d is invalid\n", size);
714  else
716  } else if (!strcasecmp(buf, "worldmaptilesizey")) {
717  int size = atoi(cp);
718 
719  if (size < 1)
720  LOG(llevError, "load_settings: worldmaptilesizey must be greater than 1, %d is invalid\n", size);
721  else
723  } else if (!strcasecmp(buf, "fastclock")) {
724  int lev = atoi(cp);
725 
726  if (lev < 0)
727  LOG(llevError, "load_settings: fastclock must be at least 0, %d is invalid\n", lev);
728  else
729  settings.fastclock = lev;
730  } else if (!strcasecmp(buf, "not_permadeth")) {
731  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
733  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
735  } else {
736  LOG(llevError, "load_settings: Unknown value for not_permadeth: %s\n", cp);
737  }
738  } else if (!strcasecmp(buf, "resurrection")) {
739  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
741  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
743  } else {
744  LOG(llevError, "load_settings: Unknown value for resurrection: %s\n", cp);
745  }
746  } else if (!strcasecmp(buf, "set_title")) {
747  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
749  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
751  } else {
752  LOG(llevError, "load_settings: Unknown value for set_title: %s\n", cp);
753  }
754  } else if (!strcasecmp(buf, "search_items")) {
755  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
757  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
759  } else {
760  LOG(llevError, "load_settings: Unknown value for search_items: %s\n", cp);
761  }
762  } else if (!strcasecmp(buf, "spell_encumbrance")) {
763  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
765  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
767  } else {
768  LOG(llevError, "load_settings: Unknown value for spell_encumbrance: %s\n", cp);
769  }
770  } else if (!strcasecmp(buf, "spell_failure_effects")) {
771  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
773  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
775  } else {
776  LOG(llevError, "load_settings: Unknown value for spell_failure_effects: %s\n", cp);
777  }
778  } else if (!strcasecmp(buf, "casting_time")) {
779  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
781  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
783  } else {
784  LOG(llevError, "load_settings: Unknown value for casting_time: %s\n", cp);
785  }
786  } else if (!strcasecmp(buf, "real_wiz")) {
787  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
789  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
791  } else {
792  LOG(llevError, "load_settings: Unknown value for real_wiz: %s\n", cp);
793  }
794  } else if (!strcasecmp(buf, "recycle_tmp_maps")) {
795  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
797  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
799  } else {
800  LOG(llevError, "load_settings: Unknown value for recycle_tmp_maps: %s\n", cp);
801  }
802  } else if (!strcasecmp(buf, "always_show_hp")) {
803  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
805  } else if (!strcasecmp(cp, "damaged")) {
807  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
809  } else {
810  LOG(llevError, "load_settings: Unknown value for always_show_hp: %s\n", cp);
811  }
812  } else if (!strcasecmp(buf, "who_format")) {
813  if (has_val)
815  sizeof(settings.who_format));
816  } else if (!strcasecmp(buf, "who_wiz_format")) {
817  if (has_val) {
819  sizeof(settings.who_wiz_format));
820  }
821  } else if (!strcasecmp(buf, "spellpoint_level_depend")) {
822  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
824  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
826  } else {
827  LOG(llevError, "load_settings: Unknown value for spellpoint_level_depend: %s\n", cp);
828  }
829  } else if (!strcasecmp(buf, "stat_loss_on_death")) {
830  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
832  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
834  } else {
835  LOG(llevError, "load_settings: Unknown value for stat_loss_on_death: %s\n", cp);
836  }
837  } else if (!strcasecmp(buf, "use_permanent_experience")) {
838  LOG(llevError, "use_permanent_experience is deprecated, usepermenent_experience_percentage instead\n");
839  } else if (!strcasecmp(buf, "permanent_experience_percentage")) {
840  int val = atoi(cp);
841  if (val < 0 || val > 100)
842  LOG(llevError, "load_settings: permenent_experience_percentage must be between 0 and 100, %d is invalid\n", val);
843  else
845  } else if (!strcasecmp(buf, "death_penalty_percentage")) {
846  int val = atoi(cp);
847  if (val < 0 || val > 100)
848  LOG(llevError, "load_settings: death_penalty_percentage must be between 0 and 100, %d is invalid\n", val);
849  else
851  } else if (!strcasecmp(buf, "death_penalty_levels")) {
852  int val = atoi(cp);
853  if (val < 0 || val > 255)
854  LOG(llevError, "load_settings: death_penalty_levels can not be negative, %d is invalid\n", val);
855  else
857  } else if (!strcasecmp(buf, "balanced_stat_loss")) {
858  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
860  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
862  } else {
863  LOG(llevError, "load_settings: Unknown value for balanced_stat_loss: %s\n", cp);
864  }
865  } else if (!strcasecmp(buf, "simple_exp")) {
866  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
868  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
870  } else {
871  LOG(llevError, "load_settings: Unknown value for simple_exp: %s\n", cp);
872  }
873  } else if (!strcasecmp(buf, "item_power_factor")) {
874  float tmp = atof(cp);
875  if (tmp < 0)
876  LOG(llevError, "load_settings: item_power_factor must be a positive number (%f < 0)\n", tmp);
877  else
879  } else if (!strcasecmp(buf, "pk_luck_penalty")) {
880  int16_t val = atoi(cp);
881 
882  if (val < -100 || val > 100)
883  LOG(llevError, "load_settings: pk_luck_penalty must be between -100 and 100, %d is invalid\n", val);
884  else
886  } else if (!strcasecmp(buf, "set_friendly_fire")) {
887  int val = atoi(cp);
888 
889  if (val < 1 || val > 100)
890  LOG(llevError, "load_settings: set_friendly_fire must be between 1 an 100, %d is invalid\n", val);
891  else
893  } else if (!strcasecmp(buf, "armor_max_enchant")) {
894  int max_e = atoi(cp);
895  if (max_e <= 0)
896  LOG(llevError, "load_settings: armor_max_enchant is %d\n", max_e);
897  else
898  settings.armor_max_enchant = max_e;
899  } else if (!strcasecmp(buf, "armor_weight_reduction")) {
900  int wr = atoi(cp);
901  if (wr < 0)
902  LOG(llevError, "load_settings: armor_weight_reduction is %d\n", wr);
903  else
905  } else if (!strcasecmp(buf, "armor_weight_linear")) {
906  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
908  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
910  } else {
911  LOG(llevError, "load_settings: unknown value for armor_weight_linear: %s\n", cp);
912  }
913  } else if (!strcasecmp(buf, "armor_speed_improvement")) {
914  int wr = atoi(cp);
915  if (wr < 0)
916  LOG(llevError, "load_settings: armor_speed_improvement is %d\n", wr);
917  else
919  } else if (!strcasecmp(buf, "armor_speed_linear")) {
920  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
922  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
924  } else {
925  LOG(llevError, "load_settings: unknown value for armor_speed_linear: %s\n", cp);
926  }
927  } else if (!strcasecmp(buf, "no_player_stealing")) {
928  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
930  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
932  } else {
933  LOG(llevError, "load_settings: unknown value for no_player_stealing: %s\n", cp);
934  }
935  } else if (!strcasecmp(buf, "create_home_portals")) {
936  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
937 #ifdef TRY_BROKEN_TOWN_PORTALS
939 #else
940  LOG(llevError, "load_settings: create_home_portals is currently broken. It results in town portals that prematurely reset when the apartment is swapped.\n");
941 #endif
942  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
944  } else {
945  LOG(llevError, "load_settings: unknown value for create_home_portals: %s\n", cp);
946  }
947  } else if (!strcasecmp(buf, "personalized_blessings")) {
948  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
950  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
952  } else {
953  LOG(llevError, "load_settings: unknown value for personalized_blessings: %s\n", cp);
954  }
955  } else if (!strcasecmp(buf, "pk_max_experience")) {
956  int64_t pkme = atoll(cp);
957  if (pkme < 0)
958  pkme = -1;
960  } else if (!strcasecmp(buf, "pk_max_experience_percent")) {
961  int pkmep = atoi(cp);
962  if (pkmep < 0) {
963  LOG(llevError, "load_settings: pk_max_experience_percent should be positive or zero (was \"%s\")\n", cp);
964  } else
966  } else if (!strcasecmp(buf, "allow_denied_spells_writing")) {
967  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
969  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
971  } else {
972  LOG(llevError, "load_settings: unknown value for allow_denied_spells_writing: %s\n", cp);
973  }
974  } else if (!strcasecmp(buf, "allow_broken_converters")) {
975  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
977  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
979  } else {
980  LOG(llevError, "load_settings: unknown value for allow_broken_converters: %s\n", cp);
981  }
982  } else if (!strcasecmp(buf, "log_timestamp")) {
983  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
985  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
987  } else {
988  LOG(llevError, "load_settings: unknown value for log_timestamp: %s\n", cp);
989  }
990  } else if (!strcasecmp(buf, "log_timestamp_format")) {
993  } else if (!strcasecmp(buf, "starting_stat_min")) {
994  int val = atoi(cp);
995 
996  if (val < 1 || val > settings.max_stat || val > settings.starting_stat_max)
997  LOG(llevError, "load_settings: starting_stat_min (%d) need to be within %d-%d (%d)\n",
999  else
1001  } else if (!strcasecmp(buf, "starting_stat_max")) {
1002  int val = atoi(cp);
1003 
1004  if (val < 1 || val > settings.max_stat || val<settings.starting_stat_min)
1005  LOG(llevError, "load_settings: starting_stat_max (%d) need to be within %d-%d (%d)\n",
1007  else
1009  } else if (!strcasecmp(buf, "starting_stat_points")) {
1010  int val = atoi(cp);
1011 
1012  if (val < NUM_STATS * settings.starting_stat_min ||
1014  LOG(llevError, "load_settings: starting_stat_points (%d) need to be within %d-%d\n",
1016  else
1018  } else if (!strcasecmp(buf, "roll_stat_points")) {
1019  int val = atoi(cp);
1020 
1021  /* The 3 and 18 values are hard coded in because we know that
1022  * roll_stat() generates a value between 3 and 18 - if that ever
1023  * changed, this code should change also, but that code will eventually
1024  * go away.
1025  */
1026  if (val < NUM_STATS * 3 || val > NUM_STATS * 18)
1027  LOG(llevError, "load_settings: roll_stat_points need to be within %d-%d\n",
1028  NUM_STATS * 3, NUM_STATS * 18);
1029  else
1030  settings.roll_stat_points = val;
1031  } else if (!strcasecmp(buf, "special_break_map")) {
1032  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
1034  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
1036  } else {
1037  LOG(llevError, "load_settings: unknown value for special_break_map: %s\n", cp);
1038  }
1039  } else if (!strcasecmp(buf, "ignore_plugin_compatibility")) {
1040  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
1042  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
1044  } else {
1045  LOG(llevError, "load_settings: unknown value for ignore_plugin_compatibility: %s\n", cp);
1046  }
1047  } else if (!strcasecmp(buf, "account_block_create")) {
1048  if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
1050  } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
1052  } else {
1053  LOG(llevError, "load_settings: unknown value for account_block_create: %s\n", cp);
1054  }
1055  } else if (!strcasecmp(buf, "account_trusted_host")) {
1058  } else if (!strcasecmp(buf, "crypt_mode")) {
1059  int val = atoi(cp);
1060  if (val != 0 && val != 1) {
1061  LOG(llevError, "load_settings: crypt_mode must be 0 or 1\n");
1062  } else {
1063  settings.crypt_mode = val;
1064  }
1065  } else if (!strcasecmp(buf, "min_name")) {
1066  int val = atoi(cp);
1067 
1068  if (val < 1 || val > MAX_NAME )
1069  LOG(llevError, "load_settings: min_name (%d) need to be within %d-%d\n",
1070  val, 1, MAX_NAME);
1071  else
1072  settings.min_name = val;
1073  } else if (!strcasecmp(buf, "stat_file")) {
1075  } else {
1076  LOG(llevError, "Unknown value in settings file: %s\n", buf);
1077  }
1078  }
1079  fclose(fp);
1080  if (settings.log_timestamp_format == NULL)
1081  settings.log_timestamp_format = strdup_local("%y/%m/%d %H:%M:%S");
1082 
1083  /*
1084  * The who formats are defined in config to be blank. They should have been
1085  * overridden by the settings file, if there are no entries however, it will
1086  * have stayed blank. Since this probably isn't what is wanted, we will check if
1087  * new formats have been specified, and if not we will use the old defaults.
1088  */
1089  if (!strcmp(settings.who_format, ""))
1090  strcpy(settings.who_format, "%N_%t%h%d%b%n<%M>");
1091  if (!strcmp(settings.who_wiz_format, ""))
1092  strcpy(settings.who_wiz_format, "%N_%t%h%d%b%nLevel %l <%M>(@%i)(%c)");
1093 }
1094 
1098 }
1099 
1107 void init(int argc, char **argv) {
1108  logfile = stderr;
1109 
1110  /* First argument pass - right now it does nothing, but in the future specifying
1111  * the LibDir in this pass would be reasonable. */
1112  parse_args(argc, argv, 1);
1113 
1115  init_modules();
1116 
1117  init_library(); /* Must be called early */
1118  load_settings(); /* Load the settings file */
1119  parse_args(argc, argv, 2);
1120 
1121  LOG(llevInfo, "Crossfire %s\n", FULL_VERSION);
1122  SRANDOM(time(NULL));
1123 
1124  init_startup(); /* Check shutdown/forbid files */
1125  init_signals(); /* Sets up signal interceptions */
1126  commands_init(); /* Sort command tables */
1127  read_map_log(); /* Load up the old temp map files */
1128  init_skills();
1129  init_ob_methods();
1130  cftimer_init();
1131  hiscore_init();
1132 
1133  parse_args(argc, argv, 3);
1134 
1135  init_beforeplay();
1136  if (argc != 0) {
1137  // Invocations from the command-line (e.g. crossfire-server) have the
1138  // binary name in argv[0]. If that is not there, assume we are running
1139  // as a test and don't create sockets.
1140  init_server();
1141  } else {
1142  LOG(llevInfo, "Running server in test mode (no sockets).\n");
1143  }
1144  metaserver2_init();
1145  accounts_load();
1146  reset_sleep();
1147 }
1148 
1154 void free_server(void) {
1155  free_materials();
1156  free_races();
1157  free_quest();
1159 }
1160 
1164 static void help(void) {
1165  printf("Usage: crossfire-server [options]\n\n");
1166 
1167  printf("Options:\n");
1168  printf(" -conf Set the directory to find configuration files.\n");
1169  printf(" -d Turn on extra debugging messages.\n");
1170  printf(" -data Set the data (share/) directory (archetypes, treasures, etc).\n");
1171  printf(" -disable-module\n"
1172  " Disable specified module, by its name\n"
1173  " Can be specified multiple times. 'All' disables all modules.\n");
1174  printf(" -enable-module\n"
1175  " Enable specified module, by its name\n"
1176  " Can be specified multiple times. 'All' enables all modules.\n");
1177  printf(" -disable-plugin\n"
1178  " Disables specified plugin. Use the name without the extension.\n"
1179  " Can be specified multiple times. 'All' disables all plugins.\n");
1180  printf(" -dump-anims Dump animations.\n");
1181  printf(" -h Print this help message.\n");
1182  printf(" -ignore-assets-errors\n");
1183  printf(" Allow going on even if there are errors in assets.\n");
1184  printf(" Warning: this may lead to strange behaviour.\n");
1185  printf(" -list-modules\n"
1186  " List built-in modules and exit.\n");
1187  printf(" -local Set the local data (var/) directory.\n");
1188  printf(" -log <file> Write logging information to the given file.\n");
1189  printf(" -m List suggested experience for all monsters.\n");
1190  printf(" -m2 Dump monster abilities.\n");
1191  printf(" -m3 Dump artifact information.\n");
1192  printf(" -m4 Dump spell information.\n");
1193  printf(" -m5 Dump skill information.\n");
1194  printf(" -m6 Dump race information.\n");
1195  printf(" -m7 Dump alchemy information.\n");
1196  printf(" -m8 Dump gods information.\n");
1197  printf(" -m9 Dump more alchemy information (formula checking).\n");
1198  printf(" -maps Set the map directory.\n");
1199  printf(" -mexp Dump the experience table.\n");
1200  printf(" -mon Turn on monster debugging.\n");
1201  printf(" -mq Dump the quest list.\n");
1202  printf(" -mt <name> Dump a list of treasures for a monster.\n");
1203  printf(" -n Turn off debugging messages if on by default.\n");
1204  printf(" -p <port> Specifies the port to listen on for incoming connections.\n");
1205  printf(" -pack-assets <type> <filename>\n");
1206  printf(" Packs specified assets type to the specified filename.\n");
1207  printf(" Valid assets type are: archs, treasures, faces, messages, facesets, artifacts, formulae, images, quests.\n");
1208  printf(" The file format will be tar ('images') or text (everything else).\n");
1209  printf(" It is possible to combine multiple assets by using '+', for instance 'faces+messages+artifacts'.\n");
1210  printf(" In this case the file will be in tar format.\n");
1211  printf(" -playerdir Set the player files directory.\n");
1212  printf(" -regions Set the region file.\n");
1213  printf(" -templatedir Set the template map directory.\n");
1214  printf(" -tmpdir Set the directory for temporary files (mostly maps.)\n");
1215  printf(" -uniquedir Set the unique items/maps directory.\n");
1216  printf(" -v Print version information.\n");
1217  exit(EXIT_SUCCESS);
1218 }
1219 
1224 static void init_beforeplay(void) {
1225  init_archetype_pointers(); /* Setup global pointers to archetypes */
1226  finish_races(); /* overwrite race designations using entries in lib/races file */
1228  init_gods(); /* init linked list of gods from archs*/
1229  init_readable(); /* inits useful arrays for readable texts */
1230 
1231  switch (settings.dumpvalues) {
1232  case 1:
1233  print_monsters();
1234  cleanup();
1235  break;
1236 
1237  case 2:
1238  dump_abilities();
1239  cleanup();
1240  break;
1241 
1242  case 3:
1243  dump_artifacts();
1244  cleanup();
1245  break;
1246 
1247  case 4:
1248  dump_spells();
1249  cleanup();
1250  break;
1251 
1252  case 5:
1253  cleanup();
1254  break;
1255 
1256  case 6:
1257  dump_races();
1258  cleanup();
1259  break;
1260 
1261  case 7:
1262  dump_alchemy();
1263  cleanup();
1264  break;
1265 
1266  case 8:
1267  dump_gods();
1268  cleanup();
1269  break;
1270 
1271  case 9:
1273  cleanup();
1274  break;
1275 
1276  case 10:
1278  cleanup();
1279  break;
1280  }
1281 }
1282 
1288 static void init_startup(void) {
1289 #ifdef SHUTDOWN_FILE
1290  char buf[MAX_BUF];
1291  FILE *fp;
1292 
1293  snprintf(buf, sizeof(buf), "%s/%s", settings.confdir, SHUTDOWN_FILE);
1294  if ((fp = fopen(buf, "r")) != NULL) {
1295  while (fgets(buf, MAX_BUF-1, fp) != NULL)
1296  printf("%s", buf);
1297  fclose(fp);
1298  exit(1);
1299  }
1300 #endif
1301 
1302  if (forbid_play()) { /* Maybe showing highscore should be allowed? */
1303  LOG(llevError, "CrossFire: Playing not allowed.\n");
1304  exit(-1);
1305  }
1306 }
1307 
1311 static void signal_shutdown(int signum_unused) {
1312  (void) signum_unused; /* avoid unused warning if enambled */
1313  shutdown_flag += 1;
1314 }
1315 
1328 static void rec_sighup(int i) {
1329  (void)i;
1330  /* Don't call LOG(). It calls non-reentrant functions. The other
1331  * signal handlers shouldn't really call LOG() either. */
1332  if (logfile != stderr) {
1333  reopen_logfile = 1;
1334  }
1335 }
1336 
1340 void init_signals(void) {
1341 #ifndef WIN32 /* init_signals() remove signals */
1342  struct sigaction sa;
1343 
1344  sa.sa_sigaction = NULL;
1345  sigemptyset(&sa.sa_mask);
1346  sa.sa_flags = 0;
1347  sa.sa_handler = rec_sighup;
1348  sigaction(SIGHUP, &sa, NULL);
1349  signal(SIGINT, signal_shutdown);
1350  signal(SIGPIPE, SIG_IGN);
1351 #endif /* win32 */
1352 }
Settings::casting_time
uint8_t casting_time
It takes awhile to cast a spell.
Definition: global.h:271
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
Command_Line_Options
One command line option definition.
Definition: init.cpp:368
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:252
global.h
Settings::meta_server
char meta_server[MAX_BUF]
Hostname/ip addr of the metaserver.
Definition: global.h:287
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:264
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:386
Settings::recycle_tmp_maps
uint8_t recycle_tmp_maps
Re-use tmp maps.
Definition: global.h:273
init
void init(int argc, char **argv)
This is the main server initialization function.
Definition: init.cpp:1107
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:1224
Settings::regions
const char * regions
Name of the regions file - libdir is prepended.
Definition: global.h:253
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:317
Settings::log_timestamp_format
char * log_timestamp_format
Format for timestap, if log_timestamp is set.
Definition: global.h:320
Settings::armor_speed_linear
uint8_t armor_speed_linear
If 1, speed improvement is linear, else exponantiel.
Definition: global.h:310
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:267
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:266
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:327
FALSE
#define FALSE
Definition: compat.h:14
Settings::not_permadeth
uint8_t not_permadeth
If true, death is non-permament.
Definition: global.h:263
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
set_datadir
static void set_datadir(const char *path)
Command line option: set data path.
Definition: init.cpp:191
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:246
Settings::datadir
const char * datadir
Read only data files.
Definition: global.h:249
load_materials
static void load_materials(BufferReader *reader, const char *filename)
Loads the materials.
Definition: init.cpp:530
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:215
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:164
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:295
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:1328
Settings::min_name
uint8_t min_name
Minimum characters for an account or player name.
Definition: global.h:331
SRANDOM
#define SRANDOM(seed)
Definition: define.h:629
Settings::worldmapstartx
uint32_t worldmapstartx
Starting x tile for the worldmap.
Definition: global.h:292
list_modules
static void list_modules()
List all modules, then exit.
Definition: init.cpp:96
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:510
set_dumpmont
static void set_dumpmont(const char *name)
Command line option: dump monster treasures.
Definition: init.cpp:182
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:159
Settings::starting_stat_min
uint8_t starting_stat_min
Minimum value of a starting stat.
Definition: global.h:321
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:324
Settings::pk_luck_penalty
int16_t pk_luck_penalty
Amount by which player luck is reduced if they PK.
Definition: global.h:258
FREE_AND_COPY_IF
#define FREE_AND_COPY_IF(sv, nv)
Definition: global.h:208
Settings::stat_file
char * stat_file
Definition: global.h:335
set_mondebug
static void set_mondebug(void)
Command line option: monster debug flag.
Definition: init.cpp:129
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:335
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:247
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:243
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:332
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:1565
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:139
Command_Line_Options::num_args
uint8_t num_args
Number or args it takes.
Definition: init.cpp:370
Settings::meta_host
char meta_host[MAX_BUF]
Hostname of this host.
Definition: global.h:288
set_dumpmon4
static void set_dumpmon4(void)
Command line option: dump spells.
Definition: init.cpp:149
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:294
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:314
Command_Line_Options::cmd_option
const char * cmd_option
How it is called on the command line.
Definition: init.cpp:369
server_dump_faces
static void server_dump_faces(void)
Dump all faces, then exit.
Definition: init.cpp:343
init_signals
void init_signals(void)
Setup our signal handlers.
Definition: init.cpp:1340
parse_args
static void parse_args(int argc, char *argv[], int pass)
Parse command line arguments.
Definition: init.cpp:458
Settings::spell_encumbrance
uint8_t spell_encumbrance
Encumbrance effects spells.
Definition: global.h:269
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:289
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:262
dump_stat_bonuses
void dump_stat_bonuses()
Definition: living.cpp:2651
Settings::debug
LogLevel debug
Default debugging level.
Definition: global.h:244
load_settings
static void load_settings(void)
This loads the settings file.
Definition: init.cpp:606
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:315
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:260
set_dumpmon3
static void set_dumpmon3(void)
Command line option: dump artifacts.
Definition: init.cpp:144
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: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
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:328
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:134
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:307
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
signal_shutdown
static void signal_shutdown(int signum_unused)
Signal handler that begins a normal server shutdown.
Definition: init.cpp:1311
Settings::item_power_factor
float item_power_factor
See note in setings file.
Definition: global.h:304
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:108
service_unregister
void service_unregister()
Settings::dumparg
const char * dumparg
Additional argument for some dump functions.
Definition: global.h:247
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:248
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:255
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:231
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:261
modules.h
fatal
void fatal(enum fatal_error err)
fatal() is meant to be called whenever a fatal signal is intercepted.
Definition: utils.cpp:590
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:174
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:199
cmdlinefunc_args2
void(* cmdlinefunc_args2)(const char *arg1, const char *arg2)
Definition: init.cpp:360
set_dumpmon8
static void set_dumpmon8(void)
Command line option: dump gods.
Definition: init.cpp:169
Settings::playerdir
const char * playerdir
Where the player files are.
Definition: global.h:251
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:270
Settings::starting_stat_points
uint8_t starting_stat_points
How many stat points character starts with.
Definition: global.h:323
Settings
Server settings.
Definition: global.h:241
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: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
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:223
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:315
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
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:275
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:298
cmdlinefunc_args1
void(* cmdlinefunc_args1)(const char *arg1)
Definition: init.cpp:359
ServerSettings
Definition: server.h:15
free_materials
static void free_materials(void)
Frees all memory allocated to materials.
Definition: init.cpp:594
Settings::personalized_blessings
uint8_t personalized_blessings
If 1, blessed weapons get an owner and a willpower value.
Definition: global.h:313
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:124
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:1164
Settings::max_stat
uint8_t max_stat
Maximum stat value - 255 should be sufficient.
Definition: global.h:325
cmdlinefunc_args0
void(* cmdlinefunc_args0)(void)
Typedefs used when calling option handlers.
Definition: init.cpp:358
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:119
close_modules
void close_modules()
Clean up all modules which are not disabled.
Definition: init.cpp:82
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:306
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:262
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:1095
Settings::armor_weight_linear
uint8_t armor_weight_linear
If 1, weight reduction is linear, else exponantiel.
Definition: global.h:308
set_dumpmon5
static void set_dumpmon5(void)
Command line option: ?
Definition: init.cpp:154
strcasecmp
int strcasecmp(const char *s1, const char *s2)
Settings::worldmaptilesizex
uint32_t worldmaptilesizex
Number of squares wide in a wm tile.
Definition: global.h:296
init_modules
void init_modules()
Init all modules which are not disabled.
Definition: init.cpp:66
call_version
static void call_version(void)
Command line option: show version.
Definition: init.cpp:113
set_csport
static void set_csport(const char *val)
Change the server's port.
Definition: init.cpp:279
loader.h
Settings::real_wiz
uint8_t real_wiz
Use mud-like wizards.
Definition: global.h:272
init_startup
static void init_startup(void)
Checks if starting the server is allowed.
Definition: init.cpp:1288
Settings::templatedir
const char * templatedir
Directory for the template map.
Definition: global.h:255
set_disable_plugin
static void set_disable_plugin(const char *name)
Disable a plugin.
Definition: init.cpp:292
Settings::worldmaptilesizey
uint32_t worldmaptilesizey
Number of squares high in a wm tile.
Definition: global.h:297
set_localdir
static void set_localdir(const char *path)
Command line option: set local path.
Definition: init.cpp:207
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:320
free_server
void free_server(void)
Frees all memory allocated around here:
Definition: init.cpp:1154
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: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
module_information
Definition: init.cpp:47
server.h
Settings::tmpdir
const char * tmpdir
Directory to use for temporary files.
Definition: global.h:256
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:274
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:239
Settings::create_home_portals
uint8_t create_home_portals
If 1, can create portals in unique maps (apartments)
Definition: global.h:312
server_dump_bonuses
static void server_dump_bonuses()
Dump all bonuses (from the stat_bonus file) then exit.
Definition: init.cpp:351
Command_Line_Options::pass
uint8_t pass
What pass this should be processed on.
Definition: init.cpp:371
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:309
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:319
Settings::who_format
char who_format[MAX_BUF]
The format that the who command should use.
Definition: global.h:277
server_pack_assets
static void server_pack_assets(const char *assets, const char *filename)
Definition: init.cpp:266
Command_Line_Options::func
void(* func)()
function to call when we match this.
Definition: init.cpp:372
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:302
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
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:250