[FEATURE] apiKey в JsonHWIDHandler и JsonAuthProvider

This commit is contained in:
Gravit 2019-01-15 09:23:27 +07:00
parent 3dd775807e
commit 302a606d22
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
3 changed files with 34 additions and 6 deletions

View file

@ -21,6 +21,7 @@ public final class JsonHWIDHandler extends HWIDHandler {
private URL urlBan;
private URL urlUnBan;
private URL urlGet;
private String apiKey;
public class banRequest {
public banRequest(OshiHWID hwid) {
@ -28,6 +29,12 @@ public banRequest(OshiHWID hwid) {
}
OshiHWID hwid;
String apiKey;
public banRequest(OshiHWID hwid, String apiKey) {
this.hwid = hwid;
this.apiKey = apiKey;
}
}
public class checkRequest {
@ -38,7 +45,13 @@ public checkRequest(String username, OshiHWID hwid) {
String username;
OshiHWID hwid;
String apiKey;
public checkRequest(String username, OshiHWID hwid, String apiKey) {
this.username = username;
this.hwid = hwid;
this.apiKey = apiKey;
}
}
public class Result {
@ -56,12 +69,18 @@ public HWIDRequest(String username) {
}
String username;
String apiKey;
public HWIDRequest(String username, String apiKey) {
this.username = username;
this.apiKey = apiKey;
}
}
@Override
public void ban(List<HWID> l_hwid) throws HWIDException {
for (HWID hwid : l_hwid) {
banRequest request = new banRequest((OshiHWID) hwid);
banRequest request = new banRequest((OshiHWID) hwid, apiKey);
try {
JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), urlBan);
Result r = gson.fromJson(result, Result.class);
@ -75,7 +94,7 @@ public void ban(List<HWID> l_hwid) throws HWIDException {
@Override
public void check0(HWID hwid, String username) throws HWIDException {
checkRequest request = new checkRequest(username, (OshiHWID) hwid);
checkRequest request = new checkRequest(username, (OshiHWID) hwid, apiKey);
try {
JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), url);
BannedResult r = gson.fromJson(result, BannedResult.class);
@ -96,7 +115,7 @@ public void close() {
@Override
public List<HWID> getHwid(String username) throws HWIDException {
ArrayList<HWID> hwids = new ArrayList<>();
HWIDRequest request = new HWIDRequest(username);
HWIDRequest request = new HWIDRequest(username, apiKey);
try {
JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), urlGet);
OshiHWID[] r = gson.fromJson(result, OshiHWID[].class);
@ -111,7 +130,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((OshiHWID) hwid);
banRequest request = new banRequest((OshiHWID) hwid, apiKey);
try {
JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), urlUnBan);
Result r = gson.fromJson(result, Result.class);

View file

@ -13,6 +13,7 @@
public final class JsonAuthProvider extends AuthProvider {
private static Gson gson = new Gson();
private URL url;
private String apiKey;
public class authResult {
String username;
@ -27,14 +28,22 @@ public authRequest(String username, String password, String ip) {
this.ip = ip;
}
public authRequest(String username, String password, String ip, String apiKey) {
this.username = username;
this.password = password;
this.ip = ip;
this.apiKey = apiKey;
}
String username;
String password;
String ip;
String apiKey;
}
@Override
public AuthProviderResult auth(String login, String password, String ip) throws IOException {
authRequest authRequest = new authRequest(login, password, ip);
authRequest authRequest = new authRequest(login, password, ip, apiKey);
JsonElement request = gson.toJsonTree(authRequest);
JsonElement content = HTTPRequest.jsonRequest(request, url);
if (!content.isJsonObject())

@ -1 +1 @@
Subproject commit b582cd6405d45d4478e62ca11045a34378c96d9d
Subproject commit ee2f9e6646a8f1972ceda68d56e88e71ab74f78f