提交示例代码
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Network.Interface;
|
||||
|
||||
namespace Fantasy;
|
||||
|
||||
public class Other2Mail_SendRequestHandler : RouteRPC<Scene, Other2Mail_SendMailRequest, Mail2Other_SendMailResponse>
|
||||
{
|
||||
protected override async FTask Run(Scene scene, Other2Mail_SendMailRequest request, Mail2Other_SendMailResponse response, Action reply)
|
||||
{
|
||||
await MailHelper.Send(scene, request.MailBox);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Network.Interface;
|
||||
// ReSharper disable ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
|
||||
|
||||
namespace Fantasy;
|
||||
|
||||
public sealed class C2Mail_GetHaveMailRequestHandler : RouteRPC<MailUnit, C2Mail_GetHaveMailRequest, Mail2C_GetHaveMailResposne>
|
||||
{
|
||||
protected override async FTask Run(MailUnit mailUnit, C2Mail_GetHaveMailRequest request, Mail2C_GetHaveMailResposne response, Action reply)
|
||||
{
|
||||
var mailComponent = mailUnit.GetComponent<MailComponent>();
|
||||
|
||||
// 这个mailComponent是不是可能会为空?答案是可能的。
|
||||
// 那如果是空的怎么办呢,这样情况只能是别人恶意发包了。
|
||||
|
||||
if (mailComponent == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// 检查是否有超时的邮件。如果有那就清楚掉
|
||||
await mailComponent.CheckTimeOut();
|
||||
// 领取当前的邮件
|
||||
mailComponent.GetMailSimplifyInfos(response.Mails);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Network.Interface;
|
||||
|
||||
namespace Fantasy;
|
||||
|
||||
public class C2Mail_OpenMailRequestHandler : RouteRPC<MailUnit, C2Mail_OpenMailRequest, Mail2C_OpenMailResposne>
|
||||
{
|
||||
protected override async FTask Run(MailUnit mailUnit, C2Mail_OpenMailRequest request, Mail2C_OpenMailResposne response, Action reply)
|
||||
{
|
||||
if (request.MailId <= 0)
|
||||
{
|
||||
response.ErrorCode = 100;
|
||||
return;
|
||||
}
|
||||
|
||||
// 根据这个MailId来拿到邮件的详细信息
|
||||
var (errorCode, mail) = await mailUnit.GetComponent<MailComponent>().OpenMail(request.MailId);
|
||||
|
||||
if (errorCode != 0)
|
||||
{
|
||||
response.ErrorCode = errorCode;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!request.ReturnMailInfo)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
response.MailInfo = mail.ToMailInfo();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Network.Interface;
|
||||
|
||||
namespace Fantasy;
|
||||
|
||||
public class C2Mail_ReceiveMailRequestHandler : RouteRPC<MailUnit, C2Mail_ReceiveMailRequest, Mail2C_ReceiveMailResponse>
|
||||
{
|
||||
protected override async FTask Run(MailUnit mailUnit, C2Mail_ReceiveMailRequest request, Mail2C_ReceiveMailResponse response, Action reply)
|
||||
{
|
||||
if (request.MailId <= 0)
|
||||
{
|
||||
response.ErrorCode = 100;
|
||||
return;
|
||||
}
|
||||
|
||||
response.ErrorCode = await mailUnit.GetComponent<MailComponent>()
|
||||
.Receive(request.MailId, request.Money, request.ItemId, true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Network.Interface;
|
||||
|
||||
namespace Fantasy;
|
||||
|
||||
public class C2Mail_RemoveMailRequestHandler : RouteRPC<MailUnit,C2Mail_RemoveMailRequest, Mail2C_RemoveMailResponse>
|
||||
{
|
||||
protected override async FTask Run(MailUnit mailUnit, C2Mail_RemoveMailRequest request, Mail2C_RemoveMailResponse response, Action reply)
|
||||
{
|
||||
if (request.MailId <= 0)
|
||||
{
|
||||
// 这里的1代表MailId不正确。
|
||||
response.ErrorCode = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
response.ErrorCode = await mailUnit.GetComponent<MailComponent>()
|
||||
.Remove(request.MailId, MailRemoveActionType.Remove, true);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
using Fantasy.Async;
|
||||
using Fantasy.DataStructure.Collection;
|
||||
using Fantasy.Network.Interface;
|
||||
|
||||
namespace Fantasy;
|
||||
|
||||
public class C2Mail_SendMailRequestHandler : RouteRPC<MailUnit, C2Mail_SendMailRequest, Mail2C_SendMailResponse>
|
||||
{
|
||||
protected override async FTask Run(MailUnit mailUnit, C2Mail_SendMailRequest request, Mail2C_SendMailResponse response, Action reply)
|
||||
{
|
||||
if (string.IsNullOrEmpty(request.UserName))
|
||||
{
|
||||
// 这里的1代表的是发送的接收玩家名字不正确。
|
||||
response.ErrorCode = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(request.Title) || string.IsNullOrEmpty(request.Content))
|
||||
{
|
||||
// 这里的2代表的是发送的邮件标题或者内容不正确。
|
||||
response.ErrorCode = 2;
|
||||
return;
|
||||
}
|
||||
|
||||
if (request.ItemId.Count > 10)
|
||||
{
|
||||
// 这里的3代表的是发送的邮件附件超出了最大范围。
|
||||
response.ErrorCode = 3;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mailUnit.Scene.GetComponent<MailUnitManageComponent>().TryGet(request.UserName, out var receiveMailUnit))
|
||||
{
|
||||
// 这里的4代表的是没有该玩家。
|
||||
response.ErrorCode = 4;
|
||||
return;
|
||||
}
|
||||
|
||||
if (request.Money > 0)
|
||||
{
|
||||
// 如果大于0,就要调用某一个接口去货币所在的服务器上面去扣除玩家的钱。
|
||||
// var moneyResposne = await MoneyHelper.Cost(mailUnit.Scene, request.Money);
|
||||
// if (moneyResposne.ErrorCode != 0)
|
||||
// {
|
||||
// response.ErrorCode = moneyResposne.ErrorCode;
|
||||
// return;
|
||||
// }
|
||||
}
|
||||
|
||||
using var mailItems = ListPool<Item>.Create();
|
||||
if (request.ItemId.Count > 0)
|
||||
{
|
||||
// var itemResposne = await BagHelper.Get(mailUnit.Scene, request.ItemId);
|
||||
// if (itemResposne.ErrorCode != 0)
|
||||
// {
|
||||
// response.ErrorCode = itemResposne.ErrorCode;
|
||||
// return;
|
||||
// }
|
||||
// mailItems.AddRange(itemResposne.Items);
|
||||
}
|
||||
|
||||
var accountId = ListPool<long>.Create(receiveMailUnit.AccountId);
|
||||
var mail = MailFactory.Create(mailUnit.Scene, MailType.User, request.Title, request.Content, request.Money, mailItems);
|
||||
var mailBox = MailBoxFactory.Create(mailUnit.Scene, MailBoxType.Specify, mailUnit.AccountId, mail, 1000 * 60 * 60, accountId);
|
||||
await MailHelper.Send(mailUnit.Scene, mailBox);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using Fantasy.Async;
|
||||
using Fantasy.DataStructure.Collection;
|
||||
using Fantasy.Network.Interface;
|
||||
|
||||
namespace Fantasy;
|
||||
|
||||
public class C2Mail_TestRequestHandler : RouteRPC<MailUnit, C2Mail_TestRequest, Mail2C_TestResponse>
|
||||
{
|
||||
protected override async FTask Run(MailUnit mailUnit, C2Mail_TestRequest request, Mail2C_TestResponse response, Action reply)
|
||||
{
|
||||
Log.Debug($"这是一个测试的自定义消息协议 Tag:{mailUnit.Name}");
|
||||
response.Tag = "666";
|
||||
// using var accountId = ListPool<long>.Create(65491190472245249);
|
||||
var mail = MailFactory.Create(mailUnit.Scene, MailType.System, "测试所有人指定日期玩家邮件", "测试所有人指定日期玩家邮件内容", 9991);
|
||||
var mailBox = MailBoxFactory.Create(mailUnit.Scene, MailBoxType.AllToDate, mailUnit.AccountId, mail,
|
||||
1000 * 60 * 60);
|
||||
await MailHelper.Send(mailUnit.Scene, mailBox);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Network.Interface;
|
||||
|
||||
namespace Fantasy;
|
||||
|
||||
public class G2Mail_ExitRequestHandler : RouteRPC<MailUnit, G2Mail_ExitRequest, Mail2G_ExitResponse>
|
||||
{
|
||||
protected override async FTask Run(MailUnit mailUnit, G2Mail_ExitRequest request, Mail2G_ExitResponse response, Action reply)
|
||||
{
|
||||
await mailUnit.Scene.GetComponent<MailUnitManageComponent>().Exit(mailUnit);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Entitas;
|
||||
using Fantasy.Network.Interface;
|
||||
|
||||
namespace Fantasy;
|
||||
|
||||
public sealed class G2Mail_LoginRequestHandler : RouteRPC<Scene, G2Mail_LoginRequest, Mail2G_LoginResponse>
|
||||
{
|
||||
protected override async FTask Run(Scene scene, G2Mail_LoginRequest request, Mail2G_LoginResponse response, Action reply)
|
||||
{
|
||||
// Scene也是继承Entity
|
||||
// 只要能知道Entity的RuntimeId,就可以通过这个RuntimeId发送消息了。
|
||||
// 并且接收消息的Handler,第一个参数的实体可以变成这个Entity的实体
|
||||
// 也可以理解为这个RuntimeId其实就是RouteId
|
||||
|
||||
// var mailUnit = Entity.Create<MailUnit>(scene, request.AccountId, true, true);
|
||||
// mailUnit.Name = request.Name;
|
||||
// Log.Debug($"SceneType:{scene.SceneType} Name:{request.Name} mailUnit:{mailUnit.RuntimeId}");
|
||||
// response.MailUnitRouteId = mailUnit.RuntimeId;
|
||||
|
||||
var mailUnit = await scene.GetComponent<MailUnitManageComponent>()
|
||||
.Online(request.AccountId, request.Name, request.GateRouteId);
|
||||
response.MailUnitRouteId = mailUnit.RuntimeId;
|
||||
await FTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Network.Interface;
|
||||
|
||||
namespace Fantasy;
|
||||
|
||||
public sealed class G2Mail_TestMessageHandler : Route<MailUnit,G2Mail_TestMessage>
|
||||
{
|
||||
protected override async FTask Run(MailUnit mailUnit, G2Mail_TestMessage message)
|
||||
{
|
||||
Log.Debug($"这是一个测试的消息协议 Tag:{mailUnit.Name}");
|
||||
await FTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user