Skip to content

Commit

Permalink
Added additional API methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
dexuby committed Feb 23, 2024
1 parent f135f9c commit 461b833
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 27 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ The API provided by this library currently only supports a few things:
- You can invite people to your current lobby: `LeagueClientAPI#inviteToLobby`
- You can create a new lobby for any active game mode: `LeagueClientAPI#createLobby`
- You can set your Solo & Duo Rank to Challenger (only visible in chat module, not profile): `LeagueClientAPI#fakeRank`
- ... and a bunch more (check the LeagueClientAPI class)

### How do I contribute/find more endpoints?
Easiest way is to use an IFEO debugger to get rid of some of the flags that get applied to the client when it gets started.
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>dev.dexuby</groupId>
<artifactId>leagueclient4j</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
Expand Down
151 changes: 147 additions & 4 deletions src/main/java/dev/dexuby/leagueclient4j/LeagueClientAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ public CompletableFuture<LoginSession> getSession() {
}

@NotNull
public CompletableFuture<CurrentSummoner> getCurrentSummoner() {
public CompletableFuture<Summoner> getCurrentSummoner() {

final HttpRequest request = this.createGetRequest("/lol-summoner/v1/current-summoner", this.requestData.clientPort(), this.requestData.clientToken());
return this.httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofString())
.thenApply(HttpResponse::body)
.thenApply(response -> Constants.GSON.fromJson(response, CurrentSummoner.class));
.thenApply(response -> Constants.GSON.fromJson(response, Summoner.class));

}

Expand Down Expand Up @@ -120,6 +120,13 @@ public CompletableFuture<InviteResponse[]> inviteToLobby(@NotNull final List<Lon

}

/**
* Creates a new lobby.
*
* @param queueId The queue id.
* @return CompletableFuture of type JsonObject.
*/

@NotNull
public CompletableFuture<JsonObject> createLobby(final int queueId) {

Expand All @@ -130,6 +137,129 @@ public CompletableFuture<JsonObject> createLobby(final int queueId) {

}

/**
* Delete the active lobby.
*
* @return CompletableFuture of type Void.
*/

public CompletableFuture<Void> deleteLobby() {

final HttpRequest request = this.createDeleteRequest("/lol-lobby/v2/lobby", this.requestData.clientPort(), this.requestData.clientToken());
return this.httpClient.sendAsync(request, HttpResponse.BodyHandlers.discarding()).thenAccept(HttpResponse::body);

}

/**
* Starts the matchmaking queue.
*
* @return CompletableFuture of type Void.
*/

public CompletableFuture<Void> startQueue() {

final HttpRequest request = this.createPostRequest("/lol-lobby/v2/lobby/matchmaking/search", this.requestData.clientPort(), this.requestData.clientToken(), "");
return this.httpClient.sendAsync(request, HttpResponse.BodyHandlers.discarding()).thenAccept(HttpResponse::body);

}

/**
* Cancels the active matchmaking queue.
*
* @return CompletableFuture of type Void.
*/

public CompletableFuture<Void> cancelQueue() {

final HttpRequest request = this.createDeleteRequest("/lol-lobby/v2/lobby/matchmaking/search", this.requestData.clientPort(), this.requestData.clientToken());
return this.httpClient.sendAsync(request, HttpResponse.BodyHandlers.discarding()).thenAccept(HttpResponse::body);

}

public CompletableFuture<Summoner[]> findSummonersByAliases(@NotNull final List<AccountName> accountNames) {

final HttpRequest request = this.createPostRequest("/lol-summoner/v1/summoners/aliases", this.requestData.clientPort(), this.requestData.clientToken(), Constants.GSON.toJson(accountNames));
return this.httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofString())
.thenApply(HttpResponse::body)
.thenApply(response -> Constants.GSON.fromJson(response, Summoner[].class));

}

public CompletableFuture<Summoner> findSummonerBySummonerId(final int summonerId) {

final HttpRequest request = this.createGetRequest("/lol-summoner/v1/summoners/" + summonerId, this.requestData.clientPort(), this.requestData.clientToken());
return this.httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofString())
.thenApply(HttpResponse::body)
.thenApply(response -> Constants.GSON.fromJson(response, Summoner.class));

}

public CompletableFuture<Summoner> findSummonerByPUUID(@NotNull final String puuid) {

final HttpRequest request = this.createGetRequest("/lol-summoner/v2/summoners/puuid/" + puuid, this.requestData.clientPort(), this.requestData.clientToken());
return this.httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofString())
.thenApply(HttpResponse::body)
.thenApply(response -> Constants.GSON.fromJson(response, Summoner.class));

}

/**
* Accepts the active ready check.
*
* @return CompletableFuture of type Void.
*/

public CompletableFuture<Void> acceptReadyCheck() {

final HttpRequest request = this.createPostRequest("/lol-matchmaking/v1/ready-check/accept", this.requestData.clientPort(), this.requestData.clientToken(), "");
return this.httpClient.sendAsync(request, HttpResponse.BodyHandlers.discarding()).thenAccept(HttpResponse::body);

}

/**
* Declines the active ready check.
*
* @return CompletableFuture of type Void.
*/

