From ab3b909187ee0a18946bff50a6bd3e8e281970f1 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 22 Sep 2015 21:44:22 +0300 Subject: Remove checking packet id in getNpc function. --- src/net/ea/npcrecv.cpp | 19 +++++++++++-------- src/net/eathena/npchandler.cpp | 21 ++++----------------- src/net/eathena/npchandler.h | 3 ++- src/net/npchandler.h | 5 ++++- src/net/tmwa/npchandler.cpp | 16 ++++------------ src/net/tmwa/npchandler.h | 3 ++- 6 files changed, 27 insertions(+), 40 deletions(-) (limited to 'src/net') 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(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, -- cgit v1.2.3-70-g09d2