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