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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The service runtime model assumes replaceable workers, not authoritative in-proc

The sections below define the target-state runtime contract. Current implementation and proof status is:

- Game Session V11 adds nullable `gameplay_command.account_uuid` storage and repository round-trip mapping alongside the retained numeric `account_id`. Historical commands remain without an inferred UUID, and no producer or session carrier supplies or consumes this field yet. The focused migration and repository PostgreSQL cases are present but skip locally while Docker is disabled; Account UUID ownership remains in [Account Runtime and Data](../account-service/runtime-and-data.md) under [ADR 0020](../../decisions/adr-0020-scoped-domain-and-operational-identifiers.md).
- Game Session V11 adds nullable `gameplay_command.account_uuid` storage and repository round-trip mapping alongside the retained numeric `account_id`. Historical commands remain without an inferred UUID, and no producer or session carrier supplies or consumes this field yet; opaque internal carrier preparation and its retained-record/proof limits are tracked in [Player Access and Session](../../../project-management/implementation-tracking/player-access-and-session.md#current-status). The focused migration and repository PostgreSQL cases are present but skip locally while Docker is disabled; Account UUID ownership remains in [Account Runtime and Data](../account-service/runtime-and-data.md) under [ADR 0020](../../decisions/adr-0020-scoped-domain-and-operational-identifiers.md).

- The current effective-settings HTTP read is admitted by the service-wide `PRIVILEGED` role requirement, whose shared classifier accepts any global privileged role or any tenant-scoped `tenantAdmin`/`moderator` claim. `EffectiveSettingsController` then trusts query tenant/game selectors and session ids: it can synthesize a requested tenant scope without binding it to the caller's scoped role, or resolve a persisted session without checking that its tenant is authorized by the caller. The current controller/integration tests do not prove denial of a tenant-A caller reading tenant-B settings.
- **Target effective-settings boundary:** keep this as a read-only operator surface but make authorization route-aware. Bind a tenant-scoped role to the exact target tenant and require persisted session tenant ownership/equality; allow a global `platformAdmin` branch to select a tenant only with current operator authorization, target-tenant generation, and `privileged_control`. Reject ambiguous/missing target authority, tenant/session mismatches, and unavailable owner/session evidence before invoking any resolver. The negative proof must cover scoped cross-tenant synthetic and persisted-session reads and the global branch without privileged control.
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ private String sessionAttestation(
return gameplaySessionAttestationService.issueGameplaySessionAttestation(
Long.toString(context.tenantId()),
Long.toString(context.sessionId()),
Long.toString(context.accountId()),
context.accountId(),
Long.toString(context.characterId()),
gameInstanceId,
canonicalRoomId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ public SendCommunicationResponse sendCommunication(
String tenantId = Long.toString(context.tenantId());
String sessionId = Long.toString(context.sessionId());
String characterId = Long.toString(context.characterId());
String accountId = Long.toString(context.accountId());
String accountId = context.accountId();
String gameInstanceId = Long.toString(context.gameInstanceId());
SendCommunicationRequest request =
SendCommunicationRequest.newBuilder()
.setTenantId(tenantId)
.setSessionId(sessionId)
.setCharacterId(characterId)
.setAccountId(accountId)
.setAccountId(accountId == null ? "" : accountId)
.setRoomInstance(
RoomInstanceRef.newBuilder()
.setTenantId(tenantId)
Expand Down Expand Up @@ -346,7 +346,7 @@ public PickupItemFromRoomResponse pickupVisibleRoomItem(
SessionContext context, String itemReference, int quantity, String effectId) {
String tenantId = Long.toString(context.tenantId());
String sessionId = Long.toString(context.sessionId());
String accountId = Long.toString(context.accountId());
String accountId = context.accountId();
String characterId = Long.toString(context.characterId());
String gameInstanceId = Long.toString(context.gameInstanceId());
String roomInstanceId =
Expand All @@ -355,7 +355,7 @@ public PickupItemFromRoomResponse pickupVisibleRoomItem(
PickupVisibleRoomItemRequest.newBuilder()
.setTenantId(tenantId)
.setSessionId(sessionId)
.setAccountId(accountId)
.setAccountId(accountId == null ? "" : accountId)
.setCharacterId(characterId)
.setGameInstanceId(gameInstanceId)
.setRoomInstanceId(roomInstanceId)
Expand Down Expand Up @@ -449,7 +449,7 @@ public DropItemToRoomResponse dropCarriedItem(
SessionContext context, String itemReference, int quantity, String effectId) {
String tenantId = Long.toString(context.tenantId());
String sessionId = Long.toString(context.sessionId());
String accountId = Long.toString(context.accountId());
String accountId = context.accountId();
String characterId = Long.toString(context.characterId());
String gameInstanceId = Long.toString(context.gameInstanceId());
String roomInstanceId =
Expand All @@ -458,7 +458,7 @@ public DropItemToRoomResponse dropCarriedItem(
DropCarriedItemRequest.newBuilder()
.setTenantId(tenantId)
.setSessionId(sessionId)
.setAccountId(accountId)
.setAccountId(accountId == null ? "" : accountId)
.setCharacterId(characterId)
.setGameInstanceId(gameInstanceId)
.setRoomInstanceId(roomInstanceId)
Expand Down Expand Up @@ -720,7 +720,7 @@ private String sessionAttestation(SessionContext context, String roomId) {
return gameplaySessionAttestationService.issueGameplaySessionAttestation(
Long.toString(context.tenantId()),
Long.toString(context.sessionId()),
Long.toString(context.accountId()),
context.accountId(),
Long.toString(context.characterId()),
Long.toString(context.gameInstanceId()),
canonicalRoomId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ public TextCommandInterpretationResult handle(TextCommand command, SessionContex
if (action.kind() == FriendActionKind.INVALID) {
return invalidUsage(action.invalidUsage());
}
TextCommandInterpretationResult usageFailure = validateUsage(action);
if (usageFailure != null) {
return usageFailure;
}
try {
numericAccountId(context);
} catch (IllegalArgumentException ex) {
return accountIdUnavailable(action);
}
if (action.kind() == FriendActionKind.LIST) {
return handleList(context, action.listFilter(), rawCommandText);
}
Expand Down Expand Up @@ -105,15 +114,79 @@ public TextCommandInterpretationResult handle(TextCommand command, SessionContex
};
}

private TextCommandInterpretationResult validateUsage(FriendAction action) {
if (action.kind() == FriendActionKind.DETAIL && !StringUtils.hasText(action.targetToken())) {
return invalidUsage("FRIENDS SHOW <friendAccountId|characterName|#entryNumber>");
}
if ((action.kind() == FriendActionKind.ADD || action.kind() == FriendActionKind.REMOVE)
&& !StringUtils.hasText(action.targetToken())) {
return invalidUsage("FRIENDS " + action.keyword() + " <friendAccountId|characterName>");
}
if (action.kind() == FriendActionKind.REMOVE
&& isOrdinalToken(action.targetToken())
&& parseOrdinal(action.targetToken()) <= 0) {
return invalidUsage("FRIENDS REMOVE <friendAccountId|characterName|#entryNumber>");
}
if (action.kind() == FriendActionKind.DETAIL
&& isOrdinalToken(action.targetToken())
&& parseOrdinal(action.targetToken()) <= 0) {
return invalidUsage("FRIENDS SHOW <friendAccountId|characterName|#entryNumber>");
}
if (action.kind() == FriendActionKind.VISIBILITY && StringUtils.hasText(action.targetToken())) {
net.firedevops.firemud.socialgroups.v1.FriendPresenceVisibilityPolicy visibilityPolicy =
parseVisibilityPolicy(action.targetToken());
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");
}
}
return null;
}

private TextCommandInterpretationResult accountIdUnavailable(FriendAction action) {
String code =
switch (action.kind()) {
case LIST -> "FRIEND_PRESENCE_UNAVAILABLE";
case ADD -> "FRIEND_ADD_UNAVAILABLE";
case REMOVE -> "FRIEND_REMOVE_UNAVAILABLE";
case DETAIL -> "FRIEND_DETAIL_UNAVAILABLE";
case SUMMARY -> "FRIEND_SUMMARY_UNAVAILABLE";
case VISIBILITY ->
StringUtils.hasText(action.targetToken())
? "FRIEND_VISIBILITY_UPDATE_UNAVAILABLE"
: "FRIEND_VISIBILITY_UNAVAILABLE";
case INVALID -> "INVALID_ARGUMENT";
};
String message =
switch (code) {
case "FRIEND_PRESENCE_UNAVAILABLE" -> "Friend presence unavailable";
case "FRIEND_ADD_UNAVAILABLE" -> "Friend add unavailable";
case "FRIEND_REMOVE_UNAVAILABLE" -> "Friend removal unavailable";
case "FRIEND_DETAIL_UNAVAILABLE" -> "Friend detail unavailable";
case "FRIEND_SUMMARY_UNAVAILABLE" -> "Friend roster summary unavailable";
case "FRIEND_VISIBILITY_UNAVAILABLE" -> "Friend presence visibility unavailable";
case "FRIEND_VISIBILITY_UPDATE_UNAVAILABLE" ->
"Friend presence visibility update unavailable";
default -> "Friend command unavailable";
};
return new TextCommandInterpretationResult(
CommandEnqueueResult.failure(code, message), List.of(PlayerOutput.error(code, message)));
}

private TextCommandInterpretationResult handleList(
SessionContext context, FriendListFilter filter, String rawCommandText) {
ListFriendsResponse response =
filter == FriendListFilter.ALL
? socialGroupsClient.listFriends(context.tenantId(), context.accountId())
? socialGroupsClient.listFriends(context.tenantId(), numericAccountId(context))
: socialGroupsClient.listFriends(
context.tenantId(), context.accountId(), mapRosterFilter(filter));
context.tenantId(), numericAccountId(context), mapRosterFilter(filter));
if (response == null && filter != FriendListFilter.ALL) {
response = socialGroupsClient.listFriends(context.tenantId(), context.accountId());
response = socialGroupsClient.listFriends(context.tenantId(), numericAccountId(context));
}
if (response.hasError()) {
String message =
Expand All @@ -137,13 +210,13 @@ private TextCommandInterpretationResult handleList(

private TextCommandInterpretationResult handleAdd(
SessionContext context, ResolvedFriendTarget target, String rawCommandText) {
if (target.friendAccountId() == context.accountId()) {
if (target.friendAccountId() == numericAccountId(context)) {
return friendTargetError(
"FRIEND_SELF_LINK_FORBIDDEN", "Cannot add or remove your own account as a friend");
}
AddFriendResponse response =
socialGroupsClient.addFriend(
context.tenantId(), context.accountId(), target.friendAccountId());
context.tenantId(), numericAccountId(context), target.friendAccountId());
if (response.hasError() || !response.getSuccess()) {
String message =
response.hasError() && !response.getError().getMessage().isBlank()
Expand All @@ -161,13 +234,13 @@ private TextCommandInterpretationResult handleAdd(

private TextCommandInterpretationResult handleRemove(
SessionContext context, ResolvedFriendTarget target, String rawCommandText) {
if (target.friendAccountId() == context.accountId()) {
if (target.friendAccountId() == numericAccountId(context)) {
return friendTargetError(
"FRIEND_SELF_LINK_FORBIDDEN", "Cannot add or remove your own account as a friend");
}
RemoveFriendResponse response =
socialGroupsClient.removeFriend(
context.tenantId(), context.accountId(), target.friendAccountId());
context.tenantId(), numericAccountId(context), target.friendAccountId());
if (response.hasError() || !response.getSuccess()) {
String message =
response.hasError() && !response.getError().getMessage().isBlank()
Expand All @@ -187,7 +260,7 @@ private TextCommandInterpretationResult handleDetail(
SessionContext context, ResolvedFriendTarget target, String rawCommandText) {
GetFriendResponse response =
socialGroupsClient.getFriend(
context.tenantId(), context.accountId(), target.friendAccountId());
context.tenantId(), numericAccountId(context), target.friendAccountId());
if (response.hasError()) {
String code =
"NOT_FOUND".equalsIgnoreCase(response.getError().getCode())
Expand Down Expand Up @@ -221,7 +294,8 @@ private TextCommandInterpretationResult handleDetailByOrdinal(
return invalidUsage("FRIENDS SHOW <friendAccountId|characterName|#entryNumber>");
}
GetFriendByOrdinalResponse response =
socialGroupsClient.getFriendByOrdinal(context.tenantId(), context.accountId(), ordinal);
socialGroupsClient.getFriendByOrdinal(
context.tenantId(), numericAccountId(context), ordinal);
if (response.hasError()) {
String code =
"NOT_FOUND".equalsIgnoreCase(response.getError().getCode())
Expand Down Expand Up @@ -251,7 +325,7 @@ private TextCommandInterpretationResult handleDetailByOrdinal(
private TextCommandInterpretationResult handleSummary(
SessionContext context, String rawCommandText) {
GetFriendRosterSummaryResponse response =
socialGroupsClient.getFriendRosterSummary(context.tenantId(), context.accountId());
socialGroupsClient.getFriendRosterSummary(context.tenantId(), numericAccountId(context));
if (response.hasError()) {
String message =
response.getError().getMessage().isBlank()
Expand Down Expand Up @@ -284,7 +358,7 @@ private TextCommandInterpretationResult handleSummary(
private TextCommandInterpretationResult handleVisibilityView(
SessionContext context, String rawCommandText) {
GetFriendPresencePolicyResponse response =
socialGroupsClient.getFriendPresencePolicy(context.tenantId(), context.accountId());
socialGroupsClient.getFriendPresencePolicy(context.tenantId(), numericAccountId(context));
if (response.hasError()) {
String code =
response.getError().getCode().isBlank()
Expand Down Expand Up @@ -318,7 +392,7 @@ private TextCommandInterpretationResult handleVisibilityUpdate(
}
UpdateFriendPresencePolicyResponse response =
socialGroupsClient.updateFriendPresencePolicy(
context.tenantId(), context.accountId(), visibilityPolicy);
context.tenantId(), numericAccountId(context), visibilityPolicy);
if (response.hasError() || !response.getSuccess()) {
String code =
response.hasError() && !response.getError().getCode().isBlank()
Expand Down Expand Up @@ -349,7 +423,8 @@ private TextCommandInterpretationResult handleRemoveByOrdinal(
return invalidUsage("FRIENDS REMOVE <friendAccountId|characterName|#entryNumber>");
}
RemoveFriendByOrdinalResponse response =
socialGroupsClient.removeFriendByOrdinal(context.tenantId(), context.accountId(), ordinal);
socialGroupsClient.removeFriendByOrdinal(
context.tenantId(), numericAccountId(context), ordinal);
if (response.hasError() || !response.getSuccess()) {
String code =
response.hasError() && "NOT_FOUND".equalsIgnoreCase(response.getError().getCode())
Expand Down Expand Up @@ -483,6 +558,11 @@ private long requireFriendAccountId(String value) {
}
}

private long numericAccountId(SessionContext context) {
return PositiveLongParsing.requireOptionalText(context.accountId(), "accountId")
.orElseThrow(() -> new IllegalArgumentException("accountId must be positive"));
}

private Long parseOptionalLong(String value) {
return PositiveLongParsing.parseOptionalText(value, "friendLinkId")
.optionalValue()
Expand Down
Loading
Loading