放放风
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Assets.Scripts.Entity;
|
||||
using Assets.Scripts.Hotfix;
|
||||
using FairyGUI;
|
||||
using NBC;
|
||||
using NBC.Network;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Audio;
|
||||
using UnityEngine.Video;
|
||||
@@ -135,6 +138,78 @@ namespace NBF
|
||||
// Fishing.Inst.Go(1);
|
||||
// SettingPanel.Show();
|
||||
// HomePanel.Show();
|
||||
|
||||
//测试登录
|
||||
OnLoginButtonClick().Coroutine();
|
||||
}
|
||||
|
||||
|
||||
#region 登录测试
|
||||
|
||||
private Session _session;
|
||||
|
||||
private async FTask OnLoginButtonClick()
|
||||
{
|
||||
// 根据用户名来选择目标的鉴权服务器
|
||||
// 根据鉴权服务器地址来创建一个新的网络会话
|
||||
_session = SessionHelper.CreateSession(App.Main, "127.0.0.1:20001", OnConnectComplete,
|
||||
OnConnectFail,
|
||||
OnConnectDisconnect);
|
||||
// 发送登录的请求给服务器
|
||||
var response = (A2C_LoginResponse)await _session.Call(new C2A_LoginRequest()
|
||||
{
|
||||
Username = "test001",
|
||||
Password = "test001",
|
||||
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 = SessionHelper.CreateSession(App.Main, payload.Address, OnConnectComplete, OnConnectFail,
|
||||
OnConnectDisconnect);
|
||||
// 发送登录请求到Gate服务器
|
||||
var loginResponse = (G2C_LoginResponse)await _session.Call(new C2G_LoginRequest()
|
||||
{
|
||||
ToKen = response.ToKen
|
||||
});
|
||||
if (loginResponse.ErrorCode != 0)
|
||||
{
|
||||
Log.Error($"登录发生错误{loginResponse.ErrorCode}");
|
||||
return;
|
||||
}
|
||||
|
||||
Log.Debug(
|
||||
$"登录到Gate服务器成功!LoginTime:{loginResponse.GameAccountInfo.LoginTime} CreateTime:{loginResponse.GameAccountInfo.CreateTime}");
|
||||
}
|
||||
|
||||
private void OnConnectComplete()
|
||||
{
|
||||
Log.Debug("连接成功");
|
||||
// 添加心跳组件给Session。
|
||||
// Start(2000)就是2000毫秒。
|
||||
_session.AddComponent<SessionHeartbeatComponent>().Start(2000);
|
||||
}
|
||||
|
||||
private void OnConnectFail()
|
||||
{
|
||||
Log.Debug("连接失败");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
private void OnConnectDisconnect()
|
||||
{
|
||||
Log.Debug("连接断开");
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
|
||||
Reference in New Issue
Block a user