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();
GameReplay *replay = new GameReplay;
replay->ParseFromArray(_data.data(), _data.size());
if (replay->ParseFromArray(_data.data(), _data.size())) {
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);
GameReplay *replay = new GameReplay;
replay->ParseFromString(resp.replay_data());
if (replay->ParseFromString(resp.replay_data())) {
emit openReplay(replay);
} else {
qDebug() << "could not parse replay!";
}
}
void TabReplays::actDownload()

View file

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

View file

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

View file

@ -101,6 +101,10 @@ QString getSafeDebugString(const ::google::protobuf::Message &message)
#endif // GOOGLE_PROTOBUF_VERSION > 3004000
std::string debug_string;
printer.PrintToString(message, &debug_string);
bool ok = printer.PrintToString(message, &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;
IslMessage newMessage;
newMessage.ParseFromArray(inputBuffer.data(), messageLength);
bool ok = newMessage.ParseFromArray(inputBuffer.data(), messageLength);
inputBuffer.remove(0, messageLength);
messageInProgress = false;
if (ok) {
processMessage(newMessage);
} else {
qDebug() << "[ISL] parsing error!";
}
} while (!inputBuffer.isEmpty());
}
@ -270,7 +274,10 @@ void IslInterface::transmitMessage(const IslMessage &item)
unsigned int size = static_cast<unsigned int>(item.ByteSize());
#endif
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()[2] = (unsigned char)(size >> 8);
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());
#endif
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());
replayDurations.append(replayList[i]->duration_seconds());
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());
#endif
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()[2] = (unsigned char)(size >> 8);
buf.data()[1] = (unsigned char)(size >> 16);
buf.data()[0] = (unsigned char)(size >> 24);
// In case socket->write() calls catchSocketError(), the mutex must not be locked during this call.
writeToSocket(buf);
} else {
qDebug() << "[TcpServerSocketInterface] serialisation error!";
}
totalBytes += size + 4;
locker.relock();
@ -2010,8 +2013,9 @@ void TcpServerSocketInterface::readClient()
return;
CommandContainer newCommandContainer;
bool ok;
try {
newCommandContainer.ParseFromArray(inputBuffer.data(), messageLength);
ok = newCommandContainer.ParseFromArray(inputBuffer.data(), messageLength);
} catch (std::exception &e) {
qDebug() << "Caught std::exception in" << __FILE__ << __LINE__ <<
#ifdef _MSC_VER // Visual Studio
@ -2032,10 +2036,10 @@ void TcpServerSocketInterface::readClient()
#endif
qDebug() << "Message coming from:" << getAddress();
}
inputBuffer.remove(0, messageLength);
messageInProgress = false;
if (ok) {
// dirty hack to make v13 client display the correct error message
if (handshakeStarted)
processCommandContainer(newCommandContainer);
@ -2045,6 +2049,10 @@ void TcpServerSocketInterface::readClient()
prepareDestroy();
}
// end of hack
} else {
qDebug() << "[TcpServerSocketInterface] parsing error!";
}
} while (!inputBuffer.isEmpty());
}
@ -2172,9 +2180,12 @@ void WebsocketServerSocketInterface::flushOutputQueue()
unsigned int size = static_cast<unsigned int>(item.ByteSize());
#endif
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.
writeToSocket(buf);
} else {
qDebug() << "[TcpServerSocketInterface] serialisation error!";
}
totalBytes += size;
locker.relock();
@ -2190,8 +2201,9 @@ void WebsocketServerSocketInterface::binaryMessageReceived(const QByteArray &mes
servatrice->incRxBytes(message.size());
CommandContainer newCommandContainer;
bool ok;
try {
newCommandContainer.ParseFromArray(message.data(), message.size());
ok = newCommandContainer.ParseFromArray(message.data(), message.size());
} catch (std::exception &e) {
qDebug() << "Caught std::exception in" << __FILE__ << __LINE__ <<
#ifdef _MSC_VER // Visual Studio
@ -2213,7 +2225,11 @@ void WebsocketServerSocketInterface::binaryMessageReceived(const QByteArray &mes
qDebug() << "Message coming from:" << getAddress();
}
if (ok) {
processCommandContainer(newCommandContainer);
} else {
qDebug() << "[WebsocketServerSocketInterface] parsing error!";
}
}
bool AbstractServerSocketInterface::isPasswordLongEnough(const int passwordLength)