Dieser Commit ist enthalten in:
Ursprung
ef71323b05
Commit
a1d8ec806f
@ -96,6 +96,7 @@ dependencies {
|
|||||||
|
|
||||||
compileOnly 'com.velocitypowered:velocity-api:3.3.0-SNAPSHOT'
|
compileOnly 'com.velocitypowered:velocity-api:3.3.0-SNAPSHOT'
|
||||||
annotationProcessor 'com.velocitypowered:velocity-api:3.3.0-SNAPSHOT'
|
annotationProcessor 'com.velocitypowered:velocity-api:3.3.0-SNAPSHOT'
|
||||||
|
// TODO: Add velocity-proxy as a compileOnly dependency to steamwar-maven
|
||||||
//compileOnly 'com.velocitypowered:velocity-proxy:3.3.0-SNAPSHOT'
|
//compileOnly 'com.velocitypowered:velocity-proxy:3.3.0-SNAPSHOT'
|
||||||
|
|
||||||
//implementation 'org.reflections:reflections:0.10.2'
|
//implementation 'org.reflections:reflections:0.10.2'
|
||||||
@ -105,6 +106,7 @@ dependencies {
|
|||||||
|
|
||||||
implementation 'org.yaml:snakeyaml:2.2'
|
implementation 'org.yaml:snakeyaml:2.2'
|
||||||
|
|
||||||
|
// TODO: Monorepo?
|
||||||
compileOnly files('persistentvelocitycore.jar')
|
compileOnly files('persistentvelocitycore.jar')
|
||||||
implementation("net.dv8tion:JDA:4.4.0_352") {
|
implementation("net.dv8tion:JDA:4.4.0_352") {
|
||||||
exclude module: 'opus-java'
|
exclude module: 'opus-java'
|
||||||
|
@ -19,27 +19,25 @@
|
|||||||
|
|
||||||
package de.steamwar.bungeecore.listeners;
|
package de.steamwar.bungeecore.listeners;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
import com.lunarclient.apollo.ApolloManager;
|
import com.lunarclient.apollo.ApolloManager;
|
||||||
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
|
import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
||||||
|
import com.velocitypowered.api.network.ProtocolVersion;
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
import com.velocitypowered.api.proxy.ServerConnection;
|
||||||
|
import com.velocitypowered.api.proxy.messages.ChannelMessageSource;
|
||||||
|
import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier;
|
||||||
|
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
||||||
import de.steamwar.bungeecore.VelocityCore;
|
import de.steamwar.bungeecore.VelocityCore;
|
||||||
import de.steamwar.messages.Message;
|
|
||||||
import de.steamwar.bungeecore.commands.TeamCommand;
|
import de.steamwar.bungeecore.commands.TeamCommand;
|
||||||
import de.steamwar.bungeecore.mods.*;
|
import de.steamwar.bungeecore.mods.*;
|
||||||
import de.steamwar.bungeecore.network.ServerMetaInfo;
|
import de.steamwar.bungeecore.network.ServerMetaInfo;
|
||||||
import de.steamwar.messages.Chatter;
|
|
||||||
import de.steamwar.network.packets.NetworkPacket;
|
import de.steamwar.network.packets.NetworkPacket;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ByteBufAllocator;
|
import io.netty.buffer.ByteBufAllocator;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import net.md_5.bungee.api.ChatMessageType;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
import net.md_5.bungee.api.connection.Connection;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.api.connection.Server;
|
|
||||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
|
||||||
import net.md_5.bungee.connection.InitialHandler;
|
|
||||||
import net.md_5.bungee.event.EventHandler;
|
|
||||||
import net.md_5.bungee.protocol.DefinedPacket;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
@ -48,16 +46,21 @@ import java.util.*;
|
|||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class PluginMessage extends BasicListener {
|
public class PluginMessage {
|
||||||
|
|
||||||
public static void send(ProxiedPlayer player, String legacyChannel, String channel, byte[] data) {
|
private final Lunar lunar;
|
||||||
|
private final LabyMod labyMod;
|
||||||
|
private final WorldDownloader wdl;
|
||||||
|
private final FabricModSender fms;
|
||||||
|
private final FML flm;
|
||||||
|
|
||||||
|
public static void send(Player player, String legacyChannel, String channel, byte[] data) {
|
||||||
// 1.12 format change
|
// 1.12 format change
|
||||||
send(player, player.getPendingConnection().getVersion() > 340 ? channel : legacyChannel, data);
|
send(player, player.getProtocolVersion().getProtocol() > 340 ? channel : legacyChannel, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void send(ProxiedPlayer player, String channel, byte[] data) {
|
public static void send(Player player, String channel, byte[] data) {
|
||||||
if(((InitialHandler)player.getPendingConnection()).getRegisteredChannels().contains(channel))
|
player.sendPluginMessage(MinecraftChannelIdentifier.from(channel), data);
|
||||||
player.sendData(channel, data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] genBufPacket(Consumer<ByteBuf> generator) {
|
public static byte[] genBufPacket(Consumer<ByteBuf> generator) {
|
||||||
@ -86,20 +89,25 @@ public class PluginMessage extends BasicListener {
|
|||||||
void accept(DataOutputStream out) throws IOException;
|
void accept(DataOutputStream out) throws IOException;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Parser UNKNOWN = event -> VelocityCore.getLogger().log(Level.WARNING, () -> "Undefined PluginMessage on channel " + event.getTag() + " from " + event.getSender() + " received.\n" + new String(event.getData()) + "\n" + Arrays.toString(event.getData()));
|
private static final Parser UNKNOWN = event -> {
|
||||||
private static final Parser PASS_THROUGH = event -> event.setCancelled(false);
|
VelocityCore.get().getLogger().log(Level.WARNING, () -> "Undefined PluginMessage on channel " + event.getIdentifier().getId() + " from " + (event.getSource() instanceof Player pl ? pl.getUsername() : event.getSource().toString()) + " received.\n" + new String(event.getData()) + "\n" + Arrays.toString(event.getData()));
|
||||||
private static final Parser DROP = event -> {};
|
event.setResult(PluginMessageEvent.ForwardResult.handled());
|
||||||
|
};
|
||||||
private final Lunar lunar = new Lunar();
|
private static final Parser PASS_THROUGH = event -> event.setResult(PluginMessageEvent.ForwardResult.forward());
|
||||||
|
private static final Parser DROP = event -> event.setResult(PluginMessageEvent.ForwardResult.handled());
|
||||||
|
|
||||||
private final Set<String> knownBrands = new HashSet<>();
|
private final Set<String> knownBrands = new HashSet<>();
|
||||||
private final Map<String, Consumer<ProxiedPlayer>> channelRegisterHandlers = new HashMap<>();
|
private final Map<String, Consumer<Player>> channelRegisterHandlers = new HashMap<>();
|
||||||
private final Map<String, Parser> handlers = new HashMap<>();
|
private final Map<String, Parser> handlers = new HashMap<>();
|
||||||
|
|
||||||
public PluginMessage() {
|
public PluginMessage() {
|
||||||
//TODO interface generalisation
|
ModUtils utils = new ModUtils();
|
||||||
LabyMod labyMod = new LabyMod();
|
|
||||||
WorldDownloader wdl = new WorldDownloader();
|
this.lunar = new Lunar(utils);
|
||||||
|
this.labyMod = new LabyMod(utils);
|
||||||
|
this.wdl = new WorldDownloader();
|
||||||
|
this.fms = new FabricModSender(utils);
|
||||||
|
this.flm = new FML(utils);
|
||||||
|
|
||||||
knownBrands.addAll(Arrays.asList("vanilla", "fabric", "quilt", "forge", "optifine", "Geyser", "labymod", "Feather Fabric"));
|
knownBrands.addAll(Arrays.asList("vanilla", "fabric", "quilt", "forge", "optifine", "Geyser", "labymod", "Feather Fabric"));
|
||||||
|
|
||||||
@ -107,7 +115,7 @@ public class PluginMessage extends BasicListener {
|
|||||||
"fabric:container/open", "fabric:registry/sync/direct", "fabric:registry/sync",
|
"fabric:container/open", "fabric:registry/sync/direct", "fabric:registry/sync",
|
||||||
"fabric-screen-handler-api-v1:open_screen",
|
"fabric-screen-handler-api-v1:open_screen",
|
||||||
|
|
||||||
FML.CHANNEL, "fml:loginwrapper", "fml:handshake", "fml:play", "forge:tier_sorting", "forge:split",
|
FML.CHANNEL.getId(), "fml:loginwrapper", "fml:handshake", "fml:play", "forge:tier_sorting", "forge:split",
|
||||||
"forge:login", "forge:handshake",
|
"forge:login", "forge:handshake",
|
||||||
|
|
||||||
"labymod3:main", "labymod:neo",
|
"labymod3:main", "labymod:neo",
|
||||||
@ -145,16 +153,18 @@ public class PluginMessage extends BasicListener {
|
|||||||
"noxesium-v1:reset", "noxesium-v1:change_server_rules", "noxesium-v1:server_info",
|
"noxesium-v1:reset", "noxesium-v1:change_server_rules", "noxesium-v1:server_info",
|
||||||
"noxesium-v1:mcc_server", "noxesium-v1:mcc_game_state", "noxesium-v1:reset_server_rules",
|
"noxesium-v1:mcc_server", "noxesium-v1:mcc_game_state", "noxesium-v1:reset_server_rules",
|
||||||
"noxesium-v1:stop_sound", "noxesium-v1:start_sound", "noxesium-v1:modify_sound"
|
"noxesium-v1:stop_sound", "noxesium-v1:start_sound", "noxesium-v1:modify_sound"
|
||||||
))
|
)) {
|
||||||
channelRegisterHandlers.put(channel, player -> {});
|
channelRegisterHandlers.put(channel, player -> {
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
channelRegisterHandlers.put(ApolloManager.PLUGIN_MESSAGE_CHANNEL, lunar::sendRestrictions);
|
channelRegisterHandlers.put(ApolloManager.PLUGIN_MESSAGE_CHANNEL, lunar::sendRestrictions);
|
||||||
channelRegisterHandlers.put(Feather.CHANNEL, new Feather()::sendRestrictions);
|
channelRegisterHandlers.put(Feather.CHANNEL.getId(), new Feather()::sendRestrictions);
|
||||||
channelRegisterHandlers.put("xaerominimap:main", player -> player.sendMessage(ChatMessageType.SYSTEM, new TextComponent("§n§o§m§i§n§i§m§a§p"))); //https://www.curseforge.com/minecraft/mc-mods/xaeros-minimap
|
channelRegisterHandlers.put("xaerominimap:main", player -> player.sendMessage(Component.text("§n§o§m§i§n§i§m§a§p"))); //https://www.curseforge.com/minecraft/mc-mods/xaeros-minimap
|
||||||
channelRegisterHandlers.put("litemoretica:init_easy_place", player -> player.disconnect(Chatter.of(player).parse(false, new Message("MOD_YELLOW_SING", "litematica")))); //https://github.com/Earthcomputer/litemoretica/tree/master
|
channelRegisterHandlers.put("litemoretica:init_easy_place", player -> player.disconnect(ChatSender.of(player).parseToComponent(false, new Message("MOD_YELLOW_SING", "litematica")))); //https://github.com/Earthcomputer/litemoretica/tree/master
|
||||||
channelRegisterHandlers.put("voxelmap:settings", player -> player.disconnect(Chatter.of(player).parse(false, new Message("MOD_YELLOW_SING", "voxelmap")))); //https://modrinth.com/mod/voxelmap-updated undocumented
|
channelRegisterHandlers.put("voxelmap:settings", player -> player.disconnect(ChatSender.of(player).parseToComponent(false, new Message("MOD_YELLOW_SING", "voxelmap")))); //https://modrinth.com/mod/voxelmap-updated undocumented
|
||||||
channelRegisterHandlers.put("worldinfo:world_id", player -> player.disconnect(Chatter.of(player).parse(false, new Message("MOD_YELLOW_SING", "minimap")))); // JourneyMap and VoxelMap
|
channelRegisterHandlers.put("worldinfo:world_id", player -> player.disconnect(ChatSender.of(player).parseToComponent(false, new Message("MOD_YELLOW_SING", "minimap")))); // JourneyMap and VoxelMap
|
||||||
channelRegisterHandlers.put(Controlify.CHANNEL, new Controlify()::onRegister);
|
channelRegisterHandlers.put(Controlify.CHANNEL.getId(), new Controlify()::onRegister);
|
||||||
|
|
||||||
registerBiDirPassthrough("worldedit:cui");
|
registerBiDirPassthrough("worldedit:cui");
|
||||||
|
|
||||||
@ -194,9 +204,9 @@ public class PluginMessage extends BasicListener {
|
|||||||
register("minecraft:brand", false, directional(this::steamWarBrand, this::userBrand));
|
register("minecraft:brand", false, directional(this::steamWarBrand, this::userBrand));
|
||||||
|
|
||||||
//Needs to be registered cause paper refuses to send PluginMessages on unregistered channels...
|
//Needs to be registered cause paper refuses to send PluginMessages on unregistered channels...
|
||||||
register("sw:bridge", true, directional(onlySWSource(async(event -> NetworkPacket.handle(new ServerMetaInfo(((Server) event.getSender()).getInfo()), event.getData()))), UNKNOWN));
|
register("sw:bridge", true, directional(onlySWSource(async(event -> NetworkPacket.handle(new ServerMetaInfo(((ServerConnection) event.getSource()).getServer()), event.getData()))), UNKNOWN));
|
||||||
register("sw:hotkeys", false, directional(UNKNOWN, PASS_THROUGH));
|
register("sw:hotkeys", false, directional(UNKNOWN, PASS_THROUGH));
|
||||||
register("fabricmodsender:mods", true, directional(UNKNOWN, async(new FabricModSender()::handlePluginMessage)));
|
register("fabricmodsender:mods", true, directional(UNKNOWN, async(fms::handlePluginMessage)));
|
||||||
|
|
||||||
register("WDL|INIT", true, directional(UNKNOWN, wdl::handlePluginMessage));
|
register("WDL|INIT", true, directional(UNKNOWN, wdl::handlePluginMessage));
|
||||||
register("wdl:init", true, directional(UNKNOWN, wdl::handlePluginMessage));
|
register("wdl:init", true, directional(UNKNOWN, wdl::handlePluginMessage));
|
||||||
@ -205,7 +215,7 @@ public class PluginMessage extends BasicListener {
|
|||||||
register("LMC", true, directional(UNKNOWN, async(labyMod::handlePluginMessage)));
|
register("LMC", true, directional(UNKNOWN, async(labyMod::handlePluginMessage)));
|
||||||
register("labymod3:main", true, directional(UNKNOWN, async(labyMod::handlePluginMessage)));
|
register("labymod3:main", true, directional(UNKNOWN, async(labyMod::handlePluginMessage)));
|
||||||
register("labymod:neo", false, directional(UNKNOWN, DROP)); //undocumented, JSON format "0" byte, packetlängen byte, {"version":"4.1.25"}
|
register("labymod:neo", false, directional(UNKNOWN, DROP)); //undocumented, JSON format "0" byte, packetlängen byte, {"version":"4.1.25"}
|
||||||
register(FML.CHANNEL, true, directional(UNKNOWN, async(new FML()::handlePluginMessage)));
|
register(FML.CHANNEL.getId(), true, directional(UNKNOWN, async(flm::handlePluginMessage)));
|
||||||
|
|
||||||
//vanilla does not register any channels (sends only one minecraft:brand vanilla, nothing else (potential spoofed client detection))
|
//vanilla does not register any channels (sends only one minecraft:brand vanilla, nothing else (potential spoofed client detection))
|
||||||
//Forge interestingly registers all channels the server registers
|
//Forge interestingly registers all channels the server registers
|
||||||
@ -214,12 +224,12 @@ public class PluginMessage extends BasicListener {
|
|||||||
// Hackclientlike modsuppressor for labymod: https://github.com/Neocraftr/LabyMod-NeoEssentials (Potentially recognizable from NO Addons/NO Mods?) https://github.com/Neocraftr/LabyMod-NeoEssentials/blob/master/src/main/java/de/neocraftr/neoessentials/utils/BytecodeMethods.java
|
// Hackclientlike modsuppressor for labymod: https://github.com/Neocraftr/LabyMod-NeoEssentials (Potentially recognizable from NO Addons/NO Mods?) https://github.com/Neocraftr/LabyMod-NeoEssentials/blob/master/src/main/java/de/neocraftr/neoessentials/utils/BytecodeMethods.java
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@Subscribe
|
||||||
public void onPluginMessage(PluginMessageEvent event) {
|
public void onPluginMessage(PluginMessageEvent event) {
|
||||||
event.setCancelled(true);
|
event.setResult(PluginMessageEvent.ForwardResult.handled());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
handlers.getOrDefault(event.getTag(), UNKNOWN).handle(event);
|
handlers.getOrDefault(event.getIdentifier().getId(), UNKNOWN).handle(event);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new SecurityException("PluginMessage handling exception: " + event + "\n" + Arrays.toString(event.getData()), e);
|
throw new SecurityException("PluginMessage handling exception: " + event + "\n" + Arrays.toString(event.getData()), e);
|
||||||
}
|
}
|
||||||
@ -247,34 +257,34 @@ public class PluginMessage extends BasicListener {
|
|||||||
private void register(String channel, boolean clientSideRegister, Parser handler) {
|
private void register(String channel, boolean clientSideRegister, Parser handler) {
|
||||||
handlers.put(channel, handler);
|
handlers.put(channel, handler);
|
||||||
if(clientSideRegister)
|
if(clientSideRegister)
|
||||||
ProxyServer.getInstance().registerChannel(channel);
|
VelocityCore.get().getProxyServer().getChannelRegistrar().register(MinecraftChannelIdentifier.from(channel));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clientRegistersChannel(PluginMessageEvent event) {
|
private void clientRegistersChannel(PluginMessageEvent event) {
|
||||||
ProxiedPlayer player = (ProxiedPlayer) event.getSender();
|
Player player = (Player) event.getSource();
|
||||||
|
|
||||||
for(String channel : new String(event.getData()).split("\0")) {
|
for(String channel : new String(event.getData()).split("\0")) {
|
||||||
channelRegisterHandlers.getOrDefault(channel, p -> VelocityCore.getLogger().log(Level.WARNING, () -> p.getName() + " registered unknown channel " + channel)).accept(player);
|
channelRegisterHandlers.getOrDefault(channel, p -> VelocityCore.get().getLogger().log(Level.WARNING, () -> p.getUsername() + " registered unknown channel " + channel)).accept(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
PASS_THROUGH.handle(event);
|
PASS_THROUGH.handle(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void serverRegistersChannel(PluginMessageEvent event) {
|
private void serverRegistersChannel(PluginMessageEvent event) {
|
||||||
ProxiedPlayer player = (ProxiedPlayer)event.getReceiver();
|
Player player = (Player) event.getTarget();
|
||||||
|
|
||||||
List<String> channels = new ArrayList<>(Arrays.asList(new String(event.getData()).split("\0")));
|
List<String> channels = new ArrayList<>(Arrays.asList(new String(event.getData()).split("\0")));
|
||||||
channels.removeIf(channel -> channel.equals("sw:bridge"));
|
channels.removeIf(channel -> channel.equals("sw:bridge"));
|
||||||
player.sendData((player).getPendingConnection().getVersion() > 340 ? "minecraft:register" : "REGISTER", String.join("\0", channels).getBytes());
|
player.sendPluginMessage((player).getProtocolVersion().greaterThan(ProtocolVersion.MINECRAFT_1_12_2) ? MinecraftChannelIdentifier.from("minecraft:register") : new LegacyChannelIdentifier("REGISTER"), String.join("\0", channels).getBytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void userBrand(PluginMessageEvent event) {
|
private void userBrand(PluginMessageEvent event) {
|
||||||
ProxiedPlayer player = (ProxiedPlayer) event.getSender();
|
Player player = (Player) event.getSource();
|
||||||
ByteBuf buf = Unpooled.wrappedBuffer(event.getData());
|
ByteBuf buf = Unpooled.wrappedBuffer(event.getData());
|
||||||
String brand = DefinedPacket.readString(buf);
|
String brand = ProtocolUtils.readString(buf);
|
||||||
boolean lunarclient = brand.startsWith("lunarclient:");
|
boolean lunarclient = brand.startsWith("lunarclient:");
|
||||||
|
|
||||||
VelocityCore.getLogger().log(knownBrands.contains(brand) || lunarclient ? Level.INFO : Level.WARNING, () -> player.getName() + " joins with brand: " + brand);
|
VelocityCore.get().getLogger().log(knownBrands.contains(brand) || lunarclient ? Level.INFO : Level.WARNING, () -> player.getUsername() + " joins with brand: " + brand);
|
||||||
if(lunarclient)
|
if(lunarclient)
|
||||||
lunar.sendRestrictions(player);
|
lunar.sendRestrictions(player);
|
||||||
|
|
||||||
@ -282,30 +292,29 @@ public class PluginMessage extends BasicListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void steamWarBrand(PluginMessageEvent event) {
|
private void steamWarBrand(PluginMessageEvent event) {
|
||||||
ProxiedPlayer player = (ProxiedPlayer) event.getReceiver();
|
Player player = (Player) event.getTarget();
|
||||||
String brandString = Chatter.of(player).parseToLegacy("STEAMWAR_BRAND", ProxyServer.getInstance().getName(), player.getServer().getInfo().getName(), new String(event.getData(), 1, event.getData().length - 1));
|
String brandString = ChatSender.of(player).parseToLegacy("STEAMWAR_BRAND", "Velocity", player.getCurrentServer().map(serverConnection -> serverConnection.getServerInfo().getName()).orElse(""), new String(event.getData(), 1, event.getData().length - 1));
|
||||||
|
|
||||||
ByteBuf brand = ByteBufAllocator.DEFAULT.heapBuffer();
|
ByteBuf brand = ByteBufAllocator.DEFAULT.heapBuffer();
|
||||||
DefinedPacket.writeString(brandString, brand);
|
ProtocolUtils.writeString(brand, brandString);
|
||||||
player.sendData(event.getTag(), DefinedPacket.toArray(brand));
|
player.sendPluginMessage(event.getIdentifier(), brand.array());
|
||||||
brand.release();
|
brand.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Parser directional(Parser fromServer, Parser fromPlayer) {
|
private Parser directional(Parser fromServer, Parser fromPlayer) {
|
||||||
return event -> {
|
return event -> {
|
||||||
if(event.getSender() instanceof ProxiedPlayer)
|
if(event.getSource() instanceof Player)
|
||||||
fromPlayer.handle(event);
|
fromPlayer.handle(event);
|
||||||
else
|
else
|
||||||
fromServer.handle(event);
|
fromServer.handle(event);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
private Parser onlySWSource(Parser parser) {
|
private Parser onlySWSource(Parser parser) {
|
||||||
return event -> {
|
return event -> {
|
||||||
Connection sender = event.getSender();
|
ChannelMessageSource sender = event.getSource();
|
||||||
if(TeamCommand.isLocalhost(sender instanceof ProxiedPlayer ? IPSanitizer.getTrueAddress(((ProxiedPlayer) sender).getPendingConnection()) : sender.getAddress().getAddress()))
|
if(TeamCommand.isLocalhost(sender instanceof Player player ? IPSanitizer.getTrueAddress((player)) : ((ServerConnection) sender).getServerInfo().getAddress().getAddress()))
|
||||||
parser.handle(event);
|
parser.handle(event);
|
||||||
else
|
else
|
||||||
UNKNOWN.handle(event);
|
UNKNOWN.handle(event);
|
||||||
@ -313,7 +322,7 @@ public class PluginMessage extends BasicListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Parser async(Parser parser) {
|
private Parser async(Parser parser) {
|
||||||
return event -> ProxyServer.getInstance().getScheduler().runAsync(VelocityCore.get(), () -> parser.handle(event));
|
return event -> VelocityCore.get().getProxyServer().getScheduler().buildTask(VelocityCore.get(), () -> parser.handle(event)).schedule();
|
||||||
}
|
}
|
||||||
|
|
||||||
private interface Parser {
|
private interface Parser {
|
||||||
|
@ -20,11 +20,11 @@
|
|||||||
package de.steamwar.bungeecore.mods;
|
package de.steamwar.bungeecore.mods;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import de.steamwar.bungeecore.listeners.BasicListener;
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
import net.md_5.bungee.api.event.PostLoginEvent;
|
import com.velocitypowered.api.event.connection.PostLoginEvent;
|
||||||
import net.md_5.bungee.event.EventHandler;
|
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
||||||
|
|
||||||
public class Badlion extends BasicListener {
|
public class Badlion {
|
||||||
// https://github.com/BadlionClient/BadlionClientModAPI
|
// https://github.com/BadlionClient/BadlionClientModAPI
|
||||||
|
|
||||||
private final byte[] packet;
|
private final byte[] packet;
|
||||||
@ -50,8 +50,8 @@ public class Badlion extends BasicListener {
|
|||||||
packet = json.toString().getBytes();
|
packet = json.toString().getBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@Subscribe
|
||||||
public void onPostLogin(PostLoginEvent event) {
|
public void onPostLogin(PostLoginEvent event) {
|
||||||
event.getPlayer().sendData("badlion:mods", packet);
|
event.getPlayer().sendPluginMessage(MinecraftChannelIdentifier.from("badlion:mods"), packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,16 +19,18 @@
|
|||||||
|
|
||||||
package de.steamwar.bungeecore.mods;
|
package de.steamwar.bungeecore.mods;
|
||||||
|
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
||||||
|
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
||||||
|
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||||
import de.steamwar.bungeecore.listeners.PluginMessage;
|
import de.steamwar.bungeecore.listeners.PluginMessage;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.protocol.DefinedPacket;
|
|
||||||
|
|
||||||
public class Controlify {
|
public class Controlify {
|
||||||
//https://modrinth.com/mod/controlify
|
//https://modrinth.com/mod/controlify
|
||||||
//https://github.com/isXander/Controlify/blob/1.20.x/dev/src/main/java/dev/isxander/controlify/server/ServerPolicyPacket.java
|
//https://github.com/isXander/Controlify/blob/1.20.x/dev/src/main/java/dev/isxander/controlify/server/ServerPolicyPacket.java
|
||||||
//https://github.com/isXander/Controlify/blob/1.20.x/dev/src/main/java/dev/isxander/controlify/server/ServerPolicies.java
|
//https://github.com/isXander/Controlify/blob/1.20.x/dev/src/main/java/dev/isxander/controlify/server/ServerPolicies.java
|
||||||
|
|
||||||
public static final String CHANNEL = "controlify:server_policy";
|
public static final ChannelIdentifier CHANNEL = MinecraftChannelIdentifier.from("controlify:server_policy");
|
||||||
|
|
||||||
private final byte[][] packets;
|
private final byte[][] packets;
|
||||||
public Controlify() {
|
public Controlify() {
|
||||||
@ -40,13 +42,13 @@ public class Controlify {
|
|||||||
|
|
||||||
private byte[] restrict(String name) {
|
private byte[] restrict(String name) {
|
||||||
return PluginMessage.genBufPacket(buf -> {
|
return PluginMessage.genBufPacket(buf -> {
|
||||||
DefinedPacket.writeString(name, buf);
|
ProtocolUtils.writeString(buf, name);
|
||||||
buf.writeBoolean(false);
|
buf.writeBoolean(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onRegister(ProxiedPlayer player) {
|
public void onRegister(Player player) {
|
||||||
for(byte[] packet : packets)
|
for(byte[] packet : packets)
|
||||||
player.sendData(CHANNEL, packet);
|
player.sendPluginMessage(CHANNEL, packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,32 +19,68 @@
|
|||||||
|
|
||||||
package de.steamwar.bungeecore.mods;
|
package de.steamwar.bungeecore.mods;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
|
import com.velocitypowered.api.event.connection.ConnectionHandshakeEvent;
|
||||||
|
import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
||||||
|
import com.velocitypowered.api.event.connection.PostLoginEvent;
|
||||||
|
import com.velocitypowered.api.proxy.LoginPhaseConnection;
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
|
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
||||||
|
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
||||||
|
import com.velocitypowered.proxy.connection.ConnectionType;
|
||||||
|
import com.velocitypowered.proxy.connection.ConnectionTypes;
|
||||||
|
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
||||||
|
import com.velocitypowered.proxy.connection.client.InitialInboundConnection;
|
||||||
|
import com.velocitypowered.proxy.connection.client.LoginInboundConnection;
|
||||||
|
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||||
|
import com.velocitypowered.proxy.protocol.packet.HandshakePacket;
|
||||||
import de.steamwar.bungeecore.VelocityCore;
|
import de.steamwar.bungeecore.VelocityCore;
|
||||||
import de.steamwar.bungeecore.listeners.BasicListener;
|
import de.steamwar.bungeecore.util.annotations.Create;
|
||||||
import de.steamwar.messages.Chatter;
|
|
||||||
import de.steamwar.sql.Mod;
|
import de.steamwar.sql.Mod;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import lombok.SneakyThrows;
|
||||||
import net.md_5.bungee.api.connection.PendingConnection;
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
|
||||||
import net.md_5.bungee.api.event.PostLoginEvent;
|
|
||||||
import net.md_5.bungee.connection.InitialHandler;
|
|
||||||
import net.md_5.bungee.event.EventHandler;
|
|
||||||
import net.md_5.bungee.protocol.DefinedPacket;
|
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class FML extends BasicListener {
|
@Create
|
||||||
|
public class FML {
|
||||||
// https://wiki.vg/Minecraft_Forge_Handshake#FML_protocol_.281.7_-_1.12.29
|
// https://wiki.vg/Minecraft_Forge_Handshake#FML_protocol_.281.7_-_1.12.29
|
||||||
|
|
||||||
public static boolean isFML(PendingConnection connection, String type) {
|
private static final Field delegateField;
|
||||||
return ((InitialHandler)connection).getExtraDataInHandshake().equals("\0" + type);
|
private static final Field handshakeField;
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
delegateField = LoginInboundConnection.class.getDeclaredField("delegate");
|
||||||
|
handshakeField = InitialInboundConnection.class.getDeclaredField("handshake");
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String CHANNEL = "FML|HS";
|
private final ModUtils utils;
|
||||||
|
private final ProxyServer proxyServer;
|
||||||
|
private final VelocityCore core;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public FML(ModUtils utils) {
|
||||||
|
this.utils = utils;
|
||||||
|
this.proxyServer = VelocityCore.getProxy();
|
||||||
|
this.core = VelocityCore.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
public static boolean isFML(LoginPhaseConnection connection, String type) {
|
||||||
|
return handshakeField.get(delegateField.get(connection)) instanceof HandshakePacket packet && packet.getServerAddress().endsWith("\0" + type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final ChannelIdentifier CHANNEL = MinecraftChannelIdentifier.from("FML|HS");
|
||||||
private final byte[] helloPacket = new byte[]{
|
private final byte[] helloPacket = new byte[]{
|
||||||
/* Packet type: ServerHello */ 0,
|
/* Packet type: ServerHello */ 0,
|
||||||
/* FML protocol version */ 2,
|
/* FML protocol version */ 2,
|
||||||
@ -53,9 +89,9 @@ public class FML extends BasicListener {
|
|||||||
|
|
||||||
private static final Set<UUID> unlocked = new HashSet<>();
|
private static final Set<UUID> unlocked = new HashSet<>();
|
||||||
|
|
||||||
@EventHandler
|
@Subscribe
|
||||||
public void onPostLogin(PostLoginEvent event) {
|
public void onPostLogin(PostLoginEvent event) {
|
||||||
ProxiedPlayer player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
synchronized (unlocked) {
|
synchronized (unlocked) {
|
||||||
if(unlocked.contains(player.getUniqueId())){
|
if(unlocked.contains(player.getUniqueId())){
|
||||||
@ -64,35 +100,36 @@ public class FML extends BasicListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isFML(player.getPendingConnection(), "FML\0"))
|
if(((ConnectedPlayer) event.getPlayer()).getConnection().getType() == ConnectionTypes.LEGACY_FORGE) {
|
||||||
player.sendData(CHANNEL, helloPacket);
|
player.sendPluginMessage(CHANNEL, helloPacket);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handlePluginMessage(PluginMessageEvent event) {
|
public void handlePluginMessage(PluginMessageEvent event) {
|
||||||
ProxiedPlayer p = (ProxiedPlayer) event.getSender();
|
Player p = (Player) event.getSource();
|
||||||
ByteBuf buf = Unpooled.wrappedBuffer(event.getData());
|
ByteBuf buf = Unpooled.wrappedBuffer(event.getData());
|
||||||
|
|
||||||
if (buf.readByte() == /* ModList */ 2) {
|
if (buf.readByte() == /* ModList */ 2) {
|
||||||
int numMods = DefinedPacket.readVarInt(buf);
|
int numMods = ProtocolUtils.readVarInt(buf);
|
||||||
|
|
||||||
List<Mod> mods = new ArrayList<>();
|
List<Mod> mods = new ArrayList<>();
|
||||||
for(int i = 0; i < numMods; i++) {
|
for(int i = 0; i < numMods; i++) {
|
||||||
String name = DefinedPacket.readString(buf);
|
String name = ProtocolUtils.readString(buf);
|
||||||
DefinedPacket.readString(buf); // version
|
ProtocolUtils.readString(buf); // version
|
||||||
|
|
||||||
mods.add(Mod.getOrCreate(name, Mod.Platform.FORGE));
|
mods.add(Mod.getOrCreate(name, Mod.Platform.FORGE));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ModUtils.handleMods(p, mods)) {
|
if (utils.handleMods(p, mods)) {
|
||||||
synchronized (unlocked) {
|
synchronized (unlocked) {
|
||||||
unlocked.add(p.getUniqueId());
|
unlocked.add(p.getUniqueId());
|
||||||
}
|
}
|
||||||
Chatter.disconnect(p).system("MODS_CHECKED");
|
p.disconnect(LegacyComponentSerializer.legacySection().deserialize("§7Deine installierten Mods wurden überprüft\n§aDu kannst nun §eSteam§8War §abetreten"));
|
||||||
ProxyServer.getInstance().getScheduler().schedule(VelocityCore.get(), () -> {
|
proxyServer.getScheduler().buildTask(core, () -> {
|
||||||
synchronized (unlocked) {
|
synchronized (unlocked) {
|
||||||
unlocked.remove(p.getUniqueId());
|
unlocked.remove(p.getUniqueId());
|
||||||
}
|
}
|
||||||
}, 30, TimeUnit.SECONDS);
|
}).delay(30, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,29 +19,29 @@
|
|||||||
|
|
||||||
package de.steamwar.bungeecore.mods;
|
package de.steamwar.bungeecore.mods;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
|
import com.velocitypowered.api.event.connection.PreLoginEvent;
|
||||||
|
import com.velocitypowered.api.proxy.LoginPhaseConnection;
|
||||||
|
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
||||||
|
import com.velocitypowered.proxy.connection.client.LoginInboundConnection;
|
||||||
|
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||||
|
import com.velocitypowered.proxy.protocol.StateRegistry;
|
||||||
import de.steamwar.bungeecore.VelocityCore;
|
import de.steamwar.bungeecore.VelocityCore;
|
||||||
import de.steamwar.bungeecore.listeners.BasicListener;
|
|
||||||
import de.steamwar.bungeecore.listeners.IPSanitizer;
|
import de.steamwar.bungeecore.listeners.IPSanitizer;
|
||||||
import de.steamwar.bungeecore.listeners.PluginMessage;
|
import de.steamwar.bungeecore.listeners.PluginMessage;
|
||||||
|
import de.steamwar.bungeecore.util.annotations.Create;
|
||||||
import de.steamwar.sql.Mod;
|
import de.steamwar.sql.Mod;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
import net.md_5.bungee.api.connection.PendingConnection;
|
|
||||||
import net.md_5.bungee.api.event.LoginEvent;
|
|
||||||
import net.md_5.bungee.event.EventHandler;
|
|
||||||
import net.md_5.bungee.netty.HandlerBoss;
|
|
||||||
import net.md_5.bungee.netty.PacketHandler;
|
|
||||||
import net.md_5.bungee.protocol.DefinedPacket;
|
|
||||||
import net.md_5.bungee.protocol.packet.LoginPayloadRequest;
|
|
||||||
import net.md_5.bungee.protocol.packet.LoginPayloadResponse;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class FML2 extends BasicListener {
|
public class FML2 {
|
||||||
|
|
||||||
|
protected final ModUtils modUtils;
|
||||||
// FML2: https://wiki.vg/Minecraft_Forge_Handshake#FML2_protocol_.281.13_-_Current.29
|
// FML2: https://wiki.vg/Minecraft_Forge_Handshake#FML2_protocol_.281.13_-_Current.29
|
||||||
// FML3: https://github.com/adde0109/Ambassador/tree/non-api/src/main/java/org/adde0109/ambassador/forge
|
// FML3: https://github.com/adde0109/Ambassador/tree/non-api/src/main/java/org/adde0109/ambassador/forge
|
||||||
|
|
||||||
@ -54,24 +54,25 @@ public class FML2 extends BasicListener {
|
|||||||
private final byte[] forgeModListPacket;
|
private final byte[] forgeModListPacket;
|
||||||
|
|
||||||
public FML2() {
|
public FML2() {
|
||||||
|
this.modUtils = modUtils;
|
||||||
fml2ModListPacket = generateModListPacket(false);
|
fml2ModListPacket = generateModListPacket(false);
|
||||||
fml3ModListPacket = generateModListPacket(true);
|
fml3ModListPacket = generateModListPacket(true);
|
||||||
forgeModListPacket = PluginMessage.genBufPacket(buf -> {
|
forgeModListPacket = PluginMessage.genBufPacket(buf -> {
|
||||||
buf.writeByte(0); // Login wrapper packet
|
buf.writeByte(0); // Login wrapper packet
|
||||||
DefinedPacket.writeString("forge:handshake", buf);
|
ProtocolUtils.writeString(buf, "forge:handshake");
|
||||||
|
|
||||||
ByteBuf packet = Unpooled.buffer();
|
ByteBuf packet = Unpooled.buffer();
|
||||||
packet.writeByte(1); // Mod list packet
|
packet.writeByte(1); // Mod list packet
|
||||||
DefinedPacket.writeVarInt(0, packet); // Mod amount
|
ProtocolUtils.writeVarInt(packet, 0); // Mod amount
|
||||||
|
|
||||||
DefinedPacket.writeVarInt(packet.readableBytes(), buf);
|
ProtocolUtils.writeVarInt(buf, packet.readableBytes());
|
||||||
buf.writeBytes(packet);
|
buf.writeBytes(packet);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@Subscribe
|
||||||
public void onLogin(LoginEvent event) {
|
public void onLogin(PreLoginEvent event) {
|
||||||
PendingConnection connection = event.getConnection();
|
LoginInboundConnection connection = (LoginInboundConnection) event.getConnection();
|
||||||
|
|
||||||
boolean fml2 = FML.isFML(connection, "FML2\0");
|
boolean fml2 = FML.isFML(connection, "FML2\0");
|
||||||
boolean fml3 = FML.isFML(connection, "FML3\0");
|
boolean fml3 = FML.isFML(connection, "FML3\0");
|
||||||
@ -79,45 +80,49 @@ public class FML2 extends BasicListener {
|
|||||||
if(!fml2 && !fml3 && !forge)
|
if(!fml2 && !fml3 && !forge)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
IPSanitizer.getChannelWrapper(connection).getHandle().pipeline().get(HandlerBoss.class).setHandler(new FML2LoginHandler(event));
|
FML2LoginHandler handler = new FML2LoginHandler(connection, event.getUniqueId(), forge);
|
||||||
|
|
||||||
event.registerIntent(VelocityCore.get());
|
if(forge) {
|
||||||
if(forge)
|
((LoginInboundConnection) event.getConnection()).sendLoginPluginMessage(MinecraftChannelIdentifier.from("forge:login"), forgeModListPacket, handler);
|
||||||
connection.unsafe().sendPacket(new LoginPayloadRequest(1, "forge:login", forgeModListPacket));
|
} else {
|
||||||
else
|
((LoginInboundConnection) event.getConnection()).sendLoginPluginMessage(MinecraftChannelIdentifier.from("fml:loginwrapper"), fml3 ? fml3ModListPacket : fml2ModListPacket, handler);
|
||||||
connection.unsafe().sendPacket(new LoginPayloadRequest(1, "fml:loginwrapper", fml3 ? fml3ModListPacket : fml2ModListPacket));
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] generateModListPacket(boolean fml3) {
|
private byte[] generateModListPacket(boolean fml3) {
|
||||||
return PluginMessage.genBufPacket(buf -> {
|
return PluginMessage.genBufPacket(buf -> {
|
||||||
DefinedPacket.writeString("fml:handshake", buf);
|
ProtocolUtils.writeString(buf, "fml:handshake");
|
||||||
|
|
||||||
ByteBuf packet = Unpooled.buffer();
|
ByteBuf packet = Unpooled.buffer();
|
||||||
packet.writeByte(1); // Mod list packet
|
packet.writeByte(1); // Mod list packet
|
||||||
DefinedPacket.writeVarInt(0, packet); // Mod amount
|
ProtocolUtils.writeVarInt(packet, 0); // Mod amount
|
||||||
|
|
||||||
if(fml3) {
|
if(fml3) {
|
||||||
DefinedPacket.writeVarInt(1, packet); // Channel amount
|
ProtocolUtils.writeVarInt(packet,1); // Channel amount
|
||||||
DefinedPacket.writeString("forge:tier_sorting", packet);
|
ProtocolUtils.writeString(packet, "forge:tier_sorting");
|
||||||
DefinedPacket.writeString("1.0", packet);
|
ProtocolUtils.writeString(packet, "1.0");
|
||||||
} else {
|
} else {
|
||||||
DefinedPacket.writeVarInt(0, packet); // Channel amount
|
ProtocolUtils.writeVarInt(packet, 0); // Channel amount
|
||||||
}
|
}
|
||||||
|
|
||||||
DefinedPacket.writeVarInt(0, packet); // Registries amount
|
ProtocolUtils.writeVarInt(packet, 0); // Registries amount
|
||||||
if(fml3)
|
if(fml3)
|
||||||
DefinedPacket.writeVarInt(0, packet); // DataPacks amount
|
ProtocolUtils.writeVarInt(packet, 0); // DataPacks amount
|
||||||
|
|
||||||
DefinedPacket.writeVarInt(packet.readableBytes(), buf);
|
ProtocolUtils.writeVarInt(buf, packet.readableBytes());
|
||||||
buf.writeBytes(packet);
|
buf.writeBytes(packet);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class FML2LoginHandler extends PacketHandler {
|
private class FML2LoginHandler implements LoginPhaseConnection.MessageConsumer {
|
||||||
private final LoginEvent event;
|
private final LoginInboundConnection connection;
|
||||||
|
private final UUID uuid;
|
||||||
|
private final boolean forge;
|
||||||
|
|
||||||
public FML2LoginHandler(LoginEvent event) {
|
private FML2LoginHandler(LoginInboundConnection connection, UUID uuid, boolean forge) {
|
||||||
this.event = event;
|
this.connection = connection;
|
||||||
|
this.uuid = uuid;
|
||||||
|
this.forge = forge;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -125,59 +130,52 @@ public class FML2 extends BasicListener {
|
|||||||
return "SteamWar Forge Handler";
|
return "SteamWar Forge Handler";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void abort(byte[] response, String error) {
|
||||||
|
|
||||||
|
VelocityCore.get().getLogger().log(Level.SEVERE, () -> error + "\n" + Base64.getEncoder().encodeToString(response));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(LoginPayloadResponse response) {
|
public void onMessageResponse(byte @Nullable [] data) {
|
||||||
boolean forge = FML.isFML(event.getConnection(), "FORGE");
|
|
||||||
byte[] data = response.getData();
|
|
||||||
if(data == null) {
|
if(data == null) {
|
||||||
abort(response, "Not FML2/3 client");
|
abort(null, "Not FML2/3 client");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuf buf = Unpooled.wrappedBuffer(data);
|
ByteBuf buf = Unpooled.wrappedBuffer(data);
|
||||||
if(forge && buf.readByte() != 0) {
|
if(forge && buf.readByte() != 0) {
|
||||||
abort(response, "Not FORGE login wrapper");
|
abort(data, "Not FORGE login wrapper");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!DefinedPacket.readString(buf).equals(forge ? "forge:handshake" : "fml:handshake")) {
|
if(!ProtocolUtils.readString(buf).equals(forge ? "forge:handshake" : "fml:handshake")) {
|
||||||
abort(response, "Not FML2/3/FORGE handshake response");
|
abort(data, "Not FML2/3/FORGE handshake response");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(DefinedPacket.readVarInt(buf) != buf.readableBytes()) {
|
if(ProtocolUtils.readVarInt(buf) != buf.readableBytes()) {
|
||||||
abort(response, "FML2/3/FORGE packet size mismatch");
|
abort(data, "FML2/3/FORGE packet size mismatch");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(DefinedPacket.readVarInt(buf) != (forge ? /* Mod Versions */ 1 : /* Mod List Reply */ 2)) {
|
if(ProtocolUtils.readVarInt(buf) != (forge ? /* Mod Versions */ 1 : /* Mod List Reply */ 2)) {
|
||||||
abort(response, "Not FML2/3/FORGE mod list reply");
|
abort(data, "Not FML2/3/FORGE mod list reply");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Mod> mods = new ArrayList<>();
|
List<Mod> mods = new ArrayList<>();
|
||||||
|
|
||||||
int modCount = DefinedPacket.readVarInt(buf);
|
int modCount = ProtocolUtils.readVarInt(buf);
|
||||||
for(int i = 0; i < modCount; i++) {
|
for(int i = 0; i < modCount; i++) {
|
||||||
mods.add(Mod.getOrCreate(DefinedPacket.readString(buf), Mod.Platform.FORGE));
|
mods.add(Mod.getOrCreate(ProtocolUtils.readString(buf), Mod.Platform.FORGE));
|
||||||
|
|
||||||
if(forge) {
|
if(forge) {
|
||||||
DefinedPacket.readString(buf); // Human readable name
|
ProtocolUtils.readString(buf); // Human readable name
|
||||||
DefinedPacket.readString(buf); // Version
|
ProtocolUtils.readString(buf); // Version
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!ModUtils.handleMods(event.getConnection().getUniqueId(), Locale.getDefault(), event::setReason, mods))
|
modUtils.handleMods(uuid, Locale.getDefault(), connection::disconnect, mods);
|
||||||
event.setCancelled(true);
|
|
||||||
|
|
||||||
event.completeIntent(VelocityCore.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void abort(LoginPayloadResponse response, String error) {
|
|
||||||
event.setReason(TextComponent.fromLegacy(error));
|
|
||||||
event.setCancelled(true);
|
|
||||||
event.completeIntent(VelocityCore.get());
|
|
||||||
VelocityCore.getLogger().log(Level.SEVERE, () -> error + "\n" + response);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,31 +22,40 @@ package de.steamwar.bungeecore.mods;
|
|||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
|
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
||||||
|
import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
||||||
|
import com.velocitypowered.api.event.player.ServerConnectedEvent;
|
||||||
|
import com.velocitypowered.api.event.player.ServerPostConnectEvent;
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
|
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||||
import de.steamwar.bungeecore.VelocityCore;
|
import de.steamwar.bungeecore.VelocityCore;
|
||||||
import de.steamwar.bungeecore.Storage;
|
import de.steamwar.bungeecore.Storage;
|
||||||
import de.steamwar.bungeecore.listeners.BasicListener;
|
import de.steamwar.bungeecore.util.annotations.Create;
|
||||||
import de.steamwar.sql.Mod;
|
import de.steamwar.sql.Mod;
|
||||||
import de.steamwar.sql.SWException;
|
import de.steamwar.sql.SWException;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import net.md_5.bungee.BungeeCord;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
|
||||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
|
||||||
import net.md_5.bungee.api.event.ServerSwitchEvent;
|
|
||||||
import net.md_5.bungee.event.EventHandler;
|
|
||||||
import net.md_5.bungee.protocol.DefinedPacket;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class FabricModSender extends BasicListener {
|
@Create
|
||||||
|
public class FabricModSender {
|
||||||
|
|
||||||
|
private final ModUtils utils;
|
||||||
|
private final ProxyServer proxyServer;
|
||||||
|
|
||||||
private final Set<String> neededFabricMods = new HashSet<>();
|
private final Set<String> neededFabricMods = new HashSet<>();
|
||||||
private final Set<String> neededQuiltMods = new HashSet<>();
|
private final Set<String> neededQuiltMods = new HashSet<>();
|
||||||
|
|
||||||
public FabricModSender() {
|
@Inject
|
||||||
|
public FabricModSender(ModUtils utils) {
|
||||||
|
this.utils = utils;
|
||||||
|
this.proxyServer = VelocityCore.getProxy();
|
||||||
neededFabricMods.add("java");
|
neededFabricMods.add("java");
|
||||||
neededFabricMods.add("minecraft");
|
neededFabricMods.add("minecraft");
|
||||||
neededFabricMods.add("steamwarmodsender");
|
neededFabricMods.add("steamwarmodsender");
|
||||||
@ -55,9 +64,9 @@ public class FabricModSender extends BasicListener {
|
|||||||
neededFabricMods.add("fabricloader");
|
neededFabricMods.add("fabricloader");
|
||||||
neededQuiltMods.add("quilt_loader");
|
neededQuiltMods.add("quilt_loader");
|
||||||
|
|
||||||
BungeeCord.getInstance().getScheduler().schedule(VelocityCore.get(), () -> {
|
proxyServer.getScheduler().buildTask(VelocityCore.get(), () -> {
|
||||||
synchronized (Storage.fabricExpectPluginMessage) {
|
synchronized (Storage.fabricExpectPluginMessage) {
|
||||||
for (Map.Entry<ProxiedPlayer, Long> entry : Storage.fabricExpectPluginMessage.entrySet()) {
|
for (Map.Entry<Player, Long> entry : Storage.fabricExpectPluginMessage.entrySet()) {
|
||||||
if (!Storage.fabricCheckedPlayers.containsKey(entry.getKey())) {
|
if (!Storage.fabricCheckedPlayers.containsKey(entry.getKey())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -67,11 +76,11 @@ public class FabricModSender extends BasicListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 0, 1, TimeUnit.SECONDS);
|
}).repeat(1, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handlePluginMessage(PluginMessageEvent e){
|
public void handlePluginMessage(PluginMessageEvent e){
|
||||||
ProxiedPlayer player = (ProxiedPlayer) e.getSender();
|
Player player = (Player) e.getSource();
|
||||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
||||||
|
|
||||||
if (!Storage.fabricCheckedPlayers.containsKey(player)) {
|
if (!Storage.fabricCheckedPlayers.containsKey(player)) {
|
||||||
@ -87,7 +96,7 @@ public class FabricModSender extends BasicListener {
|
|||||||
List<Mod> mods = new ArrayList<>();
|
List<Mod> mods = new ArrayList<>();
|
||||||
|
|
||||||
ByteBuf buf = Unpooled.wrappedBuffer(e.getData());
|
ByteBuf buf = Unpooled.wrappedBuffer(e.getData());
|
||||||
String data = DefinedPacket.readString(buf, 1024*1024);
|
String data = ProtocolUtils.readString(buf, 1024*1024);
|
||||||
if(buf.readableBytes() > 0) {
|
if(buf.readableBytes() > 0) {
|
||||||
logMessage(user, "Invalid message length", Arrays.toString(e.getData()));
|
logMessage(user, "Invalid message length", Arrays.toString(e.getData()));
|
||||||
return;
|
return;
|
||||||
@ -104,7 +113,7 @@ public class FabricModSender extends BasicListener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!ModUtils.handleMods(player,mods))
|
if(!utils.handleMods(player,mods))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!Storage.fabricCheckedPlayers.containsKey(player)) {
|
if (!Storage.fabricCheckedPlayers.containsKey(player)) {
|
||||||
@ -114,17 +123,17 @@ public class FabricModSender extends BasicListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@Subscribe
|
||||||
public void onServerSwitchEvent(ServerSwitchEvent e) {
|
public void onServerSwitchEvent(ServerConnectedEvent e) {
|
||||||
if (e.getFrom() == null) return;
|
if (e.getPreviousServer().isEmpty()) return;
|
||||||
synchronized (Storage.fabricExpectPluginMessage) {
|
synchronized (Storage.fabricExpectPluginMessage) {
|
||||||
Storage.fabricExpectPluginMessage.put(e.getPlayer(), System.currentTimeMillis());
|
Storage.fabricExpectPluginMessage.put(e.getPlayer(), System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@Subscribe
|
||||||
public void onDisconnect(PlayerDisconnectEvent e) {
|
public void onDisconnect(DisconnectEvent e) {
|
||||||
ProxiedPlayer player = e.getPlayer();
|
Player player = e.getPlayer();
|
||||||
|
|
||||||
Storage.fabricCheckedPlayers.remove(player);
|
Storage.fabricCheckedPlayers.remove(player);
|
||||||
synchronized (Storage.fabricExpectPluginMessage) {
|
synchronized (Storage.fabricExpectPluginMessage) {
|
||||||
|
@ -21,12 +21,14 @@ package de.steamwar.bungeecore.mods;
|
|||||||
|
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
||||||
|
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
||||||
|
|
||||||
public class Feather {
|
public class Feather {
|
||||||
//https://github.com/Koupah/Feather-Client-API/blob/main/src/club/koupah/feather/packets/FeatherMod.java
|
//https://github.com/Koupah/Feather-Client-API/blob/main/src/club/koupah/feather/packets/FeatherMod.java
|
||||||
//https://archive.org/details/feather-server-api
|
//https://archive.org/details/feather-server-api
|
||||||
public static final String CHANNEL = "feather:client";
|
public static final ChannelIdentifier CHANNEL = MinecraftChannelIdentifier.from("feather:client");
|
||||||
|
|
||||||
private final byte[] packet;
|
private final byte[] packet;
|
||||||
public Feather() {
|
public Feather() {
|
||||||
@ -50,7 +52,7 @@ public class Feather {
|
|||||||
packet = obj.toString().getBytes();
|
packet = obj.toString().getBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendRestrictions(ProxiedPlayer player) {
|
public void sendRestrictions(Player player) {
|
||||||
player.sendData(CHANNEL, packet);
|
player.sendPluginMessage(CHANNEL, packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,20 +19,19 @@
|
|||||||
|
|
||||||
package de.steamwar.bungeecore.mods;
|
package de.steamwar.bungeecore.mods;
|
||||||
|
|
||||||
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
|
import com.velocitypowered.api.event.proxy.ProxyPingEvent;
|
||||||
import de.steamwar.bungeecore.VelocityCore;
|
import de.steamwar.bungeecore.VelocityCore;
|
||||||
import de.steamwar.bungeecore.listeners.BasicListener;
|
import de.steamwar.bungeecore.util.annotations.Create;
|
||||||
import net.md_5.bungee.api.event.PlayerHandshakeEvent;
|
|
||||||
import net.md_5.bungee.connection.InitialHandler;
|
|
||||||
import net.md_5.bungee.event.EventHandler;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class Hostname extends BasicListener {
|
@Create
|
||||||
|
public class Hostname {
|
||||||
|
|
||||||
private final Set<String> knownHostnames = new HashSet<>();
|
private final Set<String> knownHostnames = new HashSet<>();
|
||||||
private final Set<String> knownExtraData = new HashSet<>();
|
|
||||||
|
|
||||||
public Hostname() {
|
public Hostname() {
|
||||||
knownHostnames.add("steamwar.de");
|
knownHostnames.add("steamwar.de");
|
||||||
@ -45,22 +44,13 @@ public class Hostname extends BasicListener {
|
|||||||
knownHostnames.add("wtf.mynx.lol"); //https://discord.com/invite/serverseeker
|
knownHostnames.add("wtf.mynx.lol"); //https://discord.com/invite/serverseeker
|
||||||
knownHostnames.add("masscan");
|
knownHostnames.add("masscan");
|
||||||
knownHostnames.add("aaa");
|
knownHostnames.add("aaa");
|
||||||
|
|
||||||
knownExtraData.add("");
|
|
||||||
knownExtraData.add("\0FML\0");
|
|
||||||
knownExtraData.add("\0FML2\0");
|
|
||||||
knownExtraData.add("\0FML3\0");
|
|
||||||
knownExtraData.add("\0FORGE");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@Subscribe
|
||||||
public void onHandshake(PlayerHandshakeEvent event) {
|
public void onHandshake(ProxyPingEvent event) {
|
||||||
String hostname = event.getHandshake().getHost().toLowerCase();
|
String hostname = event.getConnection().getVirtualHost().map(inetSocketAddress -> inetSocketAddress.getHostName()).orElse("");
|
||||||
String extraDataInHandshake = ((InitialHandler) event.getConnection()).getExtraDataInHandshake();
|
|
||||||
if (!knownHostnames.contains(hostname) && !hostname.endsWith(".steamwar.de")) {
|
if (!knownHostnames.contains(hostname) && !hostname.endsWith(".steamwar.de")) {
|
||||||
VelocityCore.getLogger().log(Level.WARNING, () -> event.getConnection().getSocketAddress() + " connected with unknown hostname " + event.getHandshake() + " " + extraDataInHandshake);
|
VelocityCore.get().getLogger().log(Level.WARNING, () -> event.getConnection().getRemoteAddress().toString() + " connected with unknown hostname '" + hostname + "'");
|
||||||
} else if (!knownExtraData.contains(extraDataInHandshake)) {
|
|
||||||
VelocityCore.getLogger().log(Level.WARNING, () -> event.getConnection().getSocketAddress() + " connected with unknown extra data " + event.getHandshake() + " " + extraDataInHandshake);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,48 +22,53 @@ package de.steamwar.bungeecore.mods;
|
|||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
|
import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||||
import de.steamwar.bungeecore.VelocityCore;
|
import de.steamwar.bungeecore.VelocityCore;
|
||||||
import de.steamwar.bungeecore.listeners.PluginMessage;
|
import de.steamwar.bungeecore.listeners.PluginMessage;
|
||||||
|
import de.steamwar.bungeecore.util.annotations.Create;
|
||||||
import de.steamwar.sql.Mod;
|
import de.steamwar.sql.Mod;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
|
||||||
import net.md_5.bungee.protocol.DefinedPacket;
|
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
@Create
|
||||||
public class LabyMod {
|
public class LabyMod {
|
||||||
// https://docs.labymod.net/pages/server/introduction/
|
// https://docs.labymod.net/pages/server/introduction/
|
||||||
// https://github.com/LabyMod/labymod-server-api
|
// https://github.com/LabyMod/labymod-server-api
|
||||||
// https://dl.labymod.net/addons.json
|
// https://dl.labymod.net/addons.json
|
||||||
|
|
||||||
|
private final ModUtils utils;
|
||||||
|
|
||||||
private final byte[] gameInfoPacket;
|
private final byte[] gameInfoPacket;
|
||||||
public LabyMod() {
|
public LabyMod(ModUtils utils) {
|
||||||
|
this.utils = utils;
|
||||||
gameInfoPacket = PluginMessage.genBufPacket(buf -> {
|
gameInfoPacket = PluginMessage.genBufPacket(buf -> {
|
||||||
DefinedPacket.writeString("discord_rpc", buf);
|
ProtocolUtils.writeString(buf, "discord_rpc");
|
||||||
|
|
||||||
JsonObject json = new JsonObject();
|
JsonObject json = new JsonObject();
|
||||||
json.addProperty("hasGame", true);
|
json.addProperty("hasGame", true);
|
||||||
json.addProperty("game_mode", "steamwar.de");
|
json.addProperty("game_mode", "steamwar.de");
|
||||||
json.addProperty("game_startTime", 0);
|
json.addProperty("game_startTime", 0);
|
||||||
json.addProperty("game_endTime", 0);
|
json.addProperty("game_endTime", 0);
|
||||||
DefinedPacket.writeString(json.toString(), buf);
|
ProtocolUtils.writeString(buf, json.toString());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handlePluginMessage(PluginMessageEvent event) {
|
public void handlePluginMessage(PluginMessageEvent event) {
|
||||||
ProxiedPlayer player = (ProxiedPlayer) event.getSender();
|
Player player = (Player) event.getSource();
|
||||||
player.sendData(event.getTag(), gameInfoPacket);
|
player.sendPluginMessage(event.getIdentifier(), gameInfoPacket);
|
||||||
|
|
||||||
ByteBuf buf = Unpooled.wrappedBuffer(event.getData());
|
ByteBuf buf = Unpooled.wrappedBuffer(event.getData());
|
||||||
String purpose = DefinedPacket.readString(buf);
|
String purpose = ProtocolUtils.readString(buf);
|
||||||
if(!"INFO".equals(purpose))
|
if(!"INFO".equals(purpose))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
JsonObject message = JsonParser.parseString(DefinedPacket.readString(buf)).getAsJsonObject();
|
JsonObject message = JsonParser.parseString(ProtocolUtils.readString(buf)).getAsJsonObject();
|
||||||
List<Mod> mods = new LinkedList<>();
|
List<Mod> mods = new LinkedList<>();
|
||||||
|
|
||||||
if(message.has("addons")) {
|
if(message.has("addons")) {
|
||||||
@ -74,7 +79,7 @@ public class LabyMod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(message.has("mods")) {
|
if(message.has("mods")) {
|
||||||
VelocityCore.getLogger().log(Level.WARNING, () -> "LabyMod External Mods for debugging: " + message.getAsJsonArray("mods"));
|
VelocityCore.get().getLogger().log(Level.WARNING, () -> "LabyMod External Mods for debugging: " + message.getAsJsonArray("mods"));
|
||||||
for(JsonElement element : message.getAsJsonArray("mods")) {
|
for(JsonElement element : message.getAsJsonArray("mods")) {
|
||||||
JsonObject addon = element.getAsJsonObject();
|
JsonObject addon = element.getAsJsonObject();
|
||||||
//TODO observe: FORGE and FABRIC mods available, do they always and with .jar? (would equal new mod platform)
|
//TODO observe: FORGE and FABRIC mods available, do they always and with .jar? (would equal new mod platform)
|
||||||
@ -82,6 +87,6 @@ public class LabyMod {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ModUtils.handleMods(player, mods);
|
utils.handleMods(player, mods);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,11 +32,14 @@ import com.lunarclient.apollo.option.Options;
|
|||||||
import com.lunarclient.apollo.player.AbstractApolloPlayer;
|
import com.lunarclient.apollo.player.AbstractApolloPlayer;
|
||||||
import com.lunarclient.apollo.player.v1.ModMessage;
|
import com.lunarclient.apollo.player.v1.ModMessage;
|
||||||
import com.lunarclient.apollo.player.v1.PlayerHandshakeMessage;
|
import com.lunarclient.apollo.player.v1.PlayerHandshakeMessage;
|
||||||
|
import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
||||||
|
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
||||||
import de.steamwar.bungeecore.VelocityCore;
|
import de.steamwar.bungeecore.VelocityCore;
|
||||||
|
import de.steamwar.bungeecore.util.annotations.Create;
|
||||||
import de.steamwar.sql.Mod;
|
import de.steamwar.sql.Mod;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -44,13 +47,16 @@ import java.util.UUID;
|
|||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
@Create
|
||||||
public class Lunar {
|
public class Lunar {
|
||||||
// https://lunarclient.dev/apollo/introduction
|
// https://lunarclient.dev/apollo/introduction
|
||||||
// https://github.com/LunarClient/Apollo
|
// https://github.com/LunarClient/Apollo
|
||||||
|
|
||||||
private final ApolloModuleManager manager = new ApolloModuleManagerImpl().addModule(ModSettingModule.class);
|
private final ApolloModuleManager manager = new ApolloModuleManagerImpl().addModule(ModSettingModule.class);
|
||||||
|
|
||||||
public Lunar() { //TODO seems defunct
|
private final ModUtils utils;
|
||||||
|
|
||||||
|
public Lunar(ModUtils utils) { //TODO seems defunct
|
||||||
Options modSettings = manager.getModule(ModSettingModule.class).getOptions();
|
Options modSettings = manager.getModule(ModSettingModule.class).getOptions();
|
||||||
modSettings.set(ModReplaymod.ENABLED, false); // TODO check if restrictions working
|
modSettings.set(ModReplaymod.ENABLED, false); // TODO check if restrictions working
|
||||||
modSettings.set(ModFreelook.ENABLED, false);
|
modSettings.set(ModFreelook.ENABLED, false);
|
||||||
@ -60,14 +66,16 @@ public class Lunar {
|
|||||||
modSettings.set(ModTeamView.ENABLED, false);
|
modSettings.set(ModTeamView.ENABLED, false);
|
||||||
modSettings.set(ModTntCountdown.ENABLED, false);
|
modSettings.set(ModTntCountdown.ENABLED, false);
|
||||||
modSettings.set(ModToggleSneak.TOGGLE_SNEAK_CONTAINER, false);
|
modSettings.set(ModToggleSneak.TOGGLE_SNEAK_CONTAINER, false);
|
||||||
|
|
||||||
|
this.utils = utils;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendRestrictions(ProxiedPlayer player) {
|
public void sendRestrictions(Player player) {
|
||||||
NetworkOptions.sendOptions(manager.getModules(), true, new SWApolloPlayer(player));
|
NetworkOptions.sendOptions(manager.getModules(), true, new SWApolloPlayer(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handlePluginMessage(PluginMessageEvent event) {
|
public void handlePluginMessage(PluginMessageEvent event) {
|
||||||
ProxiedPlayer player = (ProxiedPlayer) event.getSender();
|
Player player = (Player) event.getSource();
|
||||||
Any packet;
|
Any packet;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -94,12 +102,12 @@ public class Lunar {
|
|||||||
case TYPE_UNSPECIFIED:
|
case TYPE_UNSPECIFIED:
|
||||||
case UNRECOGNIZED:
|
case UNRECOGNIZED:
|
||||||
default:
|
default:
|
||||||
VelocityCore.getLogger().log(Level.INFO, () -> player.getName() + " uses Lunar mod with unknown type " + mod);
|
VelocityCore.get().getLogger().log(Level.INFO, () -> player.getUsername() + " uses Lunar mod with unknown type " + mod);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ModUtils.handleMods(player, mods);
|
utils.handleMods(player, mods);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +120,9 @@ public class Lunar {
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
private static class SWApolloPlayer extends AbstractApolloPlayer {
|
private static class SWApolloPlayer extends AbstractApolloPlayer {
|
||||||
|
|
||||||
private final ProxiedPlayer player;
|
private static final ChannelIdentifier CHANNEL = MinecraftChannelIdentifier.from(ApolloManager.PLUGIN_MESSAGE_CHANNEL);
|
||||||
|
|
||||||
|
private final Player player;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendPacket(Message message) {
|
public void sendPacket(Message message) {
|
||||||
@ -121,11 +131,11 @@ public class Lunar {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendPacket(byte[] bytes) {
|
public void sendPacket(byte[] bytes) {
|
||||||
player.sendData(ApolloManager.PLUGIN_MESSAGE_CHANNEL, bytes);
|
player.sendPluginMessage(CHANNEL, bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public UUID getUniqueId() { return player.getUniqueId(); }
|
@Override public UUID getUniqueId() { return player.getUniqueId(); }
|
||||||
@Override public String getName() { return player.getName(); }
|
@Override public String getName() { return player.getUsername(); }
|
||||||
@Override public boolean hasPermission(String s) { return player.hasPermission(s); }
|
@Override public boolean hasPermission(String s) { return player.hasPermission(s); }
|
||||||
@Override public Object getPlayer() { return player; }
|
@Override public Object getPlayer() { return player; }
|
||||||
}
|
}
|
||||||
|
@ -19,18 +19,17 @@
|
|||||||
|
|
||||||
package de.steamwar.bungeecore.mods;
|
package de.steamwar.bungeecore.mods;
|
||||||
|
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import de.steamwar.bungeecore.VelocityCore;
|
import de.steamwar.bungeecore.VelocityCore;
|
||||||
import de.steamwar.bungeecore.commands.PunishmentCommand;
|
import de.steamwar.bungeecore.commands.PunishmentCommand;
|
||||||
import de.steamwar.messages.Chatter;
|
import de.steamwar.messages.Message;
|
||||||
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import de.steamwar.sql.Mod;
|
import de.steamwar.sql.Mod;
|
||||||
import de.steamwar.sql.Mod.ModType;
|
import de.steamwar.sql.Mod.ModType;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import de.steamwar.sql.UserPerm;
|
import de.steamwar.sql.UserPerm;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.experimental.UtilityClass;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
@ -38,23 +37,27 @@ import java.time.temporal.ChronoUnit;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@UtilityClass
|
|
||||||
public class ModUtils {
|
public class ModUtils {
|
||||||
|
private final Logger logger;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private static final Map<UUID,List<Mod>> playerModMap = new HashMap<>();
|
private final Map<UUID,List<Mod>> playerModMap = new HashMap<>();
|
||||||
|
|
||||||
public static boolean handleMods(ProxiedPlayer player, List<Mod> mods) {
|
public ModUtils() {
|
||||||
return handleMods(player.getUniqueId(), Chatter.of(player).getLocale(), player::disconnect, mods);
|
this.logger = VelocityCore.getLogger();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean handleMods(UUID uuid, Locale locale, Consumer<BaseComponent> disconnect, List<Mod> mods){
|
public boolean handleMods(Player player, List<Mod> mods) {
|
||||||
Chatter sender = Chatter.of(uuid);
|
return handleMods(player.getUniqueId(), ChatSender.of(player).getLocale(), player::disconnect, mods);
|
||||||
SteamwarUser user = sender.user();
|
}
|
||||||
|
|
||||||
|
public boolean handleMods(UUID uuid, Locale locale, Consumer<Component> disconnect, List<Mod> mods){
|
||||||
|
SteamwarUser user = SteamwarUser.get(uuid);
|
||||||
playerModMap.put(uuid,new ArrayList<>(mods));
|
playerModMap.put(uuid,new ArrayList<>(mods));
|
||||||
VelocityCore.getLogger().log(Level.INFO, user.getUserName() + " declares mods: " + mods.stream().map(mod -> mod.getPlatform() + ":" + mod.getModName()).collect(Collectors.joining(" ")));
|
VelocityCore.get().getLogger().log(Level.INFO, user.getUserName() + " declares mods: " + mods.stream().map(mod -> mod.getPlatform() + ":" + mod.getModName()).collect(Collectors.joining(" ")));
|
||||||
|
|
||||||
ModType max = ModType.YELLOW;
|
ModType max = ModType.YELLOW;
|
||||||
Iterator<Mod> it = mods.iterator();
|
Iterator<Mod> it = mods.iterator();
|
||||||
@ -76,17 +79,17 @@ public class ModUtils {
|
|||||||
String message;
|
String message;
|
||||||
|
|
||||||
if(mods.size() == 1) {
|
if(mods.size() == 1) {
|
||||||
message = sender.parseToLegacy(max == ModType.RED ? "MOD_RED_SING" : "MOD_YELLOW_SING", locale, modList);
|
message = Message.parse(max == ModType.RED ? "MOD_RED_SING" : "MOD_YELLOW_SING", locale, modList);
|
||||||
} else {
|
} else {
|
||||||
message = sender.parseToLegacy(max == ModType.RED ? "MOD_RED_PLUR" : "MOD_YELLOW_PLUR", locale, modList);
|
message = Message.parse(max == ModType.RED ? "MOD_RED_PLUR" : "MOD_YELLOW_PLUR", locale, modList);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(max == ModType.RED) {
|
if(max == ModType.RED) {
|
||||||
PunishmentCommand.ban(user, Timestamp.from(Instant.now().plus(7, ChronoUnit.DAYS)), message, SteamwarUser.get(-1), false);
|
PunishmentCommand.ban(user, Timestamp.from(Instant.now().plus(7, ChronoUnit.DAYS)), message, SteamwarUser.get(-1), false);
|
||||||
VelocityCore.getLogger().log(Level.SEVERE, user.getUserName() + " " + user.getId() + " wurde automatisch wegen der Mods " + modList + " gebannt.");
|
logger.log(Level.SEVERE, user.getUserName() + " " + user.getId() + " wurde automatisch wegen der Mods " + modList + " gebannt.");
|
||||||
}
|
}
|
||||||
|
|
||||||
disconnect.accept(TextComponent.fromLegacy(message));
|
disconnect.accept(LegacyComponentSerializer.legacySection().deserialize(message));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ public class ReplayMod extends BasicListener {
|
|||||||
public void onPlayerJoin(ServerSwitchEvent event) {
|
public void onPlayerJoin(ServerSwitchEvent event) {
|
||||||
ProxiedPlayer player = event.getPlayer();
|
ProxiedPlayer player = event.getPlayer();
|
||||||
ServerInfo server = player.getServer().getInfo();
|
ServerInfo server = player.getServer().getInfo();
|
||||||
if(ProxyServer.getInstance().getServerInfo(VelocityCore.get().getConfig().getLobbyserver()) == server)
|
if(ProxyServer.getInstance().getServerInfo(VelocityCore.LOBBY_SERVER) == server)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Subserver subserver = Subserver.getSubserver(server);
|
Subserver subserver = Subserver.getSubserver(server);
|
||||||
|
@ -19,9 +19,10 @@
|
|||||||
|
|
||||||
package de.steamwar.bungeecore.mods;
|
package de.steamwar.bungeecore.mods;
|
||||||
|
|
||||||
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
|
import com.velocitypowered.api.event.connection.PostLoginEvent;
|
||||||
|
import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier;
|
||||||
import de.steamwar.bungeecore.listeners.BasicListener;
|
import de.steamwar.bungeecore.listeners.BasicListener;
|
||||||
import net.md_5.bungee.api.event.PostLoginEvent;
|
|
||||||
import net.md_5.bungee.event.EventHandler;
|
|
||||||
|
|
||||||
public class Schematica extends BasicListener {
|
public class Schematica extends BasicListener {
|
||||||
// https://github.com/Lunatrius/SchematicaPlugin/blob/master/src/main/java/com/github/lunatrius/schematica/plugin/SchematicaPlugin.java
|
// https://github.com/Lunatrius/SchematicaPlugin/blob/master/src/main/java/com/github/lunatrius/schematica/plugin/SchematicaPlugin.java
|
||||||
@ -33,8 +34,8 @@ public class Schematica extends BasicListener {
|
|||||||
/* PERM_LOAD */ 1
|
/* PERM_LOAD */ 1
|
||||||
};
|
};
|
||||||
|
|
||||||
@EventHandler
|
@Subscribe
|
||||||
public void onPostLogin(PostLoginEvent event) {
|
public void onPostLogin(PostLoginEvent event) {
|
||||||
event.getPlayer().sendData("schematica", packet);
|
event.getPlayer().sendPluginMessage(new LegacyChannelIdentifier("schematica"), packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,32 +20,51 @@
|
|||||||
package de.steamwar.bungeecore.mods;
|
package de.steamwar.bungeecore.mods;
|
||||||
|
|
||||||
import com.google.gson.*;
|
import com.google.gson.*;
|
||||||
import de.steamwar.bungeecore.listeners.BasicListener;
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
import net.md_5.bungee.BungeeCord;
|
import com.velocitypowered.api.proxy.server.ServerPing;
|
||||||
import net.md_5.bungee.api.ServerPing;
|
import de.steamwar.bungeecore.VelocityCore;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
public class ServerListPing extends BasicListener implements JsonSerializer<ServerPing>, JsonDeserializer<ServerPing> {
|
public class ServerListPing {
|
||||||
// https://github.com/Aizistral-Studios/No-Chat-Reports/discussions/206
|
// https://github.com/Aizistral-Studios/No-Chat-Reports/discussions/206
|
||||||
// https://github.com/Aizistral-Studios/No-Chat-Reports/wiki/How-to-Get-Safe-Server-Status
|
// https://github.com/Aizistral-Studios/No-Chat-Reports/wiki/How-to-Get-Safe-Server-Status
|
||||||
|
|
||||||
private final Gson gson;
|
@SuppressWarnings("unused")
|
||||||
|
private final ProxyServer proxyServer;
|
||||||
|
|
||||||
|
private static final String[] FIELDS_TO_OVERRIDE = new String[] {
|
||||||
|
"PRE_1_16_PING_SERIALIZER",
|
||||||
|
"PRE_1_20_3_PING_SERIALIZER",
|
||||||
|
"MODERN_PING_SERIALIZER"
|
||||||
|
};
|
||||||
|
|
||||||
public ServerListPing() {
|
public ServerListPing() {
|
||||||
BungeeCord bungeeCord = BungeeCord.getInstance();
|
this.proxyServer = VelocityCore.getProxy();
|
||||||
gson = bungeeCord.gson;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Field gsonField = BungeeCord.class.getDeclaredField("gson");
|
for (String fieldName : FIELDS_TO_OVERRIDE) {
|
||||||
gsonField.setAccessible(true);
|
Field field = proxyServer.getClass().getDeclaredField(fieldName);
|
||||||
gsonField.set(bungeeCord, gson.newBuilder().registerTypeAdapter(ServerPing.class, this).create());
|
field.setAccessible(true);
|
||||||
|
Object obj = field.get(null);
|
||||||
|
if (obj instanceof Gson gsonOld) {
|
||||||
|
Gson gsonNew = new GsonBuilder()
|
||||||
|
.registerTypeAdapter(ServerPing.class, new ServerListPingSerializer(gsonOld))
|
||||||
|
.create();
|
||||||
|
field.set(null, gsonNew);
|
||||||
|
} else {
|
||||||
|
throw new SecurityException("Failed to inject ServerListPing in " + fieldName);
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
|
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
|
||||||
throw new SecurityException("Failed to inject ServerListPing", e);
|
throw new SecurityException("Failed to inject ServerListPing", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private record ServerListPingSerializer(
|
||||||
|
Gson gson) implements JsonSerializer<ServerPing>, JsonDeserializer<ServerPing> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JsonElement serialize(ServerPing ping, Type type, JsonSerializationContext context) {
|
public JsonElement serialize(ServerPing ping, Type type, JsonSerializationContext context) {
|
||||||
JsonElement element = gson.toJsonTree(ping, type);
|
JsonElement element = gson.toJsonTree(ping, type);
|
||||||
@ -61,3 +80,4 @@ public class ServerListPing extends BasicListener implements JsonSerializer<Serv
|
|||||||
return gson.fromJson(element, ServerPing.class);
|
return gson.fromJson(element, ServerPing.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -19,9 +19,9 @@
|
|||||||
|
|
||||||
package de.steamwar.bungeecore.mods;
|
package de.steamwar.bungeecore.mods;
|
||||||
|
|
||||||
|
import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import de.steamwar.bungeecore.listeners.PluginMessage;
|
import de.steamwar.bungeecore.listeners.PluginMessage;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
|
||||||
|
|
||||||
public class WorldDownloader {
|
public class WorldDownloader {
|
||||||
// https://wiki.vg/Plugin_channels/World_downloader
|
// https://wiki.vg/Plugin_channels/World_downloader
|
||||||
@ -43,6 +43,6 @@ public class WorldDownloader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void handlePluginMessage(PluginMessageEvent event) {
|
public void handlePluginMessage(PluginMessageEvent event) {
|
||||||
PluginMessage.send((ProxiedPlayer) event.getSender(), "WDL|CONTROL", "wdl:control", controlPacket);
|
PluginMessage.send((Player) event.getSource(), "WDL|CONTROL", "wdl:control", controlPacket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,13 +21,12 @@ package de.steamwar.bungeecore.network.handlers;
|
|||||||
|
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
|
import com.velocitypowered.api.proxy.server.ServerInfo;
|
||||||
import de.steamwar.bungeecore.network.NetworkSender;
|
import de.steamwar.bungeecore.network.NetworkSender;
|
||||||
import de.steamwar.bungeecore.network.ServerMetaInfo;
|
import de.steamwar.bungeecore.network.ServerMetaInfo;
|
||||||
import de.steamwar.bungeecore.tablist.TablistManager;
|
import de.steamwar.bungeecore.tablist.TablistManager;
|
||||||
import de.steamwar.network.packets.PacketHandler;
|
import de.steamwar.network.packets.PacketHandler;
|
||||||
import de.steamwar.network.packets.common.FightInfoPacket;
|
import de.steamwar.network.packets.common.FightInfoPacket;
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -47,16 +46,16 @@ public class FightInfoHandler extends PacketHandler {
|
|||||||
|
|
||||||
@Handler
|
@Handler
|
||||||
public void handle(FightInfoPacket packet) {
|
public void handle(FightInfoPacket packet) {
|
||||||
ServerInfo info = ((ServerMetaInfo) packet.getMetaInfos()).getSender();
|
RegisteredServer info = ((ServerMetaInfo) packet.getMetaInfos()).getSender().getServer();
|
||||||
|
|
||||||
FightInfoPacket lobbyPacket = packet.withServerName(info.getName());
|
FightInfoPacket lobbyPacket = packet.withServerName(info.getServerInfo().getName());
|
||||||
|
|
||||||
TablistManager.newFightInfo(info, packet);
|
TablistManager.newFightInfo(info, packet);
|
||||||
|
|
||||||
Iterator<ServerInfo> lobbyIt = lobbys.iterator();
|
Iterator<RegisteredServer> lobbyIt = lobbys.iterator();
|
||||||
while(lobbyIt.hasNext()) {
|
while(lobbyIt.hasNext()) {
|
||||||
ServerInfo lobby = lobbyIt.next();
|
RegisteredServer lobby = lobbyIt.next();
|
||||||
Iterator<ProxiedPlayer> it = lobby.getPlayers().iterator();
|
Iterator<Player> it = lobby.getPlayersConnected().iterator();
|
||||||
if(!it.hasNext()){
|
if(!it.hasNext()){
|
||||||
lobbyIt.remove();
|
lobbyIt.remove();
|
||||||
continue;
|
continue;
|
||||||
|
@ -19,40 +19,32 @@
|
|||||||
|
|
||||||
package de.steamwar.bungeecore.tablist;
|
package de.steamwar.bungeecore.tablist;
|
||||||
|
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
import de.steamwar.bungeecore.VelocityCore;
|
import de.steamwar.bungeecore.VelocityCore;
|
||||||
import de.steamwar.bungeecore.Servertype;
|
|
||||||
import de.steamwar.bungeecore.Storage;
|
|
||||||
import de.steamwar.bungeecore.Subserver;
|
|
||||||
import de.steamwar.bungeecore.listeners.BasicListener;
|
import de.steamwar.bungeecore.listeners.BasicListener;
|
||||||
import de.steamwar.network.packets.common.FightInfoPacket;
|
import de.steamwar.network.packets.common.FightInfoPacket;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
|
||||||
import net.md_5.bungee.api.event.PostLoginEvent;
|
|
||||||
import net.md_5.bungee.api.event.ServerSwitchEvent;
|
|
||||||
import net.md_5.bungee.event.EventHandler;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class TablistManager extends BasicListener {
|
public class TablistManager extends BasicListener {
|
||||||
|
|
||||||
private static final Map<ServerInfo, FightInfoPacket> fightInfos = new HashMap<>();
|
private static final Map<RegisteredServer, FightInfoPacket> fightInfos = new HashMap<>();
|
||||||
|
|
||||||
public static synchronized void newFightInfo(ServerInfo info, FightInfoPacket packet) {
|
public static synchronized void newFightInfo(RegisteredServer info, FightInfoPacket packet) {
|
||||||
fightInfos.put(info, packet);
|
fightInfos.put(info, packet);
|
||||||
fightInfos.keySet().removeIf(serverInfo -> serverInfo.getPlayers().isEmpty());
|
fightInfos.keySet().removeIf(serverInfo -> serverInfo.getPlayersConnected().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Map<ProxiedPlayer, Tablist> tablists = new HashMap<>();
|
private final Map<Player, Tablist> tablists = new HashMap<>();
|
||||||
|
|
||||||
private int seconds = 0;
|
private int seconds = 0;
|
||||||
|
|
||||||
public TablistManager() {
|
public TablistManager() {
|
||||||
ProxyServer.getInstance().getScheduler().schedule(VelocityCore.get(), this::updateTablist, 1, 1, TimeUnit.SECONDS);
|
VelocityCore.schedule(this::updateTablist).repeat(1, TimeUnit.SECONDS);
|
||||||
synchronized (tablists) {
|
synchronized (tablists) {
|
||||||
ProxyServer.getInstance().getPlayers().forEach(player -> tablists.put(player, new Tablist(player)));
|
VelocityCore.getProxy().getAllPlayers().forEach(player -> tablists.put(player, new Tablist(player)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren