- Added a way to request a game to be cancelled, if both parties request, the game will be cancelled.

This commit is contained in:
marcins78@gmail.com
2012-05-13 20:18:06 +00:00
parent 69ca1c01ac
commit a41fc35069
6 changed files with 67 additions and 2 deletions

View File

@@ -43,6 +43,8 @@ public class DefaultLotroGame implements LotroGame {
private Set<GameResultListener> _gameResultListeners = new HashSet<GameResultListener>();
private Set<String> _requestedCancel = new HashSet<String>();
public DefaultLotroGame(LotroFormat format, Map<String, LotroDeck> decks, UserFeedback userFeedback, final LotroCardBlueprintLibrary library) {
_format = format;
_actionStack = new ActionStack();
@@ -130,7 +132,7 @@ public class DefaultLotroGame implements LotroGame {
_cancelled = true;
if (_gameState != null) {
_gameState.sendMessage("Game was cancelled do to an error, the error was logged and will be fixed soon.");
_gameState.sendMessage("Game was cancelled due to an error, the error was logged and will be fixed soon.");
_gameState.sendMessage("Please post the replay game link and description of what happened on the TLHH forum.");
}
@@ -141,6 +143,20 @@ public class DefaultLotroGame implements LotroGame {
}
}
public void cancelGameRequested() {
if (!_finished) {
_cancelled = true;
if (_gameState != null)
_gameState.sendMessage("Game was cancelled, as requested by all parties.");
for (GameResultListener gameResultListener : _gameResultListeners)
gameResultListener.gameCancelled();
_finished = true;
}
}
public boolean isCancelled() {
return _cancelled;
}
@@ -189,6 +205,12 @@ public class DefaultLotroGame implements LotroGame {
}
}
public void requestCancel(String playerId) {
_requestedCancel.add(playerId);
if (_requestedCancel.size() == _allPlayers.size())
cancelGameRequested();
}
@Override
public GameState getGameState() {
return _gameState;

View File

@@ -266,6 +266,17 @@ public class LotroGameMediator {
}
}
public void cancel(Player player) {
String playerId = player.getName();
_writeLock.lock();
try {
if (_playersPlaying.contains(playerId))
_lotroGame.requestCancel(playerId);
} finally {
_writeLock.unlock();
}
}
public void playerAnswered(Player player, int channelNumber, int decisionId, String answer) {
String playerName = player.getName();
_writeLock.lock();

View File

@@ -120,6 +120,21 @@ public class GameResource extends AbstractResource {
gameMediator.concede(resourceOwner);
}
@Path("/{gameId}/cancel")
@POST
public void cancel(
@PathParam("gameId") String gameId,
@FormParam("participantId") String participantId,
@Context HttpServletRequest request) throws ParserConfigurationException {
Player resourceOwner = getResourceOwnerSafely(request, participantId);
LotroGameMediator gameMediator = _lotroServer.getGameById(gameId);
if (gameMediator == null)
sendError(Response.Status.NOT_FOUND);
gameMediator.cancel(resourceOwner);
}
@Path("/{gameId}")
@POST
@Produces(MediaType.APPLICATION_XML)

View File

@@ -6,6 +6,7 @@ already carries one.
- "Assault Commander" now gives -1 resistance, rather than +1.
- "Shingle in a Storm" now correctly discards itself upon use.
- "Armored Easterling" Dmg+1 bonus lasts only until the end of the skirmish now.
- Added a way to request a game to be cancelled, if both parties request, the game will be cancelled.
<b>09 May 2012</b>
- "Wrath of Harad" should now no longer freeze the game.

View File

@@ -180,6 +180,17 @@ var GempLotrCommunication = Class.extend({
dataType: "xml"
});
},
cancel: function(errorMap) {
$.ajax({
type: "POST",
url: this.url + "/game/" + getUrlParam("gameId") + "/cancel",
cache: false,
data: {
participantId: getUrlParam("participantId")},
error: this.errorCheck(errorMap),
dataType: "xml"
});
},
getDeck: function(deckName, callback, errorMap) {
$.ajax({
type: "GET",

View File

@@ -463,11 +463,16 @@ var GempLotrGameUI = Class.extend({
this.chatBox.chatUpdateInterval = 3000;
if (!this.spectatorMode && !this.replayMode) {
$("#gameOptionsBox").append("<button id='concedeGame'>Concede game</button>");
$("#gameOptionsBox").append("<button id='concedeGame'>Concede game</button><br/>");
$("#concedeGame").button().click(
function() {
that.communication.concede();
});
$("#gameOptionsBox").append("<button id='cancelGame'>Request game cancel</button>");
$("#cancelGame").button().click(
function() {
that.communication.cancel();
});
}
},