static dbref parse_linkable_room(dbref player, char *room_name) { dbref room; init_match(player, room_name, NOTYPE); match_everything(MAT_NO_EXITS | MAT_NUMERIC | MAT_HOME); room = match_result(); /* HOME is always linkable */ if (room == HOME) return HOME; /* Make sure we can link to it */ if (!Good_obj(room)) { notify_quiet(player, "That's not a valid object."); return NOTHING; } else if (!Has_contents(room) || !Linkable(player, room)) { notify_quiet(player, "You can't link to that."); return NOTHING; } else { return room; } }
static void link_exit(dbref player, dbref exit, dbref dest, int key) { int cost, quot; /* Make sure we can link there */ if ((dest != HOME) && ((!controls(player, dest) && !Link_ok(dest)) || !could_doit(player, dest, A_LLINK, 1, 0))) { notify_quiet(player, "Permission denied."); return; } /* Exit must be unlinked or controlled by you */ if ((Location(exit) != NOTHING) && !controls(player, exit)) { notify_quiet(player, "Permission denied."); return; } /* If exit is unlinked and mudconf 'paranoid_exit_linking' is enabled * Do not allow the exit to be linked if you do not control it */ if ( (mudconf.paranoid_exit_linking == 1) && !controls(player,exit) ) { notify_quiet(player, "Permission denied."); return; } /* handle costs */ cost = mudconf.linkcost; quot = 0; if (Owner(exit) != Owner(player)) { cost += mudconf.opencost; quot += mudconf.exit_quota; } if (!canpayfees(player, player, cost, quot, TYPE_EXIT)) return; /* Pay the owner for his loss */ /* Ok, if paranoid_exit_linking is enabled the linker does NOT own exit */ if (!(mudconf.paranoid_exit_linking)) { if (Owner(exit) != Owner(player)) { giveto(Owner(exit), mudconf.opencost, NOTHING); add_quota(Owner(exit), quot, TYPE_EXIT); s_Owner(exit, Owner(player)); s_Flags(exit, (Flags(exit) & ~(INHERIT | WIZARD)) | HALT); } } /* link has been validated and paid for, do it and tell the player */ s_Location(exit, dest); if (!(Quiet(player) || (key & SIDEEFFECT)) ) notify_quiet(player, "Linked."); }
void do_parent(dbref player, dbref cause, int key, char *tname, char *pname) { dbref thing, parent, curr; int lev; /* get victim */ init_match(player, tname, NOTYPE); match_everything(0); thing = noisy_match_result(); if (thing == NOTHING) return; /* Make sure we can do it */ if ( NoMod(thing) && !WizMod(player) ) { notify_quiet(player, "Permission denied."); return; } if (!Controls(player, thing) && !could_doit(player,thing,A_LTWINK, 0, 0)) { notify_quiet(player, "Permission denied."); return; } if ( Backstage(player) && NoBackstage(thing) ) { notify_quiet(player, "Permission denied."); return; } /* Find out what the new parent is */ if (*pname) { init_match(player, pname, Typeof(thing)); match_everything(0); parent = noisy_match_result(); if (parent == NOTHING) return; /* Make sure we have rights to set parent */ if (!Parentable(player, parent)) { notify_quiet(player, "Permission denied."); return; } /* Verify no recursive reference */ ITER_PARENTS(parent, curr, lev) { if (curr == thing) { notify_quiet(player, "You can't have yourself as a parent!"); return; } } } else {
// --------------------------------------------------------------------------- // do_query: Command interface to sql_que // void do_query ( dbref executor, dbref caller, dbref enactor, int eval, int key, char *dbref_attr, char *dbname_query, char *cargs[], int ncargs ) { if (key & QUERY_SQL) { // SQL Query. // dbref thing; ATTR *pattr; if (!( parse_attrib(executor, dbref_attr, &thing, &pattr) && pattr)) { notify_quiet(executor, "No match."); return; } if (!Controls(executor, thing)) { notify_quiet(executor, NOPERM_MESSAGE); return; } char *pQuery = dbname_query; char *pDBName = parse_to(&pQuery, '/', 0); if (NULL == pQuery) { notify(executor, "QUERY: No Query."); return; } STARTLOG(LOG_ALWAYS, "CMD", "QUERY"); Log.tinyprintf("Thing=#%d, Attr=%s, dbname=%s, query=%s", thing, pattr->name, pDBName, pQuery); ENDLOG; } else { notify_quiet(executor, "At least one query option is required."); } }
static void show_quota(dbref player, dbref victim) { dbref aowner; int aflags; UTF8 *buff = alloc_lbuf("show_quota"); atr_get_str(buff, victim, A_QUOTA, &aowner, &aflags); int aq = mux_atol(buff); atr_get_str(buff, victim, A_RQUOTA, &aowner, &aflags); int rq = aq - mux_atol(buff); mux_field fldName = StripTabsAndTruncate(Name(victim), buff, LBUF_SIZE-1, 16); if (!Free_Quota(victim)) { mux_sprintf(buff + fldName.m_byte, LBUF_SIZE - fldName.m_byte, T(" Quota: %9d Used: %9d"), aq, rq); } else { mux_sprintf(buff + fldName.m_byte, LBUF_SIZE - fldName.m_byte, T(" Quota: UNLIMITED Used: %9d"), rq); } notify_quiet(player, buff); free_lbuf(buff); }
static void open_exit(dbref player, dbref loc, char *direction, char *linkto, int key) { dbref exit; char *tpr_buff, *tprp_buff; if (!Good_obj(loc)) return; if (!direction || !*direction) { notify_quiet(player, "Open where?"); return; } else if (!controls(player, loc) && !could_doit(player, loc, A_LOPEN, 0, 0)) { notify_quiet(player, "Permission denied."); return; } exit = create_obj(player, TYPE_EXIT, direction, 0); if (exit == NOTHING) return; /* Initialize everything and link it in. */ s_Exits(exit, loc); s_Next(exit, Exits(loc)); s_Exits(loc, exit); /* and we're done */ if ( !(key & SIDEEFFECT ) ) notify_quiet(player, "Opened."); /* See if we should do a link */ if (!linkto || !*linkto) return; loc = parse_linkable_room(player, linkto); if (loc != NOTHING) { /* Make sure the player passes the link lock */ if ((loc != HOME) && !could_doit(player, loc, A_LLINK, 1, 0)) { notify_quiet(player, "You can't link to there."); return; } /* Link it if the player can pay for it */ if (!payfor(player, mudconf.linkcost)) { tprp_buff = tpr_buff = alloc_lbuf("open_exit"); notify_quiet(player, safe_tprintf(tpr_buff, &tprp_buff, "You don't have enough %s to link.", mudconf.many_coins)); free_lbuf(tpr_buff); } else { s_Location(exit, loc); if ( !(key & SIDEEFFECT ) ) notify_quiet(player, "Linked."); } } }
void do_zone(dbref player, dbref cause, int key, char *tname, char *pname) { dbref thing, zonemaster; switch( key ) { case ZONE_ADD: /* or default */ if( *tname && !*pname ) { init_match(player, tname, NOTYPE); match_everything(0); thing = noisy_match_result(); if( thing == NOTHING ) return; if( !Examinable(player, thing) ) { notify_quiet(player, "You can't do that."); return; } viewzonelist(player, thing); return; } if( !*tname || !*pname ) { notify_quiet(player, "This switch expects two arguments."); return; } init_match(player, tname, NOTYPE); match_everything(0); thing = noisy_match_result(); if( thing == NOTHING ) return; /* Make sure we can do it */ if ( (NoMod(thing) && !WizMod(player)) || (Backstage(player) && NoBackstage(thing)) ) { notify_quiet(player, "Permission denied."); return; } if (!Controls(player, thing)) { notify_quiet(player, "Permission denied."); return; } if( ZoneMaster(thing) ) { notify_quiet(player, "You can't zone a Zone Master."); return; } /* Find out what the new zone is */ init_match(player, pname, NOTYPE); match_everything(0); zonemaster = noisy_match_result(); if (zonemaster == NOTHING) return; if( !ZoneMaster(zonemaster) ) { notify_quiet(player, "That's not a Zone Master."); return; } if(!Controls(player, zonemaster) && !could_doit(player, zonemaster, A_LZONETO, 0, 0) && !could_doit(player, zonemaster, A_LZONEWIZ, 0, 0)) { notify_quiet(player, "Permission denied."); return; } if( zlist_inlist(thing, zonemaster) ) { notify_quiet(player, "Object is already in that zone."); return; } zlist_add(thing, zonemaster); zlist_add(zonemaster, thing); notify_quiet(player, "Zone Master added to object."); break; case ZONE_DELETE: if( !*tname || !*pname ) { notify_quiet(player, "This switch expects two arguments."); return; } /* Find out what the zone is */ init_match(player, pname, NOTYPE); match_everything(0); zonemaster = noisy_match_result(); if (zonemaster == NOTHING) return; init_match(player, tname, NOTYPE); match_everything(0); thing = noisy_match_result(); if( thing == NOTHING ) return; if(!zlist_inlist(thing, zonemaster)) { notify_quiet(player, "That is not one of this object's Zone Masters."); return; } /* only need to control zmo or be zonewiz to delete or control object */ if(!Controls(player, thing) && !Controls(player, zonemaster) && !could_doit(player, zonemaster, A_LZONEWIZ, 0, 0) ) { notify_quiet(player, "Permission denied."); return; } if ( (NoMod(thing) && !WizMod(player)) || (Backstage(player) && NoBackstage(thing)) ) { notify_quiet(player, "Permission denied."); return; } zlist_del(thing, zonemaster); zlist_del(zonemaster, thing); notify_quiet(player, "Deleted."); break; case ZONE_PURGE: if( !*tname || *pname) { notify_quiet(player, "This switch expects one argument."); return; } /* Find out what the zone is */ init_match(player, tname, NOTYPE); match_everything(0); thing = noisy_match_result(); if (thing == NOTHING) return; if( ZoneMaster(thing) ) { if(!Controls(player, thing) && !could_doit(player, thing, A_LZONEWIZ, 0, 0)) { notify_quiet(player, "Permission denied."); return; } if ( (NoMod(thing) && !WizMod(player)) || (Backstage(player) && NoBackstage(thing)) ) { notify_quiet(player, "Permission denied."); return; } zlist_destroy(thing); notify_quiet(player, "All objects removed from zone."); } else { if(!Controls(player, thing)) { notify_quiet(player, "Permission denied."); return; } if ( (NoMod(thing) && !WizMod(player)) || (Backstage(player) && NoBackstage(thing)) ) { notify_quiet(player, "Permission denied."); return; } zlist_destroy(thing); notify_quiet(player, "Object removed from all zones."); } break; default: notify_quiet(player, "Unknown switch!"); break; } return; }
void do_link(dbref player, dbref cause, int key, char *what, char *where) { dbref thing, room; char *buff; int nomtest; if ( (key & SIDEEFFECT) && !SideFX(player) ) { notify(player, "#-1 FUNCTION DISABLED"); return; } /* Find the thing to link */ init_match(player, what, TYPE_EXIT); match_everything(0); thing = noisy_match_result(); if (thing == NOTHING) return; nomtest = ((NoMod(thing) && !WizMod(player)) || (DePriv(player,Owner(thing),DP_MODIFY,POWER7,NOTHING) && (Owner(thing) != Owner(player))) || (Backstage(player) && NoBackstage(thing) && !Immortal(player))); /* Allow unlink if where is not specified */ if (!where || !*where) { if (!nomtest) do_unlink(player, cause, key, what); else notify(player,"Permission denied."); return; } switch (Typeof(thing)) { case TYPE_EXIT: /* Set destination */ room = parse_linkable_room(player, where); if (room != NOTHING) { if (!nomtest) link_exit(player, thing, room, key); else notify(player,"Permission denied."); } break; case TYPE_PLAYER: case TYPE_THING: /* Set home */ if (!Controls(player, thing) || nomtest) { notify_quiet(player, "Permission denied."); break; } init_match(player, where, NOTYPE); match_everything(MAT_NO_EXITS); room = noisy_match_result(); if (!Good_obj(room)) break; if (!Has_contents(room)) { notify_quiet(player, "Can't link to an exit."); break; } if (!can_set_home(player, thing, room) || !could_doit(player, room, A_LLINK, 1, 0)) { notify_quiet(player, "Permission denied."); } else if (room == HOME) { notify_quiet(player, "Can't set home to home."); } else { s_Home(thing, room); if (!(Quiet(player) || (key & SIDEEFFECT)) ) notify_quiet(player, "Home set."); } break; case TYPE_ROOM: /* Set dropto */ if (!Controls(player, thing) || nomtest) { notify_quiet(player, "Permission denied."); break; } room = parse_linkable_room(player, where); if (!Good_obj(room) && (room != HOME)) { notify_quiet(player, "Permission denied."); break; } if ((room != HOME) && !isRoom(room)) { notify_quiet(player, "That is not a room!"); } else if ((room != HOME) && ((!controls(player, room) && !Link_ok(room)) || !could_doit(player, room, A_LLINK, 1, 0))) { notify_quiet(player, "Permission denied."); } else { s_Dropto(thing, room); if (!Quiet(player)) notify_quiet(player, "Dropto set."); } break; default: STARTLOG(LOG_BUGS, "BUG", "OTYPE") buff = alloc_mbuf("do_link.LOG.badtype"); sprintf(buff, "Strange object type: object #%d = %d", thing, Typeof(thing)); log_text(buff); free_mbuf(buff); ENDLOG } }
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); }
// --------------------------------------------------------------------------- // do_wait: Command interface to wait_que // void do_wait ( dbref executor, dbref caller, dbref enactor, int eval, int key, char *event, char *cmd, char *cargs[], int ncargs ) { CLinearTimeAbsolute ltaWhen; CLinearTimeDelta ltd; // If arg1 is all numeric, do simple (non-sem) timed wait. // if (is_rational(event)) { if (key & WAIT_UNTIL) { ltaWhen.SetSecondsString(event); } else { ltaWhen.GetUTC(); ltd.SetSecondsString(event); ltaWhen += ltd; } wait_que(executor, caller, enactor, eval, true, ltaWhen, NOTHING, 0, cmd, ncargs, cargs, mudstate.global_regs); return; } // Semaphore wait with optional timeout. // char *what = parse_to(&event, '/', 0); init_match(executor, what, NOTYPE); match_everything(0); dbref thing = noisy_match_result(); if (!Good_obj(thing)) { return; } else if (!Controls(executor, thing) && !Link_ok(thing)) { notify(executor, NOPERM_MESSAGE); } else { // Get timeout, default 0. // int atr = A_SEMAPHORE; bool bTimed = false; if (event && *event) { if (is_rational(event)) { if (key & WAIT_UNTIL) { ltaWhen.SetSecondsString(event); } else { ltaWhen.GetUTC(); ltd.SetSecondsString(event); ltaWhen += ltd; } bTimed = true; } else { ATTR *ap = atr_str(event); if (!ap) { atr = mkattr(executor, event); if (atr <= 0) { notify_quiet(executor, "Invalid attribute."); return; } ap = atr_num(atr); } else { atr = ap->number; } if (!bCanSetAttr(executor, thing, ap)) { notify_quiet(executor, NOPERM_MESSAGE); return; } } } int num = add_to(thing, 1, atr); if (num <= 0) { // Thing over-notified, run the command immediately. // thing = NOTHING; bTimed = false; } wait_que(executor, caller, enactor, eval, bTimed, ltaWhen, thing, atr, cmd, ncargs, cargs, mudstate.global_regs); } }
void do_notify ( dbref executor, dbref caller, dbref enactor, int key, int nargs, char *what, char *count ) { UNUSED_PARAMETER(caller); UNUSED_PARAMETER(enactor); UNUSED_PARAMETER(nargs); char *obj = parse_to(&what, '/', 0); init_match(executor, obj, NOTYPE); match_everything(0); dbref thing = noisy_match_result(); if (!Good_obj(thing)) { return; } if (!Controls(executor, thing) && !Link_ok(thing)) { notify(executor, NOPERM_MESSAGE); } else { int atr = A_SEMAPHORE; if ( what && what[0] != '\0') { int i = mkattr(executor, what); if (0 < i) { atr = i; if (atr != A_SEMAPHORE) { // Do they have permission to set this attribute? // ATTR *ap = (ATTR *)anum_get(atr); if (!bCanSetAttr(executor, thing, ap)) { notify_quiet(executor, NOPERM_MESSAGE); return; } } } } int loccount; if ( count && count[0] != '\0') { loccount = mux_atol(count); } else { loccount = 1; } if (loccount > 0) { nfy_que(thing, atr, key, loccount); if ( (!(Quiet(executor) || Quiet(thing))) && key != NFY_QUIET) { if (key == NFY_DRAIN) { notify_quiet(executor, "Drained."); } else { notify_quiet(executor, "Notified."); } } } } }
int sql_query(dbref player, char *q_string, char *buff, char **bufc, const Delim *row_delim, const Delim *field_delim) { sqlite3 *sqlite; const unsigned char *col_data; int num_rows, got_rows, got_fields; int i, j; int retries; int retval; sqlite3_stmt *stmt; const char *rest; /* * If we have no connection, and we don't have auto-reconnect on (or * we try to auto-reconnect and we fail), this is an error generating * a #-1. Notify the player, too, and set the return code. */ sqlite = sqlite3_struct; if ((!sqlite) && (mod_db_sql_config.reconnect != 0)) { /* * Try to reconnect. */ retries = 0; while ((retries < SQLITE_RETRY_TIMES) && !sqlite) { sleep(1); sql_init(0,0,NULL,NULL); sqlite = sqlite3_struct; retries++; } } if (!sqlite) { notify_quiet(player, "No SQL database connection."); if (buff) safe_str("#-1", buff, bufc); return -1; } if (!q_string || !*q_string) return 0; /* * Prepare the query. */ retval = sqlite3_prepare_v2(sqlite, q_string, -1, &stmt, &rest); if (retval != SQLITE_OK) { notify_quiet(player, sqlite3_errmsg(sqlite)); if (buff) safe_str("#-1", buff, bufc); sqlite3_finalize(stmt); return -1; } /* * Construct properly-delimited data. */ if (buff) { i = 0; while (sqlite3_step(stmt) == SQLITE_ROW) { if (i++ > 0) { print_sep(row_delim, buff, bufc); } got_fields = sqlite3_column_count(stmt); if (got_fields) { for (j = 0; j < got_fields; j++) { col_data = sqlite3_column_text(stmt, j); if (j > 0) { print_sep(field_delim, buff, bufc); } if (col_data && *col_data) safe_str((char *)col_data, buff, bufc); } } } } else { i = 0; while (sqlite3_step(stmt) == SQLITE_ROW) { if (i++ > 0) { print_sep(row_delim, buff, bufc); } got_fields = sqlite3_column_count(stmt); if (got_fields) { for (j = 0; j < got_fields; j++) { col_data = sqlite3_column_text(stmt, j); if (j > 0) { notify_check(player, player, MSG_PUP_ALWAYS|MSG_ME_ALL|MSG_F_DOWN, "Row %d, Field %d: %s", i, j + 1, col_data); } if (col_data && *col_data) { notify_check(player, player, MSG_PUP_ALWAYS|MSG_ME_ALL|MSG_F_DOWN, "Row %d, Field %d: NULL", i, j + 1); } } } } } if (i == 0) { num_rows = sqlite3_changes(sqlite); if (num_rows > 0) { notify_check(player, player, MSG_PUP_ALWAYS|MSG_ME_ALL|MSG_F_DOWN, "SQL query touched %d %s.", num_rows, (num_rows == 1) ? "row" : "rows"); } } sqlite3_finalize(stmt); return 0; }
void do_quota ( dbref executor, dbref caller, dbref enactor, int eval, int key, int nargs, UTF8 *arg1, UTF8 *arg2, const UTF8 *cargs[], int ncargs ) { UNUSED_PARAMETER(caller); UNUSED_PARAMETER(enactor); UNUSED_PARAMETER(eval); UNUSED_PARAMETER(nargs); UNUSED_PARAMETER(cargs); UNUSED_PARAMETER(ncargs); if (!(mudconf.quotas || Quota(executor))) { notify_quiet(executor, T("Quotas are not enabled.")); return; } if ((key & QUOTA_TOT) && (key & QUOTA_REM)) { notify_quiet(executor, T("Illegal combination of switches.")); return; } dbref who; int value = 0, i; bool set = false; // Show or set all quotas if requested. // if (key & QUOTA_ALL) { if (arg1 && *arg1) { value = mux_atol(arg1); set = true; } else if (key & (QUOTA_SET | QUOTA_FIX)) { value = 0; set = true; } if (set) { STARTLOG(LOG_WIZARD, "WIZ", "QUOTA"); log_name(executor); log_text(T(" changed everyone\xE2\x80\x99s quota")); ENDLOG; } DO_WHOLE_DB(i) { if (isPlayer(i)) { if (set) { mung_quotas(i, key, value); } show_quota(executor, i); } } return; } // Find out whose quota to show or set. // if (!arg1 || *arg1 == '\0') { who = Owner(executor); } else { who = lookup_player(executor, arg1, true); if (!Good_obj(who)) { notify_quiet(executor, T("Not found.")); return; } } // Make sure we have permission to do it. // if (!Quota(executor)) { if (arg2 && *arg2) { notify_quiet(executor, NOPERM_MESSAGE); return; } if (Owner(executor) != who) { notify_quiet(executor, NOPERM_MESSAGE); return; } } if (arg2 && *arg2) { set = true; value = mux_atol(arg2); } else if (key & QUOTA_FIX) { set = true; value = 0; } if (set) { STARTLOG(LOG_WIZARD, "WIZ", "QUOTA"); log_name(executor); log_text(T(" changed the quota of ")); log_name(who); ENDLOG; mung_quotas(who, key, value); } show_quota(executor, who); }