- clients see the submarines that the host has instead of their own subs in server lobby
- possible to vote for subs the client doesn't have - fixed the "votes required" slider moving when re-opening the server settings - WIP method for sending missing subs to clients before the round starts (atm the clients won't have time to request a sub file that was chosen by voting)
This commit is contained in:
@@ -29,6 +29,12 @@ namespace Barotrauma.Networking
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public string FilePath
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public ulong FileSize
|
||||
{
|
||||
@@ -190,7 +196,9 @@ namespace Barotrauma.Networking
|
||||
return;
|
||||
}
|
||||
|
||||
writeStream = new FileStream(Path.Combine(downloadFolder, FileName), FileMode.Create, FileAccess.Write, FileShare.None);
|
||||
FilePath = Path.Combine(downloadFolder, FileName);
|
||||
|
||||
writeStream = new FileStream(FilePath, FileMode.Create, FileAccess.Write, FileShare.None);
|
||||
timeStarted = Environment.TickCount;
|
||||
|
||||
Status = FileTransferStatus.NotStarted;
|
||||
|
||||
@@ -257,8 +257,8 @@ namespace Barotrauma.Networking
|
||||
GameMain.NetLobbyScreen.ClearPlayers();
|
||||
|
||||
//add the names of other connected clients to the lobby screen
|
||||
int existingClients = inc.ReadInt32();
|
||||
for (int i = 1; i <= existingClients; i++)
|
||||
int clientCount = inc.ReadByte();
|
||||
for (int i = 0; i < clientCount; i++)
|
||||
{
|
||||
Client otherClient = new Client(inc.ReadString(), inc.ReadByte());
|
||||
|
||||
@@ -266,6 +266,17 @@ namespace Barotrauma.Networking
|
||||
otherClients.Add(otherClient);
|
||||
}
|
||||
|
||||
List<Submarine> submarines = new List<Submarine>();
|
||||
int subCount = inc.ReadByte();
|
||||
for (int i = 0; i < subCount; i++ )
|
||||
{
|
||||
string subName = inc.ReadString();
|
||||
string subHash = inc.ReadString();
|
||||
|
||||
submarines.Add(new Submarine(Path.Combine(Submarine.SavePath, subName), subHash, false));
|
||||
}
|
||||
GameMain.NetLobbyScreen.UpdateSubList(submarines);
|
||||
|
||||
//add the name of own client to the lobby screen
|
||||
GameMain.NetLobbyScreen.AddPlayer(name);
|
||||
|
||||
@@ -342,7 +353,10 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
if (Screen.Selected != GameMain.GameScreen)
|
||||
{
|
||||
List<Submarine> subList = GameMain.NetLobbyScreen.GetSubList();
|
||||
|
||||
GameMain.NetLobbyScreen = new NetLobbyScreen();
|
||||
GameMain.NetLobbyScreen.UpdateSubList(subList);
|
||||
GameMain.NetLobbyScreen.Select();
|
||||
}
|
||||
connected = true;
|
||||
@@ -819,7 +833,16 @@ namespace Barotrauma.Networking
|
||||
switch (receiver.FileType)
|
||||
{
|
||||
case FileTransferMessageType.Submarine:
|
||||
Submarine.Preload();
|
||||
var textBlock = GameMain.NetLobbyScreen.SubList.children.Find(c => (c.UserData as Submarine).Name+".sub" == receiver.FileName);
|
||||
if (textBlock != null)
|
||||
{
|
||||
Submarine.SavedSubmarines.RemoveAll(s => s.Name + ".sub" == receiver.FileName);
|
||||
|
||||
(textBlock as GUITextBlock).TextColor = Color.White;
|
||||
var newSub = new Submarine(receiver.FilePath);
|
||||
Submarine.SavedSubmarines.Add(newSub);
|
||||
textBlock.UserData = newSub;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,7 +300,7 @@ namespace Barotrauma.Networking
|
||||
else if (autoRestart && Screen.Selected == GameMain.NetLobbyScreen && ConnectedClients.Count>0)
|
||||
{
|
||||
AutoRestartTimer -= deltaTime;
|
||||
if (AutoRestartTimer < 0.0f)
|
||||
if (AutoRestartTimer < 0.0f && GameMain.NetLobbyScreen.StartButton.Enabled)
|
||||
{
|
||||
StartGameClicked(null,null);
|
||||
}
|
||||
@@ -437,11 +437,11 @@ namespace Barotrauma.Networking
|
||||
outmsg.Write((byte)PacketTypes.LoggedIn);
|
||||
outmsg.Write(sender.ID);
|
||||
outmsg.Write(gameStarted);
|
||||
outmsg.Write(gameStarted && sender.Character!=null);
|
||||
outmsg.Write(gameStarted && sender.Character != null);
|
||||
outmsg.Write(allowSpectating);
|
||||
|
||||
//notify the client about other clients already logged in
|
||||
outmsg.Write((characterInfo == null) ? ConnectedClients.Count - 1 : ConnectedClients.Count);
|
||||
outmsg.Write((byte)((characterInfo == null) ? ConnectedClients.Count - 1 : ConnectedClients.Count));
|
||||
foreach (Client c in ConnectedClients)
|
||||
{
|
||||
if (c.Connection == inc.SenderConnection) continue;
|
||||
@@ -455,6 +455,14 @@ namespace Barotrauma.Networking
|
||||
outmsg.Write(-1);
|
||||
}
|
||||
|
||||
var subs = GameMain.NetLobbyScreen.GetSubList();
|
||||
outmsg.Write((byte)subs.Count);
|
||||
foreach (Submarine sub in subs)
|
||||
{
|
||||
outmsg.Write(sub.Name);
|
||||
outmsg.Write(sub.MD5Hash.Hash);
|
||||
}
|
||||
|
||||
server.SendMessage(outmsg, inc.SenderConnection, NetDeliveryMethod.ReliableUnordered, 0);
|
||||
|
||||
//notify other clients about the new client
|
||||
@@ -854,21 +862,37 @@ namespace Barotrauma.Networking
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (ConnectedClients.Any(c => c.FileStreamSender != null && c.FileStreamSender.FilePath == selectedSub.FilePath))
|
||||
{
|
||||
new GUIMessageBox("Couldn't start a round",
|
||||
"Can't start a round while sending the selected submarine to clients. Cancel the transfers or wait for them to finish before starting.", 400, 400);
|
||||
return false;
|
||||
}
|
||||
|
||||
GameMain.ShowLoading(StartGame(selectedSub, selectedMode), false);
|
||||
CoroutineManager.StartCoroutine(WaitForPlayersReady(selectedSub, selectedMode), "WaitForPlayersReady");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private IEnumerable<object> WaitForPlayersReady(Submarine selectedSub, GameModePreset selectedMode)
|
||||
{
|
||||
GameMain.NetLobbyScreen.StartButton.Enabled = false;
|
||||
|
||||
if (Voting.AllowSubVoting) yield return new WaitForSeconds(1.0f);
|
||||
|
||||
while (ConnectedClients.Any(c => c.FileStreamSender != null && c.FileStreamSender.FilePath == selectedSub.FilePath))
|
||||
{
|
||||
if (GUIMessageBox.MessageBoxes.Peek() == null)
|
||||
{
|
||||
new GUIMessageBox("File transfer in progress",
|
||||
"The round will be started after the submarine file has been sent to all players.", 400, 400);
|
||||
}
|
||||
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
}
|
||||
|
||||
GameMain.ShowLoading(StartGame(selectedSub, selectedMode), false);
|
||||
|
||||
yield return CoroutineStatus.Success;
|
||||
}
|
||||
|
||||
private IEnumerable<object> StartGame(Submarine selectedSub, GameModePreset selectedMode)
|
||||
{
|
||||
GameMain.NetLobbyScreen.StartButton.Enabled = false;
|
||||
|
||||
GUIMessageBox.CloseAll();
|
||||
|
||||
AssignJobs();
|
||||
@@ -965,6 +989,7 @@ namespace Barotrauma.Networking
|
||||
AddChatMessage("Press TAB to chat. Use ''r;'' to talk through the radio.", ChatMessageType.Server);
|
||||
}
|
||||
|
||||
GameMain.NetLobbyScreen.StartButton.Enabled = true;
|
||||
|
||||
yield return CoroutineStatus.Success;
|
||||
}
|
||||
|
||||
@@ -146,9 +146,11 @@ namespace Barotrauma.Networking
|
||||
|
||||
subSelectionMode = SelectionMode.Manual;
|
||||
Enum.TryParse<SelectionMode>(ToolBox.GetAttributeString(doc.Root, "SubSelection", "Manual"), out subSelectionMode);
|
||||
Voting.AllowSubVoting = subSelectionMode == SelectionMode.Vote;
|
||||
|
||||
modeSelectionMode = SelectionMode.Manual;
|
||||
Enum.TryParse<SelectionMode>(ToolBox.GetAttributeString(doc.Root, "ModeSelection", "Manual"), out modeSelectionMode);
|
||||
Voting.AllowModeVoting = modeSelectionMode == SelectionMode.Vote;
|
||||
|
||||
FileStreamSender.MaxTransferDuration = new TimeSpan(0,0,ToolBox.GetAttributeInt(doc.Root, "MaxFileTransferDuration", 150));
|
||||
}
|
||||
@@ -184,12 +186,12 @@ namespace Barotrauma.Networking
|
||||
|
||||
var votesRequiredSlider = new GUIScrollBar(new Rectangle(150, y+22, 100, 10), GUI.Style, 0.1f, innerFrame);
|
||||
votesRequiredSlider.UserData = votesRequiredText;
|
||||
votesRequiredSlider.Step = 0.2f;
|
||||
votesRequiredSlider.BarScroll = (EndVoteRequiredRatio - 0.5f) * 2.0f;
|
||||
votesRequiredSlider.OnMoved = (GUIScrollBar scrollBar, float barScroll) =>
|
||||
{
|
||||
GUITextBlock voteText = scrollBar.UserData as GUITextBlock;
|
||||
|
||||
scrollBar.BarScroll = MathUtils.Round(barScroll, 0.2f);
|
||||
EndVoteRequiredRatio = barScroll / 2.0f + 0.5f;
|
||||
voteText.Text = "Votes required: " + (int)MathUtils.Round(EndVoteRequiredRatio * 100.0f, 10.0f) + " %";
|
||||
return true;
|
||||
@@ -197,9 +199,7 @@ namespace Barotrauma.Networking
|
||||
votesRequiredSlider.OnMoved(votesRequiredSlider, votesRequiredSlider.BarScroll);
|
||||
|
||||
y += 40;
|
||||
|
||||
|
||||
|
||||
|
||||
var randomizeLevelBox = new GUITickBox(new Rectangle(0, y, 20, 20), "Randomize level seed between rounds", Alignment.Left, innerFrame);
|
||||
randomizeLevelBox.Selected = randomizeSeed;
|
||||
randomizeLevelBox.OnSelected = (GUITickBox) =>
|
||||
@@ -207,8 +207,7 @@ namespace Barotrauma.Networking
|
||||
randomizeSeed = GUITickBox.Selected;
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
|
||||
y += 40;
|
||||
|
||||
var shareSubsBox = new GUITickBox(new Rectangle(0, y, 20, 20), "Share submarine files with players", Alignment.Left, innerFrame);
|
||||
|
||||
Reference in New Issue
Block a user