review fixes

This commit is contained in:
Clercq 2022-07-26 00:07:41 +03:00
parent abddfeb69e
commit dc4d3e422b

View file

@ -3,6 +3,7 @@
import io.netty.util.internal.StringUtil; import io.netty.util.internal.StringUtil;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.Contract;
import pro.gravit.launcher.ClientPermissions; import pro.gravit.launcher.ClientPermissions;
import pro.gravit.launcher.events.request.AuthRequestEvent; import pro.gravit.launcher.events.request.AuthRequestEvent;
import pro.gravit.launcher.events.request.GetAvailabilityAuthRequestEvent; import pro.gravit.launcher.events.request.GetAvailabilityAuthRequestEvent;
@ -166,8 +167,9 @@ public UserHardware getHardwareInfoByData(HardwareReportRequest.HardwareInfo inf
return null; return null;
} }
try { try {
HttpHelper.HttpOptional<HttpUserHardware, HttpRequester.SimpleError> hardware = requester.send(requester.post(getHardwareInfoByDataUrl, new HardwareRequest(new HttpUserHardware(info)), HttpHelper.HttpOptional<HttpUserHardware, HttpRequester.SimpleError> hardware =
bearerToken), HttpUserHardware.class); requester.send(requester.post(getHardwareInfoByDataUrl, new HardwareRequest(new HttpUserHardware(info)),
bearerToken), HttpUserHardware.class);
//should return null if not found //should return null if not found
return hardware.isSuccessful() ? hardware.getOrThrow() : null; return hardware.isSuccessful() ? hardware.getOrThrow() : null;
} catch (IOException e) { } catch (IOException e) {
@ -196,8 +198,8 @@ public UserHardware createHardwareInfo(HardwareReportRequest.HardwareInfo info,
return null; return null;
} }
try { try {
return requester.send(requester.post(createHardwareInfoUrl, new HardwareRequest(new HttpUserHardware(info, publicKey, false)), return requester.send(requester.post(createHardwareInfoUrl, new HardwareRequest(new HttpUserHardware(info,
bearerToken), HttpUserHardware.class).getOrThrow(); publicKey, false)), bearerToken), HttpUserHardware.class).getOrThrow();
} catch (IOException e) { } catch (IOException e) {
logger.error(e); logger.error(e);
return null; return null;
@ -210,7 +212,7 @@ public void connectUserAndHardware(UserSession userSession, UserHardware hardwar
return; return;
} }
try { try {
requester.send(requester.post(connectUserAndHardwareUrl, new HardwareRequest(userSession, hardware), bearerToken), Void.class); requester.send(requester.post(connectUserAndHardwareUrl, new HardwareRequest(hardware, userSession), bearerToken), Void.class);
} catch (IOException e) { } catch (IOException e) {
logger.error(e); logger.error(e);
} }
@ -234,8 +236,8 @@ public Iterable<User> getUsersByHardwareInfo(UserHardware hardware) {
return null; return null;
} }
try { try {
return requester.send(requester.post(getUsersByHardwareInfoUrl, new HardwareRequest(hardware), return requester.send(requester
bearerToken), List.class).getOrThrow(); .post(getUsersByHardwareInfoUrl, new HardwareRequest(hardware), bearerToken), List.class).getOrThrow();
} catch (IOException e) { } catch (IOException e) {
logger.error(e); logger.error(e);
return null; return null;
@ -379,28 +381,24 @@ public RefreshTokenRequest(String refreshToken, AuthResponse.AuthContext context
} }
} }
public static class HardwareRequest { public record HardwareRequest(UserHardware userHardware, byte[] key, UserSession userSession) {
public UserHardware userHardware;
public byte[] key;
public UserSession userSession;
public HardwareRequest(UserHardware userHardware) { public HardwareRequest(UserHardware userHardware) {
this.userHardware = userHardware; this(userHardware, null, null);
} }
public HardwareRequest(UserHardware userHardware, byte[] key) { public HardwareRequest(UserHardware userHardware, byte[] key) {
this.userHardware = userHardware; this(userHardware, key, null);
this.key = key;
} }
public HardwareRequest(UserSession session, UserHardware hardware) { public HardwareRequest(UserHardware userHardware, UserSession userSession) {
this.userSession = session; this(userHardware, null, userSession);
this.userHardware = hardware;
} }
public HardwareRequest(byte[] key) { public HardwareRequest(byte[] key) {
this.key = key; this(null, key, null);
} }
} }
public class HttpUser implements User, UserSupportTextures, UserSupportProperties, UserSupportHardware { public class HttpUser implements User, UserSupportTextures, UserSupportProperties, UserSupportHardware {