放放风
This commit is contained in:
8
Assets/Scripts/Net/Entity.meta
Normal file
8
Assets/Scripts/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/Net/Entity/JWT.meta
Normal file
8
Assets/Scripts/Net/Entity/JWT.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d2b302f418e564f9bb7b2b53ac8e8194
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
17
Assets/Scripts/Net/Entity/JWT/JWTParseComponent.cs
Normal file
17
Assets/Scripts/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
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Net/Entity/JWT/JWTParseComponent.cs.meta
Normal file
11
Assets/Scripts/Net/Entity/JWT/JWTParseComponent.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b961d3db251a549139e44f247fff06f4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/Net/Hotfix.meta
Normal file
8
Assets/Scripts/Net/Hotfix.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 50a991bccd12a0a4d9495db025c6fb78
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/Scripts/Net/Hotfix/.DS_Store
vendored
Normal file
BIN
Assets/Scripts/Net/Hotfix/.DS_Store
vendored
Normal file
Binary file not shown.
8
Assets/Scripts/Net/Hotfix/Handler.meta
Normal file
8
Assets/Scripts/Net/Hotfix/Handler.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b0f4856e6f88e4e0490a5ec736aa974a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
16
Assets/Scripts/Net/Hotfix/Handler/G2C_RepeatLoginHandler.cs
Normal file
16
Assets/Scripts/Net/Hotfix/Handler/G2C_RepeatLoginHandler.cs
Normal file
@@ -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/Net/Hotfix/System.meta
Normal file
8
Assets/Scripts/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/Net/Hotfix/System/JWT.meta
Normal file
8
Assets/Scripts/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/Net/Hotfix/System/SessionHelper.cs
Normal file
30
Assets/Scripts/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/Net/Hotfix/System/SessionHelper.cs.meta
Normal file
11
Assets/Scripts/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:
|
||||
Reference in New Issue
Block a user