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
[GetSessionDbcLocale()] : "<unknown>" ),
313 zone_id
, (zoneEntry
? zoneEntry
->area_name
[GetSessionDbcLocale()] : "<unknown>" ),
314 area_id
, (areaEntry
? areaEntry
->area_name
[GetSessionDbcLocale()] : "<unknown>" ),
316 obj
->GetPositionX(), obj
->GetPositionY(), obj
->GetPositionZ(), obj
->GetOrientation(),
317 cell
.GridX(), cell
.GridY(), cell
.CellX(), cell
.CellY(), obj
->GetInstanceId(),
318 zone_x
, zone_y
, ground_z
, floor_z
, have_map
, have_vmap
);
320 sLog
.outDebug("Player %s GPS call for %s '%s' (%s: %u):",
321 m_session
? GetNameLink().c_str() : GetMangosString(LANG_CONSOLE_COMMAND
),
322 (obj
->GetTypeId() == TYPEID_PLAYER
? "player" : "creature"), obj
->GetName(),
323 (obj
->GetTypeId() == TYPEID_PLAYER
? "GUID" : "Entry"), (obj
->GetTypeId() == TYPEID_PLAYER
? obj
->GetGUIDLow(): obj
->GetEntry()) );
325 sLog
.outDebug(GetMangosString(LANG_MAP_POSITION
),
326 obj
->GetMapId(), (mapEntry
? mapEntry
->name
[sWorld
.GetDefaultDbcLocale()] : "<unknown>" ),
327 zone_id
, (zoneEntry
? zoneEntry
->area_name
[sWorld
.GetDefaultDbcLocale()] : "<unknown>" ),
328 area_id
, (areaEntry
? areaEntry
->area_name
[sWorld
.GetDefaultDbcLocale()] : "<unknown>" ),
330 obj
->GetPositionX(), obj
->GetPositionY(), obj
->GetPositionZ(), obj
->GetOrientation(),
331 cell
.GridX(), cell
.GridY(), cell
.CellX(), cell
.CellY(), obj
->GetInstanceId(),
332 zone_x
, zone_y
, ground_z
, floor_z
, have_map
, have_vmap
);
334 LiquidData liquid_status
;
335 ZLiquidStatus res
= map
->getLiquidStatus(obj
->GetPositionX(), obj
->GetPositionY(), obj
->GetPositionZ(), MAP_ALL_LIQUIDS
, &liquid_status
);
338 PSendSysMessage(LANG_LIQUID_STATUS
, liquid_status
.level
, liquid_status
.depth_level
, liquid_status
.type
, res
);
344 bool ChatHandler::HandleNamegoCommand(const char* args
)
348 std::string target_name
;
349 if (!extractPlayerTarget((char*)args
,&target
,&target_guid
,&target_name
))
352 Player
* _player
= m_session
->GetPlayer();
353 if (target
== _player
|| target_guid
== _player
->GetGUID())
355 PSendSysMessage(LANG_CANT_TELEPORT_SELF
);
356 SetSentErrorMessage(true);
362 std::string nameLink
= playerLink(target_name
);
363 // check online security
364 if (HasLowerSecurity(target
, 0))
367 if (target
->IsBeingTeleported())
369 PSendSysMessage(LANG_IS_TELEPORTED
, nameLink
.c_str());
370 SetSentErrorMessage(true);
374 Map
* pMap
= m_session
->GetPlayer()->GetMap();
376 if (pMap
->IsBattleGroundOrArena())
378 // only allow if gm mode is on
379 if (!target
->isGameMaster())
381 PSendSysMessage(LANG_CANNOT_GO_TO_BG_GM
,nameLink
.c_str());
382 SetSentErrorMessage(true);
385 // if both players are in different bgs
386 else if (target
->GetBattleGroundId() && m_session
->GetPlayer()->GetBattleGroundId() != target
->GetBattleGroundId())
388 PSendSysMessage(LANG_CANNOT_GO_TO_BG_FROM_BG
,nameLink
.c_str());
389 SetSentErrorMessage(true);
392 // all's well, set bg id
393 // when porting out from the bg, it will be reset to 0
394 target
->SetBattleGroundId(m_session
->GetPlayer()->GetBattleGroundId(), m_session
->GetPlayer()->GetBattleGroundTypeId());
395 // remember current position as entry point for return at bg end teleportation
396 target
->SetBattleGroundEntryPoint(target
->GetMapId(),target
->GetPositionX(),target
->GetPositionY(),target
->GetPositionZ(),target
->GetOrientation());
398 else if (pMap
->IsDungeon())
400 Map
* cMap
= target
->GetMap();
401 if (cMap
->Instanceable() && cMap
->GetInstanceId() != pMap
->GetInstanceId())
403 // cannot summon from instance to instance
404 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST
,nameLink
.c_str());
405 SetSentErrorMessage(true);
409 // we are in instance, and can summon only player in our group with us as lead
410 if (!m_session
->GetPlayer()->GetGroup() || !target
->GetGroup() ||
411 (target
->GetGroup()->GetLeaderGUID() != m_session
->GetPlayer()->GetGUID()) ||
412 (m_session
->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session
->GetPlayer()->GetGUID()))
413 // the last check is a bit excessive, but let it be, just in case
415 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST
,nameLink
.c_str());
416 SetSentErrorMessage(true);
421 PSendSysMessage(LANG_SUMMONING
, nameLink
.c_str(),"");
422 if (needReportToTarget(target
))
423 ChatHandler(target
).PSendSysMessage(LANG_SUMMONED_BY
, nameLink
.c_str());
425 // stop flight if need
426 if (target
->isInFlight())
428 target
->GetMotionMaster()->MovementExpired();
429 target
->m_taxi
.ClearTaxiDestinations();
431 // save only in non-flight case
433 target
->SaveRecallPosition();
437 m_session
->GetPlayer()->GetClosePoint(x
,y
,z
,target
->GetObjectSize());
438 target
->TeleportTo(m_session
->GetPlayer()->GetMapId(),x
,y
,z
,target
->GetOrientation());
442 // check offline security
443 if (HasLowerSecurity(NULL
, target_guid
))
446 std::string nameLink
= playerLink(target_name
);
448 PSendSysMessage(LANG_SUMMONING
, nameLink
.c_str(),GetMangosString(LANG_OFFLINE
));
450 // in point where GM stay
451 Player::SavePositionInDB(m_session
->GetPlayer()->GetMapId(),
452 m_session
->GetPlayer()->GetPositionX(),
453 m_session
->GetPlayer()->GetPositionY(),
454 m_session
->GetPlayer()->GetPositionZ(),
455 m_session
->GetPlayer()->GetOrientation(),
456 m_session
->GetPlayer()->GetZoneId(),
464 bool ChatHandler::HandleGonameCommand(const char* args
)
468 std::string target_name
;
469 if (!extractPlayerTarget((char*)args
,&target
,&target_guid
,&target_name
))
472 Player
* _player
= m_session
->GetPlayer();
473 if (target
== _player
|| target_guid
== _player
->GetGUID())
475 SendSysMessage(LANG_CANT_TELEPORT_SELF
);
476 SetSentErrorMessage(true);
483 // check online security
484 if (HasLowerSecurity(target
, 0))
487 std::string chrNameLink
= playerLink(target_name
);
489 Map
* cMap
= target
->GetMap();
490 if (cMap
->IsBattleGroundOrArena())
492 // only allow if gm mode is on
493 if (!_player
->isGameMaster())
495 PSendSysMessage(LANG_CANNOT_GO_TO_BG_GM
,chrNameLink
.c_str());
496 SetSentErrorMessage(true);
499 // if both players are in different bgs
500 else if (_player
->GetBattleGroundId() && _player
->GetBattleGroundId() != target
->GetBattleGroundId())
502 PSendSysMessage(LANG_CANNOT_GO_TO_BG_FROM_BG
,chrNameLink
.c_str());
503 SetSentErrorMessage(true);
506 // all's well, set bg id
507 // when porting out from the bg, it will be reset to 0
508 _player
->SetBattleGroundId(target
->GetBattleGroundId(), target
->GetBattleGroundTypeId());
509 // remember current position as entry point for return at bg end teleportation
510 _player
->SetBattleGroundEntryPoint(_player
->GetMapId(),_player
->GetPositionX(),_player
->GetPositionY(),_player
->GetPositionZ(),_player
->GetOrientation());
512 else if(cMap
->IsDungeon())
514 // we have to go to instance, and can go to player only if:
515 // 1) we are in his group (either as leader or as member)
516 // 2) we are not bound to any group and have GM mode on
517 if (_player
->GetGroup())
519 // we are in group, we can go only if we are in the player group
520 if (_player
->GetGroup() != target
->GetGroup())
522 PSendSysMessage(LANG_CANNOT_GO_TO_INST_PARTY
,chrNameLink
.c_str());
523 SetSentErrorMessage(true);
529 // we are not in group, let's verify our GM mode
530 if (!_player
->isGameMaster())
532 PSendSysMessage(LANG_CANNOT_GO_TO_INST_GM
,chrNameLink
.c_str());
533 SetSentErrorMessage(true);
538 // if the player or the player's group is bound to another instance
539 // the player will not be bound to another one
540 InstancePlayerBind
*pBind
= _player
->GetBoundInstance(target
->GetMapId(), target
->GetDifficulty());
543 Group
*group
= _player
->GetGroup();
544 // if no bind exists, create a solo bind
545 InstanceGroupBind
*gBind
= group
? group
->GetBoundInstance(target
->GetMapId(), target
->GetDifficulty()) : NULL
;
546 // if no bind exists, create a solo bind
548 if (InstanceSave
*save
= sInstanceSaveManager
.GetInstanceSave(target
->GetInstanceId()))
549 _player
->BindToInstance(save
, !save
->CanReset());
552 _player
->SetDifficulty(target
->GetDifficulty());
555 PSendSysMessage(LANG_APPEARING_AT
, chrNameLink
.c_str());
556 if (needReportToTarget(target
))
557 ChatHandler(target
).PSendSysMessage(LANG_APPEARING_TO
, GetNameLink().c_str());
559 // stop flight if need
560 if (_player
->isInFlight())
562 _player
->GetMotionMaster()->MovementExpired();
563 _player
->m_taxi
.ClearTaxiDestinations();
565 // save only in non-flight case
567 _player
->SaveRecallPosition();
569 // to point to see at target with same orientation
571 target
->GetContactPoint(_player
,x
,y
,z
);
573 _player
->TeleportTo(target
->GetMapId(), x
, y
, z
, _player
->GetAngle(target
), TELE_TO_GM_MODE
);
577 // check offline security
578 if (HasLowerSecurity(NULL
, target_guid
))
581 std::string nameLink
= playerLink(target_name
);
583 PSendSysMessage(LANG_APPEARING_AT
, nameLink
.c_str());
585 // to point where player stay (if loaded)
589 if (!Player::LoadPositionFromDB(map
,x
,y
,z
,o
,in_flight
,target_guid
))
592 // stop flight if need
593 if (_player
->isInFlight())
595 _player
->GetMotionMaster()->MovementExpired();
596 _player
->m_taxi
.ClearTaxiDestinations();
598 // save only in non-flight case
600 _player
->SaveRecallPosition();
602 _player
->TeleportTo(map
, x
, y
, z
,_player
->GetOrientation());
608 // Teleport player to last position
609 bool ChatHandler::HandleRecallCommand(const char* args
)
612 if(!extractPlayerTarget((char*)args
,&target
))
615 // check online security
616 if (HasLowerSecurity(target
, 0))
619 if (target
->IsBeingTeleported())
621 PSendSysMessage(LANG_IS_TELEPORTED
, GetNameLink(target
).c_str());
622 SetSentErrorMessage(true);
626 // stop flight if need
627 if(target
->isInFlight())
629 target
->GetMotionMaster()->MovementExpired();
630 target
->m_taxi
.ClearTaxiDestinations();
633 target
->TeleportTo(target
->m_recallMap
, target
->m_recallX
, target
->m_recallY
, target
->m_recallZ
, target
->m_recallO
);
637 //Edit Player KnownTitles
638 bool ChatHandler::HandleModifyKnownTitlesCommand(const char* args
)
645 sscanf((char*)args
, I64FMTD
, &titles
);
647 Player
*chr
= getSelectedPlayer();
650 SendSysMessage(LANG_NO_CHAR_SELECTED
);
651 SetSentErrorMessage(true);
655 // check online security
656 if (HasLowerSecurity(chr
, 0))
659 uint64 titles2
= titles
;
661 for(int i
= 1; i
< sCharTitlesStore
.GetNumRows(); ++i
)
662 if(CharTitlesEntry
const* tEntry
= sCharTitlesStore
.LookupEntry(i
))
663 titles2
&= ~(uint64(1) << tEntry
->bit_index
);
665 titles
&= ~titles2
; // remove not existed titles
667 chr
->SetUInt64Value(PLAYER__FIELD_KNOWN_TITLES
, titles
);
668 SendSysMessage(LANG_DONE
);
674 bool ChatHandler::HandleModifyHPCommand(const char* args
)
679 // char* pHp = strtok((char*)args, " ");
683 // char* pHpMax = strtok(NULL, " ");
687 // int32 hpm = atoi(pHpMax);
688 // int32 hp = atoi(pHp);
690 int32 hp
= atoi((char*)args
);
691 int32 hpm
= atoi((char*)args
);
693 if (hp
<= 0 || hpm
<= 0 || hpm
< hp
)
695 SendSysMessage(LANG_BAD_VALUE
);
696 SetSentErrorMessage(true);
700 Player
*chr
= getSelectedPlayer();
703 SendSysMessage(LANG_NO_CHAR_SELECTED
);
704 SetSentErrorMessage(true);
708 // check online security
709 if (HasLowerSecurity(chr
, 0))
712 PSendSysMessage(LANG_YOU_CHANGE_HP
, GetNameLink(chr
).c_str(), hp
, hpm
);
713 if (needReportToTarget(chr
))
714 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_HP_CHANGED
, GetNameLink().c_str(), hp
, hpm
);
716 chr
->SetMaxHealth( hpm
);
717 chr
->SetHealth( hp
);
723 bool ChatHandler::HandleModifyManaCommand(const char* args
)
728 // char* pmana = strtok((char*)args, " ");
732 // char* pmanaMax = strtok(NULL, " ");
736 // int32 manam = atoi(pmanaMax);
737 // int32 mana = atoi(pmana);
738 int32 mana
= atoi((char*)args
);
739 int32 manam
= atoi((char*)args
);
741 if (mana
<= 0 || manam
<= 0 || manam
< mana
)
743 SendSysMessage(LANG_BAD_VALUE
);
744 SetSentErrorMessage(true);
748 Player
*chr
= getSelectedPlayer();
751 SendSysMessage(LANG_NO_CHAR_SELECTED
);
752 SetSentErrorMessage(true);
756 // check online security
757 if (HasLowerSecurity(chr
, 0))
760 PSendSysMessage(LANG_YOU_CHANGE_MANA
, GetNameLink(chr
).c_str(), mana
, manam
);
761 if (needReportToTarget(chr
))
762 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_MANA_CHANGED
, GetNameLink().c_str(), mana
, manam
);
764 chr
->SetMaxPower(POWER_MANA
,manam
);
765 chr
->SetPower(POWER_MANA
, mana
);
771 bool ChatHandler::HandleModifyEnergyCommand(const char* args
)
776 // char* pmana = strtok((char*)args, " ");
780 // char* pmanaMax = strtok(NULL, " ");
784 // int32 manam = atoi(pmanaMax);
785 // int32 mana = atoi(pmana);
787 int32 energy
= atoi((char*)args
)*10;
788 int32 energym
= atoi((char*)args
)*10;
790 if (energy
<= 0 || energym
<= 0 || energym
< energy
)
792 SendSysMessage(LANG_BAD_VALUE
);
793 SetSentErrorMessage(true);
797 Player
*chr
= getSelectedPlayer();
800 SendSysMessage(LANG_NO_CHAR_SELECTED
);
801 SetSentErrorMessage(true);
805 // check online security
806 if (HasLowerSecurity(chr
, 0))
809 PSendSysMessage(LANG_YOU_CHANGE_ENERGY
, GetNameLink(chr
).c_str(), energy
/10, energym
/10);
810 if (needReportToTarget(chr
))
811 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_ENERGY_CHANGED
, GetNameLink().c_str(), energy
/10, energym
/10);
813 chr
->SetMaxPower(POWER_ENERGY
,energym
);
814 chr
->SetPower(POWER_ENERGY
, energy
);
816 sLog
.outDetail(GetMangosString(LANG_CURRENT_ENERGY
),chr
->GetMaxPower(POWER_ENERGY
));
822 bool ChatHandler::HandleModifyRageCommand(const char* args
)
827 // char* pmana = strtok((char*)args, " ");
831 // char* pmanaMax = strtok(NULL, " ");
835 // int32 manam = atoi(pmanaMax);
836 // int32 mana = atoi(pmana);
838 int32 rage
= atoi((char*)args
)*10;
839 int32 ragem
= atoi((char*)args
)*10;
841 if (rage
<= 0 || ragem
<= 0 || ragem
< rage
)
843 SendSysMessage(LANG_BAD_VALUE
);
844 SetSentErrorMessage(true);
848 Player
*chr
= getSelectedPlayer();
851 SendSysMessage(LANG_NO_CHAR_SELECTED
);
852 SetSentErrorMessage(true);
856 // check online security
857 if (HasLowerSecurity(chr
, 0))
860 PSendSysMessage(LANG_YOU_CHANGE_RAGE
, GetNameLink(chr
).c_str(), rage
/10, ragem
/10);
861 if (needReportToTarget(chr
))
862 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_RAGE_CHANGED
, GetNameLink().c_str(), rage
/10, ragem
/10);
864 chr
->SetMaxPower(POWER_RAGE
,ragem
);
865 chr
->SetPower(POWER_RAGE
, rage
);
870 // Edit Player Runic Power
871 bool ChatHandler::HandleModifyRunicPowerCommand(const char* args
)
876 int32 rune
= atoi((char*)args
)*10;
877 int32 runem
= atoi((char*)args
)*10;
879 if (rune
<= 0 || runem
<= 0 || runem
< rune
)
881 SendSysMessage(LANG_BAD_VALUE
);
882 SetSentErrorMessage(true);
886 Player
*chr
= getSelectedPlayer();
889 SendSysMessage(LANG_NO_CHAR_SELECTED
);
890 SetSentErrorMessage(true);
894 PSendSysMessage(LANG_YOU_CHANGE_RUNIC_POWER
, GetNameLink(chr
).c_str(), rune
/10, runem
/10);
895 if (needReportToTarget(chr
))
896 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_RUNIC_POWER_CHANGED
, GetNameLink().c_str(), rune
/10, runem
/10);
898 chr
->SetMaxPower(POWER_RUNIC_POWER
,runem
);
899 chr
->SetPower(POWER_RUNIC_POWER
, rune
);
904 //Edit Player Faction
905 bool ChatHandler::HandleModifyFactionCommand(const char* args
)
910 char* pfactionid
= extractKeyFromLink((char*)args
,"Hfaction");
912 Creature
* chr
= getSelectedCreature();
915 SendSysMessage(LANG_SELECT_CREATURE
);
916 SetSentErrorMessage(true);
924 uint32 factionid
= chr
->getFaction();
925 uint32 flag
= chr
->GetUInt32Value(UNIT_FIELD_FLAGS
);
926 uint32 npcflag
= chr
->GetUInt32Value(UNIT_NPC_FLAGS
);
927 uint32 dyflag
= chr
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
);
928 PSendSysMessage(LANG_CURRENT_FACTION
,chr
->GetGUIDLow(),factionid
,flag
,npcflag
,dyflag
);
935 SendSysMessage(LANG_NO_CHAR_SELECTED
);
936 SetSentErrorMessage(true);
940 uint32 factionid
= atoi(pfactionid
);
943 char *pflag
= strtok(NULL
, " ");
945 flag
= chr
->GetUInt32Value(UNIT_FIELD_FLAGS
);
949 char* pnpcflag
= strtok(NULL
, " ");
953 npcflag
= chr
->GetUInt32Value(UNIT_NPC_FLAGS
);
955 npcflag
= atoi(pnpcflag
);
957 char* pdyflag
= strtok(NULL
, " ");
961 dyflag
= chr
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
);
963 dyflag
= atoi(pdyflag
);
965 if(!sFactionTemplateStore
.LookupEntry(factionid
))
967 PSendSysMessage(LANG_WRONG_FACTION
, factionid
);
968 SetSentErrorMessage(true);
972 PSendSysMessage(LANG_YOU_CHANGE_FACTION
, chr
->GetGUIDLow(),factionid
,flag
,npcflag
,dyflag
);
974 chr
->setFaction(factionid
);
975 chr
->SetUInt32Value(UNIT_FIELD_FLAGS
,flag
);
976 chr
->SetUInt32Value(UNIT_NPC_FLAGS
,npcflag
);
977 chr
->SetUInt32Value(UNIT_DYNAMIC_FLAGS
,dyflag
);
983 bool ChatHandler::HandleModifySpellCommand(const char* args
)
985 if(!*args
) return false;
986 char* pspellflatid
= strtok((char*)args
, " ");
990 char* pop
= strtok(NULL
, " ");
994 char* pval
= strtok(NULL
, " ");
1000 char* pmark
= strtok(NULL
, " ");
1002 uint8 spellflatid
= atoi(pspellflatid
);
1003 uint8 op
= atoi(pop
);
1004 uint16 val
= atoi(pval
);
1010 Player
*chr
= getSelectedPlayer();
1013 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1014 SetSentErrorMessage(true);
1018 // check online security
1019 if (HasLowerSecurity(chr
, 0))
1022 PSendSysMessage(LANG_YOU_CHANGE_SPELLFLATID
, spellflatid
, val
, mark
, GetNameLink(chr
).c_str());
1023 if (needReportToTarget(chr
))
1024 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_SPELLFLATID_CHANGED
, GetNameLink().c_str(), spellflatid
, val
, mark
);
1026 WorldPacket
data(SMSG_SET_FLAT_SPELL_MODIFIER
, (1+1+2+2));
1027 data
<< uint8(spellflatid
);
1029 data
<< uint16(val
);
1030 data
<< uint16(mark
);
1031 chr
->GetSession()->SendPacket(&data
);
1037 bool ChatHandler::HandleModifyTalentCommand (const char* args
)
1042 int tp
= atoi((char*)args
);
1045 Player
* player
= getSelectedPlayer();
1048 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1049 SetSentErrorMessage(true);
1053 // check online security
1054 if (HasLowerSecurity(player
, 0))
1057 player
->SetFreeTalentPoints(tp
);
1063 //Enable On\OFF all taxi paths
1064 bool ChatHandler::HandleTaxiCheatCommand(const char* args
)
1068 SendSysMessage(LANG_USE_BOL
);
1069 SetSentErrorMessage(true);
1073 std::string argstr
= (char*)args
;
1075 Player
*chr
= getSelectedPlayer();
1078 chr
=m_session
->GetPlayer();
1081 // check online security
1082 else if (HasLowerSecurity(chr
, 0))
1087 chr
->SetTaxiCheater(true);
1088 PSendSysMessage(LANG_YOU_GIVE_TAXIS
, GetNameLink(chr
).c_str());
1089 if (needReportToTarget(chr
))
1090 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_TAXIS_ADDED
, GetNameLink().c_str());
1094 if (argstr
== "off")
1096 chr
->SetTaxiCheater(false);
1097 PSendSysMessage(LANG_YOU_REMOVE_TAXIS
, GetNameLink(chr
).c_str());
1098 if (needReportToTarget(chr
))
1099 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_TAXIS_REMOVED
, GetNameLink().c_str());
1104 SendSysMessage(LANG_USE_BOL
);
1105 SetSentErrorMessage(true);
1109 //Edit Player Aspeed
1110 bool ChatHandler::HandleModifyASpeedCommand(const char* args
)
1115 float ASpeed
= (float)atof((char*)args
);
1117 if (ASpeed
> 10 || ASpeed
< 0.1)
1119 SendSysMessage(LANG_BAD_VALUE
);
1120 SetSentErrorMessage(true);
1124 Player
*chr
= getSelectedPlayer();
1127 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1128 SetSentErrorMessage(true);
1132 // check online security
1133 if (HasLowerSecurity(chr
, 0))
1136 std::string chrNameLink
= GetNameLink(chr
);
1138 if(chr
->isInFlight())
1140 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chrNameLink
.c_str());
1141 SetSentErrorMessage(true);
1145 PSendSysMessage(LANG_YOU_CHANGE_ASPEED
, ASpeed
, chrNameLink
.c_str());
1146 if (needReportToTarget(chr
))
1147 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_ASPEED_CHANGED
, GetNameLink().c_str(), ASpeed
);
1149 chr
->SetSpeed(MOVE_WALK
, ASpeed
,true);
1150 chr
->SetSpeed(MOVE_RUN
, ASpeed
,true);
1151 chr
->SetSpeed(MOVE_SWIM
, ASpeed
,true);
1152 //chr->SetSpeed(MOVE_TURN, ASpeed,true);
1153 chr
->SetSpeed(MOVE_FLIGHT
, ASpeed
,true);
1158 bool ChatHandler::HandleModifySpeedCommand(const char* args
)
1163 float Speed
= (float)atof((char*)args
);
1165 if (Speed
> 10 || Speed
< 0.1)
1167 SendSysMessage(LANG_BAD_VALUE
);
1168 SetSentErrorMessage(true);
1172 Player
*chr
= getSelectedPlayer();
1175 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1176 SetSentErrorMessage(true);
1180 // check online security
1181 if (HasLowerSecurity(chr
, 0))
1184 std::string chrNameLink
= GetNameLink(chr
);
1186 if(chr
->isInFlight())
1188 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chrNameLink
.c_str());
1189 SetSentErrorMessage(true);
1193 PSendSysMessage(LANG_YOU_CHANGE_SPEED
, Speed
, chrNameLink
.c_str());
1194 if (needReportToTarget(chr
))
1195 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_SPEED_CHANGED
, GetNameLink().c_str(), Speed
);
1197 chr
->SetSpeed(MOVE_RUN
,Speed
,true);
1202 //Edit Player Swim Speed
1203 bool ChatHandler::HandleModifySwimCommand(const char* args
)
1208 float Swim
= (float)atof((char*)args
);
1210 if (Swim
> 10.0f
|| Swim
< 0.01f
)
1212 SendSysMessage(LANG_BAD_VALUE
);
1213 SetSentErrorMessage(true);
1217 Player
*chr
= getSelectedPlayer();
1220 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1221 SetSentErrorMessage(true);
1225 // check online security
1226 if (HasLowerSecurity(chr
, 0))
1229 std::string chrNameLink
= GetNameLink(chr
);
1231 if(chr
->isInFlight())
1233 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chrNameLink
.c_str());
1234 SetSentErrorMessage(true);
1238 PSendSysMessage(LANG_YOU_CHANGE_SWIM_SPEED
, Swim
, chrNameLink
.c_str());
1239 if (needReportToTarget(chr
))
1240 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_SWIM_SPEED_CHANGED
, GetNameLink().c_str(), Swim
);
1242 chr
->SetSpeed(MOVE_SWIM
,Swim
,true);
1247 //Edit Player Walk Speed
1248 bool ChatHandler::HandleModifyBWalkCommand(const char* args
)
1253 float BSpeed
= (float)atof((char*)args
);
1255 if (BSpeed
> 10.0f
|| BSpeed
< 0.1f
)
1257 SendSysMessage(LANG_BAD_VALUE
);
1258 SetSentErrorMessage(true);
1262 Player
*chr
= getSelectedPlayer();
1265 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1266 SetSentErrorMessage(true);
1270 // check online security
1271 if (HasLowerSecurity(chr
, 0))
1274 std::string chrNameLink
= GetNameLink(chr
);
1276 if(chr
->isInFlight())
1278 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chrNameLink
.c_str());
1279 SetSentErrorMessage(true);
1283 PSendSysMessage(LANG_YOU_CHANGE_BACK_SPEED
, BSpeed
, chrNameLink
.c_str());
1284 if (needReportToTarget(chr
))
1285 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_BACK_SPEED_CHANGED
, GetNameLink().c_str(), BSpeed
);
1287 chr
->SetSpeed(MOVE_RUN_BACK
,BSpeed
,true);
1293 bool ChatHandler::HandleModifyFlyCommand(const char* args
)
1298 float FSpeed
= (float)atof((char*)args
);
1300 if (FSpeed
> 10.0f
|| FSpeed
< 0.1f
)
1302 SendSysMessage(LANG_BAD_VALUE
);
1303 SetSentErrorMessage(true);
1307 Player
*chr
= getSelectedPlayer();
1310 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1311 SetSentErrorMessage(true);
1315 // check online security
1316 if (HasLowerSecurity(chr
, 0))
1319 PSendSysMessage(LANG_YOU_CHANGE_FLY_SPEED
, FSpeed
, GetNameLink(chr
).c_str());
1320 if (needReportToTarget(chr
))
1321 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_FLY_SPEED_CHANGED
, GetNameLink().c_str(), FSpeed
);
1323 chr
->SetSpeed(MOVE_FLIGHT
,FSpeed
,true);
1329 bool ChatHandler::HandleModifyScaleCommand(const char* args
)
1334 float Scale
= (float)atof((char*)args
);
1335 if (Scale
> 3.0f
|| Scale
<= 0.0f
)
1337 SendSysMessage(LANG_BAD_VALUE
);
1338 SetSentErrorMessage(true);
1342 Player
*chr
= getSelectedPlayer();
1345 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1346 SetSentErrorMessage(true);
1350 // check online security
1351 if (HasLowerSecurity(chr
, 0))
1354 PSendSysMessage(LANG_YOU_CHANGE_SIZE
, Scale
, GetNameLink(chr
).c_str());
1355 if (needReportToTarget(chr
))
1356 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_SIZE_CHANGED
, GetNameLink().c_str(), Scale
);
1358 chr
->SetFloatValue(OBJECT_FIELD_SCALE_X
, Scale
);
1363 //Enable Player mount
1364 bool ChatHandler::HandleModifyMountCommand(const char* args
)
1370 float speed
= (float)15;
1373 num
= atoi((char*)args
);
1584 SendSysMessage(LANG_NO_MOUNT
);
1585 SetSentErrorMessage(true);
1589 Player
*chr
= getSelectedPlayer();
1592 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1593 SetSentErrorMessage(true);
1597 // check online security
1598 if (HasLowerSecurity(chr
, 0))
1601 PSendSysMessage(LANG_YOU_GIVE_MOUNT
, GetNameLink(chr
).c_str());
1602 if (needReportToTarget(chr
))
1603 ChatHandler(chr
).PSendSysMessage(LANG_MOUNT_GIVED
, GetNameLink().c_str());
1605 chr
->SetUInt32Value( UNIT_FIELD_FLAGS
, 0x001000 );
1608 WorldPacket
data( SMSG_FORCE_RUN_SPEED_CHANGE
, (8+4+1+4) );
1609 data
.append(chr
->GetPackGUID());
1611 data
<< (uint8
)0; //new 2.1.0
1612 data
<< float(speed
);
1613 chr
->SendMessageToSet( &data
, true );
1615 data
.Initialize( SMSG_FORCE_SWIM_SPEED_CHANGE
, (8+4+4) );
1616 data
.append(chr
->GetPackGUID());
1618 data
<< float(speed
);
1619 chr
->SendMessageToSet( &data
, true );
1625 bool ChatHandler::HandleModifyMoneyCommand(const char* args
)
1630 Player
*chr
= getSelectedPlayer();
1633 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1634 SetSentErrorMessage(true);
1638 // check online security
1639 if (HasLowerSecurity(chr
, 0))
1642 int32 addmoney
= atoi((char*)args
);
1644 uint32 moneyuser
= chr
->GetMoney();
1648 int32 newmoney
= int32(moneyuser
) + addmoney
;
1650 sLog
.outDetail(GetMangosString(LANG_CURRENT_MONEY
), moneyuser
, addmoney
, newmoney
);
1653 PSendSysMessage(LANG_YOU_TAKE_ALL_MONEY
, GetNameLink(chr
).c_str());
1654 if (needReportToTarget(chr
))
1655 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_ALL_MONEY_GONE
, GetNameLink().c_str());
1661 if (newmoney
> MAX_MONEY_AMOUNT
)
1662 newmoney
= MAX_MONEY_AMOUNT
;
1664 PSendSysMessage(LANG_YOU_TAKE_MONEY
, abs(addmoney
), GetNameLink(chr
).c_str());
1665 if (needReportToTarget(chr
))
1666 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_MONEY_TAKEN
, GetNameLink().c_str(), abs(addmoney
));
1667 chr
->SetMoney( newmoney
);
1672 PSendSysMessage(LANG_YOU_GIVE_MONEY
, addmoney
, GetNameLink(chr
).c_str());
1673 if (needReportToTarget(chr
))
1674 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_MONEY_GIVEN
, GetNameLink().c_str(), addmoney
);
1676 if (addmoney
>=MAX_MONEY_AMOUNT
)
1677 chr
->SetMoney(MAX_MONEY_AMOUNT
);
1679 chr
->ModifyMoney( addmoney
);
1682 sLog
.outDetail(GetMangosString(LANG_NEW_MONEY
), moneyuser
, addmoney
, chr
->GetMoney() );
1688 bool ChatHandler::HandleModifyBitCommand(const char* args
)
1693 Unit
*unit
= getSelectedUnit();
1696 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1697 SetSentErrorMessage(true);
1701 // check online security
1702 if (unit
->GetTypeId() == TYPEID_PLAYER
&& HasLowerSecurity((Player
*)unit
, 0))
1705 char* pField
= strtok((char*)args
, " ");
1709 char* pBit
= strtok(NULL
, " ");
1713 uint16 field
= atoi(pField
);
1714 uint32 bit
= atoi(pBit
);
1716 if (field
< OBJECT_END
|| field
>= unit
->GetValuesCount())
1718 SendSysMessage(LANG_BAD_VALUE
);
1719 SetSentErrorMessage(true);
1722 if (bit
< 1 || bit
> 32)
1724 SendSysMessage(LANG_BAD_VALUE
);
1725 SetSentErrorMessage(true);
1729 if ( unit
->HasFlag( field
, (1<<(bit
-1)) ) )
1731 unit
->RemoveFlag( field
, (1<<(bit
-1)) );
1732 PSendSysMessage(LANG_REMOVE_BIT
, bit
, field
);
1736 unit
->SetFlag( field
, (1<<(bit
-1)) );
1737 PSendSysMessage(LANG_SET_BIT
, bit
, field
);
1742 bool ChatHandler::HandleModifyHonorCommand (const char* args
)
1747 Player
*target
= getSelectedPlayer();
1750 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1751 SetSentErrorMessage(true);
1755 // check online security
1756 if (HasLowerSecurity(target
, 0))
1759 int32 amount
= (uint32
)atoi(args
);
1761 target
->ModifyHonorPoints(amount
);
1763 PSendSysMessage(LANG_COMMAND_MODIFY_HONOR
, GetNameLink(target
).c_str(), target
->GetHonorPoints());
1768 bool ChatHandler::HandleTeleCommand(const char * args
)
1773 Player
* _player
= m_session
->GetPlayer();
1775 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
1776 GameTele
const* tele
= extractGameTeleFromLink((char*)args
);
1780 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
1781 SetSentErrorMessage(true);
1785 // stop flight if need
1786 if(_player
->isInFlight())
1788 _player
->GetMotionMaster()->MovementExpired();
1789 _player
->m_taxi
.ClearTaxiDestinations();
1791 // save only in non-flight case
1793 _player
->SaveRecallPosition();
1795 _player
->TeleportTo(tele
->mapId
, tele
->position_x
, tele
->position_y
, tele
->position_z
, tele
->orientation
);
1799 bool ChatHandler::HandleLookupAreaCommand(const char* args
)
1804 std::string namepart
= args
;
1805 std::wstring wnamepart
;
1807 if (!Utf8toWStr (namepart
,wnamepart
))
1810 uint32 counter
= 0; // Counter for figure out that we found smth.
1812 // converting string that we try to find to lower case
1813 wstrToLower (wnamepart
);
1815 // Search in AreaTable.dbc
1816 for (uint32 areaflag
= 0; areaflag
< sAreaStore
.GetNumRows (); ++areaflag
)
1818 AreaTableEntry
const *areaEntry
= sAreaStore
.LookupEntry (areaflag
);
1821 int loc
= GetSessionDbcLocale ();
1822 std::string name
= areaEntry
->area_name
[loc
];
1826 if (!Utf8FitTo (name
, wnamepart
))
1829 for(; loc
< MAX_LOCALE
; ++loc
)
1831 if (loc
==GetSessionDbcLocale ())
1834 name
= areaEntry
->area_name
[loc
];
1838 if (Utf8FitTo (name
, wnamepart
))
1843 if (loc
< MAX_LOCALE
)
1845 // send area in "id - [name]" format
1846 std::ostringstream ss
;
1848 ss
<< areaEntry
->ID
<< " - |cffffffff|Harea:" << areaEntry
->ID
<< "|h[" << name
<< " " << localeNames
[loc
]<< "]|h|r";
1850 ss
<< areaEntry
->ID
<< " - " << name
<< " " << localeNames
[loc
];
1852 SendSysMessage (ss
.str ().c_str());
1859 if (counter
== 0) // if counter == 0 then we found nth
1860 SendSysMessage (LANG_COMMAND_NOAREAFOUND
);
1865 //Find tele in game_tele order by name
1866 bool ChatHandler::HandleLookupTeleCommand(const char * args
)
1870 SendSysMessage(LANG_COMMAND_TELE_PARAMETER
);
1871 SetSentErrorMessage(true);
1875 char const* str
= strtok((char*)args
, " ");
1879 std::string namepart
= str
;
1880 std::wstring wnamepart
;
1882 if(!Utf8toWStr(namepart
,wnamepart
))
1885 // converting string that we try to find to lower case
1886 wstrToLower( wnamepart
);
1888 std::ostringstream reply
;
1890 GameTeleMap
const & teleMap
= objmgr
.GetGameTeleMap();
1891 for(GameTeleMap::const_iterator itr
= teleMap
.begin(); itr
!= teleMap
.end(); ++itr
)
1893 GameTele
const* tele
= &itr
->second
;
1895 if(tele
->wnameLow
.find(wnamepart
) == std::wstring::npos
)
1899 reply
<< " |cffffffff|Htele:" << itr
->first
<< "|h[" << tele
->name
<< "]|h|r\n";
1901 reply
<< " " << itr
->first
<< " " << tele
->name
<< "\n";
1904 if(reply
.str().empty())
1905 SendSysMessage(LANG_COMMAND_TELE_NOLOCATION
);
1907 PSendSysMessage(LANG_COMMAND_TELE_LOCATION
,reply
.str().c_str());
1912 //Enable\Dissable accept whispers (for GM)
1913 bool ChatHandler::HandleWhispersCommand(const char* args
)
1917 PSendSysMessage(LANG_COMMAND_WHISPERACCEPTING
, m_session
->GetPlayer()->isAcceptWhispers() ? GetMangosString(LANG_ON
) : GetMangosString(LANG_OFF
));
1921 std::string argstr
= (char*)args
;
1925 m_session
->GetPlayer()->SetAcceptWhispers(true);
1926 SendSysMessage(LANG_COMMAND_WHISPERON
);
1931 if (argstr
== "off")
1933 m_session
->GetPlayer()->SetAcceptWhispers(false);
1934 SendSysMessage(LANG_COMMAND_WHISPEROFF
);
1938 SendSysMessage(LANG_USE_BOL
);
1939 SetSentErrorMessage(true);
1943 //Save all players in the world
1944 bool ChatHandler::HandleSaveAllCommand(const char* /*args*/)
1946 ObjectAccessor::Instance().SaveAllPlayers();
1947 SendSysMessage(LANG_PLAYERS_SAVED
);
1951 //Send mail by command
1952 bool ChatHandler::HandleSendMailCommand(const char* args
)
1954 // format: name "subject text" "mail text"
1957 std::string target_name
;
1958 if(!extractPlayerTarget((char*)args
,&target
,&target_guid
,&target_name
))
1961 char* tail1
= strtok(NULL
, "");
1965 char* msgSubject
= extractQuotedArg(tail1
);
1969 char* tail2
= strtok(NULL
, "");
1973 char* msgText
= extractQuotedArg(tail2
);
1977 // msgSubject, msgText isn't NUL after prev. check
1978 std::string subject
= msgSubject
;
1979 std::string text
= msgText
;
1981 // from console show not existed sender
1982 uint32 sender_guidlo
= m_session
? m_session
->GetPlayer()->GetGUIDLow() : 0;
1984 uint32 messagetype
= MAIL_NORMAL
;
1985 uint32 stationery
= MAIL_STATIONERY_GM
;
1986 uint32 itemTextId
= !text
.empty() ? objmgr
.CreateItemText( text
) : 0;
1988 WorldSession::SendMailTo(target
,messagetype
, stationery
, sender_guidlo
, GUID_LOPART(target_guid
), subject
, itemTextId
, NULL
, 0, 0, MAIL_CHECK_MASK_NONE
);
1990 std::string nameLink
= playerLink(target_name
);
1991 PSendSysMessage(LANG_MAIL_SENT
, nameLink
.c_str());
1995 // teleport player to given game_tele.entry
1996 bool ChatHandler::HandleTeleNameCommand(const char * args
)
2000 extractOptFirstArg((char*)args
,&nameStr
,&teleStr
);
2006 std::string target_name
;
2007 if(!extractPlayerTarget(nameStr
,&target
,&target_guid
,&target_name
))
2010 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2011 GameTele
const* tele
= extractGameTeleFromLink(teleStr
);
2014 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
2015 SetSentErrorMessage(true);
2021 // check online security
2022 if (HasLowerSecurity(target
, 0))
2025 std::string chrNameLink
= playerLink(target_name
);
2027 if(target
->IsBeingTeleported()==true)
2029 PSendSysMessage(LANG_IS_TELEPORTED
, chrNameLink
.c_str());
2030 SetSentErrorMessage(true);
2034 PSendSysMessage(LANG_TELEPORTING_TO
, chrNameLink
.c_str(),"", tele
->name
.c_str());
2035 if (needReportToTarget(target
))
2036 ChatHandler(target
).PSendSysMessage(LANG_TELEPORTED_TO_BY
, GetNameLink().c_str());
2038 // stop flight if need
2039 if(target
->isInFlight())
2041 target
->GetMotionMaster()->MovementExpired();
2042 target
->m_taxi
.ClearTaxiDestinations();
2044 // save only in non-flight case
2046 target
->SaveRecallPosition();
2048 target
->TeleportTo(tele
->mapId
,tele
->position_x
,tele
->position_y
,tele
->position_z
,tele
->orientation
);
2052 // check offline security
2053 if (HasLowerSecurity(NULL
, target_guid
))
2056 std::string nameLink
= playerLink(target_name
);
2058 PSendSysMessage(LANG_TELEPORTING_TO
, nameLink
.c_str(), GetMangosString(LANG_OFFLINE
), tele
->name
.c_str());
2059 Player::SavePositionInDB(tele
->mapId
,tele
->position_x
,tele
->position_y
,tele
->position_z
,tele
->orientation
,
2060 MapManager::Instance().GetZoneId(tele
->mapId
,tele
->position_x
,tele
->position_y
,tele
->position_z
),target_guid
);
2066 //Teleport group to given game_tele.entry
2067 bool ChatHandler::HandleTeleGroupCommand(const char * args
)
2072 Player
*player
= getSelectedPlayer();
2075 SendSysMessage(LANG_NO_CHAR_SELECTED
);
2076 SetSentErrorMessage(true);
2080 // check online security
2081 if (HasLowerSecurity(player
, 0))
2084 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2085 GameTele
const* tele
= extractGameTeleFromLink((char*)args
);
2088 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
2089 SetSentErrorMessage(true);
2093 std::string nameLink
= GetNameLink(player
);
2095 Group
*grp
= player
->GetGroup();
2098 PSendSysMessage(LANG_NOT_IN_GROUP
,nameLink
.c_str());
2099 SetSentErrorMessage(true);
2103 for(GroupReference
*itr
= grp
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
2105 Player
*pl
= itr
->getSource();
2107 if(!pl
|| !pl
->GetSession() )
2110 // check online security
2111 if (HasLowerSecurity(pl
, 0))
2114 std::string plNameLink
= GetNameLink(pl
);
2116 if(pl
->IsBeingTeleported())
2118 PSendSysMessage(LANG_IS_TELEPORTED
, plNameLink
.c_str());
2122 PSendSysMessage(LANG_TELEPORTING_TO
, plNameLink
.c_str(),"", tele
->name
.c_str());
2123 if (needReportToTarget(pl
))
2124 ChatHandler(pl
).PSendSysMessage(LANG_TELEPORTED_TO_BY
, nameLink
.c_str());
2126 // stop flight if need
2127 if(pl
->isInFlight())
2129 pl
->GetMotionMaster()->MovementExpired();
2130 pl
->m_taxi
.ClearTaxiDestinations();
2132 // save only in non-flight case
2134 pl
->SaveRecallPosition();
2136 pl
->TeleportTo(tele
->mapId
, tele
->position_x
, tele
->position_y
, tele
->position_z
, tele
->orientation
);
2142 //Summon group of player
2143 bool ChatHandler::HandleGroupgoCommand(const char* args
)
2146 if(!extractPlayerTarget((char*)args
,&target
))
2149 // check online security
2150 if (HasLowerSecurity(target
, 0))
2153 Group
*grp
= target
->GetGroup();
2155 std::string nameLink
= GetNameLink(target
);
2159 PSendSysMessage(LANG_NOT_IN_GROUP
,nameLink
.c_str());
2160 SetSentErrorMessage(true);
2164 Map
* gmMap
= m_session
->GetPlayer()->GetMap();
2165 bool to_instance
= gmMap
->Instanceable();
2167 // we are in instance, and can summon only player in our group with us as lead
2168 if ( to_instance
&& (
2169 !m_session
->GetPlayer()->GetGroup() || (grp
->GetLeaderGUID() != m_session
->GetPlayer()->GetGUID()) ||
2170 (m_session
->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session
->GetPlayer()->GetGUID()) ) )
2171 // the last check is a bit excessive, but let it be, just in case
2173 SendSysMessage(LANG_CANNOT_SUMMON_TO_INST
);
2174 SetSentErrorMessage(true);
2178 for(GroupReference
*itr
= grp
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
2180 Player
*pl
= itr
->getSource();
2182 if(!pl
|| pl
==m_session
->GetPlayer() || !pl
->GetSession() )
2185 // check online security
2186 if (HasLowerSecurity(pl
, 0))
2189 std::string plNameLink
= GetNameLink(pl
);
2191 if(pl
->IsBeingTeleported()==true)
2193 PSendSysMessage(LANG_IS_TELEPORTED
, plNameLink
.c_str());
2194 SetSentErrorMessage(true);
2200 Map
* plMap
= pl
->GetMap();
2202 if ( plMap
->Instanceable() && plMap
->GetInstanceId() != gmMap
->GetInstanceId() )
2204 // cannot summon from instance to instance
2205 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST
,plNameLink
.c_str());
2206 SetSentErrorMessage(true);
2211 PSendSysMessage(LANG_SUMMONING
, plNameLink
.c_str(),"");
2212 if (needReportToTarget(pl
))
2213 ChatHandler(pl
).PSendSysMessage(LANG_SUMMONED_BY
, nameLink
.c_str());
2215 // stop flight if need
2216 if(pl
->isInFlight())
2218 pl
->GetMotionMaster()->MovementExpired();
2219 pl
->m_taxi
.ClearTaxiDestinations();
2221 // save only in non-flight case
2223 pl
->SaveRecallPosition();
2227 m_session
->GetPlayer()->GetClosePoint(x
,y
,z
,pl
->GetObjectSize());
2228 pl
->TeleportTo(m_session
->GetPlayer()->GetMapId(),x
,y
,z
,pl
->GetOrientation());
2234 bool ChatHandler::HandleGoTaxinodeCommand(const char* args
)
2236 Player
* _player
= m_session
->GetPlayer();
2241 char* cNodeId
= extractKeyFromLink((char*)args
,"Htaxinode");
2245 int32 i_nodeId
= atoi(cNodeId
);
2249 TaxiNodesEntry
const* node
= sTaxiNodesStore
.LookupEntry(i_nodeId
);
2252 PSendSysMessage(LANG_COMMAND_GOTAXINODENOTFOUND
,i_nodeId
);
2253 SetSentErrorMessage(true);
2257 if (node
->x
== 0.0f
&& node
->y
== 0.0f
&& node
->z
== 0.0f
||
2258 !MapManager::IsValidMapCoord(node
->map_id
,node
->x
,node
->y
,node
->z
))
2260 PSendSysMessage(LANG_INVALID_TARGET_COORD
,node
->x
,node
->y
,node
->map_id
);
2261 SetSentErrorMessage(true);
2265 // stop flight if need
2266 if (_player
->isInFlight())
2268 _player
->GetMotionMaster()->MovementExpired();
2269 _player
->m_taxi
.ClearTaxiDestinations();
2271 // save only in non-flight case
2273 _player
->SaveRecallPosition();
2275 _player
->TeleportTo(node
->map_id
, node
->x
, node
->y
, node
->z
, _player
->GetOrientation());
2279 //teleport at coordinates
2280 bool ChatHandler::HandleGoXYCommand(const char* args
)
2285 Player
* _player
= m_session
->GetPlayer();
2287 char* px
= strtok((char*)args
, " ");
2288 char* py
= strtok(NULL
, " ");
2289 char* pmapid
= strtok(NULL
, " ");
2294 float x
= (float)atof(px
);
2295 float y
= (float)atof(py
);
2298 mapid
= (uint32
)atoi(pmapid
);
2299 else mapid
= _player
->GetMapId();
2301 if(!MapManager::IsValidMapCoord(mapid
,x
,y
))
2303 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,mapid
);
2304 SetSentErrorMessage(true);
2308 // stop flight if need
2309 if(_player
->isInFlight())
2311 _player
->GetMotionMaster()->MovementExpired();
2312 _player
->m_taxi
.ClearTaxiDestinations();
2314 // save only in non-flight case
2316 _player
->SaveRecallPosition();
2318 Map
const *map
= MapManager::Instance().GetBaseMap(mapid
);
2319 float z
= std::max(map
->GetHeight(x
, y
, MAX_HEIGHT
), map
->GetWaterLevel(x
, y
));
2321 _player
->TeleportTo(mapid
, x
, y
, z
, _player
->GetOrientation());
2326 //teleport at coordinates, including Z
2327 bool ChatHandler::HandleGoXYZCommand(const char* args
)
2332 Player
* _player
= m_session
->GetPlayer();
2334 char* px
= strtok((char*)args
, " ");
2335 char* py
= strtok(NULL
, " ");
2336 char* pz
= strtok(NULL
, " ");
2337 char* pmapid
= strtok(NULL
, " ");
2339 if (!px
|| !py
|| !pz
)
2342 float x
= (float)atof(px
);
2343 float y
= (float)atof(py
);
2344 float z
= (float)atof(pz
);
2347 mapid
= (uint32
)atoi(pmapid
);
2349 mapid
= _player
->GetMapId();
2351 if(!MapManager::IsValidMapCoord(mapid
,x
,y
,z
))
2353 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,mapid
);
2354 SetSentErrorMessage(true);
2358 // stop flight if need
2359 if(_player
->isInFlight())
2361 _player
->GetMotionMaster()->MovementExpired();
2362 _player
->m_taxi
.ClearTaxiDestinations();
2364 // save only in non-flight case
2366 _player
->SaveRecallPosition();
2368 _player
->TeleportTo(mapid
, x
, y
, z
, _player
->GetOrientation());
2373 //teleport at coordinates
2374 bool ChatHandler::HandleGoZoneXYCommand(const char* args
)
2379 Player
* _player
= m_session
->GetPlayer();
2381 char* px
= strtok((char*)args
, " ");
2382 char* py
= strtok(NULL
, " ");
2383 char* tail
= strtok(NULL
,"");
2385 char* cAreaId
= extractKeyFromLink(tail
,"Harea"); // string or [name] Shift-click form |color|Harea:area_id|h[name]|h|r
2390 float x
= (float)atof(px
);
2391 float y
= (float)atof(py
);
2393 // prevent accept wrong numeric args
2394 if (x
==0.0f
&& *px
!='0' || y
==0.0f
&& *py
!='0')
2397 uint32 areaid
= cAreaId
? (uint32
)atoi(cAreaId
) : _player
->GetZoneId();
2399 AreaTableEntry
const* areaEntry
= GetAreaEntryByAreaID(areaid
);
2401 if( x
<0 || x
>100 || y
<0 || y
>100 || !areaEntry
)
2403 PSendSysMessage(LANG_INVALID_ZONE_COORD
,x
,y
,areaid
);
2404 SetSentErrorMessage(true);
2408 // update to parent zone if exist (client map show only zones without parents)
2409 AreaTableEntry
const* zoneEntry
= areaEntry
->zone
? GetAreaEntryByAreaID(areaEntry
->zone
) : areaEntry
;
2411 Map
const *map
= MapManager::Instance().GetBaseMap(zoneEntry
->mapid
);
2413 if(map
->Instanceable())
2415 PSendSysMessage(LANG_INVALID_ZONE_MAP
,areaEntry
->ID
,areaEntry
->area_name
[GetSessionDbcLocale()],map
->GetId(),map
->GetMapName());
2416 SetSentErrorMessage(true);
2420 Zone2MapCoordinates(x
,y
,zoneEntry
->ID
);
2422 if(!MapManager::IsValidMapCoord(zoneEntry
->mapid
,x
,y
))
2424 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,zoneEntry
->mapid
);
2425 SetSentErrorMessage(true);
2429 // stop flight if need
2430 if(_player
->isInFlight())
2432 _player
->GetMotionMaster()->MovementExpired();
2433 _player
->m_taxi
.ClearTaxiDestinations();
2435 // save only in non-flight case
2437 _player
->SaveRecallPosition();
2439 float z
= std::max(map
->GetHeight(x
, y
, MAX_HEIGHT
), map
->GetWaterLevel(x
, y
));
2440 _player
->TeleportTo(zoneEntry
->mapid
, x
, y
, z
, _player
->GetOrientation());
2446 bool ChatHandler::HandleGoGridCommand(const char* args
)
2448 if(!*args
) return false;
2449 Player
* _player
= m_session
->GetPlayer();
2451 char* px
= strtok((char*)args
, " ");
2452 char* py
= strtok(NULL
, " ");
2453 char* pmapid
= strtok(NULL
, " ");
2458 float grid_x
= (float)atof(px
);
2459 float grid_y
= (float)atof(py
);
2462 mapid
= (uint32
)atoi(pmapid
);
2463 else mapid
= _player
->GetMapId();
2466 float x
= (grid_x
-CENTER_GRID_ID
+0.5f
)*SIZE_OF_GRIDS
;
2467 float y
= (grid_y
-CENTER_GRID_ID
+0.5f
)*SIZE_OF_GRIDS
;
2469 if(!MapManager::IsValidMapCoord(mapid
,x
,y
))
2471 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,mapid
);
2472 SetSentErrorMessage(true);
2476 // stop flight if need
2477 if(_player
->isInFlight())
2479 _player
->GetMotionMaster()->MovementExpired();
2480 _player
->m_taxi
.ClearTaxiDestinations();
2482 // save only in non-flight case
2484 _player
->SaveRecallPosition();
2486 Map
const *map
= MapManager::Instance().GetBaseMap(mapid
);
2487 float z
= std::max(map
->GetHeight(x
, y
, MAX_HEIGHT
), map
->GetWaterLevel(x
, y
));
2488 _player
->TeleportTo(mapid
, x
, y
, z
, _player
->GetOrientation());
2493 bool ChatHandler::HandleModifyDrunkCommand(const char* args
)
2495 if(!*args
) return false;
2497 uint32 drunklevel
= (uint32
)atoi(args
);
2498 if(drunklevel
> 100)
2501 uint16 drunkMod
= drunklevel
* 0xFFFF / 100;
2503 m_session
->GetPlayer()->SetDrunkValue(drunkMod
);