summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-08-25 20:45:38 +0300
committerAndrei Karas <akaras@inbox.ru>2017-08-25 20:45:38 +0300
commitf7d3792df9fd01ea7baabaf9b612031b1f28d7ab (patch)
treea38b12795443c2c364059cf418d6171171d4434b /src/net
parent6adafcc07e2101ab085bd9f2182c965ef70d0519 (diff)
downloadmanaplus-f7d3792df9fd01ea7baabaf9b612031b1f28d7ab.tar.gz
manaplus-f7d3792df9fd01ea7baabaf9b612031b1f28d7ab.tar.bz2
manaplus-f7d3792df9fd01ea7baabaf9b612031b1f28d7ab.tar.xz
manaplus-f7d3792df9fd01ea7baabaf9b612031b1f28d7ab.zip
Add basic support for view mail message.
Diffstat (limited to 'src/net')
-rw-r--r--src/net/eathena/mail2recv.cpp91
-rw-r--r--src/net/eathena/mailrecv.cpp2
2 files changed, 78 insertions, 15 deletions
diff --git a/src/net/eathena/mail2recv.cpp b/src/net/eathena/mail2recv.cpp
index b3ffae6c0..3da4ae4c5 100644
--- a/src/net/eathena/mail2recv.cpp
+++ b/src/net/eathena/mail2recv.cpp
@@ -35,6 +35,7 @@
#include "gui/mailmessage.h"
#include "gui/windows/maileditwindow.h"
+#include "gui/windows/mailviewwindow.h"
#include "gui/windows/mailwindow.h"
#include "net/messagein.h"
@@ -310,32 +311,94 @@ void Mail2Recv::processMailListPage(Net::MessageIn &msg)
void Mail2Recv::processReadMail(Net::MessageIn &msg)
{
- UNIMPLEMENTEDPACKET;
msg.readInt16("len");
- msg.readUInt8("open type");
- msg.readInt64("mail id");
+ const MailOpenTypeT openType = static_cast<MailOpenTypeT>(
+ msg.readUInt8("open type"));
+ const int64_t mailId = msg.readInt64("mail id");
const int textLen = msg.readInt16("text len");
- msg.readInt64("money");
+ const int64_t money = msg.readInt64("money");
const int itemsCount = msg.readUInt8("item count");
- msg.readString(textLen, "text message");
+ const std::string text = msg.readString(textLen, "text message");
+ MailMessage *mail = nullptr;
+
+ if (mailWindow != nullptr &&
+ openType == mailWindow->getOpenType())
+ {
+ mail = mailWindow->findMail(mailId);
+ }
+
+ if (mail == nullptr)
+ {
+ reportAlways("Mail message not found");
+ for (int f = 0; f < itemsCount; f ++)
+ {
+ msg.readInt16("amount");
+ msg.readInt16("item id");
+ msg.readUInt8("identify");
+ msg.readUInt8("damaged");
+ msg.readUInt8("refine");
+ for (int d = 0; d < maxCards; d ++)
+ msg.readUInt16("card");
+ msg.readInt32("unknown");
+ msg.readUInt8("type");
+ msg.readInt32("unknown");
+ for (int d = 0; d < 5; d ++)
+ {
+ msg.readInt16("option index");
+ msg.readInt16("option value");
+ msg.readUInt8("option param");
+ }
+ }
+ return;
+ }
+
+ mail->money = money;
+ mail->text = text;
+ mailWindow->showMessage(mail, itemsCount);
+
+ Inventory *const inventory = mailViewWindow->getInventory();
+
for (int f = 0; f < itemsCount; f ++)
{
- msg.readInt16("amount");
- msg.readInt16("item id");
- msg.readUInt8("identify");
- msg.readUInt8("damaged");
- msg.readUInt8("refine");
+ const int amount = msg.readInt16("amount");
+ const int itemId = msg.readInt16("item id");
+ const uint8_t identify = msg.readUInt8("identify");
+ const Damaged damaged = fromBool(msg.readUInt8("attribute"), Damaged);
+ const uint8_t refine = msg.readUInt8("refine");
+ int cards[maxCards];
for (int d = 0; d < maxCards; d ++)
- msg.readUInt16("card");
+ cards[d] = msg.readUInt16("card");
msg.readInt32("unknown");
- msg.readUInt8("type");
+ const ItemTypeT itemType = static_cast<ItemTypeT>(
+ msg.readUInt8("item type"));
msg.readInt32("unknown");
+ ItemOptionsList *options = new ItemOptionsList(5);
for (int d = 0; d < 5; d ++)
{
- msg.readInt16("option index");
- msg.readInt16("option value");
+ const uint16_t idx = msg.readInt16("option index");
+ const uint16_t val = msg.readInt16("option value");
msg.readUInt8("option param");
+ options->add(idx, val);
}
+
+ const int slot = inventory->addItem(itemId,
+ itemType,
+ amount,
+ refine,
+ ItemColorManager::getColorFromCards(&cards[0]),
+ fromBool(identify, Identified),
+ damaged,
+ Favorite_false,
+ Equipm_false,
+ Equipped_false);
+ if (slot == -1)
+ {
+ delete options;
+ continue;
+ }
+ inventory->setCards(slot, cards, 4);
+ inventory->setOptions(slot, options);
+ delete options;
}
}
diff --git a/src/net/eathena/mailrecv.cpp b/src/net/eathena/mailrecv.cpp
index 93a548c69..ac638b300 100644
--- a/src/net/eathena/mailrecv.cpp
+++ b/src/net/eathena/mailrecv.cpp
@@ -110,7 +110,7 @@ void MailRecv::processReadMail(Net::MessageIn &msg)
mail->text = msg.readString(sz, "message");
msg.readUInt8("zero");
mail->strTime = timeToStr(mail->time);
- mailWindow->showMessage(mail);
+ mailWindow->showMessage(mail, mail->itemId != 0 ? 1 : 0);
}
void MailRecv::processGetAttachment(Net::MessageIn &msg)