2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
24 #include "ObjectMgr.h"
25 #include "AccountMgr.h"
26 #include "PlayerDump.h"
30 #include "GameObject.h"
34 #include "ObjectAccessor.h"
35 #include "MapManager.h"
36 #include "ScriptCalls.h"
38 #include "GridNotifiersImpl.h"
41 #include "PointMovementGenerator.h"
42 #include "TargetedMovementGenerator.h"
43 #include "SkillDiscovery.h"
44 #include "SkillExtraItems.h"
45 #include "SystemConfig.h"
46 #include "Config/ConfigEnv.h"
48 #include "ItemEnchantmentMgr.h"
49 #include "BattleGroundMgr.h"
50 #include "InstanceSaveMgr.h"
51 #include "InstanceData.h"
52 #include "CreatureEventAIMgr.h"
56 bool ChatHandler::HandleReloadAllCommand(const char*)
58 HandleReloadSkillFishingBaseLevelCommand("");
60 HandleReloadAllAchievementCommand("");
61 HandleReloadAllAreaCommand("");
62 HandleReloadAllEventAICommand("");
63 HandleReloadAllLootCommand("");
64 HandleReloadAllNpcCommand("");
65 HandleReloadAllQuestCommand("");
66 HandleReloadAllSpellCommand("");
67 HandleReloadAllItemCommand("");
68 HandleReloadAllLocalesCommand("");
70 HandleReloadMailLevelRewardCommand("");
71 HandleReloadCommandCommand("");
72 HandleReloadReservedNameCommand("");
73 HandleReloadMangosStringCommand("");
74 HandleReloadGameTeleCommand("");
78 bool ChatHandler::HandleReloadAllAchievementCommand(const char*)
80 HandleReloadAchievementCriteriaRequirementCommand("");
81 HandleReloadAchievementRewardCommand("");
85 bool ChatHandler::HandleReloadAllAreaCommand(const char*)
87 //HandleReloadQuestAreaTriggersCommand(""); -- reloaded in HandleReloadAllQuestCommand
88 HandleReloadAreaTriggerTeleportCommand("");
89 HandleReloadAreaTriggerTavernCommand("");
90 HandleReloadGameGraveyardZoneCommand("");
94 bool ChatHandler::HandleReloadAllLootCommand(const char*)
96 sLog
.outString( "Re-Loading Loot Tables..." );
98 SendGlobalSysMessage("DB tables `*_loot_template` reloaded.");
102 bool ChatHandler::HandleReloadAllNpcCommand(const char* /*args*/)
104 HandleReloadNpcGossipCommand("a");
105 HandleReloadNpcTrainerCommand("a");
106 HandleReloadNpcVendorCommand("a");
107 HandleReloadPointsOfInterestCommand("a");
108 HandleReloadSpellClickSpellsCommand("a");
112 bool ChatHandler::HandleReloadAllQuestCommand(const char* /*args*/)
114 HandleReloadQuestAreaTriggersCommand("a");
115 HandleReloadQuestTemplateCommand("a");
117 sLog
.outString( "Re-Loading Quests Relations..." );
118 sObjectMgr
.LoadQuestRelations();
119 SendGlobalSysMessage("DB tables `*_questrelation` and `*_involvedrelation` reloaded.");
123 bool ChatHandler::HandleReloadAllScriptsCommand(const char*)
125 if(sWorld
.IsScriptScheduled())
127 PSendSysMessage("DB scripts used currently, please attempt reload later.");
128 SetSentErrorMessage(true);
132 sLog
.outString( "Re-Loading Scripts..." );
133 HandleReloadGameObjectScriptsCommand("a");
134 HandleReloadEventScriptsCommand("a");
135 HandleReloadQuestEndScriptsCommand("a");
136 HandleReloadQuestStartScriptsCommand("a");
137 HandleReloadSpellScriptsCommand("a");
138 SendGlobalSysMessage("DB tables `*_scripts` reloaded.");
139 HandleReloadDbScriptStringCommand("a");
143 bool ChatHandler::HandleReloadAllEventAICommand(const char*)
145 HandleReloadEventAITextsCommand("a");
146 HandleReloadEventAISummonsCommand("a");
147 HandleReloadEventAIScriptsCommand("a");
151 bool ChatHandler::HandleReloadAllSpellCommand(const char*)
153 HandleReloadSkillDiscoveryTemplateCommand("a");
154 HandleReloadSkillExtraItemTemplateCommand("a");
155 HandleReloadSpellAreaCommand("a");
156 HandleReloadSpellChainCommand("a");
157 HandleReloadSpellElixirCommand("a");
158 HandleReloadSpellLearnSpellCommand("a");
159 HandleReloadSpellProcEventCommand("a");
160 HandleReloadSpellBonusesCommand("a");
161 HandleReloadSpellProcItemEnchantCommand("a");
162 HandleReloadSpellScriptTargetCommand("a");
163 HandleReloadSpellTargetPositionCommand("a");
164 HandleReloadSpellThreatsCommand("a");
165 HandleReloadSpellPetAurasCommand("a");
169 bool ChatHandler::HandleReloadAllItemCommand(const char*)
171 HandleReloadPageTextsCommand("a");
172 HandleReloadItemEnchantementsCommand("a");
173 HandleReloadItemRequiredTragetCommand("a");
177 bool ChatHandler::HandleReloadAllLocalesCommand(const char* /*args*/)
179 HandleReloadLocalesAchievementRewardCommand("a");
180 HandleReloadLocalesCreatureCommand("a");
181 HandleReloadLocalesGameobjectCommand("a");
182 HandleReloadLocalesItemCommand("a");
183 HandleReloadLocalesNpcTextCommand("a");
184 HandleReloadLocalesPageTextCommand("a");
185 HandleReloadLocalesPointsOfInterestCommand("a");
186 HandleReloadLocalesQuestCommand("a");
190 bool ChatHandler::HandleReloadConfigCommand(const char* /*args*/)
192 sLog
.outString( "Re-Loading config settings..." );
193 sWorld
.LoadConfigSettings(true);
194 sMapMgr
.InitializeVisibilityDistanceInfo();
195 SendGlobalSysMessage("World config settings reloaded.");
199 bool ChatHandler::HandleReloadAchievementCriteriaRequirementCommand(const char*)
201 sLog
.outString( "Re-Loading Additional Achievement Criteria Requirements Data..." );
202 sAchievementMgr
.LoadAchievementCriteriaRequirements();
203 SendGlobalSysMessage("DB table `achievement_criteria_requirement` reloaded.");
207 bool ChatHandler::HandleReloadAchievementRewardCommand(const char*)
209 sLog
.outString( "Re-Loading Achievement Reward Data..." );
210 sAchievementMgr
.LoadRewards();
211 SendGlobalSysMessage("DB table `achievement_reward` reloaded.");
215 bool ChatHandler::HandleReloadAreaTriggerTavernCommand(const char*)
217 sLog
.outString( "Re-Loading Tavern Area Triggers..." );
218 sObjectMgr
.LoadTavernAreaTriggers();
219 SendGlobalSysMessage("DB table `areatrigger_tavern` reloaded.");
223 bool ChatHandler::HandleReloadAreaTriggerTeleportCommand(const char*)
225 sLog
.outString( "Re-Loading AreaTrigger teleport definitions..." );
226 sObjectMgr
.LoadAreaTriggerTeleports();
227 SendGlobalSysMessage("DB table `areatrigger_teleport` reloaded.");
231 bool ChatHandler::HandleReloadCommandCommand(const char*)
233 load_command_table
= true;
234 SendGlobalSysMessage("DB table `command` will be reloaded at next chat command use.");
238 bool ChatHandler::HandleReloadCreatureQuestRelationsCommand(const char*)
240 sLog
.outString( "Loading Quests Relations... (`creature_questrelation`)" );
241 sObjectMgr
.LoadCreatureQuestRelations();
242 SendGlobalSysMessage("DB table `creature_questrelation` (creature quest givers) reloaded.");
246 bool ChatHandler::HandleReloadCreatureQuestInvRelationsCommand(const char*)
248 sLog
.outString( "Loading Quests Relations... (`creature_involvedrelation`)" );
249 sObjectMgr
.LoadCreatureInvolvedRelations();
250 SendGlobalSysMessage("DB table `creature_involvedrelation` (creature quest takers) reloaded.");
254 bool ChatHandler::HandleReloadGossipMenuCommand(const char*)
256 sLog
.outString( "Re-Loading `gossip_menu` Table!" );
257 sObjectMgr
.LoadGossipMenu();
258 SendGlobalSysMessage("DB table `gossip_menu` reloaded.");
262 bool ChatHandler::HandleReloadGossipMenuOptionCommand(const char*)
264 sLog
.outString( "Re-Loading `gossip_menu_option` Table!" );
265 sObjectMgr
.LoadGossipMenuItems();
266 SendGlobalSysMessage("DB table `gossip_menu_option` reloaded.");
270 bool ChatHandler::HandleReloadGOQuestRelationsCommand(const char*)
272 sLog
.outString( "Loading Quests Relations... (`gameobject_questrelation`)" );
273 sObjectMgr
.LoadGameobjectQuestRelations();
274 SendGlobalSysMessage("DB table `gameobject_questrelation` (gameobject quest givers) reloaded.");
278 bool ChatHandler::HandleReloadGOQuestInvRelationsCommand(const char*)
280 sLog
.outString( "Loading Quests Relations... (`gameobject_involvedrelation`)" );
281 sObjectMgr
.LoadGameobjectInvolvedRelations();
282 SendGlobalSysMessage("DB table `gameobject_involvedrelation` (gameobject quest takers) reloaded.");
286 bool ChatHandler::HandleReloadQuestAreaTriggersCommand(const char*)
288 sLog
.outString( "Re-Loading Quest Area Triggers..." );
289 sObjectMgr
.LoadQuestAreaTriggers();
290 SendGlobalSysMessage("DB table `areatrigger_involvedrelation` (quest area triggers) reloaded.");
294 bool ChatHandler::HandleReloadQuestTemplateCommand(const char*)
296 sLog
.outString( "Re-Loading Quest Templates..." );
297 sObjectMgr
.LoadQuests();
298 SendGlobalSysMessage("DB table `quest_template` (quest definitions) reloaded.");
300 /// dependent also from `gameobject` but this table not reloaded anyway
301 sLog
.outString( "Re-Loading GameObjects for quests..." );
302 sObjectMgr
.LoadGameObjectForQuests();
303 SendGlobalSysMessage("Data GameObjects for quests reloaded.");
307 bool ChatHandler::HandleReloadLootTemplatesCreatureCommand(const char*)
309 sLog
.outString( "Re-Loading Loot Tables... (`creature_loot_template`)" );
310 LoadLootTemplates_Creature();
311 LootTemplates_Creature
.CheckLootRefs();
312 SendGlobalSysMessage("DB table `creature_loot_template` reloaded.");
316 bool ChatHandler::HandleReloadLootTemplatesDisenchantCommand(const char*)
318 sLog
.outString( "Re-Loading Loot Tables... (`disenchant_loot_template`)" );
319 LoadLootTemplates_Disenchant();
320 LootTemplates_Disenchant
.CheckLootRefs();
321 SendGlobalSysMessage("DB table `disenchant_loot_template` reloaded.");
325 bool ChatHandler::HandleReloadLootTemplatesFishingCommand(const char*)
327 sLog
.outString( "Re-Loading Loot Tables... (`fishing_loot_template`)" );
328 LoadLootTemplates_Fishing();
329 LootTemplates_Fishing
.CheckLootRefs();
330 SendGlobalSysMessage("DB table `fishing_loot_template` reloaded.");
334 bool ChatHandler::HandleReloadLootTemplatesGameobjectCommand(const char*)
336 sLog
.outString( "Re-Loading Loot Tables... (`gameobject_loot_template`)" );
337 LoadLootTemplates_Gameobject();
338 LootTemplates_Gameobject
.CheckLootRefs();
339 SendGlobalSysMessage("DB table `gameobject_loot_template` reloaded.");
343 bool ChatHandler::HandleReloadLootTemplatesItemCommand(const char*)
345 sLog
.outString( "Re-Loading Loot Tables... (`item_loot_template`)" );
346 LoadLootTemplates_Item();
347 LootTemplates_Item
.CheckLootRefs();
348 SendGlobalSysMessage("DB table `item_loot_template` reloaded.");
352 bool ChatHandler::HandleReloadLootTemplatesMillingCommand(const char*)
354 sLog
.outString( "Re-Loading Loot Tables... (`milling_loot_template`)" );
355 LoadLootTemplates_Milling();
356 LootTemplates_Milling
.CheckLootRefs();
357 SendGlobalSysMessage("DB table `milling_loot_template` reloaded.");
361 bool ChatHandler::HandleReloadLootTemplatesPickpocketingCommand(const char*)
363 sLog
.outString( "Re-Loading Loot Tables... (`pickpocketing_loot_template`)" );
364 LoadLootTemplates_Pickpocketing();
365 LootTemplates_Pickpocketing
.CheckLootRefs();
366 SendGlobalSysMessage("DB table `pickpocketing_loot_template` reloaded.");
370 bool ChatHandler::HandleReloadLootTemplatesProspectingCommand(const char*)
372 sLog
.outString( "Re-Loading Loot Tables... (`prospecting_loot_template`)" );
373 LoadLootTemplates_Prospecting();
374 LootTemplates_Prospecting
.CheckLootRefs();
375 SendGlobalSysMessage("DB table `prospecting_loot_template` reloaded.");
379 bool ChatHandler::HandleReloadLootTemplatesMailCommand(const char*)
381 sLog
.outString( "Re-Loading Loot Tables... (`mail_loot_template`)" );
382 LoadLootTemplates_Mail();
383 LootTemplates_Mail
.CheckLootRefs();
384 SendGlobalSysMessage("DB table `mail_loot_template` reloaded.");
388 bool ChatHandler::HandleReloadLootTemplatesReferenceCommand(const char*)
390 sLog
.outString( "Re-Loading Loot Tables... (`reference_loot_template`)" );
391 LoadLootTemplates_Reference();
392 SendGlobalSysMessage("DB table `reference_loot_template` reloaded.");
396 bool ChatHandler::HandleReloadLootTemplatesSkinningCommand(const char*)
398 sLog
.outString( "Re-Loading Loot Tables... (`skinning_loot_template`)" );
399 LoadLootTemplates_Skinning();
400 LootTemplates_Skinning
.CheckLootRefs();
401 SendGlobalSysMessage("DB table `skinning_loot_template` reloaded.");
405 bool ChatHandler::HandleReloadLootTemplatesSpellCommand(const char*)
407 sLog
.outString( "Re-Loading Loot Tables... (`spell_loot_template`)" );
408 LoadLootTemplates_Spell();
409 LootTemplates_Spell
.CheckLootRefs();
410 SendGlobalSysMessage("DB table `spell_loot_template` reloaded.");
414 bool ChatHandler::HandleReloadMangosStringCommand(const char*)
416 sLog
.outString( "Re-Loading mangos_string Table!" );
417 sObjectMgr
.LoadMangosStrings();
418 SendGlobalSysMessage("DB table `mangos_string` reloaded.");
422 bool ChatHandler::HandleReloadNpcGossipCommand(const char*)
424 sLog
.outString( "Re-Loading `npc_gossip` Table!" );
425 sObjectMgr
.LoadNpcTextId();
426 SendGlobalSysMessage("DB table `npc_gossip` reloaded.");
430 bool ChatHandler::HandleReloadNpcTrainerCommand(const char*)
432 sLog
.outString( "Re-Loading `npc_trainer` Table!" );
433 sObjectMgr
.LoadTrainerSpell();
434 SendGlobalSysMessage("DB table `npc_trainer` reloaded.");
438 bool ChatHandler::HandleReloadNpcVendorCommand(const char*)
440 sLog
.outString( "Re-Loading `npc_vendor` Table!" );
441 sObjectMgr
.LoadVendors();
442 SendGlobalSysMessage("DB table `npc_vendor` reloaded.");
446 bool ChatHandler::HandleReloadPointsOfInterestCommand(const char*)
448 sLog
.outString( "Re-Loading `points_of_interest` Table!" );
449 sObjectMgr
.LoadPointsOfInterest();
450 SendGlobalSysMessage("DB table `points_of_interest` reloaded.");
454 bool ChatHandler::HandleReloadSpellClickSpellsCommand(const char*)
456 sLog
.outString( "Re-Loading `npc_spellclick_spells` Table!" );
457 sObjectMgr
.LoadNPCSpellClickSpells();
458 SendGlobalSysMessage("DB table `npc_spellclick_spells` reloaded.");
462 bool ChatHandler::HandleReloadReservedNameCommand(const char*)
464 sLog
.outString( "Loading ReservedNames... (`reserved_name`)" );
465 sObjectMgr
.LoadReservedPlayersNames();
466 SendGlobalSysMessage("DB table `reserved_name` (player reserved names) reloaded.");
470 bool ChatHandler::HandleReloadSkillDiscoveryTemplateCommand(const char* /*args*/)
472 sLog
.outString( "Re-Loading Skill Discovery Table..." );
473 LoadSkillDiscoveryTable();
474 SendGlobalSysMessage("DB table `skill_discovery_template` (recipes discovered at crafting) reloaded.");
478 bool ChatHandler::HandleReloadSkillExtraItemTemplateCommand(const char* /*args*/)
480 sLog
.outString( "Re-Loading Skill Extra Item Table..." );
481 LoadSkillExtraItemTable();
482 SendGlobalSysMessage("DB table `skill_extra_item_template` (extra item creation when crafting) reloaded.");
486 bool ChatHandler::HandleReloadSkillFishingBaseLevelCommand(const char* /*args*/)
488 sLog
.outString( "Re-Loading Skill Fishing base level requirements..." );
489 sObjectMgr
.LoadFishingBaseSkillLevel();
490 SendGlobalSysMessage("DB table `skill_fishing_base_level` (fishing base level for zone/subzone) reloaded.");
494 bool ChatHandler::HandleReloadSpellAreaCommand(const char*)
496 sLog
.outString( "Re-Loading SpellArea Data..." );
497 sSpellMgr
.LoadSpellAreas();
498 SendGlobalSysMessage("DB table `spell_area` (spell dependences from area/quest/auras state) reloaded.");
502 bool ChatHandler::HandleReloadSpellChainCommand(const char*)
504 sLog
.outString( "Re-Loading Spell Chain Data... " );
505 sSpellMgr
.LoadSpellChains();
506 SendGlobalSysMessage("DB table `spell_chain` (spell ranks) reloaded.");
510 bool ChatHandler::HandleReloadSpellElixirCommand(const char*)
512 sLog
.outString( "Re-Loading Spell Elixir types..." );
513 sSpellMgr
.LoadSpellElixirs();
514 SendGlobalSysMessage("DB table `spell_elixir` (spell elixir types) reloaded.");
518 bool ChatHandler::HandleReloadSpellLearnSpellCommand(const char*)
520 sLog
.outString( "Re-Loading Spell Learn Spells..." );
521 sSpellMgr
.LoadSpellLearnSpells();
522 SendGlobalSysMessage("DB table `spell_learn_spell` reloaded.");
526 bool ChatHandler::HandleReloadSpellProcEventCommand(const char*)
528 sLog
.outString( "Re-Loading Spell Proc Event conditions..." );
529 sSpellMgr
.LoadSpellProcEvents();
530 SendGlobalSysMessage("DB table `spell_proc_event` (spell proc trigger requirements) reloaded.");
534 bool ChatHandler::HandleReloadSpellBonusesCommand(const char*)
536 sLog
.outString( "Re-Loading Spell Bonus Data..." );
537 sSpellMgr
.LoadSpellBonusess();
538 SendGlobalSysMessage("DB table `spell_bonus_data` (spell damage/healing coefficients) reloaded.");
542 bool ChatHandler::HandleReloadSpellProcItemEnchantCommand(const char*)
544 sLog
.outString( "Re-Loading Spell Proc Item Enchant..." );
545 sSpellMgr
.LoadSpellProcItemEnchant();
546 SendGlobalSysMessage("DB table `spell_proc_item_enchant` (item enchantment ppm) reloaded.");
550 bool ChatHandler::HandleReloadSpellScriptTargetCommand(const char*)
552 sLog
.outString( "Re-Loading SpellsScriptTarget..." );
553 sSpellMgr
.LoadSpellScriptTarget();
554 SendGlobalSysMessage("DB table `spell_script_target` (spell targets selection in case specific creature/GO requirements) reloaded.");
558 bool ChatHandler::HandleReloadSpellTargetPositionCommand(const char*)
560 sLog
.outString( "Re-Loading Spell target coordinates..." );
561 sSpellMgr
.LoadSpellTargetPositions();
562 SendGlobalSysMessage("DB table `spell_target_position` (destination coordinates for spell targets) reloaded.");
566 bool ChatHandler::HandleReloadSpellThreatsCommand(const char*)
568 sLog
.outString( "Re-Loading Aggro Spells Definitions...");
569 sSpellMgr
.LoadSpellThreats();
570 SendGlobalSysMessage("DB table `spell_threat` (spell aggro definitions) reloaded.");
574 bool ChatHandler::HandleReloadSpellPetAurasCommand(const char*)
576 sLog
.outString( "Re-Loading Spell pet auras...");
577 sSpellMgr
.LoadSpellPetAuras();
578 SendGlobalSysMessage("DB table `spell_pet_auras` reloaded.");
582 bool ChatHandler::HandleReloadPageTextsCommand(const char*)
584 sLog
.outString( "Re-Loading Page Texts..." );
585 sObjectMgr
.LoadPageTexts();
586 SendGlobalSysMessage("DB table `page_texts` reloaded.");
590 bool ChatHandler::HandleReloadItemEnchantementsCommand(const char*)
592 sLog
.outString( "Re-Loading Item Random Enchantments Table..." );
593 LoadRandomEnchantmentsTable();
594 SendGlobalSysMessage("DB table `item_enchantment_template` reloaded.");
598 bool ChatHandler::HandleReloadItemRequiredTragetCommand(const char*)
600 sLog
.outString( "Re-Loading Item Required Targets Table..." );
601 sObjectMgr
.LoadItemRequiredTarget();
602 SendGlobalSysMessage("DB table `item_required_target` reloaded.");
606 bool ChatHandler::HandleReloadBattleEventCommand(const char*)
608 sLog
.outString( "Re-Loading BattleGround Eventindexes..." );
609 sBattleGroundMgr
.LoadBattleEventIndexes();
610 SendGlobalSysMessage("DB table `gameobject_battleground` and `creature_battleground` reloaded.");
614 bool ChatHandler::HandleReloadGameObjectScriptsCommand(const char* arg
)
616 if(sWorld
.IsScriptScheduled())
618 SendSysMessage("DB scripts used currently, please attempt reload later.");
619 SetSentErrorMessage(true);
624 sLog
.outString( "Re-Loading Scripts from `gameobject_scripts`...");
626 sObjectMgr
.LoadGameObjectScripts();
629 SendGlobalSysMessage("DB table `gameobject_scripts` reloaded.");
634 bool ChatHandler::HandleReloadEventScriptsCommand(const char* arg
)
636 if(sWorld
.IsScriptScheduled())
638 SendSysMessage("DB scripts used currently, please attempt reload later.");
639 SetSentErrorMessage(true);
644 sLog
.outString( "Re-Loading Scripts from `event_scripts`...");
646 sObjectMgr
.LoadEventScripts();
649 SendGlobalSysMessage("DB table `event_scripts` reloaded.");
654 bool ChatHandler::HandleReloadEventAITextsCommand(const char* arg
)
657 sLog
.outString( "Re-Loading Texts from `creature_ai_texts`...");
658 sEventAIMgr
.LoadCreatureEventAI_Texts(true);
659 SendGlobalSysMessage("DB table `creature_ai_texts` reloaded.");
663 bool ChatHandler::HandleReloadEventAISummonsCommand(const char* arg
)
665 sLog
.outString( "Re-Loading Summons from `creature_ai_summons`...");
666 sEventAIMgr
.LoadCreatureEventAI_Summons(true);
667 SendGlobalSysMessage("DB table `creature_ai_summons` reloaded.");
671 bool ChatHandler::HandleReloadEventAIScriptsCommand(const char* arg
)
673 sLog
.outString( "Re-Loading Scripts from `creature_ai_scripts`...");
674 sEventAIMgr
.LoadCreatureEventAI_Scripts();
675 SendGlobalSysMessage("DB table `creature_ai_scripts` reloaded.");
679 bool ChatHandler::HandleReloadQuestEndScriptsCommand(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 `quest_end_scripts`...");
691 sObjectMgr
.LoadQuestEndScripts();
694 SendGlobalSysMessage("DB table `quest_end_scripts` reloaded.");
699 bool ChatHandler::HandleReloadQuestStartScriptsCommand(const char* arg
)
701 if(sWorld
.IsScriptScheduled())
703 SendSysMessage("DB scripts used currently, please attempt reload later.");
704 SetSentErrorMessage(true);
709 sLog
.outString( "Re-Loading Scripts from `quest_start_scripts`...");
711 sObjectMgr
.LoadQuestStartScripts();
714 SendGlobalSysMessage("DB table `quest_start_scripts` reloaded.");
719 bool ChatHandler::HandleReloadSpellScriptsCommand(const char* arg
)
721 if(sWorld
.IsScriptScheduled())
723 SendSysMessage("DB scripts used currently, please attempt reload later.");
724 SetSentErrorMessage(true);
729 sLog
.outString( "Re-Loading Scripts from `spell_scripts`...");
731 sObjectMgr
.LoadSpellScripts();
734 SendGlobalSysMessage("DB table `spell_scripts` reloaded.");
739 bool ChatHandler::HandleReloadDbScriptStringCommand(const char* /*arg*/)
741 sLog
.outString( "Re-Loading Script strings from `db_script_string`...");
742 sObjectMgr
.LoadDbScriptStrings();
743 SendGlobalSysMessage("DB table `db_script_string` reloaded.");
747 bool ChatHandler::HandleReloadGameGraveyardZoneCommand(const char* /*arg*/)
749 sLog
.outString( "Re-Loading Graveyard-zone links...");
751 sObjectMgr
.LoadGraveyardZones();
753 SendGlobalSysMessage("DB table `game_graveyard_zone` reloaded.");
758 bool ChatHandler::HandleReloadGameTeleCommand(const char* /*arg*/)
760 sLog
.outString( "Re-Loading Game Tele coordinates...");
762 sObjectMgr
.LoadGameTele();
764 SendGlobalSysMessage("DB table `game_tele` reloaded.");
769 bool ChatHandler::HandleReloadLocalesAchievementRewardCommand(const char*)
771 sLog
.outString( "Re-Loading Locales Achievement Reward Data..." );
772 sAchievementMgr
.LoadRewardLocales();
773 SendGlobalSysMessage("DB table `locales_achievement_reward` reloaded.");
777 bool ChatHandler::HandleReloadLocalesCreatureCommand(const char* /*arg*/)
779 sLog
.outString( "Re-Loading Locales Creature ...");
780 sObjectMgr
.LoadCreatureLocales();
781 SendGlobalSysMessage("DB table `locales_creature` reloaded.");
785 bool ChatHandler::HandleReloadLocalesGameobjectCommand(const char* /*arg*/)
787 sLog
.outString( "Re-Loading Locales Gameobject ... ");
788 sObjectMgr
.LoadGameObjectLocales();
789 SendGlobalSysMessage("DB table `locales_gameobject` reloaded.");
793 bool ChatHandler::HandleReloadLocalesItemCommand(const char* /*arg*/)
795 sLog
.outString( "Re-Loading Locales Item ... ");
796 sObjectMgr
.LoadItemLocales();
797 SendGlobalSysMessage("DB table `locales_item` reloaded.");
801 bool ChatHandler::HandleReloadLocalesNpcTextCommand(const char* /*arg*/)
803 sLog
.outString( "Re-Loading Locales NPC Text ... ");
804 sObjectMgr
.LoadNpcTextLocales();
805 SendGlobalSysMessage("DB table `locales_npc_text` reloaded.");
809 bool ChatHandler::HandleReloadLocalesPageTextCommand(const char* /*arg*/)
811 sLog
.outString( "Re-Loading Locales Page Text ... ");
812 sObjectMgr
.LoadPageTextLocales();
813 SendGlobalSysMessage("DB table `locales_page_text` reloaded.");
817 bool ChatHandler::HandleReloadLocalesPointsOfInterestCommand(const char* /*arg*/)
819 sLog
.outString( "Re-Loading Locales Points Of Interest ... ");
820 sObjectMgr
.LoadPointOfInterestLocales();
821 SendGlobalSysMessage("DB table `locales_points_of_interest` reloaded.");
825 bool ChatHandler::HandleReloadLocalesQuestCommand(const char* /*arg*/)
827 sLog
.outString( "Re-Loading Locales Quest ... ");
828 sObjectMgr
.LoadQuestLocales();
829 SendGlobalSysMessage("DB table `locales_quest` reloaded.");
833 bool ChatHandler::HandleReloadMailLevelRewardCommand(const char* /*arg*/)
835 sLog
.outString( "Re-Loading Player level dependent mail rewards..." );
836 sObjectMgr
.LoadMailLevelRewards();
837 SendGlobalSysMessage("DB table `mail_level_reward` reloaded.");
841 bool ChatHandler::HandleLoadScriptsCommand(const char* args
)
843 if(!LoadScriptingModule(args
)) return true;
845 sWorld
.SendWorldText(LANG_SCRIPTS_RELOADED
);
849 bool ChatHandler::HandleAccountSetGmLevelCommand(const char* args
)
851 char* arg1
= strtok((char*)args
, " ");
855 /// must be NULL if targeted syntax and must be not nULL if not targeted
856 char* arg2
= strtok(NULL
, " ");
858 std::string targetAccountName
;
859 uint32 targetAccountId
= 0;
861 /// only target player different from self allowed (if targetPlayer!=NULL then not console)
862 Player
* targetPlayer
= getSelectedPlayer();
863 if(targetPlayer
&& m_session
->GetPlayer()!=targetPlayer
)
865 /// wrong command syntax or unexpected targeting
869 /// security level expected in arg2 after this if.
872 targetAccountId
= targetPlayer
->GetSession()->GetAccountId();
873 sAccountMgr
.GetName(targetAccountId
, targetAccountName
);
877 /// wrong command syntax (second arg expected)
881 targetAccountName
= arg1
;
882 if (!AccountMgr::normalizeString(targetAccountName
))
884 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,targetAccountName
.c_str());
885 SetSentErrorMessage(true);
889 targetAccountId
= sAccountMgr
.GetId(targetAccountName
);
892 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,targetAccountName
.c_str());
893 SetSentErrorMessage(true);
898 int32 gm
= (int32
)atoi(arg2
);
899 if ( gm
< SEC_PLAYER
|| gm
> SEC_ADMINISTRATOR
)
901 SendSysMessage(LANG_BAD_VALUE
);
902 SetSentErrorMessage(true);
906 /// can set security level only for target with less security and to less security that we have
907 /// This will reject self apply by specify account name
908 if(HasLowerSecurityAccount(NULL
,targetAccountId
,true))
911 /// account can't set security to same or grater level, need more power GM or console
912 AccountTypes plSecurity
= m_session
? m_session
->GetSecurity() : SEC_CONSOLE
;
913 if (AccountTypes(gm
) >= plSecurity
)
915 SendSysMessage(LANG_YOURS_SECURITY_IS_LOW
);
916 SetSentErrorMessage(true);
920 // This will prevent self apply by self target or no target
921 if(targetPlayer
&& m_session
->GetPlayer()!=targetPlayer
)
923 ChatHandler(targetPlayer
).PSendSysMessage(LANG_YOURS_SECURITY_CHANGED
,GetNameLink().c_str(), gm
);
924 targetPlayer
->GetSession()->SetSecurity(AccountTypes(gm
));
927 PSendSysMessage(LANG_YOU_CHANGE_SECURITY
, targetAccountName
.c_str(), gm
);
928 loginDatabase
.PExecute("UPDATE account SET gmlevel = '%i' WHERE id = '%u'", gm
, targetAccountId
);
933 /// Set password for account
934 bool ChatHandler::HandleAccountSetPasswordCommand(const char* args
)
939 ///- Get the command line arguments
940 char *szAccount
= strtok ((char*)args
," ");
941 char *szPassword1
= strtok (NULL
," ");
942 char *szPassword2
= strtok (NULL
," ");
944 if (!szAccount
||!szPassword1
|| !szPassword2
)
947 std::string account_name
= szAccount
;
948 if (!AccountMgr::normalizeString(account_name
))
950 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
951 SetSentErrorMessage(true);
955 uint32 targetAccountId
= sAccountMgr
.GetId(account_name
);
956 if (!targetAccountId
)
958 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
959 SetSentErrorMessage(true);
963 /// can set password only for target with less security
964 /// This is also reject self apply in fact
965 if(HasLowerSecurityAccount (NULL
,targetAccountId
,true))
968 if (strcmp(szPassword1
,szPassword2
))
970 SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH
);
971 SetSentErrorMessage (true);
975 AccountOpResult result
= sAccountMgr
.ChangePassword(targetAccountId
, szPassword1
);
980 SendSysMessage(LANG_COMMAND_PASSWORD
);
982 case AOR_NAME_NOT_EXIST
:
983 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
984 SetSentErrorMessage(true);
986 case AOR_PASS_TOO_LONG
:
987 SendSysMessage(LANG_PASSWORD_TOO_LONG
);
988 SetSentErrorMessage(true);
991 SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD
);
992 SetSentErrorMessage(true);
999 bool ChatHandler::HandleMaxSkillCommand(const char* /*args*/)
1001 Player
* SelectedPlayer
= getSelectedPlayer();
1004 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1005 SetSentErrorMessage(true);
1009 // each skills that have max skill value dependent from level seted to current level max skill value
1010 SelectedPlayer
->UpdateSkillsToMaxSkillsForLevel();
1014 bool ChatHandler::HandleSetSkillCommand(const char* args
)
1016 // number or [name] Shift-click form |color|Hskill:skill_id|h[name]|h|r
1017 char* skill_p
= extractKeyFromLink((char*)args
,"Hskill");
1021 char *level_p
= strtok (NULL
, " ");
1026 char *max_p
= strtok (NULL
, " ");
1028 int32 skill
= atoi(skill_p
);
1031 PSendSysMessage(LANG_INVALID_SKILL_ID
, skill
);
1032 SetSentErrorMessage(true);
1036 int32 level
= atol (level_p
);
1038 Player
* target
= getSelectedPlayer();
1041 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1042 SetSentErrorMessage(true);
1046 SkillLineEntry
const* sl
= sSkillLineStore
.LookupEntry(skill
);
1049 PSendSysMessage(LANG_INVALID_SKILL_ID
, skill
);
1050 SetSentErrorMessage(true);
1054 std::string tNameLink
= GetNameLink(target
);
1056 if(!target
->GetSkillValue(skill
))
1058 PSendSysMessage(LANG_SET_SKILL_ERROR
, tNameLink
.c_str(), skill
, sl
->name
[GetSessionDbcLocale()]);
1059 SetSentErrorMessage(true);
1063 int32 max
= max_p
? atol (max_p
) : target
->GetPureMaxSkillValue(skill
);
1065 if( level
<= 0 || level
> max
|| max
<= 0 )
1068 target
->SetSkill(skill
, level
, max
);
1069 PSendSysMessage(LANG_SET_SKILL
, skill
, sl
->name
[GetSessionDbcLocale()], tNameLink
.c_str(), level
, max
);
1074 bool ChatHandler::HandleUnLearnCommand(const char* args
)
1079 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
1080 uint32 spell_id
= extractSpellIdFromLink((char*)args
);
1084 char const* allStr
= strtok(NULL
," ");
1085 bool allRanks
= allStr
? (strncmp(allStr
, "all", strlen(allStr
)) == 0) : false;
1087 Player
* target
= getSelectedPlayer();
1090 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1091 SetSentErrorMessage(true);
1096 spell_id
= sSpellMgr
.GetFirstSpellInChain (spell_id
);
1098 if (target
->HasSpell(spell_id
))
1099 target
->removeSpell(spell_id
,false,!allRanks
);
1101 SendSysMessage(LANG_FORGET_SPELL
);
1103 if(GetTalentSpellCost(spell_id
))
1104 target
->SendTalentsInfoData(false);
1109 bool ChatHandler::HandleCooldownCommand(const char* args
)
1111 Player
* target
= getSelectedPlayer();
1114 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1115 SetSentErrorMessage(true);
1119 std::string tNameLink
= GetNameLink(target
);
1123 target
->RemoveAllSpellCooldown();
1124 PSendSysMessage(LANG_REMOVEALL_COOLDOWN
, tNameLink
.c_str());
1128 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1129 uint32 spell_id
= extractSpellIdFromLink((char*)args
);
1133 if(!sSpellStore
.LookupEntry(spell_id
))
1135 PSendSysMessage(LANG_UNKNOWN_SPELL
, target
==m_session
->GetPlayer() ? GetMangosString(LANG_YOU
) : tNameLink
.c_str());
1136 SetSentErrorMessage(true);
1140 target
->RemoveSpellCooldown(spell_id
,true);
1141 PSendSysMessage(LANG_REMOVE_COOLDOWN
, spell_id
, target
==m_session
->GetPlayer() ? GetMangosString(LANG_YOU
) : tNameLink
.c_str());
1146 bool ChatHandler::HandleLearnAllCommand(const char* /*args*/)
1148 static const char *allSpellList
[] =
1531 //"9036", problems with ghost state
1540 //"6718", phasing stealth, annoying for learn all case.
1753 while(strcmp(allSpellList
[loop
], "0"))
1755 uint32 spell
= atol((char*)allSpellList
[loop
++]);
1757 if (m_session
->GetPlayer()->HasSpell(spell
))
1760 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1761 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1763 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1767 m_session
->GetPlayer()->learnSpell(spell
,false);
1770 SendSysMessage(LANG_COMMAND_LEARN_MANY_SPELLS
);
1775 bool ChatHandler::HandleLearnAllGMCommand(const char* /*args*/)
1777 static const char *gmSpellList
[] =
1779 "24347", // Become A Fish, No Breath Bar
1780 "35132", // Visual Boom
1781 "38488", // Attack 4000-8000 AOE
1782 "38795", // Attack 2000 AOE + Slow Down 90%
1783 "15712", // Attack 200
1784 "1852", // GM Spell Silence
1787 "29878", // Kill My Self
1788 "26644", // More Kill
1790 "28550", //Invisible 24
1791 "23452", //Invisible + Target
1795 uint16 gmSpellIter
= 0;
1796 while( strcmp(gmSpellList
[gmSpellIter
], "0") )
1798 uint32 spell
= atol((char*)gmSpellList
[gmSpellIter
++]);
1800 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1801 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1803 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1807 m_session
->GetPlayer()->learnSpell(spell
,false);
1810 SendSysMessage(LANG_LEARNING_GM_SKILLS
);
1814 bool ChatHandler::HandleLearnAllMyClassCommand(const char* /*args*/)
1816 HandleLearnAllMySpellsCommand("");
1817 HandleLearnAllMyTalentsCommand("");
1821 bool ChatHandler::HandleLearnAllMySpellsCommand(const char* /*args*/)
1823 ChrClassesEntry
const* clsEntry
= sChrClassesStore
.LookupEntry(m_session
->GetPlayer()->getClass());
1826 uint32 family
= clsEntry
->spellfamily
;
1828 for (uint32 i
= 0; i
< sSpellStore
.GetNumRows(); ++i
)
1830 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(i
);
1834 // skip server-side/triggered spells
1835 if(spellInfo
->spellLevel
==0)
1838 // skip wrong class/race skills
1839 if(!m_session
->GetPlayer()->IsSpellFitByClassAndRace(spellInfo
->Id
))
1842 // skip other spell families
1843 if( spellInfo
->SpellFamilyName
!= family
)
1846 // skip spells with first rank learned as talent (and all talents then also)
1847 uint32 first_rank
= sSpellMgr
.GetFirstSpellInChain(spellInfo
->Id
);
1848 if(GetTalentSpellCost(first_rank
) > 0 )
1851 // skip broken spells
1852 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1855 m_session
->GetPlayer()->learnSpell(i
,false);
1858 SendSysMessage(LANG_COMMAND_LEARN_CLASS_SPELLS
);
1862 bool ChatHandler::HandleLearnAllMyTalentsCommand(const char* /*args*/)
1864 Player
* player
= m_session
->GetPlayer();
1865 uint32 classMask
= player
->getClassMask();
1867 for (uint32 i
= 0; i
< sTalentStore
.GetNumRows(); ++i
)
1869 TalentEntry
const *talentInfo
= sTalentStore
.LookupEntry(i
);
1873 TalentTabEntry
const *talentTabInfo
= sTalentTabStore
.LookupEntry( talentInfo
->TalentTab
);
1877 if( (classMask
& talentTabInfo
->ClassMask
) == 0 )
1880 // search highest talent rank
1883 for(int rank
= MAX_TALENT_RANK
-1; rank
>= 0; --rank
)
1885 if(talentInfo
->RankID
[rank
]!=0)
1887 spellid
= talentInfo
->RankID
[rank
];
1892 if(!spellid
) // ??? none spells in talent
1895 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spellid
);
1896 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1899 // learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
1900 player
->learnSpellHighRank(spellid
);
1903 SendSysMessage(LANG_COMMAND_LEARN_CLASS_TALENTS
);
1907 bool ChatHandler::HandleLearnAllMyPetTalentsCommand(const char* /*args*/)
1909 Player
* player
= m_session
->GetPlayer();
1911 Pet
* pet
= player
->GetPet();
1914 SendSysMessage(LANG_NO_PET_FOUND
);
1915 SetSentErrorMessage(true);
1919 CreatureInfo
const *ci
= pet
->GetCreatureInfo();
1922 SendSysMessage(LANG_WRONG_PET_TYPE
);
1923 SetSentErrorMessage(true);
1927 CreatureFamilyEntry
const *pet_family
= sCreatureFamilyStore
.LookupEntry(ci
->family
);
1930 SendSysMessage(LANG_WRONG_PET_TYPE
);
1931 SetSentErrorMessage(true);
1935 if(pet_family
->petTalentType
< 0) // not hunter pet
1937 SendSysMessage(LANG_WRONG_PET_TYPE
);
1938 SetSentErrorMessage(true);
1942 for (uint32 i
= 0; i
< sTalentStore
.GetNumRows(); ++i
)
1944 TalentEntry
const *talentInfo
= sTalentStore
.LookupEntry(i
);
1948 TalentTabEntry
const *talentTabInfo
= sTalentTabStore
.LookupEntry( talentInfo
->TalentTab
);
1952 // prevent learn talent for different family (cheating)
1953 if(((1 << pet_family
->petTalentType
) & talentTabInfo
->petTalentMask
)==0)
1956 // search highest talent rank
1959 for(int rank
= MAX_TALENT_RANK
-1; rank
>= 0; --rank
)
1961 if(talentInfo
->RankID
[rank
]!=0)
1963 spellid
= talentInfo
->RankID
[rank
];
1968 if(!spellid
) // ??? none spells in talent
1971 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spellid
);
1972 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1975 // learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
1976 pet
->learnSpellHighRank(spellid
);
1979 SendSysMessage(LANG_COMMAND_LEARN_PET_TALENTS
);
1983 bool ChatHandler::HandleLearnAllLangCommand(const char* /*args*/)
1985 // skipping UNIVERSAL language (0)
1986 for(int i
= 1; i
< LANGUAGES_COUNT
; ++i
)
1987 m_session
->GetPlayer()->learnSpell(lang_description
[i
].spell_id
,false);
1989 SendSysMessage(LANG_COMMAND_LEARN_ALL_LANG
);
1993 bool ChatHandler::HandleLearnAllDefaultCommand(const char* args
)
1996 if(!extractPlayerTarget((char*)args
,&target
))
1999 target
->learnDefaultSpells();
2000 target
->learnQuestRewardedSpells();
2002 PSendSysMessage(LANG_COMMAND_LEARN_ALL_DEFAULT_AND_QUEST
,GetNameLink(target
).c_str());
2006 bool ChatHandler::HandleLearnCommand(const char* args
)
2008 Player
* targetPlayer
= getSelectedPlayer();
2012 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
2013 SetSentErrorMessage(true);
2017 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
2018 uint32 spell
= extractSpellIdFromLink((char*)args
);
2019 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
2022 char const* allStr
= strtok(NULL
," ");
2023 bool allRanks
= allStr
? (strncmp(allStr
, "all", strlen(allStr
)) == 0) : false;
2025 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
2026 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
2028 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
2029 SetSentErrorMessage(true);
2033 if (!allRanks
&& targetPlayer
->HasSpell(spell
))
2035 if(targetPlayer
== m_session
->GetPlayer())
2036 SendSysMessage(LANG_YOU_KNOWN_SPELL
);
2038 PSendSysMessage(LANG_TARGET_KNOWN_SPELL
,GetNameLink(targetPlayer
).c_str());
2039 SetSentErrorMessage(true);
2044 targetPlayer
->learnSpellHighRank(spell
);
2046 targetPlayer
->learnSpell(spell
,false);
2048 uint32 first_spell
= sSpellMgr
.GetFirstSpellInChain(spell
);
2049 if(GetTalentSpellCost(first_spell
))
2050 targetPlayer
->SendTalentsInfoData(false);
2055 bool ChatHandler::HandleAddItemCommand(const char* args
)
2062 if(args
[0]=='[') // [name] manual form
2064 char* citemName
= strtok((char*)args
, "]");
2066 if(citemName
&& citemName
[0])
2068 std::string itemName
= citemName
+1;
2069 WorldDatabase
.escape_string(itemName
);
2070 QueryResult
*result
= WorldDatabase
.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName
.c_str());
2073 PSendSysMessage(LANG_COMMAND_COULDNOTFIND
, citemName
+1);
2074 SetSentErrorMessage(true);
2077 itemId
= result
->Fetch()->GetUInt16();
2083 else // item_id or [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r
2085 char* cId
= extractKeyFromLink((char*)args
,"Hitem");
2091 char* ccount
= strtok(NULL
, " ");
2096 count
= strtol(ccount
, NULL
, 10);
2101 Player
* pl
= m_session
->GetPlayer();
2102 Player
* plTarget
= getSelectedPlayer();
2106 sLog
.outDetail(GetMangosString(LANG_ADDITEM
), itemId
, count
);
2108 ItemPrototype
const *pProto
= ObjectMgr::GetItemPrototype(itemId
);
2111 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, itemId
);
2112 SetSentErrorMessage(true);
2119 plTarget
->DestroyItemCount(itemId
, -count
, true, false);
2120 PSendSysMessage(LANG_REMOVEITEM
, itemId
, -count
, GetNameLink(plTarget
).c_str());
2125 uint32 noSpaceForCount
= 0;
2127 // check space and find places
2128 ItemPosCountVec dest
;
2129 uint8 msg
= plTarget
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, itemId
, count
, &noSpaceForCount
);
2130 if( msg
!= EQUIP_ERR_OK
) // convert to possible store amount
2131 count
-= noSpaceForCount
;
2133 if( count
== 0 || dest
.empty()) // can't add any
2135 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, itemId
, noSpaceForCount
);
2136 SetSentErrorMessage(true);
2140 Item
* item
= plTarget
->StoreNewItem( dest
, itemId
, true, Item::GenerateItemRandomPropertyId(itemId
));
2142 // remove binding (let GM give it to another player later)
2144 for(ItemPosCountVec::const_iterator itr
= dest
.begin(); itr
!= dest
.end(); ++itr
)
2145 if(Item
* item1
= pl
->GetItemByPos(itr
->pos
))
2146 item1
->SetBinding( false );
2148 if(count
> 0 && item
)
2150 pl
->SendNewItem(item
,count
,false,true);
2152 plTarget
->SendNewItem(item
,count
,true,false);
2155 if(noSpaceForCount
> 0)
2156 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, itemId
, noSpaceForCount
);
2161 bool ChatHandler::HandleAddItemSetCommand(const char* args
)
2166 char* cId
= extractKeyFromLink((char*)args
,"Hitemset"); // number or [name] Shift-click form |color|Hitemset:itemset_id|h[name]|h|r
2170 uint32 itemsetId
= atol(cId
);
2172 // prevent generation all items with itemset field value '0'
2175 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND
,itemsetId
);
2176 SetSentErrorMessage(true);
2180 Player
* pl
= m_session
->GetPlayer();
2181 Player
* plTarget
= getSelectedPlayer();
2185 sLog
.outDetail(GetMangosString(LANG_ADDITEMSET
), itemsetId
);
2188 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
2190 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
2194 if (pProto
->ItemSet
== itemsetId
)
2197 ItemPosCountVec dest
;
2198 uint8 msg
= plTarget
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, pProto
->ItemId
, 1 );
2199 if (msg
== EQUIP_ERR_OK
)
2201 Item
* item
= plTarget
->StoreNewItem( dest
, pProto
->ItemId
, true);
2203 // remove binding (let GM give it to another player later)
2205 item
->SetBinding( false );
2207 pl
->SendNewItem(item
,1,false,true);
2209 plTarget
->SendNewItem(item
,1,true,false);
2213 pl
->SendEquipError( msg
, NULL
, NULL
);
2214 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, pProto
->ItemId
, 1);
2221 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND
,itemsetId
);
2223 SetSentErrorMessage(true);
2230 bool ChatHandler::HandleListItemCommand(const char* args
)
2235 char* cId
= extractKeyFromLink((char*)args
,"Hitem");
2239 uint32 item_id
= atol(cId
);
2242 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
2243 SetSentErrorMessage(true);
2247 ItemPrototype
const* itemProto
= ObjectMgr::GetItemPrototype(item_id
);
2250 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
2251 SetSentErrorMessage(true);
2255 char* c_count
= strtok(NULL
, " ");
2256 int count
= c_count
? atol(c_count
) : 10;
2261 QueryResult
*result
;
2264 uint32 inv_count
= 0;
2265 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM character_inventory WHERE item_template='%u'",item_id
);
2268 inv_count
= (*result
)[0].GetUInt32();
2272 result
=CharacterDatabase
.PQuery(
2274 "SELECT ci.item, cibag.slot AS bag, ci.slot, ci.guid, characters.account,characters.name "
2275 "FROM character_inventory AS ci LEFT JOIN character_inventory AS cibag ON (cibag.item=ci.bag),characters "
2276 "WHERE ci.item_template='%u' AND ci.guid = characters.guid LIMIT %u ",
2277 item_id
,uint32(count
));
2283 Field
*fields
= result
->Fetch();
2284 uint32 item_guid
= fields
[0].GetUInt32();
2285 uint32 item_bag
= fields
[1].GetUInt32();
2286 uint32 item_slot
= fields
[2].GetUInt32();
2287 uint32 owner_guid
= fields
[3].GetUInt32();
2288 uint32 owner_acc
= fields
[4].GetUInt32();
2289 std::string owner_name
= fields
[5].GetCppString();
2291 char const* item_pos
= 0;
2292 if(Player::IsEquipmentPos(item_bag
,item_slot
))
2293 item_pos
= "[equipped]";
2294 else if(Player::IsInventoryPos(item_bag
,item_slot
))
2295 item_pos
= "[in inventory]";
2296 else if(Player::IsBankPos(item_bag
,item_slot
))
2297 item_pos
= "[in bank]";
2301 PSendSysMessage(LANG_ITEMLIST_SLOT
,
2302 item_guid
,owner_name
.c_str(),owner_guid
,owner_acc
,item_pos
);
2303 } while (result
->NextRow());
2305 int64 res_count
= result
->GetRowCount();
2309 if(count
> res_count
)
2316 uint32 mail_count
= 0;
2317 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM mail_items WHERE item_template='%u'", item_id
);
2320 mail_count
= (*result
)[0].GetUInt32();
2326 result
=CharacterDatabase
.PQuery(
2328 "SELECT mail_items.item_guid, mail.sender, mail.receiver, char_s.account, char_s.name, char_r.account, char_r.name "
2329 "FROM mail,mail_items,characters as char_s,characters as char_r "
2330 "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",
2331 item_id
,uint32(count
));
2340 Field
*fields
= result
->Fetch();
2341 uint32 item_guid
= fields
[0].GetUInt32();
2342 uint32 item_s
= fields
[1].GetUInt32();
2343 uint32 item_r
= fields
[2].GetUInt32();
2344 uint32 item_s_acc
= fields
[3].GetUInt32();
2345 std::string item_s_name
= fields
[4].GetCppString();
2346 uint32 item_r_acc
= fields
[5].GetUInt32();
2347 std::string item_r_name
= fields
[6].GetCppString();
2349 char const* item_pos
= "[in mail]";
2351 PSendSysMessage(LANG_ITEMLIST_MAIL
,
2352 item_guid
,item_s_name
.c_str(),item_s
,item_s_acc
,item_r_name
.c_str(),item_r
,item_r_acc
,item_pos
);
2353 } while (result
->NextRow());
2355 int64 res_count
= result
->GetRowCount();
2359 if(count
> res_count
)
2366 uint32 auc_count
= 0;
2367 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM auctionhouse WHERE item_template='%u'",item_id
);
2370 auc_count
= (*result
)[0].GetUInt32();
2376 result
=CharacterDatabase
.PQuery(
2378 "SELECT auctionhouse.itemguid, auctionhouse.itemowner, characters.account, characters.name "
2379 "FROM auctionhouse,characters WHERE auctionhouse.item_template='%u' AND characters.guid = auctionhouse.itemowner LIMIT %u",
2380 item_id
,uint32(count
));
2389 Field
*fields
= result
->Fetch();
2390 uint32 item_guid
= fields
[0].GetUInt32();
2391 uint32 owner
= fields
[1].GetUInt32();
2392 uint32 owner_acc
= fields
[2].GetUInt32();
2393 std::string owner_name
= fields
[3].GetCppString();
2395 char const* item_pos
= "[in auction]";
2397 PSendSysMessage(LANG_ITEMLIST_AUCTION
, item_guid
, owner_name
.c_str(), owner
, owner_acc
,item_pos
);
2398 } while (result
->NextRow());
2404 uint32 guild_count
= 0;
2405 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_entry) FROM guild_bank_item WHERE item_entry='%u'",item_id
);
2408 guild_count
= (*result
)[0].GetUInt32();
2412 result
=CharacterDatabase
.PQuery(
2414 "SELECT gi.item_guid, gi.guildid, guild.name "
2415 "FROM guild_bank_item AS gi, guild WHERE gi.item_entry='%u' AND gi.guildid = guild.guildid LIMIT %u ",
2416 item_id
,uint32(count
));
2422 Field
*fields
= result
->Fetch();
2423 uint32 item_guid
= fields
[0].GetUInt32();
2424 uint32 guild_guid
= fields
[1].GetUInt32();
2425 std::string guild_name
= fields
[2].GetCppString();
2427 char const* item_pos
= "[in guild bank]";
2429 PSendSysMessage(LANG_ITEMLIST_GUILD
,item_guid
,guild_name
.c_str(),guild_guid
,item_pos
);
2430 } while (result
->NextRow());
2432 int64 res_count
= result
->GetRowCount();
2436 if(count
> res_count
)
2442 if(inv_count
+mail_count
+auc_count
+guild_count
== 0)
2444 SendSysMessage(LANG_COMMAND_NOITEMFOUND
);
2445 SetSentErrorMessage(true);
2449 PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE
,item_id
,inv_count
+mail_count
+auc_count
+guild_count
,inv_count
,mail_count
,auc_count
,guild_count
);
2454 bool ChatHandler::HandleListObjectCommand(const char* args
)
2459 // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2460 char* cId
= extractKeyFromLink((char*)args
,"Hgameobject_entry");
2464 uint32 go_id
= atol(cId
);
2467 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID
, go_id
);
2468 SetSentErrorMessage(true);
2472 GameObjectInfo
const * gInfo
= ObjectMgr::GetGameObjectInfo(go_id
);
2475 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID
, go_id
);
2476 SetSentErrorMessage(true);
2480 char* c_count
= strtok(NULL
, " ");
2481 int count
= c_count
? atol(c_count
) : 10;
2486 QueryResult
*result
;
2488 uint32 obj_count
= 0;
2489 result
=WorldDatabase
.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'",go_id
);
2492 obj_count
= (*result
)[0].GetUInt32();
2498 Player
* pl
= m_session
->GetPlayer();
2499 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",
2500 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(),go_id
,uint32(count
));
2503 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map FROM gameobject WHERE id = '%u' LIMIT %u",
2504 go_id
,uint32(count
));
2510 Field
*fields
= result
->Fetch();
2511 uint32 guid
= fields
[0].GetUInt32();
2512 float x
= fields
[1].GetFloat();
2513 float y
= fields
[2].GetFloat();
2514 float z
= fields
[3].GetFloat();
2515 int mapid
= fields
[4].GetUInt16();
2518 PSendSysMessage(LANG_GO_LIST_CHAT
, guid
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2520 PSendSysMessage(LANG_GO_LIST_CONSOLE
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2521 } while (result
->NextRow());
2526 PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE
,go_id
,obj_count
);
2530 bool ChatHandler::HandleListCreatureCommand(const char* args
)
2535 // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
2536 char* cId
= extractKeyFromLink((char*)args
,"Hcreature_entry");
2540 uint32 cr_id
= atol(cId
);
2543 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID
, cr_id
);
2544 SetSentErrorMessage(true);
2548 CreatureInfo
const* cInfo
= ObjectMgr::GetCreatureTemplate(cr_id
);
2551 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID
, cr_id
);
2552 SetSentErrorMessage(true);
2556 char* c_count
= strtok(NULL
, " ");
2557 int count
= c_count
? atol(c_count
) : 10;
2562 QueryResult
*result
;
2564 uint32 cr_count
= 0;
2565 result
=WorldDatabase
.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'",cr_id
);
2568 cr_count
= (*result
)[0].GetUInt32();
2574 Player
* pl
= m_session
->GetPlayer();
2575 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",
2576 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(), cr_id
,uint32(count
));
2579 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '%u' LIMIT %u",
2580 cr_id
,uint32(count
));
2586 Field
*fields
= result
->Fetch();
2587 uint32 guid
= fields
[0].GetUInt32();
2588 float x
= fields
[1].GetFloat();
2589 float y
= fields
[2].GetFloat();
2590 float z
= fields
[3].GetFloat();
2591 int mapid
= fields
[4].GetUInt16();
2594 PSendSysMessage(LANG_CREATURE_LIST_CHAT
, guid
, guid
, cInfo
->Name
, x
, y
, z
, mapid
);
2596 PSendSysMessage(LANG_CREATURE_LIST_CONSOLE
, guid
, cInfo
->Name
, x
, y
, z
, mapid
);
2597 } while (result
->NextRow());
2602 PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE
,cr_id
,cr_count
);
2606 bool ChatHandler::HandleLookupItemCommand(const char* args
)
2611 std::string namepart
= args
;
2612 std::wstring wnamepart
;
2614 // converting string that we try to find to lower case
2615 if(!Utf8toWStr(namepart
,wnamepart
))
2618 wstrToLower(wnamepart
);
2622 // Search in `item_template`
2623 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
2625 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
2629 int loc_idx
= GetSessionDbLocaleIndex();
2632 ItemLocale
const *il
= sObjectMgr
.GetItemLocale(pProto
->ItemId
);
2635 if (il
->Name
.size() > loc_idx
&& !il
->Name
[loc_idx
].empty())
2637 std::string name
= il
->Name
[loc_idx
];
2639 if (Utf8FitTo(name
, wnamepart
))
2642 PSendSysMessage(LANG_ITEM_LIST_CHAT
, id
, id
, name
.c_str());
2644 PSendSysMessage(LANG_ITEM_LIST_CONSOLE
, id
, name
.c_str());
2652 std::string name
= pProto
->Name1
;
2656 if (Utf8FitTo(name
, wnamepart
))
2659 PSendSysMessage(LANG_ITEM_LIST_CHAT
, id
, id
, name
.c_str());
2661 PSendSysMessage(LANG_ITEM_LIST_CONSOLE
, id
, name
.c_str());
2667 SendSysMessage(LANG_COMMAND_NOITEMFOUND
);
2672 bool ChatHandler::HandleLookupItemSetCommand(const char* args
)
2677 std::string namepart
= args
;
2678 std::wstring wnamepart
;
2680 if(!Utf8toWStr(namepart
,wnamepart
))
2683 // converting string that we try to find to lower case
2684 wstrToLower( wnamepart
);
2686 uint32 counter
= 0; // Counter for figure out that we found smth.
2688 // Search in ItemSet.dbc
2689 for (uint32 id
= 0; id
< sItemSetStore
.GetNumRows(); id
++)
2691 ItemSetEntry
const *set
= sItemSetStore
.LookupEntry(id
);
2694 int loc
= GetSessionDbcLocale();
2695 std::string name
= set
->name
[loc
];
2699 if (!Utf8FitTo(name
, wnamepart
))
2702 for(; loc
< MAX_LOCALE
; ++loc
)
2704 if(loc
==GetSessionDbcLocale())
2707 name
= set
->name
[loc
];
2711 if (Utf8FitTo(name
, wnamepart
))
2716 if(loc
< MAX_LOCALE
)
2718 // send item set in "id - [namedlink locale]" format
2720 PSendSysMessage(LANG_ITEMSET_LIST_CHAT
,id
,id
,name
.c_str(),localeNames
[loc
]);
2722 PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE
,id
,name
.c_str(),localeNames
[loc
]);
2727 if (counter
== 0) // if counter == 0 then we found nth
2728 SendSysMessage(LANG_COMMAND_NOITEMSETFOUND
);
2732 bool ChatHandler::HandleLookupSkillCommand(const char* args
)
2737 // can be NULL in console call
2738 Player
* target
= getSelectedPlayer();
2740 std::string namepart
= args
;
2741 std::wstring wnamepart
;
2743 if(!Utf8toWStr(namepart
,wnamepart
))
2746 // converting string that we try to find to lower case
2747 wstrToLower( wnamepart
);
2749 uint32 counter
= 0; // Counter for figure out that we found smth.
2751 // Search in SkillLine.dbc
2752 for (uint32 id
= 0; id
< sSkillLineStore
.GetNumRows(); id
++)
2754 SkillLineEntry
const *skillInfo
= sSkillLineStore
.LookupEntry(id
);
2757 int loc
= GetSessionDbcLocale();
2758 std::string name
= skillInfo
->name
[loc
];
2762 if (!Utf8FitTo(name
, wnamepart
))
2765 for(; loc
< MAX_LOCALE
; ++loc
)
2767 if(loc
==GetSessionDbcLocale())
2770 name
= skillInfo
->name
[loc
];
2774 if (Utf8FitTo(name
, wnamepart
))
2779 if(loc
< MAX_LOCALE
)
2781 char valStr
[50] = "";
2782 char const* knownStr
= "";
2783 if(target
&& target
->HasSkill(id
))
2785 knownStr
= GetMangosString(LANG_KNOWN
);
2786 uint32 curValue
= target
->GetPureSkillValue(id
);
2787 uint32 maxValue
= target
->GetPureMaxSkillValue(id
);
2788 uint32 permValue
= target
->GetSkillPermBonusValue(id
);
2789 uint32 tempValue
= target
->GetSkillTempBonusValue(id
);
2791 char const* valFormat
= GetMangosString(LANG_SKILL_VALUES
);
2792 snprintf(valStr
,50,valFormat
,curValue
,maxValue
,permValue
,tempValue
);
2795 // send skill in "id - [namedlink locale]" format
2797 PSendSysMessage(LANG_SKILL_LIST_CHAT
,id
,id
,name
.c_str(),localeNames
[loc
],knownStr
,valStr
);
2799 PSendSysMessage(LANG_SKILL_LIST_CONSOLE
,id
,name
.c_str(),localeNames
[loc
],knownStr
,valStr
);
2805 if (counter
== 0) // if counter == 0 then we found nth
2806 SendSysMessage(LANG_COMMAND_NOSKILLFOUND
);
2810 bool ChatHandler::HandleLookupSpellCommand(const char* args
)
2815 // can be NULL at console call
2816 Player
* target
= getSelectedPlayer();
2818 std::string namepart
= args
;
2819 std::wstring wnamepart
;
2821 if(!Utf8toWStr(namepart
,wnamepart
))
2824 // converting string that we try to find to lower case
2825 wstrToLower( wnamepart
);
2827 uint32 counter
= 0; // Counter for figure out that we found smth.
2829 // Search in Spell.dbc
2830 for (uint32 id
= 0; id
< sSpellStore
.GetNumRows(); id
++)
2832 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(id
);
2835 int loc
= GetSessionDbcLocale();
2836 std::string name
= spellInfo
->SpellName
[loc
];
2840 if (!Utf8FitTo(name
, wnamepart
))
2843 for(; loc
< MAX_LOCALE
; ++loc
)
2845 if(loc
==GetSessionDbcLocale())
2848 name
= spellInfo
->SpellName
[loc
];
2852 if (Utf8FitTo(name
, wnamepart
))
2857 if(loc
< MAX_LOCALE
)
2859 bool known
= target
&& target
->HasSpell(id
);
2860 bool learn
= (spellInfo
->Effect
[0] == SPELL_EFFECT_LEARN_SPELL
);
2862 uint32 talentCost
= GetTalentSpellCost(id
);
2864 bool talent
= (talentCost
> 0);
2865 bool passive
= IsPassiveSpell(id
);
2866 bool active
= target
&& target
->HasAura(id
);
2868 // unit32 used to prevent interpreting uint8 as char at output
2869 // find rank of learned spell for learning spell, or talent rank
2870 uint32 rank
= talentCost
? talentCost
: sSpellMgr
.GetSpellRank(learn
? spellInfo
->EffectTriggerSpell
[0] : id
);
2872 // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
2873 std::ostringstream ss
;
2875 ss
<< id
<< " - |cffffffff|Hspell:" << id
<< "|h[" << name
;
2877 ss
<< id
<< " - " << name
;
2879 // include rank in link name
2881 ss
<< GetMangosString(LANG_SPELL_RANK
) << rank
;
2884 ss
<< " " << localeNames
[loc
] << "]|h|r";
2886 ss
<< " " << localeNames
[loc
];
2889 ss
<< GetMangosString(LANG_TALENT
);
2891 ss
<< GetMangosString(LANG_PASSIVE
);
2893 ss
<< GetMangosString(LANG_LEARN
);
2895 ss
<< GetMangosString(LANG_KNOWN
);
2897 ss
<< GetMangosString(LANG_ACTIVE
);
2899 SendSysMessage(ss
.str().c_str());
2905 if (counter
== 0) // if counter == 0 then we found nth
2906 SendSysMessage(LANG_COMMAND_NOSPELLFOUND
);
2910 bool ChatHandler::HandleLookupQuestCommand(const char* args
)
2915 // can be NULL at console call
2916 Player
* target
= getSelectedPlayer();
2918 std::string namepart
= args
;
2919 std::wstring wnamepart
;
2921 // converting string that we try to find to lower case
2922 if(!Utf8toWStr(namepart
,wnamepart
))
2925 wstrToLower(wnamepart
);
2927 uint32 counter
= 0 ;
2929 ObjectMgr::QuestMap
const& qTemplates
= sObjectMgr
.GetQuestTemplates();
2930 for (ObjectMgr::QuestMap::const_iterator iter
= qTemplates
.begin(); iter
!= qTemplates
.end(); ++iter
)
2932 Quest
* qinfo
= iter
->second
;
2934 int loc_idx
= GetSessionDbLocaleIndex();
2937 QuestLocale
const *il
= sObjectMgr
.GetQuestLocale(qinfo
->GetQuestId());
2940 if (il
->Title
.size() > loc_idx
&& !il
->Title
[loc_idx
].empty())
2942 std::string title
= il
->Title
[loc_idx
];
2944 if (Utf8FitTo(title
, wnamepart
))
2946 char const* statusStr
= "";
2950 QuestStatus status
= target
->GetQuestStatus(qinfo
->GetQuestId());
2952 if(status
== QUEST_STATUS_COMPLETE
)
2954 if(target
->GetQuestRewardStatus(qinfo
->GetQuestId()))
2955 statusStr
= GetMangosString(LANG_COMMAND_QUEST_REWARDED
);
2957 statusStr
= GetMangosString(LANG_COMMAND_QUEST_COMPLETE
);
2959 else if(status
== QUEST_STATUS_INCOMPLETE
)
2960 statusStr
= GetMangosString(LANG_COMMAND_QUEST_ACTIVE
);
2964 PSendSysMessage(LANG_QUEST_LIST_CHAT
,qinfo
->GetQuestId(),qinfo
->GetQuestId(),qinfo
->GetQuestLevel(),title
.c_str(),statusStr
);
2966 PSendSysMessage(LANG_QUEST_LIST_CONSOLE
,qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2974 std::string title
= qinfo
->GetTitle();
2978 if (Utf8FitTo(title
, wnamepart
))
2980 char const* statusStr
= "";
2984 QuestStatus status
= target
->GetQuestStatus(qinfo
->GetQuestId());
2986 if(status
== QUEST_STATUS_COMPLETE
)
2988 if(target
->GetQuestRewardStatus(qinfo
->GetQuestId()))
2989 statusStr
= GetMangosString(LANG_COMMAND_QUEST_REWARDED
);
2991 statusStr
= GetMangosString(LANG_COMMAND_QUEST_COMPLETE
);
2993 else if(status
== QUEST_STATUS_INCOMPLETE
)
2994 statusStr
= GetMangosString(LANG_COMMAND_QUEST_ACTIVE
);
2998 PSendSysMessage(LANG_QUEST_LIST_CHAT
,qinfo
->GetQuestId(),qinfo
->GetQuestId(),qinfo
->GetQuestLevel(),title
.c_str(),statusStr
);
3000 PSendSysMessage(LANG_QUEST_LIST_CONSOLE
,qinfo
->GetQuestId(),title
.c_str(),statusStr
);
3007 SendSysMessage(LANG_COMMAND_NOQUESTFOUND
);
3012 bool ChatHandler::HandleLookupCreatureCommand(const char* args
)
3017 std::string namepart
= args
;
3018 std::wstring wnamepart
;
3020 // converting string that we try to find to lower case
3021 if (!Utf8toWStr (namepart
,wnamepart
))
3024 wstrToLower (wnamepart
);
3028 for (uint32 id
= 0; id
< sCreatureStorage
.MaxEntry
; ++id
)
3030 CreatureInfo
const* cInfo
= sCreatureStorage
.LookupEntry
<CreatureInfo
> (id
);
3034 int loc_idx
= GetSessionDbLocaleIndex();
3037 CreatureLocale
const *cl
= sObjectMgr
.GetCreatureLocale (id
);
3040 if (cl
->Name
.size() > loc_idx
&& !cl
->Name
[loc_idx
].empty ())
3042 std::string name
= cl
->Name
[loc_idx
];
3044 if (Utf8FitTo (name
, wnamepart
))
3047 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str ());
3049 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE
, id
, name
.c_str ());
3057 std::string name
= cInfo
->Name
;
3061 if (Utf8FitTo(name
, wnamepart
))
3064 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str ());
3066 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE
, id
, name
.c_str ());
3072 SendSysMessage (LANG_COMMAND_NOCREATUREFOUND
);
3077 bool ChatHandler::HandleLookupObjectCommand(const char* args
)
3082 std::string namepart
= args
;
3083 std::wstring wnamepart
;
3085 // converting string that we try to find to lower case
3086 if(!Utf8toWStr(namepart
,wnamepart
))
3089 wstrToLower(wnamepart
);
3093 for (uint32 id
= 0; id
< sGOStorage
.MaxEntry
; id
++ )
3095 GameObjectInfo
const* gInfo
= sGOStorage
.LookupEntry
<GameObjectInfo
>(id
);
3099 int loc_idx
= GetSessionDbLocaleIndex();
3102 GameObjectLocale
const *gl
= sObjectMgr
.GetGameObjectLocale(id
);
3105 if (gl
->Name
.size() > loc_idx
&& !gl
->Name
[loc_idx
].empty())
3107 std::string name
= gl
->Name
[loc_idx
];
3109 if (Utf8FitTo(name
, wnamepart
))
3112 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT
, id
, id
, name
.c_str());
3114 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE
, id
, name
.c_str());
3122 std::string name
= gInfo
->name
;
3126 if(Utf8FitTo(name
, wnamepart
))
3129 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT
, id
, id
, name
.c_str());
3131 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE
, id
, name
.c_str());
3137 SendSysMessage(LANG_COMMAND_NOGAMEOBJECTFOUND
);
3142 bool ChatHandler::HandleLookupTaxiNodeCommand(const char * args
)
3147 std::string namepart
= args
;
3148 std::wstring wnamepart
;
3150 if(!Utf8toWStr(namepart
,wnamepart
))
3153 // converting string that we try to find to lower case
3154 wstrToLower( wnamepart
);
3156 uint32 counter
= 0; // Counter for figure out that we found smth.
3158 // Search in TaxiNodes.dbc
3159 for (uint32 id
= 0; id
< sTaxiNodesStore
.GetNumRows(); id
++)
3161 TaxiNodesEntry
const *nodeEntry
= sTaxiNodesStore
.LookupEntry(id
);
3164 int loc
= GetSessionDbcLocale();
3165 std::string name
= nodeEntry
->name
[loc
];
3169 if (!Utf8FitTo(name
, wnamepart
))
3172 for(; loc
< MAX_LOCALE
; ++loc
)
3174 if(loc
==GetSessionDbcLocale())
3177 name
= nodeEntry
->name
[loc
];
3181 if (Utf8FitTo(name
, wnamepart
))
3186 if(loc
< MAX_LOCALE
)
3188 // send taxinode in "id - [name] (Map:m X:x Y:y Z:z)" format
3190 PSendSysMessage (LANG_TAXINODE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str(),localeNames
[loc
],
3191 nodeEntry
->map_id
,nodeEntry
->x
,nodeEntry
->y
,nodeEntry
->z
);
3193 PSendSysMessage (LANG_TAXINODE_ENTRY_LIST_CONSOLE
, id
, name
.c_str(), localeNames
[loc
],
3194 nodeEntry
->map_id
,nodeEntry
->x
,nodeEntry
->y
,nodeEntry
->z
);
3199 if (counter
== 0) // if counter == 0 then we found nth
3200 SendSysMessage(LANG_COMMAND_NOTAXINODEFOUND
);
3204 /** \brief GM command level 3 - Create a guild.
3206 * This command allows a GM (level 3) to create a guild.
3208 * The "args" parameter contains the name of the guild leader
3209 * and then the name of the guild.
3212 bool ChatHandler::HandleGuildCreateCommand(const char* args
)
3217 // if not guild name only (in "") then player name
3219 if(!extractPlayerTarget(*args
!='"' ? (char*)args
: NULL
, &target
))
3222 char* tailStr
= *args
!='"' ? strtok(NULL
, "") : (char*)args
;
3226 char* guildStr
= extractQuotedArg(tailStr
);
3230 std::string guildname
= guildStr
;
3232 if (target
->GetGuildId())
3234 SendSysMessage (LANG_PLAYER_IN_GUILD
);
3238 Guild
*guild
= new Guild
;
3239 if (!guild
->Create (target
,guildname
))
3242 SendSysMessage (LANG_GUILD_NOT_CREATED
);
3243 SetSentErrorMessage (true);
3247 sObjectMgr
.AddGuild (guild
);
3251 bool ChatHandler::HandleGuildInviteCommand(const char *args
)
3256 // if not guild name only (in "") then player name
3258 if(!extractPlayerTarget(*args
!='"' ? (char*)args
: NULL
, NULL
, &target_guid
))
3261 char* tailStr
= *args
!='"' ? strtok(NULL
, "") : (char*)args
;
3265 char* guildStr
= extractQuotedArg(tailStr
);
3269 std::string glName
= guildStr
;
3270 Guild
* targetGuild
= sObjectMgr
.GetGuildByName (glName
);
3274 // player's guild membership checked in AddMember before add
3275 if (!targetGuild
->AddMember (target_guid
,targetGuild
->GetLowestRank ()))
3281 bool ChatHandler::HandleGuildUninviteCommand(const char *args
)
3285 if(!extractPlayerTarget((char*)args
,&target
,&target_guid
))
3288 uint32 glId
= target
? target
->GetGuildId () : Player::GetGuildIdFromDB (target_guid
);
3292 Guild
* targetGuild
= sObjectMgr
.GetGuildById (glId
);
3296 targetGuild
->DelMember (target_guid
);
3300 bool ChatHandler::HandleGuildRankCommand(const char *args
)
3304 extractOptFirstArg((char*)args
,&nameStr
,&rankStr
);
3310 std::string target_name
;
3311 if(!extractPlayerTarget(nameStr
,&target
,&target_guid
,&target_name
))
3314 uint32 glId
= target
? target
->GetGuildId () : Player::GetGuildIdFromDB (target_guid
);
3318 Guild
* targetGuild
= sObjectMgr
.GetGuildById (glId
);
3322 uint32 newrank
= uint32 (atoi (rankStr
));
3323 if (newrank
> targetGuild
->GetLowestRank ())
3326 targetGuild
->ChangeRank (target_guid
,newrank
);
3330 bool ChatHandler::HandleGuildDeleteCommand(const char* args
)
3335 char* guildStr
= extractQuotedArg((char*)args
);
3339 std::string gld
= guildStr
;
3341 Guild
* targetGuild
= sObjectMgr
.GetGuildByName (gld
);
3345 targetGuild
->Disband ();
3350 bool ChatHandler::HandleGetDistanceCommand(const char* args
)
3352 WorldObject
* obj
= NULL
;
3356 uint64 guid
= extractGuidFromLink((char*)args
);
3358 obj
= (WorldObject
*)ObjectAccessor::GetObjectByTypeMask(*m_session
->GetPlayer(),guid
,TYPEMASK_UNIT
|TYPEMASK_GAMEOBJECT
);
3362 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3363 SetSentErrorMessage(true);
3369 obj
= getSelectedUnit();
3373 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3374 SetSentErrorMessage(true);
3379 PSendSysMessage(LANG_DISTANCE
, m_session
->GetPlayer()->GetDistance(obj
),m_session
->GetPlayer()->GetDistance2d(obj
));
3384 bool ChatHandler::HandleDieCommand(const char* /*args*/)
3386 Unit
* target
= getSelectedUnit();
3388 if(!target
|| !m_session
->GetPlayer()->GetSelection())
3390 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3391 SetSentErrorMessage(true);
3395 if(target
->GetTypeId()==TYPEID_PLAYER
)
3397 if(HasLowerSecurity((Player
*)target
,0,false))
3401 if( target
->isAlive() )
3403 m_session
->GetPlayer()->DealDamage(target
, target
->GetHealth(), NULL
, DIRECT_DAMAGE
, SPELL_SCHOOL_MASK_NORMAL
, NULL
, false);
3409 bool ChatHandler::HandleDamageCommand(const char * args
)
3414 Unit
* target
= getSelectedUnit();
3416 if (!target
|| !m_session
->GetPlayer()->GetSelection())
3418 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3419 SetSentErrorMessage(true);
3423 if (!target
->isAlive())
3426 char* damageStr
= strtok((char*)args
, " ");
3430 int32 damage_int
= atoi((char*)damageStr
);
3434 uint32 damage
= damage_int
;
3436 char* schoolStr
= strtok((char*)NULL
, " ");
3438 // flat melee damage without resistence/etc reduction
3441 m_session
->GetPlayer()->DealDamage(target
, damage
, NULL
, DIRECT_DAMAGE
, SPELL_SCHOOL_MASK_NORMAL
, NULL
, false);
3442 if (target
!= m_session
->GetPlayer())
3443 m_session
->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2
, target
, 1, SPELL_SCHOOL_MASK_NORMAL
, damage
, 0, 0, VICTIMSTATE_NORMAL
, 0);
3447 uint32 school
= schoolStr
? atoi((char*)schoolStr
) : SPELL_SCHOOL_NORMAL
;
3448 if(school
>= MAX_SPELL_SCHOOL
)
3451 SpellSchoolMask schoolmask
= SpellSchoolMask(1 << school
);
3453 if ( schoolmask
& SPELL_SCHOOL_MASK_NORMAL
)
3454 damage
= m_session
->GetPlayer()->CalcArmorReducedDamage(target
, damage
);
3456 char* spellStr
= strtok((char*)NULL
, " ");
3458 // melee damage by specific school
3464 m_session
->GetPlayer()->CalcAbsorbResist(target
,schoolmask
, SPELL_DIRECT_DAMAGE
, damage
, &absorb
, &resist
);
3466 if (damage
<= absorb
+ resist
)
3469 damage
-= absorb
+ resist
;
3471 m_session
->GetPlayer()->DealDamageMods(target
,damage
,&absorb
);
3472 m_session
->GetPlayer()->DealDamage(target
, damage
, NULL
, DIRECT_DAMAGE
, schoolmask
, NULL
, false);
3473 m_session
->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2
, target
, 1, schoolmask
, damage
, absorb
, resist
, VICTIMSTATE_NORMAL
, 0);
3479 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3480 uint32 spellid
= extractSpellIdFromLink((char*)args
);
3481 if (!spellid
|| !sSpellStore
.LookupEntry(spellid
))
3484 m_session
->GetPlayer()->SpellNonMeleeDamageLog(target
, spellid
, damage
);
3488 bool ChatHandler::HandleModifyArenaCommand(const char * args
)
3493 Player
*target
= getSelectedPlayer();
3496 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3497 SetSentErrorMessage(true);
3501 int32 amount
= (uint32
)atoi(args
);
3503 target
->ModifyArenaPoints(amount
);
3505 PSendSysMessage(LANG_COMMAND_MODIFY_ARENA
, GetNameLink(target
).c_str(), target
->GetArenaPoints());
3510 bool ChatHandler::HandleReviveCommand(const char* args
)
3514 if(!extractPlayerTarget((char*)args
,&target
,&target_guid
))
3519 target
->ResurrectPlayer(0.5f
);
3520 target
->SpawnCorpseBones();
3523 // will resurrected at login without corpse
3524 sObjectAccessor
.ConvertCorpseForPlayer(target_guid
);
3529 bool ChatHandler::HandleAuraCommand(const char* args
)
3531 Unit
*target
= getSelectedUnit();
3534 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3535 SetSentErrorMessage(true);
3539 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3540 uint32 spellID
= extractSpellIdFromLink((char*)args
);
3542 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry( spellID
);
3545 for(uint32 i
= 0;i
<3;++i
)
3547 uint8 eff
= spellInfo
->Effect
[i
];
3548 if (eff
>=TOTAL_SPELL_EFFECTS
)
3550 if( IsAreaAuraEffect(eff
) ||
3551 eff
== SPELL_EFFECT_APPLY_AURA
||
3552 eff
== SPELL_EFFECT_PERSISTENT_AREA_AURA
)
3554 Aura
*Aur
= CreateAura(spellInfo
, i
, NULL
, target
);
3555 target
->AddAura(Aur
);
3563 bool ChatHandler::HandleUnAuraCommand(const char* args
)
3565 Unit
*target
= getSelectedUnit();
3568 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3569 SetSentErrorMessage(true);
3573 std::string argstr
= args
;
3574 if (argstr
== "all")
3576 target
->RemoveAllAuras();
3580 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3581 uint32 spellID
= extractSpellIdFromLink((char*)args
);
3585 target
->RemoveAurasDueToSpell(spellID
);
3590 bool ChatHandler::HandleLinkGraveCommand(const char* args
)
3595 char* px
= strtok((char*)args
, " ");
3599 uint32 g_id
= (uint32
)atoi(px
);
3603 char* px2
= strtok(NULL
, " ");
3607 else if (strncmp(px2
,"horde",6)==0)
3609 else if (strncmp(px2
,"alliance",9)==0)
3614 WorldSafeLocsEntry
const* graveyard
= sWorldSafeLocsStore
.LookupEntry(g_id
);
3618 PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST
, g_id
);
3619 SetSentErrorMessage(true);
3623 Player
* player
= m_session
->GetPlayer();
3625 uint32 zoneId
= player
->GetZoneId();
3627 AreaTableEntry
const *areaEntry
= GetAreaEntryByAreaID(zoneId
);
3628 if(!areaEntry
|| areaEntry
->zone
!=0 )
3630 PSendSysMessage(LANG_COMMAND_GRAVEYARDWRONGZONE
, g_id
,zoneId
);
3631 SetSentErrorMessage(true);
3635 if(sObjectMgr
.AddGraveYardLink(g_id
,zoneId
,g_team
))
3636 PSendSysMessage(LANG_COMMAND_GRAVEYARDLINKED
, g_id
,zoneId
);
3638 PSendSysMessage(LANG_COMMAND_GRAVEYARDALRLINKED
, g_id
,zoneId
);
3643 bool ChatHandler::HandleNearGraveCommand(const char* args
)
3647 size_t argslen
= strlen(args
);
3651 else if (strncmp((char*)args
,"horde",argslen
)==0)
3653 else if (strncmp((char*)args
,"alliance",argslen
)==0)
3658 Player
* player
= m_session
->GetPlayer();
3659 uint32 zone_id
= player
->GetZoneId();
3661 WorldSafeLocsEntry
const* graveyard
= sObjectMgr
.GetClosestGraveYard(
3662 player
->GetPositionX(), player
->GetPositionY(), player
->GetPositionZ(),player
->GetMapId(),g_team
);
3666 uint32 g_id
= graveyard
->ID
;
3668 GraveYardData
const* data
= sObjectMgr
.FindGraveYardData(g_id
,zone_id
);
3671 PSendSysMessage(LANG_COMMAND_GRAVEYARDERROR
,g_id
);
3672 SetSentErrorMessage(true);
3676 g_team
= data
->team
;
3678 std::string team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_NOTEAM
);
3681 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ANY
);
3682 else if(g_team
== HORDE
)
3683 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE
);
3684 else if(g_team
== ALLIANCE
)
3685 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE
);
3687 PSendSysMessage(LANG_COMMAND_GRAVEYARDNEAREST
, g_id
,team_name
.c_str(),zone_id
);
3691 std::string team_name
;
3694 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ANY
);
3695 else if(g_team
== HORDE
)
3696 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE
);
3697 else if(g_team
== ALLIANCE
)
3698 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE
);
3700 if(g_team
== ~uint32(0))
3701 PSendSysMessage(LANG_COMMAND_ZONENOGRAVEYARDS
, zone_id
);
3703 PSendSysMessage(LANG_COMMAND_ZONENOGRAFACTION
, zone_id
,team_name
.c_str());
3709 //-----------------------Npc Commands-----------------------
3710 bool ChatHandler::HandleNpcAllowMovementCommand(const char* /*args*/)
3712 if(sWorld
.getAllowMovement())
3714 sWorld
.SetAllowMovement(false);
3715 SendSysMessage(LANG_CREATURE_MOVE_DISABLED
);
3719 sWorld
.SetAllowMovement(true);
3720 SendSysMessage(LANG_CREATURE_MOVE_ENABLED
);
3725 bool ChatHandler::HandleNpcChangeEntryCommand(const char *args
)
3730 uint32 newEntryNum
= atoi(args
);
3734 Unit
* unit
= getSelectedUnit();
3735 if(!unit
|| unit
->GetTypeId() != TYPEID_UNIT
)
3737 SendSysMessage(LANG_SELECT_CREATURE
);
3738 SetSentErrorMessage(true);
3741 Creature
* creature
= (Creature
*)unit
;
3742 if(creature
->UpdateEntry(newEntryNum
))
3743 SendSysMessage(LANG_DONE
);
3745 SendSysMessage(LANG_ERROR
);
3749 bool ChatHandler::HandleNpcInfoCommand(const char* /*args*/)
3751 Creature
* target
= getSelectedCreature();
3755 SendSysMessage(LANG_SELECT_CREATURE
);
3756 SetSentErrorMessage(true);
3760 uint32 faction
= target
->getFaction();
3761 uint32 npcflags
= target
->GetUInt32Value(UNIT_NPC_FLAGS
);
3762 uint32 displayid
= target
->GetDisplayId();
3763 uint32 nativeid
= target
->GetNativeDisplayId();
3764 uint32 Entry
= target
->GetEntry();
3765 CreatureInfo
const* cInfo
= target
->GetCreatureInfo();
3767 int32 curRespawnDelay
= target
->GetRespawnTimeEx()-time(NULL
);
3768 if(curRespawnDelay
< 0)
3769 curRespawnDelay
= 0;
3770 std::string curRespawnDelayStr
= secsToTimeString(curRespawnDelay
,true);
3771 std::string defRespawnDelayStr
= secsToTimeString(target
->GetRespawnDelay(),true);
3773 PSendSysMessage(LANG_NPCINFO_CHAR
, target
->GetDBTableGUIDLow(), faction
, npcflags
, Entry
, displayid
, nativeid
);
3774 PSendSysMessage(LANG_NPCINFO_LEVEL
, target
->getLevel());
3775 PSendSysMessage(LANG_NPCINFO_HEALTH
,target
->GetCreateHealth(), target
->GetMaxHealth(), target
->GetHealth());
3776 PSendSysMessage(LANG_NPCINFO_FLAGS
, target
->GetUInt32Value(UNIT_FIELD_FLAGS
), target
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
), target
->getFaction());
3777 PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES
, defRespawnDelayStr
.c_str(),curRespawnDelayStr
.c_str());
3778 PSendSysMessage(LANG_NPCINFO_LOOT
, cInfo
->lootid
,cInfo
->pickpocketLootId
,cInfo
->SkinLootId
);
3779 PSendSysMessage(LANG_NPCINFO_DUNGEON_ID
, target
->GetInstanceId());
3780 PSendSysMessage(LANG_NPCINFO_POSITION
,float(target
->GetPositionX()), float(target
->GetPositionY()), float(target
->GetPositionZ()));
3782 if ((npcflags
& UNIT_NPC_FLAG_VENDOR
) )
3784 SendSysMessage(LANG_NPCINFO_VENDOR
);
3786 if ((npcflags
& UNIT_NPC_FLAG_TRAINER
) )
3788 SendSysMessage(LANG_NPCINFO_TRAINER
);
3795 bool ChatHandler::HandleNpcPlayEmoteCommand(const char* args
)
3797 uint32 emote
= atoi((char*)args
);
3799 Creature
* target
= getSelectedCreature();
3802 SendSysMessage(LANG_SELECT_CREATURE
);
3803 SetSentErrorMessage(true);
3807 target
->SetUInt32Value(UNIT_NPC_EMOTESTATE
,emote
);
3812 //TODO: NpcCommands that needs to be fixed :
3814 bool ChatHandler::HandleNpcAddWeaponCommand(const char* /*args*/)
3819 uint64 guid = m_session->GetPlayer()->GetSelection();
3822 SendSysMessage(LANG_NO_SELECTION);
3826 Creature *pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
3830 SendSysMessage(LANG_SELECT_CREATURE);
3834 char* pSlotID = strtok((char*)args, " ");
3838 char* pItemID = strtok(NULL, " ");
3842 uint32 ItemID = atoi(pItemID);
3843 uint32 SlotID = atoi(pSlotID);
3845 ItemPrototype* tmpItem = ObjectMgr::GetItemPrototype(ItemID);
3853 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID);
3857 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID);
3861 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID);
3865 PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST,SlotID);
3871 PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT,ItemID,tmpItem->Name1,SlotID);
3875 PSendSysMessage(LANG_ITEM_NOT_FOUND,ItemID);
3881 //----------------------------------------------------------
3883 bool ChatHandler::HandleExploreCheatCommand(const char* args
)
3888 int flag
= atoi((char*)args
);
3890 Player
*chr
= getSelectedPlayer();
3893 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3894 SetSentErrorMessage(true);
3900 PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL
, GetNameLink(chr
).c_str());
3901 if (needReportToTarget(chr
))
3902 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_EXPLORE_SET_ALL
,GetNameLink().c_str());
3906 PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING
, GetNameLink(chr
).c_str());
3907 if (needReportToTarget(chr
))
3908 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_EXPLORE_SET_NOTHING
,GetNameLink().c_str());
3911 for (uint8 i
=0; i
<128; ++i
)
3915 m_session
->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1
+i
,0xFFFFFFFF);
3919 m_session
->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1
+i
,0);
3926 bool ChatHandler::HandleHoverCommand(const char* args
)
3928 char* px
= strtok((char*)args
, " ");
3935 m_session
->GetPlayer()->SetHover(flag
);
3938 SendSysMessage(LANG_HOVER_ENABLED
);
3940 SendSysMessage(LANG_HOVER_DISABLED
);
3945 void ChatHandler::HandleCharacterLevel(Player
* player
, uint64 player_guid
, uint32 oldlevel
, uint32 newlevel
)
3949 player
->GiveLevel(newlevel
);
3950 player
->InitTalentForLevel();
3951 player
->SetUInt32Value(PLAYER_XP
,0);
3953 if(needReportToTarget(player
))
3955 if(oldlevel
== newlevel
)
3956 ChatHandler(player
).PSendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET
,GetNameLink().c_str());
3957 else if(oldlevel
< newlevel
)
3958 ChatHandler(player
).PSendSysMessage(LANG_YOURS_LEVEL_UP
,GetNameLink().c_str(),newlevel
);
3959 else // if(oldlevel > newlevel)
3960 ChatHandler(player
).PSendSysMessage(LANG_YOURS_LEVEL_DOWN
,GetNameLink().c_str(),newlevel
);
3965 // update level and XP at level, all other will be updated at loading
3966 CharacterDatabase
.PExecute("UPDATE characters SET level = '%u', xp = 0 WHERE guid = '%u'", newlevel
, GUID_LOPART(player_guid
));
3970 bool ChatHandler::HandleCharacterLevelCommand(const char* args
)
3974 extractOptFirstArg((char*)args
,&nameStr
,&levelStr
);
3978 // exception opt second arg: .character level $name
3979 if(isalpha(levelStr
[0]))
3982 levelStr
= NULL
; // current level will used
3987 std::string target_name
;
3988 if(!extractPlayerTarget(nameStr
,&target
,&target_guid
,&target_name
))
3991 int32 oldlevel
= target
? target
->getLevel() : Player::GetLevelFromDB(target_guid
);
3992 int32 newlevel
= levelStr
? atoi(levelStr
) : oldlevel
;
3995 return false; // invalid level
3997 if(newlevel
> STRONG_MAX_LEVEL
) // hardcoded maximum level
3998 newlevel
= STRONG_MAX_LEVEL
;
4000 HandleCharacterLevel(target
,target_guid
,oldlevel
,newlevel
);
4002 if(!m_session
|| m_session
->GetPlayer() != target
) // including player==NULL
4004 std::string nameLink
= playerLink(target_name
);
4005 PSendSysMessage(LANG_YOU_CHANGE_LVL
,nameLink
.c_str(),newlevel
);
4011 bool ChatHandler::HandleLevelUpCommand(const char* args
)
4015 extractOptFirstArg((char*)args
,&nameStr
,&levelStr
);
4017 // exception opt second arg: .character level $name
4018 if(levelStr
&& isalpha(levelStr
[0]))
4021 levelStr
= NULL
; // current level will used
4026 std::string target_name
;
4027 if(!extractPlayerTarget(nameStr
,&target
,&target_guid
,&target_name
))
4030 int32 oldlevel
= target
? target
->getLevel() : Player::GetLevelFromDB(target_guid
);
4031 int32 addlevel
= levelStr
? atoi(levelStr
) : 1;
4032 int32 newlevel
= oldlevel
+ addlevel
;
4037 if(newlevel
> STRONG_MAX_LEVEL
) // hardcoded maximum level
4038 newlevel
= STRONG_MAX_LEVEL
;
4040 HandleCharacterLevel(target
,target_guid
,oldlevel
,newlevel
);
4042 if(!m_session
|| m_session
->GetPlayer() != target
) // including chr==NULL
4044 std::string nameLink
= playerLink(target_name
);
4045 PSendSysMessage(LANG_YOU_CHANGE_LVL
,nameLink
.c_str(),newlevel
);
4051 bool ChatHandler::HandleShowAreaCommand(const char* args
)
4056 Player
*chr
= getSelectedPlayer();
4059 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4060 SetSentErrorMessage(true);
4064 int area
= GetAreaFlagByAreaID(atoi((char*)args
));
4065 int offset
= area
/ 32;
4066 uint32 val
= (uint32
)(1 << (area
% 32));
4068 if(area
<0 || offset
>= 128)
4070 SendSysMessage(LANG_BAD_VALUE
);
4071 SetSentErrorMessage(true);
4075 uint32 currFields
= chr
->GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
4076 chr
->SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
| val
));
4078 SendSysMessage(LANG_EXPLORE_AREA
);
4082 bool ChatHandler::HandleHideAreaCommand(const char* args
)
4087 Player
*chr
= getSelectedPlayer();
4090 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4091 SetSentErrorMessage(true);
4095 int area
= GetAreaFlagByAreaID(atoi((char*)args
));
4096 int offset
= area
/ 32;
4097 uint32 val
= (uint32
)(1 << (area
% 32));
4099 if(area
<0 || offset
>= 128)
4101 SendSysMessage(LANG_BAD_VALUE
);
4102 SetSentErrorMessage(true);
4106 uint32 currFields
= chr
->GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
4107 chr
->SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
^ val
));
4109 SendSysMessage(LANG_UNEXPLORE_AREA
);
4113 bool ChatHandler::HandleBankCommand(const char* /*args*/)
4115 m_session
->SendShowBank( m_session
->GetPlayer()->GetGUID() );
4120 bool ChatHandler::HandleChangeWeather(const char* args
)
4126 if (!sWorld
.getConfig(CONFIG_WEATHER
))
4128 SendSysMessage(LANG_WEATHER_DISABLED
);
4129 SetSentErrorMessage(true);
4133 //*Change the weather of a cell
4134 char* px
= strtok((char*)args
, " ");
4135 char* py
= strtok(NULL
, " ");
4140 uint32 type
= (uint32
)atoi(px
); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
4141 float grade
= (float)atof(py
); //0 to 1, sending -1 is instand good weather
4143 Player
*player
= m_session
->GetPlayer();
4144 uint32 zoneid
= player
->GetZoneId();
4146 Weather
* wth
= sWorld
.FindWeather(zoneid
);
4149 wth
= sWorld
.AddWeather(zoneid
);
4152 SendSysMessage(LANG_NO_WEATHER
);
4153 SetSentErrorMessage(true);
4157 wth
->SetWeather(WeatherType(type
), grade
);
4162 bool ChatHandler::HandleTeleAddCommand(const char * args
)
4167 Player
*player
=m_session
->GetPlayer();
4171 std::string name
= args
;
4173 if(sObjectMgr
.GetGameTele(name
))
4175 SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST
);
4176 SetSentErrorMessage(true);
4181 tele
.position_x
= player
->GetPositionX();
4182 tele
.position_y
= player
->GetPositionY();
4183 tele
.position_z
= player
->GetPositionZ();
4184 tele
.orientation
= player
->GetOrientation();
4185 tele
.mapId
= player
->GetMapId();
4188 if(sObjectMgr
.AddGameTele(tele
))
4190 SendSysMessage(LANG_COMMAND_TP_ADDED
);
4194 SendSysMessage(LANG_COMMAND_TP_ADDEDERR
);
4195 SetSentErrorMessage(true);
4202 bool ChatHandler::HandleTeleDelCommand(const char * args
)
4207 std::string name
= args
;
4209 if(!sObjectMgr
.DeleteGameTele(name
))
4211 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
4212 SetSentErrorMessage(true);
4216 SendSysMessage(LANG_COMMAND_TP_DELETED
);
4220 bool ChatHandler::HandleListAurasCommand (const char * /*args*/)
4222 Unit
*unit
= getSelectedUnit();
4225 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4226 SetSentErrorMessage(true);
4230 char const* talentStr
= GetMangosString(LANG_TALENT
);
4231 char const* passiveStr
= GetMangosString(LANG_PASSIVE
);
4233 Unit::AuraMap
const& uAuras
= unit
->GetAuras();
4234 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS
, uAuras
.size());
4235 for (Unit::AuraMap::const_iterator itr
= uAuras
.begin(); itr
!= uAuras
.end(); ++itr
)
4237 bool talent
= GetTalentSpellCost(itr
->second
->GetId()) > 0;
4239 char const* name
= itr
->second
->GetSpellProto()->SpellName
[GetSessionDbcLocale()];
4243 std::ostringstream ss_name
;
4244 ss_name
<< "|cffffffff|Hspell:" << itr
->second
->GetId() << "|h[" << name
<< "]|h|r";
4246 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL
, itr
->second
->GetId(), itr
->second
->GetEffIndex(),
4247 itr
->second
->GetModifier()->m_auraname
, itr
->second
->GetAuraDuration(), itr
->second
->GetAuraMaxDuration(),
4248 ss_name
.str().c_str(),
4249 (itr
->second
->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4250 IS_PLAYER_GUID(itr
->second
->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr
->second
->GetCasterGUID()));
4254 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL
, itr
->second
->GetId(), itr
->second
->GetEffIndex(),
4255 itr
->second
->GetModifier()->m_auraname
, itr
->second
->GetAuraDuration(), itr
->second
->GetAuraMaxDuration(),
4257 (itr
->second
->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4258 IS_PLAYER_GUID(itr
->second
->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr
->second
->GetCasterGUID()));
4261 for (int i
= 0; i
< TOTAL_AURAS
; ++i
)
4263 Unit::AuraList
const& uAuraList
= unit
->GetAurasByType(AuraType(i
));
4264 if (uAuraList
.empty()) continue;
4265 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE
, uAuraList
.size(), i
);
4266 for (Unit::AuraList::const_iterator itr
= uAuraList
.begin(); itr
!= uAuraList
.end(); ++itr
)
4268 bool talent
= GetTalentSpellCost((*itr
)->GetId()) > 0;
4270 char const* name
= (*itr
)->GetSpellProto()->SpellName
[GetSessionDbcLocale()];
4274 std::ostringstream ss_name
;
4275 ss_name
<< "|cffffffff|Hspell:" << (*itr
)->GetId() << "|h[" << name
<< "]|h|r";
4277 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE
, (*itr
)->GetId(), (*itr
)->GetEffIndex(),
4278 ss_name
.str().c_str(),((*itr
)->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4279 IS_PLAYER_GUID((*itr
)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr
)->GetCasterGUID()));
4283 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE
, (*itr
)->GetId(), (*itr
)->GetEffIndex(),
4284 name
,((*itr
)->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4285 IS_PLAYER_GUID((*itr
)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr
)->GetCasterGUID()));
4292 bool ChatHandler::HandleResetAchievementsCommand (const char * args
)
4296 if (!extractPlayerTarget((char*)args
,&target
,&target_guid
))
4300 target
->GetAchievementMgr().Reset();
4302 AchievementMgr::DeleteFromDB(GUID_LOPART(target_guid
));
4307 bool ChatHandler::HandleResetHonorCommand (const char * args
)
4310 if (!extractPlayerTarget((char*)args
,&target
))
4313 target
->SetUInt32Value(PLAYER_FIELD_KILLS
, 0);
4314 target
->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS
, 0);
4315 target
->SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY
, 0);
4316 target
->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION
, 0);
4317 target
->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION
, 0);
4318 target
->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_EARN_HONORABLE_KILL
);
4323 static bool HandleResetStatsOrLevelHelper(Player
* player
)
4325 ChrClassesEntry
const* cEntry
= sChrClassesStore
.LookupEntry(player
->getClass());
4328 sLog
.outError("Class %u not found in DBC (Wrong DBC files?)",player
->getClass());
4332 uint8 powertype
= cEntry
->powerType
;
4334 // reset m_form if no aura
4335 if(!player
->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT
))
4336 player
->m_form
= FORM_NONE
;
4338 player
->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS
, DEFAULT_WORLD_OBJECT_SIZE
);
4339 player
->SetFloatValue(UNIT_FIELD_COMBATREACH
, 1.5f
);
4341 player
->setFactionForRace(player
->getRace());
4343 player
->SetUInt32Value(UNIT_FIELD_BYTES_0
, ( ( player
->getRace() ) | ( player
->getClass() << 8 ) | ( player
->getGender() << 16 ) | ( powertype
<< 24 ) ) );
4345 // reset only if player not in some form;
4346 if(player
->m_form
==FORM_NONE
)
4347 player
->InitDisplayIds();
4349 player
->SetByteValue(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_PVP
);
4350 player
->SetByteValue(UNIT_FIELD_BYTES_2
, 3, player
->m_form
);
4352 player
->SetUInt32Value(UNIT_FIELD_FLAGS
, UNIT_FLAG_PVP_ATTACKABLE
);
4354 //-1 is default value
4355 player
->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX
, uint32(-1));
4357 //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000 );
4361 bool ChatHandler::HandleResetLevelCommand(const char * args
)
4364 if(!extractPlayerTarget((char*)args
,&target
))
4367 if(!HandleResetStatsOrLevelHelper(target
))
4370 // set starting level
4371 uint32 start_level
= target
->getClass() != CLASS_DEATH_KNIGHT
4372 ? sWorld
.getConfig(CONFIG_START_PLAYER_LEVEL
)
4373 : sWorld
.getConfig(CONFIG_START_HEROIC_PLAYER_LEVEL
);
4375 target
->_ApplyAllLevelScaleItemMods(false);
4377 target
->SetLevel(start_level
);
4378 target
->InitRunes();
4379 target
->InitStatsForLevel(true);
4380 target
->InitTaxiNodesForLevel();
4381 target
->InitGlyphsForLevel();
4382 target
->InitTalentForLevel();
4383 target
->SetUInt32Value(PLAYER_XP
,0);
4385 target
->_ApplyAllLevelScaleItemMods(true);
4387 // reset level for pet
4388 if(Pet
* pet
= target
->GetPet())
4389 pet
->SynchronizeLevelWithOwner();
4394 bool ChatHandler::HandleResetStatsCommand(const char * args
)
4397 if (!extractPlayerTarget((char*)args
,&target
))
4400 if (!HandleResetStatsOrLevelHelper(target
))
4403 target
->InitRunes();
4404 target
->InitStatsForLevel(true);
4405 target
->InitTaxiNodesForLevel();
4406 target
->InitGlyphsForLevel();
4407 target
->InitTalentForLevel();
4412 bool ChatHandler::HandleResetSpellsCommand(const char * args
)
4416 std::string target_name
;
4417 if(!extractPlayerTarget((char*)args
,&target
,&target_guid
,&target_name
))
4422 target
->resetSpells();
4424 ChatHandler(target
).SendSysMessage(LANG_RESET_SPELLS
);
4425 if(!m_session
|| m_session
->GetPlayer()!=target
)
4426 PSendSysMessage(LANG_RESET_SPELLS_ONLINE
,GetNameLink(target
).c_str());
4430 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS
), GUID_LOPART(target_guid
));
4431 PSendSysMessage(LANG_RESET_SPELLS_OFFLINE
,target_name
.c_str());
4437 bool ChatHandler::HandleResetTalentsCommand(const char * args
)
4441 std::string target_name
;
4442 if (!extractPlayerTarget((char*)args
,&target
,&target_guid
,&target_name
))
4444 // Try reset talents as Hunter Pet
4445 Creature
* creature
= getSelectedCreature();
4446 if (!*args
&& creature
&& creature
->isPet())
4448 Unit
*owner
= creature
->GetOwner();
4449 if(owner
&& owner
->GetTypeId() == TYPEID_PLAYER
&& ((Pet
*)creature
)->IsPermanentPetFor((Player
*)owner
))
4451 ((Pet
*)creature
)->resetTalents(true);
4452 ((Player
*)owner
)->SendTalentsInfoData(true);
4454 ChatHandler((Player
*)owner
).SendSysMessage(LANG_RESET_PET_TALENTS
);
4455 if(!m_session
|| m_session
->GetPlayer()!=((Player
*)owner
))
4456 PSendSysMessage(LANG_RESET_PET_TALENTS_ONLINE
,GetNameLink((Player
*)owner
).c_str());
4461 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4462 SetSentErrorMessage(true);
4468 target
->resetTalents(true);
4469 target
->SendTalentsInfoData(false);
4470 ChatHandler(target
).SendSysMessage(LANG_RESET_TALENTS
);
4471 if (!m_session
|| m_session
->GetPlayer()!=target
)
4472 PSendSysMessage(LANG_RESET_TALENTS_ONLINE
,GetNameLink(target
).c_str());
4474 Pet
* pet
= target
->GetPet();
4475 Pet::resetTalentsForAllPetsOf(target
,pet
);
4477 target
->SendTalentsInfoData(true);
4480 else if (target_guid
)
4482 uint32 at_flags
= AT_LOGIN_NONE
| AT_LOGIN_RESET_PET_TALENTS
;
4483 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",at_flags
, GUID_LOPART(target_guid
) );
4484 std::string nameLink
= playerLink(target_name
);
4485 PSendSysMessage(LANG_RESET_TALENTS_OFFLINE
,nameLink
.c_str());
4489 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4490 SetSentErrorMessage(true);
4494 bool ChatHandler::HandleResetAllCommand(const char * args
)
4499 std::string casename
= args
;
4501 AtLoginFlags atLogin
;
4503 // Command specially created as single command to prevent using short case names
4504 if(casename
=="spells")
4506 atLogin
= AT_LOGIN_RESET_SPELLS
;
4507 sWorld
.SendWorldText(LANG_RESETALL_SPELLS
);
4509 SendSysMessage(LANG_RESETALL_SPELLS
);
4511 else if(casename
=="talents")
4513 atLogin
= AtLoginFlags(AT_LOGIN_RESET_TALENTS
| AT_LOGIN_RESET_PET_TALENTS
);
4514 sWorld
.SendWorldText(LANG_RESETALL_TALENTS
);
4516 SendSysMessage(LANG_RESETALL_TALENTS
);
4520 PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE
,args
);
4521 SetSentErrorMessage(true);
4525 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE (at_login & '%u') = '0'",atLogin
,atLogin
);
4526 HashMapHolder
<Player
>::MapType
const& plist
= sObjectAccessor
.GetPlayers();
4527 for(HashMapHolder
<Player
>::MapType::const_iterator itr
= plist
.begin(); itr
!= plist
.end(); ++itr
)
4528 itr
->second
->SetAtLoginFlag(atLogin
);
4533 bool ChatHandler::HandleServerShutDownCancelCommand(const char* /*args*/)
4535 sWorld
.ShutdownCancel();
4539 bool ChatHandler::HandleServerShutDownCommand(const char* args
)
4544 char* time_str
= strtok ((char*) args
, " ");
4545 char* exitcode_str
= strtok (NULL
, "");
4547 int32 time
= atoi (time_str
);
4549 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4550 if ((time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0')) || time
< 0)
4555 int32 exitcode
= atoi (exitcode_str
);
4557 // Handle atoi() errors
4558 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4561 // Exit code should be in range of 0-125, 126-255 is used
4562 // in many shells for their own return codes and code > 255
4563 // is not supported in many others
4564 if (exitcode
< 0 || exitcode
> 125)
4567 sWorld
.ShutdownServ (time
, 0, exitcode
);
4570 sWorld
.ShutdownServ(time
,0,SHUTDOWN_EXIT_CODE
);
4574 bool ChatHandler::HandleServerRestartCommand(const char* args
)
4579 char* time_str
= strtok ((char*) args
, " ");
4580 char* exitcode_str
= strtok (NULL
, "");
4582 int32 time
= atoi (time_str
);
4584 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4585 if ((time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0')) || time
< 0)
4590 int32 exitcode
= atoi (exitcode_str
);
4592 // Handle atoi() errors
4593 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4596 // Exit code should be in range of 0-125, 126-255 is used
4597 // in many shells for their own return codes and code > 255
4598 // is not supported in many others
4599 if (exitcode
< 0 || exitcode
> 125)
4602 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_RESTART
, exitcode
);
4605 sWorld
.ShutdownServ(time
, SHUTDOWN_MASK_RESTART
, RESTART_EXIT_CODE
);
4609 bool ChatHandler::HandleServerIdleRestartCommand(const char* args
)
4614 char* time_str
= strtok ((char*) args
, " ");
4615 char* exitcode_str
= strtok (NULL
, "");
4617 int32 time
= atoi (time_str
);
4619 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4620 if ((time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0')) || time
< 0)
4625 int32 exitcode
= atoi (exitcode_str
);
4627 // Handle atoi() errors
4628 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4631 // Exit code should be in range of 0-125, 126-255 is used
4632 // in many shells for their own return codes and code > 255
4633 // is not supported in many others
4634 if (exitcode
< 0 || exitcode
> 125)
4637 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_RESTART
|SHUTDOWN_MASK_IDLE
, exitcode
);
4640 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_RESTART
|SHUTDOWN_MASK_IDLE
,RESTART_EXIT_CODE
);
4644 bool ChatHandler::HandleServerIdleShutDownCommand(const char* args
)
4649 char* time_str
= strtok ((char*) args
, " ");
4650 char* exitcode_str
= strtok (NULL
, "");
4652 int32 time
= atoi (time_str
);
4654 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4655 if ((time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0')) || time
< 0)
4660 int32 exitcode
= atoi (exitcode_str
);
4662 // Handle atoi() errors
4663 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4666 // Exit code should be in range of 0-125, 126-255 is used
4667 // in many shells for their own return codes and code > 255
4668 // is not supported in many others
4669 if (exitcode
< 0 || exitcode
> 125)
4672 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_IDLE
, exitcode
);
4675 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_IDLE
,SHUTDOWN_EXIT_CODE
);
4679 bool ChatHandler::HandleQuestAdd(const char* args
)
4681 Player
* player
= getSelectedPlayer();
4684 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4685 SetSentErrorMessage(true);
4689 // .addquest #entry'
4690 // number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
4691 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4695 uint32 entry
= atol(cId
);
4697 Quest
const* pQuest
= sObjectMgr
.GetQuestTemplate(entry
);
4701 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
,entry
);
4702 SetSentErrorMessage(true);
4706 // check item starting quest (it can work incorrectly if added without item in inventory)
4707 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
4709 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
4713 if (pProto
->StartQuest
== entry
)
4715 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM
, entry
, pProto
->ItemId
);
4716 SetSentErrorMessage(true);
4721 // ok, normal (creature/GO starting) quest
4722 if( player
->CanAddQuest( pQuest
, true ) )
4724 player
->AddQuest( pQuest
, NULL
);
4726 if ( player
->CanCompleteQuest( entry
) )
4727 player
->CompleteQuest( entry
);
4733 bool ChatHandler::HandleQuestRemove(const char* args
)
4735 Player
* player
= getSelectedPlayer();
4738 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4739 SetSentErrorMessage(true);
4743 // .removequest #entry'
4744 // number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
4745 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4749 uint32 entry
= atol(cId
);
4751 Quest
const* pQuest
= sObjectMgr
.GetQuestTemplate(entry
);
4755 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
4756 SetSentErrorMessage(true);
4760 // remove all quest entries for 'entry' from quest log
4761 for(uint8 slot
= 0; slot
< MAX_QUEST_LOG_SIZE
; ++slot
)
4763 uint32 quest
= player
->GetQuestSlotQuestId(slot
);
4766 player
->SetQuestSlot(slot
,0);
4768 // we ignore unequippable quest items in this case, its' still be equipped
4769 player
->TakeQuestSourceItem( quest
, false );
4773 // set quest status to not started (will updated in DB at next save)
4774 player
->SetQuestStatus( entry
, QUEST_STATUS_NONE
);
4776 // reset rewarded for restart repeatable quest
4777 player
->getQuestStatusMap()[entry
].m_rewarded
= false;
4779 SendSysMessage(LANG_COMMAND_QUEST_REMOVED
);
4783 bool ChatHandler::HandleQuestComplete(const char* args
)
4785 Player
* player
= getSelectedPlayer();
4788 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4789 SetSentErrorMessage(true);
4793 // .quest complete #entry
4794 // number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
4795 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4799 uint32 entry
= atol(cId
);
4801 Quest
const* pQuest
= sObjectMgr
.GetQuestTemplate(entry
);
4803 // If player doesn't have the quest
4804 if(!pQuest
|| player
->GetQuestStatus(entry
) == QUEST_STATUS_NONE
)
4806 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
4807 SetSentErrorMessage(true);
4811 // Add quest items for quests that require items
4812 for(uint8 x
= 0; x
< QUEST_ITEM_OBJECTIVES_COUNT
; ++x
)
4814 uint32 id
= pQuest
->ReqItemId
[x
];
4815 uint32 count
= pQuest
->ReqItemCount
[x
];
4819 uint32 curItemCount
= player
->GetItemCount(id
,true);
4821 ItemPosCountVec dest
;
4822 uint8 msg
= player
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, id
, count
- curItemCount
);
4823 if( msg
== EQUIP_ERR_OK
)
4825 Item
* item
= player
->StoreNewItem( dest
, id
, true);
4826 player
->SendNewItem(item
,count
-curItemCount
, true, false);
4830 // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
4831 for(uint8 i
= 0; i
< QUEST_OBJECTIVES_COUNT
; ++i
)
4833 uint32 creature
= pQuest
->ReqCreatureOrGOId
[i
];
4834 uint32 creaturecount
= pQuest
->ReqCreatureOrGOCount
[i
];
4836 if(uint32 spell_id
= pQuest
->ReqSpell
[i
])
4838 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4839 player
->CastedCreatureOrGO(creature
,0,spell_id
);
4841 else if(creature
> 0)
4843 if(CreatureInfo
const* cInfo
= ObjectMgr::GetCreatureTemplate(creature
))
4844 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4845 player
->KilledMonster(cInfo
,0);
4847 else if(creature
< 0)
4849 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4850 player
->CastedCreatureOrGO(creature
,0,0);
4854 // If the quest requires reputation to complete
4855 if(uint32 repFaction
= pQuest
->GetRepObjectiveFaction())
4857 uint32 repValue
= pQuest
->GetRepObjectiveValue();
4858 uint32 curRep
= player
->GetReputationMgr().GetReputation(repFaction
);
4859 if(curRep
< repValue
)
4860 if(FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry(repFaction
))
4861 player
->GetReputationMgr().SetReputation(factionEntry
,repValue
);
4864 // If the quest requires money
4865 int32 ReqOrRewMoney
= pQuest
->GetRewOrReqMoney();
4866 if(ReqOrRewMoney
< 0)
4867 player
->ModifyMoney(-ReqOrRewMoney
);
4869 player
->CompleteQuest(entry
);
4873 bool ChatHandler::HandleBanAccountCommand(const char* args
)
4875 return HandleBanHelper(BAN_ACCOUNT
,args
);
4878 bool ChatHandler::HandleBanCharacterCommand(const char* args
)
4880 return HandleBanHelper(BAN_CHARACTER
,args
);
4883 bool ChatHandler::HandleBanIPCommand(const char* args
)
4885 return HandleBanHelper(BAN_IP
,args
);
4888 bool ChatHandler::HandleBanHelper(BanMode mode
, const char* args
)
4893 char* cnameOrIP
= strtok ((char*)args
, " ");
4897 std::string nameOrIP
= cnameOrIP
;
4899 char* duration
= strtok (NULL
," ");
4900 if(!duration
|| !atoi(duration
))
4903 char* reason
= strtok (NULL
,"");
4910 if (!AccountMgr::normalizeString(nameOrIP
))
4912 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
4913 SetSentErrorMessage(true);
4918 if(!normalizePlayerName(nameOrIP
))
4920 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4921 SetSentErrorMessage(true);
4926 if(!IsIPAddress(nameOrIP
.c_str()))
4931 switch(sWorld
.BanAccount(mode
, nameOrIP
, duration
, reason
,m_session
? m_session
->GetPlayerName() : ""))
4934 if(atoi(duration
)>0)
4935 PSendSysMessage(LANG_BAN_YOUBANNED
,nameOrIP
.c_str(),secsToTimeString(TimeStringToSecs(duration
),true).c_str(),reason
);
4937 PSendSysMessage(LANG_BAN_YOUPERMBANNED
,nameOrIP
.c_str(),reason
);
4939 case BAN_SYNTAX_ERROR
:
4945 PSendSysMessage(LANG_BAN_NOTFOUND
,"account",nameOrIP
.c_str());
4948 PSendSysMessage(LANG_BAN_NOTFOUND
,"character",nameOrIP
.c_str());
4951 PSendSysMessage(LANG_BAN_NOTFOUND
,"ip",nameOrIP
.c_str());
4954 SetSentErrorMessage(true);
4961 bool ChatHandler::HandleUnBanAccountCommand(const char* args
)
4963 return HandleUnBanHelper(BAN_ACCOUNT
,args
);
4966 bool ChatHandler::HandleUnBanCharacterCommand(const char* args
)
4968 return HandleUnBanHelper(BAN_CHARACTER
,args
);
4971 bool ChatHandler::HandleUnBanIPCommand(const char* args
)
4973 return HandleUnBanHelper(BAN_IP
,args
);
4976 bool ChatHandler::HandleUnBanHelper(BanMode mode
, const char* args
)
4981 char* cnameOrIP
= strtok ((char*)args
, " ");
4985 std::string nameOrIP
= cnameOrIP
;
4990 if (!AccountMgr::normalizeString(nameOrIP
))
4992 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
4993 SetSentErrorMessage(true);
4998 if(!normalizePlayerName(nameOrIP
))
5000 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5001 SetSentErrorMessage(true);
5006 if(!IsIPAddress(nameOrIP
.c_str()))
5011 if(sWorld
.RemoveBanAccount(mode
,nameOrIP
))
5012 PSendSysMessage(LANG_UNBAN_UNBANNED
,nameOrIP
.c_str());
5014 PSendSysMessage(LANG_UNBAN_ERROR
,nameOrIP
.c_str());
5019 bool ChatHandler::HandleBanInfoAccountCommand(const char* args
)
5024 char* cname
= strtok((char*)args
, "");
5028 std::string account_name
= cname
;
5029 if (!AccountMgr::normalizeString(account_name
))
5031 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5032 SetSentErrorMessage(true);
5036 uint32 accountid
= sAccountMgr
.GetId(account_name
);
5039 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5043 return HandleBanInfoHelper(accountid
,account_name
.c_str());
5046 bool ChatHandler::HandleBanInfoCharacterCommand(const char* args
)
5050 if (!extractPlayerTarget((char*)args
,&target
,&target_guid
))
5053 uint32 accountid
= target
? target
->GetSession()->GetAccountId() : sObjectMgr
.GetPlayerAccountIdByGUID(target_guid
);
5055 std::string accountname
;
5056 if (!sAccountMgr
.GetName(accountid
,accountname
))
5058 PSendSysMessage(LANG_BANINFO_NOCHARACTER
);
5062 return HandleBanInfoHelper(accountid
,accountname
.c_str());
5065 bool ChatHandler::HandleBanInfoHelper(uint32 accountid
, char const* accountname
)
5067 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
);
5070 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN
, accountname
);
5074 PSendSysMessage(LANG_BANINFO_BANHISTORY
,accountname
);
5077 Field
* fields
= result
->Fetch();
5079 time_t unbandate
= time_t(fields
[3].GetUInt64());
5080 bool active
= false;
5081 if(fields
[2].GetBool() && (fields
[1].GetUInt64() == (uint64
)0 ||unbandate
>= time(NULL
)) )
5083 bool permanent
= (fields
[1].GetUInt64() == (uint64
)0);
5084 std::string bantime
= permanent
?GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[1].GetUInt64(), true);
5085 PSendSysMessage(LANG_BANINFO_HISTORYENTRY
,
5086 fields
[0].GetString(), bantime
.c_str(), active
? GetMangosString(LANG_BANINFO_YES
):GetMangosString(LANG_BANINFO_NO
), fields
[4].GetString(), fields
[5].GetString());
5087 }while (result
->NextRow());
5093 bool ChatHandler::HandleBanInfoIPCommand(const char* args
)
5098 char* cIP
= strtok ((char*)args
, "");
5102 if (!IsIPAddress(cIP
))
5105 std::string IP
= cIP
;
5107 loginDatabase
.escape_string(IP
);
5108 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());
5111 PSendSysMessage(LANG_BANINFO_NOIP
);
5115 Field
*fields
= result
->Fetch();
5116 bool permanent
= !fields
[6].GetUInt64();
5117 PSendSysMessage(LANG_BANINFO_IPENTRY
,
5118 fields
[0].GetString(), fields
[1].GetString(), permanent
? GetMangosString(LANG_BANINFO_NEVER
):fields
[2].GetString(),
5119 permanent
? GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[3].GetUInt64(), true).c_str(), fields
[4].GetString(), fields
[5].GetString());
5124 bool ChatHandler::HandleBanListCharacterCommand(const char* args
)
5126 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5128 char* cFilter
= strtok ((char*)args
, " ");
5132 std::string filter
= cFilter
;
5133 loginDatabase
.escape_string(filter
);
5134 QueryResult
* result
= CharacterDatabase
.PQuery("SELECT account FROM characters WHERE name "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'"),filter
.c_str());
5137 PSendSysMessage(LANG_BANLIST_NOCHARACTER
);
5141 return HandleBanListHelper(result
);
5144 bool ChatHandler::HandleBanListAccountCommand(const char* args
)
5146 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5148 char* cFilter
= strtok((char*)args
, " ");
5149 std::string filter
= cFilter
? cFilter
: "";
5150 loginDatabase
.escape_string(filter
);
5152 QueryResult
* result
;
5156 result
= loginDatabase
.Query("SELECT account.id, username FROM account, account_banned"
5157 " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
5161 result
= loginDatabase
.PQuery("SELECT account.id, username FROM account, account_banned"
5162 " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
5168 PSendSysMessage(LANG_BANLIST_NOACCOUNT
);
5172 return HandleBanListHelper(result
);
5175 bool ChatHandler::HandleBanListHelper(QueryResult
* result
)
5177 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT
);
5179 // Chat short output
5184 Field
* fields
= result
->Fetch();
5185 uint32 accountid
= fields
[0].GetUInt32();
5187 QueryResult
* banresult
= loginDatabase
.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid
);
5190 Field
* fields2
= banresult
->Fetch();
5191 PSendSysMessage("%s",fields2
[0].GetString());
5194 } while (result
->NextRow());
5196 // Console wide output
5199 SendSysMessage(LANG_BANLIST_ACCOUNTS
);
5200 SendSysMessage("===============================================================================");
5201 SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER
);
5204 SendSysMessage("-------------------------------------------------------------------------------");
5205 Field
*fields
= result
->Fetch();
5206 uint32 account_id
= fields
[0].GetUInt32 ();
5208 std::string account_name
;
5210 // "account" case, name can be get in same query
5211 if(result
->GetFieldCount() > 1)
5212 account_name
= fields
[1].GetCppString();
5213 // "character" case, name need extract from another DB
5215 sAccountMgr
.GetName (account_id
,account_name
);
5217 // No SQL injection. id is uint32.
5218 QueryResult
*banInfo
= loginDatabase
.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id
);
5221 Field
*fields2
= banInfo
->Fetch();
5224 time_t t_ban
= fields2
[0].GetUInt64();
5225 tm
* aTm_ban
= localtime(&t_ban
);
5227 if (fields2
[0].GetUInt64() == fields2
[1].GetUInt64())
5229 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5230 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
,
5231 fields2
[2].GetString(),fields2
[3].GetString());
5235 time_t t_unban
= fields2
[1].GetUInt64();
5236 tm
* aTm_unban
= localtime(&t_unban
);
5237 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5238 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
,
5239 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5240 fields2
[2].GetString(),fields2
[3].GetString());
5242 }while ( banInfo
->NextRow() );
5245 }while( result
->NextRow() );
5246 SendSysMessage("===============================================================================");
5253 bool ChatHandler::HandleBanListIPCommand(const char* args
)
5255 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5257 char* cFilter
= strtok((char*)args
, " ");
5258 std::string filter
= cFilter
? cFilter
: "";
5259 loginDatabase
.escape_string(filter
);
5261 QueryResult
* result
;
5265 result
= loginDatabase
.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5266 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
5267 " ORDER BY unbandate" );
5271 result
= loginDatabase
.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5272 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")
5273 " ORDER BY unbandate",filter
.c_str() );
5278 PSendSysMessage(LANG_BANLIST_NOIP
);
5282 PSendSysMessage(LANG_BANLIST_MATCHINGIP
);
5283 // Chat short output
5288 Field
* fields
= result
->Fetch();
5289 PSendSysMessage("%s",fields
[0].GetString());
5290 } while (result
->NextRow());
5292 // Console wide output
5295 SendSysMessage(LANG_BANLIST_IPS
);
5296 SendSysMessage("===============================================================================");
5297 SendSysMessage(LANG_BANLIST_IPS_HEADER
);
5300 SendSysMessage("-------------------------------------------------------------------------------");
5301 Field
*fields
= result
->Fetch();
5302 time_t t_ban
= fields
[1].GetUInt64();
5303 tm
* aTm_ban
= localtime(&t_ban
);
5304 if ( fields
[1].GetUInt64() == fields
[2].GetUInt64() )
5306 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5307 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
,
5308 fields
[3].GetString(), fields
[4].GetString());
5312 time_t t_unban
= fields
[2].GetUInt64();
5313 tm
* aTm_unban
= localtime(&t_unban
);
5314 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5315 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
,
5316 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5317 fields
[3].GetString(), fields
[4].GetString());
5319 }while( result
->NextRow() );
5320 SendSysMessage("===============================================================================");
5327 bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
5329 Player
* pl
= m_session
->GetPlayer();
5331 // accept only explicitly selected target (not implicitly self targeting case)
5332 Unit
* target
= getSelectedUnit();
5333 if(pl
->GetSelection() && target
)
5335 if(target
->GetTypeId()!=TYPEID_UNIT
)
5337 SendSysMessage(LANG_SELECT_CREATURE
);
5338 SetSentErrorMessage(true);
5342 if(target
->isDead())
5343 ((Creature
*)target
)->Respawn();
5347 CellPair
p(MaNGOS::ComputeCellPair(pl
->GetPositionX(), pl
->GetPositionY()));
5349 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
5352 MaNGOS::RespawnDo u_do
;
5353 MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
> worker(pl
,u_do
);
5355 TypeContainerVisitor
<MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
>, GridTypeMapContainer
> obj_worker(worker
);
5356 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
5357 cell_lock
->Visit(cell_lock
, obj_worker
, *pl
->GetMap());
5362 bool ChatHandler::HandleGMFlyCommand(const char* args
)
5367 Player
*target
= getSelectedPlayer();
5369 target
= m_session
->GetPlayer();
5371 WorldPacket
data(12);
5372 if (strncmp(args
, "on", 3) == 0)
5373 data
.SetOpcode(SMSG_MOVE_SET_CAN_FLY
);
5374 else if (strncmp(args
, "off", 4) == 0)
5375 data
.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY
);
5378 SendSysMessage(LANG_USE_BOL
);
5381 data
.append(target
->GetPackGUID());
5382 data
<< uint32(0); // unknown
5383 target
->SendMessageToSet(&data
, true);
5384 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS
, GetNameLink(target
).c_str(), args
);
5388 bool ChatHandler::HandlePDumpLoadCommand(const char *args
)
5393 char * file
= strtok((char*)args
, " ");
5397 char * account
= strtok(NULL
, " ");
5401 std::string account_name
= account
;
5402 if (!AccountMgr::normalizeString(account_name
))
5404 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5405 SetSentErrorMessage(true);
5409 uint32 account_id
= sAccountMgr
.GetId(account_name
);
5412 account_id
= atoi(account
); // use original string
5415 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5416 SetSentErrorMessage(true);
5421 if (!sAccountMgr
.GetName(account_id
,account_name
))
5423 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5424 SetSentErrorMessage(true);
5428 char* guid_str
= NULL
;
5429 char* name_str
= strtok(NULL
, " ");
5435 // normalize the name if specified and check if it exists
5436 if (!normalizePlayerName(name
))
5438 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5439 SetSentErrorMessage(true);
5443 if (ObjectMgr::CheckPlayerName(name
,true) != CHAR_NAME_SUCCESS
)
5445 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5446 SetSentErrorMessage(true);
5450 guid_str
= strtok(NULL
, " ");
5457 guid
= atoi(guid_str
);
5460 PSendSysMessage(LANG_INVALID_CHARACTER_GUID
);
5461 SetSentErrorMessage(true);
5465 if (sObjectMgr
.GetPlayerAccountIdByGUID(guid
))
5467 PSendSysMessage(LANG_CHARACTER_GUID_IN_USE
,guid
);
5468 SetSentErrorMessage(true);
5473 switch(PlayerDumpReader().LoadDump(file
, account_id
, name
, guid
))
5476 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS
);
5478 case DUMP_FILE_OPEN_ERROR
:
5479 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
5480 SetSentErrorMessage(true);
5482 case DUMP_FILE_BROKEN
:
5483 PSendSysMessage(LANG_DUMP_BROKEN
,file
);
5484 SetSentErrorMessage(true);
5486 case DUMP_TOO_MANY_CHARS
:
5487 PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL
,account_name
.c_str(),account_id
);
5488 SetSentErrorMessage(true);
5491 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED
);
5492 SetSentErrorMessage(true);
5499 bool ChatHandler::HandlePDumpWriteCommand(const char *args
)
5504 char* file
= strtok((char*)args
, " ");
5505 char* p2
= strtok(NULL
, " ");
5511 // character name can't start from number
5512 if (isNumeric(p2
[0]))
5516 std::string name
= extractPlayerNameFromLink(p2
);
5519 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5520 SetSentErrorMessage(true);
5524 guid
= sObjectMgr
.GetPlayerGUIDByName(name
);
5527 if(!sObjectMgr
.GetPlayerAccountIdByGUID(guid
))
5529 PSendSysMessage(LANG_PLAYER_NOT_FOUND
);
5530 SetSentErrorMessage(true);
5534 switch(PlayerDumpWriter().WriteDump(file
, guid
))
5537 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS
);
5539 case DUMP_FILE_OPEN_ERROR
:
5540 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
5541 SetSentErrorMessage(true);
5544 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED
);
5545 SetSentErrorMessage(true);
5552 bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
5554 Unit
* unit
= getSelectedUnit();
5557 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5558 SetSentErrorMessage(true);
5562 PSendSysMessage(LANG_MOVEGENS_LIST
,(unit
->GetTypeId()==TYPEID_PLAYER
? "Player" : "Creature" ),unit
->GetGUIDLow());
5564 MotionMaster
* mm
= unit
->GetMotionMaster();
5565 for(MotionMaster::const_iterator itr
= mm
->begin(); itr
!= mm
->end(); ++itr
)
5567 switch((*itr
)->GetMovementGeneratorType())
5569 case IDLE_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_IDLE
); break;
5570 case RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_RANDOM
); break;
5571 case WAYPOINT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_WAYPOINT
); break;
5572 case ANIMAL_RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_ANIMAL_RANDOM
); break;
5573 case CONFUSED_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_CONFUSED
); break;
5574 case TARGETED_MOTION_TYPE
:
5576 if(unit
->GetTypeId()==TYPEID_PLAYER
)
5578 TargetedMovementGenerator
<Player
> const* mgen
= static_cast<TargetedMovementGenerator
<Player
> const*>(*itr
);
5579 Unit
* target
= mgen
->GetTarget();
5581 PSendSysMessage(LANG_MOVEGENS_TARGETED_PLAYER
,target
->GetName(),target
->GetGUIDLow());
5583 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL
);
5587 TargetedMovementGenerator
<Creature
> const* mgen
= static_cast<TargetedMovementGenerator
<Creature
> const*>(*itr
);
5588 Unit
* target
= mgen
->GetTarget();
5590 PSendSysMessage(LANG_MOVEGENS_TARGETED_CREATURE
,target
->GetName(),target
->GetGUIDLow());
5592 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL
);
5596 case HOME_MOTION_TYPE
:
5597 if(unit
->GetTypeId()==TYPEID_UNIT
)
5600 (*itr
)->GetDestination(x
,y
,z
);
5601 PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE
,x
,y
,z
);
5604 SendSysMessage(LANG_MOVEGENS_HOME_PLAYER
);
5606 case FLIGHT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FLIGHT
); break;
5607 case POINT_MOTION_TYPE
:
5610 (*itr
)->GetDestination(x
,y
,z
);
5611 PSendSysMessage(LANG_MOVEGENS_POINT
,x
,y
,z
);
5614 case FLEEING_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FEAR
); break;
5615 case DISTRACT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_DISTRACT
); break;
5617 PSendSysMessage(LANG_MOVEGENS_UNKNOWN
,(*itr
)->GetMovementGeneratorType());
5624 bool ChatHandler::HandleServerPLimitCommand(const char *args
)
5628 char* param
= strtok((char*)args
, " ");
5632 int l
= strlen(param
);
5634 if( strncmp(param
,"player",l
) == 0 )
5635 sWorld
.SetPlayerLimit(-SEC_PLAYER
);
5636 else if(strncmp(param
,"moderator",l
) == 0 )
5637 sWorld
.SetPlayerLimit(-SEC_MODERATOR
);
5638 else if(strncmp(param
,"gamemaster",l
) == 0 )
5639 sWorld
.SetPlayerLimit(-SEC_GAMEMASTER
);
5640 else if(strncmp(param
,"administrator",l
) == 0 )
5641 sWorld
.SetPlayerLimit(-SEC_ADMINISTRATOR
);
5642 else if(strncmp(param
,"reset",l
) == 0 )
5643 sWorld
.SetPlayerLimit( sConfig
.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT
) );
5646 int val
= atoi(param
);
5647 if(val
< -SEC_ADMINISTRATOR
) val
= -SEC_ADMINISTRATOR
;
5649 sWorld
.SetPlayerLimit(val
);
5652 // kick all low security level players
5653 if(sWorld
.GetPlayerAmountLimit() > SEC_PLAYER
)
5654 sWorld
.KickAllLess(sWorld
.GetPlayerSecurityLimit());
5657 uint32 pLimit
= sWorld
.GetPlayerAmountLimit();
5658 AccountTypes allowedAccountType
= sWorld
.GetPlayerSecurityLimit();
5659 char const* secName
= "";
5660 switch(allowedAccountType
)
5662 case SEC_PLAYER
: secName
= "Player"; break;
5663 case SEC_MODERATOR
: secName
= "Moderator"; break;
5664 case SEC_GAMEMASTER
: secName
= "Gamemaster"; break;
5665 case SEC_ADMINISTRATOR
: secName
= "Administrator"; break;
5666 default: secName
= "<unknown>"; break;
5669 PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit
,secName
);
5674 bool ChatHandler::HandleCastCommand(const char* args
)
5679 Unit
* target
= getSelectedUnit();
5683 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5684 SetSentErrorMessage(true);
5688 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5689 uint32 spell
= extractSpellIdFromLink((char*)args
);
5693 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5697 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5699 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5700 SetSentErrorMessage(true);
5704 char* trig_str
= strtok(NULL
, " ");
5707 int l
= strlen(trig_str
);
5708 if(strncmp(trig_str
,"triggered",l
) != 0 )
5712 bool triggered
= (trig_str
!= NULL
);
5714 m_session
->GetPlayer()->CastSpell(target
,spell
,triggered
);
5719 bool ChatHandler::HandleCastBackCommand(const char* args
)
5721 Creature
* caster
= getSelectedCreature();
5725 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5726 SetSentErrorMessage(true);
5730 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
5731 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5732 uint32 spell
= extractSpellIdFromLink((char*)args
);
5733 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
5736 char* trig_str
= strtok(NULL
, " ");
5739 int l
= strlen(trig_str
);
5740 if(strncmp(trig_str
,"triggered",l
) != 0 )
5744 bool triggered
= (trig_str
!= NULL
);
5746 caster
->SetFacingToObject(m_session
->GetPlayer());
5748 caster
->CastSpell(m_session
->GetPlayer(),spell
,triggered
);
5753 bool ChatHandler::HandleCastDistCommand(const char* args
)
5758 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5759 uint32 spell
= extractSpellIdFromLink((char*)args
);
5763 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5767 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5769 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5770 SetSentErrorMessage(true);
5774 char *distStr
= strtok(NULL
, " ");
5779 sscanf(distStr
, "%f", &dist
);
5781 char* trig_str
= strtok(NULL
, " ");
5784 int l
= strlen(trig_str
);
5785 if(strncmp(trig_str
,"triggered",l
) != 0 )
5789 bool triggered
= (trig_str
!= NULL
);
5792 m_session
->GetPlayer()->GetClosePoint(x
,y
,z
,dist
);
5794 m_session
->GetPlayer()->CastSpell(x
,y
,z
,spell
,triggered
);
5798 bool ChatHandler::HandleCastTargetCommand(const char* args
)
5800 Creature
* caster
= getSelectedCreature();
5804 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5805 SetSentErrorMessage(true);
5809 if(!caster
->getVictim())
5811 SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM
);
5812 SetSentErrorMessage(true);
5816 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5817 uint32 spell
= extractSpellIdFromLink((char*)args
);
5818 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
5821 char* trig_str
= strtok(NULL
, " ");
5824 int l
= strlen(trig_str
);
5825 if(strncmp(trig_str
,"triggered",l
) != 0 )
5829 bool triggered
= (trig_str
!= NULL
);
5831 caster
->SetFacingToObject(m_session
->GetPlayer());
5833 caster
->CastSpell(caster
->getVictim(),spell
,triggered
);
5839 ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
5840 Without this function 3rd party scripting library will get linking errors (unresolved external)
5841 when attempting to use the PointMovementGenerator
5843 bool ChatHandler::HandleComeToMeCommand(const char *args
)
5845 Creature
* caster
= getSelectedCreature();
5849 SendSysMessage(LANG_SELECT_CREATURE
);
5850 SetSentErrorMessage(true);
5854 char* newFlagStr
= strtok((char*)args
, " ");
5859 uint32 newFlags
= atoi(newFlagStr
);
5861 caster
->SetMonsterMoveFlags(MonsterMovementFlags(newFlags
));
5863 Player
* pl
= m_session
->GetPlayer();
5865 caster
->GetMotionMaster()->MovePoint(0, pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ());
5869 bool ChatHandler::HandleCastSelfCommand(const char* args
)
5874 Unit
* target
= getSelectedUnit();
5878 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5879 SetSentErrorMessage(true);
5883 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5884 uint32 spell
= extractSpellIdFromLink((char*)args
);
5888 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5892 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5894 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5895 SetSentErrorMessage(true);
5899 target
->CastSpell(target
,spell
,false);
5904 std::string
GetTimeString(uint32 time
)
5906 uint16 days
= time
/ DAY
, hours
= (time
% DAY
) / HOUR
, minute
= (time
% HOUR
) / MINUTE
;
5907 std::ostringstream ss
;
5908 if(days
) ss
<< days
<< "d ";
5909 if(hours
) ss
<< hours
<< "h ";
5910 ss
<< minute
<< "m";
5914 bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
5916 Player
* player
= getSelectedPlayer();
5917 if (!player
) player
= m_session
->GetPlayer();
5919 for(uint8 i
= 0; i
< MAX_DIFFICULTY
; ++i
)
5921 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(Difficulty(i
));
5922 for(Player::BoundInstancesMap::const_iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
5924 InstanceSave
*save
= itr
->second
.save
;
5925 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
5926 if (const MapEntry
* entry
= sMapStore
.LookupEntry(itr
->first
))
5928 PSendSysMessage("map: %d (%s) inst: %d perm: %s diff: %d canReset: %s TTR: %s",
5929 itr
->first
, entry
->name
[m_session
->GetSessionDbcLocale()], save
->GetInstanceId(), itr
->second
.perm
? "yes" : "no",
5930 save
->GetDifficulty(), save
->CanReset() ? "yes" : "no", timeleft
.c_str());
5933 PSendSysMessage("bound for a nonexistant map %u", itr
->first
);
5937 PSendSysMessage("player binds: %d", counter
);
5939 Group
*group
= player
->GetGroup();
5942 for(uint8 i
= 0; i
< MAX_DIFFICULTY
; ++i
)
5944 Group::BoundInstancesMap
&binds
= group
->GetBoundInstances(Difficulty(i
));
5945 for(Group::BoundInstancesMap::const_iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
5947 InstanceSave
*save
= itr
->second
.save
;
5948 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
5949 if (const MapEntry
* entry
= sMapStore
.LookupEntry(itr
->first
))
5951 PSendSysMessage("map: %d (%s) inst: %d perm: %s diff: %d canReset: %s TTR: %s",
5952 itr
->first
, entry
->name
[m_session
->GetSessionDbcLocale()], save
->GetInstanceId(), itr
->second
.perm
? "yes" : "no",
5953 save
->GetDifficulty(), save
->CanReset() ? "yes" : "no", timeleft
.c_str());
5956 PSendSysMessage("bound for a nonexistant map %u", itr
->first
);
5961 PSendSysMessage("group binds: %d", counter
);
5966 bool ChatHandler::HandleInstanceUnbindCommand(const char* args
)
5971 Player
* player
= getSelectedPlayer();
5973 player
= m_session
->GetPlayer();
5976 bool got_map
= false;
5978 if (strncmp(args
,"all",strlen(args
)) != 0)
5980 if(!isNumeric(args
[0]))
5987 for(uint8 i
= 0; i
< MAX_DIFFICULTY
; ++i
)
5989 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(Difficulty(i
));
5990 for(Player::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end();)
5992 if (got_map
&& mapid
!= itr
->first
)
5997 if(itr
->first
!= player
->GetMapId())
5999 InstanceSave
*save
= itr
->second
.save
;
6000 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
6002 if (const MapEntry
* entry
= sMapStore
.LookupEntry(itr
->first
))
6004 PSendSysMessage("unbinding map: %d (%s) inst: %d perm: %s diff: %d canReset: %s TTR: %s",
6005 itr
->first
, entry
->name
[m_session
->GetSessionDbcLocale()], save
->GetInstanceId(), itr
->second
.perm
? "yes" : "no",
6006 save
->GetDifficulty(), save
->CanReset() ? "yes" : "no", timeleft
.c_str());
6009 PSendSysMessage("bound for a nonexistant map %u", itr
->first
);
6010 player
->UnbindInstance(itr
, Difficulty(i
));
6017 PSendSysMessage("instances unbound: %d", counter
);
6021 bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
6023 PSendSysMessage("instances loaded: %d", sMapMgr
.GetNumInstances());
6024 PSendSysMessage("players in instances: %d", sMapMgr
.GetNumPlayersInInstances());
6025 PSendSysMessage("instance saves: %d", sInstanceSaveMgr
.GetNumInstanceSaves());
6026 PSendSysMessage("players bound: %d", sInstanceSaveMgr
.GetNumBoundPlayersTotal());
6027 PSendSysMessage("groups bound: %d", sInstanceSaveMgr
.GetNumBoundGroupsTotal());
6031 bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
6033 Player
* pl
= m_session
->GetPlayer();
6035 Map
* map
= pl
->GetMap();
6036 if (!map
->IsDungeon())
6038 PSendSysMessage("Map is not a dungeon.");
6039 SetSentErrorMessage(true);
6043 if (!((InstanceMap
*)map
)->GetInstanceData())
6045 PSendSysMessage("Map has no instance data.");
6046 SetSentErrorMessage(true);
6050 ((InstanceMap
*)map
)->GetInstanceData()->SaveToDB();
6054 /// Display the list of GMs
6055 bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
6057 ///- Get the accounts with GM Level >0
6058 QueryResult
*result
= loginDatabase
.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
6061 SendSysMessage(LANG_GMLIST
);
6062 SendSysMessage("========================");
6063 SendSysMessage(LANG_GMLIST_HEADER
);
6064 SendSysMessage("========================");
6066 ///- Circle through them. Display username and GM level
6069 Field
*fields
= result
->Fetch();
6070 PSendSysMessage("|%15s|%6s|", fields
[0].GetString(),fields
[1].GetString());
6071 }while( result
->NextRow() );
6073 PSendSysMessage("========================");
6077 PSendSysMessage(LANG_GMLIST_EMPTY
);
6081 /// Define the 'Message of the day' for the realm
6082 bool ChatHandler::HandleServerSetMotdCommand(const char* args
)
6084 sWorld
.SetMotd(args
);
6085 PSendSysMessage(LANG_MOTD_NEW
, args
);
6089 /// Set/Unset the expansion level for an account
6090 bool ChatHandler::HandleAccountSetAddonCommand(const char* args
)
6092 ///- Get the command line arguments
6093 char *szAcc
= strtok((char*)args
," ");
6094 char *szExp
= strtok(NULL
," ");
6099 std::string account_name
;
6104 Player
* player
= getSelectedPlayer();
6108 account_id
= player
->GetSession()->GetAccountId();
6109 sAccountMgr
.GetName(account_id
,account_name
);
6114 ///- Convert Account name to Upper Format
6115 account_name
= szAcc
;
6116 if (!AccountMgr::normalizeString(account_name
))
6118 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
6119 SetSentErrorMessage(true);
6123 account_id
= sAccountMgr
.GetId(account_name
);
6126 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
6127 SetSentErrorMessage(true);
6133 // Let set addon state only for lesser (strong) security level
6134 // or to self account
6135 if (m_session
&& m_session
->GetAccountId () != account_id
&&
6136 HasLowerSecurityAccount (NULL
,account_id
,true))
6139 int lev
=atoi(szExp
); //get int anyway (0 if error)
6144 loginDatabase
.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev
,account_id
);
6145 PSendSysMessage(LANG_ACCOUNT_SETADDON
,account_name
.c_str(),account_id
,lev
);
6149 //Send items by mail
6150 bool ChatHandler::HandleSendItemsCommand(const char* args
)
6152 // format: name "subject text" "mail text" item1[:count1] item2[:count2] ... item12[:count12]
6154 uint64 receiver_guid
;
6155 std::string receiver_name
;
6156 if(!extractPlayerTarget((char*)args
,&receiver
,&receiver_guid
,&receiver_name
))
6159 char* tail1
= strtok(NULL
, "");
6163 char* msgSubject
= extractQuotedArg(tail1
);
6167 char* tail2
= strtok(NULL
, "");
6171 char* msgText
= extractQuotedArg(tail2
);
6175 // msgSubject, msgText isn't NUL after prev. check
6176 std::string subject
= msgSubject
;
6177 std::string text
= msgText
;
6180 typedef std::pair
<uint32
,uint32
> ItemPair
;
6181 typedef std::list
< ItemPair
> ItemPairs
;
6184 // get all tail string
6185 char* tail
= strtok(NULL
, "");
6187 // get from tail next item str
6188 while(char* itemStr
= strtok(tail
, " "))
6191 tail
= strtok(NULL
, "");
6194 char* itemIdStr
= strtok(itemStr
, ":");
6195 char* itemCountStr
= strtok(NULL
, " ");
6197 uint32 item_id
= atoi(itemIdStr
);
6201 ItemPrototype
const* item_proto
= ObjectMgr::GetItemPrototype(item_id
);
6204 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
6205 SetSentErrorMessage(true);
6209 uint32 item_count
= itemCountStr
? atoi(itemCountStr
) : 1;
6210 if (item_count
< 1 || (item_proto
->MaxCount
> 0 && item_count
> uint32(item_proto
->MaxCount
)))
6212 PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT
, item_count
,item_id
);
6213 SetSentErrorMessage(true);
6217 while(item_count
> item_proto
->GetMaxStackSize())
6219 items
.push_back(ItemPair(item_id
,item_proto
->GetMaxStackSize()));
6220 item_count
-= item_proto
->GetMaxStackSize();
6223 items
.push_back(ItemPair(item_id
,item_count
));
6225 if(items
.size() > MAX_MAIL_ITEMS
)
6227 PSendSysMessage(LANG_COMMAND_MAIL_ITEMS_LIMIT
, MAX_MAIL_ITEMS
);
6228 SetSentErrorMessage(true);
6233 // from console show not existed sender
6234 MailSender
sender(MAIL_NORMAL
,m_session
? m_session
->GetPlayer()->GetGUIDLow() : 0, MAIL_STATIONERY_GM
);
6236 uint32 itemTextId
= !text
.empty() ? sObjectMgr
.CreateItemText( text
) : 0;
6239 MailDraft
draft(subject
, itemTextId
);
6241 for(ItemPairs::const_iterator itr
= items
.begin(); itr
!= items
.end(); ++itr
)
6243 if(Item
* item
= Item::CreateItem(itr
->first
,itr
->second
,m_session
? m_session
->GetPlayer() : 0))
6245 item
->SaveToDB(); // save for prevent lost at next mail load, if send fail then item will deleted
6246 draft
.AddItem(item
);
6250 draft
.SendMailTo(MailReceiver(receiver
,GUID_LOPART(receiver_guid
)), sender
);
6252 std::string nameLink
= playerLink(receiver_name
);
6253 PSendSysMessage(LANG_MAIL_SENT
, nameLink
.c_str());
6257 ///Send money by mail
6258 bool ChatHandler::HandleSendMoneyCommand(const char* args
)
6260 /// format: name "subject text" "mail text" money
6263 uint64 receiver_guid
;
6264 std::string receiver_name
;
6265 if(!extractPlayerTarget((char*)args
,&receiver
,&receiver_guid
,&receiver_name
))
6268 char* tail1
= strtok(NULL
, "");
6272 char* msgSubject
= extractQuotedArg(tail1
);
6276 char* tail2
= strtok(NULL
, "");
6280 char* msgText
= extractQuotedArg(tail2
);
6284 char* money_str
= strtok(NULL
, "");
6285 int32 money
= money_str
? atoi(money_str
) : 0;
6289 // msgSubject, msgText isn't NUL after prev. check
6290 std::string subject
= msgSubject
;
6291 std::string text
= msgText
;
6293 // from console show not existed sender
6294 MailSender
sender(MAIL_NORMAL
,m_session
? m_session
->GetPlayer()->GetGUIDLow() : 0, MAIL_STATIONERY_GM
);
6296 uint32 itemTextId
= !text
.empty() ? sObjectMgr
.CreateItemText( text
) : 0;
6298 MailDraft(subject
, itemTextId
)
6300 .SendMailTo(MailReceiver(receiver
,GUID_LOPART(receiver_guid
)),sender
);
6302 std::string nameLink
= playerLink(receiver_name
);
6303 PSendSysMessage(LANG_MAIL_SENT
, nameLink
.c_str());
6307 /// Send a message to a player in game
6308 bool ChatHandler::HandleSendMessageCommand(const char* args
)
6310 ///- Find the player
6312 if(!extractPlayerTarget((char*)args
,&rPlayer
))
6315 char* msg_str
= strtok(NULL
, "");
6319 ///- Check that he is not logging out.
6320 if(rPlayer
->GetSession()->isLogingOut())
6322 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6323 SetSentErrorMessage(true);
6327 ///- Send the message
6328 //Use SendAreaTriggerMessage for fastest delivery.
6329 rPlayer
->GetSession()->SendAreaTriggerMessage("%s", msg_str
);
6330 rPlayer
->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
6332 //Confirmation message
6333 std::string nameLink
= GetNameLink(rPlayer
);
6334 PSendSysMessage(LANG_SENDMESSAGE
,nameLink
.c_str(),msg_str
);
6338 bool ChatHandler::HandleFlushArenaPointsCommand(const char * /*args*/)
6340 sBattleGroundMgr
.DistributeArenaPoints();
6344 bool ChatHandler::HandleModifyGenderCommand(const char *args
)
6349 Player
*player
= getSelectedPlayer();
6353 PSendSysMessage(LANG_PLAYER_NOT_FOUND
);
6354 SetSentErrorMessage(true);
6358 PlayerInfo
const* info
= sObjectMgr
.GetPlayerInfo(player
->getRace(), player
->getClass());
6362 char const* gender_str
= (char*)args
;
6363 int gender_len
= strlen(gender_str
);
6367 if(!strncmp(gender_str
, "male", gender_len
)) // MALE
6369 if(player
->getGender() == GENDER_MALE
)
6372 gender
= GENDER_MALE
;
6374 else if (!strncmp(gender_str
, "female", gender_len
)) // FEMALE
6376 if(player
->getGender() == GENDER_FEMALE
)
6379 gender
= GENDER_FEMALE
;
6383 SendSysMessage(LANG_MUST_MALE_OR_FEMALE
);
6384 SetSentErrorMessage(true);
6389 player
->SetByteValue(UNIT_FIELD_BYTES_0
, 2, gender
);
6390 player
->SetByteValue(PLAYER_BYTES_3
, 0, gender
);
6392 // Change display ID
6393 player
->InitDisplayIds();
6395 char const* gender_full
= gender
? "female" : "male";
6397 PSendSysMessage(LANG_YOU_CHANGE_GENDER
, GetNameLink(player
).c_str(), gender_full
);
6399 if (needReportToTarget(player
))
6400 ChatHandler(player
).PSendSysMessage(LANG_YOUR_GENDER_CHANGED
, gender_full
, GetNameLink().c_str());