diff --git a/src/main/java/net/jrtechs/www/graphDB/SteamGraph.java b/src/main/java/net/jrtechs/www/graphDB/SteamGraph.java index 1da5d23..3be51cf 100644 --- a/src/main/java/net/jrtechs/www/graphDB/SteamGraph.java +++ b/src/main/java/net/jrtechs/www/graphDB/SteamGraph.java @@ -205,15 +205,20 @@ public class SteamGraph String query = "g.V().hasLabel('player')" + ".has('id', '" + id + "')" + ".both().valueMap()"; - - this.con.queryGraph(query).stream().forEach(r-> - friends.add(new Player( - ((ArrayList) (((HashMap)(r.getObject())) - .get("name"))).get(0).toString(), - ((ArrayList)(((HashMap)(r.getObject())) - .get("id"))).get(0).toString())) - ); - + try + { + this.con.queryGraph(query).stream().forEach(r -> + friends.add(new Player( + ((ArrayList) (((HashMap) (r.getObject())) + .get("name"))).get(0).toString(), + ((ArrayList) (((HashMap) (r.getObject())) + .get("id"))).get(0).toString())) + ); + } + catch(Exception e) + { + e.printStackTrace(); + } return friends; } diff --git a/src/main/java/net/jrtechs/www/server/Client.java b/src/main/java/net/jrtechs/www/server/Client.java index fb13e33..8e09553 100644 --- a/src/main/java/net/jrtechs/www/server/Client.java +++ b/src/main/java/net/jrtechs/www/server/Client.java @@ -98,6 +98,11 @@ public class Client extends Thread } + /** + * sends a json object to the client + * + * @param request + */ private void sendJSON(JSONObject request) { this.client.send(request.toString()); @@ -117,7 +122,7 @@ public class Client extends Thread * * @param p */ - private void sendPlayerToClient(Player p, int x, int y, int gen) + private void sendPlayerToClient(Player p, int x, int y, int gen, int multiplier) { if(gen == 1) { @@ -132,7 +137,8 @@ public class Client extends Thread for(Player friend: friends) { - this.sendNodeAdd(friend, (int)(x + Math.cos(currentStep) * (300/gen)), (int)(y + Math.sin(currentStep) * (300/gen))); + this.sendNodeAdd(friend, (int)(x + Math.cos(currentStep) * + (multiplier/gen)), (int)(y + Math.sin(currentStep) * (multiplier/gen))); this.sendEdgeAdd(p, friend); @@ -142,15 +148,14 @@ public class Client extends Thread /** - * Where the magic happens + * Generates a friends of friends graph for the client */ - @Override - public void run() + private void friendsOfFriends() { Player b = this.graph.getPlayer(this.baseId); List friends = b.fetchFriends(); - this.sendPlayerToClient(b, 300, 243, 1); + this.sendPlayerToClient(b, 300, 243, 1, 300); double radianStep = Math.PI * 2 / friends.size(); @@ -160,11 +165,57 @@ public class Client extends Thread 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); + this.sendPlayerToClient(f, (int)(300 + Math.cos(currentStep) * 300), (int)(243 + Math.sin(currentStep) * 300) ,2, 300); currentStep += radianStep; } + this.client.close(); + } + + + /** + * Generates the friends with friends graph for the client + * + * Displays all of the requested ids friends, then it only adds edges + * between players if they are both friends of yours. + */ + private void friendsWithFriends() + { + Player b = this.graph.getPlayer(this.baseId); + + this.sendPlayerToClient(b, 600, 440, 1, 600); + for(Player f : b.fetchFriends()) //all my friends + { + f = this.graph.getPlayer(f.getId()); + for(Player ff : f.fetchFriends()) // all my friends friends + { + for(Player f2 : b.fetchFriends()) // all my friends + { + if(f2.getId().equals(ff.getId())) + { + this.sendEdgeAdd(f, ff); + } + } + } + } this.client.close(); } + + + /** + * Where the magic happens + */ + @Override + public void run() + { + if(this.type == 1) + { + friendsOfFriends(); + } + else + { + friendsWithFriends(); + } + } } \ No newline at end of file