From ce88e69ed0be03857ed7bd34756703049fe1ff76 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 10 Apr 2022 23:41:53 +0200 Subject: [PATCH] Update stuff --- src/de/steamwar/SteamWarBungeeTeamserver.java | 8 ++--- src/de/steamwar/command/TestCommand.java | 2 +- ...r.java => SteamwarConnectionListener.java} | 32 ++++++++++++------- 3 files changed, 24 insertions(+), 18 deletions(-) rename src/de/steamwar/listener/{TestListener.java => SteamwarConnectionListener.java} (75%) diff --git a/src/de/steamwar/SteamWarBungeeTeamserver.java b/src/de/steamwar/SteamWarBungeeTeamserver.java index b92ea75..5582053 100644 --- a/src/de/steamwar/SteamWarBungeeTeamserver.java +++ b/src/de/steamwar/SteamWarBungeeTeamserver.java @@ -1,20 +1,16 @@ package de.steamwar; -import de.steamwar.command.TestCommand; -import de.steamwar.listener.TestListener; +import de.steamwar.listener.SteamwarConnectionListener; import net.md_5.bungee.api.plugin.Plugin; public final class SteamWarBungeeTeamserver extends Plugin { @Override public void onEnable() { - getProxy().getPluginManager().registerListener(this, new TestListener()); - getProxy().getPluginManager().registerCommand(this, new TestCommand()); - // Plugin startup logic + getProxy().getPluginManager().registerListener(this, new SteamwarConnectionListener()); } @Override public void onDisable() { - // Plugin shutdown logic } } diff --git a/src/de/steamwar/command/TestCommand.java b/src/de/steamwar/command/TestCommand.java index e7159ab..bc8560e 100644 --- a/src/de/steamwar/command/TestCommand.java +++ b/src/de/steamwar/command/TestCommand.java @@ -8,7 +8,7 @@ import net.md_5.bungee.api.plugin.Command; import java.net.InetSocketAddress; -public class TestCommand extends Command { +public class TestCommand extends Command { // TODO: This will be removed later on public TestCommand() { super("test"); diff --git a/src/de/steamwar/listener/TestListener.java b/src/de/steamwar/listener/SteamwarConnectionListener.java similarity index 75% rename from src/de/steamwar/listener/TestListener.java rename to src/de/steamwar/listener/SteamwarConnectionListener.java index f4fbb94..1cb0ecf 100644 --- a/src/de/steamwar/listener/TestListener.java +++ b/src/de/steamwar/listener/SteamwarConnectionListener.java @@ -1,11 +1,11 @@ package de.steamwar.listener; import io.netty.buffer.ByteBuf; -import net.md_5.bungee.api.connection.PendingConnection; import net.md_5.bungee.api.event.PreLoginEvent; import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.connection.InitialHandler; import net.md_5.bungee.event.EventHandler; +import net.md_5.bungee.netty.ChannelWrapper; import net.md_5.bungee.protocol.Protocol; import net.md_5.bungee.protocol.ProtocolConstants; import net.md_5.bungee.protocol.packet.Handshake; @@ -13,16 +13,17 @@ import net.md_5.bungee.protocol.packet.Handshake; import java.lang.reflect.Array; import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.net.InetSocketAddress; import java.util.Arrays; +import java.util.UUID; import java.util.function.Supplier; -public class TestListener implements Listener { +public class SteamwarConnectionListener implements Listener { - private Field handShakeField; + private Field chField; private static class SteamwarHandshake extends Handshake { public void read(ByteBuf buf) { - System.out.println("read"); setProtocolVersion(readVarInt(buf)); setHost(readString(buf)); setPort(buf.readUnsignedShort()); @@ -58,8 +59,8 @@ public class TestListener implements Listener { } }, protocolMappingArray); - handShakeField = InitialHandler.class.getDeclaredField("handshake"); - handShakeField.setAccessible(true); + chField = InitialHandler.class.getDeclaredField("ch"); + chField.setAccessible(true); } catch (Exception e) { e.printStackTrace(); } @@ -67,20 +68,29 @@ public class TestListener implements Listener { @EventHandler public void preLoginEvent(PreLoginEvent preLoginEvent) { - PendingConnection pendingConnection = preLoginEvent.getConnection(); - System.out.println("PreLoginEvent " + preLoginEvent); String address = preLoginEvent.getConnection().getSocketAddress().toString(); if (address.startsWith("/78.31.71.136:")) { - SteamwarHandshake handshake; + InitialHandler initialHandler = (InitialHandler) preLoginEvent.getConnection(); + String extraData = initialHandler.getExtraDataInHandshake(); + String[] split = extraData.split("\0"); + try { - handshake = (SteamwarHandshake) handShakeField.get(pendingConnection); + ChannelWrapper channelWrapper = ((ChannelWrapper) chField.get(initialHandler)); + channelWrapper.setRemoteAddress(new InetSocketAddress(split[1], ((InetSocketAddress) channelWrapper.getRemoteAddress()).getPort())); } catch (IllegalAccessException e) { e.printStackTrace(); return; } - System.out.println(Arrays.toString(handshake.getHost().split("\0"))); + // 0: host, 1: address, 2: uuid, (3): mojangProfile (properties, so skin data) preLoginEvent.getConnection().setOnlineMode(false); + + StringBuilder st = new StringBuilder(split[2]); + st.insert(8, '-'); + st.insert(13, '-'); + st.insert(18, '-'); + st.insert(23, '-'); + initialHandler.setUniqueId(UUID.fromString(st.toString())); } } }