mirror of
https://github.com/correl/mage.git
synced 2024-11-25 03:00:11 +00:00
Ban ignored users from watching
This commit bans ignored users from watching games where the creator has them on their ignore list.
This commit is contained in:
parent
62c14a9c24
commit
ad0507e739
8 changed files with 60 additions and 19 deletions
|
@ -305,10 +305,14 @@ public final class GamePanel extends javax.swing.JPanel {
|
||||||
this.players.clear();
|
this.players.clear();
|
||||||
this.playersWhoLeft.clear();
|
this.playersWhoLeft.clear();
|
||||||
|
|
||||||
jLayeredPane.remove(abilityPicker);
|
if (jLayeredPane!= null) {
|
||||||
|
jLayeredPane.remove(abilityPicker);
|
||||||
|
}
|
||||||
this.abilityPicker.cleanUp();
|
this.abilityPicker.cleanUp();
|
||||||
|
|
||||||
jLayeredPane.remove(DialogManager.getManager(gameId));
|
if (jLayeredPane != null) {
|
||||||
|
jLayeredPane.remove(DialogManager.getManager(gameId));
|
||||||
|
}
|
||||||
DialogManager.removeGame(gameId);
|
DialogManager.removeGame(gameId);
|
||||||
|
|
||||||
if (pickNumber != null) {
|
if (pickNumber != null) {
|
||||||
|
|
|
@ -137,7 +137,7 @@ public interface MageServer {
|
||||||
|
|
||||||
void joinGame(UUID gameId, String sessionId) throws MageException;
|
void joinGame(UUID gameId, String sessionId) throws MageException;
|
||||||
|
|
||||||
void watchGame(UUID gameId, String sessionId) throws MageException;
|
boolean watchGame(UUID gameId, String sessionId) throws MageException;
|
||||||
|
|
||||||
void stopWatching(UUID gameId, String sessionId) throws MageException;
|
void stopWatching(UUID gameId, String sessionId) throws MageException;
|
||||||
|
|
||||||
|
|
|
@ -1016,8 +1016,7 @@ public class SessionImpl implements Session {
|
||||||
public boolean watchGame(UUID gameId) {
|
public boolean watchGame(UUID gameId) {
|
||||||
try {
|
try {
|
||||||
if (isConnected()) {
|
if (isConnected()) {
|
||||||
server.watchGame(gameId, sessionId);
|
return server.watchGame(gameId, sessionId);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
} catch (MageException ex) {
|
} catch (MageException ex) {
|
||||||
handleMageException(ex);
|
handleMageException(ex);
|
||||||
|
|
|
@ -879,14 +879,23 @@ public class MageServerImpl implements MageServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void watchGame(final UUID gameId, final String sessionId) throws MageException {
|
public boolean watchGame(final UUID gameId, final String sessionId) throws MageException {
|
||||||
execute("watchGame", sessionId, () -> {
|
return executeWithResult("watchGame", sessionId, new ActionWithResult<Boolean>() {
|
||||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
@Override
|
||||||
if (!session.isPresent()) {
|
public Boolean execute() throws MageException {
|
||||||
logger.error("Session not found : " + sessionId);
|
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||||
} else {
|
if (!session.isPresent()) {
|
||||||
UUID userId = session.get().getUserId();
|
logger.error("Session not found : " + sessionId);
|
||||||
GameManager.instance.watchGame(gameId, userId);
|
return false;
|
||||||
|
} else {
|
||||||
|
UUID userId = session.get().getUserId();
|
||||||
|
return GameManager.instance.watchGame(gameId, userId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean negativeResult() {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -605,6 +605,7 @@ public class TableController {
|
||||||
table.initGame();
|
table.initGame();
|
||||||
GameOptions gameOptions = new GameOptions();
|
GameOptions gameOptions = new GameOptions();
|
||||||
gameOptions.rollbackTurnsAllowed = match.getOptions().isRollbackTurnsAllowed();
|
gameOptions.rollbackTurnsAllowed = match.getOptions().isRollbackTurnsAllowed();
|
||||||
|
gameOptions.bannedUsers = match.getOptions().getBannedUsers();
|
||||||
match.getGame().setGameOptions(gameOptions);
|
match.getGame().setGameOptions(gameOptions);
|
||||||
GameManager.instance.createGameSession(match.getGame(), userPlayerMap, table.getId(), choosingPlayerId, gameOptions);
|
GameManager.instance.createGameSession(match.getGame(), userPlayerMap, table.getId(), choosingPlayerId, gameOptions);
|
||||||
String creator = null;
|
String creator = null;
|
||||||
|
|
|
@ -391,14 +391,22 @@ public class GameController implements GameCallback {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void watch(UUID userId) {
|
public boolean watch(UUID userId) {
|
||||||
if (userPlayerMap.containsKey(userId)) {
|
if (userPlayerMap.containsKey(userId)) {
|
||||||
// You can't watch a game if you already a player in it
|
// You can't watch a game if you already a player in it
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
if (watchers.containsKey(userId)) {
|
if (watchers.containsKey(userId)) {
|
||||||
// You can't watch a game if you already watch it
|
// You can't watch a game if you already watch it
|
||||||
return;
|
return false;
|
||||||
|
}
|
||||||
|
if (!isAllowedToWatch(userId)) {
|
||||||
|
// Dont want people on our ignore list to stalk us
|
||||||
|
UserManager.instance.getUser(userId).ifPresent(user -> {
|
||||||
|
user.showUserMessage("Not allowed", "You are banned from watching this game");
|
||||||
|
ChatManager.instance.broadcast(chatId, user.getName(), " tried to join, but is banned", MessageColor.BLUE, true, ChatMessage.MessageType.STATUS, null);
|
||||||
|
});
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
UserManager.instance.getUser(userId).ifPresent(user -> {
|
UserManager.instance.getUser(userId).ifPresent(user -> {
|
||||||
GameSessionWatcher gameWatcher = new GameSessionWatcher(userId, game, false);
|
GameSessionWatcher gameWatcher = new GameSessionWatcher(userId, game, false);
|
||||||
|
@ -407,6 +415,7 @@ public class GameController implements GameCallback {
|
||||||
user.addGameWatchInfo(game.getId());
|
user.addGameWatchInfo(game.getId());
|
||||||
ChatManager.instance.broadcast(chatId, user.getName(), " has started watching", MessageColor.BLUE, true, ChatMessage.MessageType.STATUS, null);
|
ChatManager.instance.broadcast(chatId, user.getName(), " has started watching", MessageColor.BLUE, true, ChatMessage.MessageType.STATUS, null);
|
||||||
});
|
});
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopWatching(UUID userId) {
|
public void stopWatching(UUID userId) {
|
||||||
|
@ -1011,4 +1020,13 @@ public class GameController implements GameCallback {
|
||||||
}
|
}
|
||||||
return sb.append(']').toString();
|
return sb.append(']').toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isAllowedToWatch(UUID userId) {
|
||||||
|
Optional<User> user = UserManager.instance.getUser(userId);
|
||||||
|
if (user.isPresent()) {
|
||||||
|
return !gameOptions.bannedUsers.contains(user.get().getName());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,11 +117,12 @@ public enum GameManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void watchGame(UUID gameId, UUID userId) {
|
public boolean watchGame(UUID gameId, UUID userId) {
|
||||||
GameController gameController = gameControllers.get(gameId);
|
GameController gameController = gameControllers.get(gameId);
|
||||||
if (gameController != null) {
|
if (gameController != null) {
|
||||||
gameController.watch(userId);
|
return gameController.watch(userId);
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopWatching(UUID gameId, UUID userId) {
|
public void stopWatching(UUID gameId, UUID userId) {
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package mage.game;
|
package mage.game;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import mage.constants.PhaseStep;
|
import mage.constants.PhaseStep;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Game options for Mage game. Mainly used in tests to configure
|
* Game options for Mage game. Mainly used in tests to configure
|
||||||
* {@link GameImpl} with specific params.
|
* {@link GameImpl} with specific params.
|
||||||
|
@ -42,4 +45,10 @@ public class GameOptions implements Serializable {
|
||||||
* If true, players can rollback turn if all players agree
|
* If true, players can rollback turn if all players agree
|
||||||
*/
|
*/
|
||||||
public boolean rollbackTurnsAllowed = true;
|
public boolean rollbackTurnsAllowed = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Names of users banned from participating in the game
|
||||||
|
*/
|
||||||
|
public Set<String> bannedUsers = Collections.emptySet();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue