2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
24 #include "ObjectMgr.h"
29 #include "MapManager.h"
30 #include "ObjectAccessor.h"
33 #include "InstanceSaveMgr.h"
36 #include "VMapFactory.h"
39 bool ChatHandler::HandleNpcSayCommand(const char* args
)
44 Creature
* pCreature
= getSelectedCreature();
47 SendSysMessage(LANG_SELECT_CREATURE
);
48 SetSentErrorMessage(true);
52 pCreature
->Say(args
, LANG_UNIVERSAL
, 0);
57 bool ChatHandler::HandleNpcYellCommand(const char* args
)
62 Creature
* pCreature
= getSelectedCreature();
65 SendSysMessage(LANG_SELECT_CREATURE
);
66 SetSentErrorMessage(true);
70 pCreature
->Yell(args
, LANG_UNIVERSAL
, 0);
75 //show text emote by creature in chat
76 bool ChatHandler::HandleNpcTextEmoteCommand(const char* args
)
81 Creature
* pCreature
= getSelectedCreature();
85 SendSysMessage(LANG_SELECT_CREATURE
);
86 SetSentErrorMessage(true);
90 pCreature
->TextEmote(args
, 0);
95 // make npc whisper to player
96 bool ChatHandler::HandleNpcWhisperCommand(const char* args
)
101 char* receiver_str
= strtok((char*)args
, " ");
102 char* text
= strtok(NULL
, "");
104 uint64 guid
= m_session
->GetPlayer()->GetSelection();
105 Creature
* pCreature
= ObjectAccessor::GetCreature(*m_session
->GetPlayer(), guid
);
107 if(!pCreature
|| !receiver_str
|| !text
)
112 uint64 receiver_guid
= atol(receiver_str
);
114 // check online security
115 if (HasLowerSecurity(objmgr
.GetPlayer(receiver_guid
), 0))
118 pCreature
->Whisper(text
,receiver_guid
);
124 bool ChatHandler::HandleAnnounceCommand(const char* args
)
129 sWorld
.SendWorldText(LANG_SYSTEMMESSAGE
,args
);
133 //notification player at the screen
134 bool ChatHandler::HandleNotifyCommand(const char* args
)
139 std::string str
= GetMangosString(LANG_GLOBAL_NOTIFY
);
142 WorldPacket
data(SMSG_NOTIFICATION
, (str
.size()+1));
144 sWorld
.SendGlobalMessage(&data
);
149 //Enable\Dissable GM Mode
150 bool ChatHandler::HandleGMmodeCommand(const char* args
)
154 if(m_session
->GetPlayer()->isGameMaster())
155 m_session
->SendNotification(LANG_GM_ON
);
157 m_session
->SendNotification(LANG_GM_OFF
);
161 std::string argstr
= (char*)args
;
165 m_session
->GetPlayer()->SetGameMaster(true);
166 m_session
->SendNotification(LANG_GM_ON
);
168 VMAP::IVMapManager
*vMapManager
= VMAP::VMapFactory::createOrGetVMapManager();
169 vMapManager
->processCommand("stoplog");
176 m_session
->GetPlayer()->SetGameMaster(false);
177 m_session
->SendNotification(LANG_GM_OFF
);
179 VMAP::IVMapManager
*vMapManager
= VMAP::VMapFactory::createOrGetVMapManager();
180 vMapManager
->processCommand("startlog");
185 SendSysMessage(LANG_USE_BOL
);
186 SetSentErrorMessage(true);
190 // Enables or disables hiding of the staff badge
191 bool ChatHandler::HandleGMChatCommand(const char* args
)
195 if(m_session
->GetPlayer()->isGMChat())
196 m_session
->SendNotification(LANG_GM_CHAT_ON
);
198 m_session
->SendNotification(LANG_GM_CHAT_OFF
);
202 std::string argstr
= (char*)args
;
206 m_session
->GetPlayer()->SetGMChat(true);
207 m_session
->SendNotification(LANG_GM_CHAT_ON
);
213 m_session
->GetPlayer()->SetGMChat(false);
214 m_session
->SendNotification(LANG_GM_CHAT_OFF
);
218 SendSysMessage(LANG_USE_BOL
);
219 SetSentErrorMessage(true);
223 //Enable\Dissable Invisible mode
224 bool ChatHandler::HandleVisibleCommand(const char* args
)
228 PSendSysMessage(LANG_YOU_ARE
, m_session
->GetPlayer()->isGMVisible() ? GetMangosString(LANG_VISIBLE
) : GetMangosString(LANG_INVISIBLE
));
232 std::string argstr
= (char*)args
;
236 m_session
->GetPlayer()->SetGMVisible(true);
237 m_session
->SendNotification(LANG_INVISIBLE_VISIBLE
);
243 m_session
->SendNotification(LANG_INVISIBLE_INVISIBLE
);
244 m_session
->GetPlayer()->SetGMVisible(false);
248 SendSysMessage(LANG_USE_BOL
);
249 SetSentErrorMessage(true);
255 bool ChatHandler::HandleGPSCommand(const char* args
)
257 WorldObject
*obj
= NULL
;
260 uint64 guid
= extractGuidFromLink((char*)args
);
262 obj
= (WorldObject
*)ObjectAccessor::GetObjectByTypeMask(*m_session
->GetPlayer(),guid
,TYPEMASK_UNIT
|TYPEMASK_GAMEOBJECT
);
266 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
267 SetSentErrorMessage(true);
273 obj
= getSelectedUnit();
277 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
278 SetSentErrorMessage(true);
282 CellPair cell_val
= MaNGOS::ComputeCellPair(obj
->GetPositionX(), obj
->GetPositionY());
285 uint32 zone_id
= obj
->GetZoneId();
286 uint32 area_id
= obj
->GetAreaId();
288 MapEntry
const* mapEntry
= sMapStore
.LookupEntry(obj
->GetMapId());
289 AreaTableEntry
const* zoneEntry
= GetAreaEntryByAreaID(zone_id
);
290 AreaTableEntry
const* areaEntry
= GetAreaEntryByAreaID(area_id
);
292 float zone_x
= obj
->GetPositionX();
293 float zone_y
= obj
->GetPositionY();
295 Map2ZoneCoordinates(zone_x
,zone_y
,zone_id
);
297 Map
const *map
= obj
->GetMap();
298 float ground_z
= map
->GetHeight(obj
->GetPositionX(), obj
->GetPositionY(), MAX_HEIGHT
);
299 float floor_z
= map
->GetHeight(obj
->GetPositionX(), obj
->GetPositionY(), obj
->GetPositionZ());
301 GridPair p
= MaNGOS::ComputeGridPair(obj
->GetPositionX(), obj
->GetPositionY());
306 uint32 have_map
= Map::ExistMap(obj
->GetMapId(),gx
,gy
) ? 1 : 0;
307 uint32 have_vmap
= Map::ExistVMap(obj
->GetMapId(),gx
,gy
) ? 1 : 0;
309 PSendSysMessage(LANG_MAP_POSITION
,
310 obj
->GetMapId(), (mapEntry
? mapEntry
->name
[m_session
->GetSessionDbcLocale()] : "<unknown>" ),
311 zone_id
, (zoneEntry
? zoneEntry
->area_name
[m_session
->GetSessionDbcLocale()] : "<unknown>" ),
312 area_id
, (areaEntry
? areaEntry
->area_name
[m_session
->GetSessionDbcLocale()] : "<unknown>" ),
314 obj
->GetPositionX(), obj
->GetPositionY(), obj
->GetPositionZ(), obj
->GetOrientation(),
315 cell
.GridX(), cell
.GridY(), cell
.CellX(), cell
.CellY(), obj
->GetInstanceId(),
316 zone_x
, zone_y
, ground_z
, floor_z
, have_map
, have_vmap
);
318 sLog
.outDebug("Player %s GPS call for %s '%s' (%s: %u):",
319 m_session
? GetNameLink().c_str() : GetMangosString(LANG_CONSOLE_COMMAND
),
320 (obj
->GetTypeId() == TYPEID_PLAYER
? "player" : "creature"), obj
->GetName(),
321 (obj
->GetTypeId() == TYPEID_PLAYER
? "GUID" : "Entry"), (obj
->GetTypeId() == TYPEID_PLAYER
? obj
->GetGUIDLow(): obj
->GetEntry()) );
323 sLog
.outDebug(GetMangosString(LANG_MAP_POSITION
),
324 obj
->GetMapId(), (mapEntry
? mapEntry
->name
[sWorld
.GetDefaultDbcLocale()] : "<unknown>" ),
325 zone_id
, (zoneEntry
? zoneEntry
->area_name
[sWorld
.GetDefaultDbcLocale()] : "<unknown>" ),
326 area_id
, (areaEntry
? areaEntry
->area_name
[sWorld
.GetDefaultDbcLocale()] : "<unknown>" ),
328 obj
->GetPositionX(), obj
->GetPositionY(), obj
->GetPositionZ(), obj
->GetOrientation(),
329 cell
.GridX(), cell
.GridY(), cell
.CellX(), cell
.CellY(), obj
->GetInstanceId(),
330 zone_x
, zone_y
, ground_z
, floor_z
, have_map
, have_vmap
);
336 bool ChatHandler::HandleNamegoCommand(const char* args
)
341 std::string name
= extractPlayerNameFromLink((char*)args
);
344 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
345 SetSentErrorMessage(true);
349 Player
*chr
= objmgr
.GetPlayer(name
.c_str());
352 std::string nameLink
= playerLink(name
);
353 // check online security
354 if (HasLowerSecurity(chr
, 0))
357 if(chr
->IsBeingTeleported()==true)
359 PSendSysMessage(LANG_IS_TELEPORTED
, nameLink
.c_str());
360 SetSentErrorMessage(true);
364 Map
* pMap
= m_session
->GetPlayer()->GetMap();
366 if(pMap
->IsBattleGroundOrArena())
368 // only allow if gm mode is on
369 if (!chr
->isGameMaster())
371 PSendSysMessage(LANG_CANNOT_GO_TO_BG_GM
,chr
->GetName());
372 SetSentErrorMessage(true);
375 // if both players are in different bgs
376 else if (chr
->GetBattleGroundId() && m_session
->GetPlayer()->GetBattleGroundId() != chr
->GetBattleGroundId())
378 PSendSysMessage(LANG_CANNOT_GO_TO_BG_FROM_BG
,chr
->GetName());
379 SetSentErrorMessage(true);
382 // all's well, set bg id
383 // when porting out from the bg, it will be reset to 0
384 chr
->SetBattleGroundId(m_session
->GetPlayer()->GetBattleGroundId());
386 else if(pMap
->IsDungeon())
388 Map
* cMap
= chr
->GetMap();
389 if( cMap
->Instanceable() && cMap
->GetInstanceId() != pMap
->GetInstanceId() )
391 // cannot summon from instance to instance
392 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST
,nameLink
.c_str());
393 SetSentErrorMessage(true);
397 // we are in instance, and can summon only player in our group with us as lead
398 if ( !m_session
->GetPlayer()->GetGroup() || !chr
->GetGroup() ||
399 (chr
->GetGroup()->GetLeaderGUID() != m_session
->GetPlayer()->GetGUID()) ||
400 (m_session
->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session
->GetPlayer()->GetGUID()) )
401 // the last check is a bit excessive, but let it be, just in case
403 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST
,nameLink
.c_str());
404 SetSentErrorMessage(true);
409 PSendSysMessage(LANG_SUMMONING
, nameLink
.c_str(),"");
410 if (needReportToTarget(chr
))
411 ChatHandler(chr
).PSendSysMessage(LANG_SUMMONED_BY
, nameLink
.c_str());
413 // stop flight if need
414 if(chr
->isInFlight())
416 chr
->GetMotionMaster()->MovementExpired();
417 chr
->m_taxi
.ClearTaxiDestinations();
419 // save only in non-flight case
421 chr
->SaveRecallPosition();
425 m_session
->GetPlayer()->GetClosePoint(x
,y
,z
,chr
->GetObjectSize());
426 chr
->TeleportTo(m_session
->GetPlayer()->GetMapId(),x
,y
,z
,chr
->GetOrientation());
428 else if (uint64 guid
= objmgr
.GetPlayerGUIDByName(name
))
430 // check offline security
431 if (HasLowerSecurity(NULL
, guid
))
434 std::string nameLink
= playerLink(name
);
436 PSendSysMessage(LANG_SUMMONING
, nameLink
.c_str(),GetMangosString(LANG_OFFLINE
));
438 // in point where GM stay
439 Player::SavePositionInDB(m_session
->GetPlayer()->GetMapId(),
440 m_session
->GetPlayer()->GetPositionX(),
441 m_session
->GetPlayer()->GetPositionY(),
442 m_session
->GetPlayer()->GetPositionZ(),
443 m_session
->GetPlayer()->GetOrientation(),
444 m_session
->GetPlayer()->GetZoneId(),
449 PSendSysMessage(LANG_NO_PLAYER
, args
);
450 SetSentErrorMessage(true);
457 bool ChatHandler::HandleGonameCommand(const char* args
)
462 Player
* _player
= m_session
->GetPlayer();
464 std::string name
= extractPlayerNameFromLink((char*)args
);
467 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
468 SetSentErrorMessage(true);
472 Player
*chr
= objmgr
.GetPlayer(name
.c_str());
475 // check online security
476 if (HasLowerSecurity(chr
, 0))
479 std::string chrNameLink
= playerLink(name
);
481 Map
* cMap
= chr
->GetMap();
482 if(cMap
->IsBattleGroundOrArena())
484 // only allow if gm mode is on
485 if (!_player
->isGameMaster())
487 PSendSysMessage(LANG_CANNOT_GO_TO_BG_GM
,chrNameLink
.c_str());
488 SetSentErrorMessage(true);
491 // if both players are in different bgs
492 else if (_player
->GetBattleGroundId() && _player
->GetBattleGroundId() != chr
->GetBattleGroundId())
494 PSendSysMessage(LANG_CANNOT_GO_TO_BG_FROM_BG
,chrNameLink
.c_str());
495 SetSentErrorMessage(true);
498 // all's well, set bg id
499 // when porting out from the bg, it will be reset to 0
500 _player
->SetBattleGroundId(chr
->GetBattleGroundId());
502 else if(cMap
->IsDungeon() && cMap
->Instanceable())
504 // we have to go to instance, and can go to player only if:
505 // 1) we are in his group (either as leader or as member)
506 // 2) we are not bound to any group and have GM mode on
507 if (_player
->GetGroup())
509 // we are in group, we can go only if we are in the player group
510 if (_player
->GetGroup() != chr
->GetGroup())
512 PSendSysMessage(LANG_CANNOT_GO_TO_INST_PARTY
,chrNameLink
.c_str());
513 SetSentErrorMessage(true);
519 // we are not in group, let's verify our GM mode
520 if (!_player
->isGameMaster())
522 PSendSysMessage(LANG_CANNOT_GO_TO_INST_GM
,chrNameLink
.c_str());
523 SetSentErrorMessage(true);
528 // if the player or the player's group is bound to another instance
529 // the player will not be bound to another one
530 InstancePlayerBind
*pBind
= _player
->GetBoundInstance(chr
->GetMapId(), chr
->GetDifficulty());
533 Group
*group
= _player
->GetGroup();
534 InstanceGroupBind
*gBind
= group
? group
->GetBoundInstance(chr
->GetMapId(), chr
->GetDifficulty()) : NULL
;
537 // if no bind exists, create a solo bind
538 InstanceSave
*save
= sInstanceSaveManager
.GetInstanceSave(chr
->GetInstanceId());
539 if(save
) _player
->BindToInstance(save
, !save
->CanReset());
543 _player
->SetDifficulty(chr
->GetDifficulty());
546 PSendSysMessage(LANG_APPEARING_AT
, chrNameLink
.c_str());
547 if (_player
->IsVisibleGloballyFor(chr
))
548 ChatHandler(chr
).PSendSysMessage(LANG_APPEARING_TO
, GetNameLink().c_str());
550 // stop flight if need
551 if(_player
->isInFlight())
553 _player
->GetMotionMaster()->MovementExpired();
554 _player
->m_taxi
.ClearTaxiDestinations();
556 // save only in non-flight case
558 _player
->SaveRecallPosition();
560 // to point to see at target with same orientation
562 chr
->GetContactPoint(m_session
->GetPlayer(),x
,y
,z
);
564 _player
->TeleportTo(chr
->GetMapId(), x
, y
, z
, _player
->GetAngle( chr
), TELE_TO_GM_MODE
);
569 if (uint64 guid
= objmgr
.GetPlayerGUIDByName(name
))
571 // check offline security
572 if (HasLowerSecurity(NULL
, guid
))
575 std::string nameLink
= playerLink(name
);
577 PSendSysMessage(LANG_APPEARING_AT
, nameLink
.c_str());
579 // to point where player stay (if loaded)
583 if(Player::LoadPositionFromDB(map
,x
,y
,z
,o
,in_flight
,guid
))
585 // stop flight if need
586 if(_player
->isInFlight())
588 _player
->GetMotionMaster()->MovementExpired();
589 _player
->m_taxi
.ClearTaxiDestinations();
591 // save only in non-flight case
593 _player
->SaveRecallPosition();
595 _player
->TeleportTo(map
, x
, y
, z
,_player
->GetOrientation());
600 PSendSysMessage(LANG_NO_PLAYER
, args
);
602 SetSentErrorMessage(true);
606 // Teleport player to last position
607 bool ChatHandler::HandleRecallCommand(const char* args
)
613 chr
= getSelectedPlayer();
615 chr
= m_session
->GetPlayer();
617 // check online security
618 else if (HasLowerSecurity(chr
, 0))
623 std::string name
= extractPlayerNameFromLink((char*)args
);
626 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
627 SetSentErrorMessage(true);
631 chr
= objmgr
.GetPlayer(name
.c_str());
635 PSendSysMessage(LANG_NO_PLAYER
, args
);
636 SetSentErrorMessage(true);
640 // check online security
641 if (HasLowerSecurity(chr
, 0))
645 if(chr
->IsBeingTeleported())
647 PSendSysMessage(LANG_IS_TELEPORTED
, GetNameLink(chr
).c_str());
648 SetSentErrorMessage(true);
652 // stop flight if need
653 if(chr
->isInFlight())
655 chr
->GetMotionMaster()->MovementExpired();
656 chr
->m_taxi
.ClearTaxiDestinations();
659 chr
->TeleportTo(chr
->m_recallMap
, chr
->m_recallX
, chr
->m_recallY
, chr
->m_recallZ
, chr
->m_recallO
);
663 //Edit Player KnownTitles
664 bool ChatHandler::HandleModifyKnownTitlesCommand(const char* args
)
671 sscanf((char*)args
, I64FMTD
, &titles
);
673 Player
*chr
= getSelectedPlayer();
676 SendSysMessage(LANG_NO_CHAR_SELECTED
);
677 SetSentErrorMessage(true);
681 // check online security
682 if (HasLowerSecurity(chr
, 0))
685 uint64 titles2
= titles
;
687 for(int i
=1; i
< sCharTitlesStore
.GetNumRows(); ++i
)
688 if(CharTitlesEntry
const* tEntry
= sCharTitlesStore
.LookupEntry(i
))
689 titles2
&= ~(uint64(1) << tEntry
->bit_index
);
691 titles
&= ~titles2
; // remove not existed titles
693 chr
->SetUInt64Value(PLAYER__FIELD_KNOWN_TITLES
, titles
);
694 SendSysMessage(LANG_DONE
);
700 bool ChatHandler::HandleModifyHPCommand(const char* args
)
705 // char* pHp = strtok((char*)args, " ");
709 // char* pHpMax = strtok(NULL, " ");
713 // int32 hpm = atoi(pHpMax);
714 // int32 hp = atoi(pHp);
716 int32 hp
= atoi((char*)args
);
717 int32 hpm
= atoi((char*)args
);
719 if (hp
<= 0 || hpm
<= 0 || hpm
< hp
)
721 SendSysMessage(LANG_BAD_VALUE
);
722 SetSentErrorMessage(true);
726 Player
*chr
= getSelectedPlayer();
729 SendSysMessage(LANG_NO_CHAR_SELECTED
);
730 SetSentErrorMessage(true);
734 // check online security
735 if (HasLowerSecurity(chr
, 0))
738 PSendSysMessage(LANG_YOU_CHANGE_HP
, GetNameLink(chr
).c_str(), hp
, hpm
);
739 if (needReportToTarget(chr
))
740 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_HP_CHANGED
, GetNameLink().c_str(), hp
, hpm
);
742 chr
->SetMaxHealth( hpm
);
743 chr
->SetHealth( hp
);
749 bool ChatHandler::HandleModifyManaCommand(const char* args
)
754 // char* pmana = strtok((char*)args, " ");
758 // char* pmanaMax = strtok(NULL, " ");
762 // int32 manam = atoi(pmanaMax);
763 // int32 mana = atoi(pmana);
764 int32 mana
= atoi((char*)args
);
765 int32 manam
= atoi((char*)args
);
767 if (mana
<= 0 || manam
<= 0 || manam
< mana
)
769 SendSysMessage(LANG_BAD_VALUE
);
770 SetSentErrorMessage(true);
774 Player
*chr
= getSelectedPlayer();
777 SendSysMessage(LANG_NO_CHAR_SELECTED
);
778 SetSentErrorMessage(true);
782 // check online security
783 if (HasLowerSecurity(chr
, 0))
786 PSendSysMessage(LANG_YOU_CHANGE_MANA
, GetNameLink(chr
).c_str(), mana
, manam
);
787 if (needReportToTarget(chr
))
788 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_MANA_CHANGED
, GetNameLink().c_str(), mana
, manam
);
790 chr
->SetMaxPower(POWER_MANA
,manam
);
791 chr
->SetPower(POWER_MANA
, mana
);
797 bool ChatHandler::HandleModifyEnergyCommand(const char* args
)
802 // char* pmana = strtok((char*)args, " ");
806 // char* pmanaMax = strtok(NULL, " ");
810 // int32 manam = atoi(pmanaMax);
811 // int32 mana = atoi(pmana);
813 int32 energy
= atoi((char*)args
)*10;
814 int32 energym
= atoi((char*)args
)*10;
816 if (energy
<= 0 || energym
<= 0 || energym
< energy
)
818 SendSysMessage(LANG_BAD_VALUE
);
819 SetSentErrorMessage(true);
823 Player
*chr
= getSelectedPlayer();
826 SendSysMessage(LANG_NO_CHAR_SELECTED
);
827 SetSentErrorMessage(true);
831 // check online security
832 if (HasLowerSecurity(chr
, 0))
835 PSendSysMessage(LANG_YOU_CHANGE_ENERGY
, GetNameLink(chr
).c_str(), energy
/10, energym
/10);
836 if (needReportToTarget(chr
))
837 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_ENERGY_CHANGED
, GetNameLink().c_str(), energy
/10, energym
/10);
839 chr
->SetMaxPower(POWER_ENERGY
,energym
);
840 chr
->SetPower(POWER_ENERGY
, energy
);
842 sLog
.outDetail(GetMangosString(LANG_CURRENT_ENERGY
),chr
->GetMaxPower(POWER_ENERGY
));
848 bool ChatHandler::HandleModifyRageCommand(const char* args
)
853 // char* pmana = strtok((char*)args, " ");
857 // char* pmanaMax = strtok(NULL, " ");
861 // int32 manam = atoi(pmanaMax);
862 // int32 mana = atoi(pmana);
864 int32 rage
= atoi((char*)args
)*10;
865 int32 ragem
= atoi((char*)args
)*10;
867 if (rage
<= 0 || ragem
<= 0 || ragem
< rage
)
869 SendSysMessage(LANG_BAD_VALUE
);
870 SetSentErrorMessage(true);
874 Player
*chr
= getSelectedPlayer();
877 SendSysMessage(LANG_NO_CHAR_SELECTED
);
878 SetSentErrorMessage(true);
882 // check online security
883 if (HasLowerSecurity(chr
, 0))
886 PSendSysMessage(LANG_YOU_CHANGE_RAGE
, GetNameLink(chr
).c_str(), rage
/10, ragem
/10);
887 if (needReportToTarget(chr
))
888 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_RAGE_CHANGED
, GetNameLink().c_str(), rage
/10, ragem
/10);
890 chr
->SetMaxPower(POWER_RAGE
,ragem
);
891 chr
->SetPower(POWER_RAGE
, rage
);
896 // Edit Player Runic Power
897 bool ChatHandler::HandleModifyRunicPowerCommand(const char* args
)
902 int32 rune
= atoi((char*)args
)*10;
903 int32 runem
= atoi((char*)args
)*10;
905 if (rune
<= 0 || runem
<= 0 || runem
< rune
)
907 SendSysMessage(LANG_BAD_VALUE
);
908 SetSentErrorMessage(true);
912 Player
*chr
= getSelectedPlayer();
915 SendSysMessage(LANG_NO_CHAR_SELECTED
);
916 SetSentErrorMessage(true);
920 PSendSysMessage(LANG_YOU_CHANGE_RUNIC_POWER
, GetNameLink(chr
).c_str(), rune
/10, runem
/10);
921 if (needReportToTarget(chr
))
922 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_RUNIC_POWER_CHANGED
, GetNameLink().c_str(), rune
/10, runem
/10);
924 chr
->SetMaxPower(POWER_RUNIC_POWER
,runem
);
925 chr
->SetPower(POWER_RUNIC_POWER
, rune
);
930 //Edit Player Faction
931 bool ChatHandler::HandleModifyFactionCommand(const char* args
)
936 char* pfactionid
= extractKeyFromLink((char*)args
,"Hfaction");
938 Creature
* chr
= getSelectedCreature();
941 SendSysMessage(LANG_SELECT_CREATURE
);
942 SetSentErrorMessage(true);
950 uint32 factionid
= chr
->getFaction();
951 uint32 flag
= chr
->GetUInt32Value(UNIT_FIELD_FLAGS
);
952 uint32 npcflag
= chr
->GetUInt32Value(UNIT_NPC_FLAGS
);
953 uint32 dyflag
= chr
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
);
954 PSendSysMessage(LANG_CURRENT_FACTION
,chr
->GetGUIDLow(),factionid
,flag
,npcflag
,dyflag
);
961 SendSysMessage(LANG_NO_CHAR_SELECTED
);
962 SetSentErrorMessage(true);
966 uint32 factionid
= atoi(pfactionid
);
969 char *pflag
= strtok(NULL
, " ");
971 flag
= chr
->GetUInt32Value(UNIT_FIELD_FLAGS
);
975 char* pnpcflag
= strtok(NULL
, " ");
979 npcflag
= chr
->GetUInt32Value(UNIT_NPC_FLAGS
);
981 npcflag
= atoi(pnpcflag
);
983 char* pdyflag
= strtok(NULL
, " ");
987 dyflag
= chr
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
);
989 dyflag
= atoi(pdyflag
);
991 if(!sFactionTemplateStore
.LookupEntry(factionid
))
993 PSendSysMessage(LANG_WRONG_FACTION
, factionid
);
994 SetSentErrorMessage(true);
998 PSendSysMessage(LANG_YOU_CHANGE_FACTION
, chr
->GetGUIDLow(),factionid
,flag
,npcflag
,dyflag
);
1000 chr
->setFaction(factionid
);
1001 chr
->SetUInt32Value(UNIT_FIELD_FLAGS
,flag
);
1002 chr
->SetUInt32Value(UNIT_NPC_FLAGS
,npcflag
);
1003 chr
->SetUInt32Value(UNIT_DYNAMIC_FLAGS
,dyflag
);
1009 bool ChatHandler::HandleModifySpellCommand(const char* args
)
1011 if(!*args
) return false;
1012 char* pspellflatid
= strtok((char*)args
, " ");
1016 char* pop
= strtok(NULL
, " ");
1020 char* pval
= strtok(NULL
, " ");
1026 char* pmark
= strtok(NULL
, " ");
1028 uint8 spellflatid
= atoi(pspellflatid
);
1029 uint8 op
= atoi(pop
);
1030 uint16 val
= atoi(pval
);
1036 Player
*chr
= getSelectedPlayer();
1039 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1040 SetSentErrorMessage(true);
1044 // check online security
1045 if (HasLowerSecurity(chr
, 0))
1048 PSendSysMessage(LANG_YOU_CHANGE_SPELLFLATID
, spellflatid
, val
, mark
, GetNameLink(chr
).c_str());
1049 if (needReportToTarget(chr
))
1050 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_SPELLFLATID_CHANGED
, GetNameLink().c_str(), spellflatid
, val
, mark
);
1052 WorldPacket
data(SMSG_SET_FLAT_SPELL_MODIFIER
, (1+1+2+2));
1053 data
<< uint8(spellflatid
);
1055 data
<< uint16(val
);
1056 data
<< uint16(mark
);
1057 chr
->GetSession()->SendPacket(&data
);
1063 bool ChatHandler::HandleModifyTalentCommand (const char* args
)
1068 int tp
= atoi((char*)args
);
1071 Player
* player
= getSelectedPlayer();
1074 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1075 SetSentErrorMessage(true);
1079 // check online security
1080 if (HasLowerSecurity(player
, 0))
1083 player
->SetFreeTalentPoints(tp
);
1089 //Enable On\OFF all taxi paths
1090 bool ChatHandler::HandleTaxiCheatCommand(const char* args
)
1094 SendSysMessage(LANG_USE_BOL
);
1095 SetSentErrorMessage(true);
1099 std::string argstr
= (char*)args
;
1101 Player
*chr
= getSelectedPlayer();
1104 chr
=m_session
->GetPlayer();
1107 // check online security
1108 else if (HasLowerSecurity(chr
, 0))
1113 chr
->SetTaxiCheater(true);
1114 PSendSysMessage(LANG_YOU_GIVE_TAXIS
, GetNameLink(chr
).c_str());
1115 if (needReportToTarget(chr
))
1116 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_TAXIS_ADDED
, GetNameLink().c_str());
1120 if (argstr
== "off")
1122 chr
->SetTaxiCheater(false);
1123 PSendSysMessage(LANG_YOU_REMOVE_TAXIS
, GetNameLink(chr
).c_str());
1124 if (needReportToTarget(chr
))
1125 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_TAXIS_REMOVED
, GetNameLink().c_str());
1130 SendSysMessage(LANG_USE_BOL
);
1131 SetSentErrorMessage(true);
1135 //Edit Player Aspeed
1136 bool ChatHandler::HandleModifyASpeedCommand(const char* args
)
1141 float ASpeed
= (float)atof((char*)args
);
1143 if (ASpeed
> 10 || ASpeed
< 0.1)
1145 SendSysMessage(LANG_BAD_VALUE
);
1146 SetSentErrorMessage(true);
1150 Player
*chr
= getSelectedPlayer();
1153 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1154 SetSentErrorMessage(true);
1158 // check online security
1159 if (HasLowerSecurity(chr
, 0))
1162 std::string chrNameLink
= GetNameLink(chr
);
1164 if(chr
->isInFlight())
1166 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chrNameLink
.c_str());
1167 SetSentErrorMessage(true);
1171 PSendSysMessage(LANG_YOU_CHANGE_ASPEED
, ASpeed
, chrNameLink
.c_str());
1172 if (needReportToTarget(chr
))
1173 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_ASPEED_CHANGED
, GetNameLink().c_str(), ASpeed
);
1175 chr
->SetSpeed(MOVE_WALK
, ASpeed
,true);
1176 chr
->SetSpeed(MOVE_RUN
, ASpeed
,true);
1177 chr
->SetSpeed(MOVE_SWIM
, ASpeed
,true);
1178 //chr->SetSpeed(MOVE_TURN, ASpeed,true);
1179 chr
->SetSpeed(MOVE_FLIGHT
, ASpeed
,true);
1184 bool ChatHandler::HandleModifySpeedCommand(const char* args
)
1189 float Speed
= (float)atof((char*)args
);
1191 if (Speed
> 10 || Speed
< 0.1)
1193 SendSysMessage(LANG_BAD_VALUE
);
1194 SetSentErrorMessage(true);
1198 Player
*chr
= getSelectedPlayer();
1201 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1202 SetSentErrorMessage(true);
1206 // check online security
1207 if (HasLowerSecurity(chr
, 0))
1210 std::string chrNameLink
= GetNameLink(chr
);
1212 if(chr
->isInFlight())
1214 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chrNameLink
.c_str());
1215 SetSentErrorMessage(true);
1219 PSendSysMessage(LANG_YOU_CHANGE_SPEED
, Speed
, chrNameLink
.c_str());
1220 if (needReportToTarget(chr
))
1221 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_SPEED_CHANGED
, GetNameLink().c_str(), Speed
);
1223 chr
->SetSpeed(MOVE_RUN
,Speed
,true);
1228 //Edit Player Swim Speed
1229 bool ChatHandler::HandleModifySwimCommand(const char* args
)
1234 float Swim
= (float)atof((char*)args
);
1236 if (Swim
> 10.0f
|| Swim
< 0.01f
)
1238 SendSysMessage(LANG_BAD_VALUE
);
1239 SetSentErrorMessage(true);
1243 Player
*chr
= getSelectedPlayer();
1246 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1247 SetSentErrorMessage(true);
1251 // check online security
1252 if (HasLowerSecurity(chr
, 0))
1255 std::string chrNameLink
= GetNameLink(chr
);
1257 if(chr
->isInFlight())
1259 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chrNameLink
.c_str());
1260 SetSentErrorMessage(true);
1264 PSendSysMessage(LANG_YOU_CHANGE_SWIM_SPEED
, Swim
, chrNameLink
.c_str());
1265 if (needReportToTarget(chr
))
1266 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_SWIM_SPEED_CHANGED
, GetNameLink().c_str(), Swim
);
1268 chr
->SetSpeed(MOVE_SWIM
,Swim
,true);
1273 //Edit Player Walk Speed
1274 bool ChatHandler::HandleModifyBWalkCommand(const char* args
)
1279 float BSpeed
= (float)atof((char*)args
);
1281 if (BSpeed
> 10.0f
|| BSpeed
< 0.1f
)
1283 SendSysMessage(LANG_BAD_VALUE
);
1284 SetSentErrorMessage(true);
1288 Player
*chr
= getSelectedPlayer();
1291 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1292 SetSentErrorMessage(true);
1296 // check online security
1297 if (HasLowerSecurity(chr
, 0))
1300 std::string chrNameLink
= GetNameLink(chr
);
1302 if(chr
->isInFlight())
1304 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chrNameLink
.c_str());
1305 SetSentErrorMessage(true);
1309 PSendSysMessage(LANG_YOU_CHANGE_BACK_SPEED
, BSpeed
, chrNameLink
.c_str());
1310 if (needReportToTarget(chr
))
1311 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_BACK_SPEED_CHANGED
, GetNameLink().c_str(), BSpeed
);
1313 chr
->SetSpeed(MOVE_RUN_BACK
,BSpeed
,true);
1319 bool ChatHandler::HandleModifyFlyCommand(const char* args
)
1324 float FSpeed
= (float)atof((char*)args
);
1326 if (FSpeed
> 10.0f
|| FSpeed
< 0.1f
)
1328 SendSysMessage(LANG_BAD_VALUE
);
1329 SetSentErrorMessage(true);
1333 Player
*chr
= getSelectedPlayer();
1336 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1337 SetSentErrorMessage(true);
1341 // check online security
1342 if (HasLowerSecurity(chr
, 0))
1345 PSendSysMessage(LANG_YOU_CHANGE_FLY_SPEED
, FSpeed
, GetNameLink(chr
).c_str());
1346 if (needReportToTarget(chr
))
1347 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_FLY_SPEED_CHANGED
, GetNameLink().c_str(), FSpeed
);
1349 chr
->SetSpeed(MOVE_FLIGHT
,FSpeed
,true);
1355 bool ChatHandler::HandleModifyScaleCommand(const char* args
)
1360 float Scale
= (float)atof((char*)args
);
1361 if (Scale
> 3.0f
|| Scale
<= 0.0f
)
1363 SendSysMessage(LANG_BAD_VALUE
);
1364 SetSentErrorMessage(true);
1368 Player
*chr
= getSelectedPlayer();
1371 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1372 SetSentErrorMessage(true);
1376 // check online security
1377 if (HasLowerSecurity(chr
, 0))
1380 PSendSysMessage(LANG_YOU_CHANGE_SIZE
, Scale
, GetNameLink(chr
).c_str());
1381 if (needReportToTarget(chr
))
1382 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_SIZE_CHANGED
, GetNameLink().c_str(), Scale
);
1384 chr
->SetFloatValue(OBJECT_FIELD_SCALE_X
, Scale
);
1389 //Enable Player mount
1390 bool ChatHandler::HandleModifyMountCommand(const char* args
)
1396 float speed
= (float)15;
1399 num
= atoi((char*)args
);
1610 SendSysMessage(LANG_NO_MOUNT
);
1611 SetSentErrorMessage(true);
1615 Player
*chr
= getSelectedPlayer();
1618 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1619 SetSentErrorMessage(true);
1623 // check online security
1624 if (HasLowerSecurity(chr
, 0))
1627 PSendSysMessage(LANG_YOU_GIVE_MOUNT
, GetNameLink(chr
).c_str());
1628 if (needReportToTarget(chr
))
1629 ChatHandler(chr
).PSendSysMessage(LANG_MOUNT_GIVED
, GetNameLink().c_str());
1631 chr
->SetUInt32Value( UNIT_FIELD_FLAGS
, 0x001000 );
1634 WorldPacket
data( SMSG_FORCE_RUN_SPEED_CHANGE
, (8+4+1+4) );
1635 data
.append(chr
->GetPackGUID());
1637 data
<< (uint8
)0; //new 2.1.0
1638 data
<< float(speed
);
1639 chr
->SendMessageToSet( &data
, true );
1641 data
.Initialize( SMSG_FORCE_SWIM_SPEED_CHANGE
, (8+4+4) );
1642 data
.append(chr
->GetPackGUID());
1644 data
<< float(speed
);
1645 chr
->SendMessageToSet( &data
, true );
1651 bool ChatHandler::HandleModifyMoneyCommand(const char* args
)
1656 Player
*chr
= getSelectedPlayer();
1659 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1660 SetSentErrorMessage(true);
1664 // check online security
1665 if (HasLowerSecurity(chr
, 0))
1668 int32 addmoney
= atoi((char*)args
);
1670 uint32 moneyuser
= chr
->GetMoney();
1674 int32 newmoney
= moneyuser
+ addmoney
;
1676 sLog
.outDetail(GetMangosString(LANG_CURRENT_MONEY
), moneyuser
, addmoney
, newmoney
);
1679 PSendSysMessage(LANG_YOU_TAKE_ALL_MONEY
, GetNameLink(chr
).c_str());
1680 if (needReportToTarget(chr
))
1681 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_ALL_MONEY_GONE
, GetNameLink().c_str());
1687 PSendSysMessage(LANG_YOU_TAKE_MONEY
, abs(addmoney
), GetNameLink(chr
).c_str());
1688 if (needReportToTarget(chr
))
1689 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_MONEY_TAKEN
, GetNameLink().c_str(), abs(addmoney
));
1690 chr
->SetMoney( newmoney
);
1695 PSendSysMessage(LANG_YOU_GIVE_MONEY
, addmoney
, GetNameLink(chr
).c_str());
1696 if (needReportToTarget(chr
))
1697 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_MONEY_GIVEN
, GetNameLink().c_str(), addmoney
);
1698 chr
->ModifyMoney( addmoney
);
1701 sLog
.outDetail(GetMangosString(LANG_NEW_MONEY
), moneyuser
, addmoney
, chr
->GetMoney() );
1707 bool ChatHandler::HandleModifyBitCommand(const char* args
)
1712 Unit
*unit
= getSelectedUnit();
1715 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1716 SetSentErrorMessage(true);
1720 // check online security
1721 if (unit
->GetTypeId() == TYPEID_PLAYER
&& HasLowerSecurity((Player
*)unit
, 0))
1724 char* pField
= strtok((char*)args
, " ");
1728 char* pBit
= strtok(NULL
, " ");
1732 uint16 field
= atoi(pField
);
1733 uint32 bit
= atoi(pBit
);
1735 if (field
< OBJECT_END
|| field
>= unit
->GetValuesCount())
1737 SendSysMessage(LANG_BAD_VALUE
);
1738 SetSentErrorMessage(true);
1741 if (bit
< 1 || bit
> 32)
1743 SendSysMessage(LANG_BAD_VALUE
);
1744 SetSentErrorMessage(true);
1748 if ( unit
->HasFlag( field
, (1<<(bit
-1)) ) )
1750 unit
->RemoveFlag( field
, (1<<(bit
-1)) );
1751 PSendSysMessage(LANG_REMOVE_BIT
, bit
, field
);
1755 unit
->SetFlag( field
, (1<<(bit
-1)) );
1756 PSendSysMessage(LANG_SET_BIT
, bit
, field
);
1761 bool ChatHandler::HandleModifyHonorCommand (const char* args
)
1766 Player
*target
= getSelectedPlayer();
1769 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1770 SetSentErrorMessage(true);
1774 // check online security
1775 if (HasLowerSecurity(target
, 0))
1778 int32 amount
= (uint32
)atoi(args
);
1780 target
->ModifyHonorPoints(amount
);
1782 PSendSysMessage(LANG_COMMAND_MODIFY_HONOR
, GetNameLink(target
).c_str(), target
->GetHonorPoints());
1787 bool ChatHandler::HandleTeleCommand(const char * args
)
1792 Player
* _player
= m_session
->GetPlayer();
1794 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
1795 GameTele
const* tele
= extractGameTeleFromLink((char*)args
);
1799 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
1800 SetSentErrorMessage(true);
1804 // stop flight if need
1805 if(_player
->isInFlight())
1807 _player
->GetMotionMaster()->MovementExpired();
1808 _player
->m_taxi
.ClearTaxiDestinations();
1810 // save only in non-flight case
1812 _player
->SaveRecallPosition();
1814 _player
->TeleportTo(tele
->mapId
, tele
->position_x
, tele
->position_y
, tele
->position_z
, tele
->orientation
);
1818 bool ChatHandler::HandleLookupAreaCommand(const char* args
)
1823 std::string namepart
= args
;
1824 std::wstring wnamepart
;
1826 if (!Utf8toWStr (namepart
,wnamepart
))
1829 uint32 counter
= 0; // Counter for figure out that we found smth.
1831 // converting string that we try to find to lower case
1832 wstrToLower (wnamepart
);
1834 // Search in AreaTable.dbc
1835 for (uint32 areaflag
= 0; areaflag
< sAreaStore
.GetNumRows (); ++areaflag
)
1837 AreaTableEntry
const *areaEntry
= sAreaStore
.LookupEntry (areaflag
);
1840 int loc
= m_session
? m_session
->GetSessionDbcLocale () : sWorld
.GetDefaultDbcLocale();
1841 std::string name
= areaEntry
->area_name
[loc
];
1845 if (!Utf8FitTo (name
, wnamepart
))
1848 for(; loc
< MAX_LOCALE
; ++loc
)
1850 if (m_session
&& loc
==m_session
->GetSessionDbcLocale ())
1853 name
= areaEntry
->area_name
[loc
];
1857 if (Utf8FitTo (name
, wnamepart
))
1862 if (loc
< MAX_LOCALE
)
1864 // send area in "id - [name]" format
1865 std::ostringstream ss
;
1867 ss
<< areaEntry
->ID
<< " - |cffffffff|Harea:" << areaEntry
->ID
<< "|h[" << name
<< " " << localeNames
[loc
]<< "]|h|r";
1869 ss
<< areaEntry
->ID
<< " - " << name
<< " " << localeNames
[loc
];
1871 SendSysMessage (ss
.str ().c_str());
1878 if (counter
== 0) // if counter == 0 then we found nth
1879 SendSysMessage (LANG_COMMAND_NOAREAFOUND
);
1884 //Find tele in game_tele order by name
1885 bool ChatHandler::HandleLookupTeleCommand(const char * args
)
1889 SendSysMessage(LANG_COMMAND_TELE_PARAMETER
);
1890 SetSentErrorMessage(true);
1894 char const* str
= strtok((char*)args
, " ");
1898 std::string namepart
= str
;
1899 std::wstring wnamepart
;
1901 if(!Utf8toWStr(namepart
,wnamepart
))
1904 // converting string that we try to find to lower case
1905 wstrToLower( wnamepart
);
1907 std::ostringstream reply
;
1909 GameTeleMap
const & teleMap
= objmgr
.GetGameTeleMap();
1910 for(GameTeleMap::const_iterator itr
= teleMap
.begin(); itr
!= teleMap
.end(); ++itr
)
1912 GameTele
const* tele
= &itr
->second
;
1914 if(tele
->wnameLow
.find(wnamepart
) == std::wstring::npos
)
1918 reply
<< " |cffffffff|Htele:" << itr
->first
<< "|h[" << tele
->name
<< "]|h|r\n";
1920 reply
<< " " << itr
->first
<< " " << tele
->name
<< "\n";
1923 if(reply
.str().empty())
1924 SendSysMessage(LANG_COMMAND_TELE_NOLOCATION
);
1926 PSendSysMessage(LANG_COMMAND_TELE_LOCATION
,reply
.str().c_str());
1931 //Enable\Dissable accept whispers (for GM)
1932 bool ChatHandler::HandleWhispersCommand(const char* args
)
1936 PSendSysMessage(LANG_COMMAND_WHISPERACCEPTING
, m_session
->GetPlayer()->isAcceptWhispers() ? GetMangosString(LANG_ON
) : GetMangosString(LANG_OFF
));
1940 std::string argstr
= (char*)args
;
1944 m_session
->GetPlayer()->SetAcceptWhispers(true);
1945 SendSysMessage(LANG_COMMAND_WHISPERON
);
1950 if (argstr
== "off")
1952 m_session
->GetPlayer()->SetAcceptWhispers(false);
1953 SendSysMessage(LANG_COMMAND_WHISPEROFF
);
1957 SendSysMessage(LANG_USE_BOL
);
1958 SetSentErrorMessage(true);
1963 bool ChatHandler::HandlePlaySoundCommand(const char* args
)
1965 // USAGE: .debug playsound #soundid
1966 // #soundid - ID decimal number from SoundEntries.dbc (1st column)
1967 // this file have about 5000 sounds.
1968 // In this realization only caller can hear this sound.
1971 uint32 dwSoundId
= atoi((char*)args
);
1973 if( !sSoundEntriesStore
.LookupEntry(dwSoundId
) )
1975 PSendSysMessage(LANG_SOUND_NOT_EXIST
, dwSoundId
);
1976 SetSentErrorMessage(true);
1980 WorldPacket
data(SMSG_PLAY_OBJECT_SOUND
,4+8);
1981 data
<< uint32(dwSoundId
) << m_session
->GetPlayer()->GetGUID();
1982 m_session
->SendPacket(&data
);
1984 PSendSysMessage(LANG_YOU_HEAR_SOUND
, dwSoundId
);
1991 //Save all players in the world
1992 bool ChatHandler::HandleSaveAllCommand(const char* /*args*/)
1994 ObjectAccessor::Instance().SaveAllPlayers();
1995 SendSysMessage(LANG_PLAYERS_SAVED
);
1999 //Send mail by command
2000 bool ChatHandler::HandleSendMailCommand(const char* args
)
2005 // format: name "subject text" "mail text"
2007 std::string name
= extractPlayerNameFromLink((char*)args
);
2010 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
2011 SetSentErrorMessage(true);
2015 char* tail1
= strtok(NULL
, "");
2021 msgSubject
= strtok(tail1
+1, "\"");
2024 char* space
= strtok(tail1
, "\"");
2027 msgSubject
= strtok(NULL
, "\"");
2033 char* tail2
= strtok(NULL
, "");
2039 msgText
= strtok(tail2
+1, "\"");
2042 char* space
= strtok(tail2
, "\"");
2045 msgText
= strtok(NULL
, "\"");
2051 // msgSubject, msgText isn't NUL after prev. check
2052 std::string subject
= msgSubject
;
2053 std::string text
= msgText
;
2055 uint64 receiver_guid
= objmgr
.GetPlayerGUIDByName(name
);
2058 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
2059 SetSentErrorMessage(true);
2063 // from console show not existed sender
2064 uint32 sender_guidlo
= m_session
? m_session
->GetPlayer()->GetGUIDLow() : 0;
2066 uint32 messagetype
= MAIL_NORMAL
;
2067 uint32 stationery
= MAIL_STATIONERY_GM
;
2068 uint32 itemTextId
= !text
.empty() ? objmgr
.CreateItemText( text
) : 0;
2070 Player
*receiver
= objmgr
.GetPlayer(receiver_guid
);
2072 WorldSession::SendMailTo(receiver
,messagetype
, stationery
, sender_guidlo
, GUID_LOPART(receiver_guid
), subject
, itemTextId
, NULL
, 0, 0, MAIL_CHECK_MASK_NONE
);
2074 std::string nameLink
= playerLink(name
);
2075 PSendSysMessage(LANG_MAIL_SENT
, nameLink
.c_str());
2079 // teleport player to given game_tele.entry
2080 bool ChatHandler::HandleNameTeleCommand(const char * args
)
2085 std::string name
= extractPlayerNameFromLink((char*)args
);
2088 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
2089 SetSentErrorMessage(true);
2093 char* tail
= strtok(NULL
, "");
2097 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2098 GameTele
const* tele
= extractGameTeleFromLink(tail
);
2101 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
2102 SetSentErrorMessage(true);
2106 Player
*chr
= objmgr
.GetPlayer(name
.c_str());
2109 // check online security
2110 if (HasLowerSecurity(chr
, 0))
2113 std::string chrNameLink
= playerLink(name
);
2115 if(chr
->IsBeingTeleported()==true)
2117 PSendSysMessage(LANG_IS_TELEPORTED
, chrNameLink
.c_str());
2118 SetSentErrorMessage(true);
2122 PSendSysMessage(LANG_TELEPORTING_TO
, chrNameLink
.c_str(),"", tele
->name
.c_str());
2123 if (needReportToTarget(chr
))
2124 ChatHandler(chr
).PSendSysMessage(LANG_TELEPORTED_TO_BY
, GetNameLink().c_str());
2126 // stop flight if need
2127 if(chr
->isInFlight())
2129 chr
->GetMotionMaster()->MovementExpired();
2130 chr
->m_taxi
.ClearTaxiDestinations();
2132 // save only in non-flight case
2134 chr
->SaveRecallPosition();
2136 chr
->TeleportTo(tele
->mapId
,tele
->position_x
,tele
->position_y
,tele
->position_z
,tele
->orientation
);
2138 else if (uint64 guid
= objmgr
.GetPlayerGUIDByName(name
))
2140 // check offline security
2141 if (HasLowerSecurity(NULL
, guid
))
2144 std::string nameLink
= playerLink(name
);
2146 PSendSysMessage(LANG_TELEPORTING_TO
, nameLink
.c_str(), GetMangosString(LANG_OFFLINE
), tele
->name
.c_str());
2147 Player::SavePositionInDB(tele
->mapId
,tele
->position_x
,tele
->position_y
,tele
->position_z
,tele
->orientation
,
2148 MapManager::Instance().GetZoneId(tele
->mapId
,tele
->position_x
,tele
->position_y
,tele
->position_z
),guid
);
2151 PSendSysMessage(LANG_NO_PLAYER
, name
.c_str());
2156 //Teleport group to given game_tele.entry
2157 bool ChatHandler::HandleGroupTeleCommand(const char * args
)
2162 Player
*player
= getSelectedPlayer();
2165 SendSysMessage(LANG_NO_CHAR_SELECTED
);
2166 SetSentErrorMessage(true);
2170 // check online security
2171 if (HasLowerSecurity(player
, 0))
2174 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2175 GameTele
const* tele
= extractGameTeleFromLink((char*)args
);
2178 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
2179 SetSentErrorMessage(true);
2183 std::string nameLink
= GetNameLink(player
);
2185 Group
*grp
= player
->GetGroup();
2188 PSendSysMessage(LANG_NOT_IN_GROUP
,nameLink
.c_str());
2189 SetSentErrorMessage(true);
2193 for(GroupReference
*itr
= grp
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
2195 Player
*pl
= itr
->getSource();
2197 if(!pl
|| !pl
->GetSession() )
2200 // check online security
2201 if (HasLowerSecurity(pl
, 0))
2204 std::string plNameLink
= GetNameLink(pl
);
2206 if(pl
->IsBeingTeleported())
2208 PSendSysMessage(LANG_IS_TELEPORTED
, plNameLink
.c_str());
2212 PSendSysMessage(LANG_TELEPORTING_TO
, plNameLink
.c_str(),"", tele
->name
.c_str());
2213 if (needReportToTarget(pl
))
2214 ChatHandler(pl
).PSendSysMessage(LANG_TELEPORTED_TO_BY
, nameLink
.c_str());
2216 // stop flight if need
2217 if(pl
->isInFlight())
2219 pl
->GetMotionMaster()->MovementExpired();
2220 pl
->m_taxi
.ClearTaxiDestinations();
2222 // save only in non-flight case
2224 pl
->SaveRecallPosition();
2226 pl
->TeleportTo(tele
->mapId
, tele
->position_x
, tele
->position_y
, tele
->position_z
, tele
->orientation
);
2232 //Summon group of player
2233 bool ChatHandler::HandleGroupgoCommand(const char* args
)
2238 std::string name
= extractPlayerNameFromLink((char*)args
);
2241 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
2242 SetSentErrorMessage(true);
2246 Player
*player
= objmgr
.GetPlayer(name
.c_str());
2249 PSendSysMessage(LANG_NO_PLAYER
, args
);
2250 SetSentErrorMessage(true);
2254 // check online security
2255 if (HasLowerSecurity(player
, 0))
2258 Group
*grp
= player
->GetGroup();
2260 std::string nameLink
= playerLink(name
);
2264 PSendSysMessage(LANG_NOT_IN_GROUP
,nameLink
.c_str());
2265 SetSentErrorMessage(true);
2269 Map
* gmMap
= m_session
->GetPlayer()->GetMap();
2270 bool to_instance
= gmMap
->Instanceable();
2272 // we are in instance, and can summon only player in our group with us as lead
2273 if ( to_instance
&& (
2274 !m_session
->GetPlayer()->GetGroup() || (grp
->GetLeaderGUID() != m_session
->GetPlayer()->GetGUID()) ||
2275 (m_session
->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session
->GetPlayer()->GetGUID()) ) )
2276 // the last check is a bit excessive, but let it be, just in case
2278 SendSysMessage(LANG_CANNOT_SUMMON_TO_INST
);
2279 SetSentErrorMessage(true);
2283 for(GroupReference
*itr
= grp
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
2285 Player
*pl
= itr
->getSource();
2287 if(!pl
|| pl
==m_session
->GetPlayer() || !pl
->GetSession() )
2290 // check online security
2291 if (HasLowerSecurity(pl
, 0))
2294 std::string plNameLink
= playerLink(name
);
2296 if(pl
->IsBeingTeleported()==true)
2298 PSendSysMessage(LANG_IS_TELEPORTED
, plNameLink
.c_str());
2299 SetSentErrorMessage(true);
2305 Map
* plMap
= pl
->GetMap();
2307 if ( plMap
->Instanceable() && plMap
->GetInstanceId() != gmMap
->GetInstanceId() )
2309 // cannot summon from instance to instance
2310 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST
,plNameLink
.c_str());
2311 SetSentErrorMessage(true);
2316 PSendSysMessage(LANG_SUMMONING
, plNameLink
.c_str(),"");
2317 if (needReportToTarget(pl
))
2318 ChatHandler(pl
).PSendSysMessage(LANG_SUMMONED_BY
, nameLink
.c_str());
2320 // stop flight if need
2321 if(pl
->isInFlight())
2323 pl
->GetMotionMaster()->MovementExpired();
2324 pl
->m_taxi
.ClearTaxiDestinations();
2326 // save only in non-flight case
2328 pl
->SaveRecallPosition();
2332 m_session
->GetPlayer()->GetClosePoint(x
,y
,z
,pl
->GetObjectSize());
2333 pl
->TeleportTo(m_session
->GetPlayer()->GetMapId(),x
,y
,z
,pl
->GetOrientation());
2339 //teleport at coordinates
2340 bool ChatHandler::HandleGoXYCommand(const char* args
)
2345 Player
* _player
= m_session
->GetPlayer();
2347 char* px
= strtok((char*)args
, " ");
2348 char* py
= strtok(NULL
, " ");
2349 char* pmapid
= strtok(NULL
, " ");
2354 float x
= (float)atof(px
);
2355 float y
= (float)atof(py
);
2358 mapid
= (uint32
)atoi(pmapid
);
2359 else mapid
= _player
->GetMapId();
2361 if(!MapManager::IsValidMapCoord(mapid
,x
,y
))
2363 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,mapid
);
2364 SetSentErrorMessage(true);
2368 // stop flight if need
2369 if(_player
->isInFlight())
2371 _player
->GetMotionMaster()->MovementExpired();
2372 _player
->m_taxi
.ClearTaxiDestinations();
2374 // save only in non-flight case
2376 _player
->SaveRecallPosition();
2378 Map
const *map
= MapManager::Instance().GetBaseMap(mapid
);
2379 float z
= std::max(map
->GetHeight(x
, y
, MAX_HEIGHT
), map
->GetWaterLevel(x
, y
));
2381 _player
->TeleportTo(mapid
, x
, y
, z
, _player
->GetOrientation());
2386 //teleport at coordinates, including Z
2387 bool ChatHandler::HandleGoXYZCommand(const char* args
)
2392 Player
* _player
= m_session
->GetPlayer();
2394 char* px
= strtok((char*)args
, " ");
2395 char* py
= strtok(NULL
, " ");
2396 char* pz
= strtok(NULL
, " ");
2397 char* pmapid
= strtok(NULL
, " ");
2399 if (!px
|| !py
|| !pz
)
2402 float x
= (float)atof(px
);
2403 float y
= (float)atof(py
);
2404 float z
= (float)atof(pz
);
2407 mapid
= (uint32
)atoi(pmapid
);
2409 mapid
= _player
->GetMapId();
2411 if(!MapManager::IsValidMapCoord(mapid
,x
,y
,z
))
2413 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,mapid
);
2414 SetSentErrorMessage(true);
2418 // stop flight if need
2419 if(_player
->isInFlight())
2421 _player
->GetMotionMaster()->MovementExpired();
2422 _player
->m_taxi
.ClearTaxiDestinations();
2424 // save only in non-flight case
2426 _player
->SaveRecallPosition();
2428 _player
->TeleportTo(mapid
, x
, y
, z
, _player
->GetOrientation());
2433 //teleport at coordinates
2434 bool ChatHandler::HandleGoZoneXYCommand(const char* args
)
2439 Player
* _player
= m_session
->GetPlayer();
2441 char* px
= strtok((char*)args
, " ");
2442 char* py
= strtok(NULL
, " ");
2443 char* tail
= strtok(NULL
,"");
2445 char* cAreaId
= extractKeyFromLink(tail
,"Harea"); // string or [name] Shift-click form |color|Harea:area_id|h[name]|h|r
2450 float x
= (float)atof(px
);
2451 float y
= (float)atof(py
);
2452 uint32 areaid
= cAreaId
? (uint32
)atoi(cAreaId
) : _player
->GetZoneId();
2454 AreaTableEntry
const* areaEntry
= GetAreaEntryByAreaID(areaid
);
2456 if( x
<0 || x
>100 || y
<0 || y
>100 || !areaEntry
)
2458 PSendSysMessage(LANG_INVALID_ZONE_COORD
,x
,y
,areaid
);
2459 SetSentErrorMessage(true);
2463 // update to parent zone if exist (client map show only zones without parents)
2464 AreaTableEntry
const* zoneEntry
= areaEntry
->zone
? GetAreaEntryByAreaID(areaEntry
->zone
) : areaEntry
;
2466 Map
const *map
= MapManager::Instance().GetBaseMap(zoneEntry
->mapid
);
2468 if(map
->Instanceable())
2470 PSendSysMessage(LANG_INVALID_ZONE_MAP
,areaEntry
->ID
,areaEntry
->area_name
[m_session
->GetSessionDbcLocale()],map
->GetId(),map
->GetMapName());
2471 SetSentErrorMessage(true);
2475 Zone2MapCoordinates(x
,y
,zoneEntry
->ID
);
2477 if(!MapManager::IsValidMapCoord(zoneEntry
->mapid
,x
,y
))
2479 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,zoneEntry
->mapid
);
2480 SetSentErrorMessage(true);
2484 // stop flight if need
2485 if(_player
->isInFlight())
2487 _player
->GetMotionMaster()->MovementExpired();
2488 _player
->m_taxi
.ClearTaxiDestinations();
2490 // save only in non-flight case
2492 _player
->SaveRecallPosition();
2494 float z
= std::max(map
->GetHeight(x
, y
, MAX_HEIGHT
), map
->GetWaterLevel(x
, y
));
2495 _player
->TeleportTo(zoneEntry
->mapid
, x
, y
, z
, _player
->GetOrientation());
2501 bool ChatHandler::HandleGoGridCommand(const char* args
)
2503 if(!*args
) return false;
2504 Player
* _player
= m_session
->GetPlayer();
2506 char* px
= strtok((char*)args
, " ");
2507 char* py
= strtok(NULL
, " ");
2508 char* pmapid
= strtok(NULL
, " ");
2513 float grid_x
= (float)atof(px
);
2514 float grid_y
= (float)atof(py
);
2517 mapid
= (uint32
)atoi(pmapid
);
2518 else mapid
= _player
->GetMapId();
2521 float x
= (grid_x
-CENTER_GRID_ID
+0.5f
)*SIZE_OF_GRIDS
;
2522 float y
= (grid_y
-CENTER_GRID_ID
+0.5f
)*SIZE_OF_GRIDS
;
2524 if(!MapManager::IsValidMapCoord(mapid
,x
,y
))
2526 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,mapid
);
2527 SetSentErrorMessage(true);
2531 // stop flight if need
2532 if(_player
->isInFlight())
2534 _player
->GetMotionMaster()->MovementExpired();
2535 _player
->m_taxi
.ClearTaxiDestinations();
2537 // save only in non-flight case
2539 _player
->SaveRecallPosition();
2541 Map
const *map
= MapManager::Instance().GetBaseMap(mapid
);
2542 float z
= std::max(map
->GetHeight(x
, y
, MAX_HEIGHT
), map
->GetWaterLevel(x
, y
));
2543 _player
->TeleportTo(mapid
, x
, y
, z
, _player
->GetOrientation());
2548 bool ChatHandler::HandleDrunkCommand(const char* args
)
2550 if(!*args
) return false;
2552 uint32 drunklevel
= (uint32
)atoi(args
);
2553 if(drunklevel
> 100)
2556 uint16 drunkMod
= drunklevel
* 0xFFFF / 100;
2558 m_session
->GetPlayer()->SetDrunkValue(drunkMod
);