diff --git a/LaunchServer/build.gradle b/LaunchServer/build.gradle index de70b34b..8c9398ed 100644 --- a/LaunchServer/build.gradle +++ b/LaunchServer/build.gradle @@ -184,18 +184,6 @@ task dumpClientLibs(type: Copy) { url = 'https://www.gnu.org/licenses/gpl-3.0.html' } } - developers { - developer { - id = 'gravit' - name = 'Gravit' - email = 'gravit.min@ya.ru' - } - developer { - id = 'zaxar163' - name = 'Zaxar163' - email = 'zahar.vcherachny@yandex.ru' - } - } scm { connection = 'scm:git:https://github.com/GravitLauncher/Launcher.git' diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/PingServerManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/PingServerManager.java index 65a80829..04937680 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/PingServerManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/PingServerManager.java @@ -8,17 +8,27 @@ import java.util.Map; public class PingServerManager { + public static long REPORT_EXPIRED_TIME = 20*1000; + public static class ServerInfoEntry { public PingServerReportRequest.PingServerReport lastReport; public long lastReportTime; + public final ClientProfile profile; - public ServerInfoEntry(PingServerReportRequest.PingServerReport lastReport) { + public ServerInfoEntry(ClientProfile profile, PingServerReportRequest.PingServerReport lastReport) { this.lastReport = lastReport; + this.profile = profile; this.lastReportTime = System.currentTimeMillis(); } - public ServerInfoEntry() { + public ServerInfoEntry(ClientProfile profile) { + this.profile = profile; + } + + public boolean isExpired() + { + return System.currentTimeMillis() - lastReportTime > REPORT_EXPIRED_TIME; } } public final Map map = new HashMap<>(); @@ -35,7 +45,7 @@ public void syncServers() ServerInfoEntry entry = map.get(sp.name); if(entry == null) { - map.put(sp.name, new ServerInfoEntry()); + map.put(sp.name, new ServerInfoEntry(p)); } } }); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java index 5a8b8001..fe2a8775 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java @@ -17,6 +17,7 @@ import pro.gravit.launchserver.socket.response.WebSocketServerResponse; import pro.gravit.launchserver.socket.response.auth.*; import pro.gravit.launchserver.socket.response.management.PingServerReportResponse; +import pro.gravit.launchserver.socket.response.management.PingServerResponse; import pro.gravit.launchserver.socket.response.management.ServerStatusResponse; import pro.gravit.launchserver.socket.response.profile.BatchProfileByUsername; import pro.gravit.launchserver.socket.response.profile.ProfileByUUIDResponse; @@ -87,6 +88,7 @@ public static void registerResponses() { providers.register("hardwareReport", HardwareReportResponse.class); providers.register("serverStatus", ServerStatusResponse.class); providers.register("pingServerReport", PingServerReportResponse.class); + providers.register("pingServer", PingServerResponse.class); } public void process(ChannelHandlerContext ctx, TextWebSocketFrame frame, Client client, String ip) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/management/PingServerResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/management/PingServerResponse.java new file mode 100644 index 00000000..8fc83c28 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/management/PingServerResponse.java @@ -0,0 +1,47 @@ +package pro.gravit.launchserver.socket.response.management; + +import io.netty.channel.ChannelHandlerContext; +import pro.gravit.launcher.events.request.PingServerRequestEvent; +import pro.gravit.launcher.request.management.PingServerReportRequest; +import pro.gravit.launchserver.auth.protect.interfaces.ProfilesProtectHandler; +import pro.gravit.launchserver.socket.Client; +import pro.gravit.launchserver.socket.response.SimpleResponse; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class PingServerResponse extends SimpleResponse { + public List serverNames; //May be null + @Override + public String getType() { + return "pingServer"; + } + + @Override + public void execute(ChannelHandlerContext ctx, Client client) throws Exception { + Map map = new HashMap<>(); + if(serverNames == null) + { + server.pingServerManager.map.forEach((name, entity) -> { + if(server.config.protectHandler instanceof ProfilesProtectHandler) + { + if(!((ProfilesProtectHandler) server.config.protectHandler).canGetProfile(entity.profile, client)) + { + return; + } + } + if(!entity.isExpired()) + { + map.put(name, entity.lastReport); + } + }); + } + else + { + sendError("Not implemented"); + return; + } + sendResult(new PingServerRequestEvent(map)); + } +} diff --git a/Launcher/build.gradle b/Launcher/build.gradle index bb7ac52a..10dbc4b7 100644 --- a/Launcher/build.gradle +++ b/Launcher/build.gradle @@ -93,18 +93,6 @@ task dumpLibs(type: Copy) { url = 'https://www.gnu.org/licenses/gpl-3.0.html' } } - developers { - developer { - id = 'gravit' - name = 'Gravit' - email = 'gravit.min@ya.ru' - } - developer { - id = 'zaxar163' - name = 'Zaxar163' - email = 'zahar.vcherachny@yandex.ru' - } - } scm { connection = 'scm:git:https://github.com/GravitLauncher/Launcher.git' developerConnection = 'scm:git:ssh://git@github.com:GravitLauncher/Launcher.git' diff --git a/LauncherAPI/build.gradle b/LauncherAPI/build.gradle index 0b33f0bd..724e14f4 100644 --- a/LauncherAPI/build.gradle +++ b/LauncherAPI/build.gradle @@ -47,18 +47,6 @@ task javadocJar(type: Jar) { url = 'https://www.gnu.org/licenses/gpl-3.0.html' } } - developers { - developer { - id = 'gravit' - name = 'Gravit' - email = 'gravit.min@ya.ru' - } - developer { - id = 'zaxar163' - name = 'Zaxar163' - email = 'zahar.vcherachny@yandex.ru' - } - } scm { connection = 'scm:git:https://github.com/GravitLauncher/Launcher.git' developerConnection = 'scm:git:ssh://git@github.com:GravitLauncher/Launcher.git' diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/PingServerRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/PingServerRequestEvent.java new file mode 100644 index 00000000..c4bf8558 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/PingServerRequestEvent.java @@ -0,0 +1,22 @@ +package pro.gravit.launcher.events.request; + +import pro.gravit.launcher.events.RequestEvent; +import pro.gravit.launcher.request.management.PingServerReportRequest; + +import java.util.Map; + +public class PingServerRequestEvent extends RequestEvent { + public Map serverMap; + + public PingServerRequestEvent() { + } + + public PingServerRequestEvent(Map serverMap) { + this.serverMap = serverMap; + } + + @Override + public String getType() { + return "pingServer"; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/management/PingServerRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/management/PingServerRequest.java new file mode 100644 index 00000000..635caf41 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/management/PingServerRequest.java @@ -0,0 +1,28 @@ +package pro.gravit.launcher.request.management; + +import pro.gravit.launcher.events.request.PingServerRequestEvent; +import pro.gravit.launcher.request.Request; + +import java.util.ArrayList; +import java.util.List; + +public class PingServerRequest extends Request { + public List serverNames; //May be null + + public PingServerRequest() { + } + + public PingServerRequest(List serverNames) { + this.serverNames = serverNames; + } + + public PingServerRequest(String serverName) { + this.serverNames = new ArrayList<>(); + serverNames.add(serverName); + } + + @Override + public String getType() { + return "pingServer"; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java index 0d98c46e..fb4bd479 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java @@ -103,6 +103,7 @@ public void registerResults() { results.register("hardwareReport", HardwareReportRequestEvent.class); results.register("serverStatus", ServerStatusRequestEvent.class); results.register("pingServerReport", PingServerReportRequestEvent.class); + results.register("pingServer", PingServerRequestEvent.class); } public void waitIfNotConnected() { diff --git a/LauncherCore/build.gradle b/LauncherCore/build.gradle index cea9711f..893510f4 100644 --- a/LauncherCore/build.gradle +++ b/LauncherCore/build.gradle @@ -67,18 +67,6 @@ task javadocJar(type: Jar) { url = 'https://www.gnu.org/licenses/gpl-3.0.html' } } - developers { - developer { - id = 'gravit' - name = 'Gravit' - email = 'gravit.min@ya.ru' - } - developer { - id = 'zaxar163' - name = 'Zaxar163' - email = 'zahar.vcherachny@yandex.ru' - } - } scm { connection = 'scm:git:https://github.com/GravitLauncher/Launcher.git' developerConnection = 'scm:git:ssh://git@github.com:GravitLauncher/Launcher.git' diff --git a/ServerWrapper/build.gradle b/ServerWrapper/build.gradle index 9934b0e9..b99abe6b 100644 --- a/ServerWrapper/build.gradle +++ b/ServerWrapper/build.gradle @@ -68,18 +68,6 @@ pack project(':LauncherAuthlib') url = 'https://www.gnu.org/licenses/gpl-3.0.html' } } - developers { - developer { - id = 'gravit' - name = 'Gravit' - email = 'gravit.min@ya.ru' - } - developer { - id = 'zaxar163' - name = 'Zaxar163' - email = 'zahar.vcherachny@yandex.ru' - } - } scm { connection = 'scm:git:https://github.com/GravitLauncher/Launcher.git'