Raised This Month: $51 Target: $400
 12% 

How to detect if server crashed?


Post New Thread Reply   
 
Thread Tools Display Modes
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 08-16-2018 , 13:17   Re: How to detect if server crashed?
Reply With Quote #21

You shouldn't worry about the server crashing when making a plugin. The person who should worry is the one who uses the plugin and he should find why his server crashes. The best way for saving data is on client_disconnect(ed) and load on client_connect. Don't do it in client_putinserver or client_authorized - it will fail most of the times.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 08-16-2018 , 13:48   Re: How to detect if server crashed?
Reply With Quote #22

Loading should be done on client_authorized - it gets called when the server resolves client's Steam ID. There's no guarantee how much time will pass until that and what other forwards will be called before or after it.
__________________
klippy is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 08-16-2018 , 14:03   Re: How to detect if server crashed?
Reply With Quote #23

Quote:
Originally Posted by KliPPy View Post
Loading should be done on client_authorized - it gets called when the server resolves client's Steam ID. There's no guarantee how much time will pass until that and what other forwards will be called before or after it.
I used client_authorized with a 1-2 second delay in my rank system and I got at least 10 complaints that the XP was completely restarted randomly. I did some testing on my local server and indeed the data was not loaded properly many times, including map change and server restarting. When I changed it to client_connect without a delay, there were no problems reported ever since, even crashing the server didn't cause the data to be reset.

It's not only that specific plugin, this has happened to me way too many times and in every case changing the forward to client_connect fixed the problem.
__________________

Last edited by OciXCrom; 08-16-2018 at 14:04.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
JusTGo
Veteran Member
Join Date: Mar 2013
Old 08-16-2018 , 15:24   Re: How to detect if server crashed?
Reply With Quote #24

Quote:
Originally Posted by OciXCrom View Post
I used client_authorized with a 1-2 second delay in my rank system and I got at least 10 complaints that the XP was completely restarted randomly. I did some testing on my local server and indeed the data was not loaded properly many times, including map change and server restarting. When I changed it to client_connect without a delay, there were no problems reported ever since, even crashing the server didn't cause the data to be reset.

It's not only that specific plugin, this has happened to me way too many times and in every case changing the forward to client_connect fixed the problem.
thats because you are not checking if data is loaded before saving it and that way you are saving player data before it gets loaded which is 0.

somthing like this will fix the problem :

PHP Code:
#include <amxmodx>

new g_data[MAX_PLAYERS+1]
new 
bool:g_data_loaded[MAX_PLAYERS+1]

public 
client_authorized(id)
{
    
load_data(id)
}

public 
client_disconnected(id)
{
    
save_data(id)
    
g_data[id] = 0
}

public 
load_data(id)
{
    
g_data_loaded[id] = true

    
// Your code here
}

