-
Notifications
You must be signed in to change notification settings - Fork 96
/
MailHandler.cs
147 lines (135 loc) · 5.64 KB
/
MailHandler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
using Framework.Constants;
using HermesProxy.Enums;
using HermesProxy.World;
using HermesProxy.World.Enums;
using HermesProxy.World.Objects;
using HermesProxy.World.Server.Packets;
using System.Collections.Generic;
using static HermesProxy.World.Server.Packets.SendMail;
namespace HermesProxy.World.Server
{
public partial class WorldSocket
{
// Handlers for CMSG opcodes coming from the modern client
[PacketHandler(Opcode.CMSG_QUERY_NEXT_MAIL_TIME)]
void HandleMailGetList(EmptyClientPacket mail)
{
WorldPacket packet = new WorldPacket(Opcode.MSG_QUERY_NEXT_MAIL_TIME);
SendPacketToServer(packet);
}
[PacketHandler(Opcode.CMSG_MAIL_GET_LIST)]
void HandleMailGetList(MailGetList mail)
{
WorldPacket packet = new WorldPacket(Opcode.CMSG_MAIL_GET_LIST);
packet.WriteGuid(mail.Mailbox.To64());
SendPacketToServer(packet);
}
[PacketHandler(Opcode.CMSG_MAIL_CREATE_TEXT_ITEM)]
void HandleMailCreateTextItem(MailCreateTextItem mail)
{
WorldPacket packet = new WorldPacket(Opcode.CMSG_MAIL_CREATE_TEXT_ITEM);
packet.WriteGuid(mail.Mailbox.To64());
packet.WriteUInt32(mail.MailID);
if (LegacyVersion.RemovedInVersion(ClientVersionBuild.V3_0_2_9056))
packet.WriteUInt32(0); // Mail Template Id
SendPacketToServer(packet);
}
[PacketHandler(Opcode.CMSG_MAIL_DELETE)]
void HandleMailDelete(MailDelete mail)
{
WorldPacket packet = new WorldPacket(Opcode.CMSG_MAIL_DELETE);
packet.WriteGuid(GetSession().GameState.CurrentInteractedWithGO.To64());
packet.WriteUInt32(mail.MailID);
if (LegacyVersion.AddedInVersion(ClientVersionBuild.V2_0_1_6180))
packet.WriteUInt32(0); // Mail Template Id
SendPacketToServer(packet);
}
[PacketHandler(Opcode.CMSG_MAIL_MARK_AS_READ)]
void HandleMailMarkAsRead(MailMarkAsRead mail)
{
WorldPacket packet = new WorldPacket(Opcode.CMSG_MAIL_MARK_AS_READ);
packet.WriteGuid(mail.Mailbox.To64());
packet.WriteUInt32(mail.MailID);
SendPacketToServer(packet);
}
[PacketHandler(Opcode.CMSG_MAIL_RETURN_TO_SENDER)]
void HandleMailReturnToSender(MailReturnToSender mail)
{
WorldPacket packet = new WorldPacket(Opcode.CMSG_MAIL_RETURN_TO_SENDER);
packet.WriteGuid(GetSession().GameState.CurrentInteractedWithGO.To64());
packet.WriteUInt32(mail.MailID);
if (LegacyVersion.AddedInVersion(ClientVersionBuild.V2_0_1_6180))
packet.WriteGuid(mail.SenderGUID.To64());
SendPacketToServer(packet);
}
[PacketHandler(Opcode.CMSG_MAIL_TAKE_ITEM)]
void HandleMailTakeItem(MailTakeItem mail)
{
WorldPacket packet = new WorldPacket(Opcode.CMSG_MAIL_TAKE_ITEM);
packet.WriteGuid(mail.Mailbox.To64());
packet.WriteUInt32(mail.MailID);
if (LegacyVersion.AddedInVersion(ClientVersionBuild.V2_0_1_6180))
packet.WriteUInt32(mail.AttachID);
SendPacketToServer(packet);
}
[PacketHandler(Opcode.CMSG_MAIL_TAKE_MONEY)]
void HandleMailTakeMoney(MailTakeMoney mail)
{
WorldPacket packet = new WorldPacket(Opcode.CMSG_MAIL_TAKE_MONEY);
packet.WriteGuid(mail.Mailbox.To64());
packet.WriteUInt32(mail.MailID);
SendPacketToServer(packet);
}
void BuildSendMail(SendMail mail, List<MailAttachment> attachments)
{
WorldPacket packet = new WorldPacket(Opcode.CMSG_SEND_MAIL);
packet.WriteGuid(mail.Mailbox.To64());
packet.WriteCString(mail.Target);
packet.WriteCString(mail.Subject);
packet.WriteCString(mail.Body);
packet.WriteInt32(mail.StationeryID);
packet.WriteUInt32(0); // unk
if (LegacyVersion.AddedInVersion(ClientVersionBuild.V2_0_1_6180))
{
packet.WriteUInt8((byte)attachments.Count);
foreach (var item in attachments)
{
packet.WriteUInt8(item.AttachPosition);
packet.WriteGuid(item.ItemGUID.To64());
}
}
else
{
if (attachments.Count > 0)
packet.WriteGuid(attachments[0].ItemGUID.To64());
else
packet.WriteGuid(WowGuid64.Empty);
}
packet.WriteUInt32((uint)mail.SendMoney);
packet.WriteUInt32((uint)mail.Cod);
packet.WriteUInt64(0); // unk
packet.WriteUInt8(0); // unk
SendPacketToServer(packet);
}
[PacketHandler(Opcode.CMSG_SEND_MAIL)]
void HandleSendMail(SendMail mail)
{
if (LegacyVersion.AddedInVersion(ClientVersionBuild.V2_0_1_6180) ||
mail.Attachments.Count <= 1)
BuildSendMail(mail, mail.Attachments);
else
{
// only 1 item can be attached in vanilla
// split them into multiple mails
mail.SendMoney /= mail.Attachments.Count;
mail.Cod /= mail.Attachments.Count;
foreach (var item in mail.Attachments)
{
List<MailAttachment> attachments = new List<MailAttachment>();
attachments.Add(item);
BuildSendMail(mail, attachments);
}
}
}
}
}