Log server identification and connection lifecycle (#7731)

* Log remote server identification and connection lifecycle [skip ci]

* Update libcockatrice_network/libcockatrice/network/client/remote/remote_client.cpp

Co-authored-by: RickyRister <42636155+RickyRister@users.noreply.github.com>

---------

Co-authored-by: BruebachL <44814898+BruebachL@users.noreply.github.com>
Co-authored-by: RickyRister <42636155+RickyRister@users.noreply.github.com>
This commit is contained in:
Bryce! 2026-11-03 04:38:54 -05:00 • committed by GitHub
parent bc09ec6afe
commit ada8f399f1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -137,6 +137,7 @@ RemoteClient::~RemoteClient()
void RemoteClient::slotSocketError(QAbstractSocket::SocketError /*error*/) void RemoteClient::slotSocketError(QAbstractSocket::SocketError /*error*/)
{ {
QString errorString = socket->errorString(); QString errorString = socket->errorString();
qCWarning(RemoteClientLog) << "Server connection error:" << errorString;
doDisconnectFromServer(); doDisconnectFromServer();
emit socketError(errorString); emit socketError(errorString);
} }
@ -146,6 +147,7 @@ void RemoteClient::slotWebSocketError(QAbstractSocket::SocketError /*error*/)
QString errorString = websocket->errorString(); QString errorString = websocket->errorString();
if (getStatus() != ClientStatus::StatusDisconnected) { if (getStatus() != ClientStatus::StatusDisconnected) {
qCWarning(RemoteClientLog) << "Server connection error:" << errorString;
doDisconnectFromServer(); doDisconnectFromServer();
emit socketError(errorString); emit socketError(errorString);
} }
@ -153,6 +155,7 @@ void RemoteClient::slotWebSocketError(QAbstractSocket::SocketError /*error*/)
void RemoteClient::slotConnected() void RemoteClient::slotConnected()
{ {
qCInfo(RemoteClientLog) << "Server transport connected";
timeRunning = lastDataReceived = 0; timeRunning = lastDataReceived = 0;
timer->start(); timer->start();
@ -166,6 +169,12 @@ void RemoteClient::slotConnected()
void RemoteClient::processServerIdentificationEvent(const Event_ServerIdentification &event) void RemoteClient::processServerIdentificationEvent(const Event_ServerIdentification &event)
{ {
// Identification arrives before login, including when protocol versions differ.
// Quote the server-supplied strings in the log and limit their size.
const QString serverName = QString::fromStdString(event.server_name()).left(256);
const QString serverVersion = QString::fromStdString(event.server_version()).left(256);
qCInfo(RemoteClientLog) << "Server identification:" << serverName
<< "version" << serverVersion << "protocol version" << event.protocol_version();
if (event.protocol_version() != protocolVersion) { if (event.protocol_version() != protocolVersion) {
emit protocolVersionMismatch(protocolVersion, event.protocol_version()); emit protocolVersionMismatch(protocolVersion, event.protocol_version());
setStatus(StatusDisconnecting); setStatus(StatusDisconnecting);
@ -698,6 +707,8 @@ void RemoteClient::sendCommandContainer(const CommandContainer &cont)
void RemoteClient::connectToHost(const QString &hostname, unsigned int port) void RemoteClient::connectToHost(const QString &hostname, unsigned int port)
{ {
usingWebSocket = port == 443 || port == 80 || port == 4748 || port == 8080; usingWebSocket = port == 443 || port == 80 || port == 4748 || port == 8080;
qCInfo(RemoteClientLog) << "Connecting to server" << hostname << "port" << port
<< (usingWebSocket ? "using WebSocket" : "using TCP");
if (usingWebSocket) { if (usingWebSocket) {
QUrl url(QString("%1://%2:%3/servatrice").arg(port == 443 ? "wss" : "ws").arg(hostname).arg(port)); QUrl url(QString("%1://%2:%3/servatrice").arg(port == 443 ? "wss" : "ws").arg(hostname).arg(port));
websocket->open(url); websocket->open(url);