Fix: Fixed Model Setting Logic In RMIServer.java And TCPServer.java When A Game Is Restored From Disk.
This commit is contained in:
@@ -83,10 +83,15 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
|
||||
}
|
||||
synchronized (controller) {
|
||||
if(playerList.isEmpty()){
|
||||
if(controller.getModel() == null){
|
||||
model = new Game(preferredInt);
|
||||
controller.setModel(model);
|
||||
playerList.setLimit(preferredInt);
|
||||
}
|
||||
else{
|
||||
model = controller.getModel();
|
||||
}
|
||||
}
|
||||
if (controller.addPlayer(username)) {
|
||||
clients.put(username, callback);
|
||||
playerList.put(username,true);
|
||||
|
||||
@@ -88,12 +88,13 @@ public class TCPServer {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (playerList.isEmpty()) {
|
||||
if(controller.getModel() == null){
|
||||
Game model = new Game(eventAddPlayer.getProposedNPlayer());
|
||||
controller.setModel(model);
|
||||
playerList.setLimit(eventAddPlayer.getProposedNPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
String username = eventAddPlayer.getUsername();
|
||||
|
||||
@@ -114,7 +115,8 @@ public class TCPServer {
|
||||
// metti in attesa del socket heartbeat
|
||||
|
||||
|
||||
} else if (playerList.containsKey(username) && !playerList.get(username)) {
|
||||
}
|
||||
else if(playerList.containsKey(username) && !playerList.get(username)){
|
||||
// riconnessione
|
||||
playerList.put(username, true);
|
||||
System.out.println("Reconnected player: " + username);
|
||||
@@ -131,14 +133,16 @@ public class TCPServer {
|
||||
clientHandlers.add(handler);
|
||||
connectedPlayers++;
|
||||
actionQueue.add(new ReconnectPlayer(username));
|
||||
} else {
|
||||
}
|
||||
else{
|
||||
clientSocket.getOutputStream().write(-1);
|
||||
clientSocket.close();
|
||||
System.out.println("Player could not be added. Connection terminated.");
|
||||
}
|
||||
|
||||
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
}
|
||||
catch(IOException | ClassNotFoundException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user