public CompletableFuture<Void> declineReadyCheck() {

final HttpRequest request = this.createPostRequest("/lol-matchmaking/v1/ready-check/decline", this.requestData.clientPort(), this.requestData.clientToken(), "");
return this.httpClient.sendAsync(request, HttpResponse.BodyHandlers.discarding()).thenAccept(HttpResponse::body);

}

/**
* Re-rolls the active champion. (ARAM)
*
* @return CompletableFuture of type Void.
*/

public CompletableFuture<Void> rerollChampion() {

final HttpRequest request = this.createPostRequest("/lol-champ-select/v1/session/my-selection/reroll", this.requestData.clientPort(), this.requestData.clientToken(), "");
return this.httpClient.sendAsync(request, HttpResponse.BodyHandlers.discarding()).thenAccept(HttpResponse::body);

}

/**
* Report a summoner.
*
* @param reportRequest The report request.
* @return CompletableFuture of type Void.
*/

public CompletableFuture<Void> report(@NotNull final ReportRequest reportRequest) {

final HttpRequest request = this.createGetRequest("/lol-player-report-sender/v1/in-game-reports", this.requestData.clientPort(), this.requestData.clientToken());
return this.httpClient.sendAsync(request, HttpResponse.BodyHandlers.discarding())
.thenRun(() -> {
final HttpRequest actualRequest = this.createPostRequest("/lol-player-report-sender/v1/end-of-game-reports", this.requestData.clientPort(), this.requestData.clientToken(), Constants.GSON.toJson(reportRequest));
this.httpClient.sendAsync(actualRequest, HttpResponse.BodyHandlers.discarding());
});

}

@NotNull
public CompletableFuture<Void> fakeRank() {

Expand All @@ -145,7 +275,7 @@ public CompletableFuture<Void> fakeRank() {

}

private HttpRequest createGetRequest(@NotNull final String endpoint, @NotNull final String port, @NotNull final String token) {
protected HttpRequest createGetRequest(@NotNull final String endpoint, @NotNull final String port, @NotNull final String token) {

return HttpRequest.newBuilder()
.uri(URI.create("https://127.0.0.1:" + port + endpoint))
Expand All @@ -158,7 +288,7 @@ private HttpRequest createGetRequest(@NotNull final String endpoint, @NotNull fi

}

private HttpRequest createPostRequest(@NotNull final String endpoint, @NotNull final String port, @NotNull final String token, @NotNull final String content) {
protected HttpRequest createPostRequest(@NotNull final String endpoint, @NotNull final String port, @NotNull final String token, @NotNull final String content) {

return HttpRequest.newBuilder()
.uri(URI.create("https://127.0.0.1:" + port + endpoint))
Expand All @@ -171,4 +301,17 @@ private HttpRequest createPostRequest(@NotNull final String endpoint, @NotNull f

}

protected HttpRequest createDeleteRequest(@NotNull final String endpoint, @NotNull final String port, @NotNull final String token) {

return HttpRequest.newBuilder()
.uri(URI.create("https://127.0.0.1:" + port + endpoint))
.headers(
"Authorization", "Basic " + token,
"Content-Type", "application/json"
)
.DELETE()
.build();

}

}
7 changes: 7 additions & 0 deletions src/main/java/dev/dexuby/leagueclient4j/api/AccountName.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package dev.dexuby.leagueclient4j.api;

import dev.dexuby.easycommon.external.jetbrains.annotations.NotNull;

public record AccountName(@NotNull String gameName,
@NotNull String tagLine) {
}
21 changes: 0 additions & 21 deletions src/main/java/dev/dexuby/leagueclient4j/api/CurrentSummoner.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package dev.dexuby.leagueclient4j.api;

public enum ReportCategory {

NEGATIVE_ATTITUDE,
VERBAL_ABUSE

}
13 changes: 13 additions & 0 deletions src/main/java/dev/dexuby/leagueclient4j/api/ReportRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package dev.dexuby.leagueclient4j.api;

import dev.dexuby.easycommon.external.jetbrains.annotations.NotNull;
import dev.dexuby.easycommon.external.jetbrains.annotations.Nullable;

import java.util.List;

public record ReportRequest(@Nullable String comment,
long gameId,
@NotNull List<ReportCategory> categories,
long offenderSummonerId,
@NotNull String offenderPuuid) {
}
21 changes: 21 additions & 0 deletions src/main/java/dev/dexuby/leagueclient4j/api/Summoner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package dev.dexuby.leagueclient4j.api;

import dev.dexuby.easycommon.external.jetbrains.annotations.NotNull;

public record Summoner(long accountId,
@NotNull String displayName,
@NotNull String gameName,
@NotNull String internalName,
boolean nameChangeFlag,
int percentCompleteForNextLevel,
@NotNull String privacy,
int profileIconId,
@NotNull String puuid,
@NotNull RerollPoints rerollPoints,
long summonerId,
int summonerLevel,
@NotNull String tagLine,
boolean unnamed,
int xpSinceLastLevel,
int xpUntilNextLevel) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

public class LeagueClientAPITest {

public static void main(@NotNull final String[] args) {
public static void main(@NotNull final String[] args) throws InterruptedException {

final LeagueClientAPI leagueClientAPI = LeagueClient.getInstance().hookAPI();
if (leagueClientAPI == null) return;
Expand Down

0 comments on commit 461b833

Please sign in to comment.