/// <summary>
        /// Receives a file request packet and either starts a file transfer or cancels an existing one.
        /// </summary>
        /// <param name="packet"></param>
        private void ProcessFileTransferRequest(FileRequestPacket packet)
        {
            if (packet.FileRequestType == FileRequestTypeEnum.StartFileRequest)
            {
                string serverFilePath = DirectoryPaths.ContentPackageDirectoryPath + packet.FileName;

                // Safety check - make sure the file exists and it has an appropriate extension.
                if (Path.GetExtension(packet.FileName) != FileExtensionFactory.GetFileExtension(FileTypeEnum.ContentPackage) ||
                    !File.Exists(serverFilePath))
                {
                    return; // EARLY EXIT
                }

                // Build a new client and add them to the list.
                FileTransferProgress client = new FileTransferProgress
                {
                    BytesSent = 0,
                    FilePath = serverFilePath
                };

                FileTransferClients.Add(packet.SenderConnection, client);

                // Send the size of the file back to client so they can track the download's progress.
                StreamingFileDetailsPacket fileDetails = new StreamingFileDetailsPacket
                {
                    FileSize = new FileInfo(serverFilePath).Length
                };

                Agent.SendPacket(fileDetails, packet.SenderConnection, NetDeliveryMethod.ReliableOrdered);
            }
            else if (packet.FileRequestType == FileRequestTypeEnum.CancelFileRequest)
            {
                // Remove a client from the streaming list.
                FileTransferClients.Remove(packet.SenderConnection);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sends a request to stop a file transfer.
        /// </summary>
        private void CancelRequestFileFromServer()
        {
            if (FileStreamStatus == FileStreamerStatusEnum.Downloading)
            {
                FileRequestPacket packet = new FileRequestPacket
                {
                    FileRequestType = FileRequestTypeEnum.CancelFileRequest
                };
                FileStreamStatus = FileStreamerStatusEnum.Stopped;

                WinterEngineService.NetworkClient.SendPacket(packet, NetDeliveryMethod.ReliableSequenced);

                // Remove partially downloaded file, if it exists.
                string filePath = DirectoryPaths.ContentPackageDirectoryPath + LastReceivedFile;
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }

                FileSize = 0;
                LastReceivedFile = "";
                MissingFiles.Clear();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Sends a request to start initiating a specific file's data transfer
        /// </summary>
        /// <param name="fileName"></param>
        private void RequestFileFromServer(string fileName)
        {
            FileStreamStatus = FileStreamerStatusEnum.Downloading;

            FileRequestPacket packet = new FileRequestPacket
            {
                FileRequestType = FileRequestTypeEnum.StartFileRequest,
                FileName = fileName
            };

            WinterEngineService.NetworkClient.SendPacket(packet, NetDeliveryMethod.ReliableSequenced);
        }