sonarqube: fixed some smells
This commit is contained in:
parent
7fb4f41326
commit
6f19056fde
@ -1,7 +1,6 @@
|
||||
package uulm.teamname.marvelous.server.lobby;
|
||||
|
||||
import org.tinylog.Logger;
|
||||
import uulm.teamname.marvelous.server.Server;
|
||||
import uulm.teamname.marvelous.server.lobbymanager.Participant;
|
||||
|
||||
import java.util.concurrent.*;
|
||||
@ -12,13 +11,16 @@ public class TimeoutTimer {
|
||||
|
||||
private final ScheduledExecutorService timer;
|
||||
|
||||
private ScheduledFuture<Participant> player1AlmostTimeout, player1Timeout;
|
||||
private ScheduledFuture<Participant> player2AlmostTimeout, player2Timeout;
|
||||
private ScheduledFuture<Participant> player1AlmostTimeout;
|
||||
private ScheduledFuture<Participant> player1Timeout;
|
||||
private ScheduledFuture<Participant> player2AlmostTimeout;
|
||||
private ScheduledFuture<Participant> player2Timeout;
|
||||
|
||||
private final BiConsumer<Participant, Integer> almostTimeoutCallback;
|
||||
private final Consumer<Participant> timeoutCallback;
|
||||
|
||||
private final int almostTimeoutTime, timeoutTime;
|
||||
private final int almostTimeoutTime;
|
||||
private final int timeoutTime;
|
||||
|
||||
/**
|
||||
* Class that manages timeouts of players after not sending a message for a long time.
|
||||
|
@ -2,7 +2,6 @@ package uulm.teamname.marvelous.server.lobby;
|
||||
|
||||
import org.tinylog.Logger;
|
||||
import uulm.teamname.marvelous.gamelibrary.messages.ParticipantType;
|
||||
import uulm.teamname.marvelous.server.Server;
|
||||
import uulm.teamname.marvelous.server.lobbymanager.Participant;
|
||||
|
||||
import java.util.concurrent.*;
|
||||
@ -20,12 +19,7 @@ public class TurnTimeoutTimer {
|
||||
|
||||
public TurnTimeoutTimer(int maxRoundTime, Consumer<Participant> callback) {
|
||||
String lobbyThreadName = Thread.currentThread().getName();
|
||||
ThreadFactory threadFactory = new ThreadFactory() {
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
return new Thread(r, lobbyThreadName + "-TurnTimerThread");
|
||||
}
|
||||
};
|
||||
ThreadFactory threadFactory = r -> new Thread(r, lobbyThreadName + "-TurnTimerThread");
|
||||
this.timer = Executors.newSingleThreadScheduledExecutor(threadFactory);
|
||||
this.maxRoundTime = maxRoundTime;
|
||||
this.callback = callback;
|
||||
|
@ -2,7 +2,6 @@ package uulm.teamname.marvelous.server.lobby.pipelining;
|
||||
|
||||
import org.tinylog.Logger;
|
||||
import uulm.teamname.marvelous.gamelibrary.events.Event;
|
||||
import uulm.teamname.marvelous.gamelibrary.events.EventBuilder;
|
||||
import uulm.teamname.marvelous.gamelibrary.gamelogic.GameInstance;
|
||||
import uulm.teamname.marvelous.gamelibrary.requests.Request;
|
||||
|
||||
|
@ -5,7 +5,6 @@ import uulm.teamname.marvelous.gamelibrary.events.Event;
|
||||
import uulm.teamname.marvelous.gamelibrary.events.EventBuilder;
|
||||
import uulm.teamname.marvelous.gamelibrary.events.EventType;
|
||||
import uulm.teamname.marvelous.gamelibrary.messages.ParticipantType;
|
||||
import uulm.teamname.marvelous.gamelibrary.requests.Request;
|
||||
import uulm.teamname.marvelous.gamelibrary.requests.RequestBuilder;
|
||||
import uulm.teamname.marvelous.gamelibrary.requests.RequestType;
|
||||
|
||||
|
@ -51,7 +51,7 @@ public class Pipeline {
|
||||
for (Segment segment : segments) {
|
||||
// Give the segment the packet, carrier and abort, and let it process requests
|
||||
segment.processRequests(packet, carrier, abort);
|
||||
if (packet.size() == 0 || abort.get()) { // if packet is empty (all requests processed) or abort initiated
|
||||
if (packet.isEmpty() || abort.get()) { // if packet is empty (all requests processed) or abort initiated
|
||||
break; // (abort boolean true), break out of the loop
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package uulm.teamname.marvelous.server.lobby.pipelining;
|
||||
import org.tinylog.Logger;
|
||||
import uulm.teamname.marvelous.gamelibrary.entities.EntityType;
|
||||
import uulm.teamname.marvelous.gamelibrary.events.Event;
|
||||
import uulm.teamname.marvelous.gamelibrary.messages.ParticipantType;
|
||||
import uulm.teamname.marvelous.gamelibrary.requests.CharacterRequest;
|
||||
import uulm.teamname.marvelous.gamelibrary.requests.Request;
|
||||
import uulm.teamname.marvelous.server.lobbymanager.Participant;
|
||||
|
@ -2,12 +2,9 @@ package uulm.teamname.marvelous.server.lobby.pipelining;
|
||||
|
||||
import org.tinylog.Logger;
|
||||
import uulm.teamname.marvelous.gamelibrary.events.Event;
|
||||
import uulm.teamname.marvelous.gamelibrary.events.EventBuilder;
|
||||
import uulm.teamname.marvelous.gamelibrary.gamelogic.GameInstance;
|
||||
import uulm.teamname.marvelous.gamelibrary.messages.server.EventMessage;
|
||||
import uulm.teamname.marvelous.gamelibrary.requests.RequestBuilder;
|
||||
import uulm.teamname.marvelous.gamelibrary.requests.RequestType;
|
||||
import uulm.teamname.marvelous.server.lobby.Lobby;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
@ -26,7 +26,9 @@ public class LobbyConnection implements Runnable {
|
||||
public final String gameID;
|
||||
public LobbyConnectionState state = LobbyConnectionState.Waiting;
|
||||
|
||||
private Participant player1, player2;
|
||||
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);
|
||||
@ -59,7 +61,6 @@ public class LobbyConnection implements Runnable {
|
||||
if (participant.type == ParticipantType.Spectator) {
|
||||
Logger.trace("Adding spectator");
|
||||
spectators.add(participant);
|
||||
return;
|
||||
} else if (participant.type == ParticipantType.PlayerOne) {
|
||||
player1 = participant;
|
||||
} else {
|
||||
|
@ -120,7 +120,7 @@ public class LobbyManager {
|
||||
|
||||
int n = 0;
|
||||
for (int i = 0; i < 12; i++) {
|
||||
if (message.characters[i]) {
|
||||
if (Boolean.TRUE.equals(message.characters[i])) {
|
||||
selected[n++] = options[i].characterID;
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package uulm.teamname.marvelous.server.lobbymanager;
|
||||
|
||||
import uulm.teamname.marvelous.gamelibrary.messages.BasicMessage;
|
||||
import uulm.teamname.marvelous.gamelibrary.messages.ParticipantType;
|
||||
import uulm.teamname.marvelous.server.lobby.Lobby;
|
||||
import uulm.teamname.marvelous.server.netconnector.Client;
|
||||
import uulm.teamname.marvelous.server.netconnector.SUID;
|
||||
|
||||
@ -52,4 +51,12 @@ public class Participant {
|
||||
Participant other = (Participant) o;
|
||||
return other.id.equals(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode(){
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((client == null) ? 0 : client.hashCode()) + ((id == null) ? 0 : id.hashCode());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
*/
|
||||
public class UserManager {
|
||||
private static UserManager instance;
|
||||
private static final String errorInvalidMessage = "Invalid message.";
|
||||
|
||||
/**
|
||||
* @return the current instance of the UserManager
|
||||
@ -175,7 +176,7 @@ public class UserManager {
|
||||
return;
|
||||
}
|
||||
|
||||
if(message.reconnect) {
|
||||
if(Boolean.TRUE.equals(message.reconnect)) {
|
||||
Logger.trace("Reconnecting to lobby. Forwarding reconnect instruction to the LobbyManager");
|
||||
if(LobbyManager.getInstance().handleReconnect(client)) {
|
||||
Logger.trace("Successfully reconnected client, changing state to Playing...");
|
||||
@ -200,12 +201,12 @@ public class UserManager {
|
||||
}
|
||||
|
||||
Logger.trace("Relaying message to LobbyManager");
|
||||
if(message.startGame) {
|
||||
if(Boolean.TRUE.equals(message.startGame)) {
|
||||
if(LobbyManager.getInstance().handleReady(client, message)) {
|
||||
client.setState(ClientState.Assigned);
|
||||
} else {
|
||||
Logger.trace("Sending error to client as message couldn't be processed properly");
|
||||
client.sendError("Invalid message.");
|
||||
client.sendError(errorInvalidMessage);
|
||||
}
|
||||
} else {
|
||||
Logger.debug("Disconnecting client as game couldn't be started");
|
||||
@ -227,7 +228,7 @@ public class UserManager {
|
||||
if(LobbyManager.getInstance().handleSelection(client, message)) {
|
||||
Logger.trace("Handled successfully");
|
||||
} else {
|
||||
client.sendError("Invalid message.");
|
||||
client.sendError(errorInvalidMessage);
|
||||
}
|
||||
}
|
||||
|
||||
@ -247,7 +248,7 @@ public class UserManager {
|
||||
//"i approve" - the server
|
||||
} else {
|
||||
Logger.debug("Message couldn't be handled, sending error to client");
|
||||
client.sendError("Invalid message.");
|
||||
client.sendError(errorInvalidMessage);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user