fix(core): Fixes accounts and moves it to codegen (#644)

- [X] Fixes TimeSpan not working with codegen
- [X] Fixes bad check for generic classes with a serialize method and deserialize ctor
- [X] Moves Accounts to codegen so it is versioned
- [X] Fixes deserialization of old Accounts with no version variable.
- [X] Fixes deserialize seek not doing anything. 🙈 
- [X] Adds Email to serialization
This commit is contained in:
Kamron Batman 2021-06-05 19:39:16 -07:00 • committed by GitHub
parent ac4d349caa
commit 75db56edc4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 378 additions and 464 deletions

File diff suppressed because it is too large Load diff

View file

@ -64,23 +64,6 @@ namespace Server.Accounting
/// </summary>
public DateTime LastModified { get; private set; }
/// <summary>
/// Serializes this AccountComment instance to an XmlTextWriter.
/// </summary>
/// <param name="xml">The XmlTextWriter instance from which to serialize.</param>
public void Save(XmlTextWriter xml)
{
xml.WriteStartElement("comment");
xml.WriteAttributeString("addedBy", AddedBy);
xml.WriteAttributeString("lastModified", XmlConvert.ToString(LastModified, XmlDateTimeSerializationMode.Utc));
xml.WriteString(m_Content);
xml.WriteEndElement();
}
/// <summary>
/// Serializes this AccountComment instance.
/// </summary>

View file

@ -45,18 +45,6 @@ namespace Server.Accounting
/// </summary>
public string Value { get; set; }
/// <summary>
/// Serializes this AccountTag instance to an XmlTextWriter.
/// </summary>
/// <param name="xml">The XmlTextWriter instance from which to serialize.</param>
public void Save(XmlTextWriter xml)
{
xml.WriteStartElement("tag");
xml.WriteAttributeString("name", Name);
xml.WriteString(Value);
xml.WriteEndElement();
}
/// <summary>
/// Serializes this AccountTag instance to an XmlTextWriter.
/// </summary>

View file

@ -10,8 +10,8 @@ namespace Server.Accounting
{
private static readonly ILogger logger = LogFactory.GetLogger(typeof(Accounts));
private static readonly Dictionary<string, IAccount> _accountsByName = new(32, StringComparer.OrdinalIgnoreCase);
private static Dictionary<Serial, IAccount> _accountsById = new(32);
private static readonly Dictionary<string, Account> _accountsByName = new(32, StringComparer.OrdinalIgnoreCase);
private static Dictionary<Serial, Account> _accountsById = new(32);
private static Serial _lastAccount;
internal static List<Type> Types { get; } = new();
@ -44,7 +44,7 @@ namespace Server.Accounting
Persistence.Register("Accounts", Serialize, WriteSnapshot, Deserialize);
internal static void Serialize() =>
EntityPersistence.SaveEntities(_accountsById.Values, account => account.Serialize());
EntityPersistence.SaveEntities(_accountsById.Values, account => ((ISerializable)account).Serialize());
internal static void WriteSnapshot(string basePath)
{
@ -54,19 +54,19 @@ namespace Server.Accounting
public static IEnumerable<IAccount> GetAccounts() => _accountsByName.Values;
public static IAccount GetAccount(string username)
public static Account GetAccount(string username)
{
_accountsByName.TryGetValue(username, out var a);
return a;
}
public static void Add(IAccount a)
public static void Add(Account a)
{
_accountsByName[a.Username] = a;
_accountsById[a.Serial] = a;
}
public static void Remove(IAccount a)
public static void Remove(Account a)
{
_accountsByName.Remove(a.Username);
_accountsById.Remove(a.Serial);
@ -85,7 +85,7 @@ namespace Server.Accounting
IIndexInfo<Serial> indexInfo = new EntityTypeIndex("Accounts");
_accountsById = EntityPersistence.LoadIndex(path, indexInfo, out List<EntityIndex<IAccount>> accounts);
_accountsById = EntityPersistence.LoadIndex(path, indexInfo, out List<EntityIndex<Account>> accounts);
EntityPersistence.LoadData(path, indexInfo, accounts);
foreach (var a in _accountsById.Values)

View file

@ -1056,7 +1056,7 @@ namespace Server.Gumps
if (m_List == null)
{
ipRestrictions = a.IPRestrictions.ToList();
ipRestrictions = a.IpRestrictions.ToList();
m_List = ipRestrictions.ToList<object>();
}
else
@ -3000,7 +3000,7 @@ namespace Server.Gumps
}
else
{
var list = a.IPRestrictions;
var list = a.IpRestrictions;
var contains = false;
for (var i = 0; !contains && i < list.Length; ++i)
@ -3023,7 +3023,7 @@ namespace Server.Gumps
newList[list.Length] = ip;
a.IPRestrictions = newList;
a.IpRestrictions = newList;
notice = $"{ip} : Added to restriction list.";
}
@ -3888,9 +3888,9 @@ namespace Server.Gumps
}
else if (m_PageType == AdminGumpPage.AccountDetails_Access_Restrictions)
{
var list = a.IPRestrictions.ToList();
var list = a.IpRestrictions.ToList();
list.Remove(m_List[index] as string);
a.IPRestrictions = list.ToArray();
a.IpRestrictions = list.ToArray();
from.SendGump(
new AdminGump(

View file

@ -0,0 +1,108 @@
{
"version": 2,
"type": "Server.Accounting.Account",
"properties": [
{
"name": "Username",
"type": "string",
"rule": "PrimitiveTypeMigrationRule",
"ruleArguments": []
},
{
"name": "PasswordAlgorithm",
"type": "Server.Accounting.Security.PasswordProtectionAlgorithm",
"rule": "EnumMigrationRule",
"ruleArguments": []
},
{
"name": "Password",
"type": "string",
"rule": "PrimitiveTypeMigrationRule",
"ruleArguments": []
},
{
"name": "AccessLevel",
"type": "Server.AccessLevel",
"rule": "EnumMigrationRule",
"ruleArguments": []
},
{
"name": "Flags",
"type": "int",
"rule": "PrimitiveTypeMigrationRule",
"ruleArguments": []
},
{
"name": "Created",
"type": "System.DateTime",
"rule": "PrimitiveTypeMigrationRule",
"ruleArguments": []
},
{
"name": "LastLogin",
"type": "System.DateTime",
"rule": "PrimitiveTypeMigrationRule",
"ruleArguments": []
},
{
"name": "TotalGold",
"type": "int",
"rule": "PrimitiveTypeMigrationRule",
"ruleArguments": []
},
{
"name": "TotalPlat",
"type": "int",
"rule": "PrimitiveTypeMigrationRule",
"ruleArguments": []
},
{
"name": "Mobiles",
"type": "Server.Mobile[]",
"rule": "ArrayMigrationRule",
"ruleArguments": [
"Server.Mobile",
"SerializableInterfaceMigrationRule"
]
},
{
"name": "Comments",
"type": "System.Collections.Generic.List\u003CServer.Accounting.AccountComment\u003E",
"rule": "ListMigrationRule",
"ruleArguments": [
"Server.Accounting.AccountComment",
"SerializationMethodSignatureMigrationRule"
]
},
{
"name": "LoginIPs",
"type": "System.Net.IPAddress[]",
"rule": "ArrayMigrationRule",
"ruleArguments": [
"System.Net.IPAddress",
"PrimitiveTypeMigrationRule"
]
},
{
"name": "IpRestrictions",
"type": "string[]",
"rule": "ArrayMigrationRule",
"ruleArguments": [
"string",
"PrimitiveTypeMigrationRule"
]
},
{
"name": "TotalGameTime",
"type": "System.TimeSpan",
"rule": "PrimitiveTypeMigrationRule",
"ruleArguments": []
},
{
"name": "Email",
"type": "string",
"rule": "PrimitiveTypeMigrationRule",
"ruleArguments": []
}
]
}