mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
handle table join and waiting
This commit is contained in:
parent
c47da1f5b3
commit
dcd2907112
28 changed files with 538 additions and 151 deletions
|
|
@ -470,22 +470,22 @@ public class Main implements MageServer {
|
|||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// //FIXME: why no sessionId here???
|
||||
// public TableView getTable(UUID roomId, UUID tableId) throws MageException {
|
||||
@Override
|
||||
//FIXME: why no sessionId here???
|
||||
public TableView getTable(UUID roomId, UUID tableId) {
|
||||
// try {
|
||||
// GamesRoom room = GamesRoomManager.getInstance().getRoom(roomId);
|
||||
// if (room != null) {
|
||||
// return room.getTable(tableId);
|
||||
// } else {
|
||||
// return null;
|
||||
// }
|
||||
GamesRoom room = GamesRoomManager.getInstance().getRoom(roomId);
|
||||
if (room != null) {
|
||||
return room.getTable(tableId);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
// }
|
||||
// catch (Exception ex) {
|
||||
// handleException(ex);
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
}
|
||||
//
|
||||
// @Override
|
||||
// public boolean ping(String sessionId, String pingInfo) {
|
||||
|
|
@ -674,22 +674,22 @@ public class Main implements MageServer {
|
|||
// });
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean leaveTable(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
// TableState tableState = TableManager.getInstance().getController(tableId).getTableState();
|
||||
// if (!tableState.equals(TableState.WAITING) && !tableState.equals(TableState.READY_TO_START)) {
|
||||
// // table was already started, so player can't leave anymore now
|
||||
// return false;
|
||||
// }
|
||||
@Override
|
||||
public boolean leaveTable(final String sessionId, final UUID roomId, final UUID tableId) {
|
||||
TableState tableState = TableManager.getInstance().getController(tableId).getTableState();
|
||||
if (!tableState.equals(TableState.WAITING) && !tableState.equals(TableState.READY_TO_START)) {
|
||||
// table was already started, so player can't leave anymore now
|
||||
return false;
|
||||
}
|
||||
// execute("leaveTable", sessionId, new Action() {
|
||||
// @Override
|
||||
// public void execute() {
|
||||
// UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
// GamesRoomManager.getInstance().getRoom(roomId).leaveTable(userId, tableId);
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
GamesRoomManager.getInstance().getRoom(roomId).leaveTable(userId, tableId);
|
||||
// }
|
||||
// });
|
||||
// return true;
|
||||
// }
|
||||
return true;
|
||||
}
|
||||
//
|
||||
// @Override
|
||||
// //FIXME: why no sessionId here???
|
||||
|
|
@ -1377,4 +1377,8 @@ public class Main implements MageServer {
|
|||
return testMode;
|
||||
}
|
||||
|
||||
public void joinedTable(String sessionId, UUID roomId, UUID tableId, UUID chatId, boolean owner, boolean tournament) {
|
||||
server.joinedTable(sessionId, roomId, tableId, chatId, owner, tournament);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import mage.MageException;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
|
|
@ -222,7 +221,7 @@ public class TableController {
|
|||
if (seat.getPlayer().isHuman()) {
|
||||
seat.getPlayer().setUserData(user.getUserData());
|
||||
user.addTable(player.getId(), table);
|
||||
user.ccJoinedTable(table.getRoomId(), table.getId(), true);
|
||||
user.joinedTable(table.getRoomId(), table.getId(), chatId, isOwner(userId), true);
|
||||
userPlayerMap.put(userId, player.getId());
|
||||
}
|
||||
|
||||
|
|
@ -325,7 +324,7 @@ public class TableController {
|
|||
if (!table.isTournamentSubTable()) {
|
||||
user.addTable(player.getId(), table);
|
||||
}
|
||||
user.ccJoinedTable(table.getRoomId(), table.getId(), false);
|
||||
user.joinedTable(table.getRoomId(), table.getId(), chatId, isOwner(userId), false);
|
||||
userPlayerMap.put(userId, player.getId());
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -188,8 +188,9 @@ public class User {
|
|||
}
|
||||
}
|
||||
|
||||
public void ccJoinedTable(final UUID roomId, final UUID tableId, boolean isTournament) {
|
||||
fireCallback(new ClientCallback("joinedTable", tableId, new TableClientMessage(roomId, tableId, isTournament)));
|
||||
public void joinedTable(final UUID roomId, final UUID tableId, final UUID chatId, boolean owner, boolean tournament) {
|
||||
// fireCallback(new ClientCallback("joinedTable", tableId, new TableClientMessage(roomId, tableId, isTournament)));
|
||||
Main.getInstance().joinedTable(sessionId, roomId, tableId, chatId, owner, tournament);
|
||||
}
|
||||
|
||||
public void ccGameStarted(final UUID gameId, final UUID playerId) {
|
||||
|
|
@ -285,7 +286,8 @@ public class User {
|
|||
|
||||
private void reconnect() {
|
||||
for (Entry<UUID, Table> entry: tables.entrySet()) {
|
||||
ccJoinedTable(entry.getValue().getRoomId(), entry.getValue().getId(), entry.getValue().isTournament());
|
||||
Table t = entry.getValue();
|
||||
joinedTable(t.getRoomId(), t.getId(), TableManager.getInstance().getChatId(t.getId()), TableManager.getInstance().isTableOwner(t.getId(), userId), t.isTournament());
|
||||
}
|
||||
for (Entry<UUID, UUID> entry: userTournaments.entrySet()) {
|
||||
TournamentController tournamentController = TournamentManager.getInstance().getTournamentController(entry.getValue());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue