[6922] Whitespace and newline fixes
[getmangos.git] / src / game / Level1.cpp
blob26d5b15fee266d451d86acf28b4a027053ed760d
1 /*
2 * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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 pCreature->Whisper(text,receiver_guid);
116 return true;
119 // global announce
120 bool ChatHandler::HandleAnnounceCommand(const char* args)
122 if(!*args)
123 return false;
125 sWorld.SendWorldText(LANG_SYSTEMMESSAGE,args);
126 return true;
129 //notification player at the screen
130 bool ChatHandler::HandleNotifyCommand(const char* args)
132 if(!*args)
133 return false;
135 std::string str = GetMangosString(LANG_GLOBAL_NOTIFY);
136 str += args;
138 WorldPacket data(SMSG_NOTIFICATION, (str.size()+1));
139 data << str;
140 sWorld.SendGlobalMessage(&data);
142 return true;
145 //Enable\Dissable GM Mode
146 bool ChatHandler::HandleGMmodeCommand(const char* args)
148 if(!*args)
150 if(m_session->GetPlayer()->isGameMaster())
151 m_session->SendNotification(LANG_GM_ON);
152 else
153 m_session->SendNotification(LANG_GM_OFF);
154 return true;
157 std::string argstr = (char*)args;
159 if (argstr == "on")
161 m_session->GetPlayer()->SetGameMaster(true);
162 m_session->SendNotification(LANG_GM_ON);
163 #ifdef _DEBUG_VMAPS
164 VMAP::IVMapManager *vMapManager = VMAP::VMapFactory::createOrGetVMapManager();
165 vMapManager->processCommand("stoplog");
166 #endif
167 return true;
170 if (argstr == "off")
172 m_session->GetPlayer()->SetGameMaster(false);
173 m_session->SendNotification(LANG_GM_OFF);
174 #ifdef _DEBUG_VMAPS
175 VMAP::IVMapManager *vMapManager = VMAP::VMapFactory::createOrGetVMapManager();
176 vMapManager->processCommand("startlog");
177 #endif
178 return true;
181 SendSysMessage(LANG_USE_BOL);
182 SetSentErrorMessage(true);
183 return false;
186 // Enables or disables hiding of the staff badge
187 bool ChatHandler::HandleGMChatCommand(const char* args)
189 if(!*args)
191 if(m_session->GetPlayer()->isGMChat())
192 m_session->SendNotification(LANG_GM_CHAT_ON);
193 else
194 m_session->SendNotification(LANG_GM_CHAT_OFF);
195 return true;
198 std::string argstr = (char*)args;
200 if (argstr == "on")
202 m_session->GetPlayer()->SetGMChat(true);
203 m_session->SendNotification(LANG_GM_CHAT_ON);
204 return true;
207 if (argstr == "off")
209 m_session->GetPlayer()->SetGMChat(false);
210 m_session->SendNotification(LANG_GM_CHAT_OFF);
211 return true;
214 SendSysMessage(LANG_USE_BOL);
215 SetSentErrorMessage(true);
216 return false;
219 //Enable\Dissable Invisible mode
220 bool ChatHandler::HandleVisibleCommand(const char* args)
222 if (!*args)
224 PSendSysMessage(LANG_YOU_ARE, m_session->GetPlayer()->isGMVisible() ? GetMangosString(LANG_VISIBLE) : GetMangosString(LANG_INVISIBLE));
225 return true;
228 std::string argstr = (char*)args;
230 if (argstr == "on")
232 m_session->GetPlayer()->SetGMVisible(true);
233 m_session->SendNotification(LANG_INVISIBLE_VISIBLE);
234 return true;
237 if (argstr == "off")
239 m_session->SendNotification(LANG_INVISIBLE_INVISIBLE);
240 m_session->GetPlayer()->SetGMVisible(false);
241 return true;
244 SendSysMessage(LANG_USE_BOL);
245 SetSentErrorMessage(true);
246 return false;
249 bool ChatHandler::HandleGPSCommand(const char* args)
251 WorldObject *obj = NULL;
252 if (*args)
254 std::string name = args;
255 if(normalizePlayerName(name))
256 obj = objmgr.GetPlayer(name.c_str());
258 if(!obj)
260 SendSysMessage(LANG_PLAYER_NOT_FOUND);
261 SetSentErrorMessage(true);
262 return false;
265 else
267 obj = getSelectedUnit();
269 if(!obj)
271 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
272 SetSentErrorMessage(true);
273 return false;
276 CellPair cell_val = MaNGOS::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY());
277 Cell cell(cell_val);
279 uint32 zone_id = obj->GetZoneId();
280 uint32 area_id = obj->GetAreaId();
282 MapEntry const* mapEntry = sMapStore.LookupEntry(obj->GetMapId());
283 AreaTableEntry const* zoneEntry = GetAreaEntryByAreaID(zone_id);
284 AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(area_id);
286 float zone_x = obj->GetPositionX();
287 float zone_y = obj->GetPositionY();
289 Map2ZoneCoordinates(zone_x,zone_y,zone_id);
291 Map const *map = obj->GetMap();
292 float ground_z = map->GetHeight(obj->GetPositionX(), obj->GetPositionY(), MAX_HEIGHT);
293 float floor_z = map->GetHeight(obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ());
295 GridPair p = MaNGOS::ComputeGridPair(obj->GetPositionX(), obj->GetPositionY());
297 int gx=63-p.x_coord;
298 int gy=63-p.y_coord;
300 uint32 have_map = Map::ExistMap(obj->GetMapId(),gx,gy) ? 1 : 0;
301 uint32 have_vmap = Map::ExistVMap(obj->GetMapId(),gx,gy) ? 1 : 0;
303 PSendSysMessage(LANG_MAP_POSITION,
304 obj->GetMapId(), (mapEntry ? mapEntry->name[m_session->GetSessionDbcLocale()] : "<unknown>" ),
305 zone_id, (zoneEntry ? zoneEntry->area_name[m_session->GetSessionDbcLocale()] : "<unknown>" ),
306 area_id, (areaEntry ? areaEntry->area_name[m_session->GetSessionDbcLocale()] : "<unknown>" ),
307 obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ(), obj->GetOrientation(),
308 cell.GridX(), cell.GridY(), cell.CellX(), cell.CellY(), obj->GetInstanceId(),
309 zone_x, zone_y, ground_z, floor_z, have_map, have_vmap );
311 sLog.outDebug("Player %s GPS call for %s '%s' (%s: %u):",
312 GetName(),
313 (obj->GetTypeId() == TYPEID_PLAYER ? "player" : "creature"), obj->GetName(),
314 (obj->GetTypeId() == TYPEID_PLAYER ? "GUID" : "Entry"), (obj->GetTypeId() == TYPEID_PLAYER ? obj->GetGUIDLow(): obj->GetEntry()) );
316 sLog.outDebug(GetMangosString(LANG_MAP_POSITION),
317 obj->GetMapId(), (mapEntry ? mapEntry->name[sWorld.GetDefaultDbcLocale()] : "<unknown>" ),
318 zone_id, (zoneEntry ? zoneEntry->area_name[sWorld.GetDefaultDbcLocale()] : "<unknown>" ),
319 area_id, (areaEntry ? areaEntry->area_name[sWorld.GetDefaultDbcLocale()] : "<unknown>" ),
320 obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ(), obj->GetOrientation(),
321 cell.GridX(), cell.GridY(), cell.CellX(), cell.CellY(), obj->GetInstanceId(),
322 zone_x, zone_y, ground_z, floor_z, have_map, have_vmap );
324 return true;
327 //Summon Player
328 bool ChatHandler::HandleNamegoCommand(const char* args)
330 if(!*args)
331 return false;
333 std::string name = args;
335 if(!normalizePlayerName(name))
337 SendSysMessage(LANG_PLAYER_NOT_FOUND);
338 SetSentErrorMessage(true);
339 return false;
342 Player *chr = objmgr.GetPlayer(name.c_str());
343 if (chr)
345 if(chr->IsBeingTeleported()==true)
347 PSendSysMessage(LANG_IS_TELEPORTED, chr->GetName());
348 SetSentErrorMessage(true);
349 return false;
352 Map* pMap = m_session->GetPlayer()->GetMap();
354 if(pMap->IsBattleGroundOrArena())
356 // cannot summon to bg
357 PSendSysMessage(LANG_CANNOT_SUMMON_TO_BG,chr->GetName());
358 SetSentErrorMessage(true);
359 return false;
361 else if(pMap->IsDungeon())
363 Map* cMap = chr->GetMap();
364 if( cMap->Instanceable() && cMap->GetInstanceId() != pMap->GetInstanceId() )
366 // cannot summon from instance to instance
367 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,chr->GetName());
368 SetSentErrorMessage(true);
369 return false;
372 // we are in instance, and can summon only player in our group with us as lead
373 if ( !m_session->GetPlayer()->GetGroup() || !chr->GetGroup() ||
374 (chr->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ||
375 (m_session->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) )
376 // the last check is a bit excessive, but let it be, just in case
378 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,chr->GetName());
379 SetSentErrorMessage(true);
380 return false;
384 PSendSysMessage(LANG_SUMMONING, chr->GetName(),"");
385 if (needReportToTarget(chr))
386 ChatHandler(chr).PSendSysMessage(LANG_SUMMONED_BY, GetName());
388 // stop flight if need
389 if(chr->isInFlight())
391 chr->GetMotionMaster()->MovementExpired();
392 chr->m_taxi.ClearTaxiDestinations();
394 // save only in non-flight case
395 else
396 chr->SaveRecallPosition();
398 // before GM
399 float x,y,z;
400 m_session->GetPlayer()->GetClosePoint(x,y,z,chr->GetObjectSize());
401 chr->TeleportTo(m_session->GetPlayer()->GetMapId(),x,y,z,chr->GetOrientation());
403 else if (uint64 guid = objmgr.GetPlayerGUIDByName(name))
405 PSendSysMessage(LANG_SUMMONING, name.c_str(),GetMangosString(LANG_OFFLINE));
407 // in point where GM stay
408 Player::SavePositionInDB(m_session->GetPlayer()->GetMapId(),
409 m_session->GetPlayer()->GetPositionX(),
410 m_session->GetPlayer()->GetPositionY(),
411 m_session->GetPlayer()->GetPositionZ(),
412 m_session->GetPlayer()->GetOrientation(),
413 m_session->GetPlayer()->GetZoneId(),
414 guid);
416 else
418 PSendSysMessage(LANG_NO_PLAYER, args);
419 SetSentErrorMessage(true);
422 return true;
425 //Teleport to Player
426 bool ChatHandler::HandleGonameCommand(const char* args)
428 if(!*args)
429 return false;
431 Player* _player = m_session->GetPlayer();
433 std::string name = args;
435 if(!normalizePlayerName(name))
437 SendSysMessage(LANG_PLAYER_NOT_FOUND);
438 SetSentErrorMessage(true);
439 return false;
442 Player *chr = objmgr.GetPlayer(name.c_str());
443 if (chr)
445 Map* cMap = chr->GetMap();
446 if(cMap->IsBattleGroundOrArena())
448 // only allow if gm mode is on
449 if (!_player->isGameMaster())
451 PSendSysMessage(LANG_CANNOT_GO_TO_BG_GM,chr->GetName());
452 SetSentErrorMessage(true);
453 return false;
455 // if already in a bg, don't let port to other
456 else if (_player->GetBattleGroundId())
458 PSendSysMessage(LANG_CANNOT_GO_TO_BG_FROM_BG,chr->GetName());
459 SetSentErrorMessage(true);
460 return false;
462 // all's well, set bg id
463 // when porting out from the bg, it will be reset to 0
464 _player->SetBattleGroundId(chr->GetBattleGroundId());
466 else if(cMap->IsDungeon())
467 Map* cMap = chr->GetMap();
468 if(cMap->Instanceable())
470 // we have to go to instance, and can go to player only if:
471 // 1) we are in his group (either as leader or as member)
472 // 2) we are not bound to any group and have GM mode on
473 if (_player->GetGroup())
475 // we are in group, we can go only if we are in the player group
476 if (_player->GetGroup() != chr->GetGroup())
478 PSendSysMessage(LANG_CANNOT_GO_TO_INST_PARTY,chr->GetName());
479 SetSentErrorMessage(true);
480 return false;
483 else
485 // we are not in group, let's verify our GM mode
486 if (!_player->isGameMaster())
488 PSendSysMessage(LANG_CANNOT_GO_TO_INST_GM,chr->GetName());
489 SetSentErrorMessage(true);
490 return false;
494 // if the player or the player's group is bound to another instance
495 // the player will not be bound to another one
496 InstancePlayerBind *pBind = _player->GetBoundInstance(chr->GetMapId(), chr->GetDifficulty());
497 if(!pBind)
499 Group *group = _player->GetGroup();
500 InstanceGroupBind *gBind = group ? group->GetBoundInstance(chr->GetMapId(), chr->GetDifficulty()) : NULL;
501 if(!gBind)
503 // if no bind exists, create a solo bind
504 InstanceSave *save = sInstanceSaveManager.GetInstanceSave(chr->GetInstanceId());
505 if(save) _player->BindToInstance(save, !save->CanReset());
509 _player->SetDifficulty(chr->GetDifficulty());
512 PSendSysMessage(LANG_APPEARING_AT, chr->GetName());
514 if (_player->IsVisibleGloballyFor(chr))
515 ChatHandler(chr).PSendSysMessage(LANG_APPEARING_TO, _player->GetName());
517 // stop flight if need
518 if(_player->isInFlight())
520 _player->GetMotionMaster()->MovementExpired();
521 _player->m_taxi.ClearTaxiDestinations();
523 // save only in non-flight case
524 else
525 _player->SaveRecallPosition();
527 // to point to see at target with same orientation
528 float x,y,z;
529 chr->GetContactPoint(m_session->GetPlayer(),x,y,z);
531 _player->TeleportTo(chr->GetMapId(), x, y, z, _player->GetAngle( chr ), TELE_TO_GM_MODE);
533 return true;
536 if (uint64 guid = objmgr.GetPlayerGUIDByName(name))
538 PSendSysMessage(LANG_APPEARING_AT, name.c_str());
540 // to point where player stay (if loaded)
541 float x,y,z,o;
542 uint32 map;
543 bool in_flight;
544 if(Player::LoadPositionFromDB(map,x,y,z,o,in_flight,guid))
546 // stop flight if need
547 if(_player->isInFlight())
549 _player->GetMotionMaster()->MovementExpired();
550 _player->m_taxi.ClearTaxiDestinations();
552 // save only in non-flight case
553 else
554 _player->SaveRecallPosition();
556 _player->TeleportTo(map, x, y, z,_player->GetOrientation());
557 return true;
561 PSendSysMessage(LANG_NO_PLAYER, args);
563 SetSentErrorMessage(true);
564 return false;
567 // Teleport player to last position
568 bool ChatHandler::HandleRecallCommand(const char* args)
570 Player* chr = NULL;
572 if(!*args)
574 chr = getSelectedPlayer();
575 if(!chr)
576 chr = m_session->GetPlayer();
578 else
580 std::string name = args;
582 if(!normalizePlayerName(name))
584 SendSysMessage(LANG_PLAYER_NOT_FOUND);
585 SetSentErrorMessage(true);
586 return false;
589 chr = objmgr.GetPlayer(name.c_str());
591 if(!chr)
593 PSendSysMessage(LANG_NO_PLAYER, args);
594 SetSentErrorMessage(true);
595 return false;
599 if(chr->IsBeingTeleported())
601 PSendSysMessage(LANG_IS_TELEPORTED, chr->GetName());
602 SetSentErrorMessage(true);
603 return false;
606 // stop flight if need
607 if(chr->isInFlight())
609 chr->GetMotionMaster()->MovementExpired();
610 chr->m_taxi.ClearTaxiDestinations();
613 chr->TeleportTo(chr->m_recallMap, chr->m_recallX, chr->m_recallY, chr->m_recallZ, chr->m_recallO);
614 return true;
617 //Edit Player KnownTitles
618 bool ChatHandler::HandleModifyKnownTitlesCommand(const char* args)
620 if(!*args)
621 return false;
623 uint64 titles = 0;
625 sscanf((char*)args, I64FMTD, &titles);
627 Player *chr = getSelectedPlayer();
628 if (!chr)
630 SendSysMessage(LANG_NO_CHAR_SELECTED);
631 SetSentErrorMessage(true);
632 return false;
635 uint64 titles2 = titles;
637 for(int i=1; i < sCharTitlesStore.GetNumRows(); ++i)
638 if(CharTitlesEntry const* tEntry = sCharTitlesStore.LookupEntry(i))
639 titles2 &= ~(uint64(1) << tEntry->bit_index);
641 titles &= ~titles2; // remove not existed titles
643 chr->SetUInt64Value(PLAYER__FIELD_KNOWN_TITLES, titles);
644 SendSysMessage(LANG_DONE);
646 return true;
649 //Edit Player HP
650 bool ChatHandler::HandleModifyHPCommand(const char* args)
652 if(!*args)
653 return false;
655 // char* pHp = strtok((char*)args, " ");
656 // if (!pHp)
657 // return false;
659 // char* pHpMax = strtok(NULL, " ");
660 // if (!pHpMax)
661 // return false;
663 // int32 hpm = atoi(pHpMax);
664 // int32 hp = atoi(pHp);
666 int32 hp = atoi((char*)args);
667 int32 hpm = atoi((char*)args);
669 if (hp <= 0 || hpm <= 0 || hpm < hp)
671 SendSysMessage(LANG_BAD_VALUE);
672 SetSentErrorMessage(true);
673 return false;
676 Player *chr = getSelectedPlayer();
677 if (chr == NULL)
679 SendSysMessage(LANG_NO_CHAR_SELECTED);
680 SetSentErrorMessage(true);
681 return false;
684 PSendSysMessage(LANG_YOU_CHANGE_HP, chr->GetName(), hp, hpm);
685 if (needReportToTarget(chr))
686 ChatHandler(chr).PSendSysMessage(LANG_YOURS_HP_CHANGED, GetName(), hp, hpm);
688 chr->SetMaxHealth( hpm );
689 chr->SetHealth( hp );
691 return true;
694 //Edit Player Mana
695 bool ChatHandler::HandleModifyManaCommand(const char* args)
697 if(!*args)
698 return false;
700 // char* pmana = strtok((char*)args, " ");
701 // if (!pmana)
702 // return false;
704 // char* pmanaMax = strtok(NULL, " ");
705 // if (!pmanaMax)
706 // return false;
708 // int32 manam = atoi(pmanaMax);
709 // int32 mana = atoi(pmana);
710 int32 mana = atoi((char*)args);
711 int32 manam = atoi((char*)args);
713 if (mana <= 0 || manam <= 0 || manam < mana)
715 SendSysMessage(LANG_BAD_VALUE);
716 SetSentErrorMessage(true);
717 return false;
720 Player *chr = getSelectedPlayer();
721 if (chr == NULL)
723 SendSysMessage(LANG_NO_CHAR_SELECTED);
724 SetSentErrorMessage(true);
725 return false;
728 PSendSysMessage(LANG_YOU_CHANGE_MANA, chr->GetName(), mana, manam);
729 if (needReportToTarget(chr))
730 ChatHandler(chr).PSendSysMessage(LANG_YOURS_MANA_CHANGED, GetName(), mana, manam);
732 chr->SetMaxPower(POWER_MANA,manam );
733 chr->SetPower(POWER_MANA, mana );
735 return true;
738 //Edit Player Energy
739 bool ChatHandler::HandleModifyEnergyCommand(const char* args)
741 if(!*args)
742 return false;
744 // char* pmana = strtok((char*)args, " ");
745 // if (!pmana)
746 // return false;
748 // char* pmanaMax = strtok(NULL, " ");
749 // if (!pmanaMax)
750 // return false;
752 // int32 manam = atoi(pmanaMax);
753 // int32 mana = atoi(pmana);
755 int32 energy = atoi((char*)args)*10;
756 int32 energym = atoi((char*)args)*10;
758 if (energy <= 0 || energym <= 0 || energym < energy)
760 SendSysMessage(LANG_BAD_VALUE);
761 SetSentErrorMessage(true);
762 return false;
765 Player *chr = getSelectedPlayer();
766 if (!chr)
768 SendSysMessage(LANG_NO_CHAR_SELECTED);
769 SetSentErrorMessage(true);
770 return false;
773 PSendSysMessage(LANG_YOU_CHANGE_ENERGY, chr->GetName(), energy/10, energym/10);
774 if (needReportToTarget(chr))
775 ChatHandler(chr).PSendSysMessage(LANG_YOURS_ENERGY_CHANGED, GetName(), energy/10, energym/10);
777 chr->SetMaxPower(POWER_ENERGY,energym );
778 chr->SetPower(POWER_ENERGY, energy );
780 sLog.outDetail(GetMangosString(LANG_CURRENT_ENERGY),chr->GetMaxPower(POWER_ENERGY));
782 return true;
785 //Edit Player Rage
786 bool ChatHandler::HandleModifyRageCommand(const char* args)
788 if(!*args)
789 return false;
791 // char* pmana = strtok((char*)args, " ");
792 // if (!pmana)
793 // return false;
795 // char* pmanaMax = strtok(NULL, " ");
796 // if (!pmanaMax)
797 // return false;
799 // int32 manam = atoi(pmanaMax);
800 // int32 mana = atoi(pmana);
802 int32 rage = atoi((char*)args)*10;
803 int32 ragem = atoi((char*)args)*10;
805 if (rage <= 0 || ragem <= 0 || ragem < rage)
807 SendSysMessage(LANG_BAD_VALUE);
808 SetSentErrorMessage(true);
809 return false;
812 Player *chr = getSelectedPlayer();
813 if (chr == NULL)
815 SendSysMessage(LANG_NO_CHAR_SELECTED);
816 SetSentErrorMessage(true);
817 return false;
820 PSendSysMessage(LANG_YOU_CHANGE_RAGE, chr->GetName(), rage/10, ragem/10);
821 if (needReportToTarget(chr))
822 ChatHandler(chr).PSendSysMessage(LANG_YOURS_RAGE_CHANGED, GetName(), rage/10, ragem/10);
824 chr->SetMaxPower(POWER_RAGE,ragem );
825 chr->SetPower(POWER_RAGE, rage );
827 return true;
830 //Edit Player Faction
831 bool ChatHandler::HandleModifyFactionCommand(const char* args)
833 if(!*args)
834 return false;
836 char* pfactionid = extractKeyFromLink((char*)args,"Hfaction");
838 Creature* chr = getSelectedCreature();
839 if(!chr)
841 SendSysMessage(LANG_SELECT_CREATURE);
842 SetSentErrorMessage(true);
843 return false;
846 if(!pfactionid)
848 if(chr)
850 uint32 factionid = chr->getFaction();
851 uint32 flag = chr->GetUInt32Value(UNIT_FIELD_FLAGS);
852 uint32 npcflag = chr->GetUInt32Value(UNIT_NPC_FLAGS);
853 uint32 dyflag = chr->GetUInt32Value(UNIT_DYNAMIC_FLAGS);
854 PSendSysMessage(LANG_CURRENT_FACTION,chr->GetGUIDLow(),factionid,flag,npcflag,dyflag);
856 return true;
859 if( !chr )
861 SendSysMessage(LANG_NO_CHAR_SELECTED);
862 SetSentErrorMessage(true);
863 return false;
866 uint32 factionid = atoi(pfactionid);
867 uint32 flag;
869 char *pflag = strtok(NULL, " ");
870 if (!pflag)
871 flag = chr->GetUInt32Value(UNIT_FIELD_FLAGS);
872 else
873 flag = atoi(pflag);
875 char* pnpcflag = strtok(NULL, " ");
877 uint32 npcflag;
878 if(!pnpcflag)
879 npcflag = chr->GetUInt32Value(UNIT_NPC_FLAGS);
880 else
881 npcflag = atoi(pnpcflag);
883 char* pdyflag = strtok(NULL, " ");
885 uint32 dyflag;
886 if(!pdyflag)
887 dyflag = chr->GetUInt32Value(UNIT_DYNAMIC_FLAGS);
888 else
889 dyflag = atoi(pdyflag);
891 if(!sFactionTemplateStore.LookupEntry(factionid))
893 PSendSysMessage(LANG_WRONG_FACTION, factionid);
894 SetSentErrorMessage(true);
895 return false;
898 PSendSysMessage(LANG_YOU_CHANGE_FACTION, chr->GetGUIDLow(),factionid,flag,npcflag,dyflag);
900 chr->setFaction(factionid);
901 chr->SetUInt32Value(UNIT_FIELD_FLAGS,flag);
902 chr->SetUInt32Value(UNIT_NPC_FLAGS,npcflag);
903 chr->SetUInt32Value(UNIT_DYNAMIC_FLAGS,dyflag);
905 return true;
908 //Edit Player Spell
909 bool ChatHandler::HandleModifySpellCommand(const char* args)
911 if(!*args) return false;
912 char* pspellflatid = strtok((char*)args, " ");
913 if (!pspellflatid)
914 return false;
916 char* pop = strtok(NULL, " ");
917 if (!pop)
918 return false;
920 char* pval = strtok(NULL, " ");
921 if (!pval)
922 return false;
924 uint16 mark;
926 char* pmark = strtok(NULL, " ");
928 uint8 spellflatid = atoi(pspellflatid);
929 uint8 op = atoi(pop);
930 uint16 val = atoi(pval);
931 if(!pmark)
932 mark = 65535;
933 else
934 mark = atoi(pmark);
936 Player *chr = getSelectedPlayer();
937 if (chr == NULL)
939 SendSysMessage(LANG_NO_CHAR_SELECTED);
940 SetSentErrorMessage(true);
941 return false;
944 PSendSysMessage(LANG_YOU_CHANGE_SPELLFLATID, spellflatid, val, mark, chr->GetName());
945 if (needReportToTarget(chr))
946 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SPELLFLATID_CHANGED, GetName(), spellflatid, val, mark);
948 WorldPacket data(SMSG_SET_FLAT_SPELL_MODIFIER, (1+1+2+2));
949 data << uint8(spellflatid);
950 data << uint8(op);
951 data << uint16(val);
952 data << uint16(mark);
953 chr->GetSession()->SendPacket(&data);
955 return true;
958 //Edit Player TP
959 bool ChatHandler::HandleModifyTalentCommand (const char* args)
961 if (!*args)
962 return false;
964 int tp = atoi((char*)args);
965 if (tp>0)
967 Player* player = getSelectedPlayer();
968 if(!player)
970 SendSysMessage(LANG_NO_CHAR_SELECTED);
971 SetSentErrorMessage(true);
972 return false;
974 player->SetFreeTalentPoints(tp);
975 return true;
977 return false;
980 //Enable On\OFF all taxi paths
981 bool ChatHandler::HandleTaxiCheatCommand(const char* args)
983 if (!*args)
985 SendSysMessage(LANG_USE_BOL);
986 SetSentErrorMessage(true);
987 return false;
990 std::string argstr = (char*)args;
992 Player *chr = getSelectedPlayer();
993 if (!chr)
995 chr=m_session->GetPlayer();
998 if (argstr == "on")
1000 chr->SetTaxiCheater(true);
1001 PSendSysMessage(LANG_YOU_GIVE_TAXIS, chr->GetName());
1002 if (needReportToTarget(chr))
1003 ChatHandler(chr).PSendSysMessage(LANG_YOURS_TAXIS_ADDED, GetName());
1004 return true;
1007 if (argstr == "off")
1009 chr->SetTaxiCheater(false);
1010 PSendSysMessage(LANG_YOU_REMOVE_TAXIS, chr->GetName());
1011 if (needReportToTarget(chr))
1012 ChatHandler(chr).PSendSysMessage(LANG_YOURS_TAXIS_REMOVED, GetName());
1014 return true;
1017 SendSysMessage(LANG_USE_BOL);
1018 SetSentErrorMessage(true);
1019 return false;
1022 //Edit Player Aspeed
1023 bool ChatHandler::HandleModifyASpeedCommand(const char* args)
1025 if (!*args)
1026 return false;
1028 float ASpeed = (float)atof((char*)args);
1030 if (ASpeed > 10 || ASpeed < 0.1)
1032 SendSysMessage(LANG_BAD_VALUE);
1033 SetSentErrorMessage(true);
1034 return false;
1037 Player *chr = getSelectedPlayer();
1038 if (chr == NULL)
1040 SendSysMessage(LANG_NO_CHAR_SELECTED);
1041 SetSentErrorMessage(true);
1042 return false;
1045 if(chr->isInFlight())
1047 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chr->GetName());
1048 SetSentErrorMessage(true);
1049 return false;
1052 PSendSysMessage(LANG_YOU_CHANGE_ASPEED, ASpeed, chr->GetName());
1053 if (needReportToTarget(chr))
1054 ChatHandler(chr).PSendSysMessage(LANG_YOURS_ASPEED_CHANGED, GetName(), ASpeed);
1056 chr->SetSpeed(MOVE_WALK, ASpeed,true);
1057 chr->SetSpeed(MOVE_RUN, ASpeed,true);
1058 chr->SetSpeed(MOVE_SWIM, ASpeed,true);
1059 //chr->SetSpeed(MOVE_TURN, ASpeed,true);
1060 chr->SetSpeed(MOVE_FLIGHT, ASpeed,true);
1061 return true;
1064 //Edit Player Speed
1065 bool ChatHandler::HandleModifySpeedCommand(const char* args)
1067 if (!*args)
1068 return false;
1070 float Speed = (float)atof((char*)args);
1072 if (Speed > 10 || Speed < 0.1)
1074 SendSysMessage(LANG_BAD_VALUE);
1075 SetSentErrorMessage(true);
1076 return false;
1079 Player *chr = getSelectedPlayer();
1080 if (chr == NULL)
1082 SendSysMessage(LANG_NO_CHAR_SELECTED);
1083 SetSentErrorMessage(true);
1084 return false;
1087 if(chr->isInFlight())
1089 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chr->GetName());
1090 SetSentErrorMessage(true);
1091 return false;
1094 PSendSysMessage(LANG_YOU_CHANGE_SPEED, Speed, chr->GetName());
1095 if (needReportToTarget(chr))
1096 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SPEED_CHANGED, GetName(), Speed);
1098 chr->SetSpeed(MOVE_RUN,Speed,true);
1100 return true;
1103 //Edit Player Swim Speed
1104 bool ChatHandler::HandleModifySwimCommand(const char* args)
1106 if (!*args)
1107 return false;
1109 float Swim = (float)atof((char*)args);
1111 if (Swim > 10.0f || Swim < 0.01f)
1113 SendSysMessage(LANG_BAD_VALUE);
1114 SetSentErrorMessage(true);
1115 return false;
1118 Player *chr = getSelectedPlayer();
1119 if (chr == NULL)
1121 SendSysMessage(LANG_NO_CHAR_SELECTED);
1122 SetSentErrorMessage(true);
1123 return false;
1126 if(chr->isInFlight())
1128 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chr->GetName());
1129 SetSentErrorMessage(true);
1130 return false;
1133 PSendSysMessage(LANG_YOU_CHANGE_SWIM_SPEED, Swim, chr->GetName());
1134 if (needReportToTarget(chr))
1135 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SWIM_SPEED_CHANGED, GetName(), Swim);
1137 chr->SetSpeed(MOVE_SWIM,Swim,true);
1139 return true;
1142 //Edit Player Walk Speed
1143 bool ChatHandler::HandleModifyBWalkCommand(const char* args)
1145 if (!*args)
1146 return false;
1148 float BSpeed = (float)atof((char*)args);
1150 if (BSpeed > 10.0f || BSpeed < 0.1f)
1152 SendSysMessage(LANG_BAD_VALUE);
1153 SetSentErrorMessage(true);
1154 return false;
1157 Player *chr = getSelectedPlayer();
1158 if (chr == NULL)
1160 SendSysMessage(LANG_NO_CHAR_SELECTED);
1161 SetSentErrorMessage(true);
1162 return false;
1165 if(chr->isInFlight())
1167 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chr->GetName());
1168 SetSentErrorMessage(true);
1169 return false;
1172 PSendSysMessage(LANG_YOU_CHANGE_BACK_SPEED, BSpeed, chr->GetName());
1173 if (needReportToTarget(chr))
1174 ChatHandler(chr).PSendSysMessage(LANG_YOURS_BACK_SPEED_CHANGED, GetName(), BSpeed);
1176 chr->SetSpeed(MOVE_RUN_BACK,BSpeed,true);
1178 return true;
1181 //Edit Player Fly
1182 bool ChatHandler::HandleModifyFlyCommand(const char* args)
1184 if (!*args)
1185 return false;
1187 float FSpeed = (float)atof((char*)args);
1189 if (FSpeed > 10.0f || FSpeed < 0.1f)
1191 SendSysMessage(LANG_BAD_VALUE);
1192 SetSentErrorMessage(true);
1193 return false;
1196 Player *chr = getSelectedPlayer();
1197 if (chr == NULL)
1199 SendSysMessage(LANG_NO_CHAR_SELECTED);
1200 SetSentErrorMessage(true);
1201 return false;
1204 PSendSysMessage(LANG_YOU_CHANGE_FLY_SPEED, FSpeed, chr->GetName());
1205 if (needReportToTarget(chr))
1206 ChatHandler(chr).PSendSysMessage(LANG_YOURS_FLY_SPEED_CHANGED, GetName(), FSpeed);
1208 chr->SetSpeed(MOVE_FLIGHT,FSpeed,true);
1210 return true;
1213 //Edit Player Scale
1214 bool ChatHandler::HandleModifyScaleCommand(const char* args)
1216 if (!*args)
1217 return false;
1219 float Scale = (float)atof((char*)args);
1220 if (Scale > 3.0f || Scale <= 0.0f)
1222 SendSysMessage(LANG_BAD_VALUE);
1223 SetSentErrorMessage(true);
1224 return false;
1227 Player *chr = getSelectedPlayer();
1228 if (chr == NULL)
1230 SendSysMessage(LANG_NO_CHAR_SELECTED);
1231 SetSentErrorMessage(true);
1232 return false;
1235 PSendSysMessage(LANG_YOU_CHANGE_SIZE, Scale, chr->GetName());
1236 if (needReportToTarget(chr))
1237 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SIZE_CHANGED, GetName(), Scale);
1239 chr->SetFloatValue(OBJECT_FIELD_SCALE_X, Scale);
1241 return true;
1244 //Enable Player mount
1245 bool ChatHandler::HandleModifyMountCommand(const char* args)
1247 if(!*args)
1248 return false;
1250 uint16 mId = 1147;
1251 float speed = (float)15;
1252 uint32 num = 0;
1254 num = atoi((char*)args);
1255 switch(num)
1257 case 1:
1258 mId=14340;
1259 break;
1260 case 2:
1261 mId=4806;
1262 break;
1263 case 3:
1264 mId=6471;
1265 break;
1266 case 4:
1267 mId=12345;
1268 break;
1269 case 5:
1270 mId=6472;
1271 break;
1272 case 6:
1273 mId=6473;
1274 break;
1275 case 7:
1276 mId=10670;
1277 break;
1278 case 8:
1279 mId=10719;
1280 break;
1281 case 9:
1282 mId=10671;
1283 break;
1284 case 10:
1285 mId=10672;
1286 break;
1287 case 11:
1288 mId=10720;
1289 break;
1290 case 12:
1291 mId=14349;
1292 break;
1293 case 13:
1294 mId=11641;
1295 break;
1296 case 14:
1297 mId=12244;
1298 break;
1299 case 15:
1300 mId=12242;
1301 break;
1302 case 16:
1303 mId=14578;
1304 break;
1305 case 17:
1306 mId=14579;
1307 break;
1308 case 18:
1309 mId=14349;
1310 break;
1311 case 19:
1312 mId=12245;
1313 break;
1314 case 20:
1315 mId=14335;
1316 break;
1317 case 21:
1318 mId=207;
1319 break;
1320 case 22:
1321 mId=2328;
1322 break;
1323 case 23:
1324 mId=2327;
1325 break;
1326 case 24:
1327 mId=2326;
1328 break;
1329 case 25:
1330 mId=14573;
1331 break;
1332 case 26:
1333 mId=14574;
1334 break;
1335 case 27:
1336 mId=14575;
1337 break;
1338 case 28:
1339 mId=604;
1340 break;
1341 case 29:
1342 mId=1166;
1343 break;
1344 case 30:
1345 mId=2402;
1346 break;
1347 case 31:
1348 mId=2410;
1349 break;
1350 case 32:
1351 mId=2409;
1352 break;
1353 case 33:
1354 mId=2408;
1355 break;
1356 case 34:
1357 mId=2405;
1358 break;
1359 case 35:
1360 mId=14337;
1361 break;
1362 case 36:
1363 mId=6569;
1364 break;
1365 case 37:
1366 mId=10661;
1367 break;
1368 case 38:
1369 mId=10666;
1370 break;
1371 case 39:
1372 mId=9473;
1373 break;
1374 case 40:
1375 mId=9476;
1376 break;
1377 case 41:
1378 mId=9474;
1379 break;
1380 case 42:
1381 mId=14374;
1382 break;
1383 case 43:
1384 mId=14376;
1385 break;
1386 case 44:
1387 mId=14377;
1388 break;
1389 case 45:
1390 mId=2404;
1391 break;
1392 case 46:
1393 mId=2784;
1394 break;
1395 case 47:
1396 mId=2787;
1397 break;
1398 case 48:
1399 mId=2785;
1400 break;
1401 case 49:
1402 mId=2736;
1403 break;
1404 case 50:
1405 mId=2786;
1406 break;
1407 case 51:
1408 mId=14347;
1409 break;
1410 case 52:
1411 mId=14346;
1412 break;
1413 case 53:
1414 mId=14576;
1415 break;
1416 case 54:
1417 mId=9695;
1418 break;
1419 case 55:
1420 mId=9991;
1421 break;
1422 case 56:
1423 mId=6448;
1424 break;
1425 case 57:
1426 mId=6444;
1427 break;
1428 case 58:
1429 mId=6080;
1430 break;
1431 case 59:
1432 mId=6447;
1433 break;
1434 case 60:
1435 mId=4805;
1436 break;
1437 case 61:
1438 mId=9714;
1439 break;
1440 case 62:
1441 mId=6448;
1442 break;
1443 case 63:
1444 mId=6442;
1445 break;
1446 case 64:
1447 mId=14632;
1448 break;
1449 case 65:
1450 mId=14332;
1451 break;
1452 case 66:
1453 mId=14331;
1454 break;
1455 case 67:
1456 mId=8469;
1457 break;
1458 case 68:
1459 mId=2830;
1460 break;
1461 case 69:
1462 mId=2346;
1463 break;
1464 default:
1465 SendSysMessage(LANG_NO_MOUNT);
1466 SetSentErrorMessage(true);
1467 return false;
1470 Player *chr = getSelectedPlayer();
1471 if (chr == NULL)
1473 SendSysMessage(LANG_NO_CHAR_SELECTED);
1474 SetSentErrorMessage(true);
1475 return false;
1478 PSendSysMessage(LANG_YOU_GIVE_MOUNT, chr->GetName());
1479 if (needReportToTarget(chr))
1480 ChatHandler(chr).PSendSysMessage(LANG_MOUNT_GIVED, GetName());
1482 chr->SetUInt32Value( UNIT_FIELD_FLAGS , 0x001000 );
1483 chr->Mount(mId);
1485 WorldPacket data( SMSG_FORCE_RUN_SPEED_CHANGE, (8+4+1+4) );
1486 data.append(chr->GetPackGUID());
1487 data << (uint32)0;
1488 data << (uint8)0; //new 2.1.0
1489 data << float(speed);
1490 chr->SendMessageToSet( &data, true );
1492 data.Initialize( SMSG_FORCE_SWIM_SPEED_CHANGE, (8+4+4) );
1493 data.append(chr->GetPackGUID());
1494 data << (uint32)0;
1495 data << float(speed);
1496 chr->SendMessageToSet( &data, true );
1498 return true;
1501 //Edit Player money
1502 bool ChatHandler::HandleModifyMoneyCommand(const char* args)
1504 if (!*args)
1505 return false;
1507 Player *chr = getSelectedPlayer();
1508 if (chr == NULL)
1510 SendSysMessage(LANG_NO_CHAR_SELECTED);
1511 SetSentErrorMessage(true);
1512 return false;
1515 int32 addmoney = atoi((char*)args);
1517 uint32 moneyuser = chr->GetMoney();
1519 if(addmoney < 0)
1521 int32 newmoney = moneyuser + addmoney;
1523 sLog.outDetail(GetMangosString(LANG_CURRENT_MONEY), moneyuser, addmoney, newmoney);
1524 if(newmoney <= 0 )
1526 PSendSysMessage(LANG_YOU_TAKE_ALL_MONEY, chr->GetName());
1527 if (needReportToTarget(chr))
1528 ChatHandler(chr).PSendSysMessage(LANG_YOURS_ALL_MONEY_GONE, GetName());
1530 chr->SetMoney(0);
1532 else
1534 PSendSysMessage(LANG_YOU_TAKE_MONEY, abs(addmoney), chr->GetName());
1535 if (needReportToTarget(chr))
1536 ChatHandler(chr).PSendSysMessage(LANG_YOURS_MONEY_TAKEN, GetName(), abs(addmoney));
1537 chr->SetMoney( newmoney );
1540 else
1542 PSendSysMessage(LANG_YOU_GIVE_MONEY, addmoney, chr->GetName());
1543 if (needReportToTarget(chr))
1544 ChatHandler(chr).PSendSysMessage(LANG_YOURS_MONEY_GIVEN, GetName(), addmoney);
1545 chr->ModifyMoney( addmoney );
1548 sLog.outDetail(GetMangosString(LANG_NEW_MONEY), moneyuser, addmoney, chr->GetMoney() );
1550 return true;
1553 //Edit Player field
1554 bool ChatHandler::HandleModifyBitCommand(const char* args)
1556 if( !*args )
1557 return false;
1559 Player *chr = getSelectedPlayer();
1560 if (chr == NULL)
1562 SendSysMessage(LANG_NO_CHAR_SELECTED);
1563 SetSentErrorMessage(true);
1564 return false;
1567 char* pField = strtok((char*)args, " ");
1568 if (!pField)
1569 return false;
1571 char* pBit = strtok(NULL, " ");
1572 if (!pBit)
1573 return false;
1575 uint16 field = atoi(pField);
1576 uint32 bit = atoi(pBit);
1578 if (field < 1 || field >= PLAYER_END)
1580 SendSysMessage(LANG_BAD_VALUE);
1581 SetSentErrorMessage(true);
1582 return false;
1585 if (bit < 1 || bit > 32)
1587 SendSysMessage(LANG_BAD_VALUE);
1588 SetSentErrorMessage(true);
1589 return false;
1592 if ( chr->HasFlag( field, (1<<(bit-1)) ) )
1594 chr->RemoveFlag( field, (1<<(bit-1)) );
1595 PSendSysMessage(LANG_REMOVE_BIT, bit, field);
1597 else
1599 chr->SetFlag( field, (1<<(bit-1)) );
1600 PSendSysMessage(LANG_SET_BIT, bit, field);
1603 return true;
1606 bool ChatHandler::HandleModifyHonorCommand (const char* args)
1608 if (!*args)
1609 return false;
1611 Player *target = getSelectedPlayer();
1612 if(!target)
1614 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1615 SetSentErrorMessage(true);
1616 return false;
1619 int32 amount = (uint32)atoi(args);
1621 target->ModifyHonorPoints(amount);
1623 PSendSysMessage(LANG_COMMAND_MODIFY_HONOR, target->GetName(), target->GetHonorPoints());
1625 return true;
1628 bool ChatHandler::HandleTeleCommand(const char * args)
1630 if(!*args)
1631 return false;
1633 Player* _player = m_session->GetPlayer();
1635 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
1636 GameTele const* tele = extractGameTeleFromLink((char*)args);
1638 if (!tele)
1640 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
1641 SetSentErrorMessage(true);
1642 return false;
1645 // stop flight if need
1646 if(_player->isInFlight())
1648 _player->GetMotionMaster()->MovementExpired();
1649 _player->m_taxi.ClearTaxiDestinations();
1651 // save only in non-flight case
1652 else
1653 _player->SaveRecallPosition();
1655 _player->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
1656 return true;
1659 bool ChatHandler::HandleLookupAreaCommand(const char* args)
1661 if (!*args)
1662 return false;
1664 std::string namepart = args;
1665 std::wstring wnamepart;
1667 if (!Utf8toWStr (namepart,wnamepart))
1668 return false;
1670 uint32 counter = 0; // Counter for figure out that we found smth.
1672 // converting string that we try to find to lower case
1673 wstrToLower (wnamepart);
1675 // Search in AreaTable.dbc
1676 for (uint32 areaflag = 0; areaflag < sAreaStore.GetNumRows (); ++areaflag)
1678 AreaTableEntry const *areaEntry = sAreaStore.LookupEntry (areaflag);
1679 if (areaEntry)
1681 int loc = m_session ? m_session->GetSessionDbcLocale () : sWorld.GetDefaultDbcLocale();
1682 std::string name = areaEntry->area_name[loc];
1683 if (name.empty())
1684 continue;
1686 if (!Utf8FitTo (name, wnamepart))
1688 loc = 0;
1689 for(; loc < MAX_LOCALE; ++loc)
1691 if (m_session && loc==m_session->GetSessionDbcLocale ())
1692 continue;
1694 name = areaEntry->area_name[loc];
1695 if (name.empty ())
1696 continue;
1698 if (Utf8FitTo (name, wnamepart))
1699 break;
1703 if (loc < MAX_LOCALE)
1705 // send area in "id - [name]" format
1706 std::ostringstream ss;
1707 if (m_session)
1708 ss << areaEntry->ID << " - |cffffffff|Harea:" << areaEntry->ID << "|h[" << name << " " << localeNames[loc]<< "]|h|r";
1709 else
1710 ss << areaEntry->ID << " - " << name << " " << localeNames[loc];
1712 SendSysMessage (ss.str ().c_str());
1714 ++counter;
1719 if (counter == 0) // if counter == 0 then we found nth
1720 SendSysMessage (LANG_COMMAND_NOAREAFOUND);
1722 return true;
1725 //Find tele in game_tele order by name
1726 bool ChatHandler::HandleLookupTeleCommand(const char * args)
1728 if(!*args)
1730 SendSysMessage(LANG_COMMAND_TELE_PARAMETER);
1731 SetSentErrorMessage(true);
1732 return false;
1735 char const* str = strtok((char*)args, " ");
1736 if(!str)
1737 return false;
1739 std::string namepart = str;
1740 std::wstring wnamepart;
1742 if(!Utf8toWStr(namepart,wnamepart))
1743 return false;
1745 // converting string that we try to find to lower case
1746 wstrToLower( wnamepart );
1748 std::ostringstream reply;
1750 GameTeleMap const & teleMap = objmgr.GetGameTeleMap();
1751 for(GameTeleMap::const_iterator itr = teleMap.begin(); itr != teleMap.end(); ++itr)
1753 GameTele const* tele = &itr->second;
1755 if(tele->wnameLow.find(wnamepart) == std::wstring::npos)
1756 continue;
1758 if (m_session)
1759 reply << " |cffffffff|Htele:" << itr->first << "|h[" << tele->name << "]|h|r\n";
1760 else
1761 reply << " " << itr->first << " " << tele->name << "\n";
1764 if(reply.str().empty())
1765 SendSysMessage(LANG_COMMAND_TELE_NOLOCATION);
1766 else
1767 PSendSysMessage(LANG_COMMAND_TELE_LOCATION,reply.str().c_str());
1769 return true;
1772 //Enable\Dissable accept whispers (for GM)
1773 bool ChatHandler::HandleWhispersCommand(const char* args)
1775 if(!*args)
1777 PSendSysMessage(LANG_COMMAND_WHISPERACCEPTING, m_session->GetPlayer()->isAcceptWhispers() ? GetMangosString(LANG_ON) : GetMangosString(LANG_OFF));
1778 return true;
1781 std::string argstr = (char*)args;
1782 // whisper on
1783 if (argstr == "on")
1785 m_session->GetPlayer()->SetAcceptWhispers(true);
1786 SendSysMessage(LANG_COMMAND_WHISPERON);
1787 return true;
1790 // whisper off
1791 if (argstr == "off")
1793 m_session->GetPlayer()->SetAcceptWhispers(false);
1794 SendSysMessage(LANG_COMMAND_WHISPEROFF);
1795 return true;
1798 SendSysMessage(LANG_USE_BOL);
1799 SetSentErrorMessage(true);
1800 return false;
1803 //Play sound
1804 bool ChatHandler::HandlePlaySoundCommand(const char* args)
1806 // USAGE: .debug playsound #soundid
1807 // #soundid - ID decimal number from SoundEntries.dbc (1st column)
1808 // this file have about 5000 sounds.
1809 // In this realization only caller can hear this sound.
1810 if( *args )
1812 uint32 dwSoundId = atoi((char*)args);
1814 if( !sSoundEntriesStore.LookupEntry(dwSoundId) )
1816 PSendSysMessage(LANG_SOUND_NOT_EXIST, dwSoundId);
1817 SetSentErrorMessage(true);
1818 return false;
1821 WorldPacket data(SMSG_PLAY_OBJECT_SOUND,4+8);
1822 data << uint32(dwSoundId) << m_session->GetPlayer()->GetGUID();
1823 m_session->SendPacket(&data);
1825 PSendSysMessage(LANG_YOU_HEAR_SOUND, dwSoundId);
1826 return true;
1829 return false;
1832 //Save all players in the world
1833 bool ChatHandler::HandleSaveAllCommand(const char* /*args*/)
1835 ObjectAccessor::Instance().SaveAllPlayers();
1836 SendSysMessage(LANG_PLAYERS_SAVED);
1837 return true;
1840 //Send mail by command
1841 bool ChatHandler::HandleSendMailCommand(const char* args)
1843 if(!*args)
1844 return false;
1846 // format: name "subject text" "mail text"
1848 char* pName = strtok((char*)args, " ");
1849 if(!pName)
1850 return false;
1852 char* tail1 = strtok(NULL, "");
1853 if(!tail1)
1854 return false;
1856 char* msgSubject;
1857 if(*tail1=='"')
1858 msgSubject = strtok(tail1+1, "\"");
1859 else
1861 char* space = strtok(tail1, "\"");
1862 if(!space)
1863 return false;
1864 msgSubject = strtok(NULL, "\"");
1867 if (!msgSubject)
1868 return false;
1870 char* tail2 = strtok(NULL, "");
1871 if(!tail2)
1872 return false;
1874 char* msgText;
1875 if(*tail2=='"')
1876 msgText = strtok(tail2+1, "\"");
1877 else
1879 char* space = strtok(tail2, "\"");
1880 if(!space)
1881 return false;
1882 msgText = strtok(NULL, "\"");
1885 if (!msgText)
1886 return false;
1888 // pName, msgSubject, msgText isn't NUL after prev. check
1889 std::string name = pName;
1890 std::string subject = msgSubject;
1891 std::string text = msgText;
1893 if(!normalizePlayerName(name))
1895 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1896 SetSentErrorMessage(true);
1897 return false;
1900 uint64 receiver_guid = objmgr.GetPlayerGUIDByName(name);
1901 if(!receiver_guid)
1903 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1904 SetSentErrorMessage(true);
1905 return false;
1908 // from console show not existed sender
1909 uint32 sender_guidlo = m_session ? m_session->GetPlayer()->GetGUIDLow() : 0;
1911 uint32 messagetype = MAIL_NORMAL;
1912 uint32 stationery = MAIL_STATIONERY_GM;
1913 uint32 itemTextId = !text.empty() ? objmgr.CreateItemText( text ) : 0;
1915 Player *receiver = objmgr.GetPlayer(receiver_guid);
1917 WorldSession::SendMailTo(receiver,messagetype, stationery, sender_guidlo, GUID_LOPART(receiver_guid), subject, itemTextId, NULL, 0, 0, MAIL_CHECK_MASK_NONE);
1919 PSendSysMessage(LANG_MAIL_SENT, name.c_str());
1920 return true;
1923 // teleport player to given game_tele.entry
1924 bool ChatHandler::HandleNameTeleCommand(const char * args)
1926 if(!*args)
1927 return false;
1929 char* pName = strtok((char*)args, " ");
1931 if(!pName)
1932 return false;
1934 std::string name = pName;
1936 if(!normalizePlayerName(name))
1938 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1939 SetSentErrorMessage(true);
1940 return false;
1943 char* tail = strtok(NULL, "");
1944 if(!tail)
1945 return false;
1947 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
1948 GameTele const* tele = extractGameTeleFromLink(tail);
1949 if(!tele)
1951 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
1952 SetSentErrorMessage(true);
1953 return false;
1956 Player *chr = objmgr.GetPlayer(name.c_str());
1957 if (chr)
1960 if(chr->IsBeingTeleported()==true)
1962 PSendSysMessage(LANG_IS_TELEPORTED, chr->GetName());
1963 SetSentErrorMessage(true);
1964 return false;
1967 PSendSysMessage(LANG_TELEPORTING_TO, chr->GetName(),"", tele->name.c_str());
1968 if (needReportToTarget(chr))
1969 ChatHandler(chr).PSendSysMessage(LANG_TELEPORTED_TO_BY, GetName());
1971 // stop flight if need
1972 if(chr->isInFlight())
1974 chr->GetMotionMaster()->MovementExpired();
1975 chr->m_taxi.ClearTaxiDestinations();
1977 // save only in non-flight case
1978 else
1979 chr->SaveRecallPosition();
1981 chr->TeleportTo(tele->mapId,tele->position_x,tele->position_y,tele->position_z,tele->orientation);
1983 else if (uint64 guid = objmgr.GetPlayerGUIDByName(name.c_str()))
1985 PSendSysMessage(LANG_TELEPORTING_TO, name.c_str(), GetMangosString(LANG_OFFLINE), tele->name.c_str());
1986 Player::SavePositionInDB(tele->mapId,tele->position_x,tele->position_y,tele->position_z,tele->orientation,MapManager::Instance().GetZoneId(tele->mapId,tele->position_x,tele->position_y),guid);
1988 else
1989 PSendSysMessage(LANG_NO_PLAYER, name.c_str());
1991 return true;
1994 //Teleport group to given game_tele.entry
1995 bool ChatHandler::HandleGroupTeleCommand(const char * args)
1997 if(!*args)
1998 return false;
2000 Player *player = getSelectedPlayer();
2001 if (!player)
2003 SendSysMessage(LANG_NO_CHAR_SELECTED);
2004 SetSentErrorMessage(true);
2005 return false;
2008 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2009 GameTele const* tele = extractGameTeleFromLink((char*)args);
2010 if(!tele)
2012 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
2013 SetSentErrorMessage(true);
2014 return false;
2017 Group *grp = player->GetGroup();
2018 if(!grp)
2020 PSendSysMessage(LANG_NOT_IN_GROUP,player->GetName());
2021 SetSentErrorMessage(true);
2022 return false;
2025 for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
2027 Player *pl = itr->getSource();
2029 if(!pl || !pl->GetSession() )
2030 continue;
2032 if(pl->IsBeingTeleported())
2034 PSendSysMessage(LANG_IS_TELEPORTED, pl->GetName());
2035 continue;
2038 PSendSysMessage(LANG_TELEPORTING_TO, pl->GetName(),"", tele->name.c_str());
2039 if (needReportToTarget(pl))
2040 ChatHandler(pl).PSendSysMessage(LANG_TELEPORTED_TO_BY, GetName());
2042 // stop flight if need
2043 if(pl->isInFlight())
2045 pl->GetMotionMaster()->MovementExpired();
2046 pl->m_taxi.ClearTaxiDestinations();
2048 // save only in non-flight case
2049 else
2050 pl->SaveRecallPosition();
2052 pl->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
2055 return true;
2058 //Summon group of player
2059 bool ChatHandler::HandleGroupgoCommand(const char* args)
2061 if(!*args)
2062 return false;
2064 std::string name = args;
2066 if(!normalizePlayerName(name))
2068 SendSysMessage(LANG_PLAYER_NOT_FOUND);
2069 SetSentErrorMessage(true);
2070 return false;
2073 Player *player = objmgr.GetPlayer(name.c_str());
2074 if (!player)
2076 PSendSysMessage(LANG_NO_PLAYER, args);
2077 SetSentErrorMessage(true);
2078 return false;
2081 Group *grp = player->GetGroup();
2083 if(!grp)
2085 PSendSysMessage(LANG_NOT_IN_GROUP,player->GetName());
2086 SetSentErrorMessage(true);
2087 return false;
2090 Map* gmMap = m_session->GetPlayer()->GetMap();
2091 bool to_instance = gmMap->Instanceable();
2093 // we are in instance, and can summon only player in our group with us as lead
2094 if ( to_instance && (
2095 !m_session->GetPlayer()->GetGroup() || (grp->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ||
2096 (m_session->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ) )
2097 // the last check is a bit excessive, but let it be, just in case
2099 SendSysMessage(LANG_CANNOT_SUMMON_TO_INST);
2100 SetSentErrorMessage(true);
2101 return false;
2104 for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
2106 Player *pl = itr->getSource();
2108 if(!pl || pl==m_session->GetPlayer() || !pl->GetSession() )
2109 continue;
2111 if(pl->IsBeingTeleported()==true)
2113 PSendSysMessage(LANG_IS_TELEPORTED, pl->GetName());
2114 SetSentErrorMessage(true);
2115 return false;
2118 if (to_instance)
2120 Map* plMap = pl->GetMap();
2122 if ( plMap->Instanceable() && plMap->GetInstanceId() != gmMap->GetInstanceId() )
2124 // cannot summon from instance to instance
2125 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,pl->GetName());
2126 SetSentErrorMessage(true);
2127 return false;
2131 PSendSysMessage(LANG_SUMMONING, pl->GetName(),"");
2132 if (needReportToTarget(pl))
2133 ChatHandler(pl).PSendSysMessage(LANG_SUMMONED_BY, GetName());
2135 // stop flight if need
2136 if(pl->isInFlight())
2138 pl->GetMotionMaster()->MovementExpired();
2139 pl->m_taxi.ClearTaxiDestinations();
2141 // save only in non-flight case
2142 else
2143 pl->SaveRecallPosition();
2145 // before GM
2146 float x,y,z;
2147 m_session->GetPlayer()->GetClosePoint(x,y,z,pl->GetObjectSize());
2148 pl->TeleportTo(m_session->GetPlayer()->GetMapId(),x,y,z,pl->GetOrientation());
2151 return true;
2154 //teleport at coordinates
2155 bool ChatHandler::HandleGoXYCommand(const char* args)
2157 if(!*args)
2158 return false;
2160 Player* _player = m_session->GetPlayer();
2162 char* px = strtok((char*)args, " ");
2163 char* py = strtok(NULL, " ");
2164 char* pmapid = strtok(NULL, " ");
2166 if (!px || !py)
2167 return false;
2169 float x = (float)atof(px);
2170 float y = (float)atof(py);
2171 uint32 mapid;
2172 if (pmapid)
2173 mapid = (uint32)atoi(pmapid);
2174 else mapid = _player->GetMapId();
2176 if(!MapManager::IsValidMapCoord(mapid,x,y))
2178 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
2179 SetSentErrorMessage(true);
2180 return false;
2183 // stop flight if need
2184 if(_player->isInFlight())
2186 _player->GetMotionMaster()->MovementExpired();
2187 _player->m_taxi.ClearTaxiDestinations();
2189 // save only in non-flight case
2190 else
2191 _player->SaveRecallPosition();
2193 Map const *map = MapManager::Instance().GetBaseMap(mapid);
2194 float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
2196 _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
2198 return true;
2201 //teleport at coordinates, including Z
2202 bool ChatHandler::HandleGoXYZCommand(const char* args)
2204 if(!*args)
2205 return false;
2207 Player* _player = m_session->GetPlayer();
2209 char* px = strtok((char*)args, " ");
2210 char* py = strtok(NULL, " ");
2211 char* pz = strtok(NULL, " ");
2212 char* pmapid = strtok(NULL, " ");
2214 if (!px || !py || !pz)
2215 return false;
2217 float x = (float)atof(px);
2218 float y = (float)atof(py);
2219 float z = (float)atof(pz);
2220 uint32 mapid;
2221 if (pmapid)
2222 mapid = (uint32)atoi(pmapid);
2223 else
2224 mapid = _player->GetMapId();
2226 if(!MapManager::IsValidMapCoord(mapid,x,y,z))
2228 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
2229 SetSentErrorMessage(true);
2230 return false;
2233 // stop flight if need
2234 if(_player->isInFlight())
2236 _player->GetMotionMaster()->MovementExpired();
2237 _player->m_taxi.ClearTaxiDestinations();
2239 // save only in non-flight case
2240 else
2241 _player->SaveRecallPosition();
2243 _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
2245 return true;
2248 //teleport at coordinates
2249 bool ChatHandler::HandleGoZoneXYCommand(const char* args)
2251 if(!*args)
2252 return false;
2254 Player* _player = m_session->GetPlayer();
2256 char* px = strtok((char*)args, " ");
2257 char* py = strtok(NULL, " ");
2258 char* tail = strtok(NULL,"");
2260 char* cAreaId = extractKeyFromLink(tail,"Harea"); // string or [name] Shift-click form |color|Harea:area_id|h[name]|h|r
2262 if (!px || !py)
2263 return false;
2265 float x = (float)atof(px);
2266 float y = (float)atof(py);
2267 uint32 areaid = cAreaId ? (uint32)atoi(cAreaId) : _player->GetZoneId();
2269 AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(areaid);
2271 if( x<0 || x>100 || y<0 || y>100 || !areaEntry )
2273 PSendSysMessage(LANG_INVALID_ZONE_COORD,x,y,areaid);
2274 SetSentErrorMessage(true);
2275 return false;
2278 // update to parent zone if exist (client map show only zones without parents)
2279 AreaTableEntry const* zoneEntry = areaEntry->zone ? GetAreaEntryByAreaID(areaEntry->zone) : areaEntry;
2281 Map const *map = MapManager::Instance().GetBaseMap(zoneEntry->mapid);
2283 if(map->Instanceable())
2285 PSendSysMessage(LANG_INVALID_ZONE_MAP,areaEntry->ID,areaEntry->area_name[m_session->GetSessionDbcLocale()],map->GetId(),map->GetMapName());
2286 SetSentErrorMessage(true);
2287 return false;
2290 Zone2MapCoordinates(x,y,zoneEntry->ID);
2292 if(!MapManager::IsValidMapCoord(zoneEntry->mapid,x,y))
2294 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,zoneEntry->mapid);
2295 SetSentErrorMessage(true);
2296 return false;
2299 // stop flight if need
2300 if(_player->isInFlight())
2302 _player->GetMotionMaster()->MovementExpired();
2303 _player->m_taxi.ClearTaxiDestinations();
2305 // save only in non-flight case
2306 else
2307 _player->SaveRecallPosition();
2309 float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
2310 _player->TeleportTo(zoneEntry->mapid, x, y, z, _player->GetOrientation());
2312 return true;
2315 //teleport to grid
2316 bool ChatHandler::HandleGoGridCommand(const char* args)
2318 if(!*args) return false;
2319 Player* _player = m_session->GetPlayer();
2321 char* px = strtok((char*)args, " ");
2322 char* py = strtok(NULL, " ");
2323 char* pmapid = strtok(NULL, " ");
2325 if (!px || !py)
2326 return false;
2328 float grid_x = (float)atof(px);
2329 float grid_y = (float)atof(py);
2330 uint32 mapid;
2331 if (pmapid)
2332 mapid = (uint32)atoi(pmapid);
2333 else mapid = _player->GetMapId();
2335 // center of grid
2336 float x = (grid_x-CENTER_GRID_ID+0.5f)*SIZE_OF_GRIDS;
2337 float y = (grid_y-CENTER_GRID_ID+0.5f)*SIZE_OF_GRIDS;
2339 if(!MapManager::IsValidMapCoord(mapid,x,y))
2341 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
2342 SetSentErrorMessage(true);
2343 return false;
2346 // stop flight if need
2347 if(_player->isInFlight())
2349 _player->GetMotionMaster()->MovementExpired();
2350 _player->m_taxi.ClearTaxiDestinations();
2352 // save only in non-flight case
2353 else
2354 _player->SaveRecallPosition();
2356 Map const *map = MapManager::Instance().GetBaseMap(mapid);
2357 float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
2358 _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
2360 return true;
2363 bool ChatHandler::HandleDrunkCommand(const char* args)
2365 if(!*args) return false;
2367 uint32 drunklevel = (uint32)atoi(args);
2368 if(drunklevel > 100)
2369 drunklevel = 100;
2371 uint16 drunkMod = drunklevel * 0xFFFF / 100;
2373 m_session->GetPlayer()->SetDrunkValue(drunkMod);
2375 return true;