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."); } } }
/* doesn't really belong here, but I couldn't figure out where else */ void do_page(dbref player, const char *arg1, const char *arg2) { char buf[BUFFER_LEN]; dbref target; if (!payfor(player, tp_lookup_cost)) { notify_fmt(player, "You don't have enough %s.", tp_pennies); return; } if ((target = lookup_player(arg1)) == NOTHING) { notify(player, "I don't recognize that name."); return; } if (FLAGS(target) & HAVEN) { notify(player, "That player does not wish to be disturbed."); return; } if (blank(arg2)) snprintf(buf, sizeof(buf), "You sense that %s is looking for you in %s.", NAME(player), NAME(DBFETCH(player)->location)); else snprintf(buf, sizeof(buf), "%s pages from %s: \"%s\"", NAME(player), NAME(DBFETCH(player)->location), arg2); if (notify_from(player, target, buf)) notify(player, "Your message has been sent."); else { snprintf(buf, sizeof(buf), "%s is not connected.", NAME(target)); notify(player, buf); } }
/** Can someone pay for something (in cash and quota)? * Does who have enough pennies to pay for something, and if something * is being built, does who have enough quota? Wizards, roys * aren't subject to either. This function not only checks that they * can afford it, but actually charges them. * \param who player attempting to pay. * \param pennies cost in pennies. * \retval 1 who can pay. * \retval 0 who can't pay. */ int can_pay_fees(dbref who, int pennies) { if (Guest(who)) { notify(who, T("Sorry, you aren't allowed to build.")); return 0; } /* check database size -- EVERYONE is subject to this! */ if (DBTOP_MAX && (db_top >= DBTOP_MAX + 1) && (first_free == NOTHING)) { notify(who, T("Sorry, there is no more room in the database.")); return 0; } /* Can they afford it? */ if (!NoPay(who) && (Pennies(Owner(who)) < pennies)) { notify_format(who, T("Sorry, you don't have enough %s."), MONIES); return 0; } /* check building quota */ if (!pay_quota(who, QUOTA_COST)) { notify(who, T("Sorry, your building quota has run out.")); return 0; } /* charge */ payfor(who, pennies); return 1; }
/* doesn't really belong here, but I couldn't figure out where else */ void do_page(dbref player, const char *arg1, const char *arg2) { int ignored; char buf[BUFFER_LEN], buf2[BUFFER_LEN]; dbref target; if (!payfor(player, tp_lookup_cost)) { anotify_fmt(player, CFAIL "You don't have enough %s.", tp_pennies); return; } if ( strcmp(arg1, "me") ) { if ((target = lookup_player(arg1)) == NOTHING) { anotify(player, CINFO WHO_MESG); return; } } else target = player; if(Guest(player)) { if(!Mage(target)) { anotify(player, CINFO "Guests can only page " NAMEWIZ "s, type 'wizzes'."); return; } } if (FLAGS(target) & HAVEN) { anotify(player, CFAIL "That player is haven."); return; } ignored = ignoring(target, player); if(ignored == 1) { anotify(player, CFAIL "That player is ignoring you."); return; } else if(ignored == 2) { anotify(player, CINFO "That player is ignoring you."); } do_parse_mesg(player, player, arg2, "(page)", buf, MPI_ISPRIVATE); tct(buf,buf2); if (!*buf2) { sprintf(buf, CGREEN "You sense that %s is looking for you in %s.", PNAME(player), NAME(DBFETCH(player)->location)); } else { if(buf2[0] == ':' || buf2[0] == ';') { sprintf(buf, CGREEN "%s pages \"" CYELLOW "%s %.3900s" CGREEN "\"", PNAME(player), PNAME(player), buf2); } else { sprintf(buf, CGREEN "%s pages \"" CYELLOW "%.3900s" CGREEN "\"", PNAME(player), buf2); } } if (anotify_from(player, target, buf)) anotify(player, CSUCC "Your message has been sent."); else { sprintf(buf, CINFO "%s is not connected.", PNAME(target)); anotify(player, buf); } }
/* doesn't really belong here, but I couldn't figure out where else */ void do_page(int descr, dbref player, const char *arg1, const char *arg2) { char buf[BUFFER_LEN], buf2[BUFFER_LEN]; dbref target; if (!payfor(player, tp_lookup_cost)) { anotify_fmt(player, CFAIL "You don't have enough %s.", tp_pennies); return; } if (strcmp(arg1, "me")) { if ((target = lookup_player(arg1)) == NOTHING) { anotify_nolisten2(player, CINFO "Who?"); return; } } else target = player; if (Guest(player)) { if (!Mage(target)) { anotify_nolisten2(player, CINFO "Guests can only page wizards, type 'wizzes'."); return; } } if (FLAGS(target) & HAVEN) { anotify_nolisten2(player, CFAIL "That player is haven."); return; } if (Meeper(OWNER(player))) { do_parse_mesg(descr, player, player, arg2, "(page)", buf, MPI_ISPRIVATE); tct(buf, buf2); } else { tct(arg2, buf2); } if (!*buf2) { sprintf(buf, CSUCC "You sense that %s is looking for you in %s.", PNAME(player), NAME(DBFETCH(player)->location)); } else { if (buf2[0] == ':' || buf2[0] == ';') { sprintf(buf, SYSGREEN "%s pages \"" SYSYELLOW "%s %s" SYSGREEN "\"", PNAME(player), PNAME(player), buf2); } else { sprintf(buf, SYSGREEN "%s pages \"" SYSYELLOW "%s" SYSGREEN "\"", PNAME(player), buf2); } } if (anotify_from(player, target, buf)) anotify_nolisten2(player, CSUCC "Your message has been sent."); else { sprintf(buf, CSUCC "%s is not connected.", PNAME(target)); anotify_nolisten2(player, buf); } }
/** Create an exit. * This function opens an exit and optionally links it. * \param player the enactor. * \param direction the name of the exit. * \param linkto the room to link to, as a string. * \param pseudo a phony location for player if a back exit is needed. This is bpass by do_open() as the source room of the back exit. * \return dbref of the new exit, or NOTHING. */ dbref do_real_open(dbref player, const char *direction, const char *linkto, dbref pseudo) { dbref loc = (pseudo != NOTHING) ? pseudo : (IsExit(player) ? Source(player) : (IsRoom(player) ? player : Location(player))); dbref new_exit; char *flaglist, *flagname; char flagbuff[BUFFER_LEN]; char *name = NULL; char *alias = NULL; if (!command_check_byname(player, "@dig")) { notify(player, T("Permission denied.")); return NOTHING; } if ((loc == NOTHING) || (!IsRoom(loc))) { notify(player, T("Sorry, you can only make exits out of rooms.")); return NOTHING; } if (Going(loc)) { notify(player, T("You can't make an exit in a place that's crumbling.")); return NOTHING; } if (!*direction) { notify(player, T("Open where?")); return NOTHING; } else if (ok_object_name ((char *) direction, player, NOTHING, TYPE_EXIT, &name, &alias) < 1) { notify(player, T("That's a strange name for an exit!")); if (name) mush_free(name, "name.newname"); if (alias) mush_free(alias, "name.newname"); return NOTHING; } if (!Open_Anywhere(player) && !controls(player, loc)) { notify(player, T("Permission denied.")); } else if (can_pay_fees(player, EXIT_COST)) { /* create the exit */ new_exit = new_object(); /* initialize everything */ set_name(new_exit, name); if (alias && *alias != ALIAS_DELIMITER) atr_add(new_exit, "ALIAS", alias, player, 0); Owner(new_exit) = Owner(player); Zone(new_exit) = Zone(player); Source(new_exit) = loc; Type(new_exit) = TYPE_EXIT; Flags(new_exit) = new_flag_bitmask("FLAG"); strcpy(flagbuff, options.exit_flags); flaglist = trim_space_sep(flagbuff, ' '); if (*flaglist != '\0') { while (flaglist) { flagname = split_token(&flaglist, ' '); twiddle_flag_internal("FLAG", new_exit, flagname, 0); } } mush_free(name, "name.newname"); if (alias) mush_free(alias, "name.newname"); /* link it in */ PUSH(new_exit, Exits(loc)); /* and we're done */ notify_format(player, T("Opened exit %s"), unparse_dbref(new_exit)); /* check second arg to see if we should do a link */ if (linkto && *linkto != '\0') { notify(player, T("Trying to link...")); if ((loc = check_var_link(linkto)) == NOTHING) loc = parse_linkable_room(player, linkto); if (loc != NOTHING) { if (!payfor(player, LINK_COST)) { notify_format(player, T("You don't have enough %s to link."), MONIES); } else { /* it's ok, link it */ Location(new_exit) = loc; notify_format(player, T("Linked exit #%d to #%d"), new_exit, loc); } } } current_state.exits++; local_data_create(new_exit); queue_event(player, "OBJECT`CREATE", "%s", unparse_objid(new_exit)); return new_exit; } if (name) mush_free(name, "name.newname"); if (alias) mush_free(alias, "name.newname"); return NOTHING; }
/** Link an exit, room, player, or thing. * \verbatim * This is the top-level function for @link, which is used to link an * exit to a destination, set a player or thing's home, or set a * drop-to on a room. * * Linking an exit usually seizes ownership of the exit and costs 1 penny. * 1 penny is also transferred to the former owner. * \endverbatim * \param player the enactor. * \param name the name of the object to link. * \param room_name the name of the link destination. * \param preserve if 1, preserve ownership and zone data on exit relink. */ void do_link(dbref player, const char *name, const char *room_name, int preserve) { /* Use this to link to a room that you own. * It usually seizes ownership of the exit and costs 1 penny, * plus a penny transferred to the exit owner if they aren't you. * You must own the linked-to room AND specify it by room number. */ dbref thing; dbref room; if (!room_name || !*room_name) { do_unlink(player, name); return; } if (!IsRoom(player) && GoodObject(Location(player)) && IsExit(Location(player))) { notify(player, T("You somehow wound up in a exit. No biscuit.")); return; } if ((thing = noisy_match_result(player, name, TYPE_EXIT, MAT_EVERYTHING)) != NOTHING) { switch (Typeof(thing)) { case TYPE_EXIT: if ((room = check_var_link(room_name)) == NOTHING) room = parse_linkable_room(player, room_name); if (room == NOTHING) return; if (GoodObject(room) && !can_link_to(player, room)) { notify(player, T("Permission denied.")); break; } /* We may link an exit if it's unlinked and we pass the link-lock * or if we control it. */ if (!(controls(player, thing) || ((Location(thing) == NOTHING) && eval_lock(player, thing, Link_Lock)))) { notify(player, T("Permission denied.")); return; } if (preserve && !Wizard(player)) { notify(player, T("Permission denied.")); return; } /* handle costs */ if (Owner(thing) == Owner(player)) { if (!payfor(player, LINK_COST)) { notify_format(player, T("It costs %d %s to link this exit."), LINK_COST, ((LINK_COST == 1) ? MONEY : MONIES)); return; } } else { if (!payfor(player, LINK_COST + EXIT_COST)) { int a = LINK_COST + EXIT_COST; notify_format(player, T("It costs %d %s to link this exit."), a, ((a == 1) ? MONEY : MONIES)); return; } else if (!preserve) { /* pay the owner for his loss */ giveto(Owner(thing), EXIT_COST); chown_object(player, thing, player, 0); } } /* link has been validated and paid for; do it */ if (!preserve) { Owner(thing) = Owner(player); Zone(thing) = Zone(player); } Location(thing) = room; /* notify the player */ notify_format(player, T("Linked exit #%d to %s"), thing, unparse_object(player, room)); break; case TYPE_PLAYER: case TYPE_THING: if ((room = noisy_match_result(player, room_name, NOTYPE, MAT_EVERYTHING)) == NOTHING) { notify(player, T("No match.")); return; } if (IsExit(room)) { notify(player, T("That is an exit.")); return; } if (thing == room) { notify(player, T("You may not link something to itself.")); return; } /* abode */ if (!controls(player, room) && !Abode(room)) { notify(player, T("Permission denied.")); break; } if (!controls(player, thing)) { notify(player, T("Permission denied.")); } else if (room == HOME) { notify(player, T("Can't set home to home.")); } else { /* do the link */ Home(thing) = room; /* home */ if (!Quiet(player) && !(Quiet(thing) && (Owner(thing) == player))) notify(player, T("Home set.")); } break; case TYPE_ROOM: if ((room = parse_linkable_room(player, room_name)) == NOTHING) return; if ((room != HOME) && (!IsRoom(room))) { notify(player, T("That is not a room!")); return; } if (!controls(player, thing)) { notify(player, T("Permission denied.")); } else { /* do the link, in location */ Location(thing) = room; /* dropto */ notify(player, T("Dropto set.")); } break; default: notify(player, T("Internal error: weird object type.")); do_log(LT_ERR, NOTHING, NOTHING, "Weird object! Type of #%d is %d", thing, Typeof(thing)); break; } } }
void do_kill (dbref player, dbref cause, int key, char *what, char *costchar) { dbref victim; char *buf1, *buf2; int cost; init_match(player, what, TYPE_PLAYER); match_neighbor(); match_me(); match_here(); if (Wizard(player)) { match_player(); match_absolute(); } victim = match_result(); switch (victim) { case NOTHING: notify(player, "I don't see that player here."); break; case AMBIGUOUS: notify(player, "I don't know who you mean!"); break; default: if ((Typeof(victim) != TYPE_PLAYER) && (Typeof(victim) != TYPE_THING)) { notify(player, "Sorry, you can only kill players and things."); break; } if ((Haven(Location(victim)) && !Wizard(player)) || (controls(victim, Location(victim)) && !controls(player, Location(victim))) || Immortal(victim)) { notify(player, "Sorry."); break; } if (key == KILL_SLAY) { if (Builder(player) && Builder(victim)) { notify(player, "Sorry."); break; } } /* go for it */ cost = atoi(costchar); if (key == KILL_KILL) { if (HasPriv(victim,player,POWER_NOKILL,POWER4,NOTHING)) { notify(player, "Sorry."); break; } if (cost < mudconf.killmin) cost = mudconf.killmin; if (cost > mudconf.killmax) cost = mudconf.killmax; /* see if it works */ if (!payfor(player, cost)) { notify(player, unsafe_tprintf("You don't have enough %s.", mudconf.many_coins)); return; } } else { cost = 0; } if (!(((random() % mudconf.killguarantee) < cost) || (key == KILL_SLAY)) || Wizard(victim)) { /* Failure: notify player and victim only */ notify(player, "Your murder attempt failed."); buf1 = alloc_lbuf("do_kill.failed"); sprintf(buf1, "%s tried to kill you!", Name(player)); notify_with_cause(victim, player, buf1); if (Suspect(player)) { strcpy(buf1, Name(player)); if (player == Owner(player)) { raw_broadcast(0, WIZARD, "[Suspect] %s tried to kill %s(#%d).", buf1, Name(victim), victim); } else { buf2 = alloc_lbuf("do_kill.SUSP.failed"); strcpy(buf2, Name(Owner(player))); raw_broadcast(0, WIZARD, "[Suspect] %s <via %s(#%d)> tried to kill %s(#%d).", buf2, buf1, player, Name(victim), victim); free_lbuf(buf2); } } free_lbuf(buf1); break; } /* Success! You killed him */ buf1 = alloc_lbuf("do_kill.succ.1"); buf2 = alloc_lbuf("do_kill.succ.2"); if (Suspect(player)) { strcpy(buf1, Name(player)); if (player == Owner(player)) { raw_broadcast(0, WIZARD, "[Suspect] %s killed %s(#%d).", buf1, Name(victim), victim); } else { strcpy(buf2, Name(Owner(player))); raw_broadcast(0, WIZARD, "[Suspect] %s <via %s(#%d)> killed %s(#%d).", buf2, buf1, player, Name(victim), victim); } } sprintf(buf1, "You killed %s!", Name(victim)); sprintf(buf2, "killed %s!", Name(victim)); if (Typeof(victim) != TYPE_PLAYER) if (halt_que(NOTHING, victim) > 0) if (!Quiet(victim)) notify(Owner(victim), "Halted."); did_it(player, victim, A_KILL, buf1, A_OKILL, buf2, A_AKILL, (char **)NULL, 0); /* notify victim */ sprintf(buf1, "%s killed you!", Name(player)); notify_with_cause(victim, player, buf1); /* Pay off the bonus */ if (key == KILL_KILL) { cost /= 2; /* victim gets half */ if (Pennies(Owner(victim)) < mudconf.paylimit) { sprintf(buf1, "Your insurance policy pays %d %s.", cost, mudconf.many_coins); notify(victim, buf1); giveto(Owner(victim), cost, NOTHING); } else { notify(victim, "Your insurance policy has been revoked."); } } free_lbuf(buf1); free_lbuf(buf2); /* send him home */ move_via_generic(victim, HOME, NOTHING, 0); divest_object(victim); break; } }
// --------------------------------------------------------------------------- // setup_que: Set up a queue entry. // static BQUE *setup_que ( dbref executor, dbref caller, dbref enactor, int eval, char *command, int nargs, char *args[], reg_ref *sargs[] ) { // Can we run commands at all? // if (Halted(executor)) { return NULL; } // Make sure executor can afford to do it. // int a = mudconf.waitcost; if (mudconf.machinecost && RandomINT32(0, mudconf.machinecost-1) == 0) { a++; } if (!payfor(executor, a)) { notify(Owner(executor), "Not enough money to queue command."); return NULL; } // Wizards and their objs may queue up to db_top+1 cmds. Players are // limited to QUEUE_QUOTA. -mnp // a = QueueMax(Owner(executor)); if (a_Queue(Owner(executor), 1) > a) { a_Queue(Owner(executor), -1); notify(Owner(executor), "Run away objects: too many commands queued. Halted."); halt_que(Owner(executor), NOTHING); // Halt also means no command execution allowed. // s_Halted(executor); return NULL; } // We passed all the tests. // // Calculate the length of the save string. // size_t tlen = 0; static size_t nCommand; static size_t nLenEnv[NUM_ENV_VARS]; if (command) { nCommand = strlen(command) + 1; tlen = nCommand; } if (nargs > NUM_ENV_VARS) { nargs = NUM_ENV_VARS; } for (a = 0; a < nargs; a++) { if (args[a]) { nLenEnv[a] = strlen(args[a]) + 1; tlen += nLenEnv[a]; } } // Create the qeue entry and load the save string. // BQUE *tmp = alloc_qentry("setup_que.qblock"); tmp->comm = NULL; char *tptr = tmp->text = (char *)MEMALLOC(tlen); ISOUTOFMEMORY(tptr); if (command) { memcpy(tptr, command, nCommand); tmp->comm = tptr; tptr += nCommand; } for (a = 0; a < nargs; a++) { if (args[a]) { memcpy(tptr, args[a], nLenEnv[a]); tmp->env[a] = tptr; tptr += nLenEnv[a]; } else { tmp->env[a] = NULL; } } for ( ; a < NUM_ENV_VARS; a++) { tmp->env[a] = NULL; } if (sargs) { for (a = 0; a < MAX_GLOBAL_REGS; a++) { tmp->scr[a] = sargs[a]; if (sargs[a]) { RegAddRef(sargs[a]); } } } else { for (a = 0; a < MAX_GLOBAL_REGS; a++) { tmp->scr[a] = NULL; } } // Load the rest of the queue block. // tmp->executor = executor; tmp->IsTimed = false; tmp->sem = NOTHING; tmp->attr = 0; tmp->enactor = enactor; tmp->caller = caller; tmp->eval = eval; tmp->nargs = nargs; return tmp; }
void do_kill(int descr, dbref player, const char *what, int cost) { dbref victim; char buf[BUFFER_LEN]; struct match_data md; init_match(descr, player, what, TYPE_PLAYER, &md); match_neighbor(&md); match_me(&md); if (Wizard(OWNER(player))) { match_player(&md); match_absolute(&md); } victim = match_result(&md); switch (victim) { case NOTHING: notify(player, "I don't see that player here."); break; case AMBIGUOUS: notify(player, "I don't know who you mean!"); break; default: if (Typeof(victim) != TYPE_PLAYER) { notify(player, "Sorry, you can only kill other players."); } else { /* go for it */ /* set cost */ if (cost < tp_kill_min_cost) cost = tp_kill_min_cost; if (FLAGS(DBFETCH(player)->location) & HAVEN) { notify(player, "You can't kill anyone here!"); break; } if (tp_restrict_kill) { if (!(FLAGS(player) & KILL_OK)) { notify(player, "You have to be set Kill_OK to kill someone."); break; } if (!(FLAGS(victim) & KILL_OK)) { notify(player, "They don't want to be killed."); break; } } /* see if it works */ if (!payfor(player, cost)) { notify_fmt(player, "You don't have enough %s.", tp_pennies); } else if ((RANDOM() % tp_kill_base_cost) < cost && !Wizard(OWNER(victim))) { /* you killed him */ if (GETDROP(victim)) /* give him the drop message */ notify(player, GETDROP(victim)); else { snprintf(buf, sizeof(buf), "You killed %s!", NAME(victim)); notify(player, buf); } /* now notify everybody else */ if (GETODROP(victim)) { snprintf(buf, sizeof(buf), "%s killed %s! ", NAME(player), NAME(victim)); parse_oprop(descr, player, getloc(player), victim, MESGPROP_ODROP, buf, "(@Odrop)"); } else { snprintf(buf, sizeof(buf), "%s killed %s!", NAME(player), NAME(victim)); } notify_except(DBFETCH(DBFETCH(player)->location)->contents, player, buf, player); /* maybe pay off the bonus */ if (GETVALUE(victim) < tp_max_pennies) { snprintf(buf, sizeof(buf), "Your insurance policy pays %d %s.", tp_kill_bonus, tp_pennies); notify(victim, buf); SETVALUE(victim, GETVALUE(victim) + tp_kill_bonus); DBDIRTY(victim); } else { notify(victim, "Your insurance policy has been revoked."); } /* send him home */ send_home(descr, victim, 1); } else { /* notify player and victim only */ notify(player, "Your murder attempt failed."); snprintf(buf, sizeof(buf), "%s tried to kill you!", NAME(player)); notify(victim, buf); } break; } } }
void do_give(int descr, dbref player, const char *recipient, int amount) { dbref who; char buf[BUFFER_LEN]; struct match_data md; /* do amount consistency check */ if (amount < 0 && !Wizard(OWNER(player))) { notify(player, "Try using the \"rob\" command."); return; } else if (amount == 0) { notify_fmt(player, "You must specify a positive number of %s.", tp_pennies); return; } /* check recipient */ init_match(descr, player, recipient, TYPE_PLAYER, &md); match_neighbor(&md); match_me(&md); if (Wizard(OWNER(player))) { match_player(&md); match_absolute(&md); } switch (who = match_result(&md)) { case NOTHING: notify(player, "Give to whom?"); return; case AMBIGUOUS: notify(player, "I don't know who you mean!"); return; default: if (!Wizard(OWNER(player))) { if (Typeof(who) != TYPE_PLAYER) { notify(player, "You can only give to other players."); return; } else if (GETVALUE(who) + amount > tp_max_pennies) { notify_fmt(player, "That player doesn't need that many %s!", tp_pennies); return; } } break; } /* try to do the give */ if (!payfor(player, amount)) { notify_fmt(player, "You don't have that many %s to give!", tp_pennies); } else { /* he can do it */ switch (Typeof(who)) { case TYPE_PLAYER: SETVALUE(who, GETVALUE(who) + amount); if(amount >= 0) { snprintf(buf, sizeof(buf), "You give %d %s to %s.", amount, amount == 1 ? tp_penny : tp_pennies, NAME(who)); notify(player, buf); snprintf(buf, sizeof(buf), "%s gives you %d %s.", NAME(player), amount, amount == 1 ? tp_penny : tp_pennies); notify(who, buf); } else { snprintf(buf, sizeof(buf), "You take %d %s from %s.", -amount, amount == -1 ? tp_penny : tp_pennies, NAME(who)); notify(player, buf); snprintf(buf, sizeof(buf), "%s takes %d %s from you!", NAME(player), -amount, -amount == 1 ? tp_penny : tp_pennies); notify(who, buf); } break; case TYPE_THING: SETVALUE(who, (GETVALUE(who) + amount)); snprintf(buf, sizeof(buf), "You change the value of %s to %d %s.", NAME(who), GETVALUE(who), GETVALUE(who) == 1 ? tp_penny : tp_pennies); notify(player, buf); break; default: notify_fmt(player, "You can't give %s to that!", tp_pennies); break; } DBDIRTY(who); } }
/* * do_create * * Use this to create an object. */ void do_create(dbref player, char *name, char *acost) { dbref loc; dbref thing; int cost; static char buf[BUFFER_LEN]; char buf2[BUFFER_LEN]; char *rname, *qname; if (!Builder(player)) { anotify_nolisten2(player, CFAIL NOBBIT_MESG); return; } if (!tp_building || tp_db_readonly) { anotify_nolisten2(player, CFAIL NOBUILD_MESG); return; } strcpy(buf2, acost); for (rname = buf2; (*rname && (*rname != '=')); rname++) ; qname = rname; if (*rname) *(rname++) = '\0'; while ((qname > buf2) && (isspace(*qname))) *(qname--) = '\0'; qname = buf2; for (; *rname && isspace(*rname); rname++) ; cost = atoi(qname); if (*name == '\0') { anotify_nolisten2(player, CINFO "Create what?"); return; } else if (!ok_name(name)) { anotify_nolisten2(player, CINFO "That's a silly name for a thing!"); return; } else if (cost < 0) { anotify_nolisten2(player, CINFO "You can't create an object for less than nothing!"); return; } else if (cost < tp_object_cost) { cost = tp_object_cost; } if (!payfor(player, cost)) { anotify_fmt(player, CFAIL "You don't have enough %s.", tp_pennies); return; } else { /* create the object */ thing = new_object(player); /* initialize everything */ NAME(thing) = alloc_string(name); DBFETCH(thing)->location = player; OWNER(thing) = OWNER(player); DBFETCH(thing)->sp.thing.value = OBJECT_ENDOWMENT(cost); DBFETCH(thing)->exits = NOTHING; FLAGS(thing) = TYPE_THING; /* endow the object */ if (DBFETCH(thing)->sp.thing.value > tp_max_object_endowment) { DBFETCH(thing)->sp.thing.value = tp_max_object_endowment; } if ((loc = DBFETCH(player)->location) != NOTHING && controls(player, loc)) { DBFETCH(thing)->sp.thing.home = loc; /* home */ } else { DBFETCH(thing)->sp.thing.home = player; /* set thing's home to player instead */ } /* link it in */ PUSH(thing, DBFETCH(player)->contents); DBDIRTY(player); /* and we're done */ sprintf(buf, CSUCC "Object %s created.", unparse_object(player, thing)); anotify_nolisten2(player, buf); DBDIRTY(thing); } if (*rname) { PData pdat; sprintf(buf, CINFO "Registered as $%s", rname); anotify_nolisten2(player, buf); sprintf(buf, "_reg/%s", rname); pdat.flags = PROP_REFTYP; pdat.data.ref = thing; set_property(player, buf, &pdat); } }
/* * do_dig * * Use this to create a room. */ void do_dig(int descr, dbref player, const char *name, const char *pname) { char *rname, *qname; dbref newparent; char rbuf[BUFFER_LEN]; char qbuf[BUFFER_LEN]; char buf[BUFFER_LEN]; dbref room; struct match_data md; dbref parent; if (!Builder(player) && !tp_all_can_build_rooms) { anotify_nolisten2(player, CFAIL NOBBIT_MESG); return; } if (!tp_building || tp_db_readonly) { anotify_nolisten2(player, CFAIL NOBUILD_MESG); return; } if (*name == '\0') { anotify_nolisten2(player, CINFO "You need name for the room."); return; } if (!ok_name(name)) { anotify_nolisten2(player, CINFO "That's a silly name for a room!"); return; } if (!payfor(player, tp_room_cost)) { anotify_fmt(player, CFAIL "You don't have enough %s to dig a room.", tp_pennies); return; } room = new_object(player); /* Initialize everything */ newparent = DBFETCH(DBFETCH(player)->location)->location; while ((OkObj(newparent)) && !(FLAGS(newparent) & ABODE) && !(FLAG2(newparent) & F2PARENT)) newparent = DBFETCH(newparent)->location; if (!OkObj(newparent)) { if (OkObj(tp_default_parent)) newparent = tp_default_parent; else newparent = GLOBAL_ENVIRONMENT; } NAME(room) = alloc_string(name); DBFETCH(room)->location = newparent; OWNER(room) = OWNER(player); DBFETCH(room)->exits = NOTHING; DBFETCH(room)->sp.room.dropto = NOTHING; FLAGS(room) = TYPE_ROOM | (FLAGS(player) & JUMP_OK); PUSH(room, DBFETCH(newparent)->contents); DBDIRTY(room); DBDIRTY(newparent); sprintf(buf, CSUCC "Room %s created.", unparse_object(player, room)); anotify_nolisten2(player, buf); strcpy(buf, pname); for (rname = buf; (*rname && (*rname != '=')); rname++) ; qname = rname; if (*rname) *(rname++) = '\0'; while ((qname > buf) && (isspace(*qname))) *(qname--) = '\0'; qname = buf; for (; *rname && isspace(*rname); rname++) ; rname = strcpy(rbuf, rname); qname = strcpy(qbuf, qname); if (*qname) { anotify_nolisten2(player, CNOTE "Trying to set parent..."); init_match(descr, player, qname, TYPE_ROOM, &md); match_absolute(&md); match_registered(&md); match_here(&md); if ((parent = noisy_match_result(&md)) == NOTHING || parent == AMBIGUOUS) { anotify_nolisten2(player, CINFO "Parent set to default."); } else { if ((!can_link_to(player, Typeof(room), parent) && !(FLAG2(parent) & F2PARENT)) || room == parent) { anotify_nolisten2(player, CFAIL "Permission denied. Parent set to default."); } else { moveto(room, parent); sprintf(buf, CSUCC "Parent set to %s.", unparse_object(player, parent)); anotify_nolisten2(player, buf); } } } if (*rname) { PData pdat; sprintf(buf, "_reg/%s", rname); pdat.flags = PROP_REFTYP; pdat.data.ref = room; set_property(player, buf, &pdat); sprintf(buf, CINFO "Room registered as $%s", rname); anotify_nolisten2(player, buf); } }
/* do_link * * Use this to link to a room that you own. It also sets home for * objects and things, and drop-to's for rooms. * It seizes ownership of an unlinked exit, and costs 1 penny * plus a penny transferred to the exit owner if they aren't you * * All destinations must either be owned by you, or be LINK_OK. */ void do_link(int descr, dbref player, const char *thing_name, const char *dest_name) { dbref good_dest[MAX_LINKS]; int ndest, i; struct match_data md; char buf[BUFFER_LEN]; dbref thing, dest; if (tp_db_readonly) { anotify_nolisten2(player, CFAIL DBRO_MESG); return; } if (Guest(player)) { anotify_fmt(player, CFAIL "%s", tp_noguest_mesg); return; } init_match(descr, player, thing_name, TYPE_EXIT, &md); match_all_exits(&md); match_neighbor(&md); match_possession(&md); match_me(&md); match_here(&md); match_absolute(&md); match_registered(&md); if (Mage(OWNER(player))) match_player(&md); if ((thing = noisy_match_result(&md)) == NOTHING) return; switch (Typeof(thing)) { case TYPE_EXIT: /* we're ok, check the usual stuff */ if (DBFETCH(thing)->sp.exit.ndest != 0) { if (controls(player, thing)) { if ((DBFETCH(thing)->sp.exit.dest)[0] != NIL) { anotify_nolisten2(player, CINFO "That exit is already linked."); return; } } else { anotify_fmt(player, CFAIL "%s", tp_noperm_mesg); return; } } /* handle costs */ if (OWNER(thing) == OWNER(player)) { if (!payfor(player, tp_link_cost)) { anotify_fmt(player, CFAIL "It costs %d %s to link this exit.", tp_link_cost, (tp_link_cost == 1) ? tp_penny : tp_pennies); return; } } else { if (!payfor(player, tp_link_cost + tp_exit_cost)) { anotify_fmt(player, CFAIL "It costs %d %s to link this exit.", (tp_link_cost + tp_exit_cost), (tp_link_cost + tp_exit_cost == 1) ? tp_penny : tp_pennies); return; } else if (!Builder(player)) { anotify_nolisten2(player, CFAIL NOBBIT_MESG); return; } else { /* pay the owner for his loss */ dbref owner = OWNER(thing); DBFETCH(owner)->sp.player.pennies += tp_exit_cost; DBDIRTY(owner); } } /* link has been validated and paid for; do it */ OWNER(thing) = OWNER(player); if (! (ndest = link_exit(descr, player, thing, (char *) dest_name, good_dest))) { anotify_nolisten2(player, CFAIL "No destinations linked."); DBFETCH(player)->sp.player.pennies += tp_link_cost; /* Refund! */ DBDIRTY(player); break; } DBFETCH(thing)->sp.exit.ndest = ndest; if (DBFETCH(thing)->sp.exit.dest) free(DBFETCH(thing)->sp.exit.dest); DBFETCH(thing)->sp.exit.dest = (dbref *) malloc(sizeof(dbref) * ndest); for (i = 0; i < ndest; i++) (DBFETCH(thing)->sp.exit.dest)[i] = good_dest[i]; break; case TYPE_THING: case TYPE_PLAYER: init_match(descr, player, dest_name, TYPE_ROOM, &md); match_neighbor(&md); match_absolute(&md); match_registered(&md); match_me(&md); match_here(&md); match_null(&md); if (Typeof(thing) == TYPE_THING) match_possession(&md); if ((dest = noisy_match_result(&md)) == NOTHING) return; if (Typeof(thing) == TYPE_THING && dest == NIL) { anotify_fmt(player, CFAIL "%s", "You cannot HOME a THING to NIL."); return; } if (!controls(player, thing) || !can_link_to(player, Typeof(thing), dest)) { anotify_fmt(player, CFAIL "%s", tp_noperm_mesg); return; } if (parent_loop_check(thing, dest)) { anotify_nolisten2(player, CFAIL "That would cause a parent paradox."); return; } /* do the link */ if (Typeof(thing) == TYPE_THING) { DBFETCH(thing)->sp.thing.home = dest; } else DBFETCH(thing)->sp.player.home = dest; sprintf(buf, CSUCC "%s's home set to %s.", NAME(thing), unparse_object(player, dest)); anotify_nolisten2(player, buf); break; case TYPE_ROOM: /* room dropto's */ init_match(descr, player, dest_name, TYPE_ROOM, &md); match_neighbor(&md); match_possession(&md); match_registered(&md); match_absolute(&md); match_home(&md); match_null(&md); if ((dest = noisy_match_result(&md)) == NOTHING) break; if (!controls(player, thing) || !can_link_to(player, Typeof(thing), dest) || (thing == dest)) { anotify_fmt(player, CFAIL "%s", tp_noperm_mesg); } else { DBFETCH(thing)->sp.room.dropto = dest; /* dropto */ sprintf(buf, CSUCC "%s's dropto set to %s.", NAME(thing), unparse_object(player, dest)); anotify_nolisten2(player, buf); } break; case TYPE_PROGRAM: anotify_nolisten2(player, CFAIL "You can't link programs to things!"); break; default: anotify_nolisten2(player, CFAIL "Weird object type."); log_status("*BUG: weird object: Typeof(%d) = %d\n", thing, Typeof(thing)); break; } DBDIRTY(thing); return; }
/* * do_action() * * This routine attaches a new existing action to a source object, * where possible. * The action will not do anything until it is LINKed. * */ void do_action(int descr, dbref player, const char *action_name, const char *source_name) { dbref action, source; static char buf[BUFFER_LEN]; char buf2[BUFFER_LEN]; char *rname, *qname; if (!Builder(player)) { anotify_nolisten2(player, CFAIL NOBBIT_MESG); return; } if (!tp_building || tp_db_readonly) { anotify_nolisten2(player, CFAIL NOBUILD_MESG); return; } strcpy(buf2, source_name); for (rname = buf2; (*rname && (*rname != '=')); rname++) ; qname = rname; if (*rname) *(rname++) = '\0'; while ((qname > buf2) && (isspace(*qname))) *(qname--) = '\0'; qname = buf2; for (; *rname && isspace(*rname); rname++) ; if (!*action_name || !*qname) { anotify_nolisten2(player, CINFO "You must specify an action name and a source object."); return; } else if (!ok_name(action_name)) { anotify_nolisten2(player, CINFO "That's a strange name for an action!"); return; } if (((source = parse_source(descr, player, qname)) == NOTHING)) return; if (!payfor(player, tp_exit_cost)) { anotify_fmt(player, SYSRED "You don't have enough %s to make an action.", tp_pennies); return; } action = new_object(player); NAME(action) = alloc_string(action_name); DBFETCH(action)->location = NOTHING; OWNER(action) = OWNER(player); DBFETCH(action)->sp.exit.ndest = 0; DBFETCH(action)->sp.exit.dest = NULL; FLAGS(action) = TYPE_EXIT; set_source(player, action, source); sprintf(buf, CSUCC "Action %s created and attached to %s.", unparse_object(player, action), NAME(source)); anotify_nolisten2(player, buf); DBDIRTY(action); if (*rname) { PData pdat; sprintf(buf, CINFO "Registered as $%s", rname); anotify_nolisten2(player, buf); sprintf(buf, "_reg/%s", rname); pdat.flags = PROP_REFTYP; pdat.data.ref = action; set_property(player, buf, &pdat); } if (tp_autolinking) { DBFETCH(action)->sp.exit.ndest = 1; DBFETCH(action)->sp.exit.dest = (dbref *) malloc(sizeof(dbref)); (DBFETCH(action)->sp.exit.dest)[0] = NIL; sprintf(buf, CINFO "Linked to NIL."); anotify_nolisten2(player, buf); } }
/* use this to create an exit */ void do_open(int descr, dbref player, const char *direction, const char *linkto) { char *rname, *qname; dbref loc, exit = NOTHING; char buf2[BUFFER_LEN]; if (!Builder(player)) { anotify_nolisten2(player, CFAIL NOBBIT_MESG); return; } if (!tp_building || tp_db_readonly) { anotify_nolisten2(player, CFAIL NOBUILD_MESG); return; } strcpy(buf2, linkto); for (rname = buf2; (*rname && (*rname != '=')); rname++) ; qname = rname; if (*rname) rname++; qname = '\0'; while (((qname--) > buf2) && (isspace(*qname))) *qname = '\0'; qname = buf2; for (; *rname && isspace(*rname); rname++) ; if ((loc = getloc(player)) == NOTHING) return; if (!*direction) { anotify_nolisten2(player, CINFO "You must specify a direction or action name to open."); return; } else if (!ok_name(direction)) { anotify_nolisten2(player, CINFO "That's a strange name for an exit!"); return; } if (!controls(player, loc) && !(POWERS(player) & POW_OPEN_ANYWHERE)) { anotify_fmt(player, CFAIL "%s", tp_noperm_mesg); return; } else if (!payfor(player, tp_exit_cost)) { anotify_fmt(player, CFAIL "You don't have enough %s to open an exit.", tp_pennies); return; } else { char buf[BUFFER_LEN]; /* create the exit */ exit = new_object(player); /* initialize everything */ NAME(exit) = alloc_string(direction); DBFETCH(exit)->location = loc; OWNER(exit) = OWNER(player); FLAGS(exit) = TYPE_EXIT; DBFETCH(exit)->sp.exit.ndest = 0; DBFETCH(exit)->sp.exit.dest = NULL; /* link it in */ PUSH(exit, DBFETCH(loc)->exits); DBDIRTY(loc); /* and we're done */ sprintf(buf, CSUCC "Exit %s created and opened.", unparse_object(player, exit)); anotify_nolisten2(player, buf); /* check second arg to see if we should do a link */ if (*qname != '\0') { anotify_nolisten2(player, CNOTE "Trying to link..."); if (!payfor(player, tp_link_cost)) { anotify_fmt(player, CFAIL "You don't have enough %s to link.", tp_pennies); } else { dbref good_dest[MAX_LINKS]; int i; int ndest = link_exit(descr, player, exit, (char *) qname, good_dest); DBFETCH(exit)->sp.exit.ndest = ndest; DBFETCH(exit)->sp.exit.dest = (dbref *) malloc(sizeof(dbref) * ndest); for (i = 0; i < ndest; i++) { (DBFETCH(exit)->sp.exit.dest)[i] = good_dest[i]; } DBDIRTY(exit); } } } if (*rname && (exit != NOTHING)) { char buf[BUFFER_LEN]; PData pdat; sprintf(buf, CSUCC "Registered as $%s", rname); anotify_nolisten2(player, buf); snprintf(buf, sizeof(buf), "_reg/%s", rname); pdat.flags = PROP_REFTYP; pdat.data.ref = exit; set_property(player, buf, &pdat); } }