mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-02 10:53:44 +00:00
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>
This commit is contained in:
42
dDatabase/GameDatabase/SQLite/Tables/ServerHealth.cpp
Normal file
42
dDatabase/GameDatabase/SQLite/Tables/ServerHealth.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#include "SQLiteDatabase.h"
|
||||
|
||||
void SQLiteDatabase::InsertHealthSample(const HealthSample& sample) {
|
||||
ExecuteInsert("INSERT OR REPLACE INTO server_health (time, players, worlds, auth_online, chat_online, memory_kb) VALUES (?, ?, ?, ?, ?, ?);",
|
||||
sample.time, sample.players, sample.worlds, sample.authOnline, sample.chatOnline, static_cast<int64_t>(sample.memoryKb));
|
||||
}
|
||||
|
||||
std::vector<IServerHealth::HealthSample> SQLiteDatabase::GetHealthSamples(int64_t from, int64_t to, int64_t bucketSeconds) {
|
||||
std::vector<HealthSample> samples;
|
||||
auto [_, result] = ExecuteSelect("SELECT (time / ?) * ? AS bucket, MAX(players) AS players, MAX(worlds) AS worlds, MIN(auth_online) AS auth, MIN(chat_online) AS chat, AVG(memory_kb) AS memory "
|
||||
"FROM server_health WHERE time >= ? AND time <= ? GROUP BY bucket ORDER BY bucket;", bucketSeconds, bucketSeconds, from, to);
|
||||
while (!result.eof()) {
|
||||
samples.push_back({ result.getInt64Field("bucket"), static_cast<uint32_t>(result.getIntField("players")), static_cast<uint32_t>(result.getIntField("worlds")),
|
||||
result.getIntField("auth") != 0, result.getIntField("chat") != 0, static_cast<uint64_t>(result.getFloatField("memory")) });
|
||||
result.nextRow();
|
||||
}
|
||||
return samples;
|
||||
}
|
||||
|
||||
uint32_t SQLiteDatabase::PruneHealthSamples(int64_t beforeTime) {
|
||||
ExecuteDelete("DELETE FROM server_health_instances WHERE time < ?;", beforeTime);
|
||||
return static_cast<uint32_t>(ExecuteUpdate("DELETE FROM server_health WHERE time < ?;", beforeTime));
|
||||
}
|
||||
|
||||
void SQLiteDatabase::InsertInstanceSamples(const std::vector<InstanceSample>& samples) {
|
||||
for (const auto& sample : samples) {
|
||||
ExecuteInsert("INSERT OR REPLACE INTO server_health_instances (time, zone_id, instance_id, clone_id, players) VALUES (?, ?, ?, ?, ?);",
|
||||
sample.time, sample.zoneId, sample.instanceId, sample.cloneId, sample.players);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<IServerHealth::InstanceSample> SQLiteDatabase::GetInstanceSamples(int64_t from, int64_t to, int64_t bucketSeconds, uint32_t zoneId) {
|
||||
std::vector<InstanceSample> samples;
|
||||
const std::string query = "SELECT (time / ?) * ? AS bucket, zone_id, instance_id, MAX(clone_id) AS clone_id, MAX(players) AS players FROM server_health_instances "
|
||||
"WHERE time >= ? AND time <= ?" + std::string(zoneId ? " AND zone_id = ?" : "") + " GROUP BY bucket, zone_id, instance_id ORDER BY bucket, zone_id, instance_id;";
|
||||
auto [_, result] = zoneId ? ExecuteSelect(query, bucketSeconds, bucketSeconds, from, to, zoneId) : ExecuteSelect(query, bucketSeconds, bucketSeconds, from, to);
|
||||
for (; !result.eof(); result.nextRow()) {
|
||||
samples.push_back({ result.getInt64Field("bucket"), static_cast<uint32_t>(result.getIntField("zone_id")), static_cast<uint32_t>(result.getIntField("instance_id")),
|
||||
static_cast<uint32_t>(result.getIntField("clone_id")), static_cast<uint32_t>(result.getIntField("players")) });
|
||||
}
|
||||
return samples;
|
||||
}
|
||||
Reference in New Issue
Block a user