服务合并

This commit is contained in:
Bob.Song
2026-03-11 10:15:34 +08:00
parent 945ffe9861
commit c2ec7226c0
68 changed files with 866 additions and 1032 deletions

View File

@@ -4,7 +4,6 @@ using Fantasy.Async;
using Fantasy.Network.Interface;
using NB.Chat;
using NB.Game;
using NBF.Social;
namespace NB.Common;
@@ -23,14 +22,9 @@ public class G2Common_EnterRequestHandler : AddressRPC<Scene, G2Common_EnterRequ
break;
}
case SceneType.Social:
{
await RunSocial(scene, request, response);
break;
}
// case SceneType.Map:
// case SceneType.Social:
// {
// await RunMap(scene, request, response);
// await RunSocial(scene, request, response);
// break;
// }
}
@@ -53,21 +47,21 @@ public class G2Common_EnterRequestHandler : AddressRPC<Scene, G2Common_EnterRequ
Log.Info($"登录到游戏服成功id={response.UnitRouteId}");
}
private async FTask RunSocial(Scene scene, G2Common_EnterRequest request, G2Common_EnterResponse response)
{
// 在缓存中检查该账号是否存在
var chatUnitManageComponent = scene.GetComponent<SocialUnitManageComponent>();
var account = await chatUnitManageComponent.Online(scene, request.AccountId, request.GateRouteId);
if (account == null)
{
response.ErrorCode = ErrorCode.ErrServer;
return;
}
response.UnitRouteId = account.RuntimeId;
Log.Info($"登录到社交服成功id={response.UnitRouteId}");
}
// private async FTask RunSocial(Scene scene, G2Common_EnterRequest request, G2Common_EnterResponse response)
// {
// // 在缓存中检查该账号是否存在
// var chatUnitManageComponent = scene.GetComponent<SocialUnitManageComponent>();
// var account = await chatUnitManageComponent.Online(scene, request.AccountId, request.GateRouteId);
//
// if (account == null)
// {
// response.ErrorCode = ErrorCode.ErrServer;
// return;
// }
//
// response.UnitRouteId = account.RuntimeId;
// Log.Info($"登录到社交服成功id={response.UnitRouteId}");
// }
// private async FTask RunMap(Scene scene, G2Common_EnterRequest request, G2Common_EnterResponse response)
// {

View File

@@ -4,7 +4,6 @@ using Fantasy.Async;
using Fantasy.Network.Interface;
using NB.Chat;
using NB.Game;
using NBF.Social;
namespace NB.Common;
@@ -21,11 +20,11 @@ public class G2Common_ExitRequestHandler : AddressRPC<Scene, G2Common_ExitReques
break;
}
case SceneType.Social:
{
await RunSocial(scene, request, response);
break;
}
// case SceneType.Social:
// {
// await RunSocial(scene, request, response);
// break;
// }
// case SceneType.Map:
// {
// await RunMap(scene, request, response);
@@ -44,13 +43,13 @@ public class G2Common_ExitRequestHandler : AddressRPC<Scene, G2Common_ExitReques
Log.Info("退出游戏服成功==");
}
private async FTask RunSocial(Scene scene, G2Common_ExitRequest request, Common2G_ExitResponse response)
{
// 在缓存中检查该账号是否存在
var chatUnitManageComponent = scene.GetComponent<SocialUnitManageComponent>();
await chatUnitManageComponent.Offline(scene, request.AccountId, request.GateRouteId);
Log.Info("退出聊天服成功==");
}
// private async FTask RunSocial(Scene scene, G2Common_ExitRequest request, Common2G_ExitResponse response)
// {
// // 在缓存中检查该账号是否存在
// var chatUnitManageComponent = scene.GetComponent<SocialUnitManageComponent>();
// await chatUnitManageComponent.Offline(scene, request.AccountId, request.GateRouteId);
// Log.Info("退出聊天服成功==");
// }
// private async FTask RunMap(Scene scene, G2Common_ExitRequest request, Common2G_ExitResponse response)
// {

View File