public 
save_data(id)
{
    if(
g_data_loaded[id]==false) return
    
g_data_loaded[id] = false

    
// Your code here


__________________

Last edited by JusTGo; 08-16-2018 at 15:27.
JusTGo is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 08-16-2018 , 16:43   Re: How to detect if server crashed?
Reply With Quote #25

Quote:
Originally Posted by JusTGo View Post
thats because you are not checking if data is loaded before saving it and that way you are saving player data before it gets loaded which is 0.

somthing like this will fix the problem :

PHP Code:
#include <amxmodx>

new g_data[MAX_PLAYERS+1]
new 
bool:g_data_loaded[MAX_PLAYERS+1]

public 
client_authorized(id)
{
    
load_data(id)
}

public 
client_disconnected(id)
{
    
save_data(id)
    
g_data[id] = 0
}

public 
load_data(id)
{
    
g_data_loaded[id] = true

    
// Your code here
}

public 
save_data(id)
{
    if(
g_data_loaded[id]==false) return
    
g_data_loaded[id] = false

    
// Your code here


Using player id to save/load data?! That's never going to work. We're talking about nVault and similar methods here.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
DarthMan
Veteran Member
Join Date: Aug 2011
Old 08-16-2018 , 17:04   Re: How to detect if server crashed?
Reply With Quote #26

Quote:
Originally Posted by OciXCrom View Post
You shouldn't worry about the server crashing when making a plugin. The person who should worry is the one who uses the plugin and he should find why his server crashes. The best way for saving data is on client_disconnect(ed) and load on client_connect. Don't do it in client_putinserver or client_authorized - it will fail most of the times.
Good point. I guess that explains why my new version of the mapmanager didn't work fine at first, I was using client_putinserver but after switching to client_connect and checking if it's indeed connected the connected players count worked just fine. I don't know what's wrong with client_putinserver since as far as I know it's called after it was connected.

Last edited by DarthMan; 08-16-2018 at 17:06.
DarthMan is offline
JusTGo
Veteran Member
Join Date: Mar 2013
Old 08-17-2018 , 04:08   Re: How to detect if server crashed?
Reply With Quote #27

Quote:
Originally Posted by OciXCrom View Post
Using player id to save/load data?! That's never going to work. We're talking about nVault and similar methods here.
No...

under // Your code here you should add your saving method nvault,sql..ect

your players data is getting reset because its getting saved before it gets loaded thats why you should make sure at client_disconnected that the player data is loaded or you will be saving zero's.
__________________

Last edited by JusTGo; 08-17-2018 at 04:09.
JusTGo is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 08-17-2018 , 11:24   Re: How to detect if server crashed?
Reply With Quote #28

The data doesn't have to be loaded in order to save it. What if this is the first time the player has joined? If the data is zero, then a zero should be saved. It doesn't have to be non-zero all the time. 0 XP is still possible.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
JusTGo
Veteran Member
Join Date: Mar 2013
Old 08-17-2018 , 12:14   Re: How to detect if server crashed?
Reply With Quote #29

Quote:
Originally Posted by OciXCrom View Post
The data doesn't have to be loaded in order to save it. What if this is the first time the player has joined? If the data is zero, then a zero should be saved. It doesn't have to be non-zero all the time. 0 XP is still possible.
no problem becuase the load process will return zero for new players or old players with zero data the problem is that if you save data before it gets loaded you will be saving zero's lets say i have 400 points which are loaded in client_authorized but i diconnected before they get loaded my new points will be 0, here is a test script all you need to do is to disconnect before client_authorized call

PHP Code:
#include <amxmodx>

#define LOAD_TASK 29130

new g_points[MAX_PLAYERS+1]

public 
plugin_init()
{
    
register_plugin"Data test""0.1.0""JustGo" )
}

public 
client_authorizedid )
{
    
set_task2.0 "Load_data"LOAD_TASK+id)
}

public 
Load_data(taskid)
{
    new 
id taskid LOAD_TASK

    
if( !is_user_connected(id) ) return

    
g_points[id] = 400 // Just an example
    
server_print("Points loaded:%d"g_points[id])
}

public 
client_disconnectedid )
{
    
Save_data(id)
}

public 
Save_data(id)
{
    
server_print("Points saved:%d"g_points[id])
    
g_points[id] = 0

to fix this you can use the following way and data will no longer reset :

PHP Code:
#include <amxmodx>

#define LOAD_TASK 29130

new g_points[MAX_PLAYERS+1]
new 
bool:g_points_loaded[MAX_PLAYERS+1]

public 
plugin_init()
{
    
register_plugin"Data test""0.1.1""JustGo" )
}

public 
client_authorizedid )
{
    
set_task2.0 "Load_data"LOAD_TASK+id)
}

public 
Load_data(taskid)
{
    new 
id taskid LOAD_TASK

    
if( !is_user_connected(id) ) return

    
g_points[id] = 400 // Just an example
    
server_print("Points loaded:%d"g_points[id])
    
g_points_loaded[id] = true
}

public 
client_disconnectedid )
{
    
Save_data(id)
}

public 
Save_data(id)
{
    if(
g_points_loaded[id] == false) return // Make sure we are not saving wrong data

    
server_print("Points saved:%d"g_points[id])
    
g_points[id] = 0
    g_points_loaded
[id] = false

__________________

Last edited by JusTGo; 08-17-2018 at 12:19.
JusTGo 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 03:27.


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