2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
24 #include "ObjectMgr.h"
25 #include "AccountMgr.h"
26 #include "PlayerDump.h"
30 #include "GameObject.h"
34 #include "ObjectAccessor.h"
35 #include "MapManager.h"
36 #include "ScriptCalls.h"
38 #include "GridNotifiersImpl.h"
41 #include "PointMovementGenerator.h"
42 #include "TargetedMovementGenerator.h"
43 #include "SkillDiscovery.h"
44 #include "SkillExtraItems.h"
45 #include "SystemConfig.h"
46 #include "Config/ConfigEnv.h"
48 #include "ItemEnchantmentMgr.h"
49 #include "BattleGroundMgr.h"
50 #include "InstanceSaveMgr.h"
51 #include "InstanceData.h"
52 #include "CreatureEventAIMgr.h"
56 bool ChatHandler::HandleReloadAllCommand(const char*)
58 HandleReloadSkillFishingBaseLevelCommand("");
60 HandleReloadAllAchievementCommand("");
61 HandleReloadAllAreaCommand("");
62 HandleReloadAllEventAICommand("");
63 HandleReloadAllLootCommand("");
64 HandleReloadAllNpcCommand("");
65 HandleReloadAllQuestCommand("");
66 HandleReloadAllSpellCommand("");
67 HandleReloadAllItemCommand("");
68 HandleReloadAllLocalesCommand("");
70 HandleReloadCommandCommand("");
71 HandleReloadReservedNameCommand("");
72 HandleReloadMangosStringCommand("");
73 HandleReloadGameTeleCommand("");
77 bool ChatHandler::HandleReloadAllAchievementCommand(const char*)
79 HandleReloadAchievementCriteriaDataCommand("");
80 HandleReloadAchievementRewardCommand("");
84 bool ChatHandler::HandleReloadAllAreaCommand(const char*)
86 //HandleReloadQuestAreaTriggersCommand(""); -- reloaded in HandleReloadAllQuestCommand
87 HandleReloadAreaTriggerTeleportCommand("");
88 HandleReloadAreaTriggerTavernCommand("");
89 HandleReloadGameGraveyardZoneCommand("");
93 bool ChatHandler::HandleReloadAllLootCommand(const char*)
95 sLog
.outString( "Re-Loading Loot Tables..." );
97 SendGlobalSysMessage("DB tables `*_loot_template` reloaded.");
101 bool ChatHandler::HandleReloadAllNpcCommand(const char* /*args*/)
103 HandleReloadNpcGossipCommand("a");
104 HandleReloadNpcOptionCommand("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 objmgr
.LoadQuestRelations();
119 SendGlobalSysMessage("DB tables `*_questrelation` and `*_involvedrelation` reloaded.");
123 bool ChatHandler::HandleReloadAllScriptsCommand(const char*)
125 if(sWorld
.IsScriptScheduled())
127 PSendSysMessage("DB scripts used currently, please attempt reload later.");
128 SetSentErrorMessage(true);
132 sLog
.outString( "Re-Loading Scripts..." );
133 HandleReloadGameObjectScriptsCommand("a");
134 HandleReloadEventScriptsCommand("a");
135 HandleReloadQuestEndScriptsCommand("a");
136 HandleReloadQuestStartScriptsCommand("a");
137 HandleReloadSpellScriptsCommand("a");
138 SendGlobalSysMessage("DB tables `*_scripts` reloaded.");
139 HandleReloadDbScriptStringCommand("a");
143 bool ChatHandler::HandleReloadAllEventAICommand(const char*)
145 HandleReloadEventAITextsCommand("a");
146 HandleReloadEventAISummonsCommand("a");
147 HandleReloadEventAIScriptsCommand("a");
151 bool ChatHandler::HandleReloadAllSpellCommand(const char*)
153 HandleReloadSkillDiscoveryTemplateCommand("a");
154 HandleReloadSkillExtraItemTemplateCommand("a");
155 HandleReloadSpellAreaCommand("a");
156 HandleReloadSpellChainCommand("a");
157 HandleReloadSpellElixirCommand("a");
158 HandleReloadSpellLearnSpellCommand("a");
159 HandleReloadSpellProcEventCommand("a");
160 HandleReloadSpellBonusesCommand("a");
161 HandleReloadSpellProcItemEnchantCommand("a");
162 HandleReloadSpellScriptTargetCommand("a");
163 HandleReloadSpellTargetPositionCommand("a");
164 HandleReloadSpellThreatsCommand("a");
165 HandleReloadSpellPetAurasCommand("a");
169 bool ChatHandler::HandleReloadAllItemCommand(const char*)
171 HandleReloadPageTextsCommand("a");
172 HandleReloadItemEnchantementsCommand("a");
173 HandleReloadItemRequiredTragetCommand("a");
177 bool ChatHandler::HandleReloadAllLocalesCommand(const char* /*args*/)
179 HandleReloadLocalesAchievementRewardCommand("a");
180 HandleReloadLocalesCreatureCommand("a");
181 HandleReloadLocalesGameobjectCommand("a");
182 HandleReloadLocalesItemCommand("a");
183 HandleReloadLocalesNpcTextCommand("a");
184 HandleReloadLocalesPageTextCommand("a");
185 HandleReloadLocalesPointsOfInterestCommand("a");
186 HandleReloadLocalesQuestCommand("a");
190 bool ChatHandler::HandleReloadConfigCommand(const char* /*args*/)
192 sLog
.outString( "Re-Loading config settings..." );
193 sWorld
.LoadConfigSettings(true);
194 MapManager::Instance().InitializeVisibilityDistanceInfo();
195 SendGlobalSysMessage("World config settings reloaded.");
199 bool ChatHandler::HandleReloadAchievementCriteriaDataCommand(const char*)
201 sLog
.outString( "Re-Loading Additional Achievement Criteria Data..." );
202 achievementmgr
.LoadAchievementCriteriaData();
203 SendGlobalSysMessage("DB table `achievement_criteria_data` reloaded.");
207 bool ChatHandler::HandleReloadAchievementRewardCommand(const char*)
209 sLog
.outString( "Re-Loading Achievement Reward Data..." );
210 achievementmgr
.LoadRewards();
211 SendGlobalSysMessage("DB table `achievement_reward` reloaded.");
215 bool ChatHandler::HandleReloadAreaTriggerTavernCommand(const char*)
217 sLog
.outString( "Re-Loading Tavern Area Triggers..." );
218 objmgr
.LoadTavernAreaTriggers();
219 SendGlobalSysMessage("DB table `areatrigger_tavern` reloaded.");
223 bool ChatHandler::HandleReloadAreaTriggerTeleportCommand(const char*)
225 sLog
.outString( "Re-Loading AreaTrigger teleport definitions..." );
226 objmgr
.LoadAreaTriggerTeleports();
227 SendGlobalSysMessage("DB table `areatrigger_teleport` reloaded.");
231 bool ChatHandler::HandleReloadCommandCommand(const char*)
233 load_command_table
= true;
234 SendGlobalSysMessage("DB table `command` will be reloaded at next chat command use.");
238 bool ChatHandler::HandleReloadCreatureQuestRelationsCommand(const char*)
240 sLog
.outString( "Loading Quests Relations... (`creature_questrelation`)" );
241 objmgr
.LoadCreatureQuestRelations();
242 SendGlobalSysMessage("DB table `creature_questrelation` (creature quest givers) reloaded.");
246 bool ChatHandler::HandleReloadCreatureQuestInvRelationsCommand(const char*)
248 sLog
.outString( "Loading Quests Relations... (`creature_involvedrelation`)" );
249 objmgr
.LoadCreatureInvolvedRelations();
250 SendGlobalSysMessage("DB table `creature_involvedrelation` (creature quest takers) reloaded.");
254 bool ChatHandler::HandleReloadGOQuestRelationsCommand(const char*)
256 sLog
.outString( "Loading Quests Relations... (`gameobject_questrelation`)" );
257 objmgr
.LoadGameobjectQuestRelations();
258 SendGlobalSysMessage("DB table `gameobject_questrelation` (gameobject quest givers) reloaded.");
262 bool ChatHandler::HandleReloadGOQuestInvRelationsCommand(const char*)
264 sLog
.outString( "Loading Quests Relations... (`gameobject_involvedrelation`)" );
265 objmgr
.LoadGameobjectInvolvedRelations();
266 SendGlobalSysMessage("DB table `gameobject_involvedrelation` (gameobject quest takers) reloaded.");
270 bool ChatHandler::HandleReloadQuestAreaTriggersCommand(const char*)
272 sLog
.outString( "Re-Loading Quest Area Triggers..." );
273 objmgr
.LoadQuestAreaTriggers();
274 SendGlobalSysMessage("DB table `areatrigger_involvedrelation` (quest area triggers) reloaded.");
278 bool ChatHandler::HandleReloadQuestTemplateCommand(const char*)
280 sLog
.outString( "Re-Loading Quest Templates..." );
282 SendGlobalSysMessage("DB table `quest_template` (quest definitions) reloaded.");
284 /// dependent also from `gameobject` but this table not reloaded anyway
285 sLog
.outString( "Re-Loading GameObjects for quests..." );
286 objmgr
.LoadGameObjectForQuests();
287 SendGlobalSysMessage("Data GameObjects for quests reloaded.");
291 bool ChatHandler::HandleReloadLootTemplatesCreatureCommand(const char*)
293 sLog
.outString( "Re-Loading Loot Tables... (`creature_loot_template`)" );
294 LoadLootTemplates_Creature();
295 LootTemplates_Creature
.CheckLootRefs();
296 SendGlobalSysMessage("DB table `creature_loot_template` reloaded.");
300 bool ChatHandler::HandleReloadLootTemplatesDisenchantCommand(const char*)
302 sLog
.outString( "Re-Loading Loot Tables... (`disenchant_loot_template`)" );
303 LoadLootTemplates_Disenchant();
304 LootTemplates_Disenchant
.CheckLootRefs();
305 SendGlobalSysMessage("DB table `disenchant_loot_template` reloaded.");
309 bool ChatHandler::HandleReloadLootTemplatesFishingCommand(const char*)
311 sLog
.outString( "Re-Loading Loot Tables... (`fishing_loot_template`)" );
312 LoadLootTemplates_Fishing();
313 LootTemplates_Fishing
.CheckLootRefs();
314 SendGlobalSysMessage("DB table `fishing_loot_template` reloaded.");
318 bool ChatHandler::HandleReloadLootTemplatesGameobjectCommand(const char*)
320 sLog
.outString( "Re-Loading Loot Tables... (`gameobject_loot_template`)" );
321 LoadLootTemplates_Gameobject();
322 LootTemplates_Gameobject
.CheckLootRefs();
323 SendGlobalSysMessage("DB table `gameobject_loot_template` reloaded.");
327 bool ChatHandler::HandleReloadLootTemplatesItemCommand(const char*)
329 sLog
.outString( "Re-Loading Loot Tables... (`item_loot_template`)" );
330 LoadLootTemplates_Item();
331 LootTemplates_Item
.CheckLootRefs();
332 SendGlobalSysMessage("DB table `item_loot_template` reloaded.");
336 bool ChatHandler::HandleReloadLootTemplatesMillingCommand(const char*)
338 sLog
.outString( "Re-Loading Loot Tables... (`milling_loot_template`)" );
339 LoadLootTemplates_Milling();
340 LootTemplates_Milling
.CheckLootRefs();
341 SendGlobalSysMessage("DB table `milling_loot_template` reloaded.");
345 bool ChatHandler::HandleReloadLootTemplatesPickpocketingCommand(const char*)
347 sLog
.outString( "Re-Loading Loot Tables... (`pickpocketing_loot_template`)" );
348 LoadLootTemplates_Pickpocketing();
349 LootTemplates_Pickpocketing
.CheckLootRefs();
350 SendGlobalSysMessage("DB table `pickpocketing_loot_template` reloaded.");
354 bool ChatHandler::HandleReloadLootTemplatesProspectingCommand(const char*)
356 sLog
.outString( "Re-Loading Loot Tables... (`prospecting_loot_template`)" );
357 LoadLootTemplates_Prospecting();
358 LootTemplates_Prospecting
.CheckLootRefs();
359 SendGlobalSysMessage("DB table `prospecting_loot_template` reloaded.");
363 bool ChatHandler::HandleReloadLootTemplatesQuestMailCommand(const char*)
365 sLog
.outString( "Re-Loading Loot Tables... (`quest_mail_loot_template`)" );
366 LoadLootTemplates_QuestMail();
367 LootTemplates_QuestMail
.CheckLootRefs();
368 SendGlobalSysMessage("DB table `quest_mail_loot_template` reloaded.");
372 bool ChatHandler::HandleReloadLootTemplatesReferenceCommand(const char*)
374 sLog
.outString( "Re-Loading Loot Tables... (`reference_loot_template`)" );
375 LoadLootTemplates_Reference();
376 SendGlobalSysMessage("DB table `reference_loot_template` reloaded.");
380 bool ChatHandler::HandleReloadLootTemplatesSkinningCommand(const char*)
382 sLog
.outString( "Re-Loading Loot Tables... (`skinning_loot_template`)" );
383 LoadLootTemplates_Skinning();
384 LootTemplates_Skinning
.CheckLootRefs();
385 SendGlobalSysMessage("DB table `skinning_loot_template` reloaded.");
389 bool ChatHandler::HandleReloadLootTemplatesSpellCommand(const char*)
391 sLog
.outString( "Re-Loading Loot Tables... (`spell_loot_template`)" );
392 LoadLootTemplates_Spell();
393 LootTemplates_Spell
.CheckLootRefs();
394 SendGlobalSysMessage("DB table `spell_loot_template` reloaded.");
398 bool ChatHandler::HandleReloadMangosStringCommand(const char*)
400 sLog
.outString( "Re-Loading mangos_string Table!" );
401 objmgr
.LoadMangosStrings();
402 SendGlobalSysMessage("DB table `mangos_string` reloaded.");
406 bool ChatHandler::HandleReloadNpcOptionCommand(const char*)
408 sLog
.outString( "Re-Loading `npc_option` Table!" );
409 objmgr
.LoadNpcOptions();
410 SendGlobalSysMessage("DB table `npc_option` reloaded.");
414 bool ChatHandler::HandleReloadNpcGossipCommand(const char*)
416 sLog
.outString( "Re-Loading `npc_gossip` Table!" );
417 objmgr
.LoadNpcTextId();
418 SendGlobalSysMessage("DB table `npc_gossip` reloaded.");
422 bool ChatHandler::HandleReloadNpcTrainerCommand(const char*)
424 sLog
.outString( "Re-Loading `npc_trainer` Table!" );
425 objmgr
.LoadTrainerSpell();
426 SendGlobalSysMessage("DB table `npc_trainer` reloaded.");
430 bool ChatHandler::HandleReloadNpcVendorCommand(const char*)
432 sLog
.outString( "Re-Loading `npc_vendor` Table!" );
433 objmgr
.LoadVendors();
434 SendGlobalSysMessage("DB table `npc_vendor` reloaded.");
438 bool ChatHandler::HandleReloadPointsOfInterestCommand(const char*)
440 sLog
.outString( "Re-Loading `points_of_interest` Table!" );
441 objmgr
.LoadPointsOfInterest();
442 SendGlobalSysMessage("DB table `points_of_interest` reloaded.");
446 bool ChatHandler::HandleReloadSpellClickSpellsCommand(const char*)
448 sLog
.outString( "Re-Loading `npc_spellclick_spells` Table!" );
449 objmgr
.LoadNPCSpellClickSpells();
450 SendGlobalSysMessage("DB table `npc_spellclick_spells` reloaded.");
454 bool ChatHandler::HandleReloadReservedNameCommand(const char*)
456 sLog
.outString( "Loading ReservedNames... (`reserved_name`)" );
457 objmgr
.LoadReservedPlayersNames();
458 SendGlobalSysMessage("DB table `reserved_name` (player reserved names) reloaded.");
462 bool ChatHandler::HandleReloadSkillDiscoveryTemplateCommand(const char* /*args*/)
464 sLog
.outString( "Re-Loading Skill Discovery Table..." );
465 LoadSkillDiscoveryTable();
466 SendGlobalSysMessage("DB table `skill_discovery_template` (recipes discovered at crafting) reloaded.");
470 bool ChatHandler::HandleReloadSkillExtraItemTemplateCommand(const char* /*args*/)
472 sLog
.outString( "Re-Loading Skill Extra Item Table..." );
473 LoadSkillExtraItemTable();
474 SendGlobalSysMessage("DB table `skill_extra_item_template` (extra item creation when crafting) reloaded.");
478 bool ChatHandler::HandleReloadSkillFishingBaseLevelCommand(const char* /*args*/)
480 sLog
.outString( "Re-Loading Skill Fishing base level requirements..." );
481 objmgr
.LoadFishingBaseSkillLevel();
482 SendGlobalSysMessage("DB table `skill_fishing_base_level` (fishing base level for zone/subzone) reloaded.");
486 bool ChatHandler::HandleReloadSpellAreaCommand(const char*)
488 sLog
.outString( "Re-Loading SpellArea Data..." );
489 spellmgr
.LoadSpellAreas();
490 SendGlobalSysMessage("DB table `spell_area` (spell dependences from area/quest/auras state) reloaded.");
494 bool ChatHandler::HandleReloadSpellChainCommand(const char*)
496 sLog
.outString( "Re-Loading Spell Chain Data... " );
497 spellmgr
.LoadSpellChains();
498 SendGlobalSysMessage("DB table `spell_chain` (spell ranks) reloaded.");
502 bool ChatHandler::HandleReloadSpellElixirCommand(const char*)
504 sLog
.outString( "Re-Loading Spell Elixir types..." );
505 spellmgr
.LoadSpellElixirs();
506 SendGlobalSysMessage("DB table `spell_elixir` (spell elixir types) reloaded.");
510 bool ChatHandler::HandleReloadSpellLearnSpellCommand(const char*)
512 sLog
.outString( "Re-Loading Spell Learn Spells..." );
513 spellmgr
.LoadSpellLearnSpells();
514 SendGlobalSysMessage("DB table `spell_learn_spell` reloaded.");
518 bool ChatHandler::HandleReloadSpellProcEventCommand(const char*)
520 sLog
.outString( "Re-Loading Spell Proc Event conditions..." );
521 spellmgr
.LoadSpellProcEvents();
522 SendGlobalSysMessage("DB table `spell_proc_event` (spell proc trigger requirements) reloaded.");
526 bool ChatHandler::HandleReloadSpellBonusesCommand(const char*)
528 sLog
.outString( "Re-Loading Spell Bonus Data..." );
529 spellmgr
.LoadSpellBonusess();
530 SendGlobalSysMessage("DB table `spell_bonus_data` (spell damage/healing coefficients) reloaded.");
534 bool ChatHandler::HandleReloadSpellProcItemEnchantCommand(const char*)
536 sLog
.outString( "Re-Loading Spell Proc Item Enchant..." );
537 spellmgr
.LoadSpellProcItemEnchant();
538 SendGlobalSysMessage("DB table `spell_proc_item_enchant` (item enchantment ppm) reloaded.");
542 bool ChatHandler::HandleReloadSpellScriptTargetCommand(const char*)
544 sLog
.outString( "Re-Loading SpellsScriptTarget..." );
545 spellmgr
.LoadSpellScriptTarget();
546 SendGlobalSysMessage("DB table `spell_script_target` (spell targets selection in case specific creature/GO requirements) reloaded.");
550 bool ChatHandler::HandleReloadSpellTargetPositionCommand(const char*)
552 sLog
.outString( "Re-Loading Spell target coordinates..." );
553 spellmgr
.LoadSpellTargetPositions();
554 SendGlobalSysMessage("DB table `spell_target_position` (destination coordinates for spell targets) reloaded.");
558 bool ChatHandler::HandleReloadSpellThreatsCommand(const char*)
560 sLog
.outString( "Re-Loading Aggro Spells Definitions...");
561 spellmgr
.LoadSpellThreats();
562 SendGlobalSysMessage("DB table `spell_threat` (spell aggro definitions) reloaded.");
566 bool ChatHandler::HandleReloadSpellPetAurasCommand(const char*)
568 sLog
.outString( "Re-Loading Spell pet auras...");
569 spellmgr
.LoadSpellPetAuras();
570 SendGlobalSysMessage("DB table `spell_pet_auras` reloaded.");
574 bool ChatHandler::HandleReloadPageTextsCommand(const char*)
576 sLog
.outString( "Re-Loading Page Texts..." );
577 objmgr
.LoadPageTexts();
578 SendGlobalSysMessage("DB table `page_texts` reloaded.");
582 bool ChatHandler::HandleReloadItemEnchantementsCommand(const char*)
584 sLog
.outString( "Re-Loading Item Random Enchantments Table..." );
585 LoadRandomEnchantmentsTable();
586 SendGlobalSysMessage("DB table `item_enchantment_template` reloaded.");
590 bool ChatHandler::HandleReloadItemRequiredTragetCommand(const char*)
592 sLog
.outString( "Re-Loading Item Required Targets Table..." );
593 objmgr
.LoadItemRequiredTarget();
594 SendGlobalSysMessage("DB table `item_required_target` reloaded.");
598 bool ChatHandler::HandleReloadBattleEventCommand(const char*)
600 sLog
.outString( "Re-Loading BattleGround Eventindexes..." );
601 sBattleGroundMgr
.LoadBattleEventIndexes();
602 SendGlobalSysMessage("DB table `gameobject_battleground` and `creature_battleground` reloaded.");
606 bool ChatHandler::HandleReloadGameObjectScriptsCommand(const char* arg
)
608 if(sWorld
.IsScriptScheduled())
610 SendSysMessage("DB scripts used currently, please attempt reload later.");
611 SetSentErrorMessage(true);
616 sLog
.outString( "Re-Loading Scripts from `gameobject_scripts`...");
618 objmgr
.LoadGameObjectScripts();
621 SendGlobalSysMessage("DB table `gameobject_scripts` reloaded.");
626 bool ChatHandler::HandleReloadEventScriptsCommand(const char* arg
)
628 if(sWorld
.IsScriptScheduled())
630 SendSysMessage("DB scripts used currently, please attempt reload later.");
631 SetSentErrorMessage(true);
636 sLog
.outString( "Re-Loading Scripts from `event_scripts`...");
638 objmgr
.LoadEventScripts();
641 SendGlobalSysMessage("DB table `event_scripts` reloaded.");
646 bool ChatHandler::HandleReloadEventAITextsCommand(const char* arg
)
649 sLog
.outString( "Re-Loading Texts from `creature_ai_texts`...");
650 CreatureEAI_Mgr
.LoadCreatureEventAI_Texts();
651 SendGlobalSysMessage("DB table `creature_ai_texts` reloaded.");
655 bool ChatHandler::HandleReloadEventAISummonsCommand(const char* arg
)
657 sLog
.outString( "Re-Loading Summons from `creature_ai_summons`...");
658 CreatureEAI_Mgr
.LoadCreatureEventAI_Summons();
659 SendGlobalSysMessage("DB table `creature_ai_summons` reloaded.");
663 bool ChatHandler::HandleReloadEventAIScriptsCommand(const char* arg
)
665 sLog
.outString( "Re-Loading Scripts from `creature_ai_scripts`...");
666 CreatureEAI_Mgr
.LoadCreatureEventAI_Scripts();
667 SendGlobalSysMessage("DB table `creature_ai_scripts` reloaded.");
671 bool ChatHandler::HandleReloadQuestEndScriptsCommand(const char* arg
)
673 if(sWorld
.IsScriptScheduled())
675 SendSysMessage("DB scripts used currently, please attempt reload later.");
676 SetSentErrorMessage(true);
681 sLog
.outString( "Re-Loading Scripts from `quest_end_scripts`...");
683 objmgr
.LoadQuestEndScripts();
686 SendGlobalSysMessage("DB table `quest_end_scripts` reloaded.");
691 bool ChatHandler::HandleReloadQuestStartScriptsCommand(const char* arg
)
693 if(sWorld
.IsScriptScheduled())
695 SendSysMessage("DB scripts used currently, please attempt reload later.");
696 SetSentErrorMessage(true);
701 sLog
.outString( "Re-Loading Scripts from `quest_start_scripts`...");
703 objmgr
.LoadQuestStartScripts();
706 SendGlobalSysMessage("DB table `quest_start_scripts` reloaded.");
711 bool ChatHandler::HandleReloadSpellScriptsCommand(const char* arg
)
713 if(sWorld
.IsScriptScheduled())
715 SendSysMessage("DB scripts used currently, please attempt reload later.");
716 SetSentErrorMessage(true);
721 sLog
.outString( "Re-Loading Scripts from `spell_scripts`...");
723 objmgr
.LoadSpellScripts();
726 SendGlobalSysMessage("DB table `spell_scripts` reloaded.");
731 bool ChatHandler::HandleReloadDbScriptStringCommand(const char* /*arg*/)
733 sLog
.outString( "Re-Loading Script strings from `db_script_string`...");
734 objmgr
.LoadDbScriptStrings();
735 SendGlobalSysMessage("DB table `db_script_string` reloaded.");
739 bool ChatHandler::HandleReloadGameGraveyardZoneCommand(const char* /*arg*/)
741 sLog
.outString( "Re-Loading Graveyard-zone links...");
743 objmgr
.LoadGraveyardZones();
745 SendGlobalSysMessage("DB table `game_graveyard_zone` reloaded.");
750 bool ChatHandler::HandleReloadGameTeleCommand(const char* /*arg*/)
752 sLog
.outString( "Re-Loading Game Tele coordinates...");
754 objmgr
.LoadGameTele();
756 SendGlobalSysMessage("DB table `game_tele` reloaded.");
761 bool ChatHandler::HandleReloadLocalesAchievementRewardCommand(const char*)
763 sLog
.outString( "Re-Loading Locales Achievement Reward Data..." );
764 achievementmgr
.LoadRewardLocales();
765 SendGlobalSysMessage("DB table `locales_achievement_reward` reloaded.");
769 bool ChatHandler::HandleReloadLocalesCreatureCommand(const char* /*arg*/)
771 sLog
.outString( "Re-Loading Locales Creature ...");
772 objmgr
.LoadCreatureLocales();
773 SendGlobalSysMessage("DB table `locales_creature` reloaded.");
777 bool ChatHandler::HandleReloadLocalesGameobjectCommand(const char* /*arg*/)
779 sLog
.outString( "Re-Loading Locales Gameobject ... ");
780 objmgr
.LoadGameObjectLocales();
781 SendGlobalSysMessage("DB table `locales_gameobject` reloaded.");
785 bool ChatHandler::HandleReloadLocalesItemCommand(const char* /*arg*/)
787 sLog
.outString( "Re-Loading Locales Item ... ");
788 objmgr
.LoadItemLocales();
789 SendGlobalSysMessage("DB table `locales_item` reloaded.");
793 bool ChatHandler::HandleReloadLocalesNpcTextCommand(const char* /*arg*/)
795 sLog
.outString( "Re-Loading Locales NPC Text ... ");
796 objmgr
.LoadNpcTextLocales();
797 SendGlobalSysMessage("DB table `locales_npc_text` reloaded.");
801 bool ChatHandler::HandleReloadLocalesPageTextCommand(const char* /*arg*/)
803 sLog
.outString( "Re-Loading Locales Page Text ... ");
804 objmgr
.LoadPageTextLocales();
805 SendGlobalSysMessage("DB table `locales_page_text` reloaded.");
809 bool ChatHandler::HandleReloadLocalesPointsOfInterestCommand(const char* /*arg*/)
811 sLog
.outString( "Re-Loading Locales Points Of Interest ... ");
812 objmgr
.LoadPointOfInterestLocales();
813 SendGlobalSysMessage("DB table `locales_points_of_interest` reloaded.");
817 bool ChatHandler::HandleReloadLocalesQuestCommand(const char* /*arg*/)
819 sLog
.outString( "Re-Loading Locales Quest ... ");
820 objmgr
.LoadQuestLocales();
821 SendGlobalSysMessage("DB table `locales_quest` reloaded.");
825 bool ChatHandler::HandleLoadScriptsCommand(const char* args
)
827 if(!LoadScriptingModule(args
)) return true;
829 sWorld
.SendWorldText(LANG_SCRIPTS_RELOADED
);
833 bool ChatHandler::HandleAccountSetGmLevelCommand(const char* args
)
835 char* arg1
= strtok((char*)args
, " ");
839 /// must be NULL if targeted syntax and must be not nULL if not targeted
840 char* arg2
= strtok(NULL
, " ");
842 std::string targetAccountName
;
843 uint32 targetAccountId
= 0;
845 /// only target player different from self allowed (if targetPlayer!=NULL then not console)
846 Player
* targetPlayer
= getSelectedPlayer();
847 if(targetPlayer
&& m_session
->GetPlayer()!=targetPlayer
)
849 /// wrong command syntax or unexpected targeting
853 /// security level expected in arg2 after this if.
856 targetAccountId
= targetPlayer
->GetSession()->GetAccountId();
857 accmgr
.GetName(targetAccountId
, targetAccountName
);
861 /// wrong command syntax (second arg expected)
865 targetAccountName
= arg1
;
866 if (!AccountMgr::normalizeString(targetAccountName
))
868 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,targetAccountName
.c_str());
869 SetSentErrorMessage(true);
873 targetAccountId
= accmgr
.GetId(targetAccountName
);
876 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,targetAccountName
.c_str());
877 SetSentErrorMessage(true);
882 int32 gm
= (int32
)atoi(arg2
);
883 if ( gm
< SEC_PLAYER
|| gm
> SEC_ADMINISTRATOR
)
885 SendSysMessage(LANG_BAD_VALUE
);
886 SetSentErrorMessage(true);
890 /// can set security level only for target with less security and to less security that we have
891 /// This will reject self apply by specify account name
892 if(HasLowerSecurityAccount(NULL
,targetAccountId
,true))
895 /// account can't set security to same or grater level, need more power GM or console
896 AccountTypes plSecurity
= m_session
? m_session
->GetSecurity() : SEC_CONSOLE
;
897 if (AccountTypes(gm
) >= plSecurity
)
899 SendSysMessage(LANG_YOURS_SECURITY_IS_LOW
);
900 SetSentErrorMessage(true);
904 // This will prevent self apply by self target or no target
905 if(targetPlayer
&& m_session
->GetPlayer()!=targetPlayer
)
907 ChatHandler(targetPlayer
).PSendSysMessage(LANG_YOURS_SECURITY_CHANGED
,GetNameLink().c_str(), gm
);
908 targetPlayer
->GetSession()->SetSecurity(AccountTypes(gm
));
911 PSendSysMessage(LANG_YOU_CHANGE_SECURITY
, targetAccountName
.c_str(), gm
);
912 loginDatabase
.PExecute("UPDATE account SET gmlevel = '%i' WHERE id = '%u'", gm
, targetAccountId
);
917 /// Set password for account
918 bool ChatHandler::HandleAccountSetPasswordCommand(const char* args
)
923 ///- Get the command line arguments
924 char *szAccount
= strtok ((char*)args
," ");
925 char *szPassword1
= strtok (NULL
," ");
926 char *szPassword2
= strtok (NULL
," ");
928 if (!szAccount
||!szPassword1
|| !szPassword2
)
931 std::string account_name
= szAccount
;
932 if (!AccountMgr::normalizeString(account_name
))
934 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
935 SetSentErrorMessage(true);
939 uint32 targetAccountId
= accmgr
.GetId(account_name
);
940 if (!targetAccountId
)
942 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
943 SetSentErrorMessage(true);
947 /// can set password only for target with less security
948 /// This is also reject self apply in fact
949 if(HasLowerSecurityAccount (NULL
,targetAccountId
,true))
952 if (strcmp(szPassword1
,szPassword2
))
954 SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH
);
955 SetSentErrorMessage (true);
959 AccountOpResult result
= accmgr
.ChangePassword(targetAccountId
, szPassword1
);
964 SendSysMessage(LANG_COMMAND_PASSWORD
);
966 case AOR_NAME_NOT_EXIST
:
967 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
968 SetSentErrorMessage(true);
970 case AOR_PASS_TOO_LONG
:
971 SendSysMessage(LANG_PASSWORD_TOO_LONG
);
972 SetSentErrorMessage(true);
975 SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD
);
976 SetSentErrorMessage(true);
983 bool ChatHandler::HandleMaxSkillCommand(const char* /*args*/)
985 Player
* SelectedPlayer
= getSelectedPlayer();
988 SendSysMessage(LANG_NO_CHAR_SELECTED
);
989 SetSentErrorMessage(true);
993 // each skills that have max skill value dependent from level seted to current level max skill value
994 SelectedPlayer
->UpdateSkillsToMaxSkillsForLevel();
998 bool ChatHandler::HandleSetSkillCommand(const char* args
)
1000 // number or [name] Shift-click form |color|Hskill:skill_id|h[name]|h|r
1001 char* skill_p
= extractKeyFromLink((char*)args
,"Hskill");
1005 char *level_p
= strtok (NULL
, " ");
1010 char *max_p
= strtok (NULL
, " ");
1012 int32 skill
= atoi(skill_p
);
1015 PSendSysMessage(LANG_INVALID_SKILL_ID
, skill
);
1016 SetSentErrorMessage(true);
1020 int32 level
= atol (level_p
);
1022 Player
* target
= getSelectedPlayer();
1025 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1026 SetSentErrorMessage(true);
1030 SkillLineEntry
const* sl
= sSkillLineStore
.LookupEntry(skill
);
1033 PSendSysMessage(LANG_INVALID_SKILL_ID
, skill
);
1034 SetSentErrorMessage(true);
1038 std::string tNameLink
= GetNameLink(target
);
1040 if(!target
->GetSkillValue(skill
))
1042 PSendSysMessage(LANG_SET_SKILL_ERROR
, tNameLink
.c_str(), skill
, sl
->name
[0]);
1043 SetSentErrorMessage(true);
1047 int32 max
= max_p
? atol (max_p
) : target
->GetPureMaxSkillValue(skill
);
1049 if( level
<= 0 || level
> max
|| max
<= 0 )
1052 target
->SetSkill(skill
, level
, max
);
1053 PSendSysMessage(LANG_SET_SKILL
, skill
, sl
->name
[0], tNameLink
.c_str(), level
, max
);
1058 bool ChatHandler::HandleUnLearnCommand(const char* args
)
1063 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
1064 uint32 spell_id
= extractSpellIdFromLink((char*)args
);
1068 char const* allStr
= strtok(NULL
," ");
1069 bool allRanks
= allStr
? (strncmp(allStr
, "all", strlen(allStr
)) == 0) : false;
1071 Player
* target
= getSelectedPlayer();
1074 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1075 SetSentErrorMessage(true);
1080 spell_id
= spellmgr
.GetFirstSpellInChain (spell_id
);
1082 if (target
->HasSpell(spell_id
))
1083 target
->removeSpell(spell_id
,false,!allRanks
);
1085 SendSysMessage(LANG_FORGET_SPELL
);
1087 if(GetTalentSpellCost(spell_id
))
1088 target
->SendTalentsInfoData(false);
1093 bool ChatHandler::HandleCooldownCommand(const char* args
)
1095 Player
* target
= getSelectedPlayer();
1098 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1099 SetSentErrorMessage(true);
1103 std::string tNameLink
= GetNameLink(target
);
1107 target
->RemoveAllSpellCooldown();
1108 PSendSysMessage(LANG_REMOVEALL_COOLDOWN
, tNameLink
.c_str());
1112 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1113 uint32 spell_id
= extractSpellIdFromLink((char*)args
);
1117 if(!sSpellStore
.LookupEntry(spell_id
))
1119 PSendSysMessage(LANG_UNKNOWN_SPELL
, target
==m_session
->GetPlayer() ? GetMangosString(LANG_YOU
) : tNameLink
.c_str());
1120 SetSentErrorMessage(true);
1124 target
->RemoveSpellCooldown(spell_id
,true);
1125 PSendSysMessage(LANG_REMOVE_COOLDOWN
, spell_id
, target
==m_session
->GetPlayer() ? GetMangosString(LANG_YOU
) : tNameLink
.c_str());
1130 bool ChatHandler::HandleLearnAllCommand(const char* /*args*/)
1132 static const char *allSpellList
[] =
1515 //"9036", problems with ghost state
1524 //"6718", phasing stealth, annoying for learn all case.
1737 while(strcmp(allSpellList
[loop
], "0"))
1739 uint32 spell
= atol((char*)allSpellList
[loop
++]);
1741 if (m_session
->GetPlayer()->HasSpell(spell
))
1744 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1745 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1747 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1751 m_session
->GetPlayer()->learnSpell(spell
,false);
1754 SendSysMessage(LANG_COMMAND_LEARN_MANY_SPELLS
);
1759 bool ChatHandler::HandleLearnAllGMCommand(const char* /*args*/)
1761 static const char *gmSpellList
[] =
1763 "24347", // Become A Fish, No Breath Bar
1764 "35132", // Visual Boom
1765 "38488", // Attack 4000-8000 AOE
1766 "38795", // Attack 2000 AOE + Slow Down 90%
1767 "15712", // Attack 200
1768 "1852", // GM Spell Silence
1771 "29878", // Kill My Self
1772 "26644", // More Kill
1774 "28550", //Invisible 24
1775 "23452", //Invisible + Target
1779 uint16 gmSpellIter
= 0;
1780 while( strcmp(gmSpellList
[gmSpellIter
], "0") )
1782 uint32 spell
= atol((char*)gmSpellList
[gmSpellIter
++]);
1784 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1785 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1787 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1791 m_session
->GetPlayer()->learnSpell(spell
,false);
1794 SendSysMessage(LANG_LEARNING_GM_SKILLS
);
1798 bool ChatHandler::HandleLearnAllMyClassCommand(const char* /*args*/)
1800 HandleLearnAllMySpellsCommand("");
1801 HandleLearnAllMyTalentsCommand("");
1805 bool ChatHandler::HandleLearnAllMySpellsCommand(const char* /*args*/)
1807 ChrClassesEntry
const* clsEntry
= sChrClassesStore
.LookupEntry(m_session
->GetPlayer()->getClass());
1810 uint32 family
= clsEntry
->spellfamily
;
1812 for (uint32 i
= 0; i
< sSpellStore
.GetNumRows(); ++i
)
1814 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(i
);
1818 // skip server-side/triggered spells
1819 if(spellInfo
->spellLevel
==0)
1822 // skip wrong class/race skills
1823 if(!m_session
->GetPlayer()->IsSpellFitByClassAndRace(spellInfo
->Id
))
1826 // skip other spell families
1827 if( spellInfo
->SpellFamilyName
!= family
)
1830 // skip spells with first rank learned as talent (and all talents then also)
1831 uint32 first_rank
= spellmgr
.GetFirstSpellInChain(spellInfo
->Id
);
1832 if(GetTalentSpellCost(first_rank
) > 0 )
1835 // skip broken spells
1836 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1839 m_session
->GetPlayer()->learnSpell(i
,false);
1842 SendSysMessage(LANG_COMMAND_LEARN_CLASS_SPELLS
);
1846 bool ChatHandler::HandleLearnAllMyTalentsCommand(const char* /*args*/)
1848 Player
* player
= m_session
->GetPlayer();
1849 uint32 classMask
= player
->getClassMask();
1851 for (uint32 i
= 0; i
< sTalentStore
.GetNumRows(); ++i
)
1853 TalentEntry
const *talentInfo
= sTalentStore
.LookupEntry(i
);
1857 TalentTabEntry
const *talentTabInfo
= sTalentTabStore
.LookupEntry( talentInfo
->TalentTab
);
1861 if( (classMask
& talentTabInfo
->ClassMask
) == 0 )
1864 // search highest talent rank
1867 for(int rank
= MAX_TALENT_RANK
-1; rank
>= 0; --rank
)
1869 if(talentInfo
->RankID
[rank
]!=0)
1871 spellid
= talentInfo
->RankID
[rank
];
1876 if(!spellid
) // ??? none spells in talent
1879 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spellid
);
1880 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1883 // learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
1884 player
->learnSpellHighRank(spellid
);
1887 SendSysMessage(LANG_COMMAND_LEARN_CLASS_TALENTS
);
1891 bool ChatHandler::HandleLearnAllMyPetTalentsCommand(const char* /*args*/)
1893 Player
* player
= m_session
->GetPlayer();
1895 Pet
* pet
= player
->GetPet();
1898 SendSysMessage(LANG_NO_PET_FOUND
);
1899 SetSentErrorMessage(true);
1903 CreatureInfo
const *ci
= pet
->GetCreatureInfo();
1906 SendSysMessage(LANG_WRONG_PET_TYPE
);
1907 SetSentErrorMessage(true);
1911 CreatureFamilyEntry
const *pet_family
= sCreatureFamilyStore
.LookupEntry(ci
->family
);
1914 SendSysMessage(LANG_WRONG_PET_TYPE
);
1915 SetSentErrorMessage(true);
1919 if(pet_family
->petTalentType
< 0) // not hunter pet
1921 SendSysMessage(LANG_WRONG_PET_TYPE
);
1922 SetSentErrorMessage(true);
1926 for (uint32 i
= 0; i
< sTalentStore
.GetNumRows(); ++i
)
1928 TalentEntry
const *talentInfo
= sTalentStore
.LookupEntry(i
);
1932 TalentTabEntry
const *talentTabInfo
= sTalentTabStore
.LookupEntry( talentInfo
->TalentTab
);
1936 // prevent learn talent for different family (cheating)
1937 if(((1 << pet_family
->petTalentType
) & talentTabInfo
->petTalentMask
)==0)
1940 // search highest talent rank
1943 for(int rank
= MAX_TALENT_RANK
-1; rank
>= 0; --rank
)
1945 if(talentInfo
->RankID
[rank
]!=0)
1947 spellid
= talentInfo
->RankID
[rank
];
1952 if(!spellid
) // ??? none spells in talent
1955 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spellid
);
1956 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1959 // learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
1960 pet
->learnSpellHighRank(spellid
);
1963 SendSysMessage(LANG_COMMAND_LEARN_PET_TALENTS
);
1967 bool ChatHandler::HandleLearnAllLangCommand(const char* /*args*/)
1969 // skipping UNIVERSAL language (0)
1970 for(int i
= 1; i
< LANGUAGES_COUNT
; ++i
)
1971 m_session
->GetPlayer()->learnSpell(lang_description
[i
].spell_id
,false);
1973 SendSysMessage(LANG_COMMAND_LEARN_ALL_LANG
);
1977 bool ChatHandler::HandleLearnAllDefaultCommand(const char* args
)
1980 if(!extractPlayerTarget((char*)args
,&target
))
1983 target
->learnDefaultSpells();
1984 target
->learnQuestRewardedSpells();
1986 PSendSysMessage(LANG_COMMAND_LEARN_ALL_DEFAULT_AND_QUEST
,GetNameLink(target
).c_str());
1990 bool ChatHandler::HandleLearnCommand(const char* args
)
1992 Player
* targetPlayer
= getSelectedPlayer();
1996 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1997 SetSentErrorMessage(true);
2001 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
2002 uint32 spell
= extractSpellIdFromLink((char*)args
);
2003 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
2006 char const* allStr
= strtok(NULL
," ");
2007 bool allRanks
= allStr
? (strncmp(allStr
, "all", strlen(allStr
)) == 0) : false;
2009 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
2010 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
2012 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
2013 SetSentErrorMessage(true);
2017 if (!allRanks
&& targetPlayer
->HasSpell(spell
))
2019 if(targetPlayer
== m_session
->GetPlayer())
2020 SendSysMessage(LANG_YOU_KNOWN_SPELL
);
2022 PSendSysMessage(LANG_TARGET_KNOWN_SPELL
,GetNameLink(targetPlayer
).c_str());
2023 SetSentErrorMessage(true);
2028 targetPlayer
->learnSpellHighRank(spell
);
2030 targetPlayer
->learnSpell(spell
,false);
2032 uint32 first_spell
= spellmgr
.GetFirstSpellInChain(spell
);
2033 if(GetTalentSpellCost(first_spell
))
2034 targetPlayer
->SendTalentsInfoData(false);
2039 bool ChatHandler::HandleAddItemCommand(const char* args
)
2046 if(args
[0]=='[') // [name] manual form
2048 char* citemName
= strtok((char*)args
, "]");
2050 if(citemName
&& citemName
[0])
2052 std::string itemName
= citemName
+1;
2053 WorldDatabase
.escape_string(itemName
);
2054 QueryResult
*result
= WorldDatabase
.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName
.c_str());
2057 PSendSysMessage(LANG_COMMAND_COULDNOTFIND
, citemName
+1);
2058 SetSentErrorMessage(true);
2061 itemId
= result
->Fetch()->GetUInt16();
2067 else // item_id or [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r
2069 char* cId
= extractKeyFromLink((char*)args
,"Hitem");
2075 char* ccount
= strtok(NULL
, " ");
2080 count
= strtol(ccount
, NULL
, 10);
2085 Player
* pl
= m_session
->GetPlayer();
2086 Player
* plTarget
= getSelectedPlayer();
2090 sLog
.outDetail(GetMangosString(LANG_ADDITEM
), itemId
, count
);
2092 ItemPrototype
const *pProto
= objmgr
.GetItemPrototype(itemId
);
2095 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, itemId
);
2096 SetSentErrorMessage(true);
2103 plTarget
->DestroyItemCount(itemId
, -count
, true, false);
2104 PSendSysMessage(LANG_REMOVEITEM
, itemId
, -count
, GetNameLink(plTarget
).c_str());
2109 uint32 noSpaceForCount
= 0;
2111 // check space and find places
2112 ItemPosCountVec dest
;
2113 uint8 msg
= plTarget
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, itemId
, count
, &noSpaceForCount
);
2114 if( msg
!= EQUIP_ERR_OK
) // convert to possible store amount
2115 count
-= noSpaceForCount
;
2117 if( count
== 0 || dest
.empty()) // can't add any
2119 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, itemId
, noSpaceForCount
);
2120 SetSentErrorMessage(true);
2124 Item
* item
= plTarget
->StoreNewItem( dest
, itemId
, true, Item::GenerateItemRandomPropertyId(itemId
));
2126 // remove binding (let GM give it to another player later)
2128 for(ItemPosCountVec::const_iterator itr
= dest
.begin(); itr
!= dest
.end(); ++itr
)
2129 if(Item
* item1
= pl
->GetItemByPos(itr
->pos
))
2130 item1
->SetBinding( false );
2132 if(count
> 0 && item
)
2134 pl
->SendNewItem(item
,count
,false,true);
2136 plTarget
->SendNewItem(item
,count
,true,false);
2139 if(noSpaceForCount
> 0)
2140 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, itemId
, noSpaceForCount
);
2145 bool ChatHandler::HandleAddItemSetCommand(const char* args
)
2150 char* cId
= extractKeyFromLink((char*)args
,"Hitemset"); // number or [name] Shift-click form |color|Hitemset:itemset_id|h[name]|h|r
2154 uint32 itemsetId
= atol(cId
);
2156 // prevent generation all items with itemset field value '0'
2159 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND
,itemsetId
);
2160 SetSentErrorMessage(true);
2164 Player
* pl
= m_session
->GetPlayer();
2165 Player
* plTarget
= getSelectedPlayer();
2169 sLog
.outDetail(GetMangosString(LANG_ADDITEMSET
), itemsetId
);
2172 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
2174 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
2178 if (pProto
->ItemSet
== itemsetId
)
2181 ItemPosCountVec dest
;
2182 uint8 msg
= plTarget
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, pProto
->ItemId
, 1 );
2183 if (msg
== EQUIP_ERR_OK
)
2185 Item
* item
= plTarget
->StoreNewItem( dest
, pProto
->ItemId
, true);
2187 // remove binding (let GM give it to another player later)
2189 item
->SetBinding( false );
2191 pl
->SendNewItem(item
,1,false,true);
2193 plTarget
->SendNewItem(item
,1,true,false);
2197 pl
->SendEquipError( msg
, NULL
, NULL
);
2198 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, pProto
->ItemId
, 1);
2205 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND
,itemsetId
);
2207 SetSentErrorMessage(true);
2214 bool ChatHandler::HandleListItemCommand(const char* args
)
2219 char* cId
= extractKeyFromLink((char*)args
,"Hitem");
2223 uint32 item_id
= atol(cId
);
2226 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
2227 SetSentErrorMessage(true);
2231 ItemPrototype
const* itemProto
= objmgr
.GetItemPrototype(item_id
);
2234 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
2235 SetSentErrorMessage(true);
2239 char* c_count
= strtok(NULL
, " ");
2240 int count
= c_count
? atol(c_count
) : 10;
2245 QueryResult
*result
;
2248 uint32 inv_count
= 0;
2249 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM character_inventory WHERE item_template='%u'",item_id
);
2252 inv_count
= (*result
)[0].GetUInt32();
2256 result
=CharacterDatabase
.PQuery(
2258 "SELECT ci.item, cibag.slot AS bag, ci.slot, ci.guid, characters.account,characters.name "
2259 "FROM character_inventory AS ci LEFT JOIN character_inventory AS cibag ON (cibag.item=ci.bag),characters "
2260 "WHERE ci.item_template='%u' AND ci.guid = characters.guid LIMIT %u ",
2261 item_id
,uint32(count
));
2267 Field
*fields
= result
->Fetch();
2268 uint32 item_guid
= fields
[0].GetUInt32();
2269 uint32 item_bag
= fields
[1].GetUInt32();
2270 uint32 item_slot
= fields
[2].GetUInt32();
2271 uint32 owner_guid
= fields
[3].GetUInt32();
2272 uint32 owner_acc
= fields
[4].GetUInt32();
2273 std::string owner_name
= fields
[5].GetCppString();
2275 char const* item_pos
= 0;
2276 if(Player::IsEquipmentPos(item_bag
,item_slot
))
2277 item_pos
= "[equipped]";
2278 else if(Player::IsInventoryPos(item_bag
,item_slot
))
2279 item_pos
= "[in inventory]";
2280 else if(Player::IsBankPos(item_bag
,item_slot
))
2281 item_pos
= "[in bank]";
2285 PSendSysMessage(LANG_ITEMLIST_SLOT
,
2286 item_guid
,owner_name
.c_str(),owner_guid
,owner_acc
,item_pos
);
2287 } while (result
->NextRow());
2289 int64 res_count
= result
->GetRowCount();
2293 if(count
> res_count
)
2300 uint32 mail_count
= 0;
2301 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM mail_items WHERE item_template='%u'", item_id
);
2304 mail_count
= (*result
)[0].GetUInt32();
2310 result
=CharacterDatabase
.PQuery(
2312 "SELECT mail_items.item_guid, mail.sender, mail.receiver, char_s.account, char_s.name, char_r.account, char_r.name "
2313 "FROM mail,mail_items,characters as char_s,characters as char_r "
2314 "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",
2315 item_id
,uint32(count
));
2324 Field
*fields
= result
->Fetch();
2325 uint32 item_guid
= fields
[0].GetUInt32();
2326 uint32 item_s
= fields
[1].GetUInt32();
2327 uint32 item_r
= fields
[2].GetUInt32();
2328 uint32 item_s_acc
= fields
[3].GetUInt32();
2329 std::string item_s_name
= fields
[4].GetCppString();
2330 uint32 item_r_acc
= fields
[5].GetUInt32();
2331 std::string item_r_name
= fields
[6].GetCppString();
2333 char const* item_pos
= "[in mail]";
2335 PSendSysMessage(LANG_ITEMLIST_MAIL
,
2336 item_guid
,item_s_name
.c_str(),item_s
,item_s_acc
,item_r_name
.c_str(),item_r
,item_r_acc
,item_pos
);
2337 } while (result
->NextRow());
2339 int64 res_count
= result
->GetRowCount();
2343 if(count
> res_count
)
2350 uint32 auc_count
= 0;
2351 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM auctionhouse WHERE item_template='%u'",item_id
);
2354 auc_count
= (*result
)[0].GetUInt32();
2360 result
=CharacterDatabase
.PQuery(
2362 "SELECT auctionhouse.itemguid, auctionhouse.itemowner, characters.account, characters.name "
2363 "FROM auctionhouse,characters WHERE auctionhouse.item_template='%u' AND characters.guid = auctionhouse.itemowner LIMIT %u",
2364 item_id
,uint32(count
));
2373 Field
*fields
= result
->Fetch();
2374 uint32 item_guid
= fields
[0].GetUInt32();
2375 uint32 owner
= fields
[1].GetUInt32();
2376 uint32 owner_acc
= fields
[2].GetUInt32();
2377 std::string owner_name
= fields
[3].GetCppString();
2379 char const* item_pos
= "[in auction]";
2381 PSendSysMessage(LANG_ITEMLIST_AUCTION
, item_guid
, owner_name
.c_str(), owner
, owner_acc
,item_pos
);
2382 } while (result
->NextRow());
2388 uint32 guild_count
= 0;
2389 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_entry) FROM guild_bank_item WHERE item_entry='%u'",item_id
);
2392 guild_count
= (*result
)[0].GetUInt32();
2396 result
=CharacterDatabase
.PQuery(
2398 "SELECT gi.item_guid, gi.guildid, guild.name "
2399 "FROM guild_bank_item AS gi, guild WHERE gi.item_entry='%u' AND gi.guildid = guild.guildid LIMIT %u ",
2400 item_id
,uint32(count
));
2406 Field
*fields
= result
->Fetch();
2407 uint32 item_guid
= fields
[0].GetUInt32();
2408 uint32 guild_guid
= fields
[1].GetUInt32();
2409 std::string guild_name
= fields
[2].GetCppString();
2411 char const* item_pos
= "[in guild bank]";
2413 PSendSysMessage(LANG_ITEMLIST_GUILD
,item_guid
,guild_name
.c_str(),guild_guid
,item_pos
);
2414 } while (result
->NextRow());
2416 int64 res_count
= result
->GetRowCount();
2420 if(count
> res_count
)
2426 if(inv_count
+mail_count
+auc_count
+guild_count
== 0)
2428 SendSysMessage(LANG_COMMAND_NOITEMFOUND
);
2429 SetSentErrorMessage(true);
2433 PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE
,item_id
,inv_count
+mail_count
+auc_count
+guild_count
,inv_count
,mail_count
,auc_count
,guild_count
);
2438 bool ChatHandler::HandleListObjectCommand(const char* args
)
2443 // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2444 char* cId
= extractKeyFromLink((char*)args
,"Hgameobject_entry");
2448 uint32 go_id
= atol(cId
);
2451 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID
, go_id
);
2452 SetSentErrorMessage(true);
2456 GameObjectInfo
const * gInfo
= objmgr
.GetGameObjectInfo(go_id
);
2459 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID
, go_id
);
2460 SetSentErrorMessage(true);
2464 char* c_count
= strtok(NULL
, " ");
2465 int count
= c_count
? atol(c_count
) : 10;
2470 QueryResult
*result
;
2472 uint32 obj_count
= 0;
2473 result
=WorldDatabase
.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'",go_id
);
2476 obj_count
= (*result
)[0].GetUInt32();
2482 Player
* pl
= m_session
->GetPlayer();
2483 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",
2484 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(),go_id
,uint32(count
));
2487 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map FROM gameobject WHERE id = '%u' LIMIT %u",
2488 go_id
,uint32(count
));
2494 Field
*fields
= result
->Fetch();
2495 uint32 guid
= fields
[0].GetUInt32();
2496 float x
= fields
[1].GetFloat();
2497 float y
= fields
[2].GetFloat();
2498 float z
= fields
[3].GetFloat();
2499 int mapid
= fields
[4].GetUInt16();
2502 PSendSysMessage(LANG_GO_LIST_CHAT
, guid
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2504 PSendSysMessage(LANG_GO_LIST_CONSOLE
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2505 } while (result
->NextRow());
2510 PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE
,go_id
,obj_count
);
2514 bool ChatHandler::HandleListCreatureCommand(const char* args
)
2519 // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
2520 char* cId
= extractKeyFromLink((char*)args
,"Hcreature_entry");
2524 uint32 cr_id
= atol(cId
);
2527 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID
, cr_id
);
2528 SetSentErrorMessage(true);
2532 CreatureInfo
const* cInfo
= objmgr
.GetCreatureTemplate(cr_id
);
2535 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID
, cr_id
);
2536 SetSentErrorMessage(true);
2540 char* c_count
= strtok(NULL
, " ");
2541 int count
= c_count
? atol(c_count
) : 10;
2546 QueryResult
*result
;
2548 uint32 cr_count
= 0;
2549 result
=WorldDatabase
.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'",cr_id
);
2552 cr_count
= (*result
)[0].GetUInt32();
2558 Player
* pl
= m_session
->GetPlayer();
2559 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",
2560 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(), cr_id
,uint32(count
));
2563 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '%u' LIMIT %u",
2564 cr_id
,uint32(count
));
2570 Field
*fields
= result
->Fetch();
2571 uint32 guid
= fields
[0].GetUInt32();
2572 float x
= fields
[1].GetFloat();
2573 float y
= fields
[2].GetFloat();
2574 float z
= fields
[3].GetFloat();
2575 int mapid
= fields
[4].GetUInt16();
2578 PSendSysMessage(LANG_CREATURE_LIST_CHAT
, guid
, guid
, cInfo
->Name
, x
, y
, z
, mapid
);
2580 PSendSysMessage(LANG_CREATURE_LIST_CONSOLE
, guid
, cInfo
->Name
, x
, y
, z
, mapid
);
2581 } while (result
->NextRow());
2586 PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE
,cr_id
,cr_count
);
2590 bool ChatHandler::HandleLookupItemCommand(const char* args
)
2595 std::string namepart
= args
;
2596 std::wstring wnamepart
;
2598 // converting string that we try to find to lower case
2599 if(!Utf8toWStr(namepart
,wnamepart
))
2602 wstrToLower(wnamepart
);
2606 // Search in `item_template`
2607 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
2609 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
2613 int loc_idx
= GetSessionDbLocaleIndex();
2616 ItemLocale
const *il
= objmgr
.GetItemLocale(pProto
->ItemId
);
2619 if (il
->Name
.size() > loc_idx
&& !il
->Name
[loc_idx
].empty())
2621 std::string name
= il
->Name
[loc_idx
];
2623 if (Utf8FitTo(name
, wnamepart
))
2626 PSendSysMessage(LANG_ITEM_LIST_CHAT
, id
, id
, name
.c_str());
2628 PSendSysMessage(LANG_ITEM_LIST_CONSOLE
, id
, name
.c_str());
2636 std::string name
= pProto
->Name1
;
2640 if (Utf8FitTo(name
, wnamepart
))
2643 PSendSysMessage(LANG_ITEM_LIST_CHAT
, id
, id
, name
.c_str());
2645 PSendSysMessage(LANG_ITEM_LIST_CONSOLE
, id
, name
.c_str());
2651 SendSysMessage(LANG_COMMAND_NOITEMFOUND
);
2656 bool ChatHandler::HandleLookupItemSetCommand(const char* args
)
2661 std::string namepart
= args
;
2662 std::wstring wnamepart
;
2664 if(!Utf8toWStr(namepart
,wnamepart
))
2667 // converting string that we try to find to lower case
2668 wstrToLower( wnamepart
);
2670 uint32 counter
= 0; // Counter for figure out that we found smth.
2672 // Search in ItemSet.dbc
2673 for (uint32 id
= 0; id
< sItemSetStore
.GetNumRows(); id
++)
2675 ItemSetEntry
const *set
= sItemSetStore
.LookupEntry(id
);
2678 int loc
= GetSessionDbcLocale();
2679 std::string name
= set
->name
[loc
];
2683 if (!Utf8FitTo(name
, wnamepart
))
2686 for(; loc
< MAX_LOCALE
; ++loc
)
2688 if(loc
==GetSessionDbcLocale())
2691 name
= set
->name
[loc
];
2695 if (Utf8FitTo(name
, wnamepart
))
2700 if(loc
< MAX_LOCALE
)
2702 // send item set in "id - [namedlink locale]" format
2704 PSendSysMessage(LANG_ITEMSET_LIST_CHAT
,id
,id
,name
.c_str(),localeNames
[loc
]);
2706 PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE
,id
,name
.c_str(),localeNames
[loc
]);
2711 if (counter
== 0) // if counter == 0 then we found nth
2712 SendSysMessage(LANG_COMMAND_NOITEMSETFOUND
);
2716 bool ChatHandler::HandleLookupSkillCommand(const char* args
)
2721 // can be NULL in console call
2722 Player
* target
= getSelectedPlayer();
2724 std::string namepart
= args
;
2725 std::wstring wnamepart
;
2727 if(!Utf8toWStr(namepart
,wnamepart
))
2730 // converting string that we try to find to lower case
2731 wstrToLower( wnamepart
);
2733 uint32 counter
= 0; // Counter for figure out that we found smth.
2735 // Search in SkillLine.dbc
2736 for (uint32 id
= 0; id
< sSkillLineStore
.GetNumRows(); id
++)
2738 SkillLineEntry
const *skillInfo
= sSkillLineStore
.LookupEntry(id
);
2741 int loc
= GetSessionDbcLocale();
2742 std::string name
= skillInfo
->name
[loc
];
2746 if (!Utf8FitTo(name
, wnamepart
))
2749 for(; loc
< MAX_LOCALE
; ++loc
)
2751 if(loc
==GetSessionDbcLocale())
2754 name
= skillInfo
->name
[loc
];
2758 if (Utf8FitTo(name
, wnamepart
))
2763 if(loc
< MAX_LOCALE
)
2765 char valStr
[50] = "";
2766 char const* knownStr
= "";
2767 if(target
&& target
->HasSkill(id
))
2769 knownStr
= GetMangosString(LANG_KNOWN
);
2770 uint32 curValue
= target
->GetPureSkillValue(id
);
2771 uint32 maxValue
= target
->GetPureMaxSkillValue(id
);
2772 uint32 permValue
= target
->GetSkillPermBonusValue(id
);
2773 uint32 tempValue
= target
->GetSkillTempBonusValue(id
);
2775 char const* valFormat
= GetMangosString(LANG_SKILL_VALUES
);
2776 snprintf(valStr
,50,valFormat
,curValue
,maxValue
,permValue
,tempValue
);
2779 // send skill in "id - [namedlink locale]" format
2781 PSendSysMessage(LANG_SKILL_LIST_CHAT
,id
,id
,name
.c_str(),localeNames
[loc
],knownStr
,valStr
);
2783 PSendSysMessage(LANG_SKILL_LIST_CONSOLE
,id
,name
.c_str(),localeNames
[loc
],knownStr
,valStr
);
2789 if (counter
== 0) // if counter == 0 then we found nth
2790 SendSysMessage(LANG_COMMAND_NOSKILLFOUND
);
2794 bool ChatHandler::HandleLookupSpellCommand(const char* args
)
2799 // can be NULL at console call
2800 Player
* target
= getSelectedPlayer();
2802 std::string namepart
= args
;
2803 std::wstring wnamepart
;
2805 if(!Utf8toWStr(namepart
,wnamepart
))
2808 // converting string that we try to find to lower case
2809 wstrToLower( wnamepart
);
2811 uint32 counter
= 0; // Counter for figure out that we found smth.
2813 // Search in Spell.dbc
2814 for (uint32 id
= 0; id
< sSpellStore
.GetNumRows(); id
++)
2816 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(id
);
2819 int loc
= GetSessionDbcLocale();
2820 std::string name
= spellInfo
->SpellName
[loc
];
2824 if (!Utf8FitTo(name
, wnamepart
))
2827 for(; loc
< MAX_LOCALE
; ++loc
)
2829 if(loc
==GetSessionDbcLocale())
2832 name
= spellInfo
->SpellName
[loc
];
2836 if (Utf8FitTo(name
, wnamepart
))
2841 if(loc
< MAX_LOCALE
)
2843 bool known
= target
&& target
->HasSpell(id
);
2844 bool learn
= (spellInfo
->Effect
[0] == SPELL_EFFECT_LEARN_SPELL
);
2846 uint32 talentCost
= GetTalentSpellCost(id
);
2848 bool talent
= (talentCost
> 0);
2849 bool passive
= IsPassiveSpell(id
);
2850 bool active
= target
&& target
->HasAura(id
);
2852 // unit32 used to prevent interpreting uint8 as char at output
2853 // find rank of learned spell for learning spell, or talent rank
2854 uint32 rank
= talentCost
? talentCost
: spellmgr
.GetSpellRank(learn
? spellInfo
->EffectTriggerSpell
[0] : id
);
2856 // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
2857 std::ostringstream ss
;
2859 ss
<< id
<< " - |cffffffff|Hspell:" << id
<< "|h[" << name
;
2861 ss
<< id
<< " - " << name
;
2863 // include rank in link name
2865 ss
<< GetMangosString(LANG_SPELL_RANK
) << rank
;
2868 ss
<< " " << localeNames
[loc
] << "]|h|r";
2870 ss
<< " " << localeNames
[loc
];
2873 ss
<< GetMangosString(LANG_TALENT
);
2875 ss
<< GetMangosString(LANG_PASSIVE
);
2877 ss
<< GetMangosString(LANG_LEARN
);
2879 ss
<< GetMangosString(LANG_KNOWN
);
2881 ss
<< GetMangosString(LANG_ACTIVE
);
2883 SendSysMessage(ss
.str().c_str());
2889 if (counter
== 0) // if counter == 0 then we found nth
2890 SendSysMessage(LANG_COMMAND_NOSPELLFOUND
);
2894 bool ChatHandler::HandleLookupQuestCommand(const char* args
)
2899 // can be NULL at console call
2900 Player
* target
= getSelectedPlayer();
2902 std::string namepart
= args
;
2903 std::wstring wnamepart
;
2905 // converting string that we try to find to lower case
2906 if(!Utf8toWStr(namepart
,wnamepart
))
2909 wstrToLower(wnamepart
);
2911 uint32 counter
= 0 ;
2913 ObjectMgr::QuestMap
const& qTemplates
= objmgr
.GetQuestTemplates();
2914 for (ObjectMgr::QuestMap::const_iterator iter
= qTemplates
.begin(); iter
!= qTemplates
.end(); ++iter
)
2916 Quest
* qinfo
= iter
->second
;
2918 int loc_idx
= GetSessionDbLocaleIndex();
2921 QuestLocale
const *il
= objmgr
.GetQuestLocale(qinfo
->GetQuestId());
2924 if (il
->Title
.size() > loc_idx
&& !il
->Title
[loc_idx
].empty())
2926 std::string title
= il
->Title
[loc_idx
];
2928 if (Utf8FitTo(title
, wnamepart
))
2930 char const* statusStr
= "";
2934 QuestStatus status
= target
->GetQuestStatus(qinfo
->GetQuestId());
2936 if(status
== QUEST_STATUS_COMPLETE
)
2938 if(target
->GetQuestRewardStatus(qinfo
->GetQuestId()))
2939 statusStr
= GetMangosString(LANG_COMMAND_QUEST_REWARDED
);
2941 statusStr
= GetMangosString(LANG_COMMAND_QUEST_COMPLETE
);
2943 else if(status
== QUEST_STATUS_INCOMPLETE
)
2944 statusStr
= GetMangosString(LANG_COMMAND_QUEST_ACTIVE
);
2948 PSendSysMessage(LANG_QUEST_LIST_CHAT
,qinfo
->GetQuestId(),qinfo
->GetQuestId(),qinfo
->GetQuestLevel(),title
.c_str(),statusStr
);
2950 PSendSysMessage(LANG_QUEST_LIST_CONSOLE
,qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2958 std::string title
= qinfo
->GetTitle();
2962 if (Utf8FitTo(title
, wnamepart
))
2964 char const* statusStr
= "";
2968 QuestStatus status
= target
->GetQuestStatus(qinfo
->GetQuestId());
2970 if(status
== QUEST_STATUS_COMPLETE
)
2972 if(target
->GetQuestRewardStatus(qinfo
->GetQuestId()))
2973 statusStr
= GetMangosString(LANG_COMMAND_QUEST_REWARDED
);
2975 statusStr
= GetMangosString(LANG_COMMAND_QUEST_COMPLETE
);
2977 else if(status
== QUEST_STATUS_INCOMPLETE
)
2978 statusStr
= GetMangosString(LANG_COMMAND_QUEST_ACTIVE
);
2982 PSendSysMessage(LANG_QUEST_LIST_CHAT
,qinfo
->GetQuestId(),qinfo
->GetQuestId(),qinfo
->GetQuestLevel(),title
.c_str(),statusStr
);
2984 PSendSysMessage(LANG_QUEST_LIST_CONSOLE
,qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2991 SendSysMessage(LANG_COMMAND_NOQUESTFOUND
);
2996 bool ChatHandler::HandleLookupCreatureCommand(const char* args
)
3001 std::string namepart
= args
;
3002 std::wstring wnamepart
;
3004 // converting string that we try to find to lower case
3005 if (!Utf8toWStr (namepart
,wnamepart
))
3008 wstrToLower (wnamepart
);
3012 for (uint32 id
= 0; id
< sCreatureStorage
.MaxEntry
; ++id
)
3014 CreatureInfo
const* cInfo
= sCreatureStorage
.LookupEntry
<CreatureInfo
> (id
);
3018 int loc_idx
= GetSessionDbLocaleIndex();
3021 CreatureLocale
const *cl
= objmgr
.GetCreatureLocale (id
);
3024 if (cl
->Name
.size() > loc_idx
&& !cl
->Name
[loc_idx
].empty ())
3026 std::string name
= cl
->Name
[loc_idx
];
3028 if (Utf8FitTo (name
, wnamepart
))
3031 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str ());
3033 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE
, id
, name
.c_str ());
3041 std::string name
= cInfo
->Name
;
3045 if (Utf8FitTo(name
, wnamepart
))
3048 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str ());
3050 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE
, id
, name
.c_str ());
3056 SendSysMessage (LANG_COMMAND_NOCREATUREFOUND
);
3061 bool ChatHandler::HandleLookupObjectCommand(const char* args
)
3066 std::string namepart
= args
;
3067 std::wstring wnamepart
;
3069 // converting string that we try to find to lower case
3070 if(!Utf8toWStr(namepart
,wnamepart
))
3073 wstrToLower(wnamepart
);
3077 for (uint32 id
= 0; id
< sGOStorage
.MaxEntry
; id
++ )
3079 GameObjectInfo
const* gInfo
= sGOStorage
.LookupEntry
<GameObjectInfo
>(id
);
3083 int loc_idx
= GetSessionDbLocaleIndex();
3086 GameObjectLocale
const *gl
= objmgr
.GetGameObjectLocale(id
);
3089 if (gl
->Name
.size() > loc_idx
&& !gl
->Name
[loc_idx
].empty())
3091 std::string name
= gl
->Name
[loc_idx
];
3093 if (Utf8FitTo(name
, wnamepart
))
3096 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT
, id
, id
, name
.c_str());
3098 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE
, id
, name
.c_str());
3106 std::string name
= gInfo
->name
;
3110 if(Utf8FitTo(name
, wnamepart
))
3113 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT
, id
, id
, name
.c_str());
3115 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE
, id
, name
.c_str());
3121 SendSysMessage(LANG_COMMAND_NOGAMEOBJECTFOUND
);
3126 bool ChatHandler::HandleLookupTaxiNodeCommand(const char * args
)
3131 std::string namepart
= args
;
3132 std::wstring wnamepart
;
3134 if(!Utf8toWStr(namepart
,wnamepart
))
3137 // converting string that we try to find to lower case
3138 wstrToLower( wnamepart
);
3140 uint32 counter
= 0; // Counter for figure out that we found smth.
3142 // Search in TaxiNodes.dbc
3143 for (uint32 id
= 0; id
< sTaxiNodesStore
.GetNumRows(); id
++)
3145 TaxiNodesEntry
const *nodeEntry
= sTaxiNodesStore
.LookupEntry(id
);
3148 int loc
= GetSessionDbcLocale();
3149 std::string name
= nodeEntry
->name
[loc
];
3153 if (!Utf8FitTo(name
, wnamepart
))
3156 for(; loc
< MAX_LOCALE
; ++loc
)
3158 if(loc
==GetSessionDbcLocale())
3161 name
= nodeEntry
->name
[loc
];
3165 if (Utf8FitTo(name
, wnamepart
))
3170 if(loc
< MAX_LOCALE
)
3172 // send taxinode in "id - [name] (Map:m X:x Y:y Z:z)" format
3174 PSendSysMessage (LANG_TAXINODE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str(),localeNames
[loc
],
3175 nodeEntry
->map_id
,nodeEntry
->x
,nodeEntry
->y
,nodeEntry
->z
);
3177 PSendSysMessage (LANG_TAXINODE_ENTRY_LIST_CONSOLE
, id
, name
.c_str(), localeNames
[loc
],
3178 nodeEntry
->map_id
,nodeEntry
->x
,nodeEntry
->y
,nodeEntry
->z
);
3183 if (counter
== 0) // if counter == 0 then we found nth
3184 SendSysMessage(LANG_COMMAND_NOTAXINODEFOUND
);
3188 /** \brief GM command level 3 - Create a guild.
3190 * This command allows a GM (level 3) to create a guild.
3192 * The "args" parameter contains the name of the guild leader
3193 * and then the name of the guild.
3196 bool ChatHandler::HandleGuildCreateCommand(const char* args
)
3201 // if not guild name only (in "") then player name
3203 if(!extractPlayerTarget(*args
!='"' ? (char*)args
: NULL
, &target
))
3206 char* tailStr
= *args
!='"' ? strtok(NULL
, "") : (char*)args
;
3210 char* guildStr
= extractQuotedArg(tailStr
);
3214 std::string guildname
= guildStr
;
3216 if (target
->GetGuildId())
3218 SendSysMessage (LANG_PLAYER_IN_GUILD
);
3222 Guild
*guild
= new Guild
;
3223 if (!guild
->Create (target
,guildname
))
3226 SendSysMessage (LANG_GUILD_NOT_CREATED
);
3227 SetSentErrorMessage (true);
3231 objmgr
.AddGuild (guild
);
3235 bool ChatHandler::HandleGuildInviteCommand(const char *args
)
3240 // if not guild name only (in "") then player name
3242 if(!extractPlayerTarget(*args
!='"' ? (char*)args
: NULL
, NULL
, &target_guid
))
3245 char* tailStr
= *args
!='"' ? strtok(NULL
, "") : (char*)args
;
3249 char* guildStr
= extractQuotedArg(tailStr
);
3253 std::string glName
= guildStr
;
3254 Guild
* targetGuild
= objmgr
.GetGuildByName (glName
);
3258 // player's guild membership checked in AddMember before add
3259 if (!targetGuild
->AddMember (target_guid
,targetGuild
->GetLowestRank ()))
3265 bool ChatHandler::HandleGuildUninviteCommand(const char *args
)
3269 if(!extractPlayerTarget((char*)args
,&target
,&target_guid
))
3272 uint32 glId
= target
? target
->GetGuildId () : Player::GetGuildIdFromDB (target_guid
);
3276 Guild
* targetGuild
= objmgr
.GetGuildById (glId
);
3280 targetGuild
->DelMember (target_guid
);
3284 bool ChatHandler::HandleGuildRankCommand(const char *args
)
3288 extractOptFirstArg((char*)args
,&nameStr
,&rankStr
);
3294 std::string target_name
;
3295 if(!extractPlayerTarget(nameStr
,&target
,&target_guid
,&target_name
))
3298 uint32 glId
= target
? target
->GetGuildId () : Player::GetGuildIdFromDB (target_guid
);
3302 Guild
* targetGuild
= objmgr
.GetGuildById (glId
);
3306 uint32 newrank
= uint32 (atoi (rankStr
));
3307 if (newrank
> targetGuild
->GetLowestRank ())
3310 targetGuild
->ChangeRank (target_guid
,newrank
);
3314 bool ChatHandler::HandleGuildDeleteCommand(const char* args
)
3319 char* guildStr
= extractQuotedArg((char*)args
);
3323 std::string gld
= guildStr
;
3325 Guild
* targetGuild
= objmgr
.GetGuildByName (gld
);
3329 targetGuild
->Disband ();
3334 bool ChatHandler::HandleGetDistanceCommand(const char* args
)
3336 WorldObject
* obj
= NULL
;
3340 uint64 guid
= extractGuidFromLink((char*)args
);
3342 obj
= (WorldObject
*)ObjectAccessor::GetObjectByTypeMask(*m_session
->GetPlayer(),guid
,TYPEMASK_UNIT
|TYPEMASK_GAMEOBJECT
);
3346 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3347 SetSentErrorMessage(true);
3353 obj
= getSelectedUnit();
3357 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3358 SetSentErrorMessage(true);
3363 PSendSysMessage(LANG_DISTANCE
, m_session
->GetPlayer()->GetDistance(obj
),m_session
->GetPlayer()->GetDistance2d(obj
));
3368 bool ChatHandler::HandleDieCommand(const char* /*args*/)
3370 Unit
* target
= getSelectedUnit();
3372 if(!target
|| !m_session
->GetPlayer()->GetSelection())
3374 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3375 SetSentErrorMessage(true);
3379 if(target
->GetTypeId()==TYPEID_PLAYER
)
3381 if(HasLowerSecurity((Player
*)target
,0,false))
3385 if( target
->isAlive() )
3387 m_session
->GetPlayer()->DealDamage(target
, target
->GetHealth(), NULL
, DIRECT_DAMAGE
, SPELL_SCHOOL_MASK_NORMAL
, NULL
, false);
3393 bool ChatHandler::HandleDamageCommand(const char * args
)
3398 Unit
* target
= getSelectedUnit();
3400 if (!target
|| !m_session
->GetPlayer()->GetSelection())
3402 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3403 SetSentErrorMessage(true);
3407 if (!target
->isAlive())
3410 char* damageStr
= strtok((char*)args
, " ");
3414 int32 damage_int
= atoi((char*)damageStr
);
3418 uint32 damage
= damage_int
;
3420 char* schoolStr
= strtok((char*)NULL
, " ");
3422 // flat melee damage without resistence/etc reduction
3425 m_session
->GetPlayer()->DealDamage(target
, damage
, NULL
, DIRECT_DAMAGE
, SPELL_SCHOOL_MASK_NORMAL
, NULL
, false);
3426 if (target
!= m_session
->GetPlayer())
3427 m_session
->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2
, target
, 1, SPELL_SCHOOL_MASK_NORMAL
, damage
, 0, 0, VICTIMSTATE_NORMAL
, 0);
3431 uint32 school
= schoolStr
? atoi((char*)schoolStr
) : SPELL_SCHOOL_NORMAL
;
3432 if(school
>= MAX_SPELL_SCHOOL
)
3435 SpellSchoolMask schoolmask
= SpellSchoolMask(1 << school
);
3437 if ( schoolmask
& SPELL_SCHOOL_MASK_NORMAL
)
3438 damage
= m_session
->GetPlayer()->CalcArmorReducedDamage(target
, damage
);
3440 char* spellStr
= strtok((char*)NULL
, " ");
3442 // melee damage by specific school
3448 m_session
->GetPlayer()->CalcAbsorbResist(target
,schoolmask
, SPELL_DIRECT_DAMAGE
, damage
, &absorb
, &resist
);
3450 if (damage
<= absorb
+ resist
)
3453 damage
-= absorb
+ resist
;
3455 m_session
->GetPlayer()->DealDamageMods(target
,damage
,&absorb
);
3456 m_session
->GetPlayer()->DealDamage(target
, damage
, NULL
, DIRECT_DAMAGE
, schoolmask
, NULL
, false);
3457 m_session
->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2
, target
, 1, schoolmask
, damage
, absorb
, resist
, VICTIMSTATE_NORMAL
, 0);
3463 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3464 uint32 spellid
= extractSpellIdFromLink((char*)args
);
3465 if (!spellid
|| !sSpellStore
.LookupEntry(spellid
))
3468 m_session
->GetPlayer()->SpellNonMeleeDamageLog(target
, spellid
, damage
);
3472 bool ChatHandler::HandleModifyArenaCommand(const char * args
)
3477 Player
*target
= getSelectedPlayer();
3480 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3481 SetSentErrorMessage(true);
3485 int32 amount
= (uint32
)atoi(args
);
3487 target
->ModifyArenaPoints(amount
);
3489 PSendSysMessage(LANG_COMMAND_MODIFY_ARENA
, GetNameLink(target
).c_str(), target
->GetArenaPoints());
3494 bool ChatHandler::HandleReviveCommand(const char* args
)
3498 if(!extractPlayerTarget((char*)args
,&target
,&target_guid
))
3503 target
->ResurrectPlayer(0.5f
);
3504 target
->SpawnCorpseBones();
3508 // will resurrected at login without corpse
3509 ObjectAccessor::Instance().ConvertCorpseForPlayer(target_guid
);
3514 bool ChatHandler::HandleAuraCommand(const char* args
)
3516 Unit
*target
= getSelectedUnit();
3519 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3520 SetSentErrorMessage(true);
3524 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3525 uint32 spellID
= extractSpellIdFromLink((char*)args
);
3527 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry( spellID
);
3530 for(uint32 i
= 0;i
<3;++i
)
3532 uint8 eff
= spellInfo
->Effect
[i
];
3533 if (eff
>=TOTAL_SPELL_EFFECTS
)
3535 if( IsAreaAuraEffect(eff
) ||
3536 eff
== SPELL_EFFECT_APPLY_AURA
||
3537 eff
== SPELL_EFFECT_PERSISTENT_AREA_AURA
)
3539 Aura
*Aur
= CreateAura(spellInfo
, i
, NULL
, target
);
3540 target
->AddAura(Aur
);
3548 bool ChatHandler::HandleUnAuraCommand(const char* args
)
3550 Unit
*target
= getSelectedUnit();
3553 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3554 SetSentErrorMessage(true);
3558 std::string argstr
= args
;
3559 if (argstr
== "all")
3561 target
->RemoveAllAuras();
3565 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3566 uint32 spellID
= extractSpellIdFromLink((char*)args
);
3570 target
->RemoveAurasDueToSpell(spellID
);
3575 bool ChatHandler::HandleLinkGraveCommand(const char* args
)
3580 char* px
= strtok((char*)args
, " ");
3584 uint32 g_id
= (uint32
)atoi(px
);
3588 char* px2
= strtok(NULL
, " ");
3592 else if (strncmp(px2
,"horde",6)==0)
3594 else if (strncmp(px2
,"alliance",9)==0)
3599 WorldSafeLocsEntry
const* graveyard
= sWorldSafeLocsStore
.LookupEntry(g_id
);
3603 PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST
, g_id
);
3604 SetSentErrorMessage(true);
3608 Player
* player
= m_session
->GetPlayer();
3610 uint32 zoneId
= player
->GetZoneId();
3612 AreaTableEntry
const *areaEntry
= GetAreaEntryByAreaID(zoneId
);
3613 if(!areaEntry
|| areaEntry
->zone
!=0 )
3615 PSendSysMessage(LANG_COMMAND_GRAVEYARDWRONGZONE
, g_id
,zoneId
);
3616 SetSentErrorMessage(true);
3620 if(objmgr
.AddGraveYardLink(g_id
,zoneId
,g_team
))
3621 PSendSysMessage(LANG_COMMAND_GRAVEYARDLINKED
, g_id
,zoneId
);
3623 PSendSysMessage(LANG_COMMAND_GRAVEYARDALRLINKED
, g_id
,zoneId
);
3628 bool ChatHandler::HandleNearGraveCommand(const char* args
)
3632 size_t argslen
= strlen(args
);
3636 else if (strncmp((char*)args
,"horde",argslen
)==0)
3638 else if (strncmp((char*)args
,"alliance",argslen
)==0)
3643 Player
* player
= m_session
->GetPlayer();
3644 uint32 zone_id
= player
->GetZoneId();
3646 WorldSafeLocsEntry
const* graveyard
= objmgr
.GetClosestGraveYard(
3647 player
->GetPositionX(), player
->GetPositionY(), player
->GetPositionZ(),player
->GetMapId(),g_team
);
3651 uint32 g_id
= graveyard
->ID
;
3653 GraveYardData
const* data
= objmgr
.FindGraveYardData(g_id
,zone_id
);
3656 PSendSysMessage(LANG_COMMAND_GRAVEYARDERROR
,g_id
);
3657 SetSentErrorMessage(true);
3661 g_team
= data
->team
;
3663 std::string team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_NOTEAM
);
3666 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ANY
);
3667 else if(g_team
== HORDE
)
3668 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE
);
3669 else if(g_team
== ALLIANCE
)
3670 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE
);
3672 PSendSysMessage(LANG_COMMAND_GRAVEYARDNEAREST
, g_id
,team_name
.c_str(),zone_id
);
3676 std::string team_name
;
3679 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ANY
);
3680 else if(g_team
== HORDE
)
3681 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE
);
3682 else if(g_team
== ALLIANCE
)
3683 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE
);
3685 if(g_team
== ~uint32(0))
3686 PSendSysMessage(LANG_COMMAND_ZONENOGRAVEYARDS
, zone_id
);
3688 PSendSysMessage(LANG_COMMAND_ZONENOGRAFACTION
, zone_id
,team_name
.c_str());
3694 //-----------------------Npc Commands-----------------------
3695 bool ChatHandler::HandleNpcAllowMovementCommand(const char* /*args*/)
3697 if(sWorld
.getAllowMovement())
3699 sWorld
.SetAllowMovement(false);
3700 SendSysMessage(LANG_CREATURE_MOVE_DISABLED
);
3704 sWorld
.SetAllowMovement(true);
3705 SendSysMessage(LANG_CREATURE_MOVE_ENABLED
);
3710 bool ChatHandler::HandleNpcChangeEntryCommand(const char *args
)
3715 uint32 newEntryNum
= atoi(args
);
3719 Unit
* unit
= getSelectedUnit();
3720 if(!unit
|| unit
->GetTypeId() != TYPEID_UNIT
)
3722 SendSysMessage(LANG_SELECT_CREATURE
);
3723 SetSentErrorMessage(true);
3726 Creature
* creature
= (Creature
*)unit
;
3727 if(creature
->UpdateEntry(newEntryNum
))
3728 SendSysMessage(LANG_DONE
);
3730 SendSysMessage(LANG_ERROR
);
3734 bool ChatHandler::HandleNpcInfoCommand(const char* /*args*/)
3736 Creature
* target
= getSelectedCreature();
3740 SendSysMessage(LANG_SELECT_CREATURE
);
3741 SetSentErrorMessage(true);
3745 uint32 faction
= target
->getFaction();
3746 uint32 npcflags
= target
->GetUInt32Value(UNIT_NPC_FLAGS
);
3747 uint32 displayid
= target
->GetDisplayId();
3748 uint32 nativeid
= target
->GetNativeDisplayId();
3749 uint32 Entry
= target
->GetEntry();
3750 CreatureInfo
const* cInfo
= target
->GetCreatureInfo();
3752 int32 curRespawnDelay
= target
->GetRespawnTimeEx()-time(NULL
);
3753 if(curRespawnDelay
< 0)
3754 curRespawnDelay
= 0;
3755 std::string curRespawnDelayStr
= secsToTimeString(curRespawnDelay
,true);
3756 std::string defRespawnDelayStr
= secsToTimeString(target
->GetRespawnDelay(),true);
3758 PSendSysMessage(LANG_NPCINFO_CHAR
, target
->GetDBTableGUIDLow(), faction
, npcflags
, Entry
, displayid
, nativeid
);
3759 PSendSysMessage(LANG_NPCINFO_LEVEL
, target
->getLevel());
3760 PSendSysMessage(LANG_NPCINFO_HEALTH
,target
->GetCreateHealth(), target
->GetMaxHealth(), target
->GetHealth());
3761 PSendSysMessage(LANG_NPCINFO_FLAGS
, target
->GetUInt32Value(UNIT_FIELD_FLAGS
), target
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
), target
->getFaction());
3762 PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES
, defRespawnDelayStr
.c_str(),curRespawnDelayStr
.c_str());
3763 PSendSysMessage(LANG_NPCINFO_LOOT
, cInfo
->lootid
,cInfo
->pickpocketLootId
,cInfo
->SkinLootId
);
3764 PSendSysMessage(LANG_NPCINFO_DUNGEON_ID
, target
->GetInstanceId());
3765 PSendSysMessage(LANG_NPCINFO_POSITION
,float(target
->GetPositionX()), float(target
->GetPositionY()), float(target
->GetPositionZ()));
3767 if ((npcflags
& UNIT_NPC_FLAG_VENDOR
) )
3769 SendSysMessage(LANG_NPCINFO_VENDOR
);
3771 if ((npcflags
& UNIT_NPC_FLAG_TRAINER
) )
3773 SendSysMessage(LANG_NPCINFO_TRAINER
);
3780 bool ChatHandler::HandleNpcPlayEmoteCommand(const char* args
)
3782 uint32 emote
= atoi((char*)args
);
3784 Creature
* target
= getSelectedCreature();
3787 SendSysMessage(LANG_SELECT_CREATURE
);
3788 SetSentErrorMessage(true);
3792 target
->SetUInt32Value(UNIT_NPC_EMOTESTATE
,emote
);
3797 //TODO: NpcCommands that needs to be fixed :
3799 bool ChatHandler::HandleNpcAddWeaponCommand(const char* /*args*/)
3804 uint64 guid = m_session->GetPlayer()->GetSelection();
3807 SendSysMessage(LANG_NO_SELECTION);
3811 Creature *pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
3815 SendSysMessage(LANG_SELECT_CREATURE);
3819 char* pSlotID = strtok((char*)args, " ");
3823 char* pItemID = strtok(NULL, " ");
3827 uint32 ItemID = atoi(pItemID);
3828 uint32 SlotID = atoi(pSlotID);
3830 ItemPrototype* tmpItem = objmgr.GetItemPrototype(ItemID);
3838 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID);
3842 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID);
3846 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID);
3850 PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST,SlotID);
3856 PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT,ItemID,tmpItem->Name1,SlotID);
3860 PSendSysMessage(LANG_ITEM_NOT_FOUND,ItemID);
3866 //----------------------------------------------------------
3868 bool ChatHandler::HandleExploreCheatCommand(const char* args
)
3873 int flag
= atoi((char*)args
);
3875 Player
*chr
= getSelectedPlayer();
3878 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3879 SetSentErrorMessage(true);
3885 PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL
, GetNameLink(chr
).c_str());
3886 if (needReportToTarget(chr
))
3887 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_EXPLORE_SET_ALL
,GetNameLink().c_str());
3891 PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING
, GetNameLink(chr
).c_str());
3892 if (needReportToTarget(chr
))
3893 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_EXPLORE_SET_NOTHING
,GetNameLink().c_str());
3896 for (uint8 i
=0; i
<128; ++i
)
3900 m_session
->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1
+i
,0xFFFFFFFF);
3904 m_session
->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1
+i
,0);
3911 bool ChatHandler::HandleHoverCommand(const char* args
)
3913 char* px
= strtok((char*)args
, " ");
3920 m_session
->GetPlayer()->SetHover(flag
);
3923 SendSysMessage(LANG_HOVER_ENABLED
);
3925 SendSysMessage(LANG_HOVER_DISABLED
);
3930 void ChatHandler::HandleCharacterLevel(Player
* player
, uint64 player_guid
, uint32 oldlevel
, uint32 newlevel
)
3934 player
->GiveLevel(newlevel
);
3935 player
->InitTalentForLevel();
3936 player
->SetUInt32Value(PLAYER_XP
,0);
3938 if(needReportToTarget(player
))
3940 if(oldlevel
== newlevel
)
3941 ChatHandler(player
).PSendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET
,GetNameLink().c_str());
3942 else if(oldlevel
< newlevel
)
3943 ChatHandler(player
).PSendSysMessage(LANG_YOURS_LEVEL_UP
,GetNameLink().c_str(),newlevel
);
3944 else // if(oldlevel > newlevel)
3945 ChatHandler(player
).PSendSysMessage(LANG_YOURS_LEVEL_DOWN
,GetNameLink().c_str(),newlevel
);
3950 // update level and XP at level, all other will be updated at loading
3951 CharacterDatabase
.PExecute("UPDATE characters SET level = '%u', xp = 0 WHERE guid = '%u'", newlevel
, GUID_LOPART(player_guid
));
3955 bool ChatHandler::HandleCharacterLevelCommand(const char* args
)
3959 extractOptFirstArg((char*)args
,&nameStr
,&levelStr
);
3963 // exception opt second arg: .character level $name
3964 if(isalpha(levelStr
[0]))
3967 levelStr
= NULL
; // current level will used
3972 std::string target_name
;
3973 if(!extractPlayerTarget(nameStr
,&target
,&target_guid
,&target_name
))
3976 int32 oldlevel
= target
? target
->getLevel() : Player::GetLevelFromDB(target_guid
);
3977 int32 newlevel
= levelStr
? atoi(levelStr
) : oldlevel
;
3980 return false; // invalid level
3982 if(newlevel
> STRONG_MAX_LEVEL
) // hardcoded maximum level
3983 newlevel
= STRONG_MAX_LEVEL
;
3985 HandleCharacterLevel(target
,target_guid
,oldlevel
,newlevel
);
3987 if(!m_session
|| m_session
->GetPlayer() != target
) // including player==NULL
3989 std::string nameLink
= playerLink(target_name
);
3990 PSendSysMessage(LANG_YOU_CHANGE_LVL
,nameLink
.c_str(),newlevel
);
3996 bool ChatHandler::HandleLevelUpCommand(const char* args
)
4000 extractOptFirstArg((char*)args
,&nameStr
,&levelStr
);
4002 // exception opt second arg: .character level $name
4003 if(levelStr
&& isalpha(levelStr
[0]))
4006 levelStr
= NULL
; // current level will used
4011 std::string target_name
;
4012 if(!extractPlayerTarget(nameStr
,&target
,&target_guid
,&target_name
))
4015 int32 oldlevel
= target
? target
->getLevel() : Player::GetLevelFromDB(target_guid
);
4016 int32 addlevel
= levelStr
? atoi(levelStr
) : 1;
4017 int32 newlevel
= oldlevel
+ addlevel
;
4022 if(newlevel
> STRONG_MAX_LEVEL
) // hardcoded maximum level
4023 newlevel
= STRONG_MAX_LEVEL
;
4025 HandleCharacterLevel(target
,target_guid
,oldlevel
,newlevel
);
4027 if(!m_session
|| m_session
->GetPlayer() != target
) // including chr==NULL
4029 std::string nameLink
= playerLink(target_name
);
4030 PSendSysMessage(LANG_YOU_CHANGE_LVL
,nameLink
.c_str(),newlevel
);
4036 bool ChatHandler::HandleShowAreaCommand(const char* args
)
4041 Player
*chr
= getSelectedPlayer();
4044 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4045 SetSentErrorMessage(true);
4049 int area
= GetAreaFlagByAreaID(atoi((char*)args
));
4050 int offset
= area
/ 32;
4051 uint32 val
= (uint32
)(1 << (area
% 32));
4053 if(area
<0 || offset
>= 128)
4055 SendSysMessage(LANG_BAD_VALUE
);
4056 SetSentErrorMessage(true);
4060 uint32 currFields
= chr
->GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
4061 chr
->SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
| val
));
4063 SendSysMessage(LANG_EXPLORE_AREA
);
4067 bool ChatHandler::HandleHideAreaCommand(const char* args
)
4072 Player
*chr
= getSelectedPlayer();
4075 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4076 SetSentErrorMessage(true);
4080 int area
= GetAreaFlagByAreaID(atoi((char*)args
));
4081 int offset
= area
/ 32;
4082 uint32 val
= (uint32
)(1 << (area
% 32));
4084 if(area
<0 || offset
>= 128)
4086 SendSysMessage(LANG_BAD_VALUE
);
4087 SetSentErrorMessage(true);
4091 uint32 currFields
= chr
->GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
4092 chr
->SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
^ val
));
4094 SendSysMessage(LANG_UNEXPLORE_AREA
);
4098 bool ChatHandler::HandleBankCommand(const char* /*args*/)
4100 m_session
->SendShowBank( m_session
->GetPlayer()->GetGUID() );
4105 bool ChatHandler::HandleChangeWeather(const char* args
)
4111 if (!sWorld
.getConfig(CONFIG_WEATHER
))
4113 SendSysMessage(LANG_WEATHER_DISABLED
);
4114 SetSentErrorMessage(true);
4118 //*Change the weather of a cell
4119 char* px
= strtok((char*)args
, " ");
4120 char* py
= strtok(NULL
, " ");
4125 uint32 type
= (uint32
)atoi(px
); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
4126 float grade
= (float)atof(py
); //0 to 1, sending -1 is instand good weather
4128 Player
*player
= m_session
->GetPlayer();
4129 uint32 zoneid
= player
->GetZoneId();
4131 Weather
* wth
= sWorld
.FindWeather(zoneid
);
4134 wth
= sWorld
.AddWeather(zoneid
);
4137 SendSysMessage(LANG_NO_WEATHER
);
4138 SetSentErrorMessage(true);
4142 wth
->SetWeather(WeatherType(type
), grade
);
4147 bool ChatHandler::HandleTeleAddCommand(const char * args
)
4152 Player
*player
=m_session
->GetPlayer();
4156 std::string name
= args
;
4158 if(objmgr
.GetGameTele(name
))
4160 SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST
);
4161 SetSentErrorMessage(true);
4166 tele
.position_x
= player
->GetPositionX();
4167 tele
.position_y
= player
->GetPositionY();
4168 tele
.position_z
= player
->GetPositionZ();
4169 tele
.orientation
= player
->GetOrientation();
4170 tele
.mapId
= player
->GetMapId();
4173 if(objmgr
.AddGameTele(tele
))
4175 SendSysMessage(LANG_COMMAND_TP_ADDED
);
4179 SendSysMessage(LANG_COMMAND_TP_ADDEDERR
);
4180 SetSentErrorMessage(true);
4187 bool ChatHandler::HandleTeleDelCommand(const char * args
)
4192 std::string name
= args
;
4194 if(!objmgr
.DeleteGameTele(name
))
4196 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
4197 SetSentErrorMessage(true);
4201 SendSysMessage(LANG_COMMAND_TP_DELETED
);
4205 bool ChatHandler::HandleListAurasCommand (const char * /*args*/)
4207 Unit
*unit
= getSelectedUnit();
4210 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4211 SetSentErrorMessage(true);
4215 char const* talentStr
= GetMangosString(LANG_TALENT
);
4216 char const* passiveStr
= GetMangosString(LANG_PASSIVE
);
4218 Unit::AuraMap
const& uAuras
= unit
->GetAuras();
4219 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS
, uAuras
.size());
4220 for (Unit::AuraMap::const_iterator itr
= uAuras
.begin(); itr
!= uAuras
.end(); ++itr
)
4222 bool talent
= GetTalentSpellCost(itr
->second
->GetId()) > 0;
4224 char const* name
= itr
->second
->GetSpellProto()->SpellName
[GetSessionDbcLocale()];
4228 std::ostringstream ss_name
;
4229 ss_name
<< "|cffffffff|Hspell:" << itr
->second
->GetId() << "|h[" << name
<< "]|h|r";
4231 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL
, itr
->second
->GetId(), itr
->second
->GetEffIndex(),
4232 itr
->second
->GetModifier()->m_auraname
, itr
->second
->GetAuraDuration(), itr
->second
->GetAuraMaxDuration(),
4233 ss_name
.str().c_str(),
4234 (itr
->second
->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4235 IS_PLAYER_GUID(itr
->second
->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr
->second
->GetCasterGUID()));
4239 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL
, itr
->second
->GetId(), itr
->second
->GetEffIndex(),
4240 itr
->second
->GetModifier()->m_auraname
, itr
->second
->GetAuraDuration(), itr
->second
->GetAuraMaxDuration(),
4242 (itr
->second
->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4243 IS_PLAYER_GUID(itr
->second
->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr
->second
->GetCasterGUID()));
4246 for (int i
= 0; i
< TOTAL_AURAS
; ++i
)
4248 Unit::AuraList
const& uAuraList
= unit
->GetAurasByType(AuraType(i
));
4249 if (uAuraList
.empty()) continue;
4250 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE
, uAuraList
.size(), i
);
4251 for (Unit::AuraList::const_iterator itr
= uAuraList
.begin(); itr
!= uAuraList
.end(); ++itr
)
4253 bool talent
= GetTalentSpellCost((*itr
)->GetId()) > 0;
4255 char const* name
= (*itr
)->GetSpellProto()->SpellName
[GetSessionDbcLocale()];
4259 std::ostringstream ss_name
;
4260 ss_name
<< "|cffffffff|Hspell:" << (*itr
)->GetId() << "|h[" << name
<< "]|h|r";
4262 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE
, (*itr
)->GetId(), (*itr
)->GetEffIndex(),
4263 ss_name
.str().c_str(),((*itr
)->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4264 IS_PLAYER_GUID((*itr
)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr
)->GetCasterGUID()));
4268 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE
, (*itr
)->GetId(), (*itr
)->GetEffIndex(),
4269 name
,((*itr
)->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4270 IS_PLAYER_GUID((*itr
)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr
)->GetCasterGUID()));
4277 bool ChatHandler::HandleResetAchievementsCommand (const char * args
)
4281 if (!extractPlayerTarget((char*)args
,&target
,&target_guid
))
4285 target
->GetAchievementMgr().Reset();
4287 AchievementMgr::DeleteFromDB(GUID_LOPART(target_guid
));
4292 bool ChatHandler::HandleResetHonorCommand (const char * args
)
4295 if (!extractPlayerTarget((char*)args
,&target
))
4298 target
->SetUInt32Value(PLAYER_FIELD_KILLS
, 0);
4299 target
->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS
, 0);
4300 target
->SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY
, 0);
4301 target
->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION
, 0);
4302 target
->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION
, 0);
4303 target
->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_EARN_HONORABLE_KILL
);
4308 static bool HandleResetStatsOrLevelHelper(Player
* player
)
4310 ChrClassesEntry
const* cEntry
= sChrClassesStore
.LookupEntry(player
->getClass());
4313 sLog
.outError("Class %u not found in DBC (Wrong DBC files?)",player
->getClass());
4317 uint8 powertype
= cEntry
->powerType
;
4319 // reset m_form if no aura
4320 if(!player
->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT
))
4321 player
->m_form
= FORM_NONE
;
4323 player
->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS
, DEFAULT_WORLD_OBJECT_SIZE
);
4324 player
->SetFloatValue(UNIT_FIELD_COMBATREACH
, 1.5f
);
4326 player
->setFactionForRace(player
->getRace());
4328 player
->SetUInt32Value(UNIT_FIELD_BYTES_0
, ( ( player
->getRace() ) | ( player
->getClass() << 8 ) | ( player
->getGender() << 16 ) | ( powertype
<< 24 ) ) );
4330 // reset only if player not in some form;
4331 if(player
->m_form
==FORM_NONE
)
4332 player
->InitDisplayIds();
4334 player
->SetByteValue(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_PVP
);
4335 player
->SetByteValue(UNIT_FIELD_BYTES_2
, 3, player
->m_form
);
4337 player
->SetUInt32Value(UNIT_FIELD_FLAGS
, UNIT_FLAG_PVP_ATTACKABLE
);
4339 //-1 is default value
4340 player
->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX
, uint32(-1));
4342 //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000 );
4346 bool ChatHandler::HandleResetLevelCommand(const char * args
)
4349 if(!extractPlayerTarget((char*)args
,&target
))
4352 if(!HandleResetStatsOrLevelHelper(target
))
4355 // set starting level
4356 uint32 start_level
= target
->getClass() != CLASS_DEATH_KNIGHT
4357 ? sWorld
.getConfig(CONFIG_START_PLAYER_LEVEL
)
4358 : sWorld
.getConfig(CONFIG_START_HEROIC_PLAYER_LEVEL
);
4360 target
->_ApplyAllLevelScaleItemMods(false);
4362 target
->SetLevel(start_level
);
4363 target
->InitRunes();
4364 target
->InitStatsForLevel(true);
4365 target
->InitTaxiNodesForLevel();
4366 target
->InitGlyphsForLevel();
4367 target
->InitTalentForLevel();
4368 target
->SetUInt32Value(PLAYER_XP
,0);
4370 target
->_ApplyAllLevelScaleItemMods(true);
4372 // reset level for pet
4373 if(Pet
* pet
= target
->GetPet())
4374 pet
->SynchronizeLevelWithOwner();
4379 bool ChatHandler::HandleResetStatsCommand(const char * args
)
4382 if (!extractPlayerTarget((char*)args
,&target
))
4385 if (!HandleResetStatsOrLevelHelper(target
))
4388 target
->InitRunes();
4389 target
->InitStatsForLevel(true);
4390 target
->InitTaxiNodesForLevel();
4391 target
->InitGlyphsForLevel();
4392 target
->InitTalentForLevel();
4397 bool ChatHandler::HandleResetSpellsCommand(const char * args
)
4401 std::string target_name
;
4402 if(!extractPlayerTarget((char*)args
,&target
,&target_guid
,&target_name
))
4407 target
->resetSpells();
4409 ChatHandler(target
).SendSysMessage(LANG_RESET_SPELLS
);
4410 if(!m_session
|| m_session
->GetPlayer()!=target
)
4411 PSendSysMessage(LANG_RESET_SPELLS_ONLINE
,GetNameLink(target
).c_str());
4415 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS
), GUID_LOPART(target_guid
));
4416 PSendSysMessage(LANG_RESET_SPELLS_OFFLINE
,target_name
.c_str());
4422 bool ChatHandler::HandleResetTalentsCommand(const char * args
)
4426 std::string target_name
;
4427 if (!extractPlayerTarget((char*)args
,&target
,&target_guid
,&target_name
))
4429 // Try reset talents as Hunter Pet
4430 Creature
* creature
= getSelectedCreature();
4431 if (!*args
&& creature
&& creature
->isPet())
4433 Unit
*owner
= creature
->GetOwner();
4434 if(owner
&& owner
->GetTypeId() == TYPEID_PLAYER
&& ((Pet
*)creature
)->IsPermanentPetFor((Player
*)owner
))
4436 ((Pet
*)creature
)->resetTalents(true);
4437 ((Player
*)owner
)->SendTalentsInfoData(true);
4439 ChatHandler((Player
*)owner
).SendSysMessage(LANG_RESET_PET_TALENTS
);
4440 if(!m_session
|| m_session
->GetPlayer()!=((Player
*)owner
))
4441 PSendSysMessage(LANG_RESET_PET_TALENTS_ONLINE
,GetNameLink((Player
*)owner
).c_str());
4446 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4447 SetSentErrorMessage(true);
4453 target
->resetTalents(true);
4454 target
->SendTalentsInfoData(false);
4455 ChatHandler(target
).SendSysMessage(LANG_RESET_TALENTS
);
4456 if (!m_session
|| m_session
->GetPlayer()!=target
)
4457 PSendSysMessage(LANG_RESET_TALENTS_ONLINE
,GetNameLink(target
).c_str());
4459 Pet
* pet
= target
->GetPet();
4460 Pet::resetTalentsForAllPetsOf(target
,pet
);
4462 target
->SendTalentsInfoData(true);
4465 else if (target_guid
)
4467 uint32 at_flags
= AT_LOGIN_NONE
| AT_LOGIN_RESET_PET_TALENTS
;
4468 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",at_flags
, GUID_LOPART(target_guid
) );
4469 std::string nameLink
= playerLink(target_name
);
4470 PSendSysMessage(LANG_RESET_TALENTS_OFFLINE
,nameLink
.c_str());
4474 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4475 SetSentErrorMessage(true);
4479 bool ChatHandler::HandleResetAllCommand(const char * args
)
4484 std::string casename
= args
;
4486 AtLoginFlags atLogin
;
4488 // Command specially created as single command to prevent using short case names
4489 if(casename
=="spells")
4491 atLogin
= AT_LOGIN_RESET_SPELLS
;
4492 sWorld
.SendWorldText(LANG_RESETALL_SPELLS
);
4494 SendSysMessage(LANG_RESETALL_SPELLS
);
4496 else if(casename
=="talents")
4498 atLogin
= AtLoginFlags(AT_LOGIN_RESET_TALENTS
| AT_LOGIN_RESET_PET_TALENTS
);
4499 sWorld
.SendWorldText(LANG_RESETALL_TALENTS
);
4501 SendSysMessage(LANG_RESETALL_TALENTS
);
4505 PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE
,args
);
4506 SetSentErrorMessage(true);
4510 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE (at_login & '%u') = '0'",atLogin
,atLogin
);
4511 HashMapHolder
<Player
>::MapType
const& plist
= ObjectAccessor::Instance().GetPlayers();
4512 for(HashMapHolder
<Player
>::MapType::const_iterator itr
= plist
.begin(); itr
!= plist
.end(); ++itr
)
4513 itr
->second
->SetAtLoginFlag(atLogin
);
4518 bool ChatHandler::HandleServerShutDownCancelCommand(const char* /*args*/)
4520 sWorld
.ShutdownCancel();
4524 bool ChatHandler::HandleServerShutDownCommand(const char* args
)
4529 char* time_str
= strtok ((char*) args
, " ");
4530 char* exitcode_str
= strtok (NULL
, "");
4532 int32 time
= atoi (time_str
);
4534 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4535 if ((time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0')) || time
< 0)
4540 int32 exitcode
= atoi (exitcode_str
);
4542 // Handle atoi() errors
4543 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4546 // Exit code should be in range of 0-125, 126-255 is used
4547 // in many shells for their own return codes and code > 255
4548 // is not supported in many others
4549 if (exitcode
< 0 || exitcode
> 125)
4552 sWorld
.ShutdownServ (time
, 0, exitcode
);
4555 sWorld
.ShutdownServ(time
,0,SHUTDOWN_EXIT_CODE
);
4559 bool ChatHandler::HandleServerRestartCommand(const char* args
)
4564 char* time_str
= strtok ((char*) args
, " ");
4565 char* exitcode_str
= strtok (NULL
, "");
4567 int32 time
= atoi (time_str
);
4569 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4570 if ((time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0')) || time
< 0)
4575 int32 exitcode
= atoi (exitcode_str
);
4577 // Handle atoi() errors
4578 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4581 // Exit code should be in range of 0-125, 126-255 is used
4582 // in many shells for their own return codes and code > 255
4583 // is not supported in many others
4584 if (exitcode
< 0 || exitcode
> 125)
4587 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_RESTART
, exitcode
);
4590 sWorld
.ShutdownServ(time
, SHUTDOWN_MASK_RESTART
, RESTART_EXIT_CODE
);
4594 bool ChatHandler::HandleServerIdleRestartCommand(const char* args
)
4599 char* time_str
= strtok ((char*) args
, " ");
4600 char* exitcode_str
= strtok (NULL
, "");
4602 int32 time
= atoi (time_str
);
4604 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4605 if ((time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0')) || time
< 0)
4610 int32 exitcode
= atoi (exitcode_str
);
4612 // Handle atoi() errors
4613 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4616 // Exit code should be in range of 0-125, 126-255 is used
4617 // in many shells for their own return codes and code > 255
4618 // is not supported in many others
4619 if (exitcode
< 0 || exitcode
> 125)
4622 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_RESTART
|SHUTDOWN_MASK_IDLE
, exitcode
);
4625 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_RESTART
|SHUTDOWN_MASK_IDLE
,RESTART_EXIT_CODE
);
4629 bool ChatHandler::HandleServerIdleShutDownCommand(const char* args
)
4634 char* time_str
= strtok ((char*) args
, " ");
4635 char* exitcode_str
= strtok (NULL
, "");
4637 int32 time
= atoi (time_str
);
4639 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4640 if ((time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0')) || time
< 0)
4645 int32 exitcode
= atoi (exitcode_str
);
4647 // Handle atoi() errors
4648 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4651 // Exit code should be in range of 0-125, 126-255 is used
4652 // in many shells for their own return codes and code > 255
4653 // is not supported in many others
4654 if (exitcode
< 0 || exitcode
> 125)
4657 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_IDLE
, exitcode
);
4660 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_IDLE
,SHUTDOWN_EXIT_CODE
);
4664 bool ChatHandler::HandleQuestAdd(const char* args
)
4666 Player
* player
= getSelectedPlayer();
4669 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4670 SetSentErrorMessage(true);
4674 // .addquest #entry'
4675 // number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
4676 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4680 uint32 entry
= atol(cId
);
4682 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
4686 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
,entry
);
4687 SetSentErrorMessage(true);
4691 // check item starting quest (it can work incorrectly if added without item in inventory)
4692 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
4694 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
4698 if (pProto
->StartQuest
== entry
)
4700 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM
, entry
, pProto
->ItemId
);
4701 SetSentErrorMessage(true);
4706 // ok, normal (creature/GO starting) quest
4707 if( player
->CanAddQuest( pQuest
, true ) )
4709 player
->AddQuest( pQuest
, NULL
);
4711 if ( player
->CanCompleteQuest( entry
) )
4712 player
->CompleteQuest( entry
);
4718 bool ChatHandler::HandleQuestRemove(const char* args
)
4720 Player
* player
= getSelectedPlayer();
4723 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4724 SetSentErrorMessage(true);
4728 // .removequest #entry'
4729 // number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
4730 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4734 uint32 entry
= atol(cId
);
4736 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
4740 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
4741 SetSentErrorMessage(true);
4745 // remove all quest entries for 'entry' from quest log
4746 for(uint8 slot
= 0; slot
< MAX_QUEST_LOG_SIZE
; ++slot
)
4748 uint32 quest
= player
->GetQuestSlotQuestId(slot
);
4751 player
->SetQuestSlot(slot
,0);
4753 // we ignore unequippable quest items in this case, its' still be equipped
4754 player
->TakeQuestSourceItem( quest
, false );
4758 // set quest status to not started (will updated in DB at next save)
4759 player
->SetQuestStatus( entry
, QUEST_STATUS_NONE
);
4761 // reset rewarded for restart repeatable quest
4762 player
->getQuestStatusMap()[entry
].m_rewarded
= false;
4764 SendSysMessage(LANG_COMMAND_QUEST_REMOVED
);
4768 bool ChatHandler::HandleQuestComplete(const char* args
)
4770 Player
* player
= getSelectedPlayer();
4773 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4774 SetSentErrorMessage(true);
4778 // .quest complete #entry
4779 // number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
4780 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4784 uint32 entry
= atol(cId
);
4786 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
4788 // If player doesn't have the quest
4789 if(!pQuest
|| player
->GetQuestStatus(entry
) == QUEST_STATUS_NONE
)
4791 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
4792 SetSentErrorMessage(true);
4796 // Add quest items for quests that require items
4797 for(uint8 x
= 0; x
< QUEST_OBJECTIVES_COUNT
; ++x
)
4799 uint32 id
= pQuest
->ReqItemId
[x
];
4800 uint32 count
= pQuest
->ReqItemCount
[x
];
4804 uint32 curItemCount
= player
->GetItemCount(id
,true);
4806 ItemPosCountVec dest
;
4807 uint8 msg
= player
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, id
, count
-curItemCount
);
4808 if( msg
== EQUIP_ERR_OK
)
4810 Item
* item
= player
->StoreNewItem( dest
, id
, true);
4811 player
->SendNewItem(item
,count
-curItemCount
,true,false);
4815 // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
4816 for(uint8 i
= 0; i
< QUEST_OBJECTIVES_COUNT
; ++i
)
4818 uint32 creature
= pQuest
->ReqCreatureOrGOId
[i
];
4819 uint32 creaturecount
= pQuest
->ReqCreatureOrGOCount
[i
];
4821 if(uint32 spell_id
= pQuest
->ReqSpell
[i
])
4823 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4824 player
->CastedCreatureOrGO(creature
,0,spell_id
);
4826 else if(creature
> 0)
4828 if(CreatureInfo
const* cInfo
= objmgr
.GetCreatureTemplate(creature
))
4829 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4830 player
->KilledMonster(cInfo
,0);
4832 else if(creature
< 0)
4834 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4835 player
->CastedCreatureOrGO(creature
,0,0);
4839 // If the quest requires reputation to complete
4840 if(uint32 repFaction
= pQuest
->GetRepObjectiveFaction())
4842 uint32 repValue
= pQuest
->GetRepObjectiveValue();
4843 uint32 curRep
= player
->GetReputationMgr().GetReputation(repFaction
);
4844 if(curRep
< repValue
)
4845 if(FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry(repFaction
))
4846 player
->GetReputationMgr().SetReputation(factionEntry
,repValue
);
4849 // If the quest requires money
4850 int32 ReqOrRewMoney
= pQuest
->GetRewOrReqMoney();
4851 if(ReqOrRewMoney
< 0)
4852 player
->ModifyMoney(-ReqOrRewMoney
);
4854 player
->CompleteQuest(entry
);
4858 bool ChatHandler::HandleBanAccountCommand(const char* args
)
4860 return HandleBanHelper(BAN_ACCOUNT
,args
);
4863 bool ChatHandler::HandleBanCharacterCommand(const char* args
)
4865 return HandleBanHelper(BAN_CHARACTER
,args
);
4868 bool ChatHandler::HandleBanIPCommand(const char* args
)
4870 return HandleBanHelper(BAN_IP
,args
);
4873 bool ChatHandler::HandleBanHelper(BanMode mode
, const char* args
)
4878 char* cnameOrIP
= strtok ((char*)args
, " ");
4882 std::string nameOrIP
= cnameOrIP
;
4884 char* duration
= strtok (NULL
," ");
4885 if(!duration
|| !atoi(duration
))
4888 char* reason
= strtok (NULL
,"");
4895 if (!AccountMgr::normalizeString(nameOrIP
))
4897 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
4898 SetSentErrorMessage(true);
4903 if(!normalizePlayerName(nameOrIP
))
4905 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4906 SetSentErrorMessage(true);
4911 if(!IsIPAddress(nameOrIP
.c_str()))
4916 switch(sWorld
.BanAccount(mode
, nameOrIP
, duration
, reason
,m_session
? m_session
->GetPlayerName() : ""))
4919 if(atoi(duration
)>0)
4920 PSendSysMessage(LANG_BAN_YOUBANNED
,nameOrIP
.c_str(),secsToTimeString(TimeStringToSecs(duration
),true).c_str(),reason
);
4922 PSendSysMessage(LANG_BAN_YOUPERMBANNED
,nameOrIP
.c_str(),reason
);
4924 case BAN_SYNTAX_ERROR
:
4930 PSendSysMessage(LANG_BAN_NOTFOUND
,"account",nameOrIP
.c_str());
4933 PSendSysMessage(LANG_BAN_NOTFOUND
,"character",nameOrIP
.c_str());
4936 PSendSysMessage(LANG_BAN_NOTFOUND
,"ip",nameOrIP
.c_str());
4939 SetSentErrorMessage(true);
4946 bool ChatHandler::HandleUnBanAccountCommand(const char* args
)
4948 return HandleUnBanHelper(BAN_ACCOUNT
,args
);
4951 bool ChatHandler::HandleUnBanCharacterCommand(const char* args
)
4953 return HandleUnBanHelper(BAN_CHARACTER
,args
);
4956 bool ChatHandler::HandleUnBanIPCommand(const char* args
)
4958 return HandleUnBanHelper(BAN_IP
,args
);
4961 bool ChatHandler::HandleUnBanHelper(BanMode mode
, const char* args
)
4966 char* cnameOrIP
= strtok ((char*)args
, " ");
4970 std::string nameOrIP
= cnameOrIP
;
4975 if (!AccountMgr::normalizeString(nameOrIP
))
4977 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
4978 SetSentErrorMessage(true);
4983 if(!normalizePlayerName(nameOrIP
))
4985 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4986 SetSentErrorMessage(true);
4991 if(!IsIPAddress(nameOrIP
.c_str()))
4996 if(sWorld
.RemoveBanAccount(mode
,nameOrIP
))
4997 PSendSysMessage(LANG_UNBAN_UNBANNED
,nameOrIP
.c_str());
4999 PSendSysMessage(LANG_UNBAN_ERROR
,nameOrIP
.c_str());
5004 bool ChatHandler::HandleBanInfoAccountCommand(const char* args
)
5009 char* cname
= strtok((char*)args
, "");
5013 std::string account_name
= cname
;
5014 if (!AccountMgr::normalizeString(account_name
))
5016 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5017 SetSentErrorMessage(true);
5021 uint32 accountid
= accmgr
.GetId(account_name
);
5024 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5028 return HandleBanInfoHelper(accountid
,account_name
.c_str());
5031 bool ChatHandler::HandleBanInfoCharacterCommand(const char* args
)
5035 if (!extractPlayerTarget((char*)args
,&target
,&target_guid
))
5038 uint32 accountid
= target
? target
->GetSession()->GetAccountId() : objmgr
.GetPlayerAccountIdByGUID(target_guid
);
5040 std::string accountname
;
5041 if (!accmgr
.GetName(accountid
,accountname
))
5043 PSendSysMessage(LANG_BANINFO_NOCHARACTER
);
5047 return HandleBanInfoHelper(accountid
,accountname
.c_str());
5050 bool ChatHandler::HandleBanInfoHelper(uint32 accountid
, char const* accountname
)
5052 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
);
5055 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN
, accountname
);
5059 PSendSysMessage(LANG_BANINFO_BANHISTORY
,accountname
);
5062 Field
* fields
= result
->Fetch();
5064 time_t unbandate
= time_t(fields
[3].GetUInt64());
5065 bool active
= false;
5066 if(fields
[2].GetBool() && (fields
[1].GetUInt64() == (uint64
)0 ||unbandate
>= time(NULL
)) )
5068 bool permanent
= (fields
[1].GetUInt64() == (uint64
)0);
5069 std::string bantime
= permanent
?GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[1].GetUInt64(), true);
5070 PSendSysMessage(LANG_BANINFO_HISTORYENTRY
,
5071 fields
[0].GetString(), bantime
.c_str(), active
? GetMangosString(LANG_BANINFO_YES
):GetMangosString(LANG_BANINFO_NO
), fields
[4].GetString(), fields
[5].GetString());
5072 }while (result
->NextRow());
5078 bool ChatHandler::HandleBanInfoIPCommand(const char* args
)
5083 char* cIP
= strtok ((char*)args
, "");
5087 if (!IsIPAddress(cIP
))
5090 std::string IP
= cIP
;
5092 loginDatabase
.escape_string(IP
);
5093 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());
5096 PSendSysMessage(LANG_BANINFO_NOIP
);
5100 Field
*fields
= result
->Fetch();
5101 bool permanent
= !fields
[6].GetUInt64();
5102 PSendSysMessage(LANG_BANINFO_IPENTRY
,
5103 fields
[0].GetString(), fields
[1].GetString(), permanent
? GetMangosString(LANG_BANINFO_NEVER
):fields
[2].GetString(),
5104 permanent
? GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[3].GetUInt64(), true).c_str(), fields
[4].GetString(), fields
[5].GetString());
5109 bool ChatHandler::HandleBanListCharacterCommand(const char* args
)
5111 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5113 char* cFilter
= strtok ((char*)args
, " ");
5117 std::string filter
= cFilter
;
5118 loginDatabase
.escape_string(filter
);
5119 QueryResult
* result
= CharacterDatabase
.PQuery("SELECT account FROM characters WHERE name "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'"),filter
.c_str());
5122 PSendSysMessage(LANG_BANLIST_NOCHARACTER
);
5126 return HandleBanListHelper(result
);
5129 bool ChatHandler::HandleBanListAccountCommand(const char* args
)
5131 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5133 char* cFilter
= strtok((char*)args
, " ");
5134 std::string filter
= cFilter
? cFilter
: "";
5135 loginDatabase
.escape_string(filter
);
5137 QueryResult
* result
;
5141 result
= loginDatabase
.Query("SELECT account.id, username FROM account, account_banned"
5142 " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
5146 result
= loginDatabase
.PQuery("SELECT account.id, username FROM account, account_banned"
5147 " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
5153 PSendSysMessage(LANG_BANLIST_NOACCOUNT
);
5157 return HandleBanListHelper(result
);
5160 bool ChatHandler::HandleBanListHelper(QueryResult
* result
)
5162 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT
);
5164 // Chat short output
5169 Field
* fields
= result
->Fetch();
5170 uint32 accountid
= fields
[0].GetUInt32();
5172 QueryResult
* banresult
= loginDatabase
.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid
);
5175 Field
* fields2
= banresult
->Fetch();
5176 PSendSysMessage("%s",fields2
[0].GetString());
5179 } while (result
->NextRow());
5181 // Console wide output
5184 SendSysMessage(LANG_BANLIST_ACCOUNTS
);
5185 SendSysMessage("===============================================================================");
5186 SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER
);
5189 SendSysMessage("-------------------------------------------------------------------------------");
5190 Field
*fields
= result
->Fetch();
5191 uint32 account_id
= fields
[0].GetUInt32 ();
5193 std::string account_name
;
5195 // "account" case, name can be get in same query
5196 if(result
->GetFieldCount() > 1)
5197 account_name
= fields
[1].GetCppString();
5198 // "character" case, name need extract from another DB
5200 accmgr
.GetName (account_id
,account_name
);
5202 // No SQL injection. id is uint32.
5203 QueryResult
*banInfo
= loginDatabase
.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id
);
5206 Field
*fields2
= banInfo
->Fetch();
5209 time_t t_ban
= fields2
[0].GetUInt64();
5210 tm
* aTm_ban
= localtime(&t_ban
);
5212 if (fields2
[0].GetUInt64() == fields2
[1].GetUInt64())
5214 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5215 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
,
5216 fields2
[2].GetString(),fields2
[3].GetString());
5220 time_t t_unban
= fields2
[1].GetUInt64();
5221 tm
* aTm_unban
= localtime(&t_unban
);
5222 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5223 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
,
5224 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5225 fields2
[2].GetString(),fields2
[3].GetString());
5227 }while ( banInfo
->NextRow() );
5230 }while( result
->NextRow() );
5231 SendSysMessage("===============================================================================");
5238 bool ChatHandler::HandleBanListIPCommand(const char* args
)
5240 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5242 char* cFilter
= strtok((char*)args
, " ");
5243 std::string filter
= cFilter
? cFilter
: "";
5244 loginDatabase
.escape_string(filter
);
5246 QueryResult
* result
;
5250 result
= loginDatabase
.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5251 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
5252 " ORDER BY unbandate" );
5256 result
= loginDatabase
.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5257 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")
5258 " ORDER BY unbandate",filter
.c_str() );
5263 PSendSysMessage(LANG_BANLIST_NOIP
);
5267 PSendSysMessage(LANG_BANLIST_MATCHINGIP
);
5268 // Chat short output
5273 Field
* fields
= result
->Fetch();
5274 PSendSysMessage("%s",fields
[0].GetString());
5275 } while (result
->NextRow());
5277 // Console wide output
5280 SendSysMessage(LANG_BANLIST_IPS
);
5281 SendSysMessage("===============================================================================");
5282 SendSysMessage(LANG_BANLIST_IPS_HEADER
);
5285 SendSysMessage("-------------------------------------------------------------------------------");
5286 Field
*fields
= result
->Fetch();
5287 time_t t_ban
= fields
[1].GetUInt64();
5288 tm
* aTm_ban
= localtime(&t_ban
);
5289 if ( fields
[1].GetUInt64() == fields
[2].GetUInt64() )
5291 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5292 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
,
5293 fields
[3].GetString(), fields
[4].GetString());
5297 time_t t_unban
= fields
[2].GetUInt64();
5298 tm
* aTm_unban
= localtime(&t_unban
);
5299 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5300 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
,
5301 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5302 fields
[3].GetString(), fields
[4].GetString());
5304 }while( result
->NextRow() );
5305 SendSysMessage("===============================================================================");
5312 bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
5314 Player
* pl
= m_session
->GetPlayer();
5316 // accept only explicitly selected target (not implicitly self targeting case)
5317 Unit
* target
= getSelectedUnit();
5318 if(pl
->GetSelection() && target
)
5320 if(target
->GetTypeId()!=TYPEID_UNIT
)
5322 SendSysMessage(LANG_SELECT_CREATURE
);
5323 SetSentErrorMessage(true);
5327 if(target
->isDead())
5328 ((Creature
*)target
)->Respawn();
5332 CellPair
p(MaNGOS::ComputeCellPair(pl
->GetPositionX(), pl
->GetPositionY()));
5334 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
5337 MaNGOS::RespawnDo u_do
;
5338 MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
> worker(pl
,u_do
);
5340 TypeContainerVisitor
<MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
>, GridTypeMapContainer
> obj_worker(worker
);
5341 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
5342 cell_lock
->Visit(cell_lock
, obj_worker
, *pl
->GetMap());
5347 bool ChatHandler::HandleGMFlyCommand(const char* args
)
5352 Player
*target
= getSelectedPlayer();
5354 target
= m_session
->GetPlayer();
5356 WorldPacket
data(12);
5357 if (strncmp(args
, "on", 3) == 0)
5358 data
.SetOpcode(SMSG_MOVE_SET_CAN_FLY
);
5359 else if (strncmp(args
, "off", 4) == 0)
5360 data
.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY
);
5363 SendSysMessage(LANG_USE_BOL
);
5366 data
.append(target
->GetPackGUID());
5367 data
<< uint32(0); // unknown
5368 target
->SendMessageToSet(&data
, true);
5369 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS
, GetNameLink(target
).c_str(), args
);
5373 bool ChatHandler::HandlePDumpLoadCommand(const char *args
)
5378 char * file
= strtok((char*)args
, " ");
5382 char * account
= strtok(NULL
, " ");
5386 std::string account_name
= account
;
5387 if (!AccountMgr::normalizeString(account_name
))
5389 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5390 SetSentErrorMessage(true);
5394 uint32 account_id
= accmgr
.GetId(account_name
);
5397 account_id
= atoi(account
); // use original string
5400 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5401 SetSentErrorMessage(true);
5406 if (!accmgr
.GetName(account_id
,account_name
))
5408 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5409 SetSentErrorMessage(true);
5413 char* guid_str
= NULL
;
5414 char* name_str
= strtok(NULL
, " ");
5420 // normalize the name if specified and check if it exists
5421 if (!normalizePlayerName(name
))
5423 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5424 SetSentErrorMessage(true);
5428 if (ObjectMgr::CheckPlayerName(name
,true) != CHAR_NAME_SUCCESS
)
5430 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5431 SetSentErrorMessage(true);
5435 guid_str
= strtok(NULL
, " ");
5442 guid
= atoi(guid_str
);
5445 PSendSysMessage(LANG_INVALID_CHARACTER_GUID
);
5446 SetSentErrorMessage(true);
5450 if (objmgr
.GetPlayerAccountIdByGUID(guid
))
5452 PSendSysMessage(LANG_CHARACTER_GUID_IN_USE
,guid
);
5453 SetSentErrorMessage(true);
5458 switch(PlayerDumpReader().LoadDump(file
, account_id
, name
, guid
))
5461 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS
);
5463 case DUMP_FILE_OPEN_ERROR
:
5464 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
5465 SetSentErrorMessage(true);
5467 case DUMP_FILE_BROKEN
:
5468 PSendSysMessage(LANG_DUMP_BROKEN
,file
);
5469 SetSentErrorMessage(true);
5471 case DUMP_TOO_MANY_CHARS
:
5472 PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL
,account_name
.c_str(),account_id
);
5473 SetSentErrorMessage(true);
5476 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED
);
5477 SetSentErrorMessage(true);
5484 bool ChatHandler::HandlePDumpWriteCommand(const char *args
)
5489 char* file
= strtok((char*)args
, " ");
5490 char* p2
= strtok(NULL
, " ");
5496 // character name can't start from number
5497 if (isNumeric(p2
[0]))
5501 std::string name
= extractPlayerNameFromLink(p2
);
5504 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5505 SetSentErrorMessage(true);
5509 guid
= objmgr
.GetPlayerGUIDByName(name
);
5512 if(!objmgr
.GetPlayerAccountIdByGUID(guid
))
5514 PSendSysMessage(LANG_PLAYER_NOT_FOUND
);
5515 SetSentErrorMessage(true);
5519 switch(PlayerDumpWriter().WriteDump(file
, guid
))
5522 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS
);
5524 case DUMP_FILE_OPEN_ERROR
:
5525 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
5526 SetSentErrorMessage(true);
5529 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED
);
5530 SetSentErrorMessage(true);
5537 bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
5539 Unit
* unit
= getSelectedUnit();
5542 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5543 SetSentErrorMessage(true);
5547 PSendSysMessage(LANG_MOVEGENS_LIST
,(unit
->GetTypeId()==TYPEID_PLAYER
? "Player" : "Creature" ),unit
->GetGUIDLow());
5549 MotionMaster
* mm
= unit
->GetMotionMaster();
5550 for(MotionMaster::const_iterator itr
= mm
->begin(); itr
!= mm
->end(); ++itr
)
5552 switch((*itr
)->GetMovementGeneratorType())
5554 case IDLE_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_IDLE
); break;
5555 case RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_RANDOM
); break;
5556 case WAYPOINT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_WAYPOINT
); break;
5557 case ANIMAL_RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_ANIMAL_RANDOM
); break;
5558 case CONFUSED_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_CONFUSED
); break;
5559 case TARGETED_MOTION_TYPE
:
5561 if(unit
->GetTypeId()==TYPEID_PLAYER
)
5563 TargetedMovementGenerator
<Player
> const* mgen
= static_cast<TargetedMovementGenerator
<Player
> const*>(*itr
);
5564 Unit
* target
= mgen
->GetTarget();
5566 PSendSysMessage(LANG_MOVEGENS_TARGETED_PLAYER
,target
->GetName(),target
->GetGUIDLow());
5568 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL
);
5572 TargetedMovementGenerator
<Creature
> const* mgen
= static_cast<TargetedMovementGenerator
<Creature
> const*>(*itr
);
5573 Unit
* target
= mgen
->GetTarget();
5575 PSendSysMessage(LANG_MOVEGENS_TARGETED_CREATURE
,target
->GetName(),target
->GetGUIDLow());
5577 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL
);
5581 case HOME_MOTION_TYPE
:
5582 if(unit
->GetTypeId()==TYPEID_UNIT
)
5585 (*itr
)->GetDestination(x
,y
,z
);
5586 PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE
,x
,y
,z
);
5589 SendSysMessage(LANG_MOVEGENS_HOME_PLAYER
);
5591 case FLIGHT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FLIGHT
); break;
5592 case POINT_MOTION_TYPE
:
5595 (*itr
)->GetDestination(x
,y
,z
);
5596 PSendSysMessage(LANG_MOVEGENS_POINT
,x
,y
,z
);
5599 case FLEEING_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FEAR
); break;
5600 case DISTRACT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_DISTRACT
); break;
5602 PSendSysMessage(LANG_MOVEGENS_UNKNOWN
,(*itr
)->GetMovementGeneratorType());
5609 bool ChatHandler::HandleServerPLimitCommand(const char *args
)
5613 char* param
= strtok((char*)args
, " ");
5617 int l
= strlen(param
);
5619 if( strncmp(param
,"player",l
) == 0 )
5620 sWorld
.SetPlayerLimit(-SEC_PLAYER
);
5621 else if(strncmp(param
,"moderator",l
) == 0 )
5622 sWorld
.SetPlayerLimit(-SEC_MODERATOR
);
5623 else if(strncmp(param
,"gamemaster",l
) == 0 )
5624 sWorld
.SetPlayerLimit(-SEC_GAMEMASTER
);
5625 else if(strncmp(param
,"administrator",l
) == 0 )
5626 sWorld
.SetPlayerLimit(-SEC_ADMINISTRATOR
);
5627 else if(strncmp(param
,"reset",l
) == 0 )
5628 sWorld
.SetPlayerLimit( sConfig
.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT
) );
5631 int val
= atoi(param
);
5632 if(val
< -SEC_ADMINISTRATOR
) val
= -SEC_ADMINISTRATOR
;
5634 sWorld
.SetPlayerLimit(val
);
5637 // kick all low security level players
5638 if(sWorld
.GetPlayerAmountLimit() > SEC_PLAYER
)
5639 sWorld
.KickAllLess(sWorld
.GetPlayerSecurityLimit());
5642 uint32 pLimit
= sWorld
.GetPlayerAmountLimit();
5643 AccountTypes allowedAccountType
= sWorld
.GetPlayerSecurityLimit();
5644 char const* secName
= "";
5645 switch(allowedAccountType
)
5647 case SEC_PLAYER
: secName
= "Player"; break;
5648 case SEC_MODERATOR
: secName
= "Moderator"; break;
5649 case SEC_GAMEMASTER
: secName
= "Gamemaster"; break;
5650 case SEC_ADMINISTRATOR
: secName
= "Administrator"; break;
5651 default: secName
= "<unknown>"; break;
5654 PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit
,secName
);
5659 bool ChatHandler::HandleCastCommand(const char* args
)
5664 Unit
* target
= getSelectedUnit();
5668 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5669 SetSentErrorMessage(true);
5673 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5674 uint32 spell
= extractSpellIdFromLink((char*)args
);
5678 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5682 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5684 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5685 SetSentErrorMessage(true);
5689 char* trig_str
= strtok(NULL
, " ");
5692 int l
= strlen(trig_str
);
5693 if(strncmp(trig_str
,"triggered",l
) != 0 )
5697 bool triggered
= (trig_str
!= NULL
);
5699 m_session
->GetPlayer()->CastSpell(target
,spell
,triggered
);
5704 bool ChatHandler::HandleCastBackCommand(const char* args
)
5706 Creature
* caster
= getSelectedCreature();
5710 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5711 SetSentErrorMessage(true);
5715 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
5716 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5717 uint32 spell
= extractSpellIdFromLink((char*)args
);
5718 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
5721 char* trig_str
= strtok(NULL
, " ");
5724 int l
= strlen(trig_str
);
5725 if(strncmp(trig_str
,"triggered",l
) != 0 )
5729 bool triggered
= (trig_str
!= NULL
);
5731 // update orientation at server
5732 caster
->SetOrientation(caster
->GetAngle(m_session
->GetPlayer()));
5736 caster
->BuildHeartBeatMsg(&data
);
5737 caster
->SendMessageToSet(&data
,true);
5739 caster
->CastSpell(m_session
->GetPlayer(),spell
,triggered
);
5744 bool ChatHandler::HandleCastDistCommand(const char* args
)
5749 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5750 uint32 spell
= extractSpellIdFromLink((char*)args
);
5754 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5758 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5760 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5761 SetSentErrorMessage(true);
5765 char *distStr
= strtok(NULL
, " ");
5770 sscanf(distStr
, "%f", &dist
);
5772 char* trig_str
= strtok(NULL
, " ");
5775 int l
= strlen(trig_str
);
5776 if(strncmp(trig_str
,"triggered",l
) != 0 )
5780 bool triggered
= (trig_str
!= NULL
);
5783 m_session
->GetPlayer()->GetClosePoint(x
,y
,z
,dist
);
5785 m_session
->GetPlayer()->CastSpell(x
,y
,z
,spell
,triggered
);
5789 bool ChatHandler::HandleCastTargetCommand(const char* args
)
5791 Creature
* caster
= getSelectedCreature();
5795 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5796 SetSentErrorMessage(true);
5800 if(!caster
->getVictim())
5802 SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM
);
5803 SetSentErrorMessage(true);
5807 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5808 uint32 spell
= extractSpellIdFromLink((char*)args
);
5809 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
5812 char* trig_str
= strtok(NULL
, " ");
5815 int l
= strlen(trig_str
);
5816 if(strncmp(trig_str
,"triggered",l
) != 0 )
5820 bool triggered
= (trig_str
!= NULL
);
5822 // update orientation at server
5823 caster
->SetOrientation(caster
->GetAngle(m_session
->GetPlayer()));
5827 caster
->BuildHeartBeatMsg(&data
);
5828 caster
->SendMessageToSet(&data
,true);
5830 caster
->CastSpell(caster
->getVictim(),spell
,triggered
);
5836 ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
5837 Without this function 3rd party scripting library will get linking errors (unresolved external)
5838 when attempting to use the PointMovementGenerator
5840 bool ChatHandler::HandleComeToMeCommand(const char *args
)
5842 Creature
* caster
= getSelectedCreature();
5846 SendSysMessage(LANG_SELECT_CREATURE
);
5847 SetSentErrorMessage(true);
5851 char* newFlagStr
= strtok((char*)args
, " ");
5856 uint32 newFlags
= atoi(newFlagStr
);
5858 caster
->SetMonsterMoveFlags(MonsterMovementFlags(newFlags
));
5860 Player
* pl
= m_session
->GetPlayer();
5862 caster
->GetMotionMaster()->MovePoint(0, pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ());
5866 bool ChatHandler::HandleCastSelfCommand(const char* args
)
5871 Unit
* target
= getSelectedUnit();
5875 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5876 SetSentErrorMessage(true);
5880 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5881 uint32 spell
= extractSpellIdFromLink((char*)args
);
5885 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5889 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5891 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5892 SetSentErrorMessage(true);
5896 target
->CastSpell(target
,spell
,false);
5901 std::string
GetTimeString(uint32 time
)
5903 uint16 days
= time
/ DAY
, hours
= (time
% DAY
) / HOUR
, minute
= (time
% HOUR
) / MINUTE
;
5904 std::ostringstream ss
;
5905 if(days
) ss
<< days
<< "d ";
5906 if(hours
) ss
<< hours
<< "h ";
5907 ss
<< minute
<< "m";
5911 bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
5913 Player
* player
= getSelectedPlayer();
5914 if (!player
) player
= m_session
->GetPlayer();
5916 for(uint8 i
= 0; i
< MAX_DIFFICULTY
; ++i
)
5918 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(Difficulty(i
));
5919 for(Player::BoundInstancesMap::const_iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
5921 InstanceSave
*save
= itr
->second
.save
;
5922 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
5923 PSendSysMessage("map: %d inst: %d perm: %s diff: %s canReset: %s TTR: %s", itr
->first
, save
->GetInstanceId(), itr
->second
.perm
? "yes" : "no", save
->GetDifficulty() == DUNGEON_DIFFICULTY_NORMAL
? "normal" : "heroic", save
->CanReset() ? "yes" : "no", timeleft
.c_str());
5927 PSendSysMessage("player binds: %d", counter
);
5929 Group
*group
= player
->GetGroup();
5932 for(uint8 i
= 0; i
< MAX_DIFFICULTY
; ++i
)
5934 Group::BoundInstancesMap
&binds
= group
->GetBoundInstances(Difficulty(i
));
5935 for(Group::BoundInstancesMap::const_iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
5937 InstanceSave
*save
= itr
->second
.save
;
5938 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
5939 PSendSysMessage("map: %d inst: %d perm: %s diff: %s canReset: %s TTR: %s", itr
->first
, save
->GetInstanceId(), itr
->second
.perm
? "yes" : "no", save
->GetDifficulty() == DUNGEON_DIFFICULTY_NORMAL
? "normal" : "heroic", save
->CanReset() ? "yes" : "no", timeleft
.c_str());
5944 PSendSysMessage("group binds: %d", counter
);
5949 bool ChatHandler::HandleInstanceUnbindCommand(const char* args
)
5954 std::string cmd
= args
;
5957 Player
* player
= getSelectedPlayer();
5958 if (!player
) player
= m_session
->GetPlayer();
5960 for(uint8 i
= 0; i
< MAX_DIFFICULTY
; ++i
)
5962 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(Difficulty(i
));
5963 for(Player::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end();)
5965 if(itr
->first
!= player
->GetMapId())
5967 InstanceSave
*save
= itr
->second
.save
;
5968 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
5969 PSendSysMessage("unbinding map: %d inst: %d perm: %s diff: %s canReset: %s TTR: %s", itr
->first
, save
->GetInstanceId(), itr
->second
.perm
? "yes" : "no", save
->GetDifficulty() == DUNGEON_DIFFICULTY_NORMAL
? "normal" : "heroic", save
->CanReset() ? "yes" : "no", timeleft
.c_str());
5970 player
->UnbindInstance(itr
, Difficulty(i
));
5977 PSendSysMessage("instances unbound: %d", counter
);
5982 bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
5984 PSendSysMessage("instances loaded: %d", MapManager::Instance().GetNumInstances());
5985 PSendSysMessage("players in instances: %d", MapManager::Instance().GetNumPlayersInInstances());
5986 PSendSysMessage("instance saves: %d", sInstanceSaveManager
.GetNumInstanceSaves());
5987 PSendSysMessage("players bound: %d", sInstanceSaveManager
.GetNumBoundPlayersTotal());
5988 PSendSysMessage("groups bound: %d", sInstanceSaveManager
.GetNumBoundGroupsTotal());
5992 bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
5994 Player
* pl
= m_session
->GetPlayer();
5996 Map
* map
= pl
->GetMap();
5997 if (!map
->IsDungeon())
5999 PSendSysMessage("Map is not a dungeon.");
6000 SetSentErrorMessage(true);
6004 if (!((InstanceMap
*)map
)->GetInstanceData())
6006 PSendSysMessage("Map has no instance data.");
6007 SetSentErrorMessage(true);
6011 ((InstanceMap
*)map
)->GetInstanceData()->SaveToDB();
6015 /// Display the list of GMs
6016 bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
6018 ///- Get the accounts with GM Level >0
6019 QueryResult
*result
= loginDatabase
.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
6022 SendSysMessage(LANG_GMLIST
);
6023 SendSysMessage("========================");
6024 SendSysMessage(LANG_GMLIST_HEADER
);
6025 SendSysMessage("========================");
6027 ///- Circle through them. Display username and GM level
6030 Field
*fields
= result
->Fetch();
6031 PSendSysMessage("|%15s|%6s|", fields
[0].GetString(),fields
[1].GetString());
6032 }while( result
->NextRow() );
6034 PSendSysMessage("========================");
6038 PSendSysMessage(LANG_GMLIST_EMPTY
);
6042 /// Define the 'Message of the day' for the realm
6043 bool ChatHandler::HandleServerSetMotdCommand(const char* args
)
6045 sWorld
.SetMotd(args
);
6046 PSendSysMessage(LANG_MOTD_NEW
, args
);
6050 /// Set/Unset the expansion level for an account
6051 bool ChatHandler::HandleAccountSetAddonCommand(const char* args
)
6053 ///- Get the command line arguments
6054 char *szAcc
= strtok((char*)args
," ");
6055 char *szExp
= strtok(NULL
," ");
6060 std::string account_name
;
6065 Player
* player
= getSelectedPlayer();
6069 account_id
= player
->GetSession()->GetAccountId();
6070 accmgr
.GetName(account_id
,account_name
);
6075 ///- Convert Account name to Upper Format
6076 account_name
= szAcc
;
6077 if (!AccountMgr::normalizeString(account_name
))
6079 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
6080 SetSentErrorMessage(true);
6084 account_id
= accmgr
.GetId(account_name
);
6087 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
6088 SetSentErrorMessage(true);
6094 // Let set addon state only for lesser (strong) security level
6095 // or to self account
6096 if (m_session
&& m_session
->GetAccountId () != account_id
&&
6097 HasLowerSecurityAccount (NULL
,account_id
,true))
6100 int lev
=atoi(szExp
); //get int anyway (0 if error)
6105 loginDatabase
.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev
,account_id
);
6106 PSendSysMessage(LANG_ACCOUNT_SETADDON
,account_name
.c_str(),account_id
,lev
);
6110 //Send items by mail
6111 bool ChatHandler::HandleSendItemsCommand(const char* args
)
6113 // format: name "subject text" "mail text" item1[:count1] item2[:count2] ... item12[:count12]
6115 uint64 receiver_guid
;
6116 std::string receiver_name
;
6117 if(!extractPlayerTarget((char*)args
,&receiver
,&receiver_guid
,&receiver_name
))
6120 char* tail1
= strtok(NULL
, "");
6124 char* msgSubject
= extractQuotedArg(tail1
);
6128 char* tail2
= strtok(NULL
, "");
6132 char* msgText
= extractQuotedArg(tail2
);
6136 // msgSubject, msgText isn't NUL after prev. check
6137 std::string subject
= msgSubject
;
6138 std::string text
= msgText
;
6141 typedef std::pair
<uint32
,uint32
> ItemPair
;
6142 typedef std::list
< ItemPair
> ItemPairs
;
6145 // get all tail string
6146 char* tail
= strtok(NULL
, "");
6148 // get from tail next item str
6149 while(char* itemStr
= strtok(tail
, " "))
6152 tail
= strtok(NULL
, "");
6155 char* itemIdStr
= strtok(itemStr
, ":");
6156 char* itemCountStr
= strtok(NULL
, " ");
6158 uint32 item_id
= atoi(itemIdStr
);
6162 ItemPrototype
const* item_proto
= objmgr
.GetItemPrototype(item_id
);
6165 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
6166 SetSentErrorMessage(true);
6170 uint32 item_count
= itemCountStr
? atoi(itemCountStr
) : 1;
6171 if (item_count
< 1 || (item_proto
->MaxCount
> 0 && item_count
> uint32(item_proto
->MaxCount
)))
6173 PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT
, item_count
,item_id
);
6174 SetSentErrorMessage(true);
6178 while(item_count
> item_proto
->GetMaxStackSize())
6180 items
.push_back(ItemPair(item_id
,item_proto
->GetMaxStackSize()));
6181 item_count
-= item_proto
->GetMaxStackSize();
6184 items
.push_back(ItemPair(item_id
,item_count
));
6186 if(items
.size() > MAX_MAIL_ITEMS
)
6188 PSendSysMessage(LANG_COMMAND_MAIL_ITEMS_LIMIT
, MAX_MAIL_ITEMS
);
6189 SetSentErrorMessage(true);
6194 // from console show not existed sender
6195 uint32 sender_guidlo
= m_session
? m_session
->GetPlayer()->GetGUIDLow() : 0;
6197 uint32 messagetype
= MAIL_NORMAL
;
6198 uint32 stationery
= MAIL_STATIONERY_GM
;
6199 uint32 itemTextId
= !text
.empty() ? objmgr
.CreateItemText( text
) : 0;
6202 MailItemsInfo mi
; // item list preparing
6204 for(ItemPairs::const_iterator itr
= items
.begin(); itr
!= items
.end(); ++itr
)
6206 if(Item
* item
= Item::CreateItem(itr
->first
,itr
->second
,m_session
? m_session
->GetPlayer() : 0))
6208 item
->SaveToDB(); // save for prevent lost at next mail load, if send fail then item will deleted
6209 mi
.AddItem(item
->GetGUIDLow(), item
->GetEntry(), item
);
6213 WorldSession::SendMailTo(receiver
,messagetype
, stationery
, sender_guidlo
, GUID_LOPART(receiver_guid
), subject
, itemTextId
, &mi
, 0, 0, MAIL_CHECK_MASK_NONE
);
6215 std::string nameLink
= playerLink(receiver_name
);
6216 PSendSysMessage(LANG_MAIL_SENT
, nameLink
.c_str());
6220 ///Send money by mail
6221 bool ChatHandler::HandleSendMoneyCommand(const char* args
)
6223 /// format: name "subject text" "mail text" money
6226 uint64 receiver_guid
;
6227 std::string receiver_name
;
6228 if(!extractPlayerTarget((char*)args
,&receiver
,&receiver_guid
,&receiver_name
))
6231 char* tail1
= strtok(NULL
, "");
6235 char* msgSubject
= extractQuotedArg(tail1
);
6239 char* tail2
= strtok(NULL
, "");
6243 char* msgText
= extractQuotedArg(tail2
);
6247 char* money_str
= strtok(NULL
, "");
6248 int32 money
= money_str
? atoi(money_str
) : 0;
6252 // msgSubject, msgText isn't NUL after prev. check
6253 std::string subject
= msgSubject
;
6254 std::string text
= msgText
;
6256 // from console show not existed sender
6257 uint32 sender_guidlo
= m_session
? m_session
->GetPlayer()->GetGUIDLow() : 0;
6259 uint32 messagetype
= MAIL_NORMAL
;
6260 uint32 stationery
= MAIL_STATIONERY_GM
;
6261 uint32 itemTextId
= !text
.empty() ? objmgr
.CreateItemText( text
) : 0;
6263 WorldSession::SendMailTo(receiver
,messagetype
, stationery
, sender_guidlo
, GUID_LOPART(receiver_guid
), subject
, itemTextId
, NULL
, money
, 0, MAIL_CHECK_MASK_NONE
);
6265 std::string nameLink
= playerLink(receiver_name
);
6266 PSendSysMessage(LANG_MAIL_SENT
, nameLink
.c_str());
6270 /// Send a message to a player in game
6271 bool ChatHandler::HandleSendMessageCommand(const char* args
)
6273 ///- Find the player
6275 if(!extractPlayerTarget((char*)args
,&rPlayer
))
6278 char* msg_str
= strtok(NULL
, "");
6282 ///- Check that he is not logging out.
6283 if(rPlayer
->GetSession()->isLogingOut())
6285 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6286 SetSentErrorMessage(true);
6290 ///- Send the message
6291 //Use SendAreaTriggerMessage for fastest delivery.
6292 rPlayer
->GetSession()->SendAreaTriggerMessage("%s", msg_str
);
6293 rPlayer
->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
6295 //Confirmation message
6296 std::string nameLink
= GetNameLink(rPlayer
);
6297 PSendSysMessage(LANG_SENDMESSAGE
,nameLink
.c_str(),msg_str
);
6301 bool ChatHandler::HandleFlushArenaPointsCommand(const char * /*args*/)
6303 sBattleGroundMgr
.DistributeArenaPoints();
6307 bool ChatHandler::HandleModifyGenderCommand(const char *args
)
6312 Player
*player
= getSelectedPlayer();
6316 PSendSysMessage(LANG_PLAYER_NOT_FOUND
);
6317 SetSentErrorMessage(true);
6321 PlayerInfo
const* info
= objmgr
.GetPlayerInfo(player
->getRace(), player
->getClass());
6325 char const* gender_str
= (char*)args
;
6326 int gender_len
= strlen(gender_str
);
6330 if(!strncmp(gender_str
, "male", gender_len
)) // MALE
6332 if(player
->getGender() == GENDER_MALE
)
6335 gender
= GENDER_MALE
;
6337 else if (!strncmp(gender_str
, "female", gender_len
)) // FEMALE
6339 if(player
->getGender() == GENDER_FEMALE
)
6342 gender
= GENDER_FEMALE
;
6346 SendSysMessage(LANG_MUST_MALE_OR_FEMALE
);
6347 SetSentErrorMessage(true);
6352 player
->SetByteValue(UNIT_FIELD_BYTES_0
, 2, gender
);
6353 player
->SetByteValue(PLAYER_BYTES_3
, 0, gender
);
6355 // Change display ID
6356 player
->InitDisplayIds();
6358 char const* gender_full
= gender
? "female" : "male";
6360 PSendSysMessage(LANG_YOU_CHANGE_GENDER
, GetNameLink(player
).c_str(), gender_full
);
6362 if (needReportToTarget(player
))
6363 ChatHandler(player
).PSendSysMessage(LANG_YOUR_GENDER_CHANGED
, gender_full
, GetNameLink().c_str());