feat(dashboard): refine activity telemetry and maps
This commit is contained in:
@@ -59,6 +59,43 @@ final class AccountManagerClient {
|
||||
}
|
||||
}
|
||||
|
||||
boolean reportConnected(UUID minecraftUuid, String username) {
|
||||
String compactUuid = minecraftUuid.toString().replace("-", "").toLowerCase();
|
||||
ConnectionRequest payload = new ConnectionRequest(
|
||||
UUID.randomUUID().toString(),
|
||||
config.serverId(),
|
||||
compactUuid,
|
||||
username,
|
||||
Instant.now().toString()
|
||||
);
|
||||
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(config.apiUrl() + "/api/velocity/connection"))
|
||||
.timeout(config.timeout())
|
||||
.header("Authorization", "Bearer " + config.apiToken())
|
||||
.header("Content-Type", "application/json")
|
||||
.POST(HttpRequest.BodyPublishers.ofString(gson.toJson(payload)))
|
||||
.build();
|
||||
|
||||
try {
|
||||
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
return response.statusCode() == 204;
|
||||
} catch (InterruptedException exception) {
|
||||
Thread.currentThread().interrupt();
|
||||
return false;
|
||||
} catch (IOException | RuntimeException exception) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private record ConnectionRequest(
|
||||
String requestId,
|
||||
String serverId,
|
||||
String minecraftUuid,
|
||||
String username,
|
||||
String occurredAt
|
||||
) {}
|
||||
|
||||
private record AccessRequest(
|
||||
String requestId,
|
||||
String serverId,
|
||||
|
||||
+20
-1
@@ -5,9 +5,11 @@ import com.velocitypowered.api.event.EventTask;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.ResultedEvent;
|
||||
import com.velocitypowered.api.event.connection.LoginEvent;
|
||||
import com.velocitypowered.api.event.connection.PostLoginEvent;
|
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.plugin.Plugin;
|
||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@@ -22,13 +24,15 @@ import org.slf4j.Logger;
|
||||
public final class MinecraftAccountManagerPlugin {
|
||||
private final Logger logger;
|
||||
private final Path dataDirectory;
|
||||
private final ProxyServer proxyServer;
|
||||
private volatile AccountManagerClient accountManagerClient;
|
||||
private volatile String fallbackMessage = "Please register your Minecraft account in Discord before joining.";
|
||||
|
||||
@Inject
|
||||
public MinecraftAccountManagerPlugin(Logger logger, @DataDirectory Path dataDirectory) {
|
||||
public MinecraftAccountManagerPlugin(Logger logger, @DataDirectory Path dataDirectory, ProxyServer proxyServer) {
|
||||
this.logger = logger;
|
||||
this.dataDirectory = dataDirectory;
|
||||
this.proxyServer = proxyServer;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@@ -66,4 +70,19 @@ public final class MinecraftAccountManagerPlugin {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onPostLogin(PostLoginEvent event) {
|
||||
proxyServer.getScheduler().buildTask(this, () -> {
|
||||
AccountManagerClient client = accountManagerClient;
|
||||
if (client == null) return;
|
||||
boolean recorded = client.reportConnected(
|
||||
event.getPlayer().getUniqueId(),
|
||||
event.getPlayer().getUsername()
|
||||
);
|
||||
if (!recorded) {
|
||||
logger.warn("Could not report confirmed Minecraft connection for {} ({})", event.getPlayer().getUsername(), event.getPlayer().getUniqueId());
|
||||
}
|
||||
}).schedule();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user