Compare commits

...

4 Commits

Author SHA1 Message Date
Richard Reiber
97a2cbb74e sonarqube: removed some smells.
biggest change is that the HashSet and HashMap in LobbyConnection is now a Set and Map instead.
2021-08-09 23:19:30 +02:00
d54d2004dd fix: fix method call 2021-08-09 20:33:57 +02:00
e7c5976f9b update: updated submodule 2021-08-09 20:33:13 +02:00
d46471e601 fix: send gamestructure to players joining a running game 2021-08-09 20:29:46 +02:00
6 changed files with 25 additions and 34 deletions

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

View File

@ -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);

View File

@ -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,

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.
*
* @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);

View File

@ -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() {

View File

@ -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);