HaoYueNet/Simple/ClientCore/Manager/UserDataManager.cs

57 lines
1.4 KiB
C#
Raw Normal View History

2023-12-14 18:15:04 +08:00
using AxibugProtobuf;
namespace ClientCore.Manager
{
public class UserDataBase
{
public long UID { get; set; }
public string Account { get; set; }
}
public class MainUserDataBase : UserDataBase
{
public bool IsLoggedIn { get; set; } = false;
}
public class UserDataManager
{
public UserDataManager()
{
//注册重连成功事件,以便后续自动登录
App.networkHelper.OnReConnected += OnReConnected;
}
2023-12-15 13:34:08 +08:00
public MainUserDataBase userdata { get;private set; } = new MainUserDataBase();
public bool IsLoggedIn => userdata.IsLoggedIn;
2023-12-14 18:15:04 +08:00
public void InitMainUserData(string UName)
{
2023-12-15 13:34:08 +08:00
userdata.Account = UName;
userdata.IsLoggedIn = true;
2023-12-14 18:15:04 +08:00
//以及其他数据初始化
//...
}
/// <summary>
/// 登出
/// </summary>
public void LoginOutData()
{
2023-12-15 13:34:08 +08:00
userdata.IsLoggedIn = false;
2023-12-14 18:15:04 +08:00
//以及其他数据清理
//...
}
/// <summary>
/// 当重连成功
/// </summary>
public void OnReConnected()
{
//如果之前已登录,则重新登录
2023-12-15 13:34:08 +08:00
if (userdata.IsLoggedIn)
2023-12-14 18:15:04 +08:00
{
2023-12-15 13:34:08 +08:00
App.login.Login(userdata.Account);
2023-12-14 18:15:04 +08:00
}
}
}
}