Skip to content

Commit

Permalink
Some small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim203 committed Jun 5, 2021
1 parent 50b51f5 commit 0149264
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

package org.geysermc.floodgate.util;

public class Base64Utils {
public final class Base64Utils {
public static int getEncodedLength(int length) {
if (length <= 0) {
return -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import lombok.Getter;
import lombok.Setter;

public class FloodgateConfigHolder {
public final class FloodgateConfigHolder {
@Getter
@Setter
private static Object config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public final class LinkedPlayer implements Cloneable {
*/
private final UUID bedrockId;
/**
* If the LinkedPlayer is send from a different platform. For example the LinkedPlayer is from
* If the LinkedPlayer is sent from a different platform. For example the LinkedPlayer is from
* Bungee but the data has been sent to the Bukkit server.
*/
private boolean fromDifferentPlatform = false;
Expand Down
4 changes: 4 additions & 0 deletions connector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<groupId>org.java-websocket</groupId>
<artifactId>Java-WebSocket</artifactId>
<version>1.5.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.CloudburstMC.Protocol</groupId>
Expand Down Expand Up @@ -214,11 +215,13 @@
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.11</version> <!-- This isn't the latest version to get round https://github.com/ronmamo/reflections/issues/273 -->
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>2.1.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
Expand Down Expand Up @@ -254,6 +257,7 @@
<groupId>com.github.GeyserMC</groupId>
<artifactId>MCAuthLib</artifactId>
<version>0e48a094f2</version>
<scope>compile</scope>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public class GeyserConnector {
@Setter
private AuthType defaultAuthType;

private TimeSyncer timeSyncer;
private final TimeSyncer timeSyncer;
private FloodgateCipher cipher;
private FloodgateSkinUploader skinUploader;
private final NewsHandler newsHandler;
Expand Down Expand Up @@ -202,6 +202,7 @@ private GeyserConnector(PlatformType platformType, GeyserBootstrap bootstrap) {

defaultAuthType = AuthType.getByName(config.getRemote().getAuthType());

TimeSyncer timeSyncer = null;
if (defaultAuthType == AuthType.FLOODGATE) {
timeSyncer = new TimeSyncer(Constants.NTP_SERVER);
try {
Expand All @@ -214,6 +215,7 @@ private GeyserConnector(PlatformType platformType, GeyserBootstrap bootstrap) {
logger.severe(LanguageUtils.getLocaleStringLog("geyser.auth.floodgate.bad_key"), exception);
}
}
this.timeSyncer = timeSyncer;

String branch = "unknown";
int buildNumber = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public CommandManager(GeyserConnector connector) {
registerCommand(new VersionCommand(connector, "version", "geyser.commands.version.desc", "geyser.command.version"));
registerCommand(new SettingsCommand(connector, "settings", "geyser.commands.settings.desc", "geyser.command.settings"));
registerCommand(new StatisticsCommand(connector, "statistics", "geyser.commands.statistics.desc", "geyser.command.statistics"));
registerCommand(new AdvancementsCommand( "advancements", "geyser.commands.advancements.desc", "geyser.command.advancements"));
registerCommand(new AdvancementsCommand("advancements", "geyser.commands.advancements.desc", "geyser.command.advancements"));
}

public void registerCommand(GeyserCommand command) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ public class GeyserSession implements CommandSender {
private ChunkCache chunkCache;
private EntityCache entityCache;
private EntityEffectCache effectCache;
private final FormCache formCache;
private final PreferencesCache preferencesCache;
private final TagCache tagCache;
private WorldCache worldCache;
private FormCache formCache;
private final Int2ObjectMap<TeleportCache> teleportMap = new Int2ObjectOpenHashMap<>();

private final PlayerInventory playerInventory;
Expand Down Expand Up @@ -445,12 +445,13 @@ public GeyserSession(GeyserConnector connector, BedrockServerSession bedrockServ
this.chunkCache = new ChunkCache(this);
this.entityCache = new EntityCache(this);
this.effectCache = new EntityEffectCache();
this.formCache = new FormCache(this);
this.preferencesCache = new PreferencesCache(this);
this.tagCache = new TagCache();
this.worldCache = new WorldCache(this);
this.formCache = new FormCache(this);

this.collisionManager = new CollisionManager(this);

this.playerEntity = new SessionPlayerEntity(this);
collisionManager.updatePlayerBoundingBox(this.playerEntity.getPosition());

Expand Down Expand Up @@ -851,7 +852,6 @@ public void disconnect(String reason) {
this.entityCache = null;
this.effectCache = null;
this.worldCache = null;
this.formCache = null;

closed = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,18 @@

package org.geysermc.connector.network.session.auth;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.base.Charsets;
import lombok.Getter;
import org.geysermc.connector.skin.SkinProvider;
import org.geysermc.floodgate.util.DeviceOs;
import org.geysermc.floodgate.util.InputMode;
import org.geysermc.floodgate.util.UiProfile;

import java.util.Base64;
import java.util.UUID;

@JsonIgnoreProperties(ignoreUnknown = true)
@Getter
public final class BedrockClientData {
@JsonIgnore
private JsonNode jsonData;

@JsonProperty(value = "GameVersion")
private String gameVersion;
@JsonProperty(value = "ServerAddress")
Expand Down Expand Up @@ -115,27 +107,6 @@ public final class BedrockClientData {
@JsonProperty(value = "PlayFabId")
private String playFabId;

public void setJsonData(JsonNode data) {
if (this.jsonData == null && data != null) {
this.jsonData = data;
}
}

public boolean isAlex() {
try {
byte[] bytes = Base64.getDecoder().decode(geometryName.getBytes(Charsets.UTF_8));
String geometryName =
SkinProvider.OBJECT_MAPPER
.readTree(bytes)
.get("geometry").get("default")
.asText();
return "geometry.humanoid.customSlim".equals(geometryName);
} catch (Exception exception) {
exception.printStackTrace();
return false;
}
}

public DeviceOs getDeviceOs() {
return deviceOs != null ? deviceOs : DeviceOs.UNKNOWN;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientAdvancementTabPacket;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.chat.MessageTranslator;
import org.geysermc.connector.utils.GeyserAdvancement;
Expand Down Expand Up @@ -58,7 +57,7 @@ public class AdvancementsCache {
/**
* Stores player's chosen advancement's ID and title for use in form creators.
*/
@Setter @Accessors(chain = true)
@Setter
private String currentAdvancementCategoryId = null;

private final GeyserSession session;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import lombok.RequiredArgsConstructor;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.cumulus.Form;
import org.geysermc.cumulus.SimpleForm;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
Expand All @@ -58,13 +59,15 @@ public int showForm(Form form) {
formRequestPacket.setFormData(form.getJsonData());
session.sendUpstreamPacket(formRequestPacket);

// Hack to fix the url image loading bug
NetworkStackLatencyPacket latencyPacket = new NetworkStackLatencyPacket();
latencyPacket.setFromServer(true);
latencyPacket.setTimestamp(-System.currentTimeMillis());
session.getConnector().getGeneralThreadPool().schedule(
() -> session.sendUpstreamPacket(latencyPacket),
500, TimeUnit.MILLISECONDS);
// Hack to fix the (url) image loading bug
if (form instanceof SimpleForm) {
NetworkStackLatencyPacket latencyPacket = new NetworkStackLatencyPacket();
latencyPacket.setFromServer(true);
latencyPacket.setTimestamp(-System.currentTimeMillis());
session.getConnector().getGeneralThreadPool().schedule(
() -> session.sendUpstreamPacket(latencyPacket),
500, TimeUnit.MILLISECONDS);
}

return windowId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public void translate(NetworkStackLatencyPacket packet, GeyserSession session) {
// PS4 divides the network stack latency timestamp FOR US!!!
// WTF
if (session.getClientData().getDeviceOs().equals(DeviceOs.PS4)) {
// Ignore the weird DeviceOS, our order is wrong and will be fixed in Floodgate 2.0
pingId = packet.getTimestamp();
} else {
pingId = packet.getTimestamp() / 1000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import com.github.steveice10.mc.protocol.packet.ingame.server.ServerAdvancementTabPacket;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.session.cache.AdvancementsCache;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator;

Expand All @@ -37,8 +38,8 @@
public class JavaAdvancementsTabTranslator extends PacketTranslator<ServerAdvancementTabPacket> {
@Override
public void translate(ServerAdvancementTabPacket packet, GeyserSession session) {
session.getAdvancementsCache()
.setCurrentAdvancementCategoryId(packet.getTabId())
.buildAndShowListForm();
AdvancementsCache advancementsCache = session.getAdvancementsCache();
advancementsCache.setCurrentAdvancementCategoryId(packet.getTabId());
advancementsCache.buildAndShowListForm();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

@Translator(packet = ServerStatisticsPacket.class)
public class JavaStatisticsTranslator extends PacketTranslator<ServerStatisticsPacket> {

@Override
public void translate(ServerStatisticsPacket packet, GeyserSession session) {
session.updateStatistics(packet.getStatistics());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ private static void encryptConnectionWithCert(GeyserConnector connector, GeyserS

JsonNode clientDataJson = JSON_MAPPER.readTree(clientJwt.getPayload().toBytes());
BedrockClientData data = JSON_MAPPER.convertValue(clientDataJson, BedrockClientData.class);
data.setJsonData(clientDataJson);
session.setClientData(data);

if (EncryptionUtils.canUseEncryption()) {
Expand Down Expand Up @@ -243,7 +242,7 @@ public static void buildAndShowLoginDetailsWindow(GeyserSession session) {
}

/**
* Promts the user between either OAuth code login or manual password authentication
* Prompts the user between either OAuth code login or manual password authentication
*/
public static void buildAndShowMicrosoftAuthenticationWindow(GeyserSession session) {
session.sendForm(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ public static void buildAndSendStatisticsMenu(GeyserSession session) {
session.sendForm(
builder.content(content.toString())
.button("gui.back", FormImage.Type.PATH, "textures/gui/newgui/undo")
.responseHandler((form1, responseData1) -> {
SimpleFormResponse response1 = form.parseResponse(responseData1);
.responseHandler((form1, subFormResponseData) -> {
SimpleFormResponse response1 = form.parseResponse(subFormResponseData);
if (response1.isCorrect()) {
buildAndSendStatisticsMenu(session);
}
Expand Down

0 comments on commit 0149264

Please sign in to comment.