public void XferReceive(IClientAPI remoteClient, ulong xferID, uint packetID, byte[] data) { bool isComplete = false; if (XferID == xferID) { if ((packetID & PACKETID_COMPLETE) != 0) { isComplete = true; packetID &= ~PACKETID_COMPLETE; } if (packetID == 0) { // First (special) header packet with length. int headerLen = sizeof(uint); // 'size' field below m_assetSize = Utils.BytesToInt(data); m_xferPacketSize = data.Length - headerLen; // We must use any existing buffer, in case we didn't get the first packet first. if ((m_asset.Data == null) || (m_asset.Data.Length < m_assetSize)) { m_asset.Data = new byte[m_assetSize]; } Array.Copy(data, headerLen, m_asset.Data, 0, data.Length - headerLen); } else { // normal header, we already know how big it should be (m_xferPacketSize==1000). if (m_asset.Data == null) { m_asset.Data = new byte[0]; // just in case we get the second packet first... } int offset = (int)packetID * m_xferPacketSize; // destination for new data block int datalen = data.Length; // additional data block size if (datalen > m_xferPacketSize) { // new data packet won't fit based on m_xferPacketSize datalen = m_xferPacketSize; } int newbuflen = offset + datalen; // required size when inserting new block int oldbuflen = m_asset.Data.Length; // existing data size if (newbuflen > oldbuflen) { // grow buffer byte[] destinationArray = new byte[newbuflen]; Array.Copy(m_asset.Data, 0, destinationArray, 0, oldbuflen); m_asset.Data = destinationArray; } // insert data at the correct offset Array.Copy(data, 0, m_asset.Data, offset, datalen); } remoteClient.SendConfirmXfer(xferID, packetID); if (isComplete) { SendCompleteMessage(remoteClient); } } }
/// <summary> /// Process transfer data received from the client. /// </summary> /// <param name="xferID"></param> /// <param name="packetID"></param> /// <param name="data"></param> /// <returns>True if the transfer is complete, false otherwise or if the xferID was not valid</returns> public bool HandleXferPacket(ulong xferID, uint packetID, byte[] data) { if (XferID == xferID) { if (m_asset.Data.Length > 1) { byte[] destinationArray = new byte[m_asset.Data.Length + data.Length]; Array.Copy(m_asset.Data, 0, destinationArray, 0, m_asset.Data.Length); Array.Copy(data, 0, destinationArray, m_asset.Data.Length, data.Length); m_asset.Data = destinationArray; } else { byte[] buffer2 = new byte[data.Length - 4]; Array.Copy(data, 4, buffer2, 0, data.Length - 4); m_asset.Data = buffer2; } ourClient.SendConfirmXfer(xferID, packetID); if ((packetID & 0x80000000) != 0) { SendCompleteMessage(); return(true); } } return(false); }
/// <summary> /// Process transfer data received from the client. /// </summary> /// <param name = "xferID"></param> /// <param name = "packetID"></param> /// <param name = "data"></param> /// <returns>True if the transfer is complete, false otherwise or if the xferID was not valid</returns> public bool HandleXferPacket(IClientAPI remoteClient, ulong xferID, uint packetID, byte[] data) { if (XferID == xferID) { if (m_asset.Data.Length > 1) { byte[] destinationArray = new byte[m_asset.Data.Length + data.Length]; Array.Copy(m_asset.Data, 0, destinationArray, 0, m_asset.Data.Length); Array.Copy(data, 0, destinationArray, m_asset.Data.Length, data.Length); m_asset.Data = destinationArray; } else { byte[] buffer2 = new byte[data.Length - 4]; Array.Copy(data, 4, buffer2, 0, data.Length - 4); m_asset.Data = buffer2; } remoteClient.SendConfirmXfer(xferID, packetID); if ((packetID & 0x80000000) != 0) { SendCompleteMessage(remoteClient); return true; } } return false; }
/// <summary> /// Process transfer data received from the client. /// </summary> /// <param name="remoteClient"></param> /// <param name="xferID"></param> /// <param name="packetID"></param> /// <param name="data"></param> public void XferReceive(IClientAPI remoteClient, ulong xferID, uint packetID, byte[] data) { if (mXferID == xferID) { lock (_lock) { if (m_asset.Data.Length > 1) { byte[] destinationArray = new byte[m_asset.Data.Length + data.Length]; Array.Copy(m_asset.Data, 0, destinationArray, 0, m_asset.Data.Length); Array.Copy(data, 0, destinationArray, m_asset.Data.Length, data.Length); m_asset.Data = destinationArray; } else { byte[] buffer2 = new byte[data.Length - 4]; Array.Copy(data, 4, buffer2, 0, data.Length - 4); m_asset.Data = buffer2; } remoteClient.SendConfirmXfer(xferID, packetID); if ((packetID & 0x80000000) != 0) { SendCompleteMessage(remoteClient); } } } }
/// <summary> /// Process transfer data received from the client. /// </summary> /// <param name="xferID"></param> /// <param name="packetID"></param> /// <param name="data"></param> /// <returns>True if the transfer is complete, false otherwise or if the xferID was not valid</returns> public bool HandleXferPacket(ulong xferID, uint packetID, byte[] data) { // m_log.DebugFormat( // "[ASSET XFER UPLOADER]: Received packet {0} for xfer {1} (data length {2})", // packetID, xferID, data.Length); if (XferID == xferID) { if (m_asset.Data.Length > 1) { byte[] destinationArray = new byte[m_asset.Data.Length + data.Length]; Array.Copy(m_asset.Data, 0, destinationArray, 0, m_asset.Data.Length); Array.Copy(data, 0, destinationArray, m_asset.Data.Length, data.Length); m_asset.Data = destinationArray; } else { byte[] buffer2 = new byte[data.Length - 4]; Array.Copy(data, 4, buffer2, 0, data.Length - 4); m_asset.Data = buffer2; } ourClient.SendConfirmXfer(xferID, packetID); if ((packetID & 0x80000000) != 0) { SendCompleteMessage(); return(true); } } return(false); }
public bool HandleXferPacket(ulong xferID, uint packetID, byte[] data) { bool isComplete = false; if (XferID == xferID) { m_lastAccess = DateTime.Now; if ((packetID & PACKETID_COMPLETE) != 0) { isComplete = true; packetID &= ~PACKETID_COMPLETE; } if (packetID == 0) { // First (special) header packet with length. int headerLen = sizeof(uint); // 'size' field below m_assetSize = Utils.BytesToInt(data); m_xferPacketSize = data.Length - headerLen; // We must use any existing buffer, in case we didn't get the first packet first. if ((m_asset.Data == null) || (m_asset.Data.Length < m_xferPacketSize)) { m_asset.Data = new byte[m_xferPacketSize]; } Array.Copy(data, headerLen, m_asset.Data, 0, data.Length - headerLen); m_log.DebugFormat("[XFER]: xferID={0} packetID={1:X4} buffer={2} +{3}@0)", xferID, packetID, m_asset.Data.Length, m_xferPacketSize); } else { // normal header, we already know how big it should be (m_xferPacketSize==1000). if (m_asset.Data == null) { m_asset.Data = new byte[0]; // just in case we get the second packet first... } int offset = (int)packetID * m_xferPacketSize; // destination for new data block m_log.DebugFormat("[XFER]: xferID={0} packetID={1:X4} buffer={2} +{3}@{4}", xferID, packetID, m_asset.Data.Length, data.Length, offset); int datalen = data.Length; // additional data block size if (datalen > m_xferPacketSize) { // new data packet won't fit based on m_xferPacketSize m_log.ErrorFormat("[XFER]: Expected {0}-byte data packet, received {1} bytes of data.", m_xferPacketSize, datalen); datalen = m_xferPacketSize; } int newbuflen = offset + datalen; // required size when inserting new block int oldbuflen = m_asset.Data.Length; // existing data size if (newbuflen > oldbuflen) { // grow buffer byte[] destinationArray = new byte[newbuflen]; Array.Copy(m_asset.Data, 0, destinationArray, 0, oldbuflen); m_asset.Data = destinationArray; } // insert data at the correct offset Array.Copy(data, 0, m_asset.Data, offset, datalen); } ourClient.SendConfirmXfer(xferID, packetID); if (isComplete) { m_log.DebugFormat("[XFER]: xferID={0} packetID={1:X4} buffer={2} asset={3} (COMPLETE)", xferID, packetID, m_asset.Data.Length, m_assetSize); SendCompleteMessage(); } } return(isComplete); }
public void XferReceive(IClientAPI remoteClient, ulong xferID, uint packetID, byte[] data) { bool isComplete = false; if (XferID == xferID) { if ((packetID & PACKETID_COMPLETE) != 0) { isComplete = true; packetID &= ~PACKETID_COMPLETE; } if (packetID == 0) { // First (special) header packet with length. int headerLen = sizeof(uint); // 'size' field below m_assetSize = Utils.BytesToInt(data); m_xferPacketSize = data.Length - headerLen; // We must use any existing buffer, in case we didn't get the first packet first. if ((m_asset.Data == null) || (m_asset.Data.Length < m_assetSize)) m_asset.Data = new byte[m_assetSize]; Array.Copy(data, headerLen, m_asset.Data, 0, data.Length - headerLen); } else { // normal header, we already know how big it should be (m_xferPacketSize==1000). if (m_asset.Data == null) m_asset.Data = new byte[0]; // just in case we get the second packet first... int offset = (int)packetID * m_xferPacketSize; // destination for new data block int datalen = data.Length; // additional data block size if (datalen > m_xferPacketSize) { // new data packet won't fit based on m_xferPacketSize datalen = m_xferPacketSize; } int newbuflen = offset + datalen; // required size when inserting new block int oldbuflen = m_asset.Data.Length; // existing data size if (newbuflen > oldbuflen) { // grow buffer byte[] destinationArray = new byte[newbuflen]; Array.Copy(m_asset.Data, 0, destinationArray, 0, oldbuflen); m_asset.Data = destinationArray; } // insert data at the correct offset Array.Copy(data, 0, m_asset.Data, offset, datalen); } remoteClient.SendConfirmXfer(xferID, packetID); if (isComplete) { SendCompleteMessage(remoteClient); } } }