mirror of
https://github.com/EggLinks/DanhengServer-OpenSource.git
synced 2026-01-02 20:26:03 +08:00
fix: the friend system will cause server crash
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Newtonsoft.Json;
|
||||
using EggLink.DanhengServer.Util;
|
||||
using Newtonsoft.Json;
|
||||
using SqlSugar;
|
||||
|
||||
namespace EggLink.DanhengServer.Database;
|
||||
@@ -11,7 +12,8 @@ public class CustomSerializeService : ISerializeService
|
||||
{
|
||||
_jsonSettings = new JsonSerializerSettings
|
||||
{
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore // ignore default values
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore, // ignore default values
|
||||
ObjectCreationHandling = ObjectCreationHandling.Replace
|
||||
};
|
||||
}
|
||||
|
||||
@@ -22,7 +24,25 @@ public class CustomSerializeService : ISerializeService
|
||||
|
||||
public T DeserializeObject<T>(string value)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<T>(value)!;
|
||||
try
|
||||
{
|
||||
var clazz = JsonConvert.DeserializeObject<T>(value)!;
|
||||
return clazz;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// try to create empty instance
|
||||
try
|
||||
{
|
||||
Logger.GetByClassName().Warn("Error occured when load database, resetting the mistake value");
|
||||
var inst = Activator.CreateInstance<T>();
|
||||
return inst;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return default!;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string SugarSerializeObject(object value)
|
||||
|
||||
@@ -7,7 +7,11 @@ public class FriendData : BaseDatabaseDataHelper
|
||||
{
|
||||
|
||||
[SugarColumn(IsJson = true, ColumnDataType = "TEXT")]
|
||||
public Dictionary<int, FriendDetailData> FriendList { get; set; } = [];
|
||||
public Dictionary<int, FriendDetailData> FriendDetailList { get; set; } = [];
|
||||
|
||||
|
||||
[SugarColumn(IsJson = true, ColumnDataType = "TEXT")]
|
||||
public List<FriendDetailData> FriendList { get; set; } = []; // leave for compatibility
|
||||
|
||||
[SugarColumn(IsJson = true)] public List<int> BlackList { get; set; } = [];
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using EggLink.DanhengServer.Data;
|
||||
using System.ComponentModel;
|
||||
using EggLink.DanhengServer.Data;
|
||||
using EggLink.DanhengServer.Database.Avatar;
|
||||
using EggLink.DanhengServer.Database.Quests;
|
||||
using EggLink.DanhengServer.Proto;
|
||||
@@ -27,7 +28,7 @@ public class LineupInfo
|
||||
public int LineupType { get; set; }
|
||||
public int LeaderAvatarId { get; set; }
|
||||
public List<LineupAvatarInfo>? BaseAvatars { get; set; }
|
||||
public int Mp { get; set; } = 5;
|
||||
[DefaultValue(5)] public int Mp { get; set; } = 5;
|
||||
|
||||
[JsonIgnore] public LineupData? LineupData { get; set; }
|
||||
|
||||
|
||||
@@ -44,7 +44,10 @@ public static class ConfigManager
|
||||
using (var reader = new StreamReader(stream))
|
||||
{
|
||||
var json = reader.ReadToEnd();
|
||||
Config = JsonConvert.DeserializeObject<ConfigContainer>(json)!;
|
||||
Config = JsonConvert.DeserializeObject<ConfigContainer>(json, new JsonSerializerSettings
|
||||
{
|
||||
ObjectCreationHandling = ObjectCreationHandling.Replace
|
||||
})!;
|
||||
}
|
||||
|
||||
SaveData(Config, ConfigFilePath);
|
||||
|
||||
Reference in New Issue
Block a user