Allowing to view recent games
This commit is contained in:
@@ -15,6 +15,9 @@ import org.w3c.dom.Element;
|
|||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -79,6 +82,41 @@ public class GameHistoryRequestHandler extends LotroServerRequestHandler impleme
|
|||||||
|
|
||||||
doc.appendChild(gameHistory);
|
doc.appendChild(gameHistory);
|
||||||
|
|
||||||
|
responseWriter.writeXmlResponse(doc);
|
||||||
|
} else if (uri.equals("/list") && request.getMethod() == HttpMethod.GET) {
|
||||||
|
final List<GameHistoryEntry> playerGameHistory = _gameHistoryService.getTrackableGames(50);
|
||||||
|
|
||||||
|
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||||
|
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||||
|
Document doc = documentBuilder.newDocument();
|
||||||
|
Element gameHistory = doc.createElement("gameHistory");
|
||||||
|
|
||||||
|
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
|
||||||
|
for (GameHistoryEntry gameHistoryEntry : playerGameHistory) {
|
||||||
|
Element historyEntry = doc.createElement("historyEntry");
|
||||||
|
historyEntry.setAttribute("winner", gameHistoryEntry.getWinner());
|
||||||
|
historyEntry.setAttribute("loser", gameHistoryEntry.getLoser());
|
||||||
|
|
||||||
|
historyEntry.setAttribute("winReason", gameHistoryEntry.getWinReason());
|
||||||
|
historyEntry.setAttribute("loseReason", gameHistoryEntry.getLoseReason());
|
||||||
|
|
||||||
|
historyEntry.setAttribute("formatName", gameHistoryEntry.getFormatName());
|
||||||
|
|
||||||
|
historyEntry.setAttribute("winnerRecordingLink", "http://www.gempukku.com/gemp-lotr/game.html?replayId="+gameHistoryEntry.getWinner()+"$"+gameHistoryEntry.getWinnerRecording());
|
||||||
|
historyEntry.setAttribute("winnerDeckName", gameHistoryEntry.getWinnerDeckName());
|
||||||
|
|
||||||
|
historyEntry.setAttribute("loserRecordingLink", "http://www.gempukku.com/gemp-lotr/game.html?replayId="+gameHistoryEntry.getLoser()+"$"+gameHistoryEntry.getLoserRecording());
|
||||||
|
historyEntry.setAttribute("loserDeckName", gameHistoryEntry.getLoserDeckName());
|
||||||
|
|
||||||
|
historyEntry.setAttribute("startTime", dateFormat.format(new Date(gameHistoryEntry.getStartTime().getTime())));
|
||||||
|
historyEntry.setAttribute("endTime", dateFormat.format(new Date(gameHistoryEntry.getEndTime().getTime())));
|
||||||
|
|
||||||
|
gameHistory.appendChild(historyEntry);
|
||||||
|
}
|
||||||
|
|
||||||
|
doc.appendChild(gameHistory);
|
||||||
|
|
||||||
responseWriter.writeXmlResponse(doc);
|
responseWriter.writeXmlResponse(doc);
|
||||||
} else {
|
} else {
|
||||||
throw new HttpProcessingException(404);
|
throw new HttpProcessingException(404);
|
||||||
|
|||||||
@@ -240,6 +240,53 @@ public class DbGameHistoryDAO implements GameHistoryDAO {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<GameHistoryEntry> getLastGames(String requestedFormatName, int count) {
|
||||||
|
try {
|
||||||
|
Connection connection = _dbAccess.getDataSource().getConnection();
|
||||||
|
try {
|
||||||
|
PreparedStatement statement = connection.prepareStatement(
|
||||||
|
"select winner, loser, win_reason, lose_reason, win_recording_id, lose_recording_id, format_name, " +
|
||||||
|
"tournament, winner_deck_name, loser_deck_name, start_date, end_date from game_history " +
|
||||||
|
"where format_name=? order by end_date desc limit ?");
|
||||||
|
try {
|
||||||
|
statement.setString(1, requestedFormatName);
|
||||||
|
statement.setInt(2, count);
|
||||||
|
ResultSet rs = statement.executeQuery();
|
||||||
|
try {
|
||||||
|
List<GameHistoryEntry> result = new LinkedList<GameHistoryEntry>();
|
||||||
|
while (rs.next()) {
|
||||||
|
String winner = rs.getString(1);
|
||||||
|
String loser = rs.getString(2);
|
||||||
|
String winReason = rs.getString(3);
|
||||||
|
String loseReason = rs.getString(4);
|
||||||
|
String winRecordingId = rs.getString(5);
|
||||||
|
String loseRecordingId = rs.getString(6);
|
||||||
|
String formatName = rs.getString(7);
|
||||||
|
String tournament = rs.getString(8);
|
||||||
|
String winnerDeckName = rs.getString(9);
|
||||||
|
String loserDeckName = rs.getString(10);
|
||||||
|
Date startDate = new Date(rs.getLong(11));
|
||||||
|
Date endDate = new Date(rs.getLong(12));
|
||||||
|
|
||||||
|
GameHistoryEntry entry = new GameHistoryEntry(winner, winReason, winRecordingId, loser, loseReason, loseRecordingId, formatName, tournament, winnerDeckName, loserDeckName, startDate, endDate);
|
||||||
|
result.add(entry);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
} finally {
|
||||||
|
rs.close();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
statement.close();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
connection.close();
|
||||||
|
}
|
||||||
|
} catch (SQLException exp) {
|
||||||
|
throw new RuntimeException("Unable to get list of games", exp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public List<PlayerStatistic> getCompetitivePlayerStatistics(Player player) {
|
public List<PlayerStatistic> getCompetitivePlayerStatistics(Player player) {
|
||||||
try {
|
try {
|
||||||
Connection connection = _dbAccess.getDataSource().getConnection();
|
Connection connection = _dbAccess.getDataSource().getConnection();
|
||||||
|
|||||||
@@ -23,4 +23,6 @@ public interface GameHistoryDAO {
|
|||||||
public List<PlayerStatistic> getCasualPlayerStatistics(Player player);
|
public List<PlayerStatistic> getCasualPlayerStatistics(Player player);
|
||||||
|
|
||||||
public List<PlayerStatistic> getCompetitivePlayerStatistics(Player player);
|
public List<PlayerStatistic> getCompetitivePlayerStatistics(Player player);
|
||||||
|
|
||||||
|
List<GameHistoryEntry> getLastGames(String formatName, int count);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,10 @@ public class GameHistoryService {
|
|||||||
return _gameHistoryDAO.getGameHistoryForPlayer(player, start, count);
|
return _gameHistoryDAO.getGameHistoryForPlayer(player, start, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<GameHistoryEntry> getTrackableGames(int count) {
|
||||||
|
return _gameHistoryDAO.getLastGames("Second Edition", count);
|
||||||
|
}
|
||||||
|
|
||||||
public int getActivePlayersCount(long from, long duration) {
|
public int getActivePlayersCount(long from, long duration) {
|
||||||
return _gameHistoryDAO.getActivePlayersCount(from, duration);
|
return _gameHistoryDAO.getActivePlayersCount(from, duration);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user