diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index 968ffaee..d4c88e81 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -3,9 +3,12 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; 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.modules.events.ClosePhase; import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.launcher.request.Request; import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.auth.core.RejectAuthCoreProvider; import pro.gravit.launchserver.binary.EXEL4JLauncherBinary; @@ -19,7 +22,9 @@ import pro.gravit.launchserver.manangers.hook.AuthHookManager; import pro.gravit.launchserver.modules.events.*; 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.response.auth.ProfilesResponse; import pro.gravit.launchserver.socket.response.auth.RestoreResponse; import pro.gravit.utils.command.Command; import pro.gravit.utils.command.CommandHandler; @@ -374,6 +379,24 @@ public void syncProfilesDir() throws IOException { // Sort and set new profiles newProfies.sort(Comparator.comparing(a -> a)); 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 dirs) throws IOException { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java index 33fb67a1..875dc460 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java @@ -281,6 +281,7 @@ public static class NettyConfig { public boolean ipForwarding; public boolean disableWebApiInterface; public boolean showHiddenFiles; + public boolean sendProfileUpdatesEvent = true; public String launcherURL; public String downloadURL; public String launcherEXEURL; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/ProfilesResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/ProfilesResponse.java index c22f1603..ec602d7f 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/ProfilesResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/ProfilesResponse.java @@ -3,6 +3,7 @@ import io.netty.channel.ChannelHandlerContext; import pro.gravit.launcher.events.request.ProfilesRequestEvent; import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.auth.protect.interfaces.ProfilesProtectHandler; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.SimpleResponse; @@ -23,7 +24,10 @@ public void execute(ChannelHandlerContext ctx, Client client) { sendError("Access denied"); return; } + sendResult(new ProfilesRequestEvent(getListVisibleProfiles(server, client))); + } + public static List getListVisibleProfiles(LaunchServer server, Client client) { List profileList; Set serverProfiles = server.getProfiles(); if (server.config.protectHandler instanceof ProfilesProtectHandler protectHandler) { @@ -36,6 +40,6 @@ public void execute(ChannelHandlerContext ctx, Client client) { } else { profileList = List.copyOf(serverProfiles); } - sendResult(new ProfilesRequestEvent(profileList)); + return profileList; } }