Archiviert
1
0

Primitive Version

Dieser Commit ist enthalten in:
zOnlyKroks 2022-01-07 11:50:26 +01:00
Ursprung 55a5492a2d
Commit 9218544349
3 geänderte Dateien mit 130 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,44 @@
package de.steamwar.bungeecore.listeners.mods;
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.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.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 {
private LoginEvent event;
private ChannelWrapper wrapper;
public CustomPacketHandler(LoginEvent event, ChannelWrapper wrapper) {
this.event = event;
this.wrapper = wrapper;
}
@Override public String toString() {
return null;
}
public void handle(LoginPayloadResponse response){
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());
return;
}
event.completeIntent(BungeeCore.get());
}
}

Datei anzeigen

@ -0,0 +1,48 @@
package de.steamwar.bungeecore.listeners.mods;
import net.md_5.bungee.api.ServerPing;
import java.util.ArrayList;
import java.util.List;
public class FMLPing extends ServerPing {
private final ForgeData forgeData = new ForgeData();
public FMLPing(ServerPing existing) {
super(existing.getVersion(), existing.getPlayers(), existing.getDescriptionComponent(), existing.getFaviconObject());
}
private static class ForgeData {
private final List<ForgeChannel> channels = new ArrayList<>();
private final List<ForgeMod> mods = new ArrayList<>();
private final int fmlNetworkVersion = 2;
public ForgeData() {
channels.add(new ForgeChannel("minecraft:unregister"));
channels.add(new ForgeChannel("minecraft:register"));
channels.add(new ForgeChannel("fml:handshake"));
mods.add(new ForgeMod("minecraft", "1.15.2"));
mods.add(new ForgeMod("forge", "ANY"));
}
private static class ForgeChannel {
private final String res;
private final String version = "FML2";
private final boolean required = true;
private ForgeChannel(String res) {
this.res = res;
}
}
private static class ForgeMod {
private final String modId;
private final String modmarker;
private ForgeMod(String modId, String modmarker) {
this.modId = modId;
this.modmarker = modmarker;
}
}
}
}

Datei anzeigen

@ -27,10 +27,17 @@ import io.netty.buffer.UnpooledByteBufAllocator;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.Connection; import net.md_5.bungee.api.connection.Connection;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.LoginEvent;
import net.md_5.bungee.api.event.PluginMessageEvent; import net.md_5.bungee.api.event.PluginMessageEvent;
import net.md_5.bungee.api.event.PostLoginEvent; import net.md_5.bungee.api.event.PostLoginEvent;
import net.md_5.bungee.api.event.ProxyPingEvent;
import net.md_5.bungee.connection.InitialHandler;
import net.md_5.bungee.event.EventHandler; import net.md_5.bungee.event.EventHandler;
import net.md_5.bungee.netty.ChannelWrapper;
import net.md_5.bungee.netty.HandlerBoss;
import net.md_5.bungee.protocol.packet.LoginPayloadRequest;
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;
@ -39,6 +46,7 @@ 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 FMLHS13 = "fml:handshake";
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[] 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};
@ -58,6 +66,36 @@ public class Forge extends BasicListener {
buf.readBytes(REGISTER13); buf.readBytes(REGISTER13);
} }
@EventHandler
public void onServerConnected(LoginEvent event){
//Wir senden Packet ID 1
//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.registerIntent(BungeeCore.get());
InitialHandler handler = (InitialHandler) event.getConnection();
Field ch;
ChannelWrapper wrapper = null;
try{
ch = handler.getClass().getDeclaredField("ch");
ch.setAccessible(true);
wrapper = (ChannelWrapper) ch.get(handler);
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
wrapper.getHandle().pipeline().get(HandlerBoss.class).setHandler(new CustomPacketHandler(event, wrapper));
}
@EventHandler
public void onServerPing(ProxyPingEvent event) {
event.setResponse(new FMLPing(event.getResponse()));
}
@EventHandler @EventHandler
public void onPostLogin(PostLoginEvent event) { public void onPostLogin(PostLoginEvent event) {
ProxiedPlayer player = event.getPlayer(); ProxiedPlayer player = event.getPlayer();