From b8a3512643f2aebe4dc15b548fcfab6505f6f9db Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 22 Apr 2022 15:55:34 +0200 Subject: [PATCH] Add SubserverProtocolFixer --- src/de/steamwar/bungeecore/BungeeCore.java | 1 + .../listeners/SubserverProtocolFixer.java | 63 +++++++++++++++++++ .../steamwar/messages/BungeeCore.properties | 1 + 3 files changed, 65 insertions(+) create mode 100644 src/de/steamwar/bungeecore/listeners/SubserverProtocolFixer.java diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index a8b9c4f..ffef144 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -85,6 +85,7 @@ public class BungeeCore extends Plugin { new WorldDownloader(); new BrandListener(); new Fabric(); + new SubserverProtocolFixer(); new Node.LocalNode(); //new Node.RemoteNode("lx"); diff --git a/src/de/steamwar/bungeecore/listeners/SubserverProtocolFixer.java b/src/de/steamwar/bungeecore/listeners/SubserverProtocolFixer.java new file mode 100644 index 0000000..d14a78f --- /dev/null +++ b/src/de/steamwar/bungeecore/listeners/SubserverProtocolFixer.java @@ -0,0 +1,63 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bungeecore.listeners; + +import io.github.waterfallmc.waterfall.utils.UUIDUtils; +import net.md_5.bungee.BungeeCord; +import net.md_5.bungee.api.event.LoginEvent; +import net.md_5.bungee.connection.InitialHandler; +import net.md_5.bungee.connection.LoginResult; +import net.md_5.bungee.event.EventHandler; +import net.md_5.bungee.util.AddressUtil; + +import java.lang.reflect.Field; +import java.net.InetSocketAddress; + +public class SubserverProtocolFixer extends BasicListener { + + private final InetSocketAddress inetSocketAddress = new InetSocketAddress("127.127.127.127", 25565); + + private Field field; + + { + try { + field = InitialHandler.class.getDeclaredField("extraDataInHandshake"); + field.setAccessible(true); + } catch (Exception e) { + BungeeCord.getInstance().stop(); + } + } + + @EventHandler + public void loginEvent(LoginEvent e) { + System.out.println(e); + InitialHandler initialHandler = ((InitialHandler) e.getConnection()); + LoginResult.Property[] properties = initialHandler.getLoginProfile().getProperties(); + try { + String extraData = "\00" + AddressUtil.sanitizeAddress(inetSocketAddress) + "\00" + UUIDUtils.undash(initialHandler.getUniqueId().toString()); + if (properties.length > 0) { + extraData += "\00" + BungeeCord.getInstance().gson.toJson(properties); + } + field.set(initialHandler, extraData); + } catch (Exception ex) { + BungeeCord.getInstance().stop(); + } + } +} diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index f25476f..9cfecf9 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -467,6 +467,7 @@ TEAM_SERVER_USAGE=§8/§7team server §8[§eIP/Address§8] §8(§7Port§8) §8- TEAM_SERVER_SET=§7Du hast die Teamserveradresse geändert§8! TEAM_SERVER_PORT_INVALID=§cDer Port muss eine Zahl sein. TEAM_NO_ADDRESS=§cTeamserveradresse nicht gesetzt. +TEAM_TP_NO_TEAM=§cUnbekanntes Team. #TpCommand TP_USAGE=§8/§7tp §8[§eSpieler§8]