diff --git a/src/main/java/com/cse3310/App.java b/src/main/java/com/cse3310/App.java index 296eb5b..8a7f8f3 100644 --- a/src/main/java/com/cse3310/App.java +++ b/src/main/java/com/cse3310/App.java @@ -51,9 +51,36 @@ public void onOpen(WebSocket conn, ClientHandshake handshake) { @Override public void onClose(WebSocket conn, int code, String reason, boolean remote) { + GsonBuilder builder = new GsonBuilder(); + Gson gson = builder.create(); + int gameid = 0; + PlayerList list = new PlayerList(); for (int i = 0; i < ActiveUsers.size(); i++) { if (ActiveUsers.get(i).conn == conn) { + // Find game the user is in + for (User user : ActiveUsers) { + if (ActiveUsers.get(i).equals(user)) { + gameid = user.GameId; + } + } + + // Fill list with player data from the game (EXCEPT THE USER THAT IS ABOUT TO + // LEAVE) + for (User user : ActiveUsers) { + if (gameid == user.GameId && ActiveUsers.get(i).username != user.username) { + list.players.add(user.username); + list.playerScores.add(user.wordCount); + } + } + + // Send completed game list to all users in the specific game + for (User user : ActiveUsers) { + if (gameid == user.GameId && ActiveUsers.get(i).username != user.username) { + String jsonString = gson.toJson(list); + user.conn.send(jsonString); + } + } System.out.println("removing " + ActiveUsers.get(i).username + " from player and lobby list"); String tempName = ActiveUsers.get(i).username; @@ -70,8 +97,7 @@ public void onClose(WebSocket conn, int code, String reason, boolean remote) { break; } } - GsonBuilder builder = new GsonBuilder(); - Gson gson = builder.create(); + String jsonString = gson.toJson(LobbyUsers); broadcast(jsonString); diff --git a/target/classes/com/cse3310/App$LetterTimer.class b/target/classes/com/cse3310/App$LetterTimer.class index b2a5d01..efa5516 100644 Binary files a/target/classes/com/cse3310/App$LetterTimer.class and b/target/classes/com/cse3310/App$LetterTimer.class differ diff --git a/target/classes/com/cse3310/App.class b/target/classes/com/cse3310/App.class index f304c6f..f55ba22 100644 Binary files a/target/classes/com/cse3310/App.class and b/target/classes/com/cse3310/App.class differ diff --git a/target/cse3310-wordsearch.jar b/target/cse3310-wordsearch.jar index 766327b..da2c636 100644 Binary files a/target/cse3310-wordsearch.jar and b/target/cse3310-wordsearch.jar differ diff --git a/target/surefire-reports/TEST-com.cse3310.AppTest.xml b/target/surefire-reports/TEST-com.cse3310.AppTest.xml index 28f684d..d292892 100644 --- a/target/surefire-reports/TEST-com.cse3310.AppTest.xml +++ b/target/surefire-reports/TEST-com.cse3310.AppTest.xml @@ -1,5 +1,5 @@ - + @@ -15,7 +15,7 @@ - + @@ -31,7 +31,7 @@ - + @@ -57,5 +57,5 @@ - + \ No newline at end of file diff --git a/target/surefire-reports/com.cse3310.AppTest.txt b/target/surefire-reports/com.cse3310.AppTest.txt index 4c79d5c..27d832b 100644 --- a/target/surefire-reports/com.cse3310.AppTest.txt +++ b/target/surefire-reports/com.cse3310.AppTest.txt @@ -1,4 +1,4 @@ ------------------------------------------------------------------------------- Test set: com.cse3310.AppTest ------------------------------------------------------------------------------- -Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.075 s - in com.cse3310.AppTest +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.073 s - in com.cse3310.AppTest