Moved old codebase to old-codebase/
This commit is contained in:
1
old-codebase/src/util/.gitignore
vendored
Normal file
1
old-codebase/src/util/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
Makefile
|
93
old-codebase/src/util/Makefile.in
Normal file
93
old-codebase/src/util/Makefile.in
Normal file
@@ -0,0 +1,93 @@
|
||||
# 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@ @SQLITE3_CFLAGS@ $(MYFLAGS) $(PROFILE) -I$(INCDIR)
|
||||
|
||||
LIBS = @LIBS@ @SQLITE3_LIBS@
|
||||
|
||||
default: all
|
||||
|
||||
all: $(BINDIR)/autowiz $(BINDIR)/delobjs $(BINDIR)/listrent \
|
||||
$(BINDIR)/mudpasswd $(BINDIR)/play2to3 $(BINDIR)/purgeplay \
|
||||
$(BINDIR)/shopconv $(BINDIR)/showplay $(BINDIR)/sign $(BINDIR)/split \
|
||||
$(BINDIR)/wld2html
|
||||
|
||||
autowiz: $(BINDIR)/autowiz
|
||||
|
||||
delobjs: $(BINDIR)/delobjs
|
||||
|
||||
listrent: $(BINDIR)/listrent
|
||||
|
||||
mudpasswd: $(BINDIR)/mudpasswd
|
||||
|
||||
play2to3: $(BINDIR)/play2to3
|
||||
|
||||
purgeplay: $(BINDIR)/purgeplay
|
||||
|
||||
shopconv: $(BINDIR)/shopconv
|
||||
|
||||
showplay: $(BINDIR)/showplay
|
||||
|
||||
sign: $(BINDIR)/sign
|
||||
|
||||
split: $(BINDIR)/split
|
||||
|
||||
wld2html: $(BINDIR)/wld2html
|
||||
|
||||
$(BINDIR)/autowiz: autowiz.c $(INCDIR)/conf.h $(INCDIR)/sysdep.h \
|
||||
$(INCDIR)/structs.h $(INCDIR)/utils.h $(INCDIR)/db.h
|
||||
$(CC) $(CFLAGS) $(LIBS) -o $(BINDIR)/autowiz autowiz.c
|
||||
|
||||
$(BINDIR)/delobjs: delobjs.c $(INCDIR)/conf.h $(INCDIR)/sysdep.h \
|
||||
$(INCDIR)/structs.h $(INCDIR)/utils.h
|
||||
$(CC) $(CFLAGS) $(LIBS) -o $(BINDIR)/delobjs delobjs.c
|
||||
|
||||
$(BINDIR)/listrent: listrent.c $(INCDIR)/conf.h $(INCDIR)/sysdep.h \
|
||||
$(INCDIR)/structs.h
|
||||
$(CC) $(CFLAGS) $(LIBS) -o $(BINDIR)/listrent listrent.c
|
||||
|
||||
$(BINDIR)/mudpasswd: mudpasswd.c $(INCDIR)/conf.h $(INCDIR)/sysdep.h \
|
||||
$(INCDIR)/structs.h $(INCDIR)/utils.h
|
||||
$(CC) $(CFLAGS) $(LIBS) -o $(BINDIR)/mudpasswd mudpasswd.c @CRYPTLIB@
|
||||
|
||||
$(BINDIR)/play2to3: play2to3.c $(INCDIR)/conf.h $(INCDIR)/sysdep.h
|
||||
$(CC) $(CFLAGS) $(LIBS) -o $(BINDIR)/play2to3 play2to3.c
|
||||
|
||||
$(BINDIR)/purgeplay: purgeplay.c $(INCDIR)/conf.h $(INCDIR)/sysdep.h \
|
||||
$(INCDIR)/structs.h $(INCDIR)/utils.h
|
||||
$(CC) $(CFLAGS) $(LIBS) -o $(BINDIR)/purgeplay purgeplay.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) $(LIBS) -o $(BINDIR)/shopconv shopconv.c
|
||||
|
||||
$(BINDIR)/showplay: showplay.c $(INCDIR)/conf.h $(INCDIR)/sysdep.h \
|
||||
$(INCDIR)/structs.h
|
||||
$(CC) $(CFLAGS) $(LIBS) -o $(BINDIR)/showplay showplay.c
|
||||
|
||||
$(BINDIR)/sign: sign.c $(INCDIR)/conf.h $(INCDIR)/sysdep.h
|
||||
$(CC) $(CFLAGS) $(LIBS) -o $(BINDIR)/sign sign.c @NETLIB@
|
||||
|
||||
$(BINDIR)/split: split.c $(INCDIR)/conf.h $(INCDIR)/sysdep.h
|
||||
$(CC) $(CFLAGS) $(LIBS) -o $(BINDIR)/split split.c
|
||||
|
||||
$(BINDIR)/wld2html: wld2html.c $(INCDIR)/conf.h $(INCDIR)/sysdep.h
|
||||
$(CC) $(CFLAGS) $(LIBS) -o $(BINDIR)/wld2html wld2html.c
|
257
old-codebase/src/util/autowiz.c
Normal file
257
old-codebase/src/util/autowiz.c
Normal file
@@ -0,0 +1,257 @@
|
||||
/* ************************************************************************
|
||||
* 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);
|
||||
|
||||
struct char_file_u player;
|
||||
FILE *fl;
|
||||
|
||||
if (!(fl = fopen(PLAYER_FILE, "rb"))) {
|
||||
perror("Error opening playerfile");
|
||||
exit(1);
|
||||
}
|
||||
while (!feof(fl)) {
|
||||
fread(&player, sizeof(struct char_file_u), 1, fl);
|
||||
if (!feof(fl) && player.level >= MIN_LEVEL &&
|
||||
!(IS_SET(player.char_specials_saved.act, PLR_FROZEN)) &&
|
||||
!(IS_SET(player.char_specials_saved.act, PLR_NOWIZLIST)) &&
|
||||
!(IS_SET(player.char_specials_saved.act, PLR_DELETED)))
|
||||
add_name(player.level, player.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);
|
||||
}
|
93
old-codebase/src/util/delobjs.c
Normal file
93
old-codebase/src/util/delobjs.c
Normal file
@@ -0,0 +1,93 @@
|
||||
/* ************************************************************************
|
||||
* file: delobjs.c Part of CircleMud *
|
||||
* Usage: deleting object files for players who are not in the playerfile *
|
||||
* Written by Jeremy Elson 4/2/93 *
|
||||
* All Rights Reserved *
|
||||
* Copyright (C) 1993 The Trustees of The Johns Hopkins University *
|
||||
************************************************************************* */
|
||||
|
||||
/*
|
||||
I recommend you use the script in the lib/plrobjs directory instead of
|
||||
invoking this program directly; however, you can use this program thusly:
|
||||
|
||||
usage: switch into an obj directory; type: delobjs <plrfile> <obj wildcard>
|
||||
*/
|
||||
|
||||
#include "conf.h"
|
||||
#include "sysdep.h"
|
||||
|
||||
#include "structs.h"
|
||||
#include "utils.h"
|
||||
|
||||
struct name_element {
|
||||
char name[20];
|
||||
struct name_element *next;
|
||||
};
|
||||
|
||||
struct name_element *name_list = 0;
|
||||
|
||||
void do_purge(int argc, char **argv)
|
||||
{
|
||||
int x;
|
||||
struct name_element *tmp;
|
||||
char name[1024];
|
||||
int found;
|
||||
|
||||
for (x = 2; x < argc; x++) {
|
||||
found = 0;
|
||||
strcpy(name, argv[x]);
|
||||
*(strchr(name, '.')) = '\0';
|
||||
for (tmp = name_list; !found && tmp; tmp = tmp->next)
|
||||
if (!strcmp(tmp->name, name))
|
||||
found = 1;
|
||||
if (!found) {
|
||||
remove(argv[x]);
|
||||
printf("Deleting %s\n", argv[x]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char *ptr;
|
||||
struct char_file_u player;
|
||||
int okay;
|
||||
struct name_element *tmp;
|
||||
FILE *fl;
|
||||
|
||||
if (argc < 3) {
|
||||
printf("Usage: %s <playerfile-name> <file1> <file2> ... <filen>\n",
|
||||
argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
if (!(fl = fopen(argv[1], "rb"))) {
|
||||
perror("Unable to open playerfile for reading");
|
||||
exit(1);
|
||||
}
|
||||
while (1) {
|
||||
fread(&player, sizeof(player), 1, fl);
|
||||
|
||||
if (feof(fl)) {
|
||||
fclose(fl);
|
||||
do_purge(argc, argv);
|
||||
exit(0);
|
||||
}
|
||||
okay = 1;
|
||||
|
||||
for (ptr = player.name; *ptr; ptr++)
|
||||
*ptr = LOWER(*ptr);
|
||||
|
||||
if (player.char_specials_saved.act & PLR_DELETED)
|
||||
okay = 0;
|
||||
|
||||
if (okay) {
|
||||
tmp = (struct name_element *) malloc(sizeof(struct name_element));
|
||||
tmp->next = name_list;
|
||||
strcpy(tmp->name, player.name);
|
||||
name_list = tmp;
|
||||
}
|
||||
}
|
||||
}
|
71
old-codebase/src/util/listrent.c
Normal file
71
old-codebase/src/util/listrent.c
Normal 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);
|
||||
}
|
84
old-codebase/src/util/mudpasswd.c
Normal file
84
old-codebase/src/util/mudpasswd.c
Normal file
@@ -0,0 +1,84 @@
|
||||
/* ************************************************************************
|
||||
* file: mudpasswd.c Part of CircleMud *
|
||||
* Usage: changing passwords of chars in a Diku playerifle *
|
||||
* 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"
|
||||
|
||||
|
||||
int str_eq(char *s, char *t)
|
||||
{
|
||||
for (;;) {
|
||||
if (*s == 0 && *t == 0)
|
||||
return (TRUE);
|
||||
if (LOWER(*s) != LOWER(*t))
|
||||
return (FALSE);
|
||||
s++;
|
||||
t++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void pword(char *filename, char *name, char *password)
|
||||
{
|
||||
FILE *fl;
|
||||
struct char_file_u buf;
|
||||
int found = FALSE;
|
||||
long size;
|
||||
|
||||
if (!(fl = fopen(filename, "r+"))) {
|
||||
perror(filename);
|
||||
exit(1);
|
||||
}
|
||||
fseek(fl, 0L, SEEK_END);
|
||||
size = ftell(fl);
|
||||
rewind(fl);
|
||||
if (size % sizeof(struct char_file_u)) {
|
||||
fprintf(stderr, "\aWARNING: File size does not match structure, recompile mudpasswd.\n");
|
||||
fclose(fl);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
fread(&buf, sizeof(buf), 1, fl);
|
||||
if (feof(fl))
|
||||
break;
|
||||
|
||||
if (str_eq(name, buf.name)) {
|
||||
found = TRUE;
|
||||
strncpy(buf.pwd, CRYPT(password, buf.name), MAX_PWD_LENGTH);
|
||||
if (fseek(fl, -1L * sizeof(buf), SEEK_CUR) != 0)
|
||||
perror("fseek");
|
||||
if (fwrite(&buf, sizeof(buf), 1, fl) != 1)
|
||||
perror("fwrite");
|
||||
if (fseek(fl, 0L, SEEK_CUR) != 0)
|
||||
perror("fseek");
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
printf("%s password is now %s\n", name, password);
|
||||
} else {
|
||||
printf("%s not found\n", name);
|
||||
}
|
||||
|
||||
fclose(fl);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc != 4)
|
||||
fprintf(stderr, "Usage: %s playerfile character-name new-password\n", argv[0]);
|
||||
else
|
||||
pword(argv[1], argv[2], argv[3]);
|
||||
|
||||
return (0);
|
||||
}
|
379
old-codebase/src/util/play2to3.c
Normal file
379
old-codebase/src/util/play2to3.c
Normal file
@@ -0,0 +1,379 @@
|
||||
/*
|
||||
|
||||
play2to3.c - CircleMUD v2.2-to-v3.0 player file converter
|
||||
|
||||
June 12th, 1995
|
||||
|
||||
This is a quick&dirty hack to convert a player file from CircleMUD v2.2
|
||||
to CircleMUD v3.0. As far as I know it works and it should be portable,
|
||||
but I have only compiled and tested it under Linux 1.1.59.
|
||||
|
||||
Edward Almasy
|
||||
almasy@axis.com
|
||||
|
||||
*/
|
||||
|
||||
#include "conf.h"
|
||||
#include "sysdep.h"
|
||||
|
||||
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;
|
||||
|
||||
#define THREE_MAX_NAME_LENGTH 20
|
||||
#define THREE_MAX_PWD_LENGTH 10
|
||||
#define THREE_MAX_TITLE_LENGTH 80
|
||||
#define THREE_HOST_LENGTH 30
|
||||
#define THREE_EXDSCR_LENGTH 240
|
||||
#define THREE_MAX_TONGUE 3
|
||||
#define THREE_MAX_SKILLS 200
|
||||
#define THREE_MAX_AFFECT 32
|
||||
|
||||
struct THREE_char_ability_data {
|
||||
sbyte str;
|
||||
sbyte str_add; /* 000 - 100 if strength 18 */
|
||||
sbyte intel;
|
||||
sbyte wis;
|
||||
sbyte dex;
|
||||
sbyte con;
|
||||
sbyte cha;
|
||||
};
|
||||
|
||||
struct THREE_char_point_data {
|
||||
sh_int mana;
|
||||
sh_int max_mana; /* Max mana for PC/NPC */
|
||||
sh_int hit;
|
||||
sh_int max_hit; /* Max hit for PC/NPC */
|
||||
sh_int move;
|
||||
sh_int max_move; /* Max move for PC/NPC */
|
||||
sh_int armor; /* Internal -100..100, external -10..10 AC */
|
||||
int gold; /* Money carried */
|
||||
int bank_gold; /* Gold the char has in a bank account */
|
||||
int exp; /* The experience of the player */
|
||||
sbyte hitroll; /* Any bonus or penalty to the hit roll */
|
||||
sbyte damroll; /* Any bonus or penalty to the damage roll */
|
||||
};
|
||||
|
||||
struct THREE_char_special_data_saved {
|
||||
int alignment; /* +-1000 for alignments */
|
||||
long idnum; /* player's idnum; -1 for mobiles */
|
||||
long act; /* act flag for NPC's; player flag for PC's */
|
||||
long affected_by; /* Bitvector for spells/skills affected by */
|
||||
sh_int apply_saving_throw[5]; /* Saving throw (Bonuses) */
|
||||
};
|
||||
|
||||
struct THREE_player_special_data_saved {
|
||||
byte skills[THREE_MAX_SKILLS + 1]; /* array of skills plus skill 0 */
|
||||
byte spells_to_learn; /* How many can you learn yet this level */
|
||||
bool talks[THREE_MAX_TONGUE]; /* PC s Tongues 0 for NPC */
|
||||
int wimp_level; /* Below this # of hit points, flee! */
|
||||
byte freeze_level; /* Level of god who froze char, if any */
|
||||
sh_int invis_level; /* level of invisibility */
|
||||
room_num load_room; /* Which room to place char in */
|
||||
long pref; /* preference flags for PC's. */
|
||||
ubyte bad_pws; /* number of bad password attemps */
|
||||
sbyte conditions[3]; /* Drunk, full, thirsty */
|
||||
ubyte spare0;
|
||||
ubyte spare1;
|
||||
ubyte spare2;
|
||||
ubyte spare3;
|
||||
ubyte spare4;
|
||||
ubyte spare5;
|
||||
int spare6;
|
||||
int spare7;
|
||||
int spare8;
|
||||
int spare9;
|
||||
int spare10;
|
||||
int spare11;
|
||||
int spare12;
|
||||
int spare13;
|
||||
int spare14;
|
||||
int spare15;
|
||||
int spare16;
|
||||
long spare17;
|
||||
long spare18;
|
||||
long spare19;
|
||||
long spare20;
|
||||
long spare21;
|
||||
};
|
||||
|
||||
/* An affect structure. Used in char_file_u *DO*NOT*CHANGE* */
|
||||
struct THREE_affected_type {
|
||||
sh_int type; /* The type of spell that caused this */
|
||||
sh_int duration; /* For how long its effects will last */
|
||||
sbyte modifier; /* This is added to apropriate ability */
|
||||
byte location; /* Tells which ability to change(APPLY_XXX) */
|
||||
long bitvector; /* Tells which bits to set (AFF_XXX) */
|
||||
|
||||
struct THREE_affected_type *next;
|
||||
};
|
||||
|
||||
struct THREE_char_file_u {
|
||||
char name[THREE_MAX_NAME_LENGTH + 1];
|
||||
char description[THREE_EXDSCR_LENGTH];
|
||||
char title[THREE_MAX_TITLE_LENGTH + 1];
|
||||
byte sex;
|
||||
byte class;
|
||||
byte level;
|
||||
sh_int hometown;
|
||||
time_t birth; /* Time of birth of character */
|
||||
int played; /* Number of secs played in total */
|
||||
ubyte weight;
|
||||
ubyte height;
|
||||
char pwd[THREE_MAX_PWD_LENGTH + 1]; /* character's password */
|
||||
|
||||
struct THREE_char_special_data_saved char_specials_saved;
|
||||
struct THREE_player_special_data_saved player_specials_saved;
|
||||
struct THREE_char_ability_data abilities;
|
||||
struct THREE_char_point_data points;
|
||||
struct THREE_affected_type affected[THREE_MAX_AFFECT];
|
||||
|
||||
time_t last_logon; /* Time (in secs) of last logon */
|
||||
char host[THREE_HOST_LENGTH + 1]; /* host of last logon */
|
||||
};
|
||||
|
||||
#define TWO_MAX_PWD_LENGTH 10
|
||||
#define TWO_HOST_LEN 30
|
||||
#define TWO_MAX_TOUNGE 3
|
||||
#define TWO_MAX_SKILLS 128
|
||||
#define TWO_MAX_AFFECT 32
|
||||
|
||||
struct TWO_char_ability_data {
|
||||
sbyte str;
|
||||
sbyte str_add; /* 000 - 100 if strength 18 */
|
||||
sbyte intel;
|
||||
sbyte wis;
|
||||
sbyte dex;
|
||||
sbyte con;
|
||||
};
|
||||
|
||||
struct TWO_char_point_data {
|
||||
sh_int mana;
|
||||
sh_int max_mana; /* Max move for PC/NPC */
|
||||
sh_int hit;
|
||||
sh_int max_hit; /* Max hit for PC/NPC */
|
||||
sh_int move;
|
||||
sh_int max_move; /* Max move for PC/NPC */
|
||||
sh_int armor; /* Internal -100..100, external -10..10 AC */
|
||||
int gold; /* Money carried */
|
||||
int bank_gold; /* Gold the char has in a bank account */
|
||||
int exp; /* The experience of the player */
|
||||
sbyte hitroll; /* Any bonus or penalty to the hit roll */
|
||||
sbyte damroll; /* Any bonus or penalty to the damage roll */
|
||||
};
|
||||
|
||||
struct TWO_char_special2_data {
|
||||
long idnum; /* player's idnum */
|
||||
sh_int load_room; /* Which room to place char in */
|
||||
byte spells_to_learn; /* How many can you learn yet this level */
|
||||
int alignment; /* +-1000 for alignments */
|
||||
long act; /* act flag for NPC's; player flag for PC's */
|
||||
long pref; /* preference flags for PC's. */
|
||||
int wimp_level; /* Below this # of hit points, flee! */
|
||||
byte freeze_level; /* Level of god who froze char, if any */
|
||||
ubyte bad_pws; /* number of bad password attemps */
|
||||
sh_int apply_saving_throw[5]; /* Saving throw (Bonuses) */
|
||||
sbyte conditions[3]; /* Drunk full etc. */
|
||||
ubyte spare0;
|
||||
ubyte spare1;
|
||||
ubyte spare2;
|
||||
ubyte spare3;
|
||||
ubyte spare4;
|
||||
ubyte spare5;
|
||||
ubyte spare6;
|
||||
ubyte spare7;
|
||||
ubyte spare8;
|
||||
ubyte spare9;
|
||||
ubyte spare10;
|
||||
ubyte spare11;
|
||||
long spare12;
|
||||
long spare13;
|
||||
long spare14;
|
||||
long spare15;
|
||||
long spare16;
|
||||
long spare17;
|
||||
long spare18;
|
||||
long spare19;
|
||||
long spare20;
|
||||
long spare21;
|
||||
};
|
||||
|
||||
/* Used in CHAR_FILE_U *DO*NOT*CHANGE* */
|
||||
struct TWO_affected_type {
|
||||
sbyte type; /* The type of spell that caused this */
|
||||
sh_int duration; /* For how long its effects will last */
|
||||
sbyte modifier; /* This is added to apropriate ability */
|
||||
byte location; /* Tells which ability to change(APPLY_XXX) */
|
||||
long bitvector; /* Tells which bits to set (AFF_XXX) */
|
||||
struct TWO_affected_type *next;
|
||||
};
|
||||
|
||||
struct TWO_char_file_u {
|
||||
byte sex;
|
||||
byte class;
|
||||
byte level;
|
||||
time_t birth; /* Time of birth of character */
|
||||
int played; /* Number of secs played in total */
|
||||
ubyte weight;
|
||||
ubyte height;
|
||||
char title[80];
|
||||
sh_int hometown;
|
||||
char description[240];
|
||||
bool talks[TWO_MAX_TOUNGE];
|
||||
struct TWO_char_ability_data abilities;
|
||||
struct TWO_char_point_data points;
|
||||
byte skills[TWO_MAX_SKILLS];
|
||||
struct TWO_affected_type affected[TWO_MAX_AFFECT];
|
||||
struct TWO_char_special2_data specials2;
|
||||
time_t last_logon; /* Time (in secs) of last logon */
|
||||
char host[TWO_HOST_LEN + 1]; /* host of last logon */
|
||||
char name[20];
|
||||
char pwd[TWO_MAX_PWD_LENGTH + 1];
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct TWO_char_file_u stTwo;
|
||||
struct THREE_char_file_u stThree;
|
||||
FILE *ptTwoHndl;
|
||||
FILE *ptThreeHndl;
|
||||
int iIndex;
|
||||
char *apcClassAbbrev[] =
|
||||
{"Mu", "Cl", "Th", "Wa"};
|
||||
int aiSkillMappings[] =
|
||||
{138, 133, 139, 131, 135, 134, 132, 137};
|
||||
|
||||
if (argc < 3) {
|
||||
printf("usage: play2to3 [old 2.2 player file] [new 3.0 player file]\n");
|
||||
exit(1);
|
||||
}
|
||||
ptTwoHndl = fopen(argv[1], "rb");
|
||||
if (ptTwoHndl == NULL) {
|
||||
printf("unable to open source file \"%s\"\n", argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
ptThreeHndl = fopen(argv[2], "wb");
|
||||
if (ptThreeHndl == NULL) {
|
||||
printf("unable to open destination file \"%s\"\n", argv[2]);
|
||||
exit(1);
|
||||
}
|
||||
while (!feof(ptTwoHndl)) {
|
||||
fread(&stTwo, sizeof(struct TWO_char_file_u), 1, ptTwoHndl);
|
||||
|
||||
strcpy(stThree.name, stTwo.name);
|
||||
strcpy(stThree.description, stTwo.description);
|
||||
strcpy(stThree.title, stTwo.title);
|
||||
stThree.sex = stTwo.sex;
|
||||
stThree.class = stTwo.class - 1;
|
||||
stThree.level = stTwo.level;
|
||||
stThree.hometown = stTwo.hometown;
|
||||
stThree.birth = stTwo.birth;
|
||||
stThree.played = stTwo.played;
|
||||
stThree.weight = stTwo.weight;
|
||||
stThree.height = stTwo.height;
|
||||
strcpy(stThree.pwd, stTwo.pwd);
|
||||
|
||||
stThree.char_specials_saved.alignment = stTwo.specials2.alignment;
|
||||
stThree.char_specials_saved.idnum = stTwo.specials2.idnum;
|
||||
stThree.char_specials_saved.act = stTwo.specials2.act;
|
||||
stThree.char_specials_saved.affected_by = 0; /* ??? */
|
||||
for (iIndex = 0; iIndex < 5; iIndex++)
|
||||
stThree.char_specials_saved.apply_saving_throw[iIndex] =
|
||||
stTwo.specials2.apply_saving_throw[iIndex];
|
||||
|
||||
for (iIndex = 0; iIndex < THREE_MAX_SKILLS; iIndex++)
|
||||
stThree.player_specials_saved.skills[iIndex] = 0;
|
||||
for (iIndex = 0; iIndex < 53; iIndex++)
|
||||
if (iIndex > 44) {
|
||||
stThree.player_specials_saved.skills[
|
||||
aiSkillMappings[iIndex - 45]] = stTwo.skills[iIndex];
|
||||
} else
|
||||
stThree.player_specials_saved.skills[iIndex] =
|
||||
stTwo.skills[iIndex];
|
||||
stThree.player_specials_saved.spells_to_learn =
|
||||
stTwo.specials2.spells_to_learn;
|
||||
for (iIndex = 0; iIndex < THREE_MAX_TONGUE; iIndex++)
|
||||
stThree.player_specials_saved.talks[iIndex] = stTwo.talks[iIndex];
|
||||
stThree.player_specials_saved.wimp_level = stTwo.specials2.wimp_level;
|
||||
stThree.player_specials_saved.freeze_level =
|
||||
stTwo.specials2.freeze_level;
|
||||
stThree.player_specials_saved.invis_level = 0;
|
||||
stThree.player_specials_saved.load_room = stTwo.specials2.load_room;
|
||||
stThree.player_specials_saved.pref = stTwo.specials2.pref;
|
||||
stThree.player_specials_saved.bad_pws = stTwo.specials2.bad_pws;
|
||||
for (iIndex = 0; iIndex < 3; iIndex++)
|
||||
stThree.player_specials_saved.conditions[iIndex] =
|
||||
stTwo.specials2.conditions[iIndex];
|
||||
stThree.player_specials_saved.spare0 = 0;
|
||||
stThree.player_specials_saved.spare1 = 0;
|
||||
stThree.player_specials_saved.spare2 = 0;
|
||||
stThree.player_specials_saved.spare3 = 0;
|
||||
stThree.player_specials_saved.spare4 = 0;
|
||||
stThree.player_specials_saved.spare5 = 0;
|
||||
stThree.player_specials_saved.spare6 = 0;
|
||||
stThree.player_specials_saved.spare7 = 0;
|
||||
stThree.player_specials_saved.spare8 = 0;
|
||||
stThree.player_specials_saved.spare9 = 0;
|
||||
stThree.player_specials_saved.spare10 = 0;
|
||||
stThree.player_specials_saved.spare11 = 0;
|
||||
stThree.player_specials_saved.spare12 = 0;
|
||||
stThree.player_specials_saved.spare13 = 0;
|
||||
stThree.player_specials_saved.spare14 = 0;
|
||||
stThree.player_specials_saved.spare15 = 0;
|
||||
stThree.player_specials_saved.spare16 = 0;
|
||||
stThree.player_specials_saved.spare17 = 0;
|
||||
stThree.player_specials_saved.spare18 = 0;
|
||||
stThree.player_specials_saved.spare19 = 0;
|
||||
stThree.player_specials_saved.spare20 = 0;
|
||||
stThree.player_specials_saved.spare21 = 0;
|
||||
|
||||
stThree.abilities.str = stTwo.abilities.str;
|
||||
stThree.abilities.str_add = stTwo.abilities.str_add;
|
||||
stThree.abilities.intel = stTwo.abilities.intel;
|
||||
stThree.abilities.wis = stTwo.abilities.wis;
|
||||
stThree.abilities.dex = stTwo.abilities.dex;
|
||||
stThree.abilities.con = stTwo.abilities.con;
|
||||
stThree.abilities.cha = 12;
|
||||
|
||||
stThree.points.mana = stTwo.points.mana;
|
||||
stThree.points.max_mana = stTwo.points.max_mana;
|
||||
stThree.points.hit = stTwo.points.hit;
|
||||
stThree.points.max_hit = stTwo.points.max_hit;
|
||||
stThree.points.move = stTwo.points.move;
|
||||
stThree.points.max_move = stTwo.points.max_move;
|
||||
stThree.points.armor = stTwo.points.armor;
|
||||
stThree.points.gold = stTwo.points.gold;
|
||||
stThree.points.bank_gold = stTwo.points.bank_gold;
|
||||
stThree.points.exp = stTwo.points.exp;
|
||||
stThree.points.hitroll = stTwo.points.hitroll;
|
||||
stThree.points.damroll = stTwo.points.damroll;
|
||||
|
||||
for (iIndex = 0; iIndex < TWO_MAX_AFFECT; iIndex++) {
|
||||
stThree.affected[iIndex].type = stTwo.affected[iIndex].type;
|
||||
stThree.affected[iIndex].duration = stTwo.affected[iIndex].duration;
|
||||
stThree.affected[iIndex].modifier = stTwo.affected[iIndex].modifier;
|
||||
stThree.affected[iIndex].location = stTwo.affected[iIndex].location;
|
||||
stThree.affected[iIndex].bitvector = stTwo.affected[iIndex].bitvector;
|
||||
stThree.affected[iIndex].next = NULL;
|
||||
}
|
||||
|
||||
stThree.last_logon = stTwo.last_logon;
|
||||
strcpy(stThree.host, stTwo.host);
|
||||
|
||||
printf("[%2d %s] %s %s\n",
|
||||
stThree.level, apcClassAbbrev[(int)stThree.class],
|
||||
stThree.name, stThree.title);
|
||||
|
||||
fwrite(&stThree, sizeof(struct THREE_char_file_u), 1, ptThreeHndl);
|
||||
}
|
||||
|
||||
fclose(ptThreeHndl);
|
||||
fclose(ptTwoHndl);
|
||||
|
||||
return (0);
|
||||
}
|
120
old-codebase/src/util/purgeplay.c
Normal file
120
old-codebase/src/util/purgeplay.c
Normal file
@@ -0,0 +1,120 @@
|
||||
/* ************************************************************************
|
||||
* file: purgeplay.c Part of CircleMUD *
|
||||
* Usage: purge useless chars from playerfile *
|
||||
* All Rights Reserved *
|
||||
* Copyright (C) 1992, 1993 The Trustees of The Johns Hopkins University *
|
||||
************************************************************************* */
|
||||
|
||||
#include "conf.h"
|
||||
#include "sysdep.h"
|
||||
|
||||
#include "structs.h"
|
||||
#include "utils.h"
|
||||
|
||||
|
||||
void purge(char *filename)
|
||||
{
|
||||
FILE *fl;
|
||||
FILE *outfile;
|
||||
struct char_file_u player;
|
||||
int okay, num = 0;
|
||||
long timeout, size;
|
||||
char *ptr, reason[80];
|
||||
|
||||
if (!(fl = fopen(filename, "r+"))) {
|
||||
printf("Can't open %s.", filename);
|
||||
exit(1);
|
||||
}
|
||||
fseek(fl, 0L, SEEK_END);
|
||||
size = ftell(fl);
|
||||
rewind(fl);
|
||||
if (size % sizeof(struct char_file_u)) {
|
||||
fprintf(stderr, "\aWARNING: File size does not match structure, recompile purgeplay.\n");
|
||||
fclose(fl);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
outfile = fopen("players.new", "w");
|
||||
printf("Deleting: \n");
|
||||
|
||||
for (;;) {
|
||||
fread(&player, sizeof(struct char_file_u), 1, fl);
|
||||
if (feof(fl)) {
|
||||
fclose(fl);
|
||||
fclose(outfile);
|
||||
printf("Done.\n");
|
||||
exit(0);
|
||||
}
|
||||
okay = 1;
|
||||
*reason = '\0';
|
||||
|
||||
for (ptr = player.name; *ptr; ptr++)
|
||||
if (!isalpha(*ptr) || *ptr == ' ') {
|
||||
okay = 0;
|
||||
strcpy(reason, "Invalid name");
|
||||
}
|
||||
if (player.level == 0) {
|
||||
okay = 0;
|
||||
strcpy(reason, "Never entered game");
|
||||
}
|
||||
if (player.level < 0 || player.level > LVL_IMPL) {
|
||||
okay = 0;
|
||||
strcpy(reason, "Invalid level");
|
||||
}
|
||||
/* now, check for timeouts. They only apply if the char is not
|
||||
cryo-rented. Lev 32-34 do not time out. */
|
||||
|
||||
timeout = 1000;
|
||||
|
||||
if (okay && player.level <= LVL_IMMORT) {
|
||||
|
||||
if (!(player.char_specials_saved.act & PLR_CRYO)) {
|
||||
if (player.level == 1) timeout = 4; /* Lev 1 : 4 days */
|
||||
else if (player.level <= 4) timeout = 7; /* Lev 2-4 : 7 days */
|
||||
else if (player.level <= 10) timeout = 30; /* Lev 5-10: 30 days */
|
||||
else if (player.level <= LVL_IMMORT - 1)
|
||||
timeout = 60; /* Lev 11-30: 60 days */
|
||||
else if (player.level <= LVL_IMMORT)
|
||||
timeout = 90; /* Lev 31: 90 days */
|
||||
} else
|
||||
timeout = 90;
|
||||
|
||||
timeout *= SECS_PER_REAL_DAY;
|
||||
|
||||
if ((time(0) - player.last_logon) > timeout) {
|
||||
okay = 0;
|
||||
sprintf(reason, "Level %2d idle for %3ld days", player.level,
|
||||
((time(0) - player.last_logon) / SECS_PER_REAL_DAY));
|
||||
}
|
||||
}
|
||||
if (player.char_specials_saved.act & PLR_DELETED) {
|
||||
okay = 0;
|
||||
sprintf(reason, "Deleted flag set");
|
||||
}
|
||||
|
||||
/* Don't delete for *any* of the above reasons if they have NODELETE */
|
||||
if (!okay && (player.char_specials_saved.act & PLR_NODELETE)) {
|
||||
okay = 2;
|
||||
strcat(reason, "; NOT deleted.");
|
||||
}
|
||||
if (okay)
|
||||
fwrite(&player, sizeof(struct char_file_u), 1, outfile);
|
||||
else
|
||||
printf("%4d. %-20s %s\n", ++num, player.name, reason);
|
||||
|
||||
if (okay == 2)
|
||||
fprintf(stderr, "%-20s %s\n", player.name, reason);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc != 2)
|
||||
printf("Usage: %s playerfile-name\n", argv[0]);
|
||||
else
|
||||
purge(argv[1]);
|
||||
|
||||
return (0);
|
||||
}
|
3
old-codebase/src/util/scheck
Normal file
3
old-codebase/src/util/scheck
Normal 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
old-codebase/src/util/shopconv.c
Normal file
190
old-codebase/src/util/shopconv.c
Normal 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);
|
||||
}
|
91
old-codebase/src/util/showplay.c
Normal file
91
old-codebase/src/util/showplay.c
Normal file
@@ -0,0 +1,91 @@
|
||||
/* ************************************************************************
|
||||
* file: showplay.c Part of CircleMud *
|
||||
* Usage: list a diku playerfile *
|
||||
* Copyright (C) 1990, 1991 - see 'license.doc' for complete information. *
|
||||
* All Rights Reserved *
|
||||
************************************************************************* */
|
||||
|
||||
#include "conf.h"
|
||||
#include "sysdep.h"
|
||||
|
||||
#include "structs.h"
|
||||
|
||||
|
||||
void show(char *filename)
|
||||
{
|
||||
char sexname;
|
||||
char classname[10];
|
||||
FILE *fl;
|
||||
struct char_file_u player;
|
||||
int num = 0;
|
||||
long size;
|
||||
|
||||
if (!(fl = fopen(filename, "r+"))) {
|
||||
perror("error opening playerfile");
|
||||
exit(1);
|
||||
}
|
||||
fseek(fl, 0L, SEEK_END);
|
||||
size = ftell(fl);
|
||||
rewind(fl);
|
||||
if (size % sizeof(struct char_file_u)) {
|
||||
fprintf(stderr, "\aWARNING: File size does not match structure, recompile showplay.\n");
|
||||
fclose(fl);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
fread(&player, sizeof(struct char_file_u), 1, fl);
|
||||
if (feof(fl)) {
|
||||
fclose(fl);
|
||||
exit(0);
|
||||
}
|
||||
switch (player.chclass) {
|
||||
case CLASS_THIEF:
|
||||
strcpy(classname, "Th");
|
||||
break;
|
||||
case CLASS_WARRIOR:
|
||||
strcpy(classname, "Wa");
|
||||
break;
|
||||
case CLASS_MAGIC_USER:
|
||||
strcpy(classname, "Mu");
|
||||
break;
|
||||
case CLASS_CLERIC:
|
||||
strcpy(classname, "Cl");
|
||||
break;
|
||||
default:
|
||||
strcpy(classname, "--");
|
||||
break;
|
||||
}
|
||||
|
||||
switch (player.sex) {
|
||||
case SEX_FEMALE:
|
||||
sexname = 'F';
|
||||
break;
|
||||
case SEX_MALE:
|
||||
sexname = 'M';
|
||||
break;
|
||||
case SEX_NEUTRAL:
|
||||
sexname = 'N';
|
||||
break;
|
||||
default:
|
||||
sexname = '-';
|
||||
break;
|
||||
}
|
||||
|
||||
printf("%5d. ID: %5ld (%c) [%2d %s] %-16s %9dg %9db\n", ++num,
|
||||
player.char_specials_saved.idnum, sexname, player.level,
|
||||
classname, player.name, player.points.gold,
|
||||
player.points.bank_gold);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc != 2)
|
||||
printf("Usage: %s playerfile-name\n", argv[0]);
|
||||
else
|
||||
show(argv[1]);
|
||||
|
||||
return (0);
|
||||
}
|
159
old-codebase/src/util/sign.c
Normal file
159
old-codebase/src/util/sign.c
Normal 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
old-codebase/src/util/split.c
Normal file
57
old-codebase/src/util/split.c
Normal 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);
|
||||
}
|
513
old-codebase/src/util/wld2html.c
Normal file
513
old-codebase/src/util/wld2html.c
Normal 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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user