forked from mangoszero/server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerCommands.cpp
More file actions
2394 lines (2050 loc) · 59.6 KB
/
PlayerCommands.cpp
File metadata and controls
2394 lines (2050 loc) · 59.6 KB
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
/**
* MaNGOS is a full featured server for World of Warcraft, supporting
* the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8
*
* Copyright (C) 2005-2025 MaNGOS <https://www.getmangos.eu>
*
* 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
*
* World of Warcraft, and all World of Warcraft or Warcraft art, images,
* and lore are copyrighted by Blizzard Entertainment, Inc.
*/
#include "Chat.h"
#include "ObjectMgr.h"
#include "World.h"
#include "AccountMgr.h"
#include "SQLStorages.h"
/**********************************************************************
CommandTable : characterCommandTable
/***********************************************************************/
bool ChatHandler::HandleCharacterEraseCommand(char* args)
{
char* nameStr = ExtractLiteralArg(&args);
if (!nameStr)
{
return false;
}
Player* target;
ObjectGuid target_guid;
std::string target_name;
if (!ExtractPlayerTarget(&nameStr, &target, &target_guid, &target_name))
{
return false;
}
uint32 account_id;
if (target)
{
account_id = target->GetSession()->GetAccountId();
target->GetSession()->KickPlayer();
}
else
{
account_id = sObjectMgr.GetPlayerAccountIdByGUID(target_guid);
}
std::string account_name;
sAccountMgr.GetName(account_id, account_name);
Player::DeleteFromDB(target_guid, account_id, true, true);
PSendSysMessage(LANG_CHARACTER_DELETED, target_name.c_str(), target_guid.GetCounter(), account_name.c_str(), account_id);
return true;
}
bool ChatHandler::HandleCharacterLevelCommand(char* args)
{
char* nameStr = ExtractOptNotLastArg(&args);
int32 newlevel;
bool nolevel = false;
// exception opt second arg: .character level $name
if (!ExtractInt32(&args, newlevel))
{
if (!nameStr)
{
nameStr = ExtractArg(&args);
if (!nameStr)
{
return false;
}
nolevel = true;
}
else
{
return false;
}
}
Player* target;
ObjectGuid target_guid;
std::string target_name;
if (!ExtractPlayerTarget(&nameStr, &target, &target_guid, &target_name))
{
return false;
}
int32 oldlevel = target ? target->getLevel() : Player::GetLevelFromDB(target_guid);
if (nolevel)
{
newlevel = oldlevel;
}
if (newlevel < 1)
{
return false; // invalid level
}
if (newlevel > STRONG_MAX_LEVEL) // hardcoded maximum level
{
newlevel = STRONG_MAX_LEVEL;
}
HandleCharacterLevel(target, target_guid, oldlevel, newlevel);
if (!m_session || m_session->GetPlayer() != target) // including player==NULL
{
std::string nameLink = playerLink(target_name);
PSendSysMessage(LANG_YOU_CHANGE_LVL, nameLink.c_str(), newlevel);
}
return true;
}
// rename characters
bool ChatHandler::HandleCharacterRenameCommand(char* args)
{
Player* target;
ObjectGuid target_guid;
std::string target_name;
if (!ExtractPlayerTarget(&args, &target, &target_guid, &target_name))
{
return false;
}
if (target)
{
// check online security
if (HasLowerSecurity(target))
{
return false;
}
PSendSysMessage(LANG_RENAME_PLAYER, GetNameLink(target).c_str());
target->SetAtLoginFlag(AT_LOGIN_RENAME);
CharacterDatabase.PExecute("UPDATE `characters` SET `at_login` = `at_login` | '1' WHERE `guid` = '%u'", target->GetGUIDLow());
}
else
{
// check offline security
if (HasLowerSecurity(NULL, target_guid))
{
return false;
}
std::string oldNameLink = playerLink(target_name);
PSendSysMessage(LANG_RENAME_PLAYER_GUID, oldNameLink.c_str(), target_guid.GetCounter());
CharacterDatabase.PExecute("UPDATE `characters` SET `at_login` = `at_login` | '1' WHERE `guid` = '%u'", target_guid.GetCounter());
}
return true;
}
bool ChatHandler::HandleCharacterReputationCommand(char* args)
{
Player* target;
if (!ExtractPlayerTarget(&args, &target))
{
return false;
}
LocaleConstant loc = GetSessionDbcLocale();
FactionStateList const& targetFSL = target->GetReputationMgr().GetStateList();
for (FactionStateList::const_iterator itr = targetFSL.begin(); itr != targetFSL.end(); ++itr)
{
FactionEntry const* factionEntry = sFactionStore.LookupEntry(itr->second.ID);
ShowFactionListHelper(factionEntry, loc, &itr->second, target);
}
return true;
}
/**********************************************************************
CommandTable : characterDeletedCommandTable
/***********************************************************************/
/**
* Collects all GUIDs (and related info) from deleted characters which are still in the database.
*
* @param foundList a reference to an std::list which will be filled with info data
* @param searchString the search string which either contains a player GUID (low part) or a part of the character-name
* @return returns false if there was a problem while selecting the characters (e.g. player name not normalizeable)
*/
bool ChatHandler::GetDeletedCharacterInfoList(DeletedInfoList& foundList, std::string searchString)
{
QueryResult* resultChar;
if (!searchString.empty())
{
// search by GUID
if (isNumeric(searchString))
{
resultChar = CharacterDatabase.PQuery("SELECT `guid`, `deleteInfos_Name`, `deleteInfos_Account`, `deleteDate` FROM `characters` WHERE `deleteDate` IS NOT NULL AND `guid` = %u", uint32(atoi(searchString.c_str())));
}
// search by name
else
{
if (!normalizePlayerName(searchString))
{
return false;
}
resultChar = CharacterDatabase.PQuery("SELECT `guid`, `deleteInfos_Name`, `deleteInfos_Account`, `deleteDate` FROM `characters` WHERE `deleteDate` IS NOT NULL AND `deleteInfos_Name` " _LIKE_ " " _CONCAT3_("'%%'", "'%s'", "'%%'"), searchString.c_str());
}
}
else
{
resultChar = CharacterDatabase.Query("SELECT `guid`, `deleteInfos_Name`, `deleteInfos_Account`, `deleteDate` FROM `characters` WHERE `deleteDate` IS NOT NULL");
}
if (resultChar)
{
do
{
Field* fields = resultChar->Fetch();
DeletedInfo info;
info.lowguid = fields[0].GetUInt32();
info.name = fields[1].GetCppString();
info.accountId = fields[2].GetUInt32();
// account name will be empty for nonexistent account
sAccountMgr.GetName(info.accountId, info.accountName);
info.deleteDate = time_t(fields[3].GetUInt64());
foundList.push_back(info);
}
while (resultChar->NextRow());
delete resultChar;
}
return true;
}
/**
* Generate WHERE guids list by deleted info in way preventing return too long where list for existed query string length limit.
*
* @param itr a reference to an deleted info list iterator, it updated in function for possible next function call if list to long
* @param itr_end a reference to an deleted info list iterator end()
* @return returns generated where list string in form: 'guid IN (gui1, guid2, ...)'
*/
std::string ChatHandler::GenerateDeletedCharacterGUIDsWhereStr(DeletedInfoList::const_iterator& itr, DeletedInfoList::const_iterator const& itr_end)
{
std::ostringstream wherestr;
wherestr << "guid IN ('";
for (; itr != itr_end; ++itr)
{
wherestr << itr->lowguid;
if (wherestr.str().size() > MAX_QUERY_LEN - 50) // near to max query
{
++itr;
break;
}
DeletedInfoList::const_iterator itr2 = itr;
if (++itr2 != itr_end)
{
wherestr << "','";
}
}
wherestr << "')";
return wherestr.str();
}
/**
* Shows all deleted characters which matches the given search string, expected non empty list
*
* @see ChatHandler::HandleCharacterDeletedListCommand
* @see ChatHandler::HandleCharacterDeletedRestoreCommand
* @see ChatHandler::HandleCharacterDeletedDeleteCommand
* @see ChatHandler::DeletedInfoList
*
* @param foundList contains a list with all found deleted characters
*/
void ChatHandler::HandleCharacterDeletedListHelper(DeletedInfoList const& foundList)
{
if (!m_session)
{
SendSysMessage(LANG_CHARACTER_DELETED_LIST_BAR);
SendSysMessage(LANG_CHARACTER_DELETED_LIST_HEADER);
SendSysMessage(LANG_CHARACTER_DELETED_LIST_BAR);
}
for (DeletedInfoList::const_iterator itr = foundList.begin(); itr != foundList.end(); ++itr)
{
std::string dateStr = TimeToTimestampStr(itr->deleteDate);
if (!m_session)
PSendSysMessage(LANG_CHARACTER_DELETED_LIST_LINE_CONSOLE,
itr->lowguid, itr->name.c_str(), itr->accountName.empty() ? "<nonexistent>" : itr->accountName.c_str(),
itr->accountId, dateStr.c_str());
else
PSendSysMessage(LANG_CHARACTER_DELETED_LIST_LINE_CHAT,
itr->lowguid, itr->name.c_str(), itr->accountName.empty() ? "<nonexistent>" : itr->accountName.c_str(),
itr->accountId, dateStr.c_str());
}
if (!m_session)
{
SendSysMessage(LANG_CHARACTER_DELETED_LIST_BAR);
}
}
/**
* Restore a previously deleted character
*
* @see ChatHandler::HandleCharacterDeletedListHelper
* @see ChatHandler::HandleCharacterDeletedRestoreCommand
* @see ChatHandler::HandleCharacterDeletedDeleteCommand
* @see ChatHandler::DeletedInfoList
*
* @param delInfo the informations about the character which will be restored
*/
void ChatHandler::HandleCharacterDeletedRestoreHelper(DeletedInfo const& delInfo)
{
if (delInfo.accountName.empty()) // account not exist
{
PSendSysMessage(LANG_CHARACTER_DELETED_SKIP_ACCOUNT, delInfo.name.c_str(), delInfo.lowguid, delInfo.accountId);
return;
}
// check character count
uint32 charcount = sAccountMgr.GetCharactersCount(delInfo.accountId);
if (charcount >= 10)
{
PSendSysMessage(LANG_CHARACTER_DELETED_SKIP_FULL, delInfo.name.c_str(), delInfo.lowguid, delInfo.accountId);
return;
}
if (sObjectMgr.GetPlayerGuidByName(delInfo.name))
{
PSendSysMessage(LANG_CHARACTER_DELETED_SKIP_NAME, delInfo.name.c_str(), delInfo.lowguid, delInfo.accountId);
return;
}
CharacterDatabase.PExecute("UPDATE `characters` SET `name`='%s', `account`='%u', `deleteDate`=NULL, `deleteInfos_Name`=NULL, `deleteInfos_Account`=NULL WHERE `deleteDate` IS NOT NULL AND `guid` = %u",
delInfo.name.c_str(), delInfo.accountId, delInfo.lowguid);
}
/**
* Handles the '.character deleted delete' command, which completely deletes all deleted characters which matches the given search string
*
* @see Player::GetDeletedCharacterGUIDs
* @see Player::DeleteFromDB
* @see ChatHandler::HandleCharacterDeletedListCommand
* @see ChatHandler::HandleCharacterDeletedRestoreCommand
*
* @param args the search string which either contains a player GUID or a part of the character-name
*/
bool ChatHandler::HandleCharacterDeletedDeleteCommand(char* args)
{
// It is required to submit at least one argument
if (!*args)
{
return false;
}
DeletedInfoList foundList;
if (!GetDeletedCharacterInfoList(foundList, args))
{
return false;
}
if (foundList.empty())
{
SendSysMessage(LANG_CHARACTER_DELETED_LIST_EMPTY);
return false;
}
SendSysMessage(LANG_CHARACTER_DELETED_DELETE);
HandleCharacterDeletedListHelper(foundList);
// Call the appropriate function to delete them (current account for deleted characters is 0)
for (DeletedInfoList::const_iterator itr = foundList.begin(); itr != foundList.end(); ++itr)
{
Player::DeleteFromDB(ObjectGuid(HIGHGUID_PLAYER, itr->lowguid), 0, false, true);
}
return true;
}
/**
* Handles the '.character deleted list' command, which shows all deleted characters which matches the given search string
*
* @see ChatHandler::HandleCharacterDeletedListHelper
* @see ChatHandler::HandleCharacterDeletedRestoreCommand
* @see ChatHandler::HandleCharacterDeletedDeleteCommand
* @see ChatHandler::DeletedInfoList
*
* @param args the search string which either contains a player GUID or a part of the character-name
*/
bool ChatHandler::HandleCharacterDeletedListCommand(char* args)
{
DeletedInfoList foundList;
if (!GetDeletedCharacterInfoList(foundList, args))
{
return false;
}
// if no characters have been found, output a warning
if (foundList.empty())
{
SendSysMessage(LANG_CHARACTER_DELETED_LIST_EMPTY);
return false;
}
HandleCharacterDeletedListHelper(foundList);
return true;
}
/**
* Handles the '.character deleted restore' command, which restores all deleted characters which matches the given search string
*
* The command automatically calls '.character deleted list' command with the search string to show all restored characters.
*
* @see ChatHandler::HandleCharacterDeletedRestoreHelper
* @see ChatHandler::HandleCharacterDeletedListCommand
* @see ChatHandler::HandleCharacterDeletedDeleteCommand
*
* @param args the search string which either contains a player GUID or a part of the character-name
*/
bool ChatHandler::HandleCharacterDeletedRestoreCommand(char* args)
{
// It is required to submit at least one argument
if (!*args)
{
return false;
}
std::string searchString;
std::string newCharName;
uint32 newAccount = 0;
// GCC by some strange reason fail build code without temporary variable
std::istringstream params(args);
params >> searchString >> newCharName >> newAccount;
DeletedInfoList foundList;
if (!GetDeletedCharacterInfoList(foundList, searchString))
{
return false;
}
if (foundList.empty())
{
SendSysMessage(LANG_CHARACTER_DELETED_LIST_EMPTY);
return false;
}
SendSysMessage(LANG_CHARACTER_DELETED_RESTORE);
HandleCharacterDeletedListHelper(foundList);
if (newCharName.empty())
{
// Drop nonexistent account cases
for (DeletedInfoList::iterator itr = foundList.begin(); itr != foundList.end(); ++itr)
{
HandleCharacterDeletedRestoreHelper(*itr);
}
}
else if (foundList.size() == 1 && normalizePlayerName(newCharName))
{
DeletedInfo delInfo = foundList.front();
// update name
delInfo.name = newCharName;
// if new account provided update deleted info
if (newAccount && newAccount != delInfo.accountId)
{
delInfo.accountId = newAccount;
sAccountMgr.GetName(newAccount, delInfo.accountName);
}
HandleCharacterDeletedRestoreHelper(delInfo);
}
else
{
SendSysMessage(LANG_CHARACTER_DELETED_ERR_RENAME);
}
return true;
}
/**
* Handles the '.character deleted old' command, which completely deletes all deleted characters deleted with some days ago
*
* @see Player::DeleteOldCharacters
* @see Player::DeleteFromDB
* @see ChatHandler::HandleCharacterDeletedDeleteCommand
* @see ChatHandler::HandleCharacterDeletedListCommand
* @see ChatHandler::HandleCharacterDeletedRestoreCommand
*
* @param args the search string which either contains a player GUID or a part of the character-name
*/
bool ChatHandler::HandleCharacterDeletedOldCommand(char* args)
{
int32 keepDays = sWorld.getConfig(CONFIG_UINT32_CHARDELETE_KEEP_DAYS);
if (!ExtractOptInt32(&args, keepDays, sWorld.getConfig(CONFIG_UINT32_CHARDELETE_KEEP_DAYS)))
{
return false;
}
if (keepDays < 0)
{
return false;
}
Player::DeleteOldCharacters((uint32)keepDays);
return true;
}
/**********************************************************************
CommandTable : commandTable
/***********************************************************************/
void ChatHandler::HandleCharacterLevel(Player* player, ObjectGuid player_guid, uint32 oldlevel, uint32 newlevel)
{
if (player)
{
player->GiveLevel(newlevel);
player->InitTalentForLevel();
player->SetUInt32Value(PLAYER_XP, 0);
if (needReportToTarget(player))
{
if (oldlevel == newlevel)
{
ChatHandler(player).PSendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET, GetNameLink().c_str());
}
else if (oldlevel < newlevel)
{
ChatHandler(player).PSendSysMessage(LANG_YOURS_LEVEL_UP, GetNameLink().c_str(), newlevel);
}
else // if (oldlevel > newlevel)
{
ChatHandler(player).PSendSysMessage(LANG_YOURS_LEVEL_DOWN, GetNameLink().c_str(), newlevel);
}
}
}
else
{
// update level and XP at level, all other will be updated at loading
CharacterDatabase.PExecute("UPDATE `characters` SET `level` = '%u', `xp` = 0 WHERE `guid` = '%u'", newlevel, player_guid.GetCounter());
}
}
bool ChatHandler::HandleReviveCommand(char* args)
{
Player* target;
ObjectGuid target_guid;
if (!ExtractPlayerTarget(&args, &target, &target_guid))
{
return false;
}
if (target)
{
target->ResurrectPlayer(0.5f);
target->SpawnCorpseBones();
}
else // will resurrected at login without corpse
{
sObjectAccessor.ConvertCorpseForPlayer(target_guid);
}
return true;
}
bool ChatHandler::HandleDismountCommand(char* /*args*/)
{
Player* player = m_session->GetPlayer();
// If player is not mounted, so go out :)
if (!player->IsMounted())
{
SendSysMessage(LANG_CHAR_NON_MOUNTED);
SetSentErrorMessage(true);
return false;
}
if (player->IsTaxiFlying())
{
SendSysMessage(LANG_YOU_IN_FLIGHT);
SetSentErrorMessage(true);
return false;
}
player->Unmount();
player->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
return true;
}
bool ChatHandler::HandleLinkGraveCommand(char* args)
{
uint32 g_id;
if (!ExtractUInt32(&args, g_id))
{
return false;
}
char* teamStr = ExtractLiteralArg(&args);
Team g_team;
if (!teamStr)
{
g_team = TEAM_BOTH_ALLOWED;
}
else if (strncmp(teamStr, "horde", strlen(teamStr)) == 0)
{
g_team = HORDE;
}
else if (strncmp(teamStr, "alliance", strlen(teamStr)) == 0)
{
g_team = ALLIANCE;
}
else
{
return false;
}
WorldSafeLocsEntry const* graveyard = sWorldSafeLocsStore.LookupEntry(g_id);
if (!graveyard)
{
PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST, g_id);
SetSentErrorMessage(true);
return false;
}
Player* player = m_session->GetPlayer();
uint32 zoneId = player->GetZoneId();
AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(zoneId);
if (!areaEntry || areaEntry->zone != 0)
{
PSendSysMessage(LANG_COMMAND_GRAVEYARDWRONGZONE, g_id, zoneId);
SetSentErrorMessage(true);
return false;
}
if (sObjectMgr.AddGraveYardLink(g_id, zoneId, g_team))
{
PSendSysMessage(LANG_COMMAND_GRAVEYARDLINKED, g_id, zoneId);
}
else
{
PSendSysMessage(LANG_COMMAND_GRAVEYARDALRLINKED, g_id, zoneId);
}
return true;
}
// move item to other slot
bool ChatHandler::HandleItemMoveCommand(char* args)
{
if (!*args)
{
return false;
}
uint8 srcslot, dstslot;
char* pParam1 = strtok(args, " ");
if (!pParam1)
{
return false;
}
char* pParam2 = strtok(NULL, " ");
if (!pParam2)
{
return false;
}
srcslot = (uint8)atoi(pParam1);
dstslot = (uint8)atoi(pParam2);
if (srcslot == dstslot)
{
return true;
}
Player* player = m_session->GetPlayer();
if (!player->IsValidPos(INVENTORY_SLOT_BAG_0, srcslot, true))
{
return false;
}
// can be autostore pos
if (!player->IsValidPos(INVENTORY_SLOT_BAG_0, dstslot, false))
{
return false;
}
uint16 src = ((INVENTORY_SLOT_BAG_0 << 8) | srcslot);
uint16 dst = ((INVENTORY_SLOT_BAG_0 << 8) | dstslot);
player->SwapItem(src, dst);
return true;
}
bool ChatHandler::HandleCooldownCommand(char* args)
{
Player* target = getSelectedPlayer();
if (!target)
{
SendSysMessage(LANG_PLAYER_NOT_FOUND);
SetSentErrorMessage(true);
return false;
}
std::string tNameLink = GetNameLink(target);
if (!*args)
{
target->RemoveAllSpellCooldown();
PSendSysMessage(LANG_REMOVEALL_COOLDOWN, tNameLink.c_str());
}
else
{
// number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
uint32 spell_id = ExtractSpellIdFromLink(&args);
if (!spell_id)
{
return false;
}
if (!sSpellStore.LookupEntry(spell_id))
{
PSendSysMessage(LANG_UNKNOWN_SPELL, target == m_session->GetPlayer() ? GetMangosString(LANG_YOU) : tNameLink.c_str());
SetSentErrorMessage(true);
return false;
}
target->RemoveSpellCooldown(spell_id, true);
PSendSysMessage(LANG_REMOVE_COOLDOWN, spell_id, target == m_session->GetPlayer() ? GetMangosString(LANG_YOU) : tNameLink.c_str());
}
return true;
}
bool ChatHandler::HandleSaveCommand(char* /*args*/)
{
Player* player = m_session->GetPlayer();
// save GM account without delay and output message (testing, etc)
if (GetAccessLevel() > SEC_PLAYER)
{
player->SaveToDB();
SendSysMessage(LANG_PLAYER_SAVED);
return true;
}
// save or plan save after 20 sec (logout delay) if current next save time more this value and _not_ output any messages to prevent cheat planning
uint32 save_interval = sWorld.getConfig(CONFIG_UINT32_INTERVAL_SAVE);
if (save_interval == 0 || (save_interval > 20 * IN_MILLISECONDS && player->GetSaveTimer() <= save_interval - 20 * IN_MILLISECONDS))
{
player->SaveToDB();
}
return true;
}
// Save all players in the world
bool ChatHandler::HandleSaveAllCommand(char* /*args*/)
{
sObjectAccessor.SaveAllPlayers();
SendSysMessage(LANG_PLAYERS_SAVED);
return true;
}
bool ChatHandler::HandleStartCommand(char* /*args*/)
{
Player* chr = m_session->GetPlayer();
if (chr->IsTaxiFlying())
{
SendSysMessage(LANG_YOU_IN_FLIGHT);
SetSentErrorMessage(true);
return false;
}
if (chr->IsInCombat())
{
SendSysMessage(LANG_YOU_IN_COMBAT);
SetSentErrorMessage(true);
return false;
}
// cast spell Stuck
chr->CastSpell(chr, 7355, false);
return true;
}
// Enable On\OFF all taxi paths
bool ChatHandler::HandleTaxiCheatCommand(char* args)
{
bool value;
if (!ExtractOnOff(&args, value))
{
SendSysMessage(LANG_USE_BOL);
SetSentErrorMessage(true);
return false;
}
Player* chr = getSelectedPlayer();
if (!chr)
{
chr = m_session->GetPlayer();
}
// check online security
else if (HasLowerSecurity(chr))
{
return false;
}
if (value)
{
chr->SetTaxiCheater(true);
PSendSysMessage(LANG_YOU_GIVE_TAXIS, GetNameLink(chr).c_str());
if (needReportToTarget(chr))
{
ChatHandler(chr).PSendSysMessage(LANG_YOURS_TAXIS_ADDED, GetNameLink().c_str());
}
}
else
{
chr->SetTaxiCheater(false);
PSendSysMessage(LANG_YOU_REMOVE_TAXIS, GetNameLink(chr).c_str());
if (needReportToTarget(chr))
{
ChatHandler(chr).PSendSysMessage(LANG_YOURS_TAXIS_REMOVED, GetNameLink().c_str());
}
}
return true;
}
bool ChatHandler::HandleExploreCheatCommand(char* args)
{
if (!*args)
{
return false;
}
int flag = atoi(args);
Player* chr = getSelectedPlayer();
if (chr == NULL)
{
SendSysMessage(LANG_NO_CHAR_SELECTED);
SetSentErrorMessage(true);
return false;
}
if (flag != 0)
{
PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL, GetNameLink(chr).c_str());
if (needReportToTarget(chr))
{
ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_ALL, GetNameLink().c_str());
}
}
else
{
PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING, GetNameLink(chr).c_str());
if (needReportToTarget(chr))
{
ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_NOTHING, GetNameLink().c_str());
}
}
for (uint8 i = 0; i < PLAYER_EXPLORED_ZONES_SIZE; ++i)
{
if (flag != 0)
{
m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1 + i, 0xFFFFFFFF);
}
else
{
m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1 + i, 0);
}
}
return true;
}
bool ChatHandler::HandleLevelUpCommand(char* args)
{
int32 addlevel = 1;
char* nameStr = NULL;
if (*args)
{
nameStr = ExtractOptNotLastArg(&args);
// exception opt second arg: .levelup $name
if (!ExtractInt32(&args, addlevel))
{
if (!nameStr)
{
nameStr = ExtractArg(&args);
}
else
{
return false;
}
}
}
Player* target;
ObjectGuid target_guid;
std::string target_name;
if (!ExtractPlayerTarget(&nameStr, &target, &target_guid, &target_name))
{
return false;
}
int32 oldlevel = target ? target->getLevel() : Player::GetLevelFromDB(target_guid);
int32 newlevel = oldlevel + addlevel;
if (newlevel < 1)
{
newlevel = 1;
}
if (newlevel > STRONG_MAX_LEVEL) // hardcoded maximum level
{
newlevel = STRONG_MAX_LEVEL;
}
HandleCharacterLevel(target, target_guid, oldlevel, newlevel);
if (!m_session || m_session->GetPlayer() != target) // including chr==NULL
{
std::string nameLink = playerLink(target_name);
PSendSysMessage(LANG_YOU_CHANGE_LVL, nameLink.c_str(), newlevel);
}
return true;
}
bool ChatHandler::HandleShowAreaCommand(char* args)
{
if (!*args)
{
return false;
}
Player* chr = getSelectedPlayer();
if (chr == NULL)
{
SendSysMessage(LANG_NO_CHAR_SELECTED);
SetSentErrorMessage(true);
return false;
}
int area = GetAreaFlagByAreaID(atoi(args));
int offset = area / 32;
uint32 val = (uint32)(1 << (area % 32));
if (area < 0 || offset >= PLAYER_EXPLORED_ZONES_SIZE)
{
SendSysMessage(LANG_BAD_VALUE);
SetSentErrorMessage(true);
return false;
}
uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields | val));
SendSysMessage(LANG_EXPLORE_AREA);
return true;
}