2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
24 #include "ObjectMgr.h"
29 #include "MapManager.h"
30 #include "ObjectAccessor.h"
33 #include "InstanceSaveMgr.h"
36 #include "VMapFactory.h"
39 //-----------------------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(objmgr
.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
[m_session
->GetSessionDbcLocale()] : "<unknown>" ),
313 zone_id
, (zoneEntry
? zoneEntry
->area_name
[m_session
->GetSessionDbcLocale()] : "<unknown>" ),
314 area_id
, (areaEntry
? areaEntry
->area_name
[m_session
->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
)
349 std::string name
= extractPlayerNameFromLink((char*)args
);
352 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
353 SetSentErrorMessage(true);
357 Player
*chr
= objmgr
.GetPlayer(name
.c_str());
360 std::string nameLink
= playerLink(name
);
361 // check online security
362 if (HasLowerSecurity(chr
, 0))
365 if(chr
->IsBeingTeleported())
367 PSendSysMessage(LANG_IS_TELEPORTED
, nameLink
.c_str());
368 SetSentErrorMessage(true);
372 Map
* pMap
= m_session
->GetPlayer()->GetMap();
374 if(pMap
->IsBattleGroundOrArena())
376 // only allow if gm mode is on
377 if (!chr
->isGameMaster())
379 PSendSysMessage(LANG_CANNOT_GO_TO_BG_GM
,chr
->GetName());
380 SetSentErrorMessage(true);
383 // if both players are in different bgs
384 else if (chr
->GetBattleGroundId() && m_session
->GetPlayer()->GetBattleGroundId() != chr
->GetBattleGroundId())
386 PSendSysMessage(LANG_CANNOT_GO_TO_BG_FROM_BG
,chr
->GetName());
387 SetSentErrorMessage(true);
390 // all's well, set bg id
391 // when porting out from the bg, it will be reset to 0
392 chr
->SetBattleGroundId(m_session
->GetPlayer()->GetBattleGroundId(), m_session
->GetPlayer()->GetBattleGroundTypeId());
393 // remember current position as entry point for return at bg end teleportation
394 chr
->SetBattleGroundEntryPoint(chr
->GetMapId(),chr
->GetPositionX(),chr
->GetPositionY(),chr
->GetPositionZ(),chr
->GetOrientation());
396 else if(pMap
->IsDungeon())
398 Map
* cMap
= chr
->GetMap();
399 if( cMap
->Instanceable() && cMap
->GetInstanceId() != pMap
->GetInstanceId() )
401 // cannot summon from instance to instance
402 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST
,nameLink
.c_str());
403 SetSentErrorMessage(true);
407 // we are in instance, and can summon only player in our group with us as lead
408 if ( !m_session
->GetPlayer()->GetGroup() || !chr
->GetGroup() ||
409 (chr
->GetGroup()->GetLeaderGUID() != m_session
->GetPlayer()->GetGUID()) ||
410 (m_session
->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session
->GetPlayer()->GetGUID()) )
411 // the last check is a bit excessive, but let it be, just in case
413 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST
,nameLink
.c_str());
414 SetSentErrorMessage(true);
419 PSendSysMessage(LANG_SUMMONING
, nameLink
.c_str(),"");
420 if (needReportToTarget(chr
))
421 ChatHandler(chr
).PSendSysMessage(LANG_SUMMONED_BY
, nameLink
.c_str());
423 // stop flight if need
424 if(chr
->isInFlight())
426 chr
->GetMotionMaster()->MovementExpired();
427 chr
->m_taxi
.ClearTaxiDestinations();
429 // save only in non-flight case
431 chr
->SaveRecallPosition();
435 m_session
->GetPlayer()->GetClosePoint(x
,y
,z
,chr
->GetObjectSize());
436 chr
->TeleportTo(m_session
->GetPlayer()->GetMapId(),x
,y
,z
,chr
->GetOrientation());
438 else if (uint64 guid
= objmgr
.GetPlayerGUIDByName(name
))
440 // check offline security
441 if (HasLowerSecurity(NULL
, guid
))
444 std::string nameLink
= playerLink(name
);
446 PSendSysMessage(LANG_SUMMONING
, nameLink
.c_str(),GetMangosString(LANG_OFFLINE
));
448 // in point where GM stay
449 Player::SavePositionInDB(m_session
->GetPlayer()->GetMapId(),
450 m_session
->GetPlayer()->GetPositionX(),
451 m_session
->GetPlayer()->GetPositionY(),
452 m_session
->GetPlayer()->GetPositionZ(),
453 m_session
->GetPlayer()->GetOrientation(),
454 m_session
->GetPlayer()->GetZoneId(),
459 PSendSysMessage(LANG_NO_PLAYER
, args
);
460 SetSentErrorMessage(true);
467 bool ChatHandler::HandleGonameCommand(const char* args
)
472 Player
* _player
= m_session
->GetPlayer();
474 std::string name
= extractPlayerNameFromLink((char*)args
);
477 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
478 SetSentErrorMessage(true);
482 Player
*chr
= objmgr
.GetPlayer(name
.c_str());
485 // check online security
486 if (HasLowerSecurity(chr
, 0))
489 std::string chrNameLink
= playerLink(name
);
491 Map
* cMap
= chr
->GetMap();
492 if(cMap
->IsBattleGroundOrArena())
494 // only allow if gm mode is on
495 if (!_player
->isGameMaster())
497 PSendSysMessage(LANG_CANNOT_GO_TO_BG_GM
,chrNameLink
.c_str());
498 SetSentErrorMessage(true);
501 // if both players are in different bgs
502 else if (_player
->GetBattleGroundId() && _player
->GetBattleGroundId() != chr
->GetBattleGroundId())
504 PSendSysMessage(LANG_CANNOT_GO_TO_BG_FROM_BG
,chrNameLink
.c_str());
505 SetSentErrorMessage(true);
508 // all's well, set bg id
509 // when porting out from the bg, it will be reset to 0
510 _player
->SetBattleGroundId(chr
->GetBattleGroundId(), chr
->GetBattleGroundTypeId());
511 // remember current position as entry point for return at bg end teleportation
512 _player
->SetBattleGroundEntryPoint(_player
->GetMapId(),_player
->GetPositionX(),_player
->GetPositionY(),_player
->GetPositionZ(),_player
->GetOrientation());
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() != chr
->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(chr
->GetMapId(), chr
->GetDifficulty());
545 Group
*group
= _player
->GetGroup();
546 InstanceGroupBind
*gBind
= group
? group
->GetBoundInstance(chr
->GetMapId(), chr
->GetDifficulty()) : NULL
;
549 // if no bind exists, create a solo bind
550 InstanceSave
*save
= sInstanceSaveManager
.GetInstanceSave(chr
->GetInstanceId());
551 if(save
) _player
->BindToInstance(save
, !save
->CanReset());
555 _player
->SetDifficulty(chr
->GetDifficulty());
558 PSendSysMessage(LANG_APPEARING_AT
, chrNameLink
.c_str());
559 if (_player
->IsVisibleGloballyFor(chr
))
560 ChatHandler(chr
).PSendSysMessage(LANG_APPEARING_TO
, GetNameLink().c_str());
562 // stop flight if need
563 if(_player
->isInFlight())
565 _player
->GetMotionMaster()->MovementExpired();
566 _player
->m_taxi
.ClearTaxiDestinations();
568 // save only in non-flight case
570 _player
->SaveRecallPosition();
572 // to point to see at target with same orientation
574 chr
->GetContactPoint(m_session
->GetPlayer(),x
,y
,z
);
576 _player
->TeleportTo(chr
->GetMapId(), x
, y
, z
, _player
->GetAngle( chr
), TELE_TO_GM_MODE
);
581 if (uint64 guid
= objmgr
.GetPlayerGUIDByName(name
))
583 // check offline security
584 if (HasLowerSecurity(NULL
, guid
))
587 std::string nameLink
= playerLink(name
);
589 PSendSysMessage(LANG_APPEARING_AT
, nameLink
.c_str());
591 // to point where player stay (if loaded)
595 if(Player::LoadPositionFromDB(map
,x
,y
,z
,o
,in_flight
,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());
612 PSendSysMessage(LANG_NO_PLAYER
, args
);
614 SetSentErrorMessage(true);
618 // Teleport player to last position
619 bool ChatHandler::HandleRecallCommand(const char* args
)
625 chr
= getSelectedPlayer();
627 chr
= m_session
->GetPlayer();
629 // check online security
630 else if (HasLowerSecurity(chr
, 0))
635 std::string name
= extractPlayerNameFromLink((char*)args
);
638 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
639 SetSentErrorMessage(true);
643 chr
= objmgr
.GetPlayer(name
.c_str());
647 PSendSysMessage(LANG_NO_PLAYER
, args
);
648 SetSentErrorMessage(true);
652 // check online security
653 if (HasLowerSecurity(chr
, 0))
657 if(chr
->IsBeingTeleported())
659 PSendSysMessage(LANG_IS_TELEPORTED
, GetNameLink(chr
).c_str());
660 SetSentErrorMessage(true);
664 // stop flight if need
665 if(chr
->isInFlight())
667 chr
->GetMotionMaster()->MovementExpired();
668 chr
->m_taxi
.ClearTaxiDestinations();
671 chr
->TeleportTo(chr
->m_recallMap
, chr
->m_recallX
, chr
->m_recallY
, chr
->m_recallZ
, chr
->m_recallO
);
675 //Edit Player KnownTitles
676 bool ChatHandler::HandleModifyKnownTitlesCommand(const char* args
)
683 sscanf((char*)args
, I64FMTD
, &titles
);
685 Player
*chr
= getSelectedPlayer();
688 SendSysMessage(LANG_NO_CHAR_SELECTED
);
689 SetSentErrorMessage(true);
693 // check online security
694 if (HasLowerSecurity(chr
, 0))
697 uint64 titles2
= titles
;
699 for(int i
=1; i
< sCharTitlesStore
.GetNumRows(); ++i
)
700 if(CharTitlesEntry
const* tEntry
= sCharTitlesStore
.LookupEntry(i
))
701 titles2
&= ~(uint64(1) << tEntry
->bit_index
);
703 titles
&= ~titles2
; // remove not existed titles
705 chr
->SetUInt64Value(PLAYER__FIELD_KNOWN_TITLES
, titles
);
706 SendSysMessage(LANG_DONE
);
712 bool ChatHandler::HandleModifyHPCommand(const char* args
)
717 // char* pHp = strtok((char*)args, " ");
721 // char* pHpMax = strtok(NULL, " ");
725 // int32 hpm = atoi(pHpMax);
726 // int32 hp = atoi(pHp);
728 int32 hp
= atoi((char*)args
);
729 int32 hpm
= atoi((char*)args
);
731 if (hp
<= 0 || hpm
<= 0 || hpm
< hp
)
733 SendSysMessage(LANG_BAD_VALUE
);
734 SetSentErrorMessage(true);
738 Player
*chr
= getSelectedPlayer();
741 SendSysMessage(LANG_NO_CHAR_SELECTED
);
742 SetSentErrorMessage(true);
746 // check online security
747 if (HasLowerSecurity(chr
, 0))
750 PSendSysMessage(LANG_YOU_CHANGE_HP
, GetNameLink(chr
).c_str(), hp
, hpm
);
751 if (needReportToTarget(chr
))
752 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_HP_CHANGED
, GetNameLink().c_str(), hp
, hpm
);
754 chr
->SetMaxHealth( hpm
);
755 chr
->SetHealth( hp
);
761 bool ChatHandler::HandleModifyManaCommand(const char* args
)
766 // char* pmana = strtok((char*)args, " ");
770 // char* pmanaMax = strtok(NULL, " ");
774 // int32 manam = atoi(pmanaMax);
775 // int32 mana = atoi(pmana);
776 int32 mana
= atoi((char*)args
);
777 int32 manam
= atoi((char*)args
);
779 if (mana
<= 0 || manam
<= 0 || manam
< mana
)
781 SendSysMessage(LANG_BAD_VALUE
);
782 SetSentErrorMessage(true);
786 Player
*chr
= getSelectedPlayer();
789 SendSysMessage(LANG_NO_CHAR_SELECTED
);
790 SetSentErrorMessage(true);
794 // check online security
795 if (HasLowerSecurity(chr
, 0))
798 PSendSysMessage(LANG_YOU_CHANGE_MANA
, GetNameLink(chr
).c_str(), mana
, manam
);
799 if (needReportToTarget(chr
))
800 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_MANA_CHANGED
, GetNameLink().c_str(), mana
, manam
);
802 chr
->SetMaxPower(POWER_MANA
,manam
);
803 chr
->SetPower(POWER_MANA
, mana
);
809 bool ChatHandler::HandleModifyEnergyCommand(const char* args
)
814 // char* pmana = strtok((char*)args, " ");
818 // char* pmanaMax = strtok(NULL, " ");
822 // int32 manam = atoi(pmanaMax);
823 // int32 mana = atoi(pmana);
825 int32 energy
= atoi((char*)args
)*10;
826 int32 energym
= atoi((char*)args
)*10;
828 if (energy
<= 0 || energym
<= 0 || energym
< energy
)
830 SendSysMessage(LANG_BAD_VALUE
);
831 SetSentErrorMessage(true);
835 Player
*chr
= getSelectedPlayer();
838 SendSysMessage(LANG_NO_CHAR_SELECTED
);
839 SetSentErrorMessage(true);
843 // check online security
844 if (HasLowerSecurity(chr
, 0))
847 PSendSysMessage(LANG_YOU_CHANGE_ENERGY
, GetNameLink(chr
).c_str(), energy
/10, energym
/10);
848 if (needReportToTarget(chr
))
849 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_ENERGY_CHANGED
, GetNameLink().c_str(), energy
/10, energym
/10);
851 chr
->SetMaxPower(POWER_ENERGY
,energym
);
852 chr
->SetPower(POWER_ENERGY
, energy
);
854 sLog
.outDetail(GetMangosString(LANG_CURRENT_ENERGY
),chr
->GetMaxPower(POWER_ENERGY
));
860 bool ChatHandler::HandleModifyRageCommand(const char* args
)
865 // char* pmana = strtok((char*)args, " ");
869 // char* pmanaMax = strtok(NULL, " ");
873 // int32 manam = atoi(pmanaMax);
874 // int32 mana = atoi(pmana);
876 int32 rage
= atoi((char*)args
)*10;
877 int32 ragem
= atoi((char*)args
)*10;
879 if (rage
<= 0 || ragem
<= 0 || ragem
< rage
)
881 SendSysMessage(LANG_BAD_VALUE
);
882 SetSentErrorMessage(true);
886 Player
*chr
= getSelectedPlayer();
889 SendSysMessage(LANG_NO_CHAR_SELECTED
);
890 SetSentErrorMessage(true);
894 // check online security
895 if (HasLowerSecurity(chr
, 0))
898 PSendSysMessage(LANG_YOU_CHANGE_RAGE
, GetNameLink(chr
).c_str(), rage
/10, ragem
/10);
899 if (needReportToTarget(chr
))
900 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_RAGE_CHANGED
, GetNameLink().c_str(), rage
/10, ragem
/10);
902 chr
->SetMaxPower(POWER_RAGE
,ragem
);
903 chr
->SetPower(POWER_RAGE
, rage
);
908 // Edit Player Runic Power
909 bool ChatHandler::HandleModifyRunicPowerCommand(const char* args
)
914 int32 rune
= atoi((char*)args
)*10;
915 int32 runem
= atoi((char*)args
)*10;
917 if (rune
<= 0 || runem
<= 0 || runem
< rune
)
919 SendSysMessage(LANG_BAD_VALUE
);
920 SetSentErrorMessage(true);
924 Player
*chr
= getSelectedPlayer();
927 SendSysMessage(LANG_NO_CHAR_SELECTED
);
928 SetSentErrorMessage(true);
932 PSendSysMessage(LANG_YOU_CHANGE_RUNIC_POWER
, GetNameLink(chr
).c_str(), rune
/10, runem
/10);
933 if (needReportToTarget(chr
))
934 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_RUNIC_POWER_CHANGED
, GetNameLink().c_str(), rune
/10, runem
/10);
936 chr
->SetMaxPower(POWER_RUNIC_POWER
,runem
);
937 chr
->SetPower(POWER_RUNIC_POWER
, rune
);
942 //Edit Player Faction
943 bool ChatHandler::HandleModifyFactionCommand(const char* args
)
948 char* pfactionid
= extractKeyFromLink((char*)args
,"Hfaction");
950 Creature
* chr
= getSelectedCreature();
953 SendSysMessage(LANG_SELECT_CREATURE
);
954 SetSentErrorMessage(true);
962 uint32 factionid
= chr
->getFaction();
963 uint32 flag
= chr
->GetUInt32Value(UNIT_FIELD_FLAGS
);
964 uint32 npcflag
= chr
->GetUInt32Value(UNIT_NPC_FLAGS
);
965 uint32 dyflag
= chr
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
);
966 PSendSysMessage(LANG_CURRENT_FACTION
,chr
->GetGUIDLow(),factionid
,flag
,npcflag
,dyflag
);
973 SendSysMessage(LANG_NO_CHAR_SELECTED
);
974 SetSentErrorMessage(true);
978 uint32 factionid
= atoi(pfactionid
);
981 char *pflag
= strtok(NULL
, " ");
983 flag
= chr
->GetUInt32Value(UNIT_FIELD_FLAGS
);
987 char* pnpcflag
= strtok(NULL
, " ");
991 npcflag
= chr
->GetUInt32Value(UNIT_NPC_FLAGS
);
993 npcflag
= atoi(pnpcflag
);
995 char* pdyflag
= strtok(NULL
, " ");
999 dyflag
= chr
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
);
1001 dyflag
= atoi(pdyflag
);
1003 if(!sFactionTemplateStore
.LookupEntry(factionid
))
1005 PSendSysMessage(LANG_WRONG_FACTION
, factionid
);
1006 SetSentErrorMessage(true);
1010 PSendSysMessage(LANG_YOU_CHANGE_FACTION
, chr
->GetGUIDLow(),factionid
,flag
,npcflag
,dyflag
);
1012 chr
->setFaction(factionid
);
1013 chr
->SetUInt32Value(UNIT_FIELD_FLAGS
,flag
);
1014 chr
->SetUInt32Value(UNIT_NPC_FLAGS
,npcflag
);
1015 chr
->SetUInt32Value(UNIT_DYNAMIC_FLAGS
,dyflag
);
1021 bool ChatHandler::HandleModifySpellCommand(const char* args
)
1023 if(!*args
) return false;
1024 char* pspellflatid
= strtok((char*)args
, " ");
1028 char* pop
= strtok(NULL
, " ");
1032 char* pval
= strtok(NULL
, " ");
1038 char* pmark
= strtok(NULL
, " ");
1040 uint8 spellflatid
= atoi(pspellflatid
);
1041 uint8 op
= atoi(pop
);
1042 uint16 val
= atoi(pval
);
1048 Player
*chr
= getSelectedPlayer();
1051 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1052 SetSentErrorMessage(true);
1056 // check online security
1057 if (HasLowerSecurity(chr
, 0))
1060 PSendSysMessage(LANG_YOU_CHANGE_SPELLFLATID
, spellflatid
, val
, mark
, GetNameLink(chr
).c_str());
1061 if (needReportToTarget(chr
))
1062 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_SPELLFLATID_CHANGED
, GetNameLink().c_str(), spellflatid
, val
, mark
);
1064 WorldPacket
data(SMSG_SET_FLAT_SPELL_MODIFIER
, (1+1+2+2));
1065 data
<< uint8(spellflatid
);
1067 data
<< uint16(val
);
1068 data
<< uint16(mark
);
1069 chr
->GetSession()->SendPacket(&data
);
1075 bool ChatHandler::HandleModifyTalentCommand (const char* args
)
1080 int tp
= atoi((char*)args
);
1083 Player
* player
= getSelectedPlayer();
1086 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1087 SetSentErrorMessage(true);
1091 // check online security
1092 if (HasLowerSecurity(player
, 0))
1095 player
->SetFreeTalentPoints(tp
);
1101 //Enable On\OFF all taxi paths
1102 bool ChatHandler::HandleTaxiCheatCommand(const char* args
)
1106 SendSysMessage(LANG_USE_BOL
);
1107 SetSentErrorMessage(true);
1111 std::string argstr
= (char*)args
;
1113 Player
*chr
= getSelectedPlayer();
1116 chr
=m_session
->GetPlayer();
1119 // check online security
1120 else if (HasLowerSecurity(chr
, 0))
1125 chr
->SetTaxiCheater(true);
1126 PSendSysMessage(LANG_YOU_GIVE_TAXIS
, GetNameLink(chr
).c_str());
1127 if (needReportToTarget(chr
))
1128 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_TAXIS_ADDED
, GetNameLink().c_str());
1132 if (argstr
== "off")
1134 chr
->SetTaxiCheater(false);
1135 PSendSysMessage(LANG_YOU_REMOVE_TAXIS
, GetNameLink(chr
).c_str());
1136 if (needReportToTarget(chr
))
1137 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_TAXIS_REMOVED
, GetNameLink().c_str());
1142 SendSysMessage(LANG_USE_BOL
);
1143 SetSentErrorMessage(true);
1147 //Edit Player Aspeed
1148 bool ChatHandler::HandleModifyASpeedCommand(const char* args
)
1153 float ASpeed
= (float)atof((char*)args
);
1155 if (ASpeed
> 10 || ASpeed
< 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_ASPEED
, ASpeed
, chrNameLink
.c_str());
1184 if (needReportToTarget(chr
))
1185 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_ASPEED_CHANGED
, GetNameLink().c_str(), ASpeed
);
1187 chr
->SetSpeed(MOVE_WALK
, ASpeed
,true);
1188 chr
->SetSpeed(MOVE_RUN
, ASpeed
,true);
1189 chr
->SetSpeed(MOVE_SWIM
, ASpeed
,true);
1190 //chr->SetSpeed(MOVE_TURN, ASpeed,true);
1191 chr
->SetSpeed(MOVE_FLIGHT
, ASpeed
,true);
1196 bool ChatHandler::HandleModifySpeedCommand(const char* args
)
1201 float Speed
= (float)atof((char*)args
);
1203 if (Speed
> 10 || Speed
< 0.1)
1205 SendSysMessage(LANG_BAD_VALUE
);
1206 SetSentErrorMessage(true);
1210 Player
*chr
= getSelectedPlayer();
1213 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1214 SetSentErrorMessage(true);
1218 // check online security
1219 if (HasLowerSecurity(chr
, 0))
1222 std::string chrNameLink
= GetNameLink(chr
);
1224 if(chr
->isInFlight())
1226 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chrNameLink
.c_str());
1227 SetSentErrorMessage(true);
1231 PSendSysMessage(LANG_YOU_CHANGE_SPEED
, Speed
, chrNameLink
.c_str());
1232 if (needReportToTarget(chr
))
1233 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_SPEED_CHANGED
, GetNameLink().c_str(), Speed
);
1235 chr
->SetSpeed(MOVE_RUN
,Speed
,true);
1240 //Edit Player Swim Speed
1241 bool ChatHandler::HandleModifySwimCommand(const char* args
)
1246 float Swim
= (float)atof((char*)args
);
1248 if (Swim
> 10.0f
|| Swim
< 0.01f
)
1250 SendSysMessage(LANG_BAD_VALUE
);
1251 SetSentErrorMessage(true);
1255 Player
*chr
= getSelectedPlayer();
1258 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1259 SetSentErrorMessage(true);
1263 // check online security
1264 if (HasLowerSecurity(chr
, 0))
1267 std::string chrNameLink
= GetNameLink(chr
);
1269 if(chr
->isInFlight())
1271 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chrNameLink
.c_str());
1272 SetSentErrorMessage(true);
1276 PSendSysMessage(LANG_YOU_CHANGE_SWIM_SPEED
, Swim
, chrNameLink
.c_str());
1277 if (needReportToTarget(chr
))
1278 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_SWIM_SPEED_CHANGED
, GetNameLink().c_str(), Swim
);
1280 chr
->SetSpeed(MOVE_SWIM
,Swim
,true);
1285 //Edit Player Walk Speed
1286 bool ChatHandler::HandleModifyBWalkCommand(const char* args
)
1291 float BSpeed
= (float)atof((char*)args
);
1293 if (BSpeed
> 10.0f
|| BSpeed
< 0.1f
)
1295 SendSysMessage(LANG_BAD_VALUE
);
1296 SetSentErrorMessage(true);
1300 Player
*chr
= getSelectedPlayer();
1303 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1304 SetSentErrorMessage(true);
1308 // check online security
1309 if (HasLowerSecurity(chr
, 0))
1312 std::string chrNameLink
= GetNameLink(chr
);
1314 if(chr
->isInFlight())
1316 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chrNameLink
.c_str());
1317 SetSentErrorMessage(true);
1321 PSendSysMessage(LANG_YOU_CHANGE_BACK_SPEED
, BSpeed
, chrNameLink
.c_str());
1322 if (needReportToTarget(chr
))
1323 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_BACK_SPEED_CHANGED
, GetNameLink().c_str(), BSpeed
);
1325 chr
->SetSpeed(MOVE_RUN_BACK
,BSpeed
,true);
1331 bool ChatHandler::HandleModifyFlyCommand(const char* args
)
1336 float FSpeed
= (float)atof((char*)args
);
1338 if (FSpeed
> 10.0f
|| FSpeed
< 0.1f
)
1340 SendSysMessage(LANG_BAD_VALUE
);
1341 SetSentErrorMessage(true);
1345 Player
*chr
= getSelectedPlayer();
1348 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1349 SetSentErrorMessage(true);
1353 // check online security
1354 if (HasLowerSecurity(chr
, 0))
1357 PSendSysMessage(LANG_YOU_CHANGE_FLY_SPEED
, FSpeed
, GetNameLink(chr
).c_str());
1358 if (needReportToTarget(chr
))
1359 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_FLY_SPEED_CHANGED
, GetNameLink().c_str(), FSpeed
);
1361 chr
->SetSpeed(MOVE_FLIGHT
,FSpeed
,true);
1367 bool ChatHandler::HandleModifyScaleCommand(const char* args
)
1372 float Scale
= (float)atof((char*)args
);
1373 if (Scale
> 3.0f
|| Scale
<= 0.0f
)
1375 SendSysMessage(LANG_BAD_VALUE
);
1376 SetSentErrorMessage(true);
1380 Player
*chr
= getSelectedPlayer();
1383 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1384 SetSentErrorMessage(true);
1388 // check online security
1389 if (HasLowerSecurity(chr
, 0))
1392 PSendSysMessage(LANG_YOU_CHANGE_SIZE
, Scale
, GetNameLink(chr
).c_str());
1393 if (needReportToTarget(chr
))
1394 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_SIZE_CHANGED
, GetNameLink().c_str(), Scale
);
1396 chr
->SetFloatValue(OBJECT_FIELD_SCALE_X
, Scale
);
1401 //Enable Player mount
1402 bool ChatHandler::HandleModifyMountCommand(const char* args
)
1408 float speed
= (float)15;
1411 num
= atoi((char*)args
);
1622 SendSysMessage(LANG_NO_MOUNT
);
1623 SetSentErrorMessage(true);
1627 Player
*chr
= getSelectedPlayer();
1630 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1631 SetSentErrorMessage(true);
1635 // check online security
1636 if (HasLowerSecurity(chr
, 0))
1639 PSendSysMessage(LANG_YOU_GIVE_MOUNT
, GetNameLink(chr
).c_str());
1640 if (needReportToTarget(chr
))
1641 ChatHandler(chr
).PSendSysMessage(LANG_MOUNT_GIVED
, GetNameLink().c_str());
1643 chr
->SetUInt32Value( UNIT_FIELD_FLAGS
, 0x001000 );
1646 WorldPacket
data( SMSG_FORCE_RUN_SPEED_CHANGE
, (8+4+1+4) );
1647 data
.append(chr
->GetPackGUID());
1649 data
<< (uint8
)0; //new 2.1.0
1650 data
<< float(speed
);
1651 chr
->SendMessageToSet( &data
, true );
1653 data
.Initialize( SMSG_FORCE_SWIM_SPEED_CHANGE
, (8+4+4) );
1654 data
.append(chr
->GetPackGUID());
1656 data
<< float(speed
);
1657 chr
->SendMessageToSet( &data
, true );
1663 bool ChatHandler::HandleModifyMoneyCommand(const char* args
)
1668 Player
*chr
= getSelectedPlayer();
1671 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1672 SetSentErrorMessage(true);
1676 // check online security
1677 if (HasLowerSecurity(chr
, 0))
1680 int32 addmoney
= atoi((char*)args
);
1682 uint32 moneyuser
= chr
->GetMoney();
1686 int32 newmoney
= int32(moneyuser
) + addmoney
;
1688 sLog
.outDetail(GetMangosString(LANG_CURRENT_MONEY
), moneyuser
, addmoney
, newmoney
);
1691 PSendSysMessage(LANG_YOU_TAKE_ALL_MONEY
, GetNameLink(chr
).c_str());
1692 if (needReportToTarget(chr
))
1693 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_ALL_MONEY_GONE
, GetNameLink().c_str());
1699 if (newmoney
> MAX_MONEY_AMOUNT
)
1700 newmoney
= MAX_MONEY_AMOUNT
;
1702 PSendSysMessage(LANG_YOU_TAKE_MONEY
, abs(addmoney
), GetNameLink(chr
).c_str());
1703 if (needReportToTarget(chr
))
1704 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_MONEY_TAKEN
, GetNameLink().c_str(), abs(addmoney
));
1705 chr
->SetMoney( newmoney
);
1710 PSendSysMessage(LANG_YOU_GIVE_MONEY
, addmoney
, GetNameLink(chr
).c_str());
1711 if (needReportToTarget(chr
))
1712 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_MONEY_GIVEN
, GetNameLink().c_str(), addmoney
);
1714 if (addmoney
>=MAX_MONEY_AMOUNT
)
1715 chr
->SetMoney(MAX_MONEY_AMOUNT
);
1717 chr
->ModifyMoney( addmoney
);
1720 sLog
.outDetail(GetMangosString(LANG_NEW_MONEY
), moneyuser
, addmoney
, chr
->GetMoney() );
1726 bool ChatHandler::HandleModifyBitCommand(const char* args
)
1731 Unit
*unit
= getSelectedUnit();
1734 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1735 SetSentErrorMessage(true);
1739 // check online security
1740 if (unit
->GetTypeId() == TYPEID_PLAYER
&& HasLowerSecurity((Player
*)unit
, 0))
1743 char* pField
= strtok((char*)args
, " ");
1747 char* pBit
= strtok(NULL
, " ");
1751 uint16 field
= atoi(pField
);
1752 uint32 bit
= atoi(pBit
);
1754 if (field
< OBJECT_END
|| field
>= unit
->GetValuesCount())
1756 SendSysMessage(LANG_BAD_VALUE
);
1757 SetSentErrorMessage(true);
1760 if (bit
< 1 || bit
> 32)
1762 SendSysMessage(LANG_BAD_VALUE
);
1763 SetSentErrorMessage(true);
1767 if ( unit
->HasFlag( field
, (1<<(bit
-1)) ) )
1769 unit
->RemoveFlag( field
, (1<<(bit
-1)) );
1770 PSendSysMessage(LANG_REMOVE_BIT
, bit
, field
);
1774 unit
->SetFlag( field
, (1<<(bit
-1)) );
1775 PSendSysMessage(LANG_SET_BIT
, bit
, field
);
1780 bool ChatHandler::HandleModifyHonorCommand (const char* args
)
1785 Player
*target
= getSelectedPlayer();
1788 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1789 SetSentErrorMessage(true);
1793 // check online security
1794 if (HasLowerSecurity(target
, 0))
1797 int32 amount
= (uint32
)atoi(args
);
1799 target
->ModifyHonorPoints(amount
);
1801 PSendSysMessage(LANG_COMMAND_MODIFY_HONOR
, GetNameLink(target
).c_str(), target
->GetHonorPoints());
1806 bool ChatHandler::HandleTeleCommand(const char * args
)
1811 Player
* _player
= m_session
->GetPlayer();
1813 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
1814 GameTele
const* tele
= extractGameTeleFromLink((char*)args
);
1818 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
1819 SetSentErrorMessage(true);
1823 // stop flight if need
1824 if(_player
->isInFlight())
1826 _player
->GetMotionMaster()->MovementExpired();
1827 _player
->m_taxi
.ClearTaxiDestinations();
1829 // save only in non-flight case
1831 _player
->SaveRecallPosition();
1833 _player
->TeleportTo(tele
->mapId
, tele
->position_x
, tele
->position_y
, tele
->position_z
, tele
->orientation
);
1837 bool ChatHandler::HandleLookupAreaCommand(const char* args
)
1842 std::string namepart
= args
;
1843 std::wstring wnamepart
;
1845 if (!Utf8toWStr (namepart
,wnamepart
))
1848 uint32 counter
= 0; // Counter for figure out that we found smth.
1850 // converting string that we try to find to lower case
1851 wstrToLower (wnamepart
);
1853 // Search in AreaTable.dbc
1854 for (uint32 areaflag
= 0; areaflag
< sAreaStore
.GetNumRows (); ++areaflag
)
1856 AreaTableEntry
const *areaEntry
= sAreaStore
.LookupEntry (areaflag
);
1859 int loc
= m_session
? m_session
->GetSessionDbcLocale () : sWorld
.GetDefaultDbcLocale();
1860 std::string name
= areaEntry
->area_name
[loc
];
1864 if (!Utf8FitTo (name
, wnamepart
))
1867 for(; loc
< MAX_LOCALE
; ++loc
)
1869 if (m_session
&& loc
==m_session
->GetSessionDbcLocale ())
1872 name
= areaEntry
->area_name
[loc
];
1876 if (Utf8FitTo (name
, wnamepart
))
1881 if (loc
< MAX_LOCALE
)
1883 // send area in "id - [name]" format
1884 std::ostringstream ss
;
1886 ss
<< areaEntry
->ID
<< " - |cffffffff|Harea:" << areaEntry
->ID
<< "|h[" << name
<< " " << localeNames
[loc
]<< "]|h|r";
1888 ss
<< areaEntry
->ID
<< " - " << name
<< " " << localeNames
[loc
];
1890 SendSysMessage (ss
.str ().c_str());
1897 if (counter
== 0) // if counter == 0 then we found nth
1898 SendSysMessage (LANG_COMMAND_NOAREAFOUND
);
1903 //Find tele in game_tele order by name
1904 bool ChatHandler::HandleLookupTeleCommand(const char * args
)
1908 SendSysMessage(LANG_COMMAND_TELE_PARAMETER
);
1909 SetSentErrorMessage(true);
1913 char const* str
= strtok((char*)args
, " ");
1917 std::string namepart
= str
;
1918 std::wstring wnamepart
;
1920 if(!Utf8toWStr(namepart
,wnamepart
))
1923 // converting string that we try to find to lower case
1924 wstrToLower( wnamepart
);
1926 std::ostringstream reply
;
1928 GameTeleMap
const & teleMap
= objmgr
.GetGameTeleMap();
1929 for(GameTeleMap::const_iterator itr
= teleMap
.begin(); itr
!= teleMap
.end(); ++itr
)
1931 GameTele
const* tele
= &itr
->second
;
1933 if(tele
->wnameLow
.find(wnamepart
) == std::wstring::npos
)
1937 reply
<< " |cffffffff|Htele:" << itr
->first
<< "|h[" << tele
->name
<< "]|h|r\n";
1939 reply
<< " " << itr
->first
<< " " << tele
->name
<< "\n";
1942 if(reply
.str().empty())
1943 SendSysMessage(LANG_COMMAND_TELE_NOLOCATION
);
1945 PSendSysMessage(LANG_COMMAND_TELE_LOCATION
,reply
.str().c_str());
1950 //Enable\Dissable accept whispers (for GM)
1951 bool ChatHandler::HandleWhispersCommand(const char* args
)
1955 PSendSysMessage(LANG_COMMAND_WHISPERACCEPTING
, m_session
->GetPlayer()->isAcceptWhispers() ? GetMangosString(LANG_ON
) : GetMangosString(LANG_OFF
));
1959 std::string argstr
= (char*)args
;
1963 m_session
->GetPlayer()->SetAcceptWhispers(true);
1964 SendSysMessage(LANG_COMMAND_WHISPERON
);
1969 if (argstr
== "off")
1971 m_session
->GetPlayer()->SetAcceptWhispers(false);
1972 SendSysMessage(LANG_COMMAND_WHISPEROFF
);
1976 SendSysMessage(LANG_USE_BOL
);
1977 SetSentErrorMessage(true);
1981 //Save all players in the world
1982 bool ChatHandler::HandleSaveAllCommand(const char* /*args*/)
1984 ObjectAccessor::Instance().SaveAllPlayers();
1985 SendSysMessage(LANG_PLAYERS_SAVED
);
1989 //Send mail by command
1990 bool ChatHandler::HandleSendMailCommand(const char* args
)
1995 // format: name "subject text" "mail text"
1997 std::string name
= extractPlayerNameFromLink((char*)args
);
2000 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
2001 SetSentErrorMessage(true);
2005 char* tail1
= strtok(NULL
, "");
2011 msgSubject
= strtok(tail1
+1, "\"");
2014 char* space
= strtok(tail1
, "\"");
2017 msgSubject
= strtok(NULL
, "\"");
2023 char* tail2
= strtok(NULL
, "");
2029 msgText
= strtok(tail2
+1, "\"");
2032 char* space
= strtok(tail2
, "\"");
2035 msgText
= strtok(NULL
, "\"");
2041 // msgSubject, msgText isn't NUL after prev. check
2042 std::string subject
= msgSubject
;
2043 std::string text
= msgText
;
2045 uint64 receiver_guid
= objmgr
.GetPlayerGUIDByName(name
);
2048 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
2049 SetSentErrorMessage(true);
2053 // from console show not existed sender
2054 uint32 sender_guidlo
= m_session
? m_session
->GetPlayer()->GetGUIDLow() : 0;
2056 uint32 messagetype
= MAIL_NORMAL
;
2057 uint32 stationery
= MAIL_STATIONERY_GM
;
2058 uint32 itemTextId
= !text
.empty() ? objmgr
.CreateItemText( text
) : 0;
2060 Player
*receiver
= objmgr
.GetPlayer(receiver_guid
);
2062 WorldSession::SendMailTo(receiver
,messagetype
, stationery
, sender_guidlo
, GUID_LOPART(receiver_guid
), subject
, itemTextId
, NULL
, 0, 0, MAIL_CHECK_MASK_NONE
);
2064 std::string nameLink
= playerLink(name
);
2065 PSendSysMessage(LANG_MAIL_SENT
, nameLink
.c_str());
2069 // teleport player to given game_tele.entry
2070 bool ChatHandler::HandleTeleNameCommand(const char * args
)
2075 std::string name
= extractPlayerNameFromLink((char*)args
);
2078 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
2079 SetSentErrorMessage(true);
2083 char* tail
= strtok(NULL
, "");
2087 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2088 GameTele
const* tele
= extractGameTeleFromLink(tail
);
2091 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
2092 SetSentErrorMessage(true);
2096 Player
*chr
= objmgr
.GetPlayer(name
.c_str());
2099 // check online security
2100 if (HasLowerSecurity(chr
, 0))
2103 std::string chrNameLink
= playerLink(name
);
2105 if(chr
->IsBeingTeleported()==true)
2107 PSendSysMessage(LANG_IS_TELEPORTED
, chrNameLink
.c_str());
2108 SetSentErrorMessage(true);
2112 PSendSysMessage(LANG_TELEPORTING_TO
, chrNameLink
.c_str(),"", tele
->name
.c_str());
2113 if (needReportToTarget(chr
))
2114 ChatHandler(chr
).PSendSysMessage(LANG_TELEPORTED_TO_BY
, GetNameLink().c_str());
2116 // stop flight if need
2117 if(chr
->isInFlight())
2119 chr
->GetMotionMaster()->MovementExpired();
2120 chr
->m_taxi
.ClearTaxiDestinations();
2122 // save only in non-flight case
2124 chr
->SaveRecallPosition();
2126 chr
->TeleportTo(tele
->mapId
,tele
->position_x
,tele
->position_y
,tele
->position_z
,tele
->orientation
);
2128 else if (uint64 guid
= objmgr
.GetPlayerGUIDByName(name
))
2130 // check offline security
2131 if (HasLowerSecurity(NULL
, guid
))
2134 std::string nameLink
= playerLink(name
);
2136 PSendSysMessage(LANG_TELEPORTING_TO
, nameLink
.c_str(), GetMangosString(LANG_OFFLINE
), tele
->name
.c_str());
2137 Player::SavePositionInDB(tele
->mapId
,tele
->position_x
,tele
->position_y
,tele
->position_z
,tele
->orientation
,
2138 MapManager::Instance().GetZoneId(tele
->mapId
,tele
->position_x
,tele
->position_y
,tele
->position_z
),guid
);
2141 PSendSysMessage(LANG_NO_PLAYER
, name
.c_str());
2146 //Teleport group to given game_tele.entry
2147 bool ChatHandler::HandleTeleGroupCommand(const char * args
)
2152 Player
*player
= getSelectedPlayer();
2155 SendSysMessage(LANG_NO_CHAR_SELECTED
);
2156 SetSentErrorMessage(true);
2160 // check online security
2161 if (HasLowerSecurity(player
, 0))
2164 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2165 GameTele
const* tele
= extractGameTeleFromLink((char*)args
);
2168 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
2169 SetSentErrorMessage(true);
2173 std::string nameLink
= GetNameLink(player
);
2175 Group
*grp
= player
->GetGroup();
2178 PSendSysMessage(LANG_NOT_IN_GROUP
,nameLink
.c_str());
2179 SetSentErrorMessage(true);
2183 for(GroupReference
*itr
= grp
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
2185 Player
*pl
= itr
->getSource();
2187 if(!pl
|| !pl
->GetSession() )
2190 // check online security
2191 if (HasLowerSecurity(pl
, 0))
2194 std::string plNameLink
= GetNameLink(pl
);
2196 if(pl
->IsBeingTeleported())
2198 PSendSysMessage(LANG_IS_TELEPORTED
, plNameLink
.c_str());
2202 PSendSysMessage(LANG_TELEPORTING_TO
, plNameLink
.c_str(),"", tele
->name
.c_str());
2203 if (needReportToTarget(pl
))
2204 ChatHandler(pl
).PSendSysMessage(LANG_TELEPORTED_TO_BY
, nameLink
.c_str());
2206 // stop flight if need
2207 if(pl
->isInFlight())
2209 pl
->GetMotionMaster()->MovementExpired();
2210 pl
->m_taxi
.ClearTaxiDestinations();
2212 // save only in non-flight case
2214 pl
->SaveRecallPosition();
2216 pl
->TeleportTo(tele
->mapId
, tele
->position_x
, tele
->position_y
, tele
->position_z
, tele
->orientation
);
2222 //Summon group of player
2223 bool ChatHandler::HandleGroupgoCommand(const char* args
)
2228 std::string name
= extractPlayerNameFromLink((char*)args
);
2231 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
2232 SetSentErrorMessage(true);
2236 Player
*player
= objmgr
.GetPlayer(name
.c_str());
2239 PSendSysMessage(LANG_NO_PLAYER
, args
);
2240 SetSentErrorMessage(true);
2244 // check online security
2245 if (HasLowerSecurity(player
, 0))
2248 Group
*grp
= player
->GetGroup();
2250 std::string nameLink
= playerLink(name
);
2254 PSendSysMessage(LANG_NOT_IN_GROUP
,nameLink
.c_str());
2255 SetSentErrorMessage(true);
2259 Map
* gmMap
= m_session
->GetPlayer()->GetMap();
2260 bool to_instance
= gmMap
->Instanceable();
2262 // we are in instance, and can summon only player in our group with us as lead
2263 if ( to_instance
&& (
2264 !m_session
->GetPlayer()->GetGroup() || (grp
->GetLeaderGUID() != m_session
->GetPlayer()->GetGUID()) ||
2265 (m_session
->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session
->GetPlayer()->GetGUID()) ) )
2266 // the last check is a bit excessive, but let it be, just in case
2268 SendSysMessage(LANG_CANNOT_SUMMON_TO_INST
);
2269 SetSentErrorMessage(true);
2273 for(GroupReference
*itr
= grp
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
2275 Player
*pl
= itr
->getSource();
2277 if(!pl
|| pl
==m_session
->GetPlayer() || !pl
->GetSession() )
2280 // check online security
2281 if (HasLowerSecurity(pl
, 0))
2284 std::string plNameLink
= playerLink(name
);
2286 if(pl
->IsBeingTeleported()==true)
2288 PSendSysMessage(LANG_IS_TELEPORTED
, plNameLink
.c_str());
2289 SetSentErrorMessage(true);
2295 Map
* plMap
= pl
->GetMap();
2297 if ( plMap
->Instanceable() && plMap
->GetInstanceId() != gmMap
->GetInstanceId() )
2299 // cannot summon from instance to instance
2300 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST
,plNameLink
.c_str());
2301 SetSentErrorMessage(true);
2306 PSendSysMessage(LANG_SUMMONING
, plNameLink
.c_str(),"");
2307 if (needReportToTarget(pl
))
2308 ChatHandler(pl
).PSendSysMessage(LANG_SUMMONED_BY
, nameLink
.c_str());
2310 // stop flight if need
2311 if(pl
->isInFlight())
2313 pl
->GetMotionMaster()->MovementExpired();
2314 pl
->m_taxi
.ClearTaxiDestinations();
2316 // save only in non-flight case
2318 pl
->SaveRecallPosition();
2322 m_session
->GetPlayer()->GetClosePoint(x
,y
,z
,pl
->GetObjectSize());
2323 pl
->TeleportTo(m_session
->GetPlayer()->GetMapId(),x
,y
,z
,pl
->GetOrientation());
2329 bool ChatHandler::HandleGoTaxinodeCommand(const char* args
)
2331 Player
* _player
= m_session
->GetPlayer();
2336 char* cNodeId
= extractKeyFromLink((char*)args
,"Htaxinode");
2340 int32 i_nodeId
= atoi(cNodeId
);
2344 TaxiNodesEntry
const* node
= sTaxiNodesStore
.LookupEntry(i_nodeId
);
2347 PSendSysMessage(LANG_COMMAND_GOTAXINODENOTFOUND
,i_nodeId
);
2348 SetSentErrorMessage(true);
2352 if (node
->x
== 0.0f
&& node
->y
== 0.0f
&& node
->z
== 0.0f
||
2353 !MapManager::IsValidMapCoord(node
->map_id
,node
->x
,node
->y
,node
->z
))
2355 PSendSysMessage(LANG_INVALID_TARGET_COORD
,node
->x
,node
->y
,node
->map_id
);
2356 SetSentErrorMessage(true);
2360 // stop flight if need
2361 if (_player
->isInFlight())
2363 _player
->GetMotionMaster()->MovementExpired();
2364 _player
->m_taxi
.ClearTaxiDestinations();
2366 // save only in non-flight case
2368 _player
->SaveRecallPosition();
2370 _player
->TeleportTo(node
->map_id
, node
->x
, node
->y
, node
->z
, _player
->GetOrientation());
2374 //teleport at coordinates
2375 bool ChatHandler::HandleGoXYCommand(const char* args
)
2380 Player
* _player
= m_session
->GetPlayer();
2382 char* px
= strtok((char*)args
, " ");
2383 char* py
= strtok(NULL
, " ");
2384 char* pmapid
= strtok(NULL
, " ");
2389 float x
= (float)atof(px
);
2390 float y
= (float)atof(py
);
2393 mapid
= (uint32
)atoi(pmapid
);
2394 else mapid
= _player
->GetMapId();
2396 if(!MapManager::IsValidMapCoord(mapid
,x
,y
))
2398 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,mapid
);
2399 SetSentErrorMessage(true);
2403 // stop flight if need
2404 if(_player
->isInFlight())
2406 _player
->GetMotionMaster()->MovementExpired();
2407 _player
->m_taxi
.ClearTaxiDestinations();
2409 // save only in non-flight case
2411 _player
->SaveRecallPosition();
2413 Map
const *map
= MapManager::Instance().GetBaseMap(mapid
);
2414 float z
= std::max(map
->GetHeight(x
, y
, MAX_HEIGHT
), map
->GetWaterLevel(x
, y
));
2416 _player
->TeleportTo(mapid
, x
, y
, z
, _player
->GetOrientation());
2421 //teleport at coordinates, including Z
2422 bool ChatHandler::HandleGoXYZCommand(const char* args
)
2427 Player
* _player
= m_session
->GetPlayer();
2429 char* px
= strtok((char*)args
, " ");
2430 char* py
= strtok(NULL
, " ");
2431 char* pz
= strtok(NULL
, " ");
2432 char* pmapid
= strtok(NULL
, " ");
2434 if (!px
|| !py
|| !pz
)
2437 float x
= (float)atof(px
);
2438 float y
= (float)atof(py
);
2439 float z
= (float)atof(pz
);
2442 mapid
= (uint32
)atoi(pmapid
);
2444 mapid
= _player
->GetMapId();
2446 if(!MapManager::IsValidMapCoord(mapid
,x
,y
,z
))
2448 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,mapid
);
2449 SetSentErrorMessage(true);
2453 // stop flight if need
2454 if(_player
->isInFlight())
2456 _player
->GetMotionMaster()->MovementExpired();
2457 _player
->m_taxi
.ClearTaxiDestinations();
2459 // save only in non-flight case
2461 _player
->SaveRecallPosition();
2463 _player
->TeleportTo(mapid
, x
, y
, z
, _player
->GetOrientation());
2468 //teleport at coordinates
2469 bool ChatHandler::HandleGoZoneXYCommand(const char* args
)
2474 Player
* _player
= m_session
->GetPlayer();
2476 char* px
= strtok((char*)args
, " ");
2477 char* py
= strtok(NULL
, " ");
2478 char* tail
= strtok(NULL
,"");
2480 char* cAreaId
= extractKeyFromLink(tail
,"Harea"); // string or [name] Shift-click form |color|Harea:area_id|h[name]|h|r
2485 float x
= (float)atof(px
);
2486 float y
= (float)atof(py
);
2488 // prevent accept wrong numeric args
2489 if (x
==0.0f
&& *px
!='0' || y
==0.0f
&& *py
!='0')
2492 uint32 areaid
= cAreaId
? (uint32
)atoi(cAreaId
) : _player
->GetZoneId();
2494 AreaTableEntry
const* areaEntry
= GetAreaEntryByAreaID(areaid
);
2496 if( x
<0 || x
>100 || y
<0 || y
>100 || !areaEntry
)
2498 PSendSysMessage(LANG_INVALID_ZONE_COORD
,x
,y
,areaid
);
2499 SetSentErrorMessage(true);
2503 // update to parent zone if exist (client map show only zones without parents)
2504 AreaTableEntry
const* zoneEntry
= areaEntry
->zone
? GetAreaEntryByAreaID(areaEntry
->zone
) : areaEntry
;
2506 Map
const *map
= MapManager::Instance().GetBaseMap(zoneEntry
->mapid
);
2508 if(map
->Instanceable())
2510 PSendSysMessage(LANG_INVALID_ZONE_MAP
,areaEntry
->ID
,areaEntry
->area_name
[m_session
->GetSessionDbcLocale()],map
->GetId(),map
->GetMapName());
2511 SetSentErrorMessage(true);
2515 Zone2MapCoordinates(x
,y
,zoneEntry
->ID
);
2517 if(!MapManager::IsValidMapCoord(zoneEntry
->mapid
,x
,y
))
2519 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,zoneEntry
->mapid
);
2520 SetSentErrorMessage(true);
2524 // stop flight if need
2525 if(_player
->isInFlight())
2527 _player
->GetMotionMaster()->MovementExpired();
2528 _player
->m_taxi
.ClearTaxiDestinations();
2530 // save only in non-flight case
2532 _player
->SaveRecallPosition();
2534 float z
= std::max(map
->GetHeight(x
, y
, MAX_HEIGHT
), map
->GetWaterLevel(x
, y
));
2535 _player
->TeleportTo(zoneEntry
->mapid
, x
, y
, z
, _player
->GetOrientation());
2541 bool ChatHandler::HandleGoGridCommand(const char* args
)
2543 if(!*args
) return false;
2544 Player
* _player
= m_session
->GetPlayer();
2546 char* px
= strtok((char*)args
, " ");
2547 char* py
= strtok(NULL
, " ");
2548 char* pmapid
= strtok(NULL
, " ");
2553 float grid_x
= (float)atof(px
);
2554 float grid_y
= (float)atof(py
);
2557 mapid
= (uint32
)atoi(pmapid
);
2558 else mapid
= _player
->GetMapId();
2561 float x
= (grid_x
-CENTER_GRID_ID
+0.5f
)*SIZE_OF_GRIDS
;
2562 float y
= (grid_y
-CENTER_GRID_ID
+0.5f
)*SIZE_OF_GRIDS
;
2564 if(!MapManager::IsValidMapCoord(mapid
,x
,y
))
2566 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,mapid
);
2567 SetSentErrorMessage(true);
2571 // stop flight if need
2572 if(_player
->isInFlight())
2574 _player
->GetMotionMaster()->MovementExpired();
2575 _player
->m_taxi
.ClearTaxiDestinations();
2577 // save only in non-flight case
2579 _player
->SaveRecallPosition();
2581 Map
const *map
= MapManager::Instance().GetBaseMap(mapid
);
2582 float z
= std::max(map
->GetHeight(x
, y
, MAX_HEIGHT
), map
->GetWaterLevel(x
, y
));
2583 _player
->TeleportTo(mapid
, x
, y
, z
, _player
->GetOrientation());
2588 bool ChatHandler::HandleModifyDrunkCommand(const char* args
)
2590 if(!*args
) return false;
2592 uint32 drunklevel
= (uint32
)atoi(args
);
2593 if(drunklevel
> 100)
2596 uint16 drunkMod
= drunklevel
* 0xFFFF / 100;
2598 m_session
->GetPlayer()->SetDrunkValue(drunkMod
);