Added support for user-defined table descriptions

This commit is contained in:
Christian 'ketura' McCarty
2022-08-24 01:05:25 -05:00
parent 5cf8c6d6a6
commit c835336e61
9 changed files with 69 additions and 51 deletions

View File

@@ -125,30 +125,32 @@ public class HallRequestHandler extends LotroServerRequestHandler implements Uri
private void createTable(HttpRequest request, ResponseWriter responseWriter) throws Exception {
HttpPostRequestDecoder postDecoder = new HttpPostRequestDecoder(request);
try {
String participantId = getFormParameterSafely(postDecoder, "participantId");
String format = getFormParameterSafely(postDecoder, "format");
String deckName = getFormParameterSafely(postDecoder, "deckName");
String timer = getFormParameterSafely(postDecoder, "timer");
String participantId = getFormParameterSafely(postDecoder, "participantId");
String format = getFormParameterSafely(postDecoder, "format");
String deckName = getFormParameterSafely(postDecoder, "deckName");
String timer = getFormParameterSafely(postDecoder, "timer");
String desc = getFormParameterSafely(postDecoder, "desc");
Player resourceOwner = getResourceOwnerSafely(request, participantId);
Player resourceOwner = getResourceOwnerSafely(request, participantId);
try {
_hallServer.createNewTable(format, resourceOwner, deckName, timer);
responseWriter.writeXmlResponse(null);
} catch (HallException e) {
try
{
//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);
try {
_hallServer.createNewTable(format, resourceOwner, deckName, timer, desc);
responseWriter.writeXmlResponse(null);
} catch (HallException ex) {
}
catch (HallException e) {
try
{
//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);
responseWriter.writeXmlResponse(null);
}
catch (HallException ex) { }
responseWriter.writeXmlResponse(marshalException(e));
}
}
} finally {
finally {
postDecoder.destroy();
}
}
@@ -347,21 +349,23 @@ public class HallRequestHandler extends LotroServerRequestHandler implements Uri
private void updateHall(HttpRequest request, ResponseWriter responseWriter) throws Exception {
HttpPostRequestDecoder postDecoder = new HttpPostRequestDecoder(request);
try {
String participantId = getFormParameterSafely(postDecoder, "participantId");
int channelNumber = Integer.parseInt(getFormParameterSafely(postDecoder, "channelNumber"));
String participantId = getFormParameterSafely(postDecoder, "participantId");
int channelNumber = Integer.parseInt(getFormParameterSafely(postDecoder, "channelNumber"));
Player resourceOwner = getResourceOwnerSafely(request, participantId);
processLoginReward(resourceOwner.getName());
Player resourceOwner = getResourceOwnerSafely(request, participantId);
processLoginReward(resourceOwner.getName());
try {
HallCommunicationChannel pollableResource = _hallServer.getCommunicationChannel(resourceOwner, channelNumber);
HallUpdateLongPollingResource polledResource = new HallUpdateLongPollingResource(pollableResource, request, resourceOwner, responseWriter);
longPollingSystem.processLongPollingResource(polledResource, pollableResource);
} catch (SubscriptionExpiredException exp) {
responseWriter.writeError(410);
} catch (SubscriptionConflictException exp) {
responseWriter.writeError(409);
}
try {
HallCommunicationChannel pollableResource = _hallServer.getCommunicationChannel(resourceOwner, channelNumber);
HallUpdateLongPollingResource polledResource = new HallUpdateLongPollingResource(pollableResource, request, resourceOwner, responseWriter);
longPollingSystem.processLongPollingResource(polledResource, pollableResource);
}
catch (SubscriptionExpiredException exp) {
responseWriter.writeError(410);
}
catch (SubscriptionConflictException exp) {
responseWriter.writeError(409);
}
} finally {
postDecoder.destroy();
}

View File

@@ -162,7 +162,7 @@
</li>
<li><a href="includes/stats.html">
<span class="custom-icon icon-stats" style="display:inline-block"></span>
<span>Server Stats</span>
<span>Server Info</span>
</a>
</li>
<li><a href="includes/user.html">
@@ -286,6 +286,7 @@
|
<select id="supportedFormatsSelect" style='width: 180px'></select>
<select id="decksSelect" style="width: 220px;flex-grow:1;"></select>
<input id='tableDescInput' type='text' maxlength='50' style='width: 150px;' placeHolder='Description (optional)'>
<select id="timerSelect" style="width: 135px;">
<option value="default">Default (80m/5m)</option>
<option value="blitz">Blitz! (30m/3m)</option>

View File

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

View File

@@ -4,6 +4,7 @@ var GempLotrHallUI = Class.extend({
supportedFormatsInitialized:false,
supportedFormatsSelect:null,
decksSelect:null,
tableDescInput:null,
timerSelect:null,
createTableButton:null,
@@ -34,6 +35,7 @@ var GempLotrHallUI = Class.extend({
this.chat = chat;
this.tablesDiv = $("#tablesDiv");
this.tableDescInput = $("#tableDescInput");
var hallSettingsStr = $.cookie("hallSettings");
if (hallSettingsStr == null)
@@ -62,17 +64,14 @@ var GempLotrHallUI = Class.extend({
this.createTableButton = $("#createTableBut");
$(this.createTableButton).button().click(
function () {
//that.supportedFormatsSelect.hide();
//that.decksSelect.hide();
that.createTableButton.hide();
// $("#createTableBut").prop("disabled", true);
// $("#createTableBut").prop("aria-disabled", true);
var format = that.supportedFormatsSelect.val();
var deck = that.decksSelect.val();
var tableDesc = that.tableDescInput.val();
var timer = that.timerSelect.val();
if (deck != null)
console.log("creating table");
that.comm.createTable(format, deck, timer, function (xml) {
that.comm.createTable(format, deck, timer, tableDesc, function (xml) {
console.log("received table response");
that.processResponse(xml);
});
@@ -406,6 +405,7 @@ var GempLotrHallUI = Class.extend({
var playersAttr = table.getAttribute("players");
var formatName = table.getAttribute("format");
var tournamentName = table.getAttribute("tournament");
var userDesc = table.getAttribute("userDescription");
var players = new Array();
if (playersAttr.length > 0)
players = playersAttr.split(",");
@@ -415,7 +415,13 @@ var GempLotrHallUI = Class.extend({
var row = $("<tr class='table" + id + "'></tr>");
row.append("<td>" + formatName + "</td>");
row.append("<td>" + tournamentName + "</td>");
var name = "<td>" + tournamentName;
if(!!userDesc)
{
name += " - <i>[" + userDesc + "]</i>";
}
name += "</td>";
row.append(name);
row.append("<td>" + statusDescription + "</td>");
var playersStr = "";

View File

@@ -15,9 +15,11 @@ public class GameSettings {
private final String timerName;
private final int maxSecondsPerPlayer;
private final int maxSecondsPerDecision;
private final String userDescription;
public GameSettings(CollectionType collectionType, LotroFormat lotroFormat, League league, LeagueSerieData leagueSerie,
boolean competitive, boolean privateGame, String timerName, int maxSecondsPerPlayer, int maxSecondsPerDecision) {
boolean competitive, boolean privateGame, String timerName, int maxSecondsPerPlayer, int maxSecondsPerDecision,
String description) {
this.collectionType = collectionType;
this.lotroFormat = lotroFormat;
this.league = league;
@@ -27,6 +29,7 @@ public class GameSettings {
this.timerName = timerName;
this.maxSecondsPerPlayer = maxSecondsPerPlayer;
this.maxSecondsPerDecision = maxSecondsPerDecision;
this.userDescription = description;
}
public CollectionType getCollectionType() {
@@ -64,4 +67,6 @@ public class GameSettings {
public String getTimerName() {
return timerName;
}
public String getUserDescription() { return userDescription; }
}

View File

@@ -81,13 +81,14 @@ public class HallCommunicationChannel implements LongPollableResource {
}
@Override
public void visitTable(String tableId, String gameId, boolean watchable, TableStatus status, String statusDescription, String formatName, String tournamentName, List<String> playerIds, boolean playing, 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, String winner) {
Map<String, String> props = new HashMap<>();
props.put("gameId", gameId);
props.put("watchable", String.valueOf(watchable));
props.put("status", String.valueOf(status));
props.put("statusDescription", statusDescription);
props.put("format", formatName);
props.put("userDescription", userDesc);
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, List<String> playerIds, boolean playing, 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, 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

@@ -319,11 +319,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) throws HallException {
public void createNewTable(String type, Player player, String deckName, String timer, String description) 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);
GameSettings gameSettings = createGameSettings(type, timer, description);
LotroDeck lotroDeck = validateUserAndDeck(gameSettings.getLotroFormat(), player, deckName, gameSettings.getCollectionType());
@@ -339,11 +339,11 @@ public class HallServer extends AbstractServer {
}
}
public void spoofNewTable(String type, Player player, Player librarian, String deckName, String timer) throws HallException {
public void spoofNewTable(String type, Player player, Player librarian, String deckName, String timer, String description) 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);
GameSettings gameSettings = createGameSettings(type, timer, description);
LotroDeck lotroDeck = validateUserAndDeck(gameSettings.getLotroFormat(), librarian, deckName, gameSettings.getCollectionType());
@@ -359,7 +359,7 @@ public class HallServer extends AbstractServer {
}
}
private GameSettings createGameSettings(String type, String timer) throws HallException {
private GameSettings createGameSettings(String type, String timer, String description) throws HallException {
League league = null;
LeagueSerieData leagueSerie = null;
CollectionType collectionType = _defaultCollectionType;
@@ -385,7 +385,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());
league != null, gameTimer.isLongGame(), gameTimer.getName(), gameTimer.getMaxSecondsPerPlayer(), gameTimer.getMaxSecondsPerDecision(), description);
}
private GameTimer resolveTimer(String timer) {
@@ -812,7 +812,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, null, true, false, "Tournament", 60 * 40, 60 * 5, null);
}
@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), players, table.getPlayerNames().contains(player.getName()), 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()), 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), lotroGameMediator.getPlayersPlaying(), lotroGameMediator.getPlayersPlaying().contains(player.getName()), 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()), 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), lotroGameMediator.getPlayersPlaying(), lotroGameMediator.getPlayersPlaying().contains(player.getName()), 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()), lotroGameMediator.getWinner());
}
}
}