fix compiling on arch

This commit is contained in:
ebbit1q 2026-04-02 20:18:01 +02:00
parent ba786a0289
commit 3cf3fa789d
7 changed files with 108 additions and 56 deletions

View file

@ -265,9 +265,11 @@ void TabReplays::actOpenLocalReplay()
f.close(); f.close();
GameReplay *replay = new GameReplay; GameReplay *replay = new GameReplay;
replay->ParseFromArray(_data.data(), _data.size()); if (replay->ParseFromArray(_data.data(), _data.size())) {
emit openReplay(replay);
emit openReplay(replay); } else {
qDebug() << "could not parse replay!";
}
} }
} }
@ -379,9 +381,12 @@ void TabReplays::openRemoteReplayFinished(const Response &r)
const Response_ReplayDownload &resp = r.GetExtension(Response_ReplayDownload::ext); const Response_ReplayDownload &resp = r.GetExtension(Response_ReplayDownload::ext);
GameReplay *replay = new GameReplay; GameReplay *replay = new GameReplay;
replay->ParseFromString(resp.replay_data()); if (replay->ParseFromString(resp.replay_data())) {
emit openReplay(replay); emit openReplay(replay);
} else {
qDebug() << "could not parse replay!";
}
} }
void TabReplays::actDownload() void TabReplays::actDownload()

View file

@ -277,9 +277,11 @@ void MainWindow::actWatchReplay()
file.close(); file.close();
replay = new GameReplay; replay = new GameReplay;
replay->ParseFromArray(buf.data(), buf.size()); if (replay->ParseFromArray(buf.data(), buf.size())) {
tabSupervisor->openReplay(replay);
tabSupervisor->openReplay(replay); } else {
qDebug() << "[MainWindow] failed to parse replay!";
}
} }
void MainWindow::localGameEnded() void MainWindow::localGameEnded()

View file

@ -390,14 +390,18 @@ void RemoteClient::readData()
return; return;
ServerMessage newServerMessage; ServerMessage newServerMessage;
newServerMessage.ParseFromArray(inputBuffer.data(), messageLength); bool ok = newServerMessage.ParseFromArray(inputBuffer.data(), messageLength);
qCDebug(RemoteClientLog).noquote() << "IN" << getSafeDebugString(newServerMessage);
inputBuffer.remove(0, messageLength); inputBuffer.remove(0, messageLength);
messageInProgress = false; messageInProgress = false;
processProtocolItem(newServerMessage); if (ok) {
qCDebug(RemoteClientLog).noquote() << "IN" << getSafeDebugString(newServerMessage);
processProtocolItem(newServerMessage);
} else {
qCDebug(RemoteClientLog) << "parsing error!";
}
if (getStatus() == StatusDisconnecting) // use thread-safe getter if (getStatus() == StatusDisconnecting) // use thread-safe getter
doDisconnectFromServer(); doDisconnectFromServer();
@ -408,11 +412,13 @@ void RemoteClient::websocketMessageReceived(const QByteArray &message)
{ {
lastDataReceived = timeRunning; lastDataReceived = timeRunning;
ServerMessage newServerMessage; ServerMessage newServerMessage;
newServerMessage.ParseFromArray(message.data(), message.length()); if (newServerMessage.ParseFromArray(message.data(), message.length())) {
qCDebug(RemoteClientLog).noquote() << "IN" << getSafeDebugString(newServerMessage);
qCDebug(RemoteClientLog).noquote() << "IN" << getSafeDebugString(newServerMessage); processProtocolItem(newServerMessage);
} else {
processProtocolItem(newServerMessage); qCDebug(RemoteClientLog) << "parsing error!";
}
} }
void RemoteClient::sendCommandContainer(const CommandContainer &cont) void RemoteClient::sendCommandContainer(const CommandContainer &cont)
@ -426,19 +432,27 @@ void RemoteClient::sendCommandContainer(const CommandContainer &cont)
qCDebug(RemoteClientLog).noquote() << "OUT" << getSafeDebugString(cont); qCDebug(RemoteClientLog).noquote() << "OUT" << getSafeDebugString(cont);
QByteArray buf; QByteArray buf;
bool ok;
if (usingWebSocket) { if (usingWebSocket) {
buf.resize(size); buf.resize(size);
cont.SerializeToArray(buf.data(), size); ok = cont.SerializeToArray(buf.data(), size);
websocket->sendBinaryMessage(buf); if (ok) {
websocket->sendBinaryMessage(buf);
}
} else { } else {
buf.resize(size + 4); buf.resize(size + 4);
cont.SerializeToArray(buf.data() + 4, size); ok = cont.SerializeToArray(buf.data() + 4, size);
buf.data()[3] = (unsigned char)size; if (ok) {
buf.data()[2] = (unsigned char)(size >> 8); buf.data()[3] = (unsigned char)size;
buf.data()[1] = (unsigned char)(size >> 16); buf.data()[2] = (unsigned char)(size >> 8);
buf.data()[0] = (unsigned char)(size >> 24); buf.data()[1] = (unsigned char)(size >> 16);
buf.data()[0] = (unsigned char)(size >> 24);
socket->write(buf); socket->write(buf);
}
}
if (!ok) {
qCDebug(RemoteClientLog) << "transmit error!";
} }
} }

