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 HandleReloadAllLocalesCommand("");
70 HandleReloadMailLevelRewardCommand("");
71 HandleReloadCommandCommand("");
72 HandleReloadReservedNameCommand("");
73 HandleReloadMangosStringCommand("");
74 HandleReloadGameTeleCommand("");
78 bool ChatHandler::HandleReloadAllAchievementCommand(const char*)
80 HandleReloadAchievementCriteriaRequirementCommand("");
81 HandleReloadAchievementRewardCommand("");
85 bool ChatHandler::HandleReloadAllAreaCommand(const char*)
87 //HandleReloadQuestAreaTriggersCommand(""); -- reloaded in HandleReloadAllQuestCommand
88 HandleReloadAreaTriggerTeleportCommand("");
89 HandleReloadAreaTriggerTavernCommand("");
90 HandleReloadGameGraveyardZoneCommand("");
94 bool ChatHandler::HandleReloadAllLootCommand(const char*)
96 sLog
.outString( "Re-Loading Loot Tables..." );
98 SendGlobalSysMessage("DB tables `*_loot_template` reloaded.");
102 bool ChatHandler::HandleReloadAllNpcCommand(const char* /*args*/)
104 HandleReloadNpcGossipCommand("a");
105 HandleReloadNpcTrainerCommand("a");
106 HandleReloadNpcVendorCommand("a");
107 HandleReloadPointsOfInterestCommand("a");
108 HandleReloadSpellClickSpellsCommand("a");
112 bool ChatHandler::HandleReloadAllQuestCommand(const char* /*args*/)
114 HandleReloadQuestAreaTriggersCommand("a");
115 HandleReloadQuestTemplateCommand("a");
117 sLog
.outString( "Re-Loading Quests Relations..." );
118 sObjectMgr
.LoadQuestRelations();
119 SendGlobalSysMessage("DB tables `*_questrelation` and `*_involvedrelation` reloaded.");
123 bool ChatHandler::HandleReloadAllScriptsCommand(const char*)
125 if(sWorld
.IsScriptScheduled())
127 PSendSysMessage("DB scripts used currently, please attempt reload later.");
128 SetSentErrorMessage(true);
132 sLog
.outString( "Re-Loading Scripts..." );
133 HandleReloadGameObjectScriptsCommand("a");
134 HandleReloadGossipScriptsCommand("a");
135 HandleReloadEventScriptsCommand("a");
136 HandleReloadQuestEndScriptsCommand("a");
137 HandleReloadQuestStartScriptsCommand("a");
138 HandleReloadSpellScriptsCommand("a");
139 SendGlobalSysMessage("DB tables `*_scripts` reloaded.");
140 HandleReloadDbScriptStringCommand("a");
144 bool ChatHandler::HandleReloadAllEventAICommand(const char*)
146 HandleReloadEventAITextsCommand("a");
147 HandleReloadEventAISummonsCommand("a");
148 HandleReloadEventAIScriptsCommand("a");
152 bool ChatHandler::HandleReloadAllSpellCommand(const char*)
154 HandleReloadSkillDiscoveryTemplateCommand("a");
155 HandleReloadSkillExtraItemTemplateCommand("a");
156 HandleReloadSpellAreaCommand("a");
157 HandleReloadSpellChainCommand("a");
158 HandleReloadSpellElixirCommand("a");
159 HandleReloadSpellLearnSpellCommand("a");
160 HandleReloadSpellProcEventCommand("a");
161 HandleReloadSpellBonusesCommand("a");
162 HandleReloadSpellProcItemEnchantCommand("a");
163 HandleReloadSpellScriptTargetCommand("a");
164 HandleReloadSpellTargetPositionCommand("a");
165 HandleReloadSpellThreatsCommand("a");
166 HandleReloadSpellPetAurasCommand("a");
170 bool ChatHandler::HandleReloadAllItemCommand(const char*)
172 HandleReloadPageTextsCommand("a");
173 HandleReloadItemEnchantementsCommand("a");
174 HandleReloadItemRequiredTragetCommand("a");
178 bool ChatHandler::HandleReloadAllLocalesCommand(const char* /*args*/)
180 HandleReloadLocalesAchievementRewardCommand("a");
181 HandleReloadLocalesCreatureCommand("a");
182 HandleReloadLocalesGameobjectCommand("a");
183 HandleReloadLocalesGossipMenuOptionCommand("a");
184 HandleReloadLocalesItemCommand("a");
185 HandleReloadLocalesNpcTextCommand("a");
186 HandleReloadLocalesPageTextCommand("a");
187 HandleReloadLocalesPointsOfInterestCommand("a");
188 HandleReloadLocalesQuestCommand("a");
192 bool ChatHandler::HandleReloadConfigCommand(const char* /*args*/)
194 sLog
.outString( "Re-Loading config settings..." );
195 sWorld
.LoadConfigSettings(true);
196 sMapMgr
.InitializeVisibilityDistanceInfo();
197 SendGlobalSysMessage("World config settings reloaded.");
201 bool ChatHandler::HandleReloadAchievementCriteriaRequirementCommand(const char*)
203 sLog
.outString( "Re-Loading Additional Achievement Criteria Requirements Data..." );
204 sAchievementMgr
.LoadAchievementCriteriaRequirements();
205 SendGlobalSysMessage("DB table `achievement_criteria_requirement` reloaded.");
209 bool ChatHandler::HandleReloadAchievementRewardCommand(const char*)
211 sLog
.outString( "Re-Loading Achievement Reward Data..." );
212 sAchievementMgr
.LoadRewards();
213 SendGlobalSysMessage("DB table `achievement_reward` reloaded.");
217 bool ChatHandler::HandleReloadAreaTriggerTavernCommand(const char*)
219 sLog
.outString( "Re-Loading Tavern Area Triggers..." );
220 sObjectMgr
.LoadTavernAreaTriggers();
221 SendGlobalSysMessage("DB table `areatrigger_tavern` reloaded.");
225 bool ChatHandler::HandleReloadAreaTriggerTeleportCommand(const char*)
227 sLog
.outString( "Re-Loading AreaTrigger teleport definitions..." );
228 sObjectMgr
.LoadAreaTriggerTeleports();
229 SendGlobalSysMessage("DB table `areatrigger_teleport` reloaded.");
233 bool ChatHandler::HandleReloadCommandCommand(const char*)
235 load_command_table
= true;
236 SendGlobalSysMessage("DB table `command` will be reloaded at next chat command use.");
240 bool ChatHandler::HandleReloadCreatureQuestRelationsCommand(const char*)
242 sLog
.outString( "Loading Quests Relations... (`creature_questrelation`)" );
243 sObjectMgr
.LoadCreatureQuestRelations();
244 SendGlobalSysMessage("DB table `creature_questrelation` (creature quest givers) reloaded.");
248 bool ChatHandler::HandleReloadCreatureQuestInvRelationsCommand(const char*)
250 sLog
.outString( "Loading Quests Relations... (`creature_involvedrelation`)" );
251 sObjectMgr
.LoadCreatureInvolvedRelations();
252 SendGlobalSysMessage("DB table `creature_involvedrelation` (creature quest takers) reloaded.");
256 bool ChatHandler::HandleReloadGossipMenuCommand(const char*)
258 sLog
.outString( "Re-Loading `gossip_menu` Table!" );
259 sObjectMgr
.LoadGossipMenu();
260 SendGlobalSysMessage("DB table `gossip_menu` reloaded.");
264 bool ChatHandler::HandleReloadGossipMenuOptionCommand(const char*)
266 sLog
.outString( "Re-Loading `gossip_menu_option` Table!" );
267 sObjectMgr
.LoadGossipMenuItems();
268 SendGlobalSysMessage("DB table `gossip_menu_option` reloaded.");
272 bool ChatHandler::HandleReloadGossipScriptsCommand(const char* arg
)
274 if(sWorld
.IsScriptScheduled())
276 SendSysMessage("DB scripts used currently, please attempt reload later.");
277 SetSentErrorMessage(true);
282 sLog
.outString( "Re-Loading Scripts from `gossip_scripts`...");
284 sObjectMgr
.LoadGossipScripts();
287 SendGlobalSysMessage("DB table `gossip_scripts` reloaded.");
292 bool ChatHandler::HandleReloadGOQuestRelationsCommand(const char*)
294 sLog
.outString( "Loading Quests Relations... (`gameobject_questrelation`)" );
295 sObjectMgr
.LoadGameobjectQuestRelations();
296 SendGlobalSysMessage("DB table `gameobject_questrelation` (gameobject quest givers) reloaded.");
300 bool ChatHandler::HandleReloadGOQuestInvRelationsCommand(const char*)
302 sLog
.outString( "Loading Quests Relations... (`gameobject_involvedrelation`)" );
303 sObjectMgr
.LoadGameobjectInvolvedRelations();
304 SendGlobalSysMessage("DB table `gameobject_involvedrelation` (gameobject quest takers) reloaded.");
308 bool ChatHandler::HandleReloadQuestAreaTriggersCommand(const char*)
310 sLog
.outString( "Re-Loading Quest Area Triggers..." );
311 sObjectMgr
.LoadQuestAreaTriggers();
312 SendGlobalSysMessage("DB table `areatrigger_involvedrelation` (quest area triggers) reloaded.");
316 bool ChatHandler::HandleReloadQuestTemplateCommand(const char*)
318 sLog
.outString( "Re-Loading Quest Templates..." );
319 sObjectMgr
.LoadQuests();
320 SendGlobalSysMessage("DB table `quest_template` (quest definitions) reloaded.");
322 /// dependent also from `gameobject` but this table not reloaded anyway
323 sLog
.outString( "Re-Loading GameObjects for quests..." );
324 sObjectMgr
.LoadGameObjectForQuests();
325 SendGlobalSysMessage("Data GameObjects for quests reloaded.");
329 bool ChatHandler::HandleReloadLootTemplatesCreatureCommand(const char*)
331 sLog
.outString( "Re-Loading Loot Tables... (`creature_loot_template`)" );
332 LoadLootTemplates_Creature();
333 LootTemplates_Creature
.CheckLootRefs();
334 SendGlobalSysMessage("DB table `creature_loot_template` reloaded.");
338 bool ChatHandler::HandleReloadLootTemplatesDisenchantCommand(const char*)
340 sLog
.outString( "Re-Loading Loot Tables... (`disenchant_loot_template`)" );
341 LoadLootTemplates_Disenchant();
342 LootTemplates_Disenchant
.CheckLootRefs();
343 SendGlobalSysMessage("DB table `disenchant_loot_template` reloaded.");
347 bool ChatHandler::HandleReloadLootTemplatesFishingCommand(const char*)
349 sLog
.outString( "Re-Loading Loot Tables... (`fishing_loot_template`)" );
350 LoadLootTemplates_Fishing();
351 LootTemplates_Fishing
.CheckLootRefs();
352 SendGlobalSysMessage("DB table `fishing_loot_template` reloaded.");
356 bool ChatHandler::HandleReloadLootTemplatesGameobjectCommand(const char*)
358 sLog
.outString( "Re-Loading Loot Tables... (`gameobject_loot_template`)" );
359 LoadLootTemplates_Gameobject();
360 LootTemplates_Gameobject
.CheckLootRefs();
361 SendGlobalSysMessage("DB table `gameobject_loot_template` reloaded.");
365 bool ChatHandler::HandleReloadLootTemplatesItemCommand(const char*)
367 sLog
.outString( "Re-Loading Loot Tables... (`item_loot_template`)" );
368 LoadLootTemplates_Item();
369 LootTemplates_Item
.CheckLootRefs();
370 SendGlobalSysMessage("DB table `item_loot_template` reloaded.");
374 bool ChatHandler::HandleReloadLootTemplatesMillingCommand(const char*)
376 sLog
.outString( "Re-Loading Loot Tables... (`milling_loot_template`)" );
377 LoadLootTemplates_Milling();
378 LootTemplates_Milling
.CheckLootRefs();
379 SendGlobalSysMessage("DB table `milling_loot_template` reloaded.");
383 bool ChatHandler::HandleReloadLootTemplatesPickpocketingCommand(const char*)
385 sLog
.outString( "Re-Loading Loot Tables... (`pickpocketing_loot_template`)" );
386 LoadLootTemplates_Pickpocketing();
387 LootTemplates_Pickpocketing
.CheckLootRefs();
388 SendGlobalSysMessage("DB table `pickpocketing_loot_template` reloaded.");
392 bool ChatHandler::HandleReloadLootTemplatesProspectingCommand(const char*)
394 sLog
.outString( "Re-Loading Loot Tables... (`prospecting_loot_template`)" );
395 LoadLootTemplates_Prospecting();
396 LootTemplates_Prospecting
.CheckLootRefs();
397 SendGlobalSysMessage("DB table `prospecting_loot_template` reloaded.");
401 bool ChatHandler::HandleReloadLootTemplatesMailCommand(const char*)
403 sLog
.outString( "Re-Loading Loot Tables... (`mail_loot_template`)" );
404 LoadLootTemplates_Mail();
405 LootTemplates_Mail
.CheckLootRefs();
406 SendGlobalSysMessage("DB table `mail_loot_template` reloaded.");
410 bool ChatHandler::HandleReloadLootTemplatesReferenceCommand(const char*)
412 sLog
.outString( "Re-Loading Loot Tables... (`reference_loot_template`)" );
413 LoadLootTemplates_Reference();
414 SendGlobalSysMessage("DB table `reference_loot_template` reloaded.");
418 bool ChatHandler::HandleReloadLootTemplatesSkinningCommand(const char*)
420 sLog
.outString( "Re-Loading Loot Tables... (`skinning_loot_template`)" );
421 LoadLootTemplates_Skinning();
422 LootTemplates_Skinning
.CheckLootRefs();
423 SendGlobalSysMessage("DB table `skinning_loot_template` reloaded.");
427 bool ChatHandler::HandleReloadLootTemplatesSpellCommand(const char*)
429 sLog
.outString( "Re-Loading Loot Tables... (`spell_loot_template`)" );
430 LoadLootTemplates_Spell();
431 LootTemplates_Spell
.CheckLootRefs();
432 SendGlobalSysMessage("DB table `spell_loot_template` reloaded.");
436 bool ChatHandler::HandleReloadMangosStringCommand(const char*)
438 sLog
.outString( "Re-Loading mangos_string Table!" );
439 sObjectMgr
.LoadMangosStrings();
440 SendGlobalSysMessage("DB table `mangos_string` reloaded.");
444 bool ChatHandler::HandleReloadNpcGossipCommand(const char*)
446 sLog
.outString( "Re-Loading `npc_gossip` Table!" );
447 sObjectMgr
.LoadNpcTextId();
448 SendGlobalSysMessage("DB table `npc_gossip` reloaded.");
452 bool ChatHandler::HandleReloadNpcTrainerCommand(const char*)
454 sLog
.outString( "Re-Loading `npc_trainer` Table!" );
455 sObjectMgr
.LoadTrainerSpell();
456 SendGlobalSysMessage("DB table `npc_trainer` reloaded.");
460 bool ChatHandler::HandleReloadNpcVendorCommand(const char*)
462 sLog
.outString( "Re-Loading `npc_vendor` Table!" );
463 sObjectMgr
.LoadVendors();
464 SendGlobalSysMessage("DB table `npc_vendor` reloaded.");
468 bool ChatHandler::HandleReloadPointsOfInterestCommand(const char*)
470 sLog
.outString( "Re-Loading `points_of_interest` Table!" );
471 sObjectMgr
.LoadPointsOfInterest();
472 SendGlobalSysMessage("DB table `points_of_interest` reloaded.");
476 bool ChatHandler::HandleReloadSpellClickSpellsCommand(const char*)
478 sLog
.outString( "Re-Loading `npc_spellclick_spells` Table!" );
479 sObjectMgr
.LoadNPCSpellClickSpells();
480 SendGlobalSysMessage("DB table `npc_spellclick_spells` reloaded.");
484 bool ChatHandler::HandleReloadReservedNameCommand(const char*)
486 sLog
.outString( "Loading ReservedNames... (`reserved_name`)" );
487 sObjectMgr
.LoadReservedPlayersNames();
488 SendGlobalSysMessage("DB table `reserved_name` (player reserved names) reloaded.");
492 bool ChatHandler::HandleReloadSkillDiscoveryTemplateCommand(const char* /*args*/)
494 sLog
.outString( "Re-Loading Skill Discovery Table..." );
495 LoadSkillDiscoveryTable();
496 SendGlobalSysMessage("DB table `skill_discovery_template` (recipes discovered at crafting) reloaded.");
500 bool ChatHandler::HandleReloadSkillExtraItemTemplateCommand(const char* /*args*/)
502 sLog
.outString( "Re-Loading Skill Extra Item Table..." );
503 LoadSkillExtraItemTable();
504 SendGlobalSysMessage("DB table `skill_extra_item_template` (extra item creation when crafting) reloaded.");
508 bool ChatHandler::HandleReloadSkillFishingBaseLevelCommand(const char* /*args*/)
510 sLog
.outString( "Re-Loading Skill Fishing base level requirements..." );
511 sObjectMgr
.LoadFishingBaseSkillLevel();
512 SendGlobalSysMessage("DB table `skill_fishing_base_level` (fishing base level for zone/subzone) reloaded.");
516 bool ChatHandler::HandleReloadSpellAreaCommand(const char*)
518 sLog
.outString( "Re-Loading SpellArea Data..." );
519 sSpellMgr
.LoadSpellAreas();
520 SendGlobalSysMessage("DB table `spell_area` (spell dependences from area/quest/auras state) reloaded.");
524 bool ChatHandler::HandleReloadSpellChainCommand(const char*)
526 sLog
.outString( "Re-Loading Spell Chain Data... " );
527 sSpellMgr
.LoadSpellChains();
528 SendGlobalSysMessage("DB table `spell_chain` (spell ranks) reloaded.");
532 bool ChatHandler::HandleReloadSpellElixirCommand(const char*)
534 sLog
.outString( "Re-Loading Spell Elixir types..." );
535 sSpellMgr
.LoadSpellElixirs();
536 SendGlobalSysMessage("DB table `spell_elixir` (spell elixir types) reloaded.");
540 bool ChatHandler::HandleReloadSpellLearnSpellCommand(const char*)
542 sLog
.outString( "Re-Loading Spell Learn Spells..." );
543 sSpellMgr
.LoadSpellLearnSpells();
544 SendGlobalSysMessage("DB table `spell_learn_spell` reloaded.");
548 bool ChatHandler::HandleReloadSpellProcEventCommand(const char*)
550 sLog
.outString( "Re-Loading Spell Proc Event conditions..." );
551 sSpellMgr
.LoadSpellProcEvents();
552 SendGlobalSysMessage("DB table `spell_proc_event` (spell proc trigger requirements) reloaded.");
556 bool ChatHandler::HandleReloadSpellBonusesCommand(const char*)
558 sLog
.outString( "Re-Loading Spell Bonus Data..." );
559 sSpellMgr
.LoadSpellBonusess();
560 SendGlobalSysMessage("DB table `spell_bonus_data` (spell damage/healing coefficients) reloaded.");
564 bool ChatHandler::HandleReloadSpellProcItemEnchantCommand(const char*)
566 sLog
.outString( "Re-Loading Spell Proc Item Enchant..." );
567 sSpellMgr
.LoadSpellProcItemEnchant();
568 SendGlobalSysMessage("DB table `spell_proc_item_enchant` (item enchantment ppm) reloaded.");
572 bool ChatHandler::HandleReloadSpellScriptTargetCommand(const char*)
574 sLog
.outString( "Re-Loading SpellsScriptTarget..." );
575 sSpellMgr
.LoadSpellScriptTarget();
576 SendGlobalSysMessage("DB table `spell_script_target` (spell targets selection in case specific creature/GO requirements) reloaded.");
580 bool ChatHandler::HandleReloadSpellTargetPositionCommand(const char*)
582 sLog
.outString( "Re-Loading Spell target coordinates..." );
583 sSpellMgr
.LoadSpellTargetPositions();
584 SendGlobalSysMessage("DB table `spell_target_position` (destination coordinates for spell targets) reloaded.");
588 bool ChatHandler::HandleReloadSpellThreatsCommand(const char*)
590 sLog
.outString( "Re-Loading Aggro Spells Definitions...");
591 sSpellMgr
.LoadSpellThreats();
592 SendGlobalSysMessage("DB table `spell_threat` (spell aggro definitions) reloaded.");
596 bool ChatHandler::HandleReloadSpellPetAurasCommand(const char*)
598 sLog
.outString( "Re-Loading Spell pet auras...");
599 sSpellMgr
.LoadSpellPetAuras();
600 SendGlobalSysMessage("DB table `spell_pet_auras` reloaded.");
604 bool ChatHandler::HandleReloadPageTextsCommand(const char*)
606 sLog
.outString( "Re-Loading Page Texts..." );
607 sObjectMgr
.LoadPageTexts();
608 SendGlobalSysMessage("DB table `page_texts` reloaded.");
612 bool ChatHandler::HandleReloadItemEnchantementsCommand(const char*)
614 sLog
.outString( "Re-Loading Item Random Enchantments Table..." );
615 LoadRandomEnchantmentsTable();
616 SendGlobalSysMessage("DB table `item_enchantment_template` reloaded.");
620 bool ChatHandler::HandleReloadItemRequiredTragetCommand(const char*)
622 sLog
.outString( "Re-Loading Item Required Targets Table..." );
623 sObjectMgr
.LoadItemRequiredTarget();
624 SendGlobalSysMessage("DB table `item_required_target` reloaded.");
628 bool ChatHandler::HandleReloadBattleEventCommand(const char*)
630 sLog
.outString( "Re-Loading BattleGround Eventindexes..." );
631 sBattleGroundMgr
.LoadBattleEventIndexes();
632 SendGlobalSysMessage("DB table `gameobject_battleground` and `creature_battleground` reloaded.");
636 bool ChatHandler::HandleReloadGameObjectScriptsCommand(const char* arg
)
638 if(sWorld
.IsScriptScheduled())
640 SendSysMessage("DB scripts used currently, please attempt reload later.");
641 SetSentErrorMessage(true);
646 sLog
.outString( "Re-Loading Scripts from `gameobject_scripts`...");
648 sObjectMgr
.LoadGameObjectScripts();
651 SendGlobalSysMessage("DB table `gameobject_scripts` reloaded.");
656 bool ChatHandler::HandleReloadEventScriptsCommand(const char* arg
)
658 if(sWorld
.IsScriptScheduled())
660 SendSysMessage("DB scripts used currently, please attempt reload later.");
661 SetSentErrorMessage(true);
666 sLog
.outString( "Re-Loading Scripts from `event_scripts`...");
668 sObjectMgr
.LoadEventScripts();
671 SendGlobalSysMessage("DB table `event_scripts` reloaded.");
676 bool ChatHandler::HandleReloadEventAITextsCommand(const char* arg
)
679 sLog
.outString( "Re-Loading Texts from `creature_ai_texts`...");
680 sEventAIMgr
.LoadCreatureEventAI_Texts(true);
681 SendGlobalSysMessage("DB table `creature_ai_texts` reloaded.");
685 bool ChatHandler::HandleReloadEventAISummonsCommand(const char* arg
)
687 sLog
.outString( "Re-Loading Summons from `creature_ai_summons`...");
688 sEventAIMgr
.LoadCreatureEventAI_Summons(true);
689 SendGlobalSysMessage("DB table `creature_ai_summons` reloaded.");
693 bool ChatHandler::HandleReloadEventAIScriptsCommand(const char* arg
)
695 sLog
.outString( "Re-Loading Scripts from `creature_ai_scripts`...");
696 sEventAIMgr
.LoadCreatureEventAI_Scripts();
697 SendGlobalSysMessage("DB table `creature_ai_scripts` reloaded.");
701 bool ChatHandler::HandleReloadQuestEndScriptsCommand(const char* arg
)
703 if(sWorld
.IsScriptScheduled())
705 SendSysMessage("DB scripts used currently, please attempt reload later.");
706 SetSentErrorMessage(true);
711 sLog
.outString( "Re-Loading Scripts from `quest_end_scripts`...");
713 sObjectMgr
.LoadQuestEndScripts();
716 SendGlobalSysMessage("DB table `quest_end_scripts` reloaded.");
721 bool ChatHandler::HandleReloadQuestStartScriptsCommand(const char* arg
)
723 if(sWorld
.IsScriptScheduled())
725 SendSysMessage("DB scripts used currently, please attempt reload later.");
726 SetSentErrorMessage(true);
731 sLog
.outString( "Re-Loading Scripts from `quest_start_scripts`...");
733 sObjectMgr
.LoadQuestStartScripts();
736 SendGlobalSysMessage("DB table `quest_start_scripts` reloaded.");
741 bool ChatHandler::HandleReloadSpellScriptsCommand(const char* arg
)
743 if(sWorld
.IsScriptScheduled())
745 SendSysMessage("DB scripts used currently, please attempt reload later.");
746 SetSentErrorMessage(true);
751 sLog
.outString( "Re-Loading Scripts from `spell_scripts`...");
753 sObjectMgr
.LoadSpellScripts();
756 SendGlobalSysMessage("DB table `spell_scripts` reloaded.");
761 bool ChatHandler::HandleReloadDbScriptStringCommand(const char* /*arg*/)
763 sLog
.outString( "Re-Loading Script strings from `db_script_string`...");
764 sObjectMgr
.LoadDbScriptStrings();
765 SendGlobalSysMessage("DB table `db_script_string` reloaded.");
769 bool ChatHandler::HandleReloadGameGraveyardZoneCommand(const char* /*arg*/)
771 sLog
.outString( "Re-Loading Graveyard-zone links...");
773 sObjectMgr
.LoadGraveyardZones();
775 SendGlobalSysMessage("DB table `game_graveyard_zone` reloaded.");
780 bool ChatHandler::HandleReloadGameTeleCommand(const char* /*arg*/)
782 sLog
.outString( "Re-Loading Game Tele coordinates...");
784 sObjectMgr
.LoadGameTele();
786 SendGlobalSysMessage("DB table `game_tele` reloaded.");
791 bool ChatHandler::HandleReloadLocalesAchievementRewardCommand(const char*)
793 sLog
.outString( "Re-Loading Locales Achievement Reward Data..." );
794 sAchievementMgr
.LoadRewardLocales();
795 SendGlobalSysMessage("DB table `locales_achievement_reward` reloaded.");
799 bool ChatHandler::HandleReloadLocalesCreatureCommand(const char* /*arg*/)
801 sLog
.outString( "Re-Loading Locales Creature ...");
802 sObjectMgr
.LoadCreatureLocales();
803 SendGlobalSysMessage("DB table `locales_creature` reloaded.");
807 bool ChatHandler::HandleReloadLocalesGameobjectCommand(const char* /*arg*/)
809 sLog
.outString( "Re-Loading Locales Gameobject ... ");
810 sObjectMgr
.LoadGameObjectLocales();
811 SendGlobalSysMessage("DB table `locales_gameobject` reloaded.");
815 bool ChatHandler::HandleReloadLocalesGossipMenuOptionCommand(const char* /*arg*/)
817 sLog
.outString( "Re-Loading Locales Gossip Menu Option ... ");
818 sObjectMgr
.LoadGossipMenuItemsLocales();
819 SendGlobalSysMessage("DB table `locales_gossip_menu_option` reloaded.");
823 bool ChatHandler::HandleReloadLocalesItemCommand(const char* /*arg*/)
825 sLog
.outString( "Re-Loading Locales Item ... ");
826 sObjectMgr
.LoadItemLocales();
827 SendGlobalSysMessage("DB table `locales_item` reloaded.");
831 bool ChatHandler::HandleReloadLocalesNpcTextCommand(const char* /*arg*/)
833 sLog
.outString( "Re-Loading Locales NPC Text ... ");
834 sObjectMgr
.LoadNpcTextLocales();
835 SendGlobalSysMessage("DB table `locales_npc_text` reloaded.");
839 bool ChatHandler::HandleReloadLocalesPageTextCommand(const char* /*arg*/)
841 sLog
.outString( "Re-Loading Locales Page Text ... ");
842 sObjectMgr
.LoadPageTextLocales();
843 SendGlobalSysMessage("DB table `locales_page_text` reloaded.");
847 bool ChatHandler::HandleReloadLocalesPointsOfInterestCommand(const char* /*arg*/)
849 sLog
.outString( "Re-Loading Locales Points Of Interest ... ");
850 sObjectMgr
.LoadPointOfInterestLocales();
851 SendGlobalSysMessage("DB table `locales_points_of_interest` reloaded.");
855 bool ChatHandler::HandleReloadLocalesQuestCommand(const char* /*arg*/)
857 sLog
.outString( "Re-Loading Locales Quest ... ");
858 sObjectMgr
.LoadQuestLocales();
859 SendGlobalSysMessage("DB table `locales_quest` reloaded.");
863 bool ChatHandler::HandleReloadMailLevelRewardCommand(const char* /*arg*/)
865 sLog
.outString( "Re-Loading Player level dependent mail rewards..." );
866 sObjectMgr
.LoadMailLevelRewards();
867 SendGlobalSysMessage("DB table `mail_level_reward` reloaded.");
871 bool ChatHandler::HandleLoadScriptsCommand(const char* args
)
873 if(!LoadScriptingModule(args
)) return true;
875 sWorld
.SendWorldText(LANG_SCRIPTS_RELOADED
);
879 bool ChatHandler::HandleAccountSetGmLevelCommand(const char* args
)
881 char* arg1
= strtok((char*)args
, " ");
885 /// must be NULL if targeted syntax and must be not nULL if not targeted
886 char* arg2
= strtok(NULL
, " ");
888 std::string targetAccountName
;
889 uint32 targetAccountId
= 0;
891 /// only target player different from self allowed (if targetPlayer!=NULL then not console)
892 Player
* targetPlayer
= getSelectedPlayer();
893 if(targetPlayer
&& m_session
->GetPlayer()!=targetPlayer
)
895 /// wrong command syntax or unexpected targeting
899 /// security level expected in arg2 after this if.
902 targetAccountId
= targetPlayer
->GetSession()->GetAccountId();
903 sAccountMgr
.GetName(targetAccountId
, targetAccountName
);
907 /// wrong command syntax (second arg expected)
911 targetAccountName
= arg1
;
912 if (!AccountMgr::normalizeString(targetAccountName
))
914 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,targetAccountName
.c_str());
915 SetSentErrorMessage(true);
919 targetAccountId
= sAccountMgr
.GetId(targetAccountName
);
922 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,targetAccountName
.c_str());
923 SetSentErrorMessage(true);
928 int32 gm
= (int32
)atoi(arg2
);
929 if ( gm
< SEC_PLAYER
|| gm
> SEC_ADMINISTRATOR
)
931 SendSysMessage(LANG_BAD_VALUE
);
932 SetSentErrorMessage(true);
936 /// can set security level only for target with less security and to less security that we have
937 /// This will reject self apply by specify account name
938 if(HasLowerSecurityAccount(NULL
,targetAccountId
,true))
941 /// account can't set security to same or grater level, need more power GM or console
942 AccountTypes plSecurity
= m_session
? m_session
->GetSecurity() : SEC_CONSOLE
;
943 if (AccountTypes(gm
) >= plSecurity
)
945 SendSysMessage(LANG_YOURS_SECURITY_IS_LOW
);
946 SetSentErrorMessage(true);
950 // This will prevent self apply by self target or no target
951 if(targetPlayer
&& m_session
->GetPlayer()!=targetPlayer
)
953 ChatHandler(targetPlayer
).PSendSysMessage(LANG_YOURS_SECURITY_CHANGED
,GetNameLink().c_str(), gm
);
954 targetPlayer
->GetSession()->SetSecurity(AccountTypes(gm
));
957 PSendSysMessage(LANG_YOU_CHANGE_SECURITY
, targetAccountName
.c_str(), gm
);
958 loginDatabase
.PExecute("UPDATE account SET gmlevel = '%i' WHERE id = '%u'", gm
, targetAccountId
);
963 /// Set password for account
964 bool ChatHandler::HandleAccountSetPasswordCommand(const char* args
)
969 ///- Get the command line arguments
970 char *szAccount
= strtok ((char*)args
," ");
971 char *szPassword1
= strtok (NULL
," ");
972 char *szPassword2
= strtok (NULL
," ");
974 if (!szAccount
||!szPassword1
|| !szPassword2
)
977 std::string account_name
= szAccount
;
978 if (!AccountMgr::normalizeString(account_name
))
980 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
981 SetSentErrorMessage(true);
985 uint32 targetAccountId
= sAccountMgr
.GetId(account_name
);
986 if (!targetAccountId
)
988 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
989 SetSentErrorMessage(true);
993 /// can set password only for target with less security
994 /// This is also reject self apply in fact
995 if(HasLowerSecurityAccount (NULL
,targetAccountId
,true))
998 if (strcmp(szPassword1
,szPassword2
))
1000 SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH
);
1001 SetSentErrorMessage (true);
1005 AccountOpResult result
= sAccountMgr
.ChangePassword(targetAccountId
, szPassword1
);
1010 SendSysMessage(LANG_COMMAND_PASSWORD
);
1012 case AOR_NAME_NOT_EXIST
:
1013 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
1014 SetSentErrorMessage(true);
1016 case AOR_PASS_TOO_LONG
:
1017 SendSysMessage(LANG_PASSWORD_TOO_LONG
);
1018 SetSentErrorMessage(true);
1021 SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD
);
1022 SetSentErrorMessage(true);
1029 bool ChatHandler::HandleMaxSkillCommand(const char* /*args*/)
1031 Player
* SelectedPlayer
= getSelectedPlayer();
1034 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1035 SetSentErrorMessage(true);
1039 // each skills that have max skill value dependent from level seted to current level max skill value
1040 SelectedPlayer
->UpdateSkillsToMaxSkillsForLevel();
1044 bool ChatHandler::HandleSetSkillCommand(const char* args
)
1046 // number or [name] Shift-click form |color|Hskill:skill_id|h[name]|h|r
1047 char* skill_p
= extractKeyFromLink((char*)args
,"Hskill");
1051 char *level_p
= strtok (NULL
, " ");
1056 char *max_p
= strtok (NULL
, " ");
1058 int32 skill
= atoi(skill_p
);
1061 PSendSysMessage(LANG_INVALID_SKILL_ID
, skill
);
1062 SetSentErrorMessage(true);
1066 int32 level
= atol (level_p
);
1068 Player
* target
= getSelectedPlayer();
1071 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1072 SetSentErrorMessage(true);
1076 SkillLineEntry
const* sl
= sSkillLineStore
.LookupEntry(skill
);
1079 PSendSysMessage(LANG_INVALID_SKILL_ID
, skill
);
1080 SetSentErrorMessage(true);
1084 std::string tNameLink
= GetNameLink(target
);
1086 if(!target
->GetSkillValue(skill
))
1088 PSendSysMessage(LANG_SET_SKILL_ERROR
, tNameLink
.c_str(), skill
, sl
->name
[GetSessionDbcLocale()]);
1089 SetSentErrorMessage(true);
1093 int32 max
= max_p
? atol (max_p
) : target
->GetPureMaxSkillValue(skill
);
1095 if( level
<= 0 || level
> max
|| max
<= 0 )
1098 target
->SetSkill(skill
, level
, max
);
1099 PSendSysMessage(LANG_SET_SKILL
, skill
, sl
->name
[GetSessionDbcLocale()], tNameLink
.c_str(), level
, max
);
1104 bool ChatHandler::HandleUnLearnCommand(const char* args
)
1109 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
1110 uint32 spell_id
= extractSpellIdFromLink((char*)args
);
1114 char const* allStr
= strtok(NULL
," ");
1115 bool allRanks
= allStr
? (strncmp(allStr
, "all", strlen(allStr
)) == 0) : false;
1117 Player
* target
= getSelectedPlayer();
1120 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1121 SetSentErrorMessage(true);
1126 spell_id
= sSpellMgr
.GetFirstSpellInChain (spell_id
);
1128 if (target
->HasSpell(spell_id
))
1129 target
->removeSpell(spell_id
,false,!allRanks
);
1131 SendSysMessage(LANG_FORGET_SPELL
);
1133 if(GetTalentSpellCost(spell_id
))
1134 target
->SendTalentsInfoData(false);
1139 bool ChatHandler::HandleCooldownCommand(const char* args
)
1141 Player
* target
= getSelectedPlayer();
1144 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1145 SetSentErrorMessage(true);
1149 std::string tNameLink
= GetNameLink(target
);
1153 target
->RemoveAllSpellCooldown();
1154 PSendSysMessage(LANG_REMOVEALL_COOLDOWN
, tNameLink
.c_str());
1158 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1159 uint32 spell_id
= extractSpellIdFromLink((char*)args
);
1163 if(!sSpellStore
.LookupEntry(spell_id
))
1165 PSendSysMessage(LANG_UNKNOWN_SPELL
, target
==m_session
->GetPlayer() ? GetMangosString(LANG_YOU
) : tNameLink
.c_str());
1166 SetSentErrorMessage(true);
1170 target
->RemoveSpellCooldown(spell_id
,true);
1171 PSendSysMessage(LANG_REMOVE_COOLDOWN
, spell_id
, target
==m_session
->GetPlayer() ? GetMangosString(LANG_YOU
) : tNameLink
.c_str());
1176 bool ChatHandler::HandleLearnAllCommand(const char* /*args*/)
1178 static const char *allSpellList
[] =
1561 //"9036", problems with ghost state
1570 //"6718", phasing stealth, annoying for learn all case.
1783 while(strcmp(allSpellList
[loop
], "0"))
1785 uint32 spell
= atol((char*)allSpellList
[loop
++]);
1787 if (m_session
->GetPlayer()->HasSpell(spell
))
1790 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1791 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1793 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1797 m_session
->GetPlayer()->learnSpell(spell
,false);
1800 SendSysMessage(LANG_COMMAND_LEARN_MANY_SPELLS
);
1805 bool ChatHandler::HandleLearnAllGMCommand(const char* /*args*/)
1807 static const char *gmSpellList
[] =
1809 "24347", // Become A Fish, No Breath Bar
1810 "35132", // Visual Boom
1811 "38488", // Attack 4000-8000 AOE
1812 "38795", // Attack 2000 AOE + Slow Down 90%
1813 "15712", // Attack 200
1814 "1852", // GM Spell Silence
1817 "29878", // Kill My Self
1818 "26644", // More Kill
1820 "28550", //Invisible 24
1821 "23452", //Invisible + Target
1825 uint16 gmSpellIter
= 0;
1826 while( strcmp(gmSpellList
[gmSpellIter
], "0") )
1828 uint32 spell
= atol((char*)gmSpellList
[gmSpellIter
++]);
1830 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1831 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1833 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1837 m_session
->GetPlayer()->learnSpell(spell
,false);
1840 SendSysMessage(LANG_LEARNING_GM_SKILLS
);
1844 bool ChatHandler::HandleLearnAllMyClassCommand(const char* /*args*/)
1846 HandleLearnAllMySpellsCommand("");
1847 HandleLearnAllMyTalentsCommand("");
1851 bool ChatHandler::HandleLearnAllMySpellsCommand(const char* /*args*/)
1853 ChrClassesEntry
const* clsEntry
= sChrClassesStore
.LookupEntry(m_session
->GetPlayer()->getClass());
1856 uint32 family
= clsEntry
->spellfamily
;
1858 for (uint32 i
= 0; i
< sSpellStore
.GetNumRows(); ++i
)
1860 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(i
);
1864 // skip server-side/triggered spells
1865 if(spellInfo
->spellLevel
==0)
1868 // skip wrong class/race skills
1869 if(!m_session
->GetPlayer()->IsSpellFitByClassAndRace(spellInfo
->Id
))
1872 // skip other spell families
1873 if( spellInfo
->SpellFamilyName
!= family
)
1876 // skip spells with first rank learned as talent (and all talents then also)
1877 uint32 first_rank
= sSpellMgr
.GetFirstSpellInChain(spellInfo
->Id
);
1878 if(GetTalentSpellCost(first_rank
) > 0 )
1881 // skip broken spells
1882 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1885 m_session
->GetPlayer()->learnSpell(i
,false);
1888 SendSysMessage(LANG_COMMAND_LEARN_CLASS_SPELLS
);
1892 bool ChatHandler::HandleLearnAllMyTalentsCommand(const char* /*args*/)
1894 Player
* player
= m_session
->GetPlayer();
1895 uint32 classMask
= player
->getClassMask();
1897 for (uint32 i
= 0; i
< sTalentStore
.GetNumRows(); ++i
)
1899 TalentEntry
const *talentInfo
= sTalentStore
.LookupEntry(i
);
1903 TalentTabEntry
const *talentTabInfo
= sTalentTabStore
.LookupEntry( talentInfo
->TalentTab
);
1907 if( (classMask
& talentTabInfo
->ClassMask
) == 0 )
1910 // search highest talent rank
1913 for(int rank
= MAX_TALENT_RANK
-1; rank
>= 0; --rank
)
1915 if(talentInfo
->RankID
[rank
]!=0)
1917 spellid
= talentInfo
->RankID
[rank
];
1922 if(!spellid
) // ??? none spells in talent
1925 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spellid
);
1926 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1929 // learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
1930 player
->learnSpellHighRank(spellid
);
1933 SendSysMessage(LANG_COMMAND_LEARN_CLASS_TALENTS
);
1937 bool ChatHandler::HandleLearnAllMyPetTalentsCommand(const char* /*args*/)
1939 Player
* player
= m_session
->GetPlayer();
1941 Pet
* pet
= player
->GetPet();
1944 SendSysMessage(LANG_NO_PET_FOUND
);
1945 SetSentErrorMessage(true);
1949 CreatureInfo
const *ci
= pet
->GetCreatureInfo();
1952 SendSysMessage(LANG_WRONG_PET_TYPE
);
1953 SetSentErrorMessage(true);
1957 CreatureFamilyEntry
const *pet_family
= sCreatureFamilyStore
.LookupEntry(ci
->family
);
1960 SendSysMessage(LANG_WRONG_PET_TYPE
);
1961 SetSentErrorMessage(true);
1965 if(pet_family
->petTalentType
< 0) // not hunter pet
1967 SendSysMessage(LANG_WRONG_PET_TYPE
);
1968 SetSentErrorMessage(true);
1972 for (uint32 i
= 0; i
< sTalentStore
.GetNumRows(); ++i
)
1974 TalentEntry
const *talentInfo
= sTalentStore
.LookupEntry(i
);
1978 TalentTabEntry
const *talentTabInfo
= sTalentTabStore
.LookupEntry( talentInfo
->TalentTab
);
1982 // prevent learn talent for different family (cheating)
1983 if(((1 << pet_family
->petTalentType
) & talentTabInfo
->petTalentMask
)==0)
1986 // search highest talent rank
1989 for(int rank
= MAX_TALENT_RANK
-1; rank
>= 0; --rank
)
1991 if(talentInfo
->RankID
[rank
]!=0)
1993 spellid
= talentInfo
->RankID
[rank
];
1998 if(!spellid
) // ??? none spells in talent
2001 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spellid
);
2002 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
2005 // learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
2006 pet
->learnSpellHighRank(spellid
);
2009 SendSysMessage(LANG_COMMAND_LEARN_PET_TALENTS
);
2013 bool ChatHandler::HandleLearnAllLangCommand(const char* /*args*/)
2015 // skipping UNIVERSAL language (0)
2016 for(int i
= 1; i
< LANGUAGES_COUNT
; ++i
)
2017 m_session
->GetPlayer()->learnSpell(lang_description
[i
].spell_id
,false);
2019 SendSysMessage(LANG_COMMAND_LEARN_ALL_LANG
);
2023 bool ChatHandler::HandleLearnAllDefaultCommand(const char* args
)
2026 if(!extractPlayerTarget((char*)args
,&target
))
2029 target
->learnDefaultSpells();
2030 target
->learnQuestRewardedSpells();
2032 PSendSysMessage(LANG_COMMAND_LEARN_ALL_DEFAULT_AND_QUEST
,GetNameLink(target
).c_str());
2036 bool ChatHandler::HandleLearnCommand(const char* args
)
2038 Player
* targetPlayer
= getSelectedPlayer();
2042 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
2043 SetSentErrorMessage(true);
2047 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
2048 uint32 spell
= extractSpellIdFromLink((char*)args
);
2049 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
2052 char const* allStr
= strtok(NULL
," ");
2053 bool allRanks
= allStr
? (strncmp(allStr
, "all", strlen(allStr
)) == 0) : false;
2055 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
2056 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
2058 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
2059 SetSentErrorMessage(true);
2063 if (!allRanks
&& targetPlayer
->HasSpell(spell
))
2065 if(targetPlayer
== m_session
->GetPlayer())
2066 SendSysMessage(LANG_YOU_KNOWN_SPELL
);
2068 PSendSysMessage(LANG_TARGET_KNOWN_SPELL
,GetNameLink(targetPlayer
).c_str());
2069 SetSentErrorMessage(true);
2074 targetPlayer
->learnSpellHighRank(spell
);
2076 targetPlayer
->learnSpell(spell
,false);
2078 uint32 first_spell
= sSpellMgr
.GetFirstSpellInChain(spell
);
2079 if(GetTalentSpellCost(first_spell
))
2080 targetPlayer
->SendTalentsInfoData(false);
2085 bool ChatHandler::HandleAddItemCommand(const char* args
)
2092 if(args
[0]=='[') // [name] manual form
2094 char* citemName
= strtok((char*)args
, "]");
2096 if(citemName
&& citemName
[0])
2098 std::string itemName
= citemName
+1;
2099 WorldDatabase
.escape_string(itemName
);
2100 QueryResult
*result
= WorldDatabase
.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName
.c_str());
2103 PSendSysMessage(LANG_COMMAND_COULDNOTFIND
, citemName
+1);
2104 SetSentErrorMessage(true);
2107 itemId
= result
->Fetch()->GetUInt16();
2113 else // item_id or [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r
2115 char* cId
= extractKeyFromLink((char*)args
,"Hitem");
2121 char* ccount
= strtok(NULL
, " ");
2126 count
= strtol(ccount
, NULL
, 10);
2131 Player
* pl
= m_session
->GetPlayer();
2132 Player
* plTarget
= getSelectedPlayer();
2136 sLog
.outDetail(GetMangosString(LANG_ADDITEM
), itemId
, count
);
2138 ItemPrototype
const *pProto
= ObjectMgr::GetItemPrototype(itemId
);
2141 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, itemId
);
2142 SetSentErrorMessage(true);
2149 plTarget
->DestroyItemCount(itemId
, -count
, true, false);
2150 PSendSysMessage(LANG_REMOVEITEM
, itemId
, -count
, GetNameLink(plTarget
).c_str());
2155 uint32 noSpaceForCount
= 0;
2157 // check space and find places
2158 ItemPosCountVec dest
;
2159 uint8 msg
= plTarget
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, itemId
, count
, &noSpaceForCount
);
2160 if( msg
!= EQUIP_ERR_OK
) // convert to possible store amount
2161 count
-= noSpaceForCount
;
2163 if( count
== 0 || dest
.empty()) // can't add any
2165 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, itemId
, noSpaceForCount
);
2166 SetSentErrorMessage(true);
2170 Item
* item
= plTarget
->StoreNewItem( dest
, itemId
, true, Item::GenerateItemRandomPropertyId(itemId
));
2172 // remove binding (let GM give it to another player later)
2174 for(ItemPosCountVec::const_iterator itr
= dest
.begin(); itr
!= dest
.end(); ++itr
)
2175 if(Item
* item1
= pl
->GetItemByPos(itr
->pos
))
2176 item1
->SetBinding( false );
2178 if(count
> 0 && item
)
2180 pl
->SendNewItem(item
,count
,false,true);
2182 plTarget
->SendNewItem(item
,count
,true,false);
2185 if(noSpaceForCount
> 0)
2186 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, itemId
, noSpaceForCount
);
2191 bool ChatHandler::HandleAddItemSetCommand(const char* args
)
2196 char* cId
= extractKeyFromLink((char*)args
,"Hitemset"); // number or [name] Shift-click form |color|Hitemset:itemset_id|h[name]|h|r
2200 uint32 itemsetId
= atol(cId
);
2202 // prevent generation all items with itemset field value '0'
2205 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND
,itemsetId
);
2206 SetSentErrorMessage(true);
2210 Player
* pl
= m_session
->GetPlayer();
2211 Player
* plTarget
= getSelectedPlayer();
2215 sLog
.outDetail(GetMangosString(LANG_ADDITEMSET
), itemsetId
);
2218 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
2220 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
2224 if (pProto
->ItemSet
== itemsetId
)
2227 ItemPosCountVec dest
;
2228 uint8 msg
= plTarget
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, pProto
->ItemId
, 1 );
2229 if (msg
== EQUIP_ERR_OK
)
2231 Item
* item
= plTarget
->StoreNewItem( dest
, pProto
->ItemId
, true);
2233 // remove binding (let GM give it to another player later)
2235 item
->SetBinding( false );
2237 pl
->SendNewItem(item
,1,false,true);
2239 plTarget
->SendNewItem(item
,1,true,false);
2243 pl
->SendEquipError( msg
, NULL
, NULL
);
2244 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, pProto
->ItemId
, 1);
2251 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND
,itemsetId
);
2253 SetSentErrorMessage(true);
2260 bool ChatHandler::HandleListItemCommand(const char* args
)
2265 char* cId
= extractKeyFromLink((char*)args
,"Hitem");
2269 uint32 item_id
= atol(cId
);
2272 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
2273 SetSentErrorMessage(true);
2277 ItemPrototype
const* itemProto
= ObjectMgr::GetItemPrototype(item_id
);
2280 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
2281 SetSentErrorMessage(true);
2285 char* c_count
= strtok(NULL
, " ");
2286 int count
= c_count
? atol(c_count
) : 10;
2291 QueryResult
*result
;
2294 uint32 inv_count
= 0;
2295 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM character_inventory WHERE item_template='%u'",item_id
);
2298 inv_count
= (*result
)[0].GetUInt32();
2302 result
=CharacterDatabase
.PQuery(
2304 "SELECT ci.item, cibag.slot AS bag, ci.slot, ci.guid, characters.account,characters.name "
2305 "FROM character_inventory AS ci LEFT JOIN character_inventory AS cibag ON (cibag.item=ci.bag),characters "
2306 "WHERE ci.item_template='%u' AND ci.guid = characters.guid LIMIT %u ",
2307 item_id
,uint32(count
));
2313 Field
*fields
= result
->Fetch();
2314 uint32 item_guid
= fields
[0].GetUInt32();
2315 uint32 item_bag
= fields
[1].GetUInt32();
2316 uint32 item_slot
= fields
[2].GetUInt32();
2317 uint32 owner_guid
= fields
[3].GetUInt32();
2318 uint32 owner_acc
= fields
[4].GetUInt32();
2319 std::string owner_name
= fields
[5].GetCppString();
2321 char const* item_pos
= 0;
2322 if(Player::IsEquipmentPos(item_bag
,item_slot
))
2323 item_pos
= "[equipped]";
2324 else if(Player::IsInventoryPos(item_bag
,item_slot
))
2325 item_pos
= "[in inventory]";
2326 else if(Player::IsBankPos(item_bag
,item_slot
))
2327 item_pos
= "[in bank]";
2331 PSendSysMessage(LANG_ITEMLIST_SLOT
,
2332 item_guid
,owner_name
.c_str(),owner_guid
,owner_acc
,item_pos
);
2333 } while (result
->NextRow());
2335 int64 res_count
= result
->GetRowCount();
2339 if(count
> res_count
)
2346 uint32 mail_count
= 0;
2347 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM mail_items WHERE item_template='%u'", item_id
);
2350 mail_count
= (*result
)[0].GetUInt32();
2356 result
=CharacterDatabase
.PQuery(
2358 "SELECT mail_items.item_guid, mail.sender, mail.receiver, char_s.account, char_s.name, char_r.account, char_r.name "
2359 "FROM mail,mail_items,characters as char_s,characters as char_r "
2360 "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",
2361 item_id
,uint32(count
));
2370 Field
*fields
= result
->Fetch();
2371 uint32 item_guid
= fields
[0].GetUInt32();
2372 uint32 item_s
= fields
[1].GetUInt32();
2373 uint32 item_r
= fields
[2].GetUInt32();
2374 uint32 item_s_acc
= fields
[3].GetUInt32();
2375 std::string item_s_name
= fields
[4].GetCppString();
2376 uint32 item_r_acc
= fields
[5].GetUInt32();
2377 std::string item_r_name
= fields
[6].GetCppString();
2379 char const* item_pos
= "[in mail]";
2381 PSendSysMessage(LANG_ITEMLIST_MAIL
,
2382 item_guid
,item_s_name
.c_str(),item_s
,item_s_acc
,item_r_name
.c_str(),item_r
,item_r_acc
,item_pos
);
2383 } while (result
->NextRow());
2385 int64 res_count
= result
->GetRowCount();
2389 if(count
> res_count
)
2396 uint32 auc_count
= 0;
2397 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM auctionhouse WHERE item_template='%u'",item_id
);
2400 auc_count
= (*result
)[0].GetUInt32();
2406 result
=CharacterDatabase
.PQuery(
2408 "SELECT auctionhouse.itemguid, auctionhouse.itemowner, characters.account, characters.name "
2409 "FROM auctionhouse,characters WHERE auctionhouse.item_template='%u' AND characters.guid = auctionhouse.itemowner LIMIT %u",
2410 item_id
,uint32(count
));
2419 Field
*fields
= result
->Fetch();
2420 uint32 item_guid
= fields
[0].GetUInt32();
2421 uint32 owner
= fields
[1].GetUInt32();
2422 uint32 owner_acc
= fields
[2].GetUInt32();
2423 std::string owner_name
= fields
[3].GetCppString();
2425 char const* item_pos
= "[in auction]";
2427 PSendSysMessage(LANG_ITEMLIST_AUCTION
, item_guid
, owner_name
.c_str(), owner
, owner_acc
,item_pos
);
2428 } while (result
->NextRow());
2434 uint32 guild_count
= 0;
2435 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_entry) FROM guild_bank_item WHERE item_entry='%u'",item_id
);
2438 guild_count
= (*result
)[0].GetUInt32();
2442 result
=CharacterDatabase
.PQuery(
2444 "SELECT gi.item_guid, gi.guildid, guild.name "
2445 "FROM guild_bank_item AS gi, guild WHERE gi.item_entry='%u' AND gi.guildid = guild.guildid LIMIT %u ",
2446 item_id
,uint32(count
));
2452 Field
*fields
= result
->Fetch();
2453 uint32 item_guid
= fields
[0].GetUInt32();
2454 uint32 guild_guid
= fields
[1].GetUInt32();
2455 std::string guild_name
= fields
[2].GetCppString();
2457 char const* item_pos
= "[in guild bank]";
2459 PSendSysMessage(LANG_ITEMLIST_GUILD
,item_guid
,guild_name
.c_str(),guild_guid
,item_pos
);
2460 } while (result
->NextRow());
2462 int64 res_count
= result
->GetRowCount();
2466 if(count
> res_count
)
2472 if(inv_count
+mail_count
+auc_count
+guild_count
== 0)
2474 SendSysMessage(LANG_COMMAND_NOITEMFOUND
);
2475 SetSentErrorMessage(true);
2479 PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE
,item_id
,inv_count
+mail_count
+auc_count
+guild_count
,inv_count
,mail_count
,auc_count
,guild_count
);
2484 bool ChatHandler::HandleListObjectCommand(const char* args
)
2489 // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2490 char* cId
= extractKeyFromLink((char*)args
,"Hgameobject_entry");
2494 uint32 go_id
= atol(cId
);
2497 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID
, go_id
);
2498 SetSentErrorMessage(true);
2502 GameObjectInfo
const * gInfo
= ObjectMgr::GetGameObjectInfo(go_id
);
2505 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID
, go_id
);
2506 SetSentErrorMessage(true);
2510 char* c_count
= strtok(NULL
, " ");
2511 int count
= c_count
? atol(c_count
) : 10;
2516 QueryResult
*result
;
2518 uint32 obj_count
= 0;
2519 result
=WorldDatabase
.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'",go_id
);
2522 obj_count
= (*result
)[0].GetUInt32();
2528 Player
* pl
= m_session
->GetPlayer();
2529 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",
2530 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(),go_id
,uint32(count
));
2533 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map FROM gameobject WHERE id = '%u' LIMIT %u",
2534 go_id
,uint32(count
));
2540 Field
*fields
= result
->Fetch();
2541 uint32 guid
= fields
[0].GetUInt32();
2542 float x
= fields
[1].GetFloat();
2543 float y
= fields
[2].GetFloat();
2544 float z
= fields
[3].GetFloat();
2545 int mapid
= fields
[4].GetUInt16();
2548 PSendSysMessage(LANG_GO_LIST_CHAT
, guid
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2550 PSendSysMessage(LANG_GO_LIST_CONSOLE
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2551 } while (result
->NextRow());
2556 PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE
,go_id
,obj_count
);
2560 bool ChatHandler::HandleListCreatureCommand(const char* args
)
2565 // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
2566 char* cId
= extractKeyFromLink((char*)args
,"Hcreature_entry");
2570 uint32 cr_id
= atol(cId
);
2573 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID
, cr_id
);
2574 SetSentErrorMessage(true);
2578 CreatureInfo
const* cInfo
= ObjectMgr::GetCreatureTemplate(cr_id
);
2581 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID
, cr_id
);
2582 SetSentErrorMessage(true);
2586 char* c_count
= strtok(NULL
, " ");
2587 int count
= c_count
? atol(c_count
) : 10;
2592 QueryResult
*result
;
2594 uint32 cr_count
= 0;
2595 result
=WorldDatabase
.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'",cr_id
);
2598 cr_count
= (*result
)[0].GetUInt32();
2604 Player
* pl
= m_session
->GetPlayer();
2605 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",
2606 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(), cr_id
,uint32(count
));
2609 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '%u' LIMIT %u",
2610 cr_id
,uint32(count
));
2616 Field
*fields
= result
->Fetch();
2617 uint32 guid
= fields
[0].GetUInt32();
2618 float x
= fields
[1].GetFloat();
2619 float y
= fields
[2].GetFloat();
2620 float z
= fields
[3].GetFloat();
2621 int mapid
= fields
[4].GetUInt16();
2624 PSendSysMessage(LANG_CREATURE_LIST_CHAT
, guid
, guid
, cInfo
->Name
, x
, y
, z
, mapid
);
2626 PSendSysMessage(LANG_CREATURE_LIST_CONSOLE
, guid
, cInfo
->Name
, x
, y
, z
, mapid
);
2627 } while (result
->NextRow());
2632 PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE
,cr_id
,cr_count
);
2636 bool ChatHandler::HandleLookupItemCommand(const char* args
)
2641 std::string namepart
= args
;
2642 std::wstring wnamepart
;
2644 // converting string that we try to find to lower case
2645 if(!Utf8toWStr(namepart
,wnamepart
))
2648 wstrToLower(wnamepart
);
2652 // Search in `item_template`
2653 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
2655 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
2659 int loc_idx
= GetSessionDbLocaleIndex();
2662 ItemLocale
const *il
= sObjectMgr
.GetItemLocale(pProto
->ItemId
);
2665 if (il
->Name
.size() > loc_idx
&& !il
->Name
[loc_idx
].empty())
2667 std::string name
= il
->Name
[loc_idx
];
2669 if (Utf8FitTo(name
, wnamepart
))
2672 PSendSysMessage(LANG_ITEM_LIST_CHAT
, id
, id
, name
.c_str());
2674 PSendSysMessage(LANG_ITEM_LIST_CONSOLE
, id
, name
.c_str());
2682 std::string name
= pProto
->Name1
;
2686 if (Utf8FitTo(name
, wnamepart
))
2689 PSendSysMessage(LANG_ITEM_LIST_CHAT
, id
, id
, name
.c_str());
2691 PSendSysMessage(LANG_ITEM_LIST_CONSOLE
, id
, name
.c_str());
2697 SendSysMessage(LANG_COMMAND_NOITEMFOUND
);
2702 bool ChatHandler::HandleLookupItemSetCommand(const char* args
)
2707 std::string namepart
= args
;
2708 std::wstring wnamepart
;
2710 if(!Utf8toWStr(namepart
,wnamepart
))
2713 // converting string that we try to find to lower case
2714 wstrToLower( wnamepart
);
2716 uint32 counter
= 0; // Counter for figure out that we found smth.
2718 // Search in ItemSet.dbc
2719 for (uint32 id
= 0; id
< sItemSetStore
.GetNumRows(); id
++)
2721 ItemSetEntry
const *set
= sItemSetStore
.LookupEntry(id
);
2724 int loc
= GetSessionDbcLocale();
2725 std::string name
= set
->name
[loc
];
2729 if (!Utf8FitTo(name
, wnamepart
))
2732 for(; loc
< MAX_LOCALE
; ++loc
)
2734 if(loc
==GetSessionDbcLocale())
2737 name
= set
->name
[loc
];
2741 if (Utf8FitTo(name
, wnamepart
))
2746 if(loc
< MAX_LOCALE
)
2748 // send item set in "id - [namedlink locale]" format
2750 PSendSysMessage(LANG_ITEMSET_LIST_CHAT
,id
,id
,name
.c_str(),localeNames
[loc
]);
2752 PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE
,id
,name
.c_str(),localeNames
[loc
]);
2757 if (counter
== 0) // if counter == 0 then we found nth
2758 SendSysMessage(LANG_COMMAND_NOITEMSETFOUND
);
2762 bool ChatHandler::HandleLookupSkillCommand(const char* args
)
2767 // can be NULL in console call
2768 Player
* target
= getSelectedPlayer();
2770 std::string namepart
= args
;
2771 std::wstring wnamepart
;
2773 if(!Utf8toWStr(namepart
,wnamepart
))
2776 // converting string that we try to find to lower case
2777 wstrToLower( wnamepart
);
2779 uint32 counter
= 0; // Counter for figure out that we found smth.
2781 // Search in SkillLine.dbc
2782 for (uint32 id
= 0; id
< sSkillLineStore
.GetNumRows(); id
++)
2784 SkillLineEntry
const *skillInfo
= sSkillLineStore
.LookupEntry(id
);
2787 int loc
= GetSessionDbcLocale();
2788 std::string name
= skillInfo
->name
[loc
];
2792 if (!Utf8FitTo(name
, wnamepart
))
2795 for(; loc
< MAX_LOCALE
; ++loc
)
2797 if(loc
==GetSessionDbcLocale())
2800 name
= skillInfo
->name
[loc
];
2804 if (Utf8FitTo(name
, wnamepart
))
2809 if(loc
< MAX_LOCALE
)
2811 char valStr
[50] = "";
2812 char const* knownStr
= "";
2813 if(target
&& target
->HasSkill(id
))
2815 knownStr
= GetMangosString(LANG_KNOWN
);
2816 uint32 curValue
= target
->GetPureSkillValue(id
);
2817 uint32 maxValue
= target
->GetPureMaxSkillValue(id
);
2818 uint32 permValue
= target
->GetSkillPermBonusValue(id
);
2819 uint32 tempValue
= target
->GetSkillTempBonusValue(id
);
2821 char const* valFormat
= GetMangosString(LANG_SKILL_VALUES
);
2822 snprintf(valStr
,50,valFormat
,curValue
,maxValue
,permValue
,tempValue
);
2825 // send skill in "id - [namedlink locale]" format
2827 PSendSysMessage(LANG_SKILL_LIST_CHAT
,id
,id
,name
.c_str(),localeNames
[loc
],knownStr
,valStr
);
2829 PSendSysMessage(LANG_SKILL_LIST_CONSOLE
,id
,name
.c_str(),localeNames
[loc
],knownStr
,valStr
);
2835 if (counter
== 0) // if counter == 0 then we found nth
2836 SendSysMessage(LANG_COMMAND_NOSKILLFOUND
);
2840 bool ChatHandler::HandleLookupSpellCommand(const char* args
)
2845 // can be NULL at console call
2846 Player
* target
= getSelectedPlayer();
2848 std::string namepart
= args
;
2849 std::wstring wnamepart
;
2851 if(!Utf8toWStr(namepart
,wnamepart
))
2854 // converting string that we try to find to lower case
2855 wstrToLower( wnamepart
);
2857 uint32 counter
= 0; // Counter for figure out that we found smth.
2859 // Search in Spell.dbc
2860 for (uint32 id
= 0; id
< sSpellStore
.GetNumRows(); id
++)
2862 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(id
);
2865 int loc
= GetSessionDbcLocale();
2866 std::string name
= spellInfo
->SpellName
[loc
];
2870 if (!Utf8FitTo(name
, wnamepart
))
2873 for(; loc
< MAX_LOCALE
; ++loc
)
2875 if(loc
==GetSessionDbcLocale())
2878 name
= spellInfo
->SpellName
[loc
];
2882 if (Utf8FitTo(name
, wnamepart
))
2887 if(loc
< MAX_LOCALE
)
2889 bool known
= target
&& target
->HasSpell(id
);
2890 bool learn
= (spellInfo
->Effect
[0] == SPELL_EFFECT_LEARN_SPELL
);
2892 uint32 talentCost
= GetTalentSpellCost(id
);
2894 bool talent
= (talentCost
> 0);
2895 bool passive
= IsPassiveSpell(id
);
2896 bool active
= target
&& target
->HasAura(id
);
2898 // unit32 used to prevent interpreting uint8 as char at output
2899 // find rank of learned spell for learning spell, or talent rank
2900 uint32 rank
= talentCost
? talentCost
: sSpellMgr
.GetSpellRank(learn
? spellInfo
->EffectTriggerSpell
[0] : id
);
2902 // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
2903 std::ostringstream ss
;
2905 ss
<< id
<< " - |cffffffff|Hspell:" << id
<< "|h[" << name
;
2907 ss
<< id
<< " - " << name
;
2909 // include rank in link name
2911 ss
<< GetMangosString(LANG_SPELL_RANK
) << rank
;
2914 ss
<< " " << localeNames
[loc
] << "]|h|r";
2916 ss
<< " " << localeNames
[loc
];
2919 ss
<< GetMangosString(LANG_TALENT
);
2921 ss
<< GetMangosString(LANG_PASSIVE
);
2923 ss
<< GetMangosString(LANG_LEARN
);
2925 ss
<< GetMangosString(LANG_KNOWN
);
2927 ss
<< GetMangosString(LANG_ACTIVE
);
2929 SendSysMessage(ss
.str().c_str());
2935 if (counter
== 0) // if counter == 0 then we found nth
2936 SendSysMessage(LANG_COMMAND_NOSPELLFOUND
);
2940 bool ChatHandler::HandleLookupQuestCommand(const char* args
)
2945 // can be NULL at console call
2946 Player
* target
= getSelectedPlayer();
2948 std::string namepart
= args
;
2949 std::wstring wnamepart
;
2951 // converting string that we try to find to lower case
2952 if(!Utf8toWStr(namepart
,wnamepart
))
2955 wstrToLower(wnamepart
);
2957 uint32 counter
= 0 ;
2959 ObjectMgr::QuestMap
const& qTemplates
= sObjectMgr
.GetQuestTemplates();
2960 for (ObjectMgr::QuestMap::const_iterator iter
= qTemplates
.begin(); iter
!= qTemplates
.end(); ++iter
)
2962 Quest
* qinfo
= iter
->second
;
2964 int loc_idx
= GetSessionDbLocaleIndex();
2967 QuestLocale
const *il
= sObjectMgr
.GetQuestLocale(qinfo
->GetQuestId());
2970 if (il
->Title
.size() > loc_idx
&& !il
->Title
[loc_idx
].empty())
2972 std::string title
= il
->Title
[loc_idx
];
2974 if (Utf8FitTo(title
, wnamepart
))
2976 char const* statusStr
= "";
2980 QuestStatus status
= target
->GetQuestStatus(qinfo
->GetQuestId());
2982 if(status
== QUEST_STATUS_COMPLETE
)
2984 if(target
->GetQuestRewardStatus(qinfo
->GetQuestId()))
2985 statusStr
= GetMangosString(LANG_COMMAND_QUEST_REWARDED
);
2987 statusStr
= GetMangosString(LANG_COMMAND_QUEST_COMPLETE
);
2989 else if(status
== QUEST_STATUS_INCOMPLETE
)
2990 statusStr
= GetMangosString(LANG_COMMAND_QUEST_ACTIVE
);
2994 PSendSysMessage(LANG_QUEST_LIST_CHAT
,qinfo
->GetQuestId(),qinfo
->GetQuestId(),qinfo
->GetQuestLevel(),title
.c_str(),statusStr
);
2996 PSendSysMessage(LANG_QUEST_LIST_CONSOLE
,qinfo
->GetQuestId(),title
.c_str(),statusStr
);
3004 std::string title
= qinfo
->GetTitle();
3008 if (Utf8FitTo(title
, wnamepart
))
3010 char const* statusStr
= "";
3014 QuestStatus status
= target
->GetQuestStatus(qinfo
->GetQuestId());
3016 if(status
== QUEST_STATUS_COMPLETE
)
3018 if(target
->GetQuestRewardStatus(qinfo
->GetQuestId()))
3019 statusStr
= GetMangosString(LANG_COMMAND_QUEST_REWARDED
);
3021 statusStr
= GetMangosString(LANG_COMMAND_QUEST_COMPLETE
);
3023 else if(status
== QUEST_STATUS_INCOMPLETE
)
3024 statusStr
= GetMangosString(LANG_COMMAND_QUEST_ACTIVE
);
3028 PSendSysMessage(LANG_QUEST_LIST_CHAT
,qinfo
->GetQuestId(),qinfo
->GetQuestId(),qinfo
->GetQuestLevel(),title
.c_str(),statusStr
);
3030 PSendSysMessage(LANG_QUEST_LIST_CONSOLE
,qinfo
->GetQuestId(),title
.c_str(),statusStr
);
3037 SendSysMessage(LANG_COMMAND_NOQUESTFOUND
);
3042 bool ChatHandler::HandleLookupCreatureCommand(const char* args
)
3047 std::string namepart
= args
;
3048 std::wstring wnamepart
;
3050 // converting string that we try to find to lower case
3051 if (!Utf8toWStr (namepart
,wnamepart
))
3054 wstrToLower (wnamepart
);
3058 for (uint32 id
= 0; id
< sCreatureStorage
.MaxEntry
; ++id
)
3060 CreatureInfo
const* cInfo
= sCreatureStorage
.LookupEntry
<CreatureInfo
> (id
);
3064 int loc_idx
= GetSessionDbLocaleIndex();
3067 CreatureLocale
const *cl
= sObjectMgr
.GetCreatureLocale (id
);
3070 if (cl
->Name
.size() > loc_idx
&& !cl
->Name
[loc_idx
].empty ())
3072 std::string name
= cl
->Name
[loc_idx
];
3074 if (Utf8FitTo (name
, wnamepart
))
3077 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str ());
3079 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE
, id
, name
.c_str ());
3087 std::string name
= cInfo
->Name
;
3091 if (Utf8FitTo(name
, wnamepart
))
3094 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str ());
3096 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE
, id
, name
.c_str ());
3102 SendSysMessage (LANG_COMMAND_NOCREATUREFOUND
);
3107 bool ChatHandler::HandleLookupObjectCommand(const char* args
)
3112 std::string namepart
= args
;
3113 std::wstring wnamepart
;
3115 // converting string that we try to find to lower case
3116 if(!Utf8toWStr(namepart
,wnamepart
))
3119 wstrToLower(wnamepart
);
3123 for (uint32 id
= 0; id
< sGOStorage
.MaxEntry
; id
++ )
3125 GameObjectInfo
const* gInfo
= sGOStorage
.LookupEntry
<GameObjectInfo
>(id
);
3129 int loc_idx
= GetSessionDbLocaleIndex();
3132 GameObjectLocale
const *gl
= sObjectMgr
.GetGameObjectLocale(id
);
3135 if (gl
->Name
.size() > loc_idx
&& !gl
->Name
[loc_idx
].empty())
3137 std::string name
= gl
->Name
[loc_idx
];
3139 if (Utf8FitTo(name
, wnamepart
))
3142 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT
, id
, id
, name
.c_str());
3144 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE
, id
, name
.c_str());
3152 std::string name
= gInfo
->name
;
3156 if(Utf8FitTo(name
, wnamepart
))
3159 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT
, id
, id
, name
.c_str());
3161 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE
, id
, name
.c_str());
3167 SendSysMessage(LANG_COMMAND_NOGAMEOBJECTFOUND
);
3172 bool ChatHandler::HandleLookupTaxiNodeCommand(const char * args
)
3177 std::string namepart
= args
;
3178 std::wstring wnamepart
;
3180 if(!Utf8toWStr(namepart
,wnamepart
))
3183 // converting string that we try to find to lower case
3184 wstrToLower( wnamepart
);
3186 uint32 counter
= 0; // Counter for figure out that we found smth.
3188 // Search in TaxiNodes.dbc
3189 for (uint32 id
= 0; id
< sTaxiNodesStore
.GetNumRows(); id
++)
3191 TaxiNodesEntry
const *nodeEntry
= sTaxiNodesStore
.LookupEntry(id
);
3194 int loc
= GetSessionDbcLocale();
3195 std::string name
= nodeEntry
->name
[loc
];
3199 if (!Utf8FitTo(name
, wnamepart
))
3202 for(; loc
< MAX_LOCALE
; ++loc
)
3204 if(loc
==GetSessionDbcLocale())
3207 name
= nodeEntry
->name
[loc
];
3211 if (Utf8FitTo(name
, wnamepart
))
3216 if(loc
< MAX_LOCALE
)
3218 // send taxinode in "id - [name] (Map:m X:x Y:y Z:z)" format
3220 PSendSysMessage (LANG_TAXINODE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str(),localeNames
[loc
],
3221 nodeEntry
->map_id
,nodeEntry
->x
,nodeEntry
->y
,nodeEntry
->z
);
3223 PSendSysMessage (LANG_TAXINODE_ENTRY_LIST_CONSOLE
, id
, name
.c_str(), localeNames
[loc
],
3224 nodeEntry
->map_id
,nodeEntry
->x
,nodeEntry
->y
,nodeEntry
->z
);
3229 if (counter
== 0) // if counter == 0 then we found nth
3230 SendSysMessage(LANG_COMMAND_NOTAXINODEFOUND
);
3234 /** \brief GM command level 3 - Create a guild.
3236 * This command allows a GM (level 3) to create a guild.
3238 * The "args" parameter contains the name of the guild leader
3239 * and then the name of the guild.
3242 bool ChatHandler::HandleGuildCreateCommand(const char* args
)
3247 // if not guild name only (in "") then player name
3249 if(!extractPlayerTarget(*args
!='"' ? (char*)args
: NULL
, &target
))
3252 char* tailStr
= *args
!='"' ? strtok(NULL
, "") : (char*)args
;
3256 char* guildStr
= extractQuotedArg(tailStr
);
3260 std::string guildname
= guildStr
;
3262 if (target
->GetGuildId())
3264 SendSysMessage (LANG_PLAYER_IN_GUILD
);
3268 Guild
*guild
= new Guild
;
3269 if (!guild
->Create (target
,guildname
))
3272 SendSysMessage (LANG_GUILD_NOT_CREATED
);
3273 SetSentErrorMessage (true);
3277 sObjectMgr
.AddGuild (guild
);
3281 bool ChatHandler::HandleGuildInviteCommand(const char *args
)
3286 // if not guild name only (in "") then player name
3288 if(!extractPlayerTarget(*args
!='"' ? (char*)args
: NULL
, NULL
, &target_guid
))
3291 char* tailStr
= *args
!='"' ? strtok(NULL
, "") : (char*)args
;
3295 char* guildStr
= extractQuotedArg(tailStr
);
3299 std::string glName
= guildStr
;
3300 Guild
* targetGuild
= sObjectMgr
.GetGuildByName (glName
);
3304 // player's guild membership checked in AddMember before add
3305 if (!targetGuild
->AddMember (target_guid
,targetGuild
->GetLowestRank ()))
3311 bool ChatHandler::HandleGuildUninviteCommand(const char *args
)
3315 if(!extractPlayerTarget((char*)args
,&target
,&target_guid
))
3318 uint32 glId
= target
? target
->GetGuildId () : Player::GetGuildIdFromDB (target_guid
);
3322 Guild
* targetGuild
= sObjectMgr
.GetGuildById (glId
);
3326 targetGuild
->DelMember (target_guid
);
3330 bool ChatHandler::HandleGuildRankCommand(const char *args
)
3334 extractOptFirstArg((char*)args
,&nameStr
,&rankStr
);
3340 std::string target_name
;
3341 if(!extractPlayerTarget(nameStr
,&target
,&target_guid
,&target_name
))
3344 uint32 glId
= target
? target
->GetGuildId () : Player::GetGuildIdFromDB (target_guid
);
3348 Guild
* targetGuild
= sObjectMgr
.GetGuildById (glId
);
3352 uint32 newrank
= uint32 (atoi (rankStr
));
3353 if (newrank
> targetGuild
->GetLowestRank ())
3356 targetGuild
->ChangeRank (target_guid
,newrank
);
3360 bool ChatHandler::HandleGuildDeleteCommand(const char* args
)
3365 char* guildStr
= extractQuotedArg((char*)args
);
3369 std::string gld
= guildStr
;
3371 Guild
* targetGuild
= sObjectMgr
.GetGuildByName (gld
);
3375 targetGuild
->Disband ();
3380 bool ChatHandler::HandleGetDistanceCommand(const char* args
)
3382 WorldObject
* obj
= NULL
;
3386 uint64 guid
= extractGuidFromLink((char*)args
);
3388 obj
= (WorldObject
*)ObjectAccessor::GetObjectByTypeMask(*m_session
->GetPlayer(),guid
,TYPEMASK_UNIT
|TYPEMASK_GAMEOBJECT
);
3392 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3393 SetSentErrorMessage(true);
3399 obj
= getSelectedUnit();
3403 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3404 SetSentErrorMessage(true);
3409 PSendSysMessage(LANG_DISTANCE
, m_session
->GetPlayer()->GetDistance(obj
),m_session
->GetPlayer()->GetDistance2d(obj
));
3414 bool ChatHandler::HandleDieCommand(const char* /*args*/)
3416 Unit
* target
= getSelectedUnit();
3418 if(!target
|| !m_session
->GetPlayer()->GetSelection())
3420 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3421 SetSentErrorMessage(true);
3425 if(target
->GetTypeId()==TYPEID_PLAYER
)
3427 if(HasLowerSecurity((Player
*)target
,0,false))
3431 if( target
->isAlive() )
3433 m_session
->GetPlayer()->DealDamage(target
, target
->GetHealth(), NULL
, DIRECT_DAMAGE
, SPELL_SCHOOL_MASK_NORMAL
, NULL
, false);
3439 bool ChatHandler::HandleDamageCommand(const char * args
)
3444 Unit
* target
= getSelectedUnit();
3446 if (!target
|| !m_session
->GetPlayer()->GetSelection())
3448 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3449 SetSentErrorMessage(true);
3453 if (!target
->isAlive())
3456 char* damageStr
= strtok((char*)args
, " ");
3460 int32 damage_int
= atoi((char*)damageStr
);
3464 uint32 damage
= damage_int
;
3466 char* schoolStr
= strtok((char*)NULL
, " ");
3468 // flat melee damage without resistence/etc reduction
3471 m_session
->GetPlayer()->DealDamage(target
, damage
, NULL
, DIRECT_DAMAGE
, SPELL_SCHOOL_MASK_NORMAL
, NULL
, false);
3472 if (target
!= m_session
->GetPlayer())
3473 m_session
->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2
, target
, 1, SPELL_SCHOOL_MASK_NORMAL
, damage
, 0, 0, VICTIMSTATE_NORMAL
, 0);
3477 uint32 school
= schoolStr
? atoi((char*)schoolStr
) : SPELL_SCHOOL_NORMAL
;
3478 if(school
>= MAX_SPELL_SCHOOL
)
3481 SpellSchoolMask schoolmask
= SpellSchoolMask(1 << school
);
3483 if ( schoolmask
& SPELL_SCHOOL_MASK_NORMAL
)
3484 damage
= m_session
->GetPlayer()->CalcArmorReducedDamage(target
, damage
);
3486 char* spellStr
= strtok((char*)NULL
, " ");
3488 // melee damage by specific school
3494 m_session
->GetPlayer()->CalcAbsorbResist(target
,schoolmask
, SPELL_DIRECT_DAMAGE
, damage
, &absorb
, &resist
);
3496 if (damage
<= absorb
+ resist
)
3499 damage
-= absorb
+ resist
;
3501 m_session
->GetPlayer()->DealDamageMods(target
,damage
,&absorb
);
3502 m_session
->GetPlayer()->DealDamage(target
, damage
, NULL
, DIRECT_DAMAGE
, schoolmask
, NULL
, false);
3503 m_session
->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2
, target
, 1, schoolmask
, damage
, absorb
, resist
, VICTIMSTATE_NORMAL
, 0);
3509 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3510 uint32 spellid
= extractSpellIdFromLink((char*)args
);
3511 if (!spellid
|| !sSpellStore
.LookupEntry(spellid
))
3514 m_session
->GetPlayer()->SpellNonMeleeDamageLog(target
, spellid
, damage
);
3518 bool ChatHandler::HandleModifyArenaCommand(const char * args
)
3523 Player
*target
= getSelectedPlayer();
3526 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3527 SetSentErrorMessage(true);
3531 int32 amount
= (uint32
)atoi(args
);
3533 target
->ModifyArenaPoints(amount
);
3535 PSendSysMessage(LANG_COMMAND_MODIFY_ARENA
, GetNameLink(target
).c_str(), target
->GetArenaPoints());
3540 bool ChatHandler::HandleReviveCommand(const char* args
)
3544 if(!extractPlayerTarget((char*)args
,&target
,&target_guid
))
3549 target
->ResurrectPlayer(0.5f
);
3550 target
->SpawnCorpseBones();
3553 // will resurrected at login without corpse
3554 sObjectAccessor
.ConvertCorpseForPlayer(target_guid
);
3559 bool ChatHandler::HandleAuraCommand(const char* args
)
3561 Unit
*target
= getSelectedUnit();
3564 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3565 SetSentErrorMessage(true);
3569 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3570 uint32 spellID
= extractSpellIdFromLink((char*)args
);
3572 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry( spellID
);
3575 for(uint32 i
= 0;i
<3;++i
)
3577 uint8 eff
= spellInfo
->Effect
[i
];
3578 if (eff
>=TOTAL_SPELL_EFFECTS
)
3580 if( IsAreaAuraEffect(eff
) ||
3581 eff
== SPELL_EFFECT_APPLY_AURA
||
3582 eff
== SPELL_EFFECT_PERSISTENT_AREA_AURA
)
3584 Aura
*Aur
= CreateAura(spellInfo
, i
, NULL
, target
);
3585 target
->AddAura(Aur
);
3593 bool ChatHandler::HandleUnAuraCommand(const char* args
)
3595 Unit
*target
= getSelectedUnit();
3598 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3599 SetSentErrorMessage(true);
3603 std::string argstr
= args
;
3604 if (argstr
== "all")
3606 target
->RemoveAllAuras();
3610 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3611 uint32 spellID
= extractSpellIdFromLink((char*)args
);
3615 target
->RemoveAurasDueToSpell(spellID
);
3620 bool ChatHandler::HandleLinkGraveCommand(const char* args
)
3625 char* px
= strtok((char*)args
, " ");
3629 uint32 g_id
= (uint32
)atoi(px
);
3633 char* px2
= strtok(NULL
, " ");
3637 else if (strncmp(px2
,"horde",6)==0)
3639 else if (strncmp(px2
,"alliance",9)==0)
3644 WorldSafeLocsEntry
const* graveyard
= sWorldSafeLocsStore
.LookupEntry(g_id
);
3648 PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST
, g_id
);
3649 SetSentErrorMessage(true);
3653 Player
* player
= m_session
->GetPlayer();
3655 uint32 zoneId
= player
->GetZoneId();
3657 AreaTableEntry
const *areaEntry
= GetAreaEntryByAreaID(zoneId
);
3658 if(!areaEntry
|| areaEntry
->zone
!=0 )
3660 PSendSysMessage(LANG_COMMAND_GRAVEYARDWRONGZONE
, g_id
,zoneId
);
3661 SetSentErrorMessage(true);
3665 if(sObjectMgr
.AddGraveYardLink(g_id
,zoneId
,g_team
))
3666 PSendSysMessage(LANG_COMMAND_GRAVEYARDLINKED
, g_id
,zoneId
);
3668 PSendSysMessage(LANG_COMMAND_GRAVEYARDALRLINKED
, g_id
,zoneId
);
3673 bool ChatHandler::HandleNearGraveCommand(const char* args
)
3677 size_t argslen
= strlen(args
);
3681 else if (strncmp((char*)args
,"horde",argslen
)==0)
3683 else if (strncmp((char*)args
,"alliance",argslen
)==0)
3688 Player
* player
= m_session
->GetPlayer();
3689 uint32 zone_id
= player
->GetZoneId();
3691 WorldSafeLocsEntry
const* graveyard
= sObjectMgr
.GetClosestGraveYard(
3692 player
->GetPositionX(), player
->GetPositionY(), player
->GetPositionZ(),player
->GetMapId(),g_team
);
3696 uint32 g_id
= graveyard
->ID
;
3698 GraveYardData
const* data
= sObjectMgr
.FindGraveYardData(g_id
,zone_id
);
3701 PSendSysMessage(LANG_COMMAND_GRAVEYARDERROR
,g_id
);
3702 SetSentErrorMessage(true);
3706 g_team
= data
->team
;
3708 std::string team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_NOTEAM
);
3711 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ANY
);
3712 else if(g_team
== HORDE
)
3713 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE
);
3714 else if(g_team
== ALLIANCE
)
3715 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE
);
3717 PSendSysMessage(LANG_COMMAND_GRAVEYARDNEAREST
, g_id
,team_name
.c_str(),zone_id
);
3721 std::string team_name
;
3724 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ANY
);
3725 else if(g_team
== HORDE
)
3726 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE
);
3727 else if(g_team
== ALLIANCE
)
3728 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE
);
3730 if(g_team
== ~uint32(0))
3731 PSendSysMessage(LANG_COMMAND_ZONENOGRAVEYARDS
, zone_id
);
3733 PSendSysMessage(LANG_COMMAND_ZONENOGRAFACTION
, zone_id
,team_name
.c_str());
3739 //-----------------------Npc Commands-----------------------
3740 bool ChatHandler::HandleNpcAllowMovementCommand(const char* /*args*/)
3742 if(sWorld
.getAllowMovement())
3744 sWorld
.SetAllowMovement(false);
3745 SendSysMessage(LANG_CREATURE_MOVE_DISABLED
);
3749 sWorld
.SetAllowMovement(true);
3750 SendSysMessage(LANG_CREATURE_MOVE_ENABLED
);
3755 bool ChatHandler::HandleNpcChangeEntryCommand(const char *args
)
3760 uint32 newEntryNum
= atoi(args
);
3764 Unit
* unit
= getSelectedUnit();
3765 if(!unit
|| unit
->GetTypeId() != TYPEID_UNIT
)
3767 SendSysMessage(LANG_SELECT_CREATURE
);
3768 SetSentErrorMessage(true);
3771 Creature
* creature
= (Creature
*)unit
;
3772 if(creature
->UpdateEntry(newEntryNum
))
3773 SendSysMessage(LANG_DONE
);
3775 SendSysMessage(LANG_ERROR
);
3779 bool ChatHandler::HandleNpcInfoCommand(const char* /*args*/)
3781 Creature
* target
= getSelectedCreature();
3785 SendSysMessage(LANG_SELECT_CREATURE
);
3786 SetSentErrorMessage(true);
3790 uint32 faction
= target
->getFaction();
3791 uint32 npcflags
= target
->GetUInt32Value(UNIT_NPC_FLAGS
);
3792 uint32 displayid
= target
->GetDisplayId();
3793 uint32 nativeid
= target
->GetNativeDisplayId();
3794 uint32 Entry
= target
->GetEntry();
3795 CreatureInfo
const* cInfo
= target
->GetCreatureInfo();
3797 int32 curRespawnDelay
= target
->GetRespawnTimeEx()-time(NULL
);
3798 if(curRespawnDelay
< 0)
3799 curRespawnDelay
= 0;
3800 std::string curRespawnDelayStr
= secsToTimeString(curRespawnDelay
,true);
3801 std::string defRespawnDelayStr
= secsToTimeString(target
->GetRespawnDelay(),true);
3803 PSendSysMessage(LANG_NPCINFO_CHAR
, target
->GetDBTableGUIDLow(), faction
, npcflags
, Entry
, displayid
, nativeid
);
3804 PSendSysMessage(LANG_NPCINFO_LEVEL
, target
->getLevel());
3805 PSendSysMessage(LANG_NPCINFO_HEALTH
,target
->GetCreateHealth(), target
->GetMaxHealth(), target
->GetHealth());
3806 PSendSysMessage(LANG_NPCINFO_FLAGS
, target
->GetUInt32Value(UNIT_FIELD_FLAGS
), target
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
), target
->getFaction());
3807 PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES
, defRespawnDelayStr
.c_str(),curRespawnDelayStr
.c_str());
3808 PSendSysMessage(LANG_NPCINFO_LOOT
, cInfo
->lootid
,cInfo
->pickpocketLootId
,cInfo
->SkinLootId
);
3809 PSendSysMessage(LANG_NPCINFO_DUNGEON_ID
, target
->GetInstanceId());
3810 PSendSysMessage(LANG_NPCINFO_POSITION
,float(target
->GetPositionX()), float(target
->GetPositionY()), float(target
->GetPositionZ()));
3812 if ((npcflags
& UNIT_NPC_FLAG_VENDOR
) )
3814 SendSysMessage(LANG_NPCINFO_VENDOR
);
3816 if ((npcflags
& UNIT_NPC_FLAG_TRAINER
) )
3818 SendSysMessage(LANG_NPCINFO_TRAINER
);
3825 bool ChatHandler::HandleNpcPlayEmoteCommand(const char* args
)
3827 uint32 emote
= atoi((char*)args
);
3829 Creature
* target
= getSelectedCreature();
3832 SendSysMessage(LANG_SELECT_CREATURE
);
3833 SetSentErrorMessage(true);
3837 target
->SetUInt32Value(UNIT_NPC_EMOTESTATE
,emote
);
3842 //TODO: NpcCommands that needs to be fixed :
3844 bool ChatHandler::HandleNpcAddWeaponCommand(const char* /*args*/)
3849 uint64 guid = m_session->GetPlayer()->GetSelection();
3852 SendSysMessage(LANG_NO_SELECTION);
3856 Creature *pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
3860 SendSysMessage(LANG_SELECT_CREATURE);
3864 char* pSlotID = strtok((char*)args, " ");
3868 char* pItemID = strtok(NULL, " ");
3872 uint32 ItemID = atoi(pItemID);
3873 uint32 SlotID = atoi(pSlotID);
3875 ItemPrototype* tmpItem = ObjectMgr::GetItemPrototype(ItemID);
3883 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID);
3887 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID);
3891 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID);
3895 PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST,SlotID);
3901 PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT,ItemID,tmpItem->Name1,SlotID);
3905 PSendSysMessage(LANG_ITEM_NOT_FOUND,ItemID);
3911 //----------------------------------------------------------
3913 bool ChatHandler::HandleExploreCheatCommand(const char* args
)
3918 int flag
= atoi((char*)args
);
3920 Player
*chr
= getSelectedPlayer();
3923 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3924 SetSentErrorMessage(true);
3930 PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL
, GetNameLink(chr
).c_str());
3931 if (needReportToTarget(chr
))
3932 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_EXPLORE_SET_ALL
,GetNameLink().c_str());
3936 PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING
, GetNameLink(chr
).c_str());
3937 if (needReportToTarget(chr
))
3938 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_EXPLORE_SET_NOTHING
,GetNameLink().c_str());
3941 for (uint8 i
=0; i
<128; ++i
)
3945 m_session
->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1
+i
,0xFFFFFFFF);
3949 m_session
->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1
+i
,0);
3956 bool ChatHandler::HandleHoverCommand(const char* args
)
3958 char* px
= strtok((char*)args
, " ");
3965 m_session
->GetPlayer()->SetHover(flag
);
3968 SendSysMessage(LANG_HOVER_ENABLED
);
3970 SendSysMessage(LANG_HOVER_DISABLED
);
3975 void ChatHandler::HandleCharacterLevel(Player
* player
, uint64 player_guid
, uint32 oldlevel
, uint32 newlevel
)
3979 player
->GiveLevel(newlevel
);
3980 player
->InitTalentForLevel();
3981 player
->SetUInt32Value(PLAYER_XP
,0);
3983 if(needReportToTarget(player
))
3985 if(oldlevel
== newlevel
)
3986 ChatHandler(player
).PSendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET
,GetNameLink().c_str());
3987 else if(oldlevel
< newlevel
)
3988 ChatHandler(player
).PSendSysMessage(LANG_YOURS_LEVEL_UP
,GetNameLink().c_str(),newlevel
);
3989 else // if(oldlevel > newlevel)
3990 ChatHandler(player
).PSendSysMessage(LANG_YOURS_LEVEL_DOWN
,GetNameLink().c_str(),newlevel
);
3995 // update level and XP at level, all other will be updated at loading
3996 CharacterDatabase
.PExecute("UPDATE characters SET level = '%u', xp = 0 WHERE guid = '%u'", newlevel
, GUID_LOPART(player_guid
));
4000 bool ChatHandler::HandleCharacterLevelCommand(const char* args
)
4004 extractOptFirstArg((char*)args
,&nameStr
,&levelStr
);
4008 // exception opt second arg: .character level $name
4009 if(isalpha(levelStr
[0]))
4012 levelStr
= NULL
; // current level will used
4017 std::string target_name
;
4018 if(!extractPlayerTarget(nameStr
,&target
,&target_guid
,&target_name
))
4021 int32 oldlevel
= target
? target
->getLevel() : Player::GetLevelFromDB(target_guid
);
4022 int32 newlevel
= levelStr
? atoi(levelStr
) : oldlevel
;
4025 return false; // invalid level
4027 if(newlevel
> STRONG_MAX_LEVEL
) // hardcoded maximum level
4028 newlevel
= STRONG_MAX_LEVEL
;
4030 HandleCharacterLevel(target
,target_guid
,oldlevel
,newlevel
);
4032 if(!m_session
|| m_session
->GetPlayer() != target
) // including player==NULL
4034 std::string nameLink
= playerLink(target_name
);
4035 PSendSysMessage(LANG_YOU_CHANGE_LVL
,nameLink
.c_str(),newlevel
);
4041 bool ChatHandler::HandleLevelUpCommand(const char* args
)
4045 extractOptFirstArg((char*)args
,&nameStr
,&levelStr
);
4047 // exception opt second arg: .character level $name
4048 if(levelStr
&& isalpha(levelStr
[0]))
4051 levelStr
= NULL
; // current level will used
4056 std::string target_name
;
4057 if(!extractPlayerTarget(nameStr
,&target
,&target_guid
,&target_name
))
4060 int32 oldlevel
= target
? target
->getLevel() : Player::GetLevelFromDB(target_guid
);
4061 int32 addlevel
= levelStr
? atoi(levelStr
) : 1;
4062 int32 newlevel
= oldlevel
+ addlevel
;
4067 if(newlevel
> STRONG_MAX_LEVEL
) // hardcoded maximum level
4068 newlevel
= STRONG_MAX_LEVEL
;
4070 HandleCharacterLevel(target
,target_guid
,oldlevel
,newlevel
);
4072 if(!m_session
|| m_session
->GetPlayer() != target
) // including chr==NULL
4074 std::string nameLink
= playerLink(target_name
);
4075 PSendSysMessage(LANG_YOU_CHANGE_LVL
,nameLink
.c_str(),newlevel
);
4081 bool ChatHandler::HandleShowAreaCommand(const char* args
)
4086 Player
*chr
= getSelectedPlayer();
4089 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4090 SetSentErrorMessage(true);
4094 int area
= GetAreaFlagByAreaID(atoi((char*)args
));
4095 int offset
= area
/ 32;
4096 uint32 val
= (uint32
)(1 << (area
% 32));
4098 if(area
<0 || offset
>= 128)
4100 SendSysMessage(LANG_BAD_VALUE
);
4101 SetSentErrorMessage(true);
4105 uint32 currFields
= chr
->GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
4106 chr
->SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
| val
));
4108 SendSysMessage(LANG_EXPLORE_AREA
);
4112 bool ChatHandler::HandleHideAreaCommand(const char* args
)
4117 Player
*chr
= getSelectedPlayer();
4120 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4121 SetSentErrorMessage(true);
4125 int area
= GetAreaFlagByAreaID(atoi((char*)args
));
4126 int offset
= area
/ 32;
4127 uint32 val
= (uint32
)(1 << (area
% 32));
4129 if(area
<0 || offset
>= 128)
4131 SendSysMessage(LANG_BAD_VALUE
);
4132 SetSentErrorMessage(true);
4136 uint32 currFields
= chr
->GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
4137 chr
->SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
^ val
));
4139 SendSysMessage(LANG_UNEXPLORE_AREA
);
4143 bool ChatHandler::HandleBankCommand(const char* /*args*/)
4145 m_session
->SendShowBank( m_session
->GetPlayer()->GetGUID() );
4150 bool ChatHandler::HandleChangeWeather(const char* args
)
4156 if (!sWorld
.getConfig(CONFIG_WEATHER
))
4158 SendSysMessage(LANG_WEATHER_DISABLED
);
4159 SetSentErrorMessage(true);
4163 //*Change the weather of a cell
4164 char* px
= strtok((char*)args
, " ");
4165 char* py
= strtok(NULL
, " ");
4170 uint32 type
= (uint32
)atoi(px
); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
4171 float grade
= (float)atof(py
); //0 to 1, sending -1 is instand good weather
4173 Player
*player
= m_session
->GetPlayer();
4174 uint32 zoneid
= player
->GetZoneId();
4176 Weather
* wth
= sWorld
.FindWeather(zoneid
);
4179 wth
= sWorld
.AddWeather(zoneid
);
4182 SendSysMessage(LANG_NO_WEATHER
);
4183 SetSentErrorMessage(true);
4187 wth
->SetWeather(WeatherType(type
), grade
);
4192 bool ChatHandler::HandleTeleAddCommand(const char * args
)
4197 Player
*player
=m_session
->GetPlayer();
4201 std::string name
= args
;
4203 if(sObjectMgr
.GetGameTele(name
))
4205 SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST
);
4206 SetSentErrorMessage(true);
4211 tele
.position_x
= player
->GetPositionX();
4212 tele
.position_y
= player
->GetPositionY();
4213 tele
.position_z
= player
->GetPositionZ();
4214 tele
.orientation
= player
->GetOrientation();
4215 tele
.mapId
= player
->GetMapId();
4218 if(sObjectMgr
.AddGameTele(tele
))
4220 SendSysMessage(LANG_COMMAND_TP_ADDED
);
4224 SendSysMessage(LANG_COMMAND_TP_ADDEDERR
);
4225 SetSentErrorMessage(true);
4232 bool ChatHandler::HandleTeleDelCommand(const char * args
)
4237 std::string name
= args
;
4239 if(!sObjectMgr
.DeleteGameTele(name
))
4241 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
4242 SetSentErrorMessage(true);
4246 SendSysMessage(LANG_COMMAND_TP_DELETED
);
4250 bool ChatHandler::HandleListAurasCommand (const char * /*args*/)
4252 Unit
*unit
= getSelectedUnit();
4255 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4256 SetSentErrorMessage(true);
4260 char const* talentStr
= GetMangosString(LANG_TALENT
);
4261 char const* passiveStr
= GetMangosString(LANG_PASSIVE
);
4263 Unit::AuraMap
const& uAuras
= unit
->GetAuras();
4264 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS
, uAuras
.size());
4265 for (Unit::AuraMap::const_iterator itr
= uAuras
.begin(); itr
!= uAuras
.end(); ++itr
)
4267 bool talent
= GetTalentSpellCost(itr
->second
->GetId()) > 0;
4269 char const* name
= itr
->second
->GetSpellProto()->SpellName
[GetSessionDbcLocale()];
4273 std::ostringstream ss_name
;
4274 ss_name
<< "|cffffffff|Hspell:" << itr
->second
->GetId() << "|h[" << name
<< "]|h|r";
4276 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL
, itr
->second
->GetId(), itr
->second
->GetEffIndex(),
4277 itr
->second
->GetModifier()->m_auraname
, itr
->second
->GetAuraDuration(), itr
->second
->GetAuraMaxDuration(),
4278 ss_name
.str().c_str(),
4279 (itr
->second
->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4280 IS_PLAYER_GUID(itr
->second
->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr
->second
->GetCasterGUID()));
4284 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL
, itr
->second
->GetId(), itr
->second
->GetEffIndex(),
4285 itr
->second
->GetModifier()->m_auraname
, itr
->second
->GetAuraDuration(), itr
->second
->GetAuraMaxDuration(),
4287 (itr
->second
->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4288 IS_PLAYER_GUID(itr
->second
->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr
->second
->GetCasterGUID()));
4291 for (int i
= 0; i
< TOTAL_AURAS
; ++i
)
4293 Unit::AuraList
const& uAuraList
= unit
->GetAurasByType(AuraType(i
));
4294 if (uAuraList
.empty()) continue;
4295 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE
, uAuraList
.size(), i
);
4296 for (Unit::AuraList::const_iterator itr
= uAuraList
.begin(); itr
!= uAuraList
.end(); ++itr
)
4298 bool talent
= GetTalentSpellCost((*itr
)->GetId()) > 0;
4300 char const* name
= (*itr
)->GetSpellProto()->SpellName
[GetSessionDbcLocale()];
4304 std::ostringstream ss_name
;
4305 ss_name
<< "|cffffffff|Hspell:" << (*itr
)->GetId() << "|h[" << name
<< "]|h|r";
4307 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE
, (*itr
)->GetId(), (*itr
)->GetEffIndex(),
4308 ss_name
.str().c_str(),((*itr
)->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4309 IS_PLAYER_GUID((*itr
)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr
)->GetCasterGUID()));
4313 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE
, (*itr
)->GetId(), (*itr
)->GetEffIndex(),
4314 name
,((*itr
)->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4315 IS_PLAYER_GUID((*itr
)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr
)->GetCasterGUID()));
4322 bool ChatHandler::HandleResetAchievementsCommand (const char * args
)
4326 if (!extractPlayerTarget((char*)args
,&target
,&target_guid
))
4330 target
->GetAchievementMgr().Reset();
4332 AchievementMgr::DeleteFromDB(GUID_LOPART(target_guid
));
4337 bool ChatHandler::HandleResetHonorCommand (const char * args
)
4340 if (!extractPlayerTarget((char*)args
,&target
))
4343 target
->SetUInt32Value(PLAYER_FIELD_KILLS
, 0);
4344 target
->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS
, 0);
4345 target
->SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY
, 0);
4346 target
->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION
, 0);
4347 target
->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION
, 0);
4348 target
->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_EARN_HONORABLE_KILL
);
4353 static bool HandleResetStatsOrLevelHelper(Player
* player
)
4355 ChrClassesEntry
const* cEntry
= sChrClassesStore
.LookupEntry(player
->getClass());
4358 sLog
.outError("Class %u not found in DBC (Wrong DBC files?)",player
->getClass());
4362 uint8 powertype
= cEntry
->powerType
;
4364 // reset m_form if no aura
4365 if(!player
->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT
))
4366 player
->m_form
= FORM_NONE
;
4368 player
->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS
, DEFAULT_WORLD_OBJECT_SIZE
);
4369 player
->SetFloatValue(UNIT_FIELD_COMBATREACH
, 1.5f
);
4371 player
->setFactionForRace(player
->getRace());
4373 player
->SetUInt32Value(UNIT_FIELD_BYTES_0
, ( ( player
->getRace() ) | ( player
->getClass() << 8 ) | ( player
->getGender() << 16 ) | ( powertype
<< 24 ) ) );
4375 // reset only if player not in some form;
4376 if(player
->m_form
==FORM_NONE
)
4377 player
->InitDisplayIds();
4379 player
->SetByteValue(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_PVP
);
4380 player
->SetByteValue(UNIT_FIELD_BYTES_2
, 3, player
->m_form
);
4382 player
->SetUInt32Value(UNIT_FIELD_FLAGS
, UNIT_FLAG_PVP_ATTACKABLE
);
4384 //-1 is default value
4385 player
->SetInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX
, -1);
4387 //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000 );
4391 bool ChatHandler::HandleResetLevelCommand(const char * args
)
4394 if(!extractPlayerTarget((char*)args
,&target
))
4397 if(!HandleResetStatsOrLevelHelper(target
))
4400 // set starting level
4401 uint32 start_level
= target
->getClass() != CLASS_DEATH_KNIGHT
4402 ? sWorld
.getConfig(CONFIG_START_PLAYER_LEVEL
)
4403 : sWorld
.getConfig(CONFIG_START_HEROIC_PLAYER_LEVEL
);
4405 target
->_ApplyAllLevelScaleItemMods(false);
4407 target
->SetLevel(start_level
);
4408 target
->InitRunes();
4409 target
->InitStatsForLevel(true);
4410 target
->InitTaxiNodesForLevel();
4411 target
->InitGlyphsForLevel();
4412 target
->InitTalentForLevel();
4413 target
->SetUInt32Value(PLAYER_XP
,0);
4415 target
->_ApplyAllLevelScaleItemMods(true);
4417 // reset level for pet
4418 if(Pet
* pet
= target
->GetPet())
4419 pet
->SynchronizeLevelWithOwner();
4424 bool ChatHandler::HandleResetStatsCommand(const char * args
)
4427 if (!extractPlayerTarget((char*)args
,&target
))
4430 if (!HandleResetStatsOrLevelHelper(target
))
4433 target
->InitRunes();
4434 target
->InitStatsForLevel(true);
4435 target
->InitTaxiNodesForLevel();
4436 target
->InitGlyphsForLevel();
4437 target
->InitTalentForLevel();
4442 bool ChatHandler::HandleResetSpellsCommand(const char * args
)
4446 std::string target_name
;
4447 if(!extractPlayerTarget((char*)args
,&target
,&target_guid
,&target_name
))
4452 target
->resetSpells();
4454 ChatHandler(target
).SendSysMessage(LANG_RESET_SPELLS
);
4455 if(!m_session
|| m_session
->GetPlayer()!=target
)
4456 PSendSysMessage(LANG_RESET_SPELLS_ONLINE
,GetNameLink(target
).c_str());
4460 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS
), GUID_LOPART(target_guid
));
4461 PSendSysMessage(LANG_RESET_SPELLS_OFFLINE
,target_name
.c_str());
4467 bool ChatHandler::HandleResetTalentsCommand(const char * args
)
4471 std::string target_name
;
4472 if (!extractPlayerTarget((char*)args
,&target
,&target_guid
,&target_name
))
4474 // Try reset talents as Hunter Pet
4475 Creature
* creature
= getSelectedCreature();
4476 if (!*args
&& creature
&& creature
->isPet())
4478 Unit
*owner
= creature
->GetOwner();
4479 if(owner
&& owner
->GetTypeId() == TYPEID_PLAYER
&& ((Pet
*)creature
)->IsPermanentPetFor((Player
*)owner
))
4481 ((Pet
*)creature
)->resetTalents(true);
4482 ((Player
*)owner
)->SendTalentsInfoData(true);
4484 ChatHandler((Player
*)owner
).SendSysMessage(LANG_RESET_PET_TALENTS
);
4485 if(!m_session
|| m_session
->GetPlayer()!=((Player
*)owner
))
4486 PSendSysMessage(LANG_RESET_PET_TALENTS_ONLINE
,GetNameLink((Player
*)owner
).c_str());
4491 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4492 SetSentErrorMessage(true);
4498 target
->resetTalents(true);
4499 target
->SendTalentsInfoData(false);
4500 ChatHandler(target
).SendSysMessage(LANG_RESET_TALENTS
);
4501 if (!m_session
|| m_session
->GetPlayer()!=target
)
4502 PSendSysMessage(LANG_RESET_TALENTS_ONLINE
,GetNameLink(target
).c_str());
4504 Pet
* pet
= target
->GetPet();
4505 Pet::resetTalentsForAllPetsOf(target
,pet
);
4507 target
->SendTalentsInfoData(true);
4510 else if (target_guid
)
4512 uint32 at_flags
= AT_LOGIN_NONE
| AT_LOGIN_RESET_PET_TALENTS
;
4513 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",at_flags
, GUID_LOPART(target_guid
) );
4514 std::string nameLink
= playerLink(target_name
);
4515 PSendSysMessage(LANG_RESET_TALENTS_OFFLINE
,nameLink
.c_str());
4519 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4520 SetSentErrorMessage(true);
4524 bool ChatHandler::HandleResetAllCommand(const char * args
)
4529 std::string casename
= args
;
4531 AtLoginFlags atLogin
;
4533 // Command specially created as single command to prevent using short case names
4534 if(casename
=="spells")
4536 atLogin
= AT_LOGIN_RESET_SPELLS
;
4537 sWorld
.SendWorldText(LANG_RESETALL_SPELLS
);
4539 SendSysMessage(LANG_RESETALL_SPELLS
);
4541 else if(casename
=="talents")
4543 atLogin
= AtLoginFlags(AT_LOGIN_RESET_TALENTS
| AT_LOGIN_RESET_PET_TALENTS
);
4544 sWorld
.SendWorldText(LANG_RESETALL_TALENTS
);
4546 SendSysMessage(LANG_RESETALL_TALENTS
);
4550 PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE
,args
);
4551 SetSentErrorMessage(true);
4555 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE (at_login & '%u') = '0'",atLogin
,atLogin
);
4556 HashMapHolder
<Player
>::MapType
const& plist
= sObjectAccessor
.GetPlayers();
4557 for(HashMapHolder
<Player
>::MapType::const_iterator itr
= plist
.begin(); itr
!= plist
.end(); ++itr
)
4558 itr
->second
->SetAtLoginFlag(atLogin
);
4563 bool ChatHandler::HandleServerShutDownCancelCommand(const char* /*args*/)
4565 sWorld
.ShutdownCancel();
4569 bool ChatHandler::HandleServerShutDownCommand(const char* args
)
4574 char* time_str
= strtok ((char*) args
, " ");
4575 char* exitcode_str
= strtok (NULL
, "");
4577 int32 time
= atoi (time_str
);
4579 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4580 if ((time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0')) || time
< 0)
4585 int32 exitcode
= atoi (exitcode_str
);
4587 // Handle atoi() errors
4588 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4591 // Exit code should be in range of 0-125, 126-255 is used
4592 // in many shells for their own return codes and code > 255
4593 // is not supported in many others
4594 if (exitcode
< 0 || exitcode
> 125)
4597 sWorld
.ShutdownServ (time
, 0, exitcode
);
4600 sWorld
.ShutdownServ(time
,0,SHUTDOWN_EXIT_CODE
);
4604 bool ChatHandler::HandleServerRestartCommand(const char* args
)
4609 char* time_str
= strtok ((char*) args
, " ");
4610 char* exitcode_str
= strtok (NULL
, "");
4612 int32 time
= atoi (time_str
);
4614 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4615 if ((time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0')) || time
< 0)
4620 int32 exitcode
= atoi (exitcode_str
);
4622 // Handle atoi() errors
4623 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4626 // Exit code should be in range of 0-125, 126-255 is used
4627 // in many shells for their own return codes and code > 255
4628 // is not supported in many others
4629 if (exitcode
< 0 || exitcode
> 125)
4632 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_RESTART
, exitcode
);
4635 sWorld
.ShutdownServ(time
, SHUTDOWN_MASK_RESTART
, RESTART_EXIT_CODE
);
4639 bool ChatHandler::HandleServerIdleRestartCommand(const char* args
)
4644 char* time_str
= strtok ((char*) args
, " ");
4645 char* exitcode_str
= strtok (NULL
, "");
4647 int32 time
= atoi (time_str
);
4649 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4650 if ((time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0')) || time
< 0)
4655 int32 exitcode
= atoi (exitcode_str
);
4657 // Handle atoi() errors
4658 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4661 // Exit code should be in range of 0-125, 126-255 is used
4662 // in many shells for their own return codes and code > 255
4663 // is not supported in many others
4664 if (exitcode
< 0 || exitcode
> 125)
4667 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_RESTART
|SHUTDOWN_MASK_IDLE
, exitcode
);
4670 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_RESTART
|SHUTDOWN_MASK_IDLE
,RESTART_EXIT_CODE
);
4674 bool ChatHandler::HandleServerIdleShutDownCommand(const char* args
)
4679 char* time_str
= strtok ((char*) args
, " ");
4680 char* exitcode_str
= strtok (NULL
, "");
4682 int32 time
= atoi (time_str
);
4684 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4685 if ((time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0')) || time
< 0)
4690 int32 exitcode
= atoi (exitcode_str
);
4692 // Handle atoi() errors
4693 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4696 // Exit code should be in range of 0-125, 126-255 is used
4697 // in many shells for their own return codes and code > 255
4698 // is not supported in many others
4699 if (exitcode
< 0 || exitcode
> 125)
4702 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_IDLE
, exitcode
);
4705 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_IDLE
,SHUTDOWN_EXIT_CODE
);
4709 bool ChatHandler::HandleQuestAdd(const char* args
)
4711 Player
* player
= getSelectedPlayer();
4714 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4715 SetSentErrorMessage(true);
4719 // .addquest #entry'
4720 // number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
4721 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4725 uint32 entry
= atol(cId
);
4727 Quest
const* pQuest
= sObjectMgr
.GetQuestTemplate(entry
);
4731 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
,entry
);
4732 SetSentErrorMessage(true);
4736 // check item starting quest (it can work incorrectly if added without item in inventory)
4737 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
4739 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
4743 if (pProto
->StartQuest
== entry
)
4745 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM
, entry
, pProto
->ItemId
);
4746 SetSentErrorMessage(true);
4751 // ok, normal (creature/GO starting) quest
4752 if( player
->CanAddQuest( pQuest
, true ) )
4754 player
->AddQuest( pQuest
, NULL
);
4756 if ( player
->CanCompleteQuest( entry
) )
4757 player
->CompleteQuest( entry
);
4763 bool ChatHandler::HandleQuestRemove(const char* args
)
4765 Player
* player
= getSelectedPlayer();
4768 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4769 SetSentErrorMessage(true);
4773 // .removequest #entry'
4774 // number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
4775 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4779 uint32 entry
= atol(cId
);
4781 Quest
const* pQuest
= sObjectMgr
.GetQuestTemplate(entry
);
4785 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
4786 SetSentErrorMessage(true);
4790 // remove all quest entries for 'entry' from quest log
4791 for(uint8 slot
= 0; slot
< MAX_QUEST_LOG_SIZE
; ++slot
)
4793 uint32 quest
= player
->GetQuestSlotQuestId(slot
);
4796 player
->SetQuestSlot(slot
,0);
4798 // we ignore unequippable quest items in this case, its' still be equipped
4799 player
->TakeQuestSourceItem( quest
, false );
4803 // set quest status to not started (will updated in DB at next save)
4804 player
->SetQuestStatus( entry
, QUEST_STATUS_NONE
);
4806 // reset rewarded for restart repeatable quest
4807 player
->getQuestStatusMap()[entry
].m_rewarded
= false;
4809 SendSysMessage(LANG_COMMAND_QUEST_REMOVED
);
4813 bool ChatHandler::HandleQuestComplete(const char* args
)
4815 Player
* player
= getSelectedPlayer();
4818 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4819 SetSentErrorMessage(true);
4823 // .quest complete #entry
4824 // number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
4825 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4829 uint32 entry
= atol(cId
);
4831 Quest
const* pQuest
= sObjectMgr
.GetQuestTemplate(entry
);
4833 // If player doesn't have the quest
4834 if(!pQuest
|| player
->GetQuestStatus(entry
) == QUEST_STATUS_NONE
)
4836 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
4837 SetSentErrorMessage(true);
4841 // Add quest items for quests that require items
4842 for(uint8 x
= 0; x
< QUEST_ITEM_OBJECTIVES_COUNT
; ++x
)
4844 uint32 id
= pQuest
->ReqItemId
[x
];
4845 uint32 count
= pQuest
->ReqItemCount
[x
];
4849 uint32 curItemCount
= player
->GetItemCount(id
,true);
4851 ItemPosCountVec dest
;
4852 uint8 msg
= player
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, id
, count
- curItemCount
);
4853 if( msg
== EQUIP_ERR_OK
)
4855 Item
* item
= player
->StoreNewItem( dest
, id
, true);
4856 player
->SendNewItem(item
,count
-curItemCount
, true, false);
4860 // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
4861 for(uint8 i
= 0; i
< QUEST_OBJECTIVES_COUNT
; ++i
)
4863 uint32 creature
= pQuest
->ReqCreatureOrGOId
[i
];
4864 uint32 creaturecount
= pQuest
->ReqCreatureOrGOCount
[i
];
4866 if(uint32 spell_id
= pQuest
->ReqSpell
[i
])
4868 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4869 player
->CastedCreatureOrGO(creature
,0,spell_id
);
4871 else if(creature
> 0)
4873 if(CreatureInfo
const* cInfo
= ObjectMgr::GetCreatureTemplate(creature
))
4874 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4875 player
->KilledMonster(cInfo
,0);
4877 else if(creature
< 0)
4879 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4880 player
->CastedCreatureOrGO(creature
,0,0);
4884 // If the quest requires reputation to complete
4885 if(uint32 repFaction
= pQuest
->GetRepObjectiveFaction())
4887 uint32 repValue
= pQuest
->GetRepObjectiveValue();
4888 uint32 curRep
= player
->GetReputationMgr().GetReputation(repFaction
);
4889 if(curRep
< repValue
)
4890 if(FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry(repFaction
))
4891 player
->GetReputationMgr().SetReputation(factionEntry
,repValue
);
4894 // If the quest requires money
4895 int32 ReqOrRewMoney
= pQuest
->GetRewOrReqMoney();
4896 if(ReqOrRewMoney
< 0)
4897 player
->ModifyMoney(-ReqOrRewMoney
);
4899 player
->CompleteQuest(entry
);
4903 bool ChatHandler::HandleBanAccountCommand(const char* args
)
4905 return HandleBanHelper(BAN_ACCOUNT
,args
);
4908 bool ChatHandler::HandleBanCharacterCommand(const char* args
)
4910 return HandleBanHelper(BAN_CHARACTER
,args
);
4913 bool ChatHandler::HandleBanIPCommand(const char* args
)
4915 return HandleBanHelper(BAN_IP
,args
);
4918 bool ChatHandler::HandleBanHelper(BanMode mode
, const char* args
)
4923 char* cnameOrIP
= strtok ((char*)args
, " ");
4927 std::string nameOrIP
= cnameOrIP
;
4929 char* duration
= strtok (NULL
," ");
4930 if(!duration
|| !atoi(duration
))
4933 char* reason
= strtok (NULL
,"");
4940 if (!AccountMgr::normalizeString(nameOrIP
))
4942 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
4943 SetSentErrorMessage(true);
4948 if(!normalizePlayerName(nameOrIP
))
4950 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4951 SetSentErrorMessage(true);
4956 if(!IsIPAddress(nameOrIP
.c_str()))
4961 switch(sWorld
.BanAccount(mode
, nameOrIP
, duration
, reason
,m_session
? m_session
->GetPlayerName() : ""))
4964 if(atoi(duration
)>0)
4965 PSendSysMessage(LANG_BAN_YOUBANNED
,nameOrIP
.c_str(),secsToTimeString(TimeStringToSecs(duration
),true).c_str(),reason
);
4967 PSendSysMessage(LANG_BAN_YOUPERMBANNED
,nameOrIP
.c_str(),reason
);
4969 case BAN_SYNTAX_ERROR
:
4975 PSendSysMessage(LANG_BAN_NOTFOUND
,"account",nameOrIP
.c_str());
4978 PSendSysMessage(LANG_BAN_NOTFOUND
,"character",nameOrIP
.c_str());
4981 PSendSysMessage(LANG_BAN_NOTFOUND
,"ip",nameOrIP
.c_str());
4984 SetSentErrorMessage(true);
4991 bool ChatHandler::HandleUnBanAccountCommand(const char* args
)
4993 return HandleUnBanHelper(BAN_ACCOUNT
,args
);
4996 bool ChatHandler::HandleUnBanCharacterCommand(const char* args
)
4998 return HandleUnBanHelper(BAN_CHARACTER
,args
);
5001 bool ChatHandler::HandleUnBanIPCommand(const char* args
)
5003 return HandleUnBanHelper(BAN_IP
,args
);
5006 bool ChatHandler::HandleUnBanHelper(BanMode mode
, const char* args
)
5011 char* cnameOrIP
= strtok ((char*)args
, " ");
5015 std::string nameOrIP
= cnameOrIP
;
5020 if (!AccountMgr::normalizeString(nameOrIP
))
5022 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
5023 SetSentErrorMessage(true);
5028 if(!normalizePlayerName(nameOrIP
))
5030 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5031 SetSentErrorMessage(true);
5036 if(!IsIPAddress(nameOrIP
.c_str()))
5041 if(sWorld
.RemoveBanAccount(mode
,nameOrIP
))
5042 PSendSysMessage(LANG_UNBAN_UNBANNED
,nameOrIP
.c_str());
5044 PSendSysMessage(LANG_UNBAN_ERROR
,nameOrIP
.c_str());
5049 bool ChatHandler::HandleBanInfoAccountCommand(const char* args
)
5054 char* cname
= strtok((char*)args
, "");
5058 std::string account_name
= cname
;
5059 if (!AccountMgr::normalizeString(account_name
))
5061 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5062 SetSentErrorMessage(true);
5066 uint32 accountid
= sAccountMgr
.GetId(account_name
);
5069 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5073 return HandleBanInfoHelper(accountid
,account_name
.c_str());
5076 bool ChatHandler::HandleBanInfoCharacterCommand(const char* args
)
5080 if (!extractPlayerTarget((char*)args
,&target
,&target_guid
))
5083 uint32 accountid
= target
? target
->GetSession()->GetAccountId() : sObjectMgr
.GetPlayerAccountIdByGUID(target_guid
);
5085 std::string accountname
;
5086 if (!sAccountMgr
.GetName(accountid
,accountname
))
5088 PSendSysMessage(LANG_BANINFO_NOCHARACTER
);
5092 return HandleBanInfoHelper(accountid
,accountname
.c_str());
5095 bool ChatHandler::HandleBanInfoHelper(uint32 accountid
, char const* accountname
)
5097 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
);
5100 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN
, accountname
);
5104 PSendSysMessage(LANG_BANINFO_BANHISTORY
,accountname
);
5107 Field
* fields
= result
->Fetch();
5109 time_t unbandate
= time_t(fields
[3].GetUInt64());
5110 bool active
= false;
5111 if(fields
[2].GetBool() && (fields
[1].GetUInt64() == (uint64
)0 ||unbandate
>= time(NULL
)) )
5113 bool permanent
= (fields
[1].GetUInt64() == (uint64
)0);
5114 std::string bantime
= permanent
?GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[1].GetUInt64(), true);
5115 PSendSysMessage(LANG_BANINFO_HISTORYENTRY
,
5116 fields
[0].GetString(), bantime
.c_str(), active
? GetMangosString(LANG_BANINFO_YES
):GetMangosString(LANG_BANINFO_NO
), fields
[4].GetString(), fields
[5].GetString());
5117 }while (result
->NextRow());
5123 bool ChatHandler::HandleBanInfoIPCommand(const char* args
)
5128 char* cIP
= strtok ((char*)args
, "");
5132 if (!IsIPAddress(cIP
))
5135 std::string IP
= cIP
;
5137 loginDatabase
.escape_string(IP
);
5138 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());
5141 PSendSysMessage(LANG_BANINFO_NOIP
);
5145 Field
*fields
= result
->Fetch();
5146 bool permanent
= !fields
[6].GetUInt64();
5147 PSendSysMessage(LANG_BANINFO_IPENTRY
,
5148 fields
[0].GetString(), fields
[1].GetString(), permanent
? GetMangosString(LANG_BANINFO_NEVER
):fields
[2].GetString(),
5149 permanent
? GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[3].GetUInt64(), true).c_str(), fields
[4].GetString(), fields
[5].GetString());
5154 bool ChatHandler::HandleBanListCharacterCommand(const char* args
)
5156 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5158 char* cFilter
= strtok ((char*)args
, " ");
5162 std::string filter
= cFilter
;
5163 loginDatabase
.escape_string(filter
);
5164 QueryResult
* result
= CharacterDatabase
.PQuery("SELECT account FROM characters WHERE name "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'"),filter
.c_str());
5167 PSendSysMessage(LANG_BANLIST_NOCHARACTER
);
5171 return HandleBanListHelper(result
);
5174 bool ChatHandler::HandleBanListAccountCommand(const char* args
)
5176 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5178 char* cFilter
= strtok((char*)args
, " ");
5179 std::string filter
= cFilter
? cFilter
: "";
5180 loginDatabase
.escape_string(filter
);
5182 QueryResult
* result
;
5186 result
= loginDatabase
.Query("SELECT account.id, username FROM account, account_banned"
5187 " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
5191 result
= loginDatabase
.PQuery("SELECT account.id, username FROM account, account_banned"
5192 " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
5198 PSendSysMessage(LANG_BANLIST_NOACCOUNT
);
5202 return HandleBanListHelper(result
);
5205 bool ChatHandler::HandleBanListHelper(QueryResult
* result
)
5207 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT
);
5209 // Chat short output
5214 Field
* fields
= result
->Fetch();
5215 uint32 accountid
= fields
[0].GetUInt32();
5217 QueryResult
* banresult
= loginDatabase
.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid
);
5220 Field
* fields2
= banresult
->Fetch();
5221 PSendSysMessage("%s",fields2
[0].GetString());
5224 } while (result
->NextRow());
5226 // Console wide output
5229 SendSysMessage(LANG_BANLIST_ACCOUNTS
);
5230 SendSysMessage("===============================================================================");
5231 SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER
);
5234 SendSysMessage("-------------------------------------------------------------------------------");
5235 Field
*fields
= result
->Fetch();
5236 uint32 account_id
= fields
[0].GetUInt32 ();
5238 std::string account_name
;
5240 // "account" case, name can be get in same query
5241 if(result
->GetFieldCount() > 1)
5242 account_name
= fields
[1].GetCppString();
5243 // "character" case, name need extract from another DB
5245 sAccountMgr
.GetName (account_id
,account_name
);
5247 // No SQL injection. id is uint32.
5248 QueryResult
*banInfo
= loginDatabase
.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id
);
5251 Field
*fields2
= banInfo
->Fetch();
5254 time_t t_ban
= fields2
[0].GetUInt64();
5255 tm
* aTm_ban
= localtime(&t_ban
);
5257 if (fields2
[0].GetUInt64() == fields2
[1].GetUInt64())
5259 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5260 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
,
5261 fields2
[2].GetString(),fields2
[3].GetString());
5265 time_t t_unban
= fields2
[1].GetUInt64();
5266 tm
* aTm_unban
= localtime(&t_unban
);
5267 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5268 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
,
5269 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5270 fields2
[2].GetString(),fields2
[3].GetString());
5272 }while ( banInfo
->NextRow() );
5275 }while( result
->NextRow() );
5276 SendSysMessage("===============================================================================");
5283 bool ChatHandler::HandleBanListIPCommand(const char* args
)
5285 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5287 char* cFilter
= strtok((char*)args
, " ");
5288 std::string filter
= cFilter
? cFilter
: "";
5289 loginDatabase
.escape_string(filter
);
5291 QueryResult
* result
;
5295 result
= loginDatabase
.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5296 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
5297 " ORDER BY unbandate" );
5301 result
= loginDatabase
.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5302 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")
5303 " ORDER BY unbandate",filter
.c_str() );
5308 PSendSysMessage(LANG_BANLIST_NOIP
);
5312 PSendSysMessage(LANG_BANLIST_MATCHINGIP
);
5313 // Chat short output
5318 Field
* fields
= result
->Fetch();
5319 PSendSysMessage("%s",fields
[0].GetString());
5320 } while (result
->NextRow());
5322 // Console wide output
5325 SendSysMessage(LANG_BANLIST_IPS
);
5326 SendSysMessage("===============================================================================");
5327 SendSysMessage(LANG_BANLIST_IPS_HEADER
);
5330 SendSysMessage("-------------------------------------------------------------------------------");
5331 Field
*fields
= result
->Fetch();
5332 time_t t_ban
= fields
[1].GetUInt64();
5333 tm
* aTm_ban
= localtime(&t_ban
);
5334 if ( fields
[1].GetUInt64() == fields
[2].GetUInt64() )
5336 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5337 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
,
5338 fields
[3].GetString(), fields
[4].GetString());
5342 time_t t_unban
= fields
[2].GetUInt64();
5343 tm
* aTm_unban
= localtime(&t_unban
);
5344 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5345 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
,
5346 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5347 fields
[3].GetString(), fields
[4].GetString());
5349 }while( result
->NextRow() );
5350 SendSysMessage("===============================================================================");
5357 bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
5359 Player
* pl
= m_session
->GetPlayer();
5361 // accept only explicitly selected target (not implicitly self targeting case)
5362 Unit
* target
= getSelectedUnit();
5363 if(pl
->GetSelection() && target
)
5365 if(target
->GetTypeId()!=TYPEID_UNIT
)
5367 SendSysMessage(LANG_SELECT_CREATURE
);
5368 SetSentErrorMessage(true);
5372 if(target
->isDead())
5373 ((Creature
*)target
)->Respawn();
5377 CellPair
p(MaNGOS::ComputeCellPair(pl
->GetPositionX(), pl
->GetPositionY()));
5379 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
5382 MaNGOS::RespawnDo u_do
;
5383 MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
> worker(pl
,u_do
);
5385 TypeContainerVisitor
<MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
>, GridTypeMapContainer
> obj_worker(worker
);
5386 cell
.Visit(p
, obj_worker
, *pl
->GetMap());
5391 bool ChatHandler::HandleGMFlyCommand(const char* args
)
5396 Player
*target
= getSelectedPlayer();
5398 target
= m_session
->GetPlayer();
5400 WorldPacket
data(12);
5401 if (strncmp(args
, "on", 3) == 0)
5402 data
.SetOpcode(SMSG_MOVE_SET_CAN_FLY
);
5403 else if (strncmp(args
, "off", 4) == 0)
5404 data
.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY
);
5407 SendSysMessage(LANG_USE_BOL
);
5410 data
.append(target
->GetPackGUID());
5411 data
<< uint32(0); // unknown
5412 target
->SendMessageToSet(&data
, true);
5413 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS
, GetNameLink(target
).c_str(), args
);
5417 bool ChatHandler::HandlePDumpLoadCommand(const char *args
)
5422 char * file
= strtok((char*)args
, " ");
5426 char * account
= strtok(NULL
, " ");
5430 std::string account_name
= account
;
5431 if (!AccountMgr::normalizeString(account_name
))
5433 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5434 SetSentErrorMessage(true);
5438 uint32 account_id
= sAccountMgr
.GetId(account_name
);
5441 account_id
= atoi(account
); // use original string
5444 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5445 SetSentErrorMessage(true);
5450 if (!sAccountMgr
.GetName(account_id
,account_name
))
5452 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5453 SetSentErrorMessage(true);
5457 char* guid_str
= NULL
;
5458 char* name_str
= strtok(NULL
, " ");
5464 // normalize the name if specified and check if it exists
5465 if (!normalizePlayerName(name
))
5467 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5468 SetSentErrorMessage(true);
5472 if (ObjectMgr::CheckPlayerName(name
,true) != CHAR_NAME_SUCCESS
)
5474 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5475 SetSentErrorMessage(true);
5479 guid_str
= strtok(NULL
, " ");
5486 guid
= atoi(guid_str
);
5489 PSendSysMessage(LANG_INVALID_CHARACTER_GUID
);
5490 SetSentErrorMessage(true);
5494 if (sObjectMgr
.GetPlayerAccountIdByGUID(guid
))
5496 PSendSysMessage(LANG_CHARACTER_GUID_IN_USE
,guid
);
5497 SetSentErrorMessage(true);
5502 switch(PlayerDumpReader().LoadDump(file
, account_id
, name
, guid
))
5505 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS
);
5507 case DUMP_FILE_OPEN_ERROR
:
5508 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
5509 SetSentErrorMessage(true);
5511 case DUMP_FILE_BROKEN
:
5512 PSendSysMessage(LANG_DUMP_BROKEN
,file
);
5513 SetSentErrorMessage(true);
5515 case DUMP_TOO_MANY_CHARS
:
5516 PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL
,account_name
.c_str(),account_id
);
5517 SetSentErrorMessage(true);
5520 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED
);
5521 SetSentErrorMessage(true);
5528 bool ChatHandler::HandlePDumpWriteCommand(const char *args
)
5533 char* file
= strtok((char*)args
, " ");
5534 char* p2
= strtok(NULL
, " ");
5540 // character name can't start from number
5541 if (isNumeric(p2
[0]))
5545 std::string name
= extractPlayerNameFromLink(p2
);
5548 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5549 SetSentErrorMessage(true);
5553 guid
= sObjectMgr
.GetPlayerGUIDByName(name
);
5556 if(!sObjectMgr
.GetPlayerAccountIdByGUID(guid
))
5558 PSendSysMessage(LANG_PLAYER_NOT_FOUND
);
5559 SetSentErrorMessage(true);
5563 switch(PlayerDumpWriter().WriteDump(file
, guid
))
5566 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS
);
5568 case DUMP_FILE_OPEN_ERROR
:
5569 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
5570 SetSentErrorMessage(true);
5573 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED
);
5574 SetSentErrorMessage(true);
5581 bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
5583 Unit
* unit
= getSelectedUnit();
5586 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5587 SetSentErrorMessage(true);
5591 PSendSysMessage(LANG_MOVEGENS_LIST
,(unit
->GetTypeId()==TYPEID_PLAYER
? "Player" : "Creature" ),unit
->GetGUIDLow());
5593 MotionMaster
* mm
= unit
->GetMotionMaster();
5594 for(MotionMaster::const_iterator itr
= mm
->begin(); itr
!= mm
->end(); ++itr
)
5596 switch((*itr
)->GetMovementGeneratorType())
5598 case IDLE_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_IDLE
); break;
5599 case RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_RANDOM
); break;
5600 case WAYPOINT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_WAYPOINT
); break;
5601 case ANIMAL_RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_ANIMAL_RANDOM
); break;
5602 case CONFUSED_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_CONFUSED
); break;
5603 case CHASE_MOTION_TYPE
:
5605 Unit
* target
= NULL
;
5606 if(unit
->GetTypeId()==TYPEID_PLAYER
)
5607 target
= static_cast<ChaseMovementGenerator
<Player
> const*>(*itr
)->GetTarget();
5609 target
= static_cast<ChaseMovementGenerator
<Creature
> const*>(*itr
)->GetTarget();
5612 SendSysMessage(LANG_MOVEGENS_CHASE_NULL
);
5613 else if (target
->GetTypeId()==TYPEID_PLAYER
)
5614 PSendSysMessage(LANG_MOVEGENS_CHASE_PLAYER
,target
->GetName(),target
->GetGUIDLow());
5616 PSendSysMessage(LANG_MOVEGENS_CHASE_CREATURE
,target
->GetName(),target
->GetGUIDLow());
5619 case FOLLOW_MOTION_TYPE
:
5621 Unit
* target
= NULL
;
5622 if(unit
->GetTypeId()==TYPEID_PLAYER
)
5623 target
= static_cast<FollowMovementGenerator
<Player
> const*>(*itr
)->GetTarget();
5625 target
= static_cast<FollowMovementGenerator
<Creature
> const*>(*itr
)->GetTarget();
5628 SendSysMessage(LANG_MOVEGENS_FOLLOW_NULL
);
5629 else if (target
->GetTypeId()==TYPEID_PLAYER
)
5630 PSendSysMessage(LANG_MOVEGENS_FOLLOW_PLAYER
,target
->GetName(),target
->GetGUIDLow());
5632 PSendSysMessage(LANG_MOVEGENS_FOLLOW_CREATURE
,target
->GetName(),target
->GetGUIDLow());
5635 case HOME_MOTION_TYPE
:
5636 if(unit
->GetTypeId()==TYPEID_UNIT
)
5639 (*itr
)->GetDestination(x
,y
,z
);
5640 PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE
,x
,y
,z
);
5643 SendSysMessage(LANG_MOVEGENS_HOME_PLAYER
);
5645 case FLIGHT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FLIGHT
); break;
5646 case POINT_MOTION_TYPE
:
5649 (*itr
)->GetDestination(x
,y
,z
);
5650 PSendSysMessage(LANG_MOVEGENS_POINT
,x
,y
,z
);
5653 case FLEEING_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FEAR
); break;
5654 case DISTRACT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_DISTRACT
); break;
5656 PSendSysMessage(LANG_MOVEGENS_UNKNOWN
,(*itr
)->GetMovementGeneratorType());
5663 bool ChatHandler::HandleServerPLimitCommand(const char *args
)
5667 char* param
= strtok((char*)args
, " ");
5671 int l
= strlen(param
);
5673 if( strncmp(param
,"player",l
) == 0 )
5674 sWorld
.SetPlayerLimit(-SEC_PLAYER
);
5675 else if(strncmp(param
,"moderator",l
) == 0 )
5676 sWorld
.SetPlayerLimit(-SEC_MODERATOR
);
5677 else if(strncmp(param
,"gamemaster",l
) == 0 )
5678 sWorld
.SetPlayerLimit(-SEC_GAMEMASTER
);
5679 else if(strncmp(param
,"administrator",l
) == 0 )
5680 sWorld
.SetPlayerLimit(-SEC_ADMINISTRATOR
);
5681 else if(strncmp(param
,"reset",l
) == 0 )
5682 sWorld
.SetPlayerLimit( sConfig
.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT
) );
5685 int val
= atoi(param
);
5686 if(val
< -SEC_ADMINISTRATOR
) val
= -SEC_ADMINISTRATOR
;
5688 sWorld
.SetPlayerLimit(val
);
5691 // kick all low security level players
5692 if(sWorld
.GetPlayerAmountLimit() > SEC_PLAYER
)
5693 sWorld
.KickAllLess(sWorld
.GetPlayerSecurityLimit());
5696 uint32 pLimit
= sWorld
.GetPlayerAmountLimit();
5697 AccountTypes allowedAccountType
= sWorld
.GetPlayerSecurityLimit();
5698 char const* secName
= "";
5699 switch(allowedAccountType
)
5701 case SEC_PLAYER
: secName
= "Player"; break;
5702 case SEC_MODERATOR
: secName
= "Moderator"; break;
5703 case SEC_GAMEMASTER
: secName
= "Gamemaster"; break;
5704 case SEC_ADMINISTRATOR
: secName
= "Administrator"; break;
5705 default: secName
= "<unknown>"; break;
5708 PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit
,secName
);
5713 bool ChatHandler::HandleCastCommand(const char* args
)
5718 Unit
* target
= getSelectedUnit();
5722 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5723 SetSentErrorMessage(true);
5727 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5728 uint32 spell
= extractSpellIdFromLink((char*)args
);
5732 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5736 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5738 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5739 SetSentErrorMessage(true);
5743 char* trig_str
= strtok(NULL
, " ");
5746 int l
= strlen(trig_str
);
5747 if(strncmp(trig_str
,"triggered",l
) != 0 )
5751 bool triggered
= (trig_str
!= NULL
);
5753 m_session
->GetPlayer()->CastSpell(target
,spell
,triggered
);
5758 bool ChatHandler::HandleCastBackCommand(const char* args
)
5760 Creature
* caster
= getSelectedCreature();
5764 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5765 SetSentErrorMessage(true);
5769 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
5770 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5771 uint32 spell
= extractSpellIdFromLink((char*)args
);
5772 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
5775 char* trig_str
= strtok(NULL
, " ");
5778 int l
= strlen(trig_str
);
5779 if(strncmp(trig_str
,"triggered",l
) != 0 )
5783 bool triggered
= (trig_str
!= NULL
);
5785 caster
->SetFacingToObject(m_session
->GetPlayer());
5787 caster
->CastSpell(m_session
->GetPlayer(),spell
,triggered
);
5792 bool ChatHandler::HandleCastDistCommand(const char* args
)
5797 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5798 uint32 spell
= extractSpellIdFromLink((char*)args
);
5802 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5806 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5808 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5809 SetSentErrorMessage(true);
5813 char *distStr
= strtok(NULL
, " ");
5818 sscanf(distStr
, "%f", &dist
);
5820 char* trig_str
= strtok(NULL
, " ");
5823 int l
= strlen(trig_str
);
5824 if(strncmp(trig_str
,"triggered",l
) != 0 )
5828 bool triggered
= (trig_str
!= NULL
);
5831 m_session
->GetPlayer()->GetClosePoint(x
,y
,z
,dist
);
5833 m_session
->GetPlayer()->CastSpell(x
,y
,z
,spell
,triggered
);
5837 bool ChatHandler::HandleCastTargetCommand(const char* args
)
5839 Creature
* caster
= getSelectedCreature();
5843 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5844 SetSentErrorMessage(true);
5848 if(!caster
->getVictim())
5850 SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM
);
5851 SetSentErrorMessage(true);
5855 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5856 uint32 spell
= extractSpellIdFromLink((char*)args
);
5857 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
5860 char* trig_str
= strtok(NULL
, " ");
5863 int l
= strlen(trig_str
);
5864 if(strncmp(trig_str
,"triggered",l
) != 0 )
5868 bool triggered
= (trig_str
!= NULL
);
5870 caster
->SetFacingToObject(m_session
->GetPlayer());
5872 caster
->CastSpell(caster
->getVictim(),spell
,triggered
);
5878 ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
5879 Without this function 3rd party scripting library will get linking errors (unresolved external)
5880 when attempting to use the PointMovementGenerator
5882 bool ChatHandler::HandleComeToMeCommand(const char *args
)
5884 Creature
* caster
= getSelectedCreature();
5888 SendSysMessage(LANG_SELECT_CREATURE
);
5889 SetSentErrorMessage(true);
5893 char* newFlagStr
= strtok((char*)args
, " ");
5898 uint32 newFlags
= atoi(newFlagStr
);
5900 caster
->SetMonsterMoveFlags(MonsterMovementFlags(newFlags
));
5902 Player
* pl
= m_session
->GetPlayer();
5904 caster
->GetMotionMaster()->MovePoint(0, pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ());
5908 bool ChatHandler::HandleCastSelfCommand(const char* args
)
5913 Unit
* target
= getSelectedUnit();
5917 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5918 SetSentErrorMessage(true);
5922 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5923 uint32 spell
= extractSpellIdFromLink((char*)args
);
5927 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5931 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5933 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5934 SetSentErrorMessage(true);
5938 target
->CastSpell(target
,spell
,false);
5943 std::string
GetTimeString(uint32 time
)
5945 uint16 days
= time
/ DAY
, hours
= (time
% DAY
) / HOUR
, minute
= (time
% HOUR
) / MINUTE
;
5946 std::ostringstream ss
;
5947 if(days
) ss
<< days
<< "d ";
5948 if(hours
) ss
<< hours
<< "h ";
5949 ss
<< minute
<< "m";
5953 bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
5955 Player
* player
= getSelectedPlayer();
5956 if (!player
) player
= m_session
->GetPlayer();
5958 for(uint8 i
= 0; i
< MAX_DIFFICULTY
; ++i
)
5960 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(Difficulty(i
));
5961 for(Player::BoundInstancesMap::const_iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
5963 InstanceSave
*save
= itr
->second
.save
;
5964 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
5965 if (const MapEntry
* entry
= sMapStore
.LookupEntry(itr
->first
))
5967 PSendSysMessage("map: %d (%s) inst: %d perm: %s diff: %d canReset: %s TTR: %s",
5968 itr
->first
, entry
->name
[m_session
->GetSessionDbcLocale()], save
->GetInstanceId(), itr
->second
.perm
? "yes" : "no",
5969 save
->GetDifficulty(), save
->CanReset() ? "yes" : "no", timeleft
.c_str());
5972 PSendSysMessage("bound for a nonexistant map %u", itr
->first
);
5976 PSendSysMessage("player binds: %d", counter
);
5978 Group
*group
= player
->GetGroup();
5981 for(uint8 i
= 0; i
< MAX_DIFFICULTY
; ++i
)
5983 Group::BoundInstancesMap
&binds
= group
->GetBoundInstances(Difficulty(i
));
5984 for(Group::BoundInstancesMap::const_iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
5986 InstanceSave
*save
= itr
->second
.save
;
5987 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
5988 if (const MapEntry
* entry
= sMapStore
.LookupEntry(itr
->first
))
5990 PSendSysMessage("map: %d (%s) inst: %d perm: %s diff: %d canReset: %s TTR: %s",
5991 itr
->first
, entry
->name
[m_session
->GetSessionDbcLocale()], save
->GetInstanceId(), itr
->second
.perm
? "yes" : "no",
5992 save
->GetDifficulty(), save
->CanReset() ? "yes" : "no", timeleft
.c_str());
5995 PSendSysMessage("bound for a nonexistant map %u", itr
->first
);
6000 PSendSysMessage("group binds: %d", counter
);
6005 bool ChatHandler::HandleInstanceUnbindCommand(const char* args
)
6010 Player
* player
= getSelectedPlayer();
6012 player
= m_session
->GetPlayer();
6015 bool got_map
= false;
6017 if (strncmp(args
,"all",strlen(args
)) != 0)
6019 if(!isNumeric(args
[0]))
6026 for(uint8 i
= 0; i
< MAX_DIFFICULTY
; ++i
)
6028 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(Difficulty(i
));
6029 for(Player::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end();)
6031 if (got_map
&& mapid
!= itr
->first
)
6036 if(itr
->first
!= player
->GetMapId())
6038 InstanceSave
*save
= itr
->second
.save
;
6039 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
6041 if (const MapEntry
* entry
= sMapStore
.LookupEntry(itr
->first
))
6043 PSendSysMessage("unbinding map: %d (%s) inst: %d perm: %s diff: %d canReset: %s TTR: %s",
6044 itr
->first
, entry
->name
[m_session
->GetSessionDbcLocale()], save
->GetInstanceId(), itr
->second
.perm
? "yes" : "no",
6045 save
->GetDifficulty(), save
->CanReset() ? "yes" : "no", timeleft
.c_str());
6048 PSendSysMessage("bound for a nonexistant map %u", itr
->first
);
6049 player
->UnbindInstance(itr
, Difficulty(i
));
6056 PSendSysMessage("instances unbound: %d", counter
);
6060 bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
6062 PSendSysMessage("instances loaded: %d", sMapMgr
.GetNumInstances());
6063 PSendSysMessage("players in instances: %d", sMapMgr
.GetNumPlayersInInstances());
6064 PSendSysMessage("instance saves: %d", sInstanceSaveMgr
.GetNumInstanceSaves());
6065 PSendSysMessage("players bound: %d", sInstanceSaveMgr
.GetNumBoundPlayersTotal());
6066 PSendSysMessage("groups bound: %d", sInstanceSaveMgr
.GetNumBoundGroupsTotal());
6070 bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
6072 Player
* pl
= m_session
->GetPlayer();
6074 Map
* map
= pl
->GetMap();
6075 if (!map
->IsDungeon())
6077 PSendSysMessage("Map is not a dungeon.");
6078 SetSentErrorMessage(true);
6082 if (!((InstanceMap
*)map
)->GetInstanceData())
6084 PSendSysMessage("Map has no instance data.");
6085 SetSentErrorMessage(true);
6089 ((InstanceMap
*)map
)->GetInstanceData()->SaveToDB();
6093 /// Display the list of GMs
6094 bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
6096 ///- Get the accounts with GM Level >0
6097 QueryResult
*result
= loginDatabase
.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
6100 SendSysMessage(LANG_GMLIST
);
6101 SendSysMessage("========================");
6102 SendSysMessage(LANG_GMLIST_HEADER
);
6103 SendSysMessage("========================");
6105 ///- Circle through them. Display username and GM level
6108 Field
*fields
= result
->Fetch();
6109 PSendSysMessage("|%15s|%6s|", fields
[0].GetString(),fields
[1].GetString());
6110 }while( result
->NextRow() );
6112 PSendSysMessage("========================");
6116 PSendSysMessage(LANG_GMLIST_EMPTY
);
6120 /// Define the 'Message of the day' for the realm
6121 bool ChatHandler::HandleServerSetMotdCommand(const char* args
)
6123 sWorld
.SetMotd(args
);
6124 PSendSysMessage(LANG_MOTD_NEW
, args
);
6128 /// Set/Unset the expansion level for an account
6129 bool ChatHandler::HandleAccountSetAddonCommand(const char* args
)
6131 ///- Get the command line arguments
6132 char *szAcc
= strtok((char*)args
," ");
6133 char *szExp
= strtok(NULL
," ");
6138 std::string account_name
;
6143 Player
* player
= getSelectedPlayer();
6147 account_id
= player
->GetSession()->GetAccountId();
6148 sAccountMgr
.GetName(account_id
,account_name
);
6153 ///- Convert Account name to Upper Format
6154 account_name
= szAcc
;
6155 if (!AccountMgr::normalizeString(account_name
))
6157 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
6158 SetSentErrorMessage(true);
6162 account_id
= sAccountMgr
.GetId(account_name
);
6165 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
6166 SetSentErrorMessage(true);
6172 // Let set addon state only for lesser (strong) security level
6173 // or to self account
6174 if (m_session
&& m_session
->GetAccountId () != account_id
&&
6175 HasLowerSecurityAccount (NULL
,account_id
,true))
6178 int lev
=atoi(szExp
); //get int anyway (0 if error)
6183 loginDatabase
.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev
,account_id
);
6184 PSendSysMessage(LANG_ACCOUNT_SETADDON
,account_name
.c_str(),account_id
,lev
);
6188 //Send items by mail
6189 bool ChatHandler::HandleSendItemsCommand(const char* args
)
6191 // format: name "subject text" "mail text" item1[:count1] item2[:count2] ... item12[:count12]
6193 uint64 receiver_guid
;
6194 std::string receiver_name
;
6195 if(!extractPlayerTarget((char*)args
,&receiver
,&receiver_guid
,&receiver_name
))
6198 char* tail1
= strtok(NULL
, "");
6202 char* msgSubject
= extractQuotedArg(tail1
);
6206 char* tail2
= strtok(NULL
, "");
6210 char* msgText
= extractQuotedArg(tail2
);
6214 // msgSubject, msgText isn't NUL after prev. check
6215 std::string subject
= msgSubject
;
6216 std::string text
= msgText
;
6219 typedef std::pair
<uint32
,uint32
> ItemPair
;
6220 typedef std::list
< ItemPair
> ItemPairs
;
6223 // get all tail string
6224 char* tail
= strtok(NULL
, "");
6226 // get from tail next item str
6227 while(char* itemStr
= strtok(tail
, " "))
6230 tail
= strtok(NULL
, "");
6233 char* itemIdStr
= strtok(itemStr
, ":");
6234 char* itemCountStr
= strtok(NULL
, " ");
6236 uint32 item_id
= atoi(itemIdStr
);
6240 ItemPrototype
const* item_proto
= ObjectMgr::GetItemPrototype(item_id
);
6243 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
6244 SetSentErrorMessage(true);
6248 uint32 item_count
= itemCountStr
? atoi(itemCountStr
) : 1;
6249 if (item_count
< 1 || (item_proto
->MaxCount
> 0 && item_count
> uint32(item_proto
->MaxCount
)))
6251 PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT
, item_count
,item_id
);
6252 SetSentErrorMessage(true);
6256 while(item_count
> item_proto
->GetMaxStackSize())
6258 items
.push_back(ItemPair(item_id
,item_proto
->GetMaxStackSize()));
6259 item_count
-= item_proto
->GetMaxStackSize();
6262 items
.push_back(ItemPair(item_id
,item_count
));
6264 if(items
.size() > MAX_MAIL_ITEMS
)
6266 PSendSysMessage(LANG_COMMAND_MAIL_ITEMS_LIMIT
, MAX_MAIL_ITEMS
);
6267 SetSentErrorMessage(true);
6272 // from console show not existed sender
6273 MailSender
sender(MAIL_NORMAL
,m_session
? m_session
->GetPlayer()->GetGUIDLow() : 0, MAIL_STATIONERY_GM
);
6275 uint32 itemTextId
= !text
.empty() ? sObjectMgr
.CreateItemText( text
) : 0;
6278 MailDraft
draft(subject
, itemTextId
);
6280 for(ItemPairs::const_iterator itr
= items
.begin(); itr
!= items
.end(); ++itr
)
6282 if(Item
* item
= Item::CreateItem(itr
->first
,itr
->second
,m_session
? m_session
->GetPlayer() : 0))
6284 item
->SaveToDB(); // save for prevent lost at next mail load, if send fail then item will deleted
6285 draft
.AddItem(item
);
6289 draft
.SendMailTo(MailReceiver(receiver
,GUID_LOPART(receiver_guid
)), sender
);
6291 std::string nameLink
= playerLink(receiver_name
);
6292 PSendSysMessage(LANG_MAIL_SENT
, nameLink
.c_str());
6296 ///Send money by mail
6297 bool ChatHandler::HandleSendMoneyCommand(const char* args
)
6299 /// format: name "subject text" "mail text" money
6302 uint64 receiver_guid
;
6303 std::string receiver_name
;
6304 if(!extractPlayerTarget((char*)args
,&receiver
,&receiver_guid
,&receiver_name
))
6307 char* tail1
= strtok(NULL
, "");
6311 char* msgSubject
= extractQuotedArg(tail1
);
6315 char* tail2
= strtok(NULL
, "");
6319 char* msgText
= extractQuotedArg(tail2
);
6323 char* money_str
= strtok(NULL
, "");
6324 int32 money
= money_str
? atoi(money_str
) : 0;
6328 // msgSubject, msgText isn't NUL after prev. check
6329 std::string subject
= msgSubject
;
6330 std::string text
= msgText
;
6332 // from console show not existed sender
6333 MailSender
sender(MAIL_NORMAL
,m_session
? m_session
->GetPlayer()->GetGUIDLow() : 0, MAIL_STATIONERY_GM
);
6335 uint32 itemTextId
= !text
.empty() ? sObjectMgr
.CreateItemText( text
) : 0;
6337 MailDraft(subject
, itemTextId
)
6339 .SendMailTo(MailReceiver(receiver
,GUID_LOPART(receiver_guid
)),sender
);
6341 std::string nameLink
= playerLink(receiver_name
);
6342 PSendSysMessage(LANG_MAIL_SENT
, nameLink
.c_str());
6346 /// Send a message to a player in game
6347 bool ChatHandler::HandleSendMessageCommand(const char* args
)
6349 ///- Find the player
6351 if(!extractPlayerTarget((char*)args
,&rPlayer
))
6354 char* msg_str
= strtok(NULL
, "");
6358 ///- Check that he is not logging out.
6359 if(rPlayer
->GetSession()->isLogingOut())
6361 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6362 SetSentErrorMessage(true);
6366 ///- Send the message
6367 //Use SendAreaTriggerMessage for fastest delivery.
6368 rPlayer
->GetSession()->SendAreaTriggerMessage("%s", msg_str
);
6369 rPlayer
->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
6371 //Confirmation message
6372 std::string nameLink
= GetNameLink(rPlayer
);
6373 PSendSysMessage(LANG_SENDMESSAGE
,nameLink
.c_str(),msg_str
);
6377 bool ChatHandler::HandleFlushArenaPointsCommand(const char * /*args*/)
6379 sBattleGroundMgr
.DistributeArenaPoints();
6383 bool ChatHandler::HandleModifyGenderCommand(const char *args
)
6388 Player
*player
= getSelectedPlayer();
6392 PSendSysMessage(LANG_PLAYER_NOT_FOUND
);
6393 SetSentErrorMessage(true);
6397 PlayerInfo
const* info
= sObjectMgr
.GetPlayerInfo(player
->getRace(), player
->getClass());
6401 char const* gender_str
= (char*)args
;
6402 int gender_len
= strlen(gender_str
);
6406 if(!strncmp(gender_str
, "male", gender_len
)) // MALE
6408 if(player
->getGender() == GENDER_MALE
)
6411 gender
= GENDER_MALE
;
6413 else if (!strncmp(gender_str
, "female", gender_len
)) // FEMALE
6415 if(player
->getGender() == GENDER_FEMALE
)
6418 gender
= GENDER_FEMALE
;
6422 SendSysMessage(LANG_MUST_MALE_OR_FEMALE
);
6423 SetSentErrorMessage(true);
6428 player
->SetByteValue(UNIT_FIELD_BYTES_0
, 2, gender
);
6429 player
->SetByteValue(PLAYER_BYTES_3
, 0, gender
);
6431 // Change display ID
6432 player
->InitDisplayIds();
6434 char const* gender_full
= gender
? "female" : "male";
6436 PSendSysMessage(LANG_YOU_CHANGE_GENDER
, GetNameLink(player
).c_str(), gender_full
);
6438 if (needReportToTarget(player
))
6439 ChatHandler(player
).PSendSysMessage(LANG_YOUR_GENDER_CHANGED
, gender_full
, GetNameLink().c_str());