68 lines
1.8 KiB
C#
68 lines
1.8 KiB
C#
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="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
|
||
} |