Refactor of network stack
This commit is contained in:
@@ -2,6 +2,7 @@ package it.polimi.ingsw.gc14;
|
||||
import it.polimi.ingsw.gc14.Controller.ClientController;
|
||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Character;
|
||||
import it.polimi.ingsw.gc14.Model.GamePackage.GameStages;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkConfig;
|
||||
import it.polimi.ingsw.gc14.Network.InterfaceResolver;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
import it.polimi.ingsw.gc14.Network.RMI.Client.RMIClient;
|
||||
@@ -78,7 +79,7 @@ public class ClientLauncherTUI {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
System.setProperty("java.rmi.server.hostname", myIP);
|
||||
RMIClient client = new RMIClient(controller, IP, 1099, myIP);
|
||||
RMIClient client = new RMIClient(controller, IP, NetworkConfig.RMI_PORT, myIP);
|
||||
ErrorType serverResponse=client.connect(username, proposedNumPlayers);
|
||||
if (serverResponse==null) {
|
||||
System.out.println("Succesfully connected to RMI server\n\n");
|
||||
@@ -94,7 +95,7 @@ public class ClientLauncherTUI {
|
||||
// TCP
|
||||
} else if (networkType == 1) {
|
||||
// Connect
|
||||
TCPClient client = new TCPClient(controller, IP, 8080,8081);
|
||||
TCPClient client = new TCPClient(controller, IP, NetworkConfig.TCP_PORT, NetworkConfig.HEARTBEAT_PORT);
|
||||
ErrorType serverResponse=client.connect(username, proposedNumPlayers);
|
||||
if (serverResponse==null) {
|
||||
System.out.println("Succesfully connected to TCP server\n\n");
|
||||
|
||||
@@ -40,12 +40,12 @@ public class GameController {
|
||||
* {@code false} if no player with the specified username exists
|
||||
* or if the operation fails.
|
||||
*/
|
||||
public synchronized boolean DisconnectedPlayer(String username)
|
||||
public synchronized boolean disconnectedPlayer(String username)
|
||||
{
|
||||
Player player= model.getPlayerByUsername(username);
|
||||
if(player==null)
|
||||
return false;
|
||||
return model.DisconnectedPlayer(player);
|
||||
return model.disconnectedPlayer(player);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,12 +56,12 @@ public class GameController {
|
||||
* {@code false} if no player with the specified username exists
|
||||
* or if the operation fails.
|
||||
*/
|
||||
public synchronized boolean ReconnectPlayer(String username)
|
||||
public synchronized boolean reconnectPlayer(String username)
|
||||
{
|
||||
Player player= model.getPlayerByUsername(username);
|
||||
if(player==null)
|
||||
return false;
|
||||
return model.ReconnectPlayer(player);
|
||||
return model.reconnectPlayer(player);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -165,11 +165,11 @@ public class GameController {
|
||||
* @return {@code true} if the skip action is valid and successfully performed,
|
||||
* {@code false} if the player does not exist or if the action is not valid.
|
||||
*/
|
||||
public synchronized boolean SkipTurn(String playerUsername) {
|
||||
public synchronized boolean skipTurn(String playerUsername) {
|
||||
Player player= model.getPlayerByUsername(playerUsername);
|
||||
if(player==null)
|
||||
return false;
|
||||
return model.SkipTurn(model.getPlayerByUsername(playerUsername));
|
||||
return model.skipTurn(model.getPlayerByUsername(playerUsername));
|
||||
}
|
||||
|
||||
|
||||
@@ -199,15 +199,17 @@ public class GameController {
|
||||
* {@code false} if no player with the specified username exists
|
||||
* or if the choice operation fails.
|
||||
*/
|
||||
public synchronized boolean TotemChoice(String playerUsername,String totem) {
|
||||
public synchronized boolean totemChoice(String playerUsername,String totem) {
|
||||
Player player= model.getPlayerByUsername(playerUsername);
|
||||
if(player==null)
|
||||
return false;
|
||||
return model.TotemChoice(player, Totems.valueOf(totem));
|
||||
return model.totemChoice(player, Totems.valueOf(totem));
|
||||
}
|
||||
|
||||
//TODO
|
||||
public synchronized void EndGameForFeit(){
|
||||
model.EndGameForFeit();
|
||||
@Deprecated
|
||||
public synchronized void EndGameForFeit() { endGameForFeit(); }
|
||||
|
||||
public synchronized void endGameForFeit() {
|
||||
model.endGameForFeit();
|
||||
}
|
||||
}
|
||||
@@ -280,12 +280,11 @@ public class GameEventProcessor {
|
||||
*/
|
||||
private void endGameForFeit(Game game) {
|
||||
synchronized (gameController) {
|
||||
gameController.EndGameForFeit();
|
||||
gameController.endGameForFeit();
|
||||
EndedGame forfeitEnd = new EndedGame(
|
||||
game.getSlotMap(), game.orderLogicCard,
|
||||
game.getCurrentState(), game.getPlayerStanding()
|
||||
);
|
||||
forfeitEnd.setDisconnected(buildDisconnectedList(game));
|
||||
broadcaster.notifyAll(forfeitEnd);
|
||||
System.out.println("Timer expired: no player reconnected in 60 s.");
|
||||
removeOfflinePlayers();
|
||||
@@ -319,14 +318,12 @@ public class GameEventProcessor {
|
||||
game.getUpperListTribeCards(), game.getLowerListTribeCards(),
|
||||
game.getUpperListBuilding(), game.getLowerListBuilding()
|
||||
);
|
||||
nextRound.setDisconnected(buildDisconnectedList(game));
|
||||
broadcaster.notifyAll(nextRound);
|
||||
} else if (game.getCurrentState().getGameStage() == GameStages.ENDED) {
|
||||
EndedGame endedGame = new EndedGame(
|
||||
game.getSlotMap(), game.orderLogicCard,
|
||||
game.getCurrentState(), game.getPlayerStanding()
|
||||
);
|
||||
endedGame.setDisconnected(buildDisconnectedList(game));
|
||||
broadcaster.notifyAll(endedGame);
|
||||
if (!saveManager.delete()) {
|
||||
System.out.println("\n!!! Couldn't delete save !!!\n");
|
||||
|
||||
@@ -83,7 +83,7 @@ public class Game implements Serializable {
|
||||
* @param totem the selected totem.
|
||||
* @return {@code true} if the choice is applied successfully, {@code false} otherwise.
|
||||
*/
|
||||
public synchronized boolean TotemChoice(Player player,Totems totem) {
|
||||
public synchronized boolean totemChoice(Player player,Totems totem) {
|
||||
if(!currentState.getGameStage().equals(GameStages.TOTEM_CHOICE))
|
||||
return false;
|
||||
if(!getCurrentState().getCurrentPlayer().equals(player))
|
||||
@@ -135,7 +135,7 @@ public class Game implements Serializable {
|
||||
* @return {@code true} if the disconnection is handled successfully,
|
||||
* {@code false} if the player was already marked as disconnected.
|
||||
*/
|
||||
public synchronized boolean DisconnectedPlayer(Player player)
|
||||
public synchronized boolean disconnectedPlayer(Player player)
|
||||
{
|
||||
if(disconnetedPlayers.containsKey(player) && disconnetedPlayers.get(player))
|
||||
{
|
||||
@@ -177,7 +177,7 @@ public class Game implements Serializable {
|
||||
* @return {@code true} if the reconnection is handled successfully,
|
||||
* {@code false} if the player was not previously marked as disconnected.
|
||||
*/
|
||||
public synchronized boolean ReconnectPlayer(Player player)
|
||||
public synchronized boolean reconnectPlayer(Player player)
|
||||
{
|
||||
if(!disconnetedPlayers.containsKey(player))
|
||||
{
|
||||
@@ -516,7 +516,7 @@ public class Game implements Serializable {
|
||||
* @param player the player skipping the turn .
|
||||
* @return {@code true} if the skip succeeds, {@code false} otherwise.
|
||||
*/
|
||||
public boolean SkipTurn(Player player) {
|
||||
public boolean skipTurn(Player player) {
|
||||
if(currentState.getGameStage()!= GameStages.RES_ACTIONS && !currentState.getGameStage().equals(GameStages.OPT_CARD_E))
|
||||
{
|
||||
return false;
|
||||
@@ -992,7 +992,7 @@ public class Game implements Serializable {
|
||||
* in the first position of the final ranking. The remaining players are
|
||||
* ordered by prestige value and, in case of a tie, by food value.
|
||||
*/
|
||||
public synchronized void EndGameForFeit() {
|
||||
public synchronized void endGameForFeit() {
|
||||
Player winner=playersList.stream().filter(x->!disconnetedPlayers.containsKey(x)||!disconnetedPlayers.get(x)).toList().get(0);
|
||||
currentState.GameStageUpdate(GameStages.ENDED);
|
||||
playerStanding=new ArrayList<>(playersList);
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package it.polimi.ingsw.gc14.Network;
|
||||
|
||||
public final class NetworkConfig {
|
||||
public static final int RMI_PORT = 1099;
|
||||
public static final int TCP_PORT = 8080;
|
||||
public static final int HEARTBEAT_PORT = 8081;
|
||||
public static final long SILENCE_THRESHOLD_MS = 5_000;
|
||||
public static final long KEEPALIVE_INTERVAL_MS = 3_000;
|
||||
|
||||
private NetworkConfig() {}
|
||||
}
|
||||
@@ -44,7 +44,7 @@ public class DisconnectedPlayer extends NetworkEvent implements Serializable{
|
||||
*/
|
||||
@Override
|
||||
public boolean apply(GameController gameController){
|
||||
return gameController.DisconnectedPlayer(username);
|
||||
return gameController.disconnectedPlayer(username);
|
||||
}
|
||||
|
||||
//TODO
|
||||
|
||||
@@ -39,7 +39,7 @@ public class ReconnectPlayer extends NetworkEvent implements Serializable {
|
||||
*/
|
||||
@Override
|
||||
public boolean apply(GameController gameController) {
|
||||
return gameController.ReconnectPlayer(username);
|
||||
return gameController.reconnectPlayer(username);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,7 +28,7 @@ public class SkipTurn extends NetworkEvent implements Serializable{
|
||||
*/
|
||||
@Override
|
||||
public boolean apply(GameController gameController){
|
||||
return gameController.SkipTurn(username);
|
||||
return gameController.skipTurn(username);
|
||||
}
|
||||
|
||||
//TODO
|
||||
|
||||
@@ -62,7 +62,7 @@ public class TotemChoice extends NetworkEvent implements Serializable {
|
||||
*/
|
||||
@Override
|
||||
public boolean apply(GameController gameController) {
|
||||
return gameController.TotemChoice(username, totem);
|
||||
return gameController.totemChoice(username, totem);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.util.concurrent.*;
|
||||
import it.polimi.ingsw.gc14.Controller.ClientController;
|
||||
import it.polimi.ingsw.gc14.ErrorType;
|
||||
import it.polimi.ingsw.gc14.Network.IClient;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkConfig;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvents.*;
|
||||
import it.polimi.ingsw.gc14.Network.RMI.Common.IGameServer;
|
||||
|
||||
@@ -15,9 +16,6 @@ import it.polimi.ingsw.gc14.Network.RMI.Common.IGameServer;
|
||||
*/
|
||||
public class RMIClient implements IClient {
|
||||
|
||||
private static final long PING_INTERVAL_S = 3; // mirrors TCPClient 3 s
|
||||
private static final long PING_TIMEOUT_MS = 5_000; // mirrors SILENCE_THRESHOLD_MS
|
||||
|
||||
private final String host;
|
||||
private final int port;
|
||||
private IGameServer stub;
|
||||
@@ -27,7 +25,7 @@ public class RMIClient implements IClient {
|
||||
|
||||
private volatile boolean running = false;
|
||||
|
||||
/** Scheduler that fires ping() every PING_INTERVAL_S seconds. */
|
||||
/** Scheduler that fires ping() every {@value NetworkConfig#KEEPALIVE_INTERVAL_MS} ms. */
|
||||
private ScheduledExecutorService pingSender;
|
||||
|
||||
/**
|
||||
@@ -107,7 +105,7 @@ public class RMIClient implements IClient {
|
||||
}
|
||||
});
|
||||
try {
|
||||
future.get(PING_TIMEOUT_MS, TimeUnit.MILLISECONDS); // mirrors setSoTimeout(5000)
|
||||
future.get(NetworkConfig.SILENCE_THRESHOLD_MS, TimeUnit.MILLISECONDS);
|
||||
} catch (TimeoutException e) {
|
||||
future.cancel(true);
|
||||
controller.view.showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());
|
||||
@@ -116,7 +114,7 @@ public class RMIClient implements IClient {
|
||||
disconnect();
|
||||
controller.view.showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());
|
||||
}
|
||||
}, 0, PING_INTERVAL_S, TimeUnit.SECONDS);
|
||||
}, 0, NetworkConfig.KEEPALIVE_INTERVAL_MS, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,6 +2,7 @@ package it.polimi.ingsw.gc14.Network.RMI.Server;
|
||||
|
||||
import it.polimi.ingsw.gc14.LimitedMap;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkConfig;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvents.DisconnectedPlayer;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -14,7 +15,7 @@ import java.util.concurrent.*;
|
||||
* instead of reading raw bytes from a dedicated socket, it relies on {@link #receivePing()}
|
||||
* being called by {@link RMIServer#ping(String)} every time the client sends a ping.
|
||||
*
|
||||
* <p>If no ping is received within {@value SILENCE_THRESHOLD_MS} ms, the player is
|
||||
* <p>If no ping is received within {@value NetworkConfig#SILENCE_THRESHOLD_MS} ms, the player is
|
||||
* considered disconnected and {@link #disconnect()} is invoked, which:
|
||||
* <ul>
|
||||
* <li>stops the watchdog;</li>
|
||||
@@ -25,8 +26,6 @@ import java.util.concurrent.*;
|
||||
*/
|
||||
public class RMIHeartbeat {
|
||||
|
||||
private static final long SILENCE_THRESHOLD_MS = 5_000;
|
||||
|
||||
private String username = "";
|
||||
private final LimitedMap<String, Boolean> playerList;
|
||||
private final Map<String, ?> clients; // ConcurrentHashMap<String, IClientCallback>
|
||||
@@ -66,7 +65,7 @@ public class RMIHeartbeat {
|
||||
/** Called by {@link RMIServer} whenever it starts tracking this player. */
|
||||
public void start() {
|
||||
watchdog.scheduleAtFixedRate(() -> {
|
||||
if (System.currentTimeMillis() - lastPingTime > SILENCE_THRESHOLD_MS) {
|
||||
if (System.currentTimeMillis() - lastPingTime > NetworkConfig.SILENCE_THRESHOLD_MS) {
|
||||
System.out.println("RMI heartbeat timeout: " + username);
|
||||
disconnect();
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import it.polimi.ingsw.gc14.Model.Game;
|
||||
import it.polimi.ingsw.gc14.Model.MiniModel;
|
||||
import it.polimi.ingsw.gc14.Network.IClient;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkConfig;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvents.*;
|
||||
import javafx.application.Platform;
|
||||
|
||||
@@ -131,7 +132,7 @@ public class TCPClient implements IClient {
|
||||
}, 0, 3, TimeUnit.SECONDS);
|
||||
|
||||
try {
|
||||
heartbeatSocket.setSoTimeout(5_000);
|
||||
heartbeatSocket.setSoTimeout((int) NetworkConfig.SILENCE_THRESHOLD_MS);
|
||||
while (running) {
|
||||
int b = heartbeatIn.read();
|
||||
if (b == -1 || b != PONG) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.net.*;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkConfig;
|
||||
|
||||
/**
|
||||
* Handles the heartbeat communication associated with a TCP client.
|
||||
@@ -16,16 +17,6 @@ import java.util.concurrent.TimeUnit;
|
||||
*/
|
||||
public class HeartbeatHandler implements Runnable {
|
||||
|
||||
/**
|
||||
* Maximum allowed time without receiving heartbeat messages before disconnecting the client.
|
||||
*/
|
||||
private static final long SILENCE_THRESHOLD_MS = 5_000;
|
||||
|
||||
/**
|
||||
* Expected interval between heartbeat messages.
|
||||
*/
|
||||
private static final long KEEPALIVE_INTERVAL_MS = 3_000;
|
||||
|
||||
private final String username;
|
||||
private final Socket socket;
|
||||
private final InputStream in;
|
||||
@@ -120,7 +111,7 @@ public class HeartbeatHandler implements Runnable {
|
||||
*/
|
||||
private void startWatchdog() {
|
||||
watchdog.scheduleAtFixedRate(() -> {
|
||||
if (System.currentTimeMillis() - lastReceivedTime > SILENCE_THRESHOLD_MS) {
|
||||
if (System.currentTimeMillis() - lastReceivedTime > NetworkConfig.SILENCE_THRESHOLD_MS) {
|
||||
System.out.println("Heartbeat timeout: " + username);
|
||||
disconnect();
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@ import it.polimi.ingsw.gc14.Network.NetworkEvents.ReconnectPlayer;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -74,7 +74,7 @@ public class TCPServer {
|
||||
/**
|
||||
* List of active TCP client handlers.
|
||||
*/
|
||||
List<ClientHandler> clientHandlers;
|
||||
CopyOnWriteArrayList<ClientHandler> clientHandlers;
|
||||
|
||||
|
||||
/**
|
||||
@@ -103,7 +103,7 @@ public class TCPServer {
|
||||
this.controller = controller;
|
||||
this.actionQueue = actionQueue;
|
||||
this.playerList = playerList;
|
||||
this.clientHandlers = new ArrayList<>();
|
||||
this.clientHandlers = new CopyOnWriteArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,6 +8,7 @@ import it.polimi.ingsw.gc14.Network.ClientBroadcaster;
|
||||
import it.polimi.ingsw.gc14.Network.CompositeClientBroadcaster;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
import it.polimi.ingsw.gc14.Network.RMI.Server.RMIServer;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkConfig;
|
||||
import it.polimi.ingsw.gc14.Network.TCP.Server.TCPServer;
|
||||
|
||||
import java.net.*;
|
||||
@@ -78,8 +79,8 @@ public class ServerLauncherTest {
|
||||
}
|
||||
System.setProperty("java.rmi.server.hostname", ip);
|
||||
|
||||
RMIServer rmiServer = new RMIServer(gameController, 1099, actionQueue, playerList, ip);
|
||||
TCPServer tcpServer = new TCPServer(gameController, 8080, 8081, actionQueue, playerList);
|
||||
RMIServer rmiServer = new RMIServer(gameController, NetworkConfig.RMI_PORT, actionQueue, playerList, ip);
|
||||
TCPServer tcpServer = new TCPServer(gameController, NetworkConfig.TCP_PORT, NetworkConfig.HEARTBEAT_PORT, actionQueue, playerList);
|
||||
ClientBroadcaster broadcaster = new CompositeClientBroadcaster(rmiServer, tcpServer);
|
||||
SaveManager saveManager = new SaveManager(ServerLauncherTest.class);
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package it.polimi.ingsw.gc14.View.GUI;
|
||||
|
||||
import it.polimi.ingsw.gc14.Controller.ClientController;
|
||||
import it.polimi.ingsw.gc14.ErrorType;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkConfig;
|
||||
import it.polimi.ingsw.gc14.Network.InterfaceResolver;
|
||||
import it.polimi.ingsw.gc14.Network.RMI.Client.RMIClient;
|
||||
import it.polimi.ingsw.gc14.Network.TCP.Client.TCPClient;
|
||||
@@ -130,7 +131,7 @@ public class LoginFXMLController {
|
||||
|
||||
private void connect(String nome, String ip, int numPlayers, String localInterface) {
|
||||
if (isRMI) {
|
||||
RMIClient client = new RMIClient(controller, ip, 1099, localInterface);
|
||||
RMIClient client = new RMIClient(controller, ip, NetworkConfig.RMI_PORT, localInterface);
|
||||
ErrorType serverResponse = client.connect(nome, numPlayers);
|
||||
if (serverResponse == null) {
|
||||
controller.setClient(client);
|
||||
@@ -142,7 +143,7 @@ public class LoginFXMLController {
|
||||
});
|
||||
}
|
||||
} else {
|
||||
TCPClient client = new TCPClient(controller, ip, 8080, 8081);
|
||||
TCPClient client = new TCPClient(controller, ip, NetworkConfig.TCP_PORT, NetworkConfig.HEARTBEAT_PORT);
|
||||
ErrorType serverResponse = client.connect(nome, numPlayers);
|
||||
if (serverResponse == null) {
|
||||
controller.setClient(client);
|
||||
|
||||
@@ -29,7 +29,7 @@ class GameControllerTest {
|
||||
|
||||
Totems selectedTotem = availableTotems.get(0);
|
||||
|
||||
assertTrue(controller.TotemChoice(
|
||||
assertTrue(controller.totemChoice(
|
||||
current.getUserName(),
|
||||
selectedTotem.name()
|
||||
));
|
||||
@@ -149,7 +149,7 @@ class GameControllerTest {
|
||||
|
||||
if (game.getCurrentState().getNUpper() == 0
|
||||
|| game.getUpperListTribeCards().stream().allMatch(TribeCard::IsEventCard)) {
|
||||
assertTrue(controller.SkipTurn(username));
|
||||
assertTrue(controller.skipTurn(username));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -172,7 +172,7 @@ class GameControllerTest {
|
||||
|
||||
if (game.getCurrentState().getNLower() == 0
|
||||
|| game.getLowerListTribeCards().stream().allMatch(TribeCard::IsEventCard)) {
|
||||
assertTrue(controller.SkipTurn(username));
|
||||
assertTrue(controller.skipTurn(username));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -250,7 +250,7 @@ class GameControllerTest {
|
||||
|
||||
Totems selectedTotem = game.getAvailableTotems().get(0);
|
||||
|
||||
assertFalse(controller.TotemChoice(wrongUsername, selectedTotem.name()));
|
||||
assertFalse(controller.totemChoice(wrongUsername, selectedTotem.name()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -261,7 +261,7 @@ class GameControllerTest {
|
||||
Player current = game.getCurrentState().getCurrentPlayer();
|
||||
assertNotNull(current);
|
||||
|
||||
assertTrue(controller.DisconnectedPlayer(current.getUserName()));
|
||||
assertTrue(controller.disconnectedPlayer(current.getUserName()));
|
||||
|
||||
assertTrue(game.disconnetedPlayers.containsKey(current));
|
||||
assertTrue(game.disconnetedPlayers.get(current));
|
||||
@@ -275,8 +275,8 @@ class GameControllerTest {
|
||||
Player current = game.getCurrentState().getCurrentPlayer();
|
||||
assertNotNull(current);
|
||||
|
||||
assertTrue(controller.DisconnectedPlayer(current.getUserName()));
|
||||
assertTrue(controller.ReconnectPlayer(current.getUserName()));
|
||||
assertTrue(controller.disconnectedPlayer(current.getUserName()));
|
||||
assertTrue(controller.reconnectPlayer(current.getUserName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -289,13 +289,13 @@ class GameControllerTest {
|
||||
assertFalse(controller.drawLowerTribeCard("ghost", 0));
|
||||
assertFalse(controller.drawUpperBuildingCard("ghost", 0));
|
||||
assertFalse(controller.drawLowerBuildingCard("ghost", 0));
|
||||
assertFalse(controller.SkipTurn("ghost"));
|
||||
assertFalse(controller.skipTurn("ghost"));
|
||||
assertFalse(controller.drawUpperTribeCard("ghost", 0));
|
||||
assertFalse(controller.drawUpperBuildingCard("ghost", 0));
|
||||
assertFalse(controller.SkipTurn("ghost"));
|
||||
assertFalse(controller.TotemChoice("ghost", Totems.values()[0].name()));
|
||||
assertFalse(controller.DisconnectedPlayer("ghost"));
|
||||
assertFalse(controller.ReconnectPlayer("ghost"));
|
||||
assertFalse(controller.skipTurn("ghost"));
|
||||
assertFalse(controller.totemChoice("ghost", Totems.values()[0].name()));
|
||||
assertFalse(controller.disconnectedPlayer("ghost"));
|
||||
assertFalse(controller.reconnectPlayer("ghost"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -625,7 +625,7 @@ class GameControllerTest {
|
||||
assertTrue(optionalPlayer.buildingCards.stream()
|
||||
.anyMatch(building -> building.getEffectId() == 12));
|
||||
|
||||
assertTrue(controller.SkipTurn(optionalPlayer.getUserName()));
|
||||
assertTrue(controller.skipTurn(optionalPlayer.getUserName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -695,7 +695,7 @@ class GameControllerTest {
|
||||
|
||||
assertFalse(controller.drawUpperTribeCard(wrongPlayer.getUserName(), 0));
|
||||
assertFalse(controller.drawUpperBuildingCard(wrongPlayer.getUserName(), 0));
|
||||
assertFalse(controller.SkipTurn(wrongPlayer.getUserName()));
|
||||
assertFalse(controller.skipTurn(wrongPlayer.getUserName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -714,7 +714,7 @@ class GameControllerTest {
|
||||
assertFalse(game.getLowerListTribeCards().isEmpty());
|
||||
assertTrue(firstNonEventIndexOrMinusOne(game.getLowerListTribeCards()) != -1);
|
||||
|
||||
assertFalse(controller.SkipTurn(current.getUserName()));
|
||||
assertFalse(controller.skipTurn(current.getUserName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -733,7 +733,7 @@ class GameControllerTest {
|
||||
assertFalse(game.getUpperListTribeCards().isEmpty());
|
||||
assertTrue(firstNonEventIndexOrMinusOne(game.getUpperListTribeCards()) != -1);
|
||||
|
||||
assertFalse(controller.SkipTurn(current.getUserName()));
|
||||
assertFalse(controller.skipTurn(current.getUserName()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ class GameTest {
|
||||
|
||||
Totems selectedTotem = availableTotems.get(0);
|
||||
|
||||
assertTrue(game.TotemChoice(current, selectedTotem));
|
||||
assertTrue(game.totemChoice(current, selectedTotem));
|
||||
assertEquals(selectedTotem, current.totem);
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ class GameTest {
|
||||
|
||||
if(game.getCurrentState().getNUpper() == 0 || game.getUpperListTribeCards().stream().allMatch(TribeCard::IsEventCard))
|
||||
{
|
||||
assertTrue(game.SkipTurn(current));
|
||||
assertTrue(game.skipTurn(current));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ class GameTest {
|
||||
|
||||
if(game.getCurrentState().getNLower() == 0 || game.getLowerListTribeCards().stream().allMatch(TribeCard::IsEventCard))
|
||||
{
|
||||
assertTrue(game.SkipTurn(current));
|
||||
assertTrue(game.skipTurn(current));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -177,7 +177,7 @@ class GameTest {
|
||||
Player current = game.getCurrentState().getCurrentPlayer();
|
||||
assertNotNull(current);
|
||||
|
||||
assertTrue(game.SkipTurn(current));
|
||||
assertTrue(game.skipTurn(current));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -355,12 +355,12 @@ class GameTest {
|
||||
Player firstPlayer = game.getCurrentState().getCurrentPlayer();
|
||||
Totems chosenTotem = game.getAvailableTotems().get(0);
|
||||
|
||||
assertTrue(game.TotemChoice(firstPlayer, chosenTotem));
|
||||
assertTrue(game.totemChoice(firstPlayer, chosenTotem));
|
||||
|
||||
Player secondPlayer = game.getCurrentState().getCurrentPlayer();
|
||||
assertNotNull(secondPlayer);
|
||||
|
||||
assertFalse(game.TotemChoice(secondPlayer, chosenTotem));
|
||||
assertFalse(game.totemChoice(secondPlayer, chosenTotem));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -380,7 +380,7 @@ class GameTest {
|
||||
|
||||
Totems availableTotem = game.getAvailableTotems().get(0);
|
||||
|
||||
assertFalse(game.TotemChoice(wrongPlayer, availableTotem));
|
||||
assertFalse(game.totemChoice(wrongPlayer, availableTotem));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -400,7 +400,7 @@ class GameTest {
|
||||
Player current = game.getCurrentState().getCurrentPlayer();
|
||||
Totems chosenTotem = game.getAvailableTotems().get(0);
|
||||
|
||||
assertTrue(game.TotemChoice(current, chosenTotem));
|
||||
assertTrue(game.totemChoice(current, chosenTotem));
|
||||
|
||||
assertEquals(initialAvailableTotems - 1, game.getAvailableTotems().size());
|
||||
assertFalse(game.getAvailableTotems().contains(chosenTotem));
|
||||
@@ -651,7 +651,7 @@ class GameTest {
|
||||
Player current = game.getCurrentState().getCurrentPlayer();
|
||||
assertNotNull(current);
|
||||
|
||||
assertTrue(game.SkipTurn(current));
|
||||
assertTrue(game.skipTurn(current));
|
||||
|
||||
assertEquals(GameStages.OPT_CARD_E, game.getCurrentState().getGameStage());
|
||||
assertNotEquals(current, game.getCurrentState().getCurrentPlayer());
|
||||
@@ -787,7 +787,7 @@ class GameTest {
|
||||
|
||||
assertFalse(game.DrawUpperTribeCardByIndex(current, 0));
|
||||
assertFalse(game.DrawUpperBuildingCardByIndex(current, 0));
|
||||
assertFalse(game.SkipTurn(current));
|
||||
assertFalse(game.skipTurn(current));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -808,7 +808,7 @@ class GameTest {
|
||||
|
||||
assertFalse(game.DrawUpperTribeCardByIndex(wrongPlayer, 0));
|
||||
assertFalse(game.DrawUpperBuildingCardByIndex(wrongPlayer, 0));
|
||||
assertFalse(game.SkipTurn(wrongPlayer));
|
||||
assertFalse(game.skipTurn(wrongPlayer));
|
||||
|
||||
assertFalse(game.DrawUpperTribeCardByIndex(current, -1));
|
||||
assertFalse(game.DrawUpperTribeCardByIndex(current, 999));
|
||||
@@ -949,7 +949,7 @@ class GameTest {
|
||||
Player current = game.getCurrentState().getCurrentPlayer();
|
||||
assertNotNull(current);
|
||||
|
||||
assertTrue(game.SkipTurn(current));
|
||||
assertTrue(game.skipTurn(current));
|
||||
|
||||
assertEquals(GameStages.SLOT_CHOICE, game.getCurrentState().getGameStage());
|
||||
assertEquals(roundBefore + 1, game.getCurrentState().getRound());
|
||||
@@ -1228,7 +1228,7 @@ class GameTest {
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
|
||||
assertFalse(game.SkipTurn(wrongPlayer));
|
||||
assertFalse(game.skipTurn(wrongPlayer));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1255,7 +1255,7 @@ class GameTest {
|
||||
"The test requires at least one drawable tribe card."
|
||||
);
|
||||
|
||||
assertFalse(game.SkipTurn(current));
|
||||
assertFalse(game.skipTurn(current));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1327,7 +1327,7 @@ class GameTest {
|
||||
|
||||
assertEquals(GameStages.SLOT_CHOICE, game.getCurrentState().getGameStage());
|
||||
|
||||
assertFalse(game.SkipTurn(current));
|
||||
assertFalse(game.skipTurn(current));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1339,7 +1339,7 @@ class GameTest {
|
||||
Player current = game.getCurrentState().getCurrentPlayer();
|
||||
assertNotNull(current);
|
||||
|
||||
assertTrue(game.DisconnectedPlayer(current));
|
||||
assertTrue(game.disconnectedPlayer(current));
|
||||
|
||||
assertTrue(game.disconnetedPlayers.containsKey(current));
|
||||
assertTrue(game.disconnetedPlayers.get(current));
|
||||
@@ -1354,8 +1354,8 @@ class GameTest {
|
||||
|
||||
Player current = game.getCurrentState().getCurrentPlayer();
|
||||
|
||||
assertTrue(game.DisconnectedPlayer(current));
|
||||
assertFalse(game.DisconnectedPlayer(current));
|
||||
assertTrue(game.disconnectedPlayer(current));
|
||||
assertFalse(game.disconnectedPlayer(current));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1366,10 +1366,10 @@ class GameTest {
|
||||
|
||||
Player current = game.getCurrentState().getCurrentPlayer();
|
||||
|
||||
assertTrue(game.DisconnectedPlayer(current));
|
||||
assertTrue(game.disconnectedPlayer(current));
|
||||
assertTrue(game.disconnetedPlayers.containsKey(current));
|
||||
|
||||
assertTrue(game.ReconnectPlayer(current));
|
||||
assertTrue(game.reconnectPlayer(current));
|
||||
assertFalse(game.disconnetedPlayers.containsKey(current));
|
||||
}
|
||||
|
||||
@@ -1381,7 +1381,7 @@ class GameTest {
|
||||
|
||||
Player current = game.getCurrentState().getCurrentPlayer();
|
||||
|
||||
assertTrue(game.DisconnectedPlayer(current));
|
||||
assertTrue(game.disconnectedPlayer(current));
|
||||
assertFalse(game.disconnetedPlayers.isEmpty());
|
||||
|
||||
game.ClearDisconnected();
|
||||
|
||||
Reference in New Issue
Block a user