Code:
uint32 Bot::GetEquipmentColor(int8 material_slot) const
{
//Bot tints
int32 slotid = 0;
uint32 returncolor = 0;
uint32 botid = this->GetBotID();
//Translate code slot # to DB slot #
slotid = Inventory::CalcSlotFromMaterial(material_slot);
//read from db
char* Query = 0;
MYSQL_RES* DatasetResult;
MYSQL_ROW DataRow;
if(database.RunQuery(Query, MakeAnyLenString(&Query, "SELECT color FROM botinventory WHERE BotID = %u AND SlotID = %u", botid, slotid), 0, &DatasetResult)) {
if(mysql_num_rows(DatasetResult) == 1) {
DataRow = mysql_fetch_row(DatasetResult);
if(DataRow)
returncolor = atoul(DataRow[0]); //atoi used here is wrong
}
mysql_free_result(DatasetResult);
safe_delete_array(Query);
}
return returncolor;
}
See code and comment for details.