SteamWar/SpigotCore
Archiviert
13
0

Storing replays in the database #108

Manuell gemergt
Lixfel hat 4 Commits von fight-replays nach master 2021-08-21 20:05:04 +02:00 zusammengeführt
2 geänderte Dateien mit 40 neuen und 2 gelöschten Zeilen
Nur Änderungen aus Commit 8d6c499cd1 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -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;
}

Datei anzeigen

@ -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);
}
}
}