mirror of
https://github.com/EQEmu/Server.git
synced 2026-04-03 13:22:28 +00:00
LoadLootDrops converted to QueryDatabase
This commit is contained in:
parent
c7faf8a03c
commit
74b8f38030
@ -1801,36 +1801,36 @@ void SharedDatabase::LoadLootTables(void *data, uint32 size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SharedDatabase::LoadLootDrops(void *data, uint32 size) {
|
void SharedDatabase::LoadLootDrops(void *data, uint32 size) {
|
||||||
|
|
||||||
EQEmu::FixedMemoryVariableHashSet<LootDrop_Struct> hash(reinterpret_cast<uint8*>(data), size);
|
EQEmu::FixedMemoryVariableHashSet<LootDrop_Struct> hash(reinterpret_cast<uint8*>(data), size);
|
||||||
const char *query = "SELECT lootdrop.id, lootdrop_entries.item_id, lootdrop_entries.item_charges, "
|
uint8 loot_drop[sizeof(LootDrop_Struct) + (sizeof(LootDropEntries_Struct) * 1260)];
|
||||||
|
LootDrop_Struct *ld = reinterpret_cast<LootDrop_Struct*>(loot_drop);
|
||||||
|
|
||||||
|
const std::string query = "SELECT lootdrop.id, lootdrop_entries.item_id, lootdrop_entries.item_charges, "
|
||||||
"lootdrop_entries.equip_item, lootdrop_entries.chance, lootdrop_entries.minlevel, "
|
"lootdrop_entries.equip_item, lootdrop_entries.chance, lootdrop_entries.minlevel, "
|
||||||
"lootdrop_entries.maxlevel, lootdrop_entries.multiplier FROM lootdrop JOIN lootdrop_entries "
|
"lootdrop_entries.maxlevel, lootdrop_entries.multiplier FROM lootdrop JOIN lootdrop_entries "
|
||||||
"ON lootdrop.id = lootdrop_entries.lootdrop_id ORDER BY lootdrop_id";
|
"ON lootdrop.id = lootdrop_entries.lootdrop_id ORDER BY lootdrop_id";
|
||||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
auto results = QueryDatabase(query);
|
||||||
MYSQL_RES *result;
|
if (!results.Success()) {
|
||||||
MYSQL_ROW row;
|
LogFile->write(EQEMuLog::Error, "Error getting loot drop info from database: %s, %s", query.c_str(), results.ErrorMessage().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
uint8 loot_drop[sizeof(LootDrop_Struct) + (sizeof(LootDropEntries_Struct) * 1260)];
|
|
||||||
LootDrop_Struct *ld = reinterpret_cast<LootDrop_Struct*>(loot_drop);
|
|
||||||
if(RunQuery(query, strlen(query), errbuf, &result)) {
|
|
||||||
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_drop, (sizeof(LootDrop_Struct) +
|
hash.insert(current_id, loot_drop, (sizeof(LootDrop_Struct) +(sizeof(LootDropEntries_Struct) * ld->NumEntries)));
|
||||||
(sizeof(LootDropEntries_Struct) * ld->NumEntries)));
|
|
||||||
}
|
|
||||||
|
|
||||||
memset(loot_drop, 0, sizeof(LootDrop_Struct) + (sizeof(LootDropEntries_Struct) * 1260));
|
memset(loot_drop, 0, sizeof(LootDrop_Struct) + (sizeof(LootDropEntries_Struct) * 1260));
|
||||||
current_entry = 0;
|
current_entry = 0;
|
||||||
current_id = id;
|
current_id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(current_entry >= 1260) {
|
if(current_entry >= 1260)
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
ld->Entries[current_entry].item_id = static_cast<uint32>(atoul(row[1]));
|
ld->Entries[current_entry].item_id = static_cast<uint32>(atoul(row[1]));
|
||||||
ld->Entries[current_entry].item_charges = static_cast<int8>(atoi(row[2]));
|
ld->Entries[current_entry].item_charges = static_cast<int8>(atoi(row[2]));
|
||||||
@ -1843,15 +1843,10 @@ void SharedDatabase::LoadLootDrops(void *data, uint32 size) {
|
|||||||
++(ld->NumEntries);
|
++(ld->NumEntries);
|
||||||
++current_entry;
|
++current_entry;
|
||||||
}
|
}
|
||||||
if(current_id != 0) {
|
|
||||||
hash.insert(current_id, loot_drop, (sizeof(LootDrop_Struct) +
|
|
||||||
(sizeof(LootDropEntries_Struct) * ld->NumEntries)));
|
|
||||||
}
|
|
||||||
|
|
||||||
mysql_free_result(result);
|
if(current_id != 0)
|
||||||
} else {
|
hash.insert(current_id, loot_drop, (sizeof(LootDrop_Struct) + (sizeof(LootDropEntries_Struct) * ld->NumEntries)));
|
||||||
LogFile->write(EQEMuLog::Error, "Error getting loot drop info from database: %s, %s", query, errbuf);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SharedDatabase::LoadLoot() {
|
bool SharedDatabase::LoadLoot() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user