[2] | 1 | /* |
---|
| 2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
| 3 | * |
---|
| 4 | * This program is free software; you can redistribute it and/or modify |
---|
| 5 | * it under the terms of the GNU General Public License as published by |
---|
| 6 | * the Free Software Foundation; either version 2 of the License, or |
---|
| 7 | * (at your option) any later version. |
---|
| 8 | * |
---|
| 9 | * This program is distributed in the hope that it will be useful, |
---|
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 12 | * GNU General Public License for more details. |
---|
| 13 | * |
---|
| 14 | * You should have received a copy of the GNU General Public License |
---|
| 15 | * along with this program; if not, write to the Free Software |
---|
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 17 | */ |
---|
| 18 | |
---|
| 19 | #include "Common.h" |
---|
| 20 | #include "WorldPacket.h" |
---|
| 21 | #include "WorldSession.h" |
---|
| 22 | #include "Opcodes.h" |
---|
| 23 | #include "Log.h" |
---|
| 24 | #include "World.h" |
---|
| 25 | #include "Corpse.h" |
---|
| 26 | #include "Player.h" |
---|
| 27 | #include "MapManager.h" |
---|
| 28 | #include "Transports.h" |
---|
| 29 | #include "BattleGround.h" |
---|
| 30 | #include "WaypointMovementGenerator.h" |
---|
| 31 | #include "InstanceSaveMgr.h" |
---|
| 32 | |
---|
| 33 | void WorldSession::HandleMoveWorldportAckOpcode( WorldPacket & /*recv_data*/ ) |
---|
| 34 | { |
---|
| 35 | sLog.outDebug( "WORLD: got MSG_MOVE_WORLDPORT_ACK." ); |
---|
| 36 | HandleMoveWorldportAckOpcode(); |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | void WorldSession::HandleMoveWorldportAckOpcode() |
---|
| 40 | { |
---|
| 41 | // get the teleport destination |
---|
| 42 | WorldLocation &loc = GetPlayer()->GetTeleportDest(); |
---|
| 43 | |
---|
| 44 | // possible errors in the coordinate validity check |
---|
| 45 | if(!MapManager::IsValidMapCoord(loc.mapid,loc.x,loc.y,loc.z,loc.o)) |
---|
| 46 | { |
---|
| 47 | LogoutPlayer(false); |
---|
| 48 | return; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | // get the destination map entry, not the current one, this will fix homebind and reset greeting |
---|
| 52 | MapEntry const* mEntry = sMapStore.LookupEntry(loc.mapid); |
---|
| 53 | InstanceTemplate const* mInstance = objmgr.GetInstanceTemplate(loc.mapid); |
---|
| 54 | |
---|
| 55 | // reset instance validity, except if going to an instance inside an instance |
---|
| 56 | if(GetPlayer()->m_InstanceValid == false && !mInstance) |
---|
| 57 | GetPlayer()->m_InstanceValid = true; |
---|
| 58 | |
---|
| 59 | GetPlayer()->SetSemaphoreTeleport(false); |
---|
| 60 | |
---|
| 61 | // relocate the player to the teleport destination |
---|
| 62 | GetPlayer()->SetMapId(loc.mapid); |
---|
| 63 | GetPlayer()->Relocate(loc.x, loc.y, loc.z, loc.o); |
---|
| 64 | |
---|
| 65 | // since the MapId is set before the GetInstance call, the InstanceId must be set to 0 |
---|
| 66 | // to let GetInstance() determine the proper InstanceId based on the player's binds |
---|
| 67 | GetPlayer()->SetInstanceId(0); |
---|
| 68 | |
---|
| 69 | // check this before Map::Add(player), because that will create the instance save! |
---|
| 70 | bool reset_notify = (GetPlayer()->GetBoundInstance(GetPlayer()->GetMapId(), GetPlayer()->GetDifficulty()) == NULL); |
---|
| 71 | |
---|
| 72 | GetPlayer()->SendInitialPacketsBeforeAddToMap(); |
---|
| 73 | // the CanEnter checks are done in TeleporTo but conditions may change |
---|
| 74 | // while the player is in transit, for example the map may get full |
---|
| 75 | if(!MapManager::Instance().GetMap(GetPlayer()->GetMapId(), GetPlayer())->Add(GetPlayer())) |
---|
| 76 | { |
---|
| 77 | sLog.outDebug("WORLD: teleport of player %s (%d) to location %d,%f,%f,%f,%f failed", GetPlayer()->GetName(), GetPlayer()->GetGUIDLow(), loc.mapid, loc.x, loc.y, loc.z, loc.o); |
---|
| 78 | // teleport the player home |
---|
| 79 | GetPlayer()->SetDontMove(false); |
---|
| 80 | if(!GetPlayer()->TeleportTo(GetPlayer()->m_homebindMapId, GetPlayer()->m_homebindX, GetPlayer()->m_homebindY, GetPlayer()->m_homebindZ, GetPlayer()->GetOrientation())) |
---|
| 81 | { |
---|
| 82 | // the player must always be able to teleport home |
---|
| 83 | sLog.outError("WORLD: failed to teleport player %s (%d) to homebind location %d,%f,%f,%f,%f!", GetPlayer()->GetName(), GetPlayer()->GetGUIDLow(), GetPlayer()->m_homebindMapId, GetPlayer()->m_homebindX, GetPlayer()->m_homebindY, GetPlayer()->m_homebindZ, GetPlayer()->GetOrientation()); |
---|
| 84 | assert(false); |
---|
| 85 | } |
---|
| 86 | return; |
---|
| 87 | } |
---|
| 88 | GetPlayer()->SendInitialPacketsAfterAddToMap(); |
---|
| 89 | |
---|
| 90 | // flight fast teleport case |
---|
| 91 | if(GetPlayer()->GetMotionMaster()->GetCurrentMovementGeneratorType()==FLIGHT_MOTION_TYPE) |
---|
| 92 | { |
---|
| 93 | if(!_player->InBattleGround()) |
---|
| 94 | { |
---|
| 95 | // short preparations to continue flight |
---|
| 96 | GetPlayer()->SetDontMove(false); |
---|
| 97 | FlightPathMovementGenerator* flight = (FlightPathMovementGenerator*)(GetPlayer()->GetMotionMaster()->top()); |
---|
| 98 | flight->Initialize(*GetPlayer()); |
---|
| 99 | return; |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | // battleground state prepare, stop flight |
---|
| 103 | GetPlayer()->GetMotionMaster()->MovementExpired(); |
---|
| 104 | GetPlayer()->m_taxi.ClearTaxiDestinations(); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | // resurrect character at enter into instance where his corpse exist after add to map |
---|
| 108 | Corpse *corpse = GetPlayer()->GetCorpse(); |
---|
| 109 | if (corpse && corpse->GetType() != CORPSE_BONES && corpse->GetMapId() == GetPlayer()->GetMapId()) |
---|
| 110 | { |
---|
| 111 | if( mEntry->IsDungeon() ) |
---|
| 112 | { |
---|
| 113 | GetPlayer()->ResurrectPlayer(0.5f,false); |
---|
| 114 | GetPlayer()->SpawnCorpseBones(); |
---|
| 115 | GetPlayer()->SaveToDB(); |
---|
| 116 | } |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | if(mEntry->IsRaid() && mInstance) |
---|
| 120 | { |
---|
| 121 | if(reset_notify) |
---|
| 122 | { |
---|
| 123 | uint32 timeleft = sInstanceSaveManager.GetResetTimeFor(GetPlayer()->GetMapId()) - time(NULL); |
---|
| 124 | GetPlayer()->SendInstanceResetWarning(GetPlayer()->GetMapId(), timeleft); // greeting at the entrance of the resort raid instance |
---|
| 125 | } |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | // mount allow check |
---|
| 129 | if(!mEntry->IsMountAllowed()) |
---|
| 130 | _player->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED); |
---|
| 131 | |
---|
| 132 | // battleground state preper |
---|
| 133 | if(_player->InBattleGround()) |
---|
| 134 | { |
---|
| 135 | BattleGround *bg = _player->GetBattleGround(); |
---|
| 136 | if(bg) |
---|
| 137 | { |
---|
| 138 | if(bg->GetMapId() == _player->GetMapId()) // we teleported to bg |
---|
| 139 | { |
---|
| 140 | if(!bg->GetBgRaid(_player->GetTeam())) // first player joined |
---|
| 141 | { |
---|
| 142 | Group *group = new Group; |
---|
| 143 | bg->SetBgRaid(_player->GetTeam(), group); |
---|
| 144 | group->Create(_player->GetGUIDLow(), _player->GetName()); |
---|
| 145 | } |
---|
| 146 | else // raid already exist |
---|
| 147 | { |
---|
| 148 | bg->GetBgRaid(_player->GetTeam())->AddMember(_player->GetGUID(), _player->GetName()); |
---|
| 149 | } |
---|
| 150 | } |
---|
| 151 | } |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | // honorless target |
---|
| 155 | if(GetPlayer()->pvpInfo.inHostileArea) |
---|
| 156 | GetPlayer()->CastSpell(GetPlayer(), 2479, true); |
---|
| 157 | |
---|
| 158 | // resummon pet |
---|
| 159 | if(GetPlayer()->m_temporaryUnsummonedPetNumber) |
---|
| 160 | { |
---|
| 161 | Pet* NewPet = new Pet; |
---|
| 162 | if(!NewPet->LoadPetFromDB(GetPlayer(), 0, GetPlayer()->m_temporaryUnsummonedPetNumber, true)) |
---|
| 163 | delete NewPet; |
---|
| 164 | |
---|
| 165 | GetPlayer()->m_temporaryUnsummonedPetNumber = 0; |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | GetPlayer()->SetDontMove(false); |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | void WorldSession::HandleMovementOpcodes( WorldPacket & recv_data ) |
---|
| 172 | { |
---|
| 173 | CHECK_PACKET_SIZE(recv_data, 4+1+4+4+4+4+4); |
---|
| 174 | |
---|
| 175 | if(GetPlayer()->GetDontMove()) |
---|
| 176 | return; |
---|
| 177 | |
---|
| 178 | /* extract packet */ |
---|
| 179 | MovementInfo movementInfo; |
---|
| 180 | uint32 MovementFlags; |
---|
| 181 | |
---|
| 182 | recv_data >> MovementFlags; |
---|
| 183 | recv_data >> movementInfo.unk1; |
---|
| 184 | recv_data >> movementInfo.time; |
---|
| 185 | recv_data >> movementInfo.x; |
---|
| 186 | recv_data >> movementInfo.y; |
---|
| 187 | recv_data >> movementInfo.z; |
---|
| 188 | recv_data >> movementInfo.o; |
---|
| 189 | |
---|
| 190 | //Save movement flags |
---|
| 191 | _player->SetUnitMovementFlags(MovementFlags); |
---|
| 192 | |
---|
| 193 | if(MovementFlags & MOVEMENTFLAG_ONTRANSPORT) |
---|
| 194 | { |
---|
| 195 | // recheck |
---|
| 196 | CHECK_PACKET_SIZE(recv_data, recv_data.rpos()+8+4+4+4+4+4); |
---|
| 197 | |
---|
| 198 | recv_data >> movementInfo.t_guid; |
---|
| 199 | recv_data >> movementInfo.t_x; |
---|
| 200 | recv_data >> movementInfo.t_y; |
---|
| 201 | recv_data >> movementInfo.t_z; |
---|
| 202 | recv_data >> movementInfo.t_o; |
---|
| 203 | recv_data >> movementInfo.t_time; |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | if(MovementFlags & (MOVEMENTFLAG_SWIMMING | MOVEMENTFLAG_FLYING2)) |
---|
| 207 | { |
---|
| 208 | // recheck |
---|
| 209 | CHECK_PACKET_SIZE(recv_data, recv_data.rpos()+4); |
---|
| 210 | |
---|
| 211 | recv_data >> movementInfo.s_pitch; // pitch, -1.55=looking down, 0=looking straight forward, +1.55=looking up |
---|
| 212 | } |
---|
| 213 | |
---|
| 214 | // recheck |
---|
| 215 | CHECK_PACKET_SIZE(recv_data, recv_data.rpos()+4); |
---|
| 216 | |
---|
| 217 | recv_data >> movementInfo.fallTime; // duration of last jump (when in jump duration from jump begin to now) |
---|
| 218 | |
---|
| 219 | if(MovementFlags & MOVEMENTFLAG_JUMPING) |
---|
| 220 | { |
---|
| 221 | // recheck |
---|
| 222 | CHECK_PACKET_SIZE(recv_data, recv_data.rpos()+4+4+4+4); |
---|
| 223 | |
---|
| 224 | recv_data >> movementInfo.j_unk; // constant, but different when jumping in water and on land? |
---|
| 225 | recv_data >> movementInfo.j_sinAngle; // sin of angle between orientation0 and players orientation |
---|
| 226 | recv_data >> movementInfo.j_cosAngle; // cos of angle between orientation0 and players orientation |
---|
| 227 | recv_data >> movementInfo.j_xyspeed; // speed of xy movement |
---|
| 228 | } |
---|
| 229 | |
---|
| 230 | if(MovementFlags & MOVEMENTFLAG_SPLINE) |
---|
| 231 | { |
---|
| 232 | // recheck |
---|
| 233 | CHECK_PACKET_SIZE(recv_data, recv_data.rpos()+4); |
---|
| 234 | |
---|
| 235 | recv_data >> movementInfo.u_unk1; // unknown |
---|
| 236 | } |
---|
| 237 | /*----------------*/ |
---|
| 238 | |
---|
| 239 | if(recv_data.size() != recv_data.rpos()) |
---|
| 240 | { |
---|
| 241 | sLog.outError("MovementHandler: player %s (guid %d, account %u) sent a packet (opcode %u) that is %u bytes larger than it should be. Kicked as cheater.", _player->GetName(), _player->GetGUIDLow(), _player->GetSession()->GetAccountId(), recv_data.GetOpcode(), recv_data.size() - recv_data.rpos()); |
---|
| 242 | KickPlayer(); |
---|
| 243 | return; |
---|
| 244 | } |
---|
| 245 | |
---|
| 246 | if (!MaNGOS::IsValidMapCoord(movementInfo.x, movementInfo.y, movementInfo.z, movementInfo.o)) |
---|
| 247 | return; |
---|
| 248 | |
---|
| 249 | /* handle special cases */ |
---|
| 250 | if (MovementFlags & MOVEMENTFLAG_ONTRANSPORT) |
---|
| 251 | { |
---|
| 252 | // transports size limited |
---|
| 253 | // (also received at zeppelin leave by some reason with t_* as absolute in continent coordinates, can be safely skipped) |
---|
| 254 | if( movementInfo.t_x > 50 || movementInfo.t_y > 50 || movementInfo.t_z > 50 ) |
---|
| 255 | return; |
---|
| 256 | |
---|
| 257 | if( !MaNGOS::IsValidMapCoord(movementInfo.x+movementInfo.t_x, movementInfo.y+movementInfo.t_y, |
---|
| 258 | movementInfo.z+movementInfo.t_z, movementInfo.o+movementInfo.t_o) ) |
---|
| 259 | return; |
---|
| 260 | |
---|
| 261 | // if we boarded a transport, add us to it |
---|
| 262 | if (!GetPlayer()->m_transport) |
---|
| 263 | { |
---|
| 264 | // elevators also cause the client to send MOVEMENTFLAG_ONTRANSPORT - just unmount if the guid can be found in the transport list |
---|
| 265 | for (MapManager::TransportSet::iterator iter = MapManager::Instance().m_Transports.begin(); iter != MapManager::Instance().m_Transports.end(); ++iter) |
---|
| 266 | { |
---|
| 267 | if ((*iter)->GetGUID() == movementInfo.t_guid) |
---|
| 268 | { |
---|
| 269 | // unmount before boarding |
---|
| 270 | _player->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED); |
---|
| 271 | |
---|
| 272 | GetPlayer()->m_transport = (*iter); |
---|
| 273 | (*iter)->AddPassenger(GetPlayer()); |
---|
| 274 | break; |
---|
| 275 | } |
---|
| 276 | } |
---|
| 277 | } |
---|
| 278 | } |
---|
| 279 | else if (GetPlayer()->m_transport) // if we were on a transport, leave |
---|
| 280 | { |
---|
| 281 | GetPlayer()->m_transport->RemovePassenger(GetPlayer()); |
---|
| 282 | GetPlayer()->m_transport = NULL; |
---|
| 283 | movementInfo.t_x = 0.0f; |
---|
| 284 | movementInfo.t_y = 0.0f; |
---|
| 285 | movementInfo.t_z = 0.0f; |
---|
| 286 | movementInfo.t_o = 0.0f; |
---|
| 287 | movementInfo.t_time = 0; |
---|
| 288 | } |
---|
| 289 | |
---|
| 290 | // fall damage generation (ignore in flight case that can be triggred also at lags in moment teleportation to another map). |
---|
| 291 | if (recv_data.GetOpcode() == MSG_MOVE_FALL_LAND && !GetPlayer()->isInFlight()) |
---|
| 292 | { |
---|
| 293 | Player *target = GetPlayer(); |
---|
| 294 | |
---|
| 295 | //Players with Feather Fall or low fall time, or physical immunity (charges used) are ignored |
---|
| 296 | if (movementInfo.fallTime > 1100 && !target->isDead() && !target->isGameMaster() && |
---|
| 297 | !target->HasAuraType(SPELL_AURA_HOVER) && !target->HasAuraType(SPELL_AURA_FEATHER_FALL) && |
---|
| 298 | !target->HasAuraType(SPELL_AURA_FLY) && !target->IsImmunedToDamage(SPELL_SCHOOL_MASK_NORMAL,true) ) |
---|
| 299 | { |
---|
| 300 | //Safe fall, fall time reduction |
---|
| 301 | int32 safe_fall = target->GetTotalAuraModifier(SPELL_AURA_SAFE_FALL); |
---|
| 302 | uint32 fall_time = (movementInfo.fallTime > (safe_fall*10)) ? movementInfo.fallTime - (safe_fall*10) : 0; |
---|
| 303 | |
---|
| 304 | if(fall_time > 1100) //Prevent damage if fall time < 1100 |
---|
| 305 | { |
---|
| 306 | //Fall Damage calculation |
---|
| 307 | float fallperc = float(fall_time)/1100; |
---|
| 308 | uint32 damage = (uint32)(((fallperc*fallperc -1) / 9 * target->GetMaxHealth())*sWorld.getRate(RATE_DAMAGE_FALL)); |
---|
| 309 | |
---|
| 310 | float height = movementInfo.z; |
---|
| 311 | target->UpdateGroundPositionZ(movementInfo.x,movementInfo.y,height); |
---|
| 312 | |
---|
| 313 | if (damage > 0) |
---|
| 314 | { |
---|
| 315 | //Prevent fall damage from being more than the player maximum health |
---|
| 316 | if (damage > target->GetMaxHealth()) |
---|
| 317 | damage = target->GetMaxHealth(); |
---|
| 318 | |
---|
| 319 | // Gust of Wind |
---|
| 320 | if (target->GetDummyAura(43621)) |
---|
| 321 | damage = target->GetMaxHealth()/2; |
---|
| 322 | |
---|
| 323 | target->EnvironmentalDamage(target->GetGUID(), DAMAGE_FALL, damage); |
---|
| 324 | } |
---|
| 325 | |
---|
| 326 | //Z given by moveinfo, LastZ, FallTime, WaterZ, MapZ, Damage, Safefall reduction |
---|
| 327 | DEBUG_LOG("FALLDAMAGE z=%f sz=%f pZ=%f FallTime=%d mZ=%f damage=%d SF=%d" , movementInfo.z, height, target->GetPositionZ(), movementInfo.fallTime, height, damage, safe_fall); |
---|
| 328 | } |
---|
| 329 | } |
---|
| 330 | |
---|
| 331 | //handle fall and logout at the same time (logout started before fall finished) |
---|
| 332 | /* outdated and create problems with sit at stun sometime |
---|
| 333 | if (target->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISABLE_ROTATE)) |
---|
| 334 | { |
---|
| 335 | target->SetStandState(PLAYER_STATE_SIT); |
---|
| 336 | // Can't move |
---|
| 337 | WorldPacket data( SMSG_FORCE_MOVE_ROOT, 12 ); |
---|
| 338 | data.append(target->GetPackGUID()); |
---|
| 339 | data << (uint32)2; |
---|
| 340 | SendPacket( &data ); |
---|
| 341 | } |
---|
| 342 | */ |
---|
| 343 | } |
---|
| 344 | |
---|
| 345 | if(((MovementFlags & MOVEMENTFLAG_SWIMMING) != 0) != GetPlayer()->IsInWater()) |
---|
| 346 | { |
---|
| 347 | // now client not include swimming flag in case jumping under water |
---|
| 348 | GetPlayer()->SetInWater( !GetPlayer()->IsInWater() || GetPlayer()->GetBaseMap()->IsUnderWater(movementInfo.x, movementInfo.y, movementInfo.z) ); |
---|
| 349 | } |
---|
| 350 | |
---|
| 351 | /*----------------------*/ |
---|
| 352 | |
---|
| 353 | /* process position-change */ |
---|
| 354 | recv_data.put<uint32>(5, getMSTime()); // offset flags(4) + unk(1) |
---|
| 355 | WorldPacket data(recv_data.GetOpcode(), (GetPlayer()->GetPackGUID().size()+recv_data.size())); |
---|
| 356 | data.append(GetPlayer()->GetPackGUID()); |
---|
| 357 | data.append(recv_data.contents(), recv_data.size()); |
---|
| 358 | GetPlayer()->SendMessageToSet(&data, false); |
---|
| 359 | |
---|
| 360 | GetPlayer()->SetPosition(movementInfo.x, movementInfo.y, movementInfo.z, movementInfo.o); |
---|
| 361 | GetPlayer()->m_movementInfo = movementInfo; |
---|
| 362 | |
---|
| 363 | if(GetPlayer()->isMovingOrTurning()) |
---|
| 364 | GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); |
---|
| 365 | |
---|
| 366 | if(movementInfo.z < -500.0f) |
---|
| 367 | { |
---|
| 368 | // NOTE: this is actually called many times while falling |
---|
| 369 | // even after the player has been teleported away |
---|
| 370 | // TODO: discard movement packets after the player is rooted |
---|
| 371 | if(GetPlayer()->isAlive()) |
---|
| 372 | { |
---|
| 373 | GetPlayer()->EnvironmentalDamage(GetPlayer()->GetGUID(),DAMAGE_FALL_TO_VOID, GetPlayer()->GetMaxHealth()); |
---|
| 374 | // change the death state to CORPSE to prevent the death timer from |
---|
| 375 | // starting in the next player update |
---|
| 376 | GetPlayer()->KillPlayer(); |
---|
| 377 | GetPlayer()->BuildPlayerRepop(); |
---|
| 378 | } |
---|
| 379 | |
---|
| 380 | // cancel the death timer here if started |
---|
| 381 | GetPlayer()->RepopAtGraveyard(); |
---|
| 382 | } |
---|
| 383 | } |
---|
| 384 | |
---|
| 385 | void WorldSession::HandleForceSpeedChangeAck(WorldPacket &recv_data) |
---|
| 386 | { |
---|
| 387 | CHECK_PACKET_SIZE(recv_data, 8+4+4+1+4+4+4+4+4); |
---|
| 388 | |
---|
| 389 | /* extract packet */ |
---|
| 390 | uint64 guid; |
---|
| 391 | uint8 unkB; |
---|
| 392 | uint32 unk1, flags, time, fallTime; |
---|
| 393 | float x, y, z, orientation; |
---|
| 394 | |
---|
| 395 | uint64 t_GUID; |
---|
| 396 | float t_x, t_y, t_z, t_o; |
---|
| 397 | uint32 t_time; |
---|
| 398 | float s_pitch; |
---|
| 399 | float j_unk1, j_sinAngle, j_cosAngle, j_xyspeed; |
---|
| 400 | float u_unk1; |
---|
| 401 | float newspeed; |
---|
| 402 | |
---|
| 403 | recv_data >> guid; |
---|
| 404 | |
---|
| 405 | // now can skip not our packet |
---|
| 406 | if(_player->GetGUID() != guid) |
---|
| 407 | return; |
---|
| 408 | |
---|
| 409 | // continue parse packet |
---|
| 410 | |
---|
| 411 | recv_data >> unk1; |
---|
| 412 | recv_data >> flags >> unkB >> time; |
---|
| 413 | recv_data >> x >> y >> z >> orientation; |
---|
| 414 | if (flags & MOVEMENTFLAG_ONTRANSPORT) |
---|
| 415 | { |
---|
| 416 | // recheck |
---|
| 417 | CHECK_PACKET_SIZE(recv_data, recv_data.rpos()+8+4+4+4+4+4); |
---|
| 418 | |
---|
| 419 | recv_data >> t_GUID; |
---|
| 420 | recv_data >> t_x >> t_y >> t_z >> t_o >> t_time; |
---|
| 421 | } |
---|
| 422 | if (flags & (MOVEMENTFLAG_SWIMMING | MOVEMENTFLAG_FLYING2)) |
---|
| 423 | { |
---|
| 424 | // recheck |
---|
| 425 | CHECK_PACKET_SIZE(recv_data, recv_data.rpos()+4); |
---|
| 426 | |
---|
| 427 | recv_data >> s_pitch; // pitch, -1.55=looking down, 0=looking straight forward, +1.55=looking up |
---|
| 428 | } |
---|
| 429 | |
---|
| 430 | // recheck |
---|
| 431 | CHECK_PACKET_SIZE(recv_data, recv_data.rpos()+4); |
---|
| 432 | |
---|
| 433 | recv_data >> fallTime; // duration of last jump (when in jump duration from jump begin to now) |
---|
| 434 | |
---|
| 435 | if ((flags & MOVEMENTFLAG_JUMPING) || (flags & MOVEMENTFLAG_FALLING)) |
---|
| 436 | { |
---|
| 437 | // recheck |
---|
| 438 | CHECK_PACKET_SIZE(recv_data, recv_data.rpos()+4+4+4+4); |
---|
| 439 | |
---|
| 440 | recv_data >> j_unk1; // ?constant, but different when jumping in water and on land? |
---|
| 441 | recv_data >> j_sinAngle >> j_cosAngle; // sin + cos of angle between orientation0 and players orientation |
---|
| 442 | recv_data >> j_xyspeed; // speed of xy movement |
---|
| 443 | } |
---|
| 444 | |
---|
| 445 | if(flags & MOVEMENTFLAG_SPLINE) |
---|
| 446 | { |
---|
| 447 | // recheck |
---|
| 448 | CHECK_PACKET_SIZE(recv_data, recv_data.rpos()+4); |
---|
| 449 | |
---|
| 450 | recv_data >> u_unk1; // unknown |
---|
| 451 | } |
---|
| 452 | |
---|
| 453 | // recheck |
---|
| 454 | CHECK_PACKET_SIZE(recv_data, recv_data.rpos()+4); |
---|
| 455 | |
---|
| 456 | recv_data >> newspeed; |
---|
| 457 | /*----------------*/ |
---|
| 458 | |
---|
| 459 | // client ACK send one packet for mounted/run case and need skip all except last from its |
---|
| 460 | // in other cases anti-cheat check can be fail in false case |
---|
| 461 | UnitMoveType move_type; |
---|
| 462 | UnitMoveType force_move_type; |
---|
| 463 | |
---|
| 464 | static char const* move_type_name[MAX_MOVE_TYPE] = { "Walk", "Run", "Walkback", "Swim", "Swimback", "Turn", "Fly", "Flyback" }; |
---|
| 465 | |
---|
| 466 | uint16 opcode = recv_data.GetOpcode(); |
---|
| 467 | switch(opcode) |
---|
| 468 | { |
---|
| 469 | case CMSG_FORCE_WALK_SPEED_CHANGE_ACK: move_type = MOVE_WALK; force_move_type = MOVE_WALK; break; |
---|
| 470 | case CMSG_FORCE_RUN_SPEED_CHANGE_ACK: move_type = MOVE_RUN; force_move_type = MOVE_RUN; break; |
---|
| 471 | case CMSG_FORCE_RUN_BACK_SPEED_CHANGE_ACK: move_type = MOVE_WALKBACK; force_move_type = MOVE_WALKBACK; break; |
---|
| 472 | case CMSG_FORCE_SWIM_SPEED_CHANGE_ACK: move_type = MOVE_SWIM; force_move_type = MOVE_SWIM; break; |
---|
| 473 | case CMSG_FORCE_SWIM_BACK_SPEED_CHANGE_ACK: move_type = MOVE_SWIMBACK; force_move_type = MOVE_SWIMBACK; break; |
---|
| 474 | case CMSG_FORCE_TURN_RATE_CHANGE_ACK: move_type = MOVE_TURN; force_move_type = MOVE_TURN; break; |
---|
| 475 | case CMSG_FORCE_FLIGHT_SPEED_CHANGE_ACK: move_type = MOVE_FLY; force_move_type = MOVE_FLY; break; |
---|
| 476 | case CMSG_FORCE_FLIGHT_BACK_SPEED_CHANGE_ACK: move_type = MOVE_FLYBACK; force_move_type = MOVE_FLYBACK; break; |
---|
| 477 | default: |
---|
| 478 | sLog.outError("WorldSession::HandleForceSpeedChangeAck: Unknown move type opcode: %u", opcode); |
---|
| 479 | return; |
---|
| 480 | } |
---|
| 481 | |
---|
| 482 | // skip all forced speed changes except last and unexpected |
---|
| 483 | // in run/mounted case used one ACK and it must be skipped.m_forced_speed_changes[MOVE_RUN} store both. |
---|
| 484 | if(_player->m_forced_speed_changes[force_move_type] > 0) |
---|
| 485 | { |
---|
| 486 | --_player->m_forced_speed_changes[force_move_type]; |
---|
| 487 | if(_player->m_forced_speed_changes[force_move_type] > 0) |
---|
| 488 | return; |
---|
| 489 | } |
---|
| 490 | |
---|
| 491 | if (!_player->GetTransport() && fabs(_player->GetSpeed(move_type) - newspeed) > 0.01f) |
---|
| 492 | { |
---|
| 493 | if(_player->GetSpeed(move_type) > newspeed) // must be greater - just correct |
---|
| 494 | { |
---|
| 495 | sLog.outError("%sSpeedChange player %s is NOT correct (must be %f instead %f), force set to correct value", |
---|
| 496 | move_type_name[move_type], _player->GetName(), _player->GetSpeed(move_type), newspeed); |
---|
| 497 | _player->SetSpeed(move_type,_player->GetSpeedRate(move_type),true); |
---|
| 498 | } |
---|
| 499 | else // must be lesser - cheating |
---|
| 500 | { |
---|
| 501 | sLog.outBasic("Player %s from account id %u kicked for incorrect speed (must be %f instead %f)", |
---|
| 502 | _player->GetName(),_player->GetSession()->GetAccountId(),_player->GetSpeed(move_type), newspeed); |
---|
| 503 | _player->GetSession()->KickPlayer(); |
---|
| 504 | } |
---|
| 505 | } |
---|
| 506 | } |
---|
| 507 | |
---|
| 508 | void WorldSession::HandleSetActiveMoverOpcode(WorldPacket &recv_data) |
---|
| 509 | { |
---|
| 510 | sLog.outDebug("WORLD: Recvd CMSG_SET_ACTIVE_MOVER"); |
---|
| 511 | |
---|
| 512 | CHECK_PACKET_SIZE(recv_data,8); |
---|
| 513 | |
---|
| 514 | uint64 guid; |
---|
| 515 | recv_data >> guid; |
---|
| 516 | |
---|
| 517 | WorldPacket data(SMSG_TIME_SYNC_REQ, 4); // new 2.0.x, enable movement |
---|
| 518 | data << uint32(0x00000000); // on blizz it increments periodically |
---|
| 519 | SendPacket(&data); |
---|
| 520 | } |
---|
| 521 | |
---|
| 522 | void WorldSession::HandleMountSpecialAnimOpcode(WorldPacket& /*recvdata*/) |
---|
| 523 | { |
---|
| 524 | //sLog.outDebug("WORLD: Recvd CMSG_MOUNTSPECIAL_ANIM"); |
---|
| 525 | |
---|
| 526 | WorldPacket data(SMSG_MOUNTSPECIAL_ANIM, 8); |
---|
| 527 | data << uint64(GetPlayer()->GetGUID()); |
---|
| 528 | |
---|
| 529 | GetPlayer()->SendMessageToSet(&data, false); |
---|
| 530 | } |
---|
| 531 | |
---|
| 532 | void WorldSession::HandleMoveKnockBackAck( WorldPacket & /*recv_data*/ ) |
---|
| 533 | { |
---|
| 534 | // CHECK_PACKET_SIZE(recv_data,?); |
---|
| 535 | sLog.outDebug("CMSG_MOVE_KNOCK_BACK_ACK"); |
---|
| 536 | // Currently not used but maybe use later for recheck final player position |
---|
| 537 | // (must be at call same as into "recv_data >> x >> y >> z >> orientation;" |
---|
| 538 | |
---|
| 539 | /* |
---|
| 540 | uint32 flags, time; |
---|
| 541 | float x, y, z, orientation; |
---|
| 542 | uint64 guid; |
---|
| 543 | uint32 sequence; |
---|
| 544 | uint32 ukn1; |
---|
| 545 | float xdirection,ydirection,hspeed,vspeed; |
---|
| 546 | |
---|
| 547 | recv_data >> guid; |
---|
| 548 | recv_data >> sequence; |
---|
| 549 | recv_data >> flags >> time; |
---|
| 550 | recv_data >> x >> y >> z >> orientation; |
---|
| 551 | recv_data >> ukn1; //unknown |
---|
| 552 | recv_data >> vspeed >> xdirection >> ydirection >> hspeed; |
---|
| 553 | |
---|
| 554 | // skip not personal message; |
---|
| 555 | if(GetPlayer()->GetGUID()!=guid) |
---|
| 556 | return; |
---|
| 557 | |
---|
| 558 | // check code |
---|
| 559 | */ |
---|
| 560 | } |
---|
| 561 | |
---|
| 562 | void WorldSession::HandleMoveHoverAck( WorldPacket& /*recv_data*/ ) |
---|
| 563 | { |
---|
| 564 | sLog.outDebug("CMSG_MOVE_HOVER_ACK"); |
---|
| 565 | } |
---|
| 566 | |
---|
| 567 | void WorldSession::HandleMoveWaterWalkAck(WorldPacket& /*recv_data*/) |
---|
| 568 | { |
---|
| 569 | sLog.outDebug("CMSG_MOVE_WATER_WALK_ACK"); |
---|
| 570 | } |
---|
| 571 | |
---|
| 572 | void WorldSession::HandleSummonResponseOpcode(WorldPacket& recv_data) |
---|
| 573 | { |
---|
| 574 | CHECK_PACKET_SIZE(recv_data,8+1); |
---|
| 575 | |
---|
| 576 | if(!_player->isAlive() || _player->isInCombat() ) |
---|
| 577 | return; |
---|
| 578 | |
---|
| 579 | uint64 summoner_guid; |
---|
| 580 | bool agree; |
---|
| 581 | recv_data >> summoner_guid; |
---|
| 582 | recv_data >> agree; |
---|
| 583 | |
---|
| 584 | _player->SummonIfPossible(agree); |
---|
| 585 | } |
---|