[FIX] Унификация Results

This commit is contained in:
Gravit 2019-02-10 15:38:48 +07:00
parent 5b22989e57
commit 746fdc36e4
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
19 changed files with 75 additions and 62 deletions

View file

@ -215,7 +215,7 @@ function doAuth(login, rsaPassword) {
overlay.show(processing.overlay, function (event) {
FunctionalBridge.getHWID.join();
makeAuthRequest(login, rsaPassword, function (result) {
loginData = { pp: result.pp , accessToken: result.accessToken, permissions: result.permissions};
loginData = { pp: result.playerProfile , accessToken: result.accessToken, permissions: result.permissions};
overlay.hide(0, function () {
setCurrentScene(menuScene);

View file

@ -19,26 +19,26 @@ public final class CompatBridge {
public static CompatProfile checkServer(String username, String serverID) throws Exception {
LogHelper.debug("CompatBridge.checkServer, Username: '%s', Server ID: %s", username, serverID);
return CompatProfile.fromPlayerProfile(new CheckServerRequest(username, serverID).request());
return CompatProfile.fromPlayerProfile(new CheckServerRequest(username, serverID).request().playerProfile);
}
public static boolean joinServer(String username, String accessToken, String serverID) throws Exception {
// Join server
LogHelper.debug("LegacyBridge.joinServer, Username: '%s', Access token: %s, Server ID: %s", username, accessToken, serverID);
return new JoinServerRequest(username, accessToken, serverID).request();
return new JoinServerRequest(username, accessToken, serverID).request().allow;
}
public static CompatProfile profileByUsername(String username) throws Exception {
return CompatProfile.fromPlayerProfile(new ProfileByUsernameRequest(username).request());
return CompatProfile.fromPlayerProfile(new ProfileByUsernameRequest(username).request().playerProfile);
}
public static CompatProfile profileByUUID(UUID uuid) throws Exception {
return CompatProfile.fromPlayerProfile(new ProfileByUUIDRequest(uuid).request());
return CompatProfile.fromPlayerProfile(new ProfileByUUIDRequest(uuid).request().playerProfile);
}
public static CompatProfile[] profilesByUsername(String... usernames) throws Exception {
PlayerProfile[] profiles = new BatchProfileByUsernameRequest(usernames).request();
PlayerProfile[] profiles = new BatchProfileByUsernameRequest(usernames).request().playerProfiles;
// Convert profiles
CompatProfile[] resultProfiles = new CompatProfile[profiles.length];

View file

@ -32,7 +32,7 @@ public static String joinServer(String username, String accessToken, String serv
// Join server
LogHelper.debug("LegacyBridge.joinServer, Username: '%s', Access token: %s, Server ID: %s", username, accessToken, serverID);
try {
return new JoinServerRequest(username, accessToken, serverID).request() ? "OK" : "Bad Login (Clientside)";
return new JoinServerRequest(username, accessToken, serverID).request().allow ? "OK" : "Bad Login (Clientside)";
} catch (Exception e) {
return e.toString();
}

View file

@ -43,7 +43,7 @@ public void findProfilesByNames(String[] usernames, Agent agent, ProfileLookupCa
// Batch Username-To-UUID request
PlayerProfile[] sliceProfiles;
try {
sliceProfiles = new BatchProfileByUsernameRequest(sliceUsernames).request();
sliceProfiles = new BatchProfileByUsernameRequest(sliceUsernames).request().playerProfiles;
} catch (Exception e) {
for (String username : sliceUsernames) {
LogHelper.debug("Couldn't find profile '%s': %s", username, e);

View file

@ -98,7 +98,7 @@ public GameProfile fillProfileProperties(GameProfile profile, boolean requireSec
// Make profile request
PlayerProfile pp;
try {
pp = new ProfileByUUIDRequest(uuid).request();
pp = new ProfileByUUIDRequest(uuid).request().playerProfile;
} catch (Exception e) {
LogHelper.debug("Couldn't fetch profile properties for '%s': %s", profile, e);
return profile;
@ -155,7 +155,7 @@ public GameProfile hasJoinedServer(GameProfile profile, String serverID) throws
// Make checkServer request
PlayerProfile pp;
try {
pp = new CheckServerRequest(username, serverID).request();
pp = new CheckServerRequest(username, serverID).request().playerProfile;
} catch (Exception e) {
LogHelper.error(e);
throw new AuthenticationUnavailableException(e);
@ -184,7 +184,7 @@ public void joinServer(GameProfile profile, String accessToken, String serverID)
// Make joinServer request
boolean success;
try {
success = new JoinServerRequest(username, accessToken, serverID).request();
success = new JoinServerRequest(username, accessToken, serverID).request().allow;
} catch (Exception e) {
throw new AuthenticationUnavailableException(e);
}

View file

@ -1,10 +1,10 @@
package ru.gravit.launcher.request.auth;
import ru.gravit.launcher.*;
import ru.gravit.launcher.events.request.AuthRequestEvent;
import ru.gravit.launcher.profiles.PlayerProfile;
import ru.gravit.launcher.request.Request;
import ru.gravit.launcher.request.RequestType;
import ru.gravit.launcher.request.auth.AuthRequest.Result;
import ru.gravit.launcher.serialize.HInput;
import ru.gravit.launcher.serialize.HOutput;
import ru.gravit.launcher.serialize.SerializeLimits;
@ -13,21 +13,7 @@
import java.io.IOException;
public final class AuthRequest extends Request<Result> {
public static final class Result {
@LauncherAPI
public final PlayerProfile pp;
@LauncherAPI
public final String accessToken;
@LauncherAPI
public final ClientPermissions permissions;
private Result(PlayerProfile pp, String accessToken, ClientPermissions permissions) {
this.pp = pp;
this.accessToken = accessToken;
this.permissions = permissions;
}
}
public final class AuthRequest extends Request<AuthRequestEvent> {
private final String login;
@ -102,7 +88,7 @@ public String getType() {
}
}*/
@Override
protected Result requestDo(HInput input, HOutput output) throws IOException {
protected AuthRequestEvent requestDo(HInput input, HOutput output) throws IOException {
/*try {
LegacyRequestBridge.sendRequest(new EchoRequest("Hello World!"));
} catch (InterruptedException e) {
@ -126,6 +112,6 @@ protected Result requestDo(HInput input, HOutput output) throws IOException {
PlayerProfile pp = new PlayerProfile(input);
String accessToken = input.readASCII(-SecurityHelper.TOKEN_STRING_LENGTH);
ClientPermissions permissions = new ClientPermissions(input);
return new Result(pp, accessToken, permissions);
return new AuthRequestEvent(pp, accessToken, permissions);
}
}

View file

@ -3,6 +3,7 @@
import ru.gravit.launcher.Launcher;
import ru.gravit.launcher.LauncherAPI;
import ru.gravit.launcher.LauncherConfig;
import ru.gravit.launcher.events.request.CheckServerEvent;
import ru.gravit.launcher.profiles.PlayerProfile;
import ru.gravit.launcher.request.Request;
import ru.gravit.launcher.request.RequestType;
@ -14,7 +15,7 @@
import java.io.IOException;
public final class CheckServerRequest extends Request<PlayerProfile> {
public final class CheckServerRequest extends Request<CheckServerEvent> {
private final String username;
private final String serverID;
@ -36,7 +37,7 @@ public Integer getType() {
}
@Override
protected PlayerProfile requestDo(HInput input, HOutput output) throws IOException {
protected CheckServerEvent requestDo(HInput input, HOutput output) throws IOException {
output.writeString(username, SerializeLimits.MAX_LOGIN);
output.writeASCII(serverID, SerializeLimits.MAX_SERVERID); // 1 char for minus sign
if (Launcher.profile == null) {
@ -48,6 +49,6 @@ protected PlayerProfile requestDo(HInput input, HOutput output) throws IOExcepti
// Read response
readError(input);
return input.readBoolean() ? new PlayerProfile(input) : null;
return input.readBoolean() ? new CheckServerEvent(new PlayerProfile(input)) : null;
}
}

View file

@ -2,6 +2,7 @@
import ru.gravit.launcher.LauncherAPI;
import ru.gravit.launcher.LauncherConfig;
import ru.gravit.launcher.events.request.JoinServerRequestEvent;
import ru.gravit.launcher.request.Request;
import ru.gravit.launcher.request.RequestType;
import ru.gravit.launcher.serialize.HInput;
@ -12,7 +13,7 @@
import java.io.IOException;
public final class JoinServerRequest extends Request<Boolean> {
public final class JoinServerRequest extends Request<JoinServerRequestEvent> {
// Instance
private final String username;
@ -38,7 +39,7 @@ public Integer getType() {
}
@Override
protected Boolean requestDo(HInput input, HOutput output) throws IOException {
protected JoinServerRequestEvent requestDo(HInput input, HOutput output) throws IOException {
output.writeString(username, SerializeLimits.MAX_LOGIN);
output.writeASCII(accessToken, -SecurityHelper.TOKEN_STRING_LENGTH);
output.writeASCII(serverID, SerializeLimits.MAX_SERVERID); // 1 char for minus sign
@ -46,7 +47,7 @@ protected Boolean requestDo(HInput input, HOutput output) throws IOException {
// Read response
readError(input);
return input.readBoolean();
return new JoinServerRequestEvent(input.readBoolean());
}
}

View file

@ -3,6 +3,7 @@
import ru.gravit.launcher.Launcher;
import ru.gravit.launcher.LauncherAPI;
import ru.gravit.launcher.LauncherConfig;
import ru.gravit.launcher.events.request.ProfilesRequestEvent;
import ru.gravit.launcher.profiles.ClientProfile;
import ru.gravit.launcher.request.Request;
import ru.gravit.launcher.request.RequestType;
@ -13,16 +14,7 @@
import java.util.Collections;
import java.util.List;
public final class ProfilesRequest extends Request<ProfilesRequest.Result> {
public static final class Result {
@LauncherAPI
public final List<ClientProfile> profiles;
private Result(List<ClientProfile> profiles) {
this.profiles = Collections.unmodifiableList(profiles);
}
}
public final class ProfilesRequest extends Request<ProfilesRequestEvent> {
@LauncherAPI
public ProfilesRequest() {
@ -40,7 +32,7 @@ public Integer getType() {
}
@Override
protected Result requestDo(HInput input, HOutput output) throws Exception {
protected ProfilesRequestEvent requestDo(HInput input, HOutput output) throws Exception {
output.writeBoolean(true);
output.flush();
readError(input);
@ -52,6 +44,6 @@ protected Result requestDo(HInput input, HOutput output) throws Exception {
profiles.add(Launcher.gson.fromJson(prof, ClientProfile.class));
}
// Return request result
return new Result(profiles);
return new ProfilesRequestEvent(profiles);
}
}

View file

@ -2,6 +2,7 @@
import ru.gravit.launcher.LauncherAPI;
import ru.gravit.launcher.LauncherConfig;
import ru.gravit.launcher.events.request.BatchProfileByUsernameRequestEvent;
import ru.gravit.launcher.profiles.PlayerProfile;
import ru.gravit.launcher.request.Request;
import ru.gravit.launcher.request.RequestType;
@ -13,7 +14,7 @@
import java.io.IOException;
public final class BatchProfileByUsernameRequest extends Request<PlayerProfile[]> {
public final class BatchProfileByUsernameRequest extends Request<BatchProfileByUsernameRequestEvent> {
private final String[] usernames;
@LauncherAPI
@ -36,7 +37,7 @@ public Integer getType() {
}
@Override
protected PlayerProfile[] requestDo(HInput input, HOutput output) throws IOException {
protected BatchProfileByUsernameRequestEvent requestDo(HInput input, HOutput output) throws IOException {
output.writeLength(usernames.length, SerializeLimits.MAX_BATCH_SIZE);
for (String username : usernames) {
output.writeString(username, SerializeLimits.MAX_LOGIN);
@ -50,6 +51,6 @@ protected PlayerProfile[] requestDo(HInput input, HOutput output) throws IOExcep
profiles[i] = input.readBoolean() ? new PlayerProfile(input) : null;
// Return result
return profiles;
return new BatchProfileByUsernameRequestEvent(profiles);
}
}

View file

@ -3,6 +3,7 @@
import ru.gravit.launcher.Launcher;
import ru.gravit.launcher.LauncherAPI;
import ru.gravit.launcher.LauncherConfig;
import ru.gravit.launcher.events.request.ProfileByUUIDRequestEvent;
import ru.gravit.launcher.profiles.PlayerProfile;
import ru.gravit.launcher.request.Request;
import ru.gravit.launcher.request.RequestType;
@ -14,7 +15,7 @@
import java.util.Objects;
import java.util.UUID;
public final class ProfileByUUIDRequest extends Request<PlayerProfile> {
public final class ProfileByUUIDRequest extends Request<ProfileByUUIDRequestEvent> {
private final UUID uuid;
@LauncherAPI
@ -34,12 +35,12 @@ public Integer getType() {
}
@Override
protected PlayerProfile requestDo(HInput input, HOutput output) throws IOException {
protected ProfileByUUIDRequestEvent requestDo(HInput input, HOutput output) throws IOException {
output.writeUUID(uuid);
output.writeString(Launcher.profile.getTitle(), SerializeLimits.MAX_CLIENT);
output.flush();
// Return profile
return input.readBoolean() ? new PlayerProfile(input) : null;
return input.readBoolean() ? new ProfileByUUIDRequestEvent(new PlayerProfile(input)) : null;
}
}

View file

@ -3,6 +3,7 @@
import ru.gravit.launcher.Launcher;
import ru.gravit.launcher.LauncherAPI;
import ru.gravit.launcher.LauncherConfig;
import ru.gravit.launcher.events.request.ProfileByUsernameRequestEvent;
import ru.gravit.launcher.profiles.PlayerProfile;
import ru.gravit.launcher.request.Request;
import ru.gravit.launcher.request.RequestType;
@ -13,7 +14,7 @@
import java.io.IOException;
public final class ProfileByUsernameRequest extends Request<PlayerProfile> {
public final class ProfileByUsernameRequest extends Request<ProfileByUsernameRequestEvent> {
private final String username;
@LauncherAPI
@ -33,11 +34,11 @@ public Integer getType() {
}
@Override
protected PlayerProfile requestDo(HInput input, HOutput output) throws IOException {
protected ProfileByUsernameRequestEvent requestDo(HInput input, HOutput output) throws IOException {
output.writeString(username, SerializeLimits.MAX_LOGIN);
output.writeString(Launcher.profile.getTitle(), SerializeLimits.MAX_CLIENT);
output.flush();
// Return profile
return input.readBoolean() ? new PlayerProfile(input) : null;
return input.readBoolean() ? new ProfileByUsernameRequestEvent(new PlayerProfile(input)) : null;
}
}

View file

@ -5,6 +5,7 @@
import ru.gravit.launcher.ClientPermissions;
import ru.gravit.launcher.Launcher;
import ru.gravit.launcher.LauncherConfig;
import ru.gravit.launcher.events.request.ProfilesRequestEvent;
import ru.gravit.launcher.profiles.ClientProfile;
import ru.gravit.launcher.request.auth.AuthServerRequest;
import ru.gravit.launcher.request.update.ProfilesRequest;
@ -43,7 +44,7 @@ public static boolean auth(ServerWrapper wrapper) {
try {
LauncherConfig cfg = Launcher.getConfig();
ServerWrapper.permissions = new AuthServerRequest(cfg, config.login, SecurityHelper.newRSAEncryptCipher(cfg.publicKey).doFinal(IOHelper.encode(config.password)), 0, config.title).request();
ProfilesRequest.Result result = new ProfilesRequest(cfg).request();
ProfilesRequestEvent result = new ProfilesRequest(cfg).request();
for (ClientProfile p : result.profiles) {
LogHelper.debug("Get profile: %s", p.getTitle());
if (p.getTitle().equals(config.title)) {

View file

@ -17,6 +17,12 @@ public AuthRequestEvent() {
public PlayerProfile playerProfile;
public String accessToken;
public AuthRequestEvent(PlayerProfile pp, String accessToken, ClientPermissions permissions) {
this.playerProfile = pp;
this.accessToken = accessToken;
this.permissions = permissions;
}
@Override
public UUID getUUID() {
return uuid;

View file

@ -11,6 +11,14 @@ public class BatchProfileByUsernameRequestEvent implements EventInterface, Resul
private static final UUID uuid = UUID.fromString("c1d6729e-be2c-48cc-b5ae-af8c012232c3");
public String error;
public PlayerProfile[] playerProfiles;
public BatchProfileByUsernameRequestEvent(PlayerProfile[] profiles) {
this.playerProfiles = profiles;
}
public BatchProfileByUsernameRequestEvent() {
}
@Override
public UUID getUUID() {
return uuid;

View file

@ -11,6 +11,14 @@ public class CheckServerEvent implements EventInterface, ResultInterface {
public String type = "success";
public UUID uuid;
public PlayerProfile playerProfile;
public CheckServerEvent(PlayerProfile playerProfile) {
this.playerProfile = playerProfile;
}
public CheckServerEvent() {
}
@Override
public UUID getUUID() {
return _uuid;

View file

@ -9,12 +9,16 @@
public class ProfileByUUIDRequestEvent implements EventInterface, ResultInterface
{
private static final UUID uuid = UUID.fromString("b9014cf3-4b95-4d38-8c5f-867f190a18a0");
String error;
PlayerProfile playerProfile;
public String error;
public PlayerProfile playerProfile;
public ProfileByUUIDRequestEvent(PlayerProfile playerProfile) {
this.playerProfile = playerProfile;
}
public ProfileByUUIDRequestEvent() {
}
@Override
public UUID getUUID() {
return uuid;

View file

@ -9,8 +9,8 @@
public class ProfileByUsernameRequestEvent implements EventInterface, ResultInterface
{
private static final UUID uuid = UUID.fromString("06204302-ff6b-4779-b97d-541e3bc39aa1");
String error;
PlayerProfile playerProfile;
public String error;
public PlayerProfile playerProfile;
public ProfileByUsernameRequestEvent(PlayerProfile playerProfile) {
this.playerProfile = playerProfile;

View file

@ -10,12 +10,15 @@
public class ProfilesRequestEvent implements EventInterface, ResultInterface
{
private static final UUID uuid = UUID.fromString("2f26fbdf-598a-46dd-92fc-1699c0e173b1");
List<ClientProfile> profiles;
public List<ClientProfile> profiles;
public ProfilesRequestEvent(List<ClientProfile> profiles) {
this.profiles = profiles;
}
public ProfilesRequestEvent() {
}
String error;
@Override
public UUID getUUID() {