Tournament is now without admins

This commit is contained in:
Bas de Jong
2026-01-10 22:47:53 +01:00
parent 97657b01c9
commit 28791fcc8a
3 changed files with 49 additions and 33 deletions

View File

@@ -45,6 +45,19 @@ public final class ServerView extends ViewWidget {
private void setupLayout(String userName) {
var playerHeader = Primitive.header(user, false);
if (userName.equals("host")) {
var tournamentButton = Primitive.hbox(
gameListTour,
Primitive.button(
"tournament",
() -> GlobalEventBus.get().post(new NetworkEvents.SendCommand(clientId, "tournament", "start", gameListTour.getValue())),
false,
false
)
);
add(Pos.BOTTOM_CENTER, tournamentButton);
} else {
subscribeButton = Primitive.button(
"subscribe",
() -> new EventFlow().addPostEvent(new NetworkEvents.SendSubscribe(clientId, gameListSub.getValue())).postEvent(),
@@ -63,25 +76,12 @@ public final class ServerView extends ViewWidget {
add(Pos.CENTER, playerListSection);
if (userName.equals("host")) {
var tournamentButton = Primitive.hbox(
gameListTour,
Primitive.button(
"tournament",
() -> GlobalEventBus.get().post(new NetworkEvents.SendCommand(clientId, "tournament", "start", gameListTour.getValue())),
false,
false
)
);
add(Pos.BOTTOM_CENTER, tournamentButton);
}
var disconnectButton = Primitive.button(
"disconnect", () -> transitionPrevious(), false);
add(Pos.BOTTOM_LEFT, Primitive.vbox(disconnectButton));
}
}
public void update(List<String> players) {
Platform.runLater(() -> {

View File

@@ -123,16 +123,29 @@ public class NetworkingGameClientHandler extends ChannelInboundHandlerAdapter {
String usersRaw = extract(rec, "USERS");
String scoresRaw = extract(rec, "SCORES");
String[] users = Arrays.stream(usersRaw.substring(1, usersRaw.length() - 1).split(","))
if (usersRaw == null) return;
String[] users;
if (usersRaw.length() > 2) {
users = Arrays.stream(usersRaw.substring(1, usersRaw.length() - 1).split(","))
.map(s -> s.trim().replace("\"", ""))
.toArray(String[]::new);
} else {
users = new String[]{};
}
if (scoresRaw == null) return;
if (scoresRaw.length() > 2) {
Integer[] scores = Arrays.stream(scoresRaw.substring(1, scoresRaw.length() - 1).split(","))
.map(String::trim)
.map(Integer::parseInt)
.toArray(Integer[]::new);
eventBus.post(new NetworkEvents.TournamentResultResponse(this.connectionId, gameTypeRaw, users, scores));
} else {
eventBus.post(new NetworkEvents.TournamentResultResponse(this.connectionId, gameTypeRaw, users, new Integer[]{}));
}
}
private void gameMoveHandler(String rec) {

View File

@@ -279,11 +279,14 @@ public class Server implements GameServer<TurnBasedGame, NettyClient, Long> {
return;
}
var tournamentUsers = new ArrayList<>(onlineUsers());
tournamentUsers.removeIf(admins::contains);
Tournament tournament = new BasicTournament(new TournamentBuilder(
this,
new BasicTournamentRunner(),
new RoundRobinMatchMaker(onlineUsers()),
new BasicScoreSystem(onlineUsers())
new RoundRobinMatchMaker(tournamentUsers),
new BasicScoreSystem(tournamentUsers)
));
try {