Skip to content

Commit 7d9880a

Browse files
committed
Added GamesServerService interface
Signed-off-by: Rafael Luis Ibasco <[email protected]>
1 parent 39a6f1a commit 7d9880a

File tree

8 files changed

+501
-9
lines changed

8 files changed

+501
-9
lines changed

examples/pom.xml

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@
4242
</resource>
4343
</resources>
4444
<plugins>
45+
<plugin>
46+
<groupId>org.apache.maven.plugins</groupId>
47+
<artifactId>maven-source-plugin</artifactId>
48+
<configuration>
49+
<skipSource>true</skipSource>
50+
</configuration>
51+
</plugin>
4552
<plugin>
4653
<groupId>org.apache.maven.plugins</groupId>
4754
<artifactId>maven-gpg-plugin</artifactId>
@@ -76,13 +83,17 @@
7683
<artifactId>exec-maven-plugin</artifactId>
7784
<configuration>
7885
<mainClass>com.ibasco.agql.examples.base.ExampleRunner</mainClass>
86+
<arguments>
87+
88+
</arguments>
7989
</configuration>
8090
</plugin>
8191
<plugin>
8292
<groupId>org.apache.maven.plugins</groupId>
8393
<artifactId>maven-jar-plugin</artifactId>
8494
<configuration>
85-
<archive>
95+
<skip>true</skip>
96+
<!--<archive>
8697
<index>true</index>
8798
<manifest>
8899
<mainClass>com.ibasco.agql.examples.base.ExampleRunner</mainClass>
@@ -92,7 +103,7 @@
92103
<mode>development</mode>
93104
<url>${project.url}</url>
94105
</manifestEntries>
95-
</archive>
106+
</archive>-->
96107
</configuration>
97108
</plugin>
98109
</plugins>
@@ -130,7 +141,7 @@
130141
<dependency>
131142
<groupId>ch.qos.logback</groupId>
132143
<artifactId>logback-core</artifactId>
133-
<version>1.2.10</version>
144+
<version>1.2.11</version>
134145
</dependency>
135146
<dependency>
136147
<groupId>org.codehaus.janino</groupId>
@@ -145,12 +156,32 @@
145156
<dependency>
146157
<groupId>commons-cli</groupId>
147158
<artifactId>commons-cli</artifactId>
159+
<version>1.5.0</version>
160+
</dependency>
161+
<dependency>
162+
<groupId>org.jline</groupId>
163+
<artifactId>jline</artifactId>
164+
<version>3.21.0</version>
165+
</dependency>
166+
<dependency>
167+
<groupId>org.jline</groupId>
168+
<artifactId>jline-terminal</artifactId>
169+
<version>3.21.0</version>
170+
</dependency>
171+
<dependency>
172+
<groupId>org.jline</groupId>
173+
<artifactId>jline-reader</artifactId>
174+
<version>3.21.0</version>
148175
</dependency>
149-
<!-- https://mvnrepository.com/artifact/info.picocli/picocli -->
150176
<dependency>
151-
<groupId>info.picocli</groupId>
152-
<artifactId>picocli</artifactId>
153-
<version>4.6.3</version>
177+
<groupId>org.jline</groupId>
178+
<artifactId>jline-terminal-jansi</artifactId>
179+
<version>3.21.0</version>
154180
</dependency>
181+
<!--<dependency>
182+
<groupId>org.fusesource.jansi</groupId>
183+
<artifactId>jansi</artifactId>
184+
<version>2.4.0</version>
185+
</dependency>-->
155186
</dependencies>
156187
</project>

