Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@
class SessionClaimsTest {

@Test
void hasGameplayElevatedRoleRecognizesOnlyRequestedTenantScopedRoles() {
SessionClaims globalGod =
new SessionClaims("11", List.of("god"), Map.of("7", List.of("player")), false, null, null);
void hasGameplayElevatedRoleIgnoresGlobalRolesAndRecognizesScopedModerator() {
SessionClaims globalRoles =
new SessionClaims(
"11",
List.of("platformAdmin", "support", "billingAdmin", "god", "moderator"),
Map.of("7", List.of("player")),
false,
null,
null);
SessionClaims scopedModerator =
new SessionClaims("11", List.of(), Map.of("7", List.of("moderator")), false, null, null);

assertFalse(globalGod.hasGameplayElevatedRole("7"));
assertFalse(globalRoles.hasGameplayElevatedRole("7"));
assertTrue(scopedModerator.hasGameplayElevatedRole("7"));
}

Expand Down Expand Up @@ -45,7 +51,7 @@ void hasGameplayRoleChecksRequestedTenantScopeOnly() {
}

@Test
void controlPlanePrivilegedRoleCheckStillRecognizesGlobalRoles() {
void hasPrivilegedRoleRetainsControlPlaneGlobalRoleBehavior() {
SessionClaims claims =
new SessionClaims("11", List.of("platformAdmin"), Map.of(), false, null, null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,9 @@ private TextCommandInterpretationResult handleSummary(
response.getSummary().getRecentCount(),
response.getSummary().getPublicCount(),
response.getSummary().getFriendsOnlyCount(),
response.getSummary().getPrivateCount(),
response.getSummary().getHiddenStaffCount(),
response.getSummary().getUnspecifiedVisibilityCount(),
response.getSummary().getPrivateCount()
+ response.getSummary().getHiddenStaffCount()
+ response.getSummary().getUnspecifiedVisibilityCount(),
response.getSummary().getSharedCount(),
response.getSummary().getIsolatedCount(),
response.getSummary().getUnspecifiedScopeCount()))));
Expand Down Expand Up @@ -310,12 +310,6 @@ private TextCommandInterpretationResult handleVisibilityUpdate(
if (visibilityPolicy == null) {
return invalidUsage("FRIENDS VISIBILITY <PUBLIC|FRIENDS_ONLY|PRIVATE>");
}
if (visibilityPolicy
== net.firedevops.firemud.socialgroups.v1.FriendPresenceVisibilityPolicy
.FRIEND_PRESENCE_VISIBILITY_POLICY_HIDDEN_STAFF) {
return friendTargetError(
"INVALID_ARGUMENT", "HIDDEN_STAFF is reserved and cannot be set from gameplay");
}
UpdateFriendPresencePolicyResponse response =
socialGroupsClient.updateFriendPresencePolicy(
context.tenantId(), context.accountId(), visibilityPolicy);
Expand Down Expand Up @@ -437,6 +431,9 @@ private FriendPresenceViewOutput toView(ListFriendsResponse response, FriendList
private FriendPresenceViewOutput.Entry toEntry(int ordinal, FriendRosterEntry entry) {
FriendPresenceEntry presence = entry.getPresence();
long friendAccountId = requireFriendAccountId(entry.getFriendAccountId());
if (!isPlayerDisclosablePolicy(presence.getVisibilityPolicy())) {
return redactedEntry(ordinal, entry, friendAccountId, "Friend #" + friendAccountId);
}
String characterName =
presence.getCharacterName().isBlank() ? null : presence.getCharacterName().trim();
return new FriendPresenceViewOutput.Entry(
Expand All @@ -460,6 +457,39 @@ private FriendPresenceViewOutput.Entry toEntry(int ordinal, FriendRosterEntry en
visibilityPolicy(presence.getVisibilityPolicy()));
}

private FriendPresenceViewOutput.Entry redactedEntry(
int ordinal, FriendRosterEntry entry, long friendAccountId, String displayName) {
return new FriendPresenceViewOutput.Entry(
ordinal,
parseOptionalLong(entry.getFriendLinkId()),
friendAccountId,
blankToNull(entry.getStatus()),
entry.getCreatedAtMs() > 0 ? entry.getCreatedAtMs() : null,
displayName,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null);
}

private boolean isPlayerDisclosablePolicy(
net.firedevops.firemud.socialgroups.v1.FriendPresenceVisibilityPolicy policy) {
return policy
== net.firedevops.firemud.socialgroups.v1.FriendPresenceVisibilityPolicy
.FRIEND_PRESENCE_VISIBILITY_POLICY_PUBLIC
|| policy
== net.firedevops.firemud.socialgroups.v1.FriendPresenceVisibilityPolicy
.FRIEND_PRESENCE_VISIBILITY_POLICY_FRIENDS_ONLY;
}

private String activityState(FriendPresenceActivityState activityState) {
return switch (activityState) {
case FRIEND_PRESENCE_ACTIVITY_STATE_ACTIVE -> "ACTIVE";
Expand Down Expand Up @@ -516,7 +546,6 @@ private String visibilityPolicy(
case FRIEND_PRESENCE_VISIBILITY_POLICY_PUBLIC -> "PUBLIC";
case FRIEND_PRESENCE_VISIBILITY_POLICY_FRIENDS_ONLY -> "FRIENDS_ONLY";
case FRIEND_PRESENCE_VISIBILITY_POLICY_PRIVATE -> "PRIVATE";
case FRIEND_PRESENCE_VISIBILITY_POLICY_HIDDEN_STAFF -> "HIDDEN_STAFF";
default -> null;
};
}
Expand Down Expand Up @@ -558,16 +587,10 @@ private FriendAction parseAction(TextCommand command) {
FriendActionKind.LIST, "LIST", FriendListFilter.FRIENDS_ONLY, null, null);
case "PRIVATE" ->
new FriendAction(FriendActionKind.LIST, "LIST", FriendListFilter.PRIVATE, null, null);
case "HIDDEN_STAFF", "HIDDEN-STAFF", "HIDDEN" ->
new FriendAction(
FriendActionKind.LIST, "LIST", FriendListFilter.HIDDEN_STAFF, null, null);
case "SHARED" ->
new FriendAction(FriendActionKind.LIST, "LIST", FriendListFilter.SHARED, null, null);
case "ISOLATED" ->
new FriendAction(FriendActionKind.LIST, "LIST", FriendListFilter.ISOLATED, null, null);
case "UNSPECIFIED", "UNKNOWN", "UNSPECIFIED_VISIBILITY" ->
new FriendAction(
FriendActionKind.LIST, "LIST", FriendListFilter.UNSPECIFIED_VISIBILITY, null, null);
case "UNSCOPED", "UNKNOWN_SCOPE", "UNSPECIFIED_SCOPE" ->
new FriendAction(
FriendActionKind.LIST, "LIST", FriendListFilter.UNSPECIFIED_SCOPE, null, null);
Expand All @@ -577,7 +600,7 @@ private FriendAction parseAction(TextCommand command) {
"INVALID",
FriendListFilter.ALL,
null,
"FRIENDS [ADD|REMOVE|SHOW|SUMMARY|VISIBILITY|ONLINE|OFFLINE|RECENT|PUBLIC|FRIENDS_ONLY|PRIVATE|HIDDEN_STAFF|UNSPECIFIED_VISIBILITY|SHARED|ISOLATED|UNSPECIFIED_SCOPE]");
"FRIENDS [ADD|REMOVE|SHOW|SUMMARY|VISIBILITY|ONLINE|OFFLINE|RECENT|PUBLIC|FRIENDS_ONLY|PRIVATE|SHARED|ISOLATED|UNSPECIFIED_SCOPE]");
};
}

Expand Down Expand Up @@ -680,8 +703,6 @@ private FriendRosterFilter mapRosterFilter(FriendListFilter filter) {
case PUBLIC -> FriendRosterFilter.FRIEND_ROSTER_FILTER_PUBLIC;
case FRIENDS_ONLY -> FriendRosterFilter.FRIEND_ROSTER_FILTER_FRIENDS_ONLY;
case PRIVATE -> FriendRosterFilter.FRIEND_ROSTER_FILTER_PRIVATE;
case HIDDEN_STAFF -> FriendRosterFilter.FRIEND_ROSTER_FILTER_HIDDEN_STAFF;
case UNSPECIFIED_VISIBILITY -> FriendRosterFilter.FRIEND_ROSTER_FILTER_UNSPECIFIED_VISIBILITY;
case SHARED -> FriendRosterFilter.FRIEND_ROSTER_FILTER_SHARED;
case ISOLATED -> FriendRosterFilter.FRIEND_ROSTER_FILTER_ISOLATED;
case UNSPECIFIED_SCOPE -> FriendRosterFilter.FRIEND_ROSTER_FILTER_UNSPECIFIED_SCOPE;
Expand Down Expand Up @@ -716,37 +737,35 @@ private String notFoundMessage(String targetToken) {

private FriendPresencePolicyViewOutput friendPresencePolicyView(
net.firedevops.firemud.socialgroups.v1.FriendPresenceVisibilityPolicy current) {
net.firedevops.firemud.socialgroups.v1.FriendPresenceVisibilityPolicy effectiveCurrent =
isPlayerDisclosablePolicy(current)
? current
: net.firedevops.firemud.socialgroups.v1.FriendPresenceVisibilityPolicy
.FRIEND_PRESENCE_VISIBILITY_POLICY_PRIVATE;
return new FriendPresencePolicyViewOutput(
visibilityPolicy(current),
visibilityPolicy(effectiveCurrent),
List.of(
new FriendPresencePolicyViewOutput.Option(
"PUBLIC",
"Show the normal bounded friend-presence payload to approved social consumers.",
current
effectiveCurrent
== net.firedevops.firemud.socialgroups.v1.FriendPresenceVisibilityPolicy
.FRIEND_PRESENCE_VISIBILITY_POLICY_PUBLIC,
true),
new FriendPresencePolicyViewOutput.Option(
"FRIENDS_ONLY",
"Expose richer live identity only to approved friends.",
current
effectiveCurrent
== net.firedevops.firemud.socialgroups.v1.FriendPresenceVisibilityPolicy
.FRIEND_PRESENCE_VISIBILITY_POLICY_FRIENDS_ONLY,
true),
new FriendPresencePolicyViewOutput.Option(
"PRIVATE",
"Suppress current live character identity and expose only coarse online or recent activity.",
current
"Do not expose current presence, recent activity, or location details.",
effectiveCurrent
== net.firedevops.firemud.socialgroups.v1.FriendPresenceVisibilityPolicy
.FRIEND_PRESENCE_VISIBILITY_POLICY_PRIVATE,
true),
new FriendPresencePolicyViewOutput.Option(
"HIDDEN_STAFF",
"Reserved for staff-hidden role clamps and not set directly from gameplay.",
current
== net.firedevops.firemud.socialgroups.v1.FriendPresenceVisibilityPolicy
.FRIEND_PRESENCE_VISIBILITY_POLICY_HIDDEN_STAFF,
false)));
true)));
}

private net.firedevops.firemud.socialgroups.v1.FriendPresenceVisibilityPolicy
Expand All @@ -765,9 +784,6 @@ private FriendPresencePolicyViewOutput friendPresencePolicyView(
case "PRIVATE" ->
net.firedevops.firemud.socialgroups.v1.FriendPresenceVisibilityPolicy
.FRIEND_PRESENCE_VISIBILITY_POLICY_PRIVATE;
case "HIDDEN_STAFF" ->
net.firedevops.firemud.socialgroups.v1.FriendPresenceVisibilityPolicy
.FRIEND_PRESENCE_VISIBILITY_POLICY_HIDDEN_STAFF;
default -> null;
};
}
Expand All @@ -792,19 +808,19 @@ boolean matches(FriendPresenceViewOutput.Entry entry) {
ONLINE {
@Override
boolean matches(FriendPresenceViewOutput.Entry entry) {
return entry.online();
return Boolean.TRUE.equals(entry.online());
}
},
OFFLINE {
@Override
boolean matches(FriendPresenceViewOutput.Entry entry) {
return !entry.online();
return Boolean.FALSE.equals(entry.online());
}
},
RECENT {
@Override
boolean matches(FriendPresenceViewOutput.Entry entry) {
return !entry.online() && entry.lastSeenAtEpochMs() != null;
return Boolean.FALSE.equals(entry.online()) && entry.lastSeenAtEpochMs() != null;
}
},
PUBLIC {
Expand All @@ -822,13 +838,7 @@ boolean matches(FriendPresenceViewOutput.Entry entry) {
PRIVATE {
@Override
boolean matches(FriendPresenceViewOutput.Entry entry) {
return "PRIVATE".equals(entry.visibilityPolicy());
}
},
HIDDEN_STAFF {
@Override
boolean matches(FriendPresenceViewOutput.Entry entry) {
return "HIDDEN_STAFF".equals(entry.visibilityPolicy());
return !StringUtils.hasText(entry.visibilityPolicy());
}
},
SHARED {
Expand All @@ -843,12 +853,6 @@ boolean matches(FriendPresenceViewOutput.Entry entry) {
return "ISOLATED".equals(entry.playableStateScope());
}
},
UNSPECIFIED_VISIBILITY {
@Override
boolean matches(FriendPresenceViewOutput.Entry entry) {
return !StringUtils.hasText(entry.visibilityPolicy());
}
},
UNSPECIFIED_SCOPE {
@Override
boolean matches(FriendPresenceViewOutput.Entry entry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ public TextCommandInterpretationResult handle(
"FRIENDS\n"
+ "List your linked friends with bounded cross-game presence.\n"
+ "FRIENDS SUMMARY shows canonical linked/online/offline/recent counts.\n"
+ "FRIENDS ONLINE, FRIENDS OFFLINE, FRIENDS RECENT, FRIENDS PUBLIC, FRIENDS FRIENDS_ONLY, FRIENDS PRIVATE, FRIENDS HIDDEN_STAFF, FRIENDS UNSPECIFIED_VISIBILITY, FRIENDS SHARED, FRIENDS ISOLATED, and FRIENDS UNSPECIFIED_SCOPE filter the same canonical roster without widening WHO.\n"
+ "FRIENDS ONLINE, FRIENDS OFFLINE, FRIENDS RECENT, FRIENDS PUBLIC, FRIENDS FRIENDS_ONLY, FRIENDS PRIVATE, FRIENDS SHARED, FRIENDS ISOLATED, and FRIENDS UNSPECIFIED_SCOPE filter the same canonical roster without widening WHO.\n"
+ "FRIENDS SHOW <friendAccountId|characterName|#entryNumber> shows one canonical friend roster entry in detail, including #entryNumber lookups from the rendered roster.\n"
+ "FRIENDS ADD <friendAccountId|characterName> links another account-scoped friend.\n"
+ "FRIENDS REMOVE <friendAccountId|characterName|#entryNumber> removes an existing account-scoped friend, including canonical #entryNumber removal.\n"
+ "FRIENDS VISIBILITY shows your current cross-game friend-presence policy, and FRIENDS VISIBILITY <PUBLIC|FRIENDS_ONLY|PRIVATE> updates it.\n"
+ "Visible entries show current world/realm labels, character name, and activity state when policy allows.\n"
+ "Private or hidden-staff friends stay conservative.");
+ "Private friends stay conservative.");
case "INVENTORY" ->
success(
"INVENTORY shows what you are carrying.\n"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.firedevops.firemud.gamesession.presentation;

import com.fasterxml.jackson.annotation.JsonInclude;
import java.util.List;

public record FriendPresenceViewOutput(
Expand All @@ -9,14 +10,15 @@ public record FriendPresenceViewOutput(
friends = List.copyOf(friends);
}

@JsonInclude(JsonInclude.Include.NON_NULL)
public record Entry(
int ordinal,
Long friendLinkId,
long friendAccountId,
String status,
Long linkedAtEpochMs,
String displayName,
boolean online,
Boolean online,
String worldSlug,
String worldDisplayName,
String realmSlug,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ public record FriendRosterSummaryViewOutput(
int publicCount,
int friendsOnlyCount,
int privateCount,
int hiddenStaffCount,
int unspecifiedVisibilityCount,
int sharedCount,
int isolatedCount,
int unspecifiedScopeCount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,10 +555,6 @@ private String renderFriendRosterSummaryView(FriendRosterSummaryViewOutput outpu
+ output.friendsOnlyCount()
+ "\nVisibility private: "
+ output.privateCount()
+ "\nVisibility hidden-staff: "
+ output.hiddenStaffCount()
+ "\nVisibility unspecified: "
+ output.unspecifiedVisibilityCount()
+ "\nScope shared: "
+ output.sharedCount()
+ "\nScope isolated: "
Expand Down Expand Up @@ -595,7 +591,10 @@ private String renderFriendStatusSuffix(FriendPresenceViewOutput.Entry entry) {
}

private String renderFriendStatus(FriendPresenceViewOutput.Entry entry) {
if (entry.online()) {
if (isRedactedFriendPresence(entry)) {
return "presence unavailable";
}
if (Boolean.TRUE.equals(entry.online())) {
StringBuilder line = new StringBuilder("online");
String location = renderFriendLocation(entry);
if (StringUtils.hasText(location)) {
Expand Down Expand Up @@ -626,6 +625,21 @@ private String renderFriendStatus(FriendPresenceViewOutput.Entry entry) {
return "offline";
}

private boolean isRedactedFriendPresence(FriendPresenceViewOutput.Entry entry) {
return !StringUtils.hasText(entry.visibilityPolicy())
&& !Boolean.TRUE.equals(entry.online())
&& entry.lastSeenAtEpochMs() == null
&& !StringUtils.hasText(entry.worldSlug())
&& !StringUtils.hasText(entry.worldDisplayName())
&& !StringUtils.hasText(entry.realmSlug())
&& !StringUtils.hasText(entry.realmDisplayName())
&& !StringUtils.hasText(entry.characterName())
&& !StringUtils.hasText(entry.playableStateScope())
&& entry.pointerVersion() == null
&& !StringUtils.hasText(entry.activityState())
&& !StringUtils.hasText(entry.recentDisposition());
}

private String renderFriendLocation(FriendPresenceViewOutput.Entry entry) {
if (StringUtils.hasText(entry.worldDisplayName())
&& StringUtils.hasText(entry.realmDisplayName())) {
Expand All @@ -638,6 +652,9 @@ private String renderFriendLocation(FriendPresenceViewOutput.Entry entry) {
}

private String renderFriendActivity(String activityState) {
if (!StringUtils.hasText(activityState)) {
return null;
}
return switch (activityState) {
case "AUTO_AFK" -> "idle";
case "EXPLICIT_AFK" -> "AFK";
Expand Down
Loading
Loading