dbref create_player(const char *name, const char *password) { dbref player; if (!ok_player_name(name) || !ok_password(password)) return NOTHING; /* else he doesn't already exist, create him */ player = new_object(); /* initialize everything */ NAME(player) = alloc_string(name); DBFETCH(player)->location = tp_player_start; /* home */ FLAGS(player) = TYPE_PLAYER | PCREATE_FLAGS; OWNER(player) = player; DBFETCH(player)->sp.player.home = tp_player_start; DBFETCH(player)->exits = NOTHING; DBFETCH(player)->sp.player.pennies = tp_start_pennies; DBFETCH(player)->sp.player.password = NULL; // handle this last DBFETCH(player)->sp.player.curr_prog = NOTHING; DBFETCH(player)->sp.player.insert_mode = 0; /* link him to tp_player_start */ PUSH(player, DBFETCH(tp_player_start)->contents); add_player(player); DBDIRTY(player); DBDIRTY(tp_player_start); set_password(player, password); return player; }
/* Use this to create a program. First, find a program that matches that name. If there's one, then we put him into edit mode and do it. Otherwise, we create a new object for him, and call it a program. */ void do_prog(int descr, dbref player, const char *name) { dbref i; struct match_data md; if (Typeof(player) != TYPE_PLAYER) { anotify_nolisten2(player, CFAIL "Only players can edit programs."); return; } else if (!Mucker(player)) { anotify_nolisten2(player, CFAIL NOMBIT_MESG); return; } else if (!tp_building || tp_db_readonly) { anotify_nolisten2(player, CFAIL NOBUILD_MESG); return; } else if (!*name) { anotify_nolisten2(player, CINFO "No program name given."); return; } init_match(descr, player, name, TYPE_PROGRAM, &md); match_possession(&md); match_neighbor(&md); match_registered(&md); match_absolute(&md); if ((i = match_result(&md)) == NOTHING) { i = new_program(OWNER(player), name); FLAGS(i) |= INTERNAL; DBFETCH(player)->sp.player.curr_prog = i; anotify_fmt(player, CSUCC "Program %s created with number %d.", name, i); anotify_nolisten2(player, CINFO "Entering editor."); } else if (i == AMBIGUOUS) { anotify_nolisten2(player, CINFO "I don't know which one you mean!"); return; } else { if ((Typeof(i) != TYPE_PROGRAM) || !controls(player, i)) { anotify_fmt(player, CFAIL "%s", tp_noperm_mesg); return; } else if (FLAGS(i) & INTERNAL) { anotify_nolisten2(player, CFAIL NOEDIT_MESG); return; } DBFETCH(i)->sp.program.first = read_program(i); FLAGS(i) |= INTERNAL; DBFETCH(player)->sp.player.curr_prog = i; anotify_fmt(player, CINFO "Entering editor for %s.", unparse_object(player, i)); /* list current line */ do_list(player, i, 0, 0, 0); DBDIRTY(i); } FLAGS(player) |= INTERACTIVE; DBDIRTY(player); }
void do_edit(int descr, dbref player, const char *name) { dbref i; struct match_data md; if (Typeof(player) != TYPE_PLAYER) { anotify_nolisten2(player, CFAIL "Only players can edit programs."); return; } else if (!Mucker(player)) { anotify_nolisten2(player, CFAIL NOMBIT_MESG); return; } else if (tp_db_readonly) { anotify_nolisten2(player, CFAIL DBRO_MESG); return; } else if (!*name) { anotify_nolisten2(player, CINFO "No program name given."); return; } init_match(descr, player, name, TYPE_PROGRAM, &md); match_possession(&md); match_neighbor(&md); match_registered(&md); match_absolute(&md); if ((i = noisy_match_result(&md)) == NOTHING || i == AMBIGUOUS) return; if ((Typeof(i) != TYPE_PROGRAM) || !controls(player, i)) { anotify_fmt(player, CFAIL "%s", tp_noperm_mesg); return; } else if (FLAGS(i) & INTERNAL) { anotify_nolisten2(player, CFAIL NOEDIT_MESG); return; } FLAGS(i) |= INTERNAL; DBFETCH(i)->sp.program.first = read_program(i); DBFETCH(player)->sp.player.curr_prog = i; anotify_fmt(player, CINFO "Entering editor for %s.", unparse_object(player, i)); /* list current line */ do_list(player, i, 0, 0, 0); FLAGS(player) |= INTERACTIVE; DBDIRTY(i); DBDIRTY(player); }
/* removes property list --- if it's not there then ignore */ void remove_property_list(dbref player, int all) { PropPtr l; PropPtr p; PropPtr n; /* if( tp_db_readonly ) return; *//* Why did we remove this? */ #ifdef DISKBASE fetchprops(player); #endif if ((l = DBFETCH(player)->properties)) { p = first_node(l); while (p) { n = next_node(l, PropName(p)); remove_proplist_item(player, p, all); l = DBFETCH(player)->properties; p = n; } } #ifdef DISKBASE dirtyprops(player); #endif DBDIRTY(player); }
void do_rob(int descr, dbref player, const char *what) { dbref thing; 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_absolute(&md); match_player(&md); } thing = match_result(&md); switch (thing) { case NOTHING: notify(player, "Rob whom?"); break; case AMBIGUOUS: notify(player, "I don't know who you mean!"); break; default: if (Typeof(thing) != TYPE_PLAYER) { notify(player, "Sorry, you can only rob other players."); } else if (GETVALUE(thing) < 1) { snprintf(buf, sizeof(buf), "%s has no %s.", NAME(thing), tp_pennies); notify(player, buf); snprintf(buf, sizeof(buf), "%s tried to rob you, but you have no %s to take.", NAME(player), tp_pennies); notify(thing, buf); } else if (can_doit(descr, player, thing, "Your conscience tells you not to.")) { /* steal a penny */ SETVALUE(OWNER(player), GETVALUE(OWNER(player)) + 1); DBDIRTY(player); SETVALUE(thing, GETVALUE(thing) - 1); DBDIRTY(thing); notify_fmt(player, "You stole a %s.", tp_penny); snprintf(buf, sizeof(buf), "%s stole one of your %s!", NAME(player), tp_pennies); notify(thing, buf); } break; } }
/* quit from edit mode. Put player back into the regular game mode */ void do_quit(dbref player, dbref program) { log_status("PROGRAM SAVED: %s by %s(%d)", unparse_object(player, program), NAME(player), player); write_program(PROGRAM_FIRST(program), program); if (tp_log_programs) log_program_text(PROGRAM_FIRST(program), player, program); free_prog_text(PROGRAM_FIRST(program)); PROGRAM_SET_FIRST(program, NULL); FLAGS(program) &= ~INTERNAL; FLAGS(player) &= ~INTERACTIVE; PLAYER_SET_CURR_PROG(player, NOTHING); DBDIRTY(player); DBDIRTY(program); }
void ts_useobject(dbref thing) { if (thing == NOTHING) return; DBFETCH(thing)->ts.lastused = current_systime; DBFETCH(thing)->ts.usecount++; DBDIRTY(thing); if (Typeof(thing) == TYPE_ROOM) ts_useobject(DBFETCH(thing)->location); }
void set_property(dbref object, const char *pname, PData * dat) { #ifdef DISKBASE fetchprops(object); set_property_nofetch(object, pname, dat, 0); dirtyprops(object); #else set_property_nofetch(object, pname, dat, 0); #endif DBDIRTY(object); }
void set_property(dbref player, const char *type, int flags, PTYPE value) { /* if( tp_db_readonly ) return; *//* Why did we remove this? */ #ifdef DISKBASE fetchprops(player); set_property_nofetch(player, type, flags, (PTYPE) value); dirtyprops(player); #else set_property_nofetch(player, type, flags, (PTYPE) value); #endif DBDIRTY(player); }
/* adds a new property to an object */ void add_property(dbref player, const char *type, const char *pclass, int value) { #ifdef DISKBASE fetchprops(player); add_prop_nofetch(player, type, pclass, value); dirtyprops(player); #else add_prop_nofetch(player, type, pclass, value); #endif DBDIRTY(player); }
dbref create_player(const char *name, const char *password) { char buf[80]; dbref player; if (!ok_player_name(name) || !ok_password(password)) return NOTHING; if (!tp_building || tp_db_readonly) return NOTHING; /* else he doesn't already exist, create him */ player = new_object(); /* initialize everything */ NAME(player) = alloc_string(name); FLAGS(player) = TYPE_PLAYER | PCREATE_FLAGS; FLAG2(player) = PCREATE_FLAG2; DBFETCH(player)->location = RootRoom; /* home */ OWNER(player) = player; DBFETCH(player)->sp.player.home = RootRoom; DBFETCH(player)->exits = NOTHING; DBFETCH(player)->sp.player.pennies = tp_start_pennies; DBFETCH(player)->sp.player.password = alloc_string(password); DBFETCH(player)->sp.player.curr_prog = NOTHING; DBFETCH(player)->sp.player.insert_mode = 0; /* link him to tp_player_start */ PUSH(player, DBFETCH(RootRoom)->contents); add_player(player); DBDIRTY(player); DBDIRTY(RootRoom); sprintf(buf, CNOTE "%s is born!", PNAME(player)); anotify_except(DBFETCH(RootRoom)->contents, NOTHING, buf, player); return player; }
/* Removes 'cost' value from 'who', and returns 1 if the act has been * paid for, else returns 0. */ int payfor(dbref who, int cost) { who = OWNER(who); /* Wizards don't have to pay for anything. */ if (Wizard(who)) { return 1; } else if (GETVALUE(who) >= cost) { SETVALUE(who, GETVALUE(who) - cost); DBDIRTY(who); return 1; } else { return 0; } }
void moveto(dbref what, dbref where) { dbref loc; /* do NOT move garbage */ if (what != NOTHING && Typeof(what) == TYPE_GARBAGE) { return; } if(what != NOTHING && parent_loop_check(what, where)) { /* Prevent stupid loop holes elsewhere */ return; } /* remove what from old loc */ if ((loc = DBFETCH(what)->location) != NOTHING) { DBSTORE(loc, contents, remove_first(DBFETCH(loc)->contents, what)); } /* test for special cases */ switch (where) { case NOTHING: DBSTORE(what, location, NOTHING); return; /* NOTHING doesn't have contents */ case HOME: switch (Typeof(what)) { case TYPE_PLAYER: where = DBFETCH(what)->sp.player.home; break; case TYPE_THING: where = DBFETCH(what)->sp.thing.home; if (parent_loop_check(what, where)) where = DBFETCH(OWNER(what))->sp.player.home; break; case TYPE_ROOM: where = GLOBAL_ENVIRONMENT; break; case TYPE_PROGRAM: where = OWNER(what); break; } } /* now put what in where */ PUSH(what, DBFETCH(where)->contents); DBDIRTY(where); DBSTORE(what, location, where); }
/* Given a dbref and a cost, subtracts the cost from the player's * pennies and returns 1. Returns 0 if the player could not afford * it. */ bool payfor(dbref who, int cost) { if (who == NOTHING) return 1; who = OWNER(who); if (Mage(who) || (POWERS(who) & POW_NO_PAY)) { return 1; } else if (DBFETCH(who)->sp.player.pennies >= cost) { DBFETCH(who)->sp.player.pennies -= cost; DBDIRTY(who); return 1; } else return 0; }
/* * set_source() * * This routine sets the source of an action to the specified source. * It is called by do_action and do_attach. * */ void set_source(dbref player, dbref action, dbref source) { switch (Typeof(source)) { case TYPE_ROOM: case TYPE_THING: case TYPE_PLAYER: PUSH(action, DBFETCH(source)->exits); break; default: anotify_nolisten2(player, CFAIL "Weird object type."); log_status("*BUG: tried to source %d to %d: type: %d\n", action, source, Typeof(source)); return; break; } DBDIRTY(source); DBSTORE(action, location, source); return; }
/* removes property --- if it's not there then ignore */ void remove_property_nofetch(dbref player, const char *type) { PropPtr l; char buf[BUFFER_LEN]; char *w; /* if( tp_db_readonly ) return; *//* Why did we remove this? */ w = strcpy(buf, type); l = DBFETCH(player)->properties; l = propdir_delete_elem(l, w); DBFETCH(player)->properties = l; if ((FLAGS(player) & LISTENER) && !(get_property(player, "_listen") || get_property(player, "_olisten") || get_property(player, "~listen") || get_property(player, "~olisten") || get_property(player, "@olisten") || get_property(player, "@listen") || get_property(player, "_alisten") || get_property(player, "_aolisten") || get_property(player, "~alisten") || get_property(player, "~aolisten") || get_property(player, "@aolisten") || get_property(player, "@alisten") )) { FLAGS(player) &= ~LISTENER; } if ((FLAG2(player) & F2COMMAND) && !(get_property(player, "_command") || get_property(player, "_ocommand") || get_property(player, "~command") || get_property(player, "~ocommand") || get_property(player, "@ocommand") || get_property(player, "@command") )) { FLAG2(player) &= ~F2COMMAND; } DBDIRTY(player); }
/* 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; }
void do_toad(int descr, dbref player, const char *name, const char *recip) { dbref victim; dbref recipient; dbref stuff; char buf[BUFFER_LEN]; if (!Wizard(player) || Typeof(player) != TYPE_PLAYER) { notify(player, "Only a Wizard player can turn a person into a toad."); return; } if ((victim = lookup_player(name)) == NOTHING) { notify(player, "That player does not exist."); return; } #ifdef GOD_PRIV if (God(victim)) { notify(player, "You cannot @toad God."); if(!God(player)) { log_status("TOAD ATTEMPT: %s(#%d) tried to toad God.",NAME(player),player); } return; } #endif if(player == victim) { /* If GOD_PRIV isn't defined, this could happen: we don't want the * last wizard to be toaded, in any case, so only someone else can * do it. */ notify(player, "You cannot toad yourself. Get someone else to do it for you."); return; } if (victim == tp_toad_default_recipient) { notify(player, "That player is part of the @toad process, and cannot be deleted."); return; } if (!*recip) { recipient = tp_toad_default_recipient; } else { if ((recipient = lookup_player(recip)) == NOTHING || recipient == victim) { notify(player, "That recipient does not exist."); return; } } if (Typeof(victim) != TYPE_PLAYER) { notify(player, "You can only turn players into toads!"); #ifdef GOD_PRIV } else if (!(God(player)) && (TrueWizard(victim))) { #else } else if (TrueWizard(victim)) { #endif notify(player, "You can't turn a Wizard into a toad."); } else { /* we're ok */ /* do it */ send_contents(descr, victim, HOME); dequeue_prog(victim, 0); /* Dequeue the programs that the player's running */ for (stuff = 0; stuff < db_top; stuff++) { if (OWNER(stuff) == victim) { switch (Typeof(stuff)) { case TYPE_PROGRAM: dequeue_prog(stuff, 0); /* dequeue player's progs */ if (TrueWizard(recipient)) { FLAGS(stuff) &= ~(ABODE | WIZARD); SetMLevel(stuff, 1); } case TYPE_ROOM: case TYPE_THING: case TYPE_EXIT: OWNER(stuff) = recipient; DBDIRTY(stuff); break; } } if (Typeof(stuff) == TYPE_THING && THING_HOME(stuff) == victim) { THING_SET_HOME(stuff, tp_lost_and_found); } } chown_macros(victim, recipient); if (PLAYER_PASSWORD(victim)) { free((void *) PLAYER_PASSWORD(victim)); PLAYER_SET_PASSWORD(victim, 0); } /* notify people */ notify(victim, "You have been turned into a toad."); snprintf(buf, sizeof(buf), "You turned %s into a toad!", NAME(victim)); notify(player, buf); log_status("TOADED: %s(%d) by %s(%d)", NAME(victim), victim, NAME(player), player); /* reset name */ delete_player(victim); snprintf(buf, sizeof(buf), "A slimy toad named %s", NAME(victim)); free((void *) NAME(victim)); NAME(victim) = alloc_string(buf); DBDIRTY(victim); boot_player_off(victim); /* Disconnect the toad */ if (PLAYER_DESCRS(victim)) { free(PLAYER_DESCRS(victim)); PLAYER_SET_DESCRS(victim, NULL); PLAYER_SET_DESCRCOUNT(victim, 0); } ignore_remove_from_all_players(victim); ignore_flush_cache(victim); FREE_PLAYER_SP(victim); ALLOC_THING_SP(victim); THING_SET_HOME(victim, PLAYER_HOME(player)); FLAGS(victim) = TYPE_THING; OWNER(victim) = player; /* you get it */ SETVALUE(victim, 1); /* don't let him keep his immense wealth */ } }
dbref create_player(dbref creator, const char *name, const char *password) { char buf[BUFFER_LEN]; struct object *newp; dbref player; if (!ok_player_name(name) || !ok_password(password) || tp_db_readonly) return NOTHING; /* remove any existing alias with this name */ clear_alias(0, name); /* else he doesn't already exist, create him */ player = new_object(creator); newp = DBFETCH(player); /* initialize everything */ NAME(player) = alloc_string(name); FLAGS(player) = TYPE_PLAYER; if (OkObj(tp_player_prototype) && (Typeof(tp_player_prototype) == TYPE_PLAYER)) { FLAGS(player) = FLAGS(tp_player_prototype); FLAG2(player) = FLAG2(tp_player_prototype); if (tp_pcreate_copy_props) { newp->properties = copy_prop(tp_player_prototype); #ifdef DISKBASE newp->propsfpos = 0; newp->propsmode = PROPS_UNLOADED; newp->propstime = 0; newp->nextold = NOTHING; newp->prevold = NOTHING; dirtyprops(player); #endif } } if (OkObj(tp_player_start)) { DBFETCH(player)->location = tp_player_start; DBFETCH(player)->sp.player.home = tp_player_start; } else { DBFETCH(player)->location = GLOBAL_ENVIRONMENT; DBFETCH(player)->sp.player.home = GLOBAL_ENVIRONMENT; } OWNER(player) = player; newp->exits = NOTHING; newp->sp.player.pennies = tp_start_pennies; newp->sp.player.password = NULL; /* this has to stay here. -hinoserm */ newp->sp.player.curr_prog = NOTHING; newp->sp.player.insert_mode = 0; #ifdef IGNORE_SUPPORT newp->sp.player.ignoretime = 0; #endif /* IGNORE_SUPPORT */ /* set password */ set_password(player, password); /* link him to tp_player_start */ PUSH(player, DBFETCH(tp_player_start)->contents); add_player(player); DBDIRTY(player); DBDIRTY(tp_player_start); sprintf(buf, CNOTE "%s is born!", NAME(player)); anotify_except(DBFETCH(tp_player_start)->contents, NOTHING, buf, player); return player; }
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 prim_debug_off(PRIM_PROTOTYPE) { FLAGS(program) &= ~DARK; DBDIRTY(program); }
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); } }
void prim_debug_on(PRIM_PROTOTYPE) { FLAGS(program) |= DARK; DBDIRTY(program); }
/* * 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); } }
/* 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); } }
/* * 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); } }