public void HandleConfirmXferPacket(Message m) { var req = (ConfirmXferPacket)m; DownloadTransferData tdata; if (m_DownloadTransfersByXferID.TryGetValue(req.ID, out tdata)) { if (tdata.Packet != req.Packet || tdata.Position == 0) { return; } var res = new SendXferPacket { Packet = ++tdata.Packet }; int remaininglength = tdata.Data.Length - tdata.Position; if (remaininglength > 1400) { res.Data = new byte[1400]; Buffer.BlockCopy(tdata.Data, tdata.Position, res.Data, 0, 1400); tdata.Position += 1400; } else { res.Data = new byte[remaininglength]; Buffer.BlockCopy(tdata.Data, tdata.Position, res.Data, 0, remaininglength); m_DownloadTransfersByXferID.Remove(req.ID); m_DownloadTransfersByName.Remove(tdata.Filename); res.Packet |= 0x80000000; } res.ID = tdata.XferID; SendMessageAlways(res, req.CircuitSceneID); } }
public void HandleRequestXfer(Message m) { var req = (RequestXfer)m; DownloadTransferData tdata; if (m_DownloadTransfersByName.TryGetValue(req.Filename, out tdata)) { if (tdata.Position != 0) { return; } var res = new SendXferPacket(); tdata.XferID = req.ID; if (tdata.Data.Length > 1400) { res.Data = new byte[1400 + 4]; Buffer.BlockCopy(tdata.Data, 0, res.Data, 4, 1400); tdata.Position += 1400; m_DownloadTransfersByXferID.Add(tdata.XferID, tdata); res.Packet = 0; } else { res.Data = new byte[tdata.Data.Length + 4]; Buffer.BlockCopy(tdata.Data, 0, res.Data, 4, tdata.Data.Length); m_DownloadTransfersByName.Remove(req.Filename); tdata.Position += res.Data.Length; res.Packet = 0x80000000; } res.Data[0] = (byte)(tdata.Data.Length & 0xFF); res.Data[1] = (byte)((tdata.Data.Length >> 8) & 0xFF); res.Data[2] = (byte)((tdata.Data.Length >> 16) & 0xFF); res.Data[3] = (byte)((tdata.Data.Length >> 24) & 0xFF); res.ID = tdata.XferID; SendMessageAlways(res, req.CircuitSceneID); } }