From 626df3f861e8fe2c67e2c514688d9caa17e70832 Mon Sep 17 00:00:00 2001 From: Stanley Dimant Date: Fri, 19 Jul 2024 02:45:06 +0200 Subject: [PATCH] throw errors for multiple character with same name + world set up in config --- .../ServerConfigurationManager.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/MareSynchronos/Services/ServerConfiguration/ServerConfigurationManager.cs b/MareSynchronos/Services/ServerConfiguration/ServerConfigurationManager.cs index 64dba72..2058bce 100644 --- a/MareSynchronos/Services/ServerConfiguration/ServerConfigurationManager.cs +++ b/MareSynchronos/Services/ServerConfiguration/ServerConfigurationManager.cs @@ -78,10 +78,16 @@ public class ServerConfigurationManager Save(); } - var auth = currentServer.Authentications.Find(f => string.Equals(f.CharacterName, charaName, StringComparison.Ordinal) && f.WorldId == worldId); - if (auth == null) return null; + var auth = currentServer.Authentications.FindAll(f => string.Equals(f.CharacterName, charaName, StringComparison.Ordinal) && f.WorldId == worldId); + if (auth.Count >= 2) + { + _mareMediator.Publish(new NotificationMessage("Multiple Identical Characters detected", "Your Service configuration has multiple characters with the same name and world set up. Please delete the duplicates.", + NotificationType.Error)); + return null; + } + if (auth.Count == 0) return null; - if (currentServer.SecretKeys.TryGetValue(auth.SecretKeyIdx, out var secretKey)) + if (currentServer.SecretKeys.TryGetValue(auth.Single().SecretKeyIdx, out var secretKey)) { return secretKey.Key; }