Files
Fishing2Server/Hotfix/Chat/Helper/ChatSceneHelper.cs
2025-08-08 18:21:11 +08:00

77 lines
2.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Fantasy;
using Fantasy.Async;
using Fantasy.Platform.Net;
namespace NB.Chat;
public static class ChatSceneHelper
{
#region
/// <summary>
/// 广播记录更新
/// </summary>
/// <param name="scene"></param>
/// <param name="record"></param>
public static void BroadcastRecord(Scene scene, ChatContentRecord record)
{
}
/// <summary>
/// 广播消息给所有人
/// </summary>
/// <param name="scene"></param>
/// <param name="message"></param>
public static void Broadcast(Scene scene, ChatMessageInfo message)
{
Log.Info("广播消息===");
//发送给所有Gate服务器让Gate转发给其他客户端
var gateConfigs = SceneConfigData.Instance.GetSceneBySceneType(SceneType.Gate);
var sendMessage = new Chat2G_ChatMessage()
{
Message = message
};
var networkMessagingComponent = scene.NetworkMessagingComponent;
foreach (var config in gateConfigs)
{
//发送给Gate服务器转发消息
networkMessagingComponent.SendInnerRoute(config.RouteId, sendMessage);
}
}
#endregion
#region 线线
public static async FTask<long> Online(Scene scene, RoleSimpleInfo roleSimple, long gateRuntimeId)
{
var gameSceneConfig = GetSceneConfig();
var gameRouteId = gameSceneConfig.RouteId;
//连接到游戏中心服
var gameResponse = (Chat2G_EnterResponse)await scene.NetworkMessagingComponent.CallInnerRoute(
gameRouteId, new G2Chat_EnterRequest()
{
Role = roleSimple,
GateRouteId = gateRuntimeId
});
if (gameResponse.ErrorCode != 0)
{
return 0;
}
return gameResponse.RoleRouteId;
}
private static SceneConfig GetSceneConfig()
{
var gameSceneConfigs = SceneConfigData.Instance.GetSceneBySceneType(SceneType.Chat);
return gameSceneConfigs.First();
}
#endregion
}