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
* SelectedPlayer
= NULL
;
3446 std::string name
= extractPlayerNameFromLink((char*)args
);
3449 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3450 SetSentErrorMessage(true);
3454 SelectedPlayer
= objmgr
.GetPlayer(name
.c_str());
3457 SelectedPlayer
= getSelectedPlayer();
3461 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3462 SetSentErrorMessage(true);
3466 SelectedPlayer
->ResurrectPlayer(0.5f
);
3467 SelectedPlayer
->SpawnCorpseBones();
3468 SelectedPlayer
->SaveToDB();
3472 bool ChatHandler::HandleAuraCommand(const char* args
)
3474 Unit
*target
= getSelectedUnit();
3477 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3478 SetSentErrorMessage(true);
3482 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3483 uint32 spellID
= extractSpellIdFromLink((char*)args
);
3485 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry( spellID
);
3488 for(uint32 i
= 0;i
<3;i
++)
3490 uint8 eff
= spellInfo
->Effect
[i
];
3491 if (eff
>=TOTAL_SPELL_EFFECTS
)
3493 if( IsAreaAuraEffect(eff
) ||
3494 eff
== SPELL_EFFECT_APPLY_AURA
||
3495 eff
== SPELL_EFFECT_PERSISTENT_AREA_AURA
)
3497 Aura
*Aur
= CreateAura(spellInfo
, i
, NULL
, target
);
3498 target
->AddAura(Aur
);
3506 bool ChatHandler::HandleUnAuraCommand(const char* args
)
3508 Unit
*target
= getSelectedUnit();
3511 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3512 SetSentErrorMessage(true);
3516 std::string argstr
= args
;
3517 if (argstr
== "all")
3519 target
->RemoveAllAuras();
3523 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3524 uint32 spellID
= extractSpellIdFromLink((char*)args
);
3528 target
->RemoveAurasDueToSpell(spellID
);
3533 bool ChatHandler::HandleLinkGraveCommand(const char* args
)
3538 char* px
= strtok((char*)args
, " ");
3542 uint32 g_id
= (uint32
)atoi(px
);
3546 char* px2
= strtok(NULL
, " ");
3550 else if (strncmp(px2
,"horde",6)==0)
3552 else if (strncmp(px2
,"alliance",9)==0)
3557 WorldSafeLocsEntry
const* graveyard
= sWorldSafeLocsStore
.LookupEntry(g_id
);
3561 PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST
, g_id
);
3562 SetSentErrorMessage(true);
3566 Player
* player
= m_session
->GetPlayer();
3568 uint32 zoneId
= player
->GetZoneId();
3570 AreaTableEntry
const *areaEntry
= GetAreaEntryByAreaID(zoneId
);
3571 if(!areaEntry
|| areaEntry
->zone
!=0 )
3573 PSendSysMessage(LANG_COMMAND_GRAVEYARDWRONGZONE
, g_id
,zoneId
);
3574 SetSentErrorMessage(true);
3578 if(objmgr
.AddGraveYardLink(g_id
,zoneId
,g_team
))
3579 PSendSysMessage(LANG_COMMAND_GRAVEYARDLINKED
, g_id
,zoneId
);
3581 PSendSysMessage(LANG_COMMAND_GRAVEYARDALRLINKED
, g_id
,zoneId
);
3586 bool ChatHandler::HandleNearGraveCommand(const char* args
)
3590 size_t argslen
= strlen(args
);
3594 else if (strncmp((char*)args
,"horde",argslen
)==0)
3596 else if (strncmp((char*)args
,"alliance",argslen
)==0)
3601 Player
* player
= m_session
->GetPlayer();
3602 uint32 zone_id
= player
->GetZoneId();
3604 WorldSafeLocsEntry
const* graveyard
= objmgr
.GetClosestGraveYard(
3605 player
->GetPositionX(), player
->GetPositionY(), player
->GetPositionZ(),player
->GetMapId(),g_team
);
3609 uint32 g_id
= graveyard
->ID
;
3611 GraveYardData
const* data
= objmgr
.FindGraveYardData(g_id
,zone_id
);
3614 PSendSysMessage(LANG_COMMAND_GRAVEYARDERROR
,g_id
);
3615 SetSentErrorMessage(true);
3619 g_team
= data
->team
;
3621 std::string team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_NOTEAM
);
3624 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ANY
);
3625 else if(g_team
== HORDE
)
3626 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE
);
3627 else if(g_team
== ALLIANCE
)
3628 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE
);
3630 PSendSysMessage(LANG_COMMAND_GRAVEYARDNEAREST
, g_id
,team_name
.c_str(),zone_id
);
3634 std::string team_name
;
3637 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ANY
);
3638 else if(g_team
== HORDE
)
3639 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE
);
3640 else if(g_team
== ALLIANCE
)
3641 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE
);
3643 if(g_team
== ~uint32(0))
3644 PSendSysMessage(LANG_COMMAND_ZONENOGRAVEYARDS
, zone_id
);
3646 PSendSysMessage(LANG_COMMAND_ZONENOGRAFACTION
, zone_id
,team_name
.c_str());
3652 //-----------------------Npc Commands-----------------------
3653 bool ChatHandler::HandleNpcAllowMovementCommand(const char* /*args*/)
3655 if(sWorld
.getAllowMovement())
3657 sWorld
.SetAllowMovement(false);
3658 SendSysMessage(LANG_CREATURE_MOVE_DISABLED
);
3662 sWorld
.SetAllowMovement(true);
3663 SendSysMessage(LANG_CREATURE_MOVE_ENABLED
);
3668 bool ChatHandler::HandleNpcChangeEntryCommand(const char *args
)
3673 uint32 newEntryNum
= atoi(args
);
3677 Unit
* unit
= getSelectedUnit();
3678 if(!unit
|| unit
->GetTypeId() != TYPEID_UNIT
)
3680 SendSysMessage(LANG_SELECT_CREATURE
);
3681 SetSentErrorMessage(true);
3684 Creature
* creature
= (Creature
*)unit
;
3685 if(creature
->UpdateEntry(newEntryNum
))
3686 SendSysMessage(LANG_DONE
);
3688 SendSysMessage(LANG_ERROR
);
3692 bool ChatHandler::HandleNpcInfoCommand(const char* /*args*/)
3694 Creature
* target
= getSelectedCreature();
3698 SendSysMessage(LANG_SELECT_CREATURE
);
3699 SetSentErrorMessage(true);
3703 uint32 faction
= target
->getFaction();
3704 uint32 npcflags
= target
->GetUInt32Value(UNIT_NPC_FLAGS
);
3705 uint32 displayid
= target
->GetDisplayId();
3706 uint32 nativeid
= target
->GetNativeDisplayId();
3707 uint32 Entry
= target
->GetEntry();
3708 CreatureInfo
const* cInfo
= target
->GetCreatureInfo();
3710 int32 curRespawnDelay
= target
->GetRespawnTimeEx()-time(NULL
);
3711 if(curRespawnDelay
< 0)
3712 curRespawnDelay
= 0;
3713 std::string curRespawnDelayStr
= secsToTimeString(curRespawnDelay
,true);
3714 std::string defRespawnDelayStr
= secsToTimeString(target
->GetRespawnDelay(),true);
3716 PSendSysMessage(LANG_NPCINFO_CHAR
, target
->GetDBTableGUIDLow(), faction
, npcflags
, Entry
, displayid
, nativeid
);
3717 PSendSysMessage(LANG_NPCINFO_LEVEL
, target
->getLevel());
3718 PSendSysMessage(LANG_NPCINFO_HEALTH
,target
->GetCreateHealth(), target
->GetMaxHealth(), target
->GetHealth());
3719 PSendSysMessage(LANG_NPCINFO_FLAGS
, target
->GetUInt32Value(UNIT_FIELD_FLAGS
), target
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
), target
->getFaction());
3720 PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES
, defRespawnDelayStr
.c_str(),curRespawnDelayStr
.c_str());
3721 PSendSysMessage(LANG_NPCINFO_LOOT
, cInfo
->lootid
,cInfo
->pickpocketLootId
,cInfo
->SkinLootId
);
3722 PSendSysMessage(LANG_NPCINFO_DUNGEON_ID
, target
->GetInstanceId());
3723 PSendSysMessage(LANG_NPCINFO_POSITION
,float(target
->GetPositionX()), float(target
->GetPositionY()), float(target
->GetPositionZ()));
3725 if ((npcflags
& UNIT_NPC_FLAG_VENDOR
) )
3727 SendSysMessage(LANG_NPCINFO_VENDOR
);
3729 if ((npcflags
& UNIT_NPC_FLAG_TRAINER
) )
3731 SendSysMessage(LANG_NPCINFO_TRAINER
);
3738 bool ChatHandler::HandleNpcPlayEmoteCommand(const char* args
)
3740 uint32 emote
= atoi((char*)args
);
3742 Creature
* target
= getSelectedCreature();
3745 SendSysMessage(LANG_SELECT_CREATURE
);
3746 SetSentErrorMessage(true);
3750 target
->SetUInt32Value(UNIT_NPC_EMOTESTATE
,emote
);
3755 //TODO: NpcCommands that needs to be fixed :
3757 bool ChatHandler::HandleNpcAddWeaponCommand(const char* /*args*/)
3762 uint64 guid = m_session->GetPlayer()->GetSelection();
3765 SendSysMessage(LANG_NO_SELECTION);
3769 Creature *pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
3773 SendSysMessage(LANG_SELECT_CREATURE);
3777 char* pSlotID = strtok((char*)args, " ");
3781 char* pItemID = strtok(NULL, " ");
3785 uint32 ItemID = atoi(pItemID);
3786 uint32 SlotID = atoi(pSlotID);
3788 ItemPrototype* tmpItem = objmgr.GetItemPrototype(ItemID);
3796 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID);
3800 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID);
3804 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID);
3808 PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST,SlotID);
3814 PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT,ItemID,tmpItem->Name1,SlotID);
3818 PSendSysMessage(LANG_ITEM_NOT_FOUND,ItemID);
3824 //----------------------------------------------------------
3826 bool ChatHandler::HandleExploreCheatCommand(const char* args
)
3831 int flag
= atoi((char*)args
);
3833 Player
*chr
= getSelectedPlayer();
3836 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3837 SetSentErrorMessage(true);
3843 PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL
, GetNameLink(chr
).c_str());
3844 if (needReportToTarget(chr
))
3845 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_EXPLORE_SET_ALL
,GetNameLink().c_str());
3849 PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING
, GetNameLink(chr
).c_str());
3850 if (needReportToTarget(chr
))
3851 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_EXPLORE_SET_NOTHING
,GetNameLink().c_str());
3854 for (uint8 i
=0; i
<128; i
++)
3858 m_session
->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1
+i
,0xFFFFFFFF);
3862 m_session
->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1
+i
,0);
3869 bool ChatHandler::HandleHoverCommand(const char* args
)
3871 char* px
= strtok((char*)args
, " ");
3878 m_session
->GetPlayer()->SetHover(flag
);
3881 SendSysMessage(LANG_HOVER_ENABLED
);
3883 SendSysMessage(LANG_HOVER_DISABLED
);
3888 bool ChatHandler::HandleLevelUpCommand(const char* args
)
3890 char* px
= strtok((char*)args
, " ");
3891 char* py
= strtok((char*)NULL
, " ");
3893 // command format parsing
3894 char* pname
= (char*)NULL
;
3897 if(px
&& py
) // .levelup name level
3899 addlevel
= atoi(py
);
3902 else if(px
&& !py
) // .levelup name OR .levelup level
3904 if(isalpha(px
[0])) // .levelup name
3906 else // .levelup level
3907 addlevel
= atoi(px
);
3909 // else .levelup - nothing do for preparing
3913 uint64 chr_guid
= 0;
3917 if(pname
) // player by name
3919 name
= extractPlayerNameFromLink(pname
);
3922 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3923 SetSentErrorMessage(true);
3927 chr
= objmgr
.GetPlayer(name
.c_str());
3928 if(!chr
) // not in game
3930 chr_guid
= objmgr
.GetPlayerGUIDByName(name
);
3933 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3934 SetSentErrorMessage(true);
3939 else // player by selection
3941 chr
= getSelectedPlayer();
3945 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3946 SetSentErrorMessage(true);
3950 name
= chr
->GetName();
3953 assert(chr
|| chr_guid
);
3955 int32 oldlevel
= chr
? chr
->getLevel() : Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL
,chr_guid
);
3956 int32 newlevel
= oldlevel
+ addlevel
;
3959 if(newlevel
> STRONG_MAX_LEVEL
) // hardcoded maximum level
3960 newlevel
= STRONG_MAX_LEVEL
;
3964 chr
->GiveLevel(newlevel
);
3965 chr
->InitTalentForLevel();
3966 chr
->SetUInt32Value(PLAYER_XP
,0);
3968 if(oldlevel
== newlevel
)
3969 ChatHandler(chr
).SendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET
);
3971 if(oldlevel
< newlevel
)
3972 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_LEVEL_UP
,newlevel
-oldlevel
);
3974 if(oldlevel
> newlevel
)
3975 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_LEVEL_DOWN
,newlevel
-oldlevel
);
3979 // update level and XP at level, all other will be updated at loading
3981 Player::LoadValuesArrayFromDB(values
,chr_guid
);
3982 Player::SetUInt32ValueInArray(values
,UNIT_FIELD_LEVEL
,newlevel
);
3983 Player::SetUInt32ValueInArray(values
,PLAYER_XP
,0);
3984 Player::SaveValuesArrayInDB(values
,chr_guid
);
3987 if(m_session
->GetPlayer() != chr
) // including chr==NULL
3989 std::string nameLink
= playerLink(name
);
3990 PSendSysMessage(LANG_YOU_CHANGE_LVL
,nameLink
.c_str(),newlevel
);
3995 bool ChatHandler::HandleShowAreaCommand(const char* args
)
4000 Player
*chr
= getSelectedPlayer();
4003 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4004 SetSentErrorMessage(true);
4008 int area
= GetAreaFlagByAreaID(atoi((char*)args
));
4009 int offset
= area
/ 32;
4010 uint32 val
= (uint32
)(1 << (area
% 32));
4012 if(area
<0 || offset
>= 128)
4014 SendSysMessage(LANG_BAD_VALUE
);
4015 SetSentErrorMessage(true);
4019 uint32 currFields
= chr
->GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
4020 chr
->SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
| val
));
4022 SendSysMessage(LANG_EXPLORE_AREA
);
4026 bool ChatHandler::HandleHideAreaCommand(const char* args
)
4031 Player
*chr
= getSelectedPlayer();
4034 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4035 SetSentErrorMessage(true);
4039 int area
= GetAreaFlagByAreaID(atoi((char*)args
));
4040 int offset
= area
/ 32;
4041 uint32 val
= (uint32
)(1 << (area
% 32));
4043 if(area
<0 || offset
>= 128)
4045 SendSysMessage(LANG_BAD_VALUE
);
4046 SetSentErrorMessage(true);
4050 uint32 currFields
= chr
->GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
4051 chr
->SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
^ val
));
4053 SendSysMessage(LANG_UNEXPLORE_AREA
);
4057 bool ChatHandler::HandleDebugUpdate(const char* args
)
4065 char* pUpdateIndex
= strtok((char*)args
, " ");
4067 Unit
* chr
= getSelectedUnit();
4070 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4071 SetSentErrorMessage(true);
4079 updateIndex
= atoi(pUpdateIndex
);
4081 if(chr
->GetTypeId() == TYPEID_PLAYER
)
4083 if (updateIndex
>=PLAYER_END
) return true;
4087 if (updateIndex
>=UNIT_END
) return true;
4090 char* pvalue
= strtok(NULL
, " ");
4093 value
=chr
->GetUInt32Value(updateIndex
);
4095 PSendSysMessage(LANG_UPDATE
, chr
->GetGUIDLow(),updateIndex
,value
);
4101 PSendSysMessage(LANG_UPDATE_CHANGE
, chr
->GetGUIDLow(),updateIndex
,value
);
4103 chr
->SetUInt32Value(updateIndex
,value
);
4108 bool ChatHandler::HandleBankCommand(const char* /*args*/)
4110 m_session
->SendShowBank( m_session
->GetPlayer()->GetGUID() );
4115 bool ChatHandler::HandleChangeWeather(const char* args
)
4121 if (!sWorld
.getConfig(CONFIG_WEATHER
))
4123 SendSysMessage(LANG_WEATHER_DISABLED
);
4124 SetSentErrorMessage(true);
4128 //*Change the weather of a cell
4129 char* px
= strtok((char*)args
, " ");
4130 char* py
= strtok(NULL
, " ");
4135 uint32 type
= (uint32
)atoi(px
); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
4136 float grade
= (float)atof(py
); //0 to 1, sending -1 is instand good weather
4138 Player
*player
= m_session
->GetPlayer();
4139 uint32 zoneid
= player
->GetZoneId();
4141 Weather
* wth
= sWorld
.FindWeather(zoneid
);
4144 wth
= sWorld
.AddWeather(zoneid
);
4147 SendSysMessage(LANG_NO_WEATHER
);
4148 SetSentErrorMessage(true);
4152 wth
->SetWeather(WeatherType(type
), grade
);
4157 bool ChatHandler::HandleDebugSetValue(const char* args
)
4162 char* px
= strtok((char*)args
, " ");
4163 char* py
= strtok(NULL
, " ");
4164 char* pz
= strtok(NULL
, " ");
4169 Unit
* target
= getSelectedUnit();
4172 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4173 SetSentErrorMessage(true);
4177 uint64 guid
= target
->GetGUID();
4179 uint32 Opcode
= (uint32
)atoi(px
);
4180 if(Opcode
>= target
->GetValuesCount())
4182 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, GUID_LOPART(guid
), target
->GetValuesCount());
4187 bool isint32
= true;
4189 isint32
= (bool)atoi(pz
);
4192 iValue
= (uint32
)atoi(py
);
4193 sLog
.outDebug(GetMangosString(LANG_SET_UINT
), GUID_LOPART(guid
), Opcode
, iValue
);
4194 target
->SetUInt32Value( Opcode
, iValue
);
4195 PSendSysMessage(LANG_SET_UINT_FIELD
, GUID_LOPART(guid
), Opcode
,iValue
);
4199 fValue
= (float)atof(py
);
4200 sLog
.outDebug(GetMangosString(LANG_SET_FLOAT
), GUID_LOPART(guid
), Opcode
, fValue
);
4201 target
->SetFloatValue( Opcode
, fValue
);
4202 PSendSysMessage(LANG_SET_FLOAT_FIELD
, GUID_LOPART(guid
), Opcode
,fValue
);
4208 bool ChatHandler::HandleDebugGetValue(const char* args
)
4213 char* px
= strtok((char*)args
, " ");
4214 char* pz
= strtok(NULL
, " ");
4219 Unit
* target
= getSelectedUnit();
4222 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4223 SetSentErrorMessage(true);
4227 uint64 guid
= target
->GetGUID();
4229 uint32 Opcode
= (uint32
)atoi(px
);
4230 if(Opcode
>= target
->GetValuesCount())
4232 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, GUID_LOPART(guid
), target
->GetValuesCount());
4237 bool isint32
= true;
4239 isint32
= (bool)atoi(pz
);
4243 iValue
= target
->GetUInt32Value( Opcode
);
4244 sLog
.outDebug(GetMangosString(LANG_GET_UINT
), GUID_LOPART(guid
), Opcode
, iValue
);
4245 PSendSysMessage(LANG_GET_UINT_FIELD
, GUID_LOPART(guid
), Opcode
, iValue
);
4249 fValue
= target
->GetFloatValue( Opcode
);
4250 sLog
.outDebug(GetMangosString(LANG_GET_FLOAT
), GUID_LOPART(guid
), Opcode
, fValue
);
4251 PSendSysMessage(LANG_GET_FLOAT_FIELD
, GUID_LOPART(guid
), Opcode
, fValue
);
4257 bool ChatHandler::HandleSet32Bit(const char* args
)
4262 char* px
= strtok((char*)args
, " ");
4263 char* py
= strtok(NULL
, " ");
4268 uint32 Opcode
= (uint32
)atoi(px
);
4269 uint32 Value
= (uint32
)atoi(py
);
4270 if (Value
> 32) //uint32 = 32 bits
4273 sLog
.outDebug(GetMangosString(LANG_SET_32BIT
), Opcode
, Value
);
4275 m_session
->GetPlayer( )->SetUInt32Value( Opcode
, 2^Value
);
4277 PSendSysMessage(LANG_SET_32BIT_FIELD
, Opcode
,1);
4281 bool ChatHandler::HandleDebugMod32Value(const char* args
)
4286 char* px
= strtok((char*)args
, " ");
4287 char* py
= strtok(NULL
, " ");
4292 uint32 Opcode
= (uint32
)atoi(px
);
4293 int Value
= atoi(py
);
4295 if(Opcode
>= m_session
->GetPlayer()->GetValuesCount())
4297 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, m_session
->GetPlayer()->GetGUIDLow(), m_session
->GetPlayer( )->GetValuesCount());
4301 sLog
.outDebug(GetMangosString(LANG_CHANGE_32BIT
), Opcode
, Value
);
4303 int CurrentValue
= (int)m_session
->GetPlayer( )->GetUInt32Value( Opcode
);
4305 CurrentValue
+= Value
;
4306 m_session
->GetPlayer( )->SetUInt32Value( Opcode
, (uint32
)CurrentValue
);
4308 PSendSysMessage(LANG_CHANGE_32BIT_FIELD
, Opcode
,CurrentValue
);
4313 bool ChatHandler::HandleTeleAddCommand(const char * args
)
4318 Player
*player
=m_session
->GetPlayer();
4322 std::string name
= args
;
4324 if(objmgr
.GetGameTele(name
))
4326 SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST
);
4327 SetSentErrorMessage(true);
4332 tele
.position_x
= player
->GetPositionX();
4333 tele
.position_y
= player
->GetPositionY();
4334 tele
.position_z
= player
->GetPositionZ();
4335 tele
.orientation
= player
->GetOrientation();
4336 tele
.mapId
= player
->GetMapId();
4339 if(objmgr
.AddGameTele(tele
))
4341 SendSysMessage(LANG_COMMAND_TP_ADDED
);
4345 SendSysMessage(LANG_COMMAND_TP_ADDEDERR
);
4346 SetSentErrorMessage(true);
4353 bool ChatHandler::HandleTeleDelCommand(const char * args
)
4358 std::string name
= args
;
4360 if(!objmgr
.DeleteGameTele(name
))
4362 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
4363 SetSentErrorMessage(true);
4367 SendSysMessage(LANG_COMMAND_TP_DELETED
);
4371 bool ChatHandler::HandleListAurasCommand (const char * /*args*/)
4373 Unit
*unit
= getSelectedUnit();
4376 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4377 SetSentErrorMessage(true);
4381 char const* talentStr
= GetMangosString(LANG_TALENT
);
4382 char const* passiveStr
= GetMangosString(LANG_PASSIVE
);
4384 Unit::AuraMap
const& uAuras
= unit
->GetAuras();
4385 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS
, uAuras
.size());
4386 for (Unit::AuraMap::const_iterator itr
= uAuras
.begin(); itr
!= uAuras
.end(); ++itr
)
4388 bool talent
= GetTalentSpellCost(itr
->second
->GetId()) > 0;
4390 char const* name
= itr
->second
->GetSpellProto()->SpellName
[m_session
->GetSessionDbcLocale()];
4394 std::ostringstream ss_name
;
4395 ss_name
<< "|cffffffff|Hspell:" << itr
->second
->GetId() << "|h[" << name
<< "]|h|r";
4397 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL
, itr
->second
->GetId(), itr
->second
->GetEffIndex(),
4398 itr
->second
->GetModifier()->m_auraname
, itr
->second
->GetAuraDuration(), itr
->second
->GetAuraMaxDuration(),
4399 ss_name
.str().c_str(),
4400 (itr
->second
->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4401 IS_PLAYER_GUID(itr
->second
->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr
->second
->GetCasterGUID()));
4405 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL
, itr
->second
->GetId(), itr
->second
->GetEffIndex(),
4406 itr
->second
->GetModifier()->m_auraname
, itr
->second
->GetAuraDuration(), itr
->second
->GetAuraMaxDuration(),
4408 (itr
->second
->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4409 IS_PLAYER_GUID(itr
->second
->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr
->second
->GetCasterGUID()));
4412 for (int i
= 0; i
< TOTAL_AURAS
; i
++)
4414 Unit::AuraList
const& uAuraList
= unit
->GetAurasByType(AuraType(i
));
4415 if (uAuraList
.empty()) continue;
4416 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE
, uAuraList
.size(), i
);
4417 for (Unit::AuraList::const_iterator itr
= uAuraList
.begin(); itr
!= uAuraList
.end(); ++itr
)
4419 bool talent
= GetTalentSpellCost((*itr
)->GetId()) > 0;
4421 char const* name
= (*itr
)->GetSpellProto()->SpellName
[m_session
->GetSessionDbcLocale()];
4425 std::ostringstream ss_name
;
4426 ss_name
<< "|cffffffff|Hspell:" << (*itr
)->GetId() << "|h[" << name
<< "]|h|r";
4428 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE
, (*itr
)->GetId(), (*itr
)->GetEffIndex(),
4429 ss_name
.str().c_str(),((*itr
)->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4430 IS_PLAYER_GUID((*itr
)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr
)->GetCasterGUID()));
4434 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE
, (*itr
)->GetId(), (*itr
)->GetEffIndex(),
4435 name
,((*itr
)->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4436 IS_PLAYER_GUID((*itr
)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr
)->GetCasterGUID()));
4443 bool ChatHandler::HandleResetAchievementsCommand (const char * args
)
4445 char* pName
= strtok((char*)args
, "");
4446 Player
*player
= NULL
;
4450 std::string name
= extractPlayerNameFromLink(pName
);
4453 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4454 SetSentErrorMessage(true);
4458 guid
= objmgr
.GetPlayerGUIDByName(name
);
4459 player
= objmgr
.GetPlayer(guid
);
4463 player
= getSelectedPlayer();
4465 guid
= player
->GetGUID();
4468 if(!player
&& !guid
)
4470 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4475 player
->GetAchievementMgr().Reset();
4477 AchievementMgr::DeleteFromDB(GUID_LOPART(guid
));
4482 bool ChatHandler::HandleResetHonorCommand (const char * args
)
4484 char* pName
= strtok((char*)args
, "");
4485 Player
*player
= NULL
;
4488 std::string name
= extractPlayerNameFromLink(pName
);
4491 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4492 SetSentErrorMessage(true);
4496 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
);
4497 player
= objmgr
.GetPlayer(guid
);
4500 player
= getSelectedPlayer();
4504 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4508 player
->SetUInt32Value(PLAYER_FIELD_KILLS
, 0);
4509 player
->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS
, 0);
4510 player
->SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY
, 0);
4511 player
->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION
, 0);
4512 player
->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION
, 0);
4517 static bool HandleResetStatsOrLevelHelper(Player
* player
)
4519 PlayerInfo
const *info
= objmgr
.GetPlayerInfo(player
->getRace(), player
->getClass());
4520 if(!info
) return false;
4522 ChrClassesEntry
const* cEntry
= sChrClassesStore
.LookupEntry(player
->getClass());
4525 sLog
.outError("Class %u not found in DBC (Wrong DBC files?)",player
->getClass());
4529 uint8 powertype
= cEntry
->powerType
;
4531 // reset m_form if no aura
4532 if(!player
->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT
))
4533 player
->m_form
= FORM_NONE
;
4535 player
->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS
, DEFAULT_WORLD_OBJECT_SIZE
);
4536 player
->SetFloatValue(UNIT_FIELD_COMBATREACH
, 1.5f
);
4538 player
->setFactionForRace(player
->getRace());
4540 player
->SetUInt32Value(UNIT_FIELD_BYTES_0
, ( ( player
->getRace() ) | ( player
->getClass() << 8 ) | ( player
->getGender() << 16 ) | ( powertype
<< 24 ) ) );
4542 // reset only if player not in some form;
4543 if(player
->m_form
==FORM_NONE
)
4545 switch(player
->getGender())
4548 player
->SetDisplayId(info
->displayId_f
);
4549 player
->SetNativeDisplayId(info
->displayId_f
);
4552 player
->SetDisplayId(info
->displayId_m
);
4553 player
->SetNativeDisplayId(info
->displayId_m
);
4560 player
->SetByteValue(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_PVP
);
4561 player
->SetByteValue(UNIT_FIELD_BYTES_2
, 3, player
->m_form
);
4563 player
->SetUInt32Value(UNIT_FIELD_FLAGS
, UNIT_FLAG_PVP_ATTACKABLE
);
4565 //-1 is default value
4566 player
->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX
, uint32(-1));
4568 //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000 );
4572 bool ChatHandler::HandleResetLevelCommand(const char * args
)
4574 char* pName
= strtok((char*)args
, "");
4575 Player
*player
= NULL
;
4578 std::string name
= extractPlayerNameFromLink(pName
);
4581 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4582 SetSentErrorMessage(true);
4586 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
);
4587 player
= objmgr
.GetPlayer(guid
);
4590 player
= getSelectedPlayer();
4594 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4595 SetSentErrorMessage(true);
4599 if(!HandleResetStatsOrLevelHelper(player
))
4602 // set starting level
4603 uint32 start_level
= player
->getClass() != CLASS_DEATH_KNIGHT
4604 ? sWorld
.getConfig(CONFIG_START_PLAYER_LEVEL
)
4605 : sWorld
.getConfig(CONFIG_START_HEROIC_PLAYER_LEVEL
);
4607 player
->SetLevel(start_level
);
4608 player
->InitRunes();
4609 player
->InitStatsForLevel(true);
4610 player
->InitTaxiNodesForLevel();
4611 player
->InitGlyphsForLevel();
4612 player
->InitTalentForLevel();
4613 player
->SetUInt32Value(PLAYER_XP
,0);
4615 // reset level to summoned pet
4616 Pet
* pet
= player
->GetPet();
4617 if(pet
&& pet
->getPetType()==SUMMON_PET
)
4619 pet
->InitStatsForLevel(1);
4620 pet
->InitTalentForLevel();
4625 bool ChatHandler::HandleResetStatsCommand(const char * args
)
4627 char* pName
= strtok((char*)args
, "");
4628 Player
*player
= NULL
;
4631 std::string name
= extractPlayerNameFromLink(pName
);
4634 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4635 SetSentErrorMessage(true);
4639 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
);
4640 player
= objmgr
.GetPlayer(guid
);
4643 player
= getSelectedPlayer();
4647 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4648 SetSentErrorMessage(true);
4652 if(!HandleResetStatsOrLevelHelper(player
))
4655 player
->InitRunes();
4656 player
->InitStatsForLevel(true);
4657 player
->InitTaxiNodesForLevel();
4658 player
->InitGlyphsForLevel();
4659 player
->InitTalentForLevel();
4664 bool ChatHandler::HandleResetSpellsCommand(const char * args
)
4666 char* pName
= strtok((char*)args
, "");
4667 Player
*player
= NULL
;
4668 uint64 playerGUID
= 0;
4671 std::string name
= extractPlayerNameFromLink(pName
);
4674 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4675 SetSentErrorMessage(true);
4679 player
= objmgr
.GetPlayer(name
.c_str());
4681 playerGUID
= objmgr
.GetPlayerGUIDByName(name
);
4684 player
= getSelectedPlayer();
4686 if(!player
&& !playerGUID
)
4688 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4689 SetSentErrorMessage(true);
4695 player
->resetSpells();
4697 ChatHandler(player
).SendSysMessage(LANG_RESET_SPELLS
);
4698 if(m_session
->GetPlayer()!=player
)
4699 PSendSysMessage(LANG_RESET_SPELLS_ONLINE
,GetNameLink(player
).c_str());
4703 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS
), GUID_LOPART(playerGUID
));
4704 PSendSysMessage(LANG_RESET_SPELLS_OFFLINE
,pName
);
4710 bool ChatHandler::HandleResetTalentsCommand(const char * args
)
4712 char* pName
= strtok((char*)args
, "");
4713 Player
*player
= NULL
;
4714 uint64 playerGUID
= 0;
4717 std::string name
= extractPlayerNameFromLink(pName
);
4720 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4721 SetSentErrorMessage(true);
4725 player
= objmgr
.GetPlayer(name
.c_str());
4727 playerGUID
= objmgr
.GetPlayerGUIDByName(name
);
4730 player
= getSelectedPlayer();
4734 player
->resetTalents(true);
4736 ChatHandler(player
).SendSysMessage(LANG_RESET_TALENTS
);
4737 if(m_session
->GetPlayer()!=player
)
4738 PSendSysMessage(LANG_RESET_TALENTS_ONLINE
,GetNameLink(player
).c_str());
4742 else if (playerGUID
)
4744 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_TALENTS
), GUID_LOPART(playerGUID
) );
4745 std::string nameLink
= playerLink(pName
);
4746 PSendSysMessage(LANG_RESET_TALENTS_OFFLINE
,nameLink
.c_str());
4749 // Try reset talenents as Hunter Pet
4750 Creature
* creature
= getSelectedCreature();
4751 if (creature
&& creature
->isPet() && ((Pet
*)creature
)->getPetType() == HUNTER_PET
)
4753 ((Pet
*)creature
)->resetTalents(true);
4754 Unit
*owner
= creature
->GetOwner();
4755 if (owner
&& owner
->GetTypeId() == TYPEID_PLAYER
)
4757 player
= (Player
*)owner
;
4758 ChatHandler(player
).SendSysMessage(LANG_RESET_PET_TALENTS
);
4759 if(m_session
->GetPlayer()!=player
)
4760 PSendSysMessage(LANG_RESET_PET_TALENTS_ONLINE
,GetNameLink(player
).c_str());
4765 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4766 SetSentErrorMessage(true);
4770 bool ChatHandler::HandleResetAllCommand(const char * args
)
4775 std::string casename
= args
;
4777 AtLoginFlags atLogin
;
4779 // Command specially created as single command to prevent using short case names
4780 if(casename
=="spells")
4782 atLogin
= AT_LOGIN_RESET_SPELLS
;
4783 sWorld
.SendWorldText(LANG_RESETALL_SPELLS
);
4785 else if(casename
=="talents")
4787 atLogin
= AT_LOGIN_RESET_TALENTS
;
4788 sWorld
.SendWorldText(LANG_RESETALL_TALENTS
);
4792 PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE
,args
);
4793 SetSentErrorMessage(true);
4797 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE (at_login & '%u') = '0'",atLogin
,atLogin
);
4798 HashMapHolder
<Player
>::MapType
const& plist
= ObjectAccessor::Instance().GetPlayers();
4799 for(HashMapHolder
<Player
>::MapType::const_iterator itr
= plist
.begin(); itr
!= plist
.end(); ++itr
)
4800 itr
->second
->SetAtLoginFlag(atLogin
);
4805 bool ChatHandler::HandleServerShutDownCancelCommand(const char* args
)
4807 sWorld
.ShutdownCancel();
4811 bool ChatHandler::HandleServerShutDownCommand(const char* args
)
4816 char* time_str
= strtok ((char*) args
, " ");
4817 char* exitcode_str
= strtok (NULL
, "");
4819 int32 time
= atoi (time_str
);
4821 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4822 if(time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0') || time
< 0)
4827 int32 exitcode
= atoi (exitcode_str
);
4829 // Handle atoi() errors
4830 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4833 // Exit code should be in range of 0-125, 126-255 is used
4834 // in many shells for their own return codes and code > 255
4835 // is not supported in many others
4836 if (exitcode
< 0 || exitcode
> 125)
4839 sWorld
.ShutdownServ (time
, 0, exitcode
);
4842 sWorld
.ShutdownServ(time
,0,SHUTDOWN_EXIT_CODE
);
4846 bool ChatHandler::HandleServerRestartCommand(const char* args
)
4851 char* time_str
= strtok ((char*) args
, " ");
4852 char* exitcode_str
= strtok (NULL
, "");
4854 int32 time
= atoi (time_str
);
4856 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4857 if(time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0') || time
< 0)
4862 int32 exitcode
= atoi (exitcode_str
);
4864 // Handle atoi() errors
4865 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4868 // Exit code should be in range of 0-125, 126-255 is used
4869 // in many shells for their own return codes and code > 255
4870 // is not supported in many others
4871 if (exitcode
< 0 || exitcode
> 125)
4874 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_RESTART
, exitcode
);
4877 sWorld
.ShutdownServ(time
, SHUTDOWN_MASK_RESTART
, RESTART_EXIT_CODE
);
4881 bool ChatHandler::HandleServerIdleRestartCommand(const char* args
)
4886 char* time_str
= strtok ((char*) args
, " ");
4887 char* exitcode_str
= strtok (NULL
, "");
4889 int32 time
= atoi (time_str
);
4891 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4892 if(time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0') || time
< 0)
4897 int32 exitcode
= atoi (exitcode_str
);
4899 // Handle atoi() errors
4900 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4903 // Exit code should be in range of 0-125, 126-255 is used
4904 // in many shells for their own return codes and code > 255
4905 // is not supported in many others
4906 if (exitcode
< 0 || exitcode
> 125)
4909 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_RESTART
|SHUTDOWN_MASK_IDLE
, exitcode
);
4912 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_RESTART
|SHUTDOWN_MASK_IDLE
,RESTART_EXIT_CODE
);
4916 bool ChatHandler::HandleServerIdleShutDownCommand(const char* args
)
4921 char* time_str
= strtok ((char*) args
, " ");
4922 char* exitcode_str
= strtok (NULL
, "");
4924 int32 time
= atoi (time_str
);
4926 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4927 if(time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0') || time
< 0)
4932 int32 exitcode
= atoi (exitcode_str
);
4934 // Handle atoi() errors
4935 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4938 // Exit code should be in range of 0-125, 126-255 is used
4939 // in many shells for their own return codes and code > 255
4940 // is not supported in many others
4941 if (exitcode
< 0 || exitcode
> 125)
4944 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_IDLE
, exitcode
);
4947 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_IDLE
,SHUTDOWN_EXIT_CODE
);
4951 bool ChatHandler::HandleQuestAdd(const char* args
)
4953 Player
* player
= getSelectedPlayer();
4956 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4957 SetSentErrorMessage(true);
4961 // .addquest #entry'
4962 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4963 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4967 uint32 entry
= atol(cId
);
4969 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
4973 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
,entry
);
4974 SetSentErrorMessage(true);
4978 // check item starting quest (it can work incorrectly if added without item in inventory)
4979 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
4981 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
4985 if (pProto
->StartQuest
== entry
)
4987 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM
, entry
, pProto
->ItemId
);
4988 SetSentErrorMessage(true);
4993 // ok, normal (creature/GO starting) quest
4994 if( player
->CanAddQuest( pQuest
, true ) )
4996 player
->AddQuest( pQuest
, NULL
);
4998 if ( player
->CanCompleteQuest( entry
) )
4999 player
->CompleteQuest( entry
);
5005 bool ChatHandler::HandleQuestRemove(const char* args
)
5007 Player
* player
= getSelectedPlayer();
5010 SendSysMessage(LANG_NO_CHAR_SELECTED
);
5011 SetSentErrorMessage(true);
5015 // .removequest #entry'
5016 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
5017 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
5021 uint32 entry
= atol(cId
);
5023 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
5027 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
5028 SetSentErrorMessage(true);
5032 // remove all quest entries for 'entry' from quest log
5033 for(uint8 slot
= 0; slot
< MAX_QUEST_LOG_SIZE
; ++slot
)
5035 uint32 quest
= player
->GetQuestSlotQuestId(slot
);
5038 player
->SetQuestSlot(slot
,0);
5040 // we ignore unequippable quest items in this case, its' still be equipped
5041 player
->TakeQuestSourceItem( quest
, false );
5045 // set quest status to not started (will updated in DB at next save)
5046 player
->SetQuestStatus( entry
, QUEST_STATUS_NONE
);
5048 // reset rewarded for restart repeatable quest
5049 player
->getQuestStatusMap()[entry
].m_rewarded
= false;
5051 SendSysMessage(LANG_COMMAND_QUEST_REMOVED
);
5055 bool ChatHandler::HandleQuestComplete(const char* args
)
5057 Player
* player
= getSelectedPlayer();
5060 SendSysMessage(LANG_NO_CHAR_SELECTED
);
5061 SetSentErrorMessage(true);
5065 // .quest complete #entry
5066 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
5067 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
5071 uint32 entry
= atol(cId
);
5073 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
5075 // If player doesn't have the quest
5076 if(!pQuest
|| player
->GetQuestStatus(entry
) == QUEST_STATUS_NONE
)
5078 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
5079 SetSentErrorMessage(true);
5083 // Add quest items for quests that require items
5084 for(uint8 x
= 0; x
< QUEST_OBJECTIVES_COUNT
; ++x
)
5086 uint32 id
= pQuest
->ReqItemId
[x
];
5087 uint32 count
= pQuest
->ReqItemCount
[x
];
5091 uint32 curItemCount
= player
->GetItemCount(id
,true);
5093 ItemPosCountVec dest
;
5094 uint8 msg
= player
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, id
, count
-curItemCount
);
5095 if( msg
== EQUIP_ERR_OK
)
5097 Item
* item
= player
->StoreNewItem( dest
, id
, true);
5098 player
->SendNewItem(item
,count
-curItemCount
,true,false);
5102 // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
5103 for(uint8 i
= 0; i
< QUEST_OBJECTIVES_COUNT
; i
++)
5105 uint32 creature
= pQuest
->ReqCreatureOrGOId
[i
];
5106 uint32 creaturecount
= pQuest
->ReqCreatureOrGOCount
[i
];
5108 if(uint32 spell_id
= pQuest
->ReqSpell
[i
])
5110 for(uint16 z
= 0; z
< creaturecount
; ++z
)
5111 player
->CastedCreatureOrGO(creature
,0,spell_id
);
5113 else if(creature
> 0)
5115 for(uint16 z
= 0; z
< creaturecount
; ++z
)
5116 player
->KilledMonster(creature
,0);
5118 else if(creature
< 0)
5120 for(uint16 z
= 0; z
< creaturecount
; ++z
)
5121 player
->CastedCreatureOrGO(creature
,0,0);
5125 // If the quest requires reputation to complete
5126 if(uint32 repFaction
= pQuest
->GetRepObjectiveFaction())
5128 uint32 repValue
= pQuest
->GetRepObjectiveValue();
5129 uint32 curRep
= player
->GetReputationMgr().GetReputation(repFaction
);
5130 if(curRep
< repValue
)
5131 if(FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry(repFaction
))
5132 player
->GetReputationMgr().SetReputation(factionEntry
,repValue
);
5135 // If the quest requires money
5136 int32 ReqOrRewMoney
= pQuest
->GetRewOrReqMoney();
5137 if(ReqOrRewMoney
< 0)
5138 player
->ModifyMoney(-ReqOrRewMoney
);
5140 player
->CompleteQuest(entry
);
5144 bool ChatHandler::HandleBanAccountCommand(const char* args
)
5146 return HandleBanHelper(BAN_ACCOUNT
,args
);
5149 bool ChatHandler::HandleBanCharacterCommand(const char* args
)
5151 return HandleBanHelper(BAN_CHARACTER
,args
);
5154 bool ChatHandler::HandleBanIPCommand(const char* args
)
5156 return HandleBanHelper(BAN_IP
,args
);
5159 bool ChatHandler::HandleBanHelper(BanMode mode
, const char* args
)
5164 char* cnameOrIP
= strtok ((char*)args
, " ");
5168 std::string nameOrIP
= cnameOrIP
;
5170 char* duration
= strtok (NULL
," ");
5171 if(!duration
|| !atoi(duration
))
5174 char* reason
= strtok (NULL
,"");
5181 if(!AccountMgr::normilizeString(nameOrIP
))
5183 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
5184 SetSentErrorMessage(true);
5189 if(!normalizePlayerName(nameOrIP
))
5191 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5192 SetSentErrorMessage(true);
5197 if(!IsIPAddress(nameOrIP
.c_str()))
5202 switch(sWorld
.BanAccount(mode
, nameOrIP
, duration
, reason
,m_session
? m_session
->GetPlayerName() : ""))
5205 if(atoi(duration
)>0)
5206 PSendSysMessage(LANG_BAN_YOUBANNED
,nameOrIP
.c_str(),secsToTimeString(TimeStringToSecs(duration
),true).c_str(),reason
);
5208 PSendSysMessage(LANG_BAN_YOUPERMBANNED
,nameOrIP
.c_str(),reason
);
5210 case BAN_SYNTAX_ERROR
:
5216 PSendSysMessage(LANG_BAN_NOTFOUND
,"account",nameOrIP
.c_str());
5219 PSendSysMessage(LANG_BAN_NOTFOUND
,"character",nameOrIP
.c_str());
5222 PSendSysMessage(LANG_BAN_NOTFOUND
,"ip",nameOrIP
.c_str());
5225 SetSentErrorMessage(true);
5232 bool ChatHandler::HandleUnBanAccountCommand(const char* args
)
5234 return HandleUnBanHelper(BAN_ACCOUNT
,args
);
5237 bool ChatHandler::HandleUnBanCharacterCommand(const char* args
)
5239 return HandleUnBanHelper(BAN_CHARACTER
,args
);
5242 bool ChatHandler::HandleUnBanIPCommand(const char* args
)
5244 return HandleUnBanHelper(BAN_IP
,args
);
5247 bool ChatHandler::HandleUnBanHelper(BanMode mode
, const char* args
)
5252 char* cnameOrIP
= strtok ((char*)args
, " ");
5256 std::string nameOrIP
= cnameOrIP
;
5261 if(!AccountMgr::normilizeString(nameOrIP
))
5263 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
5264 SetSentErrorMessage(true);
5269 if(!normalizePlayerName(nameOrIP
))
5271 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5272 SetSentErrorMessage(true);
5277 if(!IsIPAddress(nameOrIP
.c_str()))
5282 if(sWorld
.RemoveBanAccount(mode
,nameOrIP
))
5283 PSendSysMessage(LANG_UNBAN_UNBANNED
,nameOrIP
.c_str());
5285 PSendSysMessage(LANG_UNBAN_ERROR
,nameOrIP
.c_str());
5290 bool ChatHandler::HandleBanInfoAccountCommand(const char* args
)
5295 char* cname
= strtok((char*)args
, "");
5299 std::string account_name
= cname
;
5300 if(!AccountMgr::normilizeString(account_name
))
5302 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5303 SetSentErrorMessage(true);
5307 uint32 accountid
= accmgr
.GetId(account_name
);
5310 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5314 return HandleBanInfoHelper(accountid
,account_name
.c_str());
5317 bool ChatHandler::HandleBanInfoCharacterCommand(const char* args
)
5322 std::string name
= extractPlayerNameFromLink((char*)args
);
5325 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5326 SetSentErrorMessage(true);
5330 uint32 accountid
= objmgr
.GetPlayerAccountIdByPlayerName(name
);
5333 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5334 SetSentErrorMessage(true);
5338 std::string accountname
;
5339 if(!accmgr
.GetName(accountid
,accountname
))
5341 PSendSysMessage(LANG_BANINFO_NOCHARACTER
);
5345 return HandleBanInfoHelper(accountid
,accountname
.c_str());
5348 bool ChatHandler::HandleBanInfoHelper(uint32 accountid
, char const* accountname
)
5350 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
);
5353 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN
, accountname
);
5357 PSendSysMessage(LANG_BANINFO_BANHISTORY
,accountname
);
5360 Field
* fields
= result
->Fetch();
5362 time_t unbandate
= time_t(fields
[3].GetUInt64());
5363 bool active
= false;
5364 if(fields
[2].GetBool() && (fields
[1].GetUInt64() == (uint64
)0 ||unbandate
>= time(NULL
)) )
5366 bool permanent
= (fields
[1].GetUInt64() == (uint64
)0);
5367 std::string bantime
= permanent
?GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[1].GetUInt64(), true);
5368 PSendSysMessage(LANG_BANINFO_HISTORYENTRY
,
5369 fields
[0].GetString(), bantime
.c_str(), active
? GetMangosString(LANG_BANINFO_YES
):GetMangosString(LANG_BANINFO_NO
), fields
[4].GetString(), fields
[5].GetString());
5370 }while (result
->NextRow());
5376 bool ChatHandler::HandleBanInfoIPCommand(const char* args
)
5381 char* cIP
= strtok ((char*)args
, "");
5385 if (!IsIPAddress(cIP
))
5388 std::string IP
= cIP
;
5390 loginDatabase
.escape_string(IP
);
5391 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());
5394 PSendSysMessage(LANG_BANINFO_NOIP
);
5398 Field
*fields
= result
->Fetch();
5399 bool permanent
= !fields
[6].GetUInt64();
5400 PSendSysMessage(LANG_BANINFO_IPENTRY
,
5401 fields
[0].GetString(), fields
[1].GetString(), permanent
? GetMangosString(LANG_BANINFO_NEVER
):fields
[2].GetString(),
5402 permanent
? GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[3].GetUInt64(), true).c_str(), fields
[4].GetString(), fields
[5].GetString());
5407 bool ChatHandler::HandleBanListCharacterCommand(const char* args
)
5409 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5411 char* cFilter
= strtok ((char*)args
, " ");
5415 std::string filter
= cFilter
;
5416 loginDatabase
.escape_string(filter
);
5417 QueryResult
* result
= CharacterDatabase
.PQuery("SELECT account FROM characters WHERE name "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'"),filter
.c_str());
5420 PSendSysMessage(LANG_BANLIST_NOCHARACTER
);
5424 return HandleBanListHelper(result
);
5427 bool ChatHandler::HandleBanListAccountCommand(const char* args
)
5429 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5431 char* cFilter
= strtok((char*)args
, " ");
5432 std::string filter
= cFilter
? cFilter
: "";
5433 loginDatabase
.escape_string(filter
);
5435 QueryResult
* result
;
5439 result
= loginDatabase
.Query("SELECT account.id, username FROM account, account_banned"
5440 " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
5444 result
= loginDatabase
.PQuery("SELECT account.id, username FROM account, account_banned"
5445 " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
5451 PSendSysMessage(LANG_BANLIST_NOACCOUNT
);
5455 return HandleBanListHelper(result
);
5458 bool ChatHandler::HandleBanListHelper(QueryResult
* result
)
5460 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT
);
5462 // Chat short output
5467 Field
* fields
= result
->Fetch();
5468 uint32 accountid
= fields
[0].GetUInt32();
5470 QueryResult
* banresult
= loginDatabase
.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid
);
5473 Field
* fields2
= banresult
->Fetch();
5474 PSendSysMessage("%s",fields2
[0].GetString());
5477 } while (result
->NextRow());
5479 // Console wide output
5482 SendSysMessage(LANG_BANLIST_ACCOUNTS
);
5483 SendSysMessage("===============================================================================");
5484 SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER
);
5487 SendSysMessage("-------------------------------------------------------------------------------");
5488 Field
*fields
= result
->Fetch();
5489 uint32 account_id
= fields
[0].GetUInt32 ();
5491 std::string account_name
;
5493 // "account" case, name can be get in same query
5494 if(result
->GetFieldCount() > 1)
5495 account_name
= fields
[1].GetCppString();
5496 // "character" case, name need extract from another DB
5498 accmgr
.GetName (account_id
,account_name
);
5500 // No SQL injection. id is uint32.
5501 QueryResult
*banInfo
= loginDatabase
.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id
);
5504 Field
*fields2
= banInfo
->Fetch();
5507 time_t t_ban
= fields2
[0].GetUInt64();
5508 tm
* aTm_ban
= localtime(&t_ban
);
5510 if (fields2
[0].GetUInt64() == fields2
[1].GetUInt64())
5512 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5513 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
,
5514 fields2
[2].GetString(),fields2
[3].GetString());
5518 time_t t_unban
= fields2
[1].GetUInt64();
5519 tm
* aTm_unban
= localtime(&t_unban
);
5520 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5521 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
,
5522 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5523 fields2
[2].GetString(),fields2
[3].GetString());
5525 }while ( banInfo
->NextRow() );
5528 }while( result
->NextRow() );
5529 SendSysMessage("===============================================================================");
5536 bool ChatHandler::HandleBanListIPCommand(const char* args
)
5538 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5540 char* cFilter
= strtok((char*)args
, " ");
5541 std::string filter
= cFilter
? cFilter
: "";
5542 loginDatabase
.escape_string(filter
);
5544 QueryResult
* result
;
5548 result
= loginDatabase
.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5549 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
5550 " ORDER BY unbandate" );
5554 result
= loginDatabase
.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5555 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")
5556 " ORDER BY unbandate",filter
.c_str() );
5561 PSendSysMessage(LANG_BANLIST_NOIP
);
5565 PSendSysMessage(LANG_BANLIST_MATCHINGIP
);
5566 // Chat short output
5571 Field
* fields
= result
->Fetch();
5572 PSendSysMessage("%s",fields
[0].GetString());
5573 } while (result
->NextRow());
5575 // Console wide output
5578 SendSysMessage(LANG_BANLIST_IPS
);
5579 SendSysMessage("===============================================================================");
5580 SendSysMessage(LANG_BANLIST_IPS_HEADER
);
5583 SendSysMessage("-------------------------------------------------------------------------------");
5584 Field
*fields
= result
->Fetch();
5585 time_t t_ban
= fields
[1].GetUInt64();
5586 tm
* aTm_ban
= localtime(&t_ban
);
5587 if ( fields
[1].GetUInt64() == fields
[2].GetUInt64() )
5589 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5590 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
,
5591 fields
[3].GetString(), fields
[4].GetString());
5595 time_t t_unban
= fields
[2].GetUInt64();
5596 tm
* aTm_unban
= localtime(&t_unban
);
5597 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5598 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
,
5599 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5600 fields
[3].GetString(), fields
[4].GetString());
5602 }while( result
->NextRow() );
5603 SendSysMessage("===============================================================================");
5610 bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
5612 Player
* pl
= m_session
->GetPlayer();
5614 // accept only explicitly selected target (not implicitly self targeting case)
5615 Unit
* target
= getSelectedUnit();
5616 if(pl
->GetSelection() && target
)
5618 if(target
->GetTypeId()!=TYPEID_UNIT
)
5620 SendSysMessage(LANG_SELECT_CREATURE
);
5621 SetSentErrorMessage(true);
5625 if(target
->isDead())
5626 ((Creature
*)target
)->Respawn();
5630 CellPair
p(MaNGOS::ComputeCellPair(pl
->GetPositionX(), pl
->GetPositionY()));
5632 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
5635 MaNGOS::RespawnDo u_do
;
5636 MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
> worker(pl
,u_do
);
5638 TypeContainerVisitor
<MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
>, GridTypeMapContainer
> obj_worker(worker
);
5639 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
5640 cell_lock
->Visit(cell_lock
, obj_worker
, *pl
->GetMap());
5645 bool ChatHandler::HandleGMFlyCommand(const char* args
)
5650 Player
*target
= getSelectedPlayer();
5652 target
= m_session
->GetPlayer();
5654 WorldPacket
data(12);
5655 if (strncmp(args
, "on", 3) == 0)
5656 data
.SetOpcode(SMSG_MOVE_SET_CAN_FLY
);
5657 else if (strncmp(args
, "off", 4) == 0)
5658 data
.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY
);
5661 SendSysMessage(LANG_USE_BOL
);
5664 data
.append(target
->GetPackGUID());
5665 data
<< uint32(0); // unknown
5666 target
->SendMessageToSet(&data
, true);
5667 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS
, GetNameLink(target
).c_str(), args
);
5671 bool ChatHandler::HandlePDumpLoadCommand(const char *args
)
5676 char * file
= strtok((char*)args
, " ");
5680 char * account
= strtok(NULL
, " ");
5684 std::string account_name
= account
;
5685 if(!AccountMgr::normilizeString(account_name
))
5687 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5688 SetSentErrorMessage(true);
5692 uint32 account_id
= accmgr
.GetId(account_name
);
5695 account_id
= atoi(account
); // use original string
5698 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5699 SetSentErrorMessage(true);
5704 if(!accmgr
.GetName(account_id
,account_name
))
5706 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5707 SetSentErrorMessage(true);
5711 char* guid_str
= NULL
;
5712 char* name_str
= strtok(NULL
, " ");
5718 // normalize the name if specified and check if it exists
5719 if(!normalizePlayerName(name
))
5721 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5722 SetSentErrorMessage(true);
5726 if(!ObjectMgr::IsValidName(name
,true))
5728 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5729 SetSentErrorMessage(true);
5733 guid_str
= strtok(NULL
, " ");
5740 guid
= atoi(guid_str
);
5743 PSendSysMessage(LANG_INVALID_CHARACTER_GUID
);
5744 SetSentErrorMessage(true);
5748 if(objmgr
.GetPlayerAccountIdByGUID(guid
))
5750 PSendSysMessage(LANG_CHARACTER_GUID_IN_USE
,guid
);
5751 SetSentErrorMessage(true);
5756 switch(PlayerDumpReader().LoadDump(file
, account_id
, name
, guid
))
5759 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS
);
5761 case DUMP_FILE_OPEN_ERROR
:
5762 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
5763 SetSentErrorMessage(true);
5765 case DUMP_FILE_BROKEN
:
5766 PSendSysMessage(LANG_DUMP_BROKEN
,file
);
5767 SetSentErrorMessage(true);
5769 case DUMP_TOO_MANY_CHARS
:
5770 PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL
,account_name
.c_str(),account_id
);
5771 SetSentErrorMessage(true);
5774 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED
);
5775 SetSentErrorMessage(true);
5782 bool ChatHandler::HandlePDumpWriteCommand(const char *args
)
5787 char* file
= strtok((char*)args
, " ");
5788 char* p2
= strtok(NULL
, " ");
5794 // character name can't start from number
5795 if (isNumeric(p2
[0]))
5799 std::string name
= extractPlayerNameFromLink(p2
);
5802 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5803 SetSentErrorMessage(true);
5807 guid
= objmgr
.GetPlayerGUIDByName(name
);
5810 if(!objmgr
.GetPlayerAccountIdByGUID(guid
))
5812 PSendSysMessage(LANG_PLAYER_NOT_FOUND
);
5813 SetSentErrorMessage(true);
5817 switch(PlayerDumpWriter().WriteDump(file
, guid
))
5820 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS
);
5822 case DUMP_FILE_OPEN_ERROR
:
5823 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
5824 SetSentErrorMessage(true);
5827 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED
);
5828 SetSentErrorMessage(true);
5835 bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
5837 Unit
* unit
= getSelectedUnit();
5840 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5841 SetSentErrorMessage(true);
5845 PSendSysMessage(LANG_MOVEGENS_LIST
,(unit
->GetTypeId()==TYPEID_PLAYER
? "Player" : "Creature" ),unit
->GetGUIDLow());
5847 MotionMaster
* mm
= unit
->GetMotionMaster();
5848 for(MotionMaster::const_iterator itr
= mm
->begin(); itr
!= mm
->end(); ++itr
)
5850 switch((*itr
)->GetMovementGeneratorType())
5852 case IDLE_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_IDLE
); break;
5853 case RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_RANDOM
); break;
5854 case WAYPOINT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_WAYPOINT
); break;
5855 case ANIMAL_RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_ANIMAL_RANDOM
); break;
5856 case CONFUSED_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_CONFUSED
); break;
5857 case TARGETED_MOTION_TYPE
:
5859 if(unit
->GetTypeId()==TYPEID_PLAYER
)
5861 TargetedMovementGenerator
<Player
> const* mgen
= static_cast<TargetedMovementGenerator
<Player
> const*>(*itr
);
5862 Unit
* target
= mgen
->GetTarget();
5864 PSendSysMessage(LANG_MOVEGENS_TARGETED_PLAYER
,target
->GetName(),target
->GetGUIDLow());
5866 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL
);
5870 TargetedMovementGenerator
<Creature
> const* mgen
= static_cast<TargetedMovementGenerator
<Creature
> const*>(*itr
);
5871 Unit
* target
= mgen
->GetTarget();
5873 PSendSysMessage(LANG_MOVEGENS_TARGETED_CREATURE
,target
->GetName(),target
->GetGUIDLow());
5875 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL
);
5879 case HOME_MOTION_TYPE
:
5880 if(unit
->GetTypeId()==TYPEID_UNIT
)
5883 (*itr
)->GetDestination(x
,y
,z
);
5884 PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE
,x
,y
,z
);
5887 SendSysMessage(LANG_MOVEGENS_HOME_PLAYER
);
5889 case FLIGHT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FLIGHT
); break;
5890 case POINT_MOTION_TYPE
:
5893 (*itr
)->GetDestination(x
,y
,z
);
5894 PSendSysMessage(LANG_MOVEGENS_POINT
,x
,y
,z
);
5897 case FLEEING_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FEAR
); break;
5898 case DISTRACT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_DISTRACT
); break;
5900 PSendSysMessage(LANG_MOVEGENS_UNKNOWN
,(*itr
)->GetMovementGeneratorType());
5907 bool ChatHandler::HandlePLimitCommand(const char *args
)
5911 char* param
= strtok((char*)args
, " ");
5915 int l
= strlen(param
);
5917 if( strncmp(param
,"player",l
) == 0 )
5918 sWorld
.SetPlayerLimit(-SEC_PLAYER
);
5919 else if(strncmp(param
,"moderator",l
) == 0 )
5920 sWorld
.SetPlayerLimit(-SEC_MODERATOR
);
5921 else if(strncmp(param
,"gamemaster",l
) == 0 )
5922 sWorld
.SetPlayerLimit(-SEC_GAMEMASTER
);
5923 else if(strncmp(param
,"administrator",l
) == 0 )
5924 sWorld
.SetPlayerLimit(-SEC_ADMINISTRATOR
);
5925 else if(strncmp(param
,"reset",l
) == 0 )
5926 sWorld
.SetPlayerLimit( sConfig
.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT
) );
5929 int val
= atoi(param
);
5930 if(val
< -SEC_ADMINISTRATOR
) val
= -SEC_ADMINISTRATOR
;
5932 sWorld
.SetPlayerLimit(val
);
5935 // kick all low security level players
5936 if(sWorld
.GetPlayerAmountLimit() > SEC_PLAYER
)
5937 sWorld
.KickAllLess(sWorld
.GetPlayerSecurityLimit());
5940 uint32 pLimit
= sWorld
.GetPlayerAmountLimit();
5941 AccountTypes allowedAccountType
= sWorld
.GetPlayerSecurityLimit();
5942 char const* secName
= "";
5943 switch(allowedAccountType
)
5945 case SEC_PLAYER
: secName
= "Player"; break;
5946 case SEC_MODERATOR
: secName
= "Moderator"; break;
5947 case SEC_GAMEMASTER
: secName
= "Gamemaster"; break;
5948 case SEC_ADMINISTRATOR
: secName
= "Administrator"; break;
5949 default: secName
= "<unknown>"; break;
5952 PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit
,secName
);
5957 bool ChatHandler::HandleCastCommand(const char* args
)
5962 Unit
* target
= getSelectedUnit();
5966 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5967 SetSentErrorMessage(true);
5971 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5972 uint32 spell
= extractSpellIdFromLink((char*)args
);
5976 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5980 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5982 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5983 SetSentErrorMessage(true);
5987 char* trig_str
= strtok(NULL
, " ");
5990 int l
= strlen(trig_str
);
5991 if(strncmp(trig_str
,"triggered",l
) != 0 )
5995 bool triggered
= (trig_str
!= NULL
);
5997 m_session
->GetPlayer()->CastSpell(target
,spell
,triggered
);
6002 bool ChatHandler::HandleCastBackCommand(const char* args
)
6004 Creature
* caster
= getSelectedCreature();
6008 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
6009 SetSentErrorMessage(true);
6013 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
6014 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6015 uint32 spell
= extractSpellIdFromLink((char*)args
);
6016 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
6019 char* trig_str
= strtok(NULL
, " ");
6022 int l
= strlen(trig_str
);
6023 if(strncmp(trig_str
,"triggered",l
) != 0 )
6027 bool triggered
= (trig_str
!= NULL
);
6029 // update orientation at server
6030 caster
->SetOrientation(caster
->GetAngle(m_session
->GetPlayer()));
6034 caster
->BuildHeartBeatMsg(&data
);
6035 caster
->SendMessageToSet(&data
,true);
6037 caster
->CastSpell(m_session
->GetPlayer(),spell
,triggered
);
6042 bool ChatHandler::HandleCastDistCommand(const char* args
)
6047 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6048 uint32 spell
= extractSpellIdFromLink((char*)args
);
6052 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
6056 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
6058 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
6059 SetSentErrorMessage(true);
6063 char *distStr
= strtok(NULL
, " ");
6068 sscanf(distStr
, "%f", &dist
);
6070 char* trig_str
= strtok(NULL
, " ");
6073 int l
= strlen(trig_str
);
6074 if(strncmp(trig_str
,"triggered",l
) != 0 )
6078 bool triggered
= (trig_str
!= NULL
);
6081 m_session
->GetPlayer()->GetClosePoint(x
,y
,z
,dist
);
6083 m_session
->GetPlayer()->CastSpell(x
,y
,z
,spell
,triggered
);
6087 bool ChatHandler::HandleCastTargetCommand(const char* args
)
6089 Creature
* caster
= getSelectedCreature();
6093 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
6094 SetSentErrorMessage(true);
6098 if(!caster
->getVictim())
6100 SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM
);
6101 SetSentErrorMessage(true);
6105 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6106 uint32 spell
= extractSpellIdFromLink((char*)args
);
6107 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
6110 char* trig_str
= strtok(NULL
, " ");
6113 int l
= strlen(trig_str
);
6114 if(strncmp(trig_str
,"triggered",l
) != 0 )
6118 bool triggered
= (trig_str
!= NULL
);
6120 // update orientation at server
6121 caster
->SetOrientation(caster
->GetAngle(m_session
->GetPlayer()));
6125 caster
->BuildHeartBeatMsg(&data
);
6126 caster
->SendMessageToSet(&data
,true);
6128 caster
->CastSpell(caster
->getVictim(),spell
,triggered
);
6134 ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
6135 Without this function 3rd party scripting library will get linking errors (unresolved external)
6136 when attempting to use the PointMovementGenerator
6138 bool ChatHandler::HandleComeToMeCommand(const char *args
)
6140 Creature
* caster
= getSelectedCreature();
6144 SendSysMessage(LANG_SELECT_CREATURE
);
6145 SetSentErrorMessage(true);
6149 char* newFlagStr
= strtok((char*)args
, " ");
6154 uint32 newFlags
= atoi(newFlagStr
);
6156 caster
->SetUnitMovementFlags(newFlags
);
6158 Player
* pl
= m_session
->GetPlayer();
6160 caster
->GetMotionMaster()->MovePoint(0, pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ());
6164 bool ChatHandler::HandleCastSelfCommand(const char* args
)
6169 Unit
* target
= getSelectedUnit();
6173 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
6174 SetSentErrorMessage(true);
6178 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6179 uint32 spell
= extractSpellIdFromLink((char*)args
);
6183 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
6187 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
6189 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
6190 SetSentErrorMessage(true);
6194 target
->CastSpell(target
,spell
,false);
6199 std::string
GetTimeString(uint32 time
)
6201 uint16 days
= time
/ DAY
, hours
= (time
% DAY
) / HOUR
, minute
= (time
% HOUR
) / MINUTE
;
6202 std::ostringstream ss
;
6203 if(days
) ss
<< days
<< "d ";
6204 if(hours
) ss
<< hours
<< "h ";
6205 ss
<< minute
<< "m";
6209 bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
6211 Player
* player
= getSelectedPlayer();
6212 if (!player
) player
= m_session
->GetPlayer();
6214 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
6216 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(i
);
6217 for(Player::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
6219 InstanceSave
*save
= itr
->second
.save
;
6220 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
6221 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());
6225 PSendSysMessage("player binds: %d", counter
);
6227 Group
*group
= player
->GetGroup();
6230 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
6232 Group::BoundInstancesMap
&binds
= group
->GetBoundInstances(i
);
6233 for(Group::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
6235 InstanceSave
*save
= itr
->second
.save
;
6236 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
6237 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());
6242 PSendSysMessage("group binds: %d", counter
);
6247 bool ChatHandler::HandleInstanceUnbindCommand(const char* args
)
6252 std::string cmd
= args
;
6255 Player
* player
= getSelectedPlayer();
6256 if (!player
) player
= m_session
->GetPlayer();
6258 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
6260 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(i
);
6261 for(Player::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end();)
6263 if(itr
->first
!= player
->GetMapId())
6265 InstanceSave
*save
= itr
->second
.save
;
6266 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
6267 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());
6268 player
->UnbindInstance(itr
, i
);
6275 PSendSysMessage("instances unbound: %d", counter
);
6280 bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
6282 PSendSysMessage("instances loaded: %d", MapManager::Instance().GetNumInstances());
6283 PSendSysMessage("players in instances: %d", MapManager::Instance().GetNumPlayersInInstances());
6284 PSendSysMessage("instance saves: %d", sInstanceSaveManager
.GetNumInstanceSaves());
6285 PSendSysMessage("players bound: %d", sInstanceSaveManager
.GetNumBoundPlayersTotal());
6286 PSendSysMessage("groups bound: %d", sInstanceSaveManager
.GetNumBoundGroupsTotal());
6290 bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
6292 Player
* pl
= m_session
->GetPlayer();
6294 Map
* map
= pl
->GetMap();
6295 if (!map
->IsDungeon())
6297 PSendSysMessage("Map is not a dungeon.");
6298 SetSentErrorMessage(true);
6302 if (!((InstanceMap
*)map
)->GetInstanceData())
6304 PSendSysMessage("Map has no instance data.");
6305 SetSentErrorMessage(true);
6309 ((InstanceMap
*)map
)->GetInstanceData()->SaveToDB();
6313 /// Display the list of GMs
6314 bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
6316 ///- Get the accounts with GM Level >0
6317 QueryResult
*result
= loginDatabase
.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
6320 SendSysMessage(LANG_GMLIST
);
6321 SendSysMessage("========================");
6322 SendSysMessage(LANG_GMLIST_HEADER
);
6323 SendSysMessage("========================");
6325 ///- Circle through them. Display username and GM level
6328 Field
*fields
= result
->Fetch();
6329 PSendSysMessage("|%15s|%6s|", fields
[0].GetString(),fields
[1].GetString());
6330 }while( result
->NextRow() );
6332 PSendSysMessage("========================");
6336 PSendSysMessage(LANG_GMLIST_EMPTY
);
6340 /// Define the 'Message of the day' for the realm
6341 bool ChatHandler::HandleServerSetMotdCommand(const char* args
)
6343 sWorld
.SetMotd(args
);
6344 PSendSysMessage(LANG_MOTD_NEW
, args
);
6348 /// Set/Unset the expansion level for an account
6349 bool ChatHandler::HandleAccountSetAddonCommand(const char* args
)
6351 ///- Get the command line arguments
6352 char *szAcc
= strtok((char*)args
," ");
6353 char *szExp
= strtok(NULL
," ");
6358 std::string account_name
;
6363 Player
* player
= getSelectedPlayer();
6367 account_id
= player
->GetSession()->GetAccountId();
6368 accmgr
.GetName(account_id
,account_name
);
6373 ///- Convert Account name to Upper Format
6374 account_name
= szAcc
;
6375 if(!AccountMgr::normilizeString(account_name
))
6377 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
6378 SetSentErrorMessage(true);
6382 account_id
= accmgr
.GetId(account_name
);
6385 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
6386 SetSentErrorMessage(true);
6392 // Let set addon state only for lesser (strong) security level
6393 // or to self account
6394 if (m_session
&& m_session
->GetAccountId () != account_id
&&
6395 HasLowerSecurityAccount (NULL
,account_id
,true))
6398 int lev
=atoi(szExp
); //get int anyway (0 if error)
6403 loginDatabase
.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev
,account_id
);
6404 PSendSysMessage(LANG_ACCOUNT_SETADDON
,account_name
.c_str(),account_id
,lev
);
6408 //Send items by mail
6409 bool ChatHandler::HandleSendItemsCommand(const char* args
)
6414 // format: name "subject text" "mail text" item1[:count1] item2[:count2] ... item12[:count12]
6416 std::string name
= extractPlayerNameFromLink((char*)args
);
6419 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6420 SetSentErrorMessage(true);
6424 char* tail1
= strtok(NULL
, "");
6430 msgSubject
= strtok(tail1
+1, "\"");
6433 char* space
= strtok(tail1
, "\"");
6436 msgSubject
= strtok(NULL
, "\"");
6442 char* tail2
= strtok(NULL
, "");
6448 msgText
= strtok(tail2
+1, "\"");
6451 char* space
= strtok(tail2
, "\"");
6454 msgText
= strtok(NULL
, "\"");
6460 // msgSubject, msgText isn't NUL after prev. check
6461 std::string subject
= msgSubject
;
6462 std::string text
= msgText
;
6465 typedef std::pair
<uint32
,uint32
> ItemPair
;
6466 typedef std::list
< ItemPair
> ItemPairs
;
6469 // get all tail string
6470 char* tail
= strtok(NULL
, "");
6472 // get from tail next item str
6473 while(char* itemStr
= strtok(tail
, " "))
6476 tail
= strtok(NULL
, "");
6479 char* itemIdStr
= strtok(itemStr
, ":");
6480 char* itemCountStr
= strtok(NULL
, " ");
6482 uint32 item_id
= atoi(itemIdStr
);
6486 ItemPrototype
const* item_proto
= objmgr
.GetItemPrototype(item_id
);
6489 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
6490 SetSentErrorMessage(true);
6494 uint32 item_count
= itemCountStr
? atoi(itemCountStr
) : 1;
6495 if(item_count
< 1 || item_proto
->MaxCount
> 0 && item_count
> uint32(item_proto
->MaxCount
))
6497 PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT
, item_count
,item_id
);
6498 SetSentErrorMessage(true);
6502 while(item_count
> item_proto
->GetMaxStackSize())
6504 items
.push_back(ItemPair(item_id
,item_proto
->GetMaxStackSize()));
6505 item_count
-= item_proto
->GetMaxStackSize();
6508 items
.push_back(ItemPair(item_id
,item_count
));
6510 if(items
.size() > MAX_MAIL_ITEMS
)
6512 PSendSysMessage(LANG_COMMAND_MAIL_ITEMS_LIMIT
, MAX_MAIL_ITEMS
);
6513 SetSentErrorMessage(true);
6518 uint64 receiver_guid
= objmgr
.GetPlayerGUIDByName(name
);
6521 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6522 SetSentErrorMessage(true);
6526 // from console show not existed sender
6527 uint32 sender_guidlo
= m_session
? m_session
->GetPlayer()->GetGUIDLow() : 0;
6529 uint32 messagetype
= MAIL_NORMAL
;
6530 uint32 stationery
= MAIL_STATIONERY_GM
;
6531 uint32 itemTextId
= !text
.empty() ? objmgr
.CreateItemText( text
) : 0;
6533 Player
*receiver
= objmgr
.GetPlayer(receiver_guid
);
6536 MailItemsInfo mi
; // item list preparing
6538 for(ItemPairs::const_iterator itr
= items
.begin(); itr
!= items
.end(); ++itr
)
6540 if(Item
* item
= Item::CreateItem(itr
->first
,itr
->second
,m_session
? m_session
->GetPlayer() : 0))
6542 item
->SaveToDB(); // save for prevent lost at next mail load, if send fail then item will deleted
6543 mi
.AddItem(item
->GetGUIDLow(), item
->GetEntry(), item
);
6547 WorldSession::SendMailTo(receiver
,messagetype
, stationery
, sender_guidlo
, GUID_LOPART(receiver_guid
), subject
, itemTextId
, &mi
, 0, 0, MAIL_CHECK_MASK_NONE
);
6549 std::string nameLink
= playerLink(name
);
6550 PSendSysMessage(LANG_MAIL_SENT
, nameLink
.c_str());
6554 ///Send money by mail
6555 bool ChatHandler::HandleSendMoneyCommand(const char* args
)
6560 /// format: name "subject text" "mail text" money
6562 std::string name
= extractPlayerNameFromLink((char*)args
);
6565 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6566 SetSentErrorMessage(true);
6570 char* tail1
= strtok(NULL
, "");
6576 msgSubject
= strtok(tail1
+1, "\"");
6579 char* space
= strtok(tail1
, "\"");
6582 msgSubject
= strtok(NULL
, "\"");
6588 char* tail2
= strtok(NULL
, "");
6594 msgText
= strtok(tail2
+1, "\"");
6597 char* space
= strtok(tail2
, "\"");
6600 msgText
= strtok(NULL
, "\"");
6606 char* money_str
= strtok(NULL
, "");
6607 int32 money
= money_str
? atoi(money_str
) : 0;
6611 // msgSubject, msgText isn't NUL after prev. check
6612 std::string subject
= msgSubject
;
6613 std::string text
= msgText
;
6615 uint64 receiver_guid
= objmgr
.GetPlayerGUIDByName(name
);
6618 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6619 SetSentErrorMessage(true);
6623 // from console show not existed sender
6624 uint32 sender_guidlo
= m_session
? m_session
->GetPlayer()->GetGUIDLow() : 0;
6626 uint32 messagetype
= MAIL_NORMAL
;
6627 uint32 stationery
= MAIL_STATIONERY_GM
;
6628 uint32 itemTextId
= !text
.empty() ? objmgr
.CreateItemText( text
) : 0;
6630 Player
*receiver
= objmgr
.GetPlayer(receiver_guid
);
6632 WorldSession::SendMailTo(receiver
,messagetype
, stationery
, sender_guidlo
, GUID_LOPART(receiver_guid
), subject
, itemTextId
, NULL
, money
, 0, MAIL_CHECK_MASK_NONE
);
6634 std::string nameLink
= playerLink(name
);
6635 PSendSysMessage(LANG_MAIL_SENT
, nameLink
.c_str());
6639 /// Send a message to a player in game
6640 bool ChatHandler::HandleSendMessageCommand(const char* args
)
6642 ///- Get the command line arguments
6643 std::string name
= extractPlayerNameFromLink((char*)args
);
6646 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6647 SetSentErrorMessage(true);
6651 char* msg_str
= strtok(NULL
, "");
6655 ///- Find the player and check that he is not logging out.
6656 Player
*rPlayer
= objmgr
.GetPlayer(name
.c_str());
6659 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6660 SetSentErrorMessage(true);
6664 if(rPlayer
->GetSession()->isLogingOut())
6666 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6667 SetSentErrorMessage(true);
6671 ///- Send the message
6672 //Use SendAreaTriggerMessage for fastest delivery.
6673 rPlayer
->GetSession()->SendAreaTriggerMessage("%s", msg_str
);
6674 rPlayer
->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
6676 //Confirmation message
6677 std::string nameLink
= playerLink(name
);
6678 PSendSysMessage(LANG_SENDMESSAGE
,nameLink
.c_str(),msg_str
);
6682 bool ChatHandler::HandleFlushArenaPointsCommand(const char * /*args*/)
6684 sBattleGroundMgr
.DistributeArenaPoints();
6688 bool ChatHandler::HandleModifyGenderCommand(const char *args
)
6693 Player
*player
= getSelectedPlayer();
6697 PSendSysMessage(LANG_NO_PLAYER
);
6698 SetSentErrorMessage(true);
6702 PlayerInfo
const* info
= objmgr
.GetPlayerInfo(player
->getRace(), player
->getClass());
6706 char const* gender_str
= (char*)args
;
6707 int gender_len
= strlen(gender_str
);
6711 if(!strncmp(gender_str
, "male", gender_len
)) // MALE
6713 if(player
->getGender() == GENDER_MALE
)
6716 gender
= GENDER_MALE
;
6718 else if (!strncmp(gender_str
, "female", gender_len
)) // FEMALE
6720 if(player
->getGender() == GENDER_FEMALE
)
6723 gender
= GENDER_FEMALE
;
6727 SendSysMessage(LANG_MUST_MALE_OR_FEMALE
);
6728 SetSentErrorMessage(true);
6733 player
->SetByteValue(UNIT_FIELD_BYTES_0
, 2, gender
);
6734 player
->SetByteValue(PLAYER_BYTES_3
, 0, gender
);
6736 // Change display ID
6737 player
->SetDisplayId(gender
? info
->displayId_f
: info
->displayId_m
);
6738 player
->SetNativeDisplayId(gender
? info
->displayId_f
: info
->displayId_m
);
6740 char const* gender_full
= gender
? "female" : "male";
6742 PSendSysMessage(LANG_YOU_CHANGE_GENDER
, GetNameLink(player
).c_str(), gender_full
);
6744 if (needReportToTarget(player
))
6745 ChatHandler(player
).PSendSysMessage(LANG_YOUR_GENDER_CHANGED
, gender_full
, GetNameLink().c_str());