mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-01-21 04:07:01 +00:00
Use proper session flag checks (#1734)
This commit is contained in:
parent
d860552776
commit
1b3cdc6d9c
@ -0,0 +1,38 @@
|
|||||||
|
#include "CDPlayerFlagsTable.h"
|
||||||
|
|
||||||
|
#include "CDClientDatabase.h"
|
||||||
|
|
||||||
|
namespace CDPlayerFlagsTable {
|
||||||
|
Table entries;
|
||||||
|
|
||||||
|
void ReadEntry(CppSQLite3Query& table) {
|
||||||
|
Entry entry;
|
||||||
|
entry.sessionOnly = table.getIntField("SessionOnly") == 1;
|
||||||
|
entry.onlySetByServer = table.getIntField("OnlySetByServer") == 1;
|
||||||
|
entry.sessionZoneOnly = table.getIntField("SessionZoneOnly") == 1;
|
||||||
|
entries[table.getIntField("id")] = entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoadValuesFromDatabase() {
|
||||||
|
auto table = CDClientDatabase::ExecuteQuery("SELECT * FROM PlayerFlags;");
|
||||||
|
|
||||||
|
if (!table.eof()) {
|
||||||
|
do {
|
||||||
|
ReadEntry(table);
|
||||||
|
} while (!table.nextRow());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::optional<Entry> GetEntry(const FlagId flagId) {
|
||||||
|
if (!entries.contains(flagId)) {
|
||||||
|
auto table = CDClientDatabase::CreatePreppedStmt("SELECT * FROM PlayerFlags WHERE id = ?;");
|
||||||
|
table.bind(1, static_cast<int>(flagId));
|
||||||
|
auto result = table.execQuery();
|
||||||
|
if (!result.eof()) {
|
||||||
|
ReadEntry(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return entries[flagId];
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
#ifndef CDPLAYERFLAGSTABLE_H
|
||||||
|
#define CDPLAYERFLAGSTABLE_H
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
|
namespace CDPlayerFlagsTable {
|
||||||
|
struct Entry {
|
||||||
|
bool sessionOnly{};
|
||||||
|
bool onlySetByServer{};
|
||||||
|
bool sessionZoneOnly{};
|
||||||
|
};
|
||||||
|
|
||||||
|
using FlagId = uint32_t;
|
||||||
|
using Table = std::map<FlagId, std::optional<Entry>>;
|
||||||
|
|
||||||
|
void LoadValuesFromDatabase();
|
||||||
|
const std::optional<Entry> GetEntry(const FlagId flagId);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //!CDPLAYERFLAGSTABLE_H
|
@ -25,6 +25,7 @@ set(DDATABASE_CDCLIENTDATABASE_CDCLIENTTABLES_SOURCES "CDActivitiesTable.cpp"
|
|||||||
"CDObjectsTable.cpp"
|
"CDObjectsTable.cpp"
|
||||||
"CDPetComponentTable.cpp"
|
"CDPetComponentTable.cpp"
|
||||||
"CDPackageComponentTable.cpp"
|
"CDPackageComponentTable.cpp"
|
||||||
|
"CDPlayerFlagsTable.cpp"
|
||||||
"CDPhysicsComponentTable.cpp"
|
"CDPhysicsComponentTable.cpp"
|
||||||
"CDPropertyEntranceComponentTable.cpp"
|
"CDPropertyEntranceComponentTable.cpp"
|
||||||
"CDPropertyTemplateTable.cpp"
|
"CDPropertyTemplateTable.cpp"
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "eObjectBits.h"
|
#include "eObjectBits.h"
|
||||||
#include "eGameMasterLevel.h"
|
#include "eGameMasterLevel.h"
|
||||||
#include "ePlayerFlag.h"
|
#include "ePlayerFlag.h"
|
||||||
|
#include "CDPlayerFlagsTable.h"
|
||||||
|
|
||||||
Character::Character(uint32_t id, User* parentUser) {
|
Character::Character(uint32_t id, User* parentUser) {
|
||||||
//First load the name, etc:
|
//First load the name, etc:
|
||||||
@ -231,6 +232,12 @@ void Character::SetBuildMode(bool buildMode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Character::SaveXMLToDatabase() {
|
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());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//For metrics, we'll record the time it took to save:
|
//For metrics, we'll record the time it took to save:
|
||||||
auto start = std::chrono::system_clock::now();
|
auto start = std::chrono::system_clock::now();
|
||||||
|
|
||||||
@ -277,39 +284,19 @@ void Character::SaveXMLToDatabase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
flags->DeleteChildren(); //Clear it if we have anything, so that we can fill it up again without dupes
|
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) {
|
for (const auto& [index, flagBucket] : m_PlayerFlags) {
|
||||||
auto* f = m_Doc.NewElement("f");
|
auto* f = flags->InsertNewChildElement("f");
|
||||||
f->SetAttribute("id", flag.first);
|
f->SetAttribute("id", index);
|
||||||
|
f->SetAttribute("v", flagBucket);
|
||||||
//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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prevents the news feed from showing up on world transfers
|
for (const auto& sessionFlag : m_SessionFlags) {
|
||||||
if (GetPlayerFlag(ePlayerFlag::IS_NEWS_SCREEN_VISIBLE)) {
|
auto* s = flags->InsertNewChildElement("s");
|
||||||
auto* s = m_Doc.NewElement("s");
|
s->SetAttribute("si", sessionFlag);
|
||||||
s->SetAttribute("si", ePlayerFlag::IS_NEWS_SCREEN_VISIBLE);
|
|
||||||
flags->LinkEndChild(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (GetPlayerFlag(ePlayerFlag::EQUPPED_TRIAL_FACTION_GEAR)) {
|
|
||||||
auto* s = m_Doc.NewElement("s");
|
|
||||||
s->SetAttribute("si", ePlayerFlag::EQUPPED_TRIAL_FACTION_GEAR);
|
|
||||||
flags->LinkEndChild(s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SaveXmlRespawnCheckpoints();
|
SaveXmlRespawnCheckpoints();
|
||||||
|
|
||||||
//Call upon the entity to update our xmlDoc:
|
|
||||||
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());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_OurEntity->UpdateXMLDoc(m_Doc);
|
m_OurEntity->UpdateXMLDoc(m_Doc);
|
||||||
|
|
||||||
WriteToDatabase();
|
WriteToDatabase();
|
||||||
@ -329,8 +316,8 @@ void Character::SetIsNewLogin() {
|
|||||||
while (currentChild) {
|
while (currentChild) {
|
||||||
auto* nextChild = currentChild->NextSiblingElement();
|
auto* nextChild = currentChild->NextSiblingElement();
|
||||||
if (currentChild->Attribute("si")) {
|
if (currentChild->Attribute("si")) {
|
||||||
|
LOG("Removed session flag (%s) from character %i:%s, saving character to database", currentChild->Attribute("si"), GetID(), GetName().c_str());
|
||||||
flags->DeleteChild(currentChild);
|
flags->DeleteChild(currentChild);
|
||||||
LOG("Removed isLoggedIn flag from character %i:%s, saving character to database", GetID(), GetName().c_str());
|
|
||||||
WriteToDatabase();
|
WriteToDatabase();
|
||||||
}
|
}
|
||||||
currentChild = nextChild;
|
currentChild = nextChild;
|
||||||
@ -363,7 +350,9 @@ void Character::SetPlayerFlag(const uint32_t flagId, const bool value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flagId == EQUPPED_TRIAL_FACTION_GEAR || flagId == IS_NEWS_SCREEN_VISIBLE) {
|
const auto flagEntry = CDPlayerFlagsTable::GetEntry(flagId);
|
||||||
|
|
||||||
|
if (flagEntry && flagEntry->sessionOnly) {
|
||||||
if (value) m_SessionFlags.insert(flagId);
|
if (value) m_SessionFlags.insert(flagId);
|
||||||
else m_SessionFlags.erase(flagId);
|
else m_SessionFlags.erase(flagId);
|
||||||
} else {
|
} else {
|
||||||
@ -402,8 +391,8 @@ bool Character::GetPlayerFlag(const uint32_t flagId) const {
|
|||||||
|
|
||||||
bool toReturn = false; //by def, return false.
|
bool toReturn = false; //by def, return false.
|
||||||
|
|
||||||
// TODO make actual session flag checker using flags table in database.
|
const auto flagEntry = CDPlayerFlagsTable::GetEntry(flagId);
|
||||||
if (flagId == EQUPPED_TRIAL_FACTION_GEAR || flagId == IS_NEWS_SCREEN_VISIBLE) {
|
if (flagEntry && flagEntry->sessionOnly) {
|
||||||
toReturn = m_SessionFlags.contains(flagId);
|
toReturn = m_SessionFlags.contains(flagId);
|
||||||
} else {
|
} else {
|
||||||
// Calculate the index first
|
// Calculate the index first
|
||||||
|
6
thirdparty/SQLite/CppSQLite3.cpp
vendored
6
thirdparty/SQLite/CppSQLite3.cpp
vendored
@ -573,16 +573,18 @@ bool CppSQLite3Query::eof()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CppSQLite3Query::nextRow()
|
bool CppSQLite3Query::nextRow()
|
||||||
{
|
{
|
||||||
checkVM();
|
checkVM();
|
||||||
|
|
||||||
int nRet = sqlite3_step(mpVM);
|
int nRet = sqlite3_step(mpVM);
|
||||||
|
|
||||||
|
bool bRet = true;
|
||||||
if (nRet == SQLITE_DONE)
|
if (nRet == SQLITE_DONE)
|
||||||
{
|
{
|
||||||
// no rows
|
// no rows
|
||||||
mbEof = true;
|
mbEof = true;
|
||||||
|
bRet = false;
|
||||||
}
|
}
|
||||||
else if (nRet == SQLITE_ROW)
|
else if (nRet == SQLITE_ROW)
|
||||||
{
|
{
|
||||||
@ -590,6 +592,7 @@ void CppSQLite3Query::nextRow()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
bRet = false;
|
||||||
nRet = sqlite3_finalize(mpVM);
|
nRet = sqlite3_finalize(mpVM);
|
||||||
mpVM = 0;
|
mpVM = 0;
|
||||||
const char* szError = sqlite3_errmsg(mpDB);
|
const char* szError = sqlite3_errmsg(mpDB);
|
||||||
@ -597,6 +600,7 @@ void CppSQLite3Query::nextRow()
|
|||||||
(char*)szError,
|
(char*)szError,
|
||||||
DONT_DELETE_MSG);
|
DONT_DELETE_MSG);
|
||||||
}
|
}
|
||||||
|
return bRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
10
thirdparty/SQLite/CppSQLite3.h
vendored
10
thirdparty/SQLite/CppSQLite3.h
vendored
@ -165,7 +165,8 @@ public:
|
|||||||
|
|
||||||
bool eof();
|
bool eof();
|
||||||
|
|
||||||
void nextRow();
|
// Returns true if there is another row to read, false otherwise.
|
||||||
|
bool nextRow();
|
||||||
|
|
||||||
void finalize();
|
void finalize();
|
||||||
|
|
||||||
@ -207,6 +208,9 @@ public:
|
|||||||
int getIntField(int nField, int nNullValue=0);
|
int getIntField(int nField, int nNullValue=0);
|
||||||
int getIntField(const char* szField, int nNullValue=0);
|
int getIntField(const char* szField, int nNullValue=0);
|
||||||
|
|
||||||
|
sqlite_int64 getInt64Field(int nField, sqlite_int64 nNullValue=0);
|
||||||
|
sqlite_int64 getInt64Field(const char* szField, sqlite_int64 nNullValue=0);
|
||||||
|
|
||||||
double getFloatField(int nField, double fNullValue=0.0);
|
double getFloatField(int nField, double fNullValue=0.0);
|
||||||
double getFloatField(const char* szField, double fNullValue=0.0);
|
double getFloatField(const char* szField, double fNullValue=0.0);
|
||||||
|
|
||||||
@ -218,6 +222,9 @@ public:
|
|||||||
|
|
||||||
void setRow(int nRow);
|
void setRow(int nRow);
|
||||||
|
|
||||||
|
// Returns true if there is another row to read, false otherwise.
|
||||||
|
bool nextRow();
|
||||||
|
|
||||||
void finalize();
|
void finalize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -226,6 +233,7 @@ private:
|
|||||||
|
|
||||||
int mnCols;
|
int mnCols;
|
||||||
int mnRows;
|
int mnRows;
|
||||||
|
bool mbEof;
|
||||||
int mnCurrentRow;
|
int mnCurrentRow;
|
||||||
char** mpaszResults;
|
char** mpaszResults;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user