广播聊天
This commit is contained in:
24
Hotfix/Gate/Handler/Inner/Chat2G_ChatMessageHandler.cs
Normal file
24
Hotfix/Gate/Handler/Inner/Chat2G_ChatMessageHandler.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using Fantasy;
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Network.Interface;
|
||||
|
||||
namespace NB.Gate;
|
||||
|
||||
public class Chat2G_ChatMessageHandler : Route<Scene, Chat2G_ChatMessage>
|
||||
{
|
||||
protected override async FTask Run(Scene scene, Chat2G_ChatMessage message)
|
||||
{
|
||||
var chatMessage = new Chat2C_Message()
|
||||
{
|
||||
Message = message.Message,
|
||||
};
|
||||
|
||||
var gateUnitManage = scene.GetComponent<GateUnitManageComponent>();
|
||||
foreach (var session in gateUnitManage.ForEachUnitSession())
|
||||
{
|
||||
session.Send(chatMessage);
|
||||
}
|
||||
|
||||
await FTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,18 @@
|
||||
using Fantasy;
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Network;
|
||||
using NB.Chat;
|
||||
using NB.Game;
|
||||
|
||||
namespace NB.Gate;
|
||||
|
||||
public static class GateLoginHelper
|
||||
{
|
||||
#region 上线
|
||||
|
||||
/// <summary>
|
||||
/// 网关通知其他服务器上线
|
||||
/// </summary>
|
||||
/// <param name="self"></param>
|
||||
/// <param name="gateUnit"></param>
|
||||
public static async FTask<uint> Online(GateUnit gateUnit)
|
||||
{
|
||||
@@ -39,29 +41,34 @@ public static class GateLoginHelper
|
||||
|
||||
gateUnitSessionComponent.AccountID = gateUnit.AccountID;
|
||||
|
||||
//安排服务器,并通知进入
|
||||
var gameSceneConfig = GameSceneHelper.GetSceneConfig(session);
|
||||
var gameRouteId = gameSceneConfig.RouteId;
|
||||
//连接到游戏中心服
|
||||
var gameResponse = (Game2G_EnterResponse)await session.Scene.NetworkMessagingComponent.CallInnerRoute(
|
||||
gameRouteId, new G2Game_EnterRequest()
|
||||
{
|
||||
AccountId = gateUnit.AccountID,
|
||||
GateRouteId = session.RuntimeId
|
||||
});
|
||||
|
||||
if (gameResponse.ErrorCode != 0)
|
||||
//安排游戏服务器,并通知进入
|
||||
var gameRouteId = await GameSceneHelper.Online(session.Scene, gateUnit.AccountID, session.RuntimeId);
|
||||
if (gameRouteId <= 0)
|
||||
{
|
||||
return ErrorCode.OnlineSceneFailed;
|
||||
}
|
||||
|
||||
routeComponent.AddAddress(RouteType.GameRoute, gameResponse.RoleRouteId);
|
||||
Log.Info($"连接游戏服成功,gameRouteId:{gameRouteId}");
|
||||
routeComponent.AddAddress(RouteType.GameRoute, gameRouteId);
|
||||
gateUnit.GameSceneRouteId = gameRouteId;
|
||||
|
||||
|
||||
|
||||
// //安排进入的聊天服
|
||||
var chatRouteId = await ChatSceneHelper.Online(session.Scene, gateUnit.AccountID, session.RuntimeId);
|
||||
if (chatRouteId <= 0)
|
||||
{
|
||||
return ErrorCode.OnlineSceneFailed;
|
||||
}
|
||||
routeComponent.AddAddress(RouteType.ChatRoute, chatRouteId);
|
||||
gateUnit.ChatSceneRouteId = chatRouteId;
|
||||
Log.Info($"连接聊天服成功,gameRouteId:{gameRouteId}");
|
||||
return ErrorCode.Successful;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 下线
|
||||
|
||||
/// <summary>
|
||||
/// 网关通知其他服务器下线
|
||||
/// </summary>
|
||||
@@ -69,7 +76,11 @@ public static class GateLoginHelper
|
||||
/// <param name="gateUnit"></param>
|
||||
public static async FTask<uint> Offline(GateUnit gateUnit)
|
||||
{
|
||||
await FTask.CompletedTask;
|
||||
//通知服务器下线
|
||||
return ErrorCode.Successful;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
@@ -52,4 +52,19 @@ public static class GateUnitManageComponentSystem
|
||||
unit.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 回话迭代器
|
||||
/// </summary>
|
||||
/// <param name="self"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<Session> ForEachUnitSession(this GateUnitManageComponent self)
|
||||
{
|
||||
foreach (var (_, gateUnit) in self.Units)
|
||||
{
|
||||
Session gateSession = gateUnit.Session;
|
||||
if (gateSession == null) continue;
|
||||
yield return gateSession;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,8 +28,8 @@ public static class GateJWTComponentSystem
|
||||
ValidateIssuer = true, // 验证发行者
|
||||
ValidateAudience = true, // 验证受众
|
||||
ValidateIssuerSigningKey = true, // 验证签名密钥
|
||||
ValidIssuer = "Fantasy", // 有效的发行者
|
||||
ValidAudience = "Fantasy", // 有效的受众
|
||||
ValidIssuer = "NoBug", // 有效的发行者
|
||||
ValidAudience = "NoBug", // 有效的受众
|
||||
IssuerSigningKey = new RsaSecurityKey(rsa) // RSA公钥作为签名密钥
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user