Skip to content

Instantly share code, notes, and snippets.

@Shauren
Created May 4, 2020 18:05
Show Gist options
  • Save Shauren/0e4aa70124d511f6fa21eaf53327a93d to your computer and use it in GitHub Desktop.
Save Shauren/0e4aa70124d511f6fa21eaf53327a93d to your computer and use it in GitHub Desktop.
diff --git a/src/server/game/Entities/Vehicle/Vehicle.cpp b/src/server/game/Entities/Vehicle/Vehicle.cpp
index 4c333e6574..36f40e9a91 100755
--- a/src/server/game/Entities/Vehicle/Vehicle.cpp
+++ b/src/server/game/Entities/Vehicle/Vehicle.cpp
@@ -30,6 +30,7 @@
#include "ScriptMgr.h"
#include "SpellAuraEffects.h"
#include "TemporarySummon.h"
+#include "Transport.h"
#include "Unit.h"
#include "Util.h"
@@ -519,13 +520,16 @@ Vehicle* Vehicle::RemovePassenger(Unit* unit)
if (_me->IsInWorld())
{
- if (!_me->GetTransport())
+ if (Transport* transport = _me->GetTransport())
+ {
+ transport->AddPassenger(unit);
+ unit->m_movementInfo.transport = _me->m_movementInfo.transport;
+ }
+ else
{
unit->RemoveUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT);
unit->m_movementInfo.transport.Reset();
}
- else
- unit->m_movementInfo.transport = _me->m_movementInfo.transport;
}
// only for flyable vehicles
diff --git a/src/server/game/Handlers/MovementHandler.cpp b/src/server/game/Handlers/MovementHandler.cpp
index 28c7d88f62..500862c83c 100644
--- a/src/server/game/Handlers/MovementHandler.cpp
+++ b/src/server/game/Handlers/MovementHandler.cpp
@@ -438,6 +438,102 @@ void WorldSession::HandleMovementOpcodes(WorldPacket& recvData)
}
}
+void WorldSession::HandleMoveChangeTransportOpcode(WorldPacket& recvData)
+{
+ uint16 opcode = recvData.GetOpcode();
+
+ /* extract packet */
+ ObjectGuid guid;
+
+ recvData >> guid.ReadAsPacked();
+
+ MovementInfo movementInfo;
+ movementInfo.guid = guid;
+ ReadMovementInfo(recvData, &movementInfo);
+
+ Unit* mover = _player->GetUnitBeingMoved();
+
+ // prevent tampered movement data
+ if (guid != mover->GetGUID() && movementInfo.transport.guid != mover->GetGUID())
+ return;
+
+ // ignore, waiting processing in WorldSession::HandleMoveWorldportAckOpcode and WorldSession::HandleMoveTeleportAck
+ if (_player->IsBeingTeleported())
+ return;
+
+ if (!movementInfo.pos.IsPositionValid())
+ return;
+
+ /* handle special cases */
+ if (movementInfo.HasMovementFlag(MOVEMENTFLAG_ONTRANSPORT))
+ {
+ // We were teleported, skip packets that were broadcast before teleport
+ if (movementInfo.pos.GetExactDist2d(_player) > SIZE_OF_GRIDS)
+ {
+ recvData.rfinish(); // prevent warnings spam
+ return;
+ }
+
+ // transports size limited
+ // (also received at zeppelin leave by some reason with t_* as absolute in continent coordinates, can be safely skipped)
+ if (fabs(movementInfo.transport.pos.GetPositionX()) > 75.0f || fabs(movementInfo.transport.pos.GetPositionY()) > 75.0f || fabs(movementInfo.transport.pos.GetPositionZ()) > 75.0f)
+ {
+ recvData.rfinish(); // prevent warnings spam
+ return;
+ }
+
+ if (!Trinity::IsValidMapCoord(movementInfo.pos.GetPositionX() + movementInfo.transport.pos.GetPositionX(), movementInfo.pos.GetPositionY() + movementInfo.transport.pos.GetPositionY(),
+ movementInfo.pos.GetPositionZ() + movementInfo.transport.pos.GetPositionZ(), movementInfo.pos.GetOrientation() + movementInfo.transport.pos.GetOrientation()))
+ {
+ recvData.rfinish(); // prevent warnings spam
+ return;
+ }
+
+ // if we boarded a transport, add us to it
+ if (!_player->GetTransport())
+ {
+ if (Transport* transport = _player->GetMap()->GetTransport(movementInfo.transport.guid))
+ transport->AddPassenger(_player);
+ }
+ else if (_player->GetTransport()->GetGUID() != movementInfo.transport.guid)
+ {
+ _player->GetTransport()->RemovePassenger(_player);
+ if (Transport* transport = _player->GetMap()->GetTransport(movementInfo.transport.guid))
+ transport->AddPassenger(_player);
+ else if (movementInfo.transport.guid != mover->GetGUID()) // entered vehicle on a transport
+ movementInfo.transport.Reset();
+ }
+
+ if (!_player->GetTransport() && !_player->GetVehicle())
+ {
+ GameObject* go = _player->GetMap()->GetGameObject(movementInfo.transport.guid);
+ if (!go || go->GetGoType() != GAMEOBJECT_TYPE_TRANSPORT)
+ movementInfo.RemoveMovementFlag(MOVEMENTFLAG_ONTRANSPORT);
+ }
+ }
+ else if (_player->GetTransport()) // if we were on a transport, leave
+ {
+ _player->GetTransport()->RemovePassenger(_player);
+ movementInfo.transport.Reset();
+ }
+
+ WorldPacket data(MSG_MOVE_HEARTBEAT, recvData.size());
+ int64 movementTime = (int64)movementInfo.time + _timeSyncClockDelta;
+ if (_timeSyncClockDelta == 0 || movementTime < 0 || movementTime > 0xFFFFFFFF)
+ {
+ TC_LOG_WARN("misc", "The computed movement time using clockDelta is erronous. Using fallback instead");
+ _player->m_movementInfo.time = GameTime::GetGameTimeMS();
+ }
+ else
+ {
+ _player->m_movementInfo.time = (uint32)movementTime;
+ }
+
+ _player->m_movementInfo.transport = movementInfo.transport;
+ WriteMovementInfo(&data, &_player->m_movementInfo);
+ _player->SendMessageToSet(&data, _player);
+}
+
void WorldSession::HandleForceSpeedChangeAck(WorldPacket &recvData)
{
/* extract packet */
diff --git a/src/server/game/Server/Protocol/Opcodes.cpp b/src/server/game/Server/Protocol/Opcodes.cpp
index fbf2a23257..9578fb1ef8 100644
--- a/src/server/game/Server/Protocol/Opcodes.cpp
+++ b/src/server/game/Server/Protocol/Opcodes.cpp
@@ -1037,7 +1037,7 @@ void OpcodeTable::Initialize()
/*0x38A*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_JOINED_BATTLEGROUND_QUEUE, STATUS_NEVER);
/*0x38B*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_REALM_SPLIT, STATUS_NEVER);
/*0x38C*/ DEFINE_HANDLER(CMSG_REALM_SPLIT, STATUS_AUTHED, PROCESS_THREADUNSAFE, &WorldSession::HandleRealmSplitOpcode );
- /*0x38D*/ DEFINE_HANDLER(CMSG_MOVE_CHNG_TRANSPORT, STATUS_LOGGEDIN, PROCESS_THREADSAFE, &WorldSession::HandleMovementOpcodes );
+ /*0x38D*/ DEFINE_HANDLER(CMSG_MOVE_CHNG_TRANSPORT, STATUS_LOGGEDIN, PROCESS_THREADSAFE, &WorldSession::HandleMoveChangeTransportOpcode );
/*0x38E*/ DEFINE_HANDLER(MSG_PARTY_ASSIGNMENT, STATUS_LOGGEDIN, PROCESS_THREADUNSAFE, &WorldSession::HandlePartyAssignmentOpcode );
/*0x38F*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_OFFER_PETITION_ERROR, STATUS_NEVER);
/*0x390*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_TIME_SYNC_REQ, STATUS_NEVER);
diff --git a/src/server/game/Server/WorldSession.h b/src/server/game/Server/WorldSession.h
index 1621ba03de..399ec478f8 100644
--- a/src/server/game/Server/WorldSession.h
+++ b/src/server/game/Server/WorldSession.h
@@ -676,6 +676,7 @@ class TC_GAME_API WorldSession
void HandleMoveWorldportAck(); // for server-side calls
void HandleMovementOpcodes(WorldPacket& recvPacket);
+ void HandleMoveChangeTransportOpcode(WorldPacket& recvPacket);
void HandleSetActiveMoverOpcode(WorldPacket& recvData);
void HandleMoveNotActiveMover(WorldPacket& recvData);
void HandleDismissControlledVehicle(WorldPacket& recvData);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment