diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-05-18 23:57:51 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-05-18 23:57:51 +0300 |
commit | d7de4533368a36b77dbc2dbe21269690d8dc5ee5 (patch) | |
tree | 66e83823b788015013834dcc7520b0b6bdba68b5 /src/net/ea/beingrecv.cpp | |
parent | dc0102e6eb4ca9a202e190e6ee84b7141d4e0fe1 (diff) | |
download | plus-d7de4533368a36b77dbc2dbe21269690d8dc5ee5.tar.gz plus-d7de4533368a36b77dbc2dbe21269690d8dc5ee5.tar.bz2 plus-d7de4533368a36b77dbc2dbe21269690d8dc5ee5.tar.xz plus-d7de4533368a36b77dbc2dbe21269690d8dc5ee5.zip |
Fix random one tile desync in SMSG_BEING_MOVE3 packet.
Diffstat (limited to 'src/net/ea/beingrecv.cpp')
-rw-r--r-- | src/net/ea/beingrecv.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/net/ea/beingrecv.cpp b/src/net/ea/beingrecv.cpp index fa1f47c69..0a8168c6c 100644 --- a/src/net/ea/beingrecv.cpp +++ b/src/net/ea/beingrecv.cpp @@ -45,6 +45,8 @@ #include "net/messagein.h" #include "net/serverfeatures.h" +#include "utils/checkutils.h" + #include "debug.h" namespace Ea @@ -440,6 +442,9 @@ void BeingRecv::processBeingMove3(Net::MessageIn &msg) dstBeing->setAction(BeingAction::STAND, 0); dstBeing->setTileCoords(x, y); + if (dstBeing == localPlayer) + return; + const unsigned char *moves = msg.readBytes(len, "moving path"); Path path; if (moves) @@ -458,8 +463,60 @@ void BeingRecv::processBeingMove3(Net::MessageIn &msg) logger->log("bad move packet: %d", dir); } } + const int x1 = dstBeing->getCachedX(); + const int y1 = dstBeing->getCachedY(); + if (x1 != x || y1 != y) + { +// reportAlways("Found desync being move. " +// "Calculated target (%d,%d). " +// "Actual target (%d,%d).", +// static_cast<int>(x), +// static_cast<int>(y), +// static_cast<int>(x1), +// static_cast<int>(y1)); + if (len > 0) + { + const unsigned char dir = moves[0]; + uint16_t x0 = x; + uint16_t y0 = y; + + if (dir <= 7) + { + x0 -= dirx[0]; + y0 -= diry[0]; + if (x1 == x0 && y1 == y0) + { + path.erase(path.begin()); + logger->log("Fixed being moving desync by " + "removing one tile"); + } + else + { + x0 = x; + y0 = y; + if (abs(x0 - x1) < 2 && abs(y0 - y1) < 2) + { + path.push_back(Position(x1, y1)); + logger->log("Fixed being moving desync by " + "adding one tile"); + } + else + { + reportAlways("Error: being moving desync. " + "Calculated target (%d,%d). " + "Actual target (%d,%d).", + static_cast<int>(x), + static_cast<int>(y), + static_cast<int>(x1), + static_cast<int>(y1)); + } + } + } + } + } delete [] moves; } + dstBeing->setPath(path); BLOCK_END("BeingRecv::processBeingMove3") } |