Fixing initial issues with tournaments.
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
package com.gempukku.lotro.db;
|
||||
|
||||
import com.gempukku.lotro.tournament.TournamentDAO;
|
||||
import com.gempukku.lotro.tournament.TournamentInfo;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class DbTournamentDAO implements TournamentDAO {
|
||||
private DbAccess _dbAccess;
|
||||
|
||||
public DbTournamentDAO(DbAccess dbAccess) {
|
||||
_dbAccess = dbAccess;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTournament(String tournamentId, String className, String parameters, Date start) {
|
||||
try {
|
||||
Connection conn = _dbAccess.getDataSource().getConnection();
|
||||
try {
|
||||
PreparedStatement statement = conn.prepareStatement("insert into tournament (tournament_id, class, parameters, start) values (?, ?, ?, ?)");
|
||||
try {
|
||||
statement.setString(1, tournamentId);
|
||||
statement.setString(2, className);
|
||||
statement.setString(3, parameters);
|
||||
statement.setLong(4, start.getTime());
|
||||
statement.execute();
|
||||
} finally {
|
||||
statement.close();
|
||||
}
|
||||
} finally {
|
||||
conn.close();
|
||||
}
|
||||
} catch (SQLException exp) {
|
||||
throw new RuntimeException(exp);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TournamentInfo getTournamentById(String tournamentId) {
|
||||
try {
|
||||
Connection connection = _dbAccess.getDataSource().getConnection();
|
||||
try {
|
||||
PreparedStatement statement = connection.prepareStatement("select class, parameters, start from tournament where tournament_id=?");
|
||||
try {
|
||||
statement.setString(1, tournamentId);
|
||||
ResultSet rs = statement.executeQuery();
|
||||
try {
|
||||
if (rs.next())
|
||||
return new TournamentInfo(tournamentId, rs.getString(1), rs.getString(2), new Date(rs.getLong(3)));
|
||||
else
|
||||
return null;
|
||||
} finally {
|
||||
rs.close();
|
||||
}
|
||||
} finally {
|
||||
statement.close();
|
||||
}
|
||||
} finally {
|
||||
connection.close();
|
||||
}
|
||||
} catch (SQLException exp) {
|
||||
throw new RuntimeException(exp);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TournamentInfo> getUnfinishedTournaments() {
|
||||
try {
|
||||
Connection connection = _dbAccess.getDataSource().getConnection();
|
||||
try {
|
||||
PreparedStatement statement = connection.prepareStatement("select tournament_id, class, parameters, start from tournament where finished=false");
|
||||
try {
|
||||
ResultSet rs = statement.executeQuery();
|
||||
try {
|
||||
List<TournamentInfo> result = new ArrayList<TournamentInfo>();
|
||||
while (rs.next())
|
||||
result.add(new TournamentInfo(rs.getString(1), rs.getString(2), rs.getString(3), new Date(rs.getLong(4))));
|
||||
return result;
|
||||
} finally {
|
||||
rs.close();
|
||||
}
|
||||
} finally {
|
||||
statement.close();
|
||||
}
|
||||
} finally {
|
||||
connection.close();
|
||||
}
|
||||
} catch (SQLException exp) {
|
||||
throw new RuntimeException(exp);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markTournamentFinished(String tournamentId) {
|
||||
try {
|
||||
Connection conn = _dbAccess.getDataSource().getConnection();
|
||||
try {
|
||||
PreparedStatement statement = conn.prepareStatement("update tournament set finished=true where tournament_id=?");
|
||||
try {
|
||||
statement.setString(1, tournamentId);
|
||||
statement.executeUpdate();
|
||||
} finally {
|
||||
statement.close();
|
||||
}
|
||||
} finally {
|
||||
conn.close();
|
||||
}
|
||||
} catch (SQLException exp) {
|
||||
throw new RuntimeException(exp);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,7 @@ public class HallServer extends AbstractServer {
|
||||
_runningTournaments.addAll(tournamentService.getLiveTournaments());
|
||||
|
||||
_tournamentQueues.put("fotr_queue", new SingleEliminationRecurringQueue(0, _formatLibrary.getFormat("fotr_block"),
|
||||
new CollectionType("default", "All cards"), "fotrQueue-", "Fellowship Block", 4,
|
||||
new CollectionType("default", "All cards"), "fotrQueue-", "Fellowship Block", 2,
|
||||
tournamentService));
|
||||
}
|
||||
|
||||
@@ -246,7 +246,7 @@ public class HallServer extends AbstractServer {
|
||||
_hallDataAccessLock.readLock().lock();
|
||||
try {
|
||||
_lastVisitedPlayers.put(player, System.currentTimeMillis());
|
||||
visitor.playerIsWaiting(isPlayerWaiting(player.getName()));
|
||||
visitor.playerIsWaiting(isPlayerBusy(player.getName()));
|
||||
|
||||
// First waiting
|
||||
for (Map.Entry<String, AwaitingTable> tableInformation : _awaitingTables.entrySet()) {
|
||||
@@ -415,13 +415,6 @@ public class HallServer extends AbstractServer {
|
||||
createGameFromAwaitingTable(tableId, awaitingTable);
|
||||
}
|
||||
|
||||
private boolean isPlayerWaiting(String playerId) {
|
||||
for (AwaitingTable awaitingTable : _awaitingTables.values())
|
||||
if (awaitingTable.hasPlayer(playerId))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private String getPlayingPlayerGameId(String playerId) {
|
||||
for (Map.Entry<String, RunningTable> runningTable : _runningTables.entrySet()) {
|
||||
String gameId = runningTable.getValue().getGameId();
|
||||
|
||||
@@ -62,7 +62,7 @@ public class SingleEliminationRecurringQueue implements TournamentQueue {
|
||||
for (Map.Entry<String, LotroDeck> playerDeck : _playerDecks.entrySet())
|
||||
_tournamentService.addPlayer(tournamentId, playerDeck.getKey(), playerDeck.getValue());
|
||||
|
||||
Tournament tournament = _tournamentService.addTournament(_cost, tournamentId, SingleEliminationTournament.class.getName(), parameters, new Date());
|
||||
Tournament tournament = _tournamentService.addTournament(tournamentId, SingleEliminationTournament.class.getName(), parameters, new Date());
|
||||
|
||||
tournamentQueueCallback.createTournament(tournament);
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public interface TournamentDAO {
|
||||
public void addTournament(int cost, String tournamentId, String className, String type, Date start);
|
||||
public void addTournament(String tournamentId, String className, String parameters, Date start);
|
||||
|
||||
public void markTournamentFinished(String tournamentId);
|
||||
|
||||
|
||||
@@ -3,37 +3,31 @@ package com.gempukku.lotro.tournament;
|
||||
import java.util.Date;
|
||||
|
||||
public class TournamentInfo {
|
||||
private int cost;
|
||||
private String tournamentId;
|
||||
private String tournamentClass;
|
||||
private String parameters;
|
||||
private Date start;
|
||||
private String _tournamentId;
|
||||
private String _tournamentClass;
|
||||
private String _parameters;
|
||||
private Date _start;
|
||||
|
||||
public TournamentInfo(int cost, String tournamentId, String tournamentClass, String parameters, Date start) {
|
||||
this.cost = cost;
|
||||
this.tournamentId = tournamentId;
|
||||
this.tournamentClass = tournamentClass;
|
||||
this.parameters = parameters;
|
||||
this.start = start;
|
||||
}
|
||||
|
||||
public int getCost() {
|
||||
return cost;
|
||||
public TournamentInfo(String tournamentId, String tournamentClass, String parameters, Date start) {
|
||||
this._tournamentId = tournamentId;
|
||||
this._tournamentClass = tournamentClass;
|
||||
this._parameters = parameters;
|
||||
this._start = start;
|
||||
}
|
||||
|
||||
public String getTournamentId() {
|
||||
return tournamentId;
|
||||
return _tournamentId;
|
||||
}
|
||||
|
||||
public String getTournamentClass() {
|
||||
return tournamentClass;
|
||||
return _tournamentClass;
|
||||
}
|
||||
|
||||
public String getParameters() {
|
||||
return parameters;
|
||||
return _parameters;
|
||||
}
|
||||
|
||||
public Date getStart() {
|
||||
return start;
|
||||
return _start;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,9 +54,9 @@ public class TournamentService {
|
||||
return _tournamentMatchDao.getMatches(tournamentId, round);
|
||||
}
|
||||
|
||||
public Tournament addTournament(int cost, String tournamentId, String tournamentClass, String parameters, Date start) {
|
||||
_tournamentDao.addTournament(cost, tournamentId, tournamentClass, parameters, start);
|
||||
return createTournamentAndStoreInCache(tournamentId, new TournamentInfo(cost, tournamentId, tournamentClass, parameters, start));
|
||||
public Tournament addTournament(String tournamentId, String tournamentClass, String parameters, Date start) {
|
||||
_tournamentDao.addTournament(tournamentId, tournamentClass, parameters, start);
|
||||
return createTournamentAndStoreInCache(tournamentId, new TournamentInfo(tournamentId, tournamentClass, parameters, start));
|
||||
}
|
||||
|
||||
public void markTournamentFinished(String tournamentId) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.gempukku.lotro.server.provider;
|
||||
import com.gempukku.lotro.collection.CollectionSerializer;
|
||||
import com.gempukku.lotro.db.*;
|
||||
import com.gempukku.lotro.game.LotroCardBlueprintLibrary;
|
||||
import com.gempukku.lotro.tournament.TournamentDAO;
|
||||
import com.gempukku.lotro.tournament.TournamentMatchDAO;
|
||||
import com.gempukku.lotro.tournament.TournamentPlayerDAO;
|
||||
import com.sun.jersey.core.spi.component.ComponentContext;
|
||||
@@ -26,6 +27,7 @@ public class DaoProvider implements InjectableProvider<Context, Type> {
|
||||
private Injectable<LeagueMatchDAO> _leagueMatchDAOInjectable;
|
||||
private Injectable<LeagueParticipationDAO> _leagueParticipationDAOInjectable;
|
||||
|
||||
private Injectable<TournamentDAO> _tournamentDAOInjectable;
|
||||
private Injectable<TournamentPlayerDAO> _tournamentPlayerDAOInjectable;
|
||||
private Injectable<TournamentMatchDAO> _tournamentMatchDAOInjectable;
|
||||
|
||||
@@ -59,6 +61,8 @@ public class DaoProvider implements InjectableProvider<Context, Type> {
|
||||
return getLeagueParticipationDaoSafely();
|
||||
else if (type.equals(MerchantDAO.class))
|
||||
return getMerchantDaoSafely();
|
||||
else if (type.equals(TournamentDAO.class))
|
||||
return getTournamentDaoSafely();
|
||||
else if (type.equals(TournamentPlayerDAO.class))
|
||||
return getTournamentPlayerDaoSafely();
|
||||
else if (type.equals(TournamentMatchDAO.class))
|
||||
@@ -92,6 +96,19 @@ public class DaoProvider implements InjectableProvider<Context, Type> {
|
||||
return _leagueMatchDAOInjectable;
|
||||
}
|
||||
|
||||
private synchronized Injectable<TournamentDAO> getTournamentDaoSafely() {
|
||||
if (_tournamentDAOInjectable == null) {
|
||||
final DbTournamentDAO tournamentDAO = new DbTournamentDAO(_dbAccess);
|
||||
_tournamentDAOInjectable = new Injectable<TournamentDAO>() {
|
||||
@Override
|
||||
public TournamentDAO getValue() {
|
||||
return tournamentDAO;
|
||||
}
|
||||
};
|
||||
}
|
||||
return _tournamentDAOInjectable;
|
||||
}
|
||||
|
||||
private synchronized Injectable<TournamentPlayerDAO> getTournamentPlayerDaoSafely() {
|
||||
if (_tournamentPlayerDAOInjectable == null) {
|
||||
final DbTournamentPlayerDAO tournamentPlayerDAO = new DbTournamentPlayerDAO(_dbAccess);
|
||||
|
||||
@@ -49,15 +49,15 @@ var GempLotrHallUI = Class.extend({
|
||||
|
||||
var editDeck = $("<button>Deck builder</button>");
|
||||
editDeck.button().click(
|
||||
function () {
|
||||
location.href = 'deckBuild.html';
|
||||
});
|
||||
function () {
|
||||
location.href = 'deckBuild.html';
|
||||
});
|
||||
|
||||
var merchant = $("<button>Merchant</button>");
|
||||
merchant.button().click(
|
||||
function () {
|
||||
location.href = 'merchant.html';
|
||||
});
|
||||
function () {
|
||||
location.href = 'merchant.html';
|
||||
});
|
||||
|
||||
this.buttonsDiv.append(editDeck);
|
||||
this.buttonsDiv.append(" | ");
|
||||
@@ -74,39 +74,41 @@ var GempLotrHallUI = Class.extend({
|
||||
|
||||
this.createTableButton = $("<button>Create table</button>");
|
||||
$(this.createTableButton).button().click(
|
||||
function () {
|
||||
that.supportedFormatsSelect.hide();
|
||||
that.decksSelect.hide();
|
||||
that.createTableButton.hide();
|
||||
var format = that.supportedFormatsSelect.val();
|
||||
var deck = that.decksSelect.val();
|
||||
if (deck != null)
|
||||
that.comm.createTable(format, deck, function (xml) {
|
||||
that.processResponse(xml);
|
||||
});
|
||||
});
|
||||
function () {
|
||||
that.supportedFormatsSelect.hide();
|
||||
that.decksSelect.hide();
|
||||
that.createTableButton.hide();
|
||||
var format = that.supportedFormatsSelect.val();
|
||||
var deck = that.decksSelect.val();
|
||||
if (deck != null)
|
||||
that.comm.createTable(format, deck, function (xml) {
|
||||
that.processResponse(xml);
|
||||
});
|
||||
});
|
||||
this.createTableButton.hide();
|
||||
|
||||
this.decksSelect = $("<select style='width: 220px'></select>");
|
||||
this.decksSelect.hide();
|
||||
|
||||
var showQueuesCheck = $("<label for='showEmptyTableQueuesCheck'>Show all queues</label><input type='checkbox' id='showEmptyTableQueuesCheck' value='showQueues'/>");
|
||||
var showQueuesCheck = $("<input type='checkbox' id='showEmptyTableQueuesCheck' value='showQueues'/><label for='showEmptyTableQueuesCheck'>Show all queues</label>");
|
||||
|
||||
this.buttonsDiv.append(this.supportedFormatsSelect);
|
||||
this.buttonsDiv.append(this.decksSelect);
|
||||
this.buttonsDiv.append(this.createTableButton);
|
||||
this.buttonsDiv.append(showQueuesCheck);
|
||||
|
||||
this.leaveTableButton = $("<button>Leave table</button>");
|
||||
$(this.leaveTableButton).button().click(
|
||||
function () {
|
||||
that.leaveTableButton.hide();
|
||||
that.comm.leaveTable();
|
||||
});
|
||||
function () {
|
||||
that.leaveTableButton.hide();
|
||||
that.comm.leaveTable();
|
||||
});
|
||||
this.leaveTableButton.hide();
|
||||
|
||||
this.buttonsDiv.append(this.leaveTableButton);
|
||||
|
||||
this.buttonsDiv.append(" | ");
|
||||
this.buttonsDiv.append(showQueuesCheck);
|
||||
|
||||
this.div.append(this.buttonsDiv);
|
||||
|
||||
this.updateHall();
|
||||
@@ -182,9 +184,9 @@ var GempLotrHallUI = Class.extend({
|
||||
var tournamentQueue = tournamentQueues[i];
|
||||
var id = tournamentQueue.getAttribute("id");
|
||||
var tournamentName = tournamentQueue.getAttribute("tournament");
|
||||
var players = parseInt(table.getAttribute("players"));
|
||||
var formatName = table.getAttribute("format");
|
||||
var joined = table.getAttribute("joined");
|
||||
var players = parseInt(tournamentQueue.getAttribute("players"));
|
||||
var formatName = tournamentQueue.getAttribute("format");
|
||||
var joined = tournamentQueue.getAttribute("joined");
|
||||
if (players > 0 || $("#showEmptyTableQueuesCheck").prop("checked"))
|
||||
this.appendTournamentQueue(tablesTable, id, formatName, tournamentName, players, joined);
|
||||
}
|
||||
@@ -257,15 +259,14 @@ var GempLotrHallUI = Class.extend({
|
||||
row.append("<td>" + formatName + "</td>");
|
||||
row.append("<td>" + tournamentName + "</td>");
|
||||
row.append("<td>" + "Accepting players" + "</td>");
|
||||
row.append("<td>" + players + "</td>");
|
||||
row.append("<td>" + "Players: " + players + "</td>");
|
||||
|
||||
var actionsField = $("<td></td>");
|
||||
if (players.length < 2) {
|
||||
var that = this;
|
||||
var that = this;
|
||||
|
||||
if (!joined) {
|
||||
var but = $("<button>Join queue</button>");
|
||||
$(but).button().click(
|
||||
if (joined != "true") {
|
||||
var but = $("<button>Join queue</button>");
|
||||
$(but).button().click(
|
||||
function (event) {
|
||||
var deck = that.decksSelect.val();
|
||||
if (deck != null)
|
||||
@@ -273,10 +274,10 @@ var GempLotrHallUI = Class.extend({
|
||||
that.processResponse(xml);
|
||||
});
|
||||
});
|
||||
actionsField.append(but);
|
||||
} else {
|
||||
var but = $("<button>Leave queue</button>");
|
||||
$(but).button().click(
|
||||
actionsField.append(but);
|
||||
} else {
|
||||
var but = $("<button>Leave queue</button>");
|
||||
$(but).button().click(
|
||||
function (event) {
|
||||
var deck = that.decksSelect.val();
|
||||
if (deck != null)
|
||||
@@ -284,8 +285,7 @@ var GempLotrHallUI = Class.extend({
|
||||
that.processResponse(xml);
|
||||
});
|
||||
});
|
||||
actionsField.append(but);
|
||||
}
|
||||
actionsField.append(but);
|
||||
}
|
||||
|
||||
row.append(actionsField);
|
||||
@@ -319,13 +319,13 @@ var GempLotrHallUI = Class.extend({
|
||||
if (!waiting) {
|
||||
var but = $("<button>Join table</button>");
|
||||
$(but).button().click(
|
||||
function (event) {
|
||||
var deck = that.decksSelect.val();
|
||||
if (deck != null)
|
||||
that.comm.joinTable(id, deck, function (xml) {
|
||||
that.processResponse(xml);
|
||||
});
|
||||
});
|
||||
function (event) {
|
||||
var deck = that.decksSelect.val();
|
||||
if (deck != null)
|
||||
that.comm.joinTable(id, deck, function (xml) {
|
||||
that.processResponse(xml);
|
||||
});
|
||||
});
|
||||
actionsField.append(but);
|
||||
}
|
||||
}
|
||||
@@ -333,13 +333,13 @@ var GempLotrHallUI = Class.extend({
|
||||
if (status == "Playing" || status == "Preparation") {
|
||||
var but = $("<button>Watch game</button>");
|
||||
$(but).button().click(
|
||||
function (event) {
|
||||
var participantId = getUrlParam("participantId");
|
||||
var participantIdAppend = "";
|
||||
if (participantId != null)
|
||||
participantIdAppend = "&participantId=" + participantId;
|
||||
location.href = "/gemp-lotr/game.html?gameId=" + gameId + participantIdAppend;
|
||||
});
|
||||
function (event) {
|
||||
var participantId = getUrlParam("participantId");
|
||||
var participantIdAppend = "";
|
||||
if (participantId != null)
|
||||
participantIdAppend = "&participantId=" + participantId;
|
||||
location.href = "/gemp-lotr/game.html?gameId=" + gameId + participantIdAppend;
|
||||
});
|
||||
actionsField.append(but);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user