Client-side file transfer UI, FileSender has a limit on how many transfers can be active simultaneously (todo: queue transfers?), some extra debug logging & small fixes

This commit is contained in:
Regalis
2017-03-08 22:56:11 +02:00
parent 64e866d771
commit ca402396a0
3 changed files with 95 additions and 9 deletions
@@ -73,13 +73,21 @@ namespace Barotrauma.Networking
private set;
}
public NetConnection Connection
{
get;
private set;
}
public int SequenceChannel;
public FileTransferIn(string filePath, FileTransferType fileType)
public FileTransferIn(NetConnection connection, string filePath, FileTransferType fileType)
{
FilePath = filePath;
FileName = Path.GetFileName(FilePath);
FileType = fileType;
Connection = connection;
WriteStream = new FileStream(FilePath, FileMode.Create, FileAccess.Write, FileShare.None);
TimeStarted = Environment.TickCount;
@@ -95,6 +103,11 @@ namespace Barotrauma.Networking
int passed = Environment.TickCount - TimeStarted;
float psec = passed / 1000.0f;
if (GameSettings.VerboseLogging)
{
DebugConsole.Log("Received "+all.Length+" bytes of the file "+FileName+" ("+Received+"/"+FileSize+" received)");
}
BytesPerSecond = Received / psec;
@@ -176,7 +189,15 @@ namespace Barotrauma.Networking
return;
}
var newTransfer = new FileTransferIn(Path.Combine(downloadFolder, fileName), (FileTransferType)fileType);
if (GameSettings.VerboseLogging)
{
DebugConsole.Log("Received file transfer initiation message: ");
DebugConsole.Log(" File: "+fileName);
DebugConsole.Log(" Size: " + fileSize);
DebugConsole.Log(" Sequence channel: " + inc.SequenceChannel);
}
var newTransfer = new FileTransferIn(inc.SenderConnection, Path.Combine(downloadFolder, fileName), (FileTransferType)fileType);
newTransfer.SequenceChannel = inc.SequenceChannel;
newTransfer.Status = FileTransferStatus.Receiving;
newTransfer.FileSize = fileSize;
@@ -185,7 +206,7 @@ namespace Barotrauma.Networking
break;
case (byte)FileTransferMessageType.Data:
var activeTransfer = activeTransfers.Find(t => t.SequenceChannel == inc.SequenceChannel);
var activeTransfer = activeTransfers.Find(t => t.Connection == inc.SenderConnection && t.SequenceChannel == inc.SequenceChannel);
if (activeTransfer == null)
{
DebugConsole.ThrowError("File transfer error: received data without a transfer initiation message");
@@ -231,6 +252,12 @@ namespace Barotrauma.Networking
}
}
break;
case (byte)FileTransferMessageType.Cancel:
byte sequenceChannel = inc.ReadByte();
var matchingTransfer = activeTransfers.Find(t => t.Connection == inc.SenderConnection && t.SequenceChannel == sequenceChannel);
if (matchingTransfer != null) StopTransfer(matchingTransfer);
break;
}
}