diff --git a/SpigotCore_Main/src/de/steamwar/comms/PacketIdManager.java b/SpigotCore_Main/src/de/steamwar/comms/PacketIdManager.java index d4e85a2..317ed7b 100644 --- a/SpigotCore_Main/src/de/steamwar/comms/PacketIdManager.java +++ b/SpigotCore_Main/src/de/steamwar/comms/PacketIdManager.java @@ -35,4 +35,5 @@ public class PacketIdManager { //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; } diff --git a/SpigotCore_Main/src/de/steamwar/comms/packets/FightEndsPacket.java b/SpigotCore_Main/src/de/steamwar/comms/packets/FightEndsPacket.java new file mode 100644 index 0000000..fd51d74 --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/comms/packets/FightEndsPacket.java @@ -0,0 +1,73 @@ +/* + * 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 lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.List; + +@AllArgsConstructor +@Getter +public class FightEndsPacket extends SpigotPacket { + + private byte win; + private int blueSchem; + private int redSchem; + private List bluePlayers; + private List redPlayers; + + public FightEndsPacket(ByteArrayDataInput byteArrayDataInput) { + win = byteArrayDataInput.readByte(); + blueSchem = byteArrayDataInput.readInt(); + redSchem = byteArrayDataInput.readInt(); + int blueSize = byteArrayDataInput.readInt(); + for (int i = 0; i < blueSize; i++) { + bluePlayers.add(byteArrayDataInput.readInt()); + } + int redSize = byteArrayDataInput.readInt(); + for (int i = 0; i < redSize; i++) { + redPlayers.add(byteArrayDataInput.readInt()); + } + } + + @Override + public int getName() { + 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); + } + } +} diff --git a/SpigotCore_Main/src/de/steamwar/sql/Elo.java b/SpigotCore_Main/src/de/steamwar/sql/Elo.java deleted file mode 100644 index 8eeeab7..0000000 --- a/SpigotCore_Main/src/de/steamwar/sql/Elo.java +++ /dev/null @@ -1,32 +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.sql; - -public class Elo { - private Elo(){} - - public static int getElo(int userId, String gameMode){ - return Provider.impl.getElo(userId, gameMode); - } - - public static void setElo(int userId, String gameMode, int elo){ - Provider.impl.setElo(userId, gameMode, elo); - } -} diff --git a/SpigotCore_Main/src/de/steamwar/sql/Provider.java b/SpigotCore_Main/src/de/steamwar/sql/Provider.java index 56737f5..21413d8 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/Provider.java +++ b/SpigotCore_Main/src/de/steamwar/sql/Provider.java @@ -39,9 +39,6 @@ public interface Provider { List getLastDeclinedOfNode(int node); List getLastDelined(int schemOwner); - int getElo(int userId, String gameMode); - void setElo(int userId, String gameMode, int elo); - Event getEvent(int eventID); EventFight getEventFight(int fightID); void setEventFightResult(EventFight fight, int winner); diff --git a/SpigotCore_Main/src/de/steamwar/sql/SQLProvider.java b/SpigotCore_Main/src/de/steamwar/sql/SQLProvider.java index 916f460..68839c5 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SQLProvider.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SQLProvider.java @@ -78,22 +78,6 @@ public class SQLProvider implements Provider { return new CheckedSchematic(rs.getInt("NodeId"), rs.getInt("Validator"), rs.getTimestamp("StartTime"), rs.getTimestamp("EndTime"), rs.getString("DeclineReason")); } - private static final Statement getElo = new Statement("SELECT Elo FROM Elo WHERE UserID = ? AND GameMode = ?"); - @Override - public int getElo(int userId, String gameMode) { - return getElo.select(rs -> { - if(rs.next()) - return rs.getInt("Elo"); - return 1000; - }, userId, gameMode); - } - - private static final Statement setElo = new Statement("INSERT INTO Elo (UserID, GameMode, Elo) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE Elo = VALUES(Elo)"); - @Override - public void setElo(int userId, String gameMode, int elo) { - setElo.update(userId, gameMode, elo); - } - private static final Statement getEvent = new Statement("SELECT * FROM Event WHERE EventID = ?"); @Override public Event getEvent(int eventID) { diff --git a/SpigotCore_Main/src/de/steamwar/sql/StandaloneProvider.java b/SpigotCore_Main/src/de/steamwar/sql/StandaloneProvider.java index 9c422f3..5e8f0c3 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/StandaloneProvider.java +++ b/SpigotCore_Main/src/de/steamwar/sql/StandaloneProvider.java @@ -64,14 +64,6 @@ public class StandaloneProvider implements Provider { return new ArrayList<>(); } - @Override - public int getElo(int userId, String gameMode) { - return 1000; - } - - @Override - public void setElo(int userId, String gameMode, int elo) {} - @Override public Event getEvent(int eventID) { return new Event(eventID, "DummyEvent", Timestamp.from(Instant.now()), Timestamp.from(Instant.now()), 6, false, false);