2 * Copyright (C) 2005-2010 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 //-----------------------Npc Commands-----------------------
40 bool ChatHandler::HandleNpcSayCommand(const char* args
)
45 Creature
* pCreature
= getSelectedCreature();
48 SendSysMessage(LANG_SELECT_CREATURE
);
49 SetSentErrorMessage(true);
53 pCreature
->MonsterSay(args
, LANG_UNIVERSAL
, 0);
58 bool ChatHandler::HandleNpcYellCommand(const char* args
)
63 Creature
* pCreature
= getSelectedCreature();
66 SendSysMessage(LANG_SELECT_CREATURE
);
67 SetSentErrorMessage(true);
71 pCreature
->MonsterYell(args
, LANG_UNIVERSAL
, 0);
76 //show text emote by creature in chat
77 bool ChatHandler::HandleNpcTextEmoteCommand(const char* args
)
82 Creature
* pCreature
= getSelectedCreature();
86 SendSysMessage(LANG_SELECT_CREATURE
);
87 SetSentErrorMessage(true);
91 pCreature
->MonsterTextEmote(args
, 0);
96 // make npc whisper to player
97 bool ChatHandler::HandleNpcWhisperCommand(const char* args
)
102 char* receiver_str
= strtok((char*)args
, " ");
103 char* text
= strtok(NULL
, "");
105 uint64 guid
= m_session
->GetPlayer()->GetSelection();
106 Creature
* pCreature
= m_session
->GetPlayer()->GetMap()->GetCreature(guid
);
108 if(!pCreature
|| !receiver_str
|| !text
)
113 uint64 receiver_guid
= atol(receiver_str
);
115 // check online security
116 if (HasLowerSecurity(sObjectMgr
.GetPlayer(receiver_guid
), 0))
119 pCreature
->MonsterWhisper(text
,receiver_guid
);
123 //----------------------------------------------------------
126 bool ChatHandler::HandleAnnounceCommand(const char* args
)
131 sWorld
.SendWorldText(LANG_SYSTEMMESSAGE
,args
);
135 //notification player at the screen
136 bool ChatHandler::HandleNotifyCommand(const char* args
)
141 std::string str
= GetMangosString(LANG_GLOBAL_NOTIFY
);
144 WorldPacket
data(SMSG_NOTIFICATION
, (str
.size()+1));
146 sWorld
.SendGlobalMessage(&data
);
151 //Enable\Dissable GM Mode
152 bool ChatHandler::HandleGMCommand(const char* args
)
156 if(m_session
->GetPlayer()->isGameMaster())
157 m_session
->SendNotification(LANG_GM_ON
);
159 m_session
->SendNotification(LANG_GM_OFF
);
163 std::string argstr
= (char*)args
;
167 m_session
->GetPlayer()->SetGameMaster(true);
168 m_session
->SendNotification(LANG_GM_ON
);
170 VMAP::IVMapManager
*vMapManager
= VMAP::VMapFactory::createOrGetVMapManager();
171 vMapManager
->processCommand("stoplog");
178 m_session
->GetPlayer()->SetGameMaster(false);
179 m_session
->SendNotification(LANG_GM_OFF
);
181 VMAP::IVMapManager
*vMapManager
= VMAP::VMapFactory::createOrGetVMapManager();
182 vMapManager
->processCommand("startlog");
187 SendSysMessage(LANG_USE_BOL
);
188 SetSentErrorMessage(true);
192 // Enables or disables hiding of the staff badge
193 bool ChatHandler::HandleGMChatCommand(const char* args
)
197 if(m_session
->GetPlayer()->isGMChat())
198 m_session
->SendNotification(LANG_GM_CHAT_ON
);
200 m_session
->SendNotification(LANG_GM_CHAT_OFF
);
204 std::string argstr
= (char*)args
;
208 m_session
->GetPlayer()->SetGMChat(true);
209 m_session
->SendNotification(LANG_GM_CHAT_ON
);
215 m_session
->GetPlayer()->SetGMChat(false);
216 m_session
->SendNotification(LANG_GM_CHAT_OFF
);
220 SendSysMessage(LANG_USE_BOL
);
221 SetSentErrorMessage(true);
225 //Enable\Dissable Invisible mode
226 bool ChatHandler::HandleGMVisibleCommand(const char* args
)
230 PSendSysMessage(LANG_YOU_ARE
, m_session
->GetPlayer()->isGMVisible() ? GetMangosString(LANG_VISIBLE
) : GetMangosString(LANG_INVISIBLE
));
234 std::string argstr
= (char*)args
;
238 m_session
->GetPlayer()->SetGMVisible(true);
239 m_session
->SendNotification(LANG_INVISIBLE_VISIBLE
);
245 m_session
->SendNotification(LANG_INVISIBLE_INVISIBLE
);
246 m_session
->GetPlayer()->SetGMVisible(false);
250 SendSysMessage(LANG_USE_BOL
);
251 SetSentErrorMessage(true);
257 bool ChatHandler::HandleGPSCommand(const char* args
)
259 WorldObject
*obj
= NULL
;
262 uint64 guid
= extractGuidFromLink((char*)args
);
264 obj
= (WorldObject
*)ObjectAccessor::GetObjectByTypeMask(*m_session
->GetPlayer(),guid
,TYPEMASK_UNIT
|TYPEMASK_GAMEOBJECT
);
268 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
269 SetSentErrorMessage(true);
275 obj
= getSelectedUnit();
279 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
280 SetSentErrorMessage(true);
284 CellPair cell_val
= MaNGOS::ComputeCellPair(obj
->GetPositionX(), obj
->GetPositionY());
287 uint32 zone_id
, area_id
;
288 obj
->GetZoneAndAreaId(zone_id
,area_id
);
290 MapEntry
const* mapEntry
= sMapStore
.LookupEntry(obj
->GetMapId());
291 AreaTableEntry
const* zoneEntry
= GetAreaEntryByAreaID(zone_id
);
292 AreaTableEntry
const* areaEntry
= GetAreaEntryByAreaID(area_id
);
294 float zone_x
= obj
->GetPositionX();
295 float zone_y
= obj
->GetPositionY();
297 Map2ZoneCoordinates(zone_x
,zone_y
,zone_id
);
299 Map
const *map
= obj
->GetMap();
300 float ground_z
= map
->GetHeight(obj
->GetPositionX(), obj
->GetPositionY(), MAX_HEIGHT
);
301 float floor_z
= map
->GetHeight(obj
->GetPositionX(), obj
->GetPositionY(), obj
->GetPositionZ());
303 GridPair p
= MaNGOS::ComputeGridPair(obj
->GetPositionX(), obj
->GetPositionY());
308 uint32 have_map
= Map::ExistMap(obj
->GetMapId(),gx
,gy
) ? 1 : 0;
309 uint32 have_vmap
= Map::ExistVMap(obj
->GetMapId(),gx
,gy
) ? 1 : 0;
311 PSendSysMessage(LANG_MAP_POSITION
,
312 obj
->GetMapId(), (mapEntry
? mapEntry
->name
[GetSessionDbcLocale()] : "<unknown>" ),
313 zone_id
, (zoneEntry
? zoneEntry
->area_name
[GetSessionDbcLocale()] : "<unknown>" ),
314 area_id
, (areaEntry
? areaEntry
->area_name
[GetSessionDbcLocale()] : "<unknown>" ),
316 obj
->GetPositionX(), obj
->GetPositionY(), obj
->GetPositionZ(), obj
->GetOrientation(),
317 cell
.GridX(), cell
.GridY(), cell
.CellX(), cell
.CellY(), obj
->GetInstanceId(),
318 zone_x
, zone_y
, ground_z
, floor_z
, have_map
, have_vmap
);
320 sLog
.outDebug("Player %s GPS call for %s '%s' (%s: %u):",
321 m_session
? GetNameLink().c_str() : GetMangosString(LANG_CONSOLE_COMMAND
),
322 (obj
->GetTypeId() == TYPEID_PLAYER
? "player" : "creature"), obj
->GetName(),
323 (obj
->GetTypeId() == TYPEID_PLAYER
? "GUID" : "Entry"), (obj
->GetTypeId() == TYPEID_PLAYER
? obj
->GetGUIDLow(): obj
->GetEntry()) );
325 sLog
.outDebug(GetMangosString(LANG_MAP_POSITION
),
326 obj
->GetMapId(), (mapEntry
? mapEntry
->name
[sWorld
.GetDefaultDbcLocale()] : "<unknown>" ),
327 zone_id
, (zoneEntry
? zoneEntry
->area_name
[sWorld
.GetDefaultDbcLocale()] : "<unknown>" ),
328 area_id
, (areaEntry
? areaEntry
->area_name
[sWorld
.GetDefaultDbcLocale()] : "<unknown>" ),
330 obj
->GetPositionX(), obj
->GetPositionY(), obj
->GetPositionZ(), obj
->GetOrientation(),
331 cell
.GridX(), cell
.GridY(), cell
.CellX(), cell
.CellY(), obj
->GetInstanceId(),
332 zone_x
, zone_y
, ground_z
, floor_z
, have_map
, have_vmap
);
334 LiquidData liquid_status
;
335 ZLiquidStatus res
= map
->getLiquidStatus(obj
->GetPositionX(), obj
->GetPositionY(), obj
->GetPositionZ(), MAP_ALL_LIQUIDS
, &liquid_status
);
338 PSendSysMessage(LANG_LIQUID_STATUS
, liquid_status
.level
, liquid_status
.depth_level
, liquid_status
.type
, res
);
344 bool ChatHandler::HandleNamegoCommand(const char* args
)
348 std::string target_name
;
349 if (!extractPlayerTarget((char*)args
,&target
,&target_guid
,&target_name
))
352 Player
* _player
= m_session
->GetPlayer();
353 if (target
== _player
|| target_guid
== _player
->GetGUID())
355 PSendSysMessage(LANG_CANT_TELEPORT_SELF
);
356 SetSentErrorMessage(true);
362 std::string nameLink
= playerLink(target_name
);
363 // check online security
364 if (HasLowerSecurity(target
, 0))
367 if (target
->IsBeingTeleported())
369 PSendSysMessage(LANG_IS_TELEPORTED
, nameLink
.c_str());
370 SetSentErrorMessage(true);
374 Map
* pMap
= m_session
->GetPlayer()->GetMap();
376 if (pMap
->IsBattleGroundOrArena())
378 // only allow if gm mode is on
379 if (!target
->isGameMaster())
381 PSendSysMessage(LANG_CANNOT_GO_TO_BG_GM
,nameLink
.c_str());
382 SetSentErrorMessage(true);
385 // if both players are in different bgs
386 else if (target
->GetBattleGroundId() && m_session
->GetPlayer()->GetBattleGroundId() != target
->GetBattleGroundId())
388 PSendSysMessage(LANG_CANNOT_GO_TO_BG_FROM_BG
,nameLink
.c_str());
389 SetSentErrorMessage(true);
392 // all's well, set bg id
393 // when porting out from the bg, it will be reset to 0
394 target
->SetBattleGroundId(m_session
->GetPlayer()->GetBattleGroundId(), m_session
->GetPlayer()->GetBattleGroundTypeId());
395 // remember current position as entry point for return at bg end teleportation
396 if (!target
->GetMap()->IsBattleGroundOrArena())
397 target
->SetBattleGroundEntryPoint();
399 else if (pMap
->IsDungeon())
401 Map
* cMap
= target
->GetMap();
402 if (cMap
->Instanceable() && cMap
->GetInstanceId() != pMap
->GetInstanceId())
404 // cannot summon from instance to instance
405 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST
,nameLink
.c_str());
406 SetSentErrorMessage(true);
410 // we are in instance, and can summon only player in our group with us as lead
411 if (!m_session
->GetPlayer()->GetGroup() || !target
->GetGroup() ||
412 (target
->GetGroup()->GetLeaderGUID() != m_session
->GetPlayer()->GetGUID()) ||
413 (m_session
->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session
->GetPlayer()->GetGUID()))
414 // the last check is a bit excessive, but let it be, just in case
416 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST
,nameLink
.c_str());
417 SetSentErrorMessage(true);
422 PSendSysMessage(LANG_SUMMONING
, nameLink
.c_str(),"");
423 if (needReportToTarget(target
))
424 ChatHandler(target
).PSendSysMessage(LANG_SUMMONED_BY
, playerLink(_player
->GetName()).c_str());
426 // stop flight if need
427 if (target
->isInFlight())
429 target
->GetMotionMaster()->MovementExpired();
430 target
->m_taxi
.ClearTaxiDestinations();
432 // save only in non-flight case
434 target
->SaveRecallPosition();
438 m_session
->GetPlayer()->GetClosePoint(x
,y
,z
,target
->GetObjectSize());
439 target
->TeleportTo(m_session
->GetPlayer()->GetMapId(),x
,y
,z
,target
->GetOrientation());
443 // check offline security
444 if (HasLowerSecurity(NULL
, target_guid
))
447 std::string nameLink
= playerLink(target_name
);
449 PSendSysMessage(LANG_SUMMONING
, nameLink
.c_str(),GetMangosString(LANG_OFFLINE
));
451 // in point where GM stay
452 Player::SavePositionInDB(m_session
->GetPlayer()->GetMapId(),
453 m_session
->GetPlayer()->GetPositionX(),
454 m_session
->GetPlayer()->GetPositionY(),
455 m_session
->GetPlayer()->GetPositionZ(),
456 m_session
->GetPlayer()->GetOrientation(),
457 m_session
->GetPlayer()->GetZoneId(),
465 bool ChatHandler::HandleGonameCommand(const char* args
)
469 std::string target_name
;
470 if (!extractPlayerTarget((char*)args
,&target
,&target_guid
,&target_name
))
473 Player
* _player
= m_session
->GetPlayer();
474 if (target
== _player
|| target_guid
== _player
->GetGUID())
476 SendSysMessage(LANG_CANT_TELEPORT_SELF
);
477 SetSentErrorMessage(true);
484 // check online security
485 if (HasLowerSecurity(target
, 0))
488 std::string chrNameLink
= playerLink(target_name
);
490 Map
* cMap
= target
->GetMap();
491 if (cMap
->IsBattleGroundOrArena())
493 // only allow if gm mode is on
494 if (!_player
->isGameMaster())
496 PSendSysMessage(LANG_CANNOT_GO_TO_BG_GM
,chrNameLink
.c_str());
497 SetSentErrorMessage(true);
500 // if both players are in different bgs
501 else if (_player
->GetBattleGroundId() && _player
->GetBattleGroundId() != target
->GetBattleGroundId())
503 PSendSysMessage(LANG_CANNOT_GO_TO_BG_FROM_BG
,chrNameLink
.c_str());
504 SetSentErrorMessage(true);
507 // all's well, set bg id
508 // when porting out from the bg, it will be reset to 0
509 _player
->SetBattleGroundId(target
->GetBattleGroundId(), target
->GetBattleGroundTypeId());
510 // remember current position as entry point for return at bg end teleportation
511 if (!_player
->GetMap()->IsBattleGroundOrArena())
512 _player
->SetBattleGroundEntryPoint();
514 else if(cMap
->IsDungeon())
516 // we have to go to instance, and can go to player only if:
517 // 1) we are in his group (either as leader or as member)
518 // 2) we are not bound to any group and have GM mode on
519 if (_player
->GetGroup())
521 // we are in group, we can go only if we are in the player group
522 if (_player
->GetGroup() != target
->GetGroup())
524 PSendSysMessage(LANG_CANNOT_GO_TO_INST_PARTY
,chrNameLink
.c_str());
525 SetSentErrorMessage(true);
531 // we are not in group, let's verify our GM mode
532 if (!_player
->isGameMaster())
534 PSendSysMessage(LANG_CANNOT_GO_TO_INST_GM
,chrNameLink
.c_str());
535 SetSentErrorMessage(true);
540 // if the player or the player's group is bound to another instance
541 // the player will not be bound to another one
542 InstancePlayerBind
*pBind
= _player
->GetBoundInstance(target
->GetMapId(), target
->GetDifficulty(cMap
->IsRaid()));
545 Group
*group
= _player
->GetGroup();
546 // if no bind exists, create a solo bind
547 InstanceGroupBind
*gBind
= group
? group
->GetBoundInstance(target
) : NULL
;
548 // if no bind exists, create a solo bind
550 if (InstanceSave
*save
= sInstanceSaveMgr
.GetInstanceSave(target
->GetInstanceId()))
551 _player
->BindToInstance(save
, !save
->CanReset());
555 _player
->SetRaidDifficulty(target
->GetRaidDifficulty());
557 _player
->SetDungeonDifficulty(target
->GetDungeonDifficulty());
560 PSendSysMessage(LANG_APPEARING_AT
, chrNameLink
.c_str());
561 if (needReportToTarget(target
))
562 ChatHandler(target
).PSendSysMessage(LANG_APPEARING_TO
, GetNameLink().c_str());
564 // stop flight if need
565 if (_player
->isInFlight())
567 _player
->GetMotionMaster()->MovementExpired();
568 _player
->m_taxi
.ClearTaxiDestinations();
570 // save only in non-flight case
572 _player
->SaveRecallPosition();
574 // to point to see at target with same orientation
576 target
->GetContactPoint(_player
,x
,y
,z
);
578 _player
->TeleportTo(target
->GetMapId(), x
, y
, z
, _player
->GetAngle(target
), TELE_TO_GM_MODE
);
582 // check offline security
583 if (HasLowerSecurity(NULL
, target_guid
))
586 std::string nameLink
= playerLink(target_name
);
588 PSendSysMessage(LANG_APPEARING_AT
, nameLink
.c_str());
590 // to point where player stay (if loaded)
594 if (!Player::LoadPositionFromDB(map
,x
,y
,z
,o
,in_flight
,target_guid
))
597 // stop flight if need
598 if (_player
->isInFlight())
600 _player
->GetMotionMaster()->MovementExpired();
601 _player
->m_taxi
.ClearTaxiDestinations();
603 // save only in non-flight case
605 _player
->SaveRecallPosition();
607 _player
->TeleportTo(map
, x
, y
, z
,_player
->GetOrientation());
613 // Teleport player to last position
614 bool ChatHandler::HandleRecallCommand(const char* args
)
617 if(!extractPlayerTarget((char*)args
,&target
))
620 // check online security
621 if (HasLowerSecurity(target
, 0))
624 if (target
->IsBeingTeleported())
626 PSendSysMessage(LANG_IS_TELEPORTED
, GetNameLink(target
).c_str());
627 SetSentErrorMessage(true);
631 // stop flight if need
632 if(target
->isInFlight())
634 target
->GetMotionMaster()->MovementExpired();
635 target
->m_taxi
.ClearTaxiDestinations();
638 target
->TeleportTo(target
->m_recallMap
, target
->m_recallX
, target
->m_recallY
, target
->m_recallZ
, target
->m_recallO
);
643 bool ChatHandler::HandleModifyHPCommand(const char* args
)
648 // char* pHp = strtok((char*)args, " ");
652 // char* pHpMax = strtok(NULL, " ");
656 // int32 hpm = atoi(pHpMax);
657 // int32 hp = atoi(pHp);
659 int32 hp
= atoi((char*)args
);
660 int32 hpm
= atoi((char*)args
);
662 if (hp
<= 0 || hpm
<= 0 || hpm
< hp
)
664 SendSysMessage(LANG_BAD_VALUE
);
665 SetSentErrorMessage(true);
669 Player
*chr
= getSelectedPlayer();
672 SendSysMessage(LANG_NO_CHAR_SELECTED
);
673 SetSentErrorMessage(true);
677 // check online security
678 if (HasLowerSecurity(chr
, 0))
681 PSendSysMessage(LANG_YOU_CHANGE_HP
, GetNameLink(chr
).c_str(), hp
, hpm
);
682 if (needReportToTarget(chr
))
683 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_HP_CHANGED
, GetNameLink().c_str(), hp
, hpm
);
685 chr
->SetMaxHealth( hpm
);
686 chr
->SetHealth( hp
);
692 bool ChatHandler::HandleModifyManaCommand(const char* args
)
697 // char* pmana = strtok((char*)args, " ");
701 // char* pmanaMax = strtok(NULL, " ");
705 // int32 manam = atoi(pmanaMax);
706 // int32 mana = atoi(pmana);
707 int32 mana
= atoi((char*)args
);
708 int32 manam
= atoi((char*)args
);
710 if (mana
<= 0 || manam
<= 0 || manam
< mana
)
712 SendSysMessage(LANG_BAD_VALUE
);
713 SetSentErrorMessage(true);
717 Player
*chr
= getSelectedPlayer();
720 SendSysMessage(LANG_NO_CHAR_SELECTED
);
721 SetSentErrorMessage(true);
725 // check online security
726 if (HasLowerSecurity(chr
, 0))
729 PSendSysMessage(LANG_YOU_CHANGE_MANA
, GetNameLink(chr
).c_str(), mana
, manam
);
730 if (needReportToTarget(chr
))
731 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_MANA_CHANGED
, GetNameLink().c_str(), mana
, manam
);
733 chr
->SetMaxPower(POWER_MANA
,manam
);
734 chr
->SetPower(POWER_MANA
, mana
);
740 bool ChatHandler::HandleModifyEnergyCommand(const char* args
)
745 // char* pmana = strtok((char*)args, " ");
749 // char* pmanaMax = strtok(NULL, " ");
753 // int32 manam = atoi(pmanaMax);
754 // int32 mana = atoi(pmana);
756 int32 energy
= atoi((char*)args
)*10;
757 int32 energym
= atoi((char*)args
)*10;
759 if (energy
<= 0 || energym
<= 0 || energym
< energy
)
761 SendSysMessage(LANG_BAD_VALUE
);
762 SetSentErrorMessage(true);
766 Player
*chr
= getSelectedPlayer();
769 SendSysMessage(LANG_NO_CHAR_SELECTED
);
770 SetSentErrorMessage(true);
774 // check online security
775 if (HasLowerSecurity(chr
, 0))
778 PSendSysMessage(LANG_YOU_CHANGE_ENERGY
, GetNameLink(chr
).c_str(), energy
/10, energym
/10);
779 if (needReportToTarget(chr
))
780 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_ENERGY_CHANGED
, GetNameLink().c_str(), energy
/10, energym
/10);
782 chr
->SetMaxPower(POWER_ENERGY
,energym
);
783 chr
->SetPower(POWER_ENERGY
, energy
);
785 sLog
.outDetail(GetMangosString(LANG_CURRENT_ENERGY
),chr
->GetMaxPower(POWER_ENERGY
));
791 bool ChatHandler::HandleModifyRageCommand(const char* args
)
796 // char* pmana = strtok((char*)args, " ");
800 // char* pmanaMax = strtok(NULL, " ");
804 // int32 manam = atoi(pmanaMax);
805 // int32 mana = atoi(pmana);
807 int32 rage
= atoi((char*)args
)*10;
808 int32 ragem
= atoi((char*)args
)*10;
810 if (rage
<= 0 || ragem
<= 0 || ragem
< rage
)
812 SendSysMessage(LANG_BAD_VALUE
);
813 SetSentErrorMessage(true);
817 Player
*chr
= getSelectedPlayer();
820 SendSysMessage(LANG_NO_CHAR_SELECTED
);
821 SetSentErrorMessage(true);
825 // check online security
826 if (HasLowerSecurity(chr
, 0))
829 PSendSysMessage(LANG_YOU_CHANGE_RAGE
, GetNameLink(chr
).c_str(), rage
/10, ragem
/10);
830 if (needReportToTarget(chr
))
831 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_RAGE_CHANGED
, GetNameLink().c_str(), rage
/10, ragem
/10);
833 chr
->SetMaxPower(POWER_RAGE
,ragem
);
834 chr
->SetPower(POWER_RAGE
, rage
);
839 // Edit Player Runic Power
840 bool ChatHandler::HandleModifyRunicPowerCommand(const char* args
)
845 int32 rune
= atoi((char*)args
)*10;
846 int32 runem
= atoi((char*)args
)*10;
848 if (rune
<= 0 || runem
<= 0 || runem
< rune
)
850 SendSysMessage(LANG_BAD_VALUE
);
851 SetSentErrorMessage(true);
855 Player
*chr
= getSelectedPlayer();
858 SendSysMessage(LANG_NO_CHAR_SELECTED
);
859 SetSentErrorMessage(true);
863 PSendSysMessage(LANG_YOU_CHANGE_RUNIC_POWER
, GetNameLink(chr
).c_str(), rune
/10, runem
/10);
864 if (needReportToTarget(chr
))
865 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_RUNIC_POWER_CHANGED
, GetNameLink().c_str(), rune
/10, runem
/10);
867 chr
->SetMaxPower(POWER_RUNIC_POWER
,runem
);
868 chr
->SetPower(POWER_RUNIC_POWER
, rune
);
873 //Edit Player Faction
874 bool ChatHandler::HandleModifyFactionCommand(const char* args
)
879 char* pfactionid
= extractKeyFromLink((char*)args
,"Hfaction");
881 Creature
* chr
= getSelectedCreature();
884 SendSysMessage(LANG_SELECT_CREATURE
);
885 SetSentErrorMessage(true);
893 uint32 factionid
= chr
->getFaction();
894 uint32 flag
= chr
->GetUInt32Value(UNIT_FIELD_FLAGS
);
895 uint32 npcflag
= chr
->GetUInt32Value(UNIT_NPC_FLAGS
);
896 uint32 dyflag
= chr
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
);
897 PSendSysMessage(LANG_CURRENT_FACTION
,chr
->GetGUIDLow(),factionid
,flag
,npcflag
,dyflag
);
904 SendSysMessage(LANG_NO_CHAR_SELECTED
);
905 SetSentErrorMessage(true);
909 uint32 factionid
= atoi(pfactionid
);
912 char *pflag
= strtok(NULL
, " ");
914 flag
= chr
->GetUInt32Value(UNIT_FIELD_FLAGS
);
918 char* pnpcflag
= strtok(NULL
, " ");
922 npcflag
= chr
->GetUInt32Value(UNIT_NPC_FLAGS
);
924 npcflag
= atoi(pnpcflag
);
926 char* pdyflag
= strtok(NULL
, " ");
930 dyflag
= chr
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
);
932 dyflag
= atoi(pdyflag
);
934 if(!sFactionTemplateStore
.LookupEntry(factionid
))
936 PSendSysMessage(LANG_WRONG_FACTION
, factionid
);
937 SetSentErrorMessage(true);
941 PSendSysMessage(LANG_YOU_CHANGE_FACTION
, chr
->GetGUIDLow(),factionid
,flag
,npcflag
,dyflag
);
943 chr
->setFaction(factionid
);
944 chr
->SetUInt32Value(UNIT_FIELD_FLAGS
,flag
);
945 chr
->SetUInt32Value(UNIT_NPC_FLAGS
,npcflag
);
946 chr
->SetUInt32Value(UNIT_DYNAMIC_FLAGS
,dyflag
);
952 bool ChatHandler::HandleModifySpellCommand(const char* args
)
954 if(!*args
) return false;
955 char* pspellflatid
= strtok((char*)args
, " ");
959 char* pop
= strtok(NULL
, " ");
963 char* pval
= strtok(NULL
, " ");
969 char* pmark
= strtok(NULL
, " ");
971 uint8 spellflatid
= atoi(pspellflatid
);
972 uint8 op
= atoi(pop
);
973 uint16 val
= atoi(pval
);
979 Player
*chr
= getSelectedPlayer();
982 SendSysMessage(LANG_NO_CHAR_SELECTED
);
983 SetSentErrorMessage(true);
987 // check online security
988 if (HasLowerSecurity(chr
, 0))
991 PSendSysMessage(LANG_YOU_CHANGE_SPELLFLATID
, spellflatid
, val
, mark
, GetNameLink(chr
).c_str());
992 if (needReportToTarget(chr
))
993 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_SPELLFLATID_CHANGED
, GetNameLink().c_str(), spellflatid
, val
, mark
);
995 WorldPacket
data(SMSG_SET_FLAT_SPELL_MODIFIER
, (1+1+2+2));
996 data
<< uint8(spellflatid
);
999 data
<< uint16(mark
);
1000 chr
->GetSession()->SendPacket(&data
);
1006 bool ChatHandler::HandleModifyTalentCommand (const char* args
)
1011 int tp
= atoi((char*)args
);
1015 Unit
* target
= getSelectedUnit();
1018 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1019 SetSentErrorMessage(true);
1023 if(target
->GetTypeId()==TYPEID_PLAYER
)
1025 // check online security
1026 if (HasLowerSecurity((Player
*)target
, 0))
1029 ((Player
*)target
)->SetFreeTalentPoints(tp
);
1030 ((Player
*)target
)->SendTalentsInfoData(false);
1033 else if(((Creature
*)target
)->isPet())
1035 Unit
*owner
= target
->GetOwner();
1036 if(owner
&& owner
->GetTypeId() == TYPEID_PLAYER
&& ((Pet
*)target
)->IsPermanentPetFor((Player
*)owner
))
1038 // check online security
1039 if (HasLowerSecurity((Player
*)owner
, 0))
1042 ((Pet
*)target
)->SetFreeTalentPoints(tp
);
1043 ((Player
*)owner
)->SendTalentsInfoData(true);
1048 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1049 SetSentErrorMessage(true);
1053 //Enable On\OFF all taxi paths
1054 bool ChatHandler::HandleTaxiCheatCommand(const char* args
)
1058 SendSysMessage(LANG_USE_BOL
);
1059 SetSentErrorMessage(true);
1063 std::string argstr
= (char*)args
;
1065 Player
*chr
= getSelectedPlayer();
1068 chr
=m_session
->GetPlayer();
1071 // check online security
1072 else if (HasLowerSecurity(chr
, 0))
1077 chr
->SetTaxiCheater(true);
1078 PSendSysMessage(LANG_YOU_GIVE_TAXIS
, GetNameLink(chr
).c_str());
1079 if (needReportToTarget(chr
))
1080 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_TAXIS_ADDED
, GetNameLink().c_str());
1084 if (argstr
== "off")
1086 chr
->SetTaxiCheater(false);
1087 PSendSysMessage(LANG_YOU_REMOVE_TAXIS
, GetNameLink(chr
).c_str());
1088 if (needReportToTarget(chr
))
1089 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_TAXIS_REMOVED
, GetNameLink().c_str());
1094 SendSysMessage(LANG_USE_BOL
);
1095 SetSentErrorMessage(true);
1099 //Edit Player Aspeed
1100 bool ChatHandler::HandleModifyASpeedCommand(const char* args
)
1105 float ASpeed
= (float)atof((char*)args
);
1107 if (ASpeed
> 10 || ASpeed
< 0.1)
1109 SendSysMessage(LANG_BAD_VALUE
);
1110 SetSentErrorMessage(true);
1114 Player
*chr
= getSelectedPlayer();
1117 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1118 SetSentErrorMessage(true);
1122 // check online security
1123 if (HasLowerSecurity(chr
, 0))
1126 std::string chrNameLink
= GetNameLink(chr
);
1128 if(chr
->isInFlight())
1130 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chrNameLink
.c_str());
1131 SetSentErrorMessage(true);
1135 PSendSysMessage(LANG_YOU_CHANGE_ASPEED
, ASpeed
, chrNameLink
.c_str());
1136 if (needReportToTarget(chr
))
1137 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_ASPEED_CHANGED
, GetNameLink().c_str(), ASpeed
);
1139 chr
->SetSpeedRate(MOVE_WALK
, ASpeed
,true);
1140 chr
->SetSpeedRate(MOVE_RUN
, ASpeed
,true);
1141 chr
->SetSpeedRate(MOVE_SWIM
, ASpeed
,true);
1142 //chr->SetSpeed(MOVE_TURN, ASpeed,true);
1143 chr
->SetSpeedRate(MOVE_FLIGHT
, ASpeed
,true);
1148 bool ChatHandler::HandleModifySpeedCommand(const char* args
)
1153 float Speed
= (float)atof((char*)args
);
1155 if (Speed
> 10 || Speed
< 0.1)
1157 SendSysMessage(LANG_BAD_VALUE
);
1158 SetSentErrorMessage(true);
1162 Player
*chr
= getSelectedPlayer();
1165 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1166 SetSentErrorMessage(true);
1170 // check online security
1171 if (HasLowerSecurity(chr
, 0))
1174 std::string chrNameLink
= GetNameLink(chr
);
1176 if(chr
->isInFlight())
1178 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chrNameLink
.c_str());
1179 SetSentErrorMessage(true);
1183 PSendSysMessage(LANG_YOU_CHANGE_SPEED
, Speed
, chrNameLink
.c_str());
1184 if (needReportToTarget(chr
))
1185 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_SPEED_CHANGED
, GetNameLink().c_str(), Speed
);
1187 chr
->SetSpeedRate(MOVE_RUN
,Speed
,true);
1192 //Edit Player Swim Speed
1193 bool ChatHandler::HandleModifySwimCommand(const char* args
)
1198 float Swim
= (float)atof((char*)args
);
1200 if (Swim
> 10.0f
|| Swim
< 0.01f
)
1202 SendSysMessage(LANG_BAD_VALUE
);
1203 SetSentErrorMessage(true);
1207 Player
*chr
= getSelectedPlayer();
1210 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1211 SetSentErrorMessage(true);
1215 // check online security
1216 if (HasLowerSecurity(chr
, 0))
1219 std::string chrNameLink
= GetNameLink(chr
);
1221 if(chr
->isInFlight())
1223 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chrNameLink
.c_str());
1224 SetSentErrorMessage(true);
1228 PSendSysMessage(LANG_YOU_CHANGE_SWIM_SPEED
, Swim
, chrNameLink
.c_str());
1229 if (needReportToTarget(chr
))
1230 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_SWIM_SPEED_CHANGED
, GetNameLink().c_str(), Swim
);
1232 chr
->SetSpeedRate(MOVE_SWIM
,Swim
,true);
1237 //Edit Player Walk Speed
1238 bool ChatHandler::HandleModifyBWalkCommand(const char* args
)
1243 float BSpeed
= (float)atof((char*)args
);
1245 if (BSpeed
> 10.0f
|| BSpeed
< 0.1f
)
1247 SendSysMessage(LANG_BAD_VALUE
);
1248 SetSentErrorMessage(true);
1252 Player
*chr
= getSelectedPlayer();
1255 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1256 SetSentErrorMessage(true);
1260 // check online security
1261 if (HasLowerSecurity(chr
, 0))
1264 std::string chrNameLink
= GetNameLink(chr
);
1266 if(chr
->isInFlight())
1268 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chrNameLink
.c_str());
1269 SetSentErrorMessage(true);
1273 PSendSysMessage(LANG_YOU_CHANGE_BACK_SPEED
, BSpeed
, chrNameLink
.c_str());
1274 if (needReportToTarget(chr
))
1275 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_BACK_SPEED_CHANGED
, GetNameLink().c_str(), BSpeed
);
1277 chr
->SetSpeedRate(MOVE_RUN_BACK
,BSpeed
,true);
1283 bool ChatHandler::HandleModifyFlyCommand(const char* args
)
1288 float FSpeed
= (float)atof((char*)args
);
1290 if (FSpeed
> 10.0f
|| FSpeed
< 0.1f
)
1292 SendSysMessage(LANG_BAD_VALUE
);
1293 SetSentErrorMessage(true);
1297 Player
*chr
= getSelectedPlayer();
1300 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1301 SetSentErrorMessage(true);
1305 // check online security
1306 if (HasLowerSecurity(chr
, 0))
1309 PSendSysMessage(LANG_YOU_CHANGE_FLY_SPEED
, FSpeed
, GetNameLink(chr
).c_str());
1310 if (needReportToTarget(chr
))
1311 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_FLY_SPEED_CHANGED
, GetNameLink().c_str(), FSpeed
);
1313 chr
->SetSpeedRate(MOVE_FLIGHT
,FSpeed
,true);
1319 bool ChatHandler::HandleModifyScaleCommand(const char* args
)
1324 float Scale
= (float)atof((char*)args
);
1325 if (Scale
> 10.0f
|| Scale
<= 0.0f
)
1327 SendSysMessage(LANG_BAD_VALUE
);
1328 SetSentErrorMessage(true);
1332 Unit
*target
= getSelectedUnit();
1335 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
1336 SetSentErrorMessage(true);
1340 if (target
->GetTypeId()==TYPEID_PLAYER
)
1342 // check online security
1343 if (HasLowerSecurity((Player
*)target
, 0))
1346 PSendSysMessage(LANG_YOU_CHANGE_SIZE
, Scale
, GetNameLink((Player
*)target
).c_str());
1347 if (needReportToTarget((Player
*)target
))
1348 ChatHandler((Player
*)target
).PSendSysMessage(LANG_YOURS_SIZE_CHANGED
, GetNameLink().c_str(), Scale
);
1351 target
->SetFloatValue(OBJECT_FIELD_SCALE_X
, Scale
);
1356 //Enable Player mount
1357 bool ChatHandler::HandleModifyMountCommand(const char* args
)
1363 float speed
= (float)15;
1366 num
= atoi((char*)args
);
1577 SendSysMessage(LANG_NO_MOUNT
);
1578 SetSentErrorMessage(true);
1582 Player
*chr
= getSelectedPlayer();
1585 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1586 SetSentErrorMessage(true);
1590 // check online security
1591 if (HasLowerSecurity(chr
, 0))
1594 PSendSysMessage(LANG_YOU_GIVE_MOUNT
, GetNameLink(chr
).c_str());
1595 if (needReportToTarget(chr
))
1596 ChatHandler(chr
).PSendSysMessage(LANG_MOUNT_GIVED
, GetNameLink().c_str());
1598 chr
->SetUInt32Value(UNIT_FIELD_FLAGS
, UNIT_FLAG_PVP
);
1601 WorldPacket
data( SMSG_FORCE_RUN_SPEED_CHANGE
, (8+4+1+4) );
1602 data
.append(chr
->GetPackGUID());
1604 data
<< (uint8
)0; //new 2.1.0
1605 data
<< float(speed
);
1606 chr
->SendMessageToSet( &data
, true );
1608 data
.Initialize( SMSG_FORCE_SWIM_SPEED_CHANGE
, (8+4+4) );
1609 data
.append(chr
->GetPackGUID());
1611 data
<< float(speed
);
1612 chr
->SendMessageToSet( &data
, true );
1618 bool ChatHandler::HandleModifyMoneyCommand(const char* args
)
1623 Player
*chr
= getSelectedPlayer();
1626 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1627 SetSentErrorMessage(true);
1631 // check online security
1632 if (HasLowerSecurity(chr
, 0))
1635 int32 addmoney
= atoi((char*)args
);
1637 uint32 moneyuser
= chr
->GetMoney();
1641 int32 newmoney
= int32(moneyuser
) + addmoney
;
1643 sLog
.outDetail(GetMangosString(LANG_CURRENT_MONEY
), moneyuser
, addmoney
, newmoney
);
1646 PSendSysMessage(LANG_YOU_TAKE_ALL_MONEY
, GetNameLink(chr
).c_str());
1647 if (needReportToTarget(chr
))
1648 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_ALL_MONEY_GONE
, GetNameLink().c_str());
1654 if (newmoney
> MAX_MONEY_AMOUNT
)
1655 newmoney
= MAX_MONEY_AMOUNT
;
1657 PSendSysMessage(LANG_YOU_TAKE_MONEY
, abs(addmoney
), GetNameLink(chr
).c_str());
1658 if (needReportToTarget(chr
))
1659 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_MONEY_TAKEN
, GetNameLink().c_str(), abs(addmoney
));
1660 chr
->SetMoney( newmoney
);
1665 PSendSysMessage(LANG_YOU_GIVE_MONEY
, addmoney
, GetNameLink(chr
).c_str());
1666 if (needReportToTarget(chr
))
1667 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_MONEY_GIVEN
, GetNameLink().c_str(), addmoney
);
1669 if (addmoney
>=MAX_MONEY_AMOUNT
)
1670 chr
->SetMoney(MAX_MONEY_AMOUNT
);
1672 chr
->ModifyMoney( addmoney
);
1675 sLog
.outDetail(GetMangosString(LANG_NEW_MONEY
), moneyuser
, addmoney
, chr
->GetMoney() );
1681 bool ChatHandler::HandleModifyBitCommand(const char* args
)
1686 Unit
*unit
= getSelectedUnit();
1689 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1690 SetSentErrorMessage(true);
1694 // check online security
1695 if (unit
->GetTypeId() == TYPEID_PLAYER
&& HasLowerSecurity((Player
*)unit
, 0))
1698 char* pField
= strtok((char*)args
, " ");
1702 char* pBit
= strtok(NULL
, " ");
1706 uint16 field
= atoi(pField
);
1707 uint32 bit
= atoi(pBit
);
1709 if (field
< OBJECT_END
|| field
>= unit
->GetValuesCount())
1711 SendSysMessage(LANG_BAD_VALUE
);
1712 SetSentErrorMessage(true);
1715 if (bit
< 1 || bit
> 32)
1717 SendSysMessage(LANG_BAD_VALUE
);
1718 SetSentErrorMessage(true);
1722 if ( unit
->HasFlag( field
, (1<<(bit
-1)) ) )
1724 unit
->RemoveFlag( field
, (1<<(bit
-1)) );
1725 PSendSysMessage(LANG_REMOVE_BIT
, bit
, field
);
1729 unit
->SetFlag( field
, (1<<(bit
-1)) );
1730 PSendSysMessage(LANG_SET_BIT
, bit
, field
);
1735 bool ChatHandler::HandleModifyHonorCommand (const char* args
)
1740 Player
*target
= getSelectedPlayer();
1743 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1744 SetSentErrorMessage(true);
1748 // check online security
1749 if (HasLowerSecurity(target
, 0))
1752 int32 amount
= (uint32
)atoi(args
);
1754 target
->ModifyHonorPoints(amount
);
1756 PSendSysMessage(LANG_COMMAND_MODIFY_HONOR
, GetNameLink(target
).c_str(), target
->GetHonorPoints());
1761 bool ChatHandler::HandleTeleCommand(const char * args
)
1766 Player
* _player
= m_session
->GetPlayer();
1768 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
1769 GameTele
const* tele
= extractGameTeleFromLink((char*)args
);
1773 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
1774 SetSentErrorMessage(true);
1778 // stop flight if need
1779 if(_player
->isInFlight())
1781 _player
->GetMotionMaster()->MovementExpired();
1782 _player
->m_taxi
.ClearTaxiDestinations();
1784 // save only in non-flight case
1786 _player
->SaveRecallPosition();
1788 _player
->TeleportTo(tele
->mapId
, tele
->position_x
, tele
->position_y
, tele
->position_z
, tele
->orientation
);
1792 bool ChatHandler::HandleLookupAreaCommand(const char* args
)
1797 std::string namepart
= args
;
1798 std::wstring wnamepart
;
1800 if (!Utf8toWStr (namepart
,wnamepart
))
1803 uint32 counter
= 0; // Counter for figure out that we found smth.
1805 // converting string that we try to find to lower case
1806 wstrToLower (wnamepart
);
1808 // Search in AreaTable.dbc
1809 for (uint32 areaflag
= 0; areaflag
< sAreaStore
.GetNumRows (); ++areaflag
)
1811 AreaTableEntry
const *areaEntry
= sAreaStore
.LookupEntry (areaflag
);
1814 int loc
= GetSessionDbcLocale ();
1815 std::string name
= areaEntry
->area_name
[loc
];
1819 if (!Utf8FitTo (name
, wnamepart
))
1822 for(; loc
< MAX_LOCALE
; ++loc
)
1824 if (loc
==GetSessionDbcLocale ())
1827 name
= areaEntry
->area_name
[loc
];
1831 if (Utf8FitTo (name
, wnamepart
))
1836 if (loc
< MAX_LOCALE
)
1838 // send area in "id - [name]" format
1839 std::ostringstream ss
;
1841 ss
<< areaEntry
->ID
<< " - |cffffffff|Harea:" << areaEntry
->ID
<< "|h[" << name
<< " " << localeNames
[loc
]<< "]|h|r";
1843 ss
<< areaEntry
->ID
<< " - " << name
<< " " << localeNames
[loc
];
1845 SendSysMessage (ss
.str ().c_str());
1852 if (counter
== 0) // if counter == 0 then we found nth
1853 SendSysMessage (LANG_COMMAND_NOAREAFOUND
);
1858 //Find tele in game_tele order by name
1859 bool ChatHandler::HandleLookupTeleCommand(const char * args
)
1863 SendSysMessage(LANG_COMMAND_TELE_PARAMETER
);
1864 SetSentErrorMessage(true);
1868 char const* str
= strtok((char*)args
, " ");
1872 std::string namepart
= str
;
1873 std::wstring wnamepart
;
1875 if(!Utf8toWStr(namepart
,wnamepart
))
1878 // converting string that we try to find to lower case
1879 wstrToLower( wnamepart
);
1881 std::ostringstream reply
;
1883 GameTeleMap
const & teleMap
= sObjectMgr
.GetGameTeleMap();
1884 for(GameTeleMap::const_iterator itr
= teleMap
.begin(); itr
!= teleMap
.end(); ++itr
)
1886 GameTele
const* tele
= &itr
->second
;
1888 if(tele
->wnameLow
.find(wnamepart
) == std::wstring::npos
)
1892 reply
<< " |cffffffff|Htele:" << itr
->first
<< "|h[" << tele
->name
<< "]|h|r\n";
1894 reply
<< " " << itr
->first
<< " " << tele
->name
<< "\n";
1897 if(reply
.str().empty())
1898 SendSysMessage(LANG_COMMAND_TELE_NOLOCATION
);
1900 PSendSysMessage(LANG_COMMAND_TELE_LOCATION
,reply
.str().c_str());
1905 //Enable\Dissable accept whispers (for GM)
1906 bool ChatHandler::HandleWhispersCommand(const char* args
)
1910 PSendSysMessage(LANG_COMMAND_WHISPERACCEPTING
, m_session
->GetPlayer()->isAcceptWhispers() ? GetMangosString(LANG_ON
) : GetMangosString(LANG_OFF
));
1914 std::string argstr
= (char*)args
;
1918 m_session
->GetPlayer()->SetAcceptWhispers(true);
1919 SendSysMessage(LANG_COMMAND_WHISPERON
);
1924 if (argstr
== "off")
1926 m_session
->GetPlayer()->SetAcceptWhispers(false);
1927 SendSysMessage(LANG_COMMAND_WHISPEROFF
);
1931 SendSysMessage(LANG_USE_BOL
);
1932 SetSentErrorMessage(true);
1936 //Save all players in the world
1937 bool ChatHandler::HandleSaveAllCommand(const char* /*args*/)
1939 sObjectAccessor
.SaveAllPlayers();
1940 SendSysMessage(LANG_PLAYERS_SAVED
);
1944 //Send mail by command
1945 bool ChatHandler::HandleSendMailCommand(const char* args
)
1947 // format: name "subject text" "mail text"
1950 std::string target_name
;
1951 if(!extractPlayerTarget((char*)args
,&target
,&target_guid
,&target_name
))
1954 char* tail1
= strtok(NULL
, "");
1958 char* msgSubject
= extractQuotedArg(tail1
);
1962 char* tail2
= strtok(NULL
, "");
1966 char* msgText
= extractQuotedArg(tail2
);
1970 // msgSubject, msgText isn't NUL after prev. check
1971 std::string subject
= msgSubject
;
1972 std::string text
= msgText
;
1974 // from console show not existed sender
1975 MailSender
sender(MAIL_NORMAL
,m_session
? m_session
->GetPlayer()->GetGUIDLow() : 0, MAIL_STATIONERY_GM
);
1977 uint32 itemTextId
= !text
.empty() ? sObjectMgr
.CreateItemText( text
) : 0;
1979 MailDraft(subject
, itemTextId
)
1980 .SendMailTo(MailReceiver(target
,GUID_LOPART(target_guid
)),sender
);
1982 std::string nameLink
= playerLink(target_name
);
1983 PSendSysMessage(LANG_MAIL_SENT
, nameLink
.c_str());
1987 // teleport player to given game_tele.entry
1988 bool ChatHandler::HandleTeleNameCommand(const char * args
)
1992 extractOptFirstArg((char*)args
,&nameStr
,&teleStr
);
1998 std::string target_name
;
1999 if(!extractPlayerTarget(nameStr
,&target
,&target_guid
,&target_name
))
2002 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2003 GameTele
const* tele
= extractGameTeleFromLink(teleStr
);
2006 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
2007 SetSentErrorMessage(true);
2013 // check online security
2014 if (HasLowerSecurity(target
, 0))
2017 std::string chrNameLink
= playerLink(target_name
);
2019 if(target
->IsBeingTeleported()==true)
2021 PSendSysMessage(LANG_IS_TELEPORTED
, chrNameLink
.c_str());
2022 SetSentErrorMessage(true);
2026 PSendSysMessage(LANG_TELEPORTING_TO
, chrNameLink
.c_str(),"", tele
->name
.c_str());
2027 if (needReportToTarget(target
))
2028 ChatHandler(target
).PSendSysMessage(LANG_TELEPORTED_TO_BY
, GetNameLink().c_str());
2030 // stop flight if need
2031 if(target
->isInFlight())
2033 target
->GetMotionMaster()->MovementExpired();
2034 target
->m_taxi
.ClearTaxiDestinations();
2036 // save only in non-flight case
2038 target
->SaveRecallPosition();
2040 target
->TeleportTo(tele
->mapId
,tele
->position_x
,tele
->position_y
,tele
->position_z
,tele
->orientation
);
2044 // check offline security
2045 if (HasLowerSecurity(NULL
, target_guid
))
2048 std::string nameLink
= playerLink(target_name
);
2050 PSendSysMessage(LANG_TELEPORTING_TO
, nameLink
.c_str(), GetMangosString(LANG_OFFLINE
), tele
->name
.c_str());
2051 Player::SavePositionInDB(tele
->mapId
,tele
->position_x
,tele
->position_y
,tele
->position_z
,tele
->orientation
,
2052 sMapMgr
.GetZoneId(tele
->mapId
,tele
->position_x
,tele
->position_y
,tele
->position_z
),target_guid
);
2058 //Teleport group to given game_tele.entry
2059 bool ChatHandler::HandleTeleGroupCommand(const char * args
)
2064 Player
*player
= getSelectedPlayer();
2067 SendSysMessage(LANG_NO_CHAR_SELECTED
);
2068 SetSentErrorMessage(true);
2072 // check online security
2073 if (HasLowerSecurity(player
, 0))
2076 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2077 GameTele
const* tele
= extractGameTeleFromLink((char*)args
);
2080 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
2081 SetSentErrorMessage(true);
2085 std::string nameLink
= GetNameLink(player
);
2087 Group
*grp
= player
->GetGroup();
2090 PSendSysMessage(LANG_NOT_IN_GROUP
,nameLink
.c_str());
2091 SetSentErrorMessage(true);
2095 for(GroupReference
*itr
= grp
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
2097 Player
*pl
= itr
->getSource();
2099 if(!pl
|| !pl
->GetSession() )
2102 // check online security
2103 if (HasLowerSecurity(pl
, 0))
2106 std::string plNameLink
= GetNameLink(pl
);
2108 if(pl
->IsBeingTeleported())
2110 PSendSysMessage(LANG_IS_TELEPORTED
, plNameLink
.c_str());
2114 PSendSysMessage(LANG_TELEPORTING_TO
, plNameLink
.c_str(),"", tele
->name
.c_str());
2115 if (needReportToTarget(pl
))
2116 ChatHandler(pl
).PSendSysMessage(LANG_TELEPORTED_TO_BY
, nameLink
.c_str());
2118 // stop flight if need
2119 if(pl
->isInFlight())
2121 pl
->GetMotionMaster()->MovementExpired();
2122 pl
->m_taxi
.ClearTaxiDestinations();
2124 // save only in non-flight case
2126 pl
->SaveRecallPosition();
2128 pl
->TeleportTo(tele
->mapId
, tele
->position_x
, tele
->position_y
, tele
->position_z
, tele
->orientation
);
2134 //Summon group of player
2135 bool ChatHandler::HandleGroupgoCommand(const char* args
)
2138 if(!extractPlayerTarget((char*)args
,&target
))
2141 // check online security
2142 if (HasLowerSecurity(target
, 0))
2145 Group
*grp
= target
->GetGroup();
2147 std::string nameLink
= GetNameLink(target
);
2151 PSendSysMessage(LANG_NOT_IN_GROUP
,nameLink
.c_str());
2152 SetSentErrorMessage(true);
2156 Map
* gmMap
= m_session
->GetPlayer()->GetMap();
2157 bool to_instance
= gmMap
->Instanceable();
2159 // we are in instance, and can summon only player in our group with us as lead
2160 if ( to_instance
&& (
2161 !m_session
->GetPlayer()->GetGroup() || (grp
->GetLeaderGUID() != m_session
->GetPlayer()->GetGUID()) ||
2162 (m_session
->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session
->GetPlayer()->GetGUID()) ) )
2163 // the last check is a bit excessive, but let it be, just in case
2165 SendSysMessage(LANG_CANNOT_SUMMON_TO_INST
);
2166 SetSentErrorMessage(true);
2170 for(GroupReference
*itr
= grp
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
2172 Player
*pl
= itr
->getSource();
2174 if(!pl
|| pl
==m_session
->GetPlayer() || !pl
->GetSession() )
2177 // check online security
2178 if (HasLowerSecurity(pl
, 0))
2181 std::string plNameLink
= GetNameLink(pl
);
2183 if(pl
->IsBeingTeleported()==true)
2185 PSendSysMessage(LANG_IS_TELEPORTED
, plNameLink
.c_str());
2186 SetSentErrorMessage(true);
2192 Map
* plMap
= pl
->GetMap();
2194 if ( plMap
->Instanceable() && plMap
->GetInstanceId() != gmMap
->GetInstanceId() )
2196 // cannot summon from instance to instance
2197 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST
,plNameLink
.c_str());
2198 SetSentErrorMessage(true);
2203 PSendSysMessage(LANG_SUMMONING
, plNameLink
.c_str(),"");
2204 if (needReportToTarget(pl
))
2205 ChatHandler(pl
).PSendSysMessage(LANG_SUMMONED_BY
, nameLink
.c_str());
2207 // stop flight if need
2208 if(pl
->isInFlight())
2210 pl
->GetMotionMaster()->MovementExpired();
2211 pl
->m_taxi
.ClearTaxiDestinations();
2213 // save only in non-flight case
2215 pl
->SaveRecallPosition();
2219 m_session
->GetPlayer()->GetClosePoint(x
,y
,z
,pl
->GetObjectSize());
2220 pl
->TeleportTo(m_session
->GetPlayer()->GetMapId(),x
,y
,z
,pl
->GetOrientation());
2226 bool ChatHandler::HandleGoTaxinodeCommand(const char* args
)
2228 Player
* _player
= m_session
->GetPlayer();
2233 char* cNodeId
= extractKeyFromLink((char*)args
,"Htaxinode");
2237 int32 i_nodeId
= atoi(cNodeId
);
2241 TaxiNodesEntry
const* node
= sTaxiNodesStore
.LookupEntry(i_nodeId
);
2244 PSendSysMessage(LANG_COMMAND_GOTAXINODENOTFOUND
,i_nodeId
);
2245 SetSentErrorMessage(true);
2249 if ((node
->x
== 0.0f
&& node
->y
== 0.0f
&& node
->z
== 0.0f
) ||
2250 !MapManager::IsValidMapCoord(node
->map_id
,node
->x
,node
->y
,node
->z
))
2252 PSendSysMessage(LANG_INVALID_TARGET_COORD
,node
->x
,node
->y
,node
->map_id
);
2253 SetSentErrorMessage(true);
2257 // stop flight if need
2258 if (_player
->isInFlight())
2260 _player
->GetMotionMaster()->MovementExpired();
2261 _player
->m_taxi
.ClearTaxiDestinations();
2263 // save only in non-flight case
2265 _player
->SaveRecallPosition();
2267 _player
->TeleportTo(node
->map_id
, node
->x
, node
->y
, node
->z
, _player
->GetOrientation());
2271 //teleport at coordinates
2272 bool ChatHandler::HandleGoXYCommand(const char* args
)
2277 Player
* _player
= m_session
->GetPlayer();
2279 char* px
= strtok((char*)args
, " ");
2280 char* py
= strtok(NULL
, " ");
2281 char* pmapid
= strtok(NULL
, " ");
2286 float x
= (float)atof(px
);
2287 float y
= (float)atof(py
);
2290 mapid
= (uint32
)atoi(pmapid
);
2291 else mapid
= _player
->GetMapId();
2293 if(!MapManager::IsValidMapCoord(mapid
,x
,y
))
2295 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,mapid
);
2296 SetSentErrorMessage(true);
2300 // stop flight if need
2301 if(_player
->isInFlight())
2303 _player
->GetMotionMaster()->MovementExpired();
2304 _player
->m_taxi
.ClearTaxiDestinations();
2306 // save only in non-flight case
2308 _player
->SaveRecallPosition();
2310 Map
const *map
= sMapMgr
.CreateBaseMap(mapid
);
2311 float z
= std::max(map
->GetHeight(x
, y
, MAX_HEIGHT
), map
->GetWaterLevel(x
, y
));
2313 _player
->TeleportTo(mapid
, x
, y
, z
, _player
->GetOrientation());
2318 //teleport at coordinates, including Z
2319 bool ChatHandler::HandleGoXYZCommand(const char* args
)
2324 Player
* _player
= m_session
->GetPlayer();
2326 char* px
= strtok((char*)args
, " ");
2327 char* py
= strtok(NULL
, " ");
2328 char* pz
= strtok(NULL
, " ");
2329 char* pmapid
= strtok(NULL
, " ");
2331 if (!px
|| !py
|| !pz
)
2334 float x
= (float)atof(px
);
2335 float y
= (float)atof(py
);
2336 float z
= (float)atof(pz
);
2339 mapid
= (uint32
)atoi(pmapid
);
2341 mapid
= _player
->GetMapId();
2343 if(!MapManager::IsValidMapCoord(mapid
,x
,y
,z
))
2345 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,mapid
);
2346 SetSentErrorMessage(true);
2350 // stop flight if need
2351 if(_player
->isInFlight())
2353 _player
->GetMotionMaster()->MovementExpired();
2354 _player
->m_taxi
.ClearTaxiDestinations();
2356 // save only in non-flight case
2358 _player
->SaveRecallPosition();
2360 _player
->TeleportTo(mapid
, x
, y
, z
, _player
->GetOrientation());
2365 //teleport at coordinates
2366 bool ChatHandler::HandleGoZoneXYCommand(const char* args
)
2371 Player
* _player
= m_session
->GetPlayer();
2373 char* px
= strtok((char*)args
, " ");
2374 char* py
= strtok(NULL
, " ");
2375 char* tail
= strtok(NULL
,"");
2377 char* cAreaId
= extractKeyFromLink(tail
,"Harea"); // string or [name] Shift-click form |color|Harea:area_id|h[name]|h|r
2382 float x
= (float)atof(px
);
2383 float y
= (float)atof(py
);
2385 // prevent accept wrong numeric args
2386 if ((x
==0.0f
&& *px
!='0') || (y
==0.0f
&& *py
!='0'))
2389 uint32 areaid
= cAreaId
? (uint32
)atoi(cAreaId
) : _player
->GetZoneId();
2391 AreaTableEntry
const* areaEntry
= GetAreaEntryByAreaID(areaid
);
2393 if( x
<0 || x
>100 || y
<0 || y
>100 || !areaEntry
)
2395 PSendSysMessage(LANG_INVALID_ZONE_COORD
,x
,y
,areaid
);
2396 SetSentErrorMessage(true);
2400 // update to parent zone if exist (client map show only zones without parents)
2401 AreaTableEntry
const* zoneEntry
= areaEntry
->zone
? GetAreaEntryByAreaID(areaEntry
->zone
) : areaEntry
;
2403 Map
const *map
= sMapMgr
.CreateBaseMap(zoneEntry
->mapid
);
2405 if(map
->Instanceable())
2407 PSendSysMessage(LANG_INVALID_ZONE_MAP
,areaEntry
->ID
,areaEntry
->area_name
[GetSessionDbcLocale()],map
->GetId(),map
->GetMapName());
2408 SetSentErrorMessage(true);
2412 Zone2MapCoordinates(x
,y
,zoneEntry
->ID
);
2414 if(!MapManager::IsValidMapCoord(zoneEntry
->mapid
,x
,y
))
2416 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,zoneEntry
->mapid
);
2417 SetSentErrorMessage(true);
2421 // stop flight if need
2422 if(_player
->isInFlight())
2424 _player
->GetMotionMaster()->MovementExpired();
2425 _player
->m_taxi
.ClearTaxiDestinations();
2427 // save only in non-flight case
2429 _player
->SaveRecallPosition();
2431 float z
= std::max(map
->GetHeight(x
, y
, MAX_HEIGHT
), map
->GetWaterLevel(x
, y
));
2432 _player
->TeleportTo(zoneEntry
->mapid
, x
, y
, z
, _player
->GetOrientation());
2438 bool ChatHandler::HandleGoGridCommand(const char* args
)
2440 if(!*args
) return false;
2441 Player
* _player
= m_session
->GetPlayer();
2443 char* px
= strtok((char*)args
, " ");
2444 char* py
= strtok(NULL
, " ");
2445 char* pmapid
= strtok(NULL
, " ");
2450 float grid_x
= (float)atof(px
);
2451 float grid_y
= (float)atof(py
);
2454 mapid
= (uint32
)atoi(pmapid
);
2455 else mapid
= _player
->GetMapId();
2458 float x
= (grid_x
-CENTER_GRID_ID
+0.5f
)*SIZE_OF_GRIDS
;
2459 float y
= (grid_y
-CENTER_GRID_ID
+0.5f
)*SIZE_OF_GRIDS
;
2461 if(!MapManager::IsValidMapCoord(mapid
,x
,y
))
2463 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,mapid
);
2464 SetSentErrorMessage(true);
2468 // stop flight if need
2469 if(_player
->isInFlight())
2471 _player
->GetMotionMaster()->MovementExpired();
2472 _player
->m_taxi
.ClearTaxiDestinations();
2474 // save only in non-flight case
2476 _player
->SaveRecallPosition();
2478 Map
const *map
= sMapMgr
.CreateBaseMap(mapid
);
2479 float z
= std::max(map
->GetHeight(x
, y
, MAX_HEIGHT
), map
->GetWaterLevel(x
, y
));
2480 _player
->TeleportTo(mapid
, x
, y
, z
, _player
->GetOrientation());
2485 bool ChatHandler::HandleModifyDrunkCommand(const char* args
)
2487 if(!*args
) return false;
2489 uint32 drunklevel
= (uint32
)atoi(args
);
2490 if(drunklevel
> 100)
2493 uint16 drunkMod
= drunklevel
* 0xFFFF / 100;
2495 m_session
->GetPlayer()->SetDrunkValue(drunkMod
);