| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include "global.h" |
| 20 |
|
| 21 |
#include <errno.h> |
| 22 |
#include <signal.h> |
| 23 |
#include <stdlib.h> |
| 24 |
#include <string.h> |
| 25 |
|
| 26 |
|
| 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 |
|
| 36 |
static void help(void); |
| 37 |
static void init_beforeplay(void); |
| 38 |
static void init_startup(void); |
| 39 |
static void init_signals(void); |
| 40 |
static void init_races(void); |
| 41 |
static void dump_races(void); |
| 42 |
static void add_to_racelist(const char *race_name, object *op); |
| 43 |
static racelink *get_racelist(void); |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
static void set_logfile(char *val) { |
| 50 |
settings.logfilename = val; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
static void call_version(void) { |
| 55 |
puts(FULL_VERSION); |
| 56 |
exit(EXIT_SUCCESS); |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
static void set_debug(void) { |
| 61 |
settings.debug = llevDebug; |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
static void unset_debug(void) { |
| 66 |
settings.debug = llevInfo; |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
static void set_mondebug(void) { |
| 71 |
settings.debug = llevMonster; |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
static void set_dumpmon1(void) { |
| 76 |
settings.dumpvalues = 1; |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
static void set_dumpmon2(void) { |
| 81 |
settings.dumpvalues = 2; |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
static void set_dumpmon3(void) { |
| 86 |
settings.dumpvalues = 3; |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
static void set_dumpmon4(void) { |
| 91 |
settings.dumpvalues = 4; |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
static void set_dumpmon5(void) { |
| 96 |
settings.dumpvalues = 5; |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
static void set_dumpmon6(void) { |
| 101 |
settings.dumpvalues = 6; |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
static void set_dumpmon7(void) { |
| 106 |
settings.dumpvalues = 7; |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
static void set_dumpmon8(void) { |
| 111 |
settings.dumpvalues = 8; |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
static void set_dumpmon9(void) { |
| 116 |
settings.dumpvalues = 9; |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
static void set_dumpmont(const char *name) { |
| 124 |
settings.dumpvalues = 10; |
| 125 |
settings.dumparg = name; |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
static void set_datadir(const char *path) { |
| 133 |
settings.datadir = path; |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
static void set_confdir(const char *path) { |
| 141 |
settings.confdir = path; |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
static void set_localdir(const char *path) { |
| 149 |
settings.localdir = path; |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
static void set_mapdir(const char *path) { |
| 157 |
settings.mapdir = path; |
| 158 |
} |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
static void set_archetypes(const char *path) { |
| 165 |
settings.archetypes = path; |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
static void set_regions(const char *path) { |
| 173 |
settings.regions = path; |
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
static void set_treasures(const char *path) { |
| 181 |
settings.treasures = path; |
| 182 |
} |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
static void set_uniquedir(const char *path) { |
| 189 |
settings.uniquedir = path; |
| 190 |
} |
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
static void set_templatedir(const char *path) { |
| 197 |
settings.templatedir = path; |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
static void set_playerdir(const char *path) { |
| 205 |
settings.playerdir = path; |
| 206 |
} |
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
static void set_tmpdir(const char *path) { |
| 213 |
settings.tmpdir = path; |
| 214 |
} |
| 215 |
|
| 216 |
static void free_races(void); |
| 217 |
|
| 218 |
static void free_materials(void); |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
static void set_csport(const char *val) { |
| 227 |
int port = atoi(val); |
| 228 |
if (port <= 0 || port > 65535) { |
| 229 |
LOG(llevError, "%d is an invalid csport number, must be between 1 and 65535.\n", port); |
| 230 |
exit(1); |
| 231 |
} |
| 232 |
settings.csport = port; |
| 233 |
} |
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
static void set_disable_plugin(const char *name) { |
| 240 |
linked_char *disable = calloc(1, sizeof(linked_char)); |
| 241 |
disable->next = settings.disabled_plugins; |
| 242 |
disable->name = strdup(name); |
| 243 |
settings.disabled_plugins = disable; |
| 244 |
} |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
static void server_dump_animations(void) { |
| 250 |
dump_animations(); |
| 251 |
cleanup(); |
| 252 |
} |
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
typedef void (*cmdlinefunc_args0)(void); |
| 257 |
typedef void (*cmdlinefunc_args1)(const char* arg1); |
| 258 |
typedef void (*cmdlinefunc_args2)(const char* arg1, const char* arg2); |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
struct Command_Line_Options { |
| 267 |
const char *cmd_option; |
| 268 |
uint8_t num_args; |
| 269 |
uint8_t pass; |
| 270 |
void (*func)(); |
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
}; |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
static struct Command_Line_Options options[] = { |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
{ "-arch", 1, 1, set_archetypes }, |
| 289 |
{ "-conf", 1, 1, set_confdir }, |
| 290 |
{ "-d", 0, 1, set_debug }, |
| 291 |
{ "-data", 1, 1, set_datadir }, |
| 292 |
{ "-disable-plugin", 1, 1, set_disable_plugin }, |
| 293 |
{ "-h", 0, 1, help }, |
| 294 |
{ "-local", 1, 1, set_localdir }, |
| 295 |
{ "-log", 1, 1, set_logfile }, |
| 296 |
{ "-maps", 1, 1, set_mapdir }, |
| 297 |
{ "-mon", 0, 1, set_mondebug }, |
| 298 |
{ "-n", 0, 1, unset_debug }, |
| 299 |
{ "-playerdir", 1, 1, set_playerdir }, |
| 300 |
{ "-regions", 1, 1, set_regions }, |
| 301 |
{ "-templatedir", 1, 1, set_templatedir }, |
| 302 |
{ "-tmpdir", 1, 1, set_tmpdir }, |
| 303 |
{ "-treasures", 1, 1, set_treasures }, |
| 304 |
{ "-uniquedir", 1, 1, set_uniquedir }, |
| 305 |
{ "-v", 0, 1, call_version }, |
| 306 |
|
| 307 |
#ifdef WIN32 |
| 308 |
|
| 309 |
{ "-regsrv", 0, 1, service_register }, |
| 310 |
{ "-unregsrv", 0, 1, service_unregister }, |
| 311 |
{ "-srv", 0, 1, service_handle }, |
| 312 |
#endif |
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
{ "-p", 1, 2, set_csport }, |
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
{ "-m", 0, 3, set_dumpmon1 }, |
| 323 |
{ "-m2", 0, 3, set_dumpmon2 }, |
| 324 |
{ "-m3", 0, 3, set_dumpmon3 }, |
| 325 |
{ "-m4", 0, 3, set_dumpmon4 }, |
| 326 |
{ "-m5", 0, 3, set_dumpmon5 }, |
| 327 |
{ "-m6", 0, 3, set_dumpmon6 }, |
| 328 |
{ "-m7", 0, 3, set_dumpmon7 }, |
| 329 |
{ "-m8", 0, 3, set_dumpmon8 }, |
| 330 |
{ "-m9", 0, 3, set_dumpmon9 }, |
| 331 |
{ "-mt", 1, 3, set_dumpmont }, |
| 332 |
{ "-mexp", 0, 3, dump_experience }, |
| 333 |
{ "-mq", 0, 3, dump_quests }, |
| 334 |
{ "-dump-anims", 0, 3, server_dump_animations }, |
| 335 |
}; |
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
static void parse_args(int argc, char *argv[], int pass) { |
| 352 |
size_t i; |
| 353 |
int on_arg = 1; |
| 354 |
|
| 355 |
while (on_arg < argc) { |
| 356 |
for (i = 0; i < sizeof(options)/sizeof(struct Command_Line_Options); i++) { |
| 357 |
if (!strcmp(options[i].cmd_option, argv[on_arg])) { |
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
if (options[i].pass != pass) { |
| 362 |
on_arg += options[i].num_args+1; |
| 363 |
break; |
| 364 |
} |
| 365 |
if (options[i].num_args) { |
| 366 |
if ((on_arg+options[i].num_args) >= argc) { |
| 367 |
fprintf(stderr, "%s requires an argument.\n", options[i].cmd_option); |
| 368 |
exit(1); |
| 369 |
} |
| 370 |
|
| 371 |
if (options[i].num_args == 1) |
| 372 |
((cmdlinefunc_args1)options[i].func)(argv[on_arg+1]); |
| 373 |
if (options[i].num_args == 2) |
| 374 |
((cmdlinefunc_args2)options[i].func)(argv[on_arg+1], argv[on_arg+2]); |
| 375 |
on_arg += options[i].num_args+1; |
| 376 |
} else { |
| 377 |
((cmdlinefunc_args0)options[i].func)(); |
| 378 |
on_arg++; |
| 379 |
} |
| 380 |
break; |
| 381 |
} |
| 382 |
} |
| 383 |
if (i == sizeof(options)/sizeof(struct Command_Line_Options)) { |
| 384 |
fprintf(stderr, "Unknown option: %s\n", argv[on_arg]); |
| 385 |
fprintf(stderr, "Type '%s -h' for usage.\n", argv[0]); |
| 386 |
exit(1); |
| 387 |
} |
| 388 |
} |
| 389 |
} |
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
static materialtype_t *get_empty_mat(void) { |
| 400 |
materialtype_t *mt; |
| 401 |
int i; |
| 402 |
|
| 403 |
mt = (materialtype_t *)malloc(sizeof(materialtype_t)); |
| 404 |
if (mt == NULL) |
| 405 |
fatal(OUT_OF_MEMORY); |
| 406 |
mt->name = NULL; |
| 407 |
mt->description = NULL; |
| 408 |
for (i = 0; i < NROFATTACKS; i++) { |
| 409 |
mt->save[i] = 0; |
| 410 |
mt->mod[i] = 0; |
| 411 |
} |
| 412 |
mt->next = NULL; |
| 413 |
return mt; |
| 414 |
} |
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
static void load_materials(void) { |
| 421 |
char buf[MAX_BUF], filename[MAX_BUF], *cp, *next; |
| 422 |
FILE *fp; |
| 423 |
materialtype_t *mt; |
| 424 |
int i, value; |
| 425 |
|
| 426 |
snprintf(filename, sizeof(filename), "%s/materials", settings.datadir); |
| 427 |
if ((fp = fopen(filename, "r")) == NULL) { |
| 428 |
LOG(llevError, "Cannot open %s for reading\n", filename); |
| 429 |
mt = get_empty_mat(); |
| 430 |
mt->next = NULL; |
| 431 |
materialt = mt; |
| 432 |
return; |
| 433 |
} |
| 434 |
mt = get_empty_mat(); |
| 435 |
materialt = mt; |
| 436 |
while (fgets(buf, MAX_BUF, fp) != NULL) { |
| 437 |
if (*buf == '#') |
| 438 |
continue; |
| 439 |
if ((cp = strchr(buf, '\n')) != NULL) |
| 440 |
*cp = '\0'; |
| 441 |
cp = buf; |
| 442 |
while (*cp == ' ') |
| 443 |
cp++; |
| 444 |
if (!strncmp(cp, "name", 4)) { |
| 445 |
|
| 446 |
if (mt->next != NULL) { |
| 447 |
if (mt->description == NULL) |
| 448 |
mt->description = add_string(mt->name); |
| 449 |
mt = mt->next; |
| 450 |
} |
| 451 |
mt->next = get_empty_mat(); |
| 452 |
mt->name = add_string(strchr(cp, ' ')+1); |
| 453 |
} else if (!strncmp(cp, "description", 11)) { |
| 454 |
mt->description = add_string(strchr(cp, ' ')+1); |
| 455 |
} else if (sscanf(cp, "material %d", &value)) { |
| 456 |
mt->material = value; |
| 457 |
} else if (!strncmp(cp, "saves", 5)) { |
| 458 |
cp = strchr(cp, ' ')+1; |
| 459 |
for (i = 0; i < NROFATTACKS; i++) { |
| 460 |
if (cp == NULL) { |
| 461 |
mt->save[i] = 0; |
| 462 |
continue; |
| 463 |
} |
| 464 |
if ((next = strchr(cp, ',')) != NULL) |
| 465 |
*(next++) = '\0'; |
| 466 |
sscanf(cp, "%d", &value); |
| 467 |
mt->save[i] = (int8_t)value; |
| 468 |
cp = next; |
| 469 |
} |
| 470 |
} else if (!strncmp(cp, "mods", 4)) { |
| 471 |
cp = strchr(cp, ' ')+1; |
| 472 |
for (i = 0; i < NROFATTACKS; i++) { |
| 473 |
if (cp == NULL) { |
| 474 |
mt->save[i] = 0; |
| 475 |
continue; |
| 476 |
} |
| 477 |
if ((next = strchr(cp, ',')) != NULL) |
| 478 |
*(next++) = '\0'; |
| 479 |
sscanf(cp, "%d", &value); |
| 480 |
mt->mod[i] = (int8_t)value; |
| 481 |
cp = next; |
| 482 |
} |
| 483 |
} |
| 484 |
} |
| 485 |
free(mt->next); |
| 486 |
mt->next = NULL; |
| 487 |
LOG(llevDebug, "loaded material type data\n"); |
| 488 |
fclose(fp); |
| 489 |
} |
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
static void free_materials(void) { |
| 495 |
materialtype_t *next; |
| 496 |
|
| 497 |
while (materialt) { |
| 498 |
next = materialt->next; |
| 499 |
free(materialt); |
| 500 |
materialt = next; |
| 501 |
} |
| 502 |
materialt = NULL; |
| 503 |
} |
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
static void load_settings(void) { |
| 511 |
char buf[MAX_BUF], *cp, dummy[1]; |
| 512 |
int has_val; |
| 513 |
FILE *fp; |
| 514 |
|
| 515 |
dummy[0] = '\0'; |
| 516 |
snprintf(buf, sizeof(buf), "%s/settings", settings.confdir); |
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
if ((fp = fopen(buf, "r")) == NULL) { |
| 523 |
LOG(llevError, "Warning: No settings file found\n"); |
| 524 |
return; |
| 525 |
} |
| 526 |
while (fgets(buf, MAX_BUF-1, fp) != NULL) { |
| 527 |
if (buf[0] == '#') |
| 528 |
continue; |
| 529 |
|
| 530 |
if ((cp = strrchr(buf, '\n')) != NULL) |
| 531 |
*cp = '\0'; |
| 532 |
|
| 533 |
|
| 534 |
if (buf[0] == 0) |
| 535 |
continue; |
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
if ((cp = strchr(buf, ' ')) != NULL) { |
| 541 |
while (*cp == ' ') |
| 542 |
*cp++ = 0; |
| 543 |
has_val = 1; |
| 544 |
} else { |
| 545 |
cp = dummy; |
| 546 |
has_val = 0; |
| 547 |
} |
| 548 |
|
| 549 |
if (!strcasecmp(buf, "metaserver_notification")) { |
| 550 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
| 551 |
settings.meta_on = TRUE; |
| 552 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
| 553 |
settings.meta_on = FALSE; |
| 554 |
} else { |
| 555 |
LOG(llevError, "load_settings: Unknown value for metaserver_notification: %s\n", cp); |
| 556 |
} |
| 557 |
} else if (!strcasecmp(buf, "metaserver_server")) { |
| 558 |
if (has_val) |
| 559 |
safe_strncpy(settings.meta_server, cp, sizeof(settings.meta_server)); |
| 560 |
else |
| 561 |
LOG(llevError, "load_settings: metaserver_server must have a value.\n"); |
| 562 |
} else if (!strcasecmp(buf, "motd")) { |
| 563 |
if (has_val) |
| 564 |
safe_strncpy(settings.motd, cp, sizeof(settings.motd)); |
| 565 |
else |
| 566 |
LOG(llevError, "load_settings: motd must have a value.\n"); |
| 567 |
} else if (!strcasecmp(buf, "dm_mail")) { |
| 568 |
if (has_val) |
| 569 |
safe_strncpy(settings.dm_mail, cp, sizeof(settings.dm_mail)); |
| 570 |
else |
| 571 |
LOG(llevError, "load_settings: dm_mail must have a value.\n"); |
| 572 |
} else if (!strcasecmp(buf, "metaserver_host")) { |
| 573 |
if (has_val) |
| 574 |
safe_strncpy(settings.meta_host, cp, sizeof(settings.meta_host)); |
| 575 |
else |
| 576 |
LOG(llevError, "load_settings: metaserver_host must have a value.\n"); |
| 577 |
} else if (!strcasecmp(buf, "port")) { |
| 578 |
set_csport(cp); |
| 579 |
} else if (!strcasecmp(buf, "metaserver_port")) { |
| 580 |
int port = atoi(cp); |
| 581 |
|
| 582 |
if (port < 1 || port > 65535) |
| 583 |
LOG(llevError, "load_settings: metaserver_port must be between 1 and 65535, %d is invalid\n", port); |
| 584 |
else |
| 585 |
settings.meta_port = port; |
| 586 |
} else if (!strcasecmp(buf, "metaserver_comment")) { |
| 587 |
safe_strncpy(settings.meta_comment, cp, sizeof(settings.meta_comment)); |
| 588 |
} else if (!strcasecmp(buf, "worldmapstartx")) { |
| 589 |
int size = atoi(cp); |
| 590 |
|
| 591 |
if (size < 0) |
| 592 |
LOG(llevError, "load_settings: worldmapstartx must be at least 0, %d is invalid\n", size); |
| 593 |
else |
| 594 |
settings.worldmapstartx = size; |
| 595 |
} else if (!strcasecmp(buf, "worldmapstarty")) { |
| 596 |
int size = atoi(cp); |
| 597 |
|
| 598 |
if (size < 0) |
| 599 |
LOG(llevError, "load_settings: worldmapstarty must be at least 0, %d is invalid\n", size); |
| 600 |
else |
| 601 |
settings.worldmapstarty = size; |
| 602 |
} else if (!strcasecmp(buf, "worldmaptilesx")) { |
| 603 |
int size = atoi(cp); |
| 604 |
|
| 605 |
if (size < 1) |
| 606 |
LOG(llevError, "load_settings: worldmaptilesx must be greater than 1, %d is invalid\n", size); |
| 607 |
else |
| 608 |
settings.worldmaptilesx = size; |
| 609 |
} else if (!strcasecmp(buf, "worldmaptilesy")) { |
| 610 |
int size = atoi(cp); |
| 611 |
|
| 612 |
if (size < 1) |
| 613 |
LOG(llevError, "load_settings: worldmaptilesy must be greater than 1, %d is invalid\n", size); |
| 614 |
else |
| 615 |
settings.worldmaptilesy = size; |
| 616 |
} else if (!strcasecmp(buf, "worldmaptilesizex")) { |
| 617 |
int size = atoi(cp); |
| 618 |
|
| 619 |
if (size < 1) |
| 620 |
LOG(llevError, "load_settings: worldmaptilesizex must be greater than 1, %d is invalid\n", size); |
| 621 |
else |
| 622 |
settings.worldmaptilesizex = size; |
| 623 |
} else if (!strcasecmp(buf, "worldmaptilesizey")) { |
| 624 |
int size = atoi(cp); |
| 625 |
|
| 626 |
if (size < 1) |
| 627 |
LOG(llevError, "load_settings: worldmaptilesizey must be greater than 1, %d is invalid\n", size); |
| 628 |
else |
| 629 |
settings.worldmaptilesizey = size; |
| 630 |
} else if (!strcasecmp(buf, "fastclock")) { |
| 631 |
int lev = atoi(cp); |
| 632 |
|
| 633 |
if (lev < 0) |
| 634 |
LOG(llevError, "load_settings: fastclock must be at least 0, %d is invalid\n", lev); |
| 635 |
else |
| 636 |
settings.fastclock = lev; |
| 637 |
} else if (!strcasecmp(buf, "not_permadeth")) { |
| 638 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
| 639 |
settings.not_permadeth = TRUE; |
| 640 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
| 641 |
settings.not_permadeth = FALSE; |
| 642 |
} else { |
| 643 |
LOG(llevError, "load_settings: Unknown value for not_permadeth: %s\n", cp); |
| 644 |
} |
| 645 |
} else if (!strcasecmp(buf, "resurrection")) { |
| 646 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
| 647 |
settings.resurrection = TRUE; |
| 648 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
| 649 |
settings.resurrection = FALSE; |
| 650 |
} else { |
| 651 |
LOG(llevError, "load_settings: Unknown value for resurrection: %s\n", cp); |
| 652 |
} |
| 653 |
} else if (!strcasecmp(buf, "set_title")) { |
| 654 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
| 655 |
settings.set_title = TRUE; |
| 656 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
| 657 |
settings.set_title = FALSE; |
| 658 |
} else { |
| 659 |
LOG(llevError, "load_settings: Unknown value for set_title: %s\n", cp); |
| 660 |
} |
| 661 |
} else if (!strcasecmp(buf, "search_items")) { |
| 662 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
| 663 |
settings.search_items = TRUE; |
| 664 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
| 665 |
settings.search_items = FALSE; |
| 666 |
} else { |
| 667 |
LOG(llevError, "load_settings: Unknown value for search_items: %s\n", cp); |
| 668 |
} |
| 669 |
} else if (!strcasecmp(buf, "spell_encumbrance")) { |
| 670 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
| 671 |
settings.spell_encumbrance = TRUE; |
| 672 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
| 673 |
settings.spell_encumbrance = FALSE; |
| 674 |
} else { |
| 675 |
LOG(llevError, "load_settings: Unknown value for spell_encumbrance: %s\n", cp); |
| 676 |
} |
| 677 |
} else if (!strcasecmp(buf, "spell_failure_effects")) { |
| 678 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
| 679 |
settings.spell_failure_effects = TRUE; |
| 680 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
| 681 |
settings.spell_failure_effects = FALSE; |
| 682 |
} else { |
| 683 |
LOG(llevError, "load_settings: Unknown value for spell_failure_effects: %s\n", cp); |
| 684 |
} |
| 685 |
} else if (!strcasecmp(buf, "casting_time")) { |
| 686 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
| 687 |
settings.casting_time = TRUE; |
| 688 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
| 689 |
settings.casting_time = FALSE; |
| 690 |
} else { |
| 691 |
LOG(llevError, "load_settings: Unknown value for casting_time: %s\n", cp); |
| 692 |
} |
| 693 |
} else if (!strcasecmp(buf, "real_wiz")) { |
| 694 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
| 695 |
settings.real_wiz = TRUE; |
| 696 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
| 697 |
settings.real_wiz = FALSE; |
| 698 |
} else { |
| 699 |
LOG(llevError, "load_settings: Unknown value for real_wiz: %s\n", cp); |
| 700 |
} |
| 701 |
} else if (!strcasecmp(buf, "recycle_tmp_maps")) { |
| 702 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
| 703 |
settings.recycle_tmp_maps = TRUE; |
| 704 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
| 705 |
settings.recycle_tmp_maps = FALSE; |
| 706 |
} else { |
| 707 |
LOG(llevError, "load_settings: Unknown value for recycle_tmp_maps: %s\n", cp); |
| 708 |
} |
| 709 |
} else if (!strcasecmp(buf, "always_show_hp")) { |
| 710 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
| 711 |
settings.always_show_hp = 2; |
| 712 |
} else if (!strcasecmp(cp, "damaged")) { |
| 713 |
settings.always_show_hp = 1; |
| 714 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
| 715 |
settings.always_show_hp = 0; |
| 716 |
} else { |
| 717 |
LOG(llevError, "load_settings: Unknown value for always_show_hp: %s\n", cp); |
| 718 |
} |
| 719 |
} else if (!strcasecmp(buf, "who_format")) { |
| 720 |
if (has_val) |
| 721 |
safe_strncpy(settings.who_format, cp, |
| 722 |
sizeof(settings.who_format)); |
| 723 |
} else if (!strcasecmp(buf, "who_wiz_format")) { |
| 724 |
if (has_val) { |
| 725 |
safe_strncpy(settings.who_wiz_format, cp, |
| 726 |
sizeof(settings.who_wiz_format)); |
| 727 |
} |
| 728 |
} else if (!strcasecmp(buf, "spellpoint_level_depend")) { |
| 729 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
| 730 |
settings.spellpoint_level_depend = TRUE; |
| 731 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
| 732 |
settings.spellpoint_level_depend = FALSE; |
| 733 |
} else { |
| 734 |
LOG(llevError, "load_settings: Unknown value for spellpoint_level_depend: %s\n", cp); |
| 735 |
} |
| 736 |
} else if (!strcasecmp(buf, "stat_loss_on_death")) { |
| 737 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
| 738 |
settings.stat_loss_on_death = TRUE; |
| 739 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
| 740 |
settings.stat_loss_on_death = FALSE; |
| 741 |
} else { |
| 742 |
LOG(llevError, "load_settings: Unknown value for stat_loss_on_death: %s\n", cp); |
| 743 |
} |
| 744 |
} else if (!strcasecmp(buf, "use_permanent_experience")) { |
| 745 |
LOG(llevError, "use_permanent_experience is deprecated, usepermenent_experience_percentage instead\n"); |
| 746 |
} else if (!strcasecmp(buf, "permanent_experience_percentage")) { |
| 747 |
int val = atoi(cp); |
| 748 |
if (val < 0 || val > 100) |
| 749 |
LOG(llevError, "load_settings: permenent_experience_percentage must be between 0 and 100, %d is invalid\n", val); |
| 750 |
else |
| 751 |
settings.permanent_exp_ratio = val; |
| 752 |
} else if (!strcasecmp(buf, "death_penalty_percentage")) { |
| 753 |
int val = atoi(cp); |
| 754 |
if (val < 0 || val > 100) |
| 755 |
LOG(llevError, "load_settings: death_penalty_percentage must be between 0 and 100, %d is invalid\n", val); |
| 756 |
else |
| 757 |
settings.death_penalty_ratio = val; |
| 758 |
} else if (!strcasecmp(buf, "death_penalty_levels")) { |
| 759 |
int val = atoi(cp); |
| 760 |
if (val < 0 || val > 255) |
| 761 |
LOG(llevError, "load_settings: death_penalty_levels can not be negative, %d is invalid\n", val); |
| 762 |
else |
| 763 |
settings.death_penalty_level = val; |
| 764 |
} else if (!strcasecmp(buf, "balanced_stat_loss")) { |
| 765 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
| 766 |
settings.balanced_stat_loss = TRUE; |
| 767 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
| 768 |
settings.balanced_stat_loss = FALSE; |
| 769 |
} else { |
| 770 |
LOG(llevError, "load_settings: Unknown value for balanced_stat_loss: %s\n", cp); |
| 771 |
} |
| 772 |
} else if (!strcasecmp(buf, "simple_exp")) { |
| 773 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
| 774 |
settings.simple_exp = TRUE; |
| 775 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
| 776 |
settings.simple_exp = FALSE; |
| 777 |
} else { |
| 778 |
LOG(llevError, "load_settings: Unknown value for simple_exp: %s\n", cp); |
| 779 |
} |
| 780 |
} else if (!strcasecmp(buf, "item_power_factor")) { |
| 781 |
float tmp = atof(cp); |
| 782 |
if (tmp < 0) |
| 783 |
LOG(llevError, "load_settings: item_power_factor must be a positive number (%f < 0)\n", tmp); |
| 784 |
else |
| 785 |
settings.item_power_factor = tmp; |
| 786 |
} else if (!strcasecmp(buf, "pk_luck_penalty")) { |
| 787 |
int16_t val = atoi(cp); |
| 788 |
|
| 789 |
if (val < -100 || val > 100) |
| 790 |
LOG(llevError, "load_settings: pk_luck_penalty must be between -100 and 100, %d is invalid\n", val); |
| 791 |
else |
| 792 |
settings.pk_luck_penalty = val; |
| 793 |
} else if (!strcasecmp(buf, "set_friendly_fire")) { |
| 794 |
int val = atoi(cp); |
| 795 |
|
| 796 |
if (val < 1 || val > 100) |
| 797 |
LOG(llevError, "load_settings: set_friendly_fire must be between 1 an 100, %d is invalid\n", val); |
| 798 |
else |
| 799 |
settings.set_friendly_fire = val; |
| 800 |
} else if (!strcasecmp(buf, "armor_max_enchant")) { |
| 801 |
int max_e = atoi(cp); |
| 802 |
if (max_e <= 0) |
| 803 |
LOG(llevError, "load_settings: armor_max_enchant is %d\n", max_e); |
| 804 |
else |
| 805 |
settings.armor_max_enchant = max_e; |
| 806 |
} else if (!strcasecmp(buf, "armor_weight_reduction")) { |
| 807 |
int wr = atoi(cp); |
| 808 |
if (wr < 0) |
| 809 |
LOG(llevError, "load_settings: armor_weight_reduction is %d\n", wr); |
| 810 |
else |
| 811 |
settings.armor_weight_reduction = wr; |
| 812 |
} else if (!strcasecmp(buf, "armor_weight_linear")) { |
| 813 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
| 814 |
settings.armor_weight_linear = TRUE; |
| 815 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
| 816 |
settings.armor_weight_linear = FALSE; |
| 817 |
} else { |
| 818 |
LOG(llevError, "load_settings: unknown value for armor_weight_linear: %s\n", cp); |
| 819 |
} |
| 820 |
} else if (!strcasecmp(buf, "armor_speed_improvement")) { |
| 821 |
int wr = atoi(cp); |
| 822 |
if (wr < 0) |
| 823 |
LOG(llevError, "load_settings: armor_speed_improvement is %d\n", wr); |
| 824 |
else |
| 825 |
settings.armor_speed_improvement = wr; |
| 826 |
} else if (!strcasecmp(buf, "armor_speed_linear")) { |
| 827 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
| 828 |
settings.armor_speed_linear = TRUE; |
| 829 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
| 830 |
settings.armor_speed_linear = FALSE; |
| 831 |
} else { |
| 832 |
LOG(llevError, "load_settings: unknown value for armor_speed_linear: %s\n", cp); |
| 833 |
} |
| 834 |
} else if (!strcasecmp(buf, "no_player_stealing")) { |
| 835 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
| 836 |
settings.no_player_stealing = TRUE; |
| 837 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
| 838 |
settings.no_player_stealing = FALSE; |
| 839 |
} else { |
| 840 |
LOG(llevError, "load_settings: unknown value for no_player_stealing: %s\n", cp); |
| 841 |
} |
| 842 |
} else if (!strcasecmp(buf, "create_home_portals")) { |
| 843 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
| 844 |
settings.create_home_portals = TRUE; |
| 845 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
| 846 |
settings.create_home_portals = FALSE; |
| 847 |
} else { |
| 848 |
LOG(llevError, "load_settings: unknown value for create_home_portals: %s\n", cp); |
| 849 |
} |
| 850 |
} else if (!strcasecmp(buf, "personalized_blessings")) { |
| 851 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
| 852 |
settings.personalized_blessings = TRUE; |
| 853 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
| 854 |
settings.personalized_blessings = FALSE; |
| 855 |
} else { |
| 856 |
LOG(llevError, "load_settings: unknown value for personalized_blessings: %s\n", cp); |
| 857 |
} |
| 858 |
} else if (!strcasecmp(buf, "pk_max_experience")) { |
| 859 |
int64_t pkme = atoll(cp); |
| 860 |
if (pkme < 0) |
| 861 |
pkme = -1; |
| 862 |
settings.pk_max_experience = pkme; |
| 863 |
} else if (!strcasecmp(buf, "pk_max_experience_percent")) { |
| 864 |
int pkmep = atoi(cp); |
| 865 |
if (pkmep < 0) { |
| 866 |
LOG(llevError, "load_settings: pk_max_experience_percent should be positive or zero (was \"%s\")\n", cp); |
| 867 |
} else |
| 868 |
settings.pk_max_experience_percent = pkmep; |
| 869 |
} else if (!strcasecmp(buf, "allow_denied_spells_writing")) { |
| 870 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
| 871 |
settings.allow_denied_spells_writing = TRUE; |
| 872 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
| 873 |
settings.allow_denied_spells_writing = FALSE; |
| 874 |
} else { |
| 875 |
LOG(llevError, "load_settings: unknown value for allow_denied_spells_writing: %s\n", cp); |
| 876 |
} |
| 877 |
} else if (!strcasecmp(buf, "allow_broken_converters")) { |
| 878 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
| 879 |
settings.allow_broken_converters = TRUE; |
| 880 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
| 881 |
settings.allow_broken_converters = FALSE; |
| 882 |
} else { |
| 883 |
LOG(llevError, "load_settings: unknown value for allow_broken_converters: %s\n", cp); |
| 884 |
} |
| 885 |
} else if (!strcasecmp(buf, "log_timestamp")) { |
| 886 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
| 887 |
settings.log_timestamp = TRUE; |
| 888 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
| 889 |
settings.log_timestamp = FALSE; |
| 890 |
} else { |
| 891 |
LOG(llevError, "load_settings: unknown value for log_timestamp: %s\n", cp); |
| 892 |
} |
| 893 |
} else if (!strcasecmp(buf, "log_timestamp_format")) { |
| 894 |
free(settings.log_timestamp_format); |
| 895 |
settings.log_timestamp_format = strdup_local(cp); |
| 896 |
} else if (!strcasecmp(buf, "starting_stat_min")) { |
| 897 |
int val = atoi(cp); |
| 898 |
|
| 899 |
if (val < 1 || val > settings.max_stat || val > settings.starting_stat_max) |
| 900 |
LOG(llevError, "load_settings: starting_stat_min (%d) need to be within %d-%d (%d)\n", |
| 901 |
val, 1, settings.max_stat, settings.starting_stat_max); |
| 902 |
else |
| 903 |
settings.starting_stat_min = val; |
| 904 |
} else if (!strcasecmp(buf, "starting_stat_max")) { |
| 905 |
int val = atoi(cp); |
| 906 |
|
| 907 |
if (val < 1 || val > settings.max_stat || val<settings.starting_stat_min) |
| 908 |
LOG(llevError, "load_settings: starting_stat_max (%d) need to be within %d-%d (%d)\n", |
| 909 |
val, 1, settings.max_stat, settings.starting_stat_min); |
| 910 |
else |
| 911 |
settings.starting_stat_max = val; |
| 912 |
} else if (!strcasecmp(buf, "starting_stat_points")) { |
| 913 |
int val = atoi(cp); |
| 914 |
|
| 915 |
if (val < NUM_STATS * settings.starting_stat_min || |
| 916 |
val > NUM_STATS * settings.starting_stat_max) |
| 917 |
LOG(llevError, "load_settings: starting_stat_points (%d) need to be within %d-%d\n", |
| 918 |
val, NUM_STATS * settings.starting_stat_min, NUM_STATS * settings.starting_stat_max); |
| 919 |
else |
| 920 |
settings.starting_stat_points = val; |
| 921 |
} else if (!strcasecmp(buf, "roll_stat_points")) { |
| 922 |
int val = atoi(cp); |
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
if (val < NUM_STATS * 3 || val > NUM_STATS * 18) |
| 930 |
LOG(llevError, "load_settings: roll_stat_points need to be within %d-%d\n", |
| 931 |
NUM_STATS * 3, NUM_STATS * 18); |
| 932 |
else |
| 933 |
settings.roll_stat_points = val; |
| 934 |
} else if (!strcasecmp(buf, "special_break_map")) { |
| 935 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
| 936 |
settings.special_break_map = TRUE; |
| 937 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
| 938 |
settings.special_break_map = FALSE; |
| 939 |
} else { |
| 940 |
LOG(llevError, "load_settings: unknown value for special_break_map: %s\n", cp); |
| 941 |
} |
| 942 |
} else if (!strcasecmp(buf, "ignore_plugin_compatibility")) { |
| 943 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
| 944 |
settings.ignore_plugin_compatibility = TRUE; |
| 945 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
| 946 |
settings.ignore_plugin_compatibility = FALSE; |
| 947 |
} else { |
| 948 |
LOG(llevError, "load_settings: unknown value for ignore_plugin_compatibility: %s\n", cp); |
| 949 |
} |
| 950 |
} else if (!strcasecmp(buf, "account_block_create")) { |
| 951 |
if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
| 952 |
settings.account_block_create = TRUE; |
| 953 |
} else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
| 954 |
settings.account_block_create = FALSE; |
| 955 |
} else { |
| 956 |
LOG(llevError, "load_settings: unknown value for account_block_create: %s\n", cp); |
| 957 |
} |
| 958 |
} else if (!strcasecmp(buf, "account_trusted_host")) { |
| 959 |
free(settings.account_trusted_host); |
| 960 |
settings.account_trusted_host = strdup_local(cp); |
| 961 |
} else if (!strcasecmp(buf, "crypt_mode")) { |
| 962 |
int val = atoi(cp); |
| 963 |
if (val != 0 && val != 1) { |
| 964 |
LOG(llevError, "load_settings: crypt_mode must be 0 or 1\n"); |
| 965 |
} else { |
| 966 |
settings.crypt_mode = val; |
| 967 |
} |
| 968 |
} else if (!strcasecmp(buf, "min_name")) { |
| 969 |
int val = atoi(cp); |
| 970 |
|
| 971 |
if (val < 1 || val > MAX_NAME ) |
| 972 |
LOG(llevError, "load_settings: min_name (%d) need to be within %d-%d\n", |
| 973 |
val, 1, MAX_NAME); |
| 974 |
else |
| 975 |
settings.min_name = val; |
| 976 |
} else { |
| 977 |
LOG(llevError, "Unknown value in settings file: %s\n", buf); |
| 978 |
} |
| 979 |
} |
| 980 |
fclose(fp); |
| 981 |
if (settings.log_timestamp_format == NULL) |
| 982 |
settings.log_timestamp_format = strdup_local("%y/%m/%d %H:%M:%S"); |
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
if (!strcmp(settings.who_format, "")) |
| 991 |
strcpy(settings.who_format, "%N_%T%t%h%d%b%n<%m>"); |
| 992 |
if (!strcmp(settings.who_wiz_format, "")) |
| 993 |
strcpy(settings.who_wiz_format, "%N_%T%t%h%d%b%nLevel %l <%m>(@%i)(%c)"); |
| 994 |
} |
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
void init(int argc, char **argv) { |
| 1004 |
init_done = 0; |
| 1005 |
logfile = stderr; |
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
parse_args(argc, argv, 1); |
| 1010 |
|
| 1011 |
init_library(); |
| 1012 |
load_settings(); |
| 1013 |
load_materials(); |
| 1014 |
parse_args(argc, argv, 2); |
| 1015 |
|
| 1016 |
LOG(llevInfo, "Crossfire %s\n", FULL_VERSION); |
| 1017 |
SRANDOM(time(NULL)); |
| 1018 |
|
| 1019 |
init_startup(); |
| 1020 |
init_signals(); |
| 1021 |
init_commands(); |
| 1022 |
read_map_log(); |
| 1023 |
init_skills(); |
| 1024 |
init_ob_methods(); |
| 1025 |
cftimer_init(); |
| 1026 |
hiscore_init(); |
| 1027 |
|
| 1028 |
parse_args(argc, argv, 3); |
| 1029 |
|
| 1030 |
init_beforeplay(); |
| 1031 |
init_server(); |
| 1032 |
metaserver2_init(); |
| 1033 |
accounts_load(); |
| 1034 |
reset_sleep(); |
| 1035 |
init_done = 1; |
| 1036 |
} |
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
void free_server(void) { |
| 1044 |
free_materials(); |
| 1045 |
free_races(); |
| 1046 |
free_quest(); |
| 1047 |
free_quest_definitions(); |
| 1048 |
while (settings.disabled_plugins) { |
| 1049 |
linked_char *next = settings.disabled_plugins->next; |
| 1050 |
free((void *)settings.disabled_plugins->name); |
| 1051 |
free(settings.disabled_plugins); |
| 1052 |
settings.disabled_plugins = next; |
| 1053 |
} |
| 1054 |
} |
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
static void help(void) { |
| 1060 |
printf("Usage: crossfire-server [options]\n\n"); |
| 1061 |
|
| 1062 |
printf("Options:\n"); |
| 1063 |
printf(" -arch Set the file with archetype definitions.\n"); |
| 1064 |
printf(" -conf Set the directory to find configuration files.\n"); |
| 1065 |
printf(" -d Turn on extra debugging messages.\n"); |
| 1066 |
printf(" -data Set the data (share/) directory (archetypes, treasures, etc).\n"); |
| 1067 |
printf(" -disable-plugin\n" |
| 1068 |
" Disables specified plugin. Use the name without the extension.\n" |
| 1069 |
" Can be specified multiple times. 'All' disables all plugins.\n"); |
| 1070 |
printf(" -dump-anims Dump animations.\n"); |
| 1071 |
printf(" -h Print this help message.\n"); |
| 1072 |
printf(" -local Set the local data (var/) directory.\n"); |
| 1073 |
printf(" -log <file> Write logging information to the given file.\n"); |
| 1074 |
printf(" -m List suggested experience for all monsters.\n"); |
| 1075 |
printf(" -m2 Dump monster abilities.\n"); |
| 1076 |
printf(" -m3 Dump artifact information.\n"); |
| 1077 |
printf(" -m4 Dump spell information.\n"); |
| 1078 |
printf(" -m5 Dump skill information.\n"); |
| 1079 |
printf(" -m6 Dump race information.\n"); |
| 1080 |
printf(" -m7 Dump alchemy information.\n"); |
| 1081 |
printf(" -m8 Dump gods information.\n"); |
| 1082 |
printf(" -m9 Dump more alchemy information (formula checking).\n"); |
| 1083 |
printf(" -maps Set the map directory.\n"); |
| 1084 |
printf(" -mexp Dump the experience table.\n"); |
| 1085 |
printf(" -mon Turn on monster debugging.\n"); |
| 1086 |
printf(" -mq Dump the quest list.\n"); |
| 1087 |
printf(" -mt <name> Dump a list of treasures for a monster.\n"); |
| 1088 |
printf(" -n Turn off debugging messages if on by default.\n"); |
| 1089 |
printf(" -p <port> Specifies the port to listen on for incoming connections.\n"); |
| 1090 |
printf(" -playerdir Set the player files directory.\n"); |
| 1091 |
printf(" -regions Set the region file.\n"); |
| 1092 |
printf(" -templatedir Set the template map directory.\n"); |
| 1093 |
printf(" -tmpdir Set the directory for temporary files (mostly maps.)\n"); |
| 1094 |
printf(" -treasures Set the treasures file.\n"); |
| 1095 |
printf(" -uniquedir Set the unique items/maps directory.\n"); |
| 1096 |
printf(" -v Print version information.\n"); |
| 1097 |
exit(EXIT_SUCCESS); |
| 1098 |
} |
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
static void init_beforeplay(void) { |
| 1105 |
init_archetypes(); |
| 1106 |
init_artifacts(); |
| 1107 |
check_spells(); |
| 1108 |
init_regions(); |
| 1109 |
init_archetype_pointers(); |
| 1110 |
init_races(); |
| 1111 |
init_gods(); |
| 1112 |
init_readable(); |
| 1113 |
init_formulae(); |
| 1114 |
|
| 1115 |
switch (settings.dumpvalues) { |
| 1116 |
case 1: |
| 1117 |
print_monsters(); |
| 1118 |
cleanup(); |
| 1119 |
|
| 1120 |
case 2: |
| 1121 |
dump_abilities(); |
| 1122 |
cleanup(); |
| 1123 |
|
| 1124 |
case 3: |
| 1125 |
dump_artifacts(); |
| 1126 |
cleanup(); |
| 1127 |
|
| 1128 |
case 4: |
| 1129 |
dump_spells(); |
| 1130 |
cleanup(); |
| 1131 |
|
| 1132 |
case 5: |
| 1133 |
cleanup(); |
| 1134 |
|
| 1135 |
case 6: |
| 1136 |
dump_races(); |
| 1137 |
cleanup(); |
| 1138 |
|
| 1139 |
case 7: |
| 1140 |
dump_alchemy(); |
| 1141 |
cleanup(); |
| 1142 |
|
| 1143 |
case 8: |
| 1144 |
dump_gods(); |
| 1145 |
cleanup(); |
| 1146 |
|
| 1147 |
case 9: |
| 1148 |
dump_alchemy_costs(); |
| 1149 |
cleanup(); |
| 1150 |
|
| 1151 |
case 10: |
| 1152 |
dump_monster_treasure(settings.dumparg); |
| 1153 |
cleanup(); |
| 1154 |
} |
| 1155 |
} |
| 1156 |
|
| 1157 |
|
| 1158 |
|
| 1159 |
|
| 1160 |
|
| 1161 |
|
| 1162 |
static void init_startup(void) { |
| 1163 |
char buf[MAX_BUF]; |
| 1164 |
FILE *fp; |
| 1165 |
|
| 1166 |
#ifdef SHUTDOWN_FILE |
| 1167 |
snprintf(buf, sizeof(buf), "%s/%s", settings.confdir, SHUTDOWN_FILE); |
| 1168 |
if ((fp = fopen(buf, "r")) != NULL) { |
| 1169 |
while (fgets(buf, MAX_BUF-1, fp) != NULL) |
| 1170 |
printf("%s", buf); |
| 1171 |
fclose(fp); |
| 1172 |
exit(1); |
| 1173 |
} |
| 1174 |
#endif |
| 1175 |
|
| 1176 |
if (forbid_play()) { |
| 1177 |
LOG(llevError, "CrossFire: Playing not allowed.\n"); |
| 1178 |
exit(-1); |
| 1179 |
} |
| 1180 |
} |
| 1181 |
|
| 1182 |
|
| 1183 |
|
| 1184 |
|
| 1185 |
static void signal_shutdown(int signum_unused) { |
| 1186 |
(void) signum_unused; |
| 1187 |
shutdown_flag += 1; |
| 1188 |
} |
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
static void rec_sighup(int i) { |
| 1203 |
|
| 1204 |
|
| 1205 |
if (logfile != stderr) { |
| 1206 |
reopen_logfile = 1; |
| 1207 |
} |
| 1208 |
} |
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
static void init_signals(void) { |
| 1214 |
#ifndef WIN32 |
| 1215 |
struct sigaction sa; |
| 1216 |
|
| 1217 |
sa.sa_sigaction = NULL; |
| 1218 |
sigemptyset(&sa.sa_mask); |
| 1219 |
sa.sa_flags = 0; |
| 1220 |
sa.sa_handler = rec_sighup; |
| 1221 |
sigaction(SIGHUP, &sa, NULL); |
| 1222 |
signal(SIGINT, signal_shutdown); |
| 1223 |
signal(SIGPIPE, SIG_IGN); |
| 1224 |
#endif |
| 1225 |
} |
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
static void init_races(void) { |
| 1234 |
FILE *file; |
| 1235 |
char race[MAX_BUF], fname[MAX_BUF], buf[MAX_BUF], *cp, variable[MAX_BUF]; |
| 1236 |
archetype *mon = NULL; |
| 1237 |
static int init_done = 0; |
| 1238 |
|
| 1239 |
if (init_done) |
| 1240 |
return; |
| 1241 |
init_done = 1; |
| 1242 |
first_race = NULL; |
| 1243 |
|
| 1244 |
snprintf(fname, sizeof(fname), "%s/races", settings.datadir); |
| 1245 |
if (!(file = fopen(fname, "r"))) { |
| 1246 |
LOG(llevError, "Cannot open races file %s: %s\n", fname, strerror(errno)); |
| 1247 |
return; |
| 1248 |
} |
| 1249 |
|
| 1250 |
while (fgets(buf, MAX_BUF, file) != NULL) { |
| 1251 |
int set_race = 1, set_list = 1; |
| 1252 |
if (*buf == '#') |
| 1253 |
continue; |
| 1254 |
if ((cp = strchr(buf, '\n')) != NULL) |
| 1255 |
*cp = '\0'; |
| 1256 |
cp = buf; |
| 1257 |
while (*cp == ' ' || *cp == '!' || *cp == '@') { |
| 1258 |
if (*cp == '!') |
| 1259 |
set_race = 0; |
| 1260 |
if (*cp == '@') |
| 1261 |
set_list = 0; |
| 1262 |
cp++; |
| 1263 |
} |
| 1264 |
if (sscanf(cp, "RACE %s", variable)) { |
| 1265 |
strcpy(race, variable); |
| 1266 |
} else { |
| 1267 |
char *cp1; |
| 1268 |
|
| 1269 |
|
| 1270 |
for (cp1 = cp; *cp1 == ' '; cp1++) |
| 1271 |
; |
| 1272 |
|
| 1273 |
for (cp1 = cp+strlen(cp)-1; *cp1 == '\n' || *cp1 == ' '; cp1--) { |
| 1274 |
*cp1 = '\0'; |
| 1275 |
if (cp == cp1) |
| 1276 |
break; |
| 1277 |
} |
| 1278 |
|
| 1279 |
if (cp[strlen(cp)-1] == '\n') |
| 1280 |
cp[strlen(cp)-1] = '\0'; |
| 1281 |
|
| 1282 |
if ((mon = find_archetype(cp)) == NULL) |
| 1283 |
LOG(llevError, "Creature %s in race file lacks archetype\n", cp); |
| 1284 |
else { |
| 1285 |
|
| 1286 |
|
| 1287 |
if (set_race && (!mon->clone.race || !strstr(mon->clone.race, race))) { |
| 1288 |
if (mon->clone.race) { |
| 1289 |
LOG(llevDebug, "races: Appending to %s from %s for archetype %s\n", race, mon->clone.race, mon->name); |
| 1290 |
|
| 1291 |
strcpy(race+strlen(race), ","); |
| 1292 |
strncpy(race+strlen(race), mon->clone.race, MAX_BUF - 1 - strlen(race)); |
| 1293 |
|
| 1294 |
free_string(mon->clone.race); |
| 1295 |
} |
| 1296 |
mon->clone.race = add_string(race); |
| 1297 |
} |
| 1298 |
|
| 1299 |
if (set_list && QUERY_FLAG(&mon->clone, FLAG_MONSTER)) |
| 1300 |
add_to_racelist(race, &mon->clone); |
| 1301 |
} |
| 1302 |
} |
| 1303 |
} |
| 1304 |
fclose(file); |
| 1305 |
LOG(llevDebug, "loaded races\n"); |
| 1306 |
} |
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
static void dump_races(void) { |
| 1312 |
racelink *list; |
| 1313 |
objectlink *tmp; |
| 1314 |
|
| 1315 |
for (list = first_race; list; list = list->next) { |
| 1316 |
fprintf(stderr, "\nRACE %s:\t", list->name); |
| 1317 |
for (tmp = list->member; tmp; tmp = tmp->next) |
| 1318 |
fprintf(stderr, "%s(%d), ", tmp->ob->arch->name, tmp->ob->level); |
| 1319 |
} |
| 1320 |
fprintf(stderr, "\n"); |
| 1321 |
} |
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
static void free_races(void) { |
| 1327 |
racelink *race; |
| 1328 |
objectlink *link; |
| 1329 |
|
| 1330 |
LOG(llevDebug, "Freeing race information.\n"); |
| 1331 |
while (first_race) { |
| 1332 |
race = first_race->next; |
| 1333 |
while (first_race->member) { |
| 1334 |
link = first_race->member->next; |
| 1335 |
free(first_race->member); |
| 1336 |
first_race->member = link; |
| 1337 |
} |
| 1338 |
free_string(first_race->name); |
| 1339 |
free(first_race); |
| 1340 |
first_race = race; |
| 1341 |
} |
| 1342 |
} |
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
|
| 1350 |
|
| 1351 |
|
| 1352 |
static void add_to_racelist(const char *race_name, object *op) { |
| 1353 |
racelink *race; |
| 1354 |
|
| 1355 |
if (!op || !race_name) |
| 1356 |
return; |
| 1357 |
race = find_racelink(race_name); |
| 1358 |
|
| 1359 |
if (!race) { |
| 1360 |
race = get_racelist(); |
| 1361 |
race->next = first_race; |
| 1362 |
first_race = race; |
| 1363 |
race->name = add_string(race_name); |
| 1364 |
} |
| 1365 |
|
| 1366 |
if (race->member->ob) { |
| 1367 |
objectlink *tmp = get_objectlink(); |
| 1368 |
|
| 1369 |
tmp->next = race->member; |
| 1370 |
race->member = tmp; |
| 1371 |
} |
| 1372 |
race->nrof++; |
| 1373 |
race->member->ob = op; |
| 1374 |
} |
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
|
| 1379 |
|
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
static racelink *get_racelist(void) { |
| 1385 |
racelink *list; |
| 1386 |
|
| 1387 |
list = (racelink *)malloc(sizeof(racelink)); |
| 1388 |
if (!list) |
| 1389 |
fatal(OUT_OF_MEMORY); |
| 1390 |
list->name = NULL; |
| 1391 |
list->nrof = 0; |
| 1392 |
list->member = get_objectlink(); |
| 1393 |
list->next = NULL; |
| 1394 |
|
| 1395 |
return list; |
| 1396 |
} |
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
|
| 1405 |
|
| 1406 |
racelink *find_racelink(const char *name) { |
| 1407 |
racelink *test = NULL; |
| 1408 |
|
| 1409 |
if (name && first_race) |
| 1410 |
for (test = first_race; test && test != test->next; test = test->next) |
| 1411 |
if (!test->name || !strcmp(name, test->name)) |
| 1412 |
break; |
| 1413 |
|
| 1414 |
return test; |
| 1415 |
} |