allow .goname and .namego in more battleground cases
[getmangos.git] / src / game / Level1.cpp
blob76c4b871d9966799426b93dc444ec85f9ac95750
1 /*
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
19 #include "Common.h"
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
23 #include "World.h"
24 #include "ObjectMgr.h"
25 #include "Player.h"
26 #include "Opcodes.h"
27 #include "Chat.h"
28 #include "Log.h"
29 #include "MapManager.h"
30 #include "ObjectAccessor.h"
31 #include "Language.h"
32 #include "CellImpl.h"
33 #include "InstanceSaveMgr.h"
34 #include "Util.h"
35 #ifdef _DEBUG_VMAPS
36 #include "VMapFactory.h"
37 #endif
39 bool ChatHandler::HandleNpcSayCommand(const char* args)
41 if(!*args)
42 return false;
44 Creature* pCreature = getSelectedCreature();
45 if(!pCreature)
47 SendSysMessage(LANG_SELECT_CREATURE);
48 SetSentErrorMessage(true);
49 return false;
52 pCreature->Say(args, LANG_UNIVERSAL, 0);
54 return true;
57 bool ChatHandler::HandleNpcYellCommand(const char* args)
59 if(!*args)
60 return false;
62 Creature* pCreature = getSelectedCreature();
63 if(!pCreature)
65 SendSysMessage(LANG_SELECT_CREATURE);
66 SetSentErrorMessage(true);
67 return false;
70 pCreature->Yell(args, LANG_UNIVERSAL, 0);
72 return true;
75 //show text emote by creature in chat
76 bool ChatHandler::HandleNpcTextEmoteCommand(const char* args)
78 if(!*args)
79 return false;
81 Creature* pCreature = getSelectedCreature();
83 if(!pCreature)
85 SendSysMessage(LANG_SELECT_CREATURE);
86 SetSentErrorMessage(true);
87 return false;
90 pCreature->TextEmote(args, 0);
92 return true;
95 // make npc whisper to player
96 bool ChatHandler::HandleNpcWhisperCommand(const char* args)
98 if(!*args)
99 return false;
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)
109 return false;
112 uint64 receiver_guid= atol(receiver_str);
114 // check online security
115 if (HasLowerSecurity(objmgr.GetPlayer(receiver_guid), 0))
116 return false;
118 pCreature->Whisper(text,receiver_guid);
120 return true;
123 // global announce
124 bool ChatHandler::HandleAnnounceCommand(const char* args)
126 if(!*args)
127 return false;
129 sWorld.SendWorldText(LANG_SYSTEMMESSAGE,args);
130 return true;
133 //notification player at the screen
134 bool ChatHandler::HandleNotifyCommand(const char* args)
136 if(!*args)
137 return false;
139 std::string str = GetMangosString(LANG_GLOBAL_NOTIFY);
140 str += args;
142 WorldPacket data(SMSG_NOTIFICATION, (str.size()+1));
143 data << str;
144 sWorld.SendGlobalMessage(&data);
146 return true;
149 //Enable\Dissable GM Mode
150 bool ChatHandler::HandleGMmodeCommand(const char* args)
152 if(!*args)
154 if(m_session->GetPlayer()->isGameMaster())
155 m_session->SendNotification(LANG_GM_ON);
156 else
157 m_session->SendNotification(LANG_GM_OFF);
158 return true;
161 std::string argstr = (char*)args;
163 if (argstr == "on")
165 m_session->GetPlayer()->SetGameMaster(true);
166 m_session->SendNotification(LANG_GM_ON);
167 #ifdef _DEBUG_VMAPS
168 VMAP::IVMapManager *vMapManager = VMAP::VMapFactory::createOrGetVMapManager();
169 vMapManager->processCommand("stoplog");
170 #endif
171 return true;
174 if (argstr == "off")
176 m_session->GetPlayer()->SetGameMaster(false);
177 m_session->SendNotification(LANG_GM_OFF);
178 #ifdef _DEBUG_VMAPS
179 VMAP::IVMapManager *vMapManager = VMAP::VMapFactory::createOrGetVMapManager();
180 vMapManager->processCommand("startlog");
181 #endif
182 return true;
185 SendSysMessage(LANG_USE_BOL);
186 SetSentErrorMessage(true);
187 return false;
190 // Enables or disables hiding of the staff badge
191 bool ChatHandler::HandleGMChatCommand(const char* args)
193 if(!*args)
195 if(m_session->GetPlayer()->isGMChat())
196 m_session->SendNotification(LANG_GM_CHAT_ON);
197 else
198 m_session->SendNotification(LANG_GM_CHAT_OFF);
199 return true;
202 std::string argstr = (char*)args;
204 if (argstr == "on")
206 m_session->GetPlayer()->SetGMChat(true);
207 m_session->SendNotification(LANG_GM_CHAT_ON);
208 return true;
211 if (argstr == "off")
213 m_session->GetPlayer()->SetGMChat(false);
214 m_session->SendNotification(LANG_GM_CHAT_OFF);
215 return true;
218 SendSysMessage(LANG_USE_BOL);
219 SetSentErrorMessage(true);
220 return false;
223 //Enable\Dissable Invisible mode
224 bool ChatHandler::HandleVisibleCommand(const char* args)
226 if (!*args)
228 PSendSysMessage(LANG_YOU_ARE, m_session->GetPlayer()->isGMVisible() ? GetMangosString(LANG_VISIBLE) : GetMangosString(LANG_INVISIBLE));
229 return true;
232 std::string argstr = (char*)args;
234 if (argstr == "on")
236 m_session->GetPlayer()->SetGMVisible(true);
237 m_session->SendNotification(LANG_INVISIBLE_VISIBLE);
238 return true;
241 if (argstr == "off")
243 m_session->SendNotification(LANG_INVISIBLE_INVISIBLE);
244 m_session->GetPlayer()->SetGMVisible(false);
245 return true;
248 SendSysMessage(LANG_USE_BOL);
249 SetSentErrorMessage(true);
250 return false;
255 bool ChatHandler::HandleGPSCommand(const char* args)
257 WorldObject *obj = NULL;
258 if (*args)
260 uint64 guid = extractGuidFromLink((char*)args);
261 if(guid)
262 obj = (WorldObject*)ObjectAccessor::GetObjectByTypeMask(*m_session->GetPlayer(),guid,TYPEMASK_UNIT|TYPEMASK_GAMEOBJECT);
264 if(!obj)
266 SendSysMessage(LANG_PLAYER_NOT_FOUND);
267 SetSentErrorMessage(true);
268 return false;
271 else
273 obj = getSelectedUnit();
275 if(!obj)
277 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
278 SetSentErrorMessage(true);
279 return false;
282 CellPair cell_val = MaNGOS::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY());
283 Cell cell(cell_val);
285 uint32 zone_id = obj->GetZoneId();
286 uint32 area_id = obj->GetAreaId();
288 MapEntry const* mapEntry = sMapStore.LookupEntry(obj->GetMapId());
289 AreaTableEntry const* zoneEntry = GetAreaEntryByAreaID(zone_id);
290 AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(area_id);
292 float zone_x = obj->GetPositionX();
293 float zone_y = obj->GetPositionY();
295 Map2ZoneCoordinates(zone_x,zone_y,zone_id);
297 Map const *map = obj->GetMap();
298 float ground_z = map->GetHeight(obj->GetPositionX(), obj->GetPositionY(), MAX_HEIGHT);
299 float floor_z = map->GetHeight(obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ());
301 GridPair p = MaNGOS::ComputeGridPair(obj->GetPositionX(), obj->GetPositionY());
303 int gx=63-p.x_coord;
304 int gy=63-p.y_coord;
306 uint32 have_map = Map::ExistMap(obj->GetMapId(),gx,gy) ? 1 : 0;
307 uint32 have_vmap = Map::ExistVMap(obj->GetMapId(),gx,gy) ? 1 : 0;
309 PSendSysMessage(LANG_MAP_POSITION,
310 obj->GetMapId(), (mapEntry ? mapEntry->name[m_session->GetSessionDbcLocale()] : "<unknown>" ),
311 zone_id, (zoneEntry ? zoneEntry->area_name[m_session->GetSessionDbcLocale()] : "<unknown>" ),
312 area_id, (areaEntry ? areaEntry->area_name[m_session->GetSessionDbcLocale()] : "<unknown>" ),
313 obj->GetPhaseMask(),
314 obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ(), obj->GetOrientation(),
315 cell.GridX(), cell.GridY(), cell.CellX(), cell.CellY(), obj->GetInstanceId(),
316 zone_x, zone_y, ground_z, floor_z, have_map, have_vmap );
318 sLog.outDebug("Player %s GPS call for %s '%s' (%s: %u):",
319 m_session ? GetNameLink().c_str() : GetMangosString(LANG_CONSOLE_COMMAND),
320 (obj->GetTypeId() == TYPEID_PLAYER ? "player" : "creature"), obj->GetName(),
321 (obj->GetTypeId() == TYPEID_PLAYER ? "GUID" : "Entry"), (obj->GetTypeId() == TYPEID_PLAYER ? obj->GetGUIDLow(): obj->GetEntry()) );
323 sLog.outDebug(GetMangosString(LANG_MAP_POSITION),
324 obj->GetMapId(), (mapEntry ? mapEntry->name[sWorld.GetDefaultDbcLocale()] : "<unknown>" ),
325 zone_id, (zoneEntry ? zoneEntry->area_name[sWorld.GetDefaultDbcLocale()] : "<unknown>" ),
326 area_id, (areaEntry ? areaEntry->area_name[sWorld.GetDefaultDbcLocale()] : "<unknown>" ),
327 obj->GetPhaseMask(),
328 obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ(), obj->GetOrientation(),
329 cell.GridX(), cell.GridY(), cell.CellX(), cell.CellY(), obj->GetInstanceId(),
330 zone_x, zone_y, ground_z, floor_z, have_map, have_vmap );
332 return true;
335 //Summon Player
336 bool ChatHandler::HandleNamegoCommand(const char* args)
338 if(!*args)
339 return false;
341 std::string name = extractPlayerNameFromLink((char*)args);
342 if(name.empty())
344 SendSysMessage(LANG_PLAYER_NOT_FOUND);
345 SetSentErrorMessage(true);
346 return false;
349 Player *chr = objmgr.GetPlayer(name.c_str());
350 if (chr)
352 std::string nameLink = playerLink(name);
353 // check online security
354 if (HasLowerSecurity(chr, 0))
355 return false;
357 if(chr->IsBeingTeleported()==true)
359 PSendSysMessage(LANG_IS_TELEPORTED, nameLink.c_str());
360 SetSentErrorMessage(true);
361 return false;
364 Map* pMap = m_session->GetPlayer()->GetMap();
366 if(pMap->IsBattleGroundOrArena())
368 // only allow if gm mode is on
369 if (!chr->isGameMaster())
371 PSendSysMessage(LANG_CANNOT_GO_TO_BG_GM,chr->GetName());
372 SetSentErrorMessage(true);
373 return false;
375 // if both players are in different bgs
376 else if (chr->GetBattleGroundId() && m_session->GetPlayer()->GetBattleGroundId() != chr->GetBattleGroundId())
378 PSendSysMessage(LANG_CANNOT_GO_TO_BG_FROM_BG,chr->GetName());
379 SetSentErrorMessage(true);
380 return false;
382 // all's well, set bg id
383 // when porting out from the bg, it will be reset to 0
384 chr->SetBattleGroundId(m_session->GetPlayer()->GetBattleGroundId());
386 else if(pMap->IsDungeon())
388 Map* cMap = chr->GetMap();
389 if( cMap->Instanceable() && cMap->GetInstanceId() != pMap->GetInstanceId() )
391 // cannot summon from instance to instance
392 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,nameLink.c_str());
393 SetSentErrorMessage(true);
394 return false;
397 // we are in instance, and can summon only player in our group with us as lead
398 if ( !m_session->GetPlayer()->GetGroup() || !chr->GetGroup() ||
399 (chr->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ||
400 (m_session->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) )
401 // the last check is a bit excessive, but let it be, just in case
403 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,nameLink.c_str());
404 SetSentErrorMessage(true);
405 return false;
409 PSendSysMessage(LANG_SUMMONING, nameLink.c_str(),"");
410 if (needReportToTarget(chr))
411 ChatHandler(chr).PSendSysMessage(LANG_SUMMONED_BY, nameLink.c_str());
413 // stop flight if need
414 if(chr->isInFlight())
416 chr->GetMotionMaster()->MovementExpired();
417 chr->m_taxi.ClearTaxiDestinations();
419 // save only in non-flight case
420 else
421 chr->SaveRecallPosition();
423 // before GM
424 float x,y,z;
425 m_session->GetPlayer()->GetClosePoint(x,y,z,chr->GetObjectSize());
426 chr->TeleportTo(m_session->GetPlayer()->GetMapId(),x,y,z,chr->GetOrientation());
428 else if (uint64 guid = objmgr.GetPlayerGUIDByName(name))
430 // check offline security
431 if (HasLowerSecurity(NULL, guid))
432 return false;
434 std::string nameLink = playerLink(name);
436 PSendSysMessage(LANG_SUMMONING, nameLink.c_str(),GetMangosString(LANG_OFFLINE));
438 // in point where GM stay
439 Player::SavePositionInDB(m_session->GetPlayer()->GetMapId(),
440 m_session->GetPlayer()->GetPositionX(),
441 m_session->GetPlayer()->GetPositionY(),
442 m_session->GetPlayer()->GetPositionZ(),
443 m_session->GetPlayer()->GetOrientation(),
444 m_session->GetPlayer()->GetZoneId(),
445 guid);
447 else
449 PSendSysMessage(LANG_NO_PLAYER, args);
450 SetSentErrorMessage(true);
453 return true;
456 //Teleport to Player
457 bool ChatHandler::HandleGonameCommand(const char* args)
459 if(!*args)
460 return false;
462 Player* _player = m_session->GetPlayer();
464 std::string name = extractPlayerNameFromLink((char*)args);
465 if(name.empty())
467 SendSysMessage(LANG_PLAYER_NOT_FOUND);
468 SetSentErrorMessage(true);
469 return false;
472 Player *chr = objmgr.GetPlayer(name.c_str());
473 if (chr)
475 // check online security
476 if (HasLowerSecurity(chr, 0))
477 return false;
479 std::string chrNameLink = playerLink(name);
481 Map* cMap = chr->GetMap();
482 if(cMap->IsBattleGroundOrArena())
484 // only allow if gm mode is on
485 if (!_player->isGameMaster())
487 PSendSysMessage(LANG_CANNOT_GO_TO_BG_GM,chrNameLink.c_str());
488 SetSentErrorMessage(true);
489 return false;
491 // if both players are in different bgs
492 else if (_player->GetBattleGroundId() && _player->GetBattleGroundId() != chr->GetBattleGroundId())
494 PSendSysMessage(LANG_CANNOT_GO_TO_BG_FROM_BG,chrNameLink.c_str());
495 SetSentErrorMessage(true);
496 return false;
498 // all's well, set bg id
499 // when porting out from the bg, it will be reset to 0
500 _player->SetBattleGroundId(chr->GetBattleGroundId());
502 else if(cMap->IsDungeon() && cMap->Instanceable())
504 // we have to go to instance, and can go to player only if:
505 // 1) we are in his group (either as leader or as member)
506 // 2) we are not bound to any group and have GM mode on
507 if (_player->GetGroup())
509 // we are in group, we can go only if we are in the player group
510 if (_player->GetGroup() != chr->GetGroup())
512 PSendSysMessage(LANG_CANNOT_GO_TO_INST_PARTY,chrNameLink.c_str());
513 SetSentErrorMessage(true);
514 return false;
517 else
519 // we are not in group, let's verify our GM mode
520 if (!_player->isGameMaster())
522 PSendSysMessage(LANG_CANNOT_GO_TO_INST_GM,chrNameLink.c_str());
523 SetSentErrorMessage(true);
524 return false;
528 // if the player or the player's group is bound to another instance
529 // the player will not be bound to another one
530 InstancePlayerBind *pBind = _player->GetBoundInstance(chr->GetMapId(), chr->GetDifficulty());
531 if(!pBind)
533 Group *group = _player->GetGroup();
534 InstanceGroupBind *gBind = group ? group->GetBoundInstance(chr->GetMapId(), chr->GetDifficulty()) : NULL;
535 if(!gBind)
537 // if no bind exists, create a solo bind
538 InstanceSave *save = sInstanceSaveManager.GetInstanceSave(chr->GetInstanceId());
539 if(save) _player->BindToInstance(save, !save->CanReset());
543 _player->SetDifficulty(chr->GetDifficulty());
546 PSendSysMessage(LANG_APPEARING_AT, chrNameLink.c_str());
547 if (_player->IsVisibleGloballyFor(chr))
548 ChatHandler(chr).PSendSysMessage(LANG_APPEARING_TO, GetNameLink().c_str());
550 // stop flight if need
551 if(_player->isInFlight())
553 _player->GetMotionMaster()->MovementExpired();
554 _player->m_taxi.ClearTaxiDestinations();
556 // save only in non-flight case
557 else
558 _player->SaveRecallPosition();
560 // to point to see at target with same orientation
561 float x,y,z;
562 chr->GetContactPoint(m_session->GetPlayer(),x,y,z);
564 _player->TeleportTo(chr->GetMapId(), x, y, z, _player->GetAngle( chr ), TELE_TO_GM_MODE);
566 return true;
569 if (uint64 guid = objmgr.GetPlayerGUIDByName(name))
571 // check offline security
572 if (HasLowerSecurity(NULL, guid))
573 return false;
575 std::string nameLink = playerLink(name);
577 PSendSysMessage(LANG_APPEARING_AT, nameLink.c_str());
579 // to point where player stay (if loaded)
580 float x,y,z,o;
581 uint32 map;
582 bool in_flight;
583 if(Player::LoadPositionFromDB(map,x,y,z,o,in_flight,guid))
585 // stop flight if need
586 if(_player->isInFlight())
588 _player->GetMotionMaster()->MovementExpired();
589 _player->m_taxi.ClearTaxiDestinations();
591 // save only in non-flight case
592 else
593 _player->SaveRecallPosition();
595 _player->TeleportTo(map, x, y, z,_player->GetOrientation());
596 return true;
600 PSendSysMessage(LANG_NO_PLAYER, args);
602 SetSentErrorMessage(true);
603 return false;
606 // Teleport player to last position
607 bool ChatHandler::HandleRecallCommand(const char* args)
609 Player* chr = NULL;
611 if(!*args)
613 chr = getSelectedPlayer();
614 if(!chr)
615 chr = m_session->GetPlayer();
617 // check online security
618 else if (HasLowerSecurity(chr, 0))
619 return false;
621 else
623 std::string name = extractPlayerNameFromLink((char*)args);
624 if(name.empty())
626 SendSysMessage(LANG_PLAYER_NOT_FOUND);
627 SetSentErrorMessage(true);
628 return false;
631 chr = objmgr.GetPlayer(name.c_str());
633 if(!chr)
635 PSendSysMessage(LANG_NO_PLAYER, args);
636 SetSentErrorMessage(true);
637 return false;
640 // check online security
641 if (HasLowerSecurity(chr, 0))
642 return false;
645 if(chr->IsBeingTeleported())
647 PSendSysMessage(LANG_IS_TELEPORTED, GetNameLink(chr).c_str());
648 SetSentErrorMessage(true);
649 return false;
652 // stop flight if need
653 if(chr->isInFlight())
655 chr->GetMotionMaster()->MovementExpired();
656 chr->m_taxi.ClearTaxiDestinations();
659 chr->TeleportTo(chr->m_recallMap, chr->m_recallX, chr->m_recallY, chr->m_recallZ, chr->m_recallO);
660 return true;
663 //Edit Player KnownTitles
664 bool ChatHandler::HandleModifyKnownTitlesCommand(const char* args)
666 if(!*args)
667 return false;
669 uint64 titles = 0;
671 sscanf((char*)args, I64FMTD, &titles);
673 Player *chr = getSelectedPlayer();
674 if (!chr)
676 SendSysMessage(LANG_NO_CHAR_SELECTED);
677 SetSentErrorMessage(true);
678 return false;
681 // check online security
682 if (HasLowerSecurity(chr, 0))
683 return false;
685 uint64 titles2 = titles;
687 for(int i=1; i < sCharTitlesStore.GetNumRows(); ++i)
688 if(CharTitlesEntry const* tEntry = sCharTitlesStore.LookupEntry(i))
689 titles2 &= ~(uint64(1) << tEntry->bit_index);
691 titles &= ~titles2; // remove not existed titles
693 chr->SetUInt64Value(PLAYER__FIELD_KNOWN_TITLES, titles);
694 SendSysMessage(LANG_DONE);
696 return true;
699 //Edit Player HP
700 bool ChatHandler::HandleModifyHPCommand(const char* args)
702 if(!*args)
703 return false;
705 // char* pHp = strtok((char*)args, " ");
706 // if (!pHp)
707 // return false;
709 // char* pHpMax = strtok(NULL, " ");
710 // if (!pHpMax)
711 // return false;
713 // int32 hpm = atoi(pHpMax);
714 // int32 hp = atoi(pHp);
716 int32 hp = atoi((char*)args);
717 int32 hpm = atoi((char*)args);
719 if (hp <= 0 || hpm <= 0 || hpm < hp)
721 SendSysMessage(LANG_BAD_VALUE);
722 SetSentErrorMessage(true);
723 return false;
726 Player *chr = getSelectedPlayer();
727 if (chr == NULL)
729 SendSysMessage(LANG_NO_CHAR_SELECTED);
730 SetSentErrorMessage(true);
731 return false;
734 // check online security
735 if (HasLowerSecurity(chr, 0))
736 return false;
738 PSendSysMessage(LANG_YOU_CHANGE_HP, GetNameLink(chr).c_str(), hp, hpm);
739 if (needReportToTarget(chr))
740 ChatHandler(chr).PSendSysMessage(LANG_YOURS_HP_CHANGED, GetNameLink().c_str(), hp, hpm);
742 chr->SetMaxHealth( hpm );
743 chr->SetHealth( hp );
745 return true;
748 //Edit Player Mana
749 bool ChatHandler::HandleModifyManaCommand(const char* args)
751 if(!*args)
752 return false;
754 // char* pmana = strtok((char*)args, " ");
755 // if (!pmana)
756 // return false;
758 // char* pmanaMax = strtok(NULL, " ");
759 // if (!pmanaMax)
760 // return false;
762 // int32 manam = atoi(pmanaMax);
763 // int32 mana = atoi(pmana);
764 int32 mana = atoi((char*)args);
765 int32 manam = atoi((char*)args);
767 if (mana <= 0 || manam <= 0 || manam < mana)
769 SendSysMessage(LANG_BAD_VALUE);
770 SetSentErrorMessage(true);
771 return false;
774 Player *chr = getSelectedPlayer();
775 if (chr == NULL)
777 SendSysMessage(LANG_NO_CHAR_SELECTED);
778 SetSentErrorMessage(true);
779 return false;
782 // check online security
783 if (HasLowerSecurity(chr, 0))
784 return false;
786 PSendSysMessage(LANG_YOU_CHANGE_MANA, GetNameLink(chr).c_str(), mana, manam);
787 if (needReportToTarget(chr))
788 ChatHandler(chr).PSendSysMessage(LANG_YOURS_MANA_CHANGED, GetNameLink().c_str(), mana, manam);
790 chr->SetMaxPower(POWER_MANA,manam );
791 chr->SetPower(POWER_MANA, mana );
793 return true;
796 //Edit Player Energy
797 bool ChatHandler::HandleModifyEnergyCommand(const char* args)
799 if(!*args)
800 return false;
802 // char* pmana = strtok((char*)args, " ");
803 // if (!pmana)
804 // return false;
806 // char* pmanaMax = strtok(NULL, " ");
807 // if (!pmanaMax)
808 // return false;
810 // int32 manam = atoi(pmanaMax);
811 // int32 mana = atoi(pmana);
813 int32 energy = atoi((char*)args)*10;
814 int32 energym = atoi((char*)args)*10;
816 if (energy <= 0 || energym <= 0 || energym < energy)
818 SendSysMessage(LANG_BAD_VALUE);
819 SetSentErrorMessage(true);
820 return false;
823 Player *chr = getSelectedPlayer();
824 if (!chr)
826 SendSysMessage(LANG_NO_CHAR_SELECTED);
827 SetSentErrorMessage(true);
828 return false;
831 // check online security
832 if (HasLowerSecurity(chr, 0))
833 return false;
835 PSendSysMessage(LANG_YOU_CHANGE_ENERGY, GetNameLink(chr).c_str(), energy/10, energym/10);
836 if (needReportToTarget(chr))
837 ChatHandler(chr).PSendSysMessage(LANG_YOURS_ENERGY_CHANGED, GetNameLink().c_str(), energy/10, energym/10);
839 chr->SetMaxPower(POWER_ENERGY,energym );
840 chr->SetPower(POWER_ENERGY, energy );
842 sLog.outDetail(GetMangosString(LANG_CURRENT_ENERGY),chr->GetMaxPower(POWER_ENERGY));
844 return true;
847 //Edit Player Rage
848 bool ChatHandler::HandleModifyRageCommand(const char* args)
850 if(!*args)
851 return false;
853 // char* pmana = strtok((char*)args, " ");
854 // if (!pmana)
855 // return false;
857 // char* pmanaMax = strtok(NULL, " ");
858 // if (!pmanaMax)
859 // return false;
861 // int32 manam = atoi(pmanaMax);
862 // int32 mana = atoi(pmana);
864 int32 rage = atoi((char*)args)*10;
865 int32 ragem = atoi((char*)args)*10;
867 if (rage <= 0 || ragem <= 0 || ragem < rage)
869 SendSysMessage(LANG_BAD_VALUE);
870 SetSentErrorMessage(true);
871 return false;
874 Player *chr = getSelectedPlayer();
875 if (chr == NULL)
877 SendSysMessage(LANG_NO_CHAR_SELECTED);
878 SetSentErrorMessage(true);
879 return false;
882 // check online security
883 if (HasLowerSecurity(chr, 0))
884 return false;
886 PSendSysMessage(LANG_YOU_CHANGE_RAGE, GetNameLink(chr).c_str(), rage/10, ragem/10);
887 if (needReportToTarget(chr))
888 ChatHandler(chr).PSendSysMessage(LANG_YOURS_RAGE_CHANGED, GetNameLink().c_str(), rage/10, ragem/10);
890 chr->SetMaxPower(POWER_RAGE,ragem );
891 chr->SetPower(POWER_RAGE, rage );
893 return true;
896 // Edit Player Runic Power
897 bool ChatHandler::HandleModifyRunicPowerCommand(const char* args)
899 if(!*args)
900 return false;
902 int32 rune = atoi((char*)args)*10;
903 int32 runem = atoi((char*)args)*10;
905 if (rune <= 0 || runem <= 0 || runem < rune)
907 SendSysMessage(LANG_BAD_VALUE);
908 SetSentErrorMessage(true);
909 return false;
912 Player *chr = getSelectedPlayer();
913 if (chr == NULL)
915 SendSysMessage(LANG_NO_CHAR_SELECTED);
916 SetSentErrorMessage(true);
917 return false;
920 PSendSysMessage(LANG_YOU_CHANGE_RUNIC_POWER, GetNameLink(chr).c_str(), rune/10, runem/10);
921 if (needReportToTarget(chr))
922 ChatHandler(chr).PSendSysMessage(LANG_YOURS_RUNIC_POWER_CHANGED, GetNameLink().c_str(), rune/10, runem/10);
924 chr->SetMaxPower(POWER_RUNIC_POWER,runem );
925 chr->SetPower(POWER_RUNIC_POWER, rune );
927 return true;
930 //Edit Player Faction
931 bool ChatHandler::HandleModifyFactionCommand(const char* args)
933 if(!*args)
934 return false;
936 char* pfactionid = extractKeyFromLink((char*)args,"Hfaction");
938 Creature* chr = getSelectedCreature();
939 if(!chr)
941 SendSysMessage(LANG_SELECT_CREATURE);
942 SetSentErrorMessage(true);
943 return false;
946 if(!pfactionid)
948 if(chr)
950 uint32 factionid = chr->getFaction();
951 uint32 flag = chr->GetUInt32Value(UNIT_FIELD_FLAGS);
952 uint32 npcflag = chr->GetUInt32Value(UNIT_NPC_FLAGS);
953 uint32 dyflag = chr->GetUInt32Value(UNIT_DYNAMIC_FLAGS);
954 PSendSysMessage(LANG_CURRENT_FACTION,chr->GetGUIDLow(),factionid,flag,npcflag,dyflag);
956 return true;
959 if( !chr )
961 SendSysMessage(LANG_NO_CHAR_SELECTED);
962 SetSentErrorMessage(true);
963 return false;
966 uint32 factionid = atoi(pfactionid);
967 uint32 flag;
969 char *pflag = strtok(NULL, " ");
970 if (!pflag)
971 flag = chr->GetUInt32Value(UNIT_FIELD_FLAGS);
972 else
973 flag = atoi(pflag);
975 char* pnpcflag = strtok(NULL, " ");
977 uint32 npcflag;
978 if(!pnpcflag)
979 npcflag = chr->GetUInt32Value(UNIT_NPC_FLAGS);
980 else
981 npcflag = atoi(pnpcflag);
983 char* pdyflag = strtok(NULL, " ");
985 uint32 dyflag;
986 if(!pdyflag)
987 dyflag = chr->GetUInt32Value(UNIT_DYNAMIC_FLAGS);
988 else
989 dyflag = atoi(pdyflag);
991 if(!sFactionTemplateStore.LookupEntry(factionid))
993 PSendSysMessage(LANG_WRONG_FACTION, factionid);
994 SetSentErrorMessage(true);
995 return false;
998 PSendSysMessage(LANG_YOU_CHANGE_FACTION, chr->GetGUIDLow(),factionid,flag,npcflag,dyflag);
1000 chr->setFaction(factionid);
1001 chr->SetUInt32Value(UNIT_FIELD_FLAGS,flag);
1002 chr->SetUInt32Value(UNIT_NPC_FLAGS,npcflag);
1003 chr->SetUInt32Value(UNIT_DYNAMIC_FLAGS,dyflag);
1005 return true;
1008 //Edit Player Spell
1009 bool ChatHandler::HandleModifySpellCommand(const char* args)
1011 if(!*args) return false;
1012 char* pspellflatid = strtok((char*)args, " ");
1013 if (!pspellflatid)
1014 return false;
1016 char* pop = strtok(NULL, " ");
1017 if (!pop)
1018 return false;
1020 char* pval = strtok(NULL, " ");
1021 if (!pval)
1022 return false;
1024 uint16 mark;
1026 char* pmark = strtok(NULL, " ");
1028 uint8 spellflatid = atoi(pspellflatid);
1029 uint8 op = atoi(pop);
1030 uint16 val = atoi(pval);
1031 if(!pmark)
1032 mark = 65535;
1033 else
1034 mark = atoi(pmark);
1036 Player *chr = getSelectedPlayer();
1037 if (chr == NULL)
1039 SendSysMessage(LANG_NO_CHAR_SELECTED);
1040 SetSentErrorMessage(true);
1041 return false;
1044 // check online security
1045 if (HasLowerSecurity(chr, 0))
1046 return false;
1048 PSendSysMessage(LANG_YOU_CHANGE_SPELLFLATID, spellflatid, val, mark, GetNameLink(chr).c_str());
1049 if (needReportToTarget(chr))
1050 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SPELLFLATID_CHANGED, GetNameLink().c_str(), spellflatid, val, mark);
1052 WorldPacket data(SMSG_SET_FLAT_SPELL_MODIFIER, (1+1+2+2));
1053 data << uint8(spellflatid);
1054 data << uint8(op);
1055 data << uint16(val);
1056 data << uint16(mark);
1057 chr->GetSession()->SendPacket(&data);
1059 return true;
1062 //Edit Player TP
1063 bool ChatHandler::HandleModifyTalentCommand (const char* args)
1065 if (!*args)
1066 return false;
1068 int tp = atoi((char*)args);
1069 if (tp>0)
1071 Player* player = getSelectedPlayer();
1072 if(!player)
1074 SendSysMessage(LANG_NO_CHAR_SELECTED);
1075 SetSentErrorMessage(true);
1076 return false;
1079 // check online security
1080 if (HasLowerSecurity(player, 0))
1081 return false;
1083 player->SetFreeTalentPoints(tp);
1084 return true;
1086 return false;
1089 //Enable On\OFF all taxi paths
1090 bool ChatHandler::HandleTaxiCheatCommand(const char* args)
1092 if (!*args)
1094 SendSysMessage(LANG_USE_BOL);
1095 SetSentErrorMessage(true);
1096 return false;
1099 std::string argstr = (char*)args;
1101 Player *chr = getSelectedPlayer();
1102 if (!chr)
1104 chr=m_session->GetPlayer();
1107 // check online security
1108 else if (HasLowerSecurity(chr, 0))
1109 return false;
1111 if (argstr == "on")
1113 chr->SetTaxiCheater(true);
1114 PSendSysMessage(LANG_YOU_GIVE_TAXIS, GetNameLink(chr).c_str());
1115 if (needReportToTarget(chr))
1116 ChatHandler(chr).PSendSysMessage(LANG_YOURS_TAXIS_ADDED, GetNameLink().c_str());
1117 return true;
1120 if (argstr == "off")
1122 chr->SetTaxiCheater(false);
1123 PSendSysMessage(LANG_YOU_REMOVE_TAXIS, GetNameLink(chr).c_str());
1124 if (needReportToTarget(chr))
1125 ChatHandler(chr).PSendSysMessage(LANG_YOURS_TAXIS_REMOVED, GetNameLink().c_str());
1127 return true;
1130 SendSysMessage(LANG_USE_BOL);
1131 SetSentErrorMessage(true);
1132 return false;
1135 //Edit Player Aspeed
1136 bool ChatHandler::HandleModifyASpeedCommand(const char* args)
1138 if (!*args)
1139 return false;
1141 float ASpeed = (float)atof((char*)args);
1143 if (ASpeed > 10 || ASpeed < 0.1)
1145 SendSysMessage(LANG_BAD_VALUE);
1146 SetSentErrorMessage(true);
1147 return false;
1150 Player *chr = getSelectedPlayer();
1151 if (chr == NULL)
1153 SendSysMessage(LANG_NO_CHAR_SELECTED);
1154 SetSentErrorMessage(true);
1155 return false;
1158 // check online security
1159 if (HasLowerSecurity(chr, 0))
1160 return false;
1162 std::string chrNameLink = GetNameLink(chr);
1164 if(chr->isInFlight())
1166 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chrNameLink.c_str());
1167 SetSentErrorMessage(true);
1168 return false;
1171 PSendSysMessage(LANG_YOU_CHANGE_ASPEED, ASpeed, chrNameLink.c_str());
1172 if (needReportToTarget(chr))
1173 ChatHandler(chr).PSendSysMessage(LANG_YOURS_ASPEED_CHANGED, GetNameLink().c_str(), ASpeed);
1175 chr->SetSpeed(MOVE_WALK, ASpeed,true);
1176 chr->SetSpeed(MOVE_RUN, ASpeed,true);
1177 chr->SetSpeed(MOVE_SWIM, ASpeed,true);
1178 //chr->SetSpeed(MOVE_TURN, ASpeed,true);
1179 chr->SetSpeed(MOVE_FLIGHT, ASpeed,true);
1180 return true;
1183 //Edit Player Speed
1184 bool ChatHandler::HandleModifySpeedCommand(const char* args)
1186 if (!*args)
1187 return false;
1189 float Speed = (float)atof((char*)args);
1191 if (Speed > 10 || Speed < 0.1)
1193 SendSysMessage(LANG_BAD_VALUE);
1194 SetSentErrorMessage(true);
1195 return false;
1198 Player *chr = getSelectedPlayer();
1199 if (chr == NULL)
1201 SendSysMessage(LANG_NO_CHAR_SELECTED);
1202 SetSentErrorMessage(true);
1203 return false;
1206 // check online security
1207 if (HasLowerSecurity(chr, 0))
1208 return false;
1210 std::string chrNameLink = GetNameLink(chr);
1212 if(chr->isInFlight())
1214 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chrNameLink.c_str());
1215 SetSentErrorMessage(true);
1216 return false;
1219 PSendSysMessage(LANG_YOU_CHANGE_SPEED, Speed, chrNameLink.c_str());
1220 if (needReportToTarget(chr))
1221 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SPEED_CHANGED, GetNameLink().c_str(), Speed);
1223 chr->SetSpeed(MOVE_RUN,Speed,true);
1225 return true;
1228 //Edit Player Swim Speed
1229 bool ChatHandler::HandleModifySwimCommand(const char* args)
1231 if (!*args)
1232 return false;
1234 float Swim = (float)atof((char*)args);
1236 if (Swim > 10.0f || Swim < 0.01f)
1238 SendSysMessage(LANG_BAD_VALUE);
1239 SetSentErrorMessage(true);
1240 return false;
1243 Player *chr = getSelectedPlayer();
1244 if (chr == NULL)
1246 SendSysMessage(LANG_NO_CHAR_SELECTED);
1247 SetSentErrorMessage(true);
1248 return false;
1251 // check online security
1252 if (HasLowerSecurity(chr, 0))
1253 return false;
1255 std::string chrNameLink = GetNameLink(chr);
1257 if(chr->isInFlight())
1259 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chrNameLink.c_str());
1260 SetSentErrorMessage(true);
1261 return false;
1264 PSendSysMessage(LANG_YOU_CHANGE_SWIM_SPEED, Swim, chrNameLink.c_str());
1265 if (needReportToTarget(chr))
1266 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SWIM_SPEED_CHANGED, GetNameLink().c_str(), Swim);
1268 chr->SetSpeed(MOVE_SWIM,Swim,true);
1270 return true;
1273 //Edit Player Walk Speed
1274 bool ChatHandler::HandleModifyBWalkCommand(const char* args)
1276 if (!*args)
1277 return false;
1279 float BSpeed = (float)atof((char*)args);
1281 if (BSpeed > 10.0f || BSpeed < 0.1f)
1283 SendSysMessage(LANG_BAD_VALUE);
1284 SetSentErrorMessage(true);
1285 return false;
1288 Player *chr = getSelectedPlayer();
1289 if (chr == NULL)
1291 SendSysMessage(LANG_NO_CHAR_SELECTED);
1292 SetSentErrorMessage(true);
1293 return false;
1296 // check online security
1297 if (HasLowerSecurity(chr, 0))
1298 return false;
1300 std::string chrNameLink = GetNameLink(chr);
1302 if(chr->isInFlight())
1304 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chrNameLink.c_str());
1305 SetSentErrorMessage(true);
1306 return false;
1309 PSendSysMessage(LANG_YOU_CHANGE_BACK_SPEED, BSpeed, chrNameLink.c_str());
1310 if (needReportToTarget(chr))
1311 ChatHandler(chr).PSendSysMessage(LANG_YOURS_BACK_SPEED_CHANGED, GetNameLink().c_str(), BSpeed);
1313 chr->SetSpeed(MOVE_RUN_BACK,BSpeed,true);
1315 return true;
1318 //Edit Player Fly
1319 bool ChatHandler::HandleModifyFlyCommand(const char* args)
1321 if (!*args)
1322 return false;
1324 float FSpeed = (float)atof((char*)args);
1326 if (FSpeed > 10.0f || FSpeed < 0.1f)
1328 SendSysMessage(LANG_BAD_VALUE);
1329 SetSentErrorMessage(true);
1330 return false;
1333 Player *chr = getSelectedPlayer();
1334 if (chr == NULL)
1336 SendSysMessage(LANG_NO_CHAR_SELECTED);
1337 SetSentErrorMessage(true);
1338 return false;
1341 // check online security
1342 if (HasLowerSecurity(chr, 0))
1343 return false;
1345 PSendSysMessage(LANG_YOU_CHANGE_FLY_SPEED, FSpeed, GetNameLink(chr).c_str());
1346 if (needReportToTarget(chr))
1347 ChatHandler(chr).PSendSysMessage(LANG_YOURS_FLY_SPEED_CHANGED, GetNameLink().c_str(), FSpeed);
1349 chr->SetSpeed(MOVE_FLIGHT,FSpeed,true);
1351 return true;
1354 //Edit Player Scale
1355 bool ChatHandler::HandleModifyScaleCommand(const char* args)
1357 if (!*args)
1358 return false;
1360 float Scale = (float)atof((char*)args);
1361 if (Scale > 3.0f || Scale <= 0.0f)
1363 SendSysMessage(LANG_BAD_VALUE);
1364 SetSentErrorMessage(true);
1365 return false;
1368 Player *chr = getSelectedPlayer();
1369 if (chr == NULL)
1371 SendSysMessage(LANG_NO_CHAR_SELECTED);
1372 SetSentErrorMessage(true);
1373 return false;
1376 // check online security
1377 if (HasLowerSecurity(chr, 0))
1378 return false;
1380 PSendSysMessage(LANG_YOU_CHANGE_SIZE, Scale, GetNameLink(chr).c_str());
1381 if (needReportToTarget(chr))
1382 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SIZE_CHANGED, GetNameLink().c_str(), Scale);
1384 chr->SetFloatValue(OBJECT_FIELD_SCALE_X, Scale);
1386 return true;
1389 //Enable Player mount
1390 bool ChatHandler::HandleModifyMountCommand(const char* args)
1392 if(!*args)
1393 return false;
1395 uint16 mId = 1147;
1396 float speed = (float)15;
1397 uint32 num = 0;
1399 num = atoi((char*)args);
1400 switch(num)
1402 case 1:
1403 mId=14340;
1404 break;
1405 case 2:
1406 mId=4806;
1407 break;
1408 case 3:
1409 mId=6471;
1410 break;
1411 case 4:
1412 mId=12345;
1413 break;
1414 case 5:
1415 mId=6472;
1416 break;
1417 case 6:
1418 mId=6473;
1419 break;
1420 case 7:
1421 mId=10670;
1422 break;
1423 case 8:
1424 mId=10719;
1425 break;
1426 case 9:
1427 mId=10671;
1428 break;
1429 case 10:
1430 mId=10672;
1431 break;
1432 case 11:
1433 mId=10720;
1434 break;
1435 case 12:
1436 mId=14349;
1437 break;
1438 case 13:
1439 mId=11641;
1440 break;
1441 case 14:
1442 mId=12244;
1443 break;
1444 case 15:
1445 mId=12242;
1446 break;
1447 case 16:
1448 mId=14578;
1449 break;
1450 case 17:
1451 mId=14579;
1452 break;
1453 case 18:
1454 mId=14349;
1455 break;
1456 case 19:
1457 mId=12245;
1458 break;
1459 case 20:
1460 mId=14335;
1461 break;
1462 case 21:
1463 mId=207;
1464 break;
1465 case 22:
1466 mId=2328;
1467 break;
1468 case 23:
1469 mId=2327;
1470 break;
1471 case 24:
1472 mId=2326;
1473 break;
1474 case 25:
1475 mId=14573;
1476 break;
1477 case 26:
1478 mId=14574;
1479 break;
1480 case 27:
1481 mId=14575;
1482 break;
1483 case 28:
1484 mId=604;
1485 break;
1486 case 29:
1487 mId=1166;
1488 break;
1489 case 30:
1490 mId=2402;
1491 break;
1492 case 31:
1493 mId=2410;
1494 break;
1495 case 32:
1496 mId=2409;
1497 break;
1498 case 33:
1499 mId=2408;
1500 break;
1501 case 34:
1502 mId=2405;
1503 break;
1504 case 35:
1505 mId=14337;
1506 break;
1507 case 36:
1508 mId=6569;
1509 break;
1510 case 37:
1511 mId=10661;
1512 break;
1513 case 38:
1514 mId=10666;
1515 break;
1516 case 39:
1517 mId=9473;
1518 break;
1519 case 40:
1520 mId=9476;
1521 break;
1522 case 41:
1523 mId=9474;
1524 break;
1525 case 42:
1526 mId=14374;
1527 break;
1528 case 43:
1529 mId=14376;
1530 break;
1531 case 44:
1532 mId=14377;
1533 break;
1534 case 45:
1535 mId=2404;
1536 break;
1537 case 46:
1538 mId=2784;
1539 break;
1540 case 47:
1541 mId=2787;
1542 break;
1543 case 48:
1544 mId=2785;
1545 break;
1546 case 49:
1547 mId=2736;
1548 break;
1549 case 50:
1550 mId=2786;
1551 break;
1552 case 51:
1553 mId=14347;
1554 break;
1555 case 52:
1556 mId=14346;
1557 break;
1558 case 53:
1559 mId=14576;
1560 break;
1561 case 54:
1562 mId=9695;
1563 break;
1564 case 55:
1565 mId=9991;
1566 break;
1567 case 56:
1568 mId=6448;
1569 break;
1570 case 57:
1571 mId=6444;
1572 break;
1573 case 58:
1574 mId=6080;
1575 break;
1576 case 59:
1577 mId=6447;
1578 break;
1579 case 60:
1580 mId=4805;
1581 break;
1582 case 61:
1583 mId=9714;
1584 break;
1585 case 62:
1586 mId=6448;
1587 break;
1588 case 63:
1589 mId=6442;
1590 break;
1591 case 64:
1592 mId=14632;
1593 break;
1594 case 65:
1595 mId=14332;
1596 break;
1597 case 66:
1598 mId=14331;
1599 break;
1600 case 67:
1601 mId=8469;
1602 break;
1603 case 68:
1604 mId=2830;
1605 break;
1606 case 69:
1607 mId=2346;
1608 break;
1609 default:
1610 SendSysMessage(LANG_NO_MOUNT);
1611 SetSentErrorMessage(true);
1612 return false;
1615 Player *chr = getSelectedPlayer();
1616 if (chr == NULL)
1618 SendSysMessage(LANG_NO_CHAR_SELECTED);
1619 SetSentErrorMessage(true);
1620 return false;
1623 // check online security
1624 if (HasLowerSecurity(chr, 0))
1625 return false;
1627 PSendSysMessage(LANG_YOU_GIVE_MOUNT, GetNameLink(chr).c_str());
1628 if (needReportToTarget(chr))
1629 ChatHandler(chr).PSendSysMessage(LANG_MOUNT_GIVED, GetNameLink().c_str());
1631 chr->SetUInt32Value( UNIT_FIELD_FLAGS , 0x001000 );
1632 chr->Mount(mId);
1634 WorldPacket data( SMSG_FORCE_RUN_SPEED_CHANGE, (8+4+1+4) );
1635 data.append(chr->GetPackGUID());
1636 data << (uint32)0;
1637 data << (uint8)0; //new 2.1.0
1638 data << float(speed);
1639 chr->SendMessageToSet( &data, true );
1641 data.Initialize( SMSG_FORCE_SWIM_SPEED_CHANGE, (8+4+4) );
1642 data.append(chr->GetPackGUID());
1643 data << (uint32)0;
1644 data << float(speed);
1645 chr->SendMessageToSet( &data, true );
1647 return true;
1650 //Edit Player money
1651 bool ChatHandler::HandleModifyMoneyCommand(const char* args)
1653 if (!*args)
1654 return false;
1656 Player *chr = getSelectedPlayer();
1657 if (chr == NULL)
1659 SendSysMessage(LANG_NO_CHAR_SELECTED);
1660 SetSentErrorMessage(true);
1661 return false;
1664 // check online security
1665 if (HasLowerSecurity(chr, 0))
1666 return false;
1668 int32 addmoney = atoi((char*)args);
1670 uint32 moneyuser = chr->GetMoney();
1672 if(addmoney < 0)
1674 int32 newmoney = moneyuser + addmoney;
1676 sLog.outDetail(GetMangosString(LANG_CURRENT_MONEY), moneyuser, addmoney, newmoney);
1677 if(newmoney <= 0 )
1679 PSendSysMessage(LANG_YOU_TAKE_ALL_MONEY, GetNameLink(chr).c_str());
1680 if (needReportToTarget(chr))
1681 ChatHandler(chr).PSendSysMessage(LANG_YOURS_ALL_MONEY_GONE, GetNameLink().c_str());
1683 chr->SetMoney(0);
1685 else
1687 PSendSysMessage(LANG_YOU_TAKE_MONEY, abs(addmoney), GetNameLink(chr).c_str());
1688 if (needReportToTarget(chr))
1689 ChatHandler(chr).PSendSysMessage(LANG_YOURS_MONEY_TAKEN, GetNameLink().c_str(), abs(addmoney));
1690 chr->SetMoney( newmoney );
1693 else
1695 PSendSysMessage(LANG_YOU_GIVE_MONEY, addmoney, GetNameLink(chr).c_str());
1696 if (needReportToTarget(chr))
1697 ChatHandler(chr).PSendSysMessage(LANG_YOURS_MONEY_GIVEN, GetNameLink().c_str(), addmoney);
1698 chr->ModifyMoney( addmoney );
1701 sLog.outDetail(GetMangosString(LANG_NEW_MONEY), moneyuser, addmoney, chr->GetMoney() );
1703 return true;
1706 //Edit Unit field
1707 bool ChatHandler::HandleModifyBitCommand(const char* args)
1709 if( !*args )
1710 return false;
1712 Unit *unit = getSelectedUnit();
1713 if (!unit)
1715 SendSysMessage(LANG_NO_CHAR_SELECTED);
1716 SetSentErrorMessage(true);
1717 return false;
1720 // check online security
1721 if (unit->GetTypeId() == TYPEID_PLAYER && HasLowerSecurity((Player *)unit, 0))
1722 return false;
1724 char* pField = strtok((char*)args, " ");
1725 if (!pField)
1726 return false;
1728 char* pBit = strtok(NULL, " ");
1729 if (!pBit)
1730 return false;
1732 uint16 field = atoi(pField);
1733 uint32 bit = atoi(pBit);
1735 if (field < OBJECT_END || field >= unit->GetValuesCount())
1737 SendSysMessage(LANG_BAD_VALUE);
1738 SetSentErrorMessage(true);
1739 return false;
1741 if (bit < 1 || bit > 32)
1743 SendSysMessage(LANG_BAD_VALUE);
1744 SetSentErrorMessage(true);
1745 return false;
1748 if ( unit->HasFlag( field, (1<<(bit-1)) ) )
1750 unit->RemoveFlag( field, (1<<(bit-1)) );
1751 PSendSysMessage(LANG_REMOVE_BIT, bit, field);
1753 else
1755 unit->SetFlag( field, (1<<(bit-1)) );
1756 PSendSysMessage(LANG_SET_BIT, bit, field);
1758 return true;
1761 bool ChatHandler::HandleModifyHonorCommand (const char* args)
1763 if (!*args)
1764 return false;
1766 Player *target = getSelectedPlayer();
1767 if(!target)
1769 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1770 SetSentErrorMessage(true);
1771 return false;
1774 // check online security
1775 if (HasLowerSecurity(target, 0))
1776 return false;
1778 int32 amount = (uint32)atoi(args);
1780 target->ModifyHonorPoints(amount);
1782 PSendSysMessage(LANG_COMMAND_MODIFY_HONOR, GetNameLink(target).c_str(), target->GetHonorPoints());
1784 return true;
1787 bool ChatHandler::HandleTeleCommand(const char * args)
1789 if(!*args)
1790 return false;
1792 Player* _player = m_session->GetPlayer();
1794 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
1795 GameTele const* tele = extractGameTeleFromLink((char*)args);
1797 if (!tele)
1799 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
1800 SetSentErrorMessage(true);
1801 return false;
1804 // stop flight if need
1805 if(_player->isInFlight())
1807 _player->GetMotionMaster()->MovementExpired();
1808 _player->m_taxi.ClearTaxiDestinations();
1810 // save only in non-flight case
1811 else
1812 _player->SaveRecallPosition();
1814 _player->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
1815 return true;
1818 bool ChatHandler::HandleLookupAreaCommand(const char* args)
1820 if (!*args)
1821 return false;
1823 std::string namepart = args;
1824 std::wstring wnamepart;
1826 if (!Utf8toWStr (namepart,wnamepart))
1827 return false;
1829 uint32 counter = 0; // Counter for figure out that we found smth.
1831 // converting string that we try to find to lower case
1832 wstrToLower (wnamepart);
1834 // Search in AreaTable.dbc
1835 for (uint32 areaflag = 0; areaflag < sAreaStore.GetNumRows (); ++areaflag)
1837 AreaTableEntry const *areaEntry = sAreaStore.LookupEntry (areaflag);
1838 if (areaEntry)
1840 int loc = m_session ? m_session->GetSessionDbcLocale () : sWorld.GetDefaultDbcLocale();
1841 std::string name = areaEntry->area_name[loc];
1842 if (name.empty())
1843 continue;
1845 if (!Utf8FitTo (name, wnamepart))
1847 loc = 0;
1848 for(; loc < MAX_LOCALE; ++loc)
1850 if (m_session && loc==m_session->GetSessionDbcLocale ())
1851 continue;
1853 name = areaEntry->area_name[loc];
1854 if (name.empty ())
1855 continue;
1857 if (Utf8FitTo (name, wnamepart))
1858 break;
1862 if (loc < MAX_LOCALE)
1864 // send area in "id - [name]" format
1865 std::ostringstream ss;
1866 if (m_session)
1867 ss << areaEntry->ID << " - |cffffffff|Harea:" << areaEntry->ID << "|h[" << name << " " << localeNames[loc]<< "]|h|r";
1868 else
1869 ss << areaEntry->ID << " - " << name << " " << localeNames[loc];
1871 SendSysMessage (ss.str ().c_str());
1873 ++counter;
1878 if (counter == 0) // if counter == 0 then we found nth
1879 SendSysMessage (LANG_COMMAND_NOAREAFOUND);
1881 return true;
1884 //Find tele in game_tele order by name
1885 bool ChatHandler::HandleLookupTeleCommand(const char * args)
1887 if(!*args)
1889 SendSysMessage(LANG_COMMAND_TELE_PARAMETER);
1890 SetSentErrorMessage(true);
1891 return false;
1894 char const* str = strtok((char*)args, " ");
1895 if(!str)
1896 return false;
1898 std::string namepart = str;
1899 std::wstring wnamepart;
1901 if(!Utf8toWStr(namepart,wnamepart))
1902 return false;
1904 // converting string that we try to find to lower case
1905 wstrToLower( wnamepart );
1907 std::ostringstream reply;
1909 GameTeleMap const & teleMap = objmgr.GetGameTeleMap();
1910 for(GameTeleMap::const_iterator itr = teleMap.begin(); itr != teleMap.end(); ++itr)
1912 GameTele const* tele = &itr->second;
1914 if(tele->wnameLow.find(wnamepart) == std::wstring::npos)
1915 continue;
1917 if (m_session)
1918 reply << " |cffffffff|Htele:" << itr->first << "|h[" << tele->name << "]|h|r\n";
1919 else
1920 reply << " " << itr->first << " " << tele->name << "\n";
1923 if(reply.str().empty())
1924 SendSysMessage(LANG_COMMAND_TELE_NOLOCATION);
1925 else
1926 PSendSysMessage(LANG_COMMAND_TELE_LOCATION,reply.str().c_str());
1928 return true;
1931 //Enable\Dissable accept whispers (for GM)
1932 bool ChatHandler::HandleWhispersCommand(const char* args)
1934 if(!*args)
1936 PSendSysMessage(LANG_COMMAND_WHISPERACCEPTING, m_session->GetPlayer()->isAcceptWhispers() ? GetMangosString(LANG_ON) : GetMangosString(LANG_OFF));
1937 return true;
1940 std::string argstr = (char*)args;
1941 // whisper on
1942 if (argstr == "on")
1944 m_session->GetPlayer()->SetAcceptWhispers(true);
1945 SendSysMessage(LANG_COMMAND_WHISPERON);
1946 return true;
1949 // whisper off
1950 if (argstr == "off")
1952 m_session->GetPlayer()->SetAcceptWhispers(false);
1953 SendSysMessage(LANG_COMMAND_WHISPEROFF);
1954 return true;
1957 SendSysMessage(LANG_USE_BOL);
1958 SetSentErrorMessage(true);
1959 return false;
1962 //Play sound
1963 bool ChatHandler::HandlePlaySoundCommand(const char* args)
1965 // USAGE: .debug playsound #soundid
1966 // #soundid - ID decimal number from SoundEntries.dbc (1st column)
1967 // this file have about 5000 sounds.
1968 // In this realization only caller can hear this sound.
1969 if( *args )
1971 uint32 dwSoundId = atoi((char*)args);
1973 if( !sSoundEntriesStore.LookupEntry(dwSoundId) )
1975 PSendSysMessage(LANG_SOUND_NOT_EXIST, dwSoundId);
1976 SetSentErrorMessage(true);
1977 return false;
1980 WorldPacket data(SMSG_PLAY_OBJECT_SOUND,4+8);
1981 data << uint32(dwSoundId) << m_session->GetPlayer()->GetGUID();
1982 m_session->SendPacket(&data);
1984 PSendSysMessage(LANG_YOU_HEAR_SOUND, dwSoundId);
1985 return true;
1988 return false;
1991 //Save all players in the world
1992 bool ChatHandler::HandleSaveAllCommand(const char* /*args*/)
1994 ObjectAccessor::Instance().SaveAllPlayers();
1995 SendSysMessage(LANG_PLAYERS_SAVED);
1996 return true;
1999 //Send mail by command
2000 bool ChatHandler::HandleSendMailCommand(const char* args)
2002 if(!*args)
2003 return false;
2005 // format: name "subject text" "mail text"
2007 std::string name = extractPlayerNameFromLink((char*)args);
2008 if(name.empty())
2010 SendSysMessage(LANG_PLAYER_NOT_FOUND);
2011 SetSentErrorMessage(true);
2012 return false;
2015 char* tail1 = strtok(NULL, "");
2016 if(!tail1)
2017 return false;
2019 char* msgSubject;
2020 if(*tail1=='"')
2021 msgSubject = strtok(tail1+1, "\"");
2022 else
2024 char* space = strtok(tail1, "\"");
2025 if(!space)
2026 return false;
2027 msgSubject = strtok(NULL, "\"");
2030 if (!msgSubject)
2031 return false;
2033 char* tail2 = strtok(NULL, "");
2034 if(!tail2)
2035 return false;
2037 char* msgText;
2038 if(*tail2=='"')
2039 msgText = strtok(tail2+1, "\"");
2040 else
2042 char* space = strtok(tail2, "\"");
2043 if(!space)
2044 return false;
2045 msgText = strtok(NULL, "\"");
2048 if (!msgText)
2049 return false;
2051 // msgSubject, msgText isn't NUL after prev. check
2052 std::string subject = msgSubject;
2053 std::string text = msgText;
2055 uint64 receiver_guid = objmgr.GetPlayerGUIDByName(name);
2056 if(!receiver_guid)
2058 SendSysMessage(LANG_PLAYER_NOT_FOUND);
2059 SetSentErrorMessage(true);
2060 return false;
2063 // from console show not existed sender
2064 uint32 sender_guidlo = m_session ? m_session->GetPlayer()->GetGUIDLow() : 0;
2066 uint32 messagetype = MAIL_NORMAL;
2067 uint32 stationery = MAIL_STATIONERY_GM;
2068 uint32 itemTextId = !text.empty() ? objmgr.CreateItemText( text ) : 0;
2070 Player *receiver = objmgr.GetPlayer(receiver_guid);
2072 WorldSession::SendMailTo(receiver,messagetype, stationery, sender_guidlo, GUID_LOPART(receiver_guid), subject, itemTextId, NULL, 0, 0, MAIL_CHECK_MASK_NONE);
2074 std::string nameLink = playerLink(name);
2075 PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
2076 return true;
2079 // teleport player to given game_tele.entry
2080 bool ChatHandler::HandleNameTeleCommand(const char * args)
2082 if(!*args)
2083 return false;
2085 std::string name = extractPlayerNameFromLink((char*)args);
2086 if(name.empty())
2088 SendSysMessage(LANG_PLAYER_NOT_FOUND);
2089 SetSentErrorMessage(true);
2090 return false;
2093 char* tail = strtok(NULL, "");
2094 if(!tail)
2095 return false;
2097 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2098 GameTele const* tele = extractGameTeleFromLink(tail);
2099 if(!tele)
2101 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
2102 SetSentErrorMessage(true);
2103 return false;
2106 Player *chr = objmgr.GetPlayer(name.c_str());
2107 if (chr)
2109 // check online security
2110 if (HasLowerSecurity(chr, 0))
2111 return false;
2113 std::string chrNameLink = playerLink(name);
2115 if(chr->IsBeingTeleported()==true)
2117 PSendSysMessage(LANG_IS_TELEPORTED, chrNameLink.c_str());
2118 SetSentErrorMessage(true);
2119 return false;
2122 PSendSysMessage(LANG_TELEPORTING_TO, chrNameLink.c_str(),"", tele->name.c_str());
2123 if (needReportToTarget(chr))
2124 ChatHandler(chr).PSendSysMessage(LANG_TELEPORTED_TO_BY, GetNameLink().c_str());
2126 // stop flight if need
2127 if(chr->isInFlight())
2129 chr->GetMotionMaster()->MovementExpired();
2130 chr->m_taxi.ClearTaxiDestinations();
2132 // save only in non-flight case
2133 else
2134 chr->SaveRecallPosition();
2136 chr->TeleportTo(tele->mapId,tele->position_x,tele->position_y,tele->position_z,tele->orientation);
2138 else if (uint64 guid = objmgr.GetPlayerGUIDByName(name))
2140 // check offline security
2141 if (HasLowerSecurity(NULL, guid))
2142 return false;
2144 std::string nameLink = playerLink(name);
2146 PSendSysMessage(LANG_TELEPORTING_TO, nameLink.c_str(), GetMangosString(LANG_OFFLINE), tele->name.c_str());
2147 Player::SavePositionInDB(tele->mapId,tele->position_x,tele->position_y,tele->position_z,tele->orientation,
2148 MapManager::Instance().GetZoneId(tele->mapId,tele->position_x,tele->position_y,tele->position_z),guid);
2150 else
2151 PSendSysMessage(LANG_NO_PLAYER, name.c_str());
2153 return true;
2156 //Teleport group to given game_tele.entry
2157 bool ChatHandler::HandleGroupTeleCommand(const char * args)
2159 if(!*args)
2160 return false;
2162 Player *player = getSelectedPlayer();
2163 if (!player)
2165 SendSysMessage(LANG_NO_CHAR_SELECTED);
2166 SetSentErrorMessage(true);
2167 return false;
2170 // check online security
2171 if (HasLowerSecurity(player, 0))
2172 return false;
2174 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2175 GameTele const* tele = extractGameTeleFromLink((char*)args);
2176 if(!tele)
2178 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
2179 SetSentErrorMessage(true);
2180 return false;
2183 std::string nameLink = GetNameLink(player);
2185 Group *grp = player->GetGroup();
2186 if(!grp)
2188 PSendSysMessage(LANG_NOT_IN_GROUP,nameLink.c_str());
2189 SetSentErrorMessage(true);
2190 return false;
2193 for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
2195 Player *pl = itr->getSource();
2197 if(!pl || !pl->GetSession() )
2198 continue;
2200 // check online security
2201 if (HasLowerSecurity(pl, 0))
2202 return false;
2204 std::string plNameLink = GetNameLink(pl);
2206 if(pl->IsBeingTeleported())
2208 PSendSysMessage(LANG_IS_TELEPORTED, plNameLink.c_str());
2209 continue;
2212 PSendSysMessage(LANG_TELEPORTING_TO, plNameLink.c_str(),"", tele->name.c_str());
2213 if (needReportToTarget(pl))
2214 ChatHandler(pl).PSendSysMessage(LANG_TELEPORTED_TO_BY, nameLink.c_str());
2216 // stop flight if need
2217 if(pl->isInFlight())
2219 pl->GetMotionMaster()->MovementExpired();
2220 pl->m_taxi.ClearTaxiDestinations();
2222 // save only in non-flight case
2223 else
2224 pl->SaveRecallPosition();
2226 pl->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
2229 return true;
2232 //Summon group of player
2233 bool ChatHandler::HandleGroupgoCommand(const char* args)
2235 if(!*args)
2236 return false;
2238 std::string name = extractPlayerNameFromLink((char*)args);
2239 if(name.empty())
2241 SendSysMessage(LANG_PLAYER_NOT_FOUND);
2242 SetSentErrorMessage(true);
2243 return false;
2246 Player *player = objmgr.GetPlayer(name.c_str());
2247 if (!player)
2249 PSendSysMessage(LANG_NO_PLAYER, args);
2250 SetSentErrorMessage(true);
2251 return false;
2254 // check online security
2255 if (HasLowerSecurity(player, 0))
2256 return false;
2258 Group *grp = player->GetGroup();
2260 std::string nameLink = playerLink(name);
2262 if(!grp)
2264 PSendSysMessage(LANG_NOT_IN_GROUP,nameLink.c_str());
2265 SetSentErrorMessage(true);
2266 return false;
2269 Map* gmMap = m_session->GetPlayer()->GetMap();
2270 bool to_instance = gmMap->Instanceable();
2272 // we are in instance, and can summon only player in our group with us as lead
2273 if ( to_instance && (
2274 !m_session->GetPlayer()->GetGroup() || (grp->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ||
2275 (m_session->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ) )
2276 // the last check is a bit excessive, but let it be, just in case
2278 SendSysMessage(LANG_CANNOT_SUMMON_TO_INST);
2279 SetSentErrorMessage(true);
2280 return false;
2283 for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
2285 Player *pl = itr->getSource();
2287 if(!pl || pl==m_session->GetPlayer() || !pl->GetSession() )
2288 continue;
2290 // check online security
2291 if (HasLowerSecurity(pl, 0))
2292 return false;
2294 std::string plNameLink = playerLink(name);
2296 if(pl->IsBeingTeleported()==true)
2298 PSendSysMessage(LANG_IS_TELEPORTED, plNameLink.c_str());
2299 SetSentErrorMessage(true);
2300 return false;
2303 if (to_instance)
2305 Map* plMap = pl->GetMap();
2307 if ( plMap->Instanceable() && plMap->GetInstanceId() != gmMap->GetInstanceId() )
2309 // cannot summon from instance to instance
2310 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,plNameLink.c_str());
2311 SetSentErrorMessage(true);
2312 return false;
2316 PSendSysMessage(LANG_SUMMONING, plNameLink.c_str(),"");
2317 if (needReportToTarget(pl))
2318 ChatHandler(pl).PSendSysMessage(LANG_SUMMONED_BY, nameLink.c_str());
2320 // stop flight if need
2321 if(pl->isInFlight())
2323 pl->GetMotionMaster()->MovementExpired();
2324 pl->m_taxi.ClearTaxiDestinations();
2326 // save only in non-flight case
2327 else
2328 pl->SaveRecallPosition();
2330 // before GM
2331 float x,y,z;
2332 m_session->GetPlayer()->GetClosePoint(x,y,z,pl->GetObjectSize());
2333 pl->TeleportTo(m_session->GetPlayer()->GetMapId(),x,y,z,pl->GetOrientation());
2336 return true;
2339 //teleport at coordinates
2340 bool ChatHandler::HandleGoXYCommand(const char* args)
2342 if(!*args)
2343 return false;
2345 Player* _player = m_session->GetPlayer();
2347 char* px = strtok((char*)args, " ");
2348 char* py = strtok(NULL, " ");
2349 char* pmapid = strtok(NULL, " ");
2351 if (!px || !py)
2352 return false;
2354 float x = (float)atof(px);
2355 float y = (float)atof(py);
2356 uint32 mapid;
2357 if (pmapid)
2358 mapid = (uint32)atoi(pmapid);
2359 else mapid = _player->GetMapId();
2361 if(!MapManager::IsValidMapCoord(mapid,x,y))
2363 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
2364 SetSentErrorMessage(true);
2365 return false;
2368 // stop flight if need
2369 if(_player->isInFlight())
2371 _player->GetMotionMaster()->MovementExpired();
2372 _player->m_taxi.ClearTaxiDestinations();
2374 // save only in non-flight case
2375 else
2376 _player->SaveRecallPosition();
2378 Map const *map = MapManager::Instance().GetBaseMap(mapid);
2379 float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
2381 _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
2383 return true;
2386 //teleport at coordinates, including Z
2387 bool ChatHandler::HandleGoXYZCommand(const char* args)
2389 if(!*args)
2390 return false;
2392 Player* _player = m_session->GetPlayer();
2394 char* px = strtok((char*)args, " ");
2395 char* py = strtok(NULL, " ");
2396 char* pz = strtok(NULL, " ");
2397 char* pmapid = strtok(NULL, " ");
2399 if (!px || !py || !pz)
2400 return false;
2402 float x = (float)atof(px);
2403 float y = (float)atof(py);
2404 float z = (float)atof(pz);
2405 uint32 mapid;
2406 if (pmapid)
2407 mapid = (uint32)atoi(pmapid);
2408 else
2409 mapid = _player->GetMapId();
2411 if(!MapManager::IsValidMapCoord(mapid,x,y,z))
2413 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
2414 SetSentErrorMessage(true);
2415 return false;
2418 // stop flight if need
2419 if(_player->isInFlight())
2421 _player->GetMotionMaster()->MovementExpired();
2422 _player->m_taxi.ClearTaxiDestinations();
2424 // save only in non-flight case
2425 else
2426 _player->SaveRecallPosition();
2428 _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
2430 return true;
2433 //teleport at coordinates
2434 bool ChatHandler::HandleGoZoneXYCommand(const char* args)
2436 if(!*args)
2437 return false;
2439 Player* _player = m_session->GetPlayer();
2441 char* px = strtok((char*)args, " ");
2442 char* py = strtok(NULL, " ");
2443 char* tail = strtok(NULL,"");
2445 char* cAreaId = extractKeyFromLink(tail,"Harea"); // string or [name] Shift-click form |color|Harea:area_id|h[name]|h|r
2447 if (!px || !py)
2448 return false;
2450 float x = (float)atof(px);
2451 float y = (float)atof(py);
2452 uint32 areaid = cAreaId ? (uint32)atoi(cAreaId) : _player->GetZoneId();
2454 AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(areaid);
2456 if( x<0 || x>100 || y<0 || y>100 || !areaEntry )
2458 PSendSysMessage(LANG_INVALID_ZONE_COORD,x,y,areaid);
2459 SetSentErrorMessage(true);
2460 return false;
2463 // update to parent zone if exist (client map show only zones without parents)
2464 AreaTableEntry const* zoneEntry = areaEntry->zone ? GetAreaEntryByAreaID(areaEntry->zone) : areaEntry;
2466 Map const *map = MapManager::Instance().GetBaseMap(zoneEntry->mapid);
2468 if(map->Instanceable())
2470 PSendSysMessage(LANG_INVALID_ZONE_MAP,areaEntry->ID,areaEntry->area_name[m_session->GetSessionDbcLocale()],map->GetId(),map->GetMapName());
2471 SetSentErrorMessage(true);
2472 return false;
2475 Zone2MapCoordinates(x,y,zoneEntry->ID);
2477 if(!MapManager::IsValidMapCoord(zoneEntry->mapid,x,y))
2479 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,zoneEntry->mapid);
2480 SetSentErrorMessage(true);
2481 return false;
2484 // stop flight if need
2485 if(_player->isInFlight())
2487 _player->GetMotionMaster()->MovementExpired();
2488 _player->m_taxi.ClearTaxiDestinations();
2490 // save only in non-flight case
2491 else
2492 _player->SaveRecallPosition();
2494 float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
2495 _player->TeleportTo(zoneEntry->mapid, x, y, z, _player->GetOrientation());
2497 return true;
2500 //teleport to grid
2501 bool ChatHandler::HandleGoGridCommand(const char* args)
2503 if(!*args) return false;
2504 Player* _player = m_session->GetPlayer();
2506 char* px = strtok((char*)args, " ");
2507 char* py = strtok(NULL, " ");
2508 char* pmapid = strtok(NULL, " ");
2510 if (!px || !py)
2511 return false;
2513 float grid_x = (float)atof(px);
2514 float grid_y = (float)atof(py);
2515 uint32 mapid;
2516 if (pmapid)
2517 mapid = (uint32)atoi(pmapid);
2518 else mapid = _player->GetMapId();
2520 // center of grid
2521 float x = (grid_x-CENTER_GRID_ID+0.5f)*SIZE_OF_GRIDS;
2522 float y = (grid_y-CENTER_GRID_ID+0.5f)*SIZE_OF_GRIDS;
2524 if(!MapManager::IsValidMapCoord(mapid,x,y))
2526 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
2527 SetSentErrorMessage(true);
2528 return false;
2531 // stop flight if need
2532 if(_player->isInFlight())
2534 _player->GetMotionMaster()->MovementExpired();
2535 _player->m_taxi.ClearTaxiDestinations();
2537 // save only in non-flight case
2538 else
2539 _player->SaveRecallPosition();
2541 Map const *map = MapManager::Instance().GetBaseMap(mapid);
2542 float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
2543 _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
2545 return true;
2548 bool ChatHandler::HandleDrunkCommand(const char* args)
2550 if(!*args) return false;
2552 uint32 drunklevel = (uint32)atoi(args);
2553 if(drunklevel > 100)
2554 drunklevel = 100;
2556 uint16 drunkMod = drunklevel * 0xFFFF / 100;
2558 m_session->GetPlayer()->SetDrunkValue(drunkMod);
2560 return true;