mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-10-12 10:28:05 +00:00
feat: convert character ids to 64 bits
remove all usages of the PERSISTENT bit with regards to storing of playerIDs on the server. the bit does not exist and was a phantom in the first place. Tested that a full playthrough of ag, ns and gf was still doable. slash commands work, ugc works, friends works, ignore list works, properties work and have names, teaming works. migrating an old mysql database works . need to test an old sqlite database
This commit is contained in:
@@ -23,7 +23,7 @@
|
||||
#include "ePlayerFlag.h"
|
||||
#include "CDPlayerFlagsTable.h"
|
||||
|
||||
Character::Character(uint32_t id, User* parentUser) {
|
||||
Character::Character(LWOOBJID id, User* parentUser) {
|
||||
//First load the name, etc:
|
||||
m_ID = id;
|
||||
m_ParentUser = parentUser;
|
||||
@@ -50,6 +50,10 @@ void Character::UpdateInfoFromDatabase() {
|
||||
|
||||
//Load the xmlData now:
|
||||
m_XMLData = Database::Get()->GetCharacterXml(m_ID);
|
||||
if (m_XMLData.empty()) {
|
||||
LOG("Character %s (%llu) has no xml data!", m_Name.c_str(), m_ID);
|
||||
return;
|
||||
}
|
||||
|
||||
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.
|
||||
@@ -61,7 +65,6 @@ void Character::UpdateInfoFromDatabase() {
|
||||
//Set our objectID:
|
||||
m_ObjectID = m_ID;
|
||||
GeneralUtils::SetBit(m_ObjectID, eObjectBits::CHARACTER);
|
||||
GeneralUtils::SetBit(m_ObjectID, eObjectBits::PERSISTENT);
|
||||
|
||||
m_OurEntity = nullptr;
|
||||
m_BuildMode = false;
|
||||
@@ -75,7 +78,7 @@ void Character::DoQuickXMLDataParse() {
|
||||
if (m_XMLData.size() == 0) return;
|
||||
|
||||
if (m_Doc.Parse(m_XMLData.c_str(), m_XMLData.size()) == 0) {
|
||||
LOG("Loaded xmlData for character %s (%i)!", m_Name.c_str(), m_ID);
|
||||
LOG("Loaded xmlData for character %s (%llu)!", m_Name.c_str(), m_ID);
|
||||
} else {
|
||||
LOG("Failed to load xmlData (%i) (%s) (%s)!", m_Doc.ErrorID(), m_Doc.ErrorIDToName(m_Doc.ErrorID()), m_Doc.ErrorStr());
|
||||
//Server::rakServer->CloseConnection(m_ParentUser->GetSystemAddress(), true);
|
||||
@@ -238,7 +241,7 @@ void Character::SetBuildMode(bool buildMode) {
|
||||
void Character::SaveXMLToDatabase() {
|
||||
// Check that we can actually _save_ before saving
|
||||
if (!m_OurEntity) {
|
||||
LOG("%i:%s didn't have an entity set while saving! CHARACTER WILL NOT BE SAVED!", this->GetID(), this->GetName().c_str());
|
||||
LOG("%llu:%s didn't have an entity set while saving! CHARACTER WILL NOT BE SAVED!", this->GetID(), this->GetName().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -308,7 +311,7 @@ void Character::SaveXMLToDatabase() {
|
||||
//For metrics, log the time it took to save:
|
||||
auto end = std::chrono::system_clock::now();
|
||||
std::chrono::duration<double> elapsed = end - start;
|
||||
LOG("%i:%s Saved character to Database in: %fs", this->GetID(), this->GetName().c_str(), elapsed.count());
|
||||
LOG("%llu:%s Saved character to Database in: %fs", this->GetID(), this->GetName().c_str(), elapsed.count());
|
||||
}
|
||||
|
||||
void Character::SetIsNewLogin() {
|
||||
@@ -320,7 +323,7 @@ void Character::SetIsNewLogin() {
|
||||
while (currentChild) {
|
||||
auto* nextChild = currentChild->NextSiblingElement();
|
||||
if (currentChild->Attribute("si")) {
|
||||
LOG("Removed session flag (%s) from character %i:%s, saving character to database", currentChild->Attribute("si"), GetID(), GetName().c_str());
|
||||
LOG("Removed session flag (%s) from character %llu:%s, saving character to database", currentChild->Attribute("si"), GetID(), GetName().c_str());
|
||||
flags->DeleteChild(currentChild);
|
||||
WriteToDatabase();
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@ enum class eLootSourceType : uint32_t;
|
||||
*/
|
||||
class Character {
|
||||
public:
|
||||
Character(uint32_t id, User* parentUser);
|
||||
Character(LWOOBJID id, User* parentUser);
|
||||
~Character();
|
||||
|
||||
/**
|
||||
@@ -53,7 +53,7 @@ public:
|
||||
* Gets the database ID of the character
|
||||
* @return the database ID of the character
|
||||
*/
|
||||
uint32_t GetID() const { return m_ID; }
|
||||
LWOOBJID GetID() const { return m_ID; }
|
||||
|
||||
/**
|
||||
* Gets the (custom) name of the character
|
||||
@@ -467,9 +467,9 @@ public:
|
||||
private:
|
||||
void UpdateInfoFromDatabase();
|
||||
/**
|
||||
* The ID of this character. First 32 bits of the ObjectID.
|
||||
* The ID of this character.
|
||||
*/
|
||||
uint32_t m_ID{};
|
||||
LWOOBJID m_ID{};
|
||||
|
||||
/**
|
||||
* The 64-bit unique ID used in the game.
|
||||
|
@@ -145,7 +145,7 @@ void QueryToLdf(Leaderboard& leaderboard, const std::vector<ILeaderboard::Entry>
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<ILeaderboard::Entry> FilterToNumResults(const std::vector<ILeaderboard::Entry>& leaderboard, const uint32_t relatedPlayer, const Leaderboard::InfoType infoType, const uint32_t numResults) {
|
||||
std::vector<ILeaderboard::Entry> FilterToNumResults(const std::vector<ILeaderboard::Entry>& leaderboard, const LWOOBJID relatedPlayer, const Leaderboard::InfoType infoType, const uint32_t numResults) {
|
||||
std::vector<ILeaderboard::Entry> toReturn;
|
||||
|
||||
int32_t index = 0;
|
||||
@@ -197,7 +197,7 @@ std::vector<ILeaderboard::Entry> FilterWeeklies(const std::vector<ILeaderboard::
|
||||
return weeklyLeaderboard;
|
||||
}
|
||||
|
||||
std::vector<ILeaderboard::Entry> FilterFriends(const std::vector<ILeaderboard::Entry>& leaderboard, const uint32_t relatedPlayer) {
|
||||
std::vector<ILeaderboard::Entry> FilterFriends(const std::vector<ILeaderboard::Entry>& leaderboard, const LWOOBJID relatedPlayer) {
|
||||
// Filter the leaderboard to only include friends of the player
|
||||
auto friendOfPlayer = Database::Get()->GetFriendsList(relatedPlayer);
|
||||
std::vector<ILeaderboard::Entry> friendsLeaderboard;
|
||||
@@ -217,7 +217,7 @@ std::vector<ILeaderboard::Entry> ProcessLeaderboard(
|
||||
const std::vector<ILeaderboard::Entry>& leaderboard,
|
||||
const bool weekly,
|
||||
const Leaderboard::InfoType infoType,
|
||||
const uint32_t relatedPlayer,
|
||||
const LWOOBJID relatedPlayer,
|
||||
const uint32_t numResults) {
|
||||
std::vector<ILeaderboard::Entry> toReturn;
|
||||
|
||||
|
@@ -39,11 +39,11 @@ User::User(const SystemAddress& sysAddr, const std::string& username, const std:
|
||||
if (Game::server->GetZoneID() != 0) {
|
||||
auto characterList = Database::Get()->GetAccountCharacterIds(m_AccountID);
|
||||
if (!characterList.empty()) {
|
||||
const uint32_t lastUsedCharacterId = characterList.front();
|
||||
const auto 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);
|
||||
LOG("Loaded %llu as it is the last used char", lastUsedCharacterId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -325,7 +325,9 @@ void UserManager::CreateCharacter(const SystemAddress& sysAddr, Packet* packet)
|
||||
}
|
||||
|
||||
//Now that the name is ok, we can get an objectID from Master:
|
||||
ObjectIDManager::RequestPersistentID([=, this](uint32_t objectID) {
|
||||
ObjectIDManager::RequestPersistentID([=, this](uint32_t persistentID) {
|
||||
LWOOBJID objectID = persistentID;
|
||||
GeneralUtils::SetBit(objectID, eObjectBits::CHARACTER);
|
||||
if (Database::Get()->GetCharacterInfo(objectID)) {
|
||||
LOG("Character object id unavailable, check object_id_tracker!");
|
||||
WorldPackets::SendCharacterCreationResponse(sysAddr, eCharacterCreationResponse::OBJECT_ID_UNAVAILABLE);
|
||||
@@ -409,9 +411,8 @@ void UserManager::DeleteCharacter(const SystemAddress& sysAddr, Packet* packet)
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
LWOOBJID objectID;
|
||||
inStream.Read(objectID);
|
||||
uint32_t charID = static_cast<uint32_t>(objectID);
|
||||
|
||||
LOG("Received char delete req for ID: %llu (%u)", objectID, charID);
|
||||
LOG("Received char delete req for ID: %llu", objectID);
|
||||
|
||||
bool hasCharacter = CheatDetection::VerifyLwoobjidIsSender(
|
||||
objectID,
|
||||
@@ -423,8 +424,8 @@ void UserManager::DeleteCharacter(const SystemAddress& sysAddr, Packet* packet)
|
||||
if (!hasCharacter) {
|
||||
WorldPackets::SendCharacterDeleteResponse(sysAddr, false);
|
||||
} else {
|
||||
LOG("Deleting character %i", charID);
|
||||
Database::Get()->DeleteCharacter(charID);
|
||||
LOG("Deleting character %llu", objectID);
|
||||
Database::Get()->DeleteCharacter(objectID);
|
||||
|
||||
CBITSTREAM;
|
||||
BitStreamUtils::WriteHeader(bitStream, ServiceType::CHAT, MessageType::Chat::UNEXPECTED_DISCONNECT);
|
||||
@@ -445,11 +446,8 @@ void UserManager::RenameCharacter(const SystemAddress& sysAddr, Packet* packet)
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
LWOOBJID objectID;
|
||||
inStream.Read(objectID);
|
||||
GeneralUtils::ClearBit(objectID, eObjectBits::CHARACTER);
|
||||
GeneralUtils::ClearBit(objectID, eObjectBits::PERSISTENT);
|
||||
|
||||
uint32_t charID = static_cast<uint32_t>(objectID);
|
||||
LOG("Received char rename request for ID: %llu (%u)", objectID, charID);
|
||||
LOG("Received char rename request for ID: %llu", objectID);
|
||||
|
||||
LUWString LUWStringName;
|
||||
inStream.Read(LUWStringName);
|
||||
@@ -466,7 +464,7 @@ void UserManager::RenameCharacter(const SystemAddress& sysAddr, Packet* packet)
|
||||
u->GetAccountID());
|
||||
|
||||
auto unusedItr = std::find_if(u->GetCharacters().begin(), u->GetCharacters().end(), [&](Character* c) {
|
||||
if (c->GetID() == charID) {
|
||||
if (c->GetID() == objectID) {
|
||||
character = c;
|
||||
return true;
|
||||
}
|
||||
@@ -483,12 +481,12 @@ void UserManager::RenameCharacter(const SystemAddress& sysAddr, Packet* packet)
|
||||
|
||||
if (!Database::Get()->GetCharacterInfo(newName)) {
|
||||
if (IsNamePreapproved(newName)) {
|
||||
Database::Get()->SetCharacterName(charID, newName);
|
||||
Database::Get()->SetCharacterName(objectID, newName);
|
||||
LOG("Character %s now known as %s", character->GetName().c_str(), newName.c_str());
|
||||
WorldPackets::SendCharacterRenameResponse(sysAddr, eRenameResponse::SUCCESS);
|
||||
UserManager::RequestCharacterList(sysAddr);
|
||||
} else {
|
||||
Database::Get()->SetPendingCharacterName(charID, newName);
|
||||
Database::Get()->SetPendingCharacterName(objectID, 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);
|
||||
@@ -502,7 +500,7 @@ void UserManager::RenameCharacter(const SystemAddress& sysAddr, Packet* packet)
|
||||
}
|
||||
}
|
||||
|
||||
void UserManager::LoginCharacter(const SystemAddress& sysAddr, uint32_t playerID) {
|
||||
void UserManager::LoginCharacter(const SystemAddress& sysAddr, LWOOBJID playerID) {
|
||||
User* u = GetUser(sysAddr);
|
||||
if (!u) {
|
||||
LOG("Couldn't get user to log in character");
|
||||
|
@@ -35,7 +35,7 @@ public:
|
||||
void CreateCharacter(const SystemAddress& sysAddr, Packet* packet);
|
||||
void DeleteCharacter(const SystemAddress& sysAddr, Packet* packet);
|
||||
void RenameCharacter(const SystemAddress& sysAddr, Packet* packet);
|
||||
void LoginCharacter(const SystemAddress& sysAddr, uint32_t playerID);
|
||||
void LoginCharacter(const SystemAddress& sysAddr, LWOOBJID playerID);
|
||||
|
||||
void SaveAllActiveCharacters();
|
||||
|
||||
|
@@ -64,7 +64,6 @@ PropertyManagementComponent::PropertyManagementComponent(Entity* parent) : Compo
|
||||
this->propertyId = propertyInfo->id;
|
||||
this->owner = propertyInfo->ownerId;
|
||||
GeneralUtils::SetBit(this->owner, eObjectBits::CHARACTER);
|
||||
GeneralUtils::SetBit(this->owner, eObjectBits::PERSISTENT);
|
||||
this->clone_Id = propertyInfo->cloneId;
|
||||
this->propertyName = propertyInfo->name;
|
||||
this->propertyDescription = propertyInfo->description;
|
||||
|
@@ -76,8 +76,8 @@ void LogAndSaveFailedAntiCheatCheck(const LWOOBJID& id, const SystemAddress& sys
|
||||
auto* user = UserManager::Instance()->GetUser(sysAddr);
|
||||
|
||||
if (user) {
|
||||
LOG("User at system address (%s) (%s) (%llu) sent a packet as (%i) which is not an id they own.",
|
||||
sysAddr.ToString(), user->GetLastUsedChar()->GetName().c_str(), user->GetLastUsedChar()->GetObjectID(), static_cast<int32_t>(id));
|
||||
LOG("User at system address (%s) (%s) (%llu) sent a packet as (%llu) which is not an id they own.",
|
||||
sysAddr.ToString(), user->GetLastUsedChar()->GetName().c_str(), user->GetLastUsedChar()->GetObjectID(), id);
|
||||
// Can't know sending player. Just log system address for IP banning.
|
||||
} else {
|
||||
LOG("No user found for system address (%s).", sysAddr.ToString());
|
||||
@@ -117,7 +117,7 @@ bool CheatDetection::VerifyLwoobjidIsSender(const LWOOBJID& id, const SystemAddr
|
||||
return false;
|
||||
}
|
||||
invalidPacket = true;
|
||||
const uint32_t characterId = static_cast<uint32_t>(id);
|
||||
const auto characterId = id;
|
||||
// Check to make sure the ID provided is one of the user's characters.
|
||||
for (const auto& character : sendingUser->GetCharacters()) {
|
||||
if (character && character->GetID() == characterId) {
|
||||
|
@@ -141,7 +141,6 @@ namespace GMGreaterThanZeroCommands {
|
||||
characterId = characterInfo->id;
|
||||
|
||||
GeneralUtils::SetBit(characterId, eObjectBits::CHARACTER);
|
||||
GeneralUtils::SetBit(characterId, eObjectBits::PERSISTENT);
|
||||
}
|
||||
|
||||
if (accountId == 0) {
|
||||
|
Reference in New Issue
Block a user