From 446b4ad5195101c4ed9644849aba779e372501d2 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 7 Jun 2022 20:53:09 +0200 Subject: [PATCH 01/20] Bungee Network --- CommonCore | 2 +- src/de/steamwar/bungeecore/BungeeCore.java | 4 +- .../steamwar/bungeecore/SubserverSystem.java | 7 +- .../bungeecore/commands/BauCommand.java | 5 +- .../bungeecore/comms/BungeePacket.java | 47 ----- .../bungeecore/comms/PacketIdManager.java | 43 ---- .../bungeecore/comms/SpigotHandler.java | 28 --- .../bungeecore/comms/SpigotReceiver.java | 66 ------- .../comms/packets/BaumemberUpdatePacket.java | 36 ---- .../comms/packets/CloseInventoryPacket.java | 43 ---- .../comms/packets/FightEndsPacket.java | 80 -------- .../comms/packets/FightInfoPacket.java | 183 ------------------ .../comms/packets/InventoryPacket.java | 80 -------- .../packets/LocaleInvalidationPacket.java | 43 ---- .../bungeecore/comms/packets/PingPacket.java | 43 ---- .../comms/packets/StartingServerPacket.java | 25 --- .../bungeecore/inventory/SWInventory.java | 20 +- .../bungeecore/listeners/ChatListener.java | 5 +- .../bungeecore/listeners/TablistManager.java | 2 +- .../network/BungeeNetworkHandler.java | 16 ++ .../bungeecore/network/NetworkReceiver.java | 27 +++ .../bungeecore/network/NetworkSender.java | 22 +++ .../handlers/ExecuteCommandHandler.java | 18 +- .../handlers/FightEndsHandler.java | 16 +- .../handlers/FightInfoHandler.java | 22 ++- .../handlers/ImALobbyHandler.java | 16 +- .../handlers/InventoryCallbackHandler.java | 38 ++-- .../handlers/PrepareSchemHandler.java | 20 +- .../steamwar/bungeecore/sql/SteamwarUser.java | 5 +- 29 files changed, 158 insertions(+), 804 deletions(-) delete mode 100644 src/de/steamwar/bungeecore/comms/BungeePacket.java delete mode 100644 src/de/steamwar/bungeecore/comms/PacketIdManager.java delete mode 100644 src/de/steamwar/bungeecore/comms/SpigotHandler.java delete mode 100644 src/de/steamwar/bungeecore/comms/SpigotReceiver.java delete mode 100644 src/de/steamwar/bungeecore/comms/packets/BaumemberUpdatePacket.java delete mode 100644 src/de/steamwar/bungeecore/comms/packets/CloseInventoryPacket.java delete mode 100644 src/de/steamwar/bungeecore/comms/packets/FightEndsPacket.java delete mode 100644 src/de/steamwar/bungeecore/comms/packets/FightInfoPacket.java delete mode 100644 src/de/steamwar/bungeecore/comms/packets/InventoryPacket.java delete mode 100644 src/de/steamwar/bungeecore/comms/packets/LocaleInvalidationPacket.java delete mode 100644 src/de/steamwar/bungeecore/comms/packets/PingPacket.java delete mode 100644 src/de/steamwar/bungeecore/comms/packets/StartingServerPacket.java create mode 100644 src/de/steamwar/bungeecore/network/BungeeNetworkHandler.java create mode 100644 src/de/steamwar/bungeecore/network/NetworkReceiver.java create mode 100644 src/de/steamwar/bungeecore/network/NetworkSender.java rename src/de/steamwar/bungeecore/{comms => network}/handlers/ExecuteCommandHandler.java (70%) rename src/de/steamwar/bungeecore/{comms => network}/handlers/FightEndsHandler.java (93%) rename src/de/steamwar/bungeecore/{comms => network}/handlers/FightInfoHandler.java (75%) rename src/de/steamwar/bungeecore/{comms => network}/handlers/ImALobbyHandler.java (67%) rename src/de/steamwar/bungeecore/{comms => network}/handlers/InventoryCallbackHandler.java (65%) rename src/de/steamwar/bungeecore/{comms => network}/handlers/PrepareSchemHandler.java (74%) diff --git a/CommonCore b/CommonCore index 919c4d5..492894c 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit 919c4d525ea39756b24bd961bb72d8d58bdd5bd4 +Subproject commit 492894ca8d41ee0bde4dcb9d520db5f7478c50c7 diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index e15cfc4..40b8399 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -22,9 +22,9 @@ package de.steamwar.bungeecore; import de.steamwar.bungeecore.bot.SteamwarDiscordBot; import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; import de.steamwar.bungeecore.commands.*; -import de.steamwar.bungeecore.comms.SpigotReceiver; import de.steamwar.bungeecore.listeners.*; import de.steamwar.bungeecore.listeners.mods.*; +import de.steamwar.bungeecore.network.NetworkReceiver; import de.steamwar.bungeecore.sql.*; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.CommandSender; @@ -156,7 +156,7 @@ public class BungeeCore extends Plugin { new EventStarter(); new SessionManager(); - new SpigotReceiver(); + new NetworkReceiver(); new TablistManager(); new SettingsChangedListener(); diff --git a/src/de/steamwar/bungeecore/SubserverSystem.java b/src/de/steamwar/bungeecore/SubserverSystem.java index 2908acb..9842154 100644 --- a/src/de/steamwar/bungeecore/SubserverSystem.java +++ b/src/de/steamwar/bungeecore/SubserverSystem.java @@ -19,10 +19,11 @@ package de.steamwar.bungeecore; -import de.steamwar.bungeecore.comms.handlers.FightInfoHandler; -import de.steamwar.bungeecore.comms.packets.StartingServerPacket; +import de.steamwar.bungeecore.network.NetworkSender; +import de.steamwar.bungeecore.network.handlers.FightInfoHandler; import de.steamwar.bungeecore.sql.IgnoreSystem; import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.network.packets.server.StartingServerPacket; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -53,6 +54,6 @@ public class SubserverSystem { public static void sendPlayer(Subserver subserver, ProxiedPlayer player) { subserver.sendPlayer(player); if(!subserver.hasStarted() && FightInfoHandler.onLobby(player)) - new StartingServerPacket(SteamwarUser.get(player.getUniqueId())).send(player); + NetworkSender.send(player, new StartingServerPacket(SteamwarUser.get(player.getUniqueId()).getId())); } } diff --git a/src/de/steamwar/bungeecore/commands/BauCommand.java b/src/de/steamwar/bungeecore/commands/BauCommand.java index 4840915..3db0c7e 100644 --- a/src/de/steamwar/bungeecore/commands/BauCommand.java +++ b/src/de/steamwar/bungeecore/commands/BauCommand.java @@ -20,12 +20,13 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; -import de.steamwar.bungeecore.comms.packets.BaumemberUpdatePacket; import de.steamwar.bungeecore.inventory.SWInventory; import de.steamwar.bungeecore.inventory.SWItem; +import de.steamwar.bungeecore.network.NetworkSender; import de.steamwar.bungeecore.sql.BauweltMember; import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.messages.ChatSender; +import de.steamwar.network.packets.server.BaumemberUpdatePacket; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.config.ServerInfo; @@ -195,7 +196,7 @@ public class BauCommand extends BasicCommand { for(ServerInfo info : ProxyServer.getInstance().getServers().values()){ Subserver server = Subserver.getSubserver(info); if(server != null && server.getType() == Servertype.BAUSERVER && ((Bauserver)server).getOwner().equals(p.getUniqueId())){ - info.getPlayers().stream().findAny().ifPresent(player -> new BaumemberUpdatePacket().send(player)); + info.getPlayers().stream().findAny().ifPresent(player -> NetworkSender.send(player, new BaumemberUpdatePacket())); break; } } diff --git a/src/de/steamwar/bungeecore/comms/BungeePacket.java b/src/de/steamwar/bungeecore/comms/BungeePacket.java deleted file mode 100644 index b0417d2..0000000 --- a/src/de/steamwar/bungeecore/comms/BungeePacket.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bungeecore.comms; - -import com.google.common.io.ByteArrayDataOutput; -import com.google.common.io.ByteStreams; -import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.api.connection.Server; - -import java.io.ByteArrayOutputStream; - -public abstract class BungeePacket { - - public void send(Server server) { - ByteArrayDataOutput out = ByteStreams.newDataOutput(); - out.writeByte(getId()); - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - writeVars(out); - out.writeUTF(outputStream.toByteArray().toString()); - server.sendData("sw:bridge", out.toByteArray()); - } - - public void send(ProxiedPlayer player) { - send(player.getServer()); - } - - public abstract int getId(); - - public abstract void writeVars(ByteArrayDataOutput byteArrayDataOutput); -} diff --git a/src/de/steamwar/bungeecore/comms/PacketIdManager.java b/src/de/steamwar/bungeecore/comms/PacketIdManager.java deleted file mode 100644 index 94edde9..0000000 --- a/src/de/steamwar/bungeecore/comms/PacketIdManager.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bungeecore.comms; - -public class PacketIdManager { - - //0x0(X) Standalone Packets - public static final byte PING_PACKET = 0x01; - public static final byte TABLIST_NAME = 0x02; - public static final byte PREPARE_SCHEM = 0x03; - public static final byte BAUMEMBER_UPDATE = 0x04; - public static final byte EXECUTE_COMMAND = 0x05; - - public static final byte LOCALE_INVALIDATION = 0x06; - - //0x1(X) Bungee Inventory - public static final byte INVENTORY_PACKET = 0x10; - public static final byte INVENTORY_CALLBACK_PACKET = 0x11; - public static final byte INVENTORY_CLOSE_PACKET = 0x12; - - //0x2(X) Server Information System - public static final byte I_AM_A_LOBBY = 0x20; - public static final byte FIGHT_INFO = 0x21; - public static final byte FIGHT_ENDS = 0x22; - public static final byte STARTING_SERVER = 0x23; -} diff --git a/src/de/steamwar/bungeecore/comms/SpigotHandler.java b/src/de/steamwar/bungeecore/comms/SpigotHandler.java deleted file mode 100644 index 574e9a2..0000000 --- a/src/de/steamwar/bungeecore/comms/SpigotHandler.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bungeecore.comms; - -import com.google.common.io.ByteArrayDataInput; -import net.md_5.bungee.api.config.ServerInfo; - -public interface SpigotHandler { - - void handle(ByteArrayDataInput in, ServerInfo info); -} diff --git a/src/de/steamwar/bungeecore/comms/SpigotReceiver.java b/src/de/steamwar/bungeecore/comms/SpigotReceiver.java deleted file mode 100644 index 04b107a..0000000 --- a/src/de/steamwar/bungeecore/comms/SpigotReceiver.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bungeecore.comms; - -import com.google.common.io.ByteArrayDataInput; -import com.google.common.io.ByteStreams; -import de.steamwar.bungeecore.BungeeCore; -import de.steamwar.bungeecore.comms.handlers.*; -import de.steamwar.bungeecore.listeners.BasicListener; -import net.md_5.bungee.api.ProxyServer; -import net.md_5.bungee.api.connection.Server; -import net.md_5.bungee.api.event.PluginMessageEvent; -import net.md_5.bungee.event.EventHandler; - -import java.util.HashMap; -import java.util.Map; - -public class SpigotReceiver extends BasicListener { - - private static final Map handlerMap = new HashMap<>(); - - @EventHandler - public void onPluginMessage(PluginMessageEvent event) { - if(!event.getTag().equalsIgnoreCase("sw:bridge")) - return; - - event.setCancelled(true); - if(!(event.getSender() instanceof Server)) - return; - - ByteArrayDataInput in = ByteStreams.newDataInput(event.getData()); - Byte handler = in.readByte(); - ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> handlerMap.get(handler).handle(in, ((Server) event.getSender()).getInfo())); - } - - public static void registerHandler(Byte id, SpigotHandler handler) { - handlerMap.put(id, handler); - } - - static { - registerHandler(PacketIdManager.INVENTORY_CALLBACK_PACKET, new InventoryCallbackHandler()); - registerHandler(PacketIdManager.TABLIST_NAME, (in, info) -> {}); - registerHandler(PacketIdManager.PREPARE_SCHEM, new PrepareSchemHandler()); - registerHandler(PacketIdManager.I_AM_A_LOBBY, new ImALobbyHandler()); - registerHandler(PacketIdManager.FIGHT_INFO, new FightInfoHandler()); - registerHandler(PacketIdManager.EXECUTE_COMMAND, new ExecuteCommandHandler()); - registerHandler(PacketIdManager.FIGHT_ENDS, new FightEndsHandler()); - } -} diff --git a/src/de/steamwar/bungeecore/comms/packets/BaumemberUpdatePacket.java b/src/de/steamwar/bungeecore/comms/packets/BaumemberUpdatePacket.java deleted file mode 100644 index ddb4021..0000000 --- a/src/de/steamwar/bungeecore/comms/packets/BaumemberUpdatePacket.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bungeecore.comms.packets; - -import com.google.common.io.ByteArrayDataOutput; -import de.steamwar.bungeecore.comms.BungeePacket; -import de.steamwar.bungeecore.comms.PacketIdManager; - -public class BaumemberUpdatePacket extends BungeePacket { - @Override - public int getId() { - return PacketIdManager.BAUMEMBER_UPDATE; - } - - @Override - public void writeVars(ByteArrayDataOutput byteArrayDataOutput) { - // empty - } -} diff --git a/src/de/steamwar/bungeecore/comms/packets/CloseInventoryPacket.java b/src/de/steamwar/bungeecore/comms/packets/CloseInventoryPacket.java deleted file mode 100644 index 0445c10..0000000 --- a/src/de/steamwar/bungeecore/comms/packets/CloseInventoryPacket.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bungeecore.comms.packets; - -import com.google.common.io.ByteArrayDataOutput; -import de.steamwar.bungeecore.comms.BungeePacket; -import de.steamwar.bungeecore.comms.PacketIdManager; - -public class CloseInventoryPacket extends BungeePacket { - - final int player; - - @Override - public int getId() { - return PacketIdManager.INVENTORY_CLOSE_PACKET; - } - - public CloseInventoryPacket(int player) { - this.player = player; - } - - @Override - public void writeVars(ByteArrayDataOutput byteArrayDataOutput) { - byteArrayDataOutput.writeInt(player); - } -} diff --git a/src/de/steamwar/bungeecore/comms/packets/FightEndsPacket.java b/src/de/steamwar/bungeecore/comms/packets/FightEndsPacket.java deleted file mode 100644 index 3e282ee..0000000 --- a/src/de/steamwar/bungeecore/comms/packets/FightEndsPacket.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2020 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bungeecore.comms.packets; - -import com.google.common.io.ByteArrayDataInput; -import com.google.common.io.ByteArrayDataOutput; -import de.steamwar.bungeecore.comms.BungeePacket; -import de.steamwar.bungeecore.comms.PacketIdManager; -import lombok.AllArgsConstructor; -import lombok.Getter; - -import java.util.ArrayList; -import java.util.List; - -@AllArgsConstructor -@Getter -public class FightEndsPacket extends BungeePacket { - - private byte win; - private int blueSchem; - private int redSchem; - private List bluePlayers; - private List redPlayers; - private String gameMode; - - public FightEndsPacket(ByteArrayDataInput byteArrayDataInput) { - win = byteArrayDataInput.readByte(); - blueSchem = byteArrayDataInput.readInt(); - redSchem = byteArrayDataInput.readInt(); - int blueSize = byteArrayDataInput.readInt(); - bluePlayers = new ArrayList<>(blueSize); - for (int i = 0; i < blueSize; i++) { - bluePlayers.add(byteArrayDataInput.readInt()); - } - int redSize = byteArrayDataInput.readInt(); - redPlayers = new ArrayList<>(redSize); - for (int i = 0; i < redSize; i++) { - redPlayers.add(byteArrayDataInput.readInt()); - } - gameMode = byteArrayDataInput.readUTF(); - } - - @Override - public int getId() { - return PacketIdManager.FIGHT_ENDS; - } - - @Override - public void writeVars(ByteArrayDataOutput byteArrayDataOutput) { - byteArrayDataOutput.writeByte(win); - byteArrayDataOutput.writeInt(blueSchem); - byteArrayDataOutput.writeInt(redSchem); - byteArrayDataOutput.writeInt(bluePlayers.size()); - for (int i : bluePlayers) { - byteArrayDataOutput.writeInt(i); - } - byteArrayDataOutput.writeInt(redPlayers.size()); - for (int i : redPlayers) { - byteArrayDataOutput.writeInt(i); - } - byteArrayDataOutput.writeUTF(gameMode); - } -} diff --git a/src/de/steamwar/bungeecore/comms/packets/FightInfoPacket.java b/src/de/steamwar/bungeecore/comms/packets/FightInfoPacket.java deleted file mode 100644 index 34f120a..0000000 --- a/src/de/steamwar/bungeecore/comms/packets/FightInfoPacket.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bungeecore.comms.packets; - -import com.google.common.io.ByteArrayDataInput; -import com.google.common.io.ByteArrayDataOutput; -import de.steamwar.bungeecore.comms.BungeePacket; -import de.steamwar.bungeecore.comms.PacketIdManager; - -import java.util.ArrayList; -import java.util.List; - -public class FightInfoPacket extends BungeePacket { - - private String serverName; // Name of the Server - private final String gameMode; // GameMode aka Schematictype (if known, else "") - private final String arena; // Name of the arena - private final String blueName; // Name of the blue team, expected to begin with "§a" colorcode - private final String redName; // Name of the red team, expected to begin with "§a" colorcode - private final String fightState; // Fight state (technical term) (if known, else "") - private final int countdown; // Countdown state in seconds (if known, else 0) - private final int blueLeader; // SWUserID of the blue team leader (if known, else 0) - private final int redLeader; // SWUserID of the red team leader (if known, else 0) - private final int blueSchem; // Blue SchemID (if known, else 0) - private final int redSchem; // Red SchemID (if known, else 0) - private final List bluePlayers; // List of Blue SWUserIDs - private final List redPlayers; // List of Red SWUserIDs - private final List spectators; // List of Spectator SWUserIDs - - public FightInfoPacket(String serverName, String gameMode, String arena, String blueName, String redName, String fightState, int countdown, int blueLeader, int redLeader, int blueSchem, int redSchem, List bluePlayers, List redPlayers, List spectators) { - this.serverName = serverName; - this.gameMode = gameMode; - this.arena = arena; - this.blueName = blueName; - this.redName = redName; - this.fightState = fightState; - this.countdown = countdown; - this.blueLeader = blueLeader; - this.redLeader = redLeader; - this.blueSchem = blueSchem; - this.redSchem = redSchem; - this.bluePlayers = bluePlayers; - this.redPlayers = redPlayers; - this.spectators = spectators; - } - - public FightInfoPacket(ByteArrayDataInput in) { - this.serverName = in.readUTF(); - this.gameMode = in.readUTF(); - this.arena = in.readUTF(); - this.blueName = in.readUTF(); - this.redName = in.readUTF(); - this.fightState = in.readUTF(); - this.countdown = in.readInt(); - this.blueLeader = in.readInt(); - this.redLeader = in.readInt(); - this.blueSchem = in.readInt(); - this.redSchem = in.readInt(); - this.bluePlayers = readPlayerList(in); - this.redPlayers = readPlayerList(in); - this.spectators = readPlayerList(in); - } - - @Override - public int getId() { - return PacketIdManager.FIGHT_INFO; - } - - @Override - public void writeVars(ByteArrayDataOutput out) { - out.writeUTF(serverName); - out.writeUTF(gameMode); - out.writeUTF(arena); - out.writeUTF(blueName); - out.writeUTF(redName); - out.writeUTF(fightState); - out.writeInt(countdown); - out.writeInt(blueLeader); - out.writeInt(redLeader); - out.writeInt(blueSchem); - out.writeInt(redSchem); - writePlayerList(out, bluePlayers); - writePlayerList(out, redPlayers); - writePlayerList(out, spectators); - } - - public String getServerName() { - return serverName; - } - - public void setServerName(String serverName) { - this.serverName = serverName; - } - - public String getGameMode() { - return gameMode; - } - - public String getArena() { - return arena; - } - - public String getBlueName() { - return blueName; - } - - public String getRedName() { - return redName; - } - - public String getFightState() { - return fightState; - } - - public int getCountdown() { - return countdown; - } - - public int getBlueLeader() { - return blueLeader; - } - - public int getRedLeader() { - return redLeader; - } - - public int getBlueSchem() { - return blueSchem; - } - - public int getRedSchem() { - return redSchem; - } - - public List getBluePlayers() { - return bluePlayers; - } - - public List getRedPlayers() { - return redPlayers; - } - - public List getSpectators() { - return spectators; - } - - public int playerSize(){ - return bluePlayers.size() + redPlayers.size() + spectators.size(); - } - - private static List readPlayerList(ByteArrayDataInput in) { - int length = in.readInt(); - List players = new ArrayList<>(length); - for(int i = 0; i < length; i++) { - players.add(in.readInt()); - } - return players; - } - - private void writePlayerList(ByteArrayDataOutput out, List players) { - out.writeInt(players.size()); - for(Integer player : players) { - out.writeInt(player); - } - } -} diff --git a/src/de/steamwar/bungeecore/comms/packets/InventoryPacket.java b/src/de/steamwar/bungeecore/comms/packets/InventoryPacket.java deleted file mode 100644 index f9a6195..0000000 --- a/src/de/steamwar/bungeecore/comms/packets/InventoryPacket.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bungeecore.comms.packets; - -import com.google.common.io.ByteArrayDataOutput; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import de.steamwar.bungeecore.comms.PacketIdManager; -import de.steamwar.bungeecore.inventory.SWInventory; -import de.steamwar.bungeecore.inventory.SWItem; -import de.steamwar.bungeecore.comms.BungeePacket; -import de.steamwar.bungeecore.sql.SteamwarUser; -import net.md_5.bungee.api.connection.ProxiedPlayer; - -import java.util.HashMap; -import java.util.Map; - -public class InventoryPacket extends BungeePacket { - - final String title; - final int player; - final int size; - final Map items; - - public InventoryPacket(int size, String title, ProxiedPlayer player) { - items = new HashMap<>(); - this.title = title; - this.size = size; - this.player = SteamwarUser.get(player).getId(); - } - - public InventoryPacket(SWInventory inventory) { - items = inventory.getItems(); - this.title = inventory.getTitle(); - this.size = inventory.getSize(); - this.player = SteamwarUser.get(inventory.getPlayer()).getId(); - } - - @Override - public int getId() { - return PacketIdManager.INVENTORY_PACKET; - } - - @Override - public void writeVars(ByteArrayDataOutput byteArrayDataOutput) { - JsonObject object = new JsonObject(); - object.addProperty("id", player); - object.addProperty("title", title); - object.addProperty("size", size); - object.addProperty("itemcount", items.size()); - JsonArray array = new JsonArray(); - for (int i = 0; i < size; i++) { - if(items.get(i) != null) - array.add(items.get(i).writeToString(i)); - } - object.add("items", array); - byteArrayDataOutput.writeUTF(object.toString()); - } - - public void setItem(int index, SWItem item) { - items.put(index, item); - } -} diff --git a/src/de/steamwar/bungeecore/comms/packets/LocaleInvalidationPacket.java b/src/de/steamwar/bungeecore/comms/packets/LocaleInvalidationPacket.java deleted file mode 100644 index 1a0f4f7..0000000 --- a/src/de/steamwar/bungeecore/comms/packets/LocaleInvalidationPacket.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2020 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bungeecore.comms.packets; - -import com.google.common.io.ByteArrayDataOutput; -import de.steamwar.bungeecore.comms.BungeePacket; -import de.steamwar.bungeecore.comms.PacketIdManager; - -public class LocaleInvalidationPacket extends BungeePacket { - - private int userId; - - public LocaleInvalidationPacket(int userId) { - this.userId = userId; - } - - @Override - public int getId() { - return PacketIdManager.LOCALE_INVALIDATION; - } - - @Override - public void writeVars(ByteArrayDataOutput byteArrayDataOutput) { - byteArrayDataOutput.writeInt(userId); - } -} diff --git a/src/de/steamwar/bungeecore/comms/packets/PingPacket.java b/src/de/steamwar/bungeecore/comms/packets/PingPacket.java deleted file mode 100644 index 47f2bd3..0000000 --- a/src/de/steamwar/bungeecore/comms/packets/PingPacket.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bungeecore.comms.packets; - -import com.google.common.io.ByteArrayDataOutput; -import de.steamwar.bungeecore.comms.BungeePacket; -import de.steamwar.bungeecore.comms.PacketIdManager; - -public class PingPacket extends BungeePacket { - - final int id; - - @Override - public int getId() { - return PacketIdManager.PING_PACKET; - } - - public PingPacket(int id) { - this.id = id; - } - - @Override - public void writeVars(ByteArrayDataOutput byteArrayDataOutput) { - byteArrayDataOutput.writeInt(id); - } -} diff --git a/src/de/steamwar/bungeecore/comms/packets/StartingServerPacket.java b/src/de/steamwar/bungeecore/comms/packets/StartingServerPacket.java deleted file mode 100644 index 1e5edf1..0000000 --- a/src/de/steamwar/bungeecore/comms/packets/StartingServerPacket.java +++ /dev/null @@ -1,25 +0,0 @@ -package de.steamwar.bungeecore.comms.packets; - -import com.google.common.io.ByteArrayDataOutput; -import de.steamwar.bungeecore.comms.BungeePacket; -import de.steamwar.bungeecore.comms.PacketIdManager; -import de.steamwar.bungeecore.sql.SteamwarUser; - -public class StartingServerPacket extends BungeePacket { - - private final int user; - - public StartingServerPacket(SteamwarUser user) { - this.user = user.getId(); - } - - @Override - public int getId() { - return PacketIdManager.STARTING_SERVER; - } - - @Override - public void writeVars(ByteArrayDataOutput out) { - out.writeInt(user); - } -} diff --git a/src/de/steamwar/bungeecore/inventory/SWInventory.java b/src/de/steamwar/bungeecore/inventory/SWInventory.java index 0d4a8d3..1f83b41 100644 --- a/src/de/steamwar/bungeecore/inventory/SWInventory.java +++ b/src/de/steamwar/bungeecore/inventory/SWInventory.java @@ -19,10 +19,11 @@ package de.steamwar.bungeecore.inventory; -import de.steamwar.bungeecore.comms.handlers.InventoryCallbackHandler; -import de.steamwar.bungeecore.comms.packets.CloseInventoryPacket; -import de.steamwar.bungeecore.comms.packets.InventoryPacket; +import de.steamwar.bungeecore.network.NetworkSender; +import de.steamwar.bungeecore.network.handlers.InventoryCallbackHandler; import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.network.packets.server.CloseInventoryPacket; +import de.steamwar.network.packets.server.InventoryPacket; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.ArrayList; @@ -30,6 +31,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.BiFunction; public class SWInventory { @@ -120,8 +122,14 @@ public class SWInventory { } public void open() { - InventoryPacket inv = new InventoryPacket(this); - inv.send(player); + InventoryPacket inv = new InventoryPacket(title, SteamwarUser.get(player).getId(), size, map(itemMap, (integer, swItem) -> swItem.writeToString(integer).getAsString())); + NetworkSender.send(player, inv); + } + + private static Map map(Map map, BiFunction function) { + Map result = new HashMap<>(); + map.forEach((key, value) -> result.put(key, function.apply(key, value))); + return result; } public void close() { @@ -129,7 +137,7 @@ public class SWInventory { } public static void close(ProxiedPlayer player) { - new CloseInventoryPacket(SteamwarUser.get(player).getId()).send(player); + NetworkSender.send(player, new CloseInventoryPacket(SteamwarUser.get(player).getId())); } public void setClose(InvCallback close) { diff --git a/src/de/steamwar/bungeecore/listeners/ChatListener.java b/src/de/steamwar/bungeecore/listeners/ChatListener.java index a09cdbf..12f152c 100644 --- a/src/de/steamwar/bungeecore/listeners/ChatListener.java +++ b/src/de/steamwar/bungeecore/listeners/ChatListener.java @@ -21,9 +21,10 @@ package de.steamwar.bungeecore.listeners; import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.bot.SteamwarDiscordBot; -import de.steamwar.bungeecore.comms.packets.PingPacket; +import de.steamwar.bungeecore.network.NetworkSender; import de.steamwar.bungeecore.sql.*; import de.steamwar.messages.ChatSender; +import de.steamwar.network.packets.server.PingPacket; import net.md_5.bungee.api.*; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.event.ChatEvent; @@ -202,7 +203,7 @@ public class ChatListener extends BasicListener { String mark = "@" + player.user().getUserName(); return Arrays.stream(message.split(" ")).map(cur -> { if(cur.equalsIgnoreCase(mark)) { - new PingPacket(player.user().getId()).send(player.user().getPlayer()); + NetworkSender.send(player.user().getPlayer(), new PingPacket(player.user().getId())); return "§e" + cur + returnColor; } return cur; diff --git a/src/de/steamwar/bungeecore/listeners/TablistManager.java b/src/de/steamwar/bungeecore/listeners/TablistManager.java index b7dd44b..cc5e529 100644 --- a/src/de/steamwar/bungeecore/listeners/TablistManager.java +++ b/src/de/steamwar/bungeecore/listeners/TablistManager.java @@ -26,9 +26,9 @@ import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.Servertype; import de.steamwar.bungeecore.Subserver; -import de.steamwar.bungeecore.comms.packets.FightInfoPacket; import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.UserGroup; +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; diff --git a/src/de/steamwar/bungeecore/network/BungeeNetworkHandler.java b/src/de/steamwar/bungeecore/network/BungeeNetworkHandler.java new file mode 100644 index 0000000..6e5ff6c --- /dev/null +++ b/src/de/steamwar/bungeecore/network/BungeeNetworkHandler.java @@ -0,0 +1,16 @@ +package de.steamwar.bungeecore.network; + +import de.steamwar.bungeecore.network.handlers.*; +import lombok.experimental.UtilityClass; + +@UtilityClass +public class BungeeNetworkHandler { + public static void register() { + new ExecuteCommandHandler().register(); + new FightEndsHandler().register(); + new FightInfoHandler().register(); + new ImALobbyHandler().register(); + new InventoryCallbackHandler().register(); + new PrepareSchemHandler().register(); + } +} diff --git a/src/de/steamwar/bungeecore/network/NetworkReceiver.java b/src/de/steamwar/bungeecore/network/NetworkReceiver.java new file mode 100644 index 0000000..a023a92 --- /dev/null +++ b/src/de/steamwar/bungeecore/network/NetworkReceiver.java @@ -0,0 +1,27 @@ +package de.steamwar.bungeecore.network; + +import de.steamwar.bungeecore.listeners.BasicListener; +import de.steamwar.network.packets.NetworkPacket; +import net.md_5.bungee.api.config.ServerInfo; +import net.md_5.bungee.api.connection.Server; +import net.md_5.bungee.api.event.PluginMessageEvent; +import net.md_5.bungee.event.EventHandler; + +public class NetworkReceiver extends BasicListener { + + public static ServerInfo sender; + + @EventHandler + public void onPluginMessage(PluginMessageEvent event) { + if(!event.getTag().equalsIgnoreCase("sw:bridge")) + return; + + event.setCancelled(true); + if(!(event.getSender() instanceof Server)) + return; + + sender = (ServerInfo) event.getSender(); + NetworkPacket.handle(event.getData()); + sender = null; + } +} diff --git a/src/de/steamwar/bungeecore/network/NetworkSender.java b/src/de/steamwar/bungeecore/network/NetworkSender.java new file mode 100644 index 0000000..050225f --- /dev/null +++ b/src/de/steamwar/bungeecore/network/NetworkSender.java @@ -0,0 +1,22 @@ +package de.steamwar.bungeecore.network; + +import de.steamwar.network.packets.NetworkPacket; +import lombok.SneakyThrows; +import net.md_5.bungee.api.config.ServerInfo; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +import java.io.ByteArrayOutputStream; +import java.io.ObjectOutputStream; + +public class NetworkSender { + + @SneakyThrows + public static void send(ProxiedPlayer player, NetworkPacket packet) { + player.sendData("sw:bridge", packet.serialize()); + } + + public static void send(ServerInfo serverInfo, NetworkPacket packet) { + ProxiedPlayer player = serverInfo.getPlayers().iterator().next(); + send(player, packet); + } +} diff --git a/src/de/steamwar/bungeecore/comms/handlers/ExecuteCommandHandler.java b/src/de/steamwar/bungeecore/network/handlers/ExecuteCommandHandler.java similarity index 70% rename from src/de/steamwar/bungeecore/comms/handlers/ExecuteCommandHandler.java rename to src/de/steamwar/bungeecore/network/handlers/ExecuteCommandHandler.java index 0051e55..ae31db5 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/ExecuteCommandHandler.java +++ b/src/de/steamwar/bungeecore/network/handlers/ExecuteCommandHandler.java @@ -17,19 +17,19 @@ along with this program. If not, see . */ -package de.steamwar.bungeecore.comms.handlers; +package de.steamwar.bungeecore.network.handlers; -import com.google.common.io.ByteArrayDataInput; -import de.steamwar.bungeecore.comms.SpigotHandler; import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.network.packets.PacketHandler; +import de.steamwar.network.packets.client.ExecuteCommandPacket; import net.md_5.bungee.api.ProxyServer; -import net.md_5.bungee.api.config.ServerInfo; -public class ExecuteCommandHandler implements SpigotHandler { - @Override - public void handle(ByteArrayDataInput in, ServerInfo info) { - SteamwarUser target = SteamwarUser.get(in.readInt()); - String command = in.readUTF(); +public class ExecuteCommandHandler extends PacketHandler { + + @Handler + public void handle(ExecuteCommandPacket packet) { + SteamwarUser target = SteamwarUser.get(packet.getPlayerId()); + String command = packet.getCommand(); ProxyServer.getInstance().getPluginManager().dispatchCommand(ProxyServer.getInstance().getPlayer(target.getUuid()), command); } diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/network/handlers/FightEndsHandler.java similarity index 93% rename from src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java rename to src/de/steamwar/bungeecore/network/handlers/FightEndsHandler.java index b9a7492..b6a3f6b 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/network/handlers/FightEndsHandler.java @@ -17,20 +17,18 @@ * along with this program. If not, see . */ -package de.steamwar.bungeecore.comms.handlers; +package de.steamwar.bungeecore.network.handlers; -import com.google.common.io.ByteArrayDataInput; import de.steamwar.bungeecore.ArenaMode; -import de.steamwar.bungeecore.comms.SpigotHandler; -import de.steamwar.bungeecore.comms.packets.FightEndsPacket; import de.steamwar.bungeecore.sql.*; +import de.steamwar.network.packets.PacketHandler; +import de.steamwar.network.packets.common.FightEndsPacket; import lombok.RequiredArgsConstructor; -import net.md_5.bungee.api.config.ServerInfo; import java.util.*; import java.util.stream.Collectors; -public class FightEndsHandler implements SpigotHandler { +public class FightEndsHandler extends PacketHandler { private Map> gameModeGames = new HashMap<>(); @@ -46,10 +44,8 @@ public class FightEndsHandler implements SpigotHandler { fightCounts.put("miniwargear", 3L); } - @Override - public void handle(ByteArrayDataInput in, ServerInfo info) { - FightEndsPacket fightEndsPacket = new FightEndsPacket(in); - + @Handler + public void handle(FightEndsPacket fightEndsPacket) { if (!ArenaMode.getBySchemType(SchematicType.fromDB(fightEndsPacket.getGameMode())).isRanked()) { return; } diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightInfoHandler.java b/src/de/steamwar/bungeecore/network/handlers/FightInfoHandler.java similarity index 75% rename from src/de/steamwar/bungeecore/comms/handlers/FightInfoHandler.java rename to src/de/steamwar/bungeecore/network/handlers/FightInfoHandler.java index eb708df..a4b6367 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightInfoHandler.java +++ b/src/de/steamwar/bungeecore/network/handlers/FightInfoHandler.java @@ -17,12 +17,13 @@ along with this program. If not, see . */ -package de.steamwar.bungeecore.comms.handlers; +package de.steamwar.bungeecore.network.handlers; -import com.google.common.io.ByteArrayDataInput; -import de.steamwar.bungeecore.comms.SpigotHandler; -import de.steamwar.bungeecore.comms.packets.FightInfoPacket; import de.steamwar.bungeecore.listeners.TablistManager; +import de.steamwar.bungeecore.network.NetworkReceiver; +import de.steamwar.bungeecore.network.NetworkSender; +import de.steamwar.network.packets.PacketHandler; +import de.steamwar.network.packets.common.FightInfoPacket; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -30,7 +31,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Set; -public class FightInfoHandler implements SpigotHandler { +public class FightInfoHandler extends PacketHandler { private static final Set lobbys = new HashSet<>(); @@ -42,10 +43,11 @@ public class FightInfoHandler implements SpigotHandler { return lobbys.contains(player.getServer().getInfo()); } - @Override - public void handle(ByteArrayDataInput in, ServerInfo info) { - FightInfoPacket packet = new FightInfoPacket(in); - packet.setServerName(info.getName()); + @Handler + public void handle(FightInfoPacket packet) { + ServerInfo info = NetworkReceiver.sender; + + FightInfoPacket lobbyPacket = packet.withServerName(info.getName()); TablistManager.newFightInfo(info, packet); @@ -58,7 +60,7 @@ public class FightInfoHandler implements SpigotHandler { continue; } - packet.send(it.next()); + NetworkSender.send(lobby, lobbyPacket); } } } diff --git a/src/de/steamwar/bungeecore/comms/handlers/ImALobbyHandler.java b/src/de/steamwar/bungeecore/network/handlers/ImALobbyHandler.java similarity index 67% rename from src/de/steamwar/bungeecore/comms/handlers/ImALobbyHandler.java rename to src/de/steamwar/bungeecore/network/handlers/ImALobbyHandler.java index 8d2013d..54ce65f 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/ImALobbyHandler.java +++ b/src/de/steamwar/bungeecore/network/handlers/ImALobbyHandler.java @@ -17,16 +17,16 @@ along with this program. If not, see . */ -package de.steamwar.bungeecore.comms.handlers; +package de.steamwar.bungeecore.network.handlers; -import com.google.common.io.ByteArrayDataInput; -import de.steamwar.bungeecore.comms.SpigotHandler; -import net.md_5.bungee.api.config.ServerInfo; +import de.steamwar.bungeecore.network.NetworkReceiver; +import de.steamwar.network.packets.PacketHandler; +import de.steamwar.network.packets.client.ImALobbyPacket; -public class ImALobbyHandler implements SpigotHandler { +public class ImALobbyHandler extends PacketHandler { - @Override - public void handle(ByteArrayDataInput in, ServerInfo info) { - FightInfoHandler.addLobby(info); + @Handler + public void handle(ImALobbyPacket packet) { + FightInfoHandler.addLobby(NetworkReceiver.sender); } } diff --git a/src/de/steamwar/bungeecore/comms/handlers/InventoryCallbackHandler.java b/src/de/steamwar/bungeecore/network/handlers/InventoryCallbackHandler.java similarity index 65% rename from src/de/steamwar/bungeecore/comms/handlers/InventoryCallbackHandler.java rename to src/de/steamwar/bungeecore/network/handlers/InventoryCallbackHandler.java index 0fd90a6..6110611 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/InventoryCallbackHandler.java +++ b/src/de/steamwar/bungeecore/network/handlers/InventoryCallbackHandler.java @@ -17,41 +17,42 @@ along with this program. If not, see . */ -package de.steamwar.bungeecore.comms.handlers; +package de.steamwar.bungeecore.network.handlers; -import com.google.common.io.ByteArrayDataInput; import de.steamwar.bungeecore.BungeeCore; -import de.steamwar.bungeecore.comms.SpigotHandler; -import de.steamwar.bungeecore.comms.packets.CloseInventoryPacket; import de.steamwar.bungeecore.inventory.InvCallback; import de.steamwar.bungeecore.inventory.SWInventory; +import de.steamwar.bungeecore.network.NetworkReceiver; +import de.steamwar.bungeecore.network.NetworkSender; import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.network.packets.PacketHandler; +import de.steamwar.network.packets.client.InventoryCallbackPacket; +import de.steamwar.network.packets.server.CloseInventoryPacket; import net.md_5.bungee.api.ProxyServer; -import net.md_5.bungee.api.config.ServerInfo; import java.util.HashMap; import java.util.Map; -public class InventoryCallbackHandler implements SpigotHandler { +public class InventoryCallbackHandler extends PacketHandler { public static final Map inventoryHashMap = new HashMap<>(); - @Override - public void handle(ByteArrayDataInput in, ServerInfo info) { - SteamwarUser owner = SteamwarUser.get(in.readInt()); - CallbackType type = CallbackType.valueOf(in.readUTF()); + @Handler + public void handle(InventoryCallbackPacket packet) { + SteamwarUser owner = SteamwarUser.get(packet.getOwner()); + InventoryCallbackPacket.CallbackType type = packet.getType(); if(!inventoryHashMap.containsKey(owner.getId())) { BungeeCore.send(ProxyServer.getInstance().getPlayer(owner.getUuid()), BungeeCore.CHAT_PREFIX + "§cBitte erneut versuchen. Durch ein Softwareupdate konnte die übliche Aktion nicht durchgeführt werden."); - if(type == CallbackType.CLICK) { - new CloseInventoryPacket(owner.getId()).send(ProxyServer.getInstance().getPlayer(owner.getUuid())); + if(type == InventoryCallbackPacket.CallbackType.CLICK) { + NetworkSender.send(NetworkReceiver.sender, new CloseInventoryPacket(owner.getId())); } return; } - if(type == CallbackType.CLICK) { - int pos = in.readInt(); - InvCallback.ClickType clickType = InvCallback.ClickType.valueOf(in.readUTF()); + if(type == InventoryCallbackPacket.CallbackType.CLICK) { + int pos = packet.getPosition(); + InvCallback.ClickType clickType = InvCallback.ClickType.valueOf(packet.getClickType().name()); inventoryHashMap.get(owner.getId()).handleCallback(clickType, pos); - }else if(type == CallbackType.CLOSE) { + }else if(type == InventoryCallbackPacket.CallbackType.CLOSE) { if(inventoryHashMap.get(owner.getId()).isNext()) { inventoryHashMap.get(owner.getId()).handleClose(); return; @@ -59,9 +60,4 @@ public class InventoryCallbackHandler implements SpigotHandler { inventoryHashMap.get(owner.getId()).setNext(true); } } - - public enum CallbackType { - CLICK, - CLOSE, - } } diff --git a/src/de/steamwar/bungeecore/comms/handlers/PrepareSchemHandler.java b/src/de/steamwar/bungeecore/network/handlers/PrepareSchemHandler.java similarity index 74% rename from src/de/steamwar/bungeecore/comms/handlers/PrepareSchemHandler.java rename to src/de/steamwar/bungeecore/network/handlers/PrepareSchemHandler.java index d968178..c59c8df 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/PrepareSchemHandler.java +++ b/src/de/steamwar/bungeecore/network/handlers/PrepareSchemHandler.java @@ -17,24 +17,24 @@ along with this program. If not, see . */ -package de.steamwar.bungeecore.comms.handlers; +package de.steamwar.bungeecore.network.handlers; -import com.google.common.io.ByteArrayDataInput; import de.steamwar.bungeecore.ArenaMode; import de.steamwar.bungeecore.ServerStarter; -import de.steamwar.bungeecore.comms.SpigotHandler; import de.steamwar.bungeecore.sql.SchematicType; import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.network.packets.PacketHandler; +import de.steamwar.network.packets.client.PrepareSchemPacket; import net.md_5.bungee.api.ProxyServer; -import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; -public class PrepareSchemHandler implements SpigotHandler { - @Override - public void handle(ByteArrayDataInput in, ServerInfo info) { - ProxiedPlayer player = ProxyServer.getInstance().getPlayer(SteamwarUser.get(in.readInt()).getUuid()); - int schematicID = in.readInt(); - ArenaMode mode = ArenaMode.getBySchemType(SchematicType.fromDB(in.readUTF())); +public class PrepareSchemHandler extends PacketHandler { + + @Handler + public void handle(PrepareSchemPacket packet) { + ProxiedPlayer player = ProxyServer.getInstance().getPlayer(SteamwarUser.get(packet.getPlayer()).getUuid()); + int schematicID = packet.getSchem(); + ArenaMode mode = ArenaMode.getBySchemType(SchematicType.fromDB(packet.getSchemType())); new ServerStarter().test(mode, mode.getRandomMap(), player).prepare(schematicID).start(); } diff --git a/src/de/steamwar/bungeecore/sql/SteamwarUser.java b/src/de/steamwar/bungeecore/sql/SteamwarUser.java index 829ee84..96c92d5 100644 --- a/src/de/steamwar/bungeecore/sql/SteamwarUser.java +++ b/src/de/steamwar/bungeecore/sql/SteamwarUser.java @@ -23,9 +23,10 @@ import com.google.gson.JsonParser; import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.commands.WebregisterCommand; -import de.steamwar.bungeecore.comms.packets.LocaleInvalidationPacket; import de.steamwar.bungeecore.listeners.ConnectionListener; +import de.steamwar.bungeecore.network.NetworkSender; import de.steamwar.messages.ChatSender; +import de.steamwar.network.packets.server.LocaleInvalidationPacket; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.connection.PendingConnection; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -388,6 +389,6 @@ public class SteamwarUser { this.locale = locale; this.manualLocale = manualLocale; updateLocale.update(locale.toLanguageTag(), manualLocale, id); - new LocaleInvalidationPacket(id).send(getPlayer()); + NetworkSender.send(getPlayer(), new LocaleInvalidationPacket(id)); } } From 01ea928652bc619f654087006593a3a4e6bd76f1 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 10 Jun 2022 19:30:15 +0200 Subject: [PATCH 02/20] 1.19 Build server Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/ServerStarter.java | 10 +++++----- src/de/steamwar/bungeecore/commands/BauCommand.java | 12 +++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/de/steamwar/bungeecore/ServerStarter.java b/src/de/steamwar/bungeecore/ServerStarter.java index 36ccac6..35a97dd 100644 --- a/src/de/steamwar/bungeecore/ServerStarter.java +++ b/src/de/steamwar/bungeecore/ServerStarter.java @@ -26,7 +26,7 @@ public class ServerStarter { private static final String EVENT_PATH = BACKBONE + "event/"; public static final String TEMP_WORLD_PATH = BACKBONE + "arenaserver/"; public static final String TUTORIAL_PATH = BACKBONE + "tutorials/"; - public static final String WORLDS18_PATH = BACKBONE + "userworlds18/"; + public static final String WORLDS19_PATH = BACKBONE + "userworlds19/"; private File directory = null; private String worldDir = null; @@ -109,10 +109,10 @@ public class ServerStarter { return this; } - public ServerStarter build18(UUID owner) { - directory = new File(SERVER_PATH, "Bau18"); - serverJar = "paper-1.18.2.jar"; - worldDir = WORLDS18_PATH; + public ServerStarter build19(UUID owner) { + directory = new File(SERVER_PATH, "Bau19"); + serverJar = "paper-1.19.jar"; + worldDir = WORLDS19_PATH; worldName = String.valueOf(SteamwarUser.get(owner).getId()); buildWithWorld(owner, new File(directory, "Bauwelt").getPath()); return this; diff --git a/src/de/steamwar/bungeecore/commands/BauCommand.java b/src/de/steamwar/bungeecore/commands/BauCommand.java index 4840915..ea21cd9 100644 --- a/src/de/steamwar/bungeecore/commands/BauCommand.java +++ b/src/de/steamwar/bungeecore/commands/BauCommand.java @@ -46,7 +46,7 @@ public class BauCommand extends BasicCommand { ProxiedPlayer p = (ProxiedPlayer) sender; versionSelector(p, args, 0, - () -> new ServerStarter().build18(p.getUniqueId()).send(p).start(), + () -> new ServerStarter().build19(p.getUniqueId()).send(p).start(), () -> new ServerStarter().build15(p.getUniqueId()).send(p).start(), () -> new ServerStarter().build12(p.getUniqueId()).send(p).start(), () -> { @@ -128,13 +128,13 @@ public class BauCommand extends BasicCommand { } versionSelector(p, args, 2, - () -> new ServerStarter().build18(worldOwner.getUuid()).send(p).start(), + () -> new ServerStarter().build19(worldOwner.getUuid()).send(p).start(), () -> new ServerStarter().build15(worldOwner.getUuid()).send(p).start(), () -> new ServerStarter().build12(worldOwner.getUuid()).send(p).start(), () -> HelpCommand.sendBauHelp(ChatSender.of(p))); } - private static void versionSelector(ProxiedPlayer p, String[] args, int pos, Runnable run18, Runnable run15, Runnable run12, Runnable runElse) { + private static void versionSelector(ProxiedPlayer p, String[] args, int pos, Runnable run19, Runnable run15, Runnable run12, Runnable runElse) { if(args.length <= pos) { int version = p.getPendingConnection().getVersion(); if(version > 340) { // Version > 1.12.2 @@ -146,9 +146,11 @@ public class BauCommand extends BasicCommand { } switch (args[pos].toLowerCase()) { + case "19": + case "1.19": case "18": case "1.18": - run18.run(); + run19.run(); break; case "ws": case "warship": @@ -231,7 +233,7 @@ public class BauCommand extends BasicCommand { private static void delete(ProxiedPlayer p, String[] args){ SteamwarUser user = SteamwarUser.get(p.getUniqueId()); versionSelector(p, args, 1, - () -> deleteConfirmation(p, () -> deleteWorld(p, ServerStarter.WORLDS18_PATH + user.getId())), + () -> deleteConfirmation(p, () -> deleteWorld(p, ServerStarter.WORLDS19_PATH + user.getId())), () -> deleteConfirmation(p, () -> deleteWorld(p, BungeeCore.USERWORLDS15 + user.getId())), () -> deleteConfirmation(p, () -> deleteWorld(p, BungeeCore.WORLD_FOLDER + p.getUniqueId().toString())), () -> HelpCommand.sendBauHelp(ChatSender.of(p))); From a97a6a78e22e212eb3b7a889f8b3cbdfbabcdd61 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 11 Jun 2022 08:55:51 +0200 Subject: [PATCH 03/20] Fix Remote Plugin Messages --- .../bungeecore/network/NetworkReceiver.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/de/steamwar/bungeecore/network/NetworkReceiver.java b/src/de/steamwar/bungeecore/network/NetworkReceiver.java index a023a92..c0818f4 100644 --- a/src/de/steamwar/bungeecore/network/NetworkReceiver.java +++ b/src/de/steamwar/bungeecore/network/NetworkReceiver.java @@ -1,5 +1,6 @@ package de.steamwar.bungeecore.network; +import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.listeners.BasicListener; import de.steamwar.network.packets.NetworkPacket; import net.md_5.bungee.api.config.ServerInfo; @@ -7,12 +8,25 @@ import net.md_5.bungee.api.connection.Server; import net.md_5.bungee.api.event.PluginMessageEvent; import net.md_5.bungee.event.EventHandler; +import java.net.InetSocketAddress; +import java.util.Arrays; +import java.util.List; +import java.util.logging.Level; + public class NetworkReceiver extends BasicListener { + private static final List blockedTags = Arrays.asList("bungeecord:main", "BungeeCord", "sw:bridge"); + private static final List allowedAddresses = Arrays.asList("localhost", "127.0.0.1", "0.0.0.0"); + public static ServerInfo sender; @EventHandler public void onPluginMessage(PluginMessageEvent event) { + if (blockedTags.contains(event.getTag()) && !allowedAddresses.contains(((InetSocketAddress) event.getSender().getSocketAddress()).getHostString())) { + BungeeCore.log(Level.SEVERE, ((InetSocketAddress) event.getSender().getSocketAddress()).getHostString() + " tried to send a plugin message with tag " + event.getTag()); + event.setCancelled(true); + return; + } if(!event.getTag().equalsIgnoreCase("sw:bridge")) return; From e49546d3d82a06ed3393c7d26276d43d2b295951 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 11 Jun 2022 09:44:39 +0200 Subject: [PATCH 04/20] Fix Remote Plugin Messages --- src/de/steamwar/bungeecore/network/NetworkReceiver.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/network/NetworkReceiver.java b/src/de/steamwar/bungeecore/network/NetworkReceiver.java index c0818f4..97a9b7c 100644 --- a/src/de/steamwar/bungeecore/network/NetworkReceiver.java +++ b/src/de/steamwar/bungeecore/network/NetworkReceiver.java @@ -7,6 +7,7 @@ import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.Server; import net.md_5.bungee.api.event.PluginMessageEvent; import net.md_5.bungee.event.EventHandler; +import net.md_5.bungee.event.EventPriority; import java.net.InetSocketAddress; import java.util.Arrays; @@ -20,7 +21,7 @@ public class NetworkReceiver extends BasicListener { public static ServerInfo sender; - @EventHandler + @EventHandler(priority = EventPriority.HIGHEST) public void onPluginMessage(PluginMessageEvent event) { if (blockedTags.contains(event.getTag()) && !allowedAddresses.contains(((InetSocketAddress) event.getSender().getSocketAddress()).getHostString())) { BungeeCore.log(Level.SEVERE, ((InetSocketAddress) event.getSender().getSocketAddress()).getHostString() + " tried to send a plugin message with tag " + event.getTag()); From 3d57f9ca805cb3cb77e8ad32aac7ac199da1b62e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 12 Jun 2022 18:17:06 +0200 Subject: [PATCH 05/20] Add debug messages for fabric checks --- .../bungeecore/listeners/mods/Fabric.java | 20 +++++++++---------- .../steamwar/messages/BungeeCore.properties | 2 +- .../messages/BungeeCore_de.properties | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java index 4e0a852..0bbbee3 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java @@ -59,7 +59,7 @@ public class Fabric extends BasicListener { continue; } if (System.currentTimeMillis() - entry.getValue() > TimeUnit.SECONDS.toMillis(20)) { - banPlayer(SteamwarUser.get(entry.getKey()), entry.getKey()); + banPlayer(SteamwarUser.get(entry.getKey()), entry.getKey(), "Expected message not received"); return; } } @@ -82,7 +82,7 @@ public class Fabric extends BasicListener { if (!Storage.fabricCheckedPlayers.containsKey(player)) { synchronized (Storage.fabricExpectPluginMessage) { if (Storage.fabricExpectPluginMessage.containsKey(player)) { - banPlayer(user, player); + banPlayer(user, player, "Was not fabric checked but send message nonetheless"); return; } } @@ -95,7 +95,7 @@ public class Fabric extends BasicListener { Utils.VarInt varInt = Utils.readVarInt(data,0); if(data.length != varInt.length + varInt.value) { - banPlayer(user,player); + banPlayer(user,player, "Invalid message length"); return; } @@ -106,7 +106,7 @@ public class Fabric extends BasicListener { try{ dataString = new String(data, StandardCharsets.UTF_8); }catch (UnsupportedCharsetException exception) { - banPlayer(user, player); + banPlayer(user, player, "Unsupported charset"); return; } @@ -115,7 +115,7 @@ public class Fabric extends BasicListener { try { array = new JsonParser().parse(dataString).getAsJsonArray(); }catch (JsonSyntaxException exception) { - banPlayer(user, player); + banPlayer(user, player, "Invalid json"); return; } @@ -126,12 +126,12 @@ public class Fabric extends BasicListener { boolean isSorted = isSortedAlphabetically(mods); if(!isSorted) { - banPlayer(user, player); + banPlayer(user, player, "Mods are not sorted alphabetically"); return; } if(!neededModsContained(mods)) { - banPlayer(user, player); + banPlayer(user, player, "Needed mods are not contained"); return; } @@ -139,7 +139,7 @@ public class Fabric extends BasicListener { if (Storage.fabricCheckedPlayers.containsKey(player)) { long current = Storage.fabricCheckedPlayers.get(player); if (current != dataString.hashCode()) { - banPlayer(user, player); + banPlayer(user, player, ""); return; } } else { @@ -176,11 +176,11 @@ public class Fabric extends BasicListener { .count() == neededMods.size(); } - public void banPlayer(SteamwarUser user, ProxiedPlayer player) { + public void banPlayer(SteamwarUser user, ProxiedPlayer player, String reason) { user.punishPerma(Punishment.PunishmentType.Ban, Message.parse("MODIFICATION_BAN_MESSAGE", player, user.getUserName(), user.getId()), 0); - BungeeCore.log(Level.SEVERE,Message.parse("MODIFICATION_BAN_LOG", player, user.getUserName())); + BungeeCore.log(Level.SEVERE,Message.parse("MODIFICATION_BAN_LOG", player, user.getUserName(), reason)); } public static void remove(ProxiedPlayer player) { diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 0ee445c..ec98820 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -615,7 +615,7 @@ RANK_NEEDED_FIGHTS_LEFT={0} §8(§e{1}§7 fights needed§8) #Fabric Mod Sender MODIFICATION_BAN_MESSAGE=You tried to bypass / modify the FabricModSender! -MODIFICATION_BAN_LOG={0} has tried to edit / bypass the FabricModSender! +MODIFICATION_BAN_LOG={0} has tried to edit / bypass the FabricModSender! Reason: {1} MODIFICATION_CHECK_SUCCESS=§eYour mods have been checked and you are now allowed to join arenas! #Arena Merging diff --git a/src/de/steamwar/messages/BungeeCore_de.properties b/src/de/steamwar/messages/BungeeCore_de.properties index 66d79db..f118020 100644 --- a/src/de/steamwar/messages/BungeeCore_de.properties +++ b/src/de/steamwar/messages/BungeeCore_de.properties @@ -595,7 +595,7 @@ RANK_NEEDED_FIGHTS_LEFT={0} §8(§7noch §e{1}§7 Kämpfe nötig§8) #Fabric Mod Sender MODIFICATION_BAN_MESSAGE=Du hast probiert den FabricModSender zu umgehen / zu modifizieren! -MODIFICATION_BAN_LOG={0} hat probiert den Fabric Mod Sender zu editieren / umzugehen! +MODIFICATION_BAN_LOG={0} hat probiert den Fabric Mod Sender zu editieren / umzugehen! Grund: {1} MODIFICATION_CHECK_SUCCESS=§eDeine Mods wurden geprüft und du darfst nun auf Arenen joinen! #Arena Merging From 3a97baa26796a37a65fd7844b665ebe4e6d273ba Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 12 Jun 2022 18:22:33 +0200 Subject: [PATCH 06/20] Add debug messages for fabric checks --- src/de/steamwar/bungeecore/listeners/mods/Fabric.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java index 0bbbee3..b2b949f 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java @@ -41,6 +41,7 @@ import java.nio.charset.UnsupportedCharsetException; import java.util.*; import java.util.concurrent.TimeUnit; import java.util.logging.Level; +import java.util.stream.Collectors; public class Fabric extends BasicListener { @@ -126,7 +127,7 @@ public class Fabric extends BasicListener { boolean isSorted = isSortedAlphabetically(mods); if(!isSorted) { - banPlayer(user, player, "Mods are not sorted alphabetically"); + banPlayer(user, player, "Mods are not sorted alphabetically: " + mods.stream().map(Mod::getModName).collect(Collectors.joining(", "))); return; } From 0446af29aaf5e70d7ceb0dd2731ae127dd236f5e Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 13 Jun 2022 22:10:10 +0200 Subject: [PATCH 07/20] Cannot spoof chat my ass Signed-off-by: Lixfel --- .../bungeecore/commands/TpCommand.java | 3 +- .../bungeecore/listeners/ChatListener.java | 3 +- src/de/steamwar/bungeecore/util/Chat19.java | 67 +++++++++++++++++++ 3 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 src/de/steamwar/bungeecore/util/Chat19.java diff --git a/src/de/steamwar/bungeecore/commands/TpCommand.java b/src/de/steamwar/bungeecore/commands/TpCommand.java index 4fa1cf8..3961f8c 100644 --- a/src/de/steamwar/bungeecore/commands/TpCommand.java +++ b/src/de/steamwar/bungeecore/commands/TpCommand.java @@ -21,6 +21,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.sql.*; +import de.steamwar.bungeecore.util.Chat19; import de.steamwar.messages.ChatSender; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.CommandSender; @@ -55,7 +56,7 @@ public class TpCommand extends BasicCommand { //Give control of teleport command to server if(server == null) { - player.chat("/tp " + String.join(" ", args)); + Chat19.chat(player, "/tp " + String.join(" ", args)); return; } diff --git a/src/de/steamwar/bungeecore/listeners/ChatListener.java b/src/de/steamwar/bungeecore/listeners/ChatListener.java index a09cdbf..483dc9d 100644 --- a/src/de/steamwar/bungeecore/listeners/ChatListener.java +++ b/src/de/steamwar/bungeecore/listeners/ChatListener.java @@ -23,6 +23,7 @@ import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.bot.SteamwarDiscordBot; import de.steamwar.bungeecore.comms.packets.PingPacket; import de.steamwar.bungeecore.sql.*; +import de.steamwar.bungeecore.util.Chat19; import de.steamwar.messages.ChatSender; import net.md_5.bungee.api.*; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -123,7 +124,7 @@ public class ChatListener extends BasicListener { return; } - player.chat(message); + Chat19.chat(player, message); } private static String modifyFilter(ChatSender sender, String message) { diff --git a/src/de/steamwar/bungeecore/util/Chat19.java b/src/de/steamwar/bungeecore/util/Chat19.java new file mode 100644 index 0000000..1110355 --- /dev/null +++ b/src/de/steamwar/bungeecore/util/Chat19.java @@ -0,0 +1,67 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2022 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bungeecore.util; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import net.md_5.bungee.ServerConnection; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.protocol.PacketWrapper; +import net.md_5.bungee.protocol.ProtocolConstants; +import net.md_5.bungee.protocol.packet.Chat; + +import java.time.Instant; + +public class Chat19 extends Chat { + + public static void chat(ProxiedPlayer p, String message) { + if(p.getPendingConnection().getVersion() >= 759) { + Chat19 packet = new Chat19(message); + + ByteBuf buf = Unpooled.buffer(); + writeVarInt(0x04, buf); + packet.write(buf, ProtocolConstants.Direction.TO_SERVER, p.getPendingConnection().getVersion()); + ((ServerConnection) p.getServer()).getCh().write(new PacketWrapper(packet, buf)); + } else { + p.chat(message); + } + } + + private final Instant timestamp = Instant.now(); + private final long salt = 0L; + private final byte[] signature = new byte[0]; + private final boolean signedPreview = false; + + public Chat19 (String message) { + super(message); + } + + @Override + public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { + if (direction == ProtocolConstants.Direction.TO_CLIENT || protocolVersion != 759) + throw new UnsupportedOperationException(); + + writeString(getMessage(), buf); + buf.writeLong(timestamp.toEpochMilli()); + buf.writeLong(salt); + writeArray(signature, buf); + buf.writeBoolean(signedPreview); + } +} From d05af2258be55a869d11aa94beb7e960483367d9 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 13 Jun 2022 22:38:09 +0200 Subject: [PATCH 08/20] Fix translation Signed-off-by: Lixfel --- src/de/steamwar/messages/BungeeCore.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index ec98820..2fd155e 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -212,7 +212,7 @@ BAU_MEMBER_TOGGLE_WORLD_EDIT = use WorldEdit BAU_MEMBER_TOGGLE_WORLD = change Settings #ChallengeCommand -CHALLENGE_USAGE=§8/§7challenge §8[§eSpieler§8] +CHALLENGE_USAGE=§8/§7challenge §8[§eplayer§8] CHALLENGE_OFFLINE=§cThe challenged player isn't online. CHALLENGE_SELF=§cSchizophrenia? CHALLENGE_IGNORED=§cThe challenged player has blocked you. @@ -293,7 +293,7 @@ HISTORIC_BROADCAST_HOVER=§afight against §7{1} JOIN_PLAYER_BLOCK=§cYou currently cannot follow this player. #JoinmeCommand -JOINME_USAGE=§8/§7join §8[§eSpieler§8]. +JOINME_USAGE=§8/§7join §8[§eplayer§8]. JOINME_BROADCAST=§7Click §ehere§8 §7to join §e{0} §7on §e{1}§8! JOINME_BROADCAST_HOVER=§aJoin player JOINME_PLAYER_OFFLINE=§cThis player is offline. From 533f0a4269dedcf943b6922854799acd31a32c05 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 14 Jun 2022 08:37:32 +0200 Subject: [PATCH 09/20] Fix copyright Signed-off-by: Lixfel --- .../network/BungeeNetworkHandler.java | 19 ++++++++++++++++ .../bungeecore/network/NetworkReceiver.java | 19 ++++++++++++++++ .../bungeecore/network/NetworkSender.java | 22 ++++++++++++++++--- 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/src/de/steamwar/bungeecore/network/BungeeNetworkHandler.java b/src/de/steamwar/bungeecore/network/BungeeNetworkHandler.java index 6e5ff6c..1cc4854 100644 --- a/src/de/steamwar/bungeecore/network/BungeeNetworkHandler.java +++ b/src/de/steamwar/bungeecore/network/BungeeNetworkHandler.java @@ -1,3 +1,22 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2022 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package de.steamwar.bungeecore.network; import de.steamwar.bungeecore.network.handlers.*; diff --git a/src/de/steamwar/bungeecore/network/NetworkReceiver.java b/src/de/steamwar/bungeecore/network/NetworkReceiver.java index 97a9b7c..ee2e000 100644 --- a/src/de/steamwar/bungeecore/network/NetworkReceiver.java +++ b/src/de/steamwar/bungeecore/network/NetworkReceiver.java @@ -1,3 +1,22 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2022 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package de.steamwar.bungeecore.network; import de.steamwar.bungeecore.BungeeCore; diff --git a/src/de/steamwar/bungeecore/network/NetworkSender.java b/src/de/steamwar/bungeecore/network/NetworkSender.java index 050225f..d683f4a 100644 --- a/src/de/steamwar/bungeecore/network/NetworkSender.java +++ b/src/de/steamwar/bungeecore/network/NetworkSender.java @@ -1,3 +1,22 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2022 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package de.steamwar.bungeecore.network; import de.steamwar.network.packets.NetworkPacket; @@ -5,9 +24,6 @@ import lombok.SneakyThrows; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; -import java.io.ByteArrayOutputStream; -import java.io.ObjectOutputStream; - public class NetworkSender { @SneakyThrows From 571fa8c7d12738704c0a069fb9faa8b5913c25bc Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 14 Jun 2022 08:56:09 +0200 Subject: [PATCH 10/20] Fix concurrency, fix cast Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/network/NetworkReceiver.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/de/steamwar/bungeecore/network/NetworkReceiver.java b/src/de/steamwar/bungeecore/network/NetworkReceiver.java index ee2e000..628270e 100644 --- a/src/de/steamwar/bungeecore/network/NetworkReceiver.java +++ b/src/de/steamwar/bungeecore/network/NetworkReceiver.java @@ -41,7 +41,7 @@ public class NetworkReceiver extends BasicListener { public static ServerInfo sender; @EventHandler(priority = EventPriority.HIGHEST) - public void onPluginMessage(PluginMessageEvent event) { + public synchronized void onPluginMessage(PluginMessageEvent event) { if (blockedTags.contains(event.getTag()) && !allowedAddresses.contains(((InetSocketAddress) event.getSender().getSocketAddress()).getHostString())) { BungeeCore.log(Level.SEVERE, ((InetSocketAddress) event.getSender().getSocketAddress()).getHostString() + " tried to send a plugin message with tag " + event.getTag()); event.setCancelled(true); @@ -54,7 +54,7 @@ public class NetworkReceiver extends BasicListener { if(!(event.getSender() instanceof Server)) return; - sender = (ServerInfo) event.getSender(); + sender = ((Server) event.getSender()).getInfo(); NetworkPacket.handle(event.getData()); sender = null; } From 07cb11e12b6c82361d960531c23221ebd2a76050 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 14 Jun 2022 09:08:05 +0200 Subject: [PATCH 11/20] Fix SWInventory Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/inventory/SWInventory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/inventory/SWInventory.java b/src/de/steamwar/bungeecore/inventory/SWInventory.java index 1f83b41..dac6be9 100644 --- a/src/de/steamwar/bungeecore/inventory/SWInventory.java +++ b/src/de/steamwar/bungeecore/inventory/SWInventory.java @@ -122,7 +122,7 @@ public class SWInventory { } public void open() { - InventoryPacket inv = new InventoryPacket(title, SteamwarUser.get(player).getId(), size, map(itemMap, (integer, swItem) -> swItem.writeToString(integer).getAsString())); + InventoryPacket inv = new InventoryPacket(title, SteamwarUser.get(player).getId(), size, map(itemMap, (integer, swItem) -> swItem.writeToString(integer).toString())); NetworkSender.send(player, inv); } From b2855856081b6a5f0f84d25c7d72ea433d830c62 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 14 Jun 2022 09:09:59 +0200 Subject: [PATCH 12/20] Fix packet direction Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/network/NetworkSender.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/network/NetworkSender.java b/src/de/steamwar/bungeecore/network/NetworkSender.java index d683f4a..c7109a5 100644 --- a/src/de/steamwar/bungeecore/network/NetworkSender.java +++ b/src/de/steamwar/bungeecore/network/NetworkSender.java @@ -28,7 +28,7 @@ public class NetworkSender { @SneakyThrows public static void send(ProxiedPlayer player, NetworkPacket packet) { - player.sendData("sw:bridge", packet.serialize()); + player.getServer().sendData("sw:bridge", packet.serialize()); } public static void send(ServerInfo serverInfo, NetworkPacket packet) { From 7aadaa2df37b8ab36e519d9446efb0d608780dbf Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 14 Jun 2022 09:32:43 +0200 Subject: [PATCH 13/20] Fix communication Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/BungeeCore.java | 2 ++ src/de/steamwar/bungeecore/commands/TeamCommand.java | 4 +--- src/de/steamwar/bungeecore/network/NetworkReceiver.java | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index 40b8399..5cd415e 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -24,6 +24,7 @@ import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; import de.steamwar.bungeecore.commands.*; import de.steamwar.bungeecore.listeners.*; import de.steamwar.bungeecore.listeners.mods.*; +import de.steamwar.bungeecore.network.BungeeNetworkHandler; import de.steamwar.bungeecore.network.NetworkReceiver; import de.steamwar.bungeecore.sql.*; import net.md_5.bungee.api.ChatMessageType; @@ -157,6 +158,7 @@ public class BungeeCore extends Plugin { new EventStarter(); new SessionManager(); new NetworkReceiver(); + BungeeNetworkHandler.register(); new TablistManager(); new SettingsChangedListener(); diff --git a/src/de/steamwar/bungeecore/commands/TeamCommand.java b/src/de/steamwar/bungeecore/commands/TeamCommand.java index f5aab33..a6d814c 100644 --- a/src/de/steamwar/bungeecore/commands/TeamCommand.java +++ b/src/de/steamwar/bungeecore/commands/TeamCommand.java @@ -25,9 +25,7 @@ import de.steamwar.bungeecore.inventory.SWItem; import de.steamwar.bungeecore.inventory.SWListInv; import de.steamwar.bungeecore.sql.*; import de.steamwar.messages.ChatSender; -import io.netty.channel.ConnectTimeoutException; import net.md_5.bungee.BungeeCord; -import net.md_5.bungee.UserConnection; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; @@ -660,7 +658,7 @@ public class TeamCommand extends BasicCommand { Message.send("TEAM_SERVER_SET", player); } - private static boolean isLocalhost(InetAddress addr) { + public static boolean isLocalhost(InetAddress addr) { // Check if the address is a valid special local or loop back if (addr.isAnyLocalAddress() || addr.isLoopbackAddress()) return true; diff --git a/src/de/steamwar/bungeecore/network/NetworkReceiver.java b/src/de/steamwar/bungeecore/network/NetworkReceiver.java index 628270e..e87c7f0 100644 --- a/src/de/steamwar/bungeecore/network/NetworkReceiver.java +++ b/src/de/steamwar/bungeecore/network/NetworkReceiver.java @@ -20,6 +20,7 @@ package de.steamwar.bungeecore.network; import de.steamwar.bungeecore.BungeeCore; +import de.steamwar.bungeecore.commands.TeamCommand; import de.steamwar.bungeecore.listeners.BasicListener; import de.steamwar.network.packets.NetworkPacket; import net.md_5.bungee.api.config.ServerInfo; @@ -36,18 +37,17 @@ import java.util.logging.Level; public class NetworkReceiver extends BasicListener { private static final List blockedTags = Arrays.asList("bungeecord:main", "BungeeCord", "sw:bridge"); - private static final List allowedAddresses = Arrays.asList("localhost", "127.0.0.1", "0.0.0.0"); public static ServerInfo sender; @EventHandler(priority = EventPriority.HIGHEST) public synchronized void onPluginMessage(PluginMessageEvent event) { - if (blockedTags.contains(event.getTag()) && !allowedAddresses.contains(((InetSocketAddress) event.getSender().getSocketAddress()).getHostString())) { + if (blockedTags.contains(event.getTag()) && !TeamCommand.isLocalhost(((InetSocketAddress) event.getSender().getSocketAddress()).getAddress())) { BungeeCore.log(Level.SEVERE, ((InetSocketAddress) event.getSender().getSocketAddress()).getHostString() + " tried to send a plugin message with tag " + event.getTag()); event.setCancelled(true); return; } - if(!event.getTag().equalsIgnoreCase("sw:bridge")) + if(!event.getTag().equals("sw:bridge")) return; event.setCancelled(true); From bf4f7c6adfe1a3f9b2bd83b18b01bb2eff6eb9d7 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 14 Jun 2022 15:47:11 +0200 Subject: [PATCH 14/20] Add ServerMetaInfo --- CommonCore | 2 +- .../bungeecore/network/NetworkReceiver.java | 9 ++--- .../bungeecore/network/ServerMetaInfo.java | 36 +++++++++++++++++++ .../network/handlers/FightInfoHandler.java | 3 +- .../network/handlers/ImALobbyHandler.java | 4 +-- .../handlers/InventoryCallbackHandler.java | 4 ++- 6 files changed, 46 insertions(+), 12 deletions(-) create mode 100644 src/de/steamwar/bungeecore/network/ServerMetaInfo.java diff --git a/CommonCore b/CommonCore index 492894c..c96efa9 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit 492894ca8d41ee0bde4dcb9d520db5f7478c50c7 +Subproject commit c96efa9a50ae8c030f4543768239613d5e72be79 diff --git a/src/de/steamwar/bungeecore/network/NetworkReceiver.java b/src/de/steamwar/bungeecore/network/NetworkReceiver.java index e87c7f0..b089141 100644 --- a/src/de/steamwar/bungeecore/network/NetworkReceiver.java +++ b/src/de/steamwar/bungeecore/network/NetworkReceiver.java @@ -23,7 +23,6 @@ import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.commands.TeamCommand; import de.steamwar.bungeecore.listeners.BasicListener; import de.steamwar.network.packets.NetworkPacket; -import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.Server; import net.md_5.bungee.api.event.PluginMessageEvent; import net.md_5.bungee.event.EventHandler; @@ -38,10 +37,8 @@ public class NetworkReceiver extends BasicListener { private static final List blockedTags = Arrays.asList("bungeecord:main", "BungeeCord", "sw:bridge"); - public static ServerInfo sender; - @EventHandler(priority = EventPriority.HIGHEST) - public synchronized void onPluginMessage(PluginMessageEvent event) { + public void onPluginMessage(PluginMessageEvent event) { if (blockedTags.contains(event.getTag()) && !TeamCommand.isLocalhost(((InetSocketAddress) event.getSender().getSocketAddress()).getAddress())) { BungeeCore.log(Level.SEVERE, ((InetSocketAddress) event.getSender().getSocketAddress()).getHostString() + " tried to send a plugin message with tag " + event.getTag()); event.setCancelled(true); @@ -54,8 +51,6 @@ public class NetworkReceiver extends BasicListener { if(!(event.getSender() instanceof Server)) return; - sender = ((Server) event.getSender()).getInfo(); - NetworkPacket.handle(event.getData()); - sender = null; + NetworkPacket.handle(new ServerMetaInfo(((Server) event.getSender()).getInfo()), event.getData()); } } diff --git a/src/de/steamwar/bungeecore/network/ServerMetaInfo.java b/src/de/steamwar/bungeecore/network/ServerMetaInfo.java new file mode 100644 index 0000000..5f38da1 --- /dev/null +++ b/src/de/steamwar/bungeecore/network/ServerMetaInfo.java @@ -0,0 +1,36 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bungeecore.network; + +import de.steamwar.network.packets.MetaInfos; +import net.md_5.bungee.api.config.ServerInfo; + +public class ServerMetaInfo implements MetaInfos { + + private ServerInfo sender; + + public ServerMetaInfo(ServerInfo sender) { + this.sender = sender; + } + + public ServerInfo getSender() { + return sender; + } +} diff --git a/src/de/steamwar/bungeecore/network/handlers/FightInfoHandler.java b/src/de/steamwar/bungeecore/network/handlers/FightInfoHandler.java index a4b6367..2c98de0 100644 --- a/src/de/steamwar/bungeecore/network/handlers/FightInfoHandler.java +++ b/src/de/steamwar/bungeecore/network/handlers/FightInfoHandler.java @@ -22,6 +22,7 @@ package de.steamwar.bungeecore.network.handlers; import de.steamwar.bungeecore.listeners.TablistManager; import de.steamwar.bungeecore.network.NetworkReceiver; import de.steamwar.bungeecore.network.NetworkSender; +import de.steamwar.bungeecore.network.ServerMetaInfo; import de.steamwar.network.packets.PacketHandler; import de.steamwar.network.packets.common.FightInfoPacket; import net.md_5.bungee.api.config.ServerInfo; @@ -45,7 +46,7 @@ public class FightInfoHandler extends PacketHandler { @Handler public void handle(FightInfoPacket packet) { - ServerInfo info = NetworkReceiver.sender; + ServerInfo info = ((ServerMetaInfo) packet.getMetaInfos()).getSender(); FightInfoPacket lobbyPacket = packet.withServerName(info.getName()); diff --git a/src/de/steamwar/bungeecore/network/handlers/ImALobbyHandler.java b/src/de/steamwar/bungeecore/network/handlers/ImALobbyHandler.java index 54ce65f..82ff82f 100644 --- a/src/de/steamwar/bungeecore/network/handlers/ImALobbyHandler.java +++ b/src/de/steamwar/bungeecore/network/handlers/ImALobbyHandler.java @@ -19,7 +19,7 @@ package de.steamwar.bungeecore.network.handlers; -import de.steamwar.bungeecore.network.NetworkReceiver; +import de.steamwar.bungeecore.network.ServerMetaInfo; import de.steamwar.network.packets.PacketHandler; import de.steamwar.network.packets.client.ImALobbyPacket; @@ -27,6 +27,6 @@ public class ImALobbyHandler extends PacketHandler { @Handler public void handle(ImALobbyPacket packet) { - FightInfoHandler.addLobby(NetworkReceiver.sender); + FightInfoHandler.addLobby(((ServerMetaInfo) packet.getMetaInfos()).getSender()); } } diff --git a/src/de/steamwar/bungeecore/network/handlers/InventoryCallbackHandler.java b/src/de/steamwar/bungeecore/network/handlers/InventoryCallbackHandler.java index 6110611..03da0f9 100644 --- a/src/de/steamwar/bungeecore/network/handlers/InventoryCallbackHandler.java +++ b/src/de/steamwar/bungeecore/network/handlers/InventoryCallbackHandler.java @@ -24,11 +24,13 @@ import de.steamwar.bungeecore.inventory.InvCallback; import de.steamwar.bungeecore.inventory.SWInventory; import de.steamwar.bungeecore.network.NetworkReceiver; import de.steamwar.bungeecore.network.NetworkSender; +import de.steamwar.bungeecore.network.ServerMetaInfo; import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.network.packets.PacketHandler; import de.steamwar.network.packets.client.InventoryCallbackPacket; import de.steamwar.network.packets.server.CloseInventoryPacket; import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.config.ServerInfo; import java.util.HashMap; import java.util.Map; @@ -44,7 +46,7 @@ public class InventoryCallbackHandler extends PacketHandler { if(!inventoryHashMap.containsKey(owner.getId())) { BungeeCore.send(ProxyServer.getInstance().getPlayer(owner.getUuid()), BungeeCore.CHAT_PREFIX + "§cBitte erneut versuchen. Durch ein Softwareupdate konnte die übliche Aktion nicht durchgeführt werden."); if(type == InventoryCallbackPacket.CallbackType.CLICK) { - NetworkSender.send(NetworkReceiver.sender, new CloseInventoryPacket(owner.getId())); + NetworkSender.send(((ServerMetaInfo) packet.getMetaInfos()).getSender(), new CloseInventoryPacket(owner.getId())); } return; } From a0ae828fbd4cf0a6bb6e8663eda227c2d1785fa4 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 14 Jun 2022 16:18:45 +0200 Subject: [PATCH 15/20] Add SWCommand and corresponding api --- src/de/steamwar/bungeecore/BungeeCore.java | 16 ++ .../steamwar/command/CommandRegistering.java | 37 +++++ src/de/steamwar/command/GuardChecker.java | 30 ++++ src/de/steamwar/command/SWCommand.java | 147 ++++++++++++++++++ src/de/steamwar/command/TypeMapper.java | 29 ++++ src/de/steamwar/command/TypeUtils.java | 36 +++++ .../steamwar/messages/BungeeCore.properties | 3 + .../messages/BungeeCore_de.properties | 2 + 8 files changed, 300 insertions(+) create mode 100644 src/de/steamwar/command/CommandRegistering.java create mode 100644 src/de/steamwar/command/GuardChecker.java create mode 100644 src/de/steamwar/command/SWCommand.java create mode 100644 src/de/steamwar/command/TypeMapper.java create mode 100644 src/de/steamwar/command/TypeUtils.java diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index 5cd415e..216722b 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -27,6 +27,9 @@ import de.steamwar.bungeecore.listeners.mods.*; import de.steamwar.bungeecore.network.BungeeNetworkHandler; import de.steamwar.bungeecore.network.NetworkReceiver; import de.steamwar.bungeecore.sql.*; +import de.steamwar.command.SWCommandUtils; +import de.steamwar.command.SWTypeMapperCreator; +import de.steamwar.command.TypeMapper; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; @@ -42,6 +45,7 @@ import net.md_5.bungee.config.YamlConfiguration; import java.io.File; import java.io.IOException; +import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -67,6 +71,18 @@ public class BungeeCore extends Plugin { @Override public void onEnable(){ + SWCommandUtils.init((SWTypeMapperCreator, CommandSender, Object>) (mapper, tabCompleter) -> new TypeMapper() { + @Override + public Object map(CommandSender commandSender, String[] previousArguments, String s) { + return mapper.apply(s); + } + + @Override + public Collection tabCompletes(CommandSender sender, String[] previousArguments, String s) { + return tabCompleter.apply(sender, s); + } + }); + getProxy().registerChannel("sw:bridge"); getProxy().registerChannel("fabricmodsender:mods"); diff --git a/src/de/steamwar/command/CommandRegistering.java b/src/de/steamwar/command/CommandRegistering.java new file mode 100644 index 0000000..b6a4994 --- /dev/null +++ b/src/de/steamwar/command/CommandRegistering.java @@ -0,0 +1,37 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.command; + +import de.steamwar.bungeecore.BungeeCore; +import lombok.experimental.UtilityClass; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.plugin.Command; + +@UtilityClass +class CommandRegistering { + + static void unregister(Command command) { + ProxyServer.getInstance().getPluginManager().unregisterCommand(command); + } + + static void register(Command command) { + ProxyServer.getInstance().getPluginManager().registerCommand(BungeeCore.get(), command); + } +} diff --git a/src/de/steamwar/command/GuardChecker.java b/src/de/steamwar/command/GuardChecker.java new file mode 100644 index 0000000..06c9110 --- /dev/null +++ b/src/de/steamwar/command/GuardChecker.java @@ -0,0 +1,30 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.command; + +import net.md_5.bungee.api.CommandSender; + +@FunctionalInterface +public interface GuardChecker extends AbstractGuardChecker { + /** + * While guarding the first parameter of the command the parameter s of this method is {@code null} + */ + GuardResult guard(CommandSender commandSender, GuardCheckType guardCheckType, String[] previousArguments, String s); +} diff --git a/src/de/steamwar/command/SWCommand.java b/src/de/steamwar/command/SWCommand.java new file mode 100644 index 0000000..026c74c --- /dev/null +++ b/src/de/steamwar/command/SWCommand.java @@ -0,0 +1,147 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.command; + +import de.steamwar.bungeecore.BungeeCore; +import de.steamwar.messages.ChatSender; +import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.plugin.Command; +import net.md_5.bungee.api.plugin.TabExecutor; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Supplier; +import java.util.logging.Level; + +public class SWCommand extends AbstractSWCommand { + + static { + TypeUtils.init(); + } + + private Command command; + + private List defaultHelpMessages = new ArrayList<>(); + + protected SWCommand(String command) { + super(CommandSender.class, command); + } + + protected SWCommand(String command, String... aliases) { + super(CommandSender.class, command, aliases); + } + + @Override + protected void createAndSafeCommand(String command, String[] aliases) { + this.command = new TabCompletableCommand(command, aliases) { + @Override + public void execute(CommandSender commandSender, String[] strings) { + SWCommand.this.execute(commandSender, null, strings); + } + + @Override + public Iterable onTabComplete(CommandSender commandSender, String[] strings) { + return SWCommand.this.tabComplete(commandSender, null, strings); + } + }; + } + + private abstract static class TabCompletableCommand extends Command implements TabExecutor { + public TabCompletableCommand(String name, String... aliases) { + super(name, null, aliases); + } + } + + @Override + public void unregister() { + CommandRegistering.unregister(this.command); + } + + @Override + public void register() { + CommandRegistering.register(this.command); + } + + @Override + protected void commandSystemError(CommandSender sender, CommandFrameworkException e) { + BungeeCore.get().getLogger().log(Level.SEVERE, e.getMessage(), e); + ChatSender.of(sender).prefixless("COMMAND_SYSTEM_ERROR"); + } + + @Override + protected void commandSystemWarning(Supplier message) { + BungeeCore.get().getLogger().log(Level.WARNING, message); + } + + public void addDefaultHelpMessage(String message) { + defaultHelpMessages.add(message); + } + + @Register(help = true) + private void internalHelp(ProxiedPlayer p, String... args) { + ChatSender chatSender = ChatSender.of(p); + try { + chatSender.prefixless("COMMAND_HELP_HEAD", command.getName()); + defaultHelpMessages.forEach(chatSender::prefixless); + } catch (Exception e) { + BungeeCore.get().getLogger().log(Level.WARNING, "Failed to send help message", e); + return; + } + AtomicInteger atomicInteger = new AtomicInteger(); + if (args.length != 0) { + commandList.forEach(subCommand -> { + List tabCompletes = subCommand.tabComplete(p, args); + if (tabCompletes == null || tabCompletes.isEmpty()) { + atomicInteger.incrementAndGet(); + return; + } + boolean hasTabCompletes = tabCompletes.stream() + .anyMatch(s -> s.toLowerCase().startsWith(args[args.length - 1].toLowerCase())); + if (hasTabCompletes) { + send(chatSender, subCommand); + } else { + atomicInteger.incrementAndGet(); + } + }); + } + if (args.length == 0 || atomicInteger.get() == commandList.size()) { + commandList.forEach(subCommand -> { + if (subCommand.guardChecker == null || subCommand.guardChecker.guard(p, GuardCheckType.TAB_COMPLETE, new String[0], null) == GuardResult.ALLOWED) { + send(chatSender, subCommand); + } + }); + } + } + + private void send(ChatSender chatSender, SubCommand subCommand) { + try { + for (String s : subCommand.description) { + String hover = "§8/§e" + command.getName() + " " + String.join(" ", subCommand.subCommand); + String suggest = "/" + command.getName() + " " + String.join(" ", subCommand.subCommand); + chatSender.prefixless(s, hover, new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, suggest)); + } + } catch (Exception e) { + BungeeCore.get().getLogger().log(Level.WARNING, "Failed to send description of registered method '" + subCommand.method + "' with description '" + subCommand.description + "'", e); + } + } +} diff --git a/src/de/steamwar/command/TypeMapper.java b/src/de/steamwar/command/TypeMapper.java new file mode 100644 index 0000000..1d9cb72 --- /dev/null +++ b/src/de/steamwar/command/TypeMapper.java @@ -0,0 +1,29 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.command; + +import net.md_5.bungee.api.CommandSender; + +public interface TypeMapper extends AbstractTypeMapper { + /** + * The CommandSender can be null! + */ + T map(CommandSender commandSender, String[] previousArguments, String s); +} diff --git a/src/de/steamwar/command/TypeUtils.java b/src/de/steamwar/command/TypeUtils.java new file mode 100644 index 0000000..df779d9 --- /dev/null +++ b/src/de/steamwar/command/TypeUtils.java @@ -0,0 +1,36 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.command; + +import de.steamwar.bungeecore.sql.SteamwarUser; +import lombok.experimental.UtilityClass; +import net.md_5.bungee.BungeeCord; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +import java.util.stream.Collectors; + +@UtilityClass +public class TypeUtils { + + static void init() { + SWCommandUtils.addMapper(ProxiedPlayer.class, SWCommandUtils.createMapper(BungeeCord.getInstance()::getPlayer, (s) -> BungeeCord.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList()))); + SWCommandUtils.addMapper(SteamwarUser.class, SWCommandUtils.createMapper(SteamwarUser::get, s -> BungeeCord.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList()))); + } +} diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 2fd155e..45a4f05 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -1,3 +1,6 @@ +COMMAND_SYSTEM_ERROR = §cError executing the command! +COMMAND_HELP_HEAD=§7---=== (§e{0}§7) ===--- + PREFIX=§eSteam§8War» SPACER= TIMEFORMAT=dd.MM.yyyy HH:mm diff --git a/src/de/steamwar/messages/BungeeCore_de.properties b/src/de/steamwar/messages/BungeeCore_de.properties index f118020..21a7a55 100644 --- a/src/de/steamwar/messages/BungeeCore_de.properties +++ b/src/de/steamwar/messages/BungeeCore_de.properties @@ -1,3 +1,5 @@ +COMMAND_SYSTEM_ERROR = §cFehler beim Ausführen des Befehls! + PREFIX=§eSteam§8War» SPACER= TIMEFORMAT=dd.MM.yyyy HH:mm From 22ef3cd13d4d9b029f2770fce82034d507ae7158 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 14 Jun 2022 18:16:44 +0200 Subject: [PATCH 16/20] Fix some stuff for later use --- src/de/steamwar/command/SWCommand.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/de/steamwar/command/SWCommand.java b/src/de/steamwar/command/SWCommand.java index 026c74c..8e8e9ab 100644 --- a/src/de/steamwar/command/SWCommand.java +++ b/src/de/steamwar/command/SWCommand.java @@ -39,21 +39,24 @@ public class SWCommand extends AbstractSWCommand { TypeUtils.init(); } + private String permission; private Command command; private List defaultHelpMessages = new ArrayList<>(); - protected SWCommand(String command) { + protected SWCommand(String command, String permission) { super(CommandSender.class, command); + this.permission = permission; } - protected SWCommand(String command, String... aliases) { + protected SWCommand(String command, String permission, String... aliases) { super(CommandSender.class, command, aliases); + this.permission = permission; } @Override protected void createAndSafeCommand(String command, String[] aliases) { - this.command = new TabCompletableCommand(command, aliases) { + this.command = new TabCompletableCommand(command, permission, aliases) { @Override public void execute(CommandSender commandSender, String[] strings) { SWCommand.this.execute(commandSender, null, strings); @@ -67,8 +70,8 @@ public class SWCommand extends AbstractSWCommand { } private abstract static class TabCompletableCommand extends Command implements TabExecutor { - public TabCompletableCommand(String name, String... aliases) { - super(name, null, aliases); + public TabCompletableCommand(String name, String permission, String... aliases) { + super(name, permission, aliases); } } From 8a417e32c113a753a36e93a1a66d51749207701b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 14 Jun 2022 18:19:25 +0200 Subject: [PATCH 17/20] Fix some stuff for later use --- src/de/steamwar/command/SWCommand.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/de/steamwar/command/SWCommand.java b/src/de/steamwar/command/SWCommand.java index 8e8e9ab..242ef4d 100644 --- a/src/de/steamwar/command/SWCommand.java +++ b/src/de/steamwar/command/SWCommand.java @@ -44,6 +44,10 @@ public class SWCommand extends AbstractSWCommand { private List defaultHelpMessages = new ArrayList<>(); + protected SWCommand(String command) { + this(command, null); + } + protected SWCommand(String command, String permission) { super(CommandSender.class, command); this.permission = permission; From d83b6564d44a9f0b88df90f96a53f80c878d1ee3 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 14 Jun 2022 19:41:50 +0200 Subject: [PATCH 18/20] CI Rebuild Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/BungeeCore.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index 216722b..8336ea7 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -264,6 +264,7 @@ public class BungeeCore extends Plugin { get().getLogger().log(Level.SEVERE, msg, e); } + private static void loadConfig(){ Configuration config; try{ From 8823368f0da69d15b1f919a30a603f2f65302ef2 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 14 Jun 2022 19:44:18 +0200 Subject: [PATCH 19/20] CI Rebuild Signed-off-by: Lixfel --- CommonCore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CommonCore b/CommonCore index c96efa9..8dbab5b 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit c96efa9a50ae8c030f4543768239613d5e72be79 +Subproject commit 8dbab5b132d2fd84db202d691fd1f817f91579d6 From 8a21d5c93dc13d4e789435d762e7da8460c89568 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 14 Jun 2022 22:53:22 +0200 Subject: [PATCH 20/20] Enable SWTSI again --- src/de/steamwar/bungeecore/commands/TeamCommand.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/TeamCommand.java b/src/de/steamwar/bungeecore/commands/TeamCommand.java index a6d814c..9ae3799 100644 --- a/src/de/steamwar/bungeecore/commands/TeamCommand.java +++ b/src/de/steamwar/bungeecore/commands/TeamCommand.java @@ -564,11 +564,6 @@ public class TeamCommand extends BasicCommand { } private void tp(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){ - if (!user.getUserGroup().isAdminGroup()) { - Message.send("DISABLED", player); - return; - } - if(args.length == 1){ if(notInTeam(player, user)) return; @@ -615,11 +610,6 @@ public class TeamCommand extends BasicCommand { } private void server(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){ - if (!user.getUserGroup().isAdminGroup()) { - Message.send("DISABLED", player); - return; - } - if(notLeader(player, user, team)) return; if (user.isPunishedWithMessage(ChatSender.of(player), Punishment.PunishmentType.NoTeamServer)) {