View file

@ -101,6 +101,10 @@ QString getSafeDebugString(const ::google::protobuf::Message &message)
#endif // GOOGLE_PROTOBUF_VERSION > 3004000 #endif // GOOGLE_PROTOBUF_VERSION > 3004000
std::string debug_string; std::string debug_string;
printer.PrintToString(message, &debug_string); bool ok = printer.PrintToString(message, &debug_string);
return QString::number(size) + " bytes " + QString::fromStdString(debug_string); if (ok) {
return QString::number(size) + " bytes " + QString::fromStdString(debug_string);
} else {
return "could not convert message to string";
}
} }

View file

@ -242,11 +242,15 @@ void IslInterface::readClient()
return; return;
IslMessage newMessage; IslMessage newMessage;
newMessage.ParseFromArray(inputBuffer.data(), messageLength); bool ok = newMessage.ParseFromArray(inputBuffer.data(), messageLength);
inputBuffer.remove(0, messageLength); inputBuffer.remove(0, messageLength);
messageInProgress = false; messageInProgress = false;
processMessage(newMessage); if (ok) {
processMessage(newMessage);
} else {
qDebug() << "[ISL] parsing error!";
}
} while (!inputBuffer.isEmpty()); } while (!inputBuffer.isEmpty());
} }
@ -270,7 +274,10 @@ void IslInterface::transmitMessage(const IslMessage &item)
unsigned int size = static_cast<unsigned int>(item.ByteSize()); unsigned int size = static_cast<unsigned int>(item.ByteSize());
#endif #endif
buf.resize(size + 4); buf.resize(size + 4);
item.SerializeToArray(buf.data() + 4, size); if (!item.SerializeToArray(buf.data() + 4, size)) {
qDebug() << "[ISL] transmit error!";
return;
}
buf.data()[3] = (unsigned char)size; buf.data()[3] = (unsigned char)size;
buf.data()[2] = (unsigned char)(size >> 8); buf.data()[2] = (unsigned char)(size >> 8);
buf.data()[1] = (unsigned char)(size >> 16); buf.data()[1] = (unsigned char)(size >> 16);

View file

