/
MiscHandler.cpp
1575 lines (1269 loc) · 51.2 KB
/
MiscHandler.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
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
*
* 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 "Language.h"
#include "Database/DatabaseEnv.h"
#include "Database/DatabaseImpl.h"
#include "WorldPacket.h"
#include "Opcodes.h"
#include "Log.h"
#include "Player.h"
#include "World.h"
#include "ObjectMgr.h"
#include "ObjectDefines.h"
#include "WorldSession.h"
#include "Auth/BigNumber.h"
#include "Auth/Sha1.h"
#include "UpdateData.h"
#include "LootMgr.h"
#include "Chat.h"
#include "ScriptCalls.h"
#include <zlib/zlib.h>
#include "ObjectAccessor.h"
#include "Object.h"
#include "BattleGround.h"
#include "Pet.h"
#include "SocialMgr.h"
#include "DBCEnums.h"
void WorldSession::HandleRepopRequestOpcode( WorldPacket & recv_data )
{
sLog.outDebug( "WORLD: Recvd CMSG_REPOP_REQUEST Message" );
recv_data.read_skip<uint8>();
if(GetPlayer()->isAlive() || GetPlayer()->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST))
return;
// the world update order is sessions, players, creatures
// the netcode runs in parallel with all of these
// creatures can kill players
// so if the server is lagging enough the player can
// release spirit after he's killed but before he is updated
if(GetPlayer()->getDeathState() == JUST_DIED)
{
sLog.outDebug("HandleRepopRequestOpcode: got request after player %s(%d) was killed and before he was updated", GetPlayer()->GetName(), GetPlayer()->GetGUIDLow());
GetPlayer()->KillPlayer();
}
//this is spirit release confirm?
GetPlayer()->RemovePet(NULL,PET_SAVE_NOT_IN_SLOT, true);
GetPlayer()->BuildPlayerRepop();
GetPlayer()->RepopAtGraveyard();
}
void WorldSession::HandleWhoOpcode( WorldPacket & recv_data )
{
sLog.outDebug( "WORLD: Recvd CMSG_WHO Message" );
//recv_data.hexlike();
uint32 clientcount = 0;
uint32 level_min, level_max, racemask, classmask, zones_count, str_count;
uint32 zoneids[10]; // 10 is client limit
std::string player_name, guild_name;
recv_data >> level_min; // maximal player level, default 0
recv_data >> level_max; // minimal player level, default 100 (MAX_LEVEL)
recv_data >> player_name; // player name, case sensitive...
recv_data >> guild_name; // guild name, case sensitive...
recv_data >> racemask; // race mask
recv_data >> classmask; // class mask
recv_data >> zones_count; // zones count, client limit=10 (2.0.10)
if(zones_count > 10)
return; // can't be received from real client or broken packet
for(uint32 i = 0; i < zones_count; ++i)
{
uint32 temp;
recv_data >> temp; // zone id, 0 if zone is unknown...
zoneids[i] = temp;
sLog.outDebug("Zone %u: %u", i, zoneids[i]);
}
recv_data >> str_count; // user entered strings count, client limit=4 (checked on 2.0.10)
if(str_count > 4)
return; // can't be received from real client or broken packet
sLog.outDebug("Minlvl %u, maxlvl %u, name %s, guild %s, racemask %u, classmask %u, zones %u, strings %u", level_min, level_max, player_name.c_str(), guild_name.c_str(), racemask, classmask, zones_count, str_count);
std::wstring str[4]; // 4 is client limit
for(uint32 i = 0; i < str_count; ++i)
{
std::string temp;
recv_data >> temp; // user entered string, it used as universal search pattern(guild+player name)?
if(!Utf8toWStr(temp,str[i]))
continue;
wstrToLower(str[i]);
sLog.outDebug("String %u: %s", i, temp.c_str());
}
std::wstring wplayer_name;
std::wstring wguild_name;
if(!(Utf8toWStr(player_name, wplayer_name) && Utf8toWStr(guild_name, wguild_name)))
return;
wstrToLower(wplayer_name);
wstrToLower(wguild_name);
// client send in case not set max level value 100 but mangos support 255 max level,
// update it to show GMs with characters after 100 level
if(level_max >= MAX_LEVEL)
level_max = STRONG_MAX_LEVEL;
uint32 team = _player->GetTeam();
uint32 security = GetSecurity();
bool allowTwoSideWhoList = sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_WHO_LIST);
AccountTypes gmLevelInWhoList = (AccountTypes)sWorld.getConfig(CONFIG_GM_LEVEL_IN_WHO_LIST);
WorldPacket data( SMSG_WHO, 50 ); // guess size
data << clientcount; // clientcount place holder
data << clientcount; // clientcount place holder
//TODO: Guard Player map
HashMapHolder<Player>::MapType& m = sObjectAccessor.GetPlayers();
for(HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
{
if (security == SEC_PLAYER)
{
// player can see member of other team only if CONFIG_ALLOW_TWO_SIDE_WHO_LIST
if (itr->second->GetTeam() != team && !allowTwoSideWhoList )
continue;
// player can see MODERATOR, GAME MASTER, ADMINISTRATOR only if CONFIG_GM_IN_WHO_LIST
if (itr->second->GetSession()->GetSecurity() > gmLevelInWhoList)
continue;
}
//do not process players which are not in world
if(!(itr->second->IsInWorld()))
continue;
// check if target is globally visible for player
if (!(itr->second->IsVisibleGloballyFor(_player)))
continue;
// check if target's level is in level range
uint32 lvl = itr->second->getLevel();
if (lvl < level_min || lvl > level_max)
continue;
// check if class matches classmask
uint32 class_ = itr->second->getClass();
if (!(classmask & (1 << class_)))
continue;
// check if race matches racemask
uint32 race = itr->second->getRace();
if (!(racemask & (1 << race)))
continue;
uint32 pzoneid = itr->second->GetZoneId();
bool z_show = true;
for(uint32 i = 0; i < zones_count; ++i)
{
if(zoneids[i] == pzoneid)
{
z_show = true;
break;
}
z_show = false;
}
if (!z_show)
continue;
std::string pname = itr->second->GetName();
std::wstring wpname;
if(!Utf8toWStr(pname,wpname))
continue;
wstrToLower(wpname);
if (!(wplayer_name.empty() || wpname.find(wplayer_name) != std::wstring::npos))
continue;
std::string gname = sObjectMgr.GetGuildNameById(itr->second->GetGuildId());
std::wstring wgname;
if(!Utf8toWStr(gname,wgname))
continue;
wstrToLower(wgname);
if (!(wguild_name.empty() || wgname.find(wguild_name) != std::wstring::npos))
continue;
std::string aname;
if(AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(itr->second->GetZoneId()))
aname = areaEntry->area_name[GetSessionDbcLocale()];
bool s_show = true;
for(uint32 i = 0; i < str_count; ++i)
{
if (!str[i].empty())
{
if (wgname.find(str[i]) != std::wstring::npos ||
wpname.find(str[i]) != std::wstring::npos ||
Utf8FitTo(aname, str[i]) )
{
s_show = true;
break;
}
s_show = false;
}
}
if (!s_show)
continue;
data << pname; // player name
data << gname; // guild name
data << uint32( lvl ); // player level
data << uint32( class_ ); // player class
data << uint32( race ); // player race
data << uint8(0); // new 2.4.0
data << uint32( pzoneid ); // player zone id
// 49 is maximum player count sent to client
if ((++clientcount) == 49)
break;
}
data.put( 0, clientcount ); // insert right count
data.put( sizeof(uint32), clientcount ); // insert right count
SendPacket(&data);
sLog.outDebug( "WORLD: Send SMSG_WHO Message" );
}
void WorldSession::HandleLogoutRequestOpcode( WorldPacket & /*recv_data*/ )
{
sLog.outDebug( "WORLD: Recvd CMSG_LOGOUT_REQUEST Message, security - %u", GetSecurity() );
if (uint64 lguid = GetPlayer()->GetLootGUID())
DoLootRelease(lguid);
//Can not logout if...
if( GetPlayer()->isInCombat() || //...is in combat
GetPlayer()->duel || //...is in Duel
//...is jumping ...is falling
GetPlayer()->m_movementInfo.HasMovementFlag(MovementFlags(MOVEFLAG_FALLING | MOVEFLAG_FALLINGFAR)))
{
WorldPacket data( SMSG_LOGOUT_RESPONSE, (2+4) ) ;
data << (uint8)0xC;
data << uint32(0);
data << uint8(0);
SendPacket( &data );
LogoutRequest(0);
return;
}
//instant logout in taverns/cities or on taxi or for admins, gm's, mod's if its enabled in mangosd.conf
if (GetPlayer()->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING) || GetPlayer()->isInFlight() ||
GetSecurity() >= (AccountTypes)sWorld.getConfig(CONFIG_INSTANT_LOGOUT))
{
LogoutPlayer(true);
return;
}
// not set flags if player can't free move to prevent lost state at logout cancel
if(GetPlayer()->CanFreeMove())
{
GetPlayer()->SetStandState(UNIT_STAND_STATE_SIT);
WorldPacket data( SMSG_FORCE_MOVE_ROOT, (8+4) ); // guess size
data.append(GetPlayer()->GetPackGUID());
data << (uint32)2;
SendPacket( &data );
GetPlayer()->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_STUNNED);
}
WorldPacket data( SMSG_LOGOUT_RESPONSE, 5 );
data << uint32(0);
data << uint8(0);
SendPacket( &data );
LogoutRequest(time(NULL));
}
void WorldSession::HandlePlayerLogoutOpcode( WorldPacket & /*recv_data*/ )
{
sLog.outDebug( "WORLD: Recvd CMSG_PLAYER_LOGOUT Message" );
}
void WorldSession::HandleLogoutCancelOpcode( WorldPacket & /*recv_data*/ )
{
sLog.outDebug( "WORLD: Recvd CMSG_LOGOUT_CANCEL Message" );
LogoutRequest(0);
WorldPacket data( SMSG_LOGOUT_CANCEL_ACK, 0 );
SendPacket( &data );
// not remove flags if can't free move - its not set in Logout request code.
if(GetPlayer()->CanFreeMove())
{
//!we can move again
data.Initialize( SMSG_FORCE_MOVE_UNROOT, 8 ); // guess size
data.append(GetPlayer()->GetPackGUID());
data << uint32(0);
SendPacket( &data );
//! Stand Up
GetPlayer()->SetStandState(UNIT_STAND_STATE_STAND);
//! DISABLE_ROTATE
GetPlayer()->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_STUNNED);
}
sLog.outDebug( "WORLD: sent SMSG_LOGOUT_CANCEL_ACK Message" );
}
void WorldSession::HandleTogglePvP( WorldPacket & recv_data )
{
// this opcode can be used in two ways: Either set explicit new status or toggle old status
if(recv_data.size() == 1)
{
bool newPvPStatus;
recv_data >> newPvPStatus;
GetPlayer()->ApplyModFlag(PLAYER_FLAGS, PLAYER_FLAGS_IN_PVP, newPvPStatus);
GetPlayer()->ApplyModFlag(PLAYER_FLAGS, PLAYER_FLAGS_PVP_TIMER, !newPvPStatus);
}
else
{
GetPlayer()->ToggleFlag(PLAYER_FLAGS, PLAYER_FLAGS_IN_PVP);
GetPlayer()->ToggleFlag(PLAYER_FLAGS, PLAYER_FLAGS_PVP_TIMER);
}
if(GetPlayer()->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_IN_PVP))
{
if(!GetPlayer()->IsPvP() || GetPlayer()->pvpInfo.endTimer != 0)
GetPlayer()->UpdatePvP(true, true);
}
else
{
if(!GetPlayer()->pvpInfo.inHostileArea && GetPlayer()->IsPvP())
GetPlayer()->pvpInfo.endTimer = time(NULL); // start toggle-off
}
}
void WorldSession::HandleZoneUpdateOpcode( WorldPacket & recv_data )
{
uint32 newZone;
recv_data >> newZone;
sLog.outDetail("WORLD: Recvd ZONE_UPDATE: %u", newZone);
// use server size data
uint32 newzone, newarea;
GetPlayer()->GetZoneAndAreaId(newzone, newarea);
GetPlayer()->UpdateZone(newzone, newarea);
}
void WorldSession::HandleSetTargetOpcode( WorldPacket & recv_data )
{
// When this packet send?
uint64 guid ;
recv_data >> guid;
_player->SetTargetGUID(guid);
// update reputation list if need
Unit* unit = ObjectAccessor::GetUnit(*_player, guid );
if(!unit)
return;
if(FactionTemplateEntry const* factionTemplateEntry = sFactionTemplateStore.LookupEntry(unit->getFaction()))
_player->GetReputationMgr().SetVisible(factionTemplateEntry);
}
void WorldSession::HandleSetSelectionOpcode( WorldPacket & recv_data )
{
uint64 guid;
recv_data >> guid;
_player->SetSelection(guid);
// update reputation list if need
Unit* unit = ObjectAccessor::GetUnit(*_player, guid );
if(!unit)
return;
if(FactionTemplateEntry const* factionTemplateEntry = sFactionTemplateStore.LookupEntry(unit->getFaction()))
_player->GetReputationMgr().SetVisible(factionTemplateEntry);
}
void WorldSession::HandleStandStateChangeOpcode( WorldPacket & recv_data )
{
// sLog.outDebug( "WORLD: Received CMSG_STANDSTATECHANGE" ); -- too many spam in log at lags/debug stop
uint32 animstate;
recv_data >> animstate;
_player->SetStandState(animstate);
}
void WorldSession::HandleContactListOpcode( WorldPacket & recv_data )
{
sLog.outDebug( "WORLD: Received CMSG_CONTACT_LIST" );
uint32 unk;
recv_data >> unk;
sLog.outDebug("unk value is %u", unk);
_player->GetSocial()->SendSocialList();
}
void WorldSession::HandleAddFriendOpcode( WorldPacket & recv_data )
{
sLog.outDebug( "WORLD: Received CMSG_ADD_FRIEND" );
std::string friendName = GetMangosString(LANG_FRIEND_IGNORE_UNKNOWN);
std::string friendNote;
recv_data >> friendName;
recv_data >> friendNote;
if(!normalizePlayerName(friendName))
return;
CharacterDatabase.escape_string(friendName); // prevent SQL injection - normal name don't must changed by this call
sLog.outDebug( "WORLD: %s asked to add friend : '%s'",
GetPlayer()->GetName(), friendName.c_str() );
CharacterDatabase.AsyncPQuery(&WorldSession::HandleAddFriendOpcodeCallBack, GetAccountId(), friendNote, "SELECT guid, race FROM characters WHERE name = '%s'", friendName.c_str());
}
void WorldSession::HandleAddFriendOpcodeCallBack(QueryResult *result, uint32 accountId, std::string friendNote)
{
if(!result)
return;
uint64 friendGuid = MAKE_NEW_GUID((*result)[0].GetUInt32(), 0, HIGHGUID_PLAYER);
uint32 team = Player::TeamForRace((*result)[1].GetUInt8());
delete result;
WorldSession * session = sWorld.FindSession(accountId);
if(!session || !session->GetPlayer())
return;
FriendsResult friendResult = FRIEND_NOT_FOUND;
if(friendGuid)
{
if(friendGuid==session->GetPlayer()->GetGUID())
friendResult = FRIEND_SELF;
else if(session->GetPlayer()->GetTeam() != team && !sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_ADD_FRIEND) && session->GetSecurity() < SEC_MODERATOR)
friendResult = FRIEND_ENEMY;
else if(session->GetPlayer()->GetSocial()->HasFriend(GUID_LOPART(friendGuid)))
friendResult = FRIEND_ALREADY;
else
{
Player* pFriend = ObjectAccessor::FindPlayer(friendGuid);
if( pFriend && pFriend->IsInWorld() && pFriend->IsVisibleGloballyFor(session->GetPlayer()))
friendResult = FRIEND_ADDED_ONLINE;
else
friendResult = FRIEND_ADDED_OFFLINE;
if(!session->GetPlayer()->GetSocial()->AddToSocialList(GUID_LOPART(friendGuid), false))
{
friendResult = FRIEND_LIST_FULL;
sLog.outDebug( "WORLD: %s's friend list is full.", session->GetPlayer()->GetName());
}
session->GetPlayer()->GetSocial()->SetFriendNote(GUID_LOPART(friendGuid), friendNote);
}
}
sSocialMgr.SendFriendStatus(session->GetPlayer(), friendResult, GUID_LOPART(friendGuid), false);
sLog.outDebug( "WORLD: Sent (SMSG_FRIEND_STATUS)" );
}
void WorldSession::HandleDelFriendOpcode( WorldPacket & recv_data )
{
uint64 FriendGUID;
sLog.outDebug( "WORLD: Received CMSG_DEL_FRIEND" );
recv_data >> FriendGUID;
_player->GetSocial()->RemoveFromSocialList(GUID_LOPART(FriendGUID), false);
sSocialMgr.SendFriendStatus(GetPlayer(), FRIEND_REMOVED, GUID_LOPART(FriendGUID), false);
sLog.outDebug( "WORLD: Sent motd (SMSG_FRIEND_STATUS)" );
}
void WorldSession::HandleAddIgnoreOpcode( WorldPacket & recv_data )
{
sLog.outDebug( "WORLD: Received CMSG_ADD_IGNORE" );
std::string IgnoreName = GetMangosString(LANG_FRIEND_IGNORE_UNKNOWN);
recv_data >> IgnoreName;
if(!normalizePlayerName(IgnoreName))
return;
CharacterDatabase.escape_string(IgnoreName); // prevent SQL injection - normal name don't must changed by this call
sLog.outDebug( "WORLD: %s asked to Ignore: '%s'",
GetPlayer()->GetName(), IgnoreName.c_str() );
CharacterDatabase.AsyncPQuery(&WorldSession::HandleAddIgnoreOpcodeCallBack, GetAccountId(), "SELECT guid FROM characters WHERE name = '%s'", IgnoreName.c_str());
}
void WorldSession::HandleAddIgnoreOpcodeCallBack(QueryResult *result, uint32 accountId)
{
if(!result)
return;
uint64 IgnoreGuid = MAKE_NEW_GUID((*result)[0].GetUInt32(), 0, HIGHGUID_PLAYER);
delete result;
WorldSession * session = sWorld.FindSession(accountId);
if(!session || !session->GetPlayer())
return;
FriendsResult ignoreResult = FRIEND_IGNORE_NOT_FOUND;
if(IgnoreGuid)
{
if(IgnoreGuid == session->GetPlayer()->GetGUID()) //not add yourself
ignoreResult = FRIEND_IGNORE_SELF;
else if( session->GetPlayer()->GetSocial()->HasIgnore(GUID_LOPART(IgnoreGuid)) )
ignoreResult = FRIEND_IGNORE_ALREADY;
else
{
ignoreResult = FRIEND_IGNORE_ADDED;
// ignore list full
if(!session->GetPlayer()->GetSocial()->AddToSocialList(GUID_LOPART(IgnoreGuid), true))
ignoreResult = FRIEND_IGNORE_FULL;
}
}
sSocialMgr.SendFriendStatus(session->GetPlayer(), ignoreResult, GUID_LOPART(IgnoreGuid), false);
sLog.outDebug( "WORLD: Sent (SMSG_FRIEND_STATUS)" );
}
void WorldSession::HandleDelIgnoreOpcode( WorldPacket & recv_data )
{
uint64 IgnoreGUID;
sLog.outDebug( "WORLD: Received CMSG_DEL_IGNORE" );
recv_data >> IgnoreGUID;
_player->GetSocial()->RemoveFromSocialList(GUID_LOPART(IgnoreGUID), true);
sSocialMgr.SendFriendStatus(GetPlayer(), FRIEND_IGNORE_REMOVED, GUID_LOPART(IgnoreGUID), false);
sLog.outDebug( "WORLD: Sent motd (SMSG_FRIEND_STATUS)" );
}
void WorldSession::HandleSetContactNotesOpcode( WorldPacket & recv_data )
{
sLog.outDebug("CMSG_SET_CONTACT_NOTES");
uint64 guid;
std::string note;
recv_data >> guid >> note;
_player->GetSocial()->SetFriendNote(GUID_LOPART(guid), note);
}
void WorldSession::HandleBugOpcode( WorldPacket & recv_data )
{
uint32 suggestion, contentlen, typelen;
std::string content, type;
recv_data >> suggestion >> contentlen >> content;
recv_data >> typelen >> type;
if( suggestion == 0 )
sLog.outDebug( "WORLD: Received CMSG_BUG [Bug Report]" );
else
sLog.outDebug( "WORLD: Received CMSG_BUG [Suggestion]" );
sLog.outDebug("%s", type.c_str() );
sLog.outDebug("%s", content.c_str() );
CharacterDatabase.escape_string(type);
CharacterDatabase.escape_string(content);
CharacterDatabase.PExecute ("INSERT INTO bugreport (type,content) VALUES('%s', '%s')", type.c_str( ), content.c_str( ));
}
void WorldSession::HandleReclaimCorpseOpcode(WorldPacket &recv_data)
{
sLog.outDetail("WORLD: Received CMSG_RECLAIM_CORPSE");
if (GetPlayer()->isAlive())
return;
// do not allow corpse reclaim in arena
if (GetPlayer()->InArena())
return;
// body not released yet
if(!GetPlayer()->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST))
return;
Corpse *corpse = GetPlayer()->GetCorpse();
if (!corpse )
return;
// prevent resurrect before 30-sec delay after body release not finished
if(corpse->GetGhostTime() + GetPlayer()->GetCorpseReclaimDelay(corpse->GetType()==CORPSE_RESURRECTABLE_PVP) > time(NULL))
return;
if (!corpse->IsWithinDistInMap(GetPlayer(), CORPSE_RECLAIM_RADIUS, true))
return;
uint64 guid;
recv_data >> guid;
// resurrect
GetPlayer()->ResurrectPlayer(GetPlayer()->InBattleGround() ? 1.0f : 0.5f);
// spawn bones
GetPlayer()->SpawnCorpseBones();
}
void WorldSession::HandleResurrectResponseOpcode(WorldPacket & recv_data)
{
sLog.outDetail("WORLD: Received CMSG_RESURRECT_RESPONSE");
if(GetPlayer()->isAlive())
return;
uint64 guid;
uint8 status;
recv_data >> guid;
recv_data >> status;
if(status == 0)
{
GetPlayer()->clearResurrectRequestData(); // reject
return;
}
if(!GetPlayer()->isRessurectRequestedBy(guid))
return;
GetPlayer()->ResurectUsingRequestData(); // will call spawncorpsebones
}
void WorldSession::HandleAreaTriggerOpcode(WorldPacket & recv_data)
{
sLog.outDebug("WORLD: Received CMSG_AREATRIGGER");
uint32 Trigger_ID;
recv_data >> Trigger_ID;
sLog.outDebug("Trigger ID: %u", Trigger_ID);
if(GetPlayer()->isInFlight())
{
sLog.outDebug("Player '%s' (GUID: %u) in flight, ignore Area Trigger ID: %u", GetPlayer()->GetName(), GetPlayer()->GetGUIDLow(), Trigger_ID);
return;
}
AreaTriggerEntry const* atEntry = sAreaTriggerStore.LookupEntry(Trigger_ID);
if(!atEntry)
{
sLog.outDebug("Player '%s' (GUID: %u) send unknown (by DBC) Area Trigger ID: %u", GetPlayer()->GetName(), GetPlayer()->GetGUIDLow(), Trigger_ID);
return;
}
if (GetPlayer()->GetMapId() != atEntry->mapid)
{
sLog.outDebug("Player '%s' (GUID: %u) too far (trigger map: %u player map: %u), ignore Area Trigger ID: %u", GetPlayer()->GetName(), atEntry->mapid, GetPlayer()->GetMapId(), GetPlayer()->GetGUIDLow(), Trigger_ID);
return;
}
// delta is safe radius
const float delta = 5.0f;
// check if player in the range of areatrigger
Player* pl = GetPlayer();
if (atEntry->radius > 0)
{
// if we have radius check it
float dist = pl->GetDistance(atEntry->x, atEntry->y, atEntry->z);
if(dist > atEntry->radius + delta)
{
sLog.outDebug("Player '%s' (GUID: %u) too far (radius: %f distance: %f), ignore Area Trigger ID: %u",
pl->GetName(), pl->GetGUIDLow(), atEntry->radius, dist, Trigger_ID);
return;
}
}
else
{
// we have only extent
// rotate the players position instead of rotating the whole cube, that way we can make a simplified
// is-in-cube check and we have to calculate only one point instead of 4
// 2PI = 360°, keep in mind that ingame orientation is counter-clockwise
double rotation = 2*M_PI-atEntry->box_orientation;
double sinVal = sin(rotation);
double cosVal = cos(rotation);
float playerBoxDistX = pl->GetPositionX() - atEntry->x;
float playerBoxDistY = pl->GetPositionY() - atEntry->y;
float rotPlayerX = atEntry->x + playerBoxDistX * cosVal - playerBoxDistY*sinVal;
float rotPlayerY = atEntry->y + playerBoxDistY * cosVal + playerBoxDistX*sinVal;
// box edges are parallel to coordiante axis, so we can treat every dimension independently :D
float dz = pl->GetPositionZ() - atEntry->z;
float dx = rotPlayerX - atEntry->x;
float dy = rotPlayerY - atEntry->y;
if( (fabs(dx) > atEntry->box_x/2 + delta) ||
(fabs(dy) > atEntry->box_y/2 + delta) ||
(fabs(dz) > atEntry->box_z/2 + delta) )
{
sLog.outDebug("Player '%s' (GUID: %u) too far (1/2 box X: %f 1/2 box Y: %f 1/2 box Z: %f rotatedPlayerX: %f rotatedPlayerY: %f dZ:%f), ignore Area Trigger ID: %u",
pl->GetName(), pl->GetGUIDLow(), atEntry->box_x/2, atEntry->box_y/2, atEntry->box_z/2, rotPlayerX, rotPlayerY, dz, Trigger_ID);
return;
}
}
if(Script->scriptAreaTrigger(GetPlayer(), atEntry))
return;
uint32 quest_id = sObjectMgr.GetQuestForAreaTrigger( Trigger_ID );
if( quest_id && GetPlayer()->isAlive() && GetPlayer()->IsActiveQuest(quest_id) )
{
Quest const* pQuest = sObjectMgr.GetQuestTemplate(quest_id);
if( pQuest )
{
if(GetPlayer()->GetQuestStatus(quest_id) == QUEST_STATUS_INCOMPLETE)
GetPlayer()->AreaExploredOrEventHappens( quest_id );
}
}
if(sObjectMgr.IsTavernAreaTrigger(Trigger_ID))
{
// set resting flag we are in the inn
GetPlayer()->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING);
GetPlayer()->InnEnter(time(NULL), atEntry->mapid, atEntry->x, atEntry->y, atEntry->z);
GetPlayer()->SetRestType(REST_TYPE_IN_TAVERN);
if(sWorld.IsFFAPvPRealm())
GetPlayer()->SetFFAPvP(false);
return;
}
if(GetPlayer()->InBattleGround())
{
BattleGround* bg = GetPlayer()->GetBattleGround();
if(bg)
bg->HandleAreaTrigger(GetPlayer(), Trigger_ID);
return;
}
// NULL if all values default (non teleport trigger)
AreaTrigger const* at = sObjectMgr.GetAreaTrigger(Trigger_ID);
if(!at)
return;
if(!GetPlayer()->isGameMaster())
{
uint32 missingLevel = 0;
if(GetPlayer()->getLevel() < at->requiredLevel && !sWorld.getConfig(CONFIG_INSTANCE_IGNORE_LEVEL))
missingLevel = at->requiredLevel;
// must have one or the other, report the first one that's missing
uint32 missingItem = 0;
if(at->requiredItem)
{
if(!GetPlayer()->HasItemCount(at->requiredItem, 1) &&
(!at->requiredItem2 || !GetPlayer()->HasItemCount(at->requiredItem2, 1)))
missingItem = at->requiredItem;
}
else if(at->requiredItem2 && !GetPlayer()->HasItemCount(at->requiredItem2, 1))
missingItem = at->requiredItem2;
MapEntry const* mapEntry = sMapStore.LookupEntry(at->target_mapId);
if(!mapEntry)
return;
bool isRegularTargetMap = GetPlayer()->GetDifficulty(mapEntry->IsRaid()) == REGULAR_DIFFICULTY;
uint32 missingKey = 0;
if (!isRegularTargetMap)
{
if(at->heroicKey)
{
if(!GetPlayer()->HasItemCount(at->heroicKey, 1) &&
(!at->heroicKey2 || !GetPlayer()->HasItemCount(at->heroicKey2, 1)))
missingKey = at->heroicKey;
}
else if(at->heroicKey2 && !GetPlayer()->HasItemCount(at->heroicKey2, 1))
missingKey = at->heroicKey2;
}
uint32 missingQuest = 0;
if (!isRegularTargetMap)
{
if (at->requiredQuestHeroic && !GetPlayer()->GetQuestRewardStatus(at->requiredQuestHeroic))
missingQuest = at->requiredQuestHeroic;
}
else
{
if(at->requiredQuest && !GetPlayer()->GetQuestRewardStatus(at->requiredQuest))
missingQuest = at->requiredQuest;
}
if(missingLevel || missingItem || missingKey || missingQuest)
{
// TODO: all this is probably wrong
if(missingItem)
SendAreaTriggerMessage(GetMangosString(LANG_LEVEL_MINREQUIRED_AND_ITEM), at->requiredLevel, ObjectMgr::GetItemPrototype(missingItem)->Name1);
else if(missingKey)
GetPlayer()->SendTransferAborted(at->target_mapId, TRANSFER_ABORT_DIFFICULTY, isRegularTargetMap ? DUNGEON_DIFFICULTY_NORMAL : DUNGEON_DIFFICULTY_HEROIC);
else if(missingQuest)
SendAreaTriggerMessage("%s", at->requiredFailedText.c_str());
else if(missingLevel)
SendAreaTriggerMessage(GetMangosString(LANG_LEVEL_MINREQUIRED), missingLevel);
return;
}
}
GetPlayer()->TeleportTo(at->target_mapId, at->target_X, at->target_Y, at->target_Z, at->target_Orientation, TELE_TO_NOT_LEAVE_TRANSPORT);
}
void WorldSession::HandleUpdateAccountData(WorldPacket &recv_data)
{
sLog.outDetail("WORLD: Received CMSG_UPDATE_ACCOUNT_DATA");
uint32 type, timestamp, decompressedSize;
recv_data >> type >> timestamp >> decompressedSize;
sLog.outDebug("UAD: type %u, time %u, decompressedSize %u", type, timestamp, decompressedSize);
if(type > NUM_ACCOUNT_DATA_TYPES)
return;
if(decompressedSize == 0) // erase
{
SetAccountData(AccountDataType(type), 0, "");
WorldPacket data(SMSG_UPDATE_ACCOUNT_DATA_COMPLETE, 4+4);
data << uint32(type);
data << uint32(0);
SendPacket(&data);
return;
}
if(decompressedSize > 0xFFFF)
{
recv_data.rpos(recv_data.wpos()); // unnneded warning spam in this case
sLog.outError("UAD: Account data packet too big, size %u", decompressedSize);
return;
}
ByteBuffer dest;
dest.resize(decompressedSize);
uLongf realSize = decompressedSize;
if(uncompress(const_cast<uint8*>(dest.contents()), &realSize, const_cast<uint8*>(recv_data.contents() + recv_data.rpos()), recv_data.size() - recv_data.rpos()) != Z_OK)
{
recv_data.rpos(recv_data.wpos()); // unneded warning spam in this case
sLog.outError("UAD: Failed to decompress account data");
return;
}
recv_data.rpos(recv_data.wpos()); // uncompress read (recv_data.size() - recv_data.rpos())
std::string adata;
dest >> adata;
SetAccountData(AccountDataType(type), timestamp, adata);
WorldPacket data(SMSG_UPDATE_ACCOUNT_DATA_COMPLETE, 4+4);
data << uint32(type);
data << uint32(0);
SendPacket(&data);
}
void WorldSession::HandleRequestAccountData(WorldPacket& recv_data)
{
sLog.outDetail("WORLD: Received CMSG_REQUEST_ACCOUNT_DATA");
uint32 type;
recv_data >> type;
sLog.outDebug("RAD: type %u", type);
if(type > NUM_ACCOUNT_DATA_TYPES)
return;
AccountData *adata = GetAccountData(AccountDataType(type));
uint32 size = adata->Data.size();
uLongf destSize = compressBound(size);
ByteBuffer dest;
dest.resize(destSize);
if(size && compress(const_cast<uint8*>(dest.contents()), &destSize, (uint8*)adata->Data.c_str(), size) != Z_OK)
{
sLog.outDebug("RAD: Failed to compress account data");
return;
}
dest.resize(destSize);
WorldPacket data(SMSG_UPDATE_ACCOUNT_DATA, 8+4+4+4+destSize);
data << uint64(_player ? _player->GetGUID() : 0); // player guid
data << uint32(type); // type (0-7)
data << uint32(adata->Time); // unix time
data << uint32(size); // decompressed length
data.append(dest); // compressed data
SendPacket(&data);
}
void WorldSession::HandleSetActionButtonOpcode(WorldPacket& recv_data)
{
sLog.outDebug( "WORLD: Received CMSG_SET_ACTION_BUTTON" );
uint8 button;
uint32 packetData;
recv_data >> button >> packetData;
uint32 action = ACTION_BUTTON_ACTION(packetData);
uint8 type = ACTION_BUTTON_TYPE(packetData);
sLog.outDetail( "BUTTON: %u ACTION: %u TYPE: %u", button, action, type );
if (!packetData)
{
sLog.outDetail( "MISC: Remove action from button %u", button );
GetPlayer()->removeActionButton(button);
}
else
{
switch(type)
{
case ACTION_BUTTON_MACRO:
case ACTION_BUTTON_CMACRO:
sLog.outDetail( "MISC: Added Macro %u into button %u", action, button );
break;
case ACTION_BUTTON_EQSET:
sLog.outDetail( "MISC: Added EquipmentSet %u into button %u", action, button );
break;
case ACTION_BUTTON_SPELL:
sLog.outDetail( "MISC: Added Spell %u into button %u", action, button );
break;
case ACTION_BUTTON_ITEM:
sLog.outDetail( "MISC: Added Item %u into button %u", action, button );
break;
default:
sLog.outError( "MISC: Unknown action button type %u for action %u into button %u", type, action, button );
return;
}
GetPlayer()->addActionButton(button, action, type);
}
}
void WorldSession::HandleCompleteCinematic( WorldPacket & /*recv_data*/ )
{
DEBUG_LOG( "WORLD: Player is watching cinema" );
}
void WorldSession::HandleNextCinematicCamera( WorldPacket & /*recv_data*/ )
{
DEBUG_LOG( "WORLD: Which movie to play" );
}