[Release] auto save function [FIXED!] Fix 

Status
Not open for further replies.
Junior Spellweaver
Joined
Sep 20, 2007
Messages
138
Reaction score
0
Alas the long awaited auto save function :)

EDIT: I've now found the better way to do the autosave :) check it out! ^_^ can't believe this took me a few hours =.= You only need to edit one file

1. Make sure you've installed: http://forum.ragezone.com/f427/release-save-command-382734/

2. Open MapleStoryServer.cpp

3. At the top with the includes, put:
Code:
#include <process.h>
#include <windows.h>
#include <stdio.h>
#include "PlayersPacket.h"
#include "Players.h"

4. Above
Code:
void main(){
put:
Code:
void autoSave( void * );

5. Above
Code:
	while(getchar()){}
put:
Code:
	int saveInterval = 150; // save interval in seconds
	_beginthread( autoSave, 0, (void*)saveInterval);

6. At the bottom of the file put:
Code:
void autoSave( void *arg ) {
	while(true) {
		for (hash_map <int, Player*>::iterator iter = Players::players.begin(); iter != Players::players.end(); iter++)
        iter->second->save();
        PlayersPacket::showMassage("All progress has been saved successfully", 5);
		printf("All progress saved by autosave\n");
		Sleep(((INT_PTR)arg)*1000);
	}
}

If you want to change the save interval in seconds, change the part where it says:
Code:
	int saveInterval = 150; // save interval in seconds

If you don't want the save message to appear in game, delete:
Code:
        PlayersPacket::showMassage("All progress has been saved successfully", 5);


credits to me and the internet for helping me research threads
 
Last edited:
Re: [Release] auto save function

simply amazing, seriously, for me this is the best release that ever came in rz ;) congrats

edit: why are there 2 empty includes in autosave.cpp?
 
Re: [Release] auto save function

recheck step 2.... the code bbcode wouldnt let the #include <stdio.h>
#include <time.h> show up
 
Re: [Release] auto save function

2azn4u, what parts from ur save script do we need to add for this to work, i dont find that script usefull, so i was not pretending to add it to me server, unless i really have to
 
Re: [Release] auto save function

2azn4u, what parts from ur save script do we need to add for this to work, i dont find that script usefull, so i was not pretending to add it to me server, unless i really have to

all of the updated one is important
 
Re: [Release] auto save function

Hmm after adding this it's caused my server to just crash "fatal error" when I debug it.
 
Re: [Release] auto save function

Code:
d:\games\fantasyms project\server\serversource\maplestoryserver\autosave.cpp(19) : error C2955: 'stdext::hash_map' : use of class template requires template argument list
        c:\programas\microsoft visual studio 9.0\vc\include\hash_map(87) : see declaration of 'stdext::hash_map'
d:\games\fantasyms project\server\serversource\maplestoryserver\autosave.cpp(19) : error C2955: 'stdext::hash_map' : use of class template requires template argument list
        c:\programas\microsoft visual studio 9.0\vc\include\hash_map(87) : see declaration of 'stdext::hash_map'
d:\games\fantasyms project\server\serversource\maplestoryserver\autosave.cpp(20) : error C2227: left of '->second' must point to class/struct/union/generic type
        type is 'list<_Hash<_Traits>::_Traits::value_type,_Hash<_Traits>::_Traits::allocator_type>::iterator'
d:\games\fantasyms project\server\serversource\maplestoryserver\autosave.cpp(20) : error C2227: left of '->save' must point to class/struct/union/generic type

Any idea how to fix it?

