Browse Source

Updated server to prompt the user when they entered an invalid steam id

pull/8/head
jrtechs 6 years ago
parent
commit
a815782f91
5 changed files with 206 additions and 40 deletions
  1. +124
    -0
      .idea/uiDesigner.xml
  2. +23
    -5
      src/main/java/net/jrtechs/www/SteamAPI/APIConnection.java
  3. +9
    -2
      src/main/java/net/jrtechs/www/graphDB/SteamGraph.java
  4. +45
    -25
      src/main/java/net/jrtechs/www/server/Client.java
  5. +5
    -8
      website/graph.html

+ 124
- 0
.idea/uiDesigner.xml View File

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

+ 23
- 5
src/main/java/net/jrtechs/www/SteamAPI/APIConnection.java View File

@ -124,12 +124,30 @@ public class APIConnection
*/
public String getPlayerName(String steamid)
{
return ((HashMap<String, String>) new JSONObject(WebScraper
// return ((HashMap<String, String>) 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)

+ 9
- 2
src/main/java/net/jrtechs/www/graphDB/SteamGraph.java View File

@ -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;
}

+ 45
- 25
src/main/java/net/jrtechs/www/server/Client.java View File

@ -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<JSONObject> 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<Player> friends = b.fetchFriends();
this.sendPlayerToClient(b, 300, 243, 1, 300);
if(b == null)
{
this.sendPlayerNotFound();
}
else
{
List<Player> 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);
}

+ 5
- 8
website/graph.html View File

@ -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;*/
/*}*/
</style>
<div id="graph-container" style="width:100%; height:100%"></div>
</div>
@ -318,6 +310,11 @@
}
}
else if(request.action == -1)
{
alert("The provided steamID was invalid.");
}
};

Loading…
Cancel
Save