[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / src / game / Level1.cpp
blob0d2f24e6ce2bbe10b9516b73848c640e428e4664
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());
385 // remember current position as entry point for return at bg end teleportation
386 chr->SetBattleGroundEntryPoint(chr->GetMapId(),chr->GetPositionX(),chr->GetPositionY(),chr->GetPositionZ(),chr->GetOrientation());
388 else if(pMap->IsDungeon())
390 Map* cMap = chr->GetMap();
391 if( cMap->Instanceable() && cMap->GetInstanceId() != pMap->GetInstanceId() )
393 // cannot summon from instance to instance
394 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,nameLink.c_str());
395 SetSentErrorMessage(true);
396 return false;
399 // we are in instance, and can summon only player in our group with us as lead
400 if ( !m_session->GetPlayer()->GetGroup() || !chr->GetGroup() ||
401 (chr->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ||
402 (m_session->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) )
403 // the last check is a bit excessive, but let it be, just in case
405 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,nameLink.c_str());
406 SetSentErrorMessage(true);
407 return false;
411 PSendSysMessage(LANG_SUMMONING, nameLink.c_str(),"");
412 if (needReportToTarget(chr))
413 ChatHandler(chr).PSendSysMessage(LANG_SUMMONED_BY, nameLink.c_str());
415 // stop flight if need
416 if(chr->isInFlight())
418 chr->GetMotionMaster()->MovementExpired();
419 chr->m_taxi.ClearTaxiDestinations();
421 // save only in non-flight case
422 else
423 chr->SaveRecallPosition();
425 // before GM
426 float x,y,z;
427 m_session->GetPlayer()->GetClosePoint(x,y,z,chr->GetObjectSize());
428 chr->TeleportTo(m_session->GetPlayer()->GetMapId(),x,y,z,chr->GetOrientation());
430 else if (uint64 guid = objmgr.GetPlayerGUIDByName(name))
432 // check offline security
433 if (HasLowerSecurity(NULL, guid))
434 return false;
436 std::string nameLink = playerLink(name);
438 PSendSysMessage(LANG_SUMMONING, nameLink.c_str(),GetMangosString(LANG_OFFLINE));
440 // in point where GM stay
441 Player::SavePositionInDB(m_session->GetPlayer()->GetMapId(),
442 m_session->GetPlayer()->GetPositionX(),
443 m_session->GetPlayer()->GetPositionY(),
444 m_session->GetPlayer()->GetPositionZ(),
445 m_session->GetPlayer()->GetOrientation(),
446 m_session->GetPlayer()->GetZoneId(),
447 guid);
449 else
451 PSendSysMessage(LANG_NO_PLAYER, args);
452 SetSentErrorMessage(true);
455 return true;
458 //Teleport to Player
459 bool ChatHandler::HandleGonameCommand(const char* args)
461 if(!*args)
462 return false;
464 Player* _player = m_session->GetPlayer();
466 std::string name = extractPlayerNameFromLink((char*)args);
467 if(name.empty())
469 SendSysMessage(LANG_PLAYER_NOT_FOUND);
470 SetSentErrorMessage(true);
471 return false;
474 Player *chr = objmgr.GetPlayer(name.c_str());
475 if (chr)
477 // check online security
478 if (HasLowerSecurity(chr, 0))
479 return false;
481 std::string chrNameLink = playerLink(name);
483 Map* cMap = chr->GetMap();
484 if(cMap->IsBattleGroundOrArena())
486 // only allow if gm mode is on
487 if (!_player->isGameMaster())
489 PSendSysMessage(LANG_CANNOT_GO_TO_BG_GM,chrNameLink.c_str());
490 SetSentErrorMessage(true);
491 return false;
493 // if both players are in different bgs
494 else if (_player->GetBattleGroundId() && _player->GetBattleGroundId() != chr->GetBattleGroundId())
496 PSendSysMessage(LANG_CANNOT_GO_TO_BG_FROM_BG,chrNameLink.c_str());
497 SetSentErrorMessage(true);
498 return false;
500 // all's well, set bg id
501 // when porting out from the bg, it will be reset to 0
502 _player->SetBattleGroundId(chr->GetBattleGroundId());
503 // remember current position as entry point for return at bg end teleportation
504 _player->SetBattleGroundEntryPoint(_player->GetMapId(),_player->GetPositionX(),_player->GetPositionY(),_player->GetPositionZ(),_player->GetOrientation());
506 else if(cMap->IsDungeon() && cMap->Instanceable())
508 // we have to go to instance, and can go to player only if:
509 // 1) we are in his group (either as leader or as member)
510 // 2) we are not bound to any group and have GM mode on
511 if (_player->GetGroup())
513 // we are in group, we can go only if we are in the player group
514 if (_player->GetGroup() != chr->GetGroup())
516 PSendSysMessage(LANG_CANNOT_GO_TO_INST_PARTY,chrNameLink.c_str());
517 SetSentErrorMessage(true);
518 return false;
521 else
523 // we are not in group, let's verify our GM mode
524 if (!_player->isGameMaster())
526 PSendSysMessage(LANG_CANNOT_GO_TO_INST_GM,chrNameLink.c_str());
527 SetSentErrorMessage(true);
528 return false;
532 // if the player or the player's group is bound to another instance
533 // the player will not be bound to another one
534 InstancePlayerBind *pBind = _player->GetBoundInstance(chr->GetMapId(), chr->GetDifficulty());
535 if(!pBind)
537 Group *group = _player->GetGroup();
538 InstanceGroupBind *gBind = group ? group->GetBoundInstance(chr->GetMapId(), chr->GetDifficulty()) : NULL;
539 if(!gBind)
541 // if no bind exists, create a solo bind
542 InstanceSave *save = sInstanceSaveManager.GetInstanceSave(chr->GetInstanceId());
543 if(save) _player->BindToInstance(save, !save->CanReset());
547 _player->SetDifficulty(chr->GetDifficulty());
550 PSendSysMessage(LANG_APPEARING_AT, chrNameLink.c_str());
551 if (_player->IsVisibleGloballyFor(chr))
552 ChatHandler(chr).PSendSysMessage(LANG_APPEARING_TO, GetNameLink().c_str());
554 // stop flight if need
555 if(_player->isInFlight())
557 _player->GetMotionMaster()->MovementExpired();
558 _player->m_taxi.ClearTaxiDestinations();
560 // save only in non-flight case
561 else
562 _player->SaveRecallPosition();
564 // to point to see at target with same orientation
565 float x,y,z;
566 chr->GetContactPoint(m_session->GetPlayer(),x,y,z);
568 _player->TeleportTo(chr->GetMapId(), x, y, z, _player->GetAngle( chr ), TELE_TO_GM_MODE);
570 return true;
573 if (uint64 guid = objmgr.GetPlayerGUIDByName(name))
575 // check offline security
576 if (HasLowerSecurity(NULL, guid))
577 return false;
579 std::string nameLink = playerLink(name);
581 PSendSysMessage(LANG_APPEARING_AT, nameLink.c_str());
583 // to point where player stay (if loaded)
584 float x,y,z,o;
585 uint32 map;
586 bool in_flight;
587 if(Player::LoadPositionFromDB(map,x,y,z,o,in_flight,guid))
589 // stop flight if need
590 if(_player->isInFlight())
592 _player->GetMotionMaster()->MovementExpired();
593 _player->m_taxi.ClearTaxiDestinations();
595 // save only in non-flight case
596 else
597 _player->SaveRecallPosition();
599 _player->TeleportTo(map, x, y, z,_player->GetOrientation());
600 return true;
604 PSendSysMessage(LANG_NO_PLAYER, args);
606 SetSentErrorMessage(true);
607 return false;
610 // Teleport player to last position
611 bool ChatHandler::HandleRecallCommand(const char* args)
613 Player* chr = NULL;
615 if(!*args)
617 chr = getSelectedPlayer();
618 if(!chr)
619 chr = m_session->GetPlayer();
621 // check online security
622 else if (HasLowerSecurity(chr, 0))
623 return false;
625 else
627 std::string name = extractPlayerNameFromLink((char*)args);
628 if(name.empty())
630 SendSysMessage(LANG_PLAYER_NOT_FOUND);
631 SetSentErrorMessage(true);
632 return false;
635 chr = objmgr.GetPlayer(name.c_str());
637 if(!chr)
639 PSendSysMessage(LANG_NO_PLAYER, args);
640 SetSentErrorMessage(true);
641 return false;
644 // check online security
645 if (HasLowerSecurity(chr, 0))
646 return false;
649 if(chr->IsBeingTeleported())
651 PSendSysMessage(LANG_IS_TELEPORTED, GetNameLink(chr).c_str());
652 SetSentErrorMessage(true);
653 return false;
656 // stop flight if need
657 if(chr->isInFlight())
659 chr->GetMotionMaster()->MovementExpired();
660 chr->m_taxi.ClearTaxiDestinations();
663 chr->TeleportTo(chr->m_recallMap, chr->m_recallX, chr->m_recallY, chr->m_recallZ, chr->m_recallO);
664 return true;
667 //Edit Player KnownTitles
668 bool ChatHandler::HandleModifyKnownTitlesCommand(const char* args)
670 if(!*args)
671 return false;
673 uint64 titles = 0;
675 sscanf((char*)args, I64FMTD, &titles);
677 Player *chr = getSelectedPlayer();
678 if (!chr)
680 SendSysMessage(LANG_NO_CHAR_SELECTED);
681 SetSentErrorMessage(true);
682 return false;
685 // check online security
686 if (HasLowerSecurity(chr, 0))
687 return false;
689 uint64 titles2 = titles;
691 for(int i=1; i < sCharTitlesStore.GetNumRows(); ++i)
692 if(CharTitlesEntry const* tEntry = sCharTitlesStore.LookupEntry(i))
693 titles2 &= ~(uint64(1) << tEntry->bit_index);
695 titles &= ~titles2; // remove not existed titles
697 chr->SetUInt64Value(PLAYER__FIELD_KNOWN_TITLES, titles);
698 SendSysMessage(LANG_DONE);
700 return true;
703 //Edit Player HP
704 bool ChatHandler::HandleModifyHPCommand(const char* args)
706 if(!*args)
707 return false;
709 // char* pHp = strtok((char*)args, " ");
710 // if (!pHp)
711 // return false;
713 // char* pHpMax = strtok(NULL, " ");
714 // if (!pHpMax)
715 // return false;
717 // int32 hpm = atoi(pHpMax);
718 // int32 hp = atoi(pHp);
720 int32 hp = atoi((char*)args);
721 int32 hpm = atoi((char*)args);
723 if (hp <= 0 || hpm <= 0 || hpm < hp)
725 SendSysMessage(LANG_BAD_VALUE);
726 SetSentErrorMessage(true);
727 return false;
730 Player *chr = getSelectedPlayer();
731 if (chr == NULL)
733 SendSysMessage(LANG_NO_CHAR_SELECTED);
734 SetSentErrorMessage(true);
735 return false;
738 // check online security
739 if (HasLowerSecurity(chr, 0))
740 return false;
742 PSendSysMessage(LANG_YOU_CHANGE_HP, GetNameLink(chr).c_str(), hp, hpm);
743 if (needReportToTarget(chr))
744 ChatHandler(chr).PSendSysMessage(LANG_YOURS_HP_CHANGED, GetNameLink().c_str(), hp, hpm);
746 chr->SetMaxHealth( hpm );
747 chr->SetHealth( hp );
749 return true;
752 //Edit Player Mana
753 bool ChatHandler::HandleModifyManaCommand(const char* args)
755 if(!*args)
756 return false;
758 // char* pmana = strtok((char*)args, " ");
759 // if (!pmana)
760 // return false;
762 // char* pmanaMax = strtok(NULL, " ");
763 // if (!pmanaMax)
764 // return false;
766 // int32 manam = atoi(pmanaMax);
767 // int32 mana = atoi(pmana);
768 int32 mana = atoi((char*)args);
769 int32 manam = atoi((char*)args);
771 if (mana <= 0 || manam <= 0 || manam < mana)
773 SendSysMessage(LANG_BAD_VALUE);
774 SetSentErrorMessage(true);
775 return false;
778 Player *chr = getSelectedPlayer();
779 if (chr == NULL)
781 SendSysMessage(LANG_NO_CHAR_SELECTED);
782 SetSentErrorMessage(true);
783 return false;
786 // check online security
787 if (HasLowerSecurity(chr, 0))
788 return false;
790 PSendSysMessage(LANG_YOU_CHANGE_MANA, GetNameLink(chr).c_str(), mana, manam);
791 if (needReportToTarget(chr))
792 ChatHandler(chr).PSendSysMessage(LANG_YOURS_MANA_CHANGED, GetNameLink().c_str(), mana, manam);
794 chr->SetMaxPower(POWER_MANA,manam );
795 chr->SetPower(POWER_MANA, mana );
797 return true;
800 //Edit Player Energy
801 bool ChatHandler::HandleModifyEnergyCommand(const char* args)
803 if(!*args)
804 return false;
806 // char* pmana = strtok((char*)args, " ");
807 // if (!pmana)
808 // return false;
810 // char* pmanaMax = strtok(NULL, " ");
811 // if (!pmanaMax)
812 // return false;
814 // int32 manam = atoi(pmanaMax);
815 // int32 mana = atoi(pmana);
817 int32 energy = atoi((char*)args)*10;
818 int32 energym = atoi((char*)args)*10;
820 if (energy <= 0 || energym <= 0 || energym < energy)
822 SendSysMessage(LANG_BAD_VALUE);
823 SetSentErrorMessage(true);
824 return false;
827 Player *chr = getSelectedPlayer();
828 if (!chr)
830 SendSysMessage(LANG_NO_CHAR_SELECTED);
831 SetSentErrorMessage(true);
832 return false;
835 // check online security
836 if (HasLowerSecurity(chr, 0))
837 return false;
839 PSendSysMessage(LANG_YOU_CHANGE_ENERGY, GetNameLink(chr).c_str(), energy/10, energym/10);
840 if (needReportToTarget(chr))
841 ChatHandler(chr).PSendSysMessage(LANG_YOURS_ENERGY_CHANGED, GetNameLink().c_str(), energy/10, energym/10);
843 chr->SetMaxPower(POWER_ENERGY,energym );
844 chr->SetPower(POWER_ENERGY, energy );
846 sLog.outDetail(GetMangosString(LANG_CURRENT_ENERGY),chr->GetMaxPower(POWER_ENERGY));
848 return true;
851 //Edit Player Rage
852 bool ChatHandler::HandleModifyRageCommand(const char* args)
854 if(!*args)
855 return false;
857 // char* pmana = strtok((char*)args, " ");
858 // if (!pmana)
859 // return false;
861 // char* pmanaMax = strtok(NULL, " ");
862 // if (!pmanaMax)
863 // return false;
865 // int32 manam = atoi(pmanaMax);
866 // int32 mana = atoi(pmana);
868 int32 rage = atoi((char*)args)*10;
869 int32 ragem = atoi((char*)args)*10;
871 if (rage <= 0 || ragem <= 0 || ragem < rage)
873 SendSysMessage(LANG_BAD_VALUE);
874 SetSentErrorMessage(true);
875 return false;
878 Player *chr = getSelectedPlayer();
879 if (chr == NULL)
881 SendSysMessage(LANG_NO_CHAR_SELECTED);
882 SetSentErrorMessage(true);
883 return false;
886 // check online security
887 if (HasLowerSecurity(chr, 0))
888 return false;
890 PSendSysMessage(LANG_YOU_CHANGE_RAGE, GetNameLink(chr).c_str(), rage/10, ragem/10);
891 if (needReportToTarget(chr))
892 ChatHandler(chr).PSendSysMessage(LANG_YOURS_RAGE_CHANGED, GetNameLink().c_str(), rage/10, ragem/10);
894 chr->SetMaxPower(POWER_RAGE,ragem );
895 chr->SetPower(POWER_RAGE, rage );
897 return true;
900 // Edit Player Runic Power
901 bool ChatHandler::HandleModifyRunicPowerCommand(const char* args)
903 if(!*args)
904 return false;
906 int32 rune = atoi((char*)args)*10;
907 int32 runem = atoi((char*)args)*10;
909 if (rune <= 0 || runem <= 0 || runem < rune)
911 SendSysMessage(LANG_BAD_VALUE);
912 SetSentErrorMessage(true);
913 return false;
916 Player *chr = getSelectedPlayer();
917 if (chr == NULL)
919 SendSysMessage(LANG_NO_CHAR_SELECTED);
920 SetSentErrorMessage(true);
921 return false;
924 PSendSysMessage(LANG_YOU_CHANGE_RUNIC_POWER, GetNameLink(chr).c_str(), rune/10, runem/10);
925 if (needReportToTarget(chr))
926 ChatHandler(chr).PSendSysMessage(LANG_YOURS_RUNIC_POWER_CHANGED, GetNameLink().c_str(), rune/10, runem/10);
928 chr->SetMaxPower(POWER_RUNIC_POWER,runem );
929 chr->SetPower(POWER_RUNIC_POWER, rune );
931 return true;
934 //Edit Player Faction
935 bool ChatHandler::HandleModifyFactionCommand(const char* args)
937 if(!*args)
938 return false;
940 char* pfactionid = extractKeyFromLink((char*)args,"Hfaction");
942 Creature* chr = getSelectedCreature();
943 if(!chr)
945 SendSysMessage(LANG_SELECT_CREATURE);
946 SetSentErrorMessage(true);
947 return false;
950 if(!pfactionid)
952 if(chr)
954 uint32 factionid = chr->getFaction();
955 uint32 flag = chr->GetUInt32Value(UNIT_FIELD_FLAGS);
956 uint32 npcflag = chr->GetUInt32Value(UNIT_NPC_FLAGS);
957 uint32 dyflag = chr->GetUInt32Value(UNIT_DYNAMIC_FLAGS);
958 PSendSysMessage(LANG_CURRENT_FACTION,chr->GetGUIDLow(),factionid,flag,npcflag,dyflag);
960 return true;
963 if( !chr )
965 SendSysMessage(LANG_NO_CHAR_SELECTED);
966 SetSentErrorMessage(true);
967 return false;
970 uint32 factionid = atoi(pfactionid);
971 uint32 flag;
973 char *pflag = strtok(NULL, " ");
974 if (!pflag)
975 flag = chr->GetUInt32Value(UNIT_FIELD_FLAGS);
976 else
977 flag = atoi(pflag);
979 char* pnpcflag = strtok(NULL, " ");
981 uint32 npcflag;
982 if(!pnpcflag)
983 npcflag = chr->GetUInt32Value(UNIT_NPC_FLAGS);
984 else
985 npcflag = atoi(pnpcflag);
987 char* pdyflag = strtok(NULL, " ");
989 uint32 dyflag;
990 if(!pdyflag)
991 dyflag = chr->GetUInt32Value(UNIT_DYNAMIC_FLAGS);
992 else
993 dyflag = atoi(pdyflag);
995 if(!sFactionTemplateStore.LookupEntry(factionid))
997 PSendSysMessage(LANG_WRONG_FACTION, factionid);
998 SetSentErrorMessage(true);
999 return false;
1002 PSendSysMessage(LANG_YOU_CHANGE_FACTION, chr->GetGUIDLow(),factionid,flag,npcflag,dyflag);
1004 chr->setFaction(factionid);
1005 chr->SetUInt32Value(UNIT_FIELD_FLAGS,flag);
1006 chr->SetUInt32Value(UNIT_NPC_FLAGS,npcflag);
1007 chr->SetUInt32Value(UNIT_DYNAMIC_FLAGS,dyflag);
1009 return true;
1012 //Edit Player Spell
1013 bool ChatHandler::HandleModifySpellCommand(const char* args)
1015 if(!*args) return false;
1016 char* pspellflatid = strtok((char*)args, " ");
1017 if (!pspellflatid)
1018 return false;
1020 char* pop = strtok(NULL, " ");
1021 if (!pop)
1022 return false;
1024 char* pval = strtok(NULL, " ");
1025 if (!pval)
1026 return false;
1028 uint16 mark;
1030 char* pmark = strtok(NULL, " ");
1032 uint8 spellflatid = atoi(pspellflatid);
1033 uint8 op = atoi(pop);
1034 uint16 val = atoi(pval);
1035 if(!pmark)
1036 mark = 65535;
1037 else
1038 mark = atoi(pmark);
1040 Player *chr = getSelectedPlayer();
1041 if (chr == NULL)
1043 SendSysMessage(LANG_NO_CHAR_SELECTED);
1044 SetSentErrorMessage(true);
1045 return false;
1048 // check online security
1049 if (HasLowerSecurity(chr, 0))
1050 return false;
1052 PSendSysMessage(LANG_YOU_CHANGE_SPELLFLATID, spellflatid, val, mark, GetNameLink(chr).c_str());
1053 if (needReportToTarget(chr))
1054 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SPELLFLATID_CHANGED, GetNameLink().c_str(), spellflatid, val, mark);
1056 WorldPacket data(SMSG_SET_FLAT_SPELL_MODIFIER, (1+1+2+2));
1057 data << uint8(spellflatid);
1058 data << uint8(op);
1059 data << uint16(val);
1060 data << uint16(mark);
1061 chr->GetSession()->SendPacket(&data);
1063 return true;
1066 //Edit Player TP
1067 bool ChatHandler::HandleModifyTalentCommand (const char* args)
1069 if (!*args)
1070 return false;
1072 int tp = atoi((char*)args);
1073 if (tp>0)
1075 Player* player = getSelectedPlayer();
1076 if(!player)
1078 SendSysMessage(LANG_NO_CHAR_SELECTED);
1079 SetSentErrorMessage(true);
1080 return false;
1083 // check online security
1084 if (HasLowerSecurity(player, 0))
1085 return false;
1087 player->SetFreeTalentPoints(tp);
1088 return true;
1090 return false;
1093 //Enable On\OFF all taxi paths
1094 bool ChatHandler::HandleTaxiCheatCommand(const char* args)
1096 if (!*args)
1098 SendSysMessage(LANG_USE_BOL);
1099 SetSentErrorMessage(true);
1100 return false;
1103 std::string argstr = (char*)args;
1105 Player *chr = getSelectedPlayer();
1106 if (!chr)
1108 chr=m_session->GetPlayer();
1111 // check online security
1112 else if (HasLowerSecurity(chr, 0))
1113 return false;
1115 if (argstr == "on")
1117 chr->SetTaxiCheater(true);
1118 PSendSysMessage(LANG_YOU_GIVE_TAXIS, GetNameLink(chr).c_str());
1119 if (needReportToTarget(chr))
1120 ChatHandler(chr).PSendSysMessage(LANG_YOURS_TAXIS_ADDED, GetNameLink().c_str());
1121 return true;
1124 if (argstr == "off")
1126 chr->SetTaxiCheater(false);
1127 PSendSysMessage(LANG_YOU_REMOVE_TAXIS, GetNameLink(chr).c_str());
1128 if (needReportToTarget(chr))
1129 ChatHandler(chr).PSendSysMessage(LANG_YOURS_TAXIS_REMOVED, GetNameLink().c_str());
1131 return true;
1134 SendSysMessage(LANG_USE_BOL);
1135 SetSentErrorMessage(true);
1136 return false;
1139 //Edit Player Aspeed
1140 bool ChatHandler::HandleModifyASpeedCommand(const char* args)
1142 if (!*args)
1143 return false;
1145 float ASpeed = (float)atof((char*)args);
1147 if (ASpeed > 10 || ASpeed < 0.1)
1149 SendSysMessage(LANG_BAD_VALUE);
1150 SetSentErrorMessage(true);
1151 return false;
1154 Player *chr = getSelectedPlayer();
1155 if (chr == NULL)
1157 SendSysMessage(LANG_NO_CHAR_SELECTED);
1158 SetSentErrorMessage(true);
1159 return false;
1162 // check online security
1163 if (HasLowerSecurity(chr, 0))
1164 return false;
1166 std::string chrNameLink = GetNameLink(chr);
1168 if(chr->isInFlight())
1170 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chrNameLink.c_str());
1171 SetSentErrorMessage(true);
1172 return false;
1175 PSendSysMessage(LANG_YOU_CHANGE_ASPEED, ASpeed, chrNameLink.c_str());
1176 if (needReportToTarget(chr))
1177 ChatHandler(chr).PSendSysMessage(LANG_YOURS_ASPEED_CHANGED, GetNameLink().c_str(), ASpeed);
1179 chr->SetSpeed(MOVE_WALK, ASpeed,true);
1180 chr->SetSpeed(MOVE_RUN, ASpeed,true);
1181 chr->SetSpeed(MOVE_SWIM, ASpeed,true);
1182 //chr->SetSpeed(MOVE_TURN, ASpeed,true);
1183 chr->SetSpeed(MOVE_FLIGHT, ASpeed,true);
1184 return true;
1187 //Edit Player Speed
1188 bool ChatHandler::HandleModifySpeedCommand(const char* args)
1190 if (!*args)
1191 return false;
1193 float Speed = (float)atof((char*)args);
1195 if (Speed > 10 || Speed < 0.1)
1197 SendSysMessage(LANG_BAD_VALUE);
1198 SetSentErrorMessage(true);
1199 return false;
1202 Player *chr = getSelectedPlayer();
1203 if (chr == NULL)
1205 SendSysMessage(LANG_NO_CHAR_SELECTED);
1206 SetSentErrorMessage(true);
1207 return false;
1210 // check online security
1211 if (HasLowerSecurity(chr, 0))
1212 return false;
1214 std::string chrNameLink = GetNameLink(chr);
1216 if(chr->isInFlight())
1218 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chrNameLink.c_str());
1219 SetSentErrorMessage(true);
1220 return false;
1223 PSendSysMessage(LANG_YOU_CHANGE_SPEED, Speed, chrNameLink.c_str());
1224 if (needReportToTarget(chr))
1225 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SPEED_CHANGED, GetNameLink().c_str(), Speed);
1227 chr->SetSpeed(MOVE_RUN,Speed,true);
1229 return true;
1232 //Edit Player Swim Speed
1233 bool ChatHandler::HandleModifySwimCommand(const char* args)
1235 if (!*args)
1236 return false;
1238 float Swim = (float)atof((char*)args);
1240 if (Swim > 10.0f || Swim < 0.01f)
1242 SendSysMessage(LANG_BAD_VALUE);
1243 SetSentErrorMessage(true);
1244 return false;
1247 Player *chr = getSelectedPlayer();
1248 if (chr == NULL)
1250 SendSysMessage(LANG_NO_CHAR_SELECTED);
1251 SetSentErrorMessage(true);
1252 return false;
1255 // check online security
1256 if (HasLowerSecurity(chr, 0))
1257 return false;
1259 std::string chrNameLink = GetNameLink(chr);
1261 if(chr->isInFlight())
1263 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chrNameLink.c_str());
1264 SetSentErrorMessage(true);
1265 return false;
1268 PSendSysMessage(LANG_YOU_CHANGE_SWIM_SPEED, Swim, chrNameLink.c_str());
1269 if (needReportToTarget(chr))
1270 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SWIM_SPEED_CHANGED, GetNameLink().c_str(), Swim);
1272 chr->SetSpeed(MOVE_SWIM,Swim,true);
1274 return true;
1277 //Edit Player Walk Speed
1278 bool ChatHandler::HandleModifyBWalkCommand(const char* args)
1280 if (!*args)
1281 return false;
1283 float BSpeed = (float)atof((char*)args);
1285 if (BSpeed > 10.0f || BSpeed < 0.1f)
1287 SendSysMessage(LANG_BAD_VALUE);
1288 SetSentErrorMessage(true);
1289 return false;
1292 Player *chr = getSelectedPlayer();
1293 if (chr == NULL)
1295 SendSysMessage(LANG_NO_CHAR_SELECTED);
1296 SetSentErrorMessage(true);
1297 return false;
1300 // check online security
1301 if (HasLowerSecurity(chr, 0))
1302 return false;
1304 std::string chrNameLink = GetNameLink(chr);
1306 if(chr->isInFlight())
1308 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chrNameLink.c_str());
1309 SetSentErrorMessage(true);
1310 return false;
1313 PSendSysMessage(LANG_YOU_CHANGE_BACK_SPEED, BSpeed, chrNameLink.c_str());
1314 if (needReportToTarget(chr))
1315 ChatHandler(chr).PSendSysMessage(LANG_YOURS_BACK_SPEED_CHANGED, GetNameLink().c_str(), BSpeed);
1317 chr->SetSpeed(MOVE_RUN_BACK,BSpeed,true);
1319 return true;
1322 //Edit Player Fly
1323 bool ChatHandler::HandleModifyFlyCommand(const char* args)
1325 if (!*args)
1326 return false;
1328 float FSpeed = (float)atof((char*)args);
1330 if (FSpeed > 10.0f || FSpeed < 0.1f)
1332 SendSysMessage(LANG_BAD_VALUE);
1333 SetSentErrorMessage(true);
1334 return false;
1337 Player *chr = getSelectedPlayer();
1338 if (chr == NULL)
1340 SendSysMessage(LANG_NO_CHAR_SELECTED);
1341 SetSentErrorMessage(true);
1342 return false;
1345 // check online security
1346 if (HasLowerSecurity(chr, 0))
1347 return false;
1349 PSendSysMessage(LANG_YOU_CHANGE_FLY_SPEED, FSpeed, GetNameLink(chr).c_str());
1350 if (needReportToTarget(chr))
1351 ChatHandler(chr).PSendSysMessage(LANG_YOURS_FLY_SPEED_CHANGED, GetNameLink().c_str(), FSpeed);
1353 chr->SetSpeed(MOVE_FLIGHT,FSpeed,true);
1355 return true;
1358 //Edit Player Scale
1359 bool ChatHandler::HandleModifyScaleCommand(const char* args)
1361 if (!*args)
1362 return false;
1364 float Scale = (float)atof((char*)args);
1365 if (Scale > 3.0f || Scale <= 0.0f)
1367 SendSysMessage(LANG_BAD_VALUE);
1368 SetSentErrorMessage(true);
1369 return false;
1372 Player *chr = getSelectedPlayer();
1373 if (chr == NULL)
1375 SendSysMessage(LANG_NO_CHAR_SELECTED);
1376 SetSentErrorMessage(true);
1377 return false;
1380 // check online security
1381 if (HasLowerSecurity(chr, 0))
1382 return false;
1384 PSendSysMessage(LANG_YOU_CHANGE_SIZE, Scale, GetNameLink(chr).c_str());
1385 if (needReportToTarget(chr))
1386 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SIZE_CHANGED, GetNameLink().c_str(), Scale);
1388 chr->SetFloatValue(OBJECT_FIELD_SCALE_X, Scale);
1390 return true;
1393 //Enable Player mount
1394 bool ChatHandler::HandleModifyMountCommand(const char* args)
1396 if(!*args)
1397 return false;
1399 uint16 mId = 1147;
1400 float speed = (float)15;
1401 uint32 num = 0;
1403 num = atoi((char*)args);
1404 switch(num)
1406 case 1:
1407 mId=14340;
1408 break;
1409 case 2:
1410 mId=4806;
1411 break;
1412 case 3:
1413 mId=6471;
1414 break;
1415 case 4:
1416 mId=12345;
1417 break;
1418 case 5:
1419 mId=6472;
1420 break;
1421 case 6:
1422 mId=6473;
1423 break;
1424 case 7:
1425 mId=10670;
1426 break;
1427 case 8:
1428 mId=10719;
1429 break;
1430 case 9:
1431 mId=10671;
1432 break;
1433 case 10:
1434 mId=10672;
1435 break;
1436 case 11:
1437 mId=10720;
1438 break;
1439 case 12:
1440 mId=14349;
1441 break;
1442 case 13:
1443 mId=11641;
1444 break;
1445 case 14:
1446 mId=12244;
1447 break;
1448 case 15:
1449 mId=12242;
1450 break;
1451 case 16:
1452 mId=14578;
1453 break;
1454 case 17:
1455 mId=14579;
1456 break;
1457 case 18:
1458 mId=14349;
1459 break;
1460 case 19:
1461 mId=12245;
1462 break;
1463 case 20:
1464 mId=14335;
1465 break;
1466 case 21:
1467 mId=207;
1468 break;
1469 case 22:
1470 mId=2328;
1471 break;
1472 case 23:
1473 mId=2327;
1474 break;
1475 case 24:
1476 mId=2326;
1477 break;
1478 case 25:
1479 mId=14573;
1480 break;
1481 case 26:
1482 mId=14574;
1483 break;
1484 case 27:
1485 mId=14575;
1486 break;
1487 case 28:
1488 mId=604;
1489 break;
1490 case 29:
1491 mId=1166;
1492 break;
1493 case 30:
1494 mId=2402;
1495 break;
1496 case 31:
1497 mId=2410;
1498 break;
1499 case 32:
1500 mId=2409;
1501 break;
1502 case 33:
1503 mId=2408;
1504 break;
1505 case 34:
1506 mId=2405;
1507 break;
1508 case 35:
1509 mId=14337;
1510 break;
1511 case 36:
1512 mId=6569;
1513 break;
1514 case 37:
1515 mId=10661;
1516 break;
1517 case 38:
1518 mId=10666;
1519 break;
1520 case 39:
1521 mId=9473;
1522 break;
1523 case 40:
1524 mId=9476;
1525 break;
1526 case 41:
1527 mId=9474;
1528 break;
1529 case 42:
1530 mId=14374;
1531 break;
1532 case 43:
1533 mId=14376;
1534 break;
1535 case 44:
1536 mId=14377;
1537 break;
1538 case 45:
1539 mId=2404;
1540 break;
1541 case 46:
1542 mId=2784;
1543 break;
1544 case 47:
1545 mId=2787;
1546 break;
1547 case 48:
1548 mId=2785;
1549 break;
1550 case 49:
1551 mId=2736;
1552 break;
1553 case 50:
1554 mId=2786;
1555 break;
1556 case 51:
1557 mId=14347;
1558 break;
1559 case 52:
1560 mId=14346;
1561 break;
1562 case 53:
1563 mId=14576;
1564 break;
1565 case 54:
1566 mId=9695;
1567 break;
1568 case 55:
1569 mId=9991;
1570 break;
1571 case 56:
1572 mId=6448;
1573 break;
1574 case 57:
1575 mId=6444;
1576 break;
1577 case 58:
1578 mId=6080;
1579 break;
1580 case 59:
1581 mId=6447;
1582 break;
1583 case 60:
1584 mId=4805;
1585 break;
1586 case 61:
1587 mId=9714;
1588 break;
1589 case 62:
1590 mId=6448;
1591 break;
1592 case 63:
1593 mId=6442;
1594 break;
1595 case 64:
1596 mId=14632;
1597 break;
1598 case 65:
1599 mId=14332;
1600 break;
1601 case 66:
1602 mId=14331;
1603 break;
1604 case 67:
1605 mId=8469;
1606 break;
1607 case 68:
1608 mId=2830;
1609 break;
1610 case 69:
1611 mId=2346;
1612 break;
1613 default:
1614 SendSysMessage(LANG_NO_MOUNT);
1615 SetSentErrorMessage(true);
1616 return false;
1619 Player *chr = getSelectedPlayer();
1620 if (chr == NULL)
1622 SendSysMessage(LANG_NO_CHAR_SELECTED);
1623 SetSentErrorMessage(true);
1624 return false;
1627 // check online security
1628 if (HasLowerSecurity(chr, 0))
1629 return false;
1631 PSendSysMessage(LANG_YOU_GIVE_MOUNT, GetNameLink(chr).c_str());
1632 if (needReportToTarget(chr))
1633 ChatHandler(chr).PSendSysMessage(LANG_MOUNT_GIVED, GetNameLink().c_str());
1635 chr->SetUInt32Value( UNIT_FIELD_FLAGS , 0x001000 );
1636 chr->Mount(mId);
1638 WorldPacket data( SMSG_FORCE_RUN_SPEED_CHANGE, (8+4+1+4) );
1639 data.append(chr->GetPackGUID());
1640 data << (uint32)0;
1641 data << (uint8)0; //new 2.1.0
1642 data << float(speed);
1643 chr->SendMessageToSet( &data, true );
1645 data.Initialize( SMSG_FORCE_SWIM_SPEED_CHANGE, (8+4+4) );
1646 data.append(chr->GetPackGUID());
1647 data << (uint32)0;
1648 data << float(speed);
1649 chr->SendMessageToSet( &data, true );
1651 return true;
1654 //Edit Player money
1655 bool ChatHandler::HandleModifyMoneyCommand(const char* args)
1657 if (!*args)
1658 return false;
1660 Player *chr = getSelectedPlayer();
1661 if (chr == NULL)
1663 SendSysMessage(LANG_NO_CHAR_SELECTED);
1664 SetSentErrorMessage(true);
1665 return false;
1668 // check online security
1669 if (HasLowerSecurity(chr, 0))
1670 return false;
1672 int32 addmoney = atoi((char*)args);
1674 uint32 moneyuser = chr->GetMoney();
1676 if(addmoney < 0)
1678 int32 newmoney = moneyuser + addmoney;
1680 sLog.outDetail(GetMangosString(LANG_CURRENT_MONEY), moneyuser, addmoney, newmoney);
1681 if(newmoney <= 0 )
1683 PSendSysMessage(LANG_YOU_TAKE_ALL_MONEY, GetNameLink(chr).c_str());
1684 if (needReportToTarget(chr))
1685 ChatHandler(chr).PSendSysMessage(LANG_YOURS_ALL_MONEY_GONE, GetNameLink().c_str());
1687 chr->SetMoney(0);
1689 else
1691 PSendSysMessage(LANG_YOU_TAKE_MONEY, abs(addmoney), GetNameLink(chr).c_str());
1692 if (needReportToTarget(chr))
1693 ChatHandler(chr).PSendSysMessage(LANG_YOURS_MONEY_TAKEN, GetNameLink().c_str(), abs(addmoney));
1694 chr->SetMoney( newmoney );
1697 else
1699 PSendSysMessage(LANG_YOU_GIVE_MONEY, addmoney, GetNameLink(chr).c_str());
1700 if (needReportToTarget(chr))
1701 ChatHandler(chr).PSendSysMessage(LANG_YOURS_MONEY_GIVEN, GetNameLink().c_str(), addmoney);
1702 chr->ModifyMoney( addmoney );
1705 sLog.outDetail(GetMangosString(LANG_NEW_MONEY), moneyuser, addmoney, chr->GetMoney() );
1707 return true;
1710 //Edit Unit field
1711 bool ChatHandler::HandleModifyBitCommand(const char* args)
1713 if( !*args )
1714 return false;
1716 Unit *unit = getSelectedUnit();
1717 if (!unit)
1719 SendSysMessage(LANG_NO_CHAR_SELECTED);
1720 SetSentErrorMessage(true);
1721 return false;
1724 // check online security
1725 if (unit->GetTypeId() == TYPEID_PLAYER && HasLowerSecurity((Player *)unit, 0))
1726 return false;
1728 char* pField = strtok((char*)args, " ");
1729 if (!pField)
1730 return false;
1732 char* pBit = strtok(NULL, " ");
1733 if (!pBit)
1734 return false;
1736 uint16 field = atoi(pField);
1737 uint32 bit = atoi(pBit);
1739 if (field < OBJECT_END || field >= unit->GetValuesCount())
1741 SendSysMessage(LANG_BAD_VALUE);
1742 SetSentErrorMessage(true);
1743 return false;
1745 if (bit < 1 || bit > 32)
1747 SendSysMessage(LANG_BAD_VALUE);
1748 SetSentErrorMessage(true);
1749 return false;
1752 if ( unit->HasFlag( field, (1<<(bit-1)) ) )
1754 unit->RemoveFlag( field, (1<<(bit-1)) );
1755 PSendSysMessage(LANG_REMOVE_BIT, bit, field);
1757 else
1759 unit->SetFlag( field, (1<<(bit-1)) );
1760 PSendSysMessage(LANG_SET_BIT, bit, field);
1762 return true;
1765 bool ChatHandler::HandleModifyHonorCommand (const char* args)
1767 if (!*args)
1768 return false;
1770 Player *target = getSelectedPlayer();
1771 if(!target)
1773 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1774 SetSentErrorMessage(true);
1775 return false;
1778 // check online security
1779 if (HasLowerSecurity(target, 0))
1780 return false;
1782 int32 amount = (uint32)atoi(args);
1784 target->ModifyHonorPoints(amount);
1786 PSendSysMessage(LANG_COMMAND_MODIFY_HONOR, GetNameLink(target).c_str(), target->GetHonorPoints());
1788 return true;
1791 bool ChatHandler::HandleTeleCommand(const char * args)
1793 if(!*args)
1794 return false;
1796 Player* _player = m_session->GetPlayer();
1798 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
1799 GameTele const* tele = extractGameTeleFromLink((char*)args);
1801 if (!tele)
1803 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
1804 SetSentErrorMessage(true);
1805 return false;
1808 // stop flight if need
1809 if(_player->isInFlight())
1811 _player->GetMotionMaster()->MovementExpired();
1812 _player->m_taxi.ClearTaxiDestinations();
1814 // save only in non-flight case
1815 else
1816 _player->SaveRecallPosition();
1818 _player->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
1819 return true;
1822 bool ChatHandler::HandleLookupAreaCommand(const char* args)
1824 if (!*args)
1825 return false;
1827 std::string namepart = args;
1828 std::wstring wnamepart;
1830 if (!Utf8toWStr (namepart,wnamepart))
1831 return false;
1833 uint32 counter = 0; // Counter for figure out that we found smth.
1835 // converting string that we try to find to lower case
1836 wstrToLower (wnamepart);
1838 // Search in AreaTable.dbc
1839 for (uint32 areaflag = 0; areaflag < sAreaStore.GetNumRows (); ++areaflag)
1841 AreaTableEntry const *areaEntry = sAreaStore.LookupEntry (areaflag);
1842 if (areaEntry)
1844 int loc = m_session ? m_session->GetSessionDbcLocale () : sWorld.GetDefaultDbcLocale();
1845 std::string name = areaEntry->area_name[loc];
1846 if (name.empty())
1847 continue;
1849 if (!Utf8FitTo (name, wnamepart))
1851 loc = 0;
1852 for(; loc < MAX_LOCALE; ++loc)
1854 if (m_session && loc==m_session->GetSessionDbcLocale ())
1855 continue;
1857 name = areaEntry->area_name[loc];
1858 if (name.empty ())
1859 continue;
1861 if (Utf8FitTo (name, wnamepart))
1862 break;
1866 if (loc < MAX_LOCALE)
1868 // send area in "id - [name]" format
1869 std::ostringstream ss;
1870 if (m_session)
1871 ss << areaEntry->ID << " - |cffffffff|Harea:" << areaEntry->ID << "|h[" << name << " " << localeNames[loc]<< "]|h|r";
1872 else
1873 ss << areaEntry->ID << " - " << name << " " << localeNames[loc];
1875 SendSysMessage (ss.str ().c_str());
1877 ++counter;
1882 if (counter == 0) // if counter == 0 then we found nth
1883 SendSysMessage (LANG_COMMAND_NOAREAFOUND);
1885 return true;
1888 //Find tele in game_tele order by name
1889 bool ChatHandler::HandleLookupTeleCommand(const char * args)
1891 if(!*args)
1893 SendSysMessage(LANG_COMMAND_TELE_PARAMETER);
1894 SetSentErrorMessage(true);
1895 return false;
1898 char const* str = strtok((char*)args, " ");
1899 if(!str)
1900 return false;
1902 std::string namepart = str;
1903 std::wstring wnamepart;
1905 if(!Utf8toWStr(namepart,wnamepart))
1906 return false;
1908 // converting string that we try to find to lower case
1909 wstrToLower( wnamepart );
1911 std::ostringstream reply;
1913 GameTeleMap const & teleMap = objmgr.GetGameTeleMap();
1914 for(GameTeleMap::const_iterator itr = teleMap.begin(); itr != teleMap.end(); ++itr)
1916 GameTele const* tele = &itr->second;
1918 if(tele->wnameLow.find(wnamepart) == std::wstring::npos)
1919 continue;
1921 if (m_session)
1922 reply << " |cffffffff|Htele:" << itr->first << "|h[" << tele->name << "]|h|r\n";
1923 else
1924 reply << " " << itr->first << " " << tele->name << "\n";
1927 if(reply.str().empty())
1928 SendSysMessage(LANG_COMMAND_TELE_NOLOCATION);
1929 else
1930 PSendSysMessage(LANG_COMMAND_TELE_LOCATION,reply.str().c_str());
1932 return true;
1935 //Enable\Dissable accept whispers (for GM)
1936 bool ChatHandler::HandleWhispersCommand(const char* args)
1938 if(!*args)
1940 PSendSysMessage(LANG_COMMAND_WHISPERACCEPTING, m_session->GetPlayer()->isAcceptWhispers() ? GetMangosString(LANG_ON) : GetMangosString(LANG_OFF));
1941 return true;
1944 std::string argstr = (char*)args;
1945 // whisper on
1946 if (argstr == "on")
1948 m_session->GetPlayer()->SetAcceptWhispers(true);
1949 SendSysMessage(LANG_COMMAND_WHISPERON);
1950 return true;
1953 // whisper off
1954 if (argstr == "off")
1956 m_session->GetPlayer()->SetAcceptWhispers(false);
1957 SendSysMessage(LANG_COMMAND_WHISPEROFF);
1958 return true;
1961 SendSysMessage(LANG_USE_BOL);
1962 SetSentErrorMessage(true);
1963 return false;
1966 //Play sound
1967 bool ChatHandler::HandlePlaySoundCommand(const char* args)
1969 // USAGE: .debug playsound #soundid
1970 // #soundid - ID decimal number from SoundEntries.dbc (1st column)
1971 // this file have about 5000 sounds.
1972 // In this realization only caller can hear this sound.
1973 if( *args )
1975 uint32 dwSoundId = atoi((char*)args);
1977 if( !sSoundEntriesStore.LookupEntry(dwSoundId) )
1979 PSendSysMessage(LANG_SOUND_NOT_EXIST, dwSoundId);
1980 SetSentErrorMessage(true);
1981 return false;
1984 WorldPacket data(SMSG_PLAY_OBJECT_SOUND,4+8);
1985 data << uint32(dwSoundId) << m_session->GetPlayer()->GetGUID();
1986 m_session->SendPacket(&data);
1988 PSendSysMessage(LANG_YOU_HEAR_SOUND, dwSoundId);
1989 return true;
1992 return false;
1995 //Save all players in the world
1996 bool ChatHandler::HandleSaveAllCommand(const char* /*args*/)
1998 ObjectAccessor::Instance().SaveAllPlayers();
1999 SendSysMessage(LANG_PLAYERS_SAVED);
2000 return true;
2003 //Send mail by command
2004 bool ChatHandler::HandleSendMailCommand(const char* args)
2006 if(!*args)
2007 return false;
2009 // format: name "subject text" "mail text"
2011 std::string name = extractPlayerNameFromLink((char*)args);
2012 if(name.empty())
2014 SendSysMessage(LANG_PLAYER_NOT_FOUND);
2015 SetSentErrorMessage(true);
2016 return false;
2019 char* tail1 = strtok(NULL, "");
2020 if(!tail1)
2021 return false;
2023 char* msgSubject;
2024 if(*tail1=='"')
2025 msgSubject = strtok(tail1+1, "\"");
2026 else
2028 char* space = strtok(tail1, "\"");
2029 if(!space)
2030 return false;
2031 msgSubject = strtok(NULL, "\"");
2034 if (!msgSubject)
2035 return false;
2037 char* tail2 = strtok(NULL, "");
2038 if(!tail2)
2039 return false;
2041 char* msgText;
2042 if(*tail2=='"')
2043 msgText = strtok(tail2+1, "\"");
2044 else
2046 char* space = strtok(tail2, "\"");
2047 if(!space)
2048 return false;
2049 msgText = strtok(NULL, "\"");
2052 if (!msgText)
2053 return false;
2055 // msgSubject, msgText isn't NUL after prev. check
2056 std::string subject = msgSubject;
2057 std::string text = msgText;
2059 uint64 receiver_guid = objmgr.GetPlayerGUIDByName(name);
2060 if(!receiver_guid)
2062 SendSysMessage(LANG_PLAYER_NOT_FOUND);
2063 SetSentErrorMessage(true);
2064 return false;
2067 // from console show not existed sender
2068 uint32 sender_guidlo = m_session ? m_session->GetPlayer()->GetGUIDLow() : 0;
2070 uint32 messagetype = MAIL_NORMAL;
2071 uint32 stationery = MAIL_STATIONERY_GM;
2072 uint32 itemTextId = !text.empty() ? objmgr.CreateItemText( text ) : 0;
2074 Player *receiver = objmgr.GetPlayer(receiver_guid);
2076 WorldSession::SendMailTo(receiver,messagetype, stationery, sender_guidlo, GUID_LOPART(receiver_guid), subject, itemTextId, NULL, 0, 0, MAIL_CHECK_MASK_NONE);
2078 std::string nameLink = playerLink(name);
2079 PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
2080 return true;
2083 // teleport player to given game_tele.entry
2084 bool ChatHandler::HandleNameTeleCommand(const char * args)
2086 if(!*args)
2087 return false;
2089 std::string name = extractPlayerNameFromLink((char*)args);
2090 if(name.empty())
2092 SendSysMessage(LANG_PLAYER_NOT_FOUND);
2093 SetSentErrorMessage(true);
2094 return false;
2097 char* tail = strtok(NULL, "");
2098 if(!tail)
2099 return false;
2101 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2102 GameTele const* tele = extractGameTeleFromLink(tail);
2103 if(!tele)
2105 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
2106 SetSentErrorMessage(true);
2107 return false;
2110 Player *chr = objmgr.GetPlayer(name.c_str());
2111 if (chr)
2113 // check online security
2114 if (HasLowerSecurity(chr, 0))
2115 return false;
2117 std::string chrNameLink = playerLink(name);
2119 if(chr->IsBeingTeleported()==true)
2121 PSendSysMessage(LANG_IS_TELEPORTED, chrNameLink.c_str());
2122 SetSentErrorMessage(true);
2123 return false;
2126 PSendSysMessage(LANG_TELEPORTING_TO, chrNameLink.c_str(),"", tele->name.c_str());
2127 if (needReportToTarget(chr))
2128 ChatHandler(chr).PSendSysMessage(LANG_TELEPORTED_TO_BY, GetNameLink().c_str());
2130 // stop flight if need
2131 if(chr->isInFlight())
2133 chr->GetMotionMaster()->MovementExpired();
2134 chr->m_taxi.ClearTaxiDestinations();
2136 // save only in non-flight case
2137 else
2138 chr->SaveRecallPosition();
2140 chr->TeleportTo(tele->mapId,tele->position_x,tele->position_y,tele->position_z,tele->orientation);
2142 else if (uint64 guid = objmgr.GetPlayerGUIDByName(name))
2144 // check offline security
2145 if (HasLowerSecurity(NULL, guid))
2146 return false;
2148 std::string nameLink = playerLink(name);
2150 PSendSysMessage(LANG_TELEPORTING_TO, nameLink.c_str(), GetMangosString(LANG_OFFLINE), tele->name.c_str());
2151 Player::SavePositionInDB(tele->mapId,tele->position_x,tele->position_y,tele->position_z,tele->orientation,
2152 MapManager::Instance().GetZoneId(tele->mapId,tele->position_x,tele->position_y,tele->position_z),guid);
2154 else
2155 PSendSysMessage(LANG_NO_PLAYER, name.c_str());
2157 return true;
2160 //Teleport group to given game_tele.entry
2161 bool ChatHandler::HandleGroupTeleCommand(const char * args)
2163 if(!*args)
2164 return false;
2166 Player *player = getSelectedPlayer();
2167 if (!player)
2169 SendSysMessage(LANG_NO_CHAR_SELECTED);
2170 SetSentErrorMessage(true);
2171 return false;
2174 // check online security
2175 if (HasLowerSecurity(player, 0))
2176 return false;
2178 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2179 GameTele const* tele = extractGameTeleFromLink((char*)args);
2180 if(!tele)
2182 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
2183 SetSentErrorMessage(true);
2184 return false;
2187 std::string nameLink = GetNameLink(player);
2189 Group *grp = player->GetGroup();
2190 if(!grp)
2192 PSendSysMessage(LANG_NOT_IN_GROUP,nameLink.c_str());
2193 SetSentErrorMessage(true);
2194 return false;
2197 for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
2199 Player *pl = itr->getSource();
2201 if(!pl || !pl->GetSession() )
2202 continue;
2204 // check online security
2205 if (HasLowerSecurity(pl, 0))
2206 return false;
2208 std::string plNameLink = GetNameLink(pl);
2210 if(pl->IsBeingTeleported())
2212 PSendSysMessage(LANG_IS_TELEPORTED, plNameLink.c_str());
2213 continue;
2216 PSendSysMessage(LANG_TELEPORTING_TO, plNameLink.c_str(),"", tele->name.c_str());
2217 if (needReportToTarget(pl))
2218 ChatHandler(pl).PSendSysMessage(LANG_TELEPORTED_TO_BY, nameLink.c_str());
2220 // stop flight if need
2221 if(pl->isInFlight())
2223 pl->GetMotionMaster()->MovementExpired();
2224 pl->m_taxi.ClearTaxiDestinations();
2226 // save only in non-flight case
2227 else
2228 pl->SaveRecallPosition();
2230 pl->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
2233 return true;
2236 //Summon group of player
2237 bool ChatHandler::HandleGroupgoCommand(const char* args)
2239 if(!*args)
2240 return false;
2242 std::string name = extractPlayerNameFromLink((char*)args);
2243 if(name.empty())
2245 SendSysMessage(LANG_PLAYER_NOT_FOUND);
2246 SetSentErrorMessage(true);
2247 return false;
2250 Player *player = objmgr.GetPlayer(name.c_str());
2251 if (!player)
2253 PSendSysMessage(LANG_NO_PLAYER, args);
2254 SetSentErrorMessage(true);
2255 return false;
2258 // check online security
2259 if (HasLowerSecurity(player, 0))
2260 return false;
2262 Group *grp = player->GetGroup();
2264 std::string nameLink = playerLink(name);
2266 if(!grp)
2268 PSendSysMessage(LANG_NOT_IN_GROUP,nameLink.c_str());
2269 SetSentErrorMessage(true);
2270 return false;
2273 Map* gmMap = m_session->GetPlayer()->GetMap();
2274 bool to_instance = gmMap->Instanceable();
2276 // we are in instance, and can summon only player in our group with us as lead
2277 if ( to_instance && (
2278 !m_session->GetPlayer()->GetGroup() || (grp->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ||
2279 (m_session->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ) )
2280 // the last check is a bit excessive, but let it be, just in case
2282 SendSysMessage(LANG_CANNOT_SUMMON_TO_INST);
2283 SetSentErrorMessage(true);
2284 return false;
2287 for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
2289 Player *pl = itr->getSource();
2291 if(!pl || pl==m_session->GetPlayer() || !pl->GetSession() )
2292 continue;
2294 // check online security
2295 if (HasLowerSecurity(pl, 0))
2296 return false;
2298 std::string plNameLink = playerLink(name);
2300 if(pl->IsBeingTeleported()==true)
2302 PSendSysMessage(LANG_IS_TELEPORTED, plNameLink.c_str());
2303 SetSentErrorMessage(true);
2304 return false;
2307 if (to_instance)
2309 Map* plMap = pl->GetMap();
2311 if ( plMap->Instanceable() && plMap->GetInstanceId() != gmMap->GetInstanceId() )
2313 // cannot summon from instance to instance
2314 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,plNameLink.c_str());
2315 SetSentErrorMessage(true);
2316 return false;
2320 PSendSysMessage(LANG_SUMMONING, plNameLink.c_str(),"");
2321 if (needReportToTarget(pl))
2322 ChatHandler(pl).PSendSysMessage(LANG_SUMMONED_BY, nameLink.c_str());
2324 // stop flight if need
2325 if(pl->isInFlight())
2327 pl->GetMotionMaster()->MovementExpired();
2328 pl->m_taxi.ClearTaxiDestinations();
2330 // save only in non-flight case
2331 else
2332 pl->SaveRecallPosition();
2334 // before GM
2335 float x,y,z;
2336 m_session->GetPlayer()->GetClosePoint(x,y,z,pl->GetObjectSize());
2337 pl->TeleportTo(m_session->GetPlayer()->GetMapId(),x,y,z,pl->GetOrientation());
2340 return true;
2343 //teleport at coordinates
2344 bool ChatHandler::HandleGoXYCommand(const char* args)
2346 if(!*args)
2347 return false;
2349 Player* _player = m_session->GetPlayer();
2351 char* px = strtok((char*)args, " ");
2352 char* py = strtok(NULL, " ");
2353 char* pmapid = strtok(NULL, " ");
2355 if (!px || !py)
2356 return false;
2358 float x = (float)atof(px);
2359 float y = (float)atof(py);
2360 uint32 mapid;
2361 if (pmapid)
2362 mapid = (uint32)atoi(pmapid);
2363 else mapid = _player->GetMapId();
2365 if(!MapManager::IsValidMapCoord(mapid,x,y))
2367 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
2368 SetSentErrorMessage(true);
2369 return false;
2372 // stop flight if need
2373 if(_player->isInFlight())
2375 _player->GetMotionMaster()->MovementExpired();
2376 _player->m_taxi.ClearTaxiDestinations();
2378 // save only in non-flight case
2379 else
2380 _player->SaveRecallPosition();
2382 Map const *map = MapManager::Instance().GetBaseMap(mapid);
2383 float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
2385 _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
2387 return true;
2390 //teleport at coordinates, including Z
2391 bool ChatHandler::HandleGoXYZCommand(const char* args)
2393 if(!*args)
2394 return false;
2396 Player* _player = m_session->GetPlayer();
2398 char* px = strtok((char*)args, " ");
2399 char* py = strtok(NULL, " ");
2400 char* pz = strtok(NULL, " ");
2401 char* pmapid = strtok(NULL, " ");
2403 if (!px || !py || !pz)
2404 return false;
2406 float x = (float)atof(px);
2407 float y = (float)atof(py);
2408 float z = (float)atof(pz);
2409 uint32 mapid;
2410 if (pmapid)
2411 mapid = (uint32)atoi(pmapid);
2412 else
2413 mapid = _player->GetMapId();
2415 if(!MapManager::IsValidMapCoord(mapid,x,y,z))
2417 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
2418 SetSentErrorMessage(true);
2419 return false;
2422 // stop flight if need
2423 if(_player->isInFlight())
2425 _player->GetMotionMaster()->MovementExpired();
2426 _player->m_taxi.ClearTaxiDestinations();
2428 // save only in non-flight case
2429 else
2430 _player->SaveRecallPosition();
2432 _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
2434 return true;
2437 //teleport at coordinates
2438 bool ChatHandler::HandleGoZoneXYCommand(const char* args)
2440 if(!*args)
2441 return false;
2443 Player* _player = m_session->GetPlayer();
2445 char* px = strtok((char*)args, " ");
2446 char* py = strtok(NULL, " ");
2447 char* tail = strtok(NULL,"");
2449 char* cAreaId = extractKeyFromLink(tail,"Harea"); // string or [name] Shift-click form |color|Harea:area_id|h[name]|h|r
2451 if (!px || !py)
2452 return false;
2454 float x = (float)atof(px);
2455 float y = (float)atof(py);
2456 uint32 areaid = cAreaId ? (uint32)atoi(cAreaId) : _player->GetZoneId();
2458 AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(areaid);
2460 if( x<0 || x>100 || y<0 || y>100 || !areaEntry )
2462 PSendSysMessage(LANG_INVALID_ZONE_COORD,x,y,areaid);
2463 SetSentErrorMessage(true);
2464 return false;
2467 // update to parent zone if exist (client map show only zones without parents)
2468 AreaTableEntry const* zoneEntry = areaEntry->zone ? GetAreaEntryByAreaID(areaEntry->zone) : areaEntry;
2470 Map const *map = MapManager::Instance().GetBaseMap(zoneEntry->mapid);
2472 if(map->Instanceable())
2474 PSendSysMessage(LANG_INVALID_ZONE_MAP,areaEntry->ID,areaEntry->area_name[m_session->GetSessionDbcLocale()],map->GetId(),map->GetMapName());
2475 SetSentErrorMessage(true);
2476 return false;
2479 Zone2MapCoordinates(x,y,zoneEntry->ID);
2481 if(!MapManager::IsValidMapCoord(zoneEntry->mapid,x,y))
2483 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,zoneEntry->mapid);
2484 SetSentErrorMessage(true);
2485 return false;
2488 // stop flight if need
2489 if(_player->isInFlight())
2491 _player->GetMotionMaster()->MovementExpired();
2492 _player->m_taxi.ClearTaxiDestinations();
2494 // save only in non-flight case
2495 else
2496 _player->SaveRecallPosition();
2498 float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
2499 _player->TeleportTo(zoneEntry->mapid, x, y, z, _player->GetOrientation());
2501 return true;
2504 //teleport to grid
2505 bool ChatHandler::HandleGoGridCommand(const char* args)
2507 if(!*args) return false;
2508 Player* _player = m_session->GetPlayer();
2510 char* px = strtok((char*)args, " ");
2511 char* py = strtok(NULL, " ");
2512 char* pmapid = strtok(NULL, " ");
2514 if (!px || !py)
2515 return false;
2517 float grid_x = (float)atof(px);
2518 float grid_y = (float)atof(py);
2519 uint32 mapid;
2520 if (pmapid)
2521 mapid = (uint32)atoi(pmapid);
2522 else mapid = _player->GetMapId();
2524 // center of grid
2525 float x = (grid_x-CENTER_GRID_ID+0.5f)*SIZE_OF_GRIDS;
2526 float y = (grid_y-CENTER_GRID_ID+0.5f)*SIZE_OF_GRIDS;
2528 if(!MapManager::IsValidMapCoord(mapid,x,y))
2530 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
2531 SetSentErrorMessage(true);
2532 return false;
2535 // stop flight if need
2536 if(_player->isInFlight())
2538 _player->GetMotionMaster()->MovementExpired();
2539 _player->m_taxi.ClearTaxiDestinations();
2541 // save only in non-flight case
2542 else
2543 _player->SaveRecallPosition();
2545 Map const *map = MapManager::Instance().GetBaseMap(mapid);
2546 float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
2547 _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
2549 return true;
2552 bool ChatHandler::HandleDrunkCommand(const char* args)
2554 if(!*args) return false;
2556 uint32 drunklevel = (uint32)atoi(args);
2557 if(drunklevel > 100)
2558 drunklevel = 100;
2560 uint16 drunkMod = drunklevel * 0xFFFF / 100;
2562 m_session->GetPlayer()->SetDrunkValue(drunkMod);
2564 return true;