Fixed new player library decks not actually allowing the player to create or join a table.

This commit is contained in:
Christian 'ketura' McCarty
2022-08-03 15:56:43 -05:00
parent bcf475e00a
commit 6e2f730560
3 changed files with 69 additions and 14 deletions

View File

@@ -54,27 +54,27 @@ public class HallRequestHandler extends LotroServerRequestHandler implements Uri
@Override
public void handleRequest(String uri, HttpRequest request, Map<Type, Object> context, ResponseWriter responseWriter, String remoteIp) throws Exception {
if (uri.equals("") && request.getMethod() == HttpMethod.GET) {
if (uri.equals("") && request.method() == HttpMethod.GET) {
getHall(request, responseWriter);
} else if (uri.equals("") && request.getMethod() == HttpMethod.POST) {
} else if (uri.equals("") && request.method() == HttpMethod.POST) {
createTable(request, responseWriter);
} else if (uri.equals("/update") && request.getMethod() == HttpMethod.POST) {
} else if (uri.equals("/update") && request.method() == HttpMethod.POST) {
updateHall(request, responseWriter);
} else if (uri.equals("/formats/html") && request.getMethod() == HttpMethod.GET) {
} else if (uri.equals("/formats/html") && request.method() == HttpMethod.GET) {
getFormats(request, responseWriter);
} else if (uri.startsWith("/format/") && request.getMethod() == HttpMethod.GET) {
} else if (uri.startsWith("/format/") && request.method() == HttpMethod.GET) {
getFormat(request, uri.substring(8), responseWriter);
} else if (uri.startsWith("/queue/") && request.getMethod() == HttpMethod.POST) {
} else if (uri.startsWith("/queue/") && request.method() == HttpMethod.POST) {
if (uri.endsWith("/leave")) {
leaveQueue(request, uri.substring(7, uri.length() - 6), responseWriter);
} else {
joinQueue(request, uri.substring(7), responseWriter);
}
} else if (uri.startsWith("/tournament/") && uri.endsWith("/leave") && request.getMethod() == HttpMethod.POST) {
} else if (uri.startsWith("/tournament/") && uri.endsWith("/leave") && request.method() == HttpMethod.POST) {
dropFromTournament(request, uri.substring(12, uri.length() - 6), responseWriter);
} else if (uri.startsWith("/") && uri.endsWith("/leave") && request.getMethod() == HttpMethod.POST) {
} else if (uri.startsWith("/") && uri.endsWith("/leave") && request.method() == HttpMethod.POST) {
leaveTable(request, uri.substring(1, uri.length() - 6), responseWriter);
} else if (uri.startsWith("/") && request.getMethod() == HttpMethod.POST) {
} else if (uri.startsWith("/") && request.method() == HttpMethod.POST) {
joinTable(request, uri.substring(1), responseWriter);
} else {
responseWriter.writeError(404);
@@ -93,6 +93,15 @@ public class HallRequestHandler extends LotroServerRequestHandler implements Uri
_hallServer.joinTableAsPlayer(tableId, resourceOwner, deckName);
responseWriter.writeXmlResponse(null);
} catch (HallException e) {
try {
//Try again assuming it's a new player using the default deck library decks
Player libraryOwner = _playerDao.getPlayer("Librarian");
_hallServer.joinTableAsPlayerWithSpoofedDeck(tableId, resourceOwner, libraryOwner, deckName);
responseWriter.writeXmlResponse(null);
return;
} catch (HallException ex) {
}
responseWriter.writeXmlResponse(marshalException(e));
}
} finally {
@@ -127,6 +136,16 @@ public class HallRequestHandler extends LotroServerRequestHandler implements Uri
_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);
responseWriter.writeXmlResponse(null);
} catch (HallException ex) {
}
responseWriter.writeXmlResponse(marshalException(e));
}
} finally {

View File

@@ -313,10 +313,8 @@ var GempLotrHallUI = Class.extend({
updateHall:function () {
var that = this;
console.log("updating");
this.comm.updateHall(
function (xml) {
console.log("calling process");
that.processHall(xml);
}, this.hallChannelId, this.hallErrorMap());
},
@@ -444,8 +442,6 @@ var GempLotrHallUI = Class.extend({
processHall:function (xml) {
var that = this;
console.log("processing");
var root = xml.documentElement;
if (root.tagName == "hall") {
this.hallChannelId = root.getAttribute("channelNumber");
@@ -756,7 +752,6 @@ var GempLotrHallUI = Class.extend({
// this.createTableButton.prop("disabled", false);
setTimeout(function () {
console.log("set timeout");
that.updateHall();
}, 100);
}

View File

@@ -339,6 +339,26 @@ public class HallServer extends AbstractServer {
}
}
public void spoofNewTable(String type, Player player, Player librarian, String deckName, String timer) 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);
LotroDeck lotroDeck = validateUserAndDeck(gameSettings.getLotroFormat(), librarian, deckName, gameSettings.getCollectionType());
_hallDataAccessLock.writeLock().lock();
try {
final GameTable table = tableHolder.createTable(player, gameSettings, lotroDeck);
if (table != null)
createGameFromTable(table);
hallChanged();
} finally {
_hallDataAccessLock.writeLock().unlock();
}
}
private GameSettings createGameSettings(String type, String timer) throws HallException {
League league = null;
LeagueSerieData leagueSerie = null;
@@ -431,6 +451,27 @@ public class HallServer extends AbstractServer {
}
}
public boolean joinTableAsPlayerWithSpoofedDeck(String tableId, Player player, Player librarian, String deckName) throws HallException {
if (_shutdown)
throw new HallException("Server is in shutdown mode. Server will be restarted after all running games are finished.");
GameSettings gameSettings = tableHolder.getGameSettings(tableId);
LotroDeck lotroDeck = validateUserAndDeck(gameSettings.getLotroFormat(), librarian, deckName, gameSettings.getCollectionType());
_hallDataAccessLock.writeLock().lock();
try {
final GameTable runningTable = tableHolder.joinTable(tableId, player, lotroDeck);
if (runningTable != null)
createGameFromTable(runningTable);
hallChanged();
return true;
} finally {
_hallDataAccessLock.writeLock().unlock();
}
}
public void leaveQueue(String queueId, Player player) {
_hallDataAccessLock.writeLock().lock();
try {