From cbc1dd6505038fb5e7de1a6194c99e0bce6d97a2 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 1 Apr 2022 10:55:29 +0200 Subject: [PATCH 01/18] Update some stuff --- .../bungeecore/comms/handlers/FightEndsHandler.java | 8 ++++---- src/de/steamwar/bungeecore/sql/UserElo.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index 0dda622..b563a7f 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -23,10 +23,7 @@ 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.SchemElo; -import de.steamwar.bungeecore.sql.SchematicNode; -import de.steamwar.bungeecore.sql.SchematicType; -import de.steamwar.bungeecore.sql.UserElo; +import de.steamwar.bungeecore.sql.*; import net.md_5.bungee.api.config.ServerInfo; import java.util.List; @@ -66,6 +63,8 @@ public class FightEndsHandler implements SpigotHandler { blueResult = 0; } + // TODO: Implement hourly unranked when against same team maybe half hourly + int blueSchemElo = SchemElo.getElo(fightEndsPacket.getBlueSchem()); int redSchemElo = SchemElo.getElo(fightEndsPacket.getRedSchem()); @@ -84,6 +83,7 @@ public class FightEndsHandler implements SpigotHandler { double winTeamExpectation = 1 / (1 + Math.pow(10, (eloTeamEnemy - eloTeamOwn) / 600f)); for (int player : players) { int playerElo = UserElo.getEloOrDefault(player, gameMode); + int fights = UserElo.getFightsOfSeason(player, gameMode); UserElo.setElo(player, gameMode, (int) Math.round(playerElo + K * (result - winTeamExpectation))); } } diff --git a/src/de/steamwar/bungeecore/sql/UserElo.java b/src/de/steamwar/bungeecore/sql/UserElo.java index 6740966..efa0078 100644 --- a/src/de/steamwar/bungeecore/sql/UserElo.java +++ b/src/de/steamwar/bungeecore/sql/UserElo.java @@ -56,7 +56,7 @@ public class UserElo { }, userID, gameMode, Season.getSeason())); } - private static int getFightsOfSeason(int userID, String gameMode) { + public static int getFightsOfSeason(int userID, String gameMode) { return fightsOfSeason.select(rs -> { if (rs.next()) return rs.getInt("Fights"); From bbd2b1950b22473d9ad671f15529415c84f30560 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 1 Apr 2022 12:05:41 +0200 Subject: [PATCH 02/18] Update FightEndsHandler --- .../steamwar/bungeecore/comms/handlers/FightEndsHandler.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index b563a7f..b0f5962 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -84,7 +84,8 @@ public class FightEndsHandler implements SpigotHandler { for (int player : players) { int playerElo = UserElo.getEloOrDefault(player, gameMode); int fights = UserElo.getFightsOfSeason(player, gameMode); - UserElo.setElo(player, gameMode, (int) Math.round(playerElo + K * (result - winTeamExpectation))); + double multiplier = Math.max(1.2 - (fights / 200.0), 0.8); + UserElo.setElo(player, gameMode, (int) Math.round(playerElo + K * (result - winTeamExpectation) * multiplier)); } } } From 895ac9843b63dde7caaa2c743578ac7d629b4ed6 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 1 Apr 2022 12:19:56 +0200 Subject: [PATCH 03/18] Update FightEndsHandler --- .../comms/handlers/FightEndsHandler.java | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index b0f5962..47e3f89 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -26,11 +26,15 @@ import de.steamwar.bungeecore.comms.packets.FightEndsPacket; import de.steamwar.bungeecore.sql.*; import net.md_5.bungee.api.config.ServerInfo; +import java.sql.Timestamp; +import java.time.Instant; import java.util.List; +import java.util.stream.Collectors; public class FightEndsHandler implements SpigotHandler { private int K = 20; + private long fightRange = 1000 /* Milliseconds */ * 60 /* Seconds */ * 30 /* Minutes */; @Override public void handle(ByteArrayDataInput in, ServerInfo info) { @@ -63,7 +67,9 @@ public class FightEndsHandler implements SpigotHandler { blueResult = 0; } - // TODO: Implement hourly unranked when against same team maybe half hourly + if (teamComboExistedAlready(fightEndsPacket.getBluePlayers(), fightEndsPacket.getRedPlayers(), fightEndsPacket.getGameMode())) { + return; + } int blueSchemElo = SchemElo.getElo(fightEndsPacket.getBlueSchem()); int redSchemElo = SchemElo.getElo(fightEndsPacket.getRedSchem()); @@ -88,4 +94,25 @@ public class FightEndsHandler implements SpigotHandler { UserElo.setElo(player, gameMode, (int) Math.round(playerElo + K * (result - winTeamExpectation) * multiplier)); } } + + private boolean teamComboExistedAlready(List bluePlayers, List redPlayers, String gameMode) { + long time = Timestamp.from(Instant.now()).getTime() - fightRange; + int page = 0; + do { + List fightsPage = Fight.getPage(page, 32); + if (fightsPage.isEmpty()) { + return false; + } + for (Fight fight : fightsPage) { + if (!fight.getGameMode().getSchemType().equals(gameMode)) continue; + if (fight.getStartTime().getTime() < time) return false; + if (fight.getBluePlayers().stream().map(FightPlayer::getUserID).collect(Collectors.toList()).containsAll(bluePlayers)) { + if (fight.getRedPlayers().stream().map(FightPlayer::getUserID).collect(Collectors.toList()).containsAll(redPlayers)) { + return true; + } + } + } + page++; + } while (true); + } } From a26e3994a3871fbaf1da8b81ed1925bd13222766 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 1 Apr 2022 12:23:08 +0200 Subject: [PATCH 04/18] Fix FightEndsHandler --- src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index 47e3f89..f90996f 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -104,7 +104,7 @@ public class FightEndsHandler implements SpigotHandler { return false; } for (Fight fight : fightsPage) { - if (!fight.getGameMode().getSchemType().equals(gameMode)) continue; + if (!gameMode.equals(fight.getGameMode().getSchemType())) continue; if (fight.getStartTime().getTime() < time) return false; if (fight.getBluePlayers().stream().map(FightPlayer::getUserID).collect(Collectors.toList()).containsAll(bluePlayers)) { if (fight.getRedPlayers().stream().map(FightPlayer::getUserID).collect(Collectors.toList()).containsAll(redPlayers)) { From afa9b4e533f65f51d9486384a12d53387dfe6d82 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 1 Apr 2022 12:28:05 +0200 Subject: [PATCH 05/18] Add Replay --- src/de/steamwar/bungeecore/sql/Fight.java | 6 ++--- src/de/steamwar/bungeecore/sql/Replay.java | 31 ++++++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 src/de/steamwar/bungeecore/sql/Replay.java diff --git a/src/de/steamwar/bungeecore/sql/Fight.java b/src/de/steamwar/bungeecore/sql/Fight.java index 514946d..e17dcbf 100644 --- a/src/de/steamwar/bungeecore/sql/Fight.java +++ b/src/de/steamwar/bungeecore/sql/Fight.java @@ -11,7 +11,7 @@ import java.util.stream.Collectors; public class Fight { - private static final Statement getPage = new Statement("SELECT f.FightID, f.GameMode, f.Server, f.StartTime, f.BlueLeader, f.RedLeader, (b.NodeId IS NULL OR b.AllowReplay) AND (r.NodeId IS NULL OR r.AllowReplay) AS ReplayAllowed, f.Win, f.Replay IS NOT NULL AS ReplayExists FROM Fight f LEFT OUTER JOIN SchematicNode b ON f.BlueSchem = b.NodeId LEFT OUTER JOIN SchematicNode r ON f.RedSchem = r.NodeId ORDER BY FightID DESC LIMIT ?, ?"); + private static final Statement getPage = new Statement("SELECT f.FightID, f.GameMode, f.Server, f.StartTime, f.BlueLeader, f.RedLeader, (b.NodeId IS NULL OR b.AllowReplay) AND (r.NodeId IS NULL OR r.AllowReplay) AS ReplayAllowed, f.Win FROM Fight f LEFT OUTER JOIN SchematicNode b ON f.BlueSchem = b.NodeId LEFT OUTER JOIN SchematicNode r ON f.RedSchem = r.NodeId ORDER BY FightID DESC LIMIT ?, ?"); private final int fightID; private final String gameMode; @@ -22,7 +22,6 @@ public class Fight { private final int redLeader; private final int win; - private final boolean replayExists; private final boolean replayAllowed; private final List bluePlayers = new ArrayList<>(); @@ -37,7 +36,6 @@ public class Fight { redLeader = rs.getInt("RedLeader"); replayAllowed = rs.getBoolean("ReplayAllowed"); win = rs.getInt("Win"); - replayExists = rs.getBoolean("ReplayExists"); } private void initPlayers(List fightPlayers) { @@ -118,6 +116,6 @@ public class Fight { } public boolean replayExists() { - return replayExists && getGameMode() != null; + return Replay.hasReplay(fightID) && getGameMode() != null; } } diff --git a/src/de/steamwar/bungeecore/sql/Replay.java b/src/de/steamwar/bungeecore/sql/Replay.java new file mode 100644 index 0000000..6c0bab2 --- /dev/null +++ b/src/de/steamwar/bungeecore/sql/Replay.java @@ -0,0 +1,31 @@ +/* + * 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.sql; + +import java.sql.ResultSet; + +public class Replay { + + private static final Statement hasReplay = new Statement("SELECT * FROM Replay WHERE id = ?"); + + public static boolean hasReplay(int id) { + return hasReplay.select(ResultSet::next, id); + } +} From 8ce2b9ab71e354f0a140ec2301da9c0be584a71e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 1 Apr 2022 13:11:48 +0200 Subject: [PATCH 06/18] Fix FightEndsHandler.fightRange --- src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index f90996f..62c7a87 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -34,7 +34,7 @@ import java.util.stream.Collectors; public class FightEndsHandler implements SpigotHandler { private int K = 20; - private long fightRange = 1000 /* Milliseconds */ * 60 /* Seconds */ * 30 /* Minutes */; + private long fightRange = 1000 /* Milliseconds */ * 60 /* Seconds */ * 15L /* Minutes */; @Override public void handle(ByteArrayDataInput in, ServerInfo info) { From b5528a6c602bb74956c2f11a2ee7a1b44cb1270b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 1 Apr 2022 13:26:05 +0200 Subject: [PATCH 07/18] Update some stuff --- .../comms/handlers/FightEndsHandler.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index 62c7a87..9b28bed 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -82,19 +82,26 @@ public class FightEndsHandler implements SpigotHandler { } private void calculateEloOfTeam(int schemId, int eloSchemOwn, int eloSchemEnemy, int eloTeamOwn, int eloTeamEnemy, double result, List players, String gameMode, boolean noPlayerRank) { - double winSchemExpectation = 1 / (1 + Math.pow(10, (eloSchemEnemy - eloSchemOwn) / 600f)); + double winSchemExpectation = calsWinExpectation(eloSchemOwn, eloSchemEnemy); SchemElo.setElo(schemId, (int) Math.round(eloSchemOwn + K * (result - winSchemExpectation))); if (noPlayerRank) return; - double winTeamExpectation = 1 / (1 + Math.pow(10, (eloTeamEnemy - eloTeamOwn) / 600f)); + double winTeamExpectation = calsWinExpectation(eloTeamOwn, eloTeamEnemy); for (int player : players) { int playerElo = UserElo.getEloOrDefault(player, gameMode); int fights = UserElo.getFightsOfSeason(player, gameMode); - double multiplier = Math.max(1.2 - (fights / 200.0), 0.8); - UserElo.setElo(player, gameMode, (int) Math.round(playerElo + K * (result - winTeamExpectation) * multiplier)); + UserElo.setElo(player, gameMode, (int) Math.round(playerElo + getK(fights) * (result - winTeamExpectation))); } } + private double calsWinExpectation(int eloOwn, int eloEnemy) { + return 1 / (1 + Math.pow(10, (eloEnemy - eloOwn) / 600f)); + } + + private double getK(int fights) { + return K * Math.max(1.2 - (fights / 200.0), 0.8); + } + private boolean teamComboExistedAlready(List bluePlayers, List redPlayers, String gameMode) { long time = Timestamp.from(Instant.now()).getTime() - fightRange; int page = 0; From 200c8eb17e5cfef89c0faa73db60bc9ecd1867bb Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 1 Apr 2022 15:13:22 +0200 Subject: [PATCH 08/18] Update some stuff --- .../bungeecore/comms/handlers/FightEndsHandler.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index 9b28bed..9e58dcc 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -28,13 +28,19 @@ import net.md_5.bungee.api.config.ServerInfo; import java.sql.Timestamp; import java.time.Instant; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; public class FightEndsHandler implements SpigotHandler { private int K = 20; - private long fightRange = 1000 /* Milliseconds */ * 60 /* Seconds */ * 15L /* Minutes */; + private long defaultFightRange = 1000 /* Milliseconds */ * 60 /* Seconds */ * 15L /* Minutes */; + private Map fightRanges = new HashMap<>(); + { + fightRanges.put("miniwargear", 1000 /* Milliseconds */ * 60 /* Seconds */ * 10L /* Minutes */); + } @Override public void handle(ByteArrayDataInput in, ServerInfo info) { @@ -103,7 +109,7 @@ public class FightEndsHandler implements SpigotHandler { } private boolean teamComboExistedAlready(List bluePlayers, List redPlayers, String gameMode) { - long time = Timestamp.from(Instant.now()).getTime() - fightRange; + long time = Timestamp.from(Instant.now()).getTime() - fightRanges.getOrDefault(gameMode, defaultFightRange); int page = 0; do { List fightsPage = Fight.getPage(page, 32); From 738189593dd8b97a8b142d0862896755b9295338 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 1 Apr 2022 15:31:45 +0200 Subject: [PATCH 09/18] Update some stuff --- .../bungeecore/comms/handlers/FightEndsHandler.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index 9e58dcc..4f0f2c3 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -31,6 +31,7 @@ import java.time.Instant; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.stream.Collectors; public class FightEndsHandler implements SpigotHandler { @@ -38,6 +39,7 @@ public class FightEndsHandler implements SpigotHandler { private int K = 20; private long defaultFightRange = 1000 /* Milliseconds */ * 60 /* Seconds */ * 15L /* Minutes */; private Map fightRanges = new HashMap<>(); + { fightRanges.put("miniwargear", 1000 /* Milliseconds */ * 60 /* Seconds */ * 10L /* Minutes */); } @@ -73,6 +75,13 @@ public class FightEndsHandler implements SpigotHandler { blueResult = 0; } + Set teamsIds = fightEndsPacket.getBluePlayers().stream().map(SteamwarUser::get).map(SteamwarUser::getTeam).collect(Collectors.toSet()); + for (int redPlayer : fightEndsPacket.getRedPlayers()) { + if (teamsIds.contains(SteamwarUser.get(redPlayer).getTeam())) { + return; + } + } + if (teamComboExistedAlready(fightEndsPacket.getBluePlayers(), fightEndsPacket.getRedPlayers(), fightEndsPacket.getGameMode())) { return; } From c4523521f70b6c02f0bf5086d8755734d3036433 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 1 Apr 2022 15:57:42 +0200 Subject: [PATCH 10/18] Update some stuff --- src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index 4f0f2c3..cda7737 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -114,7 +114,7 @@ public class FightEndsHandler implements SpigotHandler { } private double getK(int fights) { - return K * Math.max(1.2 - (fights / 200.0), 0.8); + return K * Math.max(1.3 - (fights / 200.0), 0.8); } private boolean teamComboExistedAlready(List bluePlayers, List redPlayers, String gameMode) { From c2219dec4e53cbce621181288b97c401806bb9b6 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 4 Apr 2022 18:23:18 +0200 Subject: [PATCH 11/18] Update stuff --- .../bungeecore/comms/handlers/FightEndsHandler.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index cda7737..7392d04 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -128,10 +128,15 @@ public class FightEndsHandler implements SpigotHandler { for (Fight fight : fightsPage) { if (!gameMode.equals(fight.getGameMode().getSchemType())) continue; if (fight.getStartTime().getTime() < time) return false; - if (fight.getBluePlayers().stream().map(FightPlayer::getUserID).collect(Collectors.toList()).containsAll(bluePlayers)) { - if (fight.getRedPlayers().stream().map(FightPlayer::getUserID).collect(Collectors.toList()).containsAll(redPlayers)) { - return true; - } + if (fight.getBluePlayers().stream() + .map(FightPlayer::getUserID) + .collect(Collectors.toList()) + .containsAll(bluePlayers) + && fight.getRedPlayers().stream() + .map(FightPlayer::getUserID) + .collect(Collectors.toList()) + .containsAll(redPlayers)) { + return true; } } page++; From 350ac8b66fc5179deabec9ecca815ca62f0d161a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 4 Apr 2022 20:00:21 +0200 Subject: [PATCH 12/18] Update some stuff --- .../comms/handlers/FightEndsHandler.java | 63 ++++++++++--------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index 7392d04..f86eacf 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -24,18 +24,16 @@ import de.steamwar.bungeecore.ArenaMode; import de.steamwar.bungeecore.comms.SpigotHandler; import de.steamwar.bungeecore.comms.packets.FightEndsPacket; import de.steamwar.bungeecore.sql.*; +import lombok.RequiredArgsConstructor; import net.md_5.bungee.api.config.ServerInfo; -import java.sql.Timestamp; -import java.time.Instant; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; public class FightEndsHandler implements SpigotHandler { + private Map> gameModeGames = new HashMap<>(); + private int K = 20; private long defaultFightRange = 1000 /* Milliseconds */ * 60 /* Seconds */ * 15L /* Minutes */; private Map fightRanges = new HashMap<>(); @@ -82,8 +80,12 @@ public class FightEndsHandler implements SpigotHandler { } } - if (teamComboExistedAlready(fightEndsPacket.getBluePlayers(), fightEndsPacket.getRedPlayers(), fightEndsPacket.getGameMode())) { - return; + try { + if (teamComboExistedAlready(fightEndsPacket.getBluePlayers(), fightEndsPacket.getRedPlayers(), fightEndsPacket.getGameMode())) { + return; + } + } finally { + gameModeGames.computeIfAbsent(fightEndsPacket.getGameMode(), s -> new ArrayList<>()).add(new Game(fightEndsPacket.getBluePlayers(), fightEndsPacket.getRedPlayers())); } int blueSchemElo = SchemElo.getElo(fightEndsPacket.getBlueSchem()); @@ -118,28 +120,27 @@ public class FightEndsHandler implements SpigotHandler { } private boolean teamComboExistedAlready(List bluePlayers, List redPlayers, String gameMode) { - long time = Timestamp.from(Instant.now()).getTime() - fightRanges.getOrDefault(gameMode, defaultFightRange); - int page = 0; - do { - List fightsPage = Fight.getPage(page, 32); - if (fightsPage.isEmpty()) { - return false; - } - for (Fight fight : fightsPage) { - if (!gameMode.equals(fight.getGameMode().getSchemType())) continue; - if (fight.getStartTime().getTime() < time) return false; - if (fight.getBluePlayers().stream() - .map(FightPlayer::getUserID) - .collect(Collectors.toList()) - .containsAll(bluePlayers) - && fight.getRedPlayers().stream() - .map(FightPlayer::getUserID) - .collect(Collectors.toList()) - .containsAll(redPlayers)) { - return true; - } - } - page++; - } while (true); + if (!gameModeGames.containsKey(gameMode)) { + return false; + } + List games = gameModeGames.get(gameMode); + long lifetime = fightRanges.getOrDefault(gameMode, defaultFightRange); + games.removeIf(game -> game.livedMillis() > lifetime); + return games.stream().anyMatch(game -> game.isSame(bluePlayers, redPlayers)); + } + + @RequiredArgsConstructor + private static class Game { + private long time = System.currentTimeMillis(); + private final List bluePlayers; + private final List redPlayers; + + public long livedMillis() { + return System.currentTimeMillis() - time; + } + + public boolean isSame(List bluePlayers, List redPlayers) { + return bluePlayers.containsAll(this.bluePlayers) && redPlayers.containsAll(this.redPlayers); + } } } From 9a0b3a41b909c87a061b56f43e3b86933cdd4ea1 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 6 Apr 2022 16:59:11 +0200 Subject: [PATCH 13/18] Update some stuff --- .../comms/handlers/FightEndsHandler.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index f86eacf..03fae60 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -32,14 +32,18 @@ import java.util.stream.Collectors; public class FightEndsHandler implements SpigotHandler { - private Map> gameModeGames = new HashMap<>(); + private Map> gameModeGames = new HashMap<>(); private int K = 20; + private long defaultFightRange = 1000 /* Milliseconds */ * 60 /* Seconds */ * 15L /* Minutes */; private Map fightRanges = new HashMap<>(); + private long defaultFightCount = 1; + private Map fightCounts = new HashMap<>(); { - fightRanges.put("miniwargear", 1000 /* Milliseconds */ * 60 /* Seconds */ * 10L /* Minutes */); + fightRanges.put("miniwargear", 1000 /* Milliseconds */ * 60 /* Seconds */ * 30L /* Minutes */); + fightCounts.put("miniwargear", 3L); } @Override @@ -73,6 +77,8 @@ public class FightEndsHandler implements SpigotHandler { blueResult = 0; } + // Die nächsten Zeilen filtern ein Fight innerhalb eines Teams nicht gewertet wird, bzw auch wenn nur Teile beider Teams im + // gleichen Team sind dieser ungewertet ist. Set teamsIds = fightEndsPacket.getBluePlayers().stream().map(SteamwarUser::get).map(SteamwarUser::getTeam).collect(Collectors.toSet()); for (int redPlayer : fightEndsPacket.getRedPlayers()) { if (teamsIds.contains(SteamwarUser.get(redPlayer).getTeam())) { @@ -85,7 +91,7 @@ public class FightEndsHandler implements SpigotHandler { return; } } finally { - gameModeGames.computeIfAbsent(fightEndsPacket.getGameMode(), s -> new ArrayList<>()).add(new Game(fightEndsPacket.getBluePlayers(), fightEndsPacket.getRedPlayers())); + gameModeGames.computeIfAbsent(fightEndsPacket.getGameMode(), s -> new LinkedList<>()).add(new Game(fightEndsPacket.getBluePlayers(), fightEndsPacket.getRedPlayers())); } int blueSchemElo = SchemElo.getElo(fightEndsPacket.getBlueSchem()); @@ -126,7 +132,7 @@ public class FightEndsHandler implements SpigotHandler { List games = gameModeGames.get(gameMode); long lifetime = fightRanges.getOrDefault(gameMode, defaultFightRange); games.removeIf(game -> game.livedMillis() > lifetime); - return games.stream().anyMatch(game -> game.isSame(bluePlayers, redPlayers)); + return games.stream().filter(game -> game.isSame(bluePlayers, redPlayers)).count() > fightCounts.getOrDefault(gameMode, defaultFightCount); } @RequiredArgsConstructor From 169d26852c9b902193caa4f231af982fff114769 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 6 Apr 2022 17:01:33 +0200 Subject: [PATCH 14/18] Update some stuff --- .../bungeecore/comms/handlers/FightEndsHandler.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index 03fae60..b9a7492 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -129,9 +129,16 @@ public class FightEndsHandler implements SpigotHandler { if (!gameModeGames.containsKey(gameMode)) { return false; } - List games = gameModeGames.get(gameMode); + LinkedList games = gameModeGames.get(gameMode); long lifetime = fightRanges.getOrDefault(gameMode, defaultFightRange); - games.removeIf(game -> game.livedMillis() > lifetime); + while (!games.isEmpty()) { + Game game = games.getFirst(); + if (game.livedMillis() > lifetime) { + games.removeFirst(); + } else { + break; + } + } return games.stream().filter(game -> game.isSame(bluePlayers, redPlayers)).count() > fightCounts.getOrDefault(gameMode, defaultFightCount); } From 4bdead92b520ef2a02ed3c63d526db7dc48a9ba1 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 9 Apr 2022 21:30:52 +0200 Subject: [PATCH 15/18] Update some stuff --- src/de/steamwar/bungeecore/sql/Fight.java | 2 +- src/de/steamwar/bungeecore/sql/Replay.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/de/steamwar/bungeecore/sql/Fight.java b/src/de/steamwar/bungeecore/sql/Fight.java index e17dcbf..4fd0b7d 100644 --- a/src/de/steamwar/bungeecore/sql/Fight.java +++ b/src/de/steamwar/bungeecore/sql/Fight.java @@ -116,6 +116,6 @@ public class Fight { } public boolean replayExists() { - return Replay.hasReplay(fightID) && getGameMode() != null; + return getGameMode() != null && Replay.hasReplay(fightID); } } diff --git a/src/de/steamwar/bungeecore/sql/Replay.java b/src/de/steamwar/bungeecore/sql/Replay.java index 6c0bab2..188232a 100644 --- a/src/de/steamwar/bungeecore/sql/Replay.java +++ b/src/de/steamwar/bungeecore/sql/Replay.java @@ -23,7 +23,7 @@ import java.sql.ResultSet; public class Replay { - private static final Statement hasReplay = new Statement("SELECT * FROM Replay WHERE id = ?"); + private static final Statement hasReplay = new Statement("SELECT FightID FROM Replay WHERE FightID = ?"); public static boolean hasReplay(int id) { return hasReplay.select(ResultSet::next, id); From 7a48584cbb2d5440b008eb08c8290f0d33b92a2b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 9 Apr 2022 21:36:18 +0200 Subject: [PATCH 16/18] Update some stuff --- src/de/steamwar/bungeecore/sql/Replay.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/sql/Replay.java b/src/de/steamwar/bungeecore/sql/Replay.java index 188232a..a4f2651 100644 --- a/src/de/steamwar/bungeecore/sql/Replay.java +++ b/src/de/steamwar/bungeecore/sql/Replay.java @@ -23,7 +23,7 @@ import java.sql.ResultSet; public class Replay { - private static final Statement hasReplay = new Statement("SELECT FightID FROM Replay WHERE FightID = ?"); + private static final Statement hasReplay = new Statement("SELECT 1 FROM Replay WHERE FightID = ?"); public static boolean hasReplay(int id) { return hasReplay.select(ResultSet::next, id); From fa5d4ad983463e412bf5178adfee9e32388fa4d8 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 9 Apr 2022 22:08:17 +0200 Subject: [PATCH 17/18] Update some stuff --- src/de/steamwar/bungeecore/sql/Fight.java | 6 +++-- src/de/steamwar/bungeecore/sql/Replay.java | 31 ---------------------- 2 files changed, 4 insertions(+), 33 deletions(-) delete mode 100644 src/de/steamwar/bungeecore/sql/Replay.java diff --git a/src/de/steamwar/bungeecore/sql/Fight.java b/src/de/steamwar/bungeecore/sql/Fight.java index 4fd0b7d..e13b787 100644 --- a/src/de/steamwar/bungeecore/sql/Fight.java +++ b/src/de/steamwar/bungeecore/sql/Fight.java @@ -11,7 +11,7 @@ import java.util.stream.Collectors; public class Fight { - private static final Statement getPage = new Statement("SELECT f.FightID, f.GameMode, f.Server, f.StartTime, f.BlueLeader, f.RedLeader, (b.NodeId IS NULL OR b.AllowReplay) AND (r.NodeId IS NULL OR r.AllowReplay) AS ReplayAllowed, f.Win FROM Fight f LEFT OUTER JOIN SchematicNode b ON f.BlueSchem = b.NodeId LEFT OUTER JOIN SchematicNode r ON f.RedSchem = r.NodeId ORDER BY FightID DESC LIMIT ?, ?"); + private static final Statement getPage = new Statement("SELECT f.FightID, f.GameMode, f.Server, f.StartTime, f.BlueLeader, f.RedLeader, (b.NodeId IS NULL OR b.AllowReplay) AND (r.NodeId IS NULL OR r.AllowReplay) AS ReplayAllowed, f.Win, (SELECT COUNT(1) FROM Replay WHERE Replay.FightID = f.FightID) as ReplayAvailable FROM Fight f LEFT OUTER JOIN SchematicNode b ON f.BlueSchem = b.NodeId LEFT OUTER JOIN SchematicNode r ON f.RedSchem = r.NodeId ORDER BY FightID DESC LIMIT ?, ?"); private final int fightID; private final String gameMode; @@ -23,6 +23,7 @@ public class Fight { private final int win; private final boolean replayAllowed; + private final boolean replayAvailable; private final List bluePlayers = new ArrayList<>(); private final List redPlayers = new ArrayList<>(); @@ -35,6 +36,7 @@ public class Fight { blueLeader = rs.getInt("BlueLeader"); redLeader = rs.getInt("RedLeader"); replayAllowed = rs.getBoolean("ReplayAllowed"); + replayAvailable = rs.getBoolean("ReplayAvailable"); win = rs.getInt("Win"); } @@ -116,6 +118,6 @@ public class Fight { } public boolean replayExists() { - return getGameMode() != null && Replay.hasReplay(fightID); + return getGameMode() != null && replayAvailable; } } diff --git a/src/de/steamwar/bungeecore/sql/Replay.java b/src/de/steamwar/bungeecore/sql/Replay.java deleted file mode 100644 index a4f2651..0000000 --- a/src/de/steamwar/bungeecore/sql/Replay.java +++ /dev/null @@ -1,31 +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.sql; - -import java.sql.ResultSet; - -public class Replay { - - private static final Statement hasReplay = new Statement("SELECT 1 FROM Replay WHERE FightID = ?"); - - public static boolean hasReplay(int id) { - return hasReplay.select(ResultSet::next, id); - } -} From e723224282756358d444a3083b47eb41ff7f30ad Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 10 Apr 2022 20:14:33 +0200 Subject: [PATCH 18/18] Fix Fabric stuff --- .../bungeecore/listeners/mods/Fabric.java | 35 ++++++++----------- .../listeners/mods/ModLoaderBlocker.java | 2 +- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java index 252aac0..4e0a852 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java @@ -38,8 +38,6 @@ import net.md_5.bungee.event.EventHandler; import java.nio.charset.StandardCharsets; import java.nio.charset.UnsupportedCharsetException; -import java.sql.Timestamp; -import java.time.Instant; import java.util.*; import java.util.concurrent.TimeUnit; import java.util.logging.Level; @@ -48,9 +46,6 @@ public class Fabric extends BasicListener { private final Set neededMods = new HashSet<>(); - public static final Map checkedPlayers = new HashMap<>(); - private static final Map expectPluginMessage = new HashMap<>(); - { neededMods.add("java"); neededMods.add("minecraft"); @@ -58,9 +53,9 @@ public class Fabric extends BasicListener { neededMods.add("steamwarmodsender"); BungeeCord.getInstance().getScheduler().schedule(BungeeCore.get(), () -> { - synchronized (expectPluginMessage) { - for (Map.Entry entry : expectPluginMessage.entrySet()) { - if (!checkedPlayers.containsKey(entry.getKey())) { + synchronized (Storage.fabricExpectPluginMessage) { + for (Map.Entry entry : Storage.fabricExpectPluginMessage.entrySet()) { + if (!Storage.fabricCheckedPlayers.containsKey(entry.getKey())) { continue; } if (System.currentTimeMillis() - entry.getValue() > TimeUnit.SECONDS.toMillis(20)) { @@ -84,15 +79,15 @@ public class Fabric extends BasicListener { ProxiedPlayer player = (ProxiedPlayer) e.getSender(); SteamwarUser user = SteamwarUser.get(player.getUniqueId()); - if (!checkedPlayers.containsKey(player)) { - synchronized (expectPluginMessage) { - if (expectPluginMessage.containsKey(player)) { + if (!Storage.fabricCheckedPlayers.containsKey(player)) { + synchronized (Storage.fabricExpectPluginMessage) { + if (Storage.fabricExpectPluginMessage.containsKey(player)) { banPlayer(user, player); return; } } } - expectPluginMessage.remove(player); + Storage.fabricExpectPluginMessage.remove(player); List mods = new LinkedList<>(); @@ -141,15 +136,15 @@ public class Fabric extends BasicListener { } if(Utils.handleMods(player,mods)) { - if (checkedPlayers.containsKey(player)) { - long current = checkedPlayers.get(player); + if (Storage.fabricCheckedPlayers.containsKey(player)) { + long current = Storage.fabricCheckedPlayers.get(player); if (current != dataString.hashCode()) { banPlayer(user, player); return; } } else { Message.send("MODIFICATION_CHECK_SUCCESS", player); - checkedPlayers.put(player, dataString.hashCode()); + Storage.fabricCheckedPlayers.put(player, dataString.hashCode()); } Storage.fabricPlayers.remove(player); } @@ -158,8 +153,8 @@ public class Fabric extends BasicListener { @EventHandler public void onServerSwitchEvent(ServerSwitchEvent e) { if (e.getFrom() == null) return; - synchronized (expectPluginMessage) { - expectPluginMessage.put(e.getPlayer(), System.currentTimeMillis()); + synchronized (Storage.fabricExpectPluginMessage) { + Storage.fabricExpectPluginMessage.put(e.getPlayer(), System.currentTimeMillis()); } } @@ -189,9 +184,9 @@ public class Fabric extends BasicListener { } public static void remove(ProxiedPlayer player) { - checkedPlayers.remove(player); - synchronized (expectPluginMessage) { - expectPluginMessage.remove(player); + Storage.fabricCheckedPlayers.remove(player); + synchronized (Storage.fabricExpectPluginMessage) { + Storage.fabricExpectPluginMessage.remove(player); } } } diff --git a/src/de/steamwar/bungeecore/listeners/mods/ModLoaderBlocker.java b/src/de/steamwar/bungeecore/listeners/mods/ModLoaderBlocker.java index 9965c3e..71f8220 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/ModLoaderBlocker.java +++ b/src/de/steamwar/bungeecore/listeners/mods/ModLoaderBlocker.java @@ -46,7 +46,7 @@ public class ModLoaderBlocker extends BasicListener { if(new String(e.getData()).contains("fabric")){ ProxiedPlayer p = (ProxiedPlayer) sender; - if (!Fabric.checkedPlayers.containsKey(p) && !Storage.fabricPlayers.contains(p)) { + if (!Storage.fabricCheckedPlayers.containsKey(p) && !Storage.fabricPlayers.contains(p)) { Storage.fabricPlayers.add(p); Message.send("MODLOADER_INSTALLED_FABRIC", p, "Fabric"); }