Skip to content

Commit

Permalink
update agones. (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
portlek authored Apr 12, 2023
1 parent da400ed commit 43b5c62
Show file tree
Hide file tree
Showing 6 changed files with 334 additions and 8 deletions.
4 changes: 3 additions & 1 deletion .run/build.run.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration name="build" default="false" type="GradleRunConfiguration" factoryName="Gradle">
<configuration default="false" name="build" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="executionName"/>
<option name="externalProjectPath" value="$PROJECT_DIR$"/>
Expand All @@ -11,13 +11,15 @@
<option name="taskNames">
<list>
<option value="build"/>
<option value="spotlessApply"/>
</list>
</option>
<option name="vmOptions"/>
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<ForceTestExec>false</ForceTestExec>
<method v="2"/>
</configuration>
</component>
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ spotless {
isEnforceCheck = false

java {
target("**/tr/com/infumia/agones4j/**")
target("**/src/main/java/tr/com/infumia/agones4j/**")
importOrder()
removeUnusedImports()
endWithNewline()
Expand Down
129 changes: 129 additions & 0 deletions src/main/java/tr/com/infumia/agones4j/AgonesAlphaSdk.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Alpha.List> 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
Expand All @@ -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<Alpha.Counter> 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<Alpha.List> 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
Expand Down Expand Up @@ -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<Alpha.List> 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.
*
Expand All @@ -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<Alpha.Counter> 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).
* <p>
* **THIS WILL OVERWRITE ALL EXISTING LIST.VALUES WITH ANY REQUEST LIST.VALUES**
* <p>
* 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<Alpha.List> observer
) {
this.stub.updateList(
Alpha.UpdateListRequest
.newBuilder()
.setList(list)
.setUpdateMask(updateMask)
.build(),
observer
);
}
}
20 changes: 15 additions & 5 deletions src/main/java/tr/com/infumia/agones4j/AgonesSdk.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,31 @@ 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.
*
* @param grpcHost the grpc host.
* @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()
);
}

/**
Expand Down
Loading

0 comments on commit 43b5c62

Please sign in to comment.