2011-02-26 03:47:23 +01:00
/*
2014-01-01 00:07:53 +01:00
* Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
2011-02-26 03:47:23 +01:00
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "WorldPacket.h"
#include "WorldSession.h"
#include "Opcodes.h"
#include "Vehicle.h"
#include "Player.h"
#include "Log.h"
2011-03-19 12:50:17 +01:00
#include "ObjectAccessor.h"
2013-04-11 01:14:32 +02:00
#include "MovementStructures.h"
2011-02-26 03:47:23 +01:00
2012-08-05 19:40:30 -05:00
void WorldSession :: HandleDismissControlledVehicle ( WorldPacket & recvData )
2011-02-26 03:47:23 +01:00
{
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "network" , "WORLD: Recvd CMSG_DISMISS_CONTROLLED_VEHICLE" );
2011-02-26 03:47:23 +01:00
uint64 vehicleGUID = _player -> GetCharmGUID ();
2011-02-26 12:53:17 +01:00
if ( ! vehicleGUID ) // something wrong here...
2011-02-26 03:47:23 +01:00
{
2012-08-05 19:40:30 -05:00
recvData . rfinish (); // prevent warnings spam
2011-02-26 03:47:23 +01:00
return ;
}
MovementInfo mi ;
2012-12-29 15:20:57 -05:00
_player -> ReadMovementInfo ( recvData , & mi );
2011-02-26 03:47:23 +01:00
_player -> m_movementInfo = mi ;
_player -> ExitVehicle ();
}
2012-08-07 10:56:55 -05:00
void WorldSession :: HandleChangeSeatsOnControlledVehicle ( WorldPacket & recvData )
2011-02-26 03:47:23 +01:00
{
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "network" , "WORLD: Recvd CMSG_CHANGE_SEATS_ON_CONTROLLED_VEHICLE" );
2011-02-26 03:47:23 +01:00
Unit * vehicle_base = GetPlayer () -> GetVehicleBase ();
if ( ! vehicle_base )
2011-02-26 12:53:17 +01:00
{
2012-08-05 19:40:30 -05:00
recvData . rfinish (); // prevent warnings spam
2011-02-26 03:47:23 +01:00
return ;
2011-02-26 12:53:17 +01:00
}
2011-02-26 03:47:23 +01:00
VehicleSeatEntry const * seat = GetPlayer () -> GetVehicle () -> GetSeatForPassenger ( GetPlayer ());
if ( ! seat -> CanSwitchFromSeat ())
{
2012-08-05 19:40:30 -05:00
recvData . rfinish (); // prevent warnings spam
2013-11-08 10:50:51 +01:00
TC_LOG_ERROR ( "network" , "HandleChangeSeatsOnControlledVehicle, Opcode: %u, Player %u tried to switch seats but current seatflags %u don't permit that." ,
2012-08-05 19:40:30 -05:00
recvData . GetOpcode (), GetPlayer () -> GetGUIDLow (), seat -> m_flags );
2011-02-26 03:47:23 +01:00
return ;
}
2012-08-10 16:58:39 +01:00
2012-08-05 19:40:30 -05:00
switch ( recvData . GetOpcode ())
2011-02-26 03:47:23 +01:00
{
2011-02-26 12:53:17 +01:00
case CMSG_REQUEST_VEHICLE_PREV_SEAT :
GetPlayer () -> ChangeSeat ( - 1 , false );
break ;
case CMSG_REQUEST_VEHICLE_NEXT_SEAT :
GetPlayer () -> ChangeSeat ( - 1 , true );
break ;
2013-04-11 01:14:32 +02:00
case CMSG_CHANGE_SEATS_ON_CONTROLLED_VEHICLE :
2011-02-26 03:47:23 +01:00
{
2013-04-11 01:14:32 +02:00
static MovementStatusElements const accessoryGuid [] =
{
MSEExtraInt8 ,
MSEHasGuidByte2 ,
2013-04-11 18:52:33 +02:00
MSEHasGuidByte4 ,
2013-04-11 01:14:32 +02:00
MSEHasGuidByte7 ,
MSEHasGuidByte6 ,
MSEHasGuidByte5 ,
MSEHasGuidByte0 ,
MSEHasGuidByte1 ,
MSEHasGuidByte3 ,
MSEGuidByte6 ,
MSEGuidByte1 ,
MSEGuidByte2 ,
MSEGuidByte5 ,
MSEGuidByte3 ,
MSEGuidByte0 ,
MSEGuidByte4 ,
MSEGuidByte7 ,
};
Movement :: ExtraMovementStatusElement extra ( accessoryGuid );
2012-05-30 08:01:02 +02:00
MovementInfo movementInfo ;
2013-04-11 01:14:32 +02:00
GetPlayer () -> ReadMovementInfo ( recvData , & movementInfo , & extra );
2012-05-30 08:01:02 +02:00
vehicle_base -> m_movementInfo = movementInfo ;
2011-02-26 03:47:23 +01:00
2013-04-11 01:14:32 +02:00
uint64 accessory = extra . Data . guid ;
int8 seatId = extra . Data . byteData ;
2011-02-26 03:47:23 +01:00
2013-04-11 01:14:32 +02:00
if ( vehicle_base -> GetGUID () != movementInfo . guid )
2011-02-26 03:47:23 +01:00
return ;
if ( ! accessory )
GetPlayer () -> ChangeSeat ( - 1 , seatId > 0 ); // prev/next
2011-09-15 14:08:17 +02:00
else if ( Unit * vehUnit = Unit :: GetUnit ( * GetPlayer (), accessory ))
2011-02-26 03:47:23 +01:00
{
2011-09-15 14:08:17 +02:00
if ( Vehicle * vehicle = vehUnit -> GetVehicleKit ())
2011-02-26 03:47:23 +01:00
if ( vehicle -> HasEmptySeat ( seatId ))
2011-03-21 19:37:21 +01:00
vehUnit -> HandleSpellClick ( GetPlayer (), seatId );
2011-02-26 03:47:23 +01:00
}
2011-02-26 12:53:17 +01:00
break ;
2013-04-11 01:14:32 +02:00
}
2011-02-26 12:53:17 +01:00
case CMSG_REQUEST_VEHICLE_SWITCH_SEAT :
2011-02-26 03:47:23 +01:00
{
uint64 guid ; // current vehicle guid
2012-08-05 19:40:30 -05:00
recvData . readPackGUID ( guid );
2011-02-26 03:47:23 +01:00
int8 seatId ;
2012-08-05 19:40:30 -05:00
recvData >> seatId ;
2011-02-26 03:47:23 +01:00
if ( vehicle_base -> GetGUID () == guid )
GetPlayer () -> ChangeSeat ( seatId );
2011-09-15 14:08:17 +02:00
else if ( Unit * vehUnit = Unit :: GetUnit ( * GetPlayer (), guid ))
if ( Vehicle * vehicle = vehUnit -> GetVehicleKit ())
2011-02-26 03:47:23 +01:00
if ( vehicle -> HasEmptySeat ( seatId ))
2011-03-21 19:37:21 +01:00
vehUnit -> HandleSpellClick ( GetPlayer (), seatId );
2011-02-26 12:53:17 +01:00
break ;
2011-02-26 03:47:23 +01:00
}
2011-02-26 12:53:17 +01:00
default :
break ;
2012-08-09 18:46:59 -05:00
}
2011-02-26 03:47:23 +01:00
}
2012-08-09 18:46:59 -05:00
void WorldSession :: HandleEnterPlayerVehicle ( WorldPacket & data )
2011-02-26 03:47:23 +01:00
{
// Read guid
uint64 guid ;
data >> guid ;
2011-11-07 11:18:00 -06:00
if ( Player * player = ObjectAccessor :: FindPlayer ( guid ))
2011-02-26 03:47:23 +01:00
{
2011-11-07 11:18:00 -06:00
if ( ! player -> GetVehicleKit ())
2011-02-26 03:47:23 +01:00
return ;
2011-11-07 11:18:00 -06:00
if ( ! player -> IsInRaidWith ( _player ))
2011-02-26 03:47:23 +01:00
return ;
2011-11-07 11:18:00 -06:00
if ( ! player -> IsWithinDistInMap ( _player , INTERACTION_DISTANCE ))
2011-02-26 03:47:23 +01:00
return ;
2011-02-26 12:53:17 +01:00
2011-11-07 11:18:00 -06:00
_player -> EnterVehicle ( player );
2011-02-26 03:47:23 +01:00
}
}
2012-08-09 18:46:59 -05:00
void WorldSession :: HandleEjectPassenger ( WorldPacket & data )
2011-02-26 03:47:23 +01:00
{
Vehicle * vehicle = _player -> GetVehicleKit ();
if ( ! vehicle )
{
2011-02-26 12:55:15 +01:00
data . rfinish (); // prevent warnings spam
2013-11-08 10:50:51 +01:00
TC_LOG_ERROR ( "network" , "HandleEjectPassenger: Player %u is not in a vehicle!" , GetPlayer () -> GetGUIDLow ());
2011-02-26 03:47:23 +01:00
return ;
}
uint64 guid ;
data >> guid ;
if ( IS_PLAYER_GUID ( guid ))
{
2011-11-07 11:06:39 -06:00
Player * player = ObjectAccessor :: FindPlayer ( guid );
if ( ! player )
2011-02-26 03:47:23 +01:00
{
2013-11-08 10:50:51 +01:00
TC_LOG_ERROR ( "network" , "Player %u tried to eject player %u from vehicle, but the latter was not found in world!" , GetPlayer () -> GetGUIDLow (), GUID_LOPART ( guid ));
2011-02-26 03:47:23 +01:00
return ;
}
2011-11-07 11:06:39 -06:00
if ( ! player -> IsOnVehicle ( vehicle -> GetBase ()))
2011-02-26 03:47:23 +01:00
{
2013-11-08 10:50:51 +01:00
TC_LOG_ERROR ( "network" , "Player %u tried to eject player %u, but they are not in the same vehicle" , GetPlayer () -> GetGUIDLow (), GUID_LOPART ( guid ));
2011-02-26 03:47:23 +01:00
return ;
}
2011-11-07 11:06:39 -06:00
VehicleSeatEntry const * seat = vehicle -> GetSeatForPassenger ( player );
2011-02-26 03:47:23 +01:00
ASSERT ( seat );
if ( seat -> IsEjectable ())
2011-11-07 11:06:39 -06:00
player -> ExitVehicle ();
2011-02-26 03:47:23 +01:00
else
2013-11-08 10:50:51 +01:00
TC_LOG_ERROR ( "network" , "Player %u attempted to eject player %u from non-ejectable seat." , GetPlayer () -> GetGUIDLow (), GUID_LOPART ( guid ));
2011-02-26 03:47:23 +01:00
}
else if ( IS_CREATURE_GUID ( guid ))
{
2011-09-15 14:08:17 +02:00
Unit * unit = ObjectAccessor :: GetUnit ( * _player , guid );
2011-02-26 03:47:23 +01:00
if ( ! unit ) // creatures can be ejected too from player mounts
{
2013-11-08 10:50:51 +01:00
TC_LOG_ERROR ( "network" , "Player %u tried to eject creature guid %u from vehicle, but the latter was not found in world!" , GetPlayer () -> GetGUIDLow (), GUID_LOPART ( guid ));
2011-02-26 03:47:23 +01:00
return ;
}
if ( ! unit -> IsOnVehicle ( vehicle -> GetBase ()))
{
2013-11-08 10:50:51 +01:00
TC_LOG_ERROR ( "network" , "Player %u tried to eject unit %u, but they are not in the same vehicle" , GetPlayer () -> GetGUIDLow (), GUID_LOPART ( guid ));
2011-02-26 03:47:23 +01:00
return ;
}
VehicleSeatEntry const * seat = vehicle -> GetSeatForPassenger ( unit );
ASSERT ( seat );
if ( seat -> IsEjectable ())
{
ASSERT ( GetPlayer () == vehicle -> GetBase ());
unit -> ExitVehicle ();
}
else
2013-11-08 10:50:51 +01:00
TC_LOG_ERROR ( "network" , "Player %u attempted to eject creature GUID %u from non-ejectable seat." , GetPlayer () -> GetGUIDLow (), GUID_LOPART ( guid ));
2011-02-26 03:47:23 +01:00
}
else
2013-11-08 10:50:51 +01:00
TC_LOG_ERROR ( "network" , "HandleEjectPassenger: Player %u tried to eject invalid GUID " UI64FMTD , GetPlayer () -> GetGUIDLow (), guid );
2011-02-26 03:47:23 +01:00
}
2012-08-05 19:40:30 -05:00
void WorldSession :: HandleRequestVehicleExit ( WorldPacket & /*recvData*/ )
2011-02-26 03:47:23 +01:00
{
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "network" , "WORLD: Recvd CMSG_REQUEST_VEHICLE_EXIT" );
2011-02-26 03:47:23 +01:00
if ( Vehicle * vehicle = GetPlayer () -> GetVehicle ())
{
if ( VehicleSeatEntry const * seat = vehicle -> GetSeatForPassenger ( GetPlayer ()))
{
if ( seat -> CanEnterOrExit ())
GetPlayer () -> ExitVehicle ();
else
2013-11-08 10:50:51 +01:00
TC_LOG_ERROR ( "network" , "Player %u tried to exit vehicle, but seatflags %u (ID: %u) don ' t permit that . ",
2011-02-26 03:47:23 +01:00
GetPlayer () -> GetGUIDLow (), seat -> m_ID , seat -> m_flags );
}
}
2011-02-26 12:53:17 +01:00
}