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>
114 lines
4.3 KiB
C++
114 lines
4.3 KiB
C++
#include "SQLiteDatabase.h"
|
|
#include "json.hpp"
|
|
|
|
std::vector<std::string> SQLiteDatabase::GetApprovedCharacterNames() {
|
|
auto [_, result] = ExecuteSelect("SELECT name FROM charinfo;");
|
|
|
|
std::vector<std::string> toReturn;
|
|
|
|
while (!result.eof()) {
|
|
toReturn.push_back(result.getStringField("name"));
|
|
result.nextRow();
|
|
}
|
|
|
|
return toReturn;
|
|
}
|
|
|
|
std::optional<ICharInfo::Info> CharInfoFromQueryResult(CppSQLite3Query stmt) {
|
|
if (stmt.eof()) {
|
|
return std::nullopt;
|
|
}
|
|
|
|
ICharInfo::Info toReturn;
|
|
|
|
toReturn.id = stmt.getInt64Field("id");
|
|
toReturn.name = stmt.getStringField("name");
|
|
toReturn.pendingName = stmt.getStringField("pending_name");
|
|
toReturn.needsRename = stmt.getIntField("needs_rename");
|
|
toReturn.cloneId = stmt.getInt64Field("prop_clone_id");
|
|
toReturn.accountId = stmt.getIntField("account_id");
|
|
toReturn.permissionMap = static_cast<ePermissionMap>(stmt.getIntField("permission_map"));
|
|
|
|
return toReturn;
|
|
}
|
|
|
|
std::optional<ICharInfo::Info> SQLiteDatabase::GetCharacterInfo(const LWOOBJID charId) {
|
|
return CharInfoFromQueryResult(
|
|
ExecuteSelect("SELECT name, pending_name, needs_rename, prop_clone_id, permission_map, id, account_id FROM charinfo WHERE id = ? LIMIT 1;", charId).second
|
|
);
|
|
}
|
|
|
|
std::optional<ICharInfo::Info> SQLiteDatabase::GetCharacterInfo(const std::string_view name) {
|
|
return CharInfoFromQueryResult(
|
|
ExecuteSelect("SELECT name, pending_name, needs_rename, prop_clone_id, permission_map, id, account_id FROM charinfo WHERE name = ? LIMIT 1;", name).second
|
|
);
|
|
}
|
|
|
|
std::vector<LWOOBJID> SQLiteDatabase::GetAccountCharacterIds(const LWOOBJID accountId) {
|
|
auto [_, result] = ExecuteSelect("SELECT id FROM charinfo WHERE account_id = ? ORDER BY last_login DESC LIMIT 4;", accountId);
|
|
|
|
std::vector<LWOOBJID> toReturn;
|
|
while (!result.eof()) {
|
|
toReturn.push_back(result.getInt64Field("id"));
|
|
result.nextRow();
|
|
}
|
|
|
|
return toReturn;
|
|
}
|
|
|
|
uint32_t SQLiteDatabase::GetCharacterCount() {
|
|
auto [_, res] = ExecuteSelect("SELECT COUNT(*) as count FROM charinfo;");
|
|
if (res.eof()) return 0;
|
|
|
|
return res.getIntField("count");
|
|
}
|
|
|
|
void SQLiteDatabase::InsertNewCharacter(const ICharInfo::Info info) {
|
|
ExecuteInsert(
|
|
"INSERT INTO `charinfo`(`id`, `account_id`, `name`, `pending_name`, `needs_rename`, `last_login`, `prop_clone_id`) VALUES (?,?,?,?,?,?,(SELECT IFNULL(MAX(`prop_clone_id`), 0) + 1 FROM `charinfo`))",
|
|
info.id,
|
|
info.accountId,
|
|
info.name,
|
|
info.pendingName,
|
|
false,
|
|
static_cast<uint32_t>(time(NULL)));
|
|
}
|
|
|
|
void SQLiteDatabase::SetCharacterName(const LWOOBJID characterId, const std::string_view name) {
|
|
ExecuteUpdate("UPDATE charinfo SET name = ?, pending_name = '', needs_rename = 0, last_login = ? WHERE id = ?;", name, static_cast<uint32_t>(time(NULL)), characterId);
|
|
}
|
|
|
|
void SQLiteDatabase::SetPendingCharacterName(const LWOOBJID characterId, const std::string_view name) {
|
|
ExecuteUpdate("UPDATE charinfo SET pending_name = ?, needs_rename = 0, last_login = ? WHERE id = ?;", name, static_cast<uint32_t>(time(NULL)), characterId);
|
|
}
|
|
|
|
void SQLiteDatabase::UpdateLastLoggedInCharacter(const LWOOBJID characterId) {
|
|
ExecuteUpdate("UPDATE charinfo SET last_login = ? WHERE id = ?;", static_cast<uint32_t>(time(NULL)), characterId);
|
|
}
|
|
|
|
bool SQLiteDatabase::IsNameInUse(const std::string_view name) {
|
|
auto [_, result] = ExecuteSelect("SELECT name FROM charinfo WHERE name = ? or pending_name = ? LIMIT 1;", name, name);
|
|
|
|
return !result.eof();
|
|
}
|
|
|
|
nlohmann::json SQLiteDatabase::GetCharacterById(const LWOOBJID charId) {
|
|
auto [_, result] = ExecuteSelect(
|
|
"SELECT c.id, c.name, c.pending_name, c.needs_rename, c.account_id, c.last_login, c.prop_clone_id, c.permission_map, a.name as account_name "
|
|
"FROM charinfo c LEFT JOIN accounts a ON c.account_id = a.id WHERE c.id = ? LIMIT 1;", charId);
|
|
if (result.eof()) {
|
|
return nlohmann::json({{"error", "Character not found"}});
|
|
}
|
|
return nlohmann::json({
|
|
{"id", std::to_string(result.getInt64Field("id"))},
|
|
{"name", result.getStringField("name")},
|
|
{"pending_name", result.getStringField("pending_name")},
|
|
{"needs_rename", result.getIntField("needs_rename") != 0},
|
|
{"account_id", result.getIntField("account_id")},
|
|
{"account_name", result.getStringField("account_name")},
|
|
{"last_login", result.getInt64Field("last_login")},
|
|
{"prop_clone_id", result.getInt64Field("prop_clone_id")},
|
|
{"permission_map", result.getIntField("permission_map")}
|
|
});
|
|
}
|