summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-08-23 01:12:26 +0300
committerAndrei Karas <akaras@inbox.ru>2017-08-23 01:12:26 +0300
commit75604ffe8c2ef1f2d76a44dc30e8a257b695daf5 (patch)
tree5cb43dcb41627d3313ba3d2a371b1a597fd3bab5 /src
parent17e9519c2ee0b126db5ba1df61dcddf9f7b90b47 (diff)
downloadplus-75604ffe8c2ef1f2d76a44dc30e8a257b695daf5.tar.gz
plus-75604ffe8c2ef1f2d76a44dc30e8a257b695daf5.tar.bz2
plus-75604ffe8c2ef1f2d76a44dc30e8a257b695daf5.tar.xz
plus-75604ffe8c2ef1f2d76a44dc30e8a257b695daf5.zip
Add ability to send new mail by /sendmail chat command.
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/Makefile.am1
-rw-r--r--src/actions/commands.cpp24
-rw-r--r--src/enums/resources/notifytypes.h1
-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
-rw-r--r--src/net/mail2handler.h5
-rw-r--r--src/net/tmwa/mail2handler.cpp8
-rw-r--r--src/net/tmwa/mail2handler.h5
-rw-r--r--src/resources/mailqueue.h47
-rw-r--r--src/resources/notifications.h4
13 files changed, 173 insertions, 5 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index a9215a1a4..6ef09d849 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -707,6 +707,7 @@ SET(SRCS
enums/resources/item/itemtype.h
resources/itemtypemap.h
resources/itemtypemapdata.h
+ resources/mailqueue.h
resources/db/mapdb.cpp
resources/db/mapdb.h
resources/db/mercenarydb.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index 1dc393a80..3e498f10c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1465,6 +1465,7 @@ SRC = ${BASE_SRC} \
enums/resources/item/itemtype.h \
resources/itemtypemap.h \
resources/itemtypemapdata.h \
+ resources/mailqueue.h \
resources/mapinfo.h \
enums/resources/map/mapitemtype.h \
enums/resources/map/maplayerposition.h \
diff --git a/src/actions/commands.cpp b/src/actions/commands.cpp
index a415a2117..18560f8df 100644
--- a/src/actions/commands.cpp
+++ b/src/actions/commands.cpp
@@ -63,6 +63,7 @@
#include "net/guildhandler.h"
#include "net/familyhandler.h"
#include "net/homunculushandler.h"
+#include "net/mail2handler.h"
#include "net/mailhandler.h"
#include "net/net.h"
#include "net/npchandler.h"
@@ -555,22 +556,41 @@ impHandler(imitation)
impHandler(sendMail)
{
const ServerTypeT type = Net::getNetworkType();
+#ifdef TMWA_SUPPORT
if (type == ServerType::EATHENA || type == ServerType::EVOL2)
+#endif // TMWA_SUPPORT
{
std::string name;
std::string text;
if (parse2Str(event.args, name, text))
{
- // TRANSLATORS: quick mail message caption
- mailHandler->send(name, _("Quick message"), text);
+ if (settings.enableNewMailSystem)
+ {
+ if (mail2Handler->queueSendMail(name,
+ // TRANSLATORS: quick mail message caption
+ _("Quick message"),
+ text,
+ 0))
+ {
+ mail2Handler->requestCheckName(name);
+ }
+ }
+ else
+ {
+ // TRANSLATORS: quick mail message caption
+ mailHandler->send(name, _("Quick message"), text);
+ }
}
}
+#ifdef TMWA_SUPPORT
else if (serverConfig.getBoolValue("enableManaMarketBot"))
{
chatHandler->privateMessage("ManaMarket", "!mail " + event.args);
return true;
}
+#endif // TMWA_SUPPORT
+
return false;
}
diff --git a/src/enums/resources/notifytypes.h b/src/enums/resources/notifytypes.h
index a4f9a5761..ec39b70b9 100644
--- a/src/enums/resources/notifytypes.h
+++ b/src/enums/resources/notifytypes.h
@@ -233,6 +233,7 @@ namespace NotifyTypes
BUY_FAILED_NPC_NOT_FOUND,
BUY_FAILED_SYSTEM_ERROR,
BUY_FAILED_WRONG_ITEM,
+ MAIL_NAME_VALIDATION_ERROR,
TYPE_END
};
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);
diff --git a/src/net/mail2handler.h b/src/net/mail2handler.h
index 3b04fb464..2fd0f594c 100644
--- a/src/net/mail2handler.h
+++ b/src/net/mail2handler.h
@@ -56,6 +56,11 @@ class Mail2Handler notfinal
const std::string &body,
const int64_t &money) const = 0;
+ virtual bool queueSendMail(const std::string &to,
+ const std::string &title,
+ const std::string &body,
+ const int64_t &money) const = 0;
+
virtual void nextPage(const MailOpenTypeT openType,
const int64_t mailId) const = 0;
diff --git a/src/net/tmwa/mail2handler.cpp b/src/net/tmwa/mail2handler.cpp
index 1224ed79d..b964af8cd 100644
--- a/src/net/tmwa/mail2handler.cpp
+++ b/src/net/tmwa/mail2handler.cpp
@@ -56,6 +56,14 @@ void Mail2Handler::sendMail(const std::string &to A_UNUSED,
{
}
+bool Mail2Handler::queueSendMail(const std::string &to A_UNUSED,
+ const std::string &title A_UNUSED,
+ const std::string &body A_UNUSED,
+ const int64_t &money A_UNUSED) const
+{
+ return false;
+}
+
void Mail2Handler::nextPage(const MailOpenTypeT openType A_UNUSED,
const int64_t mailId A_UNUSED) const
{
diff --git a/src/net/tmwa/mail2handler.h b/src/net/tmwa/mail2handler.h
index 0bc0e2bb2..6a3b1639b 100644
--- a/src/net/tmwa/mail2handler.h
+++ b/src/net/tmwa/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/resources/mailqueue.h b/src/resources/mailqueue.h
new file mode 100644
index 000000000..bf694ad91
--- /dev/null
+++ b/src/resources/mailqueue.h
@@ -0,0 +1,47 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2017 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef RESOURCES_MAILQUEUE_H
+#define RESOURCES_MAILQUEUE_H
+
+#include "localconsts.h"
+
+#include <string>
+
+struct MailQueue final
+{
+ MailQueue() :
+ to(),
+ title(),
+ body(),
+ money(0),
+ sendMail(false)
+ { }
+
+ A_DELETE_COPY(MailQueue)
+
+ std::string to;
+ std::string title;
+ std::string body;
+ int money;
+ bool sendMail;
+};
+
+#endif // RESOURCES_MAILQUEUE_H
diff --git a/src/resources/notifications.h b/src/resources/notifications.h
index 8fabc0217..cdfee9e3d 100644
--- a/src/resources/notifications.h
+++ b/src/resources/notifications.h
@@ -849,6 +849,10 @@ namespace NotifyManager
// TRANSLATORS: notification message
N_("Unable to buy. Wrong items selected."),
NotifyFlags::EMPTY},
+ {"mail name validation error",
+ // TRANSLATORS: notification message
+ N_("Mail destination name %s is wrong."),
+ NotifyFlags::STRING},
};
} // namespace NotifyManager
#endif // RESOURCES_NOTIFICATIONS_H