/* $Header: /u1b/games/TINYMUCK/development/src/RCS/sanity.c,v 1.2 1992/02/15 20:51:12 games Exp $ */ /* * $Log: sanity.c,v $ * Revision 1.2 1992/02/15 20:51:12 games * REAL initial checkin * * Revision 1.1 92/02/15 23:03:24 awozniak * Initial revision * */ /* This software is Copyright 1989, 1990, 1992, 1993 by various individuals. Please see the accompanying file COPYRIGHT for details. */ #include "config.h" #include "db.h" #define BUFFER_LEN 1024 #define controls(x,y) 1 int can_link_to(dbref foo,object_flag_type bar,dbref junk){return 1;} extern const char *unparse_object(dbref,dbref); extern const char *unparse_boolexp(dbref, struct boolexp *); char *dup_string(const char *string) { char *s; /* NULL, "" -> NULL */ if(string == 0 || *string == '\0') return 0; if((s = (char *)calloc(strlen(string)+1, sizeof(char))) == 0) abort(); strcpy(s, string); return s; } void add_daemon(dbref daemon){}; void remove_daemon(dbref daemon){}; void notify(dbref player, char *string) { printf("%s\n", uncompress(string));} void violate(dbref i, const char *s) { dbref content, exit, player, thing; char buf[BUFFER_LEN]; player = (dbref) 1; thing = i; printf("Object #%d violates %s rules!\n", i, s); /* db_write_object(stdout, i); */ switch(Typeof(thing)) { case TYPE_ROOM: sprintf(buf, "%s Owner: %s Parent: ", unparse_object(player, thing), NAME(OWNER(thing))); strcat(buf, unparse_object(player, DBFETCH(thing)->location)); break; case TYPE_THING: sprintf(buf, "%s Owner: %s Value: %d", unparse_object(player, thing), NAME(OWNER(thing)), DBFETCH(thing)->sp.thing.value); break; case TYPE_PLAYER: sprintf(buf, "%s %s: %d", unparse_object(player, thing), PL_MONEY_CAP, DBFETCH(thing)->sp.player.pennies); break; case TYPE_EXIT: case TYPE_PROGRAM: sprintf(buf, "%s Owner: %s", unparse_object(player, thing), NAME(OWNER(thing))); break; case TYPE_DAEMON: sprintf(buf, "%s Owner: %s", unparse_object(player, thing), NAME(OWNER(thing))); break; case TYPE_GARBAGE: strcpy(buf, unparse_object(player, thing)); break; } notify(player, buf); if(DBFETCH(thing)->description) notify(player, DBFETCH(thing)->description); sprintf(buf, "Key: %s", unparse_boolexp(player, DBFETCH(thing)->key)); notify(player, buf); if(DBFETCH(thing)->fail_message) { sprintf(buf, "Fail: %s", DBFETCH(thing)->fail_message); notify(player, buf); } if(DBFETCH(thing)->succ_message) { sprintf(buf, "Success: %s", DBFETCH(thing)->succ_message); notify(player, buf); } if (DBFETCH(thing)->drop_message) { sprintf(buf, "Drop: %s", DBFETCH(thing)->drop_message); notify(player, buf); } if(DBFETCH(thing)->ofail) { sprintf(buf, "Ofail: %s", DBFETCH(thing)->ofail); notify(player, buf); } if(DBFETCH(thing)->osuccess) { sprintf(buf, "Osuccess: %s", DBFETCH(thing)->osuccess); notify(player, buf); } if (DBFETCH(thing)->odrop) { sprintf(buf, "Odrop: %s", DBFETCH(thing)->odrop); notify(player, buf); } switch(Typeof(thing)) { case TYPE_ROOM: /* print dropto if present */ if(DBFETCH(thing)->sp.room.dropto != NOTHING) { sprintf(buf, "Dropped objects go to: %s", unparse_object(player, DBFETCH(thing)->sp.room.dropto)); notify(player, buf); } break; case TYPE_THING: /* print home */ sprintf(buf, "Home: %s", unparse_object(player, DBFETCH(thing)->sp.thing.home)); /* home */ notify(player, buf); /* print location if player can link to it */ if(DBFETCH(thing)->location != NOTHING && (controls(player, DBFETCH(thing)->location) || can_link_to(player, NOTYPE, DBFETCH(thing)->location))) { sprintf(buf, "Location: %s", unparse_object(player, DBFETCH(thing)->location)); notify(player, buf); } break; case TYPE_PLAYER: /* print home */ sprintf(buf, "Home: %s", unparse_object(player, DBFETCH(thing)->sp.player.home)); /* home */ notify(player, buf); /* print location if player can link to it */ if(DBFETCH(thing)->location != NOTHING && (controls(player, DBFETCH(thing)->location) || can_link_to(player, NOTYPE, DBFETCH(thing)->location))) { sprintf(buf, "Location: %s", unparse_object(player, DBFETCH(thing)->location)); notify(player, buf); } break; case TYPE_EXIT: if (DBFETCH(thing)->location != NOTHING) { sprintf(buf, "Source: %s", unparse_object(player, DBFETCH(thing)->location)); notify(player, buf); } /* print destinations */ if (DBFETCH(thing)->sp.exit.ndest == 0) break; for (i = 0; i < DBFETCH(thing)->sp.exit.ndest; i++) { switch( (DBFETCH(thing)->sp.exit.dest)[i]) { case NOTHING: break; case HOME: notify(player, "Destination: *HOME*"); break; case BULITIN: notify(player, "Destination: *BUILTIN*"); break; default: sprintf(buf, "Destination: %s", unparse_object(player, (DBFETCH(thing)->sp.exit.dest)[i])); notify(player, buf); break; } } break; case TYPE_PROGRAM: if (DBFETCH(thing)->sp.program.siz) { sprintf(buf, "Program compiled size: %d", DBFETCH(thing)->sp.program.siz); notify(player, buf); } else notify(player, "Program not compiled"); /* print location if player can link to it */ if(DBFETCH(thing)->location != NOTHING && (controls(player, DBFETCH(thing)->location) || can_link_to(player, NOTYPE, DBFETCH(thing)->location))) { sprintf(buf, "Location: %s", unparse_object(player, DBFETCH(thing)->location)); notify(player, buf); } break; case TYPE_DAEMON: sprintf(buf, "Next: #%d", DBFETCH(thing)->next); notify(player,buf); break; } notify(player, "Contents:"); if(DBFETCH(thing)->contents != NOTHING) { DOLIST(content, DBFETCH(thing)->contents) { notify(player, unparse_object(player, content)); } } notify (player, "Actions/exits:"); switch(Typeof(thing)) { case TYPE_ROOM: if(DBFETCH(thing)->sp.room.exits != NOTHING) { DOLIST(exit, DBFETCH(thing)->sp.room.exits) { notify(player, unparse_object(player, exit)); } } break; case TYPE_THING: if(DBFETCH(thing)->sp.thing.actions != NOTHING) { DOLIST(exit, DBFETCH(thing)->sp.thing.actions) { notify(player, unparse_object(player, exit)); } } break; case TYPE_PLAYER: if(DBFETCH(thing)->sp.player.actions != NOTHING) { DOLIST(exit, DBFETCH(thing)->sp.player.actions) { notify(player, unparse_object(player, exit)); } } break; } notify(player,"\n"); } void check_common(dbref obj) { int i; /* check location */ if (DBFETCH(obj)->location >= db_top) violate(obj, "location"); if ((Typeof (DBFETCH(obj)->location) != TYPE_ROOM) && (Typeof (DBFETCH(obj)->location) != TYPE_PLAYER) && (Typeof (DBFETCH(obj)->location) != TYPE_PROGRAM) && (Typeof(obj) != TYPE_EXIT && Typeof (DBFETCH(obj)->location) != TYPE_THING)) violate(obj, "loc_type"); /* check contents */ for (i = DBFETCH(obj)->contents; i < db_top && i != NOTHING; i =DBFETCH(i)->next) if (DBFETCH(i)->location != obj) violate(obj, "contents list"); if (i != NOTHING) violate(obj, "contents rules"); } void check_room(dbref obj) { dbref i; if ( DBFETCH(obj)->sp.room.dropto >= db_top || DBFETCH(obj)->sp.room.dropto != NOTHING && DBFETCH(obj)->sp.room.dropto != HOME && Typeof(DBFETCH(obj)->sp.room.dropto) != TYPE_ROOM) violate(obj, "dropto"); /*check exit type, etc */ for (i = DBFETCH(obj)->sp.room.exits; i != NOTHING && i < db_top; i = DBFETCH(i)->next) if (Typeof(i) != TYPE_EXIT) violate(obj,"exit_type"); if (i != NOTHING) violate(obj, "exits"); if (OWNER(obj) >= db_top || (Typeof(OWNER(obj)) != TYPE_PLAYER)) violate(obj, "owner"); } void check_thing(dbref obj) { dbref i; if (DBFETCH(obj)->sp.thing.home >= db_top || ((Typeof(DBFETCH(obj)->sp.thing.home) != TYPE_ROOM) && (Typeof(DBFETCH(obj)->sp.thing.home) != TYPE_PLAYER))) violate(obj, "home"); for (i = DBFETCH(obj)->sp.thing.actions; i < db_top && i != NOTHING; i = DBFETCH(i)->next) { if (Typeof(i) != TYPE_EXIT) violate(obj,"exit_type"); if (DBFETCH(i)->location != obj) violate(obj,"exit_list"); } if (i != NOTHING) violate(obj, "actions"); if (OWNER(obj) >= db_top || Typeof(OWNER(obj)) != TYPE_PLAYER) violate(obj, "owner"); } void check_exit(dbref obj) { int i; for (i = 0; i < DBFETCH(obj)->sp.exit.ndest; i++) if ((DBFETCH(obj)->sp.exit.dest)[i] >= db_top) violate(obj, "destination"); if (OWNER(obj) >= db_top || Typeof(OWNER(obj)) != TYPE_PLAYER) violate(obj, "owner"); } void check_player(dbref obj) { dbref i; if (DBFETCH(obj)->sp.player.home >= db_top || Typeof(DBFETCH(obj)->sp.player.home) != TYPE_ROOM) violate(obj, "home"); for (i = DBFETCH(obj)->sp.player.actions; i < db_top && i != NOTHING; i = DBFETCH(i)->next) { if (Typeof(i) != TYPE_EXIT) violate(obj,"exit_type"); if (DBFETCH(i)->location != obj) violate(obj,"exit_list"); } if (i != NOTHING) violate(obj, "actions"); } void main(int argc, char **argv) { int i; db_read(stdin); printf("dbtop = %d\n", db_top); for (i = 0; i < db_top; i++) { fprintf(stderr, "Checking object %d..\r", i); check_common(i); switch( db[i].flags & TYPE_MASK ) { case TYPE_ROOM: check_room(i); break; case TYPE_THING: check_thing(i); break; case TYPE_EXIT: check_exit(i); break; case TYPE_PLAYER: check_player(i); break; case TYPE_PROGRAM: case TYPE_DAEMON: case TYPE_GARBAGE: break; default: violate(i, "type"); break; } } printf("\n"); } /* dummy compiler */ void do_compile(dbref p, dbref pr) { } struct macrotable *new_macro(const char *name, const char *definition, dbref player) { } void init_primitives() { } void clear_primitives() { } void clear_players() { } void add_player(dbref i) { } char *alloc_string(const char *string) { char *s; /* NULL, "" -> NULL */ if(string == 0 || *string == '\0') return 0; if((s = (char *) malloc(strlen(string)+1)) == 0) { abort(); } strcpy(s, string); return s; }