here my edited part of player.cpp, i don't think i did something wront but :\
Code:
Player::~Player(){
	if(isconnect){
		Maps::removePlayer(this);
		Players::deletePlayer(this);
		save();
		isconnect= false;
	}
}
void Player::save() {
			char sql[2000];
		sprintf_s(sql, 2000, "update keymap set ");
		for(int i=0; i<90; i++){
			char temp[100];
			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, 2000, temp);
		}
		MySQL::insert(sql);
		sprintf_s(sql, 2000, "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, 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(), getGender(), getSkin(), getEyes(), getHair(), inv->getMesos() ,getPlayerid());
		MySQL::insert(sql);
		char temp[100];
		sprintf_s(temp, 100, "where charid=%d;", getPlayerid());
		strcat_s(sql, 2000, temp);
		MySQL::insert(sql);
		sprintf_s(sql, 2000, "delete from equip where charid=%d;", getPlayerid());
		MySQL::insert(sql);
		for(int i=0; i<inv->getEquipNum(); i++){
			sprintf_s(sql, 2000, "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);
			MySQL::insert(sql);
		}
		sprintf_s(sql, 2000, "delete from skills where charid=%d;", getPlayerid());
		MySQL::insert(sql);
		for(int i=0; i<skills->getSkillsNum(); i++){
			sprintf_s(sql, 2000, "insert into skills values(%d, %d, %d)", getPlayerid(), skills->getSkillID(i), skills->getSkillLevel(skills->getSkillID(i)));
			MySQL::insert(sql);
		}
		sprintf_s(sql, 2000, "delete from items where charid=%d;", getPlayerid());
		MySQL::insert(sql);
		for(int i=0; i<inv->getItemNum(); i++){
			sprintf_s(sql, 2000, "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);
			MySQL::insert(sql);
		}
		Skills::stopTimerPlayer(this);
		MySQL::setInt("characters", "online", this->getPlayerid(), 0);
		isconnect = false;
}
 
Re: [Release] auto save function

3>LINK : fatal error LNK1104: cannot open file '.\Debug\Autosave.obj'

..

Edit: fixed the linker but it's still crashing my server completely the second everything is done initializing.
 
Re: [Release] auto save function

1>AutoSave.cpp
1>d:\documents and settings\arrio\desktop\revision 003\maplestoryserver\007\maplestoryserver\autosave.cpp(21) : error C2955: 'stdext::hash_map' : use of class template requires template argument list
1> d:\program files\microsoft visual studio 9.0\vc\include\hash_map(87) : see declaration of 'stdext::hash_map'
1>d:\documents and settings\arrio\desktop\revision 003\maplestoryserver\007\maplestoryserver\autosave.cpp(21) : error C2955: 'stdext::hash_map' : use of class template requires template argument list
1> d:\program files\microsoft visual studio 9.0\vc\include\hash_map(87) : see declaration of 'stdext::hash_map'
1>d:\documents and settings\arrio\desktop\revision 003\maplestoryserver\007\maplestoryserver\autosave.cpp(22) : error C2227: left of '->second' must point to class/struct/union/generic type
1> type is 'list<_Hash<_Traits>::_Traits::value_type,_Hash<_Traits>::_Traits::allocator_type>::iterator'
1>d:\documents and settings\arrio\desktop\revision 003\maplestoryserver\007\maplestoryserver\autosave.cpp(22) : error C2227: left of '->save' must point to class/struct/union/generic type

Thats the best i can fix.
 
Re: [Release] auto save function

Code:
d:\games\fantasyms project\server\serversource\maplestoryserver\autosave.cpp(19) : error C2955: 'stdext::hash_map' : use of class template requires template argument list
        c:\programas\microsoft visual studio 9.0\vc\include\hash_map(87) : see declaration of 'stdext::hash_map'
d:\games\fantasyms project\server\serversource\maplestoryserver\autosave.cpp(19) : error C2955: 'stdext::hash_map' : use of class template requires template argument list
        c:\programas\microsoft visual studio 9.0\vc\include\hash_map(87) : see declaration of 'stdext::hash_map'
d:\games\fantasyms project\server\serversource\maplestoryserver\autosave.cpp(20) : error C2227: left of '->second' must point to class/struct/union/generic type
        type is 'list<_Hash<_Traits>::_Traits::value_type,_Hash<_Traits>::_Traits::allocator_type>::iterator'
d:\games\fantasyms project\server\serversource\maplestoryserver\autosave.cpp(20) : error C2227: left of '->save' must point to class/struct/union/generic type

Any idea how to fix it?

here my edited part of player.cpp, i don't think i did something wront but :\
Code:
Player::~Player(){
	if(isconnect){
		Maps::removePlayer(this);
		Players::deletePlayer(this);
                save();
                Skills::stopTimerPlayer(this);
		isconnect= false;
	}
}
void Player::save() {
			char sql[2000];
		sprintf_s(sql, 2000, "update keymap set ");
		for(int i=0; i<90; i++){
			char temp[100];
			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, 2000, temp);
		}
		MySQL::insert(sql);
		sprintf_s(sql, 2000, "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, 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(), getGender(), getSkin(), getEyes(), getHair(), inv->getMesos() ,getPlayerid());
		MySQL::insert(sql);
		char temp[100];
		sprintf_s(temp, 100, "where charid=%d;", getPlayerid());
		strcat_s(sql, 2000, temp);
		MySQL::insert(sql);
		sprintf_s(sql, 2000, "delete from equip where charid=%d;", getPlayerid());
		MySQL::insert(sql);
		for(int i=0; i<inv->getEquipNum(); i++){
			sprintf_s(sql, 2000, "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);
			MySQL::insert(sql);
		}
		sprintf_s(sql, 2000, "delete from skills where charid=%d;", getPlayerid());
		MySQL::insert(sql);
		for(int i=0; i<skills->getSkillsNum(); i++){
			sprintf_s(sql, 2000, "insert into skills values(%d, %d, %d)", getPlayerid(), skills->getSkillID(i), skills->getSkillLevel(skills->getSkillID(i)));
			MySQL::insert(sql);
		}
		sprintf_s(sql, 2000, "delete from items where charid=%d;", getPlayerid());
		MySQL::insert(sql);
		for(int i=0; i<inv->getItemNum(); i++){
			sprintf_s(sql, 2000, "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);
			MySQL::insert(sql);
		}

}

edited it for you
 
Re: [Release] auto save function

Technically its
Code:
add [SIZE=2][COLOR=#0000ff]
#include[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#a31515]"AutoSave.h"
[/COLOR][/SIZE]
instead of adding just autosave in the maplestoryserver.cpp :P
 
Status
Not open for further replies.
Back