fix: Fixes looking up accounts that were renamed. (#2078)

This commit is contained in:
Kamron Batman 2025-01-18 17:11:43 -08:00 committed by GitHub
parent d92b735c18
commit b4b7182ce6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 18 additions and 3 deletions

View file

@ -25,7 +25,7 @@ public class AccountPacketTests : IClassFixture<ServerFixture>
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<ServerFixture>
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();

View file

@ -97,7 +97,7 @@ public interface IGoldAccount
public interface IAccount : ISerializable, IGoldAccount, IComparable<IAccount>
{
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<IAccount>
Mobile this[int index] { get; set; }
void Delete();
bool TrySetUsername(string username);
void SetPassword(string password);
bool CheckPassword(string password);
}

View file

@ -21,7 +21,7 @@ public partial class Account : IAccount, IComparable<Account>
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<Account>
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