From 9239957b3a21a1498323b7af2b2910bc75f72859 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 22 Feb 2015 15:56:51 +0300 Subject: add function for convert server direction into client direction. --- src/net/eathena/messageout.cpp | 34 +--------------------------------- src/net/messageout.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/net/messageout.h | 2 ++ src/net/tmwa/messageout.cpp | 34 +--------------------------------- 4 files changed, 41 insertions(+), 66 deletions(-) (limited to 'src') diff --git a/src/net/eathena/messageout.cpp b/src/net/eathena/messageout.cpp index be3fb7172..adf9d17f7 100644 --- a/src/net/eathena/messageout.cpp +++ b/src/net/eathena/messageout.cpp @@ -115,39 +115,7 @@ void MessageOut::writeCoordinates(const uint16_t x, temp <<= 4; data[1] |= HIBYTE(temp); data[2] = LOBYTE(temp); - - // Translate direction to eAthena format - switch (direction) - { - case 1: - direction = 0; - break; - case 3: - direction = 1; - break; - case 2: - direction = 2; - break; - case 6: - direction = 3; - break; - case 4: - direction = 4; - break; - case 12: - direction = 5; - break; - case 8: - direction = 6; - break; - case 9: - direction = 7; - break; - default: - // OOPSIE! Impossible or unknown - direction = static_cast(-1); - break; - } + direction = toServerDirection(direction); data[2] |= direction; PacketCounters::incOutBytes(3); } diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp index e67044614..2d1389581 100644 --- a/src/net/messageout.cpp +++ b/src/net/messageout.cpp @@ -136,4 +136,41 @@ unsigned int MessageOut::getDataSize() const return mDataSize; } +unsigned char MessageOut::toServerDirection(unsigned char direction) +{ + // Translate direction to eAthena format + switch (direction) + { + case 1: // DOWN + direction = 0; + break; + case 3: // DOWN | LEFT + direction = 1; + break; + case 2: // LEFT + direction = 2; + break; + case 6: // LEFT | UP + direction = 3; + break; + case 4: // UP + direction = 4; + break; + case 12: // UP | RIGHT + direction = 5; + break; + case 8: // RIGHT + direction = 6; + break; + case 9: // RIGHT + DOWN + direction = 7; + break; + default: + // OOPSIE! Impossible or unknown + direction = static_cast(-1); + break; + } + return direction; +} + } // namespace Net diff --git a/src/net/messageout.h b/src/net/messageout.h index ecab8ec54..13a4eae1b 100644 --- a/src/net/messageout.h +++ b/src/net/messageout.h @@ -83,6 +83,8 @@ class MessageOut notfinal virtual ~MessageOut() { } + static unsigned char toServerDirection(unsigned char direction); + protected: /** * Constructor. diff --git a/src/net/tmwa/messageout.cpp b/src/net/tmwa/messageout.cpp index 80d49463d..1cad0657c 100644 --- a/src/net/tmwa/messageout.cpp +++ b/src/net/tmwa/messageout.cpp @@ -114,39 +114,7 @@ void MessageOut::writeCoordinates(const uint16_t x, temp <<= 4; data[1] |= HIBYTE(temp); data[2] = LOBYTE(temp); - - // Translate direction to eAthena format - switch (direction) - { - case 1: - direction = 0; - break; - case 3: - direction = 1; - break; - case 2: - direction = 2; - break; - case 6: - direction = 3; - break; - case 4: - direction = 4; - break; - case 12: - direction = 5; - break; - case 8: - direction = 6; - break; - case 9: - direction = 7; - break; - default: - // OOPSIE! Impossible or unknown - direction = static_cast(-1); - break; - } + direction = toServerDirection(direction); data[2] |= direction; PacketCounters::incOutBytes(3); } -- cgit v1.2.3-70-g09d2