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

Dealing with server/plugin crash


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
r3D w0LF
Senior Member
Join Date: Dec 2013
Location: Albania
Old 02-22-2018 , 15:53   Dealing with server/plugin crash
Reply With Quote #1

Hello,
Im fairly new to amx scripting, but basically i am trying to save a value (timestamp) to the database when a user joins the server, and when he leaves the server. And as far as i can tell, I am going to do that stuff in
Code:
client_putinserver(id)
and
Code:
client_disconnect(id)
. And im supposing if the server crashes, the code under client_disconnect wont run, and I need the number of values to be even. Is there any way I could achieve this even if the server crashes?

Last edited by r3D w0LF; 02-22-2018 at 15:56.
r3D w0LF is offline
JusTGo
Veteran Member
Join Date: Mar 2013
Old 02-22-2018 , 17:03   Re: Dealing with server/plugin crash
Reply With Quote #2

you can make a task that repeat itself every x second(s) depends on what you are trying to do and save stuff there in-case of server crash
__________________
JusTGo is offline
r3D w0LF
Senior Member
Join Date: Dec 2013
Location: Albania
Old 02-22-2018 , 17:58   Re: Dealing with server/plugin crash
Reply With Quote #3

Well, that case is a bit more than just creating a row in database. What i was also wondering is whether the code under client_disconnect runs before map changes?
r3D w0LF is offline
JusTGo
Veteran Member
Join Date: Mar 2013
Old 02-22-2018 , 18:23   Re: Dealing with server/plugin crash
Reply With Quote #4

then you should check if the row exist then create/update it
you can also use default game events like round end/start if you don't want an extra task depends on what you need and when you want to save your data
client_disconnect is called when ever player disconnects so yes when map changes and players droped it will get called
__________________
JusTGo is offline
Old 02-23-2018, 02:21
Clauu
This message has been deleted by Clauu.
Clauu
Senior Member
Join Date: Feb 2008
Location: RO
Old 02-23-2018 , 02:33   Re: Dealing with server/plugin crash
Reply With Quote #5

You can't handle/catch a crash. Instead you could add a new row and use that to check if something went wrong. Ex
Code:
player connects to server -> update 'connect_timestamp'=timestamp, 'completed'=0
Code:
player disconnect from server -> update 'disconnect_timestamp'=timestamp, 'completed'=1
In case of crash it won't give you the exact ammount of time when player disconnets but at least you will know how to handle such entries with completed=0 which leads to the fact that player did not disconnect yet or something went wrong/crash
Alternatively you could make some query script in php/c/whatever and check your server for uptime every 1 second. In case of crash just count the downtime and add it to players having timestamp greater that currenttime-10minutes(i guess your server won't be down more than 10minutes?) and completed=0

Last edited by Clauu; 02-23-2018 at 02:41.
Clauu is offline
r3D w0LF
Senior Member
Join Date: Dec 2013
Location: Albania
Old 02-23-2018 , 03:03   Re: Dealing with server/plugin crash
Reply With Quote #6

Well, i guess ill have to initially set connect timestamp to systemtime, and dc timestamp to 0, afterwards update it on player dc or player death.
Is there any full documentation of these events? I read somewhere that the api is not full.
Also, does client_death(victim) return the id of the victim? (Im guessing so, probably dumb to ask)
And yeah, most of the data will be used in php scripts, so i guess a few server queries wont hurt after all.

Last edited by r3D w0LF; 02-23-2018 at 03:07.
r3D w0LF is offline
E1_531G
Senior Member
Join Date: Dec 2017
Old 02-23-2018 , 04:55   Re: Dealing with server/plugin crash
Reply With Quote #7

Quote:
Also, does client_death(victim) return the id of the victim? (Im guessing so, probably dumb to ask)
Yes. https://www.amxmodx.org/api/tsx/client_death

Be aware, on crash nothing will be printed/executed.

Save on new round (for example, every 2 minutes) will be better way, i think.
__________________
My English is A0
E1_531G is offline
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 02-25-2018 , 06:43   Re: Dealing with server/plugin crash
Reply With Quote #8

well first, you're probably going to want to update to amxmodx 1.8.3 and use the new client_disconnected() instead of _disconnect, which does not get called in a very few special cases of dropped players


then, you might also add a periodic check, such as, once every 2 minutes, check the database for all players that have
WHERE join_time > leave_time (in the case of timestamps, this would only happen if a player joined but hasn't left yet, all valid data should have join_time <= leave_time assuming players can't time travel), if you find any, check if they are still on the server, if not, write the new leave_time


not sure if the logic is sound but I just gave it a minute of thinking and this is what my first approach would be
__________________
Meanwhile, in 2050:
Quote:
Originally Posted by aron9forever
useless small optimizations
Quote:
Originally Posted by Black Rose View Post
On a map that is 512x512x128 units you end up with 3,355,443,200,000 different "positions". To store each one of those positions individually in the variable "user_or" you need 12 terabytes of memory.

Last edited by aron9forever; 02-25-2018 at 06:43.
aron9forever is offline
r3D w0LF
Senior Member
Join Date: Dec 2013
Location: Albania
Old 02-25-2018 , 08:05   Re: Dealing with server/plugin crash
Reply With Quote #9

Quote:
Originally Posted by aron9forever View Post
well first, you're probably going to want to update to amxmodx 1.8.3 and use the new client_disconnected() instead of _disconnect, which does not get called in a very few special cases of dropped players

Thats interesting. Could you link me the differences between client_disconnect and client_disconnected? Which events does client_disconnect miss?
And, does it work on ReHLDS?

Last edited by r3D w0LF; 02-25-2018 at 08:05.
r3D w0LF is offline
r3D w0LF
Senior Member
Join Date: Dec 2013
Location: Albania
Old 03-12-2018 , 10:04   Re: Dealing with server/plugin crash
Reply With Quote #10

So, recently got to actually work on it and encountered a warning:
Code:
warning 209: function client_death should return a value
And here is the code that is blocking it:
PHP Code:
    if (strfind(name"myname") == -1) {
        return 
PLUGIN_CONTINUE
    

Basically, for this test period im recording stuff only for a specific name. Does the warning mess up anything else, should I just ignore it or hook the function to ResetHUD/another event?

Another thing I was thinking is:
Since before map changes client_disconnect is called, but since there are 32 players online and the sql query will have to run 32 times (im guessing thats right), will it not have time to run the query for every single player? Or does it actually wait till the function is completed for every single user, and then changes the map?

Last edited by r3D w0LF; 03-12-2018 at 10:06.
r3D w0LF 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 11:28.


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