/
MovementHandler.cpp
663 lines (552 loc) · 25 KB
/
MovementHandler.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
/*
* This file is part of the CMaNGOS Project. See AUTHORS file for Copyright information
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "Common.h"
#include "WorldPacket.h"
#include "WorldSession.h"
#include "Opcodes.h"
#include "Log.h"
#include "Player.h"
#include "SpellAuras.h"
#include "MapManager.h"
#include "Transports.h"
#include "BattleGround/BattleGround.h"
#include "WaypointMovementGenerator.h"
#include "MapPersistentStateMgr.h"
#include "ObjectMgr.h"
#define MOVEMENT_PACKET_TIME_DELAY 0
void WorldSession::HandleMoveWorldportAckOpcode(WorldPacket& /*recv_data*/)
{
DEBUG_LOG("WORLD: got MSG_MOVE_WORLDPORT_ACK.");
HandleMoveWorldportAckOpcode();
}
void WorldSession::HandleMoveWorldportAckOpcode()
{
// ignore unexpected far teleports
if (!GetPlayer()->IsBeingTeleportedFar())
return;
// get start teleport coordinates (will used later in fail case)
WorldLocation old_loc;
GetPlayer()->GetPosition(old_loc);
// get the teleport destination
WorldLocation& loc = GetPlayer()->GetTeleportDest();
// possible errors in the coordinate validity check (only cheating case possible)
if (!MapManager::IsValidMapCoord(loc.mapid, loc.coord_x, loc.coord_y, loc.coord_z, loc.orientation))
{
sLog.outError("WorldSession::HandleMoveWorldportAckOpcode: %s was teleported far to a not valid location "
"(map:%u, x:%f, y:%f, z:%f) We port him to his homebind instead..",
GetPlayer()->GetGuidStr().c_str(), loc.mapid, loc.coord_x, loc.coord_y, loc.coord_z);
// stop teleportation else we would try this again and again in LogoutPlayer...
GetPlayer()->SetSemaphoreTeleportFar(false);
// and teleport the player to a valid place
GetPlayer()->TeleportToHomebind();
return;
}
// get the destination map entry, not the current one, this will fix homebind and reset greeting
MapEntry const* mEntry = sMapStore.LookupEntry(loc.mapid);
Map* map = nullptr;
// prevent crash at attempt landing to not existed battleground instance
if (mEntry->IsBattleGroundOrArena())
{
if (GetPlayer()->GetBattleGroundId())
map = sMapMgr.FindMap(loc.mapid, GetPlayer()->GetBattleGroundId());
if (!map)
{
DETAIL_LOG("WorldSession::HandleMoveWorldportAckOpcode: %s was teleported far to nonexisten battleground instance "
" (map:%u, x:%f, y:%f, z:%f) Trying to port him to his previous place..",
GetPlayer()->GetGuidStr().c_str(), loc.mapid, loc.coord_x, loc.coord_y, loc.coord_z);
GetPlayer()->SetSemaphoreTeleportFar(false);
// Teleport to previous place, if cannot be ported back TP to homebind place
if (!GetPlayer()->TeleportTo(old_loc))
{
DETAIL_LOG("WorldSession::HandleMoveWorldportAckOpcode: %s cannot be ported to his previous place, teleporting him to his homebind place...",
GetPlayer()->GetGuidStr().c_str());
GetPlayer()->TeleportToHomebind();
}
return;
}
}
InstanceTemplate const* mInstance = ObjectMgr::GetInstanceTemplate(loc.mapid);
// reset instance validity, except if going to an instance inside an instance
if (GetPlayer()->m_InstanceValid == false && !mInstance)
GetPlayer()->m_InstanceValid = true;
GetPlayer()->SetSemaphoreTeleportFar(false);
// relocate the player to the teleport destination
if (!map)
map = sMapMgr.CreateMap(loc.mapid, GetPlayer());
GetPlayer()->SetMap(map);
GetPlayer()->Relocate(loc.coord_x, loc.coord_y, loc.coord_z, loc.orientation);
GetPlayer()->SendInitialPacketsBeforeAddToMap();
// the CanEnter checks are done in TeleporTo but conditions may change
// while the player is in transit, for example the map may get full
if (!GetPlayer()->GetMap()->Add(GetPlayer()))
{
// if player wasn't added to map, reset his map pointer!
GetPlayer()->ResetMap();
DETAIL_LOG("WorldSession::HandleMoveWorldportAckOpcode: %s was teleported far but couldn't be added to map "
" (map:%u, x:%f, y:%f, z:%f) Trying to port him to his previous place..",
GetPlayer()->GetGuidStr().c_str(), loc.mapid, loc.coord_x, loc.coord_y, loc.coord_z);
// Teleport to previous place, if cannot be ported back TP to homebind place
if (!GetPlayer()->TeleportTo(old_loc))
{
DETAIL_LOG("WorldSession::HandleMoveWorldportAckOpcode: %s cannot be ported to his previous place, teleporting him to his homebind place...",
GetPlayer()->GetGuidStr().c_str());
GetPlayer()->TeleportToHomebind();
}
return;
}
// battleground state prepare (in case join to BG), at relogin/tele player not invited
// only add to bg group and object, if the player was invited (else he entered through command)
if (_player->InBattleGround())
{
// cleanup setting if outdated
if (!mEntry->IsBattleGroundOrArena())
{
// We're not in BG
_player->SetBattleGroundId(0, BATTLEGROUND_TYPE_NONE);
// reset destination bg team
_player->SetBGTeam(TEAM_NONE);
}
// join to bg case
else if (BattleGround* bg = _player->GetBattleGround())
{
if (_player->IsInvitedForBattleGroundInstance(_player->GetBattleGroundId()))
bg->AddPlayer(_player);
}
}
GetPlayer()->SendInitialPacketsAfterAddToMap();
// flight fast teleport case
if (GetPlayer()->GetMotionMaster()->GetCurrentMovementGeneratorType() == FLIGHT_MOTION_TYPE)
{
if (!_player->InBattleGround())
{
// short preparations to continue flight
FlightPathMovementGenerator* flight = (FlightPathMovementGenerator*)(GetPlayer()->GetMotionMaster()->top());
flight->Reset(*GetPlayer());
return;
}
// battleground state prepare, stop flight
GetPlayer()->GetMotionMaster()->MovementExpired();
GetPlayer()->m_taxi.ClearTaxiDestinations();
}
if (mInstance)
{
Difficulty diff = GetPlayer()->GetDifficulty(mEntry->IsRaid());
if (MapDifficultyEntry const* mapDiff = GetMapDifficultyData(mEntry->MapID, diff))
{
if (mapDiff->resetTime)
{
if (time_t timeReset = sMapPersistentStateMgr.GetScheduler().GetResetTimeFor(mEntry->MapID, diff))
{
uint32 timeleft = uint32(timeReset - time(nullptr));
GetPlayer()->SendInstanceResetWarning(mEntry->MapID, diff, timeleft);
}
}
}
// mount allow check
if (!mEntry->IsMountAllowed())
{
_player->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
_player->RemoveSpellsCausingAura(SPELL_AURA_FLY);
}
else
{
// recheck mount capabilities at far teleport
Unit::AuraList const& mMountAuras = _player->GetAurasByType(SPELL_AURA_MOUNTED);
for (Unit::AuraList::const_iterator itr = mMountAuras.begin(); itr != mMountAuras.end(); )
{
Aura const* aura = *itr;
// mount is no longer suitable
MountCapabilityEntry const* entry = _player->GetMountCapability(aura->GetSpellEffect()->EffectMiscValueB);
if (!entry)
{
_player->RemoveAurasDueToSpell(aura->GetId());
itr = mMountAuras.begin();
continue;
}
// mount capability changed
if (entry->Id != aura->GetModifier()->m_amount)
{
if (MountCapabilityEntry const* oldEntry = sMountCapabilityStore.LookupEntry(aura->GetModifier()->m_amount))
_player->RemoveAurasDueToSpell(oldEntry->SpeedModSpell);
_player->CastSpell(_player, entry->SpeedModSpell, TRIGGERED_OLD_TRIGGERED);
const_cast<Aura*>(aura)->ChangeAmount(entry->Id);
}
++itr;
}
uint32 zone, area;
_player->GetZoneAndAreaId(zone, area);
// recheck fly auras
Unit::AuraList const& mFlyAuras = _player->GetAurasByType(SPELL_AURA_FLY);
for (Unit::AuraList::const_iterator itr = mFlyAuras.begin(); itr != mFlyAuras.end(); )
{
Aura const* aura = *itr;
if (!_player->CanStartFlyInArea(_player->GetMapId(), zone, area))
{
_player->RemoveAurasDueToSpell(aura->GetId());
itr = mFlyAuras.begin();
continue;
}
++itr;
}
}
// honorless target
if (GetPlayer()->pvpInfo.inHostileArea)
GetPlayer()->CastSpell(GetPlayer(), 2479, TRIGGERED_OLD_TRIGGERED);
// resummon pet
GetPlayer()->ResummonPetTemporaryUnSummonedIfAny();
// lets process all delayed operations on successful teleport
GetPlayer()->ProcessDelayedOperations();
// notify group after successful teleport
if (_player->GetGroup())
_player->SetGroupUpdateFlag(GROUP_UPDATE_FULL);
}
void WorldSession::HandleMoveTeleportAckOpcode(WorldPacket& recv_data)
{
DEBUG_LOG("CMSG_MOVE_TELEPORT_ACK");
ObjectGuid guid;
uint32 counter, time;
recv_data >> counter >> time;
recv_data.ReadGuidMask<5, 0, 1, 6, 3, 7, 2, 4>(guid);
recv_data.ReadGuidBytes<4, 2, 7, 6, 5, 1, 3, 0>(guid);
DEBUG_LOG("Guid: %s", guid.GetString().c_str());
DEBUG_LOG("Counter %u, time %u", counter, time / IN_MILLISECONDS);
Unit* mover = _player->GetMover();
Player* plMover = mover->GetTypeId() == TYPEID_PLAYER ? (Player*)mover : nullptr;
if (!plMover || !plMover->IsBeingTeleportedNear())
return;
if (guid != plMover->GetObjectGuid())
return;
plMover->SetSemaphoreTeleportNear(false);
uint32 old_zone = plMover->GetZoneId();
WorldLocation const& dest = plMover->GetTeleportDest();
plMover->SetPosition(dest.coord_x, dest.coord_y, dest.coord_z, dest.orientation, true);
uint32 newzone, newarea;
plMover->GetZoneAndAreaId(newzone, newarea);
plMover->UpdateZone(newzone, newarea);
// new zone
if (old_zone != newzone)
{
// honorless target
if (plMover->pvpInfo.inHostileArea)
plMover->CastSpell(plMover, 2479, TRIGGERED_OLD_TRIGGERED);
}
// resummon pet
GetPlayer()->ResummonPetTemporaryUnSummonedIfAny();
// lets process all delayed operations on successful teleport
GetPlayer()->ProcessDelayedOperations();
}
void WorldSession::HandleMovementOpcodes(WorldPacket& recv_data)
{
Opcodes opcode = recv_data.GetOpcode();
if (!sLog.HasLogFilter(LOG_FILTER_PLAYER_MOVES))
{
DEBUG_LOG("WORLD: Received opcode %s (%u, 0x%X)", LookupOpcodeName(opcode), opcode, opcode);
recv_data.hexlike();
}
Unit* mover = _player->GetMover();
Player* plMover = mover->GetTypeId() == TYPEID_PLAYER ? (Player*)mover : nullptr;
// ignore, waiting processing in WorldSession::HandleMoveWorldportAckOpcode and WorldSession::HandleMoveTeleportAck
if (plMover && plMover->IsBeingTeleported())
{
recv_data.rpos(recv_data.wpos()); // prevent warnings spam
return;
}
/* extract packet */
MovementInfo movementInfo;
recv_data >> movementInfo;
/*----------------*/
if (!VerifyMovementInfo(movementInfo, movementInfo.GetGuid()))
return;
// fall damage generation (ignore in flight case that can be triggered also at lags in moment teleportation to another map).
if (opcode == CMSG_MOVE_FALL_LAND && plMover && !plMover->IsTaxiFlying())
plMover->HandleFall(movementInfo);
// Remove auras that should be removed at landing on ground or water
if (opcode == MSG_MOVE_FALL_LAND || opcode == MSG_MOVE_START_SWIM)
mover->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_LANDING); // Parachutes
/* process position-change */
HandleMoverRelocation(movementInfo);
if (plMover)
plMover->UpdateFallInformationIfNeed(movementInfo, opcode);
WorldPacket data(SMSG_PLAYER_MOVE, recv_data.size());
data << movementInfo;
mover->SendMessageToSetExcept(&data, _player);
}
void WorldSession::HandleForceSpeedChangeAckOpcodes(WorldPacket& recv_data)
{
Opcodes opcode = recv_data.GetOpcode();
DEBUG_LOG("WORLD: Received %s (%u, 0x%X) opcode", recv_data.GetOpcodeName(), opcode, opcode);
/* extract packet */
ObjectGuid guid;
MovementInfo movementInfo;
float newspeed;
recv_data >> guid.ReadAsPacked();
recv_data >> Unused<uint32>(); // counter or moveEvent
recv_data >> movementInfo;
recv_data >> newspeed;
// now can skip not our packet
if (_player->GetObjectGuid() != guid)
{
recv_data.rpos(recv_data.wpos()); // prevent warnings spam
return;
}
/*----------------*/
// client ACK send one packet for mounted/run case and need skip all except last from its
// in other cases anti-cheat check can be fail in false case
UnitMoveType move_type;
UnitMoveType force_move_type;
static char const* move_type_name[MAX_MOVE_TYPE] = { "Walk", "Run", "RunBack", "Swim", "SwimBack", "TurnRate", "Flight", "FlightBack", "PitchRate" };
switch (opcode)
{
case CMSG_FORCE_WALK_SPEED_CHANGE_ACK: move_type = MOVE_WALK; force_move_type = MOVE_WALK; break;
case CMSG_FORCE_RUN_SPEED_CHANGE_ACK: move_type = MOVE_RUN; force_move_type = MOVE_RUN; break;
case CMSG_FORCE_RUN_BACK_SPEED_CHANGE_ACK: move_type = MOVE_RUN_BACK; force_move_type = MOVE_RUN_BACK; break;
case CMSG_FORCE_SWIM_SPEED_CHANGE_ACK: move_type = MOVE_SWIM; force_move_type = MOVE_SWIM; break;
case CMSG_FORCE_SWIM_BACK_SPEED_CHANGE_ACK: move_type = MOVE_SWIM_BACK; force_move_type = MOVE_SWIM_BACK; break;
case CMSG_FORCE_TURN_RATE_CHANGE_ACK: move_type = MOVE_TURN_RATE; force_move_type = MOVE_TURN_RATE; break;
case CMSG_FORCE_FLIGHT_SPEED_CHANGE_ACK: move_type = MOVE_FLIGHT; force_move_type = MOVE_FLIGHT; break;
case CMSG_FORCE_FLIGHT_BACK_SPEED_CHANGE_ACK: move_type = MOVE_FLIGHT_BACK; force_move_type = MOVE_FLIGHT_BACK; break;
case CMSG_FORCE_PITCH_RATE_CHANGE_ACK: move_type = MOVE_PITCH_RATE; force_move_type = MOVE_PITCH_RATE; break;
default:
sLog.outError("WorldSession::HandleForceSpeedChangeAck: Unknown move type opcode: %u", opcode);
return;
}
// skip all forced speed changes except last and unexpected
// in run/mounted case used one ACK and it must be skipped.m_forced_speed_changes[MOVE_RUN} store both.
if (_player->m_forced_speed_changes[force_move_type] > 0)
{
--_player->m_forced_speed_changes[force_move_type];
if (_player->m_forced_speed_changes[force_move_type] > 0)
return;
}
if (!_player->GetTransport() && fabs(_player->GetSpeed(move_type) - newspeed) > 0.01f)
{
if (_player->GetSpeed(move_type) > newspeed) // must be greater - just correct
{
sLog.outError("%sSpeedChange player %s is NOT correct (must be %f instead %f), force set to correct value",
move_type_name[move_type], _player->GetName(), _player->GetSpeed(move_type), newspeed);
_player->SetSpeedRate(move_type, _player->GetSpeedRate(move_type), true);
}
else // must be lesser - cheating
{
BASIC_LOG("Player %s from account id %u kicked for incorrect speed (must be %f instead %f)",
_player->GetName(), _player->GetSession()->GetAccountId(), _player->GetSpeed(move_type), newspeed);
_player->GetSession()->KickPlayer();
}
}
}
void WorldSession::HandleSetActiveMoverOpcode(WorldPacket& recv_data)
{
DEBUG_LOG("WORLD: Received opcode CMSG_SET_ACTIVE_MOVER");
recv_data.hexlike();
ObjectGuid guid;
recv_data.ReadGuidMask<7, 2, 1, 0, 4, 5, 6, 3>(guid);
recv_data.ReadGuidBytes<3, 2, 4, 0, 5, 1, 6, 7>(guid);
if (_player->GetMover()->GetObjectGuid() != guid)
{
sLog.outError("HandleSetActiveMoverOpcode: incorrect mover guid: mover is %s and should be %s",
_player->GetMover()->GetGuidStr().c_str(), guid.GetString().c_str());
return;
}
else
{
if (Unit* mover = ObjectAccessor::GetUnit(*GetPlayer(), guid))
_player->SetMover(mover);
}
}
void WorldSession::HandleMoveNotActiveMoverOpcode(WorldPacket& recv_data)
{
DEBUG_LOG("WORLD: Received opcode CMSG_MOVE_NOT_ACTIVE_MOVER");
recv_data.hexlike();
MovementInfo mi;
recv_data >> mi;
if (_player->GetMover()->GetObjectGuid() == mi.GetGuid())
{
sLog.outError("HandleMoveNotActiveMover: incorrect mover guid: mover is %s and should be %s instead of %s",
_player->GetMover()->GetGuidStr().c_str(),
_player->GetGuidStr().c_str(),
mi.GetGuid().GetString().c_str());
return;
}
_player->m_movementInfo = mi;
}
void WorldSession::HandleMountSpecialAnimOpcode(WorldPacket& /*recvdata*/)
{
// DEBUG_LOG("WORLD: Received opcode CMSG_MOUNTSPECIAL_ANIM");
WorldPacket data(SMSG_MOUNTSPECIAL_ANIM, 8);
data << GetPlayer()->GetObjectGuid();
GetPlayer()->SendMessageToSet(&data, false);
}
void WorldSession::HandleMoveKnockBackAck(WorldPacket& recv_data)
{
DEBUG_LOG("CMSG_MOVE_KNOCK_BACK_ACK");
Unit* mover = _player->GetMover();
Player* plMover = mover->GetTypeId() == TYPEID_PLAYER ? (Player*)mover : nullptr;
// ignore, waiting processing in WorldSession::HandleMoveWorldportAckOpcode and WorldSession::HandleMoveTeleportAck
if (plMover && plMover->IsBeingTeleported())
{
recv_data.rpos(recv_data.wpos()); // prevent warnings spam
return;
}
MovementInfo movementInfo;
recv_data >> movementInfo;
if (!VerifyMovementInfo(movementInfo, movementInfo.GetGuid()))
return;
HandleMoverRelocation(movementInfo);
WorldPacket data(SMSG_MOVE_UPDATE_KNOCK_BACK, recv_data.size() + 15);
data << movementInfo;
mover->SendMessageToSetExcept(&data, _player);
}
void WorldSession::SendKnockBack(float angle, float horizontalSpeed, float verticalSpeed)
{
ObjectGuid guid = GetPlayer()->GetObjectGuid();
float vsin = sin(angle);
float vcos = cos(angle);
WorldPacket data(SMSG_MOVE_KNOCK_BACK, 9 + 4 + 4 + 4 + 4 + 4 + 1 + 8);
data.WriteGuidMask<0, 3, 6, 7, 2, 5, 1, 4>(guid);
data.WriteGuidBytes<1>(guid);
data << float(vsin); // y direction
data << uint32(0); // Sequence
data.WriteGuidBytes<6, 7>(guid);
data << float(horizontalSpeed); // Horizontal speed
data.WriteGuidBytes<4, 5, 3>(guid);
data << float(-verticalSpeed); // Z Movement speed (vertical)
data << float(vcos); // x direction
data.WriteGuidBytes<2, 0>(guid);
SendPacket(&data);
}
void WorldSession::HandleMoveHoverAck(WorldPacket& recv_data)
{
DEBUG_LOG("CMSG_MOVE_HOVER_ACK");
recv_data.rfinish();
/*
MovementInfo movementInfo;
recv_data >> movementInfo;
*/
}
void WorldSession::HandleMoveWaterWalkAck(WorldPacket& recv_data)
{
DEBUG_LOG("CMSG_MOVE_WATER_WALK_ACK");
recv_data.rfinish();
/*
MovementInfo movementInfo;
recv_data >> movementInfo;
*/
}
void WorldSession::HandleSummonResponseOpcode(WorldPacket& recv_data)
{
if (!_player->isAlive() || _player->isInCombat())
return;
ObjectGuid summonerGuid;
bool agree;
recv_data >> summonerGuid;
recv_data >> agree;
_player->SummonIfPossible(agree);
}
bool WorldSession::VerifyMovementInfo(MovementInfo const& movementInfo, ObjectGuid const& guid) const
{
// ignore wrong guid (player attempt cheating own session for not own guid possible...)
if (guid != _player->GetMover()->GetObjectGuid())
return false;
if (!MaNGOS::IsValidMapCoord(movementInfo.GetPos()->x, movementInfo.GetPos()->y, movementInfo.GetPos()->z, movementInfo.GetPos()->o))
return false;
if (movementInfo.GetTransportGuid())
{
// transports size limited
// (also received at zeppelin/lift leave by some reason with t_* as absolute in continent coordinates, can be safely skipped)
if (movementInfo.GetTransportPos()->x > 50 || movementInfo.GetTransportPos()->y > 50 || movementInfo.GetTransportPos()->z > 100)
return false;
if (!MaNGOS::IsValidMapCoord(movementInfo.GetPos()->x + movementInfo.GetTransportPos()->x, movementInfo.GetPos()->y + movementInfo.GetTransportPos()->y,
movementInfo.GetPos()->z + movementInfo.GetTransportPos()->z, movementInfo.GetPos()->o + movementInfo.GetTransportPos()->o))
{
return false;
}
}
return true;
}
void WorldSession::HandleMoverRelocation(MovementInfo& movementInfo)
{
if (m_clientTimeDelay == 0)
m_clientTimeDelay = WorldTimer::getMSTime() - movementInfo.GetTime();
movementInfo.UpdateTime(movementInfo.GetTime() + m_clientTimeDelay + MOVEMENT_PACKET_TIME_DELAY);
Unit* mover = _player->GetMover();
if (Player* plMover = mover->GetTypeId() == TYPEID_PLAYER ? (Player*)mover : nullptr)
{
if (movementInfo.GetTransportGuid())
{
if (!plMover->m_transport)
{
// elevators also cause the client to send transport guid - just unmount if the guid can be found in the transport list
for (MapManager::TransportSet::const_iterator iter = sMapMgr.m_Transports.begin(); iter != sMapMgr.m_Transports.end(); ++iter)
{
if ((*iter)->GetObjectGuid() == movementInfo.GetTransportGuid())
{
plMover->m_transport = (*iter);
(*iter)->AddPassenger(plMover);
break;
}
}
}
}
else if (plMover->m_transport) // if we were on a transport, leave
{
plMover->m_transport->RemovePassenger(plMover);
plMover->m_transport = nullptr;
movementInfo.ClearTransportData();
}
if (movementInfo.HasMovementFlag(MOVEFLAG_SWIMMING) != plMover->IsInWater())
{
// now client not include swimming flag in case jumping under water
plMover->SetInWater(!plMover->IsInWater() || plMover->GetTerrain()->IsUnderWater(movementInfo.GetPos()->x, movementInfo.GetPos()->y, movementInfo.GetPos()->z));
}
plMover->SetPosition(movementInfo.GetPos()->x, movementInfo.GetPos()->y, movementInfo.GetPos()->z, movementInfo.GetPos()->o);
plMover->m_movementInfo = movementInfo;
if (movementInfo.GetPos()->z < -500.0f)
{
if (plMover->GetBattleGround()
&& plMover->GetBattleGround()->HandlePlayerUnderMap(_player))
{
// do nothing, the handle already did if returned true
}
else
{
// NOTE: this is actually called many times while falling
// even after the player has been teleported away
// TODO: discard movement packets after the player is rooted
if (plMover->isAlive())
{
plMover->EnvironmentalDamage(DAMAGE_FALL_TO_VOID, plMover->GetMaxHealth());
// pl can be alive if GM/etc
if (!plMover->isAlive())
{
// change the death state to CORPSE to prevent the death timer from
// starting in the next player update
plMover->KillPlayer();
plMover->BuildPlayerRepop();
}
}
// cancel the death timer here if started
plMover->RepopAtGraveyard();
}
}
}
else // creature charmed
{
if (mover->IsInWorld())
mover->GetMap()->CreatureRelocation((Creature*)mover, movementInfo.GetPos()->x, movementInfo.GetPos()->y, movementInfo.GetPos()->z, movementInfo.GetPos()->o);
}
}