调整目录结构
This commit is contained in:
8
Assets/Scripts/Model/Net/Entity.meta
Normal file
8
Assets/Scripts/Model/Net/Entity.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 74ec0aa87eeeae1429e7ed1dcd09f3ed
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Assets.Scripts.Entity
|
||||
{
|
||||
public class AuthenticationSelectComponent : NBC.Entitas.Entity
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d25be39e48b564e35ad8425c9636ac2e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/Model/Net/Entity/JWT.meta
Normal file
8
Assets/Scripts/Model/Net/Entity/JWT.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d2b302f418e564f9bb7b2b53ac8e8194
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
17
Assets/Scripts/Model/Net/Entity/JWT/JWTParseComponent.cs
Normal file
17
Assets/Scripts/Model/Net/Entity/JWT/JWTParseComponent.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
namespace Assets.Scripts.Entity
|
||||
{
|
||||
public sealed class Payload
|
||||
{
|
||||
public long aId { get; set; }
|
||||
public string Address { get; set; }
|
||||
public uint SceneId { get; set; }
|
||||
public int exp { get; set; }
|
||||
public string iss { get; set; }
|
||||
public string aud { get; set; }
|
||||
}
|
||||
|
||||
public sealed class JWTParseComponent : NBC.Entitas.Entity
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b961d3db251a549139e44f247fff06f4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/Model/Net/Hotfix.meta
Normal file
8
Assets/Scripts/Model/Net/Hotfix.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 50a991bccd12a0a4d9495db025c6fb78
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/Scripts/Model/Net/Hotfix/.DS_Store
vendored
Normal file
BIN
Assets/Scripts/Model/Net/Hotfix/.DS_Store
vendored
Normal file
Binary file not shown.
8
Assets/Scripts/Model/Net/Hotfix/Handler.meta
Normal file
8
Assets/Scripts/Model/Net/Hotfix/Handler.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b0f4856e6f88e4e0490a5ec736aa974a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,16 @@
|
||||
using NBC;
|
||||
using NBC.Async;
|
||||
using NBC.Network;
|
||||
using NBC.Network.Interface;
|
||||
|
||||
namespace Assets.Scripts.Hotfix
|
||||
{
|
||||
public sealed class G2C_RepeatLoginHandler : Message<G2C_RepeatLogin>
|
||||
{
|
||||
protected override async FTask Run(Session session, G2C_RepeatLogin message)
|
||||
{
|
||||
Log.Debug("客户端重复登录了");
|
||||
await FTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a7624fabae6664a6c9c9ebccebba4450
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/Model/Net/Hotfix/System.meta
Normal file
8
Assets/Scripts/Model/Net/Hotfix/System.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c3e31ce18df8044408957b2960698dc5
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,22 @@
|
||||
using System.Collections.Generic;
|
||||
using Assets.Scripts.Entity;
|
||||
using NBC.Helper;
|
||||
|
||||
namespace Assets.Scripts.Hotfix
|
||||
{
|
||||
public static class AuthenticationSelectComponentSystem
|
||||
{
|
||||
private static readonly List<string> AuthenticationList = new List<string>()
|
||||
{
|
||||
"127.0.0.1:20001", "127.0.0.1:20002", "127.0.0.1:20003"
|
||||
};
|
||||
|
||||
public static string Select(this AuthenticationSelectComponent self, string userName)
|
||||
{
|
||||
var userNameHashCode = HashCodeHelper.MurmurHash3(userName);
|
||||
var authenticationListIndex = userNameHashCode % AuthenticationList.Count;
|
||||
// 按照现在的情况下,这个模出的值只会是0 - 3
|
||||
return AuthenticationList[(int)authenticationListIndex];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 282ab32bfd2314add934876696504a36
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/Model/Net/Hotfix/System/JWT.meta
Normal file
8
Assets/Scripts/Model/Net/Hotfix/System/JWT.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9c7d4cc51480743d99ae9f1208d7c727
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using Assets.Scripts.Entity;
|
||||
using NBC;
|
||||
using NBC.Helper;
|
||||
|
||||
namespace Assets.Scripts.Hotfix
|
||||
{
|
||||
public static class JWTParseComponentSystem
|
||||
{
|
||||
//payload:{"aId":433552570364198912,"Address":"127.0.0.1:8080","exp":1729842327,"iss":"Fantasy","aud":"Fantasy"}
|
||||
public static bool Parse(this JWTParseComponent self, string toKen, out Payload payloadData)
|
||||
{
|
||||
payloadData = null;
|
||||
|
||||
try
|
||||
{
|
||||
// JWT通常是由三个部分组成的,Header,Payload,Signature。
|
||||
var tokens = toKen.Split('.');
|
||||
|
||||
if (tokens.Length != 3)
|
||||
{
|
||||
Log.Error("Invalid JWT token");
|
||||
return false;
|
||||
}
|
||||
// JWT的Payload不是标准的Base64格式,因为咱们C#的Convert要求是一个标准的Base64格式。
|
||||
// JWT的Payload是Base64URL格式,它里面的"-"替代成了"+","_"替代成了"/",需要把这些给还原成Base64格式
|
||||
var basePayload = tokens[1].Replace('-', '+').Replace('_', '/');
|
||||
// 因为Base64的编码长度需要是4的倍数,如果不是的话咱们需要把这个长度用=来填充,使其长度符合要求
|
||||
switch (basePayload.Length % 4)
|
||||
{
|
||||
// case 0:
|
||||
// {
|
||||
// // 如果这个余数是0,那就表示长度已经是4的倍数,那就没必要处理了。
|
||||
// break;
|
||||
// }
|
||||
// case 1:
|
||||
// {
|
||||
// // 如果这个余数是1,那就表示这个Base64格式是不正确的,不是咱们发放的token。
|
||||
// // 这样情况下,也不需要处理了。
|
||||
// break;
|
||||
// }
|
||||
case 2:
|
||||
{
|
||||
basePayload +="==";
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
basePayload +="=";
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 将修复后的字符串解码为数组
|
||||
var basePayloadBytes = Convert.FromBase64String(basePayload);
|
||||
var payload = System.Text.Encoding.UTF8.GetString(basePayloadBytes);
|
||||
payloadData = JsonHelper.Deserialize<Payload>(payload);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e998e2344b9894f7c9f40b04302e2765
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
30
Assets/Scripts/Model/Net/Hotfix/System/SessionHelper.cs
Normal file
30
Assets/Scripts/Model/Net/Hotfix/System/SessionHelper.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using NBC;
|
||||
using NBC.Network;
|
||||
|
||||
namespace Assets.Scripts.Hotfix
|
||||
{
|
||||
public static class SessionHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 创建一个网络会话
|
||||
/// </summary>
|
||||
/// <param name="scene"></param>
|
||||
/// <param name="address">远程服务器地址</param>
|
||||
/// <param name="onConnectComplete">当连接成功执行的委托,可为空</param>
|
||||
/// <param name="onConnectFail">当连接超时或失败执行的委托,可为空</param>
|
||||
/// <param name="onConnectDisconnect">当连接断开执行的委托,可为空</param>
|
||||
/// <returns></returns>
|
||||
public static Session CreateSession(Scene scene, string address, Action onConnectComplete, Action onConnectFail,
|
||||
Action onConnectDisconnect)
|
||||
{
|
||||
return scene.Connect(
|
||||
address,
|
||||
NetworkProtocolType.KCP,
|
||||
onConnectComplete,
|
||||
onConnectFail,
|
||||
onConnectDisconnect,
|
||||
false, 5000);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Model/Net/Hotfix/System/SessionHelper.cs.meta
Normal file
11
Assets/Scripts/Model/Net/Hotfix/System/SessionHelper.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f497ae44af4c041f5acc659665ca26fc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
3
Assets/Scripts/Model/Net/MessageHandler.meta
Normal file
3
Assets/Scripts/Model/Net/MessageHandler.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 513b2467b34d4c159035e59b0f79164c
|
||||
timeCreated: 1754532816
|
||||
@@ -0,0 +1,20 @@
|
||||
using NBC;
|
||||
using NBC.Network;
|
||||
using NBC.Network.Interface;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class Chat2C_MessageHandler : Message<S2C_Message>
|
||||
{
|
||||
protected override async FTask Run(Session session, S2C_Message message)
|
||||
{
|
||||
Log.Debug($"收到一条消息推送,message={message.Message}");
|
||||
var chatTestPanel = App.UI.GetUI<ChatTestPanel>();
|
||||
if (chatTestPanel != null)
|
||||
{
|
||||
chatTestPanel.Message(message.Message.Content);
|
||||
}
|
||||
await FTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4937340a042f4608918a01ecf456b6fe
|
||||
timeCreated: 1754532888
|
||||
75
Assets/Scripts/Model/Net/Net.cs
Normal file
75
Assets/Scripts/Model/Net/Net.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using Assets.Scripts.Entity;
|
||||
using Assets.Scripts.Hotfix;
|
||||
using NBC;
|
||||
using NBC.Network;
|
||||
using NBC.Network.Interface;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class Net : EventDispatcher
|
||||
{
|
||||
public static Session Session { get; private set; }
|
||||
|
||||
public const int HeartbeatInterval = 5000;
|
||||
|
||||
#region 单例
|
||||
|
||||
private static Net _inst;
|
||||
|
||||
public static Net Inst => _inst ??= new Net();
|
||||
|
||||
public Net()
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 连接创建和回调
|
||||
|
||||
public static Session CreateSession(string address)
|
||||
{
|
||||
var session = SessionHelper.CreateSession(App.Main, address, OnConnectComplete,
|
||||
OnConnectFail,
|
||||
OnConnectDisconnect);
|
||||
|
||||
Session = session;
|
||||
return session;
|
||||
}
|
||||
|
||||
private static void OnConnectComplete()
|
||||
{
|
||||
Log.Debug("连接成功");
|
||||
Session.AddComponent<SessionHeartbeatComponent>().Start(HeartbeatInterval);
|
||||
}
|
||||
|
||||
private static void OnConnectFail()
|
||||
{
|
||||
Log.Debug("连接失败");
|
||||
// SetLoginState(false);
|
||||
}
|
||||
|
||||
private static void OnConnectDisconnect()
|
||||
{
|
||||
Log.Debug("连接断开");
|
||||
// SetLoginState(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 消息收发
|
||||
|
||||
public static FTask<IResponse> Call(IRequest request, long routeId = 0)
|
||||
{
|
||||
// var response = await Session.Call(request, routeId);
|
||||
// response.DispatchMessage();
|
||||
return Session.Call(request, routeId);;
|
||||
}
|
||||
|
||||
public static void Send(IMessage message, uint rpcId = 0, long routeId = 0)
|
||||
{
|
||||
Session.Send(message, rpcId, routeId);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Model/Net/Net.cs.meta
Normal file
3
Assets/Scripts/Model/Net/Net.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1fe56eeffd614eaea7055d1c65f6859f
|
||||
timeCreated: 1755701226
|
||||
12
Assets/Scripts/Model/Net/NetExtends.cs
Normal file
12
Assets/Scripts/Model/Net/NetExtends.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using NBC.Network.Interface;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public static class NetExtends
|
||||
{
|
||||
public static void DispatchMessage(this IResponse response)
|
||||
{
|
||||
Net.Inst.DispatchEventWith(response.OpCode().ToString(), response);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Model/Net/NetExtends.cs.meta
Normal file
3
Assets/Scripts/Model/Net/NetExtends.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 25d56f7c87744a199e926365a516b85f
|
||||
timeCreated: 1755702255
|
||||
Reference in New Issue
Block a user