From 3106efa02347af851875927e66c0497926d080bf Mon Sep 17 00:00:00 2001 From: itchyOwl Date: Tue, 27 Mar 2018 11:24:11 +0300 Subject: [PATCH 1/3] Add "respawn" tag to the items that should persist in the Respawn Shuttle. Ignore the items with this tag when resetting the shuttle. (Issue #234) --- .../Source/Networking/RespawnManager.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Barotrauma/BarotraumaShared/Source/Networking/RespawnManager.cs b/Barotrauma/BarotraumaShared/Source/Networking/RespawnManager.cs index c575f8f4a..78a334ae3 100644 --- a/Barotrauma/BarotraumaShared/Source/Networking/RespawnManager.cs +++ b/Barotrauma/BarotraumaShared/Source/Networking/RespawnManager.cs @@ -10,6 +10,9 @@ namespace Barotrauma.Networking { class RespawnManager : Entity, IServerSerializable { + // TODO: Instead of hard-coding the tags in the code, maybe they should be defined in a config file? + private static string respawnItemTag = "respawn"; + private readonly float respawnInterval; private float maxTransportTime; @@ -364,6 +367,8 @@ namespace Barotrauma.Networking foreach (Item item in Item.ItemList) { if (item.Submarine != respawnShuttle) continue; + // Ignore the respawn items, defined in RespawnCharacters method. + if (item.HasTag(respawnItemTag)) continue; if (item.body != null && item.body.Enabled && item.ParentInventory == null) { @@ -502,20 +507,26 @@ namespace Barotrauma.Networking Vector2 pos = cargoSp == null ? character.Position : cargoSp.Position; + // Temp list to hold all respawn items. + // TODO: Instead of tags, wouldn't it be better to keep a local reference to the list that we create and simple filter out the items on it, before clearing the items in ResetShuttle method? + var respawnItems = new List(); if (divingSuitPrefab != null && oxyPrefab != null) { var divingSuit = new Item(divingSuitPrefab, pos, respawnSub); Spawner.CreateNetworkEvent(divingSuit, false); + respawnItems.Add(divingSuit); var oxyTank = new Item(oxyPrefab, pos, respawnSub); Spawner.CreateNetworkEvent(oxyTank, false); - divingSuit.Combine(oxyTank); - + divingSuit.Combine(oxyTank); + respawnItems.Add(oxyTank); + if (batteryPrefab != null) { var battery = new Item(batteryPrefab, pos, respawnSub); Spawner.CreateNetworkEvent(battery, false); divingSuit.Combine(battery); + respawnItems.Add(battery); } } @@ -528,7 +539,10 @@ namespace Barotrauma.Networking Spawner.CreateNetworkEvent(battery, false); scooter.Combine(battery); + respawnItems.Add(scooter); + respawnItems.Add(battery); } + respawnItems.ForEach(item => item.AddTag(respawnItemTag)); //give the character the items they would've gotten if they had spawned in the main sub character.GiveJobItems(mainSubSpawnPoints[i]); From a48a4975cac91e68deb4336c857e2dc3c5174dfe Mon Sep 17 00:00:00 2001 From: itchyOwl Date: Tue, 27 Mar 2018 11:27:13 +0300 Subject: [PATCH 2/3] Auto ban users that have been vote kicked. Define the auto ban time in the server settings. (Issue #128) NOTE: Not tested! --- .../BarotraumaShared/Source/Networking/GameServer.cs | 1 + .../Source/Networking/GameServerSettings.cs | 8 ++++++++ Barotrauma/BarotraumaShared/serversettings.xml | 1 + 3 files changed, 10 insertions(+) diff --git a/Barotrauma/BarotraumaShared/Source/Networking/GameServer.cs b/Barotrauma/BarotraumaShared/Source/Networking/GameServer.cs index 72a4eca3b..9c58d60a9 100644 --- a/Barotrauma/BarotraumaShared/Source/Networking/GameServer.cs +++ b/Barotrauma/BarotraumaShared/Source/Networking/GameServer.cs @@ -1934,6 +1934,7 @@ namespace Barotrauma.Networking { SendChatMessage(c.Name + " has been kicked from the server.", ChatMessageType.Server, null); KickClient(c, "Kicked by vote"); + BanClient(c, "Kicked by vote (auto ban)", duration: TimeSpan.FromSeconds(AutoBanTime)); } GameMain.NetLobbyScreen.LastUpdateID++; diff --git a/Barotrauma/BarotraumaShared/Source/Networking/GameServerSettings.cs b/Barotrauma/BarotraumaShared/Source/Networking/GameServerSettings.cs index 27403577f..b7160c07d 100644 --- a/Barotrauma/BarotraumaShared/Source/Networking/GameServerSettings.cs +++ b/Barotrauma/BarotraumaShared/Source/Networking/GameServerSettings.cs @@ -254,6 +254,12 @@ namespace Barotrauma.Networking set; } + [Serialize(60f, true)] + public float AutoBanTime + { + get; + private set; + } private void SaveSettings() { XDocument doc = new XDocument(new XElement("serversettings")); @@ -361,6 +367,8 @@ namespace Barotrauma.Networking if (!monsterEnabled.ContainsKey(s)) monsterEnabled.Add(s, true); } extraCargo = new Dictionary(); + + AutoBanTime = doc.Root.GetAttributeFloat("autobantime", 60); } public void LoadClientPermissions() diff --git a/Barotrauma/BarotraumaShared/serversettings.xml b/Barotrauma/BarotraumaShared/serversettings.xml index c1e3e950c..0cce423d4 100644 --- a/Barotrauma/BarotraumaShared/serversettings.xml +++ b/Barotrauma/BarotraumaShared/serversettings.xml @@ -29,4 +29,5 @@ GameMode="SandBox" MissionType="Random" TraitorsEnabled="No" + autobantime="60" /> From b59920629457ac2340fc8ed1b2e9bc57e7d9a010 Mon Sep 17 00:00:00 2001 From: itchyOwl Date: Tue, 27 Mar 2018 11:29:36 +0300 Subject: [PATCH 3/3] Add a GUI slider for setting the auto ban duration. Define the max auto ban length in the server settings. (Issue #128) --- .../Source/Networking/GameServerSettings.cs | 17 +++++++++++++++++ .../Source/Networking/GameServerSettings.cs | 9 +++++++++ Barotrauma/BarotraumaShared/serversettings.xml | 1 + 3 files changed, 27 insertions(+) diff --git a/Barotrauma/BarotraumaClient/Source/Networking/GameServerSettings.cs b/Barotrauma/BarotraumaClient/Source/Networking/GameServerSettings.cs index 033538684..1cde5daf4 100644 --- a/Barotrauma/BarotraumaClient/Source/Networking/GameServerSettings.cs +++ b/Barotrauma/BarotraumaClient/Source/Networking/GameServerSettings.cs @@ -350,6 +350,23 @@ namespace Barotrauma.Networking }; kickVoteSlider.OnMoved(kickVoteSlider, kickVoteSlider.BarScroll); + y += 20; + + var autobanTimeText = new GUITextBlock(new Rectangle(20, y + 20, 20, 20), $"Auto ban time: " + ToolBox.SecondsToReadableTime(AutoBanTime), "", settingsTabs[1], GUI.SmallFont); + + var autobanTimeSlider = new GUIScrollBar(new Rectangle(150, y + 22, 100, 15), "", 0.1f, settingsTabs[1]); + autobanTimeSlider.UserData = autobanTimeText; + autobanTimeSlider.Step = 0.05f; + autobanTimeSlider.BarScroll = AutoBanTime / MaxAutoBanTime; + autobanTimeSlider.OnMoved = (GUIScrollBar scrollBar, float barScroll) => + { + GUITextBlock voteText = scrollBar.UserData as GUITextBlock; + AutoBanTime = Math.Max(barScroll * MaxAutoBanTime, 0); + voteText.Text = "Auto ban time: " + ToolBox.SecondsToReadableTime(AutoBanTime); + return true; + }; + autobanTimeSlider.OnMoved(autobanTimeSlider, autobanTimeSlider.BarScroll); + y += 45; var shareSubsBox = new GUITickBox(new Rectangle(0, y, 20, 20), "Share submarine files with players", Alignment.Left, settingsTabs[1]); diff --git a/Barotrauma/BarotraumaShared/Source/Networking/GameServerSettings.cs b/Barotrauma/BarotraumaShared/Source/Networking/GameServerSettings.cs index b7160c07d..a148dde48 100644 --- a/Barotrauma/BarotraumaShared/Source/Networking/GameServerSettings.cs +++ b/Barotrauma/BarotraumaShared/Source/Networking/GameServerSettings.cs @@ -260,6 +260,14 @@ namespace Barotrauma.Networking get; private set; } + + [Serialize(360f, true)] + public float MaxAutoBanTime + { + get; + private set; + } + private void SaveSettings() { XDocument doc = new XDocument(new XElement("serversettings")); @@ -369,6 +377,7 @@ namespace Barotrauma.Networking extraCargo = new Dictionary(); AutoBanTime = doc.Root.GetAttributeFloat("autobantime", 60); + MaxAutoBanTime = doc.Root.GetAttributeFloat("maxautobantime", 360); } public void LoadClientPermissions() diff --git a/Barotrauma/BarotraumaShared/serversettings.xml b/Barotrauma/BarotraumaShared/serversettings.xml index 0cce423d4..c42cf2a7b 100644 --- a/Barotrauma/BarotraumaShared/serversettings.xml +++ b/Barotrauma/BarotraumaShared/serversettings.xml @@ -30,4 +30,5 @@ MissionType="Random" TraitorsEnabled="No" autobantime="60" + maxautobantime="360" />