完成离线消息发送和上线获取离线消息
This commit is contained in:
@@ -8,22 +8,107 @@ public static class ChatSceneHelper
|
||||
{
|
||||
#region 消息发送
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 发送一条私聊
|
||||
/// </summary>
|
||||
/// <param name="scene"></param>
|
||||
/// <param name="selfId"></param>
|
||||
/// <param name="targetId"></param>
|
||||
/// <param name="message"></param>
|
||||
public static void PrivateMessage(Scene scene, long selfId, long targetId, ChatMessageInfo message)
|
||||
{
|
||||
var chatUnitManage = scene.GetComponent<ChatUnitManageComponent>();
|
||||
if (chatUnitManage == null) return;
|
||||
var chatUnit = chatUnitManage.Get(targetId);
|
||||
message.Type = 1;
|
||||
message.Source = selfId;
|
||||
if (chatUnit != null)
|
||||
{
|
||||
//对方在线
|
||||
BroadcastAll(scene, message, [targetId]);
|
||||
}
|
||||
else
|
||||
{
|
||||
//对方不在线,存入待领取列表,等待玩家下次登录领取
|
||||
chatUnitManage.SaveOfflineMessage(targetId, message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送一条地图消息
|
||||
/// </summary>
|
||||
/// <param name="scene"></param>
|
||||
/// <param name="mapId"></param>
|
||||
/// <param name="message"></param>
|
||||
public static void BroadcastMap(Scene scene, long mapId, ChatMessageInfo message)
|
||||
{
|
||||
var chatUnitManage = scene.GetComponent<ChatUnitManageComponent>();
|
||||
if (chatUnitManage == null) return;
|
||||
HashSet<long> targets = new HashSet<long>();
|
||||
foreach (var (_, chatUnit) in chatUnitManage.ChatUnits)
|
||||
{
|
||||
if (chatUnit.MapId == mapId)
|
||||
{
|
||||
targets.Add(chatUnit.Id);
|
||||
}
|
||||
}
|
||||
|
||||
if (targets.Count < 1)
|
||||
{
|
||||
Log.Info("地图在线人数为0,群发取消");
|
||||
return;
|
||||
}
|
||||
|
||||
BroadcastAll(scene, message, targets);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送一条频道消息
|
||||
/// </summary>
|
||||
/// <param name="scene"></param>
|
||||
/// <param name="channelId"></param>
|
||||
/// <param name="message"></param>
|
||||
public static void BroadcastChannel(Scene scene, long channelId, ChatMessageInfo message)
|
||||
{
|
||||
var chatUnitManage = scene.GetComponent<ChatUnitManageComponent>();
|
||||
if (chatUnitManage == null) return;
|
||||
HashSet<long> targets = new HashSet<long>();
|
||||
foreach (var (_, chatUnit) in chatUnitManage.ChatUnits)
|
||||
{
|
||||
if (chatUnit.CurrentChannel == channelId)
|
||||
{
|
||||
targets.Add(chatUnit.Id);
|
||||
}
|
||||
}
|
||||
|
||||
if (targets.Count < 1)
|
||||
{
|
||||
Log.Info("频道在线人数为0,群发取消");
|
||||
return;
|
||||
}
|
||||
|
||||
BroadcastAll(scene, message, targets);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 广播消息给所有人
|
||||
/// </summary>
|
||||
/// <param name="scene"></param>
|
||||
/// <param name="message"></param>
|
||||
public static void Broadcast(Scene scene, ChatMessageInfo message)
|
||||
/// <param name="targets"></param>
|
||||
public static void BroadcastAll(Scene scene, ChatMessageInfo message, HashSet<long>? targets = null)
|
||||
{
|
||||
Log.Info("广播消息===");
|
||||
//发送给所有Gate服务器,让Gate转发给其他客户端
|
||||
var gateConfigs = SceneConfigData.Instance.GetSceneBySceneType(SceneType.Gate);
|
||||
var sendMessage = new Chat2G_ChatMessage()
|
||||
{
|
||||
Message = message
|
||||
Message = message,
|
||||
};
|
||||
if (targets != null && targets.Count > 0)
|
||||
{
|
||||
sendMessage.IdList.AddRange(targets);
|
||||
}
|
||||
|
||||
var networkMessagingComponent = scene.NetworkMessagingComponent;
|
||||
foreach (var config in gateConfigs)
|
||||
{
|
||||
@@ -37,7 +122,7 @@ public static class ChatSceneHelper
|
||||
|
||||
#region 上线下线
|
||||
|
||||
public static async FTask<long> Online(Scene scene, RoleSimpleInfo roleSimple, long gateRuntimeId)
|
||||
public static async FTask<(long, long)> Online(Scene scene, RoleSimpleInfo roleSimple, long gateRuntimeId)
|
||||
{
|
||||
var gameSceneConfig = GetSceneConfig();
|
||||
var gameRouteId = gameSceneConfig.RouteId;
|
||||
@@ -51,10 +136,30 @@ public static class ChatSceneHelper
|
||||
|
||||
if (gameResponse.ErrorCode != 0)
|
||||
{
|
||||
return 0;
|
||||
return (0, 0);
|
||||
}
|
||||
|
||||
return gameResponse.RoleRouteId;
|
||||
return (gameResponse.RoleRouteId, gameRouteId);
|
||||
// return gameRouteId;
|
||||
}
|
||||
|
||||
public static async FTask Offline(Scene scene, long accountId, long gateRuntimeId, long sceneRouteId)
|
||||
{
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
var gameResponse = (Chat2G_ExitResponse)await scene.NetworkMessagingComponent.CallInnerRoute(
|
||||
sceneRouteId, new G2Chat_ExitRequest()
|
||||
{
|
||||
AccountId = accountId,
|
||||
GateRouteId = gateRuntimeId
|
||||
});
|
||||
if (gameResponse.ErrorCode == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Log.Error("重试多次还是退出失败,需检查");
|
||||
}
|
||||
|
||||
private static SceneConfig GetSceneConfig()
|
||||
|
||||
Reference in New Issue
Block a user