Having multiple sub files with the same name doesn't prevent clients from selecting or requesting the correct one
This commit is contained in:
@@ -94,9 +94,9 @@ namespace Barotrauma
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
private string GetShortHash(string fullHash)
|
||||
{
|
||||
return fullHash;
|
||||
public static string GetShortHash(string fullHash)
|
||||
{
|
||||
return fullHash.Length < 7 ? fullHash : fullHash.Substring(0, 7);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,7 +271,8 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
case (byte)FileTransferType.Submarine:
|
||||
string fileName = inc.ReadString();
|
||||
var requestedSubmarine = Submarine.SavedSubmarines.Find(s => s.Name == fileName);
|
||||
string fileHash = inc.ReadString();
|
||||
var requestedSubmarine = Submarine.SavedSubmarines.Find(s => s.Name == fileName && s.MD5Hash.Hash == fileHash);
|
||||
|
||||
if (requestedSubmarine != null)
|
||||
{
|
||||
|
||||
@@ -740,7 +740,7 @@ namespace Barotrauma.Networking
|
||||
string subName = inc.ReadString();
|
||||
string subHash = inc.ReadString();
|
||||
|
||||
var matchingSub = Submarine.SavedSubmarines.Find(s => s.Name == subName);
|
||||
var matchingSub = Submarine.SavedSubmarines.Find(s => s.Name == subName && s.MD5Hash.Hash == subHash);
|
||||
if (matchingSub != null)
|
||||
{
|
||||
submarines.Add(matchingSub);
|
||||
@@ -987,13 +987,14 @@ namespace Barotrauma.Networking
|
||||
chatMsgQueue.Add(chatMessage);
|
||||
}
|
||||
|
||||
public void RequestFile(string file, FileTransferType fileType)
|
||||
public void RequestFile(FileTransferType fileType, string file, string fileHash)
|
||||
{
|
||||
NetOutgoingMessage msg = client.CreateMessage();
|
||||
msg.Write((byte)ClientPacketHeader.FILE_REQUEST);
|
||||
msg.Write((byte)FileTransferMessageType.Initiate);
|
||||
msg.Write((byte)fileType);
|
||||
msg.Write(file);
|
||||
msg.Write(fileHash);
|
||||
client.SendMessage(msg, NetDeliveryMethod.ReliableUnordered);
|
||||
}
|
||||
|
||||
@@ -1012,17 +1013,23 @@ namespace Barotrauma.Networking
|
||||
switch (transfer.FileType)
|
||||
{
|
||||
case FileTransferType.Submarine:
|
||||
Submarine.SavedSubmarines.RemoveAll(s => s.Name + ".sub" == transfer.FileName);
|
||||
var newSub = new Submarine(transfer.FilePath);
|
||||
Submarine.SavedSubmarines.RemoveAll(s => s.Name == newSub.Name && s.MD5Hash.Hash == newSub.MD5Hash.Hash);
|
||||
Submarine.SavedSubmarines.Add(newSub);
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
var textBlock = ((i == 0) ?
|
||||
GameMain.NetLobbyScreen.ShuttleList.ListBox.children.Find(c => (c.UserData as Submarine).Name + ".sub" == transfer.FileName) :
|
||||
GameMain.NetLobbyScreen.SubList.children.Find(c => (c.UserData as Submarine).Name + ".sub" == transfer.FileName)) as GUITextBlock;
|
||||
List<GUIComponent> subListChildren = (i == 0) ?
|
||||
GameMain.NetLobbyScreen.ShuttleList.ListBox.children :
|
||||
GameMain.NetLobbyScreen.SubList.children;
|
||||
|
||||
var textBlock = subListChildren.Find(c =>
|
||||
((Submarine)c.UserData).Name == newSub.Name &&
|
||||
((Submarine)c.UserData).MD5Hash.Hash == newSub.MD5Hash.Hash) as GUITextBlock;
|
||||
|
||||
if (textBlock == null) continue;
|
||||
textBlock.TextColor = Color.White;
|
||||
var newSub = new Submarine(transfer.FilePath);
|
||||
Submarine.SavedSubmarines.Add(newSub);
|
||||
|
||||
textBlock.UserData = newSub;
|
||||
textBlock.ToolTip = newSub.Description;
|
||||
}
|
||||
|
||||
@@ -716,7 +716,9 @@ namespace Barotrauma
|
||||
};
|
||||
|
||||
|
||||
var matchingSub = Submarine.SavedSubmarines.Find(s => s.Name == sub.Name);
|
||||
var matchingSub = Submarine.SavedSubmarines.Find(s => s.Name == sub.Name && s.MD5Hash.Hash == sub.MD5Hash.Hash);
|
||||
if (matchingSub == null) matchingSub = Submarine.SavedSubmarines.Find(s => s.Name == sub.Name);
|
||||
|
||||
if (matchingSub == null)
|
||||
{
|
||||
subTextBlock.TextColor = Color.Gray;
|
||||
@@ -1213,7 +1215,10 @@ namespace Barotrauma
|
||||
return false;
|
||||
}
|
||||
|
||||
var matchingListSub = subList.children.Find(c => c.UserData != null && (c.UserData as Submarine).Name == subName) as GUITextBlock;
|
||||
Submarine sub = Submarine.SavedSubmarines.Find(m => m.Name == subName && m.MD5Hash.Hash == md5Hash);
|
||||
if (sub == null) sub = Submarine.SavedSubmarines.Find(m => m.Name == subName);
|
||||
|
||||
var matchingListSub = subList.children.Find(c => c.UserData == sub) as GUITextBlock;
|
||||
if (matchingListSub != null)
|
||||
{
|
||||
subList.OnSelected -= VotableClicked;
|
||||
@@ -1221,7 +1226,6 @@ namespace Barotrauma
|
||||
subList.OnSelected += VotableClicked;
|
||||
}
|
||||
|
||||
Submarine sub = Submarine.SavedSubmarines.Find(m => m.Name == subName);
|
||||
if (sub == null || sub.MD5Hash.Hash != md5Hash)
|
||||
{
|
||||
string errorMsg = "";
|
||||
@@ -1237,9 +1241,9 @@ namespace Barotrauma
|
||||
}
|
||||
else
|
||||
{
|
||||
errorMsg = "Your version of the submarine file \"" + sub.Name + "\" doesn't match the server's version! "
|
||||
+ "Your MD5 hash: " + sub.MD5Hash.Hash + " \n"
|
||||
+ "Server's MD5 hash: " + md5Hash + ". ";
|
||||
errorMsg = "Your version of the submarine file \"" + sub.Name + "\" doesn't match the server's version!\n"
|
||||
+ "Your MD5 hash: " + sub.MD5Hash.ShortHash + "\n"
|
||||
+ "Server's MD5 hash: " + Md5Hash.GetShortHash(md5Hash) + "\n";
|
||||
}
|
||||
|
||||
errorMsg += "Do you want to download the file from the server host?";
|
||||
@@ -1252,11 +1256,12 @@ namespace Barotrauma
|
||||
|
||||
var requestFileBox = new GUIMessageBox("Submarine not found!", errorMsg, new string[] { "Yes", "No" }, 400, 300);
|
||||
requestFileBox.UserData = "request" + subName;
|
||||
requestFileBox.Buttons[0].UserData = subName;
|
||||
requestFileBox.Buttons[0].UserData = new string[] { subName, md5Hash };
|
||||
requestFileBox.Buttons[0].OnClicked += requestFileBox.Close;
|
||||
requestFileBox.Buttons[0].OnClicked += (GUIButton button, object userdata) =>
|
||||
{
|
||||
GameMain.Client.RequestFile(userdata.ToString(), FileTransferType.Submarine);
|
||||
string[] fileInfo = (string[])userdata;
|
||||
GameMain.Client.RequestFile(FileTransferType.Submarine, fileInfo[0], fileInfo[1]);
|
||||
return true;
|
||||
};
|
||||
requestFileBox.Buttons[1].OnClicked += requestFileBox.Close;
|
||||
|
||||
Reference in New Issue
Block a user