From bee570e2e308b5a94e63ef438bfaa554e17feec3 Mon Sep 17 00:00:00 2001 From: Regalis Date: Mon, 8 May 2017 21:30:54 +0300 Subject: [PATCH] - the server log view is not cleared when saving the log (but old messages are removed when going over the max number of lines) - log can be viewed in the server lobby, not just in-game - logging pump, reactor & battery state usage - GUIListBox.MouseRect doesn't return an empty rect anymore -> listboxes without selectable content can be scrolled with the mouse wheel --- Subsurface/Source/GUI/GUIListBox.cs | 2 +- .../Source/Items/Components/Machines/Pump.cs | 25 ++++++-- .../Items/Components/Machines/Reactor.cs | 57 +++++++++++++++++++ .../Items/Components/Power/PowerContainer.cs | 3 + Subsurface/Source/Networking/GameServer.cs | 9 ++- Subsurface/Source/Networking/ServerLog.cs | 28 +++++---- Subsurface/Source/Screens/NetLobbyScreen.cs | 19 ++++++- 7 files changed, 123 insertions(+), 20 deletions(-) diff --git a/Subsurface/Source/GUI/GUIListBox.cs b/Subsurface/Source/GUI/GUIListBox.cs index bf8942282..b0230cb88 100644 --- a/Subsurface/Source/GUI/GUIListBox.cs +++ b/Subsurface/Source/GUI/GUIListBox.cs @@ -271,7 +271,7 @@ namespace Barotrauma { get { - return Rectangle.Empty; + return rect; } } diff --git a/Subsurface/Source/Items/Components/Machines/Pump.cs b/Subsurface/Source/Items/Components/Machines/Pump.cs index bf33443b1..1e1a860a4 100644 --- a/Subsurface/Source/Items/Components/Machines/Pump.cs +++ b/Subsurface/Source/Items/Components/Machines/Pump.cs @@ -77,6 +77,7 @@ namespace Barotrauma.Items.Components if (GameMain.Server != null) { item.CreateServerEvent(this); + GameServer.Log(Character.Controlled + (IsActive ? " turned on " : " turned off ") + item.Name, Color.Orange); } else if (GameMain.Client != null) { @@ -95,6 +96,7 @@ namespace Barotrauma.Items.Components if (GameMain.Server != null) { item.CreateServerEvent(this); + GameServer.Log(Character.Controlled + " set the pumping speed of " + item.Name + " to " + (int)(flowPercentage) + " %", Color.Orange); } else if (GameMain.Client != null) { @@ -113,6 +115,7 @@ namespace Barotrauma.Items.Components if (GameMain.Server != null) { item.CreateServerEvent(this); + GameServer.Log(Character.Controlled + " set the pumping speed of " + item.Name + " to " + (int)(flowPercentage) + " %", Color.Orange); } else if (GameMain.Client != null) { @@ -239,14 +242,24 @@ namespace Barotrauma.Items.Components public void ServerRead(ClientNetObject type, Lidgren.Network.NetBuffer msg, Client c) { - float flowPercentage = msg.ReadRangedInteger(-10, 10) * 10.0f; - bool isActive = msg.ReadBoolean(); + float newFlowPercentage = msg.ReadRangedInteger(-10, 10) * 10.0f; + bool newIsActive = msg.ReadBoolean(); - if (!item.CanClientAccess(c)) return; - - FlowPercentage = flowPercentage; - IsActive = isActive; + if (item.CanClientAccess(c)) + { + if (newFlowPercentage != FlowPercentage) + { + GameServer.Log(c.Character + " set the pumping speed of " + item.Name + " to " + (int)(newFlowPercentage) + " %", Color.Orange); + } + if (newIsActive != IsActive) + { + GameServer.Log(c.Character + (newIsActive ? " turned on " : " turned off ") + item.Name, Color.Orange); + } + FlowPercentage = newFlowPercentage; + IsActive = newIsActive; + } + //notify all clients of the changed state item.CreateServerEvent(this); } diff --git a/Subsurface/Source/Items/Components/Machines/Reactor.cs b/Subsurface/Source/Items/Components/Machines/Reactor.cs index 93d70805f..218d6d3ec 100644 --- a/Subsurface/Source/Items/Components/Machines/Reactor.cs +++ b/Subsurface/Source/Items/Components/Machines/Reactor.cs @@ -55,6 +55,10 @@ namespace Barotrauma.Items.Components private bool unsentChanges; private float sendUpdateTimer; + private Character lastUser; + private float? nextServerLogWriteTime; + private float lastServerLogWriteTime; + [Editable, HasDefaultValue(9500.0f, true)] public float MeltDownTemp { @@ -162,6 +166,11 @@ namespace Barotrauma.Items.Components var button = new GUIButton(new Rectangle(410, 70, 40, 40), "-", "", GuiFrame); button.OnPressed = () => { + lastUser = Character.Controlled; + if (nextServerLogWriteTime == null) + { + nextServerLogWriteTime = Math.Max(lastServerLogWriteTime + 1.0f, (float)Timing.TotalTime); + } unsentChanges = true; ShutDownTemp -= 100.0f; @@ -171,6 +180,11 @@ namespace Barotrauma.Items.Components button = new GUIButton(new Rectangle(460, 70, 40,40), "+", "", GuiFrame); button.OnPressed = () => { + lastUser = Character.Controlled; + if (nextServerLogWriteTime == null) + { + nextServerLogWriteTime = Math.Max(lastServerLogWriteTime + 1.0f, (float)Timing.TotalTime); + } unsentChanges = true; ShutDownTemp += 100.0f; @@ -183,6 +197,11 @@ namespace Barotrauma.Items.Components button = new GUIButton(new Rectangle(210, 290, 40, 40), "+", "", GuiFrame); button.OnPressed = () => { + lastUser = Character.Controlled; + if (nextServerLogWriteTime == null) + { + nextServerLogWriteTime = Math.Max(lastServerLogWriteTime + 1.0f, (float)Timing.TotalTime); + } unsentChanges = true; FissionRate += 1.0f; @@ -192,6 +211,11 @@ namespace Barotrauma.Items.Components button = new GUIButton(new Rectangle(210, 340, 40, 40), "-", "", GuiFrame); button.OnPressed = () => { + lastUser = Character.Controlled; + if (nextServerLogWriteTime == null) + { + nextServerLogWriteTime = Math.Max(lastServerLogWriteTime + 1.0f, (float)Timing.TotalTime); + } unsentChanges = true; FissionRate -= 1.0f; @@ -201,6 +225,11 @@ namespace Barotrauma.Items.Components button = new GUIButton(new Rectangle(500, 290, 40, 40), "+", "", GuiFrame); button.OnPressed = () => { + lastUser = Character.Controlled; + if (nextServerLogWriteTime == null) + { + nextServerLogWriteTime = Math.Max(lastServerLogWriteTime + 1.0f, (float)Timing.TotalTime); + } unsentChanges = true; CoolingRate += 1.0f; @@ -210,6 +239,11 @@ namespace Barotrauma.Items.Components button = new GUIButton(new Rectangle(500, 340, 40, 40), "-", "", GuiFrame); button.OnPressed = () => { + lastUser = Character.Controlled; + if (nextServerLogWriteTime == null) + { + nextServerLogWriteTime = Math.Max(lastServerLogWriteTime + 1.0f, (float)Timing.TotalTime); + } unsentChanges = true; CoolingRate -= 1.0f; @@ -219,6 +253,23 @@ namespace Barotrauma.Items.Components public override void Update(float deltaTime, Camera cam) { + if (GameMain.Server != null && nextServerLogWriteTime != null) + { + if (Timing.TotalTime >= (float)nextServerLogWriteTime) + { + GameServer.Log(lastUser + " adjusted reactor settings: " + + "Temperature: " + (int)temperature + + ", Fission rate: " + (int)fissionRate + + ", Cooling rate: " + (int)coolingRate + + ", Cooling rate: " + coolingRate + + ", Shutdown temp: " + shutDownTemp, + Color.Orange); + + nextServerLogWriteTime = null; + lastServerLogWriteTime = (float)Timing.TotalTime; + } + } + ApplyStatusEffects(ActionType.OnActive, deltaTime, null); fissionRate = Math.Min(fissionRate, AvailableFuel); @@ -572,6 +623,12 @@ namespace Barotrauma.Items.Components CoolingRate = coolingRate; FissionRate = fissionRate; + lastUser = c.Character; + if (nextServerLogWriteTime == null) + { + nextServerLogWriteTime = Math.Max(lastServerLogWriteTime + 1.0f, (float)Timing.TotalTime); + } + //need to create a server event to notify all clients of the changed state unsentChanges = true; } diff --git a/Subsurface/Source/Items/Components/Power/PowerContainer.cs b/Subsurface/Source/Items/Components/Power/PowerContainer.cs index 4c7c848f0..e46c13450 100644 --- a/Subsurface/Source/Items/Components/Power/PowerContainer.cs +++ b/Subsurface/Source/Items/Components/Power/PowerContainer.cs @@ -102,6 +102,7 @@ namespace Barotrauma.Items.Components if (GameMain.Server != null) { item.CreateServerEvent(this); + GameServer.Log(Character.Controlled + " set the recharge speed of " + item.Name + " to " + (int)((rechargeSpeed / maxRechargeSpeed) * 100.0f) + " %", Color.Orange); } else if (GameMain.Client != null) { @@ -120,6 +121,7 @@ namespace Barotrauma.Items.Components if (GameMain.Server != null) { item.CreateServerEvent(this); + GameServer.Log(Character.Controlled + " set the recharge speed of " + item.Name + " to " + (int)((rechargeSpeed / maxRechargeSpeed) * 100.0f) + " %", Color.Orange); } else if (GameMain.Client != null) { @@ -287,6 +289,7 @@ namespace Barotrauma.Items.Components if (item.CanClientAccess(c)) { RechargeSpeed = newRechargeSpeed; + GameServer.Log(c.Character + " set the recharge speed of "+item.Name+" to "+ (int)((rechargeSpeed / maxRechargeSpeed) * 100.0f) + " %", Color.Orange); } item.CreateServerEvent(this); diff --git a/Subsurface/Source/Networking/GameServer.cs b/Subsurface/Source/Networking/GameServer.cs index 8e5d5df8e..7173c2238 100644 --- a/Subsurface/Source/Networking/GameServer.cs +++ b/Subsurface/Source/Networking/GameServer.cs @@ -65,6 +65,11 @@ namespace Barotrauma.Networking get { return entityEventManager; } } + public ServerLog ServerLog + { + get { return log; } + } + public TimeSpan UpdateInterval { get { return updateInterval; } @@ -194,7 +199,7 @@ namespace Barotrauma.Networking GameMain.NetworkMember = null; yield return CoroutineStatus.Success; } - + if (config.EnableUPnP) { server.UPnP.ForwardPort(config.Port, "barotrauma"); @@ -228,7 +233,7 @@ namespace Barotrauma.Networking updateInterval = new TimeSpan(0, 0, 0, 0, 150); - DebugConsole.NewMessage("Server started", Color.Green); + Log("Server started", Color.Cyan); GameMain.NetLobbyScreen.Select(); started = true; diff --git a/Subsurface/Source/Networking/ServerLog.cs b/Subsurface/Source/Networking/ServerLog.cs index 2c0df9748..f37e1c8a6 100644 --- a/Subsurface/Source/Networking/ServerLog.cs +++ b/Subsurface/Source/Networking/ServerLog.cs @@ -20,6 +20,8 @@ namespace Barotrauma.Networking private readonly Queue lines; + private int unsavedLineCount; + public int LinesPerFile { get { return linesPerFile; } @@ -38,7 +40,7 @@ namespace Barotrauma.Networking string logLine = "[" + DateTime.Now.ToLongTimeString() + "] " + line; var newText = new ColoredText(logLine, color == null ? Color.White : (Color)color); - + lines.Enqueue(newText); if (LogFrame != null) @@ -47,11 +49,19 @@ namespace Barotrauma.Networking listBox.UpdateScrollBarSize(); } + + unsavedLineCount++; - if (lines.Count >= LinesPerFile) + if (unsavedLineCount >= LinesPerFile) { Save(); - lines.Clear(); + unsavedLineCount = 0; + } + + while (lines.Count > LinesPerFile) + { + listBox.RemoveChild(listBox.children[0]); + lines.Dequeue(); } } @@ -59,10 +69,10 @@ namespace Barotrauma.Networking { LogFrame = new GUIFrame(new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.Black * 0.5f); - GUIFrame innerFrame = new GUIFrame(new Rectangle(0, 0, 500, 400), null, Alignment.Center, "", LogFrame); + GUIFrame innerFrame = new GUIFrame(new Rectangle(0, 0, 500, 420), null, Alignment.Center, "", LogFrame); innerFrame.Padding = new Vector4(10.0f, 20.0f, 10.0f, 20.0f); - new GUITextBlock(new Rectangle(-200, 0, 100, 15), "Filter", "", Alignment.TopRight, Alignment.TopRight, innerFrame, false, GUI.SmallFont); + new GUITextBlock(new Rectangle(-200, 0, 100, 15), "Filter", "", Alignment.TopRight, Alignment.CenterRight, innerFrame, false, GUI.SmallFont); GUITextBox searchBox = new GUITextBox(new Rectangle(-20, 0, 180, 15), Alignment.TopRight, "", innerFrame); searchBox.Font = GUI.SmallFont; @@ -73,7 +83,7 @@ namespace Barotrauma.Networking clearButton.OnClicked = ClearFilter; clearButton.UserData = searchBox; - listBox = new GUIListBox(new Rectangle(0, 30, 0, 310), "", innerFrame); + listBox = new GUIListBox(new Rectangle(0, 30, 0, 320), "", innerFrame); var currLines = lines.ToList(); @@ -84,9 +94,9 @@ namespace Barotrauma.Networking listBox.UpdateScrollBarSize(); - if (listBox.BarScroll==0.0f || listBox.BarScroll==1.0f) listBox.BarScroll = 1.0f; + if (listBox.BarScroll == 0.0f || listBox.BarScroll == 1.0f) listBox.BarScroll = 1.0f; - GUIButton closeButton = new GUIButton(new Rectangle(0,0,100, 15), "Close", Alignment.BottomRight, "", innerFrame); + GUIButton closeButton = new GUIButton(new Rectangle(-100, 10, 100, 15), "Close", Alignment.BottomRight, "", innerFrame); closeButton.OnClicked = (GUIButton button, object userData) => { LogFrame = null; @@ -173,8 +183,6 @@ namespace Barotrauma.Networking { DebugConsole.ThrowError("Saving the server log to " + filePath + " failed", e); } - - lines.Clear(); } } } diff --git a/Subsurface/Source/Screens/NetLobbyScreen.cs b/Subsurface/Source/Screens/NetLobbyScreen.cs index c6ee7700d..cc42e4321 100644 --- a/Subsurface/Source/Screens/NetLobbyScreen.cs +++ b/Subsurface/Source/Screens/NetLobbyScreen.cs @@ -341,7 +341,22 @@ namespace Barotrauma serverMessage = new GUITextBox(new Rectangle(0, 30, 360, 70), null, null, Alignment.TopLeft, Alignment.TopLeft, "", infoFrame); serverMessage.Wrap = true; serverMessage.OnTextChanged = UpdateServerMessage; - + + var showLogButton = new GUIButton(new Rectangle(0, 0, 100, 20), "Server Log", Alignment.TopRight, "", infoFrame); + showLogButton.UserData = "showlog"; + showLogButton.OnClicked = (GUIButton button, object userData) => + { + if (GameMain.Server.ServerLog.LogFrame == null) + { + GameMain.Server.ServerLog.CreateLogFrame(); + } + else + { + GameMain.Server.ServerLog.LogFrame = null; + GUIComponent.KeyboardDispatcher.Subscriber = null; + } + return true; + }; } public override void Deselect() @@ -383,6 +398,8 @@ namespace Barotrauma infoFrame.RemoveChild(infoFrame.children.Find(c => c.UserData as string == "settingsButton")); infoFrame.RemoveChild(infoFrame.children.Find(c => c.UserData as string == "spectateButton")); + InfoFrame.FindChild("showlog").Visible = GameMain.Server != null; + //playerList.Parent.RemoveChild(playerList.Parent.children.Find(c => c.UserData as string == "banListButton")); if (IsServer && GameMain.Server != null)