mirror of
https://github.com/magefree/mage.git
synced 2025-12-22 03:22:00 -08:00
* Added option to start matches with password protection.
This commit is contained in:
parent
36ef4c3bcf
commit
8f690f7e02
19 changed files with 151 additions and 42 deletions
|
|
@ -219,7 +219,7 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean joinTable(final String sessionId, final UUID roomId, final UUID tableId, final String name, final String playerType, final int skill, final DeckCardLists deckList) throws MageException, GameException {
|
||||
public boolean joinTable(final String sessionId, final UUID roomId, final UUID tableId, final String name, final String playerType, final int skill, final DeckCardLists deckList, final String password) throws MageException, GameException {
|
||||
return executeWithResult("joinTable", sessionId, new ActionWithBooleanResult() {
|
||||
@Override
|
||||
public Boolean execute() throws MageException {
|
||||
|
|
@ -229,7 +229,7 @@ public class MageServerImpl implements MageServer {
|
|||
logger.fatal("Got no userId from sessionId" + sessionId + " tableId" + tableId);
|
||||
return false;
|
||||
}
|
||||
boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinTable(userId, tableId, name, playerType, skill, deckList);
|
||||
boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinTable(userId, tableId, name, playerType, skill, deckList, password);
|
||||
return ret;
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -208,7 +208,7 @@ public class TableController {
|
|||
return true;
|
||||
}
|
||||
|
||||
public synchronized boolean joinTable(UUID userId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException {
|
||||
public synchronized boolean joinTable(UUID userId, String name, String playerType, int skill, DeckCardLists deckList, String password) throws MageException {
|
||||
User user = UserManager.getInstance().getUser(userId);
|
||||
if (user == null) {
|
||||
return false;
|
||||
|
|
@ -217,6 +217,13 @@ public class TableController {
|
|||
user.showUserMessage("Join Table", "No available seats.");
|
||||
return false;
|
||||
}
|
||||
// check password
|
||||
if (!table.getMatch().getOptions().getPassword().isEmpty()) {
|
||||
if (!table.getMatch().getOptions().getPassword().equals(password)) {
|
||||
user.showUserMessage("Join Table", "Wrong password.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Seat seat = table.getNextAvailableSeat(playerType);
|
||||
if (seat == null) {
|
||||
user.showUserMessage("Join Table", "No available seats.");
|
||||
|
|
@ -240,7 +247,7 @@ public class TableController {
|
|||
|
||||
Player player = createPlayer(name, seat.getPlayerType(), skill);
|
||||
if (player == null) {
|
||||
String message = new StringBuilder("Could not create player ").append(name).append(" of type ").append(seat.getPlayerType().toString()).toString();
|
||||
String message = new StringBuilder("Could not create player ").append(name).append(" of type ").append(seat.getPlayerType()).toString();
|
||||
logger.warn(new StringBuilder("User: ").append(user.getName()).append(" => ").append(message).toString());
|
||||
user.showUserMessage("Join Table",message);
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -141,9 +141,9 @@ public class TableManager {
|
|||
return controllers.get(tableId);
|
||||
}
|
||||
|
||||
public boolean joinTable(UUID userId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException {
|
||||
public boolean joinTable(UUID userId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList, String password) throws MageException {
|
||||
if (controllers.containsKey(tableId)) {
|
||||
return controllers.get(tableId).joinTable(userId, name, playerType, skill, deckList);
|
||||
return controllers.get(tableId).joinTable(userId, name, playerType, skill, deckList, password);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ public interface GamesRoom extends Room {
|
|||
List<TableView> getTables();
|
||||
List<MatchView> getFinished();
|
||||
List<RoomUsersView> getRoomUsersInfo();
|
||||
boolean joinTable(UUID userId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException;
|
||||
boolean joinTable(UUID userId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList, String password) throws MageException;
|
||||
boolean joinTournamentTable(UUID userId, UUID tableId, String name, String playerType, int skill) throws GameException;
|
||||
TableView createTable(UUID userId, MatchOptions options);
|
||||
TableView createTournamentTable(UUID userId, TournamentOptions options);
|
||||
|
|
|
|||
|
|
@ -139,9 +139,9 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean joinTable(UUID userId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException {
|
||||
public boolean joinTable(UUID userId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList, String password) throws MageException {
|
||||
if (tables.containsKey(tableId)) {
|
||||
return TableManager.getInstance().joinTable(userId, tableId, name, playerType, skill, deckList);
|
||||
return TableManager.getInstance().joinTable(userId, tableId, name, playerType, skill, deckList, password);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue