Skip to content

Commit

Permalink
Ignore set src on client verbs
Browse files Browse the repository at this point in the history
In BYOND client verbs are always visible but only executable if src is usr or world. We'll just ignore it entirely.
  • Loading branch information
wixoaGit committed Feb 10, 2024
1 parent e3655a5 commit bb18bf8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 32 deletions.
45 changes: 17 additions & 28 deletions OpenDreamClient/ClientVerbSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,30 +79,13 @@ public IEnumerable<VerbInfo> GetAllVerbs() {
seeInvisibility = _sightQuery.GetComponent(_playerManager.LocalEntity.Value).SeeInvisibility;
}

bool CanSee(VerbInfo verb, ClientObjectReference src) {
if (verb.IsHidden(ignoreHiddenAttr, seeInvisibility ?? 0))
return false; // TODO: How do invisible client verbs work when you don't have a mob?

// Check the verb's "set src" allows us to execute this
switch (verb.Accessibility) {
case VerbAccessibility.Usr:
if (!src.Equals(ourMob))
return false;

return true;
default:
// TODO: All the other kinds
return true;
}
}

// First, the verbs attached to our client
if (_clientVerbs != null) {
foreach (var verbId in _clientVerbs) {
if (!_verbs.TryGetValue(verbId, out var verb))
continue;
if (!CanSee(verb, ClientObjectReference.Client))
continue;
if (verb.IsHidden(ignoreHiddenAttr, seeInvisibility ?? 0))
continue; // TODO: How do invisible client verbs work when you don't have a mob?

yield return (verbId, ClientObjectReference.Client, verb);
}
Expand All @@ -119,10 +102,22 @@ bool CanSee(VerbInfo verb, ClientObjectReference src) {
foreach (var verbId in appearance.Verbs) {
if (!_verbs.TryGetValue(verbId, out var verb))
continue;
if (verb.IsHidden(ignoreHiddenAttr, seeInvisibility!.Value))
continue;

var src = new ClientObjectReference(_entityManager.GetNetEntity(entity));
if (!CanSee(verb, src))
continue;

// Check the verb's "set src" allows us to execute this
switch (verb.Accessibility) {
case VerbAccessibility.Usr:
if (!src.Equals(ourMob))
continue;

break;
default:
// TODO: All the other kinds
break;
}

yield return (verbId, src, verb);
}
Expand All @@ -139,14 +134,8 @@ bool CanSee(VerbInfo verb, ClientObjectReference src) {
public IEnumerable<(int Id, ClientObjectReference Src, VerbInfo VerbInfo)> GetExecutableVerbs(ClientObjectReference target) {
foreach (var verb in GetExecutableVerbs()) {
DreamValueType? targetType = verb.VerbInfo.GetTargetType();

if (targetType == null) {
// TODO: Ignore the verb if "set src =" is used instead of "set src in"
if (verb.Src.Equals(target))
yield return verb;

if (targetType == null)
continue;
}

switch (target.Type) {
case ClientObjectReference.RefType.Entity:
Expand Down
14 changes: 10 additions & 4 deletions OpenDreamRuntime/ServerVerbSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ public void RegisterVerb(DreamProc verb) {
var def = verb.OwningType.ObjectDefinition;

// Assign a default based on the type this verb is defined on
if (def.IsSubtypeOf(_objectTree.Mob) || def.IsSubtypeOf(_objectTree.Obj)) {
// TODO: Mob is "= usr" and Obj is "in usr". There is a difference when it comes to the command line.
if (def.IsSubtypeOf(_objectTree.Mob) || def.IsSubtypeOf(_objectTree.Client)) {
verbAccessibility = VerbAccessibility.Usr;
} else if (def.IsSubtypeOf(_objectTree.Obj)) {
verbAccessibility = VerbAccessibility.UsrContents;
} else if (def.IsSubtypeOf(_objectTree.Turf) || def.IsSubtypeOf(_objectTree.Area)) {
verbAccessibility = VerbAccessibility.View; // TODO: Range of 0
} else {
Expand Down Expand Up @@ -164,8 +165,13 @@ private bool CanExecute(DreamConnection connection, DreamObject src, DreamProc v
if (verb.VerbId == null) // Not even a verb
return false;

if (src is DreamObjectClient client && !client.ClientVerbs.Verbs.Contains(verb)) { // Inside client.verbs?
return false;
if (src is DreamObjectClient client) {
if (!client.ClientVerbs.Verbs.Contains(verb))
return false; // Not inside client.verbs

// Client verbs ignore "set src" checks
// Deviates from BYOND, where anything but usr and world shows the verb in the statpanel but is not executable
return true;
} else if (src is DreamObjectAtom atom) {
var appearance = _atomManager.MustGetAppearance(atom);

Expand Down

0 comments on commit bb18bf8

Please sign in to comment.