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();
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();
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
, UI64FMTD
, &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
);
1046 Unit
* target
= getSelectedUnit();
1049 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1050 SetSentErrorMessage(true);
1054 if(target
->GetTypeId()==TYPEID_PLAYER
)
1056 // check online security
1057 if (HasLowerSecurity((Player
*)target
, 0))
1060 ((Player
*)target
)->SetFreeTalentPoints(tp
);
1061 ((Player
*)target
)->SendTalentsInfoData(false);
1064 else if(((Creature
*)target
)->isPet())
1066 Unit
*owner
= target
->GetOwner();
1067 if(owner
&& owner
->GetTypeId() == TYPEID_PLAYER
&& ((Pet
*)target
)->IsPermanentPetFor((Player
*)owner
))
1069 // check online security
1070 if (HasLowerSecurity((Player
*)owner
, 0))
1073 ((Pet
*)target
)->SetFreeTalentPoints(tp
);
1074 ((Player
*)owner
)->SendTalentsInfoData(true);
1079 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1080 SetSentErrorMessage(true);
1084 //Enable On\OFF all taxi paths
1085 bool ChatHandler::HandleTaxiCheatCommand(const char* args
)
1089 SendSysMessage(LANG_USE_BOL
);
1090 SetSentErrorMessage(true);
1094 std::string argstr
= (char*)args
;
1096 Player
*chr
= getSelectedPlayer();
1099 chr
=m_session
->GetPlayer();
1102 // check online security
1103 else if (HasLowerSecurity(chr
, 0))
1108 chr
->SetTaxiCheater(true);
1109 PSendSysMessage(LANG_YOU_GIVE_TAXIS
, GetNameLink(chr
).c_str());
1110 if (needReportToTarget(chr
))
1111 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_TAXIS_ADDED
, GetNameLink().c_str());
1115 if (argstr
== "off")
1117 chr
->SetTaxiCheater(false);
1118 PSendSysMessage(LANG_YOU_REMOVE_TAXIS
, GetNameLink(chr
).c_str());
1119 if (needReportToTarget(chr
))
1120 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_TAXIS_REMOVED
, GetNameLink().c_str());
1125 SendSysMessage(LANG_USE_BOL
);
1126 SetSentErrorMessage(true);
1130 //Edit Player Aspeed
1131 bool ChatHandler::HandleModifyASpeedCommand(const char* args
)
1136 float ASpeed
= (float)atof((char*)args
);
1138 if (ASpeed
> 10 || ASpeed
< 0.1)
1140 SendSysMessage(LANG_BAD_VALUE
);
1141 SetSentErrorMessage(true);
1145 Player
*chr
= getSelectedPlayer();
1148 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1149 SetSentErrorMessage(true);
1153 // check online security
1154 if (HasLowerSecurity(chr
, 0))
1157 std::string chrNameLink
= GetNameLink(chr
);
1159 if(chr
->isInFlight())
1161 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chrNameLink
.c_str());
1162 SetSentErrorMessage(true);
1166 PSendSysMessage(LANG_YOU_CHANGE_ASPEED
, ASpeed
, chrNameLink
.c_str());
1167 if (needReportToTarget(chr
))
1168 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_ASPEED_CHANGED
, GetNameLink().c_str(), ASpeed
);
1170 chr
->SetSpeed(MOVE_WALK
, ASpeed
,true);
1171 chr
->SetSpeed(MOVE_RUN
, ASpeed
,true);
1172 chr
->SetSpeed(MOVE_SWIM
, ASpeed
,true);
1173 //chr->SetSpeed(MOVE_TURN, ASpeed,true);
1174 chr
->SetSpeed(MOVE_FLIGHT
, ASpeed
,true);
1179 bool ChatHandler::HandleModifySpeedCommand(const char* args
)
1184 float Speed
= (float)atof((char*)args
);
1186 if (Speed
> 10 || Speed
< 0.1)
1188 SendSysMessage(LANG_BAD_VALUE
);
1189 SetSentErrorMessage(true);
1193 Player
*chr
= getSelectedPlayer();
1196 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1197 SetSentErrorMessage(true);
1201 // check online security
1202 if (HasLowerSecurity(chr
, 0))
1205 std::string chrNameLink
= GetNameLink(chr
);
1207 if(chr
->isInFlight())
1209 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chrNameLink
.c_str());
1210 SetSentErrorMessage(true);
1214 PSendSysMessage(LANG_YOU_CHANGE_SPEED
, Speed
, chrNameLink
.c_str());
1215 if (needReportToTarget(chr
))
1216 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_SPEED_CHANGED
, GetNameLink().c_str(), Speed
);
1218 chr
->SetSpeed(MOVE_RUN
,Speed
,true);
1223 //Edit Player Swim Speed
1224 bool ChatHandler::HandleModifySwimCommand(const char* args
)
1229 float Swim
= (float)atof((char*)args
);
1231 if (Swim
> 10.0f
|| Swim
< 0.01f
)
1233 SendSysMessage(LANG_BAD_VALUE
);
1234 SetSentErrorMessage(true);
1238 Player
*chr
= getSelectedPlayer();
1241 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1242 SetSentErrorMessage(true);
1246 // check online security
1247 if (HasLowerSecurity(chr
, 0))
1250 std::string chrNameLink
= GetNameLink(chr
);
1252 if(chr
->isInFlight())
1254 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chrNameLink
.c_str());
1255 SetSentErrorMessage(true);
1259 PSendSysMessage(LANG_YOU_CHANGE_SWIM_SPEED
, Swim
, chrNameLink
.c_str());
1260 if (needReportToTarget(chr
))
1261 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_SWIM_SPEED_CHANGED
, GetNameLink().c_str(), Swim
);
1263 chr
->SetSpeed(MOVE_SWIM
,Swim
,true);
1268 //Edit Player Walk Speed
1269 bool ChatHandler::HandleModifyBWalkCommand(const char* args
)
1274 float BSpeed
= (float)atof((char*)args
);
1276 if (BSpeed
> 10.0f
|| BSpeed
< 0.1f
)
1278 SendSysMessage(LANG_BAD_VALUE
);
1279 SetSentErrorMessage(true);
1283 Player
*chr
= getSelectedPlayer();
1286 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1287 SetSentErrorMessage(true);
1291 // check online security
1292 if (HasLowerSecurity(chr
, 0))
1295 std::string chrNameLink
= GetNameLink(chr
);
1297 if(chr
->isInFlight())
1299 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chrNameLink
.c_str());
1300 SetSentErrorMessage(true);
1304 PSendSysMessage(LANG_YOU_CHANGE_BACK_SPEED
, BSpeed
, chrNameLink
.c_str());
1305 if (needReportToTarget(chr
))
1306 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_BACK_SPEED_CHANGED
, GetNameLink().c_str(), BSpeed
);
1308 chr
->SetSpeed(MOVE_RUN_BACK
,BSpeed
,true);
1314 bool ChatHandler::HandleModifyFlyCommand(const char* args
)
1319 float FSpeed
= (float)atof((char*)args
);
1321 if (FSpeed
> 10.0f
|| FSpeed
< 0.1f
)
1323 SendSysMessage(LANG_BAD_VALUE
);
1324 SetSentErrorMessage(true);
1328 Player
*chr
= getSelectedPlayer();
1331 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1332 SetSentErrorMessage(true);
1336 // check online security
1337 if (HasLowerSecurity(chr
, 0))
1340 PSendSysMessage(LANG_YOU_CHANGE_FLY_SPEED
, FSpeed
, GetNameLink(chr
).c_str());
1341 if (needReportToTarget(chr
))
1342 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_FLY_SPEED_CHANGED
, GetNameLink().c_str(), FSpeed
);
1344 chr
->SetSpeed(MOVE_FLIGHT
,FSpeed
,true);
1350 bool ChatHandler::HandleModifyScaleCommand(const char* args
)
1355 float Scale
= (float)atof((char*)args
);
1356 if (Scale
> 3.0f
|| Scale
<= 0.0f
)
1358 SendSysMessage(LANG_BAD_VALUE
);
1359 SetSentErrorMessage(true);
1363 Player
*chr
= getSelectedPlayer();
1366 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1367 SetSentErrorMessage(true);
1371 // check online security
1372 if (HasLowerSecurity(chr
, 0))
1375 PSendSysMessage(LANG_YOU_CHANGE_SIZE
, Scale
, GetNameLink(chr
).c_str());
1376 if (needReportToTarget(chr
))
1377 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_SIZE_CHANGED
, GetNameLink().c_str(), Scale
);
1379 chr
->SetFloatValue(OBJECT_FIELD_SCALE_X
, Scale
);
1384 //Enable Player mount
1385 bool ChatHandler::HandleModifyMountCommand(const char* args
)
1391 float speed
= (float)15;
1394 num
= atoi((char*)args
);
1605 SendSysMessage(LANG_NO_MOUNT
);
1606 SetSentErrorMessage(true);
1610 Player
*chr
= getSelectedPlayer();
1613 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1614 SetSentErrorMessage(true);
1618 // check online security
1619 if (HasLowerSecurity(chr
, 0))
1622 PSendSysMessage(LANG_YOU_GIVE_MOUNT
, GetNameLink(chr
).c_str());
1623 if (needReportToTarget(chr
))
1624 ChatHandler(chr
).PSendSysMessage(LANG_MOUNT_GIVED
, GetNameLink().c_str());
1626 chr
->SetUInt32Value(UNIT_FIELD_FLAGS
, UNIT_FLAG_PVP
);
1629 WorldPacket
data( SMSG_FORCE_RUN_SPEED_CHANGE
, (8+4+1+4) );
1630 data
.append(chr
->GetPackGUID());
1632 data
<< (uint8
)0; //new 2.1.0
1633 data
<< float(speed
);
1634 chr
->SendMessageToSet( &data
, true );
1636 data
.Initialize( SMSG_FORCE_SWIM_SPEED_CHANGE
, (8+4+4) );
1637 data
.append(chr
->GetPackGUID());
1639 data
<< float(speed
);
1640 chr
->SendMessageToSet( &data
, true );
1646 bool ChatHandler::HandleModifyMoneyCommand(const char* args
)
1651 Player
*chr
= getSelectedPlayer();
1654 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1655 SetSentErrorMessage(true);
1659 // check online security
1660 if (HasLowerSecurity(chr
, 0))
1663 int32 addmoney
= atoi((char*)args
);
1665 uint32 moneyuser
= chr
->GetMoney();
1669 int32 newmoney
= int32(moneyuser
) + addmoney
;
1671 sLog
.outDetail(GetMangosString(LANG_CURRENT_MONEY
), moneyuser
, addmoney
, newmoney
);
1674 PSendSysMessage(LANG_YOU_TAKE_ALL_MONEY
, GetNameLink(chr
).c_str());
1675 if (needReportToTarget(chr
))
1676 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_ALL_MONEY_GONE
, GetNameLink().c_str());
1682 if (newmoney
> MAX_MONEY_AMOUNT
)
1683 newmoney
= MAX_MONEY_AMOUNT
;
1685 PSendSysMessage(LANG_YOU_TAKE_MONEY
, abs(addmoney
), GetNameLink(chr
).c_str());
1686 if (needReportToTarget(chr
))
1687 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_MONEY_TAKEN
, GetNameLink().c_str(), abs(addmoney
));
1688 chr
->SetMoney( newmoney
);
1693 PSendSysMessage(LANG_YOU_GIVE_MONEY
, addmoney
, GetNameLink(chr
).c_str());
1694 if (needReportToTarget(chr
))
1695 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_MONEY_GIVEN
, GetNameLink().c_str(), addmoney
);
1697 if (addmoney
>=MAX_MONEY_AMOUNT
)
1698 chr
->SetMoney(MAX_MONEY_AMOUNT
);
1700 chr
->ModifyMoney( addmoney
);
1703 sLog
.outDetail(GetMangosString(LANG_NEW_MONEY
), moneyuser
, addmoney
, chr
->GetMoney() );
1709 bool ChatHandler::HandleModifyBitCommand(const char* args
)
1714 Unit
*unit
= getSelectedUnit();
1717 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1718 SetSentErrorMessage(true);
1722 // check online security
1723 if (unit
->GetTypeId() == TYPEID_PLAYER
&& HasLowerSecurity((Player
*)unit
, 0))
1726 char* pField
= strtok((char*)args
, " ");
1730 char* pBit
= strtok(NULL
, " ");
1734 uint16 field
= atoi(pField
);
1735 uint32 bit
= atoi(pBit
);
1737 if (field
< OBJECT_END
|| field
>= unit
->GetValuesCount())
1739 SendSysMessage(LANG_BAD_VALUE
);
1740 SetSentErrorMessage(true);
1743 if (bit
< 1 || bit
> 32)
1745 SendSysMessage(LANG_BAD_VALUE
);
1746 SetSentErrorMessage(true);
1750 if ( unit
->HasFlag( field
, (1<<(bit
-1)) ) )
1752 unit
->RemoveFlag( field
, (1<<(bit
-1)) );
1753 PSendSysMessage(LANG_REMOVE_BIT
, bit
, field
);
1757 unit
->SetFlag( field
, (1<<(bit
-1)) );
1758 PSendSysMessage(LANG_SET_BIT
, bit
, field
);
1763 bool ChatHandler::HandleModifyHonorCommand (const char* args
)
1768 Player
*target
= getSelectedPlayer();
1771 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1772 SetSentErrorMessage(true);
1776 // check online security
1777 if (HasLowerSecurity(target
, 0))
1780 int32 amount
= (uint32
)atoi(args
);
1782 target
->ModifyHonorPoints(amount
);
1784 PSendSysMessage(LANG_COMMAND_MODIFY_HONOR
, GetNameLink(target
).c_str(), target
->GetHonorPoints());
1789 bool ChatHandler::HandleTeleCommand(const char * args
)
1794 Player
* _player
= m_session
->GetPlayer();
1796 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
1797 GameTele
const* tele
= extractGameTeleFromLink((char*)args
);
1801 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
1802 SetSentErrorMessage(true);
1806 // stop flight if need
1807 if(_player
->isInFlight())
1809 _player
->GetMotionMaster()->MovementExpired();
1810 _player
->m_taxi
.ClearTaxiDestinations();
1812 // save only in non-flight case
1814 _player
->SaveRecallPosition();
1816 _player
->TeleportTo(tele
->mapId
, tele
->position_x
, tele
->position_y
, tele
->position_z
, tele
->orientation
);
1820 bool ChatHandler::HandleLookupAreaCommand(const char* args
)
1825 std::string namepart
= args
;
1826 std::wstring wnamepart
;
1828 if (!Utf8toWStr (namepart
,wnamepart
))
1831 uint32 counter
= 0; // Counter for figure out that we found smth.
1833 // converting string that we try to find to lower case
1834 wstrToLower (wnamepart
);
1836 // Search in AreaTable.dbc
1837 for (uint32 areaflag
= 0; areaflag
< sAreaStore
.GetNumRows (); ++areaflag
)
1839 AreaTableEntry
const *areaEntry
= sAreaStore
.LookupEntry (areaflag
);
1842 int loc
= GetSessionDbcLocale ();
1843 std::string name
= areaEntry
->area_name
[loc
];
1847 if (!Utf8FitTo (name
, wnamepart
))
1850 for(; loc
< MAX_LOCALE
; ++loc
)
1852 if (loc
==GetSessionDbcLocale ())
1855 name
= areaEntry
->area_name
[loc
];
1859 if (Utf8FitTo (name
, wnamepart
))
1864 if (loc
< MAX_LOCALE
)
1866 // send area in "id - [name]" format
1867 std::ostringstream ss
;
1869 ss
<< areaEntry
->ID
<< " - |cffffffff|Harea:" << areaEntry
->ID
<< "|h[" << name
<< " " << localeNames
[loc
]<< "]|h|r";
1871 ss
<< areaEntry
->ID
<< " - " << name
<< " " << localeNames
[loc
];
1873 SendSysMessage (ss
.str ().c_str());
1880 if (counter
== 0) // if counter == 0 then we found nth
1881 SendSysMessage (LANG_COMMAND_NOAREAFOUND
);
1886 //Find tele in game_tele order by name
1887 bool ChatHandler::HandleLookupTeleCommand(const char * args
)
1891 SendSysMessage(LANG_COMMAND_TELE_PARAMETER
);
1892 SetSentErrorMessage(true);
1896 char const* str
= strtok((char*)args
, " ");
1900 std::string namepart
= str
;
1901 std::wstring wnamepart
;
1903 if(!Utf8toWStr(namepart
,wnamepart
))
1906 // converting string that we try to find to lower case
1907 wstrToLower( wnamepart
);
1909 std::ostringstream reply
;
1911 GameTeleMap
const & teleMap
= objmgr
.GetGameTeleMap();
1912 for(GameTeleMap::const_iterator itr
= teleMap
.begin(); itr
!= teleMap
.end(); ++itr
)
1914 GameTele
const* tele
= &itr
->second
;
1916 if(tele
->wnameLow
.find(wnamepart
) == std::wstring::npos
)
1920 reply
<< " |cffffffff|Htele:" << itr
->first
<< "|h[" << tele
->name
<< "]|h|r\n";
1922 reply
<< " " << itr
->first
<< " " << tele
->name
<< "\n";
1925 if(reply
.str().empty())
1926 SendSysMessage(LANG_COMMAND_TELE_NOLOCATION
);
1928 PSendSysMessage(LANG_COMMAND_TELE_LOCATION
,reply
.str().c_str());
1933 //Enable\Dissable accept whispers (for GM)
1934 bool ChatHandler::HandleWhispersCommand(const char* args
)
1938 PSendSysMessage(LANG_COMMAND_WHISPERACCEPTING
, m_session
->GetPlayer()->isAcceptWhispers() ? GetMangosString(LANG_ON
) : GetMangosString(LANG_OFF
));
1942 std::string argstr
= (char*)args
;
1946 m_session
->GetPlayer()->SetAcceptWhispers(true);
1947 SendSysMessage(LANG_COMMAND_WHISPERON
);
1952 if (argstr
== "off")
1954 m_session
->GetPlayer()->SetAcceptWhispers(false);
1955 SendSysMessage(LANG_COMMAND_WHISPEROFF
);
1959 SendSysMessage(LANG_USE_BOL
);
1960 SetSentErrorMessage(true);
1964 //Save all players in the world
1965 bool ChatHandler::HandleSaveAllCommand(const char* /*args*/)
1967 ObjectAccessor::Instance().SaveAllPlayers();
1968 SendSysMessage(LANG_PLAYERS_SAVED
);
1972 //Send mail by command
1973 bool ChatHandler::HandleSendMailCommand(const char* args
)
1975 // format: name "subject text" "mail text"
1978 std::string target_name
;
1979 if(!extractPlayerTarget((char*)args
,&target
,&target_guid
,&target_name
))
1982 char* tail1
= strtok(NULL
, "");
1986 char* msgSubject
= extractQuotedArg(tail1
);
1990 char* tail2
= strtok(NULL
, "");
1994 char* msgText
= extractQuotedArg(tail2
);
1998 // msgSubject, msgText isn't NUL after prev. check
1999 std::string subject
= msgSubject
;
2000 std::string text
= msgText
;
2002 // from console show not existed sender
2003 uint32 sender_guidlo
= m_session
? m_session
->GetPlayer()->GetGUIDLow() : 0;
2005 uint32 messagetype
= MAIL_NORMAL
;
2006 uint32 stationery
= MAIL_STATIONERY_GM
;
2007 uint32 itemTextId
= !text
.empty() ? objmgr
.CreateItemText( text
) : 0;
2009 WorldSession::SendMailTo(target
,messagetype
, stationery
, sender_guidlo
, GUID_LOPART(target_guid
), subject
, itemTextId
, NULL
, 0, 0, MAIL_CHECK_MASK_NONE
);
2011 std::string nameLink
= playerLink(target_name
);
2012 PSendSysMessage(LANG_MAIL_SENT
, nameLink
.c_str());
2016 // teleport player to given game_tele.entry
2017 bool ChatHandler::HandleTeleNameCommand(const char * args
)
2021 extractOptFirstArg((char*)args
,&nameStr
,&teleStr
);
2027 std::string target_name
;
2028 if(!extractPlayerTarget(nameStr
,&target
,&target_guid
,&target_name
))
2031 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2032 GameTele
const* tele
= extractGameTeleFromLink(teleStr
);
2035 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
2036 SetSentErrorMessage(true);
2042 // check online security
2043 if (HasLowerSecurity(target
, 0))
2046 std::string chrNameLink
= playerLink(target_name
);
2048 if(target
->IsBeingTeleported()==true)
2050 PSendSysMessage(LANG_IS_TELEPORTED
, chrNameLink
.c_str());
2051 SetSentErrorMessage(true);
2055 PSendSysMessage(LANG_TELEPORTING_TO
, chrNameLink
.c_str(),"", tele
->name
.c_str());
2056 if (needReportToTarget(target
))
2057 ChatHandler(target
).PSendSysMessage(LANG_TELEPORTED_TO_BY
, GetNameLink().c_str());
2059 // stop flight if need
2060 if(target
->isInFlight())
2062 target
->GetMotionMaster()->MovementExpired();
2063 target
->m_taxi
.ClearTaxiDestinations();
2065 // save only in non-flight case
2067 target
->SaveRecallPosition();
2069 target
->TeleportTo(tele
->mapId
,tele
->position_x
,tele
->position_y
,tele
->position_z
,tele
->orientation
);
2073 // check offline security
2074 if (HasLowerSecurity(NULL
, target_guid
))
2077 std::string nameLink
= playerLink(target_name
);
2079 PSendSysMessage(LANG_TELEPORTING_TO
, nameLink
.c_str(), GetMangosString(LANG_OFFLINE
), tele
->name
.c_str());
2080 Player::SavePositionInDB(tele
->mapId
,tele
->position_x
,tele
->position_y
,tele
->position_z
,tele
->orientation
,
2081 MapManager::Instance().GetZoneId(tele
->mapId
,tele
->position_x
,tele
->position_y
,tele
->position_z
),target_guid
);
2087 //Teleport group to given game_tele.entry
2088 bool ChatHandler::HandleTeleGroupCommand(const char * args
)
2093 Player
*player
= getSelectedPlayer();
2096 SendSysMessage(LANG_NO_CHAR_SELECTED
);
2097 SetSentErrorMessage(true);
2101 // check online security
2102 if (HasLowerSecurity(player
, 0))
2105 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2106 GameTele
const* tele
= extractGameTeleFromLink((char*)args
);
2109 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
2110 SetSentErrorMessage(true);
2114 std::string nameLink
= GetNameLink(player
);
2116 Group
*grp
= player
->GetGroup();
2119 PSendSysMessage(LANG_NOT_IN_GROUP
,nameLink
.c_str());
2120 SetSentErrorMessage(true);
2124 for(GroupReference
*itr
= grp
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
2126 Player
*pl
= itr
->getSource();
2128 if(!pl
|| !pl
->GetSession() )
2131 // check online security
2132 if (HasLowerSecurity(pl
, 0))
2135 std::string plNameLink
= GetNameLink(pl
);
2137 if(pl
->IsBeingTeleported())
2139 PSendSysMessage(LANG_IS_TELEPORTED
, plNameLink
.c_str());
2143 PSendSysMessage(LANG_TELEPORTING_TO
, plNameLink
.c_str(),"", tele
->name
.c_str());
2144 if (needReportToTarget(pl
))
2145 ChatHandler(pl
).PSendSysMessage(LANG_TELEPORTED_TO_BY
, nameLink
.c_str());
2147 // stop flight if need
2148 if(pl
->isInFlight())
2150 pl
->GetMotionMaster()->MovementExpired();
2151 pl
->m_taxi
.ClearTaxiDestinations();
2153 // save only in non-flight case
2155 pl
->SaveRecallPosition();
2157 pl
->TeleportTo(tele
->mapId
, tele
->position_x
, tele
->position_y
, tele
->position_z
, tele
->orientation
);
2163 //Summon group of player
2164 bool ChatHandler::HandleGroupgoCommand(const char* args
)
2167 if(!extractPlayerTarget((char*)args
,&target
))
2170 // check online security
2171 if (HasLowerSecurity(target
, 0))
2174 Group
*grp
= target
->GetGroup();
2176 std::string nameLink
= GetNameLink(target
);
2180 PSendSysMessage(LANG_NOT_IN_GROUP
,nameLink
.c_str());
2181 SetSentErrorMessage(true);
2185 Map
* gmMap
= m_session
->GetPlayer()->GetMap();
2186 bool to_instance
= gmMap
->Instanceable();
2188 // we are in instance, and can summon only player in our group with us as lead
2189 if ( to_instance
&& (
2190 !m_session
->GetPlayer()->GetGroup() || (grp
->GetLeaderGUID() != m_session
->GetPlayer()->GetGUID()) ||
2191 (m_session
->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session
->GetPlayer()->GetGUID()) ) )
2192 // the last check is a bit excessive, but let it be, just in case
2194 SendSysMessage(LANG_CANNOT_SUMMON_TO_INST
);
2195 SetSentErrorMessage(true);
2199 for(GroupReference
*itr
= grp
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
2201 Player
*pl
= itr
->getSource();
2203 if(!pl
|| pl
==m_session
->GetPlayer() || !pl
->GetSession() )
2206 // check online security
2207 if (HasLowerSecurity(pl
, 0))
2210 std::string plNameLink
= GetNameLink(pl
);
2212 if(pl
->IsBeingTeleported()==true)
2214 PSendSysMessage(LANG_IS_TELEPORTED
, plNameLink
.c_str());
2215 SetSentErrorMessage(true);
2221 Map
* plMap
= pl
->GetMap();
2223 if ( plMap
->Instanceable() && plMap
->GetInstanceId() != gmMap
->GetInstanceId() )
2225 // cannot summon from instance to instance
2226 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST
,plNameLink
.c_str());
2227 SetSentErrorMessage(true);
2232 PSendSysMessage(LANG_SUMMONING
, plNameLink
.c_str(),"");
2233 if (needReportToTarget(pl
))
2234 ChatHandler(pl
).PSendSysMessage(LANG_SUMMONED_BY
, nameLink
.c_str());
2236 // stop flight if need
2237 if(pl
->isInFlight())
2239 pl
->GetMotionMaster()->MovementExpired();
2240 pl
->m_taxi
.ClearTaxiDestinations();
2242 // save only in non-flight case
2244 pl
->SaveRecallPosition();
2248 m_session
->GetPlayer()->GetClosePoint(x
,y
,z
,pl
->GetObjectSize());
2249 pl
->TeleportTo(m_session
->GetPlayer()->GetMapId(),x
,y
,z
,pl
->GetOrientation());
2255 bool ChatHandler::HandleGoTaxinodeCommand(const char* args
)
2257 Player
* _player
= m_session
->GetPlayer();
2262 char* cNodeId
= extractKeyFromLink((char*)args
,"Htaxinode");
2266 int32 i_nodeId
= atoi(cNodeId
);
2270 TaxiNodesEntry
const* node
= sTaxiNodesStore
.LookupEntry(i_nodeId
);
2273 PSendSysMessage(LANG_COMMAND_GOTAXINODENOTFOUND
,i_nodeId
);
2274 SetSentErrorMessage(true);
2278 if (node
->x
== 0.0f
&& node
->y
== 0.0f
&& node
->z
== 0.0f
||
2279 !MapManager::IsValidMapCoord(node
->map_id
,node
->x
,node
->y
,node
->z
))
2281 PSendSysMessage(LANG_INVALID_TARGET_COORD
,node
->x
,node
->y
,node
->map_id
);
2282 SetSentErrorMessage(true);
2286 // stop flight if need
2287 if (_player
->isInFlight())
2289 _player
->GetMotionMaster()->MovementExpired();
2290 _player
->m_taxi
.ClearTaxiDestinations();
2292 // save only in non-flight case
2294 _player
->SaveRecallPosition();
2296 _player
->TeleportTo(node
->map_id
, node
->x
, node
->y
, node
->z
, _player
->GetOrientation());
2300 //teleport at coordinates
2301 bool ChatHandler::HandleGoXYCommand(const char* args
)
2306 Player
* _player
= m_session
->GetPlayer();
2308 char* px
= strtok((char*)args
, " ");
2309 char* py
= strtok(NULL
, " ");
2310 char* pmapid
= strtok(NULL
, " ");
2315 float x
= (float)atof(px
);
2316 float y
= (float)atof(py
);
2319 mapid
= (uint32
)atoi(pmapid
);
2320 else mapid
= _player
->GetMapId();
2322 if(!MapManager::IsValidMapCoord(mapid
,x
,y
))
2324 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,mapid
);
2325 SetSentErrorMessage(true);
2329 // stop flight if need
2330 if(_player
->isInFlight())
2332 _player
->GetMotionMaster()->MovementExpired();
2333 _player
->m_taxi
.ClearTaxiDestinations();
2335 // save only in non-flight case
2337 _player
->SaveRecallPosition();
2339 Map
const *map
= MapManager::Instance().CreateBaseMap(mapid
);
2340 float z
= std::max(map
->GetHeight(x
, y
, MAX_HEIGHT
), map
->GetWaterLevel(x
, y
));
2342 _player
->TeleportTo(mapid
, x
, y
, z
, _player
->GetOrientation());
2347 //teleport at coordinates, including Z
2348 bool ChatHandler::HandleGoXYZCommand(const char* args
)
2353 Player
* _player
= m_session
->GetPlayer();
2355 char* px
= strtok((char*)args
, " ");
2356 char* py
= strtok(NULL
, " ");
2357 char* pz
= strtok(NULL
, " ");
2358 char* pmapid
= strtok(NULL
, " ");
2360 if (!px
|| !py
|| !pz
)
2363 float x
= (float)atof(px
);
2364 float y
= (float)atof(py
);
2365 float z
= (float)atof(pz
);
2368 mapid
= (uint32
)atoi(pmapid
);
2370 mapid
= _player
->GetMapId();
2372 if(!MapManager::IsValidMapCoord(mapid
,x
,y
,z
))
2374 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,mapid
);
2375 SetSentErrorMessage(true);
2379 // stop flight if need
2380 if(_player
->isInFlight())
2382 _player
->GetMotionMaster()->MovementExpired();
2383 _player
->m_taxi
.ClearTaxiDestinations();
2385 // save only in non-flight case
2387 _player
->SaveRecallPosition();
2389 _player
->TeleportTo(mapid
, x
, y
, z
, _player
->GetOrientation());
2394 //teleport at coordinates
2395 bool ChatHandler::HandleGoZoneXYCommand(const char* args
)
2400 Player
* _player
= m_session
->GetPlayer();
2402 char* px
= strtok((char*)args
, " ");
2403 char* py
= strtok(NULL
, " ");
2404 char* tail
= strtok(NULL
,"");
2406 char* cAreaId
= extractKeyFromLink(tail
,"Harea"); // string or [name] Shift-click form |color|Harea:area_id|h[name]|h|r
2411 float x
= (float)atof(px
);
2412 float y
= (float)atof(py
);
2414 // prevent accept wrong numeric args
2415 if (x
==0.0f
&& *px
!='0' || y
==0.0f
&& *py
!='0')
2418 uint32 areaid
= cAreaId
? (uint32
)atoi(cAreaId
) : _player
->GetZoneId();
2420 AreaTableEntry
const* areaEntry
= GetAreaEntryByAreaID(areaid
);
2422 if( x
<0 || x
>100 || y
<0 || y
>100 || !areaEntry
)
2424 PSendSysMessage(LANG_INVALID_ZONE_COORD
,x
,y
,areaid
);
2425 SetSentErrorMessage(true);
2429 // update to parent zone if exist (client map show only zones without parents)
2430 AreaTableEntry
const* zoneEntry
= areaEntry
->zone
? GetAreaEntryByAreaID(areaEntry
->zone
) : areaEntry
;
2432 Map
const *map
= MapManager::Instance().CreateBaseMap(zoneEntry
->mapid
);
2434 if(map
->Instanceable())
2436 PSendSysMessage(LANG_INVALID_ZONE_MAP
,areaEntry
->ID
,areaEntry
->area_name
[GetSessionDbcLocale()],map
->GetId(),map
->GetMapName());
2437 SetSentErrorMessage(true);
2441 Zone2MapCoordinates(x
,y
,zoneEntry
->ID
);
2443 if(!MapManager::IsValidMapCoord(zoneEntry
->mapid
,x
,y
))
2445 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,zoneEntry
->mapid
);
2446 SetSentErrorMessage(true);
2450 // stop flight if need
2451 if(_player
->isInFlight())
2453 _player
->GetMotionMaster()->MovementExpired();
2454 _player
->m_taxi
.ClearTaxiDestinations();
2456 // save only in non-flight case
2458 _player
->SaveRecallPosition();
2460 float z
= std::max(map
->GetHeight(x
, y
, MAX_HEIGHT
), map
->GetWaterLevel(x
, y
));
2461 _player
->TeleportTo(zoneEntry
->mapid
, x
, y
, z
, _player
->GetOrientation());
2467 bool ChatHandler::HandleGoGridCommand(const char* args
)
2469 if(!*args
) return false;
2470 Player
* _player
= m_session
->GetPlayer();
2472 char* px
= strtok((char*)args
, " ");
2473 char* py
= strtok(NULL
, " ");
2474 char* pmapid
= strtok(NULL
, " ");
2479 float grid_x
= (float)atof(px
);
2480 float grid_y
= (float)atof(py
);
2483 mapid
= (uint32
)atoi(pmapid
);
2484 else mapid
= _player
->GetMapId();
2487 float x
= (grid_x
-CENTER_GRID_ID
+0.5f
)*SIZE_OF_GRIDS
;
2488 float y
= (grid_y
-CENTER_GRID_ID
+0.5f
)*SIZE_OF_GRIDS
;
2490 if(!MapManager::IsValidMapCoord(mapid
,x
,y
))
2492 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,mapid
);
2493 SetSentErrorMessage(true);
2497 // stop flight if need
2498 if(_player
->isInFlight())
2500 _player
->GetMotionMaster()->MovementExpired();
2501 _player
->m_taxi
.ClearTaxiDestinations();
2503 // save only in non-flight case
2505 _player
->SaveRecallPosition();
2507 Map
const *map
= MapManager::Instance().CreateBaseMap(mapid
);
2508 float z
= std::max(map
->GetHeight(x
, y
, MAX_HEIGHT
), map
->GetWaterLevel(x
, y
));
2509 _player
->TeleportTo(mapid
, x
, y
, z
, _player
->GetOrientation());
2514 bool ChatHandler::HandleModifyDrunkCommand(const char* args
)
2516 if(!*args
) return false;
2518 uint32 drunklevel
= (uint32
)atoi(args
);
2519 if(drunklevel
> 100)
2522 uint16 drunkMod
= drunklevel
* 0xFFFF / 100;
2524 m_session
->GetPlayer()->SetDrunkValue(drunkMod
);