Skip to content

Commit

Permalink
Merge pull request #736 from wyld-sw/master
Browse files Browse the repository at this point in the history
Implicity define a program's home as its owner.
  • Loading branch information
tanabi authored Nov 8, 2024
2 parents ad67f9a + 7d27d1c commit 01a9b93
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/create.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ do_link(int descr, dbref player, const char *thing_name, const char *dest_name)

break;
case TYPE_PROGRAM:
notify(player, "You can't link programs to things!");
notify(player, "Program links cannot be modified.");
break;
default:
notify(player, "Internal error: weird object type.");
Expand Down
3 changes: 3 additions & 0 deletions src/mfuns2.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ mfn_links(MFUNARGS)
}

case TYPE_PROGRAM:
obj = OWNER(obj);
break;

default:
return "#-1";
}
Expand Down
52 changes: 31 additions & 21 deletions src/p_db.c
Original file line number Diff line number Diff line change
Expand Up @@ -1525,15 +1525,6 @@ prim_getlink(PRIM_PROTOTYPE)

CHECKREMOTE(oper1->data.objref);

/**
* @TODO A years-old suggestion would have this returning the
* link of a program as the home of its owner. Does this
* make sense?
*/
if (Typeof(oper1->data.objref) == TYPE_PROGRAM) {
abort_interp("Illegal object referenced.");
}

/**
* @TODO Combine with other link resolution logic as possible.
*/
Expand All @@ -1555,6 +1546,10 @@ prim_getlink(PRIM_PROTOTYPE)
ref = DBFETCH(oper1->data.objref)->sp.room.dropto;
break;

case TYPE_PROGRAM:
ref = OWNER(oper1->data.objref);
break;

default:
ref = NOTHING;
break;
Expand Down Expand Up @@ -1595,10 +1590,6 @@ prim_getlinks(PRIM_PROTOTYPE)

CHECKREMOTE(oper1->data.objref);

if (Typeof(oper1->data.objref) == TYPE_PROGRAM) {
abort_interp("Illegal object referenced.");
}

my_obj = oper1->data.objref;

switch (Typeof(my_obj)) {
Expand Down Expand Up @@ -1645,6 +1636,16 @@ prim_getlinks(PRIM_PROTOTYPE)

break;

case TYPE_PROGRAM:
CHECKOFLOW(2);

ref = OWNER(my_obj);

count = 1;

PushObject(ref);
break;

default:
count = 0;
break;
Expand Down Expand Up @@ -1750,19 +1751,24 @@ prim_setlink(PRIM_PROTOTYPE)
oper1 = POP(); /* dbref: destination */
oper2 = POP(); /* dbref: source */

if (!valid_object(oper1)) {
if (!valid_object(oper1) && oper1->data.objref != NOTHING) {
abort_interp("Invalid object. (2)");
}

if (!valid_object(oper2)) {
abort_interp("Invalid object. (1)");
}

ref = oper2->data.objref;

/**
* @TODO Combine with other link setting logic as possible.
*/

ref = oper2->data.objref;

if (Typeof(ref) == TYPE_PROGRAM) {
abort_interp("Program links cannot be modified. (1)");
}

if (oper1->data.objref == NOTHING) {
if ((mlev < 4) && !permissions(ProgUID, ref)) {
abort_interp("Permission denied.");
Expand All @@ -1784,16 +1790,12 @@ prim_setlink(PRIM_PROTOTYPE)
DBSTORE(ref, sp.room.dropto, NOTHING);
}
} else {
if (Typeof(ref) == TYPE_PROGRAM) {
abort_interp("Program objects are not linkable. (1)");
}

if (!prog_can_link_to(mlev, ProgUID, Typeof(ref), oper1->data.objref)) {
abort_interp("Can't link source to destination.");
}

if ((mlev < 4) && !permissions(ProgUID, ref)) {
abort_interp("Permission denied.");
abort_interp("Permission denied.");
}

switch (Typeof(ref)) {
Expand Down Expand Up @@ -3488,6 +3490,10 @@ array_getlinks(dbref obj, int pinned)
array_set_intkey_refval(&nw, count++, PLAYER_HOME(obj));
break;

case TYPE_PROGRAM:
array_set_intkey_refval(&nw, count++, OWNER(obj));
break;

case TYPE_EXIT:
for (count = 0; count < (DBFETCH(obj)->sp.exit.ndest); count++) {
array_set_intkey_refval(&nw, count, (DBFETCH(obj)->sp.exit.dest)[count]);
Expand Down Expand Up @@ -3962,6 +3968,10 @@ prim_setlinks_array(PRIM_PROTOTYPE)
case TYPE_ROOM:
break;

case TYPE_PROGRAM:
CLEAR(&idx);
abort_interp("Program links cannot be modified. (2)");

default:
CLEAR(&idx);
abort_interp("Invalid object. (1)");
Expand Down
2 changes: 1 addition & 1 deletion src/predicates.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ can_link_to(dbref who, object_flag_type what_type, dbref where)
&& (Typeof(where) == TYPE_EXIT || Typeof(where) == TYPE_PROGRAM))
return 0;

/* Programs cannot be linked */
/* Program links cannot be modified */
if (what_type == TYPE_PROGRAM)
return 0;

Expand Down
5 changes: 4 additions & 1 deletion src/set.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ _do_unlink(int descr, dbref player, const char *name, bool quiet)
if (!quiet)
notify(player, "Player's home reset to default player start room.");

break;
case TYPE_PROGRAM:
notify(player, "Program links cannot be modified.");
break;
default:
notify(player, "You can't unlink that!");
Expand Down Expand Up @@ -361,7 +364,7 @@ do_relink(int descr, dbref player, const char *thing_name,

break;
case TYPE_PROGRAM:
notify(player, "You can't link programs to things!");
notify(player, "Program links cannot be modified.");
return;
default:
notify(player, "Internal error: weird object type.");
Expand Down

0 comments on commit 01a9b93

Please sign in to comment.