Skip to content

Commit

Permalink
Use correct values for webhook attack statistics (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonesdevelopment authored Nov 14, 2023
1 parent 847936e commit 44754e5
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public static final class AttackStatistics {
private int peakJoinsPerSecond;
private double peakProcessCPUUsage;
private long peakProcessMemoryUsage;
// Calculate during-attack-statistics using their deltas
private int successfulVerifications, failedVerifications;
}

public void checkIfUnderAttack() {
Expand All @@ -62,6 +64,8 @@ public void checkIfUnderAttack() {
// An attack has been detected
if (currentAttack == null) {
currentAttack = new AttackStatistics();
currentAttack.successfulVerifications = Sonar.get().getVerifiedPlayerController().estimatedSize();
currentAttack.failedVerifications = Statistics.FAILED_VERIFICATIONS.get();
Sonar.get().getEventManager().publish(new AttackDetectedEvent());
} else {
// Reset attack timer if we're still under attack
Expand Down Expand Up @@ -101,8 +105,11 @@ public void checkIfUnderAttack() {
final String startTimestamp = String.valueOf(currentAttack.duration.getStart() / 1000L);
final String endTimestamp = String.valueOf(System.currentTimeMillis() / 1000L);
final long blacklisted = Sonar.get().getFallback().getBlacklisted().estimatedSize();
final long verified = Sonar.get().getVerifiedPlayerController().estimatedSize();
final long failed = Statistics.FAILED_VERIFICATIONS.get();
// Calculate during-attack-statistics using their deltas
final long totalVerified = Sonar.get().getVerifiedPlayerController().estimatedSize();
final long verified = Math.max(totalVerified - currentAttack.successfulVerifications, 0);
final long totalFailed = Statistics.FAILED_VERIFICATIONS.get();
final long failed = Math.max(totalFailed - currentAttack.failedVerifications, 0);

// Post webhook to Discord
Optional.ofNullable(Sonar.get().getConfig().getDiscordWebhook()).ifPresent(webhook -> webhook.post(() -> {
Expand Down

0 comments on commit 44754e5

Please sign in to comment.