大修改
This commit is contained in:
27
Hotfix/Social/Handler/C2S_CreateChannelRequestHandler.cs
Normal file
27
Hotfix/Social/Handler/C2S_CreateChannelRequestHandler.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using Fantasy;
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Network.Interface;
|
||||
|
||||
namespace NB.Chat;
|
||||
|
||||
/// <summary>
|
||||
/// 请求创建频道
|
||||
/// </summary>
|
||||
public class
|
||||
C2S_CreateChannelRequestHandler : RouteRPC<SocialUnit, C2S_CreateChannelRequest, S2C_CreateChannelResponse>
|
||||
{
|
||||
protected override async FTask Run(SocialUnit entity, C2S_CreateChannelRequest request,
|
||||
S2C_CreateChannelResponse response, Action reply)
|
||||
{
|
||||
var channelCenter = entity.Scene.GetComponent<ChatChannelCenterComponent>();
|
||||
if (channelCenter == null)
|
||||
{
|
||||
response.ErrorCode = ErrorCode.ErrServer;
|
||||
return;
|
||||
}
|
||||
|
||||
var channel = await channelCenter.Create(entity);
|
||||
|
||||
response.ChannelId = channel.Id;
|
||||
}
|
||||
}
|
||||
24
Hotfix/Social/Handler/C2S_GetOfflineMessageRequestHandler.cs
Normal file
24
Hotfix/Social/Handler/C2S_GetOfflineMessageRequestHandler.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using Fantasy;
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Network.Interface;
|
||||
|
||||
namespace NB.Chat;
|
||||
|
||||
public class
|
||||
C2S_GetOfflineMessageRequestHandler : RouteRPC<SocialUnit, C2S_GetOfflineMessageRequest,
|
||||
S2C_GetOfflineMessageResponse>
|
||||
{
|
||||
protected override async FTask Run(SocialUnit entity, C2S_GetOfflineMessageRequest request,
|
||||
S2C_GetOfflineMessageResponse response,
|
||||
Action reply)
|
||||
{
|
||||
var chatUnitManage = entity.Scene.GetComponent<SocialUnitManageComponent>();
|
||||
if (chatUnitManage.NotSendMessage.TryGetValue(entity.Id, out var list))
|
||||
{
|
||||
response.Message.AddRange(list);
|
||||
chatUnitManage.NotSendMessage.RemoveByKey(entity.Id);
|
||||
}
|
||||
|
||||
await FTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
60
Hotfix/Social/Handler/C2S_JoinChannelRequestHandler.cs
Normal file
60
Hotfix/Social/Handler/C2S_JoinChannelRequestHandler.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using Fantasy;
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Network.Interface;
|
||||
|
||||
namespace NB.Chat;
|
||||
|
||||
/// <summary>
|
||||
/// 请求进入频道
|
||||
/// </summary>
|
||||
public class
|
||||
C2S_JoinChannelRequestHandler : RouteRPC<SocialUnit, C2S_JoinChannelRequest, S2C_JoinChannelResponse>
|
||||
{
|
||||
protected override async FTask Run(SocialUnit entity, C2S_JoinChannelRequest request,
|
||||
S2C_JoinChannelResponse response, Action reply)
|
||||
{
|
||||
if (request.Target < 1)
|
||||
{
|
||||
response.ErrorCode = ErrorCode.ErrArgs;
|
||||
return;
|
||||
}
|
||||
|
||||
var channelCenter = entity.Scene.GetComponent<ChatChannelCenterComponent>();
|
||||
if (channelCenter == null)
|
||||
{
|
||||
response.ErrorCode = ErrorCode.ErrServer;
|
||||
return;
|
||||
}
|
||||
|
||||
var oldChannelId = entity.CurrentChannel;
|
||||
if (oldChannelId > 0)
|
||||
{
|
||||
//退出旧的频道
|
||||
var oldChannel = await channelCenter.Get(oldChannelId);
|
||||
if (oldChannel != null)
|
||||
{
|
||||
oldChannel.Exit(entity);
|
||||
}
|
||||
}
|
||||
|
||||
//加入新频道
|
||||
var newChannel = await channelCenter.Get(request.Target);
|
||||
if (newChannel != null)
|
||||
{
|
||||
if (newChannel.ChannelType == 1)
|
||||
{
|
||||
//工会频道需要再工会才能加入
|
||||
}
|
||||
else if (newChannel.ChannelType == 0)
|
||||
{
|
||||
//地图频道需要判断在这个地图才能加入
|
||||
}
|
||||
|
||||
newChannel.Enter(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
response.ErrorCode = ErrorCode.ChatNotChannel;
|
||||
}
|
||||
}
|
||||
}
|
||||
41
Hotfix/Social/Handler/C2S_SendMessageRequestHandler.cs
Normal file
41
Hotfix/Social/Handler/C2S_SendMessageRequestHandler.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System.Text;
|
||||
using Fantasy;
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Helper;
|
||||
using Fantasy.Network.Interface;
|
||||
|
||||
namespace NB.Chat;
|
||||
|
||||
public sealed class
|
||||
C2S_SendMessageRequestHandler : RouteRPC<SocialUnit, C2S_SendMessageRequest, S2C_SendMessageResponse>
|
||||
{
|
||||
protected override async FTask Run(SocialUnit socialUnit, C2S_SendMessageRequest request,
|
||||
S2C_SendMessageResponse response, Action reply)
|
||||
{
|
||||
if (request.Target < 1)
|
||||
{
|
||||
response.ErrorCode = ErrorCode.ErrArgs;
|
||||
return;
|
||||
}
|
||||
|
||||
if (request.Type == 0) //频道聊天
|
||||
{
|
||||
SocialSceneHelper.BroadcastChannel(socialUnit.Scene, request.Target, new ChatMessageInfo()
|
||||
{
|
||||
SendTime = TimeHelper.Now,
|
||||
Content = request.Message,
|
||||
});
|
||||
}
|
||||
else if (request.Type == 1) //私聊
|
||||
{
|
||||
//发送私聊
|
||||
SocialSceneHelper.PrivateMessage(socialUnit.Scene, socialUnit.Id, request.Target, new ChatMessageInfo()
|
||||
{
|
||||
SendTime = TimeHelper.Now,
|
||||
Content = request.Message,
|
||||
});
|
||||
}
|
||||
|
||||
await FTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
22
Hotfix/Social/Handler/Inner/G2S_EnterRequestHandler.cs
Normal file
22
Hotfix/Social/Handler/Inner/G2S_EnterRequestHandler.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using Fantasy;
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Network.Interface;
|
||||
using NB.Game;
|
||||
|
||||
namespace NB.Chat;
|
||||
|
||||
public class G2S_EnterRequestHandler : RouteRPC<Scene, G2S_EnterRequest, S2G_EnterResponse>
|
||||
{
|
||||
protected override async FTask Run(Scene scene, G2S_EnterRequest request, S2G_EnterResponse response,
|
||||
Action reply)
|
||||
{
|
||||
var roleId = request.Role.RoleId;
|
||||
Log.Debug($"收到 G2S_EnterRequestHandler {roleId}");
|
||||
|
||||
// 在缓存中检查该账号是否存在
|
||||
var chatUnitManageComponent = scene.GetComponent<SocialUnitManageComponent>();
|
||||
var account = await chatUnitManageComponent.Online(scene, request.Role, request.GateRouteId);
|
||||
|
||||
response.RoleRouteId = account.RuntimeId;
|
||||
}
|
||||
}
|
||||
16
Hotfix/Social/Handler/Inner/G2S_ExitRequestHandler.cs
Normal file
16
Hotfix/Social/Handler/Inner/G2S_ExitRequestHandler.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using Fantasy;
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Network.Interface;
|
||||
|
||||
namespace NB.Chat;
|
||||
|
||||
public class G2S_ExitRequestHandler : RouteRPC<Scene, G2S_ExitRequest, S2G_ExitResponse>
|
||||
{
|
||||
protected override async FTask Run(Scene scene, G2S_ExitRequest request, S2G_ExitResponse response,
|
||||
Action reply)
|
||||
{
|
||||
// 在缓存中检查该账号是否存在
|
||||
var chatUnitManageComponent = scene.GetComponent<SocialUnitManageComponent>();
|
||||
await chatUnitManageComponent.Offline(scene, request.AccountId, request.GateRouteId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user