summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-08-30 22:32:39 +0300
committerAndrei Karas <akaras@inbox.ru>2014-08-30 22:32:39 +0300
commit3f8010f23e112c1cf6506c327cdddc5260867299 (patch)
tree8f594a37ca9a89f0837ee4f4a98b5b7bb9a950c0 /src/net
parent105745205558ea0f4f8705e1630a6f7055c68e34 (diff)
downloadmv-3f8010f23e112c1cf6506c327cdddc5260867299.tar.gz
mv-3f8010f23e112c1cf6506c327cdddc5260867299.tar.bz2
mv-3f8010f23e112c1cf6506c327cdddc5260867299.tar.xz
mv-3f8010f23e112c1cf6506c327cdddc5260867299.zip
Simplify getNpc function usage.
Diffstat (limited to 'src/net')
-rw-r--r--src/net/ea/npchandler.h3
-rw-r--r--src/net/eathena/npchandler.cpp22
-rw-r--r--src/net/eathena/npchandler.h2
-rw-r--r--src/net/tmwa/npchandler.cpp36
-rw-r--r--src/net/tmwa/npchandler.h3
5 files changed, 43 insertions, 23 deletions
diff --git a/src/net/ea/npchandler.h b/src/net/ea/npchandler.h
index d6986a219..bfbc9dcfb 100644
--- a/src/net/ea/npchandler.h
+++ b/src/net/ea/npchandler.h
@@ -49,8 +49,7 @@ class NpcHandler notfinal : public Net::NpcHandler
void endShopping(const int beingId) const override final;
- virtual int getNpc(Net::MessageIn &msg,
- bool haveLength) A_WARN_UNUSED = 0;
+ virtual int getNpc(Net::MessageIn &msg) A_WARN_UNUSED = 0;
void processNpcChoice(Net::MessageIn &msg);
diff --git a/src/net/eathena/npchandler.cpp b/src/net/eathena/npchandler.cpp
index 76ae7d3b5..a15d6480e 100644
--- a/src/net/eathena/npchandler.cpp
+++ b/src/net/eathena/npchandler.cpp
@@ -65,32 +65,32 @@ void NpcHandler::handleMessage(Net::MessageIn &msg)
switch (msg.getId())
{
case SMSG_NPC_CHOICE:
- getNpc(msg, true);
+ getNpc(msg);
processNpcChoice(msg);
break;
case SMSG_NPC_MESSAGE:
- getNpc(msg, true);
+ getNpc(msg);
processNpcMessage(msg);
break;
case SMSG_NPC_CLOSE:
- getNpc(msg, false);
+ getNpc(msg);
processNpcClose(msg);
break;
case SMSG_NPC_NEXT:
- getNpc(msg, false);
+ getNpc(msg);
processNpcNext(msg);
break;
case SMSG_NPC_INT_INPUT:
- getNpc(msg, false);
+ getNpc(msg);
processNpcIntInput(msg);
break;
case SMSG_NPC_STR_INPUT:
- getNpc(msg, false);
+ getNpc(msg);
processNpcStrInput(msg);
break;
@@ -99,7 +99,7 @@ void NpcHandler::handleMessage(Net::MessageIn &msg)
break;
case SMSG_NPC_VIEWPOINT:
- getNpc(msg, true);
+ npcId = getNpc(msg);
processNpcViewPoint(msg, npcId);
break;
@@ -196,10 +196,14 @@ void NpcHandler::sellItem(const int beingId A_UNUSED,
outMsg.writeInt16(static_cast<int16_t>(amount));
}
-int NpcHandler::getNpc(Net::MessageIn &msg, const bool haveLength)
+int NpcHandler::getNpc(Net::MessageIn &msg)
{
- if (haveLength)
+ if (msg.getId() == SMSG_NPC_CHOICE
+ || msg.getId() == SMSG_NPC_MESSAGE
+ || msg.getId() == SMSG_NPC_VIEWPOINT)
+ {
msg.readInt16(); // length
+ }
const int npcId = msg.readInt32();
diff --git a/src/net/eathena/npchandler.h b/src/net/eathena/npchandler.h
index 8c2f61b55..68f64e072 100644
--- a/src/net/eathena/npchandler.h
+++ b/src/net/eathena/npchandler.h
@@ -65,7 +65,7 @@ class NpcHandler final : public MessageHandler, public Ea::NpcHandler
void sellItem(const int beingId, const int itemId,
const int amount) const override final;
- int getNpc(Net::MessageIn &msg, const bool haveLength) override final;
+ int getNpc(Net::MessageIn &msg) override final;
static void processNpcCutin(Net::MessageIn &msg, const int npcId);
diff --git a/src/net/tmwa/npchandler.cpp b/src/net/tmwa/npchandler.cpp
index 534ee99db..3a9ee00a9 100644
--- a/src/net/tmwa/npchandler.cpp
+++ b/src/net/tmwa/npchandler.cpp
@@ -68,49 +68,63 @@ void NpcHandler::handleMessage(Net::MessageIn &msg)
{
BLOCK_START("NpcHandler::handleMessage")
- const int npcId = getNpc(msg, msg.getId() == SMSG_NPC_CHOICE
- || msg.getId() == SMSG_NPC_MESSAGE
- || msg.getId() == SMSG_NPC_CHANGETITLE);
-
- if (msg.getId() != SMSG_NPC_STR_INPUT)
- mRequestLang = false;
-
switch (msg.getId())
{
case SMSG_NPC_CHOICE:
+ getNpc(msg);
+ mRequestLang = false;
processNpcChoice(msg);
break;
case SMSG_NPC_MESSAGE:
+ getNpc(msg);
+ mRequestLang = false;
processNpcMessage(msg);
break;
case SMSG_NPC_CLOSE:
+ getNpc(msg);
+ mRequestLang = false;
processNpcClose(msg);
break;
case SMSG_NPC_NEXT:
+ getNpc(msg);
+ mRequestLang = false;
processNpcNext(msg);
break;
case SMSG_NPC_INT_INPUT:
+ getNpc(msg);
+ mRequestLang = false;
processNpcIntInput(msg);
break;
case SMSG_NPC_STR_INPUT:
+ {
+ const int npcId = getNpc(msg);
if (mRequestLang)
processLangReuqest(msg, npcId);
else
processNpcStrInput(msg);
break;
+ }
case SMSG_NPC_COMMAND:
+ {
+ const int npcId = getNpc(msg);
+ mRequestLang = false;
processNpcCommand(msg, npcId);
break;
+ }
case SMSG_NPC_CHANGETITLE:
+ {
+ const int npcId = getNpc(msg);
+ mRequestLang = false;
processChangeTitle(msg, npcId);
break;
+ }
default:
break;
@@ -216,10 +230,14 @@ void NpcHandler::sellItem(const int beingId A_UNUSED,
outMsg.writeInt16(static_cast<int16_t>(amount));
}
-int NpcHandler::getNpc(Net::MessageIn &msg, const bool haveLength)
+int NpcHandler::getNpc(Net::MessageIn &msg)
{
- if (haveLength)
+ if (msg.getId() == SMSG_NPC_CHOICE
+ || msg.getId() == SMSG_NPC_MESSAGE
+ || msg.getId() == SMSG_NPC_CHANGETITLE)
+ {
msg.readInt16(); // length
+ }
const int npcId = msg.readInt32();
diff --git a/src/net/tmwa/npchandler.h b/src/net/tmwa/npchandler.h
index b36255bc2..f4b982a35 100644
--- a/src/net/tmwa/npchandler.h
+++ b/src/net/tmwa/npchandler.h
@@ -65,8 +65,7 @@ class NpcHandler final : public MessageHandler, public Ea::NpcHandler
void sellItem(const int beingId, const int itemId,
const int amount) const override final;
- int getNpc(Net::MessageIn &msg,
- const bool haveLength) override final A_WARN_UNUSED;
+ int getNpc(Net::MessageIn &msg) override final A_WARN_UNUSED;
void processNpcCommand(Net::MessageIn &msg, const int npcId);