[7796] Implement .lookup taxinode and .go taxinode commands.
[getmangos.git] / src / game / Level1.cpp
blob0d7e445103088e8070daea5c0a7d7d155ffc4093
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 //-----------------------Npc Commands-----------------------
40 bool ChatHandler::HandleNpcSayCommand(const char* args)
42 if(!*args)
43 return false;
45 Creature* pCreature = getSelectedCreature();
46 if(!pCreature)
48 SendSysMessage(LANG_SELECT_CREATURE);
49 SetSentErrorMessage(true);
50 return false;
53 pCreature->MonsterSay(args, LANG_UNIVERSAL, 0);
55 return true;
58 bool ChatHandler::HandleNpcYellCommand(const char* args)
60 if(!*args)
61 return false;
63 Creature* pCreature = getSelectedCreature();
64 if(!pCreature)
66 SendSysMessage(LANG_SELECT_CREATURE);
67 SetSentErrorMessage(true);
68 return false;
71 pCreature->MonsterYell(args, LANG_UNIVERSAL, 0);
73 return true;
76 //show text emote by creature in chat
77 bool ChatHandler::HandleNpcTextEmoteCommand(const char* args)
79 if(!*args)
80 return false;
82 Creature* pCreature = getSelectedCreature();
84 if(!pCreature)
86 SendSysMessage(LANG_SELECT_CREATURE);
87 SetSentErrorMessage(true);
88 return false;
91 pCreature->MonsterTextEmote(args, 0);
93 return true;
96 // make npc whisper to player
97 bool ChatHandler::HandleNpcWhisperCommand(const char* args)
99 if(!*args)
100 return false;
102 char* receiver_str = strtok((char*)args, " ");
103 char* text = strtok(NULL, "");
105 uint64 guid = m_session->GetPlayer()->GetSelection();
106 Creature* pCreature = m_session->GetPlayer()->GetMap()->GetCreature(guid);
108 if(!pCreature || !receiver_str || !text)
110 return false;
113 uint64 receiver_guid= atol(receiver_str);
115 // check online security
116 if (HasLowerSecurity(objmgr.GetPlayer(receiver_guid), 0))
117 return false;
119 pCreature->MonsterWhisper(text,receiver_guid);
121 return true;
123 //----------------------------------------------------------
125 // global announce
126 bool ChatHandler::HandleAnnounceCommand(const char* args)
128 if(!*args)
129 return false;
131 sWorld.SendWorldText(LANG_SYSTEMMESSAGE,args);
132 return true;
135 //notification player at the screen
136 bool ChatHandler::HandleNotifyCommand(const char* args)
138 if(!*args)
139 return false;
141 std::string str = GetMangosString(LANG_GLOBAL_NOTIFY);
142 str += args;
144 WorldPacket data(SMSG_NOTIFICATION, (str.size()+1));
145 data << str;
146 sWorld.SendGlobalMessage(&data);
148 return true;
151 //Enable\Dissable GM Mode
152 bool ChatHandler::HandleGMCommand(const char* args)
154 if(!*args)
156 if(m_session->GetPlayer()->isGameMaster())
157 m_session->SendNotification(LANG_GM_ON);
158 else
159 m_session->SendNotification(LANG_GM_OFF);
160 return true;
163 std::string argstr = (char*)args;
165 if (argstr == "on")
167 m_session->GetPlayer()->SetGameMaster(true);
168 m_session->SendNotification(LANG_GM_ON);
169 #ifdef _DEBUG_VMAPS
170 VMAP::IVMapManager *vMapManager = VMAP::VMapFactory::createOrGetVMapManager();
171 vMapManager->processCommand("stoplog");
172 #endif
173 return true;
176 if (argstr == "off")
178 m_session->GetPlayer()->SetGameMaster(false);
179 m_session->SendNotification(LANG_GM_OFF);
180 #ifdef _DEBUG_VMAPS
181 VMAP::IVMapManager *vMapManager = VMAP::VMapFactory::createOrGetVMapManager();
182 vMapManager->processCommand("startlog");
183 #endif
184 return true;
187 SendSysMessage(LANG_USE_BOL);
188 SetSentErrorMessage(true);
189 return false;
192 // Enables or disables hiding of the staff badge
193 bool ChatHandler::HandleGMChatCommand(const char* args)
195 if(!*args)
197 if(m_session->GetPlayer()->isGMChat())
198 m_session->SendNotification(LANG_GM_CHAT_ON);
199 else
200 m_session->SendNotification(LANG_GM_CHAT_OFF);
201 return true;
204 std::string argstr = (char*)args;
206 if (argstr == "on")
208 m_session->GetPlayer()->SetGMChat(true);
209 m_session->SendNotification(LANG_GM_CHAT_ON);
210 return true;
213 if (argstr == "off")
215 m_session->GetPlayer()->SetGMChat(false);
216 m_session->SendNotification(LANG_GM_CHAT_OFF);
217 return true;
220 SendSysMessage(LANG_USE_BOL);
221 SetSentErrorMessage(true);
222 return false;
225 //Enable\Dissable Invisible mode
226 bool ChatHandler::HandleGMVisibleCommand(const char* args)
228 if (!*args)
230 PSendSysMessage(LANG_YOU_ARE, m_session->GetPlayer()->isGMVisible() ? GetMangosString(LANG_VISIBLE) : GetMangosString(LANG_INVISIBLE));
231 return true;
234 std::string argstr = (char*)args;
236 if (argstr == "on")
238 m_session->GetPlayer()->SetGMVisible(true);
239 m_session->SendNotification(LANG_INVISIBLE_VISIBLE);
240 return true;
243 if (argstr == "off")
245 m_session->SendNotification(LANG_INVISIBLE_INVISIBLE);
246 m_session->GetPlayer()->SetGMVisible(false);
247 return true;
250 SendSysMessage(LANG_USE_BOL);
251 SetSentErrorMessage(true);
252 return false;
257 bool ChatHandler::HandleGPSCommand(const char* args)
259 WorldObject *obj = NULL;
260 if (*args)
262 uint64 guid = extractGuidFromLink((char*)args);
263 if(guid)
264 obj = (WorldObject*)ObjectAccessor::GetObjectByTypeMask(*m_session->GetPlayer(),guid,TYPEMASK_UNIT|TYPEMASK_GAMEOBJECT);
266 if(!obj)
268 SendSysMessage(LANG_PLAYER_NOT_FOUND);
269 SetSentErrorMessage(true);
270 return false;
273 else
275 obj = getSelectedUnit();
277 if(!obj)
279 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
280 SetSentErrorMessage(true);
281 return false;
284 CellPair cell_val = MaNGOS::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY());
285 Cell cell(cell_val);
287 uint32 zone_id, area_id;
288 obj->GetZoneAndAreaId(zone_id,area_id);
290 MapEntry const* mapEntry = sMapStore.LookupEntry(obj->GetMapId());
291 AreaTableEntry const* zoneEntry = GetAreaEntryByAreaID(zone_id);
292 AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(area_id);
294 float zone_x = obj->GetPositionX();
295 float zone_y = obj->GetPositionY();
297 Map2ZoneCoordinates(zone_x,zone_y,zone_id);
299 Map const *map = obj->GetMap();
300 float ground_z = map->GetHeight(obj->GetPositionX(), obj->GetPositionY(), MAX_HEIGHT);
301 float floor_z = map->GetHeight(obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ());
303 GridPair p = MaNGOS::ComputeGridPair(obj->GetPositionX(), obj->GetPositionY());
305 int gx=63-p.x_coord;
306 int gy=63-p.y_coord;
308 uint32 have_map = Map::ExistMap(obj->GetMapId(),gx,gy) ? 1 : 0;
309 uint32 have_vmap = Map::ExistVMap(obj->GetMapId(),gx,gy) ? 1 : 0;
311 PSendSysMessage(LANG_MAP_POSITION,
312 obj->GetMapId(), (mapEntry ? mapEntry->name[m_session->GetSessionDbcLocale()] : "<unknown>" ),
313 zone_id, (zoneEntry ? zoneEntry->area_name[m_session->GetSessionDbcLocale()] : "<unknown>" ),
314 area_id, (areaEntry ? areaEntry->area_name[m_session->GetSessionDbcLocale()] : "<unknown>" ),
315 obj->GetPhaseMask(),
316 obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ(), obj->GetOrientation(),
317 cell.GridX(), cell.GridY(), cell.CellX(), cell.CellY(), obj->GetInstanceId(),
318 zone_x, zone_y, ground_z, floor_z, have_map, have_vmap );
320 sLog.outDebug("Player %s GPS call for %s '%s' (%s: %u):",
321 m_session ? GetNameLink().c_str() : GetMangosString(LANG_CONSOLE_COMMAND),
322 (obj->GetTypeId() == TYPEID_PLAYER ? "player" : "creature"), obj->GetName(),
323 (obj->GetTypeId() == TYPEID_PLAYER ? "GUID" : "Entry"), (obj->GetTypeId() == TYPEID_PLAYER ? obj->GetGUIDLow(): obj->GetEntry()) );
325 sLog.outDebug(GetMangosString(LANG_MAP_POSITION),
326 obj->GetMapId(), (mapEntry ? mapEntry->name[sWorld.GetDefaultDbcLocale()] : "<unknown>" ),
327 zone_id, (zoneEntry ? zoneEntry->area_name[sWorld.GetDefaultDbcLocale()] : "<unknown>" ),
328 area_id, (areaEntry ? areaEntry->area_name[sWorld.GetDefaultDbcLocale()] : "<unknown>" ),
329 obj->GetPhaseMask(),
330 obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ(), obj->GetOrientation(),
331 cell.GridX(), cell.GridY(), cell.CellX(), cell.CellY(), obj->GetInstanceId(),
332 zone_x, zone_y, ground_z, floor_z, have_map, have_vmap );
334 LiquidData liquid_status;
335 ZLiquidStatus res = map->getLiquidStatus(obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ(), MAP_ALL_LIQUIDS, &liquid_status);
336 if (res)
338 PSendSysMessage(LANG_LIQUID_STATUS, liquid_status.level, liquid_status.depth_level, liquid_status.type, res);
340 return true;
343 //Summon Player
344 bool ChatHandler::HandleNamegoCommand(const char* args)
346 if(!*args)
347 return false;
349 std::string name = extractPlayerNameFromLink((char*)args);
350 if(name.empty())
352 SendSysMessage(LANG_PLAYER_NOT_FOUND);
353 SetSentErrorMessage(true);
354 return false;
357 Player *chr = objmgr.GetPlayer(name.c_str());
358 if (chr)
360 std::string nameLink = playerLink(name);
361 // check online security
362 if (HasLowerSecurity(chr, 0))
363 return false;
365 if(chr->IsBeingTeleported())
367 PSendSysMessage(LANG_IS_TELEPORTED, nameLink.c_str());
368 SetSentErrorMessage(true);
369 return false;
372 Map* pMap = m_session->GetPlayer()->GetMap();
374 if(pMap->IsBattleGroundOrArena())
376 // only allow if gm mode is on
377 if (!chr->isGameMaster())
379 PSendSysMessage(LANG_CANNOT_GO_TO_BG_GM,chr->GetName());
380 SetSentErrorMessage(true);
381 return false;
383 // if both players are in different bgs
384 else if (chr->GetBattleGroundId() && m_session->GetPlayer()->GetBattleGroundId() != chr->GetBattleGroundId())
386 PSendSysMessage(LANG_CANNOT_GO_TO_BG_FROM_BG,chr->GetName());
387 SetSentErrorMessage(true);
388 return false;
390 // all's well, set bg id
391 // when porting out from the bg, it will be reset to 0
392 chr->SetBattleGroundId(m_session->GetPlayer()->GetBattleGroundId(), m_session->GetPlayer()->GetBattleGroundTypeId());
393 // remember current position as entry point for return at bg end teleportation
394 chr->SetBattleGroundEntryPoint(chr->GetMapId(),chr->GetPositionX(),chr->GetPositionY(),chr->GetPositionZ(),chr->GetOrientation());
396 else if(pMap->IsDungeon())
398 Map* cMap = chr->GetMap();
399 if( cMap->Instanceable() && cMap->GetInstanceId() != pMap->GetInstanceId() )
401 // cannot summon from instance to instance
402 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,nameLink.c_str());
403 SetSentErrorMessage(true);
404 return false;
407 // we are in instance, and can summon only player in our group with us as lead
408 if ( !m_session->GetPlayer()->GetGroup() || !chr->GetGroup() ||
409 (chr->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ||
410 (m_session->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) )
411 // the last check is a bit excessive, but let it be, just in case
413 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,nameLink.c_str());
414 SetSentErrorMessage(true);
415 return false;
419 PSendSysMessage(LANG_SUMMONING, nameLink.c_str(),"");
420 if (needReportToTarget(chr))
421 ChatHandler(chr).PSendSysMessage(LANG_SUMMONED_BY, nameLink.c_str());
423 // stop flight if need
424 if(chr->isInFlight())
426 chr->GetMotionMaster()->MovementExpired();
427 chr->m_taxi.ClearTaxiDestinations();
429 // save only in non-flight case
430 else
431 chr->SaveRecallPosition();
433 // before GM
434 float x,y,z;
435 m_session->GetPlayer()->GetClosePoint(x,y,z,chr->GetObjectSize());
436 chr->TeleportTo(m_session->GetPlayer()->GetMapId(),x,y,z,chr->GetOrientation());
438 else if (uint64 guid = objmgr.GetPlayerGUIDByName(name))
440 // check offline security
441 if (HasLowerSecurity(NULL, guid))
442 return false;
444 std::string nameLink = playerLink(name);
446 PSendSysMessage(LANG_SUMMONING, nameLink.c_str(),GetMangosString(LANG_OFFLINE));
448 // in point where GM stay
449 Player::SavePositionInDB(m_session->GetPlayer()->GetMapId(),
450 m_session->GetPlayer()->GetPositionX(),
451 m_session->GetPlayer()->GetPositionY(),
452 m_session->GetPlayer()->GetPositionZ(),
453 m_session->GetPlayer()->GetOrientation(),
454 m_session->GetPlayer()->GetZoneId(),
455 guid);
457 else
459 PSendSysMessage(LANG_NO_PLAYER, args);
460 SetSentErrorMessage(true);
463 return true;
466 //Teleport to Player
467 bool ChatHandler::HandleGonameCommand(const char* args)
469 if(!*args)
470 return false;
472 Player* _player = m_session->GetPlayer();
474 std::string name = extractPlayerNameFromLink((char*)args);
475 if(name.empty())
477 SendSysMessage(LANG_PLAYER_NOT_FOUND);
478 SetSentErrorMessage(true);
479 return false;
482 Player *chr = objmgr.GetPlayer(name.c_str());
483 if (chr)
485 // check online security
486 if (HasLowerSecurity(chr, 0))
487 return false;
489 std::string chrNameLink = playerLink(name);
491 Map* cMap = chr->GetMap();
492 if(cMap->IsBattleGroundOrArena())
494 // only allow if gm mode is on
495 if (!_player->isGameMaster())
497 PSendSysMessage(LANG_CANNOT_GO_TO_BG_GM,chrNameLink.c_str());
498 SetSentErrorMessage(true);
499 return false;
501 // if both players are in different bgs
502 else if (_player->GetBattleGroundId() && _player->GetBattleGroundId() != chr->GetBattleGroundId())
504 PSendSysMessage(LANG_CANNOT_GO_TO_BG_FROM_BG,chrNameLink.c_str());
505 SetSentErrorMessage(true);
506 return false;
508 // all's well, set bg id
509 // when porting out from the bg, it will be reset to 0
510 _player->SetBattleGroundId(chr->GetBattleGroundId(), chr->GetBattleGroundTypeId());
511 // remember current position as entry point for return at bg end teleportation
512 _player->SetBattleGroundEntryPoint(_player->GetMapId(),_player->GetPositionX(),_player->GetPositionY(),_player->GetPositionZ(),_player->GetOrientation());
514 else if(cMap->IsDungeon())
516 // we have to go to instance, and can go to player only if:
517 // 1) we are in his group (either as leader or as member)
518 // 2) we are not bound to any group and have GM mode on
519 if (_player->GetGroup())
521 // we are in group, we can go only if we are in the player group
522 if (_player->GetGroup() != chr->GetGroup())
524 PSendSysMessage(LANG_CANNOT_GO_TO_INST_PARTY,chrNameLink.c_str());
525 SetSentErrorMessage(true);
526 return false;
529 else
531 // we are not in group, let's verify our GM mode
532 if (!_player->isGameMaster())
534 PSendSysMessage(LANG_CANNOT_GO_TO_INST_GM,chrNameLink.c_str());
535 SetSentErrorMessage(true);
536 return false;
540 // if the player or the player's group is bound to another instance
541 // the player will not be bound to another one
542 InstancePlayerBind *pBind = _player->GetBoundInstance(chr->GetMapId(), chr->GetDifficulty());
543 if(!pBind)
545 Group *group = _player->GetGroup();
546 InstanceGroupBind *gBind = group ? group->GetBoundInstance(chr->GetMapId(), chr->GetDifficulty()) : NULL;
547 if(!gBind)
549 // if no bind exists, create a solo bind
550 InstanceSave *save = sInstanceSaveManager.GetInstanceSave(chr->GetInstanceId());
551 if(save) _player->BindToInstance(save, !save->CanReset());
555 _player->SetDifficulty(chr->GetDifficulty());
558 PSendSysMessage(LANG_APPEARING_AT, chrNameLink.c_str());
559 if (_player->IsVisibleGloballyFor(chr))
560 ChatHandler(chr).PSendSysMessage(LANG_APPEARING_TO, GetNameLink().c_str());
562 // stop flight if need
563 if(_player->isInFlight())
565 _player->GetMotionMaster()->MovementExpired();
566 _player->m_taxi.ClearTaxiDestinations();
568 // save only in non-flight case
569 else
570 _player->SaveRecallPosition();
572 // to point to see at target with same orientation
573 float x,y,z;
574 chr->GetContactPoint(m_session->GetPlayer(),x,y,z);
576 _player->TeleportTo(chr->GetMapId(), x, y, z, _player->GetAngle( chr ), TELE_TO_GM_MODE);
578 return true;
581 if (uint64 guid = objmgr.GetPlayerGUIDByName(name))
583 // check offline security
584 if (HasLowerSecurity(NULL, guid))
585 return false;
587 std::string nameLink = playerLink(name);
589 PSendSysMessage(LANG_APPEARING_AT, nameLink.c_str());
591 // to point where player stay (if loaded)
592 float x,y,z,o;
593 uint32 map;
594 bool in_flight;
595 if(Player::LoadPositionFromDB(map,x,y,z,o,in_flight,guid))
597 // stop flight if need
598 if(_player->isInFlight())
600 _player->GetMotionMaster()->MovementExpired();
601 _player->m_taxi.ClearTaxiDestinations();
603 // save only in non-flight case
604 else
605 _player->SaveRecallPosition();
607 _player->TeleportTo(map, x, y, z,_player->GetOrientation());
608 return true;
612 PSendSysMessage(LANG_NO_PLAYER, args);
614 SetSentErrorMessage(true);
615 return false;
618 // Teleport player to last position
619 bool ChatHandler::HandleRecallCommand(const char* args)
621 Player* chr = NULL;
623 if(!*args)
625 chr = getSelectedPlayer();
626 if(!chr)
627 chr = m_session->GetPlayer();
629 // check online security
630 else if (HasLowerSecurity(chr, 0))
631 return false;
633 else
635 std::string name = extractPlayerNameFromLink((char*)args);
636 if(name.empty())
638 SendSysMessage(LANG_PLAYER_NOT_FOUND);
639 SetSentErrorMessage(true);
640 return false;
643 chr = objmgr.GetPlayer(name.c_str());
645 if(!chr)
647 PSendSysMessage(LANG_NO_PLAYER, args);
648 SetSentErrorMessage(true);
649 return false;
652 // check online security
653 if (HasLowerSecurity(chr, 0))
654 return false;
657 if(chr->IsBeingTeleported())
659 PSendSysMessage(LANG_IS_TELEPORTED, GetNameLink(chr).c_str());
660 SetSentErrorMessage(true);
661 return false;
664 // stop flight if need
665 if(chr->isInFlight())
667 chr->GetMotionMaster()->MovementExpired();
668 chr->m_taxi.ClearTaxiDestinations();
671 chr->TeleportTo(chr->m_recallMap, chr->m_recallX, chr->m_recallY, chr->m_recallZ, chr->m_recallO);
672 return true;
675 //Edit Player KnownTitles
676 bool ChatHandler::HandleModifyKnownTitlesCommand(const char* args)
678 if(!*args)
679 return false;
681 uint64 titles = 0;
683 sscanf((char*)args, I64FMTD, &titles);
685 Player *chr = getSelectedPlayer();
686 if (!chr)
688 SendSysMessage(LANG_NO_CHAR_SELECTED);
689 SetSentErrorMessage(true);
690 return false;
693 // check online security
694 if (HasLowerSecurity(chr, 0))
695 return false;
697 uint64 titles2 = titles;
699 for(int i=1; i < sCharTitlesStore.GetNumRows(); ++i)
700 if(CharTitlesEntry const* tEntry = sCharTitlesStore.LookupEntry(i))
701 titles2 &= ~(uint64(1) << tEntry->bit_index);
703 titles &= ~titles2; // remove not existed titles
705 chr->SetUInt64Value(PLAYER__FIELD_KNOWN_TITLES, titles);
706 SendSysMessage(LANG_DONE);
708 return true;
711 //Edit Player HP
712 bool ChatHandler::HandleModifyHPCommand(const char* args)
714 if(!*args)
715 return false;
717 // char* pHp = strtok((char*)args, " ");
718 // if (!pHp)
719 // return false;
721 // char* pHpMax = strtok(NULL, " ");
722 // if (!pHpMax)
723 // return false;
725 // int32 hpm = atoi(pHpMax);
726 // int32 hp = atoi(pHp);
728 int32 hp = atoi((char*)args);
729 int32 hpm = atoi((char*)args);
731 if (hp <= 0 || hpm <= 0 || hpm < hp)
733 SendSysMessage(LANG_BAD_VALUE);
734 SetSentErrorMessage(true);
735 return false;
738 Player *chr = getSelectedPlayer();
739 if (chr == NULL)
741 SendSysMessage(LANG_NO_CHAR_SELECTED);
742 SetSentErrorMessage(true);
743 return false;
746 // check online security
747 if (HasLowerSecurity(chr, 0))
748 return false;
750 PSendSysMessage(LANG_YOU_CHANGE_HP, GetNameLink(chr).c_str(), hp, hpm);
751 if (needReportToTarget(chr))
752 ChatHandler(chr).PSendSysMessage(LANG_YOURS_HP_CHANGED, GetNameLink().c_str(), hp, hpm);
754 chr->SetMaxHealth( hpm );
755 chr->SetHealth( hp );
757 return true;
760 //Edit Player Mana
761 bool ChatHandler::HandleModifyManaCommand(const char* args)
763 if(!*args)
764 return false;
766 // char* pmana = strtok((char*)args, " ");
767 // if (!pmana)
768 // return false;
770 // char* pmanaMax = strtok(NULL, " ");
771 // if (!pmanaMax)
772 // return false;
774 // int32 manam = atoi(pmanaMax);
775 // int32 mana = atoi(pmana);
776 int32 mana = atoi((char*)args);
777 int32 manam = atoi((char*)args);
779 if (mana <= 0 || manam <= 0 || manam < mana)
781 SendSysMessage(LANG_BAD_VALUE);
782 SetSentErrorMessage(true);
783 return false;
786 Player *chr = getSelectedPlayer();
787 if (chr == NULL)
789 SendSysMessage(LANG_NO_CHAR_SELECTED);
790 SetSentErrorMessage(true);
791 return false;
794 // check online security
795 if (HasLowerSecurity(chr, 0))
796 return false;
798 PSendSysMessage(LANG_YOU_CHANGE_MANA, GetNameLink(chr).c_str(), mana, manam);
799 if (needReportToTarget(chr))
800 ChatHandler(chr).PSendSysMessage(LANG_YOURS_MANA_CHANGED, GetNameLink().c_str(), mana, manam);
802 chr->SetMaxPower(POWER_MANA,manam );
803 chr->SetPower(POWER_MANA, mana );
805 return true;
808 //Edit Player Energy
809 bool ChatHandler::HandleModifyEnergyCommand(const char* args)
811 if(!*args)
812 return false;
814 // char* pmana = strtok((char*)args, " ");
815 // if (!pmana)
816 // return false;
818 // char* pmanaMax = strtok(NULL, " ");
819 // if (!pmanaMax)
820 // return false;
822 // int32 manam = atoi(pmanaMax);
823 // int32 mana = atoi(pmana);
825 int32 energy = atoi((char*)args)*10;
826 int32 energym = atoi((char*)args)*10;
828 if (energy <= 0 || energym <= 0 || energym < energy)
830 SendSysMessage(LANG_BAD_VALUE);
831 SetSentErrorMessage(true);
832 return false;
835 Player *chr = getSelectedPlayer();
836 if (!chr)
838 SendSysMessage(LANG_NO_CHAR_SELECTED);
839 SetSentErrorMessage(true);
840 return false;
843 // check online security
844 if (HasLowerSecurity(chr, 0))
845 return false;
847 PSendSysMessage(LANG_YOU_CHANGE_ENERGY, GetNameLink(chr).c_str(), energy/10, energym/10);
848 if (needReportToTarget(chr))
849 ChatHandler(chr).PSendSysMessage(LANG_YOURS_ENERGY_CHANGED, GetNameLink().c_str(), energy/10, energym/10);
851 chr->SetMaxPower(POWER_ENERGY,energym );
852 chr->SetPower(POWER_ENERGY, energy );
854 sLog.outDetail(GetMangosString(LANG_CURRENT_ENERGY),chr->GetMaxPower(POWER_ENERGY));
856 return true;
859 //Edit Player Rage
860 bool ChatHandler::HandleModifyRageCommand(const char* args)
862 if(!*args)
863 return false;
865 // char* pmana = strtok((char*)args, " ");
866 // if (!pmana)
867 // return false;
869 // char* pmanaMax = strtok(NULL, " ");
870 // if (!pmanaMax)
871 // return false;
873 // int32 manam = atoi(pmanaMax);
874 // int32 mana = atoi(pmana);
876 int32 rage = atoi((char*)args)*10;
877 int32 ragem = atoi((char*)args)*10;
879 if (rage <= 0 || ragem <= 0 || ragem < rage)
881 SendSysMessage(LANG_BAD_VALUE);
882 SetSentErrorMessage(true);
883 return false;
886 Player *chr = getSelectedPlayer();
887 if (chr == NULL)
889 SendSysMessage(LANG_NO_CHAR_SELECTED);
890 SetSentErrorMessage(true);
891 return false;
894 // check online security
895 if (HasLowerSecurity(chr, 0))
896 return false;
898 PSendSysMessage(LANG_YOU_CHANGE_RAGE, GetNameLink(chr).c_str(), rage/10, ragem/10);
899 if (needReportToTarget(chr))
900 ChatHandler(chr).PSendSysMessage(LANG_YOURS_RAGE_CHANGED, GetNameLink().c_str(), rage/10, ragem/10);
902 chr->SetMaxPower(POWER_RAGE,ragem );
903 chr->SetPower(POWER_RAGE, rage );
905 return true;
908 // Edit Player Runic Power
909 bool ChatHandler::HandleModifyRunicPowerCommand(const char* args)
911 if(!*args)
912 return false;
914 int32 rune = atoi((char*)args)*10;
915 int32 runem = atoi((char*)args)*10;
917 if (rune <= 0 || runem <= 0 || runem < rune)
919 SendSysMessage(LANG_BAD_VALUE);
920 SetSentErrorMessage(true);
921 return false;
924 Player *chr = getSelectedPlayer();
925 if (chr == NULL)
927 SendSysMessage(LANG_NO_CHAR_SELECTED);
928 SetSentErrorMessage(true);
929 return false;
932 PSendSysMessage(LANG_YOU_CHANGE_RUNIC_POWER, GetNameLink(chr).c_str(), rune/10, runem/10);
933 if (needReportToTarget(chr))
934 ChatHandler(chr).PSendSysMessage(LANG_YOURS_RUNIC_POWER_CHANGED, GetNameLink().c_str(), rune/10, runem/10);
936 chr->SetMaxPower(POWER_RUNIC_POWER,runem );
937 chr->SetPower(POWER_RUNIC_POWER, rune );
939 return true;
942 //Edit Player Faction
943 bool ChatHandler::HandleModifyFactionCommand(const char* args)
945 if(!*args)
946 return false;
948 char* pfactionid = extractKeyFromLink((char*)args,"Hfaction");
950 Creature* chr = getSelectedCreature();
951 if(!chr)
953 SendSysMessage(LANG_SELECT_CREATURE);
954 SetSentErrorMessage(true);
955 return false;
958 if(!pfactionid)
960 if(chr)
962 uint32 factionid = chr->getFaction();
963 uint32 flag = chr->GetUInt32Value(UNIT_FIELD_FLAGS);
964 uint32 npcflag = chr->GetUInt32Value(UNIT_NPC_FLAGS);
965 uint32 dyflag = chr->GetUInt32Value(UNIT_DYNAMIC_FLAGS);
966 PSendSysMessage(LANG_CURRENT_FACTION,chr->GetGUIDLow(),factionid,flag,npcflag,dyflag);
968 return true;
971 if( !chr )
973 SendSysMessage(LANG_NO_CHAR_SELECTED);
974 SetSentErrorMessage(true);
975 return false;
978 uint32 factionid = atoi(pfactionid);
979 uint32 flag;
981 char *pflag = strtok(NULL, " ");
982 if (!pflag)
983 flag = chr->GetUInt32Value(UNIT_FIELD_FLAGS);
984 else
985 flag = atoi(pflag);
987 char* pnpcflag = strtok(NULL, " ");
989 uint32 npcflag;
990 if(!pnpcflag)
991 npcflag = chr->GetUInt32Value(UNIT_NPC_FLAGS);
992 else
993 npcflag = atoi(pnpcflag);
995 char* pdyflag = strtok(NULL, " ");
997 uint32 dyflag;
998 if(!pdyflag)
999 dyflag = chr->GetUInt32Value(UNIT_DYNAMIC_FLAGS);
1000 else
1001 dyflag = atoi(pdyflag);
1003 if(!sFactionTemplateStore.LookupEntry(factionid))
1005 PSendSysMessage(LANG_WRONG_FACTION, factionid);
1006 SetSentErrorMessage(true);
1007 return false;
1010 PSendSysMessage(LANG_YOU_CHANGE_FACTION, chr->GetGUIDLow(),factionid,flag,npcflag,dyflag);
1012 chr->setFaction(factionid);
1013 chr->SetUInt32Value(UNIT_FIELD_FLAGS,flag);
1014 chr->SetUInt32Value(UNIT_NPC_FLAGS,npcflag);
1015 chr->SetUInt32Value(UNIT_DYNAMIC_FLAGS,dyflag);
1017 return true;
1020 //Edit Player Spell
1021 bool ChatHandler::HandleModifySpellCommand(const char* args)
1023 if(!*args) return false;
1024 char* pspellflatid = strtok((char*)args, " ");
1025 if (!pspellflatid)
1026 return false;
1028 char* pop = strtok(NULL, " ");
1029 if (!pop)
1030 return false;
1032 char* pval = strtok(NULL, " ");
1033 if (!pval)
1034 return false;
1036 uint16 mark;
1038 char* pmark = strtok(NULL, " ");
1040 uint8 spellflatid = atoi(pspellflatid);
1041 uint8 op = atoi(pop);
1042 uint16 val = atoi(pval);
1043 if(!pmark)
1044 mark = 65535;
1045 else
1046 mark = atoi(pmark);
1048 Player *chr = getSelectedPlayer();
1049 if (chr == NULL)
1051 SendSysMessage(LANG_NO_CHAR_SELECTED);
1052 SetSentErrorMessage(true);
1053 return false;
1056 // check online security
1057 if (HasLowerSecurity(chr, 0))
1058 return false;
1060 PSendSysMessage(LANG_YOU_CHANGE_SPELLFLATID, spellflatid, val, mark, GetNameLink(chr).c_str());
1061 if (needReportToTarget(chr))
1062 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SPELLFLATID_CHANGED, GetNameLink().c_str(), spellflatid, val, mark);
1064 WorldPacket data(SMSG_SET_FLAT_SPELL_MODIFIER, (1+1+2+2));
1065 data << uint8(spellflatid);
1066 data << uint8(op);
1067 data << uint16(val);
1068 data << uint16(mark);
1069 chr->GetSession()->SendPacket(&data);
1071 return true;
1074 //Edit Player TP
1075 bool ChatHandler::HandleModifyTalentCommand (const char* args)
1077 if (!*args)
1078 return false;
1080 int tp = atoi((char*)args);
1081 if (tp>0)
1083 Player* player = getSelectedPlayer();
1084 if(!player)
1086 SendSysMessage(LANG_NO_CHAR_SELECTED);
1087 SetSentErrorMessage(true);
1088 return false;
1091 // check online security
1092 if (HasLowerSecurity(player, 0))
1093 return false;
1095 player->SetFreeTalentPoints(tp);
1096 return true;
1098 return false;
1101 //Enable On\OFF all taxi paths
1102 bool ChatHandler::HandleTaxiCheatCommand(const char* args)
1104 if (!*args)
1106 SendSysMessage(LANG_USE_BOL);
1107 SetSentErrorMessage(true);
1108 return false;
1111 std::string argstr = (char*)args;
1113 Player *chr = getSelectedPlayer();
1114 if (!chr)
1116 chr=m_session->GetPlayer();
1119 // check online security
1120 else if (HasLowerSecurity(chr, 0))
1121 return false;
1123 if (argstr == "on")
1125 chr->SetTaxiCheater(true);
1126 PSendSysMessage(LANG_YOU_GIVE_TAXIS, GetNameLink(chr).c_str());
1127 if (needReportToTarget(chr))
1128 ChatHandler(chr).PSendSysMessage(LANG_YOURS_TAXIS_ADDED, GetNameLink().c_str());
1129 return true;
1132 if (argstr == "off")
1134 chr->SetTaxiCheater(false);
1135 PSendSysMessage(LANG_YOU_REMOVE_TAXIS, GetNameLink(chr).c_str());
1136 if (needReportToTarget(chr))
1137 ChatHandler(chr).PSendSysMessage(LANG_YOURS_TAXIS_REMOVED, GetNameLink().c_str());
1139 return true;
1142 SendSysMessage(LANG_USE_BOL);
1143 SetSentErrorMessage(true);
1144 return false;
1147 //Edit Player Aspeed
1148 bool ChatHandler::HandleModifyASpeedCommand(const char* args)
1150 if (!*args)
1151 return false;
1153 float ASpeed = (float)atof((char*)args);
1155 if (ASpeed > 10 || ASpeed < 0.1)
1157 SendSysMessage(LANG_BAD_VALUE);
1158 SetSentErrorMessage(true);
1159 return false;
1162 Player *chr = getSelectedPlayer();
1163 if (chr == NULL)
1165 SendSysMessage(LANG_NO_CHAR_SELECTED);
1166 SetSentErrorMessage(true);
1167 return false;
1170 // check online security
1171 if (HasLowerSecurity(chr, 0))
1172 return false;
1174 std::string chrNameLink = GetNameLink(chr);
1176 if(chr->isInFlight())
1178 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chrNameLink.c_str());
1179 SetSentErrorMessage(true);
1180 return false;
1183 PSendSysMessage(LANG_YOU_CHANGE_ASPEED, ASpeed, chrNameLink.c_str());
1184 if (needReportToTarget(chr))
1185 ChatHandler(chr).PSendSysMessage(LANG_YOURS_ASPEED_CHANGED, GetNameLink().c_str(), ASpeed);
1187 chr->SetSpeed(MOVE_WALK, ASpeed,true);
1188 chr->SetSpeed(MOVE_RUN, ASpeed,true);
1189 chr->SetSpeed(MOVE_SWIM, ASpeed,true);
1190 //chr->SetSpeed(MOVE_TURN, ASpeed,true);
1191 chr->SetSpeed(MOVE_FLIGHT, ASpeed,true);
1192 return true;
1195 //Edit Player Speed
1196 bool ChatHandler::HandleModifySpeedCommand(const char* args)
1198 if (!*args)
1199 return false;
1201 float Speed = (float)atof((char*)args);
1203 if (Speed > 10 || Speed < 0.1)
1205 SendSysMessage(LANG_BAD_VALUE);
1206 SetSentErrorMessage(true);
1207 return false;
1210 Player *chr = getSelectedPlayer();
1211 if (chr == NULL)
1213 SendSysMessage(LANG_NO_CHAR_SELECTED);
1214 SetSentErrorMessage(true);
1215 return false;
1218 // check online security
1219 if (HasLowerSecurity(chr, 0))
1220 return false;
1222 std::string chrNameLink = GetNameLink(chr);
1224 if(chr->isInFlight())
1226 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chrNameLink.c_str());
1227 SetSentErrorMessage(true);
1228 return false;
1231 PSendSysMessage(LANG_YOU_CHANGE_SPEED, Speed, chrNameLink.c_str());
1232 if (needReportToTarget(chr))
1233 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SPEED_CHANGED, GetNameLink().c_str(), Speed);
1235 chr->SetSpeed(MOVE_RUN,Speed,true);
1237 return true;
1240 //Edit Player Swim Speed
1241 bool ChatHandler::HandleModifySwimCommand(const char* args)
1243 if (!*args)
1244 return false;
1246 float Swim = (float)atof((char*)args);
1248 if (Swim > 10.0f || Swim < 0.01f)
1250 SendSysMessage(LANG_BAD_VALUE);
1251 SetSentErrorMessage(true);
1252 return false;
1255 Player *chr = getSelectedPlayer();
1256 if (chr == NULL)
1258 SendSysMessage(LANG_NO_CHAR_SELECTED);
1259 SetSentErrorMessage(true);
1260 return false;
1263 // check online security
1264 if (HasLowerSecurity(chr, 0))
1265 return false;
1267 std::string chrNameLink = GetNameLink(chr);
1269 if(chr->isInFlight())
1271 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chrNameLink.c_str());
1272 SetSentErrorMessage(true);
1273 return false;
1276 PSendSysMessage(LANG_YOU_CHANGE_SWIM_SPEED, Swim, chrNameLink.c_str());
1277 if (needReportToTarget(chr))
1278 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SWIM_SPEED_CHANGED, GetNameLink().c_str(), Swim);
1280 chr->SetSpeed(MOVE_SWIM,Swim,true);
1282 return true;
1285 //Edit Player Walk Speed
1286 bool ChatHandler::HandleModifyBWalkCommand(const char* args)
1288 if (!*args)
1289 return false;
1291 float BSpeed = (float)atof((char*)args);
1293 if (BSpeed > 10.0f || BSpeed < 0.1f)
1295 SendSysMessage(LANG_BAD_VALUE);
1296 SetSentErrorMessage(true);
1297 return false;
1300 Player *chr = getSelectedPlayer();
1301 if (chr == NULL)
1303 SendSysMessage(LANG_NO_CHAR_SELECTED);
1304 SetSentErrorMessage(true);
1305 return false;
1308 // check online security
1309 if (HasLowerSecurity(chr, 0))
1310 return false;
1312 std::string chrNameLink = GetNameLink(chr);
1314 if(chr->isInFlight())
1316 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chrNameLink.c_str());
1317 SetSentErrorMessage(true);
1318 return false;
1321 PSendSysMessage(LANG_YOU_CHANGE_BACK_SPEED, BSpeed, chrNameLink.c_str());
1322 if (needReportToTarget(chr))
1323 ChatHandler(chr).PSendSysMessage(LANG_YOURS_BACK_SPEED_CHANGED, GetNameLink().c_str(), BSpeed);
1325 chr->SetSpeed(MOVE_RUN_BACK,BSpeed,true);
1327 return true;
1330 //Edit Player Fly
1331 bool ChatHandler::HandleModifyFlyCommand(const char* args)
1333 if (!*args)
1334 return false;
1336 float FSpeed = (float)atof((char*)args);
1338 if (FSpeed > 10.0f || FSpeed < 0.1f)
1340 SendSysMessage(LANG_BAD_VALUE);
1341 SetSentErrorMessage(true);
1342 return false;
1345 Player *chr = getSelectedPlayer();
1346 if (chr == NULL)
1348 SendSysMessage(LANG_NO_CHAR_SELECTED);
1349 SetSentErrorMessage(true);
1350 return false;
1353 // check online security
1354 if (HasLowerSecurity(chr, 0))
1355 return false;
1357 PSendSysMessage(LANG_YOU_CHANGE_FLY_SPEED, FSpeed, GetNameLink(chr).c_str());
1358 if (needReportToTarget(chr))
1359 ChatHandler(chr).PSendSysMessage(LANG_YOURS_FLY_SPEED_CHANGED, GetNameLink().c_str(), FSpeed);
1361 chr->SetSpeed(MOVE_FLIGHT,FSpeed,true);
1363 return true;
1366 //Edit Player Scale
1367 bool ChatHandler::HandleModifyScaleCommand(const char* args)
1369 if (!*args)
1370 return false;
1372 float Scale = (float)atof((char*)args);
1373 if (Scale > 3.0f || Scale <= 0.0f)
1375 SendSysMessage(LANG_BAD_VALUE);
1376 SetSentErrorMessage(true);
1377 return false;
1380 Player *chr = getSelectedPlayer();
1381 if (chr == NULL)
1383 SendSysMessage(LANG_NO_CHAR_SELECTED);
1384 SetSentErrorMessage(true);
1385 return false;
1388 // check online security
1389 if (HasLowerSecurity(chr, 0))
1390 return false;
1392 PSendSysMessage(LANG_YOU_CHANGE_SIZE, Scale, GetNameLink(chr).c_str());
1393 if (needReportToTarget(chr))
1394 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SIZE_CHANGED, GetNameLink().c_str(), Scale);
1396 chr->SetFloatValue(OBJECT_FIELD_SCALE_X, Scale);
1398 return true;
1401 //Enable Player mount
1402 bool ChatHandler::HandleModifyMountCommand(const char* args)
1404 if(!*args)
1405 return false;
1407 uint16 mId = 1147;
1408 float speed = (float)15;
1409 uint32 num = 0;
1411 num = atoi((char*)args);
1412 switch(num)
1414 case 1:
1415 mId=14340;
1416 break;
1417 case 2:
1418 mId=4806;
1419 break;
1420 case 3:
1421 mId=6471;
1422 break;
1423 case 4:
1424 mId=12345;
1425 break;
1426 case 5:
1427 mId=6472;
1428 break;
1429 case 6:
1430 mId=6473;
1431 break;
1432 case 7:
1433 mId=10670;
1434 break;
1435 case 8:
1436 mId=10719;
1437 break;
1438 case 9:
1439 mId=10671;
1440 break;
1441 case 10:
1442 mId=10672;
1443 break;
1444 case 11:
1445 mId=10720;
1446 break;
1447 case 12:
1448 mId=14349;
1449 break;
1450 case 13:
1451 mId=11641;
1452 break;
1453 case 14:
1454 mId=12244;
1455 break;
1456 case 15:
1457 mId=12242;
1458 break;
1459 case 16:
1460 mId=14578;
1461 break;
1462 case 17:
1463 mId=14579;
1464 break;
1465 case 18:
1466 mId=14349;
1467 break;
1468 case 19:
1469 mId=12245;
1470 break;
1471 case 20:
1472 mId=14335;
1473 break;
1474 case 21:
1475 mId=207;
1476 break;
1477 case 22:
1478 mId=2328;
1479 break;
1480 case 23:
1481 mId=2327;
1482 break;
1483 case 24:
1484 mId=2326;
1485 break;
1486 case 25:
1487 mId=14573;
1488 break;
1489 case 26:
1490 mId=14574;
1491 break;
1492 case 27:
1493 mId=14575;
1494 break;
1495 case 28:
1496 mId=604;
1497 break;
1498 case 29:
1499 mId=1166;
1500 break;
1501 case 30:
1502 mId=2402;
1503 break;
1504 case 31:
1505 mId=2410;
1506 break;
1507 case 32:
1508 mId=2409;
1509 break;
1510 case 33:
1511 mId=2408;
1512 break;
1513 case 34:
1514 mId=2405;
1515 break;
1516 case 35:
1517 mId=14337;
1518 break;
1519 case 36:
1520 mId=6569;
1521 break;
1522 case 37:
1523 mId=10661;
1524 break;
1525 case 38:
1526 mId=10666;
1527 break;
1528 case 39:
1529 mId=9473;
1530 break;
1531 case 40:
1532 mId=9476;
1533 break;
1534 case 41:
1535 mId=9474;
1536 break;
1537 case 42:
1538 mId=14374;
1539 break;
1540 case 43:
1541 mId=14376;
1542 break;
1543 case 44:
1544 mId=14377;
1545 break;
1546 case 45:
1547 mId=2404;
1548 break;
1549 case 46:
1550 mId=2784;
1551 break;
1552 case 47:
1553 mId=2787;
1554 break;
1555 case 48:
1556 mId=2785;
1557 break;
1558 case 49:
1559 mId=2736;
1560 break;
1561 case 50:
1562 mId=2786;
1563 break;
1564 case 51:
1565 mId=14347;
1566 break;
1567 case 52:
1568 mId=14346;
1569 break;
1570 case 53:
1571 mId=14576;
1572 break;
1573 case 54:
1574 mId=9695;
1575 break;
1576 case 55:
1577 mId=9991;
1578 break;
1579 case 56:
1580 mId=6448;
1581 break;
1582 case 57:
1583 mId=6444;
1584 break;
1585 case 58:
1586 mId=6080;
1587 break;
1588 case 59:
1589 mId=6447;
1590 break;
1591 case 60:
1592 mId=4805;
1593 break;
1594 case 61:
1595 mId=9714;
1596 break;
1597 case 62:
1598 mId=6448;
1599 break;
1600 case 63:
1601 mId=6442;
1602 break;
1603 case 64:
1604 mId=14632;
1605 break;
1606 case 65:
1607 mId=14332;
1608 break;
1609 case 66:
1610 mId=14331;
1611 break;
1612 case 67:
1613 mId=8469;
1614 break;
1615 case 68:
1616 mId=2830;
1617 break;
1618 case 69:
1619 mId=2346;
1620 break;
1621 default:
1622 SendSysMessage(LANG_NO_MOUNT);
1623 SetSentErrorMessage(true);
1624 return false;
1627 Player *chr = getSelectedPlayer();
1628 if (chr == NULL)
1630 SendSysMessage(LANG_NO_CHAR_SELECTED);
1631 SetSentErrorMessage(true);
1632 return false;
1635 // check online security
1636 if (HasLowerSecurity(chr, 0))
1637 return false;
1639 PSendSysMessage(LANG_YOU_GIVE_MOUNT, GetNameLink(chr).c_str());
1640 if (needReportToTarget(chr))
1641 ChatHandler(chr).PSendSysMessage(LANG_MOUNT_GIVED, GetNameLink().c_str());
1643 chr->SetUInt32Value( UNIT_FIELD_FLAGS , 0x001000 );
1644 chr->Mount(mId);
1646 WorldPacket data( SMSG_FORCE_RUN_SPEED_CHANGE, (8+4+1+4) );
1647 data.append(chr->GetPackGUID());
1648 data << (uint32)0;
1649 data << (uint8)0; //new 2.1.0
1650 data << float(speed);
1651 chr->SendMessageToSet( &data, true );
1653 data.Initialize( SMSG_FORCE_SWIM_SPEED_CHANGE, (8+4+4) );
1654 data.append(chr->GetPackGUID());
1655 data << (uint32)0;
1656 data << float(speed);
1657 chr->SendMessageToSet( &data, true );
1659 return true;
1662 //Edit Player money
1663 bool ChatHandler::HandleModifyMoneyCommand(const char* args)
1665 if (!*args)
1666 return false;
1668 Player *chr = getSelectedPlayer();
1669 if (chr == NULL)
1671 SendSysMessage(LANG_NO_CHAR_SELECTED);
1672 SetSentErrorMessage(true);
1673 return false;
1676 // check online security
1677 if (HasLowerSecurity(chr, 0))
1678 return false;
1680 int32 addmoney = atoi((char*)args);
1682 uint32 moneyuser = chr->GetMoney();
1684 if(addmoney < 0)
1686 int32 newmoney = moneyuser + addmoney;
1688 sLog.outDetail(GetMangosString(LANG_CURRENT_MONEY), moneyuser, addmoney, newmoney);
1689 if(newmoney <= 0 )
1691 PSendSysMessage(LANG_YOU_TAKE_ALL_MONEY, GetNameLink(chr).c_str());
1692 if (needReportToTarget(chr))
1693 ChatHandler(chr).PSendSysMessage(LANG_YOURS_ALL_MONEY_GONE, GetNameLink().c_str());
1695 chr->SetMoney(0);
1697 else
1699 PSendSysMessage(LANG_YOU_TAKE_MONEY, abs(addmoney), GetNameLink(chr).c_str());
1700 if (needReportToTarget(chr))
1701 ChatHandler(chr).PSendSysMessage(LANG_YOURS_MONEY_TAKEN, GetNameLink().c_str(), abs(addmoney));
1702 chr->SetMoney( newmoney );
1705 else
1707 PSendSysMessage(LANG_YOU_GIVE_MONEY, addmoney, GetNameLink(chr).c_str());
1708 if (needReportToTarget(chr))
1709 ChatHandler(chr).PSendSysMessage(LANG_YOURS_MONEY_GIVEN, GetNameLink().c_str(), addmoney);
1710 chr->ModifyMoney( addmoney );
1713 sLog.outDetail(GetMangosString(LANG_NEW_MONEY), moneyuser, addmoney, chr->GetMoney() );
1715 return true;
1718 //Edit Unit field
1719 bool ChatHandler::HandleModifyBitCommand(const char* args)
1721 if( !*args )
1722 return false;
1724 Unit *unit = getSelectedUnit();
1725 if (!unit)
1727 SendSysMessage(LANG_NO_CHAR_SELECTED);
1728 SetSentErrorMessage(true);
1729 return false;
1732 // check online security
1733 if (unit->GetTypeId() == TYPEID_PLAYER && HasLowerSecurity((Player *)unit, 0))
1734 return false;
1736 char* pField = strtok((char*)args, " ");
1737 if (!pField)
1738 return false;
1740 char* pBit = strtok(NULL, " ");
1741 if (!pBit)
1742 return false;
1744 uint16 field = atoi(pField);
1745 uint32 bit = atoi(pBit);
1747 if (field < OBJECT_END || field >= unit->GetValuesCount())
1749 SendSysMessage(LANG_BAD_VALUE);
1750 SetSentErrorMessage(true);
1751 return false;
1753 if (bit < 1 || bit > 32)
1755 SendSysMessage(LANG_BAD_VALUE);
1756 SetSentErrorMessage(true);
1757 return false;
1760 if ( unit->HasFlag( field, (1<<(bit-1)) ) )
1762 unit->RemoveFlag( field, (1<<(bit-1)) );
1763 PSendSysMessage(LANG_REMOVE_BIT, bit, field);
1765 else
1767 unit->SetFlag( field, (1<<(bit-1)) );
1768 PSendSysMessage(LANG_SET_BIT, bit, field);
1770 return true;
1773 bool ChatHandler::HandleModifyHonorCommand (const char* args)
1775 if (!*args)
1776 return false;
1778 Player *target = getSelectedPlayer();
1779 if(!target)
1781 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1782 SetSentErrorMessage(true);
1783 return false;
1786 // check online security
1787 if (HasLowerSecurity(target, 0))
1788 return false;
1790 int32 amount = (uint32)atoi(args);
1792 target->ModifyHonorPoints(amount);
1794 PSendSysMessage(LANG_COMMAND_MODIFY_HONOR, GetNameLink(target).c_str(), target->GetHonorPoints());
1796 return true;
1799 bool ChatHandler::HandleTeleCommand(const char * args)
1801 if(!*args)
1802 return false;
1804 Player* _player = m_session->GetPlayer();
1806 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
1807 GameTele const* tele = extractGameTeleFromLink((char*)args);
1809 if (!tele)
1811 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
1812 SetSentErrorMessage(true);
1813 return false;
1816 // stop flight if need
1817 if(_player->isInFlight())
1819 _player->GetMotionMaster()->MovementExpired();
1820 _player->m_taxi.ClearTaxiDestinations();
1822 // save only in non-flight case
1823 else
1824 _player->SaveRecallPosition();
1826 _player->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
1827 return true;
1830 bool ChatHandler::HandleLookupAreaCommand(const char* args)
1832 if (!*args)
1833 return false;
1835 std::string namepart = args;
1836 std::wstring wnamepart;
1838 if (!Utf8toWStr (namepart,wnamepart))
1839 return false;
1841 uint32 counter = 0; // Counter for figure out that we found smth.
1843 // converting string that we try to find to lower case
1844 wstrToLower (wnamepart);
1846 // Search in AreaTable.dbc
1847 for (uint32 areaflag = 0; areaflag < sAreaStore.GetNumRows (); ++areaflag)
1849 AreaTableEntry const *areaEntry = sAreaStore.LookupEntry (areaflag);
1850 if (areaEntry)
1852 int loc = m_session ? m_session->GetSessionDbcLocale () : sWorld.GetDefaultDbcLocale();
1853 std::string name = areaEntry->area_name[loc];
1854 if (name.empty())
1855 continue;
1857 if (!Utf8FitTo (name, wnamepart))
1859 loc = 0;
1860 for(; loc < MAX_LOCALE; ++loc)
1862 if (m_session && loc==m_session->GetSessionDbcLocale ())
1863 continue;
1865 name = areaEntry->area_name[loc];
1866 if (name.empty ())
1867 continue;
1869 if (Utf8FitTo (name, wnamepart))
1870 break;
1874 if (loc < MAX_LOCALE)
1876 // send area in "id - [name]" format
1877 std::ostringstream ss;
1878 if (m_session)
1879 ss << areaEntry->ID << " - |cffffffff|Harea:" << areaEntry->ID << "|h[" << name << " " << localeNames[loc]<< "]|h|r";
1880 else
1881 ss << areaEntry->ID << " - " << name << " " << localeNames[loc];
1883 SendSysMessage (ss.str ().c_str());
1885 ++counter;
1890 if (counter == 0) // if counter == 0 then we found nth
1891 SendSysMessage (LANG_COMMAND_NOAREAFOUND);
1893 return true;
1896 //Find tele in game_tele order by name
1897 bool ChatHandler::HandleLookupTeleCommand(const char * args)
1899 if(!*args)
1901 SendSysMessage(LANG_COMMAND_TELE_PARAMETER);
1902 SetSentErrorMessage(true);
1903 return false;
1906 char const* str = strtok((char*)args, " ");
1907 if(!str)
1908 return false;
1910 std::string namepart = str;
1911 std::wstring wnamepart;
1913 if(!Utf8toWStr(namepart,wnamepart))
1914 return false;
1916 // converting string that we try to find to lower case
1917 wstrToLower( wnamepart );
1919 std::ostringstream reply;
1921 GameTeleMap const & teleMap = objmgr.GetGameTeleMap();
1922 for(GameTeleMap::const_iterator itr = teleMap.begin(); itr != teleMap.end(); ++itr)
1924 GameTele const* tele = &itr->second;
1926 if(tele->wnameLow.find(wnamepart) == std::wstring::npos)
1927 continue;
1929 if (m_session)
1930 reply << " |cffffffff|Htele:" << itr->first << "|h[" << tele->name << "]|h|r\n";
1931 else
1932 reply << " " << itr->first << " " << tele->name << "\n";
1935 if(reply.str().empty())
1936 SendSysMessage(LANG_COMMAND_TELE_NOLOCATION);
1937 else
1938 PSendSysMessage(LANG_COMMAND_TELE_LOCATION,reply.str().c_str());
1940 return true;
1943 //Enable\Dissable accept whispers (for GM)
1944 bool ChatHandler::HandleWhispersCommand(const char* args)
1946 if(!*args)
1948 PSendSysMessage(LANG_COMMAND_WHISPERACCEPTING, m_session->GetPlayer()->isAcceptWhispers() ? GetMangosString(LANG_ON) : GetMangosString(LANG_OFF));
1949 return true;
1952 std::string argstr = (char*)args;
1953 // whisper on
1954 if (argstr == "on")
1956 m_session->GetPlayer()->SetAcceptWhispers(true);
1957 SendSysMessage(LANG_COMMAND_WHISPERON);
1958 return true;
1961 // whisper off
1962 if (argstr == "off")
1964 m_session->GetPlayer()->SetAcceptWhispers(false);
1965 SendSysMessage(LANG_COMMAND_WHISPEROFF);
1966 return true;
1969 SendSysMessage(LANG_USE_BOL);
1970 SetSentErrorMessage(true);
1971 return false;
1974 //Save all players in the world
1975 bool ChatHandler::HandleSaveAllCommand(const char* /*args*/)
1977 ObjectAccessor::Instance().SaveAllPlayers();
1978 SendSysMessage(LANG_PLAYERS_SAVED);
1979 return true;
1982 //Send mail by command
1983 bool ChatHandler::HandleSendMailCommand(const char* args)
1985 if(!*args)
1986 return false;
1988 // format: name "subject text" "mail text"
1990 std::string name = extractPlayerNameFromLink((char*)args);
1991 if(name.empty())
1993 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1994 SetSentErrorMessage(true);
1995 return false;
1998 char* tail1 = strtok(NULL, "");
1999 if(!tail1)
2000 return false;
2002 char* msgSubject;
2003 if(*tail1=='"')
2004 msgSubject = strtok(tail1+1, "\"");
2005 else
2007 char* space = strtok(tail1, "\"");
2008 if(!space)
2009 return false;
2010 msgSubject = strtok(NULL, "\"");
2013 if (!msgSubject)
2014 return false;
2016 char* tail2 = strtok(NULL, "");
2017 if(!tail2)
2018 return false;
2020 char* msgText;
2021 if(*tail2=='"')
2022 msgText = strtok(tail2+1, "\"");
2023 else
2025 char* space = strtok(tail2, "\"");
2026 if(!space)
2027 return false;
2028 msgText = strtok(NULL, "\"");
2031 if (!msgText)
2032 return false;
2034 // msgSubject, msgText isn't NUL after prev. check
2035 std::string subject = msgSubject;
2036 std::string text = msgText;
2038 uint64 receiver_guid = objmgr.GetPlayerGUIDByName(name);
2039 if(!receiver_guid)
2041 SendSysMessage(LANG_PLAYER_NOT_FOUND);
2042 SetSentErrorMessage(true);
2043 return false;
2046 // from console show not existed sender
2047 uint32 sender_guidlo = m_session ? m_session->GetPlayer()->GetGUIDLow() : 0;
2049 uint32 messagetype = MAIL_NORMAL;
2050 uint32 stationery = MAIL_STATIONERY_GM;
2051 uint32 itemTextId = !text.empty() ? objmgr.CreateItemText( text ) : 0;
2053 Player *receiver = objmgr.GetPlayer(receiver_guid);
2055 WorldSession::SendMailTo(receiver,messagetype, stationery, sender_guidlo, GUID_LOPART(receiver_guid), subject, itemTextId, NULL, 0, 0, MAIL_CHECK_MASK_NONE);
2057 std::string nameLink = playerLink(name);
2058 PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
2059 return true;
2062 // teleport player to given game_tele.entry
2063 bool ChatHandler::HandleTeleNameCommand(const char * args)
2065 if(!*args)
2066 return false;
2068 std::string name = extractPlayerNameFromLink((char*)args);
2069 if(name.empty())
2071 SendSysMessage(LANG_PLAYER_NOT_FOUND);
2072 SetSentErrorMessage(true);
2073 return false;
2076 char* tail = strtok(NULL, "");
2077 if(!tail)
2078 return false;
2080 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2081 GameTele const* tele = extractGameTeleFromLink(tail);
2082 if(!tele)
2084 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
2085 SetSentErrorMessage(true);
2086 return false;
2089 Player *chr = objmgr.GetPlayer(name.c_str());
2090 if (chr)
2092 // check online security
2093 if (HasLowerSecurity(chr, 0))
2094 return false;
2096 std::string chrNameLink = playerLink(name);
2098 if(chr->IsBeingTeleported()==true)
2100 PSendSysMessage(LANG_IS_TELEPORTED, chrNameLink.c_str());
2101 SetSentErrorMessage(true);
2102 return false;
2105 PSendSysMessage(LANG_TELEPORTING_TO, chrNameLink.c_str(),"", tele->name.c_str());
2106 if (needReportToTarget(chr))
2107 ChatHandler(chr).PSendSysMessage(LANG_TELEPORTED_TO_BY, GetNameLink().c_str());
2109 // stop flight if need
2110 if(chr->isInFlight())
2112 chr->GetMotionMaster()->MovementExpired();
2113 chr->m_taxi.ClearTaxiDestinations();
2115 // save only in non-flight case
2116 else
2117 chr->SaveRecallPosition();
2119 chr->TeleportTo(tele->mapId,tele->position_x,tele->position_y,tele->position_z,tele->orientation);
2121 else if (uint64 guid = objmgr.GetPlayerGUIDByName(name))
2123 // check offline security
2124 if (HasLowerSecurity(NULL, guid))
2125 return false;
2127 std::string nameLink = playerLink(name);
2129 PSendSysMessage(LANG_TELEPORTING_TO, nameLink.c_str(), GetMangosString(LANG_OFFLINE), tele->name.c_str());
2130 Player::SavePositionInDB(tele->mapId,tele->position_x,tele->position_y,tele->position_z,tele->orientation,
2131 MapManager::Instance().GetZoneId(tele->mapId,tele->position_x,tele->position_y,tele->position_z),guid);
2133 else
2134 PSendSysMessage(LANG_NO_PLAYER, name.c_str());
2136 return true;
2139 //Teleport group to given game_tele.entry
2140 bool ChatHandler::HandleTeleGroupCommand(const char * args)
2142 if(!*args)
2143 return false;
2145 Player *player = getSelectedPlayer();
2146 if (!player)
2148 SendSysMessage(LANG_NO_CHAR_SELECTED);
2149 SetSentErrorMessage(true);
2150 return false;
2153 // check online security
2154 if (HasLowerSecurity(player, 0))
2155 return false;
2157 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2158 GameTele const* tele = extractGameTeleFromLink((char*)args);
2159 if(!tele)
2161 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
2162 SetSentErrorMessage(true);
2163 return false;
2166 std::string nameLink = GetNameLink(player);
2168 Group *grp = player->GetGroup();
2169 if(!grp)
2171 PSendSysMessage(LANG_NOT_IN_GROUP,nameLink.c_str());
2172 SetSentErrorMessage(true);
2173 return false;
2176 for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
2178 Player *pl = itr->getSource();
2180 if(!pl || !pl->GetSession() )
2181 continue;
2183 // check online security
2184 if (HasLowerSecurity(pl, 0))
2185 return false;
2187 std::string plNameLink = GetNameLink(pl);
2189 if(pl->IsBeingTeleported())
2191 PSendSysMessage(LANG_IS_TELEPORTED, plNameLink.c_str());
2192 continue;
2195 PSendSysMessage(LANG_TELEPORTING_TO, plNameLink.c_str(),"", tele->name.c_str());
2196 if (needReportToTarget(pl))
2197 ChatHandler(pl).PSendSysMessage(LANG_TELEPORTED_TO_BY, nameLink.c_str());
2199 // stop flight if need
2200 if(pl->isInFlight())
2202 pl->GetMotionMaster()->MovementExpired();
2203 pl->m_taxi.ClearTaxiDestinations();
2205 // save only in non-flight case
2206 else
2207 pl->SaveRecallPosition();
2209 pl->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
2212 return true;
2215 //Summon group of player
2216 bool ChatHandler::HandleGroupgoCommand(const char* args)
2218 if(!*args)
2219 return false;
2221 std::string name = extractPlayerNameFromLink((char*)args);
2222 if(name.empty())
2224 SendSysMessage(LANG_PLAYER_NOT_FOUND);
2225 SetSentErrorMessage(true);
2226 return false;
2229 Player *player = objmgr.GetPlayer(name.c_str());
2230 if (!player)
2232 PSendSysMessage(LANG_NO_PLAYER, args);
2233 SetSentErrorMessage(true);
2234 return false;
2237 // check online security
2238 if (HasLowerSecurity(player, 0))
2239 return false;
2241 Group *grp = player->GetGroup();
2243 std::string nameLink = playerLink(name);
2245 if(!grp)
2247 PSendSysMessage(LANG_NOT_IN_GROUP,nameLink.c_str());
2248 SetSentErrorMessage(true);
2249 return false;
2252 Map* gmMap = m_session->GetPlayer()->GetMap();
2253 bool to_instance = gmMap->Instanceable();
2255 // we are in instance, and can summon only player in our group with us as lead
2256 if ( to_instance && (
2257 !m_session->GetPlayer()->GetGroup() || (grp->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ||
2258 (m_session->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ) )
2259 // the last check is a bit excessive, but let it be, just in case
2261 SendSysMessage(LANG_CANNOT_SUMMON_TO_INST);
2262 SetSentErrorMessage(true);
2263 return false;
2266 for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
2268 Player *pl = itr->getSource();
2270 if(!pl || pl==m_session->GetPlayer() || !pl->GetSession() )
2271 continue;
2273 // check online security
2274 if (HasLowerSecurity(pl, 0))
2275 return false;
2277 std::string plNameLink = playerLink(name);
2279 if(pl->IsBeingTeleported()==true)
2281 PSendSysMessage(LANG_IS_TELEPORTED, plNameLink.c_str());
2282 SetSentErrorMessage(true);
2283 return false;
2286 if (to_instance)
2288 Map* plMap = pl->GetMap();
2290 if ( plMap->Instanceable() && plMap->GetInstanceId() != gmMap->GetInstanceId() )
2292 // cannot summon from instance to instance
2293 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,plNameLink.c_str());
2294 SetSentErrorMessage(true);
2295 return false;
2299 PSendSysMessage(LANG_SUMMONING, plNameLink.c_str(),"");
2300 if (needReportToTarget(pl))
2301 ChatHandler(pl).PSendSysMessage(LANG_SUMMONED_BY, nameLink.c_str());
2303 // stop flight if need
2304 if(pl->isInFlight())
2306 pl->GetMotionMaster()->MovementExpired();
2307 pl->m_taxi.ClearTaxiDestinations();
2309 // save only in non-flight case
2310 else
2311 pl->SaveRecallPosition();
2313 // before GM
2314 float x,y,z;
2315 m_session->GetPlayer()->GetClosePoint(x,y,z,pl->GetObjectSize());
2316 pl->TeleportTo(m_session->GetPlayer()->GetMapId(),x,y,z,pl->GetOrientation());
2319 return true;
2322 bool ChatHandler::HandleGoTaxinodeCommand(const char* args)
2324 Player* _player = m_session->GetPlayer();
2326 if (!*args)
2327 return false;
2329 char* cNodeId = extractKeyFromLink((char*)args,"Htaxinode");
2330 if (!cNodeId)
2331 return false;
2333 int32 i_nodeId = atoi(cNodeId);
2334 if (!i_nodeId)
2335 return false;
2337 TaxiNodesEntry const* node = sTaxiNodesStore.LookupEntry(i_nodeId);
2338 if (!node)
2340 PSendSysMessage(LANG_COMMAND_GOTAXINODENOTFOUND,i_nodeId);
2341 SetSentErrorMessage(true);
2342 return false;
2345 if (node->x == 0.0f && node->y == 0.0f && node->z == 0.0f ||
2346 !MapManager::IsValidMapCoord(node->map_id,node->x,node->y,node->z))
2348 PSendSysMessage(LANG_INVALID_TARGET_COORD,node->x,node->y,node->map_id);
2349 SetSentErrorMessage(true);
2350 return false;
2353 // stop flight if need
2354 if (_player->isInFlight())
2356 _player->GetMotionMaster()->MovementExpired();
2357 _player->m_taxi.ClearTaxiDestinations();
2359 // save only in non-flight case
2360 else
2361 _player->SaveRecallPosition();
2363 _player->TeleportTo(node->map_id, node->x, node->y, node->z, _player->GetOrientation());
2364 return true;
2367 //teleport at coordinates
2368 bool ChatHandler::HandleGoXYCommand(const char* args)
2370 if(!*args)
2371 return false;
2373 Player* _player = m_session->GetPlayer();
2375 char* px = strtok((char*)args, " ");
2376 char* py = strtok(NULL, " ");
2377 char* pmapid = strtok(NULL, " ");
2379 if (!px || !py)
2380 return false;
2382 float x = (float)atof(px);
2383 float y = (float)atof(py);
2384 uint32 mapid;
2385 if (pmapid)
2386 mapid = (uint32)atoi(pmapid);
2387 else mapid = _player->GetMapId();
2389 if(!MapManager::IsValidMapCoord(mapid,x,y))
2391 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
2392 SetSentErrorMessage(true);
2393 return false;
2396 // stop flight if need
2397 if(_player->isInFlight())
2399 _player->GetMotionMaster()->MovementExpired();
2400 _player->m_taxi.ClearTaxiDestinations();
2402 // save only in non-flight case
2403 else
2404 _player->SaveRecallPosition();
2406 Map const *map = MapManager::Instance().GetBaseMap(mapid);
2407 float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
2409 _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
2411 return true;
2414 //teleport at coordinates, including Z
2415 bool ChatHandler::HandleGoXYZCommand(const char* args)
2417 if(!*args)
2418 return false;
2420 Player* _player = m_session->GetPlayer();
2422 char* px = strtok((char*)args, " ");
2423 char* py = strtok(NULL, " ");
2424 char* pz = strtok(NULL, " ");
2425 char* pmapid = strtok(NULL, " ");
2427 if (!px || !py || !pz)
2428 return false;
2430 float x = (float)atof(px);
2431 float y = (float)atof(py);
2432 float z = (float)atof(pz);
2433 uint32 mapid;
2434 if (pmapid)
2435 mapid = (uint32)atoi(pmapid);
2436 else
2437 mapid = _player->GetMapId();
2439 if(!MapManager::IsValidMapCoord(mapid,x,y,z))
2441 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
2442 SetSentErrorMessage(true);
2443 return false;
2446 // stop flight if need
2447 if(_player->isInFlight())
2449 _player->GetMotionMaster()->MovementExpired();
2450 _player->m_taxi.ClearTaxiDestinations();
2452 // save only in non-flight case
2453 else
2454 _player->SaveRecallPosition();
2456 _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
2458 return true;
2461 //teleport at coordinates
2462 bool ChatHandler::HandleGoZoneXYCommand(const char* args)
2464 if(!*args)
2465 return false;
2467 Player* _player = m_session->GetPlayer();
2469 char* px = strtok((char*)args, " ");
2470 char* py = strtok(NULL, " ");
2471 char* tail = strtok(NULL,"");
2473 char* cAreaId = extractKeyFromLink(tail,"Harea"); // string or [name] Shift-click form |color|Harea:area_id|h[name]|h|r
2475 if (!px || !py)
2476 return false;
2478 float x = (float)atof(px);
2479 float y = (float)atof(py);
2481 // prevent accept wrong numeric args
2482 if (x==0.0f && *px!='0' || y==0.0f && *py!='0')
2483 return false;
2485 uint32 areaid = cAreaId ? (uint32)atoi(cAreaId) : _player->GetZoneId();
2487 AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(areaid);
2489 if( x<0 || x>100 || y<0 || y>100 || !areaEntry )
2491 PSendSysMessage(LANG_INVALID_ZONE_COORD,x,y,areaid);
2492 SetSentErrorMessage(true);
2493 return false;
2496 // update to parent zone if exist (client map show only zones without parents)
2497 AreaTableEntry const* zoneEntry = areaEntry->zone ? GetAreaEntryByAreaID(areaEntry->zone) : areaEntry;
2499 Map const *map = MapManager::Instance().GetBaseMap(zoneEntry->mapid);
2501 if(map->Instanceable())
2503 PSendSysMessage(LANG_INVALID_ZONE_MAP,areaEntry->ID,areaEntry->area_name[m_session->GetSessionDbcLocale()],map->GetId(),map->GetMapName());
2504 SetSentErrorMessage(true);
2505 return false;
2508 Zone2MapCoordinates(x,y,zoneEntry->ID);
2510 if(!MapManager::IsValidMapCoord(zoneEntry->mapid,x,y))
2512 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,zoneEntry->mapid);
2513 SetSentErrorMessage(true);
2514 return false;
2517 // stop flight if need
2518 if(_player->isInFlight())
2520 _player->GetMotionMaster()->MovementExpired();
2521 _player->m_taxi.ClearTaxiDestinations();
2523 // save only in non-flight case
2524 else
2525 _player->SaveRecallPosition();
2527 float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
2528 _player->TeleportTo(zoneEntry->mapid, x, y, z, _player->GetOrientation());
2530 return true;
2533 //teleport to grid
2534 bool ChatHandler::HandleGoGridCommand(const char* args)
2536 if(!*args) return false;
2537 Player* _player = m_session->GetPlayer();
2539 char* px = strtok((char*)args, " ");
2540 char* py = strtok(NULL, " ");
2541 char* pmapid = strtok(NULL, " ");
2543 if (!px || !py)
2544 return false;
2546 float grid_x = (float)atof(px);
2547 float grid_y = (float)atof(py);
2548 uint32 mapid;
2549 if (pmapid)
2550 mapid = (uint32)atoi(pmapid);
2551 else mapid = _player->GetMapId();
2553 // center of grid
2554 float x = (grid_x-CENTER_GRID_ID+0.5f)*SIZE_OF_GRIDS;
2555 float y = (grid_y-CENTER_GRID_ID+0.5f)*SIZE_OF_GRIDS;
2557 if(!MapManager::IsValidMapCoord(mapid,x,y))
2559 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
2560 SetSentErrorMessage(true);
2561 return false;
2564 // stop flight if need
2565 if(_player->isInFlight())
2567 _player->GetMotionMaster()->MovementExpired();
2568 _player->m_taxi.ClearTaxiDestinations();
2570 // save only in non-flight case
2571 else
2572 _player->SaveRecallPosition();
2574 Map const *map = MapManager::Instance().GetBaseMap(mapid);
2575 float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
2576 _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
2578 return true;
2581 bool ChatHandler::HandleModifyDrunkCommand(const char* args)
2583 if(!*args) return false;
2585 uint32 drunklevel = (uint32)atoi(args);
2586 if(drunklevel > 100)
2587 drunklevel = 100;
2589 uint16 drunkMod = drunklevel * 0xFFFF / 100;
2591 m_session->GetPlayer()->SetDrunkValue(drunkMod);
2593 return true;