2 * Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
24 #include "ObjectMgr.h"
25 #include "AccountMgr.h"
26 #include "PlayerDump.h"
30 #include "GameObject.h"
34 #include "ObjectAccessor.h"
35 #include "MapManager.h"
36 #include "ScriptCalls.h"
38 #include "GridNotifiersImpl.h"
41 #include "PointMovementGenerator.h"
42 #include "TargetedMovementGenerator.h"
43 #include "SkillDiscovery.h"
44 #include "SkillExtraItems.h"
45 #include "SystemConfig.h"
46 #include "Config/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 HandleReloadAllGossipsCommand("");
69 HandleReloadAllLocalesCommand("");
71 HandleReloadMailLevelRewardCommand("");
72 HandleReloadCommandCommand("");
73 HandleReloadReservedNameCommand("");
74 HandleReloadMangosStringCommand("");
75 HandleReloadGameTeleCommand("");
79 bool ChatHandler::HandleReloadAllAchievementCommand(const char*)
81 HandleReloadAchievementCriteriaRequirementCommand("");
82 HandleReloadAchievementRewardCommand("");
86 bool ChatHandler::HandleReloadAllAreaCommand(const char*)
88 //HandleReloadQuestAreaTriggersCommand(""); -- reloaded in HandleReloadAllQuestCommand
89 HandleReloadAreaTriggerTeleportCommand("");
90 HandleReloadAreaTriggerTavernCommand("");
91 HandleReloadGameGraveyardZoneCommand("");
95 bool ChatHandler::HandleReloadAllLootCommand(const char*)
97 sLog
.outString( "Re-Loading Loot Tables..." );
99 SendGlobalSysMessage("DB tables `*_loot_template` reloaded.");
103 bool ChatHandler::HandleReloadAllNpcCommand(const char* args
)
105 if(*args
!='a') // will be reloaded from all_gossips
106 HandleReloadNpcGossipCommand("a");
107 HandleReloadNpcTrainerCommand("a");
108 HandleReloadNpcVendorCommand("a");
109 HandleReloadPointsOfInterestCommand("a");
110 HandleReloadSpellClickSpellsCommand("a");
114 bool ChatHandler::HandleReloadAllQuestCommand(const char* /*args*/)
116 HandleReloadQuestAreaTriggersCommand("a");
117 HandleReloadQuestPOICommand("a");
118 HandleReloadQuestTemplateCommand("a");
120 sLog
.outString( "Re-Loading Quests Relations..." );
121 sObjectMgr
.LoadQuestRelations();
122 SendGlobalSysMessage("DB tables `*_questrelation` and `*_involvedrelation` reloaded.");
126 bool ChatHandler::HandleReloadAllScriptsCommand(const char*)
128 if(sWorld
.IsScriptScheduled())
130 PSendSysMessage("DB scripts used currently, please attempt reload later.");
131 SetSentErrorMessage(true);
135 sLog
.outString( "Re-Loading Scripts..." );
136 HandleReloadGameObjectScriptsCommand("a");
137 HandleReloadGossipScriptsCommand("a");
138 HandleReloadEventScriptsCommand("a");
139 HandleReloadQuestEndScriptsCommand("a");
140 HandleReloadQuestStartScriptsCommand("a");
141 HandleReloadSpellScriptsCommand("a");
142 SendGlobalSysMessage("DB tables `*_scripts` reloaded.");
143 HandleReloadDbScriptStringCommand("a");
147 bool ChatHandler::HandleReloadAllEventAICommand(const char*)
149 HandleReloadEventAITextsCommand("a");
150 HandleReloadEventAISummonsCommand("a");
151 HandleReloadEventAIScriptsCommand("a");
155 bool ChatHandler::HandleReloadAllSpellCommand(const char*)
157 HandleReloadSkillDiscoveryTemplateCommand("a");
158 HandleReloadSkillExtraItemTemplateCommand("a");
159 HandleReloadSpellAreaCommand("a");
160 HandleReloadSpellChainCommand("a");
161 HandleReloadSpellElixirCommand("a");
162 HandleReloadSpellLearnSpellCommand("a");
163 HandleReloadSpellProcEventCommand("a");
164 HandleReloadSpellBonusesCommand("a");
165 HandleReloadSpellProcItemEnchantCommand("a");
166 HandleReloadSpellScriptTargetCommand("a");
167 HandleReloadSpellTargetPositionCommand("a");
168 HandleReloadSpellThreatsCommand("a");
169 HandleReloadSpellPetAurasCommand("a");
173 bool ChatHandler::HandleReloadAllGossipsCommand(const char* args
)
175 HandleReloadGossipMenuCommand("a");
176 HandleReloadGossipMenuOptionCommand("a");
177 if(*args
!='a') // already reload from all_scripts
178 HandleReloadGossipScriptsCommand("a");
179 HandleReloadNpcGossipCommand("a");
180 HandleReloadPointsOfInterestCommand("a");
184 bool ChatHandler::HandleReloadAllItemCommand(const char*)
186 HandleReloadPageTextsCommand("a");
187 HandleReloadItemEnchantementsCommand("a");
188 HandleReloadItemRequiredTragetCommand("a");
192 bool ChatHandler::HandleReloadAllLocalesCommand(const char* /*args*/)
194 HandleReloadLocalesAchievementRewardCommand("a");
195 HandleReloadLocalesCreatureCommand("a");
196 HandleReloadLocalesGameobjectCommand("a");
197 HandleReloadLocalesGossipMenuOptionCommand("a");
198 HandleReloadLocalesItemCommand("a");
199 HandleReloadLocalesNpcTextCommand("a");
200 HandleReloadLocalesPageTextCommand("a");
201 HandleReloadLocalesPointsOfInterestCommand("a");
202 HandleReloadLocalesQuestCommand("a");
206 bool ChatHandler::HandleReloadConfigCommand(const char* /*args*/)
208 sLog
.outString( "Re-Loading config settings..." );
209 sWorld
.LoadConfigSettings(true);
210 sMapMgr
.InitializeVisibilityDistanceInfo();
211 SendGlobalSysMessage("World config settings reloaded.");
215 bool ChatHandler::HandleReloadAchievementCriteriaRequirementCommand(const char*)
217 sLog
.outString( "Re-Loading Additional Achievement Criteria Requirements Data..." );
218 sAchievementMgr
.LoadAchievementCriteriaRequirements();
219 SendGlobalSysMessage("DB table `achievement_criteria_requirement` reloaded.");
223 bool ChatHandler::HandleReloadAchievementRewardCommand(const char*)
225 sLog
.outString( "Re-Loading Achievement Reward Data..." );
226 sAchievementMgr
.LoadRewards();
227 SendGlobalSysMessage("DB table `achievement_reward` reloaded.");
231 bool ChatHandler::HandleReloadAreaTriggerTavernCommand(const char*)
233 sLog
.outString( "Re-Loading Tavern Area Triggers..." );
234 sObjectMgr
.LoadTavernAreaTriggers();
235 SendGlobalSysMessage("DB table `areatrigger_tavern` reloaded.");
239 bool ChatHandler::HandleReloadAreaTriggerTeleportCommand(const char*)
241 sLog
.outString( "Re-Loading AreaTrigger teleport definitions..." );
242 sObjectMgr
.LoadAreaTriggerTeleports();
243 SendGlobalSysMessage("DB table `areatrigger_teleport` reloaded.");
247 bool ChatHandler::HandleReloadCommandCommand(const char*)
249 load_command_table
= true;
250 SendGlobalSysMessage("DB table `command` will be reloaded at next chat command use.");
254 bool ChatHandler::HandleReloadCreatureQuestRelationsCommand(const char*)
256 sLog
.outString( "Loading Quests Relations... (`creature_questrelation`)" );
257 sObjectMgr
.LoadCreatureQuestRelations();
258 SendGlobalSysMessage("DB table `creature_questrelation` (creature quest givers) reloaded.");
262 bool ChatHandler::HandleReloadCreatureQuestInvRelationsCommand(const char*)
264 sLog
.outString( "Loading Quests Relations... (`creature_involvedrelation`)" );
265 sObjectMgr
.LoadCreatureInvolvedRelations();
266 SendGlobalSysMessage("DB table `creature_involvedrelation` (creature quest takers) reloaded.");
270 bool ChatHandler::HandleReloadGossipMenuCommand(const char*)
272 sLog
.outString( "Re-Loading `gossip_menu` Table!" );
273 sObjectMgr
.LoadGossipMenu();
274 SendGlobalSysMessage("DB table `gossip_menu` reloaded.");
278 bool ChatHandler::HandleReloadGossipMenuOptionCommand(const char*)
280 sLog
.outString( "Re-Loading `gossip_menu_option` Table!" );
281 sObjectMgr
.LoadGossipMenuItems();
282 SendGlobalSysMessage("DB table `gossip_menu_option` reloaded.");
286 bool ChatHandler::HandleReloadGossipScriptsCommand(const char* arg
)
288 if(sWorld
.IsScriptScheduled())
290 SendSysMessage("DB scripts used currently, please attempt reload later.");
291 SetSentErrorMessage(true);
296 sLog
.outString( "Re-Loading Scripts from `gossip_scripts`...");
298 sObjectMgr
.LoadGossipScripts();
301 SendGlobalSysMessage("DB table `gossip_scripts` reloaded.");
306 bool ChatHandler::HandleReloadGOQuestRelationsCommand(const char*)
308 sLog
.outString( "Loading Quests Relations... (`gameobject_questrelation`)" );
309 sObjectMgr
.LoadGameobjectQuestRelations();
310 SendGlobalSysMessage("DB table `gameobject_questrelation` (gameobject quest givers) reloaded.");
314 bool ChatHandler::HandleReloadGOQuestInvRelationsCommand(const char*)
316 sLog
.outString( "Loading Quests Relations... (`gameobject_involvedrelation`)" );
317 sObjectMgr
.LoadGameobjectInvolvedRelations();
318 SendGlobalSysMessage("DB table `gameobject_involvedrelation` (gameobject quest takers) reloaded.");
322 bool ChatHandler::HandleReloadQuestAreaTriggersCommand(const char*)
324 sLog
.outString( "Re-Loading Quest Area Triggers..." );
325 sObjectMgr
.LoadQuestAreaTriggers();
326 SendGlobalSysMessage("DB table `areatrigger_involvedrelation` (quest area triggers) reloaded.");
330 bool ChatHandler::HandleReloadQuestTemplateCommand(const char*)
332 sLog
.outString( "Re-Loading Quest Templates..." );
333 sObjectMgr
.LoadQuests();
334 SendGlobalSysMessage("DB table `quest_template` (quest definitions) reloaded.");
336 /// dependent also from `gameobject` but this table not reloaded anyway
337 sLog
.outString( "Re-Loading GameObjects for quests..." );
338 sObjectMgr
.LoadGameObjectForQuests();
339 SendGlobalSysMessage("Data GameObjects for quests reloaded.");
343 bool ChatHandler::HandleReloadLootTemplatesCreatureCommand(const char*)
345 sLog
.outString( "Re-Loading Loot Tables... (`creature_loot_template`)" );
346 LoadLootTemplates_Creature();
347 LootTemplates_Creature
.CheckLootRefs();
348 SendGlobalSysMessage("DB table `creature_loot_template` reloaded.");
352 bool ChatHandler::HandleReloadLootTemplatesDisenchantCommand(const char*)
354 sLog
.outString( "Re-Loading Loot Tables... (`disenchant_loot_template`)" );
355 LoadLootTemplates_Disenchant();
356 LootTemplates_Disenchant
.CheckLootRefs();
357 SendGlobalSysMessage("DB table `disenchant_loot_template` reloaded.");
361 bool ChatHandler::HandleReloadLootTemplatesFishingCommand(const char*)
363 sLog
.outString( "Re-Loading Loot Tables... (`fishing_loot_template`)" );
364 LoadLootTemplates_Fishing();
365 LootTemplates_Fishing
.CheckLootRefs();
366 SendGlobalSysMessage("DB table `fishing_loot_template` reloaded.");
370 bool ChatHandler::HandleReloadLootTemplatesGameobjectCommand(const char*)
372 sLog
.outString( "Re-Loading Loot Tables... (`gameobject_loot_template`)" );
373 LoadLootTemplates_Gameobject();
374 LootTemplates_Gameobject
.CheckLootRefs();
375 SendGlobalSysMessage("DB table `gameobject_loot_template` reloaded.");
379 bool ChatHandler::HandleReloadLootTemplatesItemCommand(const char*)
381 sLog
.outString( "Re-Loading Loot Tables... (`item_loot_template`)" );
382 LoadLootTemplates_Item();
383 LootTemplates_Item
.CheckLootRefs();
384 SendGlobalSysMessage("DB table `item_loot_template` reloaded.");
388 bool ChatHandler::HandleReloadLootTemplatesMillingCommand(const char*)
390 sLog
.outString( "Re-Loading Loot Tables... (`milling_loot_template`)" );
391 LoadLootTemplates_Milling();
392 LootTemplates_Milling
.CheckLootRefs();
393 SendGlobalSysMessage("DB table `milling_loot_template` reloaded.");
397 bool ChatHandler::HandleReloadLootTemplatesPickpocketingCommand(const char*)
399 sLog
.outString( "Re-Loading Loot Tables... (`pickpocketing_loot_template`)" );
400 LoadLootTemplates_Pickpocketing();
401 LootTemplates_Pickpocketing
.CheckLootRefs();
402 SendGlobalSysMessage("DB table `pickpocketing_loot_template` reloaded.");
406 bool ChatHandler::HandleReloadLootTemplatesProspectingCommand(const char*)
408 sLog
.outString( "Re-Loading Loot Tables... (`prospecting_loot_template`)" );
409 LoadLootTemplates_Prospecting();
410 LootTemplates_Prospecting
.CheckLootRefs();
411 SendGlobalSysMessage("DB table `prospecting_loot_template` reloaded.");
415 bool ChatHandler::HandleReloadLootTemplatesMailCommand(const char*)
417 sLog
.outString( "Re-Loading Loot Tables... (`mail_loot_template`)" );
418 LoadLootTemplates_Mail();
419 LootTemplates_Mail
.CheckLootRefs();
420 SendGlobalSysMessage("DB table `mail_loot_template` reloaded.");
424 bool ChatHandler::HandleReloadLootTemplatesReferenceCommand(const char*)
426 sLog
.outString( "Re-Loading Loot Tables... (`reference_loot_template`)" );
427 LoadLootTemplates_Reference();
428 SendGlobalSysMessage("DB table `reference_loot_template` reloaded.");
432 bool ChatHandler::HandleReloadLootTemplatesSkinningCommand(const char*)
434 sLog
.outString( "Re-Loading Loot Tables... (`skinning_loot_template`)" );
435 LoadLootTemplates_Skinning();
436 LootTemplates_Skinning
.CheckLootRefs();
437 SendGlobalSysMessage("DB table `skinning_loot_template` reloaded.");
441 bool ChatHandler::HandleReloadLootTemplatesSpellCommand(const char*)
443 sLog
.outString( "Re-Loading Loot Tables... (`spell_loot_template`)" );
444 LoadLootTemplates_Spell();
445 LootTemplates_Spell
.CheckLootRefs();
446 SendGlobalSysMessage("DB table `spell_loot_template` reloaded.");
450 bool ChatHandler::HandleReloadMangosStringCommand(const char*)
452 sLog
.outString( "Re-Loading mangos_string Table!" );
453 sObjectMgr
.LoadMangosStrings();
454 SendGlobalSysMessage("DB table `mangos_string` reloaded.");
458 bool ChatHandler::HandleReloadNpcGossipCommand(const char*)
460 sLog
.outString( "Re-Loading `npc_gossip` Table!" );
461 sObjectMgr
.LoadNpcTextId();
462 SendGlobalSysMessage("DB table `npc_gossip` reloaded.");
466 bool ChatHandler::HandleReloadNpcTrainerCommand(const char*)
468 sLog
.outString( "Re-Loading `npc_trainer` Table!" );
469 sObjectMgr
.LoadTrainerSpell();
470 SendGlobalSysMessage("DB table `npc_trainer` reloaded.");
474 bool ChatHandler::HandleReloadNpcVendorCommand(const char*)
476 sLog
.outString( "Re-Loading `npc_vendor` Table!" );
477 sObjectMgr
.LoadVendors();
478 SendGlobalSysMessage("DB table `npc_vendor` reloaded.");
482 bool ChatHandler::HandleReloadPointsOfInterestCommand(const char*)
484 sLog
.outString( "Re-Loading `points_of_interest` Table!" );
485 sObjectMgr
.LoadPointsOfInterest();
486 SendGlobalSysMessage("DB table `points_of_interest` reloaded.");
490 bool ChatHandler::HandleReloadQuestPOICommand(const char*)
492 sLog
.outString( "Re-Loading `quest_poi` and `quest_poi_points` Tables!" );
493 sObjectMgr
.LoadQuestPOI();
494 SendGlobalSysMessage("DB Table `quest_poi` and `quest_poi_points` reloaded.");
498 bool ChatHandler::HandleReloadSpellClickSpellsCommand(const char*)
500 sLog
.outString( "Re-Loading `npc_spellclick_spells` Table!" );
501 sObjectMgr
.LoadNPCSpellClickSpells();
502 SendGlobalSysMessage("DB table `npc_spellclick_spells` reloaded.");
506 bool ChatHandler::HandleReloadReservedNameCommand(const char*)
508 sLog
.outString( "Loading ReservedNames... (`reserved_name`)" );
509 sObjectMgr
.LoadReservedPlayersNames();
510 SendGlobalSysMessage("DB table `reserved_name` (player reserved names) reloaded.");
514 bool ChatHandler::HandleReloadSkillDiscoveryTemplateCommand(const char* /*args*/)
516 sLog
.outString( "Re-Loading Skill Discovery Table..." );
517 LoadSkillDiscoveryTable();
518 SendGlobalSysMessage("DB table `skill_discovery_template` (recipes discovered at crafting) reloaded.");
522 bool ChatHandler::HandleReloadSkillExtraItemTemplateCommand(const char* /*args*/)
524 sLog
.outString( "Re-Loading Skill Extra Item Table..." );
525 LoadSkillExtraItemTable();
526 SendGlobalSysMessage("DB table `skill_extra_item_template` (extra item creation when crafting) reloaded.");
530 bool ChatHandler::HandleReloadSkillFishingBaseLevelCommand(const char* /*args*/)
532 sLog
.outString( "Re-Loading Skill Fishing base level requirements..." );
533 sObjectMgr
.LoadFishingBaseSkillLevel();
534 SendGlobalSysMessage("DB table `skill_fishing_base_level` (fishing base level for zone/subzone) reloaded.");
538 bool ChatHandler::HandleReloadSpellAreaCommand(const char*)
540 sLog
.outString( "Re-Loading SpellArea Data..." );
541 sSpellMgr
.LoadSpellAreas();
542 SendGlobalSysMessage("DB table `spell_area` (spell dependences from area/quest/auras state) reloaded.");
546 bool ChatHandler::HandleReloadSpellChainCommand(const char*)
548 sLog
.outString( "Re-Loading Spell Chain Data... " );
549 sSpellMgr
.LoadSpellChains();
550 SendGlobalSysMessage("DB table `spell_chain` (spell ranks) reloaded.");
554 bool ChatHandler::HandleReloadSpellElixirCommand(const char*)
556 sLog
.outString( "Re-Loading Spell Elixir types..." );
557 sSpellMgr
.LoadSpellElixirs();
558 SendGlobalSysMessage("DB table `spell_elixir` (spell elixir types) reloaded.");
562 bool ChatHandler::HandleReloadSpellLearnSpellCommand(const char*)
564 sLog
.outString( "Re-Loading Spell Learn Spells..." );
565 sSpellMgr
.LoadSpellLearnSpells();
566 SendGlobalSysMessage("DB table `spell_learn_spell` reloaded.");
570 bool ChatHandler::HandleReloadSpellProcEventCommand(const char*)
572 sLog
.outString( "Re-Loading Spell Proc Event conditions..." );
573 sSpellMgr
.LoadSpellProcEvents();
574 SendGlobalSysMessage("DB table `spell_proc_event` (spell proc trigger requirements) reloaded.");
578 bool ChatHandler::HandleReloadSpellBonusesCommand(const char*)
580 sLog
.outString( "Re-Loading Spell Bonus Data..." );
581 sSpellMgr
.LoadSpellBonusess();
582 SendGlobalSysMessage("DB table `spell_bonus_data` (spell damage/healing coefficients) reloaded.");
586 bool ChatHandler::HandleReloadSpellProcItemEnchantCommand(const char*)
588 sLog
.outString( "Re-Loading Spell Proc Item Enchant..." );
589 sSpellMgr
.LoadSpellProcItemEnchant();
590 SendGlobalSysMessage("DB table `spell_proc_item_enchant` (item enchantment ppm) reloaded.");
594 bool ChatHandler::HandleReloadSpellScriptTargetCommand(const char*)
596 sLog
.outString( "Re-Loading SpellsScriptTarget..." );
597 sSpellMgr
.LoadSpellScriptTarget();
598 SendGlobalSysMessage("DB table `spell_script_target` (spell targets selection in case specific creature/GO requirements) reloaded.");
602 bool ChatHandler::HandleReloadSpellTargetPositionCommand(const char*)
604 sLog
.outString( "Re-Loading Spell target coordinates..." );
605 sSpellMgr
.LoadSpellTargetPositions();
606 SendGlobalSysMessage("DB table `spell_target_position` (destination coordinates for spell targets) reloaded.");
610 bool ChatHandler::HandleReloadSpellThreatsCommand(const char*)
612 sLog
.outString( "Re-Loading Aggro Spells Definitions...");
613 sSpellMgr
.LoadSpellThreats();
614 SendGlobalSysMessage("DB table `spell_threat` (spell aggro definitions) reloaded.");
618 bool ChatHandler::HandleReloadSpellPetAurasCommand(const char*)
620 sLog
.outString( "Re-Loading Spell pet auras...");
621 sSpellMgr
.LoadSpellPetAuras();
622 SendGlobalSysMessage("DB table `spell_pet_auras` reloaded.");
626 bool ChatHandler::HandleReloadPageTextsCommand(const char*)
628 sLog
.outString( "Re-Loading Page Texts..." );
629 sObjectMgr
.LoadPageTexts();
630 SendGlobalSysMessage("DB table `page_texts` reloaded.");
634 bool ChatHandler::HandleReloadItemEnchantementsCommand(const char*)
636 sLog
.outString( "Re-Loading Item Random Enchantments Table..." );
637 LoadRandomEnchantmentsTable();
638 SendGlobalSysMessage("DB table `item_enchantment_template` reloaded.");
642 bool ChatHandler::HandleReloadItemRequiredTragetCommand(const char*)
644 sLog
.outString( "Re-Loading Item Required Targets Table..." );
645 sObjectMgr
.LoadItemRequiredTarget();
646 SendGlobalSysMessage("DB table `item_required_target` reloaded.");
650 bool ChatHandler::HandleReloadBattleEventCommand(const char*)
652 sLog
.outString( "Re-Loading BattleGround Eventindexes..." );
653 sBattleGroundMgr
.LoadBattleEventIndexes();
654 SendGlobalSysMessage("DB table `gameobject_battleground` and `creature_battleground` reloaded.");
658 bool ChatHandler::HandleReloadGameObjectScriptsCommand(const char* arg
)
660 if(sWorld
.IsScriptScheduled())
662 SendSysMessage("DB scripts used currently, please attempt reload later.");
663 SetSentErrorMessage(true);
668 sLog
.outString( "Re-Loading Scripts from `gameobject_scripts`...");
670 sObjectMgr
.LoadGameObjectScripts();
673 SendGlobalSysMessage("DB table `gameobject_scripts` reloaded.");
678 bool ChatHandler::HandleReloadEventScriptsCommand(const char* arg
)
680 if(sWorld
.IsScriptScheduled())
682 SendSysMessage("DB scripts used currently, please attempt reload later.");
683 SetSentErrorMessage(true);
688 sLog
.outString( "Re-Loading Scripts from `event_scripts`...");
690 sObjectMgr
.LoadEventScripts();
693 SendGlobalSysMessage("DB table `event_scripts` reloaded.");
698 bool ChatHandler::HandleReloadEventAITextsCommand(const char* /*arg*/)
701 sLog
.outString( "Re-Loading Texts from `creature_ai_texts`...");
702 sEventAIMgr
.LoadCreatureEventAI_Texts(true);
703 SendGlobalSysMessage("DB table `creature_ai_texts` reloaded.");
707 bool ChatHandler::HandleReloadEventAISummonsCommand(const char* /*arg*/)
709 sLog
.outString( "Re-Loading Summons from `creature_ai_summons`...");
710 sEventAIMgr
.LoadCreatureEventAI_Summons(true);
711 SendGlobalSysMessage("DB table `creature_ai_summons` reloaded.");
715 bool ChatHandler::HandleReloadEventAIScriptsCommand(const char* /*arg*/)
717 sLog
.outString( "Re-Loading Scripts from `creature_ai_scripts`...");
718 sEventAIMgr
.LoadCreatureEventAI_Scripts();
719 SendGlobalSysMessage("DB table `creature_ai_scripts` reloaded.");
723 bool ChatHandler::HandleReloadQuestEndScriptsCommand(const char* arg
)
725 if(sWorld
.IsScriptScheduled())
727 SendSysMessage("DB scripts used currently, please attempt reload later.");
728 SetSentErrorMessage(true);
733 sLog
.outString( "Re-Loading Scripts from `quest_end_scripts`...");
735 sObjectMgr
.LoadQuestEndScripts();
738 SendGlobalSysMessage("DB table `quest_end_scripts` reloaded.");
743 bool ChatHandler::HandleReloadQuestStartScriptsCommand(const char* arg
)
745 if(sWorld
.IsScriptScheduled())
747 SendSysMessage("DB scripts used currently, please attempt reload later.");
748 SetSentErrorMessage(true);
753 sLog
.outString( "Re-Loading Scripts from `quest_start_scripts`...");
755 sObjectMgr
.LoadQuestStartScripts();
758 SendGlobalSysMessage("DB table `quest_start_scripts` reloaded.");
763 bool ChatHandler::HandleReloadSpellScriptsCommand(const char* arg
)
765 if(sWorld
.IsScriptScheduled())
767 SendSysMessage("DB scripts used currently, please attempt reload later.");
768 SetSentErrorMessage(true);
773 sLog
.outString( "Re-Loading Scripts from `spell_scripts`...");
775 sObjectMgr
.LoadSpellScripts();
778 SendGlobalSysMessage("DB table `spell_scripts` reloaded.");
783 bool ChatHandler::HandleReloadDbScriptStringCommand(const char* /*arg*/)
785 sLog
.outString( "Re-Loading Script strings from `db_script_string`...");
786 sObjectMgr
.LoadDbScriptStrings();
787 SendGlobalSysMessage("DB table `db_script_string` reloaded.");
791 bool ChatHandler::HandleReloadGameGraveyardZoneCommand(const char* /*arg*/)
793 sLog
.outString( "Re-Loading Graveyard-zone links...");
795 sObjectMgr
.LoadGraveyardZones();
797 SendGlobalSysMessage("DB table `game_graveyard_zone` reloaded.");
802 bool ChatHandler::HandleReloadGameTeleCommand(const char* /*arg*/)
804 sLog
.outString( "Re-Loading Game Tele coordinates...");
806 sObjectMgr
.LoadGameTele();
808 SendGlobalSysMessage("DB table `game_tele` reloaded.");
813 bool ChatHandler::HandleReloadLocalesAchievementRewardCommand(const char*)
815 sLog
.outString( "Re-Loading Locales Achievement Reward Data..." );
816 sAchievementMgr
.LoadRewardLocales();
817 SendGlobalSysMessage("DB table `locales_achievement_reward` reloaded.");
821 bool ChatHandler::HandleReloadLocalesCreatureCommand(const char* /*arg*/)
823 sLog
.outString( "Re-Loading Locales Creature ...");
824 sObjectMgr
.LoadCreatureLocales();
825 SendGlobalSysMessage("DB table `locales_creature` reloaded.");
829 bool ChatHandler::HandleReloadLocalesGameobjectCommand(const char* /*arg*/)
831 sLog
.outString( "Re-Loading Locales Gameobject ... ");
832 sObjectMgr
.LoadGameObjectLocales();
833 SendGlobalSysMessage("DB table `locales_gameobject` reloaded.");
837 bool ChatHandler::HandleReloadLocalesGossipMenuOptionCommand(const char* /*arg*/)
839 sLog
.outString( "Re-Loading Locales Gossip Menu Option ... ");
840 sObjectMgr
.LoadGossipMenuItemsLocales();
841 SendGlobalSysMessage("DB table `locales_gossip_menu_option` reloaded.");
845 bool ChatHandler::HandleReloadLocalesItemCommand(const char* /*arg*/)
847 sLog
.outString( "Re-Loading Locales Item ... ");
848 sObjectMgr
.LoadItemLocales();
849 SendGlobalSysMessage("DB table `locales_item` reloaded.");
853 bool ChatHandler::HandleReloadLocalesNpcTextCommand(const char* /*arg*/)
855 sLog
.outString( "Re-Loading Locales NPC Text ... ");
856 sObjectMgr
.LoadNpcTextLocales();
857 SendGlobalSysMessage("DB table `locales_npc_text` reloaded.");
861 bool ChatHandler::HandleReloadLocalesPageTextCommand(const char* /*arg*/)
863 sLog
.outString( "Re-Loading Locales Page Text ... ");
864 sObjectMgr
.LoadPageTextLocales();
865 SendGlobalSysMessage("DB table `locales_page_text` reloaded.");
869 bool ChatHandler::HandleReloadLocalesPointsOfInterestCommand(const char* /*arg*/)
871 sLog
.outString( "Re-Loading Locales Points Of Interest ... ");
872 sObjectMgr
.LoadPointOfInterestLocales();
873 SendGlobalSysMessage("DB table `locales_points_of_interest` reloaded.");
877 bool ChatHandler::HandleReloadLocalesQuestCommand(const char* /*arg*/)
879 sLog
.outString( "Re-Loading Locales Quest ... ");
880 sObjectMgr
.LoadQuestLocales();
881 SendGlobalSysMessage("DB table `locales_quest` reloaded.");
885 bool ChatHandler::HandleReloadMailLevelRewardCommand(const char* /*arg*/)
887 sLog
.outString( "Re-Loading Player level dependent mail rewards..." );
888 sObjectMgr
.LoadMailLevelRewards();
889 SendGlobalSysMessage("DB table `mail_level_reward` reloaded.");
893 bool ChatHandler::HandleLoadScriptsCommand(const char* args
)
895 if(!LoadScriptingModule(args
)) return true;
897 sWorld
.SendWorldText(LANG_SCRIPTS_RELOADED
);
901 bool ChatHandler::HandleAccountSetGmLevelCommand(const char* args
)
903 char* arg1
= strtok((char*)args
, " ");
907 /// must be NULL if targeted syntax and must be not nULL if not targeted
908 char* arg2
= strtok(NULL
, " ");
910 std::string targetAccountName
;
911 uint32 targetAccountId
= 0;
913 /// only target player different from self allowed (if targetPlayer!=NULL then not console)
914 Player
* targetPlayer
= getSelectedPlayer();
915 if(targetPlayer
&& m_session
->GetPlayer()!=targetPlayer
)
917 /// wrong command syntax or unexpected targeting
921 /// security level expected in arg2 after this if.
924 targetAccountId
= targetPlayer
->GetSession()->GetAccountId();
925 sAccountMgr
.GetName(targetAccountId
, targetAccountName
);
929 /// wrong command syntax (second arg expected)
933 targetAccountName
= arg1
;
934 if (!AccountMgr::normalizeString(targetAccountName
))
936 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,targetAccountName
.c_str());
937 SetSentErrorMessage(true);
941 targetAccountId
= sAccountMgr
.GetId(targetAccountName
);
944 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,targetAccountName
.c_str());
945 SetSentErrorMessage(true);
950 int32 gm
= (int32
)atoi(arg2
);
951 if ( gm
< SEC_PLAYER
|| gm
> SEC_ADMINISTRATOR
)
953 SendSysMessage(LANG_BAD_VALUE
);
954 SetSentErrorMessage(true);
958 /// can set security level only for target with less security and to less security that we have
959 /// This will reject self apply by specify account name
960 if(HasLowerSecurityAccount(NULL
,targetAccountId
,true))
963 /// account can't set security to same or grater level, need more power GM or console
964 AccountTypes plSecurity
= m_session
? m_session
->GetSecurity() : SEC_CONSOLE
;
965 if (AccountTypes(gm
) >= plSecurity
)
967 SendSysMessage(LANG_YOURS_SECURITY_IS_LOW
);
968 SetSentErrorMessage(true);
972 // This will prevent self apply by self target or no target
973 if(targetPlayer
&& m_session
->GetPlayer()!=targetPlayer
)
975 ChatHandler(targetPlayer
).PSendSysMessage(LANG_YOURS_SECURITY_CHANGED
,GetNameLink().c_str(), gm
);
976 targetPlayer
->GetSession()->SetSecurity(AccountTypes(gm
));
979 PSendSysMessage(LANG_YOU_CHANGE_SECURITY
, targetAccountName
.c_str(), gm
);
980 loginDatabase
.PExecute("UPDATE account SET gmlevel = '%i' WHERE id = '%u'", gm
, targetAccountId
);
985 /// Set password for account
986 bool ChatHandler::HandleAccountSetPasswordCommand(const char* args
)
991 ///- Get the command line arguments
992 char *szAccount
= strtok ((char*)args
," ");
993 char *szPassword1
= strtok (NULL
," ");
994 char *szPassword2
= strtok (NULL
," ");
996 if (!szAccount
||!szPassword1
|| !szPassword2
)
999 std::string account_name
= szAccount
;
1000 if (!AccountMgr::normalizeString(account_name
))
1002 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
1003 SetSentErrorMessage(true);
1007 uint32 targetAccountId
= sAccountMgr
.GetId(account_name
);
1008 if (!targetAccountId
)
1010 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
1011 SetSentErrorMessage(true);
1015 /// can set password only for target with less security
1016 /// This is also reject self apply in fact
1017 if(HasLowerSecurityAccount (NULL
,targetAccountId
,true))
1020 if (strcmp(szPassword1
,szPassword2
))
1022 SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH
);
1023 SetSentErrorMessage (true);
1027 AccountOpResult result
= sAccountMgr
.ChangePassword(targetAccountId
, szPassword1
);
1032 SendSysMessage(LANG_COMMAND_PASSWORD
);
1034 case AOR_NAME_NOT_EXIST
:
1035 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
1036 SetSentErrorMessage(true);
1038 case AOR_PASS_TOO_LONG
:
1039 SendSysMessage(LANG_PASSWORD_TOO_LONG
);
1040 SetSentErrorMessage(true);
1043 SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD
);
1044 SetSentErrorMessage(true);
1051 bool ChatHandler::HandleMaxSkillCommand(const char* /*args*/)
1053 Player
* SelectedPlayer
= getSelectedPlayer();
1056 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1057 SetSentErrorMessage(true);
1061 // each skills that have max skill value dependent from level seted to current level max skill value
1062 SelectedPlayer
->UpdateSkillsToMaxSkillsForLevel();
1066 bool ChatHandler::HandleSetSkillCommand(const char* args
)
1068 // number or [name] Shift-click form |color|Hskill:skill_id|h[name]|h|r
1069 char* skill_p
= extractKeyFromLink((char*)args
,"Hskill");
1073 char *level_p
= strtok (NULL
, " ");
1078 char *max_p
= strtok (NULL
, " ");
1080 int32 skill
= atoi(skill_p
);
1083 PSendSysMessage(LANG_INVALID_SKILL_ID
, skill
);
1084 SetSentErrorMessage(true);
1088 int32 level
= atol (level_p
);
1090 Player
* target
= getSelectedPlayer();
1093 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1094 SetSentErrorMessage(true);
1098 SkillLineEntry
const* sl
= sSkillLineStore
.LookupEntry(skill
);
1101 PSendSysMessage(LANG_INVALID_SKILL_ID
, skill
);
1102 SetSentErrorMessage(true);
1106 std::string tNameLink
= GetNameLink(target
);
1108 if(!target
->GetSkillValue(skill
))
1110 PSendSysMessage(LANG_SET_SKILL_ERROR
, tNameLink
.c_str(), skill
, sl
->name
[GetSessionDbcLocale()]);
1111 SetSentErrorMessage(true);
1115 int32 max
= max_p
? atol (max_p
) : target
->GetPureMaxSkillValue(skill
);
1117 if( level
<= 0 || level
> max
|| max
<= 0 )
1120 target
->SetSkill(skill
, level
, max
);
1121 PSendSysMessage(LANG_SET_SKILL
, skill
, sl
->name
[GetSessionDbcLocale()], tNameLink
.c_str(), level
, max
);
1126 bool ChatHandler::HandleUnLearnCommand(const char* args
)
1131 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
1132 uint32 spell_id
= extractSpellIdFromLink((char*)args
);
1136 char const* allStr
= strtok(NULL
," ");
1137 bool allRanks
= allStr
? (strncmp(allStr
, "all", strlen(allStr
)) == 0) : false;
1139 Player
* target
= getSelectedPlayer();
1142 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1143 SetSentErrorMessage(true);
1148 spell_id
= sSpellMgr
.GetFirstSpellInChain (spell_id
);
1150 if (target
->HasSpell(spell_id
))
1151 target
->removeSpell(spell_id
,false,!allRanks
);
1153 SendSysMessage(LANG_FORGET_SPELL
);
1155 if(GetTalentSpellCost(spell_id
))
1156 target
->SendTalentsInfoData(false);
1161 bool ChatHandler::HandleCooldownCommand(const char* args
)
1163 Player
* target
= getSelectedPlayer();
1166 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1167 SetSentErrorMessage(true);
1171 std::string tNameLink
= GetNameLink(target
);
1175 target
->RemoveAllSpellCooldown();
1176 PSendSysMessage(LANG_REMOVEALL_COOLDOWN
, tNameLink
.c_str());
1180 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1181 uint32 spell_id
= extractSpellIdFromLink((char*)args
);
1185 if(!sSpellStore
.LookupEntry(spell_id
))
1187 PSendSysMessage(LANG_UNKNOWN_SPELL
, target
==m_session
->GetPlayer() ? GetMangosString(LANG_YOU
) : tNameLink
.c_str());
1188 SetSentErrorMessage(true);
1192 target
->RemoveSpellCooldown(spell_id
,true);
1193 PSendSysMessage(LANG_REMOVE_COOLDOWN
, spell_id
, target
==m_session
->GetPlayer() ? GetMangosString(LANG_YOU
) : tNameLink
.c_str());
1198 bool ChatHandler::HandleLearnAllCommand(const char* /*args*/)
1200 static const char *allSpellList
[] =
1583 //"9036", problems with ghost state
1592 //"6718", phasing stealth, annoying for learn all case.
1805 while(strcmp(allSpellList
[loop
], "0"))
1807 uint32 spell
= atol((char*)allSpellList
[loop
++]);
1809 if (m_session
->GetPlayer()->HasSpell(spell
))
1812 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1813 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1815 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1819 m_session
->GetPlayer()->learnSpell(spell
,false);
1822 SendSysMessage(LANG_COMMAND_LEARN_MANY_SPELLS
);
1827 bool ChatHandler::HandleLearnAllGMCommand(const char* /*args*/)
1829 static const char *gmSpellList
[] =
1831 "24347", // Become A Fish, No Breath Bar
1832 "35132", // Visual Boom
1833 "38488", // Attack 4000-8000 AOE
1834 "38795", // Attack 2000 AOE + Slow Down 90%
1835 "15712", // Attack 200
1836 "1852", // GM Spell Silence
1839 "29878", // Kill My Self
1840 "26644", // More Kill
1842 "28550", //Invisible 24
1843 "23452", //Invisible + Target
1847 uint16 gmSpellIter
= 0;
1848 while( strcmp(gmSpellList
[gmSpellIter
], "0") )
1850 uint32 spell
= atol((char*)gmSpellList
[gmSpellIter
++]);
1852 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1853 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1855 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1859 m_session
->GetPlayer()->learnSpell(spell
,false);
1862 SendSysMessage(LANG_LEARNING_GM_SKILLS
);
1866 bool ChatHandler::HandleLearnAllMyClassCommand(const char* /*args*/)
1868 HandleLearnAllMySpellsCommand("");
1869 HandleLearnAllMyTalentsCommand("");
1873 bool ChatHandler::HandleLearnAllMySpellsCommand(const char* /*args*/)
1875 ChrClassesEntry
const* clsEntry
= sChrClassesStore
.LookupEntry(m_session
->GetPlayer()->getClass());
1878 uint32 family
= clsEntry
->spellfamily
;
1880 for (uint32 i
= 0; i
< sSpellStore
.GetNumRows(); ++i
)
1882 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(i
);
1886 // skip server-side/triggered spells
1887 if(spellInfo
->spellLevel
==0)
1890 // skip wrong class/race skills
1891 if(!m_session
->GetPlayer()->IsSpellFitByClassAndRace(spellInfo
->Id
))
1894 // skip other spell families
1895 if( spellInfo
->SpellFamilyName
!= family
)
1898 // skip spells with first rank learned as talent (and all talents then also)
1899 uint32 first_rank
= sSpellMgr
.GetFirstSpellInChain(spellInfo
->Id
);
1900 if(GetTalentSpellCost(first_rank
) > 0 )
1903 // skip broken spells
1904 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1907 m_session
->GetPlayer()->learnSpell(i
,false);
1910 SendSysMessage(LANG_COMMAND_LEARN_CLASS_SPELLS
);
1914 bool ChatHandler::HandleLearnAllMyTalentsCommand(const char* /*args*/)
1916 Player
* player
= m_session
->GetPlayer();
1917 uint32 classMask
= player
->getClassMask();
1919 for (uint32 i
= 0; i
< sTalentStore
.GetNumRows(); ++i
)
1921 TalentEntry
const *talentInfo
= sTalentStore
.LookupEntry(i
);
1925 TalentTabEntry
const *talentTabInfo
= sTalentTabStore
.LookupEntry( talentInfo
->TalentTab
);
1929 if( (classMask
& talentTabInfo
->ClassMask
) == 0 )
1932 // search highest talent rank
1935 for(int rank
= MAX_TALENT_RANK
-1; rank
>= 0; --rank
)
1937 if(talentInfo
->RankID
[rank
]!=0)
1939 spellid
= talentInfo
->RankID
[rank
];
1944 if(!spellid
) // ??? none spells in talent
1947 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spellid
);
1948 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1951 // learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
1952 player
->learnSpellHighRank(spellid
);
1955 SendSysMessage(LANG_COMMAND_LEARN_CLASS_TALENTS
);
1959 bool ChatHandler::HandleLearnAllMyPetTalentsCommand(const char* /*args*/)
1961 Player
* player
= m_session
->GetPlayer();
1963 Pet
* pet
= player
->GetPet();
1966 SendSysMessage(LANG_NO_PET_FOUND
);
1967 SetSentErrorMessage(true);
1971 CreatureInfo
const *ci
= pet
->GetCreatureInfo();
1974 SendSysMessage(LANG_WRONG_PET_TYPE
);
1975 SetSentErrorMessage(true);
1979 CreatureFamilyEntry
const *pet_family
= sCreatureFamilyStore
.LookupEntry(ci
->family
);
1982 SendSysMessage(LANG_WRONG_PET_TYPE
);
1983 SetSentErrorMessage(true);
1987 if(pet_family
->petTalentType
< 0) // not hunter pet
1989 SendSysMessage(LANG_WRONG_PET_TYPE
);
1990 SetSentErrorMessage(true);
1994 for (uint32 i
= 0; i
< sTalentStore
.GetNumRows(); ++i
)
1996 TalentEntry
const *talentInfo
= sTalentStore
.LookupEntry(i
);
2000 TalentTabEntry
const *talentTabInfo
= sTalentTabStore
.LookupEntry( talentInfo
->TalentTab
);
2004 // prevent learn talent for different family (cheating)
2005 if(((1 << pet_family
->petTalentType
) & talentTabInfo
->petTalentMask
)==0)
2008 // search highest talent rank
2011 for(int rank
= MAX_TALENT_RANK
-1; rank
>= 0; --rank
)
2013 if(talentInfo
->RankID
[rank
]!=0)
2015 spellid
= talentInfo
->RankID
[rank
];
2020 if(!spellid
) // ??? none spells in talent
2023 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spellid
);
2024 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
2027 // learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
2028 pet
->learnSpellHighRank(spellid
);
2031 SendSysMessage(LANG_COMMAND_LEARN_PET_TALENTS
);
2035 bool ChatHandler::HandleLearnAllLangCommand(const char* /*args*/)
2037 // skipping UNIVERSAL language (0)
2038 for(int i
= 1; i
< LANGUAGES_COUNT
; ++i
)
2039 m_session
->GetPlayer()->learnSpell(lang_description
[i
].spell_id
,false);
2041 SendSysMessage(LANG_COMMAND_LEARN_ALL_LANG
);
2045 bool ChatHandler::HandleLearnAllDefaultCommand(const char* args
)
2048 if(!extractPlayerTarget((char*)args
,&target
))
2051 target
->learnDefaultSpells();
2052 target
->learnQuestRewardedSpells();
2054 PSendSysMessage(LANG_COMMAND_LEARN_ALL_DEFAULT_AND_QUEST
,GetNameLink(target
).c_str());
2058 bool ChatHandler::HandleLearnCommand(const char* args
)
2060 Player
* targetPlayer
= getSelectedPlayer();
2064 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
2065 SetSentErrorMessage(true);
2069 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
2070 uint32 spell
= extractSpellIdFromLink((char*)args
);
2071 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
2074 char const* allStr
= strtok(NULL
," ");
2075 bool allRanks
= allStr
? (strncmp(allStr
, "all", strlen(allStr
)) == 0) : false;
2077 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
2078 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
2080 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
2081 SetSentErrorMessage(true);
2085 if (!allRanks
&& targetPlayer
->HasSpell(spell
))
2087 if(targetPlayer
== m_session
->GetPlayer())
2088 SendSysMessage(LANG_YOU_KNOWN_SPELL
);
2090 PSendSysMessage(LANG_TARGET_KNOWN_SPELL
,GetNameLink(targetPlayer
).c_str());
2091 SetSentErrorMessage(true);
2096 targetPlayer
->learnSpellHighRank(spell
);
2098 targetPlayer
->learnSpell(spell
,false);
2100 uint32 first_spell
= sSpellMgr
.GetFirstSpellInChain(spell
);
2101 if(GetTalentSpellCost(first_spell
))
2102 targetPlayer
->SendTalentsInfoData(false);
2107 bool ChatHandler::HandleAddItemCommand(const char* args
)
2114 if(args
[0]=='[') // [name] manual form
2116 char* citemName
= strtok((char*)args
, "]");
2118 if(citemName
&& citemName
[0])
2120 std::string itemName
= citemName
+1;
2121 WorldDatabase
.escape_string(itemName
);
2122 QueryResult
*result
= WorldDatabase
.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName
.c_str());
2125 PSendSysMessage(LANG_COMMAND_COULDNOTFIND
, citemName
+1);
2126 SetSentErrorMessage(true);
2129 itemId
= result
->Fetch()->GetUInt16();
2135 else // item_id or [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r
2137 char* cId
= extractKeyFromLink((char*)args
,"Hitem");
2143 char* ccount
= strtok(NULL
, " ");
2148 count
= strtol(ccount
, NULL
, 10);
2153 Player
* pl
= m_session
->GetPlayer();
2154 Player
* plTarget
= getSelectedPlayer();
2158 sLog
.outDetail(GetMangosString(LANG_ADDITEM
), itemId
, count
);
2160 ItemPrototype
const *pProto
= ObjectMgr::GetItemPrototype(itemId
);
2163 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, itemId
);
2164 SetSentErrorMessage(true);
2171 plTarget
->DestroyItemCount(itemId
, -count
, true, false);
2172 PSendSysMessage(LANG_REMOVEITEM
, itemId
, -count
, GetNameLink(plTarget
).c_str());
2177 uint32 noSpaceForCount
= 0;
2179 // check space and find places
2180 ItemPosCountVec dest
;
2181 uint8 msg
= plTarget
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, itemId
, count
, &noSpaceForCount
);
2182 if( msg
!= EQUIP_ERR_OK
) // convert to possible store amount
2183 count
-= noSpaceForCount
;
2185 if( count
== 0 || dest
.empty()) // can't add any
2187 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, itemId
, noSpaceForCount
);
2188 SetSentErrorMessage(true);
2192 Item
* item
= plTarget
->StoreNewItem( dest
, itemId
, true, Item::GenerateItemRandomPropertyId(itemId
));
2194 // remove binding (let GM give it to another player later)
2196 for(ItemPosCountVec::const_iterator itr
= dest
.begin(); itr
!= dest
.end(); ++itr
)
2197 if(Item
* item1
= pl
->GetItemByPos(itr
->pos
))
2198 item1
->SetBinding( false );
2200 if(count
> 0 && item
)
2202 pl
->SendNewItem(item
,count
,false,true);
2204 plTarget
->SendNewItem(item
,count
,true,false);
2207 if(noSpaceForCount
> 0)
2208 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, itemId
, noSpaceForCount
);
2213 bool ChatHandler::HandleAddItemSetCommand(const char* args
)
2218 char* cId
= extractKeyFromLink((char*)args
,"Hitemset"); // number or [name] Shift-click form |color|Hitemset:itemset_id|h[name]|h|r
2222 uint32 itemsetId
= atol(cId
);
2224 // prevent generation all items with itemset field value '0'
2227 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND
,itemsetId
);
2228 SetSentErrorMessage(true);
2232 Player
* pl
= m_session
->GetPlayer();
2233 Player
* plTarget
= getSelectedPlayer();
2237 sLog
.outDetail(GetMangosString(LANG_ADDITEMSET
), itemsetId
);
2240 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
2242 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
2246 if (pProto
->ItemSet
== itemsetId
)
2249 ItemPosCountVec dest
;
2250 uint8 msg
= plTarget
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, pProto
->ItemId
, 1 );
2251 if (msg
== EQUIP_ERR_OK
)
2253 Item
* item
= plTarget
->StoreNewItem( dest
, pProto
->ItemId
, true);
2255 // remove binding (let GM give it to another player later)
2257 item
->SetBinding( false );
2259 pl
->SendNewItem(item
,1,false,true);
2261 plTarget
->SendNewItem(item
,1,true,false);
2265 pl
->SendEquipError( msg
, NULL
, NULL
);
2266 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, pProto
->ItemId
, 1);
2273 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND
,itemsetId
);
2275 SetSentErrorMessage(true);
2282 bool ChatHandler::HandleListItemCommand(const char* args
)
2287 char* cId
= extractKeyFromLink((char*)args
,"Hitem");
2291 uint32 item_id
= atol(cId
);
2294 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
2295 SetSentErrorMessage(true);
2299 ItemPrototype
const* itemProto
= ObjectMgr::GetItemPrototype(item_id
);
2302 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
2303 SetSentErrorMessage(true);
2307 char* c_count
= strtok(NULL
, " ");
2308 int count
= c_count
? atol(c_count
) : 10;
2313 QueryResult
*result
;
2316 uint32 inv_count
= 0;
2317 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM character_inventory WHERE item_template='%u'",item_id
);
2320 inv_count
= (*result
)[0].GetUInt32();
2324 result
=CharacterDatabase
.PQuery(
2326 "SELECT ci.item, cibag.slot AS bag, ci.slot, ci.guid, characters.account,characters.name "
2327 "FROM character_inventory AS ci LEFT JOIN character_inventory AS cibag ON (cibag.item=ci.bag),characters "
2328 "WHERE ci.item_template='%u' AND ci.guid = characters.guid LIMIT %u ",
2329 item_id
,uint32(count
));
2335 Field
*fields
= result
->Fetch();
2336 uint32 item_guid
= fields
[0].GetUInt32();
2337 uint32 item_bag
= fields
[1].GetUInt32();
2338 uint32 item_slot
= fields
[2].GetUInt32();
2339 uint32 owner_guid
= fields
[3].GetUInt32();
2340 uint32 owner_acc
= fields
[4].GetUInt32();
2341 std::string owner_name
= fields
[5].GetCppString();
2343 char const* item_pos
= 0;
2344 if(Player::IsEquipmentPos(item_bag
,item_slot
))
2345 item_pos
= "[equipped]";
2346 else if(Player::IsInventoryPos(item_bag
,item_slot
))
2347 item_pos
= "[in inventory]";
2348 else if(Player::IsBankPos(item_bag
,item_slot
))
2349 item_pos
= "[in bank]";
2353 PSendSysMessage(LANG_ITEMLIST_SLOT
,
2354 item_guid
,owner_name
.c_str(),owner_guid
,owner_acc
,item_pos
);
2355 } while (result
->NextRow());
2357 int res_count
= (int)result
->GetRowCount();
2361 if(count
> res_count
)
2368 uint32 mail_count
= 0;
2369 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM mail_items WHERE item_template='%u'", item_id
);
2372 mail_count
= (*result
)[0].GetUInt32();
2378 result
=CharacterDatabase
.PQuery(
2380 "SELECT mail_items.item_guid, mail.sender, mail.receiver, char_s.account, char_s.name, char_r.account, char_r.name "
2381 "FROM mail,mail_items,characters as char_s,characters as char_r "
2382 "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",
2383 item_id
,uint32(count
));
2392 Field
*fields
= result
->Fetch();
2393 uint32 item_guid
= fields
[0].GetUInt32();
2394 uint32 item_s
= fields
[1].GetUInt32();
2395 uint32 item_r
= fields
[2].GetUInt32();
2396 uint32 item_s_acc
= fields
[3].GetUInt32();
2397 std::string item_s_name
= fields
[4].GetCppString();
2398 uint32 item_r_acc
= fields
[5].GetUInt32();
2399 std::string item_r_name
= fields
[6].GetCppString();
2401 char const* item_pos
= "[in mail]";
2403 PSendSysMessage(LANG_ITEMLIST_MAIL
,
2404 item_guid
,item_s_name
.c_str(),item_s
,item_s_acc
,item_r_name
.c_str(),item_r
,item_r_acc
,item_pos
);
2405 } while (result
->NextRow());
2407 int res_count
= (int)result
->GetRowCount();
2411 if(count
> res_count
)
2418 uint32 auc_count
= 0;
2419 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM auctionhouse WHERE item_template='%u'",item_id
);
2422 auc_count
= (*result
)[0].GetUInt32();
2428 result
=CharacterDatabase
.PQuery(
2430 "SELECT auctionhouse.itemguid, auctionhouse.itemowner, characters.account, characters.name "
2431 "FROM auctionhouse,characters WHERE auctionhouse.item_template='%u' AND characters.guid = auctionhouse.itemowner LIMIT %u",
2432 item_id
,uint32(count
));
2441 Field
*fields
= result
->Fetch();
2442 uint32 item_guid
= fields
[0].GetUInt32();
2443 uint32 owner
= fields
[1].GetUInt32();
2444 uint32 owner_acc
= fields
[2].GetUInt32();
2445 std::string owner_name
= fields
[3].GetCppString();
2447 char const* item_pos
= "[in auction]";
2449 PSendSysMessage(LANG_ITEMLIST_AUCTION
, item_guid
, owner_name
.c_str(), owner
, owner_acc
,item_pos
);
2450 } while (result
->NextRow());
2456 uint32 guild_count
= 0;
2457 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_entry) FROM guild_bank_item WHERE item_entry='%u'",item_id
);
2460 guild_count
= (*result
)[0].GetUInt32();
2464 result
=CharacterDatabase
.PQuery(
2466 "SELECT gi.item_guid, gi.guildid, guild.name "
2467 "FROM guild_bank_item AS gi, guild WHERE gi.item_entry='%u' AND gi.guildid = guild.guildid LIMIT %u ",
2468 item_id
,uint32(count
));
2474 Field
*fields
= result
->Fetch();
2475 uint32 item_guid
= fields
[0].GetUInt32();
2476 uint32 guild_guid
= fields
[1].GetUInt32();
2477 std::string guild_name
= fields
[2].GetCppString();
2479 char const* item_pos
= "[in guild bank]";
2481 PSendSysMessage(LANG_ITEMLIST_GUILD
,item_guid
,guild_name
.c_str(),guild_guid
,item_pos
);
2482 } while (result
->NextRow());
2484 int res_count
= (int)result
->GetRowCount();
2488 if(count
> res_count
)
2494 if(inv_count
+mail_count
+auc_count
+guild_count
== 0)
2496 SendSysMessage(LANG_COMMAND_NOITEMFOUND
);
2497 SetSentErrorMessage(true);
2501 PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE
,item_id
,inv_count
+mail_count
+auc_count
+guild_count
,inv_count
,mail_count
,auc_count
,guild_count
);
2506 bool ChatHandler::HandleListObjectCommand(const char* args
)
2511 // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2512 char* cId
= extractKeyFromLink((char*)args
,"Hgameobject_entry");
2516 uint32 go_id
= atol(cId
);
2519 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID
, go_id
);
2520 SetSentErrorMessage(true);
2524 GameObjectInfo
const * gInfo
= ObjectMgr::GetGameObjectInfo(go_id
);
2527 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID
, go_id
);
2528 SetSentErrorMessage(true);
2532 char* c_count
= strtok(NULL
, " ");
2533 int count
= c_count
? atol(c_count
) : 10;
2538 QueryResult
*result
;
2540 uint32 obj_count
= 0;
2541 result
=WorldDatabase
.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'",go_id
);
2544 obj_count
= (*result
)[0].GetUInt32();
2550 Player
* pl
= m_session
->GetPlayer();
2551 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",
2552 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(),go_id
,uint32(count
));
2555 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map FROM gameobject WHERE id = '%u' LIMIT %u",
2556 go_id
,uint32(count
));
2562 Field
*fields
= result
->Fetch();
2563 uint32 guid
= fields
[0].GetUInt32();
2564 float x
= fields
[1].GetFloat();
2565 float y
= fields
[2].GetFloat();
2566 float z
= fields
[3].GetFloat();
2567 int mapid
= fields
[4].GetUInt16();
2570 PSendSysMessage(LANG_GO_LIST_CHAT
, guid
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2572 PSendSysMessage(LANG_GO_LIST_CONSOLE
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2573 } while (result
->NextRow());
2578 PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE
,go_id
,obj_count
);
2582 bool ChatHandler::HandleListCreatureCommand(const char* args
)
2587 // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
2588 char* cId
= extractKeyFromLink((char*)args
,"Hcreature_entry");
2592 uint32 cr_id
= atol(cId
);
2595 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID
, cr_id
);
2596 SetSentErrorMessage(true);
2600 CreatureInfo
const* cInfo
= ObjectMgr::GetCreatureTemplate(cr_id
);
2603 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID
, cr_id
);
2604 SetSentErrorMessage(true);
2608 char* c_count
= strtok(NULL
, " ");
2609 int count
= c_count
? atol(c_count
) : 10;
2614 QueryResult
*result
;
2616 uint32 cr_count
= 0;
2617 result
=WorldDatabase
.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'",cr_id
);
2620 cr_count
= (*result
)[0].GetUInt32();
2626 Player
* pl
= m_session
->GetPlayer();
2627 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",
2628 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(), cr_id
,uint32(count
));
2631 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '%u' LIMIT %u",
2632 cr_id
,uint32(count
));
2638 Field
*fields
= result
->Fetch();
2639 uint32 guid
= fields
[0].GetUInt32();
2640 float x
= fields
[1].GetFloat();
2641 float y
= fields
[2].GetFloat();
2642 float z
= fields
[3].GetFloat();
2643 int mapid
= fields
[4].GetUInt16();
2646 PSendSysMessage(LANG_CREATURE_LIST_CHAT
, guid
, guid
, cInfo
->Name
, x
, y
, z
, mapid
);
2648 PSendSysMessage(LANG_CREATURE_LIST_CONSOLE
, guid
, cInfo
->Name
, x
, y
, z
, mapid
);
2649 } while (result
->NextRow());
2654 PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE
,cr_id
,cr_count
);
2658 bool ChatHandler::HandleLookupItemCommand(const char* args
)
2663 std::string namepart
= args
;
2664 std::wstring wnamepart
;
2666 // converting string that we try to find to lower case
2667 if(!Utf8toWStr(namepart
,wnamepart
))
2670 wstrToLower(wnamepart
);
2674 // Search in `item_template`
2675 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
2677 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
2681 int loc_idx
= GetSessionDbLocaleIndex();
2684 ItemLocale
const *il
= sObjectMgr
.GetItemLocale(pProto
->ItemId
);
2687 if ((int32
)il
->Name
.size() > loc_idx
&& !il
->Name
[loc_idx
].empty())
2689 std::string name
= il
->Name
[loc_idx
];
2691 if (Utf8FitTo(name
, wnamepart
))
2694 PSendSysMessage(LANG_ITEM_LIST_CHAT
, id
, id
, name
.c_str());
2696 PSendSysMessage(LANG_ITEM_LIST_CONSOLE
, id
, name
.c_str());
2704 std::string name
= pProto
->Name1
;
2708 if (Utf8FitTo(name
, wnamepart
))
2711 PSendSysMessage(LANG_ITEM_LIST_CHAT
, id
, id
, name
.c_str());
2713 PSendSysMessage(LANG_ITEM_LIST_CONSOLE
, id
, name
.c_str());
2719 SendSysMessage(LANG_COMMAND_NOITEMFOUND
);
2724 bool ChatHandler::HandleLookupItemSetCommand(const char* args
)
2729 std::string namepart
= args
;
2730 std::wstring wnamepart
;
2732 if(!Utf8toWStr(namepart
,wnamepart
))
2735 // converting string that we try to find to lower case
2736 wstrToLower( wnamepart
);
2738 uint32 counter
= 0; // Counter for figure out that we found smth.
2740 // Search in ItemSet.dbc
2741 for (uint32 id
= 0; id
< sItemSetStore
.GetNumRows(); id
++)
2743 ItemSetEntry
const *set
= sItemSetStore
.LookupEntry(id
);
2746 int loc
= GetSessionDbcLocale();
2747 std::string name
= set
->name
[loc
];
2751 if (!Utf8FitTo(name
, wnamepart
))
2754 for(; loc
< MAX_LOCALE
; ++loc
)
2756 if(loc
==GetSessionDbcLocale())
2759 name
= set
->name
[loc
];
2763 if (Utf8FitTo(name
, wnamepart
))
2768 if(loc
< MAX_LOCALE
)
2770 // send item set in "id - [namedlink locale]" format
2772 PSendSysMessage(LANG_ITEMSET_LIST_CHAT
,id
,id
,name
.c_str(),localeNames
[loc
]);
2774 PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE
,id
,name
.c_str(),localeNames
[loc
]);
2779 if (counter
== 0) // if counter == 0 then we found nth
2780 SendSysMessage(LANG_COMMAND_NOITEMSETFOUND
);
2784 bool ChatHandler::HandleLookupSkillCommand(const char* args
)
2789 // can be NULL in console call
2790 Player
* target
= getSelectedPlayer();
2792 std::string namepart
= args
;
2793 std::wstring wnamepart
;
2795 if(!Utf8toWStr(namepart
,wnamepart
))
2798 // converting string that we try to find to lower case
2799 wstrToLower( wnamepart
);
2801 uint32 counter
= 0; // Counter for figure out that we found smth.
2803 // Search in SkillLine.dbc
2804 for (uint32 id
= 0; id
< sSkillLineStore
.GetNumRows(); id
++)
2806 SkillLineEntry
const *skillInfo
= sSkillLineStore
.LookupEntry(id
);
2809 int loc
= GetSessionDbcLocale();
2810 std::string name
= skillInfo
->name
[loc
];
2814 if (!Utf8FitTo(name
, wnamepart
))
2817 for(; loc
< MAX_LOCALE
; ++loc
)
2819 if(loc
==GetSessionDbcLocale())
2822 name
= skillInfo
->name
[loc
];
2826 if (Utf8FitTo(name
, wnamepart
))
2831 if(loc
< MAX_LOCALE
)
2833 char valStr
[50] = "";
2834 char const* knownStr
= "";
2835 if(target
&& target
->HasSkill(id
))
2837 knownStr
= GetMangosString(LANG_KNOWN
);
2838 uint32 curValue
= target
->GetPureSkillValue(id
);
2839 uint32 maxValue
= target
->GetPureMaxSkillValue(id
);
2840 uint32 permValue
= target
->GetSkillPermBonusValue(id
);
2841 uint32 tempValue
= target
->GetSkillTempBonusValue(id
);
2843 char const* valFormat
= GetMangosString(LANG_SKILL_VALUES
);
2844 snprintf(valStr
,50,valFormat
,curValue
,maxValue
,permValue
,tempValue
);
2847 // send skill in "id - [namedlink locale]" format
2849 PSendSysMessage(LANG_SKILL_LIST_CHAT
,id
,id
,name
.c_str(),localeNames
[loc
],knownStr
,valStr
);
2851 PSendSysMessage(LANG_SKILL_LIST_CONSOLE
,id
,name
.c_str(),localeNames
[loc
],knownStr
,valStr
);
2857 if (counter
== 0) // if counter == 0 then we found nth
2858 SendSysMessage(LANG_COMMAND_NOSKILLFOUND
);
2862 bool ChatHandler::HandleLookupSpellCommand(const char* args
)
2867 // can be NULL at console call
2868 Player
* target
= getSelectedPlayer();
2870 std::string namepart
= args
;
2871 std::wstring wnamepart
;
2873 if(!Utf8toWStr(namepart
,wnamepart
))
2876 // converting string that we try to find to lower case
2877 wstrToLower( wnamepart
);
2879 uint32 counter
= 0; // Counter for figure out that we found smth.
2881 // Search in Spell.dbc
2882 for (uint32 id
= 0; id
< sSpellStore
.GetNumRows(); id
++)
2884 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(id
);
2887 int loc
= GetSessionDbcLocale();
2888 std::string name
= spellInfo
->SpellName
[loc
];
2892 if (!Utf8FitTo(name
, wnamepart
))
2895 for(; loc
< MAX_LOCALE
; ++loc
)
2897 if(loc
==GetSessionDbcLocale())
2900 name
= spellInfo
->SpellName
[loc
];
2904 if (Utf8FitTo(name
, wnamepart
))
2909 if(loc
< MAX_LOCALE
)
2911 bool known
= target
&& target
->HasSpell(id
);
2912 bool learn
= (spellInfo
->Effect
[EFFECT_INDEX_0
] == SPELL_EFFECT_LEARN_SPELL
);
2914 uint32 talentCost
= GetTalentSpellCost(id
);
2916 bool talent
= (talentCost
> 0);
2917 bool passive
= IsPassiveSpell(id
);
2918 bool active
= target
&& target
->HasAura(id
);
2920 // unit32 used to prevent interpreting uint8 as char at output
2921 // find rank of learned spell for learning spell, or talent rank
2922 uint32 rank
= talentCost
? talentCost
: sSpellMgr
.GetSpellRank(learn
? spellInfo
->EffectTriggerSpell
[EFFECT_INDEX_0
] : id
);
2924 // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
2925 std::ostringstream ss
;
2927 ss
<< id
<< " - |cffffffff|Hspell:" << id
<< "|h[" << name
;
2929 ss
<< id
<< " - " << name
;
2931 // include rank in link name
2933 ss
<< GetMangosString(LANG_SPELL_RANK
) << rank
;
2936 ss
<< " " << localeNames
[loc
] << "]|h|r";
2938 ss
<< " " << localeNames
[loc
];
2941 ss
<< GetMangosString(LANG_TALENT
);
2943 ss
<< GetMangosString(LANG_PASSIVE
);
2945 ss
<< GetMangosString(LANG_LEARN
);
2947 ss
<< GetMangosString(LANG_KNOWN
);
2949 ss
<< GetMangosString(LANG_ACTIVE
);
2951 SendSysMessage(ss
.str().c_str());
2957 if (counter
== 0) // if counter == 0 then we found nth
2958 SendSysMessage(LANG_COMMAND_NOSPELLFOUND
);
2962 bool ChatHandler::HandleLookupQuestCommand(const char* args
)
2967 // can be NULL at console call
2968 Player
* target
= getSelectedPlayer();
2970 std::string namepart
= args
;
2971 std::wstring wnamepart
;
2973 // converting string that we try to find to lower case
2974 if(!Utf8toWStr(namepart
,wnamepart
))
2977 wstrToLower(wnamepart
);
2979 uint32 counter
= 0 ;
2981 ObjectMgr::QuestMap
const& qTemplates
= sObjectMgr
.GetQuestTemplates();
2982 for (ObjectMgr::QuestMap::const_iterator iter
= qTemplates
.begin(); iter
!= qTemplates
.end(); ++iter
)
2984 Quest
* qinfo
= iter
->second
;
2986 int loc_idx
= GetSessionDbLocaleIndex();
2989 QuestLocale
const *il
= sObjectMgr
.GetQuestLocale(qinfo
->GetQuestId());
2992 if ((int32
)il
->Title
.size() > loc_idx
&& !il
->Title
[loc_idx
].empty())
2994 std::string title
= il
->Title
[loc_idx
];
2996 if (Utf8FitTo(title
, wnamepart
))
2998 char const* statusStr
= "";
3002 QuestStatus status
= target
->GetQuestStatus(qinfo
->GetQuestId());
3004 if(status
== QUEST_STATUS_COMPLETE
)
3006 if(target
->GetQuestRewardStatus(qinfo
->GetQuestId()))
3007 statusStr
= GetMangosString(LANG_COMMAND_QUEST_REWARDED
);
3009 statusStr
= GetMangosString(LANG_COMMAND_QUEST_COMPLETE
);
3011 else if(status
== QUEST_STATUS_INCOMPLETE
)
3012 statusStr
= GetMangosString(LANG_COMMAND_QUEST_ACTIVE
);
3016 PSendSysMessage(LANG_QUEST_LIST_CHAT
,qinfo
->GetQuestId(),qinfo
->GetQuestId(),qinfo
->GetQuestLevel(),title
.c_str(),statusStr
);
3018 PSendSysMessage(LANG_QUEST_LIST_CONSOLE
,qinfo
->GetQuestId(),title
.c_str(),statusStr
);
3026 std::string title
= qinfo
->GetTitle();
3030 if (Utf8FitTo(title
, wnamepart
))
3032 char const* statusStr
= "";
3036 QuestStatus status
= target
->GetQuestStatus(qinfo
->GetQuestId());
3038 if(status
== QUEST_STATUS_COMPLETE
)
3040 if(target
->GetQuestRewardStatus(qinfo
->GetQuestId()))
3041 statusStr
= GetMangosString(LANG_COMMAND_QUEST_REWARDED
);
3043 statusStr
= GetMangosString(LANG_COMMAND_QUEST_COMPLETE
);
3045 else if(status
== QUEST_STATUS_INCOMPLETE
)
3046 statusStr
= GetMangosString(LANG_COMMAND_QUEST_ACTIVE
);
3050 PSendSysMessage(LANG_QUEST_LIST_CHAT
,qinfo
->GetQuestId(),qinfo
->GetQuestId(),qinfo
->GetQuestLevel(),title
.c_str(),statusStr
);
3052 PSendSysMessage(LANG_QUEST_LIST_CONSOLE
,qinfo
->GetQuestId(),title
.c_str(),statusStr
);
3059 SendSysMessage(LANG_COMMAND_NOQUESTFOUND
);
3064 bool ChatHandler::HandleLookupCreatureCommand(const char* args
)
3069 std::string namepart
= args
;
3070 std::wstring wnamepart
;
3072 // converting string that we try to find to lower case
3073 if (!Utf8toWStr (namepart
,wnamepart
))
3076 wstrToLower (wnamepart
);
3080 for (uint32 id
= 0; id
< sCreatureStorage
.MaxEntry
; ++id
)
3082 CreatureInfo
const* cInfo
= sCreatureStorage
.LookupEntry
<CreatureInfo
> (id
);
3086 int loc_idx
= GetSessionDbLocaleIndex();
3089 CreatureLocale
const *cl
= sObjectMgr
.GetCreatureLocale (id
);
3092 if ((int32
)cl
->Name
.size() > loc_idx
&& !cl
->Name
[loc_idx
].empty ())
3094 std::string name
= cl
->Name
[loc_idx
];
3096 if (Utf8FitTo (name
, wnamepart
))
3099 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str ());
3101 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE
, id
, name
.c_str ());
3109 std::string name
= cInfo
->Name
;
3113 if (Utf8FitTo(name
, wnamepart
))
3116 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str ());
3118 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE
, id
, name
.c_str ());
3124 SendSysMessage (LANG_COMMAND_NOCREATUREFOUND
);
3129 bool ChatHandler::HandleLookupObjectCommand(const char* args
)
3134 std::string namepart
= args
;
3135 std::wstring wnamepart
;
3137 // converting string that we try to find to lower case
3138 if(!Utf8toWStr(namepart
,wnamepart
))
3141 wstrToLower(wnamepart
);
3145 for (uint32 id
= 0; id
< sGOStorage
.MaxEntry
; id
++ )
3147 GameObjectInfo
const* gInfo
= sGOStorage
.LookupEntry
<GameObjectInfo
>(id
);
3151 int loc_idx
= GetSessionDbLocaleIndex();
3154 GameObjectLocale
const *gl
= sObjectMgr
.GetGameObjectLocale(id
);
3157 if ((int32
)gl
->Name
.size() > loc_idx
&& !gl
->Name
[loc_idx
].empty())
3159 std::string name
= gl
->Name
[loc_idx
];
3161 if (Utf8FitTo(name
, wnamepart
))
3164 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT
, id
, id
, name
.c_str());
3166 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE
, id
, name
.c_str());
3174 std::string name
= gInfo
->name
;
3178 if(Utf8FitTo(name
, wnamepart
))
3181 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT
, id
, id
, name
.c_str());
3183 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE
, id
, name
.c_str());
3189 SendSysMessage(LANG_COMMAND_NOGAMEOBJECTFOUND
);
3194 bool ChatHandler::HandleLookupTaxiNodeCommand(const char * args
)
3199 std::string namepart
= args
;
3200 std::wstring wnamepart
;
3202 if(!Utf8toWStr(namepart
,wnamepart
))
3205 // converting string that we try to find to lower case
3206 wstrToLower( wnamepart
);
3208 uint32 counter
= 0; // Counter for figure out that we found smth.
3210 // Search in TaxiNodes.dbc
3211 for (uint32 id
= 0; id
< sTaxiNodesStore
.GetNumRows(); id
++)
3213 TaxiNodesEntry
const *nodeEntry
= sTaxiNodesStore
.LookupEntry(id
);
3216 int loc
= GetSessionDbcLocale();
3217 std::string name
= nodeEntry
->name
[loc
];
3221 if (!Utf8FitTo(name
, wnamepart
))
3224 for(; loc
< MAX_LOCALE
; ++loc
)
3226 if(loc
==GetSessionDbcLocale())
3229 name
= nodeEntry
->name
[loc
];
3233 if (Utf8FitTo(name
, wnamepart
))
3238 if(loc
< MAX_LOCALE
)
3240 // send taxinode in "id - [name] (Map:m X:x Y:y Z:z)" format
3242 PSendSysMessage (LANG_TAXINODE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str(),localeNames
[loc
],
3243 nodeEntry
->map_id
,nodeEntry
->x
,nodeEntry
->y
,nodeEntry
->z
);
3245 PSendSysMessage (LANG_TAXINODE_ENTRY_LIST_CONSOLE
, id
, name
.c_str(), localeNames
[loc
],
3246 nodeEntry
->map_id
,nodeEntry
->x
,nodeEntry
->y
,nodeEntry
->z
);
3251 if (counter
== 0) // if counter == 0 then we found nth
3252 SendSysMessage(LANG_COMMAND_NOTAXINODEFOUND
);
3256 /** \brief GM command level 3 - Create a guild.
3258 * This command allows a GM (level 3) to create a guild.
3260 * The "args" parameter contains the name of the guild leader
3261 * and then the name of the guild.
3264 bool ChatHandler::HandleGuildCreateCommand(const char* args
)
3269 // if not guild name only (in "") then player name
3271 if(!extractPlayerTarget(*args
!='"' ? (char*)args
: NULL
, &target
))
3274 char* tailStr
= *args
!='"' ? strtok(NULL
, "") : (char*)args
;
3278 char* guildStr
= extractQuotedArg(tailStr
);
3282 std::string guildname
= guildStr
;
3284 if (target
->GetGuildId())
3286 SendSysMessage (LANG_PLAYER_IN_GUILD
);
3290 Guild
*guild
= new Guild
;
3291 if (!guild
->Create (target
,guildname
))
3294 SendSysMessage (LANG_GUILD_NOT_CREATED
);
3295 SetSentErrorMessage (true);
3299 sObjectMgr
.AddGuild (guild
);
3303 bool ChatHandler::HandleGuildInviteCommand(const char *args
)
3308 // if not guild name only (in "") then player name
3310 if(!extractPlayerTarget(*args
!='"' ? (char*)args
: NULL
, NULL
, &target_guid
))
3313 char* tailStr
= *args
!='"' ? strtok(NULL
, "") : (char*)args
;
3317 char* guildStr
= extractQuotedArg(tailStr
);
3321 std::string glName
= guildStr
;
3322 Guild
* targetGuild
= sObjectMgr
.GetGuildByName (glName
);
3326 // player's guild membership checked in AddMember before add
3327 if (!targetGuild
->AddMember (target_guid
,targetGuild
->GetLowestRank ()))
3333 bool ChatHandler::HandleGuildUninviteCommand(const char *args
)
3337 if(!extractPlayerTarget((char*)args
,&target
,&target_guid
))
3340 uint32 glId
= target
? target
->GetGuildId () : Player::GetGuildIdFromDB (target_guid
);
3344 Guild
* targetGuild
= sObjectMgr
.GetGuildById (glId
);
3348 targetGuild
->DelMember (target_guid
);
3352 bool ChatHandler::HandleGuildRankCommand(const char *args
)
3356 extractOptFirstArg((char*)args
,&nameStr
,&rankStr
);
3362 std::string target_name
;
3363 if(!extractPlayerTarget(nameStr
,&target
,&target_guid
,&target_name
))
3366 uint32 glId
= target
? target
->GetGuildId () : Player::GetGuildIdFromDB (target_guid
);
3370 Guild
* targetGuild
= sObjectMgr
.GetGuildById (glId
);
3374 uint32 newrank
= uint32 (atoi (rankStr
));
3375 if (newrank
> targetGuild
->GetLowestRank ())
3378 targetGuild
->ChangeRank (target_guid
,newrank
);
3382 bool ChatHandler::HandleGuildDeleteCommand(const char* args
)
3387 char* guildStr
= extractQuotedArg((char*)args
);
3391 std::string gld
= guildStr
;
3393 Guild
* targetGuild
= sObjectMgr
.GetGuildByName (gld
);
3397 targetGuild
->Disband ();
3402 bool ChatHandler::HandleGetDistanceCommand(const char* args
)
3404 WorldObject
* obj
= NULL
;
3408 uint64 guid
= extractGuidFromLink((char*)args
);
3410 obj
= (WorldObject
*)ObjectAccessor::GetObjectByTypeMask(*m_session
->GetPlayer(),guid
,TYPEMASK_UNIT
|TYPEMASK_GAMEOBJECT
);
3414 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3415 SetSentErrorMessage(true);
3421 obj
= getSelectedUnit();
3425 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3426 SetSentErrorMessage(true);
3431 PSendSysMessage(LANG_DISTANCE
, m_session
->GetPlayer()->GetDistance(obj
),m_session
->GetPlayer()->GetDistance2d(obj
));
3436 bool ChatHandler::HandleDieCommand(const char* /*args*/)
3438 Unit
* target
= getSelectedUnit();
3440 if(!target
|| !m_session
->GetPlayer()->GetSelection())
3442 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3443 SetSentErrorMessage(true);
3447 if(target
->GetTypeId()==TYPEID_PLAYER
)
3449 if(HasLowerSecurity((Player
*)target
,0,false))
3453 if( target
->isAlive() )
3455 m_session
->GetPlayer()->DealDamage(target
, target
->GetHealth(), NULL
, DIRECT_DAMAGE
, SPELL_SCHOOL_MASK_NORMAL
, NULL
, false);
3461 bool ChatHandler::HandleDamageCommand(const char * args
)
3466 Unit
* target
= getSelectedUnit();
3468 if (!target
|| !m_session
->GetPlayer()->GetSelection())
3470 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3471 SetSentErrorMessage(true);
3475 if (!target
->isAlive())
3478 char* damageStr
= strtok((char*)args
, " ");
3482 int32 damage_int
= atoi((char*)damageStr
);
3486 uint32 damage
= damage_int
;
3488 char* schoolStr
= strtok((char*)NULL
, " ");
3490 // flat melee damage without resistence/etc reduction
3493 m_session
->GetPlayer()->DealDamage(target
, damage
, NULL
, DIRECT_DAMAGE
, SPELL_SCHOOL_MASK_NORMAL
, NULL
, false);
3494 if (target
!= m_session
->GetPlayer())
3495 m_session
->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2
, target
, 1, SPELL_SCHOOL_MASK_NORMAL
, damage
, 0, 0, VICTIMSTATE_NORMAL
, 0);
3499 uint32 school
= schoolStr
? atoi((char*)schoolStr
) : SPELL_SCHOOL_NORMAL
;
3500 if(school
>= MAX_SPELL_SCHOOL
)
3503 SpellSchoolMask schoolmask
= SpellSchoolMask(1 << school
);
3505 if ( schoolmask
& SPELL_SCHOOL_MASK_NORMAL
)
3506 damage
= m_session
->GetPlayer()->CalcArmorReducedDamage(target
, damage
);
3508 char* spellStr
= strtok((char*)NULL
, " ");
3510 // melee damage by specific school
3516 m_session
->GetPlayer()->CalcAbsorbResist(target
,schoolmask
, SPELL_DIRECT_DAMAGE
, damage
, &absorb
, &resist
);
3518 if (damage
<= absorb
+ resist
)
3521 damage
-= absorb
+ resist
;
3523 m_session
->GetPlayer()->DealDamageMods(target
,damage
,&absorb
);
3524 m_session
->GetPlayer()->DealDamage(target
, damage
, NULL
, DIRECT_DAMAGE
, schoolmask
, NULL
, false);
3525 m_session
->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2
, target
, 1, schoolmask
, damage
, absorb
, resist
, VICTIMSTATE_NORMAL
, 0);
3531 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3532 uint32 spellid
= extractSpellIdFromLink((char*)args
);
3533 if (!spellid
|| !sSpellStore
.LookupEntry(spellid
))
3536 m_session
->GetPlayer()->SpellNonMeleeDamageLog(target
, spellid
, damage
);
3540 bool ChatHandler::HandleModifyArenaCommand(const char * args
)
3545 Player
*target
= getSelectedPlayer();
3548 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3549 SetSentErrorMessage(true);
3553 int32 amount
= (uint32
)atoi(args
);
3555 target
->ModifyArenaPoints(amount
);
3557 PSendSysMessage(LANG_COMMAND_MODIFY_ARENA
, GetNameLink(target
).c_str(), target
->GetArenaPoints());
3562 bool ChatHandler::HandleReviveCommand(const char* args
)
3566 if(!extractPlayerTarget((char*)args
,&target
,&target_guid
))
3571 target
->ResurrectPlayer(0.5f
);
3572 target
->SpawnCorpseBones();
3575 // will resurrected at login without corpse
3576 sObjectAccessor
.ConvertCorpseForPlayer(target_guid
);
3581 bool ChatHandler::HandleAuraCommand(const char* args
)
3583 Unit
*target
= getSelectedUnit();
3586 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3587 SetSentErrorMessage(true);
3591 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3592 uint32 spellID
= extractSpellIdFromLink((char*)args
);
3594 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry( spellID
);
3597 for(uint32 i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
3599 uint8 eff
= spellInfo
->Effect
[i
];
3600 if (eff
>=TOTAL_SPELL_EFFECTS
)
3602 if( IsAreaAuraEffect(eff
) ||
3603 eff
== SPELL_EFFECT_APPLY_AURA
||
3604 eff
== SPELL_EFFECT_PERSISTENT_AREA_AURA
)
3606 Aura
*Aur
= CreateAura(spellInfo
, SpellEffectIndex(i
), NULL
, target
);
3607 target
->AddAura(Aur
);
3615 bool ChatHandler::HandleUnAuraCommand(const char* args
)
3617 Unit
*target
= getSelectedUnit();
3620 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3621 SetSentErrorMessage(true);
3625 std::string argstr
= args
;
3626 if (argstr
== "all")
3628 target
->RemoveAllAuras();
3632 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3633 uint32 spellID
= extractSpellIdFromLink((char*)args
);
3637 target
->RemoveAurasDueToSpell(spellID
);
3642 bool ChatHandler::HandleLinkGraveCommand(const char* args
)
3647 char* px
= strtok((char*)args
, " ");
3651 uint32 g_id
= (uint32
)atoi(px
);
3655 char* px2
= strtok(NULL
, " ");
3659 else if (strncmp(px2
,"horde",6)==0)
3661 else if (strncmp(px2
,"alliance",9)==0)
3666 WorldSafeLocsEntry
const* graveyard
= sWorldSafeLocsStore
.LookupEntry(g_id
);
3670 PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST
, g_id
);
3671 SetSentErrorMessage(true);
3675 Player
* player
= m_session
->GetPlayer();
3677 uint32 zoneId
= player
->GetZoneId();
3679 AreaTableEntry
const *areaEntry
= GetAreaEntryByAreaID(zoneId
);
3680 if(!areaEntry
|| areaEntry
->zone
!=0 )
3682 PSendSysMessage(LANG_COMMAND_GRAVEYARDWRONGZONE
, g_id
,zoneId
);
3683 SetSentErrorMessage(true);
3687 if(sObjectMgr
.AddGraveYardLink(g_id
,zoneId
,g_team
))
3688 PSendSysMessage(LANG_COMMAND_GRAVEYARDLINKED
, g_id
,zoneId
);
3690 PSendSysMessage(LANG_COMMAND_GRAVEYARDALRLINKED
, g_id
,zoneId
);
3695 bool ChatHandler::HandleNearGraveCommand(const char* args
)
3699 size_t argslen
= strlen(args
);
3703 else if (strncmp((char*)args
,"horde",argslen
)==0)
3705 else if (strncmp((char*)args
,"alliance",argslen
)==0)
3710 Player
* player
= m_session
->GetPlayer();
3711 uint32 zone_id
= player
->GetZoneId();
3713 WorldSafeLocsEntry
const* graveyard
= sObjectMgr
.GetClosestGraveYard(
3714 player
->GetPositionX(), player
->GetPositionY(), player
->GetPositionZ(),player
->GetMapId(),g_team
);
3718 uint32 g_id
= graveyard
->ID
;
3720 GraveYardData
const* data
= sObjectMgr
.FindGraveYardData(g_id
,zone_id
);
3723 PSendSysMessage(LANG_COMMAND_GRAVEYARDERROR
,g_id
);
3724 SetSentErrorMessage(true);
3728 g_team
= data
->team
;
3730 std::string team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_NOTEAM
);
3733 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ANY
);
3734 else if(g_team
== HORDE
)
3735 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE
);
3736 else if(g_team
== ALLIANCE
)
3737 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE
);
3739 PSendSysMessage(LANG_COMMAND_GRAVEYARDNEAREST
, g_id
,team_name
.c_str(),zone_id
);
3743 std::string team_name
;
3746 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ANY
);
3747 else if(g_team
== HORDE
)
3748 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE
);
3749 else if(g_team
== ALLIANCE
)
3750 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE
);
3752 if(g_team
== ~uint32(0))
3753 PSendSysMessage(LANG_COMMAND_ZONENOGRAVEYARDS
, zone_id
);
3755 PSendSysMessage(LANG_COMMAND_ZONENOGRAFACTION
, zone_id
,team_name
.c_str());
3761 //-----------------------Npc Commands-----------------------
3762 bool ChatHandler::HandleNpcAllowMovementCommand(const char* /*args*/)
3764 if(sWorld
.getAllowMovement())
3766 sWorld
.SetAllowMovement(false);
3767 SendSysMessage(LANG_CREATURE_MOVE_DISABLED
);
3771 sWorld
.SetAllowMovement(true);
3772 SendSysMessage(LANG_CREATURE_MOVE_ENABLED
);
3777 bool ChatHandler::HandleNpcChangeEntryCommand(const char *args
)
3782 uint32 newEntryNum
= atoi(args
);
3786 Unit
* unit
= getSelectedUnit();
3787 if(!unit
|| unit
->GetTypeId() != TYPEID_UNIT
)
3789 SendSysMessage(LANG_SELECT_CREATURE
);
3790 SetSentErrorMessage(true);
3793 Creature
* creature
= (Creature
*)unit
;
3794 if(creature
->UpdateEntry(newEntryNum
))
3795 SendSysMessage(LANG_DONE
);
3797 SendSysMessage(LANG_ERROR
);
3801 bool ChatHandler::HandleNpcInfoCommand(const char* /*args*/)
3803 Creature
* target
= getSelectedCreature();
3807 SendSysMessage(LANG_SELECT_CREATURE
);
3808 SetSentErrorMessage(true);
3812 uint32 faction
= target
->getFaction();
3813 uint32 npcflags
= target
->GetUInt32Value(UNIT_NPC_FLAGS
);
3814 uint32 displayid
= target
->GetDisplayId();
3815 uint32 nativeid
= target
->GetNativeDisplayId();
3816 uint32 Entry
= target
->GetEntry();
3817 CreatureInfo
const* cInfo
= target
->GetCreatureInfo();
3819 time_t curRespawnDelay
= target
->GetRespawnTimeEx()-time(NULL
);
3820 if(curRespawnDelay
< 0)
3821 curRespawnDelay
= 0;
3822 std::string curRespawnDelayStr
= secsToTimeString(curRespawnDelay
,true);
3823 std::string defRespawnDelayStr
= secsToTimeString(target
->GetRespawnDelay(),true);
3825 PSendSysMessage(LANG_NPCINFO_CHAR
, target
->GetDBTableGUIDLow(), faction
, npcflags
, Entry
, displayid
, nativeid
);
3826 PSendSysMessage(LANG_NPCINFO_LEVEL
, target
->getLevel());
3827 PSendSysMessage(LANG_NPCINFO_HEALTH
,target
->GetCreateHealth(), target
->GetMaxHealth(), target
->GetHealth());
3828 PSendSysMessage(LANG_NPCINFO_FLAGS
, target
->GetUInt32Value(UNIT_FIELD_FLAGS
), target
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
), target
->getFaction());
3829 PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES
, defRespawnDelayStr
.c_str(),curRespawnDelayStr
.c_str());
3830 PSendSysMessage(LANG_NPCINFO_LOOT
, cInfo
->lootid
,cInfo
->pickpocketLootId
,cInfo
->SkinLootId
);
3831 PSendSysMessage(LANG_NPCINFO_DUNGEON_ID
, target
->GetInstanceId());
3832 PSendSysMessage(LANG_NPCINFO_POSITION
,float(target
->GetPositionX()), float(target
->GetPositionY()), float(target
->GetPositionZ()));
3834 if ((npcflags
& UNIT_NPC_FLAG_VENDOR
) )
3836 SendSysMessage(LANG_NPCINFO_VENDOR
);
3838 if ((npcflags
& UNIT_NPC_FLAG_TRAINER
) )
3840 SendSysMessage(LANG_NPCINFO_TRAINER
);
3847 bool ChatHandler::HandleNpcPlayEmoteCommand(const char* args
)
3849 uint32 emote
= atoi((char*)args
);
3851 Creature
* target
= getSelectedCreature();
3854 SendSysMessage(LANG_SELECT_CREATURE
);
3855 SetSentErrorMessage(true);
3859 target
->SetUInt32Value(UNIT_NPC_EMOTESTATE
,emote
);
3864 //TODO: NpcCommands that needs to be fixed :
3866 bool ChatHandler::HandleNpcAddWeaponCommand(const char* /*args*/)
3871 uint64 guid = m_session->GetPlayer()->GetSelection();
3874 SendSysMessage(LANG_NO_SELECTION);
3878 Creature *pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
3882 SendSysMessage(LANG_SELECT_CREATURE);
3886 char* pSlotID = strtok((char*)args, " ");
3890 char* pItemID = strtok(NULL, " ");
3894 uint32 ItemID = atoi(pItemID);
3895 uint32 SlotID = atoi(pSlotID);
3897 ItemPrototype* tmpItem = ObjectMgr::GetItemPrototype(ItemID);
3905 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID);
3909 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID);
3913 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID);
3917 PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST,SlotID);
3923 PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT,ItemID,tmpItem->Name1,SlotID);
3927 PSendSysMessage(LANG_ITEM_NOT_FOUND,ItemID);
3933 //----------------------------------------------------------
3935 bool ChatHandler::HandleExploreCheatCommand(const char* args
)
3940 int flag
= atoi((char*)args
);
3942 Player
*chr
= getSelectedPlayer();
3945 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3946 SetSentErrorMessage(true);
3952 PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL
, GetNameLink(chr
).c_str());
3953 if (needReportToTarget(chr
))
3954 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_EXPLORE_SET_ALL
,GetNameLink().c_str());
3958 PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING
, GetNameLink(chr
).c_str());
3959 if (needReportToTarget(chr
))
3960 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_EXPLORE_SET_NOTHING
,GetNameLink().c_str());
3963 for (uint8 i
=0; i
<128; ++i
)
3967 m_session
->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1
+i
,0xFFFFFFFF);
3971 m_session
->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1
+i
,0);
3978 bool ChatHandler::HandleHoverCommand(const char* args
)
3980 char* px
= strtok((char*)args
, " ");
3987 m_session
->GetPlayer()->SetHover(flag
);
3990 SendSysMessage(LANG_HOVER_ENABLED
);
3992 SendSysMessage(LANG_HOVER_DISABLED
);
3997 void ChatHandler::HandleCharacterLevel(Player
* player
, uint64 player_guid
, uint32 oldlevel
, uint32 newlevel
)
4001 player
->GiveLevel(newlevel
);
4002 player
->InitTalentForLevel();
4003 player
->SetUInt32Value(PLAYER_XP
,0);
4005 if(needReportToTarget(player
))
4007 if(oldlevel
== newlevel
)
4008 ChatHandler(player
).PSendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET
,GetNameLink().c_str());
4009 else if(oldlevel
< newlevel
)
4010 ChatHandler(player
).PSendSysMessage(LANG_YOURS_LEVEL_UP
,GetNameLink().c_str(),newlevel
);
4011 else // if(oldlevel > newlevel)
4012 ChatHandler(player
).PSendSysMessage(LANG_YOURS_LEVEL_DOWN
,GetNameLink().c_str(),newlevel
);
4017 // update level and XP at level, all other will be updated at loading
4018 CharacterDatabase
.PExecute("UPDATE characters SET level = '%u', xp = 0 WHERE guid = '%u'", newlevel
, GUID_LOPART(player_guid
));
4022 bool ChatHandler::HandleCharacterLevelCommand(const char* args
)
4026 extractOptFirstArg((char*)args
,&nameStr
,&levelStr
);
4030 // exception opt second arg: .character level $name
4031 if(isalpha(levelStr
[0]))
4034 levelStr
= NULL
; // current level will used
4039 std::string target_name
;
4040 if(!extractPlayerTarget(nameStr
,&target
,&target_guid
,&target_name
))
4043 int32 oldlevel
= target
? target
->getLevel() : Player::GetLevelFromDB(target_guid
);
4044 int32 newlevel
= levelStr
? atoi(levelStr
) : oldlevel
;
4047 return false; // invalid level
4049 if(newlevel
> STRONG_MAX_LEVEL
) // hardcoded maximum level
4050 newlevel
= STRONG_MAX_LEVEL
;
4052 HandleCharacterLevel(target
,target_guid
,oldlevel
,newlevel
);
4054 if(!m_session
|| m_session
->GetPlayer() != target
) // including player==NULL
4056 std::string nameLink
= playerLink(target_name
);
4057 PSendSysMessage(LANG_YOU_CHANGE_LVL
,nameLink
.c_str(),newlevel
);
4063 bool ChatHandler::HandleLevelUpCommand(const char* args
)
4067 extractOptFirstArg((char*)args
,&nameStr
,&levelStr
);
4069 // exception opt second arg: .character level $name
4070 if(levelStr
&& isalpha(levelStr
[0]))
4073 levelStr
= NULL
; // current level will used
4078 std::string target_name
;
4079 if(!extractPlayerTarget(nameStr
,&target
,&target_guid
,&target_name
))
4082 int32 oldlevel
= target
? target
->getLevel() : Player::GetLevelFromDB(target_guid
);
4083 int32 addlevel
= levelStr
? atoi(levelStr
) : 1;
4084 int32 newlevel
= oldlevel
+ addlevel
;
4089 if(newlevel
> STRONG_MAX_LEVEL
) // hardcoded maximum level
4090 newlevel
= STRONG_MAX_LEVEL
;
4092 HandleCharacterLevel(target
,target_guid
,oldlevel
,newlevel
);
4094 if(!m_session
|| m_session
->GetPlayer() != target
) // including chr==NULL
4096 std::string nameLink
= playerLink(target_name
);
4097 PSendSysMessage(LANG_YOU_CHANGE_LVL
,nameLink
.c_str(),newlevel
);
4103 bool ChatHandler::HandleShowAreaCommand(const char* args
)
4108 Player
*chr
= getSelectedPlayer();
4111 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4112 SetSentErrorMessage(true);
4116 int area
= GetAreaFlagByAreaID(atoi((char*)args
));
4117 int offset
= area
/ 32;
4118 uint32 val
= (uint32
)(1 << (area
% 32));
4120 if(area
<0 || offset
>= 128)
4122 SendSysMessage(LANG_BAD_VALUE
);
4123 SetSentErrorMessage(true);
4127 uint32 currFields
= chr
->GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
4128 chr
->SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
| val
));
4130 SendSysMessage(LANG_EXPLORE_AREA
);
4134 bool ChatHandler::HandleHideAreaCommand(const char* args
)
4139 Player
*chr
= getSelectedPlayer();
4142 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4143 SetSentErrorMessage(true);
4147 int area
= GetAreaFlagByAreaID(atoi((char*)args
));
4148 int offset
= area
/ 32;
4149 uint32 val
= (uint32
)(1 << (area
% 32));
4151 if(area
<0 || offset
>= 128)
4153 SendSysMessage(LANG_BAD_VALUE
);
4154 SetSentErrorMessage(true);
4158 uint32 currFields
= chr
->GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
4159 chr
->SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
^ val
));
4161 SendSysMessage(LANG_UNEXPLORE_AREA
);
4165 bool ChatHandler::HandleBankCommand(const char* /*args*/)
4167 m_session
->SendShowBank( m_session
->GetPlayer()->GetGUID() );
4172 bool ChatHandler::HandleChangeWeather(const char* args
)
4178 if (!sWorld
.getConfig(CONFIG_BOOL_WEATHER
))
4180 SendSysMessage(LANG_WEATHER_DISABLED
);
4181 SetSentErrorMessage(true);
4185 //*Change the weather of a cell
4186 char* px
= strtok((char*)args
, " ");
4187 char* py
= strtok(NULL
, " ");
4192 uint32 type
= (uint32
)atoi(px
); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
4193 float grade
= (float)atof(py
); //0 to 1, sending -1 is instand good weather
4195 Player
*player
= m_session
->GetPlayer();
4196 uint32 zoneid
= player
->GetZoneId();
4198 Weather
* wth
= sWorld
.FindWeather(zoneid
);
4201 wth
= sWorld
.AddWeather(zoneid
);
4204 SendSysMessage(LANG_NO_WEATHER
);
4205 SetSentErrorMessage(true);
4209 wth
->SetWeather(WeatherType(type
), grade
);
4214 bool ChatHandler::HandleTeleAddCommand(const char * args
)
4219 Player
*player
=m_session
->GetPlayer();
4223 std::string name
= args
;
4225 if(sObjectMgr
.GetGameTele(name
))
4227 SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST
);
4228 SetSentErrorMessage(true);
4233 tele
.position_x
= player
->GetPositionX();
4234 tele
.position_y
= player
->GetPositionY();
4235 tele
.position_z
= player
->GetPositionZ();
4236 tele
.orientation
= player
->GetOrientation();
4237 tele
.mapId
= player
->GetMapId();
4240 if(sObjectMgr
.AddGameTele(tele
))
4242 SendSysMessage(LANG_COMMAND_TP_ADDED
);
4246 SendSysMessage(LANG_COMMAND_TP_ADDEDERR
);
4247 SetSentErrorMessage(true);
4254 bool ChatHandler::HandleTeleDelCommand(const char * args
)
4259 std::string name
= args
;
4261 if(!sObjectMgr
.DeleteGameTele(name
))
4263 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
4264 SetSentErrorMessage(true);
4268 SendSysMessage(LANG_COMMAND_TP_DELETED
);
4272 bool ChatHandler::HandleListAurasCommand (const char * /*args*/)
4274 Unit
*unit
= getSelectedUnit();
4277 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4278 SetSentErrorMessage(true);
4282 char const* talentStr
= GetMangosString(LANG_TALENT
);
4283 char const* passiveStr
= GetMangosString(LANG_PASSIVE
);
4285 Unit::AuraMap
const& uAuras
= unit
->GetAuras();
4286 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS
, uAuras
.size());
4287 for (Unit::AuraMap::const_iterator itr
= uAuras
.begin(); itr
!= uAuras
.end(); ++itr
)
4289 bool talent
= GetTalentSpellCost(itr
->second
->GetId()) > 0;
4291 char const* name
= itr
->second
->GetSpellProto()->SpellName
[GetSessionDbcLocale()];
4295 std::ostringstream ss_name
;
4296 ss_name
<< "|cffffffff|Hspell:" << itr
->second
->GetId() << "|h[" << name
<< "]|h|r";
4298 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL
, itr
->second
->GetId(), itr
->second
->GetEffIndex(),
4299 itr
->second
->GetModifier()->m_auraname
, itr
->second
->GetAuraDuration(), itr
->second
->GetAuraMaxDuration(),
4300 ss_name
.str().c_str(),
4301 (itr
->second
->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4302 IS_PLAYER_GUID(itr
->second
->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr
->second
->GetCasterGUID()));
4306 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL
, itr
->second
->GetId(), itr
->second
->GetEffIndex(),
4307 itr
->second
->GetModifier()->m_auraname
, itr
->second
->GetAuraDuration(), itr
->second
->GetAuraMaxDuration(),
4309 (itr
->second
->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4310 IS_PLAYER_GUID(itr
->second
->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr
->second
->GetCasterGUID()));
4313 for (int i
= 0; i
< TOTAL_AURAS
; ++i
)
4315 Unit::AuraList
const& uAuraList
= unit
->GetAurasByType(AuraType(i
));
4316 if (uAuraList
.empty()) continue;
4317 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE
, uAuraList
.size(), i
);
4318 for (Unit::AuraList::const_iterator itr
= uAuraList
.begin(); itr
!= uAuraList
.end(); ++itr
)
4320 bool talent
= GetTalentSpellCost((*itr
)->GetId()) > 0;
4322 char const* name
= (*itr
)->GetSpellProto()->SpellName
[GetSessionDbcLocale()];
4326 std::ostringstream ss_name
;
4327 ss_name
<< "|cffffffff|Hspell:" << (*itr
)->GetId() << "|h[" << name
<< "]|h|r";
4329 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE
, (*itr
)->GetId(), (*itr
)->GetEffIndex(),
4330 ss_name
.str().c_str(),((*itr
)->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4331 IS_PLAYER_GUID((*itr
)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr
)->GetCasterGUID()));
4335 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE
, (*itr
)->GetId(), (*itr
)->GetEffIndex(),
4336 name
,((*itr
)->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4337 IS_PLAYER_GUID((*itr
)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr
)->GetCasterGUID()));
4344 bool ChatHandler::HandleResetAchievementsCommand (const char * args
)
4348 if (!extractPlayerTarget((char*)args
,&target
,&target_guid
))
4352 target
->GetAchievementMgr().Reset();
4354 AchievementMgr::DeleteFromDB(GUID_LOPART(target_guid
));
4359 bool ChatHandler::HandleResetHonorCommand (const char * args
)
4362 if (!extractPlayerTarget((char*)args
,&target
))
4365 target
->SetUInt32Value(PLAYER_FIELD_KILLS
, 0);
4366 target
->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS
, 0);
4367 target
->SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY
, 0);
4368 target
->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION
, 0);
4369 target
->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION
, 0);
4370 target
->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_EARN_HONORABLE_KILL
);
4375 static bool HandleResetStatsOrLevelHelper(Player
* player
)
4377 ChrClassesEntry
const* cEntry
= sChrClassesStore
.LookupEntry(player
->getClass());
4380 sLog
.outError("Class %u not found in DBC (Wrong DBC files?)",player
->getClass());
4384 uint8 powertype
= cEntry
->powerType
;
4386 // reset m_form if no aura
4387 if(!player
->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT
))
4388 player
->m_form
= FORM_NONE
;
4390 player
->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS
, DEFAULT_WORLD_OBJECT_SIZE
);
4391 player
->SetFloatValue(UNIT_FIELD_COMBATREACH
, 1.5f
);
4393 player
->setFactionForRace(player
->getRace());
4395 player
->SetUInt32Value(UNIT_FIELD_BYTES_0
, ( ( player
->getRace() ) | ( player
->getClass() << 8 ) | ( player
->getGender() << 16 ) | ( powertype
<< 24 ) ) );
4397 // reset only if player not in some form;
4398 if(player
->m_form
==FORM_NONE
)
4399 player
->InitDisplayIds();
4401 player
->SetByteValue(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_PVP
);
4402 player
->SetByteValue(UNIT_FIELD_BYTES_2
, 3, player
->m_form
);
4404 player
->SetUInt32Value(UNIT_FIELD_FLAGS
, UNIT_FLAG_PVP_ATTACKABLE
);
4406 //-1 is default value
4407 player
->SetInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX
, -1);
4409 //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000 );
4413 bool ChatHandler::HandleResetLevelCommand(const char * args
)
4416 if(!extractPlayerTarget((char*)args
,&target
))
4419 if(!HandleResetStatsOrLevelHelper(target
))
4422 // set starting level
4423 uint32 start_level
= target
->getClass() != CLASS_DEATH_KNIGHT
4424 ? sWorld
.getConfig(CONFIG_UINT32_START_PLAYER_LEVEL
)
4425 : sWorld
.getConfig(CONFIG_UINT32_START_HEROIC_PLAYER_LEVEL
);
4427 target
->_ApplyAllLevelScaleItemMods(false);
4429 target
->SetLevel(start_level
);
4430 target
->InitRunes();
4431 target
->InitStatsForLevel(true);
4432 target
->InitTaxiNodesForLevel();
4433 target
->InitGlyphsForLevel();
4434 target
->InitTalentForLevel();
4435 target
->SetUInt32Value(PLAYER_XP
,0);
4437 target
->_ApplyAllLevelScaleItemMods(true);
4439 // reset level for pet
4440 if(Pet
* pet
= target
->GetPet())
4441 pet
->SynchronizeLevelWithOwner();
4446 bool ChatHandler::HandleResetStatsCommand(const char * args
)
4449 if (!extractPlayerTarget((char*)args
,&target
))
4452 if (!HandleResetStatsOrLevelHelper(target
))
4455 target
->InitRunes();
4456 target
->InitStatsForLevel(true);
4457 target
->InitTaxiNodesForLevel();
4458 target
->InitGlyphsForLevel();
4459 target
->InitTalentForLevel();
4464 bool ChatHandler::HandleResetSpellsCommand(const char * args
)
4468 std::string target_name
;
4469 if(!extractPlayerTarget((char*)args
, &target
, &target_guid
, &target_name
))
4474 target
->resetSpells();
4476 ChatHandler(target
).SendSysMessage(LANG_RESET_SPELLS
);
4477 if(!m_session
|| m_session
->GetPlayer()!=target
)
4478 PSendSysMessage(LANG_RESET_SPELLS_ONLINE
,GetNameLink(target
).c_str());
4482 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS
), GUID_LOPART(target_guid
));
4483 PSendSysMessage(LANG_RESET_SPELLS_OFFLINE
,target_name
.c_str());
4489 bool ChatHandler::HandleResetTalentsCommand(const char * args
)
4493 std::string target_name
;
4494 if (!extractPlayerTarget((char*)args
, &target
, &target_guid
, &target_name
))
4496 // Try reset talents as Hunter Pet
4497 Creature
* creature
= getSelectedCreature();
4498 if (!*args
&& creature
&& creature
->isPet())
4500 Unit
*owner
= creature
->GetOwner();
4501 if(owner
&& owner
->GetTypeId() == TYPEID_PLAYER
&& ((Pet
*)creature
)->IsPermanentPetFor((Player
*)owner
))
4503 ((Pet
*)creature
)->resetTalents(true);
4504 ((Player
*)owner
)->SendTalentsInfoData(true);
4506 ChatHandler((Player
*)owner
).SendSysMessage(LANG_RESET_PET_TALENTS
);
4507 if(!m_session
|| m_session
->GetPlayer() != ((Player
*)owner
))
4508 PSendSysMessage(LANG_RESET_PET_TALENTS_ONLINE
,GetNameLink((Player
*)owner
).c_str());
4513 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4514 SetSentErrorMessage(true);
4520 target
->resetTalents(true);
4521 target
->SendTalentsInfoData(false);
4522 ChatHandler(target
).SendSysMessage(LANG_RESET_TALENTS
);
4523 if (!m_session
|| m_session
->GetPlayer() != target
)
4524 PSendSysMessage(LANG_RESET_TALENTS_ONLINE
,GetNameLink(target
).c_str());
4526 Pet
* pet
= target
->GetPet();
4527 Pet::resetTalentsForAllPetsOf(target
, pet
);
4529 target
->SendTalentsInfoData(true);
4532 else if (target_guid
)
4534 uint32 at_flags
= AT_LOGIN_RESET_PET_TALENTS
;
4535 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'", at_flags
, GUID_LOPART(target_guid
) );
4536 std::string nameLink
= playerLink(target_name
);
4537 PSendSysMessage(LANG_RESET_TALENTS_OFFLINE
, nameLink
.c_str());
4541 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4542 SetSentErrorMessage(true);
4546 bool ChatHandler::HandleResetAllCommand(const char * args
)
4551 std::string casename
= args
;
4553 AtLoginFlags atLogin
;
4555 // Command specially created as single command to prevent using short case names
4556 if(casename
=="spells")
4558 atLogin
= AT_LOGIN_RESET_SPELLS
;
4559 sWorld
.SendWorldText(LANG_RESETALL_SPELLS
);
4561 SendSysMessage(LANG_RESETALL_SPELLS
);
4563 else if(casename
=="talents")
4565 atLogin
= AtLoginFlags(AT_LOGIN_RESET_TALENTS
| AT_LOGIN_RESET_PET_TALENTS
);
4566 sWorld
.SendWorldText(LANG_RESETALL_TALENTS
);
4568 SendSysMessage(LANG_RESETALL_TALENTS
);
4572 PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE
,args
);
4573 SetSentErrorMessage(true);
4577 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE (at_login & '%u') = '0'",atLogin
,atLogin
);
4578 HashMapHolder
<Player
>::MapType
const& plist
= sObjectAccessor
.GetPlayers();
4579 for(HashMapHolder
<Player
>::MapType::const_iterator itr
= plist
.begin(); itr
!= plist
.end(); ++itr
)
4580 itr
->second
->SetAtLoginFlag(atLogin
);
4585 bool ChatHandler::HandleServerShutDownCancelCommand(const char* /*args*/)
4587 sWorld
.ShutdownCancel();
4591 bool ChatHandler::HandleServerShutDownCommand(const char* args
)
4596 char* time_str
= strtok ((char*) args
, " ");
4597 char* exitcode_str
= strtok (NULL
, "");
4599 int32 time
= atoi (time_str
);
4601 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4602 if ((time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0')) || time
< 0)
4607 int32 exitcode
= atoi (exitcode_str
);
4609 // Handle atoi() errors
4610 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4613 // Exit code should be in range of 0-125, 126-255 is used
4614 // in many shells for their own return codes and code > 255
4615 // is not supported in many others
4616 if (exitcode
< 0 || exitcode
> 125)
4619 sWorld
.ShutdownServ (time
, 0, exitcode
);
4622 sWorld
.ShutdownServ(time
,0,SHUTDOWN_EXIT_CODE
);
4626 bool ChatHandler::HandleServerRestartCommand(const char* args
)
4631 char* time_str
= strtok ((char*) args
, " ");
4632 char* exitcode_str
= strtok (NULL
, "");
4634 int32 time
= atoi (time_str
);
4636 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4637 if ((time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0')) || time
< 0)
4642 int32 exitcode
= atoi (exitcode_str
);
4644 // Handle atoi() errors
4645 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4648 // Exit code should be in range of 0-125, 126-255 is used
4649 // in many shells for their own return codes and code > 255
4650 // is not supported in many others
4651 if (exitcode
< 0 || exitcode
> 125)
4654 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_RESTART
, exitcode
);
4657 sWorld
.ShutdownServ(time
, SHUTDOWN_MASK_RESTART
, RESTART_EXIT_CODE
);
4661 bool ChatHandler::HandleServerIdleRestartCommand(const char* args
)
4666 char* time_str
= strtok ((char*) args
, " ");
4667 char* exitcode_str
= strtok (NULL
, "");
4669 int32 time
= atoi (time_str
);
4671 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4672 if ((time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0')) || time
< 0)
4677 int32 exitcode
= atoi (exitcode_str
);
4679 // Handle atoi() errors
4680 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4683 // Exit code should be in range of 0-125, 126-255 is used
4684 // in many shells for their own return codes and code > 255
4685 // is not supported in many others
4686 if (exitcode
< 0 || exitcode
> 125)
4689 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_RESTART
|SHUTDOWN_MASK_IDLE
, exitcode
);
4692 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_RESTART
|SHUTDOWN_MASK_IDLE
,RESTART_EXIT_CODE
);
4696 bool ChatHandler::HandleServerIdleShutDownCommand(const char* args
)
4701 char* time_str
= strtok ((char*) args
, " ");
4702 char* exitcode_str
= strtok (NULL
, "");
4704 int32 time
= atoi (time_str
);
4706 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4707 if ((time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0')) || time
< 0)
4712 int32 exitcode
= atoi (exitcode_str
);
4714 // Handle atoi() errors
4715 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4718 // Exit code should be in range of 0-125, 126-255 is used
4719 // in many shells for their own return codes and code > 255
4720 // is not supported in many others
4721 if (exitcode
< 0 || exitcode
> 125)
4724 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_IDLE
, exitcode
);
4727 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_IDLE
,SHUTDOWN_EXIT_CODE
);
4731 bool ChatHandler::HandleQuestAdd(const char* args
)
4733 Player
* player
= getSelectedPlayer();
4736 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4737 SetSentErrorMessage(true);
4741 // .addquest #entry'
4742 // number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
4743 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4747 uint32 entry
= atol(cId
);
4749 Quest
const* pQuest
= sObjectMgr
.GetQuestTemplate(entry
);
4753 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
,entry
);
4754 SetSentErrorMessage(true);
4758 // check item starting quest (it can work incorrectly if added without item in inventory)
4759 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
4761 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
4765 if (pProto
->StartQuest
== entry
)
4767 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM
, entry
, pProto
->ItemId
);
4768 SetSentErrorMessage(true);
4773 // ok, normal (creature/GO starting) quest
4774 if( player
->CanAddQuest( pQuest
, true ) )
4776 player
->AddQuest( pQuest
, NULL
);
4778 if ( player
->CanCompleteQuest( entry
) )
4779 player
->CompleteQuest( entry
);
4785 bool ChatHandler::HandleQuestRemove(const char* args
)
4787 Player
* player
= getSelectedPlayer();
4790 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4791 SetSentErrorMessage(true);
4795 // .removequest #entry'
4796 // number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
4797 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4801 uint32 entry
= atol(cId
);
4803 Quest
const* pQuest
= sObjectMgr
.GetQuestTemplate(entry
);
4807 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
4808 SetSentErrorMessage(true);
4812 // remove all quest entries for 'entry' from quest log
4813 for(uint8 slot
= 0; slot
< MAX_QUEST_LOG_SIZE
; ++slot
)
4815 uint32 quest
= player
->GetQuestSlotQuestId(slot
);
4818 player
->SetQuestSlot(slot
,0);
4820 // we ignore unequippable quest items in this case, its' still be equipped
4821 player
->TakeQuestSourceItem( quest
, false );
4825 // set quest status to not started (will updated in DB at next save)
4826 player
->SetQuestStatus( entry
, QUEST_STATUS_NONE
);
4828 // reset rewarded for restart repeatable quest
4829 player
->getQuestStatusMap()[entry
].m_rewarded
= false;
4831 SendSysMessage(LANG_COMMAND_QUEST_REMOVED
);
4835 bool ChatHandler::HandleQuestComplete(const char* args
)
4837 Player
* player
= getSelectedPlayer();
4840 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4841 SetSentErrorMessage(true);
4845 // .quest complete #entry
4846 // number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
4847 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4851 uint32 entry
= atol(cId
);
4853 Quest
const* pQuest
= sObjectMgr
.GetQuestTemplate(entry
);
4855 // If player doesn't have the quest
4856 if(!pQuest
|| player
->GetQuestStatus(entry
) == QUEST_STATUS_NONE
)
4858 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
4859 SetSentErrorMessage(true);
4863 // Add quest items for quests that require items
4864 for(uint8 x
= 0; x
< QUEST_ITEM_OBJECTIVES_COUNT
; ++x
)
4866 uint32 id
= pQuest
->ReqItemId
[x
];
4867 uint32 count
= pQuest
->ReqItemCount
[x
];
4871 uint32 curItemCount
= player
->GetItemCount(id
,true);
4873 ItemPosCountVec dest
;
4874 uint8 msg
= player
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, id
, count
- curItemCount
);
4875 if( msg
== EQUIP_ERR_OK
)
4877 Item
* item
= player
->StoreNewItem( dest
, id
, true);
4878 player
->SendNewItem(item
,count
-curItemCount
, true, false);
4882 // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
4883 for(uint8 i
= 0; i
< QUEST_OBJECTIVES_COUNT
; ++i
)
4885 int32 creature
= pQuest
->ReqCreatureOrGOId
[i
];
4886 uint32 creaturecount
= pQuest
->ReqCreatureOrGOCount
[i
];
4888 if(uint32 spell_id
= pQuest
->ReqSpell
[i
])
4890 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4891 player
->CastedCreatureOrGO(creature
,0,spell_id
);
4893 else if(creature
> 0)
4895 if(CreatureInfo
const* cInfo
= ObjectMgr::GetCreatureTemplate(creature
))
4896 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4897 player
->KilledMonster(cInfo
,0);
4899 else if(creature
< 0)
4901 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4902 player
->CastedCreatureOrGO(-(creature
),0,0);
4906 // If the quest requires reputation to complete
4907 if(uint32 repFaction
= pQuest
->GetRepObjectiveFaction())
4909 uint32 repValue
= pQuest
->GetRepObjectiveValue();
4910 uint32 curRep
= player
->GetReputationMgr().GetReputation(repFaction
);
4911 if(curRep
< repValue
)
4912 if(FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry(repFaction
))
4913 player
->GetReputationMgr().SetReputation(factionEntry
,repValue
);
4916 // If the quest requires money
4917 int32 ReqOrRewMoney
= pQuest
->GetRewOrReqMoney();
4918 if(ReqOrRewMoney
< 0)
4919 player
->ModifyMoney(-ReqOrRewMoney
);
4921 player
->CompleteQuest(entry
);
4925 bool ChatHandler::HandleBanAccountCommand(const char* args
)
4927 return HandleBanHelper(BAN_ACCOUNT
,args
);
4930 bool ChatHandler::HandleBanCharacterCommand(const char* args
)
4932 return HandleBanHelper(BAN_CHARACTER
,args
);
4935 bool ChatHandler::HandleBanIPCommand(const char* args
)
4937 return HandleBanHelper(BAN_IP
,args
);
4940 bool ChatHandler::HandleBanHelper(BanMode mode
, const char* args
)
4945 char* cnameOrIP
= strtok ((char*)args
, " ");
4949 std::string nameOrIP
= cnameOrIP
;
4951 char* duration
= strtok (NULL
," ");
4952 if(!duration
|| !atoi(duration
))
4955 char* reason
= strtok (NULL
,"");
4962 if (!AccountMgr::normalizeString(nameOrIP
))
4964 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
4965 SetSentErrorMessage(true);
4970 if(!normalizePlayerName(nameOrIP
))
4972 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4973 SetSentErrorMessage(true);
4978 if(!IsIPAddress(nameOrIP
.c_str()))
4983 switch(sWorld
.BanAccount(mode
, nameOrIP
, duration
, reason
,m_session
? m_session
->GetPlayerName() : ""))
4986 if(atoi(duration
)>0)
4987 PSendSysMessage(LANG_BAN_YOUBANNED
,nameOrIP
.c_str(),secsToTimeString(TimeStringToSecs(duration
),true).c_str(),reason
);
4989 PSendSysMessage(LANG_BAN_YOUPERMBANNED
,nameOrIP
.c_str(),reason
);
4991 case BAN_SYNTAX_ERROR
:
4997 PSendSysMessage(LANG_BAN_NOTFOUND
,"account",nameOrIP
.c_str());
5000 PSendSysMessage(LANG_BAN_NOTFOUND
,"character",nameOrIP
.c_str());
5003 PSendSysMessage(LANG_BAN_NOTFOUND
,"ip",nameOrIP
.c_str());
5006 SetSentErrorMessage(true);
5013 bool ChatHandler::HandleUnBanAccountCommand(const char* args
)
5015 return HandleUnBanHelper(BAN_ACCOUNT
,args
);
5018 bool ChatHandler::HandleUnBanCharacterCommand(const char* args
)
5020 return HandleUnBanHelper(BAN_CHARACTER
,args
);
5023 bool ChatHandler::HandleUnBanIPCommand(const char* args
)
5025 return HandleUnBanHelper(BAN_IP
,args
);
5028 bool ChatHandler::HandleUnBanHelper(BanMode mode
, const char* args
)
5033 char* cnameOrIP
= strtok ((char*)args
, " ");
5037 std::string nameOrIP
= cnameOrIP
;
5042 if (!AccountMgr::normalizeString(nameOrIP
))
5044 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
5045 SetSentErrorMessage(true);
5050 if(!normalizePlayerName(nameOrIP
))
5052 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5053 SetSentErrorMessage(true);
5058 if(!IsIPAddress(nameOrIP
.c_str()))
5063 if(sWorld
.RemoveBanAccount(mode
,nameOrIP
))
5064 PSendSysMessage(LANG_UNBAN_UNBANNED
,nameOrIP
.c_str());
5066 PSendSysMessage(LANG_UNBAN_ERROR
,nameOrIP
.c_str());
5071 bool ChatHandler::HandleBanInfoAccountCommand(const char* args
)
5076 char* cname
= strtok((char*)args
, "");
5080 std::string account_name
= cname
;
5081 if (!AccountMgr::normalizeString(account_name
))
5083 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5084 SetSentErrorMessage(true);
5088 uint32 accountid
= sAccountMgr
.GetId(account_name
);
5091 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5095 return HandleBanInfoHelper(accountid
,account_name
.c_str());
5098 bool ChatHandler::HandleBanInfoCharacterCommand(const char* args
)
5102 if (!extractPlayerTarget((char*)args
,&target
,&target_guid
))
5105 uint32 accountid
= target
? target
->GetSession()->GetAccountId() : sObjectMgr
.GetPlayerAccountIdByGUID(target_guid
);
5107 std::string accountname
;
5108 if (!sAccountMgr
.GetName(accountid
,accountname
))
5110 PSendSysMessage(LANG_BANINFO_NOCHARACTER
);
5114 return HandleBanInfoHelper(accountid
,accountname
.c_str());
5117 bool ChatHandler::HandleBanInfoHelper(uint32 accountid
, char const* accountname
)
5119 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
);
5122 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN
, accountname
);
5126 PSendSysMessage(LANG_BANINFO_BANHISTORY
,accountname
);
5129 Field
* fields
= result
->Fetch();
5131 time_t unbandate
= time_t(fields
[3].GetUInt64());
5132 bool active
= false;
5133 if(fields
[2].GetBool() && (fields
[1].GetUInt64() == (uint64
)0 ||unbandate
>= time(NULL
)) )
5135 bool permanent
= (fields
[1].GetUInt64() == (uint64
)0);
5136 std::string bantime
= permanent
?GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[1].GetUInt64(), true);
5137 PSendSysMessage(LANG_BANINFO_HISTORYENTRY
,
5138 fields
[0].GetString(), bantime
.c_str(), active
? GetMangosString(LANG_BANINFO_YES
):GetMangosString(LANG_BANINFO_NO
), fields
[4].GetString(), fields
[5].GetString());
5139 }while (result
->NextRow());
5145 bool ChatHandler::HandleBanInfoIPCommand(const char* args
)
5150 char* cIP
= strtok ((char*)args
, "");
5154 if (!IsIPAddress(cIP
))
5157 std::string IP
= cIP
;
5159 loginDatabase
.escape_string(IP
);
5160 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());
5163 PSendSysMessage(LANG_BANINFO_NOIP
);
5167 Field
*fields
= result
->Fetch();
5168 bool permanent
= !fields
[6].GetUInt64();
5169 PSendSysMessage(LANG_BANINFO_IPENTRY
,
5170 fields
[0].GetString(), fields
[1].GetString(), permanent
? GetMangosString(LANG_BANINFO_NEVER
):fields
[2].GetString(),
5171 permanent
? GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[3].GetUInt64(), true).c_str(), fields
[4].GetString(), fields
[5].GetString());
5176 bool ChatHandler::HandleBanListCharacterCommand(const char* args
)
5178 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5180 char* cFilter
= strtok ((char*)args
, " ");
5184 std::string filter
= cFilter
;
5185 loginDatabase
.escape_string(filter
);
5186 QueryResult
* result
= CharacterDatabase
.PQuery("SELECT account FROM characters WHERE name "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'"),filter
.c_str());
5189 PSendSysMessage(LANG_BANLIST_NOCHARACTER
);
5193 return HandleBanListHelper(result
);
5196 bool ChatHandler::HandleBanListAccountCommand(const char* args
)
5198 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5200 char* cFilter
= strtok((char*)args
, " ");
5201 std::string filter
= cFilter
? cFilter
: "";
5202 loginDatabase
.escape_string(filter
);
5204 QueryResult
* result
;
5208 result
= loginDatabase
.Query("SELECT account.id, username FROM account, account_banned"
5209 " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
5213 result
= loginDatabase
.PQuery("SELECT account.id, username FROM account, account_banned"
5214 " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
5220 PSendSysMessage(LANG_BANLIST_NOACCOUNT
);
5224 return HandleBanListHelper(result
);
5227 bool ChatHandler::HandleBanListHelper(QueryResult
* result
)
5229 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT
);
5231 // Chat short output
5236 Field
* fields
= result
->Fetch();
5237 uint32 accountid
= fields
[0].GetUInt32();
5239 QueryResult
* banresult
= loginDatabase
.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid
);
5242 Field
* fields2
= banresult
->Fetch();
5243 PSendSysMessage("%s",fields2
[0].GetString());
5246 } while (result
->NextRow());
5248 // Console wide output
5251 SendSysMessage(LANG_BANLIST_ACCOUNTS
);
5252 SendSysMessage("===============================================================================");
5253 SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER
);
5256 SendSysMessage("-------------------------------------------------------------------------------");
5257 Field
*fields
= result
->Fetch();
5258 uint32 account_id
= fields
[0].GetUInt32 ();
5260 std::string account_name
;
5262 // "account" case, name can be get in same query
5263 if(result
->GetFieldCount() > 1)
5264 account_name
= fields
[1].GetCppString();
5265 // "character" case, name need extract from another DB
5267 sAccountMgr
.GetName (account_id
,account_name
);
5269 // No SQL injection. id is uint32.
5270 QueryResult
*banInfo
= loginDatabase
.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id
);
5273 Field
*fields2
= banInfo
->Fetch();
5276 time_t t_ban
= fields2
[0].GetUInt64();
5277 tm
* aTm_ban
= localtime(&t_ban
);
5279 if (fields2
[0].GetUInt64() == fields2
[1].GetUInt64())
5281 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5282 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
,
5283 fields2
[2].GetString(),fields2
[3].GetString());
5287 time_t t_unban
= fields2
[1].GetUInt64();
5288 tm
* aTm_unban
= localtime(&t_unban
);
5289 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5290 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
,
5291 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5292 fields2
[2].GetString(),fields2
[3].GetString());
5294 }while ( banInfo
->NextRow() );
5297 }while( result
->NextRow() );
5298 SendSysMessage("===============================================================================");
5305 bool ChatHandler::HandleBanListIPCommand(const char* args
)
5307 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5309 char* cFilter
= strtok((char*)args
, " ");
5310 std::string filter
= cFilter
? cFilter
: "";
5311 loginDatabase
.escape_string(filter
);
5313 QueryResult
* result
;
5317 result
= loginDatabase
.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5318 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
5319 " ORDER BY unbandate" );
5323 result
= loginDatabase
.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5324 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")
5325 " ORDER BY unbandate",filter
.c_str() );
5330 PSendSysMessage(LANG_BANLIST_NOIP
);
5334 PSendSysMessage(LANG_BANLIST_MATCHINGIP
);
5335 // Chat short output
5340 Field
* fields
= result
->Fetch();
5341 PSendSysMessage("%s",fields
[0].GetString());
5342 } while (result
->NextRow());
5344 // Console wide output
5347 SendSysMessage(LANG_BANLIST_IPS
);
5348 SendSysMessage("===============================================================================");
5349 SendSysMessage(LANG_BANLIST_IPS_HEADER
);
5352 SendSysMessage("-------------------------------------------------------------------------------");
5353 Field
*fields
= result
->Fetch();
5354 time_t t_ban
= fields
[1].GetUInt64();
5355 tm
* aTm_ban
= localtime(&t_ban
);
5356 if ( fields
[1].GetUInt64() == fields
[2].GetUInt64() )
5358 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5359 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
,
5360 fields
[3].GetString(), fields
[4].GetString());
5364 time_t t_unban
= fields
[2].GetUInt64();
5365 tm
* aTm_unban
= localtime(&t_unban
);
5366 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5367 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
,
5368 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5369 fields
[3].GetString(), fields
[4].GetString());
5371 }while( result
->NextRow() );
5372 SendSysMessage("===============================================================================");
5379 bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
5381 Player
* pl
= m_session
->GetPlayer();
5383 // accept only explicitly selected target (not implicitly self targeting case)
5384 Unit
* target
= getSelectedUnit();
5385 if(pl
->GetSelection() && target
)
5387 if(target
->GetTypeId()!=TYPEID_UNIT
)
5389 SendSysMessage(LANG_SELECT_CREATURE
);
5390 SetSentErrorMessage(true);
5394 if(target
->isDead())
5395 ((Creature
*)target
)->Respawn();
5399 CellPair
p(MaNGOS::ComputeCellPair(pl
->GetPositionX(), pl
->GetPositionY()));
5401 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
5404 MaNGOS::RespawnDo u_do
;
5405 MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
> worker(pl
,u_do
);
5407 TypeContainerVisitor
<MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
>, GridTypeMapContainer
> obj_worker(worker
);
5408 cell
.Visit(p
, obj_worker
, *pl
->GetMap());
5413 bool ChatHandler::HandleGMFlyCommand(const char* args
)
5418 Player
*target
= getSelectedPlayer();
5420 target
= m_session
->GetPlayer();
5422 WorldPacket
data(12);
5423 if (strncmp(args
, "on", 3) == 0)
5424 data
.SetOpcode(SMSG_MOVE_SET_CAN_FLY
);
5425 else if (strncmp(args
, "off", 4) == 0)
5426 data
.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY
);
5429 SendSysMessage(LANG_USE_BOL
);
5432 data
.append(target
->GetPackGUID());
5433 data
<< uint32(0); // unknown
5434 target
->SendMessageToSet(&data
, true);
5435 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS
, GetNameLink(target
).c_str(), args
);
5439 bool ChatHandler::HandlePDumpLoadCommand(const char *args
)
5444 char * file
= strtok((char*)args
, " ");
5448 char * account
= strtok(NULL
, " ");
5452 std::string account_name
= account
;
5453 if (!AccountMgr::normalizeString(account_name
))
5455 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5456 SetSentErrorMessage(true);
5460 uint32 account_id
= sAccountMgr
.GetId(account_name
);
5463 account_id
= atoi(account
); // use original string
5466 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5467 SetSentErrorMessage(true);
5472 if (!sAccountMgr
.GetName(account_id
,account_name
))
5474 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5475 SetSentErrorMessage(true);
5479 char* guid_str
= NULL
;
5480 char* name_str
= strtok(NULL
, " ");
5486 // normalize the name if specified and check if it exists
5487 if (!normalizePlayerName(name
))
5489 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5490 SetSentErrorMessage(true);
5494 if (ObjectMgr::CheckPlayerName(name
,true) != CHAR_NAME_SUCCESS
)
5496 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5497 SetSentErrorMessage(true);
5501 guid_str
= strtok(NULL
, " ");
5508 guid
= atoi(guid_str
);
5511 PSendSysMessage(LANG_INVALID_CHARACTER_GUID
);
5512 SetSentErrorMessage(true);
5516 if (sObjectMgr
.GetPlayerAccountIdByGUID(guid
))
5518 PSendSysMessage(LANG_CHARACTER_GUID_IN_USE
,guid
);
5519 SetSentErrorMessage(true);
5524 switch(PlayerDumpReader().LoadDump(file
, account_id
, name
, guid
))
5527 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS
);
5529 case DUMP_FILE_OPEN_ERROR
:
5530 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
5531 SetSentErrorMessage(true);
5533 case DUMP_FILE_BROKEN
:
5534 PSendSysMessage(LANG_DUMP_BROKEN
,file
);
5535 SetSentErrorMessage(true);
5537 case DUMP_TOO_MANY_CHARS
:
5538 PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL
,account_name
.c_str(),account_id
);
5539 SetSentErrorMessage(true);
5542 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED
);
5543 SetSentErrorMessage(true);
5550 bool ChatHandler::HandlePDumpWriteCommand(const char *args
)
5555 char* file
= strtok((char*)args
, " ");
5556 char* p2
= strtok(NULL
, " ");
5562 // character name can't start from number
5563 if (isNumeric(p2
[0]))
5567 std::string name
= extractPlayerNameFromLink(p2
);
5570 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5571 SetSentErrorMessage(true);
5575 guid
= GUID_LOPART(sObjectMgr
.GetPlayerGUIDByName(name
));
5578 if(!sObjectMgr
.GetPlayerAccountIdByGUID(guid
))
5580 PSendSysMessage(LANG_PLAYER_NOT_FOUND
);
5581 SetSentErrorMessage(true);
5585 switch(PlayerDumpWriter().WriteDump(file
, guid
))
5588 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS
);
5590 case DUMP_FILE_OPEN_ERROR
:
5591 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
5592 SetSentErrorMessage(true);
5595 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED
);
5596 SetSentErrorMessage(true);
5603 bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
5605 Unit
* unit
= getSelectedUnit();
5608 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5609 SetSentErrorMessage(true);
5613 PSendSysMessage(LANG_MOVEGENS_LIST
,(unit
->GetTypeId()==TYPEID_PLAYER
? "Player" : "Creature" ),unit
->GetGUIDLow());
5615 MotionMaster
* mm
= unit
->GetMotionMaster();
5616 for(MotionMaster::const_iterator itr
= mm
->begin(); itr
!= mm
->end(); ++itr
)
5618 switch((*itr
)->GetMovementGeneratorType())
5620 case IDLE_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_IDLE
); break;
5621 case RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_RANDOM
); break;
5622 case WAYPOINT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_WAYPOINT
); break;
5623 case ANIMAL_RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_ANIMAL_RANDOM
); break;
5624 case CONFUSED_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_CONFUSED
); break;
5625 case CHASE_MOTION_TYPE
:
5627 Unit
* target
= NULL
;
5628 if(unit
->GetTypeId()==TYPEID_PLAYER
)
5629 target
= static_cast<ChaseMovementGenerator
<Player
> const*>(*itr
)->GetTarget();
5631 target
= static_cast<ChaseMovementGenerator
<Creature
> const*>(*itr
)->GetTarget();
5634 SendSysMessage(LANG_MOVEGENS_CHASE_NULL
);
5635 else if (target
->GetTypeId()==TYPEID_PLAYER
)
5636 PSendSysMessage(LANG_MOVEGENS_CHASE_PLAYER
,target
->GetName(),target
->GetGUIDLow());
5638 PSendSysMessage(LANG_MOVEGENS_CHASE_CREATURE
,target
->GetName(),target
->GetGUIDLow());
5641 case FOLLOW_MOTION_TYPE
:
5643 Unit
* target
= NULL
;
5644 if(unit
->GetTypeId()==TYPEID_PLAYER
)
5645 target
= static_cast<FollowMovementGenerator
<Player
> const*>(*itr
)->GetTarget();
5647 target
= static_cast<FollowMovementGenerator
<Creature
> const*>(*itr
)->GetTarget();
5650 SendSysMessage(LANG_MOVEGENS_FOLLOW_NULL
);
5651 else if (target
->GetTypeId()==TYPEID_PLAYER
)
5652 PSendSysMessage(LANG_MOVEGENS_FOLLOW_PLAYER
,target
->GetName(),target
->GetGUIDLow());
5654 PSendSysMessage(LANG_MOVEGENS_FOLLOW_CREATURE
,target
->GetName(),target
->GetGUIDLow());
5657 case HOME_MOTION_TYPE
:
5658 if(unit
->GetTypeId()==TYPEID_UNIT
)
5661 (*itr
)->GetDestination(x
,y
,z
);
5662 PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE
,x
,y
,z
);
5665 SendSysMessage(LANG_MOVEGENS_HOME_PLAYER
);
5667 case FLIGHT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FLIGHT
); break;
5668 case POINT_MOTION_TYPE
:
5671 (*itr
)->GetDestination(x
,y
,z
);
5672 PSendSysMessage(LANG_MOVEGENS_POINT
,x
,y
,z
);
5675 case FLEEING_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FEAR
); break;
5676 case DISTRACT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_DISTRACT
); break;
5678 PSendSysMessage(LANG_MOVEGENS_UNKNOWN
,(*itr
)->GetMovementGeneratorType());
5685 bool ChatHandler::HandleServerPLimitCommand(const char *args
)
5689 char* param
= strtok((char*)args
, " ");
5693 int l
= strlen(param
);
5695 if( strncmp(param
,"player",l
) == 0 )
5696 sWorld
.SetPlayerLimit(-SEC_PLAYER
);
5697 else if(strncmp(param
,"moderator",l
) == 0 )
5698 sWorld
.SetPlayerLimit(-SEC_MODERATOR
);
5699 else if(strncmp(param
,"gamemaster",l
) == 0 )
5700 sWorld
.SetPlayerLimit(-SEC_GAMEMASTER
);
5701 else if(strncmp(param
,"administrator",l
) == 0 )
5702 sWorld
.SetPlayerLimit(-SEC_ADMINISTRATOR
);
5703 else if(strncmp(param
,"reset",l
) == 0 )
5704 sWorld
.SetPlayerLimit( sConfig
.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT
) );
5707 int val
= atoi(param
);
5708 if(val
< -SEC_ADMINISTRATOR
) val
= -SEC_ADMINISTRATOR
;
5710 sWorld
.SetPlayerLimit(val
);
5713 // kick all low security level players
5714 if(sWorld
.GetPlayerAmountLimit() > SEC_PLAYER
)
5715 sWorld
.KickAllLess(sWorld
.GetPlayerSecurityLimit());
5718 uint32 pLimit
= sWorld
.GetPlayerAmountLimit();
5719 AccountTypes allowedAccountType
= sWorld
.GetPlayerSecurityLimit();
5720 char const* secName
= "";
5721 switch(allowedAccountType
)
5723 case SEC_PLAYER
: secName
= "Player"; break;
5724 case SEC_MODERATOR
: secName
= "Moderator"; break;
5725 case SEC_GAMEMASTER
: secName
= "Gamemaster"; break;
5726 case SEC_ADMINISTRATOR
: secName
= "Administrator"; break;
5727 default: secName
= "<unknown>"; break;
5730 PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit
,secName
);
5735 bool ChatHandler::HandleCastCommand(const char* args
)
5740 Unit
* target
= getSelectedUnit();
5744 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5745 SetSentErrorMessage(true);
5749 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5750 uint32 spell
= extractSpellIdFromLink((char*)args
);
5754 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5758 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5760 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5761 SetSentErrorMessage(true);
5765 char* trig_str
= strtok(NULL
, " ");
5768 int l
= strlen(trig_str
);
5769 if(strncmp(trig_str
,"triggered",l
) != 0 )
5773 bool triggered
= (trig_str
!= NULL
);
5775 m_session
->GetPlayer()->CastSpell(target
,spell
,triggered
);
5780 bool ChatHandler::HandleCastBackCommand(const char* args
)
5782 Creature
* caster
= getSelectedCreature();
5786 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5787 SetSentErrorMessage(true);
5791 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
5792 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5793 uint32 spell
= extractSpellIdFromLink((char*)args
);
5794 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
5797 char* trig_str
= strtok(NULL
, " ");
5800 int l
= strlen(trig_str
);
5801 if(strncmp(trig_str
,"triggered",l
) != 0 )
5805 bool triggered
= (trig_str
!= NULL
);
5807 caster
->SetFacingToObject(m_session
->GetPlayer());
5809 caster
->CastSpell(m_session
->GetPlayer(),spell
,triggered
);
5814 bool ChatHandler::HandleCastDistCommand(const char* args
)
5819 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5820 uint32 spell
= extractSpellIdFromLink((char*)args
);
5824 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5828 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5830 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5831 SetSentErrorMessage(true);
5835 char *distStr
= strtok(NULL
, " ");
5840 sscanf(distStr
, "%f", &dist
);
5842 char* trig_str
= strtok(NULL
, " ");
5845 int l
= strlen(trig_str
);
5846 if(strncmp(trig_str
,"triggered",l
) != 0 )
5850 bool triggered
= (trig_str
!= NULL
);
5853 m_session
->GetPlayer()->GetClosePoint(x
,y
,z
,dist
);
5855 m_session
->GetPlayer()->CastSpell(x
,y
,z
,spell
,triggered
);
5859 bool ChatHandler::HandleCastTargetCommand(const char* args
)
5861 Creature
* caster
= getSelectedCreature();
5865 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5866 SetSentErrorMessage(true);
5870 if(!caster
->getVictim())
5872 SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM
);
5873 SetSentErrorMessage(true);
5877 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5878 uint32 spell
= extractSpellIdFromLink((char*)args
);
5879 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
5882 char* trig_str
= strtok(NULL
, " ");
5885 int l
= strlen(trig_str
);
5886 if(strncmp(trig_str
,"triggered",l
) != 0 )
5890 bool triggered
= (trig_str
!= NULL
);
5892 caster
->SetFacingToObject(m_session
->GetPlayer());
5894 caster
->CastSpell(caster
->getVictim(),spell
,triggered
);
5900 ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
5901 Without this function 3rd party scripting library will get linking errors (unresolved external)
5902 when attempting to use the PointMovementGenerator
5904 bool ChatHandler::HandleComeToMeCommand(const char *args
)
5906 Creature
* caster
= getSelectedCreature();
5910 SendSysMessage(LANG_SELECT_CREATURE
);
5911 SetSentErrorMessage(true);
5915 char* newFlagStr
= strtok((char*)args
, " ");
5920 uint32 newFlags
= atoi(newFlagStr
);
5922 caster
->SetSplineFlags(SplineFlags(newFlags
));
5924 Player
* pl
= m_session
->GetPlayer();
5926 caster
->GetMotionMaster()->MovePoint(0, pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ());
5930 bool ChatHandler::HandleCastSelfCommand(const char* args
)
5935 Unit
* target
= getSelectedUnit();
5939 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5940 SetSentErrorMessage(true);
5944 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5945 uint32 spell
= extractSpellIdFromLink((char*)args
);
5949 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5953 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5955 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5956 SetSentErrorMessage(true);
5960 target
->CastSpell(target
,spell
,false);
5965 std::string
GetTimeString(time_t time
)
5967 time_t days
= time
/ DAY
;
5968 time_t hours
= (time
% DAY
) / HOUR
;
5969 time_t minute
= (time
% HOUR
) / MINUTE
;
5970 std::ostringstream ss
;
5974 ss
<< hours
<< "h ";
5975 ss
<< minute
<< "m";
5979 bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
5981 Player
* player
= getSelectedPlayer();
5982 if (!player
) player
= m_session
->GetPlayer();
5984 for(uint8 i
= 0; i
< MAX_DIFFICULTY
; ++i
)
5986 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(Difficulty(i
));
5987 for(Player::BoundInstancesMap::const_iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
5989 InstanceSave
*save
= itr
->second
.save
;
5990 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
5991 if (const MapEntry
* entry
= sMapStore
.LookupEntry(itr
->first
))
5993 PSendSysMessage("map: %d (%s) inst: %d perm: %s diff: %d canReset: %s TTR: %s",
5994 itr
->first
, entry
->name
[m_session
->GetSessionDbcLocale()], save
->GetInstanceId(), itr
->second
.perm
? "yes" : "no",
5995 save
->GetDifficulty(), save
->CanReset() ? "yes" : "no", timeleft
.c_str());
5998 PSendSysMessage("bound for a nonexistant map %u", itr
->first
);
6002 PSendSysMessage("player binds: %d", counter
);
6004 Group
*group
= player
->GetGroup();
6007 for(uint8 i
= 0; i
< MAX_DIFFICULTY
; ++i
)
6009 Group::BoundInstancesMap
&binds
= group
->GetBoundInstances(Difficulty(i
));
6010 for(Group::BoundInstancesMap::const_iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
6012 InstanceSave
*save
= itr
->second
.save
;
6013 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
6014 if (const MapEntry
* entry
= sMapStore
.LookupEntry(itr
->first
))
6016 PSendSysMessage("map: %d (%s) inst: %d perm: %s diff: %d canReset: %s TTR: %s",
6017 itr
->first
, entry
->name
[m_session
->GetSessionDbcLocale()], save
->GetInstanceId(), itr
->second
.perm
? "yes" : "no",
6018 save
->GetDifficulty(), save
->CanReset() ? "yes" : "no", timeleft
.c_str());
6021 PSendSysMessage("bound for a nonexistant map %u", itr
->first
);
6026 PSendSysMessage("group binds: %d", counter
);
6031 bool ChatHandler::HandleInstanceUnbindCommand(const char* args
)
6036 Player
* player
= getSelectedPlayer();
6038 player
= m_session
->GetPlayer();
6041 bool got_map
= false;
6043 if (strncmp(args
,"all",strlen(args
)) != 0)
6045 if(!isNumeric(args
[0]))
6052 for(uint8 i
= 0; i
< MAX_DIFFICULTY
; ++i
)
6054 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(Difficulty(i
));
6055 for(Player::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end();)
6057 if (got_map
&& mapid
!= itr
->first
)
6062 if(itr
->first
!= player
->GetMapId())
6064 InstanceSave
*save
= itr
->second
.save
;
6065 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
6067 if (const MapEntry
* entry
= sMapStore
.LookupEntry(itr
->first
))
6069 PSendSysMessage("unbinding map: %d (%s) inst: %d perm: %s diff: %d canReset: %s TTR: %s",
6070 itr
->first
, entry
->name
[m_session
->GetSessionDbcLocale()], save
->GetInstanceId(), itr
->second
.perm
? "yes" : "no",
6071 save
->GetDifficulty(), save
->CanReset() ? "yes" : "no", timeleft
.c_str());
6074 PSendSysMessage("bound for a nonexistant map %u", itr
->first
);
6075 player
->UnbindInstance(itr
, Difficulty(i
));
6082 PSendSysMessage("instances unbound: %d", counter
);
6086 bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
6088 PSendSysMessage("instances loaded: %d", sMapMgr
.GetNumInstances());
6089 PSendSysMessage("players in instances: %d", sMapMgr
.GetNumPlayersInInstances());
6090 PSendSysMessage("instance saves: %d", sInstanceSaveMgr
.GetNumInstanceSaves());
6091 PSendSysMessage("players bound: %d", sInstanceSaveMgr
.GetNumBoundPlayersTotal());
6092 PSendSysMessage("groups bound: %d", sInstanceSaveMgr
.GetNumBoundGroupsTotal());
6096 bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
6098 Player
* pl
= m_session
->GetPlayer();
6100 Map
* map
= pl
->GetMap();
6101 if (!map
->IsDungeon())
6103 PSendSysMessage("Map is not a dungeon.");
6104 SetSentErrorMessage(true);
6108 if (!((InstanceMap
*)map
)->GetInstanceData())
6110 PSendSysMessage("Map has no instance data.");
6111 SetSentErrorMessage(true);
6115 ((InstanceMap
*)map
)->GetInstanceData()->SaveToDB();
6119 /// Display the list of GMs
6120 bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
6122 ///- Get the accounts with GM Level >0
6123 QueryResult
*result
= loginDatabase
.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
6126 SendSysMessage(LANG_GMLIST
);
6127 SendSysMessage("========================");
6128 SendSysMessage(LANG_GMLIST_HEADER
);
6129 SendSysMessage("========================");
6131 ///- Circle through them. Display username and GM level
6134 Field
*fields
= result
->Fetch();
6135 PSendSysMessage("|%15s|%6s|", fields
[0].GetString(),fields
[1].GetString());
6136 }while( result
->NextRow() );
6138 PSendSysMessage("========================");
6142 PSendSysMessage(LANG_GMLIST_EMPTY
);
6146 /// Define the 'Message of the day' for the realm
6147 bool ChatHandler::HandleServerSetMotdCommand(const char* args
)
6149 sWorld
.SetMotd(args
);
6150 PSendSysMessage(LANG_MOTD_NEW
, args
);
6154 /// Set/Unset the expansion level for an account
6155 bool ChatHandler::HandleAccountSetAddonCommand(const char* args
)
6157 ///- Get the command line arguments
6158 char *szAcc
= strtok((char*)args
," ");
6159 char *szExp
= strtok(NULL
," ");
6164 std::string account_name
;
6169 Player
* player
= getSelectedPlayer();
6173 account_id
= player
->GetSession()->GetAccountId();
6174 sAccountMgr
.GetName(account_id
,account_name
);
6179 ///- Convert Account name to Upper Format
6180 account_name
= szAcc
;
6181 if (!AccountMgr::normalizeString(account_name
))
6183 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
6184 SetSentErrorMessage(true);
6188 account_id
= sAccountMgr
.GetId(account_name
);
6191 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
6192 SetSentErrorMessage(true);
6198 // Let set addon state only for lesser (strong) security level
6199 // or to self account
6200 if (m_session
&& m_session
->GetAccountId () != account_id
&&
6201 HasLowerSecurityAccount (NULL
,account_id
,true))
6204 int lev
=atoi(szExp
); //get int anyway (0 if error)
6209 loginDatabase
.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev
,account_id
);
6210 PSendSysMessage(LANG_ACCOUNT_SETADDON
,account_name
.c_str(),account_id
,lev
);
6214 //Send items by mail
6215 bool ChatHandler::HandleSendItemsCommand(const char* args
)
6217 // format: name "subject text" "mail text" item1[:count1] item2[:count2] ... item12[:count12]
6219 uint64 receiver_guid
;
6220 std::string receiver_name
;
6221 if(!extractPlayerTarget((char*)args
,&receiver
,&receiver_guid
,&receiver_name
))
6224 char* tail1
= strtok(NULL
, "");
6228 char* msgSubject
= extractQuotedArg(tail1
);
6232 char* tail2
= strtok(NULL
, "");
6236 char* msgText
= extractQuotedArg(tail2
);
6240 // msgSubject, msgText isn't NUL after prev. check
6241 std::string subject
= msgSubject
;
6242 std::string text
= msgText
;
6245 typedef std::pair
<uint32
,uint32
> ItemPair
;
6246 typedef std::list
< ItemPair
> ItemPairs
;
6249 // get all tail string
6250 char* tail
= strtok(NULL
, "");
6252 // get from tail next item str
6253 while(char* itemStr
= strtok(tail
, " "))
6256 tail
= strtok(NULL
, "");
6259 char* itemIdStr
= strtok(itemStr
, ":");
6260 char* itemCountStr
= strtok(NULL
, " ");
6262 uint32 item_id
= atoi(itemIdStr
);
6266 ItemPrototype
const* item_proto
= ObjectMgr::GetItemPrototype(item_id
);
6269 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
6270 SetSentErrorMessage(true);
6274 uint32 item_count
= itemCountStr
? atoi(itemCountStr
) : 1;
6275 if (item_count
< 1 || (item_proto
->MaxCount
> 0 && item_count
> uint32(item_proto
->MaxCount
)))
6277 PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT
, item_count
,item_id
);
6278 SetSentErrorMessage(true);
6282 while(item_count
> item_proto
->GetMaxStackSize())
6284 items
.push_back(ItemPair(item_id
,item_proto
->GetMaxStackSize()));
6285 item_count
-= item_proto
->GetMaxStackSize();
6288 items
.push_back(ItemPair(item_id
,item_count
));
6290 if(items
.size() > MAX_MAIL_ITEMS
)
6292 PSendSysMessage(LANG_COMMAND_MAIL_ITEMS_LIMIT
, MAX_MAIL_ITEMS
);
6293 SetSentErrorMessage(true);
6298 // from console show not existed sender
6299 MailSender
sender(MAIL_NORMAL
,m_session
? m_session
->GetPlayer()->GetGUIDLow() : 0, MAIL_STATIONERY_GM
);
6301 uint32 itemTextId
= !text
.empty() ? sObjectMgr
.CreateItemText( text
) : 0;
6304 MailDraft
draft(subject
, itemTextId
);
6306 for(ItemPairs::const_iterator itr
= items
.begin(); itr
!= items
.end(); ++itr
)
6308 if(Item
* item
= Item::CreateItem(itr
->first
,itr
->second
,m_session
? m_session
->GetPlayer() : 0))
6310 item
->SaveToDB(); // save for prevent lost at next mail load, if send fail then item will deleted
6311 draft
.AddItem(item
);
6315 draft
.SendMailTo(MailReceiver(receiver
,GUID_LOPART(receiver_guid
)), sender
);
6317 std::string nameLink
= playerLink(receiver_name
);
6318 PSendSysMessage(LANG_MAIL_SENT
, nameLink
.c_str());
6322 ///Send money by mail
6323 bool ChatHandler::HandleSendMoneyCommand(const char* args
)
6325 /// format: name "subject text" "mail text" money
6328 uint64 receiver_guid
;
6329 std::string receiver_name
;
6330 if(!extractPlayerTarget((char*)args
,&receiver
,&receiver_guid
,&receiver_name
))
6333 char* tail1
= strtok(NULL
, "");
6337 char* msgSubject
= extractQuotedArg(tail1
);
6341 char* tail2
= strtok(NULL
, "");
6345 char* msgText
= extractQuotedArg(tail2
);
6349 char* money_str
= strtok(NULL
, "");
6350 int32 money
= money_str
? atoi(money_str
) : 0;
6354 // msgSubject, msgText isn't NUL after prev. check
6355 std::string subject
= msgSubject
;
6356 std::string text
= msgText
;
6358 // from console show not existed sender
6359 MailSender
sender(MAIL_NORMAL
,m_session
? m_session
->GetPlayer()->GetGUIDLow() : 0, MAIL_STATIONERY_GM
);
6361 uint32 itemTextId
= !text
.empty() ? sObjectMgr
.CreateItemText( text
) : 0;
6363 MailDraft(subject
, itemTextId
)
6365 .SendMailTo(MailReceiver(receiver
,GUID_LOPART(receiver_guid
)),sender
);
6367 std::string nameLink
= playerLink(receiver_name
);
6368 PSendSysMessage(LANG_MAIL_SENT
, nameLink
.c_str());
6372 /// Send a message to a player in game
6373 bool ChatHandler::HandleSendMessageCommand(const char* args
)
6375 ///- Find the player
6377 if(!extractPlayerTarget((char*)args
,&rPlayer
))
6380 char* msg_str
= strtok(NULL
, "");
6384 ///- Check that he is not logging out.
6385 if(rPlayer
->GetSession()->isLogingOut())
6387 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6388 SetSentErrorMessage(true);
6392 ///- Send the message
6393 //Use SendAreaTriggerMessage for fastest delivery.
6394 rPlayer
->GetSession()->SendAreaTriggerMessage("%s", msg_str
);
6395 rPlayer
->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
6397 //Confirmation message
6398 std::string nameLink
= GetNameLink(rPlayer
);
6399 PSendSysMessage(LANG_SENDMESSAGE
,nameLink
.c_str(),msg_str
);
6403 bool ChatHandler::HandleFlushArenaPointsCommand(const char * /*args*/)
6405 sBattleGroundMgr
.DistributeArenaPoints();
6409 bool ChatHandler::HandleModifyGenderCommand(const char *args
)
6414 Player
*player
= getSelectedPlayer();
6418 PSendSysMessage(LANG_PLAYER_NOT_FOUND
);
6419 SetSentErrorMessage(true);
6423 PlayerInfo
const* info
= sObjectMgr
.GetPlayerInfo(player
->getRace(), player
->getClass());
6427 char const* gender_str
= (char*)args
;
6428 int gender_len
= strlen(gender_str
);
6432 if(!strncmp(gender_str
, "male", gender_len
)) // MALE
6434 if(player
->getGender() == GENDER_MALE
)
6437 gender
= GENDER_MALE
;
6439 else if (!strncmp(gender_str
, "female", gender_len
)) // FEMALE
6441 if(player
->getGender() == GENDER_FEMALE
)
6444 gender
= GENDER_FEMALE
;
6448 SendSysMessage(LANG_MUST_MALE_OR_FEMALE
);
6449 SetSentErrorMessage(true);
6454 player
->SetByteValue(UNIT_FIELD_BYTES_0
, 2, gender
);
6455 player
->SetByteValue(PLAYER_BYTES_3
, 0, gender
);
6457 // Change display ID
6458 player
->InitDisplayIds();
6460 char const* gender_full
= gender
? "female" : "male";
6462 PSendSysMessage(LANG_YOU_CHANGE_GENDER
, GetNameLink(player
).c_str(), gender_full
);
6464 if (needReportToTarget(player
))
6465 ChatHandler(player
).PSendSysMessage(LANG_YOUR_GENDER_CHANGED
, gender_full
, GetNameLink().c_str());