[Release] Lag-free save function

Status
Not open for further replies.
Junior Spellweaver
Joined
Apr 6, 2008
Messages
181
Reaction score
0
The vanilla save function is umm... terrible. So here is one that saves things without lagging your machine to death due to so many SQL queries instead of just a few well-formed ones:

Find it here:

Helps if you already followed that guide for the !save/!saveall GM commands, along with installing my FM and other portals stuff. *sets up SQL tables for quest data, the only missing part of GMSDB currently* Cheers. =]

FM portals and such: http://forum.ragezone.com/f427/rele...rking-fm-portals-haunted-house-portal-382464/
 
Last edited:
This is suppose to replace the other one right?

If I recall correctly, it should be in Player.cpp?

I replaced the old Save function and it looks like it came out with a bunch of errors.
Can't just say it has errors, gotta tell me em. However, I know what they are caused by. Just visit the new pastebin link and recopy. Cheers.
 
Yep, it took out all the other errors, but I still get this one.

player.cpp(39) : error C3861: 'getOrigin': identifier not found

It compiles once I remove 'getOrigin' from
Code:
sprintf_s(sql, 10000, "update characters set level=%d, job=%d, str=%d, dex=%d, intt=%d, luk=%d, chp=%d, mhp=%d, cmp=%d, mmp=%d, ap=%d, sp=%d, exp=%d, fame=%d, map=%d, origin=%d, gender=%d, skin=%d, eyes=%d, hair=%d, mesos=%d where id=%d", getLevel(), getJob(), getStr(), getDex(), getInt(), getLuk(), getHP(), getMHP(), getMP(), getMMP(), getAp(), getSp(), getExp(), getFame(), getMap(), getOrigin(), getGender(), getSkin(), getEyes(), getHair(), inv->getMesos() ,getPlayerid());
. What does 'getOrigin' even do?
 
Code:
c:\documents and settings\compaq_owner\desktop\titanmsver007\maplestoryserver\maplestoryserver\player.cpp(40) : error C3861: 'getOrigin': identifier not found
Do I get this cuz I dont have the fm portal script?
Yes. getOrigin in a function that is added while following that guide.
 
I see you've combined all the equip/item/skill insert queries into one.
I tried doing it too, but I failed (I repeated added VALUES(,,,) instead of just (,,,)).

Anyways, I must warn you.
Item loss during crashes are very common.

A way to alleviate it (better) would be to run the delete sql AFTER the for loop to create the insert sql is complete.
At least it reduces the likelihood of crashing with everything lost.
 
I see you've combined all the equip/item/skill insert queries into one.
I tried doing it too, but I failed (I repeated added VALUES(,,,) instead of just (,,,)).

Anyways, I must warn you.
Item loss during crashes are very common.

A way to alleviate it (better) would be to run the delete sql AFTER the for loop to create the insert sql is complete.
At least it reduces the likelihood of crashing with everything lost.


sounds right
what i see in the last auto save...
that it crash the server sometimes(unhelden expetion)
and roll back some lvls ,loot and sp -_-
that god dam annoy
 
sounds right
what i see in the last auto save...
that it crash the server sometimes(unhelden expetion)
and roll back some lvls ,loot and sp -_-
that god dam annoy

The thing is that it deletes EVERYTHING in item/equip/skill tables before looping and adding them back in.

If the server dies during the loop, you can get partial or complete item/equip/skill loss.
 
Code:
c:\documents and settings\personal\mis documentos\descargas firefox\titanmsver007fixed\maplestoryserver\maplestoryserver\player.cpp(316) : error C2248: 'MySQL::maple_db' : no se puede obtener acceso al miembro private miembro declarado en la clase 'MySQL'
        c:\documents and settings\personal\mis documentos\descargas firefox\titanmsver007fixed\maplestoryserver\maplestoryserver\mysqlm.h(10) : vea la declaraci
 
This is my code (pulled deleted statements closer together, brought var definition out of loop).

