From 1c68d5a4d75ae4eeb7088f6f2d2fdf957f6c6052 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Mon, 26 Feb 2018 16:53:22 +0200 Subject: [PATCH] - Fixed clients using character directories to count the number of disallowed monsters, which made it possible for them to disallow incorrect monsters. - Fixed MonsterEvent checking if the name of the character directory contains the name of the disallowed character directory, which could for example cause them to disallow "someMonsterAlt" if "someMonster" is disallowed. --- .../BarotraumaClient/Source/Networking/GameClient.cs | 7 ++++--- .../BarotraumaShared/Source/Events/MonsterEvent.cs | 9 +++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs b/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs index 3b9816f0a..6ea6cfbad 100644 --- a/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs +++ b/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs @@ -701,15 +701,16 @@ namespace Barotrauma.Networking //monster spawn settings if (monsterEnabled == null) { - List monsterNames1 = Directory.GetDirectories("Content/Characters").ToList(); + List monsterNames1 = GameMain.Config.SelectedContentPackage.GetFilesOfType(ContentType.Character); for (int i = 0; i < monsterNames1.Count; i++) { - monsterNames1[i] = monsterNames1[i].Replace("Content/Characters", "").Replace("/", "").Replace("\\", ""); + monsterNames1[i] = Path.GetFileName(Path.GetDirectoryName(monsterNames1[i])); } + monsterEnabled = new Dictionary(); foreach (string s in monsterNames1) { - monsterEnabled.Add(s, true); + if (!monsterEnabled.ContainsKey(s)) monsterEnabled.Add(s, true); } } diff --git a/Barotrauma/BarotraumaShared/Source/Events/MonsterEvent.cs b/Barotrauma/BarotraumaShared/Source/Events/MonsterEvent.cs index 2fd6a7078..217512107 100644 --- a/Barotrauma/BarotraumaShared/Source/Events/MonsterEvent.cs +++ b/Barotrauma/BarotraumaShared/Source/Events/MonsterEvent.cs @@ -1,6 +1,7 @@ using Microsoft.Xna.Framework; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Xml.Linq; @@ -61,7 +62,8 @@ namespace Barotrauma if (GameMain.NetworkMember != null) { List monsterNames = GameMain.NetworkMember.monsterEnabled.Keys.ToList(); - string tryKey = monsterNames.Find(s => characterFile.ToLower().Contains(s.ToLower())); + string characterName = Path.GetFileName(Path.GetDirectoryName(characterFile)).ToLower(); + string tryKey = monsterNames.Find(s => characterName == s.ToLower()); if (!string.IsNullOrWhiteSpace(tryKey)) { if (!GameMain.NetworkMember.monsterEnabled[tryKey]) disallowed = true; //spawn was disallowed by host @@ -76,7 +78,10 @@ namespace Barotrauma monsters = SpawnMonsters(Rand.Range(minAmount, maxAmount, Rand.RandSync.Server), false); if (GameSettings.VerboseLogging) { - DebugConsole.NewMessage("Initialized MonsterEvent (" + monsters[0]?.SpeciesName + " x" + monsters.Length + ")", Color.White); + if (monsters != null) + { + DebugConsole.NewMessage("Initialized MonsterEvent (" + monsters[0]?.SpeciesName + " x" + monsters.Length + ")", Color.White); + } } }