Closed kamrote closed 1 year ago
seems that this issue is caused by some servers purposefully blocking the IP of servers/vpns/proxies, can only really fix by buying a residential proxy or running on a local machine
Thanks for the update! Linking this with issue #14 for future reference.
Some additional info for anyone finding this in the future:
This is caused by a premature socket.Close()
in the CompanionServer.Listener class inside the Assembly-CSharp.dll from the server game files.
Here is the code that causes it:
this._server.Start((Action<IWebSocketConnection>) (socket =>
{
IPAddress address = socket.ConnectionInfo.ClientIpAddress;
if (!listener.Limiter.TryAdd(address) || listener._ipBans.IsBanned(address))
{
socket.Close();
}
else
{
Connection conn = new Connection(Interlocked.Increment(ref listener._nextConnectionId), listener, socket);
socket.OnClose = (Action) (() =>
{
listener.Limiter.Remove(address);
syncContext.Post((SendOrPostCallback) (c => ((Connection) c).OnClose()), (object) conn);
});
socket.OnBinary = new BinaryDataHandler(conn.OnMessage);
socket.OnError = new Action<Exception>(UnityEngine.Debug.LogError);
}
}));
Normally, the websocket would be upgraded after the initial request, then after the handshake is complete, it would send the close packet. However, rust+ sends this prematurely, in the reply packet to the websocket initiation request, rather than after the upgrade handshake is complete. Because the ws library is expecting a reply like HTTP/1.1 101 Switching Protocols
, it errors when it receives the byte sequence 0x88, 0x02, 0x03, 0xE8
(websocket close w/ optional status code of 1000 - normal closure
) see RFC 6455.
Here's partial list of what can cause rust+ to call socket.Close() early:
Normal websocket handshake:
Rust+ premature close (highlighted frame = websocket close):
Seems that some specific servers have issues w/ connecting, in this particular case this issue was on rusticated us main