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 target
->RemoveSpellCooldown(spell_id
,true);
1068 PSendSysMessage(LANG_REMOVE_COOLDOWN
, spell_id
, target
==m_session
->GetPlayer() ? GetMangosString(LANG_YOU
) : tNameLink
.c_str());
1073 bool ChatHandler::HandleLearnAllCommand(const char* /*args*/)
1075 static const char *allSpellList
[] =
1458 //"9036", problems with ghost state
1467 //"6718", phasing stealth, annoying for learn all case.
1680 while(strcmp(allSpellList
[loop
], "0"))
1682 uint32 spell
= atol((char*)allSpellList
[loop
++]);
1684 if (m_session
->GetPlayer()->HasSpell(spell
))
1687 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1688 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1690 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1694 m_session
->GetPlayer()->learnSpell(spell
,false);
1697 SendSysMessage(LANG_COMMAND_LEARN_MANY_SPELLS
);
1702 bool ChatHandler::HandleLearnAllGMCommand(const char* /*args*/)
1704 static const char *gmSpellList
[] =
1706 "24347", // Become A Fish, No Breath Bar
1707 "35132", // Visual Boom
1708 "38488", // Attack 4000-8000 AOE
1709 "38795", // Attack 2000 AOE + Slow Down 90%
1710 "15712", // Attack 200
1711 "1852", // GM Spell Silence
1714 "29878", // Kill My Self
1715 "26644", // More Kill
1717 "28550", //Invisible 24
1718 "23452", //Invisible + Target
1722 uint16 gmSpellIter
= 0;
1723 while( strcmp(gmSpellList
[gmSpellIter
], "0") )
1725 uint32 spell
= atol((char*)gmSpellList
[gmSpellIter
++]);
1727 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1728 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1730 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1734 m_session
->GetPlayer()->learnSpell(spell
,false);
1737 SendSysMessage(LANG_LEARNING_GM_SKILLS
);
1741 bool ChatHandler::HandleLearnAllMyClassCommand(const char* /*args*/)
1743 HandleLearnAllMySpellsCommand("");
1744 HandleLearnAllMyTalentsCommand("");
1748 bool ChatHandler::HandleLearnAllMySpellsCommand(const char* /*args*/)
1750 ChrClassesEntry
const* clsEntry
= sChrClassesStore
.LookupEntry(m_session
->GetPlayer()->getClass());
1753 uint32 family
= clsEntry
->spellfamily
;
1755 for (uint32 i
= 0; i
< sSpellStore
.GetNumRows(); ++i
)
1757 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(i
);
1761 // skip server-side/triggered spells
1762 if(spellInfo
->spellLevel
==0)
1765 // skip wrong class/race skills
1766 if(!m_session
->GetPlayer()->IsSpellFitByClassAndRace(spellInfo
->Id
))
1769 // skip other spell families
1770 if( spellInfo
->SpellFamilyName
!= family
)
1773 // skip spells with first rank learned as talent (and all talents then also)
1774 uint32 first_rank
= spellmgr
.GetFirstSpellInChain(spellInfo
->Id
);
1775 if(GetTalentSpellCost(first_rank
) > 0 )
1778 // skip broken spells
1779 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1782 m_session
->GetPlayer()->learnSpell(i
,false);
1785 SendSysMessage(LANG_COMMAND_LEARN_CLASS_SPELLS
);
1789 bool ChatHandler::HandleLearnAllMyTalentsCommand(const char* /*args*/)
1791 Player
* player
= m_session
->GetPlayer();
1792 uint32 classMask
= player
->getClassMask();
1794 for (uint32 i
= 0; i
< sTalentStore
.GetNumRows(); ++i
)
1796 TalentEntry
const *talentInfo
= sTalentStore
.LookupEntry(i
);
1800 TalentTabEntry
const *talentTabInfo
= sTalentTabStore
.LookupEntry( talentInfo
->TalentTab
);
1804 if( (classMask
& talentTabInfo
->ClassMask
) == 0 )
1807 // search highest talent rank
1810 for(int rank
= MAX_TALENT_RANK
-1; rank
>= 0; --rank
)
1812 if(talentInfo
->RankID
[rank
]!=0)
1814 spellid
= talentInfo
->RankID
[rank
];
1819 if(!spellid
) // ??? none spells in talent
1822 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spellid
);
1823 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1826 // learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
1827 player
->learnSpellHighRank(spellid
);
1830 SendSysMessage(LANG_COMMAND_LEARN_CLASS_TALENTS
);
1834 bool ChatHandler::HandleLearnAllMyPetTalentsCommand(const char* /*args*/)
1836 Player
* player
= m_session
->GetPlayer();
1838 Pet
* pet
= player
->GetPet();
1841 SendSysMessage(LANG_NO_PET_FOUND
);
1842 SetSentErrorMessage(true);
1846 CreatureInfo
const *ci
= pet
->GetCreatureInfo();
1849 SendSysMessage(LANG_WRONG_PET_TYPE
);
1850 SetSentErrorMessage(true);
1854 CreatureFamilyEntry
const *pet_family
= sCreatureFamilyStore
.LookupEntry(ci
->family
);
1857 SendSysMessage(LANG_WRONG_PET_TYPE
);
1858 SetSentErrorMessage(true);
1862 if(pet_family
->petTalentType
< 0) // not hunter pet
1864 SendSysMessage(LANG_WRONG_PET_TYPE
);
1865 SetSentErrorMessage(true);
1869 for (uint32 i
= 0; i
< sTalentStore
.GetNumRows(); ++i
)
1871 TalentEntry
const *talentInfo
= sTalentStore
.LookupEntry(i
);
1875 TalentTabEntry
const *talentTabInfo
= sTalentTabStore
.LookupEntry( talentInfo
->TalentTab
);
1879 // prevent learn talent for different family (cheating)
1880 if(((1 << pet_family
->petTalentType
) & talentTabInfo
->petTalentMask
)==0)
1883 // search highest talent rank
1886 for(int rank
= MAX_TALENT_RANK
-1; rank
>= 0; --rank
)
1888 if(talentInfo
->RankID
[rank
]!=0)
1890 spellid
= talentInfo
->RankID
[rank
];
1895 if(!spellid
) // ??? none spells in talent
1898 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spellid
);
1899 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1902 // learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
1903 pet
->learnSpellHighRank(spellid
);
1906 SendSysMessage(LANG_COMMAND_LEARN_PET_TALENTS
);
1910 bool ChatHandler::HandleLearnAllLangCommand(const char* /*args*/)
1912 // skipping UNIVERSAL language (0)
1913 for(int i
= 1; i
< LANGUAGES_COUNT
; ++i
)
1914 m_session
->GetPlayer()->learnSpell(lang_description
[i
].spell_id
,false);
1916 SendSysMessage(LANG_COMMAND_LEARN_ALL_LANG
);
1920 bool ChatHandler::HandleLearnAllDefaultCommand(const char* args
)
1922 Player
*player
= NULL
;
1925 std::string name
= extractPlayerNameFromLink((char*)args
);
1928 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1929 SetSentErrorMessage(true);
1933 player
= objmgr
.GetPlayer(name
.c_str());
1936 player
= getSelectedPlayer();
1940 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1941 SetSentErrorMessage(true);
1945 player
->learnDefaultSpells();
1946 player
->learnQuestRewardedSpells();
1948 PSendSysMessage(LANG_COMMAND_LEARN_ALL_DEFAULT_AND_QUEST
,GetNameLink(player
).c_str());
1952 bool ChatHandler::HandleLearnCommand(const char* args
)
1954 Player
* targetPlayer
= getSelectedPlayer();
1958 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1959 SetSentErrorMessage(true);
1963 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1964 uint32 spell
= extractSpellIdFromLink((char*)args
);
1965 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
1968 char const* allStr
= strtok(NULL
," ");
1969 bool allRanks
= allStr
? (strncmp(allStr
, "all", strlen(allStr
)) == 0) : false;
1971 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1972 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1974 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1975 SetSentErrorMessage(true);
1979 if (!allRanks
&& targetPlayer
->HasSpell(spell
))
1981 if(targetPlayer
== m_session
->GetPlayer())
1982 SendSysMessage(LANG_YOU_KNOWN_SPELL
);
1984 PSendSysMessage(LANG_TARGET_KNOWN_SPELL
,GetNameLink(targetPlayer
).c_str());
1985 SetSentErrorMessage(true);
1990 targetPlayer
->learnSpellHighRank(spell
);
1992 targetPlayer
->learnSpell(spell
,false);
1997 bool ChatHandler::HandleAddItemCommand(const char* args
)
2004 if(args
[0]=='[') // [name] manual form
2006 char* citemName
= strtok((char*)args
, "]");
2008 if(citemName
&& citemName
[0])
2010 std::string itemName
= citemName
+1;
2011 WorldDatabase
.escape_string(itemName
);
2012 QueryResult
*result
= WorldDatabase
.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName
.c_str());
2015 PSendSysMessage(LANG_COMMAND_COULDNOTFIND
, citemName
+1);
2016 SetSentErrorMessage(true);
2019 itemId
= result
->Fetch()->GetUInt16();
2025 else // item_id or [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r
2027 char* cId
= extractKeyFromLink((char*)args
,"Hitem");
2033 char* ccount
= strtok(NULL
, " ");
2038 count
= strtol(ccount
, NULL
, 10);
2043 Player
* pl
= m_session
->GetPlayer();
2044 Player
* plTarget
= getSelectedPlayer();
2048 sLog
.outDetail(GetMangosString(LANG_ADDITEM
), itemId
, count
);
2050 ItemPrototype
const *pProto
= objmgr
.GetItemPrototype(itemId
);
2053 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, itemId
);
2054 SetSentErrorMessage(true);
2061 plTarget
->DestroyItemCount(itemId
, -count
, true, false);
2062 PSendSysMessage(LANG_REMOVEITEM
, itemId
, -count
, GetNameLink(plTarget
).c_str());
2067 uint32 noSpaceForCount
= 0;
2069 // check space and find places
2070 ItemPosCountVec dest
;
2071 uint8 msg
= plTarget
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, itemId
, count
, &noSpaceForCount
);
2072 if( msg
!= EQUIP_ERR_OK
) // convert to possible store amount
2073 count
-= noSpaceForCount
;
2075 if( count
== 0 || dest
.empty()) // can't add any
2077 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, itemId
, noSpaceForCount
);
2078 SetSentErrorMessage(true);
2082 Item
* item
= plTarget
->StoreNewItem( dest
, itemId
, true, Item::GenerateItemRandomPropertyId(itemId
));
2084 // remove binding (let GM give it to another player later)
2086 for(ItemPosCountVec::const_iterator itr
= dest
.begin(); itr
!= dest
.end(); ++itr
)
2087 if(Item
* item1
= pl
->GetItemByPos(itr
->pos
))
2088 item1
->SetBinding( false );
2090 if(count
> 0 && item
)
2092 pl
->SendNewItem(item
,count
,false,true);
2094 plTarget
->SendNewItem(item
,count
,true,false);
2097 if(noSpaceForCount
> 0)
2098 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, itemId
, noSpaceForCount
);
2103 bool ChatHandler::HandleAddItemSetCommand(const char* args
)
2108 char* cId
= extractKeyFromLink((char*)args
,"Hitemset"); // number or [name] Shift-click form |color|Hitemset:itemset_id|h[name]|h|r
2112 uint32 itemsetId
= atol(cId
);
2114 // prevent generation all items with itemset field value '0'
2117 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND
,itemsetId
);
2118 SetSentErrorMessage(true);
2122 Player
* pl
= m_session
->GetPlayer();
2123 Player
* plTarget
= getSelectedPlayer();
2127 sLog
.outDetail(GetMangosString(LANG_ADDITEMSET
), itemsetId
);
2130 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
2132 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
2136 if (pProto
->ItemSet
== itemsetId
)
2139 ItemPosCountVec dest
;
2140 uint8 msg
= plTarget
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, pProto
->ItemId
, 1 );
2141 if (msg
== EQUIP_ERR_OK
)
2143 Item
* item
= plTarget
->StoreNewItem( dest
, pProto
->ItemId
, true);
2145 // remove binding (let GM give it to another player later)
2147 item
->SetBinding( false );
2149 pl
->SendNewItem(item
,1,false,true);
2151 plTarget
->SendNewItem(item
,1,true,false);
2155 pl
->SendEquipError( msg
, NULL
, NULL
);
2156 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, pProto
->ItemId
, 1);
2163 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND
,itemsetId
);
2165 SetSentErrorMessage(true);
2172 bool ChatHandler::HandleListItemCommand(const char* args
)
2177 char* cId
= extractKeyFromLink((char*)args
,"Hitem");
2181 uint32 item_id
= atol(cId
);
2184 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
2185 SetSentErrorMessage(true);
2189 ItemPrototype
const* itemProto
= objmgr
.GetItemPrototype(item_id
);
2192 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
2193 SetSentErrorMessage(true);
2197 char* c_count
= strtok(NULL
, " ");
2198 int count
= c_count
? atol(c_count
) : 10;
2203 QueryResult
*result
;
2206 uint32 inv_count
= 0;
2207 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM character_inventory WHERE item_template='%u'",item_id
);
2210 inv_count
= (*result
)[0].GetUInt32();
2214 result
=CharacterDatabase
.PQuery(
2216 "SELECT ci.item, cibag.slot AS bag, ci.slot, ci.guid, characters.account,characters.name "
2217 "FROM character_inventory AS ci LEFT JOIN character_inventory AS cibag ON (cibag.item=ci.bag),characters "
2218 "WHERE ci.item_template='%u' AND ci.guid = characters.guid LIMIT %u ",
2219 item_id
,uint32(count
));
2225 Field
*fields
= result
->Fetch();
2226 uint32 item_guid
= fields
[0].GetUInt32();
2227 uint32 item_bag
= fields
[1].GetUInt32();
2228 uint32 item_slot
= fields
[2].GetUInt32();
2229 uint32 owner_guid
= fields
[3].GetUInt32();
2230 uint32 owner_acc
= fields
[4].GetUInt32();
2231 std::string owner_name
= fields
[5].GetCppString();
2233 char const* item_pos
= 0;
2234 if(Player::IsEquipmentPos(item_bag
,item_slot
))
2235 item_pos
= "[equipped]";
2236 else if(Player::IsInventoryPos(item_bag
,item_slot
))
2237 item_pos
= "[in inventory]";
2238 else if(Player::IsBankPos(item_bag
,item_slot
))
2239 item_pos
= "[in bank]";
2243 PSendSysMessage(LANG_ITEMLIST_SLOT
,
2244 item_guid
,owner_name
.c_str(),owner_guid
,owner_acc
,item_pos
);
2245 } while (result
->NextRow());
2247 int64 res_count
= result
->GetRowCount();
2251 if(count
> res_count
)
2258 uint32 mail_count
= 0;
2259 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM mail_items WHERE item_template='%u'", item_id
);
2262 mail_count
= (*result
)[0].GetUInt32();
2268 result
=CharacterDatabase
.PQuery(
2270 "SELECT mail_items.item_guid, mail.sender, mail.receiver, char_s.account, char_s.name, char_r.account, char_r.name "
2271 "FROM mail,mail_items,characters as char_s,characters as char_r "
2272 "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",
2273 item_id
,uint32(count
));
2282 Field
*fields
= result
->Fetch();
2283 uint32 item_guid
= fields
[0].GetUInt32();
2284 uint32 item_s
= fields
[1].GetUInt32();
2285 uint32 item_r
= fields
[2].GetUInt32();
2286 uint32 item_s_acc
= fields
[3].GetUInt32();
2287 std::string item_s_name
= fields
[4].GetCppString();
2288 uint32 item_r_acc
= fields
[5].GetUInt32();
2289 std::string item_r_name
= fields
[6].GetCppString();
2291 char const* item_pos
= "[in mail]";
2293 PSendSysMessage(LANG_ITEMLIST_MAIL
,
2294 item_guid
,item_s_name
.c_str(),item_s
,item_s_acc
,item_r_name
.c_str(),item_r
,item_r_acc
,item_pos
);
2295 } while (result
->NextRow());
2297 int64 res_count
= result
->GetRowCount();
2301 if(count
> res_count
)
2308 uint32 auc_count
= 0;
2309 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM auctionhouse WHERE item_template='%u'",item_id
);
2312 auc_count
= (*result
)[0].GetUInt32();
2318 result
=CharacterDatabase
.PQuery(
2320 "SELECT auctionhouse.itemguid, auctionhouse.itemowner, characters.account, characters.name "
2321 "FROM auctionhouse,characters WHERE auctionhouse.item_template='%u' AND characters.guid = auctionhouse.itemowner LIMIT %u",
2322 item_id
,uint32(count
));
2331 Field
*fields
= result
->Fetch();
2332 uint32 item_guid
= fields
[0].GetUInt32();
2333 uint32 owner
= fields
[1].GetUInt32();
2334 uint32 owner_acc
= fields
[2].GetUInt32();
2335 std::string owner_name
= fields
[3].GetCppString();
2337 char const* item_pos
= "[in auction]";
2339 PSendSysMessage(LANG_ITEMLIST_AUCTION
, item_guid
, owner_name
.c_str(), owner
, owner_acc
,item_pos
);
2340 } while (result
->NextRow());
2346 uint32 guild_count
= 0;
2347 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_entry) FROM guild_bank_item WHERE item_entry='%u'",item_id
);
2350 guild_count
= (*result
)[0].GetUInt32();
2354 result
=CharacterDatabase
.PQuery(
2356 "SELECT gi.item_guid, gi.guildid, guild.name "
2357 "FROM guild_bank_item AS gi, guild WHERE gi.item_entry='%u' AND gi.guildid = guild.guildid LIMIT %u ",
2358 item_id
,uint32(count
));
2364 Field
*fields
= result
->Fetch();
2365 uint32 item_guid
= fields
[0].GetUInt32();
2366 uint32 guild_guid
= fields
[1].GetUInt32();
2367 std::string guild_name
= fields
[2].GetCppString();
2369 char const* item_pos
= "[in guild bank]";
2371 PSendSysMessage(LANG_ITEMLIST_GUILD
,item_guid
,guild_name
.c_str(),guild_guid
,item_pos
);
2372 } while (result
->NextRow());
2374 int64 res_count
= result
->GetRowCount();
2378 if(count
> res_count
)
2384 if(inv_count
+mail_count
+auc_count
+guild_count
== 0)
2386 SendSysMessage(LANG_COMMAND_NOITEMFOUND
);
2387 SetSentErrorMessage(true);
2391 PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE
,item_id
,inv_count
+mail_count
+auc_count
+guild_count
,inv_count
,mail_count
,auc_count
,guild_count
);
2396 bool ChatHandler::HandleListObjectCommand(const char* args
)
2401 // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2402 char* cId
= extractKeyFromLink((char*)args
,"Hgameobject_entry");
2406 uint32 go_id
= atol(cId
);
2409 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID
, go_id
);
2410 SetSentErrorMessage(true);
2414 GameObjectInfo
const * gInfo
= objmgr
.GetGameObjectInfo(go_id
);
2417 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID
, go_id
);
2418 SetSentErrorMessage(true);
2422 char* c_count
= strtok(NULL
, " ");
2423 int count
= c_count
? atol(c_count
) : 10;
2428 QueryResult
*result
;
2430 uint32 obj_count
= 0;
2431 result
=WorldDatabase
.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'",go_id
);
2434 obj_count
= (*result
)[0].GetUInt32();
2440 Player
* pl
= m_session
->GetPlayer();
2441 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",
2442 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(),go_id
,uint32(count
));
2445 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map FROM gameobject WHERE id = '%u' LIMIT %u",
2446 go_id
,uint32(count
));
2452 Field
*fields
= result
->Fetch();
2453 uint32 guid
= fields
[0].GetUInt32();
2454 float x
= fields
[1].GetFloat();
2455 float y
= fields
[2].GetFloat();
2456 float z
= fields
[3].GetFloat();
2457 int mapid
= fields
[4].GetUInt16();
2460 PSendSysMessage(LANG_GO_LIST_CHAT
, guid
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2462 PSendSysMessage(LANG_GO_LIST_CONSOLE
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2463 } while (result
->NextRow());
2468 PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE
,go_id
,obj_count
);
2472 bool ChatHandler::HandleListCreatureCommand(const char* args
)
2477 // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
2478 char* cId
= extractKeyFromLink((char*)args
,"Hcreature_entry");
2482 uint32 cr_id
= atol(cId
);
2485 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID
, cr_id
);
2486 SetSentErrorMessage(true);
2490 CreatureInfo
const* cInfo
= objmgr
.GetCreatureTemplate(cr_id
);
2493 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID
, cr_id
);
2494 SetSentErrorMessage(true);
2498 char* c_count
= strtok(NULL
, " ");
2499 int count
= c_count
? atol(c_count
) : 10;
2504 QueryResult
*result
;
2506 uint32 cr_count
= 0;
2507 result
=WorldDatabase
.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'",cr_id
);
2510 cr_count
= (*result
)[0].GetUInt32();
2516 Player
* pl
= m_session
->GetPlayer();
2517 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",
2518 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(), cr_id
,uint32(count
));
2521 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '%u' LIMIT %u",
2522 cr_id
,uint32(count
));
2528 Field
*fields
= result
->Fetch();
2529 uint32 guid
= fields
[0].GetUInt32();
2530 float x
= fields
[1].GetFloat();
2531 float y
= fields
[2].GetFloat();
2532 float z
= fields
[3].GetFloat();
2533 int mapid
= fields
[4].GetUInt16();
2536 PSendSysMessage(LANG_CREATURE_LIST_CHAT
, guid
, guid
, cInfo
->Name
, x
, y
, z
, mapid
);
2538 PSendSysMessage(LANG_CREATURE_LIST_CONSOLE
, guid
, cInfo
->Name
, x
, y
, z
, mapid
);
2539 } while (result
->NextRow());
2544 PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE
,cr_id
,cr_count
);
2548 bool ChatHandler::HandleLookupItemCommand(const char* args
)
2553 std::string namepart
= args
;
2554 std::wstring wnamepart
;
2556 // converting string that we try to find to lower case
2557 if(!Utf8toWStr(namepart
,wnamepart
))
2560 wstrToLower(wnamepart
);
2564 // Search in `item_template`
2565 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
2567 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
2571 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2574 ItemLocale
const *il
= objmgr
.GetItemLocale(pProto
->ItemId
);
2577 if (il
->Name
.size() > loc_idx
&& !il
->Name
[loc_idx
].empty())
2579 std::string name
= il
->Name
[loc_idx
];
2581 if (Utf8FitTo(name
, wnamepart
))
2584 PSendSysMessage(LANG_ITEM_LIST_CHAT
, id
, id
, name
.c_str());
2586 PSendSysMessage(LANG_ITEM_LIST_CONSOLE
, id
, name
.c_str());
2594 std::string name
= pProto
->Name1
;
2598 if (Utf8FitTo(name
, wnamepart
))
2601 PSendSysMessage(LANG_ITEM_LIST_CHAT
, id
, id
, name
.c_str());
2603 PSendSysMessage(LANG_ITEM_LIST_CONSOLE
, id
, name
.c_str());
2609 SendSysMessage(LANG_COMMAND_NOITEMFOUND
);
2614 bool ChatHandler::HandleLookupItemSetCommand(const char* args
)
2619 std::string namepart
= args
;
2620 std::wstring wnamepart
;
2622 if(!Utf8toWStr(namepart
,wnamepart
))
2625 // converting string that we try to find to lower case
2626 wstrToLower( wnamepart
);
2628 uint32 counter
= 0; // Counter for figure out that we found smth.
2630 // Search in ItemSet.dbc
2631 for (uint32 id
= 0; id
< sItemSetStore
.GetNumRows(); id
++)
2633 ItemSetEntry
const *set
= sItemSetStore
.LookupEntry(id
);
2636 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
2637 std::string name
= set
->name
[loc
];
2641 if (!Utf8FitTo(name
, wnamepart
))
2644 for(; loc
< MAX_LOCALE
; ++loc
)
2646 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
2649 name
= set
->name
[loc
];
2653 if (Utf8FitTo(name
, wnamepart
))
2658 if(loc
< MAX_LOCALE
)
2660 // send item set in "id - [namedlink locale]" format
2662 PSendSysMessage(LANG_ITEMSET_LIST_CHAT
,id
,id
,name
.c_str(),localeNames
[loc
]);
2664 PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE
,id
,name
.c_str(),localeNames
[loc
]);
2669 if (counter
== 0) // if counter == 0 then we found nth
2670 SendSysMessage(LANG_COMMAND_NOITEMSETFOUND
);
2674 bool ChatHandler::HandleLookupSkillCommand(const char* args
)
2679 // can be NULL in console call
2680 Player
* target
= getSelectedPlayer();
2682 std::string namepart
= args
;
2683 std::wstring wnamepart
;
2685 if(!Utf8toWStr(namepart
,wnamepart
))
2688 // converting string that we try to find to lower case
2689 wstrToLower( wnamepart
);
2691 uint32 counter
= 0; // Counter for figure out that we found smth.
2693 // Search in SkillLine.dbc
2694 for (uint32 id
= 0; id
< sSkillLineStore
.GetNumRows(); id
++)
2696 SkillLineEntry
const *skillInfo
= sSkillLineStore
.LookupEntry(id
);
2699 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
2700 std::string name
= skillInfo
->name
[loc
];
2704 if (!Utf8FitTo(name
, wnamepart
))
2707 for(; loc
< MAX_LOCALE
; ++loc
)
2709 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
2712 name
= skillInfo
->name
[loc
];
2716 if (Utf8FitTo(name
, wnamepart
))
2721 if(loc
< MAX_LOCALE
)
2723 char valStr
[50] = "";
2724 char const* knownStr
= "";
2725 if(target
&& target
->HasSkill(id
))
2727 knownStr
= GetMangosString(LANG_KNOWN
);
2728 uint32 curValue
= target
->GetPureSkillValue(id
);
2729 uint32 maxValue
= target
->GetPureMaxSkillValue(id
);
2730 uint32 permValue
= target
->GetSkillPermBonusValue(id
);
2731 uint32 tempValue
= target
->GetSkillTempBonusValue(id
);
2733 char const* valFormat
= GetMangosString(LANG_SKILL_VALUES
);
2734 snprintf(valStr
,50,valFormat
,curValue
,maxValue
,permValue
,tempValue
);
2737 // send skill in "id - [namedlink locale]" format
2739 PSendSysMessage(LANG_SKILL_LIST_CHAT
,id
,id
,name
.c_str(),localeNames
[loc
],knownStr
,valStr
);
2741 PSendSysMessage(LANG_SKILL_LIST_CONSOLE
,id
,name
.c_str(),localeNames
[loc
],knownStr
,valStr
);
2747 if (counter
== 0) // if counter == 0 then we found nth
2748 SendSysMessage(LANG_COMMAND_NOSKILLFOUND
);
2752 bool ChatHandler::HandleLookupSpellCommand(const char* args
)
2757 // can be NULL at console call
2758 Player
* target
= getSelectedPlayer();
2760 std::string namepart
= args
;
2761 std::wstring wnamepart
;
2763 if(!Utf8toWStr(namepart
,wnamepart
))
2766 // converting string that we try to find to lower case
2767 wstrToLower( wnamepart
);
2769 uint32 counter
= 0; // Counter for figure out that we found smth.
2771 // Search in Spell.dbc
2772 for (uint32 id
= 0; id
< sSpellStore
.GetNumRows(); id
++)
2774 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(id
);
2777 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
2778 std::string name
= spellInfo
->SpellName
[loc
];
2782 if (!Utf8FitTo(name
, wnamepart
))
2785 for(; loc
< MAX_LOCALE
; ++loc
)
2787 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
2790 name
= spellInfo
->SpellName
[loc
];
2794 if (Utf8FitTo(name
, wnamepart
))
2799 if(loc
< MAX_LOCALE
)
2801 bool known
= target
&& target
->HasSpell(id
);
2802 bool learn
= (spellInfo
->Effect
[0] == SPELL_EFFECT_LEARN_SPELL
);
2804 uint32 talentCost
= GetTalentSpellCost(id
);
2806 bool talent
= (talentCost
> 0);
2807 bool passive
= IsPassiveSpell(id
);
2808 bool active
= target
&& target
->HasAura(id
);
2810 // unit32 used to prevent interpreting uint8 as char at output
2811 // find rank of learned spell for learning spell, or talent rank
2812 uint32 rank
= talentCost
? talentCost
: spellmgr
.GetSpellRank(learn
? spellInfo
->EffectTriggerSpell
[0] : id
);
2814 // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
2815 std::ostringstream ss
;
2817 ss
<< id
<< " - |cffffffff|Hspell:" << id
<< "|h[" << name
;
2819 ss
<< id
<< " - " << name
;
2821 // include rank in link name
2823 ss
<< GetMangosString(LANG_SPELL_RANK
) << rank
;
2826 ss
<< " " << localeNames
[loc
] << "]|h|r";
2828 ss
<< " " << localeNames
[loc
];
2831 ss
<< GetMangosString(LANG_TALENT
);
2833 ss
<< GetMangosString(LANG_PASSIVE
);
2835 ss
<< GetMangosString(LANG_LEARN
);
2837 ss
<< GetMangosString(LANG_KNOWN
);
2839 ss
<< GetMangosString(LANG_ACTIVE
);
2841 SendSysMessage(ss
.str().c_str());
2847 if (counter
== 0) // if counter == 0 then we found nth
2848 SendSysMessage(LANG_COMMAND_NOSPELLFOUND
);
2852 bool ChatHandler::HandleLookupQuestCommand(const char* args
)
2857 // can be NULL at console call
2858 Player
* target
= getSelectedPlayer();
2860 std::string namepart
= args
;
2861 std::wstring wnamepart
;
2863 // converting string that we try to find to lower case
2864 if(!Utf8toWStr(namepart
,wnamepart
))
2867 wstrToLower(wnamepart
);
2869 uint32 counter
= 0 ;
2871 ObjectMgr::QuestMap
const& qTemplates
= objmgr
.GetQuestTemplates();
2872 for (ObjectMgr::QuestMap::const_iterator iter
= qTemplates
.begin(); iter
!= qTemplates
.end(); ++iter
)
2874 Quest
* qinfo
= iter
->second
;
2876 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2879 QuestLocale
const *il
= objmgr
.GetQuestLocale(qinfo
->GetQuestId());
2882 if (il
->Title
.size() > loc_idx
&& !il
->Title
[loc_idx
].empty())
2884 std::string title
= il
->Title
[loc_idx
];
2886 if (Utf8FitTo(title
, wnamepart
))
2888 char const* statusStr
= "";
2892 QuestStatus status
= target
->GetQuestStatus(qinfo
->GetQuestId());
2894 if(status
== QUEST_STATUS_COMPLETE
)
2896 if(target
->GetQuestRewardStatus(qinfo
->GetQuestId()))
2897 statusStr
= GetMangosString(LANG_COMMAND_QUEST_REWARDED
);
2899 statusStr
= GetMangosString(LANG_COMMAND_QUEST_COMPLETE
);
2901 else if(status
== QUEST_STATUS_INCOMPLETE
)
2902 statusStr
= GetMangosString(LANG_COMMAND_QUEST_ACTIVE
);
2906 PSendSysMessage(LANG_QUEST_LIST_CHAT
,qinfo
->GetQuestId(),qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2908 PSendSysMessage(LANG_QUEST_LIST_CONSOLE
,qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2916 std::string title
= qinfo
->GetTitle();
2920 if (Utf8FitTo(title
, wnamepart
))
2922 char const* statusStr
= "";
2926 QuestStatus status
= target
->GetQuestStatus(qinfo
->GetQuestId());
2928 if(status
== QUEST_STATUS_COMPLETE
)
2930 if(target
->GetQuestRewardStatus(qinfo
->GetQuestId()))
2931 statusStr
= GetMangosString(LANG_COMMAND_QUEST_REWARDED
);
2933 statusStr
= GetMangosString(LANG_COMMAND_QUEST_COMPLETE
);
2935 else if(status
== QUEST_STATUS_INCOMPLETE
)
2936 statusStr
= GetMangosString(LANG_COMMAND_QUEST_ACTIVE
);
2940 PSendSysMessage(LANG_QUEST_LIST_CHAT
,qinfo
->GetQuestId(),qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2942 PSendSysMessage(LANG_QUEST_LIST_CONSOLE
,qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2949 SendSysMessage(LANG_COMMAND_NOQUESTFOUND
);
2954 bool ChatHandler::HandleLookupCreatureCommand(const char* args
)
2959 std::string namepart
= args
;
2960 std::wstring wnamepart
;
2962 // converting string that we try to find to lower case
2963 if (!Utf8toWStr (namepart
,wnamepart
))
2966 wstrToLower (wnamepart
);
2970 for (uint32 id
= 0; id
< sCreatureStorage
.MaxEntry
; ++id
)
2972 CreatureInfo
const* cInfo
= sCreatureStorage
.LookupEntry
<CreatureInfo
> (id
);
2976 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2979 CreatureLocale
const *cl
= objmgr
.GetCreatureLocale (id
);
2982 if (cl
->Name
.size() > loc_idx
&& !cl
->Name
[loc_idx
].empty ())
2984 std::string name
= cl
->Name
[loc_idx
];
2986 if (Utf8FitTo (name
, wnamepart
))
2989 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str ());
2991 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE
, id
, name
.c_str ());
2999 std::string name
= cInfo
->Name
;
3003 if (Utf8FitTo(name
, wnamepart
))
3006 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str ());
3008 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE
, id
, name
.c_str ());
3014 SendSysMessage (LANG_COMMAND_NOCREATUREFOUND
);
3019 bool ChatHandler::HandleLookupObjectCommand(const char* args
)
3024 std::string namepart
= args
;
3025 std::wstring wnamepart
;
3027 // converting string that we try to find to lower case
3028 if(!Utf8toWStr(namepart
,wnamepart
))
3031 wstrToLower(wnamepart
);
3035 for (uint32 id
= 0; id
< sGOStorage
.MaxEntry
; id
++ )
3037 GameObjectInfo
const* gInfo
= sGOStorage
.LookupEntry
<GameObjectInfo
>(id
);
3041 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
3044 GameObjectLocale
const *gl
= objmgr
.GetGameObjectLocale(id
);
3047 if (gl
->Name
.size() > loc_idx
&& !gl
->Name
[loc_idx
].empty())
3049 std::string name
= gl
->Name
[loc_idx
];
3051 if (Utf8FitTo(name
, wnamepart
))
3054 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT
, id
, id
, name
.c_str());
3056 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE
, id
, name
.c_str());
3064 std::string name
= gInfo
->name
;
3068 if(Utf8FitTo(name
, wnamepart
))
3071 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT
, id
, id
, name
.c_str());
3073 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE
, id
, name
.c_str());
3079 SendSysMessage(LANG_COMMAND_NOGAMEOBJECTFOUND
);
3084 bool ChatHandler::HandleLookupTaxiNodeCommand(const char * args
)
3089 std::string namepart
= args
;
3090 std::wstring wnamepart
;
3092 if(!Utf8toWStr(namepart
,wnamepart
))
3095 // converting string that we try to find to lower case
3096 wstrToLower( wnamepart
);
3098 uint32 counter
= 0; // Counter for figure out that we found smth.
3100 // Search in TaxiNodes.dbc
3101 for (uint32 id
= 0; id
< sTaxiNodesStore
.GetNumRows(); id
++)
3103 TaxiNodesEntry
const *nodeEntry
= sTaxiNodesStore
.LookupEntry(id
);
3106 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
3107 std::string name
= nodeEntry
->name
[loc
];
3111 if (!Utf8FitTo(name
, wnamepart
))
3114 for(; loc
< MAX_LOCALE
; ++loc
)
3116 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
3119 name
= nodeEntry
->name
[loc
];
3123 if (Utf8FitTo(name
, wnamepart
))
3128 if(loc
< MAX_LOCALE
)
3130 // send taxinode in "id - [name] (Map:m X:x Y:y Z:z)" format
3132 PSendSysMessage (LANG_TAXINODE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str(),localeNames
[loc
],
3133 nodeEntry
->map_id
,nodeEntry
->x
,nodeEntry
->y
,nodeEntry
->z
);
3135 PSendSysMessage (LANG_TAXINODE_ENTRY_LIST_CONSOLE
, id
, name
.c_str(), localeNames
[loc
],
3136 nodeEntry
->map_id
,nodeEntry
->x
,nodeEntry
->y
,nodeEntry
->z
);
3141 if (counter
== 0) // if counter == 0 then we found nth
3142 SendSysMessage(LANG_COMMAND_NOSPELLFOUND
);
3146 /** \brief GM command level 3 - Create a guild.
3148 * This command allows a GM (level 3) to create a guild.
3150 * The "args" parameter contains the name of the guild leader
3151 * and then the name of the guild.
3154 bool ChatHandler::HandleGuildCreateCommand(const char* args
)
3160 char *lname
= strtok ((char*)args
, " ");
3161 char *gname
= strtok (NULL
, "");
3168 SendSysMessage (LANG_INSERT_GUILD_NAME
);
3169 SetSentErrorMessage (true);
3173 std::string guildname
= gname
;
3175 Player
* player
= ObjectAccessor::Instance ().FindPlayerByName (lname
);
3178 SendSysMessage (LANG_PLAYER_NOT_FOUND
);
3179 SetSentErrorMessage (true);
3183 if (player
->GetGuildId())
3185 SendSysMessage (LANG_PLAYER_IN_GUILD
);
3189 Guild
*guild
= new Guild
;
3190 if (!guild
->create (player
,guildname
))
3193 SendSysMessage (LANG_GUILD_NOT_CREATED
);
3194 SetSentErrorMessage (true);
3198 objmgr
.AddGuild (guild
);
3202 bool ChatHandler::HandleGuildInviteCommand(const char *args
)
3207 char* par1
= strtok ((char*)args
, " ");
3208 char* par2
= strtok (NULL
, "");
3212 std::string glName
= par2
;
3213 Guild
* targetGuild
= objmgr
.GetGuildByName (glName
);
3217 std::string plName
= extractPlayerNameFromLink(par1
);
3220 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3221 SetSentErrorMessage(true);
3226 if (Player
* targetPlayer
= ObjectAccessor::Instance ().FindPlayerByName (plName
.c_str ()))
3227 plGuid
= targetPlayer
->GetGUID ();
3229 plGuid
= objmgr
.GetPlayerGUIDByName (plName
);
3234 // player's guild membership checked in AddMember before add
3235 if (!targetGuild
->AddMember (plGuid
,targetGuild
->GetLowestRank ()))
3241 bool ChatHandler::HandleGuildUninviteCommand(const char *args
)
3246 char* par1
= strtok ((char*)args
, " ");
3250 std::string plName
= extractPlayerNameFromLink(par1
);
3253 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3254 SetSentErrorMessage(true);
3260 if (Player
* targetPlayer
= ObjectAccessor::Instance ().FindPlayerByName (plName
.c_str ()))
3262 plGuid
= targetPlayer
->GetGUID ();
3263 glId
= targetPlayer
->GetGuildId ();
3267 plGuid
= objmgr
.GetPlayerGUIDByName (plName
);
3268 glId
= Player::GetGuildIdFromDB (plGuid
);
3271 if (!plGuid
|| !glId
)
3274 Guild
* targetGuild
= objmgr
.GetGuildById (glId
);
3278 targetGuild
->DelMember (plGuid
);
3283 bool ChatHandler::HandleGuildRankCommand(const char *args
)
3288 char* par1
= strtok ((char*)args
, " ");
3289 char* par2
= strtok (NULL
, " ");
3293 std::string plName
= extractPlayerNameFromLink(par1
);
3296 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3297 SetSentErrorMessage(true);
3304 if (Player
* targetPlayer
= ObjectAccessor::Instance ().FindPlayerByName (plName
.c_str ()))
3306 plGuid
= targetPlayer
->GetGUID ();
3307 glId
= targetPlayer
->GetGuildId ();
3311 plGuid
= objmgr
.GetPlayerGUIDByName (plName
);
3312 glId
= Player::GetGuildIdFromDB (plGuid
);
3315 if (!plGuid
|| !glId
)
3318 Guild
* targetGuild
= objmgr
.GetGuildById (glId
);
3322 uint32 newrank
= uint32 (atoi (par2
));
3323 if (newrank
> targetGuild
->GetLowestRank ())
3326 targetGuild
->ChangeRank (plGuid
,newrank
);
3331 bool ChatHandler::HandleGuildDeleteCommand(const char* args
)
3336 char* par1
= strtok ((char*)args
, " ");
3340 std::string gld
= par1
;
3342 Guild
* targetGuild
= objmgr
.GetGuildByName (gld
);
3346 targetGuild
->Disband ();
3351 bool ChatHandler::HandleGetDistanceCommand(const char* args
)
3353 WorldObject
* obj
= NULL
;
3357 uint64 guid
= extractGuidFromLink((char*)args
);
3359 obj
= (WorldObject
*)ObjectAccessor::GetObjectByTypeMask(*m_session
->GetPlayer(),guid
,TYPEMASK_UNIT
|TYPEMASK_GAMEOBJECT
);
3363 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3364 SetSentErrorMessage(true);
3370 obj
= getSelectedUnit();
3374 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3375 SetSentErrorMessage(true);
3380 PSendSysMessage(LANG_DISTANCE
, m_session
->GetPlayer()->GetDistance(obj
),m_session
->GetPlayer()->GetDistance2d(obj
));
3385 bool ChatHandler::HandleDieCommand(const char* /*args*/)
3387 Unit
* target
= getSelectedUnit();
3389 if(!target
|| !m_session
->GetPlayer()->GetSelection())
3391 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3392 SetSentErrorMessage(true);
3396 if(target
->GetTypeId()==TYPEID_PLAYER
)
3398 if(HasLowerSecurity((Player
*)target
,0,false))
3402 if( target
->isAlive() )
3404 m_session
->GetPlayer()->DealDamage(target
, target
->GetHealth(), NULL
, DIRECT_DAMAGE
, SPELL_SCHOOL_MASK_NORMAL
, NULL
, false);
3410 bool ChatHandler::HandleDamageCommand(const char * args
)
3415 Unit
* target
= getSelectedUnit();
3417 if (!target
|| !m_session
->GetPlayer()->GetSelection())
3419 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3420 SetSentErrorMessage(true);
3424 if (!target
->isAlive())
3427 char* damageStr
= strtok((char*)args
, " ");
3431 int32 damage_int
= atoi((char*)damageStr
);
3435 uint32 damage
= damage_int
;
3437 char* schoolStr
= strtok((char*)NULL
, " ");
3439 // flat melee damage without resistence/etc reduction
3442 m_session
->GetPlayer()->DealDamage(target
, damage
, NULL
, DIRECT_DAMAGE
, SPELL_SCHOOL_MASK_NORMAL
, NULL
, false);
3443 if (target
!= m_session
->GetPlayer())
3444 m_session
->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2
, target
, 1, SPELL_SCHOOL_MASK_NORMAL
, damage
, 0, 0, VICTIMSTATE_NORMAL
, 0);
3448 uint32 school
= schoolStr
? atoi((char*)schoolStr
) : SPELL_SCHOOL_NORMAL
;
3449 if(school
>= MAX_SPELL_SCHOOL
)
3452 SpellSchoolMask schoolmask
= SpellSchoolMask(1 << school
);
3454 if ( schoolmask
& SPELL_SCHOOL_MASK_NORMAL
)
3455 damage
= m_session
->GetPlayer()->CalcArmorReducedDamage(target
, damage
);
3457 char* spellStr
= strtok((char*)NULL
, " ");
3459 // melee damage by specific school
3465 m_session
->GetPlayer()->CalcAbsorbResist(target
,schoolmask
, SPELL_DIRECT_DAMAGE
, damage
, &absorb
, &resist
);
3467 if (damage
<= absorb
+ resist
)
3470 damage
-= absorb
+ resist
;
3472 m_session
->GetPlayer()->DealDamageMods(target
,damage
,&absorb
);
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 for pet
4796 if(Pet
* pet
= player
->GetPet())
4797 pet
->SynchronizeLevelWithOwner();
4802 bool ChatHandler::HandleResetStatsCommand(const char * args
)
4804 char* pName
= strtok((char*)args
, "");
4805 Player
*player
= NULL
;
4808 std::string name
= extractPlayerNameFromLink(pName
);
4811 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4812 SetSentErrorMessage(true);
4816 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
);
4817 player
= objmgr
.GetPlayer(guid
);
4820 player
= getSelectedPlayer();
4824 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4825 SetSentErrorMessage(true);
4829 if(!HandleResetStatsOrLevelHelper(player
))
4832 player
->InitRunes();
4833 player
->InitStatsForLevel(true);
4834 player
->InitTaxiNodesForLevel();
4835 player
->InitGlyphsForLevel();
4836 player
->InitTalentForLevel();
4841 bool ChatHandler::HandleResetSpellsCommand(const char * args
)
4843 char* pName
= strtok((char*)args
, "");
4844 Player
*player
= NULL
;
4845 uint64 playerGUID
= 0;
4848 std::string name
= extractPlayerNameFromLink(pName
);
4851 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4852 SetSentErrorMessage(true);
4856 player
= objmgr
.GetPlayer(name
.c_str());
4858 playerGUID
= objmgr
.GetPlayerGUIDByName(name
);
4861 player
= getSelectedPlayer();
4863 if(!player
&& !playerGUID
)
4865 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4866 SetSentErrorMessage(true);
4872 player
->resetSpells();
4874 ChatHandler(player
).SendSysMessage(LANG_RESET_SPELLS
);
4875 if(m_session
->GetPlayer()!=player
)
4876 PSendSysMessage(LANG_RESET_SPELLS_ONLINE
,GetNameLink(player
).c_str());
4880 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS
), GUID_LOPART(playerGUID
));
4881 PSendSysMessage(LANG_RESET_SPELLS_OFFLINE
,pName
);
4887 bool ChatHandler::HandleResetTalentsCommand(const char * args
)
4889 char* pName
= strtok((char*)args
, "");
4890 Player
*player
= NULL
;
4891 uint64 playerGUID
= 0;
4894 std::string name
= extractPlayerNameFromLink(pName
);
4897 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4898 SetSentErrorMessage(true);
4902 player
= objmgr
.GetPlayer(name
.c_str());
4904 playerGUID
= objmgr
.GetPlayerGUIDByName(name
);
4907 player
= getSelectedPlayer();
4911 player
->resetTalents(true);
4913 ChatHandler(player
).SendSysMessage(LANG_RESET_TALENTS
);
4914 if(m_session
->GetPlayer()!=player
)
4915 PSendSysMessage(LANG_RESET_TALENTS_ONLINE
,GetNameLink(player
).c_str());
4919 else if (playerGUID
)
4921 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_TALENTS
), GUID_LOPART(playerGUID
) );
4922 std::string nameLink
= playerLink(pName
);
4923 PSendSysMessage(LANG_RESET_TALENTS_OFFLINE
,nameLink
.c_str());
4926 // Try reset talenents as Hunter Pet
4927 Creature
* creature
= getSelectedCreature();
4928 if (creature
&& creature
->isPet() && ((Pet
*)creature
)->getPetType() == HUNTER_PET
)
4930 ((Pet
*)creature
)->resetTalents(true);
4931 Unit
*owner
= creature
->GetOwner();
4932 if (owner
&& owner
->GetTypeId() == TYPEID_PLAYER
)
4934 player
= (Player
*)owner
;
4935 ChatHandler(player
).SendSysMessage(LANG_RESET_PET_TALENTS
);
4936 if(m_session
->GetPlayer()!=player
)
4937 PSendSysMessage(LANG_RESET_PET_TALENTS_ONLINE
,GetNameLink(player
).c_str());
4942 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4943 SetSentErrorMessage(true);
4947 bool ChatHandler::HandleResetAllCommand(const char * args
)
4952 std::string casename
= args
;
4954 AtLoginFlags atLogin
;
4956 // Command specially created as single command to prevent using short case names
4957 if(casename
=="spells")
4959 atLogin
= AT_LOGIN_RESET_SPELLS
;
4960 sWorld
.SendWorldText(LANG_RESETALL_SPELLS
);
4962 else if(casename
=="talents")
4964 atLogin
= AT_LOGIN_RESET_TALENTS
;
4965 sWorld
.SendWorldText(LANG_RESETALL_TALENTS
);
4969 PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE
,args
);
4970 SetSentErrorMessage(true);
4974 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE (at_login & '%u') = '0'",atLogin
,atLogin
);
4975 HashMapHolder
<Player
>::MapType
const& plist
= ObjectAccessor::Instance().GetPlayers();
4976 for(HashMapHolder
<Player
>::MapType::const_iterator itr
= plist
.begin(); itr
!= plist
.end(); ++itr
)
4977 itr
->second
->SetAtLoginFlag(atLogin
);
4982 bool ChatHandler::HandleServerShutDownCancelCommand(const char* /*args*/)
4984 sWorld
.ShutdownCancel();
4988 bool ChatHandler::HandleServerShutDownCommand(const char* args
)
4993 char* time_str
= strtok ((char*) args
, " ");
4994 char* exitcode_str
= strtok (NULL
, "");
4996 int32 time
= atoi (time_str
);
4998 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4999 if ((time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0')) || time
< 0)
5004 int32 exitcode
= atoi (exitcode_str
);
5006 // Handle atoi() errors
5007 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
5010 // Exit code should be in range of 0-125, 126-255 is used
5011 // in many shells for their own return codes and code > 255
5012 // is not supported in many others
5013 if (exitcode
< 0 || exitcode
> 125)
5016 sWorld
.ShutdownServ (time
, 0, exitcode
);
5019 sWorld
.ShutdownServ(time
,0,SHUTDOWN_EXIT_CODE
);
5023 bool ChatHandler::HandleServerRestartCommand(const char* args
)
5028 char* time_str
= strtok ((char*) args
, " ");
5029 char* exitcode_str
= strtok (NULL
, "");
5031 int32 time
= atoi (time_str
);
5033 ///- Prevent interpret wrong arg value as 0 secs shutdown time
5034 if(time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0') || time
< 0)
5039 int32 exitcode
= atoi (exitcode_str
);
5041 // Handle atoi() errors
5042 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
5045 // Exit code should be in range of 0-125, 126-255 is used
5046 // in many shells for their own return codes and code > 255
5047 // is not supported in many others
5048 if (exitcode
< 0 || exitcode
> 125)
5051 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_RESTART
, exitcode
);
5054 sWorld
.ShutdownServ(time
, SHUTDOWN_MASK_RESTART
, RESTART_EXIT_CODE
);
5058 bool ChatHandler::HandleServerIdleRestartCommand(const char* args
)
5063 char* time_str
= strtok ((char*) args
, " ");
5064 char* exitcode_str
= strtok (NULL
, "");
5066 int32 time
= atoi (time_str
);
5068 ///- Prevent interpret wrong arg value as 0 secs shutdown time
5069 if(time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0') || time
< 0)
5074 int32 exitcode
= atoi (exitcode_str
);
5076 // Handle atoi() errors
5077 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
5080 // Exit code should be in range of 0-125, 126-255 is used
5081 // in many shells for their own return codes and code > 255
5082 // is not supported in many others
5083 if (exitcode
< 0 || exitcode
> 125)
5086 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_RESTART
|SHUTDOWN_MASK_IDLE
, exitcode
);
5089 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_RESTART
|SHUTDOWN_MASK_IDLE
,RESTART_EXIT_CODE
);
5093 bool ChatHandler::HandleServerIdleShutDownCommand(const char* args
)
5098 char* time_str
= strtok ((char*) args
, " ");
5099 char* exitcode_str
= strtok (NULL
, "");
5101 int32 time
= atoi (time_str
);
5103 ///- Prevent interpret wrong arg value as 0 secs shutdown time
5104 if(time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0') || time
< 0)
5109 int32 exitcode
= atoi (exitcode_str
);
5111 // Handle atoi() errors
5112 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
5115 // Exit code should be in range of 0-125, 126-255 is used
5116 // in many shells for their own return codes and code > 255
5117 // is not supported in many others
5118 if (exitcode
< 0 || exitcode
> 125)
5121 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_IDLE
, exitcode
);
5124 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_IDLE
,SHUTDOWN_EXIT_CODE
);
5128 bool ChatHandler::HandleQuestAdd(const char* args
)
5130 Player
* player
= getSelectedPlayer();
5133 SendSysMessage(LANG_NO_CHAR_SELECTED
);
5134 SetSentErrorMessage(true);
5138 // .addquest #entry'
5139 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
5140 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
5144 uint32 entry
= atol(cId
);
5146 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
5150 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
,entry
);
5151 SetSentErrorMessage(true);
5155 // check item starting quest (it can work incorrectly if added without item in inventory)
5156 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
5158 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
5162 if (pProto
->StartQuest
== entry
)
5164 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM
, entry
, pProto
->ItemId
);
5165 SetSentErrorMessage(true);
5170 // ok, normal (creature/GO starting) quest
5171 if( player
->CanAddQuest( pQuest
, true ) )
5173 player
->AddQuest( pQuest
, NULL
);
5175 if ( player
->CanCompleteQuest( entry
) )
5176 player
->CompleteQuest( entry
);
5182 bool ChatHandler::HandleQuestRemove(const char* args
)
5184 Player
* player
= getSelectedPlayer();
5187 SendSysMessage(LANG_NO_CHAR_SELECTED
);
5188 SetSentErrorMessage(true);
5192 // .removequest #entry'
5193 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
5194 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
5198 uint32 entry
= atol(cId
);
5200 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
5204 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
5205 SetSentErrorMessage(true);
5209 // remove all quest entries for 'entry' from quest log
5210 for(uint8 slot
= 0; slot
< MAX_QUEST_LOG_SIZE
; ++slot
)
5212 uint32 quest
= player
->GetQuestSlotQuestId(slot
);
5215 player
->SetQuestSlot(slot
,0);
5217 // we ignore unequippable quest items in this case, its' still be equipped
5218 player
->TakeQuestSourceItem( quest
, false );
5222 // set quest status to not started (will updated in DB at next save)
5223 player
->SetQuestStatus( entry
, QUEST_STATUS_NONE
);
5225 // reset rewarded for restart repeatable quest
5226 player
->getQuestStatusMap()[entry
].m_rewarded
= false;
5228 SendSysMessage(LANG_COMMAND_QUEST_REMOVED
);
5232 bool ChatHandler::HandleQuestComplete(const char* args
)
5234 Player
* player
= getSelectedPlayer();
5237 SendSysMessage(LANG_NO_CHAR_SELECTED
);
5238 SetSentErrorMessage(true);
5242 // .quest complete #entry
5243 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
5244 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
5248 uint32 entry
= atol(cId
);
5250 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
5252 // If player doesn't have the quest
5253 if(!pQuest
|| player
->GetQuestStatus(entry
) == QUEST_STATUS_NONE
)
5255 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
5256 SetSentErrorMessage(true);
5260 // Add quest items for quests that require items
5261 for(uint8 x
= 0; x
< QUEST_OBJECTIVES_COUNT
; ++x
)
5263 uint32 id
= pQuest
->ReqItemId
[x
];
5264 uint32 count
= pQuest
->ReqItemCount
[x
];
5268 uint32 curItemCount
= player
->GetItemCount(id
,true);
5270 ItemPosCountVec dest
;
5271 uint8 msg
= player
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, id
, count
-curItemCount
);
5272 if( msg
== EQUIP_ERR_OK
)
5274 Item
* item
= player
->StoreNewItem( dest
, id
, true);
5275 player
->SendNewItem(item
,count
-curItemCount
,true,false);
5279 // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
5280 for(uint8 i
= 0; i
< QUEST_OBJECTIVES_COUNT
; ++i
)
5282 uint32 creature
= pQuest
->ReqCreatureOrGOId
[i
];
5283 uint32 creaturecount
= pQuest
->ReqCreatureOrGOCount
[i
];
5285 if(uint32 spell_id
= pQuest
->ReqSpell
[i
])
5287 for(uint16 z
= 0; z
< creaturecount
; ++z
)
5288 player
->CastedCreatureOrGO(creature
,0,spell_id
);
5290 else if(creature
> 0)
5292 for(uint16 z
= 0; z
< creaturecount
; ++z
)
5293 player
->KilledMonster(creature
,0);
5295 else if(creature
< 0)
5297 for(uint16 z
= 0; z
< creaturecount
; ++z
)
5298 player
->CastedCreatureOrGO(creature
,0,0);
5302 // If the quest requires reputation to complete
5303 if(uint32 repFaction
= pQuest
->GetRepObjectiveFaction())
5305 uint32 repValue
= pQuest
->GetRepObjectiveValue();
5306 uint32 curRep
= player
->GetReputationMgr().GetReputation(repFaction
);
5307 if(curRep
< repValue
)
5308 if(FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry(repFaction
))
5309 player
->GetReputationMgr().SetReputation(factionEntry
,repValue
);
5312 // If the quest requires money
5313 int32 ReqOrRewMoney
= pQuest
->GetRewOrReqMoney();
5314 if(ReqOrRewMoney
< 0)
5315 player
->ModifyMoney(-ReqOrRewMoney
);
5317 player
->CompleteQuest(entry
);
5321 bool ChatHandler::HandleBanAccountCommand(const char* args
)
5323 return HandleBanHelper(BAN_ACCOUNT
,args
);
5326 bool ChatHandler::HandleBanCharacterCommand(const char* args
)
5328 return HandleBanHelper(BAN_CHARACTER
,args
);
5331 bool ChatHandler::HandleBanIPCommand(const char* args
)
5333 return HandleBanHelper(BAN_IP
,args
);
5336 bool ChatHandler::HandleBanHelper(BanMode mode
, const char* args
)
5341 char* cnameOrIP
= strtok ((char*)args
, " ");
5345 std::string nameOrIP
= cnameOrIP
;
5347 char* duration
= strtok (NULL
," ");
5348 if(!duration
|| !atoi(duration
))
5351 char* reason
= strtok (NULL
,"");
5358 if(!AccountMgr::normilizeString(nameOrIP
))
5360 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
5361 SetSentErrorMessage(true);
5366 if(!normalizePlayerName(nameOrIP
))
5368 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5369 SetSentErrorMessage(true);
5374 if(!IsIPAddress(nameOrIP
.c_str()))
5379 switch(sWorld
.BanAccount(mode
, nameOrIP
, duration
, reason
,m_session
? m_session
->GetPlayerName() : ""))
5382 if(atoi(duration
)>0)
5383 PSendSysMessage(LANG_BAN_YOUBANNED
,nameOrIP
.c_str(),secsToTimeString(TimeStringToSecs(duration
),true).c_str(),reason
);
5385 PSendSysMessage(LANG_BAN_YOUPERMBANNED
,nameOrIP
.c_str(),reason
);
5387 case BAN_SYNTAX_ERROR
:
5393 PSendSysMessage(LANG_BAN_NOTFOUND
,"account",nameOrIP
.c_str());
5396 PSendSysMessage(LANG_BAN_NOTFOUND
,"character",nameOrIP
.c_str());
5399 PSendSysMessage(LANG_BAN_NOTFOUND
,"ip",nameOrIP
.c_str());
5402 SetSentErrorMessage(true);
5409 bool ChatHandler::HandleUnBanAccountCommand(const char* args
)
5411 return HandleUnBanHelper(BAN_ACCOUNT
,args
);
5414 bool ChatHandler::HandleUnBanCharacterCommand(const char* args
)
5416 return HandleUnBanHelper(BAN_CHARACTER
,args
);
5419 bool ChatHandler::HandleUnBanIPCommand(const char* args
)
5421 return HandleUnBanHelper(BAN_IP
,args
);
5424 bool ChatHandler::HandleUnBanHelper(BanMode mode
, const char* args
)
5429 char* cnameOrIP
= strtok ((char*)args
, " ");
5433 std::string nameOrIP
= cnameOrIP
;
5438 if(!AccountMgr::normilizeString(nameOrIP
))
5440 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
5441 SetSentErrorMessage(true);
5446 if(!normalizePlayerName(nameOrIP
))
5448 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5449 SetSentErrorMessage(true);
5454 if(!IsIPAddress(nameOrIP
.c_str()))
5459 if(sWorld
.RemoveBanAccount(mode
,nameOrIP
))
5460 PSendSysMessage(LANG_UNBAN_UNBANNED
,nameOrIP
.c_str());
5462 PSendSysMessage(LANG_UNBAN_ERROR
,nameOrIP
.c_str());
5467 bool ChatHandler::HandleBanInfoAccountCommand(const char* args
)
5472 char* cname
= strtok((char*)args
, "");
5476 std::string account_name
= cname
;
5477 if(!AccountMgr::normilizeString(account_name
))
5479 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5480 SetSentErrorMessage(true);
5484 uint32 accountid
= accmgr
.GetId(account_name
);
5487 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5491 return HandleBanInfoHelper(accountid
,account_name
.c_str());
5494 bool ChatHandler::HandleBanInfoCharacterCommand(const char* args
)
5499 std::string name
= extractPlayerNameFromLink((char*)args
);
5502 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5503 SetSentErrorMessage(true);
5507 uint32 accountid
= objmgr
.GetPlayerAccountIdByPlayerName(name
);
5510 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5511 SetSentErrorMessage(true);
5515 std::string accountname
;
5516 if(!accmgr
.GetName(accountid
,accountname
))
5518 PSendSysMessage(LANG_BANINFO_NOCHARACTER
);
5522 return HandleBanInfoHelper(accountid
,accountname
.c_str());
5525 bool ChatHandler::HandleBanInfoHelper(uint32 accountid
, char const* accountname
)
5527 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
);
5530 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN
, accountname
);
5534 PSendSysMessage(LANG_BANINFO_BANHISTORY
,accountname
);
5537 Field
* fields
= result
->Fetch();
5539 time_t unbandate
= time_t(fields
[3].GetUInt64());
5540 bool active
= false;
5541 if(fields
[2].GetBool() && (fields
[1].GetUInt64() == (uint64
)0 ||unbandate
>= time(NULL
)) )
5543 bool permanent
= (fields
[1].GetUInt64() == (uint64
)0);
5544 std::string bantime
= permanent
?GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[1].GetUInt64(), true);
5545 PSendSysMessage(LANG_BANINFO_HISTORYENTRY
,
5546 fields
[0].GetString(), bantime
.c_str(), active
? GetMangosString(LANG_BANINFO_YES
):GetMangosString(LANG_BANINFO_NO
), fields
[4].GetString(), fields
[5].GetString());
5547 }while (result
->NextRow());
5553 bool ChatHandler::HandleBanInfoIPCommand(const char* args
)
5558 char* cIP
= strtok ((char*)args
, "");
5562 if (!IsIPAddress(cIP
))
5565 std::string IP
= cIP
;
5567 loginDatabase
.escape_string(IP
);
5568 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());
5571 PSendSysMessage(LANG_BANINFO_NOIP
);
5575 Field
*fields
= result
->Fetch();
5576 bool permanent
= !fields
[6].GetUInt64();
5577 PSendSysMessage(LANG_BANINFO_IPENTRY
,
5578 fields
[0].GetString(), fields
[1].GetString(), permanent
? GetMangosString(LANG_BANINFO_NEVER
):fields
[2].GetString(),
5579 permanent
? GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[3].GetUInt64(), true).c_str(), fields
[4].GetString(), fields
[5].GetString());
5584 bool ChatHandler::HandleBanListCharacterCommand(const char* args
)
5586 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5588 char* cFilter
= strtok ((char*)args
, " ");
5592 std::string filter
= cFilter
;
5593 loginDatabase
.escape_string(filter
);
5594 QueryResult
* result
= CharacterDatabase
.PQuery("SELECT account FROM characters WHERE name "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'"),filter
.c_str());
5597 PSendSysMessage(LANG_BANLIST_NOCHARACTER
);
5601 return HandleBanListHelper(result
);
5604 bool ChatHandler::HandleBanListAccountCommand(const char* args
)
5606 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5608 char* cFilter
= strtok((char*)args
, " ");
5609 std::string filter
= cFilter
? cFilter
: "";
5610 loginDatabase
.escape_string(filter
);
5612 QueryResult
* result
;
5616 result
= loginDatabase
.Query("SELECT account.id, username FROM account, account_banned"
5617 " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
5621 result
= loginDatabase
.PQuery("SELECT account.id, username FROM account, account_banned"
5622 " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
5628 PSendSysMessage(LANG_BANLIST_NOACCOUNT
);
5632 return HandleBanListHelper(result
);
5635 bool ChatHandler::HandleBanListHelper(QueryResult
* result
)
5637 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT
);
5639 // Chat short output
5644 Field
* fields
= result
->Fetch();
5645 uint32 accountid
= fields
[0].GetUInt32();
5647 QueryResult
* banresult
= loginDatabase
.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid
);
5650 Field
* fields2
= banresult
->Fetch();
5651 PSendSysMessage("%s",fields2
[0].GetString());
5654 } while (result
->NextRow());
5656 // Console wide output
5659 SendSysMessage(LANG_BANLIST_ACCOUNTS
);
5660 SendSysMessage("===============================================================================");
5661 SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER
);
5664 SendSysMessage("-------------------------------------------------------------------------------");
5665 Field
*fields
= result
->Fetch();
5666 uint32 account_id
= fields
[0].GetUInt32 ();
5668 std::string account_name
;
5670 // "account" case, name can be get in same query
5671 if(result
->GetFieldCount() > 1)
5672 account_name
= fields
[1].GetCppString();
5673 // "character" case, name need extract from another DB
5675 accmgr
.GetName (account_id
,account_name
);
5677 // No SQL injection. id is uint32.
5678 QueryResult
*banInfo
= loginDatabase
.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id
);
5681 Field
*fields2
= banInfo
->Fetch();
5684 time_t t_ban
= fields2
[0].GetUInt64();
5685 tm
* aTm_ban
= localtime(&t_ban
);
5687 if (fields2
[0].GetUInt64() == fields2
[1].GetUInt64())
5689 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5690 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
,
5691 fields2
[2].GetString(),fields2
[3].GetString());
5695 time_t t_unban
= fields2
[1].GetUInt64();
5696 tm
* aTm_unban
= localtime(&t_unban
);
5697 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5698 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
,
5699 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5700 fields2
[2].GetString(),fields2
[3].GetString());
5702 }while ( banInfo
->NextRow() );
5705 }while( result
->NextRow() );
5706 SendSysMessage("===============================================================================");
5713 bool ChatHandler::HandleBanListIPCommand(const char* args
)
5715 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5717 char* cFilter
= strtok((char*)args
, " ");
5718 std::string filter
= cFilter
? cFilter
: "";
5719 loginDatabase
.escape_string(filter
);
5721 QueryResult
* result
;
5725 result
= loginDatabase
.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5726 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
5727 " ORDER BY unbandate" );
5731 result
= loginDatabase
.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5732 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")
5733 " ORDER BY unbandate",filter
.c_str() );
5738 PSendSysMessage(LANG_BANLIST_NOIP
);
5742 PSendSysMessage(LANG_BANLIST_MATCHINGIP
);
5743 // Chat short output
5748 Field
* fields
= result
->Fetch();
5749 PSendSysMessage("%s",fields
[0].GetString());
5750 } while (result
->NextRow());
5752 // Console wide output
5755 SendSysMessage(LANG_BANLIST_IPS
);
5756 SendSysMessage("===============================================================================");
5757 SendSysMessage(LANG_BANLIST_IPS_HEADER
);
5760 SendSysMessage("-------------------------------------------------------------------------------");
5761 Field
*fields
= result
->Fetch();
5762 time_t t_ban
= fields
[1].GetUInt64();
5763 tm
* aTm_ban
= localtime(&t_ban
);
5764 if ( fields
[1].GetUInt64() == fields
[2].GetUInt64() )
5766 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5767 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
,
5768 fields
[3].GetString(), fields
[4].GetString());
5772 time_t t_unban
= fields
[2].GetUInt64();
5773 tm
* aTm_unban
= localtime(&t_unban
);
5774 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5775 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
,
5776 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5777 fields
[3].GetString(), fields
[4].GetString());
5779 }while( result
->NextRow() );
5780 SendSysMessage("===============================================================================");
5787 bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
5789 Player
* pl
= m_session
->GetPlayer();
5791 // accept only explicitly selected target (not implicitly self targeting case)
5792 Unit
* target
= getSelectedUnit();
5793 if(pl
->GetSelection() && target
)
5795 if(target
->GetTypeId()!=TYPEID_UNIT
)
5797 SendSysMessage(LANG_SELECT_CREATURE
);
5798 SetSentErrorMessage(true);
5802 if(target
->isDead())
5803 ((Creature
*)target
)->Respawn();
5807 CellPair
p(MaNGOS::ComputeCellPair(pl
->GetPositionX(), pl
->GetPositionY()));
5809 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
5812 MaNGOS::RespawnDo u_do
;
5813 MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
> worker(pl
,u_do
);
5815 TypeContainerVisitor
<MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
>, GridTypeMapContainer
> obj_worker(worker
);
5816 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
5817 cell_lock
->Visit(cell_lock
, obj_worker
, *pl
->GetMap());
5822 bool ChatHandler::HandleGMFlyCommand(const char* args
)
5827 Player
*target
= getSelectedPlayer();
5829 target
= m_session
->GetPlayer();
5831 WorldPacket
data(12);
5832 if (strncmp(args
, "on", 3) == 0)
5833 data
.SetOpcode(SMSG_MOVE_SET_CAN_FLY
);
5834 else if (strncmp(args
, "off", 4) == 0)
5835 data
.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY
);
5838 SendSysMessage(LANG_USE_BOL
);
5841 data
.append(target
->GetPackGUID());
5842 data
<< uint32(0); // unknown
5843 target
->SendMessageToSet(&data
, true);
5844 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS
, GetNameLink(target
).c_str(), args
);
5848 bool ChatHandler::HandlePDumpLoadCommand(const char *args
)
5853 char * file
= strtok((char*)args
, " ");
5857 char * account
= strtok(NULL
, " ");
5861 std::string account_name
= account
;
5862 if(!AccountMgr::normilizeString(account_name
))
5864 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5865 SetSentErrorMessage(true);
5869 uint32 account_id
= accmgr
.GetId(account_name
);
5872 account_id
= atoi(account
); // use original string
5875 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5876 SetSentErrorMessage(true);
5881 if(!accmgr
.GetName(account_id
,account_name
))
5883 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5884 SetSentErrorMessage(true);
5888 char* guid_str
= NULL
;
5889 char* name_str
= strtok(NULL
, " ");
5895 // normalize the name if specified and check if it exists
5896 if(!normalizePlayerName(name
))
5898 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5899 SetSentErrorMessage(true);
5903 if(!ObjectMgr::IsValidName(name
,true))
5905 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5906 SetSentErrorMessage(true);
5910 guid_str
= strtok(NULL
, " ");
5917 guid
= atoi(guid_str
);
5920 PSendSysMessage(LANG_INVALID_CHARACTER_GUID
);
5921 SetSentErrorMessage(true);
5925 if(objmgr
.GetPlayerAccountIdByGUID(guid
))
5927 PSendSysMessage(LANG_CHARACTER_GUID_IN_USE
,guid
);
5928 SetSentErrorMessage(true);
5933 switch(PlayerDumpReader().LoadDump(file
, account_id
, name
, guid
))
5936 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS
);
5938 case DUMP_FILE_OPEN_ERROR
:
5939 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
5940 SetSentErrorMessage(true);
5942 case DUMP_FILE_BROKEN
:
5943 PSendSysMessage(LANG_DUMP_BROKEN
,file
);
5944 SetSentErrorMessage(true);
5946 case DUMP_TOO_MANY_CHARS
:
5947 PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL
,account_name
.c_str(),account_id
);
5948 SetSentErrorMessage(true);
5951 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED
);
5952 SetSentErrorMessage(true);
5959 bool ChatHandler::HandlePDumpWriteCommand(const char *args
)
5964 char* file
= strtok((char*)args
, " ");
5965 char* p2
= strtok(NULL
, " ");
5971 // character name can't start from number
5972 if (isNumeric(p2
[0]))
5976 std::string name
= extractPlayerNameFromLink(p2
);
5979 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5980 SetSentErrorMessage(true);
5984 guid
= objmgr
.GetPlayerGUIDByName(name
);
5987 if(!objmgr
.GetPlayerAccountIdByGUID(guid
))
5989 PSendSysMessage(LANG_PLAYER_NOT_FOUND
);
5990 SetSentErrorMessage(true);
5994 switch(PlayerDumpWriter().WriteDump(file
, guid
))
5997 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS
);
5999 case DUMP_FILE_OPEN_ERROR
:
6000 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
6001 SetSentErrorMessage(true);
6004 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED
);
6005 SetSentErrorMessage(true);
6012 bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
6014 Unit
* unit
= getSelectedUnit();
6017 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
6018 SetSentErrorMessage(true);
6022 PSendSysMessage(LANG_MOVEGENS_LIST
,(unit
->GetTypeId()==TYPEID_PLAYER
? "Player" : "Creature" ),unit
->GetGUIDLow());
6024 MotionMaster
* mm
= unit
->GetMotionMaster();
6025 for(MotionMaster::const_iterator itr
= mm
->begin(); itr
!= mm
->end(); ++itr
)
6027 switch((*itr
)->GetMovementGeneratorType())
6029 case IDLE_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_IDLE
); break;
6030 case RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_RANDOM
); break;
6031 case WAYPOINT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_WAYPOINT
); break;
6032 case ANIMAL_RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_ANIMAL_RANDOM
); break;
6033 case CONFUSED_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_CONFUSED
); break;
6034 case TARGETED_MOTION_TYPE
:
6036 if(unit
->GetTypeId()==TYPEID_PLAYER
)
6038 TargetedMovementGenerator
<Player
> const* mgen
= static_cast<TargetedMovementGenerator
<Player
> const*>(*itr
);
6039 Unit
* target
= mgen
->GetTarget();
6041 PSendSysMessage(LANG_MOVEGENS_TARGETED_PLAYER
,target
->GetName(),target
->GetGUIDLow());
6043 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL
);
6047 TargetedMovementGenerator
<Creature
> const* mgen
= static_cast<TargetedMovementGenerator
<Creature
> const*>(*itr
);
6048 Unit
* target
= mgen
->GetTarget();
6050 PSendSysMessage(LANG_MOVEGENS_TARGETED_CREATURE
,target
->GetName(),target
->GetGUIDLow());
6052 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL
);
6056 case HOME_MOTION_TYPE
:
6057 if(unit
->GetTypeId()==TYPEID_UNIT
)
6060 (*itr
)->GetDestination(x
,y
,z
);
6061 PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE
,x
,y
,z
);
6064 SendSysMessage(LANG_MOVEGENS_HOME_PLAYER
);
6066 case FLIGHT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FLIGHT
); break;
6067 case POINT_MOTION_TYPE
:
6070 (*itr
)->GetDestination(x
,y
,z
);
6071 PSendSysMessage(LANG_MOVEGENS_POINT
,x
,y
,z
);
6074 case FLEEING_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FEAR
); break;
6075 case DISTRACT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_DISTRACT
); break;
6077 PSendSysMessage(LANG_MOVEGENS_UNKNOWN
,(*itr
)->GetMovementGeneratorType());
6084 bool ChatHandler::HandleServerPLimitCommand(const char *args
)
6088 char* param
= strtok((char*)args
, " ");
6092 int l
= strlen(param
);
6094 if( strncmp(param
,"player",l
) == 0 )
6095 sWorld
.SetPlayerLimit(-SEC_PLAYER
);
6096 else if(strncmp(param
,"moderator",l
) == 0 )
6097 sWorld
.SetPlayerLimit(-SEC_MODERATOR
);
6098 else if(strncmp(param
,"gamemaster",l
) == 0 )
6099 sWorld
.SetPlayerLimit(-SEC_GAMEMASTER
);
6100 else if(strncmp(param
,"administrator",l
) == 0 )
6101 sWorld
.SetPlayerLimit(-SEC_ADMINISTRATOR
);
6102 else if(strncmp(param
,"reset",l
) == 0 )
6103 sWorld
.SetPlayerLimit( sConfig
.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT
) );
6106 int val
= atoi(param
);
6107 if(val
< -SEC_ADMINISTRATOR
) val
= -SEC_ADMINISTRATOR
;
6109 sWorld
.SetPlayerLimit(val
);
6112 // kick all low security level players
6113 if(sWorld
.GetPlayerAmountLimit() > SEC_PLAYER
)
6114 sWorld
.KickAllLess(sWorld
.GetPlayerSecurityLimit());
6117 uint32 pLimit
= sWorld
.GetPlayerAmountLimit();
6118 AccountTypes allowedAccountType
= sWorld
.GetPlayerSecurityLimit();
6119 char const* secName
= "";
6120 switch(allowedAccountType
)
6122 case SEC_PLAYER
: secName
= "Player"; break;
6123 case SEC_MODERATOR
: secName
= "Moderator"; break;
6124 case SEC_GAMEMASTER
: secName
= "Gamemaster"; break;
6125 case SEC_ADMINISTRATOR
: secName
= "Administrator"; break;
6126 default: secName
= "<unknown>"; break;
6129 PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit
,secName
);
6134 bool ChatHandler::HandleCastCommand(const char* args
)
6139 Unit
* target
= getSelectedUnit();
6143 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
6144 SetSentErrorMessage(true);
6148 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6149 uint32 spell
= extractSpellIdFromLink((char*)args
);
6153 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
6157 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
6159 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
6160 SetSentErrorMessage(true);
6164 char* trig_str
= strtok(NULL
, " ");
6167 int l
= strlen(trig_str
);
6168 if(strncmp(trig_str
,"triggered",l
) != 0 )
6172 bool triggered
= (trig_str
!= NULL
);
6174 m_session
->GetPlayer()->CastSpell(target
,spell
,triggered
);
6179 bool ChatHandler::HandleCastBackCommand(const char* args
)
6181 Creature
* caster
= getSelectedCreature();
6185 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
6186 SetSentErrorMessage(true);
6190 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
6191 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6192 uint32 spell
= extractSpellIdFromLink((char*)args
);
6193 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
6196 char* trig_str
= strtok(NULL
, " ");
6199 int l
= strlen(trig_str
);
6200 if(strncmp(trig_str
,"triggered",l
) != 0 )
6204 bool triggered
= (trig_str
!= NULL
);
6206 // update orientation at server
6207 caster
->SetOrientation(caster
->GetAngle(m_session
->GetPlayer()));
6211 caster
->BuildHeartBeatMsg(&data
);
6212 caster
->SendMessageToSet(&data
,true);
6214 caster
->CastSpell(m_session
->GetPlayer(),spell
,triggered
);
6219 bool ChatHandler::HandleCastDistCommand(const char* args
)
6224 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6225 uint32 spell
= extractSpellIdFromLink((char*)args
);
6229 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
6233 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
6235 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
6236 SetSentErrorMessage(true);
6240 char *distStr
= strtok(NULL
, " ");
6245 sscanf(distStr
, "%f", &dist
);
6247 char* trig_str
= strtok(NULL
, " ");
6250 int l
= strlen(trig_str
);
6251 if(strncmp(trig_str
,"triggered",l
) != 0 )
6255 bool triggered
= (trig_str
!= NULL
);
6258 m_session
->GetPlayer()->GetClosePoint(x
,y
,z
,dist
);
6260 m_session
->GetPlayer()->CastSpell(x
,y
,z
,spell
,triggered
);
6264 bool ChatHandler::HandleCastTargetCommand(const char* args
)
6266 Creature
* caster
= getSelectedCreature();
6270 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
6271 SetSentErrorMessage(true);
6275 if(!caster
->getVictim())
6277 SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM
);
6278 SetSentErrorMessage(true);
6282 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6283 uint32 spell
= extractSpellIdFromLink((char*)args
);
6284 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
6287 char* trig_str
= strtok(NULL
, " ");
6290 int l
= strlen(trig_str
);
6291 if(strncmp(trig_str
,"triggered",l
) != 0 )
6295 bool triggered
= (trig_str
!= NULL
);
6297 // update orientation at server
6298 caster
->SetOrientation(caster
->GetAngle(m_session
->GetPlayer()));
6302 caster
->BuildHeartBeatMsg(&data
);
6303 caster
->SendMessageToSet(&data
,true);
6305 caster
->CastSpell(caster
->getVictim(),spell
,triggered
);
6311 ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
6312 Without this function 3rd party scripting library will get linking errors (unresolved external)
6313 when attempting to use the PointMovementGenerator
6315 bool ChatHandler::HandleComeToMeCommand(const char *args
)
6317 Creature
* caster
= getSelectedCreature();
6321 SendSysMessage(LANG_SELECT_CREATURE
);
6322 SetSentErrorMessage(true);
6326 char* newFlagStr
= strtok((char*)args
, " ");
6331 uint32 newFlags
= atoi(newFlagStr
);
6333 caster
->SetUnitMovementFlags(newFlags
);
6335 Player
* pl
= m_session
->GetPlayer();
6337 caster
->GetMotionMaster()->MovePoint(0, pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ());
6341 bool ChatHandler::HandleCastSelfCommand(const char* args
)
6346 Unit
* target
= getSelectedUnit();
6350 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
6351 SetSentErrorMessage(true);
6355 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6356 uint32 spell
= extractSpellIdFromLink((char*)args
);
6360 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
6364 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
6366 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
6367 SetSentErrorMessage(true);
6371 target
->CastSpell(target
,spell
,false);
6376 std::string
GetTimeString(uint32 time
)
6378 uint16 days
= time
/ DAY
, hours
= (time
% DAY
) / HOUR
, minute
= (time
% HOUR
) / MINUTE
;
6379 std::ostringstream ss
;
6380 if(days
) ss
<< days
<< "d ";
6381 if(hours
) ss
<< hours
<< "h ";
6382 ss
<< minute
<< "m";
6386 bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
6388 Player
* player
= getSelectedPlayer();
6389 if (!player
) player
= m_session
->GetPlayer();
6391 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; ++i
)
6393 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(i
);
6394 for(Player::BoundInstancesMap::const_iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
6396 InstanceSave
*save
= itr
->second
.save
;
6397 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
6398 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());
6402 PSendSysMessage("player binds: %d", counter
);
6404 Group
*group
= player
->GetGroup();
6407 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; ++i
)
6409 Group::BoundInstancesMap
&binds
= group
->GetBoundInstances(i
);
6410 for(Group::BoundInstancesMap::const_iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
6412 InstanceSave
*save
= itr
->second
.save
;
6413 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
6414 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());
6419 PSendSysMessage("group binds: %d", counter
);
6424 bool ChatHandler::HandleInstanceUnbindCommand(const char* args
)
6429 std::string cmd
= args
;
6432 Player
* player
= getSelectedPlayer();
6433 if (!player
) player
= m_session
->GetPlayer();
6435 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; ++i
)
6437 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(i
);
6438 for(Player::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end();)
6440 if(itr
->first
!= player
->GetMapId())
6442 InstanceSave
*save
= itr
->second
.save
;
6443 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
6444 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());
6445 player
->UnbindInstance(itr
, i
);
6452 PSendSysMessage("instances unbound: %d", counter
);
6457 bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
6459 PSendSysMessage("instances loaded: %d", MapManager::Instance().GetNumInstances());
6460 PSendSysMessage("players in instances: %d", MapManager::Instance().GetNumPlayersInInstances());
6461 PSendSysMessage("instance saves: %d", sInstanceSaveManager
.GetNumInstanceSaves());
6462 PSendSysMessage("players bound: %d", sInstanceSaveManager
.GetNumBoundPlayersTotal());
6463 PSendSysMessage("groups bound: %d", sInstanceSaveManager
.GetNumBoundGroupsTotal());
6467 bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
6469 Player
* pl
= m_session
->GetPlayer();
6471 Map
* map
= pl
->GetMap();
6472 if (!map
->IsDungeon())
6474 PSendSysMessage("Map is not a dungeon.");
6475 SetSentErrorMessage(true);
6479 if (!((InstanceMap
*)map
)->GetInstanceData())
6481 PSendSysMessage("Map has no instance data.");
6482 SetSentErrorMessage(true);
6486 ((InstanceMap
*)map
)->GetInstanceData()->SaveToDB();
6490 /// Display the list of GMs
6491 bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
6493 ///- Get the accounts with GM Level >0
6494 QueryResult
*result
= loginDatabase
.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
6497 SendSysMessage(LANG_GMLIST
);
6498 SendSysMessage("========================");
6499 SendSysMessage(LANG_GMLIST_HEADER
);
6500 SendSysMessage("========================");
6502 ///- Circle through them. Display username and GM level
6505 Field
*fields
= result
->Fetch();
6506 PSendSysMessage("|%15s|%6s|", fields
[0].GetString(),fields
[1].GetString());
6507 }while( result
->NextRow() );
6509 PSendSysMessage("========================");
6513 PSendSysMessage(LANG_GMLIST_EMPTY
);
6517 /// Define the 'Message of the day' for the realm
6518 bool ChatHandler::HandleServerSetMotdCommand(const char* args
)
6520 sWorld
.SetMotd(args
);
6521 PSendSysMessage(LANG_MOTD_NEW
, args
);
6525 /// Set/Unset the expansion level for an account
6526 bool ChatHandler::HandleAccountSetAddonCommand(const char* args
)
6528 ///- Get the command line arguments
6529 char *szAcc
= strtok((char*)args
," ");
6530 char *szExp
= strtok(NULL
," ");
6535 std::string account_name
;
6540 Player
* player
= getSelectedPlayer();
6544 account_id
= player
->GetSession()->GetAccountId();
6545 accmgr
.GetName(account_id
,account_name
);
6550 ///- Convert Account name to Upper Format
6551 account_name
= szAcc
;
6552 if(!AccountMgr::normilizeString(account_name
))
6554 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
6555 SetSentErrorMessage(true);
6559 account_id
= accmgr
.GetId(account_name
);
6562 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
6563 SetSentErrorMessage(true);
6569 // Let set addon state only for lesser (strong) security level
6570 // or to self account
6571 if (m_session
&& m_session
->GetAccountId () != account_id
&&
6572 HasLowerSecurityAccount (NULL
,account_id
,true))
6575 int lev
=atoi(szExp
); //get int anyway (0 if error)
6580 loginDatabase
.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev
,account_id
);
6581 PSendSysMessage(LANG_ACCOUNT_SETADDON
,account_name
.c_str(),account_id
,lev
);
6585 //Send items by mail
6586 bool ChatHandler::HandleSendItemsCommand(const char* args
)
6591 // format: name "subject text" "mail text" item1[:count1] item2[:count2] ... item12[:count12]
6593 std::string name
= extractPlayerNameFromLink((char*)args
);
6596 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6597 SetSentErrorMessage(true);
6601 char* tail1
= strtok(NULL
, "");
6607 msgSubject
= strtok(tail1
+1, "\"");
6610 char* space
= strtok(tail1
, "\"");
6613 msgSubject
= strtok(NULL
, "\"");
6619 char* tail2
= strtok(NULL
, "");
6625 msgText
= strtok(tail2
+1, "\"");
6628 char* space
= strtok(tail2
, "\"");
6631 msgText
= strtok(NULL
, "\"");
6637 // msgSubject, msgText isn't NUL after prev. check
6638 std::string subject
= msgSubject
;
6639 std::string text
= msgText
;
6642 typedef std::pair
<uint32
,uint32
> ItemPair
;
6643 typedef std::list
< ItemPair
> ItemPairs
;
6646 // get all tail string
6647 char* tail
= strtok(NULL
, "");
6649 // get from tail next item str
6650 while(char* itemStr
= strtok(tail
, " "))
6653 tail
= strtok(NULL
, "");
6656 char* itemIdStr
= strtok(itemStr
, ":");
6657 char* itemCountStr
= strtok(NULL
, " ");
6659 uint32 item_id
= atoi(itemIdStr
);
6663 ItemPrototype
const* item_proto
= objmgr
.GetItemPrototype(item_id
);
6666 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
6667 SetSentErrorMessage(true);
6671 uint32 item_count
= itemCountStr
? atoi(itemCountStr
) : 1;
6672 if(item_count
< 1 || item_proto
->MaxCount
> 0 && item_count
> uint32(item_proto
->MaxCount
))
6674 PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT
, item_count
,item_id
);
6675 SetSentErrorMessage(true);
6679 while(item_count
> item_proto
->GetMaxStackSize())
6681 items
.push_back(ItemPair(item_id
,item_proto
->GetMaxStackSize()));
6682 item_count
-= item_proto
->GetMaxStackSize();
6685 items
.push_back(ItemPair(item_id
,item_count
));
6687 if(items
.size() > MAX_MAIL_ITEMS
)
6689 PSendSysMessage(LANG_COMMAND_MAIL_ITEMS_LIMIT
, MAX_MAIL_ITEMS
);
6690 SetSentErrorMessage(true);
6695 uint64 receiver_guid
= objmgr
.GetPlayerGUIDByName(name
);
6698 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6699 SetSentErrorMessage(true);
6703 // from console show not existed sender
6704 uint32 sender_guidlo
= m_session
? m_session
->GetPlayer()->GetGUIDLow() : 0;
6706 uint32 messagetype
= MAIL_NORMAL
;
6707 uint32 stationery
= MAIL_STATIONERY_GM
;
6708 uint32 itemTextId
= !text
.empty() ? objmgr
.CreateItemText( text
) : 0;
6710 Player
*receiver
= objmgr
.GetPlayer(receiver_guid
);
6713 MailItemsInfo mi
; // item list preparing
6715 for(ItemPairs::const_iterator itr
= items
.begin(); itr
!= items
.end(); ++itr
)
6717 if(Item
* item
= Item::CreateItem(itr
->first
,itr
->second
,m_session
? m_session
->GetPlayer() : 0))
6719 item
->SaveToDB(); // save for prevent lost at next mail load, if send fail then item will deleted
6720 mi
.AddItem(item
->GetGUIDLow(), item
->GetEntry(), item
);
6724 WorldSession::SendMailTo(receiver
,messagetype
, stationery
, sender_guidlo
, GUID_LOPART(receiver_guid
), subject
, itemTextId
, &mi
, 0, 0, MAIL_CHECK_MASK_NONE
);
6726 std::string nameLink
= playerLink(name
);
6727 PSendSysMessage(LANG_MAIL_SENT
, nameLink
.c_str());
6731 ///Send money by mail
6732 bool ChatHandler::HandleSendMoneyCommand(const char* args
)
6737 /// format: name "subject text" "mail text" money
6739 std::string name
= extractPlayerNameFromLink((char*)args
);
6742 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6743 SetSentErrorMessage(true);
6747 char* tail1
= strtok(NULL
, "");
6753 msgSubject
= strtok(tail1
+1, "\"");
6756 char* space
= strtok(tail1
, "\"");
6759 msgSubject
= strtok(NULL
, "\"");
6765 char* tail2
= strtok(NULL
, "");
6771 msgText
= strtok(tail2
+1, "\"");
6774 char* space
= strtok(tail2
, "\"");
6777 msgText
= strtok(NULL
, "\"");
6783 char* money_str
= strtok(NULL
, "");
6784 int32 money
= money_str
? atoi(money_str
) : 0;
6788 // msgSubject, msgText isn't NUL after prev. check
6789 std::string subject
= msgSubject
;
6790 std::string text
= msgText
;
6792 uint64 receiver_guid
= objmgr
.GetPlayerGUIDByName(name
);
6795 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6796 SetSentErrorMessage(true);
6800 // from console show not existed sender
6801 uint32 sender_guidlo
= m_session
? m_session
->GetPlayer()->GetGUIDLow() : 0;
6803 uint32 messagetype
= MAIL_NORMAL
;
6804 uint32 stationery
= MAIL_STATIONERY_GM
;
6805 uint32 itemTextId
= !text
.empty() ? objmgr
.CreateItemText( text
) : 0;
6807 Player
*receiver
= objmgr
.GetPlayer(receiver_guid
);
6809 WorldSession::SendMailTo(receiver
,messagetype
, stationery
, sender_guidlo
, GUID_LOPART(receiver_guid
), subject
, itemTextId
, NULL
, money
, 0, MAIL_CHECK_MASK_NONE
);
6811 std::string nameLink
= playerLink(name
);
6812 PSendSysMessage(LANG_MAIL_SENT
, nameLink
.c_str());
6816 /// Send a message to a player in game
6817 bool ChatHandler::HandleSendMessageCommand(const char* args
)
6819 ///- Get the command line arguments
6820 std::string name
= extractPlayerNameFromLink((char*)args
);
6823 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6824 SetSentErrorMessage(true);
6828 char* msg_str
= strtok(NULL
, "");
6832 ///- Find the player and check that he is not logging out.
6833 Player
*rPlayer
= objmgr
.GetPlayer(name
.c_str());
6836 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6837 SetSentErrorMessage(true);
6841 if(rPlayer
->GetSession()->isLogingOut())
6843 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6844 SetSentErrorMessage(true);
6848 ///- Send the message
6849 //Use SendAreaTriggerMessage for fastest delivery.
6850 rPlayer
->GetSession()->SendAreaTriggerMessage("%s", msg_str
);
6851 rPlayer
->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
6853 //Confirmation message
6854 std::string nameLink
= playerLink(name
);
6855 PSendSysMessage(LANG_SENDMESSAGE
,nameLink
.c_str(),msg_str
);
6859 bool ChatHandler::HandleFlushArenaPointsCommand(const char * /*args*/)
6861 sBattleGroundMgr
.DistributeArenaPoints();
6865 bool ChatHandler::HandleModifyGenderCommand(const char *args
)
6870 Player
*player
= getSelectedPlayer();
6874 PSendSysMessage(LANG_PLAYER_NOT_FOUND
);
6875 SetSentErrorMessage(true);
6879 PlayerInfo
const* info
= objmgr
.GetPlayerInfo(player
->getRace(), player
->getClass());
6883 char const* gender_str
= (char*)args
;
6884 int gender_len
= strlen(gender_str
);
6888 if(!strncmp(gender_str
, "male", gender_len
)) // MALE
6890 if(player
->getGender() == GENDER_MALE
)
6893 gender
= GENDER_MALE
;
6895 else if (!strncmp(gender_str
, "female", gender_len
)) // FEMALE
6897 if(player
->getGender() == GENDER_FEMALE
)
6900 gender
= GENDER_FEMALE
;
6904 SendSysMessage(LANG_MUST_MALE_OR_FEMALE
);
6905 SetSentErrorMessage(true);
6910 player
->SetByteValue(UNIT_FIELD_BYTES_0
, 2, gender
);
6911 player
->SetByteValue(PLAYER_BYTES_3
, 0, gender
);
6913 // Change display ID
6914 player
->SetDisplayId(gender
? info
->displayId_f
: info
->displayId_m
);
6915 player
->SetNativeDisplayId(gender
? info
->displayId_f
: info
->displayId_m
);
6917 char const* gender_full
= gender
? "female" : "male";
6919 PSendSysMessage(LANG_YOU_CHANGE_GENDER
, GetNameLink(player
).c_str(), gender_full
);
6921 if (needReportToTarget(player
))
6922 ChatHandler(player
).PSendSysMessage(LANG_YOUR_GENDER_CHANGED
, gender_full
, GetNameLink().c_str());