房间创建和进入相关逻辑和协议

This commit is contained in:
2025-08-27 00:04:40 +08:00
parent 7325e268ce
commit f6d85a1e0a
45 changed files with 1246 additions and 729 deletions

View File

@@ -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<C2G_EnterRoomRequest, G2C_EnterRoomResponse>
{
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<GateUnitSessionComponent>();
if (gateUnitSessionComponent == null)
{
response.ErrorCode = ErrorCode.ErrServer;
return;
}
// 在缓存中检查该账号是否存在
var gateUnitManageComponent = session.Scene.GetComponent<GateUnitManageComponent>();
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);
//执行进入房间操作
}
}

View File

@@ -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<C2G_LoginRequest, G2C_LoginResponse>
{

View File

@@ -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<RouteComponent>();
}
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;
}