mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
[FEATURE] GetAvailabilityAuth
This commit is contained in:
parent
477798e30c
commit
1ad67d4a75
12 changed files with 121 additions and 16 deletions
|
@ -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();
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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<GetAvailabilityAuthRequestEvent.AuthAvailability> 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));
|
||||
}
|
||||
}
|
|
@ -224,6 +224,11 @@ function verifyLauncher(e) {
|
|||
if (settings.offline) {
|
||||
initOffline();
|
||||
}
|
||||
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);
|
||||
|
@ -235,6 +240,7 @@ function verifyLauncher(e) {
|
|||
});
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
}
|
||||
|
||||
function doAuth(login, rsaPassword) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<String, Object> 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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<GetAvailabilityAuthRequestEvent> implements RequestInterface {
|
||||
@Override
|
||||
protected GetAvailabilityAuthRequestEvent requestDo() throws Exception {
|
||||
return (GetAvailabilityAuthRequestEvent) LegacyRequestBridge.sendRequest(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "getAvailabilityAuth";
|
||||
}
|
||||
}
|
|
@ -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) {
|
||||
|
|
|
@ -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<AuthAvailability> list;
|
||||
|
||||
public GetAvailabilityAuthRequestEvent(List<AuthAvailability> list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "getAvailabilityAuth";
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue