From d7de4533368a36b77dbc2dbe21269690d8dc5ee5 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 18 May 2016 23:57:51 +0300 Subject: Fix random one tile desync in SMSG_BEING_MOVE3 packet. --- src/net/ea/beingrecv.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'src/net/ea') 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(x), +// static_cast(y), +// static_cast(x1), +// static_cast(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(x), + static_cast(y), + static_cast(x1), + static_cast(y1)); + } + } + } + } + } delete [] moves; } + dstBeing->setPath(path); BLOCK_END("BeingRecv::processBeingMove3") } -- cgit v1.2.3-70-g09d2