[7893] Fixed work chat guild commands that expect guild name in args. Now guild name...
[getmangos.git] / src / game / Level1.cpp
blob35f1b59f46047c87163a2f8ab26360881d6fd060
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[GetSessionDbcLocale()] : "<unknown>" ),
313 zone_id, (zoneEntry ? zoneEntry->area_name[GetSessionDbcLocale()] : "<unknown>" ),
314 area_id, (areaEntry ? areaEntry->area_name[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 Player* target;
347 uint64 target_guid;
348 std::string target_name;
349 if (!extractPlayerTarget((char*)args,&target,&target_guid,&target_name))
350 return false;
352 Player* _player = m_session->GetPlayer();
353 if (target == _player || target_guid == _player->GetGUID())
355 PSendSysMessage(LANG_CANT_TELEPORT_SELF);
356 SetSentErrorMessage(true);
357 return false;
360 if (target)
362 std::string nameLink = playerLink(target_name);
363 // check online security
364 if (HasLowerSecurity(target, 0))
365 return false;
367 if (target->IsBeingTeleported())
369 PSendSysMessage(LANG_IS_TELEPORTED, nameLink.c_str());
370 SetSentErrorMessage(true);
371 return false;
374 Map* pMap = m_session->GetPlayer()->GetMap();
376 if (pMap->IsBattleGroundOrArena())
378 // only allow if gm mode is on
379 if (!target->isGameMaster())
381 PSendSysMessage(LANG_CANNOT_GO_TO_BG_GM,nameLink.c_str());
382 SetSentErrorMessage(true);
383 return false;
385 // if both players are in different bgs
386 else if (target->GetBattleGroundId() && m_session->GetPlayer()->GetBattleGroundId() != target->GetBattleGroundId())
388 PSendSysMessage(LANG_CANNOT_GO_TO_BG_FROM_BG,nameLink.c_str());
389 SetSentErrorMessage(true);
390 return false;
392 // all's well, set bg id
393 // when porting out from the bg, it will be reset to 0
394 target->SetBattleGroundId(m_session->GetPlayer()->GetBattleGroundId(), m_session->GetPlayer()->GetBattleGroundTypeId());
395 // remember current position as entry point for return at bg end teleportation
396 target->SetBattleGroundEntryPoint(target->GetMapId(),target->GetPositionX(),target->GetPositionY(),target->GetPositionZ(),target->GetOrientation());
398 else if (pMap->IsDungeon())
400 Map* cMap = target->GetMap();
401 if (cMap->Instanceable() && cMap->GetInstanceId() != pMap->GetInstanceId())
403 // cannot summon from instance to instance
404 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,nameLink.c_str());
405 SetSentErrorMessage(true);
406 return false;
409 // we are in instance, and can summon only player in our group with us as lead
410 if (!m_session->GetPlayer()->GetGroup() || !target->GetGroup() ||
411 (target->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ||
412 (m_session->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()))
413 // the last check is a bit excessive, but let it be, just in case
415 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,nameLink.c_str());
416 SetSentErrorMessage(true);
417 return false;
421 PSendSysMessage(LANG_SUMMONING, nameLink.c_str(),"");
422 if (needReportToTarget(target))
423 ChatHandler(target).PSendSysMessage(LANG_SUMMONED_BY, nameLink.c_str());
425 // stop flight if need
426 if (target->isInFlight())
428 target->GetMotionMaster()->MovementExpired();
429 target->m_taxi.ClearTaxiDestinations();
431 // save only in non-flight case
432 else
433 target->SaveRecallPosition();
435 // before GM
436 float x,y,z;
437 m_session->GetPlayer()->GetClosePoint(x,y,z,target->GetObjectSize());
438 target->TeleportTo(m_session->GetPlayer()->GetMapId(),x,y,z,target->GetOrientation());
440 else
442 // check offline security
443 if (HasLowerSecurity(NULL, target_guid))
444 return false;
446 std::string nameLink = playerLink(target_name);
448 PSendSysMessage(LANG_SUMMONING, nameLink.c_str(),GetMangosString(LANG_OFFLINE));
450 // in point where GM stay
451 Player::SavePositionInDB(m_session->GetPlayer()->GetMapId(),
452 m_session->GetPlayer()->GetPositionX(),
453 m_session->GetPlayer()->GetPositionY(),
454 m_session->GetPlayer()->GetPositionZ(),
455 m_session->GetPlayer()->GetOrientation(),
456 m_session->GetPlayer()->GetZoneId(),
457 target_guid);
460 return true;
463 //Teleport to Player
464 bool ChatHandler::HandleGonameCommand(const char* args)
466 Player* target;
467 uint64 target_guid;
468 std::string target_name;
469 if (!extractPlayerTarget((char*)args,&target,&target_guid,&target_name))
470 return false;
472 Player* _player = m_session->GetPlayer();
473 if (target == _player || target_guid == _player->GetGUID())
475 SendSysMessage(LANG_CANT_TELEPORT_SELF);
476 SetSentErrorMessage(true);
477 return false;
481 if (target)
483 // check online security
484 if (HasLowerSecurity(target, 0))
485 return false;
487 std::string chrNameLink = playerLink(target_name);
489 Map* cMap = target->GetMap();
490 if (cMap->IsBattleGroundOrArena())
492 // only allow if gm mode is on
493 if (!_player->isGameMaster())
495 PSendSysMessage(LANG_CANNOT_GO_TO_BG_GM,chrNameLink.c_str());
496 SetSentErrorMessage(true);
497 return false;
499 // if both players are in different bgs
500 else if (_player->GetBattleGroundId() && _player->GetBattleGroundId() != target->GetBattleGroundId())
502 PSendSysMessage(LANG_CANNOT_GO_TO_BG_FROM_BG,chrNameLink.c_str());
503 SetSentErrorMessage(true);
504 return false;
506 // all's well, set bg id
507 // when porting out from the bg, it will be reset to 0
508 _player->SetBattleGroundId(target->GetBattleGroundId(), target->GetBattleGroundTypeId());
509 // remember current position as entry point for return at bg end teleportation
510 _player->SetBattleGroundEntryPoint(_player->GetMapId(),_player->GetPositionX(),_player->GetPositionY(),_player->GetPositionZ(),_player->GetOrientation());
512 else if(cMap->IsDungeon())
514 // we have to go to instance, and can go to player only if:
515 // 1) we are in his group (either as leader or as member)
516 // 2) we are not bound to any group and have GM mode on
517 if (_player->GetGroup())
519 // we are in group, we can go only if we are in the player group
520 if (_player->GetGroup() != target->GetGroup())
522 PSendSysMessage(LANG_CANNOT_GO_TO_INST_PARTY,chrNameLink.c_str());
523 SetSentErrorMessage(true);
524 return false;
527 else
529 // we are not in group, let's verify our GM mode
530 if (!_player->isGameMaster())
532 PSendSysMessage(LANG_CANNOT_GO_TO_INST_GM,chrNameLink.c_str());
533 SetSentErrorMessage(true);
534 return false;
538 // if the player or the player's group is bound to another instance
539 // the player will not be bound to another one
540 InstancePlayerBind *pBind = _player->GetBoundInstance(target->GetMapId(), target->GetDifficulty());
541 if (!pBind)
543 Group *group = _player->GetGroup();
544 // if no bind exists, create a solo bind
545 InstanceGroupBind *gBind = group ? group->GetBoundInstance(target->GetMapId(), target->GetDifficulty()) : NULL;
546 // if no bind exists, create a solo bind
547 if (!gBind)
548 if (InstanceSave *save = sInstanceSaveManager.GetInstanceSave(target->GetInstanceId()))
549 _player->BindToInstance(save, !save->CanReset());
552 _player->SetDifficulty(target->GetDifficulty());
555 PSendSysMessage(LANG_APPEARING_AT, chrNameLink.c_str());
556 if (needReportToTarget(target))
557 ChatHandler(target).PSendSysMessage(LANG_APPEARING_TO, GetNameLink().c_str());
559 // stop flight if need
560 if (_player->isInFlight())
562 _player->GetMotionMaster()->MovementExpired();
563 _player->m_taxi.ClearTaxiDestinations();
565 // save only in non-flight case
566 else
567 _player->SaveRecallPosition();
569 // to point to see at target with same orientation
570 float x,y,z;
571 target->GetContactPoint(_player,x,y,z);
573 _player->TeleportTo(target->GetMapId(), x, y, z, _player->GetAngle(target), TELE_TO_GM_MODE);
575 else
577 // check offline security
578 if (HasLowerSecurity(NULL, target_guid))
579 return false;
581 std::string nameLink = playerLink(target_name);
583 PSendSysMessage(LANG_APPEARING_AT, nameLink.c_str());
585 // to point where player stay (if loaded)
586 float x,y,z,o;
587 uint32 map;
588 bool in_flight;
589 if (!Player::LoadPositionFromDB(map,x,y,z,o,in_flight,target_guid))
590 return false;
592 // stop flight if need
593 if (_player->isInFlight())
595 _player->GetMotionMaster()->MovementExpired();
596 _player->m_taxi.ClearTaxiDestinations();
598 // save only in non-flight case
599 else
600 _player->SaveRecallPosition();
602 _player->TeleportTo(map, x, y, z,_player->GetOrientation());
605 return true;
608 // Teleport player to last position
609 bool ChatHandler::HandleRecallCommand(const char* args)
611 Player* target;
612 if(!extractPlayerTarget((char*)args,&target))
613 return false;
615 // check online security
616 if (HasLowerSecurity(target, 0))
617 return false;
619 if (target->IsBeingTeleported())
621 PSendSysMessage(LANG_IS_TELEPORTED, GetNameLink(target).c_str());
622 SetSentErrorMessage(true);
623 return false;
626 // stop flight if need
627 if(target->isInFlight())
629 target->GetMotionMaster()->MovementExpired();
630 target->m_taxi.ClearTaxiDestinations();
633 target->TeleportTo(target->m_recallMap, target->m_recallX, target->m_recallY, target->m_recallZ, target->m_recallO);
634 return true;
637 //Edit Player KnownTitles
638 bool ChatHandler::HandleModifyKnownTitlesCommand(const char* args)
640 if(!*args)
641 return false;
643 uint64 titles = 0;
645 sscanf((char*)args, I64FMTD, &titles);
647 Player *chr = getSelectedPlayer();
648 if (!chr)
650 SendSysMessage(LANG_NO_CHAR_SELECTED);
651 SetSentErrorMessage(true);
652 return false;
655 // check online security
656 if (HasLowerSecurity(chr, 0))
657 return false;
659 uint64 titles2 = titles;
661 for(int i=1; i < sCharTitlesStore.GetNumRows(); ++i)
662 if(CharTitlesEntry const* tEntry = sCharTitlesStore.LookupEntry(i))
663 titles2 &= ~(uint64(1) << tEntry->bit_index);
665 titles &= ~titles2; // remove not existed titles
667 chr->SetUInt64Value(PLAYER__FIELD_KNOWN_TITLES, titles);
668 SendSysMessage(LANG_DONE);
670 return true;
673 //Edit Player HP
674 bool ChatHandler::HandleModifyHPCommand(const char* args)
676 if(!*args)
677 return false;
679 // char* pHp = strtok((char*)args, " ");
680 // if (!pHp)
681 // return false;
683 // char* pHpMax = strtok(NULL, " ");
684 // if (!pHpMax)
685 // return false;
687 // int32 hpm = atoi(pHpMax);
688 // int32 hp = atoi(pHp);
690 int32 hp = atoi((char*)args);
691 int32 hpm = atoi((char*)args);
693 if (hp <= 0 || hpm <= 0 || hpm < hp)
695 SendSysMessage(LANG_BAD_VALUE);
696 SetSentErrorMessage(true);
697 return false;
700 Player *chr = getSelectedPlayer();
701 if (chr == NULL)
703 SendSysMessage(LANG_NO_CHAR_SELECTED);
704 SetSentErrorMessage(true);
705 return false;
708 // check online security
709 if (HasLowerSecurity(chr, 0))
710 return false;
712 PSendSysMessage(LANG_YOU_CHANGE_HP, GetNameLink(chr).c_str(), hp, hpm);
713 if (needReportToTarget(chr))
714 ChatHandler(chr).PSendSysMessage(LANG_YOURS_HP_CHANGED, GetNameLink().c_str(), hp, hpm);
716 chr->SetMaxHealth( hpm );
717 chr->SetHealth( hp );
719 return true;
722 //Edit Player Mana
723 bool ChatHandler::HandleModifyManaCommand(const char* args)
725 if(!*args)
726 return false;
728 // char* pmana = strtok((char*)args, " ");
729 // if (!pmana)
730 // return false;
732 // char* pmanaMax = strtok(NULL, " ");
733 // if (!pmanaMax)
734 // return false;
736 // int32 manam = atoi(pmanaMax);
737 // int32 mana = atoi(pmana);
738 int32 mana = atoi((char*)args);
739 int32 manam = atoi((char*)args);
741 if (mana <= 0 || manam <= 0 || manam < mana)
743 SendSysMessage(LANG_BAD_VALUE);
744 SetSentErrorMessage(true);
745 return false;
748 Player *chr = getSelectedPlayer();
749 if (chr == NULL)
751 SendSysMessage(LANG_NO_CHAR_SELECTED);
752 SetSentErrorMessage(true);
753 return false;
756 // check online security
757 if (HasLowerSecurity(chr, 0))
758 return false;
760 PSendSysMessage(LANG_YOU_CHANGE_MANA, GetNameLink(chr).c_str(), mana, manam);
761 if (needReportToTarget(chr))
762 ChatHandler(chr).PSendSysMessage(LANG_YOURS_MANA_CHANGED, GetNameLink().c_str(), mana, manam);
764 chr->SetMaxPower(POWER_MANA,manam );
765 chr->SetPower(POWER_MANA, mana );
767 return true;
770 //Edit Player Energy
771 bool ChatHandler::HandleModifyEnergyCommand(const char* args)
773 if(!*args)
774 return false;
776 // char* pmana = strtok((char*)args, " ");
777 // if (!pmana)
778 // return false;
780 // char* pmanaMax = strtok(NULL, " ");
781 // if (!pmanaMax)
782 // return false;
784 // int32 manam = atoi(pmanaMax);
785 // int32 mana = atoi(pmana);
787 int32 energy = atoi((char*)args)*10;
788 int32 energym = atoi((char*)args)*10;
790 if (energy <= 0 || energym <= 0 || energym < energy)
792 SendSysMessage(LANG_BAD_VALUE);
793 SetSentErrorMessage(true);
794 return false;
797 Player *chr = getSelectedPlayer();
798 if (!chr)
800 SendSysMessage(LANG_NO_CHAR_SELECTED);
801 SetSentErrorMessage(true);
802 return false;
805 // check online security
806 if (HasLowerSecurity(chr, 0))
807 return false;
809 PSendSysMessage(LANG_YOU_CHANGE_ENERGY, GetNameLink(chr).c_str(), energy/10, energym/10);
810 if (needReportToTarget(chr))
811 ChatHandler(chr).PSendSysMessage(LANG_YOURS_ENERGY_CHANGED, GetNameLink().c_str(), energy/10, energym/10);
813 chr->SetMaxPower(POWER_ENERGY,energym );
814 chr->SetPower(POWER_ENERGY, energy );
816 sLog.outDetail(GetMangosString(LANG_CURRENT_ENERGY),chr->GetMaxPower(POWER_ENERGY));
818 return true;
821 //Edit Player Rage
822 bool ChatHandler::HandleModifyRageCommand(const char* args)
824 if(!*args)
825 return false;
827 // char* pmana = strtok((char*)args, " ");
828 // if (!pmana)
829 // return false;
831 // char* pmanaMax = strtok(NULL, " ");
832 // if (!pmanaMax)
833 // return false;
835 // int32 manam = atoi(pmanaMax);
836 // int32 mana = atoi(pmana);
838 int32 rage = atoi((char*)args)*10;
839 int32 ragem = atoi((char*)args)*10;
841 if (rage <= 0 || ragem <= 0 || ragem < rage)
843 SendSysMessage(LANG_BAD_VALUE);
844 SetSentErrorMessage(true);
845 return false;
848 Player *chr = getSelectedPlayer();
849 if (chr == NULL)
851 SendSysMessage(LANG_NO_CHAR_SELECTED);
852 SetSentErrorMessage(true);
853 return false;
856 // check online security
857 if (HasLowerSecurity(chr, 0))
858 return false;
860 PSendSysMessage(LANG_YOU_CHANGE_RAGE, GetNameLink(chr).c_str(), rage/10, ragem/10);
861 if (needReportToTarget(chr))
862 ChatHandler(chr).PSendSysMessage(LANG_YOURS_RAGE_CHANGED, GetNameLink().c_str(), rage/10, ragem/10);
864 chr->SetMaxPower(POWER_RAGE,ragem );
865 chr->SetPower(POWER_RAGE, rage );
867 return true;
870 // Edit Player Runic Power
871 bool ChatHandler::HandleModifyRunicPowerCommand(const char* args)
873 if(!*args)
874 return false;
876 int32 rune = atoi((char*)args)*10;
877 int32 runem = atoi((char*)args)*10;
879 if (rune <= 0 || runem <= 0 || runem < rune)
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 PSendSysMessage(LANG_YOU_CHANGE_RUNIC_POWER, GetNameLink(chr).c_str(), rune/10, runem/10);
895 if (needReportToTarget(chr))
896 ChatHandler(chr).PSendSysMessage(LANG_YOURS_RUNIC_POWER_CHANGED, GetNameLink().c_str(), rune/10, runem/10);
898 chr->SetMaxPower(POWER_RUNIC_POWER,runem );
899 chr->SetPower(POWER_RUNIC_POWER, rune );
901 return true;
904 //Edit Player Faction
905 bool ChatHandler::HandleModifyFactionCommand(const char* args)
907 if(!*args)
908 return false;
910 char* pfactionid = extractKeyFromLink((char*)args,"Hfaction");
912 Creature* chr = getSelectedCreature();
913 if(!chr)
915 SendSysMessage(LANG_SELECT_CREATURE);
916 SetSentErrorMessage(true);
917 return false;
920 if(!pfactionid)
922 if(chr)
924 uint32 factionid = chr->getFaction();
925 uint32 flag = chr->GetUInt32Value(UNIT_FIELD_FLAGS);
926 uint32 npcflag = chr->GetUInt32Value(UNIT_NPC_FLAGS);
927 uint32 dyflag = chr->GetUInt32Value(UNIT_DYNAMIC_FLAGS);
928 PSendSysMessage(LANG_CURRENT_FACTION,chr->GetGUIDLow(),factionid,flag,npcflag,dyflag);
930 return true;
933 if( !chr )
935 SendSysMessage(LANG_NO_CHAR_SELECTED);
936 SetSentErrorMessage(true);
937 return false;
940 uint32 factionid = atoi(pfactionid);
941 uint32 flag;
943 char *pflag = strtok(NULL, " ");
944 if (!pflag)
945 flag = chr->GetUInt32Value(UNIT_FIELD_FLAGS);
946 else
947 flag = atoi(pflag);
949 char* pnpcflag = strtok(NULL, " ");
951 uint32 npcflag;
952 if(!pnpcflag)
953 npcflag = chr->GetUInt32Value(UNIT_NPC_FLAGS);
954 else
955 npcflag = atoi(pnpcflag);
957 char* pdyflag = strtok(NULL, " ");
959 uint32 dyflag;
960 if(!pdyflag)
961 dyflag = chr->GetUInt32Value(UNIT_DYNAMIC_FLAGS);
962 else
963 dyflag = atoi(pdyflag);
965 if(!sFactionTemplateStore.LookupEntry(factionid))
967 PSendSysMessage(LANG_WRONG_FACTION, factionid);
968 SetSentErrorMessage(true);
969 return false;
972 PSendSysMessage(LANG_YOU_CHANGE_FACTION, chr->GetGUIDLow(),factionid,flag,npcflag,dyflag);
974 chr->setFaction(factionid);
975 chr->SetUInt32Value(UNIT_FIELD_FLAGS,flag);
976 chr->SetUInt32Value(UNIT_NPC_FLAGS,npcflag);
977 chr->SetUInt32Value(UNIT_DYNAMIC_FLAGS,dyflag);
979 return true;
982 //Edit Player Spell
983 bool ChatHandler::HandleModifySpellCommand(const char* args)
985 if(!*args) return false;
986 char* pspellflatid = strtok((char*)args, " ");
987 if (!pspellflatid)
988 return false;
990 char* pop = strtok(NULL, " ");
991 if (!pop)
992 return false;
994 char* pval = strtok(NULL, " ");
995 if (!pval)
996 return false;
998 uint16 mark;
1000 char* pmark = strtok(NULL, " ");
1002 uint8 spellflatid = atoi(pspellflatid);
1003 uint8 op = atoi(pop);
1004 uint16 val = atoi(pval);
1005 if(!pmark)
1006 mark = 65535;
1007 else
1008 mark = atoi(pmark);
1010 Player *chr = getSelectedPlayer();
1011 if (chr == NULL)
1013 SendSysMessage(LANG_NO_CHAR_SELECTED);
1014 SetSentErrorMessage(true);
1015 return false;
1018 // check online security
1019 if (HasLowerSecurity(chr, 0))
1020 return false;
1022 PSendSysMessage(LANG_YOU_CHANGE_SPELLFLATID, spellflatid, val, mark, GetNameLink(chr).c_str());
1023 if (needReportToTarget(chr))
1024 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SPELLFLATID_CHANGED, GetNameLink().c_str(), spellflatid, val, mark);
1026 WorldPacket data(SMSG_SET_FLAT_SPELL_MODIFIER, (1+1+2+2));
1027 data << uint8(spellflatid);
1028 data << uint8(op);
1029 data << uint16(val);
1030 data << uint16(mark);
1031 chr->GetSession()->SendPacket(&data);
1033 return true;
1036 //Edit Player TP
1037 bool ChatHandler::HandleModifyTalentCommand (const char* args)
1039 if (!*args)
1040 return false;
1042 int tp = atoi((char*)args);
1043 if (tp>0)
1045 Player* player = getSelectedPlayer();
1046 if(!player)
1048 SendSysMessage(LANG_NO_CHAR_SELECTED);
1049 SetSentErrorMessage(true);
1050 return false;
1053 // check online security
1054 if (HasLowerSecurity(player, 0))
1055 return false;
1057 player->SetFreeTalentPoints(tp);
1058 return true;
1060 return false;
1063 //Enable On\OFF all taxi paths
1064 bool ChatHandler::HandleTaxiCheatCommand(const char* args)
1066 if (!*args)
1068 SendSysMessage(LANG_USE_BOL);
1069 SetSentErrorMessage(true);
1070 return false;
1073 std::string argstr = (char*)args;
1075 Player *chr = getSelectedPlayer();
1076 if (!chr)
1078 chr=m_session->GetPlayer();
1081 // check online security
1082 else if (HasLowerSecurity(chr, 0))
1083 return false;
1085 if (argstr == "on")
1087 chr->SetTaxiCheater(true);
1088 PSendSysMessage(LANG_YOU_GIVE_TAXIS, GetNameLink(chr).c_str());
1089 if (needReportToTarget(chr))
1090 ChatHandler(chr).PSendSysMessage(LANG_YOURS_TAXIS_ADDED, GetNameLink().c_str());
1091 return true;
1094 if (argstr == "off")
1096 chr->SetTaxiCheater(false);
1097 PSendSysMessage(LANG_YOU_REMOVE_TAXIS, GetNameLink(chr).c_str());
1098 if (needReportToTarget(chr))
1099 ChatHandler(chr).PSendSysMessage(LANG_YOURS_TAXIS_REMOVED, GetNameLink().c_str());
1101 return true;
1104 SendSysMessage(LANG_USE_BOL);
1105 SetSentErrorMessage(true);
1106 return false;
1109 //Edit Player Aspeed
1110 bool ChatHandler::HandleModifyASpeedCommand(const char* args)
1112 if (!*args)
1113 return false;
1115 float ASpeed = (float)atof((char*)args);
1117 if (ASpeed > 10 || ASpeed < 0.1)
1119 SendSysMessage(LANG_BAD_VALUE);
1120 SetSentErrorMessage(true);
1121 return false;
1124 Player *chr = getSelectedPlayer();
1125 if (chr == NULL)
1127 SendSysMessage(LANG_NO_CHAR_SELECTED);
1128 SetSentErrorMessage(true);
1129 return false;
1132 // check online security
1133 if (HasLowerSecurity(chr, 0))
1134 return false;
1136 std::string chrNameLink = GetNameLink(chr);
1138 if(chr->isInFlight())
1140 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chrNameLink.c_str());
1141 SetSentErrorMessage(true);
1142 return false;
1145 PSendSysMessage(LANG_YOU_CHANGE_ASPEED, ASpeed, chrNameLink.c_str());
1146 if (needReportToTarget(chr))
1147 ChatHandler(chr).PSendSysMessage(LANG_YOURS_ASPEED_CHANGED, GetNameLink().c_str(), ASpeed);
1149 chr->SetSpeed(MOVE_WALK, ASpeed,true);
1150 chr->SetSpeed(MOVE_RUN, ASpeed,true);
1151 chr->SetSpeed(MOVE_SWIM, ASpeed,true);
1152 //chr->SetSpeed(MOVE_TURN, ASpeed,true);
1153 chr->SetSpeed(MOVE_FLIGHT, ASpeed,true);
1154 return true;
1157 //Edit Player Speed
1158 bool ChatHandler::HandleModifySpeedCommand(const char* args)
1160 if (!*args)
1161 return false;
1163 float Speed = (float)atof((char*)args);
1165 if (Speed > 10 || Speed < 0.1)
1167 SendSysMessage(LANG_BAD_VALUE);
1168 SetSentErrorMessage(true);
1169 return false;
1172 Player *chr = getSelectedPlayer();
1173 if (chr == NULL)
1175 SendSysMessage(LANG_NO_CHAR_SELECTED);
1176 SetSentErrorMessage(true);
1177 return false;
1180 // check online security
1181 if (HasLowerSecurity(chr, 0))
1182 return false;
1184 std::string chrNameLink = GetNameLink(chr);
1186 if(chr->isInFlight())
1188 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chrNameLink.c_str());
1189 SetSentErrorMessage(true);
1190 return false;
1193 PSendSysMessage(LANG_YOU_CHANGE_SPEED, Speed, chrNameLink.c_str());
1194 if (needReportToTarget(chr))
1195 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SPEED_CHANGED, GetNameLink().c_str(), Speed);
1197 chr->SetSpeed(MOVE_RUN,Speed,true);
1199 return true;
1202 //Edit Player Swim Speed
1203 bool ChatHandler::HandleModifySwimCommand(const char* args)
1205 if (!*args)
1206 return false;
1208 float Swim = (float)atof((char*)args);
1210 if (Swim > 10.0f || Swim < 0.01f)
1212 SendSysMessage(LANG_BAD_VALUE);
1213 SetSentErrorMessage(true);
1214 return false;
1217 Player *chr = getSelectedPlayer();
1218 if (chr == NULL)
1220 SendSysMessage(LANG_NO_CHAR_SELECTED);
1221 SetSentErrorMessage(true);
1222 return false;
1225 // check online security
1226 if (HasLowerSecurity(chr, 0))
1227 return false;
1229 std::string chrNameLink = GetNameLink(chr);
1231 if(chr->isInFlight())
1233 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chrNameLink.c_str());
1234 SetSentErrorMessage(true);
1235 return false;
1238 PSendSysMessage(LANG_YOU_CHANGE_SWIM_SPEED, Swim, chrNameLink.c_str());
1239 if (needReportToTarget(chr))
1240 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SWIM_SPEED_CHANGED, GetNameLink().c_str(), Swim);
1242 chr->SetSpeed(MOVE_SWIM,Swim,true);
1244 return true;
1247 //Edit Player Walk Speed
1248 bool ChatHandler::HandleModifyBWalkCommand(const char* args)
1250 if (!*args)
1251 return false;
1253 float BSpeed = (float)atof((char*)args);
1255 if (BSpeed > 10.0f || BSpeed < 0.1f)
1257 SendSysMessage(LANG_BAD_VALUE);
1258 SetSentErrorMessage(true);
1259 return false;
1262 Player *chr = getSelectedPlayer();
1263 if (chr == NULL)
1265 SendSysMessage(LANG_NO_CHAR_SELECTED);
1266 SetSentErrorMessage(true);
1267 return false;
1270 // check online security
1271 if (HasLowerSecurity(chr, 0))
1272 return false;
1274 std::string chrNameLink = GetNameLink(chr);
1276 if(chr->isInFlight())
1278 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chrNameLink.c_str());
1279 SetSentErrorMessage(true);
1280 return false;
1283 PSendSysMessage(LANG_YOU_CHANGE_BACK_SPEED, BSpeed, chrNameLink.c_str());
1284 if (needReportToTarget(chr))
1285 ChatHandler(chr).PSendSysMessage(LANG_YOURS_BACK_SPEED_CHANGED, GetNameLink().c_str(), BSpeed);
1287 chr->SetSpeed(MOVE_RUN_BACK,BSpeed,true);
1289 return true;
1292 //Edit Player Fly
1293 bool ChatHandler::HandleModifyFlyCommand(const char* args)
1295 if (!*args)
1296 return false;
1298 float FSpeed = (float)atof((char*)args);
1300 if (FSpeed > 10.0f || FSpeed < 0.1f)
1302 SendSysMessage(LANG_BAD_VALUE);
1303 SetSentErrorMessage(true);
1304 return false;
1307 Player *chr = getSelectedPlayer();
1308 if (chr == NULL)
1310 SendSysMessage(LANG_NO_CHAR_SELECTED);
1311 SetSentErrorMessage(true);
1312 return false;
1315 // check online security
1316 if (HasLowerSecurity(chr, 0))
1317 return false;
1319 PSendSysMessage(LANG_YOU_CHANGE_FLY_SPEED, FSpeed, GetNameLink(chr).c_str());
1320 if (needReportToTarget(chr))
1321 ChatHandler(chr).PSendSysMessage(LANG_YOURS_FLY_SPEED_CHANGED, GetNameLink().c_str(), FSpeed);
1323 chr->SetSpeed(MOVE_FLIGHT,FSpeed,true);
1325 return true;
1328 //Edit Player Scale
1329 bool ChatHandler::HandleModifyScaleCommand(const char* args)
1331 if (!*args)
1332 return false;
1334 float Scale = (float)atof((char*)args);
1335 if (Scale > 3.0f || Scale <= 0.0f)
1337 SendSysMessage(LANG_BAD_VALUE);
1338 SetSentErrorMessage(true);
1339 return false;
1342 Player *chr = getSelectedPlayer();
1343 if (chr == NULL)
1345 SendSysMessage(LANG_NO_CHAR_SELECTED);
1346 SetSentErrorMessage(true);
1347 return false;
1350 // check online security
1351 if (HasLowerSecurity(chr, 0))
1352 return false;
1354 PSendSysMessage(LANG_YOU_CHANGE_SIZE, Scale, GetNameLink(chr).c_str());
1355 if (needReportToTarget(chr))
1356 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SIZE_CHANGED, GetNameLink().c_str(), Scale);
1358 chr->SetFloatValue(OBJECT_FIELD_SCALE_X, Scale);
1360 return true;
1363 //Enable Player mount
1364 bool ChatHandler::HandleModifyMountCommand(const char* args)
1366 if(!*args)
1367 return false;
1369 uint16 mId = 1147;
1370 float speed = (float)15;
1371 uint32 num = 0;
1373 num = atoi((char*)args);
1374 switch(num)
1376 case 1:
1377 mId=14340;
1378 break;
1379 case 2:
1380 mId=4806;
1381 break;
1382 case 3:
1383 mId=6471;
1384 break;
1385 case 4:
1386 mId=12345;
1387 break;
1388 case 5:
1389 mId=6472;
1390 break;
1391 case 6:
1392 mId=6473;
1393 break;
1394 case 7:
1395 mId=10670;
1396 break;
1397 case 8:
1398 mId=10719;
1399 break;
1400 case 9:
1401 mId=10671;
1402 break;
1403 case 10:
1404 mId=10672;
1405 break;
1406 case 11:
1407 mId=10720;
1408 break;
1409 case 12:
1410 mId=14349;
1411 break;
1412 case 13:
1413 mId=11641;
1414 break;
1415 case 14:
1416 mId=12244;
1417 break;
1418 case 15:
1419 mId=12242;
1420 break;
1421 case 16:
1422 mId=14578;
1423 break;
1424 case 17:
1425 mId=14579;
1426 break;
1427 case 18:
1428 mId=14349;
1429 break;
1430 case 19:
1431 mId=12245;
1432 break;
1433 case 20:
1434 mId=14335;
1435 break;
1436 case 21:
1437 mId=207;
1438 break;
1439 case 22:
1440 mId=2328;
1441 break;
1442 case 23:
1443 mId=2327;
1444 break;
1445 case 24:
1446 mId=2326;
1447 break;
1448 case 25:
1449 mId=14573;
1450 break;
1451 case 26:
1452 mId=14574;
1453 break;
1454 case 27:
1455 mId=14575;
1456 break;
1457 case 28:
1458 mId=604;
1459 break;
1460 case 29:
1461 mId=1166;
1462 break;
1463 case 30:
1464 mId=2402;
1465 break;
1466 case 31:
1467 mId=2410;
1468 break;
1469 case 32:
1470 mId=2409;
1471 break;
1472 case 33:
1473 mId=2408;
1474 break;
1475 case 34:
1476 mId=2405;
1477 break;
1478 case 35:
1479 mId=14337;
1480 break;
1481 case 36:
1482 mId=6569;
1483 break;
1484 case 37:
1485 mId=10661;
1486 break;
1487 case 38:
1488 mId=10666;
1489 break;
1490 case 39:
1491 mId=9473;
1492 break;
1493 case 40:
1494 mId=9476;
1495 break;
1496 case 41:
1497 mId=9474;
1498 break;
1499 case 42:
1500 mId=14374;
1501 break;
1502 case 43:
1503 mId=14376;
1504 break;
1505 case 44:
1506 mId=14377;
1507 break;
1508 case 45:
1509 mId=2404;
1510 break;
1511 case 46:
1512 mId=2784;
1513 break;
1514 case 47:
1515 mId=2787;
1516 break;
1517 case 48:
1518 mId=2785;
1519 break;
1520 case 49:
1521 mId=2736;
1522 break;
1523 case 50:
1524 mId=2786;
1525 break;
1526 case 51:
1527 mId=14347;
1528 break;
1529 case 52:
1530 mId=14346;
1531 break;
1532 case 53:
1533 mId=14576;
1534 break;
1535 case 54:
1536 mId=9695;
1537 break;
1538 case 55:
1539 mId=9991;
1540 break;
1541 case 56:
1542 mId=6448;
1543 break;
1544 case 57:
1545 mId=6444;
1546 break;
1547 case 58:
1548 mId=6080;
1549 break;
1550 case 59:
1551 mId=6447;
1552 break;
1553 case 60:
1554 mId=4805;
1555 break;
1556 case 61:
1557 mId=9714;
1558 break;
1559 case 62:
1560 mId=6448;
1561 break;
1562 case 63:
1563 mId=6442;
1564 break;
1565 case 64:
1566 mId=14632;
1567 break;
1568 case 65:
1569 mId=14332;
1570 break;
1571 case 66:
1572 mId=14331;
1573 break;
1574 case 67:
1575 mId=8469;
1576 break;
1577 case 68:
1578 mId=2830;
1579 break;
1580 case 69:
1581 mId=2346;
1582 break;
1583 default:
1584 SendSysMessage(LANG_NO_MOUNT);
1585 SetSentErrorMessage(true);
1586 return false;
1589 Player *chr = getSelectedPlayer();
1590 if (chr == NULL)
1592 SendSysMessage(LANG_NO_CHAR_SELECTED);
1593 SetSentErrorMessage(true);
1594 return false;
1597 // check online security
1598 if (HasLowerSecurity(chr, 0))
1599 return false;
1601 PSendSysMessage(LANG_YOU_GIVE_MOUNT, GetNameLink(chr).c_str());
1602 if (needReportToTarget(chr))
1603 ChatHandler(chr).PSendSysMessage(LANG_MOUNT_GIVED, GetNameLink().c_str());
1605 chr->SetUInt32Value( UNIT_FIELD_FLAGS , 0x001000 );
1606 chr->Mount(mId);
1608 WorldPacket data( SMSG_FORCE_RUN_SPEED_CHANGE, (8+4+1+4) );
1609 data.append(chr->GetPackGUID());
1610 data << (uint32)0;
1611 data << (uint8)0; //new 2.1.0
1612 data << float(speed);
1613 chr->SendMessageToSet( &data, true );
1615 data.Initialize( SMSG_FORCE_SWIM_SPEED_CHANGE, (8+4+4) );
1616 data.append(chr->GetPackGUID());
1617 data << (uint32)0;
1618 data << float(speed);
1619 chr->SendMessageToSet( &data, true );
1621 return true;
1624 //Edit Player money
1625 bool ChatHandler::HandleModifyMoneyCommand(const char* args)
1627 if (!*args)
1628 return false;
1630 Player *chr = getSelectedPlayer();
1631 if (chr == NULL)
1633 SendSysMessage(LANG_NO_CHAR_SELECTED);
1634 SetSentErrorMessage(true);
1635 return false;
1638 // check online security
1639 if (HasLowerSecurity(chr, 0))
1640 return false;
1642 int32 addmoney = atoi((char*)args);
1644 uint32 moneyuser = chr->GetMoney();
1646 if (addmoney < 0)
1648 int32 newmoney = int32(moneyuser) + addmoney;
1650 sLog.outDetail(GetMangosString(LANG_CURRENT_MONEY), moneyuser, addmoney, newmoney);
1651 if (newmoney <= 0 )
1653 PSendSysMessage(LANG_YOU_TAKE_ALL_MONEY, GetNameLink(chr).c_str());
1654 if (needReportToTarget(chr))
1655 ChatHandler(chr).PSendSysMessage(LANG_YOURS_ALL_MONEY_GONE, GetNameLink().c_str());
1657 chr->SetMoney(0);
1659 else
1661 if (newmoney > MAX_MONEY_AMOUNT)
1662 newmoney = MAX_MONEY_AMOUNT;
1664 PSendSysMessage(LANG_YOU_TAKE_MONEY, abs(addmoney), GetNameLink(chr).c_str());
1665 if (needReportToTarget(chr))
1666 ChatHandler(chr).PSendSysMessage(LANG_YOURS_MONEY_TAKEN, GetNameLink().c_str(), abs(addmoney));
1667 chr->SetMoney( newmoney );
1670 else
1672 PSendSysMessage(LANG_YOU_GIVE_MONEY, addmoney, GetNameLink(chr).c_str());
1673 if (needReportToTarget(chr))
1674 ChatHandler(chr).PSendSysMessage(LANG_YOURS_MONEY_GIVEN, GetNameLink().c_str(), addmoney);
1676 if (addmoney >=MAX_MONEY_AMOUNT)
1677 chr->SetMoney(MAX_MONEY_AMOUNT);
1678 else
1679 chr->ModifyMoney( addmoney );
1682 sLog.outDetail(GetMangosString(LANG_NEW_MONEY), moneyuser, addmoney, chr->GetMoney() );
1684 return true;
1687 //Edit Unit field
1688 bool ChatHandler::HandleModifyBitCommand(const char* args)
1690 if( !*args )
1691 return false;
1693 Unit *unit = getSelectedUnit();
1694 if (!unit)
1696 SendSysMessage(LANG_NO_CHAR_SELECTED);
1697 SetSentErrorMessage(true);
1698 return false;
1701 // check online security
1702 if (unit->GetTypeId() == TYPEID_PLAYER && HasLowerSecurity((Player *)unit, 0))
1703 return false;
1705 char* pField = strtok((char*)args, " ");
1706 if (!pField)
1707 return false;
1709 char* pBit = strtok(NULL, " ");
1710 if (!pBit)
1711 return false;
1713 uint16 field = atoi(pField);
1714 uint32 bit = atoi(pBit);
1716 if (field < OBJECT_END || field >= unit->GetValuesCount())
1718 SendSysMessage(LANG_BAD_VALUE);
1719 SetSentErrorMessage(true);
1720 return false;
1722 if (bit < 1 || bit > 32)
1724 SendSysMessage(LANG_BAD_VALUE);
1725 SetSentErrorMessage(true);
1726 return false;
1729 if ( unit->HasFlag( field, (1<<(bit-1)) ) )
1731 unit->RemoveFlag( field, (1<<(bit-1)) );
1732 PSendSysMessage(LANG_REMOVE_BIT, bit, field);
1734 else
1736 unit->SetFlag( field, (1<<(bit-1)) );
1737 PSendSysMessage(LANG_SET_BIT, bit, field);
1739 return true;
1742 bool ChatHandler::HandleModifyHonorCommand (const char* args)
1744 if (!*args)
1745 return false;
1747 Player *target = getSelectedPlayer();
1748 if(!target)
1750 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1751 SetSentErrorMessage(true);
1752 return false;
1755 // check online security
1756 if (HasLowerSecurity(target, 0))
1757 return false;
1759 int32 amount = (uint32)atoi(args);
1761 target->ModifyHonorPoints(amount);
1763 PSendSysMessage(LANG_COMMAND_MODIFY_HONOR, GetNameLink(target).c_str(), target->GetHonorPoints());
1765 return true;
1768 bool ChatHandler::HandleTeleCommand(const char * args)
1770 if(!*args)
1771 return false;
1773 Player* _player = m_session->GetPlayer();
1775 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
1776 GameTele const* tele = extractGameTeleFromLink((char*)args);
1778 if (!tele)
1780 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
1781 SetSentErrorMessage(true);
1782 return false;
1785 // stop flight if need
1786 if(_player->isInFlight())
1788 _player->GetMotionMaster()->MovementExpired();
1789 _player->m_taxi.ClearTaxiDestinations();
1791 // save only in non-flight case
1792 else
1793 _player->SaveRecallPosition();
1795 _player->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
1796 return true;
1799 bool ChatHandler::HandleLookupAreaCommand(const char* args)
1801 if (!*args)
1802 return false;
1804 std::string namepart = args;
1805 std::wstring wnamepart;
1807 if (!Utf8toWStr (namepart,wnamepart))
1808 return false;
1810 uint32 counter = 0; // Counter for figure out that we found smth.
1812 // converting string that we try to find to lower case
1813 wstrToLower (wnamepart);
1815 // Search in AreaTable.dbc
1816 for (uint32 areaflag = 0; areaflag < sAreaStore.GetNumRows (); ++areaflag)
1818 AreaTableEntry const *areaEntry = sAreaStore.LookupEntry (areaflag);
1819 if (areaEntry)
1821 int loc = GetSessionDbcLocale ();
1822 std::string name = areaEntry->area_name[loc];
1823 if (name.empty())
1824 continue;
1826 if (!Utf8FitTo (name, wnamepart))
1828 loc = 0;
1829 for(; loc < MAX_LOCALE; ++loc)
1831 if (loc==GetSessionDbcLocale ())
1832 continue;
1834 name = areaEntry->area_name[loc];
1835 if (name.empty ())
1836 continue;
1838 if (Utf8FitTo (name, wnamepart))
1839 break;
1843 if (loc < MAX_LOCALE)
1845 // send area in "id - [name]" format
1846 std::ostringstream ss;
1847 if (m_session)
1848 ss << areaEntry->ID << " - |cffffffff|Harea:" << areaEntry->ID << "|h[" << name << " " << localeNames[loc]<< "]|h|r";
1849 else
1850 ss << areaEntry->ID << " - " << name << " " << localeNames[loc];
1852 SendSysMessage (ss.str ().c_str());
1854 ++counter;
1859 if (counter == 0) // if counter == 0 then we found nth
1860 SendSysMessage (LANG_COMMAND_NOAREAFOUND);
1862 return true;
1865 //Find tele in game_tele order by name
1866 bool ChatHandler::HandleLookupTeleCommand(const char * args)
1868 if(!*args)
1870 SendSysMessage(LANG_COMMAND_TELE_PARAMETER);
1871 SetSentErrorMessage(true);
1872 return false;
1875 char const* str = strtok((char*)args, " ");
1876 if(!str)
1877 return false;
1879 std::string namepart = str;
1880 std::wstring wnamepart;
1882 if(!Utf8toWStr(namepart,wnamepart))
1883 return false;
1885 // converting string that we try to find to lower case
1886 wstrToLower( wnamepart );
1888 std::ostringstream reply;
1890 GameTeleMap const & teleMap = objmgr.GetGameTeleMap();
1891 for(GameTeleMap::const_iterator itr = teleMap.begin(); itr != teleMap.end(); ++itr)
1893 GameTele const* tele = &itr->second;
1895 if(tele->wnameLow.find(wnamepart) == std::wstring::npos)
1896 continue;
1898 if (m_session)
1899 reply << " |cffffffff|Htele:" << itr->first << "|h[" << tele->name << "]|h|r\n";
1900 else
1901 reply << " " << itr->first << " " << tele->name << "\n";
1904 if(reply.str().empty())
1905 SendSysMessage(LANG_COMMAND_TELE_NOLOCATION);
1906 else
1907 PSendSysMessage(LANG_COMMAND_TELE_LOCATION,reply.str().c_str());
1909 return true;
1912 //Enable\Dissable accept whispers (for GM)
1913 bool ChatHandler::HandleWhispersCommand(const char* args)
1915 if(!*args)
1917 PSendSysMessage(LANG_COMMAND_WHISPERACCEPTING, m_session->GetPlayer()->isAcceptWhispers() ? GetMangosString(LANG_ON) : GetMangosString(LANG_OFF));
1918 return true;
1921 std::string argstr = (char*)args;
1922 // whisper on
1923 if (argstr == "on")
1925 m_session->GetPlayer()->SetAcceptWhispers(true);
1926 SendSysMessage(LANG_COMMAND_WHISPERON);
1927 return true;
1930 // whisper off
1931 if (argstr == "off")
1933 m_session->GetPlayer()->SetAcceptWhispers(false);
1934 SendSysMessage(LANG_COMMAND_WHISPEROFF);
1935 return true;
1938 SendSysMessage(LANG_USE_BOL);
1939 SetSentErrorMessage(true);
1940 return false;
1943 //Save all players in the world
1944 bool ChatHandler::HandleSaveAllCommand(const char* /*args*/)
1946 ObjectAccessor::Instance().SaveAllPlayers();
1947 SendSysMessage(LANG_PLAYERS_SAVED);
1948 return true;
1951 //Send mail by command
1952 bool ChatHandler::HandleSendMailCommand(const char* args)
1954 // format: name "subject text" "mail text"
1955 Player* target;
1956 uint64 target_guid;
1957 std::string target_name;
1958 if(!extractPlayerTarget((char*)args,&target,&target_guid,&target_name))
1959 return false;
1961 char* tail1 = strtok(NULL, "");
1962 if(!tail1)
1963 return false;
1965 char* msgSubject = extractQuotedArg(tail1);
1966 if (!msgSubject)
1967 return false;
1969 char* tail2 = strtok(NULL, "");
1970 if(!tail2)
1971 return false;
1973 char* msgText = extractQuotedArg(tail2);
1974 if (!msgText)
1975 return false;
1977 // msgSubject, msgText isn't NUL after prev. check
1978 std::string subject = msgSubject;
1979 std::string text = msgText;
1981 // from console show not existed sender
1982 uint32 sender_guidlo = m_session ? m_session->GetPlayer()->GetGUIDLow() : 0;
1984 uint32 messagetype = MAIL_NORMAL;
1985 uint32 stationery = MAIL_STATIONERY_GM;
1986 uint32 itemTextId = !text.empty() ? objmgr.CreateItemText( text ) : 0;
1988 WorldSession::SendMailTo(target,messagetype, stationery, sender_guidlo, GUID_LOPART(target_guid), subject, itemTextId, NULL, 0, 0, MAIL_CHECK_MASK_NONE);
1990 std::string nameLink = playerLink(target_name);
1991 PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
1992 return true;
1995 // teleport player to given game_tele.entry
1996 bool ChatHandler::HandleTeleNameCommand(const char * args)
1998 char* nameStr;
1999 char* teleStr;
2000 extractOptFirstArg((char*)args,&nameStr,&teleStr);
2001 if(!teleStr)
2002 return false;
2004 Player* target;
2005 uint64 target_guid;
2006 std::string target_name;
2007 if(!extractPlayerTarget(nameStr,&target,&target_guid,&target_name))
2008 return false;
2010 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2011 GameTele const* tele = extractGameTeleFromLink(teleStr);
2012 if(!tele)
2014 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
2015 SetSentErrorMessage(true);
2016 return false;
2019 if (target)
2021 // check online security
2022 if (HasLowerSecurity(target, 0))
2023 return false;
2025 std::string chrNameLink = playerLink(target_name);
2027 if(target->IsBeingTeleported()==true)
2029 PSendSysMessage(LANG_IS_TELEPORTED, chrNameLink.c_str());
2030 SetSentErrorMessage(true);
2031 return false;
2034 PSendSysMessage(LANG_TELEPORTING_TO, chrNameLink.c_str(),"", tele->name.c_str());
2035 if (needReportToTarget(target))
2036 ChatHandler(target).PSendSysMessage(LANG_TELEPORTED_TO_BY, GetNameLink().c_str());
2038 // stop flight if need
2039 if(target->isInFlight())
2041 target->GetMotionMaster()->MovementExpired();
2042 target->m_taxi.ClearTaxiDestinations();
2044 // save only in non-flight case
2045 else
2046 target->SaveRecallPosition();
2048 target->TeleportTo(tele->mapId,tele->position_x,tele->position_y,tele->position_z,tele->orientation);
2050 else
2052 // check offline security
2053 if (HasLowerSecurity(NULL, target_guid))
2054 return false;
2056 std::string nameLink = playerLink(target_name);
2058 PSendSysMessage(LANG_TELEPORTING_TO, nameLink.c_str(), GetMangosString(LANG_OFFLINE), tele->name.c_str());
2059 Player::SavePositionInDB(tele->mapId,tele->position_x,tele->position_y,tele->position_z,tele->orientation,
2060 MapManager::Instance().GetZoneId(tele->mapId,tele->position_x,tele->position_y,tele->position_z),target_guid);
2063 return true;
2066 //Teleport group to given game_tele.entry
2067 bool ChatHandler::HandleTeleGroupCommand(const char * args)
2069 if(!*args)
2070 return false;
2072 Player *player = getSelectedPlayer();
2073 if (!player)
2075 SendSysMessage(LANG_NO_CHAR_SELECTED);
2076 SetSentErrorMessage(true);
2077 return false;
2080 // check online security
2081 if (HasLowerSecurity(player, 0))
2082 return false;
2084 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2085 GameTele const* tele = extractGameTeleFromLink((char*)args);
2086 if(!tele)
2088 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
2089 SetSentErrorMessage(true);
2090 return false;
2093 std::string nameLink = GetNameLink(player);
2095 Group *grp = player->GetGroup();
2096 if(!grp)
2098 PSendSysMessage(LANG_NOT_IN_GROUP,nameLink.c_str());
2099 SetSentErrorMessage(true);
2100 return false;
2103 for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
2105 Player *pl = itr->getSource();
2107 if(!pl || !pl->GetSession() )
2108 continue;
2110 // check online security
2111 if (HasLowerSecurity(pl, 0))
2112 return false;
2114 std::string plNameLink = GetNameLink(pl);
2116 if(pl->IsBeingTeleported())
2118 PSendSysMessage(LANG_IS_TELEPORTED, plNameLink.c_str());
2119 continue;
2122 PSendSysMessage(LANG_TELEPORTING_TO, plNameLink.c_str(),"", tele->name.c_str());
2123 if (needReportToTarget(pl))
2124 ChatHandler(pl).PSendSysMessage(LANG_TELEPORTED_TO_BY, nameLink.c_str());
2126 // stop flight if need
2127 if(pl->isInFlight())
2129 pl->GetMotionMaster()->MovementExpired();
2130 pl->m_taxi.ClearTaxiDestinations();
2132 // save only in non-flight case
2133 else
2134 pl->SaveRecallPosition();
2136 pl->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
2139 return true;
2142 //Summon group of player
2143 bool ChatHandler::HandleGroupgoCommand(const char* args)
2145 Player* target;
2146 if(!extractPlayerTarget((char*)args,&target))
2147 return false;
2149 // check online security
2150 if (HasLowerSecurity(target, 0))
2151 return false;
2153 Group *grp = target->GetGroup();
2155 std::string nameLink = GetNameLink(target);
2157 if(!grp)
2159 PSendSysMessage(LANG_NOT_IN_GROUP,nameLink.c_str());
2160 SetSentErrorMessage(true);
2161 return false;
2164 Map* gmMap = m_session->GetPlayer()->GetMap();
2165 bool to_instance = gmMap->Instanceable();
2167 // we are in instance, and can summon only player in our group with us as lead
2168 if ( to_instance && (
2169 !m_session->GetPlayer()->GetGroup() || (grp->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ||
2170 (m_session->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ) )
2171 // the last check is a bit excessive, but let it be, just in case
2173 SendSysMessage(LANG_CANNOT_SUMMON_TO_INST);
2174 SetSentErrorMessage(true);
2175 return false;
2178 for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
2180 Player *pl = itr->getSource();
2182 if(!pl || pl==m_session->GetPlayer() || !pl->GetSession() )
2183 continue;
2185 // check online security
2186 if (HasLowerSecurity(pl, 0))
2187 return false;
2189 std::string plNameLink = GetNameLink(pl);
2191 if(pl->IsBeingTeleported()==true)
2193 PSendSysMessage(LANG_IS_TELEPORTED, plNameLink.c_str());
2194 SetSentErrorMessage(true);
2195 return false;
2198 if (to_instance)
2200 Map* plMap = pl->GetMap();
2202 if ( plMap->Instanceable() && plMap->GetInstanceId() != gmMap->GetInstanceId() )
2204 // cannot summon from instance to instance
2205 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,plNameLink.c_str());
2206 SetSentErrorMessage(true);
2207 return false;
2211 PSendSysMessage(LANG_SUMMONING, plNameLink.c_str(),"");
2212 if (needReportToTarget(pl))
2213 ChatHandler(pl).PSendSysMessage(LANG_SUMMONED_BY, nameLink.c_str());
2215 // stop flight if need
2216 if(pl->isInFlight())
2218 pl->GetMotionMaster()->MovementExpired();
2219 pl->m_taxi.ClearTaxiDestinations();
2221 // save only in non-flight case
2222 else
2223 pl->SaveRecallPosition();
2225 // before GM
2226 float x,y,z;
2227 m_session->GetPlayer()->GetClosePoint(x,y,z,pl->GetObjectSize());
2228 pl->TeleportTo(m_session->GetPlayer()->GetMapId(),x,y,z,pl->GetOrientation());
2231 return true;
2234 bool ChatHandler::HandleGoTaxinodeCommand(const char* args)
2236 Player* _player = m_session->GetPlayer();
2238 if (!*args)
2239 return false;
2241 char* cNodeId = extractKeyFromLink((char*)args,"Htaxinode");
2242 if (!cNodeId)
2243 return false;
2245 int32 i_nodeId = atoi(cNodeId);
2246 if (!i_nodeId)
2247 return false;
2249 TaxiNodesEntry const* node = sTaxiNodesStore.LookupEntry(i_nodeId);
2250 if (!node)
2252 PSendSysMessage(LANG_COMMAND_GOTAXINODENOTFOUND,i_nodeId);
2253 SetSentErrorMessage(true);
2254 return false;
2257 if (node->x == 0.0f && node->y == 0.0f && node->z == 0.0f ||
2258 !MapManager::IsValidMapCoord(node->map_id,node->x,node->y,node->z))
2260 PSendSysMessage(LANG_INVALID_TARGET_COORD,node->x,node->y,node->map_id);
2261 SetSentErrorMessage(true);
2262 return false;
2265 // stop flight if need
2266 if (_player->isInFlight())
2268 _player->GetMotionMaster()->MovementExpired();
2269 _player->m_taxi.ClearTaxiDestinations();
2271 // save only in non-flight case
2272 else
2273 _player->SaveRecallPosition();
2275 _player->TeleportTo(node->map_id, node->x, node->y, node->z, _player->GetOrientation());
2276 return true;
2279 //teleport at coordinates
2280 bool ChatHandler::HandleGoXYCommand(const char* args)
2282 if(!*args)
2283 return false;
2285 Player* _player = m_session->GetPlayer();
2287 char* px = strtok((char*)args, " ");
2288 char* py = strtok(NULL, " ");
2289 char* pmapid = strtok(NULL, " ");
2291 if (!px || !py)
2292 return false;
2294 float x = (float)atof(px);
2295 float y = (float)atof(py);
2296 uint32 mapid;
2297 if (pmapid)
2298 mapid = (uint32)atoi(pmapid);
2299 else mapid = _player->GetMapId();
2301 if(!MapManager::IsValidMapCoord(mapid,x,y))
2303 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
2304 SetSentErrorMessage(true);
2305 return false;
2308 // stop flight if need
2309 if(_player->isInFlight())
2311 _player->GetMotionMaster()->MovementExpired();
2312 _player->m_taxi.ClearTaxiDestinations();
2314 // save only in non-flight case
2315 else
2316 _player->SaveRecallPosition();
2318 Map const *map = MapManager::Instance().GetBaseMap(mapid);
2319 float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
2321 _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
2323 return true;
2326 //teleport at coordinates, including Z
2327 bool ChatHandler::HandleGoXYZCommand(const char* args)
2329 if(!*args)
2330 return false;
2332 Player* _player = m_session->GetPlayer();
2334 char* px = strtok((char*)args, " ");
2335 char* py = strtok(NULL, " ");
2336 char* pz = strtok(NULL, " ");
2337 char* pmapid = strtok(NULL, " ");
2339 if (!px || !py || !pz)
2340 return false;
2342 float x = (float)atof(px);
2343 float y = (float)atof(py);
2344 float z = (float)atof(pz);
2345 uint32 mapid;
2346 if (pmapid)
2347 mapid = (uint32)atoi(pmapid);
2348 else
2349 mapid = _player->GetMapId();
2351 if(!MapManager::IsValidMapCoord(mapid,x,y,z))
2353 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
2354 SetSentErrorMessage(true);
2355 return false;
2358 // stop flight if need
2359 if(_player->isInFlight())
2361 _player->GetMotionMaster()->MovementExpired();
2362 _player->m_taxi.ClearTaxiDestinations();
2364 // save only in non-flight case
2365 else
2366 _player->SaveRecallPosition();
2368 _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
2370 return true;
2373 //teleport at coordinates
2374 bool ChatHandler::HandleGoZoneXYCommand(const char* args)
2376 if(!*args)
2377 return false;
2379 Player* _player = m_session->GetPlayer();
2381 char* px = strtok((char*)args, " ");
2382 char* py = strtok(NULL, " ");
2383 char* tail = strtok(NULL,"");
2385 char* cAreaId = extractKeyFromLink(tail,"Harea"); // string or [name] Shift-click form |color|Harea:area_id|h[name]|h|r
2387 if (!px || !py)
2388 return false;
2390 float x = (float)atof(px);
2391 float y = (float)atof(py);
2393 // prevent accept wrong numeric args
2394 if (x==0.0f && *px!='0' || y==0.0f && *py!='0')
2395 return false;
2397 uint32 areaid = cAreaId ? (uint32)atoi(cAreaId) : _player->GetZoneId();
2399 AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(areaid);
2401 if( x<0 || x>100 || y<0 || y>100 || !areaEntry )
2403 PSendSysMessage(LANG_INVALID_ZONE_COORD,x,y,areaid);
2404 SetSentErrorMessage(true);
2405 return false;
2408 // update to parent zone if exist (client map show only zones without parents)
2409 AreaTableEntry const* zoneEntry = areaEntry->zone ? GetAreaEntryByAreaID(areaEntry->zone) : areaEntry;
2411 Map const *map = MapManager::Instance().GetBaseMap(zoneEntry->mapid);
2413 if(map->Instanceable())
2415 PSendSysMessage(LANG_INVALID_ZONE_MAP,areaEntry->ID,areaEntry->area_name[GetSessionDbcLocale()],map->GetId(),map->GetMapName());
2416 SetSentErrorMessage(true);
2417 return false;
2420 Zone2MapCoordinates(x,y,zoneEntry->ID);
2422 if(!MapManager::IsValidMapCoord(zoneEntry->mapid,x,y))
2424 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,zoneEntry->mapid);
2425 SetSentErrorMessage(true);
2426 return false;
2429 // stop flight if need
2430 if(_player->isInFlight())
2432 _player->GetMotionMaster()->MovementExpired();
2433 _player->m_taxi.ClearTaxiDestinations();
2435 // save only in non-flight case
2436 else
2437 _player->SaveRecallPosition();
2439 float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
2440 _player->TeleportTo(zoneEntry->mapid, x, y, z, _player->GetOrientation());
2442 return true;
2445 //teleport to grid
2446 bool ChatHandler::HandleGoGridCommand(const char* args)
2448 if(!*args) return false;
2449 Player* _player = m_session->GetPlayer();
2451 char* px = strtok((char*)args, " ");
2452 char* py = strtok(NULL, " ");
2453 char* pmapid = strtok(NULL, " ");
2455 if (!px || !py)
2456 return false;
2458 float grid_x = (float)atof(px);
2459 float grid_y = (float)atof(py);
2460 uint32 mapid;
2461 if (pmapid)
2462 mapid = (uint32)atoi(pmapid);
2463 else mapid = _player->GetMapId();
2465 // center of grid
2466 float x = (grid_x-CENTER_GRID_ID+0.5f)*SIZE_OF_GRIDS;
2467 float y = (grid_y-CENTER_GRID_ID+0.5f)*SIZE_OF_GRIDS;
2469 if(!MapManager::IsValidMapCoord(mapid,x,y))
2471 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
2472 SetSentErrorMessage(true);
2473 return false;
2476 // stop flight if need
2477 if(_player->isInFlight())
2479 _player->GetMotionMaster()->MovementExpired();
2480 _player->m_taxi.ClearTaxiDestinations();
2482 // save only in non-flight case
2483 else
2484 _player->SaveRecallPosition();
2486 Map const *map = MapManager::Instance().GetBaseMap(mapid);
2487 float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
2488 _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
2490 return true;
2493 bool ChatHandler::HandleModifyDrunkCommand(const char* args)
2495 if(!*args) return false;
2497 uint32 drunklevel = (uint32)atoi(args);
2498 if(drunklevel > 100)
2499 drunklevel = 100;
2501 uint16 drunkMod = drunklevel * 0xFFFF / 100;
2503 m_session->GetPlayer()->SetDrunkValue(drunkMod);
2505 return true;