mirror of
https://github.com/tbamud/tbamud.git
synced 2026-01-26 19:06:10 +01:00
Setting up 3.5.0 as trunk
This commit is contained in:
parent
0ddbd8b56e
commit
99e3aa4d8b
1336 changed files with 514917 additions and 0 deletions
79
src/util/Makefile
Normal file
79
src/util/Makefile
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
# Generated automatically from Makefile.in by configure.
|
||||
# CircleMUD Makefile.in - Makefile template used by 'configure'
|
||||
# for the 'util' directory
|
||||
|
||||
# C compiler to use
|
||||
CC = gcc
|
||||
|
||||
# Any special flags you want to pass to the compiler
|
||||
MYFLAGS = -Wall -DCIRCLE_UTIL
|
||||
|
||||
#flags for profiling (see hacker.doc for more information)
|
||||
PROFILE =
|
||||
|
||||
##############################################################################
|
||||
# Do Not Modify Anything Below This Line (unless you know what you're doing) #
|
||||
##############################################################################
|
||||
|
||||
# binary destination directory
|
||||
BINDIR = ../../bin
|
||||
# location of Circle include files
|
||||
INCDIR = ..
|
||||
|
||||
CFLAGS = -g -O2 $(MYFLAGS) $(PROFILE) -I$(INCDIR)
|
||||
|
||||
default: all
|
||||
|
||||
all: $(BINDIR)/asciipasswd $(BINDIR)/autowiz $(BINDIR)/listrent \
|
||||
$(BINDIR)/plrtoascii $(BINDIR)/shopconv $(BINDIR)/sign \
|
||||
$(BINDIR)/split $(BINDIR)/wld2html
|
||||
|
||||
asciipasswd: $(BINDIR)/asciipasswd
|
||||
|
||||
autowiz: $(BINDIR)/autowiz
|
||||
|
||||
listrent: $(BINDIR)/listrent
|
||||
|
||||
plrtoascii: $(BINDIR)/plrtoascii
|
||||
|
||||
shopconv: $(BINDIR)/shopconv
|
||||
|
||||
sign: $(BINDIR)/sign
|
||||
|
||||
split: $(BINDIR)/split
|
||||
|
||||
wld2html: $(BINDIR)/wld2html
|
||||
|
||||
webster: $(BINDIR)/webster
|
||||
|
||||
$(BINDIR)/asciipasswd: asciipasswd.c $(INCDIR)/conf.h $(INCDIR)/sysdep.h \
|
||||
$(INCDIR)/structs.h $(INCDIR)/utils.h
|
||||
$(CC) $(CFLAGS) -o $(BINDIR)/asciipasswd asciipasswd.c -lcrypt
|
||||
|
||||
$(BINDIR)/autowiz: autowiz.c $(INCDIR)/conf.h $(INCDIR)/sysdep.h \
|
||||
$(INCDIR)/structs.h $(INCDIR)/utils.h $(INCDIR)/db.h
|
||||
$(CC) $(CFLAGS) -o $(BINDIR)/autowiz autowiz.c
|
||||
|
||||
$(BINDIR)/listrent: listrent.c $(INCDIR)/conf.h $(INCDIR)/sysdep.h \
|
||||
$(INCDIR)/structs.h
|
||||
$(CC) $(CFLAGS) -o $(BINDIR)/listrent listrent.c
|
||||
|
||||
$(BINDIR)/plrtoascii: plrtoascii.c $(INCDIR)/conf.h $(INCDIR)/sysdep.h \
|
||||
$(INCDIR)/db.h $(INCDIR)/pfdefaults.h
|
||||
$(CC) $(CFLAGS) -o $(BINDIR)/plrtoascii plrtoascii.c
|
||||
|
||||
$(BINDIR)/shopconv: shopconv.c $(INCDIR)/conf.h $(INCDIR)/sysdep.h \
|
||||
$(INCDIR)/structs.h $(INCDIR)/db.h $(INCDIR)/utils.h $(INCDIR)/shop.h
|
||||
$(CC) $(CFLAGS) -o $(BINDIR)/shopconv shopconv.c
|
||||
|
||||
$(BINDIR)/sign: sign.c $(INCDIR)/conf.h $(INCDIR)/sysdep.h
|
||||
$(CC) $(CFLAGS) -o $(BINDIR)/sign sign.c
|
||||
|
||||
$(BINDIR)/split: split.c $(INCDIR)/conf.h $(INCDIR)/sysdep.h
|
||||
$(CC) $(CFLAGS) -o $(BINDIR)/split split.c
|
||||
|
||||
$(BINDIR)/wld2html: wld2html.c $(INCDIR)/conf.h $(INCDIR)/sysdep.h
|
||||
$(CC) $(CFLAGS) -o $(BINDIR)/wld2html wld2html.c
|
||||
|
||||
$(BINDIR)/webster: webster.c $(INCDIR)/conf.h $(INCDIR)/sysdep.h
|
||||
$(CC) $(CFLAGS) -o $(BINDIR)/webster webster.c
|
||||
78
src/util/Makefile.in
Executable file
78
src/util/Makefile.in
Executable file
|
|
@ -0,0 +1,78 @@
|
|||
# CircleMUD Makefile.in - Makefile template used by 'configure'
|
||||
# for the 'util' directory
|
||||
|
||||
# C compiler to use
|
||||
CC = @CC@
|
||||
|
||||
# Any special flags you want to pass to the compiler
|
||||
MYFLAGS = @MYFLAGS@ -DCIRCLE_UTIL
|
||||
|
||||
#flags for profiling (see hacker.doc for more information)
|
||||
PROFILE =
|
||||
|
||||
##############################################################################
|
||||
# Do Not Modify Anything Below This Line (unless you know what you're doing) #
|
||||
##############################################################################
|
||||
|
||||
# binary destination directory
|
||||
BINDIR = ../../bin
|
||||
# location of Circle include files
|
||||
INCDIR = ..
|
||||
|
||||
CFLAGS = @CFLAGS@ $(MYFLAGS) $(PROFILE) -I$(INCDIR)
|
||||
|
||||
default: all
|
||||
|
||||
all: $(BINDIR)/asciipasswd $(BINDIR)/autowiz $(BINDIR)/listrent \
|
||||
$(BINDIR)/plrtoascii $(BINDIR)/shopconv $(BINDIR)/sign \
|
||||
$(BINDIR)/split $(BINDIR)/wld2html
|
||||
|
||||
asciipasswd: $(BINDIR)/asciipasswd
|
||||
|
||||
autowiz: $(BINDIR)/autowiz
|
||||
|
||||
listrent: $(BINDIR)/listrent
|
||||
|
||||
plrtoascii: $(BINDIR)/plrtoascii
|
||||
|
||||
shopconv: $(BINDIR)/shopconv
|
||||
|
||||
sign: $(BINDIR)/sign
|
||||
|
||||
split: $(BINDIR)/split
|
||||
|
||||
wld2html: $(BINDIR)/wld2html
|
||||
|
||||
webster: $(BINDIR)/webster
|
||||
|
||||
$(BINDIR)/asciipasswd: asciipasswd.c $(INCDIR)/conf.h $(INCDIR)/sysdep.h \
|
||||
$(INCDIR)/structs.h $(INCDIR)/utils.h
|
||||
$(CC) $(CFLAGS) -o $(BINDIR)/asciipasswd asciipasswd.c @CRYPTLIB@
|
||||
|
||||
$(BINDIR)/autowiz: autowiz.c $(INCDIR)/conf.h $(INCDIR)/sysdep.h \
|
||||
$(INCDIR)/structs.h $(INCDIR)/utils.h $(INCDIR)/db.h
|
||||
$(CC) $(CFLAGS) -o $(BINDIR)/autowiz autowiz.c
|
||||
|
||||
$(BINDIR)/listrent: listrent.c $(INCDIR)/conf.h $(INCDIR)/sysdep.h \
|
||||
$(INCDIR)/structs.h
|
||||
$(CC) $(CFLAGS) -o $(BINDIR)/listrent listrent.c
|
||||
|
||||
$(BINDIR)/plrtoascii: plrtoascii.c $(INCDIR)/conf.h $(INCDIR)/sysdep.h \
|
||||
$(INCDIR)/db.h $(INCDIR)/pfdefaults.h
|
||||
$(CC) $(CFLAGS) -o $(BINDIR)/plrtoascii plrtoascii.c
|
||||
|
||||
$(BINDIR)/shopconv: shopconv.c $(INCDIR)/conf.h $(INCDIR)/sysdep.h \
|
||||
$(INCDIR)/structs.h $(INCDIR)/db.h $(INCDIR)/utils.h $(INCDIR)/shop.h
|
||||
$(CC) $(CFLAGS) -o $(BINDIR)/shopconv shopconv.c
|
||||
|
||||
$(BINDIR)/sign: sign.c $(INCDIR)/conf.h $(INCDIR)/sysdep.h
|
||||
$(CC) $(CFLAGS) -o $(BINDIR)/sign sign.c @NETLIB@
|
||||
|
||||
$(BINDIR)/split: split.c $(INCDIR)/conf.h $(INCDIR)/sysdep.h
|
||||
$(CC) $(CFLAGS) -o $(BINDIR)/split split.c
|
||||
|
||||
$(BINDIR)/wld2html: wld2html.c $(INCDIR)/conf.h $(INCDIR)/sysdep.h
|
||||
$(CC) $(CFLAGS) -o $(BINDIR)/wld2html wld2html.c
|
||||
|
||||
$(BINDIR)/webster: webster.c $(INCDIR)/conf.h $(INCDIR)/sysdep.h
|
||||
$(CC) $(CFLAGS) -o $(BINDIR)/webster webster.c
|
||||
28
src/util/asciipasswd.c
Executable file
28
src/util/asciipasswd.c
Executable file
|
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************
|
||||
* file: asciipasswd.c (derived from mudpasswd.c) Part of CircleMud *
|
||||
* Usage: generating hashed passwords for an ascii playerfile *
|
||||
* Copyright (C) 1990, 1991 - see 'license.doc' for complete information. *
|
||||
* All Rights Reserved *
|
||||
************************************************************************* */
|
||||
|
||||
|
||||
#include "conf.h"
|
||||
#include "sysdep.h"
|
||||
|
||||
#include "structs.h"
|
||||
#include "utils.h"
|
||||
|
||||
|
||||
char *CAP(char *txt) {
|
||||
*txt = UPPER(*txt);
|
||||
return (txt);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (argc != 3)
|
||||
fprintf(stderr, "Usage: %s name password\n", argv[0]);
|
||||
else
|
||||
printf("Name: %s\nPass: %s\n", CAP(argv[1]), CRYPT(argv[2], CAP(argv[1])));
|
||||
return (0);
|
||||
}
|
||||
|
||||
327
src/util/autowiz.c
Executable file
327
src/util/autowiz.c
Executable file
|
|
@ -0,0 +1,327 @@
|
|||
/* ************************************************************************
|
||||
* file: autowiz.c Part of CircleMUD *
|
||||
* Usage: self-updating wizlists *
|
||||
* Written by Jeremy Elson *
|
||||
* All Rights Reserved *
|
||||
* Copyright (C) 1993 The Trustees of The Johns Hopkins University *
|
||||
************************************************************************* */
|
||||
|
||||
|
||||
/*
|
||||
WARNING: THIS CODE IS A HACK. WE CAN NOT AND WILL NOT BE RESPONSIBLE
|
||||
FOR ANY NASUEA, DIZZINESS, VOMITING, OR SHORTNESS OF BREATH RESULTING
|
||||
FROM READING THIS CODE. PREGNANT WOMEN AND INDIVIDUALS WITH BACK
|
||||
INJURIES, HEART CONDITIONS, OR ARE UNDER THE CARE OF A PHYSICIAN SHOULD
|
||||
NOT READ THIS CODE.
|
||||
|
||||
-- The Management
|
||||
*/
|
||||
|
||||
#include "conf.h"
|
||||
#include "sysdep.h"
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#include "structs.h"
|
||||
#include "utils.h"
|
||||
#include "db.h"
|
||||
|
||||
#define IMM_LMARG " "
|
||||
#define IMM_NSIZE 16
|
||||
#define LINE_LEN 64
|
||||
#define MIN_LEVEL LVL_IMMORT
|
||||
|
||||
/* max level that should be in columns instead of centered */
|
||||
#define COL_LEVEL LVL_IMMORT
|
||||
|
||||
struct name_rec {
|
||||
char name[25];
|
||||
struct name_rec *next;
|
||||
};
|
||||
|
||||
struct control_rec {
|
||||
int level;
|
||||
char *level_name;
|
||||
};
|
||||
|
||||
struct level_rec {
|
||||
struct control_rec *params;
|
||||
struct level_rec *next;
|
||||
struct name_rec *names;
|
||||
};
|
||||
|
||||
struct control_rec level_params[] =
|
||||
{
|
||||
{LVL_IMMORT, "Immortals"},
|
||||
{LVL_GOD, "Gods"},
|
||||
{LVL_GRGOD, "Greater Gods"},
|
||||
{LVL_IMPL, "Implementors"},
|
||||
{0, ""}
|
||||
};
|
||||
|
||||
|
||||
struct level_rec *levels = 0;
|
||||
|
||||
void initialize(void)
|
||||
{
|
||||
struct level_rec *tmp;
|
||||
int i = 0;
|
||||
|
||||
while (level_params[i].level > 0) {
|
||||
tmp = (struct level_rec *) malloc(sizeof(struct level_rec));
|
||||
tmp->names = 0;
|
||||
tmp->params = &(level_params[i++]);
|
||||
tmp->next = levels;
|
||||
levels = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void read_file(void)
|
||||
{
|
||||
void add_name(byte level, char *name);
|
||||
char *CAP(char *txt);
|
||||
int get_line(FILE * fl, char *buf);
|
||||
bitvector_t asciiflag_conv(char *flag);
|
||||
|
||||
FILE *fl;
|
||||
int recs, i, last = 0, level = 0, flags = 0;
|
||||
char index_name[40], line[256], bits[64];
|
||||
char name[MAX_NAME_LENGTH];
|
||||
long id = 0;
|
||||
|
||||
sprintf(index_name, "%s%s", LIB_PLRFILES, INDEX_FILE);
|
||||
if (!(fl = fopen(index_name, "r"))) {
|
||||
perror("Error opening playerfile");
|
||||
exit(1);
|
||||
}
|
||||
/* count the number of players in the index */
|
||||
recs = 0;
|
||||
while (get_line(fl, line))
|
||||
if (*line != '~')
|
||||
recs++;
|
||||
rewind(fl);
|
||||
|
||||
for (i = 0; i < recs; i++) {
|
||||
get_line(fl, line);
|
||||
sscanf(line, "%ld %s %d %s %d", &id, name, &level, bits, &last);
|
||||
CAP(name);
|
||||
flags = asciiflag_conv(bits);
|
||||
if (level >= MIN_LEVEL &&
|
||||
!(IS_SET(flags, PINDEX_NOWIZLIST)) &&
|
||||
!(IS_SET(flags, PINDEX_DELETED)))
|
||||
add_name(level, name);
|
||||
}
|
||||
|
||||
fclose(fl);
|
||||
}
|
||||
|
||||
|
||||
void add_name(byte level, char *name)
|
||||
{
|
||||
struct name_rec *tmp;
|
||||
struct level_rec *curr_level;
|
||||
char *ptr;
|
||||
|
||||
if (!*name)
|
||||
return;
|
||||
|
||||
for (ptr = name; *ptr; ptr++)
|
||||
if (!isalpha(*ptr))
|
||||
return;
|
||||
|
||||
tmp = (struct name_rec *) malloc(sizeof(struct name_rec));
|
||||
strcpy(tmp->name, name);
|
||||
tmp->next = 0;
|
||||
|
||||
curr_level = levels;
|
||||
while (curr_level->params->level > level)
|
||||
curr_level = curr_level->next;
|
||||
|
||||
tmp->next = curr_level->names;
|
||||
curr_level->names = tmp;
|
||||
}
|
||||
|
||||
|
||||
void sort_names(void)
|
||||
{
|
||||
struct level_rec *curr_level;
|
||||
struct name_rec *a, *b;
|
||||
char temp[100];
|
||||
|
||||
for (curr_level = levels; curr_level; curr_level = curr_level->next) {
|
||||
for (a = curr_level->names; a && a->next; a = a->next) {
|
||||
for (b = a->next; b; b = b->next) {
|
||||
if (strcmp(a->name, b->name) > 0) {
|
||||
strcpy(temp, a->name);
|
||||
strcpy(a->name, b->name);
|
||||
strcpy(b->name, temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void write_wizlist(FILE * out, int minlev, int maxlev)
|
||||
{
|
||||
char buf[100];
|
||||
struct level_rec *curr_level;
|
||||
struct name_rec *curr_name;
|
||||
int i, j;
|
||||
|
||||
fprintf(out,
|
||||
"*************************************************************************\n"
|
||||
"* The following people have reached immortality on CircleMUD. They are *\n"
|
||||
"* to be treated with respect and awe. Occasional prayers to them are *\n"
|
||||
"* advisable. Annoying them is not recommended. Stealing from them is *\n"
|
||||
"* punishable by immediate death. *\n"
|
||||
"*************************************************************************\n\n");
|
||||
|
||||
for (curr_level = levels; curr_level; curr_level = curr_level->next) {
|
||||
if (curr_level->params->level < minlev ||
|
||||
curr_level->params->level > maxlev)
|
||||
continue;
|
||||
i = 39 - (strlen(curr_level->params->level_name) >> 1);
|
||||
for (j = 1; j <= i; j++)
|
||||
fputc(' ', out);
|
||||
fprintf(out, "%s\n", curr_level->params->level_name);
|
||||
for (j = 1; j <= i; j++)
|
||||
fputc(' ', out);
|
||||
for (j = 1; j <= strlen(curr_level->params->level_name); j++)
|
||||
fputc('~', out);
|
||||
fprintf(out, "\n");
|
||||
|
||||
strcpy(buf, "");
|
||||
curr_name = curr_level->names;
|
||||
while (curr_name) {
|
||||
strcat(buf, curr_name->name);
|
||||
if (strlen(buf) > LINE_LEN) {
|
||||
if (curr_level->params->level <= COL_LEVEL)
|
||||
fprintf(out, IMM_LMARG);
|
||||
else {
|
||||
i = 40 - (strlen(buf) >> 1);
|
||||
for (j = 1; j <= i; j++)
|
||||
fputc(' ', out);
|
||||
}
|
||||
fprintf(out, "%s\n", buf);
|
||||
strcpy(buf, "");
|
||||
} else {
|
||||
if (curr_level->params->level <= COL_LEVEL) {
|
||||
for (j = 1; j <= (IMM_NSIZE - strlen(curr_name->name)); j++)
|
||||
strcat(buf, " ");
|
||||
}
|
||||
if (curr_level->params->level > COL_LEVEL)
|
||||
strcat(buf, " ");
|
||||
}
|
||||
curr_name = curr_name->next;
|
||||
}
|
||||
|
||||
if (*buf) {
|
||||
if (curr_level->params->level <= COL_LEVEL)
|
||||
fprintf(out, "%s%s\n", IMM_LMARG, buf);
|
||||
else {
|
||||
i = 40 - (strlen(buf) >> 1);
|
||||
for (j = 1; j <= i; j++)
|
||||
fputc(' ', out);
|
||||
fprintf(out, "%s\n", buf);
|
||||
}
|
||||
}
|
||||
fprintf(out, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int wizlevel, immlevel, pid = 0;
|
||||
FILE *fl;
|
||||
|
||||
if (argc != 5 && argc != 6) {
|
||||
printf("Format: %s wizlev wizlistfile immlev immlistfile [pid to signal]\n",
|
||||
argv[0]);
|
||||
exit(0);
|
||||
}
|
||||
wizlevel = atoi(argv[1]);
|
||||
immlevel = atoi(argv[3]);
|
||||
|
||||
#ifdef CIRCLE_UNIX /* Perhaps #ifndef CIRCLE_WINDOWS but ... */
|
||||
if (argc == 6)
|
||||
pid = atoi(argv[5]);
|
||||
#endif
|
||||
|
||||
initialize();
|
||||
read_file();
|
||||
sort_names();
|
||||
|
||||
fl = fopen(argv[2], "w");
|
||||
write_wizlist(fl, wizlevel, LVL_IMPL);
|
||||
fclose(fl);
|
||||
|
||||
fl = fopen(argv[4], "w");
|
||||
write_wizlist(fl, immlevel, wizlevel - 1);
|
||||
fclose(fl);
|
||||
|
||||
#ifdef CIRCLE_UNIX /* ... I don't have the platforms to test. */
|
||||
if (pid)
|
||||
kill(pid, SIGUSR1);
|
||||
#endif
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
char *CAP(char *txt)
|
||||
{
|
||||
*txt = UPPER(*txt);
|
||||
return (txt);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* get_line reads the next non-blank line off of the input stream.
|
||||
* The newline character is removed from the input. Lines which begin
|
||||
* with '*' are considered to be comments.
|
||||
*
|
||||
* Returns the number of lines advanced in the file.
|
||||
*/
|
||||
int get_line(FILE * fl, char *buf)
|
||||
{
|
||||
char temp[256];
|
||||
int lines = 0;
|
||||
|
||||
do {
|
||||
fgets(temp, 256, fl);
|
||||
if (feof(fl))
|
||||
return (0);
|
||||
lines++;
|
||||
} while (*temp == '*' || *temp == '\n');
|
||||
|
||||
temp[strlen(temp) - 1] = '\0';
|
||||
strcpy(buf, temp);
|
||||
return (lines);
|
||||
}
|
||||
|
||||
|
||||
bitvector_t asciiflag_conv(char *flag)
|
||||
{
|
||||
bitvector_t flags = 0;
|
||||
int is_number = 1;
|
||||
register char *p;
|
||||
|
||||
for (p = flag; *p; p++) {
|
||||
if (islower(*p))
|
||||
flags |= 1 << (*p - 'a');
|
||||
else if (isupper(*p))
|
||||
flags |= 1 << (26 + (*p - 'A'));
|
||||
|
||||
if (!isdigit(*p))
|
||||
is_number = 0;
|
||||
}
|
||||
|
||||
if (is_number)
|
||||
flags = atol(flag);
|
||||
|
||||
return (flags);
|
||||
}
|
||||
71
src/util/listrent.c
Executable file
71
src/util/listrent.c
Executable file
|
|
@ -0,0 +1,71 @@
|
|||
/* ************************************************************************
|
||||
* file: listrent.c Part of CircleMUD *
|
||||
* Usage: list player rent files *
|
||||
* Written by Jeremy Elson *
|
||||
* All Rights Reserved *
|
||||
* Copyright (C) 1993 The Trustees of The Johns Hopkins University *
|
||||
************************************************************************* */
|
||||
|
||||
#include "conf.h"
|
||||
#include "sysdep.h"
|
||||
|
||||
#include "structs.h"
|
||||
|
||||
void Crash_listrent(char *fname);
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int x;
|
||||
|
||||
for (x = 1; x < argc; x++)
|
||||
Crash_listrent(argv[x]);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
void Crash_listrent(char *fname)
|
||||
{
|
||||
FILE *fl;
|
||||
char buf[MAX_STRING_LENGTH];
|
||||
struct obj_file_elem object;
|
||||
struct rent_info rent;
|
||||
|
||||
if (!(fl = fopen(fname, "rb"))) {
|
||||
sprintf(buf, "%s has no rent file.\r\n", fname);
|
||||
printf("%s", buf);
|
||||
return;
|
||||
}
|
||||
sprintf(buf, "%s\r\n", fname);
|
||||
if (!feof(fl))
|
||||
fread(&rent, sizeof(struct rent_info), 1, fl);
|
||||
switch (rent.rentcode) {
|
||||
case RENT_RENTED:
|
||||
strcat(buf, "Rent\r\n");
|
||||
break;
|
||||
case RENT_CRASH:
|
||||
strcat(buf, "Crash\r\n");
|
||||
break;
|
||||
case RENT_CRYO:
|
||||
strcat(buf, "Cryo\r\n");
|
||||
break;
|
||||
case RENT_TIMEDOUT:
|
||||
case RENT_FORCED:
|
||||
strcat(buf, "TimedOut\r\n");
|
||||
break;
|
||||
default:
|
||||
strcat(buf, "Undef\r\n");
|
||||
break;
|
||||
}
|
||||
while (!feof(fl)) {
|
||||
fread(&object, sizeof(struct obj_file_elem), 1, fl);
|
||||
if (ferror(fl)) {
|
||||
fclose(fl);
|
||||
return;
|
||||
}
|
||||
if (!feof(fl))
|
||||
sprintf(buf, "%s[%5d] %s\n", buf, object.item_number, fname);
|
||||
}
|
||||
printf("%s", buf);
|
||||
fclose(fl);
|
||||
}
|
||||
260
src/util/plrtoascii.c
Executable file
260
src/util/plrtoascii.c
Executable file
|
|
@ -0,0 +1,260 @@
|
|||
/* ************************************************************************
|
||||
* file: plrtoascii.c Part of CircleMud *
|
||||
* Copyright (C) 1990, 1991 - see 'license.doc' for complete information. *
|
||||
* All Rights Reserved *
|
||||
************************************************************************* */
|
||||
|
||||
#include "../conf.h"
|
||||
#include "../sysdep.h"
|
||||
|
||||
#include "../structs.h"
|
||||
#include "../utils.h"
|
||||
#include "../db.h"
|
||||
#include "../pfdefaults.h"
|
||||
|
||||
int sprintascii(char *out, bitvector_t bits);
|
||||
int plr_filename(char *orig_name, char *filename);
|
||||
|
||||
void convert(char *filename)
|
||||
{
|
||||
FILE *fl, *outfile, *index_file;
|
||||
struct char_file_u player;
|
||||
char index_name[40], outname[40], bits[127];
|
||||
int i;
|
||||
struct char_special_data_saved *csds;
|
||||
struct player_special_data_saved *psds;
|
||||
struct char_ability_data *cad;
|
||||
struct char_point_data *cpd;
|
||||
struct affected_type *aff;
|
||||
|
||||
if (!(fl = fopen(filename, "r+"))) {
|
||||
perror("error opening playerfile");
|
||||
exit(1);
|
||||
}
|
||||
sprintf(index_name, "%s%s", LIB_PLRFILES, INDEX_FILE);
|
||||
if (!(index_file = fopen(index_name, "w"))) {
|
||||
perror("error opening index file");
|
||||
exit(1);
|
||||
}
|
||||
for (;;) {
|
||||
fread(&player, sizeof(struct char_file_u), 1, fl);
|
||||
if (feof(fl)) {
|
||||
fclose(fl);
|
||||
fclose(index_file);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!plr_filename(player.name, outname))
|
||||
exit(1);
|
||||
printf("writing: %s\n", outname);
|
||||
|
||||
fprintf(index_file, "%ld %s %d 0 %ld\n",
|
||||
player.char_specials_saved.idnum, bits, player.level,
|
||||
player.last_logon);
|
||||
|
||||
if (!(outfile = fopen(outname, "w"))) {
|
||||
printf("error opening output file");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* char_file_u */
|
||||
if (player.name)
|
||||
fprintf(outfile, "Name: %s\n", player.name);
|
||||
if (player.pwd)
|
||||
fprintf(outfile, "Pass: %s\n", player.pwd);
|
||||
if (player.title)
|
||||
fprintf(outfile, "Titl: %s\n", player.title);
|
||||
if (player.description && *player.description)
|
||||
fprintf(outfile, "Desc:\n%s~\n", player.description);
|
||||
if (player.sex != PFDEF_SEX)
|
||||
fprintf(outfile, "Sex : %d\n", (int)player.sex);
|
||||
if (player.chclass != PFDEF_CLASS)
|
||||
fprintf(outfile, "Clas: %d\n", (int)player.chclass);
|
||||
if (player.level != PFDEF_LEVEL)
|
||||
fprintf(outfile, "Levl: %d\n", (int)player.level);
|
||||
if (player.hometown != PFDEF_HOMETOWN)
|
||||
fprintf(outfile, "Home: %d\n", (int)player.hometown);
|
||||
fprintf(outfile, "Brth: %d\n", (int)player.birth);
|
||||
fprintf(outfile, "Plyd: %d\n", (int)player.played);
|
||||
fprintf(outfile, "Last: %d\n", (int)player.last_logon);
|
||||
fprintf(outfile, "Host: %s\n", player.host);
|
||||
if (player.height != PFDEF_HEIGHT)
|
||||
fprintf(outfile, "Hite: %d\n", (int)player.height);
|
||||
if (player.weight != PFDEF_WEIGHT)
|
||||
fprintf(outfile, "Wate: %d\n", (int)player.weight);
|
||||
|
||||
/* char_special_data_saved */
|
||||
csds = &(player.char_specials_saved);
|
||||
if (csds->alignment != PFDEF_ALIGNMENT)
|
||||
fprintf(outfile, "Alin: %d\n", csds->alignment);
|
||||
fprintf(outfile, "Id : %d\n", (int)csds->idnum);
|
||||
if (csds->act != PFDEF_PLRFLAGS)
|
||||
fprintf(outfile, "Act : %d\n", (int)csds->act);
|
||||
if (csds->affected_by != PFDEF_AFFFLAGS) {
|
||||
sprintascii(bits, csds->affected_by);
|
||||
fprintf(outfile, "Aff : %s\n", bits);
|
||||
}
|
||||
if (csds->apply_saving_throw[0] != PFDEF_SAVETHROW)
|
||||
fprintf(outfile, "Thr1: %d\n", csds->apply_saving_throw[0]);
|
||||
if (csds->apply_saving_throw[1] != PFDEF_SAVETHROW)
|
||||
fprintf(outfile, "Thr2: %d\n", csds->apply_saving_throw[1]);
|
||||
if (csds->apply_saving_throw[2] != PFDEF_SAVETHROW)
|
||||
fprintf(outfile, "Thr3: %d\n", csds->apply_saving_throw[2]);
|
||||
if (csds->apply_saving_throw[3] != PFDEF_SAVETHROW)
|
||||
fprintf(outfile, "Thr4: %d\n", csds->apply_saving_throw[3]);
|
||||
if (csds->apply_saving_throw[4] != PFDEF_SAVETHROW)
|
||||
fprintf(outfile, "Thr5: %d\n", csds->apply_saving_throw[4]);
|
||||
|
||||
/* player_special_data_saved */
|
||||
psds = &(player.player_specials_saved);
|
||||
if (player.level < LVL_IMMORT) {
|
||||
fprintf(outfile, "Skil:\n");
|
||||
for (i = 1; i <= MAX_SKILLS; i++) {
|
||||
if (psds->skills[i])
|
||||
fprintf(outfile, "%d %d\n", i, (int)psds->skills[i]);
|
||||
}
|
||||
fprintf(outfile, "0 0\n");
|
||||
}
|
||||
if (psds->wimp_level != PFDEF_WIMPLEV)
|
||||
fprintf(outfile, "Wimp: %d\n", psds->wimp_level);
|
||||
if (psds->freeze_level != PFDEF_FREEZELEV)
|
||||
fprintf(outfile, "Frez: %d\n", (int)psds->freeze_level);
|
||||
if (psds->invis_level != PFDEF_INVISLEV)
|
||||
fprintf(outfile, "Invs: %d\n", (int)psds->invis_level);
|
||||
if (psds->load_room != PFDEF_LOADROOM)
|
||||
fprintf(outfile, "Room: %d\n", (int)psds->load_room);
|
||||
if (psds->pref != PFDEF_PREFFLAGS) {
|
||||
sprintascii(bits, psds->pref);
|
||||
fprintf(outfile, "Pref: %s\n", bits);
|
||||
}
|
||||
if (psds->conditions[FULL] && player.level < LVL_IMMORT &&
|
||||
psds->conditions[FULL] != PFDEF_HUNGER)
|
||||
fprintf(outfile, "Hung: %d\n", (int)psds->conditions[0]);
|
||||
if (psds->conditions[THIRST] && player.level < LVL_IMMORT &&
|
||||
psds->conditions[THIRST] != PFDEF_THIRST)
|
||||
fprintf(outfile, "Thir: %d\n", (int)psds->conditions[1]);
|
||||
if (psds->conditions[2] && player.level < LVL_IMMORT &&
|
||||
psds->conditions[DRUNK] != PFDEF_DRUNK)
|
||||
fprintf(outfile, "Drnk: %d\n", (int)psds->conditions[2]);
|
||||
if (psds->spells_to_learn != PFDEF_PRACTICES)
|
||||
fprintf(outfile, "Lern: %d\n", (int)psds->spells_to_learn);
|
||||
|
||||
/* char_ability_data */
|
||||
cad = &(player.abilities);
|
||||
if (cad->str != PFDEF_STR || cad->str_add != PFDEF_STRADD)
|
||||
fprintf(outfile, "Str : %d/%d\n", cad->str, cad->str_add);
|
||||
if (cad->intel != PFDEF_INT)
|
||||
fprintf(outfile, "Int : %d\n", cad->intel);
|
||||
if (cad->wis != PFDEF_WIS)
|
||||
fprintf(outfile, "Wis : %d\n", cad->wis);
|
||||
if (cad->dex != PFDEF_DEX)
|
||||
fprintf(outfile, "Dex : %d\n", cad->dex);
|
||||
if (cad->con != PFDEF_CON)
|
||||
fprintf(outfile, "Con : %d\n", cad->con);
|
||||
if (cad->cha != PFDEF_CHA)
|
||||
fprintf(outfile, "Cha : %d\n", cad->cha);
|
||||
|
||||
/* char_point_data */
|
||||
cpd = &(player.points);
|
||||
if (cpd->hit != PFDEF_HIT || cpd->max_hit != PFDEF_MAXHIT)
|
||||
fprintf(outfile, "Hit : %d/%d\n", cpd->hit, cpd->max_hit);
|
||||
if (cpd->mana != PFDEF_MANA || cpd->max_mana != PFDEF_MAXMANA)
|
||||
fprintf(outfile, "Mana: %d/%d\n", cpd->mana, cpd->max_mana);
|
||||
if (cpd->move != PFDEF_MOVE || cpd->max_move != PFDEF_MAXMOVE)
|
||||
fprintf(outfile, "Move: %d/%d\n", cpd->move, cpd->max_move);
|
||||
if (cpd->armor != PFDEF_AC)
|
||||
fprintf(outfile, "Ac : %d\n", cpd->armor);
|
||||
if (cpd->gold != PFDEF_GOLD)
|
||||
fprintf(outfile, "Gold: %d\n", cpd->gold);
|
||||
if (cpd->bank_gold != PFDEF_BANK)
|
||||
fprintf(outfile, "Bank: %d\n", cpd->bank_gold);
|
||||
if (cpd->exp != PFDEF_EXP)
|
||||
fprintf(outfile, "Exp : %d\n", cpd->exp);
|
||||
if (cpd->hitroll != PFDEF_HITROLL)
|
||||
fprintf(outfile, "Hrol: %d\n", cpd->hitroll);
|
||||
if (cpd->damroll != PFDEF_DAMROLL)
|
||||
fprintf(outfile, "Drol: %d\n", cpd->damroll);
|
||||
|
||||
/* affected_type */
|
||||
fprintf(outfile, "Affs:\n");
|
||||
for (i = 0; i < MAX_AFFECT; i++) {
|
||||
aff = &(player.affected[i]);
|
||||
if (aff->type)
|
||||
fprintf(outfile, "%d %d %d %d %d\n", aff->type, aff->duration,
|
||||
aff->modifier, aff->location, (int)aff->bitvector);
|
||||
}
|
||||
fprintf(outfile, "0 0 0 0 0\n");
|
||||
|
||||
fclose(outfile);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc != 2)
|
||||
printf("Usage: %s playerfile-name\n", argv[0]);
|
||||
else
|
||||
convert(argv[1]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int sprintascii(char *out, bitvector_t bits)
|
||||
{
|
||||
int i, j = 0;
|
||||
/* 32 bits, don't just add letters to try to get more unless your bitvector_t is also as large. */
|
||||
char *flags = "abcdefghijklmnopqrstuvwxyzABCDEF";
|
||||
|
||||
for (i = 0; flags[i] != '\0'; i++)
|
||||
if (bits & (1 << i))
|
||||
out[j++] = flags[i];
|
||||
|
||||
if (j == 0) /* Didn't write anything. */
|
||||
out[j++] = '0';
|
||||
|
||||
/* NUL terminate the output string. */
|
||||
out[j++] = '\0';
|
||||
return j;
|
||||
}
|
||||
|
||||
|
||||
int plr_filename(char *orig_name, char *filename)
|
||||
{
|
||||
const char *middle;
|
||||
char name[64], *ptr;
|
||||
|
||||
if (orig_name == NULL || *orig_name == '\0' || filename == NULL) {
|
||||
perror("error getting player file name");
|
||||
return (0);
|
||||
}
|
||||
|
||||
strcpy(name, orig_name);
|
||||
for (ptr = name; *ptr; ptr++)
|
||||
*ptr = LOWER(*ptr);
|
||||
|
||||
switch (LOWER(*name)) {
|
||||
case 'a': case 'b': case 'c': case 'd': case 'e':
|
||||
middle = "A-E";
|
||||
break;
|
||||
case 'f': case 'g': case 'h': case 'i': case 'j':
|
||||
middle = "F-J";
|
||||
break;
|
||||
case 'k': case 'l': case 'm': case 'n': case 'o':
|
||||
middle = "K-O";
|
||||
break;
|
||||
case 'p': case 'q': case 'r': case 's': case 't':
|
||||
middle = "P-T";
|
||||
break;
|
||||
case 'u': case 'v': case 'w': case 'x': case 'y': case 'z':
|
||||
middle = "U-Z";
|
||||
break;
|
||||
default:
|
||||
middle = "ZZZ";
|
||||
break;
|
||||
}
|
||||
|
||||
sprintf(filename, "%s%s"SLASH"%s.%s", LIB_PLRFILES, middle, name, SUF_PLR);
|
||||
return (1);
|
||||
}
|
||||
3
src/util/scheck
Executable file
3
src/util/scheck
Executable file
|
|
@ -0,0 +1,3 @@
|
|||
scheck (the syntax checker) no longer exists as an independent utility.
|
||||
If you want to check the syntax of the world files, just use the -c
|
||||
switch on the main server.
|
||||
190
src/util/shopconv.c
Executable file
190
src/util/shopconv.c
Executable file
|
|
@ -0,0 +1,190 @@
|
|||
/* code to convert 2.20 shop files to 3.0 shop files - written by Jeff Fink */
|
||||
|
||||
#include "conf.h"
|
||||
#include "sysdep.h"
|
||||
|
||||
#include "structs.h"
|
||||
#include "db.h"
|
||||
#include "utils.h"
|
||||
#include "shop.h"
|
||||
|
||||
void basic_mud_log(const char *x, ...)
|
||||
{
|
||||
puts(x);
|
||||
}
|
||||
|
||||
char *fread_string(FILE * fl, const char *error)
|
||||
{
|
||||
char buf[MAX_STRING_LENGTH], tmp[512], *rslt, *point;
|
||||
int flag;
|
||||
|
||||
*buf = '\0';
|
||||
|
||||
do {
|
||||
if (!fgets(tmp, sizeof(tmp), fl)) {
|
||||
printf("fread_string: format error at or near %s\n", error);
|
||||
exit(1);
|
||||
}
|
||||
if (strlen(tmp) + strlen(buf) > MAX_STRING_LENGTH) {
|
||||
printf("SYSERR: fread_string: string too large (shopconv.c)");
|
||||
exit(1);
|
||||
} else
|
||||
strcat(buf, tmp);
|
||||
|
||||
for (point = buf + strlen(buf) - 2; point >= buf && isspace(*point);
|
||||
point--);
|
||||
if ((flag = (*point == '~'))) {
|
||||
if (*(buf + strlen(buf) - 3) == '\n')
|
||||
*(buf + strlen(buf) - 2) = '\0';
|
||||
else
|
||||
*(buf + strlen(buf) - 2) = '\0';
|
||||
}
|
||||
} while (!flag);
|
||||
|
||||
/* do the allocate boogie */
|
||||
|
||||
if (strlen(buf) > 0) {
|
||||
CREATE(rslt, char, strlen(buf) + 1);
|
||||
strcpy(rslt, buf);
|
||||
} else
|
||||
rslt = NULL;
|
||||
return (rslt);
|
||||
}
|
||||
|
||||
|
||||
void do_list(FILE * shop_f, FILE * newshop_f, int max)
|
||||
{
|
||||
int count, temp;
|
||||
char buf[MAX_STRING_LENGTH];
|
||||
|
||||
for (count = 0; count < max; count++) {
|
||||
fscanf(shop_f, "%d", &temp);
|
||||
fgets(buf, MAX_STRING_LENGTH - 1, shop_f);
|
||||
if (temp > 0)
|
||||
fprintf(newshop_f, "%d%s", temp, buf);
|
||||
}
|
||||
|
||||
fprintf(newshop_f, "-1\n");
|
||||
}
|
||||
|
||||
|
||||
void do_float(FILE * shop_f, FILE * newshop_f)
|
||||
{
|
||||
float f;
|
||||
char str[20];
|
||||
|
||||
fscanf(shop_f, "%f \n", &f);
|
||||
sprintf(str, "%f", f);
|
||||
while ((str[strlen(str) - 1] == '0') && (str[strlen(str) - 2] != '.'))
|
||||
str[strlen(str) - 1] = 0;
|
||||
fprintf(newshop_f, "%s \n", str);
|
||||
}
|
||||
|
||||
|
||||
void do_int(FILE * shop_f, FILE * newshop_f)
|
||||
{
|
||||
int i;
|
||||
|
||||
fscanf(shop_f, "%d \n", &i);
|
||||
fprintf(newshop_f, "%d \n", i);
|
||||
}
|
||||
|
||||
|
||||
void do_string(FILE * shop_f, FILE * newshop_f, char *msg)
|
||||
{
|
||||
char *ptr;
|
||||
|
||||
ptr = fread_string(shop_f, msg);
|
||||
fprintf(newshop_f, "%s~\n", ptr);
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
|
||||
int boot_the_shops(FILE * shop_f, FILE * newshop_f, char *filename)
|
||||
{
|
||||
char *buf, buf2[150];
|
||||
int temp, count;
|
||||
|
||||
sprintf(buf2, "beginning of shop file %s", filename);
|
||||
fprintf(newshop_f, "CircleMUD %s Shop File~\n", VERSION3_TAG);
|
||||
for (;;) {
|
||||
buf = fread_string(shop_f, buf2);
|
||||
if (*buf == '#') { /* New shop */
|
||||
sscanf(buf, "#%d\n", &temp);
|
||||
sprintf(buf2, "shop #%d in shop file %s", temp, filename);
|
||||
fprintf(newshop_f, "#%d~\n", temp);
|
||||
free(buf); /* Plug memory leak! */
|
||||
printf(" #%d\n", temp);
|
||||
|
||||
do_list(shop_f, newshop_f, MAX_PROD); /* Produced Items */
|
||||
|
||||
do_float(shop_f, newshop_f); /* Ratios */
|
||||
do_float(shop_f, newshop_f);
|
||||
|
||||
do_list(shop_f, newshop_f, MAX_TRADE); /* Bought Items */
|
||||
|
||||
for (count = 0; count < 7; count++) /* Keeper msgs */
|
||||
do_string(shop_f, newshop_f, buf2);
|
||||
|
||||
for (count = 0; count < 5; count++) /* Misc */
|
||||
do_int(shop_f, newshop_f);
|
||||
fprintf(newshop_f, "-1\n");
|
||||
for (count = 0; count < 4; count++) /* Open/Close */
|
||||
do_int(shop_f, newshop_f);
|
||||
|
||||
} else {
|
||||
if (*buf == '$') { /* EOF */
|
||||
free(buf); /* Plug memory leak! */
|
||||
fprintf(newshop_f, "$~\n");
|
||||
break;
|
||||
} else if (strstr(buf, VERSION3_TAG)) {
|
||||
printf("%s: New format detected, conversion aborted!\n", filename);
|
||||
free(buf); /* Plug memory leak! */
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
FILE *sfp, *nsfp;
|
||||
char fn[256], part[256];
|
||||
int result, index;
|
||||
|
||||
if (argc < 2) {
|
||||
printf("Usage: shopconv <file1> [file2] [file3] ...\n");
|
||||
exit(1);
|
||||
}
|
||||
for (index = 1; index < argc; index++) {
|
||||
sprintf(fn, "%s", argv[index]);
|
||||
sprintf(part, "mv %s %s.tmp", fn, fn);
|
||||
system(part);
|
||||
sprintf(part, "%s.tmp", fn);
|
||||
sfp = fopen(part, "r");
|
||||
if (sfp == NULL) {
|
||||
strcat(fn, " could not be opened");
|
||||
perror(fn);
|
||||
} else {
|
||||
if ((nsfp = fopen(fn, "w")) == NULL) {
|
||||
printf("Error writing to %s.\n", fn);
|
||||
continue;
|
||||
}
|
||||
printf("%s:\n", fn);
|
||||
result = boot_the_shops(sfp, nsfp, fn);
|
||||
fclose(nsfp);
|
||||
fclose(sfp);
|
||||
if (result) {
|
||||
sprintf(part, "mv %s.tmp %s", fn, fn);
|
||||
system(part);
|
||||
} else {
|
||||
sprintf(part, "mv %s.tmp %s.bak", fn, fn);
|
||||
system(part);
|
||||
printf("Done!\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
159
src/util/sign.c
Executable file
159
src/util/sign.c
Executable file
|
|
@ -0,0 +1,159 @@
|
|||
/*
|
||||
* sign.c: a program to present text on a TCP port
|
||||
*
|
||||
* Author: Jeremy Elson (jelson@circlemud.org)
|
||||
* Usage: sign <port> <filename> or
|
||||
* sign <port> -
|
||||
*
|
||||
* '-' indicates file should be read from stdin.
|
||||
*
|
||||
* This program is in the public domain. It may be copied, redistributed,
|
||||
* reused, modified, etc., but a notice of my authorship must be maintained.
|
||||
*
|
||||
* This program comes with no warranty of any kind, expressed or implied.
|
||||
*/
|
||||
|
||||
#define MAX_FILESIZE 8192
|
||||
#define LINEBUF_SIZE 128
|
||||
|
||||
#include "conf.h"
|
||||
#include "sysdep.h"
|
||||
|
||||
|
||||
/*
|
||||
* init_socket sets up the mother descriptor - creates the socket, sets
|
||||
* its options up, binds it, and listens.
|
||||
*/
|
||||
int init_socket(int port)
|
||||
{
|
||||
int s, opt;
|
||||
struct sockaddr_in sa;
|
||||
|
||||
/*
|
||||
* Should the first argument to socket() be AF_INET or PF_INET? I don't
|
||||
* know, take your pick. PF_INET seems to be more widely adopted, and
|
||||
* Comer (_Internetworking with TCP/IP_) even makes a point to say that
|
||||
* people erroneously use AF_INET with socket() when they should be using
|
||||
* PF_INET. However, the man pages of some systems indicate that AF_INET
|
||||
* is correct; some such as ConvexOS even say that you can use either one.
|
||||
* All implementations I've seen define AF_INET and PF_INET to be the same
|
||||
* number anyway, so ths point is (hopefully) moot.
|
||||
*/
|
||||
|
||||
if ((s = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
|
||||
perror("Create socket");
|
||||
exit(1);
|
||||
}
|
||||
#if defined(SO_REUSEADDR)
|
||||
opt = 1;
|
||||
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *) &opt, sizeof(opt)) < 0) {
|
||||
perror("setsockopt REUSEADDR");
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(SO_LINGER)
|
||||
{
|
||||
struct linger ld;
|
||||
|
||||
ld.l_onoff = 0;
|
||||
ld.l_linger = 0;
|
||||
if (setsockopt(s, SOL_SOCKET, SO_LINGER, (char *) &ld, sizeof(ld)) < 0) {
|
||||
perror("setsockopt LINGER");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
sa.sin_family = AF_INET;
|
||||
sa.sin_port = htons(port);
|
||||
sa.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
|
||||
if (bind(s, (struct sockaddr *) &sa, sizeof(sa)) < 0) {
|
||||
perror("bind");
|
||||
close(s);
|
||||
exit(1);
|
||||
}
|
||||
listen(s, 5);
|
||||
return (s);
|
||||
}
|
||||
|
||||
|
||||
char *get_text(char *fname)
|
||||
{
|
||||
static char t[MAX_FILESIZE];
|
||||
char tmp[LINEBUF_SIZE + 2];
|
||||
FILE *fl = NULL;
|
||||
|
||||
*t = '\0';
|
||||
|
||||
if (!strcmp(fname, "-")) {
|
||||
fl = stdin;
|
||||
if (isatty(STDIN_FILENO))
|
||||
fprintf(stderr, "Enter sign text; terminate with Ctrl-D.\n");
|
||||
} else {
|
||||
if (!(fl = fopen(fname, "r"))) {
|
||||
perror(fname);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
while (fgets(tmp, LINEBUF_SIZE, fl)) {
|
||||
if (strlen(tmp) + strlen(t) < MAX_FILESIZE - 1)
|
||||
strcat(t, strcat(tmp, "\r"));
|
||||
else {
|
||||
fprintf(stderr, "String too long. Truncated.\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return (t);
|
||||
}
|
||||
|
||||
|
||||
/* clean up our zombie kids to avoid defunct processes */
|
||||
RETSIGTYPE reap(int sig)
|
||||
{
|
||||
while (waitpid(-1, NULL, WNOHANG) > 0);
|
||||
|
||||
signal(SIGCHLD, reap);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char *txt;
|
||||
int desc, remaining, bytes_written, len, s, port, child;
|
||||
|
||||
if (argc != 3 || (port = atoi(argv[1])) < 1024) {
|
||||
fprintf(stderr, "usage: %s <portnum> <\"-\" | filename>\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
s = init_socket(port);
|
||||
len = strlen(txt = get_text(argv[2]));
|
||||
|
||||
if ((child = fork()) > 0) {
|
||||
fprintf(stderr, "Sign started on port %d (pid %d).\n", port, child);
|
||||
exit(0);
|
||||
}
|
||||
signal(SIGCHLD, reap);
|
||||
|
||||
for (;;) {
|
||||
if ((desc = accept(s, (struct sockaddr *) NULL, 0)) < 0)
|
||||
continue;
|
||||
|
||||
if (fork() == 0) {
|
||||
remaining = len;
|
||||
do {
|
||||
if ((bytes_written = write(desc, txt, remaining)) < 0)
|
||||
exit(0);
|
||||
else {
|
||||
txt += bytes_written;
|
||||
remaining -= bytes_written;
|
||||
}
|
||||
} while (remaining > 0);
|
||||
exit(0);
|
||||
}
|
||||
close(desc);
|
||||
}
|
||||
}
|
||||
57
src/util/split.c
Executable file
57
src/util/split.c
Executable file
|
|
@ -0,0 +1,57 @@
|
|||
/* ************************************************************************
|
||||
* file: split.c Part of CircleMud *
|
||||
* Usage: split one large file into multiple smaller ones, with index *
|
||||
* Written by Jeremy Elson *
|
||||
* All Rights Reserved *
|
||||
* Copyright (C) 1993 The Trustees of The Johns Hopkins University *
|
||||
************************************************************************* */
|
||||
|
||||
/*
|
||||
* This utility is meant to split a large file into multiple smaller ones,
|
||||
* mainly to help break huge world files (ala Diku) into zone-sized files
|
||||
* that are easier to manage.
|
||||
*
|
||||
* At each point in the original file where you want a break, insert a line
|
||||
* containng "=filename" at the break point.
|
||||
*/
|
||||
|
||||
#define INDEX_NAME "index"
|
||||
#define BSZ 256
|
||||
#define MAGIC_CHAR '='
|
||||
|
||||
#include "conf.h"
|
||||
#include "sysdep.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char line[BSZ + 1];
|
||||
FILE *index = 0, *outfile = 0;
|
||||
|
||||
if (!(index = fopen(INDEX_NAME, "w"))) {
|
||||
perror("error opening index for write");
|
||||
exit(1);
|
||||
}
|
||||
while (fgets(line, BSZ, stdin)) {
|
||||
if (*line == MAGIC_CHAR) {
|
||||
*(strchr(line, '\n')) = '\0';
|
||||
if (outfile) {
|
||||
/* fputs("$\n", outfile);*/
|
||||
fclose(outfile);
|
||||
}
|
||||
if (!(outfile = fopen((line + 1), "a"))) {
|
||||
perror("Error opening output file");
|
||||
exit(0);
|
||||
}
|
||||
fputs(line + 1, index);
|
||||
fputs("\n", index);
|
||||
} else if (outfile)
|
||||
fputs(line, outfile);
|
||||
}
|
||||
|
||||
fputs("$\r\n", index);
|
||||
fclose(index);
|
||||
if (outfile)
|
||||
fclose(outfile);
|
||||
|
||||
return (0);
|
||||
}
|
||||
166
src/util/webster.c
Executable file
166
src/util/webster.c
Executable file
|
|
@ -0,0 +1,166 @@
|
|||
/* ************************************************************************
|
||||
* File: wld2html.c *
|
||||
* Usage: Convert a DikuMUD .wld file into a series of .html files *
|
||||
* *
|
||||
* This program is in the public domain. *
|
||||
* Written (QUICKLY AND DIRTILY) by Jeremy Elson (jelson@circlemud.org) *
|
||||
* Based on the Circle 3.0 syntax checker program (scheck.c) *
|
||||
************************************************************************ */
|
||||
|
||||
#define log(msg) fprintf(stderr, "%s\n", msg)
|
||||
|
||||
#include "conf.h"
|
||||
#include "sysdep.h"
|
||||
|
||||
|
||||
#define MEM_USE 10000
|
||||
char buf[MEM_USE];
|
||||
|
||||
int get_line(FILE * fl, char *buf);
|
||||
void skip_spaces(char **string);
|
||||
void parse_webster_html(void);
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int pid = 0;
|
||||
if (argc != 3) {
|
||||
return 0; /* no word/pid given */
|
||||
}
|
||||
pid = atoi(argv[2]);
|
||||
|
||||
snprintf(buf, sizeof(buf),
|
||||
"wget http://www.m-w.com/cgi-bin/dictionary?book=Dictionary\\&va=%s"
|
||||
" -Owebster.html -o/dev/null", argv[1]);
|
||||
system(buf);
|
||||
|
||||
parse_webster_html();
|
||||
|
||||
if (pid)
|
||||
kill(pid, SIGUSR2);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
void parse_webster_html(void) {
|
||||
FILE *infile, *outfile;
|
||||
char scanbuf[MEM_USE], *p, *q;
|
||||
|
||||
outfile = fopen("websterinfo", "w");
|
||||
if (!outfile)
|
||||
exit(1);
|
||||
|
||||
infile = fopen("webster.html", "r");
|
||||
if (!infile) {
|
||||
fprintf(outfile, "A bug has occured in webster. (no webster.html) Please notify Welcor.");
|
||||
fclose(outfile);
|
||||
return;
|
||||
}
|
||||
|
||||
unlink("webster.html"); /* We can still read */
|
||||
|
||||
for ( ; get_line(infile, buf)!=0; ) {
|
||||
p = buf;
|
||||
skip_spaces(&p);
|
||||
/* <PRE> tag means word wasn't found in dictionary */
|
||||
/* list on the form
|
||||
|
||||
1. <a href="/cgi-bin/dictionary?va=XXX">XXX</a>
|
||||
2. <a href="/cgi-bin/dictionary?va=YYY">YYY</a>
|
||||
...
|
||||
</PRE>
|
||||
follows */
|
||||
if (!strncmp(p, "<PRE>", 5)) {
|
||||
fprintf(outfile, "Did you really mean any of these instead ?\n");
|
||||
for (; get_line(infile, buf) != 0;) {
|
||||
p = buf;
|
||||
skip_spaces(&p);
|
||||
if (!strncmp(p, "</PRE>", 6))
|
||||
break;
|
||||
p = strchr(p, '>');
|
||||
p++; /* p now points to first letter of word. */
|
||||
q = strchr(p, '<');
|
||||
*q = '\0';
|
||||
fprintf(outfile, "%s\n", p);
|
||||
}
|
||||
break;
|
||||
} else if (!strncmp(p, "Main Entry:", 10)) {
|
||||
int coloumn = 0;
|
||||
/* Date: means word was found in dictionary */
|
||||
/* M-W has changed their site layout, so we need to find the correct line :*/
|
||||
while (*p != '<') {
|
||||
get_line(infile, buf);
|
||||
p = buf;
|
||||
skip_spaces(&p);
|
||||
}
|
||||
/* The next line contains ALL info on that word.
|
||||
* Including html tags, this can be very much
|
||||
*/
|
||||
fprintf(outfile, "That means:\n");
|
||||
/* remove all tags from this line - ALL tags */
|
||||
for (q = scanbuf; *p && q - scanbuf < sizeof(scanbuf); p++) {
|
||||
if (*p == '&') {
|
||||
/* > and < translates into '"' */
|
||||
if ((*(p+1) == 'l' || *(p+1) == 'g') && *(p+2) == 't' && *(p+3) == ';') {
|
||||
*q++='"';
|
||||
coloumn++;
|
||||
p += 3;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (*p == '<') {
|
||||
/* <br> tags translate into '\n' */
|
||||
if (*(p+1) == 'b' && *(p+2) == 'r') {
|
||||
*q++='\n';
|
||||
coloumn = 0;
|
||||
}
|
||||
for (; *p && *p != '>';p++) ;
|
||||
continue;
|
||||
}
|
||||
if (isspace(*p) && coloumn > 70) { /* wrap at first space after 70th coloumn */
|
||||
*q++='\n';
|
||||
coloumn = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
*q++ = *p;
|
||||
coloumn++;
|
||||
}
|
||||
*q = '\0';
|
||||
|
||||
fprintf(outfile, "%s\n", scanbuf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(infile);
|
||||
|
||||
fprintf(outfile, "~");
|
||||
fclose(outfile);
|
||||
}
|
||||
|
||||
/* get_line reads the next non-blank line off of the input stream.
|
||||
* The newline character is removed from the input.
|
||||
*/
|
||||
int get_line(FILE * fl, char *buf)
|
||||
{
|
||||
char temp[MEM_USE];
|
||||
|
||||
do {
|
||||
fgets(temp, MEM_USE, fl);
|
||||
if (*temp)
|
||||
temp[strlen(temp) - 1] = '\0';
|
||||
} while (!feof(fl) && !*temp);
|
||||
|
||||
if (feof(fl))
|
||||
return (0);
|
||||
else {
|
||||
strcpy(buf, temp);
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Function to skip over the leading spaces of a string.
|
||||
*/
|
||||
void skip_spaces(char **string)
|
||||
{
|
||||
for (; **string && isspace(**string); (*string)++);
|
||||
}
|
||||
513
src/util/wld2html.c
Executable file
513
src/util/wld2html.c
Executable file
|
|
@ -0,0 +1,513 @@
|
|||
/* ************************************************************************
|
||||
* File: wld2html.c *
|
||||
* Usage: Convert a DikuMUD .wld file into a series of .html files *
|
||||
* *
|
||||
* This program is in the public domain. *
|
||||
* Written (QUICKLY AND DIRTILY) by Jeremy Elson (jelson@circlemud.org) *
|
||||
* Based on the Circle 3.0 syntax checker program (scheck.c) *
|
||||
************************************************************************ */
|
||||
|
||||
#define log(msg) fprintf(stderr, "%s\n", msg)
|
||||
|
||||
#include "conf.h"
|
||||
#include "sysdep.h"
|
||||
|
||||
|
||||
#define NOWHERE -1 /* nil reference for room-database */
|
||||
|
||||
/* The cardinal directions: used as index to room_data.dir_option[] */
|
||||
#define NORTH 0
|
||||
#define EAST 1
|
||||
#define SOUTH 2
|
||||
#define WEST 3
|
||||
#define UP 4
|
||||
#define DOWN 5
|
||||
|
||||
#define NUM_OF_DIRS 6
|
||||
|
||||
#define CREATE(result, type, number) do {\
|
||||
if (!((result) = (type *) calloc ((number), sizeof(type))))\
|
||||
{ perror("malloc failure"); abort(); } } while(0)
|
||||
|
||||
|
||||
/* Exit info: used in room_data.dir_option.exit_info */
|
||||
#define EX_ISDOOR (1 << 0) /* Exit is a door */
|
||||
#define EX_CLOSED (1 << 1) /* The door is closed */
|
||||
#define EX_LOCKED (1 << 2) /* The door is locked */
|
||||
#define EX_PICKPROOF (1 << 3) /* Lock can't be picked */
|
||||
|
||||
#define MAX_STRING_LENGTH 8192
|
||||
|
||||
typedef signed char sbyte;
|
||||
typedef unsigned char ubyte;
|
||||
typedef signed short int sh_int;
|
||||
typedef unsigned short int ush_int;
|
||||
typedef char bool;
|
||||
typedef char byte;
|
||||
|
||||
typedef sh_int room_num;
|
||||
typedef sh_int obj_num;
|
||||
|
||||
|
||||
char buf[MAX_STRING_LENGTH];
|
||||
char buf1[MAX_STRING_LENGTH];
|
||||
char buf2[MAX_STRING_LENGTH];
|
||||
char arg[MAX_STRING_LENGTH];
|
||||
|
||||
int get_line(FILE * fl, char *buf);
|
||||
int real_room(int virtual, int reference);
|
||||
|
||||
/* room-related structures *********************************************** */
|
||||
|
||||
|
||||
struct room_direction_data {
|
||||
char *general_description; /* When look DIR. */
|
||||
|
||||
char *keyword; /* for open/close */
|
||||
|
||||
sh_int exit_info; /* Exit info */
|
||||
obj_num key; /* Key's number (-1 for no key) */
|
||||
room_num to_room; /* Where direction leads (NOWHERE) */
|
||||
};
|
||||
|
||||
struct extra_descr_data {
|
||||
char *keyword; /* Keyword in look/examine */
|
||||
char *description; /* What to see */
|
||||
struct extra_descr_data *next; /* Next in list */
|
||||
};
|
||||
|
||||
struct reset_com {
|
||||
char command; /* current command */
|
||||
|
||||
bool if_flag; /* if TRUE: exe only if preceding exe'd */
|
||||
int arg1; /* */
|
||||
int arg2; /* Arguments to the command */
|
||||
int arg3; /* */
|
||||
|
||||
/*
|
||||
* Commands: * 'M': Read a mobile * 'O': Read an object *
|
||||
* 'G': Give obj to mob * 'P': Put obj in obj * 'G': Obj to char *
|
||||
* 'E': Obj to char equip * 'D': Set state of door *
|
||||
*/
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct zone_data {
|
||||
char *name; /* name of this zone */
|
||||
int lifespan; /* how long between resets (minutes) */
|
||||
int age; /* current age of this zone (minutes) */
|
||||
int top; /* upper limit for rooms in this zone */
|
||||
|
||||
int reset_mode; /* conditions for reset (see below) */
|
||||
int number; /* virtual number of this zone */
|
||||
struct reset_com *cmd; /* command table for reset */
|
||||
|
||||
/*
|
||||
* Reset mode: * 0: Don't reset, and don't
|
||||
* update age. * 1: Reset if no PC's are located in zone. * 2: Just
|
||||
* reset. *
|
||||
*/
|
||||
};
|
||||
|
||||
/* ================== Memory Structure for room ======================= */
|
||||
struct room_data {
|
||||
room_num number; /* Rooms number (vnum) */
|
||||
sh_int zone; /* Room zone (for resetting) */
|
||||
int sector_type; /* sector type (move/hide) */
|
||||
char *name; /* Rooms name 'You are ...' */
|
||||
char *description; /* Shown when entered */
|
||||
struct extra_descr_data *ex_description; /* for examine/look */
|
||||
struct room_direction_data *dir_option[NUM_OF_DIRS]; /* Directions */
|
||||
int room_flags; /* DEATH,DARK ... etc */
|
||||
|
||||
byte light; /* Number of lightsources in room */
|
||||
};
|
||||
|
||||
/* ====================================================================== */
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* declarations of most of the 'global' variables *
|
||||
************************************************************************ */
|
||||
|
||||
struct room_data *world = NULL; /* array of rooms */
|
||||
int top_of_world = 0; /* ref to top element of world */
|
||||
|
||||
|
||||
|
||||
/* local functions */
|
||||
char *fread_string(FILE * fl, char *error);
|
||||
void setup_dir(FILE * fl, int room, int dir);
|
||||
void index_boot(char *name);
|
||||
void discrete_load(FILE * fl);
|
||||
void parse_room(FILE * fl, int virtual_nr);
|
||||
void parse_mobile(FILE * mob_f, int nr);
|
||||
char *parse_object(FILE * obj_f, int nr);
|
||||
void assign_rooms(void);
|
||||
void renum_world(void);
|
||||
void write_output(void);
|
||||
|
||||
|
||||
char *dir_names[] =
|
||||
{"North", "East", "South", "West", "Up", "Down"};
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
* routines for booting the system *
|
||||
*********************************************************************** */
|
||||
|
||||
/* body of the booting system */
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Usage: %s <world-file-name>\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
index_boot(argv[1]);
|
||||
|
||||
log("Renumbering rooms.");
|
||||
renum_world();
|
||||
|
||||
log("Writing output.");
|
||||
write_output();
|
||||
log("Done.");
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
void write_output(void)
|
||||
{
|
||||
int i;
|
||||
FILE *fl;
|
||||
char buf[128];
|
||||
register int door, found;
|
||||
|
||||
for (i = 0; i <= top_of_world; i++) {
|
||||
sprintf(buf, "Writing %d.html", world[i].number);
|
||||
log(buf);
|
||||
sprintf(buf, "%d.html", world[i].number);
|
||||
|
||||
if (!(fl = fopen(buf, "w"))) {
|
||||
perror("opening output file");
|
||||
exit(1);
|
||||
}
|
||||
fprintf(fl, "<title> %s </title>\n", world[i].name);
|
||||
fprintf(fl, "<h1> %s </h1>\n", world[i].name);
|
||||
fprintf(fl, "<pre>\n");
|
||||
fputs(world[i].description, fl);
|
||||
fprintf(fl, "</pre>\n");
|
||||
fprintf(fl, "<P> Exits: <P> \n");
|
||||
|
||||
found = 0;
|
||||
for (door = 0; door < NUM_OF_DIRS; door++)
|
||||
if (world[i].dir_option[door] &&
|
||||
world[i].dir_option[door]->to_room != NOWHERE) {
|
||||
found = 1;
|
||||
fprintf(fl, "<a href = \"%d.html\"> %s to %s</a> <p>\n",
|
||||
world[world[i].dir_option[door]->to_room].number,
|
||||
dir_names[door],
|
||||
world[world[i].dir_option[door]->to_room].name);
|
||||
}
|
||||
if (!found)
|
||||
fprintf(fl, "None!");
|
||||
fclose(fl);
|
||||
}
|
||||
}
|
||||
|
||||
/* function to count how many hash-mark delimited records exist in a file */
|
||||
int count_hash_records(FILE * fl)
|
||||
{
|
||||
char buf[128];
|
||||
int count = 0;
|
||||
|
||||
while (fgets(buf, 128, fl))
|
||||
if (*buf == '#')
|
||||
count++;
|
||||
|
||||
return (count);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void index_boot(char *name)
|
||||
{
|
||||
FILE *db_file;
|
||||
int rec_count = 0;
|
||||
|
||||
if (!(db_file = fopen(name, "r"))) {
|
||||
perror("error opening world file");
|
||||
exit(1);
|
||||
}
|
||||
rec_count = count_hash_records(db_file);
|
||||
CREATE(world, struct room_data, rec_count);
|
||||
rewind(db_file);
|
||||
discrete_load(db_file);
|
||||
}
|
||||
|
||||
|
||||
void discrete_load(FILE * fl)
|
||||
{
|
||||
int nr = -1, last = 0;
|
||||
char line[256];
|
||||
|
||||
for (;;) {
|
||||
if (!get_line(fl, line)) {
|
||||
fprintf(stderr, "Format error after room #%d\n", nr);
|
||||
exit(1);
|
||||
}
|
||||
if (*line == '$')
|
||||
return;
|
||||
|
||||
if (*line == '#') {
|
||||
last = nr;
|
||||
if (sscanf(line, "#%d", &nr) != 1) {
|
||||
fprintf(stderr, "Format error after room #%d\n", last);
|
||||
exit(1);
|
||||
}
|
||||
if (nr >= 99999)
|
||||
return;
|
||||
else
|
||||
parse_room(fl, nr);
|
||||
} else {
|
||||
fprintf(stderr, "Format error in world file near room #%d\n", nr);
|
||||
fprintf(stderr, "Offending line: '%s'\n", line);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
long asciiflag_conv(char *flag)
|
||||
{
|
||||
long flags = 0;
|
||||
int is_number = 1;
|
||||
register char *p;
|
||||
|
||||
for (p = flag; *p; p++) {
|
||||
if (islower(*p))
|
||||
flags |= 1 << (*p - 'a');
|
||||
else if (isupper(*p))
|
||||
flags |= 1 << (26 + (*p - 'A'));
|
||||
|
||||
if (!isdigit(*p))
|
||||
is_number = 0;
|
||||
}
|
||||
|
||||
if (is_number)
|
||||
flags = atol(flag);
|
||||
|
||||
return (flags);
|
||||
}
|
||||
|
||||
/* load the rooms */
|
||||
void parse_room(FILE * fl, int virtual_nr)
|
||||
{
|
||||
static int room_nr = 0, zone = 0;
|
||||
int t[10], i;
|
||||
char line[256], flags[128];
|
||||
struct extra_descr_data *new_descr;
|
||||
|
||||
sprintf(buf2, "room #%d", virtual_nr);
|
||||
|
||||
world[room_nr].zone = zone;
|
||||
world[room_nr].number = virtual_nr;
|
||||
world[room_nr].name = fread_string(fl, buf2);
|
||||
world[room_nr].description = fread_string(fl, buf2);
|
||||
|
||||
if (!get_line(fl, line) || sscanf(line, " %d %s %d ", t, flags, t + 2) != 3) {
|
||||
fprintf(stderr, "Format error in room #%d\n", virtual_nr);
|
||||
exit(1);
|
||||
}
|
||||
/* t[0] is the zone number; ignored with the zone-file system */
|
||||
world[room_nr].room_flags = asciiflag_conv(flags);
|
||||
world[room_nr].sector_type = t[2];
|
||||
|
||||
world[room_nr].light = 0; /* Zero light sources */
|
||||
|
||||
for (i = 0; i < NUM_OF_DIRS; i++)
|
||||
world[room_nr].dir_option[i] = NULL;
|
||||
|
||||
world[room_nr].ex_description = NULL;
|
||||
|
||||
sprintf(buf, "Format error in room #%d (expecting D/E/S)", virtual_nr);
|
||||
|
||||
for (;;) {
|
||||
if (!get_line(fl, line)) {
|
||||
fprintf(stderr, "%s\n", buf);
|
||||
exit(1);
|
||||
}
|
||||
switch (*line) {
|
||||
case 'D':
|
||||
setup_dir(fl, room_nr, atoi(line + 1));
|
||||
break;
|
||||
case 'E':
|
||||
CREATE(new_descr, struct extra_descr_data, 1);
|
||||
new_descr->keyword = fread_string(fl, buf2);
|
||||
new_descr->description = fread_string(fl, buf2);
|
||||
new_descr->next = world[room_nr].ex_description;
|
||||
world[room_nr].ex_description = new_descr;
|
||||
break;
|
||||
case 'S': /* end of room */
|
||||
top_of_world = room_nr++;
|
||||
return;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "%s\n", buf);
|
||||
exit(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* read direction data */
|
||||
void setup_dir(FILE * fl, int room, int dir)
|
||||
{
|
||||
int t[5];
|
||||
char line[256];
|
||||
|
||||
sprintf(buf2, "room #%d, direction D%d", world[room].number, dir);
|
||||
|
||||
CREATE(world[room].dir_option[dir], struct room_direction_data, 1);
|
||||
world[room].dir_option[dir]->general_description = fread_string(fl, buf2);
|
||||
world[room].dir_option[dir]->keyword = fread_string(fl, buf2);
|
||||
|
||||
if (!get_line(fl, line)) {
|
||||
fprintf(stderr, "Format error, %s\n", buf2);
|
||||
exit(1);
|
||||
}
|
||||
if (sscanf(line, " %d %d %d ", t, t + 1, t + 2) != 3) {
|
||||
fprintf(stderr, "Format error, %s\n", buf2);
|
||||
exit(1);
|
||||
}
|
||||
if (t[0] == 1)
|
||||
world[room].dir_option[dir]->exit_info = EX_ISDOOR;
|
||||
else if (t[0] == 2)
|
||||
world[room].dir_option[dir]->exit_info = EX_ISDOOR | EX_PICKPROOF;
|
||||
else
|
||||
world[room].dir_option[dir]->exit_info = 0;
|
||||
|
||||
world[room].dir_option[dir]->key = t[1];
|
||||
world[room].dir_option[dir]->to_room = t[2];
|
||||
}
|
||||
|
||||
|
||||
/* resolve all vnums into rnums in the world */
|
||||
void renum_world(void)
|
||||
{
|
||||
register int room, door;
|
||||
|
||||
for (room = 0; room <= top_of_world; room++)
|
||||
for (door = 0; door < NUM_OF_DIRS; door++)
|
||||
if (world[room].dir_option[door])
|
||||
if (world[room].dir_option[door]->to_room != NOWHERE)
|
||||
world[room].dir_option[door]->to_room =
|
||||
real_room(world[room].dir_option[door]->to_room,
|
||||
world[room].number);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
* procedures for resetting, both play-time and boot-time *
|
||||
*********************************************************************** */
|
||||
|
||||
/* read and allocate space for a '~'-terminated string from a given file */
|
||||
char *fread_string(FILE * fl, char *error)
|
||||
{
|
||||
char buf[MAX_STRING_LENGTH], tmp[512], *rslt;
|
||||
register char *point;
|
||||
int done = 0, length = 0, templength = 0;
|
||||
|
||||
*buf = '\0';
|
||||
|
||||
do {
|
||||
if (!fgets(tmp, 512, fl)) {
|
||||
fprintf(stderr, "SYSERR: fread_string: format error at or near %s\n",
|
||||
error);
|
||||
exit(1);
|
||||
}
|
||||
/* If there is a '~', end the string; else put an "\r\n" over the '\n'. */
|
||||
if ((point = strchr(tmp, '~')) != NULL) {
|
||||
*point = '\0';
|
||||
done = 1;
|
||||
} else {
|
||||
point = tmp + strlen(tmp) - 1;
|
||||
*(point++) = '\r';
|
||||
*(point++) = '\n';
|
||||
*point = '\0';
|
||||
}
|
||||
|
||||
templength = strlen(tmp);
|
||||
|
||||
if (length + templength >= MAX_STRING_LENGTH) {
|
||||
log("SYSERR: fread_string: string too large (db.c)");
|
||||
log(error);
|
||||
exit(1);
|
||||
} else {
|
||||
strcat(buf + length, tmp);
|
||||
length += templength;
|
||||
}
|
||||
} while (!done);
|
||||
|
||||
/* allocate space for the new string and copy it */
|
||||
if (strlen(buf) > 0) {
|
||||
CREATE(rslt, char, length + 1);
|
||||
strcpy(rslt, buf);
|
||||
} else
|
||||
rslt = NULL;
|
||||
|
||||
return (rslt);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* returns the real number of the room with given virtual number */
|
||||
int real_room(int virtual, int reference)
|
||||
{
|
||||
int bot, top, mid;
|
||||
|
||||
bot = 0;
|
||||
top = top_of_world;
|
||||
|
||||
/* perform binary search on world-table */
|
||||
for (;;) {
|
||||
mid = (bot + top) / 2;
|
||||
|
||||
if ((world + mid)->number == virtual)
|
||||
return (mid);
|
||||
if (bot >= top) {
|
||||
fprintf(stderr, "Room %d does not exist in database (referenced in room %d)\n", virtual, reference);
|
||||
return (-1);
|
||||
}
|
||||
if ((world + mid)->number > virtual)
|
||||
top = mid - 1;
|
||||
else
|
||||
bot = mid + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* get_line reads the next non-blank line off of the input stream.
|
||||
* The newline character is removed from the input. Lines which begin
|
||||
* with '*' are considered to be comments.
|
||||
*/
|
||||
int get_line(FILE * fl, char *buf)
|
||||
{
|
||||
char temp[256];
|
||||
|
||||
do {
|
||||
fgets(temp, 256, fl);
|
||||
if (*temp)
|
||||
temp[strlen(temp) - 1] = '\0';
|
||||
} while (!feof(fl) && (*temp == '*' || !*temp));
|
||||
|
||||
if (feof(fl))
|
||||
return (0);
|
||||
else {
|
||||
strcpy(buf, temp);
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue