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
*)m_session
->GetPlayer()->GetObjectByTypeMask(guid
, TYPEMASK_CREATURE_OR_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 if (!Map2ZoneCoordinates(zone_x
, zone_y
, zone_id
))
303 Map
const *map
= obj
->GetMap();
304 float ground_z
= map
->GetHeight(obj
->GetPositionX(), obj
->GetPositionY(), MAX_HEIGHT
);
305 float floor_z
= map
->GetHeight(obj
->GetPositionX(), obj
->GetPositionY(), obj
->GetPositionZ());
307 GridPair p
= MaNGOS::ComputeGridPair(obj
->GetPositionX(), obj
->GetPositionY());
312 uint32 have_map
= Map::ExistMap(obj
->GetMapId(),gx
,gy
) ? 1 : 0;
313 uint32 have_vmap
= Map::ExistVMap(obj
->GetMapId(),gx
,gy
) ? 1 : 0;
315 PSendSysMessage(LANG_MAP_POSITION
,
316 obj
->GetMapId(), (mapEntry
? mapEntry
->name
[GetSessionDbcLocale()] : "<unknown>" ),
317 zone_id
, (zoneEntry
? zoneEntry
->area_name
[GetSessionDbcLocale()] : "<unknown>" ),
318 area_id
, (areaEntry
? areaEntry
->area_name
[GetSessionDbcLocale()] : "<unknown>" ),
320 obj
->GetPositionX(), obj
->GetPositionY(), obj
->GetPositionZ(), obj
->GetOrientation(),
321 cell
.GridX(), cell
.GridY(), cell
.CellX(), cell
.CellY(), obj
->GetInstanceId(),
322 zone_x
, zone_y
, ground_z
, floor_z
, have_map
, have_vmap
);
324 sLog
.outDebug("Player %s GPS call for %s '%s' (%s: %u):",
325 m_session
? GetNameLink().c_str() : GetMangosString(LANG_CONSOLE_COMMAND
),
326 (obj
->GetTypeId() == TYPEID_PLAYER
? "player" : "creature"), obj
->GetName(),
327 (obj
->GetTypeId() == TYPEID_PLAYER
? "GUID" : "Entry"), (obj
->GetTypeId() == TYPEID_PLAYER
? obj
->GetGUIDLow(): obj
->GetEntry()) );
329 sLog
.outDebug(GetMangosString(LANG_MAP_POSITION
),
330 obj
->GetMapId(), (mapEntry
? mapEntry
->name
[sWorld
.GetDefaultDbcLocale()] : "<unknown>" ),
331 zone_id
, (zoneEntry
? zoneEntry
->area_name
[sWorld
.GetDefaultDbcLocale()] : "<unknown>" ),
332 area_id
, (areaEntry
? areaEntry
->area_name
[sWorld
.GetDefaultDbcLocale()] : "<unknown>" ),
334 obj
->GetPositionX(), obj
->GetPositionY(), obj
->GetPositionZ(), obj
->GetOrientation(),
335 cell
.GridX(), cell
.GridY(), cell
.CellX(), cell
.CellY(), obj
->GetInstanceId(),
336 zone_x
, zone_y
, ground_z
, floor_z
, have_map
, have_vmap
);
338 LiquidData liquid_status
;
339 ZLiquidStatus res
= map
->getLiquidStatus(obj
->GetPositionX(), obj
->GetPositionY(), obj
->GetPositionZ(), MAP_ALL_LIQUIDS
, &liquid_status
);
342 PSendSysMessage(LANG_LIQUID_STATUS
, liquid_status
.level
, liquid_status
.depth_level
, liquid_status
.type
, res
);
348 bool ChatHandler::HandleNamegoCommand(const char* args
)
352 std::string target_name
;
353 if (!extractPlayerTarget((char*)args
,&target
,&target_guid
,&target_name
))
356 Player
* _player
= m_session
->GetPlayer();
357 if (target
== _player
|| target_guid
== _player
->GetGUID())
359 PSendSysMessage(LANG_CANT_TELEPORT_SELF
);
360 SetSentErrorMessage(true);
366 std::string nameLink
= playerLink(target_name
);
367 // check online security
368 if (HasLowerSecurity(target
, 0))
371 if (target
->IsBeingTeleported())
373 PSendSysMessage(LANG_IS_TELEPORTED
, nameLink
.c_str());
374 SetSentErrorMessage(true);
378 Map
* pMap
= m_session
->GetPlayer()->GetMap();
380 if (pMap
->IsBattleGroundOrArena())
382 // only allow if gm mode is on
383 if (!target
->isGameMaster())
385 PSendSysMessage(LANG_CANNOT_GO_TO_BG_GM
,nameLink
.c_str());
386 SetSentErrorMessage(true);
389 // if both players are in different bgs
390 else if (target
->GetBattleGroundId() && m_session
->GetPlayer()->GetBattleGroundId() != target
->GetBattleGroundId())
392 PSendSysMessage(LANG_CANNOT_GO_TO_BG_FROM_BG
,nameLink
.c_str());
393 SetSentErrorMessage(true);
396 // all's well, set bg id
397 // when porting out from the bg, it will be reset to 0
398 target
->SetBattleGroundId(m_session
->GetPlayer()->GetBattleGroundId(), m_session
->GetPlayer()->GetBattleGroundTypeId());
399 // remember current position as entry point for return at bg end teleportation
400 if (!target
->GetMap()->IsBattleGroundOrArena())
401 target
->SetBattleGroundEntryPoint();
403 else if (pMap
->IsDungeon())
405 Map
* cMap
= target
->GetMap();
406 if (cMap
->Instanceable() && cMap
->GetInstanceId() != pMap
->GetInstanceId())
408 // cannot summon from instance to instance
409 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST
,nameLink
.c_str());
410 SetSentErrorMessage(true);
414 // we are in instance, and can summon only player in our group with us as lead
415 if (!m_session
->GetPlayer()->GetGroup() || !target
->GetGroup() ||
416 (target
->GetGroup()->GetLeaderGUID() != m_session
->GetPlayer()->GetGUID()) ||
417 (m_session
->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session
->GetPlayer()->GetGUID()))
418 // the last check is a bit excessive, but let it be, just in case
420 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST
,nameLink
.c_str());
421 SetSentErrorMessage(true);
426 PSendSysMessage(LANG_SUMMONING
, nameLink
.c_str(),"");
427 if (needReportToTarget(target
))
428 ChatHandler(target
).PSendSysMessage(LANG_SUMMONED_BY
, playerLink(_player
->GetName()).c_str());
430 // stop flight if need
431 if (target
->isInFlight())
433 target
->GetMotionMaster()->MovementExpired();
434 target
->m_taxi
.ClearTaxiDestinations();
436 // save only in non-flight case
438 target
->SaveRecallPosition();
442 m_session
->GetPlayer()->GetClosePoint(x
,y
,z
,target
->GetObjectSize());
443 target
->TeleportTo(m_session
->GetPlayer()->GetMapId(),x
,y
,z
,target
->GetOrientation());
447 // check offline security
448 if (HasLowerSecurity(NULL
, target_guid
))
451 std::string nameLink
= playerLink(target_name
);
453 PSendSysMessage(LANG_SUMMONING
, nameLink
.c_str(),GetMangosString(LANG_OFFLINE
));
455 // in point where GM stay
456 Player::SavePositionInDB(m_session
->GetPlayer()->GetMapId(),
457 m_session
->GetPlayer()->GetPositionX(),
458 m_session
->GetPlayer()->GetPositionY(),
459 m_session
->GetPlayer()->GetPositionZ(),
460 m_session
->GetPlayer()->GetOrientation(),
461 m_session
->GetPlayer()->GetZoneId(),
469 bool ChatHandler::HandleGonameCommand(const char* args
)
473 std::string target_name
;
474 if (!extractPlayerTarget((char*)args
,&target
,&target_guid
,&target_name
))
477 Player
* _player
= m_session
->GetPlayer();
478 if (target
== _player
|| target_guid
== _player
->GetGUID())
480 SendSysMessage(LANG_CANT_TELEPORT_SELF
);
481 SetSentErrorMessage(true);
488 // check online security
489 if (HasLowerSecurity(target
, 0))
492 std::string chrNameLink
= playerLink(target_name
);
494 Map
* cMap
= target
->GetMap();
495 if (cMap
->IsBattleGroundOrArena())
497 // only allow if gm mode is on
498 if (!_player
->isGameMaster())
500 PSendSysMessage(LANG_CANNOT_GO_TO_BG_GM
,chrNameLink
.c_str());
501 SetSentErrorMessage(true);
504 // if both players are in different bgs
505 else if (_player
->GetBattleGroundId() && _player
->GetBattleGroundId() != target
->GetBattleGroundId())
507 PSendSysMessage(LANG_CANNOT_GO_TO_BG_FROM_BG
,chrNameLink
.c_str());
508 SetSentErrorMessage(true);
511 // all's well, set bg id
512 // when porting out from the bg, it will be reset to 0
513 _player
->SetBattleGroundId(target
->GetBattleGroundId(), target
->GetBattleGroundTypeId());
514 // remember current position as entry point for return at bg end teleportation
515 if (!_player
->GetMap()->IsBattleGroundOrArena())
516 _player
->SetBattleGroundEntryPoint();
518 else if(cMap
->IsDungeon())
520 // we have to go to instance, and can go to player only if:
521 // 1) we are in his group (either as leader or as member)
522 // 2) we are not bound to any group and have GM mode on
523 if (_player
->GetGroup())
525 // we are in group, we can go only if we are in the player group
526 if (_player
->GetGroup() != target
->GetGroup())
528 PSendSysMessage(LANG_CANNOT_GO_TO_INST_PARTY
,chrNameLink
.c_str());
529 SetSentErrorMessage(true);
535 // we are not in group, let's verify our GM mode
536 if (!_player
->isGameMaster())
538 PSendSysMessage(LANG_CANNOT_GO_TO_INST_GM
,chrNameLink
.c_str());
539 SetSentErrorMessage(true);
544 // if the player or the player's group is bound to another instance
545 // the player will not be bound to another one
546 InstancePlayerBind
*pBind
= _player
->GetBoundInstance(target
->GetMapId(), target
->GetDifficulty(cMap
->IsRaid()));
549 Group
*group
= _player
->GetGroup();
550 // if no bind exists, create a solo bind
551 InstanceGroupBind
*gBind
= group
? group
->GetBoundInstance(target
) : NULL
;
552 // if no bind exists, create a solo bind
554 if (InstanceSave
*save
= sInstanceSaveMgr
.GetInstanceSave(target
->GetInstanceId()))
555 _player
->BindToInstance(save
, !save
->CanReset());
559 _player
->SetRaidDifficulty(target
->GetRaidDifficulty());
561 _player
->SetDungeonDifficulty(target
->GetDungeonDifficulty());
564 PSendSysMessage(LANG_APPEARING_AT
, chrNameLink
.c_str());
565 if (needReportToTarget(target
))
566 ChatHandler(target
).PSendSysMessage(LANG_APPEARING_TO
, GetNameLink().c_str());
568 // stop flight if need
569 if (_player
->isInFlight())
571 _player
->GetMotionMaster()->MovementExpired();
572 _player
->m_taxi
.ClearTaxiDestinations();
574 // save only in non-flight case
576 _player
->SaveRecallPosition();
578 // to point to see at target with same orientation
580 target
->GetContactPoint(_player
,x
,y
,z
);
582 _player
->TeleportTo(target
->GetMapId(), x
, y
, z
, _player
->GetAngle(target
), TELE_TO_GM_MODE
);
586 // check offline security
587 if (HasLowerSecurity(NULL
, target_guid
))
590 std::string nameLink
= playerLink(target_name
);
592 PSendSysMessage(LANG_APPEARING_AT
, nameLink
.c_str());
594 // to point where player stay (if loaded)
598 if (!Player::LoadPositionFromDB(map
,x
,y
,z
,o
,in_flight
,target_guid
))
601 // stop flight if need
602 if (_player
->isInFlight())
604 _player
->GetMotionMaster()->MovementExpired();
605 _player
->m_taxi
.ClearTaxiDestinations();
607 // save only in non-flight case
609 _player
->SaveRecallPosition();
611 _player
->TeleportTo(map
, x
, y
, z
,_player
->GetOrientation());
617 // Teleport player to last position
618 bool ChatHandler::HandleRecallCommand(const char* args
)
621 if(!extractPlayerTarget((char*)args
,&target
))
624 // check online security
625 if (HasLowerSecurity(target
, 0))
628 if (target
->IsBeingTeleported())
630 PSendSysMessage(LANG_IS_TELEPORTED
, GetNameLink(target
).c_str());
631 SetSentErrorMessage(true);
635 // stop flight if need
636 if(target
->isInFlight())
638 target
->GetMotionMaster()->MovementExpired();
639 target
->m_taxi
.ClearTaxiDestinations();
642 target
->TeleportTo(target
->m_recallMap
, target
->m_recallX
, target
->m_recallY
, target
->m_recallZ
, target
->m_recallO
);
647 bool ChatHandler::HandleModifyHPCommand(const char* args
)
652 // char* pHp = strtok((char*)args, " ");
656 // char* pHpMax = strtok(NULL, " ");
660 // int32 hpm = atoi(pHpMax);
661 // int32 hp = atoi(pHp);
663 int32 hp
= atoi((char*)args
);
664 int32 hpm
= atoi((char*)args
);
666 if (hp
<= 0 || hpm
<= 0 || hpm
< hp
)
668 SendSysMessage(LANG_BAD_VALUE
);
669 SetSentErrorMessage(true);
673 Player
*chr
= getSelectedPlayer();
676 SendSysMessage(LANG_NO_CHAR_SELECTED
);
677 SetSentErrorMessage(true);
681 // check online security
682 if (HasLowerSecurity(chr
, 0))
685 PSendSysMessage(LANG_YOU_CHANGE_HP
, GetNameLink(chr
).c_str(), hp
, hpm
);
686 if (needReportToTarget(chr
))
687 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_HP_CHANGED
, GetNameLink().c_str(), hp
, hpm
);
689 chr
->SetMaxHealth( hpm
);
690 chr
->SetHealth( hp
);
696 bool ChatHandler::HandleModifyManaCommand(const char* args
)
701 // char* pmana = strtok((char*)args, " ");
705 // char* pmanaMax = strtok(NULL, " ");
709 // int32 manam = atoi(pmanaMax);
710 // int32 mana = atoi(pmana);
711 int32 mana
= atoi((char*)args
);
712 int32 manam
= atoi((char*)args
);
714 if (mana
<= 0 || manam
<= 0 || manam
< mana
)
716 SendSysMessage(LANG_BAD_VALUE
);
717 SetSentErrorMessage(true);
721 Player
*chr
= getSelectedPlayer();
724 SendSysMessage(LANG_NO_CHAR_SELECTED
);
725 SetSentErrorMessage(true);
729 // check online security
730 if (HasLowerSecurity(chr
, 0))
733 PSendSysMessage(LANG_YOU_CHANGE_MANA
, GetNameLink(chr
).c_str(), mana
, manam
);
734 if (needReportToTarget(chr
))
735 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_MANA_CHANGED
, GetNameLink().c_str(), mana
, manam
);
737 chr
->SetMaxPower(POWER_MANA
,manam
);
738 chr
->SetPower(POWER_MANA
, mana
);
744 bool ChatHandler::HandleModifyEnergyCommand(const char* args
)
749 // char* pmana = strtok((char*)args, " ");
753 // char* pmanaMax = strtok(NULL, " ");
757 // int32 manam = atoi(pmanaMax);
758 // int32 mana = atoi(pmana);
760 int32 energy
= atoi((char*)args
)*10;
761 int32 energym
= atoi((char*)args
)*10;
763 if (energy
<= 0 || energym
<= 0 || energym
< energy
)
765 SendSysMessage(LANG_BAD_VALUE
);
766 SetSentErrorMessage(true);
770 Player
*chr
= getSelectedPlayer();
773 SendSysMessage(LANG_NO_CHAR_SELECTED
);
774 SetSentErrorMessage(true);
778 // check online security
779 if (HasLowerSecurity(chr
, 0))
782 PSendSysMessage(LANG_YOU_CHANGE_ENERGY
, GetNameLink(chr
).c_str(), energy
/10, energym
/10);
783 if (needReportToTarget(chr
))
784 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_ENERGY_CHANGED
, GetNameLink().c_str(), energy
/10, energym
/10);
786 chr
->SetMaxPower(POWER_ENERGY
,energym
);
787 chr
->SetPower(POWER_ENERGY
, energy
);
789 sLog
.outDetail(GetMangosString(LANG_CURRENT_ENERGY
),chr
->GetMaxPower(POWER_ENERGY
));
795 bool ChatHandler::HandleModifyRageCommand(const char* args
)
800 // char* pmana = strtok((char*)args, " ");
804 // char* pmanaMax = strtok(NULL, " ");
808 // int32 manam = atoi(pmanaMax);
809 // int32 mana = atoi(pmana);
811 int32 rage
= atoi((char*)args
)*10;
812 int32 ragem
= atoi((char*)args
)*10;
814 if (rage
<= 0 || ragem
<= 0 || ragem
< rage
)
816 SendSysMessage(LANG_BAD_VALUE
);
817 SetSentErrorMessage(true);
821 Player
*chr
= getSelectedPlayer();
824 SendSysMessage(LANG_NO_CHAR_SELECTED
);
825 SetSentErrorMessage(true);
829 // check online security
830 if (HasLowerSecurity(chr
, 0))
833 PSendSysMessage(LANG_YOU_CHANGE_RAGE
, GetNameLink(chr
).c_str(), rage
/10, ragem
/10);
834 if (needReportToTarget(chr
))
835 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_RAGE_CHANGED
, GetNameLink().c_str(), rage
/10, ragem
/10);
837 chr
->SetMaxPower(POWER_RAGE
,ragem
);
838 chr
->SetPower(POWER_RAGE
, rage
);
843 // Edit Player Runic Power
844 bool ChatHandler::HandleModifyRunicPowerCommand(const char* args
)
849 int32 rune
= atoi((char*)args
)*10;
850 int32 runem
= atoi((char*)args
)*10;
852 if (rune
<= 0 || runem
<= 0 || runem
< rune
)
854 SendSysMessage(LANG_BAD_VALUE
);
855 SetSentErrorMessage(true);
859 Player
*chr
= getSelectedPlayer();
862 SendSysMessage(LANG_NO_CHAR_SELECTED
);
863 SetSentErrorMessage(true);
867 PSendSysMessage(LANG_YOU_CHANGE_RUNIC_POWER
, GetNameLink(chr
).c_str(), rune
/10, runem
/10);
868 if (needReportToTarget(chr
))
869 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_RUNIC_POWER_CHANGED
, GetNameLink().c_str(), rune
/10, runem
/10);
871 chr
->SetMaxPower(POWER_RUNIC_POWER
,runem
);
872 chr
->SetPower(POWER_RUNIC_POWER
, rune
);
877 //Edit Player Faction
878 bool ChatHandler::HandleModifyFactionCommand(const char* args
)
883 char* pfactionid
= extractKeyFromLink((char*)args
,"Hfaction");
885 Creature
* chr
= getSelectedCreature();
888 SendSysMessage(LANG_SELECT_CREATURE
);
889 SetSentErrorMessage(true);
897 uint32 factionid
= chr
->getFaction();
898 uint32 flag
= chr
->GetUInt32Value(UNIT_FIELD_FLAGS
);
899 uint32 npcflag
= chr
->GetUInt32Value(UNIT_NPC_FLAGS
);
900 uint32 dyflag
= chr
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
);
901 PSendSysMessage(LANG_CURRENT_FACTION
,chr
->GetGUIDLow(),factionid
,flag
,npcflag
,dyflag
);
908 SendSysMessage(LANG_NO_CHAR_SELECTED
);
909 SetSentErrorMessage(true);
913 uint32 factionid
= atoi(pfactionid
);
916 char *pflag
= strtok(NULL
, " ");
918 flag
= chr
->GetUInt32Value(UNIT_FIELD_FLAGS
);
922 char* pnpcflag
= strtok(NULL
, " ");
926 npcflag
= chr
->GetUInt32Value(UNIT_NPC_FLAGS
);
928 npcflag
= atoi(pnpcflag
);
930 char* pdyflag
= strtok(NULL
, " ");
934 dyflag
= chr
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
);
936 dyflag
= atoi(pdyflag
);
938 if(!sFactionTemplateStore
.LookupEntry(factionid
))
940 PSendSysMessage(LANG_WRONG_FACTION
, factionid
);
941 SetSentErrorMessage(true);
945 PSendSysMessage(LANG_YOU_CHANGE_FACTION
, chr
->GetGUIDLow(),factionid
,flag
,npcflag
,dyflag
);
947 chr
->setFaction(factionid
);
948 chr
->SetUInt32Value(UNIT_FIELD_FLAGS
,flag
);
949 chr
->SetUInt32Value(UNIT_NPC_FLAGS
,npcflag
);
950 chr
->SetUInt32Value(UNIT_DYNAMIC_FLAGS
,dyflag
);
956 bool ChatHandler::HandleModifySpellCommand(const char* args
)
958 if(!*args
) return false;
959 char* pspellflatid
= strtok((char*)args
, " ");
963 char* pop
= strtok(NULL
, " ");
967 char* pval
= strtok(NULL
, " ");
973 char* pmark
= strtok(NULL
, " ");
975 uint8 spellflatid
= atoi(pspellflatid
);
976 uint8 op
= atoi(pop
);
977 uint16 val
= atoi(pval
);
983 Player
*chr
= getSelectedPlayer();
986 SendSysMessage(LANG_NO_CHAR_SELECTED
);
987 SetSentErrorMessage(true);
991 // check online security
992 if (HasLowerSecurity(chr
, 0))
995 PSendSysMessage(LANG_YOU_CHANGE_SPELLFLATID
, spellflatid
, val
, mark
, GetNameLink(chr
).c_str());
996 if (needReportToTarget(chr
))
997 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_SPELLFLATID_CHANGED
, GetNameLink().c_str(), spellflatid
, val
, mark
);
999 WorldPacket
data(SMSG_SET_FLAT_SPELL_MODIFIER
, (1+1+2+2));
1000 data
<< uint8(spellflatid
);
1002 data
<< uint16(val
);
1003 data
<< uint16(mark
);
1004 chr
->GetSession()->SendPacket(&data
);
1010 bool ChatHandler::HandleModifyTalentCommand (const char* args
)
1015 int tp
= atoi((char*)args
);
1019 Unit
* target
= getSelectedUnit();
1022 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1023 SetSentErrorMessage(true);
1027 if(target
->GetTypeId()==TYPEID_PLAYER
)
1029 // check online security
1030 if (HasLowerSecurity((Player
*)target
, 0))
1033 ((Player
*)target
)->SetFreeTalentPoints(tp
);
1034 ((Player
*)target
)->SendTalentsInfoData(false);
1037 else if(((Creature
*)target
)->isPet())
1039 Unit
*owner
= target
->GetOwner();
1040 if(owner
&& owner
->GetTypeId() == TYPEID_PLAYER
&& ((Pet
*)target
)->IsPermanentPetFor((Player
*)owner
))
1042 // check online security
1043 if (HasLowerSecurity((Player
*)owner
, 0))
1046 ((Pet
*)target
)->SetFreeTalentPoints(tp
);
1047 ((Player
*)owner
)->SendTalentsInfoData(true);
1052 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1053 SetSentErrorMessage(true);
1057 //Enable On\OFF all taxi paths
1058 bool ChatHandler::HandleTaxiCheatCommand(const char* args
)
1062 SendSysMessage(LANG_USE_BOL
);
1063 SetSentErrorMessage(true);
1067 std::string argstr
= (char*)args
;
1069 Player
*chr
= getSelectedPlayer();
1072 chr
=m_session
->GetPlayer();
1075 // check online security
1076 else if (HasLowerSecurity(chr
, 0))
1081 chr
->SetTaxiCheater(true);
1082 PSendSysMessage(LANG_YOU_GIVE_TAXIS
, GetNameLink(chr
).c_str());
1083 if (needReportToTarget(chr
))
1084 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_TAXIS_ADDED
, GetNameLink().c_str());
1088 if (argstr
== "off")
1090 chr
->SetTaxiCheater(false);
1091 PSendSysMessage(LANG_YOU_REMOVE_TAXIS
, GetNameLink(chr
).c_str());
1092 if (needReportToTarget(chr
))
1093 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_TAXIS_REMOVED
, GetNameLink().c_str());
1098 SendSysMessage(LANG_USE_BOL
);
1099 SetSentErrorMessage(true);
1103 //Edit Player Aspeed
1104 bool ChatHandler::HandleModifyASpeedCommand(const char* args
)
1109 float ASpeed
= (float)atof((char*)args
);
1111 if (ASpeed
> 10 || ASpeed
< 0.1)
1113 SendSysMessage(LANG_BAD_VALUE
);
1114 SetSentErrorMessage(true);
1118 Player
*chr
= getSelectedPlayer();
1121 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1122 SetSentErrorMessage(true);
1126 // check online security
1127 if (HasLowerSecurity(chr
, 0))
1130 std::string chrNameLink
= GetNameLink(chr
);
1132 if(chr
->isInFlight())
1134 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chrNameLink
.c_str());
1135 SetSentErrorMessage(true);
1139 PSendSysMessage(LANG_YOU_CHANGE_ASPEED
, ASpeed
, chrNameLink
.c_str());
1140 if (needReportToTarget(chr
))
1141 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_ASPEED_CHANGED
, GetNameLink().c_str(), ASpeed
);
1143 chr
->SetSpeedRate(MOVE_WALK
, ASpeed
,true);
1144 chr
->SetSpeedRate(MOVE_RUN
, ASpeed
,true);
1145 chr
->SetSpeedRate(MOVE_SWIM
, ASpeed
,true);
1146 //chr->SetSpeed(MOVE_TURN, ASpeed,true);
1147 chr
->SetSpeedRate(MOVE_FLIGHT
, ASpeed
,true);
1152 bool ChatHandler::HandleModifySpeedCommand(const char* args
)
1157 float Speed
= (float)atof((char*)args
);
1159 if (Speed
> 10 || Speed
< 0.1)
1161 SendSysMessage(LANG_BAD_VALUE
);
1162 SetSentErrorMessage(true);
1166 Player
*chr
= getSelectedPlayer();
1169 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1170 SetSentErrorMessage(true);
1174 // check online security
1175 if (HasLowerSecurity(chr
, 0))
1178 std::string chrNameLink
= GetNameLink(chr
);
1180 if(chr
->isInFlight())
1182 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chrNameLink
.c_str());
1183 SetSentErrorMessage(true);
1187 PSendSysMessage(LANG_YOU_CHANGE_SPEED
, Speed
, chrNameLink
.c_str());
1188 if (needReportToTarget(chr
))
1189 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_SPEED_CHANGED
, GetNameLink().c_str(), Speed
);
1191 chr
->SetSpeedRate(MOVE_RUN
,Speed
,true);
1196 //Edit Player Swim Speed
1197 bool ChatHandler::HandleModifySwimCommand(const char* args
)
1202 float Swim
= (float)atof((char*)args
);
1204 if (Swim
> 10.0f
|| Swim
< 0.01f
)
1206 SendSysMessage(LANG_BAD_VALUE
);
1207 SetSentErrorMessage(true);
1211 Player
*chr
= getSelectedPlayer();
1214 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1215 SetSentErrorMessage(true);
1219 // check online security
1220 if (HasLowerSecurity(chr
, 0))
1223 std::string chrNameLink
= GetNameLink(chr
);
1225 if(chr
->isInFlight())
1227 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chrNameLink
.c_str());
1228 SetSentErrorMessage(true);
1232 PSendSysMessage(LANG_YOU_CHANGE_SWIM_SPEED
, Swim
, chrNameLink
.c_str());
1233 if (needReportToTarget(chr
))
1234 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_SWIM_SPEED_CHANGED
, GetNameLink().c_str(), Swim
);
1236 chr
->SetSpeedRate(MOVE_SWIM
,Swim
,true);
1241 //Edit Player Walk Speed
1242 bool ChatHandler::HandleModifyBWalkCommand(const char* args
)
1247 float BSpeed
= (float)atof((char*)args
);
1249 if (BSpeed
> 10.0f
|| BSpeed
< 0.1f
)
1251 SendSysMessage(LANG_BAD_VALUE
);
1252 SetSentErrorMessage(true);
1256 Player
*chr
= getSelectedPlayer();
1259 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1260 SetSentErrorMessage(true);
1264 // check online security
1265 if (HasLowerSecurity(chr
, 0))
1268 std::string chrNameLink
= GetNameLink(chr
);
1270 if(chr
->isInFlight())
1272 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chrNameLink
.c_str());
1273 SetSentErrorMessage(true);
1277 PSendSysMessage(LANG_YOU_CHANGE_BACK_SPEED
, BSpeed
, chrNameLink
.c_str());
1278 if (needReportToTarget(chr
))
1279 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_BACK_SPEED_CHANGED
, GetNameLink().c_str(), BSpeed
);
1281 chr
->SetSpeedRate(MOVE_RUN_BACK
,BSpeed
,true);
1287 bool ChatHandler::HandleModifyFlyCommand(const char* args
)
1292 float FSpeed
= (float)atof((char*)args
);
1294 if (FSpeed
> 10.0f
|| FSpeed
< 0.1f
)
1296 SendSysMessage(LANG_BAD_VALUE
);
1297 SetSentErrorMessage(true);
1301 Player
*chr
= getSelectedPlayer();
1304 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1305 SetSentErrorMessage(true);
1309 // check online security
1310 if (HasLowerSecurity(chr
, 0))
1313 PSendSysMessage(LANG_YOU_CHANGE_FLY_SPEED
, FSpeed
, GetNameLink(chr
).c_str());
1314 if (needReportToTarget(chr
))
1315 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_FLY_SPEED_CHANGED
, GetNameLink().c_str(), FSpeed
);
1317 chr
->SetSpeedRate(MOVE_FLIGHT
,FSpeed
,true);
1323 bool ChatHandler::HandleModifyScaleCommand(const char* args
)
1328 float Scale
= (float)atof((char*)args
);
1329 if (Scale
> 10.0f
|| Scale
<= 0.0f
)
1331 SendSysMessage(LANG_BAD_VALUE
);
1332 SetSentErrorMessage(true);
1336 Unit
*target
= getSelectedUnit();
1339 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
1340 SetSentErrorMessage(true);
1344 if (target
->GetTypeId()==TYPEID_PLAYER
)
1346 // check online security
1347 if (HasLowerSecurity((Player
*)target
, 0))
1350 PSendSysMessage(LANG_YOU_CHANGE_SIZE
, Scale
, GetNameLink((Player
*)target
).c_str());
1351 if (needReportToTarget((Player
*)target
))
1352 ChatHandler((Player
*)target
).PSendSysMessage(LANG_YOURS_SIZE_CHANGED
, GetNameLink().c_str(), Scale
);
1355 target
->SetFloatValue(OBJECT_FIELD_SCALE_X
, Scale
);
1360 //Enable Player mount
1361 bool ChatHandler::HandleModifyMountCommand(const char* args
)
1367 float speed
= (float)15;
1370 num
= atoi((char*)args
);
1581 SendSysMessage(LANG_NO_MOUNT
);
1582 SetSentErrorMessage(true);
1586 Player
*chr
= getSelectedPlayer();
1589 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1590 SetSentErrorMessage(true);
1594 // check online security
1595 if (HasLowerSecurity(chr
, 0))
1598 PSendSysMessage(LANG_YOU_GIVE_MOUNT
, GetNameLink(chr
).c_str());
1599 if (needReportToTarget(chr
))
1600 ChatHandler(chr
).PSendSysMessage(LANG_MOUNT_GIVED
, GetNameLink().c_str());
1602 chr
->SetUInt32Value(UNIT_FIELD_FLAGS
, UNIT_FLAG_PVP
);
1605 WorldPacket
data( SMSG_FORCE_RUN_SPEED_CHANGE
, (8+4+1+4) );
1606 data
<< chr
->GetPackGUID();
1608 data
<< (uint8
)0; //new 2.1.0
1609 data
<< float(speed
);
1610 chr
->SendMessageToSet( &data
, true );
1612 data
.Initialize( SMSG_FORCE_SWIM_SPEED_CHANGE
, (8+4+4) );
1613 data
<< chr
->GetPackGUID();
1615 data
<< float(speed
);
1616 chr
->SendMessageToSet( &data
, true );
1622 bool ChatHandler::HandleModifyMoneyCommand(const char* args
)
1627 Player
*chr
= getSelectedPlayer();
1630 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1631 SetSentErrorMessage(true);
1635 // check online security
1636 if (HasLowerSecurity(chr
, 0))
1639 int32 addmoney
= atoi((char*)args
);
1641 uint32 moneyuser
= chr
->GetMoney();
1645 int32 newmoney
= int32(moneyuser
) + addmoney
;
1647 sLog
.outDetail(GetMangosString(LANG_CURRENT_MONEY
), moneyuser
, addmoney
, newmoney
);
1650 PSendSysMessage(LANG_YOU_TAKE_ALL_MONEY
, GetNameLink(chr
).c_str());
1651 if (needReportToTarget(chr
))
1652 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_ALL_MONEY_GONE
, GetNameLink().c_str());
1658 if (newmoney
> MAX_MONEY_AMOUNT
)
1659 newmoney
= MAX_MONEY_AMOUNT
;
1661 PSendSysMessage(LANG_YOU_TAKE_MONEY
, abs(addmoney
), GetNameLink(chr
).c_str());
1662 if (needReportToTarget(chr
))
1663 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_MONEY_TAKEN
, GetNameLink().c_str(), abs(addmoney
));
1664 chr
->SetMoney( newmoney
);
1669 PSendSysMessage(LANG_YOU_GIVE_MONEY
, addmoney
, GetNameLink(chr
).c_str());
1670 if (needReportToTarget(chr
))
1671 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_MONEY_GIVEN
, GetNameLink().c_str(), addmoney
);
1673 if (addmoney
>=MAX_MONEY_AMOUNT
)
1674 chr
->SetMoney(MAX_MONEY_AMOUNT
);
1676 chr
->ModifyMoney( addmoney
);
1679 sLog
.outDetail(GetMangosString(LANG_NEW_MONEY
), moneyuser
, addmoney
, chr
->GetMoney() );
1685 bool ChatHandler::HandleModifyBitCommand(const char* args
)
1690 Unit
*unit
= getSelectedUnit();
1693 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1694 SetSentErrorMessage(true);
1698 // check online security
1699 if (unit
->GetTypeId() == TYPEID_PLAYER
&& HasLowerSecurity((Player
*)unit
, 0))
1702 char* pField
= strtok((char*)args
, " ");
1706 char* pBit
= strtok(NULL
, " ");
1710 uint16 field
= atoi(pField
);
1711 uint32 bit
= atoi(pBit
);
1713 if (field
< OBJECT_END
|| field
>= unit
->GetValuesCount())
1715 SendSysMessage(LANG_BAD_VALUE
);
1716 SetSentErrorMessage(true);
1719 if (bit
< 1 || bit
> 32)
1721 SendSysMessage(LANG_BAD_VALUE
);
1722 SetSentErrorMessage(true);
1726 if ( unit
->HasFlag( field
, (1<<(bit
-1)) ) )
1728 unit
->RemoveFlag( field
, (1<<(bit
-1)) );
1729 PSendSysMessage(LANG_REMOVE_BIT
, bit
, field
);
1733 unit
->SetFlag( field
, (1<<(bit
-1)) );
1734 PSendSysMessage(LANG_SET_BIT
, bit
, field
);
1739 bool ChatHandler::HandleModifyHonorCommand (const char* args
)
1744 Player
*target
= getSelectedPlayer();
1747 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1748 SetSentErrorMessage(true);
1752 // check online security
1753 if (HasLowerSecurity(target
, 0))
1756 int32 amount
= (uint32
)atoi(args
);
1758 target
->ModifyHonorPoints(amount
);
1760 PSendSysMessage(LANG_COMMAND_MODIFY_HONOR
, GetNameLink(target
).c_str(), target
->GetHonorPoints());
1765 bool ChatHandler::HandleTeleCommand(const char * args
)
1770 Player
* _player
= m_session
->GetPlayer();
1772 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
1773 GameTele
const* tele
= extractGameTeleFromLink((char*)args
);
1777 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
1778 SetSentErrorMessage(true);
1782 // stop flight if need
1783 if(_player
->isInFlight())
1785 _player
->GetMotionMaster()->MovementExpired();
1786 _player
->m_taxi
.ClearTaxiDestinations();
1788 // save only in non-flight case
1790 _player
->SaveRecallPosition();
1792 _player
->TeleportTo(tele
->mapId
, tele
->position_x
, tele
->position_y
, tele
->position_z
, tele
->orientation
);
1796 bool ChatHandler::HandleLookupAreaCommand(const char* args
)
1801 std::string namepart
= args
;
1802 std::wstring wnamepart
;
1804 if (!Utf8toWStr (namepart
,wnamepart
))
1807 uint32 counter
= 0; // Counter for figure out that we found smth.
1809 // converting string that we try to find to lower case
1810 wstrToLower (wnamepart
);
1812 // Search in AreaTable.dbc
1813 for (uint32 areaflag
= 0; areaflag
< sAreaStore
.GetNumRows (); ++areaflag
)
1815 AreaTableEntry
const *areaEntry
= sAreaStore
.LookupEntry (areaflag
);
1818 int loc
= GetSessionDbcLocale ();
1819 std::string name
= areaEntry
->area_name
[loc
];
1823 if (!Utf8FitTo (name
, wnamepart
))
1826 for(; loc
< MAX_LOCALE
; ++loc
)
1828 if (loc
==GetSessionDbcLocale ())
1831 name
= areaEntry
->area_name
[loc
];
1835 if (Utf8FitTo (name
, wnamepart
))
1840 if (loc
< MAX_LOCALE
)
1842 // send area in "id - [name]" format
1843 std::ostringstream ss
;
1845 ss
<< areaEntry
->ID
<< " - |cffffffff|Harea:" << areaEntry
->ID
<< "|h[" << name
<< " " << localeNames
[loc
]<< "]|h|r";
1847 ss
<< areaEntry
->ID
<< " - " << name
<< " " << localeNames
[loc
];
1849 SendSysMessage (ss
.str ().c_str());
1856 if (counter
== 0) // if counter == 0 then we found nth
1857 SendSysMessage (LANG_COMMAND_NOAREAFOUND
);
1862 //Find tele in game_tele order by name
1863 bool ChatHandler::HandleLookupTeleCommand(const char * args
)
1867 SendSysMessage(LANG_COMMAND_TELE_PARAMETER
);
1868 SetSentErrorMessage(true);
1872 char const* str
= strtok((char*)args
, " ");
1876 std::string namepart
= str
;
1877 std::wstring wnamepart
;
1879 if(!Utf8toWStr(namepart
,wnamepart
))
1882 // converting string that we try to find to lower case
1883 wstrToLower( wnamepart
);
1885 std::ostringstream reply
;
1887 GameTeleMap
const & teleMap
= sObjectMgr
.GetGameTeleMap();
1888 for(GameTeleMap::const_iterator itr
= teleMap
.begin(); itr
!= teleMap
.end(); ++itr
)
1890 GameTele
const* tele
= &itr
->second
;
1892 if(tele
->wnameLow
.find(wnamepart
) == std::wstring::npos
)
1896 reply
<< " |cffffffff|Htele:" << itr
->first
<< "|h[" << tele
->name
<< "]|h|r\n";
1898 reply
<< " " << itr
->first
<< " " << tele
->name
<< "\n";
1901 if(reply
.str().empty())
1902 SendSysMessage(LANG_COMMAND_TELE_NOLOCATION
);
1904 PSendSysMessage(LANG_COMMAND_TELE_LOCATION
,reply
.str().c_str());
1909 //Enable\Dissable accept whispers (for GM)
1910 bool ChatHandler::HandleWhispersCommand(const char* args
)
1914 PSendSysMessage(LANG_COMMAND_WHISPERACCEPTING
, m_session
->GetPlayer()->isAcceptWhispers() ? GetMangosString(LANG_ON
) : GetMangosString(LANG_OFF
));
1918 std::string argstr
= (char*)args
;
1922 m_session
->GetPlayer()->SetAcceptWhispers(true);
1923 SendSysMessage(LANG_COMMAND_WHISPERON
);
1928 if (argstr
== "off")
1930 m_session
->GetPlayer()->SetAcceptWhispers(false);
1931 SendSysMessage(LANG_COMMAND_WHISPEROFF
);
1935 SendSysMessage(LANG_USE_BOL
);
1936 SetSentErrorMessage(true);
1940 //Save all players in the world
1941 bool ChatHandler::HandleSaveAllCommand(const char* /*args*/)
1943 sObjectAccessor
.SaveAllPlayers();
1944 SendSysMessage(LANG_PLAYERS_SAVED
);
1948 //Send mail by command
1949 bool ChatHandler::HandleSendMailCommand(const char* args
)
1951 // format: name "subject text" "mail text"
1954 std::string target_name
;
1955 if(!extractPlayerTarget((char*)args
,&target
,&target_guid
,&target_name
))
1958 char* tail1
= strtok(NULL
, "");
1962 char* msgSubject
= extractQuotedArg(tail1
);
1966 char* tail2
= strtok(NULL
, "");
1970 char* msgText
= extractQuotedArg(tail2
);
1974 // msgSubject, msgText isn't NUL after prev. check
1975 std::string subject
= msgSubject
;
1976 std::string text
= msgText
;
1978 // from console show not existed sender
1979 MailSender
sender(MAIL_NORMAL
,m_session
? m_session
->GetPlayer()->GetGUIDLow() : 0, MAIL_STATIONERY_GM
);
1981 uint32 itemTextId
= !text
.empty() ? sObjectMgr
.CreateItemText( text
) : 0;
1983 MailDraft(subject
, itemTextId
)
1984 .SendMailTo(MailReceiver(target
,GUID_LOPART(target_guid
)),sender
);
1986 std::string nameLink
= playerLink(target_name
);
1987 PSendSysMessage(LANG_MAIL_SENT
, nameLink
.c_str());
1991 // teleport player to given game_tele.entry
1992 bool ChatHandler::HandleTeleNameCommand(const char * args
)
1996 extractOptFirstArg((char*)args
,&nameStr
,&teleStr
);
2002 std::string target_name
;
2003 if(!extractPlayerTarget(nameStr
,&target
,&target_guid
,&target_name
))
2006 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2007 GameTele
const* tele
= extractGameTeleFromLink(teleStr
);
2010 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
2011 SetSentErrorMessage(true);
2017 // check online security
2018 if (HasLowerSecurity(target
, 0))
2021 std::string chrNameLink
= playerLink(target_name
);
2023 if(target
->IsBeingTeleported()==true)
2025 PSendSysMessage(LANG_IS_TELEPORTED
, chrNameLink
.c_str());
2026 SetSentErrorMessage(true);
2030 PSendSysMessage(LANG_TELEPORTING_TO
, chrNameLink
.c_str(),"", tele
->name
.c_str());
2031 if (needReportToTarget(target
))
2032 ChatHandler(target
).PSendSysMessage(LANG_TELEPORTED_TO_BY
, GetNameLink().c_str());
2034 // stop flight if need
2035 if(target
->isInFlight())
2037 target
->GetMotionMaster()->MovementExpired();
2038 target
->m_taxi
.ClearTaxiDestinations();
2040 // save only in non-flight case
2042 target
->SaveRecallPosition();
2044 target
->TeleportTo(tele
->mapId
,tele
->position_x
,tele
->position_y
,tele
->position_z
,tele
->orientation
);
2048 // check offline security
2049 if (HasLowerSecurity(NULL
, target_guid
))
2052 std::string nameLink
= playerLink(target_name
);
2054 PSendSysMessage(LANG_TELEPORTING_TO
, nameLink
.c_str(), GetMangosString(LANG_OFFLINE
), tele
->name
.c_str());
2055 Player::SavePositionInDB(tele
->mapId
,tele
->position_x
,tele
->position_y
,tele
->position_z
,tele
->orientation
,
2056 sMapMgr
.GetZoneId(tele
->mapId
,tele
->position_x
,tele
->position_y
,tele
->position_z
),target_guid
);
2062 //Teleport group to given game_tele.entry
2063 bool ChatHandler::HandleTeleGroupCommand(const char * args
)
2068 Player
*player
= getSelectedPlayer();
2071 SendSysMessage(LANG_NO_CHAR_SELECTED
);
2072 SetSentErrorMessage(true);
2076 // check online security
2077 if (HasLowerSecurity(player
, 0))
2080 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2081 GameTele
const* tele
= extractGameTeleFromLink((char*)args
);
2084 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
2085 SetSentErrorMessage(true);
2089 std::string nameLink
= GetNameLink(player
);
2091 Group
*grp
= player
->GetGroup();
2094 PSendSysMessage(LANG_NOT_IN_GROUP
,nameLink
.c_str());
2095 SetSentErrorMessage(true);
2099 for(GroupReference
*itr
= grp
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
2101 Player
*pl
= itr
->getSource();
2103 if(!pl
|| !pl
->GetSession() )
2106 // check online security
2107 if (HasLowerSecurity(pl
, 0))
2110 std::string plNameLink
= GetNameLink(pl
);
2112 if(pl
->IsBeingTeleported())
2114 PSendSysMessage(LANG_IS_TELEPORTED
, plNameLink
.c_str());
2118 PSendSysMessage(LANG_TELEPORTING_TO
, plNameLink
.c_str(),"", tele
->name
.c_str());
2119 if (needReportToTarget(pl
))
2120 ChatHandler(pl
).PSendSysMessage(LANG_TELEPORTED_TO_BY
, nameLink
.c_str());
2122 // stop flight if need
2123 if(pl
->isInFlight())
2125 pl
->GetMotionMaster()->MovementExpired();
2126 pl
->m_taxi
.ClearTaxiDestinations();
2128 // save only in non-flight case
2130 pl
->SaveRecallPosition();
2132 pl
->TeleportTo(tele
->mapId
, tele
->position_x
, tele
->position_y
, tele
->position_z
, tele
->orientation
);
2138 //Summon group of player
2139 bool ChatHandler::HandleGroupgoCommand(const char* args
)
2142 if(!extractPlayerTarget((char*)args
,&target
))
2145 // check online security
2146 if (HasLowerSecurity(target
, 0))
2149 Group
*grp
= target
->GetGroup();
2151 std::string nameLink
= GetNameLink(target
);
2155 PSendSysMessage(LANG_NOT_IN_GROUP
,nameLink
.c_str());
2156 SetSentErrorMessage(true);
2160 Map
* gmMap
= m_session
->GetPlayer()->GetMap();
2161 bool to_instance
= gmMap
->Instanceable();
2163 // we are in instance, and can summon only player in our group with us as lead
2164 if ( to_instance
&& (
2165 !m_session
->GetPlayer()->GetGroup() || (grp
->GetLeaderGUID() != m_session
->GetPlayer()->GetGUID()) ||
2166 (m_session
->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session
->GetPlayer()->GetGUID()) ) )
2167 // the last check is a bit excessive, but let it be, just in case
2169 SendSysMessage(LANG_CANNOT_SUMMON_TO_INST
);
2170 SetSentErrorMessage(true);
2174 for(GroupReference
*itr
= grp
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
2176 Player
*pl
= itr
->getSource();
2178 if(!pl
|| pl
==m_session
->GetPlayer() || !pl
->GetSession() )
2181 // check online security
2182 if (HasLowerSecurity(pl
, 0))
2185 std::string plNameLink
= GetNameLink(pl
);
2187 if(pl
->IsBeingTeleported()==true)
2189 PSendSysMessage(LANG_IS_TELEPORTED
, plNameLink
.c_str());
2190 SetSentErrorMessage(true);
2196 Map
* plMap
= pl
->GetMap();
2198 if ( plMap
->Instanceable() && plMap
->GetInstanceId() != gmMap
->GetInstanceId() )
2200 // cannot summon from instance to instance
2201 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST
,plNameLink
.c_str());
2202 SetSentErrorMessage(true);
2207 PSendSysMessage(LANG_SUMMONING
, plNameLink
.c_str(),"");
2208 if (needReportToTarget(pl
))
2209 ChatHandler(pl
).PSendSysMessage(LANG_SUMMONED_BY
, nameLink
.c_str());
2211 // stop flight if need
2212 if(pl
->isInFlight())
2214 pl
->GetMotionMaster()->MovementExpired();
2215 pl
->m_taxi
.ClearTaxiDestinations();
2217 // save only in non-flight case
2219 pl
->SaveRecallPosition();
2223 m_session
->GetPlayer()->GetClosePoint(x
,y
,z
,pl
->GetObjectSize());
2224 pl
->TeleportTo(m_session
->GetPlayer()->GetMapId(),x
,y
,z
,pl
->GetOrientation());
2230 bool ChatHandler::HandleGoTaxinodeCommand(const char* args
)
2232 Player
* _player
= m_session
->GetPlayer();
2237 char* cNodeId
= extractKeyFromLink((char*)args
,"Htaxinode");
2241 int32 i_nodeId
= atoi(cNodeId
);
2245 TaxiNodesEntry
const* node
= sTaxiNodesStore
.LookupEntry(i_nodeId
);
2248 PSendSysMessage(LANG_COMMAND_GOTAXINODENOTFOUND
,i_nodeId
);
2249 SetSentErrorMessage(true);
2253 if ((node
->x
== 0.0f
&& node
->y
== 0.0f
&& node
->z
== 0.0f
) ||
2254 !MapManager::IsValidMapCoord(node
->map_id
,node
->x
,node
->y
,node
->z
))
2256 PSendSysMessage(LANG_INVALID_TARGET_COORD
,node
->x
,node
->y
,node
->map_id
);
2257 SetSentErrorMessage(true);
2261 // stop flight if need
2262 if (_player
->isInFlight())
2264 _player
->GetMotionMaster()->MovementExpired();
2265 _player
->m_taxi
.ClearTaxiDestinations();
2267 // save only in non-flight case
2269 _player
->SaveRecallPosition();
2271 _player
->TeleportTo(node
->map_id
, node
->x
, node
->y
, node
->z
, _player
->GetOrientation());
2275 //teleport at coordinates
2276 bool ChatHandler::HandleGoXYCommand(const char* args
)
2281 Player
* _player
= m_session
->GetPlayer();
2283 char* px
= strtok((char*)args
, " ");
2284 char* py
= strtok(NULL
, " ");
2285 char* pmapid
= strtok(NULL
, " ");
2290 float x
= (float)atof(px
);
2291 float y
= (float)atof(py
);
2294 mapid
= (uint32
)atoi(pmapid
);
2295 else mapid
= _player
->GetMapId();
2297 if(!MapManager::IsValidMapCoord(mapid
,x
,y
))
2299 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,mapid
);
2300 SetSentErrorMessage(true);
2304 // stop flight if need
2305 if(_player
->isInFlight())
2307 _player
->GetMotionMaster()->MovementExpired();
2308 _player
->m_taxi
.ClearTaxiDestinations();
2310 // save only in non-flight case
2312 _player
->SaveRecallPosition();
2314 Map
const *map
= sMapMgr
.CreateBaseMap(mapid
);
2315 float z
= std::max(map
->GetHeight(x
, y
, MAX_HEIGHT
), map
->GetWaterLevel(x
, y
));
2317 _player
->TeleportTo(mapid
, x
, y
, z
, _player
->GetOrientation());
2322 //teleport at coordinates, including Z
2323 bool ChatHandler::HandleGoXYZCommand(const char* args
)
2328 Player
* _player
= m_session
->GetPlayer();
2330 char* px
= strtok((char*)args
, " ");
2331 char* py
= strtok(NULL
, " ");
2332 char* pz
= strtok(NULL
, " ");
2333 char* pmapid
= strtok(NULL
, " ");
2335 if (!px
|| !py
|| !pz
)
2338 float x
= (float)atof(px
);
2339 float y
= (float)atof(py
);
2340 float z
= (float)atof(pz
);
2343 mapid
= (uint32
)atoi(pmapid
);
2345 mapid
= _player
->GetMapId();
2347 if(!MapManager::IsValidMapCoord(mapid
,x
,y
,z
))
2349 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,mapid
);
2350 SetSentErrorMessage(true);
2354 // stop flight if need
2355 if(_player
->isInFlight())
2357 _player
->GetMotionMaster()->MovementExpired();
2358 _player
->m_taxi
.ClearTaxiDestinations();
2360 // save only in non-flight case
2362 _player
->SaveRecallPosition();
2364 _player
->TeleportTo(mapid
, x
, y
, z
, _player
->GetOrientation());
2369 //teleport at coordinates
2370 bool ChatHandler::HandleGoZoneXYCommand(const char* args
)
2375 Player
* _player
= m_session
->GetPlayer();
2377 char* px
= strtok((char*)args
, " ");
2378 char* py
= strtok(NULL
, " ");
2379 char* tail
= strtok(NULL
,"");
2381 char* cAreaId
= extractKeyFromLink(tail
,"Harea"); // string or [name] Shift-click form |color|Harea:area_id|h[name]|h|r
2386 float x
= (float)atof(px
);
2387 float y
= (float)atof(py
);
2389 // prevent accept wrong numeric args
2390 if ((x
==0.0f
&& *px
!='0') || (y
==0.0f
&& *py
!='0'))
2393 uint32 areaid
= cAreaId
? (uint32
)atoi(cAreaId
) : _player
->GetZoneId();
2395 AreaTableEntry
const* areaEntry
= GetAreaEntryByAreaID(areaid
);
2397 if( x
<0 || x
>100 || y
<0 || y
>100 || !areaEntry
)
2399 PSendSysMessage(LANG_INVALID_ZONE_COORD
,x
,y
,areaid
);
2400 SetSentErrorMessage(true);
2404 // update to parent zone if exist (client map show only zones without parents)
2405 AreaTableEntry
const* zoneEntry
= areaEntry
->zone
? GetAreaEntryByAreaID(areaEntry
->zone
) : areaEntry
;
2407 Map
const *map
= sMapMgr
.CreateBaseMap(zoneEntry
->mapid
);
2409 if(map
->Instanceable())
2411 PSendSysMessage(LANG_INVALID_ZONE_MAP
,areaEntry
->ID
,areaEntry
->area_name
[GetSessionDbcLocale()],map
->GetId(),map
->GetMapName());
2412 SetSentErrorMessage(true);
2416 if (!Zone2MapCoordinates(x
,y
,zoneEntry
->ID
))
2418 PSendSysMessage(LANG_INVALID_ZONE_MAP
,areaEntry
->ID
,areaEntry
->area_name
[GetSessionDbcLocale()],map
->GetId(),map
->GetMapName());
2419 SetSentErrorMessage(true);
2423 if(!MapManager::IsValidMapCoord(zoneEntry
->mapid
,x
,y
))
2425 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,zoneEntry
->mapid
);
2426 SetSentErrorMessage(true);
2430 // stop flight if need
2431 if(_player
->isInFlight())
2433 _player
->GetMotionMaster()->MovementExpired();
2434 _player
->m_taxi
.ClearTaxiDestinations();
2436 // save only in non-flight case
2438 _player
->SaveRecallPosition();
2440 float z
= std::max(map
->GetHeight(x
, y
, MAX_HEIGHT
), map
->GetWaterLevel(x
, y
));
2441 _player
->TeleportTo(zoneEntry
->mapid
, x
, y
, z
, _player
->GetOrientation());
2447 bool ChatHandler::HandleGoGridCommand(const char* args
)
2449 if(!*args
) return false;
2450 Player
* _player
= m_session
->GetPlayer();
2452 char* px
= strtok((char*)args
, " ");
2453 char* py
= strtok(NULL
, " ");
2454 char* pmapid
= strtok(NULL
, " ");
2459 float grid_x
= (float)atof(px
);
2460 float grid_y
= (float)atof(py
);
2463 mapid
= (uint32
)atoi(pmapid
);
2464 else mapid
= _player
->GetMapId();
2467 float x
= (grid_x
-CENTER_GRID_ID
+0.5f
)*SIZE_OF_GRIDS
;
2468 float y
= (grid_y
-CENTER_GRID_ID
+0.5f
)*SIZE_OF_GRIDS
;
2470 if(!MapManager::IsValidMapCoord(mapid
,x
,y
))
2472 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,mapid
);
2473 SetSentErrorMessage(true);
2477 // stop flight if need
2478 if(_player
->isInFlight())
2480 _player
->GetMotionMaster()->MovementExpired();
2481 _player
->m_taxi
.ClearTaxiDestinations();
2483 // save only in non-flight case
2485 _player
->SaveRecallPosition();
2487 Map
const *map
= sMapMgr
.CreateBaseMap(mapid
);
2488 float z
= std::max(map
->GetHeight(x
, y
, MAX_HEIGHT
), map
->GetWaterLevel(x
, y
));
2489 _player
->TeleportTo(mapid
, x
, y
, z
, _player
->GetOrientation());
2494 bool ChatHandler::HandleModifyDrunkCommand(const char* args
)
2496 if(!*args
) return false;
2498 uint32 drunklevel
= (uint32
)atoi(args
);
2499 if(drunklevel
> 100)
2502 uint16 drunkMod
= drunklevel
* 0xFFFF / 100;
2504 m_session
->GetPlayer()->SetDrunkValue(drunkMod
);