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..7604b12 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/Fight.java +++ b/SpigotCore_Main/src/de/steamwar/sql/Fight.java @@ -19,6 +19,8 @@ package de.steamwar.sql; +import java.io.InputStream; +import java.sql.Blob; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; @@ -27,8 +29,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 +45,27 @@ 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 void setReplay(int fightID, byte[] data) { + Blob blob = SQL.blob(); + try { + blob.setBytes(1, data); + } catch (SQLException e) { + throw new SecurityException(e); + } + SQL.update("UPDATE Fight SET Replay = ? WHERE FightID = ?", blob, fightID); + } }