diff --git a/Subsurface/Source/Map/Entity.cs b/Subsurface/Source/Map/Entity.cs index ccb0f386c..01abcb297 100644 --- a/Subsurface/Source/Map/Entity.cs +++ b/Subsurface/Source/Map/Entity.cs @@ -2,6 +2,8 @@ using Lidgren.Network; using Microsoft.Xna.Framework; using Barotrauma.Networking; +using System.Linq; +using System; namespace Barotrauma { @@ -128,30 +130,13 @@ namespace Barotrauma public static void DumpIds(int count) { - List e = new List(); + List entities = dictionary.Values.OrderByDescending(e => e.id).ToList(); - foreach (Entity ent in dictionary.Values) + count = Math.Min(entities.Count, count); + + for (int i = 0; i < count; i++) { - int index = 0; - for (int i = 0; i < e.Count; i++) - { - if (e[i].id < ent.id) - { - index = i; - break; - } - } - - e.Insert(index, ent); - } - - int c = 0; - foreach (Entity ent in e) - { - if (c>count) break; - - DebugConsole.ThrowError(ent.id+": "+ent.ToString()); - c++; + DebugConsole.ThrowError(entities[i].id + ": " + entities[i].ToString()); } } } diff --git a/Subsurface/Source/Networking/GameClient.cs b/Subsurface/Source/Networking/GameClient.cs index 919e51063..2356b9461 100644 --- a/Subsurface/Source/Networking/GameClient.cs +++ b/Subsurface/Source/Networking/GameClient.cs @@ -19,6 +19,7 @@ namespace Barotrauma.Networking private ReliableChannel reliableChannel; private FileStreamReceiver fileStreamReceiver; + private Queue> requestFileQueue; private GUITickBox endRoundButton; @@ -63,6 +64,8 @@ namespace Barotrauma.Networking name = newName; + requestFileQueue = new Queue>(); + characterInfo = new CharacterInfo(Character.HumanConfigFile, name); characterInfo.Job = null; @@ -251,7 +254,7 @@ namespace Barotrauma.Networking "A round is already running and the admin has disabled spectating. You will have to wait for a new round to start."); } - if (gameStarted && !hasCharacter && myCharacter!=null) + if (gameStarted && !hasCharacter && myCharacter != null) { GameMain.NetLobbyScreen.Select(); @@ -277,17 +280,19 @@ namespace Barotrauma.Networking string subName = inc.ReadString(); string subHash = inc.ReadString(); - string mySubPath = Path.Combine(Submarine.SavePath, subName); var matchingSub = Submarine.SavedSubmarines.Find(s => s.Name == subName); if (matchingSub != null) { - mySubPath = matchingSub.FilePath; + submarines.Add(matchingSub); } - - submarines.Add(new Submarine(mySubPath, subHash, false)); + else + { + submarines.Add(new Submarine(Path.Combine(Submarine.SavePath, subName), subHash, false)); + } + } - GameMain.NetLobbyScreen.UpdateSubList(GameMain.NetLobbyScreen.SubList, Submarine.SavedSubmarines); - GameMain.NetLobbyScreen.UpdateSubList(GameMain.NetLobbyScreen.ShuttleList.ListBox, Submarine.SavedSubmarines); + GameMain.NetLobbyScreen.UpdateSubList(GameMain.NetLobbyScreen.SubList, submarines); + GameMain.NetLobbyScreen.UpdateSubList(GameMain.NetLobbyScreen.ShuttleList.ListBox, submarines); //add the name of own client to the lobby screen GameMain.NetLobbyScreen.AddPlayer(name); @@ -470,6 +475,12 @@ namespace Barotrauma.Networking NetIncomingMessage inc; if (startGameCoroutine != null && CoroutineManager.IsCoroutineRunning(startGameCoroutine)) return; + + if (fileStreamReceiver == null && requestFileQueue.Count > 0) + { + var newRequest = requestFileQueue.Dequeue(); + RequestFile(newRequest.First, newRequest.Second); + } while ((inc = client.ReadMessage()) != null) { @@ -913,7 +924,14 @@ namespace Barotrauma.Networking { if (fileStreamReceiver!=null) { - CancelFileTransfer(); + var request = new Pair() + { + First = file, + Second = fileType + }; + + requestFileQueue.Enqueue(request); + return; } NetOutgoingMessage msg = client.CreateMessage(); diff --git a/Subsurface/Source/Networking/GameServer.cs b/Subsurface/Source/Networking/GameServer.cs index 53f0d3a7a..9af184d6f 100644 --- a/Subsurface/Source/Networking/GameServer.cs +++ b/Subsurface/Source/Networking/GameServer.cs @@ -100,6 +100,7 @@ namespace Barotrauma.Networking else { log.LogFrame = null; + GUIComponent.KeyboardDispatcher.Subscriber = null; } return true; }; @@ -464,7 +465,7 @@ 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 && !sender.Character.IsDead); outmsg.Write(AllowSpectating); //notify the client about other clients already logged in diff --git a/Subsurface/Source/Networking/RespawnManager.cs b/Subsurface/Source/Networking/RespawnManager.cs index c4fa6be6d..00d6e6062 100644 --- a/Subsurface/Source/Networking/RespawnManager.cs +++ b/Subsurface/Source/Networking/RespawnManager.cs @@ -84,7 +84,10 @@ namespace Barotrauma.Networking if (door != null) shuttleDoors.Add(door); } - shuttleSteering.TargetPosition = ConvertUnits.ToSimUnits(Level.Loaded.StartPosition); + if (shuttleSteering != null) + { + shuttleSteering.TargetPosition = ConvertUnits.ToSimUnits(Level.Loaded.StartPosition); + } var server = networkMember as GameServer; if (server != null) diff --git a/Subsurface/Source/Networking/ServerLog.cs b/Subsurface/Source/Networking/ServerLog.cs index 9dc388a5a..a4b3858a8 100644 --- a/Subsurface/Source/Networking/ServerLog.cs +++ b/Subsurface/Source/Networking/ServerLog.cs @@ -96,11 +96,17 @@ namespace Barotrauma.Networking private void AddLine(ColoredText line) { - var textBlock = new GUITextBlock(new Rectangle(0, 0, 0, 0), line.Text, GUI.Style, Alignment.TopLeft, Alignment.TopLeft, listBox, true, GUI.SmallFont); + float prevSize = listBox.BarSize; + + var textBlock = new GUITextBlock(new Rectangle(0, 0, 0, 0), line.Text, GUI.Style, Alignment.TopLeft, Alignment.TopLeft, null, true, GUI.SmallFont); textBlock.Rect = new Rectangle(textBlock.Rect.X, textBlock.Rect.Y, textBlock.Rect.Width, Math.Max(13, textBlock.Rect.Height)); + listBox.AddChild(textBlock); + textBlock.TextColor = line.Color; textBlock.CanBeFocused = false; + + if ((prevSize == 1.0f && listBox.BarScroll == 0.0f) || (prevSize < 1.0f && listBox.BarScroll == 1.0f)) listBox.BarScroll = 1.0f; } private bool FilterMessages(GUITextBox textBox, string text)