@@ -13,10 +13,6 @@ public static class SceneConfigHelper
{
sceneType = SceneType.Game;
}
else if (routeType == RouteType.SocialRoute)
{
sceneType = SceneType.Social;
}
else if (routeType == RouteType.GateRoute)
{
sceneType = SceneType.Gate;

View File

@@ -6,10 +6,10 @@ using Fantasy.Network.Interface;
namespace NB.Game;
public class C2Map_CreateRoomRequestHandler : AddressRPC<Player, C2Map_CreateRoomRequest, Map2C_CreateRoomResponse>
public class C2Map_CreateRoomRequestHandler : AddressRPC<Player, C2Game_CreateRoomRequest, Game2C_CreateRoomResponse>
{
protected override async FTask Run(Player entity, C2Map_CreateRoomRequest request,
Map2C_CreateRoomResponse response,
protected override async FTask Run(Player entity, C2Game_CreateRoomRequest request,
Game2C_CreateRoomResponse response,
Action reply)
{
var mapUnit = entity.GetComponent<MapUnitComponent>();

View File

@@ -4,9 +4,9 @@ using Fantasy.Network.Interface;
namespace NB.Game;
public class C2Map_LookHandler : Address<Player, C2Map_Look>
public class C2Map_LookHandler : Address<Player, C2Game_Look>
{
protected override async FTask Run(Player entity, C2Map_Look message)
protected override async FTask Run(Player entity, C2Game_Look message)
{
var mapUnit = entity.GetComponent<MapUnitComponent>();
if (mapUnit == null)
@@ -23,7 +23,7 @@ public class C2Map_LookHandler : Address<Player, C2Map_Look>
return;
}
var notifyMessage = new Map2C_LookeNotify()
var notifyMessage = new Game2C_LookeNotify()
{
Id = entity.Id,
Rotation = message.Rotation,

View File

@@ -5,9 +5,9 @@ using Fantasy.Network.Interface;
namespace NB.Game;
public class C2Map_MoveHandler : Address<Player, C2Map_Move>
public class C2Map_MoveHandler : Address<Player, C2Game_Move>
{
protected override async FTask Run(Player entity, C2Map_Move message)
protected override async FTask Run(Player entity, C2Game_Move message)
{
var mapUnit = entity.GetComponent<MapUnitComponent>();
if (mapUnit == null)
@@ -24,7 +24,7 @@ public class C2Map_MoveHandler : Address<Player, C2Map_Move>
return;
}
// var mapUnitManageComponent = entity.Scene.GetComponent<MapUnitManageComponent>();
var notifyMessage = new Map2C_MoveNotify()
var notifyMessage = new Game2C_MoveNotify()
{
Id = entity.Id,
Position = message.Position,

View File

@@ -4,9 +4,9 @@ using Fantasy.Network.Interface;
namespace NB.Game;
public class C2Map_RolePropertyChangeHandler : Address<Player, C2Map_RolePropertyChange>
public class C2Map_RolePropertyChangeHandler : Address<Player, C2Game_RolePropertyChange>
{
protected override async FTask Run(Player entity, C2Map_RolePropertyChange message)
protected override async FTask Run(Player entity, C2Game_RolePropertyChange message)
{
var mapUnit = entity.GetComponent<MapUnitComponent>();
if (mapUnit == null)
@@ -23,7 +23,7 @@ public class C2Map_RolePropertyChangeHandler : Address<Player, C2Map_RolePropert
return;
}
var notifyMessage = new Map2C_RolePropertyChangeNotify()
var notifyMessage = new Game2C_RolePropertyChangeNotify()
{
Id = entity.Id,
Propertys = message.Propertys,

View File

@@ -5,9 +5,9 @@ using Fantasy.Network.Interface;
namespace NB.Game;
public class C2Map_TakeItemRequestHandler : AddressRPC<Player, C2Map_TakeItemRequest, Map2C_TakeItemResponse>
public class C2Map_TakeItemRequestHandler : AddressRPC<Player, C2Game_TakeItemRequest, Game2C_TakeItemResponse>
{
protected override async FTask Run(Player entity, C2Map_TakeItemRequest request, Map2C_TakeItemResponse response,
protected override async FTask Run(Player entity, C2Game_TakeItemRequest request, Game2C_TakeItemResponse response,
Action reply)
{
var itemContainer = entity.GetComponent<PlayerItemContainerComponent>();
@@ -48,7 +48,7 @@ public class C2Map_TakeItemRequestHandler : AddressRPC<Player, C2Map_TakeItemReq
var room = roomManageComponent.Get(roomId);
if (room != null)
{
var notifyMessage = new Map2C_RoleGearChangeNotify();
var notifyMessage = new Game2C_RoleGearChangeNotify();
// notifyMessage
// return;
foreach (var (_, unit) in room.Units)

View File

@@ -0,0 +1,20 @@
// using Fantasy;
// using Fantasy.Async;
// using Fantasy.Network.Interface;
//
// namespace NB.Chat;
//
// public sealed class Other2Chat_ChatMessageHandler : Address<SocialUnit, Other2Chat_ChatMessage>
// {
// protected override async FTask Run(SocialUnit chatUnit, Other2Chat_ChatMessage message)
// {
// var result = ChatSceneHelper.Distribution(chatUnit, message.ChatInfoTree, false);
//
// if (result != 0)
// {
// Log.Warning($"Other2Chat_ChatMessageHandler: Distribution failed, result: {result}");
// }
//
// await FTask.CompletedTask;
// }
// }

View File

@@ -1,12 +1,13 @@
using Fantasy;
using Fantasy.Async;
using Fantasy.Network.Interface;
using NB.Game;
namespace NB.Chat;
public sealed class C2Chat_SendMessageRequestHandler : AddressRPC<SocialUnit, C2Chat_SendMessageRequest, Chat2C_SendMessageResponse>
public sealed class C2Chat_SendMessageRequestHandler : AddressRPC<Player, C2Game_SendMessageRequest, Game2C_SendMessageResponse>
{
protected override async FTask Run(SocialUnit chatUnit, C2Chat_SendMessageRequest request, Chat2C_SendMessageResponse response, Action reply)
protected override async FTask Run(Player chatUnit, C2Game_SendMessageRequest request, Game2C_SendMessageResponse response, Action reply)
{
response.ErrorCode = ChatSceneHelper.Distribution(chatUnit, request.ChatInfoTree);
await FTask.CompletedTask;

View File

@@ -13,11 +13,11 @@ public static class ChatHelper
/// <param name="tree"></param>
public static void SendChatMessage(Scene scene, long chatUnitRouteId, ChatInfoTree tree)
{
if (scene.SceneType == SceneType.Social)
{
Log.Warning("ChatHelper.SendChatMessage: scene is not a chat scene.");
return;
}
// if (scene.SceneType == SceneType.Social)
// {
// Log.Warning("ChatHelper.SendChatMessage: scene is not a chat scene.");
// return;
// }
var other2ChatChatMessage = new Other2Chat_ChatMessage()
{

View File

@@ -2,7 +2,7 @@ using System.Threading.Channels;
using Fantasy;
using Fantasy.Helper;
using Fantasy.Platform.Net;
using NBF.Social;
using NB.Game;
// ReSharper disable ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
@@ -21,7 +21,7 @@ public static class ChatSceneHelper
/// <param name="tree"></param>
/// <param name="isCheckSendTime"></param>
/// <returns></returns>
public static uint Distribution(SocialUnit chatUnit, ChatInfoTree tree, bool isCheckSendTime = true)
public static uint Distribution(Player chatUnit, ChatInfoTree tree, bool isCheckSendTime = true)
{
var result = Condition(chatUnit, tree, isCheckSendTime);
@@ -60,7 +60,7 @@ public static class ChatSceneHelper
/// <param name="tree"></param>
/// <param name="isCheckSendTime"></param>
/// <returns></returns>
private static uint Condition(SocialUnit chatUnit, ChatInfoTree tree, bool isCheckSendTime = true)
private static uint Condition(Player chatUnit, ChatInfoTree tree, bool isCheckSendTime = true)
{
// 每个频道可能聊天的间隔都不一样。
// 这里的条件判断,是根据频道的类型,来判断是否到达了聊天的间隔。
@@ -152,7 +152,7 @@ public static class ChatSceneHelper
if (tree.Target.Count > 0)
{
var chatUnitManageComponent = scene.GetComponent<SocialUnitManageComponent>();
var chatUnitManageComponent = scene.GetComponent<PlayerManageComponent>();
// 给一部分人广播消息
foreach (var chatUnitId in tree.Target)
{
@@ -162,7 +162,7 @@ public static class ChatSceneHelper
}
// networkMessagingComponent.SendInnerRoute(chatUnit.GateRouteId, chatMessage);
networkMessagingComponent.Send(chatUnit.GateRouteId, chatMessage);
networkMessagingComponent.Send(chatUnit.SessionRunTimeId, chatMessage);
}
return;
}
@@ -182,7 +182,7 @@ public static class ChatSceneHelper
/// </summary>
/// <param name="chatUnit"></param>
/// <param name="tree"></param>
private static uint Channel(SocialUnit chatUnit, ChatInfoTree tree)
private static uint Channel(Player chatUnit, ChatInfoTree tree)
{
// 那组队,公会、地图、等这个的聊天,如何使用频道呢?
// 这里的频道,是指一个频道,比如一个公会的频道,一个队伍的频道,一个地图的频道。
@@ -213,7 +213,7 @@ public static class ChatSceneHelper
/// <param name="chatUnit"></param>
/// <param name="tree"></param>
/// <returns></returns>
private static uint Private(SocialUnit chatUnit, ChatInfoTree tree)
private static uint Private(Player chatUnit, ChatInfoTree tree)
{
// 私聊,就是两个玩家之间,直接聊天。
// 1、首先客户端需要知道对方的ID这个ID是通过什么方式获取的呢
@@ -230,14 +230,14 @@ public static class ChatSceneHelper
var targetChatUnitId = tree.Target[0];
var scene = chatUnit.Scene;
if (!scene.GetComponent<SocialUnitManageComponent>().TryGet(targetChatUnitId, out var targetChatUnit))
if (!scene.GetComponent<PlayerManageComponent>().TryGet(targetChatUnitId, out var targetChatUnit))
{
// 这个2代表对方不在线。
return 2;
}
var networkMessagingComponent = scene.NetworkMessagingComponent;
var chatMessage = new Chat2C_Message()
var chatMessage = new Game2C_Message()
{
ChatInfoTree = tree
};
@@ -248,9 +248,9 @@ public static class ChatSceneHelper
// networkMessagingComponent.SendInnerRoute(targetChatUnit.GateRouteId, chatMessage);
// 先给自己发送一个聊天消息。
networkMessagingComponent.Send(chatUnit.GateRouteId, chatMessage);
networkMessagingComponent.Send(chatUnit.SessionRunTimeId, chatMessage);
// 然后再给对方发送一个聊天消息。
networkMessagingComponent.Send(targetChatUnit.GateRouteId, chatMessage);
networkMessagingComponent.Send(targetChatUnit.SessionRunTimeId, chatMessage);
return 0;
}

View File

@@ -1,41 +1,39 @@
using Fantasy;
using Fantasy.Entitas;
using NBF.Social;
using NB.Game;
namespace NB.Chat;
public class MemoryEntity : Entity
{
}
public static class ChatChannelComponentSystem
{
public static void Send(this ChatChannelComponent self, ChatInfoTree tree)
{
var chatUnitManageComponent = self.Scene.GetComponent<SocialUnitManageComponent>();
var chatUnitManageComponent = self.Scene.GetComponent<PlayerManageComponent>();
var networkMessagingComponent = self.Scene.NetworkMessagingComponent;
var chatMessage = new Chat2C_Message()
var chatMessage = new Game2C_Message()
{
ChatInfoTree = tree
};
foreach (var unitId in self.Units)
{
if (!chatUnitManageComponent.Units.TryGetValue(unitId, out var chatUnit))
if (!chatUnitManageComponent.TryGet(unitId, out var chatUnit))
{
continue;
}
// networkMessagingComponent.SendInnerRoute(chatUnit.GateRouteId, chatMessage);
networkMessagingComponent.Send(chatUnit.GateRouteId, chatMessage);
networkMessagingComponent.Send(chatUnit.SessionRunTimeId, chatMessage);
}
}
public static bool JoinChannel(this ChatChannelComponent self, long chatUnitId)
{
var chatUnitManageComponent = self.Scene.GetComponent<SocialUnitManageComponent>();
var chatUnitManageComponent = self.Scene.GetComponent<PlayerManageComponent>();
if (!chatUnitManageComponent.TryGet(chatUnitId, out var chatUnit))
{
@@ -49,6 +47,7 @@ public static class ChatChannelComponentSystem
{
chatUnit.Channels.Add(self.Id, self);
}
// 可以在这里给客户端发送一个加入频道成功的消息。
return true;
}
@@ -65,7 +64,7 @@ public static class ChatChannelComponentSystem
return;
}
var chatUnitManageComponent = self.Scene.GetComponent<SocialUnitManageComponent>();
var chatUnitManageComponent = self.Scene.GetComponent<PlayerManageComponent>();
if (!chatUnitManageComponent.TryGet(chatUnitId, out var chatUnit))
{
@@ -77,7 +76,7 @@ public static class ChatChannelComponentSystem
// 给用户移除频道。
chatUnit.Channels.Remove(self.Id);
}
// 在当前频道中移除该用户。
self.Units.Remove(chatUnitId);
// 如果当前频道中没有用户了,则销毁该频道。

View File

@@ -2,13 +2,14 @@
using Fantasy;
using Fantasy.Async;
using Fantasy.Network.Interface;
using NB.Game;
namespace NB.Chat;
public class C2S_DeleteMailRequestHandler : AddressRPC<SocialUnit, C2S_DeleteMailRequest, S2C_DeleteMailResponse>
public class C2Game_DeleteMailRequestHandler : AddressRPC<Player, C2Game_DeleteMailRequest, Game2C_DeleteMailResponse>
{
protected override async FTask Run(SocialUnit entity, C2S_DeleteMailRequest request,
S2C_DeleteMailResponse response, Action reply)
protected override async FTask Run(Player entity, C2Game_DeleteMailRequest request,
Game2C_DeleteMailResponse response, Action reply)
{
if (request.Id < 1)
{

View File

@@ -3,14 +3,15 @@ using System.Diagnostics;
using Fantasy;
using Fantasy.Async;
using Fantasy.Network.Interface;
using NB.Game;
namespace NB.Chat;
public class
C2S_GetConversationsRequestHandler : AddressRPC<SocialUnit, C2S_GetConversationsRequest, S2C_GetConversationsResponse>
C2Game_GetConversationsRequestHandler : AddressRPC<Player, C2Game_GetConversationsRequest, Game2C_GetConversationsResponse>
{
protected override async FTask Run(SocialUnit entity, C2S_GetConversationsRequest request,
S2C_GetConversationsResponse response, Action reply)
protected override async FTask Run(Player entity, C2Game_GetConversationsRequest request,
Game2C_GetConversationsResponse response, Action reply)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();

View File

@@ -2,12 +2,13 @@
using Fantasy;
using Fantasy.Async;
using Fantasy.Network.Interface;
using NB.Game;
namespace NB.Chat;
public class C2S_SendMailRequestHandler : AddressRPC<SocialUnit, C2S_SendMailRequest, S2C_SendMailResponse>
public class C2Game_SendMailRequestHandler : AddressRPC<Player, C2Game_SendMailRequest, Game2C_SendMailResponse>
{
protected override async FTask Run(SocialUnit entity, C2S_SendMailRequest request, S2C_SendMailResponse response,
protected override async FTask Run(Player entity, C2Game_SendMailRequest request, Game2C_SendMailResponse response,
Action reply)
{
if (request.Target < 1)
@@ -24,7 +25,7 @@ public class C2S_SendMailRequestHandler : AddressRPC<SocialUnit, C2S_SendMailReq
return;
}
var chatUnitManage = entity.Scene.GetComponent<SocialUnitManageComponent>();
var chatUnitManage = entity.Scene.GetComponent<PlayerManageComponent>();
if (chatUnitManage == null)
{
Log.Error("组件不存在 SocialUnitManageComponent");
@@ -50,13 +51,13 @@ public class C2S_SendMailRequestHandler : AddressRPC<SocialUnit, C2S_SendMailReq
mail.OwnerId = request.Target;
await conversation.Add(mail);
var res = new S2C_HaveMail()
var res = new Game2C_HaveMail()
{
Mail = mail.ToMailInfo(),
Key = conversation.Key
};
//同步客户端
entity.Scene.NetworkMessagingComponent.Send(entity.GateRouteId, res);
entity.Scene.NetworkMessagingComponent.Send(entity.SessionRunTimeId, res);
// var chatUnit = chatUnitManage.Get(request.Target);
//

View File

@@ -43,7 +43,7 @@ public static class MailComponentSystem
if (sync)
{
//同步客户端
self.Scene.NetworkMessagingComponent.Send(0,new S2C_HaveMail()
self.Scene.NetworkMessagingComponent.Send(0,new Game2C_HaveMail()
{
Mail = mail.ToMailInfo(),
});
@@ -66,7 +66,7 @@ public static class MailComponentSystem
if (sync)
{
//同步客户端
self.Scene.NetworkMessagingComponent.Send(0,new S2C_MailState()
self.Scene.NetworkMessagingComponent.Send(0,new Game2C_MailState()
{
MailState = (int)MailState.Deleted,
MailId = mailId,

View File

@@ -0,0 +1,146 @@
// using Fantasy;
// using Fantasy.Async;
// using Fantasy.Entitas;
// using Fantasy.Entitas.Interface;
// using NB.Chat;
//
// namespace NBF.Social;
//
// public sealed class ChatUnitManageComponentDestroySystem : DestroySystem<SocialUnitManageComponent>
// {
// protected override void Destroy(SocialUnitManageComponent self)
// {
// foreach (var chatUnit in self.Units.Values.ToArray())
// {
// chatUnit.Dispose();
// }
//
// self.Units.Clear();
// }
// }
//
// public static class SocialUnitManageComponentSystem
// {
// #region 消息缓存
//
// /// <summary>
// /// 离线消息,进入待领取队列
// /// </summary>
// /// <param name="self"></param>
// /// <param name="targetId"></param>
// /// <param name="message"></param>
// public static void SaveOfflineMessage(this SocialUnitManageComponent self, long targetId, ChatMessageInfo message)
// {
// // self.NotSendMessage.Add(targetId, message);
// }
//
// #endregion
//
// #region 上线下线
//
// /// <summary>
// /// 玩家上线
// /// </summary>
// /// <param name="self"></param>
// /// <param name="scene"></param>
// /// <param name="accountId"></param>
// /// <param name="gateRouteId"></param>
// public static async FTask<SocialUnit?> Online(this SocialUnitManageComponent self, Scene scene,
// long accountId,
// long gateRouteId)
// {
// // var accountId = roleSimpleInfo.RoleId;
// if (!self.TryGet(accountId, out var account))
// {
// account = Entity.Create<SocialUnit>(scene, accountId, true, true);
// self.Add(account);
// }
//
// if (account != null)
// {
// await account.TryComponent<MailComponent>();
// account.GateRouteId = gateRouteId;
// // account.Role = roleSimpleInfo;
// }
//
// await FTask.CompletedTask;
// return account;
// }
//
// public static async FTask Offline(this SocialUnitManageComponent self, Scene scene, long accountId,
// long gateRouteId)
// {
// if (self.TryGet(accountId, out var unit) && unit != null)
// {
// if (unit.GateRouteId == gateRouteId)
// {
// Log.Info("退出当前聊天服==");
// self.Remove(accountId); //如果当前网关和下线的网关一致
// }
// }
//
// await FTask.CompletedTask;
// }
//
// #endregion
//
// #region 获取&移除
//
// public static void Add(this SocialUnitManageComponent self, SocialUnit account)
// {
// self.Units.Add(account.Id, account);
// }
//
// public static SocialUnit? Get(this SocialUnitManageComponent self, long accountId)
// {
// return self.Units.GetValueOrDefault(accountId);
// }
//
// public static bool TryGet(this SocialUnitManageComponent self, long accountId, out SocialUnit? account)
// {
// return self.Units.TryGetValue(accountId, out account);
// }
//
// public static void Remove(this SocialUnitManageComponent self, long accountId, bool isDispose = true)
// {
// if (!self.Units.Remove(accountId, out var account))
// {
// return;
// }
//
// if (!isDispose)
// {
// return;
// }
//
// account.Dispose();
// }
//
// #endregion
//
// #region 组件
//
// /// <summary>
// /// 尝试给增加相关组件
// /// </summary>
// /// <param name="socialUnit"></param>
// /// <typeparam name="T"></typeparam>
// public static async FTask TryComponent<T>(this SocialUnit socialUnit) where T : Entity, new()
// {
// if (socialUnit.GetComponent<T>() == null)
// {
// var mailComponent = await socialUnit.Scene.World.Database.Query<T>(socialUnit.Id, true);
// if (mailComponent == null)
// {
// //如果没有邮件组件
// socialUnit.AddComponent<T>();
// }
// else
// {
// socialUnit.AddComponent(mailComponent);
// }
// }
// }
//
// #endregion
// }

View File

@@ -0,0 +1,22 @@
// using Fantasy.Entitas.Interface;
// #pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
//
// namespace NB.Chat;
//
// public sealed class SocialUnitDestroySystem : DestroySystem<SocialUnit>
// {
// protected override void Destroy(SocialUnit self)
// {
// self.Role?.Return();
// self.Role = null;
// self.GateRouteId = 0;
// // 退出当前ChatUnit拥有的所有频道
// foreach (var (_,chatChannelComponent) in self.Channels)
// {
// chatChannelComponent.ExitChannel(self.Id, false);
// }
// // 理论情况下这个self.Channels不会存在因为数据的因为上面已经给清空掉了。
// // 但是self.Channels.Clear();还是加上吧,防止以后忘记了。
// self.Channels.Clear();
// }
// }

View File

@@ -11,7 +11,7 @@ public class S2G_ChatMessageHandler : Address<Scene, Chat2G_ChatMessage>
{
protected override async FTask Run(Scene scene, Chat2G_ChatMessage message)
{
// var chatMessage = new S2C_Message()
// var chatMessage = new Game2C_Message()
// {
// Msg = message.Message,
// };
@@ -42,7 +42,7 @@ public class S2G_ChatMessageHandler : Address<Scene, Chat2G_ChatMessage>
// }
// }
// }
var chatMessage = new Chat2C_Message()
var chatMessage = new Game2C_Message()
{
ChatInfoTree = message.ChatInfoTree
};

View File

@@ -45,7 +45,7 @@ public static class GateLoginHelper
gateUnitSessionComponent.AccountID = gateUnit.AccountID;
gateUnitSessionComponent.SessionId = session.RuntimeId;
return await gateUnit.Online(RouteType.GameRoute, RouteType.SocialRoute);
return await gateUnit.Online(RouteType.GameRoute);
}
#endregion
@@ -61,7 +61,7 @@ public static class GateLoginHelper
{
//通知服务器下线
Log.Info($"断线的session id={sessionId}");
var ret = await gateUnit.Offline(sessionId, RouteType.GameRoute, RouteType.SocialRoute);
var ret = await gateUnit.Offline(sessionId, RouteType.GameRoute);
return ret;
}

View File

@@ -12,8 +12,4 @@
<ProjectReference Include="..\Entity\Entity.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Social\Chat\Handler\Inner\" />
</ItemGroup>
</Project>

View File

@@ -44,15 +44,16 @@ public sealed class OnCreateSceneEvent : AsyncEventSystem<OnCreateScene>
// await InitializeMapScene(scene);
// break;
// }
case SceneType.Social:
{
// Gate 场景初始化
await InitializeSocialScene(scene);
break;
}
// case SceneType.Social:
// {
// // Gate 场景初始化
// await InitializeSocialScene(scene);
// break;
// }
case SceneType.Game:
{
await InitializeGameScene(scene);
await InitializeSocialScene(scene);
break;
}
}
@@ -139,7 +140,6 @@ public sealed class OnCreateSceneEvent : AsyncEventSystem<OnCreateScene>
{
Log.Info($"初始化 Social 场景: {scene.Id}");
//用于管理玩家的组件
scene.AddComponent<SocialUnitManageComponent>();
scene.AddComponent<MailManageComponent>();
//聊天
// 聊天频道中控中心组件。

View File

@@ -1,20 +0,0 @@
using Fantasy;
using Fantasy.Async;
using Fantasy.Network.Interface;
namespace NB.Chat;
public sealed class Other2Chat_ChatMessageHandler : Address<SocialUnit, Other2Chat_ChatMessage>
{
protected override async FTask Run(SocialUnit chatUnit, Other2Chat_ChatMessage message)
{
var result = ChatSceneHelper.Distribution(chatUnit, message.ChatInfoTree, false);
if (result != 0)
{
Log.Warning($"Other2Chat_ChatMessageHandler: Distribution failed, result: {result}");
}
await FTask.CompletedTask;
}
}

View File

@@ -1,146 +0,0 @@
using Fantasy;
using Fantasy.Async;
using Fantasy.Entitas;
using Fantasy.Entitas.Interface;
using NB.Chat;
namespace NBF.Social;
public sealed class ChatUnitManageComponentDestroySystem : DestroySystem<SocialUnitManageComponent>
{
protected override void Destroy(SocialUnitManageComponent self)
{
foreach (var chatUnit in self.Units.Values.ToArray())
{
chatUnit.Dispose();
}
self.Units.Clear();
}
}
public static class SocialUnitManageComponentSystem
{
#region
/// <summary>
/// 离线消息,进入待领取队列
/// </summary>
/// <param name="self"></param>
/// <param name="targetId"></param>
/// <param name="message"></param>
public static void SaveOfflineMessage(this SocialUnitManageComponent self, long targetId, ChatMessageInfo message)
{
// self.NotSendMessage.Add(targetId, message);
}
#endregion
#region 线线
/// <summary>
/// 玩家上线
/// </summary>
/// <param name="self"></param>
/// <param name="scene"></param>
/// <param name="accountId"></param>
/// <param name="gateRouteId"></param>
public static async FTask<SocialUnit?> Online(this SocialUnitManageComponent self, Scene scene,
long accountId,
long gateRouteId)
{
// var accountId = roleSimpleInfo.RoleId;
if (!self.TryGet(accountId, out var account))
{
account = Entity.Create<SocialUnit>(scene, accountId, true, true);
self.Add(account);
}
if (account != null)
{
await account.TryComponent<MailComponent>();
account.GateRouteId = gateRouteId;
// account.Role = roleSimpleInfo;
}
await FTask.CompletedTask;
return account;
}
public static async FTask Offline(this SocialUnitManageComponent self, Scene scene, long accountId,
long gateRouteId)
{
if (self.TryGet(accountId, out var unit) && unit != null)
{
if (unit.GateRouteId == gateRouteId)
{
Log.Info("退出当前聊天服==");
self.Remove(accountId); //如果当前网关和下线的网关一致
}
}
await FTask.CompletedTask;
}
#endregion
#region &
public static void Add(this SocialUnitManageComponent self, SocialUnit account)
{
self.Units.Add(account.Id, account);
}
public static SocialUnit? Get(this SocialUnitManageComponent self, long accountId)
{
return self.Units.GetValueOrDefault(accountId);
}
public static bool TryGet(this SocialUnitManageComponent self, long accountId, out SocialUnit? account)
{
return self.Units.TryGetValue(accountId, out account);
}
public static void Remove(this SocialUnitManageComponent self, long accountId, bool isDispose = true)
{
if (!self.Units.Remove(accountId, out var account))
{
return;
}
if (!isDispose)
{
return;
}
account.Dispose();
}
#endregion
#region
/// <summary>
/// 尝试给增加相关组件
/// </summary>
/// <param name="socialUnit"></param>
/// <typeparam name="T"></typeparam>
public static async FTask TryComponent<T>(this SocialUnit socialUnit) where T : Entity, new()
{
if (socialUnit.GetComponent<T>() == null)
{
var mailComponent = await socialUnit.Scene.World.Database.Query<T>(socialUnit.Id, true);
if (mailComponent == null)
{
//如果没有邮件组件
socialUnit.AddComponent<T>();
}
else
{
socialUnit.AddComponent(mailComponent);
}
}
}
#endregion
}

View File

@@ -1,22 +0,0 @@
using Fantasy.Entitas.Interface;
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
namespace NB.Chat;
public sealed class SocialUnitDestroySystem : DestroySystem<SocialUnit>
{
protected override void Destroy(SocialUnit self)
{
self.Role?.Return();
self.Role = null;
self.GateRouteId = 0;
// 退出当前ChatUnit拥有的所有频道
foreach (var (_,chatChannelComponent) in self.Channels)
{
chatChannelComponent.ExitChannel(self.Id, false);
}
// 理论情况下这个self.Channels不会存在因为数据的因为上面已经给清空掉了。
// 但是self.Channels.Clear();还是加上吧,防止以后忘记了。
self.Channels.Clear();
}
}