Open knightzac19 opened 8 years ago
Hello, thank you for the investigation.
I will take a look at your notes and at ark survival, sounds like it behaves differently. Meanwhile, could you please fork and push your working changes to github? :)
Sure, here you go https://github.com/knightzac19/node-srcds-rcon/tree/hanging-connection-fix
I also uncommented the code and went back to it and found the only culprit to be is that getData function in connection.js. Also, I'm thinking my specific game doesn't give back anything after the Auth packet and that's why I had to comment out lines 52 and 54.
In comparing this to other RCON language libraries, I'm not sure if you need to wait for the packet response after getting the initial auth packet.
For example in the PHP library I have used they put this in there,
// If we receive SERVERDATA_RESPONSE_VALUE, then we need to read again
// More info: https://developer.valvesoftware.com/wiki/Source_RCON_Protocol#Additional_Comments
if( $Type === SourceQuery::SERVERDATA_RESPONSE_VALUE )
{
$Buffer = $this->Read( );
$RequestID = $Buffer->GetLong( );
$Type = $Buffer->GetLong( );
}
Edit: I went ahead and ported the if statement over to nodejs and put this in and it works fine for me so far: https://github.com/knightzac19/node-srcds-rcon/blob/hanging-connection-fix/index.js#L51
I also edited the if statement above to look at the packet instead of the ID. https://github.com/knightzac19/node-srcds-rcon/blob/hanging-connection-fix/index.js#L46
@knightzac19 thank you, again :) I probably won't find the time to test / update until this weekend, but your work isn't in vain, it's really helpful.
Unfortunately, the added conditions if (res.id === -1 || res.type !== packet.SERVERDATA_AUTH_RESPONSE) {
and especially if(res.type === packet.SERVERDATA_RESPONSE_VALUE) {
could potentially break other games' rcon commands. This library is being used for Minecraft afaik, and there's no guarantee it's following valve's protocol, just like ark survival isn't.
I'll have to test some of these games before committing to this fix.
Based on the list provided here, https://github.com/xPaw/PHP-Source-Query , RCON should work fine for most games using the SERVERDATA_RESPONSE_VALUE. (and from the looks of it, Minecraft is on their list)
Is there any update to this old server connection hang? I am experiencing this constantly with my node app and would love a fix.
I would also love to see @knightzac19 changes merged, as it seems to fix the connection hanging issue.
ok, it doesn't really fix things, sometimes it still hangs while querying servers, sad times.
Yes, I've given up on this module in favor of the rcon module for now. @gelzis
For some reason when connecting to my RCON server the authorization hangs forever.
I narrowed it down to lines 53-55 of the index.js. For some reason that promise is hanging forever and it just ends up timing out at some point. I pulled the _init out of there and commented out the promise and it connects instantly and runs commands without any issue.
return connection.getData(dataHandler).then(() => { _init(connection); });
I also found that if I don't provide a timeout for the rcon.command function it also just sits there and hangs for at least 5-10 seconds and then returns the buffer. If I provide at least a 1000ms timeout it runs instantly.
Node version: 6.2.2 Node-srcds-rcon version: latest RCON Game: Ark Survival Evolved
Code being used,
rcon.connect().then(function(){ console.log("Connected!"); rcon.command('getchat',1000).then((test) => { console.log("chat ",test); }); });
Update: Did a little more digging because I started having more issues and found a packet getting thrown in with my rcon request. Found these on lines 87-92 and 100-102 of the index.js causing issues.
let ackId = _getNextPacketId(); let ack = packet.request({ id: ackId, type: packet.SERVERDATA_EXECCOMMAND, body: '' });
andif (res.id === ackId) { return false; } else if (res.id === reqId) {
Seems like every time the "getData" function gets sent a false variable it just hangs terribly as well. I've since commented out the first part and the first if statement. Everything connects/returns within less than a second now, both on my local server and my remote server.