mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-22 16:41:46 +03:00
[FEATURE] PingServerRequest
This commit is contained in:
parent
6c76e0758d
commit
4bea6bb16b
11 changed files with 113 additions and 63 deletions
|
@ -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'
|
||||
|
|
|
@ -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<String, ServerInfoEntry> 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));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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<String> serverNames; //May be null
|
||||
@Override
|
||||
public String getType() {
|
||||
return "pingServer";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(ChannelHandlerContext ctx, Client client) throws Exception {
|
||||
Map<String, PingServerReportRequest.PingServerReport> 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));
|
||||
}
|
||||
}
|
|
@ -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'
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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<String, PingServerReportRequest.PingServerReport> serverMap;
|
||||
|
||||
public PingServerRequestEvent() {
|
||||
}
|
||||
|
||||
public PingServerRequestEvent(Map<String, PingServerReportRequest.PingServerReport> serverMap) {
|
||||
this.serverMap = serverMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "pingServer";
|
||||
}
|
||||
}
|
|
@ -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<PingServerRequestEvent> {
|
||||
public List<String> serverNames; //May be null
|
||||
|
||||
public PingServerRequest() {
|
||||
}
|
||||
|
||||
public PingServerRequest(List<String> serverNames) {
|
||||
this.serverNames = serverNames;
|
||||
}
|
||||
|
||||
public PingServerRequest(String serverName) {
|
||||
this.serverNames = new ArrayList<>();
|
||||
serverNames.add(serverName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "pingServer";
|
||||
}
|
||||
}
|
|
@ -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() {
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Reference in a new issue