@ -865,12 +865,16 @@ void Servatrice_DatabaseInterface::storeGameInformation(const QString &roomName,
const unsigned int size = static_cast<unsigned int>(replayList[i]->ByteSize()); const unsigned int size = static_cast<unsigned int>(replayList[i]->ByteSize());
#endif #endif
blob.resize(size); blob.resize(size);
replayList[i]->SerializeToArray(blob.data(), size); qulonglong replayId = replayList[i]->replay_id();
if (replayList[i]->SerializeToArray(blob.data(), size)) {
replayIds.append(QVariant((qulonglong)replayList[i]->replay_id())); replayIds.append(QVariant(replayId));
replayGameIds.append(gameInfo.game_id()); replayGameIds.append(gameInfo.game_id());
replayDurations.append(replayList[i]->duration_seconds()); replayDurations.append(replayList[i]->duration_seconds());
replayBlobs.append(blob); replayBlobs.append(blob);
} else {
qDebug() << "failed to serialise replay, id:" << replayId << "game:" << gameInfo.game_id();
}
} }
{ {

View file

@ -1971,13 +1971,16 @@ void TcpServerSocketInterface::flushOutputQueue()
unsigned int size = static_cast<unsigned int>(item.ByteSize()); unsigned int size = static_cast<unsigned int>(item.ByteSize());
#endif #endif
buf.resize(size + 4); buf.resize(size + 4);
item.SerializeToArray(buf.data() + 4, size); if (item.SerializeToArray(buf.data() + 4, size)) {
buf.data()[3] = (unsigned char)size; buf.data()[3] = (unsigned char)size;
buf.data()[2] = (unsigned char)(size >> 8); buf.data()[2] = (unsigned char)(size >> 8);
buf.data()[1] = (unsigned char)(size >> 16); buf.data()[1] = (unsigned char)(size >> 16);
buf.data()[0] = (unsigned char)(size >> 24); buf.data()[0] = (unsigned char)(size >> 24);
// In case socket->write() calls catchSocketError(), the mutex must not be locked during this call. // In case socket->write() calls catchSocketError(), the mutex must not be locked during this call.
writeToSocket(buf); writeToSocket(buf);
} else {
qDebug() << "[TcpServerSocketInterface] serialisation error!";
}
totalBytes += size + 4; totalBytes += size + 4;
locker.relock(); locker.relock();
@ -2010,8 +2013,9 @@ void TcpServerSocketInterface::readClient()
return; return;
CommandContainer newCommandContainer; CommandContainer newCommandContainer;
bool ok;
try { try {
newCommandContainer.ParseFromArray(inputBuffer.data(), messageLength); ok = newCommandContainer.ParseFromArray(inputBuffer.data(), messageLength);
} catch (std::exception &e) { } catch (std::exception &e) {
qDebug() << "Caught std::exception in" << __FILE__ << __LINE__ << qDebug() << "Caught std::exception in" << __FILE__ << __LINE__ <<
#ifdef _MSC_VER // Visual Studio #ifdef _MSC_VER // Visual Studio
@ -2032,19 +2036,23 @@ void TcpServerSocketInterface::readClient()
#endif #endif
qDebug() << "Message coming from:" << getAddress(); qDebug() << "Message coming from:" << getAddress();
} }
inputBuffer.remove(0, messageLength); inputBuffer.remove(0, messageLength);
messageInProgress = false; messageInProgress = false;
// dirty hack to make v13 client display the correct error message if (ok) {
if (handshakeStarted) // dirty hack to make v13 client display the correct error message
processCommandContainer(newCommandContainer); if (handshakeStarted)
else if (!newCommandContainer.has_cmd_id()) { processCommandContainer(newCommandContainer);
handshakeStarted = true; else if (!newCommandContainer.has_cmd_id()) {
if (!initTcpSession()) handshakeStarted = true;
prepareDestroy(); if (!initTcpSession())
prepareDestroy();
}
// end of hack
} else {
qDebug() << "[TcpServerSocketInterface] parsing error!";
} }
// end of hack
} while (!inputBuffer.isEmpty()); } while (!inputBuffer.isEmpty());
} }
@ -2172,9 +2180,12 @@ void WebsocketServerSocketInterface::flushOutputQueue()
unsigned int size = static_cast<unsigned int>(item.ByteSize()); unsigned int size = static_cast<unsigned int>(item.ByteSize());
#endif #endif
buf.resize(size); buf.resize(size);
item.SerializeToArray(buf.data(), size); if (item.SerializeToArray(buf.data(), size)) {
// In case socket->write() calls catchSocketError(), the mutex must not be locked during this call. // In case socket->write() calls catchSocketError(), the mutex must not be locked during this call.
writeToSocket(buf); writeToSocket(buf);
} else {
qDebug() << "[TcpServerSocketInterface] serialisation error!";
}
totalBytes += size; totalBytes += size;
locker.relock(); locker.relock();
@ -2190,8 +2201,9 @@ void WebsocketServerSocketInterface::binaryMessageReceived(const QByteArray &mes
servatrice->incRxBytes(message.size()); servatrice->incRxBytes(message.size());
CommandContainer newCommandContainer; CommandContainer newCommandContainer;
bool ok;
try { try {
newCommandContainer.ParseFromArray(message.data(), message.size()); ok = newCommandContainer.ParseFromArray(message.data(), message.size());
} catch (std::exception &e) { } catch (std::exception &e) {
qDebug() << "Caught std::exception in" << __FILE__ << __LINE__ << qDebug() << "Caught std::exception in" << __FILE__ << __LINE__ <<
#ifdef _MSC_VER // Visual Studio #ifdef _MSC_VER // Visual Studio
@ -2213,7 +2225,11 @@ void WebsocketServerSocketInterface::binaryMessageReceived(const QByteArray &mes
qDebug() << "Message coming from:" << getAddress(); qDebug() << "Message coming from:" << getAddress();
} }
processCommandContainer(newCommandContainer); if (ok) {
processCommandContainer(newCommandContainer);
} else {
qDebug() << "[WebsocketServerSocketInterface] parsing error!";
}
} }
bool AbstractServerSocketInterface::isPasswordLongEnough(const int passwordLength) bool AbstractServerSocketInterface::isPasswordLongEnough(const int passwordLength)