- server asks the clients whether they're ready to start a round, giving some time to load the selected sub before the round starts

- fixed joining clients not being informed about vote status or voting being enabled
This commit is contained in:
Regalis
2016-05-24 19:10:11 +03:00
parent 4f4c59eba3
commit 52f28f98a7
4 changed files with 61 additions and 10 deletions
@@ -487,6 +487,17 @@ namespace Barotrauma.Networking
switch (packetType) switch (packetType)
{ {
case (byte)PacketTypes.CanStartGame:
string subName = inc.ReadString();
string subHash = inc.ReadString();
if (GameMain.NetLobbyScreen.TrySelectSub(subName,subHash))
{
NetOutgoingMessage readyToStartMsg = client.CreateMessage();
readyToStartMsg.Write((byte)PacketTypes.StartGame);
client.SendMessage(readyToStartMsg, NetDeliveryMethod.ReliableUnordered);
}
break;
case (byte)PacketTypes.StartGame: case (byte)PacketTypes.StartGame:
if (Screen.Selected == GameMain.GameScreen) continue; if (Screen.Selected == GameMain.GameScreen) continue;
+44 -6
View File
@@ -474,6 +474,8 @@ namespace Barotrauma.Networking
//send the message to everyone except the client who just logged in //send the message to everyone except the client who just logged in
SendMessage(outmsg, NetDeliveryMethod.ReliableUnordered, inc.SenderConnection); SendMessage(outmsg, NetDeliveryMethod.ReliableUnordered, inc.SenderConnection);
UpdateVoteStatus();
AddChatMessage(sender.name + " has joined the server", ChatMessageType.Server); AddChatMessage(sender.name + " has joined the server", ChatMessageType.Server);
} }
} }
@@ -521,6 +523,9 @@ namespace Barotrauma.Networking
case (byte)PacketTypes.PlayerLeft: case (byte)PacketTypes.PlayerLeft:
DisconnectClient(inc.SenderConnection); DisconnectClient(inc.SenderConnection);
break; break;
case (byte)PacketTypes.StartGame:
dataSender.ReadyToStart = true;
break;
case (byte)PacketTypes.CharacterInfo: case (byte)PacketTypes.CharacterInfo:
ReadCharacterData(inc); ReadCharacterData(inc);
break; break;
@@ -871,17 +876,38 @@ namespace Barotrauma.Networking
{ {
GameMain.NetLobbyScreen.StartButton.Enabled = false; GameMain.NetLobbyScreen.StartButton.Enabled = false;
if (Voting.AllowSubVoting) yield return new WaitForSeconds(1.0f); NetOutgoingMessage msg = server.CreateMessage();
msg.Write((byte)PacketTypes.CanStartGame);
msg.Write(selectedSub.Name);
msg.Write(selectedSub.MD5Hash.Hash);
while (ConnectedClients.Any(c => c.FileStreamSender != null && c.FileStreamSender.FilePath == selectedSub.FilePath)) SendMessage(msg, NetDeliveryMethod.ReliableUnordered);
ConnectedClients.ForEach(c => c.ReadyToStart = false);
float waitForResponseTimer = 5.0f;
while (ConnectedClients.Any(c => !c.ReadyToStart) && waitForResponseTimer > 0.0f)
{ {
waitForResponseTimer -= CoroutineManager.UnscaledDeltaTime;
yield return CoroutineStatus.Running;
}
float fileTransferTimeOut = 60.0f;
while (ConnectedClients.Any(c => c.FileStreamSender != null && c.FileStreamSender.FilePath == selectedSub.FilePath) && fileTransferTimeOut>0.0f)
{
fileTransferTimeOut -= CoroutineManager.UnscaledDeltaTime;
if (GUIMessageBox.MessageBoxes.Peek() == null) if (GUIMessageBox.MessageBoxes.Peek() == null)
{ {
new GUIMessageBox("File transfer in progress", var messageBox = new GUIMessageBox("File transfer in progress",
"The round will be started after the submarine file has been sent to all players.", 400, 400); "The round will be started after the submarine file has been sent to all players.", new string[] {"Cancel transfer"}, 400, 400);
messageBox.Buttons[0].UserData = ConnectedClients.Find(c => c.FileStreamSender != null && c.FileStreamSender.FilePath == selectedSub.FilePath);
messageBox.Buttons[0].OnClicked = (button, obj) =>
{
(button.UserData as Client).CancelTransfer();
return true;
};
} }
yield return new WaitForSeconds(0.1f);
} }
GameMain.ShowLoading(StartGame(selectedSub, selectedMode), false); GameMain.ShowLoading(StartGame(selectedSub, selectedMode), false);
@@ -1782,6 +1808,8 @@ namespace Barotrauma.Networking
public string version; public string version;
public bool inGame; public bool inGame;
public bool ReadyToStart;
private object[] votes; private object[] votes;
public List<JobPrefab> jobPreferences; public List<JobPrefab> jobPreferences;
@@ -1828,5 +1856,15 @@ namespace Barotrauma.Networking
votes[i] = null; votes[i] = null;
} }
} }
public void CancelTransfer()
{
if (FileStreamSender == null) return;
FileStreamSender.CancelTransfer();
FileStreamSender.Dispose();
FileStreamSender = null;
}
} }
} }
@@ -19,7 +19,7 @@ namespace Barotrauma.Networking
RequestNetLobbyUpdate, RequestNetLobbyUpdate,
StartGame, EndGame, StartGame, EndGame, CanStartGame,
NewItem, RemoveItem, NewItem, RemoveItem,
+5 -3
View File
@@ -1027,8 +1027,8 @@ namespace Barotrauma
//already downloading the selected sub file //already downloading the selected sub file
if (GameMain.Client.ActiveFileTransferName == subName+".sub") return false; if (GameMain.Client.ActiveFileTransferName == subName+".sub") return false;
var matchingListSub = subList.children.Find(c => c.UserData != null && (c.UserData as Submarine).Name == subName); var matchingListSub = subList.children.Find(c => c.UserData != null && (c.UserData as Submarine).Name == subName) as GUITextBlock;
if (matchingListSub!=null) if (matchingListSub != null)
{ {
subList.Select(subList.children.IndexOf(matchingListSub), true); subList.Select(subList.children.IndexOf(matchingListSub), true);
} }
@@ -1043,7 +1043,9 @@ namespace Barotrauma
} }
else if (sub.MD5Hash.Hash == null) else if (sub.MD5Hash.Hash == null)
{ {
errorMsg = "Couldn't load submarine ''" + subName + "''. The file may be corrupted. "; errorMsg = "Couldn't load submarine ''" + subName + "''. The file may be corrupted. ";
if (matchingListSub != null) matchingListSub.TextColor = Color.Red;
} }
else else
{ {