Compare commits

...

3 Commits

Author SHA1 Message Date
chris 05e668894d
Merge f16084fc2e into 42a9ba617b 2024-04-26 23:32:00 +02:00
RK_01 42a9ba617b
Update ViaProxy platform (#4607)
* Update ViaProxy API usage

* Don't reference ViaProxy API in dummy application
2024-04-26 20:06:37 +02:00
onebeastchris f16084fc2e Feat: Make connection data exposed in api less prone to throw errors 2024-04-25 19:42:35 +02:00
10 changed files with 47 additions and 29 deletions

View File

@ -46,13 +46,35 @@ public final class ConnectionRequestEvent implements Event, Cancellable {
this.proxyIp = proxyIp;
}
/**
* The IP address of the client attempting to connect
*
* @return the IP address of the client attempting to connect
* @deprecated Use {@link #inetSocketAddress()} instead
*/
@NonNull @Deprecated
public InetSocketAddress getInetSocketAddress() {
return ip;
}
/**
* The IP address of the proxy handling the connection. It will return null if there is no proxy.
*
* @return the IP address of the proxy handling the connection
* @deprecated Use {@link #proxyIp()} instead
*/
@Nullable @Deprecated
public InetSocketAddress getProxyIp() {
return proxyIp;
}
/**
* The IP address of the client attempting to connect
*
* @return the IP address of the client attempting to connect
*/
@NonNull
public InetSocketAddress getInetSocketAddress() {
public InetSocketAddress inetSocketAddress() {
return ip;
}
@ -62,7 +84,7 @@ public final class ConnectionRequestEvent implements Event, Cancellable {
* @return the IP address of the proxy handling the connection
*/
@Nullable
public InetSocketAddress getProxyIp() {
public InetSocketAddress proxyIp() {
return proxyIp;
}

View File

@ -26,7 +26,7 @@ package org.geysermc.geyser.platform.viaproxy;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
import net.raphimc.viaproxy.cli.options.Options;
import net.raphimc.viaproxy.ViaProxy;
import org.geysermc.geyser.configuration.GeyserJacksonConfiguration;
import java.io.File;
@ -43,7 +43,7 @@ public class GeyserViaProxyConfiguration extends GeyserJacksonConfiguration {
@Override
public int getPingPassthroughInterval() {
int interval = super.getPingPassthroughInterval();
if (interval < 15 && Options.PROTOCOL_VERSION != null && Options.PROTOCOL_VERSION.olderThanOrEqualTo(LegacyProtocolVersion.r1_6_4)) {
if (interval < 15 && ViaProxy.getConfig().getTargetVersion() != null && ViaProxy.getConfig().getTargetVersion().olderThanOrEqualTo(LegacyProtocolVersion.r1_6_4)) {
// <= 1.6.4 servers sometimes block incoming connections from an IP address if too many connections are made
interval = 15;
}

View File

@ -26,7 +26,6 @@ package org.geysermc.geyser.platform.viaproxy;
import lombok.Getter;
import net.raphimc.viaproxy.ViaProxy;
import net.raphimc.viaproxy.cli.options.Options;
import net.raphimc.viaproxy.plugins.ViaProxyPlugin;
import org.geysermc.geyser.dump.BootstrapDumpInfo;
import org.geysermc.geyser.text.AsteriskSerializer;
@ -49,8 +48,8 @@ public class GeyserViaProxyDumpInfo extends BootstrapDumpInfo {
public GeyserViaProxyDumpInfo() {
this.platformVersion = ViaProxy.VERSION;
this.onlineMode = Options.ONLINE_MODE;
if (Options.BIND_ADDRESS instanceof InetSocketAddress inetSocketAddress) {
this.onlineMode = ViaProxy.getConfig().isProxyOnlineMode();
if (ViaProxy.getConfig().getBindAddress() instanceof InetSocketAddress inetSocketAddress) {
this.serverIP = inetSocketAddress.getHostString();
this.serverPort = inetSocketAddress.getPort();
} else {

View File

@ -25,7 +25,6 @@
package org.geysermc.geyser.platform.viaproxy;
import net.raphimc.viaproxy.plugins.PluginManager;
import org.geysermc.geyser.GeyserMain;
public class GeyserViaProxyMain extends GeyserMain {
@ -39,7 +38,7 @@ public class GeyserViaProxyMain extends GeyserMain {
}
public String getPluginFolder() {
return PluginManager.PLUGINS_DIR.getName();
return "plugins";
}
}

View File

@ -27,7 +27,6 @@ package org.geysermc.geyser.platform.viaproxy;
import net.lenni0451.lambdaevents.EventHandler;
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
import net.raphimc.viaproxy.ViaProxy;
import net.raphimc.viaproxy.cli.options.Options;
import net.raphimc.viaproxy.plugins.PluginManager;
import net.raphimc.viaproxy.plugins.ViaProxyPlugin;
import net.raphimc.viaproxy.plugins.events.ConsoleCommandEvent;
@ -137,7 +136,7 @@ public class GeyserViaProxyPlugin extends ViaProxyPlugin implements GeyserBootst
GeyserImpl.start();
if (Options.PROTOCOL_VERSION != null && Options.PROTOCOL_VERSION.newerThanOrEqualTo(LegacyProtocolVersion.b1_8tob1_8_1)) {
if (ViaProxy.getConfig().getTargetVersion() != null && ViaProxy.getConfig().getTargetVersion().newerThanOrEqualTo(LegacyProtocolVersion.b1_8tob1_8_1)) {
// Only initialize the ping passthrough if the protocol version is above beta 1.7.3, as that's when the status protocol was added
this.pingPassthrough = GeyserLegacyPingPassthrough.init(this.geyser);
}
@ -186,19 +185,19 @@ public class GeyserViaProxyPlugin extends ViaProxyPlugin implements GeyserBootst
@NotNull
@Override
public String getServerBindAddress() {
if (Options.BIND_ADDRESS instanceof InetSocketAddress socketAddress) {
if (ViaProxy.getConfig().getBindAddress() instanceof InetSocketAddress socketAddress) {
return socketAddress.getHostString();
} else {
throw new IllegalStateException("Unsupported bind address type: " + Options.BIND_ADDRESS.getClass().getName());
throw new IllegalStateException("Unsupported bind address type: " + ViaProxy.getConfig().getBindAddress().getClass().getName());
}
}
@Override
public int getServerPort() {
if (Options.BIND_ADDRESS instanceof InetSocketAddress socketAddress) {
if (ViaProxy.getConfig().getBindAddress() instanceof InetSocketAddress socketAddress) {
return socketAddress.getPort();
} else {
throw new IllegalStateException("Unsupported bind address type: " + Options.BIND_ADDRESS.getClass().getName());
throw new IllegalStateException("Unsupported bind address type: " + ViaProxy.getConfig().getBindAddress().getClass().getName());
}
}

View File

@ -2,4 +2,4 @@ name: "${name}-ViaProxy"
version: "${version}"
author: "${author}"
main: "org.geysermc.geyser.platform.viaproxy.GeyserViaProxyPlugin"
min-version: "3.2.0"
min-version: "3.2.1"

View File

@ -25,11 +25,8 @@
package org.geysermc.geyser.network;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.DefaultEventLoopGroup;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.concurrent.DefaultThreadFactory;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.cloudburstmc.protocol.bedrock.BedrockPeer;
@ -37,7 +34,6 @@ import org.cloudburstmc.protocol.bedrock.BedrockServerSession;
import org.cloudburstmc.protocol.bedrock.netty.codec.packet.BedrockPacketCodec;
import org.cloudburstmc.protocol.bedrock.netty.initializer.BedrockServerInitializer;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.event.bedrock.SessionInitializeEvent;
import org.geysermc.geyser.session.GeyserSession;
import java.net.InetSocketAddress;
@ -72,7 +68,6 @@ public class GeyserServerInitializer extends BedrockServerInitializer {
channel.pipeline().addAfter(BedrockPacketCodec.NAME, InvalidPacketHandler.NAME, new InvalidPacketHandler(session));
bedrockServerSession.setPacketHandler(new UpstreamPacketHandler(this.geyser, session));
this.geyser.eventBus().fire(new SessionInitializeEvent(session));
} catch (Throwable e) {
// Error must be caught or it will be swallowed
this.geyser.getLogger().error("Error occurred while initializing player!", e);

View File

@ -65,8 +65,6 @@ import io.netty.channel.Channel;
import io.netty.channel.EventLoop;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
@ -1100,9 +1098,11 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
if (!closed) {
loggedIn = false;
// Fire SessionDisconnectEvent
SessionDisconnectEvent disconnectEvent = new SessionDisconnectEvent(this, reason);
geyser.getEventBus().fire(disconnectEvent);
if (authData != null && clientData != null) {
// Fire SessionDisconnectEvent
geyser.getEventBus().fire(disconnectEvent);
}
// Disconnect downstream if necessary
if (downstream != null) {
@ -1427,7 +1427,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
@Override
public String name() {
return null;
return this.isLoggedIn() ? this.javaUsername() : this.bedrockUsername();
}
@Override
@ -1953,12 +1953,12 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
@Override
public @MonotonicNonNull String javaUsername() {
return playerEntity.getUsername();
return playerEntity != null ? playerEntity.getUsername() : null;
}
@Override
public UUID javaUuid() {
return playerEntity.getUuid();
return playerEntity != null ? playerEntity.getUuid() : null ;
}
@Override

View File

@ -40,6 +40,7 @@ import org.geysermc.cumulus.response.SimpleFormResponse;
import org.geysermc.cumulus.response.result.FormResponseResult;
import org.geysermc.cumulus.response.result.ValidFormResponseResult;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.event.bedrock.SessionInitializeEvent;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.session.auth.AuthData;
import org.geysermc.geyser.session.auth.BedrockClientData;
@ -100,6 +101,9 @@ public class LoginEncryptionUtils {
sendEncryptionFailedMessage(geyser);
}
// Fire SessionInitializeEvent here as we now know the client data etc
geyser.eventBus().fire(new SessionInitializeEvent(session));
} catch (Exception ex) {
session.disconnect("disconnectionScreen.internalError.cantConnect");
throw new RuntimeException("Unable to complete login", ex);

View File

@ -29,7 +29,7 @@ adapters = "1.11-SNAPSHOT"
commodore = "2.2"
bungeecord = "a7c6ede"
velocity = "3.1.1"
viaproxy = "3.2.0-SNAPSHOT"
viaproxy = "3.2.1"
fabric-minecraft = "1.20.4"
fabric-loader = "0.15.2"
fabric-api = "0.91.2+1.20.4"