mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 19:04:49 +00:00
Tournament is now without admins
This commit is contained in:
@@ -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(() -> {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user