Files
DarkflameServer/dDashboardServer/routes/StrikeSteps.h
Aaron Kimbrell e213a7aeff feat: web dashboard and playground work
The NexusDashboard-parity dashboard (dDashboardServer) and everything built on it on the experimental branch:
accounts, characters, properties and moderation tools, permissions shared with in-game slash commands, economy
reports, World 3D and property 3D views with client scenery, scheduled events (features, vanity changes, live
events, announcements, restarts), vanity files and events, the CDClient browser, the message inspector with saved
captures, chat filter tools, community challenges, live ops, the AI moderator helper, and the server-side changes
they need.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 22:30:43 -05:00

40 lines
1.5 KiB
C++

#pragma once
#include <cstdint>
#include <optional>
#include <utility>
#include <vector>
#include "eStrikeStep.h"
/**
* Strike thresholds: what happens on its own when an account reaches a number of active strikes (Settings, Dashboard:
* strike_warn_at, strike_mute_at with strike_mute_days, strike_ban_at with strike_ban_days; 0 turns a step off).
* Pure, so it is unit tested.
*/
namespace StrikeSteps {
struct Threshold {
eStrikeStep step{};
uint32_t at{}; // active strikes that set it off
int64_t days{}; // MUTE, BAN: how long (BAN: 0 is permanent)
};
/**
* The step to apply now that the account has `active` strikes: the one with the highest threshold reached (the
* most severe on a tie), unless that step was already applied for that number of strikes (`applied`: step and the
* count it was applied for, while those strikes count).
*/
inline std::optional<Threshold> Choose(const std::vector<Threshold>& thresholds, uint32_t active, const std::vector<std::pair<eStrikeStep, uint32_t>>& applied) {
std::optional<Threshold> chosen;
for (const auto& threshold : thresholds) {
if (threshold.at == 0 || threshold.at > active) continue;
if (!chosen || threshold.at > chosen->at || (threshold.at == chosen->at && threshold.step > chosen->step)) chosen = threshold;
}
if (!chosen) return std::nullopt;
for (const auto& [step, count] : applied) {
if (step == chosen->step && count == chosen->at) return std::nullopt;
}
return chosen;
}
}