mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-11 16:51:29 +00:00
[Validation] Add Size Validation to #hotfix. (#2304)
* [Validation] Add Size Validation to #hotfix. - Validates size of shared memory pool versus current count of database so people don't accidentally #hotfix and mess something up. * Typo. * Message change.
This commit is contained in:
parent
dfd8f84cac
commit
849f4e18a5
@ -932,6 +932,8 @@ bool SharedDatabase::LoadItems(const std::string &prefix) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_shared_items_count = GetItemsCount();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1782,6 +1784,9 @@ bool SharedDatabase::LoadSpells(const std::string &prefix, int32 *records, const
|
||||
LogError("Error Loading Spells: {}", ex.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
m_shared_spells_count = GetSpellsCount();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -2367,3 +2372,35 @@ void SharedDatabase::SaveCharacterInspectMessage(uint32 character_id, const Insp
|
||||
const std::string query = StringFormat("REPLACE INTO `character_inspect_messages` (id, inspect_message) VALUES (%u, '%s')", character_id, Strings::Escape(message->text).c_str());
|
||||
auto results = QueryDatabase(query);
|
||||
}
|
||||
|
||||
uint32 SharedDatabase::GetSpellsCount()
|
||||
{
|
||||
auto results = QueryDatabase("SELECT count(*) FROM spells_new");
|
||||
if (!results.Success() || !results.RowCount()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto& row = results.begin();
|
||||
|
||||
if (row[0]) {
|
||||
return atoul(row[0]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32 SharedDatabase::GetItemsCount()
|
||||
{
|
||||
auto results = QueryDatabase("SELECT count(*) FROM items");
|
||||
if (!results.Success() || !results.RowCount()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto& row = results.begin();
|
||||
|
||||
if (row[0]) {
|
||||
return atoul(row[0]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -146,6 +146,8 @@ public:
|
||||
const EQ::ItemData *IterateItems(uint32 *id) const;
|
||||
const EQ::ItemData *GetItem(uint32 id) const;
|
||||
const EvolveInfo *GetEvolveInfo(uint32 loregroup);
|
||||
uint32 GetSharedItemsCount() { return m_shared_items_count; }
|
||||
uint32 GetItemsCount();
|
||||
|
||||
/**
|
||||
* faction
|
||||
@ -181,6 +183,8 @@ public:
|
||||
bool LoadSpells(const std::string &prefix, int32 *records, const SPDat_Spell_Struct **sp);
|
||||
void LoadSpells(void *data, int max_spells);
|
||||
void LoadDamageShieldTypes(SPDat_Spell_Struct *sp, int32 iMaxSpellID);
|
||||
uint32 GetSharedSpellsCount() { return m_shared_spells_count; }
|
||||
uint32 GetSpellsCount();
|
||||
|
||||
/**
|
||||
* basedata
|
||||
@ -212,6 +216,9 @@ protected:
|
||||
std::unique_ptr<EQ::FixedMemoryVariableHashSet<LootDrop_Struct>> loot_drop_hash;
|
||||
std::unique_ptr<EQ::MemoryMappedFile> base_data_mmf;
|
||||
std::unique_ptr<EQ::MemoryMappedFile> spells_mmf;
|
||||
|
||||
uint32 m_shared_items_count = 0;
|
||||
uint32 m_shared_spells_count = 0;
|
||||
};
|
||||
|
||||
#endif /*SHAREDDB_H_*/
|
||||
|
||||
@ -752,6 +752,46 @@ void command_findaliases(Client *c, const Seperator *sep)
|
||||
|
||||
void command_hotfix(Client *c, const Seperator *sep)
|
||||
{
|
||||
auto items_count = database.GetItemsCount();
|
||||
auto shared_items_count = database.GetSharedItemsCount();
|
||||
if (items_count != shared_items_count) {
|
||||
c->Message(Chat::Yellow, "Your database does not have the same item count as your shared memory.");
|
||||
|
||||
c->Message(
|
||||
Chat::Yellow,
|
||||
fmt::format(
|
||||
"Database Count: {} Shared Memory Count: {}",
|
||||
items_count,
|
||||
shared_items_count
|
||||
).c_str()
|
||||
);
|
||||
|
||||
c->Message(Chat::Yellow, "If you want to be able to add new items to your server while it is online, you need to create placeholder entries in the database ahead of time and do not add or remove rows/entries. Only modify the existing placeholder rows/entries to safely use #hotfix.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
auto spells_count = database.GetSpellsCount();
|
||||
auto shared_spells_count = database.GetSharedSpellsCount();
|
||||
if (spells_count != shared_spells_count) {
|
||||
c->Message(Chat::Yellow, "Your database does not have the same spell count as your shared memory.");
|
||||
|
||||
c->Message(
|
||||
Chat::Yellow,
|
||||
fmt::format(
|
||||
"Database Count: {} Shared Memory Count: {}",
|
||||
spells_count,
|
||||
shared_spells_count
|
||||
).c_str()
|
||||
);
|
||||
|
||||
c->Message(Chat::Yellow, "If you want to be able to add new spells to your server while it is online, you need to create placeholder entries in the database ahead of time and do not add or remove rows/entries. Only modify the existing placeholder rows/entries to safely use #hotfix.");
|
||||
|
||||
c->Message(Chat::Yellow, "Note: You may still have to distribute a spell file, even with dynamic changes.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
std::string hotfix;
|
||||
database.GetVariable("hotfix_name", hotfix);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user