diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-09-22 21:44:22 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-09-22 21:44:22 +0300 |
commit | ab3b909187ee0a18946bff50a6bd3e8e281970f1 (patch) | |
tree | 070f99fa55315de2a4e688e5ff0397e395681d28 | |
parent | d27c8b53bcd8c7e8e0aa74656e32aeb688629b4b (diff) | |
download | mv-ab3b909187ee0a18946bff50a6bd3e8e281970f1.tar.gz mv-ab3b909187ee0a18946bff50a6bd3e8e281970f1.tar.bz2 mv-ab3b909187ee0a18946bff50a6bd3e8e281970f1.tar.xz mv-ab3b909187ee0a18946bff50a6bd3e8e281970f1.zip |
Remove checking packet id in getNpc function.
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/enums/net/npcaction.h | 34 | ||||
-rw-r--r-- | src/net/ea/npcrecv.cpp | 19 | ||||
-rw-r--r-- | src/net/eathena/npchandler.cpp | 21 | ||||
-rw-r--r-- | src/net/eathena/npchandler.h | 3 | ||||
-rw-r--r-- | src/net/npchandler.h | 5 | ||||
-rw-r--r-- | src/net/tmwa/npchandler.cpp | 16 | ||||
-rw-r--r-- | src/net/tmwa/npchandler.h | 3 |
9 files changed, 63 insertions, 40 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2272a3125..18ed37784 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -537,6 +537,7 @@ SET(SRCS enums/net/battlegroundtype.h enums/net/deleteitemreason.h enums/net/downloadstatus.h + enums/net/npcaction.h enums/net/packettype.h net/gamehandler.h net/generalhandler.h diff --git a/src/Makefile.am b/src/Makefile.am index 6587795ff..807bbcfaa 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -301,6 +301,7 @@ SRC += events/actionevent.h \ enums/net/battlegroundtype.h \ enums/net/deleteitemreason.h \ enums/net/downloadstatus.h \ + enums/net/npcaction.h \ enums/net/packettype.h \ enums/net/partyshare.h \ enums/net/servertype.h \ diff --git a/src/enums/net/npcaction.h b/src/enums/net/npcaction.h new file mode 100644 index 000000000..7fe9e3756 --- /dev/null +++ b/src/enums/net/npcaction.h @@ -0,0 +1,34 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011-2015 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 ENUMS_NET_NPCACTION_H +#define ENUMS_NET_NPCACTION_H + +#include "enums/simpletypes/enumdefines.h" + +enumStart(NpcAction) +{ + Next = 0, + Close = 1, + Other = 2 +} +enumEnd(NpcAction); + +#endif // ENUMS_NET_NPCACTION_H diff --git a/src/net/ea/npcrecv.cpp b/src/net/ea/npcrecv.cpp index e38a06531..fa4833447 100644 --- a/src/net/ea/npcrecv.cpp +++ b/src/net/ea/npcrecv.cpp @@ -44,7 +44,8 @@ namespace NpcRecv void NpcRecv::processNpcChoice(Net::MessageIn &msg) { - npcHandler->getNpc(msg); + msg.readInt16("len"); + npcHandler->getNpc(msg, NpcAction::Other); mRequestLang = false; if (mDialog) @@ -61,7 +62,8 @@ void NpcRecv::processNpcChoice(Net::MessageIn &msg) void NpcRecv::processNpcMessage(Net::MessageIn &msg) { - npcHandler->getNpc(msg); + msg.readInt16("len"); + npcHandler->getNpc(msg, NpcAction::Other); mRequestLang = false; const std::string message = msg.readString(msg.getLength() - 8, "message"); @@ -75,7 +77,7 @@ void NpcRecv::processNpcMessage(Net::MessageIn &msg) void NpcRecv::processNpcClose(Net::MessageIn &msg) { // Show the close button - npcHandler->getNpc(msg); + npcHandler->getNpc(msg, NpcAction::Close); mRequestLang = false; if (mDialog) mDialog->showCloseButton(); @@ -84,7 +86,7 @@ void NpcRecv::processNpcClose(Net::MessageIn &msg) void NpcRecv::processNpcNext(Net::MessageIn &msg) { // Show the next button - npcHandler->getNpc(msg); + npcHandler->getNpc(msg, NpcAction::Next); mRequestLang = false; if (mDialog) mDialog->showNextButton(); @@ -93,7 +95,7 @@ void NpcRecv::processNpcNext(Net::MessageIn &msg) void NpcRecv::processNpcIntInput(Net::MessageIn &msg) { // Request for an integer - npcHandler->getNpc(msg); + npcHandler->getNpc(msg, NpcAction::Other); mRequestLang = false; if (mDialog) mDialog->integerRequest(0); @@ -102,7 +104,7 @@ void NpcRecv::processNpcIntInput(Net::MessageIn &msg) void NpcRecv::processNpcStrInput(Net::MessageIn &msg) { // Request for a string - BeingId npcId = npcHandler->getNpc(msg); + BeingId npcId = npcHandler->getNpc(msg, NpcAction::Other); if (mRequestLang) { mRequestLang = false; @@ -116,7 +118,7 @@ void NpcRecv::processNpcStrInput(Net::MessageIn &msg) void NpcRecv::processNpcCommand(Net::MessageIn &msg) { - const BeingId npcId = npcHandler->getNpc(msg); + const BeingId npcId = npcHandler->getNpc(msg, NpcAction::Other); mRequestLang = false; const int cmd = msg.readInt16("cmd"); @@ -208,7 +210,8 @@ void NpcRecv::processNpcCommand(Net::MessageIn &msg) void NpcRecv::processChangeTitle(Net::MessageIn &msg) { - npcHandler->getNpc(msg); + msg.readInt16("len"); + npcHandler->getNpc(msg, NpcAction::Other); mRequestLang = false; const std::string str = msg.readString(-1, "title"); if (mDialog) diff --git a/src/net/eathena/npchandler.cpp b/src/net/eathena/npchandler.cpp index 74474b08f..97b1c28dc 100644 --- a/src/net/eathena/npchandler.cpp +++ b/src/net/eathena/npchandler.cpp @@ -34,7 +34,6 @@ #include "net/ea/npcrecv.h" #include "net/eathena/messageout.h" -#include "net/eathena/protocolin.h" #include "net/eathena/protocolout.h" #include "debug.h" @@ -196,35 +195,23 @@ void NpcHandler::selectAutoSpell(const int skillId) const outMsg.writeInt32(static_cast<int16_t>(skillId), "skill id"); } -BeingId NpcHandler::getNpc(Net::MessageIn &msg) +BeingId NpcHandler::getNpc(Net::MessageIn &msg, + const NpcAction action) { - // +++ must be removed SMSG_* - if (msg.getId() == SMSG_NPC_CHOICE - || msg.getId() == SMSG_NPC_MESSAGE - || msg.getId() == SMSG_NPC_CHANGETITLE) - { - msg.readInt16("len"); - } - const BeingId npcId = msg.readBeingId("npc id"); const NpcDialogs::const_iterator diag = NpcDialog::mNpcDialogs.find(npcId); Ea::NpcRecv::mDialog = nullptr; - // +++ must be removed SMSG_* - if (msg.getId() == SMSG_NPC_VIEWPOINT) - return npcId; - if (diag == NpcDialog::mNpcDialogs.end()) { - // +++ must be removed SMSG_* // Empty dialogs don't help - if (msg.getId() == SMSG_NPC_CLOSE) + if (action == NpcAction::Close) { closeDialog(npcId); return npcId; } - else if (msg.getId() == SMSG_NPC_NEXT) + else if (action == NpcAction::Next) { nextDialog(npcId); return npcId; diff --git a/src/net/eathena/npchandler.h b/src/net/eathena/npchandler.h index f31225de7..e05b93bd0 100644 --- a/src/net/eathena/npchandler.h +++ b/src/net/eathena/npchandler.h @@ -77,7 +77,8 @@ class NpcHandler final : public Ea::NpcHandler void refine(const int index) const override final; - BeingId getNpc(Net::MessageIn &msg) override final; + BeingId getNpc(Net::MessageIn &msg, + const NpcAction action) override final; void identify(const int index) const override final; diff --git a/src/net/npchandler.h b/src/net/npchandler.h index 29ecc5632..bad291fc8 100644 --- a/src/net/npchandler.h +++ b/src/net/npchandler.h @@ -27,6 +27,8 @@ #include "enums/being/cookingtype.h" +#include "enums/net/npcaction.h" + #include "enums/simpletypes/beingid.h" #include "enums/simpletypes/itemcolor.h" @@ -43,7 +45,8 @@ class NpcHandler notfinal virtual ~NpcHandler() { } - virtual BeingId getNpc(Net::MessageIn &msg) = 0; + virtual BeingId getNpc(Net::MessageIn &msg, + const NpcAction action) = 0; virtual void talk(const BeingId npcId) const = 0; diff --git a/src/net/tmwa/npchandler.cpp b/src/net/tmwa/npchandler.cpp index 351cb2d7a..f742ecb38 100644 --- a/src/net/tmwa/npchandler.cpp +++ b/src/net/tmwa/npchandler.cpp @@ -31,7 +31,6 @@ #include "net/messagein.h" #include "net/tmwa/messageout.h" -#include "net/tmwa/protocolin.h" #include "net/tmwa/protocolout.h" #include "net/ea/eaprotocol.h" @@ -180,16 +179,9 @@ void NpcHandler::selectAutoSpell(const int skillId A_UNUSED) const { } -BeingId NpcHandler::getNpc(Net::MessageIn &msg) +BeingId NpcHandler::getNpc(Net::MessageIn &msg, + const NpcAction action) { - // +++ must be removed packet id checks from here - if (msg.getId() == SMSG_NPC_CHOICE - || msg.getId() == SMSG_NPC_MESSAGE - || msg.getId() == SMSG_NPC_CHANGETITLE) - { - msg.readInt16("len"); - } - const BeingId npcId = msg.readBeingId("npc id"); const NpcDialogs::const_iterator diag = NpcDialog::mNpcDialogs.find(npcId); @@ -199,12 +191,12 @@ BeingId NpcHandler::getNpc(Net::MessageIn &msg) { // +++ must be removed packet id checks from here // Empty dialogs don't help - if (msg.getId() == SMSG_NPC_CLOSE) + if (action == NpcAction::Close) { closeDialog(npcId); return npcId; } - else if (msg.getId() == SMSG_NPC_NEXT) + else if (action == NpcAction::Next) { nextDialog(npcId); return npcId; diff --git a/src/net/tmwa/npchandler.h b/src/net/tmwa/npchandler.h index a69845724..51402768c 100644 --- a/src/net/tmwa/npchandler.h +++ b/src/net/tmwa/npchandler.h @@ -65,7 +65,8 @@ class NpcHandler final : public Ea::NpcHandler void completeProgressBar() const override final; - BeingId getNpc(Net::MessageIn &msg) override final; + BeingId getNpc(Net::MessageIn &msg, + const NpcAction action) override final; void produceMix(const int nameId, const int materialId1, |