mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-13 10:31:29 +00:00
[Bug Fix] Fix use-after-free corruption with some DB calls (#1335)
This commit is contained in:
parent
c063d9512e
commit
4358e24dab
@ -870,36 +870,40 @@ void Database::GetCharName(uint32 char_id, char* name) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* Database::GetCharNameByID(uint32 char_id) {
|
std::string Database::GetCharNameByID(uint32 char_id) {
|
||||||
std::string query = fmt::format("SELECT `name` FROM `character_data` WHERE id = {}", char_id);
|
std::string query = fmt::format("SELECT `name` FROM `character_data` WHERE id = {}", char_id);
|
||||||
auto results = QueryDatabase(query);
|
auto results = QueryDatabase(query);
|
||||||
|
std::string res;
|
||||||
|
|
||||||
if (!results.Success()) {
|
if (!results.Success()) {
|
||||||
return "";
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (results.RowCount() == 0) {
|
if (results.RowCount() == 0) {
|
||||||
return "";
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto row = results.begin();
|
auto row = results.begin();
|
||||||
return row[0];
|
res = row[0];
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* Database::GetNPCNameByID(uint32 npc_id) {
|
std::string Database::GetNPCNameByID(uint32 npc_id) {
|
||||||
std::string query = fmt::format("SELECT `name` FROM `npc_types` WHERE id = {}", npc_id);
|
std::string query = fmt::format("SELECT `name` FROM `npc_types` WHERE id = {}", npc_id);
|
||||||
auto results = QueryDatabase(query);
|
auto results = QueryDatabase(query);
|
||||||
|
std::string res;
|
||||||
|
|
||||||
if (!results.Success()) {
|
if (!results.Success()) {
|
||||||
return "";
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (results.RowCount() == 0) {
|
if (results.RowCount() == 0) {
|
||||||
return "";
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto row = results.begin();
|
auto row = results.begin();
|
||||||
return row[0];
|
res = row[0];
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Database::LoadVariables() {
|
bool Database::LoadVariables() {
|
||||||
|
|||||||
@ -138,8 +138,8 @@ public:
|
|||||||
|
|
||||||
void GetAccountName(uint32 accountid, char* name, uint32* oLSAccountID = 0);
|
void GetAccountName(uint32 accountid, char* name, uint32* oLSAccountID = 0);
|
||||||
void GetCharName(uint32 char_id, char* name);
|
void GetCharName(uint32 char_id, char* name);
|
||||||
const char *GetCharNameByID(uint32 char_id);
|
std::string GetCharNameByID(uint32 char_id);
|
||||||
const char *GetNPCNameByID(uint32 npc_id);
|
std::string GetNPCNameByID(uint32 npc_id);
|
||||||
void LoginIP(uint32 AccountID, const char* LoginIP);
|
void LoginIP(uint32 AccountID, const char* LoginIP);
|
||||||
|
|
||||||
/* Instancing */
|
/* Instancing */
|
||||||
|
|||||||
@ -3033,9 +3033,9 @@ XS(XS__getnpcnamebyid) {
|
|||||||
|
|
||||||
dXSTARG;
|
dXSTARG;
|
||||||
uint32 npc_id = (int) SvIV(ST(0));
|
uint32 npc_id = (int) SvIV(ST(0));
|
||||||
const char *npc_name = quest_manager.getnpcnamebyid(npc_id);
|
auto npc_name = quest_manager.getnpcnamebyid(npc_id);
|
||||||
|
|
||||||
sv_setpv(TARG, npc_name);
|
sv_setpv(TARG, npc_name.c_str());
|
||||||
XSprePUSH;
|
XSprePUSH;
|
||||||
PUSHTARG;
|
PUSHTARG;
|
||||||
XSRETURN(1);
|
XSRETURN(1);
|
||||||
@ -3423,8 +3423,9 @@ XS(XS__getcharnamebyid) {
|
|||||||
|
|
||||||
Const_char *RETVAL;
|
Const_char *RETVAL;
|
||||||
uint32 char_id = (int) SvUV(ST(0));
|
uint32 char_id = (int) SvUV(ST(0));
|
||||||
|
auto name = quest_manager.getcharnamebyid(char_id);
|
||||||
|
|
||||||
RETVAL = quest_manager.getcharnamebyid(char_id);
|
RETVAL = name.c_str();
|
||||||
|
|
||||||
sv_setpv(TARG, RETVAL);
|
sv_setpv(TARG, RETVAL);
|
||||||
XSprePUSH;
|
XSprePUSH;
|
||||||
|
|||||||
@ -901,7 +901,7 @@ bool lua_delete_data(std::string bucket_key) {
|
|||||||
return DataBucket::DeleteData(bucket_key);
|
return DataBucket::DeleteData(bucket_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *lua_get_char_name_by_id(uint32 char_id) {
|
std::string lua_get_char_name_by_id(uint32 char_id) {
|
||||||
return database.GetCharNameByID(char_id);
|
return database.GetCharNameByID(char_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -937,7 +937,7 @@ int lua_get_group_id_by_char_id(uint32 char_id) {
|
|||||||
return database.GetGroupIDByCharID(char_id);
|
return database.GetGroupIDByCharID(char_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *lua_get_npc_name_by_id(uint32 npc_id) {
|
std::string lua_get_npc_name_by_id(uint32 npc_id) {
|
||||||
return quest_manager.getnpcnamebyid(npc_id);
|
return quest_manager.getnpcnamebyid(npc_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2781,11 +2781,12 @@ std::string QuestManager::getitemname(uint32 item_id) {
|
|||||||
return item_name;
|
return item_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *QuestManager::getnpcnamebyid(uint32 npc_id) {
|
std::string QuestManager::getnpcnamebyid(uint32 npc_id) {
|
||||||
|
std::string res;
|
||||||
if (npc_id > 0) {
|
if (npc_id > 0) {
|
||||||
return database.GetNPCNameByID(npc_id);
|
res = database.GetNPCNameByID(npc_id);
|
||||||
}
|
}
|
||||||
return "";
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16 QuestManager::CreateInstance(const char *zone, int16 version, uint32 duration)
|
uint16 QuestManager::CreateInstance(const char *zone, int16 version, uint32 duration)
|
||||||
@ -2991,11 +2992,12 @@ std::string QuestManager::saylink(char *saylink_text, bool silent, const char *l
|
|||||||
return EQ::SayLinkEngine::GenerateQuestSaylink(saylink_text, silent, link_name);
|
return EQ::SayLinkEngine::GenerateQuestSaylink(saylink_text, silent, link_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* QuestManager::getcharnamebyid(uint32 char_id) {
|
std::string QuestManager::getcharnamebyid(uint32 char_id) {
|
||||||
|
std::string res;
|
||||||
if (char_id > 0) {
|
if (char_id > 0) {
|
||||||
return database.GetCharNameByID(char_id);
|
res = database.GetCharNameByID(char_id);
|
||||||
}
|
}
|
||||||
return "";
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 QuestManager::getcharidbyname(const char* name) {
|
uint32 QuestManager::getcharidbyname(const char* name) {
|
||||||
|
|||||||
@ -265,7 +265,7 @@ public:
|
|||||||
void FlagInstanceByRaidLeader(uint32 zone, int16 version);
|
void FlagInstanceByRaidLeader(uint32 zone, int16 version);
|
||||||
const char* varlink(char* perltext, int item_id);
|
const char* varlink(char* perltext, int item_id);
|
||||||
std::string saylink(char *saylink_text, bool silent, const char *link_name);
|
std::string saylink(char *saylink_text, bool silent, const char *link_name);
|
||||||
const char* getcharnamebyid(uint32 char_id);
|
std::string getcharnamebyid(uint32 char_id);
|
||||||
uint32 getcharidbyname(const char* name);
|
uint32 getcharidbyname(const char* name);
|
||||||
std::string getclassname(uint8 class_id, uint8 level = 0);
|
std::string getclassname(uint8 class_id, uint8 level = 0);
|
||||||
int getcurrencyid(uint32 item_id);
|
int getcurrencyid(uint32 item_id);
|
||||||
@ -273,7 +273,7 @@ public:
|
|||||||
const char* getguildnamebyid(int guild_id);
|
const char* getguildnamebyid(int guild_id);
|
||||||
int getguildidbycharid(uint32 char_id);
|
int getguildidbycharid(uint32 char_id);
|
||||||
int getgroupidbycharid(uint32 char_id);
|
int getgroupidbycharid(uint32 char_id);
|
||||||
const char* getnpcnamebyid(uint32 npc_id);
|
std::string getnpcnamebyid(uint32 npc_id);
|
||||||
int getraididbycharid(uint32 char_id);
|
int getraididbycharid(uint32 char_id);
|
||||||
void SetRunning(bool val);
|
void SetRunning(bool val);
|
||||||
bool IsRunning();
|
bool IsRunning();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user