server-master/srcs/_plugins/WingsEmu.Plugins.BasicImplementation/Mail/NoteOpenEventHandler.cs
2026-02-10 18:21:30 +01:00

48 lines
No EOL
1.4 KiB
C#

using System.Threading;
using System.Threading.Tasks;
using PhoenixLib.Events;
using WingsAPI.Communication;
using WingsAPI.Communication.Mail;
using WingsAPI.Game.Extensions.PacketGeneration;
using WingsEmu.Game.Mails;
using WingsEmu.Game.Mails.Events;
using WingsEmu.Game.Networking;
namespace WingsEmu.Plugins.BasicImplementations.Mail;
public class NoteOpenEventHandler : IAsyncEventProcessor<NoteOpenEvent>
{
private readonly INoteService _noteService;
public NoteOpenEventHandler(INoteService noteService) => _noteService = noteService;
public async Task HandleAsync(NoteOpenEvent e, CancellationToken cancellation)
{
IClientSession session = e.Sender;
long noteId = e.NoteId;
bool isSenderCopy = e.IsSenderCopy;
CharacterNote note = session.PlayerEntity.MailNoteComponent.GetNote(noteId, isSenderCopy);
if (note == null)
{
return;
}
if (!note.IsOpened && !note.IsSenderCopy)
{
BasicRpcResponse response = await _noteService.OpenNoteAsync(new OpenNoteRequest
{
NoteId = note.Id
});
if (response.ResponseType != RpcResponseType.SUCCESS)
{
return;
}
note.IsOpened = true;
}
session.SendPostMessage(note, (byte)(note.IsSenderCopy ? 2 : 1));
}
}