mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-10-11 01:48:07 +00:00
format codebase
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
|
||||
Character::Character(uint32_t id, User* parentUser) {
|
||||
//First load the name, etc:
|
||||
m_ID = id;
|
||||
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;"
|
||||
@@ -65,21 +65,20 @@ Character::Character(uint32_t id, User* parentUser) {
|
||||
|
||||
//Set our objectID:
|
||||
m_ObjectID = m_ID;
|
||||
m_ObjectID = GeneralUtils::SetBit(m_ObjectID, OBJECT_BIT_CHARACTER);
|
||||
m_ObjectID = GeneralUtils::SetBit(m_ObjectID, OBJECT_BIT_PERSISTENT);
|
||||
m_ObjectID = GeneralUtils::SetBit(m_ObjectID, OBJECT_BIT_CHARACTER);
|
||||
m_ObjectID = GeneralUtils::SetBit(m_ObjectID, OBJECT_BIT_PERSISTENT);
|
||||
|
||||
m_ParentUser = parentUser;
|
||||
m_ParentUser = parentUser;
|
||||
m_OurEntity = nullptr;
|
||||
m_BuildMode = false;
|
||||
}
|
||||
|
||||
Character::~Character() {
|
||||
delete m_Doc;
|
||||
m_Doc = nullptr;
|
||||
m_Doc = nullptr;
|
||||
}
|
||||
|
||||
void Character::UpdateFromDatabase()
|
||||
{
|
||||
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;"
|
||||
);
|
||||
@@ -125,8 +124,8 @@ void Character::UpdateFromDatabase()
|
||||
|
||||
//Set our objectID:
|
||||
m_ObjectID = m_ID;
|
||||
m_ObjectID = GeneralUtils::SetBit(m_ObjectID, OBJECT_BIT_CHARACTER);
|
||||
m_ObjectID = GeneralUtils::SetBit(m_ObjectID, OBJECT_BIT_PERSISTENT);
|
||||
m_ObjectID = GeneralUtils::SetBit(m_ObjectID, OBJECT_BIT_CHARACTER);
|
||||
m_ObjectID = GeneralUtils::SetBit(m_ObjectID, OBJECT_BIT_PERSISTENT);
|
||||
|
||||
m_OurEntity = nullptr;
|
||||
m_BuildMode = false;
|
||||
@@ -136,14 +135,14 @@ void Character::DoQuickXMLDataParse() {
|
||||
if (m_XMLData.size() == 0) return;
|
||||
|
||||
delete m_Doc;
|
||||
m_Doc = new tinyxml2::XMLDocument();
|
||||
if (!m_Doc) return;
|
||||
m_Doc = new tinyxml2::XMLDocument();
|
||||
if (!m_Doc) return;
|
||||
|
||||
if (m_Doc->Parse(m_XMLData.c_str(), m_XMLData.size()) == 0) {
|
||||
Game::logger->Log("Character", "Loaded xmlData for character %s (%i)!", m_Name.c_str(), m_ID);
|
||||
} else {
|
||||
Game::logger->Log("Character", "Failed to load xmlData!");
|
||||
//Server::rakServer->CloseConnection(m_ParentUser->GetSystemAddress(), true);
|
||||
//Server::rakServer->CloseConnection(m_ParentUser->GetSystemAddress(), true);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -179,8 +178,7 @@ void Character::DoQuickXMLDataParse() {
|
||||
return;
|
||||
}
|
||||
|
||||
while (bag != nullptr)
|
||||
{
|
||||
while (bag != nullptr) {
|
||||
auto* sib = bag->FirstChildElement();
|
||||
|
||||
while (sib != nullptr) {
|
||||
@@ -201,9 +199,9 @@ void Character::DoQuickXMLDataParse() {
|
||||
|
||||
|
||||
tinyxml2::XMLElement* character = m_Doc->FirstChildElement("obj")->FirstChildElement("char");
|
||||
if (character) {
|
||||
if (character) {
|
||||
character->QueryAttribute("cc", &m_Coins);
|
||||
character->QueryAttribute("gm", &m_GMLevel);
|
||||
character->QueryAttribute("gm", &m_GMLevel);
|
||||
|
||||
uint64_t lzidConcat = 0;
|
||||
if (character->FindAttribute("lzid")) {
|
||||
@@ -221,9 +219,9 @@ void Character::DoQuickXMLDataParse() {
|
||||
}
|
||||
|
||||
if (character->FindAttribute("lnzid")) {
|
||||
uint32_t lastNonInstanceZoneID = 0;
|
||||
character->QueryAttribute("lnzid", &lastNonInstanceZoneID);
|
||||
m_LastNonInstanceZoneID = lastNonInstanceZoneID;
|
||||
uint32_t lastNonInstanceZoneID = 0;
|
||||
character->QueryAttribute("lnzid", &lastNonInstanceZoneID);
|
||||
m_LastNonInstanceZoneID = lastNonInstanceZoneID;
|
||||
}
|
||||
|
||||
if (character->FindAttribute("tscene")) {
|
||||
@@ -260,33 +258,31 @@ void Character::DoQuickXMLDataParse() {
|
||||
character->QueryAttribute("lzry", &m_OriginalRotation.y);
|
||||
character->QueryAttribute("lzrz", &m_OriginalRotation.z);
|
||||
character->QueryAttribute("lzrw", &m_OriginalRotation.w);
|
||||
}
|
||||
}
|
||||
|
||||
auto* flags = m_Doc->FirstChildElement("obj")->FirstChildElement("flag");
|
||||
if (flags) {
|
||||
auto* currentChild = flags->FirstChildElement();
|
||||
while (currentChild) {
|
||||
uint32_t index = 0;
|
||||
uint64_t value = 0;
|
||||
const auto* temp = currentChild->Attribute("v");
|
||||
auto* flags = m_Doc->FirstChildElement("obj")->FirstChildElement("flag");
|
||||
if (flags) {
|
||||
auto* currentChild = flags->FirstChildElement();
|
||||
while (currentChild) {
|
||||
uint32_t index = 0;
|
||||
uint64_t value = 0;
|
||||
const auto* temp = currentChild->Attribute("v");
|
||||
|
||||
index = std::stoul(currentChild->Attribute("id"));
|
||||
value = std::stoull(temp);
|
||||
value = std::stoull(temp);
|
||||
|
||||
m_PlayerFlags.insert(std::make_pair(index, value));
|
||||
currentChild = currentChild->NextSiblingElement();
|
||||
}
|
||||
}
|
||||
m_PlayerFlags.insert(std::make_pair(index, value));
|
||||
currentChild = currentChild->NextSiblingElement();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Character::UnlockEmote(int emoteID)
|
||||
{
|
||||
void Character::UnlockEmote(int emoteID) {
|
||||
m_UnlockedEmotes.push_back(emoteID);
|
||||
GameMessages::SendSetEmoteLockState(EntityManager::Instance()->GetEntity(m_ObjectID), false, emoteID);
|
||||
}
|
||||
|
||||
void Character::SetBuildMode(bool buildMode)
|
||||
{
|
||||
void Character::SetBuildMode(bool buildMode) {
|
||||
m_BuildMode = buildMode;
|
||||
|
||||
auto* controller = dZoneManager::Instance()->GetZoneControlObject();
|
||||
@@ -295,14 +291,14 @@ void Character::SetBuildMode(bool buildMode)
|
||||
}
|
||||
|
||||
void Character::SaveXMLToDatabase() {
|
||||
if (!m_Doc) return;
|
||||
if (!m_Doc) return;
|
||||
|
||||
//For metrics, we'll record the time it took to save:
|
||||
auto start = std::chrono::system_clock::now();
|
||||
//For metrics, we'll record the time it took to save:
|
||||
auto start = std::chrono::system_clock::now();
|
||||
|
||||
tinyxml2::XMLElement* character = m_Doc->FirstChildElement("obj")->FirstChildElement("char");
|
||||
if (character) {
|
||||
character->SetAttribute("gm", m_GMLevel);
|
||||
tinyxml2::XMLElement* character = m_Doc->FirstChildElement("obj")->FirstChildElement("char");
|
||||
if (character) {
|
||||
character->SetAttribute("gm", m_GMLevel);
|
||||
character->SetAttribute("cc", m_Coins);
|
||||
|
||||
// lzid garbage, binary concat of zoneID, zoneInstance and zoneClone
|
||||
@@ -333,31 +329,31 @@ void Character::SaveXMLToDatabase() {
|
||||
}
|
||||
|
||||
character->LinkEndChild(emotes);
|
||||
}
|
||||
}
|
||||
|
||||
//Export our flags:
|
||||
auto* flags = m_Doc->FirstChildElement("obj")->FirstChildElement("flag");
|
||||
//Export our flags:
|
||||
auto* flags = m_Doc->FirstChildElement("obj")->FirstChildElement("flag");
|
||||
if (!flags) {
|
||||
flags = m_Doc->NewElement("flag"); //Create a flags tag if we don't have one
|
||||
m_Doc->FirstChildElement("obj")->LinkEndChild(flags); //Link it to the obj tag so we can find next time
|
||||
}
|
||||
|
||||
flags->DeleteChildren(); //Clear it if we have anything, so that we can fill it up again without dupes
|
||||
for (std::pair<uint32_t, uint64_t> flag : m_PlayerFlags) {
|
||||
auto* f = m_Doc->NewElement("f");
|
||||
f->SetAttribute("id", flag.first);
|
||||
flags->DeleteChildren(); //Clear it if we have anything, so that we can fill it up again without dupes
|
||||
for (std::pair<uint32_t, uint64_t> flag : m_PlayerFlags) {
|
||||
auto* f = m_Doc->NewElement("f");
|
||||
f->SetAttribute("id", flag.first);
|
||||
|
||||
//Because of the joy that is tinyxml2, it doesn't offer a function to set a uint64 as an attribute.
|
||||
//Only signed 64-bits ints would work.
|
||||
std::string v = std::to_string(flag.second);
|
||||
f->SetAttribute("v", v.c_str());
|
||||
//Because of the joy that is tinyxml2, it doesn't offer a function to set a uint64 as an attribute.
|
||||
//Only signed 64-bits ints would work.
|
||||
std::string v = std::to_string(flag.second);
|
||||
f->SetAttribute("v", v.c_str());
|
||||
|
||||
flags->LinkEndChild(f);
|
||||
}
|
||||
|
||||
SaveXmlRespawnCheckpoints();
|
||||
|
||||
//Call upon the entity to update our xmlDoc:
|
||||
//Call upon the entity to update our xmlDoc:
|
||||
if (!m_OurEntity) {
|
||||
Game::logger->Log("Character", "We didn't have an entity set while saving! CHARACTER WILL NOT BE SAVED!");
|
||||
return;
|
||||
@@ -365,22 +361,22 @@ void Character::SaveXMLToDatabase() {
|
||||
|
||||
m_OurEntity->UpdateXMLDoc(m_Doc);
|
||||
|
||||
//Dump our xml into m_XMLData:
|
||||
auto* printer = new tinyxml2::XMLPrinter(0, true, 0);
|
||||
m_Doc->Print(printer);
|
||||
m_XMLData = printer->CStr();
|
||||
//Dump our xml into m_XMLData:
|
||||
auto* printer = new tinyxml2::XMLPrinter(0, true, 0);
|
||||
m_Doc->Print(printer);
|
||||
m_XMLData = printer->CStr();
|
||||
|
||||
//Finally, save to db:
|
||||
//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;
|
||||
stmt->setString(1, m_XMLData.c_str());
|
||||
stmt->setUInt(2, m_ID);
|
||||
stmt->execute();
|
||||
delete stmt;
|
||||
|
||||
//For metrics, log the time it took to save:
|
||||
auto end = std::chrono::system_clock::now();
|
||||
std::chrono::duration<double> elapsed = end - start;
|
||||
Game::logger->Log("Character", "Saved character to Database in: %fs", elapsed.count());
|
||||
//For metrics, log the time it took to save:
|
||||
auto end = std::chrono::system_clock::now();
|
||||
std::chrono::duration<double> elapsed = end - start;
|
||||
Game::logger->Log("Character", "Saved character to Database in: %fs", elapsed.count());
|
||||
|
||||
delete printer;
|
||||
}
|
||||
@@ -389,51 +385,47 @@ void Character::SetPlayerFlag(const uint32_t flagId, const bool value) {
|
||||
// If the flag is already set, we don't have to recalculate it
|
||||
if (GetPlayerFlag(flagId) == value) return;
|
||||
|
||||
if (value)
|
||||
{
|
||||
if (value) {
|
||||
// Update the mission component:
|
||||
auto* player = EntityManager::Instance()->GetEntity(m_ObjectID);
|
||||
|
||||
if (player != nullptr)
|
||||
{
|
||||
if (player != nullptr) {
|
||||
auto* missionComponent = player->GetComponent<MissionComponent>();
|
||||
|
||||
if (missionComponent != nullptr)
|
||||
{
|
||||
if (missionComponent != nullptr) {
|
||||
missionComponent->Progress(MissionTaskType::MISSION_TASK_TYPE_PLAYER_FLAG, flagId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate the index first
|
||||
auto flagIndex = uint32_t(std::floor(flagId / 64));
|
||||
// Calculate the index first
|
||||
auto flagIndex = uint32_t(std::floor(flagId / 64));
|
||||
|
||||
const auto shiftedValue = 1ULL << flagId % 64;
|
||||
const auto shiftedValue = 1ULL << flagId % 64;
|
||||
|
||||
auto it = m_PlayerFlags.find(flagIndex);
|
||||
auto it = m_PlayerFlags.find(flagIndex);
|
||||
|
||||
// Check if flag index exists
|
||||
if (it != m_PlayerFlags.end())
|
||||
{
|
||||
// Update the value
|
||||
if (value) {
|
||||
it->second |= shiftedValue;
|
||||
} else {
|
||||
it->second &= ~shiftedValue;
|
||||
}
|
||||
} else {
|
||||
if (value) {
|
||||
// Otherwise, insert the value
|
||||
uint64_t flagValue = 0;
|
||||
if (it != m_PlayerFlags.end()) {
|
||||
// Update the value
|
||||
if (value) {
|
||||
it->second |= shiftedValue;
|
||||
} else {
|
||||
it->second &= ~shiftedValue;
|
||||
}
|
||||
} else {
|
||||
if (value) {
|
||||
// Otherwise, insert the value
|
||||
uint64_t flagValue = 0;
|
||||
|
||||
flagValue |= shiftedValue;
|
||||
|
||||
m_PlayerFlags.insert(std::make_pair(flagIndex, flagValue));
|
||||
}
|
||||
}
|
||||
m_PlayerFlags.insert(std::make_pair(flagIndex, flagValue));
|
||||
}
|
||||
}
|
||||
|
||||
// Notify the client that a flag has changed server-side
|
||||
GameMessages::SendNotifyClientFlagChange(m_ObjectID, flagId, value, m_ParentUser->GetSystemAddress());
|
||||
// Notify the client that a flag has changed server-side
|
||||
GameMessages::SendNotifyClientFlagChange(m_ObjectID, flagId, value, m_ParentUser->GetSystemAddress());
|
||||
}
|
||||
|
||||
bool Character::GetPlayerFlag(const uint32_t flagId) const {
|
||||
@@ -458,40 +450,37 @@ void Character::SetRetroactiveFlags() {
|
||||
}
|
||||
}
|
||||
|
||||
void Character::SaveXmlRespawnCheckpoints()
|
||||
{
|
||||
//Export our respawn points:
|
||||
auto* points = m_Doc->FirstChildElement("obj")->FirstChildElement("res");
|
||||
void Character::SaveXmlRespawnCheckpoints() {
|
||||
//Export our respawn points:
|
||||
auto* points = m_Doc->FirstChildElement("obj")->FirstChildElement("res");
|
||||
if (!points) {
|
||||
points = m_Doc->NewElement("res");
|
||||
m_Doc->FirstChildElement("obj")->LinkEndChild(points);
|
||||
}
|
||||
|
||||
points->DeleteChildren();
|
||||
for (const auto& point : m_WorldRespawnCheckpoints) {
|
||||
auto* r = m_Doc->NewElement("r");
|
||||
r->SetAttribute("w", point.first);
|
||||
points->DeleteChildren();
|
||||
for (const auto& point : m_WorldRespawnCheckpoints) {
|
||||
auto* r = m_Doc->NewElement("r");
|
||||
r->SetAttribute("w", point.first);
|
||||
|
||||
r->SetAttribute("x", point.second.x);
|
||||
r->SetAttribute("y", point.second.y);
|
||||
r->SetAttribute("z", point.second.z);
|
||||
r->SetAttribute("x", point.second.x);
|
||||
r->SetAttribute("y", point.second.y);
|
||||
r->SetAttribute("z", point.second.z);
|
||||
|
||||
points->LinkEndChild(r);
|
||||
}
|
||||
}
|
||||
|
||||
void Character::LoadXmlRespawnCheckpoints()
|
||||
{
|
||||
void Character::LoadXmlRespawnCheckpoints() {
|
||||
m_WorldRespawnCheckpoints.clear();
|
||||
|
||||
auto* points = m_Doc->FirstChildElement("obj")->FirstChildElement("res");
|
||||
auto* points = m_Doc->FirstChildElement("obj")->FirstChildElement("res");
|
||||
if (!points) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto* r = points->FirstChildElement("r");
|
||||
while (r != nullptr)
|
||||
{
|
||||
while (r != nullptr) {
|
||||
int32_t map = 0;
|
||||
NiPoint3 point = NiPoint3::ZERO;
|
||||
|
||||
@@ -507,8 +496,7 @@ void Character::LoadXmlRespawnCheckpoints()
|
||||
|
||||
}
|
||||
|
||||
void Character::OnZoneLoad()
|
||||
{
|
||||
void Character::OnZoneLoad() {
|
||||
if (m_OurEntity == nullptr) {
|
||||
return;
|
||||
}
|
||||
@@ -550,23 +538,19 @@ void Character::OnZoneLoad()
|
||||
}
|
||||
}
|
||||
|
||||
PermissionMap Character::GetPermissionMap() const
|
||||
{
|
||||
PermissionMap Character::GetPermissionMap() const {
|
||||
return m_PermissionMap;
|
||||
}
|
||||
|
||||
bool Character::HasPermission(PermissionMap permission) const
|
||||
{
|
||||
bool Character::HasPermission(PermissionMap permission) const {
|
||||
return (static_cast<uint64_t>(m_PermissionMap) & static_cast<uint64_t>(permission)) != 0;
|
||||
}
|
||||
|
||||
void Character::SetRespawnPoint(LWOMAPID map, const NiPoint3& point)
|
||||
{
|
||||
void Character::SetRespawnPoint(LWOMAPID map, const NiPoint3& point) {
|
||||
m_WorldRespawnCheckpoints[map] = point;
|
||||
}
|
||||
|
||||
const NiPoint3& Character::GetRespawnPoint(LWOMAPID map) const
|
||||
{
|
||||
const NiPoint3& Character::GetRespawnPoint(LWOMAPID map) const {
|
||||
const auto& pair = m_WorldRespawnCheckpoints.find(map);
|
||||
|
||||
if (pair == m_WorldRespawnCheckpoints.end()) return NiPoint3::ZERO;
|
||||
@@ -575,8 +559,7 @@ const NiPoint3& Character::GetRespawnPoint(LWOMAPID map) const
|
||||
}
|
||||
|
||||
void Character::SetCoins(int64_t newCoins, eLootSourceType lootSource) {
|
||||
if (newCoins < 0)
|
||||
{
|
||||
if (newCoins < 0) {
|
||||
newCoins = 0;
|
||||
}
|
||||
|
||||
@@ -585,22 +568,19 @@ void Character::SetCoins(int64_t newCoins, eLootSourceType lootSource) {
|
||||
GameMessages::SendSetCurrency(EntityManager::Instance()->GetEntity(m_ObjectID), m_Coins, 0, 0, 0, 0, true, lootSource);
|
||||
}
|
||||
|
||||
bool Character::HasBeenToWorld(LWOMAPID mapID) const
|
||||
{
|
||||
bool Character::HasBeenToWorld(LWOMAPID mapID) const {
|
||||
return m_WorldRespawnCheckpoints.find(mapID) != m_WorldRespawnCheckpoints.end();
|
||||
}
|
||||
|
||||
void Character::SendMuteNotice() const
|
||||
{
|
||||
void Character::SendMuteNotice() const {
|
||||
if (!m_ParentUser->GetIsMuted()) return;
|
||||
|
||||
time_t expire = m_ParentUser->GetMuteExpire();
|
||||
|
||||
char buffer[32] = "brought up for review.\0";
|
||||
|
||||
if (expire != 1)
|
||||
{
|
||||
std::tm * ptm = std::localtime(&expire);
|
||||
if (expire != 1) {
|
||||
std::tm* ptm = std::localtime(&expire);
|
||||
// Format: Mo, 15.06.2009 20:20:00
|
||||
std::strftime(buffer, 32, "%a, %d.%m.%Y %H:%M:%S", ptm);
|
||||
}
|
||||
|
Reference in New Issue
Block a user