mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
[FEATURE] Profiles refresh
This commit is contained in:
parent
28a9b5efc4
commit
36d97e7f8b
3 changed files with 29 additions and 1 deletions
|
@ -3,9 +3,12 @@
|
||||||
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 pro.gravit.launcher.Launcher;
|
import pro.gravit.launcher.Launcher;
|
||||||
|
import pro.gravit.launcher.events.RequestEvent;
|
||||||
|
import pro.gravit.launcher.events.request.ProfilesRequestEvent;
|
||||||
import pro.gravit.launcher.managers.ConfigManager;
|
import pro.gravit.launcher.managers.ConfigManager;
|
||||||
import pro.gravit.launcher.modules.events.ClosePhase;
|
import pro.gravit.launcher.modules.events.ClosePhase;
|
||||||
import pro.gravit.launcher.profiles.ClientProfile;
|
import pro.gravit.launcher.profiles.ClientProfile;
|
||||||
|
import pro.gravit.launcher.request.Request;
|
||||||
import pro.gravit.launchserver.auth.AuthProviderPair;
|
import pro.gravit.launchserver.auth.AuthProviderPair;
|
||||||
import pro.gravit.launchserver.auth.core.RejectAuthCoreProvider;
|
import pro.gravit.launchserver.auth.core.RejectAuthCoreProvider;
|
||||||
import pro.gravit.launchserver.binary.EXEL4JLauncherBinary;
|
import pro.gravit.launchserver.binary.EXEL4JLauncherBinary;
|
||||||
|
@ -19,7 +22,9 @@
|
||||||
import pro.gravit.launchserver.manangers.hook.AuthHookManager;
|
import pro.gravit.launchserver.manangers.hook.AuthHookManager;
|
||||||
import pro.gravit.launchserver.modules.events.*;
|
import pro.gravit.launchserver.modules.events.*;
|
||||||
import pro.gravit.launchserver.modules.impl.LaunchServerModulesManager;
|
import pro.gravit.launchserver.modules.impl.LaunchServerModulesManager;
|
||||||
|
import pro.gravit.launchserver.socket.Client;
|
||||||
import pro.gravit.launchserver.socket.handlers.NettyServerSocketHandler;
|
import pro.gravit.launchserver.socket.handlers.NettyServerSocketHandler;
|
||||||
|
import pro.gravit.launchserver.socket.response.auth.ProfilesResponse;
|
||||||
import pro.gravit.launchserver.socket.response.auth.RestoreResponse;
|
import pro.gravit.launchserver.socket.response.auth.RestoreResponse;
|
||||||
import pro.gravit.utils.command.Command;
|
import pro.gravit.utils.command.Command;
|
||||||
import pro.gravit.utils.command.CommandHandler;
|
import pro.gravit.utils.command.CommandHandler;
|
||||||
|
@ -374,6 +379,24 @@ public void syncProfilesDir() throws IOException {
|
||||||
// Sort and set new profiles
|
// Sort and set new profiles
|
||||||
newProfies.sort(Comparator.comparing(a -> a));
|
newProfies.sort(Comparator.comparing(a -> a));
|
||||||
profilesList = Set.copyOf(newProfies);
|
profilesList = Set.copyOf(newProfies);
|
||||||
|
if(config.netty.sendProfileUpdatesEvent) {
|
||||||
|
sendUpdateProfilesEvent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendUpdateProfilesEvent() {
|
||||||
|
if(nettyServerSocketHandler == null || nettyServerSocketHandler.nettyServer == null || nettyServerSocketHandler.nettyServer.service == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
nettyServerSocketHandler.nettyServer.service.forEachActiveChannels((ch, handler) -> {
|
||||||
|
Client client = handler.getClient();
|
||||||
|
if(client == null || !client.isAuth) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ProfilesRequestEvent event = new ProfilesRequestEvent(ProfilesResponse.getListVisibleProfiles(this, client));
|
||||||
|
event.requestUUID = RequestEvent.eventUUID;
|
||||||
|
handler.service.sendObject(ch, event);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void syncUpdatesDir(Collection<String> dirs) throws IOException {
|
public void syncUpdatesDir(Collection<String> dirs) throws IOException {
|
||||||
|
|
|
@ -281,6 +281,7 @@ public static class NettyConfig {
|
||||||
public boolean ipForwarding;
|
public boolean ipForwarding;
|
||||||
public boolean disableWebApiInterface;
|
public boolean disableWebApiInterface;
|
||||||
public boolean showHiddenFiles;
|
public boolean showHiddenFiles;
|
||||||
|
public boolean sendProfileUpdatesEvent = true;
|
||||||
public String launcherURL;
|
public String launcherURL;
|
||||||
public String downloadURL;
|
public String downloadURL;
|
||||||
public String launcherEXEURL;
|
public String launcherEXEURL;
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import pro.gravit.launcher.events.request.ProfilesRequestEvent;
|
import pro.gravit.launcher.events.request.ProfilesRequestEvent;
|
||||||
import pro.gravit.launcher.profiles.ClientProfile;
|
import pro.gravit.launcher.profiles.ClientProfile;
|
||||||
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.auth.protect.interfaces.ProfilesProtectHandler;
|
import pro.gravit.launchserver.auth.protect.interfaces.ProfilesProtectHandler;
|
||||||
import pro.gravit.launchserver.socket.Client;
|
import pro.gravit.launchserver.socket.Client;
|
||||||
import pro.gravit.launchserver.socket.response.SimpleResponse;
|
import pro.gravit.launchserver.socket.response.SimpleResponse;
|
||||||
|
@ -23,7 +24,10 @@ public void execute(ChannelHandlerContext ctx, Client client) {
|
||||||
sendError("Access denied");
|
sendError("Access denied");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
sendResult(new ProfilesRequestEvent(getListVisibleProfiles(server, client)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<ClientProfile> getListVisibleProfiles(LaunchServer server, Client client) {
|
||||||
List<ClientProfile> profileList;
|
List<ClientProfile> profileList;
|
||||||
Set<ClientProfile> serverProfiles = server.getProfiles();
|
Set<ClientProfile> serverProfiles = server.getProfiles();
|
||||||
if (server.config.protectHandler instanceof ProfilesProtectHandler protectHandler) {
|
if (server.config.protectHandler instanceof ProfilesProtectHandler protectHandler) {
|
||||||
|
@ -36,6 +40,6 @@ public void execute(ChannelHandlerContext ctx, Client client) {
|
||||||
} else {
|
} else {
|
||||||
profileList = List.copyOf(serverProfiles);
|
profileList = List.copyOf(serverProfiles);
|
||||||
}
|
}
|
||||||
sendResult(new ProfilesRequestEvent(profileList));
|
return profileList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue