From a815782f91f8bd422da295f01aa75a8522a54a6f Mon Sep 17 00:00:00 2001 From: jrtechs Date: Sun, 10 Jun 2018 17:04:40 -0400 Subject: [PATCH] Updated server to prompt the user when they entered an invalid steam id --- .idea/uiDesigner.xml | 124 ++++++++++++++++++ .../jrtechs/www/SteamAPI/APIConnection.java | 28 +++- .../net/jrtechs/www/graphDB/SteamGraph.java | 11 +- .../java/net/jrtechs/www/server/Client.java | 70 ++++++---- website/graph.html | 13 +- 5 files changed, 206 insertions(+), 40 deletions(-) create mode 100644 .idea/uiDesigner.xml diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/net/jrtechs/www/SteamAPI/APIConnection.java b/src/main/java/net/jrtechs/www/SteamAPI/APIConnection.java index 2af5122..6e802df 100644 --- a/src/main/java/net/jrtechs/www/SteamAPI/APIConnection.java +++ b/src/main/java/net/jrtechs/www/SteamAPI/APIConnection.java @@ -124,12 +124,30 @@ public class APIConnection */ public String getPlayerName(String steamid) { - return ((HashMap) new JSONObject(WebScraper +// return ((HashMap) new JSONObject(WebScraper +// .getWebsite(this.baseURL + this.playerInfoURL + +// this.apiKey + "&steamids=" + steamid)) +// .getJSONObject("response") +// .getJSONArray("players") +// .toList().stream().findAny().get()).get("personaname"); + + JSONObject response = new JSONObject(WebScraper .getWebsite(this.baseURL + this.playerInfoURL + - this.apiKey + "&steamids=" + steamid)) - .getJSONObject("response") - .getJSONArray("players") - .toList().stream().findAny().get()).get("personaname"); + this.apiKey + "&steamids=" + steamid)); + + if(response.has("response")) + { + response = response.getJSONObject("response"); + if(response.has("players")) + { + JSONArray arr = response.getJSONArray("players"); + if(arr.length() > 0) + { + return arr.getJSONObject(0).getString("personname"); + } + } + } + return null; } public static void main(String[] args) diff --git a/src/main/java/net/jrtechs/www/graphDB/SteamGraph.java b/src/main/java/net/jrtechs/www/graphDB/SteamGraph.java index 3be51cf..13b8285 100644 --- a/src/main/java/net/jrtechs/www/graphDB/SteamGraph.java +++ b/src/main/java/net/jrtechs/www/graphDB/SteamGraph.java @@ -279,8 +279,15 @@ public class SteamGraph { System.out.println("brand spanking new request " + id); String name = this.api.getPlayerName(id); - this.insertPlayerIntoGraph(id, name); - return this.getPlayer(id); + if(name == null) + { + return null; + } + else + { + this.insertPlayerIntoGraph(id, name); + return this.getPlayer(id); + } } return p; } diff --git a/src/main/java/net/jrtechs/www/server/Client.java b/src/main/java/net/jrtechs/www/server/Client.java index 1bd52c0..4fea5cc 100644 --- a/src/main/java/net/jrtechs/www/server/Client.java +++ b/src/main/java/net/jrtechs/www/server/Client.java @@ -26,9 +26,6 @@ public class Client extends Thread /** base id to look at */ private String baseId; - /** How many layers of friends we are traversing */ - private int debth; - /** JSONObjects to send the client */ private List queue; @@ -47,7 +44,6 @@ public class Client extends Thread this.graph = new SteamGraph(); this.type = type; this.baseId = id; - this.debth = 1; this.queue = new ArrayList<>(); } @@ -184,7 +180,6 @@ public class Client extends Thread (multiplier/gen)), 30); } - this.sendEdgeAdd(p, friend); currentStep += radianStep; @@ -199,23 +194,30 @@ public class Client extends Thread { Player b = this.graph.getPlayer(this.baseId); - List friends = b.fetchFriends(); - this.sendPlayerToClient(b, 300, 243, 1, 300); + if(b == null) + { + this.sendPlayerNotFound(); + } + else + { + List friends = b.fetchFriends(); + this.sendPlayerToClient(b, 300, 243, 1, 300); - double radianStep = Math.PI * 2 / friends.size(); + double radianStep = Math.PI * 2 / friends.size(); - double currentStep = 0; + double currentStep = 0; - for(Player f : b.fetchFriends()) - { - f = this.graph.getPlayer(f.getId()); - this.sendPlayerToClient(f, (int)(300 + Math.cos(currentStep) * 300), - (int)(243 + Math.sin(currentStep) * 300) ,2, 300); + for(Player f : b.fetchFriends()) + { + f = this.graph.getPlayer(f.getId()); + this.sendPlayerToClient(f, (int)(300 + Math.cos(currentStep) * 300), + (int)(243 + Math.sin(currentStep) * 300) ,2, 300); - currentStep += radianStep; + currentStep += radianStep; + } + this.sendFinished(); } - this.sendFinished(); } @@ -229,23 +231,41 @@ public class Client extends Thread { Player b = this.graph.getPlayer(this.baseId); - this.sendPlayerToClient(b, 600, 440, 1, 600); - - for(Player f : b.fetchFriends()) //all my friends + if(b == null) { - f = this.graph.getPlayer(f.getId()); - for(Player ff : f.fetchFriends()) // all my friends friends + this.sendPlayerNotFound(); + } + else + { + this.sendPlayerToClient(b, 600, 440, 1, 600); + + for(Player f : b.fetchFriends()) //all my friends { - for(Player f2 : b.fetchFriends()) // all my friends + f = this.graph.getPlayer(f.getId()); + for(Player ff : f.fetchFriends()) // all my friends friends { - if(f2.getId().equals(ff.getId())) + for(Player f2 : b.fetchFriends()) // all my friends { - this.sendEdgeAdd(f, ff); + if(f2.getId().equals(ff.getId())) + { + this.sendEdgeAdd(f, ff); + } } } } + this.sendFinished(); } - this.sendFinished(); + } + + + /** + * Tells the client that the steam id provided was invalid + */ + private void sendPlayerNotFound() + { + JSONObject request = new JSONObject(); + request.put("action", -1); + this.sendJSON(request); } diff --git a/website/graph.html b/website/graph.html index dc12875..b9b9c82 100644 --- a/website/graph.html +++ b/website/graph.html @@ -134,14 +134,6 @@ fill-opacity: 0.1; stroke-opacity: 0.1; } - /*.sigma-node:hover {*/ - /*fill: blue;*/ - /*}*/ - /*.muted {*/ - /*fill-opacity: 0.1;*/ - /*stroke-opacity: 0.1;*/ - /*font-size: 0;*/ - /*}*/
@@ -318,6 +310,11 @@ } } + else if(request.action == -1) + { + alert("The provided steamID was invalid."); + + } };