05-30-2024, 05:14 PM
Just wanna add more information since i am dig in to it:
i've manage to make it works correctly but if you launch the command a few times, it sometimes report the error 3306 has been blocked. The system should still works as expected ?
bool CMagicProtoList::ReloadFromDB() {
CDBCmd cmd1;
CDBCmd cmd2;
cmd1.Init(&gserver->m_dbdata);
cmd2.Init(&gserver->m_dbdata);
cmd1.SetQuery("SELECT * FROM t_magic ORDER BY a_index");
if (!cmd1.Open())
return false;
while (cmd1.MoveNext()) {
int index;
char maxlevel;
char type;
char subtype;
char damagetype;
char hittype;
char attribute;
int psp;
int ptp;
int hsp;
int htp;
int bTogel;
cmd1.GetRec("a_index", index);
cmd1.GetRec("a_maxlevel", maxlevel);
cmd1.GetRec("a_type", type);
cmd1.GetRec("a_subtype", subtype);
cmd1.GetRec("a_damagetype", damagetype);
cmd1.GetRec("a_hittype", hittype);
cmd1.GetRec("a_attribute", attribute);
cmd1.GetRec("a_psp", psp);
cmd1.GetRec("a_ptp", ptp);
cmd1.GetRec("a_hsp", hsp);
cmd1.GetRec("a_htp", htp);
cmd1.GetRec("a_togle", bTogel);
std:
tring select_magiclevel_query = boost:
tr(boost::format("SELECT * FROM t_magiclevel WHERE a_index=%d ORDER BY a_level") % index);
cmd2.SetQuery(select_magiclevel_query);
if (!cmd2.Open())
return false;
CMagicLevelProto** levelproto = new CMagicLevelProto * [maxlevel];
memset(levelproto, 0, sizeof(CMagicLevelProto*) * maxlevel);
int j = 0;
while (cmd2.MoveNext()) {
int power;
int hitrate;
cmd2.GetRec("a_power", power);
cmd2.GetRec("a_hitrate", hitrate);
levelproto[j] = new CMagicLevelProto(power, hitrate);
j++;
}
// Find the existing CMagicProto object in m_list by index
for (int k = 0; k < m_count; ++k) {
if (m_list[k]->m_index == index) {
// Update the m_levelproto with the new levelproto
//delete[] m_list[k]->m_levelproto; // Delete the old levelproto array (commented since may crash the reference, but may occure in memory leaks!)
m_list[k]->m_levelproto = levelproto; // Assign the new levelproto array
break;
}
}
}
return true;
}

