mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-04-09 17:26:58 +00:00
- Added ICharacterReputation and IPropertyReputationContribution interfaces for managing character and property reputations. - Implemented MySQL and SQLite database methods for getting and setting character reputations. - Created migration scripts for character and property reputation tables in both MySQL and SQLite. - Updated CharacterComponent to retrieve and set character reputation. - Enhanced PropertyManagementComponent to manage property reputation and contributions. - Added methods for handling reputation contributions and decay. - Introduced CharacterReputationMigration to migrate existing character reputations from XML to the database.
95 lines
3.4 KiB
C++
95 lines
3.4 KiB
C++
#include "MySQLDatabase.h"
|
|
|
|
std::vector<std::string> MySQLDatabase::GetApprovedCharacterNames() {
|
|
auto result = ExecuteSelect("SELECT name FROM charinfo;");
|
|
|
|
std::vector<std::string> toReturn;
|
|
|
|
while (result->next()) {
|
|
toReturn.push_back(result->getString("name").c_str());
|
|
}
|
|
|
|
return toReturn;
|
|
}
|
|
|
|
std::optional<ICharInfo::Info> CharInfoFromQueryResult(PreparedStmtResultSet& stmt) {
|
|
if (!stmt->next()) {
|
|
return std::nullopt;
|
|
}
|
|
|
|
ICharInfo::Info toReturn;
|
|
|
|
toReturn.id = stmt->getInt64("id");
|
|
toReturn.name = stmt->getString("name").c_str();
|
|
toReturn.pendingName = stmt->getString("pending_name").c_str();
|
|
toReturn.needsRename = stmt->getBoolean("needs_rename");
|
|
toReturn.cloneId = stmt->getUInt64("prop_clone_id");
|
|
toReturn.accountId = stmt->getUInt("account_id");
|
|
toReturn.permissionMap = static_cast<ePermissionMap>(stmt->getUInt("permission_map"));
|
|
|
|
return toReturn;
|
|
}
|
|
|
|
std::optional<ICharInfo::Info> MySQLDatabase::GetCharacterInfo(const LWOOBJID charId) {
|
|
auto result = ExecuteSelect("SELECT name, pending_name, needs_rename, prop_clone_id, permission_map, id, account_id FROM charinfo WHERE id = ? LIMIT 1;", charId);
|
|
return CharInfoFromQueryResult(result);
|
|
}
|
|
|
|
std::optional<ICharInfo::Info> MySQLDatabase::GetCharacterInfo(const std::string_view name) {
|
|
auto result = ExecuteSelect("SELECT name, pending_name, needs_rename, prop_clone_id, permission_map, id, account_id FROM charinfo WHERE name = ? LIMIT 1;", name);
|
|
return CharInfoFromQueryResult(result);
|
|
}
|
|
|
|
std::vector<LWOOBJID> MySQLDatabase::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;
|
|
toReturn.reserve(result->rowsCount());
|
|
while (result->next()) {
|
|
toReturn.push_back(result->getInt64("id"));
|
|
}
|
|
|
|
return toReturn;
|
|
}
|
|
|
|
std::vector<LWOOBJID> MySQLDatabase::GetAllCharacterIds() {
|
|
auto result = ExecuteSelect("SELECT id FROM charinfo;");
|
|
|
|
std::vector<LWOOBJID> toReturn;
|
|
toReturn.reserve(result->rowsCount());
|
|
while (result->next()) {
|
|
toReturn.push_back(result->getInt64("id"));
|
|
}
|
|
|
|
return toReturn;
|
|
}
|
|
|
|
void MySQLDatabase::InsertNewCharacter(const ICharInfo::Info info) {
|
|
ExecuteInsert(
|
|
"INSERT INTO `charinfo`(`id`, `account_id`, `name`, `pending_name`, `needs_rename`, `last_login`) VALUES (?,?,?,?,?,?)",
|
|
info.id,
|
|
info.accountId,
|
|
info.name,
|
|
info.pendingName,
|
|
false,
|
|
static_cast<uint32_t>(time(NULL)));
|
|
}
|
|
|
|
void MySQLDatabase::SetCharacterName(const LWOOBJID characterId, const std::string_view name) {
|
|
ExecuteUpdate("UPDATE charinfo SET name = ?, pending_name = '', needs_rename = 0, last_login = ? WHERE id = ? LIMIT 1;", name, static_cast<uint32_t>(time(NULL)), characterId);
|
|
}
|
|
|
|
void MySQLDatabase::SetPendingCharacterName(const LWOOBJID characterId, const std::string_view name) {
|
|
ExecuteUpdate("UPDATE charinfo SET pending_name = ?, needs_rename = 0, last_login = ? WHERE id = ? LIMIT 1", name, static_cast<uint32_t>(time(NULL)), characterId);
|
|
}
|
|
|
|
void MySQLDatabase::UpdateLastLoggedInCharacter(const LWOOBJID characterId) {
|
|
ExecuteUpdate("UPDATE charinfo SET last_login = ? WHERE id = ? LIMIT 1", static_cast<uint32_t>(time(NULL)), characterId);
|
|
}
|
|
|
|
bool MySQLDatabase::IsNameInUse(const std::string_view name) {
|
|
auto result = ExecuteSelect("SELECT name FROM charinfo WHERE name = ? or pending_name = ? LIMIT 1;", name, name);
|
|
|
|
return result->next();
|
|
}
|