* Game watching - Show number of games watched by player in player list.

This commit is contained in:
LevelX2 2014-05-29 18:21:04 +02:00
parent 83be13a68b
commit 3a5dd428e6
4 changed files with 25 additions and 4 deletions

View file

@ -337,9 +337,7 @@ public class TableController {
if (userPlayerMap.get(userId) != null) {
return false;
}
UserManager.getInstance().getUser(userId).watchGame(match.getGame().getId());
return true;
return UserManager.getInstance().getUser(userId).watchGame(match.getGame().getId());
}
}

View file

@ -27,6 +27,7 @@
*/
package mage.server;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
@ -75,6 +76,7 @@ public class User {
private final Map<UUID, TournamentSession> tournamentSessions;
private final Map<UUID, TournamentSession> constructing;
private final Map<UUID, Deck> sideboarding;
private final List<UUID> watchedGames;
private String sessionId;
private String info;
@ -97,6 +99,7 @@ public class User {
this.tournamentSessions = new ConcurrentHashMap<>();
this.constructing = new ConcurrentHashMap<>();
this.sideboarding = new ConcurrentHashMap<>();
this.watchedGames = new ArrayList<>();
this.sessionId = "";
}
@ -205,8 +208,9 @@ public class User {
fireCallback(new ClientCallback("showUserMessage", null, messageData ));
}
public void watchGame(final UUID gameId) {
public boolean watchGame(final UUID gameId) {
fireCallback(new ClientCallback("watchGame", gameId));
return true;
}
public void replayGame(final UUID gameId) {
@ -405,6 +409,10 @@ public class User {
if (tournament > 0) {
sb.append("TP: ").append(tournament).append(" ");
}
if (watchedGames.size() > 0) {
sb.append("WA: ").append(watchedGames.size()).append(" ");
}
sb.append(disconnectInfo);
return sb.toString();
}
@ -416,4 +424,12 @@ public class User {
public void setInfo(String Info) {
this.info = Info;
}
public void addGameWatchInfo(UUID gameId) {
watchedGames.add(gameId);
}
public void removeGameWatchInfo(UUID gameId) {
watchedGames.remove(gameId);
}
}

View file

@ -336,11 +336,16 @@ public class GameController implements GameCallback {
// You can't watch a game if you already a player in it
return;
}
if (watchers.get(userId) != null) {
// You can't watch a game if you already watch it
return;
}
User user = UserManager.getInstance().getUser(userId);
if (user != null) {
GameWatcher gameWatcher = new GameWatcher(userId, game, false);
watchers.put(userId, gameWatcher);
gameWatcher.init();
user.addGameWatchInfo(game.getId());
ChatManager.getInstance().broadcast(chatId, user.getName(), " has started watching", MessageColor.BLUE, true, ChatMessage.MessageType.STATUS);
}
}
@ -349,6 +354,7 @@ public class GameController implements GameCallback {
watchers.remove(userId);
User user = UserManager.getInstance().getUser(userId);
if (user != null) {
user.removeGameWatchInfo(game.getId());
ChatManager.getInstance().broadcast(chatId, user.getName(), " has stopped watching", MessageColor.BLUE, true, ChatMessage.MessageType.STATUS);
}
}

View file

@ -100,6 +100,7 @@ public class GameWatcher {
if (!killed) {
User user = UserManager.getInstance().getUser(userId);
if (user != null) {
user.removeGameWatchInfo(game.getId());
user.fireCallback(new ClientCallback("gameOver", game.getId(), message));
}
}