Raised This Month: $ Target: $400
 0% 

[HELP] nVault problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
KaLoIaN
Senior Member
Join Date: Feb 2013
Old 05-09-2016 , 10:31   [HELP] nVault problem
Reply With Quote #1

I decided to go to MySQL because nVault is very problematic on my server..
Sometimes when the server crashes everyone on the server loses his variables stored in the vault, but another plugin which also uses nVault does not loses it's variables?

PHP Code:
public SaveData(id)
{
    new 
AuthID[35]
    
get_user_name(idAuthID34)
 
    new 
vaultkey[64], vaultdata[256]
    
format(vaultkey63"%s"AuthID)
    
format(vaultdata255"%i#%i#%i#%i#"g_Health[id], g_Armor[id], g_Damage[id], g_Money[id])
    
nvault_set(g_Nvaultvaultkeyvaultdata)
    return 
PLUGIN_CONTINUE
}

public 
LoadData(id)
{
    new 
AuthID[35]
    
get_user_name(idAuthID34)
 
    new 
vaultkey[64], vaultdata[256]
    
format(vaultkey63"%s"AuthID)
    
format(vaultdata255"%i#%i#%i#%i#"g_Health[id], g_Armor[id], g_Damage[id], g_Money[id])
    
nvault_get(g_Nvaultvaultkeyvaultdata,255)
 
    
replace_all(vaultdata255"#"" ")
 
    new 
PlayerHP[32], PlayerAP[32], PlayerDM[32], PlayerMY[32]
 
    
parse(vaultdataPlayerHP31PlayerAP31PlayerDM31PlayerMY31)
 
    
g_Health[id] = str_to_num(PlayerHP)
    
g_Armor[id] = str_to_num(PlayerAP)
    
g_Damage[id] = str_to_num(PlayerDM)
    
g_Money[id] = str_to_num(PlayerMY)
 
    return 
PLUGIN_CONTINUE

This code of nVault loses the stored variables on server crash. I don't found the code which does not loses the stored variables because it does not have .SMA file.
KaLoIaN is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-09-2016 , 21:06   Re: [HELP] nVault problem
Reply With Quote #2

This is because when a server does not close gracefully, client_disconnect() is not called on all clients and this is most likely where SaveData() is called from on each player.

To avoid this issue, you will need to save data as it changes for each player. It is not as efficient, but you wouldn't lose any data. My recommendation is to track down your crash issue and resolve it and not use a band-aid on all of your plugins.
__________________
Bugsy is offline
KaLoIaN
Senior Member
Join Date: Feb 2013
Old 05-10-2016 , 05:40   Re: [HELP] nVault problem
Reply With Quote #3

Here is the another part of save code i forgot :

PHP Code:
stock save_user_levels(id)
{
    
gVault nvault_open("SavedLevel")
    
    if(
gVault == INVALID_HANDLE)
        
set_fail_state("[ZE SS] nVault Open Error => Invalid Handle")
    
    
get_user_name(idgName31)
    
formatex(vKeycharsmax(vKey), "%s"gName)
    
formatex(vDatacharsmax(vData), "%i#%i#"g_iLevel[id], g_iExp[id])
    
nvault_set(gVaultvKeyvData)
    
    
nvault_close(gVault)
}

stock load_user_levels(id)
{
    
gVault nvault_open("SavedLevel")
    
    if(
gVault == INVALID_HANDLE)
        
set_fail_state("[Upgrades] nVault ERROR => Invalid Handle .")
    
    
get_user_name(idgName31)
    
formatex(vKeycharsmax(vData), "%s"gName)
    
formatex(vDatacharsmax(vData), "%i#%i#"g_iLevel[id], g_iExp[id])
    
nvault_get(gVaultvKeyvDatacharsmax(vData))
    
    
replace_all(vDatacharsmax(vData), "#"" ")
    
    new 
experience[32], playerlevel[32]
    
    
parse(vDataexperience31playerlevel31);
    
    
g_iLevel[id] = str_to_num(experience)
    
g_iExp[id] = str_to_num(playerlevel)
    
    
nvault_close(gVault);


Here are the Load/Save:

PHP Code:

public client_putinserveriPlayer )
{    
        
load_user_levels(iPlayer);
    
LoadData(iPlayer)

PHP Code:

public client_disconnect(id
{
    
save_user_levels(id);
    
    
SaveData(id)

What's the matter with them?




----------------------

Quote:
Originally Posted by Bugsy View Post
This is because when a server does not close gracefully, client_disconnect() is not called on all clients and this is most likely where SaveData() is called from on each player.

To avoid this issue, you will need to save data as it changes for each player. It is not as efficient, but you wouldn't lose any data. My recommendation is to track down your crash issue and resolve it and not use a band-aid on all of your plugins.
I tracked the issue which causes the crash, but sometimes the VPS on which is located the server crashesh and server dies also, and I don't want to lose any data.

How I can make nVault save when the data changes?

Last edited by KaLoIaN; 05-10-2016 at 05:42.
KaLoIaN is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 05-10-2016 , 06:56   Re: [HELP] nVault problem
Reply With Quote #4

It doesn't mean that the crashes are caused by that plugin or the code above has errors in it. Save the data more often by adding SaveData(id) whenever the player's data is updated. This will save the data right away and it won't really matter whether client_disconnect(id) is called, i.e. the server shuts down properly.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
KaLoIaN
Senior Member
Join Date: Feb 2013
Old 05-10-2016 , 10:26   Re: [HELP] nVault problem
Reply With Quote #5

So may I set a task with SaveData(id) ?
Will it work good?
KaLoIaN is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 05-10-2016 , 10:33   Re: [HELP] nVault problem
Reply With Quote #6

Yes, you can. A better idea in some aspects is setting a repeating task that will save the data for all players every 5 minutes (for example).
OciXCrom is offline
Send a message via Skype™ to OciXCrom
KaLoIaN
Senior Member
Join Date: Feb 2013
Old 05-10-2016 , 11:16   Re: [HELP] nVault problem
Reply With Quote #7

Quote:
Originally Posted by OciXCrom View Post
Yes, you can. A better idea in some aspects is setting a repeating task that will save the data for all players every 5 minutes (for example).
Will that overflow the server much and cause lag? As like Bugsy said it's not efficient.
KaLoIaN is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 05-10-2016 , 14:08   Re: [HELP] nVault problem
Reply With Quote #8

Not really. Yes, it's totally unfefficient, because the best way is to save them on client_disconnect(id). But, still, unefficient doesn't mean that it wouldn't work.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 05-11-2016 , 09:21   Re: [HELP] nVault problem
Reply With Quote #9

ok, client_disconnect is not called. But maybe other forwards are called , for example plugin_end?
To use get_players then save_data() on plugin_end?
siriusmd99 is offline
Andu.
Member
Join Date: Oct 2013
Location: Belgravistan
Old 05-11-2016 , 11:49   Re: [HELP] nVault problem
Reply With Quote #10

You can save data when player get +exp(on deathmsg event or idk) for example and no data will be lost
Andu. is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 23:00.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode