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 bool ChatHandler::HandleNpcSayCommand(const char* args
)
44 Creature
* pCreature
= getSelectedCreature();
47 SendSysMessage(LANG_SELECT_CREATURE
);
48 SetSentErrorMessage(true);
52 pCreature
->Say(args
, LANG_UNIVERSAL
, 0);
57 bool ChatHandler::HandleNpcYellCommand(const char* args
)
62 Creature
* pCreature
= getSelectedCreature();
65 SendSysMessage(LANG_SELECT_CREATURE
);
66 SetSentErrorMessage(true);
70 pCreature
->Yell(args
, LANG_UNIVERSAL
, 0);
75 //show text emote by creature in chat
76 bool ChatHandler::HandleNpcTextEmoteCommand(const char* args
)
81 Creature
* pCreature
= getSelectedCreature();
85 SendSysMessage(LANG_SELECT_CREATURE
);
86 SetSentErrorMessage(true);
90 pCreature
->TextEmote(args
, 0);
95 // make npc whisper to player
96 bool ChatHandler::HandleNpcWhisperCommand(const char* args
)
101 char* receiver_str
= strtok((char*)args
, " ");
102 char* text
= strtok(NULL
, "");
104 uint64 guid
= m_session
->GetPlayer()->GetSelection();
105 Creature
* pCreature
= ObjectAccessor::GetCreature(*m_session
->GetPlayer(), guid
);
107 if(!pCreature
|| !receiver_str
|| !text
)
112 uint64 receiver_guid
= atol(receiver_str
);
114 // check online security
115 if (HasLowerSecurity(objmgr
.GetPlayer(receiver_guid
), 0))
118 pCreature
->Whisper(text
,receiver_guid
);
124 bool ChatHandler::HandleAnnounceCommand(const char* args
)
129 sWorld
.SendWorldText(LANG_SYSTEMMESSAGE
,args
);
133 //notification player at the screen
134 bool ChatHandler::HandleNotifyCommand(const char* args
)
139 std::string str
= GetMangosString(LANG_GLOBAL_NOTIFY
);
142 WorldPacket
data(SMSG_NOTIFICATION
, (str
.size()+1));
144 sWorld
.SendGlobalMessage(&data
);
149 //Enable\Dissable GM Mode
150 bool ChatHandler::HandleGMmodeCommand(const char* args
)
154 if(m_session
->GetPlayer()->isGameMaster())
155 m_session
->SendNotification(LANG_GM_ON
);
157 m_session
->SendNotification(LANG_GM_OFF
);
161 std::string argstr
= (char*)args
;
165 m_session
->GetPlayer()->SetGameMaster(true);
166 m_session
->SendNotification(LANG_GM_ON
);
168 VMAP::IVMapManager
*vMapManager
= VMAP::VMapFactory::createOrGetVMapManager();
169 vMapManager
->processCommand("stoplog");
176 m_session
->GetPlayer()->SetGameMaster(false);
177 m_session
->SendNotification(LANG_GM_OFF
);
179 VMAP::IVMapManager
*vMapManager
= VMAP::VMapFactory::createOrGetVMapManager();
180 vMapManager
->processCommand("startlog");
185 SendSysMessage(LANG_USE_BOL
);
186 SetSentErrorMessage(true);
190 // Enables or disables hiding of the staff badge
191 bool ChatHandler::HandleGMChatCommand(const char* args
)
195 if(m_session
->GetPlayer()->isGMChat())
196 m_session
->SendNotification(LANG_GM_CHAT_ON
);
198 m_session
->SendNotification(LANG_GM_CHAT_OFF
);
202 std::string argstr
= (char*)args
;
206 m_session
->GetPlayer()->SetGMChat(true);
207 m_session
->SendNotification(LANG_GM_CHAT_ON
);
213 m_session
->GetPlayer()->SetGMChat(false);
214 m_session
->SendNotification(LANG_GM_CHAT_OFF
);
218 SendSysMessage(LANG_USE_BOL
);
219 SetSentErrorMessage(true);
223 //Enable\Dissable Invisible mode
224 bool ChatHandler::HandleVisibleCommand(const char* args
)
228 PSendSysMessage(LANG_YOU_ARE
, m_session
->GetPlayer()->isGMVisible() ? GetMangosString(LANG_VISIBLE
) : GetMangosString(LANG_INVISIBLE
));
232 std::string argstr
= (char*)args
;
236 m_session
->GetPlayer()->SetGMVisible(true);
237 m_session
->SendNotification(LANG_INVISIBLE_VISIBLE
);
243 m_session
->SendNotification(LANG_INVISIBLE_INVISIBLE
);
244 m_session
->GetPlayer()->SetGMVisible(false);
248 SendSysMessage(LANG_USE_BOL
);
249 SetSentErrorMessage(true);
253 bool ChatHandler::HandleGPSCommand(const char* args
)
255 WorldObject
*obj
= NULL
;
258 std::string name
= args
;
259 if(normalizePlayerName(name
))
260 obj
= objmgr
.GetPlayer(name
.c_str());
264 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
265 SetSentErrorMessage(true);
271 obj
= getSelectedUnit();
275 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
276 SetSentErrorMessage(true);
280 CellPair cell_val
= MaNGOS::ComputeCellPair(obj
->GetPositionX(), obj
->GetPositionY());
283 uint32 zone_id
= obj
->GetZoneId();
284 uint32 area_id
= obj
->GetAreaId();
286 MapEntry
const* mapEntry
= sMapStore
.LookupEntry(obj
->GetMapId());
287 AreaTableEntry
const* zoneEntry
= GetAreaEntryByAreaID(zone_id
);
288 AreaTableEntry
const* areaEntry
= GetAreaEntryByAreaID(area_id
);
290 float zone_x
= obj
->GetPositionX();
291 float zone_y
= obj
->GetPositionY();
293 Map2ZoneCoordinates(zone_x
,zone_y
,zone_id
);
295 Map
const *map
= obj
->GetMap();
296 float ground_z
= map
->GetHeight(obj
->GetPositionX(), obj
->GetPositionY(), MAX_HEIGHT
);
297 float floor_z
= map
->GetHeight(obj
->GetPositionX(), obj
->GetPositionY(), obj
->GetPositionZ());
299 GridPair p
= MaNGOS::ComputeGridPair(obj
->GetPositionX(), obj
->GetPositionY());
304 uint32 have_map
= Map::ExistMap(obj
->GetMapId(),gx
,gy
) ? 1 : 0;
305 uint32 have_vmap
= Map::ExistVMap(obj
->GetMapId(),gx
,gy
) ? 1 : 0;
307 PSendSysMessage(LANG_MAP_POSITION
,
308 obj
->GetMapId(), (mapEntry
? mapEntry
->name
[m_session
->GetSessionDbcLocale()] : "<unknown>" ),
309 zone_id
, (zoneEntry
? zoneEntry
->area_name
[m_session
->GetSessionDbcLocale()] : "<unknown>" ),
310 area_id
, (areaEntry
? areaEntry
->area_name
[m_session
->GetSessionDbcLocale()] : "<unknown>" ),
311 obj
->GetPositionX(), obj
->GetPositionY(), obj
->GetPositionZ(), obj
->GetOrientation(),
312 cell
.GridX(), cell
.GridY(), cell
.CellX(), cell
.CellY(), obj
->GetInstanceId(),
313 zone_x
, zone_y
, ground_z
, floor_z
, have_map
, have_vmap
);
315 sLog
.outDebug("Player %s GPS call for %s '%s' (%s: %u):",
317 (obj
->GetTypeId() == TYPEID_PLAYER
? "player" : "creature"), obj
->GetName(),
318 (obj
->GetTypeId() == TYPEID_PLAYER
? "GUID" : "Entry"), (obj
->GetTypeId() == TYPEID_PLAYER
? obj
->GetGUIDLow(): obj
->GetEntry()) );
320 sLog
.outDebug(GetMangosString(LANG_MAP_POSITION
),
321 obj
->GetMapId(), (mapEntry
? mapEntry
->name
[sWorld
.GetDefaultDbcLocale()] : "<unknown>" ),
322 zone_id
, (zoneEntry
? zoneEntry
->area_name
[sWorld
.GetDefaultDbcLocale()] : "<unknown>" ),
323 area_id
, (areaEntry
? areaEntry
->area_name
[sWorld
.GetDefaultDbcLocale()] : "<unknown>" ),
324 obj
->GetPositionX(), obj
->GetPositionY(), obj
->GetPositionZ(), obj
->GetOrientation(),
325 cell
.GridX(), cell
.GridY(), cell
.CellX(), cell
.CellY(), obj
->GetInstanceId(),
326 zone_x
, zone_y
, ground_z
, floor_z
, have_map
, have_vmap
);
332 bool ChatHandler::HandleNamegoCommand(const char* args
)
337 std::string name
= args
;
339 if(!normalizePlayerName(name
))
341 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
342 SetSentErrorMessage(true);
346 Player
*chr
= objmgr
.GetPlayer(name
.c_str());
349 // check online security
350 if (HasLowerSecurity(chr
, 0))
353 if(chr
->IsBeingTeleported()==true)
355 PSendSysMessage(LANG_IS_TELEPORTED
, chr
->GetName());
356 SetSentErrorMessage(true);
360 Map
* pMap
= m_session
->GetPlayer()->GetMap();
362 if(pMap
->IsBattleGroundOrArena())
364 // cannot summon to bg
365 PSendSysMessage(LANG_CANNOT_SUMMON_TO_BG
,chr
->GetName());
366 SetSentErrorMessage(true);
369 else if(pMap
->IsDungeon())
371 Map
* cMap
= chr
->GetMap();
372 if( cMap
->Instanceable() && cMap
->GetInstanceId() != pMap
->GetInstanceId() )
374 // cannot summon from instance to instance
375 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST
,chr
->GetName());
376 SetSentErrorMessage(true);
380 // we are in instance, and can summon only player in our group with us as lead
381 if ( !m_session
->GetPlayer()->GetGroup() || !chr
->GetGroup() ||
382 (chr
->GetGroup()->GetLeaderGUID() != m_session
->GetPlayer()->GetGUID()) ||
383 (m_session
->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session
->GetPlayer()->GetGUID()) )
384 // the last check is a bit excessive, but let it be, just in case
386 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST
,chr
->GetName());
387 SetSentErrorMessage(true);
392 PSendSysMessage(LANG_SUMMONING
, chr
->GetName(),"");
393 if (needReportToTarget(chr
))
394 ChatHandler(chr
).PSendSysMessage(LANG_SUMMONED_BY
, GetName());
396 // stop flight if need
397 if(chr
->isInFlight())
399 chr
->GetMotionMaster()->MovementExpired();
400 chr
->m_taxi
.ClearTaxiDestinations();
402 // save only in non-flight case
404 chr
->SaveRecallPosition();
408 m_session
->GetPlayer()->GetClosePoint(x
,y
,z
,chr
->GetObjectSize());
409 chr
->TeleportTo(m_session
->GetPlayer()->GetMapId(),x
,y
,z
,chr
->GetOrientation());
411 else if (uint64 guid
= objmgr
.GetPlayerGUIDByName(name
))
413 // check offline security
414 if (HasLowerSecurity(NULL
, guid
))
417 PSendSysMessage(LANG_SUMMONING
, name
.c_str(),GetMangosString(LANG_OFFLINE
));
419 // in point where GM stay
420 Player::SavePositionInDB(m_session
->GetPlayer()->GetMapId(),
421 m_session
->GetPlayer()->GetPositionX(),
422 m_session
->GetPlayer()->GetPositionY(),
423 m_session
->GetPlayer()->GetPositionZ(),
424 m_session
->GetPlayer()->GetOrientation(),
425 m_session
->GetPlayer()->GetZoneId(),
430 PSendSysMessage(LANG_NO_PLAYER
, args
);
431 SetSentErrorMessage(true);
438 bool ChatHandler::HandleGonameCommand(const char* args
)
443 Player
* _player
= m_session
->GetPlayer();
445 std::string name
= args
;
447 if(!normalizePlayerName(name
))
449 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
450 SetSentErrorMessage(true);
454 Player
*chr
= objmgr
.GetPlayer(name
.c_str());
457 // check online security
458 if (HasLowerSecurity(chr
, 0))
461 Map
* cMap
= chr
->GetMap();
462 if(cMap
->IsBattleGroundOrArena())
464 // only allow if gm mode is on
465 if (!_player
->isGameMaster())
467 PSendSysMessage(LANG_CANNOT_GO_TO_BG_GM
,chr
->GetName());
468 SetSentErrorMessage(true);
471 // if already in a bg, don't let port to other
472 else if (_player
->GetBattleGroundId())
474 PSendSysMessage(LANG_CANNOT_GO_TO_BG_FROM_BG
,chr
->GetName());
475 SetSentErrorMessage(true);
478 // all's well, set bg id
479 // when porting out from the bg, it will be reset to 0
480 _player
->SetBattleGroundId(chr
->GetBattleGroundId());
482 else if(cMap
->IsDungeon())
483 Map
* cMap
= chr
->GetMap();
484 if(cMap
->Instanceable())
486 // we have to go to instance, and can go to player only if:
487 // 1) we are in his group (either as leader or as member)
488 // 2) we are not bound to any group and have GM mode on
489 if (_player
->GetGroup())
491 // we are in group, we can go only if we are in the player group
492 if (_player
->GetGroup() != chr
->GetGroup())
494 PSendSysMessage(LANG_CANNOT_GO_TO_INST_PARTY
,chr
->GetName());
495 SetSentErrorMessage(true);
501 // we are not in group, let's verify our GM mode
502 if (!_player
->isGameMaster())
504 PSendSysMessage(LANG_CANNOT_GO_TO_INST_GM
,chr
->GetName());
505 SetSentErrorMessage(true);
510 // if the player or the player's group is bound to another instance
511 // the player will not be bound to another one
512 InstancePlayerBind
*pBind
= _player
->GetBoundInstance(chr
->GetMapId(), chr
->GetDifficulty());
515 Group
*group
= _player
->GetGroup();
516 InstanceGroupBind
*gBind
= group
? group
->GetBoundInstance(chr
->GetMapId(), chr
->GetDifficulty()) : NULL
;
519 // if no bind exists, create a solo bind
520 InstanceSave
*save
= sInstanceSaveManager
.GetInstanceSave(chr
->GetInstanceId());
521 if(save
) _player
->BindToInstance(save
, !save
->CanReset());
525 _player
->SetDifficulty(chr
->GetDifficulty());
528 PSendSysMessage(LANG_APPEARING_AT
, chr
->GetName());
530 if (_player
->IsVisibleGloballyFor(chr
))
531 ChatHandler(chr
).PSendSysMessage(LANG_APPEARING_TO
, _player
->GetName());
533 // stop flight if need
534 if(_player
->isInFlight())
536 _player
->GetMotionMaster()->MovementExpired();
537 _player
->m_taxi
.ClearTaxiDestinations();
539 // save only in non-flight case
541 _player
->SaveRecallPosition();
543 // to point to see at target with same orientation
545 chr
->GetContactPoint(m_session
->GetPlayer(),x
,y
,z
);
547 _player
->TeleportTo(chr
->GetMapId(), x
, y
, z
, _player
->GetAngle( chr
), TELE_TO_GM_MODE
);
552 if (uint64 guid
= objmgr
.GetPlayerGUIDByName(name
))
554 // check offline security
555 if (HasLowerSecurity(NULL
, guid
))
558 PSendSysMessage(LANG_APPEARING_AT
, name
.c_str());
560 // to point where player stay (if loaded)
564 if(Player::LoadPositionFromDB(map
,x
,y
,z
,o
,in_flight
,guid
))
566 // stop flight if need
567 if(_player
->isInFlight())
569 _player
->GetMotionMaster()->MovementExpired();
570 _player
->m_taxi
.ClearTaxiDestinations();
572 // save only in non-flight case
574 _player
->SaveRecallPosition();
576 _player
->TeleportTo(map
, x
, y
, z
,_player
->GetOrientation());
581 PSendSysMessage(LANG_NO_PLAYER
, args
);
583 SetSentErrorMessage(true);
587 // Teleport player to last position
588 bool ChatHandler::HandleRecallCommand(const char* args
)
594 chr
= getSelectedPlayer();
596 chr
= m_session
->GetPlayer();
598 // check online security
599 else if (HasLowerSecurity(chr
, 0))
604 std::string name
= args
;
606 if(!normalizePlayerName(name
))
608 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
609 SetSentErrorMessage(true);
613 chr
= objmgr
.GetPlayer(name
.c_str());
617 PSendSysMessage(LANG_NO_PLAYER
, args
);
618 SetSentErrorMessage(true);
622 // check online security
623 if (HasLowerSecurity(chr
, 0))
627 if(chr
->IsBeingTeleported())
629 PSendSysMessage(LANG_IS_TELEPORTED
, chr
->GetName());
630 SetSentErrorMessage(true);
634 // stop flight if need
635 if(chr
->isInFlight())
637 chr
->GetMotionMaster()->MovementExpired();
638 chr
->m_taxi
.ClearTaxiDestinations();
641 chr
->TeleportTo(chr
->m_recallMap
, chr
->m_recallX
, chr
->m_recallY
, chr
->m_recallZ
, chr
->m_recallO
);
645 //Edit Player KnownTitles
646 bool ChatHandler::HandleModifyKnownTitlesCommand(const char* args
)
653 sscanf((char*)args
, I64FMTD
, &titles
);
655 Player
*chr
= getSelectedPlayer();
658 SendSysMessage(LANG_NO_CHAR_SELECTED
);
659 SetSentErrorMessage(true);
663 // check online security
664 if (HasLowerSecurity(chr
, 0))
667 uint64 titles2
= titles
;
669 for(int i
=1; i
< sCharTitlesStore
.GetNumRows(); ++i
)
670 if(CharTitlesEntry
const* tEntry
= sCharTitlesStore
.LookupEntry(i
))
671 titles2
&= ~(uint64(1) << tEntry
->bit_index
);
673 titles
&= ~titles2
; // remove not existed titles
675 chr
->SetUInt64Value(PLAYER__FIELD_KNOWN_TITLES
, titles
);
676 SendSysMessage(LANG_DONE
);
682 bool ChatHandler::HandleModifyHPCommand(const char* args
)
687 // char* pHp = strtok((char*)args, " ");
691 // char* pHpMax = strtok(NULL, " ");
695 // int32 hpm = atoi(pHpMax);
696 // int32 hp = atoi(pHp);
698 int32 hp
= atoi((char*)args
);
699 int32 hpm
= atoi((char*)args
);
701 if (hp
<= 0 || hpm
<= 0 || hpm
< hp
)
703 SendSysMessage(LANG_BAD_VALUE
);
704 SetSentErrorMessage(true);
708 Player
*chr
= getSelectedPlayer();
711 SendSysMessage(LANG_NO_CHAR_SELECTED
);
712 SetSentErrorMessage(true);
716 // check online security
717 if (HasLowerSecurity(chr
, 0))
720 PSendSysMessage(LANG_YOU_CHANGE_HP
, chr
->GetName(), hp
, hpm
);
721 if (needReportToTarget(chr
))
722 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_HP_CHANGED
, GetName(), hp
, hpm
);
724 chr
->SetMaxHealth( hpm
);
725 chr
->SetHealth( hp
);
731 bool ChatHandler::HandleModifyManaCommand(const char* args
)
736 // char* pmana = strtok((char*)args, " ");
740 // char* pmanaMax = strtok(NULL, " ");
744 // int32 manam = atoi(pmanaMax);
745 // int32 mana = atoi(pmana);
746 int32 mana
= atoi((char*)args
);
747 int32 manam
= atoi((char*)args
);
749 if (mana
<= 0 || manam
<= 0 || manam
< mana
)
751 SendSysMessage(LANG_BAD_VALUE
);
752 SetSentErrorMessage(true);
756 Player
*chr
= getSelectedPlayer();
759 SendSysMessage(LANG_NO_CHAR_SELECTED
);
760 SetSentErrorMessage(true);
764 // check online security
765 if (HasLowerSecurity(chr
, 0))
768 PSendSysMessage(LANG_YOU_CHANGE_MANA
, chr
->GetName(), mana
, manam
);
769 if (needReportToTarget(chr
))
770 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_MANA_CHANGED
, GetName(), mana
, manam
);
772 chr
->SetMaxPower(POWER_MANA
,manam
);
773 chr
->SetPower(POWER_MANA
, mana
);
779 bool ChatHandler::HandleModifyEnergyCommand(const char* args
)
784 // char* pmana = strtok((char*)args, " ");
788 // char* pmanaMax = strtok(NULL, " ");
792 // int32 manam = atoi(pmanaMax);
793 // int32 mana = atoi(pmana);
795 int32 energy
= atoi((char*)args
)*10;
796 int32 energym
= atoi((char*)args
)*10;
798 if (energy
<= 0 || energym
<= 0 || energym
< energy
)
800 SendSysMessage(LANG_BAD_VALUE
);
801 SetSentErrorMessage(true);
805 Player
*chr
= getSelectedPlayer();
808 SendSysMessage(LANG_NO_CHAR_SELECTED
);
809 SetSentErrorMessage(true);
813 // check online security
814 if (HasLowerSecurity(chr
, 0))
817 PSendSysMessage(LANG_YOU_CHANGE_ENERGY
, chr
->GetName(), energy
/10, energym
/10);
818 if (needReportToTarget(chr
))
819 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_ENERGY_CHANGED
, GetName(), energy
/10, energym
/10);
821 chr
->SetMaxPower(POWER_ENERGY
,energym
);
822 chr
->SetPower(POWER_ENERGY
, energy
);
824 sLog
.outDetail(GetMangosString(LANG_CURRENT_ENERGY
),chr
->GetMaxPower(POWER_ENERGY
));
830 bool ChatHandler::HandleModifyRageCommand(const char* args
)
835 // char* pmana = strtok((char*)args, " ");
839 // char* pmanaMax = strtok(NULL, " ");
843 // int32 manam = atoi(pmanaMax);
844 // int32 mana = atoi(pmana);
846 int32 rage
= atoi((char*)args
)*10;
847 int32 ragem
= atoi((char*)args
)*10;
849 if (rage
<= 0 || ragem
<= 0 || ragem
< rage
)
851 SendSysMessage(LANG_BAD_VALUE
);
852 SetSentErrorMessage(true);
856 Player
*chr
= getSelectedPlayer();
859 SendSysMessage(LANG_NO_CHAR_SELECTED
);
860 SetSentErrorMessage(true);
864 // check online security
865 if (HasLowerSecurity(chr
, 0))
868 PSendSysMessage(LANG_YOU_CHANGE_RAGE
, chr
->GetName(), rage
/10, ragem
/10);
869 if (needReportToTarget(chr
))
870 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_RAGE_CHANGED
, GetName(), rage
/10, ragem
/10);
872 chr
->SetMaxPower(POWER_RAGE
,ragem
);
873 chr
->SetPower(POWER_RAGE
, rage
);
878 // Edit Player Runic Power
879 bool ChatHandler::HandleModifyRunicPowerCommand(const char* args
)
884 int32 rune
= atoi((char*)args
)*10;
885 int32 runem
= atoi((char*)args
)*10;
887 if (rune
<= 0 || runem
<= 0 || runem
< rune
)
889 SendSysMessage(LANG_BAD_VALUE
);
890 SetSentErrorMessage(true);
894 Player
*chr
= getSelectedPlayer();
897 SendSysMessage(LANG_NO_CHAR_SELECTED
);
898 SetSentErrorMessage(true);
902 PSendSysMessage(LANG_YOU_CHANGE_RUNIC_POWER
, chr
->GetName(), rune
/10, runem
/10);
903 if (needReportToTarget(chr
))
904 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_RUNIC_POWER_CHANGED
, GetName(), rune
/10, runem
/10);
906 chr
->SetMaxPower(POWER_RUNIC_POWER
,runem
);
907 chr
->SetPower(POWER_RUNIC_POWER
, rune
);
912 //Edit Player Faction
913 bool ChatHandler::HandleModifyFactionCommand(const char* args
)
918 char* pfactionid
= extractKeyFromLink((char*)args
,"Hfaction");
920 Creature
* chr
= getSelectedCreature();
923 SendSysMessage(LANG_SELECT_CREATURE
);
924 SetSentErrorMessage(true);
932 uint32 factionid
= chr
->getFaction();
933 uint32 flag
= chr
->GetUInt32Value(UNIT_FIELD_FLAGS
);
934 uint32 npcflag
= chr
->GetUInt32Value(UNIT_NPC_FLAGS
);
935 uint32 dyflag
= chr
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
);
936 PSendSysMessage(LANG_CURRENT_FACTION
,chr
->GetGUIDLow(),factionid
,flag
,npcflag
,dyflag
);
943 SendSysMessage(LANG_NO_CHAR_SELECTED
);
944 SetSentErrorMessage(true);
948 uint32 factionid
= atoi(pfactionid
);
951 char *pflag
= strtok(NULL
, " ");
953 flag
= chr
->GetUInt32Value(UNIT_FIELD_FLAGS
);
957 char* pnpcflag
= strtok(NULL
, " ");
961 npcflag
= chr
->GetUInt32Value(UNIT_NPC_FLAGS
);
963 npcflag
= atoi(pnpcflag
);
965 char* pdyflag
= strtok(NULL
, " ");
969 dyflag
= chr
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
);
971 dyflag
= atoi(pdyflag
);
973 if(!sFactionTemplateStore
.LookupEntry(factionid
))
975 PSendSysMessage(LANG_WRONG_FACTION
, factionid
);
976 SetSentErrorMessage(true);
980 PSendSysMessage(LANG_YOU_CHANGE_FACTION
, chr
->GetGUIDLow(),factionid
,flag
,npcflag
,dyflag
);
982 chr
->setFaction(factionid
);
983 chr
->SetUInt32Value(UNIT_FIELD_FLAGS
,flag
);
984 chr
->SetUInt32Value(UNIT_NPC_FLAGS
,npcflag
);
985 chr
->SetUInt32Value(UNIT_DYNAMIC_FLAGS
,dyflag
);
991 bool ChatHandler::HandleModifySpellCommand(const char* args
)
993 if(!*args
) return false;
994 char* pspellflatid
= strtok((char*)args
, " ");
998 char* pop
= strtok(NULL
, " ");
1002 char* pval
= strtok(NULL
, " ");
1008 char* pmark
= strtok(NULL
, " ");
1010 uint8 spellflatid
= atoi(pspellflatid
);
1011 uint8 op
= atoi(pop
);
1012 uint16 val
= atoi(pval
);
1018 Player
*chr
= getSelectedPlayer();
1021 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1022 SetSentErrorMessage(true);
1026 // check online security
1027 if (HasLowerSecurity(chr
, 0))
1030 PSendSysMessage(LANG_YOU_CHANGE_SPELLFLATID
, spellflatid
, val
, mark
, chr
->GetName());
1031 if (needReportToTarget(chr
))
1032 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_SPELLFLATID_CHANGED
, GetName(), spellflatid
, val
, mark
);
1034 WorldPacket
data(SMSG_SET_FLAT_SPELL_MODIFIER
, (1+1+2+2));
1035 data
<< uint8(spellflatid
);
1037 data
<< uint16(val
);
1038 data
<< uint16(mark
);
1039 chr
->GetSession()->SendPacket(&data
);
1045 bool ChatHandler::HandleModifyTalentCommand (const char* args
)
1050 int tp
= atoi((char*)args
);
1053 Player
* player
= getSelectedPlayer();
1056 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1057 SetSentErrorMessage(true);
1061 // check online security
1062 if (HasLowerSecurity(player
, 0))
1065 player
->SetFreeTalentPoints(tp
);
1071 //Enable On\OFF all taxi paths
1072 bool ChatHandler::HandleTaxiCheatCommand(const char* args
)
1076 SendSysMessage(LANG_USE_BOL
);
1077 SetSentErrorMessage(true);
1081 std::string argstr
= (char*)args
;
1083 Player
*chr
= getSelectedPlayer();
1086 chr
=m_session
->GetPlayer();
1089 // check online security
1090 else if (HasLowerSecurity(chr
, 0))
1095 chr
->SetTaxiCheater(true);
1096 PSendSysMessage(LANG_YOU_GIVE_TAXIS
, chr
->GetName());
1097 if (needReportToTarget(chr
))
1098 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_TAXIS_ADDED
, GetName());
1102 if (argstr
== "off")
1104 chr
->SetTaxiCheater(false);
1105 PSendSysMessage(LANG_YOU_REMOVE_TAXIS
, chr
->GetName());
1106 if (needReportToTarget(chr
))
1107 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_TAXIS_REMOVED
, GetName());
1112 SendSysMessage(LANG_USE_BOL
);
1113 SetSentErrorMessage(true);
1117 //Edit Player Aspeed
1118 bool ChatHandler::HandleModifyASpeedCommand(const char* args
)
1123 float ASpeed
= (float)atof((char*)args
);
1125 if (ASpeed
> 10 || ASpeed
< 0.1)
1127 SendSysMessage(LANG_BAD_VALUE
);
1128 SetSentErrorMessage(true);
1132 Player
*chr
= getSelectedPlayer();
1135 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1136 SetSentErrorMessage(true);
1140 // check online security
1141 if (HasLowerSecurity(chr
, 0))
1144 if(chr
->isInFlight())
1146 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chr
->GetName());
1147 SetSentErrorMessage(true);
1151 PSendSysMessage(LANG_YOU_CHANGE_ASPEED
, ASpeed
, chr
->GetName());
1152 if (needReportToTarget(chr
))
1153 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_ASPEED_CHANGED
, GetName(), ASpeed
);
1155 chr
->SetSpeed(MOVE_WALK
, ASpeed
,true);
1156 chr
->SetSpeed(MOVE_RUN
, ASpeed
,true);
1157 chr
->SetSpeed(MOVE_SWIM
, ASpeed
,true);
1158 //chr->SetSpeed(MOVE_TURN, ASpeed,true);
1159 chr
->SetSpeed(MOVE_FLIGHT
, ASpeed
,true);
1164 bool ChatHandler::HandleModifySpeedCommand(const char* args
)
1169 float Speed
= (float)atof((char*)args
);
1171 if (Speed
> 10 || Speed
< 0.1)
1173 SendSysMessage(LANG_BAD_VALUE
);
1174 SetSentErrorMessage(true);
1178 Player
*chr
= getSelectedPlayer();
1181 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1182 SetSentErrorMessage(true);
1186 // check online security
1187 if (HasLowerSecurity(chr
, 0))
1190 if(chr
->isInFlight())
1192 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chr
->GetName());
1193 SetSentErrorMessage(true);
1197 PSendSysMessage(LANG_YOU_CHANGE_SPEED
, Speed
, chr
->GetName());
1198 if (needReportToTarget(chr
))
1199 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_SPEED_CHANGED
, GetName(), Speed
);
1201 chr
->SetSpeed(MOVE_RUN
,Speed
,true);
1206 //Edit Player Swim Speed
1207 bool ChatHandler::HandleModifySwimCommand(const char* args
)
1212 float Swim
= (float)atof((char*)args
);
1214 if (Swim
> 10.0f
|| Swim
< 0.01f
)
1216 SendSysMessage(LANG_BAD_VALUE
);
1217 SetSentErrorMessage(true);
1221 Player
*chr
= getSelectedPlayer();
1224 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1225 SetSentErrorMessage(true);
1229 // check online security
1230 if (HasLowerSecurity(chr
, 0))
1233 if(chr
->isInFlight())
1235 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chr
->GetName());
1236 SetSentErrorMessage(true);
1240 PSendSysMessage(LANG_YOU_CHANGE_SWIM_SPEED
, Swim
, chr
->GetName());
1241 if (needReportToTarget(chr
))
1242 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_SWIM_SPEED_CHANGED
, GetName(), Swim
);
1244 chr
->SetSpeed(MOVE_SWIM
,Swim
,true);
1249 //Edit Player Walk Speed
1250 bool ChatHandler::HandleModifyBWalkCommand(const char* args
)
1255 float BSpeed
= (float)atof((char*)args
);
1257 if (BSpeed
> 10.0f
|| BSpeed
< 0.1f
)
1259 SendSysMessage(LANG_BAD_VALUE
);
1260 SetSentErrorMessage(true);
1264 Player
*chr
= getSelectedPlayer();
1267 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1268 SetSentErrorMessage(true);
1272 // check online security
1273 if (HasLowerSecurity(chr
, 0))
1276 if(chr
->isInFlight())
1278 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chr
->GetName());
1279 SetSentErrorMessage(true);
1283 PSendSysMessage(LANG_YOU_CHANGE_BACK_SPEED
, BSpeed
, chr
->GetName());
1284 if (needReportToTarget(chr
))
1285 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_BACK_SPEED_CHANGED
, GetName(), 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
, chr
->GetName());
1320 if (needReportToTarget(chr
))
1321 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_FLY_SPEED_CHANGED
, GetName(), 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
, chr
->GetName());
1355 if (needReportToTarget(chr
))
1356 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_SIZE_CHANGED
, GetName(), 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
, chr
->GetName());
1602 if (needReportToTarget(chr
))
1603 ChatHandler(chr
).PSendSysMessage(LANG_MOUNT_GIVED
, GetName());
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
= moneyuser
+ addmoney
;
1650 sLog
.outDetail(GetMangosString(LANG_CURRENT_MONEY
), moneyuser
, addmoney
, newmoney
);
1653 PSendSysMessage(LANG_YOU_TAKE_ALL_MONEY
, chr
->GetName());
1654 if (needReportToTarget(chr
))
1655 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_ALL_MONEY_GONE
, GetName());
1661 PSendSysMessage(LANG_YOU_TAKE_MONEY
, abs(addmoney
), chr
->GetName());
1662 if (needReportToTarget(chr
))
1663 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_MONEY_TAKEN
, GetName(), abs(addmoney
));
1664 chr
->SetMoney( newmoney
);
1669 PSendSysMessage(LANG_YOU_GIVE_MONEY
, addmoney
, chr
->GetName());
1670 if (needReportToTarget(chr
))
1671 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_MONEY_GIVEN
, GetName(), addmoney
);
1672 chr
->ModifyMoney( addmoney
);
1675 sLog
.outDetail(GetMangosString(LANG_NEW_MONEY
), moneyuser
, addmoney
, chr
->GetMoney() );
1681 bool ChatHandler::HandleModifyBitCommand(const char* args
)
1686 Unit
*unit
= getSelectedUnit();
1689 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1690 SetSentErrorMessage(true);
1694 // check online security
1695 if (unit
->GetTypeId() == TYPEID_PLAYER
&& HasLowerSecurity((Player
*)unit
, 0))
1698 char* pField
= strtok((char*)args
, " ");
1702 char* pBit
= strtok(NULL
, " ");
1706 uint16 field
= atoi(pField
);
1707 uint32 bit
= atoi(pBit
);
1709 if (field
< OBJECT_END
|| field
>= unit
->GetValuesCount())
1711 SendSysMessage(LANG_BAD_VALUE
);
1712 SetSentErrorMessage(true);
1715 if (bit
< 1 || bit
> 32)
1717 SendSysMessage(LANG_BAD_VALUE
);
1718 SetSentErrorMessage(true);
1722 if ( unit
->HasFlag( field
, (1<<(bit
-1)) ) )
1724 unit
->RemoveFlag( field
, (1<<(bit
-1)) );
1725 PSendSysMessage(LANG_REMOVE_BIT
, bit
, field
);
1729 unit
->SetFlag( field
, (1<<(bit
-1)) );
1730 PSendSysMessage(LANG_SET_BIT
, bit
, field
);
1735 bool ChatHandler::HandleModifyHonorCommand (const char* args
)
1740 Player
*target
= getSelectedPlayer();
1743 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1744 SetSentErrorMessage(true);
1748 // check online security
1749 if (HasLowerSecurity(target
, 0))
1752 int32 amount
= (uint32
)atoi(args
);
1754 target
->ModifyHonorPoints(amount
);
1756 PSendSysMessage(LANG_COMMAND_MODIFY_HONOR
, target
->GetName(), target
->GetHonorPoints());
1761 bool ChatHandler::HandleTeleCommand(const char * args
)
1766 Player
* _player
= m_session
->GetPlayer();
1768 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
1769 GameTele
const* tele
= extractGameTeleFromLink((char*)args
);
1773 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
1774 SetSentErrorMessage(true);
1778 // stop flight if need
1779 if(_player
->isInFlight())
1781 _player
->GetMotionMaster()->MovementExpired();
1782 _player
->m_taxi
.ClearTaxiDestinations();
1784 // save only in non-flight case
1786 _player
->SaveRecallPosition();
1788 _player
->TeleportTo(tele
->mapId
, tele
->position_x
, tele
->position_y
, tele
->position_z
, tele
->orientation
);
1792 bool ChatHandler::HandleLookupAreaCommand(const char* args
)
1797 std::string namepart
= args
;
1798 std::wstring wnamepart
;
1800 if (!Utf8toWStr (namepart
,wnamepart
))
1803 uint32 counter
= 0; // Counter for figure out that we found smth.
1805 // converting string that we try to find to lower case
1806 wstrToLower (wnamepart
);
1808 // Search in AreaTable.dbc
1809 for (uint32 areaflag
= 0; areaflag
< sAreaStore
.GetNumRows (); ++areaflag
)
1811 AreaTableEntry
const *areaEntry
= sAreaStore
.LookupEntry (areaflag
);
1814 int loc
= m_session
? m_session
->GetSessionDbcLocale () : sWorld
.GetDefaultDbcLocale();
1815 std::string name
= areaEntry
->area_name
[loc
];
1819 if (!Utf8FitTo (name
, wnamepart
))
1822 for(; loc
< MAX_LOCALE
; ++loc
)
1824 if (m_session
&& loc
==m_session
->GetSessionDbcLocale ())
1827 name
= areaEntry
->area_name
[loc
];
1831 if (Utf8FitTo (name
, wnamepart
))
1836 if (loc
< MAX_LOCALE
)
1838 // send area in "id - [name]" format
1839 std::ostringstream ss
;
1841 ss
<< areaEntry
->ID
<< " - |cffffffff|Harea:" << areaEntry
->ID
<< "|h[" << name
<< " " << localeNames
[loc
]<< "]|h|r";
1843 ss
<< areaEntry
->ID
<< " - " << name
<< " " << localeNames
[loc
];
1845 SendSysMessage (ss
.str ().c_str());
1852 if (counter
== 0) // if counter == 0 then we found nth
1853 SendSysMessage (LANG_COMMAND_NOAREAFOUND
);
1858 //Find tele in game_tele order by name
1859 bool ChatHandler::HandleLookupTeleCommand(const char * args
)
1863 SendSysMessage(LANG_COMMAND_TELE_PARAMETER
);
1864 SetSentErrorMessage(true);
1868 char const* str
= strtok((char*)args
, " ");
1872 std::string namepart
= str
;
1873 std::wstring wnamepart
;
1875 if(!Utf8toWStr(namepart
,wnamepart
))
1878 // converting string that we try to find to lower case
1879 wstrToLower( wnamepart
);
1881 std::ostringstream reply
;
1883 GameTeleMap
const & teleMap
= objmgr
.GetGameTeleMap();
1884 for(GameTeleMap::const_iterator itr
= teleMap
.begin(); itr
!= teleMap
.end(); ++itr
)
1886 GameTele
const* tele
= &itr
->second
;
1888 if(tele
->wnameLow
.find(wnamepart
) == std::wstring::npos
)
1892 reply
<< " |cffffffff|Htele:" << itr
->first
<< "|h[" << tele
->name
<< "]|h|r\n";
1894 reply
<< " " << itr
->first
<< " " << tele
->name
<< "\n";
1897 if(reply
.str().empty())
1898 SendSysMessage(LANG_COMMAND_TELE_NOLOCATION
);
1900 PSendSysMessage(LANG_COMMAND_TELE_LOCATION
,reply
.str().c_str());
1905 //Enable\Dissable accept whispers (for GM)
1906 bool ChatHandler::HandleWhispersCommand(const char* args
)
1910 PSendSysMessage(LANG_COMMAND_WHISPERACCEPTING
, m_session
->GetPlayer()->isAcceptWhispers() ? GetMangosString(LANG_ON
) : GetMangosString(LANG_OFF
));
1914 std::string argstr
= (char*)args
;
1918 m_session
->GetPlayer()->SetAcceptWhispers(true);
1919 SendSysMessage(LANG_COMMAND_WHISPERON
);
1924 if (argstr
== "off")
1926 m_session
->GetPlayer()->SetAcceptWhispers(false);
1927 SendSysMessage(LANG_COMMAND_WHISPEROFF
);
1931 SendSysMessage(LANG_USE_BOL
);
1932 SetSentErrorMessage(true);
1937 bool ChatHandler::HandlePlaySoundCommand(const char* args
)
1939 // USAGE: .debug playsound #soundid
1940 // #soundid - ID decimal number from SoundEntries.dbc (1st column)
1941 // this file have about 5000 sounds.
1942 // In this realization only caller can hear this sound.
1945 uint32 dwSoundId
= atoi((char*)args
);
1947 if( !sSoundEntriesStore
.LookupEntry(dwSoundId
) )
1949 PSendSysMessage(LANG_SOUND_NOT_EXIST
, dwSoundId
);
1950 SetSentErrorMessage(true);
1954 WorldPacket
data(SMSG_PLAY_OBJECT_SOUND
,4+8);
1955 data
<< uint32(dwSoundId
) << m_session
->GetPlayer()->GetGUID();
1956 m_session
->SendPacket(&data
);
1958 PSendSysMessage(LANG_YOU_HEAR_SOUND
, dwSoundId
);
1965 //Save all players in the world
1966 bool ChatHandler::HandleSaveAllCommand(const char* /*args*/)
1968 ObjectAccessor::Instance().SaveAllPlayers();
1969 SendSysMessage(LANG_PLAYERS_SAVED
);
1973 //Send mail by command
1974 bool ChatHandler::HandleSendMailCommand(const char* args
)
1979 // format: name "subject text" "mail text"
1981 char* pName
= strtok((char*)args
, " ");
1985 char* tail1
= strtok(NULL
, "");
1991 msgSubject
= strtok(tail1
+1, "\"");
1994 char* space
= strtok(tail1
, "\"");
1997 msgSubject
= strtok(NULL
, "\"");
2003 char* tail2
= strtok(NULL
, "");
2009 msgText
= strtok(tail2
+1, "\"");
2012 char* space
= strtok(tail2
, "\"");
2015 msgText
= strtok(NULL
, "\"");
2021 // pName, msgSubject, msgText isn't NUL after prev. check
2022 std::string name
= pName
;
2023 std::string subject
= msgSubject
;
2024 std::string text
= msgText
;
2026 if(!normalizePlayerName(name
))
2028 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
2029 SetSentErrorMessage(true);
2033 uint64 receiver_guid
= objmgr
.GetPlayerGUIDByName(name
);
2036 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
2037 SetSentErrorMessage(true);
2041 // from console show not existed sender
2042 uint32 sender_guidlo
= m_session
? m_session
->GetPlayer()->GetGUIDLow() : 0;
2044 uint32 messagetype
= MAIL_NORMAL
;
2045 uint32 stationery
= MAIL_STATIONERY_GM
;
2046 uint32 itemTextId
= !text
.empty() ? objmgr
.CreateItemText( text
) : 0;
2048 Player
*receiver
= objmgr
.GetPlayer(receiver_guid
);
2050 WorldSession::SendMailTo(receiver
,messagetype
, stationery
, sender_guidlo
, GUID_LOPART(receiver_guid
), subject
, itemTextId
, NULL
, 0, 0, MAIL_CHECK_MASK_NONE
);
2052 PSendSysMessage(LANG_MAIL_SENT
, name
.c_str());
2056 // teleport player to given game_tele.entry
2057 bool ChatHandler::HandleNameTeleCommand(const char * args
)
2062 char* pName
= strtok((char*)args
, " ");
2067 std::string name
= pName
;
2069 if(!normalizePlayerName(name
))
2071 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
2072 SetSentErrorMessage(true);
2076 char* tail
= strtok(NULL
, "");
2080 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2081 GameTele
const* tele
= extractGameTeleFromLink(tail
);
2084 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
2085 SetSentErrorMessage(true);
2089 Player
*chr
= objmgr
.GetPlayer(name
.c_str());
2092 // check online security
2093 if (HasLowerSecurity(chr
, 0))
2096 if(chr
->IsBeingTeleported()==true)
2098 PSendSysMessage(LANG_IS_TELEPORTED
, chr
->GetName());
2099 SetSentErrorMessage(true);
2103 PSendSysMessage(LANG_TELEPORTING_TO
, chr
->GetName(),"", tele
->name
.c_str());
2104 if (needReportToTarget(chr
))
2105 ChatHandler(chr
).PSendSysMessage(LANG_TELEPORTED_TO_BY
, GetName());
2107 // stop flight if need
2108 if(chr
->isInFlight())
2110 chr
->GetMotionMaster()->MovementExpired();
2111 chr
->m_taxi
.ClearTaxiDestinations();
2113 // save only in non-flight case
2115 chr
->SaveRecallPosition();
2117 chr
->TeleportTo(tele
->mapId
,tele
->position_x
,tele
->position_y
,tele
->position_z
,tele
->orientation
);
2119 else if (uint64 guid
= objmgr
.GetPlayerGUIDByName(name
.c_str()))
2121 // check offline security
2122 if (HasLowerSecurity(NULL
, guid
))
2125 PSendSysMessage(LANG_TELEPORTING_TO
, name
.c_str(), GetMangosString(LANG_OFFLINE
), tele
->name
.c_str());
2126 Player::SavePositionInDB(tele
->mapId
,tele
->position_x
,tele
->position_y
,tele
->position_z
,tele
->orientation
,
2127 MapManager::Instance().GetZoneId(tele
->mapId
,tele
->position_x
,tele
->position_y
,tele
->position_z
),guid
);
2130 PSendSysMessage(LANG_NO_PLAYER
, name
.c_str());
2135 //Teleport group to given game_tele.entry
2136 bool ChatHandler::HandleGroupTeleCommand(const char * args
)
2141 Player
*player
= getSelectedPlayer();
2144 SendSysMessage(LANG_NO_CHAR_SELECTED
);
2145 SetSentErrorMessage(true);
2149 // check online security
2150 if (HasLowerSecurity(player
, 0))
2153 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2154 GameTele
const* tele
= extractGameTeleFromLink((char*)args
);
2157 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
2158 SetSentErrorMessage(true);
2162 Group
*grp
= player
->GetGroup();
2165 PSendSysMessage(LANG_NOT_IN_GROUP
,player
->GetName());
2166 SetSentErrorMessage(true);
2170 for(GroupReference
*itr
= grp
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
2172 Player
*pl
= itr
->getSource();
2174 if(!pl
|| !pl
->GetSession() )
2177 // check online security
2178 if (HasLowerSecurity(pl
, 0))
2181 if(pl
->IsBeingTeleported())
2183 PSendSysMessage(LANG_IS_TELEPORTED
, pl
->GetName());
2187 PSendSysMessage(LANG_TELEPORTING_TO
, pl
->GetName(),"", tele
->name
.c_str());
2188 if (needReportToTarget(pl
))
2189 ChatHandler(pl
).PSendSysMessage(LANG_TELEPORTED_TO_BY
, GetName());
2191 // stop flight if need
2192 if(pl
->isInFlight())
2194 pl
->GetMotionMaster()->MovementExpired();
2195 pl
->m_taxi
.ClearTaxiDestinations();
2197 // save only in non-flight case
2199 pl
->SaveRecallPosition();
2201 pl
->TeleportTo(tele
->mapId
, tele
->position_x
, tele
->position_y
, tele
->position_z
, tele
->orientation
);
2207 //Summon group of player
2208 bool ChatHandler::HandleGroupgoCommand(const char* args
)
2213 std::string name
= args
;
2215 if(!normalizePlayerName(name
))
2217 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
2218 SetSentErrorMessage(true);
2222 Player
*player
= objmgr
.GetPlayer(name
.c_str());
2225 PSendSysMessage(LANG_NO_PLAYER
, args
);
2226 SetSentErrorMessage(true);
2230 // check online security
2231 if (HasLowerSecurity(player
, 0))
2234 Group
*grp
= player
->GetGroup();
2238 PSendSysMessage(LANG_NOT_IN_GROUP
,player
->GetName());
2239 SetSentErrorMessage(true);
2243 Map
* gmMap
= m_session
->GetPlayer()->GetMap();
2244 bool to_instance
= gmMap
->Instanceable();
2246 // we are in instance, and can summon only player in our group with us as lead
2247 if ( to_instance
&& (
2248 !m_session
->GetPlayer()->GetGroup() || (grp
->GetLeaderGUID() != m_session
->GetPlayer()->GetGUID()) ||
2249 (m_session
->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session
->GetPlayer()->GetGUID()) ) )
2250 // the last check is a bit excessive, but let it be, just in case
2252 SendSysMessage(LANG_CANNOT_SUMMON_TO_INST
);
2253 SetSentErrorMessage(true);
2257 for(GroupReference
*itr
= grp
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
2259 Player
*pl
= itr
->getSource();
2261 if(!pl
|| pl
==m_session
->GetPlayer() || !pl
->GetSession() )
2264 // check online security
2265 if (HasLowerSecurity(pl
, 0))
2268 if(pl
->IsBeingTeleported()==true)
2270 PSendSysMessage(LANG_IS_TELEPORTED
, pl
->GetName());
2271 SetSentErrorMessage(true);
2277 Map
* plMap
= pl
->GetMap();
2279 if ( plMap
->Instanceable() && plMap
->GetInstanceId() != gmMap
->GetInstanceId() )
2281 // cannot summon from instance to instance
2282 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST
,pl
->GetName());
2283 SetSentErrorMessage(true);
2288 PSendSysMessage(LANG_SUMMONING
, pl
->GetName(),"");
2289 if (needReportToTarget(pl
))
2290 ChatHandler(pl
).PSendSysMessage(LANG_SUMMONED_BY
, GetName());
2292 // stop flight if need
2293 if(pl
->isInFlight())
2295 pl
->GetMotionMaster()->MovementExpired();
2296 pl
->m_taxi
.ClearTaxiDestinations();
2298 // save only in non-flight case
2300 pl
->SaveRecallPosition();
2304 m_session
->GetPlayer()->GetClosePoint(x
,y
,z
,pl
->GetObjectSize());
2305 pl
->TeleportTo(m_session
->GetPlayer()->GetMapId(),x
,y
,z
,pl
->GetOrientation());
2311 //teleport at coordinates
2312 bool ChatHandler::HandleGoXYCommand(const char* args
)
2317 Player
* _player
= m_session
->GetPlayer();
2319 char* px
= strtok((char*)args
, " ");
2320 char* py
= strtok(NULL
, " ");
2321 char* pmapid
= strtok(NULL
, " ");
2326 float x
= (float)atof(px
);
2327 float y
= (float)atof(py
);
2330 mapid
= (uint32
)atoi(pmapid
);
2331 else mapid
= _player
->GetMapId();
2333 if(!MapManager::IsValidMapCoord(mapid
,x
,y
))
2335 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,mapid
);
2336 SetSentErrorMessage(true);
2340 // stop flight if need
2341 if(_player
->isInFlight())
2343 _player
->GetMotionMaster()->MovementExpired();
2344 _player
->m_taxi
.ClearTaxiDestinations();
2346 // save only in non-flight case
2348 _player
->SaveRecallPosition();
2350 Map
const *map
= MapManager::Instance().GetBaseMap(mapid
);
2351 float z
= std::max(map
->GetHeight(x
, y
, MAX_HEIGHT
), map
->GetWaterLevel(x
, y
));
2353 _player
->TeleportTo(mapid
, x
, y
, z
, _player
->GetOrientation());
2358 //teleport at coordinates, including Z
2359 bool ChatHandler::HandleGoXYZCommand(const char* args
)
2364 Player
* _player
= m_session
->GetPlayer();
2366 char* px
= strtok((char*)args
, " ");
2367 char* py
= strtok(NULL
, " ");
2368 char* pz
= strtok(NULL
, " ");
2369 char* pmapid
= strtok(NULL
, " ");
2371 if (!px
|| !py
|| !pz
)
2374 float x
= (float)atof(px
);
2375 float y
= (float)atof(py
);
2376 float z
= (float)atof(pz
);
2379 mapid
= (uint32
)atoi(pmapid
);
2381 mapid
= _player
->GetMapId();
2383 if(!MapManager::IsValidMapCoord(mapid
,x
,y
,z
))
2385 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,mapid
);
2386 SetSentErrorMessage(true);
2390 // stop flight if need
2391 if(_player
->isInFlight())
2393 _player
->GetMotionMaster()->MovementExpired();
2394 _player
->m_taxi
.ClearTaxiDestinations();
2396 // save only in non-flight case
2398 _player
->SaveRecallPosition();
2400 _player
->TeleportTo(mapid
, x
, y
, z
, _player
->GetOrientation());
2405 //teleport at coordinates
2406 bool ChatHandler::HandleGoZoneXYCommand(const char* args
)
2411 Player
* _player
= m_session
->GetPlayer();
2413 char* px
= strtok((char*)args
, " ");
2414 char* py
= strtok(NULL
, " ");
2415 char* tail
= strtok(NULL
,"");
2417 char* cAreaId
= extractKeyFromLink(tail
,"Harea"); // string or [name] Shift-click form |color|Harea:area_id|h[name]|h|r
2422 float x
= (float)atof(px
);
2423 float y
= (float)atof(py
);
2424 uint32 areaid
= cAreaId
? (uint32
)atoi(cAreaId
) : _player
->GetZoneId();
2426 AreaTableEntry
const* areaEntry
= GetAreaEntryByAreaID(areaid
);
2428 if( x
<0 || x
>100 || y
<0 || y
>100 || !areaEntry
)
2430 PSendSysMessage(LANG_INVALID_ZONE_COORD
,x
,y
,areaid
);
2431 SetSentErrorMessage(true);
2435 // update to parent zone if exist (client map show only zones without parents)
2436 AreaTableEntry
const* zoneEntry
= areaEntry
->zone
? GetAreaEntryByAreaID(areaEntry
->zone
) : areaEntry
;
2438 Map
const *map
= MapManager::Instance().GetBaseMap(zoneEntry
->mapid
);
2440 if(map
->Instanceable())
2442 PSendSysMessage(LANG_INVALID_ZONE_MAP
,areaEntry
->ID
,areaEntry
->area_name
[m_session
->GetSessionDbcLocale()],map
->GetId(),map
->GetMapName());
2443 SetSentErrorMessage(true);
2447 Zone2MapCoordinates(x
,y
,zoneEntry
->ID
);
2449 if(!MapManager::IsValidMapCoord(zoneEntry
->mapid
,x
,y
))
2451 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,zoneEntry
->mapid
);
2452 SetSentErrorMessage(true);
2456 // stop flight if need
2457 if(_player
->isInFlight())
2459 _player
->GetMotionMaster()->MovementExpired();
2460 _player
->m_taxi
.ClearTaxiDestinations();
2462 // save only in non-flight case
2464 _player
->SaveRecallPosition();
2466 float z
= std::max(map
->GetHeight(x
, y
, MAX_HEIGHT
), map
->GetWaterLevel(x
, y
));
2467 _player
->TeleportTo(zoneEntry
->mapid
, x
, y
, z
, _player
->GetOrientation());
2473 bool ChatHandler::HandleGoGridCommand(const char* args
)
2475 if(!*args
) return false;
2476 Player
* _player
= m_session
->GetPlayer();
2478 char* px
= strtok((char*)args
, " ");
2479 char* py
= strtok(NULL
, " ");
2480 char* pmapid
= strtok(NULL
, " ");
2485 float grid_x
= (float)atof(px
);
2486 float grid_y
= (float)atof(py
);
2489 mapid
= (uint32
)atoi(pmapid
);
2490 else mapid
= _player
->GetMapId();
2493 float x
= (grid_x
-CENTER_GRID_ID
+0.5f
)*SIZE_OF_GRIDS
;
2494 float y
= (grid_y
-CENTER_GRID_ID
+0.5f
)*SIZE_OF_GRIDS
;
2496 if(!MapManager::IsValidMapCoord(mapid
,x
,y
))
2498 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,mapid
);
2499 SetSentErrorMessage(true);
2503 // stop flight if need
2504 if(_player
->isInFlight())
2506 _player
->GetMotionMaster()->MovementExpired();
2507 _player
->m_taxi
.ClearTaxiDestinations();
2509 // save only in non-flight case
2511 _player
->SaveRecallPosition();
2513 Map
const *map
= MapManager::Instance().GetBaseMap(mapid
);
2514 float z
= std::max(map
->GetHeight(x
, y
, MAX_HEIGHT
), map
->GetWaterLevel(x
, y
));
2515 _player
->TeleportTo(mapid
, x
, y
, z
, _player
->GetOrientation());
2520 bool ChatHandler::HandleDrunkCommand(const char* args
)
2522 if(!*args
) return false;
2524 uint32 drunklevel
= (uint32
)atoi(args
);
2525 if(drunklevel
> 100)
2528 uint16 drunkMod
= drunklevel
* 0xFFFF / 100;
2530 m_session
->GetPlayer()->SetDrunkValue(drunkMod
);