Compare commits

..

No commits in common. "97a2cbb74e05cf07f14a794a936416103956ce80" and "2e839c176819bd9e93191e1e282366426103b255" have entirely different histories.

6 changed files with 34 additions and 25 deletions

@ -1 +1 @@
Subproject commit 9f5303ba745c72e868124d94743ac8fe5f41aecb Subproject commit ddd0f2f953aa29932706a429faa82da58fd62815

View File

@ -92,6 +92,7 @@ public class Server {
* It has to be executed <b>BEFORE ANY LOGGING OPERATIONS</b> . * It has to be executed <b>BEFORE ANY LOGGING OPERATIONS</b> .
*/ */
private static void setLogLevel(int logLevel) { private static void setLogLevel(int logLevel) {
// System.out.println("setting log level to " + logLevel);
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
Configuration.replace(map); Configuration.replace(map);

View File

@ -1,9 +1,13 @@
package uulm.teamname.marvelous.server.lobby; package uulm.teamname.marvelous.server.lobby;
import uulm.teamname.marvelous.server.Server;
import uulm.teamname.marvelous.server.lobbymanager.Participant;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
/** /**
* A timer meant to time the entire Lifetime of the lobby, and if it is higher than the maximum permitted value, * A timer meant to time the entire Lifetime of the lobby, and if it is higher than the maximum permitted value,

View File

@ -28,19 +28,19 @@ public class TurnTimeoutTimer {
/** /**
* This method checks if the participant is not a spectator. Otherwise it won't start a timer. * This method checks if the participant is not a spectator. Otherwise it won't start a timer.
* *
* @param participant the timer is for * @param Participant the timer is for
*/ */
public void startTurnTimer(Participant participant) { public void startTurnTimer(Participant Participant) {
if (participant.type == ParticipantType.Spectator) { if (Participant.type == ParticipantType.Spectator) {
throw new IllegalStateException("Spectators don't have TurnTime"); throw new IllegalStateException("Spectators don't have TurnTime");
} }
clear(); clear();
Logger.debug("Starting turn timer for participant '{}' with role {}", Logger.debug("Starting turn timer for participant '{}' with role {}",
participant.id.getName(), participant.type); Participant.id.getName(), Participant.type);
current = timer.schedule(() -> { current = timer.schedule(() -> {
callback.accept(participant); callback.accept(Participant);
return participant; return Participant;
}, },
maxRoundTime, maxRoundTime,
TimeUnit.SECONDS); TimeUnit.SECONDS);

View File

@ -29,9 +29,9 @@ public class LobbyConnection implements Runnable {
private Participant player1; private Participant player1;
private Participant player2; private Participant player2;
private final Set<Participant> spectators = new HashSet<>(10); private final HashSet<Participant> spectators = new HashSet<>(10);
private final Map<SUID, List<Integer>> selection = new HashMap<>(2); private final HashMap<SUID, List<Integer>> selection = new HashMap<>(2);
public final Map<ParticipantType, CharacterProperties[]> options = new HashMap<>(2); public final HashMap<ParticipantType, CharacterProperties[]> options = new HashMap<>(2);
private final BlockingQueue<Tuple<Participant, Request[]>> requestQueue = new LinkedBlockingQueue<>(); private final BlockingQueue<Tuple<Participant, Request[]>> requestQueue = new LinkedBlockingQueue<>();
@ -57,7 +57,6 @@ public class LobbyConnection implements Runnable {
Logger.trace("Set client state to playing"); Logger.trace("Set client state to playing");
participant.getClient().setState(ClientState.Playing); participant.getClient().setState(ClientState.Playing);
participant.state = ParticipantState.Playing; participant.state = ParticipantState.Playing;
participant.sendMessage(generateGameStructure(participant.type));
} }
if (participant.type == ParticipantType.Spectator) { if (participant.type == ParticipantType.Spectator) {
Logger.trace("Adding spectator"); Logger.trace("Adding spectator");
@ -117,7 +116,7 @@ public class LobbyConnection implements Runnable {
return player2; return player2;
} }
public Set<Participant> getSpectators() { public HashSet<Participant> getSpectators() {
return spectators; return spectators;
} }
@ -159,7 +158,7 @@ public class LobbyConnection implements Runnable {
response.gameID = gameID; response.gameID = gameID;
participant.sendMessage(response); participant.sendMessage(response);
participant.sendMessage(generateGameStructure(participant.type)); sendGameStructure(participant.equals(player1), participant.equals(player2), false);
lobby.handleReconnect(participant); lobby.handleReconnect(participant);
} }
@ -187,7 +186,7 @@ public class LobbyConnection implements Runnable {
Logger.info("Starting Lobby in main thread for lobby '{}'", gameID); Logger.info("Starting Lobby in main thread for lobby '{}'", gameID);
} }
broadcastGameStructure(); sendGameStructure(true, true, true);
this.lobby = new Lobby( this.lobby = new Lobby(
gameID, gameID,
@ -222,14 +221,7 @@ public class LobbyConnection implements Runnable {
} }
private void broadcastGameStructure() { private void sendGameStructure(boolean p1, boolean p2, boolean spectators) {
// Sending GameStructure message with fitting assignment
player1.sendMessage(generateGameStructure(ParticipantType.PlayerOne));
player2.sendMessage(generateGameStructure(ParticipantType.PlayerTwo));
broadcastToSpectators(generateGameStructure(ParticipantType.Spectator));
}
private GameStructureMessage generateGameStructure(ParticipantType assignment) {
GameStructureMessage gameStructureMessage = new GameStructureMessage(); GameStructureMessage gameStructureMessage = new GameStructureMessage();
gameStructureMessage.playerOneName = player1.id.getName(); gameStructureMessage.playerOneName = player1.id.getName();
gameStructureMessage.playerTwoName = player2.id.getName(); gameStructureMessage.playerTwoName = player2.id.getName();
@ -248,9 +240,21 @@ public class LobbyConnection implements Runnable {
gameStructureMessage.matchconfig = Server.getPartyConfig(); gameStructureMessage.matchconfig = Server.getPartyConfig();
gameStructureMessage.scenarioconfig = Server.getScenarioConfig(); gameStructureMessage.scenarioconfig = Server.getScenarioConfig();
gameStructureMessage.assignment = assignment; // Sending GameStructure message with fitting assignment
if (p1) {
gameStructureMessage.assignment = ParticipantType.PlayerOne;
player1.sendMessage(gameStructureMessage);
}
return gameStructureMessage; if (p2) {
gameStructureMessage.assignment = ParticipantType.PlayerTwo;
player2.sendMessage(gameStructureMessage);
}
if (spectators) {
gameStructureMessage.assignment = ParticipantType.Spectator;
broadcastToSpectators(gameStructureMessage);
}
} }
private Tuple<Participant, Request[]> pollQueueAsync() { private Tuple<Participant, Request[]> pollQueueAsync() {

View File

@ -43,7 +43,7 @@ class UserManagerTest {
@Test @Test
void userIsConnectedTest() { void userIsConnectedTest() {
assertThat(manager.getUserCount()).isZero(); assertThat(manager.getUserCount()).isEqualTo(0);
assertThat(manager.containsConnection(socket1)).isFalse(); assertThat(manager.containsConnection(socket1)).isFalse();
manager.connectUser(socket1); manager.connectUser(socket1);
assertThat(manager.getUserCount()).isEqualTo(1); assertThat(manager.getUserCount()).isEqualTo(1);