[2008_11_09_01_mangos_command.sql] Create new command .senditems and remove from...
[auctionmangos.git] / src / game / Level1.cpp
blob3bb2475cde36dd623671e57c244c5bd664378370
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 = MapManager::Instance().GetMap(obj->GetMapId(), obj);
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 = MapManager::Instance().GetMap(m_session->GetPlayer()->GetMapId(),m_session->GetPlayer());
354 if(pMap->Instanceable())
356 Map* cMap = MapManager::Instance().GetMap(chr->GetMapId(),chr);
357 if( cMap->Instanceable() && cMap->GetInstanceId() != pMap->GetInstanceId() )
359 // cannot summon from instance to instance
360 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,chr->GetName());
361 SetSentErrorMessage(true);
362 return false;
365 // we are in instance, and can summon only player in our group with us as lead
366 if ( !m_session->GetPlayer()->GetGroup() || !chr->GetGroup() ||
367 (chr->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ||
368 (m_session->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) )
369 // the last check is a bit excessive, but let it be, just in case
371 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,chr->GetName());
372 SetSentErrorMessage(true);
373 return false;
377 PSendSysMessage(LANG_SUMMONING, chr->GetName(),"");
378 if (needReportToTarget(chr))
379 ChatHandler(chr).PSendSysMessage(LANG_SUMMONED_BY, GetName());
381 // stop flight if need
382 if(chr->isInFlight())
384 chr->GetMotionMaster()->MovementExpired();
385 chr->m_taxi.ClearTaxiDestinations();
387 // save only in non-flight case
388 else
389 chr->SaveRecallPosition();
391 // before GM
392 float x,y,z;
393 m_session->GetPlayer()->GetClosePoint(x,y,z,chr->GetObjectSize());
394 chr->TeleportTo(m_session->GetPlayer()->GetMapId(),x,y,z,chr->GetOrientation());
396 else if (uint64 guid = objmgr.GetPlayerGUIDByName(name))
398 PSendSysMessage(LANG_SUMMONING, name.c_str(),GetMangosString(LANG_OFFLINE));
400 // in point where GM stay
401 Player::SavePositionInDB(m_session->GetPlayer()->GetMapId(),
402 m_session->GetPlayer()->GetPositionX(),
403 m_session->GetPlayer()->GetPositionY(),
404 m_session->GetPlayer()->GetPositionZ(),
405 m_session->GetPlayer()->GetOrientation(),
406 m_session->GetPlayer()->GetZoneId(),
407 guid);
409 else
411 PSendSysMessage(LANG_NO_PLAYER, args);
412 SetSentErrorMessage(true);
415 return true;
418 //Teleport to Player
419 bool ChatHandler::HandleGonameCommand(const char* args)
421 if(!*args)
422 return false;
424 Player* _player = m_session->GetPlayer();
426 std::string name = args;
428 if(!normalizePlayerName(name))
430 SendSysMessage(LANG_PLAYER_NOT_FOUND);
431 SetSentErrorMessage(true);
432 return false;
435 Player *chr = objmgr.GetPlayer(name.c_str());
436 if (chr)
438 Map* cMap = MapManager::Instance().GetMap(chr->GetMapId(),chr);
439 if(cMap->Instanceable())
441 // we have to go to instance, and can go to player only if:
442 // 1) we are in his group (either as leader or as member)
443 // 2) we are not bound to any group and have GM mode on
444 if (_player->GetGroup())
446 // we are in group, we can go only if we are in the player group
447 if (_player->GetGroup() != chr->GetGroup())
449 PSendSysMessage(LANG_CANNOT_GO_TO_INST_PARTY,chr->GetName());
450 SetSentErrorMessage(true);
451 return false;
454 else
456 // we are not in group, let's verify our GM mode
457 if (!_player->isGameMaster())
459 PSendSysMessage(LANG_CANNOT_GO_TO_INST_GM,chr->GetName());
460 SetSentErrorMessage(true);
461 return false;
465 // if the player or the player's group is bound to another instance
466 // the player will not be bound to another one
467 InstancePlayerBind *pBind = _player->GetBoundInstance(chr->GetMapId(), chr->GetDifficulty());
468 if(!pBind)
470 Group *group = _player->GetGroup();
471 InstanceGroupBind *gBind = group ? group->GetBoundInstance(chr->GetMapId(), chr->GetDifficulty()) : NULL;
472 if(!gBind)
474 // if no bind exists, create a solo bind
475 InstanceSave *save = sInstanceSaveManager.GetInstanceSave(chr->GetInstanceId());
476 if(save) _player->BindToInstance(save, !save->CanReset());
480 _player->SetDifficulty(chr->GetDifficulty());
483 PSendSysMessage(LANG_APPEARING_AT, chr->GetName());
485 if (_player->IsVisibleGloballyFor(chr))
486 ChatHandler(chr).PSendSysMessage(LANG_APPEARING_TO, _player->GetName());
488 // stop flight if need
489 if(_player->isInFlight())
491 _player->GetMotionMaster()->MovementExpired();
492 _player->m_taxi.ClearTaxiDestinations();
494 // save only in non-flight case
495 else
496 _player->SaveRecallPosition();
498 // to point to see at target with same orientation
499 float x,y,z;
500 chr->GetContactPoint(m_session->GetPlayer(),x,y,z);
502 _player->TeleportTo(chr->GetMapId(), x, y, z, _player->GetAngle( chr ), TELE_TO_GM_MODE);
504 return true;
507 if (uint64 guid = objmgr.GetPlayerGUIDByName(name))
509 PSendSysMessage(LANG_APPEARING_AT, name.c_str());
511 // to point where player stay (if loaded)
512 float x,y,z,o;
513 uint32 map;
514 bool in_flight;
515 if(Player::LoadPositionFromDB(map,x,y,z,o,in_flight,guid))
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 _player->TeleportTo(map, x, y, z,_player->GetOrientation());
528 return true;
532 PSendSysMessage(LANG_NO_PLAYER, args);
534 SetSentErrorMessage(true);
535 return false;
538 // Teleport player to last position
539 bool ChatHandler::HandleRecallCommand(const char* args)
541 Player* chr = NULL;
543 if(!*args)
545 chr = getSelectedPlayer();
546 if(!chr)
547 chr = m_session->GetPlayer();
549 else
551 std::string name = args;
553 if(!normalizePlayerName(name))
555 SendSysMessage(LANG_PLAYER_NOT_FOUND);
556 SetSentErrorMessage(true);
557 return false;
560 chr = objmgr.GetPlayer(name.c_str());
562 if(!chr)
564 PSendSysMessage(LANG_NO_PLAYER, args);
565 SetSentErrorMessage(true);
566 return false;
570 if(chr->IsBeingTeleported())
572 PSendSysMessage(LANG_IS_TELEPORTED, chr->GetName());
573 SetSentErrorMessage(true);
574 return false;
577 // stop flight if need
578 if(chr->isInFlight())
580 chr->GetMotionMaster()->MovementExpired();
581 chr->m_taxi.ClearTaxiDestinations();
584 chr->TeleportTo(chr->m_recallMap, chr->m_recallX, chr->m_recallY, chr->m_recallZ, chr->m_recallO);
585 return true;
588 //Edit Player KnownTitles
589 bool ChatHandler::HandleModifyKnownTitlesCommand(const char* args)
591 if(!*args)
592 return false;
594 uint64 titles = 0;
596 sscanf((char*)args, I64FMTD, &titles);
598 Player *chr = getSelectedPlayer();
599 if (!chr)
601 SendSysMessage(LANG_NO_CHAR_SELECTED);
602 SetSentErrorMessage(true);
603 return false;
606 uint64 titles2 = titles;
608 for(int i=1; i < sCharTitlesStore.GetNumRows(); ++i)
609 if(CharTitlesEntry const* tEntry = sCharTitlesStore.LookupEntry(i))
610 titles2 &= ~(uint64(1) << tEntry->bit_index);
612 titles &= ~titles2; // remove not existed titles
614 chr->SetUInt64Value(PLAYER__FIELD_KNOWN_TITLES, titles);
615 SendSysMessage(LANG_DONE);
617 return true;
620 //Edit Player HP
621 bool ChatHandler::HandleModifyHPCommand(const char* args)
623 if(!*args)
624 return false;
626 // char* pHp = strtok((char*)args, " ");
627 // if (!pHp)
628 // return false;
630 // char* pHpMax = strtok(NULL, " ");
631 // if (!pHpMax)
632 // return false;
634 // int32 hpm = atoi(pHpMax);
635 // int32 hp = atoi(pHp);
637 int32 hp = atoi((char*)args);
638 int32 hpm = atoi((char*)args);
640 if (hp <= 0 || hpm <= 0 || hpm < hp)
642 SendSysMessage(LANG_BAD_VALUE);
643 SetSentErrorMessage(true);
644 return false;
647 Player *chr = getSelectedPlayer();
648 if (chr == NULL)
650 SendSysMessage(LANG_NO_CHAR_SELECTED);
651 SetSentErrorMessage(true);
652 return false;
655 PSendSysMessage(LANG_YOU_CHANGE_HP, chr->GetName(), hp, hpm);
656 if (needReportToTarget(chr))
657 ChatHandler(chr).PSendSysMessage(LANG_YOURS_HP_CHANGED, GetName(), hp, hpm);
659 chr->SetMaxHealth( hpm );
660 chr->SetHealth( hp );
662 return true;
665 //Edit Player Mana
666 bool ChatHandler::HandleModifyManaCommand(const char* args)
668 if(!*args)
669 return false;
671 // char* pmana = strtok((char*)args, " ");
672 // if (!pmana)
673 // return false;
675 // char* pmanaMax = strtok(NULL, " ");
676 // if (!pmanaMax)
677 // return false;
679 // int32 manam = atoi(pmanaMax);
680 // int32 mana = atoi(pmana);
681 int32 mana = atoi((char*)args);
682 int32 manam = atoi((char*)args);
684 if (mana <= 0 || manam <= 0 || manam < mana)
686 SendSysMessage(LANG_BAD_VALUE);
687 SetSentErrorMessage(true);
688 return false;
691 Player *chr = getSelectedPlayer();
692 if (chr == NULL)
694 SendSysMessage(LANG_NO_CHAR_SELECTED);
695 SetSentErrorMessage(true);
696 return false;
699 PSendSysMessage(LANG_YOU_CHANGE_MANA, chr->GetName(), mana, manam);
700 if (needReportToTarget(chr))
701 ChatHandler(chr).PSendSysMessage(LANG_YOURS_MANA_CHANGED, GetName(), mana, manam);
703 chr->SetMaxPower(POWER_MANA,manam );
704 chr->SetPower(POWER_MANA, mana );
706 return true;
709 //Edit Player Energy
710 bool ChatHandler::HandleModifyEnergyCommand(const char* args)
712 if(!*args)
713 return false;
715 // char* pmana = strtok((char*)args, " ");
716 // if (!pmana)
717 // return false;
719 // char* pmanaMax = strtok(NULL, " ");
720 // if (!pmanaMax)
721 // return false;
723 // int32 manam = atoi(pmanaMax);
724 // int32 mana = atoi(pmana);
726 int32 energy = atoi((char*)args)*10;
727 int32 energym = atoi((char*)args)*10;
729 if (energy <= 0 || energym <= 0 || energym < energy)
731 SendSysMessage(LANG_BAD_VALUE);
732 SetSentErrorMessage(true);
733 return false;
736 Player *chr = getSelectedPlayer();
737 if (!chr)
739 SendSysMessage(LANG_NO_CHAR_SELECTED);
740 SetSentErrorMessage(true);
741 return false;
744 PSendSysMessage(LANG_YOU_CHANGE_ENERGY, chr->GetName(), energy/10, energym/10);
745 if (needReportToTarget(chr))
746 ChatHandler(chr).PSendSysMessage(LANG_YOURS_ENERGY_CHANGED, GetName(), energy/10, energym/10);
748 chr->SetMaxPower(POWER_ENERGY,energym );
749 chr->SetPower(POWER_ENERGY, energy );
751 sLog.outDetail(GetMangosString(LANG_CURRENT_ENERGY),chr->GetMaxPower(POWER_ENERGY));
753 return true;
756 //Edit Player Rage
757 bool ChatHandler::HandleModifyRageCommand(const char* args)
759 if(!*args)
760 return false;
762 // char* pmana = strtok((char*)args, " ");
763 // if (!pmana)
764 // return false;
766 // char* pmanaMax = strtok(NULL, " ");
767 // if (!pmanaMax)
768 // return false;
770 // int32 manam = atoi(pmanaMax);
771 // int32 mana = atoi(pmana);
773 int32 rage = atoi((char*)args)*10;
774 int32 ragem = atoi((char*)args)*10;
776 if (rage <= 0 || ragem <= 0 || ragem < rage)
778 SendSysMessage(LANG_BAD_VALUE);
779 SetSentErrorMessage(true);
780 return false;
783 Player *chr = getSelectedPlayer();
784 if (chr == NULL)
786 SendSysMessage(LANG_NO_CHAR_SELECTED);
787 SetSentErrorMessage(true);
788 return false;
791 PSendSysMessage(LANG_YOU_CHANGE_RAGE, chr->GetName(), rage/10, ragem/10);
792 if (needReportToTarget(chr))
793 ChatHandler(chr).PSendSysMessage(LANG_YOURS_RAGE_CHANGED, GetName(), rage/10, ragem/10);
795 chr->SetMaxPower(POWER_RAGE,ragem );
796 chr->SetPower(POWER_RAGE, rage );
798 return true;
801 //Edit Player Faction
802 bool ChatHandler::HandleModifyFactionCommand(const char* args)
804 if(!*args)
805 return false;
807 char* pfactionid = extractKeyFromLink((char*)args,"Hfaction");
809 Creature* chr = getSelectedCreature();
810 if(!chr)
812 SendSysMessage(LANG_SELECT_CREATURE);
813 SetSentErrorMessage(true);
814 return false;
817 if(!pfactionid)
819 if(chr)
821 uint32 factionid = chr->getFaction();
822 uint32 flag = chr->GetUInt32Value(UNIT_FIELD_FLAGS);
823 uint32 npcflag = chr->GetUInt32Value(UNIT_NPC_FLAGS);
824 uint32 dyflag = chr->GetUInt32Value(UNIT_DYNAMIC_FLAGS);
825 PSendSysMessage(LANG_CURRENT_FACTION,chr->GetGUIDLow(),factionid,flag,npcflag,dyflag);
827 return true;
830 if( !chr )
832 SendSysMessage(LANG_NO_CHAR_SELECTED);
833 SetSentErrorMessage(true);
834 return false;
837 uint32 factionid = atoi(pfactionid);
838 uint32 flag;
840 char *pflag = strtok(NULL, " ");
841 if (!pflag)
842 flag = chr->GetUInt32Value(UNIT_FIELD_FLAGS);
843 else
844 flag = atoi(pflag);
846 char* pnpcflag = strtok(NULL, " ");
848 uint32 npcflag;
849 if(!pnpcflag)
850 npcflag = chr->GetUInt32Value(UNIT_NPC_FLAGS);
851 else
852 npcflag = atoi(pnpcflag);
854 char* pdyflag = strtok(NULL, " ");
856 uint32 dyflag;
857 if(!pdyflag)
858 dyflag = chr->GetUInt32Value(UNIT_DYNAMIC_FLAGS);
859 else
860 dyflag = atoi(pdyflag);
862 if(!sFactionTemplateStore.LookupEntry(factionid))
864 PSendSysMessage(LANG_WRONG_FACTION, factionid);
865 SetSentErrorMessage(true);
866 return false;
869 PSendSysMessage(LANG_YOU_CHANGE_FACTION, chr->GetGUIDLow(),factionid,flag,npcflag,dyflag);
871 chr->setFaction(factionid);
872 chr->SetUInt32Value(UNIT_FIELD_FLAGS,flag);
873 chr->SetUInt32Value(UNIT_NPC_FLAGS,npcflag);
874 chr->SetUInt32Value(UNIT_DYNAMIC_FLAGS,dyflag);
876 return true;
879 //Edit Player Spell
880 bool ChatHandler::HandleModifySpellCommand(const char* args)
882 if(!*args) return false;
883 char* pspellflatid = strtok((char*)args, " ");
884 if (!pspellflatid)
885 return false;
887 char* pop = strtok(NULL, " ");
888 if (!pop)
889 return false;
891 char* pval = strtok(NULL, " ");
892 if (!pval)
893 return false;
895 uint16 mark;
897 char* pmark = strtok(NULL, " ");
899 uint8 spellflatid = atoi(pspellflatid);
900 uint8 op = atoi(pop);
901 uint16 val = atoi(pval);
902 if(!pmark)
903 mark = 65535;
904 else
905 mark = atoi(pmark);
907 Player *chr = getSelectedPlayer();
908 if (chr == NULL)
910 SendSysMessage(LANG_NO_CHAR_SELECTED);
911 SetSentErrorMessage(true);
912 return false;
915 PSendSysMessage(LANG_YOU_CHANGE_SPELLFLATID, spellflatid, val, mark, chr->GetName());
916 if (needReportToTarget(chr))
917 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SPELLFLATID_CHANGED, GetName(), spellflatid, val, mark);
919 WorldPacket data(SMSG_SET_FLAT_SPELL_MODIFIER, (1+1+2+2));
920 data << uint8(spellflatid);
921 data << uint8(op);
922 data << uint16(val);
923 data << uint16(mark);
924 chr->GetSession()->SendPacket(&data);
926 return true;
929 //Edit Player TP
930 bool ChatHandler::HandleModifyTalentCommand (const char* args)
932 if (!*args)
933 return false;
935 int tp = atoi((char*)args);
936 if (tp>0)
938 Player* player = getSelectedPlayer();
939 if(!player)
941 SendSysMessage(LANG_NO_CHAR_SELECTED);
942 SetSentErrorMessage(true);
943 return false;
945 player->SetFreeTalentPoints(tp);
946 return true;
948 return false;
951 //Enable On\OFF all taxi paths
952 bool ChatHandler::HandleTaxiCheatCommand(const char* args)
954 if (!*args)
956 SendSysMessage(LANG_USE_BOL);
957 SetSentErrorMessage(true);
958 return false;
961 std::string argstr = (char*)args;
963 Player *chr = getSelectedPlayer();
964 if (!chr)
966 chr=m_session->GetPlayer();
969 if (argstr == "on")
971 chr->SetTaxiCheater(true);
972 PSendSysMessage(LANG_YOU_GIVE_TAXIS, chr->GetName());
973 if (needReportToTarget(chr))
974 ChatHandler(chr).PSendSysMessage(LANG_YOURS_TAXIS_ADDED, GetName());
975 return true;
978 if (argstr == "off")
980 chr->SetTaxiCheater(false);
981 PSendSysMessage(LANG_YOU_REMOVE_TAXIS, chr->GetName());
982 if (needReportToTarget(chr))
983 ChatHandler(chr).PSendSysMessage(LANG_YOURS_TAXIS_REMOVED, GetName());
985 return true;
988 SendSysMessage(LANG_USE_BOL);
989 SetSentErrorMessage(true);
990 return false;
993 //Edit Player Aspeed
994 bool ChatHandler::HandleModifyASpeedCommand(const char* args)
996 if (!*args)
997 return false;
999 float ASpeed = (float)atof((char*)args);
1001 if (ASpeed > 10 || ASpeed < 0.1)
1003 SendSysMessage(LANG_BAD_VALUE);
1004 SetSentErrorMessage(true);
1005 return false;
1008 Player *chr = getSelectedPlayer();
1009 if (chr == NULL)
1011 SendSysMessage(LANG_NO_CHAR_SELECTED);
1012 SetSentErrorMessage(true);
1013 return false;
1016 if(chr->isInFlight())
1018 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chr->GetName());
1019 SetSentErrorMessage(true);
1020 return false;
1023 PSendSysMessage(LANG_YOU_CHANGE_ASPEED, ASpeed, chr->GetName());
1024 if (needReportToTarget(chr))
1025 ChatHandler(chr).PSendSysMessage(LANG_YOURS_ASPEED_CHANGED, GetName(), ASpeed);
1027 chr->SetSpeed(MOVE_WALK, ASpeed,true);
1028 chr->SetSpeed(MOVE_RUN, ASpeed,true);
1029 chr->SetSpeed(MOVE_SWIM, ASpeed,true);
1030 //chr->SetSpeed(MOVE_TURN, ASpeed,true);
1031 chr->SetSpeed(MOVE_FLY, ASpeed,true);
1032 return true;
1035 //Edit Player Speed
1036 bool ChatHandler::HandleModifySpeedCommand(const char* args)
1038 if (!*args)
1039 return false;
1041 float Speed = (float)atof((char*)args);
1043 if (Speed > 10 || Speed < 0.1)
1045 SendSysMessage(LANG_BAD_VALUE);
1046 SetSentErrorMessage(true);
1047 return false;
1050 Player *chr = getSelectedPlayer();
1051 if (chr == NULL)
1053 SendSysMessage(LANG_NO_CHAR_SELECTED);
1054 SetSentErrorMessage(true);
1055 return false;
1058 if(chr->isInFlight())
1060 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chr->GetName());
1061 SetSentErrorMessage(true);
1062 return false;
1065 PSendSysMessage(LANG_YOU_CHANGE_SPEED, Speed, chr->GetName());
1066 if (needReportToTarget(chr))
1067 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SPEED_CHANGED, GetName(), Speed);
1069 chr->SetSpeed(MOVE_RUN,Speed,true);
1071 return true;
1074 //Edit Player Swim Speed
1075 bool ChatHandler::HandleModifySwimCommand(const char* args)
1077 if (!*args)
1078 return false;
1080 float Swim = (float)atof((char*)args);
1082 if (Swim > 10.0f || Swim < 0.01f)
1084 SendSysMessage(LANG_BAD_VALUE);
1085 SetSentErrorMessage(true);
1086 return false;
1089 Player *chr = getSelectedPlayer();
1090 if (chr == NULL)
1092 SendSysMessage(LANG_NO_CHAR_SELECTED);
1093 SetSentErrorMessage(true);
1094 return false;
1097 if(chr->isInFlight())
1099 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chr->GetName());
1100 SetSentErrorMessage(true);
1101 return false;
1104 PSendSysMessage(LANG_YOU_CHANGE_SWIM_SPEED, Swim, chr->GetName());
1105 if (needReportToTarget(chr))
1106 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SWIM_SPEED_CHANGED, GetName(), Swim);
1108 chr->SetSpeed(MOVE_SWIM,Swim,true);
1110 return true;
1113 //Edit Player Walk Speed
1114 bool ChatHandler::HandleModifyBWalkCommand(const char* args)
1116 if (!*args)
1117 return false;
1119 float BSpeed = (float)atof((char*)args);
1121 if (BSpeed > 10.0f || BSpeed < 0.1f)
1123 SendSysMessage(LANG_BAD_VALUE);
1124 SetSentErrorMessage(true);
1125 return false;
1128 Player *chr = getSelectedPlayer();
1129 if (chr == NULL)
1131 SendSysMessage(LANG_NO_CHAR_SELECTED);
1132 SetSentErrorMessage(true);
1133 return false;
1136 if(chr->isInFlight())
1138 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chr->GetName());
1139 SetSentErrorMessage(true);
1140 return false;
1143 PSendSysMessage(LANG_YOU_CHANGE_BACK_SPEED, BSpeed, chr->GetName());
1144 if (needReportToTarget(chr))
1145 ChatHandler(chr).PSendSysMessage(LANG_YOURS_BACK_SPEED_CHANGED, GetName(), BSpeed);
1147 chr->SetSpeed(MOVE_WALKBACK,BSpeed,true);
1149 return true;
1152 //Edit Player Fly
1153 bool ChatHandler::HandleModifyFlyCommand(const char* args)
1155 if (!*args)
1156 return false;
1158 float FSpeed = (float)atof((char*)args);
1160 if (FSpeed > 10.0f || FSpeed < 0.1f)
1162 SendSysMessage(LANG_BAD_VALUE);
1163 SetSentErrorMessage(true);
1164 return false;
1167 Player *chr = getSelectedPlayer();
1168 if (chr == NULL)
1170 SendSysMessage(LANG_NO_CHAR_SELECTED);
1171 SetSentErrorMessage(true);
1172 return false;
1175 PSendSysMessage(LANG_YOU_CHANGE_FLY_SPEED, FSpeed, chr->GetName());
1176 if (needReportToTarget(chr))
1177 ChatHandler(chr).PSendSysMessage(LANG_YOURS_FLY_SPEED_CHANGED, GetName(), FSpeed);
1179 chr->SetSpeed(MOVE_FLY,FSpeed,true);
1181 return true;
1184 //Edit Player Scale
1185 bool ChatHandler::HandleModifyScaleCommand(const char* args)
1187 if (!*args)
1188 return false;
1190 float Scale = (float)atof((char*)args);
1191 if (Scale > 3.0f || Scale <= 0.0f)
1193 SendSysMessage(LANG_BAD_VALUE);
1194 SetSentErrorMessage(true);
1195 return false;
1198 Player *chr = getSelectedPlayer();
1199 if (chr == NULL)
1201 SendSysMessage(LANG_NO_CHAR_SELECTED);
1202 SetSentErrorMessage(true);
1203 return false;
1206 PSendSysMessage(LANG_YOU_CHANGE_SIZE, Scale, chr->GetName());
1207 if (needReportToTarget(chr))
1208 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SIZE_CHANGED, GetName(), Scale);
1210 chr->SetFloatValue(OBJECT_FIELD_SCALE_X, Scale);
1212 return true;
1215 //Enable Player mount
1216 bool ChatHandler::HandleModifyMountCommand(const char* args)
1218 if(!*args)
1219 return false;
1221 uint16 mId = 1147;
1222 float speed = (float)15;
1223 uint32 num = 0;
1225 num = atoi((char*)args);
1226 switch(num)
1228 case 1:
1229 mId=14340;
1230 break;
1231 case 2:
1232 mId=4806;
1233 break;
1234 case 3:
1235 mId=6471;
1236 break;
1237 case 4:
1238 mId=12345;
1239 break;
1240 case 5:
1241 mId=6472;
1242 break;
1243 case 6:
1244 mId=6473;
1245 break;
1246 case 7:
1247 mId=10670;
1248 break;
1249 case 8:
1250 mId=10719;
1251 break;
1252 case 9:
1253 mId=10671;
1254 break;
1255 case 10:
1256 mId=10672;
1257 break;
1258 case 11:
1259 mId=10720;
1260 break;
1261 case 12:
1262 mId=14349;
1263 break;
1264 case 13:
1265 mId=11641;
1266 break;
1267 case 14:
1268 mId=12244;
1269 break;
1270 case 15:
1271 mId=12242;
1272 break;
1273 case 16:
1274 mId=14578;
1275 break;
1276 case 17:
1277 mId=14579;
1278 break;
1279 case 18:
1280 mId=14349;
1281 break;
1282 case 19:
1283 mId=12245;
1284 break;
1285 case 20:
1286 mId=14335;
1287 break;
1288 case 21:
1289 mId=207;
1290 break;
1291 case 22:
1292 mId=2328;
1293 break;
1294 case 23:
1295 mId=2327;
1296 break;
1297 case 24:
1298 mId=2326;
1299 break;
1300 case 25:
1301 mId=14573;
1302 break;
1303 case 26:
1304 mId=14574;
1305 break;
1306 case 27:
1307 mId=14575;
1308 break;
1309 case 28:
1310 mId=604;
1311 break;
1312 case 29:
1313 mId=1166;
1314 break;
1315 case 30:
1316 mId=2402;
1317 break;
1318 case 31:
1319 mId=2410;
1320 break;
1321 case 32:
1322 mId=2409;
1323 break;
1324 case 33:
1325 mId=2408;
1326 break;
1327 case 34:
1328 mId=2405;
1329 break;
1330 case 35:
1331 mId=14337;
1332 break;
1333 case 36:
1334 mId=6569;
1335 break;
1336 case 37:
1337 mId=10661;
1338 break;
1339 case 38:
1340 mId=10666;
1341 break;
1342 case 39:
1343 mId=9473;
1344 break;
1345 case 40:
1346 mId=9476;
1347 break;
1348 case 41:
1349 mId=9474;
1350 break;
1351 case 42:
1352 mId=14374;
1353 break;
1354 case 43:
1355 mId=14376;
1356 break;
1357 case 44:
1358 mId=14377;
1359 break;
1360 case 45:
1361 mId=2404;
1362 break;
1363 case 46:
1364 mId=2784;
1365 break;
1366 case 47:
1367 mId=2787;
1368 break;
1369 case 48:
1370 mId=2785;
1371 break;
1372 case 49:
1373 mId=2736;
1374 break;
1375 case 50:
1376 mId=2786;
1377 break;
1378 case 51:
1379 mId=14347;
1380 break;
1381 case 52:
1382 mId=14346;
1383 break;
1384 case 53:
1385 mId=14576;
1386 break;
1387 case 54:
1388 mId=9695;
1389 break;
1390 case 55:
1391 mId=9991;
1392 break;
1393 case 56:
1394 mId=6448;
1395 break;
1396 case 57:
1397 mId=6444;
1398 break;
1399 case 58:
1400 mId=6080;
1401 break;
1402 case 59:
1403 mId=6447;
1404 break;
1405 case 60:
1406 mId=4805;
1407 break;
1408 case 61:
1409 mId=9714;
1410 break;
1411 case 62:
1412 mId=6448;
1413 break;
1414 case 63:
1415 mId=6442;
1416 break;
1417 case 64:
1418 mId=14632;
1419 break;
1420 case 65:
1421 mId=14332;
1422 break;
1423 case 66:
1424 mId=14331;
1425 break;
1426 case 67:
1427 mId=8469;
1428 break;
1429 case 68:
1430 mId=2830;
1431 break;
1432 case 69:
1433 mId=2346;
1434 break;
1435 default:
1436 SendSysMessage(LANG_NO_MOUNT);
1437 SetSentErrorMessage(true);
1438 return false;
1441 Player *chr = getSelectedPlayer();
1442 if (chr == NULL)
1444 SendSysMessage(LANG_NO_CHAR_SELECTED);
1445 SetSentErrorMessage(true);
1446 return false;
1449 PSendSysMessage(LANG_YOU_GIVE_MOUNT, chr->GetName());
1450 if (needReportToTarget(chr))
1451 ChatHandler(chr).PSendSysMessage(LANG_MOUNT_GIVED, GetName());
1453 chr->SetUInt32Value( UNIT_FIELD_FLAGS , 0x001000 );
1454 chr->Mount(mId);
1456 WorldPacket data( SMSG_FORCE_RUN_SPEED_CHANGE, (8+4+1+4) );
1457 data.append(chr->GetPackGUID());
1458 data << (uint32)0;
1459 data << (uint8)0; //new 2.1.0
1460 data << float(speed);
1461 chr->SendMessageToSet( &data, true );
1463 data.Initialize( SMSG_FORCE_SWIM_SPEED_CHANGE, (8+4+4) );
1464 data.append(chr->GetPackGUID());
1465 data << (uint32)0;
1466 data << float(speed);
1467 chr->SendMessageToSet( &data, true );
1469 return true;
1472 //Edit Player money
1473 bool ChatHandler::HandleModifyMoneyCommand(const char* args)
1475 if (!*args)
1476 return false;
1478 Player *chr = getSelectedPlayer();
1479 if (chr == NULL)
1481 SendSysMessage(LANG_NO_CHAR_SELECTED);
1482 SetSentErrorMessage(true);
1483 return false;
1486 int32 addmoney = atoi((char*)args);
1488 uint32 moneyuser = chr->GetMoney();
1490 if(addmoney < 0)
1492 int32 newmoney = moneyuser + addmoney;
1494 sLog.outDetail(GetMangosString(LANG_CURRENT_MONEY), moneyuser, addmoney, newmoney);
1495 if(newmoney <= 0 )
1497 PSendSysMessage(LANG_YOU_TAKE_ALL_MONEY, chr->GetName());
1498 if (needReportToTarget(chr))
1499 ChatHandler(chr).PSendSysMessage(LANG_YOURS_ALL_MONEY_GONE, GetName());
1501 chr->SetMoney(0);
1503 else
1505 PSendSysMessage(LANG_YOU_TAKE_MONEY, abs(addmoney), chr->GetName());
1506 if (needReportToTarget(chr))
1507 ChatHandler(chr).PSendSysMessage(LANG_YOURS_MONEY_TAKEN, GetName(), abs(addmoney));
1508 chr->SetMoney( newmoney );
1511 else
1513 PSendSysMessage(LANG_YOU_GIVE_MONEY, addmoney, chr->GetName());
1514 if (needReportToTarget(chr))
1515 ChatHandler(chr).PSendSysMessage(LANG_YOURS_MONEY_GIVEN, GetName(), addmoney);
1516 chr->ModifyMoney( addmoney );
1519 sLog.outDetail(GetMangosString(LANG_NEW_MONEY), moneyuser, addmoney, chr->GetMoney() );
1521 return true;
1524 //Edit Player field
1525 bool ChatHandler::HandleModifyBitCommand(const char* args)
1527 if( !*args )
1528 return false;
1530 Player *chr = getSelectedPlayer();
1531 if (chr == NULL)
1533 SendSysMessage(LANG_NO_CHAR_SELECTED);
1534 SetSentErrorMessage(true);
1535 return false;
1538 char* pField = strtok((char*)args, " ");
1539 if (!pField)
1540 return false;
1542 char* pBit = strtok(NULL, " ");
1543 if (!pBit)
1544 return false;
1546 uint16 field = atoi(pField);
1547 uint32 bit = atoi(pBit);
1549 if (field < 1 || field >= PLAYER_END)
1551 SendSysMessage(LANG_BAD_VALUE);
1552 SetSentErrorMessage(true);
1553 return false;
1556 if (bit < 1 || bit > 32)
1558 SendSysMessage(LANG_BAD_VALUE);
1559 SetSentErrorMessage(true);
1560 return false;
1563 if ( chr->HasFlag( field, (1<<(bit-1)) ) )
1565 chr->RemoveFlag( field, (1<<(bit-1)) );
1566 PSendSysMessage(LANG_REMOVE_BIT, bit, field);
1568 else
1570 chr->SetFlag( field, (1<<(bit-1)) );
1571 PSendSysMessage(LANG_SET_BIT, bit, field);
1574 return true;
1577 bool ChatHandler::HandleModifyHonorCommand (const char* args)
1579 if (!*args)
1580 return false;
1582 Player *target = getSelectedPlayer();
1583 if(!target)
1585 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1586 SetSentErrorMessage(true);
1587 return false;
1590 int32 amount = (uint32)atoi(args);
1592 target->ModifyHonorPoints(amount);
1594 PSendSysMessage(LANG_COMMAND_MODIFY_HONOR, target->GetName(), target->GetHonorPoints());
1596 return true;
1599 bool ChatHandler::HandleTeleCommand(const char * args)
1601 if(!*args)
1602 return false;
1604 Player* _player = m_session->GetPlayer();
1606 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
1607 GameTele const* tele = extractGameTeleFromLink((char*)args);
1609 if (!tele)
1611 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
1612 SetSentErrorMessage(true);
1613 return false;
1616 // stop flight if need
1617 if(_player->isInFlight())
1619 _player->GetMotionMaster()->MovementExpired();
1620 _player->m_taxi.ClearTaxiDestinations();
1622 // save only in non-flight case
1623 else
1624 _player->SaveRecallPosition();
1626 _player->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
1627 return true;
1630 bool ChatHandler::HandleLookupAreaCommand(const char* args)
1632 if (!*args)
1633 return false;
1635 std::string namepart = args;
1636 std::wstring wnamepart;
1638 if (!Utf8toWStr (namepart,wnamepart))
1639 return false;
1641 uint32 counter = 0; // Counter for figure out that we found smth.
1643 // converting string that we try to find to lower case
1644 wstrToLower (wnamepart);
1646 // Search in AreaTable.dbc
1647 for (uint32 areaflag = 0; areaflag < sAreaStore.GetNumRows (); ++areaflag)
1649 AreaTableEntry const *areaEntry = sAreaStore.LookupEntry (areaflag);
1650 if (areaEntry)
1652 int loc = m_session ? m_session->GetSessionDbcLocale () : sWorld.GetDefaultDbcLocale();
1653 std::string name = areaEntry->area_name[loc];
1654 if (name.empty())
1655 continue;
1657 if (!Utf8FitTo (name, wnamepart))
1659 loc = 0;
1660 for(; loc < MAX_LOCALE; ++loc)
1662 if (m_session && loc==m_session->GetSessionDbcLocale ())
1663 continue;
1665 name = areaEntry->area_name[loc];
1666 if (name.empty ())
1667 continue;
1669 if (Utf8FitTo (name, wnamepart))
1670 break;
1674 if (loc < MAX_LOCALE)
1676 // send area in "id - [name]" format
1677 std::ostringstream ss;
1678 if (m_session)
1679 ss << areaEntry->ID << " - |cffffffff|Harea:" << areaEntry->ID << "|h[" << name << " " << localeNames[loc]<< "]|h|r";
1680 else
1681 ss << areaEntry->ID << " - " << name << " " << localeNames[loc];
1683 SendSysMessage (ss.str ().c_str());
1685 ++counter;
1690 if (counter == 0) // if counter == 0 then we found nth
1691 SendSysMessage (LANG_COMMAND_NOAREAFOUND);
1693 return true;
1696 //Find tele in game_tele order by name
1697 bool ChatHandler::HandleLookupTeleCommand(const char * args)
1699 if(!*args)
1701 SendSysMessage(LANG_COMMAND_TELE_PARAMETER);
1702 SetSentErrorMessage(true);
1703 return false;
1706 char const* str = strtok((char*)args, " ");
1707 if(!str)
1708 return false;
1710 std::string namepart = str;
1711 std::wstring wnamepart;
1713 if(!Utf8toWStr(namepart,wnamepart))
1714 return false;
1716 // converting string that we try to find to lower case
1717 wstrToLower( wnamepart );
1719 std::ostringstream reply;
1721 GameTeleMap const & teleMap = objmgr.GetGameTeleMap();
1722 for(GameTeleMap::const_iterator itr = teleMap.begin(); itr != teleMap.end(); ++itr)
1724 GameTele const* tele = &itr->second;
1726 if(tele->wnameLow.find(wnamepart) == std::wstring::npos)
1727 continue;
1729 if (m_session)
1730 reply << " |cffffffff|Htele:" << itr->first << "|h[" << tele->name << "]|h|r\n";
1731 else
1732 reply << " " << itr->first << " " << tele->name << "\n";
1735 if(reply.str().empty())
1736 SendSysMessage(LANG_COMMAND_TELE_NOLOCATION);
1737 else
1738 PSendSysMessage(LANG_COMMAND_TELE_LOCATION,reply.str().c_str());
1740 return true;
1743 //Enable\Dissable accept whispers (for GM)
1744 bool ChatHandler::HandleWhispersCommand(const char* args)
1746 if(!*args)
1748 PSendSysMessage(LANG_COMMAND_WHISPERACCEPTING, m_session->GetPlayer()->isAcceptWhispers() ? GetMangosString(LANG_ON) : GetMangosString(LANG_OFF));
1749 return true;
1752 std::string argstr = (char*)args;
1753 // whisper on
1754 if (argstr == "on")
1756 m_session->GetPlayer()->SetAcceptWhispers(true);
1757 SendSysMessage(LANG_COMMAND_WHISPERON);
1758 return true;
1761 // whisper off
1762 if (argstr == "off")
1764 m_session->GetPlayer()->SetAcceptWhispers(false);
1765 SendSysMessage(LANG_COMMAND_WHISPEROFF);
1766 return true;
1769 SendSysMessage(LANG_USE_BOL);
1770 SetSentErrorMessage(true);
1771 return false;
1774 //Play sound
1775 bool ChatHandler::HandlePlaySoundCommand(const char* args)
1777 // USAGE: .debug playsound #soundid
1778 // #soundid - ID decimal number from SoundEntries.dbc (1st column)
1779 // this file have about 5000 sounds.
1780 // In this realization only caller can hear this sound.
1781 if( *args )
1783 uint32 dwSoundId = atoi((char*)args);
1785 if( !sSoundEntriesStore.LookupEntry(dwSoundId) )
1787 PSendSysMessage(LANG_SOUND_NOT_EXIST, dwSoundId);
1788 SetSentErrorMessage(true);
1789 return false;
1792 WorldPacket data(SMSG_PLAY_OBJECT_SOUND,4+8);
1793 data << uint32(dwSoundId) << m_session->GetPlayer()->GetGUID();
1794 m_session->SendPacket(&data);
1796 PSendSysMessage(LANG_YOU_HEAR_SOUND, dwSoundId);
1797 return true;
1800 return false;
1803 //Save all players in the world
1804 bool ChatHandler::HandleSaveAllCommand(const char* /*args*/)
1806 ObjectAccessor::Instance().SaveAllPlayers();
1807 SendSysMessage(LANG_PLAYERS_SAVED);
1808 return true;
1811 //Send mail by command
1812 bool ChatHandler::HandleSendMailCommand(const char* args)
1814 if(!*args)
1815 return false;
1817 // format: name "subject text" "mail text"
1819 char* pName = strtok((char*)args, " ");
1820 if(!pName)
1821 return false;
1823 char* tail1 = strtok(NULL, "");
1824 if(!tail1)
1825 return false;
1827 char* msgSubject;
1828 if(*tail1=='"')
1829 msgSubject = strtok(tail1+1, "\"");
1830 else
1832 char* space = strtok(tail1, "\"");
1833 if(!space)
1834 return false;
1835 msgSubject = strtok(NULL, "\"");
1838 if (!msgSubject)
1839 return false;
1841 char* tail2 = strtok(NULL, "");
1842 if(!tail2)
1843 return false;
1845 char* msgText;
1846 if(*tail2=='"')
1847 msgText = strtok(tail2+1, "\"");
1848 else
1850 char* space = strtok(tail2, "\"");
1851 if(!space)
1852 return false;
1853 msgText = strtok(NULL, "\"");
1856 if (!msgText)
1857 return false;
1859 // pName, msgSubject, msgText isn't NUL after prev. check
1860 std::string name = pName;
1861 std::string subject = msgSubject;
1862 std::string text = msgText;
1864 if(!normalizePlayerName(name))
1866 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1867 SetSentErrorMessage(true);
1868 return false;
1871 uint64 receiver_guid = objmgr.GetPlayerGUIDByName(name);
1872 if(!receiver_guid)
1874 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1875 SetSentErrorMessage(true);
1876 return false;
1879 // from console show not existed sender
1880 uint32 sender_guidlo = m_session ? m_session->GetPlayer()->GetGUIDLow() : 0;
1882 uint32 messagetype = MAIL_NORMAL;
1883 uint32 stationery = MAIL_STATIONERY_GM;
1884 uint32 itemTextId = !text.empty() ? objmgr.CreateItemText( text ) : 0;
1886 Player *receiver = objmgr.GetPlayer(receiver_guid);
1888 WorldSession::SendMailTo(receiver,messagetype, stationery, sender_guidlo, GUID_LOPART(receiver_guid), subject, itemTextId, NULL, 0, 0, MAIL_CHECK_MASK_NONE);
1890 PSendSysMessage(LANG_MAIL_SENT, name.c_str());
1891 return true;
1894 // teleport player to given game_tele.entry
1895 bool ChatHandler::HandleNameTeleCommand(const char * args)
1897 if(!*args)
1898 return false;
1900 char* pName = strtok((char*)args, " ");
1902 if(!pName)
1903 return false;
1905 std::string name = pName;
1907 if(!normalizePlayerName(name))
1909 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1910 SetSentErrorMessage(true);
1911 return false;
1914 char* tail = strtok(NULL, "");
1915 if(!tail)
1916 return false;
1918 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
1919 GameTele const* tele = extractGameTeleFromLink(tail);
1920 if(!tele)
1922 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
1923 SetSentErrorMessage(true);
1924 return false;
1927 Player *chr = objmgr.GetPlayer(name.c_str());
1928 if (chr)
1931 if(chr->IsBeingTeleported()==true)
1933 PSendSysMessage(LANG_IS_TELEPORTED, chr->GetName());
1934 SetSentErrorMessage(true);
1935 return false;
1938 PSendSysMessage(LANG_TELEPORTING_TO, chr->GetName(),"", tele->name.c_str());
1939 if (needReportToTarget(chr))
1940 ChatHandler(chr).PSendSysMessage(LANG_TELEPORTED_TO_BY, GetName());
1942 // stop flight if need
1943 if(chr->isInFlight())
1945 chr->GetMotionMaster()->MovementExpired();
1946 chr->m_taxi.ClearTaxiDestinations();
1948 // save only in non-flight case
1949 else
1950 chr->SaveRecallPosition();
1952 chr->TeleportTo(tele->mapId,tele->position_x,tele->position_y,tele->position_z,tele->orientation);
1954 else if (uint64 guid = objmgr.GetPlayerGUIDByName(name.c_str()))
1956 PSendSysMessage(LANG_TELEPORTING_TO, name.c_str(), GetMangosString(LANG_OFFLINE), tele->name.c_str());
1957 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);
1959 else
1960 PSendSysMessage(LANG_NO_PLAYER, name.c_str());
1962 return true;
1965 //Teleport group to given game_tele.entry
1966 bool ChatHandler::HandleGroupTeleCommand(const char * args)
1968 if(!*args)
1969 return false;
1971 Player *player = getSelectedPlayer();
1972 if (!player)
1974 SendSysMessage(LANG_NO_CHAR_SELECTED);
1975 SetSentErrorMessage(true);
1976 return false;
1979 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
1980 GameTele const* tele = extractGameTeleFromLink((char*)args);
1981 if(!tele)
1983 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
1984 SetSentErrorMessage(true);
1985 return false;
1988 Group *grp = player->GetGroup();
1989 if(!grp)
1991 PSendSysMessage(LANG_NOT_IN_GROUP,player->GetName());
1992 SetSentErrorMessage(true);
1993 return false;
1996 for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
1998 Player *pl = itr->getSource();
2000 if(!pl || !pl->GetSession() )
2001 continue;
2003 if(pl->IsBeingTeleported())
2005 PSendSysMessage(LANG_IS_TELEPORTED, pl->GetName());
2006 continue;
2009 PSendSysMessage(LANG_TELEPORTING_TO, pl->GetName(),"", tele->name.c_str());
2010 if (needReportToTarget(pl))
2011 ChatHandler(pl).PSendSysMessage(LANG_TELEPORTED_TO_BY, GetName());
2013 // stop flight if need
2014 if(pl->isInFlight())
2016 pl->GetMotionMaster()->MovementExpired();
2017 pl->m_taxi.ClearTaxiDestinations();
2019 // save only in non-flight case
2020 else
2021 pl->SaveRecallPosition();
2023 pl->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
2026 return true;
2029 //Summon group of player
2030 bool ChatHandler::HandleGroupgoCommand(const char* args)
2032 if(!*args)
2033 return false;
2035 std::string name = args;
2037 if(!normalizePlayerName(name))
2039 SendSysMessage(LANG_PLAYER_NOT_FOUND);
2040 SetSentErrorMessage(true);
2041 return false;
2044 Player *player = objmgr.GetPlayer(name.c_str());
2045 if (!player)
2047 PSendSysMessage(LANG_NO_PLAYER, args);
2048 SetSentErrorMessage(true);
2049 return false;
2052 Group *grp = player->GetGroup();
2054 if(!grp)
2056 PSendSysMessage(LANG_NOT_IN_GROUP,player->GetName());
2057 SetSentErrorMessage(true);
2058 return false;
2061 Map* gmMap = MapManager::Instance().GetMap(m_session->GetPlayer()->GetMapId(),m_session->GetPlayer());
2062 bool to_instance = gmMap->Instanceable();
2064 // we are in instance, and can summon only player in our group with us as lead
2065 if ( to_instance && (
2066 !m_session->GetPlayer()->GetGroup() || (grp->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ||
2067 (m_session->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ) )
2068 // the last check is a bit excessive, but let it be, just in case
2070 SendSysMessage(LANG_CANNOT_SUMMON_TO_INST);
2071 SetSentErrorMessage(true);
2072 return false;
2075 for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
2077 Player *pl = itr->getSource();
2079 if(!pl || pl==m_session->GetPlayer() || !pl->GetSession() )
2080 continue;
2082 if(pl->IsBeingTeleported()==true)
2084 PSendSysMessage(LANG_IS_TELEPORTED, pl->GetName());
2085 SetSentErrorMessage(true);
2086 return false;
2089 if (to_instance)
2091 Map* plMap = MapManager::Instance().GetMap(pl->GetMapId(),pl);
2093 if ( plMap->Instanceable() && plMap->GetInstanceId() != gmMap->GetInstanceId() )
2095 // cannot summon from instance to instance
2096 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,pl->GetName());
2097 SetSentErrorMessage(true);
2098 return false;
2102 PSendSysMessage(LANG_SUMMONING, pl->GetName(),"");
2103 if (needReportToTarget(pl))
2104 ChatHandler(pl).PSendSysMessage(LANG_SUMMONED_BY, GetName());
2106 // stop flight if need
2107 if(pl->isInFlight())
2109 pl->GetMotionMaster()->MovementExpired();
2110 pl->m_taxi.ClearTaxiDestinations();
2112 // save only in non-flight case
2113 else
2114 pl->SaveRecallPosition();
2116 // before GM
2117 float x,y,z;
2118 m_session->GetPlayer()->GetClosePoint(x,y,z,pl->GetObjectSize());
2119 pl->TeleportTo(m_session->GetPlayer()->GetMapId(),x,y,z,pl->GetOrientation());
2122 return true;
2125 //teleport at coordinates
2126 bool ChatHandler::HandleGoXYCommand(const char* args)
2128 if(!*args)
2129 return false;
2131 Player* _player = m_session->GetPlayer();
2133 char* px = strtok((char*)args, " ");
2134 char* py = strtok(NULL, " ");
2135 char* pmapid = strtok(NULL, " ");
2137 if (!px || !py)
2138 return false;
2140 float x = (float)atof(px);
2141 float y = (float)atof(py);
2142 uint32 mapid;
2143 if (pmapid)
2144 mapid = (uint32)atoi(pmapid);
2145 else mapid = _player->GetMapId();
2147 if(!MapManager::IsValidMapCoord(mapid,x,y))
2149 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
2150 SetSentErrorMessage(true);
2151 return false;
2154 // stop flight if need
2155 if(_player->isInFlight())
2157 _player->GetMotionMaster()->MovementExpired();
2158 _player->m_taxi.ClearTaxiDestinations();
2160 // save only in non-flight case
2161 else
2162 _player->SaveRecallPosition();
2164 Map const *map = MapManager::Instance().GetBaseMap(mapid);
2165 float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
2167 _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
2169 return true;
2172 //teleport at coordinates, including Z
2173 bool ChatHandler::HandleGoXYZCommand(const char* args)
2175 if(!*args)
2176 return false;
2178 Player* _player = m_session->GetPlayer();
2180 char* px = strtok((char*)args, " ");
2181 char* py = strtok(NULL, " ");
2182 char* pz = strtok(NULL, " ");
2183 char* pmapid = strtok(NULL, " ");
2185 if (!px || !py || !pz)
2186 return false;
2188 float x = (float)atof(px);
2189 float y = (float)atof(py);
2190 float z = (float)atof(pz);
2191 uint32 mapid;
2192 if (pmapid)
2193 mapid = (uint32)atoi(pmapid);
2194 else
2195 mapid = _player->GetMapId();
2197 if(!MapManager::IsValidMapCoord(mapid,x,y,z))
2199 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
2200 SetSentErrorMessage(true);
2201 return false;
2204 // stop flight if need
2205 if(_player->isInFlight())
2207 _player->GetMotionMaster()->MovementExpired();
2208 _player->m_taxi.ClearTaxiDestinations();
2210 // save only in non-flight case
2211 else
2212 _player->SaveRecallPosition();
2214 _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
2216 return true;
2219 //teleport at coordinates
2220 bool ChatHandler::HandleGoZoneXYCommand(const char* args)
2222 if(!*args)
2223 return false;
2225 Player* _player = m_session->GetPlayer();
2227 char* px = strtok((char*)args, " ");
2228 char* py = strtok(NULL, " ");
2229 char* tail = strtok(NULL,"");
2231 char* cAreaId = extractKeyFromLink(tail,"Harea"); // string or [name] Shift-click form |color|Harea:area_id|h[name]|h|r
2233 if (!px || !py)
2234 return false;
2236 float x = (float)atof(px);
2237 float y = (float)atof(py);
2238 uint32 areaid = cAreaId ? (uint32)atoi(cAreaId) : _player->GetZoneId();
2240 AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(areaid);
2242 if( x<0 || x>100 || y<0 || y>100 || !areaEntry )
2244 PSendSysMessage(LANG_INVALID_ZONE_COORD,x,y,areaid);
2245 SetSentErrorMessage(true);
2246 return false;
2249 // update to parent zone if exist (client map show only zones without parents)
2250 AreaTableEntry const* zoneEntry = areaEntry->zone ? GetAreaEntryByAreaID(areaEntry->zone) : areaEntry;
2252 Map const *map = MapManager::Instance().GetBaseMap(zoneEntry->mapid);
2254 if(map->Instanceable())
2256 PSendSysMessage(LANG_INVALID_ZONE_MAP,areaEntry->ID,areaEntry->area_name[m_session->GetSessionDbcLocale()],map->GetId(),map->GetMapName());
2257 SetSentErrorMessage(true);
2258 return false;
2261 Zone2MapCoordinates(x,y,zoneEntry->ID);
2263 if(!MapManager::IsValidMapCoord(zoneEntry->mapid,x,y))
2265 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,zoneEntry->mapid);
2266 SetSentErrorMessage(true);
2267 return false;
2270 // stop flight if need
2271 if(_player->isInFlight())
2273 _player->GetMotionMaster()->MovementExpired();
2274 _player->m_taxi.ClearTaxiDestinations();
2276 // save only in non-flight case
2277 else
2278 _player->SaveRecallPosition();
2280 float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
2281 _player->TeleportTo(zoneEntry->mapid, x, y, z, _player->GetOrientation());
2283 return true;
2286 //teleport to grid
2287 bool ChatHandler::HandleGoGridCommand(const char* args)
2289 if(!*args) return false;
2290 Player* _player = m_session->GetPlayer();
2292 char* px = strtok((char*)args, " ");
2293 char* py = strtok(NULL, " ");
2294 char* pmapid = strtok(NULL, " ");
2296 if (!px || !py)
2297 return false;
2299 float grid_x = (float)atof(px);
2300 float grid_y = (float)atof(py);
2301 uint32 mapid;
2302 if (pmapid)
2303 mapid = (uint32)atoi(pmapid);
2304 else mapid = _player->GetMapId();
2306 // center of grid
2307 float x = (grid_x-CENTER_GRID_ID+0.5f)*SIZE_OF_GRIDS;
2308 float y = (grid_y-CENTER_GRID_ID+0.5f)*SIZE_OF_GRIDS;
2310 if(!MapManager::IsValidMapCoord(mapid,x,y))
2312 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
2313 SetSentErrorMessage(true);
2314 return false;
2317 // stop flight if need
2318 if(_player->isInFlight())
2320 _player->GetMotionMaster()->MovementExpired();
2321 _player->m_taxi.ClearTaxiDestinations();
2323 // save only in non-flight case
2324 else
2325 _player->SaveRecallPosition();
2327 Map const *map = MapManager::Instance().GetBaseMap(mapid);
2328 float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
2329 _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
2331 return true;
2334 bool ChatHandler::HandleDrunkCommand(const char* args)
2336 if(!*args) return false;
2338 uint32 drunklevel = (uint32)atoi(args);
2339 if(drunklevel > 100)
2340 drunklevel = 100;
2342 uint16 drunkMod = drunklevel * 0xFFFF / 100;
2344 m_session->GetPlayer()->SetDrunkValue(drunkMod);
2346 return true;