Esempio n. 1
0
int ph_any(dbref target, dbref player, POWER power, int fpowers, int reset)
{
    if (fpowers & POWER_EXT) {
	if (reset) {
	    s_Powers2(target, Powers2(target) & ~power);
	} else {
	    s_Powers2(target, Powers2(target) | power);
	}
    } else {
	if (reset) {
	    s_Powers(target, Powers(target) & ~power);
	} else {
	    s_Powers(target, Powers(target) | power);
	}
    }

    return 1;
}
Esempio n. 2
0
File: db_rw.c Progetto: chazu/btmux
dbref db_read(FILE * f, int *db_format, int *db_version, int *db_flags)
{
	dbref i, anum;
	char ch;
	const char *tstr;
	int header_gotten, size_gotten, nextattr_gotten;
	int read_attribs, read_name, read_zone, read_link, read_key, read_parent;
	int read_extflags, read_3flags, read_money, read_timestamps,
		read_new_strings;
	int read_powers, read_powers_player, read_powers_any;
	int deduce_version, deduce_name, deduce_zone, deduce_timestamps;
	int aflags, f1, f2, f3;
	BOOLEXP *tempbool;

	header_gotten = 0;
	size_gotten = 0;
	nextattr_gotten = 0;
	g_format = F_UNKNOWN;
	g_version = 0;
	g_flags = 0;
	read_attribs = 1;
	read_name = 1;
	read_zone = 0;
	read_link = 0;
	read_key = 1;
	read_parent = 0;
	read_money = 1;
	read_extflags = 0;
	read_3flags = 0;
	read_timestamps = 0;
	read_new_strings = 0;
	read_powers = 0;
	read_powers_player = 0;
	read_powers_any = 0;
	deduce_version = 1;
	deduce_zone = 1;
	deduce_name = 1;
	deduce_timestamps = 1;
	db_free();
	for(i = 0;; i++) {

		switch (ch = getc(f)) {
		case '-':				/* Misc tag */
			switch (ch = getc(f)) {
			case 'R':			/* Record number of players */
				mudstate.record_players = getref(f);
				break;
			default:
				(void) getstring_noalloc(f, 0);
			}
			break;
		case '+':				/*
								 * MUX and MUSH header 
								 */
			switch (ch = getc(f)) {	/*
									 * 2nd char selects 
									 * type 
									 */
			case 'X':			/*
								 * MUX VERSION 
								 */
				if(header_gotten) {
					fprintf(stderr,
							"\nDuplicate MUX version header entry at object %d, ignored.\n",
							i);
					tstr = getstring_noalloc(f, 0);
					break;
				}
				header_gotten = 1;
				deduce_version = 0;
				g_format = F_MUX;
				g_version = getref(f);

				/*
				 * Otherwise extract feature flags 
				 */

				if(g_version & V_GDBM) {
					read_attribs = 0;
					read_name = !(g_version & V_ATRNAME);
				}
				read_zone = (g_version & V_ZONE);
				read_link = (g_version & V_LINK);
				read_key = !(g_version & V_ATRKEY);
				read_parent = (g_version & V_PARENT);
				read_money = !(g_version & V_ATRMONEY);
				read_extflags = (g_version & V_XFLAGS);
				read_3flags = (g_version & V_3FLAGS);
				read_powers = (g_version & V_POWERS);
				read_new_strings = (g_version & V_QUOTED);
				g_flags = g_version & ~V_MASK;

				g_version &= V_MASK;
				deduce_name = 0;
				deduce_version = 0;
				deduce_zone = 0;
				break;
			case 'S':			/*
								 * SIZE 
								 */
				if(size_gotten) {
					fprintf(stderr,
							"\nDuplicate size entry at object %d, ignored.\n",
							i);
					tstr = getstring_noalloc(f, 0);
				} else {
					mudstate.min_size = getref(f);
				}
				size_gotten = 1;
				break;
			case 'A':			/*
								 * USER-NAMED ATTRIBUTE 
								 */
				anum = getref(f);
				tstr = getstring_noalloc(f, read_new_strings);
				if(isdigit(*tstr)) {
					aflags = 0;
					while (isdigit(*tstr))
						aflags = (aflags * 10) + (*tstr++ - '0');
					tstr++;		/*
								 * skip ':' 
								 */
				} else {
					aflags = mudconf.vattr_flags;
				}
				vattr_define((char *) tstr, anum, aflags);
				break;
			case 'F':			/*
								 * OPEN USER ATTRIBUTE SLOT 
								 */
				anum = getref(f);
				break;
			case 'N':			/*
								 * NEXT ATTR TO ALLOC WHEN NO
								 * FREELIST 
								 */
				if(nextattr_gotten) {
					fprintf(stderr,
							"\nDuplicate next free vattr entry at object %d, ignored.\n",
							i);
					tstr = getstring_noalloc(f, 0);
				} else {
					mudstate.attr_next = getref(f);
					nextattr_gotten = 1;
				}
				break;
			default:
				fprintf(stderr,
						"\nUnexpected character '%c' in MUX header near object #%d, ignored.\n",
						ch, i);
				tstr = getstring_noalloc(f, 0);
			}
			break;
		case '!':				/*
								 * MUX entry/MUSH entry/MUSE non-zoned entry 
								 */
			if(deduce_version) {
				g_format = F_MUX;
				g_version = 1;
				deduce_name = 0;
				deduce_zone = 0;
				deduce_version = 0;
			} else if(deduce_zone) {
				deduce_zone = 0;
				read_zone = 0;
			}
			i = getref(f);
			db_grow(i + 1);

			if(read_name) {
				tstr = getstring_noalloc(f, read_new_strings);
				if(deduce_name) {
					if(isdigit(*tstr)) {
						read_name = 0;
						s_Location(i, atoi(tstr));
					} else {
						s_Name(i, (char *) tstr);
						s_Location(i, getref(f));
					}
					deduce_name = 0;
				} else {
					s_Name(i, (char *) tstr);
					s_Location(i, getref(f));
				}
			} else {
				s_Location(i, getref(f));
			}

			/*
			 * ZONE on MUSE databases and some others 
			 */

			if(read_zone)
				s_Zone(i, getref(f));

			/*
			 * else
			 * * s_Zone(i, NOTHING); 
			 */

			/*
			 * CONTENTS and EXITS 
			 */

			s_Contents(i, getref(f));
			s_Exits(i, getref(f));

			/*
			 * LINK 
			 */

			if(read_link)
				s_Link(i, getref(f));
			else
				s_Link(i, NOTHING);

			/*
			 * NEXT 
			 */

			s_Next(i, getref(f));

			/*
			 * LOCK
			 */

			if(read_key) {
				tempbool = getboolexp(f);
				atr_add_raw(i, A_LOCK, unparse_boolexp_quiet(1, tempbool));
				free_boolexp(tempbool);
			}
			/*
			 * OWNER 
			 */

			s_Owner(i, getref(f));

			/*
			 * PARENT: PennMUSH uses this field for ZONE
			 * (which we  use as PARENT if we
			 * didn't already read in a  
			 * non-NOTHING parent. 
			 */

			if(read_parent) {
				s_Parent(i, getref(f));
			} else {
				s_Parent(i, NOTHING);
			}

			/*
			 * PENNIES 
			 */

			if(read_money)		/*
								 *  if not fix in
								 * unscraw_foreign  
								 */
				s_Pennies(i, getref(f));

			/*
			 * FLAGS 
			 */

			f1 = getref(f);
			if(read_extflags)
				f2 = getref(f);
			else
				f2 = 0;

			if(read_3flags)
				f3 = getref(f);
			else
				f3 = 0;

			s_Flags(i, f1);
			s_Flags2(i, f2);
			s_Flags3(i, f3);

			if(read_powers) {
				f1 = getref(f);
				f2 = getref(f);
				s_Powers(i, f1);
				s_Powers2(i, f2);
			}

			/*
			 * ATTRIBUTES 
			 */

			if(read_attribs) {
				if(!get_list(f, i, read_new_strings)) {
					fprintf(stderr,
							"\nError reading attrs for object #%d\n", i);
					return -1;
				}
			}
			/*
			 * check to see if it's a player 
			 */

			if(Typeof(i) == TYPE_PLAYER) {
				c_Connected(i);
			}
			break;
		case '*':				/*
								 * EOF marker 
								 */
			tstr = getstring_noalloc(f, 0);
			if(strcmp(tstr, "**END OF DUMP***")) {
				fprintf(stderr, "\nBad EOF marker at object #%d\n", i);
				return -1;
			} else {
				/*
				 * Fix up bizarro foreign DBs 
				 */

				*db_version = g_version;
				*db_format = g_format;
				*db_flags = g_flags;
				load_player_names();
				return mudstate.db_top;
			}
		default:
			fprintf(stderr, "\nIllegal character '%c' near object #%d\n",
					ch, i);
			return -1;
		}

	}

}