频道聊天相关
This commit is contained in:
@@ -78,12 +78,23 @@ message Game2C_MailState // ICustomRouteMessage,GameRoute
|
|||||||
int64 MailId = 2;
|
int64 MailId = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message C2Chat_JoinChannelRequest // ICustomRouteRequest,Caht2C_JoinChannelResponse,ChatRoute
|
||||||
|
{
|
||||||
|
int64 Target = 1; // 频道id
|
||||||
|
}
|
||||||
|
|
||||||
|
///进入频道响应
|
||||||
|
message Caht2C_JoinChannelResponse // ICustomRouteResponse
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
///发送聊天
|
///发送聊天
|
||||||
message C2Chat_SendMessageRequest // ICustomRouteRequest,Caht2C_SendMessageResponse,ChatRoute
|
message C2Chat_SendMessageRequest // ICustomRouteRequest,Caht2C_SendMessageResponse,ChatRoute
|
||||||
{
|
{
|
||||||
int32 Type = 1; //消息类型
|
int32 Type = 1; //消息类型 0.频道聊天 1.私聊
|
||||||
string Message = 2;
|
string Message = 2;
|
||||||
int64 Target = 3; //目标id,如果有
|
int64 Target = 3; //目标id,频道id或者好友id
|
||||||
}
|
}
|
||||||
|
|
||||||
///发送聊天响应
|
///发送聊天响应
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
using Fantasy.Entitas;
|
|
||||||
|
|
||||||
namespace NB.Chat;
|
|
||||||
|
|
||||||
public class ChatComponent : Entity
|
|
||||||
{
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
namespace NB.Chat;
|
|
||||||
|
|
||||||
[Serializable]
|
|
||||||
public abstract class ChatContentData
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
[Serializable]
|
|
||||||
public class ChatContentNormal : ChatContentData
|
|
||||||
{
|
|
||||||
public string Content = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
[Serializable]
|
|
||||||
public class ChatContentFished : ChatContentData
|
|
||||||
{
|
|
||||||
public long Id;
|
|
||||||
public int Weight;
|
|
||||||
public int Type;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Serializable]
|
|
||||||
public class ChatContentRecord : ChatContentData
|
|
||||||
{
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
using Fantasy.Entitas;
|
|
||||||
|
|
||||||
namespace NB.Chat;
|
|
||||||
|
|
||||||
@@ -8,6 +8,11 @@ namespace NB.Chat;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ChatChannel : Entity
|
public class ChatChannel : Entity
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 频道短id
|
||||||
|
/// </summary>
|
||||||
|
[BsonElement("cid")] public uint ChannelId;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 频道类型 0.地图 1.公开 2.私密
|
/// 频道类型 0.地图 1.公开 2.私密
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -37,9 +42,9 @@ public class ChatChannel : Entity
|
|||||||
/// 频道地区 0,全球 非0地区 如果是地图频道则表示地图位置
|
/// 频道地区 0,全球 非0地区 如果是地图频道则表示地图位置
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[BsonElement("region")] public int Region;
|
[BsonElement("region")] public int Region;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 当前频道在线人数
|
/// 当前频道在线人数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[BsonElement("ids")] public readonly HashSet<long> Units = new HashSet<long>();
|
[BsonIgnore] public readonly HashSet<long> Units = new HashSet<long>();
|
||||||
}
|
}
|
||||||
@@ -6,9 +6,19 @@ namespace NB.Chat;
|
|||||||
public sealed class ChatUnit : Entity
|
public sealed class ChatUnit : Entity
|
||||||
{
|
{
|
||||||
public long GateRouteId;
|
public long GateRouteId;
|
||||||
|
|
||||||
public RoleSimpleInfo Role;
|
public RoleSimpleInfo Role;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 当前所在地图
|
||||||
|
/// </summary>
|
||||||
|
public long MapId;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 当前频道
|
||||||
|
/// </summary>
|
||||||
|
public long CurrentChannel;
|
||||||
|
|
||||||
public override void Dispose()
|
public override void Dispose()
|
||||||
{
|
{
|
||||||
if (IsDisposed)
|
if (IsDisposed)
|
||||||
8
Entity/Club/Club.cs
Normal file
8
Entity/Club/Club.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
using Fantasy.Entitas;
|
||||||
|
|
||||||
|
namespace NB.Club;
|
||||||
|
|
||||||
|
public class Club : Entity
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -28,7 +28,6 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Club\" />
|
|
||||||
<Folder Include="Map\" />
|
<Folder Include="Map\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -287,6 +287,49 @@ namespace Fantasy
|
|||||||
[ProtoMember(2)]
|
[ProtoMember(2)]
|
||||||
public long MailId { get; set; }
|
public long MailId { get; set; }
|
||||||
}
|
}
|
||||||
|
[ProtoContract]
|
||||||
|
public partial class C2Chat_JoinChannelRequest : AMessage, ICustomRouteRequest, IProto
|
||||||
|
{
|
||||||
|
public static C2Chat_JoinChannelRequest Create(Scene scene)
|
||||||
|
{
|
||||||
|
return scene.MessagePoolComponent.Rent<C2Chat_JoinChannelRequest>();
|
||||||
|
}
|
||||||
|
public override void Dispose()
|
||||||
|
{
|
||||||
|
Target = default;
|
||||||
|
#if FANTASY_NET || FANTASY_UNITY
|
||||||
|
GetScene().MessagePoolComponent.Return<C2Chat_JoinChannelRequest>(this);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
[ProtoIgnore]
|
||||||
|
public Caht2C_JoinChannelResponse ResponseType { get; set; }
|
||||||
|
public uint OpCode() { return OuterOpcode.C2Chat_JoinChannelRequest; }
|
||||||
|
[ProtoIgnore]
|
||||||
|
public int RouteType => Fantasy.RouteType.ChatRoute;
|
||||||
|
[ProtoMember(1)]
|
||||||
|
public long Target { get; set; }
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 进入频道响应
|
||||||
|
/// </summary>
|
||||||
|
[ProtoContract]
|
||||||
|
public partial class Caht2C_JoinChannelResponse : AMessage, ICustomRouteResponse, IProto
|
||||||
|
{
|
||||||
|
public static Caht2C_JoinChannelResponse Create(Scene scene)
|
||||||
|
{
|
||||||
|
return scene.MessagePoolComponent.Rent<Caht2C_JoinChannelResponse>();
|
||||||
|
}
|
||||||
|
public override void Dispose()
|
||||||
|
{
|
||||||
|
ErrorCode = default;
|
||||||
|
#if FANTASY_NET || FANTASY_UNITY
|
||||||
|
GetScene().MessagePoolComponent.Return<Caht2C_JoinChannelResponse>(this);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
public uint OpCode() { return OuterOpcode.Caht2C_JoinChannelResponse; }
|
||||||
|
[ProtoMember(1)]
|
||||||
|
public uint ErrorCode { get; set; }
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 发送聊天
|
/// 发送聊天
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -362,4 +405,24 @@ namespace Fantasy
|
|||||||
[ProtoMember(1)]
|
[ProtoMember(1)]
|
||||||
public ChatMessageInfo Message { get; set; }
|
public ChatMessageInfo Message { get; set; }
|
||||||
}
|
}
|
||||||
|
[ProtoContract]
|
||||||
|
public partial class C2G_LoginRequest1 : AMessage, IRequest, IProto
|
||||||
|
{
|
||||||
|
public static C2G_LoginRequest1 Create(Scene scene)
|
||||||
|
{
|
||||||
|
return scene.MessagePoolComponent.Rent<C2G_LoginRequest1>();
|
||||||
|
}
|
||||||
|
public override void Dispose()
|
||||||
|
{
|
||||||
|
ToKen = default;
|
||||||
|
#if FANTASY_NET || FANTASY_UNITY
|
||||||
|
GetScene().MessagePoolComponent.Return<C2G_LoginRequest1>(this);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
[ProtoIgnore]
|
||||||
|
public G2C_LoginResponse ResponseType { get; set; }
|
||||||
|
public uint OpCode() { return OuterOpcode.C2G_LoginRequest1; }
|
||||||
|
[ProtoMember(1)]
|
||||||
|
public string ToKen { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,8 +13,11 @@ namespace Fantasy
|
|||||||
public const uint Game2C_GetMailsResponse = 2415929106;
|
public const uint Game2C_GetMailsResponse = 2415929106;
|
||||||
public const uint Game2C_HaveMail = 2147493649;
|
public const uint Game2C_HaveMail = 2147493649;
|
||||||
public const uint Game2C_MailState = 2147493650;
|
public const uint Game2C_MailState = 2147493650;
|
||||||
public const uint C2Chat_SendMessageRequest = 2281711379;
|
public const uint C2Chat_JoinChannelRequest = 2281711379;
|
||||||
public const uint Caht2C_SendMessageResponse = 2415929107;
|
public const uint Caht2C_JoinChannelResponse = 2415929107;
|
||||||
|
public const uint C2Chat_SendMessageRequest = 2281711380;
|
||||||
|
public const uint Caht2C_SendMessageResponse = 2415929108;
|
||||||
public const uint Chat2C_Message = 2147493651;
|
public const uint Chat2C_Message = 2147493651;
|
||||||
|
public const uint C2G_LoginRequest1 = 268445459;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,4 +39,9 @@ public class ErrorCode
|
|||||||
/// 登录自动注册没有设置地区
|
/// 登录自动注册没有设置地区
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const uint RegisterNotRegion = 11011;
|
public const uint RegisterNotRegion = 11011;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 聊天频道不存在
|
||||||
|
/// </summary>
|
||||||
|
public const uint ChatNotChannel = 12011;
|
||||||
}
|
}
|
||||||
45
Hotfix/Chat/Handler/C2Chat_JoinChannelRequestHandler.cs
Normal file
45
Hotfix/Chat/Handler/C2Chat_JoinChannelRequestHandler.cs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
using Fantasy;
|
||||||
|
using Fantasy.Async;
|
||||||
|
using Fantasy.Network.Interface;
|
||||||
|
|
||||||
|
namespace NB.Chat;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 请求进入频道
|
||||||
|
/// </summary>
|
||||||
|
public class
|
||||||
|
C2Chat_JoinChannelRequestHandler : RouteRPC<ChatUnit, C2Chat_JoinChannelRequest, Caht2C_JoinChannelResponse>
|
||||||
|
{
|
||||||
|
protected override async FTask Run(ChatUnit entity, C2Chat_JoinChannelRequest request,
|
||||||
|
Caht2C_JoinChannelResponse response, Action reply)
|
||||||
|
{
|
||||||
|
var channelCenter = entity.Scene.GetComponent<ChatChannelCenterComponent>();
|
||||||
|
if (channelCenter == null)
|
||||||
|
{
|
||||||
|
response.ErrorCode = ErrorCode.ErrServer;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var oldChannelId = entity.CurrentChannel;
|
||||||
|
if (oldChannelId > 0)
|
||||||
|
{
|
||||||
|
//退出旧的频道
|
||||||
|
if (channelCenter.TryGet(oldChannelId, out var oldChannel) && oldChannel != null)
|
||||||
|
{
|
||||||
|
oldChannel.Exit(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//加入新频道
|
||||||
|
if (channelCenter.TryGet(request.Target, out var channel) && channel != null)
|
||||||
|
{
|
||||||
|
channel.Enter(entity);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
response.ErrorCode = ErrorCode.ChatNotChannel;
|
||||||
|
}
|
||||||
|
|
||||||
|
await FTask.CompletedTask;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,16 +8,7 @@ public static class ChatSceneHelper
|
|||||||
{
|
{
|
||||||
#region 消息发送
|
#region 消息发送
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 广播记录更新
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="scene"></param>
|
|
||||||
/// <param name="record"></param>
|
|
||||||
public static void BroadcastRecord(Scene scene, ChatContentRecord record)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 广播消息给所有人
|
/// 广播消息给所有人
|
||||||
|
|||||||
@@ -1,10 +1,38 @@
|
|||||||
using Fantasy.Entitas;
|
using Fantasy.Entitas;
|
||||||
|
using Fantasy.Entitas.Interface;
|
||||||
using Fantasy.Helper;
|
using Fantasy.Helper;
|
||||||
|
|
||||||
namespace NB.Chat;
|
namespace NB.Chat;
|
||||||
|
|
||||||
|
public class ChatChannelCenterComponentAwakeSystem : AwakeSystem<ChatChannelCenterComponent>
|
||||||
|
{
|
||||||
|
protected override void Awake(ChatChannelCenterComponent self)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ChatChannelCenterComponentDestroySystem : DestroySystem<ChatChannelCenterComponent>
|
||||||
|
{
|
||||||
|
protected override void Destroy(ChatChannelCenterComponent self)
|
||||||
|
{
|
||||||
|
self.Channels.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class ChatChannelCenterComponentSystem
|
public static class ChatChannelCenterComponentSystem
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 获取
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="self"></param>
|
||||||
|
/// <param name="channelId"></param>
|
||||||
|
/// <param name="channel"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool TryGet(this ChatChannelCenterComponent self, long channelId, out ChatChannel? channel)
|
||||||
|
{
|
||||||
|
return self.Channels.TryGetValue(channelId, out channel);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 申请创建一个频道
|
/// 申请创建一个频道
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -26,18 +54,6 @@ public static class ChatChannelCenterComponentSystem
|
|||||||
return channel;
|
return channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="self"></param>
|
|
||||||
/// <param name="channelId"></param>
|
|
||||||
/// <param name="channel"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static bool TryGet(this ChatChannelCenterComponent self, long channelId, out ChatChannel? channel)
|
|
||||||
{
|
|
||||||
return self.Channels.TryGetValue(channelId, out channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 解散
|
/// 解散
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
26
Hotfix/Chat/System/ChatChannelSystem.cs
Normal file
26
Hotfix/Chat/System/ChatChannelSystem.cs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
namespace NB.Chat;
|
||||||
|
|
||||||
|
public static class ChatChannelSystem
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 进入频道
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="channel"></param>
|
||||||
|
/// <param name="unit"></param>
|
||||||
|
public static void Enter(this ChatChannel channel, ChatUnit unit)
|
||||||
|
{
|
||||||
|
channel.Units.Add(unit.Id);
|
||||||
|
unit.CurrentChannel = channel.Id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 离开频道
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="channel"></param>
|
||||||
|
/// <param name="unit"></param>
|
||||||
|
public static void Exit(this ChatChannel channel, ChatUnit unit)
|
||||||
|
{
|
||||||
|
channel.Units.Remove(unit.Id);
|
||||||
|
unit.CurrentChannel = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user