diff --git a/Assets/Scripts/Generate.meta b/Assets/Scripts/Generate.meta new file mode 100644 index 000000000..15ea9ba6b --- /dev/null +++ b/Assets/Scripts/Generate.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 418928520eda48558d6ff3350d301e78 +timeCreated: 1752655646 \ No newline at end of file diff --git a/Assets/Scripts/Generate/NetworkProtocol.meta b/Assets/Scripts/Generate/NetworkProtocol.meta new file mode 100644 index 000000000..778cb8a0a --- /dev/null +++ b/Assets/Scripts/Generate/NetworkProtocol.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 28af371d580930a4682dfc9be6deec1d +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Generate/NetworkProtocol/OuterMessage.cs b/Assets/Scripts/Generate/NetworkProtocol/OuterMessage.cs new file mode 100644 index 000000000..76d5c4b62 --- /dev/null +++ b/Assets/Scripts/Generate/NetworkProtocol/OuterMessage.cs @@ -0,0 +1,606 @@ +using ProtoBuf; +using System.Collections.Generic; +using NBC; +using NBC.Network.Interface; +using NBC.Serialize; + +#pragma warning disable CS8618 + +namespace NBC +{ + [ProtoContract] + public partial class C2A_RegisterRequest : AMessage, IRequest, IProto + { + public static C2A_RegisterRequest Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + + public override void Dispose() + { + Username = default; + Password = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + + [ProtoIgnore] public A2C_RegisterResponse ResponseType { get; set; } + + public uint OpCode() + { + return OuterOpcode.C2A_RegisterRequest; + } + + [ProtoMember(1)] public string Username { get; set; } + [ProtoMember(2)] public string Password { get; set; } + } + + [ProtoContract] + public partial class A2C_RegisterResponse : AMessage, IResponse, IProto + { + public static A2C_RegisterResponse Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + + public override void Dispose() + { + ErrorCode = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + + public uint OpCode() + { + return OuterOpcode.A2C_RegisterResponse; + } + + [ProtoMember(1)] public uint ErrorCode { get; set; } + } + + [ProtoContract] + public partial class C2A_LoginRequest : AMessage, IRequest, IProto + { + public static C2A_LoginRequest Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + + public override void Dispose() + { + Username = default; + Password = default; + LoginType = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + + [ProtoIgnore] public A2C_LoginResponse ResponseType { get; set; } + + public uint OpCode() + { + return OuterOpcode.C2A_LoginRequest; + } + + [ProtoMember(1)] public string Username { get; set; } + [ProtoMember(2)] public string Password { get; set; } + [ProtoMember(3)] public int LoginType { get; set; } + } + + [ProtoContract] + public partial class A2C_LoginResponse : AMessage, IResponse, IProto + { + public static A2C_LoginResponse Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + + public override void Dispose() + { + ErrorCode = default; + ToKen = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + + public uint OpCode() + { + return OuterOpcode.A2C_LoginResponse; + } + + [ProtoMember(1)] public string ToKen { get; set; } + [ProtoMember(2)] public uint ErrorCode { get; set; } + } + + /// + /// 客户端登录到Gate服务器 + /// + [ProtoContract] + public partial class C2G_LoginRequest : AMessage, IRequest, IProto + { + public static C2G_LoginRequest Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + + public override void Dispose() + { + ToKen = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + + [ProtoIgnore] public G2C_LoginResponse ResponseType { get; set; } + + public uint OpCode() + { + return OuterOpcode.C2G_LoginRequest; + } + + [ProtoMember(1)] public string ToKen { get; set; } + } + + [ProtoContract] + public partial class G2C_LoginResponse : AMessage, IResponse, IProto + { + public static G2C_LoginResponse Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + + public override void Dispose() + { + ErrorCode = default; + GameAccountInfo = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + + public uint OpCode() + { + return OuterOpcode.G2C_LoginResponse; + } + + [ProtoMember(1)] public GameAccountInfo GameAccountInfo { get; set; } + [ProtoMember(2)] public uint ErrorCode { get; set; } + } + + /// + /// 通知客户端重复登录 + /// + [ProtoContract] + public partial class G2C_RepeatLogin : AMessage, IMessage, IProto + { + public static G2C_RepeatLogin Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + + public override void Dispose() + { +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + + public uint OpCode() + { + return OuterOpcode.G2C_RepeatLogin; + } + } + + /// + /// GameAccount实体类 + /// + [ProtoContract] + public partial class GameAccountInfo : AMessage, IProto + { + public static GameAccountInfo Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + + public override void Dispose() + { + CreateTime = default; + LoginTime = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + + [ProtoMember(1)] public long CreateTime { get; set; } + [ProtoMember(2)] public long LoginTime { get; set; } + } + + /// + /// 拿到当前账号的信息 + /// + [ProtoContract] + public partial class C2G_GetAccountInfoRequest : AMessage, IRequest, IProto + { + public static C2G_GetAccountInfoRequest Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + + public override void Dispose() + { +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + + [ProtoIgnore] public G2C_GetAccountInfoResponse ResponseType { get; set; } + + public uint OpCode() + { + return OuterOpcode.C2G_GetAccountInfoRequest; + } + } + + [ProtoContract] + public partial class G2C_GetAccountInfoResponse : AMessage, IResponse, IProto + { + public static G2C_GetAccountInfoResponse Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + + public override void Dispose() + { + ErrorCode = default; + GameAccountInfo = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + + public uint OpCode() + { + return OuterOpcode.G2C_GetAccountInfoResponse; + } + + [ProtoMember(1)] public GameAccountInfo GameAccountInfo { get; set; } + [ProtoMember(2)] public uint ErrorCode { get; set; } + } + + [ProtoContract] + public partial class C2G_TestMessage : AMessage, IMessage, IProto + { + public static C2G_TestMessage Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + + public override void Dispose() + { + Tag = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + + public uint OpCode() + { + return OuterOpcode.C2G_TestMessage; + } + + [ProtoMember(1)] public string Tag { get; set; } + } + + [ProtoContract] + public partial class C2G_TestRequest : AMessage, IRequest, IProto + { + public static C2G_TestRequest Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + + public override void Dispose() + { + Tag = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + + [ProtoIgnore] public G2C_TestResponse ResponseType { get; set; } + + public uint OpCode() + { + return OuterOpcode.C2G_TestRequest; + } + + [ProtoMember(1)] public string Tag { get; set; } + } + + [ProtoContract] + public partial class G2C_TestResponse : AMessage, IResponse, IProto + { + public static G2C_TestResponse Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + + public override void Dispose() + { + ErrorCode = default; + Tag = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + + public uint OpCode() + { + return OuterOpcode.G2C_TestResponse; + } + + [ProtoMember(1)] public string Tag { get; set; } + [ProtoMember(2)] public uint ErrorCode { get; set; } + } + + [ProtoContract] + public partial class C2G_CreateAddressableRequest : AMessage, IRequest, IProto + { + public static C2G_CreateAddressableRequest Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + + public override void Dispose() + { +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + + [ProtoIgnore] public G2C_CreateAddressableResponse ResponseType { get; set; } + + public uint OpCode() + { + return OuterOpcode.C2G_CreateAddressableRequest; + } + } + + [ProtoContract] + public partial class G2C_CreateAddressableResponse : AMessage, IResponse, IProto + { + public static G2C_CreateAddressableResponse Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + + public override void Dispose() + { + ErrorCode = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + + public uint OpCode() + { + return OuterOpcode.G2C_CreateAddressableResponse; + } + + [ProtoMember(1)] public uint ErrorCode { get; set; } + } + + [ProtoContract] + public partial class C2M_TestMessage : AMessage, IAddressableRouteMessage, IProto + { + public static C2M_TestMessage Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + + public override void Dispose() + { + Tag = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + + public uint OpCode() + { + return OuterOpcode.C2M_TestMessage; + } + + [ProtoMember(1)] public string Tag { get; set; } + } + + [ProtoContract] + public partial class C2M_TestRequest : AMessage, IAddressableRouteRequest, IProto + { + public static C2M_TestRequest Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + + public override void Dispose() + { + Tag = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + + [ProtoIgnore] public M2C_TestResponse ResponseType { get; set; } + + public uint OpCode() + { + return OuterOpcode.C2M_TestRequest; + } + + [ProtoMember(1)] public string Tag { get; set; } + } + + [ProtoContract] + public partial class M2C_TestResponse : AMessage, IAddressableRouteResponse, IProto + { + public static M2C_TestResponse Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + + public override void Dispose() + { + ErrorCode = default; + Tag = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + + public uint OpCode() + { + return OuterOpcode.M2C_TestResponse; + } + + [ProtoMember(1)] public string Tag { get; set; } + [ProtoMember(2)] public uint ErrorCode { get; set; } + } + + /// + /// 通知Gate服务器创建一个Chat的Route连接 + /// + [ProtoContract] + public partial class C2G_CreateChatRouteRequest : AMessage, IRequest, IProto + { + public static C2G_CreateChatRouteRequest Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + + public override void Dispose() + { +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + + [ProtoIgnore] public G2C_CreateChatRouteResponse ResponseType { get; set; } + + public uint OpCode() + { + return OuterOpcode.C2G_CreateChatRouteRequest; + } + } + + [ProtoContract] + public partial class G2C_CreateChatRouteResponse : AMessage, IResponse, IProto + { + public static G2C_CreateChatRouteResponse Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + + public override void Dispose() + { + ErrorCode = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + + public uint OpCode() + { + return OuterOpcode.G2C_CreateChatRouteResponse; + } + + [ProtoMember(1)] public uint ErrorCode { get; set; } + } + + /// + /// 发送一个Route消息给Chat + /// + [ProtoContract] + public partial class C2Chat_TestMessage : AMessage, ICustomRouteMessage, IProto + { + public static C2Chat_TestMessage Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + + public override void Dispose() + { + Tag = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + + public uint OpCode() + { + return OuterOpcode.C2Chat_TestMessage; + } + + [ProtoIgnore] public int RouteType => NBC.RouteType.ChatRoute; + [ProtoMember(1)] public string Tag { get; set; } + } + + /// + /// 发送一个RPCRoute消息给Chat + /// + [ProtoContract] + public partial class C2Chat_TestMessageRequest : AMessage, ICustomRouteRequest, IProto + { + public static C2Chat_TestMessageRequest Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + + public override void Dispose() + { + Tag = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + + [ProtoIgnore] public Chat2C_TestMessageResponse ResponseType { get; set; } + + public uint OpCode() + { + return OuterOpcode.C2Chat_TestMessageRequest; + } + + [ProtoIgnore] public int RouteType => NBC.RouteType.ChatRoute; + [ProtoMember(1)] public string Tag { get; set; } + } + + [ProtoContract] + public partial class Chat2C_TestMessageResponse : AMessage, ICustomRouteResponse, IProto + { + public static Chat2C_TestMessageResponse Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + + public override void Dispose() + { + ErrorCode = default; + Tag = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + + public uint OpCode() + { + return OuterOpcode.Chat2C_TestMessageResponse; + } + + [ProtoMember(1)] public string Tag { get; set; } + [ProtoMember(2)] public uint ErrorCode { get; set; } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Generate/NetworkProtocol/OuterMessage.cs.meta b/Assets/Scripts/Generate/NetworkProtocol/OuterMessage.cs.meta new file mode 100644 index 000000000..8002bf12f --- /dev/null +++ b/Assets/Scripts/Generate/NetworkProtocol/OuterMessage.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: cf5bc579defd25640b8f277220459410 \ No newline at end of file diff --git a/Assets/Scripts/Generate/NetworkProtocol/OuterOpcode.cs b/Assets/Scripts/Generate/NetworkProtocol/OuterOpcode.cs new file mode 100644 index 000000000..36b3c2e27 --- /dev/null +++ b/Assets/Scripts/Generate/NetworkProtocol/OuterOpcode.cs @@ -0,0 +1,28 @@ +namespace NBC +{ + public static partial class OuterOpcode + { + public const uint C2A_RegisterRequest = 268445457; + public const uint A2C_RegisterResponse = 402663185; + public const uint C2A_LoginRequest = 268445458; + public const uint A2C_LoginResponse = 402663186; + public const uint C2G_LoginRequest = 268445459; + public const uint G2C_LoginResponse = 402663187; + public const uint G2C_RepeatLogin = 134227729; + public const uint C2G_GetAccountInfoRequest = 268445460; + public const uint G2C_GetAccountInfoResponse = 402663188; + public const uint C2G_TestMessage = 134227730; + public const uint C2G_TestRequest = 268445461; + public const uint G2C_TestResponse = 402663189; + public const uint C2G_CreateAddressableRequest = 268445462; + public const uint G2C_CreateAddressableResponse = 402663190; + public const uint C2M_TestMessage = 1342187281; + public const uint C2M_TestRequest = 1476405009; + public const uint M2C_TestResponse = 1610622737; + public const uint C2G_CreateChatRouteRequest = 268445463; + public const uint G2C_CreateChatRouteResponse = 402663191; + public const uint C2Chat_TestMessage = 2147493649; + public const uint C2Chat_TestMessageRequest = 2281711377; + public const uint Chat2C_TestMessageResponse = 2415929105; + } +} diff --git a/Assets/Scripts/Generate/NetworkProtocol/OuterOpcode.cs.meta b/Assets/Scripts/Generate/NetworkProtocol/OuterOpcode.cs.meta new file mode 100644 index 000000000..42fa8a791 --- /dev/null +++ b/Assets/Scripts/Generate/NetworkProtocol/OuterOpcode.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: dc84d27ae0bdf764fb50b6d543cbcf7e \ No newline at end of file diff --git a/Assets/Scripts/Generate/NetworkProtocol/RoamingType.cs b/Assets/Scripts/Generate/NetworkProtocol/RoamingType.cs new file mode 100644 index 000000000..9c6f28b67 --- /dev/null +++ b/Assets/Scripts/Generate/NetworkProtocol/RoamingType.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; +namespace NBC +{ + // Roaming协议定义(需要定义10000以上、因为10000以内的框架预留) + public static class RoamingType + { + public const int MapRoamingType = 10001; + public const int ChatRoamingType = 10002; + public static IEnumerable RoamingTypes + { + get + { + yield return 10001; + yield return 10002; + } + } + } +} diff --git a/Assets/Scripts/Generate/NetworkProtocol/RoamingType.cs.meta b/Assets/Scripts/Generate/NetworkProtocol/RoamingType.cs.meta new file mode 100644 index 000000000..10f98e8ae --- /dev/null +++ b/Assets/Scripts/Generate/NetworkProtocol/RoamingType.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 61409fb8349e78a4ca1db7e0b5342687 \ No newline at end of file diff --git a/Assets/Scripts/Generate/NetworkProtocol/RouteType.cs b/Assets/Scripts/Generate/NetworkProtocol/RouteType.cs new file mode 100644 index 000000000..a885e2d26 --- /dev/null +++ b/Assets/Scripts/Generate/NetworkProtocol/RouteType.cs @@ -0,0 +1,9 @@ +namespace NBC +{ + // Route协议定义(需要定义1000以上、因为1000以内的框架预留) + public static class RouteType + { + public const int GateRoute = 1001; // Gate + public const int ChatRoute = 1002; // Chat + } +} \ No newline at end of file diff --git a/Assets/Scripts/Generate/NetworkProtocol/RouteType.cs.meta b/Assets/Scripts/Generate/NetworkProtocol/RouteType.cs.meta new file mode 100644 index 000000000..fd249cfe8 --- /dev/null +++ b/Assets/Scripts/Generate/NetworkProtocol/RouteType.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 76b668cc0db30b34ab2a64d695b14ac4 \ No newline at end of file diff --git a/Assets/Scripts/Net.meta b/Assets/Scripts/Net.meta new file mode 100644 index 000000000..fd9aa4f83 --- /dev/null +++ b/Assets/Scripts/Net.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 5af9172d15de48549ab5e6d2fc4f39a2 +timeCreated: 1752656726 \ No newline at end of file diff --git a/Assets/Scripts/Net/Entity.meta b/Assets/Scripts/Net/Entity.meta new file mode 100644 index 000000000..1e388566c --- /dev/null +++ b/Assets/Scripts/Net/Entity.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 74ec0aa87eeeae1429e7ed1dcd09f3ed +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Net/Entity/AuthenticationSelectComponent.cs b/Assets/Scripts/Net/Entity/AuthenticationSelectComponent.cs new file mode 100644 index 000000000..3b17a0864 --- /dev/null +++ b/Assets/Scripts/Net/Entity/AuthenticationSelectComponent.cs @@ -0,0 +1,7 @@ +namespace Assets.Scripts.Entity +{ + public class AuthenticationSelectComponent : NBC.Entitas.Entity + { + + } +} \ No newline at end of file diff --git a/Assets/Scripts/Net/Entity/AuthenticationSelectComponent.cs.meta b/Assets/Scripts/Net/Entity/AuthenticationSelectComponent.cs.meta new file mode 100644 index 000000000..c8e243089 --- /dev/null +++ b/Assets/Scripts/Net/Entity/AuthenticationSelectComponent.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d25be39e48b564e35ad8425c9636ac2e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Net/Entity/JWT.meta b/Assets/Scripts/Net/Entity/JWT.meta new file mode 100644 index 000000000..b257d4553 --- /dev/null +++ b/Assets/Scripts/Net/Entity/JWT.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d2b302f418e564f9bb7b2b53ac8e8194 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Net/Entity/JWT/JWTParseComponent.cs b/Assets/Scripts/Net/Entity/JWT/JWTParseComponent.cs new file mode 100644 index 000000000..6bcac1083 --- /dev/null +++ b/Assets/Scripts/Net/Entity/JWT/JWTParseComponent.cs @@ -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 + { + + } +} \ No newline at end of file diff --git a/Assets/Scripts/Net/Entity/JWT/JWTParseComponent.cs.meta b/Assets/Scripts/Net/Entity/JWT/JWTParseComponent.cs.meta new file mode 100644 index 000000000..2cd06633d --- /dev/null +++ b/Assets/Scripts/Net/Entity/JWT/JWTParseComponent.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b961d3db251a549139e44f247fff06f4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Net/Hotfix.meta b/Assets/Scripts/Net/Hotfix.meta new file mode 100644 index 000000000..f0367d08c --- /dev/null +++ b/Assets/Scripts/Net/Hotfix.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 50a991bccd12a0a4d9495db025c6fb78 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Net/Hotfix/.DS_Store b/Assets/Scripts/Net/Hotfix/.DS_Store new file mode 100644 index 000000000..7c6d737b0 Binary files /dev/null and b/Assets/Scripts/Net/Hotfix/.DS_Store differ diff --git a/Assets/Scripts/Net/Hotfix/Handler.meta b/Assets/Scripts/Net/Hotfix/Handler.meta new file mode 100644 index 000000000..2846f77ef --- /dev/null +++ b/Assets/Scripts/Net/Hotfix/Handler.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b0f4856e6f88e4e0490a5ec736aa974a +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Net/Hotfix/Handler/G2C_RepeatLoginHandler.cs b/Assets/Scripts/Net/Hotfix/Handler/G2C_RepeatLoginHandler.cs new file mode 100644 index 000000000..fb843a551 --- /dev/null +++ b/Assets/Scripts/Net/Hotfix/Handler/G2C_RepeatLoginHandler.cs @@ -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 + { + protected override async FTask Run(Session session, G2C_RepeatLogin message) + { + Log.Debug("客户端重复登录了"); + await FTask.CompletedTask; + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Net/Hotfix/Handler/G2C_RepeatLoginHandler.cs.meta b/Assets/Scripts/Net/Hotfix/Handler/G2C_RepeatLoginHandler.cs.meta new file mode 100644 index 000000000..a22143981 --- /dev/null +++ b/Assets/Scripts/Net/Hotfix/Handler/G2C_RepeatLoginHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a7624fabae6664a6c9c9ebccebba4450 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Net/Hotfix/System.meta b/Assets/Scripts/Net/Hotfix/System.meta new file mode 100644 index 000000000..5dab2dc98 --- /dev/null +++ b/Assets/Scripts/Net/Hotfix/System.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c3e31ce18df8044408957b2960698dc5 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Net/Hotfix/System/AuthenticationSelectComponentSystem.cs b/Assets/Scripts/Net/Hotfix/System/AuthenticationSelectComponentSystem.cs new file mode 100644 index 000000000..a9d491854 --- /dev/null +++ b/Assets/Scripts/Net/Hotfix/System/AuthenticationSelectComponentSystem.cs @@ -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 AuthenticationList = new List() + { + "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]; + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Net/Hotfix/System/AuthenticationSelectComponentSystem.cs.meta b/Assets/Scripts/Net/Hotfix/System/AuthenticationSelectComponentSystem.cs.meta new file mode 100644 index 000000000..96720be23 --- /dev/null +++ b/Assets/Scripts/Net/Hotfix/System/AuthenticationSelectComponentSystem.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 282ab32bfd2314add934876696504a36 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Net/Hotfix/System/JWT.meta b/Assets/Scripts/Net/Hotfix/System/JWT.meta new file mode 100644 index 000000000..4c30da437 --- /dev/null +++ b/Assets/Scripts/Net/Hotfix/System/JWT.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9c7d4cc51480743d99ae9f1208d7c727 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Net/Hotfix/System/JWT/JWTParseComponentSystem.cs b/Assets/Scripts/Net/Hotfix/System/JWT/JWTParseComponentSystem.cs new file mode 100644 index 000000000..a8d650610 --- /dev/null +++ b/Assets/Scripts/Net/Hotfix/System/JWT/JWTParseComponentSystem.cs @@ -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); + return true; + } + catch (Exception e) + { + Log.Error(e); + return false; + } + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Net/Hotfix/System/JWT/JWTParseComponentSystem.cs.meta b/Assets/Scripts/Net/Hotfix/System/JWT/JWTParseComponentSystem.cs.meta new file mode 100644 index 000000000..bfc7c89d0 --- /dev/null +++ b/Assets/Scripts/Net/Hotfix/System/JWT/JWTParseComponentSystem.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e998e2344b9894f7c9f40b04302e2765 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Net/Hotfix/System/SessionHelper.cs b/Assets/Scripts/Net/Hotfix/System/SessionHelper.cs new file mode 100644 index 000000000..9daec1590 --- /dev/null +++ b/Assets/Scripts/Net/Hotfix/System/SessionHelper.cs @@ -0,0 +1,30 @@ +using System; +using NBC; +using NBC.Network; + +namespace Assets.Scripts.Hotfix +{ + public static class SessionHelper + { + /// + /// 创建一个网络会话 + /// + /// + /// 远程服务器地址 + /// 当连接成功执行的委托,可为空 + /// 当连接超时或失败执行的委托,可为空 + /// 当连接断开执行的委托,可为空 + /// + 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); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Net/Hotfix/System/SessionHelper.cs.meta b/Assets/Scripts/Net/Hotfix/System/SessionHelper.cs.meta new file mode 100644 index 000000000..02f1369ef --- /dev/null +++ b/Assets/Scripts/Net/Hotfix/System/SessionHelper.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f497ae44af4c041f5acc659665ca26fc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/SessionHelper.cs b/Assets/Scripts/SessionHelper.cs new file mode 100644 index 000000000..51efe9f06 --- /dev/null +++ b/Assets/Scripts/SessionHelper.cs @@ -0,0 +1,30 @@ +using System; +using NBC; +using NBC.Network; + +namespace NBF +{ + public static class SessionHelper + { + /// + /// 创建一个网络会话 + /// + /// + /// 远程服务器地址 + /// 当连接成功执行的委托,可为空 + /// 当连接超时或失败执行的委托,可为空 + /// 当连接断开执行的委托,可为空 + /// + 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); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/SessionHelper.cs.meta b/Assets/Scripts/SessionHelper.cs.meta new file mode 100644 index 000000000..2e358fa87 --- /dev/null +++ b/Assets/Scripts/SessionHelper.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 55c68672713040e4978ccb0e17564338 +timeCreated: 1752656502 \ No newline at end of file diff --git a/Assets/Scripts/Startup/Init.cs b/Assets/Scripts/Startup/Init.cs index b94e9b418..27000b8d2 100644 --- a/Assets/Scripts/Startup/Init.cs +++ b/Assets/Scripts/Startup/Init.cs @@ -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().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().Start(2000); + } + + private void OnConnectFail() + { + Log.Debug("连接失败"); + } + + #endregion + + + private void OnConnectDisconnect() + { + Log.Debug("连接断开"); } private void LoadData()