examples/src/main/java/com/ibasco/agql/examples/SteamWebApiExample.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.ibasco.agql.core.util.Console;
2020
import com.ibasco.agql.examples.base.BaseWebApiAuthExample;
21+
import com.ibasco.agql.protocols.valve.steam.master.MasterServerFilter;
2122
import com.ibasco.agql.protocols.valve.steam.webapi.SteamWebApiClient;
2223
import com.ibasco.agql.protocols.valve.steam.webapi.enums.VanityUrlType;
2324
import com.ibasco.agql.protocols.valve.steam.webapi.interfaces.*;
@@ -30,6 +31,7 @@
3031
import java.util.ArrayList;
3132
import java.util.List;
3233
import java.util.Map;
34+
import java.util.concurrent.CompletableFuture;
3335
import java.util.function.Consumer;
3436

3537
/**
@@ -68,6 +70,7 @@ public void run(String[] args) throws Exception {
6870
SteamEconomy steamEconomy = new SteamEconomy(client);
6971
SteamStorefront storeFront = new SteamStorefront(client);
7072
SteamEconItems steamEconItems = new SteamEconItems(client);
73+
GameServersService gameServersService = new GameServersService(client);
7174

7275
steamApps.getAppList().exceptionally(throwable -> {
7376
log.error("Error Occured", throwable);
@@ -315,6 +318,13 @@ public void accept(Map<String, SteamAssetClassInfo> stringSteamAssetClassInfoMap
315318

316319
StoreSaleDetails storeSaleDetails = storeFront.getSaleDetails(0).join();
317320
log.info("Sale Details: {}", storeSaleDetails);
321+
322+
MasterServerFilter filter = MasterServerFilter.create().appId(730).dedicated(true);
323+
CompletableFuture<List<Server>> serverListFuture = gameServersService.getServerList(filter.toString(), 10);
324+
int ctr = 1;
325+
for (Server server : serverListFuture.join()) {
326+
System.out.printf("%03d) name = %s, ip = %s%n", ctr++, server.getName(), server.getAddr());
327+
}
318328
}
319329

320330
private static void displayResult(Object result) {

protocols/valve/steam/webapi/src/main/java/com/ibasco/agql/protocols/valve/steam/webapi/SteamApiConstants.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,32 @@ public class SteamApiConstants {
7272
public static final String STEAM_DIRECTORY = "ISteamDirectory";
7373
/** Constant <code>STEAM_ENVOY="ISteamEnvoy"</code> */
7474
public static final String STEAM_ENVOY = "ISteamEnvoy";
75+
7576
/** Constant <code>STEAM_PAYPAL_PAYMENTS_HUB="ISteamPayPalPaymentsHub"</code> */
7677
public static final String STEAM_PAYPAL_PAYMENTS_HUB = "ISteamPayPalPaymentsHub";
78+
7779
/** Constant <code>STEAM_ECON_SERVICE="IEconService"</code> */
7880
public static final String STEAM_ECON_SERVICE = "IEconService";
81+
7982
/** Constant <code>STEAM_ECON_ITEMS="IEconItems_${appId}"</code> */
8083
public static final String STEAM_ECON_ITEMS = "IEconItems_${appId}";
84+
8185
/** Constant <code>STEAM_CHEATREPORT_SERVICE="ICheatReportingService"</code> */
8286
public static final String STEAM_CHEATREPORT_SERVICE = "ICheatReportingService";
8387

