show completed matches - view replays

This commit is contained in:
BetaSteward 2011-08-26 10:41:28 -04:00
parent 8c9db5876e
commit 4a653d55cd
11 changed files with 396 additions and 46 deletions

View file

@ -39,6 +39,7 @@ import mage.utils.MageVersion;
import mage.view.DraftPickView;
import mage.view.TableView;
import mage.view.GameView;
import mage.view.MatchView;
import mage.view.TournamentView;
import mage.view.UserView;
@ -68,6 +69,7 @@ public interface MageServer {
public TableView getTable(UUID roomId, UUID tableId) throws MageException;
public List<TableView> getTables(UUID roomId) throws MageException;
public List<String> getConnectedPlayers(UUID roomId) throws MageException;
public List<MatchView> getFinishedMatches(UUID roomId) throws MageException;
//chat methods
public void sendChatMessage(UUID chatId, String userName, String message) throws MageException;
@ -91,7 +93,6 @@ public interface MageServer {
public void sendPlayerBoolean(UUID gameId, String sessionId, Boolean data) throws MageException;
public void sendPlayerInteger(UUID gameId, String sessionId, Integer data) throws MageException;
public void concedeGame(UUID gameId, String sessionId) throws MageException;
//tournament methods
public void startTournament(String sessionId, UUID roomId, UUID tableId) throws MageException;

View file

@ -49,6 +49,7 @@ import mage.interfaces.callback.ClientCallback;
import mage.utils.CompressUtil;
import mage.view.DraftPickView;
import mage.view.GameTypeView;
import mage.view.MatchView;
import mage.view.TableView;
import mage.view.TournamentTypeView;
import mage.view.TournamentView;
@ -342,7 +343,6 @@ public class Session {
}
public Collection<TableView> getTables(UUID roomId) throws MageRemoteException {
// lock.readLock().lock();
try {
if (isConnected())
return server.getTables(roomId);
@ -351,14 +351,24 @@ public class Session {
throw new MageRemoteException();
} catch (Throwable t) {
handleThrowable(t);
// } finally {
// lock.readLock().unlock();
}
return null;
}
public Collection<String> getConnectedPlayers(UUID roomId) throws MageRemoteException {
// lock.readLock().lock();
public Collection<MatchView> getFinishedMatches(UUID roomId) throws MageRemoteException {
try {
if (isConnected())
return server.getFinishedMatches(roomId);
} catch (MageException ex) {
handleMageException(ex);
throw new MageRemoteException();
} catch (Throwable t) {
handleThrowable(t);
}
return null;
}
public Collection<String> getConnectedPlayers(UUID roomId) throws MageRemoteException {
try {
if (isConnected())
return server.getConnectedPlayers(roomId);
@ -367,8 +377,6 @@ public class Session {
throw new MageRemoteException();
} catch (Throwable t) {
handleThrowable(t);
// } finally {
// lock.readLock().unlock();
}
return null;
}

View file

@ -0,0 +1,100 @@
/*
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.view;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import mage.game.Game;
import mage.game.match.Match;
import mage.game.match.MatchPlayer;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class MatchView implements Serializable {
private UUID matchId;
private String matchName;
private String gameType;
private String deckType;
private List<UUID> games = new ArrayList<UUID>();
private String result;
private String players;
public MatchView(Match match) {
this.matchId = match.getId();
this.matchName = match.getName();
this.gameType = match.getOptions().getGameType();
this.deckType = match.getOptions().getDeckType();
for (Game game: match.getGames()) {
games.add(game.getId());
}
StringBuilder sb1 = new StringBuilder();
StringBuilder sb2 = new StringBuilder();
for (MatchPlayer player: match.getPlayers()) {
sb1.append(player.getPlayer().getName()).append(", ");
sb2.append(player.getPlayer().getName()).append(" ").append(player.getWins()).append("-").append(player.getLoses()).append(", ");
players = sb1.substring(0, sb1.length() - 2);
result = sb2.substring(0, sb2.length() - 2);
}
}
public UUID getMatchId() {
return matchId;
}
public String getName() {
return matchName;
}
public String getGameType() {
return gameType;
}
public String getDeckType() {
return deckType;
}
public List<UUID> getGames() {
return games;
}
public String getResult() {
return result;
}
public String getPlayers() {
return players;
}
}