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"
54 bool ChatHandler::HandleReloadAllCommand(const char*)
56 HandleReloadSkillFishingBaseLevelCommand("");
58 HandleReloadAllAchievementCommand("");
59 HandleReloadAllAreaCommand("");
60 HandleReloadAllLootCommand("");
61 HandleReloadAllNpcCommand("");
62 HandleReloadAllQuestCommand("");
63 HandleReloadAllSpellCommand("");
64 HandleReloadAllItemCommand("");
65 HandleReloadAllLocalesCommand("");
67 HandleReloadCommandCommand("");
68 HandleReloadReservedNameCommand("");
69 HandleReloadMangosStringCommand("");
70 HandleReloadGameTeleCommand("");
74 bool ChatHandler::HandleReloadAllAchievementCommand(const char*)
76 HandleReloadAchievementCriteriaDataCommand("");
77 HandleReloadAchievementRewardCommand("");
81 bool ChatHandler::HandleReloadAllAreaCommand(const char*)
83 //HandleReloadQuestAreaTriggersCommand(""); -- reloaded in HandleReloadAllQuestCommand
84 HandleReloadAreaTriggerTeleportCommand("");
85 HandleReloadAreaTriggerTavernCommand("");
86 HandleReloadGameGraveyardZoneCommand("");
90 bool ChatHandler::HandleReloadAllLootCommand(const char*)
92 sLog
.outString( "Re-Loading Loot Tables..." );
94 SendGlobalSysMessage("DB tables `*_loot_template` reloaded.");
98 bool ChatHandler::HandleReloadAllNpcCommand(const char* /*args*/)
100 HandleReloadNpcGossipCommand("a");
101 HandleReloadNpcOptionCommand("a");
102 HandleReloadNpcTrainerCommand("a");
103 HandleReloadNpcVendorCommand("a");
104 HandleReloadPointsOfInterestCommand("a");
105 HandleReloadSpellClickSpellsCommand("a");
109 bool ChatHandler::HandleReloadAllQuestCommand(const char* /*args*/)
111 HandleReloadQuestAreaTriggersCommand("a");
112 HandleReloadQuestTemplateCommand("a");
114 sLog
.outString( "Re-Loading Quests Relations..." );
115 objmgr
.LoadQuestRelations();
116 SendGlobalSysMessage("DB tables `*_questrelation` and `*_involvedrelation` reloaded.");
120 bool ChatHandler::HandleReloadAllScriptsCommand(const char*)
122 if(sWorld
.IsScriptScheduled())
124 PSendSysMessage("DB scripts used currently, please attempt reload later.");
125 SetSentErrorMessage(true);
129 sLog
.outString( "Re-Loading Scripts..." );
130 HandleReloadGameObjectScriptsCommand("a");
131 HandleReloadEventScriptsCommand("a");
132 HandleReloadQuestEndScriptsCommand("a");
133 HandleReloadQuestStartScriptsCommand("a");
134 HandleReloadSpellScriptsCommand("a");
135 SendGlobalSysMessage("DB tables `*_scripts` reloaded.");
136 HandleReloadDbScriptStringCommand("a");
140 bool ChatHandler::HandleReloadAllSpellCommand(const char*)
142 HandleReloadSkillDiscoveryTemplateCommand("a");
143 HandleReloadSkillExtraItemTemplateCommand("a");
144 HandleReloadSpellAffectCommand("a");
145 HandleReloadSpellAreaCommand("a");
146 HandleReloadSpellChainCommand("a");
147 HandleReloadSpellElixirCommand("a");
148 HandleReloadSpellLearnSpellCommand("a");
149 HandleReloadSpellProcEventCommand("a");
150 HandleReloadSpellBonusesCommand("a");
151 HandleReloadSpellScriptTargetCommand("a");
152 HandleReloadSpellTargetPositionCommand("a");
153 HandleReloadSpellThreatsCommand("a");
154 HandleReloadSpellPetAurasCommand("a");
158 bool ChatHandler::HandleReloadAllItemCommand(const char*)
160 HandleReloadPageTextsCommand("a");
161 HandleReloadItemEnchantementsCommand("a");
165 bool ChatHandler::HandleReloadAllLocalesCommand(const char* /*args*/)
167 HandleReloadLocalesAchievementRewardCommand("a");
168 HandleReloadLocalesCreatureCommand("a");
169 HandleReloadLocalesGameobjectCommand("a");
170 HandleReloadLocalesItemCommand("a");
171 HandleReloadLocalesNpcTextCommand("a");
172 HandleReloadLocalesPageTextCommand("a");
173 HandleReloadLocalesPointsOfInterestCommand("a");
174 HandleReloadLocalesQuestCommand("a");
178 bool ChatHandler::HandleReloadConfigCommand(const char* /*args*/)
180 sLog
.outString( "Re-Loading config settings..." );
181 sWorld
.LoadConfigSettings(true);
182 SendGlobalSysMessage("World config settings reloaded.");
186 bool ChatHandler::HandleReloadAchievementCriteriaDataCommand(const char*)
188 sLog
.outString( "Re-Loading Additional Achievement Criteria Data..." );
189 achievementmgr
.LoadAchievementCriteriaData();
190 SendGlobalSysMessage("DB table `achievement_criteria_data` reloaded.");
194 bool ChatHandler::HandleReloadAchievementRewardCommand(const char*)
196 sLog
.outString( "Re-Loading Achievement Reward Data..." );
197 achievementmgr
.LoadRewards();
198 SendGlobalSysMessage("DB table `achievement_reward` reloaded.");
202 bool ChatHandler::HandleReloadAreaTriggerTavernCommand(const char*)
204 sLog
.outString( "Re-Loading Tavern Area Triggers..." );
205 objmgr
.LoadTavernAreaTriggers();
206 SendGlobalSysMessage("DB table `areatrigger_tavern` reloaded.");
210 bool ChatHandler::HandleReloadAreaTriggerTeleportCommand(const char*)
212 sLog
.outString( "Re-Loading AreaTrigger teleport definitions..." );
213 objmgr
.LoadAreaTriggerTeleports();
214 SendGlobalSysMessage("DB table `areatrigger_teleport` reloaded.");
218 bool ChatHandler::HandleReloadCommandCommand(const char*)
220 load_command_table
= true;
221 SendGlobalSysMessage("DB table `command` will be reloaded at next chat command use.");
225 bool ChatHandler::HandleReloadCreatureQuestRelationsCommand(const char*)
227 sLog
.outString( "Loading Quests Relations... (`creature_questrelation`)" );
228 objmgr
.LoadCreatureQuestRelations();
229 SendGlobalSysMessage("DB table `creature_questrelation` (creature quest givers) reloaded.");
233 bool ChatHandler::HandleReloadCreatureQuestInvRelationsCommand(const char*)
235 sLog
.outString( "Loading Quests Relations... (`creature_involvedrelation`)" );
236 objmgr
.LoadCreatureInvolvedRelations();
237 SendGlobalSysMessage("DB table `creature_involvedrelation` (creature quest takers) reloaded.");
241 bool ChatHandler::HandleReloadGOQuestRelationsCommand(const char*)
243 sLog
.outString( "Loading Quests Relations... (`gameobject_questrelation`)" );
244 objmgr
.LoadGameobjectQuestRelations();
245 SendGlobalSysMessage("DB table `gameobject_questrelation` (gameobject quest givers) reloaded.");
249 bool ChatHandler::HandleReloadGOQuestInvRelationsCommand(const char*)
251 sLog
.outString( "Loading Quests Relations... (`gameobject_involvedrelation`)" );
252 objmgr
.LoadGameobjectInvolvedRelations();
253 SendGlobalSysMessage("DB table `gameobject_involvedrelation` (gameobject quest takers) reloaded.");
257 bool ChatHandler::HandleReloadQuestAreaTriggersCommand(const char*)
259 sLog
.outString( "Re-Loading Quest Area Triggers..." );
260 objmgr
.LoadQuestAreaTriggers();
261 SendGlobalSysMessage("DB table `areatrigger_involvedrelation` (quest area triggers) reloaded.");
265 bool ChatHandler::HandleReloadQuestTemplateCommand(const char*)
267 sLog
.outString( "Re-Loading Quest Templates..." );
269 SendGlobalSysMessage("DB table `quest_template` (quest definitions) reloaded.");
271 /// dependent also from `gameobject` but this table not reloaded anyway
272 sLog
.outString( "Re-Loading GameObjects for quests..." );
273 objmgr
.LoadGameObjectForQuests();
274 SendGlobalSysMessage("Data GameObjects for quests reloaded.");
278 bool ChatHandler::HandleReloadLootTemplatesCreatureCommand(const char*)
280 sLog
.outString( "Re-Loading Loot Tables... (`creature_loot_template`)" );
281 LoadLootTemplates_Creature();
282 LootTemplates_Creature
.CheckLootRefs();
283 SendGlobalSysMessage("DB table `creature_loot_template` reloaded.");
287 bool ChatHandler::HandleReloadLootTemplatesDisenchantCommand(const char*)
289 sLog
.outString( "Re-Loading Loot Tables... (`disenchant_loot_template`)" );
290 LoadLootTemplates_Disenchant();
291 LootTemplates_Disenchant
.CheckLootRefs();
292 SendGlobalSysMessage("DB table `disenchant_loot_template` reloaded.");
296 bool ChatHandler::HandleReloadLootTemplatesFishingCommand(const char*)
298 sLog
.outString( "Re-Loading Loot Tables... (`fishing_loot_template`)" );
299 LoadLootTemplates_Fishing();
300 LootTemplates_Fishing
.CheckLootRefs();
301 SendGlobalSysMessage("DB table `fishing_loot_template` reloaded.");
305 bool ChatHandler::HandleReloadLootTemplatesGameobjectCommand(const char*)
307 sLog
.outString( "Re-Loading Loot Tables... (`gameobject_loot_template`)" );
308 LoadLootTemplates_Gameobject();
309 LootTemplates_Gameobject
.CheckLootRefs();
310 SendGlobalSysMessage("DB table `gameobject_loot_template` reloaded.");
314 bool ChatHandler::HandleReloadLootTemplatesItemCommand(const char*)
316 sLog
.outString( "Re-Loading Loot Tables... (`item_loot_template`)" );
317 LoadLootTemplates_Item();
318 LootTemplates_Item
.CheckLootRefs();
319 SendGlobalSysMessage("DB table `item_loot_template` reloaded.");
323 bool ChatHandler::HandleReloadLootTemplatesMillingCommand(const char*)
325 sLog
.outString( "Re-Loading Loot Tables... (`milling_loot_template`)" );
326 LoadLootTemplates_Milling();
327 LootTemplates_Milling
.CheckLootRefs();
328 SendGlobalSysMessage("DB table `milling_loot_template` reloaded.");
332 bool ChatHandler::HandleReloadLootTemplatesPickpocketingCommand(const char*)
334 sLog
.outString( "Re-Loading Loot Tables... (`pickpocketing_loot_template`)" );
335 LoadLootTemplates_Pickpocketing();
336 LootTemplates_Pickpocketing
.CheckLootRefs();
337 SendGlobalSysMessage("DB table `pickpocketing_loot_template` reloaded.");
341 bool ChatHandler::HandleReloadLootTemplatesProspectingCommand(const char*)
343 sLog
.outString( "Re-Loading Loot Tables... (`prospecting_loot_template`)" );
344 LoadLootTemplates_Prospecting();
345 LootTemplates_Prospecting
.CheckLootRefs();
346 SendGlobalSysMessage("DB table `prospecting_loot_template` reloaded.");
350 bool ChatHandler::HandleReloadLootTemplatesQuestMailCommand(const char*)
352 sLog
.outString( "Re-Loading Loot Tables... (`quest_mail_loot_template`)" );
353 LoadLootTemplates_QuestMail();
354 LootTemplates_QuestMail
.CheckLootRefs();
355 SendGlobalSysMessage("DB table `quest_mail_loot_template` reloaded.");
359 bool ChatHandler::HandleReloadLootTemplatesReferenceCommand(const char*)
361 sLog
.outString( "Re-Loading Loot Tables... (`reference_loot_template`)" );
362 LoadLootTemplates_Reference();
363 SendGlobalSysMessage("DB table `reference_loot_template` reloaded.");
367 bool ChatHandler::HandleReloadLootTemplatesSkinningCommand(const char*)
369 sLog
.outString( "Re-Loading Loot Tables... (`skinning_loot_template`)" );
370 LoadLootTemplates_Skinning();
371 LootTemplates_Skinning
.CheckLootRefs();
372 SendGlobalSysMessage("DB table `skinning_loot_template` reloaded.");
376 bool ChatHandler::HandleReloadLootTemplatesSpellCommand(const char*)
378 sLog
.outString( "Re-Loading Loot Tables... (`spell_loot_template`)" );
379 LoadLootTemplates_Spell();
380 LootTemplates_Spell
.CheckLootRefs();
381 SendGlobalSysMessage("DB table `spell_loot_template` reloaded.");
385 bool ChatHandler::HandleReloadMangosStringCommand(const char*)
387 sLog
.outString( "Re-Loading mangos_string Table!" );
388 objmgr
.LoadMangosStrings();
389 SendGlobalSysMessage("DB table `mangos_string` reloaded.");
393 bool ChatHandler::HandleReloadNpcOptionCommand(const char*)
395 sLog
.outString( "Re-Loading `npc_option` Table!" );
396 objmgr
.LoadNpcOptions();
397 SendGlobalSysMessage("DB table `npc_option` reloaded.");
401 bool ChatHandler::HandleReloadNpcGossipCommand(const char*)
403 sLog
.outString( "Re-Loading `npc_gossip` Table!" );
404 objmgr
.LoadNpcTextId();
405 SendGlobalSysMessage("DB table `npc_gossip` reloaded.");
409 bool ChatHandler::HandleReloadNpcTrainerCommand(const char*)
411 sLog
.outString( "Re-Loading `npc_trainer` Table!" );
412 objmgr
.LoadTrainerSpell();
413 SendGlobalSysMessage("DB table `npc_trainer` reloaded.");
417 bool ChatHandler::HandleReloadNpcVendorCommand(const char*)
419 sLog
.outString( "Re-Loading `npc_vendor` Table!" );
420 objmgr
.LoadVendors();
421 SendGlobalSysMessage("DB table `npc_vendor` reloaded.");
425 bool ChatHandler::HandleReloadPointsOfInterestCommand(const char*)
427 sLog
.outString( "Re-Loading `points_of_interest` Table!" );
428 objmgr
.LoadPointsOfInterest();
429 SendGlobalSysMessage("DB table `points_of_interest` reloaded.");
433 bool ChatHandler::HandleReloadSpellClickSpellsCommand(const char*)
435 sLog
.outString( "Re-Loading `npc_spellclick_spells` Table!" );
436 objmgr
.LoadNPCSpellClickSpells();
437 SendGlobalSysMessage("DB table `npc_spellclick_spells` reloaded.");
441 bool ChatHandler::HandleReloadReservedNameCommand(const char*)
443 sLog
.outString( "Loading ReservedNames... (`reserved_name`)" );
444 objmgr
.LoadReservedPlayersNames();
445 SendGlobalSysMessage("DB table `reserved_name` (player reserved names) reloaded.");
449 bool ChatHandler::HandleReloadSkillDiscoveryTemplateCommand(const char* /*args*/)
451 sLog
.outString( "Re-Loading Skill Discovery Table..." );
452 LoadSkillDiscoveryTable();
453 SendGlobalSysMessage("DB table `skill_discovery_template` (recipes discovered at crafting) reloaded.");
457 bool ChatHandler::HandleReloadSkillExtraItemTemplateCommand(const char* /*args*/)
459 sLog
.outString( "Re-Loading Skill Extra Item Table..." );
460 LoadSkillExtraItemTable();
461 SendGlobalSysMessage("DB table `skill_extra_item_template` (extra item creation when crafting) reloaded.");
465 bool ChatHandler::HandleReloadSkillFishingBaseLevelCommand(const char* /*args*/)
467 sLog
.outString( "Re-Loading Skill Fishing base level requirements..." );
468 objmgr
.LoadFishingBaseSkillLevel();
469 SendGlobalSysMessage("DB table `skill_fishing_base_level` (fishing base level for zone/subzone) reloaded.");
473 bool ChatHandler::HandleReloadSpellAffectCommand(const char*)
475 sLog
.outString( "Re-Loading SpellAffect definitions..." );
476 spellmgr
.LoadSpellAffects();
477 SendGlobalSysMessage("DB table `spell_affect` (spell mods apply requirements) reloaded.");
481 bool ChatHandler::HandleReloadSpellAreaCommand(const char*)
483 sLog
.outString( "Re-Loading SpellArea Data..." );
484 spellmgr
.LoadSpellAreas();
485 SendGlobalSysMessage("DB table `spell_area` (spell dependences from area/quest/auras state) reloaded.");
489 bool ChatHandler::HandleReloadSpellChainCommand(const char*)
491 sLog
.outString( "Re-Loading Spell Chain Data... " );
492 spellmgr
.LoadSpellChains();
493 SendGlobalSysMessage("DB table `spell_chain` (spell ranks) reloaded.");
497 bool ChatHandler::HandleReloadSpellElixirCommand(const char*)
499 sLog
.outString( "Re-Loading Spell Elixir types..." );
500 spellmgr
.LoadSpellElixirs();
501 SendGlobalSysMessage("DB table `spell_elixir` (spell elixir types) reloaded.");
505 bool ChatHandler::HandleReloadSpellLearnSpellCommand(const char*)
507 sLog
.outString( "Re-Loading Spell Learn Spells..." );
508 spellmgr
.LoadSpellLearnSpells();
509 SendGlobalSysMessage("DB table `spell_learn_spell` reloaded.");
513 bool ChatHandler::HandleReloadSpellProcEventCommand(const char*)
515 sLog
.outString( "Re-Loading Spell Proc Event conditions..." );
516 spellmgr
.LoadSpellProcEvents();
517 SendGlobalSysMessage("DB table `spell_proc_event` (spell proc trigger requirements) reloaded.");
521 bool ChatHandler::HandleReloadSpellBonusesCommand(const char*)
523 sLog
.outString( "Re-Loading Spell Bonus Data..." );
524 spellmgr
.LoadSpellBonusess();
525 SendGlobalSysMessage("DB table `spell_bonus_data` (spell damage/healing coefficients) reloaded.");
529 bool ChatHandler::HandleReloadSpellScriptTargetCommand(const char*)
531 sLog
.outString( "Re-Loading SpellsScriptTarget..." );
532 spellmgr
.LoadSpellScriptTarget();
533 SendGlobalSysMessage("DB table `spell_script_target` (spell targets selection in case specific creature/GO requirements) reloaded.");
537 bool ChatHandler::HandleReloadSpellTargetPositionCommand(const char*)
539 sLog
.outString( "Re-Loading Spell target coordinates..." );
540 spellmgr
.LoadSpellTargetPositions();
541 SendGlobalSysMessage("DB table `spell_target_position` (destination coordinates for spell targets) reloaded.");
545 bool ChatHandler::HandleReloadSpellThreatsCommand(const char*)
547 sLog
.outString( "Re-Loading Aggro Spells Definitions...");
548 spellmgr
.LoadSpellThreats();
549 SendGlobalSysMessage("DB table `spell_threat` (spell aggro definitions) reloaded.");
553 bool ChatHandler::HandleReloadSpellPetAurasCommand(const char*)
555 sLog
.outString( "Re-Loading Spell pet auras...");
556 spellmgr
.LoadSpellPetAuras();
557 SendGlobalSysMessage("DB table `spell_pet_auras` reloaded.");
561 bool ChatHandler::HandleReloadPageTextsCommand(const char*)
563 sLog
.outString( "Re-Loading Page Texts..." );
564 objmgr
.LoadPageTexts();
565 SendGlobalSysMessage("DB table `page_texts` reloaded.");
569 bool ChatHandler::HandleReloadItemEnchantementsCommand(const char*)
571 sLog
.outString( "Re-Loading Item Random Enchantments Table..." );
572 LoadRandomEnchantmentsTable();
573 SendGlobalSysMessage("DB table `item_enchantment_template` reloaded.");
577 bool ChatHandler::HandleReloadGameObjectScriptsCommand(const char* arg
)
579 if(sWorld
.IsScriptScheduled())
581 SendSysMessage("DB scripts used currently, please attempt reload later.");
582 SetSentErrorMessage(true);
587 sLog
.outString( "Re-Loading Scripts from `gameobject_scripts`...");
589 objmgr
.LoadGameObjectScripts();
592 SendGlobalSysMessage("DB table `gameobject_scripts` reloaded.");
597 bool ChatHandler::HandleReloadEventScriptsCommand(const char* arg
)
599 if(sWorld
.IsScriptScheduled())
601 SendSysMessage("DB scripts used currently, please attempt reload later.");
602 SetSentErrorMessage(true);
607 sLog
.outString( "Re-Loading Scripts from `event_scripts`...");
609 objmgr
.LoadEventScripts();
612 SendGlobalSysMessage("DB table `event_scripts` reloaded.");
617 bool ChatHandler::HandleReloadQuestEndScriptsCommand(const char* arg
)
619 if(sWorld
.IsScriptScheduled())
621 SendSysMessage("DB scripts used currently, please attempt reload later.");
622 SetSentErrorMessage(true);
627 sLog
.outString( "Re-Loading Scripts from `quest_end_scripts`...");
629 objmgr
.LoadQuestEndScripts();
632 SendGlobalSysMessage("DB table `quest_end_scripts` reloaded.");
637 bool ChatHandler::HandleReloadQuestStartScriptsCommand(const char* arg
)
639 if(sWorld
.IsScriptScheduled())
641 SendSysMessage("DB scripts used currently, please attempt reload later.");
642 SetSentErrorMessage(true);
647 sLog
.outString( "Re-Loading Scripts from `quest_start_scripts`...");
649 objmgr
.LoadQuestStartScripts();
652 SendGlobalSysMessage("DB table `quest_start_scripts` reloaded.");
657 bool ChatHandler::HandleReloadSpellScriptsCommand(const char* arg
)
659 if(sWorld
.IsScriptScheduled())
661 SendSysMessage("DB scripts used currently, please attempt reload later.");
662 SetSentErrorMessage(true);
667 sLog
.outString( "Re-Loading Scripts from `spell_scripts`...");
669 objmgr
.LoadSpellScripts();
672 SendGlobalSysMessage("DB table `spell_scripts` reloaded.");
677 bool ChatHandler::HandleReloadDbScriptStringCommand(const char* /*arg*/)
679 sLog
.outString( "Re-Loading Script strings from `db_script_string`...");
680 objmgr
.LoadDbScriptStrings();
681 SendGlobalSysMessage("DB table `db_script_string` reloaded.");
685 bool ChatHandler::HandleReloadGameGraveyardZoneCommand(const char* /*arg*/)
687 sLog
.outString( "Re-Loading Graveyard-zone links...");
689 objmgr
.LoadGraveyardZones();
691 SendGlobalSysMessage("DB table `game_graveyard_zone` reloaded.");
696 bool ChatHandler::HandleReloadGameTeleCommand(const char* /*arg*/)
698 sLog
.outString( "Re-Loading Game Tele coordinates...");
700 objmgr
.LoadGameTele();
702 SendGlobalSysMessage("DB table `game_tele` reloaded.");
707 bool ChatHandler::HandleReloadLocalesAchievementRewardCommand(const char*)
709 sLog
.outString( "Re-Loading Locales Achievement Reward Data..." );
710 achievementmgr
.LoadRewardLocales();
711 SendGlobalSysMessage("DB table `locales_achievement_reward` reloaded.");
715 bool ChatHandler::HandleReloadLocalesCreatureCommand(const char* /*arg*/)
717 sLog
.outString( "Re-Loading Locales Creature ...");
718 objmgr
.LoadCreatureLocales();
719 SendGlobalSysMessage("DB table `locales_creature` reloaded.");
723 bool ChatHandler::HandleReloadLocalesGameobjectCommand(const char* /*arg*/)
725 sLog
.outString( "Re-Loading Locales Gameobject ... ");
726 objmgr
.LoadGameObjectLocales();
727 SendGlobalSysMessage("DB table `locales_gameobject` reloaded.");
731 bool ChatHandler::HandleReloadLocalesItemCommand(const char* /*arg*/)
733 sLog
.outString( "Re-Loading Locales Item ... ");
734 objmgr
.LoadItemLocales();
735 SendGlobalSysMessage("DB table `locales_item` reloaded.");
739 bool ChatHandler::HandleReloadLocalesNpcTextCommand(const char* /*arg*/)
741 sLog
.outString( "Re-Loading Locales NPC Text ... ");
742 objmgr
.LoadNpcTextLocales();
743 SendGlobalSysMessage("DB table `locales_npc_text` reloaded.");
747 bool ChatHandler::HandleReloadLocalesPageTextCommand(const char* /*arg*/)
749 sLog
.outString( "Re-Loading Locales Page Text ... ");
750 objmgr
.LoadPageTextLocales();
751 SendGlobalSysMessage("DB table `locales_page_text` reloaded.");
755 bool ChatHandler::HandleReloadLocalesPointsOfInterestCommand(const char* /*arg*/)
757 sLog
.outString( "Re-Loading Locales Points Of Interest ... ");
758 objmgr
.LoadPointOfInterestLocales();
759 SendGlobalSysMessage("DB table `locales_points_of_interest` reloaded.");
763 bool ChatHandler::HandleReloadLocalesQuestCommand(const char* /*arg*/)
765 sLog
.outString( "Re-Loading Locales Quest ... ");
766 objmgr
.LoadQuestLocales();
767 SendGlobalSysMessage("DB table `locales_quest` reloaded.");
771 bool ChatHandler::HandleLoadScriptsCommand(const char* args
)
773 if(!LoadScriptingModule(args
)) return true;
775 sWorld
.SendWorldText(LANG_SCRIPTS_RELOADED
);
779 bool ChatHandler::HandleAccountSetGmLevelCommand(const char* args
)
781 char* arg1
= strtok((char*)args
, " ");
785 /// must be NULL if targeted syntax and must be not nULL if not targeted
786 char* arg2
= strtok(NULL
, " ");
788 std::string targetAccountName
;
789 uint32 targetAccountId
= 0;
791 /// only target player different from self allowed (if targetPlayer!=NULL then not console)
792 Player
* targetPlayer
= getSelectedPlayer();
793 if(targetPlayer
&& m_session
->GetPlayer()!=targetPlayer
)
795 /// wrong command syntax or unexpected targeting
799 /// security level expected in arg2 after this if.
802 targetAccountId
= targetPlayer
->GetSession()->GetAccountId();
803 accmgr
.GetName(targetAccountId
, targetAccountName
);
807 /// wrong command syntax (second arg expected)
811 targetAccountName
= arg1
;
812 if(!AccountMgr::normilizeString(targetAccountName
))
814 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,targetAccountName
.c_str());
815 SetSentErrorMessage(true);
819 targetAccountId
= accmgr
.GetId(targetAccountName
);
822 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,targetAccountName
.c_str());
823 SetSentErrorMessage(true);
828 int32 gm
= (int32
)atoi(arg2
);
829 if ( gm
< SEC_PLAYER
|| gm
> SEC_ADMINISTRATOR
)
831 SendSysMessage(LANG_BAD_VALUE
);
832 SetSentErrorMessage(true);
836 /// can set security level only for target with less security and to less security that we have
837 /// This will reject self apply by specify account name
838 if(HasLowerSecurityAccount(NULL
,targetAccountId
,true))
841 /// account can't set security to same or grater level, need more power GM or console
842 AccountTypes plSecurity
= m_session
? m_session
->GetSecurity() : SEC_CONSOLE
;
843 if (AccountTypes(gm
) >= plSecurity
)
845 SendSysMessage(LANG_YOURS_SECURITY_IS_LOW
);
846 SetSentErrorMessage(true);
850 // This will prevent self apply by self target or no target
851 if(targetPlayer
&& m_session
->GetPlayer()!=targetPlayer
)
853 ChatHandler(targetPlayer
).PSendSysMessage(LANG_YOURS_SECURITY_CHANGED
,GetNameLink().c_str(), gm
);
854 targetPlayer
->GetSession()->SetSecurity(AccountTypes(gm
));
857 PSendSysMessage(LANG_YOU_CHANGE_SECURITY
, targetAccountName
.c_str(), gm
);
858 loginDatabase
.PExecute("UPDATE account SET gmlevel = '%i' WHERE id = '%u'", gm
, targetAccountId
);
863 /// Set password for account
864 bool ChatHandler::HandleAccountSetPasswordCommand(const char* args
)
869 ///- Get the command line arguments
870 char *szAccount
= strtok ((char*)args
," ");
871 char *szPassword1
= strtok (NULL
," ");
872 char *szPassword2
= strtok (NULL
," ");
874 if (!szAccount
||!szPassword1
|| !szPassword2
)
877 std::string account_name
= szAccount
;
878 if(!AccountMgr::normilizeString(account_name
))
880 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
881 SetSentErrorMessage(true);
885 uint32 targetAccountId
= accmgr
.GetId(account_name
);
886 if (!targetAccountId
)
888 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
889 SetSentErrorMessage(true);
893 /// can set password only for target with less security
894 /// This is also reject self apply in fact
895 if(HasLowerSecurityAccount (NULL
,targetAccountId
,true))
898 if (strcmp(szPassword1
,szPassword2
))
900 SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH
);
901 SetSentErrorMessage (true);
905 AccountOpResult result
= accmgr
.ChangePassword(targetAccountId
, szPassword1
);
910 SendSysMessage(LANG_COMMAND_PASSWORD
);
912 case AOR_NAME_NOT_EXIST
:
913 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
914 SetSentErrorMessage(true);
916 case AOR_PASS_TOO_LONG
:
917 SendSysMessage(LANG_PASSWORD_TOO_LONG
);
918 SetSentErrorMessage(true);
921 SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD
);
922 SetSentErrorMessage(true);
929 bool ChatHandler::HandleMaxSkillCommand(const char* /*args*/)
931 Player
* SelectedPlayer
= getSelectedPlayer();
934 SendSysMessage(LANG_NO_CHAR_SELECTED
);
935 SetSentErrorMessage(true);
939 // each skills that have max skill value dependent from level seted to current level max skill value
940 SelectedPlayer
->UpdateSkillsToMaxSkillsForLevel();
944 bool ChatHandler::HandleSetSkillCommand(const char* args
)
946 // number or [name] Shift-click form |color|Hskill:skill_id|h[name]|h|r
947 char* skill_p
= extractKeyFromLink((char*)args
,"Hskill");
951 char *level_p
= strtok (NULL
, " ");
956 char *max_p
= strtok (NULL
, " ");
958 int32 skill
= atoi(skill_p
);
961 PSendSysMessage(LANG_INVALID_SKILL_ID
, skill
);
962 SetSentErrorMessage(true);
966 int32 level
= atol (level_p
);
968 Player
* target
= getSelectedPlayer();
971 SendSysMessage(LANG_NO_CHAR_SELECTED
);
972 SetSentErrorMessage(true);
976 SkillLineEntry
const* sl
= sSkillLineStore
.LookupEntry(skill
);
979 PSendSysMessage(LANG_INVALID_SKILL_ID
, skill
);
980 SetSentErrorMessage(true);
984 std::string tNameLink
= GetNameLink(target
);
986 if(!target
->GetSkillValue(skill
))
988 PSendSysMessage(LANG_SET_SKILL_ERROR
, tNameLink
.c_str(), skill
, sl
->name
[0]);
989 SetSentErrorMessage(true);
993 int32 max
= max_p
? atol (max_p
) : target
->GetPureMaxSkillValue(skill
);
995 if( level
<= 0 || level
> max
|| max
<= 0 )
998 target
->SetSkill(skill
, level
, max
);
999 PSendSysMessage(LANG_SET_SKILL
, skill
, sl
->name
[0], tNameLink
.c_str(), level
, max
);
1004 bool ChatHandler::HandleUnLearnCommand(const char* args
)
1009 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
1010 uint32 spell_id
= extractSpellIdFromLink((char*)args
);
1014 char const* allStr
= strtok(NULL
," ");
1015 bool allRanks
= allStr
? (strncmp(allStr
, "all", strlen(allStr
)) == 0) : false;
1017 Player
* target
= getSelectedPlayer();
1020 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1021 SetSentErrorMessage(true);
1026 spell_id
= spellmgr
.GetFirstSpellInChain (spell_id
);
1028 if (target
->HasSpell(spell_id
))
1029 target
->removeSpell(spell_id
,false,!allRanks
);
1031 SendSysMessage(LANG_FORGET_SPELL
);
1036 bool ChatHandler::HandleCooldownCommand(const char* args
)
1038 Player
* target
= getSelectedPlayer();
1041 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1042 SetSentErrorMessage(true);
1046 std::string tNameLink
= GetNameLink(target
);
1050 target
->RemoveAllSpellCooldown();
1051 PSendSysMessage(LANG_REMOVEALL_COOLDOWN
, tNameLink
.c_str());
1055 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1056 uint32 spell_id
= extractSpellIdFromLink((char*)args
);
1060 if(!sSpellStore
.LookupEntry(spell_id
))
1062 PSendSysMessage(LANG_UNKNOWN_SPELL
, target
==m_session
->GetPlayer() ? GetMangosString(LANG_YOU
) : tNameLink
.c_str());
1063 SetSentErrorMessage(true);
1067 WorldPacket
data( SMSG_CLEAR_COOLDOWN
, (4+8) );
1068 data
<< uint32(spell_id
);
1069 data
<< uint64(target
->GetGUID());
1070 target
->GetSession()->SendPacket(&data
);
1071 target
->RemoveSpellCooldown(spell_id
);
1072 PSendSysMessage(LANG_REMOVE_COOLDOWN
, spell_id
, target
==m_session
->GetPlayer() ? GetMangosString(LANG_YOU
) : tNameLink
.c_str());
1077 bool ChatHandler::HandleLearnAllCommand(const char* /*args*/)
1079 static const char *allSpellList
[] =
1462 //"9036", problems with ghost state
1471 //"6718", phasing stealth, annoying for learn all case.
1684 while(strcmp(allSpellList
[loop
], "0"))
1686 uint32 spell
= atol((char*)allSpellList
[loop
++]);
1688 if (m_session
->GetPlayer()->HasSpell(spell
))
1691 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1692 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1694 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1698 m_session
->GetPlayer()->learnSpell(spell
,false);
1701 SendSysMessage(LANG_COMMAND_LEARN_MANY_SPELLS
);
1706 bool ChatHandler::HandleLearnAllGMCommand(const char* /*args*/)
1708 static const char *gmSpellList
[] =
1710 "24347", // Become A Fish, No Breath Bar
1711 "35132", // Visual Boom
1712 "38488", // Attack 4000-8000 AOE
1713 "38795", // Attack 2000 AOE + Slow Down 90%
1714 "15712", // Attack 200
1715 "1852", // GM Spell Silence
1718 "29878", // Kill My Self
1719 "26644", // More Kill
1721 "28550", //Invisible 24
1722 "23452", //Invisible + Target
1726 uint16 gmSpellIter
= 0;
1727 while( strcmp(gmSpellList
[gmSpellIter
], "0") )
1729 uint32 spell
= atol((char*)gmSpellList
[gmSpellIter
++]);
1731 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1732 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1734 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1738 m_session
->GetPlayer()->learnSpell(spell
,false);
1741 SendSysMessage(LANG_LEARNING_GM_SKILLS
);
1745 bool ChatHandler::HandleLearnAllMyClassCommand(const char* /*args*/)
1747 HandleLearnAllMySpellsCommand("");
1748 HandleLearnAllMyTalentsCommand("");
1752 bool ChatHandler::HandleLearnAllMySpellsCommand(const char* /*args*/)
1754 ChrClassesEntry
const* clsEntry
= sChrClassesStore
.LookupEntry(m_session
->GetPlayer()->getClass());
1757 uint32 family
= clsEntry
->spellfamily
;
1759 for (uint32 i
= 0; i
< sSpellStore
.GetNumRows(); ++i
)
1761 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(i
);
1765 // skip server-side/triggered spells
1766 if(spellInfo
->spellLevel
==0)
1769 // skip wrong class/race skills
1770 if(!m_session
->GetPlayer()->IsSpellFitByClassAndRace(spellInfo
->Id
))
1773 // skip other spell families
1774 if( spellInfo
->SpellFamilyName
!= family
)
1777 // skip spells with first rank learned as talent (and all talents then also)
1778 uint32 first_rank
= spellmgr
.GetFirstSpellInChain(spellInfo
->Id
);
1779 if(GetTalentSpellCost(first_rank
) > 0 )
1782 // skip broken spells
1783 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1786 m_session
->GetPlayer()->learnSpell(i
,false);
1789 SendSysMessage(LANG_COMMAND_LEARN_CLASS_SPELLS
);
1793 bool ChatHandler::HandleLearnAllMyTalentsCommand(const char* /*args*/)
1795 Player
* player
= m_session
->GetPlayer();
1796 uint32 classMask
= player
->getClassMask();
1798 for (uint32 i
= 0; i
< sTalentStore
.GetNumRows(); ++i
)
1800 TalentEntry
const *talentInfo
= sTalentStore
.LookupEntry(i
);
1804 TalentTabEntry
const *talentTabInfo
= sTalentTabStore
.LookupEntry( talentInfo
->TalentTab
);
1808 if( (classMask
& talentTabInfo
->ClassMask
) == 0 )
1811 // search highest talent rank
1814 for(int rank
= MAX_TALENT_RANK
-1; rank
>= 0; --rank
)
1816 if(talentInfo
->RankID
[rank
]!=0)
1818 spellid
= talentInfo
->RankID
[rank
];
1823 if(!spellid
) // ??? none spells in talent
1826 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spellid
);
1827 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1830 // learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
1831 player
->learnSpellHighRank(spellid
);
1834 SendSysMessage(LANG_COMMAND_LEARN_CLASS_TALENTS
);
1838 bool ChatHandler::HandleLearnAllMyPetTalentsCommand(const char* /*args*/)
1840 Player
* player
= m_session
->GetPlayer();
1842 Pet
* pet
= player
->GetPet();
1845 SendSysMessage(LANG_NO_PET_FOUND
);
1846 SetSentErrorMessage(true);
1850 CreatureInfo
const *ci
= pet
->GetCreatureInfo();
1853 SendSysMessage(LANG_WRONG_PET_TYPE
);
1854 SetSentErrorMessage(true);
1858 CreatureFamilyEntry
const *pet_family
= sCreatureFamilyStore
.LookupEntry(ci
->family
);
1861 SendSysMessage(LANG_WRONG_PET_TYPE
);
1862 SetSentErrorMessage(true);
1866 if(pet_family
->petTalentType
< 0) // not hunter pet
1868 SendSysMessage(LANG_WRONG_PET_TYPE
);
1869 SetSentErrorMessage(true);
1873 for (uint32 i
= 0; i
< sTalentStore
.GetNumRows(); ++i
)
1875 TalentEntry
const *talentInfo
= sTalentStore
.LookupEntry(i
);
1879 TalentTabEntry
const *talentTabInfo
= sTalentTabStore
.LookupEntry( talentInfo
->TalentTab
);
1883 // prevent learn talent for different family (cheating)
1884 if(((1 << pet_family
->petTalentType
) & talentTabInfo
->petTalentMask
)==0)
1887 // search highest talent rank
1890 for(int rank
= MAX_TALENT_RANK
-1; rank
>= 0; --rank
)
1892 if(talentInfo
->RankID
[rank
]!=0)
1894 spellid
= talentInfo
->RankID
[rank
];
1899 if(!spellid
) // ??? none spells in talent
1902 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spellid
);
1903 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1906 // learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
1907 pet
->learnSpellHighRank(spellid
);
1910 SendSysMessage(LANG_COMMAND_LEARN_PET_TALENTS
);
1914 bool ChatHandler::HandleLearnAllLangCommand(const char* /*args*/)
1916 // skipping UNIVERSAL language (0)
1917 for(int i
= 1; i
< LANGUAGES_COUNT
; ++i
)
1918 m_session
->GetPlayer()->learnSpell(lang_description
[i
].spell_id
,false);
1920 SendSysMessage(LANG_COMMAND_LEARN_ALL_LANG
);
1924 bool ChatHandler::HandleLearnAllDefaultCommand(const char* args
)
1926 Player
*player
= NULL
;
1929 std::string name
= extractPlayerNameFromLink((char*)args
);
1932 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1933 SetSentErrorMessage(true);
1937 player
= objmgr
.GetPlayer(name
.c_str());
1940 player
= getSelectedPlayer();
1944 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1945 SetSentErrorMessage(true);
1949 player
->learnDefaultSpells();
1950 player
->learnQuestRewardedSpells();
1952 PSendSysMessage(LANG_COMMAND_LEARN_ALL_DEFAULT_AND_QUEST
,GetNameLink(player
).c_str());
1956 bool ChatHandler::HandleLearnCommand(const char* args
)
1958 Player
* targetPlayer
= getSelectedPlayer();
1962 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1963 SetSentErrorMessage(true);
1967 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1968 uint32 spell
= extractSpellIdFromLink((char*)args
);
1969 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
1972 char const* allStr
= strtok(NULL
," ");
1973 bool allRanks
= allStr
? (strncmp(allStr
, "all", strlen(allStr
)) == 0) : false;
1975 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1976 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1978 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1979 SetSentErrorMessage(true);
1983 if (!allRanks
&& targetPlayer
->HasSpell(spell
))
1985 if(targetPlayer
== m_session
->GetPlayer())
1986 SendSysMessage(LANG_YOU_KNOWN_SPELL
);
1988 PSendSysMessage(LANG_TARGET_KNOWN_SPELL
,GetNameLink(targetPlayer
).c_str());
1989 SetSentErrorMessage(true);
1994 targetPlayer
->learnSpellHighRank(spell
);
1996 targetPlayer
->learnSpell(spell
,false);
2001 bool ChatHandler::HandleAddItemCommand(const char* args
)
2008 if(args
[0]=='[') // [name] manual form
2010 char* citemName
= strtok((char*)args
, "]");
2012 if(citemName
&& citemName
[0])
2014 std::string itemName
= citemName
+1;
2015 WorldDatabase
.escape_string(itemName
);
2016 QueryResult
*result
= WorldDatabase
.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName
.c_str());
2019 PSendSysMessage(LANG_COMMAND_COULDNOTFIND
, citemName
+1);
2020 SetSentErrorMessage(true);
2023 itemId
= result
->Fetch()->GetUInt16();
2029 else // item_id or [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r
2031 char* cId
= extractKeyFromLink((char*)args
,"Hitem");
2037 char* ccount
= strtok(NULL
, " ");
2042 count
= strtol(ccount
, NULL
, 10);
2047 Player
* pl
= m_session
->GetPlayer();
2048 Player
* plTarget
= getSelectedPlayer();
2052 sLog
.outDetail(GetMangosString(LANG_ADDITEM
), itemId
, count
);
2054 ItemPrototype
const *pProto
= objmgr
.GetItemPrototype(itemId
);
2057 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, itemId
);
2058 SetSentErrorMessage(true);
2065 plTarget
->DestroyItemCount(itemId
, -count
, true, false);
2066 PSendSysMessage(LANG_REMOVEITEM
, itemId
, -count
, GetNameLink(plTarget
).c_str());
2071 uint32 noSpaceForCount
= 0;
2073 // check space and find places
2074 ItemPosCountVec dest
;
2075 uint8 msg
= plTarget
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, itemId
, count
, &noSpaceForCount
);
2076 if( msg
!= EQUIP_ERR_OK
) // convert to possible store amount
2077 count
-= noSpaceForCount
;
2079 if( count
== 0 || dest
.empty()) // can't add any
2081 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, itemId
, noSpaceForCount
);
2082 SetSentErrorMessage(true);
2086 Item
* item
= plTarget
->StoreNewItem( dest
, itemId
, true, Item::GenerateItemRandomPropertyId(itemId
));
2088 // remove binding (let GM give it to another player later)
2090 for(ItemPosCountVec::const_iterator itr
= dest
.begin(); itr
!= dest
.end(); ++itr
)
2091 if(Item
* item1
= pl
->GetItemByPos(itr
->pos
))
2092 item1
->SetBinding( false );
2094 if(count
> 0 && item
)
2096 pl
->SendNewItem(item
,count
,false,true);
2098 plTarget
->SendNewItem(item
,count
,true,false);
2101 if(noSpaceForCount
> 0)
2102 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, itemId
, noSpaceForCount
);
2107 bool ChatHandler::HandleAddItemSetCommand(const char* args
)
2112 char* cId
= extractKeyFromLink((char*)args
,"Hitemset"); // number or [name] Shift-click form |color|Hitemset:itemset_id|h[name]|h|r
2116 uint32 itemsetId
= atol(cId
);
2118 // prevent generation all items with itemset field value '0'
2121 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND
,itemsetId
);
2122 SetSentErrorMessage(true);
2126 Player
* pl
= m_session
->GetPlayer();
2127 Player
* plTarget
= getSelectedPlayer();
2131 sLog
.outDetail(GetMangosString(LANG_ADDITEMSET
), itemsetId
);
2134 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
2136 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
2140 if (pProto
->ItemSet
== itemsetId
)
2143 ItemPosCountVec dest
;
2144 uint8 msg
= plTarget
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, pProto
->ItemId
, 1 );
2145 if (msg
== EQUIP_ERR_OK
)
2147 Item
* item
= plTarget
->StoreNewItem( dest
, pProto
->ItemId
, true);
2149 // remove binding (let GM give it to another player later)
2151 item
->SetBinding( false );
2153 pl
->SendNewItem(item
,1,false,true);
2155 plTarget
->SendNewItem(item
,1,true,false);
2159 pl
->SendEquipError( msg
, NULL
, NULL
);
2160 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, pProto
->ItemId
, 1);
2167 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND
,itemsetId
);
2169 SetSentErrorMessage(true);
2176 bool ChatHandler::HandleListItemCommand(const char* args
)
2181 char* cId
= extractKeyFromLink((char*)args
,"Hitem");
2185 uint32 item_id
= atol(cId
);
2188 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
2189 SetSentErrorMessage(true);
2193 ItemPrototype
const* itemProto
= objmgr
.GetItemPrototype(item_id
);
2196 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
2197 SetSentErrorMessage(true);
2201 char* c_count
= strtok(NULL
, " ");
2202 int count
= c_count
? atol(c_count
) : 10;
2207 QueryResult
*result
;
2210 uint32 inv_count
= 0;
2211 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM character_inventory WHERE item_template='%u'",item_id
);
2214 inv_count
= (*result
)[0].GetUInt32();
2218 result
=CharacterDatabase
.PQuery(
2220 "SELECT ci.item, cibag.slot AS bag, ci.slot, ci.guid, characters.account,characters.name "
2221 "FROM character_inventory AS ci LEFT JOIN character_inventory AS cibag ON (cibag.item=ci.bag),characters "
2222 "WHERE ci.item_template='%u' AND ci.guid = characters.guid LIMIT %u ",
2223 item_id
,uint32(count
));
2229 Field
*fields
= result
->Fetch();
2230 uint32 item_guid
= fields
[0].GetUInt32();
2231 uint32 item_bag
= fields
[1].GetUInt32();
2232 uint32 item_slot
= fields
[2].GetUInt32();
2233 uint32 owner_guid
= fields
[3].GetUInt32();
2234 uint32 owner_acc
= fields
[4].GetUInt32();
2235 std::string owner_name
= fields
[5].GetCppString();
2237 char const* item_pos
= 0;
2238 if(Player::IsEquipmentPos(item_bag
,item_slot
))
2239 item_pos
= "[equipped]";
2240 else if(Player::IsInventoryPos(item_bag
,item_slot
))
2241 item_pos
= "[in inventory]";
2242 else if(Player::IsBankPos(item_bag
,item_slot
))
2243 item_pos
= "[in bank]";
2247 PSendSysMessage(LANG_ITEMLIST_SLOT
,
2248 item_guid
,owner_name
.c_str(),owner_guid
,owner_acc
,item_pos
);
2249 } while (result
->NextRow());
2251 int64 res_count
= result
->GetRowCount();
2255 if(count
> res_count
)
2262 uint32 mail_count
= 0;
2263 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM mail_items WHERE item_template='%u'", item_id
);
2266 mail_count
= (*result
)[0].GetUInt32();
2272 result
=CharacterDatabase
.PQuery(
2274 "SELECT mail_items.item_guid, mail.sender, mail.receiver, char_s.account, char_s.name, char_r.account, char_r.name "
2275 "FROM mail,mail_items,characters as char_s,characters as char_r "
2276 "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",
2277 item_id
,uint32(count
));
2286 Field
*fields
= result
->Fetch();
2287 uint32 item_guid
= fields
[0].GetUInt32();
2288 uint32 item_s
= fields
[1].GetUInt32();
2289 uint32 item_r
= fields
[2].GetUInt32();
2290 uint32 item_s_acc
= fields
[3].GetUInt32();
2291 std::string item_s_name
= fields
[4].GetCppString();
2292 uint32 item_r_acc
= fields
[5].GetUInt32();
2293 std::string item_r_name
= fields
[6].GetCppString();
2295 char const* item_pos
= "[in mail]";
2297 PSendSysMessage(LANG_ITEMLIST_MAIL
,
2298 item_guid
,item_s_name
.c_str(),item_s
,item_s_acc
,item_r_name
.c_str(),item_r
,item_r_acc
,item_pos
);
2299 } while (result
->NextRow());
2301 int64 res_count
= result
->GetRowCount();
2305 if(count
> res_count
)
2312 uint32 auc_count
= 0;
2313 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM auctionhouse WHERE item_template='%u'",item_id
);
2316 auc_count
= (*result
)[0].GetUInt32();
2322 result
=CharacterDatabase
.PQuery(
2324 "SELECT auctionhouse.itemguid, auctionhouse.itemowner, characters.account, characters.name "
2325 "FROM auctionhouse,characters WHERE auctionhouse.item_template='%u' AND characters.guid = auctionhouse.itemowner LIMIT %u",
2326 item_id
,uint32(count
));
2335 Field
*fields
= result
->Fetch();
2336 uint32 item_guid
= fields
[0].GetUInt32();
2337 uint32 owner
= fields
[1].GetUInt32();
2338 uint32 owner_acc
= fields
[2].GetUInt32();
2339 std::string owner_name
= fields
[3].GetCppString();
2341 char const* item_pos
= "[in auction]";
2343 PSendSysMessage(LANG_ITEMLIST_AUCTION
, item_guid
, owner_name
.c_str(), owner
, owner_acc
,item_pos
);
2344 } while (result
->NextRow());
2350 uint32 guild_count
= 0;
2351 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_entry) FROM guild_bank_item WHERE item_entry='%u'",item_id
);
2354 guild_count
= (*result
)[0].GetUInt32();
2358 result
=CharacterDatabase
.PQuery(
2360 "SELECT gi.item_guid, gi.guildid, guild.name "
2361 "FROM guild_bank_item AS gi, guild WHERE gi.item_entry='%u' AND gi.guildid = guild.guildid LIMIT %u ",
2362 item_id
,uint32(count
));
2368 Field
*fields
= result
->Fetch();
2369 uint32 item_guid
= fields
[0].GetUInt32();
2370 uint32 guild_guid
= fields
[1].GetUInt32();
2371 std::string guild_name
= fields
[2].GetCppString();
2373 char const* item_pos
= "[in guild bank]";
2375 PSendSysMessage(LANG_ITEMLIST_GUILD
,item_guid
,guild_name
.c_str(),guild_guid
,item_pos
);
2376 } while (result
->NextRow());
2378 int64 res_count
= result
->GetRowCount();
2382 if(count
> res_count
)
2388 if(inv_count
+mail_count
+auc_count
+guild_count
== 0)
2390 SendSysMessage(LANG_COMMAND_NOITEMFOUND
);
2391 SetSentErrorMessage(true);
2395 PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE
,item_id
,inv_count
+mail_count
+auc_count
+guild_count
,inv_count
,mail_count
,auc_count
,guild_count
);
2400 bool ChatHandler::HandleListObjectCommand(const char* args
)
2405 // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2406 char* cId
= extractKeyFromLink((char*)args
,"Hgameobject_entry");
2410 uint32 go_id
= atol(cId
);
2413 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID
, go_id
);
2414 SetSentErrorMessage(true);
2418 GameObjectInfo
const * gInfo
= objmgr
.GetGameObjectInfo(go_id
);
2421 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID
, go_id
);
2422 SetSentErrorMessage(true);
2426 char* c_count
= strtok(NULL
, " ");
2427 int count
= c_count
? atol(c_count
) : 10;
2432 QueryResult
*result
;
2434 uint32 obj_count
= 0;
2435 result
=WorldDatabase
.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'",go_id
);
2438 obj_count
= (*result
)[0].GetUInt32();
2444 Player
* pl
= m_session
->GetPlayer();
2445 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",
2446 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(),go_id
,uint32(count
));
2449 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map FROM gameobject WHERE id = '%u' LIMIT %u",
2450 go_id
,uint32(count
));
2456 Field
*fields
= result
->Fetch();
2457 uint32 guid
= fields
[0].GetUInt32();
2458 float x
= fields
[1].GetFloat();
2459 float y
= fields
[2].GetFloat();
2460 float z
= fields
[3].GetFloat();
2461 int mapid
= fields
[4].GetUInt16();
2464 PSendSysMessage(LANG_GO_LIST_CHAT
, guid
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2466 PSendSysMessage(LANG_GO_LIST_CONSOLE
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2467 } while (result
->NextRow());
2472 PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE
,go_id
,obj_count
);
2476 bool ChatHandler::HandleListCreatureCommand(const char* args
)
2481 // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
2482 char* cId
= extractKeyFromLink((char*)args
,"Hcreature_entry");
2486 uint32 cr_id
= atol(cId
);
2489 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID
, cr_id
);
2490 SetSentErrorMessage(true);
2494 CreatureInfo
const* cInfo
= objmgr
.GetCreatureTemplate(cr_id
);
2497 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID
, cr_id
);
2498 SetSentErrorMessage(true);
2502 char* c_count
= strtok(NULL
, " ");
2503 int count
= c_count
? atol(c_count
) : 10;
2508 QueryResult
*result
;
2510 uint32 cr_count
= 0;
2511 result
=WorldDatabase
.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'",cr_id
);
2514 cr_count
= (*result
)[0].GetUInt32();
2520 Player
* pl
= m_session
->GetPlayer();
2521 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",
2522 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(), cr_id
,uint32(count
));
2525 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '%u' LIMIT %u",
2526 cr_id
,uint32(count
));
2532 Field
*fields
= result
->Fetch();
2533 uint32 guid
= fields
[0].GetUInt32();
2534 float x
= fields
[1].GetFloat();
2535 float y
= fields
[2].GetFloat();
2536 float z
= fields
[3].GetFloat();
2537 int mapid
= fields
[4].GetUInt16();
2540 PSendSysMessage(LANG_CREATURE_LIST_CHAT
, guid
, guid
, cInfo
->Name
, x
, y
, z
, mapid
);
2542 PSendSysMessage(LANG_CREATURE_LIST_CONSOLE
, guid
, cInfo
->Name
, x
, y
, z
, mapid
);
2543 } while (result
->NextRow());
2548 PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE
,cr_id
,cr_count
);
2552 bool ChatHandler::HandleLookupItemCommand(const char* args
)
2557 std::string namepart
= args
;
2558 std::wstring wnamepart
;
2560 // converting string that we try to find to lower case
2561 if(!Utf8toWStr(namepart
,wnamepart
))
2564 wstrToLower(wnamepart
);
2568 // Search in `item_template`
2569 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
2571 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
2575 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2578 ItemLocale
const *il
= objmgr
.GetItemLocale(pProto
->ItemId
);
2581 if (il
->Name
.size() > loc_idx
&& !il
->Name
[loc_idx
].empty())
2583 std::string name
= il
->Name
[loc_idx
];
2585 if (Utf8FitTo(name
, wnamepart
))
2588 PSendSysMessage(LANG_ITEM_LIST_CHAT
, id
, id
, name
.c_str());
2590 PSendSysMessage(LANG_ITEM_LIST_CONSOLE
, id
, name
.c_str());
2598 std::string name
= pProto
->Name1
;
2602 if (Utf8FitTo(name
, wnamepart
))
2605 PSendSysMessage(LANG_ITEM_LIST_CHAT
, id
, id
, name
.c_str());
2607 PSendSysMessage(LANG_ITEM_LIST_CONSOLE
, id
, name
.c_str());
2613 SendSysMessage(LANG_COMMAND_NOITEMFOUND
);
2618 bool ChatHandler::HandleLookupItemSetCommand(const char* args
)
2623 std::string namepart
= args
;
2624 std::wstring wnamepart
;
2626 if(!Utf8toWStr(namepart
,wnamepart
))
2629 // converting string that we try to find to lower case
2630 wstrToLower( wnamepart
);
2632 uint32 counter
= 0; // Counter for figure out that we found smth.
2634 // Search in ItemSet.dbc
2635 for (uint32 id
= 0; id
< sItemSetStore
.GetNumRows(); id
++)
2637 ItemSetEntry
const *set
= sItemSetStore
.LookupEntry(id
);
2640 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
2641 std::string name
= set
->name
[loc
];
2645 if (!Utf8FitTo(name
, wnamepart
))
2648 for(; loc
< MAX_LOCALE
; ++loc
)
2650 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
2653 name
= set
->name
[loc
];
2657 if (Utf8FitTo(name
, wnamepart
))
2662 if(loc
< MAX_LOCALE
)
2664 // send item set in "id - [namedlink locale]" format
2666 PSendSysMessage(LANG_ITEMSET_LIST_CHAT
,id
,id
,name
.c_str(),localeNames
[loc
]);
2668 PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE
,id
,name
.c_str(),localeNames
[loc
]);
2673 if (counter
== 0) // if counter == 0 then we found nth
2674 SendSysMessage(LANG_COMMAND_NOITEMSETFOUND
);
2678 bool ChatHandler::HandleLookupSkillCommand(const char* args
)
2683 // can be NULL in console call
2684 Player
* target
= getSelectedPlayer();
2686 std::string namepart
= args
;
2687 std::wstring wnamepart
;
2689 if(!Utf8toWStr(namepart
,wnamepart
))
2692 // converting string that we try to find to lower case
2693 wstrToLower( wnamepart
);
2695 uint32 counter
= 0; // Counter for figure out that we found smth.
2697 // Search in SkillLine.dbc
2698 for (uint32 id
= 0; id
< sSkillLineStore
.GetNumRows(); id
++)
2700 SkillLineEntry
const *skillInfo
= sSkillLineStore
.LookupEntry(id
);
2703 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
2704 std::string name
= skillInfo
->name
[loc
];
2708 if (!Utf8FitTo(name
, wnamepart
))
2711 for(; loc
< MAX_LOCALE
; ++loc
)
2713 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
2716 name
= skillInfo
->name
[loc
];
2720 if (Utf8FitTo(name
, wnamepart
))
2725 if(loc
< MAX_LOCALE
)
2727 char valStr
[50] = "";
2728 char const* knownStr
= "";
2729 if(target
&& target
->HasSkill(id
))
2731 knownStr
= GetMangosString(LANG_KNOWN
);
2732 uint32 curValue
= target
->GetPureSkillValue(id
);
2733 uint32 maxValue
= target
->GetPureMaxSkillValue(id
);
2734 uint32 permValue
= target
->GetSkillPermBonusValue(id
);
2735 uint32 tempValue
= target
->GetSkillTempBonusValue(id
);
2737 char const* valFormat
= GetMangosString(LANG_SKILL_VALUES
);
2738 snprintf(valStr
,50,valFormat
,curValue
,maxValue
,permValue
,tempValue
);
2741 // send skill in "id - [namedlink locale]" format
2743 PSendSysMessage(LANG_SKILL_LIST_CHAT
,id
,id
,name
.c_str(),localeNames
[loc
],knownStr
,valStr
);
2745 PSendSysMessage(LANG_SKILL_LIST_CONSOLE
,id
,name
.c_str(),localeNames
[loc
],knownStr
,valStr
);
2751 if (counter
== 0) // if counter == 0 then we found nth
2752 SendSysMessage(LANG_COMMAND_NOSKILLFOUND
);
2756 bool ChatHandler::HandleLookupSpellCommand(const char* args
)
2761 // can be NULL at console call
2762 Player
* target
= getSelectedPlayer();
2764 std::string namepart
= args
;
2765 std::wstring wnamepart
;
2767 if(!Utf8toWStr(namepart
,wnamepart
))
2770 // converting string that we try to find to lower case
2771 wstrToLower( wnamepart
);
2773 uint32 counter
= 0; // Counter for figure out that we found smth.
2775 // Search in Spell.dbc
2776 for (uint32 id
= 0; id
< sSpellStore
.GetNumRows(); id
++)
2778 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(id
);
2781 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
2782 std::string name
= spellInfo
->SpellName
[loc
];
2786 if (!Utf8FitTo(name
, wnamepart
))
2789 for(; loc
< MAX_LOCALE
; ++loc
)
2791 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
2794 name
= spellInfo
->SpellName
[loc
];
2798 if (Utf8FitTo(name
, wnamepart
))
2803 if(loc
< MAX_LOCALE
)
2805 bool known
= target
&& target
->HasSpell(id
);
2806 bool learn
= (spellInfo
->Effect
[0] == SPELL_EFFECT_LEARN_SPELL
);
2808 uint32 talentCost
= GetTalentSpellCost(id
);
2810 bool talent
= (talentCost
> 0);
2811 bool passive
= IsPassiveSpell(id
);
2812 bool active
= target
&& target
->HasAura(id
);
2814 // unit32 used to prevent interpreting uint8 as char at output
2815 // find rank of learned spell for learning spell, or talent rank
2816 uint32 rank
= talentCost
? talentCost
: spellmgr
.GetSpellRank(learn
? spellInfo
->EffectTriggerSpell
[0] : id
);
2818 // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
2819 std::ostringstream ss
;
2821 ss
<< id
<< " - |cffffffff|Hspell:" << id
<< "|h[" << name
;
2823 ss
<< id
<< " - " << name
;
2825 // include rank in link name
2827 ss
<< GetMangosString(LANG_SPELL_RANK
) << rank
;
2830 ss
<< " " << localeNames
[loc
] << "]|h|r";
2832 ss
<< " " << localeNames
[loc
];
2835 ss
<< GetMangosString(LANG_TALENT
);
2837 ss
<< GetMangosString(LANG_PASSIVE
);
2839 ss
<< GetMangosString(LANG_LEARN
);
2841 ss
<< GetMangosString(LANG_KNOWN
);
2843 ss
<< GetMangosString(LANG_ACTIVE
);
2845 SendSysMessage(ss
.str().c_str());
2851 if (counter
== 0) // if counter == 0 then we found nth
2852 SendSysMessage(LANG_COMMAND_NOSPELLFOUND
);
2856 bool ChatHandler::HandleLookupQuestCommand(const char* args
)
2861 // can be NULL at console call
2862 Player
* target
= getSelectedPlayer();
2864 std::string namepart
= args
;
2865 std::wstring wnamepart
;
2867 // converting string that we try to find to lower case
2868 if(!Utf8toWStr(namepart
,wnamepart
))
2871 wstrToLower(wnamepart
);
2873 uint32 counter
= 0 ;
2875 ObjectMgr::QuestMap
const& qTemplates
= objmgr
.GetQuestTemplates();
2876 for (ObjectMgr::QuestMap::const_iterator iter
= qTemplates
.begin(); iter
!= qTemplates
.end(); ++iter
)
2878 Quest
* qinfo
= iter
->second
;
2880 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2883 QuestLocale
const *il
= objmgr
.GetQuestLocale(qinfo
->GetQuestId());
2886 if (il
->Title
.size() > loc_idx
&& !il
->Title
[loc_idx
].empty())
2888 std::string title
= il
->Title
[loc_idx
];
2890 if (Utf8FitTo(title
, wnamepart
))
2892 char const* statusStr
= "";
2896 QuestStatus status
= target
->GetQuestStatus(qinfo
->GetQuestId());
2898 if(status
== QUEST_STATUS_COMPLETE
)
2900 if(target
->GetQuestRewardStatus(qinfo
->GetQuestId()))
2901 statusStr
= GetMangosString(LANG_COMMAND_QUEST_REWARDED
);
2903 statusStr
= GetMangosString(LANG_COMMAND_QUEST_COMPLETE
);
2905 else if(status
== QUEST_STATUS_INCOMPLETE
)
2906 statusStr
= GetMangosString(LANG_COMMAND_QUEST_ACTIVE
);
2910 PSendSysMessage(LANG_QUEST_LIST_CHAT
,qinfo
->GetQuestId(),qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2912 PSendSysMessage(LANG_QUEST_LIST_CONSOLE
,qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2920 std::string title
= qinfo
->GetTitle();
2924 if (Utf8FitTo(title
, wnamepart
))
2926 char const* statusStr
= "";
2930 QuestStatus status
= target
->GetQuestStatus(qinfo
->GetQuestId());
2932 if(status
== QUEST_STATUS_COMPLETE
)
2934 if(target
->GetQuestRewardStatus(qinfo
->GetQuestId()))
2935 statusStr
= GetMangosString(LANG_COMMAND_QUEST_REWARDED
);
2937 statusStr
= GetMangosString(LANG_COMMAND_QUEST_COMPLETE
);
2939 else if(status
== QUEST_STATUS_INCOMPLETE
)
2940 statusStr
= GetMangosString(LANG_COMMAND_QUEST_ACTIVE
);
2944 PSendSysMessage(LANG_QUEST_LIST_CHAT
,qinfo
->GetQuestId(),qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2946 PSendSysMessage(LANG_QUEST_LIST_CONSOLE
,qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2953 SendSysMessage(LANG_COMMAND_NOQUESTFOUND
);
2958 bool ChatHandler::HandleLookupCreatureCommand(const char* args
)
2963 std::string namepart
= args
;
2964 std::wstring wnamepart
;
2966 // converting string that we try to find to lower case
2967 if (!Utf8toWStr (namepart
,wnamepart
))
2970 wstrToLower (wnamepart
);
2974 for (uint32 id
= 0; id
< sCreatureStorage
.MaxEntry
; ++id
)
2976 CreatureInfo
const* cInfo
= sCreatureStorage
.LookupEntry
<CreatureInfo
> (id
);
2980 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2983 CreatureLocale
const *cl
= objmgr
.GetCreatureLocale (id
);
2986 if (cl
->Name
.size() > loc_idx
&& !cl
->Name
[loc_idx
].empty ())
2988 std::string name
= cl
->Name
[loc_idx
];
2990 if (Utf8FitTo (name
, wnamepart
))
2993 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str ());
2995 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE
, id
, name
.c_str ());
3003 std::string name
= cInfo
->Name
;
3007 if (Utf8FitTo(name
, wnamepart
))
3010 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str ());
3012 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE
, id
, name
.c_str ());
3018 SendSysMessage (LANG_COMMAND_NOCREATUREFOUND
);
3023 bool ChatHandler::HandleLookupObjectCommand(const char* args
)
3028 std::string namepart
= args
;
3029 std::wstring wnamepart
;
3031 // converting string that we try to find to lower case
3032 if(!Utf8toWStr(namepart
,wnamepart
))
3035 wstrToLower(wnamepart
);
3039 for (uint32 id
= 0; id
< sGOStorage
.MaxEntry
; id
++ )
3041 GameObjectInfo
const* gInfo
= sGOStorage
.LookupEntry
<GameObjectInfo
>(id
);
3045 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
3048 GameObjectLocale
const *gl
= objmgr
.GetGameObjectLocale(id
);
3051 if (gl
->Name
.size() > loc_idx
&& !gl
->Name
[loc_idx
].empty())
3053 std::string name
= gl
->Name
[loc_idx
];
3055 if (Utf8FitTo(name
, wnamepart
))
3058 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT
, id
, id
, name
.c_str());
3060 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE
, id
, name
.c_str());
3068 std::string name
= gInfo
->name
;
3072 if(Utf8FitTo(name
, wnamepart
))
3075 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT
, id
, id
, name
.c_str());
3077 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE
, id
, name
.c_str());
3083 SendSysMessage(LANG_COMMAND_NOGAMEOBJECTFOUND
);
3088 bool ChatHandler::HandleLookupTaxiNodeCommand(const char * args
)
3093 std::string namepart
= args
;
3094 std::wstring wnamepart
;
3096 if(!Utf8toWStr(namepart
,wnamepart
))
3099 // converting string that we try to find to lower case
3100 wstrToLower( wnamepart
);
3102 uint32 counter
= 0; // Counter for figure out that we found smth.
3104 // Search in TaxiNodes.dbc
3105 for (uint32 id
= 0; id
< sTaxiNodesStore
.GetNumRows(); id
++)
3107 TaxiNodesEntry
const *nodeEntry
= sTaxiNodesStore
.LookupEntry(id
);
3110 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
3111 std::string name
= nodeEntry
->name
[loc
];
3115 if (!Utf8FitTo(name
, wnamepart
))
3118 for(; loc
< MAX_LOCALE
; ++loc
)
3120 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
3123 name
= nodeEntry
->name
[loc
];
3127 if (Utf8FitTo(name
, wnamepart
))
3132 if(loc
< MAX_LOCALE
)
3134 // send taxinode in "id - [name] (Map:m X:x Y:y Z:z)" format
3136 PSendSysMessage (LANG_TAXINODE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str(),localeNames
[loc
],
3137 nodeEntry
->map_id
,nodeEntry
->x
,nodeEntry
->y
,nodeEntry
->z
);
3139 PSendSysMessage (LANG_TAXINODE_ENTRY_LIST_CONSOLE
, id
, name
.c_str(), localeNames
[loc
],
3140 nodeEntry
->map_id
,nodeEntry
->x
,nodeEntry
->y
,nodeEntry
->z
);
3145 if (counter
== 0) // if counter == 0 then we found nth
3146 SendSysMessage(LANG_COMMAND_NOSPELLFOUND
);
3150 /** \brief GM command level 3 - Create a guild.
3152 * This command allows a GM (level 3) to create a guild.
3154 * The "args" parameter contains the name of the guild leader
3155 * and then the name of the guild.
3158 bool ChatHandler::HandleGuildCreateCommand(const char* args
)
3164 char *lname
= strtok ((char*)args
, " ");
3165 char *gname
= strtok (NULL
, "");
3172 SendSysMessage (LANG_INSERT_GUILD_NAME
);
3173 SetSentErrorMessage (true);
3177 std::string guildname
= gname
;
3179 Player
* player
= ObjectAccessor::Instance ().FindPlayerByName (lname
);
3182 SendSysMessage (LANG_PLAYER_NOT_FOUND
);
3183 SetSentErrorMessage (true);
3187 if (player
->GetGuildId())
3189 SendSysMessage (LANG_PLAYER_IN_GUILD
);
3193 Guild
*guild
= new Guild
;
3194 if (!guild
->create (player
,guildname
))
3197 SendSysMessage (LANG_GUILD_NOT_CREATED
);
3198 SetSentErrorMessage (true);
3202 objmgr
.AddGuild (guild
);
3206 bool ChatHandler::HandleGuildInviteCommand(const char *args
)
3211 char* par1
= strtok ((char*)args
, " ");
3212 char* par2
= strtok (NULL
, "");
3216 std::string glName
= par2
;
3217 Guild
* targetGuild
= objmgr
.GetGuildByName (glName
);
3221 std::string plName
= extractPlayerNameFromLink(par1
);
3224 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3225 SetSentErrorMessage(true);
3230 if (Player
* targetPlayer
= ObjectAccessor::Instance ().FindPlayerByName (plName
.c_str ()))
3231 plGuid
= targetPlayer
->GetGUID ();
3233 plGuid
= objmgr
.GetPlayerGUIDByName (plName
);
3238 // player's guild membership checked in AddMember before add
3239 if (!targetGuild
->AddMember (plGuid
,targetGuild
->GetLowestRank ()))
3245 bool ChatHandler::HandleGuildUninviteCommand(const char *args
)
3250 char* par1
= strtok ((char*)args
, " ");
3254 std::string plName
= extractPlayerNameFromLink(par1
);
3257 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3258 SetSentErrorMessage(true);
3264 if (Player
* targetPlayer
= ObjectAccessor::Instance ().FindPlayerByName (plName
.c_str ()))
3266 plGuid
= targetPlayer
->GetGUID ();
3267 glId
= targetPlayer
->GetGuildId ();
3271 plGuid
= objmgr
.GetPlayerGUIDByName (plName
);
3272 glId
= Player::GetGuildIdFromDB (plGuid
);
3275 if (!plGuid
|| !glId
)
3278 Guild
* targetGuild
= objmgr
.GetGuildById (glId
);
3282 targetGuild
->DelMember (plGuid
);
3287 bool ChatHandler::HandleGuildRankCommand(const char *args
)
3292 char* par1
= strtok ((char*)args
, " ");
3293 char* par2
= strtok (NULL
, " ");
3297 std::string plName
= extractPlayerNameFromLink(par1
);
3300 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3301 SetSentErrorMessage(true);
3308 if (Player
* targetPlayer
= ObjectAccessor::Instance ().FindPlayerByName (plName
.c_str ()))
3310 plGuid
= targetPlayer
->GetGUID ();
3311 glId
= targetPlayer
->GetGuildId ();
3315 plGuid
= objmgr
.GetPlayerGUIDByName (plName
);
3316 glId
= Player::GetGuildIdFromDB (plGuid
);
3319 if (!plGuid
|| !glId
)
3322 Guild
* targetGuild
= objmgr
.GetGuildById (glId
);
3326 uint32 newrank
= uint32 (atoi (par2
));
3327 if (newrank
> targetGuild
->GetLowestRank ())
3330 targetGuild
->ChangeRank (plGuid
,newrank
);
3335 bool ChatHandler::HandleGuildDeleteCommand(const char* args
)
3340 char* par1
= strtok ((char*)args
, " ");
3344 std::string gld
= par1
;
3346 Guild
* targetGuild
= objmgr
.GetGuildByName (gld
);
3350 targetGuild
->Disband ();
3355 bool ChatHandler::HandleGetDistanceCommand(const char* args
)
3357 WorldObject
* obj
= NULL
;
3361 uint64 guid
= extractGuidFromLink((char*)args
);
3363 obj
= (WorldObject
*)ObjectAccessor::GetObjectByTypeMask(*m_session
->GetPlayer(),guid
,TYPEMASK_UNIT
|TYPEMASK_GAMEOBJECT
);
3367 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3368 SetSentErrorMessage(true);
3374 obj
= getSelectedUnit();
3378 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3379 SetSentErrorMessage(true);
3384 PSendSysMessage(LANG_DISTANCE
, m_session
->GetPlayer()->GetDistance(obj
),m_session
->GetPlayer()->GetDistance2d(obj
));
3389 bool ChatHandler::HandleDieCommand(const char* /*args*/)
3391 Unit
* target
= getSelectedUnit();
3393 if(!target
|| !m_session
->GetPlayer()->GetSelection())
3395 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3396 SetSentErrorMessage(true);
3400 if(target
->GetTypeId()==TYPEID_PLAYER
)
3402 if(HasLowerSecurity((Player
*)target
,0,false))
3406 if( target
->isAlive() )
3408 m_session
->GetPlayer()->DealDamage(target
, target
->GetHealth(), NULL
, DIRECT_DAMAGE
, SPELL_SCHOOL_MASK_NORMAL
, NULL
, false);
3414 bool ChatHandler::HandleDamageCommand(const char * args
)
3419 Unit
* target
= getSelectedUnit();
3421 if(!target
|| !m_session
->GetPlayer()->GetSelection())
3423 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3424 SetSentErrorMessage(true);
3428 if( !target
->isAlive() )
3431 char* damageStr
= strtok((char*)args
, " ");
3435 int32 damage
= atoi((char*)damageStr
);
3439 char* schoolStr
= strtok((char*)NULL
, " ");
3441 // flat melee damage without resistence/etc reduction
3444 m_session
->GetPlayer()->DealDamage(target
, damage
, NULL
, DIRECT_DAMAGE
, SPELL_SCHOOL_MASK_NORMAL
, NULL
, false);
3445 m_session
->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2
, target
, 1, SPELL_SCHOOL_MASK_NORMAL
, damage
, 0, 0, VICTIMSTATE_NORMAL
, 0);
3449 uint32 school
= schoolStr
? atoi((char*)schoolStr
) : SPELL_SCHOOL_NORMAL
;
3450 if(school
>= MAX_SPELL_SCHOOL
)
3453 SpellSchoolMask schoolmask
= SpellSchoolMask(1 << school
);
3455 if ( schoolmask
& SPELL_SCHOOL_MASK_NORMAL
)
3456 damage
= m_session
->GetPlayer()->CalcArmorReducedDamage(target
, damage
);
3458 char* spellStr
= strtok((char*)NULL
, " ");
3460 // melee damage by specific school
3466 m_session
->GetPlayer()->CalcAbsorbResist(target
,schoolmask
, SPELL_DIRECT_DAMAGE
, damage
, &absorb
, &resist
);
3468 if (damage
<= absorb
+ resist
)
3471 damage
-= absorb
+ resist
;
3473 m_session
->GetPlayer()->DealDamage(target
, damage
, NULL
, DIRECT_DAMAGE
, schoolmask
, NULL
, false);
3474 m_session
->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2
, target
, 1, schoolmask
, damage
, absorb
, resist
, VICTIMSTATE_NORMAL
, 0);
3480 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3481 uint32 spellid
= extractSpellIdFromLink((char*)args
);
3482 if(!spellid
|| !sSpellStore
.LookupEntry(spellid
))
3485 m_session
->GetPlayer()->SpellNonMeleeDamageLog(target
, spellid
, damage
);
3489 bool ChatHandler::HandleModifyArenaCommand(const char * args
)
3494 Player
*target
= getSelectedPlayer();
3497 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3498 SetSentErrorMessage(true);
3502 int32 amount
= (uint32
)atoi(args
);
3504 target
->ModifyArenaPoints(amount
);
3506 PSendSysMessage(LANG_COMMAND_MODIFY_ARENA
, GetNameLink(target
).c_str(), target
->GetArenaPoints());
3511 bool ChatHandler::HandleReviveCommand(const char* args
)
3513 Player
* player
= NULL
;
3514 uint64 player_guid
= 0;
3518 std::string name
= extractPlayerNameFromLink((char*)args
);
3521 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3522 SetSentErrorMessage(true);
3526 player
= objmgr
.GetPlayer(name
.c_str());
3528 player_guid
= objmgr
.GetPlayerGUIDByName(name
);
3531 player
= getSelectedPlayer();
3535 player
->ResurrectPlayer(0.5f
);
3536 player
->SpawnCorpseBones();
3539 else if (player_guid
)
3541 // will resurrected at login without corpse
3542 ObjectAccessor::Instance().ConvertCorpseForPlayer(player_guid
);
3546 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3547 SetSentErrorMessage(true);
3554 bool ChatHandler::HandleAuraCommand(const char* args
)
3556 Unit
*target
= getSelectedUnit();
3559 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3560 SetSentErrorMessage(true);
3564 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3565 uint32 spellID
= extractSpellIdFromLink((char*)args
);
3567 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry( spellID
);
3570 for(uint32 i
= 0;i
<3;++i
)
3572 uint8 eff
= spellInfo
->Effect
[i
];
3573 if (eff
>=TOTAL_SPELL_EFFECTS
)
3575 if( IsAreaAuraEffect(eff
) ||
3576 eff
== SPELL_EFFECT_APPLY_AURA
||
3577 eff
== SPELL_EFFECT_PERSISTENT_AREA_AURA
)
3579 Aura
*Aur
= CreateAura(spellInfo
, i
, NULL
, target
);
3580 target
->AddAura(Aur
);
3588 bool ChatHandler::HandleUnAuraCommand(const char* args
)
3590 Unit
*target
= getSelectedUnit();
3593 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3594 SetSentErrorMessage(true);
3598 std::string argstr
= args
;
3599 if (argstr
== "all")
3601 target
->RemoveAllAuras();
3605 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3606 uint32 spellID
= extractSpellIdFromLink((char*)args
);
3610 target
->RemoveAurasDueToSpell(spellID
);
3615 bool ChatHandler::HandleLinkGraveCommand(const char* args
)
3620 char* px
= strtok((char*)args
, " ");
3624 uint32 g_id
= (uint32
)atoi(px
);
3628 char* px2
= strtok(NULL
, " ");
3632 else if (strncmp(px2
,"horde",6)==0)
3634 else if (strncmp(px2
,"alliance",9)==0)
3639 WorldSafeLocsEntry
const* graveyard
= sWorldSafeLocsStore
.LookupEntry(g_id
);
3643 PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST
, g_id
);
3644 SetSentErrorMessage(true);
3648 Player
* player
= m_session
->GetPlayer();
3650 uint32 zoneId
= player
->GetZoneId();
3652 AreaTableEntry
const *areaEntry
= GetAreaEntryByAreaID(zoneId
);
3653 if(!areaEntry
|| areaEntry
->zone
!=0 )
3655 PSendSysMessage(LANG_COMMAND_GRAVEYARDWRONGZONE
, g_id
,zoneId
);
3656 SetSentErrorMessage(true);
3660 if(objmgr
.AddGraveYardLink(g_id
,zoneId
,g_team
))
3661 PSendSysMessage(LANG_COMMAND_GRAVEYARDLINKED
, g_id
,zoneId
);
3663 PSendSysMessage(LANG_COMMAND_GRAVEYARDALRLINKED
, g_id
,zoneId
);
3668 bool ChatHandler::HandleNearGraveCommand(const char* args
)
3672 size_t argslen
= strlen(args
);
3676 else if (strncmp((char*)args
,"horde",argslen
)==0)
3678 else if (strncmp((char*)args
,"alliance",argslen
)==0)
3683 Player
* player
= m_session
->GetPlayer();
3684 uint32 zone_id
= player
->GetZoneId();
3686 WorldSafeLocsEntry
const* graveyard
= objmgr
.GetClosestGraveYard(
3687 player
->GetPositionX(), player
->GetPositionY(), player
->GetPositionZ(),player
->GetMapId(),g_team
);
3691 uint32 g_id
= graveyard
->ID
;
3693 GraveYardData
const* data
= objmgr
.FindGraveYardData(g_id
,zone_id
);
3696 PSendSysMessage(LANG_COMMAND_GRAVEYARDERROR
,g_id
);
3697 SetSentErrorMessage(true);
3701 g_team
= data
->team
;
3703 std::string team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_NOTEAM
);
3706 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ANY
);
3707 else if(g_team
== HORDE
)
3708 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE
);
3709 else if(g_team
== ALLIANCE
)
3710 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE
);
3712 PSendSysMessage(LANG_COMMAND_GRAVEYARDNEAREST
, g_id
,team_name
.c_str(),zone_id
);
3716 std::string team_name
;
3719 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ANY
);
3720 else if(g_team
== HORDE
)
3721 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE
);
3722 else if(g_team
== ALLIANCE
)
3723 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE
);
3725 if(g_team
== ~uint32(0))
3726 PSendSysMessage(LANG_COMMAND_ZONENOGRAVEYARDS
, zone_id
);
3728 PSendSysMessage(LANG_COMMAND_ZONENOGRAFACTION
, zone_id
,team_name
.c_str());
3734 //-----------------------Npc Commands-----------------------
3735 bool ChatHandler::HandleNpcAllowMovementCommand(const char* /*args*/)
3737 if(sWorld
.getAllowMovement())
3739 sWorld
.SetAllowMovement(false);
3740 SendSysMessage(LANG_CREATURE_MOVE_DISABLED
);
3744 sWorld
.SetAllowMovement(true);
3745 SendSysMessage(LANG_CREATURE_MOVE_ENABLED
);
3750 bool ChatHandler::HandleNpcChangeEntryCommand(const char *args
)
3755 uint32 newEntryNum
= atoi(args
);
3759 Unit
* unit
= getSelectedUnit();
3760 if(!unit
|| unit
->GetTypeId() != TYPEID_UNIT
)
3762 SendSysMessage(LANG_SELECT_CREATURE
);
3763 SetSentErrorMessage(true);
3766 Creature
* creature
= (Creature
*)unit
;
3767 if(creature
->UpdateEntry(newEntryNum
))
3768 SendSysMessage(LANG_DONE
);
3770 SendSysMessage(LANG_ERROR
);
3774 bool ChatHandler::HandleNpcInfoCommand(const char* /*args*/)
3776 Creature
* target
= getSelectedCreature();
3780 SendSysMessage(LANG_SELECT_CREATURE
);
3781 SetSentErrorMessage(true);
3785 uint32 faction
= target
->getFaction();
3786 uint32 npcflags
= target
->GetUInt32Value(UNIT_NPC_FLAGS
);
3787 uint32 displayid
= target
->GetDisplayId();
3788 uint32 nativeid
= target
->GetNativeDisplayId();
3789 uint32 Entry
= target
->GetEntry();
3790 CreatureInfo
const* cInfo
= target
->GetCreatureInfo();
3792 int32 curRespawnDelay
= target
->GetRespawnTimeEx()-time(NULL
);
3793 if(curRespawnDelay
< 0)
3794 curRespawnDelay
= 0;
3795 std::string curRespawnDelayStr
= secsToTimeString(curRespawnDelay
,true);
3796 std::string defRespawnDelayStr
= secsToTimeString(target
->GetRespawnDelay(),true);
3798 PSendSysMessage(LANG_NPCINFO_CHAR
, target
->GetDBTableGUIDLow(), faction
, npcflags
, Entry
, displayid
, nativeid
);
3799 PSendSysMessage(LANG_NPCINFO_LEVEL
, target
->getLevel());
3800 PSendSysMessage(LANG_NPCINFO_HEALTH
,target
->GetCreateHealth(), target
->GetMaxHealth(), target
->GetHealth());
3801 PSendSysMessage(LANG_NPCINFO_FLAGS
, target
->GetUInt32Value(UNIT_FIELD_FLAGS
), target
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
), target
->getFaction());
3802 PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES
, defRespawnDelayStr
.c_str(),curRespawnDelayStr
.c_str());
3803 PSendSysMessage(LANG_NPCINFO_LOOT
, cInfo
->lootid
,cInfo
->pickpocketLootId
,cInfo
->SkinLootId
);
3804 PSendSysMessage(LANG_NPCINFO_DUNGEON_ID
, target
->GetInstanceId());
3805 PSendSysMessage(LANG_NPCINFO_POSITION
,float(target
->GetPositionX()), float(target
->GetPositionY()), float(target
->GetPositionZ()));
3807 if ((npcflags
& UNIT_NPC_FLAG_VENDOR
) )
3809 SendSysMessage(LANG_NPCINFO_VENDOR
);
3811 if ((npcflags
& UNIT_NPC_FLAG_TRAINER
) )
3813 SendSysMessage(LANG_NPCINFO_TRAINER
);
3820 bool ChatHandler::HandleNpcPlayEmoteCommand(const char* args
)
3822 uint32 emote
= atoi((char*)args
);
3824 Creature
* target
= getSelectedCreature();
3827 SendSysMessage(LANG_SELECT_CREATURE
);
3828 SetSentErrorMessage(true);
3832 target
->SetUInt32Value(UNIT_NPC_EMOTESTATE
,emote
);
3837 //TODO: NpcCommands that needs to be fixed :
3839 bool ChatHandler::HandleNpcAddWeaponCommand(const char* /*args*/)
3844 uint64 guid = m_session->GetPlayer()->GetSelection();
3847 SendSysMessage(LANG_NO_SELECTION);
3851 Creature *pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
3855 SendSysMessage(LANG_SELECT_CREATURE);
3859 char* pSlotID = strtok((char*)args, " ");
3863 char* pItemID = strtok(NULL, " ");
3867 uint32 ItemID = atoi(pItemID);
3868 uint32 SlotID = atoi(pSlotID);
3870 ItemPrototype* tmpItem = objmgr.GetItemPrototype(ItemID);
3878 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID);
3882 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID);
3886 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID);
3890 PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST,SlotID);
3896 PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT,ItemID,tmpItem->Name1,SlotID);
3900 PSendSysMessage(LANG_ITEM_NOT_FOUND,ItemID);
3906 //----------------------------------------------------------
3908 bool ChatHandler::HandleExploreCheatCommand(const char* args
)
3913 int flag
= atoi((char*)args
);
3915 Player
*chr
= getSelectedPlayer();
3918 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3919 SetSentErrorMessage(true);
3925 PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL
, GetNameLink(chr
).c_str());
3926 if (needReportToTarget(chr
))
3927 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_EXPLORE_SET_ALL
,GetNameLink().c_str());
3931 PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING
, GetNameLink(chr
).c_str());
3932 if (needReportToTarget(chr
))
3933 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_EXPLORE_SET_NOTHING
,GetNameLink().c_str());
3936 for (uint8 i
=0; i
<128; ++i
)
3940 m_session
->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1
+i
,0xFFFFFFFF);
3944 m_session
->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1
+i
,0);
3951 bool ChatHandler::HandleHoverCommand(const char* args
)
3953 char* px
= strtok((char*)args
, " ");
3960 m_session
->GetPlayer()->SetHover(flag
);
3963 SendSysMessage(LANG_HOVER_ENABLED
);
3965 SendSysMessage(LANG_HOVER_DISABLED
);
3970 void ChatHandler::HandleCharacterLevel(Player
* player
, uint64 player_guid
, uint32 oldlevel
, uint32 newlevel
)
3974 player
->GiveLevel(newlevel
);
3975 player
->InitTalentForLevel();
3976 player
->SetUInt32Value(PLAYER_XP
,0);
3978 if(needReportToTarget(player
))
3980 if(oldlevel
== newlevel
)
3981 ChatHandler(player
).PSendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET
,GetNameLink().c_str());
3982 else if(oldlevel
< newlevel
)
3983 ChatHandler(player
).PSendSysMessage(LANG_YOURS_LEVEL_UP
,GetNameLink().c_str(),newlevel
);
3984 else // if(oldlevel > newlevel)
3985 ChatHandler(player
).PSendSysMessage(LANG_YOURS_LEVEL_DOWN
,GetNameLink().c_str(),newlevel
);
3990 // update level and XP at level, all other will be updated at loading
3992 Player::LoadValuesArrayFromDB(values
,player_guid
);
3993 Player::SetUInt32ValueInArray(values
,UNIT_FIELD_LEVEL
,newlevel
);
3994 Player::SetUInt32ValueInArray(values
,PLAYER_XP
,0);
3995 Player::SaveValuesArrayInDB(values
,player_guid
);
3999 bool ChatHandler::HandleCharacterLevelCommand(const char* args
)
4001 char* px
= strtok((char*)args
, " ");
4002 char* py
= strtok((char*)NULL
, " ");
4004 // command format parsing
4005 char* pname
= (char*)NULL
;
4008 if(px
&& py
) // .character level $name #level
4010 newlevel
= atoi(py
);
4013 else if(px
&& !py
) // .character level $name OR .character level #level
4015 if(isalpha(px
[0])) // .character level $name
4017 else // .character level #level
4018 newlevel
= atoi(px
);
4020 // // .character level - progress reset
4023 return false; // invalid level
4025 if(newlevel
> STRONG_MAX_LEVEL
) // hardcoded maximum level
4026 newlevel
= STRONG_MAX_LEVEL
;
4030 uint64 chr_guid
= 0;
4034 if(pname
) // player by name
4036 name
= extractPlayerNameFromLink(pname
);
4039 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4040 SetSentErrorMessage(true);
4044 chr
= objmgr
.GetPlayer(name
.c_str());
4045 if(!chr
) // not in game
4047 chr_guid
= objmgr
.GetPlayerGUIDByName(name
);
4050 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4051 SetSentErrorMessage(true);
4056 else // player by selection
4058 chr
= getSelectedPlayer();
4062 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4063 SetSentErrorMessage(true);
4067 name
= chr
->GetName();
4070 assert(chr
|| chr_guid
);
4072 int32 oldlevel
= chr
? chr
->getLevel() : Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL
,chr_guid
);
4074 if(!px
&& !py
) // .character level - progress reset
4075 newlevel
= oldlevel
;
4077 HandleCharacterLevel(chr
,chr_guid
,oldlevel
,newlevel
);
4079 if(m_session
&& m_session
->GetPlayer() != chr
) // including player==NULL
4081 std::string nameLink
= playerLink(name
);
4082 PSendSysMessage(LANG_YOU_CHANGE_LVL
,nameLink
.c_str(),newlevel
);
4088 bool ChatHandler::HandleLevelUpCommand(const char* args
)
4090 char* px
= strtok((char*)args
, " ");
4091 char* py
= strtok((char*)NULL
, " ");
4093 // command format parsing
4094 char* pname
= (char*)NULL
;
4097 if(px
&& py
) // .levelup name level
4099 addlevel
= atoi(py
);
4102 else if(px
&& !py
) // .levelup name OR .levelup level
4104 if(isalpha(px
[0])) // .levelup name
4106 else // .levelup level
4107 addlevel
= atoi(px
);
4109 // else .levelup - nothing do for preparing
4113 uint64 chr_guid
= 0;
4117 if(pname
) // player by name
4119 name
= extractPlayerNameFromLink(pname
);
4122 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4123 SetSentErrorMessage(true);
4127 chr
= objmgr
.GetPlayer(name
.c_str());
4128 if(!chr
) // not in game
4130 chr_guid
= objmgr
.GetPlayerGUIDByName(name
);
4133 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4134 SetSentErrorMessage(true);
4139 else // player by selection
4141 chr
= getSelectedPlayer();
4145 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4146 SetSentErrorMessage(true);
4150 name
= chr
->GetName();
4153 assert(chr
|| chr_guid
);
4155 int32 oldlevel
= chr
? chr
->getLevel() : Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL
,chr_guid
);
4156 int32 newlevel
= oldlevel
+ addlevel
;
4159 if(newlevel
> STRONG_MAX_LEVEL
) // hardcoded maximum level
4160 newlevel
= STRONG_MAX_LEVEL
;
4162 HandleCharacterLevel(chr
,chr_guid
,oldlevel
,newlevel
);
4164 if(m_session
&& m_session
->GetPlayer() != chr
) // including chr==NULL
4166 std::string nameLink
= playerLink(name
);
4167 PSendSysMessage(LANG_YOU_CHANGE_LVL
,nameLink
.c_str(),newlevel
);
4173 bool ChatHandler::HandleShowAreaCommand(const char* args
)
4178 Player
*chr
= getSelectedPlayer();
4181 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4182 SetSentErrorMessage(true);
4186 int area
= GetAreaFlagByAreaID(atoi((char*)args
));
4187 int offset
= area
/ 32;
4188 uint32 val
= (uint32
)(1 << (area
% 32));
4190 if(area
<0 || offset
>= 128)
4192 SendSysMessage(LANG_BAD_VALUE
);
4193 SetSentErrorMessage(true);
4197 uint32 currFields
= chr
->GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
4198 chr
->SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
| val
));
4200 SendSysMessage(LANG_EXPLORE_AREA
);
4204 bool ChatHandler::HandleHideAreaCommand(const char* args
)
4209 Player
*chr
= getSelectedPlayer();
4212 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4213 SetSentErrorMessage(true);
4217 int area
= GetAreaFlagByAreaID(atoi((char*)args
));
4218 int offset
= area
/ 32;
4219 uint32 val
= (uint32
)(1 << (area
% 32));
4221 if(area
<0 || offset
>= 128)
4223 SendSysMessage(LANG_BAD_VALUE
);
4224 SetSentErrorMessage(true);
4228 uint32 currFields
= chr
->GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
4229 chr
->SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
^ val
));
4231 SendSysMessage(LANG_UNEXPLORE_AREA
);
4235 bool ChatHandler::HandleDebugUpdate(const char* args
)
4243 char* pUpdateIndex
= strtok((char*)args
, " ");
4245 Unit
* chr
= getSelectedUnit();
4248 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4249 SetSentErrorMessage(true);
4257 updateIndex
= atoi(pUpdateIndex
);
4259 if(chr
->GetTypeId() == TYPEID_PLAYER
)
4261 if (updateIndex
>=PLAYER_END
) return true;
4265 if (updateIndex
>=UNIT_END
) return true;
4268 char* pvalue
= strtok(NULL
, " ");
4271 value
=chr
->GetUInt32Value(updateIndex
);
4273 PSendSysMessage(LANG_UPDATE
, chr
->GetGUIDLow(),updateIndex
,value
);
4279 PSendSysMessage(LANG_UPDATE_CHANGE
, chr
->GetGUIDLow(),updateIndex
,value
);
4281 chr
->SetUInt32Value(updateIndex
,value
);
4286 bool ChatHandler::HandleBankCommand(const char* /*args*/)
4288 m_session
->SendShowBank( m_session
->GetPlayer()->GetGUID() );
4293 bool ChatHandler::HandleChangeWeather(const char* args
)
4299 if (!sWorld
.getConfig(CONFIG_WEATHER
))
4301 SendSysMessage(LANG_WEATHER_DISABLED
);
4302 SetSentErrorMessage(true);
4306 //*Change the weather of a cell
4307 char* px
= strtok((char*)args
, " ");
4308 char* py
= strtok(NULL
, " ");
4313 uint32 type
= (uint32
)atoi(px
); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
4314 float grade
= (float)atof(py
); //0 to 1, sending -1 is instand good weather
4316 Player
*player
= m_session
->GetPlayer();
4317 uint32 zoneid
= player
->GetZoneId();
4319 Weather
* wth
= sWorld
.FindWeather(zoneid
);
4322 wth
= sWorld
.AddWeather(zoneid
);
4325 SendSysMessage(LANG_NO_WEATHER
);
4326 SetSentErrorMessage(true);
4330 wth
->SetWeather(WeatherType(type
), grade
);
4335 bool ChatHandler::HandleDebugSetValue(const char* args
)
4340 char* px
= strtok((char*)args
, " ");
4341 char* py
= strtok(NULL
, " ");
4342 char* pz
= strtok(NULL
, " ");
4347 Unit
* target
= getSelectedUnit();
4350 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4351 SetSentErrorMessage(true);
4355 uint64 guid
= target
->GetGUID();
4357 uint32 Opcode
= (uint32
)atoi(px
);
4358 if(Opcode
>= target
->GetValuesCount())
4360 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, GUID_LOPART(guid
), target
->GetValuesCount());
4365 bool isint32
= true;
4367 isint32
= (bool)atoi(pz
);
4370 iValue
= (uint32
)atoi(py
);
4371 sLog
.outDebug(GetMangosString(LANG_SET_UINT
), GUID_LOPART(guid
), Opcode
, iValue
);
4372 target
->SetUInt32Value( Opcode
, iValue
);
4373 PSendSysMessage(LANG_SET_UINT_FIELD
, GUID_LOPART(guid
), Opcode
,iValue
);
4377 fValue
= (float)atof(py
);
4378 sLog
.outDebug(GetMangosString(LANG_SET_FLOAT
), GUID_LOPART(guid
), Opcode
, fValue
);
4379 target
->SetFloatValue( Opcode
, fValue
);
4380 PSendSysMessage(LANG_SET_FLOAT_FIELD
, GUID_LOPART(guid
), Opcode
,fValue
);
4386 bool ChatHandler::HandleDebugGetValue(const char* args
)
4391 char* px
= strtok((char*)args
, " ");
4392 char* pz
= strtok(NULL
, " ");
4397 Unit
* target
= getSelectedUnit();
4400 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4401 SetSentErrorMessage(true);
4405 uint64 guid
= target
->GetGUID();
4407 uint32 Opcode
= (uint32
)atoi(px
);
4408 if(Opcode
>= target
->GetValuesCount())
4410 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, GUID_LOPART(guid
), target
->GetValuesCount());
4415 bool isint32
= true;
4417 isint32
= (bool)atoi(pz
);
4421 iValue
= target
->GetUInt32Value( Opcode
);
4422 sLog
.outDebug(GetMangosString(LANG_GET_UINT
), GUID_LOPART(guid
), Opcode
, iValue
);
4423 PSendSysMessage(LANG_GET_UINT_FIELD
, GUID_LOPART(guid
), Opcode
, iValue
);
4427 fValue
= target
->GetFloatValue( Opcode
);
4428 sLog
.outDebug(GetMangosString(LANG_GET_FLOAT
), GUID_LOPART(guid
), Opcode
, fValue
);
4429 PSendSysMessage(LANG_GET_FLOAT_FIELD
, GUID_LOPART(guid
), Opcode
, fValue
);
4435 bool ChatHandler::HandleSet32Bit(const char* args
)
4440 char* px
= strtok((char*)args
, " ");
4441 char* py
= strtok(NULL
, " ");
4446 uint32 Opcode
= (uint32
)atoi(px
);
4447 uint32 Value
= (uint32
)atoi(py
);
4448 if (Value
> 32) //uint32 = 32 bits
4451 sLog
.outDebug(GetMangosString(LANG_SET_32BIT
), Opcode
, Value
);
4453 m_session
->GetPlayer( )->SetUInt32Value( Opcode
, 2^Value
);
4455 PSendSysMessage(LANG_SET_32BIT_FIELD
, Opcode
,1);
4459 bool ChatHandler::HandleDebugMod32Value(const char* args
)
4464 char* px
= strtok((char*)args
, " ");
4465 char* py
= strtok(NULL
, " ");
4470 uint32 Opcode
= (uint32
)atoi(px
);
4471 int Value
= atoi(py
);
4473 if(Opcode
>= m_session
->GetPlayer()->GetValuesCount())
4475 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, m_session
->GetPlayer()->GetGUIDLow(), m_session
->GetPlayer( )->GetValuesCount());
4479 sLog
.outDebug(GetMangosString(LANG_CHANGE_32BIT
), Opcode
, Value
);
4481 int CurrentValue
= (int)m_session
->GetPlayer( )->GetUInt32Value( Opcode
);
4483 CurrentValue
+= Value
;
4484 m_session
->GetPlayer( )->SetUInt32Value( Opcode
, (uint32
)CurrentValue
);
4486 PSendSysMessage(LANG_CHANGE_32BIT_FIELD
, Opcode
,CurrentValue
);
4491 bool ChatHandler::HandleTeleAddCommand(const char * args
)
4496 Player
*player
=m_session
->GetPlayer();
4500 std::string name
= args
;
4502 if(objmgr
.GetGameTele(name
))
4504 SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST
);
4505 SetSentErrorMessage(true);
4510 tele
.position_x
= player
->GetPositionX();
4511 tele
.position_y
= player
->GetPositionY();
4512 tele
.position_z
= player
->GetPositionZ();
4513 tele
.orientation
= player
->GetOrientation();
4514 tele
.mapId
= player
->GetMapId();
4517 if(objmgr
.AddGameTele(tele
))
4519 SendSysMessage(LANG_COMMAND_TP_ADDED
);
4523 SendSysMessage(LANG_COMMAND_TP_ADDEDERR
);
4524 SetSentErrorMessage(true);
4531 bool ChatHandler::HandleTeleDelCommand(const char * args
)
4536 std::string name
= args
;
4538 if(!objmgr
.DeleteGameTele(name
))
4540 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
4541 SetSentErrorMessage(true);
4545 SendSysMessage(LANG_COMMAND_TP_DELETED
);
4549 bool ChatHandler::HandleListAurasCommand (const char * /*args*/)
4551 Unit
*unit
= getSelectedUnit();
4554 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4555 SetSentErrorMessage(true);
4559 char const* talentStr
= GetMangosString(LANG_TALENT
);
4560 char const* passiveStr
= GetMangosString(LANG_PASSIVE
);
4562 Unit::AuraMap
const& uAuras
= unit
->GetAuras();
4563 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS
, uAuras
.size());
4564 for (Unit::AuraMap::const_iterator itr
= uAuras
.begin(); itr
!= uAuras
.end(); ++itr
)
4566 bool talent
= GetTalentSpellCost(itr
->second
->GetId()) > 0;
4568 char const* name
= itr
->second
->GetSpellProto()->SpellName
[m_session
->GetSessionDbcLocale()];
4572 std::ostringstream ss_name
;
4573 ss_name
<< "|cffffffff|Hspell:" << itr
->second
->GetId() << "|h[" << name
<< "]|h|r";
4575 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL
, itr
->second
->GetId(), itr
->second
->GetEffIndex(),
4576 itr
->second
->GetModifier()->m_auraname
, itr
->second
->GetAuraDuration(), itr
->second
->GetAuraMaxDuration(),
4577 ss_name
.str().c_str(),
4578 (itr
->second
->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4579 IS_PLAYER_GUID(itr
->second
->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr
->second
->GetCasterGUID()));
4583 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL
, itr
->second
->GetId(), itr
->second
->GetEffIndex(),
4584 itr
->second
->GetModifier()->m_auraname
, itr
->second
->GetAuraDuration(), itr
->second
->GetAuraMaxDuration(),
4586 (itr
->second
->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4587 IS_PLAYER_GUID(itr
->second
->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr
->second
->GetCasterGUID()));
4590 for (int i
= 0; i
< TOTAL_AURAS
; ++i
)
4592 Unit::AuraList
const& uAuraList
= unit
->GetAurasByType(AuraType(i
));
4593 if (uAuraList
.empty()) continue;
4594 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE
, uAuraList
.size(), i
);
4595 for (Unit::AuraList::const_iterator itr
= uAuraList
.begin(); itr
!= uAuraList
.end(); ++itr
)
4597 bool talent
= GetTalentSpellCost((*itr
)->GetId()) > 0;
4599 char const* name
= (*itr
)->GetSpellProto()->SpellName
[m_session
->GetSessionDbcLocale()];
4603 std::ostringstream ss_name
;
4604 ss_name
<< "|cffffffff|Hspell:" << (*itr
)->GetId() << "|h[" << name
<< "]|h|r";
4606 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE
, (*itr
)->GetId(), (*itr
)->GetEffIndex(),
4607 ss_name
.str().c_str(),((*itr
)->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4608 IS_PLAYER_GUID((*itr
)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr
)->GetCasterGUID()));
4612 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE
, (*itr
)->GetId(), (*itr
)->GetEffIndex(),
4613 name
,((*itr
)->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4614 IS_PLAYER_GUID((*itr
)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr
)->GetCasterGUID()));
4621 bool ChatHandler::HandleResetAchievementsCommand (const char * args
)
4623 char* pName
= strtok((char*)args
, "");
4624 Player
*player
= NULL
;
4628 std::string name
= extractPlayerNameFromLink(pName
);
4631 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4632 SetSentErrorMessage(true);
4636 guid
= objmgr
.GetPlayerGUIDByName(name
);
4637 player
= objmgr
.GetPlayer(guid
);
4641 player
= getSelectedPlayer();
4643 guid
= player
->GetGUID();
4646 if(!player
&& !guid
)
4648 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4653 player
->GetAchievementMgr().Reset();
4655 AchievementMgr::DeleteFromDB(GUID_LOPART(guid
));
4660 bool ChatHandler::HandleResetHonorCommand (const char * args
)
4662 char* pName
= strtok((char*)args
, "");
4663 Player
*player
= NULL
;
4666 std::string name
= extractPlayerNameFromLink(pName
);
4669 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4670 SetSentErrorMessage(true);
4674 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
);
4675 player
= objmgr
.GetPlayer(guid
);
4678 player
= getSelectedPlayer();
4682 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4686 player
->SetUInt32Value(PLAYER_FIELD_KILLS
, 0);
4687 player
->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS
, 0);
4688 player
->SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY
, 0);
4689 player
->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION
, 0);
4690 player
->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION
, 0);
4692 player
->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_EARN_HONORABLE_KILL
);
4697 static bool HandleResetStatsOrLevelHelper(Player
* player
)
4699 PlayerInfo
const *info
= objmgr
.GetPlayerInfo(player
->getRace(), player
->getClass());
4700 if(!info
) return false;
4702 ChrClassesEntry
const* cEntry
= sChrClassesStore
.LookupEntry(player
->getClass());
4705 sLog
.outError("Class %u not found in DBC (Wrong DBC files?)",player
->getClass());
4709 uint8 powertype
= cEntry
->powerType
;
4711 // reset m_form if no aura
4712 if(!player
->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT
))
4713 player
->m_form
= FORM_NONE
;
4715 player
->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS
, DEFAULT_WORLD_OBJECT_SIZE
);
4716 player
->SetFloatValue(UNIT_FIELD_COMBATREACH
, 1.5f
);
4718 player
->setFactionForRace(player
->getRace());
4720 player
->SetUInt32Value(UNIT_FIELD_BYTES_0
, ( ( player
->getRace() ) | ( player
->getClass() << 8 ) | ( player
->getGender() << 16 ) | ( powertype
<< 24 ) ) );
4722 // reset only if player not in some form;
4723 if(player
->m_form
==FORM_NONE
)
4725 switch(player
->getGender())
4728 player
->SetDisplayId(info
->displayId_f
);
4729 player
->SetNativeDisplayId(info
->displayId_f
);
4732 player
->SetDisplayId(info
->displayId_m
);
4733 player
->SetNativeDisplayId(info
->displayId_m
);
4740 player
->SetByteValue(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_PVP
);
4741 player
->SetByteValue(UNIT_FIELD_BYTES_2
, 3, player
->m_form
);
4743 player
->SetUInt32Value(UNIT_FIELD_FLAGS
, UNIT_FLAG_PVP_ATTACKABLE
);
4745 //-1 is default value
4746 player
->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX
, uint32(-1));
4748 //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000 );
4752 bool ChatHandler::HandleResetLevelCommand(const char * args
)
4754 char* pName
= strtok((char*)args
, "");
4755 Player
*player
= NULL
;
4758 std::string name
= extractPlayerNameFromLink(pName
);
4761 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4762 SetSentErrorMessage(true);
4766 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
);
4767 player
= objmgr
.GetPlayer(guid
);
4770 player
= getSelectedPlayer();
4774 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4775 SetSentErrorMessage(true);
4779 if(!HandleResetStatsOrLevelHelper(player
))
4782 // set starting level
4783 uint32 start_level
= player
->getClass() != CLASS_DEATH_KNIGHT
4784 ? sWorld
.getConfig(CONFIG_START_PLAYER_LEVEL
)
4785 : sWorld
.getConfig(CONFIG_START_HEROIC_PLAYER_LEVEL
);
4787 player
->SetLevel(start_level
);
4788 player
->InitRunes();
4789 player
->InitStatsForLevel(true);
4790 player
->InitTaxiNodesForLevel();
4791 player
->InitGlyphsForLevel();
4792 player
->InitTalentForLevel();
4793 player
->SetUInt32Value(PLAYER_XP
,0);
4795 // reset level to summoned pet
4796 Pet
* pet
= player
->GetPet();
4797 if(pet
&& pet
->getPetType()==SUMMON_PET
)
4799 pet
->InitStatsForLevel(1);
4800 pet
->InitTalentForLevel();
4805 bool ChatHandler::HandleResetStatsCommand(const char * args
)
4807 char* pName
= strtok((char*)args
, "");
4808 Player
*player
= NULL
;
4811 std::string name
= extractPlayerNameFromLink(pName
);
4814 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4815 SetSentErrorMessage(true);
4819 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
);
4820 player
= objmgr
.GetPlayer(guid
);
4823 player
= getSelectedPlayer();
4827 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4828 SetSentErrorMessage(true);
4832 if(!HandleResetStatsOrLevelHelper(player
))
4835 player
->InitRunes();
4836 player
->InitStatsForLevel(true);
4837 player
->InitTaxiNodesForLevel();
4838 player
->InitGlyphsForLevel();
4839 player
->InitTalentForLevel();
4844 bool ChatHandler::HandleResetSpellsCommand(const char * args
)
4846 char* pName
= strtok((char*)args
, "");
4847 Player
*player
= NULL
;
4848 uint64 playerGUID
= 0;
4851 std::string name
= extractPlayerNameFromLink(pName
);
4854 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4855 SetSentErrorMessage(true);
4859 player
= objmgr
.GetPlayer(name
.c_str());
4861 playerGUID
= objmgr
.GetPlayerGUIDByName(name
);
4864 player
= getSelectedPlayer();
4866 if(!player
&& !playerGUID
)
4868 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4869 SetSentErrorMessage(true);
4875 player
->resetSpells();
4877 ChatHandler(player
).SendSysMessage(LANG_RESET_SPELLS
);
4878 if(m_session
->GetPlayer()!=player
)
4879 PSendSysMessage(LANG_RESET_SPELLS_ONLINE
,GetNameLink(player
).c_str());
4883 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS
), GUID_LOPART(playerGUID
));
4884 PSendSysMessage(LANG_RESET_SPELLS_OFFLINE
,pName
);
4890 bool ChatHandler::HandleResetTalentsCommand(const char * args
)
4892 char* pName
= strtok((char*)args
, "");
4893 Player
*player
= NULL
;
4894 uint64 playerGUID
= 0;
4897 std::string name
= extractPlayerNameFromLink(pName
);
4900 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4901 SetSentErrorMessage(true);
4905 player
= objmgr
.GetPlayer(name
.c_str());
4907 playerGUID
= objmgr
.GetPlayerGUIDByName(name
);
4910 player
= getSelectedPlayer();
4914 player
->resetTalents(true);
4916 ChatHandler(player
).SendSysMessage(LANG_RESET_TALENTS
);
4917 if(m_session
->GetPlayer()!=player
)
4918 PSendSysMessage(LANG_RESET_TALENTS_ONLINE
,GetNameLink(player
).c_str());
4922 else if (playerGUID
)
4924 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_TALENTS
), GUID_LOPART(playerGUID
) );
4925 std::string nameLink
= playerLink(pName
);
4926 PSendSysMessage(LANG_RESET_TALENTS_OFFLINE
,nameLink
.c_str());
4929 // Try reset talenents as Hunter Pet
4930 Creature
* creature
= getSelectedCreature();
4931 if (creature
&& creature
->isPet() && ((Pet
*)creature
)->getPetType() == HUNTER_PET
)
4933 ((Pet
*)creature
)->resetTalents(true);
4934 Unit
*owner
= creature
->GetOwner();
4935 if (owner
&& owner
->GetTypeId() == TYPEID_PLAYER
)
4937 player
= (Player
*)owner
;
4938 ChatHandler(player
).SendSysMessage(LANG_RESET_PET_TALENTS
);
4939 if(m_session
->GetPlayer()!=player
)
4940 PSendSysMessage(LANG_RESET_PET_TALENTS_ONLINE
,GetNameLink(player
).c_str());
4945 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4946 SetSentErrorMessage(true);
4950 bool ChatHandler::HandleResetAllCommand(const char * args
)
4955 std::string casename
= args
;
4957 AtLoginFlags atLogin
;
4959 // Command specially created as single command to prevent using short case names
4960 if(casename
=="spells")
4962 atLogin
= AT_LOGIN_RESET_SPELLS
;
4963 sWorld
.SendWorldText(LANG_RESETALL_SPELLS
);
4965 else if(casename
=="talents")
4967 atLogin
= AT_LOGIN_RESET_TALENTS
;
4968 sWorld
.SendWorldText(LANG_RESETALL_TALENTS
);
4972 PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE
,args
);
4973 SetSentErrorMessage(true);
4977 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE (at_login & '%u') = '0'",atLogin
,atLogin
);
4978 HashMapHolder
<Player
>::MapType
const& plist
= ObjectAccessor::Instance().GetPlayers();
4979 for(HashMapHolder
<Player
>::MapType::const_iterator itr
= plist
.begin(); itr
!= plist
.end(); ++itr
)
4980 itr
->second
->SetAtLoginFlag(atLogin
);
4985 bool ChatHandler::HandleServerShutDownCancelCommand(const char* /*args*/)
4987 sWorld
.ShutdownCancel();
4991 bool ChatHandler::HandleServerShutDownCommand(const char* args
)
4996 char* time_str
= strtok ((char*) args
, " ");
4997 char* exitcode_str
= strtok (NULL
, "");
4999 int32 time
= atoi (time_str
);
5001 ///- Prevent interpret wrong arg value as 0 secs shutdown time
5002 if ((time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0')) || time
< 0)
5007 int32 exitcode
= atoi (exitcode_str
);
5009 // Handle atoi() errors
5010 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
5013 // Exit code should be in range of 0-125, 126-255 is used
5014 // in many shells for their own return codes and code > 255
5015 // is not supported in many others
5016 if (exitcode
< 0 || exitcode
> 125)
5019 sWorld
.ShutdownServ (time
, 0, exitcode
);
5022 sWorld
.ShutdownServ(time
,0,SHUTDOWN_EXIT_CODE
);
5026 bool ChatHandler::HandleServerRestartCommand(const char* args
)
5031 char* time_str
= strtok ((char*) args
, " ");
5032 char* exitcode_str
= strtok (NULL
, "");
5034 int32 time
= atoi (time_str
);
5036 ///- Prevent interpret wrong arg value as 0 secs shutdown time
5037 if(time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0') || time
< 0)
5042 int32 exitcode
= atoi (exitcode_str
);
5044 // Handle atoi() errors
5045 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
5048 // Exit code should be in range of 0-125, 126-255 is used
5049 // in many shells for their own return codes and code > 255
5050 // is not supported in many others
5051 if (exitcode
< 0 || exitcode
> 125)
5054 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_RESTART
, exitcode
);
5057 sWorld
.ShutdownServ(time
, SHUTDOWN_MASK_RESTART
, RESTART_EXIT_CODE
);
5061 bool ChatHandler::HandleServerIdleRestartCommand(const char* args
)
5066 char* time_str
= strtok ((char*) args
, " ");
5067 char* exitcode_str
= strtok (NULL
, "");
5069 int32 time
= atoi (time_str
);
5071 ///- Prevent interpret wrong arg value as 0 secs shutdown time
5072 if(time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0') || time
< 0)
5077 int32 exitcode
= atoi (exitcode_str
);
5079 // Handle atoi() errors
5080 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
5083 // Exit code should be in range of 0-125, 126-255 is used
5084 // in many shells for their own return codes and code > 255
5085 // is not supported in many others
5086 if (exitcode
< 0 || exitcode
> 125)
5089 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_RESTART
|SHUTDOWN_MASK_IDLE
, exitcode
);
5092 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_RESTART
|SHUTDOWN_MASK_IDLE
,RESTART_EXIT_CODE
);
5096 bool ChatHandler::HandleServerIdleShutDownCommand(const char* args
)
5101 char* time_str
= strtok ((char*) args
, " ");
5102 char* exitcode_str
= strtok (NULL
, "");
5104 int32 time
= atoi (time_str
);
5106 ///- Prevent interpret wrong arg value as 0 secs shutdown time
5107 if(time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0') || time
< 0)
5112 int32 exitcode
= atoi (exitcode_str
);
5114 // Handle atoi() errors
5115 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
5118 // Exit code should be in range of 0-125, 126-255 is used
5119 // in many shells for their own return codes and code > 255
5120 // is not supported in many others
5121 if (exitcode
< 0 || exitcode
> 125)
5124 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_IDLE
, exitcode
);
5127 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_IDLE
,SHUTDOWN_EXIT_CODE
);
5131 bool ChatHandler::HandleQuestAdd(const char* args
)
5133 Player
* player
= getSelectedPlayer();
5136 SendSysMessage(LANG_NO_CHAR_SELECTED
);
5137 SetSentErrorMessage(true);
5141 // .addquest #entry'
5142 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
5143 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
5147 uint32 entry
= atol(cId
);
5149 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
5153 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
,entry
);
5154 SetSentErrorMessage(true);
5158 // check item starting quest (it can work incorrectly if added without item in inventory)
5159 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
5161 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
5165 if (pProto
->StartQuest
== entry
)
5167 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM
, entry
, pProto
->ItemId
);
5168 SetSentErrorMessage(true);
5173 // ok, normal (creature/GO starting) quest
5174 if( player
->CanAddQuest( pQuest
, true ) )
5176 player
->AddQuest( pQuest
, NULL
);
5178 if ( player
->CanCompleteQuest( entry
) )
5179 player
->CompleteQuest( entry
);
5185 bool ChatHandler::HandleQuestRemove(const char* args
)
5187 Player
* player
= getSelectedPlayer();
5190 SendSysMessage(LANG_NO_CHAR_SELECTED
);
5191 SetSentErrorMessage(true);
5195 // .removequest #entry'
5196 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
5197 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
5201 uint32 entry
= atol(cId
);
5203 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
5207 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
5208 SetSentErrorMessage(true);
5212 // remove all quest entries for 'entry' from quest log
5213 for(uint8 slot
= 0; slot
< MAX_QUEST_LOG_SIZE
; ++slot
)
5215 uint32 quest
= player
->GetQuestSlotQuestId(slot
);
5218 player
->SetQuestSlot(slot
,0);
5220 // we ignore unequippable quest items in this case, its' still be equipped
5221 player
->TakeQuestSourceItem( quest
, false );
5225 // set quest status to not started (will updated in DB at next save)
5226 player
->SetQuestStatus( entry
, QUEST_STATUS_NONE
);
5228 // reset rewarded for restart repeatable quest
5229 player
->getQuestStatusMap()[entry
].m_rewarded
= false;
5231 SendSysMessage(LANG_COMMAND_QUEST_REMOVED
);
5235 bool ChatHandler::HandleQuestComplete(const char* args
)
5237 Player
* player
= getSelectedPlayer();
5240 SendSysMessage(LANG_NO_CHAR_SELECTED
);
5241 SetSentErrorMessage(true);
5245 // .quest complete #entry
5246 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
5247 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
5251 uint32 entry
= atol(cId
);
5253 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
5255 // If player doesn't have the quest
5256 if(!pQuest
|| player
->GetQuestStatus(entry
) == QUEST_STATUS_NONE
)
5258 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
5259 SetSentErrorMessage(true);
5263 // Add quest items for quests that require items
5264 for(uint8 x
= 0; x
< QUEST_OBJECTIVES_COUNT
; ++x
)
5266 uint32 id
= pQuest
->ReqItemId
[x
];
5267 uint32 count
= pQuest
->ReqItemCount
[x
];
5271 uint32 curItemCount
= player
->GetItemCount(id
,true);
5273 ItemPosCountVec dest
;
5274 uint8 msg
= player
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, id
, count
-curItemCount
);
5275 if( msg
== EQUIP_ERR_OK
)
5277 Item
* item
= player
->StoreNewItem( dest
, id
, true);
5278 player
->SendNewItem(item
,count
-curItemCount
,true,false);
5282 // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
5283 for(uint8 i
= 0; i
< QUEST_OBJECTIVES_COUNT
; ++i
)
5285 uint32 creature
= pQuest
->ReqCreatureOrGOId
[i
];
5286 uint32 creaturecount
= pQuest
->ReqCreatureOrGOCount
[i
];
5288 if(uint32 spell_id
= pQuest
->ReqSpell
[i
])
5290 for(uint16 z
= 0; z
< creaturecount
; ++z
)
5291 player
->CastedCreatureOrGO(creature
,0,spell_id
);
5293 else if(creature
> 0)
5295 for(uint16 z
= 0; z
< creaturecount
; ++z
)
5296 player
->KilledMonster(creature
,0);
5298 else if(creature
< 0)
5300 for(uint16 z
= 0; z
< creaturecount
; ++z
)
5301 player
->CastedCreatureOrGO(creature
,0,0);
5305 // If the quest requires reputation to complete
5306 if(uint32 repFaction
= pQuest
->GetRepObjectiveFaction())
5308 uint32 repValue
= pQuest
->GetRepObjectiveValue();
5309 uint32 curRep
= player
->GetReputationMgr().GetReputation(repFaction
);
5310 if(curRep
< repValue
)
5311 if(FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry(repFaction
))
5312 player
->GetReputationMgr().SetReputation(factionEntry
,repValue
);
5315 // If the quest requires money
5316 int32 ReqOrRewMoney
= pQuest
->GetRewOrReqMoney();
5317 if(ReqOrRewMoney
< 0)
5318 player
->ModifyMoney(-ReqOrRewMoney
);
5320 player
->CompleteQuest(entry
);
5324 bool ChatHandler::HandleBanAccountCommand(const char* args
)
5326 return HandleBanHelper(BAN_ACCOUNT
,args
);
5329 bool ChatHandler::HandleBanCharacterCommand(const char* args
)
5331 return HandleBanHelper(BAN_CHARACTER
,args
);
5334 bool ChatHandler::HandleBanIPCommand(const char* args
)
5336 return HandleBanHelper(BAN_IP
,args
);
5339 bool ChatHandler::HandleBanHelper(BanMode mode
, const char* args
)
5344 char* cnameOrIP
= strtok ((char*)args
, " ");
5348 std::string nameOrIP
= cnameOrIP
;
5350 char* duration
= strtok (NULL
," ");
5351 if(!duration
|| !atoi(duration
))
5354 char* reason
= strtok (NULL
,"");
5361 if(!AccountMgr::normilizeString(nameOrIP
))
5363 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
5364 SetSentErrorMessage(true);
5369 if(!normalizePlayerName(nameOrIP
))
5371 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5372 SetSentErrorMessage(true);
5377 if(!IsIPAddress(nameOrIP
.c_str()))
5382 switch(sWorld
.BanAccount(mode
, nameOrIP
, duration
, reason
,m_session
? m_session
->GetPlayerName() : ""))
5385 if(atoi(duration
)>0)
5386 PSendSysMessage(LANG_BAN_YOUBANNED
,nameOrIP
.c_str(),secsToTimeString(TimeStringToSecs(duration
),true).c_str(),reason
);
5388 PSendSysMessage(LANG_BAN_YOUPERMBANNED
,nameOrIP
.c_str(),reason
);
5390 case BAN_SYNTAX_ERROR
:
5396 PSendSysMessage(LANG_BAN_NOTFOUND
,"account",nameOrIP
.c_str());
5399 PSendSysMessage(LANG_BAN_NOTFOUND
,"character",nameOrIP
.c_str());
5402 PSendSysMessage(LANG_BAN_NOTFOUND
,"ip",nameOrIP
.c_str());
5405 SetSentErrorMessage(true);
5412 bool ChatHandler::HandleUnBanAccountCommand(const char* args
)
5414 return HandleUnBanHelper(BAN_ACCOUNT
,args
);
5417 bool ChatHandler::HandleUnBanCharacterCommand(const char* args
)
5419 return HandleUnBanHelper(BAN_CHARACTER
,args
);
5422 bool ChatHandler::HandleUnBanIPCommand(const char* args
)
5424 return HandleUnBanHelper(BAN_IP
,args
);
5427 bool ChatHandler::HandleUnBanHelper(BanMode mode
, const char* args
)
5432 char* cnameOrIP
= strtok ((char*)args
, " ");
5436 std::string nameOrIP
= cnameOrIP
;
5441 if(!AccountMgr::normilizeString(nameOrIP
))
5443 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
5444 SetSentErrorMessage(true);
5449 if(!normalizePlayerName(nameOrIP
))
5451 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5452 SetSentErrorMessage(true);
5457 if(!IsIPAddress(nameOrIP
.c_str()))
5462 if(sWorld
.RemoveBanAccount(mode
,nameOrIP
))
5463 PSendSysMessage(LANG_UNBAN_UNBANNED
,nameOrIP
.c_str());
5465 PSendSysMessage(LANG_UNBAN_ERROR
,nameOrIP
.c_str());
5470 bool ChatHandler::HandleBanInfoAccountCommand(const char* args
)
5475 char* cname
= strtok((char*)args
, "");
5479 std::string account_name
= cname
;
5480 if(!AccountMgr::normilizeString(account_name
))
5482 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5483 SetSentErrorMessage(true);
5487 uint32 accountid
= accmgr
.GetId(account_name
);
5490 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5494 return HandleBanInfoHelper(accountid
,account_name
.c_str());
5497 bool ChatHandler::HandleBanInfoCharacterCommand(const char* args
)
5502 std::string name
= extractPlayerNameFromLink((char*)args
);
5505 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5506 SetSentErrorMessage(true);
5510 uint32 accountid
= objmgr
.GetPlayerAccountIdByPlayerName(name
);
5513 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5514 SetSentErrorMessage(true);
5518 std::string accountname
;
5519 if(!accmgr
.GetName(accountid
,accountname
))
5521 PSendSysMessage(LANG_BANINFO_NOCHARACTER
);
5525 return HandleBanInfoHelper(accountid
,accountname
.c_str());
5528 bool ChatHandler::HandleBanInfoHelper(uint32 accountid
, char const* accountname
)
5530 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
);
5533 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN
, accountname
);
5537 PSendSysMessage(LANG_BANINFO_BANHISTORY
,accountname
);
5540 Field
* fields
= result
->Fetch();
5542 time_t unbandate
= time_t(fields
[3].GetUInt64());
5543 bool active
= false;
5544 if(fields
[2].GetBool() && (fields
[1].GetUInt64() == (uint64
)0 ||unbandate
>= time(NULL
)) )
5546 bool permanent
= (fields
[1].GetUInt64() == (uint64
)0);
5547 std::string bantime
= permanent
?GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[1].GetUInt64(), true);
5548 PSendSysMessage(LANG_BANINFO_HISTORYENTRY
,
5549 fields
[0].GetString(), bantime
.c_str(), active
? GetMangosString(LANG_BANINFO_YES
):GetMangosString(LANG_BANINFO_NO
), fields
[4].GetString(), fields
[5].GetString());
5550 }while (result
->NextRow());
5556 bool ChatHandler::HandleBanInfoIPCommand(const char* args
)
5561 char* cIP
= strtok ((char*)args
, "");
5565 if (!IsIPAddress(cIP
))
5568 std::string IP
= cIP
;
5570 loginDatabase
.escape_string(IP
);
5571 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());
5574 PSendSysMessage(LANG_BANINFO_NOIP
);
5578 Field
*fields
= result
->Fetch();
5579 bool permanent
= !fields
[6].GetUInt64();
5580 PSendSysMessage(LANG_BANINFO_IPENTRY
,
5581 fields
[0].GetString(), fields
[1].GetString(), permanent
? GetMangosString(LANG_BANINFO_NEVER
):fields
[2].GetString(),
5582 permanent
? GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[3].GetUInt64(), true).c_str(), fields
[4].GetString(), fields
[5].GetString());
5587 bool ChatHandler::HandleBanListCharacterCommand(const char* args
)
5589 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5591 char* cFilter
= strtok ((char*)args
, " ");
5595 std::string filter
= cFilter
;
5596 loginDatabase
.escape_string(filter
);
5597 QueryResult
* result
= CharacterDatabase
.PQuery("SELECT account FROM characters WHERE name "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'"),filter
.c_str());
5600 PSendSysMessage(LANG_BANLIST_NOCHARACTER
);
5604 return HandleBanListHelper(result
);
5607 bool ChatHandler::HandleBanListAccountCommand(const char* args
)
5609 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5611 char* cFilter
= strtok((char*)args
, " ");
5612 std::string filter
= cFilter
? cFilter
: "";
5613 loginDatabase
.escape_string(filter
);
5615 QueryResult
* result
;
5619 result
= loginDatabase
.Query("SELECT account.id, username FROM account, account_banned"
5620 " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
5624 result
= loginDatabase
.PQuery("SELECT account.id, username FROM account, account_banned"
5625 " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
5631 PSendSysMessage(LANG_BANLIST_NOACCOUNT
);
5635 return HandleBanListHelper(result
);
5638 bool ChatHandler::HandleBanListHelper(QueryResult
* result
)
5640 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT
);
5642 // Chat short output
5647 Field
* fields
= result
->Fetch();
5648 uint32 accountid
= fields
[0].GetUInt32();
5650 QueryResult
* banresult
= loginDatabase
.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid
);
5653 Field
* fields2
= banresult
->Fetch();
5654 PSendSysMessage("%s",fields2
[0].GetString());
5657 } while (result
->NextRow());
5659 // Console wide output
5662 SendSysMessage(LANG_BANLIST_ACCOUNTS
);
5663 SendSysMessage("===============================================================================");
5664 SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER
);
5667 SendSysMessage("-------------------------------------------------------------------------------");
5668 Field
*fields
= result
->Fetch();
5669 uint32 account_id
= fields
[0].GetUInt32 ();
5671 std::string account_name
;
5673 // "account" case, name can be get in same query
5674 if(result
->GetFieldCount() > 1)
5675 account_name
= fields
[1].GetCppString();
5676 // "character" case, name need extract from another DB
5678 accmgr
.GetName (account_id
,account_name
);
5680 // No SQL injection. id is uint32.
5681 QueryResult
*banInfo
= loginDatabase
.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id
);
5684 Field
*fields2
= banInfo
->Fetch();
5687 time_t t_ban
= fields2
[0].GetUInt64();
5688 tm
* aTm_ban
= localtime(&t_ban
);
5690 if (fields2
[0].GetUInt64() == fields2
[1].GetUInt64())
5692 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5693 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
,
5694 fields2
[2].GetString(),fields2
[3].GetString());
5698 time_t t_unban
= fields2
[1].GetUInt64();
5699 tm
* aTm_unban
= localtime(&t_unban
);
5700 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5701 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
,
5702 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5703 fields2
[2].GetString(),fields2
[3].GetString());
5705 }while ( banInfo
->NextRow() );
5708 }while( result
->NextRow() );
5709 SendSysMessage("===============================================================================");
5716 bool ChatHandler::HandleBanListIPCommand(const char* args
)
5718 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5720 char* cFilter
= strtok((char*)args
, " ");
5721 std::string filter
= cFilter
? cFilter
: "";
5722 loginDatabase
.escape_string(filter
);
5724 QueryResult
* result
;
5728 result
= loginDatabase
.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5729 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
5730 " ORDER BY unbandate" );
5734 result
= loginDatabase
.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5735 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")
5736 " ORDER BY unbandate",filter
.c_str() );
5741 PSendSysMessage(LANG_BANLIST_NOIP
);
5745 PSendSysMessage(LANG_BANLIST_MATCHINGIP
);
5746 // Chat short output
5751 Field
* fields
= result
->Fetch();
5752 PSendSysMessage("%s",fields
[0].GetString());
5753 } while (result
->NextRow());
5755 // Console wide output
5758 SendSysMessage(LANG_BANLIST_IPS
);
5759 SendSysMessage("===============================================================================");
5760 SendSysMessage(LANG_BANLIST_IPS_HEADER
);
5763 SendSysMessage("-------------------------------------------------------------------------------");
5764 Field
*fields
= result
->Fetch();
5765 time_t t_ban
= fields
[1].GetUInt64();
5766 tm
* aTm_ban
= localtime(&t_ban
);
5767 if ( fields
[1].GetUInt64() == fields
[2].GetUInt64() )
5769 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5770 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
,
5771 fields
[3].GetString(), fields
[4].GetString());
5775 time_t t_unban
= fields
[2].GetUInt64();
5776 tm
* aTm_unban
= localtime(&t_unban
);
5777 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5778 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
,
5779 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5780 fields
[3].GetString(), fields
[4].GetString());
5782 }while( result
->NextRow() );
5783 SendSysMessage("===============================================================================");
5790 bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
5792 Player
* pl
= m_session
->GetPlayer();
5794 // accept only explicitly selected target (not implicitly self targeting case)
5795 Unit
* target
= getSelectedUnit();
5796 if(pl
->GetSelection() && target
)
5798 if(target
->GetTypeId()!=TYPEID_UNIT
)
5800 SendSysMessage(LANG_SELECT_CREATURE
);
5801 SetSentErrorMessage(true);
5805 if(target
->isDead())
5806 ((Creature
*)target
)->Respawn();
5810 CellPair
p(MaNGOS::ComputeCellPair(pl
->GetPositionX(), pl
->GetPositionY()));
5812 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
5815 MaNGOS::RespawnDo u_do
;
5816 MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
> worker(pl
,u_do
);
5818 TypeContainerVisitor
<MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
>, GridTypeMapContainer
> obj_worker(worker
);
5819 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
5820 cell_lock
->Visit(cell_lock
, obj_worker
, *pl
->GetMap());
5825 bool ChatHandler::HandleGMFlyCommand(const char* args
)
5830 Player
*target
= getSelectedPlayer();
5832 target
= m_session
->GetPlayer();
5834 WorldPacket
data(12);
5835 if (strncmp(args
, "on", 3) == 0)
5836 data
.SetOpcode(SMSG_MOVE_SET_CAN_FLY
);
5837 else if (strncmp(args
, "off", 4) == 0)
5838 data
.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY
);
5841 SendSysMessage(LANG_USE_BOL
);
5844 data
.append(target
->GetPackGUID());
5845 data
<< uint32(0); // unknown
5846 target
->SendMessageToSet(&data
, true);
5847 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS
, GetNameLink(target
).c_str(), args
);
5851 bool ChatHandler::HandlePDumpLoadCommand(const char *args
)
5856 char * file
= strtok((char*)args
, " ");
5860 char * account
= strtok(NULL
, " ");
5864 std::string account_name
= account
;
5865 if(!AccountMgr::normilizeString(account_name
))
5867 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5868 SetSentErrorMessage(true);
5872 uint32 account_id
= accmgr
.GetId(account_name
);
5875 account_id
= atoi(account
); // use original string
5878 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5879 SetSentErrorMessage(true);
5884 if(!accmgr
.GetName(account_id
,account_name
))
5886 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5887 SetSentErrorMessage(true);
5891 char* guid_str
= NULL
;
5892 char* name_str
= strtok(NULL
, " ");
5898 // normalize the name if specified and check if it exists
5899 if(!normalizePlayerName(name
))
5901 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5902 SetSentErrorMessage(true);
5906 if(!ObjectMgr::IsValidName(name
,true))
5908 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5909 SetSentErrorMessage(true);
5913 guid_str
= strtok(NULL
, " ");
5920 guid
= atoi(guid_str
);
5923 PSendSysMessage(LANG_INVALID_CHARACTER_GUID
);
5924 SetSentErrorMessage(true);
5928 if(objmgr
.GetPlayerAccountIdByGUID(guid
))
5930 PSendSysMessage(LANG_CHARACTER_GUID_IN_USE
,guid
);
5931 SetSentErrorMessage(true);
5936 switch(PlayerDumpReader().LoadDump(file
, account_id
, name
, guid
))
5939 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS
);
5941 case DUMP_FILE_OPEN_ERROR
:
5942 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
5943 SetSentErrorMessage(true);
5945 case DUMP_FILE_BROKEN
:
5946 PSendSysMessage(LANG_DUMP_BROKEN
,file
);
5947 SetSentErrorMessage(true);
5949 case DUMP_TOO_MANY_CHARS
:
5950 PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL
,account_name
.c_str(),account_id
);
5951 SetSentErrorMessage(true);
5954 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED
);
5955 SetSentErrorMessage(true);
5962 bool ChatHandler::HandlePDumpWriteCommand(const char *args
)
5967 char* file
= strtok((char*)args
, " ");
5968 char* p2
= strtok(NULL
, " ");
5974 // character name can't start from number
5975 if (isNumeric(p2
[0]))
5979 std::string name
= extractPlayerNameFromLink(p2
);
5982 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5983 SetSentErrorMessage(true);
5987 guid
= objmgr
.GetPlayerGUIDByName(name
);
5990 if(!objmgr
.GetPlayerAccountIdByGUID(guid
))
5992 PSendSysMessage(LANG_PLAYER_NOT_FOUND
);
5993 SetSentErrorMessage(true);
5997 switch(PlayerDumpWriter().WriteDump(file
, guid
))
6000 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS
);
6002 case DUMP_FILE_OPEN_ERROR
:
6003 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
6004 SetSentErrorMessage(true);
6007 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED
);
6008 SetSentErrorMessage(true);
6015 bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
6017 Unit
* unit
= getSelectedUnit();
6020 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
6021 SetSentErrorMessage(true);
6025 PSendSysMessage(LANG_MOVEGENS_LIST
,(unit
->GetTypeId()==TYPEID_PLAYER
? "Player" : "Creature" ),unit
->GetGUIDLow());
6027 MotionMaster
* mm
= unit
->GetMotionMaster();
6028 for(MotionMaster::const_iterator itr
= mm
->begin(); itr
!= mm
->end(); ++itr
)
6030 switch((*itr
)->GetMovementGeneratorType())
6032 case IDLE_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_IDLE
); break;
6033 case RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_RANDOM
); break;
6034 case WAYPOINT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_WAYPOINT
); break;
6035 case ANIMAL_RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_ANIMAL_RANDOM
); break;
6036 case CONFUSED_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_CONFUSED
); break;
6037 case TARGETED_MOTION_TYPE
:
6039 if(unit
->GetTypeId()==TYPEID_PLAYER
)
6041 TargetedMovementGenerator
<Player
> const* mgen
= static_cast<TargetedMovementGenerator
<Player
> const*>(*itr
);
6042 Unit
* target
= mgen
->GetTarget();
6044 PSendSysMessage(LANG_MOVEGENS_TARGETED_PLAYER
,target
->GetName(),target
->GetGUIDLow());
6046 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL
);
6050 TargetedMovementGenerator
<Creature
> const* mgen
= static_cast<TargetedMovementGenerator
<Creature
> const*>(*itr
);
6051 Unit
* target
= mgen
->GetTarget();
6053 PSendSysMessage(LANG_MOVEGENS_TARGETED_CREATURE
,target
->GetName(),target
->GetGUIDLow());
6055 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL
);
6059 case HOME_MOTION_TYPE
:
6060 if(unit
->GetTypeId()==TYPEID_UNIT
)
6063 (*itr
)->GetDestination(x
,y
,z
);
6064 PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE
,x
,y
,z
);
6067 SendSysMessage(LANG_MOVEGENS_HOME_PLAYER
);
6069 case FLIGHT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FLIGHT
); break;
6070 case POINT_MOTION_TYPE
:
6073 (*itr
)->GetDestination(x
,y
,z
);
6074 PSendSysMessage(LANG_MOVEGENS_POINT
,x
,y
,z
);
6077 case FLEEING_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FEAR
); break;
6078 case DISTRACT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_DISTRACT
); break;
6080 PSendSysMessage(LANG_MOVEGENS_UNKNOWN
,(*itr
)->GetMovementGeneratorType());
6087 bool ChatHandler::HandleServerPLimitCommand(const char *args
)
6091 char* param
= strtok((char*)args
, " ");
6095 int l
= strlen(param
);
6097 if( strncmp(param
,"player",l
) == 0 )
6098 sWorld
.SetPlayerLimit(-SEC_PLAYER
);
6099 else if(strncmp(param
,"moderator",l
) == 0 )
6100 sWorld
.SetPlayerLimit(-SEC_MODERATOR
);
6101 else if(strncmp(param
,"gamemaster",l
) == 0 )
6102 sWorld
.SetPlayerLimit(-SEC_GAMEMASTER
);
6103 else if(strncmp(param
,"administrator",l
) == 0 )
6104 sWorld
.SetPlayerLimit(-SEC_ADMINISTRATOR
);
6105 else if(strncmp(param
,"reset",l
) == 0 )
6106 sWorld
.SetPlayerLimit( sConfig
.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT
) );
6109 int val
= atoi(param
);
6110 if(val
< -SEC_ADMINISTRATOR
) val
= -SEC_ADMINISTRATOR
;
6112 sWorld
.SetPlayerLimit(val
);
6115 // kick all low security level players
6116 if(sWorld
.GetPlayerAmountLimit() > SEC_PLAYER
)
6117 sWorld
.KickAllLess(sWorld
.GetPlayerSecurityLimit());
6120 uint32 pLimit
= sWorld
.GetPlayerAmountLimit();
6121 AccountTypes allowedAccountType
= sWorld
.GetPlayerSecurityLimit();
6122 char const* secName
= "";
6123 switch(allowedAccountType
)
6125 case SEC_PLAYER
: secName
= "Player"; break;
6126 case SEC_MODERATOR
: secName
= "Moderator"; break;
6127 case SEC_GAMEMASTER
: secName
= "Gamemaster"; break;
6128 case SEC_ADMINISTRATOR
: secName
= "Administrator"; break;
6129 default: secName
= "<unknown>"; break;
6132 PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit
,secName
);
6137 bool ChatHandler::HandleCastCommand(const char* args
)
6142 Unit
* target
= getSelectedUnit();
6146 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
6147 SetSentErrorMessage(true);
6151 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6152 uint32 spell
= extractSpellIdFromLink((char*)args
);
6156 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
6160 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
6162 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
6163 SetSentErrorMessage(true);
6167 char* trig_str
= strtok(NULL
, " ");
6170 int l
= strlen(trig_str
);
6171 if(strncmp(trig_str
,"triggered",l
) != 0 )
6175 bool triggered
= (trig_str
!= NULL
);
6177 m_session
->GetPlayer()->CastSpell(target
,spell
,triggered
);
6182 bool ChatHandler::HandleCastBackCommand(const char* args
)
6184 Creature
* caster
= getSelectedCreature();
6188 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
6189 SetSentErrorMessage(true);
6193 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
6194 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6195 uint32 spell
= extractSpellIdFromLink((char*)args
);
6196 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
6199 char* trig_str
= strtok(NULL
, " ");
6202 int l
= strlen(trig_str
);
6203 if(strncmp(trig_str
,"triggered",l
) != 0 )
6207 bool triggered
= (trig_str
!= NULL
);
6209 // update orientation at server
6210 caster
->SetOrientation(caster
->GetAngle(m_session
->GetPlayer()));
6214 caster
->BuildHeartBeatMsg(&data
);
6215 caster
->SendMessageToSet(&data
,true);
6217 caster
->CastSpell(m_session
->GetPlayer(),spell
,triggered
);
6222 bool ChatHandler::HandleCastDistCommand(const char* args
)
6227 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6228 uint32 spell
= extractSpellIdFromLink((char*)args
);
6232 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
6236 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
6238 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
6239 SetSentErrorMessage(true);
6243 char *distStr
= strtok(NULL
, " ");
6248 sscanf(distStr
, "%f", &dist
);
6250 char* trig_str
= strtok(NULL
, " ");
6253 int l
= strlen(trig_str
);
6254 if(strncmp(trig_str
,"triggered",l
) != 0 )
6258 bool triggered
= (trig_str
!= NULL
);
6261 m_session
->GetPlayer()->GetClosePoint(x
,y
,z
,dist
);
6263 m_session
->GetPlayer()->CastSpell(x
,y
,z
,spell
,triggered
);
6267 bool ChatHandler::HandleCastTargetCommand(const char* args
)
6269 Creature
* caster
= getSelectedCreature();
6273 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
6274 SetSentErrorMessage(true);
6278 if(!caster
->getVictim())
6280 SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM
);
6281 SetSentErrorMessage(true);
6285 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6286 uint32 spell
= extractSpellIdFromLink((char*)args
);
6287 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
6290 char* trig_str
= strtok(NULL
, " ");
6293 int l
= strlen(trig_str
);
6294 if(strncmp(trig_str
,"triggered",l
) != 0 )
6298 bool triggered
= (trig_str
!= NULL
);
6300 // update orientation at server
6301 caster
->SetOrientation(caster
->GetAngle(m_session
->GetPlayer()));
6305 caster
->BuildHeartBeatMsg(&data
);
6306 caster
->SendMessageToSet(&data
,true);
6308 caster
->CastSpell(caster
->getVictim(),spell
,triggered
);
6314 ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
6315 Without this function 3rd party scripting library will get linking errors (unresolved external)
6316 when attempting to use the PointMovementGenerator
6318 bool ChatHandler::HandleComeToMeCommand(const char *args
)
6320 Creature
* caster
= getSelectedCreature();
6324 SendSysMessage(LANG_SELECT_CREATURE
);
6325 SetSentErrorMessage(true);
6329 char* newFlagStr
= strtok((char*)args
, " ");
6334 uint32 newFlags
= atoi(newFlagStr
);
6336 caster
->SetUnitMovementFlags(newFlags
);
6338 Player
* pl
= m_session
->GetPlayer();
6340 caster
->GetMotionMaster()->MovePoint(0, pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ());
6344 bool ChatHandler::HandleCastSelfCommand(const char* args
)
6349 Unit
* target
= getSelectedUnit();
6353 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
6354 SetSentErrorMessage(true);
6358 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6359 uint32 spell
= extractSpellIdFromLink((char*)args
);
6363 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
6367 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
6369 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
6370 SetSentErrorMessage(true);
6374 target
->CastSpell(target
,spell
,false);
6379 std::string
GetTimeString(uint32 time
)
6381 uint16 days
= time
/ DAY
, hours
= (time
% DAY
) / HOUR
, minute
= (time
% HOUR
) / MINUTE
;
6382 std::ostringstream ss
;
6383 if(days
) ss
<< days
<< "d ";
6384 if(hours
) ss
<< hours
<< "h ";
6385 ss
<< minute
<< "m";
6389 bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
6391 Player
* player
= getSelectedPlayer();
6392 if (!player
) player
= m_session
->GetPlayer();
6394 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; ++i
)
6396 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(i
);
6397 for(Player::BoundInstancesMap::const_iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
6399 InstanceSave
*save
= itr
->second
.save
;
6400 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
6401 PSendSysMessage("map: %d inst: %d perm: %s diff: %s canReset: %s TTR: %s", itr
->first
, save
->GetInstanceId(), itr
->second
.perm
? "yes" : "no", save
->GetDifficulty() == DIFFICULTY_NORMAL
? "normal" : "heroic", save
->CanReset() ? "yes" : "no", timeleft
.c_str());
6405 PSendSysMessage("player binds: %d", counter
);
6407 Group
*group
= player
->GetGroup();
6410 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; ++i
)
6412 Group::BoundInstancesMap
&binds
= group
->GetBoundInstances(i
);
6413 for(Group::BoundInstancesMap::const_iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
6415 InstanceSave
*save
= itr
->second
.save
;
6416 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
6417 PSendSysMessage("map: %d inst: %d perm: %s diff: %s canReset: %s TTR: %s", itr
->first
, save
->GetInstanceId(), itr
->second
.perm
? "yes" : "no", save
->GetDifficulty() == DIFFICULTY_NORMAL
? "normal" : "heroic", save
->CanReset() ? "yes" : "no", timeleft
.c_str());
6422 PSendSysMessage("group binds: %d", counter
);
6427 bool ChatHandler::HandleInstanceUnbindCommand(const char* args
)
6432 std::string cmd
= args
;
6435 Player
* player
= getSelectedPlayer();
6436 if (!player
) player
= m_session
->GetPlayer();
6438 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; ++i
)
6440 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(i
);
6441 for(Player::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end();)
6443 if(itr
->first
!= player
->GetMapId())
6445 InstanceSave
*save
= itr
->second
.save
;
6446 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
6447 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() == DIFFICULTY_NORMAL
? "normal" : "heroic", save
->CanReset() ? "yes" : "no", timeleft
.c_str());
6448 player
->UnbindInstance(itr
, i
);
6455 PSendSysMessage("instances unbound: %d", counter
);
6460 bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
6462 PSendSysMessage("instances loaded: %d", MapManager::Instance().GetNumInstances());
6463 PSendSysMessage("players in instances: %d", MapManager::Instance().GetNumPlayersInInstances());
6464 PSendSysMessage("instance saves: %d", sInstanceSaveManager
.GetNumInstanceSaves());
6465 PSendSysMessage("players bound: %d", sInstanceSaveManager
.GetNumBoundPlayersTotal());
6466 PSendSysMessage("groups bound: %d", sInstanceSaveManager
.GetNumBoundGroupsTotal());
6470 bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
6472 Player
* pl
= m_session
->GetPlayer();
6474 Map
* map
= pl
->GetMap();
6475 if (!map
->IsDungeon())
6477 PSendSysMessage("Map is not a dungeon.");
6478 SetSentErrorMessage(true);
6482 if (!((InstanceMap
*)map
)->GetInstanceData())
6484 PSendSysMessage("Map has no instance data.");
6485 SetSentErrorMessage(true);
6489 ((InstanceMap
*)map
)->GetInstanceData()->SaveToDB();
6493 /// Display the list of GMs
6494 bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
6496 ///- Get the accounts with GM Level >0
6497 QueryResult
*result
= loginDatabase
.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
6500 SendSysMessage(LANG_GMLIST
);
6501 SendSysMessage("========================");
6502 SendSysMessage(LANG_GMLIST_HEADER
);
6503 SendSysMessage("========================");
6505 ///- Circle through them. Display username and GM level
6508 Field
*fields
= result
->Fetch();
6509 PSendSysMessage("|%15s|%6s|", fields
[0].GetString(),fields
[1].GetString());
6510 }while( result
->NextRow() );
6512 PSendSysMessage("========================");
6516 PSendSysMessage(LANG_GMLIST_EMPTY
);
6520 /// Define the 'Message of the day' for the realm
6521 bool ChatHandler::HandleServerSetMotdCommand(const char* args
)
6523 sWorld
.SetMotd(args
);
6524 PSendSysMessage(LANG_MOTD_NEW
, args
);
6528 /// Set/Unset the expansion level for an account
6529 bool ChatHandler::HandleAccountSetAddonCommand(const char* args
)
6531 ///- Get the command line arguments
6532 char *szAcc
= strtok((char*)args
," ");
6533 char *szExp
= strtok(NULL
," ");
6538 std::string account_name
;
6543 Player
* player
= getSelectedPlayer();
6547 account_id
= player
->GetSession()->GetAccountId();
6548 accmgr
.GetName(account_id
,account_name
);
6553 ///- Convert Account name to Upper Format
6554 account_name
= szAcc
;
6555 if(!AccountMgr::normilizeString(account_name
))
6557 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
6558 SetSentErrorMessage(true);
6562 account_id
= accmgr
.GetId(account_name
);
6565 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
6566 SetSentErrorMessage(true);
6572 // Let set addon state only for lesser (strong) security level
6573 // or to self account
6574 if (m_session
&& m_session
->GetAccountId () != account_id
&&
6575 HasLowerSecurityAccount (NULL
,account_id
,true))
6578 int lev
=atoi(szExp
); //get int anyway (0 if error)
6583 loginDatabase
.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev
,account_id
);
6584 PSendSysMessage(LANG_ACCOUNT_SETADDON
,account_name
.c_str(),account_id
,lev
);
6588 //Send items by mail
6589 bool ChatHandler::HandleSendItemsCommand(const char* args
)
6594 // format: name "subject text" "mail text" item1[:count1] item2[:count2] ... item12[:count12]
6596 std::string name
= extractPlayerNameFromLink((char*)args
);
6599 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6600 SetSentErrorMessage(true);
6604 char* tail1
= strtok(NULL
, "");
6610 msgSubject
= strtok(tail1
+1, "\"");
6613 char* space
= strtok(tail1
, "\"");
6616 msgSubject
= strtok(NULL
, "\"");
6622 char* tail2
= strtok(NULL
, "");
6628 msgText
= strtok(tail2
+1, "\"");
6631 char* space
= strtok(tail2
, "\"");
6634 msgText
= strtok(NULL
, "\"");
6640 // msgSubject, msgText isn't NUL after prev. check
6641 std::string subject
= msgSubject
;
6642 std::string text
= msgText
;
6645 typedef std::pair
<uint32
,uint32
> ItemPair
;
6646 typedef std::list
< ItemPair
> ItemPairs
;
6649 // get all tail string
6650 char* tail
= strtok(NULL
, "");
6652 // get from tail next item str
6653 while(char* itemStr
= strtok(tail
, " "))
6656 tail
= strtok(NULL
, "");
6659 char* itemIdStr
= strtok(itemStr
, ":");
6660 char* itemCountStr
= strtok(NULL
, " ");
6662 uint32 item_id
= atoi(itemIdStr
);
6666 ItemPrototype
const* item_proto
= objmgr
.GetItemPrototype(item_id
);
6669 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
6670 SetSentErrorMessage(true);
6674 uint32 item_count
= itemCountStr
? atoi(itemCountStr
) : 1;
6675 if(item_count
< 1 || item_proto
->MaxCount
> 0 && item_count
> uint32(item_proto
->MaxCount
))
6677 PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT
, item_count
,item_id
);
6678 SetSentErrorMessage(true);
6682 while(item_count
> item_proto
->GetMaxStackSize())
6684 items
.push_back(ItemPair(item_id
,item_proto
->GetMaxStackSize()));
6685 item_count
-= item_proto
->GetMaxStackSize();
6688 items
.push_back(ItemPair(item_id
,item_count
));
6690 if(items
.size() > MAX_MAIL_ITEMS
)
6692 PSendSysMessage(LANG_COMMAND_MAIL_ITEMS_LIMIT
, MAX_MAIL_ITEMS
);
6693 SetSentErrorMessage(true);
6698 uint64 receiver_guid
= objmgr
.GetPlayerGUIDByName(name
);
6701 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6702 SetSentErrorMessage(true);
6706 // from console show not existed sender
6707 uint32 sender_guidlo
= m_session
? m_session
->GetPlayer()->GetGUIDLow() : 0;
6709 uint32 messagetype
= MAIL_NORMAL
;
6710 uint32 stationery
= MAIL_STATIONERY_GM
;
6711 uint32 itemTextId
= !text
.empty() ? objmgr
.CreateItemText( text
) : 0;
6713 Player
*receiver
= objmgr
.GetPlayer(receiver_guid
);
6716 MailItemsInfo mi
; // item list preparing
6718 for(ItemPairs::const_iterator itr
= items
.begin(); itr
!= items
.end(); ++itr
)
6720 if(Item
* item
= Item::CreateItem(itr
->first
,itr
->second
,m_session
? m_session
->GetPlayer() : 0))
6722 item
->SaveToDB(); // save for prevent lost at next mail load, if send fail then item will deleted
6723 mi
.AddItem(item
->GetGUIDLow(), item
->GetEntry(), item
);
6727 WorldSession::SendMailTo(receiver
,messagetype
, stationery
, sender_guidlo
, GUID_LOPART(receiver_guid
), subject
, itemTextId
, &mi
, 0, 0, MAIL_CHECK_MASK_NONE
);
6729 std::string nameLink
= playerLink(name
);
6730 PSendSysMessage(LANG_MAIL_SENT
, nameLink
.c_str());
6734 ///Send money by mail
6735 bool ChatHandler::HandleSendMoneyCommand(const char* args
)
6740 /// format: name "subject text" "mail text" money
6742 std::string name
= extractPlayerNameFromLink((char*)args
);
6745 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6746 SetSentErrorMessage(true);
6750 char* tail1
= strtok(NULL
, "");
6756 msgSubject
= strtok(tail1
+1, "\"");
6759 char* space
= strtok(tail1
, "\"");
6762 msgSubject
= strtok(NULL
, "\"");
6768 char* tail2
= strtok(NULL
, "");
6774 msgText
= strtok(tail2
+1, "\"");
6777 char* space
= strtok(tail2
, "\"");
6780 msgText
= strtok(NULL
, "\"");
6786 char* money_str
= strtok(NULL
, "");
6787 int32 money
= money_str
? atoi(money_str
) : 0;
6791 // msgSubject, msgText isn't NUL after prev. check
6792 std::string subject
= msgSubject
;
6793 std::string text
= msgText
;
6795 uint64 receiver_guid
= objmgr
.GetPlayerGUIDByName(name
);
6798 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6799 SetSentErrorMessage(true);
6803 // from console show not existed sender
6804 uint32 sender_guidlo
= m_session
? m_session
->GetPlayer()->GetGUIDLow() : 0;
6806 uint32 messagetype
= MAIL_NORMAL
;
6807 uint32 stationery
= MAIL_STATIONERY_GM
;
6808 uint32 itemTextId
= !text
.empty() ? objmgr
.CreateItemText( text
) : 0;
6810 Player
*receiver
= objmgr
.GetPlayer(receiver_guid
);
6812 WorldSession::SendMailTo(receiver
,messagetype
, stationery
, sender_guidlo
, GUID_LOPART(receiver_guid
), subject
, itemTextId
, NULL
, money
, 0, MAIL_CHECK_MASK_NONE
);
6814 std::string nameLink
= playerLink(name
);
6815 PSendSysMessage(LANG_MAIL_SENT
, nameLink
.c_str());
6819 /// Send a message to a player in game
6820 bool ChatHandler::HandleSendMessageCommand(const char* args
)
6822 ///- Get the command line arguments
6823 std::string name
= extractPlayerNameFromLink((char*)args
);
6826 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6827 SetSentErrorMessage(true);
6831 char* msg_str
= strtok(NULL
, "");
6835 ///- Find the player and check that he is not logging out.
6836 Player
*rPlayer
= objmgr
.GetPlayer(name
.c_str());
6839 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6840 SetSentErrorMessage(true);
6844 if(rPlayer
->GetSession()->isLogingOut())
6846 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6847 SetSentErrorMessage(true);
6851 ///- Send the message
6852 //Use SendAreaTriggerMessage for fastest delivery.
6853 rPlayer
->GetSession()->SendAreaTriggerMessage("%s", msg_str
);
6854 rPlayer
->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
6856 //Confirmation message
6857 std::string nameLink
= playerLink(name
);
6858 PSendSysMessage(LANG_SENDMESSAGE
,nameLink
.c_str(),msg_str
);
6862 bool ChatHandler::HandleFlushArenaPointsCommand(const char * /*args*/)
6864 sBattleGroundMgr
.DistributeArenaPoints();
6868 bool ChatHandler::HandleModifyGenderCommand(const char *args
)
6873 Player
*player
= getSelectedPlayer();
6877 PSendSysMessage(LANG_PLAYER_NOT_FOUND
);
6878 SetSentErrorMessage(true);
6882 PlayerInfo
const* info
= objmgr
.GetPlayerInfo(player
->getRace(), player
->getClass());
6886 char const* gender_str
= (char*)args
;
6887 int gender_len
= strlen(gender_str
);
6891 if(!strncmp(gender_str
, "male", gender_len
)) // MALE
6893 if(player
->getGender() == GENDER_MALE
)
6896 gender
= GENDER_MALE
;
6898 else if (!strncmp(gender_str
, "female", gender_len
)) // FEMALE
6900 if(player
->getGender() == GENDER_FEMALE
)
6903 gender
= GENDER_FEMALE
;
6907 SendSysMessage(LANG_MUST_MALE_OR_FEMALE
);
6908 SetSentErrorMessage(true);
6913 player
->SetByteValue(UNIT_FIELD_BYTES_0
, 2, gender
);
6914 player
->SetByteValue(PLAYER_BYTES_3
, 0, gender
);
6916 // Change display ID
6917 player
->SetDisplayId(gender
? info
->displayId_f
: info
->displayId_m
);
6918 player
->SetNativeDisplayId(gender
? info
->displayId_f
: info
->displayId_m
);
6920 char const* gender_full
= gender
? "female" : "male";
6922 PSendSysMessage(LANG_YOU_CHANGE_GENDER
, GetNameLink(player
).c_str(), gender_full
);
6924 if (needReportToTarget(player
))
6925 ChatHandler(player
).PSendSysMessage(LANG_YOUR_GENDER_CHANGED
, gender_full
, GetNameLink().c_str());