From f6857ac6350954254995b4093521960520a14f8c Mon Sep 17 00:00:00 2001 From: RaidMax Date: Sun, 18 Aug 2019 11:18:20 -0500 Subject: [PATCH] bugfix for issue #81 (linked accounts being demoted) --- SharedLibraryCore/Commands/NativeCommands.cs | 15 +++++++-------- SharedLibraryCore/Services/ClientService.cs | 10 ++-------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/SharedLibraryCore/Commands/NativeCommands.cs b/SharedLibraryCore/Commands/NativeCommands.cs index 32f04000c..f26531dfa 100644 --- a/SharedLibraryCore/Commands/NativeCommands.cs +++ b/SharedLibraryCore/Commands/NativeCommands.cs @@ -487,7 +487,7 @@ namespace SharedLibraryCore.Commands }) { } - public override Task ExecuteAsync(GameEvent E) + public override async Task ExecuteAsync(GameEvent E) { Permission oldPerm = E.Target.Level; Permission newPerm = Utilities.MatchPermission(E.Data); @@ -495,15 +495,16 @@ namespace SharedLibraryCore.Commands if (E.Target == E.Origin) { E.Origin.Tell(Utilities.CurrentLocalization.LocalizationIndex["COMMANDS_SETLEVEL_SELF"]); - return Task.CompletedTask; + return; } else if (newPerm == Permission.Owner && - !E.Owner.Manager.GetApplicationSettings().Configuration().EnableMultipleOwners) + !E.Owner.Manager.GetApplicationSettings().Configuration().EnableMultipleOwners && + await E.Owner.Manager.GetClientService().GetOwnerCount() > 0) { // only one owner is allowed E.Origin.Tell(Utilities.CurrentLocalization.LocalizationIndex["COMMANDS_SETLEVEL_OWNER"]); - return Task.CompletedTask; + return; } else if (E.Origin.Level < Permission.Owner && @@ -511,7 +512,7 @@ namespace SharedLibraryCore.Commands { // only the owner is allowed to set levels E.Origin.Tell($"{Utilities.CurrentLocalization.LocalizationIndex["COMMANDS_SETLEVEL_STEPPEDDISABLED"]} ^5{E.Target.Name}"); - return Task.CompletedTask; + return; } else if ((E.Origin.Level <= newPerm && @@ -521,7 +522,7 @@ namespace SharedLibraryCore.Commands // can't promote a client to higher than your current perms // or your peer E.Origin.Tell(string.Format(Utilities.CurrentLocalization.LocalizationIndex["COMMANDS_SETLEVEL_LEVELTOOHIGH"], E.Target.Name, (E.Origin.Level - 1).ToString())); - return Task.CompletedTask; + return; } else if (newPerm > Permission.Banned) @@ -556,8 +557,6 @@ namespace SharedLibraryCore.Commands { E.Origin.Tell(Utilities.CurrentLocalization.LocalizationIndex["COMMANDS_SETLEVEL_FAIL"]); } - - return Task.CompletedTask; } } diff --git a/SharedLibraryCore/Services/ClientService.cs b/SharedLibraryCore/Services/ClientService.cs index 8bdaeaaf7..a238f3f8b 100644 --- a/SharedLibraryCore/Services/ClientService.cs +++ b/SharedLibraryCore/Services/ClientService.cs @@ -228,19 +228,13 @@ namespace SharedLibraryCore.Services temporalClient.CurrentServer.Logger.WriteDebug($"Updated {temporalClient.ClientId} to {newPermission}"); #endif + var linkedPermissionSet = new[] { Permission.Banned, Permission.Flagged }; // if their permission level has been changed to level that needs to be updated on all accounts - if ((oldPermission != newPermission) && - (newPermission == Permission.Banned || - newPermission == Permission.Flagged || - newPermission == Permission.User)) + if (linkedPermissionSet.Contains(newPermission) || linkedPermissionSet.Contains(oldPermission)) { - var changeSvc = new ChangeHistoryService(); - //get all clients that have the same linkId var iqMatchingClients = ctx.Clients .Where(_client => _client.AliasLinkId == entity.AliasLinkId); - // make sure we don't select ourselves twice - //.Where(_client => _client.ClientId != temporalClient.ClientId); // this updates the level for all the clients with the same LinkId // only if their new level is flagged or banned