Proof-of-concept for Geyser-Floodgate merge

This commit is contained in:
Camotoy 2022-11-06 21:32:55 -05:00
parent 592b48dbf5
commit 1c49036e3a
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
40 changed files with 545 additions and 726 deletions

View file

@ -60,6 +60,10 @@ dependencies {
compileOnly(projects.ap)
annotationProcessor(projects.ap)
implementation("org.geysermc.floodgate", "core", "2.2.0-SNAPSHOT") {
exclude("org.geysermc", "api")
}
}
configurations.api {

View file

@ -25,9 +25,12 @@
package org.geysermc.geyser;
import org.geysermc.floodgate.skin.SkinApplier;
import org.geysermc.geyser.command.GeyserCommandManager;
import org.geysermc.geyser.configuration.GeyserConfiguration;
import org.geysermc.geyser.dump.BootstrapDumpInfo;
import org.geysermc.geyser.hybrid.FloodgateHybridProvider;
import org.geysermc.geyser.hybrid.HybridProvider;
import org.geysermc.geyser.level.GeyserWorldManager;
import org.geysermc.geyser.level.WorldManager;
import org.geysermc.geyser.ping.IGeyserPingPassthrough;
@ -134,6 +137,20 @@ public interface GeyserBootstrap {
return Paths.get("logs/latest.log");
}
/**
* Creates the hybrid provider for this platform. The provider will differ based on server access.
*/
default HybridProvider createHybridProvider(GeyserImpl geyser) {
return new FloodgateHybridProvider(geyser);
}
/**
* Returns the skin applier for this platform, if the hybrid provider is integrated with the system.
*/
default SkinApplier createSkinApplier() {
throw new IllegalStateException();
}
/**
* Get an InputStream for the given resource path.
* Overridden on platforms that have different class loader properties.

View file

@ -50,10 +50,8 @@ import org.geysermc.api.Geyser;
import org.geysermc.common.PlatformType;
import org.geysermc.cumulus.form.Form;
import org.geysermc.cumulus.form.util.FormBuilder;
import org.geysermc.floodgate.crypto.AesCipher;
import org.geysermc.floodgate.crypto.AesKeyProducer;
import org.geysermc.floodgate.crypto.Base64Topping;
import org.geysermc.floodgate.crypto.FloodgateCipher;
import org.geysermc.floodgate.api.InstanceHolder;
import org.geysermc.floodgate.api.impl.FloodgateApiWrapper;
import org.geysermc.floodgate.news.NewsItemAction;
import org.geysermc.geyser.api.GeyserApi;
import org.geysermc.geyser.api.event.EventBus;
@ -69,6 +67,7 @@ import org.geysermc.geyser.configuration.GeyserConfiguration;
import org.geysermc.geyser.entity.EntityDefinitions;
import org.geysermc.geyser.event.GeyserEventBus;
import org.geysermc.geyser.extension.GeyserExtensionManager;
import org.geysermc.geyser.hybrid.HybridProvider;
import org.geysermc.geyser.level.WorldManager;
import org.geysermc.geyser.network.ConnectorServerEventHandler;
import org.geysermc.geyser.pack.ResourcePack;
@ -78,7 +77,7 @@ import org.geysermc.geyser.scoreboard.ScoreboardUpdater;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.session.PendingMicrosoftAuthentication;
import org.geysermc.geyser.session.SessionManager;
import org.geysermc.geyser.skin.FloodgateSkinUploader;
import org.geysermc.geyser.skin.BedrockSkinUploader;
import org.geysermc.geyser.skin.SkinProvider;
import org.geysermc.geyser.text.GeyserLocale;
import org.geysermc.geyser.text.MinecraftLocale;
@ -92,7 +91,6 @@ import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.security.Key;
import java.text.DecimalFormat;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
@ -134,8 +132,8 @@ public class GeyserImpl implements GeyserApi {
@Setter
private static boolean shouldStartListener = true;
private FloodgateCipher cipher;
private FloodgateSkinUploader skinUploader;
private HybridProvider hybridProvider;
private BedrockSkinUploader skinUploader;
private NewsHandler newsHandler;
private volatile boolean shuttingDown = false;
@ -161,6 +159,7 @@ public class GeyserImpl implements GeyserApi {
instance = this;
Geyser.set(this);
InstanceHolder.set(new FloodgateApiWrapper(this), null, null, null, null); // TODO
this.platformType = platformType;
this.bootstrap = bootstrap;
@ -325,16 +324,14 @@ public class GeyserImpl implements GeyserApi {
}
if (config.getRemote().authType() == AuthType.FLOODGATE) {
hybridProvider = bootstrap.createHybridProvider(this);
try {
Key key = new AesKeyProducer().produceFrom(config.getFloodgateKeyPath());
cipher = new AesCipher(new Base64Topping());
cipher.init(key);
logger.debug(GeyserLocale.getLocaleStringLog("geyser.auth.floodgate.loaded_key"));
// Note: this is positioned after the bind so the skin uploader doesn't try to run if Geyser fails
// to load successfully. Spigot complains about class loader if the plugin is disabled.
skinUploader = new FloodgateSkinUploader(this).start();
// TODO not Floodgate exclusive?
skinUploader = new BedrockSkinUploader(this).start();
} catch (Exception exception) {
logger.severe(GeyserLocale.getLocaleStringLog("geyser.auth.floodgate.bad_key"), exception);
logger.severe("Could not start the skin uploader!", exception);
}
}

View file

@ -46,6 +46,8 @@ public interface GeyserConfiguration {
IRemoteConfiguration getRemote();
HybridInfo getHybridInfo();
List<String> getSavedUserLogins();
@Deprecated
@ -152,6 +154,13 @@ public interface GeyserConfiguration {
}
}
// TODO this is definitely temporary
interface HybridInfo {
String usernamePrefix();
boolean replaceSpaces();
}
interface IUserAuthenticationInfo {
String getEmail();

View file

@ -62,6 +62,18 @@ public abstract class GeyserJacksonConfiguration implements GeyserConfiguration
private BedrockConfiguration bedrock = new BedrockConfiguration();
private RemoteConfiguration remote = new RemoteConfiguration();
private HybridInfo hybridInfo = new HybridInfo() {
@Override
public String usernamePrefix() {
return ".";
}
@Override
public boolean replaceSpaces() {
return true;
}
};
@JsonProperty("saved-user-logins")
private List<String> savedUserLogins = Collections.emptyList();

View file

@ -36,7 +36,7 @@ import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.geysermc.floodgate.util.DeviceOs;
import org.geysermc.api.util.BedrockPlatform;
import org.geysermc.floodgate.util.FloodgateInfoHolder;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.GeyserApi;
@ -73,7 +73,7 @@ public class DumpInfo {
private final GitInfo gitInfo;
private final GeyserConfiguration config;
private final Floodgate floodgate;
private final Object2IntMap<DeviceOs> userPlatforms;
private final Object2IntMap<BedrockPlatform> userPlatforms;
private final HashInfo hashInfo;
private final RamInfo ramInfo;
private LogsInfo logsInfo;
@ -121,7 +121,7 @@ public class DumpInfo {
this.userPlatforms = new Object2IntOpenHashMap<>();
for (GeyserSession session : GeyserImpl.getInstance().getSessionManager().getAllSessions()) {
DeviceOs device = session.getClientData().getDeviceOs();
BedrockPlatform device = session.getClientData().getDeviceOs();
userPlatforms.put(device, userPlatforms.getOrDefault(device, 0) + 1);
}

View file

@ -36,7 +36,6 @@ import com.nukkitx.nbt.NbtMapBuilder;
import com.nukkitx.nbt.NbtType;
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import com.nukkitx.protocol.bedrock.packet.SetEntityMotionPacket;
import org.geysermc.floodgate.util.DeviceOs;
import org.geysermc.geyser.entity.EntityDefinition;
import org.geysermc.geyser.entity.type.player.PlayerEntity;
import org.geysermc.geyser.level.FireworkColor;
@ -65,13 +64,6 @@ public class FireworkEntity extends Entity {
return;
}
// TODO: Remove once Mojang fixes bugs with fireworks crashing clients on these specific devices.
// https://bugs.mojang.com/browse/MCPE-89115
if (session.getClientData().getDeviceOs() == DeviceOs.XBOX
|| session.getClientData().getDeviceOs() == DeviceOs.PS4) {
return;
}
CompoundTag fireworks = tag.get("Fireworks");
if (fireworks == null) {
// Thank you Mineplex very cool

View file

@ -0,0 +1,54 @@
/*
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.geyser.hybrid;
import org.geysermc.floodgate.crypto.FloodgateCipher;
import org.geysermc.floodgate.pluginmessage.PluginMessageChannels;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.util.PluginMessageUtils;
import java.nio.charset.StandardCharsets;
public final class FloodgateHybridProvider implements HybridProvider {
private final FloodgateCipher cipher;
public FloodgateHybridProvider(GeyserImpl geyser) {
cipher = HybridProvider.getOrCreateKey(geyser);
}
@Override
public void onSkinUpload(GeyserSession session, String value, String signature) {
byte[] bytes = (value + '\0' + signature)
.getBytes(StandardCharsets.UTF_8);
PluginMessageUtils.sendMessage(session, PluginMessageChannels.SKIN, bytes);
}
@Override
public FloodgateCipher getCipher() {
return cipher;
}
}

View file

@ -0,0 +1,90 @@
/*
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.geyser.hybrid;
import org.geysermc.floodgate.crypto.AesCipher;
import org.geysermc.floodgate.crypto.AesKeyProducer;
import org.geysermc.floodgate.crypto.Base64Topping;
import org.geysermc.floodgate.crypto.FloodgateCipher;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.GeyserLogger;
import org.geysermc.geyser.configuration.GeyserConfiguration;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.text.GeyserLocale;
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.Key;
public interface HybridProvider {
void onSkinUpload(GeyserSession session, String value, String signature);
FloodgateCipher getCipher();
static FloodgateCipher getOrCreateKey(GeyserImpl geyser) {
GeyserLogger logger = geyser.getLogger();
GeyserConfiguration config = geyser.getConfig();
try {
// TODO make this common code with Floodgate. Like, make sure Geyser's core and Floodgate's core points to the same thing
FloodgateCipher cipher = new AesCipher(new Base64Topping());
Path keyPath = config.getFloodgateKeyPath();
if (!Files.exists(keyPath)) {
generateFloodgateKey(cipher, keyPath); // Should also init the cipher for us.
// TODO good?
logger.info("We just created a Floodgate key at " + keyPath + ". You will need to copy this file into " +
"your Floodgate config folder(s).");
} else {
Key key = new AesKeyProducer().produceFrom(keyPath);
cipher.init(key);
}
logger.debug(GeyserLocale.getLocaleStringLog("geyser.auth.floodgate.loaded_key"));
return cipher;
} catch (Exception exception) {
logger.severe(GeyserLocale.getLocaleStringLog("geyser.auth.floodgate.bad_key"), exception);
return null;
}
}
static void generateFloodgateKey(FloodgateCipher cipher, Path keyPath) throws Exception {
Key key = new AesKeyProducer().produce();
cipher.init(key);
String test = "abcdefghijklmnopqrstuvwxyz0123456789";
byte[] encrypted = cipher.encryptFromString(test);
String decrypted = cipher.decryptToString(encrypted);
if (!test.equals(decrypted)) {
throw new RuntimeException("Failed to decrypt test message.\n" +
"Original message: " + test + "." +
"Decrypted message: " + decrypted + ".\n" +
"The encrypted message itself: " + new String(encrypted)
);
}
Files.write(keyPath, key.getEncoded());
}
}

View file

@ -0,0 +1,54 @@
/*
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.geyser.hybrid;
import io.netty.util.AttributeKey;
import org.geysermc.floodgate.crypto.FloodgateCipher;
import org.geysermc.floodgate.skin.SkinApplier;
import org.geysermc.floodgate.skin.SkinData;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.session.GeyserSession;
public class IntegratedHybridProvider implements HybridProvider {
// TODO This will probably end up as its own class.
public static final AttributeKey<GeyserSession> SESSION_KEY = AttributeKey.valueOf("geyser-session");
private final SkinApplier skinApplier;
public IntegratedHybridProvider(GeyserImpl geyser) {
skinApplier = geyser.getBootstrap().createSkinApplier();
}
@Override
public void onSkinUpload(GeyserSession session, String value, String signature) {
skinApplier.applySkin(session, new SkinData(value, signature));
}
@Override
public FloodgateCipher getCipher() {
throw new UnsupportedOperationException();
}
}

View file

@ -0,0 +1,60 @@
/*
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.geyser.hybrid;
import org.geysermc.floodgate.crypto.FloodgateCipher;
import org.geysermc.floodgate.util.BedrockData;
import org.geysermc.geyser.GeyserImpl;
import java.nio.charset.StandardCharsets;
public final class ProxyHybridProvider extends IntegratedHybridProvider {
private final FloodgateCipher cipher;
public ProxyHybridProvider(GeyserImpl geyser) {
super(geyser);
this.cipher = HybridProvider.getOrCreateKey(geyser);
}
@Override
public FloodgateCipher getCipher() {
return cipher;
}
// TODO copied from ProxyFloodgateApi
public byte[] createEncryptedData(BedrockData bedrockData) {
try {
return cipher.encryptFromString(bedrockData.toString());
} catch (Exception exception) {
throw new IllegalStateException("We failed to create the encrypted data, " +
"but creating encrypted data is mandatory!", exception);
}
}
public String createEncryptedDataString(BedrockData bedrockData) {
return new String(createEncryptedData(bedrockData), StandardCharsets.UTF_8);
}
}

View file

@ -27,6 +27,10 @@ package org.geysermc.geyser.network.netty;
import io.netty.channel.local.LocalChannel;
import io.netty.channel.local.LocalServerChannel;
import io.netty.util.Attribute;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.hybrid.IntegratedHybridProvider;
import org.geysermc.geyser.session.GeyserSession;
/**
* If the incoming channel if an instance of LocalChannelWithRemoteAddress, this server creates a LocalChannelWrapper
@ -36,9 +40,17 @@ public class LocalServerChannelWrapper extends LocalServerChannel {
@Override
protected LocalChannel newLocalChannel(LocalChannel peer) {
// LocalChannel here should be an instance of LocalChannelWithRemoteAddress, which we can use to set the "remote address" on the other end
if (peer instanceof LocalChannelWithRemoteAddress) {
if (peer instanceof LocalChannelWithRemoteAddress) { // TODO also use attribute for this
LocalChannelWrapper channel = new LocalChannelWrapper(this, peer);
channel.wrapper().remoteAddress(((LocalChannelWithRemoteAddress) peer).spoofedRemoteAddress());
if (GeyserImpl.getInstance().getHybridProvider() instanceof IntegratedHybridProvider) {
Attribute<GeyserSession> attribute = peer.attr(IntegratedHybridProvider.SESSION_KEY);
GeyserSession session = attribute.get();
// Garbage collect since it's no longer relevant for the PacketLib side.
attribute.set(null);
channel.attr(IntegratedHybridProvider.SESSION_KEY).set(session);
}
return channel;
}
return super.newLocalChannel(peer);

View file

@ -36,7 +36,12 @@ import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.*;
import io.netty.channel.unix.PreferredDirectByteBufAllocator;
import io.netty.handler.codec.haproxy.*;
import io.netty.util.Attribute;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.hybrid.IntegratedHybridProvider;
import org.geysermc.geyser.session.GeyserSession;
import javax.annotation.Nullable;
import java.net.Inet4Address;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
@ -52,11 +57,14 @@ public final class LocalSession extends TcpSession {
private final String clientIp;
private final PacketCodecHelper codecHelper;
public LocalSession(String host, int port, SocketAddress targetAddress, String clientIp, PacketProtocol protocol, PacketCodecHelper codecHelper) {
private final GeyserSession session;
public LocalSession(@Nullable GeyserSession session, String host, int port, SocketAddress targetAddress, String clientIp, PacketProtocol protocol, PacketCodecHelper codecHelper) {
super(host, port, protocol);
this.targetAddress = targetAddress;
this.clientIp = clientIp;
this.codecHelper = codecHelper;
this.session = session;
}
@Override
@ -88,6 +96,11 @@ public final class LocalSession extends TcpSession {
pipeline.addLast("manager", LocalSession.this);
addHAProxySupport(pipeline);
if (GeyserImpl.getInstance().getHybridProvider() instanceof IntegratedHybridProvider) {
Attribute<GeyserSession> attribute = channel.attr(IntegratedHybridProvider.SESSION_KEY);
attribute.set(session);
}
}
}).group(DEFAULT_EVENT_LOOP_GROUP).option(ChannelOption.CONNECT_TIMEOUT_MILLIS, getConnectTimeout() * 1000);

View file

@ -112,6 +112,8 @@ import org.geysermc.geyser.entity.type.Entity;
import org.geysermc.geyser.entity.type.ItemFrameEntity;
import org.geysermc.geyser.entity.type.Tickable;
import org.geysermc.geyser.entity.type.player.SessionPlayerEntity;
import org.geysermc.geyser.hybrid.FloodgateHybridProvider;
import org.geysermc.geyser.hybrid.HybridProvider;
import org.geysermc.geyser.inventory.Inventory;
import org.geysermc.geyser.inventory.PlayerInventory;
import org.geysermc.geyser.inventory.recipe.GeyserRecipe;
@ -128,7 +130,7 @@ import org.geysermc.geyser.registry.type.ItemMappings;
import org.geysermc.geyser.session.auth.AuthData;
import org.geysermc.geyser.session.auth.BedrockClientData;
import org.geysermc.geyser.session.cache.*;
import org.geysermc.geyser.skin.FloodgateSkinUploader;
import org.geysermc.geyser.skin.BedrockSkinUploader;
import org.geysermc.geyser.text.GeyserLocale;
import org.geysermc.geyser.text.MinecraftLocale;
import org.geysermc.geyser.text.TextDecoration;
@ -857,7 +859,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
if (geyser.getBootstrap().getSocketAddress() != null) {
// We're going to connect through the JVM and not through TCP
downstream = new LocalSession(this.remoteServer.address(), this.remoteServer.port(),
downstream = new LocalSession(this, this.remoteServer.address(), this.remoteServer.port(),
geyser.getBootstrap().getSocketAddress(), upstream.getAddress().getAddress().getHostAddress(),
this.protocol, this.protocol.createHelper());
} else {
@ -879,12 +881,13 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
//todo move this somewhere else
if (event.getPacket() instanceof ClientIntentionPacket) {
String addressSuffix;
if (floodgate) {
HybridProvider provider;
if (floodgate && (provider = geyser.getHybridProvider()) instanceof FloodgateHybridProvider) {
byte[] encryptedData;
try {
FloodgateSkinUploader skinUploader = geyser.getSkinUploader();
FloodgateCipher cipher = geyser.getCipher();
BedrockSkinUploader skinUploader = geyser.getSkinUploader();
FloodgateCipher cipher = provider.getCipher();
String bedrockAddress = upstream.getAddress().getAddress().getHostAddress();
// both BungeeCord and Velocity remove the IPv6 scope (if there is one) for Spigot
@ -1377,7 +1380,8 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
upstream.sendPacket(chunkRadiusUpdatedPacket);
}
public InetSocketAddress getSocketAddress() {
@Override
public InetSocketAddress socketAddress() {
return this.upstream.getAddress();
}
@ -1857,7 +1861,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
@Override
public @NonNull BedrockPlatform platform() {
return BedrockPlatform.values()[clientData.getDeviceOs().ordinal()]; //todo
return clientData.getDeviceOs();
}
@Override
@ -1867,12 +1871,12 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
@Override
public @NonNull UiProfile uiProfile() {
return UiProfile.values()[clientData.getUiProfile().ordinal()]; //todo
return clientData.getUiProfile();
}
@Override
public @NonNull InputMode inputMode() {
return InputMode.values()[clientData.getCurrentInputMode().ordinal()]; //todo
return clientData.getCurrentInputMode();
}
@Override

View file

@ -30,9 +30,9 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;
import org.geysermc.floodgate.util.DeviceOs;
import org.geysermc.floodgate.util.InputMode;
import org.geysermc.floodgate.util.UiProfile;
import org.geysermc.api.util.BedrockPlatform;
import org.geysermc.api.util.InputMode;
import org.geysermc.api.util.UiProfile;
import java.util.UUID;
@ -80,7 +80,7 @@ public final class BedrockClientData {
@JsonProperty(value = "DeviceModel")
private String deviceModel;
@JsonProperty(value = "DeviceOS")
private DeviceOs deviceOs;
private BedrockPlatform deviceOs;
@JsonProperty(value = "UIProfile")
private UiProfile uiProfile;
@JsonProperty(value = "GuiScale")
@ -113,8 +113,8 @@ public final class BedrockClientData {
@Setter
private String originalString = null;
public DeviceOs getDeviceOs() {
return deviceOs != null ? deviceOs : DeviceOs.UNKNOWN;
public BedrockPlatform getDeviceOs() {
return deviceOs != null ? deviceOs : BedrockPlatform.UNKNOWN;
}
public InputMode getCurrentInputMode() {

View file

@ -30,26 +30,23 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.Getter;
import org.geysermc.floodgate.pluginmessage.PluginMessageChannels;
import org.geysermc.floodgate.util.WebsocketEventType;
import org.geysermc.geyser.Constants;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.GeyserLogger;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.util.PluginMessageUtils;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;
import javax.net.ssl.SSLException;
import java.net.ConnectException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
public final class FloodgateSkinUploader {
public final class BedrockSkinUploader {
private final ObjectMapper JACKSON = new ObjectMapper();
private final List<String> skinQueue = new ArrayList<>();
@ -59,9 +56,8 @@ public final class FloodgateSkinUploader {
@Getter private int id;
@Getter private String verifyCode;
@Getter private int subscribersCount;
public FloodgateSkinUploader(GeyserImpl geyser) {
public BedrockSkinUploader(GeyserImpl geyser) {
this.logger = geyser.getLogger();
this.client = new WebSocketClient(Constants.GLOBAL_API_WS_URI) {
@Override
@ -100,14 +96,11 @@ public final class FloodgateSkinUploader {
verifyCode = node.get("verify_code").asText();
break;
case SUBSCRIBER_COUNT:
subscribersCount = node.get("subscribers_count").asInt();
logger.debug("Ignoring subscribers count message.");
break;
case SKIN_UPLOADED:
// if Geyser is the only subscriber we have send it to the server manually
// otherwise it's handled by the Floodgate plugin subscribers
if (subscribersCount != 1) {
break;
}
String xuid = node.get("xuid").asText();
GeyserSession session = geyser.connectionByXuid(xuid);
@ -123,9 +116,7 @@ public final class FloodgateSkinUploader {
String value = data.get("value").asText();
String signature = data.get("signature").asText();
byte[] bytes = (value + '\0' + signature)
.getBytes(StandardCharsets.UTF_8);
PluginMessageUtils.sendMessage(session, PluginMessageChannels.SKIN, bytes);
geyser.getHybridProvider().onSkinUpload(session, value, signature);
}
break;
case LOG_MESSAGE:
@ -222,7 +213,7 @@ public final class FloodgateSkinUploader {
.schedule(client::reconnect, 8 + additionalTime, TimeUnit.SECONDS);
}
public FloodgateSkinUploader start() {
public BedrockSkinUploader start() {
client.connect();
return this;
}

View file

@ -29,7 +29,7 @@ import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundKe
import com.nukkitx.protocol.bedrock.data.AttributeData;
import com.nukkitx.protocol.bedrock.packet.NetworkStackLatencyPacket;
import com.nukkitx.protocol.bedrock.packet.UpdateAttributesPacket;
import org.geysermc.floodgate.util.DeviceOs;
import org.geysermc.api.util.BedrockPlatform;
import org.geysermc.geyser.entity.attribute.GeyserAttributeType;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.protocol.PacketTranslator;
@ -50,7 +50,7 @@ public class BedrockNetworkStackLatencyTranslator extends PacketTranslator<Netwo
// so apparently, as of 1.16.200
// PS4 divides the network stack latency timestamp FOR US!!!
// WTF
if (session.getClientData().getDeviceOs().equals(DeviceOs.PS4)) {
if (session.getClientData().getDeviceOs() == BedrockPlatform.PS4) {
pingId = packet.getTimestamp();
} else {
pingId = packet.getTimestamp() / 1000;

View file

@ -209,10 +209,4 @@ enable-proxy-connections: false
# 1400 is the default.
mtu: 1400
# Whether to connect directly into the Java server without creating a TCP connection.
# This should only be disabled if a plugin that interfaces with packets or the network does not work correctly with Geyser.
# If enabled on plugin versions, the remote address and port sections are ignored
# If disabled on plugin versions, expect performance decrease and latency increase
use-direct-connection: true
config-version: 4