88+
public static final String STEAM_GAMESERVERS_SERVICE = "IGameServersService";
89+
8490
//Steam URL Params
91+
8592
/** Constant <code>STEAM_URLPARAM_STEAMID="steamid"</code> */
8693
public static final String STEAM_URLPARAM_STEAMID = "steamid";
94+
8795
/** Constant <code>STEAM_URLPARAM_APPID="appid"</code> */
8896
public static final String STEAM_URLPARAM_APPID = "appid";
97+
8998
/** Constant <code>STEAM_URLPARAM_CURRENCY="currency"</code> */
9099
public static final String STEAM_URLPARAM_CURRENCY = "currency";
100+
91101
/** Constant <code>STEAM_URLPARAM_LANGUAGE="language"</code> */
92102
public static final String STEAM_URLPARAM_LANGUAGE = "language";
93103
/** Constant <code>STEAM_URLPARAM_MAXLENGTH="maxlength"</code> */
@@ -145,4 +155,5 @@ public class SteamApiConstants {
145155
public static final String SF_METHOD_PACKAGE_DETAILS = "${baseUrl}/packagedetails";
146156
/** Constant <code>SF_METHOD_SALE_DETAILS="${baseUrl}/salepage"</code> */
147157
public static final String SF_METHOD_SALE_DETAILS = "${baseUrl}/salepage";
158+
148159
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) 2022 Asynchronous Game Query Library
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.ibasco.agql.protocols.valve.steam.webapi.interfaces;
18+
19+
import com.google.gson.JsonArray;
20+
import com.google.gson.JsonObject;
21+
import com.google.gson.reflect.TypeToken;
22+
import com.ibasco.agql.protocols.valve.steam.webapi.SteamWebApiClient;
23+
import com.ibasco.agql.protocols.valve.steam.webapi.SteamWebApiInterface;
24+
import com.ibasco.agql.protocols.valve.steam.webapi.interfaces.gameservers.GetServerList;
25+
import com.ibasco.agql.protocols.valve.steam.webapi.pojos.Server;
26+
27+
import java.lang.reflect.Type;
28+
import java.util.ArrayList;
29+
import java.util.List;
30+
import java.util.concurrent.CompletableFuture;
31+
32+
public class GameServersService extends SteamWebApiInterface {
33+
34+
/**
35+
* <p>Default Constructor</p>
36+
*
37+
* @param client
38+
* A {@link SteamWebApiClient} instance
39+
*/
40+
public GameServersService(SteamWebApiClient client) {
41+
super(client);
42+
}
43+
44+
public CompletableFuture<List<Server>> getServerList(String filter) {
45+
return getServerList(filter, -1);
46+
}
47+
48+
public CompletableFuture<List<Server>> getServerList(String filter, int limit) {
49+
CompletableFuture<JsonObject> json = sendRequest(new GetServerList(VERSION_1, filter, limit));
50+
return json.thenApply((JsonObject element) -> {
51+
JsonObject response = element.get("response").getAsJsonObject();
52+
if (response.has("servers")) {
53+
JsonArray array = response.getAsJsonArray("servers");
54+
Type listType = new TypeToken<List<Server>>() {}.getType();
55+
return builder().fromJson(array, listType);
56+
}
57+
return new ArrayList<>();
58+
});
59+
}
60+
}

protocols/valve/steam/webapi/src/main/java/com/ibasco/agql/protocols/valve/steam/webapi/interfaces/SteamNews.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ public CompletableFuture<List<SteamNewsItem>> getNewsForApp(int appId, int maxLe
6969
return newsItems.thenApply(root -> {
7070
JsonObject appNews = root.getAsJsonObject("appnews");
7171
JsonArray newsItems1 = appNews.getAsJsonArray("newsitems");
72-
Type newsListType = new TypeToken<List<SteamNewsItem>>() {
73-
}.getType();
72+
Type newsListType = new TypeToken<List<SteamNewsItem>>() {}.getType();
7473
return builder().fromJson(newsItems1, newsListType);
7574
});
7675
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) 2022 Asynchronous Game Query Library
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.ibasco.agql.protocols.valve.steam.webapi.interfaces.gameservers;
18+
19+
import com.ibasco.agql.protocols.valve.steam.webapi.requests.GameServersRequest;
20+
21+
public class GetServerList extends GameServersRequest {
22+
23+
/**
24+
* <p>Constructor for SteamWebApiRequest.</p>
25+
*
26+
* @param apiVersion
27+
* a int
28+
*/
29+
public GetServerList(int apiVersion, String filter, int limit) {
30+
super("GetServerList", apiVersion);
31+
urlParam("filter", filter);
32+
if (limit > 0)
33+
urlParam("limit", limit);
34+
}
35+
}

0 commit comments

Comments
 (0)