Fix: public attribute are now private with getter/setter, useless synchronized removed
This commit is contained in:
@@ -62,14 +62,19 @@
|
|||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.13.0</version>
|
<version>3.13.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>25</source>
|
<release>25</release>
|
||||||
<target>25</target>
|
<compilerArgs>
|
||||||
|
<arg>--enable-preview</arg>
|
||||||
|
</compilerArgs>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>3.2.5</version>
|
<version>3.2.5</version>
|
||||||
|
<configuration>
|
||||||
|
<argLine>--enable-preview</argLine>
|
||||||
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.openjfx</groupId>
|
<groupId>org.openjfx</groupId>
|
||||||
@@ -77,7 +82,6 @@
|
|||||||
<version>0.0.8</version>
|
<version>0.0.8</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<!-- Default configuration for running with: mvn clean javafx:run -->
|
|
||||||
<id>default-cli</id>
|
<id>default-cli</id>
|
||||||
<configuration>
|
<configuration>
|
||||||
<mainClass>it.polimi.ingsw.gc14.HelloApplication</mainClass>
|
<mainClass>it.polimi.ingsw.gc14.HelloApplication</mainClass>
|
||||||
|
|||||||
@@ -206,12 +206,6 @@ public class GameController {
|
|||||||
return model.totemChoice(player, Totems.valueOf(totem));
|
return model.totemChoice(player, Totems.valueOf(totem));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #endGameForFeit()} instead.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public synchronized void EndGameForFeit() { endGameForFeit(); }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ends the game due to forfeit: all remaining players are absent,
|
* Ends the game due to forfeit: all remaining players are absent,
|
||||||
* so the game is terminated and final scores are computed.
|
* so the game is terminated and final scores are computed.
|
||||||
|
|||||||
@@ -282,7 +282,7 @@ public class GameEventProcessor {
|
|||||||
synchronized (gameController) {
|
synchronized (gameController) {
|
||||||
gameController.endGameForFeit();
|
gameController.endGameForFeit();
|
||||||
EndedGame forfeitEnd = new EndedGame(
|
EndedGame forfeitEnd = new EndedGame(
|
||||||
game.getSlotMap(), game.orderLogicCard,
|
game.getSlotMap(), game.getOrderLogicCard(),
|
||||||
game.getCurrentState(), game.getPlayerStanding()
|
game.getCurrentState(), game.getPlayerStanding()
|
||||||
);
|
);
|
||||||
broadcaster.notifyAll(forfeitEnd);
|
broadcaster.notifyAll(forfeitEnd);
|
||||||
@@ -313,7 +313,7 @@ public class GameEventProcessor {
|
|||||||
broadcaster.notifyAll(event);
|
broadcaster.notifyAll(event);
|
||||||
if (game.getCurrentState().getRound() != roundBefore) {
|
if (game.getCurrentState().getRound() != roundBefore) {
|
||||||
ApplyNextRound nextRound = new ApplyNextRound(
|
ApplyNextRound nextRound = new ApplyNextRound(
|
||||||
game.getSlotMap(), game.orderLogicCard, game.getCurrentState(),
|
game.getSlotMap(), game.getOrderLogicCard(), game.getCurrentState(),
|
||||||
game.getPlayers(),
|
game.getPlayers(),
|
||||||
game.getUpperListTribeCards(), game.getLowerListTribeCards(),
|
game.getUpperListTribeCards(), game.getLowerListTribeCards(),
|
||||||
game.getUpperListBuilding(), game.getLowerListBuilding()
|
game.getUpperListBuilding(), game.getLowerListBuilding()
|
||||||
@@ -321,7 +321,7 @@ public class GameEventProcessor {
|
|||||||
broadcaster.notifyAll(nextRound);
|
broadcaster.notifyAll(nextRound);
|
||||||
} else if (game.getCurrentState().getGameStage() == GameStages.ENDED) {
|
} else if (game.getCurrentState().getGameStage() == GameStages.ENDED) {
|
||||||
EndedGame endedGame = new EndedGame(
|
EndedGame endedGame = new EndedGame(
|
||||||
game.getSlotMap(), game.orderLogicCard,
|
game.getSlotMap(), game.getOrderLogicCard(),
|
||||||
game.getCurrentState(), game.getPlayerStanding()
|
game.getCurrentState(), game.getPlayerStanding()
|
||||||
);
|
);
|
||||||
broadcaster.notifyAll(endedGame);
|
broadcaster.notifyAll(endedGame);
|
||||||
@@ -349,7 +349,7 @@ public class GameEventProcessor {
|
|||||||
* @return a new {@link ArrayList} of disconnected usernames.
|
* @return a new {@link ArrayList} of disconnected usernames.
|
||||||
*/
|
*/
|
||||||
private ArrayList<String> buildDisconnectedList(Game game) {
|
private ArrayList<String> buildDisconnectedList(Game game) {
|
||||||
return game.disconnetedPlayers.entrySet().stream()
|
return game.disconnectedPlayers.entrySet().stream()
|
||||||
.filter(Map.Entry::getValue)
|
.filter(Map.Entry::getValue)
|
||||||
.map(e -> e.getKey().getUserName())
|
.map(e -> e.getKey().getUserName())
|
||||||
.collect(Collectors.toCollection(ArrayList::new));
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
|||||||
@@ -63,37 +63,37 @@ public class LimitedMap<K, V> implements Map<K, V> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized V remove(Object key) { return map.remove(key); }
|
public V remove(Object key) { return map.remove(key); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized V get(Object key) { return map.get(key); }
|
public V get(Object key) { return map.get(key); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized boolean containsKey(Object key) { return map.containsKey(key); }
|
public boolean containsKey(Object key) { return map.containsKey(key); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized boolean containsValue(Object value) { return map.containsValue(value); }
|
public boolean containsValue(Object value) { return map.containsValue(value); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized int size() { return map.size(); }
|
public int size() { return map.size(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized boolean isEmpty() { return map.isEmpty(); }
|
public boolean isEmpty() { return map.isEmpty(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void putAll(Map<? extends K, ? extends V> m) { m.forEach(this::put); }
|
public void putAll(Map<? extends K, ? extends V> m) { m.forEach(this::put); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void clear() { map.clear(); }
|
public void clear() { map.clear(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized Set<K> keySet() { return map.keySet(); }
|
public Set<K> keySet() { return map.keySet(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized Collection<V> values() { return map.values(); }
|
public Collection<V> values() { return map.values(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized Set<Entry<K, V>> entrySet() { return map.entrySet(); }
|
public Set<Entry<K, V>> entrySet() { return map.entrySet(); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a new size limit for this map.
|
* Sets a new size limit for this map.
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ public class Game implements Serializable {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
while(disconnetedPlayers.containsKey(nextPlayer)&& disconnetedPlayers.get(nextPlayer))
|
while(disconnectedPlayers.containsKey(nextPlayer)&& disconnectedPlayers.get(nextPlayer))
|
||||||
{
|
{
|
||||||
nextPlayer.setTotem(getAvailableTotems().get(new Random().nextInt(0,getAvailableTotems().size())));
|
nextPlayer.setTotem(getAvailableTotems().get(new Random().nextInt(0,getAvailableTotems().size())));
|
||||||
nextPlayer=totemChoiceQueue.poll();
|
nextPlayer=totemChoiceQueue.poll();
|
||||||
@@ -121,7 +121,7 @@ public class Game implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* Map tracking the players who are currently disconnected.
|
* Map tracking the players who are currently disconnected.
|
||||||
*/
|
*/
|
||||||
public Map<Player,Boolean> disconnetedPlayers = new HashMap<>();
|
public Map<Player,Boolean> disconnectedPlayers = new HashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks the specified player as disconnected and updates the game flow accordingly.
|
* Marks the specified player as disconnected and updates the game flow accordingly.
|
||||||
@@ -137,11 +137,11 @@ public class Game implements Serializable {
|
|||||||
*/
|
*/
|
||||||
public synchronized boolean disconnectedPlayer(Player player)
|
public synchronized boolean disconnectedPlayer(Player player)
|
||||||
{
|
{
|
||||||
if(disconnetedPlayers.containsKey(player) && disconnetedPlayers.get(player))
|
if(disconnectedPlayers.containsKey(player) && disconnectedPlayers.get(player))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
disconnetedPlayers.put(player,true);
|
disconnectedPlayers.put(player,true);
|
||||||
if (currentState.getGameStage().equals(GameStages.WAITING)) {
|
if (currentState.getGameStage().equals(GameStages.WAITING)) {
|
||||||
playersList.remove(player);
|
playersList.remove(player);
|
||||||
totemChoiceQueue.remove(player);
|
totemChoiceQueue.remove(player);
|
||||||
@@ -179,14 +179,14 @@ public class Game implements Serializable {
|
|||||||
*/
|
*/
|
||||||
public synchronized boolean reconnectPlayer(Player player)
|
public synchronized boolean reconnectPlayer(Player player)
|
||||||
{
|
{
|
||||||
if(!disconnetedPlayers.containsKey(player))
|
if(!disconnectedPlayers.containsKey(player))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
disconnetedPlayers.put(player,false);
|
disconnectedPlayers.put(player,false);
|
||||||
if(currentState.getGameStage().equals(GameStages.SLOT_CHOICE) )
|
if(currentState.getGameStage().equals(GameStages.SLOT_CHOICE) )
|
||||||
{
|
{
|
||||||
disconnetedPlayers.remove(player);
|
disconnectedPlayers.remove(player);
|
||||||
if(!orderLogicCard.players.contains(player))
|
if(!orderLogicCard.players.contains(player))
|
||||||
{
|
{
|
||||||
orderLogicCard.pushNoEffect(player);
|
orderLogicCard.pushNoEffect(player);
|
||||||
@@ -195,7 +195,7 @@ public class Game implements Serializable {
|
|||||||
else if(currentState.getGameStage().equals(GameStages.RES_ACTIONS)) {
|
else if(currentState.getGameStage().equals(GameStages.RES_ACTIONS)) {
|
||||||
if(slotMap.containsValue(player))
|
if(slotMap.containsValue(player))
|
||||||
{
|
{
|
||||||
disconnetedPlayers.remove(player);
|
disconnectedPlayers.remove(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -206,7 +206,7 @@ public class Game implements Serializable {
|
|||||||
*/
|
*/
|
||||||
public synchronized void ClearDisconnected()
|
public synchronized void ClearDisconnected()
|
||||||
{
|
{
|
||||||
disconnetedPlayers.clear();
|
disconnectedPlayers.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -252,7 +252,14 @@ public class Game implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* The order logic card associated with this game.
|
* The order logic card associated with this game.
|
||||||
*/
|
*/
|
||||||
public OrderLogicCard orderLogicCard;
|
private OrderLogicCard orderLogicCard;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the order logic card associated with this game.
|
||||||
|
*
|
||||||
|
* @return the order logic card.
|
||||||
|
*/
|
||||||
|
public OrderLogicCard getOrderLogicCard() { return orderLogicCard; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The board associated with this game.
|
* The board associated with this game.
|
||||||
@@ -698,7 +705,7 @@ public class Game implements Serializable {
|
|||||||
|
|
||||||
if (GameStages.SLOT_CHOICE == currentState.getGameStage()) {
|
if (GameStages.SLOT_CHOICE == currentState.getGameStage()) {
|
||||||
Player tempPlayer = orderLogicCard.pull();
|
Player tempPlayer = orderLogicCard.pull();
|
||||||
if(disconnetedPlayers.containsKey(tempPlayer) && disconnetedPlayers.get(tempPlayer)) {
|
if(disconnectedPlayers.containsKey(tempPlayer) && disconnectedPlayers.get(tempPlayer)) {
|
||||||
nextPlayerSetup();
|
nextPlayerSetup();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -750,7 +757,7 @@ public class Game implements Serializable {
|
|||||||
|
|
||||||
for (Map.Entry<Slot,Player> entry : slotMap.entrySet()) {
|
for (Map.Entry<Slot,Player> entry : slotMap.entrySet()) {
|
||||||
if (entry.getValue() != null) {
|
if (entry.getValue() != null) {
|
||||||
if(disconnetedPlayers.containsKey(entry.getValue())&&disconnetedPlayers.get(entry.getValue()))
|
if(disconnectedPlayers.containsKey(entry.getValue())&& disconnectedPlayers.get(entry.getValue()))
|
||||||
{
|
{
|
||||||
orderLogicCard.push(entry.getValue());
|
orderLogicCard.push(entry.getValue());
|
||||||
entry.setValue(null);
|
entry.setValue(null);
|
||||||
@@ -782,7 +789,7 @@ public class Game implements Serializable {
|
|||||||
|
|
||||||
if (optionalPlayer != null) {
|
if (optionalPlayer != null) {
|
||||||
currentState.PlayerUpdate(optionalPlayer, null);
|
currentState.PlayerUpdate(optionalPlayer, null);
|
||||||
if(disconnetedPlayers.containsKey(currentState.getCurrentPlayer())&& disconnetedPlayers.get(currentState.getCurrentPlayer())) {
|
if(disconnectedPlayers.containsKey(currentState.getCurrentPlayer())&& disconnectedPlayers.get(currentState.getCurrentPlayer())) {
|
||||||
nextPlayerSetup();
|
nextPlayerSetup();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -815,7 +822,7 @@ public class Game implements Serializable {
|
|||||||
for (Player p :playersList) {
|
for (Player p :playersList) {
|
||||||
long count = p.getBuildingCards().stream().filter(x -> x.getEffectId() == 12).count();
|
long count = p.getBuildingCards().stream().filter(x -> x.getEffectId() == 12).count();
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
if(disconnetedPlayers.containsKey(p)&& disconnetedPlayers.get(p))
|
if(disconnectedPlayers.containsKey(p)&& disconnectedPlayers.get(p))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -832,12 +839,12 @@ public class Game implements Serializable {
|
|||||||
|
|
||||||
if (currentState.getRound() < 10) {
|
if (currentState.getRound() < 10) {
|
||||||
nextRound();
|
nextRound();
|
||||||
for(Map.Entry<Player,Boolean> entry: disconnetedPlayers.entrySet())
|
for(Map.Entry<Player,Boolean> entry: disconnectedPlayers.entrySet())
|
||||||
{
|
{
|
||||||
if(!entry.getValue())
|
if(!entry.getValue())
|
||||||
{
|
{
|
||||||
orderLogicCard.pushNoEffect(entry.getKey());
|
orderLogicCard.pushNoEffect(entry.getKey());
|
||||||
disconnetedPlayers.remove(entry.getKey());
|
disconnectedPlayers.remove(entry.getKey());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -999,7 +1006,7 @@ public class Game implements Serializable {
|
|||||||
* ordered by prestige value and, in case of a tie, by food value.
|
* 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);
|
Player winner=playersList.stream().filter(x->!disconnectedPlayers.containsKey(x)||!disconnectedPlayers.get(x)).toList().get(0);
|
||||||
currentState.GameStageUpdate(GameStages.ENDED);
|
currentState.GameStageUpdate(GameStages.ENDED);
|
||||||
playerStanding=new ArrayList<>(playersList);
|
playerStanding=new ArrayList<>(playersList);
|
||||||
playerStanding.remove(winner);
|
playerStanding.remove(winner);
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ public abstract class NetworkEvent implements Serializable {
|
|||||||
* @param disconnectedUsernames usernames of currently disconnected players.
|
* @param disconnectedUsernames usernames of currently disconnected players.
|
||||||
*/
|
*/
|
||||||
public void enrichWithGameState(Game game, ArrayList<String> disconnectedUsernames) {
|
public void enrichWithGameState(Game game, ArrayList<String> disconnectedUsernames) {
|
||||||
setData(game.getSlotMap(), game.orderLogicCard, game.getCurrentState(), game.getPlayers());
|
setData(game.getSlotMap(), game.getOrderLogicCard(), game.getCurrentState(), game.getPlayers());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ public class RMIClient implements IClient {
|
|||||||
if (!running) return;
|
if (!running) return;
|
||||||
running = false;
|
running = false;
|
||||||
if (pingSender != null) pingSender.shutdownNow();
|
if (pingSender != null) pingSender.shutdownNow();
|
||||||
controller.miniModel=null;
|
controller.setModel(null);
|
||||||
controller.setClient(null);
|
controller.setClient(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import java.rmi.registry.LocateRegistry;
|
|||||||
import java.rmi.registry.Registry;
|
import java.rmi.registry.Registry;
|
||||||
import java.rmi.server.UnicastRemoteObject;
|
import java.rmi.server.UnicastRemoteObject;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
@@ -130,7 +129,7 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
|
|||||||
System.out.println("Reconnected player: " + username);
|
System.out.println("Reconnected player: " + username);
|
||||||
startWatchdog(username);
|
startWatchdog(username);
|
||||||
Game game = controller.getModel();
|
Game game = controller.getModel();
|
||||||
callback.onGameInit(new MiniModel(game.getSlotMap(), game.orderLogicCard, game.getCurrentState(), game.getPlayers(), game.getAvailableTotems(), game.getUpperListTribeCards(), game.getLowerListTribeCards(), game.getUpperListBuilding(), game.getLowerListBuilding(), game.disconnetedPlayers.entrySet().stream().filter(Map.Entry::getValue).map(x -> x.getKey().getUserName()).collect(Collectors.toCollection(ArrayList::new))));
|
callback.onGameInit(new MiniModel(game.getSlotMap(), game.getOrderLogicCard(), game.getCurrentState(), game.getPlayers(), game.getAvailableTotems(), game.getUpperListTribeCards(), game.getLowerListTribeCards(), game.getUpperListBuilding(), game.getLowerListBuilding(), game.disconnectedPlayers.entrySet().stream().filter(Map.Entry::getValue).map(x -> x.getKey().getUserName()).collect(Collectors.toCollection(ArrayList::new))));
|
||||||
System.out.println("Model sent: " + username);
|
System.out.println("Model sent: " + username);
|
||||||
actionQueue.add(new ReconnectPlayer(username));
|
actionQueue.add(new ReconnectPlayer(username));
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -262,11 +262,11 @@ public class TCPServer {
|
|||||||
Game game = controller.getModel();
|
Game game = controller.getModel();
|
||||||
handler.notifyMiniModel(new MiniModel(
|
handler.notifyMiniModel(new MiniModel(
|
||||||
game.getSlotMap(),
|
game.getSlotMap(),
|
||||||
game.orderLogicCard,
|
game.getOrderLogicCard(),
|
||||||
game.getCurrentState(),
|
game.getCurrentState(),
|
||||||
game.getPlayers(),
|
game.getPlayers(),
|
||||||
game.getAvailableTotems(),
|
game.getAvailableTotems(),
|
||||||
game.getUpperListTribeCards(), game.getLowerListTribeCards(), game.getUpperListBuilding(), game.getLowerListBuilding(), game.disconnetedPlayers.entrySet().stream().filter(Map.Entry::getValue).map(x -> x.getKey().getUserName()).collect(Collectors.toCollection(ArrayList::new))
|
game.getUpperListTribeCards(), game.getLowerListTribeCards(), game.getUpperListBuilding(), game.getLowerListBuilding(), game.disconnectedPlayers.entrySet().stream().filter(Map.Entry::getValue).map(x -> x.getKey().getUserName()).collect(Collectors.toCollection(ArrayList::new))
|
||||||
));
|
));
|
||||||
|
|
||||||
Thread thread = new Thread(handler);
|
Thread thread = new Thread(handler);
|
||||||
|
|||||||
@@ -95,11 +95,11 @@ public class ServerLauncher {
|
|||||||
synchronized (gameController) {
|
synchronized (gameController) {
|
||||||
Game game = gameController.getModel();
|
Game game = gameController.getModel();
|
||||||
miniModel = new MiniModel(
|
miniModel = new MiniModel(
|
||||||
game.getSlotMap(), game.orderLogicCard, game.getCurrentState(),
|
game.getSlotMap(), game.getOrderLogicCard(), game.getCurrentState(),
|
||||||
game.getPlayers(), game.getAvailableTotems(),
|
game.getPlayers(), game.getAvailableTotems(),
|
||||||
game.getUpperListTribeCards(), game.getLowerListTribeCards(),
|
game.getUpperListTribeCards(), game.getLowerListTribeCards(),
|
||||||
game.getUpperListBuilding(), game.getLowerListBuilding(),
|
game.getUpperListBuilding(), game.getLowerListBuilding(),
|
||||||
game.disconnetedPlayers.entrySet().stream()
|
game.disconnectedPlayers.entrySet().stream()
|
||||||
.filter(Map.Entry::getValue)
|
.filter(Map.Entry::getValue)
|
||||||
.map(e -> e.getKey().getUserName())
|
.map(e -> e.getKey().getUserName())
|
||||||
.collect(Collectors.toCollection(ArrayList::new))
|
.collect(Collectors.toCollection(ArrayList::new))
|
||||||
@@ -127,16 +127,11 @@ public class ServerLauncher {
|
|||||||
* Runs the event-processing loop until the thread is interrupted.
|
* Runs the event-processing loop until the thread is interrupted.
|
||||||
*
|
*
|
||||||
* <p>A {@link ConcurrentModificationException} is caught and logged rather
|
* <p>A {@link ConcurrentModificationException} is caught and logged rather
|
||||||
* than propagated; it is caused by an unsafe {@link ArrayList} in
|
|
||||||
* {@code TCPServer.clientHandlers} (tracked as a separate issue) and does
|
|
||||||
* not leave the game in an inconsistent state.
|
|
||||||
*/
|
*/
|
||||||
public void run() {
|
public void run() {
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
eventProcessor.doFirstEvent();
|
eventProcessor.doFirstEvent();
|
||||||
} catch (ConcurrentModificationException e) {
|
|
||||||
System.err.println("Concurrent modification in notifyAll — skipping tick");
|
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
break;
|
break;
|
||||||
@@ -167,7 +162,7 @@ public class ServerLauncher {
|
|||||||
Game game = saveManager.load();
|
Game game = saveManager.load();
|
||||||
if (game == null) return;
|
if (game == null) return;
|
||||||
|
|
||||||
long disconnectedCount = game.disconnetedPlayers.entrySet().stream()
|
long disconnectedCount = game.disconnectedPlayers.entrySet().stream()
|
||||||
.filter(Map.Entry::getValue).count();
|
.filter(Map.Entry::getValue).count();
|
||||||
|
|
||||||
if (disconnectedCount >= game.getNPlayers() - 1) {
|
if (disconnectedCount >= game.getNPlayers() - 1) {
|
||||||
@@ -179,7 +174,7 @@ public class ServerLauncher {
|
|||||||
gameController.setModel(game);
|
gameController.setModel(game);
|
||||||
playerList.setLimit(game.getNPlayers());
|
playerList.setLimit(game.getNPlayers());
|
||||||
|
|
||||||
for (Map.Entry<Player, Boolean> entry : game.disconnetedPlayers.entrySet()) {
|
for (Map.Entry<Player, Boolean> entry : game.disconnectedPlayers.entrySet()) {
|
||||||
if (entry.getValue()) {
|
if (entry.getValue()) {
|
||||||
playerList.put(entry.getKey().getUserName(), false);
|
playerList.put(entry.getKey().getUserName(), false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -263,8 +263,8 @@ class GameControllerTest {
|
|||||||
|
|
||||||
assertTrue(controller.disconnectedPlayer(current.getUserName()));
|
assertTrue(controller.disconnectedPlayer(current.getUserName()));
|
||||||
|
|
||||||
assertTrue(game.disconnetedPlayers.containsKey(current));
|
assertTrue(game.disconnectedPlayers.containsKey(current));
|
||||||
assertTrue(game.disconnetedPlayers.get(current));
|
assertTrue(game.disconnectedPlayers.get(current));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -1341,8 +1341,8 @@ class GameTest {
|
|||||||
|
|
||||||
assertTrue(game.disconnectedPlayer(current));
|
assertTrue(game.disconnectedPlayer(current));
|
||||||
|
|
||||||
assertTrue(game.disconnetedPlayers.containsKey(current));
|
assertTrue(game.disconnectedPlayers.containsKey(current));
|
||||||
assertTrue(game.disconnetedPlayers.get(current));
|
assertTrue(game.disconnectedPlayers.get(current));
|
||||||
assertNotEquals(current, game.getCurrentState().getCurrentPlayer());
|
assertNotEquals(current, game.getCurrentState().getCurrentPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1367,10 +1367,10 @@ class GameTest {
|
|||||||
Player current = game.getCurrentState().getCurrentPlayer();
|
Player current = game.getCurrentState().getCurrentPlayer();
|
||||||
|
|
||||||
assertTrue(game.disconnectedPlayer(current));
|
assertTrue(game.disconnectedPlayer(current));
|
||||||
assertTrue(game.disconnetedPlayers.containsKey(current));
|
assertTrue(game.disconnectedPlayers.containsKey(current));
|
||||||
|
|
||||||
assertTrue(game.reconnectPlayer(current));
|
assertTrue(game.reconnectPlayer(current));
|
||||||
assertFalse(game.disconnetedPlayers.containsKey(current));
|
assertFalse(game.disconnectedPlayers.containsKey(current));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1382,11 +1382,11 @@ class GameTest {
|
|||||||
Player current = game.getCurrentState().getCurrentPlayer();
|
Player current = game.getCurrentState().getCurrentPlayer();
|
||||||
|
|
||||||
assertTrue(game.disconnectedPlayer(current));
|
assertTrue(game.disconnectedPlayer(current));
|
||||||
assertFalse(game.disconnetedPlayers.isEmpty());
|
assertFalse(game.disconnectedPlayers.isEmpty());
|
||||||
|
|
||||||
game.ClearDisconnected();
|
game.ClearDisconnected();
|
||||||
|
|
||||||
assertTrue(game.disconnetedPlayers.isEmpty());
|
assertTrue(game.disconnectedPlayers.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user