Фикс JsonHWIDHandler

This commit is contained in:
Gravit 2018-12-30 01:58:58 +07:00
parent 49c53d4b35
commit 726bcff1b4
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
2 changed files with 13 additions and 18 deletions

View file

@ -3,6 +3,7 @@
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import com.google.gson.Gson; import com.google.gson.Gson;
@ -24,21 +25,21 @@ public final class JsonHWIDHandler extends HWIDHandler {
private URL urlGet; private URL urlGet;
public class banRequest { public class banRequest {
public banRequest(String hwid) { public banRequest(OshiHWID hwid) {
this.hwid = hwid; this.hwid = hwid;
} }
String hwid; OshiHWID hwid;
} }
public class checkRequest { public class checkRequest {
public checkRequest(String username, String hwid) { public checkRequest(String username, OshiHWID hwid) {
this.username = username; this.username = username;
this.hwid = hwid; this.hwid = hwid;
} }
String username; String username;
String hwid; OshiHWID hwid;
} }
@ -51,10 +52,6 @@ public class BannedResult {
String error; String error;
} }
public class HWIDResult {
String string;
}
public class HWIDRequest { public class HWIDRequest {
public HWIDRequest(String username) { public HWIDRequest(String username) {
this.username = username; this.username = username;
@ -66,7 +63,7 @@ public HWIDRequest(String username) {
@Override @Override
public void ban(List<HWID> l_hwid) throws HWIDException { public void ban(List<HWID> l_hwid) throws HWIDException {
for (HWID hwid : l_hwid) { for (HWID hwid : l_hwid) {
banRequest request = new banRequest(hwid.getSerializeString()); banRequest request = new banRequest((OshiHWID) hwid);
try { try {
JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), urlBan); JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), urlBan);
Result r = gson.fromJson(result, Result.class); Result r = gson.fromJson(result, Result.class);
@ -80,9 +77,9 @@ public void ban(List<HWID> l_hwid) throws HWIDException {
@Override @Override
public void check0(HWID hwid, String username) throws HWIDException { public void check0(HWID hwid, String username) throws HWIDException {
checkRequest request = new checkRequest(username, hwid.getSerializeString()); checkRequest request = new checkRequest(username, (OshiHWID) hwid);
try { try {
JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), urlBan); JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), url);
BannedResult r = gson.fromJson(result, BannedResult.class); BannedResult r = gson.fromJson(result, BannedResult.class);
if (r.error != null) throw new HWIDException(r.error); if (r.error != null) throw new HWIDException(r.error);
boolean isBanned = r.isBanned; boolean isBanned = r.isBanned;
@ -103,11 +100,9 @@ public List<HWID> getHwid(String username) throws HWIDException {
ArrayList<HWID> hwids = new ArrayList<>(); ArrayList<HWID> hwids = new ArrayList<>();
HWIDRequest request = new HWIDRequest(username); HWIDRequest request = new HWIDRequest(username);
try { try {
JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), urlBan); JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), urlGet);
HWIDResult[] r = gson.fromJson(result, HWIDResult[].class); OshiHWID[] r = gson.fromJson(result, OshiHWID[].class);
for (HWIDResult hw : r) { hwids.addAll(Arrays.asList(r));
hwids.add(OshiHWID.gson.fromJson(hw.string, OshiHWID.class));
}
} catch (IOException e) { } catch (IOException e) {
LogHelper.error(e); LogHelper.error(e);
throw new HWIDException("HWID service error"); throw new HWIDException("HWID service error");
@ -118,7 +113,7 @@ public List<HWID> getHwid(String username) throws HWIDException {
@Override @Override
public void unban(List<HWID> l_hwid) throws HWIDException { public void unban(List<HWID> l_hwid) throws HWIDException {
for (HWID hwid : l_hwid) { for (HWID hwid : l_hwid) {
banRequest request = new banRequest(hwid.getSerializeString()); banRequest request = new banRequest((OshiHWID) hwid);
try { try {
JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), urlUnBan); JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), urlUnBan);
Result r = gson.fromJson(result, Result.class); Result r = gson.fromJson(result, Result.class);

View file

@ -14,7 +14,7 @@
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
public class HTTPRequest { public class HTTPRequest {
private static final int TIMEOUT = 10; private static final int TIMEOUT = 10000;
private static final JsonParser parser = new JsonParser(); private static final JsonParser parser = new JsonParser();
public static int sendCrashreport(String strurl, byte[] data) throws IOException { public static int sendCrashreport(String strurl, byte[] data) throws IOException {