Merge pull request 'Storing replays in the database' (#108) from fight-replays into master
Reviewed-on: #108 Reviewed-by: YoyoNow <jwsteam@nidido.de>
Dieser Commit ist enthalten in:
Commit
4ec347e2d9
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
package de.steamwar.sql;
|
package de.steamwar.sql;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
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 +29,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 +45,27 @@ 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 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren