summaryrefslogtreecommitdiff
path: root/src/net/eathena
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/eathena')
-rw-r--r--src/net/eathena/mail2handler.cpp25
-rw-r--r--src/net/eathena/mail2handler.h5
-rw-r--r--src/net/eathena/mail2recv.cpp46
-rw-r--r--src/net/eathena/mail2recv.h6
4 files changed, 79 insertions, 3 deletions
diff --git a/src/net/eathena/mail2handler.cpp b/src/net/eathena/mail2handler.cpp
index 52360d7b7..513994d2a 100644
--- a/src/net/eathena/mail2handler.cpp
+++ b/src/net/eathena/mail2handler.cpp
@@ -24,10 +24,12 @@
#include "being/localplayer.h"
+#include "net/eathena/mail2recv.h"
#include "net/eathena/messageout.h"
#include "net/eathena/protocolout.h"
#include "utils/checkutils.h"
+#include "utils/dtor.h"
#include "resources/item/item.h"
@@ -47,6 +49,12 @@ Mail2Handler::Mail2Handler()
Mail2Handler::~Mail2Handler()
{
mail2Handler = nullptr;
+ while (!Mail2Recv::mMailQueue.empty())
+ {
+ MailQueue *const mail = Mail2Recv::mMailQueue.front();
+ delete mail;
+ Mail2Recv::mMailQueue.pop();
+ }
}
void Mail2Handler::openWriteMail(const std::string &receiver) const
@@ -132,6 +140,23 @@ void Mail2Handler::sendMail(const std::string &to,
outMsg.writeString(body, bodySz, "body");
}
+bool Mail2Handler::queueSendMail(const std::string &to,
+ const std::string &title,
+ const std::string &body,
+ const int64_t &money) const
+{
+ if (!Mail2Recv::mMailQueue.empty())
+ return false;
+ MailQueue *const mail = new MailQueue;
+ mail->to = to;
+ mail->title = title;
+ mail->body = body;
+ mail->money = money;
+ mail->sendMail = true;
+ Mail2Recv::mMailQueue.push(mail);
+ return true;
+}
+
void Mail2Handler::nextPage(const MailOpenTypeT openType,
const int64_t mailId) const
{
diff --git a/src/net/eathena/mail2handler.h b/src/net/eathena/mail2handler.h
index af28b7631..8e450da9d 100644
--- a/src/net/eathena/mail2handler.h
+++ b/src/net/eathena/mail2handler.h
@@ -48,6 +48,11 @@ class Mail2Handler final : public Net::Mail2Handler
const std::string &body,
const int64_t &money) const override final;
+ bool queueSendMail(const std::string &to,
+ const std::string &title,
+ const std::string &body,
+ const int64_t &money) const override final;
+
void nextPage(const MailOpenTypeT openType,
const int64_t mailId) const override final;
diff --git a/src/net/eathena/mail2recv.cpp b/src/net/eathena/mail2recv.cpp
index ec5f8d6a8..1af7d47e2 100644
--- a/src/net/eathena/mail2recv.cpp
+++ b/src/net/eathena/mail2recv.cpp
@@ -22,15 +22,28 @@
#include "logger.h"
-#include "net/messagein.h"
+#include "notifymanager.h"
#include "const/resources/item/cards.h"
+#include "enums/resources/notifytypes.h"
+
+#include "net/messagein.h"
+
+#include "net/eathena/mail2handler.h"
+
+#include "utils/checkutils.h"
+
#include "debug.h"
namespace EAthena
{
+namespace Mail2Recv
+{
+ std::queue<MailQueue*> mMailQueue;
+} // namespace Mail2Recv
+
void Mail2Recv::processMailIcon(Net::MessageIn &msg)
{
UNIMPLEMENTEDPACKET;
@@ -82,12 +95,39 @@ void Mail2Recv::processRemoveItemResult(Net::MessageIn &msg)
void Mail2Recv::processCheckNameResult(Net::MessageIn &msg)
{
- UNIMPLEMENTEDPACKET;
- msg.readInt32("char id");
+ const int charId = msg.readInt32("char id");
msg.readInt16("class");
msg.readInt16("level");
if (msg.getVersion() >= 20160316)
msg.readString(24, "name");
+ // +++ in future if name received, need use it in map
+ if (mMailQueue.empty())
+ {
+ reportAlways("Mail2Recv::processCheckNameResult no names in queue."
+ "Char id: %d", charId);
+ return;
+ }
+ MailQueue *const mail = mMailQueue.front();
+ mMailQueue.pop();
+ if (charId == 0)
+ {
+ NotifyManager::notify(NotifyTypes::MAIL_NAME_VALIDATION_ERROR,
+ mail->to);
+ delete mail;
+ return;
+ }
+ if (mail->sendMail)
+ {
+ mail2Handler->sendMail(mail->to,
+ mail->title,
+ mail->body,
+ mail->money);
+ }
+ else
+ {
+ reportAlways("Not implemented yet.");
+ }
+ delete mail;
}
void Mail2Recv::processSendResult(Net::MessageIn &msg)
diff --git a/src/net/eathena/mail2recv.h b/src/net/eathena/mail2recv.h
index 99c88647a..dd867618e 100644
--- a/src/net/eathena/mail2recv.h
+++ b/src/net/eathena/mail2recv.h
@@ -21,6 +21,10 @@
#ifndef NET_EATHENA_MAIL2RECV_H
#define NET_EATHENA_MAIL2RECV_H
+#include "resources/mailqueue.h"
+
+#include <queue>
+
namespace Net
{
class MessageIn;
@@ -30,6 +34,8 @@ namespace EAthena
{
namespace Mail2Recv
{
+ extern std::queue<MailQueue*> mMailQueue;
+
void processMailIcon(Net::MessageIn &msg);
void processOpenNewMailWindow(Net::MessageIn &msg);
void processAddItemResult(Net::MessageIn &msg);