static int get_list(FILE * f, dbref i, int new_strings) { dbref atr; int c; char *buff; buff = alloc_lbuf("get_list"); while (1) { switch (c = getc(f)) { case '>': /* * read # then string */ atr = getref(f); if(atr > 0) { /* * Store the attr */ atr_add_raw(i, atr, (char *) getstring_noalloc(f, new_strings)); } else { /* * Silently discard */ getstring_noalloc(f, new_strings); } break; case '\n': /* * ignore newlines. They're due to v(r). */ break; case '<': /* * end of list */ free_lbuf(buff); c = getc(f); if(c != '\n') { ungetc(c, f); fprintf(stderr, "No line feed on object %d\n", i); return 1; } return 1; default: fprintf(stderr, "Bad character '%c' when getting attributes on object %d\n", c, i); /* * We've found a bad spot. I hope things aren't * * * * * * * too bad. */ (void) getstring_noalloc(f, new_strings); } } }
// Can be used to set a type of lock on an object void CHSInterface::SetLock(int objnum, int lockto, HS_LOCKTYPE lock) { #ifdef PENNMUSH // No change in code between versions char tmp[32]; sprintf_s(tmp, "#%d", lockto); switch (lock) { case LOCK_USE: add_lock(GOD, objnum, Use_Lock, parse_boolexp(lockto, tmp, Use_Lock), -1); break; case LOCK_ZONE: add_lock(GOD, objnum, Zone_Lock, parse_boolexp(lockto, tmp, Zone_Lock), -1); break; case LOCK_NORMAL: default: break; } #endif #if defined(TM3) || defined(MUX) char tmp[SBUF_SIZE]; BOOLEXP *key; snprintf(tmp, SBUF_SIZE - 1, "#%d", lockto); key = parse_boolexp(objnum, tmp, 1); switch (lock) { case LOCK_USE: atr_add_raw(objnum, A_LUSE, unparse_boolexp_quiet(objnum, key)); break; case LOCK_ZONE: atr_add_raw(objnum, A_LCONTROL, unparse_boolexp_quiet(objnum, key)); case LOCK_NORMAL: break; } free_boolexp(key); #endif }
void destroy_guest(dbref guest) { if(!Wizard(mudconf.guest_nuker) || !Good_obj(mudconf.guest_nuker)) mudconf.guest_nuker = 1; if(!Guest(guest)) return; toast_player(guest); atr_add_raw(guest, A_DESTROYER, tprintf("%d", mudconf.guest_nuker)); destroy_player(guest); destroy_obj(mudconf.guest_nuker, guest); }
int my_atr_put(dbref obj, const char *atrname, const char *val) { int atr; char name[SBUF_SIZE]; strcpy(name, atrname); #ifdef TM3 atr = mkattr(name); #endif #ifdef MUX atr = mkattr(GOD, name); #endif if (atr <= 0) return 0; atr_add_raw(obj, atr, (char *) val); return 1; }
/* --------------------------------------------------------------------------- * did_it_rlevel: Have player do something to/with thing, watching the * attributes. 'what' is actually ignored, the desclist match being used * instead. */ void did_it_rlevel ( dbref player, dbref thing, int what, const UTF8 *def, int owhat, const UTF8 *odef, int awhat, int ctrl_flags, const UTF8 *args[], int nargs ) { if (MuxAlarm.bAlarmed) { return; } UTF8 *d, *buff, *act, *charges, *bp; dbref aowner; int num, aflags; int i; bool found_a_desc; reg_ref **preserve = NULL; bool need_pres = false; // Message to player. // if (0 < what) { // Get description list. // DESC_INFO *desclist = desclist_match(player, thing); found_a_desc = false; for (i = 0; i < desclist->n; i++) { // Ok, if it's A_DESC, we need to check against A_IDESC. // if ( A_IDESC == what && A_DESC == desclist->descs[i]) { d = atr_pget(thing, A_IDESC, &aowner, &aflags); } else { d = atr_pget(thing, desclist->descs[i], &aowner, &aflags); } if ('\0' != d[0]) { // No need for the 'def' message. // found_a_desc = true; if (!need_pres) { need_pres = true; preserve = PushRegisters(MAX_GLOBAL_REGS); save_global_regs(preserve); } buff = bp = alloc_lbuf("did_it.1"); mux_exec(d, LBUF_SIZE-1, buff, &bp, thing, thing, player, AttrTrace(aflags, EV_EVAL|EV_FIGNORE|EV_TOP), args, nargs); *bp = '\0'; if ( A_HTDESC == desclist->descs[i] && Html(player)) { safe_str(T("\r\n"), buff, &bp); *bp = '\0'; notify_html(player, buff); } else { notify(player, buff); } free_lbuf(buff); } free_lbuf(d); } if (!found_a_desc) { // No desc found... try the default desc (again). // A_DESC or A_HTDESC... the worst case we look for it twice. // d = atr_pget(thing, what, &aowner, &aflags); if ('\0' != d[0]) { // No need for the 'def' message // found_a_desc = true; if (!need_pres) { need_pres = true; preserve = PushRegisters(MAX_GLOBAL_REGS); save_global_regs(preserve); } buff = bp = alloc_lbuf("did_it.1"); mux_exec(d, LBUF_SIZE-1, buff, &bp, thing, thing, player, AttrTrace(aflags, EV_EVAL|EV_FIGNORE|EV_TOP), args, nargs); *bp = '\0'; if ( A_HTDESC == what && Html(player)) { safe_str(T("\r\n"), buff, &bp); *bp = '\0'; notify_html(player, buff); } else { notify(player, buff); } free_lbuf(buff); } else if (def) { notify(player, def); } free_lbuf(d); } } else if ( what < 0 && def) { notify(player, def); } if (isPlayer(thing)) { d = atr_pget(mudconf.master_room, get_atr(T("ASSET_DESC")), &aowner, &aflags); if (*d) { if (!need_pres) { need_pres = true; preserve = PushRegisters(MAX_GLOBAL_REGS); save_global_regs(preserve); } buff = bp = alloc_lbuf("did_it.1"); mux_exec(d, LBUF_SIZE-1, buff, &bp, thing, thing, player, AttrTrace(aflags, EV_EVAL|EV_FIGNORE|EV_TOP), args, nargs); *bp = '\0'; notify(player, buff); free_lbuf(buff); } free_lbuf(d); } // Message to neighbors. // dbref loc; if ( 0 < owhat && Has_location(player) && Good_obj(loc = Location(player))) { d = atr_pget(thing, owhat, &aowner, &aflags); if (*d) { if (!need_pres) { need_pres = true; preserve = PushRegisters(MAX_GLOBAL_REGS); save_global_regs(preserve); } buff = bp = alloc_lbuf("did_it.2"); mux_exec(d, LBUF_SIZE-1, buff, &bp, thing, thing, player, AttrTrace(aflags, EV_EVAL|EV_FIGNORE|EV_TOP), args, nargs); *bp = '\0'; if (*buff) { if (aflags & AF_NONAME) { notify_except2_rlevel2(loc, player, player, thing, buff); } else { notify_except2_rlevel2(loc, player, player, thing, tprintf(T("%s %s"), Name(player), buff)); } } free_lbuf(buff); } else if (odef) { if (ctrl_flags & VERB_NONAME) { notify_except2_rlevel2(loc, player, player, thing, odef); } else { notify_except2_rlevel2(loc, player, player, thing, tprintf(T("%s %s"), Name(player), odef)); } } free_lbuf(d); } else if ( owhat < 0 && odef && Has_location(player) && Good_obj(loc = Location(player))) { if (ctrl_flags & VERB_NONAME) { notify_except2_rlevel2(loc, player, player, thing, odef); } else { notify_except2_rlevel2(loc, player, player, thing, tprintf(T("%s %s"), Name(player), odef)); } } // If we preserved the state of the global registers, restore them. // if (need_pres) { restore_global_regs(preserve); PopRegisters(preserve, MAX_GLOBAL_REGS); } // Do the action attribute. // if ( awhat > 0 && IsReal(thing, player)) { act = atr_pget(thing, awhat, &aowner, &aflags); if (*act != '\0') { charges = atr_pget(thing, A_CHARGES, &aowner, &aflags); if (*charges) { num = mux_atol(charges); if (num > 0) { buff = alloc_sbuf("did_it.charges"); mux_ltoa(num-1, buff); atr_add_raw(thing, A_CHARGES, buff); free_sbuf(buff); } else { buff = atr_pget(thing, A_RUNOUT, &aowner, &aflags); if (*buff != '\0') { free_lbuf(act); act = buff; } else { free_lbuf(act); free_lbuf(buff); free_lbuf(charges); return; } } } free_lbuf(charges); CLinearTimeAbsolute lta; wait_que(thing, player, player, AttrTrace(aflags, 0), false, lta, NOTHING, 0, act, nargs, args, mudstate.global_regs); } free_lbuf(act); } }
void do_txlevel ( dbref executor, dbref caller, dbref enactor, int eval, int key, int nargs, UTF8 *object, UTF8 *arg, const UTF8 *cargs[], int ncargs ) { UNUSED_PARAMETER(caller); UNUSED_PARAMETER(enactor); UNUSED_PARAMETER(eval); UNUSED_PARAMETER(cargs); UNUSED_PARAMETER(ncargs); if (!arg || !*arg) { notify_quiet(executor, T("I don\xE2\x80\x99t know what you want to set!")); return; } // Find thing. // dbref thing = match_controlled(executor, object); if (NOTHING == thing) { return; } UTF8 lname[9]; RLEVEL ormask = 0; RLEVEL andmask = ~ormask; while (*arg) { int negate = 0; while ( *arg && mux_isspace(*arg)) { arg++; } if (*arg == '!') { negate = 1; ++arg; } int i; for (i = 0; *arg && !mux_isspace(*arg); arg++) { if (i < 8) { lname[i++] = *arg; } } lname[i] = '\0'; if (!lname[0]) { if (negate) { notify(executor, T("You must specify a reality level to clear.")); } else { notify(executor, T("You must specify a reality level to set.")); } return; } RLEVEL result = find_rlevel(lname); if (!result) { notify(executor, T("No such reality level.")); continue; } if (negate) { andmask &= ~result; notify(executor, T("Cleared.")); } else { ormask |= result; notify(executor, T("Set.")); } } // Set the Tx Level. // UTF8 *buff = alloc_lbuf("do_rxlevel"); mux_sprintf(buff, LBUF_SIZE, T("%08X %08X"), RxLevel(thing), TxLevel(thing) & andmask | ormask); atr_add_raw(thing, A_RLEVEL, buff); free_lbuf(buff); }
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; } } }
static int get_slave_result( void ) { char *buf, *host1, *hostname, *host2, *p, *userid; int remote_port, len; unsigned long addr; DESC *d; char s[MBUF_SIZE]; buf = alloc_lbuf( "slave_buf" ); len = read( slave_socket, buf, LBUF_SIZE - 1 ); if( len < 0 ) { if( ( errno == EAGAIN ) || ( errno == EWOULDBLOCK ) ) { free_lbuf( buf ); return ( -1 ); } close( slave_socket ); slave_socket = -1; free_lbuf( buf ); return ( -1 ); } else if( len == 0 ) { free_lbuf( buf ); return ( -1 ); } buf[len] = '\0'; host1 = buf; GSR_STRCHR_INC( hostname, host1, ' ' ); hostname[-1] = '\0'; GSR_STRCHR_INC( host2, hostname, '\n' ); host2[-1] = '\0'; if( mudconf.use_hostname ) { for( d = descriptor_list; d; d = d->next ) { if( strcmp( d->addr, host1 ) ) { continue; } if( d->player != 0 ) { if( d->username[0] ) { snprintf(s, MBUF_SIZE, "%s@%s", d->username, hostname ); atr_add_raw( d->player, A_LASTSITE, s ); } else { atr_add_raw( d->player, A_LASTSITE, hostname ); } } strncpy( d->addr, hostname, 50 ); d->addr[50] = '\0'; } } GSR_STRCHR_INC( p, host2, ' ' ); p[-1] = '\0'; addr = inet_addr( host2 ); if( addr == INADDR_NONE ) { goto gsr_end; } /* * now we're into the RFC 1413 ident reply */ GSR_SKIP_WHITESPACE( p ); remote_port = 0; while( isdigit( *p ) ) { remote_port <<= 1; remote_port += ( remote_port << 2 ) + ( *p & 0x0f ); ++p; } GSR_SKIP_WHITESPACE( p ); GSR_REQUIRE_CHAR( p, ',' ); GSR_SKIP_WHITESPACE( p ); /* * skip the local port, making sure it consists of digits */ while( isdigit( *p ) ) { ++p; } GSR_SKIP_WHITESPACE( p ); GSR_REQUIRE_CHAR( p, ':' ); GSR_SKIP_WHITESPACE( p ); /* * identify the reply type */ if( strncmp( p, "USERID", 6 ) ) { /* * the other standard possibility here is "ERROR" */ goto gsr_end; } p += 6; GSR_SKIP_WHITESPACE( p ); GSR_REQUIRE_CHAR( p, ':' ); GSR_SKIP_WHITESPACE( p ); /* * don't include the trailing linefeed in the userid */ GSR_STRCHR_INC( userid, p, '\n' ); userid[-1] = '\0'; /* * go back and skip over the "OS [, charset] : " field */ GSR_STRCHR_INC( userid, p, ':' ); GSR_SKIP_WHITESPACE( userid ); for( d = descriptor_list; d; d = d->next ) { if( ntohs( ( d->address ).sin_port ) != remote_port ) { continue; } if( ( d->address ).sin_addr.s_addr != addr ) { continue; } if( d->player != 0 ) { if( mudconf.use_hostname ) { snprintf(s, MBUF_SIZE, "%s@%s", userid, hostname ); atr_add_raw( d->player, A_LASTSITE, s ); } else { snprintf(s, MBUF_SIZE, "%s@%s", userid, host2 ); atr_add_raw( d->player, A_LASTSITE, s ); } } strncpy( d->username, userid, 10 ); d->username[10] = '\0'; break; } gsr_end: free_lbuf( buf ); return 0; }
void do_dbclean( dbref player, dbref cause, int key ) { VATTR *vp, *vpx; dbref i, end; int ca, n_oldtotal, n_oldtop, n_deleted, n_renumbered, n_objt, n_atrt, got; char *as, *str; int *used_table; ATTR **new_table; UFUN *ufp; CMDENT *cmdp; ADDENT *addp; raw_broadcast( 0, "GAME: Cleaning database. Game may freeze for a few minutes." ); used_table = ( int * ) XCALLOC( mudstate.attr_next, sizeof( int ), "dbclean.used_table" ); n_oldtotal = mudstate.attr_next; n_oldtop = anum_alc_top; n_deleted = n_renumbered = n_objt = n_atrt = 0; /* * Non-user-defined attributes are always considered used. */ for( i = 0; i < A_USER_START; i++ ) { used_table[i] = i; } /* * Walk the database. Mark all the attribute numbers in use. */ atr_push(); DO_WHOLE_DB( i ) { for( ca = atr_head( i, &as ); ca; ca = atr_next( &as ) ) { used_table[ca] = ca; } } atr_pop(); /* * Walk the vattr table. If a number isn't in use, zorch it. */ vp = vattr_first(); while( vp ) { vpx = vp; vp = vattr_next( vp ); if( used_table[vpx->number] == 0 ) { anum_set( vpx->number, NULL ); hashdelete( vpx->name, &mudstate.vattr_name_htab ); XFREE( vpx, "dbclean.vpx" ); n_deleted++; } } /* * The user-defined function, added command, and hook structures embed * * attribute numbers. Clean out the ones we've deleted, resetting them * * to the *Invalid (A_TEMP) attr. */ for( ufp = ( UFUN * ) hash_firstentry( &mudstate.ufunc_htab ); ufp != NULL; ufp = ( UFUN * ) hash_nextentry( &mudstate.ufunc_htab ) ) { if( used_table[ufp->atr] == 0 ) { ufp->atr = A_TEMP; } } for( cmdp = ( CMDENT * ) hash_firstentry( &mudstate.command_htab ); cmdp != NULL; cmdp = ( CMDENT * ) hash_nextentry( &mudstate.command_htab ) ) { if( cmdp->pre_hook ) { if( used_table[cmdp->pre_hook->atr] == 0 ) { cmdp->pre_hook->atr = A_TEMP; } } if( cmdp->post_hook ) { if( used_table[cmdp->post_hook->atr] == 0 ) { cmdp->post_hook->atr = A_TEMP; } } if( cmdp->userperms ) { if( used_table[cmdp->userperms->atr] == 0 ) { cmdp->userperms->atr = A_TEMP; } } if( cmdp->callseq & CS_ADDED ) { for( addp = ( ADDENT * ) cmdp->info.added; addp != NULL; addp = addp->next ) { if( used_table[addp->atr] == 0 ) { addp->atr = A_TEMP; } } } } /* * Walk the table we've created of used statuses. When we find free * * slots, walk backwards to the first used slot at the end of the * * table. Write the number of the free slot into that used slot. */ for( i = A_USER_START, end = mudstate.attr_next - 1; ( i < mudstate.attr_next ) && ( i < end ); i++ ) { if( used_table[i] == 0 ) { while( ( end > i ) && ( used_table[end] == 0 ) ) { end--; } if( end > i ) { used_table[end] = used_table[i] = i; end--; } } } /* * Renumber the necessary attributes in the vattr tables. */ for( i = A_USER_START; i < mudstate.attr_next; i++ ) { if( used_table[i] != i ) { vp = ( VATTR * ) anum_get( i ); if( vp ) { vp->number = used_table[i]; vp->flags |= AF_DIRTY; anum_set( used_table[i], ( ATTR * ) vp ); anum_set( i, NULL ); n_renumbered++; } } } /* * Now we walk the database. For every object, if we have an attribute * * we're renumbering (the slot number is not equal to the array value * * at that slot), we delete the old attribute and add the new one. */ atr_push(); DO_WHOLE_DB( i ) { got = 0; for( ca = atr_head( i, &as ); ca; ca = atr_next( &as ) ) { if( used_table[ca] != ca ) { str = atr_get_raw( i, ca ); atr_add_raw( i, used_table[ca], str ); atr_clr( i, ca ); n_atrt++; got = 1; } } if( got ) { n_objt++; } } atr_pop(); /* * The new end of the attribute table is the first thing we've * * renumbered. */ for( end = A_USER_START; ( ( end == used_table[end] ) && ( end < mudstate.attr_next ) ); end++ ); mudstate.attr_next = end; /* * We might be able to shrink the size of the attribute table. * * If the current size of the table is less than the initial * * size, shrink it back down to the initial size. * * Otherwise, shrink it down so it's the current top plus the * * initial size, as if we'd just called anum_extend() for it. */ if( anum_alc_top > mudconf.init_size + A_USER_START ) { if( mudstate.attr_next < mudconf.init_size + A_USER_START ) { end = mudconf.init_size + A_USER_START; } else { end = mudstate.attr_next + mudconf.init_size; } if( end < anum_alc_top ) { new_table = ( ATTR ** ) XCALLOC( end + 1, sizeof( ATTR * ), "dbclean.new_table" ); for( i = 0; i < mudstate.attr_next; i++ ) { new_table[i] = anum_table[i]; } XFREE( anum_table, "dbclean.anum_table" ); anum_table = new_table; anum_alc_top = end; } } /* * Go through the function and added command tables again, and * * take care of the attributes that got renumbered. */ for( ufp = ( UFUN * ) hash_firstentry( &mudstate.ufunc_htab ); ufp != NULL; ufp = ( UFUN * ) hash_nextentry( &mudstate.ufunc_htab ) ) { if( used_table[ufp->atr] != ufp->atr ) { ufp->atr = used_table[ufp->atr]; } } for( cmdp = ( CMDENT * ) hash_firstentry( &mudstate.command_htab ); cmdp != NULL; cmdp = ( CMDENT * ) hash_nextentry( &mudstate.command_htab ) ) { if( cmdp->pre_hook ) { if( used_table[cmdp->pre_hook->atr] != cmdp->pre_hook->atr ) cmdp->pre_hook->atr = used_table[cmdp->pre_hook->atr]; } if( cmdp->post_hook ) { if( used_table[cmdp->post_hook->atr] != cmdp->post_hook->atr ) cmdp->post_hook->atr = used_table[cmdp->post_hook->atr]; } if( cmdp->userperms ) { if( used_table[cmdp->userperms->atr] != cmdp->userperms->atr ) cmdp->userperms->atr = used_table[cmdp->userperms->atr]; } if( cmdp->callseq & CS_ADDED ) { for( addp = ( ADDENT * ) cmdp->info.added; addp != NULL; addp = addp->next ) { if( used_table[addp->atr] != addp->atr ) { addp->atr = used_table[addp->atr]; } } } } /* * Clean up. */ XFREE( used_table, "dbclean.used_table" ); if( anum_alc_top != n_oldtop ) { notify_check( player, player, MSG_PUP_ALWAYS|MSG_ME_ALL|MSG_F_DOWN, "Cleaned %d user attribute slots (reduced to %d): %d deleted, %d renumbered (%d objects and %d individual attrs touched). Table size reduced from %d to %d.", n_oldtotal - A_USER_START, mudstate.attr_next - A_USER_START, n_deleted, n_renumbered, n_objt, n_atrt, n_oldtop, anum_alc_top ); } else { notify_check( player, player, MSG_PUP_ALWAYS|MSG_ME_ALL|MSG_F_DOWN, "Cleaned %d attributes (now %d): %d deleted, %d renumbered (%d objects and %d individual attrs touched).", n_oldtotal, mudstate.attr_next, n_deleted, n_renumbered, n_objt, n_atrt ); } raw_broadcast( 0, "GAME: Database cleaning complete." ); }
/* * get a result from the slave */ static int get_slave_result() { char *buf; char *token; char *os; char *userid; char *host; int local_port, remote_port; char *p; DESC *d; int len; buf = alloc_lbuf("slave_buf"); len = read(slave_socket, buf, LBUF_SIZE - 1); if (len < 0) { if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) { free_lbuf(buf); return (-1); } close(slave_socket); slave_socket = -1; free_lbuf(buf); return (-1); } else if (len == 0) { free_lbuf(buf); return (-1); } buf[len] = '\0'; token = alloc_lbuf("slave_token"); os = alloc_lbuf("slave_os"); userid = alloc_lbuf("slave_userid"); host = alloc_lbuf("slave_host"); if (sscanf(buf, "%s %s", host, token) != 2) { free_lbuf(buf); free_lbuf(token); free_lbuf(os); free_lbuf(userid); free_lbuf(host); return (0); } p = strchr(buf, '\n'); *p = '\0'; for (d = descriptor_list; d; d = d->next) { if (strcmp(d->addr, host)) continue; if (mudconf.use_hostname) { StringCopyTrunc(d->addr, token, 50); d->addr[50] = '\0'; if (d->player != 0) { if (d->username[0]) atr_add_raw(d->player, A_LASTSITE, tprintf("%s@%s", d->username, d->addr)); else atr_add_raw(d->player, A_LASTSITE, d->addr); } } } if (sscanf(p + 1, "%s %d , %d : %s : %s : %s", host, &remote_port, &local_port, token, os, userid) != 6) { free_lbuf(buf); free_lbuf(token); free_lbuf(os); free_lbuf(userid); free_lbuf(host); return (0); } for (d = descriptor_list; d; d = d->next) { if (ntohs((d->address).sin_port) != remote_port) continue; StringCopyTrunc(d->username, userid, 10); d->username[10] = '\0'; if (d->player != 0) { atr_add_raw(d->player, A_LASTSITE, tprintf("%s@%s", d->username, d->addr)); } free_lbuf(buf); free_lbuf(token); free_lbuf(os); free_lbuf(userid); free_lbuf(host); return (0); } free_lbuf(buf); free_lbuf(token); free_lbuf(os); free_lbuf(userid); free_lbuf(host); return (0); }
static void mung_quotas(dbref player, int key, int value) { dbref aowner; int aq, rq, xq, aflags; UTF8 *buff; if (key & QUOTA_FIX) { // Get value of stuff owned and good value, set other value from that. // xq = count_quota(player); if (key & QUOTA_TOT) { buff = atr_get("mung_quotas.79", player, A_RQUOTA, &aowner, &aflags); aq = mux_atol(buff) + xq; atr_add_raw(player, A_QUOTA, mux_ltoa_t(aq)); free_lbuf(buff); } else { buff = atr_get("mung_quotas.86", player, A_QUOTA, &aowner, &aflags); rq = mux_atol(buff) - xq; atr_add_raw(player, A_RQUOTA, mux_ltoa_t(rq)); free_lbuf(buff); } } else { // Obtain (or calculate) current relative and absolute quota. // buff = atr_get("mung_quotas.96", player, A_QUOTA, &aowner, &aflags); if (!*buff) { free_lbuf(buff); buff = atr_get("mung_quotas.100", player, A_RQUOTA, &aowner, &aflags); rq = mux_atol(buff); free_lbuf(buff); aq = rq + count_quota(player); } else { aq = mux_atol(buff); free_lbuf(buff); buff = atr_get("mung_quotas.109", player, A_RQUOTA, &aowner, &aflags); rq = mux_atol(buff); free_lbuf(buff); } // Adjust values. // if (key & QUOTA_REM) { aq += (value - rq); rq = value; } else { rq += (value - aq); aq = value; } // Set both abs and relative quota. // atr_add_raw(player, A_QUOTA, mux_ltoa_t(aq)); atr_add_raw(player, A_RQUOTA, mux_ltoa_t(rq)); } }