From 8d6c499cd131cf3a7290a13ba0049c8bb2cb540c Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 31 May 2021 08:01:21 +0200 Subject: [PATCH 1/7] Storing replays in the database --- .../src/de/steamwar/sql/EventFight.java | 5 +++ .../src/de/steamwar/sql/Fight.java | 37 ++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/EventFight.java b/SpigotCore_Main/src/de/steamwar/sql/EventFight.java index 8d5bb86..5b5d4f5 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/EventFight.java +++ b/SpigotCore_Main/src/de/steamwar/sql/EventFight.java @@ -57,6 +57,11 @@ public class EventFight { SQL.update("UPDATE EventFight SET Ergebnis = ? WHERE FightID = ?", winner, fightID); } + public void setFight(int fight){ + //Fight.FightID, not EventFight.FightID + SQL.update("UPDATE EventFight SET Fight = ? WHERE FightID = ?", fight, fightID); + } + public int getTeamBlue() { return teamBlue; } diff --git a/SpigotCore_Main/src/de/steamwar/sql/Fight.java b/SpigotCore_Main/src/de/steamwar/sql/Fight.java index c0448dc..089de5a 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/Fight.java +++ b/SpigotCore_Main/src/de/steamwar/sql/Fight.java @@ -19,6 +19,9 @@ package de.steamwar.sql; +import java.io.InputStream; +import java.io.OutputStream; +import java.sql.Blob; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; @@ -27,8 +30,12 @@ public class Fight { private Fight(){} public static int create(String gamemode, String arena, Timestamp starttime, int duration, int blueleader, int redleader, Integer blueschem, Integer redschem, int win, String wincondition){ - SQL.update("INSERT INTO Fight (GameMode, Arena, StartTime, Duration, BlueLeader, RedLeader, BlueSchem, RedSchem, Win, WinCondition) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", - gamemode, arena, starttime, duration, blueleader, redleader,blueschem, redschem, win, wincondition); + return create(gamemode, arena, null, starttime, duration, blueleader, redleader, blueschem, redschem, win, wincondition); + } + + public static int create(String gamemode, String server, String arena, Timestamp starttime, int duration, int blueleader, int redleader, Integer blueschem, Integer redschem, int win, String wincondition){ + SQL.update("INSERT INTO Fight (GameMode, Server, Arena, StartTime, Duration, BlueLeader, RedLeader, BlueSchem, RedSchem, Win, WinCondition) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + gamemode, server, arena, starttime, duration, blueleader, redleader, blueschem, redschem, win, wincondition); ResultSet rs = SQL.select("SELECT LAST_INSERT_ID() AS FightID"); try{ if(!rs.next()) @@ -39,4 +46,30 @@ public class Fight { throw new SecurityException(e); } } + + public static InputStream getReplay(int fightID) { + ResultSet rs = SQL.select("SELECT Replay FROM Fight WHERE FightID = ?", fightID); + try { + rs.next(); + Blob replay = rs.getBlob("Replay"); + if(replay == null) + throw new SecurityException("Replay null"); + return replay.getBinaryStream(); + } catch (SQLException e) { + throw new SecurityException(e); + } + } + + public static OutputStream setReplay(int fightID) { + ResultSet rs = SQL.select("SELECT Replay FROM Fight WHERE FightID = ?", fightID); + try { + rs.next(); + Blob replay = rs.getBlob("Replay"); + if(replay == null) + throw new SecurityException("Replay null"); + return replay.setBinaryStream(1); + } catch (SQLException e) { + throw new SecurityException(e); + } + } } From 77766621f8a2711d53f2cfd8955ba4b25f91975c Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 31 May 2021 08:14:46 +0200 Subject: [PATCH 2/7] Fix replay saving --- SpigotCore_Main/src/de/steamwar/sql/Fight.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/Fight.java b/SpigotCore_Main/src/de/steamwar/sql/Fight.java index 089de5a..7604b12 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/Fight.java +++ b/SpigotCore_Main/src/de/steamwar/sql/Fight.java @@ -20,7 +20,6 @@ package de.steamwar.sql; import java.io.InputStream; -import java.io.OutputStream; import java.sql.Blob; import java.sql.ResultSet; import java.sql.SQLException; @@ -60,16 +59,13 @@ public class Fight { } } - public static OutputStream setReplay(int fightID) { - ResultSet rs = SQL.select("SELECT Replay FROM Fight WHERE FightID = ?", fightID); + public static void setReplay(int fightID, byte[] data) { + Blob blob = SQL.blob(); try { - rs.next(); - Blob replay = rs.getBlob("Replay"); - if(replay == null) - throw new SecurityException("Replay null"); - return replay.setBinaryStream(1); + blob.setBytes(1, data); } catch (SQLException e) { throw new SecurityException(e); } + SQL.update("UPDATE Fight SET Replay = ? WHERE FightID = ?", blob, fightID); } } From 35bbb2e450a1a5ff472a5f2b8210077a42e2a8a9 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 30 Jul 2021 18:04:38 +0200 Subject: [PATCH 3/7] Trigger build --- SpigotCore_Main/src/de/steamwar/sql/UserConfig.java | 1 - 1 file changed, 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/UserConfig.java b/SpigotCore_Main/src/de/steamwar/sql/UserConfig.java index b7a87c3..7c87302 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/UserConfig.java +++ b/SpigotCore_Main/src/de/steamwar/sql/UserConfig.java @@ -64,5 +64,4 @@ public class UserConfig { public static void removePlayerConfig(int id, String config) { SQL.update("DELETE FROM UserConfig WHERE User = ? AND Config = ?", id, config); } - } From 31550da8debefc89bd56782836acaf26612fa61f Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 30 Jul 2021 18:05:24 +0200 Subject: [PATCH 4/7] Trigger build --- SpigotCore_Main/src/de/steamwar/command/TypeMapper.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/TypeMapper.java b/SpigotCore_Main/src/de/steamwar/command/TypeMapper.java index c0c160c..dce1882 100644 --- a/SpigotCore_Main/src/de/steamwar/command/TypeMapper.java +++ b/SpigotCore_Main/src/de/steamwar/command/TypeMapper.java @@ -29,7 +29,8 @@ public interface TypeMapper { } // For backwards compatibility, can be removed later on - @Deprecated(since = "Use the other map Function without calling super!") + // SINCE="Use the other map Function without calling super!" + @Deprecated default T map(String[] previousArguments, String s) { throw new SecurityException(); } From a685088e076c2f56b064834b300f98eadb60e45b Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 21 Aug 2021 11:14:46 +0200 Subject: [PATCH 5/7] Lobby preparation: FightState + ImALobby --- .../de/steamwar/comms/PacketIdManager.java | 16 +- .../comms/packets/FightInfoPacket.java | 174 ++++++++++++++++++ .../comms/packets/ImALobbyPacket.java | 36 ++++ 3 files changed, 220 insertions(+), 6 deletions(-) create mode 100644 SpigotCore_Main/src/de/steamwar/comms/packets/FightInfoPacket.java create mode 100644 SpigotCore_Main/src/de/steamwar/comms/packets/ImALobbyPacket.java diff --git a/SpigotCore_Main/src/de/steamwar/comms/PacketIdManager.java b/SpigotCore_Main/src/de/steamwar/comms/PacketIdManager.java index b326674..f7b71e4 100644 --- a/SpigotCore_Main/src/de/steamwar/comms/PacketIdManager.java +++ b/SpigotCore_Main/src/de/steamwar/comms/PacketIdManager.java @@ -20,14 +20,18 @@ package de.steamwar.comms; public class PacketIdManager { + private PacketIdManager(){} //0x0(X) Standalone Packets - public final static byte PING_PACKET = 0x01; - public final static byte TABLIST_NAME = 0x02; + public static final byte PING_PACKET = 0x01; + public static final byte TABLIST_NAME = 0x02; public static final byte PREPARE_SCHEM = 0x03; - public final static byte BAUMEMBER_UPDATE = 0x04; + public static final byte BAUMEMBER_UPDATE = 0x04; //0x1(X) Bungee Inventory - public final static byte INVENTORY_PACKET = 0x10; - public final static byte INVENTORY_CALLBACK_PACKET = 0x11; - public final static byte INVENTORY_CLOSE_PACKET = 0x12; + 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; } diff --git a/SpigotCore_Main/src/de/steamwar/comms/packets/FightInfoPacket.java b/SpigotCore_Main/src/de/steamwar/comms/packets/FightInfoPacket.java new file mode 100644 index 0000000..54b9498 --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/comms/packets/FightInfoPacket.java @@ -0,0 +1,174 @@ +/* + 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.comms.packets; + +import com.google.common.io.ByteArrayDataInput; +import com.google.common.io.ByteArrayDataOutput; +import de.steamwar.comms.PacketIdManager; + +import java.util.ArrayList; +import java.util.List; + +public class FightInfoPacket extends SpigotPacket { + + private final String serverName; // Name of the Server, might be changed by Bungee + 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 getName() { + 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 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; + } + + 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/SpigotCore_Main/src/de/steamwar/comms/packets/ImALobbyPacket.java b/SpigotCore_Main/src/de/steamwar/comms/packets/ImALobbyPacket.java new file mode 100644 index 0000000..dbe7c0a --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/comms/packets/ImALobbyPacket.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.comms.packets; + +import com.google.common.io.ByteArrayDataOutput; +import de.steamwar.comms.PacketIdManager; + +public class ImALobbyPacket extends SpigotPacket { + + @Override + public int getName() { + return PacketIdManager.I_AM_A_LOBBY; + } + + @Override + public void writeVars(ByteArrayDataOutput byteArrayDataOutput) { + //no content + } +} From a6a5499d0c55bbc880fb9db3e6adc27eef16ffcb Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 23 Aug 2021 18:52:40 +0200 Subject: [PATCH 6/7] Schematic inputstream api --- .../src/de/steamwar/sql/Schematic.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/Schematic.java b/SpigotCore_Main/src/de/steamwar/sql/Schematic.java index dbdee0f..417fb1e 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/Schematic.java +++ b/SpigotCore_Main/src/de/steamwar/sql/Schematic.java @@ -182,21 +182,28 @@ public class Schematic { return true; } - public Clipboard load() throws IOException, NoClipboardException { + public InputStream schemData() throws IOException { ResultSet rs = SQL.select("SELECT SchemData FROM Schematic WHERE SchemID = ?", schemID); try { rs.next(); Blob schemData = rs.getBlob("SchemData"); if(schemData == null) throw new IOException("SchemData is null"); - InputStream is = schemData.getBinaryStream(); - return VersionedCallable.call(new VersionedCallable<>(() -> Schematic_8.getClipboard(is, schemFormat), 8), - new VersionedCallable<>(() -> Schematic_14.getClipboard(is, schemFormat), 14)); + return schemData.getBinaryStream(); } catch (SQLException e) { throw new IOException(e); } } + public static Clipboard clipboardFromStream(InputStream is, boolean schemFormat) { + return VersionedCallable.call(new VersionedCallable<>(() -> Schematic_8.getClipboard(is, schemFormat), 8), + new VersionedCallable<>(() -> Schematic_14.getClipboard(is, schemFormat), 14)); + } + + public Clipboard load() throws IOException, NoClipboardException { + return clipboardFromStream(schemData(), schemFormat); + } + public void loadToPlayer(Player player) throws IOException, NoClipboardException { ResultSet rs = SQL.select("SELECT SchemData FROM Schematic WHERE SchemID = ?", schemID); try { From c032baf879bf75dba9a2cbc3bfbb1529c9714271 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 24 Aug 2021 07:50:14 +0200 Subject: [PATCH 7/7] Uncompressed schem api --- .../src/de/steamwar/sql/Schematic_14.java | 5 ++--- .../src/de/steamwar/sql/Schematic_8.java | 6 +++--- .../src/de/steamwar/sql/Schematic.java | 18 +++++------------- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/SpigotCore_14/src/de/steamwar/sql/Schematic_14.java b/SpigotCore_14/src/de/steamwar/sql/Schematic_14.java index 3e3164f..255530f 100644 --- a/SpigotCore_14/src/de/steamwar/sql/Schematic_14.java +++ b/SpigotCore_14/src/de/steamwar/sql/Schematic_14.java @@ -54,7 +54,6 @@ import java.io.IOException; import java.io.InputStream; import java.util.*; import java.util.stream.Collectors; -import java.util.zip.GZIPInputStream; import static com.google.common.base.Preconditions.checkNotNull; @@ -111,9 +110,9 @@ class Schematic_14 { static Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException { try { if(schemFormat){ - return new SpongeSchematicReader(new NBTInputStream(new GZIPInputStream(is))).read(); + return new SpongeSchematicReader(new NBTInputStream(is)).read(); }else{ - return new MCEditSchematicReader(new NBTInputStream(new GZIPInputStream(is))).read(); + return new MCEditSchematicReader(new NBTInputStream(is)).read(); } } catch (NullPointerException e) { throw new NoClipboardException(); diff --git a/SpigotCore_8/src/de/steamwar/sql/Schematic_8.java b/SpigotCore_8/src/de/steamwar/sql/Schematic_8.java index 87afb82..29974ab 100644 --- a/SpigotCore_8/src/de/steamwar/sql/Schematic_8.java +++ b/SpigotCore_8/src/de/steamwar/sql/Schematic_8.java @@ -32,6 +32,7 @@ import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader; +import com.sk89q.worldedit.extent.clipboard.io.SchematicReader; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.world.registry.WorldData; @@ -47,7 +48,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.stream.Collectors; -import java.util.zip.GZIPInputStream; class Schematic_8 { private Schematic_8(){} @@ -88,9 +88,9 @@ class Schematic_8 { static Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException { if(schemFormat) - return new SpongeSchematicReader(new NBTInputStream(new GZIPInputStream(is))).read(WorldEdit.getInstance().getServer().getWorlds().get(0).getWorldData()); + return new SpongeSchematicReader(new NBTInputStream(is)).read(WorldEdit.getInstance().getServer().getWorlds().get(0).getWorldData()); else - return ClipboardFormat.SCHEMATIC.getReader(is).read(WorldEdit.getInstance().getServer().getWorlds().get(0).getWorldData()); + return new SchematicReader(new NBTInputStream(is)).read(WorldEdit.getInstance().getServer().getWorlds().get(0).getWorldData()); } private static WorldEditPlugin getWorldEditPlugin() { diff --git a/SpigotCore_Main/src/de/steamwar/sql/Schematic.java b/SpigotCore_Main/src/de/steamwar/sql/Schematic.java index 417fb1e..a7d8c45 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/Schematic.java +++ b/SpigotCore_Main/src/de/steamwar/sql/Schematic.java @@ -32,6 +32,7 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import java.util.UUID; +import java.util.zip.GZIPInputStream; public class Schematic { @@ -189,7 +190,7 @@ public class Schematic { Blob schemData = rs.getBlob("SchemData"); if(schemData == null) throw new IOException("SchemData is null"); - return schemData.getBinaryStream(); + return new GZIPInputStream(schemData.getBinaryStream()); } catch (SQLException e) { throw new IOException(e); } @@ -205,18 +206,9 @@ public class Schematic { } public void loadToPlayer(Player player) throws IOException, NoClipboardException { - ResultSet rs = SQL.select("SELECT SchemData FROM Schematic WHERE SchemID = ?", schemID); - try { - rs.next(); - Blob blob = rs.getBlob("SchemData"); - if(blob == null) - throw new NoClipboardException(); - InputStream is = blob.getBinaryStream(); - VersionedRunnable.call(new VersionedRunnable(() -> Schematic_8.setPlayerClipboard(player, is, schemFormat), 8), - new VersionedRunnable(() -> Schematic_14.setPlayerClipboard(player, is, schemFormat), 14)); - } catch (SQLException e) { - throw new IOException(e); - } + InputStream is = schemData(); + VersionedRunnable.call(new VersionedRunnable(() -> Schematic_8.setPlayerClipboard(player, is, schemFormat), 8), + new VersionedRunnable(() -> Schematic_14.setPlayerClipboard(player, is, schemFormat), 14)); } public void saveOldFormatFromPlayer(Player player) throws IOException, NoClipboardException {