mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-02 19:03:43 +00:00
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>
92 lines
3.3 KiB
C++
92 lines
3.3 KiB
C++
#include "MySQLDatabase.h"
|
|
|
|
std::string MySQLDatabase::GetCharacterXml(const LWOOBJID charId) {
|
|
auto result = ExecuteSelect("SELECT xml_data FROM charxml WHERE id = ? LIMIT 1;", charId);
|
|
|
|
if (!result->next()) {
|
|
return "";
|
|
}
|
|
|
|
return result->getString("xml_data").c_str();
|
|
}
|
|
|
|
void MySQLDatabase::UpdateCharacterXml(const LWOOBJID charId, const std::string_view lxfml) {
|
|
ExecuteUpdate("UPDATE charxml SET xml_data = ? WHERE id = ?;", lxfml, charId);
|
|
}
|
|
|
|
void MySQLDatabase::InsertCharacterXml(const LWOOBJID characterId, const std::string_view lxfml) {
|
|
ExecuteInsert("INSERT INTO `charxml` (`id`, `xml_data`) VALUES (?,?)", characterId, lxfml);
|
|
}
|
|
|
|
#include "GeneralUtils.h"
|
|
#include "json.hpp"
|
|
|
|
std::string MySQLDatabase::GetCharactersTable(uint32_t start, uint32_t length, const std::string_view search, uint32_t orderColumn, bool orderAsc) {
|
|
// A number in the search box also matches IDs exactly (-1 never matches)
|
|
const int64_t searchId = GeneralUtils::TryParse<int64_t>(std::string(search)).value_or(-1);
|
|
// Build base query
|
|
std::string baseQuery = "SELECT c.id, c.name, c.account_id, c.last_login, a.name as account_name FROM charinfo c JOIN accounts a ON c.account_id = a.id";
|
|
std::string whereClause;
|
|
std::string orderClause;
|
|
|
|
// Add search filter if provided
|
|
if (!search.empty()) {
|
|
whereClause = " WHERE (c.name LIKE CONCAT('%', ?, '%') OR c.id = ? OR a.name LIKE CONCAT('%', ?, '%'))";
|
|
}
|
|
|
|
// Map column indices to database columns
|
|
std::string orderColumnName = "c.id";
|
|
switch (orderColumn) {
|
|
case 0: orderColumnName = "c.id"; break;
|
|
case 1: orderColumnName = "c.name"; break;
|
|
case 2: orderColumnName = "a.name"; break;
|
|
case 3: orderColumnName = "c.last_login"; break;
|
|
default: orderColumnName = "c.id";
|
|
}
|
|
|
|
orderClause = " ORDER BY " + orderColumnName + (orderAsc ? " ASC" : " DESC") + ", c.id";
|
|
|
|
// Build the main query
|
|
std::string mainQuery = baseQuery + whereClause + orderClause + " LIMIT ?, ?;";
|
|
|
|
// Get total count
|
|
std::string totalCountQuery = "SELECT COUNT(*) as count FROM charinfo;";
|
|
auto totalCountResult = ExecuteSelect(totalCountQuery);
|
|
uint32_t totalRecords = totalCountResult->next() ? totalCountResult->getUInt("count") : 0;
|
|
|
|
// Get filtered count
|
|
uint32_t filteredRecords = totalRecords;
|
|
if (!search.empty()) {
|
|
std::string filteredCountQuery = "SELECT COUNT(*) as count FROM charinfo c JOIN accounts a ON c.account_id = a.id WHERE (c.name LIKE CONCAT('%', ?, '%') OR c.id = ? OR a.name LIKE CONCAT('%', ?, '%'));";
|
|
auto filteredCountResult = ExecuteSelect(filteredCountQuery, search, searchId, search);
|
|
filteredRecords = filteredCountResult->next() ? filteredCountResult->getUInt("count") : 0;
|
|
}
|
|
|
|
// Execute main query
|
|
auto result = !search.empty()
|
|
? ExecuteSelect(mainQuery, search, searchId, search, start, length)
|
|
: ExecuteSelect(mainQuery, start, length);
|
|
|
|
// Build response JSON
|
|
nlohmann::json charactersArray = nlohmann::json::array();
|
|
|
|
while (result->next()) {
|
|
nlohmann::json character = {
|
|
{"id", std::to_string(result->getUInt64("id"))},
|
|
{"name", result->getString("name")},
|
|
{"account_name", result->getString("account_name")},
|
|
{"last_login", result->getUInt64("last_login")}
|
|
};
|
|
charactersArray.push_back(character);
|
|
}
|
|
|
|
nlohmann::json response = {
|
|
{"draw", 0},
|
|
{"recordsTotal", totalRecords},
|
|
{"recordsFiltered", filteredRecords},
|
|
{"data", charactersArray}
|
|
};
|
|
|
|
return response.dump();
|
|
}
|