Merge remote-tracking branch 'origin/main'
This commit is contained in:
@@ -10,6 +10,8 @@ public enum ErrorType {
|
||||
WRONG_PLAYER_NUMBER("Wrong player number"),
|
||||
/** The server has crashed or become unreachable. */
|
||||
SERVER_CRASHED("Server crashed"),
|
||||
/** The server is unreachable. */
|
||||
SERVER_UNREACHABLE("Server unreachable"),
|
||||
/** A generic, unclassified error occurred. */
|
||||
GENERIC_ERROR("Generic error"),
|
||||
/** The game has already started and cannot accept new players. */
|
||||
|
||||
@@ -208,6 +208,9 @@ public class GameEventProcessor {
|
||||
if (!saveManager.save(game)) {
|
||||
System.out.println("\n!!! Save failed !!!\n");
|
||||
}
|
||||
else {
|
||||
System.out.println(event.getUsername()+": "+ event.getEventType() + " save successful.");
|
||||
}
|
||||
|
||||
// During the lobby phase a disconnection only removes the player
|
||||
// from the list; no broadcast is needed.
|
||||
@@ -268,12 +271,14 @@ public class GameEventProcessor {
|
||||
|
||||
if (disconnectionTimer != null && !disconnectionTimer.isDone()) {
|
||||
disconnectionTimer.cancel(false);
|
||||
System.out.println("Disconnection TIMER reset");
|
||||
}
|
||||
|
||||
disconnectionTimer = timerExecutor.schedule(
|
||||
() -> endGameForfeit(game),
|
||||
1, TimeUnit.MINUTES
|
||||
);
|
||||
System.out.println("Disconnection TIMER started, 60 seconds from now..." );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -162,6 +162,7 @@ public class Game implements Serializable {
|
||||
nextPlayerSetup();
|
||||
}
|
||||
else {
|
||||
totemChoiceQueue.removeIf(x->x.getUserName().equals(player.getUserName()));
|
||||
if (totemChoiceQueue.isEmpty()) {
|
||||
player.setTotem(getAvailableTotems().get(new Random().nextInt(getAvailableTotems().size())));
|
||||
} else {
|
||||
@@ -207,6 +208,11 @@ public class Game implements Serializable {
|
||||
disconnectedPlayers.remove(player);
|
||||
}
|
||||
}
|
||||
else if(currentState.getGameStage() == GameStages.TOTEM_CHOICE)
|
||||
{
|
||||
totemChoiceQueue.removeIf(x->x.getUserName().equals(player.getUserName()));
|
||||
totemChoiceQueue.add(player);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ public class RMIClient implements IClient {
|
||||
return status;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return ErrorType.GENERIC_ERROR;
|
||||
return ErrorType.SERVER_UNREACHABLE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -98,6 +98,6 @@ public class RMIHeartbeat {
|
||||
|
||||
clients.remove(username);
|
||||
actionQueue.add(new DisconnectedPlayer(username));
|
||||
System.out.println("RMI disconnected: " + username);
|
||||
System.err.println("(RMI) Disconnected player: " + username);
|
||||
}
|
||||
}
|
||||
@@ -107,8 +107,9 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
|
||||
if (controller.addPlayer(username)) {
|
||||
clients.put(username, callback);
|
||||
playerList.put(username, true);
|
||||
startWatchdog(username);
|
||||
System.out.println("Accepted player: " + username);
|
||||
startWatchdog(username);
|
||||
System.out.println("Heartbeat connected for: " + username);
|
||||
return null;
|
||||
} else {
|
||||
return ErrorType.USERNAME_ALREADY_USED;
|
||||
@@ -119,8 +120,9 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
|
||||
if(!playerList.containsKey(username)){
|
||||
clients.put(username, callback);
|
||||
playerList.put(username, true);
|
||||
startWatchdog(username);
|
||||
System.out.println("(After crash)Reconnected player: " + username);
|
||||
startWatchdog(username);
|
||||
System.out.println("Heartbeat connected for: " + username);
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
@@ -130,6 +132,7 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
|
||||
clients.put(username, callback);
|
||||
System.out.println("Reconnected player: " + username);
|
||||
startWatchdog(username);
|
||||
System.out.println("Heartbeat connected for: " + username);
|
||||
Game game = controller.getModel();
|
||||
callback.onGameInit(new MiniModel(
|
||||
game.getSlotMap(), game.getOrderLogicCard(), game.getCurrentState(),
|
||||
|
||||
@@ -105,7 +105,7 @@ public class TCPClient implements IClient {
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return ErrorType.GENERIC_ERROR;
|
||||
return ErrorType.SERVER_UNREACHABLE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -91,7 +91,6 @@ public class ClientHandler implements Runnable {
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println("Error in incoming connection/disconnection: " + username);
|
||||
} catch (ClassNotFoundException e) {
|
||||
System.err.println("Class not found: " + username);
|
||||
} finally {
|
||||
@@ -144,7 +143,7 @@ public class ClientHandler implements Runnable {
|
||||
clientHandlers.remove(this);
|
||||
limitedMap.put(username, false);
|
||||
actionQueue.add(new DisconnectedPlayer(username));
|
||||
System.out.println("Disconnected player: " + username);
|
||||
System.err.println("(TCP) Disconnected player: " + username);
|
||||
try { clientSocket.close(); } catch (IOException ignored) {}
|
||||
}
|
||||
}
|
||||
@@ -124,8 +124,7 @@ public class HeartbeatHandler implements Runnable {
|
||||
private synchronized void disconnect() {
|
||||
running = false;
|
||||
watchdog.shutdownNow();
|
||||
mainHandler.disconnect(); // disconnette anche il socket principale
|
||||
System.out.println("Disconnected: " + username);
|
||||
mainHandler.disconnect();
|
||||
try { socket.close(); } catch (IOException ignored) {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,6 @@ public class SaveManager {
|
||||
try (ObjectOutputStream oos = new ObjectOutputStream(
|
||||
new BufferedOutputStream(new FileOutputStream(filePath.toFile())))) {
|
||||
oos.writeObject(game);
|
||||
System.out.println("Game saved to: " + filePath.toAbsolutePath());
|
||||
return true;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
||||
Reference in New Issue
Block a user