2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
24 #include "ObjectMgr.h"
25 #include "AccountMgr.h"
26 #include "PlayerDump.h"
30 #include "GameObject.h"
34 #include "ObjectAccessor.h"
35 #include "MapManager.h"
36 #include "ScriptCalls.h"
38 #include "GridNotifiersImpl.h"
41 #include "PointMovementGenerator.h"
42 #include "TargetedMovementGenerator.h"
43 #include "SkillDiscovery.h"
44 #include "SkillExtraItems.h"
45 #include "SystemConfig.h"
46 #include "Config/ConfigEnv.h"
48 #include "ItemEnchantmentMgr.h"
49 #include "BattleGroundMgr.h"
50 #include "InstanceSaveMgr.h"
51 #include "InstanceData.h"
52 #include "CreatureEventAIMgr.h"
55 bool ChatHandler::HandleReloadAllCommand(const char*)
57 HandleReloadSkillFishingBaseLevelCommand("");
59 HandleReloadAllAchievementCommand("");
60 HandleReloadAllAreaCommand("");
61 HandleReloadAllEventAICommand("");
62 HandleReloadAllLootCommand("");
63 HandleReloadAllNpcCommand("");
64 HandleReloadAllQuestCommand("");
65 HandleReloadAllSpellCommand("");
66 HandleReloadAllItemCommand("");
67 HandleReloadAllLocalesCommand("");
69 HandleReloadCommandCommand("");
70 HandleReloadReservedNameCommand("");
71 HandleReloadMangosStringCommand("");
72 HandleReloadGameTeleCommand("");
76 bool ChatHandler::HandleReloadAllAchievementCommand(const char*)
78 HandleReloadAchievementCriteriaDataCommand("");
79 HandleReloadAchievementRewardCommand("");
83 bool ChatHandler::HandleReloadAllAreaCommand(const char*)
85 //HandleReloadQuestAreaTriggersCommand(""); -- reloaded in HandleReloadAllQuestCommand
86 HandleReloadAreaTriggerTeleportCommand("");
87 HandleReloadAreaTriggerTavernCommand("");
88 HandleReloadGameGraveyardZoneCommand("");
92 bool ChatHandler::HandleReloadAllLootCommand(const char*)
94 sLog
.outString( "Re-Loading Loot Tables..." );
96 SendGlobalSysMessage("DB tables `*_loot_template` reloaded.");
100 bool ChatHandler::HandleReloadAllNpcCommand(const char* /*args*/)
102 HandleReloadNpcGossipCommand("a");
103 HandleReloadNpcOptionCommand("a");
104 HandleReloadNpcTrainerCommand("a");
105 HandleReloadNpcVendorCommand("a");
106 HandleReloadPointsOfInterestCommand("a");
107 HandleReloadSpellClickSpellsCommand("a");
111 bool ChatHandler::HandleReloadAllQuestCommand(const char* /*args*/)
113 HandleReloadQuestAreaTriggersCommand("a");
114 HandleReloadQuestTemplateCommand("a");
116 sLog
.outString( "Re-Loading Quests Relations..." );
117 objmgr
.LoadQuestRelations();
118 SendGlobalSysMessage("DB tables `*_questrelation` and `*_involvedrelation` reloaded.");
122 bool ChatHandler::HandleReloadAllScriptsCommand(const char*)
124 if(sWorld
.IsScriptScheduled())
126 PSendSysMessage("DB scripts used currently, please attempt reload later.");
127 SetSentErrorMessage(true);
131 sLog
.outString( "Re-Loading Scripts..." );
132 HandleReloadGameObjectScriptsCommand("a");
133 HandleReloadEventScriptsCommand("a");
134 HandleReloadQuestEndScriptsCommand("a");
135 HandleReloadQuestStartScriptsCommand("a");
136 HandleReloadSpellScriptsCommand("a");
137 SendGlobalSysMessage("DB tables `*_scripts` reloaded.");
138 HandleReloadDbScriptStringCommand("a");
142 bool ChatHandler::HandleReloadAllEventAICommand(const char*)
144 HandleReloadEventAITextsCommand("a");
145 HandleReloadEventAISummonsCommand("a");
146 HandleReloadEventAIScriptsCommand("a");
150 bool ChatHandler::HandleReloadAllSpellCommand(const char*)
152 HandleReloadSkillDiscoveryTemplateCommand("a");
153 HandleReloadSkillExtraItemTemplateCommand("a");
154 HandleReloadSpellAffectCommand("a");
155 HandleReloadSpellAreaCommand("a");
156 HandleReloadSpellChainCommand("a");
157 HandleReloadSpellElixirCommand("a");
158 HandleReloadSpellLearnSpellCommand("a");
159 HandleReloadSpellProcEventCommand("a");
160 HandleReloadSpellBonusesCommand("a");
161 HandleReloadSpellScriptTargetCommand("a");
162 HandleReloadSpellTargetPositionCommand("a");
163 HandleReloadSpellThreatsCommand("a");
164 HandleReloadSpellPetAurasCommand("a");
168 bool ChatHandler::HandleReloadAllItemCommand(const char*)
170 HandleReloadPageTextsCommand("a");
171 HandleReloadItemEnchantementsCommand("a");
172 HandleReloadItemRequiredTragetCommand("a");
176 bool ChatHandler::HandleReloadAllLocalesCommand(const char* /*args*/)
178 HandleReloadLocalesAchievementRewardCommand("a");
179 HandleReloadLocalesCreatureCommand("a");
180 HandleReloadLocalesGameobjectCommand("a");
181 HandleReloadLocalesItemCommand("a");
182 HandleReloadLocalesNpcTextCommand("a");
183 HandleReloadLocalesPageTextCommand("a");
184 HandleReloadLocalesPointsOfInterestCommand("a");
185 HandleReloadLocalesQuestCommand("a");
189 bool ChatHandler::HandleReloadConfigCommand(const char* /*args*/)
191 sLog
.outString( "Re-Loading config settings..." );
192 sWorld
.LoadConfigSettings(true);
193 SendGlobalSysMessage("World config settings reloaded.");
197 bool ChatHandler::HandleReloadAchievementCriteriaDataCommand(const char*)
199 sLog
.outString( "Re-Loading Additional Achievement Criteria Data..." );
200 achievementmgr
.LoadAchievementCriteriaData();
201 SendGlobalSysMessage("DB table `achievement_criteria_data` reloaded.");
205 bool ChatHandler::HandleReloadAchievementRewardCommand(const char*)
207 sLog
.outString( "Re-Loading Achievement Reward Data..." );
208 achievementmgr
.LoadRewards();
209 SendGlobalSysMessage("DB table `achievement_reward` reloaded.");
213 bool ChatHandler::HandleReloadAreaTriggerTavernCommand(const char*)
215 sLog
.outString( "Re-Loading Tavern Area Triggers..." );
216 objmgr
.LoadTavernAreaTriggers();
217 SendGlobalSysMessage("DB table `areatrigger_tavern` reloaded.");
221 bool ChatHandler::HandleReloadAreaTriggerTeleportCommand(const char*)
223 sLog
.outString( "Re-Loading AreaTrigger teleport definitions..." );
224 objmgr
.LoadAreaTriggerTeleports();
225 SendGlobalSysMessage("DB table `areatrigger_teleport` reloaded.");
229 bool ChatHandler::HandleReloadCommandCommand(const char*)
231 load_command_table
= true;
232 SendGlobalSysMessage("DB table `command` will be reloaded at next chat command use.");
236 bool ChatHandler::HandleReloadCreatureQuestRelationsCommand(const char*)
238 sLog
.outString( "Loading Quests Relations... (`creature_questrelation`)" );
239 objmgr
.LoadCreatureQuestRelations();
240 SendGlobalSysMessage("DB table `creature_questrelation` (creature quest givers) reloaded.");
244 bool ChatHandler::HandleReloadCreatureQuestInvRelationsCommand(const char*)
246 sLog
.outString( "Loading Quests Relations... (`creature_involvedrelation`)" );
247 objmgr
.LoadCreatureInvolvedRelations();
248 SendGlobalSysMessage("DB table `creature_involvedrelation` (creature quest takers) reloaded.");
252 bool ChatHandler::HandleReloadGOQuestRelationsCommand(const char*)
254 sLog
.outString( "Loading Quests Relations... (`gameobject_questrelation`)" );
255 objmgr
.LoadGameobjectQuestRelations();
256 SendGlobalSysMessage("DB table `gameobject_questrelation` (gameobject quest givers) reloaded.");
260 bool ChatHandler::HandleReloadGOQuestInvRelationsCommand(const char*)
262 sLog
.outString( "Loading Quests Relations... (`gameobject_involvedrelation`)" );
263 objmgr
.LoadGameobjectInvolvedRelations();
264 SendGlobalSysMessage("DB table `gameobject_involvedrelation` (gameobject quest takers) reloaded.");
268 bool ChatHandler::HandleReloadQuestAreaTriggersCommand(const char*)
270 sLog
.outString( "Re-Loading Quest Area Triggers..." );
271 objmgr
.LoadQuestAreaTriggers();
272 SendGlobalSysMessage("DB table `areatrigger_involvedrelation` (quest area triggers) reloaded.");
276 bool ChatHandler::HandleReloadQuestTemplateCommand(const char*)
278 sLog
.outString( "Re-Loading Quest Templates..." );
280 SendGlobalSysMessage("DB table `quest_template` (quest definitions) reloaded.");
282 /// dependent also from `gameobject` but this table not reloaded anyway
283 sLog
.outString( "Re-Loading GameObjects for quests..." );
284 objmgr
.LoadGameObjectForQuests();
285 SendGlobalSysMessage("Data GameObjects for quests reloaded.");
289 bool ChatHandler::HandleReloadLootTemplatesCreatureCommand(const char*)
291 sLog
.outString( "Re-Loading Loot Tables... (`creature_loot_template`)" );
292 LoadLootTemplates_Creature();
293 LootTemplates_Creature
.CheckLootRefs();
294 SendGlobalSysMessage("DB table `creature_loot_template` reloaded.");
298 bool ChatHandler::HandleReloadLootTemplatesDisenchantCommand(const char*)
300 sLog
.outString( "Re-Loading Loot Tables... (`disenchant_loot_template`)" );
301 LoadLootTemplates_Disenchant();
302 LootTemplates_Disenchant
.CheckLootRefs();
303 SendGlobalSysMessage("DB table `disenchant_loot_template` reloaded.");
307 bool ChatHandler::HandleReloadLootTemplatesFishingCommand(const char*)
309 sLog
.outString( "Re-Loading Loot Tables... (`fishing_loot_template`)" );
310 LoadLootTemplates_Fishing();
311 LootTemplates_Fishing
.CheckLootRefs();
312 SendGlobalSysMessage("DB table `fishing_loot_template` reloaded.");
316 bool ChatHandler::HandleReloadLootTemplatesGameobjectCommand(const char*)
318 sLog
.outString( "Re-Loading Loot Tables... (`gameobject_loot_template`)" );
319 LoadLootTemplates_Gameobject();
320 LootTemplates_Gameobject
.CheckLootRefs();
321 SendGlobalSysMessage("DB table `gameobject_loot_template` reloaded.");
325 bool ChatHandler::HandleReloadLootTemplatesItemCommand(const char*)
327 sLog
.outString( "Re-Loading Loot Tables... (`item_loot_template`)" );
328 LoadLootTemplates_Item();
329 LootTemplates_Item
.CheckLootRefs();
330 SendGlobalSysMessage("DB table `item_loot_template` reloaded.");
334 bool ChatHandler::HandleReloadLootTemplatesMillingCommand(const char*)
336 sLog
.outString( "Re-Loading Loot Tables... (`milling_loot_template`)" );
337 LoadLootTemplates_Milling();
338 LootTemplates_Milling
.CheckLootRefs();
339 SendGlobalSysMessage("DB table `milling_loot_template` reloaded.");
343 bool ChatHandler::HandleReloadLootTemplatesPickpocketingCommand(const char*)
345 sLog
.outString( "Re-Loading Loot Tables... (`pickpocketing_loot_template`)" );
346 LoadLootTemplates_Pickpocketing();
347 LootTemplates_Pickpocketing
.CheckLootRefs();
348 SendGlobalSysMessage("DB table `pickpocketing_loot_template` reloaded.");
352 bool ChatHandler::HandleReloadLootTemplatesProspectingCommand(const char*)
354 sLog
.outString( "Re-Loading Loot Tables... (`prospecting_loot_template`)" );
355 LoadLootTemplates_Prospecting();
356 LootTemplates_Prospecting
.CheckLootRefs();
357 SendGlobalSysMessage("DB table `prospecting_loot_template` reloaded.");
361 bool ChatHandler::HandleReloadLootTemplatesQuestMailCommand(const char*)
363 sLog
.outString( "Re-Loading Loot Tables... (`quest_mail_loot_template`)" );
364 LoadLootTemplates_QuestMail();
365 LootTemplates_QuestMail
.CheckLootRefs();
366 SendGlobalSysMessage("DB table `quest_mail_loot_template` reloaded.");
370 bool ChatHandler::HandleReloadLootTemplatesReferenceCommand(const char*)
372 sLog
.outString( "Re-Loading Loot Tables... (`reference_loot_template`)" );
373 LoadLootTemplates_Reference();
374 SendGlobalSysMessage("DB table `reference_loot_template` reloaded.");
378 bool ChatHandler::HandleReloadLootTemplatesSkinningCommand(const char*)
380 sLog
.outString( "Re-Loading Loot Tables... (`skinning_loot_template`)" );
381 LoadLootTemplates_Skinning();
382 LootTemplates_Skinning
.CheckLootRefs();
383 SendGlobalSysMessage("DB table `skinning_loot_template` reloaded.");
387 bool ChatHandler::HandleReloadLootTemplatesSpellCommand(const char*)
389 sLog
.outString( "Re-Loading Loot Tables... (`spell_loot_template`)" );
390 LoadLootTemplates_Spell();
391 LootTemplates_Spell
.CheckLootRefs();
392 SendGlobalSysMessage("DB table `spell_loot_template` reloaded.");
396 bool ChatHandler::HandleReloadMangosStringCommand(const char*)
398 sLog
.outString( "Re-Loading mangos_string Table!" );
399 objmgr
.LoadMangosStrings();
400 SendGlobalSysMessage("DB table `mangos_string` reloaded.");
404 bool ChatHandler::HandleReloadNpcOptionCommand(const char*)
406 sLog
.outString( "Re-Loading `npc_option` Table!" );
407 objmgr
.LoadNpcOptions();
408 SendGlobalSysMessage("DB table `npc_option` reloaded.");
412 bool ChatHandler::HandleReloadNpcGossipCommand(const char*)
414 sLog
.outString( "Re-Loading `npc_gossip` Table!" );
415 objmgr
.LoadNpcTextId();
416 SendGlobalSysMessage("DB table `npc_gossip` reloaded.");
420 bool ChatHandler::HandleReloadNpcTrainerCommand(const char*)
422 sLog
.outString( "Re-Loading `npc_trainer` Table!" );
423 objmgr
.LoadTrainerSpell();
424 SendGlobalSysMessage("DB table `npc_trainer` reloaded.");
428 bool ChatHandler::HandleReloadNpcVendorCommand(const char*)
430 sLog
.outString( "Re-Loading `npc_vendor` Table!" );
431 objmgr
.LoadVendors();
432 SendGlobalSysMessage("DB table `npc_vendor` reloaded.");
436 bool ChatHandler::HandleReloadPointsOfInterestCommand(const char*)
438 sLog
.outString( "Re-Loading `points_of_interest` Table!" );
439 objmgr
.LoadPointsOfInterest();
440 SendGlobalSysMessage("DB table `points_of_interest` reloaded.");
444 bool ChatHandler::HandleReloadSpellClickSpellsCommand(const char*)
446 sLog
.outString( "Re-Loading `npc_spellclick_spells` Table!" );
447 objmgr
.LoadNPCSpellClickSpells();
448 SendGlobalSysMessage("DB table `npc_spellclick_spells` reloaded.");
452 bool ChatHandler::HandleReloadReservedNameCommand(const char*)
454 sLog
.outString( "Loading ReservedNames... (`reserved_name`)" );
455 objmgr
.LoadReservedPlayersNames();
456 SendGlobalSysMessage("DB table `reserved_name` (player reserved names) reloaded.");
460 bool ChatHandler::HandleReloadSkillDiscoveryTemplateCommand(const char* /*args*/)
462 sLog
.outString( "Re-Loading Skill Discovery Table..." );
463 LoadSkillDiscoveryTable();
464 SendGlobalSysMessage("DB table `skill_discovery_template` (recipes discovered at crafting) reloaded.");
468 bool ChatHandler::HandleReloadSkillExtraItemTemplateCommand(const char* /*args*/)
470 sLog
.outString( "Re-Loading Skill Extra Item Table..." );
471 LoadSkillExtraItemTable();
472 SendGlobalSysMessage("DB table `skill_extra_item_template` (extra item creation when crafting) reloaded.");
476 bool ChatHandler::HandleReloadSkillFishingBaseLevelCommand(const char* /*args*/)
478 sLog
.outString( "Re-Loading Skill Fishing base level requirements..." );
479 objmgr
.LoadFishingBaseSkillLevel();
480 SendGlobalSysMessage("DB table `skill_fishing_base_level` (fishing base level for zone/subzone) reloaded.");
484 bool ChatHandler::HandleReloadSpellAffectCommand(const char*)
486 sLog
.outString( "Re-Loading SpellAffect definitions..." );
487 spellmgr
.LoadSpellAffects();
488 SendGlobalSysMessage("DB table `spell_affect` (spell mods apply requirements) reloaded.");
492 bool ChatHandler::HandleReloadSpellAreaCommand(const char*)
494 sLog
.outString( "Re-Loading SpellArea Data..." );
495 spellmgr
.LoadSpellAreas();
496 SendGlobalSysMessage("DB table `spell_area` (spell dependences from area/quest/auras state) reloaded.");
500 bool ChatHandler::HandleReloadSpellChainCommand(const char*)
502 sLog
.outString( "Re-Loading Spell Chain Data... " );
503 spellmgr
.LoadSpellChains();
504 SendGlobalSysMessage("DB table `spell_chain` (spell ranks) reloaded.");
508 bool ChatHandler::HandleReloadSpellElixirCommand(const char*)
510 sLog
.outString( "Re-Loading Spell Elixir types..." );
511 spellmgr
.LoadSpellElixirs();
512 SendGlobalSysMessage("DB table `spell_elixir` (spell elixir types) reloaded.");
516 bool ChatHandler::HandleReloadSpellLearnSpellCommand(const char*)
518 sLog
.outString( "Re-Loading Spell Learn Spells..." );
519 spellmgr
.LoadSpellLearnSpells();
520 SendGlobalSysMessage("DB table `spell_learn_spell` reloaded.");
524 bool ChatHandler::HandleReloadSpellProcEventCommand(const char*)
526 sLog
.outString( "Re-Loading Spell Proc Event conditions..." );
527 spellmgr
.LoadSpellProcEvents();
528 SendGlobalSysMessage("DB table `spell_proc_event` (spell proc trigger requirements) reloaded.");
532 bool ChatHandler::HandleReloadSpellBonusesCommand(const char*)
534 sLog
.outString( "Re-Loading Spell Bonus Data..." );
535 spellmgr
.LoadSpellBonusess();
536 SendGlobalSysMessage("DB table `spell_bonus_data` (spell damage/healing coefficients) reloaded.");
540 bool ChatHandler::HandleReloadSpellScriptTargetCommand(const char*)
542 sLog
.outString( "Re-Loading SpellsScriptTarget..." );
543 spellmgr
.LoadSpellScriptTarget();
544 SendGlobalSysMessage("DB table `spell_script_target` (spell targets selection in case specific creature/GO requirements) reloaded.");
548 bool ChatHandler::HandleReloadSpellTargetPositionCommand(const char*)
550 sLog
.outString( "Re-Loading Spell target coordinates..." );
551 spellmgr
.LoadSpellTargetPositions();
552 SendGlobalSysMessage("DB table `spell_target_position` (destination coordinates for spell targets) reloaded.");
556 bool ChatHandler::HandleReloadSpellThreatsCommand(const char*)
558 sLog
.outString( "Re-Loading Aggro Spells Definitions...");
559 spellmgr
.LoadSpellThreats();
560 SendGlobalSysMessage("DB table `spell_threat` (spell aggro definitions) reloaded.");
564 bool ChatHandler::HandleReloadSpellPetAurasCommand(const char*)
566 sLog
.outString( "Re-Loading Spell pet auras...");
567 spellmgr
.LoadSpellPetAuras();
568 SendGlobalSysMessage("DB table `spell_pet_auras` reloaded.");
572 bool ChatHandler::HandleReloadPageTextsCommand(const char*)
574 sLog
.outString( "Re-Loading Page Texts..." );
575 objmgr
.LoadPageTexts();
576 SendGlobalSysMessage("DB table `page_texts` reloaded.");
580 bool ChatHandler::HandleReloadItemEnchantementsCommand(const char*)
582 sLog
.outString( "Re-Loading Item Random Enchantments Table..." );
583 LoadRandomEnchantmentsTable();
584 SendGlobalSysMessage("DB table `item_enchantment_template` reloaded.");
588 bool ChatHandler::HandleReloadItemRequiredTragetCommand(const char*)
590 sLog
.outString( "Re-Loading Item Required Targets Table..." );
591 objmgr
.LoadItemRequiredTarget();
592 SendGlobalSysMessage("DB table `item_required_target` reloaded.");
596 bool ChatHandler::HandleReloadGameObjectScriptsCommand(const char* arg
)
598 if(sWorld
.IsScriptScheduled())
600 SendSysMessage("DB scripts used currently, please attempt reload later.");
601 SetSentErrorMessage(true);
606 sLog
.outString( "Re-Loading Scripts from `gameobject_scripts`...");
608 objmgr
.LoadGameObjectScripts();
611 SendGlobalSysMessage("DB table `gameobject_scripts` reloaded.");
616 bool ChatHandler::HandleReloadEventScriptsCommand(const char* arg
)
618 if(sWorld
.IsScriptScheduled())
620 SendSysMessage("DB scripts used currently, please attempt reload later.");
621 SetSentErrorMessage(true);
626 sLog
.outString( "Re-Loading Scripts from `event_scripts`...");
628 objmgr
.LoadEventScripts();
631 SendGlobalSysMessage("DB table `event_scripts` reloaded.");
636 bool ChatHandler::HandleReloadEventAITextsCommand(const char* arg
)
639 sLog
.outString( "Re-Loading Texts from `creature_ai_texts`...");
640 CreatureEAI_Mgr
.LoadCreatureEventAI_Texts();
641 SendGlobalSysMessage("DB table `creature_ai_texts` reloaded.");
645 bool ChatHandler::HandleReloadEventAISummonsCommand(const char* arg
)
647 sLog
.outString( "Re-Loading Summons from `creature_ai_summons`...");
648 CreatureEAI_Mgr
.LoadCreatureEventAI_Summons();
649 SendGlobalSysMessage("DB table `creature_ai_summons` reloaded.");
653 bool ChatHandler::HandleReloadEventAIScriptsCommand(const char* arg
)
655 sLog
.outString( "Re-Loading Scripts from `creature_ai_scripts`...");
656 CreatureEAI_Mgr
.LoadCreatureEventAI_Scripts();
657 SendGlobalSysMessage("DB table `creature_ai_scripts` reloaded.");
661 bool ChatHandler::HandleReloadQuestEndScriptsCommand(const char* arg
)
663 if(sWorld
.IsScriptScheduled())
665 SendSysMessage("DB scripts used currently, please attempt reload later.");
666 SetSentErrorMessage(true);
671 sLog
.outString( "Re-Loading Scripts from `quest_end_scripts`...");
673 objmgr
.LoadQuestEndScripts();
676 SendGlobalSysMessage("DB table `quest_end_scripts` reloaded.");
681 bool ChatHandler::HandleReloadQuestStartScriptsCommand(const char* arg
)
683 if(sWorld
.IsScriptScheduled())
685 SendSysMessage("DB scripts used currently, please attempt reload later.");
686 SetSentErrorMessage(true);
691 sLog
.outString( "Re-Loading Scripts from `quest_start_scripts`...");
693 objmgr
.LoadQuestStartScripts();
696 SendGlobalSysMessage("DB table `quest_start_scripts` reloaded.");
701 bool ChatHandler::HandleReloadSpellScriptsCommand(const char* arg
)
703 if(sWorld
.IsScriptScheduled())
705 SendSysMessage("DB scripts used currently, please attempt reload later.");
706 SetSentErrorMessage(true);
711 sLog
.outString( "Re-Loading Scripts from `spell_scripts`...");
713 objmgr
.LoadSpellScripts();
716 SendGlobalSysMessage("DB table `spell_scripts` reloaded.");
721 bool ChatHandler::HandleReloadDbScriptStringCommand(const char* /*arg*/)
723 sLog
.outString( "Re-Loading Script strings from `db_script_string`...");
724 objmgr
.LoadDbScriptStrings();
725 SendGlobalSysMessage("DB table `db_script_string` reloaded.");
729 bool ChatHandler::HandleReloadGameGraveyardZoneCommand(const char* /*arg*/)
731 sLog
.outString( "Re-Loading Graveyard-zone links...");
733 objmgr
.LoadGraveyardZones();
735 SendGlobalSysMessage("DB table `game_graveyard_zone` reloaded.");
740 bool ChatHandler::HandleReloadGameTeleCommand(const char* /*arg*/)
742 sLog
.outString( "Re-Loading Game Tele coordinates...");
744 objmgr
.LoadGameTele();
746 SendGlobalSysMessage("DB table `game_tele` reloaded.");
751 bool ChatHandler::HandleReloadLocalesAchievementRewardCommand(const char*)
753 sLog
.outString( "Re-Loading Locales Achievement Reward Data..." );
754 achievementmgr
.LoadRewardLocales();
755 SendGlobalSysMessage("DB table `locales_achievement_reward` reloaded.");
759 bool ChatHandler::HandleReloadLocalesCreatureCommand(const char* /*arg*/)
761 sLog
.outString( "Re-Loading Locales Creature ...");
762 objmgr
.LoadCreatureLocales();
763 SendGlobalSysMessage("DB table `locales_creature` reloaded.");
767 bool ChatHandler::HandleReloadLocalesGameobjectCommand(const char* /*arg*/)
769 sLog
.outString( "Re-Loading Locales Gameobject ... ");
770 objmgr
.LoadGameObjectLocales();
771 SendGlobalSysMessage("DB table `locales_gameobject` reloaded.");
775 bool ChatHandler::HandleReloadLocalesItemCommand(const char* /*arg*/)
777 sLog
.outString( "Re-Loading Locales Item ... ");
778 objmgr
.LoadItemLocales();
779 SendGlobalSysMessage("DB table `locales_item` reloaded.");
783 bool ChatHandler::HandleReloadLocalesNpcTextCommand(const char* /*arg*/)
785 sLog
.outString( "Re-Loading Locales NPC Text ... ");
786 objmgr
.LoadNpcTextLocales();
787 SendGlobalSysMessage("DB table `locales_npc_text` reloaded.");
791 bool ChatHandler::HandleReloadLocalesPageTextCommand(const char* /*arg*/)
793 sLog
.outString( "Re-Loading Locales Page Text ... ");
794 objmgr
.LoadPageTextLocales();
795 SendGlobalSysMessage("DB table `locales_page_text` reloaded.");
799 bool ChatHandler::HandleReloadLocalesPointsOfInterestCommand(const char* /*arg*/)
801 sLog
.outString( "Re-Loading Locales Points Of Interest ... ");
802 objmgr
.LoadPointOfInterestLocales();
803 SendGlobalSysMessage("DB table `locales_points_of_interest` reloaded.");
807 bool ChatHandler::HandleReloadLocalesQuestCommand(const char* /*arg*/)
809 sLog
.outString( "Re-Loading Locales Quest ... ");
810 objmgr
.LoadQuestLocales();
811 SendGlobalSysMessage("DB table `locales_quest` reloaded.");
815 bool ChatHandler::HandleLoadScriptsCommand(const char* args
)
817 if(!LoadScriptingModule(args
)) return true;
819 sWorld
.SendWorldText(LANG_SCRIPTS_RELOADED
);
823 bool ChatHandler::HandleAccountSetGmLevelCommand(const char* args
)
825 char* arg1
= strtok((char*)args
, " ");
829 /// must be NULL if targeted syntax and must be not nULL if not targeted
830 char* arg2
= strtok(NULL
, " ");
832 std::string targetAccountName
;
833 uint32 targetAccountId
= 0;
835 /// only target player different from self allowed (if targetPlayer!=NULL then not console)
836 Player
* targetPlayer
= getSelectedPlayer();
837 if(targetPlayer
&& m_session
->GetPlayer()!=targetPlayer
)
839 /// wrong command syntax or unexpected targeting
843 /// security level expected in arg2 after this if.
846 targetAccountId
= targetPlayer
->GetSession()->GetAccountId();
847 accmgr
.GetName(targetAccountId
, targetAccountName
);
851 /// wrong command syntax (second arg expected)
855 targetAccountName
= arg1
;
856 if(!AccountMgr::normilizeString(targetAccountName
))
858 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,targetAccountName
.c_str());
859 SetSentErrorMessage(true);
863 targetAccountId
= accmgr
.GetId(targetAccountName
);
866 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,targetAccountName
.c_str());
867 SetSentErrorMessage(true);
872 int32 gm
= (int32
)atoi(arg2
);
873 if ( gm
< SEC_PLAYER
|| gm
> SEC_ADMINISTRATOR
)
875 SendSysMessage(LANG_BAD_VALUE
);
876 SetSentErrorMessage(true);
880 /// can set security level only for target with less security and to less security that we have
881 /// This will reject self apply by specify account name
882 if(HasLowerSecurityAccount(NULL
,targetAccountId
,true))
885 /// account can't set security to same or grater level, need more power GM or console
886 AccountTypes plSecurity
= m_session
? m_session
->GetSecurity() : SEC_CONSOLE
;
887 if (AccountTypes(gm
) >= plSecurity
)
889 SendSysMessage(LANG_YOURS_SECURITY_IS_LOW
);
890 SetSentErrorMessage(true);
894 // This will prevent self apply by self target or no target
895 if(targetPlayer
&& m_session
->GetPlayer()!=targetPlayer
)
897 ChatHandler(targetPlayer
).PSendSysMessage(LANG_YOURS_SECURITY_CHANGED
,GetNameLink().c_str(), gm
);
898 targetPlayer
->GetSession()->SetSecurity(AccountTypes(gm
));
901 PSendSysMessage(LANG_YOU_CHANGE_SECURITY
, targetAccountName
.c_str(), gm
);
902 loginDatabase
.PExecute("UPDATE account SET gmlevel = '%i' WHERE id = '%u'", gm
, targetAccountId
);
907 /// Set password for account
908 bool ChatHandler::HandleAccountSetPasswordCommand(const char* args
)
913 ///- Get the command line arguments
914 char *szAccount
= strtok ((char*)args
," ");
915 char *szPassword1
= strtok (NULL
," ");
916 char *szPassword2
= strtok (NULL
," ");
918 if (!szAccount
||!szPassword1
|| !szPassword2
)
921 std::string account_name
= szAccount
;
922 if(!AccountMgr::normilizeString(account_name
))
924 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
925 SetSentErrorMessage(true);
929 uint32 targetAccountId
= accmgr
.GetId(account_name
);
930 if (!targetAccountId
)
932 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
933 SetSentErrorMessage(true);
937 /// can set password only for target with less security
938 /// This is also reject self apply in fact
939 if(HasLowerSecurityAccount (NULL
,targetAccountId
,true))
942 if (strcmp(szPassword1
,szPassword2
))
944 SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH
);
945 SetSentErrorMessage (true);
949 AccountOpResult result
= accmgr
.ChangePassword(targetAccountId
, szPassword1
);
954 SendSysMessage(LANG_COMMAND_PASSWORD
);
956 case AOR_NAME_NOT_EXIST
:
957 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
958 SetSentErrorMessage(true);
960 case AOR_PASS_TOO_LONG
:
961 SendSysMessage(LANG_PASSWORD_TOO_LONG
);
962 SetSentErrorMessage(true);
965 SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD
);
966 SetSentErrorMessage(true);
973 bool ChatHandler::HandleMaxSkillCommand(const char* /*args*/)
975 Player
* SelectedPlayer
= getSelectedPlayer();
978 SendSysMessage(LANG_NO_CHAR_SELECTED
);
979 SetSentErrorMessage(true);
983 // each skills that have max skill value dependent from level seted to current level max skill value
984 SelectedPlayer
->UpdateSkillsToMaxSkillsForLevel();
988 bool ChatHandler::HandleSetSkillCommand(const char* args
)
990 // number or [name] Shift-click form |color|Hskill:skill_id|h[name]|h|r
991 char* skill_p
= extractKeyFromLink((char*)args
,"Hskill");
995 char *level_p
= strtok (NULL
, " ");
1000 char *max_p
= strtok (NULL
, " ");
1002 int32 skill
= atoi(skill_p
);
1005 PSendSysMessage(LANG_INVALID_SKILL_ID
, skill
);
1006 SetSentErrorMessage(true);
1010 int32 level
= atol (level_p
);
1012 Player
* target
= getSelectedPlayer();
1015 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1016 SetSentErrorMessage(true);
1020 SkillLineEntry
const* sl
= sSkillLineStore
.LookupEntry(skill
);
1023 PSendSysMessage(LANG_INVALID_SKILL_ID
, skill
);
1024 SetSentErrorMessage(true);
1028 std::string tNameLink
= GetNameLink(target
);
1030 if(!target
->GetSkillValue(skill
))
1032 PSendSysMessage(LANG_SET_SKILL_ERROR
, tNameLink
.c_str(), skill
, sl
->name
[0]);
1033 SetSentErrorMessage(true);
1037 int32 max
= max_p
? atol (max_p
) : target
->GetPureMaxSkillValue(skill
);
1039 if( level
<= 0 || level
> max
|| max
<= 0 )
1042 target
->SetSkill(skill
, level
, max
);
1043 PSendSysMessage(LANG_SET_SKILL
, skill
, sl
->name
[0], tNameLink
.c_str(), level
, max
);
1048 bool ChatHandler::HandleUnLearnCommand(const char* args
)
1053 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
1054 uint32 spell_id
= extractSpellIdFromLink((char*)args
);
1058 char const* allStr
= strtok(NULL
," ");
1059 bool allRanks
= allStr
? (strncmp(allStr
, "all", strlen(allStr
)) == 0) : false;
1061 Player
* target
= getSelectedPlayer();
1064 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1065 SetSentErrorMessage(true);
1070 spell_id
= spellmgr
.GetFirstSpellInChain (spell_id
);
1072 if (target
->HasSpell(spell_id
))
1073 target
->removeSpell(spell_id
,false,!allRanks
);
1075 SendSysMessage(LANG_FORGET_SPELL
);
1080 bool ChatHandler::HandleCooldownCommand(const char* args
)
1082 Player
* target
= getSelectedPlayer();
1085 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1086 SetSentErrorMessage(true);
1090 std::string tNameLink
= GetNameLink(target
);
1094 target
->RemoveAllSpellCooldown();
1095 PSendSysMessage(LANG_REMOVEALL_COOLDOWN
, tNameLink
.c_str());
1099 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1100 uint32 spell_id
= extractSpellIdFromLink((char*)args
);
1104 if(!sSpellStore
.LookupEntry(spell_id
))
1106 PSendSysMessage(LANG_UNKNOWN_SPELL
, target
==m_session
->GetPlayer() ? GetMangosString(LANG_YOU
) : tNameLink
.c_str());
1107 SetSentErrorMessage(true);
1111 target
->RemoveSpellCooldown(spell_id
,true);
1112 PSendSysMessage(LANG_REMOVE_COOLDOWN
, spell_id
, target
==m_session
->GetPlayer() ? GetMangosString(LANG_YOU
) : tNameLink
.c_str());
1117 bool ChatHandler::HandleLearnAllCommand(const char* /*args*/)
1119 static const char *allSpellList
[] =
1502 //"9036", problems with ghost state
1511 //"6718", phasing stealth, annoying for learn all case.
1724 while(strcmp(allSpellList
[loop
], "0"))
1726 uint32 spell
= atol((char*)allSpellList
[loop
++]);
1728 if (m_session
->GetPlayer()->HasSpell(spell
))
1731 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1732 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1734 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1738 m_session
->GetPlayer()->learnSpell(spell
,false);
1741 SendSysMessage(LANG_COMMAND_LEARN_MANY_SPELLS
);
1746 bool ChatHandler::HandleLearnAllGMCommand(const char* /*args*/)
1748 static const char *gmSpellList
[] =
1750 "24347", // Become A Fish, No Breath Bar
1751 "35132", // Visual Boom
1752 "38488", // Attack 4000-8000 AOE
1753 "38795", // Attack 2000 AOE + Slow Down 90%
1754 "15712", // Attack 200
1755 "1852", // GM Spell Silence
1758 "29878", // Kill My Self
1759 "26644", // More Kill
1761 "28550", //Invisible 24
1762 "23452", //Invisible + Target
1766 uint16 gmSpellIter
= 0;
1767 while( strcmp(gmSpellList
[gmSpellIter
], "0") )
1769 uint32 spell
= atol((char*)gmSpellList
[gmSpellIter
++]);
1771 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1772 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1774 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1778 m_session
->GetPlayer()->learnSpell(spell
,false);
1781 SendSysMessage(LANG_LEARNING_GM_SKILLS
);
1785 bool ChatHandler::HandleLearnAllMyClassCommand(const char* /*args*/)
1787 HandleLearnAllMySpellsCommand("");
1788 HandleLearnAllMyTalentsCommand("");
1792 bool ChatHandler::HandleLearnAllMySpellsCommand(const char* /*args*/)
1794 ChrClassesEntry
const* clsEntry
= sChrClassesStore
.LookupEntry(m_session
->GetPlayer()->getClass());
1797 uint32 family
= clsEntry
->spellfamily
;
1799 for (uint32 i
= 0; i
< sSpellStore
.GetNumRows(); ++i
)
1801 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(i
);
1805 // skip server-side/triggered spells
1806 if(spellInfo
->spellLevel
==0)
1809 // skip wrong class/race skills
1810 if(!m_session
->GetPlayer()->IsSpellFitByClassAndRace(spellInfo
->Id
))
1813 // skip other spell families
1814 if( spellInfo
->SpellFamilyName
!= family
)
1817 // skip spells with first rank learned as talent (and all talents then also)
1818 uint32 first_rank
= spellmgr
.GetFirstSpellInChain(spellInfo
->Id
);
1819 if(GetTalentSpellCost(first_rank
) > 0 )
1822 // skip broken spells
1823 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1826 m_session
->GetPlayer()->learnSpell(i
,false);
1829 SendSysMessage(LANG_COMMAND_LEARN_CLASS_SPELLS
);
1833 bool ChatHandler::HandleLearnAllMyTalentsCommand(const char* /*args*/)
1835 Player
* player
= m_session
->GetPlayer();
1836 uint32 classMask
= player
->getClassMask();
1838 for (uint32 i
= 0; i
< sTalentStore
.GetNumRows(); ++i
)
1840 TalentEntry
const *talentInfo
= sTalentStore
.LookupEntry(i
);
1844 TalentTabEntry
const *talentTabInfo
= sTalentTabStore
.LookupEntry( talentInfo
->TalentTab
);
1848 if( (classMask
& talentTabInfo
->ClassMask
) == 0 )
1851 // search highest talent rank
1854 for(int rank
= MAX_TALENT_RANK
-1; rank
>= 0; --rank
)
1856 if(talentInfo
->RankID
[rank
]!=0)
1858 spellid
= talentInfo
->RankID
[rank
];
1863 if(!spellid
) // ??? none spells in talent
1866 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spellid
);
1867 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1870 // learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
1871 player
->learnSpellHighRank(spellid
);
1874 SendSysMessage(LANG_COMMAND_LEARN_CLASS_TALENTS
);
1878 bool ChatHandler::HandleLearnAllMyPetTalentsCommand(const char* /*args*/)
1880 Player
* player
= m_session
->GetPlayer();
1882 Pet
* pet
= player
->GetPet();
1885 SendSysMessage(LANG_NO_PET_FOUND
);
1886 SetSentErrorMessage(true);
1890 CreatureInfo
const *ci
= pet
->GetCreatureInfo();
1893 SendSysMessage(LANG_WRONG_PET_TYPE
);
1894 SetSentErrorMessage(true);
1898 CreatureFamilyEntry
const *pet_family
= sCreatureFamilyStore
.LookupEntry(ci
->family
);
1901 SendSysMessage(LANG_WRONG_PET_TYPE
);
1902 SetSentErrorMessage(true);
1906 if(pet_family
->petTalentType
< 0) // not hunter pet
1908 SendSysMessage(LANG_WRONG_PET_TYPE
);
1909 SetSentErrorMessage(true);
1913 for (uint32 i
= 0; i
< sTalentStore
.GetNumRows(); ++i
)
1915 TalentEntry
const *talentInfo
= sTalentStore
.LookupEntry(i
);
1919 TalentTabEntry
const *talentTabInfo
= sTalentTabStore
.LookupEntry( talentInfo
->TalentTab
);
1923 // prevent learn talent for different family (cheating)
1924 if(((1 << pet_family
->petTalentType
) & talentTabInfo
->petTalentMask
)==0)
1927 // search highest talent rank
1930 for(int rank
= MAX_TALENT_RANK
-1; rank
>= 0; --rank
)
1932 if(talentInfo
->RankID
[rank
]!=0)
1934 spellid
= talentInfo
->RankID
[rank
];
1939 if(!spellid
) // ??? none spells in talent
1942 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spellid
);
1943 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1946 // learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
1947 pet
->learnSpellHighRank(spellid
);
1950 SendSysMessage(LANG_COMMAND_LEARN_PET_TALENTS
);
1954 bool ChatHandler::HandleLearnAllLangCommand(const char* /*args*/)
1956 // skipping UNIVERSAL language (0)
1957 for(int i
= 1; i
< LANGUAGES_COUNT
; ++i
)
1958 m_session
->GetPlayer()->learnSpell(lang_description
[i
].spell_id
,false);
1960 SendSysMessage(LANG_COMMAND_LEARN_ALL_LANG
);
1964 bool ChatHandler::HandleLearnAllDefaultCommand(const char* args
)
1967 if(!extractPlayerTarget((char*)args
,&target
))
1970 target
->learnDefaultSpells();
1971 target
->learnQuestRewardedSpells();
1973 PSendSysMessage(LANG_COMMAND_LEARN_ALL_DEFAULT_AND_QUEST
,GetNameLink(target
).c_str());
1977 bool ChatHandler::HandleLearnCommand(const char* args
)
1979 Player
* targetPlayer
= getSelectedPlayer();
1983 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1984 SetSentErrorMessage(true);
1988 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1989 uint32 spell
= extractSpellIdFromLink((char*)args
);
1990 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
1993 char const* allStr
= strtok(NULL
," ");
1994 bool allRanks
= allStr
? (strncmp(allStr
, "all", strlen(allStr
)) == 0) : false;
1996 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1997 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1999 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
2000 SetSentErrorMessage(true);
2004 if (!allRanks
&& targetPlayer
->HasSpell(spell
))
2006 if(targetPlayer
== m_session
->GetPlayer())
2007 SendSysMessage(LANG_YOU_KNOWN_SPELL
);
2009 PSendSysMessage(LANG_TARGET_KNOWN_SPELL
,GetNameLink(targetPlayer
).c_str());
2010 SetSentErrorMessage(true);
2015 targetPlayer
->learnSpellHighRank(spell
);
2017 targetPlayer
->learnSpell(spell
,false);
2022 bool ChatHandler::HandleAddItemCommand(const char* args
)
2029 if(args
[0]=='[') // [name] manual form
2031 char* citemName
= strtok((char*)args
, "]");
2033 if(citemName
&& citemName
[0])
2035 std::string itemName
= citemName
+1;
2036 WorldDatabase
.escape_string(itemName
);
2037 QueryResult
*result
= WorldDatabase
.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName
.c_str());
2040 PSendSysMessage(LANG_COMMAND_COULDNOTFIND
, citemName
+1);
2041 SetSentErrorMessage(true);
2044 itemId
= result
->Fetch()->GetUInt16();
2050 else // item_id or [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r
2052 char* cId
= extractKeyFromLink((char*)args
,"Hitem");
2058 char* ccount
= strtok(NULL
, " ");
2063 count
= strtol(ccount
, NULL
, 10);
2068 Player
* pl
= m_session
->GetPlayer();
2069 Player
* plTarget
= getSelectedPlayer();
2073 sLog
.outDetail(GetMangosString(LANG_ADDITEM
), itemId
, count
);
2075 ItemPrototype
const *pProto
= objmgr
.GetItemPrototype(itemId
);
2078 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, itemId
);
2079 SetSentErrorMessage(true);
2086 plTarget
->DestroyItemCount(itemId
, -count
, true, false);
2087 PSendSysMessage(LANG_REMOVEITEM
, itemId
, -count
, GetNameLink(plTarget
).c_str());
2092 uint32 noSpaceForCount
= 0;
2094 // check space and find places
2095 ItemPosCountVec dest
;
2096 uint8 msg
= plTarget
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, itemId
, count
, &noSpaceForCount
);
2097 if( msg
!= EQUIP_ERR_OK
) // convert to possible store amount
2098 count
-= noSpaceForCount
;
2100 if( count
== 0 || dest
.empty()) // can't add any
2102 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, itemId
, noSpaceForCount
);
2103 SetSentErrorMessage(true);
2107 Item
* item
= plTarget
->StoreNewItem( dest
, itemId
, true, Item::GenerateItemRandomPropertyId(itemId
));
2109 // remove binding (let GM give it to another player later)
2111 for(ItemPosCountVec::const_iterator itr
= dest
.begin(); itr
!= dest
.end(); ++itr
)
2112 if(Item
* item1
= pl
->GetItemByPos(itr
->pos
))
2113 item1
->SetBinding( false );
2115 if(count
> 0 && item
)
2117 pl
->SendNewItem(item
,count
,false,true);
2119 plTarget
->SendNewItem(item
,count
,true,false);
2122 if(noSpaceForCount
> 0)
2123 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, itemId
, noSpaceForCount
);
2128 bool ChatHandler::HandleAddItemSetCommand(const char* args
)
2133 char* cId
= extractKeyFromLink((char*)args
,"Hitemset"); // number or [name] Shift-click form |color|Hitemset:itemset_id|h[name]|h|r
2137 uint32 itemsetId
= atol(cId
);
2139 // prevent generation all items with itemset field value '0'
2142 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND
,itemsetId
);
2143 SetSentErrorMessage(true);
2147 Player
* pl
= m_session
->GetPlayer();
2148 Player
* plTarget
= getSelectedPlayer();
2152 sLog
.outDetail(GetMangosString(LANG_ADDITEMSET
), itemsetId
);
2155 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
2157 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
2161 if (pProto
->ItemSet
== itemsetId
)
2164 ItemPosCountVec dest
;
2165 uint8 msg
= plTarget
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, pProto
->ItemId
, 1 );
2166 if (msg
== EQUIP_ERR_OK
)
2168 Item
* item
= plTarget
->StoreNewItem( dest
, pProto
->ItemId
, true);
2170 // remove binding (let GM give it to another player later)
2172 item
->SetBinding( false );
2174 pl
->SendNewItem(item
,1,false,true);
2176 plTarget
->SendNewItem(item
,1,true,false);
2180 pl
->SendEquipError( msg
, NULL
, NULL
);
2181 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, pProto
->ItemId
, 1);
2188 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND
,itemsetId
);
2190 SetSentErrorMessage(true);
2197 bool ChatHandler::HandleListItemCommand(const char* args
)
2202 char* cId
= extractKeyFromLink((char*)args
,"Hitem");
2206 uint32 item_id
= atol(cId
);
2209 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
2210 SetSentErrorMessage(true);
2214 ItemPrototype
const* itemProto
= objmgr
.GetItemPrototype(item_id
);
2217 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
2218 SetSentErrorMessage(true);
2222 char* c_count
= strtok(NULL
, " ");
2223 int count
= c_count
? atol(c_count
) : 10;
2228 QueryResult
*result
;
2231 uint32 inv_count
= 0;
2232 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM character_inventory WHERE item_template='%u'",item_id
);
2235 inv_count
= (*result
)[0].GetUInt32();
2239 result
=CharacterDatabase
.PQuery(
2241 "SELECT ci.item, cibag.slot AS bag, ci.slot, ci.guid, characters.account,characters.name "
2242 "FROM character_inventory AS ci LEFT JOIN character_inventory AS cibag ON (cibag.item=ci.bag),characters "
2243 "WHERE ci.item_template='%u' AND ci.guid = characters.guid LIMIT %u ",
2244 item_id
,uint32(count
));
2250 Field
*fields
= result
->Fetch();
2251 uint32 item_guid
= fields
[0].GetUInt32();
2252 uint32 item_bag
= fields
[1].GetUInt32();
2253 uint32 item_slot
= fields
[2].GetUInt32();
2254 uint32 owner_guid
= fields
[3].GetUInt32();
2255 uint32 owner_acc
= fields
[4].GetUInt32();
2256 std::string owner_name
= fields
[5].GetCppString();
2258 char const* item_pos
= 0;
2259 if(Player::IsEquipmentPos(item_bag
,item_slot
))
2260 item_pos
= "[equipped]";
2261 else if(Player::IsInventoryPos(item_bag
,item_slot
))
2262 item_pos
= "[in inventory]";
2263 else if(Player::IsBankPos(item_bag
,item_slot
))
2264 item_pos
= "[in bank]";
2268 PSendSysMessage(LANG_ITEMLIST_SLOT
,
2269 item_guid
,owner_name
.c_str(),owner_guid
,owner_acc
,item_pos
);
2270 } while (result
->NextRow());
2272 int64 res_count
= result
->GetRowCount();
2276 if(count
> res_count
)
2283 uint32 mail_count
= 0;
2284 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM mail_items WHERE item_template='%u'", item_id
);
2287 mail_count
= (*result
)[0].GetUInt32();
2293 result
=CharacterDatabase
.PQuery(
2295 "SELECT mail_items.item_guid, mail.sender, mail.receiver, char_s.account, char_s.name, char_r.account, char_r.name "
2296 "FROM mail,mail_items,characters as char_s,characters as char_r "
2297 "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",
2298 item_id
,uint32(count
));
2307 Field
*fields
= result
->Fetch();
2308 uint32 item_guid
= fields
[0].GetUInt32();
2309 uint32 item_s
= fields
[1].GetUInt32();
2310 uint32 item_r
= fields
[2].GetUInt32();
2311 uint32 item_s_acc
= fields
[3].GetUInt32();
2312 std::string item_s_name
= fields
[4].GetCppString();
2313 uint32 item_r_acc
= fields
[5].GetUInt32();
2314 std::string item_r_name
= fields
[6].GetCppString();
2316 char const* item_pos
= "[in mail]";
2318 PSendSysMessage(LANG_ITEMLIST_MAIL
,
2319 item_guid
,item_s_name
.c_str(),item_s
,item_s_acc
,item_r_name
.c_str(),item_r
,item_r_acc
,item_pos
);
2320 } while (result
->NextRow());
2322 int64 res_count
= result
->GetRowCount();
2326 if(count
> res_count
)
2333 uint32 auc_count
= 0;
2334 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM auctionhouse WHERE item_template='%u'",item_id
);
2337 auc_count
= (*result
)[0].GetUInt32();
2343 result
=CharacterDatabase
.PQuery(
2345 "SELECT auctionhouse.itemguid, auctionhouse.itemowner, characters.account, characters.name "
2346 "FROM auctionhouse,characters WHERE auctionhouse.item_template='%u' AND characters.guid = auctionhouse.itemowner LIMIT %u",
2347 item_id
,uint32(count
));
2356 Field
*fields
= result
->Fetch();
2357 uint32 item_guid
= fields
[0].GetUInt32();
2358 uint32 owner
= fields
[1].GetUInt32();
2359 uint32 owner_acc
= fields
[2].GetUInt32();
2360 std::string owner_name
= fields
[3].GetCppString();
2362 char const* item_pos
= "[in auction]";
2364 PSendSysMessage(LANG_ITEMLIST_AUCTION
, item_guid
, owner_name
.c_str(), owner
, owner_acc
,item_pos
);
2365 } while (result
->NextRow());
2371 uint32 guild_count
= 0;
2372 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_entry) FROM guild_bank_item WHERE item_entry='%u'",item_id
);
2375 guild_count
= (*result
)[0].GetUInt32();
2379 result
=CharacterDatabase
.PQuery(
2381 "SELECT gi.item_guid, gi.guildid, guild.name "
2382 "FROM guild_bank_item AS gi, guild WHERE gi.item_entry='%u' AND gi.guildid = guild.guildid LIMIT %u ",
2383 item_id
,uint32(count
));
2389 Field
*fields
= result
->Fetch();
2390 uint32 item_guid
= fields
[0].GetUInt32();
2391 uint32 guild_guid
= fields
[1].GetUInt32();
2392 std::string guild_name
= fields
[2].GetCppString();
2394 char const* item_pos
= "[in guild bank]";
2396 PSendSysMessage(LANG_ITEMLIST_GUILD
,item_guid
,guild_name
.c_str(),guild_guid
,item_pos
);
2397 } while (result
->NextRow());
2399 int64 res_count
= result
->GetRowCount();
2403 if(count
> res_count
)
2409 if(inv_count
+mail_count
+auc_count
+guild_count
== 0)
2411 SendSysMessage(LANG_COMMAND_NOITEMFOUND
);
2412 SetSentErrorMessage(true);
2416 PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE
,item_id
,inv_count
+mail_count
+auc_count
+guild_count
,inv_count
,mail_count
,auc_count
,guild_count
);
2421 bool ChatHandler::HandleListObjectCommand(const char* args
)
2426 // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2427 char* cId
= extractKeyFromLink((char*)args
,"Hgameobject_entry");
2431 uint32 go_id
= atol(cId
);
2434 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID
, go_id
);
2435 SetSentErrorMessage(true);
2439 GameObjectInfo
const * gInfo
= objmgr
.GetGameObjectInfo(go_id
);
2442 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID
, go_id
);
2443 SetSentErrorMessage(true);
2447 char* c_count
= strtok(NULL
, " ");
2448 int count
= c_count
? atol(c_count
) : 10;
2453 QueryResult
*result
;
2455 uint32 obj_count
= 0;
2456 result
=WorldDatabase
.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'",go_id
);
2459 obj_count
= (*result
)[0].GetUInt32();
2465 Player
* pl
= m_session
->GetPlayer();
2466 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",
2467 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(),go_id
,uint32(count
));
2470 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map FROM gameobject WHERE id = '%u' LIMIT %u",
2471 go_id
,uint32(count
));
2477 Field
*fields
= result
->Fetch();
2478 uint32 guid
= fields
[0].GetUInt32();
2479 float x
= fields
[1].GetFloat();
2480 float y
= fields
[2].GetFloat();
2481 float z
= fields
[3].GetFloat();
2482 int mapid
= fields
[4].GetUInt16();
2485 PSendSysMessage(LANG_GO_LIST_CHAT
, guid
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2487 PSendSysMessage(LANG_GO_LIST_CONSOLE
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2488 } while (result
->NextRow());
2493 PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE
,go_id
,obj_count
);
2497 bool ChatHandler::HandleListCreatureCommand(const char* args
)
2502 // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
2503 char* cId
= extractKeyFromLink((char*)args
,"Hcreature_entry");
2507 uint32 cr_id
= atol(cId
);
2510 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID
, cr_id
);
2511 SetSentErrorMessage(true);
2515 CreatureInfo
const* cInfo
= objmgr
.GetCreatureTemplate(cr_id
);
2518 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID
, cr_id
);
2519 SetSentErrorMessage(true);
2523 char* c_count
= strtok(NULL
, " ");
2524 int count
= c_count
? atol(c_count
) : 10;
2529 QueryResult
*result
;
2531 uint32 cr_count
= 0;
2532 result
=WorldDatabase
.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'",cr_id
);
2535 cr_count
= (*result
)[0].GetUInt32();
2541 Player
* pl
= m_session
->GetPlayer();
2542 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",
2543 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(), cr_id
,uint32(count
));
2546 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '%u' LIMIT %u",
2547 cr_id
,uint32(count
));
2553 Field
*fields
= result
->Fetch();
2554 uint32 guid
= fields
[0].GetUInt32();
2555 float x
= fields
[1].GetFloat();
2556 float y
= fields
[2].GetFloat();
2557 float z
= fields
[3].GetFloat();
2558 int mapid
= fields
[4].GetUInt16();
2561 PSendSysMessage(LANG_CREATURE_LIST_CHAT
, guid
, guid
, cInfo
->Name
, x
, y
, z
, mapid
);
2563 PSendSysMessage(LANG_CREATURE_LIST_CONSOLE
, guid
, cInfo
->Name
, x
, y
, z
, mapid
);
2564 } while (result
->NextRow());
2569 PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE
,cr_id
,cr_count
);
2573 bool ChatHandler::HandleLookupItemCommand(const char* args
)
2578 std::string namepart
= args
;
2579 std::wstring wnamepart
;
2581 // converting string that we try to find to lower case
2582 if(!Utf8toWStr(namepart
,wnamepart
))
2585 wstrToLower(wnamepart
);
2589 // Search in `item_template`
2590 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
2592 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
2596 int loc_idx
= GetSessionDbLocaleIndex();
2599 ItemLocale
const *il
= objmgr
.GetItemLocale(pProto
->ItemId
);
2602 if (il
->Name
.size() > loc_idx
&& !il
->Name
[loc_idx
].empty())
2604 std::string name
= il
->Name
[loc_idx
];
2606 if (Utf8FitTo(name
, wnamepart
))
2609 PSendSysMessage(LANG_ITEM_LIST_CHAT
, id
, id
, name
.c_str());
2611 PSendSysMessage(LANG_ITEM_LIST_CONSOLE
, id
, name
.c_str());
2619 std::string name
= pProto
->Name1
;
2623 if (Utf8FitTo(name
, wnamepart
))
2626 PSendSysMessage(LANG_ITEM_LIST_CHAT
, id
, id
, name
.c_str());
2628 PSendSysMessage(LANG_ITEM_LIST_CONSOLE
, id
, name
.c_str());
2634 SendSysMessage(LANG_COMMAND_NOITEMFOUND
);
2639 bool ChatHandler::HandleLookupItemSetCommand(const char* args
)
2644 std::string namepart
= args
;
2645 std::wstring wnamepart
;
2647 if(!Utf8toWStr(namepart
,wnamepart
))
2650 // converting string that we try to find to lower case
2651 wstrToLower( wnamepart
);
2653 uint32 counter
= 0; // Counter for figure out that we found smth.
2655 // Search in ItemSet.dbc
2656 for (uint32 id
= 0; id
< sItemSetStore
.GetNumRows(); id
++)
2658 ItemSetEntry
const *set
= sItemSetStore
.LookupEntry(id
);
2661 int loc
= GetSessionDbcLocale();
2662 std::string name
= set
->name
[loc
];
2666 if (!Utf8FitTo(name
, wnamepart
))
2669 for(; loc
< MAX_LOCALE
; ++loc
)
2671 if(loc
==GetSessionDbcLocale())
2674 name
= set
->name
[loc
];
2678 if (Utf8FitTo(name
, wnamepart
))
2683 if(loc
< MAX_LOCALE
)
2685 // send item set in "id - [namedlink locale]" format
2687 PSendSysMessage(LANG_ITEMSET_LIST_CHAT
,id
,id
,name
.c_str(),localeNames
[loc
]);
2689 PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE
,id
,name
.c_str(),localeNames
[loc
]);
2694 if (counter
== 0) // if counter == 0 then we found nth
2695 SendSysMessage(LANG_COMMAND_NOITEMSETFOUND
);
2699 bool ChatHandler::HandleLookupSkillCommand(const char* args
)
2704 // can be NULL in console call
2705 Player
* target
= getSelectedPlayer();
2707 std::string namepart
= args
;
2708 std::wstring wnamepart
;
2710 if(!Utf8toWStr(namepart
,wnamepart
))
2713 // converting string that we try to find to lower case
2714 wstrToLower( wnamepart
);
2716 uint32 counter
= 0; // Counter for figure out that we found smth.
2718 // Search in SkillLine.dbc
2719 for (uint32 id
= 0; id
< sSkillLineStore
.GetNumRows(); id
++)
2721 SkillLineEntry
const *skillInfo
= sSkillLineStore
.LookupEntry(id
);
2724 int loc
= GetSessionDbcLocale();
2725 std::string name
= skillInfo
->name
[loc
];
2729 if (!Utf8FitTo(name
, wnamepart
))
2732 for(; loc
< MAX_LOCALE
; ++loc
)
2734 if(loc
==GetSessionDbcLocale())
2737 name
= skillInfo
->name
[loc
];
2741 if (Utf8FitTo(name
, wnamepart
))
2746 if(loc
< MAX_LOCALE
)
2748 char valStr
[50] = "";
2749 char const* knownStr
= "";
2750 if(target
&& target
->HasSkill(id
))
2752 knownStr
= GetMangosString(LANG_KNOWN
);
2753 uint32 curValue
= target
->GetPureSkillValue(id
);
2754 uint32 maxValue
= target
->GetPureMaxSkillValue(id
);
2755 uint32 permValue
= target
->GetSkillPermBonusValue(id
);
2756 uint32 tempValue
= target
->GetSkillTempBonusValue(id
);
2758 char const* valFormat
= GetMangosString(LANG_SKILL_VALUES
);
2759 snprintf(valStr
,50,valFormat
,curValue
,maxValue
,permValue
,tempValue
);
2762 // send skill in "id - [namedlink locale]" format
2764 PSendSysMessage(LANG_SKILL_LIST_CHAT
,id
,id
,name
.c_str(),localeNames
[loc
],knownStr
,valStr
);
2766 PSendSysMessage(LANG_SKILL_LIST_CONSOLE
,id
,name
.c_str(),localeNames
[loc
],knownStr
,valStr
);
2772 if (counter
== 0) // if counter == 0 then we found nth
2773 SendSysMessage(LANG_COMMAND_NOSKILLFOUND
);
2777 bool ChatHandler::HandleLookupSpellCommand(const char* args
)
2782 // can be NULL at console call
2783 Player
* target
= getSelectedPlayer();
2785 std::string namepart
= args
;
2786 std::wstring wnamepart
;
2788 if(!Utf8toWStr(namepart
,wnamepart
))
2791 // converting string that we try to find to lower case
2792 wstrToLower( wnamepart
);
2794 uint32 counter
= 0; // Counter for figure out that we found smth.
2796 // Search in Spell.dbc
2797 for (uint32 id
= 0; id
< sSpellStore
.GetNumRows(); id
++)
2799 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(id
);
2802 int loc
= GetSessionDbcLocale();
2803 std::string name
= spellInfo
->SpellName
[loc
];
2807 if (!Utf8FitTo(name
, wnamepart
))
2810 for(; loc
< MAX_LOCALE
; ++loc
)
2812 if(loc
==GetSessionDbcLocale())
2815 name
= spellInfo
->SpellName
[loc
];
2819 if (Utf8FitTo(name
, wnamepart
))
2824 if(loc
< MAX_LOCALE
)
2826 bool known
= target
&& target
->HasSpell(id
);
2827 bool learn
= (spellInfo
->Effect
[0] == SPELL_EFFECT_LEARN_SPELL
);
2829 uint32 talentCost
= GetTalentSpellCost(id
);
2831 bool talent
= (talentCost
> 0);
2832 bool passive
= IsPassiveSpell(id
);
2833 bool active
= target
&& target
->HasAura(id
);
2835 // unit32 used to prevent interpreting uint8 as char at output
2836 // find rank of learned spell for learning spell, or talent rank
2837 uint32 rank
= talentCost
? talentCost
: spellmgr
.GetSpellRank(learn
? spellInfo
->EffectTriggerSpell
[0] : id
);
2839 // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
2840 std::ostringstream ss
;
2842 ss
<< id
<< " - |cffffffff|Hspell:" << id
<< "|h[" << name
;
2844 ss
<< id
<< " - " << name
;
2846 // include rank in link name
2848 ss
<< GetMangosString(LANG_SPELL_RANK
) << rank
;
2851 ss
<< " " << localeNames
[loc
] << "]|h|r";
2853 ss
<< " " << localeNames
[loc
];
2856 ss
<< GetMangosString(LANG_TALENT
);
2858 ss
<< GetMangosString(LANG_PASSIVE
);
2860 ss
<< GetMangosString(LANG_LEARN
);
2862 ss
<< GetMangosString(LANG_KNOWN
);
2864 ss
<< GetMangosString(LANG_ACTIVE
);
2866 SendSysMessage(ss
.str().c_str());
2872 if (counter
== 0) // if counter == 0 then we found nth
2873 SendSysMessage(LANG_COMMAND_NOSPELLFOUND
);
2877 bool ChatHandler::HandleLookupQuestCommand(const char* args
)
2882 // can be NULL at console call
2883 Player
* target
= getSelectedPlayer();
2885 std::string namepart
= args
;
2886 std::wstring wnamepart
;
2888 // converting string that we try to find to lower case
2889 if(!Utf8toWStr(namepart
,wnamepart
))
2892 wstrToLower(wnamepart
);
2894 uint32 counter
= 0 ;
2896 ObjectMgr::QuestMap
const& qTemplates
= objmgr
.GetQuestTemplates();
2897 for (ObjectMgr::QuestMap::const_iterator iter
= qTemplates
.begin(); iter
!= qTemplates
.end(); ++iter
)
2899 Quest
* qinfo
= iter
->second
;
2901 int loc_idx
= GetSessionDbLocaleIndex();
2904 QuestLocale
const *il
= objmgr
.GetQuestLocale(qinfo
->GetQuestId());
2907 if (il
->Title
.size() > loc_idx
&& !il
->Title
[loc_idx
].empty())
2909 std::string title
= il
->Title
[loc_idx
];
2911 if (Utf8FitTo(title
, wnamepart
))
2913 char const* statusStr
= "";
2917 QuestStatus status
= target
->GetQuestStatus(qinfo
->GetQuestId());
2919 if(status
== QUEST_STATUS_COMPLETE
)
2921 if(target
->GetQuestRewardStatus(qinfo
->GetQuestId()))
2922 statusStr
= GetMangosString(LANG_COMMAND_QUEST_REWARDED
);
2924 statusStr
= GetMangosString(LANG_COMMAND_QUEST_COMPLETE
);
2926 else if(status
== QUEST_STATUS_INCOMPLETE
)
2927 statusStr
= GetMangosString(LANG_COMMAND_QUEST_ACTIVE
);
2931 PSendSysMessage(LANG_QUEST_LIST_CHAT
,qinfo
->GetQuestId(),qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2933 PSendSysMessage(LANG_QUEST_LIST_CONSOLE
,qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2941 std::string title
= qinfo
->GetTitle();
2945 if (Utf8FitTo(title
, wnamepart
))
2947 char const* statusStr
= "";
2951 QuestStatus status
= target
->GetQuestStatus(qinfo
->GetQuestId());
2953 if(status
== QUEST_STATUS_COMPLETE
)
2955 if(target
->GetQuestRewardStatus(qinfo
->GetQuestId()))
2956 statusStr
= GetMangosString(LANG_COMMAND_QUEST_REWARDED
);
2958 statusStr
= GetMangosString(LANG_COMMAND_QUEST_COMPLETE
);
2960 else if(status
== QUEST_STATUS_INCOMPLETE
)
2961 statusStr
= GetMangosString(LANG_COMMAND_QUEST_ACTIVE
);
2965 PSendSysMessage(LANG_QUEST_LIST_CHAT
,qinfo
->GetQuestId(),qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2967 PSendSysMessage(LANG_QUEST_LIST_CONSOLE
,qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2974 SendSysMessage(LANG_COMMAND_NOQUESTFOUND
);
2979 bool ChatHandler::HandleLookupCreatureCommand(const char* args
)
2984 std::string namepart
= args
;
2985 std::wstring wnamepart
;
2987 // converting string that we try to find to lower case
2988 if (!Utf8toWStr (namepart
,wnamepart
))
2991 wstrToLower (wnamepart
);
2995 for (uint32 id
= 0; id
< sCreatureStorage
.MaxEntry
; ++id
)
2997 CreatureInfo
const* cInfo
= sCreatureStorage
.LookupEntry
<CreatureInfo
> (id
);
3001 int loc_idx
= GetSessionDbLocaleIndex();
3004 CreatureLocale
const *cl
= objmgr
.GetCreatureLocale (id
);
3007 if (cl
->Name
.size() > loc_idx
&& !cl
->Name
[loc_idx
].empty ())
3009 std::string name
= cl
->Name
[loc_idx
];
3011 if (Utf8FitTo (name
, wnamepart
))
3014 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str ());
3016 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE
, id
, name
.c_str ());
3024 std::string name
= cInfo
->Name
;
3028 if (Utf8FitTo(name
, wnamepart
))
3031 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str ());
3033 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE
, id
, name
.c_str ());
3039 SendSysMessage (LANG_COMMAND_NOCREATUREFOUND
);
3044 bool ChatHandler::HandleLookupObjectCommand(const char* args
)
3049 std::string namepart
= args
;
3050 std::wstring wnamepart
;
3052 // converting string that we try to find to lower case
3053 if(!Utf8toWStr(namepart
,wnamepart
))
3056 wstrToLower(wnamepart
);
3060 for (uint32 id
= 0; id
< sGOStorage
.MaxEntry
; id
++ )
3062 GameObjectInfo
const* gInfo
= sGOStorage
.LookupEntry
<GameObjectInfo
>(id
);
3066 int loc_idx
= GetSessionDbLocaleIndex();
3069 GameObjectLocale
const *gl
= objmgr
.GetGameObjectLocale(id
);
3072 if (gl
->Name
.size() > loc_idx
&& !gl
->Name
[loc_idx
].empty())
3074 std::string name
= gl
->Name
[loc_idx
];
3076 if (Utf8FitTo(name
, wnamepart
))
3079 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT
, id
, id
, name
.c_str());
3081 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE
, id
, name
.c_str());
3089 std::string name
= gInfo
->name
;
3093 if(Utf8FitTo(name
, wnamepart
))
3096 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT
, id
, id
, name
.c_str());
3098 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE
, id
, name
.c_str());
3104 SendSysMessage(LANG_COMMAND_NOGAMEOBJECTFOUND
);
3109 bool ChatHandler::HandleLookupTaxiNodeCommand(const char * args
)
3114 std::string namepart
= args
;
3115 std::wstring wnamepart
;
3117 if(!Utf8toWStr(namepart
,wnamepart
))
3120 // converting string that we try to find to lower case
3121 wstrToLower( wnamepart
);
3123 uint32 counter
= 0; // Counter for figure out that we found smth.
3125 // Search in TaxiNodes.dbc
3126 for (uint32 id
= 0; id
< sTaxiNodesStore
.GetNumRows(); id
++)
3128 TaxiNodesEntry
const *nodeEntry
= sTaxiNodesStore
.LookupEntry(id
);
3131 int loc
= GetSessionDbcLocale();
3132 std::string name
= nodeEntry
->name
[loc
];
3136 if (!Utf8FitTo(name
, wnamepart
))
3139 for(; loc
< MAX_LOCALE
; ++loc
)
3141 if(loc
==GetSessionDbcLocale())
3144 name
= nodeEntry
->name
[loc
];
3148 if (Utf8FitTo(name
, wnamepart
))
3153 if(loc
< MAX_LOCALE
)
3155 // send taxinode in "id - [name] (Map:m X:x Y:y Z:z)" format
3157 PSendSysMessage (LANG_TAXINODE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str(),localeNames
[loc
],
3158 nodeEntry
->map_id
,nodeEntry
->x
,nodeEntry
->y
,nodeEntry
->z
);
3160 PSendSysMessage (LANG_TAXINODE_ENTRY_LIST_CONSOLE
, id
, name
.c_str(), localeNames
[loc
],
3161 nodeEntry
->map_id
,nodeEntry
->x
,nodeEntry
->y
,nodeEntry
->z
);
3166 if (counter
== 0) // if counter == 0 then we found nth
3167 SendSysMessage(LANG_COMMAND_NOSPELLFOUND
);
3171 /** \brief GM command level 3 - Create a guild.
3173 * This command allows a GM (level 3) to create a guild.
3175 * The "args" parameter contains the name of the guild leader
3176 * and then the name of the guild.
3179 bool ChatHandler::HandleGuildCreateCommand(const char* args
)
3184 // if not guild name only (in "") then player name
3186 if(!extractPlayerTarget(*args
!='"' ? (char*)args
: NULL
, &target
))
3189 char* tailStr
= *args
!='"' ? strtok(NULL
, "") : (char*)args
;
3193 char* guildStr
= extractQuotedArg(tailStr
);
3197 std::string guildname
= guildStr
;
3199 if (target
->GetGuildId())
3201 SendSysMessage (LANG_PLAYER_IN_GUILD
);
3205 Guild
*guild
= new Guild
;
3206 if (!guild
->create (target
,guildname
))
3209 SendSysMessage (LANG_GUILD_NOT_CREATED
);
3210 SetSentErrorMessage (true);
3214 objmgr
.AddGuild (guild
);
3218 bool ChatHandler::HandleGuildInviteCommand(const char *args
)
3223 // if not guild name only (in "") then player name
3225 if(!extractPlayerTarget(*args
!='"' ? (char*)args
: NULL
, NULL
, &target_guid
))
3228 char* tailStr
= *args
!='"' ? strtok(NULL
, "") : (char*)args
;
3232 char* guildStr
= extractQuotedArg(tailStr
);
3236 std::string glName
= guildStr
;
3237 Guild
* targetGuild
= objmgr
.GetGuildByName (glName
);
3241 // player's guild membership checked in AddMember before add
3242 if (!targetGuild
->AddMember (target_guid
,targetGuild
->GetLowestRank ()))
3248 bool ChatHandler::HandleGuildUninviteCommand(const char *args
)
3252 if(!extractPlayerTarget((char*)args
,&target
,&target_guid
))
3255 uint32 glId
= target
? target
->GetGuildId () : Player::GetGuildIdFromDB (target_guid
);
3259 Guild
* targetGuild
= objmgr
.GetGuildById (glId
);
3263 targetGuild
->DelMember (target_guid
);
3267 bool ChatHandler::HandleGuildRankCommand(const char *args
)
3271 extractOptFirstArg((char*)args
,&nameStr
,&rankStr
);
3277 std::string target_name
;
3278 if(!extractPlayerTarget(nameStr
,&target
,&target_guid
,&target_name
))
3281 uint32 glId
= target
? target
->GetGuildId () : Player::GetGuildIdFromDB (target_guid
);
3285 Guild
* targetGuild
= objmgr
.GetGuildById (glId
);
3289 uint32 newrank
= uint32 (atoi (rankStr
));
3290 if (newrank
> targetGuild
->GetLowestRank ())
3293 targetGuild
->ChangeRank (target_guid
,newrank
);
3297 bool ChatHandler::HandleGuildDeleteCommand(const char* args
)
3302 char* guildStr
= extractQuotedArg((char*)args
);
3306 std::string gld
= guildStr
;
3308 Guild
* targetGuild
= objmgr
.GetGuildByName (gld
);
3312 targetGuild
->Disband ();
3317 bool ChatHandler::HandleGetDistanceCommand(const char* args
)
3319 WorldObject
* obj
= NULL
;
3323 uint64 guid
= extractGuidFromLink((char*)args
);
3325 obj
= (WorldObject
*)ObjectAccessor::GetObjectByTypeMask(*m_session
->GetPlayer(),guid
,TYPEMASK_UNIT
|TYPEMASK_GAMEOBJECT
);
3329 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3330 SetSentErrorMessage(true);
3336 obj
= getSelectedUnit();
3340 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3341 SetSentErrorMessage(true);
3346 PSendSysMessage(LANG_DISTANCE
, m_session
->GetPlayer()->GetDistance(obj
),m_session
->GetPlayer()->GetDistance2d(obj
));
3351 bool ChatHandler::HandleDieCommand(const char* /*args*/)
3353 Unit
* target
= getSelectedUnit();
3355 if(!target
|| !m_session
->GetPlayer()->GetSelection())
3357 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3358 SetSentErrorMessage(true);
3362 if(target
->GetTypeId()==TYPEID_PLAYER
)
3364 if(HasLowerSecurity((Player
*)target
,0,false))
3368 if( target
->isAlive() )
3370 m_session
->GetPlayer()->DealDamage(target
, target
->GetHealth(), NULL
, DIRECT_DAMAGE
, SPELL_SCHOOL_MASK_NORMAL
, NULL
, false);
3376 bool ChatHandler::HandleDamageCommand(const char * args
)
3381 Unit
* target
= getSelectedUnit();
3383 if (!target
|| !m_session
->GetPlayer()->GetSelection())
3385 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3386 SetSentErrorMessage(true);
3390 if (!target
->isAlive())
3393 char* damageStr
= strtok((char*)args
, " ");
3397 int32 damage_int
= atoi((char*)damageStr
);
3401 uint32 damage
= damage_int
;
3403 char* schoolStr
= strtok((char*)NULL
, " ");
3405 // flat melee damage without resistence/etc reduction
3408 m_session
->GetPlayer()->DealDamage(target
, damage
, NULL
, DIRECT_DAMAGE
, SPELL_SCHOOL_MASK_NORMAL
, NULL
, false);
3409 if (target
!= m_session
->GetPlayer())
3410 m_session
->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2
, target
, 1, SPELL_SCHOOL_MASK_NORMAL
, damage
, 0, 0, VICTIMSTATE_NORMAL
, 0);
3414 uint32 school
= schoolStr
? atoi((char*)schoolStr
) : SPELL_SCHOOL_NORMAL
;
3415 if(school
>= MAX_SPELL_SCHOOL
)
3418 SpellSchoolMask schoolmask
= SpellSchoolMask(1 << school
);
3420 if ( schoolmask
& SPELL_SCHOOL_MASK_NORMAL
)
3421 damage
= m_session
->GetPlayer()->CalcArmorReducedDamage(target
, damage
);
3423 char* spellStr
= strtok((char*)NULL
, " ");
3425 // melee damage by specific school
3431 m_session
->GetPlayer()->CalcAbsorbResist(target
,schoolmask
, SPELL_DIRECT_DAMAGE
, damage
, &absorb
, &resist
);
3433 if (damage
<= absorb
+ resist
)
3436 damage
-= absorb
+ resist
;
3438 m_session
->GetPlayer()->DealDamageMods(target
,damage
,&absorb
);
3439 m_session
->GetPlayer()->DealDamage(target
, damage
, NULL
, DIRECT_DAMAGE
, schoolmask
, NULL
, false);
3440 m_session
->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2
, target
, 1, schoolmask
, damage
, absorb
, resist
, VICTIMSTATE_NORMAL
, 0);
3446 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3447 uint32 spellid
= extractSpellIdFromLink((char*)args
);
3448 if (!spellid
|| !sSpellStore
.LookupEntry(spellid
))
3451 m_session
->GetPlayer()->SpellNonMeleeDamageLog(target
, spellid
, damage
);
3455 bool ChatHandler::HandleModifyArenaCommand(const char * args
)
3460 Player
*target
= getSelectedPlayer();
3463 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3464 SetSentErrorMessage(true);
3468 int32 amount
= (uint32
)atoi(args
);
3470 target
->ModifyArenaPoints(amount
);
3472 PSendSysMessage(LANG_COMMAND_MODIFY_ARENA
, GetNameLink(target
).c_str(), target
->GetArenaPoints());
3477 bool ChatHandler::HandleReviveCommand(const char* args
)
3481 if(!extractPlayerTarget((char*)args
,&target
,&target_guid
))
3486 target
->ResurrectPlayer(0.5f
);
3487 target
->SpawnCorpseBones();
3491 // will resurrected at login without corpse
3492 ObjectAccessor::Instance().ConvertCorpseForPlayer(target_guid
);
3497 bool ChatHandler::HandleAuraCommand(const char* args
)
3499 Unit
*target
= getSelectedUnit();
3502 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3503 SetSentErrorMessage(true);
3507 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3508 uint32 spellID
= extractSpellIdFromLink((char*)args
);
3510 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry( spellID
);
3513 for(uint32 i
= 0;i
<3;++i
)
3515 uint8 eff
= spellInfo
->Effect
[i
];
3516 if (eff
>=TOTAL_SPELL_EFFECTS
)
3518 if( IsAreaAuraEffect(eff
) ||
3519 eff
== SPELL_EFFECT_APPLY_AURA
||
3520 eff
== SPELL_EFFECT_PERSISTENT_AREA_AURA
)
3522 Aura
*Aur
= CreateAura(spellInfo
, i
, NULL
, target
);
3523 target
->AddAura(Aur
);
3531 bool ChatHandler::HandleUnAuraCommand(const char* args
)
3533 Unit
*target
= getSelectedUnit();
3536 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3537 SetSentErrorMessage(true);
3541 std::string argstr
= args
;
3542 if (argstr
== "all")
3544 target
->RemoveAllAuras();
3548 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3549 uint32 spellID
= extractSpellIdFromLink((char*)args
);
3553 target
->RemoveAurasDueToSpell(spellID
);
3558 bool ChatHandler::HandleLinkGraveCommand(const char* args
)
3563 char* px
= strtok((char*)args
, " ");
3567 uint32 g_id
= (uint32
)atoi(px
);
3571 char* px2
= strtok(NULL
, " ");
3575 else if (strncmp(px2
,"horde",6)==0)
3577 else if (strncmp(px2
,"alliance",9)==0)
3582 WorldSafeLocsEntry
const* graveyard
= sWorldSafeLocsStore
.LookupEntry(g_id
);
3586 PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST
, g_id
);
3587 SetSentErrorMessage(true);
3591 Player
* player
= m_session
->GetPlayer();
3593 uint32 zoneId
= player
->GetZoneId();
3595 AreaTableEntry
const *areaEntry
= GetAreaEntryByAreaID(zoneId
);
3596 if(!areaEntry
|| areaEntry
->zone
!=0 )
3598 PSendSysMessage(LANG_COMMAND_GRAVEYARDWRONGZONE
, g_id
,zoneId
);
3599 SetSentErrorMessage(true);
3603 if(objmgr
.AddGraveYardLink(g_id
,zoneId
,g_team
))
3604 PSendSysMessage(LANG_COMMAND_GRAVEYARDLINKED
, g_id
,zoneId
);
3606 PSendSysMessage(LANG_COMMAND_GRAVEYARDALRLINKED
, g_id
,zoneId
);
3611 bool ChatHandler::HandleNearGraveCommand(const char* args
)
3615 size_t argslen
= strlen(args
);
3619 else if (strncmp((char*)args
,"horde",argslen
)==0)
3621 else if (strncmp((char*)args
,"alliance",argslen
)==0)
3626 Player
* player
= m_session
->GetPlayer();
3627 uint32 zone_id
= player
->GetZoneId();
3629 WorldSafeLocsEntry
const* graveyard
= objmgr
.GetClosestGraveYard(
3630 player
->GetPositionX(), player
->GetPositionY(), player
->GetPositionZ(),player
->GetMapId(),g_team
);
3634 uint32 g_id
= graveyard
->ID
;
3636 GraveYardData
const* data
= objmgr
.FindGraveYardData(g_id
,zone_id
);
3639 PSendSysMessage(LANG_COMMAND_GRAVEYARDERROR
,g_id
);
3640 SetSentErrorMessage(true);
3644 g_team
= data
->team
;
3646 std::string team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_NOTEAM
);
3649 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ANY
);
3650 else if(g_team
== HORDE
)
3651 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE
);
3652 else if(g_team
== ALLIANCE
)
3653 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE
);
3655 PSendSysMessage(LANG_COMMAND_GRAVEYARDNEAREST
, g_id
,team_name
.c_str(),zone_id
);
3659 std::string team_name
;
3662 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ANY
);
3663 else if(g_team
== HORDE
)
3664 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE
);
3665 else if(g_team
== ALLIANCE
)
3666 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE
);
3668 if(g_team
== ~uint32(0))
3669 PSendSysMessage(LANG_COMMAND_ZONENOGRAVEYARDS
, zone_id
);
3671 PSendSysMessage(LANG_COMMAND_ZONENOGRAFACTION
, zone_id
,team_name
.c_str());
3677 //-----------------------Npc Commands-----------------------
3678 bool ChatHandler::HandleNpcAllowMovementCommand(const char* /*args*/)
3680 if(sWorld
.getAllowMovement())
3682 sWorld
.SetAllowMovement(false);
3683 SendSysMessage(LANG_CREATURE_MOVE_DISABLED
);
3687 sWorld
.SetAllowMovement(true);
3688 SendSysMessage(LANG_CREATURE_MOVE_ENABLED
);
3693 bool ChatHandler::HandleNpcChangeEntryCommand(const char *args
)
3698 uint32 newEntryNum
= atoi(args
);
3702 Unit
* unit
= getSelectedUnit();
3703 if(!unit
|| unit
->GetTypeId() != TYPEID_UNIT
)
3705 SendSysMessage(LANG_SELECT_CREATURE
);
3706 SetSentErrorMessage(true);
3709 Creature
* creature
= (Creature
*)unit
;
3710 if(creature
->UpdateEntry(newEntryNum
))
3711 SendSysMessage(LANG_DONE
);
3713 SendSysMessage(LANG_ERROR
);
3717 bool ChatHandler::HandleNpcInfoCommand(const char* /*args*/)
3719 Creature
* target
= getSelectedCreature();
3723 SendSysMessage(LANG_SELECT_CREATURE
);
3724 SetSentErrorMessage(true);
3728 uint32 faction
= target
->getFaction();
3729 uint32 npcflags
= target
->GetUInt32Value(UNIT_NPC_FLAGS
);
3730 uint32 displayid
= target
->GetDisplayId();
3731 uint32 nativeid
= target
->GetNativeDisplayId();
3732 uint32 Entry
= target
->GetEntry();
3733 CreatureInfo
const* cInfo
= target
->GetCreatureInfo();
3735 int32 curRespawnDelay
= target
->GetRespawnTimeEx()-time(NULL
);
3736 if(curRespawnDelay
< 0)
3737 curRespawnDelay
= 0;
3738 std::string curRespawnDelayStr
= secsToTimeString(curRespawnDelay
,true);
3739 std::string defRespawnDelayStr
= secsToTimeString(target
->GetRespawnDelay(),true);
3741 PSendSysMessage(LANG_NPCINFO_CHAR
, target
->GetDBTableGUIDLow(), faction
, npcflags
, Entry
, displayid
, nativeid
);
3742 PSendSysMessage(LANG_NPCINFO_LEVEL
, target
->getLevel());
3743 PSendSysMessage(LANG_NPCINFO_HEALTH
,target
->GetCreateHealth(), target
->GetMaxHealth(), target
->GetHealth());
3744 PSendSysMessage(LANG_NPCINFO_FLAGS
, target
->GetUInt32Value(UNIT_FIELD_FLAGS
), target
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
), target
->getFaction());
3745 PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES
, defRespawnDelayStr
.c_str(),curRespawnDelayStr
.c_str());
3746 PSendSysMessage(LANG_NPCINFO_LOOT
, cInfo
->lootid
,cInfo
->pickpocketLootId
,cInfo
->SkinLootId
);
3747 PSendSysMessage(LANG_NPCINFO_DUNGEON_ID
, target
->GetInstanceId());
3748 PSendSysMessage(LANG_NPCINFO_POSITION
,float(target
->GetPositionX()), float(target
->GetPositionY()), float(target
->GetPositionZ()));
3750 if ((npcflags
& UNIT_NPC_FLAG_VENDOR
) )
3752 SendSysMessage(LANG_NPCINFO_VENDOR
);
3754 if ((npcflags
& UNIT_NPC_FLAG_TRAINER
) )
3756 SendSysMessage(LANG_NPCINFO_TRAINER
);
3763 bool ChatHandler::HandleNpcPlayEmoteCommand(const char* args
)
3765 uint32 emote
= atoi((char*)args
);
3767 Creature
* target
= getSelectedCreature();
3770 SendSysMessage(LANG_SELECT_CREATURE
);
3771 SetSentErrorMessage(true);
3775 target
->SetUInt32Value(UNIT_NPC_EMOTESTATE
,emote
);
3780 //TODO: NpcCommands that needs to be fixed :
3782 bool ChatHandler::HandleNpcAddWeaponCommand(const char* /*args*/)
3787 uint64 guid = m_session->GetPlayer()->GetSelection();
3790 SendSysMessage(LANG_NO_SELECTION);
3794 Creature *pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
3798 SendSysMessage(LANG_SELECT_CREATURE);
3802 char* pSlotID = strtok((char*)args, " ");
3806 char* pItemID = strtok(NULL, " ");
3810 uint32 ItemID = atoi(pItemID);
3811 uint32 SlotID = atoi(pSlotID);
3813 ItemPrototype* tmpItem = objmgr.GetItemPrototype(ItemID);
3821 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID);
3825 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID);
3829 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID);
3833 PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST,SlotID);
3839 PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT,ItemID,tmpItem->Name1,SlotID);
3843 PSendSysMessage(LANG_ITEM_NOT_FOUND,ItemID);
3849 //----------------------------------------------------------
3851 bool ChatHandler::HandleExploreCheatCommand(const char* args
)
3856 int flag
= atoi((char*)args
);
3858 Player
*chr
= getSelectedPlayer();
3861 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3862 SetSentErrorMessage(true);
3868 PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL
, GetNameLink(chr
).c_str());
3869 if (needReportToTarget(chr
))
3870 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_EXPLORE_SET_ALL
,GetNameLink().c_str());
3874 PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING
, GetNameLink(chr
).c_str());
3875 if (needReportToTarget(chr
))
3876 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_EXPLORE_SET_NOTHING
,GetNameLink().c_str());
3879 for (uint8 i
=0; i
<128; ++i
)
3883 m_session
->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1
+i
,0xFFFFFFFF);
3887 m_session
->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1
+i
,0);
3894 bool ChatHandler::HandleHoverCommand(const char* args
)
3896 char* px
= strtok((char*)args
, " ");
3903 m_session
->GetPlayer()->SetHover(flag
);
3906 SendSysMessage(LANG_HOVER_ENABLED
);
3908 SendSysMessage(LANG_HOVER_DISABLED
);
3913 void ChatHandler::HandleCharacterLevel(Player
* player
, uint64 player_guid
, uint32 oldlevel
, uint32 newlevel
)
3917 player
->GiveLevel(newlevel
);
3918 player
->InitTalentForLevel();
3919 player
->SetUInt32Value(PLAYER_XP
,0);
3921 if(needReportToTarget(player
))
3923 if(oldlevel
== newlevel
)
3924 ChatHandler(player
).PSendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET
,GetNameLink().c_str());
3925 else if(oldlevel
< newlevel
)
3926 ChatHandler(player
).PSendSysMessage(LANG_YOURS_LEVEL_UP
,GetNameLink().c_str(),newlevel
);
3927 else // if(oldlevel > newlevel)
3928 ChatHandler(player
).PSendSysMessage(LANG_YOURS_LEVEL_DOWN
,GetNameLink().c_str(),newlevel
);
3933 // update level and XP at level, all other will be updated at loading
3935 Player::LoadValuesArrayFromDB(values
,player_guid
);
3936 Player::SetUInt32ValueInArray(values
,UNIT_FIELD_LEVEL
,newlevel
);
3937 Player::SetUInt32ValueInArray(values
,PLAYER_XP
,0);
3938 Player::SaveValuesArrayInDB(values
,player_guid
);
3942 bool ChatHandler::HandleCharacterLevelCommand(const char* args
)
3946 extractOptFirstArg((char*)args
,&nameStr
,&levelStr
);
3950 // exception opt second arg: .character level $name
3951 if(isalpha(levelStr
[0]))
3954 levelStr
= NULL
; // current level will used
3959 std::string target_name
;
3960 if(!extractPlayerTarget(nameStr
,&target
,&target_guid
,&target_name
))
3963 int32 oldlevel
= target
? target
->getLevel() : Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL
,target_guid
);
3964 int32 newlevel
= levelStr
? atoi(levelStr
) : oldlevel
;
3967 return false; // invalid level
3969 if(newlevel
> STRONG_MAX_LEVEL
) // hardcoded maximum level
3970 newlevel
= STRONG_MAX_LEVEL
;
3972 HandleCharacterLevel(target
,target_guid
,oldlevel
,newlevel
);
3974 if(!m_session
|| m_session
->GetPlayer() != target
) // including player==NULL
3976 std::string nameLink
= playerLink(target_name
);
3977 PSendSysMessage(LANG_YOU_CHANGE_LVL
,nameLink
.c_str(),newlevel
);
3983 bool ChatHandler::HandleLevelUpCommand(const char* args
)
3987 extractOptFirstArg((char*)args
,&nameStr
,&levelStr
);
3989 // exception opt second arg: .character level $name
3990 if(levelStr
&& isalpha(levelStr
[0]))
3993 levelStr
= NULL
; // current level will used
3998 std::string target_name
;
3999 if(!extractPlayerTarget(nameStr
,&target
,&target_guid
,&target_name
))
4002 int32 oldlevel
= target
? target
->getLevel() : Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL
,target_guid
);
4003 int32 addlevel
= levelStr
? atoi(levelStr
) : 1;
4004 int32 newlevel
= oldlevel
+ addlevel
;
4009 if(newlevel
> STRONG_MAX_LEVEL
) // hardcoded maximum level
4010 newlevel
= STRONG_MAX_LEVEL
;
4012 HandleCharacterLevel(target
,target_guid
,oldlevel
,newlevel
);
4014 if(!m_session
|| m_session
->GetPlayer() != target
) // including chr==NULL
4016 std::string nameLink
= playerLink(target_name
);
4017 PSendSysMessage(LANG_YOU_CHANGE_LVL
,nameLink
.c_str(),newlevel
);
4023 bool ChatHandler::HandleShowAreaCommand(const char* args
)
4028 Player
*chr
= getSelectedPlayer();
4031 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4032 SetSentErrorMessage(true);
4036 int area
= GetAreaFlagByAreaID(atoi((char*)args
));
4037 int offset
= area
/ 32;
4038 uint32 val
= (uint32
)(1 << (area
% 32));
4040 if(area
<0 || offset
>= 128)
4042 SendSysMessage(LANG_BAD_VALUE
);
4043 SetSentErrorMessage(true);
4047 uint32 currFields
= chr
->GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
4048 chr
->SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
| val
));
4050 SendSysMessage(LANG_EXPLORE_AREA
);
4054 bool ChatHandler::HandleHideAreaCommand(const char* args
)
4059 Player
*chr
= getSelectedPlayer();
4062 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4063 SetSentErrorMessage(true);
4067 int area
= GetAreaFlagByAreaID(atoi((char*)args
));
4068 int offset
= area
/ 32;
4069 uint32 val
= (uint32
)(1 << (area
% 32));
4071 if(area
<0 || offset
>= 128)
4073 SendSysMessage(LANG_BAD_VALUE
);
4074 SetSentErrorMessage(true);
4078 uint32 currFields
= chr
->GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
4079 chr
->SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
^ val
));
4081 SendSysMessage(LANG_UNEXPLORE_AREA
);
4085 bool ChatHandler::HandleDebugUpdate(const char* args
)
4093 char* pUpdateIndex
= strtok((char*)args
, " ");
4095 Unit
* chr
= getSelectedUnit();
4098 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4099 SetSentErrorMessage(true);
4107 updateIndex
= atoi(pUpdateIndex
);
4109 if(chr
->GetTypeId() == TYPEID_PLAYER
)
4111 if (updateIndex
>=PLAYER_END
) return true;
4115 if (updateIndex
>=UNIT_END
) return true;
4118 char* pvalue
= strtok(NULL
, " ");
4121 value
=chr
->GetUInt32Value(updateIndex
);
4123 PSendSysMessage(LANG_UPDATE
, chr
->GetGUIDLow(),updateIndex
,value
);
4129 PSendSysMessage(LANG_UPDATE_CHANGE
, chr
->GetGUIDLow(),updateIndex
,value
);
4131 chr
->SetUInt32Value(updateIndex
,value
);
4136 bool ChatHandler::HandleBankCommand(const char* /*args*/)
4138 m_session
->SendShowBank( m_session
->GetPlayer()->GetGUID() );
4143 bool ChatHandler::HandleChangeWeather(const char* args
)
4149 if (!sWorld
.getConfig(CONFIG_WEATHER
))
4151 SendSysMessage(LANG_WEATHER_DISABLED
);
4152 SetSentErrorMessage(true);
4156 //*Change the weather of a cell
4157 char* px
= strtok((char*)args
, " ");
4158 char* py
= strtok(NULL
, " ");
4163 uint32 type
= (uint32
)atoi(px
); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
4164 float grade
= (float)atof(py
); //0 to 1, sending -1 is instand good weather
4166 Player
*player
= m_session
->GetPlayer();
4167 uint32 zoneid
= player
->GetZoneId();
4169 Weather
* wth
= sWorld
.FindWeather(zoneid
);
4172 wth
= sWorld
.AddWeather(zoneid
);
4175 SendSysMessage(LANG_NO_WEATHER
);
4176 SetSentErrorMessage(true);
4180 wth
->SetWeather(WeatherType(type
), grade
);
4185 bool ChatHandler::HandleDebugSetValue(const char* args
)
4190 char* px
= strtok((char*)args
, " ");
4191 char* py
= strtok(NULL
, " ");
4192 char* pz
= strtok(NULL
, " ");
4197 Unit
* target
= getSelectedUnit();
4200 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4201 SetSentErrorMessage(true);
4205 uint64 guid
= target
->GetGUID();
4207 uint32 Opcode
= (uint32
)atoi(px
);
4208 if(Opcode
>= target
->GetValuesCount())
4210 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, GUID_LOPART(guid
), target
->GetValuesCount());
4215 bool isint32
= true;
4217 isint32
= (bool)atoi(pz
);
4220 iValue
= (uint32
)atoi(py
);
4221 sLog
.outDebug(GetMangosString(LANG_SET_UINT
), GUID_LOPART(guid
), Opcode
, iValue
);
4222 target
->SetUInt32Value( Opcode
, iValue
);
4223 PSendSysMessage(LANG_SET_UINT_FIELD
, GUID_LOPART(guid
), Opcode
,iValue
);
4227 fValue
= (float)atof(py
);
4228 sLog
.outDebug(GetMangosString(LANG_SET_FLOAT
), GUID_LOPART(guid
), Opcode
, fValue
);
4229 target
->SetFloatValue( Opcode
, fValue
);
4230 PSendSysMessage(LANG_SET_FLOAT_FIELD
, GUID_LOPART(guid
), Opcode
,fValue
);
4236 bool ChatHandler::HandleDebugGetValue(const char* args
)
4241 char* px
= strtok((char*)args
, " ");
4242 char* pz
= strtok(NULL
, " ");
4247 Unit
* target
= getSelectedUnit();
4250 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4251 SetSentErrorMessage(true);
4255 uint64 guid
= target
->GetGUID();
4257 uint32 Opcode
= (uint32
)atoi(px
);
4258 if(Opcode
>= target
->GetValuesCount())
4260 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, GUID_LOPART(guid
), target
->GetValuesCount());
4265 bool isint32
= true;
4267 isint32
= (bool)atoi(pz
);
4271 iValue
= target
->GetUInt32Value( Opcode
);
4272 sLog
.outDebug(GetMangosString(LANG_GET_UINT
), GUID_LOPART(guid
), Opcode
, iValue
);
4273 PSendSysMessage(LANG_GET_UINT_FIELD
, GUID_LOPART(guid
), Opcode
, iValue
);
4277 fValue
= target
->GetFloatValue( Opcode
);
4278 sLog
.outDebug(GetMangosString(LANG_GET_FLOAT
), GUID_LOPART(guid
), Opcode
, fValue
);
4279 PSendSysMessage(LANG_GET_FLOAT_FIELD
, GUID_LOPART(guid
), Opcode
, fValue
);
4285 bool ChatHandler::HandleSet32Bit(const char* args
)
4290 char* px
= strtok((char*)args
, " ");
4291 char* py
= strtok(NULL
, " ");
4296 uint32 Opcode
= (uint32
)atoi(px
);
4297 uint32 Value
= (uint32
)atoi(py
);
4298 if (Value
> 32) //uint32 = 32 bits
4301 sLog
.outDebug(GetMangosString(LANG_SET_32BIT
), Opcode
, Value
);
4303 m_session
->GetPlayer( )->SetUInt32Value( Opcode
, 2^Value
);
4305 PSendSysMessage(LANG_SET_32BIT_FIELD
, Opcode
,1);
4309 bool ChatHandler::HandleDebugMod32Value(const char* args
)
4314 char* px
= strtok((char*)args
, " ");
4315 char* py
= strtok(NULL
, " ");
4320 uint32 Opcode
= (uint32
)atoi(px
);
4321 int Value
= atoi(py
);
4323 if(Opcode
>= m_session
->GetPlayer()->GetValuesCount())
4325 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, m_session
->GetPlayer()->GetGUIDLow(), m_session
->GetPlayer( )->GetValuesCount());
4329 sLog
.outDebug(GetMangosString(LANG_CHANGE_32BIT
), Opcode
, Value
);
4331 int CurrentValue
= (int)m_session
->GetPlayer( )->GetUInt32Value( Opcode
);
4333 CurrentValue
+= Value
;
4334 m_session
->GetPlayer( )->SetUInt32Value( Opcode
, (uint32
)CurrentValue
);
4336 PSendSysMessage(LANG_CHANGE_32BIT_FIELD
, Opcode
,CurrentValue
);
4341 bool ChatHandler::HandleTeleAddCommand(const char * args
)
4346 Player
*player
=m_session
->GetPlayer();
4350 std::string name
= args
;
4352 if(objmgr
.GetGameTele(name
))
4354 SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST
);
4355 SetSentErrorMessage(true);
4360 tele
.position_x
= player
->GetPositionX();
4361 tele
.position_y
= player
->GetPositionY();
4362 tele
.position_z
= player
->GetPositionZ();
4363 tele
.orientation
= player
->GetOrientation();
4364 tele
.mapId
= player
->GetMapId();
4367 if(objmgr
.AddGameTele(tele
))
4369 SendSysMessage(LANG_COMMAND_TP_ADDED
);
4373 SendSysMessage(LANG_COMMAND_TP_ADDEDERR
);
4374 SetSentErrorMessage(true);
4381 bool ChatHandler::HandleTeleDelCommand(const char * args
)
4386 std::string name
= args
;
4388 if(!objmgr
.DeleteGameTele(name
))
4390 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
4391 SetSentErrorMessage(true);
4395 SendSysMessage(LANG_COMMAND_TP_DELETED
);
4399 bool ChatHandler::HandleListAurasCommand (const char * /*args*/)
4401 Unit
*unit
= getSelectedUnit();
4404 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4405 SetSentErrorMessage(true);
4409 char const* talentStr
= GetMangosString(LANG_TALENT
);
4410 char const* passiveStr
= GetMangosString(LANG_PASSIVE
);
4412 Unit::AuraMap
const& uAuras
= unit
->GetAuras();
4413 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS
, uAuras
.size());
4414 for (Unit::AuraMap::const_iterator itr
= uAuras
.begin(); itr
!= uAuras
.end(); ++itr
)
4416 bool talent
= GetTalentSpellCost(itr
->second
->GetId()) > 0;
4418 char const* name
= itr
->second
->GetSpellProto()->SpellName
[GetSessionDbcLocale()];
4422 std::ostringstream ss_name
;
4423 ss_name
<< "|cffffffff|Hspell:" << itr
->second
->GetId() << "|h[" << name
<< "]|h|r";
4425 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL
, itr
->second
->GetId(), itr
->second
->GetEffIndex(),
4426 itr
->second
->GetModifier()->m_auraname
, itr
->second
->GetAuraDuration(), itr
->second
->GetAuraMaxDuration(),
4427 ss_name
.str().c_str(),
4428 (itr
->second
->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4429 IS_PLAYER_GUID(itr
->second
->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr
->second
->GetCasterGUID()));
4433 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL
, itr
->second
->GetId(), itr
->second
->GetEffIndex(),
4434 itr
->second
->GetModifier()->m_auraname
, itr
->second
->GetAuraDuration(), itr
->second
->GetAuraMaxDuration(),
4436 (itr
->second
->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4437 IS_PLAYER_GUID(itr
->second
->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr
->second
->GetCasterGUID()));
4440 for (int i
= 0; i
< TOTAL_AURAS
; ++i
)
4442 Unit::AuraList
const& uAuraList
= unit
->GetAurasByType(AuraType(i
));
4443 if (uAuraList
.empty()) continue;
4444 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE
, uAuraList
.size(), i
);
4445 for (Unit::AuraList::const_iterator itr
= uAuraList
.begin(); itr
!= uAuraList
.end(); ++itr
)
4447 bool talent
= GetTalentSpellCost((*itr
)->GetId()) > 0;
4449 char const* name
= (*itr
)->GetSpellProto()->SpellName
[GetSessionDbcLocale()];
4453 std::ostringstream ss_name
;
4454 ss_name
<< "|cffffffff|Hspell:" << (*itr
)->GetId() << "|h[" << name
<< "]|h|r";
4456 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE
, (*itr
)->GetId(), (*itr
)->GetEffIndex(),
4457 ss_name
.str().c_str(),((*itr
)->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4458 IS_PLAYER_GUID((*itr
)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr
)->GetCasterGUID()));
4462 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE
, (*itr
)->GetId(), (*itr
)->GetEffIndex(),
4463 name
,((*itr
)->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4464 IS_PLAYER_GUID((*itr
)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr
)->GetCasterGUID()));
4471 bool ChatHandler::HandleResetAchievementsCommand (const char * args
)
4475 if (!extractPlayerTarget((char*)args
,&target
,&target_guid
))
4479 target
->GetAchievementMgr().Reset();
4481 AchievementMgr::DeleteFromDB(GUID_LOPART(target_guid
));
4486 bool ChatHandler::HandleResetHonorCommand (const char * args
)
4489 if (!extractPlayerTarget((char*)args
,&target
))
4492 target
->SetUInt32Value(PLAYER_FIELD_KILLS
, 0);
4493 target
->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS
, 0);
4494 target
->SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY
, 0);
4495 target
->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION
, 0);
4496 target
->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION
, 0);
4497 target
->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_EARN_HONORABLE_KILL
);
4502 static bool HandleResetStatsOrLevelHelper(Player
* player
)
4504 PlayerInfo
const *info
= objmgr
.GetPlayerInfo(player
->getRace(), player
->getClass());
4505 if(!info
) return false;
4507 ChrClassesEntry
const* cEntry
= sChrClassesStore
.LookupEntry(player
->getClass());
4510 sLog
.outError("Class %u not found in DBC (Wrong DBC files?)",player
->getClass());
4514 uint8 powertype
= cEntry
->powerType
;
4516 // reset m_form if no aura
4517 if(!player
->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT
))
4518 player
->m_form
= FORM_NONE
;
4520 player
->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS
, DEFAULT_WORLD_OBJECT_SIZE
);
4521 player
->SetFloatValue(UNIT_FIELD_COMBATREACH
, 1.5f
);
4523 player
->setFactionForRace(player
->getRace());
4525 player
->SetUInt32Value(UNIT_FIELD_BYTES_0
, ( ( player
->getRace() ) | ( player
->getClass() << 8 ) | ( player
->getGender() << 16 ) | ( powertype
<< 24 ) ) );
4527 // reset only if player not in some form;
4528 if(player
->m_form
==FORM_NONE
)
4530 switch(player
->getGender())
4533 player
->SetDisplayId(info
->displayId_f
);
4534 player
->SetNativeDisplayId(info
->displayId_f
);
4537 player
->SetDisplayId(info
->displayId_m
);
4538 player
->SetNativeDisplayId(info
->displayId_m
);
4545 player
->SetByteValue(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_PVP
);
4546 player
->SetByteValue(UNIT_FIELD_BYTES_2
, 3, player
->m_form
);
4548 player
->SetUInt32Value(UNIT_FIELD_FLAGS
, UNIT_FLAG_PVP_ATTACKABLE
);
4550 //-1 is default value
4551 player
->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX
, uint32(-1));
4553 //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000 );
4557 bool ChatHandler::HandleResetLevelCommand(const char * args
)
4560 if(!extractPlayerTarget((char*)args
,&target
))
4563 if(!HandleResetStatsOrLevelHelper(target
))
4566 // set starting level
4567 uint32 start_level
= target
->getClass() != CLASS_DEATH_KNIGHT
4568 ? sWorld
.getConfig(CONFIG_START_PLAYER_LEVEL
)
4569 : sWorld
.getConfig(CONFIG_START_HEROIC_PLAYER_LEVEL
);
4571 target
->SetLevel(start_level
);
4572 target
->InitRunes();
4573 target
->InitStatsForLevel(true);
4574 target
->InitTaxiNodesForLevel();
4575 target
->InitGlyphsForLevel();
4576 target
->InitTalentForLevel();
4577 target
->SetUInt32Value(PLAYER_XP
,0);
4579 // reset level for pet
4580 if(Pet
* pet
= target
->GetPet())
4581 pet
->SynchronizeLevelWithOwner();
4586 bool ChatHandler::HandleResetStatsCommand(const char * args
)
4589 if (!extractPlayerTarget((char*)args
,&target
))
4592 if (!HandleResetStatsOrLevelHelper(target
))
4595 target
->InitRunes();
4596 target
->InitStatsForLevel(true);
4597 target
->InitTaxiNodesForLevel();
4598 target
->InitGlyphsForLevel();
4599 target
->InitTalentForLevel();
4604 bool ChatHandler::HandleResetSpellsCommand(const char * args
)
4608 std::string target_name
;
4609 if(!extractPlayerTarget((char*)args
,&target
,&target_guid
,&target_name
))
4614 target
->resetSpells();
4616 ChatHandler(target
).SendSysMessage(LANG_RESET_SPELLS
);
4617 if(!m_session
|| m_session
->GetPlayer()!=target
)
4618 PSendSysMessage(LANG_RESET_SPELLS_ONLINE
,GetNameLink(target
).c_str());
4622 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS
), GUID_LOPART(target_guid
));
4623 PSendSysMessage(LANG_RESET_SPELLS_OFFLINE
,target_name
.c_str());
4629 bool ChatHandler::HandleResetTalentsCommand(const char * args
)
4633 std::string target_name
;
4634 if (!extractPlayerTarget((char*)args
,&target
,&target_guid
,&target_name
))
4639 target
->resetTalents(true);
4641 ChatHandler(target
).SendSysMessage(LANG_RESET_TALENTS
);
4642 if (!m_session
|| m_session
->GetPlayer()!=target
)
4643 PSendSysMessage(LANG_RESET_TALENTS_ONLINE
,GetNameLink(target
).c_str());
4647 else if (target_guid
)
4649 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_TALENTS
), GUID_LOPART(target_guid
) );
4650 std::string nameLink
= playerLink(target_name
);
4651 PSendSysMessage(LANG_RESET_TALENTS_OFFLINE
,nameLink
.c_str());
4655 // Try reset talenents as Hunter Pet
4656 Creature
* creature
= getSelectedCreature();
4657 if (creature
&& creature
->isPet() && ((Pet
*)creature
)->getPetType() == HUNTER_PET
)
4659 ((Pet
*)creature
)->resetTalents(true);
4660 Unit
*owner
= creature
->GetOwner();
4661 if (owner
&& owner
->GetTypeId() == TYPEID_PLAYER
)
4663 Player
* owner_player
= (Player
*)owner
;
4664 ChatHandler(owner_player
).SendSysMessage(LANG_RESET_PET_TALENTS
);
4665 if(!m_session
|| m_session
->GetPlayer()!=owner_player
)
4666 PSendSysMessage(LANG_RESET_PET_TALENTS_ONLINE
,GetNameLink(owner_player
).c_str());
4671 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4672 SetSentErrorMessage(true);
4676 bool ChatHandler::HandleResetAllCommand(const char * args
)
4681 std::string casename
= args
;
4683 AtLoginFlags atLogin
;
4685 // Command specially created as single command to prevent using short case names
4686 if(casename
=="spells")
4688 atLogin
= AT_LOGIN_RESET_SPELLS
;
4689 sWorld
.SendWorldText(LANG_RESETALL_SPELLS
);
4691 SendSysMessage(LANG_RESETALL_SPELLS
);
4693 else if(casename
=="talents")
4695 atLogin
= AT_LOGIN_RESET_TALENTS
;
4696 sWorld
.SendWorldText(LANG_RESETALL_TALENTS
);
4698 SendSysMessage(LANG_RESETALL_TALENTS
);
4702 PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE
,args
);
4703 SetSentErrorMessage(true);
4707 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE (at_login & '%u') = '0'",atLogin
,atLogin
);
4708 HashMapHolder
<Player
>::MapType
const& plist
= ObjectAccessor::Instance().GetPlayers();
4709 for(HashMapHolder
<Player
>::MapType::const_iterator itr
= plist
.begin(); itr
!= plist
.end(); ++itr
)
4710 itr
->second
->SetAtLoginFlag(atLogin
);
4715 bool ChatHandler::HandleServerShutDownCancelCommand(const char* /*args*/)
4717 sWorld
.ShutdownCancel();
4721 bool ChatHandler::HandleServerShutDownCommand(const char* args
)
4726 char* time_str
= strtok ((char*) args
, " ");
4727 char* exitcode_str
= strtok (NULL
, "");
4729 int32 time
= atoi (time_str
);
4731 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4732 if ((time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0')) || time
< 0)
4737 int32 exitcode
= atoi (exitcode_str
);
4739 // Handle atoi() errors
4740 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4743 // Exit code should be in range of 0-125, 126-255 is used
4744 // in many shells for their own return codes and code > 255
4745 // is not supported in many others
4746 if (exitcode
< 0 || exitcode
> 125)
4749 sWorld
.ShutdownServ (time
, 0, exitcode
);
4752 sWorld
.ShutdownServ(time
,0,SHUTDOWN_EXIT_CODE
);
4756 bool ChatHandler::HandleServerRestartCommand(const char* args
)
4761 char* time_str
= strtok ((char*) args
, " ");
4762 char* exitcode_str
= strtok (NULL
, "");
4764 int32 time
= atoi (time_str
);
4766 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4767 if(time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0') || time
< 0)
4772 int32 exitcode
= atoi (exitcode_str
);
4774 // Handle atoi() errors
4775 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4778 // Exit code should be in range of 0-125, 126-255 is used
4779 // in many shells for their own return codes and code > 255
4780 // is not supported in many others
4781 if (exitcode
< 0 || exitcode
> 125)
4784 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_RESTART
, exitcode
);
4787 sWorld
.ShutdownServ(time
, SHUTDOWN_MASK_RESTART
, RESTART_EXIT_CODE
);
4791 bool ChatHandler::HandleServerIdleRestartCommand(const char* args
)
4796 char* time_str
= strtok ((char*) args
, " ");
4797 char* exitcode_str
= strtok (NULL
, "");
4799 int32 time
= atoi (time_str
);
4801 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4802 if(time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0') || time
< 0)
4807 int32 exitcode
= atoi (exitcode_str
);
4809 // Handle atoi() errors
4810 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4813 // Exit code should be in range of 0-125, 126-255 is used
4814 // in many shells for their own return codes and code > 255
4815 // is not supported in many others
4816 if (exitcode
< 0 || exitcode
> 125)
4819 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_RESTART
|SHUTDOWN_MASK_IDLE
, exitcode
);
4822 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_RESTART
|SHUTDOWN_MASK_IDLE
,RESTART_EXIT_CODE
);
4826 bool ChatHandler::HandleServerIdleShutDownCommand(const char* args
)
4831 char* time_str
= strtok ((char*) args
, " ");
4832 char* exitcode_str
= strtok (NULL
, "");
4834 int32 time
= atoi (time_str
);
4836 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4837 if(time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0') || time
< 0)
4842 int32 exitcode
= atoi (exitcode_str
);
4844 // Handle atoi() errors
4845 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4848 // Exit code should be in range of 0-125, 126-255 is used
4849 // in many shells for their own return codes and code > 255
4850 // is not supported in many others
4851 if (exitcode
< 0 || exitcode
> 125)
4854 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_IDLE
, exitcode
);
4857 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_IDLE
,SHUTDOWN_EXIT_CODE
);
4861 bool ChatHandler::HandleQuestAdd(const char* args
)
4863 Player
* player
= getSelectedPlayer();
4866 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4867 SetSentErrorMessage(true);
4871 // .addquest #entry'
4872 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4873 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4877 uint32 entry
= atol(cId
);
4879 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
4883 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
,entry
);
4884 SetSentErrorMessage(true);
4888 // check item starting quest (it can work incorrectly if added without item in inventory)
4889 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
4891 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
4895 if (pProto
->StartQuest
== entry
)
4897 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM
, entry
, pProto
->ItemId
);
4898 SetSentErrorMessage(true);
4903 // ok, normal (creature/GO starting) quest
4904 if( player
->CanAddQuest( pQuest
, true ) )
4906 player
->AddQuest( pQuest
, NULL
);
4908 if ( player
->CanCompleteQuest( entry
) )
4909 player
->CompleteQuest( entry
);
4915 bool ChatHandler::HandleQuestRemove(const char* args
)
4917 Player
* player
= getSelectedPlayer();
4920 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4921 SetSentErrorMessage(true);
4925 // .removequest #entry'
4926 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4927 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4931 uint32 entry
= atol(cId
);
4933 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
4937 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
4938 SetSentErrorMessage(true);
4942 // remove all quest entries for 'entry' from quest log
4943 for(uint8 slot
= 0; slot
< MAX_QUEST_LOG_SIZE
; ++slot
)
4945 uint32 quest
= player
->GetQuestSlotQuestId(slot
);
4948 player
->SetQuestSlot(slot
,0);
4950 // we ignore unequippable quest items in this case, its' still be equipped
4951 player
->TakeQuestSourceItem( quest
, false );
4955 // set quest status to not started (will updated in DB at next save)
4956 player
->SetQuestStatus( entry
, QUEST_STATUS_NONE
);
4958 // reset rewarded for restart repeatable quest
4959 player
->getQuestStatusMap()[entry
].m_rewarded
= false;
4961 SendSysMessage(LANG_COMMAND_QUEST_REMOVED
);
4965 bool ChatHandler::HandleQuestComplete(const char* args
)
4967 Player
* player
= getSelectedPlayer();
4970 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4971 SetSentErrorMessage(true);
4975 // .quest complete #entry
4976 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4977 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4981 uint32 entry
= atol(cId
);
4983 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
4985 // If player doesn't have the quest
4986 if(!pQuest
|| player
->GetQuestStatus(entry
) == QUEST_STATUS_NONE
)
4988 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
4989 SetSentErrorMessage(true);
4993 // Add quest items for quests that require items
4994 for(uint8 x
= 0; x
< QUEST_OBJECTIVES_COUNT
; ++x
)
4996 uint32 id
= pQuest
->ReqItemId
[x
];
4997 uint32 count
= pQuest
->ReqItemCount
[x
];
5001 uint32 curItemCount
= player
->GetItemCount(id
,true);
5003 ItemPosCountVec dest
;
5004 uint8 msg
= player
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, id
, count
-curItemCount
);
5005 if( msg
== EQUIP_ERR_OK
)
5007 Item
* item
= player
->StoreNewItem( dest
, id
, true);
5008 player
->SendNewItem(item
,count
-curItemCount
,true,false);
5012 // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
5013 for(uint8 i
= 0; i
< QUEST_OBJECTIVES_COUNT
; ++i
)
5015 uint32 creature
= pQuest
->ReqCreatureOrGOId
[i
];
5016 uint32 creaturecount
= pQuest
->ReqCreatureOrGOCount
[i
];
5018 if(uint32 spell_id
= pQuest
->ReqSpell
[i
])
5020 for(uint16 z
= 0; z
< creaturecount
; ++z
)
5021 player
->CastedCreatureOrGO(creature
,0,spell_id
);
5023 else if(creature
> 0)
5025 for(uint16 z
= 0; z
< creaturecount
; ++z
)
5026 player
->KilledMonster(creature
,0);
5028 else if(creature
< 0)
5030 for(uint16 z
= 0; z
< creaturecount
; ++z
)
5031 player
->CastedCreatureOrGO(creature
,0,0);
5035 // If the quest requires reputation to complete
5036 if(uint32 repFaction
= pQuest
->GetRepObjectiveFaction())
5038 uint32 repValue
= pQuest
->GetRepObjectiveValue();
5039 uint32 curRep
= player
->GetReputationMgr().GetReputation(repFaction
);
5040 if(curRep
< repValue
)
5041 if(FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry(repFaction
))
5042 player
->GetReputationMgr().SetReputation(factionEntry
,repValue
);
5045 // If the quest requires money
5046 int32 ReqOrRewMoney
= pQuest
->GetRewOrReqMoney();
5047 if(ReqOrRewMoney
< 0)
5048 player
->ModifyMoney(-ReqOrRewMoney
);
5050 player
->CompleteQuest(entry
);
5054 bool ChatHandler::HandleBanAccountCommand(const char* args
)
5056 return HandleBanHelper(BAN_ACCOUNT
,args
);
5059 bool ChatHandler::HandleBanCharacterCommand(const char* args
)
5061 return HandleBanHelper(BAN_CHARACTER
,args
);
5064 bool ChatHandler::HandleBanIPCommand(const char* args
)
5066 return HandleBanHelper(BAN_IP
,args
);
5069 bool ChatHandler::HandleBanHelper(BanMode mode
, const char* args
)
5074 char* cnameOrIP
= strtok ((char*)args
, " ");
5078 std::string nameOrIP
= cnameOrIP
;
5080 char* duration
= strtok (NULL
," ");
5081 if(!duration
|| !atoi(duration
))
5084 char* reason
= strtok (NULL
,"");
5091 if(!AccountMgr::normilizeString(nameOrIP
))
5093 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
5094 SetSentErrorMessage(true);
5099 if(!normalizePlayerName(nameOrIP
))
5101 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5102 SetSentErrorMessage(true);
5107 if(!IsIPAddress(nameOrIP
.c_str()))
5112 switch(sWorld
.BanAccount(mode
, nameOrIP
, duration
, reason
,m_session
? m_session
->GetPlayerName() : ""))
5115 if(atoi(duration
)>0)
5116 PSendSysMessage(LANG_BAN_YOUBANNED
,nameOrIP
.c_str(),secsToTimeString(TimeStringToSecs(duration
),true).c_str(),reason
);
5118 PSendSysMessage(LANG_BAN_YOUPERMBANNED
,nameOrIP
.c_str(),reason
);
5120 case BAN_SYNTAX_ERROR
:
5126 PSendSysMessage(LANG_BAN_NOTFOUND
,"account",nameOrIP
.c_str());
5129 PSendSysMessage(LANG_BAN_NOTFOUND
,"character",nameOrIP
.c_str());
5132 PSendSysMessage(LANG_BAN_NOTFOUND
,"ip",nameOrIP
.c_str());
5135 SetSentErrorMessage(true);
5142 bool ChatHandler::HandleUnBanAccountCommand(const char* args
)
5144 return HandleUnBanHelper(BAN_ACCOUNT
,args
);
5147 bool ChatHandler::HandleUnBanCharacterCommand(const char* args
)
5149 return HandleUnBanHelper(BAN_CHARACTER
,args
);
5152 bool ChatHandler::HandleUnBanIPCommand(const char* args
)
5154 return HandleUnBanHelper(BAN_IP
,args
);
5157 bool ChatHandler::HandleUnBanHelper(BanMode mode
, const char* args
)
5162 char* cnameOrIP
= strtok ((char*)args
, " ");
5166 std::string nameOrIP
= cnameOrIP
;
5171 if(!AccountMgr::normilizeString(nameOrIP
))
5173 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
5174 SetSentErrorMessage(true);
5179 if(!normalizePlayerName(nameOrIP
))
5181 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5182 SetSentErrorMessage(true);
5187 if(!IsIPAddress(nameOrIP
.c_str()))
5192 if(sWorld
.RemoveBanAccount(mode
,nameOrIP
))
5193 PSendSysMessage(LANG_UNBAN_UNBANNED
,nameOrIP
.c_str());
5195 PSendSysMessage(LANG_UNBAN_ERROR
,nameOrIP
.c_str());
5200 bool ChatHandler::HandleBanInfoAccountCommand(const char* args
)
5205 char* cname
= strtok((char*)args
, "");
5209 std::string account_name
= cname
;
5210 if(!AccountMgr::normilizeString(account_name
))
5212 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5213 SetSentErrorMessage(true);
5217 uint32 accountid
= accmgr
.GetId(account_name
);
5220 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5224 return HandleBanInfoHelper(accountid
,account_name
.c_str());
5227 bool ChatHandler::HandleBanInfoCharacterCommand(const char* args
)
5231 if(!extractPlayerTarget((char*)args
,&target
,&target_guid
))
5234 uint32 accountid
= target
? target
->GetSession()->GetAccountId() : objmgr
.GetPlayerAccountIdByGUID(target_guid
);
5236 std::string accountname
;
5237 if(!accmgr
.GetName(accountid
,accountname
))
5239 PSendSysMessage(LANG_BANINFO_NOCHARACTER
);
5243 return HandleBanInfoHelper(accountid
,accountname
.c_str());
5246 bool ChatHandler::HandleBanInfoHelper(uint32 accountid
, char const* accountname
)
5248 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
);
5251 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN
, accountname
);
5255 PSendSysMessage(LANG_BANINFO_BANHISTORY
,accountname
);
5258 Field
* fields
= result
->Fetch();
5260 time_t unbandate
= time_t(fields
[3].GetUInt64());
5261 bool active
= false;
5262 if(fields
[2].GetBool() && (fields
[1].GetUInt64() == (uint64
)0 ||unbandate
>= time(NULL
)) )
5264 bool permanent
= (fields
[1].GetUInt64() == (uint64
)0);
5265 std::string bantime
= permanent
?GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[1].GetUInt64(), true);
5266 PSendSysMessage(LANG_BANINFO_HISTORYENTRY
,
5267 fields
[0].GetString(), bantime
.c_str(), active
? GetMangosString(LANG_BANINFO_YES
):GetMangosString(LANG_BANINFO_NO
), fields
[4].GetString(), fields
[5].GetString());
5268 }while (result
->NextRow());
5274 bool ChatHandler::HandleBanInfoIPCommand(const char* args
)
5279 char* cIP
= strtok ((char*)args
, "");
5283 if (!IsIPAddress(cIP
))
5286 std::string IP
= cIP
;
5288 loginDatabase
.escape_string(IP
);
5289 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'",IP
.c_str());
5292 PSendSysMessage(LANG_BANINFO_NOIP
);
5296 Field
*fields
= result
->Fetch();
5297 bool permanent
= !fields
[6].GetUInt64();
5298 PSendSysMessage(LANG_BANINFO_IPENTRY
,
5299 fields
[0].GetString(), fields
[1].GetString(), permanent
? GetMangosString(LANG_BANINFO_NEVER
):fields
[2].GetString(),
5300 permanent
? GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[3].GetUInt64(), true).c_str(), fields
[4].GetString(), fields
[5].GetString());
5305 bool ChatHandler::HandleBanListCharacterCommand(const char* args
)
5307 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5309 char* cFilter
= strtok ((char*)args
, " ");
5313 std::string filter
= cFilter
;
5314 loginDatabase
.escape_string(filter
);
5315 QueryResult
* result
= CharacterDatabase
.PQuery("SELECT account FROM characters WHERE name "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'"),filter
.c_str());
5318 PSendSysMessage(LANG_BANLIST_NOCHARACTER
);
5322 return HandleBanListHelper(result
);
5325 bool ChatHandler::HandleBanListAccountCommand(const char* args
)
5327 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5329 char* cFilter
= strtok((char*)args
, " ");
5330 std::string filter
= cFilter
? cFilter
: "";
5331 loginDatabase
.escape_string(filter
);
5333 QueryResult
* result
;
5337 result
= loginDatabase
.Query("SELECT account.id, username FROM account, account_banned"
5338 " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
5342 result
= loginDatabase
.PQuery("SELECT account.id, username FROM account, account_banned"
5343 " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
5349 PSendSysMessage(LANG_BANLIST_NOACCOUNT
);
5353 return HandleBanListHelper(result
);
5356 bool ChatHandler::HandleBanListHelper(QueryResult
* result
)
5358 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT
);
5360 // Chat short output
5365 Field
* fields
= result
->Fetch();
5366 uint32 accountid
= fields
[0].GetUInt32();
5368 QueryResult
* banresult
= loginDatabase
.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid
);
5371 Field
* fields2
= banresult
->Fetch();
5372 PSendSysMessage("%s",fields2
[0].GetString());
5375 } while (result
->NextRow());
5377 // Console wide output
5380 SendSysMessage(LANG_BANLIST_ACCOUNTS
);
5381 SendSysMessage("===============================================================================");
5382 SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER
);
5385 SendSysMessage("-------------------------------------------------------------------------------");
5386 Field
*fields
= result
->Fetch();
5387 uint32 account_id
= fields
[0].GetUInt32 ();
5389 std::string account_name
;
5391 // "account" case, name can be get in same query
5392 if(result
->GetFieldCount() > 1)
5393 account_name
= fields
[1].GetCppString();
5394 // "character" case, name need extract from another DB
5396 accmgr
.GetName (account_id
,account_name
);
5398 // No SQL injection. id is uint32.
5399 QueryResult
*banInfo
= loginDatabase
.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id
);
5402 Field
*fields2
= banInfo
->Fetch();
5405 time_t t_ban
= fields2
[0].GetUInt64();
5406 tm
* aTm_ban
= localtime(&t_ban
);
5408 if (fields2
[0].GetUInt64() == fields2
[1].GetUInt64())
5410 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5411 account_name
.c_str(),aTm_ban
->tm_year
%100, aTm_ban
->tm_mon
+1, aTm_ban
->tm_mday
, aTm_ban
->tm_hour
, aTm_ban
->tm_min
,
5412 fields2
[2].GetString(),fields2
[3].GetString());
5416 time_t t_unban
= fields2
[1].GetUInt64();
5417 tm
* aTm_unban
= localtime(&t_unban
);
5418 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5419 account_name
.c_str(),aTm_ban
->tm_year
%100, aTm_ban
->tm_mon
+1, aTm_ban
->tm_mday
, aTm_ban
->tm_hour
, aTm_ban
->tm_min
,
5420 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5421 fields2
[2].GetString(),fields2
[3].GetString());
5423 }while ( banInfo
->NextRow() );
5426 }while( result
->NextRow() );
5427 SendSysMessage("===============================================================================");
5434 bool ChatHandler::HandleBanListIPCommand(const char* args
)
5436 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5438 char* cFilter
= strtok((char*)args
, " ");
5439 std::string filter
= cFilter
? cFilter
: "";
5440 loginDatabase
.escape_string(filter
);
5442 QueryResult
* result
;
5446 result
= loginDatabase
.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5447 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
5448 " ORDER BY unbandate" );
5452 result
= loginDatabase
.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5453 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")
5454 " ORDER BY unbandate",filter
.c_str() );
5459 PSendSysMessage(LANG_BANLIST_NOIP
);
5463 PSendSysMessage(LANG_BANLIST_MATCHINGIP
);
5464 // Chat short output
5469 Field
* fields
= result
->Fetch();
5470 PSendSysMessage("%s",fields
[0].GetString());
5471 } while (result
->NextRow());
5473 // Console wide output
5476 SendSysMessage(LANG_BANLIST_IPS
);
5477 SendSysMessage("===============================================================================");
5478 SendSysMessage(LANG_BANLIST_IPS_HEADER
);
5481 SendSysMessage("-------------------------------------------------------------------------------");
5482 Field
*fields
= result
->Fetch();
5483 time_t t_ban
= fields
[1].GetUInt64();
5484 tm
* aTm_ban
= localtime(&t_ban
);
5485 if ( fields
[1].GetUInt64() == fields
[2].GetUInt64() )
5487 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5488 fields
[0].GetString(), aTm_ban
->tm_year
%100, aTm_ban
->tm_mon
+1, aTm_ban
->tm_mday
, aTm_ban
->tm_hour
, aTm_ban
->tm_min
,
5489 fields
[3].GetString(), fields
[4].GetString());
5493 time_t t_unban
= fields
[2].GetUInt64();
5494 tm
* aTm_unban
= localtime(&t_unban
);
5495 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5496 fields
[0].GetString(), aTm_ban
->tm_year
%100, aTm_ban
->tm_mon
+1, aTm_ban
->tm_mday
, aTm_ban
->tm_hour
, aTm_ban
->tm_min
,
5497 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5498 fields
[3].GetString(), fields
[4].GetString());
5500 }while( result
->NextRow() );
5501 SendSysMessage("===============================================================================");
5508 bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
5510 Player
* pl
= m_session
->GetPlayer();
5512 // accept only explicitly selected target (not implicitly self targeting case)
5513 Unit
* target
= getSelectedUnit();
5514 if(pl
->GetSelection() && target
)
5516 if(target
->GetTypeId()!=TYPEID_UNIT
)
5518 SendSysMessage(LANG_SELECT_CREATURE
);
5519 SetSentErrorMessage(true);
5523 if(target
->isDead())
5524 ((Creature
*)target
)->Respawn();
5528 CellPair
p(MaNGOS::ComputeCellPair(pl
->GetPositionX(), pl
->GetPositionY()));
5530 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
5533 MaNGOS::RespawnDo u_do
;
5534 MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
> worker(pl
,u_do
);
5536 TypeContainerVisitor
<MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
>, GridTypeMapContainer
> obj_worker(worker
);
5537 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
5538 cell_lock
->Visit(cell_lock
, obj_worker
, *pl
->GetMap());
5543 bool ChatHandler::HandleGMFlyCommand(const char* args
)
5548 Player
*target
= getSelectedPlayer();
5550 target
= m_session
->GetPlayer();
5552 WorldPacket
data(12);
5553 if (strncmp(args
, "on", 3) == 0)
5554 data
.SetOpcode(SMSG_MOVE_SET_CAN_FLY
);
5555 else if (strncmp(args
, "off", 4) == 0)
5556 data
.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY
);
5559 SendSysMessage(LANG_USE_BOL
);
5562 data
.append(target
->GetPackGUID());
5563 data
<< uint32(0); // unknown
5564 target
->SendMessageToSet(&data
, true);
5565 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS
, GetNameLink(target
).c_str(), args
);
5569 bool ChatHandler::HandlePDumpLoadCommand(const char *args
)
5574 char * file
= strtok((char*)args
, " ");
5578 char * account
= strtok(NULL
, " ");
5582 std::string account_name
= account
;
5583 if(!AccountMgr::normilizeString(account_name
))
5585 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5586 SetSentErrorMessage(true);
5590 uint32 account_id
= accmgr
.GetId(account_name
);
5593 account_id
= atoi(account
); // use original string
5596 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5597 SetSentErrorMessage(true);
5602 if(!accmgr
.GetName(account_id
,account_name
))
5604 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5605 SetSentErrorMessage(true);
5609 char* guid_str
= NULL
;
5610 char* name_str
= strtok(NULL
, " ");
5616 // normalize the name if specified and check if it exists
5617 if(!normalizePlayerName(name
))
5619 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5620 SetSentErrorMessage(true);
5624 if(!ObjectMgr::IsValidName(name
,true))
5626 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5627 SetSentErrorMessage(true);
5631 guid_str
= strtok(NULL
, " ");
5638 guid
= atoi(guid_str
);
5641 PSendSysMessage(LANG_INVALID_CHARACTER_GUID
);
5642 SetSentErrorMessage(true);
5646 if(objmgr
.GetPlayerAccountIdByGUID(guid
))
5648 PSendSysMessage(LANG_CHARACTER_GUID_IN_USE
,guid
);
5649 SetSentErrorMessage(true);
5654 switch(PlayerDumpReader().LoadDump(file
, account_id
, name
, guid
))
5657 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS
);
5659 case DUMP_FILE_OPEN_ERROR
:
5660 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
5661 SetSentErrorMessage(true);
5663 case DUMP_FILE_BROKEN
:
5664 PSendSysMessage(LANG_DUMP_BROKEN
,file
);
5665 SetSentErrorMessage(true);
5667 case DUMP_TOO_MANY_CHARS
:
5668 PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL
,account_name
.c_str(),account_id
);
5669 SetSentErrorMessage(true);
5672 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED
);
5673 SetSentErrorMessage(true);
5680 bool ChatHandler::HandlePDumpWriteCommand(const char *args
)
5685 char* file
= strtok((char*)args
, " ");
5686 char* p2
= strtok(NULL
, " ");
5692 // character name can't start from number
5693 if (isNumeric(p2
[0]))
5697 std::string name
= extractPlayerNameFromLink(p2
);
5700 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5701 SetSentErrorMessage(true);
5705 guid
= objmgr
.GetPlayerGUIDByName(name
);
5708 if(!objmgr
.GetPlayerAccountIdByGUID(guid
))
5710 PSendSysMessage(LANG_PLAYER_NOT_FOUND
);
5711 SetSentErrorMessage(true);
5715 switch(PlayerDumpWriter().WriteDump(file
, guid
))
5718 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS
);
5720 case DUMP_FILE_OPEN_ERROR
:
5721 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
5722 SetSentErrorMessage(true);
5725 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED
);
5726 SetSentErrorMessage(true);
5733 bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
5735 Unit
* unit
= getSelectedUnit();
5738 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5739 SetSentErrorMessage(true);
5743 PSendSysMessage(LANG_MOVEGENS_LIST
,(unit
->GetTypeId()==TYPEID_PLAYER
? "Player" : "Creature" ),unit
->GetGUIDLow());
5745 MotionMaster
* mm
= unit
->GetMotionMaster();
5746 for(MotionMaster::const_iterator itr
= mm
->begin(); itr
!= mm
->end(); ++itr
)
5748 switch((*itr
)->GetMovementGeneratorType())
5750 case IDLE_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_IDLE
); break;
5751 case RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_RANDOM
); break;
5752 case WAYPOINT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_WAYPOINT
); break;
5753 case ANIMAL_RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_ANIMAL_RANDOM
); break;
5754 case CONFUSED_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_CONFUSED
); break;
5755 case TARGETED_MOTION_TYPE
:
5757 if(unit
->GetTypeId()==TYPEID_PLAYER
)
5759 TargetedMovementGenerator
<Player
> const* mgen
= static_cast<TargetedMovementGenerator
<Player
> const*>(*itr
);
5760 Unit
* target
= mgen
->GetTarget();
5762 PSendSysMessage(LANG_MOVEGENS_TARGETED_PLAYER
,target
->GetName(),target
->GetGUIDLow());
5764 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL
);
5768 TargetedMovementGenerator
<Creature
> const* mgen
= static_cast<TargetedMovementGenerator
<Creature
> const*>(*itr
);
5769 Unit
* target
= mgen
->GetTarget();
5771 PSendSysMessage(LANG_MOVEGENS_TARGETED_CREATURE
,target
->GetName(),target
->GetGUIDLow());
5773 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL
);
5777 case HOME_MOTION_TYPE
:
5778 if(unit
->GetTypeId()==TYPEID_UNIT
)
5781 (*itr
)->GetDestination(x
,y
,z
);
5782 PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE
,x
,y
,z
);
5785 SendSysMessage(LANG_MOVEGENS_HOME_PLAYER
);
5787 case FLIGHT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FLIGHT
); break;
5788 case POINT_MOTION_TYPE
:
5791 (*itr
)->GetDestination(x
,y
,z
);
5792 PSendSysMessage(LANG_MOVEGENS_POINT
,x
,y
,z
);
5795 case FLEEING_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FEAR
); break;
5796 case DISTRACT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_DISTRACT
); break;
5798 PSendSysMessage(LANG_MOVEGENS_UNKNOWN
,(*itr
)->GetMovementGeneratorType());
5805 bool ChatHandler::HandleServerPLimitCommand(const char *args
)
5809 char* param
= strtok((char*)args
, " ");
5813 int l
= strlen(param
);
5815 if( strncmp(param
,"player",l
) == 0 )
5816 sWorld
.SetPlayerLimit(-SEC_PLAYER
);
5817 else if(strncmp(param
,"moderator",l
) == 0 )
5818 sWorld
.SetPlayerLimit(-SEC_MODERATOR
);
5819 else if(strncmp(param
,"gamemaster",l
) == 0 )
5820 sWorld
.SetPlayerLimit(-SEC_GAMEMASTER
);
5821 else if(strncmp(param
,"administrator",l
) == 0 )
5822 sWorld
.SetPlayerLimit(-SEC_ADMINISTRATOR
);
5823 else if(strncmp(param
,"reset",l
) == 0 )
5824 sWorld
.SetPlayerLimit( sConfig
.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT
) );
5827 int val
= atoi(param
);
5828 if(val
< -SEC_ADMINISTRATOR
) val
= -SEC_ADMINISTRATOR
;
5830 sWorld
.SetPlayerLimit(val
);
5833 // kick all low security level players
5834 if(sWorld
.GetPlayerAmountLimit() > SEC_PLAYER
)
5835 sWorld
.KickAllLess(sWorld
.GetPlayerSecurityLimit());
5838 uint32 pLimit
= sWorld
.GetPlayerAmountLimit();
5839 AccountTypes allowedAccountType
= sWorld
.GetPlayerSecurityLimit();
5840 char const* secName
= "";
5841 switch(allowedAccountType
)
5843 case SEC_PLAYER
: secName
= "Player"; break;
5844 case SEC_MODERATOR
: secName
= "Moderator"; break;
5845 case SEC_GAMEMASTER
: secName
= "Gamemaster"; break;
5846 case SEC_ADMINISTRATOR
: secName
= "Administrator"; break;
5847 default: secName
= "<unknown>"; break;
5850 PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit
,secName
);
5855 bool ChatHandler::HandleCastCommand(const char* args
)
5860 Unit
* target
= getSelectedUnit();
5864 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5865 SetSentErrorMessage(true);
5869 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5870 uint32 spell
= extractSpellIdFromLink((char*)args
);
5874 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5878 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5880 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5881 SetSentErrorMessage(true);
5885 char* trig_str
= strtok(NULL
, " ");
5888 int l
= strlen(trig_str
);
5889 if(strncmp(trig_str
,"triggered",l
) != 0 )
5893 bool triggered
= (trig_str
!= NULL
);
5895 m_session
->GetPlayer()->CastSpell(target
,spell
,triggered
);
5900 bool ChatHandler::HandleCastBackCommand(const char* args
)
5902 Creature
* caster
= getSelectedCreature();
5906 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5907 SetSentErrorMessage(true);
5911 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
5912 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5913 uint32 spell
= extractSpellIdFromLink((char*)args
);
5914 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
5917 char* trig_str
= strtok(NULL
, " ");
5920 int l
= strlen(trig_str
);
5921 if(strncmp(trig_str
,"triggered",l
) != 0 )
5925 bool triggered
= (trig_str
!= NULL
);
5927 // update orientation at server
5928 caster
->SetOrientation(caster
->GetAngle(m_session
->GetPlayer()));
5932 caster
->BuildHeartBeatMsg(&data
);
5933 caster
->SendMessageToSet(&data
,true);
5935 caster
->CastSpell(m_session
->GetPlayer(),spell
,triggered
);
5940 bool ChatHandler::HandleCastDistCommand(const char* args
)
5945 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5946 uint32 spell
= extractSpellIdFromLink((char*)args
);
5950 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5954 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5956 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5957 SetSentErrorMessage(true);
5961 char *distStr
= strtok(NULL
, " ");
5966 sscanf(distStr
, "%f", &dist
);
5968 char* trig_str
= strtok(NULL
, " ");
5971 int l
= strlen(trig_str
);
5972 if(strncmp(trig_str
,"triggered",l
) != 0 )
5976 bool triggered
= (trig_str
!= NULL
);
5979 m_session
->GetPlayer()->GetClosePoint(x
,y
,z
,dist
);
5981 m_session
->GetPlayer()->CastSpell(x
,y
,z
,spell
,triggered
);
5985 bool ChatHandler::HandleCastTargetCommand(const char* args
)
5987 Creature
* caster
= getSelectedCreature();
5991 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5992 SetSentErrorMessage(true);
5996 if(!caster
->getVictim())
5998 SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM
);
5999 SetSentErrorMessage(true);
6003 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6004 uint32 spell
= extractSpellIdFromLink((char*)args
);
6005 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
6008 char* trig_str
= strtok(NULL
, " ");
6011 int l
= strlen(trig_str
);
6012 if(strncmp(trig_str
,"triggered",l
) != 0 )
6016 bool triggered
= (trig_str
!= NULL
);
6018 // update orientation at server
6019 caster
->SetOrientation(caster
->GetAngle(m_session
->GetPlayer()));
6023 caster
->BuildHeartBeatMsg(&data
);
6024 caster
->SendMessageToSet(&data
,true);
6026 caster
->CastSpell(caster
->getVictim(),spell
,triggered
);
6032 ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
6033 Without this function 3rd party scripting library will get linking errors (unresolved external)
6034 when attempting to use the PointMovementGenerator
6036 bool ChatHandler::HandleComeToMeCommand(const char *args
)
6038 Creature
* caster
= getSelectedCreature();
6042 SendSysMessage(LANG_SELECT_CREATURE
);
6043 SetSentErrorMessage(true);
6047 char* newFlagStr
= strtok((char*)args
, " ");
6052 uint32 newFlags
= atoi(newFlagStr
);
6054 caster
->SetUnitMovementFlags(newFlags
);
6056 Player
* pl
= m_session
->GetPlayer();
6058 caster
->GetMotionMaster()->MovePoint(0, pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ());
6062 bool ChatHandler::HandleCastSelfCommand(const char* args
)
6067 Unit
* target
= getSelectedUnit();
6071 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
6072 SetSentErrorMessage(true);
6076 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6077 uint32 spell
= extractSpellIdFromLink((char*)args
);
6081 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
6085 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
6087 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
6088 SetSentErrorMessage(true);
6092 target
->CastSpell(target
,spell
,false);
6097 std::string
GetTimeString(uint32 time
)
6099 uint16 days
= time
/ DAY
, hours
= (time
% DAY
) / HOUR
, minute
= (time
% HOUR
) / MINUTE
;
6100 std::ostringstream ss
;
6101 if(days
) ss
<< days
<< "d ";
6102 if(hours
) ss
<< hours
<< "h ";
6103 ss
<< minute
<< "m";
6107 bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
6109 Player
* player
= getSelectedPlayer();
6110 if (!player
) player
= m_session
->GetPlayer();
6112 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; ++i
)
6114 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(i
);
6115 for(Player::BoundInstancesMap::const_iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
6117 InstanceSave
*save
= itr
->second
.save
;
6118 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
6119 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());
6123 PSendSysMessage("player binds: %d", counter
);
6125 Group
*group
= player
->GetGroup();
6128 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; ++i
)
6130 Group::BoundInstancesMap
&binds
= group
->GetBoundInstances(i
);
6131 for(Group::BoundInstancesMap::const_iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
6133 InstanceSave
*save
= itr
->second
.save
;
6134 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
6135 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());
6140 PSendSysMessage("group binds: %d", counter
);
6145 bool ChatHandler::HandleInstanceUnbindCommand(const char* args
)
6150 std::string cmd
= args
;
6153 Player
* player
= getSelectedPlayer();
6154 if (!player
) player
= m_session
->GetPlayer();
6156 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; ++i
)
6158 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(i
);
6159 for(Player::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end();)
6161 if(itr
->first
!= player
->GetMapId())
6163 InstanceSave
*save
= itr
->second
.save
;
6164 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
6165 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());
6166 player
->UnbindInstance(itr
, i
);
6173 PSendSysMessage("instances unbound: %d", counter
);
6178 bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
6180 PSendSysMessage("instances loaded: %d", MapManager::Instance().GetNumInstances());
6181 PSendSysMessage("players in instances: %d", MapManager::Instance().GetNumPlayersInInstances());
6182 PSendSysMessage("instance saves: %d", sInstanceSaveManager
.GetNumInstanceSaves());
6183 PSendSysMessage("players bound: %d", sInstanceSaveManager
.GetNumBoundPlayersTotal());
6184 PSendSysMessage("groups bound: %d", sInstanceSaveManager
.GetNumBoundGroupsTotal());
6188 bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
6190 Player
* pl
= m_session
->GetPlayer();
6192 Map
* map
= pl
->GetMap();
6193 if (!map
->IsDungeon())
6195 PSendSysMessage("Map is not a dungeon.");
6196 SetSentErrorMessage(true);
6200 if (!((InstanceMap
*)map
)->GetInstanceData())
6202 PSendSysMessage("Map has no instance data.");
6203 SetSentErrorMessage(true);
6207 ((InstanceMap
*)map
)->GetInstanceData()->SaveToDB();
6211 /// Display the list of GMs
6212 bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
6214 ///- Get the accounts with GM Level >0
6215 QueryResult
*result
= loginDatabase
.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
6218 SendSysMessage(LANG_GMLIST
);
6219 SendSysMessage("========================");
6220 SendSysMessage(LANG_GMLIST_HEADER
);
6221 SendSysMessage("========================");
6223 ///- Circle through them. Display username and GM level
6226 Field
*fields
= result
->Fetch();
6227 PSendSysMessage("|%15s|%6s|", fields
[0].GetString(),fields
[1].GetString());
6228 }while( result
->NextRow() );
6230 PSendSysMessage("========================");
6234 PSendSysMessage(LANG_GMLIST_EMPTY
);
6238 /// Define the 'Message of the day' for the realm
6239 bool ChatHandler::HandleServerSetMotdCommand(const char* args
)
6241 sWorld
.SetMotd(args
);
6242 PSendSysMessage(LANG_MOTD_NEW
, args
);
6246 /// Set/Unset the expansion level for an account
6247 bool ChatHandler::HandleAccountSetAddonCommand(const char* args
)
6249 ///- Get the command line arguments
6250 char *szAcc
= strtok((char*)args
," ");
6251 char *szExp
= strtok(NULL
," ");
6256 std::string account_name
;
6261 Player
* player
= getSelectedPlayer();
6265 account_id
= player
->GetSession()->GetAccountId();
6266 accmgr
.GetName(account_id
,account_name
);
6271 ///- Convert Account name to Upper Format
6272 account_name
= szAcc
;
6273 if(!AccountMgr::normilizeString(account_name
))
6275 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
6276 SetSentErrorMessage(true);
6280 account_id
= accmgr
.GetId(account_name
);
6283 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
6284 SetSentErrorMessage(true);
6290 // Let set addon state only for lesser (strong) security level
6291 // or to self account
6292 if (m_session
&& m_session
->GetAccountId () != account_id
&&
6293 HasLowerSecurityAccount (NULL
,account_id
,true))
6296 int lev
=atoi(szExp
); //get int anyway (0 if error)
6301 loginDatabase
.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev
,account_id
);
6302 PSendSysMessage(LANG_ACCOUNT_SETADDON
,account_name
.c_str(),account_id
,lev
);
6306 //Send items by mail
6307 bool ChatHandler::HandleSendItemsCommand(const char* args
)
6309 // format: name "subject text" "mail text" item1[:count1] item2[:count2] ... item12[:count12]
6311 uint64 receiver_guid
;
6312 std::string receiver_name
;
6313 if(!extractPlayerTarget((char*)args
,&receiver
,&receiver_guid
,&receiver_name
))
6316 char* tail1
= strtok(NULL
, "");
6320 char* msgSubject
= extractQuotedArg(tail1
);
6324 char* tail2
= strtok(NULL
, "");
6328 char* msgText
= extractQuotedArg(tail2
);
6332 // msgSubject, msgText isn't NUL after prev. check
6333 std::string subject
= msgSubject
;
6334 std::string text
= msgText
;
6337 typedef std::pair
<uint32
,uint32
> ItemPair
;
6338 typedef std::list
< ItemPair
> ItemPairs
;
6341 // get all tail string
6342 char* tail
= strtok(NULL
, "");
6344 // get from tail next item str
6345 while(char* itemStr
= strtok(tail
, " "))
6348 tail
= strtok(NULL
, "");
6351 char* itemIdStr
= strtok(itemStr
, ":");
6352 char* itemCountStr
= strtok(NULL
, " ");
6354 uint32 item_id
= atoi(itemIdStr
);
6358 ItemPrototype
const* item_proto
= objmgr
.GetItemPrototype(item_id
);
6361 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
6362 SetSentErrorMessage(true);
6366 uint32 item_count
= itemCountStr
? atoi(itemCountStr
) : 1;
6367 if(item_count
< 1 || item_proto
->MaxCount
> 0 && item_count
> uint32(item_proto
->MaxCount
))
6369 PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT
, item_count
,item_id
);
6370 SetSentErrorMessage(true);
6374 while(item_count
> item_proto
->GetMaxStackSize())
6376 items
.push_back(ItemPair(item_id
,item_proto
->GetMaxStackSize()));
6377 item_count
-= item_proto
->GetMaxStackSize();
6380 items
.push_back(ItemPair(item_id
,item_count
));
6382 if(items
.size() > MAX_MAIL_ITEMS
)
6384 PSendSysMessage(LANG_COMMAND_MAIL_ITEMS_LIMIT
, MAX_MAIL_ITEMS
);
6385 SetSentErrorMessage(true);
6390 // from console show not existed sender
6391 uint32 sender_guidlo
= m_session
? m_session
->GetPlayer()->GetGUIDLow() : 0;
6393 uint32 messagetype
= MAIL_NORMAL
;
6394 uint32 stationery
= MAIL_STATIONERY_GM
;
6395 uint32 itemTextId
= !text
.empty() ? objmgr
.CreateItemText( text
) : 0;
6398 MailItemsInfo mi
; // item list preparing
6400 for(ItemPairs::const_iterator itr
= items
.begin(); itr
!= items
.end(); ++itr
)
6402 if(Item
* item
= Item::CreateItem(itr
->first
,itr
->second
,m_session
? m_session
->GetPlayer() : 0))
6404 item
->SaveToDB(); // save for prevent lost at next mail load, if send fail then item will deleted
6405 mi
.AddItem(item
->GetGUIDLow(), item
->GetEntry(), item
);
6409 WorldSession::SendMailTo(receiver
,messagetype
, stationery
, sender_guidlo
, GUID_LOPART(receiver_guid
), subject
, itemTextId
, &mi
, 0, 0, MAIL_CHECK_MASK_NONE
);
6411 std::string nameLink
= playerLink(receiver_name
);
6412 PSendSysMessage(LANG_MAIL_SENT
, nameLink
.c_str());
6416 ///Send money by mail
6417 bool ChatHandler::HandleSendMoneyCommand(const char* args
)
6419 /// format: name "subject text" "mail text" money
6422 uint64 receiver_guid
;
6423 std::string receiver_name
;
6424 if(!extractPlayerTarget((char*)args
,&receiver
,&receiver_guid
,&receiver_name
))
6427 char* tail1
= strtok(NULL
, "");
6431 char* msgSubject
= extractQuotedArg(tail1
);
6435 char* tail2
= strtok(NULL
, "");
6439 char* msgText
= extractQuotedArg(tail2
);
6443 char* money_str
= strtok(NULL
, "");
6444 int32 money
= money_str
? atoi(money_str
) : 0;
6448 // msgSubject, msgText isn't NUL after prev. check
6449 std::string subject
= msgSubject
;
6450 std::string text
= msgText
;
6452 // from console show not existed sender
6453 uint32 sender_guidlo
= m_session
? m_session
->GetPlayer()->GetGUIDLow() : 0;
6455 uint32 messagetype
= MAIL_NORMAL
;
6456 uint32 stationery
= MAIL_STATIONERY_GM
;
6457 uint32 itemTextId
= !text
.empty() ? objmgr
.CreateItemText( text
) : 0;
6459 WorldSession::SendMailTo(receiver
,messagetype
, stationery
, sender_guidlo
, GUID_LOPART(receiver_guid
), subject
, itemTextId
, NULL
, money
, 0, MAIL_CHECK_MASK_NONE
);
6461 std::string nameLink
= playerLink(receiver_name
);
6462 PSendSysMessage(LANG_MAIL_SENT
, nameLink
.c_str());
6466 /// Send a message to a player in game
6467 bool ChatHandler::HandleSendMessageCommand(const char* args
)
6469 ///- Find the player
6471 if(!extractPlayerTarget((char*)args
,&rPlayer
))
6474 char* msg_str
= strtok(NULL
, "");
6478 ///- Check that he is not logging out.
6479 if(rPlayer
->GetSession()->isLogingOut())
6481 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6482 SetSentErrorMessage(true);
6486 ///- Send the message
6487 //Use SendAreaTriggerMessage for fastest delivery.
6488 rPlayer
->GetSession()->SendAreaTriggerMessage("%s", msg_str
);
6489 rPlayer
->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
6491 //Confirmation message
6492 std::string nameLink
= GetNameLink(rPlayer
);
6493 PSendSysMessage(LANG_SENDMESSAGE
,nameLink
.c_str(),msg_str
);
6497 bool ChatHandler::HandleFlushArenaPointsCommand(const char * /*args*/)
6499 sBattleGroundMgr
.DistributeArenaPoints();
6503 bool ChatHandler::HandleModifyGenderCommand(const char *args
)
6508 Player
*player
= getSelectedPlayer();
6512 PSendSysMessage(LANG_PLAYER_NOT_FOUND
);
6513 SetSentErrorMessage(true);
6517 PlayerInfo
const* info
= objmgr
.GetPlayerInfo(player
->getRace(), player
->getClass());
6521 char const* gender_str
= (char*)args
;
6522 int gender_len
= strlen(gender_str
);
6526 if(!strncmp(gender_str
, "male", gender_len
)) // MALE
6528 if(player
->getGender() == GENDER_MALE
)
6531 gender
= GENDER_MALE
;
6533 else if (!strncmp(gender_str
, "female", gender_len
)) // FEMALE
6535 if(player
->getGender() == GENDER_FEMALE
)
6538 gender
= GENDER_FEMALE
;
6542 SendSysMessage(LANG_MUST_MALE_OR_FEMALE
);
6543 SetSentErrorMessage(true);
6548 player
->SetByteValue(UNIT_FIELD_BYTES_0
, 2, gender
);
6549 player
->SetByteValue(PLAYER_BYTES_3
, 0, gender
);
6551 // Change display ID
6552 player
->SetDisplayId(gender
? info
->displayId_f
: info
->displayId_m
);
6553 player
->SetNativeDisplayId(gender
? info
->displayId_f
: info
->displayId_m
);
6555 char const* gender_full
= gender
? "female" : "male";
6557 PSendSysMessage(LANG_YOU_CHANGE_GENDER
, GetNameLink(player
).c_str(), gender_full
);
6559 if (needReportToTarget(player
))
6560 ChatHandler(player
).PSendSysMessage(LANG_YOUR_GENDER_CHANGED
, gender_full
, GetNameLink().c_str());