diff --git a/Assignment 4/src/ca/cosc3p91/a4/util/network/Server.java b/Assignment 4/src/ca/cosc3p91/a4/util/network/Server.java index 87da8f5..8bc8f76 100644 --- a/Assignment 4/src/ca/cosc3p91/a4/util/network/Server.java +++ b/Assignment 4/src/ca/cosc3p91/a4/util/network/Server.java @@ -205,12 +205,20 @@ public class Server implements Runnable { break; } int pos = rand.nextInt(clients); - while (pos == clientID) + long findingClientID = clientID; + ConnectedClient foundClient = null; + int searchCount = 0; + while (findingClientID == clientID) { pos = rand.nextInt(clients); - Iterator> entries = server.clients.entrySet().iterator(); - for (int i = 0; i < pos; i++) - entries.next(); - exploringMap = entries.next().getValue().clientMap; + Iterator> entries = server.clients.entrySet().iterator(); + for (int i = 0; i < pos; i++) + entries.next(); + foundClient = entries.next().getValue(); + findingClientID = foundClient.clientID; + if(searchCount++ > 50) + break; + } + exploringMap = foundClient.clientMap; sendMapData(usingEngine.view.getVillageStateTable(exploringMap, "Other Village")); break; case PacketTable.GENERATE: