mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +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) {
|
private void setupLayout(String userName) {
|
||||||
var playerHeader = Primitive.header(user, false);
|
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")) {
|
if (userName.equals("host")) {
|
||||||
var tournamentButton = Primitive.hbox(
|
var tournamentButton = Primitive.hbox(
|
||||||
gameListTour,
|
gameListTour,
|
||||||
@@ -75,12 +57,30 @@ public final class ServerView extends ViewWidget {
|
|||||||
);
|
);
|
||||||
|
|
||||||
add(Pos.BOTTOM_CENTER, tournamentButton);
|
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) {
|
public void update(List<String> players) {
|
||||||
|
|||||||
@@ -120,19 +120,32 @@ public class NetworkingGameClientHandler extends ChannelInboundHandlerAdapter {
|
|||||||
IO.println(rec);
|
IO.println(rec);
|
||||||
|
|
||||||
String gameTypeRaw = extract(rec, "GAMETYPE");
|
String gameTypeRaw = extract(rec, "GAMETYPE");
|
||||||
String usersRaw = extract(rec, "USERS");
|
String usersRaw = extract(rec, "USERS");
|
||||||
String scoresRaw = extract(rec, "SCORES");
|
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("\"", ""))
|
.map(s -> s.trim().replace("\"", ""))
|
||||||
.toArray(String[]::new);
|
.toArray(String[]::new);
|
||||||
|
} else {
|
||||||
|
users = new String[]{};
|
||||||
|
}
|
||||||
|
|
||||||
Integer[] scores = Arrays.stream(scoresRaw.substring(1, scoresRaw.length() - 1).split(","))
|
if (scoresRaw == null) return;
|
||||||
.map(String::trim)
|
if (scoresRaw.length() > 2) {
|
||||||
.map(Integer::parseInt)
|
Integer[] scores = Arrays.stream(scoresRaw.substring(1, scoresRaw.length() - 1).split(","))
|
||||||
.toArray(Integer[]::new);
|
.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) {
|
private void gameMoveHandler(String rec) {
|
||||||
|
|||||||
@@ -279,11 +279,14 @@ public class Server implements GameServer<TurnBasedGame, NettyClient, Long> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var tournamentUsers = new ArrayList<>(onlineUsers());
|
||||||
|
tournamentUsers.removeIf(admins::contains);
|
||||||
|
|
||||||
Tournament tournament = new BasicTournament(new TournamentBuilder(
|
Tournament tournament = new BasicTournament(new TournamentBuilder(
|
||||||
this,
|
this,
|
||||||
new BasicTournamentRunner(),
|
new BasicTournamentRunner(),
|
||||||
new RoundRobinMatchMaker(onlineUsers()),
|
new RoundRobinMatchMaker(tournamentUsers),
|
||||||
new BasicScoreSystem(onlineUsers())
|
new BasicScoreSystem(tournamentUsers)
|
||||||
));
|
));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user