SteamWar/SpigotCore
Archiviert
13
0

Storing replays in the database

Dieser Commit ist enthalten in:
Lixfel 2021-05-31 08:01:21 +02:00
Ursprung 98c2ae397b
Commit 8d6c499cd1
2 geänderte Dateien mit 40 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -57,6 +57,11 @@ public class EventFight {
SQL.update("UPDATE EventFight SET Ergebnis = ? WHERE FightID = ?", winner, fightID); 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() { public int getTeamBlue() {
return teamBlue; return teamBlue;
} }

Datei anzeigen

@ -19,6 +19,9 @@
package de.steamwar.sql; package de.steamwar.sql;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.Blob;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
@ -27,8 +30,12 @@ public class Fight {
private 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){ 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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", return create(gamemode, arena, null, starttime, duration, blueleader, redleader, blueschem, redschem, win, wincondition);
gamemode, arena, 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"); ResultSet rs = SQL.select("SELECT LAST_INSERT_ID() AS FightID");
try{ try{
if(!rs.next()) if(!rs.next())
@ -39,4 +46,30 @@ public class Fight {
throw new SecurityException(e); 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);
}
}
} }