-
-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port reduce session server lookups (#509) to development
Co-authored-by: Bridge <29434554+bridgelol@users.noreply.github.com>
- Loading branch information
Showing
13 changed files
with
171 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
core/src/main/java/org/geysermc/floodgate/core/http/mojang/ProfileProperty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.geysermc.floodgate.core.http.mojang; | ||
|
||
import io.micronaut.serde.annotation.Serdeable; | ||
import jakarta.validation.constraints.NotNull; | ||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
||
@Serdeable | ||
public record ProfileProperty(@NotNull String name, @NotNull String value, @Nullable String signature) { | ||
} |
17 changes: 17 additions & 0 deletions
17
core/src/main/java/org/geysermc/floodgate/core/http/mojang/ProfileWithProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.geysermc.floodgate.core.http.mojang; | ||
|
||
import io.micronaut.serde.annotation.Serdeable; | ||
import java.util.List; | ||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
||
@Serdeable | ||
public record ProfileWithProperties(String id, String name, List<ProfileProperty> properties) { | ||
public @Nullable ProfileProperty texture() { | ||
for (ProfileProperty property : properties) { | ||
if (property.name().equals("texture")) { | ||
return property; | ||
} | ||
} | ||
return null; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
core/src/main/java/org/geysermc/floodgate/core/http/mojang/SessionServerClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.geysermc.floodgate.core.http.mojang; | ||
|
||
import static io.micronaut.http.HttpHeaders.USER_AGENT; | ||
|
||
import io.micronaut.http.annotation.Get; | ||
import io.micronaut.http.annotation.Header; | ||
import io.micronaut.http.client.annotation.Client; | ||
import jakarta.validation.constraints.NotNull; | ||
import java.util.UUID; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
@Client("https://sessionserver.mojang.com/session/minecraft") | ||
@Header(name = USER_AGENT, value = "${http.userAgent}") | ||
public interface SessionServerClient { | ||
@Get("/profile/{uuid}?unsigned=false") | ||
CompletableFuture<ProfileWithProperties> profileWithProperties(@NotNull UUID uuid); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
core/src/main/java/org/geysermc/floodgate/core/util/MojangUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.geysermc.floodgate.core.util; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.inject.Singleton; | ||
import java.util.UUID; | ||
import java.util.concurrent.CompletableFuture; | ||
import org.geysermc.floodgate.api.event.skin.SkinApplyEvent.SkinData; | ||
import org.geysermc.floodgate.core.http.mojang.SessionServerClient; | ||
import org.geysermc.floodgate.core.logger.FloodgateLogger; | ||
import org.geysermc.floodgate.core.skin.SkinDataImpl; | ||
|
||
@Singleton | ||
public final class MojangUtils { | ||
@Inject SessionServerClient sessionClient; | ||
@Inject FloodgateLogger logger; | ||
|
||
public CompletableFuture<SkinData> skinFor(UUID uuid) { | ||
return sessionClient.profileWithProperties(uuid) | ||
.thenApply(skin -> { | ||
var texture = skin.texture(); | ||
if (texture == null) { | ||
return SkinDataImpl.DEFAULT_SKIN; | ||
} | ||
return new SkinDataImpl(texture.value(), texture.signature()); | ||
}).exceptionally(exception -> { | ||
logger.debug("Unexpected skin fetch error for " + uuid, exception); | ||
return SkinDataImpl.DEFAULT_SKIN; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.