1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895
|
#include "c_defs.h"
/************************************************************************
*
* conf.c - handle configuration issues, both personal and system wide.
*
* $Id: conf.c,v 1.19 2004/11/24 01:31:12 jon Exp $
*
* Copyright 1999-2004 Jon Trulson under the ARTISTIC LICENSE. (See LICENSE).
***********************************************************************/
/**********************************************************************/
/* Unix/C specific porting and supporting code Copyright (C)1994-1996 */
/* by Jon Trulson <jon@radscan.com> under the same terms and */
/* conditions of the original copyright by Jef Poskanzer and Craig */
/* Leres. */
/* */
/**********************************************************************/
#include "global.h"
#include "conqcom.h"
#include "color.h"
#include "ui.h"
#include "datatypes.h"
#include "conqnet.h"
#define CONF_NOEXTERN
#include "conf.h"
#undef CONF_NOEXTERN
#include "protocol.h"
#define HOME_BUFSZ 1024
/* if this is set, then the conquest client is running as the shell on
a telnet based server. In this case, we will never try to load or save
the user config file. GetConf() will only set the defaults. */
static int telnetClient = FALSE;
void confSetTelnetClientMode(int telnetc)
{
telnetClient = telnetc;
return;
}
/* GetSysConf(int checkonly) - load system-wide configuration values */
/* If checkonly is TRUE, then just load internel defaults, and the existing
conquesrtc file, if there. Don't output errmsgs since this will
only be TRUE when 'priming the pump' in conqoper -C, before writing a
new conquestrc file (preserving existing settings if possible).
*/
int GetSysConf(int checkonly)
{
FILE *conf_fd;
int i, j;
char conf_name[MID_BUFFER_SIZE];
char buffer[BUFFER_SIZE];
int FoundOne = FALSE;
int buflen;
char *bufptr;
/* init some defaults */
SysConf.NoDoomsday = FALSE;
SysConf.DoRandomRobotKills = FALSE;
SysConf.AllowVacant = FALSE;
SysConf.AllowSwitchteams = TRUE;
SysConf.UserExpiredays = DEFAULT_USEREXPIRE;
SysConf.LogMessages = FALSE;
SysConf.AllowRefits = TRUE;
SysConf.AllowSlingShot = FALSE;
strncpy(SysConf.ServerName, "Generic Conquest Server",
CONF_SERVER_NAME_SZ);
strncpy(SysConf.ServerMotd, "Keep your shields up in battle.",
CONF_SERVER_MOTD_SZ);
strncpy(SysConf.ServerContact, "root@localhost",
META_GEN_STRSIZE);
/* start building the filename */
snprintf(conf_name, sizeof(conf_name)-1, "%s/%s", CONQETC, SYSCONFIG_FILE);
if ((conf_fd = fopen(conf_name, "r")) == NULL)
{
int err;
err = errno;
clog("GetSysConf(): fopen(%s) failed: %s",
conf_name,
strerror(err));
if (checkonly != TRUE)
{
fprintf(stderr, "Error opening system-wide config file: %s: %s\n",
conf_name,
strerror(err));
fprintf(stderr, "'conqoper -C' needs to be run. Using internal defaults.\n");
sleep(4);
}
return(ERR);
}
#ifdef DEBUG_CONFIG
clog("GetSysConf(): Opened '%s'", conf_name);
#endif
/* Do it dude... */
while (fgets(buffer, BUFFER_SIZE - 1, conf_fd) != NULL)
{ /* get em one at a time */
buflen = strlen(buffer);
if (buffer[0] == '#')
continue;
if (buffer[0] == '\n')
continue;
if (buflen == 0)
continue; /* shouldn't happen...but the universe is
mysterious... */
buffer[buflen - 1] = EOS; /* remove trailing LF */
buflen--;
#ifdef DEBUG_CONFIG
clog("GetSysConf(): got '%s'", buffer);
#endif
/* check for everything else */
FoundOne = FALSE;
for (j = 0; (j < SysCfEnd) && (FoundOne == FALSE); j++)
{
if (SysConfData[j].ConfName != NULL)
if (strncmp(SysConfData[j].ConfName,
buffer,
strlen(SysConfData[j].ConfName)) == 0)
{ /* we found a valid variable */
if (buflen > 0)
{ /* split off the value */
bufptr = &buffer[strlen(SysConfData[j].ConfName)];
switch(SysConfData[j].ConfType)
{
case CTYPE_NULL:
/* special check for version */
if (j == SYSCF_VERSION)
{
if(strncmp((char *)SysConfData[j].ConfValue,
bufptr,
strlen((char *)SysConfData[j].ConfValue)) == 0)
{
SysConfData[j].Found = TRUE;
#ifdef DEBUG_CONFIG
clog("GetSysConf(): got correct version = '%s'", buffer);
#endif
}
}
break;
case CTYPE_BOOL:
i = process_bool(bufptr);
if (i != ERR)
{
*((int *) SysConfData[j].ConfValue) = i;
SysConfData[j].Found = TRUE;
FoundOne = TRUE;
}
break;
case CTYPE_NUMERIC:
if (alldig(bufptr))
{
*((int *) SysConfData[j].ConfValue) = atoi(bufptr);
SysConfData[j].Found = TRUE;
FoundOne = TRUE;
}
break;
case CTYPE_STRING:
memset((char *)(SysConfData[j].ConfValue), 0,
SysConfData[j].max);
strncpy((char *)(SysConfData[j].ConfValue),
bufptr, SysConfData[j].max);
((char *)SysConfData[j].ConfValue)[SysConfData[j].max - 1] = 0;
SysConfData[j].Found = TRUE;
FoundOne = TRUE;
break;
} /* switch */
} /* if */
} /* if */
} /* for */
} /* while */
if (!feof(conf_fd))
{
fprintf(stderr, "GetSysConf(): Error reading %s: %s\n",
conf_name,
strerror(errno));
fclose(conf_fd);
return(ERR);
}
fclose(conf_fd);
/* Now we check them all to see if one */
/* of the options wasn't read in. If one */
/* is found, notify user that operator
needs to run conqoper -C . */
/* see if we found the version */
if (SysConfData[SYSCF_VERSION].Found == FALSE)
{ /* conquestrc version not found */
#ifdef DEBUG_CONFIG
clog("GetSysConf(): Incorrect version found. Update needed.");
#endif
if (checkonly != TRUE)
{
fprintf(stderr, "The %s file needs to be updated by an operator with\n",
conf_name);
fprintf(stderr, " 'conqoper -C'\n");
sleep(4);
}
}
else
{ /* version found. check everything else */
for (i=0; i<SysCfEnd; i++)
{
if (SysConfData[i].ConfType != CTYPE_NULL)
if (SysConfData[i].Found != TRUE)
{
#ifdef DEBUG_CONFIG
clog("GetSysConf(): option '%s' not found - Update needed.",
SysConfData[i].ConfName);
#endif
if (checkonly != TRUE)
{
fprintf(stderr, "The %s file needs to be updated by an operator with\n",
conf_name);
fprintf(stderr, " 'conqoper -C'\n");
sleep(4);
}
break;
}
}
}
return(TRUE);
}
/* get user's configuration */
int GetConf(int usernum)
{
FILE *conf_fd;
int i, j, n;
char conf_name[MID_BUFFER_SIZE];
char *homevar, *cptr;
char home[HOME_BUFSZ];
char buffer[BUFFER_SIZE];
int buflen;
char *bufptr;
int FoundOne = FALSE;
/* init some defaults */
UserConf.DoAlarms = TRUE;
UserConf.ShowPhasers = TRUE;
UserConf.ShowPlanNames = TRUE;
UserConf.DoIntrudeAlert = TRUE;
UserConf.DoNumMap = TRUE;
UserConf.Terse = FALSE;
UserConf.DoExplode = TRUE;
UserConf.MessageBell = TRUE;
UserConf.NoColor = FALSE;
UserConf.NoRobotMsgs = FALSE;
UserConf.UpdatesPerSecond = 5; /* default of 5 per sec */
UserConf.DistressToFriendly = FALSE;
UserConf.AltHUD = FALSE;
UserConf.DoLRTorpScan = TRUE;
UserConf.DoLocalLRScan = TRUE;
UserConf.DoETAStats = TRUE;
UserConf.EnemyShipBox = TRUE;
UserConf.doVBG = TRUE;
for (i=0; i<MAX_MACROS; i++)
{
UserConf.MacrosF[i][0] = EOS;
}
/* a telnet client leaves here after the defaults are set */
if (telnetClient)
return TRUE;
/* start building the filename */
if ((homevar = getenv("HOME")) == NULL)
{
clog("GetConf(): getenv(HOME) failed");
fprintf(stderr, "Can't get HOME environment variable. Exiting\n");
return(ERR);
}
memset(home, 0, HOME_BUFSZ);
strncpy(home, homevar, HOME_BUFSZ - 1);
snprintf(conf_name, sizeof(conf_name)-1, "%s/%s", home, CONFIG_FILE);
if ((conf_fd = fopen(conf_name, "r")) == NULL)
{
if (errno != ENOENT)
{
clog("GetConf(): fopen(%s) failed: %s, using defaults",
conf_name,
strerror(errno));
fprintf(stderr, "Error opening config file: %s: %s, using defaults\n",
conf_name,
strerror(errno));
return(ERR);
}
#ifdef DEBUG_CONFIG
clog("GetConf(): No config file.");
#endif
if (MakeConf(conf_name) == ERR)
return(ERR);
return(FALSE); /* no config file */
}
#ifdef DEBUG_CONFIG
clog("GetConf(): Opened '%s'", conf_name);
#endif
/* We got it! Now lets process it. */
while (fgets(buffer, BUFFER_SIZE - 1, conf_fd) != NULL)
{ /* get em one at a time */
buflen = strlen(buffer);
if (buffer[0] == '#')
continue;
if (buffer[0] == '\n')
continue;
if (buflen == 0)
continue; /* shouldn't happen...but the universe is
mysterious... */
buffer[buflen - 1] = EOS; /* remove trailing LF */
buflen--;
#ifdef DEBUG_CONFIG
clog("GetConf(): got '%s'", buffer);
#endif
FoundOne = FALSE;
for (j = 0; (j < CfEnd) && (FoundOne == FALSE); j++)
{
if (ConfData[j].ConfName != NULL)
if(strncmp(ConfData[j].ConfName,
buffer,
strlen(ConfData[j].ConfName)) == 0)
{ /* we found a valid variable */
if (buflen > 0)
{ /* split off the value */
bufptr = &buffer[strlen(ConfData[j].ConfName)];
switch(ConfData[j].ConfType)
{
case CTYPE_NULL:
/* special check for version */
if (j == CF_VERSION)
{
if(strncmp((char *)ConfData[j].ConfValue,
bufptr,
strlen((char *)ConfData[j].ConfValue)) == 0)
{
ConfData[j].Found = TRUE;
FoundOne = TRUE;
#ifdef DEBUG_CONFIG
clog("GetConf(): got correct version = '%s'", buffer);
#endif
}
}
break;
case CTYPE_BOOL:
i = process_bool(bufptr);
if (i != ERR)
{
*((int *) ConfData[j].ConfValue) = i;
ConfData[j].Found = TRUE;
FoundOne = TRUE;
}
break;
case CTYPE_MACRO:
/* need to parse out macro number. */
cptr = strchr(bufptr, '=');
if (cptr != NULL)
{ /* valid entry */
*cptr = '\0';
n = atoi(bufptr);
if (n > 0 && n <= MAX_MACROS)
{ /* valid macro number */
#ifdef DEBUG_CONFIG
clog("GetConf(): Macro %d[%d], value '%s' read",
n, n - 1, (char *)cptr + 1);
#endif
/* clean it first... */
memset((char *)(((char *)ConfData[j].ConfValue)
+ ((n - 1) * MAX_MACRO_LEN)),
0,
MAX_MACRO_LEN);
strncpy((char *)(((char *)ConfData[j].ConfValue)
+ ((n - 1) * MAX_MACRO_LEN)),
Str2Macro((char *)cptr + 1),
MAX_MACRO_LEN - 1);
ConfData[j].Found = TRUE;
FoundOne = TRUE;
}
}
break;
case CTYPE_NUMERIC:
if (alldig(bufptr))
{
*((int *) ConfData[j].ConfValue) = atoi(bufptr);
ConfData[j].Found = TRUE;
FoundOne = TRUE;
}
break;
} /* switch */
} /* if */
} /* if */
} /* for */
} /* while */
if (!feof(conf_fd))
{
fprintf(stderr, "GetConf(): Error reading %s: %s\n",
conf_name,
strerror(errno));
fclose(conf_fd);
return(ERR);
}
fclose(conf_fd);
/* Now we check them all to see if one */
/* of the options wasn't read in. If one */
/* is found, re-write the config file. */
/* see if we found the version */
if (ConfData[CF_VERSION].Found == FALSE)
{ /* .conquestrc version not found */
#ifdef DEBUG_CONFIG
clog("GetConf(): Incorrect version found. - rebuilding");
#endif
MakeConf(conf_name); /* rebuild */
}
else
{ /* version found. check everything else */
for (i=0; i<CfEnd; i++)
{
if (ConfData[i].ConfType != CTYPE_NULL &&
ConfData[i].ConfType != CTYPE_MACRO )
if (ConfData[i].Found != TRUE)
{
#ifdef DEBUG_CONFIG
clog("GetConf(): option '%s' not found - rebuilding.",
ConfData[i].ConfName);
#endif
MakeConf(conf_name); /* rebuild - one not found */
break; /* no need to cont if we rebuilt */
}
}
}
return(TRUE);
}
/* SaveUserConfig(int unum) - do what the name implies ;-) */
int SaveUserConfig(void)
{
char conf_name[MID_BUFFER_SIZE];
char *homevar;
char home[HOME_BUFSZ];
/* start building the filename */
if ((homevar = getenv("HOME")) == NULL)
{
clog("SaveUserConfig(): getenv(HOME) failed");
fprintf(stderr, "SaveUserConfig(): Can't get HOME environment variable. Exiting\n");
return(ERR);
}
memset(home, 0, HOME_BUFSZ);
strncpy(home, homevar, HOME_BUFSZ - 1);
snprintf(conf_name, sizeof(conf_name)-1, "%s/%s", home, CONFIG_FILE);
#ifdef DEBUG_OPTIONS
clog("SaveUserConfig(): saving user config: conf_name = '%s'", conf_name);
#endif
return(MakeConf(conf_name));
}
/* SaveSysConfig() - do what the name implies ;-) */
int SaveSysConfig(void)
{
#ifdef DEBUG_OPTIONS
clog("SaveSysConfig(): saving system config");
#endif
return(MakeSysConf());
}
/* process a string value - converts it into a macro string */
char *Str2Macro(char *str)
{
static char retstr[BUFFER_SIZE];
char *s;
int i;
i = 0;
s = str;
retstr[0] = EOS;
while (*s && i < (BUFFER_SIZE - 1))
{
if (*s == '\\')
{
s++;
if (*s)
{
switch (*s)
{
case 'r':
retstr[i++] = '\r';
s++;
break;
case 't':
retstr[i++] = '\t';
s++;
break;
case 'n':
retstr[i++] = '\n';
s++;
break;
case '\\':
default:
retstr[i++] = '\\';
s++;
break;
}
}
}
else
{
retstr[i++] = *s;
s++;
}
}
retstr[i] = EOS;
return(retstr);
}
/* process a macro value - converts it back into a printable string */
char *Macro2Str(char *str)
{
static char retstr[BUFFER_SIZE];
char *s;
int i;
i = 0;
s = str;
retstr[0] = EOS;
#if defined(DEBUG_CONFIG)
if (str != NULL )
clog("Macro2Str('%s')", str);
else
clog("Macro2Str(NULL)");
#endif
while (*s && i < (BUFFER_SIZE - 1))
{
switch (*s)
{
case '\r':
retstr[i++] = '\\';
retstr[i++] = 'r';
s++;
break;
case '\t':
retstr[i++] = '\\';
retstr[i++] = 't';
s++;
break;
case '\n':
retstr[i++] = '\\';
retstr[i++] = 'n';
s++;
break;
case '\\':
retstr[i++] = '\\';
retstr[i++] = '\\';
s++;
break;
default:
retstr[i++] = *s;
s++;
break;
}
}
retstr[i] = EOS;
return(retstr);
}
/* process a boolean value */
int process_bool(char *bufptr)
{
lower(bufptr);
if ((strstr("false", bufptr) != NULL) ||
(strstr("no", bufptr) != NULL) ||
(strstr("off", bufptr) != NULL))
{
return(FALSE);
}
else if ((strstr("true", bufptr) != NULL) ||
(strstr("yes", bufptr) != NULL) ||
(strstr("on", bufptr) != NULL))
{
return(TRUE);
}
else
{
fprintf(stderr, "process_bool(): error parsing '%s', \n\t%s\n",
bufptr,
"Value must be yes or no or true or false.");
return(ERR);
}
}
/* MakeConf(filename) - make a fresh, spiffy new conquestrc file. */
int MakeConf(char *filename)
{
FILE *conf_fd;
int i, j, n;
/* a telnet client should never get here, but... */
if (telnetClient)
return TRUE;
unlink(filename);
if ((conf_fd = fopen(filename, "w")) == NULL)
{
clog("Makeconf(): fopen(%s) failed: %s",
filename,
strerror(errno));
fprintf(stderr, "Error creating %s: %s\n",
filename,
strerror(errno));
return(ERR);
}
for (j=0; j<CfEnd; j++)
{
/* option header first */
i = 0;
/* check for version - this won't be output in the loop below due to the
fact that CF_VERSION is of type CTYPE_NULL */
if (j == CF_VERSION)
{
fprintf(conf_fd, "%s%s\n",
ConfData[j].ConfName,
(char *)ConfData[j].ConfValue);
}
while (ConfData[j].ConfComment[i] != NULL)
fprintf(conf_fd, "%s\n", ConfData[j].ConfComment[i++]);
/* now write the variable and value if not a
CTYPE_NULL */
if (ConfData[j].ConfType != CTYPE_NULL)
switch (ConfData[j].ConfType)
{
case CTYPE_MACRO:
for (n=0; n < MAX_MACROS; n++)
{
if (strlen((char *)(((char *)ConfData[j].ConfValue)
+ (n * MAX_MACRO_LEN))) != 0)
{
fprintf(conf_fd, "%s%d=%s\n",
ConfData[j].ConfName,
n + 1,
Macro2Str((char *)(((char *)ConfData[j].ConfValue)
+ (n * MAX_MACRO_LEN))));
}
}
break;
case CTYPE_BOOL:
fprintf(conf_fd, "%s%s\n",
ConfData[j].ConfName,
(*((int *)ConfData[j].ConfValue) == TRUE) ? "true" : "false");
break;
case CTYPE_NUMERIC:
fprintf(conf_fd, "%s%d\n",
ConfData[j].ConfName,
*((int *)ConfData[j].ConfValue));
break;
}
/* output a blank line */
fprintf(conf_fd, "\n");
}
fclose(conf_fd);
#ifdef DEBUG_CONFIG
clog("MakeConf(%s): Succeeded.", filename);
#endif
/* that's it! */
return(TRUE);
}
/* MakeSysConf() - make a fresh, spiffy new sys-wide conquestrc file.*/
int MakeSysConf()
{
FILE *sysconf_fd;
char conf_name[BUFFER_SIZE];
int i, j, n;
snprintf(conf_name, sizeof(conf_name)-1, "%s/%s", CONQETC, SYSCONFIG_FILE);
umask(002);
unlink(conf_name);
if ((sysconf_fd = fopen(conf_name, "w")) == NULL)
{
clog("MakeSysconf(): fopen(%s) failed: %s",
conf_name,
strerror(errno));
fprintf(stderr, "Error creating %s: %s\n",
conf_name,
strerror(errno));
return(ERR);
}
clog("OPER: Updating %s file...", conf_name);
fprintf(stderr, "Updating %s file...", conf_name);
for (j=0; j<SysCfEnd; j++)
{
/* option header first */
i = 0;
/* check for version - this won't be output in the loop below due to the
fact that SYSCF_VERSION is of type CTYPE_NULL */
if (j == SYSCF_VERSION)
{
fprintf(sysconf_fd, "%s%s\n",
SysConfData[j].ConfName,
(char *)SysConfData[j].ConfValue);
}
while (SysConfData[j].ConfComment[i] != NULL)
fprintf(sysconf_fd, "%s\n", SysConfData[j].ConfComment[i++]);
/* now write the variable and value if not a
CTYPE_NULL*/
if (SysConfData[j].ConfType != CTYPE_NULL)
switch (SysConfData[j].ConfType)
{
case CTYPE_STRING:
fprintf(sysconf_fd, "%s%s\n",
SysConfData[j].ConfName,
(char *)SysConfData[j].ConfValue);
break;
case CTYPE_MACRO:
for (n=0; n < MAX_MACROS; n++)
{
if (strlen(((char **)SysConfData[j].ConfValue)[n]) != 0)
{
fprintf(sysconf_fd, "%s%d=%s\n",
SysConfData[j].ConfName,
n + 1,
Macro2Str(((char **)SysConfData[j].ConfValue)[n]));
}
}
break;
case CTYPE_BOOL:
fprintf(sysconf_fd, "%s%s\n",
SysConfData[j].ConfName,
(*((int *)SysConfData[j].ConfValue) == TRUE) ? "true" : "false");
break;
case CTYPE_NUMERIC:
fprintf(sysconf_fd, "%s%d\n",
SysConfData[j].ConfName,
*((int *)SysConfData[j].ConfValue));
break;
}
/* output a blank line */
fprintf(sysconf_fd, "\n");
}
fclose(sysconf_fd);
#ifdef DEBUG_CONFIG
clog("MakeSysConf(%s): Succeeded.", conf_name);
#endif
fprintf(stderr, "Done.\n");
/* that's it! */
return(TRUE);
}
Unsgn32 getServerFlags(void)
{
Unsgn32 f;
/* get the current flags */
f = SPSSTAT_FLAGS_NONE;
if (SysConf.AllowRefits)
f |= SPSSTAT_FLAGS_REFIT;
if (SysConf.AllowVacant)
f |= SPSSTAT_FLAGS_VACANT;
if (SysConf.AllowSlingShot)
f |= SPSSTAT_FLAGS_SLINGSHOT;
if (SysConf.NoDoomsday)
f |= SPSSTAT_FLAGS_NODOOMSDAY;
if (SysConf.DoRandomRobotKills)
f |= SPSSTAT_FLAGS_KILLBOTS;
if (SysConf.AllowSwitchteams)
f |= SPSSTAT_FLAGS_SWITCHTEAM;
return f;
}
|