* Move account related functions from ObjectMgr to AccountMgr and drop duplicate...
[auctionmangos.git] / src / game / Level3.cpp
blob742ddaef8c023e8fbb5e8e24f8995507af1cf6b6
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 "AccountMgr.h"
26 #include "PlayerDump.h"
27 #include "SpellMgr.h"
28 #include "Player.h"
29 #include "Opcodes.h"
30 #include "GameObject.h"
31 #include "Chat.h"
32 #include "Log.h"
33 #include "Guild.h"
34 #include "ObjectAccessor.h"
35 #include "MapManager.h"
36 #include "SpellAuras.h"
37 #include "ScriptCalls.h"
38 #include "Language.h"
39 #include "GridNotifiersImpl.h"
40 #include "CellImpl.h"
41 #include "Weather.h"
42 #include "PointMovementGenerator.h"
43 #include "TargetedMovementGenerator.h"
44 #include "SkillDiscovery.h"
45 #include "SkillExtraItems.h"
46 #include "SystemConfig.h"
47 #include "Config/ConfigEnv.h"
48 #include "Util.h"
49 #include "ItemEnchantmentMgr.h"
50 #include "InstanceSaveMgr.h"
51 #include "InstanceData.h"
53 //reload commands
54 bool ChatHandler::HandleReloadCommand(const char* arg)
56 // this is error catcher for wrong table name in .reload commands
57 PSendSysMessage("Db table with name starting from '%s' not found and can't be reloaded.",arg);
58 SetSentErrorMessage(true);
59 return false;
62 bool ChatHandler::HandleReloadAllCommand(const char*)
64 HandleReloadAreaTriggerTeleportCommand("");
65 HandleReloadSkillFishingBaseLevelCommand("");
67 HandleReloadAllAreaCommand("");
68 HandleReloadAllLootCommand("");
69 HandleReloadAllNpcCommand("");
70 HandleReloadAllQuestCommand("");
71 HandleReloadAllSpellCommand("");
72 HandleReloadAllItemCommand("");
73 HandleReloadAllLocalesCommand("");
75 HandleReloadCommandCommand("");
76 HandleReloadReservedNameCommand("");
77 HandleReloadMangosStringCommand("");
78 HandleReloadGameTeleCommand("");
79 return true;
82 bool ChatHandler::HandleReloadAllAreaCommand(const char*)
84 //HandleReloadQuestAreaTriggersCommand(""); -- reloaded in HandleReloadAllQuestCommand
85 HandleReloadAreaTriggerTeleportCommand("");
86 HandleReloadAreaTriggerTavernCommand("");
87 HandleReloadGameGraveyardZoneCommand("");
88 return true;
91 bool ChatHandler::HandleReloadAllLootCommand(const char*)
93 sLog.outString( "Re-Loading Loot Tables..." );
94 LoadLootTables();
95 SendGlobalSysMessage("DB tables `*_loot_template` reloaded.");
96 return true;
99 bool ChatHandler::HandleReloadAllNpcCommand(const char* /*args*/)
101 HandleReloadNpcGossipCommand("a");
102 HandleReloadNpcTrainerCommand("a");
103 HandleReloadNpcVendorCommand("a");
104 return true;
107 bool ChatHandler::HandleReloadAllQuestCommand(const char* /*args*/)
109 HandleReloadQuestAreaTriggersCommand("a");
110 HandleReloadQuestTemplateCommand("a");
112 sLog.outString( "Re-Loading Quests Relations..." );
113 objmgr.LoadQuestRelations();
114 SendGlobalSysMessage("DB tables `*_questrelation` and `*_involvedrelation` reloaded.");
115 return true;
118 bool ChatHandler::HandleReloadAllScriptsCommand(const char*)
120 if(sWorld.IsScriptScheduled())
122 PSendSysMessage("DB scripts used currently, please attempt reload later.");
123 SetSentErrorMessage(true);
124 return false;
127 sLog.outString( "Re-Loading Scripts..." );
128 HandleReloadGameObjectScriptsCommand("a");
129 HandleReloadEventScriptsCommand("a");
130 HandleReloadQuestEndScriptsCommand("a");
131 HandleReloadQuestStartScriptsCommand("a");
132 HandleReloadSpellScriptsCommand("a");
133 SendGlobalSysMessage("DB tables `*_scripts` reloaded.");
134 return true;
137 bool ChatHandler::HandleReloadAllSpellCommand(const char*)
139 HandleReloadSkillDiscoveryTemplateCommand("a");
140 HandleReloadSkillExtraItemTemplateCommand("a");
141 HandleReloadSpellAffectCommand("a");
142 HandleReloadSpellChainCommand("a");
143 HandleReloadSpellElixirCommand("a");
144 HandleReloadSpellLearnSpellCommand("a");
145 HandleReloadSpellProcEventCommand("a");
146 HandleReloadSpellScriptTargetCommand("a");
147 HandleReloadSpellTargetPositionCommand("a");
148 HandleReloadSpellThreatsCommand("a");
149 HandleReloadSpellPetAurasCommand("a");
150 return true;
153 bool ChatHandler::HandleReloadAllItemCommand(const char*)
155 HandleReloadPageTextsCommand("a");
156 HandleReloadItemEnchantementsCommand("a");
157 return true;
160 bool ChatHandler::HandleReloadAllLocalesCommand(const char* args)
162 HandleReloadLocalesCreatureCommand("a");
163 HandleReloadLocalesGameobjectCommand("a");
164 HandleReloadLocalesItemCommand("a");
165 HandleReloadLocalesNpcTextCommand("a");
166 HandleReloadLocalesPageTextCommand("a");
167 HandleReloadLocalesQuestCommand("a");
168 return true;
171 bool ChatHandler::HandleReloadConfigCommand(const char* arg)
173 sLog.outString( "Re-Loading config settings..." );
174 sWorld.LoadConfigSettings(true);
175 SendGlobalSysMessage("World config settings reloaded.");
176 return true;
179 bool ChatHandler::HandleReloadAreaTriggerTavernCommand(const char*)
181 sLog.outString( "Re-Loading Tavern Area Triggers..." );
182 objmgr.LoadTavernAreaTriggers();
183 SendGlobalSysMessage("DB table `areatrigger_tavern` reloaded.");
184 return true;
187 bool ChatHandler::HandleReloadAreaTriggerTeleportCommand(const char*)
189 sLog.outString( "Re-Loading AreaTrigger teleport definitions..." );
190 objmgr.LoadAreaTriggerTeleports();
191 SendGlobalSysMessage("DB table `areatrigger_teleport` reloaded.");
192 return true;
195 bool ChatHandler::HandleReloadCommandCommand(const char*)
197 load_command_table = true;
198 SendGlobalSysMessage("DB table `command` will be reloaded at next chat command use.");
199 return true;
202 bool ChatHandler::HandleReloadCreatureQuestRelationsCommand(const char*)
204 sLog.outString( "Loading Quests Relations... (`creature_questrelation`)" );
205 objmgr.LoadCreatureQuestRelations();
206 SendGlobalSysMessage("DB table `creature_questrelation` (creature quest givers) reloaded.");
207 return true;
210 bool ChatHandler::HandleReloadCreatureQuestInvRelationsCommand(const char*)
212 sLog.outString( "Loading Quests Relations... (`creature_involvedrelation`)" );
213 objmgr.LoadCreatureInvolvedRelations();
214 SendGlobalSysMessage("DB table `creature_involvedrelation` (creature quest takers) reloaded.");
215 return true;
218 bool ChatHandler::HandleReloadGOQuestRelationsCommand(const char*)
220 sLog.outString( "Loading Quests Relations... (`gameobject_questrelation`)" );
221 objmgr.LoadGameobjectQuestRelations();
222 SendGlobalSysMessage("DB table `gameobject_questrelation` (gameobject quest givers) reloaded.");
223 return true;
226 bool ChatHandler::HandleReloadGOQuestInvRelationsCommand(const char*)
228 sLog.outString( "Loading Quests Relations... (`gameobject_involvedrelation`)" );
229 objmgr.LoadGameobjectInvolvedRelations();
230 SendGlobalSysMessage("DB table `gameobject_involvedrelation` (gameobject quest takers) reloaded.");
231 return true;
234 bool ChatHandler::HandleReloadQuestAreaTriggersCommand(const char*)
236 sLog.outString( "Re-Loading Quest Area Triggers..." );
237 objmgr.LoadQuestAreaTriggers();
238 SendGlobalSysMessage("DB table `areatrigger_involvedrelation` (quest area triggers) reloaded.");
239 return true;
242 bool ChatHandler::HandleReloadQuestTemplateCommand(const char*)
244 sLog.outString( "Re-Loading Quest Templates..." );
245 objmgr.LoadQuests();
246 SendGlobalSysMessage("DB table `quest_template` (quest definitions) reloaded.");
247 return true;
250 bool ChatHandler::HandleReloadLootTemplatesCreatureCommand(const char*)
252 sLog.outString( "Re-Loading Loot Tables... (`creature_loot_template`)" );
253 LoadLootTemplates_Creature();
254 LootTemplates_Creature.CheckLootRefs();
255 SendGlobalSysMessage("DB table `creature_loot_template` reloaded.");
256 return true;
259 bool ChatHandler::HandleReloadLootTemplatesDisenchantCommand(const char*)
261 sLog.outString( "Re-Loading Loot Tables... (`disenchant_loot_template`)" );
262 LoadLootTemplates_Disenchant();
263 LootTemplates_Disenchant.CheckLootRefs();
264 SendGlobalSysMessage("DB table `disenchant_loot_template` reloaded.");
265 return true;
268 bool ChatHandler::HandleReloadLootTemplatesFishingCommand(const char*)
270 sLog.outString( "Re-Loading Loot Tables... (`fishing_loot_template`)" );
271 LoadLootTemplates_Fishing();
272 LootTemplates_Fishing.CheckLootRefs();
273 SendGlobalSysMessage("DB table `fishing_loot_template` reloaded.");
274 return true;
277 bool ChatHandler::HandleReloadLootTemplatesGameobjectCommand(const char*)
279 sLog.outString( "Re-Loading Loot Tables... (`gameobject_loot_template`)" );
280 LoadLootTemplates_Gameobject();
281 LootTemplates_Gameobject.CheckLootRefs();
282 SendGlobalSysMessage("DB table `gameobject_loot_template` reloaded.");
283 return true;
286 bool ChatHandler::HandleReloadLootTemplatesItemCommand(const char*)
288 sLog.outString( "Re-Loading Loot Tables... (`item_loot_template`)" );
289 LoadLootTemplates_Item();
290 LootTemplates_Item.CheckLootRefs();
291 SendGlobalSysMessage("DB table `item_loot_template` reloaded.");
292 return true;
295 bool ChatHandler::HandleReloadLootTemplatesPickpocketingCommand(const char*)
297 sLog.outString( "Re-Loading Loot Tables... (`pickpocketing_loot_template`)" );
298 LoadLootTemplates_Pickpocketing();
299 LootTemplates_Pickpocketing.CheckLootRefs();
300 SendGlobalSysMessage("DB table `pickpocketing_loot_template` reloaded.");
301 return true;
304 bool ChatHandler::HandleReloadLootTemplatesProspectingCommand(const char*)
306 sLog.outString( "Re-Loading Loot Tables... (`prospecting_loot_template`)" );
307 LoadLootTemplates_Prospecting();
308 LootTemplates_Prospecting.CheckLootRefs();
309 SendGlobalSysMessage("DB table `prospecting_loot_template` reloaded.");
310 return true;
313 bool ChatHandler::HandleReloadLootTemplatesQuestMailCommand(const char*)
315 sLog.outString( "Re-Loading Loot Tables... (`quest_mail_loot_template`)" );
316 LoadLootTemplates_QuestMail();
317 LootTemplates_QuestMail.CheckLootRefs();
318 SendGlobalSysMessage("DB table `quest_mail_loot_template` reloaded.");
319 return true;
322 bool ChatHandler::HandleReloadLootTemplatesReferenceCommand(const char*)
324 sLog.outString( "Re-Loading Loot Tables... (`reference_loot_template`)" );
325 LoadLootTemplates_Reference();
326 SendGlobalSysMessage("DB table `reference_loot_template` reloaded.");
327 return true;
330 bool ChatHandler::HandleReloadLootTemplatesSkinningCommand(const char*)
332 sLog.outString( "Re-Loading Loot Tables... (`skinning_loot_template`)" );
333 LoadLootTemplates_Skinning();
334 LootTemplates_Skinning.CheckLootRefs();
335 SendGlobalSysMessage("DB table `skinning_loot_template` reloaded.");
336 return true;
339 bool ChatHandler::HandleReloadMangosStringCommand(const char*)
341 sLog.outString( "Re-Loading mangos_string Table!" );
342 objmgr.LoadMangosStrings();
343 SendGlobalSysMessage("DB table `mangos_string` reloaded.");
344 return true;
347 bool ChatHandler::HandleReloadNpcGossipCommand(const char*)
349 sLog.outString( "Re-Loading `npc_gossip` Table!" );
350 objmgr.LoadNpcTextId();
351 SendGlobalSysMessage("DB table `npc_gossip` reloaded.");
352 return true;
355 bool ChatHandler::HandleReloadNpcTrainerCommand(const char*)
357 sLog.outString( "Re-Loading `npc_trainer` Table!" );
358 objmgr.LoadTrainerSpell();
359 SendGlobalSysMessage("DB table `npc_trainer` reloaded.");
360 return true;
363 bool ChatHandler::HandleReloadNpcVendorCommand(const char*)
365 sLog.outString( "Re-Loading `npc_vendor` Table!" );
366 objmgr.LoadVendors();
367 SendGlobalSysMessage("DB table `npc_vendor` reloaded.");
368 return true;
371 bool ChatHandler::HandleReloadReservedNameCommand(const char*)
373 sLog.outString( "Loading ReservedNames... (`reserved_name`)" );
374 objmgr.LoadReservedPlayersNames();
375 SendGlobalSysMessage("DB table `reserved_name` (player reserved names) reloaded.");
376 return true;
379 bool ChatHandler::HandleReloadSkillDiscoveryTemplateCommand(const char* /*args*/)
381 sLog.outString( "Re-Loading Skill Discovery Table..." );
382 LoadSkillDiscoveryTable();
383 SendGlobalSysMessage("DB table `skill_discovery_template` (recipes discovered at crafting) reloaded.");
384 return true;
387 bool ChatHandler::HandleReloadSkillExtraItemTemplateCommand(const char* /*args*/)
389 sLog.outString( "Re-Loading Skill Extra Item Table..." );
390 LoadSkillExtraItemTable();
391 SendGlobalSysMessage("DB table `skill_extra_item_template` (extra item creation when crafting) reloaded.");
392 return true;
395 bool ChatHandler::HandleReloadSkillFishingBaseLevelCommand(const char* /*args*/)
397 sLog.outString( "Re-Loading Skill Fishing base level requirements..." );
398 objmgr.LoadFishingBaseSkillLevel();
399 SendGlobalSysMessage("DB table `skill_fishing_base_level` (fishing base level for zone/subzone) reloaded.");
400 return true;
403 bool ChatHandler::HandleReloadSpellAffectCommand(const char*)
405 sLog.outString( "Re-Loading SpellAffect definitions..." );
406 spellmgr.LoadSpellAffects();
407 SendGlobalSysMessage("DB table `spell_affect` (spell mods apply requirements) reloaded.");
408 return true;
411 bool ChatHandler::HandleReloadSpellChainCommand(const char*)
413 sLog.outString( "Re-Loading Spell Chain Data... " );
414 spellmgr.LoadSpellChains();
415 SendGlobalSysMessage("DB table `spell_chain` (spell ranks) reloaded.");
416 return true;
419 bool ChatHandler::HandleReloadSpellElixirCommand(const char*)
421 sLog.outString( "Re-Loading Spell Elixir types..." );
422 spellmgr.LoadSpellElixirs();
423 SendGlobalSysMessage("DB table `spell_elixir` (spell exlixir types) reloaded.");
424 return true;
427 bool ChatHandler::HandleReloadSpellLearnSpellCommand(const char*)
429 sLog.outString( "Re-Loading Spell Learn Spells..." );
430 spellmgr.LoadSpellLearnSpells();
431 SendGlobalSysMessage("DB table `spell_learn_spell` reloaded.");
432 return true;
435 bool ChatHandler::HandleReloadSpellProcEventCommand(const char*)
437 sLog.outString( "Re-Loading Spell Proc Event conditions..." );
438 spellmgr.LoadSpellProcEvents();
439 SendGlobalSysMessage("DB table `spell_proc_event` (spell proc trigger requirements) reloaded.");
440 return true;
443 bool ChatHandler::HandleReloadSpellScriptTargetCommand(const char*)
445 sLog.outString( "Re-Loading SpellsScriptTarget..." );
446 spellmgr.LoadSpellScriptTarget();
447 SendGlobalSysMessage("DB table `spell_script_target` (spell targets selection in case specific creature/GO requirements) reloaded.");
448 return true;
451 bool ChatHandler::HandleReloadSpellTargetPositionCommand(const char*)
453 sLog.outString( "Re-Loading Spell target coordinates..." );
454 spellmgr.LoadSpellTargetPositions();
455 SendGlobalSysMessage("DB table `spell_target_position` (destination coordinates for spell targets) reloaded.");
456 return true;
459 bool ChatHandler::HandleReloadSpellThreatsCommand(const char*)
461 sLog.outString( "Re-Loading Aggro Spells Definitions...");
462 spellmgr.LoadSpellThreats();
463 SendGlobalSysMessage("DB table `spell_threat` (spell aggro definitions) reloaded.");
464 return true;
467 bool ChatHandler::HandleReloadSpellPetAurasCommand(const char*)
469 sLog.outString( "Re-Loading Spell pet auras...");
470 spellmgr.LoadSpellPetAuras();
471 SendGlobalSysMessage("DB table `spell_pet_auras` reloaded.");
472 return true;
475 bool ChatHandler::HandleReloadPageTextsCommand(const char*)
477 sLog.outString( "Re-Loading Page Texts..." );
478 objmgr.LoadPageTexts();
479 SendGlobalSysMessage("DB table `page_texts` reloaded.");
480 return true;
483 bool ChatHandler::HandleReloadItemEnchantementsCommand(const char*)
485 sLog.outString( "Re-Loading Item Random Enchantments Table..." );
486 LoadRandomEnchantmentsTable();
487 SendGlobalSysMessage("DB table `item_enchantment_template` reloaded.");
488 return true;
491 bool ChatHandler::HandleReloadGameObjectScriptsCommand(const char* arg)
493 if(sWorld.IsScriptScheduled())
495 SendSysMessage("DB scripts used currently, please attempt reload later.");
496 SetSentErrorMessage(true);
497 return false;
500 if(*arg!='a')
501 sLog.outString( "Re-Loading Scripts from `gameobject_scripts`...");
503 objmgr.LoadGameObjectScripts();
505 if(*arg!='a')
506 SendGlobalSysMessage("DB table `gameobject_scripts` reloaded.");
508 return true;
511 bool ChatHandler::HandleReloadEventScriptsCommand(const char* arg)
513 if(sWorld.IsScriptScheduled())
515 SendSysMessage("DB scripts used currently, please attempt reload later.");
516 SetSentErrorMessage(true);
517 return false;
520 if(*arg!='a')
521 sLog.outString( "Re-Loading Scripts from `event_scripts`...");
523 objmgr.LoadEventScripts();
525 if(*arg!='a')
526 SendGlobalSysMessage("DB table `event_scripts` reloaded.");
528 return true;
531 bool ChatHandler::HandleReloadQuestEndScriptsCommand(const char* arg)
533 if(sWorld.IsScriptScheduled())
535 SendSysMessage("DB scripts used currently, please attempt reload later.");
536 SetSentErrorMessage(true);
537 return false;
540 if(*arg!='a')
541 sLog.outString( "Re-Loading Scripts from `quest_end_scripts`...");
543 objmgr.LoadQuestEndScripts();
545 if(*arg!='a')
546 SendGlobalSysMessage("DB table `quest_end_scripts` reloaded.");
548 return true;
551 bool ChatHandler::HandleReloadQuestStartScriptsCommand(const char* arg)
553 if(sWorld.IsScriptScheduled())
555 SendSysMessage("DB scripts used currently, please attempt reload later.");
556 SetSentErrorMessage(true);
557 return false;
560 if(*arg!='a')
561 sLog.outString( "Re-Loading Scripts from `quest_start_scripts`...");
563 objmgr.LoadQuestStartScripts();
565 if(*arg!='a')
566 SendGlobalSysMessage("DB table `quest_start_scripts` reloaded.");
568 return true;
571 bool ChatHandler::HandleReloadSpellScriptsCommand(const char* arg)
573 if(sWorld.IsScriptScheduled())
575 SendSysMessage("DB scripts used currently, please attempt reload later.");
576 SetSentErrorMessage(true);
577 return false;
580 if(*arg!='a')
581 sLog.outString( "Re-Loading Scripts from `spell_scripts`...");
583 objmgr.LoadSpellScripts();
585 if(*arg!='a')
586 SendGlobalSysMessage("DB table `spell_scripts` reloaded.");
588 return true;
591 bool ChatHandler::HandleReloadGameGraveyardZoneCommand(const char* /*arg*/)
593 sLog.outString( "Re-Loading Graveyard-zone links...");
595 objmgr.LoadGraveyardZones();
597 SendGlobalSysMessage("DB table `game_graveyard_zone` reloaded.");
599 return true;
602 bool ChatHandler::HandleReloadGameTeleCommand(const char* /*arg*/)
604 sLog.outString( "Re-Loading Game Tele coordinates...");
606 objmgr.LoadGameTele();
608 SendGlobalSysMessage("DB table `game_tele` reloaded.");
610 return true;
613 bool ChatHandler::HandleReloadLocalesCreatureCommand(const char* /*arg*/)
615 sLog.outString( "Re-Loading Locales Creature ...");
616 objmgr.LoadCreatureLocales();
617 SendGlobalSysMessage("DB table `locales_creature` reloaded.");
618 return true;
621 bool ChatHandler::HandleReloadLocalesGameobjectCommand(const char* /*arg*/)
623 sLog.outString( "Re-Loading Locales Gameobject ... ");
624 objmgr.LoadGameObjectLocales();
625 SendGlobalSysMessage("DB table `locales_gameobject` reloaded.");
626 return true;
629 bool ChatHandler::HandleReloadLocalesItemCommand(const char* /*arg*/)
631 sLog.outString( "Re-Loading Locales Item ... ");
632 objmgr.LoadItemLocales();
633 SendGlobalSysMessage("DB table `locales_item` reloaded.");
634 return true;
637 bool ChatHandler::HandleReloadLocalesNpcTextCommand(const char* /*arg*/)
639 sLog.outString( "Re-Loading Locales NPC Text ... ");
640 objmgr.LoadNpcTextLocales();
641 SendGlobalSysMessage("DB table `locales_npc_text` reloaded.");
642 return true;
645 bool ChatHandler::HandleReloadLocalesPageTextCommand(const char* /*arg*/)
647 sLog.outString( "Re-Loading Locales Page Text ... ");
648 objmgr.LoadPageTextLocales();
649 SendGlobalSysMessage("DB table `locales_page_text` reloaded.");
650 return true;
653 bool ChatHandler::HandleReloadLocalesQuestCommand(const char* /*arg*/)
655 sLog.outString( "Re-Loading Locales Quest ... ");
656 objmgr.LoadQuestLocales();
657 SendGlobalSysMessage("DB table `locales_quest` reloaded.");
658 return true;
661 bool ChatHandler::HandleLoadScriptsCommand(const char* args)
663 if(!LoadScriptingModule(args)) return true;
665 sWorld.SendWorldText(LANG_SCRIPTS_RELOADED);
666 return true;
669 bool ChatHandler::HandleSecurityCommand(const char* args)
671 char* arg1 = strtok((char*)args, " ");
672 if( !arg1 )
673 return false;
675 char* arg2 = 0;
677 std::string targetName;
678 uint32 targetAccountId = 0;
679 uint32 targetSecurity = 0;
681 Player* targetPlayer = getSelectedPlayer();
682 if(targetPlayer)
684 targetName = targetPlayer->GetName();
685 targetAccountId = targetPlayer->GetSession()->GetAccountId();
686 targetSecurity = targetPlayer->GetSession()->GetSecurity();
687 arg2 = arg1;
689 else
691 targetName = arg1;
692 if(!normalizePlayerName(targetName))
694 SendSysMessage(LANG_PLAYER_NOT_FOUND);
695 SetSentErrorMessage(true);
696 return false;
699 targetPlayer = ObjectAccessor::Instance().FindPlayerByName(targetName.c_str());
700 if(targetPlayer)
702 targetAccountId = targetPlayer->GetSession()->GetAccountId();
703 targetSecurity = targetPlayer->GetSession()->GetSecurity();
705 else
707 uint64 targetGUID = objmgr.GetPlayerGUIDByName(targetName.c_str());
708 if(!targetGUID)
710 SendSysMessage(LANG_PLAYER_NOT_FOUND);
711 SetSentErrorMessage(true);
712 return false;
714 targetAccountId = objmgr.GetPlayerAccountIdByGUID(targetGUID);
715 targetSecurity = accmgr.GetSecurity(targetAccountId);
718 arg2 = strtok(NULL, " ");
721 int32 gm = (int32)atoi(arg2);
722 if ( gm < SEC_PLAYER || gm > SEC_ADMINISTRATOR )
724 SendSysMessage(LANG_BAD_VALUE);
725 SetSentErrorMessage(true);
726 return false;
729 // can set security level only for target with less security and to less security that we have
730 if(targetSecurity >= m_session->GetSecurity() || uint32(gm) >= m_session->GetSecurity() )
732 SendSysMessage(LANG_YOURS_SECURITY_IS_LOW);
733 SetSentErrorMessage(true);
734 return false;
737 if(targetPlayer)
739 if( targetPlayer != m_session->GetPlayer() )
740 ChatHandler(targetPlayer).PSendSysMessage(LANG_YOURS_SECURITY_CHANGED,m_session->GetPlayer()->GetName(), gm);
742 targetPlayer->GetSession()->SetSecurity(gm);
745 PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetName.c_str(), gm);
746 loginDatabase.PExecute("UPDATE account SET gmlevel = '%i' WHERE id = '%u'", gm, targetAccountId);
748 return true;
751 bool ChatHandler::HandleAllowMovementCommand(const char* /*args*/)
753 if(sWorld.getAllowMovement())
755 sWorld.SetAllowMovement(false);
756 SendSysMessage(LANG_CREATURE_MOVE_DISABLED);
758 else
760 sWorld.SetAllowMovement(true);
761 SendSysMessage(LANG_CREATURE_MOVE_ENABLED);
763 return true;
766 bool ChatHandler::HandleMaxSkillCommand(const char* /*args*/)
768 Player* SelectedPlayer = getSelectedPlayer();
769 if(!SelectedPlayer)
771 SendSysMessage(LANG_NO_CHAR_SELECTED);
772 SetSentErrorMessage(true);
773 return false;
776 // each skills that have max skill value dependent from level seted to current level max skill value
777 SelectedPlayer->UpdateSkillsToMaxSkillsForLevel();
778 return true;
781 bool ChatHandler::HandleSetSkillCommand(const char* args)
783 // number or [name] Shift-click form |color|Hskill:skill_id|h[name]|h|r
784 char* skill_p = extractKeyFromLink((char*)args,"Hskill");
785 if(!skill_p)
786 return false;
788 char *level_p = strtok (NULL, " ");
790 if( !level_p)
791 return false;
793 char *max_p = strtok (NULL, " ");
795 int32 skill = atoi(skill_p);
797 if (skill <= 0)
799 PSendSysMessage(LANG_INVALID_SKILL_ID, skill);
800 SetSentErrorMessage(true);
801 return false;
804 int32 level = atol (level_p);
806 Player * target = getSelectedPlayer();
807 if(!target)
809 SendSysMessage(LANG_NO_CHAR_SELECTED);
810 SetSentErrorMessage(true);
811 return false;
814 SkillLineEntry const* sl = sSkillLineStore.LookupEntry(skill);
815 if(!sl)
817 PSendSysMessage(LANG_INVALID_SKILL_ID, skill);
818 SetSentErrorMessage(true);
819 return false;
822 if(!target->GetSkillValue(skill))
824 PSendSysMessage(LANG_SET_SKILL_ERROR, target->GetName(), skill, sl->name[0]);
825 SetSentErrorMessage(true);
826 return false;
829 int32 max = max_p ? atol (max_p) : target->GetPureMaxSkillValue(skill);
831 if( level <= 0 || level > max || max <= 0 )
832 return false;
834 target->SetSkill(skill, level, max);
835 PSendSysMessage(LANG_SET_SKILL, skill, sl->name[0], target->GetName(), level, max);
837 return true;
840 bool ChatHandler::HandleUnLearnCommand(const char* args)
842 if (!*args)
843 return false;
845 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
846 uint32 min_id = extractSpellIdFromLink((char*)args);
847 if(!min_id)
848 return false;
850 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
851 char* tail = strtok(NULL,"");
853 uint32 max_id = extractSpellIdFromLink(tail);
855 if (!max_id)
857 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
858 max_id = min_id+1;
860 else
862 if (max_id < min_id)
863 std::swap(min_id,max_id);
865 max_id=max_id+1;
868 Player* target = getSelectedPlayer();
869 if(!target)
871 SendSysMessage(LANG_NO_CHAR_SELECTED);
872 SetSentErrorMessage(true);
873 return false;
876 for(uint32 spell=min_id;spell<max_id;spell++)
878 if (target->HasSpell(spell))
879 target->removeSpell(spell);
880 else
881 SendSysMessage(LANG_FORGET_SPELL);
884 return true;
887 bool ChatHandler::HandleCooldownCommand(const char* args)
889 Player* target = getSelectedPlayer();
890 if(!target)
892 SendSysMessage(LANG_PLAYER_NOT_FOUND);
893 SetSentErrorMessage(true);
894 return false;
897 if (!*args)
899 target->RemoveAllSpellCooldown();
900 PSendSysMessage(LANG_REMOVEALL_COOLDOWN, target->GetName());
902 else
904 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
905 uint32 spell_id = extractSpellIdFromLink((char*)args);
906 if(!spell_id)
907 return false;
909 if(!sSpellStore.LookupEntry(spell_id))
911 PSendSysMessage(LANG_UNKNOWN_SPELL, target==m_session->GetPlayer() ? GetMangosString(LANG_YOU) : target->GetName());
912 SetSentErrorMessage(true);
913 return false;
916 WorldPacket data( SMSG_CLEAR_COOLDOWN, (4+8) );
917 data << uint32(spell_id);
918 data << uint64(target->GetGUID());
919 target->GetSession()->SendPacket(&data);
920 target->RemoveSpellCooldown(spell_id);
921 PSendSysMessage(LANG_REMOVE_COOLDOWN, spell_id, target==m_session->GetPlayer() ? GetMangosString(LANG_YOU) : target->GetName());
923 return true;
926 bool ChatHandler::HandleLearnAllCommand(const char* /*args*/)
928 static const char *allSpellList[] =
930 "3365",
931 "6233",
932 "6247",
933 "6246",
934 "6477",
935 "6478",
936 "22810",
937 "8386",
938 "21651",
939 "21652",
940 "522",
941 "7266",
942 "8597",
943 "2479",
944 "22027",
945 "6603",
946 "5019",
947 "133",
948 "168",
949 "227",
950 "5009",
951 "9078",
952 "668",
953 "203",
954 "20599",
955 "20600",
956 "81",
957 "20597",
958 "20598",
959 "20864",
960 "1459",
961 "5504",
962 "587",
963 "5143",
964 "118",
965 "5505",
966 "597",
967 "604",
968 "1449",
969 "1460",
970 "2855",
971 "1008",
972 "475",
973 "5506",
974 "1463",
975 "12824",
976 "8437",
977 "990",
978 "5145",
979 "8450",
980 "1461",
981 "759",
982 "8494",
983 "8455",
984 "8438",
985 "6127",
986 "8416",
987 "6129",
988 "8451",
989 "8495",
990 "8439",
991 "3552",
992 "8417",
993 "10138",
994 "12825",
995 "10169",
996 "10156",
997 "10144",
998 "10191",
999 "10201",
1000 "10211",
1001 "10053",
1002 "10173",
1003 "10139",
1004 "10145",
1005 "10192",
1006 "10170",
1007 "10202",
1008 "10054",
1009 "10174",
1010 "10193",
1011 "12826",
1012 "2136",
1013 "143",
1014 "145",
1015 "2137",
1016 "2120",
1017 "3140",
1018 "543",
1019 "2138",
1020 "2948",
1021 "8400",
1022 "2121",
1023 "8444",
1024 "8412",
1025 "8457",
1026 "8401",
1027 "8422",
1028 "8445",
1029 "8402",
1030 "8413",
1031 "8458",
1032 "8423",
1033 "8446",
1034 "10148",
1035 "10197",
1036 "10205",
1037 "10149",
1038 "10215",
1039 "10223",
1040 "10206",
1041 "10199",
1042 "10150",
1043 "10216",
1044 "10207",
1045 "10225",
1046 "10151",
1047 "116",
1048 "205",
1049 "7300",
1050 "122",
1051 "837",
1052 "10",
1053 "7301",
1054 "7322",
1055 "6143",
1056 "120",
1057 "865",
1058 "8406",
1059 "6141",
1060 "7302",
1061 "8461",
1062 "8407",
1063 "8492",
1064 "8427",
1065 "8408",
1066 "6131",
1067 "7320",
1068 "10159",
1069 "8462",
1070 "10185",
1071 "10179",
1072 "10160",
1073 "10180",
1074 "10219",
1075 "10186",
1076 "10177",
1077 "10230",
1078 "10181",
1079 "10161",
1080 "10187",
1081 "10220",
1082 "2018",
1083 "2663",
1084 "12260",
1085 "2660",
1086 "3115",
1087 "3326",
1088 "2665",
1089 "3116",
1090 "2738",
1091 "3293",
1092 "2661",
1093 "3319",
1094 "2662",
1095 "9983",
1096 "8880",
1097 "2737",
1098 "2739",
1099 "7408",
1100 "3320",
1101 "2666",
1102 "3323",
1103 "3324",
1104 "3294",
1105 "22723",
1106 "23219",
1107 "23220",
1108 "23221",
1109 "23228",
1110 "23338",
1111 "10788",
1112 "10790",
1113 "5611",
1114 "5016",
1115 "5609",
1116 "2060",
1117 "10963",
1118 "10964",
1119 "10965",
1120 "22593",
1121 "22594",
1122 "596",
1123 "996",
1124 "499",
1125 "768",
1126 "17002",
1127 "1448",
1128 "1082",
1129 "16979",
1130 "1079",
1131 "5215",
1132 "20484",
1133 "5221",
1134 "15590",
1135 "17007",
1136 "6795",
1137 "6807",
1138 "5487",
1139 "1446",
1140 "1066",
1141 "5421",
1142 "3139",
1143 "779",
1144 "6811",
1145 "6808",
1146 "1445",
1147 "5216",
1148 "1737",
1149 "5222",
1150 "5217",
1151 "1432",
1152 "6812",
1153 "9492",
1154 "5210",
1155 "3030",
1156 "1441",
1157 "783",
1158 "6801",
1159 "20739",
1160 "8944",
1161 "9491",
1162 "22569",
1163 "5226",
1164 "6786",
1165 "1433",
1166 "8973",
1167 "1828",
1168 "9495",
1169 "9006",
1170 "6794",
1171 "8993",
1172 "5203",
1173 "16914",
1174 "6784",
1175 "9635",
1176 "22830",
1177 "20722",
1178 "9748",
1179 "6790",
1180 "9753",
1181 "9493",
1182 "9752",
1183 "9831",
1184 "9825",
1185 "9822",
1186 "5204",
1187 "5401",
1188 "22831",
1189 "6793",
1190 "9845",
1191 "17401",
1192 "9882",
1193 "9868",
1194 "20749",
1195 "9893",
1196 "9899",
1197 "9895",
1198 "9832",
1199 "9902",
1200 "9909",
1201 "22832",
1202 "9828",
1203 "9851",
1204 "9883",
1205 "9869",
1206 "17406",
1207 "17402",
1208 "9914",
1209 "20750",
1210 "9897",
1211 "9848",
1212 "3127",
1213 "107",
1214 "204",
1215 "9116",
1216 "2457",
1217 "78",
1218 "18848",
1219 "331",
1220 "403",
1221 "2098",
1222 "1752",
1223 "11278",
1224 "11288",
1225 "11284",
1226 "6461",
1227 "2344",
1228 "2345",
1229 "6463",
1230 "2346",
1231 "2352",
1232 "775",
1233 "1434",
1234 "1612",
1235 "71",
1236 "2468",
1237 "2458",
1238 "2467",
1239 "7164",
1240 "7178",
1241 "7367",
1242 "7376",
1243 "7381",
1244 "21156",
1245 "5209",
1246 "3029",
1247 "5201",
1248 "9849",
1249 "9850",
1250 "20719",
1251 "22568",
1252 "22827",
1253 "22828",
1254 "22829",
1255 "6809",
1256 "8972",
1257 "9005",
1258 "9823",
1259 "9827",
1260 "6783",
1261 "9913",
1262 "6785",
1263 "6787",
1264 "9866",
1265 "9867",
1266 "9894",
1267 "9896",
1268 "6800",
1269 "8992",
1270 "9829",
1271 "9830",
1272 "780",
1273 "769",
1274 "6749",
1275 "6750",
1276 "9755",
1277 "9754",
1278 "9908",
1279 "20745",
1280 "20742",
1281 "20747",
1282 "20748",
1283 "9746",
1284 "9745",
1285 "9880",
1286 "9881",
1287 "5391",
1288 "842",
1289 "3025",
1290 "3031",
1291 "3287",
1292 "3329",
1293 "1945",
1294 "3559",
1295 "4933",
1296 "4934",
1297 "4935",
1298 "4936",
1299 "5142",
1300 "5390",
1301 "5392",
1302 "5404",
1303 "5420",
1304 "6405",
1305 "7293",
1306 "7965",
1307 "8041",
1308 "8153",
1309 "9033",
1310 "9034",
1311 //"9036", problems with ghost state
1312 "16421",
1313 "21653",
1314 "22660",
1315 "5225",
1316 "9846",
1317 "2426",
1318 "5916",
1319 "6634",
1320 //"6718", phasing stealth, annoing for learn all case.
1321 "6719",
1322 "8822",
1323 "9591",
1324 "9590",
1325 "10032",
1326 "17746",
1327 "17747",
1328 "8203",
1329 "11392",
1330 "12495",
1331 "16380",
1332 "23452",
1333 "4079",
1334 "4996",
1335 "4997",
1336 "4998",
1337 "4999",
1338 "5000",
1339 "6348",
1340 "6349",
1341 "6481",
1342 "6482",
1343 "6483",
1344 "6484",
1345 "11362",
1346 "11410",
1347 "11409",
1348 "12510",
1349 "12509",
1350 "12885",
1351 "13142",
1352 "21463",
1353 "23460",
1354 "11421",
1355 "11416",
1356 "11418",
1357 "1851",
1358 "10059",
1359 "11423",
1360 "11417",
1361 "11422",
1362 "11419",
1363 "11424",
1364 "11420",
1365 "27",
1366 "31",
1367 "33",
1368 "34",
1369 "35",
1370 "15125",
1371 "21127",
1372 "22950",
1373 "1180",
1374 "201",
1375 "12593",
1376 "12842",
1377 "16770",
1378 "6057",
1379 "12051",
1380 "18468",
1381 "12606",
1382 "12605",
1383 "18466",
1384 "12502",
1385 "12043",
1386 "15060",
1387 "12042",
1388 "12341",
1389 "12848",
1390 "12344",
1391 "12353",
1392 "18460",
1393 "11366",
1394 "12350",
1395 "12352",
1396 "13043",
1397 "11368",
1398 "11113",
1399 "12400",
1400 "11129",
1401 "16766",
1402 "12573",
1403 "15053",
1404 "12580",
1405 "12475",
1406 "12472",
1407 "12953",
1408 "12488",
1409 "11189",
1410 "12985",
1411 "12519",
1412 "16758",
1413 "11958",
1414 "12490",
1415 "11426",
1416 "3565",
1417 "3562",
1418 "18960",
1419 "3567",
1420 "3561",
1421 "3566",
1422 "3563",
1423 "1953",
1424 "2139",
1425 "12505",
1426 "13018",
1427 "12522",
1428 "12523",
1429 "5146",
1430 "5144",
1431 "5148",
1432 "8419",
1433 "8418",
1434 "10213",
1435 "10212",
1436 "10157",
1437 "12524",
1438 "13019",
1439 "12525",
1440 "13020",
1441 "12526",
1442 "13021",
1443 "18809",
1444 "13031",
1445 "13032",
1446 "13033",
1447 "4036",
1448 "3920",
1449 "3919",
1450 "3918",
1451 "7430",
1452 "3922",
1453 "3923",
1454 "7411",
1455 "7418",
1456 "7421",
1457 "13262",
1458 "7412",
1459 "7415",
1460 "7413",
1461 "7416",
1462 "13920",
1463 "13921",
1464 "7745",
1465 "7779",
1466 "7428",
1467 "7457",
1468 "7857",
1469 "7748",
1470 "7426",
1471 "13421",
1472 "7454",
1473 "13378",
1474 "7788",
1475 "14807",
1476 "14293",
1477 "7795",
1478 "6296",
1479 "20608",
1480 "755",
1481 "444",
1482 "427",
1483 "428",
1484 "442",
1485 "447",
1486 "3578",
1487 "3581",
1488 "19027",
1489 "3580",
1490 "665",
1491 "3579",
1492 "3577",
1493 "6755",
1494 "3576",
1495 "2575",
1496 "2577",
1497 "2578",
1498 "2579",
1499 "2580",
1500 "2656",
1501 "2657",
1502 "2576",
1503 "3564",
1504 "10248",
1505 "8388",
1506 "2659",
1507 "14891",
1508 "3308",
1509 "3307",
1510 "10097",
1511 "2658",
1512 "3569",
1513 "16153",
1514 "3304",
1515 "10098",
1516 "4037",
1517 "3929",
1518 "3931",
1519 "3926",
1520 "3924",
1521 "3930",
1522 "3977",
1523 "3925",
1524 "136",
1525 "228",
1526 "5487",
1527 "43",
1528 "202",
1532 int loop = 0;
1533 while(strcmp(allSpellList[loop], "0"))
1535 uint32 spell = atol((char*)allSpellList[loop++]);
1537 if (m_session->GetPlayer()->HasSpell(spell))
1538 continue;
1540 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
1541 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
1543 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
1544 continue;
1547 m_session->GetPlayer()->learnSpell(spell);
1550 SendSysMessage(LANG_COMMAND_LEARN_MANY_SPELLS);
1552 return true;
1555 bool ChatHandler::HandleLearnAllGMCommand(const char* /*args*/)
1557 static const char *gmSpellList[] =
1559 "24347", // Become A Fish, No Breath Bar
1560 "35132", // Visual Boom
1561 "38488", // Attack 4000-8000 AOE
1562 "38795", // Attack 2000 AOE + Slow Down 90%
1563 "15712", // Attack 200
1564 "1852", // GM Spell Silence
1565 "31899", // Kill
1566 "31924", // Kill
1567 "29878", // Kill My Self
1568 "26644", // More Kill
1570 "28550", //Invisible 24
1571 "23452", //Invisible + Target
1575 uint16 gmSpellIter = 0;
1576 while( strcmp(gmSpellList[gmSpellIter], "0") )
1578 uint32 spell = atol((char*)gmSpellList[gmSpellIter++]);
1580 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
1581 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
1583 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
1584 continue;
1587 m_session->GetPlayer()->learnSpell(spell);
1590 SendSysMessage(LANG_LEARNING_GM_SKILLS);
1591 return true;
1594 bool ChatHandler::HandleLearnAllMyClassCommand(const char* /*args*/)
1596 HandleLearnAllMySpellsCommand("");
1597 HandleLearnAllMyTalentsCommand("");
1598 return true;
1601 bool ChatHandler::HandleLearnAllMySpellsCommand(const char* /*args*/)
1603 ChrClassesEntry const* clsEntry = sChrClassesStore.LookupEntry(m_session->GetPlayer()->getClass());
1604 if(!clsEntry)
1605 return true;
1606 uint32 family = clsEntry->spellfamily;
1608 for (uint32 i = 0; i < sSpellStore.GetNumRows(); i++)
1610 SpellEntry const *spellInfo = sSpellStore.LookupEntry(i);
1611 if(!spellInfo)
1612 continue;
1614 // skip wrong class/race skills
1615 if(!m_session->GetPlayer()->IsSpellFitByClassAndRace(spellInfo->Id))
1616 continue;
1618 // skip other spell families
1619 if( spellInfo->SpellFamilyName != family)
1620 continue;
1622 //TODO: skip triggered spells
1624 // skip spells with first rank learned as talent (and all talents then also)
1625 uint32 first_rank = spellmgr.GetFirstSpellInChain(spellInfo->Id);
1626 if(GetTalentSpellCost(first_rank) > 0 )
1627 continue;
1629 // skip broken spells
1630 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
1631 continue;
1633 m_session->GetPlayer()->learnSpell(i);
1636 SendSysMessage(LANG_COMMAND_LEARN_CLASS_SPELLS);
1637 return true;
1640 static void learnAllHighRanks(Player* player, uint32 spellid)
1642 SpellChainMapNext const& nextMap = spellmgr.GetSpellChainNext();
1643 for(SpellChainMapNext::const_iterator itr = nextMap.lower_bound(spellid); itr != nextMap.upper_bound(spellid); ++itr)
1645 player->learnSpell(itr->second);
1646 learnAllHighRanks(player,itr->second);
1650 bool ChatHandler::HandleLearnAllMyTalentsCommand(const char* /*args*/)
1652 Player* player = m_session->GetPlayer();
1653 uint32 classMask = player->getClassMask();
1655 for (uint32 i = 0; i < sTalentStore.GetNumRows(); i++)
1657 TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
1658 if(!talentInfo)
1659 continue;
1661 TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentInfo->TalentTab );
1662 if(!talentTabInfo)
1663 continue;
1665 if( (classMask & talentTabInfo->ClassMask) == 0 )
1666 continue;
1668 // search highest talent rank
1669 uint32 spellid = 0;
1670 int rank = 4;
1671 for(; rank >= 0; --rank)
1673 if(talentInfo->RankID[rank]!=0)
1675 spellid = talentInfo->RankID[rank];
1676 break;
1680 if(!spellid) // ??? none spells in telent
1681 continue;
1683 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellid);
1684 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
1685 continue;
1687 // learn highest rank of talent
1688 player->learnSpell(spellid);
1690 // and learn all non-talent spell ranks (recursive by tree)
1691 learnAllHighRanks(player,spellid);
1694 SendSysMessage(LANG_COMMAND_LEARN_CLASS_TALENTS);
1695 return true;
1698 bool ChatHandler::HandleLearnAllLangCommand(const char* /*args*/)
1700 // skipping UNIVERSAL language (0)
1701 for(int i = 1; i < LANGUAGES_COUNT; ++i)
1702 m_session->GetPlayer()->learnSpell(lang_description[i].spell_id);
1704 SendSysMessage(LANG_COMMAND_LEARN_ALL_LANG);
1705 return true;
1708 bool ChatHandler::HandleLearnAllDefaultCommand(const char* args)
1710 char* pName = strtok((char*)args, "");
1711 Player *player = NULL;
1712 if (pName)
1714 std::string name = pName;
1716 if(!normalizePlayerName(name))
1718 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1719 SetSentErrorMessage(true);
1720 return false;
1723 player = objmgr.GetPlayer(name.c_str());
1725 else
1726 player = getSelectedPlayer();
1728 if(!player)
1730 SendSysMessage(LANG_NO_CHAR_SELECTED);
1731 SetSentErrorMessage(true);
1732 return false;
1735 player->learnDefaultSpells();
1736 player->learnQuestRewardedSpells();
1738 PSendSysMessage(LANG_COMMAND_LEARN_ALL_DEFAULT_AND_QUEST,player->GetName());
1739 return true;
1742 bool ChatHandler::HandleLearnCommand(const char* args)
1744 Player* targetPlayer = getSelectedPlayer();
1746 if(!targetPlayer)
1748 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1749 SetSentErrorMessage(true);
1750 return false;
1753 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1754 uint32 spell = extractSpellIdFromLink((char*)args);
1755 if(!spell || !sSpellStore.LookupEntry(spell))
1756 return false;
1758 if (targetPlayer->HasSpell(spell))
1760 if(targetPlayer == m_session->GetPlayer())
1761 SendSysMessage(LANG_YOU_KNOWN_SPELL);
1762 else
1763 PSendSysMessage(LANG_TARGET_KNOWN_SPELL,targetPlayer->GetName());
1764 SetSentErrorMessage(true);
1765 return false;
1768 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
1769 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
1771 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
1772 SetSentErrorMessage(true);
1773 return false;
1776 targetPlayer->learnSpell(spell);
1778 return true;
1781 bool ChatHandler::HandleAddItemCommand(const char* args)
1783 if (!*args)
1784 return false;
1786 uint32 itemId = 0;
1788 if(args[0]=='[') // [name] manual form
1790 char* citemName = citemName = strtok((char*)args, "]");
1792 if(citemName && citemName[0])
1794 std::string itemName = citemName+1;
1795 WorldDatabase.escape_string(itemName);
1796 QueryResult *result = WorldDatabase.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName.c_str());
1797 if (!result)
1799 PSendSysMessage(LANG_COMMAND_COULDNOTFIND, citemName+1);
1800 SetSentErrorMessage(true);
1801 return false;
1803 itemId = result->Fetch()->GetUInt16();
1804 delete result;
1806 else
1807 return false;
1809 else // item_id or [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r
1811 char* cId = extractKeyFromLink((char*)args,"Hitem");
1812 if(!cId)
1813 return false;
1814 itemId = atol(cId);
1817 char* ccount = strtok(NULL, " ");
1819 int32 count = 1;
1821 if (ccount)
1822 count = strtol(ccount, NULL, 10);
1824 if (count == 0)
1825 count = 1;
1827 Player* pl = m_session->GetPlayer();
1828 Player* plTarget = getSelectedPlayer();
1829 if(!plTarget)
1830 plTarget = pl;
1832 sLog.outDetail(GetMangosString(LANG_ADDITEM), itemId, count);
1834 ItemPrototype const *pProto = objmgr.GetItemPrototype(itemId);
1835 if(!pProto)
1837 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, itemId);
1838 SetSentErrorMessage(true);
1839 return false;
1842 //Subtract
1843 if (count < 0)
1845 plTarget->DestroyItemCount(itemId, -count, true, false);
1846 PSendSysMessage(LANG_REMOVEITEM, itemId, -count, plTarget->GetName());
1847 return true;
1850 //Adding items
1851 uint32 noSpaceForCount = 0;
1853 // check space and find places
1854 ItemPosCountVec dest;
1855 uint8 msg = plTarget->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, itemId, count, &noSpaceForCount );
1856 if( msg != EQUIP_ERR_OK ) // convert to possible store amount
1857 count -= noSpaceForCount;
1859 if( count == 0 || dest.empty()) // can't add any
1861 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount );
1862 SetSentErrorMessage(true);
1863 return false;
1866 Item* item = plTarget->StoreNewItem( dest, itemId, true, Item::GenerateItemRandomPropertyId(itemId));
1868 // remove binding (let GM give it to another player later)
1869 if(pl==plTarget)
1870 for(ItemPosCountVec::const_iterator itr = dest.begin(); itr != dest.end(); ++itr)
1871 if(Item* item1 = pl->GetItemByPos(itr->pos))
1872 item1->SetBinding( false );
1874 if(count > 0 && item)
1876 pl->SendNewItem(item,count,false,true);
1877 if(pl!=plTarget)
1878 plTarget->SendNewItem(item,count,true,false);
1881 if(noSpaceForCount > 0)
1882 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount);
1884 return true;
1887 bool ChatHandler::HandleAddItemSetCommand(const char* args)
1889 if (!*args)
1890 return false;
1892 char* cId = extractKeyFromLink((char*)args,"Hitemset"); // number or [name] Shift-click form |color|Hitemset:itemset_id|h[name]|h|r
1893 if (!cId)
1894 return false;
1896 uint32 itemsetId = atol(cId);
1898 // prevent generation all items with itemset field value '0'
1899 if (itemsetId == 0)
1901 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND,itemsetId);
1902 SetSentErrorMessage(true);
1903 return false;
1906 Player* pl = m_session->GetPlayer();
1907 Player* plTarget = getSelectedPlayer();
1908 if(!plTarget)
1909 plTarget = pl;
1911 sLog.outDetail(GetMangosString(LANG_ADDITEMSET), itemsetId);
1913 QueryResult *result = WorldDatabase.PQuery("SELECT entry FROM item_template WHERE itemset = %u",itemsetId);
1915 if(!result)
1917 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND,itemsetId);
1919 SetSentErrorMessage(true);
1920 return false;
1925 Field *fields = result->Fetch();
1926 uint32 itemId = fields[0].GetUInt32();
1928 ItemPosCountVec dest;
1929 uint8 msg = plTarget->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, itemId, 1 );
1930 if( msg == EQUIP_ERR_OK )
1932 Item* item = plTarget->StoreNewItem( dest, itemId, true);
1934 // remove binding (let GM give it to another player later)
1935 if(pl==plTarget)
1936 item->SetBinding( false );
1938 pl->SendNewItem(item,1,false,true);
1939 if(pl!=plTarget)
1940 plTarget->SendNewItem(item,1,true,false);
1942 else
1944 pl->SendEquipError( msg, NULL, NULL );
1945 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, 1);
1948 }while( result->NextRow() );
1950 delete result;
1952 return true;
1955 bool ChatHandler::HandleListItemCommand(const char* args)
1957 if(!*args)
1958 return false;
1960 char* cId = extractKeyFromLink((char*)args,"Hitem");
1961 if(!cId)
1962 return false;
1963 uint32 item_id = atol(cId);
1965 ItemPrototype const* itemProto = item_id ? itemProto = objmgr.GetItemPrototype(item_id) : NULL;
1967 if(!itemProto)
1969 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
1970 SetSentErrorMessage(true);
1971 return false;
1974 char* c_count = strtok(NULL, " ");
1975 int count = c_count ? atol(c_count) : 10;
1977 if(count < 0)
1978 return false;
1980 QueryResult *result;
1982 // inventory case
1983 uint32 inv_count = 0;
1984 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM character_inventory WHERE item_template='%u'",item_id);
1985 if(result)
1987 inv_count = (*result)[0].GetUInt32();
1988 delete result;
1991 result=CharacterDatabase.PQuery(
1992 // 0 1 2 3 4 5
1993 "SELECT ci.item, cibag.slot AS bag, ci.slot, ci.guid, characters.account,characters.name "
1994 "FROM character_inventory AS ci LEFT JOIN character_inventory AS cibag ON (cibag.item=ci.bag),characters "
1995 "WHERE ci.item_template='%u' AND ci.guid = characters.guid LIMIT %u ",
1996 item_id,uint32(count));
1998 if(result)
2002 Field *fields = result->Fetch();
2003 uint32 item_guid = fields[0].GetUInt32();
2004 uint32 item_bag = fields[1].GetUInt32();
2005 uint32 item_slot = fields[2].GetUInt32();
2006 uint32 owner_guid = fields[3].GetUInt32();
2007 uint32 owner_acc = fields[4].GetUInt32();
2008 std::string owner_name = fields[5].GetCppString();
2010 char const* item_pos = 0;
2011 if(Player::IsEquipmentPos(item_bag,item_slot))
2012 item_pos = "[equipped]";
2013 else if(Player::IsInventoryPos(item_bag,item_slot))
2014 item_pos = "[in inventory]";
2015 else if(Player::IsBankPos(item_bag,item_slot))
2016 item_pos = "[in bank]";
2017 else
2018 item_pos = "";
2020 PSendSysMessage(LANG_ITEMLIST_SLOT,
2021 item_guid,owner_name.c_str(),owner_guid,owner_acc,item_pos);
2022 } while (result->NextRow());
2024 int64 res_count = result->GetRowCount();
2026 delete result;
2028 if(count > res_count)
2029 count-=res_count;
2030 else if(count)
2031 count = 0;
2034 // mail case
2035 uint32 mail_count = 0;
2036 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM mail_items WHERE item_template='%u'", item_id);
2037 if(result)
2039 mail_count = (*result)[0].GetUInt32();
2040 delete result;
2043 if(count > 0)
2045 result=CharacterDatabase.PQuery(
2046 // 0 1 2 3 4 5 6
2047 "SELECT mail_items.item_guid, mail.sender, mail.receiver, char_s.account, char_s.name, char_r.account, char_r.name "
2048 "FROM mail,mail_items,characters as char_s,characters as char_r "
2049 "WHERE mail_items.item_template='%u' AND char_s.guid = mail.sender AND char_r.guid = mail.receiver AND mail.id=mail_items.mail_id LIMIT %u",
2050 item_id,uint32(count));
2052 else
2053 result = NULL;
2055 if(result)
2059 Field *fields = result->Fetch();
2060 uint32 item_guid = fields[0].GetUInt32();
2061 uint32 item_s = fields[1].GetUInt32();
2062 uint32 item_r = fields[2].GetUInt32();
2063 uint32 item_s_acc = fields[3].GetUInt32();
2064 std::string item_s_name = fields[4].GetCppString();
2065 uint32 item_r_acc = fields[5].GetUInt32();
2066 std::string item_r_name = fields[6].GetCppString();
2068 char const* item_pos = "[in mail]";
2070 PSendSysMessage(LANG_ITEMLIST_MAIL,
2071 item_guid,item_s_name.c_str(),item_s,item_s_acc,item_r_name.c_str(),item_r,item_r_acc,item_pos);
2072 } while (result->NextRow());
2074 int64 res_count = result->GetRowCount();
2076 delete result;
2078 if(count > res_count)
2079 count-=res_count;
2080 else if(count)
2081 count = 0;
2084 // auction case
2085 uint32 auc_count = 0;
2086 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM auctionhouse WHERE item_template='%u'",item_id);
2087 if(result)
2089 auc_count = (*result)[0].GetUInt32();
2090 delete result;
2093 if(count > 0)
2095 result=CharacterDatabase.PQuery(
2096 // 0 1 2 3
2097 "SELECT auctionhouse.itemguid, auctionhouse.itemowner, characters.account, characters.name "
2098 "FROM auctionhouse,characters WHERE auctionhouse.item_template='%u' AND characters.guid = auctionhouse.itemowner LIMIT %u",
2099 item_id,uint32(count));
2101 else
2102 result = NULL;
2104 if(result)
2108 Field *fields = result->Fetch();
2109 uint32 item_guid = fields[0].GetUInt32();
2110 uint32 owner = fields[1].GetUInt32();
2111 uint32 owner_acc = fields[2].GetUInt32();
2112 std::string owner_name = fields[3].GetCppString();
2114 char const* item_pos = "[in auction]";
2116 PSendSysMessage(LANG_ITEMLIST_AUCTION, item_guid, owner_name.c_str(), owner, owner_acc,item_pos);
2117 } while (result->NextRow());
2119 delete result;
2122 if(inv_count+mail_count+auc_count == 0)
2124 SendSysMessage(LANG_COMMAND_NOITEMFOUND);
2125 SetSentErrorMessage(true);
2126 return false;
2129 PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE,item_id,inv_count+mail_count+auc_count,inv_count,mail_count,auc_count);
2131 return true;
2134 bool ChatHandler::HandleListObjectCommand(const char* args)
2136 if(!*args)
2137 return false;
2139 // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2140 char* cId = extractKeyFromLink((char*)args,"Hgameobject_entry");
2141 if(!cId)
2142 return false;
2144 uint32 go_id = atol(cId);
2146 GameObjectInfo const * gInfo = objmgr.GetGameObjectInfo(go_id);
2148 if(!go_id || !gInfo)
2150 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, go_id);
2151 SetSentErrorMessage(true);
2152 return false;
2155 char* c_count = strtok(NULL, " ");
2156 int count = c_count ? atol(c_count) : 10;
2158 if(count < 0)
2159 return false;
2161 Player* pl = m_session->GetPlayer();
2162 QueryResult *result;
2164 uint32 obj_count = 0;
2165 result=WorldDatabase.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'",go_id);
2166 if(result)
2168 obj_count = (*result)[0].GetUInt32();
2169 delete result;
2172 result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map, (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ FROM gameobject WHERE id = '%u' ORDER BY order_ ASC LIMIT %u",
2173 pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(),go_id,uint32(count));
2175 if (result)
2179 Field *fields = result->Fetch();
2180 uint32 guid = fields[0].GetUInt32();
2181 float x = fields[1].GetFloat();
2182 float y = fields[2].GetFloat();
2183 float z = fields[3].GetFloat();
2184 int mapid = fields[4].GetUInt16();
2186 PSendSysMessage(LANG_GO_LIST, guid, guid, gInfo->name, x, y, z, mapid);
2187 } while (result->NextRow());
2189 delete result;
2192 PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE,go_id,obj_count);
2193 return true;
2196 bool ChatHandler::HandleNearObjectCommand(const char* args)
2198 float distance = (!*args) ? 10 : atol(args);
2199 uint32 count = 0;
2201 Player* pl = m_session->GetPlayer();
2202 QueryResult *result = WorldDatabase.PQuery("SELECT guid, id, position_x, position_y, position_z, map, "
2203 "(POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ "
2204 "FROM gameobject WHERE map='%u' AND (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) <= '%f' ORDER BY order_",
2205 pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(),
2206 pl->GetMapId(),pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(),distance*distance);
2208 if (result)
2212 Field *fields = result->Fetch();
2213 uint32 guid = fields[0].GetUInt32();
2214 uint32 entry = fields[1].GetUInt32();
2215 float x = fields[2].GetFloat();
2216 float y = fields[3].GetFloat();
2217 float z = fields[4].GetFloat();
2218 int mapid = fields[5].GetUInt16();
2220 GameObjectInfo const * gInfo = objmgr.GetGameObjectInfo(entry);
2222 if(!gInfo)
2223 continue;
2225 PSendSysMessage(LANG_GO_LIST, guid, guid, gInfo->name, x, y, z, mapid);
2227 ++count;
2228 } while (result->NextRow());
2230 delete result;
2233 PSendSysMessage(LANG_COMMAND_NEAROBJMESSAGE,distance,count);
2234 return true;
2237 bool ChatHandler::HandleListCreatureCommand(const char* args)
2239 if(!*args)
2240 return false;
2242 // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
2243 char* cId = extractKeyFromLink((char*)args,"Hcreature_entry");
2244 if(!cId)
2245 return false;
2247 uint32 cr_id = atol(cId);
2249 CreatureInfo const* cInfo = objmgr.GetCreatureTemplate(cr_id);
2251 if(!cr_id || !cInfo)
2253 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, cr_id);
2254 SetSentErrorMessage(true);
2255 return false;
2258 char* c_count = strtok(NULL, " ");
2259 int count = c_count ? atol(c_count) : 10;
2261 if(count < 0)
2262 return false;
2264 Player* pl = m_session->GetPlayer();
2265 QueryResult *result;
2267 uint32 cr_count = 0;
2268 result=WorldDatabase.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'",cr_id);
2269 if(result)
2271 cr_count = (*result)[0].GetUInt32();
2272 delete result;
2275 result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map, (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ FROM creature WHERE id = '%u' ORDER BY order_ ASC LIMIT %u",
2276 pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(), cr_id,uint32(count));
2278 if (result)
2282 Field *fields = result->Fetch();
2283 uint32 guid = fields[0].GetUInt32();
2284 float x = fields[1].GetFloat();
2285 float y = fields[2].GetFloat();
2286 float z = fields[3].GetFloat();
2287 int mapid = fields[4].GetUInt16();
2289 PSendSysMessage(LANG_CREATURE_LIST, guid, guid, cInfo->Name, x, y, z, mapid);
2290 } while (result->NextRow());
2292 delete result;
2295 PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE,cr_id,cr_count);
2296 return true;
2299 bool ChatHandler::HandleLookupItemCommand(const char* args)
2301 if(!*args)
2302 return false;
2304 std::string namepart = args;
2305 std::wstring wnamepart;
2307 // converting string that we try to find to lower case
2308 if(!Utf8toWStr(namepart,wnamepart))
2309 return false;
2311 wstrToLower(wnamepart);
2313 uint32 counter = 0;
2315 // Search in `item_template`
2316 for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
2318 ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype >(id);
2319 if(!pProto)
2320 continue;
2322 int loc_idx = m_session->GetSessionDbLocaleIndex();
2323 if ( loc_idx >= 0 )
2325 ItemLocale const *il = objmgr.GetItemLocale(pProto->ItemId);
2326 if (il)
2328 if (il->Name.size() > loc_idx && !il->Name[loc_idx].empty())
2330 std::string name = il->Name[loc_idx];
2332 if (Utf8FitTo(name, wnamepart))
2334 PSendSysMessage(LANG_ITEM_LIST, id, id, name.c_str());
2335 ++counter;
2336 continue;
2342 std::string name = pProto->Name1;
2343 if(name.empty())
2344 continue;
2346 if (Utf8FitTo(name, wnamepart))
2348 PSendSysMessage(LANG_ITEM_LIST, id, id, name.c_str());
2349 ++counter;
2353 if (counter==0)
2354 SendSysMessage(LANG_COMMAND_NOITEMFOUND);
2356 return true;
2359 bool ChatHandler::HandleLookupItemSetCommand(const char* args)
2361 if(!*args)
2362 return false;
2364 std::string namepart = args;
2365 std::wstring wnamepart;
2367 if(!Utf8toWStr(namepart,wnamepart))
2368 return false;
2370 // converting string that we try to find to lower case
2371 wstrToLower( wnamepart );
2373 uint32 counter = 0; // Counter for figure out that we found smth.
2375 // Search in ItemSet.dbc
2376 for (uint32 id = 0; id < sItemSetStore.GetNumRows(); id++)
2378 ItemSetEntry const *set = sItemSetStore.LookupEntry(id);
2379 if(set)
2381 int loc = m_session->GetSessionDbcLocale();
2382 std::string name = set->name[m_session->GetSessionDbcLocale()];
2383 if(name.empty())
2384 continue;
2386 if (!Utf8FitTo(name, wnamepart))
2388 loc = 0;
2389 for(; loc < MAX_LOCALE; ++loc)
2391 if(loc==m_session->GetSessionDbcLocale())
2392 continue;
2394 name = set->name[m_session->GetSessionDbcLocale()];
2395 if(name.empty())
2396 continue;
2398 if (Utf8FitTo(name, wnamepart))
2399 break;
2403 if(loc < MAX_LOCALE)
2405 // send item set in "id - [namedlink locale]" format
2406 PSendSysMessage(LANG_ITEMSET_LIST,id,id,name.c_str(),localeNames[loc]);
2407 ++counter;
2411 if (counter == 0) // if counter == 0 then we found nth
2412 SendSysMessage(LANG_COMMAND_NOITEMSETFOUND);
2413 return true;
2416 bool ChatHandler::HandleLookupSkillCommand(const char* args)
2418 Player* target = getSelectedPlayer();
2419 if(!target)
2421 SendSysMessage(LANG_PLAYER_NOT_FOUND);
2422 SetSentErrorMessage(true);
2423 return false;
2426 if(!*args)
2427 return false;
2429 std::string namepart = args;
2430 std::wstring wnamepart;
2432 if(!Utf8toWStr(namepart,wnamepart))
2433 return false;
2435 // converting string that we try to find to lower case
2436 wstrToLower( wnamepart );
2438 uint32 counter = 0; // Counter for figure out that we found smth.
2440 // Search in SkillLine.dbc
2441 for (uint32 id = 0; id < sSkillLineStore.GetNumRows(); id++)
2443 SkillLineEntry const *skillInfo = sSkillLineStore.LookupEntry(id);
2444 if(skillInfo)
2446 int loc = m_session->GetSessionDbcLocale();
2447 std::string name = skillInfo->name[loc];
2448 if(name.empty())
2449 continue;
2451 if (!Utf8FitTo(name, wnamepart))
2453 loc = 0;
2454 for(; loc < MAX_LOCALE; ++loc)
2456 if(loc==m_session->GetSessionDbcLocale())
2457 continue;
2459 name = skillInfo->name[loc];
2460 if(name.empty())
2461 continue;
2463 if (Utf8FitTo(name, wnamepart))
2464 break;
2468 if(loc < MAX_LOCALE)
2470 // send skill in "id - [namedlink locale]" format
2471 PSendSysMessage(LANG_SKILL_LIST,id,id,name.c_str(),localeNames[loc],(target->HasSkill(id) ? m_session->GetMangosString(LANG_KNOWN) : ""));
2473 ++counter;
2477 if (counter == 0) // if counter == 0 then we found nth
2478 SendSysMessage(LANG_COMMAND_NOSKILLFOUND);
2479 return true;
2482 bool ChatHandler::HandleLookupSpellCommand(const char* args)
2484 Player* target = getSelectedPlayer();
2485 if( !target )
2487 SendSysMessage(LANG_PLAYER_NOT_FOUND);
2488 SetSentErrorMessage(true);
2489 return false;
2492 if(!*args)
2493 return false;
2495 std::string namepart = args;
2496 std::wstring wnamepart;
2498 if(!Utf8toWStr(namepart,wnamepart))
2499 return false;
2501 // converting string that we try to find to lower case
2502 wstrToLower( wnamepart );
2504 uint32 counter = 0; // Counter for figure out that we found smth.
2506 // Search in Spell.dbc
2507 for (uint32 id = 0; id < sSpellStore.GetNumRows(); id++)
2509 SpellEntry const *spellInfo = sSpellStore.LookupEntry(id);
2510 if(spellInfo)
2512 int loc = m_session->GetSessionDbcLocale();
2513 std::string name = spellInfo->SpellName[loc];
2514 if(name.empty())
2515 continue;
2517 if (!Utf8FitTo(name, wnamepart))
2519 loc = 0;
2520 for(; loc < MAX_LOCALE; ++loc)
2522 if(loc==m_session->GetSessionDbcLocale())
2523 continue;
2525 name = spellInfo->SpellName[loc];
2526 if(name.empty())
2527 continue;
2529 if (Utf8FitTo(name, wnamepart))
2530 break;
2534 if(loc < MAX_LOCALE)
2536 bool known = target->HasSpell(id);
2537 bool learn = (spellInfo->Effect[0] == SPELL_EFFECT_LEARN_SPELL);
2539 uint32 telentCost = GetTalentSpellCost(id);
2541 bool talent = (telentCost > 0);
2542 bool passive = IsPassiveSpell(id);
2543 bool active = target->HasAura(id,0) || target->HasAura(id,1) || target->HasAura(id,2);
2545 // unit32 used to prevent interpreting uint8 as char at output
2546 // find rank of learned spell for learning spell, or talent rank
2547 uint32 rank = telentCost ? telentCost : spellmgr.GetSpellRank(learn ? spellInfo->EffectTriggerSpell[0] : id);
2549 // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
2550 std::ostringstream ss;
2551 ss << id << " - |cffffffff|Hspell:" << id << "|h[" << name;
2553 // include rank in link name
2554 if(rank)
2555 ss << GetMangosString(LANG_SPELL_RANK) << rank;
2557 ss << " " << localeNames[loc] << "]|h|r";
2559 if(talent)
2560 ss << GetMangosString(LANG_TALENT);
2561 if(passive)
2562 ss << GetMangosString(LANG_PASSIVE);
2563 if(learn)
2564 ss << GetMangosString(LANG_LEARN);
2565 if(known)
2566 ss << GetMangosString(LANG_KNOWN);
2567 if(active)
2568 ss << GetMangosString(LANG_ACTIVE);
2570 SendSysMessage(ss.str().c_str());
2572 ++counter;
2576 if (counter == 0) // if counter == 0 then we found nth
2577 SendSysMessage(LANG_COMMAND_NOSPELLFOUND);
2578 return true;
2581 bool ChatHandler::HandleLookupQuestCommand(const char* args)
2583 Player* target = getSelectedPlayer();
2584 if( !target )
2586 SendSysMessage(LANG_PLAYER_NOT_FOUND);
2587 SetSentErrorMessage(true);
2588 return false;
2591 if(!*args)
2592 return false;
2594 std::string namepart = args;
2595 std::wstring wnamepart;
2597 // converting string that we try to find to lower case
2598 if(!Utf8toWStr(namepart,wnamepart))
2599 return false;
2601 wstrToLower(wnamepart);
2603 uint32 counter = 0 ;
2605 ObjectMgr::QuestMap const& qTemplates = objmgr.GetQuestTemplates();
2606 for (ObjectMgr::QuestMap::const_iterator iter = qTemplates.begin(); iter != qTemplates.end(); ++iter)
2608 Quest * qinfo = iter->second;
2610 int loc_idx = m_session->GetSessionDbLocaleIndex();
2611 if ( loc_idx >= 0 )
2613 QuestLocale const *il = objmgr.GetQuestLocale(qinfo->GetQuestId());
2614 if (il)
2616 if (il->Title.size() > loc_idx && !il->Title[loc_idx].empty())
2618 std::string title = il->Title[loc_idx];
2620 if (Utf8FitTo(title, wnamepart))
2622 QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId());
2624 char const* statusStr = "";
2625 if(status == QUEST_STATUS_COMPLETE)
2627 if(target->GetQuestRewardStatus(qinfo->GetQuestId()))
2628 statusStr = GetMangosString(LANG_COMMAND_QUEST_REWARDED);
2629 else
2630 statusStr = GetMangosString(LANG_COMMAND_QUEST_COMPLETE);
2632 else if(status == QUEST_STATUS_INCOMPLETE)
2633 statusStr = GetMangosString(LANG_COMMAND_QUEST_ACTIVE);
2635 PSendSysMessage(LANG_QUEST_LIST,qinfo->GetQuestId(),qinfo->GetQuestId(),title.c_str(),(status == QUEST_STATUS_COMPLETE ? GetMangosString(LANG_COMPLETE) : (status == QUEST_STATUS_INCOMPLETE ? GetMangosString(LANG_ACTIVE) : "") ));
2636 ++counter;
2637 continue;
2643 std::string title = qinfo->GetTitle();
2644 if(title.empty())
2645 continue;
2647 if (Utf8FitTo(title, wnamepart))
2649 QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId());
2651 char const* statusStr = "";
2652 if(status == QUEST_STATUS_COMPLETE)
2654 if(target->GetQuestRewardStatus(qinfo->GetQuestId()))
2655 statusStr = GetMangosString(LANG_COMMAND_QUEST_REWARDED);
2656 else
2657 statusStr = GetMangosString(LANG_COMMAND_QUEST_COMPLETE);
2659 else if(status == QUEST_STATUS_INCOMPLETE)
2660 statusStr = GetMangosString(LANG_COMMAND_QUEST_ACTIVE);
2662 PSendSysMessage(LANG_QUEST_LIST,qinfo->GetQuestId(),qinfo->GetQuestId(), title.c_str(),(status == QUEST_STATUS_COMPLETE ? GetMangosString(LANG_COMPLETE) : (status == QUEST_STATUS_INCOMPLETE ? GetMangosString(LANG_ACTIVE) : "") ));
2663 ++counter;
2667 if (counter==0)
2668 SendSysMessage(LANG_COMMAND_NOQUESTFOUND);
2670 return true;
2673 bool ChatHandler::HandleLookupCreatureCommand(const char* args)
2675 if(!*args)
2676 return false;
2678 std::string namepart = args;
2679 std::wstring wnamepart;
2681 // converting string that we try to find to lower case
2682 if(!Utf8toWStr(namepart,wnamepart))
2683 return false;
2685 wstrToLower(wnamepart);
2687 uint32 counter = 0;
2689 for (uint32 id = 0; id< sCreatureStorage.MaxEntry; id++ )
2691 CreatureInfo const* cInfo = sCreatureStorage.LookupEntry<CreatureInfo>(id);
2692 if(!cInfo)
2693 continue;
2695 int loc_idx = m_session->GetSessionDbLocaleIndex();
2696 if ( loc_idx >= 0 )
2698 CreatureLocale const *cl = objmgr.GetCreatureLocale(id);
2699 if (cl)
2701 if (cl->Name.size() > loc_idx && !cl->Name[loc_idx].empty())
2703 std::string name = cl->Name[loc_idx];
2705 if (Utf8FitTo(name, wnamepart))
2707 PSendSysMessage(LANG_CREATURE_ENTRY_LIST, id, id, name.c_str());
2708 ++counter;
2709 continue;
2715 std::string name = cInfo->Name;
2716 if(name.empty())
2717 continue;
2719 if (Utf8FitTo(name, wnamepart))
2721 PSendSysMessage(LANG_CREATURE_ENTRY_LIST,id,id,name.c_str());
2722 ++counter;
2726 if (counter==0)
2727 SendSysMessage(LANG_COMMAND_NOCREATUREFOUND);
2729 return true;
2732 bool ChatHandler::HandleLookupObjectCommand(const char* args)
2734 if(!*args)
2735 return false;
2737 std::string namepart = args;
2738 std::wstring wnamepart;
2740 // converting string that we try to find to lower case
2741 if(!Utf8toWStr(namepart,wnamepart))
2742 return false;
2744 wstrToLower(wnamepart);
2746 uint32 counter = 0;
2748 for (uint32 id = 0; id< sGOStorage.MaxEntry; id++ )
2750 GameObjectInfo const* gInfo = sGOStorage.LookupEntry<GameObjectInfo>(id);
2751 if(!gInfo)
2752 continue;
2754 int loc_idx = m_session->GetSessionDbLocaleIndex();
2755 if ( loc_idx >= 0 )
2757 GameObjectLocale const *gl = objmgr.GetGameObjectLocale(id);
2758 if (gl)
2760 if (gl->Name.size() > loc_idx && !gl->Name[loc_idx].empty())
2762 std::string name = gl->Name[loc_idx];
2764 if (Utf8FitTo(name, wnamepart))
2766 PSendSysMessage(LANG_GO_ENTRY_LIST, id, id, name.c_str());
2767 ++counter;
2768 continue;
2774 std::string name = gInfo->name;
2775 if(name.empty())
2776 continue;
2778 if(Utf8FitTo(name, wnamepart))
2780 PSendSysMessage(LANG_GO_ENTRY_LIST, id, id, name.c_str());
2781 ++counter;
2785 if(counter==0)
2786 SendSysMessage(LANG_COMMAND_NOGAMEOBJECTFOUND);
2788 return true;
2791 /** \brief GM command level 3 - Create a guild.
2793 * This command allows a GM (level 3) to create a guild.
2795 * The "args" parameter contains the name of the guild leader
2796 * and then the name of the guild.
2799 bool ChatHandler::HandleGuildCreateCommand(const char* args)
2802 if (!*args)
2803 return false;
2805 Guild *guild;
2806 Player * player;
2807 char *lname,*gname;
2808 std::string guildname;
2810 lname = strtok((char*)args, " ");
2811 gname = strtok(NULL, "");
2813 if(!lname)
2814 return false;
2815 else if(!gname)
2817 SendSysMessage(LANG_INSERT_GUILD_NAME);
2818 SetSentErrorMessage(true);
2819 return false;
2822 guildname = gname;
2823 player = ObjectAccessor::Instance().FindPlayerByName(lname);
2825 if(!player)
2827 SendSysMessage(LANG_PLAYER_NOT_FOUND);
2828 SetSentErrorMessage(true);
2829 return false;
2832 if(!player->GetGuildId())
2834 guild = new Guild;
2835 if(!guild->create(player->GetGUID(),guildname))
2837 delete guild;
2838 SendSysMessage(LANG_GUILD_NOT_CREATED);
2839 SetSentErrorMessage(true);
2840 return false;
2843 objmgr.AddGuild(guild);
2845 else
2846 SendSysMessage(LANG_PLAYER_IN_GUILD);
2848 return true;
2851 bool ChatHandler::HandleGuildInviteCommand(const char *args)
2853 if(!*args)
2854 return false;
2856 char* par1 = strtok((char*)args, " ");
2857 char* par2 = strtok (NULL, "");
2858 if(!par1 || !par2)
2859 return false;
2861 std::string glName = par2;
2862 Guild* targetGuild = objmgr.GetGuildByName(glName);
2863 if(!targetGuild)
2864 return false;
2866 std::string plName = par1;
2867 if(!normalizePlayerName(plName))
2869 SendSysMessage(LANG_PLAYER_NOT_FOUND);
2870 SetSentErrorMessage(true);
2871 return false;
2874 uint64 plGuid = 0;
2875 if(Player* targetPlayer = ObjectAccessor::Instance().FindPlayerByName(plName.c_str()))
2876 plGuid = targetPlayer->GetGUID();
2877 else
2878 plGuid = objmgr.GetPlayerGUIDByName(plName.c_str());
2880 if(!plGuid)
2881 false;
2883 // players's guild membership checked in AddMember before add
2884 if(!targetGuild->AddMember(plGuid,targetGuild->GetLowestRank()))
2885 return false;
2887 return true;
2890 bool ChatHandler::HandleGuildUninviteCommand(const char *args)
2892 if(!*args)
2893 return false;
2895 char* par1 = strtok((char*)args, " ");
2896 if(!par1)
2897 return false;
2898 std::string plName = par1;
2899 if(!normalizePlayerName(plName))
2901 SendSysMessage(LANG_PLAYER_NOT_FOUND);
2902 SetSentErrorMessage(true);
2903 return false;
2906 uint64 plGuid = 0;
2907 uint32 glId = 0;
2908 if(Player* targetPlayer = ObjectAccessor::Instance().FindPlayerByName(plName.c_str()))
2910 plGuid = targetPlayer->GetGUID();
2911 glId = targetPlayer->GetGuildId();
2913 else
2915 plGuid = objmgr.GetPlayerGUIDByName(plName.c_str());
2916 glId = Player::GetGuildIdFromDB(plGuid);
2919 if(!plGuid || !glId)
2920 return false;
2922 Guild* targetGuild = objmgr.GetGuildById(glId);
2923 if(!targetGuild)
2924 return false;
2926 targetGuild->DelMember(plGuid);
2928 return true;
2931 bool ChatHandler::HandleGuildRankCommand(const char *args)
2933 if(!*args)
2934 return false;
2936 char* par1 = strtok((char*)args, " ");
2937 char* par2 = strtok(NULL, " ");
2938 if(!par1 || !par2)
2939 return false;
2940 std::string plName = par1;
2941 if(!normalizePlayerName(plName))
2943 SendSysMessage(LANG_PLAYER_NOT_FOUND);
2944 SetSentErrorMessage(true);
2945 return false;
2948 uint64 plGuid = 0;
2949 uint32 glId = 0;
2950 if(Player* targetPlayer = ObjectAccessor::Instance().FindPlayerByName(plName.c_str()))
2952 plGuid = targetPlayer->GetGUID();
2953 glId = targetPlayer->GetGuildId();
2955 else
2957 plGuid = objmgr.GetPlayerGUIDByName(plName.c_str());
2958 glId = Player::GetGuildIdFromDB(plGuid);
2961 if(!plGuid || !glId)
2962 return false;
2964 Guild* targetGuild = objmgr.GetGuildById(glId);
2965 if(!targetGuild)
2966 return false;
2968 uint32 newrank = uint32(atoi(par2));
2969 if(newrank > targetGuild->GetLowestRank())
2970 return false;
2972 targetGuild->ChangeRank(plGuid,newrank);
2974 return true;
2977 bool ChatHandler::HandleGuildDeleteCommand(const char* args)
2979 if(!*args)
2980 return false;
2982 char* par1 = strtok((char*)args, " ");
2983 if(!par1)
2984 return false;
2986 std::string gld = par1;
2988 Guild* targetGuild = objmgr.GetGuildByName(gld);
2989 if(!targetGuild)
2990 return false;
2992 targetGuild->Disband();
2994 return true;
2997 bool ChatHandler::HandleGetDistanceCommand(const char* /*args*/)
2999 Unit* pUnit = getSelectedUnit();
3001 if(!pUnit)
3003 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3004 SetSentErrorMessage(true);
3005 return false;
3008 PSendSysMessage(LANG_DISTANCE, m_session->GetPlayer()->GetDistance(pUnit),m_session->GetPlayer()->GetDistance2d(pUnit));
3010 return true;
3013 // FIX-ME!!!
3015 bool ChatHandler::HandleAddWeaponCommand(const char* /*args*/)
3017 /*if (!*args)
3018 return false;
3020 uint64 guid = m_session->GetPlayer()->GetSelection();
3021 if (guid == 0)
3023 SendSysMessage(LANG_NO_SELECTION);
3024 return true;
3027 Creature *pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
3029 if(!pCreature)
3031 SendSysMessage(LANG_SELECT_CREATURE);
3032 return true;
3035 char* pSlotID = strtok((char*)args, " ");
3036 if (!pSlotID)
3037 return false;
3039 char* pItemID = strtok(NULL, " ");
3040 if (!pItemID)
3041 return false;
3043 uint32 ItemID = atoi(pItemID);
3044 uint32 SlotID = atoi(pSlotID);
3046 ItemPrototype* tmpItem = objmgr.GetItemPrototype(ItemID);
3048 bool added = false;
3049 if(tmpItem)
3051 switch(SlotID)
3053 case 1:
3054 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID);
3055 added = true;
3056 break;
3057 case 2:
3058 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID);
3059 added = true;
3060 break;
3061 case 3:
3062 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID);
3063 added = true;
3064 break;
3065 default:
3066 PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST,SlotID);
3067 added = false;
3068 break;
3070 if(added)
3072 PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT,ItemID,tmpItem->Name1,SlotID);
3075 else
3077 PSendSysMessage(LANG_ITEM_NOT_FOUND,ItemID);
3078 return true;
3081 return true;
3084 bool ChatHandler::HandleDieCommand(const char* /*args*/)
3086 Unit* target = getSelectedUnit();
3088 if(!target || !m_session->GetPlayer()->GetSelection())
3090 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3091 SetSentErrorMessage(true);
3092 return false;
3095 if( target->isAlive() )
3097 m_session->GetPlayer()->DealDamage(target, target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
3100 return true;
3103 bool ChatHandler::HandleDamageCommand(const char * args)
3105 if (!*args)
3106 return false;
3108 Unit* target = getSelectedUnit();
3110 if(!target || !m_session->GetPlayer()->GetSelection())
3112 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3113 SetSentErrorMessage(true);
3114 return false;
3117 if( !target->isAlive() )
3118 return true;
3120 char* damageStr = strtok((char*)args, " ");
3121 if(!damageStr)
3122 return false;
3124 int32 damage = atoi((char*)damageStr);
3125 if(damage <=0)
3126 return true;
3128 char* schoolStr = strtok((char*)NULL, " ");
3130 // flat melee damage without resistence/etc reduction
3131 if(!schoolStr)
3133 m_session->GetPlayer()->DealDamage(target, damage, NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
3134 m_session->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2, target, 1, SPELL_SCHOOL_MASK_NORMAL, damage, 0, 0, VICTIMSTATE_NORMAL, 0);
3135 return true;
3138 uint32 school = schoolStr ? atoi((char*)schoolStr) : SPELL_SCHOOL_NORMAL;
3139 if(school >= MAX_SPELL_SCHOOL)
3140 return false;
3142 SpellSchoolMask schoolmask = SpellSchoolMask(1 << school);
3144 if ( schoolmask & SPELL_SCHOOL_MASK_NORMAL )
3145 damage = m_session->GetPlayer()->CalcArmorReducedDamage(target, damage);
3147 char* spellStr = strtok((char*)NULL, " ");
3149 // melee damage by specific school
3150 if(!spellStr)
3152 uint32 absorb = 0;
3153 uint32 resist = 0;
3155 m_session->GetPlayer()->CalcAbsorbResist(target,schoolmask, SPELL_DIRECT_DAMAGE, damage, &absorb, &resist);
3157 if (damage <= absorb + resist)
3158 return true;
3160 damage -= absorb + resist;
3162 m_session->GetPlayer()->DealDamage(target, damage, NULL, DIRECT_DAMAGE, schoolmask, NULL, false);
3163 m_session->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2, target, 1, schoolmask, damage, absorb, resist, VICTIMSTATE_NORMAL, 0);
3164 return true;
3167 // non-melee damage
3169 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3170 uint32 spellid = extractSpellIdFromLink((char*)args);
3171 if(!spellid || !sSpellStore.LookupEntry(spellid))
3172 return false;
3174 m_session->GetPlayer()->SpellNonMeleeDamageLog(target, spellid, damage, false);
3175 return true;
3178 bool ChatHandler::HandleModifyArenaCommand(const char * args)
3180 if (!*args)
3181 return false;
3183 Player *target = getSelectedPlayer();
3184 if(!target)
3186 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3187 SetSentErrorMessage(true);
3188 return false;
3191 int32 amount = (uint32)atoi(args);
3193 target->ModifyArenaPoints(amount);
3195 PSendSysMessage(LANG_COMMAND_MODIFY_ARENA, target->GetName(), target->GetArenaPoints());
3197 return true;
3200 bool ChatHandler::HandleReviveCommand(const char* args)
3202 Player* SelectedPlayer = NULL;
3204 if (*args)
3206 std::string name = args;
3207 if(!normalizePlayerName(name))
3209 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3210 SetSentErrorMessage(true);
3211 return false;
3214 SelectedPlayer = objmgr.GetPlayer(name.c_str());
3216 else
3217 SelectedPlayer = getSelectedPlayer();
3219 if(!SelectedPlayer)
3221 SendSysMessage(LANG_NO_CHAR_SELECTED);
3222 SetSentErrorMessage(true);
3223 return false;
3226 SelectedPlayer->ResurrectPlayer(0.5f);
3227 SelectedPlayer->SpawnCorpseBones();
3228 SelectedPlayer->SaveToDB();
3229 return true;
3232 bool ChatHandler::HandleAuraCommand(const char* args)
3234 char* px = strtok((char*)args, " ");
3235 if (!px)
3236 return false;
3238 Unit *target = getSelectedUnit();
3239 if(!target)
3241 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3242 SetSentErrorMessage(true);
3243 return false;
3246 uint32 spellID = (uint32)atoi(px);
3247 SpellEntry const *spellInfo = sSpellStore.LookupEntry( spellID );
3248 if(spellInfo)
3250 for(uint32 i = 0;i<3;i++)
3252 uint8 eff = spellInfo->Effect[i];
3253 if (eff>=TOTAL_SPELL_EFFECTS)
3254 continue;
3255 if( IsAreaAuraEffect(eff) ||
3256 eff == SPELL_EFFECT_APPLY_AURA ||
3257 eff == SPELL_EFFECT_PERSISTENT_AREA_AURA )
3259 Aura *Aur = CreateAura(spellInfo, i, NULL, target);
3260 target->AddAura(Aur);
3265 return true;
3268 bool ChatHandler::HandleUnAuraCommand(const char* args)
3270 char* px = strtok((char*)args, " ");
3271 if (!px)
3272 return false;
3274 Unit *target = getSelectedUnit();
3275 if(!target)
3277 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3278 SetSentErrorMessage(true);
3279 return false;
3282 std::string argstr = args;
3283 if (argstr == "all")
3285 target->RemoveAllAuras();
3286 return true;
3289 uint32 spellID = (uint32)atoi(px);
3290 target->RemoveAurasDueToSpell(spellID);
3292 return true;
3295 bool ChatHandler::HandleLinkGraveCommand(const char* args)
3297 if(!*args)
3298 return false;
3300 char* px = strtok((char*)args, " ");
3301 if (!px)
3302 return false;
3304 uint32 g_id = (uint32)atoi(px);
3306 uint32 g_team;
3308 char* px2 = strtok(NULL, " ");
3310 if (!px2)
3311 g_team = 0;
3312 else if (strncmp(px2,"horde",6)==0)
3313 g_team = HORDE;
3314 else if (strncmp(px2,"alliance",9)==0)
3315 g_team = ALLIANCE;
3316 else
3317 return false;
3319 WorldSafeLocsEntry const* graveyard = sWorldSafeLocsStore.LookupEntry(g_id);
3321 if(!graveyard )
3323 PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST, g_id);
3324 SetSentErrorMessage(true);
3325 return false;
3328 Player* player = m_session->GetPlayer();
3330 uint32 zoneId = player->GetZoneId();
3332 AreaTableEntry const *areaEntry = GetAreaEntryByAreaID(zoneId);
3333 if(!areaEntry || areaEntry->zone !=0 )
3335 PSendSysMessage(LANG_COMMAND_GRAVEYARDWRONGZONE, g_id,zoneId);
3336 SetSentErrorMessage(true);
3337 return false;
3340 if(graveyard->map_id != areaEntry->mapid && g_team != 0)
3342 SendSysMessage(LANG_COMMAND_GRAVEYARDWRONGTEAM);
3343 SetSentErrorMessage(true);
3344 return false;
3347 if(objmgr.AddGraveYardLink(g_id,player->GetZoneId(),g_team))
3348 PSendSysMessage(LANG_COMMAND_GRAVEYARDLINKED, g_id,zoneId);
3349 else
3350 PSendSysMessage(LANG_COMMAND_GRAVEYARDALRLINKED, g_id,zoneId);
3352 return true;
3355 bool ChatHandler::HandleNearGraveCommand(const char* args)
3357 uint32 g_team;
3359 size_t argslen = strlen(args);
3361 if(!*args)
3362 g_team = 0;
3363 else if (strncmp((char*)args,"horde",argslen)==0)
3364 g_team = HORDE;
3365 else if (strncmp((char*)args,"alliance",argslen)==0)
3366 g_team = ALLIANCE;
3367 else
3368 return false;
3370 Player* player = m_session->GetPlayer();
3372 WorldSafeLocsEntry const* graveyard = objmgr.GetClosestGraveYard(
3373 player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(),player->GetMapId(),g_team);
3375 if(graveyard)
3377 uint32 g_id = graveyard->ID;
3379 GraveYardData const* data = objmgr.FindGraveYardData(g_id,player->GetZoneId());
3380 if (!data)
3382 PSendSysMessage(LANG_COMMAND_GRAVEYARDERROR,g_id);
3383 SetSentErrorMessage(true);
3384 return false;
3387 g_team = data->team;
3389 std::string team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_NOTEAM);
3391 if(g_team == 0)
3392 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ANY);
3393 else if(g_team == HORDE)
3394 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE);
3395 else if(g_team == ALLIANCE)
3396 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE);
3398 PSendSysMessage(LANG_COMMAND_GRAVEYARDNEAREST, g_id,team_name.c_str(),player->GetZoneId());
3400 else
3402 std::string team_name;
3404 if(g_team == 0)
3405 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ANY);
3406 else if(g_team == HORDE)
3407 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE);
3408 else if(g_team == ALLIANCE)
3409 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE);
3411 if(g_team == ~uint32(0))
3412 PSendSysMessage(LANG_COMMAND_ZONENOGRAVEYARDS, player->GetZoneId());
3413 else
3414 PSendSysMessage(LANG_COMMAND_ZONENOGRAFACTION, player->GetZoneId(),team_name.c_str());
3417 return true;
3420 bool ChatHandler::HandleSpawnTransportCommand(const char* /*args*/)
3422 return true;
3425 //play npc emote
3426 bool ChatHandler::HandlePlayEmoteCommand(const char* args)
3428 uint32 emote = atoi((char*)args);
3430 Creature* target = getSelectedCreature();
3431 if(!target)
3433 SendSysMessage(LANG_SELECT_CREATURE);
3434 SetSentErrorMessage(true);
3435 return false;
3438 target->SetUInt32Value(UNIT_NPC_EMOTESTATE,emote);
3440 return true;
3443 bool ChatHandler::HandleNpcInfoCommand(const char* /*args*/)
3445 Creature* target = getSelectedCreature();
3447 if(!target)
3449 SendSysMessage(LANG_SELECT_CREATURE);
3450 SetSentErrorMessage(true);
3451 return false;
3454 uint32 faction = target->getFaction();
3455 uint32 npcflags = target->GetUInt32Value(UNIT_NPC_FLAGS);
3456 uint32 displayid = target->GetDisplayId();
3457 uint32 nativeid = target->GetNativeDisplayId();
3458 uint32 Entry = target->GetEntry();
3459 CreatureInfo const* cInfo = target->GetCreatureInfo();
3461 int32 curRespawnDelay = target->GetRespawnTimeEx()-time(NULL);
3462 if(curRespawnDelay < 0)
3463 curRespawnDelay = 0;
3464 std::string curRespawnDelayStr = secsToTimeString(curRespawnDelay,true);
3465 std::string defRespawnDelayStr = secsToTimeString(target->GetRespawnDelay(),true);
3467 PSendSysMessage(LANG_NPCINFO_CHAR, target->GetDBTableGUIDLow(), faction, npcflags, Entry, displayid, nativeid);
3468 PSendSysMessage(LANG_NPCINFO_LEVEL, target->getLevel());
3469 PSendSysMessage(LANG_NPCINFO_HEALTH,target->GetCreateHealth(), target->GetMaxHealth(), target->GetHealth());
3470 PSendSysMessage(LANG_NPCINFO_FLAGS, target->GetUInt32Value(UNIT_FIELD_FLAGS), target->GetUInt32Value(UNIT_DYNAMIC_FLAGS), target->getFaction());
3471 PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES, defRespawnDelayStr.c_str(),curRespawnDelayStr.c_str());
3472 PSendSysMessage(LANG_NPCINFO_LOOT, cInfo->lootid,cInfo->pickpocketLootId,cInfo->SkinLootId);
3473 PSendSysMessage(LANG_NPCINFO_DUNGEON_ID, target->GetInstanceId());
3474 PSendSysMessage(LANG_NPCINFO_POSITION,float(target->GetPositionX()), float(target->GetPositionY()), float(target->GetPositionZ()));
3476 if ((npcflags & UNIT_NPC_FLAG_VENDOR) )
3478 SendSysMessage(LANG_NPCINFO_VENDOR);
3480 if ((npcflags & UNIT_NPC_FLAG_TRAINER) )
3482 SendSysMessage(LANG_NPCINFO_TRAINER);
3485 return true;
3488 bool ChatHandler::HandleExploreCheatCommand(const char* args)
3490 if (!*args)
3491 return false;
3493 int flag = atoi((char*)args);
3495 Player *chr = getSelectedPlayer();
3496 if (chr == NULL)
3498 SendSysMessage(LANG_NO_CHAR_SELECTED);
3499 SetSentErrorMessage(true);
3500 return false;
3503 if (flag != 0)
3505 PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL, chr->GetName());
3506 if(chr!=m_session->GetPlayer())
3507 ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_ALL,m_session->GetPlayer()->GetName());
3509 else
3511 PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING, chr->GetName());
3512 if(chr!=m_session->GetPlayer())
3513 ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_NOTHING,m_session->GetPlayer()->GetName());
3516 for (uint8 i=0; i<128; i++)
3518 if (flag != 0)
3520 m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1+i,0xFFFFFFFF);
3522 else
3524 m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1+i,0);
3528 return true;
3531 bool ChatHandler::HandleHoverCommand(const char* args)
3533 char* px = strtok((char*)args, " ");
3534 uint32 flag;
3535 if (!px)
3536 flag = 1;
3537 else
3538 flag = atoi(px);
3540 m_session->GetPlayer()->SetHover(flag);
3542 if (flag)
3543 SendSysMessage(LANG_HOVER_ENABLED);
3544 else
3545 SendSysMessage(LANG_HOVER_DISABLED);
3547 return true;
3550 bool ChatHandler::HandleLevelUpCommand(const char* args)
3552 char* px = strtok((char*)args, " ");
3553 char* py = strtok((char*)NULL, " ");
3555 // command format parsing
3556 char* pname = (char*)NULL;
3557 int addlevel = 1;
3559 if(px && py) // .levelup name level
3561 addlevel = atoi(py);
3562 pname = px;
3564 else if(px && !py) // .levelup name OR .levelup level
3566 if(isalpha(px[0])) // .levelup name
3567 pname = px;
3568 else // .levelup level
3569 addlevel = atoi(px);
3571 // else .levelup - nothing do for prepering
3573 // player
3574 Player *chr = NULL;
3575 uint64 chr_guid = 0;
3577 std::string name;
3579 if(pname) // player by name
3581 name = pname;
3582 if(!normalizePlayerName(name))
3584 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3585 SetSentErrorMessage(true);
3586 return false;
3589 chr = objmgr.GetPlayer(name.c_str());
3590 if(!chr) // not in game
3592 chr_guid = objmgr.GetPlayerGUIDByName(name);
3593 if (chr_guid == 0)
3595 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3596 SetSentErrorMessage(true);
3597 return false;
3601 else // player by selection
3603 chr = getSelectedPlayer();
3605 if (chr == NULL)
3607 SendSysMessage(LANG_NO_CHAR_SELECTED);
3608 SetSentErrorMessage(true);
3609 return false;
3612 name = chr->GetName();
3615 assert(chr || chr_guid);
3617 int32 oldlevel = chr ? chr->getLevel() : Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL,chr_guid);
3618 int32 newlevel = oldlevel + addlevel;
3619 if(newlevel < 1)
3620 newlevel = 1;
3621 if(newlevel > 255) // hardcoded maximum level
3622 newlevel = 255;
3624 if(chr)
3626 chr->GiveLevel(newlevel);
3627 chr->InitTalentForLevel();
3628 chr->SetUInt32Value(PLAYER_XP,0);
3630 if(oldlevel == newlevel)
3631 ChatHandler(chr).SendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET);
3632 else
3633 if(oldlevel < newlevel)
3634 ChatHandler(chr).PSendSysMessage(LANG_YOURS_LEVEL_UP,newlevel-oldlevel);
3635 else
3636 if(oldlevel > newlevel)
3637 ChatHandler(chr).PSendSysMessage(LANG_YOURS_LEVEL_DOWN,newlevel-oldlevel);
3639 else
3641 // update levle and XP at level, all other will be updated at loading
3642 Tokens values;
3643 Player::LoadValuesArrayFromDB(values,chr_guid);
3644 Player::SetUInt32ValueInArray(values,UNIT_FIELD_LEVEL,newlevel);
3645 Player::SetUInt32ValueInArray(values,PLAYER_XP,0);
3646 Player::SaveValuesArrayInDB(values,chr_guid);
3649 if(m_session->GetPlayer() != chr) // including chr==NULL
3650 PSendSysMessage(LANG_YOU_CHANGE_LVL,name.c_str(),newlevel);
3651 return true;
3654 bool ChatHandler::HandleShowAreaCommand(const char* args)
3656 if (!*args)
3657 return false;
3659 int area = atoi((char*)args);
3661 Player *chr = getSelectedPlayer();
3662 if (chr == NULL)
3664 SendSysMessage(LANG_NO_CHAR_SELECTED);
3665 SetSentErrorMessage(true);
3666 return false;
3669 int offset = area / 32;
3670 uint32 val = (uint32)(1 << (area % 32));
3672 if(offset >= 128)
3674 SendSysMessage(LANG_BAD_VALUE);
3675 SetSentErrorMessage(true);
3676 return false;
3679 uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
3680 chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields | val));
3682 SendSysMessage(LANG_EXPLORE_AREA);
3683 return true;
3686 bool ChatHandler::HandleHideAreaCommand(const char* args)
3688 if (!*args)
3689 return false;
3691 int area = atoi((char*)args);
3693 Player *chr = getSelectedPlayer();
3694 if (chr == NULL)
3696 SendSysMessage(LANG_NO_CHAR_SELECTED);
3697 SetSentErrorMessage(true);
3698 return false;
3701 int offset = area / 32;
3702 uint32 val = (uint32)(1 << (area % 32));
3704 if(offset >= 128)
3706 SendSysMessage(LANG_BAD_VALUE);
3707 SetSentErrorMessage(true);
3708 return false;
3711 uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
3712 chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields ^ val));
3714 SendSysMessage(LANG_UNEXPLORE_AREA);
3715 return true;
3718 bool ChatHandler::HandleUpdate(const char* args)
3720 if(!*args)
3721 return false;
3723 uint32 updateIndex;
3724 uint32 value;
3726 char* pUpdateIndex = strtok((char*)args, " ");
3728 Unit* chr = getSelectedUnit();
3729 if (chr == NULL)
3731 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3732 SetSentErrorMessage(true);
3733 return false;
3736 if(!pUpdateIndex)
3738 return true;
3740 updateIndex = atoi(pUpdateIndex);
3741 //check updateIndex
3742 if(chr->GetTypeId() == TYPEID_PLAYER)
3744 if (updateIndex>=PLAYER_END) return true;
3746 else
3748 if (updateIndex>=UNIT_END) return true;
3751 char* pvalue = strtok(NULL, " ");
3752 if (!pvalue)
3754 value=chr->GetUInt32Value(updateIndex);
3756 PSendSysMessage(LANG_UPDATE, chr->GetGUIDLow(),updateIndex,value);
3757 return true;
3760 value=atoi(pvalue);
3762 PSendSysMessage(LANG_UPDATE_CHANGE, chr->GetGUIDLow(),updateIndex,value);
3764 chr->SetUInt32Value(updateIndex,value);
3766 return true;
3769 bool ChatHandler::HandleBankCommand(const char* /*args*/)
3771 m_session->SendShowBank( m_session->GetPlayer()->GetGUID() );
3773 return true;
3776 bool ChatHandler::HandleChangeWeather(const char* args)
3778 if(!*args)
3779 return false;
3781 //Weather is OFF
3782 if (!sWorld.getConfig(CONFIG_WEATHER))
3784 SendSysMessage(LANG_WEATHER_DISABLED);
3785 SetSentErrorMessage(true);
3786 return false;
3789 //*Change the weather of a cell
3790 char* px = strtok((char*)args, " ");
3791 char* py = strtok(NULL, " ");
3793 if (!px || !py)
3794 return false;
3796 uint32 type = (uint32)atoi(px); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
3797 float grade = (float)atof(py); //0 to 1, sending -1 is instand good weather
3799 Player *player = m_session->GetPlayer();
3800 uint32 zoneid = player->GetZoneId();
3802 Weather* wth = sWorld.FindWeather(zoneid);
3804 if(!wth)
3805 wth = sWorld.AddWeather(zoneid);
3806 if(!wth)
3808 SendSysMessage(LANG_NO_WEATHER);
3809 SetSentErrorMessage(true);
3810 return false;
3813 wth->SetWeather(WeatherType(type), grade);
3815 return true;
3818 bool ChatHandler::HandleSetValue(const char* args)
3820 if(!*args)
3821 return false;
3823 char* px = strtok((char*)args, " ");
3824 char* py = strtok(NULL, " ");
3825 char* pz = strtok(NULL, " ");
3827 if (!px || !py)
3828 return false;
3830 Unit* target = getSelectedUnit();
3831 if(!target)
3833 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3834 SetSentErrorMessage(true);
3835 return false;
3838 uint64 guid = target->GetGUID();
3840 uint32 Opcode = (uint32)atoi(px);
3841 if(Opcode >= target->GetValuesCount())
3843 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, GUID_LOPART(guid), target->GetValuesCount());
3844 return false;
3846 uint32 iValue;
3847 float fValue;
3848 bool isint32 = true;
3849 if(pz)
3850 isint32 = (bool)atoi(pz);
3851 if(isint32)
3853 iValue = (uint32)atoi(py);
3854 sLog.outDebug(GetMangosString(LANG_SET_UINT), GUID_LOPART(guid), Opcode, iValue);
3855 target->SetUInt32Value( Opcode , iValue );
3856 PSendSysMessage(LANG_SET_UINT_FIELD, GUID_LOPART(guid), Opcode,iValue);
3858 else
3860 fValue = (float)atof(py);
3861 sLog.outDebug(GetMangosString(LANG_SET_FLOAT), GUID_LOPART(guid), Opcode, fValue);
3862 target->SetFloatValue( Opcode , fValue );
3863 PSendSysMessage(LANG_SET_FLOAT_FIELD, GUID_LOPART(guid), Opcode,fValue);
3866 return true;
3869 bool ChatHandler::HandleGetValue(const char* args)
3871 if(!*args)
3872 return false;
3874 char* px = strtok((char*)args, " ");
3875 char* pz = strtok(NULL, " ");
3877 if (!px)
3878 return false;
3880 Unit* target = getSelectedUnit();
3881 if(!target)
3883 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3884 SetSentErrorMessage(true);
3885 return false;
3888 uint64 guid = target->GetGUID();
3890 uint32 Opcode = (uint32)atoi(px);
3891 if(Opcode >= target->GetValuesCount())
3893 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, GUID_LOPART(guid), target->GetValuesCount());
3894 return false;
3896 uint32 iValue;
3897 float fValue;
3898 bool isint32 = true;
3899 if(pz)
3900 isint32 = (bool)atoi(pz);
3902 if(isint32)
3904 iValue = target->GetUInt32Value( Opcode );
3905 sLog.outDebug(GetMangosString(LANG_GET_UINT), GUID_LOPART(guid), Opcode, iValue);
3906 PSendSysMessage(LANG_GET_UINT_FIELD, GUID_LOPART(guid), Opcode, iValue);
3908 else
3910 fValue = target->GetFloatValue( Opcode );
3911 sLog.outDebug(GetMangosString(LANG_GET_FLOAT), GUID_LOPART(guid), Opcode, fValue);
3912 PSendSysMessage(LANG_GET_FLOAT_FIELD, GUID_LOPART(guid), Opcode, fValue);
3915 return true;
3918 bool ChatHandler::HandleSet32Bit(const char* args)
3920 if(!*args)
3921 return false;
3923 char* px = strtok((char*)args, " ");
3924 char* py = strtok(NULL, " ");
3926 if (!px || !py)
3927 return false;
3929 uint32 Opcode = (uint32)atoi(px);
3930 uint32 Value = (uint32)atoi(py);
3931 if (Value > 32) //uint32 = 32 bits
3932 return false;
3934 sLog.outDebug(GetMangosString(LANG_SET_32BIT), Opcode, Value);
3936 m_session->GetPlayer( )->SetUInt32Value( Opcode , 2^Value );
3938 PSendSysMessage(LANG_SET_32BIT_FIELD, Opcode,1);
3939 return true;
3942 bool ChatHandler::HandleMod32Value(const char* args)
3944 if(!*args)
3945 return false;
3947 char* px = strtok((char*)args, " ");
3948 char* py = strtok(NULL, " ");
3950 if (!px || !py)
3951 return false;
3953 uint32 Opcode = (uint32)atoi(px);
3954 int Value = atoi(py);
3956 if(Opcode >= m_session->GetPlayer()->GetValuesCount())
3958 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, m_session->GetPlayer()->GetGUIDLow(), m_session->GetPlayer( )->GetValuesCount());
3959 return false;
3962 sLog.outDebug(GetMangosString(LANG_CHANGE_32BIT), Opcode, Value);
3964 int CurrentValue = (int)m_session->GetPlayer( )->GetUInt32Value( Opcode );
3966 CurrentValue += Value;
3967 m_session->GetPlayer( )->SetUInt32Value( Opcode , (uint32)CurrentValue );
3969 PSendSysMessage(LANG_CHANGE_32BIT_FIELD, Opcode,CurrentValue);
3971 return true;
3974 bool ChatHandler::HandleAddTeleCommand(const char * args)
3976 if(!*args)
3977 return false;
3979 Player *player=m_session->GetPlayer();
3980 if (!player)
3981 return false;
3983 std::string name = args;
3985 if(objmgr.GetGameTele(name))
3987 SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST);
3988 SetSentErrorMessage(true);
3989 return false;
3992 GameTele tele;
3993 tele.position_x = player->GetPositionX();
3994 tele.position_y = player->GetPositionY();
3995 tele.position_z = player->GetPositionZ();
3996 tele.orientation = player->GetOrientation();
3997 tele.mapId = player->GetMapId();
3998 tele.name = name;
4000 if(objmgr.AddGameTele(tele))
4002 SendSysMessage(LANG_COMMAND_TP_ADDED);
4004 else
4006 SendSysMessage(LANG_COMMAND_TP_ADDEDERR);
4007 SetSentErrorMessage(true);
4008 return false;
4011 return true;
4014 bool ChatHandler::HandleDelTeleCommand(const char * args)
4016 if(!*args)
4017 return false;
4019 std::string name = args;
4021 if(!objmgr.DeleteGameTele(name))
4023 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
4024 SetSentErrorMessage(true);
4025 return false;
4028 SendSysMessage(LANG_COMMAND_TP_DELETED);
4029 return true;
4032 bool ChatHandler::HandleListAurasCommand (const char * /*args*/)
4034 Unit *unit = getSelectedUnit();
4035 if(!unit)
4037 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4038 SetSentErrorMessage(true);
4039 return false;
4042 char const* talentStr = GetMangosString(LANG_TALENT);
4043 char const* passiveStr = GetMangosString(LANG_PASSIVE);
4045 Unit::AuraMap const& uAuras = unit->GetAuras();
4046 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS, uAuras.size());
4047 for (Unit::AuraMap::const_iterator itr = uAuras.begin(); itr != uAuras.end(); ++itr)
4049 bool talent = GetTalentSpellCost(itr->second->GetId()) > 0;
4050 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL, itr->second->GetId(), itr->second->GetEffIndex(),
4051 itr->second->GetModifier()->m_auraname, itr->second->GetAuraDuration(), itr->second->GetAuraMaxDuration(),
4052 itr->second->GetSpellProto()->SpellName[m_session->GetSessionDbcLocale()],
4053 (itr->second->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4054 IS_PLAYER_GUID(itr->second->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr->second->GetCasterGUID()));
4056 for (int i = 0; i < TOTAL_AURAS; i++)
4058 Unit::AuraList const& uAuraList = unit->GetAurasByType(AuraType(i));
4059 if (uAuraList.empty()) continue;
4060 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE, uAuraList.size(), i);
4061 for (Unit::AuraList::const_iterator itr = uAuraList.begin(); itr != uAuraList.end(); ++itr)
4063 bool talent = GetTalentSpellCost((*itr)->GetId()) > 0;
4064 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE, (*itr)->GetId(), (*itr)->GetEffIndex(),
4065 (*itr)->GetSpellProto()->SpellName[m_session->GetSessionDbcLocale()],((*itr)->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4066 IS_PLAYER_GUID((*itr)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr)->GetCasterGUID()));
4069 return true;
4072 bool ChatHandler::HandleResetHonorCommand (const char * args)
4074 char* pName = strtok((char*)args, "");
4075 Player *player = NULL;
4076 if (pName)
4078 std::string name = pName;
4079 if(!normalizePlayerName(name))
4081 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4082 SetSentErrorMessage(true);
4083 return false;
4086 uint64 guid = objmgr.GetPlayerGUIDByName(name.c_str());
4087 player = objmgr.GetPlayer(guid);
4089 else
4090 player = getSelectedPlayer();
4092 if(!player)
4094 SendSysMessage(LANG_NO_CHAR_SELECTED);
4095 return true;
4098 player->SetUInt32Value(PLAYER_FIELD_KILLS, 0);
4099 player->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS, 0);
4100 player->SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY, 0);
4101 player->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION, 0);
4102 player->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION, 0);
4104 return true;
4107 static bool HandleResetStatsOrLevelHelper(Player* player)
4109 PlayerInfo const *info = objmgr.GetPlayerInfo(player->getRace(), player->getClass());
4110 if(!info) return false;
4112 ChrClassesEntry const* cEntry = sChrClassesStore.LookupEntry(player->getClass());
4113 if(!cEntry)
4115 sLog.outError("Class %u not found in DBC (Wrong DBC files?)",player->getClass());
4116 return false;
4119 uint8 powertype = cEntry->powerType;
4121 uint32 unitfield;
4122 if(powertype == POWER_RAGE)
4123 unitfield = 0x1100EE00;
4124 else if(powertype == POWER_ENERGY)
4125 unitfield = 0x00000000;
4126 else if(powertype == POWER_MANA)
4127 unitfield = 0x0000EE00;
4128 else
4130 sLog.outError("Invalid default powertype %u for player (class %u)",powertype,player->getClass());
4131 return false;
4134 // reset m_form if no aura
4135 if(!player->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT))
4136 player->m_form = FORM_NONE;
4138 player->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, DEFAULT_WORLD_OBJECT_SIZE );
4139 player->SetFloatValue(UNIT_FIELD_COMBATREACH, 1.5f );
4141 player->setFactionForRace(player->getRace());
4143 player->SetUInt32Value(UNIT_FIELD_BYTES_0, ( ( player->getRace() ) | ( player->getClass() << 8 ) | ( player->getGender() << 16 ) | ( powertype << 24 ) ) );
4145 // reset only if player not in some form;
4146 if(player->m_form==FORM_NONE)
4148 switch(player->getGender())
4150 case GENDER_FEMALE:
4151 player->SetDisplayId(info->displayId_f);
4152 player->SetNativeDisplayId(info->displayId_f);
4153 break;
4154 case GENDER_MALE:
4155 player->SetDisplayId(info->displayId_m);
4156 player->SetNativeDisplayId(info->displayId_m);
4157 break;
4158 default:
4159 break;
4163 // set UNIT_FIELD_BYTES_1 to init state but preserve m_form value
4164 player->SetUInt32Value(UNIT_FIELD_BYTES_1, unitfield);
4165 player->SetByteValue(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_UNK3 | UNIT_BYTE2_FLAG_UNK5 );
4166 player->SetByteValue(UNIT_FIELD_BYTES_2, 3, player->m_form);
4168 player->SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
4170 //-1 is default value
4171 player->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX, uint32(-1));
4173 //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000 );
4174 return true;
4177 bool ChatHandler::HandleResetLevelCommand(const char * args)
4179 char* pName = strtok((char*)args, "");
4180 Player *player = NULL;
4181 if (pName)
4183 std::string name = pName;
4184 if(!normalizePlayerName(name))
4186 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4187 SetSentErrorMessage(true);
4188 return false;
4191 uint64 guid = objmgr.GetPlayerGUIDByName(name.c_str());
4192 player = objmgr.GetPlayer(guid);
4194 else
4195 player = getSelectedPlayer();
4197 if(!player)
4199 SendSysMessage(LANG_NO_CHAR_SELECTED);
4200 SetSentErrorMessage(true);
4201 return false;
4204 if(!HandleResetStatsOrLevelHelper(player))
4205 return false;
4207 player->SetLevel(1);
4208 player->InitStatsForLevel(true);
4209 player->InitTaxiNodesForLevel();
4210 player->InitTalentForLevel();
4211 player->SetUInt32Value(PLAYER_XP,0);
4213 // reset level to summoned pet
4214 Pet* pet = player->GetPet();
4215 if(pet && pet->getPetType()==SUMMON_PET)
4216 pet->InitStatsForLevel(1);
4218 return true;
4221 bool ChatHandler::HandleResetStatsCommand(const char * args)
4223 char* pName = strtok((char*)args, "");
4224 Player *player = NULL;
4225 if (pName)
4227 std::string name = pName;
4228 if(!normalizePlayerName(name))
4230 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4231 SetSentErrorMessage(true);
4232 return false;
4235 uint64 guid = objmgr.GetPlayerGUIDByName(name.c_str());
4236 player = objmgr.GetPlayer(guid);
4238 else
4239 player = getSelectedPlayer();
4241 if(!player)
4243 SendSysMessage(LANG_NO_CHAR_SELECTED);
4244 SetSentErrorMessage(true);
4245 return false;
4248 if(!HandleResetStatsOrLevelHelper(player))
4249 return false;
4251 player->InitStatsForLevel(true);
4252 player->InitTaxiNodesForLevel();
4253 player->InitTalentForLevel();
4255 return true;
4258 bool ChatHandler::HandleResetSpellsCommand(const char * args)
4260 char* pName = strtok((char*)args, "");
4261 Player *player = NULL;
4262 uint64 playerGUID = 0;
4263 if (pName)
4265 std::string name = pName;
4267 if(!normalizePlayerName(name))
4269 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4270 SetSentErrorMessage(true);
4271 return false;
4274 player = objmgr.GetPlayer(name.c_str());
4275 if(!player)
4276 playerGUID = objmgr.GetPlayerGUIDByName(name.c_str());
4278 else
4279 player = getSelectedPlayer();
4281 if(!player && !playerGUID)
4283 SendSysMessage(LANG_NO_CHAR_SELECTED);
4284 SetSentErrorMessage(true);
4285 return false;
4288 if(player)
4290 player->resetSpells();
4292 ChatHandler(player).SendSysMessage(LANG_RESET_SPELLS);
4294 if(m_session->GetPlayer()!=player)
4295 PSendSysMessage(LANG_RESET_SPELLS_ONLINE,player->GetName());
4297 else
4299 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS), GUID_LOPART(playerGUID));
4300 PSendSysMessage(LANG_RESET_SPELLS_OFFLINE,pName);
4303 return true;
4306 bool ChatHandler::HandleResetTalentsCommand(const char * args)
4308 char* pName = strtok((char*)args, "");
4309 Player *player = NULL;
4310 uint64 playerGUID = 0;
4311 if (pName)
4313 std::string name = pName;
4314 if(!normalizePlayerName(name))
4316 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4317 SetSentErrorMessage(true);
4318 return false;
4321 player = objmgr.GetPlayer(name.c_str());
4322 if(!player)
4323 playerGUID = objmgr.GetPlayerGUIDByName(name.c_str());
4325 else
4326 player = getSelectedPlayer();
4328 if(!player && !playerGUID)
4330 SendSysMessage(LANG_NO_CHAR_SELECTED);
4331 SetSentErrorMessage(true);
4332 return false;
4335 if(player)
4337 player->resetTalents(true);
4339 ChatHandler(player).SendSysMessage(LANG_RESET_TALENTS);
4341 if(m_session->GetPlayer()!=player)
4342 PSendSysMessage(LANG_RESET_TALENTS_ONLINE,player->GetName());
4344 else
4346 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_TALENTS), GUID_LOPART(playerGUID) );
4347 PSendSysMessage(LANG_RESET_TALENTS_OFFLINE,pName);
4350 return true;
4353 bool ChatHandler::HandleResetAllCommand(const char * args)
4355 if(!*args)
4356 return false;
4358 std::string casename = args;
4360 AtLoginFlags atLogin;
4362 // Command specially created as single command to prevent using short case names
4363 if(casename=="spells")
4365 atLogin = AT_LOGIN_RESET_SPELLS;
4366 sWorld.SendWorldText(LANG_RESETALL_SPELLS);
4368 else if(casename=="talents")
4370 atLogin = AT_LOGIN_RESET_TALENTS;
4371 sWorld.SendWorldText(LANG_RESETALL_TALENTS);
4373 else
4375 PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE,args);
4376 SetSentErrorMessage(true);
4377 return false;
4380 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u'",atLogin);
4381 HashMapHolder<Player>::MapType const& plist = ObjectAccessor::Instance().GetPlayers();
4382 for(HashMapHolder<Player>::MapType::const_iterator itr = plist.begin(); itr != plist.end(); ++itr)
4383 itr->second->SetAtLoginFlag(atLogin);
4385 return true;
4388 bool ChatHandler::HandleShutDownCommand(const char* args)
4390 if(!*args)
4391 return false;
4393 if(std::string(args)=="cancel")
4395 sWorld.ShutdownCancel();
4397 else
4399 int32 time = atoi(args);
4401 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4402 if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
4403 return false;
4405 sWorld.ShutdownServ(time);
4407 return true;
4410 bool ChatHandler::HandleRestartCommand(const char* args)
4412 if(!*args)
4413 return false;
4415 if(std::string(args)=="cancel")
4417 sWorld.ShutdownCancel();
4419 else
4421 int32 time = atoi(args);
4423 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4424 if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
4425 return false;
4427 sWorld.ShutdownServ(time, SHUTDOWN_MASK_RESTART);
4429 return true;
4432 bool ChatHandler::HandleIdleRestartCommand(const char* args)
4434 if(!*args)
4435 return false;
4437 if(std::string(args)=="cancel")
4439 sWorld.ShutdownCancel();
4441 else
4443 int32 time = atoi(args);
4445 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4446 if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
4447 return false;
4449 sWorld.ShutdownServ(time,SHUTDOWN_MASK_RESTART+SHUTDOWN_MASK_IDLE);
4451 return true;
4454 bool ChatHandler::HandleIdleShutDownCommand(const char* args)
4456 if(!*args)
4457 return false;
4459 if(std::string(args)=="cancel")
4461 sWorld.ShutdownCancel();
4463 else
4465 int32 time = atoi(args);
4467 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4468 if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
4469 return false;
4471 sWorld.ShutdownServ(time,SHUTDOWN_MASK_IDLE);
4473 return true;
4476 bool ChatHandler::HandleAddQuest(const char* args)
4478 Player* player = getSelectedPlayer();
4479 if(!player)
4481 SendSysMessage(LANG_NO_CHAR_SELECTED);
4482 SetSentErrorMessage(true);
4483 return false;
4486 // .addquest #entry'
4487 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4488 char* cId = extractKeyFromLink((char*)args,"Hquest");
4489 if(!cId)
4490 return false;
4492 uint32 entry = atol(cId);
4494 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
4496 if(!pQuest)
4498 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND,entry);
4499 SetSentErrorMessage(true);
4500 return false;
4503 // check item starting quest (it can work incorrectly if added without item in inventory)
4504 QueryResult *result = WorldDatabase.PQuery("SELECT entry FROM item_template WHERE startquest = '%u' LIMIT 1",entry);
4505 if(result)
4507 Field* fields = result->Fetch();
4508 uint32 item_id = fields[0].GetUInt32();
4509 delete result;
4511 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, entry,item_id);
4512 SetSentErrorMessage(true);
4513 return false;
4516 // ok, normal (creature/GO starting) quest
4517 if( player->CanAddQuest( pQuest, true ) )
4519 player->AddQuest( pQuest, NULL );
4521 if ( player->CanCompleteQuest( entry ) )
4522 player->CompleteQuest( entry );
4525 return true;
4528 bool ChatHandler::HandleRemoveQuest(const char* args)
4530 Player* player = getSelectedPlayer();
4531 if(!player)
4533 SendSysMessage(LANG_NO_CHAR_SELECTED);
4534 SetSentErrorMessage(true);
4535 return false;
4538 // .removequest #entry'
4539 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4540 char* cId = extractKeyFromLink((char*)args,"Hquest");
4541 if(!cId)
4542 return false;
4544 uint32 entry = atol(cId);
4546 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
4548 if(!pQuest)
4550 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
4551 SetSentErrorMessage(true);
4552 return false;
4555 // remove all quest entries for 'entry' from quest log
4556 for(uint8 slot = 0; slot < MAX_QUEST_LOG_SIZE; ++slot )
4558 uint32 quest = player->GetQuestSlotQuestId(slot);
4559 if(quest==entry)
4561 player->SetQuestSlot(slot,0);
4563 // we ignore unequippable quest items in this case, its' still be equipped
4564 player->TakeQuestSourceItem( quest, false );
4568 // set quest status to not started (will updated in DB at next save)
4569 player->SetQuestStatus( entry, QUEST_STATUS_NONE);
4571 // reset rewarded for restart repeatable quest
4572 player->getQuestStatusMap()[entry].m_rewarded = false;
4574 SendSysMessage(LANG_COMMAND_QUEST_REMOVED);
4575 return true;
4578 bool ChatHandler::HandleCompleteQuest(const char* args)
4580 Player* player = getSelectedPlayer();
4581 if(!player)
4583 SendSysMessage(LANG_NO_CHAR_SELECTED);
4584 SetSentErrorMessage(true);
4585 return false;
4588 // .quest complete #entry
4589 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4590 char* cId = extractKeyFromLink((char*)args,"Hquest");
4591 if(!cId)
4592 return false;
4594 uint32 entry = atol(cId);
4596 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
4598 // If player doesn't have the quest
4599 if(!pQuest || player->GetQuestStatus(entry) == QUEST_STATUS_NONE)
4601 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
4602 SetSentErrorMessage(true);
4603 return false;
4606 // Add quest items for quests that require items
4607 for(uint8 x = 0; x < QUEST_OBJECTIVES_COUNT; ++x)
4609 uint32 id = pQuest->ReqItemId[x];
4610 uint32 count = pQuest->ReqItemCount[x];
4611 if(!id || !count)
4612 continue;
4614 uint32 curItemCount = player->GetItemCount(id,true);
4616 ItemPosCountVec dest;
4617 uint8 msg = player->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, id, count-curItemCount );
4618 if( msg == EQUIP_ERR_OK )
4620 Item* item = player->StoreNewItem( dest, id, true);
4621 player->SendNewItem(item,count-curItemCount,true,false);
4625 // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
4626 for(uint8 i = 0; i < QUEST_OBJECTIVES_COUNT; i++)
4628 uint32 creature = pQuest->ReqCreatureOrGOId[i];
4629 uint32 creaturecount = pQuest->ReqCreatureOrGOCount[i];
4631 if(uint32 spell_id = pQuest->ReqSpell[i])
4633 for(uint16 z = 0; z < creaturecount; ++z)
4634 player->CastedCreatureOrGO(creature,0,spell_id);
4636 else if(creature > 0)
4638 for(uint16 z = 0; z < creaturecount; ++z)
4639 player->KilledMonster(creature,0);
4641 else if(creature < 0)
4643 for(uint16 z = 0; z < creaturecount; ++z)
4644 player->CastedCreatureOrGO(creature,0,0);
4648 // If the quest requires reputation to complete
4649 if(uint32 repFaction = pQuest->GetRepObjectiveFaction())
4651 uint32 repValue = pQuest->GetRepObjectiveValue();
4652 uint32 curRep = player->GetReputation(repFaction);
4653 if(curRep < repValue)
4655 FactionEntry const *factionEntry = sFactionStore.LookupEntry(repFaction);
4656 player->SetFactionReputation(factionEntry,repValue);
4660 // If the quest requires money
4661 int32 ReqOrRewMoney = pQuest->GetRewOrReqMoney();
4662 if(ReqOrRewMoney < 0)
4663 player->ModifyMoney(-ReqOrRewMoney);
4665 player->CompleteQuest(entry);
4666 return true;
4669 bool ChatHandler::HandleBanCommand(const char* args)
4671 if(!args)
4672 return false;
4674 char* type = strtok((char*)args, " ");
4676 if(!type)
4677 return false;
4678 char* nameOrIP = strtok(NULL, " ");
4680 if(!nameOrIP)
4681 return false;
4683 char* duration = strtok(NULL," ");
4684 if(!duration || !atoi(duration))
4685 return false;
4687 char* reason = strtok(NULL,"");
4688 if(!reason)
4689 return false;
4691 switch(sWorld.BanAccount(type, nameOrIP, duration, reason,m_session->GetPlayerName()))
4693 case BAN_SUCCESS:
4694 if(atoi(duration)>0)
4695 PSendSysMessage(LANG_BAN_YOUBANNED,nameOrIP,secsToTimeString(TimeStringToSecs(duration),true).c_str(),reason);
4696 else
4697 PSendSysMessage(LANG_BAN_YOUPERMBANNED,nameOrIP,reason);
4698 break;
4699 case BAN_SYNTAX_ERROR:
4700 return false;
4701 case BAN_NOTFOUND:
4702 PSendSysMessage(LANG_BAN_NOTFOUND,type,nameOrIP);
4703 break;
4706 return true;
4709 bool ChatHandler::HandleUnBanCommand(const char* args)
4711 if(!args)
4712 return false;
4713 char* type = strtok((char*)args, " ");
4714 if(!type)
4715 return false;
4716 char* nameOrIP = strtok(NULL, " ");
4718 if(!nameOrIP)
4719 return false;
4721 if(sWorld.RemoveBanAccount(type,nameOrIP))
4722 PSendSysMessage(LANG_UNBAN_UNBANNED,nameOrIP);
4723 else
4724 PSendSysMessage(LANG_UNBAN_ERROR,nameOrIP);
4726 return true;
4729 bool ChatHandler::HandleBanInfoCommand(const char* args)
4731 if(!args)
4732 return false;
4734 char* cType = strtok((char*)args, " ");
4735 char* cnameOrIP = strtok(NULL, "");
4736 if(!cType || !cnameOrIP)
4737 return false;
4739 std::string nameOrIP = cnameOrIP;
4740 std::string type = cType;
4741 if (!IsIPAddress(cnameOrIP) && type=="ip")
4742 return false;
4744 Field *fields;
4745 if(type != "ip")
4747 //look the accountid up
4748 uint32 accountid;
4749 std::string accountname;
4750 if(type == "account")
4752 loginDatabase.escape_string(nameOrIP);
4753 QueryResult *result = loginDatabase.PQuery("SELECT id, username FROM account WHERE username = '%s'",nameOrIP.c_str());
4754 if (!result)
4756 PSendSysMessage(LANG_BANINFO_NOACCOUNT);
4757 return true;
4759 fields = result->Fetch();
4760 accountid = fields[0].GetUInt32();
4761 accountname = fields[1].GetCppString();
4762 delete result;
4764 else if(type == "character")
4766 if(!normalizePlayerName(nameOrIP))
4768 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4769 SetSentErrorMessage(true);
4770 return false;
4773 loginDatabase.escape_string(nameOrIP);
4774 QueryResult *result = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name = '%s'", nameOrIP.c_str());
4775 if (!result)
4777 PSendSysMessage(LANG_BANINFO_NOCHARACTER);
4778 return true;
4780 fields = result->Fetch();
4781 accountid = fields[0].GetUInt32();
4782 delete result;
4783 result = loginDatabase.PQuery("SELECT username FROM account WHERE id = '%u'", accountid);
4784 if (!result)
4786 PSendSysMessage(LANG_BANINFO_NOCHARACTER);
4787 return true;
4789 fields = result->Fetch();
4790 accountname = fields[0].GetCppString();
4791 delete result;
4793 else
4794 return false;
4796 QueryResult *result = loginDatabase.PQuery("SELECT FROM_UNIXTIME(bandate), unbandate-bandate, active, unbandate,banreason,bannedby FROM account_banned WHERE id = '%u' ORDER BY bandate ASC",accountid);
4797 if(!result)
4799 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN, accountname.c_str());
4800 return true;
4803 PSendSysMessage(LANG_BANINFO_BANHISTORY,accountname.c_str());
4806 fields = result->Fetch();
4808 time_t unbandate = time_t(fields[3].GetUInt64());
4809 bool active = false;
4810 if(fields[2].GetBool() && (fields[1].GetUInt64() == (uint64)0 ||unbandate >= time(NULL)) )
4811 active = true;
4812 bool permanent = (fields[1].GetUInt64() == (uint64)0);
4813 std::string bantime = permanent?GetMangosString(LANG_BANINFO_INFINITE):secsToTimeString(fields[1].GetUInt64(), true);
4814 PSendSysMessage(LANG_BANINFO_HISTORYENTRY,
4815 fields[0].GetString(), bantime.c_str(), active ? GetMangosString(LANG_BANINFO_YES):GetMangosString(LANG_BANINFO_NO), fields[4].GetString(), fields[5].GetString());
4816 }while (result->NextRow());
4818 delete result;
4820 else
4822 loginDatabase.escape_string(nameOrIP);
4823 QueryResult *result = loginDatabase.PQuery("SELECT ip, FROM_UNIXTIME(bandate), FROM_UNIXTIME(unbandate), unbandate-UNIX_TIMESTAMP(), banreason,bannedby,unbandate-bandate FROM ip_banned WHERE ip = '%s'",nameOrIP.c_str());
4824 if(!result)
4826 PSendSysMessage(LANG_BANINFO_NOIP);
4827 return true;
4829 fields = result->Fetch();
4830 bool permanent = (fields[6].GetUInt64()==(uint64)0);
4831 PSendSysMessage(LANG_BANINFO_IPENTRY,
4832 fields[0].GetString(), fields[1].GetString(), permanent ? GetMangosString(LANG_BANINFO_NEVER):fields[2].GetString(),
4833 permanent ? GetMangosString(LANG_BANINFO_INFINITE):secsToTimeString(fields[3].GetUInt64(), true).c_str(), fields[4].GetString(), fields[5].GetString());
4834 delete result;
4836 return true;
4839 bool ChatHandler::HandleBanListCommand(const char* args)
4841 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
4842 if(!*args)
4843 return false;
4844 char* cType = strtok((char*)args, " ");
4845 char* cFilter = strtok(NULL, "");
4846 if(!cType || !cFilter)
4847 return false;
4848 std::string Filter = cFilter;
4849 std::string Type = cType;
4850 loginDatabase.escape_string(Filter);
4852 QueryResult* result = NULL;
4853 Field *fields = NULL;
4854 if(Type == "ip")
4856 result = loginDatabase.PQuery("SELECT ip FROM ip_banned WHERE ip "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'"),Filter.c_str());
4857 if(!result)
4859 PSendSysMessage(LANG_BANLIST_NOIP);
4860 return true;
4862 PSendSysMessage(LANG_BANLIST_MATCHINGIP);
4865 fields = result->Fetch();
4866 PSendSysMessage("%s",fields[0].GetString());
4867 } while (result->NextRow());
4869 delete result;
4870 return true;
4872 //lookup accountid
4873 if(Type == "account")
4875 result = loginDatabase.PQuery("SELECT id FROM account WHERE username "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'"),Filter.c_str());
4876 if (!result)
4878 PSendSysMessage(LANG_BANLIST_NOACCOUNT);
4879 return true;
4881 //do not delete result
4883 else if(Type == "characters")
4885 result = CharacterDatabase.PQuery("SELECT account FROM characters, WHERE name "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'"),Filter.c_str());
4886 if (!result)
4888 PSendSysMessage(LANG_BANLIST_NOCHARACTER);
4889 return true;
4892 else
4893 return false;
4895 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT);
4898 fields = result->Fetch();
4899 uint32 accountid = fields[0].GetUInt32();
4900 QueryResult* banresult = loginDatabase.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.active = '1' AND account_banned.id=account.id",accountid);
4901 if(banresult)
4903 Field* fields2 = banresult->Fetch();
4904 PSendSysMessage("%s",fields2[0].GetString());
4905 delete banresult;
4907 } while (result->NextRow());
4909 delete result;
4910 return true;
4913 bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
4915 Player* pl = m_session->GetPlayer();
4917 CellPair p(MaNGOS::ComputeCellPair(pl->GetPositionX(), pl->GetPositionY()));
4918 Cell cell(p);
4919 cell.data.Part.reserved = ALL_DISTRICT;
4920 cell.SetNoCreate();
4922 MaNGOS::RespawnDo u_do;
4923 MaNGOS::WorldObjectWorker<MaNGOS::RespawnDo> worker(u_do);
4925 TypeContainerVisitor<MaNGOS::WorldObjectWorker<MaNGOS::RespawnDo>, GridTypeMapContainer > obj_worker(worker);
4926 CellLock<GridReadGuard> cell_lock(cell, p);
4927 cell_lock->Visit(cell_lock, obj_worker, *MapManager::Instance().GetMap(pl->GetMapId(), pl));
4929 return true;
4932 bool ChatHandler::HandleFlyModeCommand(const char* args)
4934 if(!args)
4935 return false;
4937 Unit *unit = getSelectedUnit();
4938 if (!unit || (unit->GetTypeId() != TYPEID_PLAYER))
4939 unit = m_session->GetPlayer();
4941 WorldPacket data(12);
4942 if (strncmp(args, "on", 3) == 0)
4943 data.SetOpcode(SMSG_MOVE_SET_CAN_FLY);
4944 else if (strncmp(args, "off", 4) == 0)
4945 data.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY);
4946 else
4948 SendSysMessage(LANG_USE_BOL);
4949 return false;
4951 data.append(unit->GetPackGUID());
4952 data << uint32(0); // unknown
4953 unit->SendMessageToSet(&data, true);
4954 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS, unit->GetName(), args);
4955 return true;
4958 bool ChatHandler::HandleLoadPDumpCommand(const char *args)
4960 if(!args)
4961 return false;
4963 char * file = strtok((char*)args, " "); if(!file) return false;
4964 char * acc = strtok(NULL, " "); if(!acc) return false;
4965 if(!file || !acc)
4966 return false;
4968 uint32 account_id = accmgr.GetId(acc);
4969 if(!account_id)
4971 account_id = atoi(acc);
4972 if(account_id)
4974 std::string acc_name;
4975 if(!accmgr.GetName(account_id,acc_name))
4976 return false;
4978 else
4979 return false;
4982 char * name = strtok(NULL, " ");
4983 char * guid_str = name ? strtok(NULL, " ") : NULL;
4985 uint32 guid = guid_str ? atoi(guid_str) : 0;
4987 if(PlayerDumpReader().LoadDump(file, account_id, name ? name : "", guid))
4988 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS);
4989 else
4990 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED);
4992 return true;
4995 bool ChatHandler::HandleChangeEntryCommand(const char *args)
4997 if(!args)
4998 return false;
5000 uint32 newEntryNum = atoi(args);
5001 if(!newEntryNum)
5002 return false;
5004 Unit* unit = getSelectedUnit();
5005 if(!unit || unit->GetTypeId() != TYPEID_UNIT)
5007 SendSysMessage(LANG_SELECT_CREATURE);
5008 SetSentErrorMessage(true);
5009 return false;
5011 Creature* creature = (Creature*)unit;
5012 if(creature->UpdateEntry(newEntryNum))
5013 SendSysMessage(LANG_DONE);
5014 else
5015 SendSysMessage(LANG_ERROR);
5016 return true;
5019 bool ChatHandler::HandleWritePDumpCommand(const char *args)
5021 if(!args)
5022 return false;
5024 char* file = strtok((char*)args, " ");
5025 char* p2 = strtok(NULL, " ");
5027 if(!file || !p2)
5028 return false;
5030 uint32 guid = objmgr.GetPlayerGUIDByName(p2);
5031 if(!guid)
5032 guid = atoi(p2);
5034 if (PlayerDumpWriter().WriteDump(file, guid))
5035 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS);
5036 else
5037 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED);
5039 return true;
5042 bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
5044 Unit* unit = getSelectedUnit();
5045 if(!unit)
5047 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5048 SetSentErrorMessage(true);
5049 return false;
5052 PSendSysMessage(LANG_MOVEGENS_LIST,(unit->GetTypeId()==TYPEID_PLAYER ? "Player" : "Creature" ),unit->GetGUIDLow());
5054 MotionMaster* mm = unit->GetMotionMaster();
5055 for(MotionMaster::const_iterator itr = mm->begin(); itr != mm->end(); ++itr)
5057 switch((*itr)->GetMovementGeneratorType())
5059 case IDLE_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_IDLE); break;
5060 case RANDOM_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_RANDOM); break;
5061 case WAYPOINT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_WAYPOINT); break;
5062 case ANIMAL_RANDOM_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_ANIMAL_RANDOM); break;
5063 case CONFUSED_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_CONFUSED); break;
5064 case TARGETED_MOTION_TYPE:
5066 if(unit->GetTypeId()==TYPEID_PLAYER)
5068 TargetedMovementGenerator<Player> const* mgen = static_cast<TargetedMovementGenerator<Player> const*>(*itr);
5069 Unit* target = mgen->GetTarget();
5070 if(target)
5071 PSendSysMessage(LANG_MOVEGENS_TARGETED_PLAYER,target->GetName(),target->GetGUIDLow());
5072 else
5073 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL);
5075 else
5077 TargetedMovementGenerator<Creature> const* mgen = static_cast<TargetedMovementGenerator<Creature> const*>(*itr);
5078 Unit* target = mgen->GetTarget();
5079 if(target)
5080 PSendSysMessage(LANG_MOVEGENS_TARGETED_CREATURE,target->GetName(),target->GetGUIDLow());
5081 else
5082 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL);
5084 break;
5086 case HOME_MOTION_TYPE:
5087 if(unit->GetTypeId()==TYPEID_UNIT)
5089 float x,y,z;
5090 (*itr)->GetDestination(x,y,z);
5091 PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE,x,y,z);
5093 else
5094 SendSysMessage(LANG_MOVEGENS_HOME_PLAYER);
5095 break;
5096 case FLIGHT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FLIGHT); break;
5097 case POINT_MOTION_TYPE:
5099 float x,y,z;
5100 (*itr)->GetDestination(x,y,z);
5101 PSendSysMessage(LANG_MOVEGENS_POINT,x,y,z);
5102 break;
5104 case FLEEING_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FEAR); break;
5105 case DISTRACT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_DISTRACT); break;
5106 default:
5107 PSendSysMessage(LANG_MOVEGENS_UNKNOWN,(*itr)->GetMovementGeneratorType());
5108 break;
5111 return true;
5114 bool ChatHandler::HandlePLimitCommand(const char *args)
5116 if(*args)
5118 char* param = strtok((char*)args, " ");
5119 if(!param)
5120 return false;
5122 int l = strlen(param);
5124 if( strncmp(param,"player",l) == 0 )
5125 sWorld.SetPlayerLimit(-SEC_PLAYER);
5126 else if(strncmp(param,"moderator",l) == 0 )
5127 sWorld.SetPlayerLimit(-SEC_MODERATOR);
5128 else if(strncmp(param,"gamemaster",l) == 0 )
5129 sWorld.SetPlayerLimit(-SEC_GAMEMASTER);
5130 else if(strncmp(param,"administrator",l) == 0 )
5131 sWorld.SetPlayerLimit(-SEC_ADMINISTRATOR);
5132 else if(strncmp(param,"reset",l) == 0 )
5133 sWorld.SetPlayerLimit( sConfig.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT) );
5134 else
5136 int val = atoi(param);
5137 if(val < -SEC_ADMINISTRATOR) val = -SEC_ADMINISTRATOR;
5139 sWorld.SetPlayerLimit(val);
5142 // kick all low security level players
5143 if(sWorld.GetPlayerAmountLimit() > SEC_PLAYER)
5144 sWorld.KickAllLess(sWorld.GetPlayerSecurityLimit());
5147 uint32 pLimit = sWorld.GetPlayerAmountLimit();
5148 AccountTypes allowedAccountType = sWorld.GetPlayerSecurityLimit();
5149 char const* secName = "";
5150 switch(allowedAccountType)
5152 case SEC_PLAYER: secName = "Player"; break;
5153 case SEC_MODERATOR: secName = "Moderator"; break;
5154 case SEC_GAMEMASTER: secName = "Gamemaster"; break;
5155 case SEC_ADMINISTRATOR: secName = "Administrator"; break;
5156 default: secName = "<unknown>"; break;
5159 PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit,secName);
5161 return true;
5164 bool ChatHandler::HandleCastCommand(const char* args)
5166 if(!*args)
5167 return false;
5169 Unit* target = getSelectedUnit();
5171 if(!target)
5173 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5174 SetSentErrorMessage(true);
5175 return false;
5178 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5179 uint32 spell = extractSpellIdFromLink((char*)args);
5180 if(!spell)
5181 return false;
5183 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
5184 if(!spellInfo)
5185 return false;
5187 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
5189 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
5190 SetSentErrorMessage(true);
5191 return false;
5194 char* trig_str = strtok(NULL, " ");
5195 if(trig_str)
5197 int l = strlen(trig_str);
5198 if(strncmp(trig_str,"triggered",l) != 0 )
5199 return false;
5202 bool triggered = (trig_str != NULL);
5204 m_session->GetPlayer()->CastSpell(target,spell,triggered);
5206 return true;
5209 bool ChatHandler::HandleCastBackCommand(const char* args)
5211 Creature* caster = getSelectedCreature();
5213 if(!caster)
5215 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5216 SetSentErrorMessage(true);
5217 return false;
5220 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
5221 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5222 uint32 spell = extractSpellIdFromLink((char*)args);
5223 if(!spell || !sSpellStore.LookupEntry(spell))
5224 return false;
5226 char* trig_str = strtok(NULL, " ");
5227 if(trig_str)
5229 int l = strlen(trig_str);
5230 if(strncmp(trig_str,"triggered",l) != 0 )
5231 return false;
5234 bool triggered = (trig_str != NULL);
5236 // update orientation at server
5237 caster->SetOrientation(caster->GetAngle(m_session->GetPlayer()));
5239 // and client
5240 WorldPacket data;
5241 caster->BuildHeartBeatMsg(&data);
5242 caster->SendMessageToSet(&data,true);
5244 caster->CastSpell(m_session->GetPlayer(),spell,false);
5246 return true;
5249 bool ChatHandler::HandleCastDistCommand(const char* args)
5251 if(!*args)
5252 return false;
5254 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5255 uint32 spell = extractSpellIdFromLink((char*)args);
5256 if(!spell)
5257 return false;
5259 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
5260 if(!spellInfo)
5261 return false;
5263 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
5265 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
5266 SetSentErrorMessage(true);
5267 return false;
5270 char *distStr = strtok(NULL, " ");
5272 float dist = 0;
5274 if(distStr)
5275 sscanf(distStr, "%f", &dist);
5277 char* trig_str = strtok(NULL, " ");
5278 if(trig_str)
5280 int l = strlen(trig_str);
5281 if(strncmp(trig_str,"triggered",l) != 0 )
5282 return false;
5285 bool triggered = (trig_str != NULL);
5287 float x,y,z;
5288 m_session->GetPlayer()->GetClosePoint(x,y,z,dist);
5290 m_session->GetPlayer()->CastSpell(x,y,z,spell,triggered);
5291 return true;
5294 bool ChatHandler::HandleCastTargetCommand(const char* args)
5296 Creature* caster = getSelectedCreature();
5298 if(!caster)
5300 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5301 SetSentErrorMessage(true);
5302 return false;
5305 if(!caster->getVictim())
5307 SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM);
5308 SetSentErrorMessage(true);
5309 return false;
5312 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5313 uint32 spell = extractSpellIdFromLink((char*)args);
5314 if(!spell || !sSpellStore.LookupEntry(spell))
5315 return false;
5317 char* trig_str = strtok(NULL, " ");
5318 if(trig_str)
5320 int l = strlen(trig_str);
5321 if(strncmp(trig_str,"triggered",l) != 0 )
5322 return false;
5325 bool triggered = (trig_str != NULL);
5327 // update orientation at server
5328 caster->SetOrientation(caster->GetAngle(m_session->GetPlayer()));
5330 // and client
5331 WorldPacket data;
5332 caster->BuildHeartBeatMsg(&data);
5333 caster->SendMessageToSet(&data,true);
5335 caster->CastSpell(caster->getVictim(),spell,false);
5337 return true;
5341 ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
5342 Without this function 3rd party scripting library will get linking errors (unresolved external)
5343 when attempting to use the PointMovementGenerator
5345 bool ChatHandler::HandleComeToMeCommand(const char *args)
5347 Creature* caster = getSelectedCreature();
5349 if(!caster)
5351 SendSysMessage(LANG_SELECT_CREATURE);
5352 SetSentErrorMessage(true);
5353 return false;
5356 char* newFlagStr = strtok((char*)args, " ");
5358 if(!newFlagStr)
5359 return false;
5361 uint32 newFlags = atoi(newFlagStr);
5363 caster->SetUnitMovementFlags(newFlags);
5365 Player* pl = m_session->GetPlayer();
5367 caster->GetMotionMaster()->MovePoint(0, pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ());
5368 return true;
5371 bool ChatHandler::HandleCastSelfCommand(const char* args)
5373 if(!*args)
5374 return false;
5376 Unit* target = getSelectedUnit();
5378 if(!target)
5380 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5381 SetSentErrorMessage(true);
5382 return false;
5385 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5386 uint32 spell = extractSpellIdFromLink((char*)args);
5387 if(!spell)
5388 return false;
5390 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
5391 if(!spellInfo)
5392 return false;
5394 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
5396 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
5397 SetSentErrorMessage(true);
5398 return false;
5401 target->CastSpell(target,spell,false);
5403 return true;
5406 std::string GetTimeString(uint32 time)
5408 uint16 days = time / DAY, hours = (time % DAY) / HOUR, minute = (time % HOUR) / MINUTE;
5409 std::ostringstream ss;
5410 if(days) ss << days << "d ";
5411 if(hours) ss << hours << "h ";
5412 ss << minute << "m";
5413 return ss.str();
5416 bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
5418 Player* player = getSelectedPlayer();
5419 if (!player) player = m_session->GetPlayer();
5420 uint32 counter = 0;
5421 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; i++)
5423 Player::BoundInstancesMap &binds = player->GetBoundInstances(i);
5424 for(Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end(); ++itr)
5426 InstanceSave *save = itr->second.save;
5427 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
5428 PSendSysMessage("map: %d inst: %d perm: %s diff: %s canReset: %s TTR: %s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty() == DIFFICULTY_NORMAL ? "normal" : "heroic", save->CanReset() ? "yes" : "no", timeleft.c_str());
5429 counter++;
5432 PSendSysMessage("player binds: %d", counter);
5433 counter = 0;
5434 Group *group = player->GetGroup();
5435 if(group)
5437 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; i++)
5439 Group::BoundInstancesMap &binds = group->GetBoundInstances(i);
5440 for(Group::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end(); ++itr)
5442 InstanceSave *save = itr->second.save;
5443 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
5444 PSendSysMessage("map: %d inst: %d perm: %s diff: %s canReset: %s TTR: %s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty() == DIFFICULTY_NORMAL ? "normal" : "heroic", save->CanReset() ? "yes" : "no", timeleft.c_str());
5445 counter++;
5449 PSendSysMessage("group binds: %d", counter);
5451 return true;
5454 bool ChatHandler::HandleInstanceUnbindCommand(const char* args)
5456 if(!*args)
5457 return false;
5459 std::string cmd = args;
5460 if(cmd == "all")
5462 Player* player = getSelectedPlayer();
5463 if (!player) player = m_session->GetPlayer();
5464 uint32 counter = 0;
5465 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; i++)
5467 Player::BoundInstancesMap &binds = player->GetBoundInstances(i);
5468 for(Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end();)
5470 if(itr->first != player->GetMapId())
5472 InstanceSave *save = itr->second.save;
5473 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
5474 PSendSysMessage("unbinding map: %d inst: %d perm: %s diff: %s canReset: %s TTR: %s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty() == DIFFICULTY_NORMAL ? "normal" : "heroic", save->CanReset() ? "yes" : "no", timeleft.c_str());
5475 player->UnbindInstance(itr, i);
5476 counter++;
5478 else
5479 ++itr;
5482 PSendSysMessage("instances unbound: %d", counter);
5484 return true;
5487 bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
5489 PSendSysMessage("instances loaded: %d", MapManager::Instance().GetNumInstances());
5490 PSendSysMessage("players in instances: %d", MapManager::Instance().GetNumPlayersInInstances());
5491 PSendSysMessage("instance saves: %d", sInstanceSaveManager.GetNumInstanceSaves());
5492 PSendSysMessage("players bound: %d", sInstanceSaveManager.GetNumBoundPlayersTotal());
5493 PSendSysMessage("groups bound: %d", sInstanceSaveManager.GetNumBoundGroupsTotal());
5494 return true;
5497 bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
5499 Player* pl = m_session->GetPlayer();
5501 Map* map = pl->GetMap();
5502 if (!map->IsDungeon())
5504 PSendSysMessage("Map is not a dungeon.");
5505 SetSentErrorMessage(true);
5506 return false;
5509 if (!((InstanceMap*)map)->GetInstanceData())
5511 PSendSysMessage("Map has no instance data.");
5512 SetSentErrorMessage(true);
5513 return false;
5516 ((InstanceMap*)map)->GetInstanceData()->SaveToDB();
5517 return true;