2 * Copyright (C) 2005-2008 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::HandleSayCommand(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::HandleYellCommand(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::HandleTextEmoteCommand(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 pCreature
->Whisper(text
,receiver_guid
);
120 bool ChatHandler::HandleAnnounceCommand(const char* args
)
125 sWorld
.SendWorldText(LANG_SYSTEMMESSAGE
,args
);
129 //notification player at the screen
130 bool ChatHandler::HandleNotifyCommand(const char* args
)
135 std::string str
= GetMangosString(LANG_GLOBAL_NOTIFY
);
138 WorldPacket
data(SMSG_NOTIFICATION
, (str
.size()+1));
140 sWorld
.SendGlobalMessage(&data
);
145 //Enable\Dissable GM Mode
146 bool ChatHandler::HandleGMmodeCommand(const char* args
)
150 if(m_session
->GetPlayer()->isGameMaster())
151 m_session
->SendNotification(LANG_GM_ON
);
153 m_session
->SendNotification(LANG_GM_OFF
);
157 std::string argstr
= (char*)args
;
161 m_session
->GetPlayer()->SetGameMaster(true);
162 m_session
->SendNotification(LANG_GM_ON
);
164 VMAP::IVMapManager
*vMapManager
= VMAP::VMapFactory::createOrGetVMapManager();
165 vMapManager
->processCommand("stoplog");
172 m_session
->GetPlayer()->SetGameMaster(false);
173 m_session
->SendNotification(LANG_GM_OFF
);
175 VMAP::IVMapManager
*vMapManager
= VMAP::VMapFactory::createOrGetVMapManager();
176 vMapManager
->processCommand("startlog");
181 SendSysMessage(LANG_USE_BOL
);
182 SetSentErrorMessage(true);
186 // Enables or disables hiding of the staff badge
187 bool ChatHandler::HandleGMChatCommand(const char* args
)
191 if(m_session
->GetPlayer()->isGMChat())
192 m_session
->SendNotification(LANG_GM_CHAT_ON
);
194 m_session
->SendNotification(LANG_GM_CHAT_OFF
);
198 std::string argstr
= (char*)args
;
202 m_session
->GetPlayer()->SetGMChat(true);
203 m_session
->SendNotification(LANG_GM_CHAT_ON
);
209 m_session
->GetPlayer()->SetGMChat(false);
210 m_session
->SendNotification(LANG_GM_CHAT_OFF
);
214 SendSysMessage(LANG_USE_BOL
);
215 SetSentErrorMessage(true);
219 //Enable\Dissable Invisible mode
220 bool ChatHandler::HandleVisibleCommand(const char* args
)
224 PSendSysMessage(LANG_YOU_ARE
, m_session
->GetPlayer()->isGMVisible() ? GetMangosString(LANG_VISIBLE
) : GetMangosString(LANG_INVISIBLE
));
228 std::string argstr
= (char*)args
;
232 m_session
->GetPlayer()->SetGMVisible(true);
233 m_session
->SendNotification(LANG_INVISIBLE_VISIBLE
);
239 m_session
->SendNotification(LANG_INVISIBLE_INVISIBLE
);
240 m_session
->GetPlayer()->SetGMVisible(false);
244 SendSysMessage(LANG_USE_BOL
);
245 SetSentErrorMessage(true);
249 bool ChatHandler::HandleGPSCommand(const char* args
)
251 WorldObject
*obj
= NULL
;
254 std::string name
= args
;
255 if(normalizePlayerName(name
))
256 obj
= objmgr
.GetPlayer(name
.c_str());
260 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
261 SetSentErrorMessage(true);
267 obj
= getSelectedUnit();
271 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
272 SetSentErrorMessage(true);
276 CellPair cell_val
= MaNGOS::ComputeCellPair(obj
->GetPositionX(), obj
->GetPositionY());
279 uint32 zone_id
= obj
->GetZoneId();
280 uint32 area_id
= obj
->GetAreaId();
282 MapEntry
const* mapEntry
= sMapStore
.LookupEntry(obj
->GetMapId());
283 AreaTableEntry
const* zoneEntry
= GetAreaEntryByAreaID(zone_id
);
284 AreaTableEntry
const* areaEntry
= GetAreaEntryByAreaID(area_id
);
286 float zone_x
= obj
->GetPositionX();
287 float zone_y
= obj
->GetPositionY();
289 Map2ZoneCoordinates(zone_x
,zone_y
,zone_id
);
291 Map
const *map
= MapManager::Instance().GetMap(obj
->GetMapId(), obj
);
292 float ground_z
= map
->GetHeight(obj
->GetPositionX(), obj
->GetPositionY(), MAX_HEIGHT
);
293 float floor_z
= map
->GetHeight(obj
->GetPositionX(), obj
->GetPositionY(), obj
->GetPositionZ());
295 GridPair p
= MaNGOS::ComputeGridPair(obj
->GetPositionX(), obj
->GetPositionY());
300 uint32 have_map
= Map::ExistMap(obj
->GetMapId(),gx
,gy
) ? 1 : 0;
301 uint32 have_vmap
= Map::ExistVMap(obj
->GetMapId(),gx
,gy
) ? 1 : 0;
303 PSendSysMessage(LANG_MAP_POSITION
,
304 obj
->GetMapId(), (mapEntry
? mapEntry
->name
[m_session
->GetSessionDbcLocale()] : "<unknown>" ),
305 zone_id
, (zoneEntry
? zoneEntry
->area_name
[m_session
->GetSessionDbcLocale()] : "<unknown>" ),
306 area_id
, (areaEntry
? areaEntry
->area_name
[m_session
->GetSessionDbcLocale()] : "<unknown>" ),
307 obj
->GetPositionX(), obj
->GetPositionY(), obj
->GetPositionZ(), obj
->GetOrientation(),
308 cell
.GridX(), cell
.GridY(), cell
.CellX(), cell
.CellY(), obj
->GetInstanceId(),
309 zone_x
, zone_y
, ground_z
, floor_z
, have_map
, have_vmap
);
311 sLog
.outDebug("Player %s GPS call for %s '%s' (%s: %u):",
312 m_session
->GetPlayer()->GetName(),
313 (obj
->GetTypeId() == TYPEID_PLAYER
? "player" : "creature"), obj
->GetName(),
314 (obj
->GetTypeId() == TYPEID_PLAYER
? "GUID" : "Entry"), (obj
->GetTypeId() == TYPEID_PLAYER
? obj
->GetGUIDLow(): obj
->GetEntry()) );
315 sLog
.outDebug(GetMangosString(LANG_MAP_POSITION
),
316 obj
->GetMapId(), (mapEntry
? mapEntry
->name
[sWorld
.GetDefaultDbcLocale()] : "<unknown>" ),
317 zone_id
, (zoneEntry
? zoneEntry
->area_name
[sWorld
.GetDefaultDbcLocale()] : "<unknown>" ),
318 area_id
, (areaEntry
? areaEntry
->area_name
[sWorld
.GetDefaultDbcLocale()] : "<unknown>" ),
319 obj
->GetPositionX(), obj
->GetPositionY(), obj
->GetPositionZ(), obj
->GetOrientation(),
320 cell
.GridX(), cell
.GridY(), cell
.CellX(), cell
.CellY(), obj
->GetInstanceId(),
321 zone_x
, zone_y
, ground_z
, floor_z
, have_map
, have_vmap
);
327 bool ChatHandler::HandleNamegoCommand(const char* args
)
332 std::string name
= args
;
334 if(!normalizePlayerName(name
))
336 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
337 SetSentErrorMessage(true);
341 Player
*chr
= objmgr
.GetPlayer(name
.c_str());
344 if(chr
->IsBeingTeleported()==true)
346 PSendSysMessage(LANG_IS_TELEPORTED
, chr
->GetName());
347 SetSentErrorMessage(true);
351 Map
* pMap
= MapManager::Instance().GetMap(m_session
->GetPlayer()->GetMapId(),m_session
->GetPlayer());
353 if(pMap
->Instanceable())
355 Map
* cMap
= MapManager::Instance().GetMap(chr
->GetMapId(),chr
);
356 if( cMap
->Instanceable() && cMap
->GetInstanceId() != pMap
->GetInstanceId() )
358 // cannot summon from instance to instance
359 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST
,chr
->GetName());
360 SetSentErrorMessage(true);
364 // we are in instance, and can summon only player in our group with us as lead
365 if ( !m_session
->GetPlayer()->GetGroup() || !chr
->GetGroup() ||
366 (chr
->GetGroup()->GetLeaderGUID() != m_session
->GetPlayer()->GetGUID()) ||
367 (m_session
->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session
->GetPlayer()->GetGUID()) )
368 // the last check is a bit excessive, but let it be, just in case
370 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST
,chr
->GetName());
371 SetSentErrorMessage(true);
376 PSendSysMessage(LANG_SUMMONING
, chr
->GetName(),"");
378 if (m_session
->GetPlayer()->IsVisibleGloballyFor(chr
))
379 ChatHandler(chr
).PSendSysMessage(LANG_SUMMONED_BY
, m_session
->GetPlayer()->GetName());
381 // stop flight if need
382 if(chr
->isInFlight())
384 chr
->GetMotionMaster()->MovementExpired();
385 chr
->m_taxi
.ClearTaxiDestinations();
387 // save only in non-flight case
389 chr
->SaveRecallPosition();
393 m_session
->GetPlayer()->GetClosePoint(x
,y
,z
,chr
->GetObjectSize());
394 chr
->TeleportTo(m_session
->GetPlayer()->GetMapId(),x
,y
,z
,chr
->GetOrientation());
396 else if (uint64 guid
= objmgr
.GetPlayerGUIDByName(name
))
398 PSendSysMessage(LANG_SUMMONING
, name
.c_str(),GetMangosString(LANG_OFFLINE
));
400 // in point where GM stay
401 Player::SavePositionInDB(m_session
->GetPlayer()->GetMapId(),
402 m_session
->GetPlayer()->GetPositionX(),
403 m_session
->GetPlayer()->GetPositionY(),
404 m_session
->GetPlayer()->GetPositionZ(),
405 m_session
->GetPlayer()->GetOrientation(),
406 m_session
->GetPlayer()->GetZoneId(),
411 PSendSysMessage(LANG_NO_PLAYER
, args
);
412 SetSentErrorMessage(true);
419 bool ChatHandler::HandleGonameCommand(const char* args
)
424 Player
* _player
= m_session
->GetPlayer();
426 std::string name
= args
;
428 if(!normalizePlayerName(name
))
430 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
431 SetSentErrorMessage(true);
435 Player
*chr
= objmgr
.GetPlayer(name
.c_str());
438 Map
* cMap
= MapManager::Instance().GetMap(chr
->GetMapId(),chr
);
439 if(cMap
->Instanceable())
441 Map
* pMap
= MapManager::Instance().GetMap(_player
->GetMapId(),_player
);
443 // we have to go to instance, and can go to player only if:
444 // 1) we are in his group (either as leader or as member)
445 // 2) we are not bound to any group and have GM mode on
446 if (_player
->GetGroup())
448 // we are in group, we can go only if we are in the player group
449 if (_player
->GetGroup() != chr
->GetGroup())
451 PSendSysMessage(LANG_CANNOT_GO_TO_INST_PARTY
,chr
->GetName());
452 SetSentErrorMessage(true);
458 // we are not in group, let's verify our GM mode
459 if (!_player
->isGameMaster())
461 PSendSysMessage(LANG_CANNOT_GO_TO_INST_GM
,chr
->GetName());
462 SetSentErrorMessage(true);
467 // if the player or the player's group is bound to another instance
468 // the player will not be bound to another one
469 InstancePlayerBind
*pBind
= _player
->GetBoundInstance(chr
->GetMapId(), chr
->GetDifficulty());
472 Group
*group
= _player
->GetGroup();
473 InstanceGroupBind
*gBind
= group
? group
->GetBoundInstance(chr
->GetMapId(), chr
->GetDifficulty()) : NULL
;
476 // if no bind exists, create a solo bind
477 InstanceSave
*save
= sInstanceSaveManager
.GetInstanceSave(chr
->GetInstanceId());
478 if(save
) _player
->BindToInstance(save
, !save
->CanReset());
482 _player
->SetDifficulty(chr
->GetDifficulty());
485 PSendSysMessage(LANG_APPEARING_AT
, chr
->GetName());
487 if (_player
->IsVisibleGloballyFor(chr
))
488 ChatHandler(chr
).PSendSysMessage(LANG_APPEARING_TO
, _player
->GetName());
490 // stop flight if need
491 if(_player
->isInFlight())
493 _player
->GetMotionMaster()->MovementExpired();
494 _player
->m_taxi
.ClearTaxiDestinations();
496 // save only in non-flight case
498 _player
->SaveRecallPosition();
500 // to point to see at target with same orientation
502 chr
->GetContactPoint(m_session
->GetPlayer(),x
,y
,z
);
504 _player
->TeleportTo(chr
->GetMapId(), x
, y
, z
, _player
->GetAngle( chr
), TELE_TO_GM_MODE
);
509 if (uint64 guid
= objmgr
.GetPlayerGUIDByName(name
))
511 PSendSysMessage(LANG_APPEARING_AT
, name
.c_str());
513 // to point where player stay (if loaded)
517 if(Player::LoadPositionFromDB(map
,x
,y
,z
,o
,in_flight
,guid
))
519 // stop flight if need
520 if(_player
->isInFlight())
522 _player
->GetMotionMaster()->MovementExpired();
523 _player
->m_taxi
.ClearTaxiDestinations();
525 // save only in non-flight case
527 _player
->SaveRecallPosition();
529 _player
->TeleportTo(map
, x
, y
, z
,_player
->GetOrientation());
534 PSendSysMessage(LANG_NO_PLAYER
, args
);
536 SetSentErrorMessage(true);
540 // Teleport player to last position
541 bool ChatHandler::HandleRecallCommand(const char* args
)
547 chr
= getSelectedPlayer();
549 chr
= m_session
->GetPlayer();
553 std::string name
= args
;
555 if(!normalizePlayerName(name
))
557 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
558 SetSentErrorMessage(true);
562 chr
= objmgr
.GetPlayer(name
.c_str());
566 PSendSysMessage(LANG_NO_PLAYER
, args
);
567 SetSentErrorMessage(true);
572 if(chr
->IsBeingTeleported())
574 PSendSysMessage(LANG_IS_TELEPORTED
, chr
->GetName());
575 SetSentErrorMessage(true);
579 // stop flight if need
580 if(chr
->isInFlight())
582 chr
->GetMotionMaster()->MovementExpired();
583 chr
->m_taxi
.ClearTaxiDestinations();
586 chr
->TeleportTo(chr
->m_recallMap
, chr
->m_recallX
, chr
->m_recallY
, chr
->m_recallZ
, chr
->m_recallO
);
590 //Edit Player KnownTitles
591 bool ChatHandler::HandleModifyKnownTitlesCommand(const char* args
)
598 sscanf((char*)args
, I64FMTD
, &titles
);
600 Player
*chr
= getSelectedPlayer();
603 SendSysMessage(LANG_NO_CHAR_SELECTED
);
604 SetSentErrorMessage(true);
608 uint64 titles2
= titles
;
610 for(int i
=1; i
< sCharTitlesStore
.GetNumRows(); ++i
)
611 if(CharTitlesEntry
const* tEntry
= sCharTitlesStore
.LookupEntry(i
))
612 titles2
&= ~(uint64(1) << tEntry
->bit_index
);
614 titles
&= ~titles2
; // remove not existed titles
616 chr
->SetUInt64Value(PLAYER__FIELD_KNOWN_TITLES
, titles
);
617 SendSysMessage(LANG_DONE
);
623 bool ChatHandler::HandleModifyHPCommand(const char* args
)
628 // char* pHp = strtok((char*)args, " ");
632 // char* pHpMax = strtok(NULL, " ");
636 // int32 hpm = atoi(pHpMax);
637 // int32 hp = atoi(pHp);
639 int32 hp
= atoi((char*)args
);
640 int32 hpm
= atoi((char*)args
);
642 if (hp
<= 0 || hpm
<= 0 || hpm
< hp
)
644 SendSysMessage(LANG_BAD_VALUE
);
645 SetSentErrorMessage(true);
649 Player
*chr
= getSelectedPlayer();
652 SendSysMessage(LANG_NO_CHAR_SELECTED
);
653 SetSentErrorMessage(true);
657 PSendSysMessage(LANG_YOU_CHANGE_HP
, chr
->GetName(), hp
, hpm
);
658 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_HP_CHANGED
, m_session
->GetPlayer()->GetName(), hp
, hpm
);
660 chr
->SetMaxHealth( hpm
);
661 chr
->SetHealth( hp
);
667 bool ChatHandler::HandleModifyManaCommand(const char* args
)
672 // char* pmana = strtok((char*)args, " ");
676 // char* pmanaMax = strtok(NULL, " ");
680 // int32 manam = atoi(pmanaMax);
681 // int32 mana = atoi(pmana);
682 int32 mana
= atoi((char*)args
);
683 int32 manam
= atoi((char*)args
);
685 if (mana
<= 0 || manam
<= 0 || manam
< mana
)
687 SendSysMessage(LANG_BAD_VALUE
);
688 SetSentErrorMessage(true);
692 Player
*chr
= getSelectedPlayer();
695 SendSysMessage(LANG_NO_CHAR_SELECTED
);
696 SetSentErrorMessage(true);
700 PSendSysMessage(LANG_YOU_CHANGE_MANA
, chr
->GetName(), mana
, manam
);
701 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_MANA_CHANGED
, m_session
->GetPlayer()->GetName(), mana
, manam
);
703 chr
->SetMaxPower(POWER_MANA
,manam
);
704 chr
->SetPower(POWER_MANA
, mana
);
710 bool ChatHandler::HandleModifyEnergyCommand(const char* args
)
715 // char* pmana = strtok((char*)args, " ");
719 // char* pmanaMax = strtok(NULL, " ");
723 // int32 manam = atoi(pmanaMax);
724 // int32 mana = atoi(pmana);
726 int32 energy
= atoi((char*)args
)*10;
727 int32 energym
= atoi((char*)args
)*10;
729 if (energy
<= 0 || energym
<= 0 || energym
< energy
)
731 SendSysMessage(LANG_BAD_VALUE
);
732 SetSentErrorMessage(true);
736 Player
*chr
= getSelectedPlayer();
739 SendSysMessage(LANG_NO_CHAR_SELECTED
);
740 SetSentErrorMessage(true);
744 PSendSysMessage(LANG_YOU_CHANGE_ENERGY
, chr
->GetName(), energy
/10, energym
/10);
745 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_ENERGY_CHANGED
, m_session
->GetPlayer()->GetName(), energy
/10, energym
/10);
747 chr
->SetMaxPower(POWER_ENERGY
,energym
);
748 chr
->SetPower(POWER_ENERGY
, energy
);
750 sLog
.outDetail(GetMangosString(LANG_CURRENT_ENERGY
),chr
->GetMaxPower(POWER_ENERGY
));
756 bool ChatHandler::HandleModifyRageCommand(const char* args
)
761 // char* pmana = strtok((char*)args, " ");
765 // char* pmanaMax = strtok(NULL, " ");
769 // int32 manam = atoi(pmanaMax);
770 // int32 mana = atoi(pmana);
772 int32 rage
= atoi((char*)args
)*10;
773 int32 ragem
= atoi((char*)args
)*10;
775 if (rage
<= 0 || ragem
<= 0 || ragem
< rage
)
777 SendSysMessage(LANG_BAD_VALUE
);
778 SetSentErrorMessage(true);
782 Player
*chr
= getSelectedPlayer();
785 SendSysMessage(LANG_NO_CHAR_SELECTED
);
786 SetSentErrorMessage(true);
790 PSendSysMessage(LANG_YOU_CHANGE_RAGE
, chr
->GetName(), rage
/10, ragem
/10);
791 // Special case: I use GetMangosString here to get local of destination char ;)
792 ChatHandler(chr
).PSendSysMessage(ChatHandler(chr
).GetMangosString(LANG_YOURS_RAGE_CHANGED
), m_session
->GetPlayer()->GetName(), rage
/10, ragem
/10);
794 chr
->SetMaxPower(POWER_RAGE
,ragem
);
795 chr
->SetPower(POWER_RAGE
, rage
);
800 //Edit Player Faction
801 bool ChatHandler::HandleModifyFactionCommand(const char* args
)
806 char* pfactionid
= extractKeyFromLink((char*)args
,"Hfaction");
808 Creature
* chr
= getSelectedCreature();
811 SendSysMessage(LANG_SELECT_CREATURE
);
812 SetSentErrorMessage(true);
820 uint32 factionid
= chr
->getFaction();
821 uint32 flag
= chr
->GetUInt32Value(UNIT_FIELD_FLAGS
);
822 uint32 npcflag
= chr
->GetUInt32Value(UNIT_NPC_FLAGS
);
823 uint32 dyflag
= chr
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
);
824 PSendSysMessage(LANG_CURRENT_FACTION
,chr
->GetGUIDLow(),factionid
,flag
,npcflag
,dyflag
);
831 SendSysMessage(LANG_NO_CHAR_SELECTED
);
832 SetSentErrorMessage(true);
836 uint32 factionid
= atoi(pfactionid
);
839 char *pflag
= strtok(NULL
, " ");
841 flag
= chr
->GetUInt32Value(UNIT_FIELD_FLAGS
);
845 char* pnpcflag
= strtok(NULL
, " ");
849 npcflag
= chr
->GetUInt32Value(UNIT_NPC_FLAGS
);
851 npcflag
= atoi(pnpcflag
);
853 char* pdyflag
= strtok(NULL
, " ");
857 dyflag
= chr
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
);
859 dyflag
= atoi(pdyflag
);
861 if(!sFactionTemplateStore
.LookupEntry(factionid
))
863 PSendSysMessage(LANG_WRONG_FACTION
, factionid
);
864 SetSentErrorMessage(true);
868 PSendSysMessage(LANG_YOU_CHANGE_FACTION
, chr
->GetGUIDLow(),factionid
,flag
,npcflag
,dyflag
);
870 //sprintf((char*)buf,"%s changed your Faction to %i.", m_session->GetPlayer()->GetName(), factionid);
871 //FillSystemMessageData(&data, m_session, buf);
873 //chr->GetSession()->SendPacket(&data);
875 chr
->setFaction(factionid
);
876 chr
->SetUInt32Value(UNIT_FIELD_FLAGS
,flag
);
877 chr
->SetUInt32Value(UNIT_NPC_FLAGS
,npcflag
);
878 chr
->SetUInt32Value(UNIT_DYNAMIC_FLAGS
,dyflag
);
884 bool ChatHandler::HandleModifySpellCommand(const char* args
)
886 if(!*args
) return false;
887 char* pspellflatid
= strtok((char*)args
, " ");
891 char* pop
= strtok(NULL
, " ");
895 char* pval
= strtok(NULL
, " ");
901 char* pmark
= strtok(NULL
, " ");
903 uint8 spellflatid
= atoi(pspellflatid
);
904 uint8 op
= atoi(pop
);
905 uint16 val
= atoi(pval
);
911 Player
*chr
= getSelectedPlayer();
914 SendSysMessage(LANG_NO_CHAR_SELECTED
);
915 SetSentErrorMessage(true);
919 PSendSysMessage(LANG_YOU_CHANGE_SPELLFLATID
, spellflatid
, val
, mark
, chr
->GetName());
920 if(chr
!= m_session
->GetPlayer())
921 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_SPELLFLATID_CHANGED
, m_session
->GetPlayer()->GetName(), spellflatid
, val
, mark
);
923 WorldPacket
data(SMSG_SET_FLAT_SPELL_MODIFIER
, (1+1+2+2));
924 data
<< uint8(spellflatid
);
927 data
<< uint16(mark
);
928 chr
->GetSession()->SendPacket(&data
);
934 bool ChatHandler::HandleModifyTalentCommand (const char* args
)
939 int tp
= atoi((char*)args
);
942 Player
* player
= getSelectedPlayer();
945 SendSysMessage(LANG_NO_CHAR_SELECTED
);
946 SetSentErrorMessage(true);
949 player
->SetFreeTalentPoints(tp
);
955 //Enable On\OFF all taxi paths
956 bool ChatHandler::HandleTaxiCheatCommand(const char* args
)
960 SendSysMessage(LANG_USE_BOL
);
961 SetSentErrorMessage(true);
965 std::string argstr
= (char*)args
;
967 Player
*chr
= getSelectedPlayer();
970 chr
=m_session
->GetPlayer();
975 chr
->SetTaxiCheater(true);
976 PSendSysMessage(LANG_YOU_GIVE_TAXIS
, chr
->GetName());
978 if(chr
!= m_session
->GetPlayer())
979 // to send localized data to target
980 ChatHandler(chr
).PSendSysMessage(ChatHandler(chr
).GetMangosString(LANG_YOURS_TAXIS_ADDED
), m_session
->GetPlayer()->GetName());
986 chr
->SetTaxiCheater(false);
987 PSendSysMessage(LANG_YOU_REMOVE_TAXIS
, chr
->GetName());
989 if(chr
!= m_session
->GetPlayer())
990 ChatHandler(chr
).PSendSysMessage(ChatHandler(chr
).GetMangosString(LANG_YOURS_TAXIS_REMOVED
), m_session
->GetPlayer()->GetName());
995 SendSysMessage(LANG_USE_BOL
);
996 SetSentErrorMessage(true);
1000 //Edit Player Aspeed
1001 bool ChatHandler::HandleModifyASpeedCommand(const char* args
)
1006 float ASpeed
= (float)atof((char*)args
);
1008 if (ASpeed
> 10 || ASpeed
< 0.1)
1010 SendSysMessage(LANG_BAD_VALUE
);
1011 SetSentErrorMessage(true);
1015 Player
*chr
= getSelectedPlayer();
1018 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1019 SetSentErrorMessage(true);
1023 if(chr
->isInFlight())
1025 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chr
->GetName());
1026 SetSentErrorMessage(true);
1030 PSendSysMessage(LANG_YOU_CHANGE_ASPEED
, ASpeed
, chr
->GetName());
1032 if(chr
!= m_session
->GetPlayer())
1033 ChatHandler(chr
).PSendSysMessage(ChatHandler(chr
).GetMangosString(LANG_YOURS_ASPEED_CHANGED
), m_session
->GetPlayer()->GetName(), ASpeed
);
1035 chr
->SetSpeed(MOVE_WALK
, ASpeed
,true);
1036 chr
->SetSpeed(MOVE_RUN
, ASpeed
,true);
1037 chr
->SetSpeed(MOVE_SWIM
, ASpeed
,true);
1038 //chr->SetSpeed(MOVE_TURN, ASpeed,true);
1039 chr
->SetSpeed(MOVE_FLY
, ASpeed
,true);
1044 bool ChatHandler::HandleModifySpeedCommand(const char* args
)
1049 float Speed
= (float)atof((char*)args
);
1051 if (Speed
> 10 || Speed
< 0.1)
1053 SendSysMessage(LANG_BAD_VALUE
);
1054 SetSentErrorMessage(true);
1058 Player
*chr
= getSelectedPlayer();
1061 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1062 SetSentErrorMessage(true);
1066 if(chr
->isInFlight())
1068 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chr
->GetName());
1069 SetSentErrorMessage(true);
1073 PSendSysMessage(LANG_YOU_CHANGE_SPEED
, Speed
, chr
->GetName());
1075 if(chr
!= m_session
->GetPlayer())
1076 ChatHandler(chr
).PSendSysMessage(ChatHandler(chr
).GetMangosString(LANG_YOURS_SPEED_CHANGED
), m_session
->GetPlayer()->GetName(), Speed
);
1078 chr
->SetSpeed(MOVE_RUN
,Speed
,true);
1083 //Edit Player Swim Speed
1084 bool ChatHandler::HandleModifySwimCommand(const char* args
)
1089 float Swim
= (float)atof((char*)args
);
1091 if (Swim
> 10.0f
|| Swim
< 0.01f
)
1093 SendSysMessage(LANG_BAD_VALUE
);
1094 SetSentErrorMessage(true);
1098 Player
*chr
= getSelectedPlayer();
1101 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1102 SetSentErrorMessage(true);
1106 if(chr
->isInFlight())
1108 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chr
->GetName());
1109 SetSentErrorMessage(true);
1113 PSendSysMessage(LANG_YOU_CHANGE_SWIM_SPEED
, Swim
, chr
->GetName());
1115 if(chr
!= m_session
->GetPlayer())
1116 ChatHandler(chr
).PSendSysMessage(ChatHandler(chr
).GetMangosString(LANG_YOURS_SWIM_SPEED_CHANGED
), m_session
->GetPlayer()->GetName(), Swim
);
1118 chr
->SetSpeed(MOVE_SWIM
,Swim
,true);
1123 //Edit Player Walk Speed
1124 bool ChatHandler::HandleModifyBWalkCommand(const char* args
)
1129 float BSpeed
= (float)atof((char*)args
);
1131 if (BSpeed
> 10.0f
|| BSpeed
< 0.1f
)
1133 SendSysMessage(LANG_BAD_VALUE
);
1134 SetSentErrorMessage(true);
1138 Player
*chr
= getSelectedPlayer();
1141 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1142 SetSentErrorMessage(true);
1146 if(chr
->isInFlight())
1148 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chr
->GetName());
1149 SetSentErrorMessage(true);
1153 PSendSysMessage(LANG_YOU_CHANGE_BACK_SPEED
, BSpeed
, chr
->GetName());
1155 if(chr
!= m_session
->GetPlayer())
1156 ChatHandler(chr
).PSendSysMessage(ChatHandler(chr
).GetMangosString(LANG_YOURS_BACK_SPEED_CHANGED
), m_session
->GetPlayer()->GetName(), BSpeed
);
1158 chr
->SetSpeed(MOVE_WALKBACK
,BSpeed
,true);
1164 bool ChatHandler::HandleModifyFlyCommand(const char* args
)
1169 float FSpeed
= (float)atof((char*)args
);
1171 if (FSpeed
> 10.0f
|| FSpeed
< 0.1f
)
1173 SendSysMessage(LANG_BAD_VALUE
);
1174 SetSentErrorMessage(true);
1178 Player
*chr
= getSelectedPlayer();
1181 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1182 SetSentErrorMessage(true);
1186 PSendSysMessage(LANG_YOU_CHANGE_FLY_SPEED
, FSpeed
, chr
->GetName());
1188 if(chr
!= m_session
->GetPlayer())
1189 ChatHandler(chr
).PSendSysMessage(ChatHandler(chr
).GetMangosString(LANG_YOURS_FLY_SPEED_CHANGED
), m_session
->GetPlayer()->GetName(), FSpeed
);
1191 chr
->SetSpeed(MOVE_FLY
,FSpeed
,true);
1197 bool ChatHandler::HandleModifyScaleCommand(const char* args
)
1202 float Scale
= (float)atof((char*)args
);
1203 if (Scale
> 3.0f
|| Scale
<= 0.0f
)
1205 SendSysMessage(LANG_BAD_VALUE
);
1206 SetSentErrorMessage(true);
1210 Player
*chr
= getSelectedPlayer();
1213 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1214 SetSentErrorMessage(true);
1218 PSendSysMessage(LANG_YOU_CHANGE_SIZE
, Scale
, chr
->GetName());
1220 if(chr
!= m_session
->GetPlayer())
1221 ChatHandler(chr
).PSendSysMessage(ChatHandler(chr
).GetMangosString(LANG_YOURS_SIZE_CHANGED
), m_session
->GetPlayer()->GetName(), Scale
);
1223 chr
->SetFloatValue(OBJECT_FIELD_SCALE_X
, Scale
);
1228 //Enable Player mount
1229 bool ChatHandler::HandleModifyMountCommand(const char* args
)
1235 float speed
= (float)15;
1238 num
= atoi((char*)args
);
1449 SendSysMessage(LANG_NO_MOUNT
);
1450 SetSentErrorMessage(true);
1454 Player
*chr
= getSelectedPlayer();
1457 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1458 SetSentErrorMessage(true);
1462 PSendSysMessage(LANG_YOU_GIVE_MOUNT
, chr
->GetName());
1464 if(chr
!= m_session
->GetPlayer())
1465 ChatHandler(chr
).PSendSysMessage(ChatHandler(chr
).GetMangosString(LANG_MOUNT_GIVED
), m_session
->GetPlayer()->GetName());
1467 chr
->SetUInt32Value( UNIT_FIELD_FLAGS
, 0x001000 );
1470 WorldPacket
data( SMSG_FORCE_RUN_SPEED_CHANGE
, (8+4+1+4) );
1471 data
.append(chr
->GetPackGUID());
1473 data
<< (uint8
)0; //new 2.1.0
1474 data
<< float(speed
);
1475 chr
->SendMessageToSet( &data
, true );
1477 data
.Initialize( SMSG_FORCE_SWIM_SPEED_CHANGE
, (8+4+4) );
1478 data
.append(chr
->GetPackGUID());
1480 data
<< float(speed
);
1481 chr
->SendMessageToSet( &data
, true );
1487 bool ChatHandler::HandleModifyMoneyCommand(const char* args
)
1492 Player
*chr
= getSelectedPlayer();
1495 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1496 SetSentErrorMessage(true);
1500 int32 addmoney
= atoi((char*)args
);
1502 uint32 moneyuser
= chr
->GetMoney();
1506 int32 newmoney
= moneyuser
+ addmoney
;
1508 sLog
.outDetail(GetMangosString(LANG_CURRENT_MONEY
), moneyuser
, addmoney
, newmoney
);
1511 PSendSysMessage(LANG_YOU_TAKE_ALL_MONEY
, chr
->GetName());
1513 if(chr
!= m_session
->GetPlayer())
1514 ChatHandler(chr
).PSendSysMessage(ChatHandler(chr
).GetMangosString(LANG_YOURS_ALL_MONEY_GONE
), m_session
->GetPlayer()->GetName());
1520 PSendSysMessage(LANG_YOU_TAKE_MONEY
, abs(addmoney
), chr
->GetName());
1521 if(chr
!= m_session
->GetPlayer())
1522 ChatHandler(chr
).PSendSysMessage(ChatHandler(chr
).GetMangosString(LANG_YOURS_MONEY_TAKEN
), m_session
->GetPlayer()->GetName(), abs(addmoney
));
1523 chr
->SetMoney( newmoney
);
1528 PSendSysMessage(LANG_YOU_GIVE_MONEY
, addmoney
, chr
->GetName());
1529 if(chr
!= m_session
->GetPlayer())
1530 ChatHandler(chr
).PSendSysMessage(ChatHandler(chr
).GetMangosString(LANG_YOURS_MONEY_GIVEN
), m_session
->GetPlayer()->GetName(), addmoney
);
1531 chr
->ModifyMoney( addmoney
);
1534 sLog
.outDetail(GetMangosString(LANG_NEW_MONEY
), moneyuser
, addmoney
, chr
->GetMoney() );
1540 bool ChatHandler::HandleModifyBitCommand(const char* args
)
1545 Player
*chr
= getSelectedPlayer();
1548 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1549 SetSentErrorMessage(true);
1553 char* pField
= strtok((char*)args
, " ");
1557 char* pBit
= strtok(NULL
, " ");
1561 uint16 field
= atoi(pField
);
1562 uint32 bit
= atoi(pBit
);
1564 if (field
< 1 || field
>= PLAYER_END
)
1566 SendSysMessage(LANG_BAD_VALUE
);
1567 SetSentErrorMessage(true);
1571 if (bit
< 1 || bit
> 32)
1573 SendSysMessage(LANG_BAD_VALUE
);
1574 SetSentErrorMessage(true);
1578 if ( chr
->HasFlag( field
, (1<<(bit
-1)) ) )
1580 chr
->RemoveFlag( field
, (1<<(bit
-1)) );
1581 PSendSysMessage(LANG_REMOVE_BIT
, bit
, field
);
1585 chr
->SetFlag( field
, (1<<(bit
-1)) );
1586 PSendSysMessage(LANG_SET_BIT
, bit
, field
);
1592 bool ChatHandler::HandleModifyHonorCommand (const char* args
)
1597 Player
*target
= getSelectedPlayer();
1600 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1601 SetSentErrorMessage(true);
1605 int32 amount
= (uint32
)atoi(args
);
1607 target
->ModifyHonorPoints(amount
);
1609 PSendSysMessage(LANG_COMMAND_MODIFY_HONOR
, target
->GetName(), target
->GetHonorPoints());
1614 bool ChatHandler::HandleTeleCommand(const char * args
)
1619 Player
* _player
= m_session
->GetPlayer();
1621 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
1622 GameTele
const* tele
= extractGameTeleFromLink((char*)args
);
1626 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
1627 SetSentErrorMessage(true);
1631 // stop flight if need
1632 if(_player
->isInFlight())
1634 _player
->GetMotionMaster()->MovementExpired();
1635 _player
->m_taxi
.ClearTaxiDestinations();
1637 // save only in non-flight case
1639 _player
->SaveRecallPosition();
1641 _player
->TeleportTo(tele
->mapId
, tele
->position_x
, tele
->position_y
, tele
->position_z
, tele
->orientation
);
1645 bool ChatHandler::HandleLookupAreaCommand(const char* args
)
1650 std::string namepart
= args
;
1651 std::wstring wnamepart
;
1653 if(!Utf8toWStr(namepart
,wnamepart
))
1656 uint32 counter
= 0; // Counter for figure out that we found smth.
1658 // converting string that we try to find to lower case
1659 wstrToLower( wnamepart
);
1661 // Search in AreaTable.dbc
1662 for (uint32 areaflag
= 0; areaflag
< sAreaStore
.GetNumRows(); ++areaflag
)
1664 AreaTableEntry
const *areaEntry
= sAreaStore
.LookupEntry(areaflag
);
1667 int loc
= m_session
->GetSessionDbcLocale();
1668 std::string name
= areaEntry
->area_name
[loc
];
1672 if(!Utf8FitTo(name
, wnamepart
))
1675 for(; loc
< MAX_LOCALE
; ++loc
)
1677 if(loc
==m_session
->GetSessionDbcLocale())
1680 name
= areaEntry
->area_name
[loc
];
1684 if (Utf8FitTo(name
, wnamepart
))
1689 if(loc
< MAX_LOCALE
)
1691 // send area in "id - [name]" format
1692 std::ostringstream ss
;
1693 ss
<< areaEntry
->ID
<< " - |cffffffff|Harea:" << areaEntry
->ID
<< "|h[" << name
<< " " << localeNames
[loc
]<< "]|h|r";
1695 SendSysMessage(ss
.str().c_str());
1701 if (counter
== 0) // if counter == 0 then we found nth
1702 SendSysMessage(LANG_COMMAND_NOAREAFOUND
);
1706 //Find tele in game_tele order by name
1707 bool ChatHandler::HandleLookupTeleCommand(const char * args
)
1711 SendSysMessage(LANG_COMMAND_TELE_PARAMETER
);
1712 SetSentErrorMessage(true);
1715 char const* str
= strtok((char*)args
, " ");
1719 std::string namepart
= str
;
1720 std::wstring wnamepart
;
1722 if(!Utf8toWStr(namepart
,wnamepart
))
1725 // converting string that we try to find to lower case
1726 wstrToLower( wnamepart
);
1728 GameTeleMap
const & teleMap
= objmgr
.GetGameTeleMap();
1730 std::ostringstream reply
;
1731 for(GameTeleMap::const_iterator itr
= teleMap
.begin(); itr
!= teleMap
.end(); ++itr
)
1733 GameTele
const* tele
= &itr
->second
;
1735 if(tele
->wnameLow
.find(wnamepart
) == std::wstring::npos
)
1738 reply
<< " |cffffffff|Htele:";
1739 reply
<< itr
->first
;
1741 reply
<< tele
->name
;
1745 if(reply
.str().empty())
1746 SendSysMessage(LANG_COMMAND_TELE_NOLOCATION
);
1748 PSendSysMessage(LANG_COMMAND_TELE_LOCATION
,reply
.str().c_str());
1753 //Enable\Dissable accept whispers (for GM)
1754 bool ChatHandler::HandleWhispersCommand(const char* args
)
1758 PSendSysMessage(LANG_COMMAND_WHISPERACCEPTING
, m_session
->GetPlayer()->isAcceptWhispers() ? GetMangosString(LANG_ON
) : GetMangosString(LANG_OFF
));
1762 std::string argstr
= (char*)args
;
1766 m_session
->GetPlayer()->SetAcceptWhispers(true);
1767 SendSysMessage(LANG_COMMAND_WHISPERON
);
1772 if (argstr
== "off")
1774 m_session
->GetPlayer()->SetAcceptWhispers(false);
1775 SendSysMessage(LANG_COMMAND_WHISPEROFF
);
1779 SendSysMessage(LANG_USE_BOL
);
1780 SetSentErrorMessage(true);
1785 bool ChatHandler::HandlePlaySoundCommand(const char* args
)
1787 // USAGE: .debug playsound #soundid
1788 // #soundid - ID decimal number from SoundEntries.dbc (1st column)
1789 // this file have about 5000 sounds.
1790 // In this realization only caller can hear this sound.
1793 uint32 dwSoundId
= atoi((char*)args
);
1795 if( !sSoundEntriesStore
.LookupEntry(dwSoundId
) )
1797 PSendSysMessage(LANG_SOUND_NOT_EXIST
, dwSoundId
);
1798 SetSentErrorMessage(true);
1802 WorldPacket
data(SMSG_PLAY_OBJECT_SOUND
,4+8);
1803 data
<< uint32(dwSoundId
) << m_session
->GetPlayer()->GetGUID();
1804 m_session
->SendPacket(&data
);
1806 PSendSysMessage(LANG_YOU_HEAR_SOUND
, dwSoundId
);
1813 //Save all players in the world
1814 bool ChatHandler::HandleSaveAllCommand(const char* /*args*/)
1816 ObjectAccessor::Instance().SaveAllPlayers();
1817 SendSysMessage(LANG_PLAYERS_SAVED
);
1821 //Send mail by command
1822 bool ChatHandler::HandleSendMailCommand(const char* args
)
1827 // format: name "subject text" "mail text" item1[:count1] item2[:count2] ... item12[:count12]
1829 char* pName
= strtok((char*)args
, " ");
1833 char* tail1
= strtok(NULL
, "");
1839 msgSubject
= strtok(tail1
+1, "\"");
1842 char* space
= strtok(tail1
, "\"");
1845 msgSubject
= strtok(NULL
, "\"");
1851 char* tail2
= strtok(NULL
, "");
1857 msgText
= strtok(tail2
+1, "\"");
1860 char* space
= strtok(tail2
, "\"");
1863 msgText
= strtok(NULL
, "\"");
1869 // pName, msgSubject, msgText isn't NUL after prev. check
1870 std::string name
= pName
;
1871 std::string subject
= msgSubject
;
1872 std::string text
= msgText
;
1875 typedef std::pair
<uint32
,uint32
> ItemPair
;
1876 typedef std::list
< ItemPair
> ItemPairs
;
1879 // get all tail string
1880 char* tail
= strtok(NULL
, "");
1882 // get from tail next item str
1883 while(char* itemStr
= strtok(tail
, " "))
1886 tail
= strtok(NULL
, "");
1889 char* itemIdStr
= strtok(itemStr
, ":");
1890 char* itemCountStr
= strtok(NULL
, " ");
1892 uint32 item_id
= atoi(itemIdStr
);
1896 ItemPrototype
const* item_proto
= objmgr
.GetItemPrototype(item_id
);
1899 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
1900 SetSentErrorMessage(true);
1904 uint32 item_count
= itemCountStr
? atoi(itemCountStr
) : 1;
1905 if(item_count
< 1 || item_proto
->MaxCount
&& item_count
> item_proto
->MaxCount
)
1907 PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT
, item_count
,item_id
);
1908 SetSentErrorMessage(true);
1912 while(item_count
> item_proto
->Stackable
)
1914 items
.push_back(ItemPair(item_id
,item_proto
->Stackable
));
1915 item_count
-= item_proto
->Stackable
;
1918 items
.push_back(ItemPair(item_id
,item_count
));
1920 if(items
.size() > MAX_MAIL_ITEMS
)
1922 PSendSysMessage(LANG_COMMAND_MAIL_ITEMS_LIMIT
, MAX_MAIL_ITEMS
);
1923 SetSentErrorMessage(true);
1928 if(!normalizePlayerName(name
))
1930 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1931 SetSentErrorMessage(true);
1935 uint64 receiver_guid
= objmgr
.GetPlayerGUIDByName(name
);
1938 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1939 SetSentErrorMessage(true);
1943 uint32 mailId
= objmgr
.GenerateMailID();
1944 uint32 sender_guidlo
= m_session
->GetPlayer()->GetGUIDLow();
1945 uint32 messagetype
= MAIL_NORMAL
;
1946 uint32 stationery
= MAIL_STATIONERY_GM
;
1947 uint32 itemTextId
= 0;
1950 itemTextId
= objmgr
.CreateItemText( text
);
1953 Player
*receiver
= objmgr
.GetPlayer(receiver_guid
);
1956 MailItemsInfo mi
; // item list preparing
1958 for(ItemPairs::const_iterator itr
= items
.begin(); itr
!= items
.end(); ++itr
)
1960 if(Item
* item
= Item::CreateItem(itr
->first
,itr
->second
,m_session
->GetPlayer()))
1962 item
->SaveToDB(); // save for prevent lost at next mail load, if send fail then item will deleted
1963 mi
.AddItem(item
->GetGUIDLow(), item
->GetEntry(), item
);
1967 WorldSession::SendMailTo(receiver
,messagetype
, stationery
, sender_guidlo
, GUID_LOPART(receiver_guid
), subject
, itemTextId
, &mi
, 0, 0, MAIL_CHECK_MASK_NONE
);
1969 PSendSysMessage(LANG_MAIL_SENT
, name
.c_str());
1973 // teleport player to given game_tele.entry
1974 bool ChatHandler::HandleNameTeleCommand(const char * args
)
1979 char* pName
= strtok((char*)args
, " ");
1984 std::string name
= pName
;
1986 if(!normalizePlayerName(name
))
1988 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1989 SetSentErrorMessage(true);
1993 char* tail
= strtok(NULL
, "");
1997 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
1998 GameTele
const* tele
= extractGameTeleFromLink(tail
);
2001 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
2002 SetSentErrorMessage(true);
2006 Player
*chr
= objmgr
.GetPlayer(name
.c_str());
2010 if(chr
->IsBeingTeleported()==true)
2012 PSendSysMessage(LANG_IS_TELEPORTED
, chr
->GetName());
2013 SetSentErrorMessage(true);
2017 PSendSysMessage(LANG_TELEPORTING_TO
, chr
->GetName(),"", tele
->name
.c_str());
2021 if(m_session
->GetPlayer()->IsVisibleGloballyFor(chr
))
2022 ChatHandler(chr
).PSendSysMessage(LANG_TELEPORTED_TO_BY
, m_session
->GetPlayer()->GetName());
2025 ChatHandler(chr
).SendSysMessage(LANG_TELEPORTED_TO_BY_CONSOLE
);
2027 // stop flight if need
2028 if(chr
->isInFlight())
2030 chr
->GetMotionMaster()->MovementExpired();
2031 chr
->m_taxi
.ClearTaxiDestinations();
2033 // save only in non-flight case
2035 chr
->SaveRecallPosition();
2037 chr
->TeleportTo(tele
->mapId
,tele
->position_x
,tele
->position_y
,tele
->position_z
,tele
->orientation
);
2039 else if (uint64 guid
= objmgr
.GetPlayerGUIDByName(name
.c_str()))
2041 PSendSysMessage(LANG_TELEPORTING_TO
, name
.c_str(), GetMangosString(LANG_OFFLINE
), tele
->name
.c_str());
2042 Player::SavePositionInDB(tele
->mapId
,tele
->position_x
,tele
->position_y
,tele
->position_z
,tele
->orientation
,MapManager::Instance().GetZoneId(tele
->mapId
,tele
->position_x
,tele
->position_y
),guid
);
2045 PSendSysMessage(LANG_NO_PLAYER
, name
.c_str());
2050 //Teleport group to given game_tele.entry
2051 bool ChatHandler::HandleGroupTeleCommand(const char * args
)
2056 Player
*player
= getSelectedPlayer();
2059 SendSysMessage(LANG_NO_CHAR_SELECTED
);
2060 SetSentErrorMessage(true);
2064 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2065 GameTele
const* tele
= extractGameTeleFromLink((char*)args
);
2068 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
2069 SetSentErrorMessage(true);
2073 Group
*grp
= player
->GetGroup();
2076 PSendSysMessage(LANG_NOT_IN_GROUP
,player
->GetName());
2077 SetSentErrorMessage(true);
2081 for(GroupReference
*itr
= grp
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
2083 Player
*pl
= itr
->getSource();
2085 if(!pl
|| !pl
->GetSession() )
2088 if(pl
->IsBeingTeleported())
2090 PSendSysMessage(LANG_IS_TELEPORTED
, pl
->GetName());
2094 PSendSysMessage(LANG_TELEPORTING_TO
, pl
->GetName(),"", tele
->name
.c_str());
2096 if (m_session
->GetPlayer() != pl
&& m_session
->GetPlayer()->IsVisibleGloballyFor(pl
))
2097 ChatHandler(pl
).PSendSysMessage(LANG_TELEPORTED_TO_BY
, m_session
->GetPlayer()->GetName());
2099 // stop flight if need
2100 if(pl
->isInFlight())
2102 pl
->GetMotionMaster()->MovementExpired();
2103 pl
->m_taxi
.ClearTaxiDestinations();
2105 // save only in non-flight case
2107 pl
->SaveRecallPosition();
2109 pl
->TeleportTo(tele
->mapId
, tele
->position_x
, tele
->position_y
, tele
->position_z
, tele
->orientation
);
2115 //Summon group of player
2116 bool ChatHandler::HandleGroupgoCommand(const char* args
)
2121 std::string name
= args
;
2123 if(!normalizePlayerName(name
))
2125 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
2126 SetSentErrorMessage(true);
2130 Player
*player
= objmgr
.GetPlayer(name
.c_str());
2133 PSendSysMessage(LANG_NO_PLAYER
, args
);
2134 SetSentErrorMessage(true);
2138 Group
*grp
= player
->GetGroup();
2142 PSendSysMessage(LANG_NOT_IN_GROUP
,player
->GetName());
2143 SetSentErrorMessage(true);
2147 Map
* gmMap
= MapManager::Instance().GetMap(m_session
->GetPlayer()->GetMapId(),m_session
->GetPlayer());
2148 bool to_instance
= gmMap
->Instanceable();
2150 // we are in instance, and can summon only player in our group with us as lead
2151 if ( to_instance
&& (
2152 !m_session
->GetPlayer()->GetGroup() || (grp
->GetLeaderGUID() != m_session
->GetPlayer()->GetGUID()) ||
2153 (m_session
->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session
->GetPlayer()->GetGUID()) ) )
2154 // the last check is a bit excessive, but let it be, just in case
2156 SendSysMessage(LANG_CANNOT_SUMMON_TO_INST
);
2157 SetSentErrorMessage(true);
2161 for(GroupReference
*itr
= grp
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
2163 Player
*pl
= itr
->getSource();
2165 if(!pl
|| pl
==m_session
->GetPlayer() || !pl
->GetSession() )
2168 if(pl
->IsBeingTeleported()==true)
2170 PSendSysMessage(LANG_IS_TELEPORTED
, pl
->GetName());
2171 SetSentErrorMessage(true);
2177 Map
* plMap
= MapManager::Instance().GetMap(pl
->GetMapId(),pl
);
2179 if ( plMap
->Instanceable() && plMap
->GetInstanceId() != gmMap
->GetInstanceId() )
2181 // cannot summon from instance to instance
2182 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST
,pl
->GetName());
2183 SetSentErrorMessage(true);
2188 PSendSysMessage(LANG_SUMMONING
, pl
->GetName(),"");
2190 if (m_session
->GetPlayer()->IsVisibleGloballyFor(pl
))
2191 ChatHandler(pl
).PSendSysMessage(LANG_SUMMONED_BY
, m_session
->GetPlayer()->GetName());
2193 // stop flight if need
2194 if(pl
->isInFlight())
2196 pl
->GetMotionMaster()->MovementExpired();
2197 pl
->m_taxi
.ClearTaxiDestinations();
2199 // save only in non-flight case
2201 pl
->SaveRecallPosition();
2205 m_session
->GetPlayer()->GetClosePoint(x
,y
,z
,pl
->GetObjectSize());
2206 pl
->TeleportTo(m_session
->GetPlayer()->GetMapId(),x
,y
,z
,pl
->GetOrientation());
2212 //teleport at coordinates
2213 bool ChatHandler::HandleGoXYCommand(const char* args
)
2218 Player
* _player
= m_session
->GetPlayer();
2220 char* px
= strtok((char*)args
, " ");
2221 char* py
= strtok(NULL
, " ");
2222 char* pmapid
= strtok(NULL
, " ");
2227 float x
= (float)atof(px
);
2228 float y
= (float)atof(py
);
2231 mapid
= (uint32
)atoi(pmapid
);
2232 else mapid
= _player
->GetMapId();
2234 if(!MapManager::IsValidMapCoord(mapid
,x
,y
))
2236 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,mapid
);
2237 SetSentErrorMessage(true);
2241 // stop flight if need
2242 if(_player
->isInFlight())
2244 _player
->GetMotionMaster()->MovementExpired();
2245 _player
->m_taxi
.ClearTaxiDestinations();
2247 // save only in non-flight case
2249 _player
->SaveRecallPosition();
2251 Map
const *map
= MapManager::Instance().GetBaseMap(mapid
);
2252 float z
= std::max(map
->GetHeight(x
, y
, MAX_HEIGHT
), map
->GetWaterLevel(x
, y
));
2254 _player
->TeleportTo(mapid
, x
, y
, z
, _player
->GetOrientation());
2259 //teleport at coordinates, including Z
2260 bool ChatHandler::HandleGoXYZCommand(const char* args
)
2265 Player
* _player
= m_session
->GetPlayer();
2267 char* px
= strtok((char*)args
, " ");
2268 char* py
= strtok(NULL
, " ");
2269 char* pz
= strtok(NULL
, " ");
2270 char* pmapid
= strtok(NULL
, " ");
2272 if (!px
|| !py
|| !pz
)
2275 float x
= (float)atof(px
);
2276 float y
= (float)atof(py
);
2277 float z
= (float)atof(pz
);
2280 mapid
= (uint32
)atoi(pmapid
);
2282 mapid
= _player
->GetMapId();
2284 if(!MapManager::IsValidMapCoord(mapid
,x
,y
,z
))
2286 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,mapid
);
2287 SetSentErrorMessage(true);
2291 // stop flight if need
2292 if(_player
->isInFlight())
2294 _player
->GetMotionMaster()->MovementExpired();
2295 _player
->m_taxi
.ClearTaxiDestinations();
2297 // save only in non-flight case
2299 _player
->SaveRecallPosition();
2301 _player
->TeleportTo(mapid
, x
, y
, z
, _player
->GetOrientation());
2306 //teleport at coordinates
2307 bool ChatHandler::HandleGoZoneXYCommand(const char* args
)
2312 Player
* _player
= m_session
->GetPlayer();
2314 char* px
= strtok((char*)args
, " ");
2315 char* py
= strtok(NULL
, " ");
2316 char* tail
= strtok(NULL
,"");
2318 char* cAreaId
= extractKeyFromLink(tail
,"Harea"); // string or [name] Shift-click form |color|Harea:area_id|h[name]|h|r
2323 float x
= (float)atof(px
);
2324 float y
= (float)atof(py
);
2325 uint32 areaid
= cAreaId
? (uint32
)atoi(cAreaId
) : _player
->GetZoneId();
2327 AreaTableEntry
const* areaEntry
= GetAreaEntryByAreaID(areaid
);
2329 if( x
<0 || x
>100 || y
<0 || y
>100 || !areaEntry
)
2331 PSendSysMessage(LANG_INVALID_ZONE_COORD
,x
,y
,areaid
);
2332 SetSentErrorMessage(true);
2336 // update to parent zone if exist (client map show only zones without parents)
2337 AreaTableEntry
const* zoneEntry
= areaEntry
->zone
? GetAreaEntryByAreaID(areaEntry
->zone
) : areaEntry
;
2339 Map
const *map
= MapManager::Instance().GetBaseMap(zoneEntry
->mapid
);
2341 if(map
->Instanceable())
2343 PSendSysMessage(LANG_INVALID_ZONE_MAP
,areaEntry
->ID
,areaEntry
->area_name
[m_session
->GetSessionDbcLocale()],map
->GetId(),map
->GetMapName());
2344 SetSentErrorMessage(true);
2348 Zone2MapCoordinates(x
,y
,zoneEntry
->ID
);
2350 if(!MapManager::IsValidMapCoord(zoneEntry
->mapid
,x
,y
))
2352 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,zoneEntry
->mapid
);
2353 SetSentErrorMessage(true);
2357 // stop flight if need
2358 if(_player
->isInFlight())
2360 _player
->GetMotionMaster()->MovementExpired();
2361 _player
->m_taxi
.ClearTaxiDestinations();
2363 // save only in non-flight case
2365 _player
->SaveRecallPosition();
2367 float z
= std::max(map
->GetHeight(x
, y
, MAX_HEIGHT
), map
->GetWaterLevel(x
, y
));
2368 _player
->TeleportTo(zoneEntry
->mapid
, x
, y
, z
, _player
->GetOrientation());
2374 bool ChatHandler::HandleGoGridCommand(const char* args
)
2376 if(!*args
) return false;
2377 Player
* _player
= m_session
->GetPlayer();
2379 char* px
= strtok((char*)args
, " ");
2380 char* py
= strtok(NULL
, " ");
2381 char* pmapid
= strtok(NULL
, " ");
2386 float grid_x
= (float)atof(px
);
2387 float grid_y
= (float)atof(py
);
2390 mapid
= (uint32
)atoi(pmapid
);
2391 else mapid
= _player
->GetMapId();
2394 float x
= (grid_x
-CENTER_GRID_ID
+0.5f
)*SIZE_OF_GRIDS
;
2395 float y
= (grid_y
-CENTER_GRID_ID
+0.5f
)*SIZE_OF_GRIDS
;
2397 if(!MapManager::IsValidMapCoord(mapid
,x
,y
))
2399 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,mapid
);
2400 SetSentErrorMessage(true);
2404 // stop flight if need
2405 if(_player
->isInFlight())
2407 _player
->GetMotionMaster()->MovementExpired();
2408 _player
->m_taxi
.ClearTaxiDestinations();
2410 // save only in non-flight case
2412 _player
->SaveRecallPosition();
2414 Map
const *map
= MapManager::Instance().GetBaseMap(mapid
);
2415 float z
= std::max(map
->GetHeight(x
, y
, MAX_HEIGHT
), map
->GetWaterLevel(x
, y
));
2416 _player
->TeleportTo(mapid
, x
, y
, z
, _player
->GetOrientation());
2421 bool ChatHandler::HandleDrunkCommand(const char* args
)
2423 if(!*args
) return false;
2425 uint32 drunklevel
= (uint32
)atoi(args
);
2426 if(drunklevel
> 100)
2429 uint16 drunkMod
= drunklevel
* 0xFFFF / 100;
2431 m_session
->GetPlayer()->SetDrunkValue(drunkMod
);