fix: Reverts GetAccount to use IAccount. Adds IAccount to serialization. (#1565)
### Summary - Fixes usernames not being `Intern`ed - Reverts methods related to getting accounts from returning `Account` to `IAccount`. - Makes `IAccount` also `ISerializable` - Adds `IGenericReader.ReadAccount()` and `IGenericWriter.Write(IAccount)` -> The read method supports the original serialization of username, and using `IAccount.Serial`. The write method only serializes the `Serial`. - Exposes `ReadStringRaw()` to allow some advanced scenarios.
This commit is contained in:
parent
a4e2226a5c
commit
e6d30fef0f
9 changed files with 201 additions and 19 deletions
|
|
@ -7,9 +7,30 @@ namespace Server.Accounting
|
|||
{
|
||||
public partial class Account
|
||||
{
|
||||
// Username was not interned
|
||||
private void MigrateFrom(V4Content content)
|
||||
{
|
||||
_username = content.Username;
|
||||
_passwordAlgorithm = content.PasswordAlgorithm;
|
||||
_password = content.Password;
|
||||
_accessLevel = content.AccessLevel;
|
||||
_flags = content.Flags;
|
||||
_lastLogin = content.LastLogin;
|
||||
_totalGold = content.TotalGold;
|
||||
_totalPlat = content.TotalPlat;
|
||||
_mobiles = content.Mobiles;
|
||||
_comments = content.Comments;
|
||||
_tags = content.Tags;
|
||||
_loginIPs = content.LoginIPs;
|
||||
_ipRestrictions = content.IpRestrictions;
|
||||
_totalGameTime = content.TotalGameTime;
|
||||
_email = content.Email;
|
||||
}
|
||||
|
||||
private void MigrateFrom(V3Content content)
|
||||
{
|
||||
_username = content.Username;
|
||||
_username.Intern();
|
||||
_passwordAlgorithm = content.PasswordAlgorithm;
|
||||
_password = content.Password;
|
||||
_accessLevel = content.AccessLevel;
|
||||
|
|
@ -35,7 +56,7 @@ namespace Server.Accounting
|
|||
reader.Seek(0, SeekOrigin.Begin);
|
||||
}
|
||||
|
||||
_username = reader.ReadString();
|
||||
_username = reader.ReadString(true);
|
||||
_passwordAlgorithm = version < 2 ? (PasswordProtectionAlgorithm)reader.ReadInt() : reader.ReadEnum<PasswordProtectionAlgorithm>();
|
||||
_password = reader.ReadString();
|
||||
_accessLevel = version < 2 ? (AccessLevel)reader.ReadInt() : reader.ReadEnum<AccessLevel>();
|
||||
|
|
|
|||
|
|
@ -12,13 +12,14 @@ using Server.Network;
|
|||
|
||||
namespace Server.Accounting
|
||||
{
|
||||
[SerializationGenerator(4)]
|
||||
public partial class Account : IAccount, IComparable<Account>, ISerializable
|
||||
[SerializationGenerator(5)]
|
||||
public partial class Account : IAccount, IComparable<Account>
|
||||
{
|
||||
public static readonly TimeSpan YoungDuration = TimeSpan.FromHours(40.0);
|
||||
public static readonly TimeSpan InactiveDuration = TimeSpan.FromDays(180.0);
|
||||
public static readonly TimeSpan EmptyInactiveDuration = TimeSpan.FromDays(30.0);
|
||||
|
||||
[InternString]
|
||||
[SerializableField(0)]
|
||||
private string _username;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@ using Server.Logging;
|
|||
|
||||
namespace Server.Accounting;
|
||||
|
||||
public class Accounts : GenericEntityPersistence<Account>
|
||||
public class Accounts : GenericEntityPersistence<IAccount>
|
||||
{
|
||||
private static readonly ILogger logger = LogFactory.GetLogger(typeof(Accounts));
|
||||
|
||||
private static readonly Dictionary<string, Account> _accountsByName = new(32, StringComparer.OrdinalIgnoreCase);
|
||||
private static readonly Dictionary<string, IAccount> _accountsByName = new(32, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
public static int Count => _accountsByName.Count;
|
||||
|
||||
|
|
@ -29,7 +29,7 @@ public class Accounts : GenericEntityPersistence<Account>
|
|||
|
||||
public static IEnumerable<IAccount> GetAccounts() => _accountsByName.Values;
|
||||
|
||||
public static Account GetAccount(string username)
|
||||
public static IAccount GetAccount(string username)
|
||||
{
|
||||
_accountsByName.TryGetValue(username, out var a);
|
||||
return a;
|
||||
|
|
@ -41,7 +41,7 @@ public class Accounts : GenericEntityPersistence<Account>
|
|||
_accountsPersistence.AddEntity(a);
|
||||
}
|
||||
|
||||
public static void Remove(Account a)
|
||||
public static void Remove(IAccount a)
|
||||
{
|
||||
_accountsByName.Remove(a.Username);
|
||||
_accountsPersistence.RemoveEntity(a);
|
||||
|
|
@ -91,5 +91,5 @@ public class Accounts : GenericEntityPersistence<Account>
|
|||
}
|
||||
}
|
||||
|
||||
public static IAccount FindAccount(Serial serial) => _accountsPersistence.FindEntity<Account>(serial);
|
||||
public static IAccount FindAccount(Serial serial) => _accountsPersistence.FindEntity<IAccount>(serial);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue