提交示例代码

This commit is contained in:
Bob.Song
2026-03-05 11:39:06 +08:00
commit 25958f58c3
2534 changed files with 209593 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
using Fantasy.Async;
using Fantasy.Entitas;
using Fantasy.Network.Interface;
namespace Fantasy;
public sealed class G2Chat_LoginRequestHandler : RouteRPC<Scene, G2Chat_LoginRequest, Chat2G_LoginResponse>
{
protected override async FTask Run(Scene scene, G2Chat_LoginRequest request, Chat2G_LoginResponse response, Action reply)
{
var chatUnit = scene.GetComponent<ChatUnitManageComponent>().Add(request.UnitId, request.UserName, request.GateRouteId);
response.ChatRouteId = chatUnit.RunTimeId;
// 这里模拟创建一个频道用于测试用
var chatChannelCenterComponent = scene.GetComponent<ChatChannelCenterComponent>();
var chatChannelComponent = chatChannelCenterComponent.Apply(1);
// 加入到聊天频道
chatChannelComponent.JoinChannel(request.UnitId);
await FTask.CompletedTask;
}
}

View File

@@ -0,0 +1,13 @@
using Fantasy.Async;
using Fantasy.Network.Interface;
namespace Fantasy;
public sealed class G2Chat_OfflineRequestHandler : RouteRPC<ChatUnit, G2Chat_OfflineRequest, Chat2G_OfflineResponse>
{
protected override async FTask Run(ChatUnit chatUnit, G2Chat_OfflineRequest request, Chat2G_OfflineResponse response, Action reply)
{
await FTask.CompletedTask;
chatUnit.Scene.GetComponent<ChatUnitManageComponent>().Remove(chatUnit.Id);
}
}

View File

@@ -0,0 +1,19 @@
using Fantasy.Async;
using Fantasy.Network.Interface;
namespace Fantasy;
public sealed class Other2Chat_ChatMessageHandler : Route<ChatUnit, Other2Chat_ChatMessage>
{
protected override async FTask Run(ChatUnit 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

@@ -0,0 +1,13 @@
using Fantasy.Async;
using Fantasy.Network.Interface;
namespace Fantasy;
public sealed class C2Chat_SendMessageRequestHandler : RouteRPC<ChatUnit, C2Chat_SendMessageRequest, Chat2C_SendMessageResponse>
{
protected override async FTask Run(ChatUnit chatUnit, C2Chat_SendMessageRequest request, Chat2C_SendMessageResponse response, Action reply)
{
response.ErrorCode = ChatSceneHelper.Distribution(chatUnit, request.ChatInfoTree);
await FTask.CompletedTask;
}
}