SteamWar/BungeeCore
Archiviert
13
2

Fixes
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
zOnlyKroks 2022-01-08 09:57:45 +01:00
Ursprung 9218544349
Commit 28946876cf
4 geänderte Dateien mit 52 neuen und 61 gelöschten Zeilen

Datei anzeigen

@ -1,43 +1,48 @@
/*
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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bungeecore.listeners.mods; package de.steamwar.bungeecore.listeners.mods;
import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.sql.Mod;
import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.LoginEvent; import net.md_5.bungee.api.event.LoginEvent;
import net.md_5.bungee.api.event.PreLoginEvent;
import net.md_5.bungee.api.plugin.Event;
import net.md_5.bungee.netty.ChannelWrapper;
import net.md_5.bungee.netty.PacketHandler; import net.md_5.bungee.netty.PacketHandler;
import net.md_5.bungee.protocol.packet.LoginPayloadResponse; import net.md_5.bungee.protocol.packet.LoginPayloadResponse;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
public class CustomPacketHandler extends PacketHandler { public class CustomPacketHandler extends PacketHandler {
private LoginEvent event; private LoginEvent event;
private ChannelWrapper wrapper;
public CustomPacketHandler(LoginEvent event, ChannelWrapper wrapper) { public CustomPacketHandler(LoginEvent event) {
this.event = event; this.event = event;
this.wrapper = wrapper;
} }
@Override public String toString() { @Override
public String toString() {
return null; return null;
} }
public void handle(LoginPayloadResponse response){ public void handle(LoginPayloadResponse response){
if(response.getData() == null) { if(response.getData() == null) {
System.out.println("Data is null with id: " + response.getId() + " , which means Client has no installed mods!");
event.completeIntent(BungeeCore.get()); event.completeIntent(BungeeCore.get());
return; return;
} }
byte[] data = response.getData();
event.completeIntent(BungeeCore.get()); event.completeIntent(BungeeCore.get());
} }

Datei anzeigen

@ -1,3 +1,21 @@
/*
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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bungeecore.listeners.mods; package de.steamwar.bungeecore.listeners.mods;
import net.md_5.bungee.api.ServerPing; import net.md_5.bungee.api.ServerPing;

Datei anzeigen

@ -19,6 +19,7 @@
package de.steamwar.bungeecore.listeners.mods; package de.steamwar.bungeecore.listeners.mods;
import com.google.common.collect.ImmutableMap;
import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.listeners.BasicListener; import de.steamwar.bungeecore.listeners.BasicListener;
import de.steamwar.bungeecore.sql.Mod; import de.steamwar.bungeecore.sql.Mod;
@ -41,14 +42,13 @@ import java.lang.reflect.Field;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
public class Forge extends BasicListener { public class Forge extends BasicListener {
private static final String FMLHS = "FML|HS"; private static final String FMLHS = "FML|HS";
private static final String FMLHS13 = "fml:handshake";
private static final String WRAPPER = "fml:loginwrapper"; private static final String WRAPPER = "fml:loginwrapper";
private static final byte[] REGISTER; private static final byte[] REGISTER;
private static final byte[] REGISTER13;
private static final byte[] HELLO = new byte[]{0, 2, 0, 0, 0, 0}; private static final byte[] HELLO = new byte[]{0, 2, 0, 0, 0, 0};
private static final Set<UUID> unlocked = new HashSet<>(); private static final Set<UUID> unlocked = new HashSet<>();
@ -58,37 +58,28 @@ public class Forge extends BasicListener {
buf.writeCharSequence(FMLHS, StandardCharsets.UTF_8); buf.writeCharSequence(FMLHS, StandardCharsets.UTF_8);
REGISTER = new byte[buf.readableBytes()]; REGISTER = new byte[buf.readableBytes()];
buf.readBytes(REGISTER); buf.readBytes(REGISTER);
buf.clear();
buf.writeByte(13);
buf.writeCharSequence(FMLHS13, StandardCharsets.UTF_8);
REGISTER13 = new byte[buf.readableBytes()];
buf.readBytes(REGISTER13);
} }
@EventHandler @EventHandler
public void onServerConnected(LoginEvent event){ public void onServerConnected(LoginEvent event){
//Wir senden Packet ID 1 if(event.getConnection().getVersion() < 340) return; //1.13+
//Wir wollen empfangen Packet ID 2
//(FMLHS13, new byte[]{4, 1, 0, 0, 0});
//13,102,109,108,58,104,97,110,100,115,104,97,107,101 = 13 + "fml:handshake"
event.getConnection().unsafe().sendPacket(new LoginPayloadRequest(1,WRAPPER, new byte[]{13,102,109,108,58,104,97,110,100,115,104,97,107,101,4,1,0,0,0})); event.getConnection().unsafe().sendPacket(new LoginPayloadRequest(1,WRAPPER, new byte[]{13,102,109,108,58,104,97,110,100,115,104,97,107,101,4,1,0,0,0}));
event.registerIntent(BungeeCore.get());
InitialHandler handler = (InitialHandler) event.getConnection(); InitialHandler handler = (InitialHandler) event.getConnection();
Field ch; Field ch;
ChannelWrapper wrapper = null; ChannelWrapper wrapper;
try{ try{
ch = handler.getClass().getDeclaredField("ch"); ch = handler.getClass().getDeclaredField("ch");
ch.setAccessible(true); ch.setAccessible(true);
wrapper = (ChannelWrapper) ch.get(handler); wrapper = (ChannelWrapper) ch.get(handler);
} catch (NoSuchFieldException | IllegalAccessException e) { } catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace(); BungeeCore.get().getLogger().log(Level.SEVERE, "Could not get Channel", e);
return;
} }
wrapper.getHandle().pipeline().get(HandlerBoss.class).setHandler(new CustomPacketHandler(event, wrapper)); event.registerIntent(BungeeCore.get());
wrapper.getHandle().pipeline().get(HandlerBoss.class).setHandler(new CustomPacketHandler(event));
} }
@EventHandler @EventHandler
@ -107,10 +98,7 @@ public class Forge extends BasicListener {
} }
} }
if(player.getPendingConnection().getVersion() > 340) { if(player.getPendingConnection().getVersion() <= 340) {
player.sendData("minecraft:register", REGISTER13); //1.13+
player.sendData(FMLHS13, Forge.HELLO);
}else{
player.sendData("REGISTER", REGISTER); //1.12- player.sendData("REGISTER", REGISTER); //1.12-
player.sendData(FMLHS, Forge.HELLO); player.sendData(FMLHS, Forge.HELLO);
} }
@ -118,7 +106,7 @@ public class Forge extends BasicListener {
@EventHandler @EventHandler
public void onPluginMessageEvent(PluginMessageEvent e){ public void onPluginMessageEvent(PluginMessageEvent e){
if(!e.getTag().equals(FMLHS) && !e.getTag().equals(FMLHS13)) if(!e.getTag().equals(FMLHS))
return; return;
e.setCancelled(true); e.setCancelled(true);

Datei anzeigen

@ -56,26 +56,6 @@ public class ModLoaderBlocker extends BasicListener {
} }
} }
@EventHandler
public void onPluginMessage(PluginMessageEvent e){
if(!e.getTag().equals("minecraft:register"))
return;
Connection sender = e.getSender();
if(!(sender instanceof ProxiedPlayer))
return;
ProxiedPlayer p = (ProxiedPlayer) sender;
if(p.getPendingConnection().getVersion() <= 340)
return;
String registered = new String(e.getData(), StandardCharsets.UTF_8);
if(registered.contains("fml:loginwrapper") || registered.contains("fml:handshake") || registered.contains("fml:play")){
Storage.fabricPlayers.add(p);
Message.send("MODLOADER_INSTALLED", p, "Forge");
}
}
@EventHandler @EventHandler
public void onDisconnect(PlayerDisconnectEvent e){ public void onDisconnect(PlayerDisconnectEvent e){
Storage.fabricPlayers.remove(e.getPlayer()); Storage.fabricPlayers.remove(e.getPlayer());