NoSugarNet/NoSugarNet.ClientCore.Standard2/Manager/AppLogin.cs

47 lines
1.5 KiB
C#
Raw Normal View History

2024-04-15 15:16:10 +08:00
using AxibugProtobuf;
2024-10-18 16:47:32 +08:00
using NoSugarNet.ClientCore.Common;
using NoSugarNet.ClientCore.Network;
using System;
2024-04-15 15:16:10 +08:00
2024-10-18 16:47:32 +08:00
namespace NoSugarNet.ClientCore.Manager
2024-04-15 15:16:10 +08:00
{
public class AppLogin
{
2024-10-18 16:47:32 +08:00
static string LastLoginGuid = "";
2024-04-15 15:16:10 +08:00
public AppLogin()
{
NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdLogin, RecvLoginMsg);
}
2024-10-18 16:47:32 +08:00
public void Login()
2024-04-15 15:16:10 +08:00
{
2024-10-18 16:47:32 +08:00
AppNoSugarNet.log.Debug("-->Login");
if(string.IsNullOrEmpty(LastLoginGuid))
LastLoginGuid = Guid.NewGuid().ToString();
AppNoSugarNet.user.userdata.Account = LastLoginGuid;
2024-04-15 15:16:10 +08:00
Protobuf_Login msg = new Protobuf_Login()
{
LoginType = 0,
2024-10-18 16:47:32 +08:00
Account = AppNoSugarNet.user.userdata.Account,
2024-04-15 15:16:10 +08:00
};
AppNoSugarNet.networkHelper.SendToServer((int)CommandID.CmdLogin, ProtoBufHelper.Serizlize(msg));
}
public void RecvLoginMsg(byte[] reqData)
{
Protobuf_Login_RESP msg = ProtoBufHelper.DeSerizlize<Protobuf_Login_RESP>(reqData);
if (msg.Status == LoginResultStatus.Ok)
{
AppNoSugarNet.log.Info("登录成功");
2024-10-18 16:47:32 +08:00
AppNoSugarNet.user.InitMainUserData(AppNoSugarNet.user.userdata.Account,msg.UID);
AppNoSugarNet.reverselocal.Send_ClientCfg();
2024-04-15 15:16:10 +08:00
}
else
{
AppNoSugarNet.log.Info("登录失败");
}
}
}
}