[Bug Fix] GLAA fix after database.cpp updates (#4277)

* Hopefully fix glaa

* Potential Fix for GroupAA Issues

This seems to resolve the GroupAA issue.  Tested with two characters joining a group.  Functions the same as previous builds like 22.45, 22.46, etc.

* Fix for GLAA issue - For testing.

* Redo fix for GLAA

* Cleanup GLAA fix and move savng to repo

---------

Co-authored-by: Akkadius <akkadius1@gmail.com>
This commit is contained in:
Mitch Freeman 2024-04-20 22:13:17 -03:00 committed by GitHub
parent 7b44745c67
commit 64fefaebe4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 73 additions and 37 deletions

View File

@ -1125,27 +1125,27 @@ std::string Database::GetGroupLeaderForLogin(const std::string& character_name)
return e.gid ? e.leadername : std::string();
}
void Database::SetGroupLeaderName(uint32 group_id, const std::string& name)
void Database::SetGroupLeaderName(uint32 group_id, const std::string &name)
{
auto e = GroupLeadersRepository::FindOne(*this, group_id);
auto e = GroupLeadersRepository::FindOne(*this, group_id);
e.leadername = name;
e.leadername = name;
if (e.gid) {
GroupLeadersRepository::UpdateOne(*this, e);
return;
}
if (e.gid) {
GroupLeadersRepository::UpdateOne(*this, e);
return;
}
e.gid = group_id;
e.marknpc = std::string();
e.leadershipaa = std::string();
e.maintank = std::string();
e.assist = std::string();
e.puller = std::string();
e.mentoree = std::string();
e.mentor_percent = 0;
e.gid = group_id;
e.marknpc = std::string();
e.leadershipaa = std::string();
e.maintank = std::string();
e.assist = std::string();
e.puller = std::string();
e.mentoree = std::string();
e.mentor_percent = 0;
GroupLeadersRepository::InsertOne(*this, e);
GroupLeadersRepository::ReplaceOne(*this, e);
}
std::string Database::GetGroupLeaderName(uint32 group_id)
@ -1178,7 +1178,7 @@ char* Database::GetGroupLeadershipInfo(
GroupLeadershipAA_Struct* GLAA
)
{
const auto& e = GroupLeadersRepository::FindOne(*this, group_id);
auto e = GroupLeadersRepository::FindOne(*this, group_id);
if (!e.gid) {
if (leaderbuf) {
@ -1239,9 +1239,9 @@ char* Database::GetGroupLeadershipInfo(
if (mentor_percent) {
*mentor_percent = e.mentor_percent;
}
if (GLAA && e.leadershipaa.length() == sizeof(GroupLeadershipAA_Struct)) {
memcpy(GLAA, e.leadershipaa.c_str(), sizeof(GroupLeadershipAA_Struct));
if(GLAA && e.leadershipaa.length() == sizeof(GroupLeadershipAA_Struct)) {
Decode(e.leadershipaa);
memcpy(GLAA, e.leadershipaa.data(), sizeof(GroupLeadershipAA_Struct));
}
return leaderbuf;
@ -2028,3 +2028,17 @@ void Database::SourceSqlFromUrl(const std::string& url)
LogError("URI parser error [{}]", iae.what());
}
}
void Database::Encode(std::string &in)
{
for(int i = 0; i < in.length(); i++) {
in.at(i) += char('0');
}
};
void Database::Decode(std::string &in)
{
for(int i = 0; i < in.length(); i++) {
in.at(i) -= char('0');
}
};

View File

@ -267,6 +267,8 @@ public:
void SourceDatabaseTableFromUrl(const std::string& table_name, const std::string& url);
void SourceSqlFromUrl(const std::string& url);
void Encode(std::string &in);
void Decode(std::string &in);
private:
Mutex Mvarcache;

View File

@ -192,7 +192,7 @@ public:
v.push_back(columns[0] + " = " + std::to_string(e.gid));
v.push_back(columns[1] + " = '" + Strings::Escape(e.leadername) + "'");
v.push_back(columns[2] + " = '" + Strings::Escape(e.marknpc) + "'");
v.push_back(columns[3] + " = '" + Strings::Escape(e.leadershipaa) + "'");
v.push_back(columns[3] + " = '" + e.leadershipaa + "'");
v.push_back(columns[4] + " = '" + Strings::Escape(e.maintank) + "'");
v.push_back(columns[5] + " = '" + Strings::Escape(e.assist) + "'");
v.push_back(columns[6] + " = '" + Strings::Escape(e.puller) + "'");
@ -222,7 +222,7 @@ public:
v.push_back(std::to_string(e.gid));
v.push_back("'" + Strings::Escape(e.leadername) + "'");
v.push_back("'" + Strings::Escape(e.marknpc) + "'");
v.push_back("'" + Strings::Escape(e.leadershipaa) + "'");
v.push_back("'" + e.leadershipaa + "'");
v.push_back("'" + Strings::Escape(e.maintank) + "'");
v.push_back("'" + Strings::Escape(e.assist) + "'");
v.push_back("'" + Strings::Escape(e.puller) + "'");
@ -260,7 +260,7 @@ public:
v.push_back(std::to_string(e.gid));
v.push_back("'" + Strings::Escape(e.leadername) + "'");
v.push_back("'" + Strings::Escape(e.marknpc) + "'");
v.push_back("'" + Strings::Escape(e.leadershipaa) + "'");
v.push_back("'" + e.leadershipaa + "'");
v.push_back("'" + Strings::Escape(e.maintank) + "'");
v.push_back("'" + Strings::Escape(e.assist) + "'");
v.push_back("'" + Strings::Escape(e.puller) + "'");
@ -418,7 +418,7 @@ public:
v.push_back(std::to_string(e.gid));
v.push_back("'" + Strings::Escape(e.leadername) + "'");
v.push_back("'" + Strings::Escape(e.marknpc) + "'");
v.push_back("'" + Strings::Escape(e.leadershipaa) + "'");
v.push_back("'" + e.leadershipaa + "'");
v.push_back("'" + Strings::Escape(e.maintank) + "'");
v.push_back("'" + Strings::Escape(e.assist) + "'");
v.push_back("'" + Strings::Escape(e.puller) + "'");
@ -449,7 +449,7 @@ public:
v.push_back(std::to_string(e.gid));
v.push_back("'" + Strings::Escape(e.leadername) + "'");
v.push_back("'" + Strings::Escape(e.marknpc) + "'");
v.push_back("'" + Strings::Escape(e.leadershipaa) + "'");
v.push_back("'" + e.leadershipaa + "'");
v.push_back("'" + Strings::Escape(e.maintank) + "'");
v.push_back("'" + Strings::Escape(e.assist) + "'");
v.push_back("'" + Strings::Escape(e.puller) + "'");

View File

@ -7,7 +7,6 @@
class GroupLeadersRepository: public BaseGroupLeadersRepository {
public:
/**
* This file was auto generated and can be modified and extended upon
*
@ -53,6 +52,20 @@ public:
)
);
}
static int UpdateLeadershipAA(Database &db, std::string &aa, uint32 group_id)
{
const auto group_leader = GetWhere(db, fmt::format("gid = '{}' LIMIT 1", group_id));
if(group_leader.empty()) {
return 0;
}
db.Encode(aa);
auto m = group_leader[0];
m.leadershipaa = aa;
return UpdateOne(db, m);
}
};
#endif //EQEMU_GROUP_LEADERS_REPOSITORY_H

View File

@ -260,6 +260,9 @@ foreach my $table_to_generate (@tables) {
elsif ((trim($column_default) eq "" || $column_default eq "NULL") && $column_type =~ /text|varchar/i) {
$default_value = '""';
}
elsif ((trim($column_default) eq "" || $column_default eq "NULL") && $column_type =~ /blob/i) {
$default_value = '""';
}
# for datetime values that set default value all zeroed out
if ($default_value =~ /0000-00-00 00:00:00/i) {
@ -296,6 +299,9 @@ foreach my $table_to_generate (@tables) {
elsif ($data_type =~ /datetime|timestamp/) {
$query_value = sprintf('FROM_UNIXTIME(" + (e.%s > 0 ? std::to_string(e.%s) : "null") + ")");', $column_name_formatted, $column_name_formatted);
}
elsif ($data_type =~ /blob/) {
$query_value = sprintf('\'" + e.%s + "\'");', $column_name_formatted);
}
$update_one_entries .= sprintf(
"\t\t" . 'v.push_back(columns[%s] + " = %s' . "\n",
@ -312,6 +318,9 @@ foreach my $table_to_generate (@tables) {
elsif ($data_type =~ /datetime|timestamp/) {
$value = sprintf('"FROM_UNIXTIME(" + (e.%s > 0 ? std::to_string(e.%s) : "null") + ")"', $column_name_formatted, $column_name_formatted);
}
elsif ($data_type =~ /blob/) {
$value = sprintf("\"'\" + e.%s + \"'\"", $column_name_formatted);
}
$insert_one_entries .= sprintf("\t\tv.push_back(%s);\n", $value);
$insert_many_entries .= sprintf("\t\t\tv.push_back(%s);\n", $value);

View File

@ -24,6 +24,8 @@
#include "string_ids.h"
#include "../common/events/player_event_logs.h"
#include "../common/repositories/group_id_repository.h"
#include "../common/repositories/group_leaders_repository.h"
extern EntityList entity_list;
extern WorldServer worldserver;
@ -2103,19 +2105,15 @@ void Group::UnDelegateMarkNPC(const char *OldNPCMarkerName)
void Group::SaveGroupLeaderAA()
{
// Stores the Group Leaders Leadership AA data from the Player Profile as a blob in the group_leaders table.
// This is done so that group members not in the same zone as the Leader still have access to this information.
auto queryBuffer = new char[sizeof(GroupLeadershipAA_Struct) * 2 + 1];
database.DoEscapeString(queryBuffer, (char *)&LeaderAbilities, sizeof(GroupLeadershipAA_Struct));
// Stores the Group Leaders Leadership AA data from the Player Profile as a blob in the group_leaders table.
// This is done so that group members not in the same zone as the Leader still have access to this information.
std::string query = "UPDATE group_leaders SET leadershipaa = '";
query += queryBuffer;
query += StringFormat("' WHERE gid = %i LIMIT 1", GetID());
safe_delete_array(queryBuffer);
auto results = database.QueryDatabase(query);
if (!results.Success())
LogError("Unable to store LeadershipAA: [{}]\n", results.ErrorMessage().c_str());
std::string aa((char *) &LeaderAbilities, sizeof(GroupLeadershipAA_Struct));
auto results = GroupLeadersRepository::UpdateLeadershipAA(database, aa, GetID());
if (!results) {
LogError("Unable to store GroupLeadershipAA for group_id: [{}]", GetID());
}
}
void Group::UnMarkNPC(uint16 ID)