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

View file

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