mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-20 13:21:28 +00:00
LoadLootTables converted to QueryDatabase
This commit is contained in:
parent
aa9601352d
commit
c7faf8a03c
@ -1748,26 +1748,28 @@ void SharedDatabase::GetLootDropInfo(uint32 &loot_drop_count, uint32 &max_loot_d
|
|||||||
|
|
||||||
void SharedDatabase::LoadLootTables(void *data, uint32 size) {
|
void SharedDatabase::LoadLootTables(void *data, uint32 size) {
|
||||||
EQEmu::FixedMemoryVariableHashSet<LootTable_Struct> hash(reinterpret_cast<uint8*>(data), size);
|
EQEmu::FixedMemoryVariableHashSet<LootTable_Struct> hash(reinterpret_cast<uint8*>(data), size);
|
||||||
const char *query = "SELECT loottable.id, loottable.mincash, loottable.maxcash, loottable.avgcoin,"
|
|
||||||
" loottable_entries.lootdrop_id, loottable_entries.multiplier, loottable_entries.droplimit, "
|
|
||||||
"loottable_entries.mindrop, loottable_entries.probability FROM loottable LEFT JOIN loottable_entries"
|
|
||||||
" ON loottable.id = loottable_entries.loottable_id ORDER BY id";
|
|
||||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
|
||||||
MYSQL_RES *result;
|
|
||||||
MYSQL_ROW row;
|
|
||||||
uint8 loot_table[sizeof(LootTable_Struct) + (sizeof(LootTableEntries_Struct) * 128)];
|
uint8 loot_table[sizeof(LootTable_Struct) + (sizeof(LootTableEntries_Struct) * 128)];
|
||||||
LootTable_Struct *lt = reinterpret_cast<LootTable_Struct*>(loot_table);
|
LootTable_Struct *lt = reinterpret_cast<LootTable_Struct*>(loot_table);
|
||||||
|
|
||||||
if(RunQuery(query, strlen(query), errbuf, &result)) {
|
const std::string query = "SELECT loottable.id, loottable.mincash, loottable.maxcash, loottable.avgcoin, "
|
||||||
|
"loottable_entries.lootdrop_id, loottable_entries.multiplier, loottable_entries.droplimit, "
|
||||||
|
"loottable_entries.mindrop, loottable_entries.probability FROM loottable LEFT JOIN loottable_entries "
|
||||||
|
"ON loottable.id = loottable_entries.loottable_id ORDER BY id";
|
||||||
|
auto results = QueryDatabase(query);
|
||||||
|
if (!results.Success()) {
|
||||||
|
LogFile->write(EQEMuLog::Error, "Error getting loot table info from database: %s, %s", query.c_str(), results.ErrorMessage().c_str());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
uint32 current_id = 0;
|
uint32 current_id = 0;
|
||||||
uint32 current_entry = 0;
|
uint32 current_entry = 0;
|
||||||
while(row = mysql_fetch_row(result)) {
|
|
||||||
|
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||||
uint32 id = static_cast<uint32>(atoul(row[0]));
|
uint32 id = static_cast<uint32>(atoul(row[0]));
|
||||||
if(id != current_id) {
|
if(id != current_id) {
|
||||||
if(current_id != 0) {
|
if(current_id != 0)
|
||||||
hash.insert(current_id, loot_table, (sizeof(LootTable_Struct) +
|
hash.insert(current_id, loot_table, (sizeof(LootTable_Struct) + (sizeof(LootTableEntries_Struct) * lt->NumEntries)));
|
||||||
(sizeof(LootTableEntries_Struct) * lt->NumEntries)));
|
|
||||||
}
|
|
||||||
|
|
||||||
memset(loot_table, 0, sizeof(LootTable_Struct) + (sizeof(LootTableEntries_Struct) * 128));
|
memset(loot_table, 0, sizeof(LootTable_Struct) + (sizeof(LootTableEntries_Struct) * 128));
|
||||||
current_entry = 0;
|
current_entry = 0;
|
||||||
@ -1777,13 +1779,11 @@ void SharedDatabase::LoadLootTables(void *data, uint32 size) {
|
|||||||
lt->avgcoin = static_cast<uint32>(atoul(row[3]));
|
lt->avgcoin = static_cast<uint32>(atoul(row[3]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(current_entry > 128) {
|
if(current_entry > 128)
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
if(!row[4]) {
|
if(!row[4])
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
lt->Entries[current_entry].lootdrop_id = static_cast<uint32>(atoul(row[4]));
|
lt->Entries[current_entry].lootdrop_id = static_cast<uint32>(atoul(row[4]));
|
||||||
lt->Entries[current_entry].multiplier = static_cast<uint8>(atoi(row[5]));
|
lt->Entries[current_entry].multiplier = static_cast<uint8>(atoi(row[5]));
|
||||||
@ -1794,15 +1794,10 @@ void SharedDatabase::LoadLootTables(void *data, uint32 size) {
|
|||||||
++(lt->NumEntries);
|
++(lt->NumEntries);
|
||||||
++current_entry;
|
++current_entry;
|
||||||
}
|
}
|
||||||
if(current_id != 0) {
|
|
||||||
hash.insert(current_id, loot_table, (sizeof(LootTable_Struct) +
|
|
||||||
(sizeof(LootTableEntries_Struct) * lt->NumEntries)));
|
|
||||||
}
|
|
||||||
|
|
||||||
mysql_free_result(result);
|
if(current_id != 0)
|
||||||
} else {
|
hash.insert(current_id, loot_table, (sizeof(LootTable_Struct) + (sizeof(LootTableEntries_Struct) * lt->NumEntries)));
|
||||||
LogFile->write(EQEMuLog::Error, "Error getting loot table info from database: %s, %s", query, errbuf);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SharedDatabase::LoadLootDrops(void *data, uint32 size) {
|
void SharedDatabase::LoadLootDrops(void *data, uint32 size) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user