Re: [Pre] No more XML, Database Driven Data
Well, that code is very flawed(at least what is posted on the first page).
First of all, it does not create a new instance of type MobInfo each time, and therefore is adding EVERY summon monster to EVERY monster. Well, it would be, if not for this next error:
Code:
mob.summon.push_back(atoi(mrow[2]));
Which is getting the HP of the monster as the summon ID, which in turn will crash your client all the time unless by some lucky ass chance the summon monster's HP is the ID of another monster, but I doubt it.
Haha, that's incredible, because it works with the code I posted, really well =/ Not entirely sure how, because I agree with every fix you posted above.. As for the mrow[2] error, that's a result of my ambiguous naming haha. Are monster summons actually implemented yet into the server? If not, that would be one reason I would point at it actually still functioning (and not crashing and burning like it should.) The MobInfo not being initialized each time is due to me combining the init mob functions from two into one.. I guess it's just hard to keep track of what you changed and where you changed it hehe.
I'll update the main post with these fixes.. thanks for protecting people from my ignorance haha.
So in order for it to perform properly, you would need to have the following:
Code:
void Initializing::initializeMobs(){
MYSQL_RES *mres;
MYSQL_ROW mrow;
char query[255];
sprintf_s(query,255,"SELECT * FROM dataMob");
mysql_real_query(&MySQL::maple_db, query, strlen(query));
mres = mysql_store_result(&MySQL::maple_db);
mrow = mysql_fetch_row(mres);
int ret = 0;
while ((mrow = mysql_fetch_row(mres))) {
MobInfo mob; // Create new instance of type MobInfo each loop for proper data
MYSQL_RES *mres2;
MYSQL_ROW mrow2;
// Col0 : RowID
// 1 : MobNumber
// 2 : HP
// 3 : MP
// 4 : Exp
int mobnumber = atoi(mrow[1]); // Mob Number
mob.hp = atoi(mrow[2]);
mob.mp = atoi(mrow[3]);
mob.exp = atoi(mrow[4]);
sprintf_s(query,255,"SELECT * FROM dataMobSummon WHERE MobNumber = '%i'", mobnumber);
mysql_real_query(&MySQL::maple_db, query, strlen(query));
mres2 = mysql_store_result(&MySQL::maple_db);
while((mrow2 = mysql_fetch_row(mres2))) {
mob.summon.push_back(atoi(mrow2[2]));
}
/* We do special handling for the summons, as it's stored in another table
to preserve normalization. */
Mobs::addMob(mobnumber,mob);
}
}
That's really close, although you'll want to initialize
MobInfo mob; because if it's used later, without having values set (lets say, when there are no summons for a monster, the summon.push_back function will never be ran, resulting in it possibly being a pointer to who knows where.)
Thank you so much for your help ^^ That's a great contribution.. I just wish that my errors would've been more apparent to me haha. Little embarassing
EDIT: Hm, was thinking those were classes, but they're structs.. (though still uninitialized) I've just seen alot of crashes happen around the uninit'ed variables in the project so they seem to be problem areas (understandably so), but I don't think they will be in these cases.. ^^; sorry bout that.. haha
I also did shops, as an addition to this project. However, I believe this should be posted in Development, because it is a development issue and this section is mostly filled with leechers that have no idea wtf all of this means, and I doubt klook pays too much attention to this section either due to the whole cluttered business
Agreed, anyone feel like rallying a Mod to move it? Also, once it's done, it would probably be a good idea to point klook to it... It's very easy to implement into the existing source code haha. (of course, that should probably after it goes under thorough testing and code critique (like mine just did :d) to make sure it's stable and effective.
Regarding the code you posted. Would you mind if I included it into the original post?
Code:
PS: I believe that all the data should be in a separate database from the user data. That would deal with some security issues, and would also better organisation and such.
Slightly agree, but that's ignoring (several) bigger problems, such as the unhashed passwords in the database, the server administrators not making users specific to the maple database and with only certain necessary permissions. Not to mention that the user that the server
defaults to is root, with
no password. How many kids are running around with a MySQL server that has no root password? The case gets even worse if they have their server bound on their NIC, which would result in anyone being able to remote admin in, and do whatever they want with the database (including dump the users table... thank god there are no email addresses attached.. yet) Also, selecting against multiple databases is a pain and expensive haha. But really, the above issues need to be addressed first =/ Maybe in .8 klook can make it mandatory to not use root, and to have a password on the server (or at least default that way)
Also, table names like datamob and datamobsummon are quite long and unecessary
Slightly agreed, moreso than the above quote. They can be trimmed down, but I tend to prefix things to prevent naming collisions, especially if someone wants to add easy IPB+MapleDB integration or something similar. (That problem already comes up with the Users table.. maybe a maple_ prefix would be better just for every table?) Long table names are, well, long, but short table names can be hellish. Imagine if I opted for
mbsm for
mobsummon instead.. And when you have hundreds of tables, things start getting really confusing. I guess this is just personal perference, but I really would like to avoid
itm.cnsm... haha :]
EDIT: I just ran a script, and the person who wrote it used 'equip' for the, well, equip data table.. haha, so I had my entire Equip table truncated :] oops (not their fault :d I should've checked, nor was it a big loss haha) But that's even more reason to try to prevent against table ambiguoity... maybe if we just use a 'd' prefix?
Code:
column names like mobnumber are misleading when the DB's main lingo is id. Try to stick to what klook did rather than reinventing the wheel. KISS is a good thing to follow for any DB that is going to be read by others.
Touche. I couldn't think of any alternatives, and was trying to avoid ID, as well,
Mob.MobID, that's not Mob.ID but is the ID of a Mob, although not in the context of a table, gets confusing too XD
Okay, ignore that :d I agree, it should be MobID or something similar. External/Internal ID's are hard to deal with without making too ambiguous... Thanks for your help and comments :]