server, refactor: added client side info about current table and parent table (tourney's sub-tables with matches);

This commit is contained in:
Oleg Agafonov 2024-08-11 19:29:42 +04:00
parent bd7aaa34ee
commit 7916af0e52
21 changed files with 315 additions and 161 deletions

View file

@ -37,7 +37,7 @@ import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
/**
* @author BetaSteward_at_googlemail.com
* @author BetaSteward_at_googlemail.com, JayDi85
*/
public class TableController {
@ -204,7 +204,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.ccJoinedTable(table.getRoomId(), table.getId(), table.getParentTableId(), true);
userPlayerMap.put(userId, player.getId());
}
@ -394,7 +394,7 @@ public class TableController {
if (!table.isTournamentSubTable()) {
user.addTable(player.getId(), table);
}
user.ccJoinedTable(table.getRoomId(), table.getId(), false);
user.ccJoinedTable(table.getRoomId(), table.getId(), table.getParentTableId(), false);
userPlayerMap.put(userId, player.getId());
}
@ -524,7 +524,7 @@ public class TableController {
public boolean watchTable(UUID userId) {
if (table.isTournament()) {
managerFactory.userManager().getUser(userId).ifPresent(user -> user.ccShowTournament(table.getTournament().getId()));
managerFactory.userManager().getUser(userId).ifPresent(user -> user.ccShowTournament(table.getId(), table.getTournament().getId()));
return true;
} else {
if (table.isTournamentSubTable() && !table.getTournament().getOptions().isWatchingAllowed()) {
@ -541,7 +541,7 @@ public class TableController {
if (!_user.isPresent()) {
return false;
}
return _user.get().ccWatchGame(match.getGame().getId());
return _user.get().ccWatchGame(table.getId(), table.getParentTableId(), match.getGame().getId());
}
}
@ -685,7 +685,7 @@ public class TableController {
Optional<User> _user = managerFactory.userManager().getUser(entry.getKey());
if (_user.isPresent()) {
User user = _user.get();
user.ccGameStarted(match.getGame().getId(), entry.getValue());
user.ccGameStarted(table.getId(), table.getParentTableId(), match.getGame().getId(), entry.getValue());
if (creator == null) {
creator = user.getName();
@ -744,7 +744,7 @@ public class TableController {
for (Entry<UUID, UUID> entry : userPlayerMap.entrySet()) {
managerFactory.userManager().getUser(entry.getKey()).ifPresent(user -> {
logger.info(new StringBuilder("User ").append(user.getName()).append(" tournament started: ").append(tournament.getId()).append(" userId: ").append(user.getId()));
user.ccTournamentStarted(tournament.getId(), entry.getValue());
user.ccTournamentStarted(table.getId(), tournament.getId(), entry.getValue());
});
}
ServerMessagesUtil.instance.incTournamentsStarted();
@ -757,13 +757,13 @@ public class TableController {
}
public void startDraft(Draft draft) {
table.initDraft();
table.initDraft(draft);
managerFactory.draftManager().createDraftSession(draft, userPlayerMap, table.getId());
for (Entry<UUID, UUID> entry : userPlayerMap.entrySet()) {
Optional<User> user = managerFactory.userManager().getUser(entry.getKey());
if (user.isPresent()) {
logger.info(new StringBuilder("User ").append(user.get().getName()).append(" draft started: ").append(draft.getId()).append(" userId: ").append(user.get().getId()));
user.get().ccDraftStarted(draft.getId(), entry.getValue());
user.get().ccDraftStarted(table.getId(), draft.getId(), entry.getValue());
} else {
logger.fatal(new StringBuilder("Start draft user not found userId: ").append(entry.getKey()));
}
@ -776,7 +776,7 @@ public class TableController {
if (entry.getValue().equals(playerId)) {
Optional<User> user = managerFactory.userManager().getUser(entry.getKey());
int remaining = (int) futureTimeout.getDelay(TimeUnit.SECONDS);
user.ifPresent(user1 -> user1.ccSideboard(deck, table.getId(), remaining, options.isLimited()));
user.ifPresent(user1 -> user1.ccSideboard(deck, table.getId(), table.getParentTableId(), remaining, options.isLimited()));
break;
}
}