mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-05 10:14:06 +00:00
refactor: Database abstraction and organization of files (#1274)
* Database: Convert to proper namespace * Database: Use base class and getter * Database: Move files around * Database: Add property Management query Database: Move over user queries Tested at gm 0 that pre-approved names are pre-approved, unapproved need moderator approval deleting characters deletes the selcted one refreshing the character page shows the last character you logged in as tested all my characters show up when i login tested that you can delete all 4 characters and the correct character is selected each time tested renaming, approving names as gm0 Database: Add ugc model getter Hey it works, look I got around the mariadb issue. Database: Add queries Database: consolidate name query Database: Add friends list query Update name of approved names query Documentation Database: Add name check Database: Add BFF Query Database: Move BFF Setter Database: Move new friend query Database: Add remove friend queries Database: Add activity log Database: Add ugc & prop content removal Database: Add model update Database: Add migration queries Database: Add character and xml queries Database: Add user queries Untested, but compiling code Need to test that new character names are properly assigned in the following scenarios gm 0 and pre-approved name gm 0 and unapproved name gm 9 and pre-approved name gm 9 and unapproved name Database: constify function arguments Database: Add pet queries * Database: Move property model queries Untested. Need to test placing a new model moving existing one removing ugc model placing ugc model moving ugc model(?) changing privacy option variously change description and name approve property can properly travel to property * Property: Move stale reference deletion * Database: Move performance update query * Database: Add bug report query * Database: Add cheat detection query * Database: Add mail send query * Untested code need to test mailing from slash command, from all users of SendMail, getting bbb of a property and sending messages to bffs * Update CDComponentsRegistryTable.h Database: Rename and add further comments Datavbase: Add comments Add some comments Build: Fix PCH directories Database: Fix time thanks apple Database: Fix compiler warnings Overload destructor Define specialty for time_t Use string instead of string_view for temp empty string Update CDTable.h Property: Update queries to use mapId Database: Reorganize Reorganize into CDClient folder and GameDatabase folder for clearer meanings and file structure Folders: Rename to GameDatabase MySQL: Remove MySQL Specifier from table Database: Move Tables to Interfaces Database: Reorder functions in header Database: Simplify property queries Database: Remove unused queries Remove extra query definitions as well Database: Consolidate User getters Database: Comment logs Update MySQLDatabase.cpp Database: Use generic code Playkey: Fix bad optional access Database: Move stuff around WorldServer: Update queries Ugc reduced by many scopes use new queries very fast tested that ugc still loads Database: Add auth queries I tested that only the correct password can sign into an account. Tested that disabled playkeys do not allow the user to play the game Database: Add donation query Database: add objectId queries Database: Add master queries Database: Fix mis-named function Database: Add slash command queries Mail: Fix itemId type CharFilter: Use new query ObjectID: Remove duplicate code SlashCommand: Update query with function Database: Add mail queries Ugc: Fix issues with saving models Resolve large scope blocks as well * Database: Add debug try catch rethrow macro * General fixes * fix play key not working * Further fixes --------- Co-authored-by: Aaron Kimbre <aronwk.aaron@gmail.com>
This commit is contained in:
@@ -25,104 +25,36 @@
|
||||
Character::Character(uint32_t id, User* parentUser) {
|
||||
//First load the name, etc:
|
||||
m_ID = id;
|
||||
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt(
|
||||
"SELECT name, pending_name, needs_rename, prop_clone_id, permission_map FROM charinfo WHERE id=? LIMIT 1;"
|
||||
);
|
||||
|
||||
stmt->setInt64(1, id);
|
||||
|
||||
sql::ResultSet* res = stmt->executeQuery();
|
||||
|
||||
while (res->next()) {
|
||||
m_Name = res->getString(1).c_str();
|
||||
m_UnapprovedName = res->getString(2).c_str();
|
||||
m_NameRejected = res->getBoolean(3);
|
||||
m_PropertyCloneID = res->getUInt(4);
|
||||
m_PermissionMap = static_cast<ePermissionMap>(res->getUInt64(5));
|
||||
}
|
||||
|
||||
delete res;
|
||||
delete stmt;
|
||||
|
||||
//Load the xmlData now:
|
||||
sql::PreparedStatement* xmlStmt = Database::CreatePreppedStmt(
|
||||
"SELECT xml_data FROM charxml WHERE id=? LIMIT 1;"
|
||||
);
|
||||
|
||||
xmlStmt->setInt64(1, id);
|
||||
|
||||
sql::ResultSet* xmlRes = xmlStmt->executeQuery();
|
||||
while (xmlRes->next()) {
|
||||
m_XMLData = xmlRes->getString(1).c_str();
|
||||
}
|
||||
|
||||
delete xmlRes;
|
||||
delete xmlStmt;
|
||||
|
||||
m_ZoneID = 0; //TEMP! Set back to 0 when done. This is so we can see loading screen progress for testing.
|
||||
m_ZoneInstanceID = 0; //These values don't really matter, these are only used on the char select screen and seem unused.
|
||||
m_ZoneCloneID = 0;
|
||||
|
||||
m_Doc = nullptr;
|
||||
|
||||
//Quickly and dirtly parse the xmlData to get the info we need:
|
||||
DoQuickXMLDataParse();
|
||||
|
||||
//Set our objectID:
|
||||
m_ObjectID = m_ID;
|
||||
GeneralUtils::SetBit(m_ObjectID, eObjectBits::CHARACTER);
|
||||
GeneralUtils::SetBit(m_ObjectID, eObjectBits::PERSISTENT);
|
||||
|
||||
m_ParentUser = parentUser;
|
||||
m_OurEntity = nullptr;
|
||||
m_BuildMode = false;
|
||||
m_Doc = nullptr;
|
||||
}
|
||||
|
||||
Character::~Character() {
|
||||
delete m_Doc;
|
||||
if (m_Doc) delete m_Doc;
|
||||
m_Doc = nullptr;
|
||||
m_OurEntity = nullptr;
|
||||
m_ParentUser = nullptr;
|
||||
}
|
||||
|
||||
void Character::UpdateFromDatabase() {
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt(
|
||||
"SELECT name, pending_name, needs_rename, prop_clone_id, permission_map FROM charinfo WHERE id=? LIMIT 1;"
|
||||
);
|
||||
void Character::UpdateInfoFromDatabase() {
|
||||
auto charInfo = Database::Get()->GetCharacterInfo(m_ID);
|
||||
|
||||
stmt->setInt64(1, m_ID);
|
||||
|
||||
sql::ResultSet* res = stmt->executeQuery();
|
||||
|
||||
while (res->next()) {
|
||||
m_Name = res->getString(1).c_str();
|
||||
m_UnapprovedName = res->getString(2).c_str();
|
||||
m_NameRejected = res->getBoolean(3);
|
||||
m_PropertyCloneID = res->getUInt(4);
|
||||
m_PermissionMap = static_cast<ePermissionMap>(res->getUInt64(5));
|
||||
if (charInfo) {
|
||||
m_Name = charInfo->name;
|
||||
m_UnapprovedName = charInfo->pendingName;
|
||||
m_NameRejected = charInfo->needsRename;
|
||||
m_PropertyCloneID = charInfo->cloneId;
|
||||
m_PermissionMap = charInfo->permissionMap;
|
||||
}
|
||||
|
||||
delete res;
|
||||
delete stmt;
|
||||
|
||||
//Load the xmlData now:
|
||||
sql::PreparedStatement* xmlStmt = Database::CreatePreppedStmt(
|
||||
"SELECT xml_data FROM charxml WHERE id=? LIMIT 1;"
|
||||
);
|
||||
xmlStmt->setInt64(1, m_ID);
|
||||
|
||||
sql::ResultSet* xmlRes = xmlStmt->executeQuery();
|
||||
while (xmlRes->next()) {
|
||||
m_XMLData = xmlRes->getString(1).c_str();
|
||||
}
|
||||
|
||||
delete xmlRes;
|
||||
delete xmlStmt;
|
||||
m_XMLData = Database::Get()->GetCharacterXml(m_ID);
|
||||
|
||||
m_ZoneID = 0; //TEMP! Set back to 0 when done. This is so we can see loading screen progress for testing.
|
||||
m_ZoneInstanceID = 0; //These values don't really matter, these are only used on the char select screen and seem unused.
|
||||
m_ZoneCloneID = 0;
|
||||
|
||||
delete m_Doc;
|
||||
m_Doc = nullptr;
|
||||
|
||||
//Quickly and dirtly parse the xmlData to get the info we need:
|
||||
@@ -137,6 +69,11 @@ void Character::UpdateFromDatabase() {
|
||||
m_BuildMode = false;
|
||||
}
|
||||
|
||||
void Character::UpdateFromDatabase() {
|
||||
if (m_Doc) delete m_Doc;
|
||||
UpdateInfoFromDatabase();
|
||||
}
|
||||
|
||||
void Character::DoQuickXMLDataParse() {
|
||||
if (m_XMLData.size() == 0) return;
|
||||
|
||||
@@ -406,17 +343,11 @@ void Character::SetIsNewLogin() {
|
||||
|
||||
void Character::WriteToDatabase() {
|
||||
//Dump our xml into m_XMLData:
|
||||
auto* printer = new tinyxml2::XMLPrinter(0, true, 0);
|
||||
m_Doc->Print(printer);
|
||||
m_XMLData = printer->CStr();
|
||||
tinyxml2::XMLPrinter printer(0, true, 0);
|
||||
m_Doc->Print(&printer);
|
||||
|
||||
//Finally, save to db:
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt("UPDATE charxml SET xml_data=? WHERE id=?");
|
||||
stmt->setString(1, m_XMLData.c_str());
|
||||
stmt->setUInt(2, m_ID);
|
||||
stmt->execute();
|
||||
delete stmt;
|
||||
delete printer;
|
||||
Database::Get()->UpdateCharacterXml(m_ID, printer.CStr());
|
||||
}
|
||||
|
||||
void Character::SetPlayerFlag(const uint32_t flagId, const bool value) {
|
||||
|
@@ -458,6 +458,7 @@ public:
|
||||
void SetBillboardVisible(bool visible);
|
||||
|
||||
private:
|
||||
void UpdateInfoFromDatabase();
|
||||
/**
|
||||
* The ID of this character. First 32 bits of the ObjectID.
|
||||
*/
|
||||
|
@@ -237,7 +237,7 @@ void Leaderboard::SetupLeaderboard(bool weekly, uint32_t resultStart, uint32_t r
|
||||
}
|
||||
baseLookup += " LIMIT 1";
|
||||
LOG_DEBUG("query is %s", baseLookup.c_str());
|
||||
std::unique_ptr<sql::PreparedStatement> baseQuery(Database::CreatePreppedStmt(baseLookup));
|
||||
std::unique_ptr<sql::PreparedStatement> baseQuery(Database::Get()->CreatePreppedStmt(baseLookup));
|
||||
baseQuery->setInt(1, this->gameID);
|
||||
std::unique_ptr<sql::ResultSet> baseResult(baseQuery->executeQuery());
|
||||
|
||||
@@ -250,7 +250,7 @@ void Leaderboard::SetupLeaderboard(bool weekly, uint32_t resultStart, uint32_t r
|
||||
std::unique_ptr<char[]> lookupBuffer = std::make_unique<char[]>(STRING_LENGTH);
|
||||
int32_t res = snprintf(lookupBuffer.get(), STRING_LENGTH, queryBase.c_str(), orderBase.data(), filter.c_str(), resultStart, resultEnd);
|
||||
DluAssert(res != -1);
|
||||
std::unique_ptr<sql::PreparedStatement> query(Database::CreatePreppedStmt(lookupBuffer.get()));
|
||||
std::unique_ptr<sql::PreparedStatement> query(Database::Get()->CreatePreppedStmt(lookupBuffer.get()));
|
||||
LOG_DEBUG("Query is %s vars are %i %i %i", lookupBuffer.get(), this->gameID, this->relatedPlayer, relatedPlayerLeaderboardId);
|
||||
query->setInt(1, this->gameID);
|
||||
if (this->infoType == InfoType::Friends) {
|
||||
@@ -301,7 +301,7 @@ std::string FormatInsert(const Leaderboard::Type& type, const Score& score, cons
|
||||
void LeaderboardManager::SaveScore(const LWOOBJID& playerID, const GameID activityId, const float primaryScore, const float secondaryScore, const float tertiaryScore) {
|
||||
const Leaderboard::Type leaderboardType = GetLeaderboardType(activityId);
|
||||
|
||||
std::unique_ptr<sql::PreparedStatement> query(Database::CreatePreppedStmt("SELECT * FROM leaderboard WHERE character_id = ? AND game_id = ?;"));
|
||||
std::unique_ptr<sql::PreparedStatement> query(Database::Get()->CreatePreppedStmt("SELECT * FROM leaderboard WHERE character_id = ? AND game_id = ?;"));
|
||||
query->setInt(1, playerID);
|
||||
query->setInt(2, activityId);
|
||||
std::unique_ptr<sql::ResultSet> myScoreResult(query->executeQuery());
|
||||
@@ -378,14 +378,14 @@ void LeaderboardManager::SaveScore(const LWOOBJID& playerID, const GameID activi
|
||||
saveQuery = FormatInsert(leaderboardType, newScore, false);
|
||||
}
|
||||
LOG("save query %s %i %i", saveQuery.c_str(), playerID, activityId);
|
||||
std::unique_ptr<sql::PreparedStatement> saveStatement(Database::CreatePreppedStmt(saveQuery));
|
||||
std::unique_ptr<sql::PreparedStatement> saveStatement(Database::Get()->CreatePreppedStmt(saveQuery));
|
||||
saveStatement->setInt(1, playerID);
|
||||
saveStatement->setInt(2, activityId);
|
||||
saveStatement->execute();
|
||||
|
||||
// track wins separately
|
||||
if (leaderboardType == Leaderboard::Type::Racing && tertiaryScore != 0.0f) {
|
||||
std::unique_ptr<sql::PreparedStatement> winUpdate(Database::CreatePreppedStmt("UPDATE leaderboard SET numWins = numWins + 1 WHERE character_id = ? AND game_id = ?;"));
|
||||
std::unique_ptr<sql::PreparedStatement> winUpdate(Database::Get()->CreatePreppedStmt("UPDATE leaderboard SET numWins = numWins + 1 WHERE character_id = ? AND game_id = ?;"));
|
||||
winUpdate->setInt(1, playerID);
|
||||
winUpdate->setInt(2, activityId);
|
||||
winUpdate->execute();
|
||||
|
@@ -23,41 +23,23 @@ User::User(const SystemAddress& sysAddr, const std::string& username, const std:
|
||||
|
||||
m_IsBestFriendMap = std::unordered_map<std::string, bool>();
|
||||
|
||||
//HACK HACK HACK
|
||||
//This needs to be re-enabled / updated whenever the mute stuff is moved to another table.
|
||||
//This was only done because otherwise the website's account page dies and the website is waiting on a migration to wordpress.
|
||||
|
||||
//sql::PreparedStatement* stmt = Database::CreatePreppedStmt("SELECT id, gmlevel, mute_expire FROM accounts WHERE name=? LIMIT 1;");
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt("SELECT id, gm_level FROM accounts WHERE name=? LIMIT 1;");
|
||||
stmt->setString(1, username.c_str());
|
||||
|
||||
sql::ResultSet* res = stmt->executeQuery();
|
||||
while (res->next()) {
|
||||
m_AccountID = res->getUInt(1);
|
||||
m_MaxGMLevel = static_cast<eGameMasterLevel>(res->getInt(2));
|
||||
auto userInfo = Database::Get()->GetAccountInfo(username);
|
||||
if (userInfo) {
|
||||
m_AccountID = userInfo->id;
|
||||
m_MaxGMLevel = userInfo->maxGmLevel;
|
||||
m_MuteExpire = 0; //res->getUInt64(3);
|
||||
}
|
||||
|
||||
delete res;
|
||||
delete stmt;
|
||||
|
||||
//If we're loading a zone, we'll load the last used (aka current) character:
|
||||
if (Game::server->GetZoneID() != 0) {
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt("SELECT id FROM charinfo WHERE account_id=? ORDER BY last_login DESC LIMIT 1;");
|
||||
stmt->setUInt(1, m_AccountID);
|
||||
|
||||
sql::ResultSet* res = stmt->executeQuery();
|
||||
if (res->rowsCount() > 0) {
|
||||
while (res->next()) {
|
||||
LWOOBJID objID = res->getUInt64(1);
|
||||
Character* character = new Character(uint32_t(objID), this);
|
||||
m_Characters.push_back(character);
|
||||
LOG("Loaded %llu as it is the last used char", objID);
|
||||
}
|
||||
auto characterList = Database::Get()->GetAccountCharacterIds(m_AccountID);
|
||||
if (!characterList.empty()) {
|
||||
const uint32_t lastUsedCharacterId = characterList.front();
|
||||
Character* character = new Character(lastUsedCharacterId, this);
|
||||
character->UpdateFromDatabase();
|
||||
m_Characters.push_back(character);
|
||||
LOG("Loaded %i as it is the last used char", lastUsedCharacterId);
|
||||
}
|
||||
|
||||
delete res;
|
||||
delete stmt;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,10 +74,7 @@ User& User::operator= (const User& other) {
|
||||
}
|
||||
|
||||
bool User::operator== (const User& other) const {
|
||||
if (m_Username == other.m_Username || m_SessionKey == other.m_SessionKey || m_SystemAddress == other.m_SystemAddress)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
return m_Username == other.m_Username || m_SessionKey == other.m_SessionKey || m_SystemAddress == other.m_SystemAddress;
|
||||
}
|
||||
|
||||
Character* User::GetLastUsedChar() {
|
||||
|
@@ -158,20 +158,6 @@ void UserManager::DeletePendingRemovals() {
|
||||
m_UsersToDelete.clear();
|
||||
}
|
||||
|
||||
bool UserManager::IsNameAvailable(const std::string& requestedName) {
|
||||
bool toReturn = false; //To allow for a clean exit
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt("SELECT id FROM charinfo WHERE name=? OR pending_name=? LIMIT 1;");
|
||||
stmt->setString(1, requestedName.c_str());
|
||||
stmt->setString(2, requestedName.c_str());
|
||||
|
||||
sql::ResultSet* res = stmt->executeQuery();
|
||||
if (res->rowsCount() == 0) toReturn = true;
|
||||
|
||||
delete stmt;
|
||||
delete res;
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
std::string UserManager::GetPredefinedName(uint32_t firstNameIndex, uint32_t middleNameIndex, uint32_t lastNameIndex) {
|
||||
if (firstNameIndex > m_FirstNames.size() || middleNameIndex > m_MiddleNames.size() || lastNameIndex > m_LastNames.size()) return std::string("INVALID");
|
||||
return std::string(m_FirstNames[firstNameIndex] + m_MiddleNames[middleNameIndex] + m_LastNames[lastNameIndex]);
|
||||
@@ -200,11 +186,6 @@ bool UserManager::IsNamePreapproved(const std::string& requestedName) {
|
||||
void UserManager::RequestCharacterList(const SystemAddress& sysAddr) {
|
||||
User* u = GetUser(sysAddr);
|
||||
if (!u) return;
|
||||
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt("SELECT id FROM charinfo WHERE account_id=? ORDER BY last_login DESC LIMIT 4;");
|
||||
stmt->setUInt(1, u->GetAccountID());
|
||||
|
||||
sql::ResultSet* res = stmt->executeQuery();
|
||||
std::vector<Character*>& chars = u->GetCharacters();
|
||||
|
||||
for (size_t i = 0; i < chars.size(); ++i) {
|
||||
@@ -232,16 +213,13 @@ void UserManager::RequestCharacterList(const SystemAddress& sysAddr) {
|
||||
|
||||
chars.clear();
|
||||
|
||||
while (res->next()) {
|
||||
LWOOBJID objID = res->getUInt64(1);
|
||||
Character* character = new Character(uint32_t(objID), u);
|
||||
for (const auto& characterId : Database::Get()->GetAccountCharacterIds(u->GetAccountID())) {
|
||||
Character* character = new Character(characterId, u);
|
||||
character->UpdateFromDatabase();
|
||||
character->SetIsNewLogin();
|
||||
chars.push_back(character);
|
||||
}
|
||||
|
||||
delete res;
|
||||
delete stmt;
|
||||
|
||||
WorldPackets::SendCharacterList(sysAddr, u);
|
||||
}
|
||||
|
||||
@@ -270,19 +248,19 @@ void UserManager::CreateCharacter(const SystemAddress& sysAddr, Packet* packet)
|
||||
LOT shirtLOT = FindCharShirtID(shirtColor, shirtStyle);
|
||||
LOT pantsLOT = FindCharPantsID(pantsColor);
|
||||
|
||||
if (name != "" && !UserManager::IsNameAvailable(name)) {
|
||||
if (!name.empty() && Database::Get()->GetCharacterInfo(name)) {
|
||||
LOG("AccountID: %i chose unavailable name: %s", u->GetAccountID(), name.c_str());
|
||||
WorldPackets::SendCharacterCreationResponse(sysAddr, eCharacterCreationResponse::CUSTOM_NAME_IN_USE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!IsNameAvailable(predefinedName)) {
|
||||
if (Database::Get()->GetCharacterInfo(predefinedName)) {
|
||||
LOG("AccountID: %i chose unavailable predefined name: %s", u->GetAccountID(), predefinedName.c_str());
|
||||
WorldPackets::SendCharacterCreationResponse(sysAddr, eCharacterCreationResponse::PREDEFINED_NAME_IN_USE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (name == "") {
|
||||
if (name.empty()) {
|
||||
LOG("AccountID: %i is creating a character with predefined name: %s", u->GetAccountID(), predefinedName.c_str());
|
||||
} else {
|
||||
LOG("AccountID: %i is creating a character with name: %s (temporary: %s)", u->GetAccountID(), name.c_str(), predefinedName.c_str());
|
||||
@@ -290,13 +268,8 @@ void UserManager::CreateCharacter(const SystemAddress& sysAddr, Packet* packet)
|
||||
|
||||
//Now that the name is ok, we can get an objectID from Master:
|
||||
ObjectIDManager::Instance()->RequestPersistentID([=](uint32_t objectID) {
|
||||
sql::PreparedStatement* overlapStmt = Database::CreatePreppedStmt("SELECT id FROM charinfo WHERE id = ?");
|
||||
overlapStmt->setUInt(1, objectID);
|
||||
|
||||
auto* overlapResult = overlapStmt->executeQuery();
|
||||
|
||||
if (overlapResult->next()) {
|
||||
LOG("Character object id unavailable, check objectidtracker!");
|
||||
if (Database::Get()->GetCharacterInfo(objectID)) {
|
||||
LOG("Character object id unavailable, check object_id_tracker!");
|
||||
WorldPackets::SendCharacterCreationResponse(sysAddr, eCharacterCreationResponse::OBJECT_ID_UNAVAILABLE);
|
||||
return;
|
||||
}
|
||||
@@ -337,41 +310,19 @@ void UserManager::CreateCharacter(const SystemAddress& sysAddr, Packet* packet)
|
||||
bool nameOk = IsNamePreapproved(name);
|
||||
if (!nameOk && u->GetMaxGMLevel() > eGameMasterLevel::FORUM_MODERATOR) nameOk = true;
|
||||
|
||||
if (name != "") {
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt("INSERT INTO `charinfo`(`id`, `account_id`, `name`, `pending_name`, `needs_rename`, `last_login`) VALUES (?,?,?,?,?,?)");
|
||||
stmt->setUInt(1, objectID);
|
||||
stmt->setUInt(2, u->GetAccountID());
|
||||
stmt->setString(3, predefinedName.c_str());
|
||||
stmt->setString(4, name.c_str());
|
||||
stmt->setBoolean(5, false);
|
||||
stmt->setUInt64(6, time(NULL));
|
||||
std::string_view nameToAssign = !name.empty() && nameOk ? name : predefinedName;
|
||||
std::string pendingName = !name.empty() && !nameOk ? name : "";
|
||||
|
||||
if (nameOk) {
|
||||
stmt->setString(3, name.c_str());
|
||||
stmt->setString(4, "");
|
||||
}
|
||||
ICharInfo::Info info;
|
||||
info.name = nameToAssign;
|
||||
info.pendingName = pendingName;
|
||||
info.id = objectID;
|
||||
info.accountId = u->GetAccountID();
|
||||
|
||||
stmt->execute();
|
||||
delete stmt;
|
||||
} else {
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt("INSERT INTO `charinfo`(`id`, `account_id`, `name`, `pending_name`, `needs_rename`, `last_login`) VALUES (?,?,?,?,?,?)");
|
||||
stmt->setUInt(1, objectID);
|
||||
stmt->setUInt(2, u->GetAccountID());
|
||||
stmt->setString(3, predefinedName.c_str());
|
||||
stmt->setString(4, "");
|
||||
stmt->setBoolean(5, false);
|
||||
stmt->setUInt64(6, time(NULL));
|
||||
|
||||
stmt->execute();
|
||||
delete stmt;
|
||||
}
|
||||
Database::Get()->InsertNewCharacter(info);
|
||||
|
||||
//Now finally insert our character xml:
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt("INSERT INTO `charxml`(`id`, `xml_data`) VALUES (?,?)");
|
||||
stmt->setUInt(1, objectID);
|
||||
stmt->setString(2, xml3.str().c_str());
|
||||
stmt->execute();
|
||||
delete stmt;
|
||||
Database::Get()->InsertCharacterXml(objectID, xml3.str());
|
||||
|
||||
WorldPackets::SendCharacterCreationResponse(sysAddr, eCharacterCreationResponse::SUCCESS);
|
||||
UserManager::RequestCharacterList(sysAddr);
|
||||
@@ -403,73 +354,12 @@ void UserManager::DeleteCharacter(const SystemAddress& sysAddr, Packet* packet)
|
||||
WorldPackets::SendCharacterDeleteResponse(sysAddr, false);
|
||||
} else {
|
||||
LOG("Deleting character %i", charID);
|
||||
{
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt("DELETE FROM charxml WHERE id=? LIMIT 1;");
|
||||
stmt->setUInt64(1, charID);
|
||||
stmt->execute();
|
||||
delete stmt;
|
||||
}
|
||||
{
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt("DELETE FROM command_log WHERE character_id=?;");
|
||||
stmt->setUInt64(1, charID);
|
||||
stmt->execute();
|
||||
delete stmt;
|
||||
}
|
||||
{
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt("DELETE FROM friends WHERE player_id=? OR friend_id=?;");
|
||||
stmt->setUInt(1, charID);
|
||||
stmt->setUInt(2, charID);
|
||||
stmt->execute();
|
||||
delete stmt;
|
||||
CBITSTREAM;
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::PLAYER_REMOVED_NOTIFICATION);
|
||||
bitStream.Write(objectID);
|
||||
Game::chatServer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE, 0, Game::chatSysAddr, false);
|
||||
}
|
||||
{
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt("DELETE FROM leaderboard WHERE character_id=?;");
|
||||
stmt->setUInt64(1, charID);
|
||||
stmt->execute();
|
||||
delete stmt;
|
||||
}
|
||||
{
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt(
|
||||
"DELETE FROM properties_contents WHERE property_id IN (SELECT id FROM properties WHERE owner_id=?);"
|
||||
);
|
||||
stmt->setUInt64(1, charID);
|
||||
stmt->execute();
|
||||
delete stmt;
|
||||
}
|
||||
{
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt("DELETE FROM properties WHERE owner_id=?;");
|
||||
stmt->setUInt64(1, charID);
|
||||
stmt->execute();
|
||||
delete stmt;
|
||||
}
|
||||
{
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt("DELETE FROM ugc WHERE character_id=?;");
|
||||
stmt->setUInt64(1, charID);
|
||||
stmt->execute();
|
||||
delete stmt;
|
||||
}
|
||||
{
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt("DELETE FROM activity_log WHERE character_id=?;");
|
||||
stmt->setUInt64(1, charID);
|
||||
stmt->execute();
|
||||
delete stmt;
|
||||
}
|
||||
{
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt("DELETE FROM mail WHERE receiver_id=?;");
|
||||
stmt->setUInt64(1, charID);
|
||||
stmt->execute();
|
||||
delete stmt;
|
||||
}
|
||||
{
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt("DELETE FROM charinfo WHERE id=? LIMIT 1;");
|
||||
stmt->setUInt64(1, charID);
|
||||
stmt->execute();
|
||||
delete stmt;
|
||||
}
|
||||
Database::Get()->DeleteCharacter(charID);
|
||||
|
||||
CBITSTREAM;
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::PLAYER_REMOVED_NOTIFICATION);
|
||||
bitStream.Write(objectID);
|
||||
Game::chatServer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE, 0, Game::chatSysAddr, false);
|
||||
|
||||
WorldPackets::SendCharacterDeleteResponse(sysAddr, true);
|
||||
}
|
||||
@@ -517,26 +407,14 @@ void UserManager::RenameCharacter(const SystemAddress& sysAddr, Packet* packet)
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsNameAvailable(newName)) {
|
||||
if (Database::Get()->GetCharacterInfo(newName)) {
|
||||
if (IsNamePreapproved(newName)) {
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt("UPDATE charinfo SET name=?, pending_name='', needs_rename=0, last_login=? WHERE id=? LIMIT 1");
|
||||
stmt->setString(1, newName);
|
||||
stmt->setUInt64(2, time(NULL));
|
||||
stmt->setUInt(3, character->GetID());
|
||||
stmt->execute();
|
||||
delete stmt;
|
||||
|
||||
Database::Get()->SetCharacterName(charID, newName);
|
||||
LOG("Character %s now known as %s", character->GetName().c_str(), newName.c_str());
|
||||
WorldPackets::SendCharacterRenameResponse(sysAddr, eRenameResponse::SUCCESS);
|
||||
UserManager::RequestCharacterList(sysAddr);
|
||||
} else {
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt("UPDATE charinfo SET pending_name=?, needs_rename=0, last_login=? WHERE id=? LIMIT 1");
|
||||
stmt->setString(1, newName);
|
||||
stmt->setUInt64(2, time(NULL));
|
||||
stmt->setUInt(3, character->GetID());
|
||||
stmt->execute();
|
||||
delete stmt;
|
||||
|
||||
Database::Get()->SetPendingCharacterName(charID, newName);
|
||||
LOG("Character %s has been renamed to %s and is pending approval by a moderator.", character->GetName().c_str(), newName.c_str());
|
||||
WorldPackets::SendCharacterRenameResponse(sysAddr, eRenameResponse::SUCCESS);
|
||||
UserManager::RequestCharacterList(sysAddr);
|
||||
@@ -566,11 +444,7 @@ void UserManager::LoginCharacter(const SystemAddress& sysAddr, uint32_t playerID
|
||||
}
|
||||
|
||||
if (hasCharacter && character) {
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt("UPDATE charinfo SET last_login=? WHERE id=? LIMIT 1");
|
||||
stmt->setUInt64(1, time(NULL));
|
||||
stmt->setUInt(2, playerID);
|
||||
stmt->execute();
|
||||
delete stmt;
|
||||
Database::Get()->UpdateLastLoggedInCharacter(playerID);
|
||||
|
||||
uint32_t zoneID = character->GetZoneID();
|
||||
if (zoneID == LWOZONEID_INVALID) zoneID = 1000; //Send char to VE
|
||||
|
@@ -28,7 +28,6 @@ public:
|
||||
bool DeleteUser(const SystemAddress& sysAddr); //Returns true on succesful deletion
|
||||
void DeletePendingRemovals();
|
||||
|
||||
bool IsNameAvailable(const std::string& requestedName);
|
||||
std::string GetPredefinedName(uint32_t firstNameIndex, uint32_t middleNameIndex, uint32_t lastNameIndex);
|
||||
bool IsNamePreapproved(const std::string& requestedName);
|
||||
|
||||
|
@@ -700,7 +700,7 @@ std::string CharacterComponent::StatisticsToString() const {
|
||||
}
|
||||
|
||||
uint64_t CharacterComponent::GetStatisticFromSplit(std::vector<std::string> split, uint32_t index) {
|
||||
return split.size() > index ? std::stoul(split.at(index)) : 0;
|
||||
return split.size() > index ? std::stoull(split.at(index)) : 0;
|
||||
}
|
||||
|
||||
ZoneStatistics& CharacterComponent::GetZoneStatisticsForMap(LWOMAPID mapID) {
|
||||
|
@@ -22,10 +22,8 @@ DonationVendorComponent::DonationVendorComponent(Entity* parent) : VendorCompone
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr<sql::PreparedStatement> query(Database::CreatePreppedStmt("SELECT SUM(primaryScore) as donation_total FROM leaderboard WHERE game_id = ?;"));
|
||||
query->setInt(1, m_ActivityId);
|
||||
std::unique_ptr<sql::ResultSet> donation_total(query->executeQuery());
|
||||
if (donation_total->next()) m_TotalDonated = donation_total->getInt("donation_total");
|
||||
auto donationTotal = Database::Get()->GetDonationTotal(m_ActivityId);
|
||||
if (donationTotal) m_TotalDonated = donationTotal.value();
|
||||
m_TotalRemaining = m_Goal - m_TotalDonated;
|
||||
m_PercentComplete = m_TotalDonated/static_cast<float>(m_Goal);
|
||||
}
|
||||
|
@@ -1097,37 +1097,18 @@ void PetComponent::SetPetNameForModeration(const std::string& petName) {
|
||||
approved = 2; //approved
|
||||
}
|
||||
|
||||
auto deleteStmt = Database::CreatePreppedStmt("DELETE FROM pet_names WHERE id = ? LIMIT 1;");
|
||||
deleteStmt->setUInt64(1, m_DatabaseId);
|
||||
|
||||
deleteStmt->execute();
|
||||
|
||||
delete deleteStmt;
|
||||
|
||||
//Save to db:
|
||||
auto stmt = Database::CreatePreppedStmt("INSERT INTO `pet_names` (`id`, `pet_name`, `approved`) VALUES (?, ?, ?);");
|
||||
stmt->setUInt64(1, m_DatabaseId);
|
||||
stmt->setString(2, petName);
|
||||
stmt->setInt(3, approved);
|
||||
stmt->execute();
|
||||
delete stmt;
|
||||
Database::Get()->SetPetNameModerationStatus(m_DatabaseId, IPetNames::Info{petName, approved});
|
||||
}
|
||||
|
||||
void PetComponent::LoadPetNameFromModeration() {
|
||||
auto stmt = Database::CreatePreppedStmt("SELECT pet_name, approved FROM pet_names WHERE id = ? LIMIT 1;");
|
||||
stmt->setUInt64(1, m_DatabaseId);
|
||||
|
||||
auto res = stmt->executeQuery();
|
||||
while (res->next()) {
|
||||
m_ModerationStatus = res->getInt(2);
|
||||
|
||||
auto petNameInfo = Database::Get()->GetPetNameInfo(m_DatabaseId);
|
||||
if (petNameInfo) {
|
||||
m_ModerationStatus = petNameInfo->approvalStatus;
|
||||
if (m_ModerationStatus == 2) {
|
||||
m_Name = res->getString(1);
|
||||
m_Name = petNameInfo->petName;
|
||||
}
|
||||
}
|
||||
|
||||
delete res;
|
||||
delete stmt;
|
||||
}
|
||||
|
||||
void PetComponent::SetPreconditions(std::string& preconditions) {
|
||||
|
@@ -103,7 +103,7 @@ std::string PropertyEntranceComponent::BuildQuery(Entity* entity, int32_t sortMe
|
||||
if (sortMethod == SORT_TYPE_FEATURED || sortMethod == SORT_TYPE_FRIENDS) {
|
||||
std::string friendsList = " AND p.owner_id IN (";
|
||||
|
||||
auto friendsListQuery = Database::CreatePreppedStmt("SELECT * FROM (SELECT CASE WHEN player_id = ? THEN friend_id WHEN friend_id = ? THEN player_id END AS requested_player FROM friends ) AS fr WHERE requested_player IS NOT NULL ORDER BY requested_player DESC;");
|
||||
auto friendsListQuery = Database::Get()->CreatePreppedStmt("SELECT * FROM (SELECT CASE WHEN player_id = ? THEN friend_id WHEN friend_id = ? THEN player_id END AS requested_player FROM friends ) AS fr WHERE requested_player IS NOT NULL ORDER BY requested_player DESC;");
|
||||
|
||||
friendsListQuery->setUInt(1, character->GetID());
|
||||
friendsListQuery->setUInt(2, character->GetID());
|
||||
@@ -147,7 +147,7 @@ void PropertyEntranceComponent::OnPropertyEntranceSync(Entity* entity, bool incl
|
||||
if (!character) return;
|
||||
|
||||
// Player property goes in index 1 of the vector. This is how the client expects it.
|
||||
auto playerPropertyLookup = Database::CreatePreppedStmt("SELECT * FROM properties WHERE owner_id = ? AND zone_id = ?");
|
||||
auto playerPropertyLookup = Database::Get()->CreatePreppedStmt("SELECT * FROM properties WHERE owner_id = ? AND zone_id = ?");
|
||||
|
||||
playerPropertyLookup->setInt(1, character->GetID());
|
||||
playerPropertyLookup->setInt(2, this->m_MapID);
|
||||
@@ -180,7 +180,7 @@ void PropertyEntranceComponent::OnPropertyEntranceSync(Entity* entity, bool incl
|
||||
|
||||
const auto query = BuildQuery(entity, sortMethod, character);
|
||||
|
||||
auto propertyLookup = Database::CreatePreppedStmt(query);
|
||||
auto propertyLookup = Database::Get()->CreatePreppedStmt(query);
|
||||
|
||||
const auto searchString = "%" + filterText + "%";
|
||||
propertyLookup->setUInt(1, this->m_MapID);
|
||||
@@ -209,7 +209,7 @@ void PropertyEntranceComponent::OnPropertyEntranceSync(Entity* entity, bool incl
|
||||
|
||||
std::string ownerName = "";
|
||||
bool isOwned = true;
|
||||
auto nameLookup = Database::CreatePreppedStmt("SELECT name FROM charinfo WHERE prop_clone_id = ?;");
|
||||
auto nameLookup = Database::Get()->CreatePreppedStmt("SELECT name FROM charinfo WHERE prop_clone_id = ?;");
|
||||
|
||||
nameLookup->setUInt64(1, cloneId);
|
||||
|
||||
@@ -245,7 +245,7 @@ void PropertyEntranceComponent::OnPropertyEntranceSync(Entity* entity, bool incl
|
||||
GeneralUtils::SetBit(ownerObjId, eObjectBits::PERSISTENT);
|
||||
|
||||
// Query to get friend and best friend fields
|
||||
auto friendCheck = Database::CreatePreppedStmt("SELECT best_friend FROM friends WHERE (player_id = ? AND friend_id = ?) OR (player_id = ? AND friend_id = ?)");
|
||||
auto friendCheck = Database::Get()->CreatePreppedStmt("SELECT best_friend FROM friends WHERE (player_id = ? AND friend_id = ?) OR (player_id = ? AND friend_id = ?)");
|
||||
|
||||
friendCheck->setUInt(1, character->GetID());
|
||||
friendCheck->setUInt(2, ownerObjId);
|
||||
@@ -278,7 +278,7 @@ void PropertyEntranceComponent::OnPropertyEntranceSync(Entity* entity, bool incl
|
||||
|
||||
bool isAlt = false;
|
||||
// Query to determine whether this property is an alt character of the entity.
|
||||
auto isAltQuery = Database::CreatePreppedStmt("SELECT id FROM charinfo where account_id in (SELECT account_id from charinfo WHERE id = ?) AND id = ?;");
|
||||
auto isAltQuery = Database::Get()->CreatePreppedStmt("SELECT id FROM charinfo where account_id in (SELECT account_id from charinfo WHERE id = ?) AND id = ?;");
|
||||
|
||||
isAltQuery->setInt(1, character->GetID());
|
||||
isAltQuery->setInt(2, owner);
|
||||
@@ -312,7 +312,7 @@ void PropertyEntranceComponent::OnPropertyEntranceSync(Entity* entity, bool incl
|
||||
int32_t numberOfProperties = 0;
|
||||
|
||||
auto buttonQuery = BuildQuery(entity, sortMethod, character, "SELECT COUNT(*) FROM properties as p JOIN charinfo as ci ON ci.prop_clone_id = p.clone_id where p.zone_id = ? AND (p.description LIKE ? OR p.name LIKE ? OR ci.name LIKE ?) AND p.privacy_option >= ? ", false);
|
||||
auto propertiesLeft = Database::CreatePreppedStmt(buttonQuery);
|
||||
auto propertiesLeft = Database::Get()->CreatePreppedStmt(buttonQuery);
|
||||
|
||||
propertiesLeft->setUInt(1, this->m_MapID);
|
||||
propertiesLeft->setString(2, searchString.c_str());
|
||||
|
@@ -39,13 +39,12 @@ PropertyManagementComponent::PropertyManagementComponent(Entity* parent) : Compo
|
||||
instance = this;
|
||||
|
||||
const auto& worldId = Game::zoneManager->GetZone()->GetZoneID();
|
||||
|
||||
const auto zoneId = worldId.GetMapID();
|
||||
const auto cloneId = worldId.GetCloneID();
|
||||
|
||||
auto query = CDClientDatabase::CreatePreppedStmt(
|
||||
"SELECT id FROM PropertyTemplate WHERE mapID = ?;");
|
||||
query.bind(1, (int)zoneId);
|
||||
auto query = CDClientDatabase::CreatePreppedStmt("SELECT id FROM PropertyTemplate WHERE mapID = ?;");
|
||||
|
||||
query.bind(1, static_cast<int32_t>(zoneId));
|
||||
|
||||
auto result = query.execQuery();
|
||||
|
||||
@@ -55,34 +54,25 @@ PropertyManagementComponent::PropertyManagementComponent(Entity* parent) : Compo
|
||||
|
||||
templateId = result.getIntField(0);
|
||||
|
||||
result.finalize();
|
||||
auto propertyInfo = Database::Get()->GetPropertyInfo(zoneId, cloneId);
|
||||
|
||||
auto* propertyLookup = Database::CreatePreppedStmt("SELECT * FROM properties WHERE template_id = ? AND clone_id = ?;");
|
||||
|
||||
propertyLookup->setInt(1, templateId);
|
||||
propertyLookup->setInt64(2, cloneId);
|
||||
|
||||
auto* propertyEntry = propertyLookup->executeQuery();
|
||||
|
||||
if (propertyEntry->next()) {
|
||||
this->propertyId = propertyEntry->getUInt64(1);
|
||||
this->owner = propertyEntry->getUInt64(2);
|
||||
if (propertyInfo) {
|
||||
this->propertyId = propertyInfo->id;
|
||||
this->owner = propertyInfo->ownerId;
|
||||
GeneralUtils::SetBit(this->owner, eObjectBits::CHARACTER);
|
||||
GeneralUtils::SetBit(this->owner, eObjectBits::PERSISTENT);
|
||||
this->clone_Id = propertyEntry->getInt(2);
|
||||
this->propertyName = propertyEntry->getString(5).c_str();
|
||||
this->propertyDescription = propertyEntry->getString(6).c_str();
|
||||
this->privacyOption = static_cast<PropertyPrivacyOption>(propertyEntry->getUInt(9));
|
||||
this->moderatorRequested = propertyEntry->getInt(10) == 0 && rejectionReason == "" && privacyOption == PropertyPrivacyOption::Public;
|
||||
this->LastUpdatedTime = propertyEntry->getUInt64(11);
|
||||
this->claimedTime = propertyEntry->getUInt64(12);
|
||||
this->rejectionReason = std::string(propertyEntry->getString(13).c_str());
|
||||
this->reputation = propertyEntry->getUInt(14);
|
||||
this->clone_Id = propertyInfo->cloneId;
|
||||
this->propertyName = propertyInfo->name;
|
||||
this->propertyDescription = propertyInfo->description;
|
||||
this->privacyOption = static_cast<PropertyPrivacyOption>(propertyInfo->privacyOption);
|
||||
this->rejectionReason = propertyInfo->rejectionReason;
|
||||
this->moderatorRequested = propertyInfo->modApproved == 0 && rejectionReason == "" && privacyOption == PropertyPrivacyOption::Public;
|
||||
this->LastUpdatedTime = propertyInfo->lastUpdatedTime;
|
||||
this->claimedTime = propertyInfo->claimedTime;
|
||||
this->reputation = propertyInfo->reputation;
|
||||
|
||||
Load();
|
||||
}
|
||||
|
||||
delete propertyLookup;
|
||||
}
|
||||
|
||||
LWOOBJID PropertyManagementComponent::GetOwnerId() const {
|
||||
@@ -152,14 +142,13 @@ void PropertyManagementComponent::SetPrivacyOption(PropertyPrivacyOption value)
|
||||
}
|
||||
privacyOption = value;
|
||||
|
||||
auto* propertyUpdate = Database::CreatePreppedStmt("UPDATE properties SET privacy_option = ?, rejection_reason = ?, mod_approved = ? WHERE id = ?;");
|
||||
IProperty::Info info;
|
||||
info.id = propertyId;
|
||||
info.privacyOption = static_cast<uint32_t>(privacyOption);
|
||||
info.rejectionReason = rejectionReason;
|
||||
info.modApproved = 0;
|
||||
|
||||
propertyUpdate->setInt(1, static_cast<int32_t>(value));
|
||||
propertyUpdate->setString(2, "");
|
||||
propertyUpdate->setInt(3, 0);
|
||||
propertyUpdate->setInt64(4, propertyId);
|
||||
|
||||
propertyUpdate->executeUpdate();
|
||||
Database::Get()->UpdatePropertyModerationInfo(info);
|
||||
}
|
||||
|
||||
void PropertyManagementComponent::UpdatePropertyDetails(std::string name, std::string description) {
|
||||
@@ -169,13 +158,12 @@ void PropertyManagementComponent::UpdatePropertyDetails(std::string name, std::s
|
||||
|
||||
propertyDescription = description;
|
||||
|
||||
auto* propertyUpdate = Database::CreatePreppedStmt("UPDATE properties SET name = ?, description = ? WHERE id = ?;");
|
||||
IProperty::Info info;
|
||||
info.id = propertyId;
|
||||
info.name = propertyName;
|
||||
info.description = propertyDescription;
|
||||
|
||||
propertyUpdate->setString(1, name.c_str());
|
||||
propertyUpdate->setString(2, description.c_str());
|
||||
propertyUpdate->setInt64(3, propertyId);
|
||||
|
||||
propertyUpdate->executeUpdate();
|
||||
Database::Get()->UpdatePropertyDetails(info);
|
||||
|
||||
OnQueryPropertyData(GetOwner(), UNASSIGNED_SYSTEM_ADDRESS);
|
||||
}
|
||||
@@ -217,28 +205,14 @@ bool PropertyManagementComponent::Claim(const LWOOBJID playerId) {
|
||||
|
||||
propertyId = ObjectIDManager::GenerateRandomObjectID();
|
||||
|
||||
auto* insertion = Database::CreatePreppedStmt(
|
||||
"INSERT INTO properties"
|
||||
"(id, owner_id, template_id, clone_id, name, description, rent_amount, rent_due, privacy_option, last_updated, time_claimed, rejection_reason, reputation, zone_id, performance_cost)"
|
||||
"VALUES (?, ?, ?, ?, ?, ?, 0, 0, 0, UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), '', 0, ?, 0.0)"
|
||||
);
|
||||
insertion->setUInt64(1, propertyId);
|
||||
insertion->setUInt64(2, (uint32_t)playerId);
|
||||
insertion->setUInt(3, templateId);
|
||||
insertion->setUInt64(4, playerCloneId);
|
||||
insertion->setString(5, name.c_str());
|
||||
insertion->setString(6, description.c_str());
|
||||
insertion->setInt(7, propertyZoneId);
|
||||
IProperty::Info info;
|
||||
info.id = propertyId;
|
||||
info.ownerId = character->GetID();
|
||||
info.cloneId = playerCloneId;
|
||||
info.name = name;
|
||||
info.description = description;
|
||||
|
||||
// Try and execute the query, print an error if it fails.
|
||||
try {
|
||||
insertion->execute();
|
||||
} catch (sql::SQLException& exception) {
|
||||
LOG("Failed to execute query: (%s)!", exception.what());
|
||||
|
||||
throw exception;
|
||||
return false;
|
||||
}
|
||||
Database::Get()->InsertNewProperty(info, templateId, worldId);
|
||||
|
||||
auto* zoneControlObject = Game::zoneManager->GetZoneControlObject();
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(zoneControlObject)) {
|
||||
@@ -545,7 +519,7 @@ void PropertyManagementComponent::DeleteModel(const LWOOBJID id, const int delet
|
||||
{
|
||||
item->SetCount(item->GetCount() - 1);
|
||||
|
||||
LOG("YES IT GOES HERE");
|
||||
LOG("BODGE TIME, YES IT GOES HERE");
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -569,14 +543,13 @@ void PropertyManagementComponent::DeleteModel(const LWOOBJID id, const int delet
|
||||
void PropertyManagementComponent::UpdateApprovedStatus(const bool value) {
|
||||
if (owner == LWOOBJID_EMPTY) return;
|
||||
|
||||
auto* update = Database::CreatePreppedStmt("UPDATE properties SET mod_approved = ? WHERE id = ?;");
|
||||
IProperty::Info info;
|
||||
info.id = propertyId;
|
||||
info.modApproved = value;
|
||||
info.privacyOption = static_cast<uint32_t>(privacyOption);
|
||||
info.rejectionReason = "";
|
||||
|
||||
update->setBoolean(1, value);
|
||||
update->setInt64(2, propertyId);
|
||||
|
||||
update->executeUpdate();
|
||||
|
||||
delete update;
|
||||
Database::Get()->UpdatePropertyModerationInfo(info);
|
||||
}
|
||||
|
||||
void PropertyManagementComponent::Load() {
|
||||
@@ -584,39 +557,17 @@ void PropertyManagementComponent::Load() {
|
||||
return;
|
||||
}
|
||||
|
||||
auto* lookup = Database::CreatePreppedStmt("SELECT id, lot, x, y, z, rx, ry, rz, rw, ugc_id FROM properties_contents WHERE property_id = ?;");
|
||||
|
||||
lookup->setUInt64(1, propertyId);
|
||||
|
||||
auto* lookupResult = lookup->executeQuery();
|
||||
|
||||
while (lookupResult->next()) {
|
||||
const LWOOBJID id = lookupResult->getUInt64(1);
|
||||
const LOT lot = lookupResult->getInt(2);
|
||||
|
||||
const NiPoint3 position =
|
||||
{
|
||||
static_cast<float>(lookupResult->getDouble(3)),
|
||||
static_cast<float>(lookupResult->getDouble(4)),
|
||||
static_cast<float>(lookupResult->getDouble(5))
|
||||
};
|
||||
|
||||
const NiQuaternion rotation =
|
||||
{
|
||||
static_cast<float>(lookupResult->getDouble(9)),
|
||||
static_cast<float>(lookupResult->getDouble(6)),
|
||||
static_cast<float>(lookupResult->getDouble(7)),
|
||||
static_cast<float>(lookupResult->getDouble(8))
|
||||
};
|
||||
auto propertyModels = Database::Get()->GetPropertyModels(propertyId);
|
||||
|
||||
for (const auto& databaseModel : propertyModels) {
|
||||
auto* node = new SpawnerNode();
|
||||
|
||||
node->position = position;
|
||||
node->rotation = rotation;
|
||||
node->position = databaseModel.position;
|
||||
node->rotation = databaseModel.rotation;
|
||||
|
||||
SpawnerInfo info{};
|
||||
|
||||
info.templateID = lot;
|
||||
info.templateID = databaseModel.lot;
|
||||
info.nodes = { node };
|
||||
info.templateScale = 1.0f;
|
||||
info.activeOnLoad = true;
|
||||
@@ -626,13 +577,13 @@ void PropertyManagementComponent::Load() {
|
||||
//info.emulated = true;
|
||||
//info.emulator = Game::entityManager->GetZoneControlEntity()->GetObjectID();
|
||||
|
||||
info.spawnerID = id;
|
||||
info.spawnerID = databaseModel.id;
|
||||
|
||||
std::vector<LDFBaseData*> settings;
|
||||
|
||||
//BBB property models need to have extra stuff set for them:
|
||||
if (lot == 14) {
|
||||
LWOOBJID blueprintID = lookupResult->getUInt(10);
|
||||
if (databaseModel.lot == 14) {
|
||||
LWOOBJID blueprintID = databaseModel.ugcId;
|
||||
GeneralUtils::SetBit(blueprintID, eObjectBits::CHARACTER);
|
||||
GeneralUtils::SetBit(blueprintID, eObjectBits::PERSISTENT);
|
||||
|
||||
@@ -640,7 +591,7 @@ void PropertyManagementComponent::Load() {
|
||||
LDFBaseData* componentWhitelist = new LDFData<int>(u"componentWhitelist", 1);
|
||||
LDFBaseData* modelType = new LDFData<int>(u"modelType", 2);
|
||||
LDFBaseData* propertyObjectID = new LDFData<bool>(u"propertyObjectID", true);
|
||||
LDFBaseData* userModelID = new LDFData<LWOOBJID>(u"userModelID", id);
|
||||
LDFBaseData* userModelID = new LDFData<LWOOBJID>(u"userModelID", databaseModel.id);
|
||||
|
||||
settings.push_back(ldfBlueprintID);
|
||||
settings.push_back(componentWhitelist);
|
||||
@@ -649,7 +600,7 @@ void PropertyManagementComponent::Load() {
|
||||
settings.push_back(userModelID);
|
||||
} else {
|
||||
auto modelType = new LDFData<int>(u"modelType", 2);
|
||||
auto userModelID = new LDFData<LWOOBJID>(u"userModelID", id);
|
||||
auto userModelID = new LDFData<LWOOBJID>(u"userModelID", databaseModel.id);
|
||||
auto ldfModelBehavior = new LDFData<LWOOBJID>(u"modelBehaviors", 0);
|
||||
auto propertyObjectID = new LDFData<bool>(u"propertyObjectID", true);
|
||||
auto componentWhitelist = new LDFData<int>(u"componentWhitelist", 1);
|
||||
@@ -671,8 +622,6 @@ void PropertyManagementComponent::Load() {
|
||||
|
||||
models.insert_or_assign(model->GetObjectID(), spawnerId);
|
||||
}
|
||||
|
||||
delete lookup;
|
||||
}
|
||||
|
||||
void PropertyManagementComponent::Save() {
|
||||
@@ -680,27 +629,7 @@ void PropertyManagementComponent::Save() {
|
||||
return;
|
||||
}
|
||||
|
||||
auto* insertion = Database::CreatePreppedStmt("INSERT INTO properties_contents VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);");
|
||||
auto* update = Database::CreatePreppedStmt("UPDATE properties_contents SET x = ?, y = ?, z = ?, rx = ?, ry = ?, rz = ?, rw = ? WHERE id = ?;");
|
||||
auto* lookup = Database::CreatePreppedStmt("SELECT id FROM properties_contents WHERE property_id = ?;");
|
||||
auto* remove = Database::CreatePreppedStmt("DELETE FROM properties_contents WHERE id = ?;");
|
||||
|
||||
lookup->setUInt64(1, propertyId);
|
||||
sql::ResultSet* lookupResult = nullptr;
|
||||
try {
|
||||
lookupResult = lookup->executeQuery();
|
||||
} catch (sql::SQLException& ex) {
|
||||
LOG("lookup error %s", ex.what());
|
||||
}
|
||||
std::vector<LWOOBJID> present;
|
||||
|
||||
while (lookupResult->next()) {
|
||||
const auto dbId = lookupResult->getUInt64(1);
|
||||
|
||||
present.push_back(dbId);
|
||||
}
|
||||
|
||||
delete lookupResult;
|
||||
auto present = Database::Get()->GetPropertyModels(propertyId);
|
||||
|
||||
std::vector<LWOOBJID> modelIds;
|
||||
|
||||
@@ -719,69 +648,26 @@ void PropertyManagementComponent::Save() {
|
||||
const auto rotation = entity->GetRotation();
|
||||
|
||||
if (std::find(present.begin(), present.end(), id) == present.end()) {
|
||||
insertion->setInt64(1, id);
|
||||
insertion->setUInt64(2, propertyId);
|
||||
insertion->setNull(3, 0);
|
||||
insertion->setInt(4, entity->GetLOT());
|
||||
insertion->setDouble(5, position.x);
|
||||
insertion->setDouble(6, position.y);
|
||||
insertion->setDouble(7, position.z);
|
||||
insertion->setDouble(8, rotation.x);
|
||||
insertion->setDouble(9, rotation.y);
|
||||
insertion->setDouble(10, rotation.z);
|
||||
insertion->setDouble(11, rotation.w);
|
||||
insertion->setString(12, ("Objects_" + std::to_string(entity->GetLOT()) + "_name").c_str()); // Model name. TODO make this customizable
|
||||
insertion->setString(13, ""); // Model description. TODO implement this.
|
||||
insertion->setDouble(14, 0); // behavior 1. TODO implement this.
|
||||
insertion->setDouble(15, 0); // behavior 2. TODO implement this.
|
||||
insertion->setDouble(16, 0); // behavior 3. TODO implement this.
|
||||
insertion->setDouble(17, 0); // behavior 4. TODO implement this.
|
||||
insertion->setDouble(18, 0); // behavior 5. TODO implement this.
|
||||
try {
|
||||
insertion->execute();
|
||||
} catch (sql::SQLException& ex) {
|
||||
LOG("Error inserting into properties_contents. Error %s", ex.what());
|
||||
}
|
||||
} else {
|
||||
update->setDouble(1, position.x);
|
||||
update->setDouble(2, position.y);
|
||||
update->setDouble(3, position.z);
|
||||
update->setDouble(4, rotation.x);
|
||||
update->setDouble(5, rotation.y);
|
||||
update->setDouble(6, rotation.z);
|
||||
update->setDouble(7, rotation.w);
|
||||
IPropertyContents::Model model;
|
||||
model.id = id;
|
||||
model.lot = entity->GetLOT();
|
||||
model.position = position;
|
||||
model.rotation = rotation;
|
||||
model.ugcId = 0;
|
||||
|
||||
update->setInt64(8, id);
|
||||
try {
|
||||
update->executeUpdate();
|
||||
} catch (sql::SQLException& ex) {
|
||||
LOG("Error updating properties_contents. Error: %s", ex.what());
|
||||
}
|
||||
Database::Get()->InsertNewPropertyModel(propertyId, model, "Objects_" + std::to_string(model.lot) + "_name");
|
||||
} else {
|
||||
Database::Get()->UpdateModelPositionRotation(id, position, rotation);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto id : present) {
|
||||
if (std::find(modelIds.begin(), modelIds.end(), id) != modelIds.end()) {
|
||||
for (auto model : present) {
|
||||
if (std::find(modelIds.begin(), modelIds.end(), model.id) != modelIds.end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
remove->setInt64(1, id);
|
||||
try {
|
||||
remove->execute();
|
||||
} catch (sql::SQLException& ex) {
|
||||
LOG("Error removing from properties_contents. Error %s", ex.what());
|
||||
}
|
||||
Database::Get()->RemoveModel(model.id);
|
||||
}
|
||||
|
||||
auto* removeUGC = Database::CreatePreppedStmt("DELETE FROM ugc WHERE id NOT IN (SELECT ugc_id FROM properties_contents);");
|
||||
|
||||
removeUGC->execute();
|
||||
|
||||
delete removeUGC;
|
||||
delete insertion;
|
||||
delete update;
|
||||
delete lookup;
|
||||
delete remove;
|
||||
}
|
||||
|
||||
void PropertyManagementComponent::AddModel(LWOOBJID modelId, LWOOBJID spawnerId) {
|
||||
@@ -799,6 +685,7 @@ void PropertyManagementComponent::OnQueryPropertyData(Entity* originator, const
|
||||
|
||||
const auto& worldId = Game::zoneManager->GetZone()->GetZoneID();
|
||||
const auto zoneId = worldId.GetMapID();
|
||||
const auto cloneId = worldId.GetCloneID();
|
||||
|
||||
LOG("Getting property info for %d", zoneId);
|
||||
GameMessages::PropertyDataMessage message = GameMessages::PropertyDataMessage(zoneId);
|
||||
@@ -806,45 +693,25 @@ void PropertyManagementComponent::OnQueryPropertyData(Entity* originator, const
|
||||
const auto isClaimed = GetOwnerId() != LWOOBJID_EMPTY;
|
||||
|
||||
LWOOBJID ownerId = GetOwnerId();
|
||||
std::string ownerName = "";
|
||||
std::string ownerName;
|
||||
auto charInfo = Database::Get()->GetCharacterInfo(ownerId);
|
||||
if (charInfo) ownerName = charInfo->name;
|
||||
std::string name = "";
|
||||
std::string description = "";
|
||||
uint64_t claimed = 0;
|
||||
char privacy = 0;
|
||||
|
||||
if (isClaimed) {
|
||||
const auto cloneId = worldId.GetCloneID();
|
||||
|
||||
auto* nameLookup = Database::CreatePreppedStmt("SELECT name FROM charinfo WHERE prop_clone_id = ?;");
|
||||
nameLookup->setUInt64(1, cloneId);
|
||||
|
||||
auto* nameResult = nameLookup->executeQuery();
|
||||
if (nameResult->next()) {
|
||||
ownerName = nameResult->getString(1).c_str();
|
||||
}
|
||||
|
||||
delete nameResult;
|
||||
delete nameLookup;
|
||||
|
||||
name = propertyName;
|
||||
description = propertyDescription;
|
||||
claimed = claimedTime;
|
||||
privacy = static_cast<char>(this->privacyOption);
|
||||
if (moderatorRequested) {
|
||||
auto checkStatus = Database::CreatePreppedStmt("SELECT rejection_reason, mod_approved FROM properties WHERE id = ?;");
|
||||
|
||||
checkStatus->setInt64(1, propertyId);
|
||||
|
||||
auto result = checkStatus->executeQuery();
|
||||
|
||||
result->next();
|
||||
|
||||
const auto reason = std::string(result->getString(1).c_str());
|
||||
const auto modApproved = result->getInt(2);
|
||||
if (reason != "") {
|
||||
auto moderationInfo = Database::Get()->GetPropertyInfo(zoneId, cloneId);
|
||||
if (moderationInfo->rejectionReason != "") {
|
||||
moderatorRequested = false;
|
||||
rejectionReason = reason;
|
||||
} else if (reason == "" && modApproved == 1) {
|
||||
rejectionReason = moderationInfo->rejectionReason;
|
||||
} else if (moderationInfo->rejectionReason == "" && moderationInfo->modApproved == 1) {
|
||||
moderatorRequested = false;
|
||||
rejectionReason = "";
|
||||
} else {
|
||||
|
@@ -18,7 +18,7 @@
|
||||
#include "Game.h"
|
||||
#include "Logger.h"
|
||||
#include "GameMessages.h"
|
||||
#include "../dDatabase/CDClientDatabase.h"
|
||||
#include "CDClientDatabase.h"
|
||||
|
||||
enum class eGameMessageType : uint16_t;
|
||||
|
||||
|
@@ -2577,70 +2577,23 @@ void GameMessages::HandleBBBSaveRequest(RakNet::BitStream* inStream, Entity* ent
|
||||
const auto zoneId = worldId.GetMapID();
|
||||
const auto cloneId = worldId.GetCloneID();
|
||||
|
||||
auto query = CDClientDatabase::CreatePreppedStmt(
|
||||
"SELECT id FROM PropertyTemplate WHERE mapID = ?;");
|
||||
query.bind(1, (int)zoneId);
|
||||
|
||||
auto result = query.execQuery();
|
||||
|
||||
if (result.eof() || result.fieldIsNull(0)) return;
|
||||
|
||||
int templateId = result.getIntField(0);
|
||||
|
||||
auto* propertyLookup = Database::CreatePreppedStmt("SELECT * FROM properties WHERE template_id = ? AND clone_id = ?;");
|
||||
|
||||
propertyLookup->setInt(1, templateId);
|
||||
propertyLookup->setInt64(2, cloneId);
|
||||
|
||||
auto* propertyEntry = propertyLookup->executeQuery();
|
||||
uint64_t propertyId = 0;
|
||||
|
||||
if (propertyEntry->next()) {
|
||||
propertyId = propertyEntry->getUInt64(1);
|
||||
}
|
||||
|
||||
delete propertyEntry;
|
||||
delete propertyLookup;
|
||||
auto propertyInfo = Database::Get()->GetPropertyInfo(zoneId, cloneId);
|
||||
LWOOBJID propertyId = LWOOBJID_EMPTY;
|
||||
if (propertyInfo) propertyId = propertyInfo->id;
|
||||
|
||||
//Insert into ugc:
|
||||
auto ugcs = Database::CreatePreppedStmt("INSERT INTO `ugc`(`id`, `account_id`, `character_id`, `is_optimized`, `lxfml`, `bake_ao`, `filename`) VALUES (?,?,?,?,?,?,?)");
|
||||
ugcs->setUInt(1, blueprintIDSmall);
|
||||
ugcs->setInt(2, entity->GetParentUser()->GetAccountID());
|
||||
ugcs->setInt(3, entity->GetCharacter()->GetID());
|
||||
ugcs->setInt(4, 0);
|
||||
|
||||
//whacky stream biz
|
||||
std::string s(sd0Data.get(), sd0Size);
|
||||
std::istringstream iss(s);
|
||||
|
||||
ugcs->setBlob(5, &iss);
|
||||
ugcs->setBoolean(6, false);
|
||||
ugcs->setString(7, "weedeater.lxfml");
|
||||
ugcs->execute();
|
||||
delete ugcs;
|
||||
std::string str(sd0Data.get(), sd0Size);
|
||||
std::istringstream sd0DataStream(str);
|
||||
Database::Get()->InsertNewUgcModel(sd0DataStream, blueprintIDSmall, entity->GetParentUser()->GetAccountID(), entity->GetCharacter()->GetID());
|
||||
|
||||
//Insert into the db as a BBB model:
|
||||
auto* stmt = Database::CreatePreppedStmt("INSERT INTO `properties_contents` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
|
||||
stmt->setUInt64(1, newIDL);
|
||||
stmt->setUInt64(2, propertyId);
|
||||
stmt->setUInt(3, blueprintIDSmall);
|
||||
stmt->setUInt(4, 14); // 14 is the lot the BBB models use
|
||||
stmt->setDouble(5, 0.0f); // x
|
||||
stmt->setDouble(6, 0.0f); // y
|
||||
stmt->setDouble(7, 0.0f); // z
|
||||
stmt->setDouble(8, 0.0f); // rx
|
||||
stmt->setDouble(9, 0.0f); // ry
|
||||
stmt->setDouble(10, 0.0f); // rz
|
||||
stmt->setDouble(11, 0.0f); // rw
|
||||
stmt->setString(12, "Objects_14_name"); // Model name. TODO make this customizable
|
||||
stmt->setString(13, ""); // Model description. TODO implement this.
|
||||
stmt->setDouble(14, 0); // behavior 1. TODO implement this.
|
||||
stmt->setDouble(15, 0); // behavior 2. TODO implement this.
|
||||
stmt->setDouble(16, 0); // behavior 3. TODO implement this.
|
||||
stmt->setDouble(17, 0); // behavior 4. TODO implement this.
|
||||
stmt->setDouble(18, 0); // behavior 5. TODO implement this.
|
||||
stmt->execute();
|
||||
delete stmt;
|
||||
IPropertyContents::Model model;
|
||||
model.id = newIDL;
|
||||
model.ugcId = blueprintIDSmall;
|
||||
model.position = NiPoint3::ZERO;
|
||||
model.rotation = NiQuaternion(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
model.lot = 14;
|
||||
Database::Get()->InsertNewPropertyModel(propertyId, model, "Objects_14_name");
|
||||
|
||||
/*
|
||||
Commented out until UGC server would be updated to use a sd0 file instead of lxfml stream.
|
||||
@@ -4232,20 +4185,12 @@ void GameMessages::HandleUpdatePropertyPerformanceCost(RakNet::BitStream* inStre
|
||||
if (performanceCost == 0.0f) return;
|
||||
|
||||
auto zone = Game::zoneManager->GetZone();
|
||||
const auto& worldId = zone->GetZoneID();
|
||||
const auto cloneId = worldId.GetCloneID();
|
||||
const auto zoneId = worldId.GetMapID();
|
||||
if (!zone) {
|
||||
LOG("If you see this message, something is very wrong.");
|
||||
return;
|
||||
}
|
||||
|
||||
auto updatePerformanceCostQuery = Database::CreatePreppedStmt("UPDATE properties SET performance_cost = ? WHERE clone_id = ? AND zone_id = ?");
|
||||
|
||||
updatePerformanceCostQuery->setDouble(1, performanceCost);
|
||||
updatePerformanceCostQuery->setInt(2, cloneId);
|
||||
updatePerformanceCostQuery->setInt(3, zoneId);
|
||||
|
||||
updatePerformanceCostQuery->executeUpdate();
|
||||
|
||||
delete updatePerformanceCostQuery;
|
||||
updatePerformanceCostQuery = nullptr;
|
||||
Database::Get()->UpdatePerformanceCost(zone->GetZoneID(), performanceCost);
|
||||
}
|
||||
|
||||
void GameMessages::HandleVehicleNotifyHitImaginationServer(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr) {
|
||||
@@ -5126,7 +5071,7 @@ void GameMessages::HandleModularBuildConvertModel(RakNet::BitStream* inStream, E
|
||||
|
||||
item->Disassemble(TEMP_MODELS);
|
||||
|
||||
std::unique_ptr<sql::PreparedStatement> stmt(Database::CreatePreppedStmt("DELETE FROM ugc_modular_build where ugc_id = ?"));
|
||||
std::unique_ptr<sql::PreparedStatement> stmt(Database::Get()->CreatePreppedStmt("DELETE FROM ugc_modular_build where ugc_id = ?"));
|
||||
stmt->setUInt64(1, item->GetSubKey());
|
||||
stmt->execute();
|
||||
|
||||
@@ -5629,7 +5574,7 @@ void GameMessages::HandleModularBuildFinish(RakNet::BitStream* inStream, Entity*
|
||||
inv->AddItem(8092, 1, eLootSourceType::QUICKBUILD, eInventoryType::MODELS, config, LWOOBJID_EMPTY, true, false, newIdBig);
|
||||
}
|
||||
|
||||
std::unique_ptr<sql::PreparedStatement> stmt(Database::CreatePreppedStmt("INSERT INTO ugc_modular_build (ugc_id, ldf_config, character_id) VALUES (?,?,?)"));
|
||||
std::unique_ptr<sql::PreparedStatement> stmt(Database::Get()->CreatePreppedStmt("INSERT INTO ugc_modular_build (ugc_id, ldf_config, character_id) VALUES (?,?,?)"));
|
||||
stmt->setUInt64(1, newIdBig);
|
||||
stmt->setString(2, GeneralUtils::UTF16ToWTF8(modules));
|
||||
auto* pCharacter = character->GetCharacter();
|
||||
@@ -5986,31 +5931,27 @@ void GameMessages::SendGetHotPropertyData(RakNet::BitStream* inStream, Entity* e
|
||||
|
||||
void GameMessages::HandleReportBug(RakNet::BitStream* inStream, Entity* entity) {
|
||||
//Definitely not stolen from autogenerated code, no sir:
|
||||
std::u16string body;
|
||||
std::string clientVersion;
|
||||
std::string nOtherPlayerID;
|
||||
std::string selection;
|
||||
uint32_t messageLength;
|
||||
int32_t reporterID = 0;
|
||||
IBugReports::Info reportInfo;
|
||||
|
||||
//Reading:
|
||||
uint32_t messageLength;
|
||||
inStream->Read(messageLength);
|
||||
|
||||
for (uint32_t i = 0; i < (messageLength); ++i) {
|
||||
uint16_t character;
|
||||
inStream->Read(character);
|
||||
body.push_back(character);
|
||||
reportInfo.body.push_back(static_cast<char>(character));
|
||||
}
|
||||
|
||||
auto character = entity->GetCharacter();
|
||||
if (character) reporterID = character->GetID();
|
||||
if (character) reportInfo.characterId = character->GetID();
|
||||
|
||||
uint32_t clientVersionLength;
|
||||
inStream->Read(clientVersionLength);
|
||||
for (unsigned int k = 0; k < clientVersionLength; k++) {
|
||||
unsigned char character;
|
||||
inStream->Read(character);
|
||||
clientVersion.push_back(character);
|
||||
reportInfo.clientVersion.push_back(character);
|
||||
}
|
||||
|
||||
uint32_t nOtherPlayerIDLength;
|
||||
@@ -6018,32 +5959,18 @@ void GameMessages::HandleReportBug(RakNet::BitStream* inStream, Entity* entity)
|
||||
for (unsigned int k = 0; k < nOtherPlayerIDLength; k++) {
|
||||
unsigned char character;
|
||||
inStream->Read(character);
|
||||
nOtherPlayerID.push_back(character);
|
||||
reportInfo.otherPlayer.push_back(character);
|
||||
}
|
||||
// Convert other player id from LWOOBJID to the database id.
|
||||
uint32_t otherPlayer = LWOOBJID_EMPTY;
|
||||
if (nOtherPlayerID != "") otherPlayer = std::atoi(nOtherPlayerID.c_str());
|
||||
|
||||
uint32_t selectionLength;
|
||||
inStream->Read(selectionLength);
|
||||
for (unsigned int k = 0; k < selectionLength; k++) {
|
||||
unsigned char character;
|
||||
inStream->Read(character);
|
||||
selection.push_back(character);
|
||||
reportInfo.selection.push_back(character);
|
||||
}
|
||||
|
||||
try {
|
||||
sql::PreparedStatement* insertBug = Database::CreatePreppedStmt("INSERT INTO `bug_reports`(body, client_version, other_player_id, selection, reporter_id) VALUES (?, ?, ?, ?, ?)");
|
||||
insertBug->setString(1, GeneralUtils::UTF16ToWTF8(body));
|
||||
insertBug->setString(2, clientVersion);
|
||||
insertBug->setString(3, std::to_string(otherPlayer));
|
||||
insertBug->setString(4, selection);
|
||||
insertBug->setInt(5, reporterID);
|
||||
insertBug->execute();
|
||||
delete insertBug;
|
||||
} catch (sql::SQLException& e) {
|
||||
LOG("Couldn't save bug report! (%s)", e.what());
|
||||
}
|
||||
Database::Get()->InsertNewBugReport(reportInfo);
|
||||
}
|
||||
|
||||
void
|
||||
|
@@ -9,6 +9,7 @@
|
||||
#include "User.h"
|
||||
#include "UserManager.h"
|
||||
#include "dConfig.h"
|
||||
#include <optional>
|
||||
|
||||
Entity* GetPossessedEntity(const LWOOBJID& objId) {
|
||||
auto* entity = Game::entityManager->GetEntity(objId);
|
||||
@@ -26,20 +27,22 @@ void ReportCheat(User* user, const SystemAddress& sysAddr, const char* messageIf
|
||||
if (!user) {
|
||||
LOG("WARNING: User is null, using defaults.");
|
||||
}
|
||||
std::unique_ptr<sql::PreparedStatement> stmt(Database::CreatePreppedStmt(
|
||||
"INSERT INTO player_cheat_detections (account_id, name, violation_msg, violation_system_address) VALUES (?, ?, ?, ?)")
|
||||
);
|
||||
user ? stmt->setInt(1, user->GetAccountID()) : stmt->setNull(1, sql::DataType::INTEGER);
|
||||
stmt->setString(2, user ? user->GetUsername().c_str() : "User is null.");
|
||||
|
||||
IPlayerCheatDetections::Info info;
|
||||
if (user) info.userId = user->GetAccountID();
|
||||
info.username = user ? user->GetUsername().c_str() : "User is null.";
|
||||
|
||||
// user string here because ToString is static and may change.
|
||||
info.systemAddress = sysAddr.ToString();
|
||||
|
||||
constexpr int32_t bufSize = 4096;
|
||||
char buffer[bufSize];
|
||||
vsnprintf(buffer, bufSize, messageIfNotSender, args);
|
||||
char extraMsg[bufSize];
|
||||
vsnprintf(extraMsg, bufSize, messageIfNotSender, args);
|
||||
info.extraMessage = extraMsg;
|
||||
|
||||
stmt->setString(3, buffer);
|
||||
stmt->setString(4, Game::config->GetValue("log_ip_addresses_for_anti_cheat") == "1" ? sysAddr.ToString() : "IP logging disabled.");
|
||||
stmt->execute();
|
||||
LOG("Anti-cheat message: %s", buffer);
|
||||
Database::Get()->InsertCheatDetection(info);
|
||||
|
||||
LOG("Anti-cheat message: %s", extraMsg);
|
||||
}
|
||||
|
||||
void LogAndSaveFailedAntiCheatCheck(const LWOOBJID& id, const SystemAddress& sysAddr, const CheckType checkType, const char* messageIfNotSender, va_list args) {
|
||||
|
@@ -76,22 +76,19 @@ void Mail::SendMail(const LWOOBJID sender, const std::string& senderName, const
|
||||
void Mail::SendMail(const LWOOBJID sender, const std::string& senderName, LWOOBJID recipient,
|
||||
const std::string& recipientName, const std::string& subject, const std::string& body, const LOT attachment,
|
||||
const uint16_t attachmentCount, const SystemAddress& sysAddr) {
|
||||
auto* ins = Database::CreatePreppedStmt("INSERT INTO `mail`(`sender_id`, `sender_name`, `receiver_id`, `receiver_name`, `time_sent`, `subject`, `body`, `attachment_id`, `attachment_lot`, `attachment_subkey`, `attachment_count`, `was_read`) VALUES (?,?,?,?,?,?,?,?,?,?,?,0)");
|
||||
IMail::MailInfo mailInsert;
|
||||
mailInsert.senderUsername = senderName;
|
||||
mailInsert.recipient = recipientName;
|
||||
mailInsert.subject = subject;
|
||||
mailInsert.body = body;
|
||||
mailInsert.senderId = sender;
|
||||
mailInsert.receiverId = recipient;
|
||||
mailInsert.itemCount = attachmentCount;
|
||||
mailInsert.itemID = LWOOBJID_EMPTY;
|
||||
mailInsert.itemLOT = attachment;
|
||||
mailInsert.itemSubkey = LWOOBJID_EMPTY;
|
||||
|
||||
ins->setUInt(1, sender);
|
||||
ins->setString(2, senderName.c_str());
|
||||
ins->setUInt(3, recipient);
|
||||
ins->setString(4, recipientName.c_str());
|
||||
ins->setUInt64(5, time(nullptr));
|
||||
ins->setString(6, subject.c_str());
|
||||
ins->setString(7, body.c_str());
|
||||
ins->setUInt(8, 0);
|
||||
ins->setInt(9, attachment);
|
||||
ins->setInt(10, 0);
|
||||
ins->setInt(11, attachmentCount);
|
||||
ins->execute();
|
||||
|
||||
delete ins;
|
||||
Database::Get()->InsertNewMail(mailInsert);
|
||||
|
||||
if (sysAddr == UNASSIGNED_SYSTEM_ADDRESS) return; // TODO: Echo to chat server
|
||||
|
||||
@@ -220,43 +217,30 @@ void Mail::HandleSendMail(RakNet::BitStream* packet, const SystemAddress& sysAdd
|
||||
}
|
||||
|
||||
//Get the receiver's id:
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt("SELECT id from charinfo WHERE name=? LIMIT 1;");
|
||||
stmt->setString(1, recipient);
|
||||
sql::ResultSet* res = stmt->executeQuery();
|
||||
uint32_t receiverID = 0;
|
||||
auto receiverID = Database::Get()->GetCharacterInfo(recipient);
|
||||
|
||||
if (res->rowsCount() > 0) {
|
||||
while (res->next()) receiverID = res->getUInt(1);
|
||||
} else {
|
||||
if (!receiverID) {
|
||||
Mail::SendSendResponse(sysAddr, Mail::MailSendResponse::RecipientNotFound);
|
||||
delete stmt;
|
||||
delete res;
|
||||
return;
|
||||
}
|
||||
|
||||
delete stmt;
|
||||
delete res;
|
||||
|
||||
//Check if we have a valid receiver:
|
||||
if (GeneralUtils::CaseInsensitiveStringCompare(recipient, character->GetName()) || receiverID == character->GetObjectID()) {
|
||||
if (GeneralUtils::CaseInsensitiveStringCompare(recipient, character->GetName()) || receiverID->id == character->GetID()) {
|
||||
Mail::SendSendResponse(sysAddr, Mail::MailSendResponse::CannotMailSelf);
|
||||
return;
|
||||
} else {
|
||||
uint64_t currentTime = time(NULL);
|
||||
sql::PreparedStatement* ins = Database::CreatePreppedStmt("INSERT INTO `mail`(`sender_id`, `sender_name`, `receiver_id`, `receiver_name`, `time_sent`, `subject`, `body`, `attachment_id`, `attachment_lot`, `attachment_subkey`, `attachment_count`, `was_read`) VALUES (?,?,?,?,?,?,?,?,?,?,?,0)");
|
||||
ins->setUInt(1, character->GetObjectID());
|
||||
ins->setString(2, character->GetName());
|
||||
ins->setUInt(3, receiverID);
|
||||
ins->setString(4, recipient);
|
||||
ins->setUInt64(5, currentTime);
|
||||
ins->setString(6, subject);
|
||||
ins->setString(7, body);
|
||||
ins->setUInt(8, itemID);
|
||||
ins->setInt(9, itemLOT);
|
||||
ins->setInt(10, 0);
|
||||
ins->setInt(11, attachmentCount);
|
||||
ins->execute();
|
||||
delete ins;
|
||||
IMail::MailInfo mailInsert;
|
||||
mailInsert.senderUsername = character->GetName();
|
||||
mailInsert.recipient = recipient;
|
||||
mailInsert.subject = subject;
|
||||
mailInsert.body = body;
|
||||
mailInsert.senderId = character->GetID();
|
||||
mailInsert.receiverId = receiverID->id;
|
||||
mailInsert.itemCount = attachmentCount;
|
||||
mailInsert.itemID = itemID;
|
||||
mailInsert.itemLOT = itemLOT;
|
||||
mailInsert.itemSubkey = LWOOBJID_EMPTY;
|
||||
Database::Get()->InsertNewMail(mailInsert);
|
||||
}
|
||||
|
||||
Mail::SendSendResponse(sysAddr, Mail::MailSendResponse::Success);
|
||||
@@ -279,61 +263,49 @@ void Mail::HandleSendMail(RakNet::BitStream* packet, const SystemAddress& sysAdd
|
||||
}
|
||||
|
||||
void Mail::HandleDataRequest(RakNet::BitStream* packet, const SystemAddress& sysAddr, Entity* player) {
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt("SELECT * FROM mail WHERE receiver_id=? limit 20;");
|
||||
stmt->setUInt(1, player->GetCharacter()->GetObjectID());
|
||||
sql::ResultSet* res = stmt->executeQuery();
|
||||
auto playerMail = Database::Get()->GetMailForPlayer(player->GetCharacter()->GetID(), 20);
|
||||
|
||||
RakNet::BitStream bitStream;
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::MAIL);
|
||||
bitStream.Write(int(MailMessageID::MailData));
|
||||
bitStream.Write(int(0));
|
||||
|
||||
bitStream.Write(uint16_t(res->rowsCount()));
|
||||
bitStream.Write(uint16_t(0));
|
||||
bitStream.Write<uint16_t>(playerMail.size());
|
||||
bitStream.Write<uint16_t>(0);
|
||||
|
||||
if (res->rowsCount() > 0) {
|
||||
while (res->next()) {
|
||||
bitStream.Write(res->getUInt64(1)); //MailID
|
||||
for (const auto& mail : playerMail) {
|
||||
bitStream.Write(mail.id); //MailID
|
||||
|
||||
/*std::u16string subject = GeneralUtils::UTF8ToUTF16(res->getString(7));
|
||||
std::u16string body = GeneralUtils::UTF8ToUTF16(res->getString(8));
|
||||
std::u16string sender = GeneralUtils::UTF8ToUTF16(res->getString(3));
|
||||
WriteStringAsWString(&bitStream, mail.subject.c_str(), 50); //subject
|
||||
WriteStringAsWString(&bitStream, mail.body.c_str(), 400); //body
|
||||
WriteStringAsWString(&bitStream, mail.senderUsername.c_str(), 32); //sender
|
||||
|
||||
WriteToPacket(&bitStream, subject, 50);
|
||||
WriteToPacket(&bitStream, body, 400);
|
||||
WriteToPacket(&bitStream, sender, 32);*/
|
||||
bitStream.Write(uint32_t(0));
|
||||
bitStream.Write(uint64_t(0));
|
||||
|
||||
WriteStringAsWString(&bitStream, res->getString(7).c_str(), 50); //subject
|
||||
WriteStringAsWString(&bitStream, res->getString(8).c_str(), 400); //body
|
||||
WriteStringAsWString(&bitStream, res->getString(3).c_str(), 32); //sender
|
||||
bitStream.Write(mail.itemID); //Attachment ID
|
||||
LOT lot = mail.itemLOT;
|
||||
if (lot <= 0) bitStream.Write(LOT(-1));
|
||||
else bitStream.Write(lot);
|
||||
bitStream.Write(uint32_t(0));
|
||||
|
||||
bitStream.Write(uint32_t(0));
|
||||
bitStream.Write(uint64_t(0));
|
||||
bitStream.Write(mail.itemSubkey); //Attachment subKey
|
||||
bitStream.Write<uint16_t>(mail.itemCount); //Attachment count
|
||||
|
||||
bitStream.Write(res->getUInt64(9)); //Attachment ID
|
||||
LOT lot = res->getInt(10);
|
||||
if (lot <= 0) bitStream.Write(LOT(-1));
|
||||
else bitStream.Write(lot);
|
||||
bitStream.Write(uint32_t(0));
|
||||
bitStream.Write(uint32_t(0));
|
||||
bitStream.Write(uint16_t(0));
|
||||
|
||||
bitStream.Write(res->getInt64(11)); //Attachment subKey
|
||||
bitStream.Write(uint16_t(res->getInt(12))); //Attachment count
|
||||
bitStream.Write<uint64_t>(mail.timeSent); //time sent (twice?)
|
||||
bitStream.Write<uint64_t>(mail.timeSent);
|
||||
bitStream.Write<uint8_t>(mail.wasRead); //was read
|
||||
|
||||
bitStream.Write(uint32_t(0));
|
||||
bitStream.Write(uint16_t(0));
|
||||
|
||||
bitStream.Write(uint64_t(res->getUInt64(6))); //time sent (twice?)
|
||||
bitStream.Write(uint64_t(res->getUInt64(6)));
|
||||
bitStream.Write(uint8_t(res->getBoolean(13))); //was read
|
||||
|
||||
bitStream.Write(uint8_t(0));
|
||||
bitStream.Write(uint16_t(0));
|
||||
bitStream.Write(uint32_t(0));
|
||||
}
|
||||
bitStream.Write(uint8_t(0));
|
||||
bitStream.Write(uint16_t(0));
|
||||
bitStream.Write(uint32_t(0));
|
||||
}
|
||||
|
||||
Game::server->Send(&bitStream, sysAddr, false);
|
||||
PacketUtils::SavePacket("Max_Mail_Data.bin", (const char*)bitStream.GetData(), bitStream.GetNumberOfBytesUsed());
|
||||
// PacketUtils::SavePacket("Max_Mail_Data.bin", (const char*)bitStream.GetData(), bitStream.GetNumberOfBytesUsed());
|
||||
}
|
||||
|
||||
void Mail::HandleAttachmentCollect(RakNet::BitStream* packet, const SystemAddress& sysAddr, Entity* player) {
|
||||
@@ -345,31 +317,24 @@ void Mail::HandleAttachmentCollect(RakNet::BitStream* packet, const SystemAddres
|
||||
packet->Read(playerID);
|
||||
|
||||
if (mailID > 0 && playerID == player->GetObjectID()) {
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt("SELECT attachment_lot, attachment_count FROM mail WHERE id=? LIMIT 1;");
|
||||
stmt->setUInt64(1, mailID);
|
||||
sql::ResultSet* res = stmt->executeQuery();
|
||||
auto playerMail = Database::Get()->GetMail(mailID);
|
||||
|
||||
LOT attachmentLOT = 0;
|
||||
uint32_t attachmentCount = 0;
|
||||
|
||||
while (res->next()) {
|
||||
attachmentLOT = res->getInt(1);
|
||||
attachmentCount = res->getInt(2);
|
||||
if (playerMail) {
|
||||
attachmentLOT = playerMail->itemLOT;
|
||||
attachmentCount = playerMail->itemCount;
|
||||
}
|
||||
|
||||
auto inv = static_cast<InventoryComponent*>(player->GetComponent(eReplicaComponentType::INVENTORY));
|
||||
auto inv = player->GetComponent<InventoryComponent>();
|
||||
if (!inv) return;
|
||||
|
||||
inv->AddItem(attachmentLOT, attachmentCount, eLootSourceType::MAIL);
|
||||
|
||||
Mail::SendAttachmentRemoveConfirm(sysAddr, mailID);
|
||||
|
||||
sql::PreparedStatement* up = Database::CreatePreppedStmt("UPDATE mail SET attachment_lot=0 WHERE id=?;");
|
||||
up->setUInt64(1, mailID);
|
||||
up->execute();
|
||||
delete up;
|
||||
delete res;
|
||||
delete stmt;
|
||||
Database::Get()->ClaimMailItem(mailID);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -394,15 +359,9 @@ void Mail::HandleMailRead(RakNet::BitStream* packet, const SystemAddress& sysAdd
|
||||
}
|
||||
|
||||
void Mail::HandleNotificationRequest(const SystemAddress& sysAddr, uint32_t objectID) {
|
||||
auto returnVal = std::async(std::launch::async, [&]() {
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt("SELECT id FROM mail WHERE receiver_id=? AND was_read=0");
|
||||
stmt->setUInt(1, objectID);
|
||||
sql::ResultSet* res = stmt->executeQuery();
|
||||
auto unreadMailCount = Database::Get()->GetUnreadMailCount(objectID);
|
||||
|
||||
if (res->rowsCount() > 0) Mail::SendNotification(sysAddr, res->rowsCount());
|
||||
delete res;
|
||||
delete stmt;
|
||||
});
|
||||
if (unreadMailCount > 0) Mail::SendNotification(sysAddr, unreadMailCount);
|
||||
}
|
||||
|
||||
void Mail::SendSendResponse(const SystemAddress& sysAddr, MailSendResponse response) {
|
||||
@@ -449,10 +408,7 @@ void Mail::SendDeleteConfirm(const SystemAddress& sysAddr, uint64_t mailID, LWOO
|
||||
bitStream.Write(mailID);
|
||||
Game::server->Send(&bitStream, sysAddr, false);
|
||||
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt("DELETE FROM mail WHERE id=? LIMIT 1;");
|
||||
stmt->setUInt64(1, mailID);
|
||||
stmt->execute();
|
||||
delete stmt;
|
||||
Database::Get()->DeleteMail(mailID);
|
||||
}
|
||||
|
||||
void Mail::SendReadConfirm(const SystemAddress& sysAddr, uint64_t mailID) {
|
||||
@@ -463,8 +419,5 @@ void Mail::SendReadConfirm(const SystemAddress& sysAddr, uint64_t mailID) {
|
||||
bitStream.Write(mailID);
|
||||
Game::server->Send(&bitStream, sysAddr, false);
|
||||
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt("UPDATE mail SET was_read=1 WHERE id=?");
|
||||
stmt->setUInt64(1, mailID);
|
||||
stmt->execute();
|
||||
delete stmt;
|
||||
Database::Get()->MarkMailRead(mailID);
|
||||
}
|
||||
|
@@ -360,11 +360,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
|
||||
}
|
||||
|
||||
// Log command to database
|
||||
auto stmt = Database::CreatePreppedStmt("INSERT INTO command_log (character_id, command) VALUES (?, ?);");
|
||||
stmt->setInt(1, entity->GetCharacter()->GetID());
|
||||
stmt->setString(2, GeneralUtils::UTF16ToWTF8(command).c_str());
|
||||
stmt->execute();
|
||||
delete stmt;
|
||||
Database::Get()->InsertSlashCommandUsage(entity->GetObjectID(), chatCommand);
|
||||
|
||||
if (chatCommand == "setminifig" && args.size() == 2 && entity->GetGMLevel() >= eGameMasterLevel::FORUM_MODERATOR) { // could break characters so only allow if GM > 0
|
||||
int32_t minifigItemId;
|
||||
@@ -816,46 +812,36 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
|
||||
if (chatCommand == "mailitem" && entity->GetGMLevel() >= eGameMasterLevel::MODERATOR && args.size() >= 2) {
|
||||
const auto& playerName = args[0];
|
||||
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt("SELECT id from charinfo WHERE name=? LIMIT 1;");
|
||||
stmt->setString(1, playerName);
|
||||
sql::ResultSet* res = stmt->executeQuery();
|
||||
auto playerInfo = Database::Get()->GetCharacterInfo(playerName);
|
||||
|
||||
uint32_t receiverID = 0;
|
||||
|
||||
if (res->rowsCount() > 0) {
|
||||
while (res->next()) receiverID = res->getUInt(1);
|
||||
}
|
||||
|
||||
delete stmt;
|
||||
delete res;
|
||||
|
||||
if (receiverID == 0) {
|
||||
if (!playerInfo) {
|
||||
ChatPackets::SendSystemMessage(sysAddr, u"Failed to find that player");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t lot;
|
||||
receiverID = playerInfo->id;
|
||||
|
||||
LOT lot;
|
||||
|
||||
if (!GeneralUtils::TryParse(args[1], lot)) {
|
||||
ChatPackets::SendSystemMessage(sysAddr, u"Invalid item lot.");
|
||||
return;
|
||||
}
|
||||
|
||||
uint64_t currentTime = time(NULL);
|
||||
sql::PreparedStatement* ins = Database::CreatePreppedStmt("INSERT INTO `mail`(`sender_id`, `sender_name`, `receiver_id`, `receiver_name`, `time_sent`, `subject`, `body`, `attachment_id`, `attachment_lot`, `attachment_subkey`, `attachment_count`, `was_read`) VALUES (?,?,?,?,?,?,?,?,?,?,?,0)");
|
||||
ins->setUInt(1, entity->GetObjectID());
|
||||
ins->setString(2, "Darkflame Universe");
|
||||
ins->setUInt(3, receiverID);
|
||||
ins->setString(4, playerName);
|
||||
ins->setUInt64(5, currentTime);
|
||||
ins->setString(6, "Lost item");
|
||||
ins->setString(7, "This is a replacement item for one you lost.");
|
||||
ins->setUInt(8, 0);
|
||||
ins->setInt(9, lot);
|
||||
ins->setInt(10, 0);
|
||||
ins->setInt(11, 1);
|
||||
ins->execute();
|
||||
delete ins;
|
||||
IMail::MailInfo mailInsert;
|
||||
mailInsert.senderId = entity->GetObjectID();
|
||||
mailInsert.senderUsername = "Darkflame Universe";
|
||||
mailInsert.receiverId = receiverID;
|
||||
mailInsert.recipient = playerName;
|
||||
mailInsert.subject = "Lost item";
|
||||
mailInsert.body = "This is a replacement item for one you lost.";
|
||||
mailInsert.itemID = LWOOBJID_EMPTY;
|
||||
mailInsert.itemLOT = lot;
|
||||
mailInsert.itemSubkey = LWOOBJID_EMPTY;
|
||||
mailInsert.itemCount = 1;
|
||||
Database::Get()->InsertNewMail(mailInsert);
|
||||
|
||||
ChatPackets::SendSystemMessage(sysAddr, u"Mail sent");
|
||||
|
||||
@@ -1015,25 +1001,16 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
|
||||
LWOOBJID characterId = 0;
|
||||
|
||||
if (player == nullptr) {
|
||||
auto* accountQuery = Database::CreatePreppedStmt("SELECT account_id, id FROM charinfo WHERE name=? LIMIT 1;");
|
||||
auto characterInfo = Database::Get()->GetCharacterInfo(args[0]);
|
||||
|
||||
accountQuery->setString(1, args[0]);
|
||||
if (characterInfo) {
|
||||
accountId = characterInfo->accountId;
|
||||
characterId = characterInfo->id;
|
||||
|
||||
auto result = accountQuery->executeQuery();
|
||||
|
||||
if (result->rowsCount() > 0) {
|
||||
while (result->next()) {
|
||||
accountId = result->getUInt(1);
|
||||
characterId = result->getUInt64(2);
|
||||
|
||||
GeneralUtils::SetBit(characterId, eObjectBits::CHARACTER);
|
||||
GeneralUtils::SetBit(characterId, eObjectBits::PERSISTENT);
|
||||
}
|
||||
GeneralUtils::SetBit(characterId, eObjectBits::CHARACTER);
|
||||
GeneralUtils::SetBit(characterId, eObjectBits::PERSISTENT);
|
||||
}
|
||||
|
||||
delete accountQuery;
|
||||
delete result;
|
||||
|
||||
if (accountId == 0) {
|
||||
ChatPackets::SendSystemMessage(sysAddr, u"Count not find player of name: " + GeneralUtils::UTF8ToUTF16(args[0]));
|
||||
|
||||
@@ -1044,8 +1021,6 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
|
||||
characterId = player->GetObjectID();
|
||||
}
|
||||
|
||||
auto* userUpdate = Database::CreatePreppedStmt("UPDATE accounts SET mute_expire = ? WHERE id = ?;");
|
||||
|
||||
time_t expire = 1; // Default to indefinate mute
|
||||
|
||||
if (args.size() >= 2) {
|
||||
@@ -1070,12 +1045,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
|
||||
expire += 60 * 60 * hours;
|
||||
}
|
||||
|
||||
userUpdate->setUInt64(1, expire);
|
||||
userUpdate->setInt(2, accountId);
|
||||
|
||||
userUpdate->executeUpdate();
|
||||
|
||||
delete userUpdate;
|
||||
Database::Get()->UpdateAccountUnmuteTime(accountId, expire);
|
||||
|
||||
char buffer[32] = "brought up for review.\0";
|
||||
|
||||
@@ -1127,19 +1097,12 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
|
||||
uint32_t accountId = 0;
|
||||
|
||||
if (player == nullptr) {
|
||||
auto* accountQuery = Database::CreatePreppedStmt("SELECT account_id FROM charinfo WHERE name=? LIMIT 1;");
|
||||
auto characterInfo = Database::Get()->GetCharacterInfo(args[0]);
|
||||
|
||||
accountQuery->setString(1, args[0]);
|
||||
|
||||
auto result = accountQuery->executeQuery();
|
||||
|
||||
if (result->rowsCount() > 0) {
|
||||
while (result->next()) accountId = result->getUInt(1);
|
||||
if (characterInfo) {
|
||||
accountId = characterInfo->accountId;
|
||||
}
|
||||
|
||||
delete accountQuery;
|
||||
delete result;
|
||||
|
||||
if (accountId == 0) {
|
||||
ChatPackets::SendSystemMessage(sysAddr, u"Count not find player of name: " + GeneralUtils::UTF8ToUTF16(args[0]));
|
||||
|
||||
@@ -1149,13 +1112,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
|
||||
accountId = player->GetParentUser()->GetAccountID();
|
||||
}
|
||||
|
||||
auto* userUpdate = Database::CreatePreppedStmt("UPDATE accounts SET banned = true WHERE id = ?;");
|
||||
|
||||
userUpdate->setInt(1, accountId);
|
||||
|
||||
userUpdate->executeUpdate();
|
||||
|
||||
delete userUpdate;
|
||||
Database::Get()->UpdateAccountBan(accountId, true);
|
||||
|
||||
if (player != nullptr) {
|
||||
Game::server->Disconnect(player->GetSystemAddress(), eServerDisconnectIdentifiers::FREE_TRIAL_EXPIRED);
|
||||
|
Reference in New Issue
Block a user