mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-21 01:51:30 +00:00
LoadLootTables converted to QueryDatabase
This commit is contained in:
parent
aa9601352d
commit
c7faf8a03c
@ -1748,61 +1748,56 @@ 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, "
|
||||||
uint32 current_id = 0;
|
"loottable_entries.lootdrop_id, loottable_entries.multiplier, loottable_entries.droplimit, "
|
||||||
uint32 current_entry = 0;
|
"loottable_entries.mindrop, loottable_entries.probability FROM loottable LEFT JOIN loottable_entries "
|
||||||
while(row = mysql_fetch_row(result)) {
|
"ON loottable.id = loottable_entries.loottable_id ORDER BY id";
|
||||||
uint32 id = static_cast<uint32>(atoul(row[0]));
|
auto results = QueryDatabase(query);
|
||||||
if(id != current_id) {
|
if (!results.Success()) {
|
||||||
if(current_id != 0) {
|
LogFile->write(EQEMuLog::Error, "Error getting loot table info from database: %s, %s", query.c_str(), results.ErrorMessage().c_str());
|
||||||
hash.insert(current_id, loot_table, (sizeof(LootTable_Struct) +
|
return;
|
||||||
(sizeof(LootTableEntries_Struct) * lt->NumEntries)));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
memset(loot_table, 0, sizeof(LootTable_Struct) + (sizeof(LootTableEntries_Struct) * 128));
|
uint32 current_id = 0;
|
||||||
current_entry = 0;
|
uint32 current_entry = 0;
|
||||||
current_id = id;
|
|
||||||
lt->mincash = static_cast<uint32>(atoul(row[1]));
|
|
||||||
lt->maxcash = static_cast<uint32>(atoul(row[2]));
|
|
||||||
lt->avgcoin = static_cast<uint32>(atoul(row[3]));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(current_entry > 128) {
|
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||||
continue;
|
uint32 id = static_cast<uint32>(atoul(row[0]));
|
||||||
}
|
if(id != current_id) {
|
||||||
|
if(current_id != 0)
|
||||||
|
hash.insert(current_id, loot_table, (sizeof(LootTable_Struct) + (sizeof(LootTableEntries_Struct) * lt->NumEntries)));
|
||||||
|
|
||||||
if(!row[4]) {
|
memset(loot_table, 0, sizeof(LootTable_Struct) + (sizeof(LootTableEntries_Struct) * 128));
|
||||||
continue;
|
current_entry = 0;
|
||||||
}
|
current_id = id;
|
||||||
|
lt->mincash = static_cast<uint32>(atoul(row[1]));
|
||||||
|
lt->maxcash = static_cast<uint32>(atoul(row[2]));
|
||||||
|
lt->avgcoin = static_cast<uint32>(atoul(row[3]));
|
||||||
|
}
|
||||||
|
|
||||||
lt->Entries[current_entry].lootdrop_id = static_cast<uint32>(atoul(row[4]));
|
if(current_entry > 128)
|
||||||
lt->Entries[current_entry].multiplier = static_cast<uint8>(atoi(row[5]));
|
continue;
|
||||||
lt->Entries[current_entry].droplimit = static_cast<uint8>(atoi(row[6]));
|
|
||||||
lt->Entries[current_entry].mindrop = static_cast<uint8>(atoi(row[7]));
|
|
||||||
lt->Entries[current_entry].probability = static_cast<float>(atof(row[8]));
|
|
||||||
|
|
||||||
++(lt->NumEntries);
|
if(!row[4])
|
||||||
++current_entry;
|
continue;
|
||||||
}
|
|
||||||
if(current_id != 0) {
|
lt->Entries[current_entry].lootdrop_id = static_cast<uint32>(atoul(row[4]));
|
||||||
hash.insert(current_id, loot_table, (sizeof(LootTable_Struct) +
|
lt->Entries[current_entry].multiplier = static_cast<uint8>(atoi(row[5]));
|
||||||
(sizeof(LootTableEntries_Struct) * lt->NumEntries)));
|
lt->Entries[current_entry].droplimit = static_cast<uint8>(atoi(row[6]));
|
||||||
}
|
lt->Entries[current_entry].mindrop = static_cast<uint8>(atoi(row[7]));
|
||||||
|
lt->Entries[current_entry].probability = static_cast<float>(atof(row[8]));
|
||||||
|
|
||||||
|
++(lt->NumEntries);
|
||||||
|
++current_entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(current_id != 0)
|
||||||
|
hash.insert(current_id, loot_table, (sizeof(LootTable_Struct) + (sizeof(LootTableEntries_Struct) * lt->NumEntries)));
|
||||||
|
|
||||||
mysql_free_result(result);
|
|
||||||
} else {
|
|
||||||
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