Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 34 additions & 20 deletions common/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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');
}
};
2 changes: 2 additions & 0 deletions common/database.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ class Database : public DBcore {

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;
Expand Down
10 changes: 5 additions & 5 deletions common/repositories/base/base_group_leaders_repository.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class BaseGroupLeadersRepository {
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) + "'");
Expand Down Expand Up @@ -222,7 +222,7 @@ class BaseGroupLeadersRepository {
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) + "'");
Expand Down Expand Up @@ -260,7 +260,7 @@ class BaseGroupLeadersRepository {
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) + "'");
Expand Down Expand Up @@ -418,7 +418,7 @@ class BaseGroupLeadersRepository {
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) + "'");
Expand Down Expand Up @@ -449,7 +449,7 @@ class BaseGroupLeadersRepository {
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) + "'");
Expand Down
15 changes: 14 additions & 1 deletion common/repositories/group_leaders_repository.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

class GroupLeadersRepository: public BaseGroupLeadersRepository {
public:

/**
* This file was auto generated and can be modified and extended upon
*
Expand Down Expand Up @@ -53,6 +52,20 @@ class GroupLeadersRepository: public BaseGroupLeadersRepository {
)
);
}

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
9 changes: 9 additions & 0 deletions utils/scripts/generators/repository-generator.pl
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@
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) {
Expand Down Expand Up @@ -296,6 +299,9 @@
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",
Expand All @@ -312,6 +318,9 @@
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);
Expand Down
20 changes: 9 additions & 11 deletions zone/groups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down