From 43b5c62bf2705c7c54bca9804fe213129eae917d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20Demirta=C5=9F?= Date: Wed, 12 Apr 2023 06:51:19 +0300 Subject: [PATCH] update agones. (#33) --- .run/build.run.xml | 4 +- build.gradle.kts | 2 +- .../com/infumia/agones4j/AgonesAlphaSdk.java | 129 ++++++++++++++ .../tr/com/infumia/agones4j/AgonesSdk.java | 20 ++- src/main/proto/sdk/alpha/alpha.proto | 165 +++++++++++++++++- src/main/proto/sdk/sdk.proto | 22 +++ 6 files changed, 334 insertions(+), 8 deletions(-) diff --git a/.run/build.run.xml b/.run/build.run.xml index 3852126..9bdb6c5 100644 --- a/.run/build.run.xml +++ b/.run/build.run.xml @@ -1,5 +1,5 @@ - + \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 7d3ba19..b0adb39 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -113,7 +113,7 @@ spotless { isEnforceCheck = false java { - target("**/tr/com/infumia/agones4j/**") + target("**/src/main/java/tr/com/infumia/agones4j/**") importOrder() removeUnusedImports() endWithNewline() diff --git a/src/main/java/tr/com/infumia/agones4j/AgonesAlphaSdk.java b/src/main/java/tr/com/infumia/agones4j/AgonesAlphaSdk.java index f898122..0beabc6 100644 --- a/src/main/java/tr/com/infumia/agones4j/AgonesAlphaSdk.java +++ b/src/main/java/tr/com/infumia/agones4j/AgonesAlphaSdk.java @@ -3,6 +3,7 @@ import agones.dev.sdk.Sdk; import agones.dev.sdk.alpha.Alpha; import agones.dev.sdk.alpha.SDKGrpc; +import com.google.protobuf.FieldMask; import io.grpc.ManagedChannel; import io.grpc.stub.StreamObserver; import lombok.AccessLevel; @@ -30,6 +31,29 @@ public final class AgonesAlphaSdk { this.stub = SDKGrpc.newStub(channel); } + /** + * adds a value to a list and returns updated list. returns NOT_FOUND if the list does not exist. returns + * ALREADY_EXISTS if the value is already in the list. returns OUT_OF_RANGE if the list is already at Capacity. + * + * @param name the name to add. + * @param value the value to add. + * @param observer the observer to add. + */ + public void addList( + @NotNull final String name, + @NotNull final String value, + @NotNull final StreamObserver observer + ) { + this.stub.addListValue( + Alpha.AddListValueRequest + .newBuilder() + .setName(name) + .setValue(value) + .build(), + observer + ); + } + /** * returns the list of the currently connected player ids. * this is always accurate from what has been set through this SDK, even if the value has yet to be updated on the @@ -46,6 +70,38 @@ public void getConnectedPlayers( this.stub.getConnectedPlayers(Alpha.Empty.getDefaultInstance(), observer); } + /** + * gets a counter. returns NOT_FOUND if the counter does not exist. + * + * @param name the name of the counter. + * @param observer the observer to get counter. + */ + public void getCounter( + @NotNull final String name, + @NotNull final StreamObserver observer + ) { + this.stub.getCounter( + Alpha.GetCounterRequest.newBuilder().setName(name).build(), + observer + ); + } + + /** + * gets a list. returns NOT_FOUND if the List does not exist. + * + * @param name the name to get. + * @param observer the observer to get. + */ + public void getList( + @NotNull final String name, + @NotNull final StreamObserver observer + ) { + this.stub.getList( + Alpha.GetListRequest.newBuilder().setName(name).build(), + observer + ); + } + /** * retrieves the current player capacity. * this is always accurate from what has been set through this SDK, even if the value has yet to be updated on the @@ -225,6 +281,29 @@ public void playerDisconnect( ); } + /** + * removes a value from a list and returns updated list. returns NOT_FOUND if the list does not exist. returns + * NOT_FOUND if the value is not in the list. + * + * @param name the name to remove. + * @param value the value to remove. + * @param observer the observer to add. + */ + public void removeList( + @NotNull final String name, + @NotNull final String value, + @NotNull final StreamObserver observer + ) { + this.stub.removeListValue( + Alpha.RemoveListValueRequest + .newBuilder() + .setName(name) + .setValue(value) + .build(), + observer + ); + } + /** * update the {@link Sdk.GameServer.Status.PlayerStatus#getCapacity()} value with a new capacity. * @@ -237,4 +316,54 @@ public void setPlayerCapacity( ) { this.stub.setPlayerCapacity(capacity, observer); } + + /** + * returns the updated counter. returns NOT_FOUND if the counter does not exist (name cannot be updated). returns + * OUT_OF_RANGE if the count is out of range [0,Capacity]. returns INVALID_ARGUMENT if the field mask path(s) are not + * field(s) of the counter. if a field mask path(s) is specified, but the value is not set in the request counter + * object, then the default value for the variable will be set (i.e. 0 for "capacity" or "count"). + * + * @param counter the counter to update. + * @param updateMask the update mask to update. + * @param observer the observer to update. + */ + public void updateCounter( + @NotNull final Alpha.Counter counter, + @NotNull final FieldMask updateMask, + @NotNull final StreamObserver observer + ) { + this.stub.updateCounter( + Alpha.UpdateCounterRequest + .newBuilder() + .setCounter(counter) + .setUpdateMask(updateMask) + .build(), + observer + ); + } + + /** + * returns the updated list. returns NOT_FOUND if the list does not exist (name cannot be updated). + *

+ * **THIS WILL OVERWRITE ALL EXISTING LIST.VALUES WITH ANY REQUEST LIST.VALUES** + *

+ * use addListValue() or removeListValue() for modifying the List.Values field. + * returns INVALID_ARGUMENT if the field mask path(s) are not field(s) of the list. + * + * @param observer the observer to update. + */ + public void updateList( + @NotNull final Alpha.List list, + @NotNull final FieldMask updateMask, + @NotNull final StreamObserver observer + ) { + this.stub.updateList( + Alpha.UpdateListRequest + .newBuilder() + .setList(list) + .setUpdateMask(updateMask) + .build(), + observer + ); + } } diff --git a/src/main/java/tr/com/infumia/agones4j/AgonesSdk.java b/src/main/java/tr/com/infumia/agones4j/AgonesSdk.java index 7bf4234..850257a 100644 --- a/src/main/java/tr/com/infumia/agones4j/AgonesSdk.java +++ b/src/main/java/tr/com/infumia/agones4j/AgonesSdk.java @@ -47,6 +47,18 @@ public final class AgonesSdk implements Terminable { @NotNull SDKGrpc.SDKStub stub; + /** + * ctor. + * + * @param channel the channel. + */ + public AgonesSdk(@NotNull final ManagedChannel channel) { + this.channel = channel; + this.stub = SDKGrpc.newStub(this.channel); + this.alpha = new AgonesAlphaSdk(this.channel); + this.beta = new AgonesBetaSdk(this.channel); + } + /** * ctor. * @@ -54,14 +66,12 @@ public final class AgonesSdk implements Terminable { * @param grpcPort the grpc port. */ public AgonesSdk(@NotNull final String grpcHost, final int grpcPort) { - this.channel = + this( ManagedChannelBuilder .forAddress(grpcHost, grpcPort) .usePlaintext() - .build(); - this.stub = SDKGrpc.newStub(this.channel); - this.alpha = new AgonesAlphaSdk(this.channel); - this.beta = new AgonesBetaSdk(this.channel); + .build() + ); } /** diff --git a/src/main/proto/sdk/alpha/alpha.proto b/src/main/proto/sdk/alpha/alpha.proto index e774b9d..d255923 100644 --- a/src/main/proto/sdk/alpha/alpha.proto +++ b/src/main/proto/sdk/alpha/alpha.proto @@ -18,6 +18,11 @@ package agones.dev.sdk.alpha; option go_package = "./alpha"; import "google/api/annotations.proto"; +import "google/api/client.proto"; +import "google/api/field_behavior.proto"; +import "google/api/resource.proto"; +import "google/protobuf/empty.proto"; +import "google/protobuf/field_mask.proto"; import "grpc-gateway/protoc-gen-openapiv2/options/annotations.proto"; option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = { @@ -122,6 +127,68 @@ service SDK { get: "/alpha/player/connected" }; } + + // Gets a Counter. Returns NOT_FOUND if the Counter does not exist. + rpc GetCounter(GetCounterRequest) returns (Counter) { + option (google.api.http) = { + get: "/v1alpha1/{name=counters/*}" + }; + option (google.api.method_signature) = "name"; + } + + // UpdateCounter returns the updated Counter. Returns NOT_FOUND if the Counter does not exist (name cannot be updated). + // Returns OUT_OF_RANGE if the Count is out of range [0,Capacity]. + // Returns INVALID_ARGUMENT if the field mask path(s) are not field(s) of the Counter. + // If a field mask path(s) is specified, but the value is not set in the request Counter object, + // then the default value for the variable will be set (i.e. 0 for "capacity" or "count"). + rpc UpdateCounter(UpdateCounterRequest) returns (Counter) { + option (google.api.http) = { + patch: "/v1alpha1/{counter.name=counters/*}" + body: "counter" + }; + option (google.api.method_signature) = "counter,update_mask"; + } + + // Gets a List. Returns NOT_FOUND if the List does not exist. + rpc GetList(GetListRequest) returns (List) { + option (google.api.http) = { + get: "/v1alpha1/{name=lists/*}" + }; + option (google.api.method_signature) = "name"; + } + + // UpdateList returns the updated List. Returns NOT_FOUND if the List does not exist (name cannot be updated). + // **THIS WILL OVERWRITE ALL EXISTING LIST.VALUES WITH ANY REQUEST LIST.VALUES** + // Use AddListValue() or RemoveListValue() for modifying the List.Values field. + // Returns INVALID_ARGUMENT if the field mask path(s) are not field(s) of the List. + // If a field mask path(s) is specified, but the value is not set in the request List object, + // then the default value for the variable will be set (i.e. 0 for "capacity", empty list for "values"). + rpc UpdateList(UpdateListRequest) returns (List) { + option (google.api.http) = { + patch: "/v1alpha1/{list.name=lists/*}" + body: "list" + }; + option (google.api.method_signature) = "list,update_mask"; + } + + // Adds a value to a List and returns updated List. Returns NOT_FOUND if the List does not exist. + // Returns ALREADY_EXISTS if the value is already in the List. + // Returns OUT_OF_RANGE if the List is already at Capacity. + rpc AddListValue(AddListValueRequest) returns (List) { + option (google.api.http) = { + post: "/v1alpha1/{name=lists/*}:addValue" + body: "*" + }; + } + + // Removes a value from a List and returns updated List. Returns NOT_FOUND if the List does not exist. + // Returns NOT_FOUND if the value is not in the List. + rpc RemoveListValue(RemoveListValueRequest) returns (List) { + option (google.api.http) = { + post: "/v1alpha1/{name=lists/*}:removeValue" + body: "*" + }; + } } // I am Empty @@ -146,4 +213,100 @@ message PlayerID { // List of Player IDs message PlayerIDList { repeated string list = 1; -} \ No newline at end of file +} + +// A representation of a Counter. +message Counter { + option (google.api.resource) = { + type: "agones.dev/Counter" + pattern: "counters/{counter}" + }; + // The name of the Counter + string name = 1; + // The current count of the Counter + int64 count = 2; + // The maximum capacity of the Counter + int64 capacity = 3; +} + +message GetCounterRequest { + // The name of the Counter to get + string name = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "agones.dev/Counter" + }]; +} + +message UpdateCounterRequest { + // The Counter to update + Counter counter = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "agones.dev/Counter" + }]; + + // Required. Mask (list) of fields to update. + // Fields are specified relative to the Counter + // (e.g. `count`, `capacity`; *not* `Counter.count` or `Counter.capacity`). + google.protobuf.FieldMask update_mask = 2 [(google.api.field_behavior) = REQUIRED]; +} + +// A representation of a List. +message List { + option (google.api.resource) = { + type: "agones.dev/List" + pattern: "lists/{list}" + }; + // The name of the List + string name = 1; + // The maximum capacity of the List + int64 capacity = 2; + // The array of items in the List ["v1", "v2", …] + repeated string values = 3; +} + +message GetListRequest { + // The name of the List to get + string name = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "agones.dev/List" + }]; +} + +message UpdateListRequest { + // The List to update + List list = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "agones.dev/List" + }]; + + // Required. Mask (list) of fields to update. + // Fields are specified relative to the List + // (e.g. `capacity`, `values`; *not* `List.capacity` or `List.values`). + google.protobuf.FieldMask update_mask = 2 [(google.api.field_behavior) = REQUIRED]; +} + +message AddListValueRequest { + // The name of the List to add a value to. + string name = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "agones.dev/List" + }]; + + string value = 2 [(google.api.field_behavior) = REQUIRED]; +} + +message RemoveListValueRequest { + // The name of the List to remove a value from. + string name = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "agones.dev/List" + }]; + + string value = 2 [(google.api.field_behavior) = REQUIRED]; +} diff --git a/src/main/proto/sdk/sdk.proto b/src/main/proto/sdk/sdk.proto index aa5bb9e..df5b499 100644 --- a/src/main/proto/sdk/sdk.proto +++ b/src/main/proto/sdk/sdk.proto @@ -162,6 +162,20 @@ message GameServer { repeated string ids = 3; } + // [Stage:Alpha] + // [FeatureFlag:CountsAndLists] + message CounterStatus { + int64 count = 1; + int64 capacity = 2; + } + + // [Stage:Alpha] + // [FeatureFlag:CountsAndLists] + message ListStatus { + int64 capacity = 1; + repeated string values = 2; + } + string state = 1; string address = 2; repeated Port ports = 3; @@ -169,5 +183,13 @@ message GameServer { // [Stage:Alpha] // [FeatureFlag:PlayerTracking] PlayerStatus players = 4; + + // [Stage:Alpha] + // [FeatureFlag:CountsAndLists] + map counters = 5; + + // [Stage:Alpha] + // [FeatureFlag:CountsAndLists] + map lists = 6; } }