新增相关协议

This commit is contained in:
2025-08-26 18:03:52 +08:00
parent e0665aae01
commit 7325e268ce
36 changed files with 1402 additions and 1085 deletions

View File

@@ -1,5 +1,6 @@
using Fantasy;
using Fantasy.Async;
using NB.Common;
namespace NB.Game;
@@ -13,7 +14,7 @@ public static class CacheHandler
/// <returns></returns>
public static async FTask<List<RoleSimpleInfo>> GetPlayerBasicCacheInfos(Scene scene, List<long> id)
{
var gameSceneConfig = GameSceneHelper.GetSceneConfig();
var gameSceneConfig = SceneConfigHelper.GetConfig(SceneType.Game);
var gameRouteId = gameSceneConfig.RouteId;
//连接到游戏中心服
var gameResponse = (G2S_GetPlayerBasicInfoResponse)await scene.NetworkMessagingComponent.CallInnerRoute(

View File

@@ -1,29 +1,29 @@
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<Scene, G2Game_EnterRequest, Game2G_EnterResponse>
{
protected override async FTask Run(Scene scene, G2Game_EnterRequest request, Game2G_EnterResponse response,
Action reply)
{
Log.Debug("收到 G2Game_EnterRequestHandler");
// 在缓存中检查该账号是否存在
var gameAccountManageComponent = scene.GetComponent<PlayerManageComponent>();
var account = await gameAccountManageComponent.Online(scene, request.AccountId, request.GateRouteId);
response.RoleRouteId = account.RuntimeId;
response.RoleInfo = account.GetRoleSimpleInfo();
await FTask.CompletedTask;
}
}
// 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<Scene, G2Game_EnterRequest, Game2G_EnterResponse>
// {
// protected override async FTask Run(Scene scene, G2Game_EnterRequest request, Game2G_EnterResponse response,
// Action reply)
// {
// Log.Debug("收到 G2Game_EnterRequestHandler");
//
//
// // 在缓存中检查该账号是否存在
// var gameAccountManageComponent = scene.GetComponent<PlayerManageComponent>();
//
// var account = await gameAccountManageComponent.Online(scene, request.AccountId, request.GateRouteId);
//
// response.RoleRouteId = account.RuntimeId;
// response.RoleInfo = account.GetRoleSimpleInfo();
// await FTask.CompletedTask;
// }
// }

View File

@@ -1,48 +0,0 @@
using System.Net;
using Fantasy;
using Fantasy.Async;
using Fantasy.Network;
using Fantasy.Platform.Net;
namespace NB.Game;
public static class GameSceneHelper
{
#region 线 线
public static SceneConfig GetSceneConfig()
{
var gameSceneConfigs = SceneConfigData.Instance.GetSceneBySceneType(SceneType.Game);
return gameSceneConfigs.First();
}
public static async FTask<(long, RoleSimpleInfo?)> Online(Scene scene, long accountID, long gateRuntimeId)
{
var gameSceneConfig = GetSceneConfig();
var gameRouteId = gameSceneConfig.RouteId;
//连接到游戏中心服
var gameResponse = (Game2G_EnterResponse)await scene.NetworkMessagingComponent.CallInnerRoute(
gameRouteId, new G2Game_EnterRequest()
{
AccountId = accountID,
GateRouteId = gateRuntimeId
});
if (gameResponse.ErrorCode != 0)
{
return (0, null);
}
return (gameResponse.RoleRouteId, gameResponse.RoleInfo);
}
public static async FTask Offline(Scene scene, long accountId, long gateRuntimeId)
{
}
#endregion
}

View File

@@ -42,7 +42,8 @@ public static class PlayerManageComponentSystem
/// <param name="self"></param>
/// <param name="scene"></param>
/// <param name="accountId"></param>
public static async FTask<Player> Online(this PlayerManageComponent self, Scene scene, long accountId,
/// <param name="gateRouteId"></param>
public static async FTask<Player?> Online(this PlayerManageComponent self, Scene scene, long accountId,
long gateRouteId)
{
Log.Debug("检查账号是否在缓存中");

View File

@@ -61,7 +61,7 @@ public static class PlayerHelper
/// <param name="scene"></param>
/// <param name="accountId">账号Id</param>
/// <returns></returns>
public static async FTask<Player> LoadDataBase(Scene scene, long accountId)
public static async FTask<Player?> LoadDataBase(Scene scene, long accountId)
{
var account = await scene.World.DataBase.First<Player>(d => d.Id == accountId);
if (account == null)