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");
108 bool ChatHandler::HandleReloadAllQuestCommand(const char* /*args*/)
110 HandleReloadQuestAreaTriggersCommand("a");
111 HandleReloadQuestTemplateCommand("a");
113 sLog
.outString( "Re-Loading Quests Relations..." );
114 objmgr
.LoadQuestRelations();
115 SendGlobalSysMessage("DB tables `*_questrelation` and `*_involvedrelation` reloaded.");
119 bool ChatHandler::HandleReloadAllScriptsCommand(const char*)
121 if(sWorld
.IsScriptScheduled())
123 PSendSysMessage("DB scripts used currently, please attempt reload later.");
124 SetSentErrorMessage(true);
128 sLog
.outString( "Re-Loading Scripts..." );
129 HandleReloadGameObjectScriptsCommand("a");
130 HandleReloadEventScriptsCommand("a");
131 HandleReloadQuestEndScriptsCommand("a");
132 HandleReloadQuestStartScriptsCommand("a");
133 HandleReloadSpellScriptsCommand("a");
134 SendGlobalSysMessage("DB tables `*_scripts` reloaded.");
135 HandleReloadDbScriptStringCommand("a");
139 bool ChatHandler::HandleReloadAllSpellCommand(const char*)
141 HandleReloadSkillDiscoveryTemplateCommand("a");
142 HandleReloadSkillExtraItemTemplateCommand("a");
143 HandleReloadSpellAffectCommand("a");
144 HandleReloadSpellAreaCommand("a");
145 HandleReloadSpellChainCommand("a");
146 HandleReloadSpellElixirCommand("a");
147 HandleReloadSpellLearnSpellCommand("a");
148 HandleReloadSpellProcEventCommand("a");
149 HandleReloadSpellBonusesCommand("a");
150 HandleReloadSpellScriptTargetCommand("a");
151 HandleReloadSpellTargetPositionCommand("a");
152 HandleReloadSpellThreatsCommand("a");
153 HandleReloadSpellPetAurasCommand("a");
157 bool ChatHandler::HandleReloadAllItemCommand(const char*)
159 HandleReloadPageTextsCommand("a");
160 HandleReloadItemEnchantementsCommand("a");
164 bool ChatHandler::HandleReloadAllLocalesCommand(const char* /*args*/)
166 HandleReloadLocalesAchievementRewardCommand("a");
167 HandleReloadLocalesCreatureCommand("a");
168 HandleReloadLocalesGameobjectCommand("a");
169 HandleReloadLocalesItemCommand("a");
170 HandleReloadLocalesNpcTextCommand("a");
171 HandleReloadLocalesPageTextCommand("a");
172 HandleReloadLocalesPointsOfInterestCommand("a");
173 HandleReloadLocalesQuestCommand("a");
177 bool ChatHandler::HandleReloadConfigCommand(const char* /*args*/)
179 sLog
.outString( "Re-Loading config settings..." );
180 sWorld
.LoadConfigSettings(true);
181 SendGlobalSysMessage("World config settings reloaded.");
185 bool ChatHandler::HandleReloadAchievementCriteriaDataCommand(const char*)
187 sLog
.outString( "Re-Loading Additional Achievement Criteria Data..." );
188 achievementmgr
.LoadAchievementCriteriaData();
189 SendGlobalSysMessage("DB table `achievement_criteria_data` reloaded.");
193 bool ChatHandler::HandleReloadAchievementRewardCommand(const char*)
195 sLog
.outString( "Re-Loading Achievement Reward Data..." );
196 achievementmgr
.LoadRewards();
197 SendGlobalSysMessage("DB table `achievement_reward` reloaded.");
201 bool ChatHandler::HandleReloadAreaTriggerTavernCommand(const char*)
203 sLog
.outString( "Re-Loading Tavern Area Triggers..." );
204 objmgr
.LoadTavernAreaTriggers();
205 SendGlobalSysMessage("DB table `areatrigger_tavern` reloaded.");
209 bool ChatHandler::HandleReloadAreaTriggerTeleportCommand(const char*)
211 sLog
.outString( "Re-Loading AreaTrigger teleport definitions..." );
212 objmgr
.LoadAreaTriggerTeleports();
213 SendGlobalSysMessage("DB table `areatrigger_teleport` reloaded.");
217 bool ChatHandler::HandleReloadCommandCommand(const char*)
219 load_command_table
= true;
220 SendGlobalSysMessage("DB table `command` will be reloaded at next chat command use.");
224 bool ChatHandler::HandleReloadCreatureQuestRelationsCommand(const char*)
226 sLog
.outString( "Loading Quests Relations... (`creature_questrelation`)" );
227 objmgr
.LoadCreatureQuestRelations();
228 SendGlobalSysMessage("DB table `creature_questrelation` (creature quest givers) reloaded.");
232 bool ChatHandler::HandleReloadCreatureQuestInvRelationsCommand(const char*)
234 sLog
.outString( "Loading Quests Relations... (`creature_involvedrelation`)" );
235 objmgr
.LoadCreatureInvolvedRelations();
236 SendGlobalSysMessage("DB table `creature_involvedrelation` (creature quest takers) reloaded.");
240 bool ChatHandler::HandleReloadGOQuestRelationsCommand(const char*)
242 sLog
.outString( "Loading Quests Relations... (`gameobject_questrelation`)" );
243 objmgr
.LoadGameobjectQuestRelations();
244 SendGlobalSysMessage("DB table `gameobject_questrelation` (gameobject quest givers) reloaded.");
248 bool ChatHandler::HandleReloadGOQuestInvRelationsCommand(const char*)
250 sLog
.outString( "Loading Quests Relations... (`gameobject_involvedrelation`)" );
251 objmgr
.LoadGameobjectInvolvedRelations();
252 SendGlobalSysMessage("DB table `gameobject_involvedrelation` (gameobject quest takers) reloaded.");
256 bool ChatHandler::HandleReloadQuestAreaTriggersCommand(const char*)
258 sLog
.outString( "Re-Loading Quest Area Triggers..." );
259 objmgr
.LoadQuestAreaTriggers();
260 SendGlobalSysMessage("DB table `areatrigger_involvedrelation` (quest area triggers) reloaded.");
264 bool ChatHandler::HandleReloadQuestTemplateCommand(const char*)
266 sLog
.outString( "Re-Loading Quest Templates..." );
268 SendGlobalSysMessage("DB table `quest_template` (quest definitions) reloaded.");
270 /// dependent also from `gameobject` but this table not reloaded anyway
271 sLog
.outString( "Re-Loading GameObjects for quests..." );
272 objmgr
.LoadGameObjectForQuests();
273 SendGlobalSysMessage("Data GameObjects for quests reloaded.");
277 bool ChatHandler::HandleReloadLootTemplatesCreatureCommand(const char*)
279 sLog
.outString( "Re-Loading Loot Tables... (`creature_loot_template`)" );
280 LoadLootTemplates_Creature();
281 LootTemplates_Creature
.CheckLootRefs();
282 SendGlobalSysMessage("DB table `creature_loot_template` reloaded.");
286 bool ChatHandler::HandleReloadLootTemplatesDisenchantCommand(const char*)
288 sLog
.outString( "Re-Loading Loot Tables... (`disenchant_loot_template`)" );
289 LoadLootTemplates_Disenchant();
290 LootTemplates_Disenchant
.CheckLootRefs();
291 SendGlobalSysMessage("DB table `disenchant_loot_template` reloaded.");
295 bool ChatHandler::HandleReloadLootTemplatesFishingCommand(const char*)
297 sLog
.outString( "Re-Loading Loot Tables... (`fishing_loot_template`)" );
298 LoadLootTemplates_Fishing();
299 LootTemplates_Fishing
.CheckLootRefs();
300 SendGlobalSysMessage("DB table `fishing_loot_template` reloaded.");
304 bool ChatHandler::HandleReloadLootTemplatesGameobjectCommand(const char*)
306 sLog
.outString( "Re-Loading Loot Tables... (`gameobject_loot_template`)" );
307 LoadLootTemplates_Gameobject();
308 LootTemplates_Gameobject
.CheckLootRefs();
309 SendGlobalSysMessage("DB table `gameobject_loot_template` reloaded.");
313 bool ChatHandler::HandleReloadLootTemplatesItemCommand(const char*)
315 sLog
.outString( "Re-Loading Loot Tables... (`item_loot_template`)" );
316 LoadLootTemplates_Item();
317 LootTemplates_Item
.CheckLootRefs();
318 SendGlobalSysMessage("DB table `item_loot_template` reloaded.");
322 bool ChatHandler::HandleReloadLootTemplatesMillingCommand(const char*)
324 sLog
.outString( "Re-Loading Loot Tables... (`milling_loot_template`)" );
325 LoadLootTemplates_Milling();
326 LootTemplates_Milling
.CheckLootRefs();
327 SendGlobalSysMessage("DB table `milling_loot_template` reloaded.");
331 bool ChatHandler::HandleReloadLootTemplatesPickpocketingCommand(const char*)
333 sLog
.outString( "Re-Loading Loot Tables... (`pickpocketing_loot_template`)" );
334 LoadLootTemplates_Pickpocketing();
335 LootTemplates_Pickpocketing
.CheckLootRefs();
336 SendGlobalSysMessage("DB table `pickpocketing_loot_template` reloaded.");
340 bool ChatHandler::HandleReloadLootTemplatesProspectingCommand(const char*)
342 sLog
.outString( "Re-Loading Loot Tables... (`prospecting_loot_template`)" );
343 LoadLootTemplates_Prospecting();
344 LootTemplates_Prospecting
.CheckLootRefs();
345 SendGlobalSysMessage("DB table `prospecting_loot_template` reloaded.");
349 bool ChatHandler::HandleReloadLootTemplatesQuestMailCommand(const char*)
351 sLog
.outString( "Re-Loading Loot Tables... (`quest_mail_loot_template`)" );
352 LoadLootTemplates_QuestMail();
353 LootTemplates_QuestMail
.CheckLootRefs();
354 SendGlobalSysMessage("DB table `quest_mail_loot_template` reloaded.");
358 bool ChatHandler::HandleReloadLootTemplatesReferenceCommand(const char*)
360 sLog
.outString( "Re-Loading Loot Tables... (`reference_loot_template`)" );
361 LoadLootTemplates_Reference();
362 SendGlobalSysMessage("DB table `reference_loot_template` reloaded.");
366 bool ChatHandler::HandleReloadLootTemplatesSkinningCommand(const char*)
368 sLog
.outString( "Re-Loading Loot Tables... (`skinning_loot_template`)" );
369 LoadLootTemplates_Skinning();
370 LootTemplates_Skinning
.CheckLootRefs();
371 SendGlobalSysMessage("DB table `skinning_loot_template` reloaded.");
375 bool ChatHandler::HandleReloadLootTemplatesSpellCommand(const char*)
377 sLog
.outString( "Re-Loading Loot Tables... (`spell_loot_template`)" );
378 LoadLootTemplates_Spell();
379 LootTemplates_Spell
.CheckLootRefs();
380 SendGlobalSysMessage("DB table `spell_loot_template` reloaded.");
384 bool ChatHandler::HandleReloadMangosStringCommand(const char*)
386 sLog
.outString( "Re-Loading mangos_string Table!" );
387 objmgr
.LoadMangosStrings();
388 SendGlobalSysMessage("DB table `mangos_string` reloaded.");
392 bool ChatHandler::HandleReloadNpcOptionCommand(const char*)
394 sLog
.outString( "Re-Loading `npc_option` Table!" );
395 objmgr
.LoadNpcOptions();
396 SendGlobalSysMessage("DB table `npc_option` reloaded.");
400 bool ChatHandler::HandleReloadNpcGossipCommand(const char*)
402 sLog
.outString( "Re-Loading `npc_gossip` Table!" );
403 objmgr
.LoadNpcTextId();
404 SendGlobalSysMessage("DB table `npc_gossip` reloaded.");
408 bool ChatHandler::HandleReloadNpcTrainerCommand(const char*)
410 sLog
.outString( "Re-Loading `npc_trainer` Table!" );
411 objmgr
.LoadTrainerSpell();
412 SendGlobalSysMessage("DB table `npc_trainer` reloaded.");
416 bool ChatHandler::HandleReloadNpcVendorCommand(const char*)
418 sLog
.outString( "Re-Loading `npc_vendor` Table!" );
419 objmgr
.LoadVendors();
420 SendGlobalSysMessage("DB table `npc_vendor` reloaded.");
424 bool ChatHandler::HandleReloadPointsOfInterestCommand(const char*)
426 sLog
.outString( "Re-Loading `points_of_interest` Table!" );
427 objmgr
.LoadPointsOfInterest();
428 SendGlobalSysMessage("DB table `points_of_interest` reloaded.");
432 bool ChatHandler::HandleReloadReservedNameCommand(const char*)
434 sLog
.outString( "Loading ReservedNames... (`reserved_name`)" );
435 objmgr
.LoadReservedPlayersNames();
436 SendGlobalSysMessage("DB table `reserved_name` (player reserved names) reloaded.");
440 bool ChatHandler::HandleReloadSkillDiscoveryTemplateCommand(const char* /*args*/)
442 sLog
.outString( "Re-Loading Skill Discovery Table..." );
443 LoadSkillDiscoveryTable();
444 SendGlobalSysMessage("DB table `skill_discovery_template` (recipes discovered at crafting) reloaded.");
448 bool ChatHandler::HandleReloadSkillExtraItemTemplateCommand(const char* /*args*/)
450 sLog
.outString( "Re-Loading Skill Extra Item Table..." );
451 LoadSkillExtraItemTable();
452 SendGlobalSysMessage("DB table `skill_extra_item_template` (extra item creation when crafting) reloaded.");
456 bool ChatHandler::HandleReloadSkillFishingBaseLevelCommand(const char* /*args*/)
458 sLog
.outString( "Re-Loading Skill Fishing base level requirements..." );
459 objmgr
.LoadFishingBaseSkillLevel();
460 SendGlobalSysMessage("DB table `skill_fishing_base_level` (fishing base level for zone/subzone) reloaded.");
464 bool ChatHandler::HandleReloadSpellAffectCommand(const char*)
466 sLog
.outString( "Re-Loading SpellAffect definitions..." );
467 spellmgr
.LoadSpellAffects();
468 SendGlobalSysMessage("DB table `spell_affect` (spell mods apply requirements) reloaded.");
472 bool ChatHandler::HandleReloadSpellAreaCommand(const char*)
474 sLog
.outString( "Re-Loading SpellArea Data..." );
475 spellmgr
.LoadSpellAreas();
476 SendGlobalSysMessage("DB table `spell_area` (spell dependences from area/quest/auras state) reloaded.");
480 bool ChatHandler::HandleReloadSpellChainCommand(const char*)
482 sLog
.outString( "Re-Loading Spell Chain Data... " );
483 spellmgr
.LoadSpellChains();
484 SendGlobalSysMessage("DB table `spell_chain` (spell ranks) reloaded.");
488 bool ChatHandler::HandleReloadSpellElixirCommand(const char*)
490 sLog
.outString( "Re-Loading Spell Elixir types..." );
491 spellmgr
.LoadSpellElixirs();
492 SendGlobalSysMessage("DB table `spell_elixir` (spell elixir types) reloaded.");
496 bool ChatHandler::HandleReloadSpellLearnSpellCommand(const char*)
498 sLog
.outString( "Re-Loading Spell Learn Spells..." );
499 spellmgr
.LoadSpellLearnSpells();
500 SendGlobalSysMessage("DB table `spell_learn_spell` reloaded.");
504 bool ChatHandler::HandleReloadSpellProcEventCommand(const char*)
506 sLog
.outString( "Re-Loading Spell Proc Event conditions..." );
507 spellmgr
.LoadSpellProcEvents();
508 SendGlobalSysMessage("DB table `spell_proc_event` (spell proc trigger requirements) reloaded.");
512 bool ChatHandler::HandleReloadSpellBonusesCommand(const char*)
514 sLog
.outString( "Re-Loading Spell Bonus Data..." );
515 spellmgr
.LoadSpellBonusess();
516 SendGlobalSysMessage("DB table `spell_bonus_data` (spell damage/healing coefficients) reloaded.");
520 bool ChatHandler::HandleReloadSpellScriptTargetCommand(const char*)
522 sLog
.outString( "Re-Loading SpellsScriptTarget..." );
523 spellmgr
.LoadSpellScriptTarget();
524 SendGlobalSysMessage("DB table `spell_script_target` (spell targets selection in case specific creature/GO requirements) reloaded.");
528 bool ChatHandler::HandleReloadSpellTargetPositionCommand(const char*)
530 sLog
.outString( "Re-Loading Spell target coordinates..." );
531 spellmgr
.LoadSpellTargetPositions();
532 SendGlobalSysMessage("DB table `spell_target_position` (destination coordinates for spell targets) reloaded.");
536 bool ChatHandler::HandleReloadSpellThreatsCommand(const char*)
538 sLog
.outString( "Re-Loading Aggro Spells Definitions...");
539 spellmgr
.LoadSpellThreats();
540 SendGlobalSysMessage("DB table `spell_threat` (spell aggro definitions) reloaded.");
544 bool ChatHandler::HandleReloadSpellPetAurasCommand(const char*)
546 sLog
.outString( "Re-Loading Spell pet auras...");
547 spellmgr
.LoadSpellPetAuras();
548 SendGlobalSysMessage("DB table `spell_pet_auras` reloaded.");
552 bool ChatHandler::HandleReloadPageTextsCommand(const char*)
554 sLog
.outString( "Re-Loading Page Texts..." );
555 objmgr
.LoadPageTexts();
556 SendGlobalSysMessage("DB table `page_texts` reloaded.");
560 bool ChatHandler::HandleReloadItemEnchantementsCommand(const char*)
562 sLog
.outString( "Re-Loading Item Random Enchantments Table..." );
563 LoadRandomEnchantmentsTable();
564 SendGlobalSysMessage("DB table `item_enchantment_template` reloaded.");
568 bool ChatHandler::HandleReloadGameObjectScriptsCommand(const char* arg
)
570 if(sWorld
.IsScriptScheduled())
572 SendSysMessage("DB scripts used currently, please attempt reload later.");
573 SetSentErrorMessage(true);
578 sLog
.outString( "Re-Loading Scripts from `gameobject_scripts`...");
580 objmgr
.LoadGameObjectScripts();
583 SendGlobalSysMessage("DB table `gameobject_scripts` reloaded.");
588 bool ChatHandler::HandleReloadEventScriptsCommand(const char* arg
)
590 if(sWorld
.IsScriptScheduled())
592 SendSysMessage("DB scripts used currently, please attempt reload later.");
593 SetSentErrorMessage(true);
598 sLog
.outString( "Re-Loading Scripts from `event_scripts`...");
600 objmgr
.LoadEventScripts();
603 SendGlobalSysMessage("DB table `event_scripts` reloaded.");
608 bool ChatHandler::HandleReloadQuestEndScriptsCommand(const char* arg
)
610 if(sWorld
.IsScriptScheduled())
612 SendSysMessage("DB scripts used currently, please attempt reload later.");
613 SetSentErrorMessage(true);
618 sLog
.outString( "Re-Loading Scripts from `quest_end_scripts`...");
620 objmgr
.LoadQuestEndScripts();
623 SendGlobalSysMessage("DB table `quest_end_scripts` reloaded.");
628 bool ChatHandler::HandleReloadQuestStartScriptsCommand(const char* arg
)
630 if(sWorld
.IsScriptScheduled())
632 SendSysMessage("DB scripts used currently, please attempt reload later.");
633 SetSentErrorMessage(true);
638 sLog
.outString( "Re-Loading Scripts from `quest_start_scripts`...");
640 objmgr
.LoadQuestStartScripts();
643 SendGlobalSysMessage("DB table `quest_start_scripts` reloaded.");
648 bool ChatHandler::HandleReloadSpellScriptsCommand(const char* arg
)
650 if(sWorld
.IsScriptScheduled())
652 SendSysMessage("DB scripts used currently, please attempt reload later.");
653 SetSentErrorMessage(true);
658 sLog
.outString( "Re-Loading Scripts from `spell_scripts`...");
660 objmgr
.LoadSpellScripts();
663 SendGlobalSysMessage("DB table `spell_scripts` reloaded.");
668 bool ChatHandler::HandleReloadDbScriptStringCommand(const char* arg
)
670 sLog
.outString( "Re-Loading Script strings from `db_script_string`...");
671 objmgr
.LoadDbScriptStrings();
672 SendGlobalSysMessage("DB table `db_script_string` reloaded.");
676 bool ChatHandler::HandleReloadGameGraveyardZoneCommand(const char* /*arg*/)
678 sLog
.outString( "Re-Loading Graveyard-zone links...");
680 objmgr
.LoadGraveyardZones();
682 SendGlobalSysMessage("DB table `game_graveyard_zone` reloaded.");
687 bool ChatHandler::HandleReloadGameTeleCommand(const char* /*arg*/)
689 sLog
.outString( "Re-Loading Game Tele coordinates...");
691 objmgr
.LoadGameTele();
693 SendGlobalSysMessage("DB table `game_tele` reloaded.");
698 bool ChatHandler::HandleReloadLocalesAchievementRewardCommand(const char*)
700 sLog
.outString( "Re-Loading Locales Achievement Reward Data..." );
701 achievementmgr
.LoadRewardLocales();
702 SendGlobalSysMessage("DB table `locales_achievement_reward` reloaded.");
706 bool ChatHandler::HandleReloadLocalesCreatureCommand(const char* /*arg*/)
708 sLog
.outString( "Re-Loading Locales Creature ...");
709 objmgr
.LoadCreatureLocales();
710 SendGlobalSysMessage("DB table `locales_creature` reloaded.");
714 bool ChatHandler::HandleReloadLocalesGameobjectCommand(const char* /*arg*/)
716 sLog
.outString( "Re-Loading Locales Gameobject ... ");
717 objmgr
.LoadGameObjectLocales();
718 SendGlobalSysMessage("DB table `locales_gameobject` reloaded.");
722 bool ChatHandler::HandleReloadLocalesItemCommand(const char* /*arg*/)
724 sLog
.outString( "Re-Loading Locales Item ... ");
725 objmgr
.LoadItemLocales();
726 SendGlobalSysMessage("DB table `locales_item` reloaded.");
730 bool ChatHandler::HandleReloadLocalesNpcTextCommand(const char* /*arg*/)
732 sLog
.outString( "Re-Loading Locales NPC Text ... ");
733 objmgr
.LoadNpcTextLocales();
734 SendGlobalSysMessage("DB table `locales_npc_text` reloaded.");
738 bool ChatHandler::HandleReloadLocalesPageTextCommand(const char* /*arg*/)
740 sLog
.outString( "Re-Loading Locales Page Text ... ");
741 objmgr
.LoadPageTextLocales();
742 SendGlobalSysMessage("DB table `locales_page_text` reloaded.");
746 bool ChatHandler::HandleReloadLocalesPointsOfInterestCommand(const char* /*arg*/)
748 sLog
.outString( "Re-Loading Locales Points Of Interest ... ");
749 objmgr
.LoadPointOfInterestLocales();
750 SendGlobalSysMessage("DB table `locales_points_of_interest` reloaded.");
754 bool ChatHandler::HandleReloadLocalesQuestCommand(const char* /*arg*/)
756 sLog
.outString( "Re-Loading Locales Quest ... ");
757 objmgr
.LoadQuestLocales();
758 SendGlobalSysMessage("DB table `locales_quest` reloaded.");
762 bool ChatHandler::HandleLoadScriptsCommand(const char* args
)
764 if(!LoadScriptingModule(args
)) return true;
766 sWorld
.SendWorldText(LANG_SCRIPTS_RELOADED
);
770 bool ChatHandler::HandleAccountSetGmLevelCommand(const char* args
)
772 char* arg1
= strtok((char*)args
, " ");
776 /// must be NULL if targeted syntax and must be not nULL if not targeted
777 char* arg2
= strtok(NULL
, " ");
779 std::string targetAccountName
;
780 uint32 targetAccountId
= 0;
782 /// only target player different from self allowed (if targetPlayer!=NULL then not console)
783 Player
* targetPlayer
= getSelectedPlayer();
784 if(targetPlayer
&& m_session
->GetPlayer()!=targetPlayer
)
786 /// wrong command syntax or unexpected targeting
790 /// security level expected in arg2 after this if.
793 targetAccountId
= targetPlayer
->GetSession()->GetAccountId();
794 accmgr
.GetName(targetAccountId
, targetAccountName
);
798 /// wrong command syntax (second arg expected)
802 targetAccountName
= arg1
;
803 if(!AccountMgr::normilizeString(targetAccountName
))
805 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,targetAccountName
.c_str());
806 SetSentErrorMessage(true);
810 targetAccountId
= accmgr
.GetId(targetAccountName
);
813 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,targetAccountName
.c_str());
814 SetSentErrorMessage(true);
819 int32 gm
= (int32
)atoi(arg2
);
820 if ( gm
< SEC_PLAYER
|| gm
> SEC_ADMINISTRATOR
)
822 SendSysMessage(LANG_BAD_VALUE
);
823 SetSentErrorMessage(true);
827 /// can set security level only for target with less security and to less security that we have
828 /// This will reject self apply by specify account name
829 if(HasLowerSecurityAccount(NULL
,targetAccountId
,true))
832 /// account can't set security to same or grater level, need more power GM or console
833 uint32 plSecurity
= m_session
? m_session
->GetSecurity() : SEC_CONSOLE
;
834 if (uint32(gm
) >= plSecurity
)
836 SendSysMessage(LANG_YOURS_SECURITY_IS_LOW
);
837 SetSentErrorMessage(true);
841 // This will prevent self apply by self target or no target
842 if(targetPlayer
&& m_session
->GetPlayer()!=targetPlayer
)
844 ChatHandler(targetPlayer
).PSendSysMessage(LANG_YOURS_SECURITY_CHANGED
,GetNameLink().c_str(), gm
);
845 targetPlayer
->GetSession()->SetSecurity(gm
);
848 PSendSysMessage(LANG_YOU_CHANGE_SECURITY
, targetAccountName
.c_str(), gm
);
849 loginDatabase
.PExecute("UPDATE account SET gmlevel = '%i' WHERE id = '%u'", gm
, targetAccountId
);
854 /// Set password for account
855 bool ChatHandler::HandleAccountSetPasswordCommand(const char* args
)
860 ///- Get the command line arguments
861 char *szAccount
= strtok ((char*)args
," ");
862 char *szPassword1
= strtok (NULL
," ");
863 char *szPassword2
= strtok (NULL
," ");
865 if (!szAccount
||!szPassword1
|| !szPassword2
)
868 std::string account_name
= szAccount
;
869 if(!AccountMgr::normilizeString(account_name
))
871 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
872 SetSentErrorMessage(true);
876 uint32 targetAccountId
= accmgr
.GetId(account_name
);
877 if (!targetAccountId
)
879 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
880 SetSentErrorMessage(true);
884 /// can set password only for target with less security
885 /// This is also reject self apply in fact
886 if(HasLowerSecurityAccount (NULL
,targetAccountId
,true))
889 if (strcmp(szPassword1
,szPassword2
))
891 SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH
);
892 SetSentErrorMessage (true);
896 AccountOpResult result
= accmgr
.ChangePassword(targetAccountId
, szPassword1
);
901 SendSysMessage(LANG_COMMAND_PASSWORD
);
903 case AOR_NAME_NOT_EXIST
:
904 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
905 SetSentErrorMessage(true);
907 case AOR_PASS_TOO_LONG
:
908 SendSysMessage(LANG_PASSWORD_TOO_LONG
);
909 SetSentErrorMessage(true);
912 SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD
);
913 SetSentErrorMessage(true);
920 bool ChatHandler::HandleMaxSkillCommand(const char* /*args*/)
922 Player
* SelectedPlayer
= getSelectedPlayer();
925 SendSysMessage(LANG_NO_CHAR_SELECTED
);
926 SetSentErrorMessage(true);
930 // each skills that have max skill value dependent from level seted to current level max skill value
931 SelectedPlayer
->UpdateSkillsToMaxSkillsForLevel();
935 bool ChatHandler::HandleSetSkillCommand(const char* args
)
937 // number or [name] Shift-click form |color|Hskill:skill_id|h[name]|h|r
938 char* skill_p
= extractKeyFromLink((char*)args
,"Hskill");
942 char *level_p
= strtok (NULL
, " ");
947 char *max_p
= strtok (NULL
, " ");
949 int32 skill
= atoi(skill_p
);
952 PSendSysMessage(LANG_INVALID_SKILL_ID
, skill
);
953 SetSentErrorMessage(true);
957 int32 level
= atol (level_p
);
959 Player
* target
= getSelectedPlayer();
962 SendSysMessage(LANG_NO_CHAR_SELECTED
);
963 SetSentErrorMessage(true);
967 SkillLineEntry
const* sl
= sSkillLineStore
.LookupEntry(skill
);
970 PSendSysMessage(LANG_INVALID_SKILL_ID
, skill
);
971 SetSentErrorMessage(true);
975 std::string tNameLink
= GetNameLink(target
);
977 if(!target
->GetSkillValue(skill
))
979 PSendSysMessage(LANG_SET_SKILL_ERROR
, tNameLink
.c_str(), skill
, sl
->name
[0]);
980 SetSentErrorMessage(true);
984 int32 max
= max_p
? atol (max_p
) : target
->GetPureMaxSkillValue(skill
);
986 if( level
<= 0 || level
> max
|| max
<= 0 )
989 target
->SetSkill(skill
, level
, max
);
990 PSendSysMessage(LANG_SET_SKILL
, skill
, sl
->name
[0], tNameLink
.c_str(), level
, max
);
995 bool ChatHandler::HandleUnLearnCommand(const char* args
)
1000 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
1001 uint32 spell_id
= extractSpellIdFromLink((char*)args
);
1005 char const* allStr
= strtok(NULL
," ");
1006 bool allRanks
= allStr
? (strncmp(allStr
, "all", strlen(allStr
)) == 0) : false;
1008 Player
* target
= getSelectedPlayer();
1011 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1012 SetSentErrorMessage(true);
1017 spell_id
= spellmgr
.GetFirstSpellInChain (spell_id
);
1019 if (target
->HasSpell(spell_id
))
1020 target
->removeSpell(spell_id
,false,!allRanks
);
1022 SendSysMessage(LANG_FORGET_SPELL
);
1027 bool ChatHandler::HandleCooldownCommand(const char* args
)
1029 Player
* target
= getSelectedPlayer();
1032 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1033 SetSentErrorMessage(true);
1037 std::string tNameLink
= GetNameLink(target
);
1041 target
->RemoveAllSpellCooldown();
1042 PSendSysMessage(LANG_REMOVEALL_COOLDOWN
, tNameLink
.c_str());
1046 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1047 uint32 spell_id
= extractSpellIdFromLink((char*)args
);
1051 if(!sSpellStore
.LookupEntry(spell_id
))
1053 PSendSysMessage(LANG_UNKNOWN_SPELL
, target
==m_session
->GetPlayer() ? GetMangosString(LANG_YOU
) : tNameLink
.c_str());
1054 SetSentErrorMessage(true);
1058 WorldPacket
data( SMSG_CLEAR_COOLDOWN
, (4+8) );
1059 data
<< uint32(spell_id
);
1060 data
<< uint64(target
->GetGUID());
1061 target
->GetSession()->SendPacket(&data
);
1062 target
->RemoveSpellCooldown(spell_id
);
1063 PSendSysMessage(LANG_REMOVE_COOLDOWN
, spell_id
, target
==m_session
->GetPlayer() ? GetMangosString(LANG_YOU
) : tNameLink
.c_str());
1068 bool ChatHandler::HandleLearnAllCommand(const char* /*args*/)
1070 static const char *allSpellList
[] =
1453 //"9036", problems with ghost state
1462 //"6718", phasing stealth, annoying for learn all case.
1675 while(strcmp(allSpellList
[loop
], "0"))
1677 uint32 spell
= atol((char*)allSpellList
[loop
++]);
1679 if (m_session
->GetPlayer()->HasSpell(spell
))
1682 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1683 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1685 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1689 m_session
->GetPlayer()->learnSpell(spell
,false);
1692 SendSysMessage(LANG_COMMAND_LEARN_MANY_SPELLS
);
1697 bool ChatHandler::HandleLearnAllGMCommand(const char* /*args*/)
1699 static const char *gmSpellList
[] =
1701 "24347", // Become A Fish, No Breath Bar
1702 "35132", // Visual Boom
1703 "38488", // Attack 4000-8000 AOE
1704 "38795", // Attack 2000 AOE + Slow Down 90%
1705 "15712", // Attack 200
1706 "1852", // GM Spell Silence
1709 "29878", // Kill My Self
1710 "26644", // More Kill
1712 "28550", //Invisible 24
1713 "23452", //Invisible + Target
1717 uint16 gmSpellIter
= 0;
1718 while( strcmp(gmSpellList
[gmSpellIter
], "0") )
1720 uint32 spell
= atol((char*)gmSpellList
[gmSpellIter
++]);
1722 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1723 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1725 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1729 m_session
->GetPlayer()->learnSpell(spell
,false);
1732 SendSysMessage(LANG_LEARNING_GM_SKILLS
);
1736 bool ChatHandler::HandleLearnAllMyClassCommand(const char* /*args*/)
1738 HandleLearnAllMySpellsCommand("");
1739 HandleLearnAllMyTalentsCommand("");
1743 bool ChatHandler::HandleLearnAllMySpellsCommand(const char* /*args*/)
1745 ChrClassesEntry
const* clsEntry
= sChrClassesStore
.LookupEntry(m_session
->GetPlayer()->getClass());
1748 uint32 family
= clsEntry
->spellfamily
;
1750 for (uint32 i
= 0; i
< sSpellStore
.GetNumRows(); i
++)
1752 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(i
);
1756 // skip server-side/triggered spells
1757 if(spellInfo
->spellLevel
==0)
1760 // skip wrong class/race skills
1761 if(!m_session
->GetPlayer()->IsSpellFitByClassAndRace(spellInfo
->Id
))
1764 // skip other spell families
1765 if( spellInfo
->SpellFamilyName
!= family
)
1768 // skip spells with first rank learned as talent (and all talents then also)
1769 uint32 first_rank
= spellmgr
.GetFirstSpellInChain(spellInfo
->Id
);
1770 if(GetTalentSpellCost(first_rank
) > 0 )
1773 // skip broken spells
1774 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1777 m_session
->GetPlayer()->learnSpell(i
,false);
1780 SendSysMessage(LANG_COMMAND_LEARN_CLASS_SPELLS
);
1784 bool ChatHandler::HandleLearnAllMyTalentsCommand(const char* /*args*/)
1786 Player
* player
= m_session
->GetPlayer();
1787 uint32 classMask
= player
->getClassMask();
1789 for (uint32 i
= 0; i
< sTalentStore
.GetNumRows(); i
++)
1791 TalentEntry
const *talentInfo
= sTalentStore
.LookupEntry(i
);
1795 TalentTabEntry
const *talentTabInfo
= sTalentTabStore
.LookupEntry( talentInfo
->TalentTab
);
1799 if( (classMask
& talentTabInfo
->ClassMask
) == 0 )
1802 // search highest talent rank
1805 for(int rank
= MAX_TALENT_RANK
-1; rank
>= 0; --rank
)
1807 if(talentInfo
->RankID
[rank
]!=0)
1809 spellid
= talentInfo
->RankID
[rank
];
1814 if(!spellid
) // ??? none spells in talent
1817 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spellid
);
1818 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1821 // learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
1822 player
->learnSpellHighRank(spellid
);
1825 SendSysMessage(LANG_COMMAND_LEARN_CLASS_TALENTS
);
1829 bool ChatHandler::HandleLearnAllMyPetTalentsCommand(const char* /*args*/)
1831 Player
* player
= m_session
->GetPlayer();
1833 Pet
* pet
= player
->GetPet();
1836 SendSysMessage(LANG_NO_PET_FOUND
);
1837 SetSentErrorMessage(true);
1841 CreatureInfo
const *ci
= pet
->GetCreatureInfo();
1844 SendSysMessage(LANG_WRONG_PET_TYPE
);
1845 SetSentErrorMessage(true);
1849 CreatureFamilyEntry
const *pet_family
= sCreatureFamilyStore
.LookupEntry(ci
->family
);
1852 SendSysMessage(LANG_WRONG_PET_TYPE
);
1853 SetSentErrorMessage(true);
1857 if(pet_family
->petTalentType
< 0) // not hunter pet
1859 SendSysMessage(LANG_WRONG_PET_TYPE
);
1860 SetSentErrorMessage(true);
1864 for (uint32 i
= 0; i
< sTalentStore
.GetNumRows(); i
++)
1866 TalentEntry
const *talentInfo
= sTalentStore
.LookupEntry(i
);
1870 TalentTabEntry
const *talentTabInfo
= sTalentTabStore
.LookupEntry( talentInfo
->TalentTab
);
1874 // prevent learn talent for different family (cheating)
1875 if(((1 << pet_family
->petTalentType
) & talentTabInfo
->petTalentMask
)==0)
1878 // search highest talent rank
1881 for(int rank
= MAX_TALENT_RANK
-1; rank
>= 0; --rank
)
1883 if(talentInfo
->RankID
[rank
]!=0)
1885 spellid
= talentInfo
->RankID
[rank
];
1890 if(!spellid
) // ??? none spells in talent
1893 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spellid
);
1894 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1897 // learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
1898 pet
->learnSpellHighRank(spellid
);
1901 SendSysMessage(LANG_COMMAND_LEARN_PET_TALENTS
);
1905 bool ChatHandler::HandleLearnAllLangCommand(const char* /*args*/)
1907 // skipping UNIVERSAL language (0)
1908 for(int i
= 1; i
< LANGUAGES_COUNT
; ++i
)
1909 m_session
->GetPlayer()->learnSpell(lang_description
[i
].spell_id
,false);
1911 SendSysMessage(LANG_COMMAND_LEARN_ALL_LANG
);
1915 bool ChatHandler::HandleLearnAllDefaultCommand(const char* args
)
1917 Player
*player
= NULL
;
1920 std::string name
= extractPlayerNameFromLink((char*)args
);
1923 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1924 SetSentErrorMessage(true);
1928 player
= objmgr
.GetPlayer(name
.c_str());
1931 player
= getSelectedPlayer();
1935 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1936 SetSentErrorMessage(true);
1940 player
->learnDefaultSpells();
1941 player
->learnQuestRewardedSpells();
1943 PSendSysMessage(LANG_COMMAND_LEARN_ALL_DEFAULT_AND_QUEST
,GetNameLink(player
).c_str());
1947 bool ChatHandler::HandleLearnCommand(const char* args
)
1949 Player
* targetPlayer
= getSelectedPlayer();
1953 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1954 SetSentErrorMessage(true);
1958 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1959 uint32 spell
= extractSpellIdFromLink((char*)args
);
1960 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
1963 char const* allStr
= strtok(NULL
," ");
1964 bool allRanks
= allStr
? (strncmp(allStr
, "all", strlen(allStr
)) == 0) : false;
1966 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1967 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1969 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1970 SetSentErrorMessage(true);
1974 if (!allRanks
&& targetPlayer
->HasSpell(spell
))
1976 if(targetPlayer
== m_session
->GetPlayer())
1977 SendSysMessage(LANG_YOU_KNOWN_SPELL
);
1979 PSendSysMessage(LANG_TARGET_KNOWN_SPELL
,GetNameLink(targetPlayer
).c_str());
1980 SetSentErrorMessage(true);
1985 targetPlayer
->learnSpellHighRank(spell
);
1987 targetPlayer
->learnSpell(spell
,false);
1992 bool ChatHandler::HandleAddItemCommand(const char* args
)
1999 if(args
[0]=='[') // [name] manual form
2001 char* citemName
= citemName
= strtok((char*)args
, "]");
2003 if(citemName
&& citemName
[0])
2005 std::string itemName
= citemName
+1;
2006 WorldDatabase
.escape_string(itemName
);
2007 QueryResult
*result
= WorldDatabase
.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName
.c_str());
2010 PSendSysMessage(LANG_COMMAND_COULDNOTFIND
, citemName
+1);
2011 SetSentErrorMessage(true);
2014 itemId
= result
->Fetch()->GetUInt16();
2020 else // item_id or [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r
2022 char* cId
= extractKeyFromLink((char*)args
,"Hitem");
2028 char* ccount
= strtok(NULL
, " ");
2033 count
= strtol(ccount
, NULL
, 10);
2038 Player
* pl
= m_session
->GetPlayer();
2039 Player
* plTarget
= getSelectedPlayer();
2043 sLog
.outDetail(GetMangosString(LANG_ADDITEM
), itemId
, count
);
2045 ItemPrototype
const *pProto
= objmgr
.GetItemPrototype(itemId
);
2048 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, itemId
);
2049 SetSentErrorMessage(true);
2056 plTarget
->DestroyItemCount(itemId
, -count
, true, false);
2057 PSendSysMessage(LANG_REMOVEITEM
, itemId
, -count
, GetNameLink(plTarget
).c_str());
2062 uint32 noSpaceForCount
= 0;
2064 // check space and find places
2065 ItemPosCountVec dest
;
2066 uint8 msg
= plTarget
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, itemId
, count
, &noSpaceForCount
);
2067 if( msg
!= EQUIP_ERR_OK
) // convert to possible store amount
2068 count
-= noSpaceForCount
;
2070 if( count
== 0 || dest
.empty()) // can't add any
2072 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, itemId
, noSpaceForCount
);
2073 SetSentErrorMessage(true);
2077 Item
* item
= plTarget
->StoreNewItem( dest
, itemId
, true, Item::GenerateItemRandomPropertyId(itemId
));
2079 // remove binding (let GM give it to another player later)
2081 for(ItemPosCountVec::const_iterator itr
= dest
.begin(); itr
!= dest
.end(); ++itr
)
2082 if(Item
* item1
= pl
->GetItemByPos(itr
->pos
))
2083 item1
->SetBinding( false );
2085 if(count
> 0 && item
)
2087 pl
->SendNewItem(item
,count
,false,true);
2089 plTarget
->SendNewItem(item
,count
,true,false);
2092 if(noSpaceForCount
> 0)
2093 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, itemId
, noSpaceForCount
);
2098 bool ChatHandler::HandleAddItemSetCommand(const char* args
)
2103 char* cId
= extractKeyFromLink((char*)args
,"Hitemset"); // number or [name] Shift-click form |color|Hitemset:itemset_id|h[name]|h|r
2107 uint32 itemsetId
= atol(cId
);
2109 // prevent generation all items with itemset field value '0'
2112 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND
,itemsetId
);
2113 SetSentErrorMessage(true);
2117 Player
* pl
= m_session
->GetPlayer();
2118 Player
* plTarget
= getSelectedPlayer();
2122 sLog
.outDetail(GetMangosString(LANG_ADDITEMSET
), itemsetId
);
2125 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
2127 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
2131 if (pProto
->ItemSet
== itemsetId
)
2134 ItemPosCountVec dest
;
2135 uint8 msg
= plTarget
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, pProto
->ItemId
, 1 );
2136 if (msg
== EQUIP_ERR_OK
)
2138 Item
* item
= plTarget
->StoreNewItem( dest
, pProto
->ItemId
, true);
2140 // remove binding (let GM give it to another player later)
2142 item
->SetBinding( false );
2144 pl
->SendNewItem(item
,1,false,true);
2146 plTarget
->SendNewItem(item
,1,true,false);
2150 pl
->SendEquipError( msg
, NULL
, NULL
);
2151 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, pProto
->ItemId
, 1);
2158 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND
,itemsetId
);
2160 SetSentErrorMessage(true);
2167 bool ChatHandler::HandleListItemCommand(const char* args
)
2172 char* cId
= extractKeyFromLink((char*)args
,"Hitem");
2176 uint32 item_id
= atol(cId
);
2179 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
2180 SetSentErrorMessage(true);
2184 ItemPrototype
const* itemProto
= objmgr
.GetItemPrototype(item_id
);
2187 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
2188 SetSentErrorMessage(true);
2192 char* c_count
= strtok(NULL
, " ");
2193 int count
= c_count
? atol(c_count
) : 10;
2198 QueryResult
*result
;
2201 uint32 inv_count
= 0;
2202 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM character_inventory WHERE item_template='%u'",item_id
);
2205 inv_count
= (*result
)[0].GetUInt32();
2209 result
=CharacterDatabase
.PQuery(
2211 "SELECT ci.item, cibag.slot AS bag, ci.slot, ci.guid, characters.account,characters.name "
2212 "FROM character_inventory AS ci LEFT JOIN character_inventory AS cibag ON (cibag.item=ci.bag),characters "
2213 "WHERE ci.item_template='%u' AND ci.guid = characters.guid LIMIT %u ",
2214 item_id
,uint32(count
));
2220 Field
*fields
= result
->Fetch();
2221 uint32 item_guid
= fields
[0].GetUInt32();
2222 uint32 item_bag
= fields
[1].GetUInt32();
2223 uint32 item_slot
= fields
[2].GetUInt32();
2224 uint32 owner_guid
= fields
[3].GetUInt32();
2225 uint32 owner_acc
= fields
[4].GetUInt32();
2226 std::string owner_name
= fields
[5].GetCppString();
2228 char const* item_pos
= 0;
2229 if(Player::IsEquipmentPos(item_bag
,item_slot
))
2230 item_pos
= "[equipped]";
2231 else if(Player::IsInventoryPos(item_bag
,item_slot
))
2232 item_pos
= "[in inventory]";
2233 else if(Player::IsBankPos(item_bag
,item_slot
))
2234 item_pos
= "[in bank]";
2238 PSendSysMessage(LANG_ITEMLIST_SLOT
,
2239 item_guid
,owner_name
.c_str(),owner_guid
,owner_acc
,item_pos
);
2240 } while (result
->NextRow());
2242 int64 res_count
= result
->GetRowCount();
2246 if(count
> res_count
)
2253 uint32 mail_count
= 0;
2254 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM mail_items WHERE item_template='%u'", item_id
);
2257 mail_count
= (*result
)[0].GetUInt32();
2263 result
=CharacterDatabase
.PQuery(
2265 "SELECT mail_items.item_guid, mail.sender, mail.receiver, char_s.account, char_s.name, char_r.account, char_r.name "
2266 "FROM mail,mail_items,characters as char_s,characters as char_r "
2267 "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",
2268 item_id
,uint32(count
));
2277 Field
*fields
= result
->Fetch();
2278 uint32 item_guid
= fields
[0].GetUInt32();
2279 uint32 item_s
= fields
[1].GetUInt32();
2280 uint32 item_r
= fields
[2].GetUInt32();
2281 uint32 item_s_acc
= fields
[3].GetUInt32();
2282 std::string item_s_name
= fields
[4].GetCppString();
2283 uint32 item_r_acc
= fields
[5].GetUInt32();
2284 std::string item_r_name
= fields
[6].GetCppString();
2286 char const* item_pos
= "[in mail]";
2288 PSendSysMessage(LANG_ITEMLIST_MAIL
,
2289 item_guid
,item_s_name
.c_str(),item_s
,item_s_acc
,item_r_name
.c_str(),item_r
,item_r_acc
,item_pos
);
2290 } while (result
->NextRow());
2292 int64 res_count
= result
->GetRowCount();
2296 if(count
> res_count
)
2303 uint32 auc_count
= 0;
2304 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM auctionhouse WHERE item_template='%u'",item_id
);
2307 auc_count
= (*result
)[0].GetUInt32();
2313 result
=CharacterDatabase
.PQuery(
2315 "SELECT auctionhouse.itemguid, auctionhouse.itemowner, characters.account, characters.name "
2316 "FROM auctionhouse,characters WHERE auctionhouse.item_template='%u' AND characters.guid = auctionhouse.itemowner LIMIT %u",
2317 item_id
,uint32(count
));
2326 Field
*fields
= result
->Fetch();
2327 uint32 item_guid
= fields
[0].GetUInt32();
2328 uint32 owner
= fields
[1].GetUInt32();
2329 uint32 owner_acc
= fields
[2].GetUInt32();
2330 std::string owner_name
= fields
[3].GetCppString();
2332 char const* item_pos
= "[in auction]";
2334 PSendSysMessage(LANG_ITEMLIST_AUCTION
, item_guid
, owner_name
.c_str(), owner
, owner_acc
,item_pos
);
2335 } while (result
->NextRow());
2341 uint32 guild_count
= 0;
2342 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_entry) FROM guild_bank_item WHERE item_entry='%u'",item_id
);
2345 guild_count
= (*result
)[0].GetUInt32();
2349 result
=CharacterDatabase
.PQuery(
2351 "SELECT gi.item_guid, gi.guildid, guild.name "
2352 "FROM guild_bank_item AS gi, guild WHERE gi.item_entry='%u' AND gi.guildid = guild.guildid LIMIT %u ",
2353 item_id
,uint32(count
));
2359 Field
*fields
= result
->Fetch();
2360 uint32 item_guid
= fields
[0].GetUInt32();
2361 uint32 guild_guid
= fields
[1].GetUInt32();
2362 std::string guild_name
= fields
[2].GetCppString();
2364 char const* item_pos
= "[in guild bank]";
2366 PSendSysMessage(LANG_ITEMLIST_GUILD
,item_guid
,guild_name
.c_str(),guild_guid
,item_pos
);
2367 } while (result
->NextRow());
2369 int64 res_count
= result
->GetRowCount();
2373 if(count
> res_count
)
2379 if(inv_count
+mail_count
+auc_count
+guild_count
== 0)
2381 SendSysMessage(LANG_COMMAND_NOITEMFOUND
);
2382 SetSentErrorMessage(true);
2386 PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE
,item_id
,inv_count
+mail_count
+auc_count
+guild_count
,inv_count
,mail_count
,auc_count
,guild_count
);
2391 bool ChatHandler::HandleListObjectCommand(const char* args
)
2396 // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2397 char* cId
= extractKeyFromLink((char*)args
,"Hgameobject_entry");
2401 uint32 go_id
= atol(cId
);
2404 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID
, go_id
);
2405 SetSentErrorMessage(true);
2409 GameObjectInfo
const * gInfo
= objmgr
.GetGameObjectInfo(go_id
);
2412 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID
, go_id
);
2413 SetSentErrorMessage(true);
2417 char* c_count
= strtok(NULL
, " ");
2418 int count
= c_count
? atol(c_count
) : 10;
2423 QueryResult
*result
;
2425 uint32 obj_count
= 0;
2426 result
=WorldDatabase
.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'",go_id
);
2429 obj_count
= (*result
)[0].GetUInt32();
2435 Player
* pl
= m_session
->GetPlayer();
2436 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",
2437 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(),go_id
,uint32(count
));
2440 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map FROM gameobject WHERE id = '%u' LIMIT %u",
2441 go_id
,uint32(count
));
2447 Field
*fields
= result
->Fetch();
2448 uint32 guid
= fields
[0].GetUInt32();
2449 float x
= fields
[1].GetFloat();
2450 float y
= fields
[2].GetFloat();
2451 float z
= fields
[3].GetFloat();
2452 int mapid
= fields
[4].GetUInt16();
2455 PSendSysMessage(LANG_GO_LIST_CHAT
, guid
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2457 PSendSysMessage(LANG_GO_LIST_CONSOLE
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2458 } while (result
->NextRow());
2463 PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE
,go_id
,obj_count
);
2467 bool ChatHandler::HandleListCreatureCommand(const char* args
)
2472 // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
2473 char* cId
= extractKeyFromLink((char*)args
,"Hcreature_entry");
2477 uint32 cr_id
= atol(cId
);
2480 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID
, cr_id
);
2481 SetSentErrorMessage(true);
2485 CreatureInfo
const* cInfo
= objmgr
.GetCreatureTemplate(cr_id
);
2488 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID
, cr_id
);
2489 SetSentErrorMessage(true);
2493 char* c_count
= strtok(NULL
, " ");
2494 int count
= c_count
? atol(c_count
) : 10;
2499 QueryResult
*result
;
2501 uint32 cr_count
= 0;
2502 result
=WorldDatabase
.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'",cr_id
);
2505 cr_count
= (*result
)[0].GetUInt32();
2511 Player
* pl
= m_session
->GetPlayer();
2512 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",
2513 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(), cr_id
,uint32(count
));
2516 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '%u' LIMIT %u",
2517 cr_id
,uint32(count
));
2523 Field
*fields
= result
->Fetch();
2524 uint32 guid
= fields
[0].GetUInt32();
2525 float x
= fields
[1].GetFloat();
2526 float y
= fields
[2].GetFloat();
2527 float z
= fields
[3].GetFloat();
2528 int mapid
= fields
[4].GetUInt16();
2531 PSendSysMessage(LANG_CREATURE_LIST_CHAT
, guid
, guid
, cInfo
->Name
, x
, y
, z
, mapid
);
2533 PSendSysMessage(LANG_CREATURE_LIST_CONSOLE
, guid
, cInfo
->Name
, x
, y
, z
, mapid
);
2534 } while (result
->NextRow());
2539 PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE
,cr_id
,cr_count
);
2543 bool ChatHandler::HandleLookupItemCommand(const char* args
)
2548 std::string namepart
= args
;
2549 std::wstring wnamepart
;
2551 // converting string that we try to find to lower case
2552 if(!Utf8toWStr(namepart
,wnamepart
))
2555 wstrToLower(wnamepart
);
2559 // Search in `item_template`
2560 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
2562 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
2566 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2569 ItemLocale
const *il
= objmgr
.GetItemLocale(pProto
->ItemId
);
2572 if (il
->Name
.size() > loc_idx
&& !il
->Name
[loc_idx
].empty())
2574 std::string name
= il
->Name
[loc_idx
];
2576 if (Utf8FitTo(name
, wnamepart
))
2579 PSendSysMessage(LANG_ITEM_LIST_CHAT
, id
, id
, name
.c_str());
2581 PSendSysMessage(LANG_ITEM_LIST_CONSOLE
, id
, name
.c_str());
2589 std::string name
= pProto
->Name1
;
2593 if (Utf8FitTo(name
, wnamepart
))
2596 PSendSysMessage(LANG_ITEM_LIST_CHAT
, id
, id
, name
.c_str());
2598 PSendSysMessage(LANG_ITEM_LIST_CONSOLE
, id
, name
.c_str());
2604 SendSysMessage(LANG_COMMAND_NOITEMFOUND
);
2609 bool ChatHandler::HandleLookupItemSetCommand(const char* args
)
2614 std::string namepart
= args
;
2615 std::wstring wnamepart
;
2617 if(!Utf8toWStr(namepart
,wnamepart
))
2620 // converting string that we try to find to lower case
2621 wstrToLower( wnamepart
);
2623 uint32 counter
= 0; // Counter for figure out that we found smth.
2625 // Search in ItemSet.dbc
2626 for (uint32 id
= 0; id
< sItemSetStore
.GetNumRows(); id
++)
2628 ItemSetEntry
const *set
= sItemSetStore
.LookupEntry(id
);
2631 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
2632 std::string name
= set
->name
[loc
];
2636 if (!Utf8FitTo(name
, wnamepart
))
2639 for(; loc
< MAX_LOCALE
; ++loc
)
2641 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
2644 name
= set
->name
[loc
];
2648 if (Utf8FitTo(name
, wnamepart
))
2653 if(loc
< MAX_LOCALE
)
2655 // send item set in "id - [namedlink locale]" format
2657 PSendSysMessage(LANG_ITEMSET_LIST_CHAT
,id
,id
,name
.c_str(),localeNames
[loc
]);
2659 PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE
,id
,name
.c_str(),localeNames
[loc
]);
2664 if (counter
== 0) // if counter == 0 then we found nth
2665 SendSysMessage(LANG_COMMAND_NOITEMSETFOUND
);
2669 bool ChatHandler::HandleLookupSkillCommand(const char* args
)
2674 // can be NULL in console call
2675 Player
* target
= getSelectedPlayer();
2677 std::string namepart
= args
;
2678 std::wstring wnamepart
;
2680 if(!Utf8toWStr(namepart
,wnamepart
))
2683 // converting string that we try to find to lower case
2684 wstrToLower( wnamepart
);
2686 uint32 counter
= 0; // Counter for figure out that we found smth.
2688 // Search in SkillLine.dbc
2689 for (uint32 id
= 0; id
< sSkillLineStore
.GetNumRows(); id
++)
2691 SkillLineEntry
const *skillInfo
= sSkillLineStore
.LookupEntry(id
);
2694 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
2695 std::string name
= skillInfo
->name
[loc
];
2699 if (!Utf8FitTo(name
, wnamepart
))
2702 for(; loc
< MAX_LOCALE
; ++loc
)
2704 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
2707 name
= skillInfo
->name
[loc
];
2711 if (Utf8FitTo(name
, wnamepart
))
2716 if(loc
< MAX_LOCALE
)
2718 char valStr
[50] = "";
2719 char const* knownStr
= "";
2720 if(target
&& target
->HasSkill(id
))
2722 knownStr
= GetMangosString(LANG_KNOWN
);
2723 uint32 curValue
= target
->GetPureSkillValue(id
);
2724 uint32 maxValue
= target
->GetPureMaxSkillValue(id
);
2725 uint32 permValue
= target
->GetSkillPermBonusValue(id
);
2726 uint32 tempValue
= target
->GetSkillTempBonusValue(id
);
2728 char const* valFormat
= GetMangosString(LANG_SKILL_VALUES
);
2729 snprintf(valStr
,50,valFormat
,curValue
,maxValue
,permValue
,tempValue
);
2732 // send skill in "id - [namedlink locale]" format
2734 PSendSysMessage(LANG_SKILL_LIST_CHAT
,id
,id
,name
.c_str(),localeNames
[loc
],knownStr
,valStr
);
2736 PSendSysMessage(LANG_SKILL_LIST_CONSOLE
,id
,name
.c_str(),localeNames
[loc
],knownStr
,valStr
);
2742 if (counter
== 0) // if counter == 0 then we found nth
2743 SendSysMessage(LANG_COMMAND_NOSKILLFOUND
);
2747 bool ChatHandler::HandleLookupSpellCommand(const char* args
)
2752 // can be NULL at console call
2753 Player
* target
= getSelectedPlayer();
2755 std::string namepart
= args
;
2756 std::wstring wnamepart
;
2758 if(!Utf8toWStr(namepart
,wnamepart
))
2761 // converting string that we try to find to lower case
2762 wstrToLower( wnamepart
);
2764 uint32 counter
= 0; // Counter for figure out that we found smth.
2766 // Search in Spell.dbc
2767 for (uint32 id
= 0; id
< sSpellStore
.GetNumRows(); id
++)
2769 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(id
);
2772 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
2773 std::string name
= spellInfo
->SpellName
[loc
];
2777 if (!Utf8FitTo(name
, wnamepart
))
2780 for(; loc
< MAX_LOCALE
; ++loc
)
2782 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
2785 name
= spellInfo
->SpellName
[loc
];
2789 if (Utf8FitTo(name
, wnamepart
))
2794 if(loc
< MAX_LOCALE
)
2796 bool known
= target
&& target
->HasSpell(id
);
2797 bool learn
= (spellInfo
->Effect
[0] == SPELL_EFFECT_LEARN_SPELL
);
2799 uint32 talentCost
= GetTalentSpellCost(id
);
2801 bool talent
= (talentCost
> 0);
2802 bool passive
= IsPassiveSpell(id
);
2803 bool active
= target
&& target
->HasAura(id
);
2805 // unit32 used to prevent interpreting uint8 as char at output
2806 // find rank of learned spell for learning spell, or talent rank
2807 uint32 rank
= talentCost
? talentCost
: spellmgr
.GetSpellRank(learn
? spellInfo
->EffectTriggerSpell
[0] : id
);
2809 // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
2810 std::ostringstream ss
;
2812 ss
<< id
<< " - |cffffffff|Hspell:" << id
<< "|h[" << name
;
2814 ss
<< id
<< " - " << name
;
2816 // include rank in link name
2818 ss
<< GetMangosString(LANG_SPELL_RANK
) << rank
;
2821 ss
<< " " << localeNames
[loc
] << "]|h|r";
2823 ss
<< " " << localeNames
[loc
];
2826 ss
<< GetMangosString(LANG_TALENT
);
2828 ss
<< GetMangosString(LANG_PASSIVE
);
2830 ss
<< GetMangosString(LANG_LEARN
);
2832 ss
<< GetMangosString(LANG_KNOWN
);
2834 ss
<< GetMangosString(LANG_ACTIVE
);
2836 SendSysMessage(ss
.str().c_str());
2842 if (counter
== 0) // if counter == 0 then we found nth
2843 SendSysMessage(LANG_COMMAND_NOSPELLFOUND
);
2847 bool ChatHandler::HandleLookupQuestCommand(const char* args
)
2852 // can be NULL at console call
2853 Player
* target
= getSelectedPlayer();
2855 std::string namepart
= args
;
2856 std::wstring wnamepart
;
2858 // converting string that we try to find to lower case
2859 if(!Utf8toWStr(namepart
,wnamepart
))
2862 wstrToLower(wnamepart
);
2864 uint32 counter
= 0 ;
2866 ObjectMgr::QuestMap
const& qTemplates
= objmgr
.GetQuestTemplates();
2867 for (ObjectMgr::QuestMap::const_iterator iter
= qTemplates
.begin(); iter
!= qTemplates
.end(); ++iter
)
2869 Quest
* qinfo
= iter
->second
;
2871 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2874 QuestLocale
const *il
= objmgr
.GetQuestLocale(qinfo
->GetQuestId());
2877 if (il
->Title
.size() > loc_idx
&& !il
->Title
[loc_idx
].empty())
2879 std::string title
= il
->Title
[loc_idx
];
2881 if (Utf8FitTo(title
, wnamepart
))
2883 char const* statusStr
= "";
2887 QuestStatus status
= target
->GetQuestStatus(qinfo
->GetQuestId());
2889 if(status
== QUEST_STATUS_COMPLETE
)
2891 if(target
->GetQuestRewardStatus(qinfo
->GetQuestId()))
2892 statusStr
= GetMangosString(LANG_COMMAND_QUEST_REWARDED
);
2894 statusStr
= GetMangosString(LANG_COMMAND_QUEST_COMPLETE
);
2896 else if(status
== QUEST_STATUS_INCOMPLETE
)
2897 statusStr
= GetMangosString(LANG_COMMAND_QUEST_ACTIVE
);
2901 PSendSysMessage(LANG_QUEST_LIST_CHAT
,qinfo
->GetQuestId(),qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2903 PSendSysMessage(LANG_QUEST_LIST_CONSOLE
,qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2911 std::string title
= qinfo
->GetTitle();
2915 if (Utf8FitTo(title
, wnamepart
))
2917 char const* statusStr
= "";
2921 QuestStatus status
= target
->GetQuestStatus(qinfo
->GetQuestId());
2923 if(status
== QUEST_STATUS_COMPLETE
)
2925 if(target
->GetQuestRewardStatus(qinfo
->GetQuestId()))
2926 statusStr
= GetMangosString(LANG_COMMAND_QUEST_REWARDED
);
2928 statusStr
= GetMangosString(LANG_COMMAND_QUEST_COMPLETE
);
2930 else if(status
== QUEST_STATUS_INCOMPLETE
)
2931 statusStr
= GetMangosString(LANG_COMMAND_QUEST_ACTIVE
);
2935 PSendSysMessage(LANG_QUEST_LIST_CHAT
,qinfo
->GetQuestId(),qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2937 PSendSysMessage(LANG_QUEST_LIST_CONSOLE
,qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2944 SendSysMessage(LANG_COMMAND_NOQUESTFOUND
);
2949 bool ChatHandler::HandleLookupCreatureCommand(const char* args
)
2954 std::string namepart
= args
;
2955 std::wstring wnamepart
;
2957 // converting string that we try to find to lower case
2958 if (!Utf8toWStr (namepart
,wnamepart
))
2961 wstrToLower (wnamepart
);
2965 for (uint32 id
= 0; id
< sCreatureStorage
.MaxEntry
; ++id
)
2967 CreatureInfo
const* cInfo
= sCreatureStorage
.LookupEntry
<CreatureInfo
> (id
);
2971 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2974 CreatureLocale
const *cl
= objmgr
.GetCreatureLocale (id
);
2977 if (cl
->Name
.size() > loc_idx
&& !cl
->Name
[loc_idx
].empty ())
2979 std::string name
= cl
->Name
[loc_idx
];
2981 if (Utf8FitTo (name
, wnamepart
))
2984 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str ());
2986 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE
, id
, name
.c_str ());
2994 std::string name
= cInfo
->Name
;
2998 if (Utf8FitTo(name
, wnamepart
))
3001 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str ());
3003 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE
, id
, name
.c_str ());
3009 SendSysMessage (LANG_COMMAND_NOCREATUREFOUND
);
3014 bool ChatHandler::HandleLookupObjectCommand(const char* args
)
3019 std::string namepart
= args
;
3020 std::wstring wnamepart
;
3022 // converting string that we try to find to lower case
3023 if(!Utf8toWStr(namepart
,wnamepart
))
3026 wstrToLower(wnamepart
);
3030 for (uint32 id
= 0; id
< sGOStorage
.MaxEntry
; id
++ )
3032 GameObjectInfo
const* gInfo
= sGOStorage
.LookupEntry
<GameObjectInfo
>(id
);
3036 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
3039 GameObjectLocale
const *gl
= objmgr
.GetGameObjectLocale(id
);
3042 if (gl
->Name
.size() > loc_idx
&& !gl
->Name
[loc_idx
].empty())
3044 std::string name
= gl
->Name
[loc_idx
];
3046 if (Utf8FitTo(name
, wnamepart
))
3049 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT
, id
, id
, name
.c_str());
3051 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE
, id
, name
.c_str());
3059 std::string name
= gInfo
->name
;
3063 if(Utf8FitTo(name
, wnamepart
))
3066 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT
, id
, id
, name
.c_str());
3068 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE
, id
, name
.c_str());
3074 SendSysMessage(LANG_COMMAND_NOGAMEOBJECTFOUND
);
3079 /** \brief GM command level 3 - Create a guild.
3081 * This command allows a GM (level 3) to create a guild.
3083 * The "args" parameter contains the name of the guild leader
3084 * and then the name of the guild.
3087 bool ChatHandler::HandleGuildCreateCommand(const char* args
)
3093 char *lname
= strtok ((char*)args
, " ");
3094 char *gname
= strtok (NULL
, "");
3101 SendSysMessage (LANG_INSERT_GUILD_NAME
);
3102 SetSentErrorMessage (true);
3106 std::string guildname
= gname
;
3108 Player
* player
= ObjectAccessor::Instance ().FindPlayerByName (lname
);
3111 SendSysMessage (LANG_PLAYER_NOT_FOUND
);
3112 SetSentErrorMessage (true);
3116 if (player
->GetGuildId())
3118 SendSysMessage (LANG_PLAYER_IN_GUILD
);
3122 Guild
*guild
= new Guild
;
3123 if (!guild
->create (player
,guildname
))
3126 SendSysMessage (LANG_GUILD_NOT_CREATED
);
3127 SetSentErrorMessage (true);
3131 objmgr
.AddGuild (guild
);
3135 bool ChatHandler::HandleGuildInviteCommand(const char *args
)
3140 char* par1
= strtok ((char*)args
, " ");
3141 char* par2
= strtok (NULL
, "");
3145 std::string glName
= par2
;
3146 Guild
* targetGuild
= objmgr
.GetGuildByName (glName
);
3150 std::string plName
= extractPlayerNameFromLink(par1
);
3153 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3154 SetSentErrorMessage(true);
3159 if (Player
* targetPlayer
= ObjectAccessor::Instance ().FindPlayerByName (plName
.c_str ()))
3160 plGuid
= targetPlayer
->GetGUID ();
3162 plGuid
= objmgr
.GetPlayerGUIDByName (plName
);
3167 // player's guild membership checked in AddMember before add
3168 if (!targetGuild
->AddMember (plGuid
,targetGuild
->GetLowestRank ()))
3174 bool ChatHandler::HandleGuildUninviteCommand(const char *args
)
3179 char* par1
= strtok ((char*)args
, " ");
3183 std::string plName
= extractPlayerNameFromLink(par1
);
3186 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3187 SetSentErrorMessage(true);
3193 if (Player
* targetPlayer
= ObjectAccessor::Instance ().FindPlayerByName (plName
.c_str ()))
3195 plGuid
= targetPlayer
->GetGUID ();
3196 glId
= targetPlayer
->GetGuildId ();
3200 plGuid
= objmgr
.GetPlayerGUIDByName (plName
);
3201 glId
= Player::GetGuildIdFromDB (plGuid
);
3204 if (!plGuid
|| !glId
)
3207 Guild
* targetGuild
= objmgr
.GetGuildById (glId
);
3211 targetGuild
->DelMember (plGuid
);
3216 bool ChatHandler::HandleGuildRankCommand(const char *args
)
3221 char* par1
= strtok ((char*)args
, " ");
3222 char* par2
= strtok (NULL
, " ");
3226 std::string plName
= extractPlayerNameFromLink(par1
);
3229 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3230 SetSentErrorMessage(true);
3237 if (Player
* targetPlayer
= ObjectAccessor::Instance ().FindPlayerByName (plName
.c_str ()))
3239 plGuid
= targetPlayer
->GetGUID ();
3240 glId
= targetPlayer
->GetGuildId ();
3244 plGuid
= objmgr
.GetPlayerGUIDByName (plName
);
3245 glId
= Player::GetGuildIdFromDB (plGuid
);
3248 if (!plGuid
|| !glId
)
3251 Guild
* targetGuild
= objmgr
.GetGuildById (glId
);
3255 uint32 newrank
= uint32 (atoi (par2
));
3256 if (newrank
> targetGuild
->GetLowestRank ())
3259 targetGuild
->ChangeRank (plGuid
,newrank
);
3264 bool ChatHandler::HandleGuildDeleteCommand(const char* args
)
3269 char* par1
= strtok ((char*)args
, " ");
3273 std::string gld
= par1
;
3275 Guild
* targetGuild
= objmgr
.GetGuildByName (gld
);
3279 targetGuild
->Disband ();
3284 bool ChatHandler::HandleGetDistanceCommand(const char* args
)
3286 WorldObject
* obj
= NULL
;
3290 uint64 guid
= extractGuidFromLink((char*)args
);
3292 obj
= (WorldObject
*)ObjectAccessor::GetObjectByTypeMask(*m_session
->GetPlayer(),guid
,TYPEMASK_UNIT
|TYPEMASK_GAMEOBJECT
);
3296 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3297 SetSentErrorMessage(true);
3303 obj
= getSelectedUnit();
3307 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3308 SetSentErrorMessage(true);
3313 PSendSysMessage(LANG_DISTANCE
, m_session
->GetPlayer()->GetDistance(obj
),m_session
->GetPlayer()->GetDistance2d(obj
));
3318 bool ChatHandler::HandleDieCommand(const char* /*args*/)
3320 Unit
* target
= getSelectedUnit();
3322 if(!target
|| !m_session
->GetPlayer()->GetSelection())
3324 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3325 SetSentErrorMessage(true);
3329 if(target
->GetTypeId()==TYPEID_PLAYER
)
3331 if(HasLowerSecurity((Player
*)target
,0,false))
3335 if( target
->isAlive() )
3337 m_session
->GetPlayer()->DealDamage(target
, target
->GetHealth(), NULL
, DIRECT_DAMAGE
, SPELL_SCHOOL_MASK_NORMAL
, NULL
, false);
3343 bool ChatHandler::HandleDamageCommand(const char * args
)
3348 Unit
* target
= getSelectedUnit();
3350 if(!target
|| !m_session
->GetPlayer()->GetSelection())
3352 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3353 SetSentErrorMessage(true);
3357 if( !target
->isAlive() )
3360 char* damageStr
= strtok((char*)args
, " ");
3364 int32 damage
= atoi((char*)damageStr
);
3368 char* schoolStr
= strtok((char*)NULL
, " ");
3370 // flat melee damage without resistence/etc reduction
3373 m_session
->GetPlayer()->DealDamage(target
, damage
, NULL
, DIRECT_DAMAGE
, SPELL_SCHOOL_MASK_NORMAL
, NULL
, false);
3374 m_session
->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2
, target
, 1, SPELL_SCHOOL_MASK_NORMAL
, damage
, 0, 0, VICTIMSTATE_NORMAL
, 0);
3378 uint32 school
= schoolStr
? atoi((char*)schoolStr
) : SPELL_SCHOOL_NORMAL
;
3379 if(school
>= MAX_SPELL_SCHOOL
)
3382 SpellSchoolMask schoolmask
= SpellSchoolMask(1 << school
);
3384 if ( schoolmask
& SPELL_SCHOOL_MASK_NORMAL
)
3385 damage
= m_session
->GetPlayer()->CalcArmorReducedDamage(target
, damage
);
3387 char* spellStr
= strtok((char*)NULL
, " ");
3389 // melee damage by specific school
3395 m_session
->GetPlayer()->CalcAbsorbResist(target
,schoolmask
, SPELL_DIRECT_DAMAGE
, damage
, &absorb
, &resist
);
3397 if (damage
<= absorb
+ resist
)
3400 damage
-= absorb
+ resist
;
3402 m_session
->GetPlayer()->DealDamage(target
, damage
, NULL
, DIRECT_DAMAGE
, schoolmask
, NULL
, false);
3403 m_session
->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2
, target
, 1, schoolmask
, damage
, absorb
, resist
, VICTIMSTATE_NORMAL
, 0);
3409 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3410 uint32 spellid
= extractSpellIdFromLink((char*)args
);
3411 if(!spellid
|| !sSpellStore
.LookupEntry(spellid
))
3414 m_session
->GetPlayer()->SpellNonMeleeDamageLog(target
, spellid
, damage
, false);
3418 bool ChatHandler::HandleModifyArenaCommand(const char * args
)
3423 Player
*target
= getSelectedPlayer();
3426 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3427 SetSentErrorMessage(true);
3431 int32 amount
= (uint32
)atoi(args
);
3433 target
->ModifyArenaPoints(amount
);
3435 PSendSysMessage(LANG_COMMAND_MODIFY_ARENA
, GetNameLink(target
).c_str(), target
->GetArenaPoints());
3440 bool ChatHandler::HandleReviveCommand(const char* args
)
3442 Player
* player
= NULL
;
3443 uint64 player_guid
= 0;
3447 std::string name
= extractPlayerNameFromLink((char*)args
);
3450 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3451 SetSentErrorMessage(true);
3455 player
= objmgr
.GetPlayer(name
.c_str());
3457 player_guid
= objmgr
.GetPlayerGUIDByName(name
);
3460 player
= getSelectedPlayer();
3464 player
->ResurrectPlayer(0.5f
);
3465 player
->SpawnCorpseBones();
3468 else if (player_guid
)
3470 // will resurrected at login without corpse
3471 ObjectAccessor::Instance().ConvertCorpseForPlayer(player_guid
);
3475 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3476 SetSentErrorMessage(true);
3483 bool ChatHandler::HandleAuraCommand(const char* args
)
3485 Unit
*target
= getSelectedUnit();
3488 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3489 SetSentErrorMessage(true);
3493 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3494 uint32 spellID
= extractSpellIdFromLink((char*)args
);
3496 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry( spellID
);
3499 for(uint32 i
= 0;i
<3;i
++)
3501 uint8 eff
= spellInfo
->Effect
[i
];
3502 if (eff
>=TOTAL_SPELL_EFFECTS
)
3504 if( IsAreaAuraEffect(eff
) ||
3505 eff
== SPELL_EFFECT_APPLY_AURA
||
3506 eff
== SPELL_EFFECT_PERSISTENT_AREA_AURA
)
3508 Aura
*Aur
= CreateAura(spellInfo
, i
, NULL
, target
);
3509 target
->AddAura(Aur
);
3517 bool ChatHandler::HandleUnAuraCommand(const char* args
)
3519 Unit
*target
= getSelectedUnit();
3522 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3523 SetSentErrorMessage(true);
3527 std::string argstr
= args
;
3528 if (argstr
== "all")
3530 target
->RemoveAllAuras();
3534 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3535 uint32 spellID
= extractSpellIdFromLink((char*)args
);
3539 target
->RemoveAurasDueToSpell(spellID
);
3544 bool ChatHandler::HandleLinkGraveCommand(const char* args
)
3549 char* px
= strtok((char*)args
, " ");
3553 uint32 g_id
= (uint32
)atoi(px
);
3557 char* px2
= strtok(NULL
, " ");
3561 else if (strncmp(px2
,"horde",6)==0)
3563 else if (strncmp(px2
,"alliance",9)==0)
3568 WorldSafeLocsEntry
const* graveyard
= sWorldSafeLocsStore
.LookupEntry(g_id
);
3572 PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST
, g_id
);
3573 SetSentErrorMessage(true);
3577 Player
* player
= m_session
->GetPlayer();
3579 uint32 zoneId
= player
->GetZoneId();
3581 AreaTableEntry
const *areaEntry
= GetAreaEntryByAreaID(zoneId
);
3582 if(!areaEntry
|| areaEntry
->zone
!=0 )
3584 PSendSysMessage(LANG_COMMAND_GRAVEYARDWRONGZONE
, g_id
,zoneId
);
3585 SetSentErrorMessage(true);
3589 if(objmgr
.AddGraveYardLink(g_id
,zoneId
,g_team
))
3590 PSendSysMessage(LANG_COMMAND_GRAVEYARDLINKED
, g_id
,zoneId
);
3592 PSendSysMessage(LANG_COMMAND_GRAVEYARDALRLINKED
, g_id
,zoneId
);
3597 bool ChatHandler::HandleNearGraveCommand(const char* args
)
3601 size_t argslen
= strlen(args
);
3605 else if (strncmp((char*)args
,"horde",argslen
)==0)
3607 else if (strncmp((char*)args
,"alliance",argslen
)==0)
3612 Player
* player
= m_session
->GetPlayer();
3613 uint32 zone_id
= player
->GetZoneId();
3615 WorldSafeLocsEntry
const* graveyard
= objmgr
.GetClosestGraveYard(
3616 player
->GetPositionX(), player
->GetPositionY(), player
->GetPositionZ(),player
->GetMapId(),g_team
);
3620 uint32 g_id
= graveyard
->ID
;
3622 GraveYardData
const* data
= objmgr
.FindGraveYardData(g_id
,zone_id
);
3625 PSendSysMessage(LANG_COMMAND_GRAVEYARDERROR
,g_id
);
3626 SetSentErrorMessage(true);
3630 g_team
= data
->team
;
3632 std::string team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_NOTEAM
);
3635 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ANY
);
3636 else if(g_team
== HORDE
)
3637 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE
);
3638 else if(g_team
== ALLIANCE
)
3639 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE
);
3641 PSendSysMessage(LANG_COMMAND_GRAVEYARDNEAREST
, g_id
,team_name
.c_str(),zone_id
);
3645 std::string team_name
;
3648 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ANY
);
3649 else if(g_team
== HORDE
)
3650 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE
);
3651 else if(g_team
== ALLIANCE
)
3652 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE
);
3654 if(g_team
== ~uint32(0))
3655 PSendSysMessage(LANG_COMMAND_ZONENOGRAVEYARDS
, zone_id
);
3657 PSendSysMessage(LANG_COMMAND_ZONENOGRAFACTION
, zone_id
,team_name
.c_str());
3663 //-----------------------Npc Commands-----------------------
3664 bool ChatHandler::HandleNpcAllowMovementCommand(const char* /*args*/)
3666 if(sWorld
.getAllowMovement())
3668 sWorld
.SetAllowMovement(false);
3669 SendSysMessage(LANG_CREATURE_MOVE_DISABLED
);
3673 sWorld
.SetAllowMovement(true);
3674 SendSysMessage(LANG_CREATURE_MOVE_ENABLED
);
3679 bool ChatHandler::HandleNpcChangeEntryCommand(const char *args
)
3684 uint32 newEntryNum
= atoi(args
);
3688 Unit
* unit
= getSelectedUnit();
3689 if(!unit
|| unit
->GetTypeId() != TYPEID_UNIT
)
3691 SendSysMessage(LANG_SELECT_CREATURE
);
3692 SetSentErrorMessage(true);
3695 Creature
* creature
= (Creature
*)unit
;
3696 if(creature
->UpdateEntry(newEntryNum
))
3697 SendSysMessage(LANG_DONE
);
3699 SendSysMessage(LANG_ERROR
);
3703 bool ChatHandler::HandleNpcInfoCommand(const char* /*args*/)
3705 Creature
* target
= getSelectedCreature();
3709 SendSysMessage(LANG_SELECT_CREATURE
);
3710 SetSentErrorMessage(true);
3714 uint32 faction
= target
->getFaction();
3715 uint32 npcflags
= target
->GetUInt32Value(UNIT_NPC_FLAGS
);
3716 uint32 displayid
= target
->GetDisplayId();
3717 uint32 nativeid
= target
->GetNativeDisplayId();
3718 uint32 Entry
= target
->GetEntry();
3719 CreatureInfo
const* cInfo
= target
->GetCreatureInfo();
3721 int32 curRespawnDelay
= target
->GetRespawnTimeEx()-time(NULL
);
3722 if(curRespawnDelay
< 0)
3723 curRespawnDelay
= 0;
3724 std::string curRespawnDelayStr
= secsToTimeString(curRespawnDelay
,true);
3725 std::string defRespawnDelayStr
= secsToTimeString(target
->GetRespawnDelay(),true);
3727 PSendSysMessage(LANG_NPCINFO_CHAR
, target
->GetDBTableGUIDLow(), faction
, npcflags
, Entry
, displayid
, nativeid
);
3728 PSendSysMessage(LANG_NPCINFO_LEVEL
, target
->getLevel());
3729 PSendSysMessage(LANG_NPCINFO_HEALTH
,target
->GetCreateHealth(), target
->GetMaxHealth(), target
->GetHealth());
3730 PSendSysMessage(LANG_NPCINFO_FLAGS
, target
->GetUInt32Value(UNIT_FIELD_FLAGS
), target
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
), target
->getFaction());
3731 PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES
, defRespawnDelayStr
.c_str(),curRespawnDelayStr
.c_str());
3732 PSendSysMessage(LANG_NPCINFO_LOOT
, cInfo
->lootid
,cInfo
->pickpocketLootId
,cInfo
->SkinLootId
);
3733 PSendSysMessage(LANG_NPCINFO_DUNGEON_ID
, target
->GetInstanceId());
3734 PSendSysMessage(LANG_NPCINFO_POSITION
,float(target
->GetPositionX()), float(target
->GetPositionY()), float(target
->GetPositionZ()));
3736 if ((npcflags
& UNIT_NPC_FLAG_VENDOR
) )
3738 SendSysMessage(LANG_NPCINFO_VENDOR
);
3740 if ((npcflags
& UNIT_NPC_FLAG_TRAINER
) )
3742 SendSysMessage(LANG_NPCINFO_TRAINER
);
3749 bool ChatHandler::HandleNpcPlayEmoteCommand(const char* args
)
3751 uint32 emote
= atoi((char*)args
);
3753 Creature
* target
= getSelectedCreature();
3756 SendSysMessage(LANG_SELECT_CREATURE
);
3757 SetSentErrorMessage(true);
3761 target
->SetUInt32Value(UNIT_NPC_EMOTESTATE
,emote
);
3766 //TODO: NpcCommands that needs to be fixed :
3768 bool ChatHandler::HandleNpcAddWeaponCommand(const char* /*args*/)
3773 uint64 guid = m_session->GetPlayer()->GetSelection();
3776 SendSysMessage(LANG_NO_SELECTION);
3780 Creature *pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
3784 SendSysMessage(LANG_SELECT_CREATURE);
3788 char* pSlotID = strtok((char*)args, " ");
3792 char* pItemID = strtok(NULL, " ");
3796 uint32 ItemID = atoi(pItemID);
3797 uint32 SlotID = atoi(pSlotID);
3799 ItemPrototype* tmpItem = objmgr.GetItemPrototype(ItemID);
3807 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID);
3811 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID);
3815 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID);
3819 PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST,SlotID);
3825 PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT,ItemID,tmpItem->Name1,SlotID);
3829 PSendSysMessage(LANG_ITEM_NOT_FOUND,ItemID);
3835 //----------------------------------------------------------
3837 bool ChatHandler::HandleExploreCheatCommand(const char* args
)
3842 int flag
= atoi((char*)args
);
3844 Player
*chr
= getSelectedPlayer();
3847 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3848 SetSentErrorMessage(true);
3854 PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL
, GetNameLink(chr
).c_str());
3855 if (needReportToTarget(chr
))
3856 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_EXPLORE_SET_ALL
,GetNameLink().c_str());
3860 PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING
, GetNameLink(chr
).c_str());
3861 if (needReportToTarget(chr
))
3862 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_EXPLORE_SET_NOTHING
,GetNameLink().c_str());
3865 for (uint8 i
=0; i
<128; i
++)
3869 m_session
->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1
+i
,0xFFFFFFFF);
3873 m_session
->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1
+i
,0);
3880 bool ChatHandler::HandleHoverCommand(const char* args
)
3882 char* px
= strtok((char*)args
, " ");
3889 m_session
->GetPlayer()->SetHover(flag
);
3892 SendSysMessage(LANG_HOVER_ENABLED
);
3894 SendSysMessage(LANG_HOVER_DISABLED
);
3899 bool ChatHandler::HandleLevelUpCommand(const char* args
)
3901 char* px
= strtok((char*)args
, " ");
3902 char* py
= strtok((char*)NULL
, " ");
3904 // command format parsing
3905 char* pname
= (char*)NULL
;
3908 if(px
&& py
) // .levelup name level
3910 addlevel
= atoi(py
);
3913 else if(px
&& !py
) // .levelup name OR .levelup level
3915 if(isalpha(px
[0])) // .levelup name
3917 else // .levelup level
3918 addlevel
= atoi(px
);
3920 // else .levelup - nothing do for preparing
3924 uint64 chr_guid
= 0;
3928 if(pname
) // player by name
3930 name
= extractPlayerNameFromLink(pname
);
3933 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3934 SetSentErrorMessage(true);
3938 chr
= objmgr
.GetPlayer(name
.c_str());
3939 if(!chr
) // not in game
3941 chr_guid
= objmgr
.GetPlayerGUIDByName(name
);
3944 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3945 SetSentErrorMessage(true);
3950 else // player by selection
3952 chr
= getSelectedPlayer();
3956 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3957 SetSentErrorMessage(true);
3961 name
= chr
->GetName();
3964 assert(chr
|| chr_guid
);
3966 int32 oldlevel
= chr
? chr
->getLevel() : Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL
,chr_guid
);
3967 int32 newlevel
= oldlevel
+ addlevel
;
3970 if(newlevel
> STRONG_MAX_LEVEL
) // hardcoded maximum level
3971 newlevel
= STRONG_MAX_LEVEL
;
3975 chr
->GiveLevel(newlevel
);
3976 chr
->InitTalentForLevel();
3977 chr
->SetUInt32Value(PLAYER_XP
,0);
3979 if(oldlevel
== newlevel
)
3980 ChatHandler(chr
).SendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET
);
3982 if(oldlevel
< newlevel
)
3983 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_LEVEL_UP
,newlevel
-oldlevel
);
3985 if(oldlevel
> newlevel
)
3986 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_LEVEL_DOWN
,newlevel
-oldlevel
);
3990 // update level and XP at level, all other will be updated at loading
3992 Player::LoadValuesArrayFromDB(values
,chr_guid
);
3993 Player::SetUInt32ValueInArray(values
,UNIT_FIELD_LEVEL
,newlevel
);
3994 Player::SetUInt32ValueInArray(values
,PLAYER_XP
,0);
3995 Player::SaveValuesArrayInDB(values
,chr_guid
);
3998 if(m_session
->GetPlayer() != chr
) // including chr==NULL
4000 std::string nameLink
= playerLink(name
);
4001 PSendSysMessage(LANG_YOU_CHANGE_LVL
,nameLink
.c_str(),newlevel
);
4006 bool ChatHandler::HandleShowAreaCommand(const char* args
)
4011 Player
*chr
= getSelectedPlayer();
4014 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4015 SetSentErrorMessage(true);
4019 int area
= GetAreaFlagByAreaID(atoi((char*)args
));
4020 int offset
= area
/ 32;
4021 uint32 val
= (uint32
)(1 << (area
% 32));
4023 if(area
<0 || offset
>= 128)
4025 SendSysMessage(LANG_BAD_VALUE
);
4026 SetSentErrorMessage(true);
4030 uint32 currFields
= chr
->GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
4031 chr
->SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
| val
));
4033 SendSysMessage(LANG_EXPLORE_AREA
);
4037 bool ChatHandler::HandleHideAreaCommand(const char* args
)
4042 Player
*chr
= getSelectedPlayer();
4045 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4046 SetSentErrorMessage(true);
4050 int area
= GetAreaFlagByAreaID(atoi((char*)args
));
4051 int offset
= area
/ 32;
4052 uint32 val
= (uint32
)(1 << (area
% 32));
4054 if(area
<0 || offset
>= 128)
4056 SendSysMessage(LANG_BAD_VALUE
);
4057 SetSentErrorMessage(true);
4061 uint32 currFields
= chr
->GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
4062 chr
->SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
^ val
));
4064 SendSysMessage(LANG_UNEXPLORE_AREA
);
4068 bool ChatHandler::HandleDebugUpdate(const char* args
)
4076 char* pUpdateIndex
= strtok((char*)args
, " ");
4078 Unit
* chr
= getSelectedUnit();
4081 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4082 SetSentErrorMessage(true);
4090 updateIndex
= atoi(pUpdateIndex
);
4092 if(chr
->GetTypeId() == TYPEID_PLAYER
)
4094 if (updateIndex
>=PLAYER_END
) return true;
4098 if (updateIndex
>=UNIT_END
) return true;
4101 char* pvalue
= strtok(NULL
, " ");
4104 value
=chr
->GetUInt32Value(updateIndex
);
4106 PSendSysMessage(LANG_UPDATE
, chr
->GetGUIDLow(),updateIndex
,value
);
4112 PSendSysMessage(LANG_UPDATE_CHANGE
, chr
->GetGUIDLow(),updateIndex
,value
);
4114 chr
->SetUInt32Value(updateIndex
,value
);
4119 bool ChatHandler::HandleBankCommand(const char* /*args*/)
4121 m_session
->SendShowBank( m_session
->GetPlayer()->GetGUID() );
4126 bool ChatHandler::HandleChangeWeather(const char* args
)
4132 if (!sWorld
.getConfig(CONFIG_WEATHER
))
4134 SendSysMessage(LANG_WEATHER_DISABLED
);
4135 SetSentErrorMessage(true);
4139 //*Change the weather of a cell
4140 char* px
= strtok((char*)args
, " ");
4141 char* py
= strtok(NULL
, " ");
4146 uint32 type
= (uint32
)atoi(px
); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
4147 float grade
= (float)atof(py
); //0 to 1, sending -1 is instand good weather
4149 Player
*player
= m_session
->GetPlayer();
4150 uint32 zoneid
= player
->GetZoneId();
4152 Weather
* wth
= sWorld
.FindWeather(zoneid
);
4155 wth
= sWorld
.AddWeather(zoneid
);
4158 SendSysMessage(LANG_NO_WEATHER
);
4159 SetSentErrorMessage(true);
4163 wth
->SetWeather(WeatherType(type
), grade
);
4168 bool ChatHandler::HandleDebugSetValue(const char* args
)
4173 char* px
= strtok((char*)args
, " ");
4174 char* py
= strtok(NULL
, " ");
4175 char* pz
= strtok(NULL
, " ");
4180 Unit
* target
= getSelectedUnit();
4183 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4184 SetSentErrorMessage(true);
4188 uint64 guid
= target
->GetGUID();
4190 uint32 Opcode
= (uint32
)atoi(px
);
4191 if(Opcode
>= target
->GetValuesCount())
4193 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, GUID_LOPART(guid
), target
->GetValuesCount());
4198 bool isint32
= true;
4200 isint32
= (bool)atoi(pz
);
4203 iValue
= (uint32
)atoi(py
);
4204 sLog
.outDebug(GetMangosString(LANG_SET_UINT
), GUID_LOPART(guid
), Opcode
, iValue
);
4205 target
->SetUInt32Value( Opcode
, iValue
);
4206 PSendSysMessage(LANG_SET_UINT_FIELD
, GUID_LOPART(guid
), Opcode
,iValue
);
4210 fValue
= (float)atof(py
);
4211 sLog
.outDebug(GetMangosString(LANG_SET_FLOAT
), GUID_LOPART(guid
), Opcode
, fValue
);
4212 target
->SetFloatValue( Opcode
, fValue
);
4213 PSendSysMessage(LANG_SET_FLOAT_FIELD
, GUID_LOPART(guid
), Opcode
,fValue
);
4219 bool ChatHandler::HandleDebugGetValue(const char* args
)
4224 char* px
= strtok((char*)args
, " ");
4225 char* pz
= strtok(NULL
, " ");
4230 Unit
* target
= getSelectedUnit();
4233 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4234 SetSentErrorMessage(true);
4238 uint64 guid
= target
->GetGUID();
4240 uint32 Opcode
= (uint32
)atoi(px
);
4241 if(Opcode
>= target
->GetValuesCount())
4243 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, GUID_LOPART(guid
), target
->GetValuesCount());
4248 bool isint32
= true;
4250 isint32
= (bool)atoi(pz
);
4254 iValue
= target
->GetUInt32Value( Opcode
);
4255 sLog
.outDebug(GetMangosString(LANG_GET_UINT
), GUID_LOPART(guid
), Opcode
, iValue
);
4256 PSendSysMessage(LANG_GET_UINT_FIELD
, GUID_LOPART(guid
), Opcode
, iValue
);
4260 fValue
= target
->GetFloatValue( Opcode
);
4261 sLog
.outDebug(GetMangosString(LANG_GET_FLOAT
), GUID_LOPART(guid
), Opcode
, fValue
);
4262 PSendSysMessage(LANG_GET_FLOAT_FIELD
, GUID_LOPART(guid
), Opcode
, fValue
);
4268 bool ChatHandler::HandleSet32Bit(const char* args
)
4273 char* px
= strtok((char*)args
, " ");
4274 char* py
= strtok(NULL
, " ");
4279 uint32 Opcode
= (uint32
)atoi(px
);
4280 uint32 Value
= (uint32
)atoi(py
);
4281 if (Value
> 32) //uint32 = 32 bits
4284 sLog
.outDebug(GetMangosString(LANG_SET_32BIT
), Opcode
, Value
);
4286 m_session
->GetPlayer( )->SetUInt32Value( Opcode
, 2^Value
);
4288 PSendSysMessage(LANG_SET_32BIT_FIELD
, Opcode
,1);
4292 bool ChatHandler::HandleDebugMod32Value(const char* args
)
4297 char* px
= strtok((char*)args
, " ");
4298 char* py
= strtok(NULL
, " ");
4303 uint32 Opcode
= (uint32
)atoi(px
);
4304 int Value
= atoi(py
);
4306 if(Opcode
>= m_session
->GetPlayer()->GetValuesCount())
4308 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, m_session
->GetPlayer()->GetGUIDLow(), m_session
->GetPlayer( )->GetValuesCount());
4312 sLog
.outDebug(GetMangosString(LANG_CHANGE_32BIT
), Opcode
, Value
);
4314 int CurrentValue
= (int)m_session
->GetPlayer( )->GetUInt32Value( Opcode
);
4316 CurrentValue
+= Value
;
4317 m_session
->GetPlayer( )->SetUInt32Value( Opcode
, (uint32
)CurrentValue
);
4319 PSendSysMessage(LANG_CHANGE_32BIT_FIELD
, Opcode
,CurrentValue
);
4324 bool ChatHandler::HandleTeleAddCommand(const char * args
)
4329 Player
*player
=m_session
->GetPlayer();
4333 std::string name
= args
;
4335 if(objmgr
.GetGameTele(name
))
4337 SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST
);
4338 SetSentErrorMessage(true);
4343 tele
.position_x
= player
->GetPositionX();
4344 tele
.position_y
= player
->GetPositionY();
4345 tele
.position_z
= player
->GetPositionZ();
4346 tele
.orientation
= player
->GetOrientation();
4347 tele
.mapId
= player
->GetMapId();
4350 if(objmgr
.AddGameTele(tele
))
4352 SendSysMessage(LANG_COMMAND_TP_ADDED
);
4356 SendSysMessage(LANG_COMMAND_TP_ADDEDERR
);
4357 SetSentErrorMessage(true);
4364 bool ChatHandler::HandleTeleDelCommand(const char * args
)
4369 std::string name
= args
;
4371 if(!objmgr
.DeleteGameTele(name
))
4373 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
4374 SetSentErrorMessage(true);
4378 SendSysMessage(LANG_COMMAND_TP_DELETED
);
4382 bool ChatHandler::HandleListAurasCommand (const char * /*args*/)
4384 Unit
*unit
= getSelectedUnit();
4387 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4388 SetSentErrorMessage(true);
4392 char const* talentStr
= GetMangosString(LANG_TALENT
);
4393 char const* passiveStr
= GetMangosString(LANG_PASSIVE
);
4395 Unit::AuraMap
const& uAuras
= unit
->GetAuras();
4396 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS
, uAuras
.size());
4397 for (Unit::AuraMap::const_iterator itr
= uAuras
.begin(); itr
!= uAuras
.end(); ++itr
)
4399 bool talent
= GetTalentSpellCost(itr
->second
->GetId()) > 0;
4401 char const* name
= itr
->second
->GetSpellProto()->SpellName
[m_session
->GetSessionDbcLocale()];
4405 std::ostringstream ss_name
;
4406 ss_name
<< "|cffffffff|Hspell:" << itr
->second
->GetId() << "|h[" << name
<< "]|h|r";
4408 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL
, itr
->second
->GetId(), itr
->second
->GetEffIndex(),
4409 itr
->second
->GetModifier()->m_auraname
, itr
->second
->GetAuraDuration(), itr
->second
->GetAuraMaxDuration(),
4410 ss_name
.str().c_str(),
4411 (itr
->second
->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4412 IS_PLAYER_GUID(itr
->second
->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr
->second
->GetCasterGUID()));
4416 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL
, itr
->second
->GetId(), itr
->second
->GetEffIndex(),
4417 itr
->second
->GetModifier()->m_auraname
, itr
->second
->GetAuraDuration(), itr
->second
->GetAuraMaxDuration(),
4419 (itr
->second
->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4420 IS_PLAYER_GUID(itr
->second
->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr
->second
->GetCasterGUID()));
4423 for (int i
= 0; i
< TOTAL_AURAS
; i
++)
4425 Unit::AuraList
const& uAuraList
= unit
->GetAurasByType(AuraType(i
));
4426 if (uAuraList
.empty()) continue;
4427 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE
, uAuraList
.size(), i
);
4428 for (Unit::AuraList::const_iterator itr
= uAuraList
.begin(); itr
!= uAuraList
.end(); ++itr
)
4430 bool talent
= GetTalentSpellCost((*itr
)->GetId()) > 0;
4432 char const* name
= (*itr
)->GetSpellProto()->SpellName
[m_session
->GetSessionDbcLocale()];
4436 std::ostringstream ss_name
;
4437 ss_name
<< "|cffffffff|Hspell:" << (*itr
)->GetId() << "|h[" << name
<< "]|h|r";
4439 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE
, (*itr
)->GetId(), (*itr
)->GetEffIndex(),
4440 ss_name
.str().c_str(),((*itr
)->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4441 IS_PLAYER_GUID((*itr
)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr
)->GetCasterGUID()));
4445 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE
, (*itr
)->GetId(), (*itr
)->GetEffIndex(),
4446 name
,((*itr
)->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4447 IS_PLAYER_GUID((*itr
)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr
)->GetCasterGUID()));
4454 bool ChatHandler::HandleResetAchievementsCommand (const char * args
)
4456 char* pName
= strtok((char*)args
, "");
4457 Player
*player
= NULL
;
4461 std::string name
= extractPlayerNameFromLink(pName
);
4464 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4465 SetSentErrorMessage(true);
4469 guid
= objmgr
.GetPlayerGUIDByName(name
);
4470 player
= objmgr
.GetPlayer(guid
);
4474 player
= getSelectedPlayer();
4476 guid
= player
->GetGUID();
4479 if(!player
&& !guid
)
4481 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4486 player
->GetAchievementMgr().Reset();
4488 AchievementMgr::DeleteFromDB(GUID_LOPART(guid
));
4493 bool ChatHandler::HandleResetHonorCommand (const char * args
)
4495 char* pName
= strtok((char*)args
, "");
4496 Player
*player
= NULL
;
4499 std::string name
= extractPlayerNameFromLink(pName
);
4502 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4503 SetSentErrorMessage(true);
4507 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
);
4508 player
= objmgr
.GetPlayer(guid
);
4511 player
= getSelectedPlayer();
4515 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4519 player
->SetUInt32Value(PLAYER_FIELD_KILLS
, 0);
4520 player
->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS
, 0);
4521 player
->SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY
, 0);
4522 player
->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION
, 0);
4523 player
->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION
, 0);
4525 player
->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_EARN_HONORABLE_KILL
);
4530 static bool HandleResetStatsOrLevelHelper(Player
* player
)
4532 PlayerInfo
const *info
= objmgr
.GetPlayerInfo(player
->getRace(), player
->getClass());
4533 if(!info
) return false;
4535 ChrClassesEntry
const* cEntry
= sChrClassesStore
.LookupEntry(player
->getClass());
4538 sLog
.outError("Class %u not found in DBC (Wrong DBC files?)",player
->getClass());
4542 uint8 powertype
= cEntry
->powerType
;
4544 // reset m_form if no aura
4545 if(!player
->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT
))
4546 player
->m_form
= FORM_NONE
;
4548 player
->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS
, DEFAULT_WORLD_OBJECT_SIZE
);
4549 player
->SetFloatValue(UNIT_FIELD_COMBATREACH
, 1.5f
);
4551 player
->setFactionForRace(player
->getRace());
4553 player
->SetUInt32Value(UNIT_FIELD_BYTES_0
, ( ( player
->getRace() ) | ( player
->getClass() << 8 ) | ( player
->getGender() << 16 ) | ( powertype
<< 24 ) ) );
4555 // reset only if player not in some form;
4556 if(player
->m_form
==FORM_NONE
)
4558 switch(player
->getGender())
4561 player
->SetDisplayId(info
->displayId_f
);
4562 player
->SetNativeDisplayId(info
->displayId_f
);
4565 player
->SetDisplayId(info
->displayId_m
);
4566 player
->SetNativeDisplayId(info
->displayId_m
);
4573 player
->SetByteValue(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_PVP
);
4574 player
->SetByteValue(UNIT_FIELD_BYTES_2
, 3, player
->m_form
);
4576 player
->SetUInt32Value(UNIT_FIELD_FLAGS
, UNIT_FLAG_PVP_ATTACKABLE
);
4578 //-1 is default value
4579 player
->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX
, uint32(-1));
4581 //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000 );
4585 bool ChatHandler::HandleResetLevelCommand(const char * args
)
4587 char* pName
= strtok((char*)args
, "");
4588 Player
*player
= NULL
;
4591 std::string name
= extractPlayerNameFromLink(pName
);
4594 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4595 SetSentErrorMessage(true);
4599 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
);
4600 player
= objmgr
.GetPlayer(guid
);
4603 player
= getSelectedPlayer();
4607 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4608 SetSentErrorMessage(true);
4612 if(!HandleResetStatsOrLevelHelper(player
))
4615 // set starting level
4616 uint32 start_level
= player
->getClass() != CLASS_DEATH_KNIGHT
4617 ? sWorld
.getConfig(CONFIG_START_PLAYER_LEVEL
)
4618 : sWorld
.getConfig(CONFIG_START_HEROIC_PLAYER_LEVEL
);
4620 player
->SetLevel(start_level
);
4621 player
->InitRunes();
4622 player
->InitStatsForLevel(true);
4623 player
->InitTaxiNodesForLevel();
4624 player
->InitGlyphsForLevel();
4625 player
->InitTalentForLevel();
4626 player
->SetUInt32Value(PLAYER_XP
,0);
4628 // reset level to summoned pet
4629 Pet
* pet
= player
->GetPet();
4630 if(pet
&& pet
->getPetType()==SUMMON_PET
)
4632 pet
->InitStatsForLevel(1);
4633 pet
->InitTalentForLevel();
4638 bool ChatHandler::HandleResetStatsCommand(const char * args
)
4640 char* pName
= strtok((char*)args
, "");
4641 Player
*player
= NULL
;
4644 std::string name
= extractPlayerNameFromLink(pName
);
4647 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4648 SetSentErrorMessage(true);
4652 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
);
4653 player
= objmgr
.GetPlayer(guid
);
4656 player
= getSelectedPlayer();
4660 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4661 SetSentErrorMessage(true);
4665 if(!HandleResetStatsOrLevelHelper(player
))
4668 player
->InitRunes();
4669 player
->InitStatsForLevel(true);
4670 player
->InitTaxiNodesForLevel();
4671 player
->InitGlyphsForLevel();
4672 player
->InitTalentForLevel();
4677 bool ChatHandler::HandleResetSpellsCommand(const char * args
)
4679 char* pName
= strtok((char*)args
, "");
4680 Player
*player
= NULL
;
4681 uint64 playerGUID
= 0;
4684 std::string name
= extractPlayerNameFromLink(pName
);
4687 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4688 SetSentErrorMessage(true);
4692 player
= objmgr
.GetPlayer(name
.c_str());
4694 playerGUID
= objmgr
.GetPlayerGUIDByName(name
);
4697 player
= getSelectedPlayer();
4699 if(!player
&& !playerGUID
)
4701 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4702 SetSentErrorMessage(true);
4708 player
->resetSpells();
4710 ChatHandler(player
).SendSysMessage(LANG_RESET_SPELLS
);
4711 if(m_session
->GetPlayer()!=player
)
4712 PSendSysMessage(LANG_RESET_SPELLS_ONLINE
,GetNameLink(player
).c_str());
4716 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS
), GUID_LOPART(playerGUID
));
4717 PSendSysMessage(LANG_RESET_SPELLS_OFFLINE
,pName
);
4723 bool ChatHandler::HandleResetTalentsCommand(const char * args
)
4725 char* pName
= strtok((char*)args
, "");
4726 Player
*player
= NULL
;
4727 uint64 playerGUID
= 0;
4730 std::string name
= extractPlayerNameFromLink(pName
);
4733 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4734 SetSentErrorMessage(true);
4738 player
= objmgr
.GetPlayer(name
.c_str());
4740 playerGUID
= objmgr
.GetPlayerGUIDByName(name
);
4743 player
= getSelectedPlayer();
4747 player
->resetTalents(true);
4749 ChatHandler(player
).SendSysMessage(LANG_RESET_TALENTS
);
4750 if(m_session
->GetPlayer()!=player
)
4751 PSendSysMessage(LANG_RESET_TALENTS_ONLINE
,GetNameLink(player
).c_str());
4755 else if (playerGUID
)
4757 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_TALENTS
), GUID_LOPART(playerGUID
) );
4758 std::string nameLink
= playerLink(pName
);
4759 PSendSysMessage(LANG_RESET_TALENTS_OFFLINE
,nameLink
.c_str());
4762 // Try reset talenents as Hunter Pet
4763 Creature
* creature
= getSelectedCreature();
4764 if (creature
&& creature
->isPet() && ((Pet
*)creature
)->getPetType() == HUNTER_PET
)
4766 ((Pet
*)creature
)->resetTalents(true);
4767 Unit
*owner
= creature
->GetOwner();
4768 if (owner
&& owner
->GetTypeId() == TYPEID_PLAYER
)
4770 player
= (Player
*)owner
;
4771 ChatHandler(player
).SendSysMessage(LANG_RESET_PET_TALENTS
);
4772 if(m_session
->GetPlayer()!=player
)
4773 PSendSysMessage(LANG_RESET_PET_TALENTS_ONLINE
,GetNameLink(player
).c_str());
4778 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4779 SetSentErrorMessage(true);
4783 bool ChatHandler::HandleResetAllCommand(const char * args
)
4788 std::string casename
= args
;
4790 AtLoginFlags atLogin
;
4792 // Command specially created as single command to prevent using short case names
4793 if(casename
=="spells")
4795 atLogin
= AT_LOGIN_RESET_SPELLS
;
4796 sWorld
.SendWorldText(LANG_RESETALL_SPELLS
);
4798 else if(casename
=="talents")
4800 atLogin
= AT_LOGIN_RESET_TALENTS
;
4801 sWorld
.SendWorldText(LANG_RESETALL_TALENTS
);
4805 PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE
,args
);
4806 SetSentErrorMessage(true);
4810 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE (at_login & '%u') = '0'",atLogin
,atLogin
);
4811 HashMapHolder
<Player
>::MapType
const& plist
= ObjectAccessor::Instance().GetPlayers();
4812 for(HashMapHolder
<Player
>::MapType::const_iterator itr
= plist
.begin(); itr
!= plist
.end(); ++itr
)
4813 itr
->second
->SetAtLoginFlag(atLogin
);
4818 bool ChatHandler::HandleServerShutDownCancelCommand(const char* args
)
4820 sWorld
.ShutdownCancel();
4824 bool ChatHandler::HandleServerShutDownCommand(const char* args
)
4829 char* time_str
= strtok ((char*) args
, " ");
4830 char* exitcode_str
= strtok (NULL
, "");
4832 int32 time
= atoi (time_str
);
4834 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4835 if(time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0') || time
< 0)
4840 int32 exitcode
= atoi (exitcode_str
);
4842 // Handle atoi() errors
4843 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4846 // Exit code should be in range of 0-125, 126-255 is used
4847 // in many shells for their own return codes and code > 255
4848 // is not supported in many others
4849 if (exitcode
< 0 || exitcode
> 125)
4852 sWorld
.ShutdownServ (time
, 0, exitcode
);
4855 sWorld
.ShutdownServ(time
,0,SHUTDOWN_EXIT_CODE
);
4859 bool ChatHandler::HandleServerRestartCommand(const char* args
)
4864 char* time_str
= strtok ((char*) args
, " ");
4865 char* exitcode_str
= strtok (NULL
, "");
4867 int32 time
= atoi (time_str
);
4869 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4870 if(time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0') || time
< 0)
4875 int32 exitcode
= atoi (exitcode_str
);
4877 // Handle atoi() errors
4878 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4881 // Exit code should be in range of 0-125, 126-255 is used
4882 // in many shells for their own return codes and code > 255
4883 // is not supported in many others
4884 if (exitcode
< 0 || exitcode
> 125)
4887 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_RESTART
, exitcode
);
4890 sWorld
.ShutdownServ(time
, SHUTDOWN_MASK_RESTART
, RESTART_EXIT_CODE
);
4894 bool ChatHandler::HandleServerIdleRestartCommand(const char* args
)
4899 char* time_str
= strtok ((char*) args
, " ");
4900 char* exitcode_str
= strtok (NULL
, "");
4902 int32 time
= atoi (time_str
);
4904 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4905 if(time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0') || time
< 0)
4910 int32 exitcode
= atoi (exitcode_str
);
4912 // Handle atoi() errors
4913 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4916 // Exit code should be in range of 0-125, 126-255 is used
4917 // in many shells for their own return codes and code > 255
4918 // is not supported in many others
4919 if (exitcode
< 0 || exitcode
> 125)
4922 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_RESTART
|SHUTDOWN_MASK_IDLE
, exitcode
);
4925 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_RESTART
|SHUTDOWN_MASK_IDLE
,RESTART_EXIT_CODE
);
4929 bool ChatHandler::HandleServerIdleShutDownCommand(const char* args
)
4934 char* time_str
= strtok ((char*) args
, " ");
4935 char* exitcode_str
= strtok (NULL
, "");
4937 int32 time
= atoi (time_str
);
4939 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4940 if(time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0') || time
< 0)
4945 int32 exitcode
= atoi (exitcode_str
);
4947 // Handle atoi() errors
4948 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4951 // Exit code should be in range of 0-125, 126-255 is used
4952 // in many shells for their own return codes and code > 255
4953 // is not supported in many others
4954 if (exitcode
< 0 || exitcode
> 125)
4957 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_IDLE
, exitcode
);
4960 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_IDLE
,SHUTDOWN_EXIT_CODE
);
4964 bool ChatHandler::HandleQuestAdd(const char* args
)
4966 Player
* player
= getSelectedPlayer();
4969 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4970 SetSentErrorMessage(true);
4974 // .addquest #entry'
4975 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4976 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4980 uint32 entry
= atol(cId
);
4982 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
4986 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
,entry
);
4987 SetSentErrorMessage(true);
4991 // check item starting quest (it can work incorrectly if added without item in inventory)
4992 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
4994 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
4998 if (pProto
->StartQuest
== entry
)
5000 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM
, entry
, pProto
->ItemId
);
5001 SetSentErrorMessage(true);
5006 // ok, normal (creature/GO starting) quest
5007 if( player
->CanAddQuest( pQuest
, true ) )
5009 player
->AddQuest( pQuest
, NULL
);
5011 if ( player
->CanCompleteQuest( entry
) )
5012 player
->CompleteQuest( entry
);
5018 bool ChatHandler::HandleQuestRemove(const char* args
)
5020 Player
* player
= getSelectedPlayer();
5023 SendSysMessage(LANG_NO_CHAR_SELECTED
);
5024 SetSentErrorMessage(true);
5028 // .removequest #entry'
5029 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
5030 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
5034 uint32 entry
= atol(cId
);
5036 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
5040 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
5041 SetSentErrorMessage(true);
5045 // remove all quest entries for 'entry' from quest log
5046 for(uint8 slot
= 0; slot
< MAX_QUEST_LOG_SIZE
; ++slot
)
5048 uint32 quest
= player
->GetQuestSlotQuestId(slot
);
5051 player
->SetQuestSlot(slot
,0);
5053 // we ignore unequippable quest items in this case, its' still be equipped
5054 player
->TakeQuestSourceItem( quest
, false );
5058 // set quest status to not started (will updated in DB at next save)
5059 player
->SetQuestStatus( entry
, QUEST_STATUS_NONE
);
5061 // reset rewarded for restart repeatable quest
5062 player
->getQuestStatusMap()[entry
].m_rewarded
= false;
5064 SendSysMessage(LANG_COMMAND_QUEST_REMOVED
);
5068 bool ChatHandler::HandleQuestComplete(const char* args
)
5070 Player
* player
= getSelectedPlayer();
5073 SendSysMessage(LANG_NO_CHAR_SELECTED
);
5074 SetSentErrorMessage(true);
5078 // .quest complete #entry
5079 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
5080 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
5084 uint32 entry
= atol(cId
);
5086 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
5088 // If player doesn't have the quest
5089 if(!pQuest
|| player
->GetQuestStatus(entry
) == QUEST_STATUS_NONE
)
5091 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
5092 SetSentErrorMessage(true);
5096 // Add quest items for quests that require items
5097 for(uint8 x
= 0; x
< QUEST_OBJECTIVES_COUNT
; ++x
)
5099 uint32 id
= pQuest
->ReqItemId
[x
];
5100 uint32 count
= pQuest
->ReqItemCount
[x
];
5104 uint32 curItemCount
= player
->GetItemCount(id
,true);
5106 ItemPosCountVec dest
;
5107 uint8 msg
= player
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, id
, count
-curItemCount
);
5108 if( msg
== EQUIP_ERR_OK
)
5110 Item
* item
= player
->StoreNewItem( dest
, id
, true);
5111 player
->SendNewItem(item
,count
-curItemCount
,true,false);
5115 // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
5116 for(uint8 i
= 0; i
< QUEST_OBJECTIVES_COUNT
; i
++)
5118 uint32 creature
= pQuest
->ReqCreatureOrGOId
[i
];
5119 uint32 creaturecount
= pQuest
->ReqCreatureOrGOCount
[i
];
5121 if(uint32 spell_id
= pQuest
->ReqSpell
[i
])
5123 for(uint16 z
= 0; z
< creaturecount
; ++z
)
5124 player
->CastedCreatureOrGO(creature
,0,spell_id
);
5126 else if(creature
> 0)
5128 for(uint16 z
= 0; z
< creaturecount
; ++z
)
5129 player
->KilledMonster(creature
,0);
5131 else if(creature
< 0)
5133 for(uint16 z
= 0; z
< creaturecount
; ++z
)
5134 player
->CastedCreatureOrGO(creature
,0,0);
5138 // If the quest requires reputation to complete
5139 if(uint32 repFaction
= pQuest
->GetRepObjectiveFaction())
5141 uint32 repValue
= pQuest
->GetRepObjectiveValue();
5142 uint32 curRep
= player
->GetReputationMgr().GetReputation(repFaction
);
5143 if(curRep
< repValue
)
5144 if(FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry(repFaction
))
5145 player
->GetReputationMgr().SetReputation(factionEntry
,repValue
);
5148 // If the quest requires money
5149 int32 ReqOrRewMoney
= pQuest
->GetRewOrReqMoney();
5150 if(ReqOrRewMoney
< 0)
5151 player
->ModifyMoney(-ReqOrRewMoney
);
5153 player
->CompleteQuest(entry
);
5157 bool ChatHandler::HandleBanAccountCommand(const char* args
)
5159 return HandleBanHelper(BAN_ACCOUNT
,args
);
5162 bool ChatHandler::HandleBanCharacterCommand(const char* args
)
5164 return HandleBanHelper(BAN_CHARACTER
,args
);
5167 bool ChatHandler::HandleBanIPCommand(const char* args
)
5169 return HandleBanHelper(BAN_IP
,args
);
5172 bool ChatHandler::HandleBanHelper(BanMode mode
, const char* args
)
5177 char* cnameOrIP
= strtok ((char*)args
, " ");
5181 std::string nameOrIP
= cnameOrIP
;
5183 char* duration
= strtok (NULL
," ");
5184 if(!duration
|| !atoi(duration
))
5187 char* reason
= strtok (NULL
,"");
5194 if(!AccountMgr::normilizeString(nameOrIP
))
5196 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
5197 SetSentErrorMessage(true);
5202 if(!normalizePlayerName(nameOrIP
))
5204 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5205 SetSentErrorMessage(true);
5210 if(!IsIPAddress(nameOrIP
.c_str()))
5215 switch(sWorld
.BanAccount(mode
, nameOrIP
, duration
, reason
,m_session
? m_session
->GetPlayerName() : ""))
5218 if(atoi(duration
)>0)
5219 PSendSysMessage(LANG_BAN_YOUBANNED
,nameOrIP
.c_str(),secsToTimeString(TimeStringToSecs(duration
),true).c_str(),reason
);
5221 PSendSysMessage(LANG_BAN_YOUPERMBANNED
,nameOrIP
.c_str(),reason
);
5223 case BAN_SYNTAX_ERROR
:
5229 PSendSysMessage(LANG_BAN_NOTFOUND
,"account",nameOrIP
.c_str());
5232 PSendSysMessage(LANG_BAN_NOTFOUND
,"character",nameOrIP
.c_str());
5235 PSendSysMessage(LANG_BAN_NOTFOUND
,"ip",nameOrIP
.c_str());
5238 SetSentErrorMessage(true);
5245 bool ChatHandler::HandleUnBanAccountCommand(const char* args
)
5247 return HandleUnBanHelper(BAN_ACCOUNT
,args
);
5250 bool ChatHandler::HandleUnBanCharacterCommand(const char* args
)
5252 return HandleUnBanHelper(BAN_CHARACTER
,args
);
5255 bool ChatHandler::HandleUnBanIPCommand(const char* args
)
5257 return HandleUnBanHelper(BAN_IP
,args
);
5260 bool ChatHandler::HandleUnBanHelper(BanMode mode
, const char* args
)
5265 char* cnameOrIP
= strtok ((char*)args
, " ");
5269 std::string nameOrIP
= cnameOrIP
;
5274 if(!AccountMgr::normilizeString(nameOrIP
))
5276 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
5277 SetSentErrorMessage(true);
5282 if(!normalizePlayerName(nameOrIP
))
5284 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5285 SetSentErrorMessage(true);
5290 if(!IsIPAddress(nameOrIP
.c_str()))
5295 if(sWorld
.RemoveBanAccount(mode
,nameOrIP
))
5296 PSendSysMessage(LANG_UNBAN_UNBANNED
,nameOrIP
.c_str());
5298 PSendSysMessage(LANG_UNBAN_ERROR
,nameOrIP
.c_str());
5303 bool ChatHandler::HandleBanInfoAccountCommand(const char* args
)
5308 char* cname
= strtok((char*)args
, "");
5312 std::string account_name
= cname
;
5313 if(!AccountMgr::normilizeString(account_name
))
5315 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5316 SetSentErrorMessage(true);
5320 uint32 accountid
= accmgr
.GetId(account_name
);
5323 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5327 return HandleBanInfoHelper(accountid
,account_name
.c_str());
5330 bool ChatHandler::HandleBanInfoCharacterCommand(const char* args
)
5335 std::string name
= extractPlayerNameFromLink((char*)args
);
5338 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5339 SetSentErrorMessage(true);
5343 uint32 accountid
= objmgr
.GetPlayerAccountIdByPlayerName(name
);
5346 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5347 SetSentErrorMessage(true);
5351 std::string accountname
;
5352 if(!accmgr
.GetName(accountid
,accountname
))
5354 PSendSysMessage(LANG_BANINFO_NOCHARACTER
);
5358 return HandleBanInfoHelper(accountid
,accountname
.c_str());
5361 bool ChatHandler::HandleBanInfoHelper(uint32 accountid
, char const* accountname
)
5363 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
);
5366 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN
, accountname
);
5370 PSendSysMessage(LANG_BANINFO_BANHISTORY
,accountname
);
5373 Field
* fields
= result
->Fetch();
5375 time_t unbandate
= time_t(fields
[3].GetUInt64());
5376 bool active
= false;
5377 if(fields
[2].GetBool() && (fields
[1].GetUInt64() == (uint64
)0 ||unbandate
>= time(NULL
)) )
5379 bool permanent
= (fields
[1].GetUInt64() == (uint64
)0);
5380 std::string bantime
= permanent
?GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[1].GetUInt64(), true);
5381 PSendSysMessage(LANG_BANINFO_HISTORYENTRY
,
5382 fields
[0].GetString(), bantime
.c_str(), active
? GetMangosString(LANG_BANINFO_YES
):GetMangosString(LANG_BANINFO_NO
), fields
[4].GetString(), fields
[5].GetString());
5383 }while (result
->NextRow());
5389 bool ChatHandler::HandleBanInfoIPCommand(const char* args
)
5394 char* cIP
= strtok ((char*)args
, "");
5398 if (!IsIPAddress(cIP
))
5401 std::string IP
= cIP
;
5403 loginDatabase
.escape_string(IP
);
5404 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());
5407 PSendSysMessage(LANG_BANINFO_NOIP
);
5411 Field
*fields
= result
->Fetch();
5412 bool permanent
= !fields
[6].GetUInt64();
5413 PSendSysMessage(LANG_BANINFO_IPENTRY
,
5414 fields
[0].GetString(), fields
[1].GetString(), permanent
? GetMangosString(LANG_BANINFO_NEVER
):fields
[2].GetString(),
5415 permanent
? GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[3].GetUInt64(), true).c_str(), fields
[4].GetString(), fields
[5].GetString());
5420 bool ChatHandler::HandleBanListCharacterCommand(const char* args
)
5422 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5424 char* cFilter
= strtok ((char*)args
, " ");
5428 std::string filter
= cFilter
;
5429 loginDatabase
.escape_string(filter
);
5430 QueryResult
* result
= CharacterDatabase
.PQuery("SELECT account FROM characters WHERE name "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'"),filter
.c_str());
5433 PSendSysMessage(LANG_BANLIST_NOCHARACTER
);
5437 return HandleBanListHelper(result
);
5440 bool ChatHandler::HandleBanListAccountCommand(const char* args
)
5442 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5444 char* cFilter
= strtok((char*)args
, " ");
5445 std::string filter
= cFilter
? cFilter
: "";
5446 loginDatabase
.escape_string(filter
);
5448 QueryResult
* result
;
5452 result
= loginDatabase
.Query("SELECT account.id, username FROM account, account_banned"
5453 " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
5457 result
= loginDatabase
.PQuery("SELECT account.id, username FROM account, account_banned"
5458 " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
5464 PSendSysMessage(LANG_BANLIST_NOACCOUNT
);
5468 return HandleBanListHelper(result
);
5471 bool ChatHandler::HandleBanListHelper(QueryResult
* result
)
5473 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT
);
5475 // Chat short output
5480 Field
* fields
= result
->Fetch();
5481 uint32 accountid
= fields
[0].GetUInt32();
5483 QueryResult
* banresult
= loginDatabase
.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid
);
5486 Field
* fields2
= banresult
->Fetch();
5487 PSendSysMessage("%s",fields2
[0].GetString());
5490 } while (result
->NextRow());
5492 // Console wide output
5495 SendSysMessage(LANG_BANLIST_ACCOUNTS
);
5496 SendSysMessage("===============================================================================");
5497 SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER
);
5500 SendSysMessage("-------------------------------------------------------------------------------");
5501 Field
*fields
= result
->Fetch();
5502 uint32 account_id
= fields
[0].GetUInt32 ();
5504 std::string account_name
;
5506 // "account" case, name can be get in same query
5507 if(result
->GetFieldCount() > 1)
5508 account_name
= fields
[1].GetCppString();
5509 // "character" case, name need extract from another DB
5511 accmgr
.GetName (account_id
,account_name
);
5513 // No SQL injection. id is uint32.
5514 QueryResult
*banInfo
= loginDatabase
.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id
);
5517 Field
*fields2
= banInfo
->Fetch();
5520 time_t t_ban
= fields2
[0].GetUInt64();
5521 tm
* aTm_ban
= localtime(&t_ban
);
5523 if (fields2
[0].GetUInt64() == fields2
[1].GetUInt64())
5525 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5526 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
,
5527 fields2
[2].GetString(),fields2
[3].GetString());
5531 time_t t_unban
= fields2
[1].GetUInt64();
5532 tm
* aTm_unban
= localtime(&t_unban
);
5533 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5534 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
,
5535 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5536 fields2
[2].GetString(),fields2
[3].GetString());
5538 }while ( banInfo
->NextRow() );
5541 }while( result
->NextRow() );
5542 SendSysMessage("===============================================================================");
5549 bool ChatHandler::HandleBanListIPCommand(const char* args
)
5551 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5553 char* cFilter
= strtok((char*)args
, " ");
5554 std::string filter
= cFilter
? cFilter
: "";
5555 loginDatabase
.escape_string(filter
);
5557 QueryResult
* result
;
5561 result
= loginDatabase
.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5562 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
5563 " ORDER BY unbandate" );
5567 result
= loginDatabase
.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5568 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")
5569 " ORDER BY unbandate",filter
.c_str() );
5574 PSendSysMessage(LANG_BANLIST_NOIP
);
5578 PSendSysMessage(LANG_BANLIST_MATCHINGIP
);
5579 // Chat short output
5584 Field
* fields
= result
->Fetch();
5585 PSendSysMessage("%s",fields
[0].GetString());
5586 } while (result
->NextRow());
5588 // Console wide output
5591 SendSysMessage(LANG_BANLIST_IPS
);
5592 SendSysMessage("===============================================================================");
5593 SendSysMessage(LANG_BANLIST_IPS_HEADER
);
5596 SendSysMessage("-------------------------------------------------------------------------------");
5597 Field
*fields
= result
->Fetch();
5598 time_t t_ban
= fields
[1].GetUInt64();
5599 tm
* aTm_ban
= localtime(&t_ban
);
5600 if ( fields
[1].GetUInt64() == fields
[2].GetUInt64() )
5602 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5603 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
,
5604 fields
[3].GetString(), fields
[4].GetString());
5608 time_t t_unban
= fields
[2].GetUInt64();
5609 tm
* aTm_unban
= localtime(&t_unban
);
5610 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5611 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
,
5612 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5613 fields
[3].GetString(), fields
[4].GetString());
5615 }while( result
->NextRow() );
5616 SendSysMessage("===============================================================================");
5623 bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
5625 Player
* pl
= m_session
->GetPlayer();
5627 // accept only explicitly selected target (not implicitly self targeting case)
5628 Unit
* target
= getSelectedUnit();
5629 if(pl
->GetSelection() && target
)
5631 if(target
->GetTypeId()!=TYPEID_UNIT
)
5633 SendSysMessage(LANG_SELECT_CREATURE
);
5634 SetSentErrorMessage(true);
5638 if(target
->isDead())
5639 ((Creature
*)target
)->Respawn();
5643 CellPair
p(MaNGOS::ComputeCellPair(pl
->GetPositionX(), pl
->GetPositionY()));
5645 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
5648 MaNGOS::RespawnDo u_do
;
5649 MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
> worker(pl
,u_do
);
5651 TypeContainerVisitor
<MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
>, GridTypeMapContainer
> obj_worker(worker
);
5652 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
5653 cell_lock
->Visit(cell_lock
, obj_worker
, *pl
->GetMap());
5658 bool ChatHandler::HandleGMFlyCommand(const char* args
)
5663 Player
*target
= getSelectedPlayer();
5665 target
= m_session
->GetPlayer();
5667 WorldPacket
data(12);
5668 if (strncmp(args
, "on", 3) == 0)
5669 data
.SetOpcode(SMSG_MOVE_SET_CAN_FLY
);
5670 else if (strncmp(args
, "off", 4) == 0)
5671 data
.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY
);
5674 SendSysMessage(LANG_USE_BOL
);
5677 data
.append(target
->GetPackGUID());
5678 data
<< uint32(0); // unknown
5679 target
->SendMessageToSet(&data
, true);
5680 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS
, GetNameLink(target
).c_str(), args
);
5684 bool ChatHandler::HandlePDumpLoadCommand(const char *args
)
5689 char * file
= strtok((char*)args
, " ");
5693 char * account
= strtok(NULL
, " ");
5697 std::string account_name
= account
;
5698 if(!AccountMgr::normilizeString(account_name
))
5700 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5701 SetSentErrorMessage(true);
5705 uint32 account_id
= accmgr
.GetId(account_name
);
5708 account_id
= atoi(account
); // use original string
5711 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5712 SetSentErrorMessage(true);
5717 if(!accmgr
.GetName(account_id
,account_name
))
5719 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5720 SetSentErrorMessage(true);
5724 char* guid_str
= NULL
;
5725 char* name_str
= strtok(NULL
, " ");
5731 // normalize the name if specified and check if it exists
5732 if(!normalizePlayerName(name
))
5734 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5735 SetSentErrorMessage(true);
5739 if(!ObjectMgr::IsValidName(name
,true))
5741 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5742 SetSentErrorMessage(true);
5746 guid_str
= strtok(NULL
, " ");
5753 guid
= atoi(guid_str
);
5756 PSendSysMessage(LANG_INVALID_CHARACTER_GUID
);
5757 SetSentErrorMessage(true);
5761 if(objmgr
.GetPlayerAccountIdByGUID(guid
))
5763 PSendSysMessage(LANG_CHARACTER_GUID_IN_USE
,guid
);
5764 SetSentErrorMessage(true);
5769 switch(PlayerDumpReader().LoadDump(file
, account_id
, name
, guid
))
5772 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS
);
5774 case DUMP_FILE_OPEN_ERROR
:
5775 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
5776 SetSentErrorMessage(true);
5778 case DUMP_FILE_BROKEN
:
5779 PSendSysMessage(LANG_DUMP_BROKEN
,file
);
5780 SetSentErrorMessage(true);
5782 case DUMP_TOO_MANY_CHARS
:
5783 PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL
,account_name
.c_str(),account_id
);
5784 SetSentErrorMessage(true);
5787 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED
);
5788 SetSentErrorMessage(true);
5795 bool ChatHandler::HandlePDumpWriteCommand(const char *args
)
5800 char* file
= strtok((char*)args
, " ");
5801 char* p2
= strtok(NULL
, " ");
5807 // character name can't start from number
5808 if (isNumeric(p2
[0]))
5812 std::string name
= extractPlayerNameFromLink(p2
);
5815 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5816 SetSentErrorMessage(true);
5820 guid
= objmgr
.GetPlayerGUIDByName(name
);
5823 if(!objmgr
.GetPlayerAccountIdByGUID(guid
))
5825 PSendSysMessage(LANG_PLAYER_NOT_FOUND
);
5826 SetSentErrorMessage(true);
5830 switch(PlayerDumpWriter().WriteDump(file
, guid
))
5833 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS
);
5835 case DUMP_FILE_OPEN_ERROR
:
5836 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
5837 SetSentErrorMessage(true);
5840 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED
);
5841 SetSentErrorMessage(true);
5848 bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
5850 Unit
* unit
= getSelectedUnit();
5853 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5854 SetSentErrorMessage(true);
5858 PSendSysMessage(LANG_MOVEGENS_LIST
,(unit
->GetTypeId()==TYPEID_PLAYER
? "Player" : "Creature" ),unit
->GetGUIDLow());
5860 MotionMaster
* mm
= unit
->GetMotionMaster();
5861 for(MotionMaster::const_iterator itr
= mm
->begin(); itr
!= mm
->end(); ++itr
)
5863 switch((*itr
)->GetMovementGeneratorType())
5865 case IDLE_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_IDLE
); break;
5866 case RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_RANDOM
); break;
5867 case WAYPOINT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_WAYPOINT
); break;
5868 case ANIMAL_RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_ANIMAL_RANDOM
); break;
5869 case CONFUSED_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_CONFUSED
); break;
5870 case TARGETED_MOTION_TYPE
:
5872 if(unit
->GetTypeId()==TYPEID_PLAYER
)
5874 TargetedMovementGenerator
<Player
> const* mgen
= static_cast<TargetedMovementGenerator
<Player
> const*>(*itr
);
5875 Unit
* target
= mgen
->GetTarget();
5877 PSendSysMessage(LANG_MOVEGENS_TARGETED_PLAYER
,target
->GetName(),target
->GetGUIDLow());
5879 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL
);
5883 TargetedMovementGenerator
<Creature
> const* mgen
= static_cast<TargetedMovementGenerator
<Creature
> const*>(*itr
);
5884 Unit
* target
= mgen
->GetTarget();
5886 PSendSysMessage(LANG_MOVEGENS_TARGETED_CREATURE
,target
->GetName(),target
->GetGUIDLow());
5888 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL
);
5892 case HOME_MOTION_TYPE
:
5893 if(unit
->GetTypeId()==TYPEID_UNIT
)
5896 (*itr
)->GetDestination(x
,y
,z
);
5897 PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE
,x
,y
,z
);
5900 SendSysMessage(LANG_MOVEGENS_HOME_PLAYER
);
5902 case FLIGHT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FLIGHT
); break;
5903 case POINT_MOTION_TYPE
:
5906 (*itr
)->GetDestination(x
,y
,z
);
5907 PSendSysMessage(LANG_MOVEGENS_POINT
,x
,y
,z
);
5910 case FLEEING_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FEAR
); break;
5911 case DISTRACT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_DISTRACT
); break;
5913 PSendSysMessage(LANG_MOVEGENS_UNKNOWN
,(*itr
)->GetMovementGeneratorType());
5920 bool ChatHandler::HandlePLimitCommand(const char *args
)
5924 char* param
= strtok((char*)args
, " ");
5928 int l
= strlen(param
);
5930 if( strncmp(param
,"player",l
) == 0 )
5931 sWorld
.SetPlayerLimit(-SEC_PLAYER
);
5932 else if(strncmp(param
,"moderator",l
) == 0 )
5933 sWorld
.SetPlayerLimit(-SEC_MODERATOR
);
5934 else if(strncmp(param
,"gamemaster",l
) == 0 )
5935 sWorld
.SetPlayerLimit(-SEC_GAMEMASTER
);
5936 else if(strncmp(param
,"administrator",l
) == 0 )
5937 sWorld
.SetPlayerLimit(-SEC_ADMINISTRATOR
);
5938 else if(strncmp(param
,"reset",l
) == 0 )
5939 sWorld
.SetPlayerLimit( sConfig
.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT
) );
5942 int val
= atoi(param
);
5943 if(val
< -SEC_ADMINISTRATOR
) val
= -SEC_ADMINISTRATOR
;
5945 sWorld
.SetPlayerLimit(val
);
5948 // kick all low security level players
5949 if(sWorld
.GetPlayerAmountLimit() > SEC_PLAYER
)
5950 sWorld
.KickAllLess(sWorld
.GetPlayerSecurityLimit());
5953 uint32 pLimit
= sWorld
.GetPlayerAmountLimit();
5954 AccountTypes allowedAccountType
= sWorld
.GetPlayerSecurityLimit();
5955 char const* secName
= "";
5956 switch(allowedAccountType
)
5958 case SEC_PLAYER
: secName
= "Player"; break;
5959 case SEC_MODERATOR
: secName
= "Moderator"; break;
5960 case SEC_GAMEMASTER
: secName
= "Gamemaster"; break;
5961 case SEC_ADMINISTRATOR
: secName
= "Administrator"; break;
5962 default: secName
= "<unknown>"; break;
5965 PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit
,secName
);
5970 bool ChatHandler::HandleCastCommand(const char* args
)
5975 Unit
* target
= getSelectedUnit();
5979 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5980 SetSentErrorMessage(true);
5984 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5985 uint32 spell
= extractSpellIdFromLink((char*)args
);
5989 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5993 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5995 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5996 SetSentErrorMessage(true);
6000 char* trig_str
= strtok(NULL
, " ");
6003 int l
= strlen(trig_str
);
6004 if(strncmp(trig_str
,"triggered",l
) != 0 )
6008 bool triggered
= (trig_str
!= NULL
);
6010 m_session
->GetPlayer()->CastSpell(target
,spell
,triggered
);
6015 bool ChatHandler::HandleCastBackCommand(const char* args
)
6017 Creature
* caster
= getSelectedCreature();
6021 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
6022 SetSentErrorMessage(true);
6026 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
6027 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6028 uint32 spell
= extractSpellIdFromLink((char*)args
);
6029 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
6032 char* trig_str
= strtok(NULL
, " ");
6035 int l
= strlen(trig_str
);
6036 if(strncmp(trig_str
,"triggered",l
) != 0 )
6040 bool triggered
= (trig_str
!= NULL
);
6042 // update orientation at server
6043 caster
->SetOrientation(caster
->GetAngle(m_session
->GetPlayer()));
6047 caster
->BuildHeartBeatMsg(&data
);
6048 caster
->SendMessageToSet(&data
,true);
6050 caster
->CastSpell(m_session
->GetPlayer(),spell
,triggered
);
6055 bool ChatHandler::HandleCastDistCommand(const char* args
)
6060 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6061 uint32 spell
= extractSpellIdFromLink((char*)args
);
6065 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
6069 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
6071 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
6072 SetSentErrorMessage(true);
6076 char *distStr
= strtok(NULL
, " ");
6081 sscanf(distStr
, "%f", &dist
);
6083 char* trig_str
= strtok(NULL
, " ");
6086 int l
= strlen(trig_str
);
6087 if(strncmp(trig_str
,"triggered",l
) != 0 )
6091 bool triggered
= (trig_str
!= NULL
);
6094 m_session
->GetPlayer()->GetClosePoint(x
,y
,z
,dist
);
6096 m_session
->GetPlayer()->CastSpell(x
,y
,z
,spell
,triggered
);
6100 bool ChatHandler::HandleCastTargetCommand(const char* args
)
6102 Creature
* caster
= getSelectedCreature();
6106 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
6107 SetSentErrorMessage(true);
6111 if(!caster
->getVictim())
6113 SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM
);
6114 SetSentErrorMessage(true);
6118 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6119 uint32 spell
= extractSpellIdFromLink((char*)args
);
6120 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
6123 char* trig_str
= strtok(NULL
, " ");
6126 int l
= strlen(trig_str
);
6127 if(strncmp(trig_str
,"triggered",l
) != 0 )
6131 bool triggered
= (trig_str
!= NULL
);
6133 // update orientation at server
6134 caster
->SetOrientation(caster
->GetAngle(m_session
->GetPlayer()));
6138 caster
->BuildHeartBeatMsg(&data
);
6139 caster
->SendMessageToSet(&data
,true);
6141 caster
->CastSpell(caster
->getVictim(),spell
,triggered
);
6147 ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
6148 Without this function 3rd party scripting library will get linking errors (unresolved external)
6149 when attempting to use the PointMovementGenerator
6151 bool ChatHandler::HandleComeToMeCommand(const char *args
)
6153 Creature
* caster
= getSelectedCreature();
6157 SendSysMessage(LANG_SELECT_CREATURE
);
6158 SetSentErrorMessage(true);
6162 char* newFlagStr
= strtok((char*)args
, " ");
6167 uint32 newFlags
= atoi(newFlagStr
);
6169 caster
->SetUnitMovementFlags(newFlags
);
6171 Player
* pl
= m_session
->GetPlayer();
6173 caster
->GetMotionMaster()->MovePoint(0, pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ());
6177 bool ChatHandler::HandleCastSelfCommand(const char* args
)
6182 Unit
* target
= getSelectedUnit();
6186 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
6187 SetSentErrorMessage(true);
6191 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6192 uint32 spell
= extractSpellIdFromLink((char*)args
);
6196 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
6200 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
6202 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
6203 SetSentErrorMessage(true);
6207 target
->CastSpell(target
,spell
,false);
6212 std::string
GetTimeString(uint32 time
)
6214 uint16 days
= time
/ DAY
, hours
= (time
% DAY
) / HOUR
, minute
= (time
% HOUR
) / MINUTE
;
6215 std::ostringstream ss
;
6216 if(days
) ss
<< days
<< "d ";
6217 if(hours
) ss
<< hours
<< "h ";
6218 ss
<< minute
<< "m";
6222 bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
6224 Player
* player
= getSelectedPlayer();
6225 if (!player
) player
= m_session
->GetPlayer();
6227 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
6229 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(i
);
6230 for(Player::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
6232 InstanceSave
*save
= itr
->second
.save
;
6233 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
6234 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());
6238 PSendSysMessage("player binds: %d", counter
);
6240 Group
*group
= player
->GetGroup();
6243 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
6245 Group::BoundInstancesMap
&binds
= group
->GetBoundInstances(i
);
6246 for(Group::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
6248 InstanceSave
*save
= itr
->second
.save
;
6249 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
6250 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());
6255 PSendSysMessage("group binds: %d", counter
);
6260 bool ChatHandler::HandleInstanceUnbindCommand(const char* args
)
6265 std::string cmd
= args
;
6268 Player
* player
= getSelectedPlayer();
6269 if (!player
) player
= m_session
->GetPlayer();
6271 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
6273 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(i
);
6274 for(Player::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end();)
6276 if(itr
->first
!= player
->GetMapId())
6278 InstanceSave
*save
= itr
->second
.save
;
6279 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
6280 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());
6281 player
->UnbindInstance(itr
, i
);
6288 PSendSysMessage("instances unbound: %d", counter
);
6293 bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
6295 PSendSysMessage("instances loaded: %d", MapManager::Instance().GetNumInstances());
6296 PSendSysMessage("players in instances: %d", MapManager::Instance().GetNumPlayersInInstances());
6297 PSendSysMessage("instance saves: %d", sInstanceSaveManager
.GetNumInstanceSaves());
6298 PSendSysMessage("players bound: %d", sInstanceSaveManager
.GetNumBoundPlayersTotal());
6299 PSendSysMessage("groups bound: %d", sInstanceSaveManager
.GetNumBoundGroupsTotal());
6303 bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
6305 Player
* pl
= m_session
->GetPlayer();
6307 Map
* map
= pl
->GetMap();
6308 if (!map
->IsDungeon())
6310 PSendSysMessage("Map is not a dungeon.");
6311 SetSentErrorMessage(true);
6315 if (!((InstanceMap
*)map
)->GetInstanceData())
6317 PSendSysMessage("Map has no instance data.");
6318 SetSentErrorMessage(true);
6322 ((InstanceMap
*)map
)->GetInstanceData()->SaveToDB();
6326 /// Display the list of GMs
6327 bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
6329 ///- Get the accounts with GM Level >0
6330 QueryResult
*result
= loginDatabase
.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
6333 SendSysMessage(LANG_GMLIST
);
6334 SendSysMessage("========================");
6335 SendSysMessage(LANG_GMLIST_HEADER
);
6336 SendSysMessage("========================");
6338 ///- Circle through them. Display username and GM level
6341 Field
*fields
= result
->Fetch();
6342 PSendSysMessage("|%15s|%6s|", fields
[0].GetString(),fields
[1].GetString());
6343 }while( result
->NextRow() );
6345 PSendSysMessage("========================");
6349 PSendSysMessage(LANG_GMLIST_EMPTY
);
6353 /// Define the 'Message of the day' for the realm
6354 bool ChatHandler::HandleServerSetMotdCommand(const char* args
)
6356 sWorld
.SetMotd(args
);
6357 PSendSysMessage(LANG_MOTD_NEW
, args
);
6361 /// Set/Unset the expansion level for an account
6362 bool ChatHandler::HandleAccountSetAddonCommand(const char* args
)
6364 ///- Get the command line arguments
6365 char *szAcc
= strtok((char*)args
," ");
6366 char *szExp
= strtok(NULL
," ");
6371 std::string account_name
;
6376 Player
* player
= getSelectedPlayer();
6380 account_id
= player
->GetSession()->GetAccountId();
6381 accmgr
.GetName(account_id
,account_name
);
6386 ///- Convert Account name to Upper Format
6387 account_name
= szAcc
;
6388 if(!AccountMgr::normilizeString(account_name
))
6390 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
6391 SetSentErrorMessage(true);
6395 account_id
= accmgr
.GetId(account_name
);
6398 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
6399 SetSentErrorMessage(true);
6405 // Let set addon state only for lesser (strong) security level
6406 // or to self account
6407 if (m_session
&& m_session
->GetAccountId () != account_id
&&
6408 HasLowerSecurityAccount (NULL
,account_id
,true))
6411 int lev
=atoi(szExp
); //get int anyway (0 if error)
6416 loginDatabase
.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev
,account_id
);
6417 PSendSysMessage(LANG_ACCOUNT_SETADDON
,account_name
.c_str(),account_id
,lev
);
6421 //Send items by mail
6422 bool ChatHandler::HandleSendItemsCommand(const char* args
)
6427 // format: name "subject text" "mail text" item1[:count1] item2[:count2] ... item12[:count12]
6429 std::string name
= extractPlayerNameFromLink((char*)args
);
6432 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6433 SetSentErrorMessage(true);
6437 char* tail1
= strtok(NULL
, "");
6443 msgSubject
= strtok(tail1
+1, "\"");
6446 char* space
= strtok(tail1
, "\"");
6449 msgSubject
= strtok(NULL
, "\"");
6455 char* tail2
= strtok(NULL
, "");
6461 msgText
= strtok(tail2
+1, "\"");
6464 char* space
= strtok(tail2
, "\"");
6467 msgText
= strtok(NULL
, "\"");
6473 // msgSubject, msgText isn't NUL after prev. check
6474 std::string subject
= msgSubject
;
6475 std::string text
= msgText
;
6478 typedef std::pair
<uint32
,uint32
> ItemPair
;
6479 typedef std::list
< ItemPair
> ItemPairs
;
6482 // get all tail string
6483 char* tail
= strtok(NULL
, "");
6485 // get from tail next item str
6486 while(char* itemStr
= strtok(tail
, " "))
6489 tail
= strtok(NULL
, "");
6492 char* itemIdStr
= strtok(itemStr
, ":");
6493 char* itemCountStr
= strtok(NULL
, " ");
6495 uint32 item_id
= atoi(itemIdStr
);
6499 ItemPrototype
const* item_proto
= objmgr
.GetItemPrototype(item_id
);
6502 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
6503 SetSentErrorMessage(true);
6507 uint32 item_count
= itemCountStr
? atoi(itemCountStr
) : 1;
6508 if(item_count
< 1 || item_proto
->MaxCount
> 0 && item_count
> uint32(item_proto
->MaxCount
))
6510 PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT
, item_count
,item_id
);
6511 SetSentErrorMessage(true);
6515 while(item_count
> item_proto
->GetMaxStackSize())
6517 items
.push_back(ItemPair(item_id
,item_proto
->GetMaxStackSize()));
6518 item_count
-= item_proto
->GetMaxStackSize();
6521 items
.push_back(ItemPair(item_id
,item_count
));
6523 if(items
.size() > MAX_MAIL_ITEMS
)
6525 PSendSysMessage(LANG_COMMAND_MAIL_ITEMS_LIMIT
, MAX_MAIL_ITEMS
);
6526 SetSentErrorMessage(true);
6531 uint64 receiver_guid
= objmgr
.GetPlayerGUIDByName(name
);
6534 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6535 SetSentErrorMessage(true);
6539 // from console show not existed sender
6540 uint32 sender_guidlo
= m_session
? m_session
->GetPlayer()->GetGUIDLow() : 0;
6542 uint32 messagetype
= MAIL_NORMAL
;
6543 uint32 stationery
= MAIL_STATIONERY_GM
;
6544 uint32 itemTextId
= !text
.empty() ? objmgr
.CreateItemText( text
) : 0;
6546 Player
*receiver
= objmgr
.GetPlayer(receiver_guid
);
6549 MailItemsInfo mi
; // item list preparing
6551 for(ItemPairs::const_iterator itr
= items
.begin(); itr
!= items
.end(); ++itr
)
6553 if(Item
* item
= Item::CreateItem(itr
->first
,itr
->second
,m_session
? m_session
->GetPlayer() : 0))
6555 item
->SaveToDB(); // save for prevent lost at next mail load, if send fail then item will deleted
6556 mi
.AddItem(item
->GetGUIDLow(), item
->GetEntry(), item
);
6560 WorldSession::SendMailTo(receiver
,messagetype
, stationery
, sender_guidlo
, GUID_LOPART(receiver_guid
), subject
, itemTextId
, &mi
, 0, 0, MAIL_CHECK_MASK_NONE
);
6562 std::string nameLink
= playerLink(name
);
6563 PSendSysMessage(LANG_MAIL_SENT
, nameLink
.c_str());
6567 ///Send money by mail
6568 bool ChatHandler::HandleSendMoneyCommand(const char* args
)
6573 /// format: name "subject text" "mail text" money
6575 std::string name
= extractPlayerNameFromLink((char*)args
);
6578 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6579 SetSentErrorMessage(true);
6583 char* tail1
= strtok(NULL
, "");
6589 msgSubject
= strtok(tail1
+1, "\"");
6592 char* space
= strtok(tail1
, "\"");
6595 msgSubject
= strtok(NULL
, "\"");
6601 char* tail2
= strtok(NULL
, "");
6607 msgText
= strtok(tail2
+1, "\"");
6610 char* space
= strtok(tail2
, "\"");
6613 msgText
= strtok(NULL
, "\"");
6619 char* money_str
= strtok(NULL
, "");
6620 int32 money
= money_str
? atoi(money_str
) : 0;
6624 // msgSubject, msgText isn't NUL after prev. check
6625 std::string subject
= msgSubject
;
6626 std::string text
= msgText
;
6628 uint64 receiver_guid
= objmgr
.GetPlayerGUIDByName(name
);
6631 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6632 SetSentErrorMessage(true);
6636 // from console show not existed sender
6637 uint32 sender_guidlo
= m_session
? m_session
->GetPlayer()->GetGUIDLow() : 0;
6639 uint32 messagetype
= MAIL_NORMAL
;
6640 uint32 stationery
= MAIL_STATIONERY_GM
;
6641 uint32 itemTextId
= !text
.empty() ? objmgr
.CreateItemText( text
) : 0;
6643 Player
*receiver
= objmgr
.GetPlayer(receiver_guid
);
6645 WorldSession::SendMailTo(receiver
,messagetype
, stationery
, sender_guidlo
, GUID_LOPART(receiver_guid
), subject
, itemTextId
, NULL
, money
, 0, MAIL_CHECK_MASK_NONE
);
6647 std::string nameLink
= playerLink(name
);
6648 PSendSysMessage(LANG_MAIL_SENT
, nameLink
.c_str());
6652 /// Send a message to a player in game
6653 bool ChatHandler::HandleSendMessageCommand(const char* args
)
6655 ///- Get the command line arguments
6656 std::string name
= extractPlayerNameFromLink((char*)args
);
6659 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6660 SetSentErrorMessage(true);
6664 char* msg_str
= strtok(NULL
, "");
6668 ///- Find the player and check that he is not logging out.
6669 Player
*rPlayer
= objmgr
.GetPlayer(name
.c_str());
6672 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6673 SetSentErrorMessage(true);
6677 if(rPlayer
->GetSession()->isLogingOut())
6679 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6680 SetSentErrorMessage(true);
6684 ///- Send the message
6685 //Use SendAreaTriggerMessage for fastest delivery.
6686 rPlayer
->GetSession()->SendAreaTriggerMessage("%s", msg_str
);
6687 rPlayer
->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
6689 //Confirmation message
6690 std::string nameLink
= playerLink(name
);
6691 PSendSysMessage(LANG_SENDMESSAGE
,nameLink
.c_str(),msg_str
);
6695 bool ChatHandler::HandleFlushArenaPointsCommand(const char * /*args*/)
6697 sBattleGroundMgr
.DistributeArenaPoints();
6701 bool ChatHandler::HandleModifyGenderCommand(const char *args
)
6706 Player
*player
= getSelectedPlayer();
6710 PSendSysMessage(LANG_NO_PLAYER
);
6711 SetSentErrorMessage(true);
6715 PlayerInfo
const* info
= objmgr
.GetPlayerInfo(player
->getRace(), player
->getClass());
6719 char const* gender_str
= (char*)args
;
6720 int gender_len
= strlen(gender_str
);
6724 if(!strncmp(gender_str
, "male", gender_len
)) // MALE
6726 if(player
->getGender() == GENDER_MALE
)
6729 gender
= GENDER_MALE
;
6731 else if (!strncmp(gender_str
, "female", gender_len
)) // FEMALE
6733 if(player
->getGender() == GENDER_FEMALE
)
6736 gender
= GENDER_FEMALE
;
6740 SendSysMessage(LANG_MUST_MALE_OR_FEMALE
);
6741 SetSentErrorMessage(true);
6746 player
->SetByteValue(UNIT_FIELD_BYTES_0
, 2, gender
);
6747 player
->SetByteValue(PLAYER_BYTES_3
, 0, gender
);
6749 // Change display ID
6750 player
->SetDisplayId(gender
? info
->displayId_f
: info
->displayId_m
);
6751 player
->SetNativeDisplayId(gender
? info
->displayId_f
: info
->displayId_m
);
6753 char const* gender_full
= gender
? "female" : "male";
6755 PSendSysMessage(LANG_YOU_CHANGE_GENDER
, GetNameLink(player
).c_str(), gender_full
);
6757 if (needReportToTarget(player
))
6758 ChatHandler(player
).PSendSysMessage(LANG_YOUR_GENDER_CHANGED
, gender_full
, GetNameLink().c_str());