Skip to content

Commit

Permalink
Give instance permissions in instance list
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Dec 21, 2024
1 parent b9b2e6c commit 54e8c66
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
1 change: 1 addition & 0 deletions proto/src/main/proto/soulfire/instance.proto
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ message InstanceListResponse {
string id = 1;
string friendlyName = 2;
InstanceState state = 3;
repeated InstancePermissionState instancePermissions = 4;
}

repeated Instance instances = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.soulfiremc.grpc.generated.InstanceListResponse;
import com.soulfiremc.server.account.MCAuthService;
import com.soulfiremc.server.account.MinecraftAccount;
import com.soulfiremc.server.account.OfflineAuthService;
Expand Down Expand Up @@ -399,14 +398,6 @@ public CompletableFuture<?> stopAttackSession() {
});
}

public InstanceListResponse.Instance toProto() {
return InstanceListResponse.Instance.newBuilder()
.setId(id.toString())
.setFriendlyName(friendlyName)
.setState(attackLifecycle.toProto())
.build();
}

public JsonElement toJson() {
var json = new JsonObject();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package com.soulfiremc.server.grpc;

import com.soulfiremc.grpc.generated.*;
import com.soulfiremc.server.InstanceManager;
import com.soulfiremc.server.SoulFireServer;
import com.soulfiremc.server.api.AttackLifecycle;
import com.soulfiremc.server.settings.lib.SettingsImpl;
Expand Down Expand Up @@ -89,7 +88,12 @@ public void listInstances(InstanceListRequest request, StreamObserver<InstanceLi
responseObserver.onNext(InstanceListResponse.newBuilder()
.addAllInstances(soulFireServer.instances().values().stream()
.filter(instance -> ServerRPCConstants.USER_CONTEXT_KEY.get().hasPermission(PermissionContext.instance(InstancePermission.READ_INSTANCE, instance.id())))
.map(InstanceManager::toProto)
.map(instance -> InstanceListResponse.Instance.newBuilder()
.setId(instance.id().toString())
.setFriendlyName(instance.friendlyName())
.setState(instance.attackLifecycle().toProto())
.addAllInstancePermissions(getInstancePermissions(instance.id()))
.build())
.toList())
.build());
responseObserver.onCompleted();
Expand Down

0 comments on commit 54e8c66

Please sign in to comment.