Skip to content

Commit 43b5c62

Browse files
authored
update agones. (#33)
1 parent da400ed commit 43b5c62

File tree

6 files changed

+334
-8
lines changed

6 files changed

+334
-8
lines changed

.run/build.run.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<component name="ProjectRunConfigurationManager">
2-
<configuration name="build" default="false" type="GradleRunConfiguration" factoryName="Gradle">
2+
<configuration default="false" name="build" type="GradleRunConfiguration" factoryName="Gradle">
33
<ExternalSystemSettings>
44
<option name="executionName"/>
55
<option name="externalProjectPath" value="$PROJECT_DIR$"/>
@@ -11,13 +11,15 @@
1111
<option name="taskNames">
1212
<list>
1313
<option value="build"/>
14+
<option value="spotlessApply"/>
1415
</list>
1516
</option>
1617
<option name="vmOptions"/>
1718
</ExternalSystemSettings>
1819
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
1920
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
2021
<DebugAllEnabled>false</DebugAllEnabled>
22+
<ForceTestExec>false</ForceTestExec>
2123
<method v="2"/>
2224
</configuration>
2325
</component>

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ spotless {
113113
isEnforceCheck = false
114114

115115
java {
116-
target("**/tr/com/infumia/agones4j/**")
116+
target("**/src/main/java/tr/com/infumia/agones4j/**")
117117
importOrder()
118118
removeUnusedImports()
119119
endWithNewline()

src/main/java/tr/com/infumia/agones4j/AgonesAlphaSdk.java

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import agones.dev.sdk.Sdk;
44
import agones.dev.sdk.alpha.Alpha;
55
import agones.dev.sdk.alpha.SDKGrpc;
6+
import com.google.protobuf.FieldMask;
67
import io.grpc.ManagedChannel;
78
import io.grpc.stub.StreamObserver;
89
import lombok.AccessLevel;
@@ -30,6 +31,29 @@ public final class AgonesAlphaSdk {
3031
this.stub = SDKGrpc.newStub(channel);
3132
}
3233

34+
/**
35+
* adds a value to a list and returns updated list. returns NOT_FOUND if the list does not exist. returns
36+
* ALREADY_EXISTS if the value is already in the list. returns OUT_OF_RANGE if the list is already at Capacity.
37+
*
38+
* @param name the name to add.
39+
* @param value the value to add.
40+
* @param observer the observer to add.
41+
*/
42+
public void addList(
43+
@NotNull final String name,
44+
@NotNull final String value,
45+
@NotNull final StreamObserver<Alpha.List> observer
46+
) {
47+
this.stub.addListValue(
48+
Alpha.AddListValueRequest
49+
.newBuilder()
50+
.setName(name)
51+
.setValue(value)
52+
.build(),
53+
observer
54+
);
55+
}
56+
3357
/**
3458
* returns the list of the currently connected player ids.
3559
* 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(
4670
this.stub.getConnectedPlayers(Alpha.Empty.getDefaultInstance(), observer);
4771
}
4872

73+
/**
74+
* gets a counter. returns NOT_FOUND if the counter does not exist.
75+
*
76+
* @param name the name of the counter.
77+
* @param observer the observer to get counter.
78+
*/
79+
public void getCounter(
80+
@NotNull final String name,
81+
@NotNull final StreamObserver<Alpha.Counter> observer
82+
) {
83+
this.stub.getCounter(
84+
Alpha.GetCounterRequest.newBuilder().setName(name).build(),
85+
observer
86+
);
87+
}
88+
89+
/**
90+
* gets a list. returns NOT_FOUND if the List does not exist.
91+
*
92+
* @param name the name to get.
93+
* @param observer the observer to get.
94+
*/
95+
public void getList(
96+
@NotNull final String name,
97+
@NotNull final StreamObserver<Alpha.List> observer
98+
) {
99+
this.stub.getList(
100+
Alpha.GetListRequest.newBuilder().setName(name).build(),
101+
observer
102+
);
103+
}
104+
49105
/**
50106
* retrieves the current player capacity.
51107
* 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(
225281
);
226282
}
227283

284+
/**
285+
* removes a value from a list and returns updated list. returns NOT_FOUND if the list does not exist. returns
286+
* NOT_FOUND if the value is not in the list.
287+
*
288+
* @param name the name to remove.
289+
* @param value the value to remove.
290+
* @param observer the observer to add.
291+
*/
292+
public void removeList(
293+
@NotNull final String name,
294+
@NotNull final String value,
295+
@NotNull final StreamObserver<Alpha.List> observer
296+
) {
297+
this.stub.removeListValue(
298+
Alpha.RemoveListValueRequest
299+
.newBuilder()
300+
.setName(name)
301+
.setValue(value)
302+
.build(),
303+
observer
304+
);
305+
}
306+
228307
/**
229308
* update the {@link Sdk.GameServer.Status.PlayerStatus#getCapacity()} value with a new capacity.
230309
*
@@ -237,4 +316,54 @@ public void setPlayerCapacity(
237316
) {
238317
this.stub.setPlayerCapacity(capacity, observer);
239318
}
319+
320+
/**
321+
* returns the updated counter. returns NOT_FOUND if the counter does not exist (name cannot be updated). returns
322+
* OUT_OF_RANGE if the count is out of range [0,Capacity]. returns INVALID_ARGUMENT if the field mask path(s) are not
323+
* field(s) of the counter. if a field mask path(s) is specified, but the value is not set in the request counter
324+
* object, then the default value for the variable will be set (i.e. 0 for "capacity" or "count").
325+
*
326+
* @param counter the counter to update.
327+
* @param updateMask the update mask to update.
328+
* @param observer the observer to update.
329+
*/
330+
public void updateCounter(
331+
@NotNull final Alpha.Counter counter,
332+
@NotNull final FieldMask updateMask,
333+
@NotNull final StreamObserver<Alpha.Counter> observer
334+
) {
335+
this.stub.updateCounter(
336+
Alpha.UpdateCounterRequest
337+
.newBuilder()
338+
.setCounter(counter)
339+
.setUpdateMask(updateMask)
340+
.build(),
341+
observer
342+
);
343+
}
344+
345+
/**
346+
* returns the updated list. returns NOT_FOUND if the list does not exist (name cannot be updated).
347+
* <p>
348+
* **THIS WILL OVERWRITE ALL EXISTING LIST.VALUES WITH ANY REQUEST LIST.VALUES**
349+
* <p>
350+
* use addListValue() or removeListValue() for modifying the List.Values field.
351+
* returns INVALID_ARGUMENT if the field mask path(s) are not field(s) of the list.
352+
*
353+
* @param observer the observer to update.
354+
*/
355+
public void updateList(
356+
@NotNull final Alpha.List list,
357+
@NotNull final FieldMask updateMask,
358+
@NotNull final StreamObserver<Alpha.List> observer
359+
) {
360+
this.stub.updateList(
361+
Alpha.UpdateListRequest
362+
.newBuilder()
363+
.setList(list)
364+
.setUpdateMask(updateMask)
365+
.build(),
366+
observer
367+
);
368+
}
240369
}

src/main/java/tr/com/infumia/agones4j/AgonesSdk.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,31 @@ public final class AgonesSdk implements Terminable {
4747
@NotNull
4848
SDKGrpc.SDKStub stub;
4949

50+
/**
51+
* ctor.
52+
*
53+
* @param channel the channel.
54+
*/
55+
public AgonesSdk(@NotNull final ManagedChannel channel) {
56+
this.channel = channel;
57+
this.stub = SDKGrpc.newStub(this.channel);
58+
this.alpha = new AgonesAlphaSdk(this.channel);
59+
this.beta = new AgonesBetaSdk(this.channel);
60+
}
61+
5062
/**
5163
* ctor.
5264
*
5365
* @param grpcHost the grpc host.
5466
* @param grpcPort the grpc port.
5567
*/
5668
public AgonesSdk(@NotNull final String grpcHost, final int grpcPort) {
57-
this.channel =
69+
this(
5870
ManagedChannelBuilder
5971
.forAddress(grpcHost, grpcPort)
6072
.usePlaintext()
61-
.build();
62-
this.stub = SDKGrpc.newStub(this.channel);
63-
this.alpha = new AgonesAlphaSdk(this.channel);
64-
this.beta = new AgonesBetaSdk(this.channel);
73+
.build()
74+
);
6575
}
6676

6777
/**

0 commit comments

Comments
 (0)