From b4b7182ce6c17cf5f7f227c647330daceb118fb8 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Sat, 18 Jan 2025 17:11:43 -0800 Subject: [PATCH] fix: Fixes looking up accounts that were renamed. (#2078) --- .../Packets/Outgoing/AccountPacketTests.cs | 3 ++- Projects/Server/IAccount.cs | 3 ++- Projects/UOContent/Accounting/Account.cs | 15 ++++++++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Projects/Server.Tests/Tests/Network/Packets/Outgoing/AccountPacketTests.cs b/Projects/Server.Tests/Tests/Network/Packets/Outgoing/AccountPacketTests.cs index ed3bfd4e3..a384a2d44 100644 --- a/Projects/Server.Tests/Tests/Network/Packets/Outgoing/AccountPacketTests.cs +++ b/Projects/Server.Tests/Tests/Network/Packets/Outgoing/AccountPacketTests.cs @@ -25,7 +25,7 @@ public class AccountPacketTests : IClassFixture public int CompareTo(IAccount other) => throw new NotImplementedException(); - public string Username { get; set; } + public string Username { get; } public string Email { get; set; } public AccessLevel AccessLevel { get; set; } public int Length { get; } @@ -60,6 +60,7 @@ public class AccountPacketTests : IClassFixture public bool Deleted { get; } public void Delete() => throw new NotImplementedException(); + public bool TrySetUsername(string username) => throw new NotImplementedException(); public void SetPassword(string password) => throw new NotImplementedException(); diff --git a/Projects/Server/IAccount.cs b/Projects/Server/IAccount.cs index 911bb8c0a..57b70baaa 100644 --- a/Projects/Server/IAccount.cs +++ b/Projects/Server/IAccount.cs @@ -97,7 +97,7 @@ public interface IGoldAccount public interface IAccount : ISerializable, IGoldAccount, IComparable { - string Username { get; set; } + string Username { get; } string Email { get; set; } AccessLevel AccessLevel { get; set; } @@ -107,6 +107,7 @@ public interface IAccount : ISerializable, IGoldAccount, IComparable Mobile this[int index] { get; set; } void Delete(); + bool TrySetUsername(string username); void SetPassword(string password); bool CheckPassword(string password); } diff --git a/Projects/UOContent/Accounting/Account.cs b/Projects/UOContent/Accounting/Account.cs index 73519eb04..9e554fd72 100644 --- a/Projects/UOContent/Accounting/Account.cs +++ b/Projects/UOContent/Accounting/Account.cs @@ -21,7 +21,7 @@ public partial class Account : IAccount, IComparable public static readonly TimeSpan EmptyInactiveDuration = TimeSpan.FromDays(30.0); [InternString] - [SerializableField(0)] + [SerializableField(0, setter: "private")] private string _username; [SerializableField(1)] @@ -365,6 +365,19 @@ public partial class Account : IAccount, IComparable public bool Deleted { get; private set; } + public bool TrySetUsername(string username) + { + if (username == _username || Accounts.GetAccount(username) != null) + { + return false; + } + + Accounts.Remove(this); + Username = username; + Accounts.Add(this); + return true; + } + public void SetPassword(string plainPassword) { var phrase = _passwordAlgorithm is PasswordProtectionAlgorithm.SHA1 or PasswordProtectionAlgorithm.SHA2