2 * Copyright (C) 2005-2010 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/Config.h"
49 #include "ItemEnchantmentMgr.h"
50 #include "BattleGroundMgr.h"
51 #include "InstanceSaveMgr.h"
52 #include "InstanceData.h"
53 #include "CreatureEventAIMgr.h"
57 bool ChatHandler::HandleReloadAllCommand(const char*)
59 HandleReloadSkillFishingBaseLevelCommand("");
61 HandleReloadAllAchievementCommand("");
62 HandleReloadAllAreaCommand("");
63 HandleReloadAllEventAICommand("");
64 HandleReloadAllLootCommand("");
65 HandleReloadAllNpcCommand("");
66 HandleReloadAllQuestCommand("");
67 HandleReloadAllSpellCommand("");
68 HandleReloadAllItemCommand("");
69 HandleReloadAllGossipsCommand("");
70 HandleReloadAllLocalesCommand("");
72 HandleReloadMailLevelRewardCommand("");
73 HandleReloadCommandCommand("");
74 HandleReloadReservedNameCommand("");
75 HandleReloadMangosStringCommand("");
76 HandleReloadGameTeleCommand("");
80 bool ChatHandler::HandleReloadAllAchievementCommand(const char*)
82 HandleReloadAchievementCriteriaRequirementCommand("");
83 HandleReloadAchievementRewardCommand("");
87 bool ChatHandler::HandleReloadAllAreaCommand(const char*)
89 //HandleReloadQuestAreaTriggersCommand(""); -- reloaded in HandleReloadAllQuestCommand
90 HandleReloadAreaTriggerTeleportCommand("");
91 HandleReloadAreaTriggerTavernCommand("");
92 HandleReloadGameGraveyardZoneCommand("");
96 bool ChatHandler::HandleReloadAllLootCommand(const char*)
98 sLog
.outString( "Re-Loading Loot Tables..." );
100 SendGlobalSysMessage("DB tables `*_loot_template` reloaded.");
104 bool ChatHandler::HandleReloadAllNpcCommand(const char* args
)
106 if(*args
!='a') // will be reloaded from all_gossips
107 HandleReloadNpcGossipCommand("a");
108 HandleReloadNpcTrainerCommand("a");
109 HandleReloadNpcVendorCommand("a");
110 HandleReloadPointsOfInterestCommand("a");
111 HandleReloadSpellClickSpellsCommand("a");
115 bool ChatHandler::HandleReloadAllQuestCommand(const char* /*args*/)
117 HandleReloadQuestAreaTriggersCommand("a");
118 HandleReloadQuestPOICommand("a");
119 HandleReloadQuestTemplateCommand("a");
121 sLog
.outString( "Re-Loading Quests Relations..." );
122 sObjectMgr
.LoadQuestRelations();
123 SendGlobalSysMessage("DB tables `*_questrelation` and `*_involvedrelation` reloaded.");
127 bool ChatHandler::HandleReloadAllScriptsCommand(const char*)
129 if(sWorld
.IsScriptScheduled())
131 PSendSysMessage("DB scripts used currently, please attempt reload later.");
132 SetSentErrorMessage(true);
136 sLog
.outString( "Re-Loading Scripts..." );
137 HandleReloadGameObjectScriptsCommand("a");
138 HandleReloadGossipScriptsCommand("a");
139 HandleReloadEventScriptsCommand("a");
140 HandleReloadQuestEndScriptsCommand("a");
141 HandleReloadQuestStartScriptsCommand("a");
142 HandleReloadSpellScriptsCommand("a");
143 SendGlobalSysMessage("DB tables `*_scripts` reloaded.");
144 HandleReloadDbScriptStringCommand("a");
148 bool ChatHandler::HandleReloadAllEventAICommand(const char*)
150 HandleReloadEventAITextsCommand("a");
151 HandleReloadEventAISummonsCommand("a");
152 HandleReloadEventAIScriptsCommand("a");
156 bool ChatHandler::HandleReloadAllSpellCommand(const char*)
158 HandleReloadSkillDiscoveryTemplateCommand("a");
159 HandleReloadSkillExtraItemTemplateCommand("a");
160 HandleReloadSpellAreaCommand("a");
161 HandleReloadSpellChainCommand("a");
162 HandleReloadSpellElixirCommand("a");
163 HandleReloadSpellLearnSpellCommand("a");
164 HandleReloadSpellProcEventCommand("a");
165 HandleReloadSpellBonusesCommand("a");
166 HandleReloadSpellProcItemEnchantCommand("a");
167 HandleReloadSpellScriptTargetCommand("a");
168 HandleReloadSpellTargetPositionCommand("a");
169 HandleReloadSpellThreatsCommand("a");
170 HandleReloadSpellPetAurasCommand("a");
174 bool ChatHandler::HandleReloadAllGossipsCommand(const char* args
)
176 HandleReloadGossipMenuCommand("a");
177 HandleReloadGossipMenuOptionCommand("a");
178 if(*args
!='a') // already reload from all_scripts
179 HandleReloadGossipScriptsCommand("a");
180 HandleReloadNpcGossipCommand("a");
181 HandleReloadPointsOfInterestCommand("a");
185 bool ChatHandler::HandleReloadAllItemCommand(const char*)
187 HandleReloadPageTextsCommand("a");
188 HandleReloadItemEnchantementsCommand("a");
189 HandleReloadItemRequiredTragetCommand("a");
193 bool ChatHandler::HandleReloadAllLocalesCommand(const char* /*args*/)
195 HandleReloadLocalesAchievementRewardCommand("a");
196 HandleReloadLocalesCreatureCommand("a");
197 HandleReloadLocalesGameobjectCommand("a");
198 HandleReloadLocalesGossipMenuOptionCommand("a");
199 HandleReloadLocalesItemCommand("a");
200 HandleReloadLocalesNpcTextCommand("a");
201 HandleReloadLocalesPageTextCommand("a");
202 HandleReloadLocalesPointsOfInterestCommand("a");
203 HandleReloadLocalesQuestCommand("a");
207 bool ChatHandler::HandleReloadConfigCommand(const char* /*args*/)
209 sLog
.outString( "Re-Loading config settings..." );
210 sWorld
.LoadConfigSettings(true);
211 sMapMgr
.InitializeVisibilityDistanceInfo();
212 SendGlobalSysMessage("World config settings reloaded.");
216 bool ChatHandler::HandleReloadAchievementCriteriaRequirementCommand(const char*)
218 sLog
.outString( "Re-Loading Additional Achievement Criteria Requirements Data..." );
219 sAchievementMgr
.LoadAchievementCriteriaRequirements();
220 SendGlobalSysMessage("DB table `achievement_criteria_requirement` reloaded.");
224 bool ChatHandler::HandleReloadAchievementRewardCommand(const char*)
226 sLog
.outString( "Re-Loading Achievement Reward Data..." );
227 sAchievementMgr
.LoadRewards();
228 SendGlobalSysMessage("DB table `achievement_reward` reloaded.");
232 bool ChatHandler::HandleReloadAreaTriggerTavernCommand(const char*)
234 sLog
.outString( "Re-Loading Tavern Area Triggers..." );
235 sObjectMgr
.LoadTavernAreaTriggers();
236 SendGlobalSysMessage("DB table `areatrigger_tavern` reloaded.");
240 bool ChatHandler::HandleReloadAreaTriggerTeleportCommand(const char*)
242 sLog
.outString( "Re-Loading AreaTrigger teleport definitions..." );
243 sObjectMgr
.LoadAreaTriggerTeleports();
244 SendGlobalSysMessage("DB table `areatrigger_teleport` reloaded.");
248 bool ChatHandler::HandleReloadCommandCommand(const char*)
250 load_command_table
= true;
251 SendGlobalSysMessage("DB table `command` will be reloaded at next chat command use.");
255 bool ChatHandler::HandleReloadCreatureQuestRelationsCommand(const char*)
257 sLog
.outString( "Loading Quests Relations... (`creature_questrelation`)" );
258 sObjectMgr
.LoadCreatureQuestRelations();
259 SendGlobalSysMessage("DB table `creature_questrelation` (creature quest givers) reloaded.");
263 bool ChatHandler::HandleReloadCreatureQuestInvRelationsCommand(const char*)
265 sLog
.outString( "Loading Quests Relations... (`creature_involvedrelation`)" );
266 sObjectMgr
.LoadCreatureInvolvedRelations();
267 SendGlobalSysMessage("DB table `creature_involvedrelation` (creature quest takers) reloaded.");
271 bool ChatHandler::HandleReloadGossipMenuCommand(const char*)
273 sLog
.outString( "Re-Loading `gossip_menu` Table!" );
274 sObjectMgr
.LoadGossipMenu();
275 SendGlobalSysMessage("DB table `gossip_menu` reloaded.");
279 bool ChatHandler::HandleReloadGossipMenuOptionCommand(const char*)
281 sLog
.outString( "Re-Loading `gossip_menu_option` Table!" );
282 sObjectMgr
.LoadGossipMenuItems();
283 SendGlobalSysMessage("DB table `gossip_menu_option` reloaded.");
287 bool ChatHandler::HandleReloadGossipScriptsCommand(const char* arg
)
289 if(sWorld
.IsScriptScheduled())
291 SendSysMessage("DB scripts used currently, please attempt reload later.");
292 SetSentErrorMessage(true);
297 sLog
.outString( "Re-Loading Scripts from `gossip_scripts`...");
299 sObjectMgr
.LoadGossipScripts();
302 SendGlobalSysMessage("DB table `gossip_scripts` reloaded.");
307 bool ChatHandler::HandleReloadGOQuestRelationsCommand(const char*)
309 sLog
.outString( "Loading Quests Relations... (`gameobject_questrelation`)" );
310 sObjectMgr
.LoadGameobjectQuestRelations();
311 SendGlobalSysMessage("DB table `gameobject_questrelation` (gameobject quest givers) reloaded.");
315 bool ChatHandler::HandleReloadGOQuestInvRelationsCommand(const char*)
317 sLog
.outString( "Loading Quests Relations... (`gameobject_involvedrelation`)" );
318 sObjectMgr
.LoadGameobjectInvolvedRelations();
319 SendGlobalSysMessage("DB table `gameobject_involvedrelation` (gameobject quest takers) reloaded.");
323 bool ChatHandler::HandleReloadQuestAreaTriggersCommand(const char*)
325 sLog
.outString( "Re-Loading Quest Area Triggers..." );
326 sObjectMgr
.LoadQuestAreaTriggers();
327 SendGlobalSysMessage("DB table `areatrigger_involvedrelation` (quest area triggers) reloaded.");
331 bool ChatHandler::HandleReloadQuestTemplateCommand(const char*)
333 sLog
.outString( "Re-Loading Quest Templates..." );
334 sObjectMgr
.LoadQuests();
335 SendGlobalSysMessage("DB table `quest_template` (quest definitions) reloaded.");
337 /// dependent also from `gameobject` but this table not reloaded anyway
338 sLog
.outString( "Re-Loading GameObjects for quests..." );
339 sObjectMgr
.LoadGameObjectForQuests();
340 SendGlobalSysMessage("Data GameObjects for quests reloaded.");
344 bool ChatHandler::HandleReloadLootTemplatesCreatureCommand(const char*)
346 sLog
.outString( "Re-Loading Loot Tables... (`creature_loot_template`)" );
347 LoadLootTemplates_Creature();
348 LootTemplates_Creature
.CheckLootRefs();
349 SendGlobalSysMessage("DB table `creature_loot_template` reloaded.");
353 bool ChatHandler::HandleReloadLootTemplatesDisenchantCommand(const char*)
355 sLog
.outString( "Re-Loading Loot Tables... (`disenchant_loot_template`)" );
356 LoadLootTemplates_Disenchant();
357 LootTemplates_Disenchant
.CheckLootRefs();
358 SendGlobalSysMessage("DB table `disenchant_loot_template` reloaded.");
362 bool ChatHandler::HandleReloadLootTemplatesFishingCommand(const char*)
364 sLog
.outString( "Re-Loading Loot Tables... (`fishing_loot_template`)" );
365 LoadLootTemplates_Fishing();
366 LootTemplates_Fishing
.CheckLootRefs();
367 SendGlobalSysMessage("DB table `fishing_loot_template` reloaded.");
371 bool ChatHandler::HandleReloadLootTemplatesGameobjectCommand(const char*)
373 sLog
.outString( "Re-Loading Loot Tables... (`gameobject_loot_template`)" );
374 LoadLootTemplates_Gameobject();
375 LootTemplates_Gameobject
.CheckLootRefs();
376 SendGlobalSysMessage("DB table `gameobject_loot_template` reloaded.");
380 bool ChatHandler::HandleReloadLootTemplatesItemCommand(const char*)
382 sLog
.outString( "Re-Loading Loot Tables... (`item_loot_template`)" );
383 LoadLootTemplates_Item();
384 LootTemplates_Item
.CheckLootRefs();
385 SendGlobalSysMessage("DB table `item_loot_template` reloaded.");
389 bool ChatHandler::HandleReloadLootTemplatesMillingCommand(const char*)
391 sLog
.outString( "Re-Loading Loot Tables... (`milling_loot_template`)" );
392 LoadLootTemplates_Milling();
393 LootTemplates_Milling
.CheckLootRefs();
394 SendGlobalSysMessage("DB table `milling_loot_template` reloaded.");
398 bool ChatHandler::HandleReloadLootTemplatesPickpocketingCommand(const char*)
400 sLog
.outString( "Re-Loading Loot Tables... (`pickpocketing_loot_template`)" );
401 LoadLootTemplates_Pickpocketing();
402 LootTemplates_Pickpocketing
.CheckLootRefs();
403 SendGlobalSysMessage("DB table `pickpocketing_loot_template` reloaded.");
407 bool ChatHandler::HandleReloadLootTemplatesProspectingCommand(const char*)
409 sLog
.outString( "Re-Loading Loot Tables... (`prospecting_loot_template`)" );
410 LoadLootTemplates_Prospecting();
411 LootTemplates_Prospecting
.CheckLootRefs();
412 SendGlobalSysMessage("DB table `prospecting_loot_template` reloaded.");
416 bool ChatHandler::HandleReloadLootTemplatesMailCommand(const char*)
418 sLog
.outString( "Re-Loading Loot Tables... (`mail_loot_template`)" );
419 LoadLootTemplates_Mail();
420 LootTemplates_Mail
.CheckLootRefs();
421 SendGlobalSysMessage("DB table `mail_loot_template` reloaded.");
425 bool ChatHandler::HandleReloadLootTemplatesReferenceCommand(const char*)
427 sLog
.outString( "Re-Loading Loot Tables... (`reference_loot_template`)" );
428 LoadLootTemplates_Reference();
429 SendGlobalSysMessage("DB table `reference_loot_template` reloaded.");
433 bool ChatHandler::HandleReloadLootTemplatesSkinningCommand(const char*)
435 sLog
.outString( "Re-Loading Loot Tables... (`skinning_loot_template`)" );
436 LoadLootTemplates_Skinning();
437 LootTemplates_Skinning
.CheckLootRefs();
438 SendGlobalSysMessage("DB table `skinning_loot_template` reloaded.");
442 bool ChatHandler::HandleReloadLootTemplatesSpellCommand(const char*)
444 sLog
.outString( "Re-Loading Loot Tables... (`spell_loot_template`)" );
445 LoadLootTemplates_Spell();
446 LootTemplates_Spell
.CheckLootRefs();
447 SendGlobalSysMessage("DB table `spell_loot_template` reloaded.");
451 bool ChatHandler::HandleReloadMangosStringCommand(const char*)
453 sLog
.outString( "Re-Loading mangos_string Table!" );
454 sObjectMgr
.LoadMangosStrings();
455 SendGlobalSysMessage("DB table `mangos_string` reloaded.");
459 bool ChatHandler::HandleReloadNpcGossipCommand(const char*)
461 sLog
.outString( "Re-Loading `npc_gossip` Table!" );
462 sObjectMgr
.LoadNpcTextId();
463 SendGlobalSysMessage("DB table `npc_gossip` reloaded.");
467 bool ChatHandler::HandleReloadNpcTrainerCommand(const char*)
469 sLog
.outString( "Re-Loading `npc_trainer` Table!" );
470 sObjectMgr
.LoadTrainerSpell();
471 SendGlobalSysMessage("DB table `npc_trainer` reloaded.");
475 bool ChatHandler::HandleReloadNpcVendorCommand(const char*)
477 sLog
.outString( "Re-Loading `npc_vendor` Table!" );
478 sObjectMgr
.LoadVendors();
479 SendGlobalSysMessage("DB table `npc_vendor` reloaded.");
483 bool ChatHandler::HandleReloadPointsOfInterestCommand(const char*)
485 sLog
.outString( "Re-Loading `points_of_interest` Table!" );
486 sObjectMgr
.LoadPointsOfInterest();
487 SendGlobalSysMessage("DB table `points_of_interest` reloaded.");
491 bool ChatHandler::HandleReloadQuestPOICommand(const char*)
493 sLog
.outString( "Re-Loading `quest_poi` and `quest_poi_points` Tables!" );
494 sObjectMgr
.LoadQuestPOI();
495 SendGlobalSysMessage("DB Table `quest_poi` and `quest_poi_points` reloaded.");
499 bool ChatHandler::HandleReloadSpellClickSpellsCommand(const char*)
501 sLog
.outString( "Re-Loading `npc_spellclick_spells` Table!" );
502 sObjectMgr
.LoadNPCSpellClickSpells();
503 SendGlobalSysMessage("DB table `npc_spellclick_spells` reloaded.");
507 bool ChatHandler::HandleReloadReservedNameCommand(const char*)
509 sLog
.outString( "Loading ReservedNames... (`reserved_name`)" );
510 sObjectMgr
.LoadReservedPlayersNames();
511 SendGlobalSysMessage("DB table `reserved_name` (player reserved names) reloaded.");
515 bool ChatHandler::HandleReloadSkillDiscoveryTemplateCommand(const char* /*args*/)
517 sLog
.outString( "Re-Loading Skill Discovery Table..." );
518 LoadSkillDiscoveryTable();
519 SendGlobalSysMessage("DB table `skill_discovery_template` (recipes discovered at crafting) reloaded.");
523 bool ChatHandler::HandleReloadSkillExtraItemTemplateCommand(const char* /*args*/)
525 sLog
.outString( "Re-Loading Skill Extra Item Table..." );
526 LoadSkillExtraItemTable();
527 SendGlobalSysMessage("DB table `skill_extra_item_template` (extra item creation when crafting) reloaded.");
531 bool ChatHandler::HandleReloadSkillFishingBaseLevelCommand(const char* /*args*/)
533 sLog
.outString( "Re-Loading Skill Fishing base level requirements..." );
534 sObjectMgr
.LoadFishingBaseSkillLevel();
535 SendGlobalSysMessage("DB table `skill_fishing_base_level` (fishing base level for zone/subzone) reloaded.");
539 bool ChatHandler::HandleReloadSpellAreaCommand(const char*)
541 sLog
.outString( "Re-Loading SpellArea Data..." );
542 sSpellMgr
.LoadSpellAreas();
543 SendGlobalSysMessage("DB table `spell_area` (spell dependences from area/quest/auras state) reloaded.");
547 bool ChatHandler::HandleReloadSpellChainCommand(const char*)
549 sLog
.outString( "Re-Loading Spell Chain Data... " );
550 sSpellMgr
.LoadSpellChains();
551 SendGlobalSysMessage("DB table `spell_chain` (spell ranks) reloaded.");
555 bool ChatHandler::HandleReloadSpellElixirCommand(const char*)
557 sLog
.outString( "Re-Loading Spell Elixir types..." );
558 sSpellMgr
.LoadSpellElixirs();
559 SendGlobalSysMessage("DB table `spell_elixir` (spell elixir types) reloaded.");
563 bool ChatHandler::HandleReloadSpellLearnSpellCommand(const char*)
565 sLog
.outString( "Re-Loading Spell Learn Spells..." );
566 sSpellMgr
.LoadSpellLearnSpells();
567 SendGlobalSysMessage("DB table `spell_learn_spell` reloaded.");
571 bool ChatHandler::HandleReloadSpellProcEventCommand(const char*)
573 sLog
.outString( "Re-Loading Spell Proc Event conditions..." );
574 sSpellMgr
.LoadSpellProcEvents();
575 SendGlobalSysMessage("DB table `spell_proc_event` (spell proc trigger requirements) reloaded.");
579 bool ChatHandler::HandleReloadSpellBonusesCommand(const char*)
581 sLog
.outString( "Re-Loading Spell Bonus Data..." );
582 sSpellMgr
.LoadSpellBonuses();
583 SendGlobalSysMessage("DB table `spell_bonus_data` (spell damage/healing coefficients) reloaded.");
587 bool ChatHandler::HandleReloadSpellProcItemEnchantCommand(const char*)
589 sLog
.outString( "Re-Loading Spell Proc Item Enchant..." );
590 sSpellMgr
.LoadSpellProcItemEnchant();
591 SendGlobalSysMessage("DB table `spell_proc_item_enchant` (item enchantment ppm) reloaded.");
595 bool ChatHandler::HandleReloadSpellScriptTargetCommand(const char*)
597 sLog
.outString( "Re-Loading SpellsScriptTarget..." );
598 sSpellMgr
.LoadSpellScriptTarget();
599 SendGlobalSysMessage("DB table `spell_script_target` (spell targets selection in case specific creature/GO requirements) reloaded.");
603 bool ChatHandler::HandleReloadSpellTargetPositionCommand(const char*)
605 sLog
.outString( "Re-Loading Spell target coordinates..." );
606 sSpellMgr
.LoadSpellTargetPositions();
607 SendGlobalSysMessage("DB table `spell_target_position` (destination coordinates for spell targets) reloaded.");
611 bool ChatHandler::HandleReloadSpellThreatsCommand(const char*)
613 sLog
.outString( "Re-Loading Aggro Spells Definitions...");
614 sSpellMgr
.LoadSpellThreats();
615 SendGlobalSysMessage("DB table `spell_threat` (spell aggro definitions) reloaded.");
619 bool ChatHandler::HandleReloadSpellPetAurasCommand(const char*)
621 sLog
.outString( "Re-Loading Spell pet auras...");
622 sSpellMgr
.LoadSpellPetAuras();
623 SendGlobalSysMessage("DB table `spell_pet_auras` reloaded.");
627 bool ChatHandler::HandleReloadPageTextsCommand(const char*)
629 sLog
.outString( "Re-Loading Page Texts..." );
630 sObjectMgr
.LoadPageTexts();
631 SendGlobalSysMessage("DB table `page_texts` reloaded.");
635 bool ChatHandler::HandleReloadItemEnchantementsCommand(const char*)
637 sLog
.outString( "Re-Loading Item Random Enchantments Table..." );
638 LoadRandomEnchantmentsTable();
639 SendGlobalSysMessage("DB table `item_enchantment_template` reloaded.");
643 bool ChatHandler::HandleReloadItemRequiredTragetCommand(const char*)
645 sLog
.outString( "Re-Loading Item Required Targets Table..." );
646 sObjectMgr
.LoadItemRequiredTarget();
647 SendGlobalSysMessage("DB table `item_required_target` reloaded.");
651 bool ChatHandler::HandleReloadBattleEventCommand(const char*)
653 sLog
.outString( "Re-Loading BattleGround Eventindexes..." );
654 sBattleGroundMgr
.LoadBattleEventIndexes();
655 SendGlobalSysMessage("DB table `gameobject_battleground` and `creature_battleground` reloaded.");
659 bool ChatHandler::HandleReloadGameObjectScriptsCommand(const char* arg
)
661 if(sWorld
.IsScriptScheduled())
663 SendSysMessage("DB scripts used currently, please attempt reload later.");
664 SetSentErrorMessage(true);
669 sLog
.outString( "Re-Loading Scripts from `gameobject_scripts`...");
671 sObjectMgr
.LoadGameObjectScripts();
674 SendGlobalSysMessage("DB table `gameobject_scripts` reloaded.");
679 bool ChatHandler::HandleReloadEventScriptsCommand(const char* arg
)
681 if(sWorld
.IsScriptScheduled())
683 SendSysMessage("DB scripts used currently, please attempt reload later.");
684 SetSentErrorMessage(true);
689 sLog
.outString( "Re-Loading Scripts from `event_scripts`...");
691 sObjectMgr
.LoadEventScripts();
694 SendGlobalSysMessage("DB table `event_scripts` reloaded.");
699 bool ChatHandler::HandleReloadEventAITextsCommand(const char* /*arg*/)
702 sLog
.outString( "Re-Loading Texts from `creature_ai_texts`...");
703 sEventAIMgr
.LoadCreatureEventAI_Texts(true);
704 SendGlobalSysMessage("DB table `creature_ai_texts` reloaded.");
708 bool ChatHandler::HandleReloadEventAISummonsCommand(const char* /*arg*/)
710 sLog
.outString( "Re-Loading Summons from `creature_ai_summons`...");
711 sEventAIMgr
.LoadCreatureEventAI_Summons(true);
712 SendGlobalSysMessage("DB table `creature_ai_summons` reloaded.");
716 bool ChatHandler::HandleReloadEventAIScriptsCommand(const char* /*arg*/)
718 sLog
.outString( "Re-Loading Scripts from `creature_ai_scripts`...");
719 sEventAIMgr
.LoadCreatureEventAI_Scripts();
720 SendGlobalSysMessage("DB table `creature_ai_scripts` reloaded.");
724 bool ChatHandler::HandleReloadQuestEndScriptsCommand(const char* arg
)
726 if(sWorld
.IsScriptScheduled())
728 SendSysMessage("DB scripts used currently, please attempt reload later.");
729 SetSentErrorMessage(true);
734 sLog
.outString( "Re-Loading Scripts from `quest_end_scripts`...");
736 sObjectMgr
.LoadQuestEndScripts();
739 SendGlobalSysMessage("DB table `quest_end_scripts` reloaded.");
744 bool ChatHandler::HandleReloadQuestStartScriptsCommand(const char* arg
)
746 if(sWorld
.IsScriptScheduled())
748 SendSysMessage("DB scripts used currently, please attempt reload later.");
749 SetSentErrorMessage(true);
754 sLog
.outString( "Re-Loading Scripts from `quest_start_scripts`...");
756 sObjectMgr
.LoadQuestStartScripts();
759 SendGlobalSysMessage("DB table `quest_start_scripts` reloaded.");
764 bool ChatHandler::HandleReloadSpellScriptsCommand(const char* arg
)
766 if(sWorld
.IsScriptScheduled())
768 SendSysMessage("DB scripts used currently, please attempt reload later.");
769 SetSentErrorMessage(true);
774 sLog
.outString( "Re-Loading Scripts from `spell_scripts`...");
776 sObjectMgr
.LoadSpellScripts();
779 SendGlobalSysMessage("DB table `spell_scripts` reloaded.");
784 bool ChatHandler::HandleReloadDbScriptStringCommand(const char* /*arg*/)
786 sLog
.outString( "Re-Loading Script strings from `db_script_string`...");
787 sObjectMgr
.LoadDbScriptStrings();
788 SendGlobalSysMessage("DB table `db_script_string` reloaded.");
792 bool ChatHandler::HandleReloadGameGraveyardZoneCommand(const char* /*arg*/)
794 sLog
.outString( "Re-Loading Graveyard-zone links...");
796 sObjectMgr
.LoadGraveyardZones();
798 SendGlobalSysMessage("DB table `game_graveyard_zone` reloaded.");
803 bool ChatHandler::HandleReloadGameTeleCommand(const char* /*arg*/)
805 sLog
.outString( "Re-Loading Game Tele coordinates...");
807 sObjectMgr
.LoadGameTele();
809 SendGlobalSysMessage("DB table `game_tele` reloaded.");
814 bool ChatHandler::HandleReloadLocalesAchievementRewardCommand(const char*)
816 sLog
.outString( "Re-Loading Locales Achievement Reward Data..." );
817 sAchievementMgr
.LoadRewardLocales();
818 SendGlobalSysMessage("DB table `locales_achievement_reward` reloaded.");
822 bool ChatHandler::HandleReloadLocalesCreatureCommand(const char* /*arg*/)
824 sLog
.outString( "Re-Loading Locales Creature ...");
825 sObjectMgr
.LoadCreatureLocales();
826 SendGlobalSysMessage("DB table `locales_creature` reloaded.");
830 bool ChatHandler::HandleReloadLocalesGameobjectCommand(const char* /*arg*/)
832 sLog
.outString( "Re-Loading Locales Gameobject ... ");
833 sObjectMgr
.LoadGameObjectLocales();
834 SendGlobalSysMessage("DB table `locales_gameobject` reloaded.");
838 bool ChatHandler::HandleReloadLocalesGossipMenuOptionCommand(const char* /*arg*/)
840 sLog
.outString( "Re-Loading Locales Gossip Menu Option ... ");
841 sObjectMgr
.LoadGossipMenuItemsLocales();
842 SendGlobalSysMessage("DB table `locales_gossip_menu_option` reloaded.");
846 bool ChatHandler::HandleReloadLocalesItemCommand(const char* /*arg*/)
848 sLog
.outString( "Re-Loading Locales Item ... ");
849 sObjectMgr
.LoadItemLocales();
850 SendGlobalSysMessage("DB table `locales_item` reloaded.");
854 bool ChatHandler::HandleReloadLocalesNpcTextCommand(const char* /*arg*/)
856 sLog
.outString( "Re-Loading Locales NPC Text ... ");
857 sObjectMgr
.LoadNpcTextLocales();
858 SendGlobalSysMessage("DB table `locales_npc_text` reloaded.");
862 bool ChatHandler::HandleReloadLocalesPageTextCommand(const char* /*arg*/)
864 sLog
.outString( "Re-Loading Locales Page Text ... ");
865 sObjectMgr
.LoadPageTextLocales();
866 SendGlobalSysMessage("DB table `locales_page_text` reloaded.");
870 bool ChatHandler::HandleReloadLocalesPointsOfInterestCommand(const char* /*arg*/)
872 sLog
.outString( "Re-Loading Locales Points Of Interest ... ");
873 sObjectMgr
.LoadPointOfInterestLocales();
874 SendGlobalSysMessage("DB table `locales_points_of_interest` reloaded.");
878 bool ChatHandler::HandleReloadLocalesQuestCommand(const char* /*arg*/)
880 sLog
.outString( "Re-Loading Locales Quest ... ");
881 sObjectMgr
.LoadQuestLocales();
882 SendGlobalSysMessage("DB table `locales_quest` reloaded.");
886 bool ChatHandler::HandleReloadMailLevelRewardCommand(const char* /*arg*/)
888 sLog
.outString( "Re-Loading Player level dependent mail rewards..." );
889 sObjectMgr
.LoadMailLevelRewards();
890 SendGlobalSysMessage("DB table `mail_level_reward` reloaded.");
894 bool ChatHandler::HandleLoadScriptsCommand(const char* args
)
896 if(!LoadScriptingModule(args
)) return true;
898 sWorld
.SendWorldText(LANG_SCRIPTS_RELOADED
);
902 bool ChatHandler::HandleAccountSetGmLevelCommand(const char* args
)
907 extractOptFirstArg((char*)args
, &arg1
, &arg2
);
909 std::string targetAccountName
;
910 Player
* targetPlayer
= NULL
;
911 uint32 targetAccountId
= extractAccountId(arg1
,&targetAccountName
,&targetPlayer
);
912 if (!targetAccountId
)
915 /// only target player different from self allowed
916 if (GetAccountId() == targetAccountId
)
919 int32 gm
= (int32
)atoi(arg2
);
920 if ( gm
< SEC_PLAYER
|| gm
> SEC_ADMINISTRATOR
)
922 SendSysMessage(LANG_BAD_VALUE
);
923 SetSentErrorMessage(true);
927 /// can set security level only for target with less security and to less security that we have
928 /// This will reject self apply by specify account name
929 if(HasLowerSecurityAccount(NULL
,targetAccountId
,true))
932 /// account can't set security to same or grater level, need more power GM or console
933 AccountTypes plSecurity
= GetAccessLevel();
934 if (AccountTypes(gm
) >= plSecurity
)
936 SendSysMessage(LANG_YOURS_SECURITY_IS_LOW
);
937 SetSentErrorMessage(true);
943 ChatHandler(targetPlayer
).PSendSysMessage(LANG_YOURS_SECURITY_CHANGED
,GetNameLink().c_str(), gm
);
944 targetPlayer
->GetSession()->SetSecurity(AccountTypes(gm
));
947 PSendSysMessage(LANG_YOU_CHANGE_SECURITY
, targetAccountName
.c_str(), gm
);
948 loginDatabase
.PExecute("UPDATE account SET gmlevel = '%i' WHERE id = '%u'", gm
, targetAccountId
);
953 /// Set password for account
954 bool ChatHandler::HandleAccountSetPasswordCommand(const char* args
)
959 ///- Get the command line arguments
960 std::string account_name
;
961 uint32 targetAccountId
= extractAccountId((char*)args
, &account_name
);
962 if (!targetAccountId
)
965 char *szPassword1
= strtok (NULL
," ");
966 char *szPassword2
= strtok (NULL
," ");
967 if (!szPassword1
|| !szPassword2
)
970 /// can set password only for target with less security
971 /// This is also reject self apply in fact
972 if(HasLowerSecurityAccount (NULL
,targetAccountId
,true))
975 if (strcmp(szPassword1
,szPassword2
))
977 SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH
);
978 SetSentErrorMessage (true);
982 AccountOpResult result
= sAccountMgr
.ChangePassword(targetAccountId
, szPassword1
);
987 SendSysMessage(LANG_COMMAND_PASSWORD
);
989 case AOR_NAME_NOT_EXIST
:
990 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
991 SetSentErrorMessage(true);
993 case AOR_PASS_TOO_LONG
:
994 SendSysMessage(LANG_PASSWORD_TOO_LONG
);
995 SetSentErrorMessage(true);
998 SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD
);
999 SetSentErrorMessage(true);
1006 bool ChatHandler::HandleMaxSkillCommand(const char* /*args*/)
1008 Player
* SelectedPlayer
= getSelectedPlayer();
1011 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1012 SetSentErrorMessage(true);
1016 // each skills that have max skill value dependent from level seted to current level max skill value
1017 SelectedPlayer
->UpdateSkillsToMaxSkillsForLevel();
1021 bool ChatHandler::HandleSetSkillCommand(const char* args
)
1023 // number or [name] Shift-click form |color|Hskill:skill_id|h[name]|h|r
1024 char* skill_p
= extractKeyFromLink((char*)args
,"Hskill");
1028 char *level_p
= strtok (NULL
, " ");
1033 char *max_p
= strtok (NULL
, " ");
1035 int32 skill
= atoi(skill_p
);
1038 PSendSysMessage(LANG_INVALID_SKILL_ID
, skill
);
1039 SetSentErrorMessage(true);
1043 int32 level
= atol (level_p
);
1045 Player
* target
= getSelectedPlayer();
1048 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1049 SetSentErrorMessage(true);
1053 SkillLineEntry
const* sl
= sSkillLineStore
.LookupEntry(skill
);
1056 PSendSysMessage(LANG_INVALID_SKILL_ID
, skill
);
1057 SetSentErrorMessage(true);
1061 std::string tNameLink
= GetNameLink(target
);
1063 if(!target
->GetSkillValue(skill
))
1065 PSendSysMessage(LANG_SET_SKILL_ERROR
, tNameLink
.c_str(), skill
, sl
->name
[GetSessionDbcLocale()]);
1066 SetSentErrorMessage(true);
1070 int32 max
= max_p
? atol (max_p
) : target
->GetPureMaxSkillValue(skill
);
1072 if( level
<= 0 || level
> max
|| max
<= 0 )
1075 target
->SetSkill(skill
, level
, max
);
1076 PSendSysMessage(LANG_SET_SKILL
, skill
, sl
->name
[GetSessionDbcLocale()], tNameLink
.c_str(), level
, max
);
1081 bool ChatHandler::HandleUnLearnCommand(const char* args
)
1086 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
1087 uint32 spell_id
= extractSpellIdFromLink((char*)args
);
1091 char const* allStr
= strtok(NULL
," ");
1092 bool allRanks
= allStr
? (strncmp(allStr
, "all", strlen(allStr
)) == 0) : false;
1094 Player
* target
= getSelectedPlayer();
1097 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1098 SetSentErrorMessage(true);
1103 spell_id
= sSpellMgr
.GetFirstSpellInChain (spell_id
);
1105 if (target
->HasSpell(spell_id
))
1106 target
->removeSpell(spell_id
,false,!allRanks
);
1108 SendSysMessage(LANG_FORGET_SPELL
);
1110 if(GetTalentSpellCost(spell_id
))
1111 target
->SendTalentsInfoData(false);
1116 bool ChatHandler::HandleCooldownCommand(const char* args
)
1118 Player
* target
= getSelectedPlayer();
1121 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1122 SetSentErrorMessage(true);
1126 std::string tNameLink
= GetNameLink(target
);
1130 target
->RemoveAllSpellCooldown();
1131 PSendSysMessage(LANG_REMOVEALL_COOLDOWN
, tNameLink
.c_str());
1135 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1136 uint32 spell_id
= extractSpellIdFromLink((char*)args
);
1140 if(!sSpellStore
.LookupEntry(spell_id
))
1142 PSendSysMessage(LANG_UNKNOWN_SPELL
, target
==m_session
->GetPlayer() ? GetMangosString(LANG_YOU
) : tNameLink
.c_str());
1143 SetSentErrorMessage(true);
1147 target
->RemoveSpellCooldown(spell_id
,true);
1148 PSendSysMessage(LANG_REMOVE_COOLDOWN
, spell_id
, target
==m_session
->GetPlayer() ? GetMangosString(LANG_YOU
) : tNameLink
.c_str());
1153 bool ChatHandler::HandleLearnAllCommand(const char* /*args*/)
1155 static const char *allSpellList
[] =
1538 //"9036", problems with ghost state
1547 //"6718", phasing stealth, annoying for learn all case.
1760 while(strcmp(allSpellList
[loop
], "0"))
1762 uint32 spell
= atol((char*)allSpellList
[loop
++]);
1764 if (m_session
->GetPlayer()->HasSpell(spell
))
1767 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1768 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1770 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1774 m_session
->GetPlayer()->learnSpell(spell
, false);
1777 SendSysMessage(LANG_COMMAND_LEARN_MANY_SPELLS
);
1782 bool ChatHandler::HandleLearnAllGMCommand(const char* /*args*/)
1784 static const char *gmSpellList
[] =
1786 "24347", // Become A Fish, No Breath Bar
1787 "35132", // Visual Boom
1788 "38488", // Attack 4000-8000 AOE
1789 "38795", // Attack 2000 AOE + Slow Down 90%
1790 "15712", // Attack 200
1791 "1852", // GM Spell Silence
1794 "29878", // Kill My Self
1795 "26644", // More Kill
1797 "28550", //Invisible 24
1798 "23452", //Invisible + Target
1802 uint16 gmSpellIter
= 0;
1803 while( strcmp(gmSpellList
[gmSpellIter
], "0") )
1805 uint32 spell
= atol((char*)gmSpellList
[gmSpellIter
++]);
1807 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1808 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1810 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1814 m_session
->GetPlayer()->learnSpell(spell
, false);
1817 SendSysMessage(LANG_LEARNING_GM_SKILLS
);
1821 bool ChatHandler::HandleLearnAllMyClassCommand(const char* /*args*/)
1823 HandleLearnAllMySpellsCommand("");
1824 HandleLearnAllMyTalentsCommand("");
1828 bool ChatHandler::HandleLearnAllMySpellsCommand(const char* /*args*/)
1830 ChrClassesEntry
const* clsEntry
= sChrClassesStore
.LookupEntry(m_session
->GetPlayer()->getClass());
1833 uint32 family
= clsEntry
->spellfamily
;
1835 for (uint32 i
= 0; i
< sSkillLineAbilityStore
.GetNumRows(); ++i
)
1837 SkillLineAbilityEntry
const *entry
= sSkillLineAbilityStore
.LookupEntry(i
);
1841 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(entry
->spellId
);
1845 // skip server-side/triggered spells
1846 if(spellInfo
->spellLevel
==0)
1849 // skip wrong class/race skills
1850 if(!m_session
->GetPlayer()->IsSpellFitByClassAndRace(spellInfo
->Id
))
1853 // skip other spell families
1854 if( spellInfo
->SpellFamilyName
!= family
)
1857 // skip spells with first rank learned as talent (and all talents then also)
1858 uint32 first_rank
= sSpellMgr
.GetFirstSpellInChain(spellInfo
->Id
);
1859 if(GetTalentSpellCost(first_rank
) > 0 )
1862 // skip broken spells
1863 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1866 m_session
->GetPlayer()->learnSpell(spellInfo
->Id
, false);
1869 SendSysMessage(LANG_COMMAND_LEARN_CLASS_SPELLS
);
1873 bool ChatHandler::HandleLearnAllMyTalentsCommand(const char* /*args*/)
1875 Player
* player
= m_session
->GetPlayer();
1876 uint32 classMask
= player
->getClassMask();
1878 for (uint32 i
= 0; i
< sTalentStore
.GetNumRows(); ++i
)
1880 TalentEntry
const *talentInfo
= sTalentStore
.LookupEntry(i
);
1884 TalentTabEntry
const *talentTabInfo
= sTalentTabStore
.LookupEntry( talentInfo
->TalentTab
);
1888 if( (classMask
& talentTabInfo
->ClassMask
) == 0 )
1891 // search highest talent rank
1894 for(int rank
= MAX_TALENT_RANK
-1; rank
>= 0; --rank
)
1896 if(talentInfo
->RankID
[rank
]!=0)
1898 spellid
= talentInfo
->RankID
[rank
];
1903 if(!spellid
) // ??? none spells in talent
1906 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spellid
);
1907 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1910 // learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
1911 player
->learnSpellHighRank(spellid
);
1914 player
->SendTalentsInfoData(false);
1916 SendSysMessage(LANG_COMMAND_LEARN_CLASS_TALENTS
);
1920 bool ChatHandler::HandleLearnAllMyPetTalentsCommand(const char* /*args*/)
1922 Player
* player
= m_session
->GetPlayer();
1924 Pet
* pet
= player
->GetPet();
1927 SendSysMessage(LANG_NO_PET_FOUND
);
1928 SetSentErrorMessage(true);
1932 CreatureInfo
const *ci
= pet
->GetCreatureInfo();
1935 SendSysMessage(LANG_WRONG_PET_TYPE
);
1936 SetSentErrorMessage(true);
1940 CreatureFamilyEntry
const *pet_family
= sCreatureFamilyStore
.LookupEntry(ci
->family
);
1943 SendSysMessage(LANG_WRONG_PET_TYPE
);
1944 SetSentErrorMessage(true);
1948 if(pet_family
->petTalentType
< 0) // not hunter pet
1950 SendSysMessage(LANG_WRONG_PET_TYPE
);
1951 SetSentErrorMessage(true);
1955 for (uint32 i
= 0; i
< sTalentStore
.GetNumRows(); ++i
)
1957 TalentEntry
const *talentInfo
= sTalentStore
.LookupEntry(i
);
1961 TalentTabEntry
const *talentTabInfo
= sTalentTabStore
.LookupEntry( talentInfo
->TalentTab
);
1965 // prevent learn talent for different family (cheating)
1966 if(((1 << pet_family
->petTalentType
) & talentTabInfo
->petTalentMask
)==0)
1969 // search highest talent rank
1972 for(int rank
= MAX_TALENT_RANK
-1; rank
>= 0; --rank
)
1974 if(talentInfo
->RankID
[rank
]!=0)
1976 spellid
= talentInfo
->RankID
[rank
];
1981 if(!spellid
) // ??? none spells in talent
1984 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spellid
);
1985 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1988 // learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
1989 pet
->learnSpellHighRank(spellid
);
1992 player
->SendTalentsInfoData(true);
1994 SendSysMessage(LANG_COMMAND_LEARN_PET_TALENTS
);
1998 bool ChatHandler::HandleLearnAllLangCommand(const char* /*args*/)
2000 // skipping UNIVERSAL language (0)
2001 for(int i
= 1; i
< LANGUAGES_COUNT
; ++i
)
2002 m_session
->GetPlayer()->learnSpell(lang_description
[i
].spell_id
, false);
2004 SendSysMessage(LANG_COMMAND_LEARN_ALL_LANG
);
2008 bool ChatHandler::HandleLearnAllDefaultCommand(const char* args
)
2011 if(!extractPlayerTarget((char*)args
,&target
))
2014 target
->learnDefaultSpells();
2015 target
->learnQuestRewardedSpells();
2017 PSendSysMessage(LANG_COMMAND_LEARN_ALL_DEFAULT_AND_QUEST
,GetNameLink(target
).c_str());
2021 bool ChatHandler::HandleLearnCommand(const char* args
)
2023 Player
* targetPlayer
= getSelectedPlayer();
2027 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
2028 SetSentErrorMessage(true);
2032 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
2033 uint32 spell
= extractSpellIdFromLink((char*)args
);
2034 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
2037 char const* allStr
= strtok(NULL
," ");
2038 bool allRanks
= allStr
? (strncmp(allStr
, "all", strlen(allStr
)) == 0) : false;
2040 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
2041 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
2043 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
2044 SetSentErrorMessage(true);
2048 if (!allRanks
&& targetPlayer
->HasSpell(spell
))
2050 if(targetPlayer
== m_session
->GetPlayer())
2051 SendSysMessage(LANG_YOU_KNOWN_SPELL
);
2053 PSendSysMessage(LANG_TARGET_KNOWN_SPELL
,GetNameLink(targetPlayer
).c_str());
2054 SetSentErrorMessage(true);
2059 targetPlayer
->learnSpellHighRank(spell
);
2061 targetPlayer
->learnSpell(spell
, false);
2063 uint32 first_spell
= sSpellMgr
.GetFirstSpellInChain(spell
);
2064 if(GetTalentSpellCost(first_spell
))
2065 targetPlayer
->SendTalentsInfoData(false);
2070 bool ChatHandler::HandleAddItemCommand(const char* args
)
2077 if(args
[0]=='[') // [name] manual form
2079 char* citemName
= strtok((char*)args
, "]");
2081 if(citemName
&& citemName
[0])
2083 std::string itemName
= citemName
+1;
2084 WorldDatabase
.escape_string(itemName
);
2085 QueryResult
*result
= WorldDatabase
.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName
.c_str());
2088 PSendSysMessage(LANG_COMMAND_COULDNOTFIND
, citemName
+1);
2089 SetSentErrorMessage(true);
2092 itemId
= result
->Fetch()->GetUInt16();
2098 else // item_id or [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r
2100 char* cId
= extractKeyFromLink((char*)args
,"Hitem");
2106 char* ccount
= strtok(NULL
, " ");
2111 count
= strtol(ccount
, NULL
, 10);
2116 Player
* pl
= m_session
->GetPlayer();
2117 Player
* plTarget
= getSelectedPlayer();
2121 DETAIL_LOG(GetMangosString(LANG_ADDITEM
), itemId
, count
);
2123 ItemPrototype
const *pProto
= ObjectMgr::GetItemPrototype(itemId
);
2126 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, itemId
);
2127 SetSentErrorMessage(true);
2134 plTarget
->DestroyItemCount(itemId
, -count
, true, false);
2135 PSendSysMessage(LANG_REMOVEITEM
, itemId
, -count
, GetNameLink(plTarget
).c_str());
2140 uint32 noSpaceForCount
= 0;
2142 // check space and find places
2143 ItemPosCountVec dest
;
2144 uint8 msg
= plTarget
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, itemId
, count
, &noSpaceForCount
);
2145 if( msg
!= EQUIP_ERR_OK
) // convert to possible store amount
2146 count
-= noSpaceForCount
;
2148 if( count
== 0 || dest
.empty()) // can't add any
2150 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, itemId
, noSpaceForCount
);
2151 SetSentErrorMessage(true);
2155 Item
* item
= plTarget
->StoreNewItem( dest
, itemId
, true, Item::GenerateItemRandomPropertyId(itemId
));
2157 // remove binding (let GM give it to another player later)
2159 for(ItemPosCountVec::const_iterator itr
= dest
.begin(); itr
!= dest
.end(); ++itr
)
2160 if(Item
* item1
= pl
->GetItemByPos(itr
->pos
))
2161 item1
->SetBinding( false );
2163 if(count
> 0 && item
)
2165 pl
->SendNewItem(item
,count
,false,true);
2167 plTarget
->SendNewItem(item
,count
,true,false);
2170 if(noSpaceForCount
> 0)
2171 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, itemId
, noSpaceForCount
);
2176 bool ChatHandler::HandleAddItemSetCommand(const char* args
)
2181 char* cId
= extractKeyFromLink((char*)args
,"Hitemset"); // number or [name] Shift-click form |color|Hitemset:itemset_id|h[name]|h|r
2185 uint32 itemsetId
= atol(cId
);
2187 // prevent generation all items with itemset field value '0'
2190 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND
,itemsetId
);
2191 SetSentErrorMessage(true);
2195 Player
* pl
= m_session
->GetPlayer();
2196 Player
* plTarget
= getSelectedPlayer();
2200 DETAIL_LOG(GetMangosString(LANG_ADDITEMSET
), itemsetId
);
2203 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
2205 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
2209 if (pProto
->ItemSet
== itemsetId
)
2212 ItemPosCountVec dest
;
2213 uint8 msg
= plTarget
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, pProto
->ItemId
, 1 );
2214 if (msg
== EQUIP_ERR_OK
)
2216 Item
* item
= plTarget
->StoreNewItem( dest
, pProto
->ItemId
, true);
2218 // remove binding (let GM give it to another player later)
2220 item
->SetBinding( false );
2222 pl
->SendNewItem(item
,1,false,true);
2224 plTarget
->SendNewItem(item
,1,true,false);
2228 pl
->SendEquipError( msg
, NULL
, NULL
, pProto
->ItemId
);
2229 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, pProto
->ItemId
, 1);
2236 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND
,itemsetId
);
2238 SetSentErrorMessage(true);
2245 bool ChatHandler::HandleListItemCommand(const char* args
)
2250 char* cId
= extractKeyFromLink((char*)args
,"Hitem");
2254 uint32 item_id
= atol(cId
);
2257 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
2258 SetSentErrorMessage(true);
2262 ItemPrototype
const* itemProto
= ObjectMgr::GetItemPrototype(item_id
);
2265 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
2266 SetSentErrorMessage(true);
2270 char* c_count
= strtok(NULL
, " ");
2271 int count
= c_count
? atol(c_count
) : 10;
2276 QueryResult
*result
;
2279 uint32 inv_count
= 0;
2280 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM character_inventory WHERE item_template='%u'",item_id
);
2283 inv_count
= (*result
)[0].GetUInt32();
2287 result
=CharacterDatabase
.PQuery(
2289 "SELECT ci.item, cibag.slot AS bag, ci.slot, ci.guid, characters.account,characters.name "
2290 "FROM character_inventory AS ci LEFT JOIN character_inventory AS cibag ON (cibag.item=ci.bag),characters "
2291 "WHERE ci.item_template='%u' AND ci.guid = characters.guid LIMIT %u ",
2292 item_id
,uint32(count
));
2298 Field
*fields
= result
->Fetch();
2299 uint32 item_guid
= fields
[0].GetUInt32();
2300 uint32 item_bag
= fields
[1].GetUInt32();
2301 uint32 item_slot
= fields
[2].GetUInt32();
2302 uint32 owner_guid
= fields
[3].GetUInt32();
2303 uint32 owner_acc
= fields
[4].GetUInt32();
2304 std::string owner_name
= fields
[5].GetCppString();
2306 char const* item_pos
= 0;
2307 if(Player::IsEquipmentPos(item_bag
,item_slot
))
2308 item_pos
= "[equipped]";
2309 else if(Player::IsInventoryPos(item_bag
,item_slot
))
2310 item_pos
= "[in inventory]";
2311 else if(Player::IsBankPos(item_bag
,item_slot
))
2312 item_pos
= "[in bank]";
2316 PSendSysMessage(LANG_ITEMLIST_SLOT
,
2317 item_guid
,owner_name
.c_str(),owner_guid
,owner_acc
,item_pos
);
2318 } while (result
->NextRow());
2320 int res_count
= (int)result
->GetRowCount();
2324 if(count
> res_count
)
2331 uint32 mail_count
= 0;
2332 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM mail_items WHERE item_template='%u'", item_id
);
2335 mail_count
= (*result
)[0].GetUInt32();
2341 result
=CharacterDatabase
.PQuery(
2343 "SELECT mail_items.item_guid, mail.sender, mail.receiver, char_s.account, char_s.name, char_r.account, char_r.name "
2344 "FROM mail,mail_items,characters as char_s,characters as char_r "
2345 "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",
2346 item_id
,uint32(count
));
2355 Field
*fields
= result
->Fetch();
2356 uint32 item_guid
= fields
[0].GetUInt32();
2357 uint32 item_s
= fields
[1].GetUInt32();
2358 uint32 item_r
= fields
[2].GetUInt32();
2359 uint32 item_s_acc
= fields
[3].GetUInt32();
2360 std::string item_s_name
= fields
[4].GetCppString();
2361 uint32 item_r_acc
= fields
[5].GetUInt32();
2362 std::string item_r_name
= fields
[6].GetCppString();
2364 char const* item_pos
= "[in mail]";
2366 PSendSysMessage(LANG_ITEMLIST_MAIL
,
2367 item_guid
,item_s_name
.c_str(),item_s
,item_s_acc
,item_r_name
.c_str(),item_r
,item_r_acc
,item_pos
);
2368 } while (result
->NextRow());
2370 int res_count
= (int)result
->GetRowCount();
2374 if(count
> res_count
)
2381 uint32 auc_count
= 0;
2382 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM auctionhouse WHERE item_template='%u'",item_id
);
2385 auc_count
= (*result
)[0].GetUInt32();
2391 result
=CharacterDatabase
.PQuery(
2393 "SELECT auctionhouse.itemguid, auctionhouse.itemowner, characters.account, characters.name "
2394 "FROM auctionhouse,characters WHERE auctionhouse.item_template='%u' AND characters.guid = auctionhouse.itemowner LIMIT %u",
2395 item_id
,uint32(count
));
2404 Field
*fields
= result
->Fetch();
2405 uint32 item_guid
= fields
[0].GetUInt32();
2406 uint32 owner
= fields
[1].GetUInt32();
2407 uint32 owner_acc
= fields
[2].GetUInt32();
2408 std::string owner_name
= fields
[3].GetCppString();
2410 char const* item_pos
= "[in auction]";
2412 PSendSysMessage(LANG_ITEMLIST_AUCTION
, item_guid
, owner_name
.c_str(), owner
, owner_acc
,item_pos
);
2413 } while (result
->NextRow());
2419 uint32 guild_count
= 0;
2420 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_entry) FROM guild_bank_item WHERE item_entry='%u'",item_id
);
2423 guild_count
= (*result
)[0].GetUInt32();
2427 result
=CharacterDatabase
.PQuery(
2429 "SELECT gi.item_guid, gi.guildid, guild.name "
2430 "FROM guild_bank_item AS gi, guild WHERE gi.item_entry='%u' AND gi.guildid = guild.guildid LIMIT %u ",
2431 item_id
,uint32(count
));
2437 Field
*fields
= result
->Fetch();
2438 uint32 item_guid
= fields
[0].GetUInt32();
2439 uint32 guild_guid
= fields
[1].GetUInt32();
2440 std::string guild_name
= fields
[2].GetCppString();
2442 char const* item_pos
= "[in guild bank]";
2444 PSendSysMessage(LANG_ITEMLIST_GUILD
,item_guid
,guild_name
.c_str(),guild_guid
,item_pos
);
2445 } while (result
->NextRow());
2447 int res_count
= (int)result
->GetRowCount();
2451 if(count
> res_count
)
2457 if(inv_count
+mail_count
+auc_count
+guild_count
== 0)
2459 SendSysMessage(LANG_COMMAND_NOITEMFOUND
);
2460 SetSentErrorMessage(true);
2464 PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE
,item_id
,inv_count
+mail_count
+auc_count
+guild_count
,inv_count
,mail_count
,auc_count
,guild_count
);
2469 bool ChatHandler::HandleListObjectCommand(const char* args
)
2474 // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2475 char* cId
= extractKeyFromLink((char*)args
,"Hgameobject_entry");
2479 uint32 go_id
= atol(cId
);
2482 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID
, go_id
);
2483 SetSentErrorMessage(true);
2487 GameObjectInfo
const * gInfo
= ObjectMgr::GetGameObjectInfo(go_id
);
2490 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID
, go_id
);
2491 SetSentErrorMessage(true);
2495 char* c_count
= strtok(NULL
, " ");
2496 int count
= c_count
? atol(c_count
) : 10;
2501 QueryResult
*result
;
2503 uint32 obj_count
= 0;
2504 result
=WorldDatabase
.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'",go_id
);
2507 obj_count
= (*result
)[0].GetUInt32();
2513 Player
* pl
= m_session
->GetPlayer();
2514 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",
2515 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(),go_id
,uint32(count
));
2518 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map FROM gameobject WHERE id = '%u' LIMIT %u",
2519 go_id
,uint32(count
));
2525 Field
*fields
= result
->Fetch();
2526 uint32 guid
= fields
[0].GetUInt32();
2527 float x
= fields
[1].GetFloat();
2528 float y
= fields
[2].GetFloat();
2529 float z
= fields
[3].GetFloat();
2530 int mapid
= fields
[4].GetUInt16();
2533 PSendSysMessage(LANG_GO_LIST_CHAT
, guid
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2535 PSendSysMessage(LANG_GO_LIST_CONSOLE
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2536 } while (result
->NextRow());
2541 PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE
,go_id
,obj_count
);
2545 bool ChatHandler::HandleListCreatureCommand(const char* args
)
2550 // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
2551 char* cId
= extractKeyFromLink((char*)args
,"Hcreature_entry");
2555 uint32 cr_id
= atol(cId
);
2558 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID
, cr_id
);
2559 SetSentErrorMessage(true);
2563 CreatureInfo
const* cInfo
= ObjectMgr::GetCreatureTemplate(cr_id
);
2566 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID
, cr_id
);
2567 SetSentErrorMessage(true);
2571 char* c_count
= strtok(NULL
, " ");
2572 int count
= c_count
? atol(c_count
) : 10;
2577 QueryResult
*result
;
2579 uint32 cr_count
= 0;
2580 result
=WorldDatabase
.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'",cr_id
);
2583 cr_count
= (*result
)[0].GetUInt32();
2589 Player
* pl
= m_session
->GetPlayer();
2590 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",
2591 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(), cr_id
,uint32(count
));
2594 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '%u' LIMIT %u",
2595 cr_id
,uint32(count
));
2601 Field
*fields
= result
->Fetch();
2602 uint32 guid
= fields
[0].GetUInt32();
2603 float x
= fields
[1].GetFloat();
2604 float y
= fields
[2].GetFloat();
2605 float z
= fields
[3].GetFloat();
2606 int mapid
= fields
[4].GetUInt16();
2609 PSendSysMessage(LANG_CREATURE_LIST_CHAT
, guid
, guid
, cInfo
->Name
, x
, y
, z
, mapid
);
2611 PSendSysMessage(LANG_CREATURE_LIST_CONSOLE
, guid
, cInfo
->Name
, x
, y
, z
, mapid
);
2612 } while (result
->NextRow());
2617 PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE
,cr_id
,cr_count
);
2621 bool ChatHandler::HandleLookupItemCommand(const char* args
)
2626 std::string namepart
= args
;
2627 std::wstring wnamepart
;
2629 // converting string that we try to find to lower case
2630 if(!Utf8toWStr(namepart
,wnamepart
))
2633 wstrToLower(wnamepart
);
2637 // Search in `item_template`
2638 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
2640 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
2644 int loc_idx
= GetSessionDbLocaleIndex();
2647 ItemLocale
const *il
= sObjectMgr
.GetItemLocale(pProto
->ItemId
);
2650 if ((int32
)il
->Name
.size() > loc_idx
&& !il
->Name
[loc_idx
].empty())
2652 std::string name
= il
->Name
[loc_idx
];
2654 if (Utf8FitTo(name
, wnamepart
))
2657 PSendSysMessage(LANG_ITEM_LIST_CHAT
, id
, id
, name
.c_str());
2659 PSendSysMessage(LANG_ITEM_LIST_CONSOLE
, id
, name
.c_str());
2667 std::string name
= pProto
->Name1
;
2671 if (Utf8FitTo(name
, wnamepart
))
2674 PSendSysMessage(LANG_ITEM_LIST_CHAT
, id
, id
, name
.c_str());
2676 PSendSysMessage(LANG_ITEM_LIST_CONSOLE
, id
, name
.c_str());
2682 SendSysMessage(LANG_COMMAND_NOITEMFOUND
);
2687 bool ChatHandler::HandleLookupItemSetCommand(const char* args
)
2692 std::string namepart
= args
;
2693 std::wstring wnamepart
;
2695 if(!Utf8toWStr(namepart
,wnamepart
))
2698 // converting string that we try to find to lower case
2699 wstrToLower( wnamepart
);
2701 uint32 counter
= 0; // Counter for figure out that we found smth.
2703 // Search in ItemSet.dbc
2704 for (uint32 id
= 0; id
< sItemSetStore
.GetNumRows(); id
++)
2706 ItemSetEntry
const *set
= sItemSetStore
.LookupEntry(id
);
2709 int loc
= GetSessionDbcLocale();
2710 std::string name
= set
->name
[loc
];
2714 if (!Utf8FitTo(name
, wnamepart
))
2717 for(; loc
< MAX_LOCALE
; ++loc
)
2719 if(loc
==GetSessionDbcLocale())
2722 name
= set
->name
[loc
];
2726 if (Utf8FitTo(name
, wnamepart
))
2731 if(loc
< MAX_LOCALE
)
2733 // send item set in "id - [namedlink locale]" format
2735 PSendSysMessage(LANG_ITEMSET_LIST_CHAT
,id
,id
,name
.c_str(),localeNames
[loc
]);
2737 PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE
,id
,name
.c_str(),localeNames
[loc
]);
2742 if (counter
== 0) // if counter == 0 then we found nth
2743 SendSysMessage(LANG_COMMAND_NOITEMSETFOUND
);
2747 bool ChatHandler::HandleLookupSkillCommand(const char* args
)
2752 // can be NULL in console call
2753 Player
* target
= getSelectedPlayer();
2755 std::string namepart
= args
;
2756 std::wstring wnamepart
;
2758 if(!Utf8toWStr(namepart
,wnamepart
))
2761 // converting string that we try to find to lower case
2762 wstrToLower( wnamepart
);
2764 uint32 counter
= 0; // Counter for figure out that we found smth.
2766 // Search in SkillLine.dbc
2767 for (uint32 id
= 0; id
< sSkillLineStore
.GetNumRows(); id
++)
2769 SkillLineEntry
const *skillInfo
= sSkillLineStore
.LookupEntry(id
);
2772 int loc
= GetSessionDbcLocale();
2773 std::string name
= skillInfo
->name
[loc
];
2777 if (!Utf8FitTo(name
, wnamepart
))
2780 for(; loc
< MAX_LOCALE
; ++loc
)
2782 if(loc
==GetSessionDbcLocale())
2785 name
= skillInfo
->name
[loc
];
2789 if (Utf8FitTo(name
, wnamepart
))
2794 if(loc
< MAX_LOCALE
)
2796 char valStr
[50] = "";
2797 char const* knownStr
= "";
2798 if(target
&& target
->HasSkill(id
))
2800 knownStr
= GetMangosString(LANG_KNOWN
);
2801 uint32 curValue
= target
->GetPureSkillValue(id
);
2802 uint32 maxValue
= target
->GetPureMaxSkillValue(id
);
2803 uint32 permValue
= target
->GetSkillPermBonusValue(id
);
2804 uint32 tempValue
= target
->GetSkillTempBonusValue(id
);
2806 char const* valFormat
= GetMangosString(LANG_SKILL_VALUES
);
2807 snprintf(valStr
,50,valFormat
,curValue
,maxValue
,permValue
,tempValue
);
2810 // send skill in "id - [namedlink locale]" format
2812 PSendSysMessage(LANG_SKILL_LIST_CHAT
,id
,id
,name
.c_str(),localeNames
[loc
],knownStr
,valStr
);
2814 PSendSysMessage(LANG_SKILL_LIST_CONSOLE
,id
,name
.c_str(),localeNames
[loc
],knownStr
,valStr
);
2820 if (counter
== 0) // if counter == 0 then we found nth
2821 SendSysMessage(LANG_COMMAND_NOSKILLFOUND
);
2825 void ChatHandler::ShowSpellListHelper(Player
* target
, SpellEntry
const* spellInfo
, LocaleConstant loc
)
2827 uint32 id
= spellInfo
->Id
;
2829 bool known
= target
&& target
->HasSpell(id
);
2830 bool learn
= (spellInfo
->Effect
[EFFECT_INDEX_0
] == SPELL_EFFECT_LEARN_SPELL
);
2832 uint32 talentCost
= GetTalentSpellCost(id
);
2834 bool talent
= (talentCost
> 0);
2835 bool passive
= IsPassiveSpell(spellInfo
);
2836 bool active
= target
&& target
->HasAura(id
);
2838 // unit32 used to prevent interpreting uint8 as char at output
2839 // find rank of learned spell for learning spell, or talent rank
2840 uint32 rank
= talentCost
? talentCost
: sSpellMgr
.GetSpellRank(learn
? spellInfo
->EffectTriggerSpell
[EFFECT_INDEX_0
] : id
);
2842 // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
2843 std::ostringstream ss
;
2845 ss
<< id
<< " - |cffffffff|Hspell:" << id
<< "|h[" << spellInfo
->SpellName
[loc
];
2847 ss
<< id
<< " - " << spellInfo
->SpellName
[loc
];
2849 // include rank in link name
2851 ss
<< GetMangosString(LANG_SPELL_RANK
) << rank
;
2854 ss
<< " " << localeNames
[loc
] << "]|h|r";
2856 ss
<< " " << localeNames
[loc
];
2859 ss
<< GetMangosString(LANG_TALENT
);
2861 ss
<< GetMangosString(LANG_PASSIVE
);
2863 ss
<< GetMangosString(LANG_LEARN
);
2865 ss
<< GetMangosString(LANG_KNOWN
);
2867 ss
<< GetMangosString(LANG_ACTIVE
);
2869 SendSysMessage(ss
.str().c_str());
2872 bool ChatHandler::HandleLookupSpellCommand(const char* args
)
2877 // can be NULL at console call
2878 Player
* target
= getSelectedPlayer();
2880 std::string namepart
= args
;
2881 std::wstring wnamepart
;
2883 if(!Utf8toWStr(namepart
,wnamepart
))
2886 // converting string that we try to find to lower case
2887 wstrToLower( wnamepart
);
2889 uint32 counter
= 0; // Counter for figure out that we found smth.
2891 // Search in Spell.dbc
2892 for (uint32 id
= 0; id
< sSpellStore
.GetNumRows(); id
++)
2894 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(id
);
2897 int loc
= GetSessionDbcLocale();
2898 std::string name
= spellInfo
->SpellName
[loc
];
2902 if (!Utf8FitTo(name
, wnamepart
))
2905 for(; loc
< MAX_LOCALE
; ++loc
)
2907 if(loc
==GetSessionDbcLocale())
2910 name
= spellInfo
->SpellName
[loc
];
2914 if (Utf8FitTo(name
, wnamepart
))
2919 if(loc
< MAX_LOCALE
)
2921 ShowSpellListHelper(target
, spellInfo
, LocaleConstant(loc
));
2926 if (counter
== 0) // if counter == 0 then we found nth
2927 SendSysMessage(LANG_COMMAND_NOSPELLFOUND
);
2931 bool ChatHandler::HandleLookupQuestCommand(const char* args
)
2936 // can be NULL at console call
2937 Player
* target
= getSelectedPlayer();
2939 std::string namepart
= args
;
2940 std::wstring wnamepart
;
2942 // converting string that we try to find to lower case
2943 if(!Utf8toWStr(namepart
,wnamepart
))
2946 wstrToLower(wnamepart
);
2948 uint32 counter
= 0 ;
2950 ObjectMgr::QuestMap
const& qTemplates
= sObjectMgr
.GetQuestTemplates();
2951 for (ObjectMgr::QuestMap::const_iterator iter
= qTemplates
.begin(); iter
!= qTemplates
.end(); ++iter
)
2953 Quest
* qinfo
= iter
->second
;
2955 int loc_idx
= GetSessionDbLocaleIndex();
2958 QuestLocale
const *il
= sObjectMgr
.GetQuestLocale(qinfo
->GetQuestId());
2961 if ((int32
)il
->Title
.size() > loc_idx
&& !il
->Title
[loc_idx
].empty())
2963 std::string title
= il
->Title
[loc_idx
];
2965 if (Utf8FitTo(title
, wnamepart
))
2967 char const* statusStr
= "";
2971 QuestStatus status
= target
->GetQuestStatus(qinfo
->GetQuestId());
2973 if(status
== QUEST_STATUS_COMPLETE
)
2975 if(target
->GetQuestRewardStatus(qinfo
->GetQuestId()))
2976 statusStr
= GetMangosString(LANG_COMMAND_QUEST_REWARDED
);
2978 statusStr
= GetMangosString(LANG_COMMAND_QUEST_COMPLETE
);
2980 else if(status
== QUEST_STATUS_INCOMPLETE
)
2981 statusStr
= GetMangosString(LANG_COMMAND_QUEST_ACTIVE
);
2985 PSendSysMessage(LANG_QUEST_LIST_CHAT
,qinfo
->GetQuestId(),qinfo
->GetQuestId(),qinfo
->GetQuestLevel(),title
.c_str(),statusStr
);
2987 PSendSysMessage(LANG_QUEST_LIST_CONSOLE
,qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2995 std::string title
= qinfo
->GetTitle();
2999 if (Utf8FitTo(title
, wnamepart
))
3001 char const* statusStr
= "";
3005 QuestStatus status
= target
->GetQuestStatus(qinfo
->GetQuestId());
3007 if(status
== QUEST_STATUS_COMPLETE
)
3009 if(target
->GetQuestRewardStatus(qinfo
->GetQuestId()))
3010 statusStr
= GetMangosString(LANG_COMMAND_QUEST_REWARDED
);
3012 statusStr
= GetMangosString(LANG_COMMAND_QUEST_COMPLETE
);
3014 else if(status
== QUEST_STATUS_INCOMPLETE
)
3015 statusStr
= GetMangosString(LANG_COMMAND_QUEST_ACTIVE
);
3019 PSendSysMessage(LANG_QUEST_LIST_CHAT
,qinfo
->GetQuestId(),qinfo
->GetQuestId(),qinfo
->GetQuestLevel(),title
.c_str(),statusStr
);
3021 PSendSysMessage(LANG_QUEST_LIST_CONSOLE
,qinfo
->GetQuestId(),title
.c_str(),statusStr
);
3028 SendSysMessage(LANG_COMMAND_NOQUESTFOUND
);
3033 bool ChatHandler::HandleLookupCreatureCommand(const char* args
)
3038 std::string namepart
= args
;
3039 std::wstring wnamepart
;
3041 // converting string that we try to find to lower case
3042 if (!Utf8toWStr (namepart
,wnamepart
))
3045 wstrToLower (wnamepart
);
3049 for (uint32 id
= 0; id
< sCreatureStorage
.MaxEntry
; ++id
)
3051 CreatureInfo
const* cInfo
= sCreatureStorage
.LookupEntry
<CreatureInfo
> (id
);
3055 int loc_idx
= GetSessionDbLocaleIndex();
3058 CreatureLocale
const *cl
= sObjectMgr
.GetCreatureLocale (id
);
3061 if ((int32
)cl
->Name
.size() > loc_idx
&& !cl
->Name
[loc_idx
].empty ())
3063 std::string name
= cl
->Name
[loc_idx
];
3065 if (Utf8FitTo (name
, wnamepart
))
3068 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str ());
3070 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE
, id
, name
.c_str ());
3078 std::string name
= cInfo
->Name
;
3082 if (Utf8FitTo(name
, wnamepart
))
3085 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str ());
3087 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE
, id
, name
.c_str ());
3093 SendSysMessage (LANG_COMMAND_NOCREATUREFOUND
);
3098 bool ChatHandler::HandleLookupObjectCommand(const char* args
)
3103 std::string namepart
= args
;
3104 std::wstring wnamepart
;
3106 // converting string that we try to find to lower case
3107 if(!Utf8toWStr(namepart
,wnamepart
))
3110 wstrToLower(wnamepart
);
3114 for (uint32 id
= 0; id
< sGOStorage
.MaxEntry
; id
++ )
3116 GameObjectInfo
const* gInfo
= sGOStorage
.LookupEntry
<GameObjectInfo
>(id
);
3120 int loc_idx
= GetSessionDbLocaleIndex();
3123 GameObjectLocale
const *gl
= sObjectMgr
.GetGameObjectLocale(id
);
3126 if ((int32
)gl
->Name
.size() > loc_idx
&& !gl
->Name
[loc_idx
].empty())
3128 std::string name
= gl
->Name
[loc_idx
];
3130 if (Utf8FitTo(name
, wnamepart
))
3133 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT
, id
, id
, name
.c_str());
3135 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE
, id
, name
.c_str());
3143 std::string name
= gInfo
->name
;
3147 if(Utf8FitTo(name
, wnamepart
))
3150 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT
, id
, id
, name
.c_str());
3152 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE
, id
, name
.c_str());
3158 SendSysMessage(LANG_COMMAND_NOGAMEOBJECTFOUND
);
3163 bool ChatHandler::HandleLookupTaxiNodeCommand(const char * args
)
3168 std::string namepart
= args
;
3169 std::wstring wnamepart
;
3171 if(!Utf8toWStr(namepart
,wnamepart
))
3174 // converting string that we try to find to lower case
3175 wstrToLower( wnamepart
);
3177 uint32 counter
= 0; // Counter for figure out that we found smth.
3179 // Search in TaxiNodes.dbc
3180 for (uint32 id
= 0; id
< sTaxiNodesStore
.GetNumRows(); id
++)
3182 TaxiNodesEntry
const *nodeEntry
= sTaxiNodesStore
.LookupEntry(id
);
3185 int loc
= GetSessionDbcLocale();
3186 std::string name
= nodeEntry
->name
[loc
];
3190 if (!Utf8FitTo(name
, wnamepart
))
3193 for(; loc
< MAX_LOCALE
; ++loc
)
3195 if(loc
==GetSessionDbcLocale())
3198 name
= nodeEntry
->name
[loc
];
3202 if (Utf8FitTo(name
, wnamepart
))
3207 if(loc
< MAX_LOCALE
)
3209 // send taxinode in "id - [name] (Map:m X:x Y:y Z:z)" format
3211 PSendSysMessage (LANG_TAXINODE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str(),localeNames
[loc
],
3212 nodeEntry
->map_id
,nodeEntry
->x
,nodeEntry
->y
,nodeEntry
->z
);
3214 PSendSysMessage (LANG_TAXINODE_ENTRY_LIST_CONSOLE
, id
, name
.c_str(), localeNames
[loc
],
3215 nodeEntry
->map_id
,nodeEntry
->x
,nodeEntry
->y
,nodeEntry
->z
);
3220 if (counter
== 0) // if counter == 0 then we found nth
3221 SendSysMessage(LANG_COMMAND_NOTAXINODEFOUND
);
3225 /** \brief GM command level 3 - Create a guild.
3227 * This command allows a GM (level 3) to create a guild.
3229 * The "args" parameter contains the name of the guild leader
3230 * and then the name of the guild.
3233 bool ChatHandler::HandleGuildCreateCommand(const char* args
)
3238 // if not guild name only (in "") then player name
3240 if(!extractPlayerTarget(*args
!='"' ? (char*)args
: NULL
, &target
))
3243 char* tailStr
= *args
!='"' ? strtok(NULL
, "") : (char*)args
;
3247 char* guildStr
= extractQuotedArg(tailStr
);
3251 std::string guildname
= guildStr
;
3253 if (target
->GetGuildId())
3255 SendSysMessage (LANG_PLAYER_IN_GUILD
);
3259 Guild
*guild
= new Guild
;
3260 if (!guild
->Create (target
,guildname
))
3263 SendSysMessage (LANG_GUILD_NOT_CREATED
);
3264 SetSentErrorMessage (true);
3268 sObjectMgr
.AddGuild (guild
);
3272 bool ChatHandler::HandleGuildInviteCommand(const char *args
)
3277 // if not guild name only (in "") then player name
3279 if(!extractPlayerTarget(*args
!='"' ? (char*)args
: NULL
, NULL
, &target_guid
))
3282 char* tailStr
= *args
!='"' ? strtok(NULL
, "") : (char*)args
;
3286 char* guildStr
= extractQuotedArg(tailStr
);
3290 std::string glName
= guildStr
;
3291 Guild
* targetGuild
= sObjectMgr
.GetGuildByName (glName
);
3295 // player's guild membership checked in AddMember before add
3296 if (!targetGuild
->AddMember (target_guid
,targetGuild
->GetLowestRank ()))
3302 bool ChatHandler::HandleGuildUninviteCommand(const char *args
)
3306 if(!extractPlayerTarget((char*)args
,&target
,&target_guid
))
3309 uint32 glId
= target
? target
->GetGuildId () : Player::GetGuildIdFromDB (target_guid
);
3313 Guild
* targetGuild
= sObjectMgr
.GetGuildById (glId
);
3317 targetGuild
->DelMember (target_guid
);
3321 bool ChatHandler::HandleGuildRankCommand(const char *args
)
3325 extractOptFirstArg((char*)args
,&nameStr
,&rankStr
);
3331 std::string target_name
;
3332 if(!extractPlayerTarget(nameStr
,&target
,&target_guid
,&target_name
))
3335 uint32 glId
= target
? target
->GetGuildId () : Player::GetGuildIdFromDB (target_guid
);
3339 Guild
* targetGuild
= sObjectMgr
.GetGuildById (glId
);
3343 uint32 newrank
= uint32 (atoi (rankStr
));
3344 if (newrank
> targetGuild
->GetLowestRank ())
3347 targetGuild
->ChangeRank (target_guid
,newrank
);
3351 bool ChatHandler::HandleGuildDeleteCommand(const char* args
)
3356 char* guildStr
= extractQuotedArg((char*)args
);
3360 std::string gld
= guildStr
;
3362 Guild
* targetGuild
= sObjectMgr
.GetGuildByName (gld
);
3366 targetGuild
->Disband ();
3371 bool ChatHandler::HandleGetDistanceCommand(const char* args
)
3373 WorldObject
* obj
= NULL
;
3377 uint64 guid
= extractGuidFromLink((char*)args
);
3379 obj
= (WorldObject
*)m_session
->GetPlayer()->GetObjectByTypeMask(guid
, TYPEMASK_CREATURE_OR_GAMEOBJECT
);
3383 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3384 SetSentErrorMessage(true);
3390 obj
= getSelectedUnit();
3394 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3395 SetSentErrorMessage(true);
3400 PSendSysMessage(LANG_DISTANCE
, m_session
->GetPlayer()->GetDistance(obj
),m_session
->GetPlayer()->GetDistance2d(obj
));
3405 bool ChatHandler::HandleDieCommand(const char* /*args*/)
3407 Unit
* target
= getSelectedUnit();
3409 if(!target
|| !m_session
->GetPlayer()->GetSelection())
3411 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3412 SetSentErrorMessage(true);
3416 if(target
->GetTypeId()==TYPEID_PLAYER
)
3418 if(HasLowerSecurity((Player
*)target
,0,false))
3422 if( target
->isAlive() )
3424 m_session
->GetPlayer()->DealDamage(target
, target
->GetHealth(), NULL
, DIRECT_DAMAGE
, SPELL_SCHOOL_MASK_NORMAL
, NULL
, false);
3430 bool ChatHandler::HandleDamageCommand(const char * args
)
3435 Unit
* target
= getSelectedUnit();
3437 if (!target
|| !m_session
->GetPlayer()->GetSelection())
3439 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3440 SetSentErrorMessage(true);
3444 if (!target
->isAlive())
3447 char* damageStr
= strtok((char*)args
, " ");
3451 int32 damage_int
= atoi((char*)damageStr
);
3455 uint32 damage
= damage_int
;
3457 char* schoolStr
= strtok((char*)NULL
, " ");
3459 // flat melee damage without resistence/etc reduction
3462 m_session
->GetPlayer()->DealDamage(target
, damage
, NULL
, DIRECT_DAMAGE
, SPELL_SCHOOL_MASK_NORMAL
, NULL
, false);
3463 if (target
!= m_session
->GetPlayer())
3464 m_session
->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2
, target
, 1, SPELL_SCHOOL_MASK_NORMAL
, damage
, 0, 0, VICTIMSTATE_NORMAL
, 0);
3468 uint32 school
= schoolStr
? atoi((char*)schoolStr
) : SPELL_SCHOOL_NORMAL
;
3469 if(school
>= MAX_SPELL_SCHOOL
)
3472 SpellSchoolMask schoolmask
= SpellSchoolMask(1 << school
);
3474 if ( schoolmask
& SPELL_SCHOOL_MASK_NORMAL
)
3475 damage
= m_session
->GetPlayer()->CalcArmorReducedDamage(target
, damage
);
3477 char* spellStr
= strtok((char*)NULL
, " ");
3479 // melee damage by specific school
3485 target
->CalculateAbsorbAndResist(m_session
->GetPlayer(),schoolmask
, SPELL_DIRECT_DAMAGE
, damage
, &absorb
, &resist
);
3487 if (damage
<= absorb
+ resist
)
3490 damage
-= absorb
+ resist
;
3492 m_session
->GetPlayer()->DealDamageMods(target
,damage
,&absorb
);
3493 m_session
->GetPlayer()->DealDamage(target
, damage
, NULL
, DIRECT_DAMAGE
, schoolmask
, NULL
, false);
3494 m_session
->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2
, target
, 1, schoolmask
, damage
, absorb
, resist
, VICTIMSTATE_NORMAL
, 0);
3500 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3501 uint32 spellid
= extractSpellIdFromLink((char*)args
);
3502 if (!spellid
|| !sSpellStore
.LookupEntry(spellid
))
3505 m_session
->GetPlayer()->SpellNonMeleeDamageLog(target
, spellid
, damage
);
3509 bool ChatHandler::HandleModifyArenaCommand(const char * args
)
3514 Player
*target
= getSelectedPlayer();
3517 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3518 SetSentErrorMessage(true);
3522 int32 amount
= (uint32
)atoi(args
);
3524 target
->ModifyArenaPoints(amount
);
3526 PSendSysMessage(LANG_COMMAND_MODIFY_ARENA
, GetNameLink(target
).c_str(), target
->GetArenaPoints());
3531 bool ChatHandler::HandleReviveCommand(const char* args
)
3535 if(!extractPlayerTarget((char*)args
,&target
,&target_guid
))
3540 target
->ResurrectPlayer(0.5f
);
3541 target
->SpawnCorpseBones();
3544 // will resurrected at login without corpse
3545 sObjectAccessor
.ConvertCorpseForPlayer(target_guid
);
3550 bool ChatHandler::HandleAuraCommand(const char* args
)
3552 Unit
*target
= getSelectedUnit();
3555 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3556 SetSentErrorMessage(true);
3560 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3561 uint32 spellID
= extractSpellIdFromLink((char*)args
);
3563 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry( spellID
);
3566 for(uint32 i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
3568 uint8 eff
= spellInfo
->Effect
[i
];
3569 if (eff
>=TOTAL_SPELL_EFFECTS
)
3571 if( IsAreaAuraEffect(eff
) ||
3572 eff
== SPELL_EFFECT_APPLY_AURA
||
3573 eff
== SPELL_EFFECT_PERSISTENT_AREA_AURA
)
3575 Aura
*Aur
= CreateAura(spellInfo
, SpellEffectIndex(i
), NULL
, target
);
3576 target
->AddAura(Aur
);
3584 bool ChatHandler::HandleUnAuraCommand(const char* args
)
3586 Unit
*target
= getSelectedUnit();
3589 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3590 SetSentErrorMessage(true);
3594 std::string argstr
= args
;
3595 if (argstr
== "all")
3597 target
->RemoveAllAuras();
3601 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3602 uint32 spellID
= extractSpellIdFromLink((char*)args
);
3606 target
->RemoveAurasDueToSpell(spellID
);
3611 bool ChatHandler::HandleLinkGraveCommand(const char* args
)
3616 char* px
= strtok((char*)args
, " ");
3620 uint32 g_id
= (uint32
)atoi(px
);
3624 char* px2
= strtok(NULL
, " ");
3628 else if (strncmp(px2
,"horde",6)==0)
3630 else if (strncmp(px2
,"alliance",9)==0)
3635 WorldSafeLocsEntry
const* graveyard
= sWorldSafeLocsStore
.LookupEntry(g_id
);
3639 PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST
, g_id
);
3640 SetSentErrorMessage(true);
3644 Player
* player
= m_session
->GetPlayer();
3646 uint32 zoneId
= player
->GetZoneId();
3648 AreaTableEntry
const *areaEntry
= GetAreaEntryByAreaID(zoneId
);
3649 if(!areaEntry
|| areaEntry
->zone
!=0 )
3651 PSendSysMessage(LANG_COMMAND_GRAVEYARDWRONGZONE
, g_id
,zoneId
);
3652 SetSentErrorMessage(true);
3656 if(sObjectMgr
.AddGraveYardLink(g_id
,zoneId
,g_team
))
3657 PSendSysMessage(LANG_COMMAND_GRAVEYARDLINKED
, g_id
,zoneId
);
3659 PSendSysMessage(LANG_COMMAND_GRAVEYARDALRLINKED
, g_id
,zoneId
);
3664 bool ChatHandler::HandleNearGraveCommand(const char* args
)
3668 size_t argslen
= strlen(args
);
3672 else if (strncmp((char*)args
,"horde",argslen
)==0)
3674 else if (strncmp((char*)args
,"alliance",argslen
)==0)
3679 Player
* player
= m_session
->GetPlayer();
3680 uint32 zone_id
= player
->GetZoneId();
3682 WorldSafeLocsEntry
const* graveyard
= sObjectMgr
.GetClosestGraveYard(
3683 player
->GetPositionX(), player
->GetPositionY(), player
->GetPositionZ(),player
->GetMapId(),g_team
);
3687 uint32 g_id
= graveyard
->ID
;
3689 GraveYardData
const* data
= sObjectMgr
.FindGraveYardData(g_id
,zone_id
);
3692 PSendSysMessage(LANG_COMMAND_GRAVEYARDERROR
,g_id
);
3693 SetSentErrorMessage(true);
3697 g_team
= data
->team
;
3699 std::string team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_NOTEAM
);
3702 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ANY
);
3703 else if(g_team
== HORDE
)
3704 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE
);
3705 else if(g_team
== ALLIANCE
)
3706 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE
);
3708 PSendSysMessage(LANG_COMMAND_GRAVEYARDNEAREST
, g_id
,team_name
.c_str(),zone_id
);
3712 std::string team_name
;
3715 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ANY
);
3716 else if(g_team
== HORDE
)
3717 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE
);
3718 else if(g_team
== ALLIANCE
)
3719 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE
);
3721 if(g_team
== ~uint32(0))
3722 PSendSysMessage(LANG_COMMAND_ZONENOGRAVEYARDS
, zone_id
);
3724 PSendSysMessage(LANG_COMMAND_ZONENOGRAFACTION
, zone_id
,team_name
.c_str());
3730 //-----------------------Npc Commands-----------------------
3731 bool ChatHandler::HandleNpcAllowMovementCommand(const char* /*args*/)
3733 if(sWorld
.getAllowMovement())
3735 sWorld
.SetAllowMovement(false);
3736 SendSysMessage(LANG_CREATURE_MOVE_DISABLED
);
3740 sWorld
.SetAllowMovement(true);
3741 SendSysMessage(LANG_CREATURE_MOVE_ENABLED
);
3746 bool ChatHandler::HandleNpcChangeEntryCommand(const char *args
)
3751 uint32 newEntryNum
= atoi(args
);
3755 Unit
* unit
= getSelectedUnit();
3756 if(!unit
|| unit
->GetTypeId() != TYPEID_UNIT
)
3758 SendSysMessage(LANG_SELECT_CREATURE
);
3759 SetSentErrorMessage(true);
3762 Creature
* creature
= (Creature
*)unit
;
3763 if(creature
->UpdateEntry(newEntryNum
))
3764 SendSysMessage(LANG_DONE
);
3766 SendSysMessage(LANG_ERROR
);
3770 bool ChatHandler::HandleNpcInfoCommand(const char* /*args*/)
3772 Creature
* target
= getSelectedCreature();
3776 SendSysMessage(LANG_SELECT_CREATURE
);
3777 SetSentErrorMessage(true);
3781 uint32 faction
= target
->getFaction();
3782 uint32 npcflags
= target
->GetUInt32Value(UNIT_NPC_FLAGS
);
3783 uint32 displayid
= target
->GetDisplayId();
3784 uint32 nativeid
= target
->GetNativeDisplayId();
3785 uint32 Entry
= target
->GetEntry();
3786 CreatureInfo
const* cInfo
= target
->GetCreatureInfo();
3788 time_t curRespawnDelay
= target
->GetRespawnTimeEx()-time(NULL
);
3789 if(curRespawnDelay
< 0)
3790 curRespawnDelay
= 0;
3791 std::string curRespawnDelayStr
= secsToTimeString(curRespawnDelay
,true);
3792 std::string defRespawnDelayStr
= secsToTimeString(target
->GetRespawnDelay(),true);
3794 PSendSysMessage(LANG_NPCINFO_CHAR
, target
->GetDBTableGUIDLow(), faction
, npcflags
, Entry
, displayid
, nativeid
);
3795 PSendSysMessage(LANG_NPCINFO_LEVEL
, target
->getLevel());
3796 PSendSysMessage(LANG_NPCINFO_HEALTH
,target
->GetCreateHealth(), target
->GetMaxHealth(), target
->GetHealth());
3797 PSendSysMessage(LANG_NPCINFO_FLAGS
, target
->GetUInt32Value(UNIT_FIELD_FLAGS
), target
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
), target
->getFaction());
3798 PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES
, defRespawnDelayStr
.c_str(),curRespawnDelayStr
.c_str());
3799 PSendSysMessage(LANG_NPCINFO_LOOT
, cInfo
->lootid
,cInfo
->pickpocketLootId
,cInfo
->SkinLootId
);
3800 PSendSysMessage(LANG_NPCINFO_DUNGEON_ID
, target
->GetInstanceId());
3801 PSendSysMessage(LANG_NPCINFO_POSITION
,float(target
->GetPositionX()), float(target
->GetPositionY()), float(target
->GetPositionZ()));
3803 if ((npcflags
& UNIT_NPC_FLAG_VENDOR
) )
3805 SendSysMessage(LANG_NPCINFO_VENDOR
);
3807 if ((npcflags
& UNIT_NPC_FLAG_TRAINER
) )
3809 SendSysMessage(LANG_NPCINFO_TRAINER
);
3816 bool ChatHandler::HandleNpcPlayEmoteCommand(const char* args
)
3818 uint32 emote
= atoi((char*)args
);
3820 Creature
* target
= getSelectedCreature();
3823 SendSysMessage(LANG_SELECT_CREATURE
);
3824 SetSentErrorMessage(true);
3828 target
->HandleEmote(emote
);
3833 //TODO: NpcCommands that needs to be fixed :
3835 bool ChatHandler::HandleNpcAddWeaponCommand(const char* /*args*/)
3840 uint64 guid = m_session->GetPlayer()->GetSelection();
3843 SendSysMessage(LANG_NO_SELECTION);
3847 Creature *pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
3851 SendSysMessage(LANG_SELECT_CREATURE);
3855 char* pSlotID = strtok((char*)args, " ");
3859 char* pItemID = strtok(NULL, " ");
3863 uint32 ItemID = atoi(pItemID);
3864 uint32 SlotID = atoi(pSlotID);
3866 ItemPrototype* tmpItem = ObjectMgr::GetItemPrototype(ItemID);
3874 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID);
3878 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID);
3882 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID);
3886 PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST,SlotID);
3892 PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT,ItemID,tmpItem->Name1,SlotID);
3896 PSendSysMessage(LANG_ITEM_NOT_FOUND,ItemID);
3902 //----------------------------------------------------------
3904 bool ChatHandler::HandleExploreCheatCommand(const char* args
)
3909 int flag
= atoi((char*)args
);
3911 Player
*chr
= getSelectedPlayer();
3914 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3915 SetSentErrorMessage(true);
3921 PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL
, GetNameLink(chr
).c_str());
3922 if (needReportToTarget(chr
))
3923 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_EXPLORE_SET_ALL
,GetNameLink().c_str());
3927 PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING
, GetNameLink(chr
).c_str());
3928 if (needReportToTarget(chr
))
3929 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_EXPLORE_SET_NOTHING
,GetNameLink().c_str());
3932 for (uint8 i
=0; i
<PLAYER_EXPLORED_ZONES_SIZE
; ++i
)
3936 m_session
->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1
+i
,0xFFFFFFFF);
3940 m_session
->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1
+i
,0);
3947 bool ChatHandler::HandleHoverCommand(const char* args
)
3949 char* px
= strtok((char*)args
, " ");
3956 m_session
->GetPlayer()->SetHover(flag
);
3959 SendSysMessage(LANG_HOVER_ENABLED
);
3961 SendSysMessage(LANG_HOVER_DISABLED
);
3966 void ChatHandler::HandleCharacterLevel(Player
* player
, uint64 player_guid
, uint32 oldlevel
, uint32 newlevel
)
3970 player
->GiveLevel(newlevel
);
3971 player
->InitTalentForLevel();
3972 player
->SetUInt32Value(PLAYER_XP
,0);
3974 if(needReportToTarget(player
))
3976 if(oldlevel
== newlevel
)
3977 ChatHandler(player
).PSendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET
,GetNameLink().c_str());
3978 else if(oldlevel
< newlevel
)
3979 ChatHandler(player
).PSendSysMessage(LANG_YOURS_LEVEL_UP
,GetNameLink().c_str(),newlevel
);
3980 else // if(oldlevel > newlevel)
3981 ChatHandler(player
).PSendSysMessage(LANG_YOURS_LEVEL_DOWN
,GetNameLink().c_str(),newlevel
);
3986 // update level and XP at level, all other will be updated at loading
3987 CharacterDatabase
.PExecute("UPDATE characters SET level = '%u', xp = 0 WHERE guid = '%u'", newlevel
, GUID_LOPART(player_guid
));
3991 bool ChatHandler::HandleCharacterLevelCommand(const char* args
)
3995 extractOptFirstArg((char*)args
,&nameStr
,&levelStr
);
3999 // exception opt second arg: .character level $name
4000 if(isalpha(levelStr
[0]))
4003 levelStr
= NULL
; // current level will used
4008 std::string target_name
;
4009 if(!extractPlayerTarget(nameStr
,&target
,&target_guid
,&target_name
))
4012 int32 oldlevel
= target
? target
->getLevel() : Player::GetLevelFromDB(target_guid
);
4013 int32 newlevel
= levelStr
? atoi(levelStr
) : oldlevel
;
4016 return false; // invalid level
4018 if(newlevel
> STRONG_MAX_LEVEL
) // hardcoded maximum level
4019 newlevel
= STRONG_MAX_LEVEL
;
4021 HandleCharacterLevel(target
,target_guid
,oldlevel
,newlevel
);
4023 if(!m_session
|| m_session
->GetPlayer() != target
) // including player==NULL
4025 std::string nameLink
= playerLink(target_name
);
4026 PSendSysMessage(LANG_YOU_CHANGE_LVL
,nameLink
.c_str(),newlevel
);
4032 bool ChatHandler::HandleLevelUpCommand(const char* args
)
4036 extractOptFirstArg((char*)args
,&nameStr
,&levelStr
);
4038 // exception opt second arg: .character level $name
4039 if(levelStr
&& isalpha(levelStr
[0]))
4042 levelStr
= NULL
; // current level will used
4047 std::string target_name
;
4048 if(!extractPlayerTarget(nameStr
,&target
,&target_guid
,&target_name
))
4051 int32 oldlevel
= target
? target
->getLevel() : Player::GetLevelFromDB(target_guid
);
4052 int32 addlevel
= levelStr
? atoi(levelStr
) : 1;
4053 int32 newlevel
= oldlevel
+ addlevel
;
4058 if(newlevel
> STRONG_MAX_LEVEL
) // hardcoded maximum level
4059 newlevel
= STRONG_MAX_LEVEL
;
4061 HandleCharacterLevel(target
,target_guid
,oldlevel
,newlevel
);
4063 if(!m_session
|| m_session
->GetPlayer() != target
) // including chr==NULL
4065 std::string nameLink
= playerLink(target_name
);
4066 PSendSysMessage(LANG_YOU_CHANGE_LVL
,nameLink
.c_str(),newlevel
);
4072 bool ChatHandler::HandleShowAreaCommand(const char* args
)
4077 Player
*chr
= getSelectedPlayer();
4080 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4081 SetSentErrorMessage(true);
4085 int area
= GetAreaFlagByAreaID(atoi((char*)args
));
4086 int offset
= area
/ 32;
4087 uint32 val
= (uint32
)(1 << (area
% 32));
4089 if(area
<0 || offset
>= PLAYER_EXPLORED_ZONES_SIZE
)
4091 SendSysMessage(LANG_BAD_VALUE
);
4092 SetSentErrorMessage(true);
4096 uint32 currFields
= chr
->GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
4097 chr
->SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
| val
));
4099 SendSysMessage(LANG_EXPLORE_AREA
);
4103 bool ChatHandler::HandleHideAreaCommand(const char* args
)
4108 Player
*chr
= getSelectedPlayer();
4111 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4112 SetSentErrorMessage(true);
4116 int area
= GetAreaFlagByAreaID(atoi((char*)args
));
4117 int offset
= area
/ 32;
4118 uint32 val
= (uint32
)(1 << (area
% 32));
4120 if(area
<0 || offset
>= PLAYER_EXPLORED_ZONES_SIZE
)
4122 SendSysMessage(LANG_BAD_VALUE
);
4123 SetSentErrorMessage(true);
4127 uint32 currFields
= chr
->GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
4128 chr
->SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
^ val
));
4130 SendSysMessage(LANG_UNEXPLORE_AREA
);
4134 bool ChatHandler::HandleBankCommand(const char* /*args*/)
4136 m_session
->SendShowBank( m_session
->GetPlayer()->GetGUID() );
4141 bool ChatHandler::HandleChangeWeather(const char* args
)
4147 if (!sWorld
.getConfig(CONFIG_BOOL_WEATHER
))
4149 SendSysMessage(LANG_WEATHER_DISABLED
);
4150 SetSentErrorMessage(true);
4154 //*Change the weather of a cell
4155 char* px
= strtok((char*)args
, " ");
4156 char* py
= strtok(NULL
, " ");
4161 uint32 type
= (uint32
)atoi(px
); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
4162 float grade
= (float)atof(py
); //0 to 1, sending -1 is instand good weather
4164 Player
*player
= m_session
->GetPlayer();
4165 uint32 zoneid
= player
->GetZoneId();
4167 Weather
* wth
= sWorld
.FindWeather(zoneid
);
4170 wth
= sWorld
.AddWeather(zoneid
);
4173 SendSysMessage(LANG_NO_WEATHER
);
4174 SetSentErrorMessage(true);
4178 wth
->SetWeather(WeatherType(type
), grade
);
4183 bool ChatHandler::HandleTeleAddCommand(const char * args
)
4188 Player
*player
=m_session
->GetPlayer();
4192 std::string name
= args
;
4194 if(sObjectMgr
.GetGameTele(name
))
4196 SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST
);
4197 SetSentErrorMessage(true);
4202 tele
.position_x
= player
->GetPositionX();
4203 tele
.position_y
= player
->GetPositionY();
4204 tele
.position_z
= player
->GetPositionZ();
4205 tele
.orientation
= player
->GetOrientation();
4206 tele
.mapId
= player
->GetMapId();
4209 if(sObjectMgr
.AddGameTele(tele
))
4211 SendSysMessage(LANG_COMMAND_TP_ADDED
);
4215 SendSysMessage(LANG_COMMAND_TP_ADDEDERR
);
4216 SetSentErrorMessage(true);
4223 bool ChatHandler::HandleTeleDelCommand(const char * args
)
4228 std::string name
= args
;
4230 if(!sObjectMgr
.DeleteGameTele(name
))
4232 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
4233 SetSentErrorMessage(true);
4237 SendSysMessage(LANG_COMMAND_TP_DELETED
);
4241 bool ChatHandler::HandleListAurasCommand (const char * /*args*/)
4243 Unit
*unit
= getSelectedUnit();
4246 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4247 SetSentErrorMessage(true);
4251 char const* talentStr
= GetMangosString(LANG_TALENT
);
4252 char const* passiveStr
= GetMangosString(LANG_PASSIVE
);
4254 Unit::AuraMap
const& uAuras
= unit
->GetAuras();
4255 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS
, uAuras
.size());
4256 for (Unit::AuraMap::const_iterator itr
= uAuras
.begin(); itr
!= uAuras
.end(); ++itr
)
4258 bool talent
= GetTalentSpellCost(itr
->second
->GetId()) > 0;
4260 char const* name
= itr
->second
->GetSpellProto()->SpellName
[GetSessionDbcLocale()];
4264 std::ostringstream ss_name
;
4265 ss_name
<< "|cffffffff|Hspell:" << itr
->second
->GetId() << "|h[" << name
<< "]|h|r";
4267 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL
, itr
->second
->GetId(), itr
->second
->GetEffIndex(),
4268 itr
->second
->GetModifier()->m_auraname
, itr
->second
->GetAuraDuration(), itr
->second
->GetAuraMaxDuration(),
4269 ss_name
.str().c_str(),
4270 (itr
->second
->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4271 IS_PLAYER_GUID(itr
->second
->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr
->second
->GetCasterGUID()));
4275 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL
, itr
->second
->GetId(), itr
->second
->GetEffIndex(),
4276 itr
->second
->GetModifier()->m_auraname
, itr
->second
->GetAuraDuration(), itr
->second
->GetAuraMaxDuration(),
4278 (itr
->second
->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4279 IS_PLAYER_GUID(itr
->second
->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr
->second
->GetCasterGUID()));
4282 for (int i
= 0; i
< TOTAL_AURAS
; ++i
)
4284 Unit::AuraList
const& uAuraList
= unit
->GetAurasByType(AuraType(i
));
4285 if (uAuraList
.empty()) continue;
4286 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE
, uAuraList
.size(), i
);
4287 for (Unit::AuraList::const_iterator itr
= uAuraList
.begin(); itr
!= uAuraList
.end(); ++itr
)
4289 bool talent
= GetTalentSpellCost((*itr
)->GetId()) > 0;
4291 char const* name
= (*itr
)->GetSpellProto()->SpellName
[GetSessionDbcLocale()];
4295 std::ostringstream ss_name
;
4296 ss_name
<< "|cffffffff|Hspell:" << (*itr
)->GetId() << "|h[" << name
<< "]|h|r";
4298 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE
, (*itr
)->GetId(), (*itr
)->GetEffIndex(),
4299 ss_name
.str().c_str(),((*itr
)->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4300 IS_PLAYER_GUID((*itr
)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr
)->GetCasterGUID()));
4304 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE
, (*itr
)->GetId(), (*itr
)->GetEffIndex(),
4305 name
,((*itr
)->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4306 IS_PLAYER_GUID((*itr
)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr
)->GetCasterGUID()));
4313 bool ChatHandler::HandleListTalentsCommand (const char * /*args*/)
4315 Player
*player
= getSelectedPlayer();
4318 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4319 SetSentErrorMessage(true);
4323 SendSysMessage(LANG_LIST_TALENTS_TITLE
);
4326 PlayerSpellMap
const& uSpells
= player
->GetSpellMap();
4327 for (PlayerSpellMap::const_iterator itr
= uSpells
.begin(); itr
!= uSpells
.end(); ++itr
)
4329 if (itr
->second
.state
== PLAYERSPELL_REMOVED
|| itr
->second
.disabled
)
4332 uint32 cost_itr
= GetTalentSpellCost(itr
->first
);
4337 SpellEntry
const* spellEntry
= sSpellStore
.LookupEntry(itr
->first
);
4341 ShowSpellListHelper(player
, spellEntry
, GetSessionDbcLocale());
4345 PSendSysMessage(LANG_LIST_TALENTS_COUNT
, count
, cost
);
4350 bool ChatHandler::HandleResetAchievementsCommand (const char * args
)
4354 if (!extractPlayerTarget((char*)args
,&target
,&target_guid
))
4358 target
->GetAchievementMgr().Reset();
4360 AchievementMgr::DeleteFromDB(GUID_LOPART(target_guid
));
4365 bool ChatHandler::HandleResetHonorCommand (const char * args
)
4368 if (!extractPlayerTarget((char*)args
,&target
))
4371 target
->SetUInt32Value(PLAYER_FIELD_KILLS
, 0);
4372 target
->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS
, 0);
4373 target
->SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY
, 0);
4374 target
->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION
, 0);
4375 target
->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION
, 0);
4376 target
->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_EARN_HONORABLE_KILL
);
4381 static bool HandleResetStatsOrLevelHelper(Player
* player
)
4383 ChrClassesEntry
const* cEntry
= sChrClassesStore
.LookupEntry(player
->getClass());
4386 sLog
.outError("Class %u not found in DBC (Wrong DBC files?)",player
->getClass());
4390 uint8 powertype
= cEntry
->powerType
;
4392 // reset m_form if no aura
4393 if(!player
->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT
))
4394 player
->m_form
= FORM_NONE
;
4396 player
->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS
, DEFAULT_WORLD_OBJECT_SIZE
);
4397 player
->SetFloatValue(UNIT_FIELD_COMBATREACH
, 1.5f
);
4399 player
->setFactionForRace(player
->getRace());
4401 player
->SetUInt32Value(UNIT_FIELD_BYTES_0
, ( ( player
->getRace() ) | ( player
->getClass() << 8 ) | ( player
->getGender() << 16 ) | ( powertype
<< 24 ) ) );
4403 // reset only if player not in some form;
4404 if(player
->m_form
==FORM_NONE
)
4405 player
->InitDisplayIds();
4407 player
->SetByteValue(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_PVP
);
4408 player
->SetByteValue(UNIT_FIELD_BYTES_2
, 3, player
->m_form
);
4410 player
->SetUInt32Value(UNIT_FIELD_FLAGS
, UNIT_FLAG_PVP_ATTACKABLE
);
4412 //-1 is default value
4413 player
->SetInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX
, -1);
4415 //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000 );
4419 bool ChatHandler::HandleResetLevelCommand(const char * args
)
4422 if(!extractPlayerTarget((char*)args
,&target
))
4425 if(!HandleResetStatsOrLevelHelper(target
))
4428 // set starting level
4429 uint32 start_level
= target
->getClass() != CLASS_DEATH_KNIGHT
4430 ? sWorld
.getConfig(CONFIG_UINT32_START_PLAYER_LEVEL
)
4431 : sWorld
.getConfig(CONFIG_UINT32_START_HEROIC_PLAYER_LEVEL
);
4433 target
->_ApplyAllLevelScaleItemMods(false);
4435 target
->SetLevel(start_level
);
4436 target
->InitRunes();
4437 target
->InitStatsForLevel(true);
4438 target
->InitTaxiNodesForLevel();
4439 target
->InitGlyphsForLevel();
4440 target
->InitTalentForLevel();
4441 target
->SetUInt32Value(PLAYER_XP
,0);
4443 target
->_ApplyAllLevelScaleItemMods(true);
4445 // reset level for pet
4446 if(Pet
* pet
= target
->GetPet())
4447 pet
->SynchronizeLevelWithOwner();
4452 bool ChatHandler::HandleResetStatsCommand(const char * args
)
4455 if (!extractPlayerTarget((char*)args
,&target
))
4458 if (!HandleResetStatsOrLevelHelper(target
))
4461 target
->InitRunes();
4462 target
->InitStatsForLevel(true);
4463 target
->InitTaxiNodesForLevel();
4464 target
->InitGlyphsForLevel();
4465 target
->InitTalentForLevel();
4470 bool ChatHandler::HandleResetSpellsCommand(const char * args
)
4474 std::string target_name
;
4475 if(!extractPlayerTarget((char*)args
, &target
, &target_guid
, &target_name
))
4480 target
->resetSpells();
4482 ChatHandler(target
).SendSysMessage(LANG_RESET_SPELLS
);
4483 if(!m_session
|| m_session
->GetPlayer()!=target
)
4484 PSendSysMessage(LANG_RESET_SPELLS_ONLINE
,GetNameLink(target
).c_str());
4488 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS
), GUID_LOPART(target_guid
));
4489 PSendSysMessage(LANG_RESET_SPELLS_OFFLINE
,target_name
.c_str());
4495 bool ChatHandler::HandleResetSpecsCommand(const char * args
)
4499 std::string target_name
;
4500 if (!extractPlayerTarget((char*)args
, &target
, &target_guid
, &target_name
))
4505 target
->resetTalents(true,true);
4506 target
->SendTalentsInfoData(false);
4507 ChatHandler(target
).SendSysMessage(LANG_RESET_TALENTS
);
4508 if (!m_session
|| m_session
->GetPlayer() != target
)
4509 PSendSysMessage(LANG_RESET_TALENTS_ONLINE
,GetNameLink(target
).c_str());
4511 Pet
* pet
= target
->GetPet();
4512 Pet::resetTalentsForAllPetsOf(target
, pet
);
4514 target
->SendTalentsInfoData(true);
4517 else if (target_guid
)
4519 uint32 at_flags
= AT_LOGIN_RESET_TALENTS
| AT_LOGIN_RESET_PET_TALENTS
;
4520 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'", at_flags
, GUID_LOPART(target_guid
) );
4521 std::string nameLink
= playerLink(target_name
);
4522 PSendSysMessage(LANG_RESET_TALENTS_OFFLINE
, nameLink
.c_str());
4526 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4527 SetSentErrorMessage(true);
4531 bool ChatHandler::HandleResetTalentsCommand(const char * args
)
4534 std::string target_name
;
4535 if (!extractPlayerTarget((char*)args
, &target
, NULL
, &target_name
))
4537 // Try reset talents as Hunter Pet
4538 Creature
* creature
= getSelectedCreature();
4539 if (!*args
&& creature
&& creature
->isPet())
4541 Unit
*owner
= creature
->GetOwner();
4542 if(owner
&& owner
->GetTypeId() == TYPEID_PLAYER
&& ((Pet
*)creature
)->IsPermanentPetFor((Player
*)owner
))
4544 ((Pet
*)creature
)->resetTalents(true);
4545 ((Player
*)owner
)->SendTalentsInfoData(true);
4547 ChatHandler((Player
*)owner
).SendSysMessage(LANG_RESET_PET_TALENTS
);
4548 if(!m_session
|| m_session
->GetPlayer() != ((Player
*)owner
))
4549 PSendSysMessage(LANG_RESET_PET_TALENTS_ONLINE
,GetNameLink((Player
*)owner
).c_str());
4554 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4555 SetSentErrorMessage(true);
4561 target
->resetTalents(true);
4562 target
->SendTalentsInfoData(false);
4563 ChatHandler(target
).SendSysMessage(LANG_RESET_TALENTS
);
4564 if (!m_session
|| m_session
->GetPlayer() != target
)
4565 PSendSysMessage(LANG_RESET_TALENTS_ONLINE
,GetNameLink(target
).c_str());
4567 Pet
* pet
= target
->GetPet();
4568 Pet::resetTalentsForAllPetsOf(target
, pet
);
4570 target
->SendTalentsInfoData(true);
4574 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4575 SetSentErrorMessage(true);
4579 bool ChatHandler::HandleResetAllCommand(const char * args
)
4584 std::string casename
= args
;
4586 AtLoginFlags atLogin
;
4588 // Command specially created as single command to prevent using short case names
4589 if(casename
=="spells")
4591 atLogin
= AT_LOGIN_RESET_SPELLS
;
4592 sWorld
.SendWorldText(LANG_RESETALL_SPELLS
);
4594 SendSysMessage(LANG_RESETALL_SPELLS
);
4596 else if(casename
=="talents")
4598 atLogin
= AtLoginFlags(AT_LOGIN_RESET_TALENTS
| AT_LOGIN_RESET_PET_TALENTS
);
4599 sWorld
.SendWorldText(LANG_RESETALL_TALENTS
);
4601 SendSysMessage(LANG_RESETALL_TALENTS
);
4605 PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE
,args
);
4606 SetSentErrorMessage(true);
4610 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE (at_login & '%u') = '0'",atLogin
,atLogin
);
4611 HashMapHolder
<Player
>::MapType
const& plist
= sObjectAccessor
.GetPlayers();
4612 for(HashMapHolder
<Player
>::MapType::const_iterator itr
= plist
.begin(); itr
!= plist
.end(); ++itr
)
4613 itr
->second
->SetAtLoginFlag(atLogin
);
4618 bool ChatHandler::HandleServerShutDownCancelCommand(const char* /*args*/)
4620 sWorld
.ShutdownCancel();
4624 bool ChatHandler::HandleServerShutDownCommand(const char* args
)
4629 char* time_str
= strtok ((char*) args
, " ");
4630 char* exitcode_str
= strtok (NULL
, "");
4632 int32 time
= atoi (time_str
);
4634 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4635 if ((time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0')) || time
< 0)
4640 int32 exitcode
= atoi (exitcode_str
);
4642 // Handle atoi() errors
4643 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4646 // Exit code should be in range of 0-125, 126-255 is used
4647 // in many shells for their own return codes and code > 255
4648 // is not supported in many others
4649 if (exitcode
< 0 || exitcode
> 125)
4652 sWorld
.ShutdownServ (time
, 0, exitcode
);
4655 sWorld
.ShutdownServ(time
,0,SHUTDOWN_EXIT_CODE
);
4659 bool ChatHandler::HandleServerRestartCommand(const char* args
)
4664 char* time_str
= strtok ((char*) args
, " ");
4665 char* exitcode_str
= strtok (NULL
, "");
4667 int32 time
= atoi (time_str
);
4669 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4670 if ((time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0')) || time
< 0)
4675 int32 exitcode
= atoi (exitcode_str
);
4677 // Handle atoi() errors
4678 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4681 // Exit code should be in range of 0-125, 126-255 is used
4682 // in many shells for their own return codes and code > 255
4683 // is not supported in many others
4684 if (exitcode
< 0 || exitcode
> 125)
4687 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_RESTART
, exitcode
);
4690 sWorld
.ShutdownServ(time
, SHUTDOWN_MASK_RESTART
, RESTART_EXIT_CODE
);
4694 bool ChatHandler::HandleServerIdleRestartCommand(const char* args
)
4699 char* time_str
= strtok ((char*) args
, " ");
4700 char* exitcode_str
= strtok (NULL
, "");
4702 int32 time
= atoi (time_str
);
4704 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4705 if ((time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0')) || time
< 0)
4710 int32 exitcode
= atoi (exitcode_str
);
4712 // Handle atoi() errors
4713 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4716 // Exit code should be in range of 0-125, 126-255 is used
4717 // in many shells for their own return codes and code > 255
4718 // is not supported in many others
4719 if (exitcode
< 0 || exitcode
> 125)
4722 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_RESTART
|SHUTDOWN_MASK_IDLE
, exitcode
);
4725 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_RESTART
|SHUTDOWN_MASK_IDLE
,RESTART_EXIT_CODE
);
4729 bool ChatHandler::HandleServerIdleShutDownCommand(const char* args
)
4734 char* time_str
= strtok ((char*) args
, " ");
4735 char* exitcode_str
= strtok (NULL
, "");
4737 int32 time
= atoi (time_str
);
4739 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4740 if ((time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0')) || time
< 0)
4745 int32 exitcode
= atoi (exitcode_str
);
4747 // Handle atoi() errors
4748 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4751 // Exit code should be in range of 0-125, 126-255 is used
4752 // in many shells for their own return codes and code > 255
4753 // is not supported in many others
4754 if (exitcode
< 0 || exitcode
> 125)
4757 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_IDLE
, exitcode
);
4760 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_IDLE
,SHUTDOWN_EXIT_CODE
);
4764 bool ChatHandler::HandleQuestAdd(const char* args
)
4766 Player
* player
= getSelectedPlayer();
4769 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4770 SetSentErrorMessage(true);
4774 // .addquest #entry'
4775 // number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
4776 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4780 uint32 entry
= atol(cId
);
4782 Quest
const* pQuest
= sObjectMgr
.GetQuestTemplate(entry
);
4786 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
,entry
);
4787 SetSentErrorMessage(true);
4791 // check item starting quest (it can work incorrectly if added without item in inventory)
4792 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
4794 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
4798 if (pProto
->StartQuest
== entry
)
4800 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM
, entry
, pProto
->ItemId
);
4801 SetSentErrorMessage(true);
4806 // ok, normal (creature/GO starting) quest
4807 if( player
->CanAddQuest( pQuest
, true ) )
4809 player
->AddQuest( pQuest
, NULL
);
4811 if ( player
->CanCompleteQuest( entry
) )
4812 player
->CompleteQuest( entry
);
4818 bool ChatHandler::HandleQuestRemove(const char* args
)
4820 Player
* player
= getSelectedPlayer();
4823 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4824 SetSentErrorMessage(true);
4828 // .removequest #entry'
4829 // number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
4830 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4834 uint32 entry
= atol(cId
);
4836 Quest
const* pQuest
= sObjectMgr
.GetQuestTemplate(entry
);
4840 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
4841 SetSentErrorMessage(true);
4845 // remove all quest entries for 'entry' from quest log
4846 for(uint8 slot
= 0; slot
< MAX_QUEST_LOG_SIZE
; ++slot
)
4848 uint32 quest
= player
->GetQuestSlotQuestId(slot
);
4851 player
->SetQuestSlot(slot
,0);
4853 // we ignore unequippable quest items in this case, its' still be equipped
4854 player
->TakeQuestSourceItem( quest
, false );
4858 // set quest status to not started (will updated in DB at next save)
4859 player
->SetQuestStatus( entry
, QUEST_STATUS_NONE
);
4861 // reset rewarded for restart repeatable quest
4862 player
->getQuestStatusMap()[entry
].m_rewarded
= false;
4864 SendSysMessage(LANG_COMMAND_QUEST_REMOVED
);
4868 bool ChatHandler::HandleQuestComplete(const char* args
)
4870 Player
* player
= getSelectedPlayer();
4873 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4874 SetSentErrorMessage(true);
4878 // .quest complete #entry
4879 // number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
4880 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4884 uint32 entry
= atol(cId
);
4886 Quest
const* pQuest
= sObjectMgr
.GetQuestTemplate(entry
);
4888 // If player doesn't have the quest
4889 if(!pQuest
|| player
->GetQuestStatus(entry
) == QUEST_STATUS_NONE
)
4891 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
4892 SetSentErrorMessage(true);
4896 // Add quest items for quests that require items
4897 for(uint8 x
= 0; x
< QUEST_ITEM_OBJECTIVES_COUNT
; ++x
)
4899 uint32 id
= pQuest
->ReqItemId
[x
];
4900 uint32 count
= pQuest
->ReqItemCount
[x
];
4904 uint32 curItemCount
= player
->GetItemCount(id
,true);
4906 ItemPosCountVec dest
;
4907 uint8 msg
= player
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, id
, count
- curItemCount
);
4908 if( msg
== EQUIP_ERR_OK
)
4910 Item
* item
= player
->StoreNewItem( dest
, id
, true);
4911 player
->SendNewItem(item
,count
-curItemCount
, true, false);
4915 // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
4916 for(uint8 i
= 0; i
< QUEST_OBJECTIVES_COUNT
; ++i
)
4918 int32 creature
= pQuest
->ReqCreatureOrGOId
[i
];
4919 uint32 creaturecount
= pQuest
->ReqCreatureOrGOCount
[i
];
4921 if(uint32 spell_id
= pQuest
->ReqSpell
[i
])
4923 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4924 player
->CastedCreatureOrGO(creature
, ObjectGuid(), spell_id
);
4926 else if(creature
> 0)
4928 if(CreatureInfo
const* cInfo
= ObjectMgr::GetCreatureTemplate(creature
))
4929 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4930 player
->KilledMonster(cInfo
, ObjectGuid());
4932 else if(creature
< 0)
4934 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4935 player
->CastedCreatureOrGO(-creature
, ObjectGuid(), 0);
4939 // If the quest requires reputation to complete
4940 if(uint32 repFaction
= pQuest
->GetRepObjectiveFaction())
4942 uint32 repValue
= pQuest
->GetRepObjectiveValue();
4943 uint32 curRep
= player
->GetReputationMgr().GetReputation(repFaction
);
4944 if(curRep
< repValue
)
4945 if(FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry(repFaction
))
4946 player
->GetReputationMgr().SetReputation(factionEntry
,repValue
);
4949 // If the quest requires money
4950 int32 ReqOrRewMoney
= pQuest
->GetRewOrReqMoney();
4951 if(ReqOrRewMoney
< 0)
4952 player
->ModifyMoney(-ReqOrRewMoney
);
4954 player
->CompleteQuest(entry
);
4958 bool ChatHandler::HandleBanAccountCommand(const char* args
)
4960 return HandleBanHelper(BAN_ACCOUNT
,args
);
4963 bool ChatHandler::HandleBanCharacterCommand(const char* args
)
4965 return HandleBanHelper(BAN_CHARACTER
,args
);
4968 bool ChatHandler::HandleBanIPCommand(const char* args
)
4970 return HandleBanHelper(BAN_IP
,args
);
4973 bool ChatHandler::HandleBanHelper(BanMode mode
, const char* args
)
4978 char* cnameOrIP
= strtok ((char*)args
, " ");
4982 std::string nameOrIP
= cnameOrIP
;
4984 char* duration
= strtok (NULL
," ");
4985 if(!duration
|| !atoi(duration
))
4988 char* reason
= strtok (NULL
,"");
4995 if (!AccountMgr::normalizeString(nameOrIP
))
4997 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
4998 SetSentErrorMessage(true);
5003 if(!normalizePlayerName(nameOrIP
))
5005 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5006 SetSentErrorMessage(true);
5011 if(!IsIPAddress(nameOrIP
.c_str()))
5016 switch(sWorld
.BanAccount(mode
, nameOrIP
, duration
, reason
,m_session
? m_session
->GetPlayerName() : ""))
5019 if(atoi(duration
)>0)
5020 PSendSysMessage(LANG_BAN_YOUBANNED
,nameOrIP
.c_str(),secsToTimeString(TimeStringToSecs(duration
),true).c_str(),reason
);
5022 PSendSysMessage(LANG_BAN_YOUPERMBANNED
,nameOrIP
.c_str(),reason
);
5024 case BAN_SYNTAX_ERROR
:
5030 PSendSysMessage(LANG_BAN_NOTFOUND
,"account",nameOrIP
.c_str());
5033 PSendSysMessage(LANG_BAN_NOTFOUND
,"character",nameOrIP
.c_str());
5036 PSendSysMessage(LANG_BAN_NOTFOUND
,"ip",nameOrIP
.c_str());
5039 SetSentErrorMessage(true);
5046 bool ChatHandler::HandleUnBanAccountCommand(const char* args
)
5048 return HandleUnBanHelper(BAN_ACCOUNT
,args
);
5051 bool ChatHandler::HandleUnBanCharacterCommand(const char* args
)
5053 return HandleUnBanHelper(BAN_CHARACTER
,args
);
5056 bool ChatHandler::HandleUnBanIPCommand(const char* args
)
5058 return HandleUnBanHelper(BAN_IP
,args
);
5061 bool ChatHandler::HandleUnBanHelper(BanMode mode
, const char* args
)
5066 char* cnameOrIP
= strtok ((char*)args
, " ");
5070 std::string nameOrIP
= cnameOrIP
;
5075 if (!AccountMgr::normalizeString(nameOrIP
))
5077 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
5078 SetSentErrorMessage(true);
5083 if(!normalizePlayerName(nameOrIP
))
5085 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5086 SetSentErrorMessage(true);
5091 if(!IsIPAddress(nameOrIP
.c_str()))
5096 if(sWorld
.RemoveBanAccount(mode
,nameOrIP
))
5097 PSendSysMessage(LANG_UNBAN_UNBANNED
,nameOrIP
.c_str());
5099 PSendSysMessage(LANG_UNBAN_ERROR
,nameOrIP
.c_str());
5104 bool ChatHandler::HandleBanInfoAccountCommand(const char* args
)
5109 std::string account_name
;
5110 uint32 accountid
= extractAccountId((char*)args
, &account_name
);
5114 return HandleBanInfoHelper(accountid
,account_name
.c_str());
5117 bool ChatHandler::HandleBanInfoCharacterCommand(const char* args
)
5121 if (!extractPlayerTarget((char*)args
,&target
,&target_guid
))
5124 uint32 accountid
= target
? target
->GetSession()->GetAccountId() : sObjectMgr
.GetPlayerAccountIdByGUID(target_guid
);
5126 std::string accountname
;
5127 if (!sAccountMgr
.GetName(accountid
,accountname
))
5129 PSendSysMessage(LANG_BANINFO_NOCHARACTER
);
5133 return HandleBanInfoHelper(accountid
,accountname
.c_str());
5136 bool ChatHandler::HandleBanInfoHelper(uint32 accountid
, char const* accountname
)
5138 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
);
5141 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN
, accountname
);
5145 PSendSysMessage(LANG_BANINFO_BANHISTORY
,accountname
);
5148 Field
* fields
= result
->Fetch();
5150 time_t unbandate
= time_t(fields
[3].GetUInt64());
5151 bool active
= false;
5152 if(fields
[2].GetBool() && (fields
[1].GetUInt64() == (uint64
)0 ||unbandate
>= time(NULL
)) )
5154 bool permanent
= (fields
[1].GetUInt64() == (uint64
)0);
5155 std::string bantime
= permanent
?GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[1].GetUInt64(), true);
5156 PSendSysMessage(LANG_BANINFO_HISTORYENTRY
,
5157 fields
[0].GetString(), bantime
.c_str(), active
? GetMangosString(LANG_BANINFO_YES
):GetMangosString(LANG_BANINFO_NO
), fields
[4].GetString(), fields
[5].GetString());
5158 }while (result
->NextRow());
5164 bool ChatHandler::HandleBanInfoIPCommand(const char* args
)
5169 char* cIP
= strtok ((char*)args
, "");
5173 if (!IsIPAddress(cIP
))
5176 std::string IP
= cIP
;
5178 loginDatabase
.escape_string(IP
);
5179 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());
5182 PSendSysMessage(LANG_BANINFO_NOIP
);
5186 Field
*fields
= result
->Fetch();
5187 bool permanent
= !fields
[6].GetUInt64();
5188 PSendSysMessage(LANG_BANINFO_IPENTRY
,
5189 fields
[0].GetString(), fields
[1].GetString(), permanent
? GetMangosString(LANG_BANINFO_NEVER
):fields
[2].GetString(),
5190 permanent
? GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[3].GetUInt64(), true).c_str(), fields
[4].GetString(), fields
[5].GetString());
5195 bool ChatHandler::HandleBanListCharacterCommand(const char* args
)
5197 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5199 char* cFilter
= strtok ((char*)args
, " ");
5203 std::string filter
= cFilter
;
5204 loginDatabase
.escape_string(filter
);
5205 QueryResult
* result
= CharacterDatabase
.PQuery("SELECT account FROM characters WHERE name "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'"),filter
.c_str());
5208 PSendSysMessage(LANG_BANLIST_NOCHARACTER
);
5212 return HandleBanListHelper(result
);
5215 bool ChatHandler::HandleBanListAccountCommand(const char* args
)
5217 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5219 char* cFilter
= strtok((char*)args
, " ");
5220 std::string filter
= cFilter
? cFilter
: "";
5221 loginDatabase
.escape_string(filter
);
5223 QueryResult
* result
;
5227 result
= loginDatabase
.Query("SELECT account.id, username FROM account, account_banned"
5228 " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
5232 result
= loginDatabase
.PQuery("SELECT account.id, username FROM account, account_banned"
5233 " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
5239 PSendSysMessage(LANG_BANLIST_NOACCOUNT
);
5243 return HandleBanListHelper(result
);
5246 bool ChatHandler::HandleBanListHelper(QueryResult
* result
)
5248 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT
);
5250 // Chat short output
5255 Field
* fields
= result
->Fetch();
5256 uint32 accountid
= fields
[0].GetUInt32();
5258 QueryResult
* banresult
= loginDatabase
.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid
);
5261 Field
* fields2
= banresult
->Fetch();
5262 PSendSysMessage("%s",fields2
[0].GetString());
5265 } while (result
->NextRow());
5267 // Console wide output
5270 SendSysMessage(LANG_BANLIST_ACCOUNTS
);
5271 SendSysMessage("===============================================================================");
5272 SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER
);
5275 SendSysMessage("-------------------------------------------------------------------------------");
5276 Field
*fields
= result
->Fetch();
5277 uint32 account_id
= fields
[0].GetUInt32 ();
5279 std::string account_name
;
5281 // "account" case, name can be get in same query
5282 if(result
->GetFieldCount() > 1)
5283 account_name
= fields
[1].GetCppString();
5284 // "character" case, name need extract from another DB
5286 sAccountMgr
.GetName (account_id
,account_name
);
5288 // No SQL injection. id is uint32.
5289 QueryResult
*banInfo
= loginDatabase
.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id
);
5292 Field
*fields2
= banInfo
->Fetch();
5295 time_t t_ban
= fields2
[0].GetUInt64();
5296 tm
* aTm_ban
= localtime(&t_ban
);
5298 if (fields2
[0].GetUInt64() == fields2
[1].GetUInt64())
5300 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5301 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
,
5302 fields2
[2].GetString(),fields2
[3].GetString());
5306 time_t t_unban
= fields2
[1].GetUInt64();
5307 tm
* aTm_unban
= localtime(&t_unban
);
5308 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5309 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
,
5310 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5311 fields2
[2].GetString(),fields2
[3].GetString());
5313 }while ( banInfo
->NextRow() );
5316 }while( result
->NextRow() );
5317 SendSysMessage("===============================================================================");
5324 bool ChatHandler::HandleBanListIPCommand(const char* args
)
5326 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5328 char* cFilter
= strtok((char*)args
, " ");
5329 std::string filter
= cFilter
? cFilter
: "";
5330 loginDatabase
.escape_string(filter
);
5332 QueryResult
* result
;
5336 result
= loginDatabase
.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5337 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
5338 " ORDER BY unbandate" );
5342 result
= loginDatabase
.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5343 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")
5344 " ORDER BY unbandate",filter
.c_str() );
5349 PSendSysMessage(LANG_BANLIST_NOIP
);
5353 PSendSysMessage(LANG_BANLIST_MATCHINGIP
);
5354 // Chat short output
5359 Field
* fields
= result
->Fetch();
5360 PSendSysMessage("%s",fields
[0].GetString());
5361 } while (result
->NextRow());
5363 // Console wide output
5366 SendSysMessage(LANG_BANLIST_IPS
);
5367 SendSysMessage("===============================================================================");
5368 SendSysMessage(LANG_BANLIST_IPS_HEADER
);
5371 SendSysMessage("-------------------------------------------------------------------------------");
5372 Field
*fields
= result
->Fetch();
5373 time_t t_ban
= fields
[1].GetUInt64();
5374 tm
* aTm_ban
= localtime(&t_ban
);
5375 if ( fields
[1].GetUInt64() == fields
[2].GetUInt64() )
5377 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5378 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
,
5379 fields
[3].GetString(), fields
[4].GetString());
5383 time_t t_unban
= fields
[2].GetUInt64();
5384 tm
* aTm_unban
= localtime(&t_unban
);
5385 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5386 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
,
5387 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5388 fields
[3].GetString(), fields
[4].GetString());
5390 }while( result
->NextRow() );
5391 SendSysMessage("===============================================================================");
5398 bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
5400 Player
* pl
= m_session
->GetPlayer();
5402 // accept only explicitly selected target (not implicitly self targeting case)
5403 Unit
* target
= getSelectedUnit();
5404 if(pl
->GetSelection() && target
)
5406 if(target
->GetTypeId()!=TYPEID_UNIT
)
5408 SendSysMessage(LANG_SELECT_CREATURE
);
5409 SetSentErrorMessage(true);
5413 if(target
->isDead())
5414 ((Creature
*)target
)->Respawn();
5418 MaNGOS::RespawnDo u_do
;
5419 MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
> worker(pl
,u_do
);
5420 Cell::VisitGridObjects(pl
, worker
, pl
->GetMap()->GetVisibilityDistance());
5424 bool ChatHandler::HandleGMFlyCommand(const char* args
)
5429 Player
*target
= getSelectedPlayer();
5431 target
= m_session
->GetPlayer();
5433 WorldPacket
data(12);
5434 if (strncmp(args
, "on", 3) == 0)
5435 data
.SetOpcode(SMSG_MOVE_SET_CAN_FLY
);
5436 else if (strncmp(args
, "off", 4) == 0)
5437 data
.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY
);
5440 SendSysMessage(LANG_USE_BOL
);
5443 data
<< target
->GetPackGUID();
5444 data
<< uint32(0); // unknown
5445 target
->SendMessageToSet(&data
, true);
5446 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS
, GetNameLink(target
).c_str(), args
);
5450 bool ChatHandler::HandlePDumpLoadCommand(const char *args
)
5455 char* file
= strtok((char*)args
, " ");
5459 char* account
= strtok(NULL
, " ");
5463 char* name_str
= strtok(NULL
, " ");
5465 std::string account_name
;
5466 uint32 account_id
= extractAccountId(account
, &account_name
);
5470 char* guid_str
= NULL
;
5476 // normalize the name if specified and check if it exists
5477 if (!normalizePlayerName(name
))
5479 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5480 SetSentErrorMessage(true);
5484 if (ObjectMgr::CheckPlayerName(name
,true) != CHAR_NAME_SUCCESS
)
5486 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5487 SetSentErrorMessage(true);
5491 guid_str
= strtok(NULL
, " ");
5498 guid
= atoi(guid_str
);
5501 PSendSysMessage(LANG_INVALID_CHARACTER_GUID
);
5502 SetSentErrorMessage(true);
5506 if (sObjectMgr
.GetPlayerAccountIdByGUID(guid
))
5508 PSendSysMessage(LANG_CHARACTER_GUID_IN_USE
,guid
);
5509 SetSentErrorMessage(true);
5514 switch(PlayerDumpReader().LoadDump(file
, account_id
, name
, guid
))
5517 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS
);
5519 case DUMP_FILE_OPEN_ERROR
:
5520 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
5521 SetSentErrorMessage(true);
5523 case DUMP_FILE_BROKEN
:
5524 PSendSysMessage(LANG_DUMP_BROKEN
,file
);
5525 SetSentErrorMessage(true);
5527 case DUMP_TOO_MANY_CHARS
:
5528 PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL
,account_name
.c_str(),account_id
);
5529 SetSentErrorMessage(true);
5532 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED
);
5533 SetSentErrorMessage(true);
5540 bool ChatHandler::HandlePDumpWriteCommand(const char *args
)
5545 char* file
= strtok((char*)args
, " ");
5546 char* p2
= strtok(NULL
, " ");
5552 // character name can't start from number
5557 std::string name
= extractPlayerNameFromLink(p2
);
5560 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5561 SetSentErrorMessage(true);
5565 guid
= GUID_LOPART(sObjectMgr
.GetPlayerGUIDByName(name
));
5568 if(!sObjectMgr
.GetPlayerAccountIdByGUID(guid
))
5570 PSendSysMessage(LANG_PLAYER_NOT_FOUND
);
5571 SetSentErrorMessage(true);
5575 switch(PlayerDumpWriter().WriteDump(file
, guid
))
5578 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS
);
5580 case DUMP_FILE_OPEN_ERROR
:
5581 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
5582 SetSentErrorMessage(true);
5585 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED
);
5586 SetSentErrorMessage(true);
5593 bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
5595 Unit
* unit
= getSelectedUnit();
5598 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5599 SetSentErrorMessage(true);
5603 PSendSysMessage(LANG_MOVEGENS_LIST
,(unit
->GetTypeId()==TYPEID_PLAYER
? "Player" : "Creature" ),unit
->GetGUIDLow());
5605 MotionMaster
* mm
= unit
->GetMotionMaster();
5606 for(MotionMaster::const_iterator itr
= mm
->begin(); itr
!= mm
->end(); ++itr
)
5608 switch((*itr
)->GetMovementGeneratorType())
5610 case IDLE_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_IDLE
); break;
5611 case RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_RANDOM
); break;
5612 case WAYPOINT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_WAYPOINT
); break;
5613 case CONFUSED_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_CONFUSED
); break;
5614 case CHASE_MOTION_TYPE
:
5616 Unit
* target
= NULL
;
5617 if(unit
->GetTypeId()==TYPEID_PLAYER
)
5618 target
= static_cast<ChaseMovementGenerator
<Player
> const*>(*itr
)->GetTarget();
5620 target
= static_cast<ChaseMovementGenerator
<Creature
> const*>(*itr
)->GetTarget();
5623 SendSysMessage(LANG_MOVEGENS_CHASE_NULL
);
5624 else if (target
->GetTypeId()==TYPEID_PLAYER
)
5625 PSendSysMessage(LANG_MOVEGENS_CHASE_PLAYER
,target
->GetName(),target
->GetGUIDLow());
5627 PSendSysMessage(LANG_MOVEGENS_CHASE_CREATURE
,target
->GetName(),target
->GetGUIDLow());
5630 case FOLLOW_MOTION_TYPE
:
5632 Unit
* target
= NULL
;
5633 if(unit
->GetTypeId()==TYPEID_PLAYER
)
5634 target
= static_cast<FollowMovementGenerator
<Player
> const*>(*itr
)->GetTarget();
5636 target
= static_cast<FollowMovementGenerator
<Creature
> const*>(*itr
)->GetTarget();
5639 SendSysMessage(LANG_MOVEGENS_FOLLOW_NULL
);
5640 else if (target
->GetTypeId()==TYPEID_PLAYER
)
5641 PSendSysMessage(LANG_MOVEGENS_FOLLOW_PLAYER
,target
->GetName(),target
->GetGUIDLow());
5643 PSendSysMessage(LANG_MOVEGENS_FOLLOW_CREATURE
,target
->GetName(),target
->GetGUIDLow());
5646 case HOME_MOTION_TYPE
:
5647 if(unit
->GetTypeId()==TYPEID_UNIT
)
5650 (*itr
)->GetDestination(x
,y
,z
);
5651 PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE
,x
,y
,z
);
5654 SendSysMessage(LANG_MOVEGENS_HOME_PLAYER
);
5656 case FLIGHT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FLIGHT
); break;
5657 case POINT_MOTION_TYPE
:
5660 (*itr
)->GetDestination(x
,y
,z
);
5661 PSendSysMessage(LANG_MOVEGENS_POINT
,x
,y
,z
);
5664 case FLEEING_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FEAR
); break;
5665 case DISTRACT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_DISTRACT
); break;
5667 PSendSysMessage(LANG_MOVEGENS_UNKNOWN
,(*itr
)->GetMovementGeneratorType());
5674 bool ChatHandler::HandleServerPLimitCommand(const char *args
)
5678 char* param
= strtok((char*)args
, " ");
5682 int l
= strlen(param
);
5684 if( strncmp(param
,"player",l
) == 0 )
5685 sWorld
.SetPlayerLimit(-SEC_PLAYER
);
5686 else if(strncmp(param
,"moderator",l
) == 0 )
5687 sWorld
.SetPlayerLimit(-SEC_MODERATOR
);
5688 else if(strncmp(param
,"gamemaster",l
) == 0 )
5689 sWorld
.SetPlayerLimit(-SEC_GAMEMASTER
);
5690 else if(strncmp(param
,"administrator",l
) == 0 )
5691 sWorld
.SetPlayerLimit(-SEC_ADMINISTRATOR
);
5692 else if(strncmp(param
,"reset",l
) == 0 )
5693 sWorld
.SetPlayerLimit( sConfig
.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT
) );
5696 int val
= atoi(param
);
5697 if(val
< -SEC_ADMINISTRATOR
) val
= -SEC_ADMINISTRATOR
;
5699 sWorld
.SetPlayerLimit(val
);
5702 // kick all low security level players
5703 if(sWorld
.GetPlayerAmountLimit() > SEC_PLAYER
)
5704 sWorld
.KickAllLess(sWorld
.GetPlayerSecurityLimit());
5707 uint32 pLimit
= sWorld
.GetPlayerAmountLimit();
5708 AccountTypes allowedAccountType
= sWorld
.GetPlayerSecurityLimit();
5709 char const* secName
= "";
5710 switch(allowedAccountType
)
5712 case SEC_PLAYER
: secName
= "Player"; break;
5713 case SEC_MODERATOR
: secName
= "Moderator"; break;
5714 case SEC_GAMEMASTER
: secName
= "Gamemaster"; break;
5715 case SEC_ADMINISTRATOR
: secName
= "Administrator"; break;
5716 default: secName
= "<unknown>"; break;
5719 PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit
,secName
);
5724 bool ChatHandler::HandleCastCommand(const char* args
)
5729 Unit
* target
= getSelectedUnit();
5733 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5734 SetSentErrorMessage(true);
5738 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5739 uint32 spell
= extractSpellIdFromLink((char*)args
);
5743 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5747 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5749 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5750 SetSentErrorMessage(true);
5754 char* trig_str
= strtok(NULL
, " ");
5757 int l
= strlen(trig_str
);
5758 if(strncmp(trig_str
,"triggered",l
) != 0 )
5762 bool triggered
= (trig_str
!= NULL
);
5764 m_session
->GetPlayer()->CastSpell(target
,spell
,triggered
);
5769 bool ChatHandler::HandleCastBackCommand(const char* args
)
5771 Creature
* caster
= getSelectedCreature();
5775 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5776 SetSentErrorMessage(true);
5780 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
5781 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5782 uint32 spell
= extractSpellIdFromLink((char*)args
);
5783 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
5786 char* trig_str
= strtok(NULL
, " ");
5789 int l
= strlen(trig_str
);
5790 if(strncmp(trig_str
,"triggered",l
) != 0 )
5794 bool triggered
= (trig_str
!= NULL
);
5796 caster
->SetFacingToObject(m_session
->GetPlayer());
5798 caster
->CastSpell(m_session
->GetPlayer(),spell
,triggered
);
5803 bool ChatHandler::HandleCastDistCommand(const char* args
)
5808 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5809 uint32 spell
= extractSpellIdFromLink((char*)args
);
5813 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5817 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5819 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5820 SetSentErrorMessage(true);
5824 char *distStr
= strtok(NULL
, " ");
5829 sscanf(distStr
, "%f", &dist
);
5831 char* trig_str
= strtok(NULL
, " ");
5834 int l
= strlen(trig_str
);
5835 if(strncmp(trig_str
,"triggered",l
) != 0 )
5839 bool triggered
= (trig_str
!= NULL
);
5842 m_session
->GetPlayer()->GetClosePoint(x
,y
,z
,dist
);
5844 m_session
->GetPlayer()->CastSpell(x
,y
,z
,spell
,triggered
);
5848 bool ChatHandler::HandleCastTargetCommand(const char* args
)
5850 Creature
* caster
= getSelectedCreature();
5854 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5855 SetSentErrorMessage(true);
5859 if(!caster
->getVictim())
5861 SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM
);
5862 SetSentErrorMessage(true);
5866 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5867 uint32 spell
= extractSpellIdFromLink((char*)args
);
5868 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
5871 char* trig_str
= strtok(NULL
, " ");
5874 int l
= strlen(trig_str
);
5875 if(strncmp(trig_str
,"triggered",l
) != 0 )
5879 bool triggered
= (trig_str
!= NULL
);
5881 caster
->SetFacingToObject(m_session
->GetPlayer());
5883 caster
->CastSpell(caster
->getVictim(),spell
,triggered
);
5889 ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
5890 Without this function 3rd party scripting library will get linking errors (unresolved external)
5891 when attempting to use the PointMovementGenerator
5893 bool ChatHandler::HandleComeToMeCommand(const char *args
)
5895 Creature
* caster
= getSelectedCreature();
5899 SendSysMessage(LANG_SELECT_CREATURE
);
5900 SetSentErrorMessage(true);
5904 char* newFlagStr
= strtok((char*)args
, " ");
5909 uint32 newFlags
= atoi(newFlagStr
);
5911 caster
->SetSplineFlags(SplineFlags(newFlags
));
5913 Player
* pl
= m_session
->GetPlayer();
5915 caster
->GetMotionMaster()->MovePoint(0, pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ());
5919 bool ChatHandler::HandleCastSelfCommand(const char* args
)
5924 Unit
* target
= getSelectedUnit();
5928 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5929 SetSentErrorMessage(true);
5933 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5934 uint32 spell
= extractSpellIdFromLink((char*)args
);
5938 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5942 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5944 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5945 SetSentErrorMessage(true);
5949 target
->CastSpell(target
,spell
,false);
5954 std::string
GetTimeString(time_t time
)
5956 time_t days
= time
/ DAY
;
5957 time_t hours
= (time
% DAY
) / HOUR
;
5958 time_t minute
= (time
% HOUR
) / MINUTE
;
5959 std::ostringstream ss
;
5963 ss
<< hours
<< "h ";
5964 ss
<< minute
<< "m";
5968 bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
5970 Player
* player
= getSelectedPlayer();
5971 if (!player
) player
= m_session
->GetPlayer();
5973 for(uint8 i
= 0; i
< MAX_DIFFICULTY
; ++i
)
5975 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(Difficulty(i
));
5976 for(Player::BoundInstancesMap::const_iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
5978 InstanceSave
*save
= itr
->second
.save
;
5979 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
5980 if (const MapEntry
* entry
= sMapStore
.LookupEntry(itr
->first
))
5982 PSendSysMessage("map: %d (%s) inst: %d perm: %s diff: %d canReset: %s TTR: %s",
5983 itr
->first
, entry
->name
[GetSessionDbcLocale()], save
->GetInstanceId(), itr
->second
.perm
? "yes" : "no",
5984 save
->GetDifficulty(), save
->CanReset() ? "yes" : "no", timeleft
.c_str());
5987 PSendSysMessage("bound for a nonexistant map %u", itr
->first
);
5991 PSendSysMessage("player binds: %d", counter
);
5993 Group
*group
= player
->GetGroup();
5996 for(uint8 i
= 0; i
< MAX_DIFFICULTY
; ++i
)
5998 Group::BoundInstancesMap
&binds
= group
->GetBoundInstances(Difficulty(i
));
5999 for(Group::BoundInstancesMap::const_iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
6001 InstanceSave
*save
= itr
->second
.save
;
6002 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
6003 if (const MapEntry
* entry
= sMapStore
.LookupEntry(itr
->first
))
6005 PSendSysMessage("map: %d (%s) inst: %d perm: %s diff: %d canReset: %s TTR: %s",
6006 itr
->first
, entry
->name
[GetSessionDbcLocale()], save
->GetInstanceId(), itr
->second
.perm
? "yes" : "no",
6007 save
->GetDifficulty(), save
->CanReset() ? "yes" : "no", timeleft
.c_str());
6010 PSendSysMessage("bound for a nonexistant map %u", itr
->first
);
6015 PSendSysMessage("group binds: %d", counter
);
6020 bool ChatHandler::HandleInstanceUnbindCommand(const char* args
)
6025 Player
* player
= getSelectedPlayer();
6027 player
= m_session
->GetPlayer();
6030 bool got_map
= false;
6032 if (strncmp(args
,"all",strlen(args
)) != 0)
6034 if(!isNumeric(args
[0]))
6041 for(uint8 i
= 0; i
< MAX_DIFFICULTY
; ++i
)
6043 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(Difficulty(i
));
6044 for(Player::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end();)
6046 if (got_map
&& mapid
!= itr
->first
)
6051 if(itr
->first
!= player
->GetMapId())
6053 InstanceSave
*save
= itr
->second
.save
;
6054 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
6056 if (const MapEntry
* entry
= sMapStore
.LookupEntry(itr
->first
))
6058 PSendSysMessage("unbinding map: %d (%s) inst: %d perm: %s diff: %d canReset: %s TTR: %s",
6059 itr
->first
, entry
->name
[GetSessionDbcLocale()], save
->GetInstanceId(), itr
->second
.perm
? "yes" : "no",
6060 save
->GetDifficulty(), save
->CanReset() ? "yes" : "no", timeleft
.c_str());
6063 PSendSysMessage("bound for a nonexistant map %u", itr
->first
);
6064 player
->UnbindInstance(itr
, Difficulty(i
));
6071 PSendSysMessage("instances unbound: %d", counter
);
6075 bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
6077 PSendSysMessage("instances loaded: %d", sMapMgr
.GetNumInstances());
6078 PSendSysMessage("players in instances: %d", sMapMgr
.GetNumPlayersInInstances());
6079 PSendSysMessage("instance saves: %d", sInstanceSaveMgr
.GetNumInstanceSaves());
6080 PSendSysMessage("players bound: %d", sInstanceSaveMgr
.GetNumBoundPlayersTotal());
6081 PSendSysMessage("groups bound: %d", sInstanceSaveMgr
.GetNumBoundGroupsTotal());
6085 bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
6087 Player
* pl
= m_session
->GetPlayer();
6089 Map
* map
= pl
->GetMap();
6090 if (!map
->IsDungeon())
6092 PSendSysMessage("Map is not a dungeon.");
6093 SetSentErrorMessage(true);
6097 if (!((InstanceMap
*)map
)->GetInstanceData())
6099 PSendSysMessage("Map has no instance data.");
6100 SetSentErrorMessage(true);
6104 ((InstanceMap
*)map
)->GetInstanceData()->SaveToDB();
6108 /// Display the list of GMs
6109 bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
6111 ///- Get the accounts with GM Level >0
6112 QueryResult
*result
= loginDatabase
.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
6115 SendSysMessage(LANG_GMLIST
);
6116 SendSysMessage("========================");
6117 SendSysMessage(LANG_GMLIST_HEADER
);
6118 SendSysMessage("========================");
6120 ///- Circle through them. Display username and GM level
6123 Field
*fields
= result
->Fetch();
6124 PSendSysMessage("|%15s|%6s|", fields
[0].GetString(),fields
[1].GetString());
6125 }while( result
->NextRow() );
6127 PSendSysMessage("========================");
6131 PSendSysMessage(LANG_GMLIST_EMPTY
);
6135 /// Define the 'Message of the day' for the realm
6136 bool ChatHandler::HandleServerSetMotdCommand(const char* args
)
6138 sWorld
.SetMotd(args
);
6139 PSendSysMessage(LANG_MOTD_NEW
, args
);
6143 bool ChatHandler::ShowPlayerListHelper(QueryResult
* result
, uint32
* limit
, bool title
, bool error
)
6149 PSendSysMessage(LANG_NO_PLAYERS_FOUND
);
6150 SetSentErrorMessage(true);
6155 if (!m_session
&& title
)
6157 SendSysMessage(LANG_CHARACTERS_LIST_BAR
);
6158 SendSysMessage(LANG_CHARACTERS_LIST_HEADER
);
6159 SendSysMessage(LANG_CHARACTERS_LIST_BAR
);
6164 ///- Circle through them. Display username and GM level
6175 Field
*fields
= result
->Fetch();
6176 uint32 guid
= fields
[0].GetUInt32();
6177 std::string name
= fields
[1].GetCppString();
6178 uint8 race
= fields
[2].GetUInt8();
6179 uint8 class_
= fields
[3].GetUInt8();
6180 uint32 level
= fields
[4].GetUInt32();
6182 ChrRacesEntry
const* raceEntry
= sChrRacesStore
.LookupEntry(race
);
6183 ChrClassesEntry
const* classEntry
= sChrClassesStore
.LookupEntry(class_
);
6185 char const* race_name
= raceEntry
? raceEntry
->name
[GetSessionDbcLocale()] : "<?>";
6186 char const* class_name
= classEntry
? classEntry
->name
[GetSessionDbcLocale()] : "<?>";
6189 PSendSysMessage(LANG_CHARACTERS_LIST_LINE_CONSOLE
, guid
, name
.c_str(), race_name
, class_name
, level
);
6191 PSendSysMessage(LANG_CHARACTERS_LIST_LINE_CHAT
, guid
, name
.c_str(), name
.c_str(), race_name
, class_name
, level
);
6193 }while( result
->NextRow() );
6199 SendSysMessage(LANG_CHARACTERS_LIST_BAR
);
6205 /// Output list of character for account
6206 bool ChatHandler::HandleAccountCharactersCommand(const char* args
)
6208 ///- Get the command line arguments
6209 std::string account_name
;
6210 Player
* target
= NULL
; // only for triggering use targeted player account
6211 uint32 account_id
= extractAccountId((char*)args
, &account_name
, &target
);
6215 ///- Get the characters for account id
6216 QueryResult
*result
= CharacterDatabase
.PQuery( "SELECT guid, name, race, class, level FROM characters WHERE account = %u", account_id
);
6218 return ShowPlayerListHelper(result
);
6221 /// Set/Unset the expansion level for an account
6222 bool ChatHandler::HandleAccountSetAddonCommand(const char* args
)
6224 ///- Get the command line arguments
6228 extractOptFirstArg((char*)args
, &arg1
, &arg2
);
6230 std::string account_name
;
6231 uint32 account_id
= extractAccountId(arg1
, &account_name
);
6235 // Let set addon state only for lesser (strong) security level
6236 // or to self account
6237 if (GetAccountId() && GetAccountId () != account_id
&&
6238 HasLowerSecurityAccount (NULL
,account_id
,true))
6241 int lev
=atoi(arg2
); //get int anyway (0 if error)
6246 loginDatabase
.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev
,account_id
);
6247 PSendSysMessage(LANG_ACCOUNT_SETADDON
,account_name
.c_str(),account_id
,lev
);
6251 //Send items by mail
6252 bool ChatHandler::HandleSendItemsCommand(const char* args
)
6254 // format: name "subject text" "mail text" item1[:count1] item2[:count2] ... item12[:count12]
6256 uint64 receiver_guid
;
6257 std::string receiver_name
;
6258 if(!extractPlayerTarget((char*)args
,&receiver
,&receiver_guid
,&receiver_name
))
6261 char* tail1
= strtok(NULL
, "");
6265 char* msgSubject
= extractQuotedArg(tail1
);
6269 char* tail2
= strtok(NULL
, "");
6273 char* msgText
= extractQuotedArg(tail2
);
6277 // msgSubject, msgText isn't NUL after prev. check
6278 std::string subject
= msgSubject
;
6279 std::string text
= msgText
;
6282 typedef std::pair
<uint32
,uint32
> ItemPair
;
6283 typedef std::list
< ItemPair
> ItemPairs
;
6286 // get all tail string
6287 char* tail
= strtok(NULL
, "");
6289 // get from tail next item str
6290 while(char* itemStr
= strtok(tail
, " "))
6293 tail
= strtok(NULL
, "");
6296 char* itemIdStr
= strtok(itemStr
, ":");
6297 char* itemCountStr
= strtok(NULL
, " ");
6299 uint32 item_id
= atoi(itemIdStr
);
6303 ItemPrototype
const* item_proto
= ObjectMgr::GetItemPrototype(item_id
);
6306 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
6307 SetSentErrorMessage(true);
6311 uint32 item_count
= itemCountStr
? atoi(itemCountStr
) : 1;
6312 if (item_count
< 1 || (item_proto
->MaxCount
> 0 && item_count
> uint32(item_proto
->MaxCount
)))
6314 PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT
, item_count
,item_id
);
6315 SetSentErrorMessage(true);
6319 while(item_count
> item_proto
->GetMaxStackSize())
6321 items
.push_back(ItemPair(item_id
,item_proto
->GetMaxStackSize()));
6322 item_count
-= item_proto
->GetMaxStackSize();
6325 items
.push_back(ItemPair(item_id
,item_count
));
6327 if(items
.size() > MAX_MAIL_ITEMS
)
6329 PSendSysMessage(LANG_COMMAND_MAIL_ITEMS_LIMIT
, MAX_MAIL_ITEMS
);
6330 SetSentErrorMessage(true);
6335 // from console show not existed sender
6336 MailSender
sender(MAIL_NORMAL
,m_session
? m_session
->GetPlayer()->GetGUIDLow() : 0, MAIL_STATIONERY_GM
);
6339 MailDraft
draft(subject
, text
);
6341 for(ItemPairs::const_iterator itr
= items
.begin(); itr
!= items
.end(); ++itr
)
6343 if(Item
* item
= Item::CreateItem(itr
->first
,itr
->second
,m_session
? m_session
->GetPlayer() : 0))
6345 item
->SaveToDB(); // save for prevent lost at next mail load, if send fail then item will deleted
6346 draft
.AddItem(item
);
6350 draft
.SendMailTo(MailReceiver(receiver
,GUID_LOPART(receiver_guid
)), sender
);
6352 std::string nameLink
= playerLink(receiver_name
);
6353 PSendSysMessage(LANG_MAIL_SENT
, nameLink
.c_str());
6357 ///Send money by mail
6358 bool ChatHandler::HandleSendMoneyCommand(const char* args
)
6360 /// format: name "subject text" "mail text" money
6363 uint64 receiver_guid
;
6364 std::string receiver_name
;
6365 if(!extractPlayerTarget((char*)args
,&receiver
,&receiver_guid
,&receiver_name
))
6368 char* tail1
= strtok(NULL
, "");
6372 char* msgSubject
= extractQuotedArg(tail1
);
6376 char* tail2
= strtok(NULL
, "");
6380 char* msgText
= extractQuotedArg(tail2
);
6384 char* money_str
= strtok(NULL
, "");
6385 int32 money
= money_str
? atoi(money_str
) : 0;
6389 // msgSubject, msgText isn't NUL after prev. check
6390 std::string subject
= msgSubject
;
6391 std::string text
= msgText
;
6393 // from console show not existed sender
6394 MailSender
sender(MAIL_NORMAL
,m_session
? m_session
->GetPlayer()->GetGUIDLow() : 0, MAIL_STATIONERY_GM
);
6396 MailDraft(subject
, text
)
6398 .SendMailTo(MailReceiver(receiver
,GUID_LOPART(receiver_guid
)),sender
);
6400 std::string nameLink
= playerLink(receiver_name
);
6401 PSendSysMessage(LANG_MAIL_SENT
, nameLink
.c_str());
6405 /// Send a message to a player in game
6406 bool ChatHandler::HandleSendMessageCommand(const char* args
)
6408 ///- Find the player
6410 if(!extractPlayerTarget((char*)args
,&rPlayer
))
6413 char* msg_str
= strtok(NULL
, "");
6417 ///- Check that he is not logging out.
6418 if(rPlayer
->GetSession()->isLogingOut())
6420 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6421 SetSentErrorMessage(true);
6425 ///- Send the message
6426 //Use SendAreaTriggerMessage for fastest delivery.
6427 rPlayer
->GetSession()->SendAreaTriggerMessage("%s", msg_str
);
6428 rPlayer
->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
6430 //Confirmation message
6431 std::string nameLink
= GetNameLink(rPlayer
);
6432 PSendSysMessage(LANG_SENDMESSAGE
,nameLink
.c_str(),msg_str
);
6436 bool ChatHandler::HandleFlushArenaPointsCommand(const char * /*args*/)
6438 sBattleGroundMgr
.DistributeArenaPoints();
6442 bool ChatHandler::HandleModifyGenderCommand(const char *args
)
6447 Player
*player
= getSelectedPlayer();
6451 PSendSysMessage(LANG_PLAYER_NOT_FOUND
);
6452 SetSentErrorMessage(true);
6456 PlayerInfo
const* info
= sObjectMgr
.GetPlayerInfo(player
->getRace(), player
->getClass());
6460 char const* gender_str
= (char*)args
;
6461 int gender_len
= strlen(gender_str
);
6465 if(!strncmp(gender_str
, "male", gender_len
)) // MALE
6467 if(player
->getGender() == GENDER_MALE
)
6470 gender
= GENDER_MALE
;
6472 else if (!strncmp(gender_str
, "female", gender_len
)) // FEMALE
6474 if(player
->getGender() == GENDER_FEMALE
)
6477 gender
= GENDER_FEMALE
;
6481 SendSysMessage(LANG_MUST_MALE_OR_FEMALE
);
6482 SetSentErrorMessage(true);
6487 player
->SetByteValue(UNIT_FIELD_BYTES_0
, 2, gender
);
6488 player
->SetByteValue(PLAYER_BYTES_3
, 0, gender
);
6490 // Change display ID
6491 player
->InitDisplayIds();
6493 char const* gender_full
= gender
? "female" : "male";
6495 PSendSysMessage(LANG_YOU_CHANGE_GENDER
, GetNameLink(player
).c_str(), gender_full
);
6497 if (needReportToTarget(player
))
6498 ChatHandler(player
).PSendSysMessage(LANG_YOUR_GENDER_CHANGED
, gender_full
, GetNameLink().c_str());