mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 02:44:50 +00:00
Tournament is now without admins
This commit is contained in:
@@ -45,24 +45,6 @@ public final class ServerView extends ViewWidget {
|
||||
private void setupLayout(String userName) {
|
||||
var playerHeader = Primitive.header(user, false);
|
||||
|
||||
subscribeButton = Primitive.button(
|
||||
"subscribe",
|
||||
() -> new EventFlow().addPostEvent(new NetworkEvents.SendSubscribe(clientId, gameListSub.getValue())).postEvent(),
|
||||
false,
|
||||
true
|
||||
); // TODO localize
|
||||
|
||||
var subscribe = Primitive.hbox(gameListSub, subscribeButton);
|
||||
|
||||
var playerListSection = Primitive.vbox(
|
||||
playerHeader,
|
||||
Primitive.separator(),
|
||||
subscribe,
|
||||
listView
|
||||
);
|
||||
|
||||
add(Pos.CENTER, playerListSection);
|
||||
|
||||
if (userName.equals("host")) {
|
||||
var tournamentButton = Primitive.hbox(
|
||||
gameListTour,
|
||||
@@ -75,12 +57,30 @@ public final class ServerView extends ViewWidget {
|
||||
);
|
||||
|
||||
add(Pos.BOTTOM_CENTER, tournamentButton);
|
||||
} else {
|
||||
subscribeButton = Primitive.button(
|
||||
"subscribe",
|
||||
() -> new EventFlow().addPostEvent(new NetworkEvents.SendSubscribe(clientId, gameListSub.getValue())).postEvent(),
|
||||
false,
|
||||
true
|
||||
); // TODO localize
|
||||
|
||||
var subscribe = Primitive.hbox(gameListSub, subscribeButton);
|
||||
|
||||
var playerListSection = Primitive.vbox(
|
||||
playerHeader,
|
||||
Primitive.separator(),
|
||||
subscribe,
|
||||
listView
|
||||
);
|
||||
|
||||
add(Pos.CENTER, playerListSection);
|
||||
|
||||
var disconnectButton = Primitive.button(
|
||||
"disconnect", () -> transitionPrevious(), false);
|
||||
|
||||
add(Pos.BOTTOM_LEFT, Primitive.vbox(disconnectButton));
|
||||
}
|
||||
|
||||
var disconnectButton = Primitive.button(
|
||||
"disconnect", () -> transitionPrevious(), false);
|
||||
|
||||
add(Pos.BOTTOM_LEFT, Primitive.vbox(disconnectButton));
|
||||
}
|
||||
|
||||
public void update(List<String> players) {
|
||||
|
||||
@@ -120,19 +120,32 @@ public class NetworkingGameClientHandler extends ChannelInboundHandlerAdapter {
|
||||
IO.println(rec);
|
||||
|
||||
String gameTypeRaw = extract(rec, "GAMETYPE");
|
||||
String usersRaw = extract(rec, "USERS");
|
||||
String scoresRaw = extract(rec, "SCORES");
|
||||
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[]{};
|
||||
}
|
||||
|
||||
Integer[] scores = Arrays.stream(scoresRaw.substring(1, scoresRaw.length() - 1).split(","))
|
||||
.map(String::trim)
|
||||
.map(Integer::parseInt)
|
||||
.toArray(Integer[]::new);
|
||||
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[]{}));
|
||||
}
|
||||
|
||||
eventBus.post(new NetworkEvents.TournamentResultResponse(this.connectionId, gameTypeRaw, users, scores));
|
||||
}
|
||||
|
||||
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