• Reliably get Steam ID on client disconnect
    18 replies, posted
From personal experience, using PlayerDisconnect does NOT work well. EntityRemoved seems to be the more reliable way to detect disconnects. However this returns an Entity instead of a Player. So I either need to find a way to reliably get disconnected players or find a way to get the steam ID of an Entity. Anybody have any ideas?
Use gameevent.Listen (it has example for player_disconnect), you can get player entity with Player(data.userid)
data.networkid
Thanks for your replies! I will see if it works as intended on the next server restart and either post a new reply or mark as answer. This is my code BTW: gameevent.Listen( "player_disconnect" ) function GadisOnDisconnect( data )         local ply = player.GetBySteamID(data.networkid)         if !data.bot and ply != false then                 local hours = math.floor((ply:GetUTime() + CurTime() - ply:GetUTimeStart())/60/60)                 -- Replaced actual domains with example.com                 http.Fetch("http://example.com/player.php?id="..ply:SteamID64().."&rank="..ply:GetUserGroup().."&hours="..hours)                 http.Fetch("http://example.com/metrics.php?id="..ply:SteamID64().."&acc=0&act=1")         end end hook.Add( "player_disconnect", "GadisOnDisconnect", GadisOnDisconnect )
What are you trying to do?
Sorry about the delay. Trying to coordinate between me, the programmer, and the systems admin takes a while, given our schedules. @LoweChaser @_Fancy_ That alternative does not seem to work, at least not for running disconnect in console. It never calls the HTTP API. I will continue to research what does and does not activate this, but for I know for a fact something isn't working. @Kevlon I'm working on an integration platform. Right now I'm adding player connect/disconnect analytics.
Why GET and not POST? Do you know about MySQL modules (mysqloo and tmysql)?
https://github.com/FredyH/MySQLOO This is much more efficient than going through a web server.
I was made aware of it's existence and that it was installed on the server by the sysadmin. As such I will be removing the middle man web services from the source. Lots of refactoring and conversion involved, but worth it in the end. Here's the status update on the event: On client crash On console disconnect On kick On ban On server restart Getting player object So the question is, how can I get the UTime of the player? Converting Steam ID to Steam ID 64 for the database is no problem, but without the UTime my autoranking system breaks.
I really just want to know how you guys get PlayerDisconnect to fail? I've never once had it misbehave on me. Also @tinkerwolf do you mean you need to get UTime based off of the SteamID? You need to calculate the UniqueID from the SteamID because I believe UTime still uses those (bleh), then run an SQL query to pull it out: local uid = util.CRC("gm_" .. steamID .. "_gm") local row = sql.QueryRow("SELECT totaltime, lastvisit FROM utime WHERE player = " .. uid .. ";") local time = row and row.totaltime
Are you referring to gameevent method, it's working fine. It just doesn't give me all the attributes I need. If you're referring to OnPlayerDisconnect, it doesn't receive crashes or console quitting.
Yes it does?
It doesn't on my community's server. It even says in the wiki that it's highly unreliable and has more than one circumstance that it won't call it. Most don't notice, I assume, because they don't log a connection and a disconnection as a pair. Either way, I'm working on the lua code right now to remove the web server from the picture and try that code you posted to get the required info. P.S. anyone have a way to convert from regular steam ID to steam ID 64 in lua handy?
The wiki says nothing about it being unreliable, as @KingofBeast said I've never had this happen to me. Sounds like something is either erroring in that hook or returning early. util.SteamIDTo64
@bigdogmat My bad, I was thinking of another wiki that said it was unreliable. Thank you for the function.
Yeah, I went and tested it just to be sure with both 'quit' and an infinite loop to crash my game and both scenarios got the hook called. If ever it was an issue I don't believe it is any longer. Still I don't think I've ever experienced it before, and that's running popular servers for almost 10 years now. It's odd that I keep seeing the concern pop up recently.
I don't know then. The normal hook just does not trigger when people timeout, quit from console, or crash on my community's server. From reports to/from the sysadmin, it's looking like the gameevent.Listen method is working just as badly, but I don't have enough data to say for sure right now. The hook isn't returning early, it just isn't being called. I tested it by adding a log entry at the top of the hook before anything else and using console quit, and it didn't show up at all in the log. It was actually my first thought.
I don't think you understood what I meant, I meant return early as in another hook returning a value other than nil, thus making it so yours doesn't run.
I didn't even know you could do that to other addons... I found that my issue was with the data.bot. I tried using if not data.bot then but for some reason it was always evaluating to false. So instead, I switched to something I know will work if data.networkid ~= "BOT" then because I found that when it is a bot, data.networkid returns BOT and it worked with player:SteamID().
Sorry, you need to Log In to post a reply to this thread.