Code:
void Player::save(){
	char* sql = new char[10000];
	char* temp = new char[1000];
	sprintf_s(sql, 10000, "update keymap set ");
	for(int i=0; i<90; i++){
		if(i!=89)
			sprintf_s(temp, 100, "pos%d=%d, ", i, keys[i]);
		else
			sprintf_s(temp, 100, "pos%d=%d where charid=%d; ", i, keys[i], getPlayerid());
		strcat_s(sql, 10000, temp);
	}
	MySQL::insert(sql);
	sprintf_s(sql, 10000, "update characters set level=%d, job=%d, str=%d, dex=%d, intt=%d, luk=%d, chp=%d, mhp=%d, cmp=%d, mmp=%d, ap=%d, sp=%d, exp=%d, fame=%d, map=%d, origin=%d, gender=%d, skin=%d, eyes=%d, hair=%d, mesos=%d where id=%d", getLevel(), getJob(), getStr(), getDex(), getInt(), getLuk(), getHP(), getMHP(), getMP(), getMMP(), getAp(), getSp(), getExp(), getFame(), getMap(), getOrigin(), getGender(), getSkin(), getEyes(), getHair(), inv->getMesos() ,getPlayerid());
	MySQL::insert(sql);
	sprintf_s(sql2, 10000, "delete from equip where charid=%d;", getPlayerid());
	bool firstrun = true;
	for(int i=0; i<inv->getEquipNum(); i++){
		if(firstrun == true){
			sprintf_s(sql, 10000, "INSERT INTO equip VALUES (%d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d)", inv->getEquip(i)->id, Drops::equips[inv->getEquip(i)->id].type ,getPlayerid(), inv->getEquipPos(i), inv->getEquip(i)->slots, inv->getEquip(i)->scrolls,
				inv->getEquip(i)->istr, inv->getEquip(i)->idex, inv->getEquip(i)->iint, inv->getEquip(i)->iluk, inv->getEquip(i)->ihp, inv->getEquip(i)->imp, inv->getEquip(i)->iwatk, inv->getEquip(i)->imatk, inv->getEquip(i)->iwdef, 
				inv->getEquip(i)->imdef, inv->getEquip(i)->iacc, inv->getEquip(i)->iavo, inv->getEquip(i)->ihand, inv->getEquip(i)->ijump, inv->getEquip(i)->ispeed);
			firstrun = false;
		}
		else{
			sprintf_s(temp, 1000, ",(%d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d)", inv->getEquip(i)->id, Drops::equips[inv->getEquip(i)->id].type ,getPlayerid(), inv->getEquipPos(i), inv->getEquip(i)->slots, inv->getEquip(i)->scrolls,
				inv->getEquip(i)->istr, inv->getEquip(i)->idex, inv->getEquip(i)->iint, inv->getEquip(i)->iluk, inv->getEquip(i)->ihp, inv->getEquip(i)->imp, inv->getEquip(i)->iwatk, inv->getEquip(i)->imatk, inv->getEquip(i)->iwdef, 
				inv->getEquip(i)->imdef, inv->getEquip(i)->iacc, inv->getEquip(i)->iavo, inv->getEquip(i)->ihand, inv->getEquip(i)->ijump, inv->getEquip(i)->ispeed);
			strcat_s(sql, 10000, temp);
		}
	}
	MySQL::insert(sql2);
	MySQL::insert(sql);
	sprintf_s(sql2, 10000, "delete from skills where charid=%d;", getPlayerid());
	firstrun = true;
	for(int i=0; i<skills->getSkillsNum(); i++){
		if(firstrun == true){
			sprintf_s(sql, 10000, "INSERT INTO skills VALUES (%d, %d, %d)", getPlayerid(), skills->getSkillID(i), skills->getSkillLevel(skills->getSkillID(i)));
			firstrun = false;
		}
		else{
			sprintf_s(temp, 1000, ",(%d, %d, %d)", getPlayerid(), skills->getSkillID(i), skills->getSkillLevel(skills->getSkillID(i)));
			strcat_s(sql, 10000, temp);
		}
	}
	MySQL::insert(sql2);
	MySQL::insert(sql);
	sprintf_s(sql2, 10000, "DELETE FROM items WHERE charid=%d;", getPlayerid());
	firstrun = true;
	for(int i=0; i<inv->getItemNum(); i++){
		if(firstrun == true){
			sprintf_s(sql, 10000, "INSERT INTO items VALUES (%d, %d, %d, %d, %d)", inv->getItem(i)->id, getPlayerid() ,inv->getItem(i)->inv, inv->getItem(i)->pos, inv->getItem(i)->amount);
			firstrun = false;
		}
		else{
			sprintf_s(temp, 1000, ",(%d, %d, %d, %d, %d)", inv->getItem(i)->id, getPlayerid() ,inv->getItem(i)->inv, inv->getItem(i)->pos, inv->getItem(i)->amount);
			strcat_s(sql, 10000, temp);
		}
	}
	MySQL::insert(sql2);
	MySQL::insert(sql);
}
 
Status
Not open for further replies.
Back