登录和输入控件
This commit is contained in:
54
Assets/Scripts/UI/Login/LoginHelper.cs
Normal file
54
Assets/Scripts/UI/Login/LoginHelper.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using Assets.Scripts.Entity;
|
||||
using Assets.Scripts.Hotfix;
|
||||
using NBC;
|
||||
using NBC.Network;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public static class LoginHelper
|
||||
{
|
||||
private static Session _session;
|
||||
|
||||
public static async FTask Login(string account)
|
||||
{
|
||||
_session = Net.CreateSession("127.0.0.1:20001");
|
||||
|
||||
var acc = account;
|
||||
|
||||
// 发送登录的请求给服务器
|
||||
var response = (A2C_LoginResponse)await Net.Call(new C2A_LoginRequest()
|
||||
{
|
||||
Username = acc,
|
||||
Password = acc,
|
||||
LoginType = 1
|
||||
});
|
||||
|
||||
if (response.ErrorCode != 0)
|
||||
{
|
||||
Log.Error($"登录发生错误{response.ErrorCode}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!App.Main.GetComponent<JWTParseComponent>().Parse(response.ToKen, out var payload))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 根据ToKen返回的Address登录到Gate服务器
|
||||
_session = Net.CreateSession(payload.Address);
|
||||
|
||||
// 发送登录请求到Gate服务器
|
||||
var loginResponse = (G2C_LoginResponse)await Net.Call(new C2G_LoginRequest()
|
||||
{
|
||||
ToKen = response.ToKen
|
||||
});
|
||||
if (loginResponse.ErrorCode != 0)
|
||||
{
|
||||
Log.Error($"登录发生错误{loginResponse.ErrorCode}");
|
||||
return;
|
||||
}
|
||||
|
||||
Log.Debug($"登录到Gate服务器成功!ErrorCode:{loginResponse.ErrorCode}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user