swift-project / pilotclient

Cross-platform cross-simulator pilot client for virtual air traffic networks
https://swift-project.org
GNU General Public License v3.0
94 stars 27 forks source link

FSD server error hidden by TCP socket error #159

Open oktal3700 opened 2 years ago

oktal3700 commented 2 years ago

When the server sends a kick packet or error packet and then disconnects the socket, the socket error seems to take priority in the swift GUI, so the server error or kick message gets hidden.

oktal3700 commented 2 years ago

The issue could possibly be in CFsdClient. If there are too many packets waiting, the method readDataFromSocketMaxLines will return after scheduling itself to be called again in a few milliseconds. The disconnection could occur before the method is called again, and therefore before the error packet has been read.

A solution could be along the following lines:

const QByteArray allBytes = m_socket->peek(m_socket->bytesAvailable());
int index = allBytes.indexOf("\r\n$ER");
if (index < 0) { index = allBytes.indexOf("\r\n$!!"); }
if (index >= 0)
{
    index += 2;
    const int end = allBytes.indexOf("\r\n", index);
    if (end >= 0)
    {
        const QByteArray dataEncoded = allBytes.mid(index, end - index);
        // ...
    }
}