mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 04:37:48 +02:00
fix the new send asset task
This commit is contained in:
parent
dc7d7ef444
commit
cb903a8d06
2 changed files with 15 additions and 22 deletions
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
#include "AssetUtils.h"
|
#include "AssetUtils.h"
|
||||||
|
|
||||||
SendAssetTask::SendAssetTask(QSharedPointer<udt::Packet> packet, const SharedNodePointer& sendToNode, const QDir& resourcesDir) :
|
SendAssetTask::SendAssetTask(QSharedPointer<NLPacket> packet, const SharedNodePointer& sendToNode, const QDir& resourcesDir) :
|
||||||
QRunnable(),
|
QRunnable(),
|
||||||
_packet(packet),
|
_packet(packet),
|
||||||
_senderNode(sendToNode),
|
_senderNode(sendToNode),
|
||||||
|
@ -43,31 +43,31 @@ void SendAssetTask::run() {
|
||||||
_packet->readPrimitive(&start);
|
_packet->readPrimitive(&start);
|
||||||
_packet->readPrimitive(&end);
|
_packet->readPrimitive(&end);
|
||||||
|
|
||||||
QString hexHash = _assetHash.toHex();
|
QString hexHash = assetHash.toHex();
|
||||||
|
|
||||||
qDebug() << "Received a request for the file (" << messageID << "): " << hexHash << " from " << start << " to " << end;
|
qDebug() << "Received a request for the file (" << messageID << "): " << hexHash << " from " << start << " to " << end;
|
||||||
|
|
||||||
qDebug() << "Starting task to send asset: " << hexHash << " for messageID " << _messageID;
|
qDebug() << "Starting task to send asset: " << hexHash << " for messageID " << messageID;
|
||||||
auto replyPacketList = std::unique_ptr<NLPacketList>(new NLPacketList(PacketType::AssetGetReply, QByteArray(), true, true));
|
auto replyPacketList = std::unique_ptr<NLPacketList>(new NLPacketList(PacketType::AssetGetReply, QByteArray(), true, true));
|
||||||
|
|
||||||
replyPacketList->write(_assetHash);
|
replyPacketList->write(assetHash);
|
||||||
|
|
||||||
replyPacketList->writePrimitive(_messageID);
|
replyPacketList->writePrimitive(messageID);
|
||||||
|
|
||||||
if (_end <= _start) {
|
if (end <= start) {
|
||||||
writeError(replyPacketList.get(), AssetServerError::INVALID_BYTE_RANGE);
|
writeError(replyPacketList.get(), AssetServerError::INVALID_BYTE_RANGE);
|
||||||
} else {
|
} else {
|
||||||
QString filePath = _resourcesDir.filePath(QString(hexHash) + "." + QString(extension));
|
QString filePath = _resourcesDir.filePath(QString(hexHash) + "." + QString(extension));
|
||||||
|
|
||||||
QFile file { _filePath };
|
QFile file { filePath };
|
||||||
|
|
||||||
if (file.open(QIODevice::ReadOnly)) {
|
if (file.open(QIODevice::ReadOnly)) {
|
||||||
if (file.size() < _end) {
|
if (file.size() < end) {
|
||||||
writeError(replyPacketList.get(), AssetServerError::INVALID_BYTE_RANGE);
|
writeError(replyPacketList.get(), AssetServerError::INVALID_BYTE_RANGE);
|
||||||
qCDebug(networking) << "Bad byte range: " << hexHash << " " << _start << ":" << _end;
|
qCDebug(networking) << "Bad byte range: " << hexHash << " " << start << ":" << end;
|
||||||
} else {
|
} else {
|
||||||
auto size = _end - _start;
|
auto size = end - start;
|
||||||
file.seek(_start);
|
file.seek(start);
|
||||||
replyPacketList->writePrimitive(AssetServerError::NO_ERROR);
|
replyPacketList->writePrimitive(AssetServerError::NO_ERROR);
|
||||||
replyPacketList->writePrimitive(size);
|
replyPacketList->writePrimitive(size);
|
||||||
replyPacketList->write(file.read(size));
|
replyPacketList->write(file.read(size));
|
||||||
|
@ -75,7 +75,7 @@ void SendAssetTask::run() {
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
} else {
|
} else {
|
||||||
qCDebug(networking) << "Asset not found: " << _filePath << "(" << hexHash << ")";
|
qCDebug(networking) << "Asset not found: " << filePath << "(" << hexHash << ")";
|
||||||
writeError(replyPacketList.get(), AssetServerError::ASSET_NOT_FOUND);
|
writeError(replyPacketList.get(), AssetServerError::ASSET_NOT_FOUND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,23 +21,16 @@
|
||||||
#include "AssetServer.h"
|
#include "AssetServer.h"
|
||||||
#include "Node.h"
|
#include "Node.h"
|
||||||
|
|
||||||
namespace udt {
|
class NLPacket;
|
||||||
class Packet;
|
|
||||||
}
|
|
||||||
|
|
||||||
class SendAssetTask : public QRunnable {
|
class SendAssetTask : public QRunnable {
|
||||||
public:
|
public:
|
||||||
SendAssetTask(QSharedPointer<udt::Packet> packet, const SharedNodePointer& sendToNode, const QDir& resourcesDir);
|
SendAssetTask(QSharedPointer<NLPacket> packet, const SharedNodePointer& sendToNode, const QDir& resourcesDir);
|
||||||
|
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSharedPointer<udt::Packet> _packet;
|
QSharedPointer<NLPacket> _packet;
|
||||||
MessageID _messageID;
|
|
||||||
QByteArray _assetHash;
|
|
||||||
QString _filePath;
|
|
||||||
DataOffset _start;
|
|
||||||
DataOffset _end;
|
|
||||||
SharedNodePointer _senderNode;
|
SharedNodePointer _senderNode;
|
||||||
QDir _resourcesDir;
|
QDir _resourcesDir;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue