Private tables can now be enabled from the game hall for casual tables. Private tables cannot be spectated.

This commit is contained in:
Christian 'ketura' McCarty
2023-05-11 23:05:23 -05:00
parent 5d672c26d0
commit 01b82852e0
12 changed files with 96 additions and 39 deletions

View File

@@ -142,12 +142,14 @@ public class HallRequestHandler extends LotroServerRequestHandler implements Uri
String desc = getFormParameterSafely(postDecoder, "desc").trim();
String isPrivateVal = getFormParameterSafely(postDecoder, "isPrivate");
boolean isPrivate = (isPrivateVal != null ? Boolean.valueOf(isPrivateVal) : false);
String isInviteOnlyVal = getFormParameterSafely(postDecoder, "isInviteOnly");
boolean isInviteOnly = (isInviteOnlyVal != null ? Boolean.valueOf(isInviteOnlyVal) : false);
Player resourceOwner = getResourceOwnerSafely(request, participantId);
if(isPrivate) {
if(isInviteOnly) {
if(desc.length()==0) {
responseWriter.writeXmlResponse(marshalException(new HallException("Private games must have your intended opponent in the description")));
responseWriter.writeXmlResponse(marshalException(new HallException("Invite-only games must have your intended opponent in the description")));
return;
}
@@ -173,7 +175,7 @@ public class HallRequestHandler extends LotroServerRequestHandler implements Uri
try {
_hallServer.createNewTable(format, resourceOwner, deckName, timer, desc, isPrivate);
_hallServer.createNewTable(format, resourceOwner, deckName, timer, desc, isInviteOnly, isPrivate);
responseWriter.writeXmlResponse(null);
}
catch (HallException e) {
@@ -181,7 +183,7 @@ public class HallRequestHandler extends LotroServerRequestHandler implements Uri
{
//try again assuming it's a new player with one of the default library decks selected
Player librarian = _playerDao.getPlayer("Librarian");
_hallServer.spoofNewTable(format, resourceOwner, librarian, deckName, timer, "(New Player) " + desc, isPrivate);
_hallServer.spoofNewTable(format, resourceOwner, librarian, deckName, timer, "(New Player) " + desc, isInviteOnly, isPrivate);
responseWriter.writeXmlResponse(null);
return;
}

View File

@@ -337,6 +337,11 @@ table.tables tr.privateForPlayer {
flex-grow:2;
}
.checkboxes {
display: grid;
min-width: max-content;
}
#tableDescInput {
min-width: 150px;
flex-grow: 1;

View File

@@ -223,7 +223,10 @@
<option value="glacial">Glacial (3d/1d)</option>
</select>
<input id='tableDescInput' type='text' maxlength='100' placeHolder='Description (or player to invite)'>
<label id="inviteCheckbox"><input type='checkbox' id='isPrivateCheckbox'>Invite Only</input></label>
<div class="checkboxes">
<label id="inviteCheckbox"><input type='checkbox' id='isInviteOnlyCheckbox'>Invite Only</input></label>
<label id="privateCheckbox"><input type='checkbox' id='isPrivateCheckbox'>Private</input></label>
</div>
<button id="createTableBut">Create table</button>
</div>
<div id="chat" class="flex-horiz" >

View File

@@ -652,7 +652,7 @@ var GempLotrCommunication = Class.extend({
dataType:"xml"
});
},
createTable:function (format, deckName, timer, desc, isPrivate, callback, errorMap) {
createTable:function (format, deckName, timer, desc, isPrivate, isInviteOnly, callback, errorMap) {
$.ajax({
type:"POST",
url:this.url + "/hall",
@@ -663,6 +663,7 @@ var GempLotrCommunication = Class.extend({
timer:timer,
desc:desc,
isPrivate:isPrivate,
isInviteOnly:isInviteOnly,
participantId:getUrlParam("participantId")},
success:this.deliveryCheck(callback),
error:this.errorCheck(errorMap),

View File

@@ -8,6 +8,7 @@ var GempLotrHallUI = Class.extend({
timerSelect:null,
createTableButton:null,
isPrivateCheckbox:null,
isInviteOnlyCheckbox:null,
tablesDiv:null,
buttonsDiv:null,
@@ -64,6 +65,7 @@ var GempLotrHallUI = Class.extend({
this.tablesDiv = $("#tablesDiv");
this.tableDescInput = $("#tableDescInput");
this.isPrivateCheckbox = $("#isPrivateCheckbox");
this.isInviteOnlyCheckbox = $("#isInviteOnlyCheckbox");
this.pocketDiv = $("#pocketDiv");
this.supportedFormatsSelect = $("#supportedFormatsSelect");
this.createTableButton = $("#createTableBut");
@@ -116,9 +118,10 @@ var GempLotrHallUI = Class.extend({
var tableDesc = that.tableDescInput.val();
var timer = that.timerSelect.val();
var isPrivate = that.isPrivateCheckbox.is(':checked');
var isInviteOnly = that.isInviteOnlyCheckbox.is(':checked');
if (deck != null)
console.log("creating table");
that.comm.createTable(format, deck, timer, tableDesc, isPrivate, function (xml) {
that.comm.createTable(format, deck, timer, tableDesc, isPrivate, isInviteOnly, function (xml) {
console.log("received table response");
that.processResponse(xml);
});
@@ -451,7 +454,8 @@ var GempLotrHallUI = Class.extend({
var tournamentName = table.getAttribute("tournament");
var userDesc = table.getAttribute("userDescription");
var isPrivate = (table.getAttribute("isPrivate") === "true");
var privateForYou = isPrivate && userDesc === chat.userName;
var isInviteOnly = (table.getAttribute("isInviteOnly") === "true");
var inviteForYou = isInviteOnly && userDesc === chat.userName;
var players = new Array();
if (playersAttr.length > 0)
players = playersAttr.split(",");
@@ -462,17 +466,38 @@ var GempLotrHallUI = Class.extend({
row.append("<td>" + formatName + "</td>");
var name = "<td>" + tournamentName;
if(!!userDesc)
if(isPrivate)
{
if(isPrivate)
if(!!userDesc)
{
name += " - <i>Match for user '" + userDesc + "'.";
if(isInviteOnly)
{
name += " - <i>Private match for user '" + userDesc + "'.";
}
else
{
name += " - <i>Private match: [" + userDesc + "]</i>";
}
}
else
{
name += " - <i>[" + userDesc + "]</i>";
else {
name += " - <i>Private.</i>";
}
}
else
{
if(!!userDesc)
{
if(isInviteOnly)
{
name += " - <i>Match for user '" + userDesc + "'.";
}
else
{
name += " - <i>[" + userDesc + "]</i>";
}
}
}
name += "</td>";
row.append(name);
row.append("<td>" + statusDescription + "</td>");
@@ -499,7 +524,7 @@ var GempLotrHallUI = Class.extend({
})(id));
lastField.append(but);
}
else if(!isPrivate || privateForYou) {
else if(!isInviteOnly || inviteForYou) {
var that = this;
var but = $("<button>Join Table</button>");
@@ -591,7 +616,7 @@ var GempLotrHallUI = Class.extend({
if (playing == "true")
row.addClass("played");
if(privateForYou)
if(inviteForYou)
row.addClass("privateForPlayer");
} else if (action == "remove") {
$(".table" + id, this.tablesDiv).remove();

View File

@@ -36,7 +36,7 @@ public class LotroGameMediator {
private final int _maxSecondsPerDecision;
private final boolean _allowSpectators;
private final boolean _cancellable;
private final boolean privateGame;
private final boolean _showInGameHall;
private final ReentrantReadWriteLock _lock = new ReentrantReadWriteLock(true);
private final ReentrantReadWriteLock.ReadLock _readLock = _lock.readLock();
@@ -45,13 +45,13 @@ public class LotroGameMediator {
private volatile boolean _destroyed;
public LotroGameMediator(String gameId, LotroFormat lotroFormat, LotroGameParticipant[] participants, LotroCardBlueprintLibrary library, int maxSecondsForGamePerPlayer,
int maxSecondsPerDecision, boolean allowSpectators, boolean cancellable, boolean privateGame) {
int maxSecondsPerDecision, boolean allowSpectators, boolean cancellable, boolean showInGameHall) {
_gameId = gameId;
_maxSecondsForGamePerPlayer = maxSecondsForGamePerPlayer;
_maxSecondsPerDecision = maxSecondsPerDecision;
_allowSpectators = allowSpectators;
_cancellable = cancellable;
this.privateGame = privateGame;
this._showInGameHall = showInGameHall;
if (participants.length < 1)
throw new IllegalArgumentException("Game can't have less than one participant");
@@ -68,7 +68,7 @@ public class LotroGameMediator {
}
public boolean isVisibleToUser(String username) {
return !privateGame || _playersPlaying.contains(username);
return !_showInGameHall || _playersPlaying.contains(username);
}
public boolean isDestroyed() {

View File

@@ -100,9 +100,19 @@ public class LotroServer extends AbstractServer {
_chatServer.createChatRoom(getChatRoomName(gameId), false, 30, false, null);
// Allow spectators for leagues, but not tournaments
boolean spectate = true;
if(gameSettings.getLeague() != null) {
spectate = true;
}
else if(gameSettings.isCompetitive()) {
spectate = false;
}
if(gameSettings.isPrivateGame()) {
spectate = false;
}
LotroGameMediator lotroGameMediator = new LotroGameMediator(gameId, gameSettings.getLotroFormat(), participants, _lotroCardBlueprintLibrary,
gameSettings.getMaxSecondsPerPlayer(), gameSettings.getMaxSecondsPerDecision(),
gameSettings.getLeague() != null || !gameSettings.isCompetitive(), !gameSettings.isCompetitive(), gameSettings.isPrivateGame());
spectate, !gameSettings.isCompetitive(), gameSettings.isHiddenGame());
lotroGameMediator.addGameResultListener(
new GameResultListener() {
@Override

View File

@@ -12,26 +12,28 @@ public class GameSettings {
private final LeagueSerieData leagueSerie;
private final boolean competitive;
private final boolean privateGame;
private final boolean hiddenGame;
private final String timerName;
private final int maxSecondsPerPlayer;
private final int maxSecondsPerDecision;
private final String userDescription;
private final boolean isPrivate;
private final boolean isInviteOnly;
public GameSettings(CollectionType collectionType, LotroFormat lotroFormat, League league, LeagueSerieData leagueSerie,
boolean competitive, boolean privateGame, String timerName, int maxSecondsPerPlayer, int maxSecondsPerDecision,
String description, boolean isPrivate) {
boolean competitive, boolean privateGame, boolean hiddenGame, String timerName, int maxSecondsPerPlayer, int maxSecondsPerDecision,
String description, boolean isInviteOnly) {
this.collectionType = collectionType;
this.lotroFormat = lotroFormat;
this.league = league;
this.leagueSerie = leagueSerie;
this.competitive = competitive;
this.privateGame = privateGame;
this.hiddenGame = hiddenGame;
this.timerName = timerName;
this.maxSecondsPerPlayer = maxSecondsPerPlayer;
this.maxSecondsPerDecision = maxSecondsPerDecision;
this.userDescription = description;
this.isPrivate = isPrivate;
this.isInviteOnly = isInviteOnly;
}
public CollectionType getCollectionType() {
@@ -58,6 +60,10 @@ public class GameSettings {
return privateGame;
}
public boolean isHiddenGame() {
return hiddenGame;
}
public int getMaxSecondsPerPlayer() {
return maxSecondsPerPlayer;
}
@@ -72,5 +78,5 @@ public class GameSettings {
public String getUserDescription() { return userDescription; }
public boolean isUserPrivateGame() { return isPrivate; }
public boolean isUserInviteOnly() { return isInviteOnly; }
}

View File

@@ -81,7 +81,7 @@ public class HallCommunicationChannel implements LongPollableResource {
}
@Override
public void visitTable(String tableId, String gameId, boolean watchable, TableStatus status, String statusDescription, String formatName, String tournamentName, String userDesc, List<String> playerIds, boolean playing, boolean isPrivate, String winner) {
public void visitTable(String tableId, String gameId, boolean watchable, TableStatus status, String statusDescription, String formatName, String tournamentName, String userDesc, List<String> playerIds, boolean playing, boolean isPrivate, boolean isInviteOnly, String winner) {
Map<String, String> props = new HashMap<>();
props.put("gameId", gameId);
props.put("watchable", String.valueOf(watchable));
@@ -90,6 +90,7 @@ public class HallCommunicationChannel implements LongPollableResource {
props.put("format", formatName);
props.put("userDescription", userDesc);
props.put("isPrivate", String.valueOf(isPrivate));
props.put("isInviteOnly", String.valueOf(isInviteOnly));
props.put("tournament", tournamentName);
props.put("players", StringUtils.join(playerIds, ","));
props.put("playing", String.valueOf(playing));

View File

@@ -11,7 +11,7 @@ public interface HallInfoVisitor {
public void motd(String motd);
public void visitTable(String tableId, String gameId, boolean watchable, TableStatus status, String statusDescription, String formatName, String tournamentName, String userDesc, List<String> playerIds, boolean playing, boolean isPrivate, String winner);
public void visitTable(String tableId, String gameId, boolean watchable, TableStatus status, String statusDescription, String formatName, String tournamentName, String userDesc, List<String> playerIds, boolean playing, boolean isPrivate, boolean isInviteOnly, String winner);
public void visitTournamentQueue(String tournamentQueueKey, int cost, String collectionName, String formatName, String tournamentQueueName, String tournamentPrizes,
String pairingDescription, String startCondition, int playerCount, boolean playerSignedUp, boolean joinable);

View File

@@ -344,11 +344,11 @@ public class HallServer extends AbstractServer {
/**
* @return If table created, otherwise <code>false</code> (if the user already is sitting at a table or playing).
*/
public void createNewTable(String type, Player player, String deckName, String timer, String description, boolean isPrivate) throws HallException {
public void createNewTable(String type, Player player, String deckName, String timer, String description, boolean isInviteOnly, boolean isPrivate) throws HallException {
if (_shutdown)
throw new HallException("Server is in shutdown mode. Server will be restarted after all running games are finished.");
GameSettings gameSettings = createGameSettings(type, timer, description, isPrivate);
GameSettings gameSettings = createGameSettings(type, timer, description, isInviteOnly, isPrivate);
LotroDeck lotroDeck = validateUserAndDeck(gameSettings.getLotroFormat(), player, deckName, gameSettings.getCollectionType());
@@ -364,11 +364,11 @@ public class HallServer extends AbstractServer {
}
}
public void spoofNewTable(String type, Player player, Player librarian, String deckName, String timer, String description, boolean isPrivate) throws HallException {
public void spoofNewTable(String type, Player player, Player librarian, String deckName, String timer, String description, boolean isInviteOnly, boolean isPrivate) throws HallException {
if (_shutdown)
throw new HallException("Server is in shutdown mode. Server will be restarted after all running games are finished.");
GameSettings gameSettings = createGameSettings(type, timer, description, isPrivate);
GameSettings gameSettings = createGameSettings(type, timer, description, isInviteOnly, isPrivate);
LotroDeck lotroDeck = validateUserAndDeck(gameSettings.getLotroFormat(), librarian, deckName, gameSettings.getCollectionType());
@@ -384,7 +384,7 @@ public class HallServer extends AbstractServer {
}
}
private GameSettings createGameSettings(String type, String timer, String description, boolean isPrivate) throws HallException {
private GameSettings createGameSettings(String type, String timer, String description, boolean isInviteOnly, boolean isPrivate) throws HallException {
League league = null;
LeagueSerieData leagueSerie = null;
CollectionType collectionType = _defaultCollectionType;
@@ -399,10 +399,14 @@ public class HallServer extends AbstractServer {
if (leagueSerie == null)
throw new HallException("There is no ongoing serie for that league");
if(isPrivate) {
if(isInviteOnly) {
throw new HallException("League games cannot be invite-only");
}
if(isPrivate) {
throw new HallException("League games cannot be private");
}
//Don't want people getting around the anonymity for leagues.
if(description != null)
description = "";
@@ -418,7 +422,7 @@ public class HallServer extends AbstractServer {
throw new HallException("This format is not supported: " + type);
return new GameSettings(collectionType, format, league, leagueSerie,
league != null, gameTimer.isLongGame(), gameTimer.getName(), gameTimer.getMaxSecondsPerPlayer(), gameTimer.getMaxSecondsPerDecision(), description, isPrivate);
league != null, isPrivate, gameTimer.isLongGame(), gameTimer.getName(), gameTimer.getMaxSecondsPerPlayer(), gameTimer.getMaxSecondsPerDecision(), description, isInviteOnly);
}
private GameTimer resolveTimer(String timer) {
@@ -874,7 +878,7 @@ public class HallServer extends AbstractServer {
private HallTournamentCallback(Tournament tournament) {
_tournament = tournament;
tournamentGameSettings = new GameSettings(null, _formatLibrary.getFormat(_tournament.getFormat()),
null, null, true, false, "Tournament", 60 * 40, 60 * 5, null, false);
null, null, true, false, false, "Tournament", 60 * 40, 60 * 5, null, false);
}
@Override

View File

@@ -177,7 +177,7 @@ public class TableHolder {
players = table.getPlayerNames();
if (isAdmin || isNoIgnores(players, player.getName()))
visitor.visitTable(tableInformation.getKey(), null, false, HallInfoVisitor.TableStatus.WAITING, "Waiting", table.getGameSettings().getLotroFormat().getName(), getTournamentName(table), table.getGameSettings().getUserDescription(), players, table.getPlayerNames().contains(player.getName()), table.getGameSettings().isUserPrivateGame(), null);
visitor.visitTable(tableInformation.getKey(), null, false, HallInfoVisitor.TableStatus.WAITING, "Waiting", table.getGameSettings().getLotroFormat().getName(), getTournamentName(table), table.getGameSettings().getUserDescription(), players, table.getPlayerNames().contains(player.getName()), table.getGameSettings().isPrivateGame(), table.getGameSettings().isUserInviteOnly(), null);
}
// Then non-finished
@@ -192,7 +192,7 @@ public class TableHolder {
if (lotroGameMediator.isFinished())
finishedTables.put(runningGame.getKey(), runningTable);
else
visitor.visitTable(runningGame.getKey(), lotroGameMediator.getGameId(), isAdmin || lotroGameMediator.isAllowSpectators(), HallInfoVisitor.TableStatus.PLAYING, lotroGameMediator.getGameStatus(), runningTable.getGameSettings().getLotroFormat().getName(), getTournamentName(runningTable), runningTable.getGameSettings().getUserDescription(), lotroGameMediator.getPlayersPlaying(), lotroGameMediator.getPlayersPlaying().contains(player.getName()), runningTable.getGameSettings().isUserPrivateGame(), lotroGameMediator.getWinner());
visitor.visitTable(runningGame.getKey(), lotroGameMediator.getGameId(), isAdmin || lotroGameMediator.isAllowSpectators(), HallInfoVisitor.TableStatus.PLAYING, lotroGameMediator.getGameStatus(), runningTable.getGameSettings().getLotroFormat().getName(), getTournamentName(runningTable), runningTable.getGameSettings().getUserDescription(), lotroGameMediator.getPlayersPlaying(), lotroGameMediator.getPlayersPlaying().contains(player.getName()), runningTable.getGameSettings().isPrivateGame(), runningTable.getGameSettings().isUserInviteOnly(), lotroGameMediator.getWinner());
if (!lotroGameMediator.isFinished() && lotroGameMediator.getPlayersPlaying().contains(player.getName()))
visitor.runningPlayerGame(lotroGameMediator.getGameId());
@@ -206,7 +206,7 @@ public class TableHolder {
LotroGameMediator lotroGameMediator = runningTable.getLotroGameMediator();
if (lotroGameMediator != null) {
if (isAdmin || isNoIgnores(lotroGameMediator.getPlayersPlaying(), player.getName()))
visitor.visitTable(nonPlayingGame.getKey(), lotroGameMediator.getGameId(), false, HallInfoVisitor.TableStatus.FINISHED, lotroGameMediator.getGameStatus(), runningTable.getGameSettings().getLotroFormat().getName(), getTournamentName(runningTable), runningTable.getGameSettings().getUserDescription(), lotroGameMediator.getPlayersPlaying(), lotroGameMediator.getPlayersPlaying().contains(player.getName()), runningTable.getGameSettings().isUserPrivateGame(), lotroGameMediator.getWinner());
visitor.visitTable(nonPlayingGame.getKey(), lotroGameMediator.getGameId(), false, HallInfoVisitor.TableStatus.FINISHED, lotroGameMediator.getGameStatus(), runningTable.getGameSettings().getLotroFormat().getName(), getTournamentName(runningTable), runningTable.getGameSettings().getUserDescription(), lotroGameMediator.getPlayersPlaying(), lotroGameMediator.getPlayersPlaying().contains(player.getName()), runningTable.getGameSettings().isPrivateGame(), runningTable.getGameSettings().isUserInviteOnly(), lotroGameMediator.getWinner());
}
}
}