Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
97a2cbb74e | ||
d54d2004dd | |||
e7c5976f9b | |||
d46471e601 |
2
Gamelib
2
Gamelib
@ -1 +1 @@
|
||||
Subproject commit ddd0f2f953aa29932706a429faa82da58fd62815
|
||||
Subproject commit 9f5303ba745c72e868124d94743ac8fe5f41aecb
|
@ -92,7 +92,6 @@ public class Server {
|
||||
* It has to be executed <b>BEFORE ANY LOGGING OPERATIONS</b> .
|
||||
*/
|
||||
private static void setLogLevel(int logLevel) {
|
||||
// System.out.println("setting log level to " + logLevel);
|
||||
Map<String, String> map = new HashMap<>();
|
||||
|
||||
Configuration.replace(map);
|
||||
|
@ -1,13 +1,9 @@
|
||||
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.ScheduledExecutorService;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
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,
|
||||
|
@ -28,19 +28,19 @@ public class TurnTimeoutTimer {
|
||||
/**
|
||||
* 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) {
|
||||
if (Participant.type == ParticipantType.Spectator) {
|
||||
public void startTurnTimer(Participant participant) {
|
||||
if (participant.type == ParticipantType.Spectator) {
|
||||
throw new IllegalStateException("Spectators don't have TurnTime");
|
||||
}
|
||||
|
||||
clear();
|
||||
Logger.debug("Starting turn timer for participant '{}' with role {}",
|
||||
Participant.id.getName(), Participant.type);
|
||||
participant.id.getName(), participant.type);
|
||||
current = timer.schedule(() -> {
|
||||
callback.accept(Participant);
|
||||
return Participant;
|
||||
callback.accept(participant);
|
||||
return participant;
|
||||
},
|
||||
maxRoundTime,
|
||||
TimeUnit.SECONDS);
|
||||
|
@ -29,9 +29,9 @@ public class LobbyConnection implements Runnable {
|
||||
private Participant player1;
|
||||
private Participant player2;
|
||||
|
||||
private final HashSet<Participant> spectators = new HashSet<>(10);
|
||||
private final HashMap<SUID, List<Integer>> selection = new HashMap<>(2);
|
||||
public final HashMap<ParticipantType, CharacterProperties[]> options = new HashMap<>(2);
|
||||
private final Set<Participant> spectators = new HashSet<>(10);
|
||||
private final Map<SUID, List<Integer>> selection = new HashMap<>(2);
|
||||
public final Map<ParticipantType, CharacterProperties[]> options = new HashMap<>(2);
|
||||
|
||||
private final BlockingQueue<Tuple<Participant, Request[]>> requestQueue = new LinkedBlockingQueue<>();
|
||||
|
||||
@ -57,6 +57,7 @@ public class LobbyConnection implements Runnable {
|
||||
Logger.trace("Set client state to playing");
|
||||
participant.getClient().setState(ClientState.Playing);
|
||||
participant.state = ParticipantState.Playing;
|
||||
participant.sendMessage(generateGameStructure(participant.type));
|
||||
}
|
||||
if (participant.type == ParticipantType.Spectator) {
|
||||
Logger.trace("Adding spectator");
|
||||
@ -116,7 +117,7 @@ public class LobbyConnection implements Runnable {
|
||||
return player2;
|
||||
}
|
||||
|
||||
public HashSet<Participant> getSpectators() {
|
||||
public Set<Participant> getSpectators() {
|
||||
return spectators;
|
||||
}
|
||||
|
||||
@ -158,7 +159,7 @@ public class LobbyConnection implements Runnable {
|
||||
response.gameID = gameID;
|
||||
participant.sendMessage(response);
|
||||
|
||||
sendGameStructure(participant.equals(player1), participant.equals(player2), false);
|
||||
participant.sendMessage(generateGameStructure(participant.type));
|
||||
|
||||
lobby.handleReconnect(participant);
|
||||
}
|
||||
@ -186,7 +187,7 @@ public class LobbyConnection implements Runnable {
|
||||
Logger.info("Starting Lobby in main thread for lobby '{}'", gameID);
|
||||
}
|
||||
|
||||
sendGameStructure(true, true, true);
|
||||
broadcastGameStructure();
|
||||
|
||||
this.lobby = new Lobby(
|
||||
gameID,
|
||||
@ -221,7 +222,14 @@ public class LobbyConnection implements Runnable {
|
||||
}
|
||||
|
||||
|
||||
private void sendGameStructure(boolean p1, boolean p2, boolean spectators) {
|
||||
private void broadcastGameStructure() {
|
||||
// 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.playerOneName = player1.id.getName();
|
||||
gameStructureMessage.playerTwoName = player2.id.getName();
|
||||
@ -240,21 +248,9 @@ public class LobbyConnection implements Runnable {
|
||||
gameStructureMessage.matchconfig = Server.getPartyConfig();
|
||||
gameStructureMessage.scenarioconfig = Server.getScenarioConfig();
|
||||
|
||||
// Sending GameStructure message with fitting assignment
|
||||
if (p1) {
|
||||
gameStructureMessage.assignment = ParticipantType.PlayerOne;
|
||||
player1.sendMessage(gameStructureMessage);
|
||||
}
|
||||
gameStructureMessage.assignment = assignment;
|
||||
|
||||
if (p2) {
|
||||
gameStructureMessage.assignment = ParticipantType.PlayerTwo;
|
||||
player2.sendMessage(gameStructureMessage);
|
||||
}
|
||||
|
||||
if (spectators) {
|
||||
gameStructureMessage.assignment = ParticipantType.Spectator;
|
||||
broadcastToSpectators(gameStructureMessage);
|
||||
}
|
||||
return gameStructureMessage;
|
||||
}
|
||||
|
||||
private Tuple<Participant, Request[]> pollQueueAsync() {
|
||||
|
@ -43,7 +43,7 @@ class UserManagerTest {
|
||||
|
||||
@Test
|
||||
void userIsConnectedTest() {
|
||||
assertThat(manager.getUserCount()).isEqualTo(0);
|
||||
assertThat(manager.getUserCount()).isZero();
|
||||
assertThat(manager.containsConnection(socket1)).isFalse();
|
||||
manager.connectUser(socket1);
|
||||
assertThat(manager.getUserCount()).isEqualTo(1);
|
||||
|
Loading…
Reference in New Issue
Block a user