首次提交
This commit is contained in:
BIN
Assets/Scripts/Common/Net/Hotfix/.DS_Store
vendored
Normal file
BIN
Assets/Scripts/Common/Net/Hotfix/.DS_Store
vendored
Normal file
Binary file not shown.
8
Assets/Scripts/Common/Net/Hotfix/Handler.meta
Normal file
8
Assets/Scripts/Common/Net/Hotfix/Handler.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b0f4856e6f88e4e0490a5ec736aa974a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,17 @@
|
||||
using Fantasy;
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Network;
|
||||
using Fantasy.Network.Interface;
|
||||
using Log = NBC.Log;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public sealed class G2C_RepeatLoginHandler : Message<G2C_RepeatLogin>
|
||||
{
|
||||
protected override async FTask Run(Session session, G2C_RepeatLogin message)
|
||||
{
|
||||
Log.Info("客户端重复登录了");
|
||||
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/Common/Net/Hotfix/System.meta
Normal file
8
Assets/Scripts/Common/Net/Hotfix/System.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c3e31ce18df8044408957b2960698dc5
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,21 @@
|
||||
using System.Collections.Generic;
|
||||
using Fantasy.Helper;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
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/Common/Net/Hotfix/System/JWT.meta
Normal file
8
Assets/Scripts/Common/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,69 @@
|
||||
using System;
|
||||
using Fantasy.Helper;
|
||||
using NBC;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
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 =
|
||||
JsonConvert.DeserializeObject<Payload>(payload); //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:
|
||||
31
Assets/Scripts/Common/Net/Hotfix/System/SessionHelper.cs
Normal file
31
Assets/Scripts/Common/Net/Hotfix/System/SessionHelper.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
// using System;
|
||||
// using Fantasy;
|
||||
// using Fantasy.Network;
|
||||
// using NBC;
|
||||
//
|
||||
// namespace NBF
|
||||
// {
|
||||
// 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);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
@@ -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