From f6d85a1e0ad422dd4cadee216c44d80140e2f0e6 Mon Sep 17 00:00:00 2001 From: BobSong <605277374@qq.com> Date: Wed, 27 Aug 2025 00:04:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=BF=E9=97=B4=E5=88=9B=E5=BB=BA=E5=92=8C?= =?UTF-8?q?=E8=BF=9B=E5=85=A5=E7=9B=B8=E5=85=B3=E9=80=BB=E8=BE=91=E5=92=8C?= =?UTF-8?q?=E5=8D=8F=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Config/Excel/Server/SceneConfig.xlsx | Bin 16886 -> 16874 bytes Config/Excel/Version.txt | 2 +- .../NetworkProtocol/Inner/InnerMessage.proto | 19 +- .../NetworkProtocol/Outer/GameMessage.proto | 41 --- Config/NetworkProtocol/Outer/MapMessage.proto | 40 +++ .../NetworkProtocol/Outer/OuterMessage.proto | 11 +- .../NetworkProtocol/Outer/RoomMessage.proto | 76 ----- .../Outer/data/MapProtoData.proto | 65 +++++ Entity/Entity.csproj | 1 - .../Generate/NetworkProtocol/GameMessage.cs | 165 ----------- .../Generate/NetworkProtocol/InnerMessage.cs | 57 +++- .../Generate/NetworkProtocol/InnerOpcode.cs | 2 + Entity/Generate/NetworkProtocol/MapMessage.cs | 148 ++++++++++ .../Generate/NetworkProtocol/MapProtoData.cs | 234 ++++++++++++++++ .../Generate/NetworkProtocol/OuterMessage.cs | 44 --- .../Generate/NetworkProtocol/OuterOpcode.cs | 87 +++--- .../Generate/NetworkProtocol/RoomMessage.cs | 263 ------------------ Entity/Map/Component/MapManageComponent.cs | 8 + .../Map/Component/MapUnitManageComponent.cs | 8 + Entity/Map/Component/RoomManageComponent.cs | 11 + Entity/Map/Entity/Map.cs | 7 + Entity/Map/{ => Entity}/MapRoom.cs | 13 +- Entity/Map/{ => Entity}/MapUnit.cs | 12 + Entity/Model/Def/ErrorCode.cs | 20 ++ .../Handler/G2Common_EnterRequestHandler.cs | 26 +- .../Handler/G2Common_ExitRequestHandler.cs | 26 +- Hotfix/Common/Helper/SceneConfigHelper.cs | 28 +- .../Handler/G2Game_EnterRequestHandler.cs | 29 -- .../Components/PlayerManageComponentSystem.cs | 21 +- .../Outer/C2G_EnterRoomRequestHandler.cs | 63 +++++ .../Handler/Outer/C2G_LoginRequestHandler.cs | 2 +- Hotfix/Gate/System/GateUnitSystem.cs | 16 +- Hotfix/Hotfix.csproj | 4 +- .../Handler/C2Map_CreateRoomRequestHandler.cs | 59 +++- .../Handler/C2Map_EnterMapRequestHandler.cs | 33 +++ .../Inner/G2Map_EnterRequestHandler.cs | 27 ++ Hotfix/Map/Helper/MapUnitFactory.cs | 19 ++ Hotfix/Map/Helper/RoomHelper.cs | 69 +++++ Hotfix/Map/System/MapRoomSystem.cs | 19 ++ .../System/MapUnitManageComponentSystem.cs | 84 ++++++ .../Map/System/RoomManageComponentSystem.cs | 93 +++++++ Hotfix/OnCreateSceneEvent.cs | 14 +- Hotfix/OnSceneCreate_Init.cs | 4 + Main/Properties/launchSettings.json | 2 +- Server.sln.DotSettings.user | 3 + 45 files changed, 1246 insertions(+), 729 deletions(-) create mode 100644 Config/NetworkProtocol/Outer/data/MapProtoData.proto create mode 100644 Entity/Generate/NetworkProtocol/MapProtoData.cs create mode 100644 Entity/Map/Component/MapManageComponent.cs create mode 100644 Entity/Map/Component/MapUnitManageComponent.cs create mode 100644 Entity/Map/Component/RoomManageComponent.cs create mode 100644 Entity/Map/Entity/Map.cs rename Entity/Map/{ => Entity}/MapRoom.cs (69%) rename Entity/Map/{ => Entity}/MapUnit.cs (60%) delete mode 100644 Hotfix/Game/Handler/G2Game_EnterRequestHandler.cs create mode 100644 Hotfix/Gate/Handler/Outer/C2G_EnterRoomRequestHandler.cs create mode 100644 Hotfix/Map/Handler/C2Map_EnterMapRequestHandler.cs create mode 100644 Hotfix/Map/Handler/Inner/G2Map_EnterRequestHandler.cs create mode 100644 Hotfix/Map/Helper/MapUnitFactory.cs create mode 100644 Hotfix/Map/Helper/RoomHelper.cs create mode 100644 Hotfix/Map/System/MapRoomSystem.cs create mode 100644 Hotfix/Map/System/MapUnitManageComponentSystem.cs create mode 100644 Hotfix/Map/System/RoomManageComponentSystem.cs diff --git a/Config/Excel/Server/SceneConfig.xlsx b/Config/Excel/Server/SceneConfig.xlsx index 6ba3130ec6b3adb58eebf10d590463c5f20074be..56dbff95928d5aa22b29d3e2cb83ad7bdd04f0c2 100644 GIT binary patch delta 3331 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 - diff --git a/Entity/Generate/NetworkProtocol/GameMessage.cs b/Entity/Generate/NetworkProtocol/GameMessage.cs index 9c9cb9b..c4f45da 100644 --- a/Entity/Generate/NetworkProtocol/GameMessage.cs +++ b/Entity/Generate/NetworkProtocol/GameMessage.cs @@ -17,169 +17,4 @@ using Fantasy.Serialize; namespace Fantasy { - /// - /// 请求创建房间 - /// - [ProtoContract] - public partial class C2Game_CreateRoomRequest : AMessage, ICustomRouteRequest, IProto - { - public static C2Game_CreateRoomRequest Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - MapId = default; - Password = default; -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - [ProtoIgnore] - public Game2C_CreateRoomResponse ResponseType { get; set; } - public uint OpCode() { return OuterOpcode.C2Game_CreateRoomRequest; } - [ProtoIgnore] - public int RouteType => Fantasy.RouteType.MapRoute; - [ProtoMember(1)] - public int MapId { get; set; } - [ProtoMember(2)] - public string Password { get; set; } - } - /// - /// 请求创建房间成功 - /// - [ProtoContract] - public partial class Game2C_CreateRoomResponse : AMessage, ICustomRouteResponse, IProto - { - public static Game2C_CreateRoomResponse Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - ErrorCode = default; - MapId = default; - RoomId = default; -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - public uint OpCode() { return OuterOpcode.Game2C_CreateRoomResponse; } - [ProtoMember(1)] - public int MapId { get; set; } - [ProtoMember(2)] - public long RoomId { get; set; } - [ProtoMember(3)] - public uint ErrorCode { get; set; } - } - /// - /// 请求进入地图 - /// - [ProtoContract] - public partial class C2Game_EnterMapRequest : AMessage, ICustomRouteRequest, IProto - { - public static C2Game_EnterMapRequest Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - MapId = default; - Type = default; -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - [ProtoIgnore] - public Game2C_EnterMapResponse ResponseType { get; set; } - public uint OpCode() { return OuterOpcode.C2Game_EnterMapRequest; } - [ProtoIgnore] - public int RouteType => Fantasy.RouteType.MapRoute; - [ProtoMember(1)] - public int MapId { get; set; } - [ProtoMember(2)] - public int Type { get; set; } - } - /// - /// 请求进入地图响应 - /// - [ProtoContract] - public partial class Game2C_EnterMapResponse : AMessage, ICustomRouteResponse, IProto - { - public static Game2C_EnterMapResponse Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - ErrorCode = default; - MapId = default; - Pos = default; -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - public uint OpCode() { return OuterOpcode.Game2C_EnterMapResponse; } - [ProtoMember(1)] - public int MapId { get; set; } - [ProtoMember(2)] - public int Pos { get; set; } - [ProtoMember(3)] - public uint ErrorCode { get; set; } - } - /// - /// 请求进入房间 - /// - [ProtoContract] - public partial class C2Game_EnterRoomRequest : AMessage, ICustomRouteRequest, IProto - { - public static C2Game_EnterRoomRequest Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - MapId = default; - Password = default; -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - [ProtoIgnore] - public Game2C_EnterRoomResponse ResponseType { get; set; } - public uint OpCode() { return OuterOpcode.C2Game_EnterRoomRequest; } - [ProtoIgnore] - public int RouteType => Fantasy.RouteType.MapRoute; - [ProtoMember(1)] - public int MapId { get; set; } - [ProtoMember(2)] - public string Password { get; set; } - } - /// - /// 请求进入房间响应 - /// - [ProtoContract] - public partial class Game2C_EnterRoomResponse : AMessage, ICustomRouteResponse, IProto - { - public static Game2C_EnterRoomResponse Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - ErrorCode = default; - MapId = default; - RoomId = default; -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - public uint OpCode() { return OuterOpcode.Game2C_EnterRoomResponse; } - [ProtoMember(1)] - public int MapId { get; set; } - [ProtoMember(2)] - public long RoomId { get; set; } - [ProtoMember(3)] - public uint ErrorCode { get; set; } - } } diff --git a/Entity/Generate/NetworkProtocol/InnerMessage.cs b/Entity/Generate/NetworkProtocol/InnerMessage.cs index e5f64b7..2519fb0 100644 --- a/Entity/Generate/NetworkProtocol/InnerMessage.cs +++ b/Entity/Generate/NetworkProtocol/InnerMessage.cs @@ -56,7 +56,7 @@ namespace Fantasy public override void Dispose() { ErrorCode = default; - RoleRouteId = default; + UnitRouteId = default; RouteType = default; #if FANTASY_NET || FANTASY_UNITY GetScene().MessagePoolComponent.Return(this); @@ -64,7 +64,7 @@ namespace Fantasy } public uint OpCode() { return InnerOpcode.G2Common_EnterResponse; } [ProtoMember(1)] - public long RoleRouteId { get; set; } + public long UnitRouteId { get; set; } [ProtoMember(2)] public int RouteType { get; set; } [ProtoMember(3)] @@ -200,4 +200,57 @@ namespace Fantasy [ProtoMember(1)] public long ChannelId { get; set; } } + /// + /// 请求进入房间 + /// + [ProtoContract] + public partial class G2Map_EnterRoomRequest : AMessage, IRouteRequest, IProto + { + public static G2Map_EnterRoomRequest Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + RoomCode = default; + AccountId = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + [ProtoIgnore] + public Map2G_EnterRoomResponse ResponseType { get; set; } + public uint OpCode() { return InnerOpcode.G2Map_EnterRoomRequest; } + [ProtoMember(1)] + public string RoomCode { get; set; } + [ProtoMember(2)] + public long AccountId { get; set; } + } + /// + /// 请求进入房间响应 + /// + [ProtoContract] + public partial class Map2G_EnterRoomResponse : AMessage, IRouteResponse, IProto + { + public static Map2G_EnterRoomResponse Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + ErrorCode = default; + RoomCode = default; + Units.Clear(); +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + public uint OpCode() { return InnerOpcode.Map2G_EnterRoomResponse; } + [ProtoMember(1)] + public string RoomCode { get; set; } + [ProtoMember(2)] + public List Units = new List(); + [ProtoMember(3)] + public uint ErrorCode { get; set; } + } } diff --git a/Entity/Generate/NetworkProtocol/InnerOpcode.cs b/Entity/Generate/NetworkProtocol/InnerOpcode.cs index 095a392..81c5c0b 100644 --- a/Entity/Generate/NetworkProtocol/InnerOpcode.cs +++ b/Entity/Generate/NetworkProtocol/InnerOpcode.cs @@ -10,5 +10,7 @@ namespace Fantasy public const uint G2S_GetPlayerBasicInfoResponse = 1207969555; public const uint S2G_ChatMessage = 939534097; public const uint Club2Chat_CreateChannel = 939534098; + public const uint G2Map_EnterRoomRequest = 1073751828; + public const uint Map2G_EnterRoomResponse = 1207969556; } } diff --git a/Entity/Generate/NetworkProtocol/MapMessage.cs b/Entity/Generate/NetworkProtocol/MapMessage.cs index c4f45da..9029d73 100644 --- a/Entity/Generate/NetworkProtocol/MapMessage.cs +++ b/Entity/Generate/NetworkProtocol/MapMessage.cs @@ -17,4 +17,152 @@ using Fantasy.Serialize; namespace Fantasy { + /// + /// 请求创建房间 + /// + [ProtoContract] + public partial class C2Map_CreateRoomRequest : AMessage, ICustomRouteRequest, IProto + { + public static C2Map_CreateRoomRequest Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + MapId = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + [ProtoIgnore] + public Map2C_CreateRoomResponse ResponseType { get; set; } + public uint OpCode() { return OuterOpcode.C2Map_CreateRoomRequest; } + [ProtoIgnore] + public int RouteType => Fantasy.RouteType.MapRoute; + [ProtoMember(1)] + public int MapId { get; set; } + } + /// + /// 请求创建房间成功 + /// + [ProtoContract] + public partial class Map2C_CreateRoomResponse : AMessage, ICustomRouteResponse, IProto + { + public static Map2C_CreateRoomResponse Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + ErrorCode = default; + RoomCode = default; + Units.Clear(); +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + public uint OpCode() { return OuterOpcode.Map2C_CreateRoomResponse; } + [ProtoMember(1)] + public string RoomCode { get; set; } + [ProtoMember(2)] + public List Units = new List(); + [ProtoMember(3)] + public uint ErrorCode { get; set; } + } + /// + /// 请求网关进入房间 + /// + [ProtoContract] + public partial class C2G_EnterRoomRequest : AMessage, IRequest, IProto + { + public static C2G_EnterRoomRequest Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + RoomCode = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + [ProtoIgnore] + public G2C_EnterRoomResponse ResponseType { get; set; } + public uint OpCode() { return OuterOpcode.C2G_EnterRoomRequest; } + [ProtoMember(1)] + public string RoomCode { get; set; } + } + /// + /// 请求网关进入房间响应 + /// + [ProtoContract] + public partial class G2C_EnterRoomResponse : AMessage, IResponse, IProto + { + public static G2C_EnterRoomResponse Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + ErrorCode = default; + RoomCode = default; + Units.Clear(); +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + public uint OpCode() { return OuterOpcode.G2C_EnterRoomResponse; } + [ProtoMember(1)] + public string RoomCode { get; set; } + [ProtoMember(2)] + public List Units = new List(); + [ProtoMember(3)] + public uint ErrorCode { get; set; } + } + [ProtoContract] + public partial class C2Map_EnterMapRequest : AMessage, ICustomRouteRequest, IProto + { + public static C2Map_EnterMapRequest Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + MapId = default; + RoomId = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + [ProtoIgnore] + public Map2C_EnterMapResponse ResponseType { get; set; } + public uint OpCode() { return OuterOpcode.C2Map_EnterMapRequest; } + [ProtoIgnore] + public int RouteType => Fantasy.RouteType.MapRoute; + [ProtoMember(1)] + public int MapId { get; set; } + [ProtoMember(2)] + public long RoomId { get; set; } + } + [ProtoContract] + public partial class Map2C_EnterMapResponse : AMessage, ICustomRouteResponse, IProto + { + public static Map2C_EnterMapResponse Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + ErrorCode = default; + MapId = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + public uint OpCode() { return OuterOpcode.Map2C_EnterMapResponse; } + [ProtoMember(1)] + public int MapId { get; set; } + [ProtoMember(2)] + public uint ErrorCode { get; set; } + } } diff --git a/Entity/Generate/NetworkProtocol/MapProtoData.cs b/Entity/Generate/NetworkProtocol/MapProtoData.cs new file mode 100644 index 0000000..d361b08 --- /dev/null +++ b/Entity/Generate/NetworkProtocol/MapProtoData.cs @@ -0,0 +1,234 @@ +using ProtoBuf; + +using System.Collections.Generic; +using MongoDB.Bson.Serialization.Attributes; +using Fantasy; +using Fantasy.Network.Interface; +using Fantasy.Serialize; +// ReSharper disable InconsistentNaming +// ReSharper disable RedundantUsingDirective +// ReSharper disable RedundantOverriddenMember +// ReSharper disable PartialTypeWithSinglePart +// ReSharper disable UnusedAutoPropertyAccessor.Global +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable CheckNamespace +#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type. +#pragma warning disable CS8618 + +namespace Fantasy +{ + [ProtoContract] + public partial class UnitGearItemInfo : AMessage, IProto + { + public static UnitGearItemInfo Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + Id = default; + ConfigId = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + [ProtoMember(1)] + public long Id { get; set; } + [ProtoMember(2)] + public int ConfigId { get; set; } + } + [ProtoContract] + public partial class UnitGearInfo : AMessage, IProto + { + public static UnitGearInfo Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + Rod = default; + Reel = default; + Bobber = default; + Hook = default; + Bait = default; + Lure = default; + Weight = default; + Line = default; + Leader = default; + Feeder = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + [ProtoMember(1)] + public UnitGearItemInfo Rod { get; set; } + [ProtoMember(2)] + public UnitGearItemInfo Reel { get; set; } + [ProtoMember(3)] + public UnitGearItemInfo Bobber { get; set; } + [ProtoMember(4)] + public UnitGearItemInfo Hook { get; set; } + [ProtoMember(5)] + public UnitGearItemInfo Bait { get; set; } + [ProtoMember(6)] + public UnitGearItemInfo Lure { get; set; } + [ProtoMember(7)] + public UnitGearItemInfo Weight { get; set; } + [ProtoMember(8)] + public UnitGearItemInfo Line { get; set; } + [ProtoMember(9)] + public UnitGearItemInfo Leader { get; set; } + [ProtoMember(10)] + public UnitGearItemInfo Feeder { get; set; } + } + [ProtoContract] + public partial class Vector3Info : AMessage, IProto + { + public static Vector3Info Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + x = default; + y = default; + z = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + [ProtoMember(1)] + public float x { get; set; } + [ProtoMember(2)] + public float y { get; set; } + [ProtoMember(3)] + public float z { get; set; } + } + [ProtoContract] + public partial class QuaternionInfo : AMessage, IProto + { + public static QuaternionInfo Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + x = default; + y = default; + z = default; + w = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + [ProtoMember(1)] + public float x { get; set; } + [ProtoMember(2)] + public float y { get; set; } + [ProtoMember(3)] + public float z { get; set; } + [ProtoMember(4)] + public float w { get; set; } + } + [ProtoContract] + public partial class UnitFishingInfo : AMessage, IProto + { + public static UnitFishingInfo Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + LineLength = default; + ReelSpeed = default; + OpenLight = default; + RodSetting = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + [ProtoMember(1)] + public float LineLength { get; set; } + [ProtoMember(2)] + public float ReelSpeed { get; set; } + [ProtoMember(3)] + public bool OpenLight { get; set; } + [ProtoMember(4)] + public int RodSetting { get; set; } + } + [ProtoContract] + public partial class UnitStateInfo : AMessage, IProto + { + public static UnitStateInfo Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + State = default; + Args.Clear(); +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + [ProtoMember(1)] + public int State { get; set; } + [ProtoMember(2)] + public List Args = new List(); + } + [ProtoContract] + public partial class MapUnitInfo : AMessage, IProto + { + public static MapUnitInfo Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + Id = default; + RoleInfo = default; + Location = default; + State = default; + Gears = default; + FishingInfo = default; + KV.Clear(); +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + [ProtoMember(1)] + public long Id { get; set; } + [ProtoMember(2)] + public RoleSimpleInfo RoleInfo { get; set; } + [ProtoMember(3)] + public MapUnitPositionInfo Location { get; set; } + [ProtoMember(4)] + public UnitStateInfo State { get; set; } + [ProtoMember(5)] + public UnitGearInfo Gears { get; set; } + [ProtoMember(6)] + public UnitFishingInfo FishingInfo { get; set; } + [ProtoMember(7)] + public List KV = new List(); + } + [ProtoContract] + public partial class MapUnitPositionInfo : AMessage, IProto + { + public static MapUnitPositionInfo Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + Position = default; + Rotation = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + [ProtoMember(1)] + public Vector3Info Position { get; set; } + [ProtoMember(2)] + public QuaternionInfo Rotation { get; set; } + } +} diff --git a/Entity/Generate/NetworkProtocol/OuterMessage.cs b/Entity/Generate/NetworkProtocol/OuterMessage.cs index 18d4604..cb9c2d8 100644 --- a/Entity/Generate/NetworkProtocol/OuterMessage.cs +++ b/Entity/Generate/NetworkProtocol/OuterMessage.cs @@ -112,50 +112,6 @@ namespace Fantasy public uint ErrorCode { get; set; } } /// - /// 客户端登陆聊天服 - /// - [ProtoContract] - public partial class C2G_LoginChatRequest : AMessage, IProto - { - public static C2G_LoginChatRequest Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - Type = default; -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - [ProtoMember(1)] - public int Type { get; set; } - } - /// - /// 客户端登陆聊天服响应 - /// - [ProtoContract] - public partial class G2C_LoginChatResponse : AMessage, IResponse, IProto - { - public static G2C_LoginChatResponse Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - ErrorCode = default; - RouteId = default; -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - public uint OpCode() { return OuterOpcode.G2C_LoginChatResponse; } - [ProtoMember(1)] - public long RouteId { get; set; } - [ProtoMember(2)] - public uint ErrorCode { get; set; } - } - /// /// 通知客户端重复登录 /// [ProtoContract] diff --git a/Entity/Generate/NetworkProtocol/OuterOpcode.cs b/Entity/Generate/NetworkProtocol/OuterOpcode.cs index 425911b..e380a2c 100644 --- a/Entity/Generate/NetworkProtocol/OuterOpcode.cs +++ b/Entity/Generate/NetworkProtocol/OuterOpcode.cs @@ -2,61 +2,58 @@ namespace Fantasy { public static partial class OuterOpcode { - public const uint C2Game_CreateRoomRequest = 2281711377; - public const uint Game2C_CreateRoomResponse = 2415929105; - public const uint C2Game_EnterMapRequest = 2281711378; - public const uint Game2C_EnterMapResponse = 2415929106; - public const uint C2Game_EnterRoomRequest = 2281711379; - public const uint Game2C_EnterRoomResponse = 2415929107; - public const uint C2A_LoginRequest = 268445457; - public const uint A2C_LoginResponse = 402663185; - public const uint C2G_LoginRequest = 268445458; - public const uint G2C_LoginResponse = 402663186; - public const uint G2C_LoginChatResponse = 402663187; + public const uint C2Map_CreateRoomRequest = 2281711377; + public const uint Map2C_CreateRoomResponse = 2415929105; + public const uint C2G_EnterRoomRequest = 268445457; + public const uint G2C_EnterRoomResponse = 402663185; + public const uint C2Map_EnterMapRequest = 2281711378; + public const uint Map2C_EnterMapResponse = 2415929106; + 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 C2Game_GetRoleInfoRequest = 2281711380; - public const uint Game2C_GetRoleInfoResponse = 2415929108; - public const uint C2Map_EnterRoomRequest = 2281711381; - public const uint Map2C_EnterRoomResponse = 2415929109; - public const uint C2Map_EnterMapRequest = 2281711382; - public const uint Map2C_EnterMapResponse = 2415929110; + public const uint C2Game_GetRoleInfoRequest = 2281711379; + public const uint Game2C_GetRoleInfoResponse = 2415929107; + public const uint C2Map_EnterRoomRequest = 2281711380; + public const uint Map2C_EnterRoomResponse = 2415929108; public const uint C2Map_Move = 2147493649; public const uint Map2C_RoleEnterMapNotify = 2147493650; public const uint Map2C_RoleExitMapNotify = 2147493651; public const uint Map2C_RoleStateNotify = 2147493652; public const uint Map2C_RoleGearStateNotify = 2147493653; public const uint Map2C_RoleGearChangeNotify = 2147493654; - public const uint C2S_GetConversationsRequest = 2281711383; - public const uint S2C_GetConversationsResponse = 2415929111; - public const uint C2S_SendMailRequest = 2281711384; - public const uint S2C_SendMailResponse = 2415929112; - public const uint C2S_DeleteMailRequest = 2281711385; - public const uint S2C_DeleteMailResponse = 2415929113; + public const uint C2S_GetConversationsRequest = 2281711381; + public const uint S2C_GetConversationsResponse = 2415929109; + public const uint C2S_SendMailRequest = 2281711382; + public const uint S2C_SendMailResponse = 2415929110; + public const uint C2S_DeleteMailRequest = 2281711383; + public const uint S2C_DeleteMailResponse = 2415929111; public const uint S2C_HaveMail = 2147493655; public const uint S2C_MailState = 2147493656; - public const uint C2S_CreateChannelRequest = 2281711386; - public const uint S2C_CreateChannelResponse = 2415929114; - public const uint C2S_JoinChannelRequest = 2281711387; - public const uint S2C_JoinChannelResponse = 2415929115; - public const uint C2S_SendMessageRequest = 2281711388; - public const uint S2C_SendMessageResponse = 2415929116; + public const uint C2S_CreateChannelRequest = 2281711384; + public const uint S2C_CreateChannelResponse = 2415929112; + public const uint C2S_JoinChannelRequest = 2281711385; + public const uint S2C_JoinChannelResponse = 2415929113; + public const uint C2S_SendMessageRequest = 2281711386; + public const uint S2C_SendMessageResponse = 2415929114; public const uint S2C_Message = 2147493657; - public const uint C2S_CreateClubRequest = 2281711389; - public const uint S2C_CreateClubResponse = 2415929117; - public const uint C2S_GetClubInfoRequest = 2281711390; - public const uint S2C_GetClubInfoResponse = 2415929118; - public const uint C2S_GetMemberListRequest = 2281711391; - public const uint S2C_GetMemberListResponse = 2415929119; - public const uint C2S_GetClubListRequest = 2281711392; - public const uint S2C_GetClubListResponse = 2415929120; - public const uint C2S_JoinClubRequest = 2281711393; - public const uint S2C_JoinClubResponse = 2415929121; - public const uint C2S_LeaveClubRequest = 2281711394; - public const uint S2C_LeaveClubResponse = 2415929122; - public const uint C2S_DissolveClubRequest = 2281711395; - public const uint S2C_DissolveClubResponse = 2415929123; - public const uint C2S_DisposeJoinRequest = 2281711396; - public const uint S2C_DisposeJoinResponse = 2415929124; + public const uint C2S_CreateClubRequest = 2281711387; + public const uint S2C_CreateClubResponse = 2415929115; + public const uint C2S_GetClubInfoRequest = 2281711388; + public const uint S2C_GetClubInfoResponse = 2415929116; + public const uint C2S_GetMemberListRequest = 2281711389; + public const uint S2C_GetMemberListResponse = 2415929117; + public const uint C2S_GetClubListRequest = 2281711390; + public const uint S2C_GetClubListResponse = 2415929118; + public const uint C2S_JoinClubRequest = 2281711391; + public const uint S2C_JoinClubResponse = 2415929119; + public const uint C2S_LeaveClubRequest = 2281711392; + public const uint S2C_LeaveClubResponse = 2415929120; + public const uint C2S_DissolveClubRequest = 2281711393; + public const uint S2C_DissolveClubResponse = 2415929121; + public const uint C2S_DisposeJoinRequest = 2281711394; + public const uint S2C_DisposeJoinResponse = 2415929122; public const uint S2C_ClubChange = 2147493658; } } diff --git a/Entity/Generate/NetworkProtocol/RoomMessage.cs b/Entity/Generate/NetworkProtocol/RoomMessage.cs index c3d09da..e54e478 100644 --- a/Entity/Generate/NetworkProtocol/RoomMessage.cs +++ b/Entity/Generate/NetworkProtocol/RoomMessage.cs @@ -17,220 +17,6 @@ using Fantasy.Serialize; namespace Fantasy { - [ProtoContract] - public partial class UnitGearItemInfo : AMessage, IProto - { - public static UnitGearItemInfo Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - Id = default; - ConfigId = default; -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - [ProtoMember(1)] - public long Id { get; set; } - [ProtoMember(2)] - public int ConfigId { get; set; } - } - [ProtoContract] - public partial class UnitGearInfo : AMessage, IProto - { - public static UnitGearInfo Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - Rod = default; - Reel = default; - Bobber = default; - Hook = default; - Bait = default; - Lure = default; - Weight = default; - Line = default; - Leader = default; - Feeder = default; -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - [ProtoMember(1)] - public UnitGearItemInfo Rod { get; set; } - [ProtoMember(2)] - public UnitGearItemInfo Reel { get; set; } - [ProtoMember(3)] - public UnitGearItemInfo Bobber { get; set; } - [ProtoMember(4)] - public UnitGearItemInfo Hook { get; set; } - [ProtoMember(5)] - public UnitGearItemInfo Bait { get; set; } - [ProtoMember(6)] - public UnitGearItemInfo Lure { get; set; } - [ProtoMember(7)] - public UnitGearItemInfo Weight { get; set; } - [ProtoMember(8)] - public UnitGearItemInfo Line { get; set; } - [ProtoMember(9)] - public UnitGearItemInfo Leader { get; set; } - [ProtoMember(10)] - public UnitGearItemInfo Feeder { get; set; } - } - [ProtoContract] - public partial class Vector3Info : AMessage, IProto - { - public static Vector3Info Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - x = default; - y = default; - z = default; -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - [ProtoMember(1)] - public float x { get; set; } - [ProtoMember(2)] - public float y { get; set; } - [ProtoMember(3)] - public float z { get; set; } - } - [ProtoContract] - public partial class QuaternionInfo : AMessage, IProto - { - public static QuaternionInfo Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - x = default; - y = default; - z = default; - w = default; -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - [ProtoMember(1)] - public float x { get; set; } - [ProtoMember(2)] - public float y { get; set; } - [ProtoMember(3)] - public float z { get; set; } - [ProtoMember(4)] - public float w { get; set; } - } - [ProtoContract] - public partial class UnitFishingInfo : AMessage, IProto - { - public static UnitFishingInfo Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - LineLength = default; - ReelSpeed = default; - OpenLight = default; - RodSetting = default; -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - [ProtoMember(1)] - public float LineLength { get; set; } - [ProtoMember(2)] - public float ReelSpeed { get; set; } - [ProtoMember(3)] - public bool OpenLight { get; set; } - [ProtoMember(4)] - public int RodSetting { get; set; } - } - [ProtoContract] - public partial class UnitStateInfo : AMessage, IProto - { - public static UnitStateInfo Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - State = default; - Args.Clear(); -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - [ProtoMember(1)] - public int State { get; set; } - [ProtoMember(2)] - public List Args = new List(); - } - [ProtoContract] - public partial class MapUnitInfo : AMessage, IProto - { - public static MapUnitInfo Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - Id = default; - RoleInfo = default; - Location = default; - State = default; - Gears = default; - FishingInfo = default; - KV.Clear(); -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - [ProtoMember(1)] - public long Id { get; set; } - [ProtoMember(2)] - public RoleSimpleInfo RoleInfo { get; set; } - [ProtoMember(3)] - public MapUnitPositionInfo Location { get; set; } - [ProtoMember(4)] - public UnitStateInfo State { get; set; } - [ProtoMember(5)] - public UnitGearInfo Gears { get; set; } - [ProtoMember(6)] - public UnitFishingInfo FishingInfo { get; set; } - [ProtoMember(7)] - public List KV = new List(); - } - [ProtoContract] - public partial class MapUnitPositionInfo : AMessage, IProto - { - public static MapUnitPositionInfo Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - Position = default; - Rotation = default; -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - [ProtoMember(1)] - public Vector3Info Position { get; set; } - [ProtoMember(2)] - public QuaternionInfo Rotation { get; set; } - } [ProtoContract] public partial class C2Map_EnterRoomRequest : AMessage, ICustomRouteRequest, IProto { @@ -281,55 +67,6 @@ namespace Fantasy public uint ErrorCode { get; set; } } [ProtoContract] - public partial class C2Map_EnterMapRequest : AMessage, ICustomRouteRequest, IProto - { - public static C2Map_EnterMapRequest Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - MapId = default; - RoomId = default; -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - [ProtoIgnore] - public Map2C_EnterMapResponse ResponseType { get; set; } - public uint OpCode() { return OuterOpcode.C2Map_EnterMapRequest; } - [ProtoIgnore] - public int RouteType => Fantasy.RouteType.MapRoute; - [ProtoMember(1)] - public int MapId { get; set; } - [ProtoMember(2)] - public long RoomId { get; set; } - } - [ProtoContract] - public partial class Map2C_EnterMapResponse : AMessage, ICustomRouteResponse, IProto - { - public static Map2C_EnterMapResponse Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - ErrorCode = default; - Roles.Clear(); - MapId = default; -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - public uint OpCode() { return OuterOpcode.Map2C_EnterMapResponse; } - [ProtoMember(1)] - public List Roles = new List(); - [ProtoMember(2)] - public long MapId { get; set; } - [ProtoMember(3)] - public uint ErrorCode { get; set; } - } - [ProtoContract] public partial class C2Map_Move : AMessage, ICustomRouteMessage, IProto { public static C2Map_Move Create(Scene scene) diff --git a/Entity/Map/Component/MapManageComponent.cs b/Entity/Map/Component/MapManageComponent.cs new file mode 100644 index 0000000..0af5b52 --- /dev/null +++ b/Entity/Map/Component/MapManageComponent.cs @@ -0,0 +1,8 @@ +using Fantasy.Entitas; + +namespace NB.Map; + +public class MapManageComponent: Entity +{ + public readonly Dictionary Maps = new(); +} \ No newline at end of file diff --git a/Entity/Map/Component/MapUnitManageComponent.cs b/Entity/Map/Component/MapUnitManageComponent.cs new file mode 100644 index 0000000..260efe6 --- /dev/null +++ b/Entity/Map/Component/MapUnitManageComponent.cs @@ -0,0 +1,8 @@ +using Fantasy.Entitas; + +namespace NB.Map; + +public class MapUnitManageComponent : Entity +{ + public readonly Dictionary Units = new(); +} \ No newline at end of file diff --git a/Entity/Map/Component/RoomManageComponent.cs b/Entity/Map/Component/RoomManageComponent.cs new file mode 100644 index 0000000..84bc787 --- /dev/null +++ b/Entity/Map/Component/RoomManageComponent.cs @@ -0,0 +1,11 @@ +using Fantasy.Entitas; + +namespace NB.Map; + +public class RoomManageComponent : Entity +{ + public readonly Dictionary Rooms = new(); + + public readonly PriorityQueue FreeIds = new(); + public readonly HashSet InUseID = new(); +} \ No newline at end of file diff --git a/Entity/Map/Entity/Map.cs b/Entity/Map/Entity/Map.cs new file mode 100644 index 0000000..0a2046e --- /dev/null +++ b/Entity/Map/Entity/Map.cs @@ -0,0 +1,7 @@ +using Fantasy.Entitas; + +namespace NB.Map; + +public class Map : Entity +{ +} \ No newline at end of file diff --git a/Entity/Map/MapRoom.cs b/Entity/Map/Entity/MapRoom.cs similarity index 69% rename from Entity/Map/MapRoom.cs rename to Entity/Map/Entity/MapRoom.cs index a088240..adaf556 100644 --- a/Entity/Map/MapRoom.cs +++ b/Entity/Map/Entity/MapRoom.cs @@ -1,4 +1,5 @@ using Fantasy.Entitas; +using NB.Map; namespace NB.Map; @@ -7,10 +8,20 @@ namespace NB.Map; /// public class MapRoom : Entity { + /// + /// 房间序号id + /// + public int RoomId; + + /// + /// 房间代码 + /// + public string Code = string.Empty; + /// /// 房间密码 /// - public string Password; + public string Password = string.Empty; /// /// 房间玩家 diff --git a/Entity/Map/MapUnit.cs b/Entity/Map/Entity/MapUnit.cs similarity index 60% rename from Entity/Map/MapUnit.cs rename to Entity/Map/Entity/MapUnit.cs index faa74a1..edf10b7 100644 --- a/Entity/Map/MapUnit.cs +++ b/Entity/Map/Entity/MapUnit.cs @@ -17,4 +17,16 @@ public class MapUnit : Entity /// 旋转 /// public float4 Rotation; + + /// + /// 当前所在地图id + /// + public int MapId; + + /// + /// 当前所在房间id + /// + public int RoomId; + + public long GateRouteId; } \ No newline at end of file diff --git a/Entity/Model/Def/ErrorCode.cs b/Entity/Model/Def/ErrorCode.cs index 636a0f8..d57c45b 100644 --- a/Entity/Model/Def/ErrorCode.cs +++ b/Entity/Model/Def/ErrorCode.cs @@ -49,4 +49,24 @@ public class ErrorCode /// 没回复前不能再发消息 /// public const uint MailNotReply = 12021; + + /// + /// 创建房间失败,不在地图中 + /// + public const uint MapCreateRoomNotEnter = 13001; + + /// + /// 创建房间失败,房间数量超限 + /// + public const uint MapCreateRoomMax = 13002; + + /// + /// 房间id 错误 + /// + public const uint MapRoomIdError = 13003; + + /// + /// 已在房间,不能加入另一个 + /// + public const uint MapRoomHave = 13004; } \ No newline at end of file diff --git a/Hotfix/Common/Handler/G2Common_EnterRequestHandler.cs b/Hotfix/Common/Handler/G2Common_EnterRequestHandler.cs index 42c5e96..7aa9c4e 100644 --- a/Hotfix/Common/Handler/G2Common_EnterRequestHandler.cs +++ b/Hotfix/Common/Handler/G2Common_EnterRequestHandler.cs @@ -3,6 +3,7 @@ using Fantasy.Async; using Fantasy.Network.Interface; using NB.Chat; using NB.Game; +using NB.Map; namespace NB.Common; @@ -28,6 +29,7 @@ public class G2Common_EnterRequestHandler : RouteRPC(); - var account = await gameAccountManageComponent.Online(scene, request.AccountId, request.GateRouteId); + var account = await gameAccountManageComponent.Online(request.AccountId, request.GateRouteId); if (account == null) { response.ErrorCode = ErrorCode.ErrServer; return; } - response.RoleRouteId = account.RuntimeId; + response.UnitRouteId = account.RuntimeId; + Log.Info($"登录到游戏服成功,id={response.UnitRouteId}"); } private async FTask RunSocial(Scene scene, G2Common_EnterRequest request, G2Common_EnterResponse response) @@ -61,6 +64,23 @@ public class G2Common_EnterRequestHandler : RouteRPC(); + var account = await chatUnitManageComponent.Online(scene, request.AccountId, request.GateRouteId); + + if (account == null) + { + response.ErrorCode = ErrorCode.ErrServer; + return; + } + + response.UnitRouteId = account.RuntimeId; + Log.Info($"登录到地图服成功,id={response.UnitRouteId}"); } } \ No newline at end of file diff --git a/Hotfix/Common/Handler/G2Common_ExitRequestHandler.cs b/Hotfix/Common/Handler/G2Common_ExitRequestHandler.cs index 15b8568..6bb6aff 100644 --- a/Hotfix/Common/Handler/G2Common_ExitRequestHandler.cs +++ b/Hotfix/Common/Handler/G2Common_ExitRequestHandler.cs @@ -2,6 +2,8 @@ using Fantasy.Async; using Fantasy.Network.Interface; using NB.Chat; +using NB.Game; +using NB.Map; namespace NB.Common; @@ -25,6 +27,7 @@ public class G2Common_ExitRequestHandler : RouteRPC(); - // var account = await gameAccountManageComponent.Online(scene, request.AccountId, request.GateRouteId); - // if (account == null) - // { - // response.ErrorCode = ErrorCode.ErrServer; - // return; - // } - // - // response.RoleRouteId = account.RuntimeId; + // 在缓存中检查该账号是否存在 + var gameAccountManageComponent = scene.GetComponent(); + await gameAccountManageComponent.Offline(request.AccountId, request.GateRouteId); + Log.Info("退出游戏服成功=="); } private async FTask RunSocial(Scene scene, G2Common_ExitRequest request, Common2G_ExitResponse response) @@ -51,5 +48,14 @@ public class G2Common_ExitRequestHandler : RouteRPC(); await chatUnitManageComponent.Offline(scene, request.AccountId, request.GateRouteId); + Log.Info("退出聊天服成功=="); + } + + private async FTask RunMap(Scene scene, G2Common_ExitRequest request, Common2G_ExitResponse response) + { + // 在缓存中检查该账号是否存在 + var chatUnitManageComponent = scene.GetComponent(); + await chatUnitManageComponent.Offline(scene, request.AccountId, request.GateRouteId); + Log.Info("退出房间服成功=="); } } \ No newline at end of file diff --git a/Hotfix/Common/Helper/SceneConfigHelper.cs b/Hotfix/Common/Helper/SceneConfigHelper.cs index e12cb8d..f7f55c3 100644 --- a/Hotfix/Common/Helper/SceneConfigHelper.cs +++ b/Hotfix/Common/Helper/SceneConfigHelper.cs @@ -3,12 +3,38 @@ using Fantasy.Platform.Net; namespace NB.Common; -public class SceneConfigHelper +public static class SceneConfigHelper { + public static SceneConfig GetConfigByRouteType(int routeType) + { + var sceneType = SceneType.Game; + if (routeType == RouteType.GameRoute) + { + sceneType = SceneType.Game; + } + else if (routeType == RouteType.SocialRoute) + { + sceneType = SceneType.Social; + } + else if (routeType == RouteType.MapRoute) + { + sceneType = SceneType.Map; + } + else if (routeType == RouteType.GateRoute) + { + sceneType = SceneType.Gate; + } + + return GetConfig(sceneType); + } + public static SceneConfig GetConfig(int sceneType) { + var gameSceneConfigs = SceneConfigData.Instance.GetSceneBySceneType(sceneType); return gameSceneConfigs.First(); } + + } \ No newline at end of file diff --git a/Hotfix/Game/Handler/G2Game_EnterRequestHandler.cs b/Hotfix/Game/Handler/G2Game_EnterRequestHandler.cs deleted file mode 100644 index d1033f8..0000000 --- a/Hotfix/Game/Handler/G2Game_EnterRequestHandler.cs +++ /dev/null @@ -1,29 +0,0 @@ -// using Fantasy; -// using Fantasy.Async; -// using Fantasy.Entitas; -// using Fantasy.Helper; -// using Fantasy.Network; -// using Fantasy.Network.Interface; -// using NB; -// using NB.Gate; -// -// namespace NB.Game; -// -// public class G2Game_EnterRequestHandler : RouteRPC -// { -// protected override async FTask Run(Scene scene, G2Game_EnterRequest request, Game2G_EnterResponse response, -// Action reply) -// { -// Log.Debug("收到 G2Game_EnterRequestHandler"); -// -// -// // 在缓存中检查该账号是否存在 -// var gameAccountManageComponent = scene.GetComponent(); -// -// var account = await gameAccountManageComponent.Online(scene, request.AccountId, request.GateRouteId); -// -// response.RoleRouteId = account.RuntimeId; -// response.RoleInfo = account.GetRoleSimpleInfo(); -// await FTask.CompletedTask; -// } -// } \ No newline at end of file diff --git a/Hotfix/Game/Player/Components/PlayerManageComponentSystem.cs b/Hotfix/Game/Player/Components/PlayerManageComponentSystem.cs index d94b893..cb411db 100644 --- a/Hotfix/Game/Player/Components/PlayerManageComponentSystem.cs +++ b/Hotfix/Game/Player/Components/PlayerManageComponentSystem.cs @@ -40,24 +40,22 @@ public static class PlayerManageComponentSystem /// 玩家上线 /// /// - /// /// /// - public static async FTask Online(this PlayerManageComponent self, Scene scene, long accountId, - long gateRouteId) + public static async FTask Online(this PlayerManageComponent self, long accountId, long gateRouteId) { Log.Debug("检查账号是否在缓存中"); if (!self.TryGet(accountId, out var account)) { // 首先要先到数据库中查询是否有这个账号 - account = await PlayerHelper.LoadDataBase(scene, accountId); + account = await PlayerHelper.LoadDataBase(self.Scene, accountId); // 如果有的话,就直接加入在缓存中就可以了 if (account == null) { Log.Debug("检查到账号没有在数据库中,需要创建一个新的账号并且保存到数据库中"); // 如果没有,就要创建一个新的并且保存到数据库。 // 如果不存在,表示这是一个新的账号,需要创建一下这个账号。 - account = PlayerFactory.Create(scene, accountId); + account = PlayerFactory.Create(self.Scene, accountId); account.Level = 99; @@ -111,6 +109,19 @@ public static class PlayerManageComponentSystem return account; } + public static async FTask Offline(this PlayerManageComponent self, long accountId, long sessionId) + { + if (self.TryGet(accountId, out var account)) + { + if (account.SessionRunTimeId == sessionId) + { + //退出的是当前的 + await account.Save(); + self.Remove(accountId); + } + } + } + #endregion #region 获取&移除 diff --git a/Hotfix/Gate/Handler/Outer/C2G_EnterRoomRequestHandler.cs b/Hotfix/Gate/Handler/Outer/C2G_EnterRoomRequestHandler.cs new file mode 100644 index 0000000..bd56c76 --- /dev/null +++ b/Hotfix/Gate/Handler/Outer/C2G_EnterRoomRequestHandler.cs @@ -0,0 +1,63 @@ +using Fantasy; +using Fantasy.Async; +using Fantasy.Network; +using Fantasy.Network.Interface; +using Fantasy.Platform.Net; +using NB.Common; +using NB.Map; + +namespace NB.Gate.Handler; + +public class C2G_EnterRoomRequestHandler : MessageRPC +{ + protected override async FTask Run(Session session, C2G_EnterRoomRequest request, G2C_EnterRoomResponse response, + Action reply) + { + if (string.IsNullOrEmpty(request.RoomCode)) + { + response.ErrorCode = ErrorCode.MapRoomIdError; + return; + } + + var gateUnitSessionComponent = session.GetComponent(); + if (gateUnitSessionComponent == null) + { + response.ErrorCode = ErrorCode.ErrServer; + return; + } + + // 在缓存中检查该账号是否存在 + var gateUnitManageComponent = session.Scene.GetComponent(); + if (gateUnitManageComponent == null) + { + response.ErrorCode = ErrorCode.ErrServer; + return; + } + + var gateUnit = gateUnitManageComponent.Get(gateUnitSessionComponent.AccountID); + if (gateUnit == null) + { + response.ErrorCode = ErrorCode.ErrServer; + return; + } + + RoomHelper.ParseCode(request.RoomCode, out var serviceId, out var roomId); + if (serviceId < 1 || roomId < 1) + { + response.ErrorCode = ErrorCode.MapRoomIdError; + return; + } + + var sceneConfig = SceneConfigData.Instance.Get(serviceId); + if (sceneConfig == null) + { + response.ErrorCode = ErrorCode.MapRoomIdError; + return; + } + + //先判断是否需要更好地图服务器 + var mapRouteId = gateUnit.GetAddress(RouteType.MapRoute); + + //执行进入房间操作 + } +} \ No newline at end of file diff --git a/Hotfix/Gate/Handler/Outer/C2G_LoginRequestHandler.cs b/Hotfix/Gate/Handler/Outer/C2G_LoginRequestHandler.cs index d18b09f..7e77b22 100644 --- a/Hotfix/Gate/Handler/Outer/C2G_LoginRequestHandler.cs +++ b/Hotfix/Gate/Handler/Outer/C2G_LoginRequestHandler.cs @@ -5,7 +5,7 @@ using Fantasy.Network.Interface; using Fantasy.Platform.Net; using NB.Game; -namespace NB.Gate.Handler; +namespace NB.Gate; public sealed class C2G_LoginRequestHandler : MessageRPC { diff --git a/Hotfix/Gate/System/GateUnitSystem.cs b/Hotfix/Gate/System/GateUnitSystem.cs index b9d6757..6bbcc1e 100644 --- a/Hotfix/Gate/System/GateUnitSystem.cs +++ b/Hotfix/Gate/System/GateUnitSystem.cs @@ -21,7 +21,7 @@ public static class GateUnitSystem { #region Address - private static void RemoveAddress(this GateUnit self, int routType, long routeId) + public static void RemoveAddress(this GateUnit self, int routType, long routeId) { if (self.SceneRoutes.TryGetValue(routType, out var route)) { @@ -32,12 +32,12 @@ public static class GateUnitSystem } } - private static void AddAddress(this GateUnit self, int routType, long routeId) + public static void AddAddress(this GateUnit self, int routType, long routeId) { self.SceneRoutes[routType] = routeId; } - private static long GetAddress(this GateUnit self, int routType) + public static long GetAddress(this GateUnit self, int routType) { return self.SceneRoutes.GetValueOrDefault(routType, 0); } @@ -69,10 +69,10 @@ public static class GateUnitSystem { routeComponent = session.AddComponent(); } - - var gameSceneConfig = SceneConfigHelper.GetConfig(routeType); + + var gameSceneConfig = SceneConfigHelper.GetConfigByRouteType(routeType); var gameRouteId = gameSceneConfig.RouteId; - //连接到游戏中心服 + var gameResponse = (G2Common_EnterResponse)await self.Scene.NetworkMessagingComponent.CallInnerRoute( gameRouteId, new G2Common_EnterRequest() { @@ -85,8 +85,8 @@ public static class GateUnitSystem return gameResponse.ErrorCode; } - routeComponent.AddAddress(routeType, gameRouteId); - self.AddAddress(routeType, gameRouteId); + routeComponent.AddAddress(routeType, gameResponse.UnitRouteId); + self.AddAddress(routeType, gameResponse.UnitRouteId); return ErrorCode.Successful; } diff --git a/Hotfix/Hotfix.csproj b/Hotfix/Hotfix.csproj index 34e133c..8ccc1aa 100644 --- a/Hotfix/Hotfix.csproj +++ b/Hotfix/Hotfix.csproj @@ -13,10 +13,8 @@ + - - - diff --git a/Hotfix/Map/Handler/C2Map_CreateRoomRequestHandler.cs b/Hotfix/Map/Handler/C2Map_CreateRoomRequestHandler.cs index 6295c17..3d60f11 100644 --- a/Hotfix/Map/Handler/C2Map_CreateRoomRequestHandler.cs +++ b/Hotfix/Map/Handler/C2Map_CreateRoomRequestHandler.cs @@ -1,15 +1,44 @@ -// using Fantasy; -// using Fantasy.Async; -// using Fantasy.Network.Interface; -// -// namespace NB.Map; -// -// public class C2Map_CreateRoomRequestHandler : RouteRPC -// { -// protected override async FTask Run(Scene entity, C2Map_CreateRoomRequest request, Map2C_CreateRoomResponse response, -// Action reply) -// { -// Log.Info($"创建房间=== map:{request.MapId} pass:{request.Password}"); -// await FTask.CompletedTask; -// } -// } \ No newline at end of file +using Fantasy; +using Fantasy.Async; +using Fantasy.Entitas; +using Fantasy.Network.Interface; + +namespace NB.Map; + +public class C2Map_CreateRoomRequestHandler : RouteRPC +{ + protected override async FTask Run(MapUnit entity, C2Map_CreateRoomRequest request, + Map2C_CreateRoomResponse response, + Action reply) + { + if (entity.MapId != request.MapId) + { + response.ErrorCode = ErrorCode.MapCreateRoomNotEnter; + return; + } + + var roomManageComponent = entity.Scene.GetComponent(); + if (roomManageComponent == null) + { + response.ErrorCode = ErrorCode.ErrServer; + return; + } + + var roomId = roomManageComponent.AllocateId(); + if (roomId < 1) + { + response.ErrorCode = ErrorCode.MapCreateRoomMax; + return; + } + + // roomManageComponent.on + var room = Entity.Create(entity.Scene, true, true); + room.Owner = entity.Id; + room.RoomId = roomId; + room.Code = RoomHelper.GenerateCode(entity.Scene.SceneConfigId, roomId); + roomManageComponent.Add(room); + Log.Info( + $"创建房间=== sId={entity.Scene.SceneConfigId} map:{request.MapId} id={room.RoomId} code={room.Code}"); + await FTask.CompletedTask; + } +} \ No newline at end of file diff --git a/Hotfix/Map/Handler/C2Map_EnterMapRequestHandler.cs b/Hotfix/Map/Handler/C2Map_EnterMapRequestHandler.cs new file mode 100644 index 0000000..ba49003 --- /dev/null +++ b/Hotfix/Map/Handler/C2Map_EnterMapRequestHandler.cs @@ -0,0 +1,33 @@ +using Fantasy; +using Fantasy.Async; +using Fantasy.Network.Interface; + +namespace NB.Map; + +public class C2Map_EnterMapRequestHandler : RouteRPC +{ + protected override async FTask Run(MapUnit entity, C2Map_EnterMapRequest request, Map2C_EnterMapResponse response, + Action reply) + { + var roomManageComponent = entity.Scene.GetComponent(); + if (roomManageComponent == null) + { + response.ErrorCode = ErrorCode.ErrServer; + return; + } + + // if (entity.RoomId > 0) + // { + // response.ErrorCode = ErrorCode.MapRoomHave; + // return; + // } + // + // roomManageComponent.Enter(entity, request.RoomId); + + Log.Info($"进入地图=== map:{request.MapId}"); + entity.MapId = request.MapId; + response.MapId = request.MapId; + + await FTask.CompletedTask; + } +} \ No newline at end of file diff --git a/Hotfix/Map/Handler/Inner/G2Map_EnterRequestHandler.cs b/Hotfix/Map/Handler/Inner/G2Map_EnterRequestHandler.cs new file mode 100644 index 0000000..eeb03a6 --- /dev/null +++ b/Hotfix/Map/Handler/Inner/G2Map_EnterRequestHandler.cs @@ -0,0 +1,27 @@ +using Fantasy; +using Fantasy.Async; +using Fantasy.Network.Interface; + +namespace NB.Map.Inner; + +public class G2Map_EnterRequestHandler : RouteRPC +{ + protected override async FTask Run(Scene entity, G2Map_EnterRoomRequest request, Map2G_EnterRoomResponse response, + Action reply) + { + var roomManageComponent = entity.GetComponent(); + if (roomManageComponent == null) + { + response.ErrorCode = ErrorCode.ErrServer; + return; + } + + RoomHelper.ParseCode(request.RoomCode, out var serviceId, out var roomId); + if (serviceId < 1 || roomId < 1) + { + response.ErrorCode = ErrorCode.MapRoomIdError; + return; + } + // roomManageComponent.Enter(); + } +} \ No newline at end of file diff --git a/Hotfix/Map/Helper/MapUnitFactory.cs b/Hotfix/Map/Helper/MapUnitFactory.cs new file mode 100644 index 0000000..7d7f980 --- /dev/null +++ b/Hotfix/Map/Helper/MapUnitFactory.cs @@ -0,0 +1,19 @@ +using Fantasy; +using Fantasy.Entitas; + +namespace NB.Map; + +public static class MapUnitFactory +{ + /// + /// 创建一个新的Player + /// + /// + /// ToKen令牌传递过来的aId + /// + public static MapUnit Create(Scene scene, long aId) + { + var player = Entity.Create(scene, aId, true, true); + return player; + } +} \ No newline at end of file diff --git a/Hotfix/Map/Helper/RoomHelper.cs b/Hotfix/Map/Helper/RoomHelper.cs new file mode 100644 index 0000000..cf6f85b --- /dev/null +++ b/Hotfix/Map/Helper/RoomHelper.cs @@ -0,0 +1,69 @@ +using System.Text; + +namespace NB.Map; + +public static class RoomHelper +{ + #region 房间id + + private const string Base36Chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + private const int RoomSeqBits = 16; // 每个服务最多 65535 个房间 + + /// + /// 生成房间码(固定5位) + /// + /// + /// + /// + public static string GenerateCode(uint serviceId, int roomSeq) + { + long packed = ((long)serviceId << RoomSeqBits) | (uint)roomSeq; + string code = EncodeBase36(packed); + + // 固定5位,不够左侧补0 + return code.PadLeft(5, '0'); + } + + /// + /// 解析房间码 + /// + /// + /// + /// + public static void ParseCode(string code, out uint serviceId, out int roomSeq) + { + long packed = DecodeBase36(code); + roomSeq = (int)(packed & ((1 << RoomSeqBits) - 1)); + serviceId = (uint)(packed >> RoomSeqBits); + } + + private static string EncodeBase36(long value) + { + if (value == 0) return "0"; + StringBuilder sb = new StringBuilder(); + while (value > 0) + { + int remainder = (int)(value % 36); + sb.Insert(0, Base36Chars[remainder]); + value /= 36; + } + + return sb.ToString(); + } + + private static long DecodeBase36(string str) + { + long result = 0; + foreach (char c in str) + { + int val = Base36Chars.IndexOf(c); + if (val < 0) throw new ArgumentException("Invalid Base36 character: " + c); + result = result * 36 + val; + } + + return result; + } + + #endregion + +} \ No newline at end of file diff --git a/Hotfix/Map/System/MapRoomSystem.cs b/Hotfix/Map/System/MapRoomSystem.cs new file mode 100644 index 0000000..2b4cdfb --- /dev/null +++ b/Hotfix/Map/System/MapRoomSystem.cs @@ -0,0 +1,19 @@ +using Fantasy.Entitas.Interface; + +namespace NB.Map; + +public class MapRoomDestroySystem : DestroySystem +{ + protected override void Destroy(MapRoom self) + { + self.Map = 0; + self.Password = string.Empty; + self.CreateTime = 0; + self.Owner = 0; + self.Units.Clear(); + } +} + +public static class MapRoomSystem +{ +} \ No newline at end of file diff --git a/Hotfix/Map/System/MapUnitManageComponentSystem.cs b/Hotfix/Map/System/MapUnitManageComponentSystem.cs new file mode 100644 index 0000000..72af0a0 --- /dev/null +++ b/Hotfix/Map/System/MapUnitManageComponentSystem.cs @@ -0,0 +1,84 @@ +using Fantasy; +using Fantasy.Async; + +namespace NB.Map; + +public static class MapUnitManageComponentSystem +{ + #region 上线下线 + + /// + /// 玩家上线 + /// + /// + /// + /// + /// + public static async FTask Online(this MapUnitManageComponent self, Scene scene, + long accountId, + long gateRouteId) + { + if (!self.TryGet(accountId, out var unit)) + { + unit = MapUnitFactory.Create(scene, accountId); + self.Add(unit); + } + + if (unit != null) + { + unit.GateRouteId = gateRouteId; + } + + await FTask.CompletedTask; + return unit; + } + + public static async FTask Offline(this MapUnitManageComponent self, Scene scene, long accountId, long gateRouteId) + { + if (self.TryGet(accountId, out var unit) && unit != null) + { + if (unit.GateRouteId == gateRouteId) + { + self.Remove(accountId); //如果当前网关和下线的网关一致 + } + } + + await FTask.CompletedTask; + } + + #endregion + + #region 获取&移除 + + public static void Add(this MapUnitManageComponent self, MapUnit unit) + { + self.Units.Add(unit.Id, unit); + } + + public static MapUnit? Get(this MapUnitManageComponent self, long accountId) + { + return self.Units.GetValueOrDefault(accountId); + } + + public static bool TryGet(this MapUnitManageComponent self, long accountId, out MapUnit? unit) + { + return self.Units.TryGetValue(accountId, out unit); + } + + public static void Remove(this MapUnitManageComponent self, long accountId, bool isDispose = true) + { + if (!self.Units.Remove(accountId, out var account)) + { + return; + } + + if (!isDispose) + { + return; + } + + account.Dispose(); + } + + #endregion +} \ No newline at end of file diff --git a/Hotfix/Map/System/RoomManageComponentSystem.cs b/Hotfix/Map/System/RoomManageComponentSystem.cs new file mode 100644 index 0000000..d759524 --- /dev/null +++ b/Hotfix/Map/System/RoomManageComponentSystem.cs @@ -0,0 +1,93 @@ +using Fantasy.Entitas; +using Fantasy.Entitas.Interface; + +namespace NB.Map; + +public class RoomManageComponentAwakeSystem : AwakeSystem +{ + protected override void Awake(RoomManageComponent self) + { + for (int i = 1; i <= 65535; i++) + { + self.FreeIds.Enqueue(i, i); + } + } +} + +public class RoomManageComponentDestroySystem : DestroySystem +{ + protected override void Destroy(RoomManageComponent self) + { + foreach (var (_, room) in self.Rooms) + { + room.Dispose(); + } + + self.Rooms.Clear(); + } +} + +public static class RoomManageComponentSystem +{ + #region 增删 + + public static void Add(this RoomManageComponent self, MapRoom room) + { + self.Rooms[room.RoomId] = room; + } + + public static bool Remove(this RoomManageComponent self, int roomId) + { + if (self.Rooms.TryGetValue(roomId, out var room)) + { + self.ReleaseId(room.RoomId); + room.Dispose(); + } + + return true; + } + + #endregion + + #region 房间Id + + /// + /// 分配一个新的房间ID + /// + /// + /// + public static int AllocateId(this RoomManageComponent self) + { + if (self.FreeIds.Count == 0) return 0; + int id = self.FreeIds.Dequeue(); + self.InUseID.Add(id); + return id; + } + + /// + /// 释放房间ID + /// + /// + /// + public static void ReleaseId(this RoomManageComponent self, int id) + { + if (self.InUseID.Remove(id)) + { + self.FreeIds.Enqueue(id, id); + } + } + + #endregion + + #region 进入退出 + + public static void Enter(this RoomManageComponent self, MapUnit unit, long roomId) + { + } + + public static void Exit(this RoomManageComponent self, MapUnit unit) + { + } + + #endregion +} \ No newline at end of file diff --git a/Hotfix/OnCreateSceneEvent.cs b/Hotfix/OnCreateSceneEvent.cs index 7322027..82d262e 100644 --- a/Hotfix/OnCreateSceneEvent.cs +++ b/Hotfix/OnCreateSceneEvent.cs @@ -6,6 +6,7 @@ using Fantasy.Event; using Fantasy.Helper; using Fantasy.Serialize; using NB.Game; +using NB.Map; using ProtoBuf; namespace NB; @@ -66,6 +67,14 @@ public sealed class OnCreateSceneEvent : AsyncEventSystem case SceneType.Map: { Log.Debug($"Map Scene SceneRuntimeId:{scene.RuntimeId}"); + // uint serverId = 25255; + // for (int i = 1; i < 65535; i++) + // { + // var roomId = RoomHelper.GenerateCode(serverId, i); + // RoomHelper.ParseCode(roomId, out var pId, out var rId); + // Log.Info($"生成id测试,房间id={roomId} 原始服务id:{serverId} 原始房间id={i} 解析={pId} {rId}"); + // } + break; } case SceneType.Social: @@ -74,7 +83,6 @@ public sealed class OnCreateSceneEvent : AsyncEventSystem } case SceneType.Game: { - // // Begins transaction // using (var session = mongoClient.StartSession()) // { @@ -131,8 +139,8 @@ public sealed class OnCreateSceneEvent : AsyncEventSystem // // stopwatch.Stop(); // Log.Info($"创建100个号入库耗时={stopwatch.ElapsedMilliseconds}ms"); - - + + break; } case SceneType.Gate: diff --git a/Hotfix/OnSceneCreate_Init.cs b/Hotfix/OnSceneCreate_Init.cs index 4206cff..25f9913 100644 --- a/Hotfix/OnSceneCreate_Init.cs +++ b/Hotfix/OnSceneCreate_Init.cs @@ -5,6 +5,7 @@ using NB.Authentication; using NB.Chat; using NB.Game; using NB.Gate; +using NB.Map; namespace NB; @@ -50,6 +51,9 @@ public class OnSceneCreate_Init : AsyncEventSystem case SceneType.Map: { Log.Info("创建地图场景==="); + scene.AddComponent(); + scene.AddComponent(); + scene.AddComponent(); break; } } diff --git a/Main/Properties/launchSettings.json b/Main/Properties/launchSettings.json index cd8b993..b30e999 100644 --- a/Main/Properties/launchSettings.json +++ b/Main/Properties/launchSettings.json @@ -7,4 +7,4 @@ "commandLineArgs": "--m Develop" } } -} +} \ No newline at end of file diff --git a/Server.sln.DotSettings.user b/Server.sln.DotSettings.user index b23042f..3d97d67 100644 --- a/Server.sln.DotSettings.user +++ b/Server.sln.DotSettings.user @@ -16,6 +16,7 @@ ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded @@ -55,6 +56,7 @@ ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded @@ -66,6 +68,7 @@ ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded