mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-12 01:11:29 +00:00
[Bug Fix] Fix #door Save (#2699)
* [Bug Fix] Fix #door Create # Notes - Using `#door create` then `#door save` was overwriting doors instead of using the next highest ID. - Remove the following unused commands. ```cpp uint32 GetGuildEQID(uint32 guilddbid); void UpdateDoorGuildID(int doorid, int guild_id); int32 GetDoorsCount(uint32* oMaxID, const char *zone_name, int16 version);``` * Update doors.cpp * Update doors.cpp * Update doors.cpp
This commit is contained in:
parent
7e13d07108
commit
f322e85d4e
@ -20,6 +20,8 @@
|
||||
#include "../common/eqemu_logsys.h"
|
||||
#include "../common/strings.h"
|
||||
|
||||
#include "../common/repositories/doors_repository.h"
|
||||
|
||||
#include "client.h"
|
||||
#include "doors.h"
|
||||
#include "entity.h"
|
||||
@ -87,8 +89,8 @@ Doors::Doors(const char *model, const glm::vec4 &position, uint8 open_type, uint
|
||||
strn0cpy(m_door_name, model, 32);
|
||||
strn0cpy(m_destination_zone_name, "NONE", 32);
|
||||
|
||||
m_database_id = (uint32) content_db.GetDoorsCountPlusOne(zone->GetShortName(), zone->GetInstanceVersion());
|
||||
m_door_id = (uint8) content_db.GetDoorsDBCountPlusOne(zone->GetShortName(), zone->GetInstanceVersion());
|
||||
m_database_id = content_db.GetDoorsCountPlusOne();
|
||||
m_door_id = content_db.GetDoorsDBCountPlusOne(zone->GetShortName(), zone->GetInstanceVersion());
|
||||
|
||||
m_open_type = open_type;
|
||||
m_size = size;
|
||||
@ -685,53 +687,23 @@ void Doors::ToggleState(Mob *sender)
|
||||
safe_delete(outapp);
|
||||
}
|
||||
|
||||
int32 ZoneDatabase::GetDoorsCount(uint32 *oMaxID, const char *zone_name, int16 version)
|
||||
uint32 ZoneDatabase::GetDoorsCountPlusOne()
|
||||
{
|
||||
const uint32 max_door_id = static_cast<uint32>(DoorsRepository::GetMaxId(*this));
|
||||
|
||||
std::string query = StringFormat(
|
||||
"SELECT MAX(id), count(*) FROM doors "
|
||||
"WHERE zone = '%s' AND (version = %u OR version = -1)",
|
||||
zone_name, version
|
||||
);
|
||||
auto results = QueryDatabase(query);
|
||||
if (!results.Success()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (results.RowCount() != 1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
auto row = results.begin();
|
||||
|
||||
if (!oMaxID) {
|
||||
return atoi(row[1]);
|
||||
}
|
||||
|
||||
if (row[0]) {
|
||||
*oMaxID = atoi(row[0]);
|
||||
}
|
||||
else {
|
||||
*oMaxID = 0;
|
||||
}
|
||||
|
||||
return atoi(row[1]);
|
||||
|
||||
return (max_door_id + 1);
|
||||
}
|
||||
|
||||
int32 ZoneDatabase::GetDoorsCountPlusOne(const char *zone_name, int16 version)
|
||||
int ZoneDatabase::GetDoorsDBCountPlusOne(std::string zone_short_name, int16 version)
|
||||
{
|
||||
std::string query = StringFormat(
|
||||
"SELECT MAX(id) FROM doors WHERE zone = '%s' AND version = %u",
|
||||
zone_name,
|
||||
const auto query = fmt::format(
|
||||
"SELECT COALESCE(MAX(doorid), 1) FROM doors "
|
||||
"WHERE zone = '{}' AND (version = {} OR version = -1)",
|
||||
zone_short_name,
|
||||
version
|
||||
);
|
||||
auto results = QueryDatabase(query);
|
||||
if (!results.Success()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (results.RowCount() != 1) {
|
||||
auto results = QueryDatabase(query);
|
||||
if (!results.Success() || !results.RowCount()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -741,35 +713,7 @@ int32 ZoneDatabase::GetDoorsCountPlusOne(const char *zone_name, int16 version)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return atoi(row[0]) + 1;
|
||||
}
|
||||
|
||||
int32 ZoneDatabase::GetDoorsDBCountPlusOne(const char *zone_name, int16 version)
|
||||
{
|
||||
|
||||
uint32 oMaxID = 0;
|
||||
|
||||
std::string query = StringFormat(
|
||||
"SELECT MAX(doorid) FROM doors "
|
||||
"WHERE zone = '%s' AND (version = %u OR version = -1)",
|
||||
zone_name, version
|
||||
);
|
||||
auto results = QueryDatabase(query);
|
||||
if (!results.Success()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (results.RowCount() != 1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
auto row = results.begin();
|
||||
|
||||
if (!row[0]) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return atoi(row[0]) + 1;
|
||||
return std::stoi(row[0]) + 1;
|
||||
}
|
||||
|
||||
std::vector<DoorsRepository::Doors> ZoneDatabase::LoadDoors(const std::string &zone_name, int16 version)
|
||||
@ -847,9 +791,6 @@ void Doors::CreateDatabaseEntry()
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Persist
|
||||
*/
|
||||
content_db.InsertDoor(
|
||||
GetDoorDBID(),
|
||||
GetDoorID(),
|
||||
|
||||
@ -3075,17 +3075,51 @@ void ZoneDatabase::QGlobalPurge()
|
||||
database.QueryDatabase(query);
|
||||
}
|
||||
|
||||
void ZoneDatabase::InsertDoor(uint32 ddoordbid, uint16 ddoorid, const char* ddoor_name, const glm::vec4& position, uint8 dopentype, uint16 dguildid, uint32 dlockpick, uint32 dkeyitem, uint8 ddoor_param, uint8 dinvert, int dincline, uint16 dsize, bool ddisabletimer){
|
||||
void ZoneDatabase::InsertDoor(
|
||||
uint32 database_id,
|
||||
uint8 id,
|
||||
std::string name,
|
||||
const glm::vec4 &position,
|
||||
uint8 open_type,
|
||||
uint16 guild_id,
|
||||
uint32 lockpick,
|
||||
uint32 key_item_id,
|
||||
uint8 door_param,
|
||||
uint8 invert,
|
||||
int incline,
|
||||
uint16 size,
|
||||
bool disable_timer
|
||||
) {
|
||||
auto e = DoorsRepository::NewEntity();
|
||||
|
||||
std::string query = StringFormat("REPLACE INTO doors (id, doorid, zone, version, name, "
|
||||
"pos_x, pos_y, pos_z, heading, opentype, guild, lockpick, "
|
||||
"keyitem, disable_timer, door_param, invert_state, incline, size) "
|
||||
"VALUES('%i', '%i', '%s', '%i', '%s', '%f', '%f', "
|
||||
"'%f', '%f', '%i', '%i', '%i', '%i', '%i', '%i', '%i', '%i', '%i')",
|
||||
ddoordbid, ddoorid, zone->GetShortName(), zone->GetInstanceVersion(),
|
||||
ddoor_name, position.x, position.y, position.z, position.w,
|
||||
dopentype, dguildid, dlockpick, dkeyitem, (ddisabletimer ? 1 : 0), ddoor_param, dinvert, dincline, dsize);
|
||||
QueryDatabase(query);
|
||||
e.id = database_id;
|
||||
e.doorid = id;
|
||||
e.zone = zone->GetShortName();
|
||||
e.version = zone->GetInstanceVersion();
|
||||
e.name = name;
|
||||
e.pos_x = position.x;
|
||||
e.pos_y = position.y;
|
||||
e.pos_z = position.z;
|
||||
e.opentype = open_type;
|
||||
e.guild = guild_id;
|
||||
e.lockpick = lockpick;
|
||||
e.keyitem = key_item_id;
|
||||
e.disable_timer = static_cast<int8_t>(disable_timer);
|
||||
e.door_param = door_param;
|
||||
e.invert_state = invert;
|
||||
e.incline = incline;
|
||||
e.size = size;
|
||||
|
||||
const auto& n = DoorsRepository::InsertOne(*this, e);
|
||||
if (!n.id) {
|
||||
LogError(
|
||||
"Failed to create door in Zone [{}] Version [{}] Database ID [{}] ID [{}]",
|
||||
zone->GetShortName(),
|
||||
zone->GetInstanceVersion(),
|
||||
database_id,
|
||||
id
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void ZoneDatabase::LoadAltCurrencyValues(uint32 char_id, std::map<uint32, uint32> ¤cy) {
|
||||
|
||||
@ -570,12 +570,23 @@ public:
|
||||
|
||||
/* Doors */
|
||||
std::vector<DoorsRepository::Doors> LoadDoors(const std::string& zone_name, int16 version);
|
||||
uint32 GetGuildEQID(uint32 guilddbid);
|
||||
void UpdateDoorGuildID(int doorid, int guild_id);
|
||||
int32 GetDoorsCount(uint32* oMaxID, const char *zone_name, int16 version);
|
||||
int32 GetDoorsCountPlusOne(const char *zone_name, int16 version);
|
||||
int32 GetDoorsDBCountPlusOne(const char *zone_name, int16 version);
|
||||
void InsertDoor(uint32 did, uint16 ddoorid, const char* ddoor_name, const glm::vec4& position, uint8 dopentype, uint16 dguildid, uint32 dlockpick, uint32 dkeyitem, uint8 ddoor_param, uint8 dinvert, int dincline, uint16 dsize, bool ddisabletimer = false);
|
||||
uint32 GetDoorsCountPlusOne();
|
||||
int GetDoorsDBCountPlusOne(std::string zone_short_name, int16 version);
|
||||
void InsertDoor(
|
||||
uint32 database_id,
|
||||
uint8 id,
|
||||
std::string name,
|
||||
const glm::vec4 &position,
|
||||
uint8 open_type,
|
||||
uint16 guild_id,
|
||||
uint32 ockpick,
|
||||
uint32 key_item_id,
|
||||
uint8 door_param,
|
||||
uint8 invert,
|
||||
int incline,
|
||||
uint16 size,
|
||||
bool disable_timer = false
|
||||
);
|
||||
|
||||
/* Blocked Spells */
|
||||
int32 GetBlockedSpellsCount(uint32 zoneid);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user