diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index 5a0f00b2..f02a6627 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -690,6 +690,7 @@ private void generateConfigIfNotExists(boolean testEnv) throws IOException { new MemoryAuthHandler(), new RequestTextureProvider("http://example.com/skins/%username%.png", "http://example.com/cloaks/%username%.png") , "std")}; + newConfig.auth[0].displayName = "Default"; newConfig.protectHandler = new NoProtectHandler(); if (testEnv) newConfig.permissionsHandler = new DefaultPermissionsHandler(); else newConfig.permissionsHandler = new JsonFilePermissionsHandler(); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/AuthProviderPair.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/AuthProviderPair.java index 4fd8bf32..7538b969 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/AuthProviderPair.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/AuthProviderPair.java @@ -11,6 +11,7 @@ public class AuthProviderPair { public AuthHandler handler; public TextureProvider textureProvider; public String name; + public String displayName; public boolean isDefault = true; public AuthProviderPair(AuthProvider provider, AuthHandler handler, TextureProvider textureProvider, String name) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/websocket/WebSocketService.java b/LaunchServer/src/main/java/ru/gravit/launchserver/websocket/WebSocketService.java index 08e6f35e..135c5759 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/websocket/WebSocketService.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/websocket/WebSocketService.java @@ -92,6 +92,7 @@ public void registerResponses() { registerResponse("profileByUUID", ProfileByUUIDResponse.class); registerResponse("getSecureToken", GetSecureTokenResponse.class); registerResponse("verifySecureToken", VerifySecureTokenResponse.class); + registerResponse("getAvailabilityAuth", GetAvailabilityAuthResponse.class); } public void sendObject(ChannelHandlerContext ctx, Object obj) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/websocket/json/auth/GetAvailabilityAuthResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/websocket/json/auth/GetAvailabilityAuthResponse.java new file mode 100644 index 00000000..858277d1 --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/websocket/json/auth/GetAvailabilityAuthResponse.java @@ -0,0 +1,29 @@ +package ru.gravit.launchserver.websocket.json.auth; + +import io.netty.channel.ChannelHandlerContext; +import ru.gravit.launcher.events.request.GetAvailabilityAuthRequestEvent; +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.auth.AuthProviderPair; +import ru.gravit.launchserver.socket.Client; +import ru.gravit.launchserver.websocket.WebSocketService; +import ru.gravit.launchserver.websocket.json.JsonResponseInterface; + +import java.util.ArrayList; +import java.util.List; + +public class GetAvailabilityAuthResponse implements JsonResponseInterface { + @Override + public String getType() { + return "getAvailabilityAuth"; + } + + @Override + public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { + List list = new ArrayList<>(); + for(AuthProviderPair pair : LaunchServer.server.config.auth) + { + list.add(new GetAvailabilityAuthRequestEvent.AuthAvailability(pair.name, pair.displayName)); + } + service.sendObject(ctx, new GetAvailabilityAuthRequestEvent(list)); + } +} diff --git a/Launcher/runtime/dialog/dialog.js b/Launcher/runtime/dialog/dialog.js index cc320481..d88edc46 100644 --- a/Launcher/runtime/dialog/dialog.js +++ b/Launcher/runtime/dialog/dialog.js @@ -224,16 +224,22 @@ function verifyLauncher(e) { if (settings.offline) { initOffline(); } - overlay.swap(0, processing.overlay, function(event) makeProfilesRequest(function(result) { - settings.lastProfiles = result.profiles; - updateProfilesList(result.profiles); - options.load(); - overlay.hide(0, function() { - if (cliParams.autoLogin) { - goAuth(null); - } - }); - })); + overlay.swap(0, processing.overlay, function(event) makeAuthAvailabilityRequest(function(result) { + //@DrLeonardo нужно напистаь добавление в список + //result.list весь список + //result.list[0].name имя авторизации(не видно) + //result.list[0].displayName имя авторизации(видно) + overlay.swap(0, processing.overlay, function(event) makeProfilesRequest(function(result) { + settings.lastProfiles = result.profiles; + updateProfilesList(result.profiles); + options.load(); + overlay.hide(0, function() { + if (cliParams.autoLogin) { + goAuth(null); + } + }); + })); + })); })); } diff --git a/Launcher/runtime/dialog/overlay/processing/processing.js b/Launcher/runtime/dialog/overlay/processing/processing.js index f9897c9b..d02589c1 100644 --- a/Launcher/runtime/dialog/overlay/processing/processing.js +++ b/Launcher/runtime/dialog/overlay/processing/processing.js @@ -91,7 +91,23 @@ function makeProfilesRequest(callback) { settings.offline = true; overlay.swap(2500, processing.overlay, function() makeProfilesRequest(callback)); }, false); - task.updateMessage("Обновление лаунчера"); + task.updateMessage("Обновление профилей"); + startTask(task); +} +function makeAuthAvailabilityRequest(callback) { + var task = newRequestTask(new GetAvailabilityAuthRequest()); + + // Set task properties and start + processing.setTaskProperties(task, callback, function() { + if (settings.offline) { + return; + } + + // Repeat request, but in offline mode + settings.offline = true; + overlay.swap(2500, processing.overlay, function() makeAuthAvailabilityRequest(callback)); + }, false); + task.updateMessage("Обновление способов авторизации"); startTask(task); } function makeSetProfileRequest(profile, callback) { diff --git a/Launcher/runtime/engine/api.js b/Launcher/runtime/engine/api.js index a11bde9d..ffc8d5f4 100644 --- a/Launcher/runtime/engine/api.js +++ b/Launcher/runtime/engine/api.js @@ -28,6 +28,7 @@ var SetProfileRequest = SetProfileRequestClass.static; var ProfileByUsernameRequest = ProfileByUsernameRequestClass.static; var ProfileByUUIDRequest = ProfileByUUIDRequestClass.static; var BatchProfileByUsernameRequest = BatchProfileByUsernameRequestClass.static; +var GetAvailabilityAuthRequest = GetAvailabilityAuthRequestClass.static; // Hasher class API imports var FileNameMatcher = FileNameMatcherClass.static; diff --git a/Launcher/src/main/java/ru/gravit/launcher/gui/JSRuntimeProvider.java b/Launcher/src/main/java/ru/gravit/launcher/gui/JSRuntimeProvider.java index e0fa8dbf..47b2ac46 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/gui/JSRuntimeProvider.java +++ b/Launcher/src/main/java/ru/gravit/launcher/gui/JSRuntimeProvider.java @@ -15,10 +15,7 @@ import ru.gravit.launcher.request.Request; import ru.gravit.launcher.request.RequestException; import ru.gravit.launcher.request.RequestType; -import ru.gravit.launcher.request.auth.AuthRequest; -import ru.gravit.launcher.request.auth.CheckServerRequest; -import ru.gravit.launcher.request.auth.JoinServerRequest; -import ru.gravit.launcher.request.auth.SetProfileRequest; +import ru.gravit.launcher.request.auth.*; import ru.gravit.launcher.request.update.LauncherRequest; import ru.gravit.launcher.request.update.ProfilesRequest; import ru.gravit.launcher.request.update.UpdateRequest; @@ -77,6 +74,7 @@ public static void addLauncherClassBindings(Map bindings) { bindings.put("ProfileByUsernameRequestClass", ProfileByUsernameRequest.class); bindings.put("ProfileByUUIDRequestClass", ProfileByUUIDRequest.class); bindings.put("BatchProfileByUsernameRequestClass", BatchProfileByUsernameRequest.class); + bindings.put("GetAvailabilityAuthRequestClass", GetAvailabilityAuthRequest.class); // Set hasher class bindings bindings.put("FileNameMatcherClass", FileNameMatcher.class); diff --git a/Launcher/src/main/java/ru/gravit/launcher/managers/SettingsManager.java b/Launcher/src/main/java/ru/gravit/launcher/managers/SettingsManager.java index 0865e2c9..42c6ee3b 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/managers/SettingsManager.java +++ b/Launcher/src/main/java/ru/gravit/launcher/managers/SettingsManager.java @@ -70,7 +70,8 @@ public void saveHDirStore(Path storeProjectPath) throws IOException Files.createDirectories(storeProjectPath); for(NewLauncherSettings.HashedStoreEntry e : settings.lastHDirs) { - Path file = Files.createFile(storeProjectPath.resolve(e.name.concat(".bin"))); + Path file = storeProjectPath.resolve(e.name.concat(".bin")); + if(!Files.exists(file)) Files.createFile(file); try(HOutput output = new HOutput(IOHelper.newOutput(file))) { output.writeString(e.name, 128); diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/GetAvailabilityAuthRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/GetAvailabilityAuthRequest.java new file mode 100644 index 00000000..6713134f --- /dev/null +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/GetAvailabilityAuthRequest.java @@ -0,0 +1,18 @@ +package ru.gravit.launcher.request.auth; + +import ru.gravit.launcher.events.request.GetAvailabilityAuthRequestEvent; +import ru.gravit.launcher.request.Request; +import ru.gravit.launcher.request.websockets.LegacyRequestBridge; +import ru.gravit.launcher.request.websockets.RequestInterface; + +public class GetAvailabilityAuthRequest extends Request implements RequestInterface { + @Override + protected GetAvailabilityAuthRequestEvent requestDo() throws Exception { + return (GetAvailabilityAuthRequestEvent) LegacyRequestBridge.sendRequest(this); + } + + @Override + public String getType() { + return "getAvailabilityAuth"; + } +} diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientWebSocketService.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientWebSocketService.java index bf7790c8..927e30e5 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientWebSocketService.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientWebSocketService.java @@ -115,6 +115,7 @@ public void registerResults() { registerResult("verifySecureToken", VerifySecureTokenRequestEvent.class); registerResult("log", LogEvent.class); registerResult("execCmd", ExecCommandRequestEvent.class); + registerResult("getAvailabilityAuth", GetAvailabilityAuthRequestEvent.class); } public void registerHandler(EventHandler eventHandler) { diff --git a/libLauncher/src/main/java/ru/gravit/launcher/events/request/GetAvailabilityAuthRequestEvent.java b/libLauncher/src/main/java/ru/gravit/launcher/events/request/GetAvailabilityAuthRequestEvent.java new file mode 100644 index 00000000..db1517f5 --- /dev/null +++ b/libLauncher/src/main/java/ru/gravit/launcher/events/request/GetAvailabilityAuthRequestEvent.java @@ -0,0 +1,32 @@ +package ru.gravit.launcher.events.request; + +import ru.gravit.launcher.LauncherNetworkAPI; +import ru.gravit.launcher.request.ResultInterface; + +import java.util.List; + +public class GetAvailabilityAuthRequestEvent implements ResultInterface { + public static class AuthAvailability + { + @LauncherNetworkAPI + public String name; + @LauncherNetworkAPI + public String displayName; + + public AuthAvailability(String name, String displayName) { + this.name = name; + this.displayName = displayName; + } + } + @LauncherNetworkAPI + public List list; + + public GetAvailabilityAuthRequestEvent(List list) { + this.list = list; + } + + @Override + public String getType() { + return "getAvailabilityAuth"; + } +}