Clients send the latest received campaign ID to the server when in the lobby instead of requesting it once with a reliable message. -> Now the server reattempts sending the save file if the transfer fails at either end.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Lidgren.Network;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@@ -84,14 +85,17 @@ namespace Barotrauma.Networking
|
||||
FileName = Path.GetFileName(FilePath);
|
||||
FileType = fileType;
|
||||
|
||||
Connection = connection;
|
||||
|
||||
WriteStream = new FileStream(FilePath, FileMode.Create, FileAccess.Write, FileShare.None);
|
||||
TimeStarted = Environment.TickCount;
|
||||
Connection = connection;
|
||||
|
||||
Status = FileTransferStatus.NotStarted;
|
||||
}
|
||||
|
||||
public void OpenStream()
|
||||
{
|
||||
WriteStream = new FileStream(FilePath, FileMode.Create, FileAccess.Write, FileShare.None);
|
||||
TimeStarted = Environment.TickCount;
|
||||
}
|
||||
|
||||
public void ReadBytes(NetIncomingMessage inc)
|
||||
{
|
||||
byte[] all = inc.ReadBytes(inc.LengthBytes - inc.PositionInBytes);
|
||||
@@ -100,17 +104,17 @@ 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)");
|
||||
DebugConsole.Log("Received " + all.Length + " bytes of the file " + FileName + " (" + Received + "/" + FileSize + " received)");
|
||||
}
|
||||
|
||||
BytesPerSecond = Received / psec;
|
||||
|
||||
Status = Received >= FileSize ? FileTransferStatus.Finished : FileTransferStatus.Receiving;
|
||||
}
|
||||
|
||||
|
||||
private bool disposed = false;
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
@@ -137,8 +141,9 @@ namespace Barotrauma.Networking
|
||||
|
||||
const int MaxFileSize = 1000000;
|
||||
|
||||
public delegate void OnFinishedDelegate(FileTransferIn fileStreamReceiver);
|
||||
public OnFinishedDelegate OnFinished;
|
||||
public delegate void TransferInDelegate(FileTransferIn fileStreamReceiver);
|
||||
public TransferInDelegate OnFinished;
|
||||
public TransferInDelegate OnTransferFailed;
|
||||
|
||||
private List<FileTransferIn> activeTransfers;
|
||||
|
||||
@@ -223,11 +228,25 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
}
|
||||
|
||||
var newTransfer = new FileTransferIn(inc.SenderConnection, Path.Combine(downloadFolder, fileName), (FileTransferType)fileType);
|
||||
FileTransferIn newTransfer = new FileTransferIn(inc.SenderConnection, Path.Combine(downloadFolder, fileName), (FileTransferType)fileType);
|
||||
newTransfer.SequenceChannel = inc.SequenceChannel;
|
||||
newTransfer.Status = FileTransferStatus.Receiving;
|
||||
newTransfer.FileSize = fileSize;
|
||||
|
||||
try
|
||||
{
|
||||
newTransfer.OpenStream();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
GameMain.Client.CancelFileTransfer(inc.SequenceChannel);
|
||||
DebugConsole.NewMessage("Failed to initiate a file transfer {" + e.Message + "}", Color.Red);
|
||||
|
||||
newTransfer.Status = FileTransferStatus.Error;
|
||||
OnTransferFailed(newTransfer);
|
||||
return;
|
||||
}
|
||||
|
||||
activeTransfers.Add(newTransfer);
|
||||
|
||||
break;
|
||||
@@ -240,7 +259,7 @@ namespace Barotrauma.Networking
|
||||
return;
|
||||
}
|
||||
|
||||
if (activeTransfer.Received + (ulong)(inc.LengthBytes-inc.PositionInBytes) > activeTransfer.FileSize)
|
||||
if (activeTransfer.Received + (ulong)(inc.LengthBytes - inc.PositionInBytes) > activeTransfer.FileSize)
|
||||
{
|
||||
GameMain.Client.CancelFileTransfer(inc.SequenceChannel);
|
||||
DebugConsole.ThrowError("File transfer error: Received more data than expected");
|
||||
@@ -256,7 +275,7 @@ namespace Barotrauma.Networking
|
||||
catch (Exception e)
|
||||
{
|
||||
GameMain.Client.CancelFileTransfer(inc.SequenceChannel);
|
||||
DebugConsole.ThrowError("File transfer error: "+e.Message);
|
||||
DebugConsole.ThrowError("File transfer error: " + e.Message);
|
||||
activeTransfer.Status = FileTransferStatus.Error;
|
||||
StopTransfer(activeTransfer, true);
|
||||
return;
|
||||
|
||||
@@ -990,7 +990,15 @@ namespace Barotrauma.Networking
|
||||
outmsg.Write(ChatMessage.LastID);
|
||||
|
||||
var campaign = GameMain.GameSession?.GameMode as MultiplayerCampaign;
|
||||
outmsg.Write(campaign == null ? 0 : campaign.LastUpdateID);
|
||||
if (campaign == null || campaign.LastSaveID == 0)
|
||||
{
|
||||
outmsg.Write((UInt16)0);
|
||||
}
|
||||
else
|
||||
{
|
||||
outmsg.Write(campaign.LastSaveID);
|
||||
outmsg.Write(campaign.LastUpdateID);
|
||||
}
|
||||
|
||||
chatMsgQueue.RemoveAll(cMsg => !NetIdUtils.IdMoreRecent(cMsg.NetStateID, lastSentChatMsgID));
|
||||
for (int i = 0; i < chatMsgQueue.Count && i < ChatMessage.MaxMessagesPerPacket; i++)
|
||||
@@ -1090,10 +1098,10 @@ namespace Barotrauma.Networking
|
||||
|
||||
private void OnFileReceived(FileReceiver.FileTransferIn transfer)
|
||||
{
|
||||
new GUIMessageBox("Download finished", "File \"" + transfer.FileName + "\" was downloaded succesfully.");
|
||||
switch (transfer.FileType)
|
||||
{
|
||||
case FileTransferType.Submarine:
|
||||
new GUIMessageBox("Download finished", "File \"" + transfer.FileName + "\" was downloaded succesfully.");
|
||||
var newSub = new Submarine(transfer.FilePath);
|
||||
Submarine.SavedSubmarines.RemoveAll(s => s.Name == newSub.Name && s.MD5Hash.Hash == newSub.MD5Hash.Hash);
|
||||
Submarine.SavedSubmarines.Add(newSub);
|
||||
|
||||
Reference in New Issue
Block a user