[Repositories] Convert database.cpp to Repositories (#4054)

* [Repositories] Convert database.cpp to Repositories

- Convert all database.cpp methods to repositories where possible.

* Final push.

* Cleanup

* Cleanup

* Update database.h

* Fix crash

* Update database.cpp
This commit is contained in:
Alex King
2024-03-23 20:30:56 -04:00
committed by GitHub
parent d7ea290b6b
commit 523ba30d81
23 changed files with 1287 additions and 1631 deletions
+28 -10
View File
@@ -54,6 +54,7 @@
#include "../common/events/player_event_logs.h"
#include "../common/content/world_content_service.h"
#include "../common/repositories/group_id_repository.h"
#include "../common/repositories/character_data_repository.h"
#include <iostream>
#include <iomanip>
@@ -191,9 +192,9 @@ bool Client::CanTradeFVNoDropItem()
void Client::SendEnterWorld(std::string name)
{
char char_name[64] = { 0 };
if (is_player_zoning && database.GetLiveChar(GetAccountID(), char_name)) {
if(database.GetAccountIDByChar(char_name) != GetAccountID()) {
const std::string& live_name = database.GetLiveChar(GetAccountID());
if (is_player_zoning) {
if(database.GetAccountIDByChar(live_name) != GetAccountID()) {
eqs->Close();
return;
} else {
@@ -201,8 +202,8 @@ void Client::SendEnterWorld(std::string name)
}
}
auto outapp = new EQApplicationPacket(OP_EnterWorld, strlen(char_name) + 1);
memcpy(outapp->pBuffer,char_name,strlen(char_name)+1);
auto outapp = new EQApplicationPacket(OP_EnterWorld, live_name.length() + 1);
memcpy(outapp->pBuffer, live_name.c_str(), live_name.length() + 1);
QueuePacket(outapp);
safe_delete(outapp);
}
@@ -765,9 +766,15 @@ bool Client::HandleEnterWorldPacket(const EQApplicationPacket *app) {
auto ew = (EnterWorld_Struct *) app->pBuffer;
strn0cpy(char_name, ew->name, sizeof(char_name));
uint32 temporary_account_id = 0;
charid = database.GetCharacterInfo(char_name, &temporary_account_id, &zone_id, &instance_id);
if (!charid) {
const auto& l = CharacterDataRepository::GetWhere(
database,
fmt::format(
"`name` = '{}' LIMIT 1",
Strings::Escape(char_name)
)
);
if (l.empty()) {
LogInfo("Could not get CharInfo for [{}]", char_name);
eqs->Close();
return true;
@@ -785,13 +792,24 @@ bool Client::HandleEnterWorldPacket(const EQApplicationPacket *app) {
instance_id = r.instance.id;
}
const auto& e = l.front();
// Make sure this account owns this character
if (temporary_account_id != account_id) {
LogInfo("Account [{}] does not own the character named [{}] from account [{}]", account_id, char_name, temporary_account_id);
if (e.account_id != account_id) {
LogInfo(
"Account [{}] does not own the character named [{}] from account [{}]",
account_id,
char_name,
e.account_id
);
eqs->Close();
return true;
}
charid = e.id;
zone_id = e.zone_id;
instance_id = e.zone_instance;
// This can probably be moved outside and have another method return requested info (don't forget to remove the #include "../common/shareddb.h" above)
// (This is a literal translation of the original process..I don't see why it can't be changed to a single-target query over account iteration)
if (!is_player_zoning) {