Fixing Bukkit vpn processing and adding failure reasons to output

This commit is contained in:
Dawson Hessler
2021-08-20 14:11:37 -04:00
parent 68b6335ad5
commit 7533b32039
4 changed files with 41 additions and 22 deletions
@@ -46,10 +46,13 @@ public abstract class VPNExecutor {
if(response.isSuccess()) {
AntiVPN.getInstance().getDatabase().cacheResponse(response);
} else {
System.out.println("Query to VPN API failed! Reason: " + response.getFailureReason());
}
return response;
} catch (JSONException | IOException e) {
System.out.println("Query to VPN API failed! Reason: Java Exception");
e.printStackTrace();
}
}
@@ -72,10 +75,13 @@ public abstract class VPNExecutor {
if(response.isSuccess()) {
threadExecutor.execute(() -> AntiVPN.getInstance().getDatabase().cacheResponse(response));
} else {
System.out.println("Query to VPN API failed! Reason: " + response.getFailureReason());
}
return response;
} catch (JSONException | IOException e) {
System.out.println("Query to VPN API failed! Reason: Java Exception");
e.printStackTrace();
}
}
@@ -54,7 +54,7 @@ public class MySqlVPN implements VPNDatabase {
VPNResponse response = new VPNResponse(rs.getString("asn"), rs.getString("ip"),
rs.getString("countryName"), rs.getString("countryCode"),
rs.getString("city"), rs.getString("timeZone"),
rs.getString("method"), rs.getString("isp"),
rs.getString("method"), rs.getString("isp"), "N/A",
rs.getBoolean("proxy"), rs.getBoolean("cached"), true,
rs.getDouble("latitude"), rs.getDouble("longitude"),
System.currentTimeMillis(), -1);
@@ -12,7 +12,7 @@ import lombok.Setter;
@AllArgsConstructor
@RequiredArgsConstructor
public class VPNResponse {
private String asn, ip, countryName, countryCode, city, timeZone, method, isp;
private String asn, ip, countryName, countryCode, city, timeZone, method, isp, failureReason = "N/A";
private boolean proxy, cached;
private final boolean success;
private double latitude, longitude;
@@ -41,14 +41,22 @@ public class VPNResponse {
public static VPNResponse fromJson(String json) throws JSONException {
JSONObject jsonObject = new JSONObject(json);
return new VPNResponse(jsonObject.getString("asn"), jsonObject.getString("ip"),
jsonObject.getString("countryName"), jsonObject.getString("countryCode"),
jsonObject.getString("city"), jsonObject.getString("timeZone"),
jsonObject.has("method") ? jsonObject.getString("method") : "N/A",
jsonObject.getString("isp"), jsonObject.getBoolean("proxy"),
jsonObject.getBoolean("cached"), jsonObject.getBoolean("success"),
jsonObject.getDouble("latitude"), jsonObject.getDouble("longitude"),
jsonObject.getLong("lastAccess"), jsonObject.getInt("queriesLeft"));
if(jsonObject.getBoolean("success")) {
return new VPNResponse(jsonObject.getString("asn"), jsonObject.getString("ip"),
jsonObject.getString("countryName"), jsonObject.getString("countryCode"),
jsonObject.getString("city"), jsonObject.getString("timeZone"),
jsonObject.has("method") ? jsonObject.getString("method") : "N/A",
jsonObject.getString("isp"), "N/A", jsonObject.getBoolean("proxy"),
jsonObject.getBoolean("cached"), jsonObject.getBoolean("success"),
jsonObject.getDouble("latitude"), jsonObject.getDouble("longitude"),
jsonObject.getLong("lastAccess"), jsonObject.getInt("queriesLeft"));
} else {
VPNResponse response = new VPNResponse(false);
response.failureReason = jsonObject.getString("failureReason");
return response;
}
}
public static VPNResponse fromJson(JSONObject jsonObject) throws JSONException {
@@ -57,12 +65,16 @@ public class VPNResponse {
jsonObject.getString("countryName"), jsonObject.getString("countryCode"),
jsonObject.getString("city"), jsonObject.getString("timeZone"),
jsonObject.has("method") ? jsonObject.getString("method") : "N/A",
jsonObject.getString("isp"), jsonObject.getBoolean("proxy"),
jsonObject.getString("isp"), "N/A", jsonObject.getBoolean("proxy"),
jsonObject.getBoolean("cached"), jsonObject.getBoolean("success"),
jsonObject.getDouble("latitude"), jsonObject.getDouble("longitude"),
jsonObject.getLong("lastAccess"), jsonObject.getInt("queriesLeft"));
}
} else {
VPNResponse response = new VPNResponse(false);
return new VPNResponse(false);
response.failureReason = jsonObject.getString("failureReason");
return response;
}
}
}