13
0
Dieser Commit ist enthalten in:
yoyosource 2022-04-10 23:41:53 +02:00
Ursprung 1e2a3030ca
Commit ce88e69ed0
3 geänderte Dateien mit 24 neuen und 18 gelöschten Zeilen

Datei anzeigen

@ -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
}
}

Datei anzeigen

@ -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");

Datei anzeigen

@ -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()));
}
}
}