Just a few renames.
[AHbot.git] / src / game / Level3.cpp
blob2cccc2e565cb000b87a4e3c61d83c9989e9f3b92
1 /*
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
19 #include "Common.h"
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
23 #include "World.h"
24 #include "ObjectMgr.h"
25 #include "AccountMgr.h"
26 #include "PlayerDump.h"
27 #include "SpellMgr.h"
28 #include "Player.h"
29 #include "Opcodes.h"
30 #include "GameObject.h"
31 #include "Chat.h"
32 #include "Log.h"
33 #include "Guild.h"
34 #include "ObjectAccessor.h"
35 #include "MapManager.h"
36 #include "ScriptCalls.h"
37 #include "Language.h"
38 #include "GridNotifiersImpl.h"
39 #include "CellImpl.h"
40 #include "Weather.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"
47 #include "Util.h"
48 #include "ItemEnchantmentMgr.h"
49 #include "BattleGroundMgr.h"
50 #include "InstanceSaveMgr.h"
51 #include "InstanceData.h"
53 //reload commands
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("");
71 return true;
74 bool ChatHandler::HandleReloadAllAchievementCommand(const char*)
76 HandleReloadAchievementCriteriaDataCommand("");
77 HandleReloadAchievementRewardCommand("");
78 return true;
81 bool ChatHandler::HandleReloadAllAreaCommand(const char*)
83 //HandleReloadQuestAreaTriggersCommand(""); -- reloaded in HandleReloadAllQuestCommand
84 HandleReloadAreaTriggerTeleportCommand("");
85 HandleReloadAreaTriggerTavernCommand("");
86 HandleReloadGameGraveyardZoneCommand("");
87 return true;
90 bool ChatHandler::HandleReloadAllLootCommand(const char*)
92 sLog.outString( "Re-Loading Loot Tables..." );
93 LoadLootTables();
94 SendGlobalSysMessage("DB tables `*_loot_template` reloaded.");
95 return true;
98 bool ChatHandler::HandleReloadAllNpcCommand(const char* /*args*/)
100 HandleReloadNpcGossipCommand("a");
101 HandleReloadNpcOptionCommand("a");
102 HandleReloadNpcTrainerCommand("a");
103 HandleReloadNpcVendorCommand("a");
104 HandleReloadPointsOfInterestCommand("a");
105 HandleReloadSpellClickSpellsCommand("a");
106 return true;
109 bool ChatHandler::HandleReloadAllQuestCommand(const char* /*args*/)
111 HandleReloadQuestAreaTriggersCommand("a");
112 HandleReloadQuestTemplateCommand("a");
114 sLog.outString( "Re-Loading Quests Relations..." );
115 objmgr.LoadQuestRelations();
116 SendGlobalSysMessage("DB tables `*_questrelation` and `*_involvedrelation` reloaded.");
117 return true;
120 bool ChatHandler::HandleReloadAllScriptsCommand(const char*)
122 if(sWorld.IsScriptScheduled())
124 PSendSysMessage("DB scripts used currently, please attempt reload later.");
125 SetSentErrorMessage(true);
126 return false;
129 sLog.outString( "Re-Loading Scripts..." );
130 HandleReloadGameObjectScriptsCommand("a");
131 HandleReloadEventScriptsCommand("a");
132 HandleReloadQuestEndScriptsCommand("a");
133 HandleReloadQuestStartScriptsCommand("a");
134 HandleReloadSpellScriptsCommand("a");
135 SendGlobalSysMessage("DB tables `*_scripts` reloaded.");
136 HandleReloadDbScriptStringCommand("a");
137 return true;
140 bool ChatHandler::HandleReloadAllSpellCommand(const char*)
142 HandleReloadSkillDiscoveryTemplateCommand("a");
143 HandleReloadSkillExtraItemTemplateCommand("a");
144 HandleReloadSpellAffectCommand("a");
145 HandleReloadSpellAreaCommand("a");
146 HandleReloadSpellChainCommand("a");
147 HandleReloadSpellElixirCommand("a");
148 HandleReloadSpellLearnSpellCommand("a");
149 HandleReloadSpellProcEventCommand("a");
150 HandleReloadSpellBonusesCommand("a");
151 HandleReloadSpellScriptTargetCommand("a");
152 HandleReloadSpellTargetPositionCommand("a");
153 HandleReloadSpellThreatsCommand("a");
154 HandleReloadSpellPetAurasCommand("a");
155 return true;
158 bool ChatHandler::HandleReloadAllItemCommand(const char*)
160 HandleReloadPageTextsCommand("a");
161 HandleReloadItemEnchantementsCommand("a");
162 return true;
165 bool ChatHandler::HandleReloadAllLocalesCommand(const char* /*args*/)
167 HandleReloadLocalesAchievementRewardCommand("a");
168 HandleReloadLocalesCreatureCommand("a");
169 HandleReloadLocalesGameobjectCommand("a");
170 HandleReloadLocalesItemCommand("a");
171 HandleReloadLocalesNpcTextCommand("a");
172 HandleReloadLocalesPageTextCommand("a");
173 HandleReloadLocalesPointsOfInterestCommand("a");
174 HandleReloadLocalesQuestCommand("a");
175 return true;
178 bool ChatHandler::HandleReloadConfigCommand(const char* /*args*/)
180 sLog.outString( "Re-Loading config settings..." );
181 sWorld.LoadConfigSettings(true);
182 SendGlobalSysMessage("World config settings reloaded.");
183 return true;
186 bool ChatHandler::HandleReloadAchievementCriteriaDataCommand(const char*)
188 sLog.outString( "Re-Loading Additional Achievement Criteria Data..." );
189 achievementmgr.LoadAchievementCriteriaData();
190 SendGlobalSysMessage("DB table `achievement_criteria_data` reloaded.");
191 return true;
194 bool ChatHandler::HandleReloadAchievementRewardCommand(const char*)
196 sLog.outString( "Re-Loading Achievement Reward Data..." );
197 achievementmgr.LoadRewards();
198 SendGlobalSysMessage("DB table `achievement_reward` reloaded.");
199 return true;
202 bool ChatHandler::HandleReloadAreaTriggerTavernCommand(const char*)
204 sLog.outString( "Re-Loading Tavern Area Triggers..." );
205 objmgr.LoadTavernAreaTriggers();
206 SendGlobalSysMessage("DB table `areatrigger_tavern` reloaded.");
207 return true;
210 bool ChatHandler::HandleReloadAreaTriggerTeleportCommand(const char*)
212 sLog.outString( "Re-Loading AreaTrigger teleport definitions..." );
213 objmgr.LoadAreaTriggerTeleports();
214 SendGlobalSysMessage("DB table `areatrigger_teleport` reloaded.");
215 return true;
218 bool ChatHandler::HandleReloadCommandCommand(const char*)
220 load_command_table = true;
221 SendGlobalSysMessage("DB table `command` will be reloaded at next chat command use.");
222 return true;
225 bool ChatHandler::HandleReloadCreatureQuestRelationsCommand(const char*)
227 sLog.outString( "Loading Quests Relations... (`creature_questrelation`)" );
228 objmgr.LoadCreatureQuestRelations();
229 SendGlobalSysMessage("DB table `creature_questrelation` (creature quest givers) reloaded.");
230 return true;
233 bool ChatHandler::HandleReloadCreatureQuestInvRelationsCommand(const char*)
235 sLog.outString( "Loading Quests Relations... (`creature_involvedrelation`)" );
236 objmgr.LoadCreatureInvolvedRelations();
237 SendGlobalSysMessage("DB table `creature_involvedrelation` (creature quest takers) reloaded.");
238 return true;
241 bool ChatHandler::HandleReloadGOQuestRelationsCommand(const char*)
243 sLog.outString( "Loading Quests Relations... (`gameobject_questrelation`)" );
244 objmgr.LoadGameobjectQuestRelations();
245 SendGlobalSysMessage("DB table `gameobject_questrelation` (gameobject quest givers) reloaded.");
246 return true;
249 bool ChatHandler::HandleReloadGOQuestInvRelationsCommand(const char*)
251 sLog.outString( "Loading Quests Relations... (`gameobject_involvedrelation`)" );
252 objmgr.LoadGameobjectInvolvedRelations();
253 SendGlobalSysMessage("DB table `gameobject_involvedrelation` (gameobject quest takers) reloaded.");
254 return true;
257 bool ChatHandler::HandleReloadQuestAreaTriggersCommand(const char*)
259 sLog.outString( "Re-Loading Quest Area Triggers..." );
260 objmgr.LoadQuestAreaTriggers();
261 SendGlobalSysMessage("DB table `areatrigger_involvedrelation` (quest area triggers) reloaded.");
262 return true;
265 bool ChatHandler::HandleReloadQuestTemplateCommand(const char*)
267 sLog.outString( "Re-Loading Quest Templates..." );
268 objmgr.LoadQuests();
269 SendGlobalSysMessage("DB table `quest_template` (quest definitions) reloaded.");
271 /// dependent also from `gameobject` but this table not reloaded anyway
272 sLog.outString( "Re-Loading GameObjects for quests..." );
273 objmgr.LoadGameObjectForQuests();
274 SendGlobalSysMessage("Data GameObjects for quests reloaded.");
275 return true;
278 bool ChatHandler::HandleReloadLootTemplatesCreatureCommand(const char*)
280 sLog.outString( "Re-Loading Loot Tables... (`creature_loot_template`)" );
281 LoadLootTemplates_Creature();
282 LootTemplates_Creature.CheckLootRefs();
283 SendGlobalSysMessage("DB table `creature_loot_template` reloaded.");
284 return true;
287 bool ChatHandler::HandleReloadLootTemplatesDisenchantCommand(const char*)
289 sLog.outString( "Re-Loading Loot Tables... (`disenchant_loot_template`)" );
290 LoadLootTemplates_Disenchant();
291 LootTemplates_Disenchant.CheckLootRefs();
292 SendGlobalSysMessage("DB table `disenchant_loot_template` reloaded.");
293 return true;
296 bool ChatHandler::HandleReloadLootTemplatesFishingCommand(const char*)
298 sLog.outString( "Re-Loading Loot Tables... (`fishing_loot_template`)" );
299 LoadLootTemplates_Fishing();
300 LootTemplates_Fishing.CheckLootRefs();
301 SendGlobalSysMessage("DB table `fishing_loot_template` reloaded.");
302 return true;
305 bool ChatHandler::HandleReloadLootTemplatesGameobjectCommand(const char*)
307 sLog.outString( "Re-Loading Loot Tables... (`gameobject_loot_template`)" );
308 LoadLootTemplates_Gameobject();
309 LootTemplates_Gameobject.CheckLootRefs();
310 SendGlobalSysMessage("DB table `gameobject_loot_template` reloaded.");
311 return true;
314 bool ChatHandler::HandleReloadLootTemplatesItemCommand(const char*)
316 sLog.outString( "Re-Loading Loot Tables... (`item_loot_template`)" );
317 LoadLootTemplates_Item();
318 LootTemplates_Item.CheckLootRefs();
319 SendGlobalSysMessage("DB table `item_loot_template` reloaded.");
320 return true;
323 bool ChatHandler::HandleReloadLootTemplatesMillingCommand(const char*)
325 sLog.outString( "Re-Loading Loot Tables... (`milling_loot_template`)" );
326 LoadLootTemplates_Milling();
327 LootTemplates_Milling.CheckLootRefs();
328 SendGlobalSysMessage("DB table `milling_loot_template` reloaded.");
329 return true;
332 bool ChatHandler::HandleReloadLootTemplatesPickpocketingCommand(const char*)
334 sLog.outString( "Re-Loading Loot Tables... (`pickpocketing_loot_template`)" );
335 LoadLootTemplates_Pickpocketing();
336 LootTemplates_Pickpocketing.CheckLootRefs();
337 SendGlobalSysMessage("DB table `pickpocketing_loot_template` reloaded.");
338 return true;
341 bool ChatHandler::HandleReloadLootTemplatesProspectingCommand(const char*)
343 sLog.outString( "Re-Loading Loot Tables... (`prospecting_loot_template`)" );
344 LoadLootTemplates_Prospecting();
345 LootTemplates_Prospecting.CheckLootRefs();
346 SendGlobalSysMessage("DB table `prospecting_loot_template` reloaded.");
347 return true;
350 bool ChatHandler::HandleReloadLootTemplatesQuestMailCommand(const char*)
352 sLog.outString( "Re-Loading Loot Tables... (`quest_mail_loot_template`)" );
353 LoadLootTemplates_QuestMail();
354 LootTemplates_QuestMail.CheckLootRefs();
355 SendGlobalSysMessage("DB table `quest_mail_loot_template` reloaded.");
356 return true;
359 bool ChatHandler::HandleReloadLootTemplatesReferenceCommand(const char*)
361 sLog.outString( "Re-Loading Loot Tables... (`reference_loot_template`)" );
362 LoadLootTemplates_Reference();
363 SendGlobalSysMessage("DB table `reference_loot_template` reloaded.");
364 return true;
367 bool ChatHandler::HandleReloadLootTemplatesSkinningCommand(const char*)
369 sLog.outString( "Re-Loading Loot Tables... (`skinning_loot_template`)" );
370 LoadLootTemplates_Skinning();
371 LootTemplates_Skinning.CheckLootRefs();
372 SendGlobalSysMessage("DB table `skinning_loot_template` reloaded.");
373 return true;
376 bool ChatHandler::HandleReloadLootTemplatesSpellCommand(const char*)
378 sLog.outString( "Re-Loading Loot Tables... (`spell_loot_template`)" );
379 LoadLootTemplates_Spell();
380 LootTemplates_Spell.CheckLootRefs();
381 SendGlobalSysMessage("DB table `spell_loot_template` reloaded.");
382 return true;
385 bool ChatHandler::HandleReloadMangosStringCommand(const char*)
387 sLog.outString( "Re-Loading mangos_string Table!" );
388 objmgr.LoadMangosStrings();
389 SendGlobalSysMessage("DB table `mangos_string` reloaded.");
390 return true;
393 bool ChatHandler::HandleReloadNpcOptionCommand(const char*)
395 sLog.outString( "Re-Loading `npc_option` Table!" );
396 objmgr.LoadNpcOptions();
397 SendGlobalSysMessage("DB table `npc_option` reloaded.");
398 return true;
401 bool ChatHandler::HandleReloadNpcGossipCommand(const char*)
403 sLog.outString( "Re-Loading `npc_gossip` Table!" );
404 objmgr.LoadNpcTextId();
405 SendGlobalSysMessage("DB table `npc_gossip` reloaded.");
406 return true;
409 bool ChatHandler::HandleReloadNpcTrainerCommand(const char*)
411 sLog.outString( "Re-Loading `npc_trainer` Table!" );
412 objmgr.LoadTrainerSpell();
413 SendGlobalSysMessage("DB table `npc_trainer` reloaded.");
414 return true;
417 bool ChatHandler::HandleReloadNpcVendorCommand(const char*)
419 sLog.outString( "Re-Loading `npc_vendor` Table!" );
420 objmgr.LoadVendors();
421 SendGlobalSysMessage("DB table `npc_vendor` reloaded.");
422 return true;
425 bool ChatHandler::HandleReloadPointsOfInterestCommand(const char*)
427 sLog.outString( "Re-Loading `points_of_interest` Table!" );
428 objmgr.LoadPointsOfInterest();
429 SendGlobalSysMessage("DB table `points_of_interest` reloaded.");
430 return true;
433 bool ChatHandler::HandleReloadSpellClickSpellsCommand(const char*)
435 sLog.outString( "Re-Loading `npc_spellclick_spells` Table!" );
436 objmgr.LoadNPCSpellClickSpells();
437 SendGlobalSysMessage("DB table `npc_spellclick_spells` reloaded.");
438 return true;
441 bool ChatHandler::HandleReloadReservedNameCommand(const char*)
443 sLog.outString( "Loading ReservedNames... (`reserved_name`)" );
444 objmgr.LoadReservedPlayersNames();
445 SendGlobalSysMessage("DB table `reserved_name` (player reserved names) reloaded.");
446 return true;
449 bool ChatHandler::HandleReloadSkillDiscoveryTemplateCommand(const char* /*args*/)
451 sLog.outString( "Re-Loading Skill Discovery Table..." );
452 LoadSkillDiscoveryTable();
453 SendGlobalSysMessage("DB table `skill_discovery_template` (recipes discovered at crafting) reloaded.");
454 return true;
457 bool ChatHandler::HandleReloadSkillExtraItemTemplateCommand(const char* /*args*/)
459 sLog.outString( "Re-Loading Skill Extra Item Table..." );
460 LoadSkillExtraItemTable();
461 SendGlobalSysMessage("DB table `skill_extra_item_template` (extra item creation when crafting) reloaded.");
462 return true;
465 bool ChatHandler::HandleReloadSkillFishingBaseLevelCommand(const char* /*args*/)
467 sLog.outString( "Re-Loading Skill Fishing base level requirements..." );
468 objmgr.LoadFishingBaseSkillLevel();
469 SendGlobalSysMessage("DB table `skill_fishing_base_level` (fishing base level for zone/subzone) reloaded.");
470 return true;
473 bool ChatHandler::HandleReloadSpellAffectCommand(const char*)
475 sLog.outString( "Re-Loading SpellAffect definitions..." );
476 spellmgr.LoadSpellAffects();
477 SendGlobalSysMessage("DB table `spell_affect` (spell mods apply requirements) reloaded.");
478 return true;
481 bool ChatHandler::HandleReloadSpellAreaCommand(const char*)
483 sLog.outString( "Re-Loading SpellArea Data..." );
484 spellmgr.LoadSpellAreas();
485 SendGlobalSysMessage("DB table `spell_area` (spell dependences from area/quest/auras state) reloaded.");
486 return true;
489 bool ChatHandler::HandleReloadSpellChainCommand(const char*)
491 sLog.outString( "Re-Loading Spell Chain Data... " );
492 spellmgr.LoadSpellChains();
493 SendGlobalSysMessage("DB table `spell_chain` (spell ranks) reloaded.");
494 return true;
497 bool ChatHandler::HandleReloadSpellElixirCommand(const char*)
499 sLog.outString( "Re-Loading Spell Elixir types..." );
500 spellmgr.LoadSpellElixirs();
501 SendGlobalSysMessage("DB table `spell_elixir` (spell elixir types) reloaded.");
502 return true;
505 bool ChatHandler::HandleReloadSpellLearnSpellCommand(const char*)
507 sLog.outString( "Re-Loading Spell Learn Spells..." );
508 spellmgr.LoadSpellLearnSpells();
509 SendGlobalSysMessage("DB table `spell_learn_spell` reloaded.");
510 return true;
513 bool ChatHandler::HandleReloadSpellProcEventCommand(const char*)
515 sLog.outString( "Re-Loading Spell Proc Event conditions..." );
516 spellmgr.LoadSpellProcEvents();
517 SendGlobalSysMessage("DB table `spell_proc_event` (spell proc trigger requirements) reloaded.");
518 return true;
521 bool ChatHandler::HandleReloadSpellBonusesCommand(const char*)
523 sLog.outString( "Re-Loading Spell Bonus Data..." );
524 spellmgr.LoadSpellBonusess();
525 SendGlobalSysMessage("DB table `spell_bonus_data` (spell damage/healing coefficients) reloaded.");
526 return true;
529 bool ChatHandler::HandleReloadSpellScriptTargetCommand(const char*)
531 sLog.outString( "Re-Loading SpellsScriptTarget..." );
532 spellmgr.LoadSpellScriptTarget();
533 SendGlobalSysMessage("DB table `spell_script_target` (spell targets selection in case specific creature/GO requirements) reloaded.");
534 return true;
537 bool ChatHandler::HandleReloadSpellTargetPositionCommand(const char*)
539 sLog.outString( "Re-Loading Spell target coordinates..." );
540 spellmgr.LoadSpellTargetPositions();
541 SendGlobalSysMessage("DB table `spell_target_position` (destination coordinates for spell targets) reloaded.");
542 return true;
545 bool ChatHandler::HandleReloadSpellThreatsCommand(const char*)
547 sLog.outString( "Re-Loading Aggro Spells Definitions...");
548 spellmgr.LoadSpellThreats();
549 SendGlobalSysMessage("DB table `spell_threat` (spell aggro definitions) reloaded.");
550 return true;
553 bool ChatHandler::HandleReloadSpellPetAurasCommand(const char*)
555 sLog.outString( "Re-Loading Spell pet auras...");
556 spellmgr.LoadSpellPetAuras();
557 SendGlobalSysMessage("DB table `spell_pet_auras` reloaded.");
558 return true;
561 bool ChatHandler::HandleReloadPageTextsCommand(const char*)
563 sLog.outString( "Re-Loading Page Texts..." );
564 objmgr.LoadPageTexts();
565 SendGlobalSysMessage("DB table `page_texts` reloaded.");
566 return true;
569 bool ChatHandler::HandleReloadItemEnchantementsCommand(const char*)
571 sLog.outString( "Re-Loading Item Random Enchantments Table..." );
572 LoadRandomEnchantmentsTable();
573 SendGlobalSysMessage("DB table `item_enchantment_template` reloaded.");
574 return true;
577 bool ChatHandler::HandleReloadGameObjectScriptsCommand(const char* arg)
579 if(sWorld.IsScriptScheduled())
581 SendSysMessage("DB scripts used currently, please attempt reload later.");
582 SetSentErrorMessage(true);
583 return false;
586 if(*arg!='a')
587 sLog.outString( "Re-Loading Scripts from `gameobject_scripts`...");
589 objmgr.LoadGameObjectScripts();
591 if(*arg!='a')
592 SendGlobalSysMessage("DB table `gameobject_scripts` reloaded.");
594 return true;
597 bool ChatHandler::HandleReloadEventScriptsCommand(const char* arg)
599 if(sWorld.IsScriptScheduled())
601 SendSysMessage("DB scripts used currently, please attempt reload later.");
602 SetSentErrorMessage(true);
603 return false;
606 if(*arg!='a')
607 sLog.outString( "Re-Loading Scripts from `event_scripts`...");
609 objmgr.LoadEventScripts();
611 if(*arg!='a')
612 SendGlobalSysMessage("DB table `event_scripts` reloaded.");
614 return true;
617 bool ChatHandler::HandleReloadQuestEndScriptsCommand(const char* arg)
619 if(sWorld.IsScriptScheduled())
621 SendSysMessage("DB scripts used currently, please attempt reload later.");
622 SetSentErrorMessage(true);
623 return false;
626 if(*arg!='a')
627 sLog.outString( "Re-Loading Scripts from `quest_end_scripts`...");
629 objmgr.LoadQuestEndScripts();
631 if(*arg!='a')
632 SendGlobalSysMessage("DB table `quest_end_scripts` reloaded.");
634 return true;
637 bool ChatHandler::HandleReloadQuestStartScriptsCommand(const char* arg)
639 if(sWorld.IsScriptScheduled())
641 SendSysMessage("DB scripts used currently, please attempt reload later.");
642 SetSentErrorMessage(true);
643 return false;
646 if(*arg!='a')
647 sLog.outString( "Re-Loading Scripts from `quest_start_scripts`...");
649 objmgr.LoadQuestStartScripts();
651 if(*arg!='a')
652 SendGlobalSysMessage("DB table `quest_start_scripts` reloaded.");
654 return true;
657 bool ChatHandler::HandleReloadSpellScriptsCommand(const char* arg)
659 if(sWorld.IsScriptScheduled())
661 SendSysMessage("DB scripts used currently, please attempt reload later.");
662 SetSentErrorMessage(true);
663 return false;
666 if(*arg!='a')
667 sLog.outString( "Re-Loading Scripts from `spell_scripts`...");
669 objmgr.LoadSpellScripts();
671 if(*arg!='a')
672 SendGlobalSysMessage("DB table `spell_scripts` reloaded.");
674 return true;
677 bool ChatHandler::HandleReloadDbScriptStringCommand(const char* /*arg*/)
679 sLog.outString( "Re-Loading Script strings from `db_script_string`...");
680 objmgr.LoadDbScriptStrings();
681 SendGlobalSysMessage("DB table `db_script_string` reloaded.");
682 return true;
685 bool ChatHandler::HandleReloadGameGraveyardZoneCommand(const char* /*arg*/)
687 sLog.outString( "Re-Loading Graveyard-zone links...");
689 objmgr.LoadGraveyardZones();
691 SendGlobalSysMessage("DB table `game_graveyard_zone` reloaded.");
693 return true;
696 bool ChatHandler::HandleReloadGameTeleCommand(const char* /*arg*/)
698 sLog.outString( "Re-Loading Game Tele coordinates...");
700 objmgr.LoadGameTele();
702 SendGlobalSysMessage("DB table `game_tele` reloaded.");
704 return true;
707 bool ChatHandler::HandleReloadLocalesAchievementRewardCommand(const char*)
709 sLog.outString( "Re-Loading Locales Achievement Reward Data..." );
710 achievementmgr.LoadRewardLocales();
711 SendGlobalSysMessage("DB table `locales_achievement_reward` reloaded.");
712 return true;
715 bool ChatHandler::HandleReloadLocalesCreatureCommand(const char* /*arg*/)
717 sLog.outString( "Re-Loading Locales Creature ...");
718 objmgr.LoadCreatureLocales();
719 SendGlobalSysMessage("DB table `locales_creature` reloaded.");
720 return true;
723 bool ChatHandler::HandleReloadLocalesGameobjectCommand(const char* /*arg*/)
725 sLog.outString( "Re-Loading Locales Gameobject ... ");
726 objmgr.LoadGameObjectLocales();
727 SendGlobalSysMessage("DB table `locales_gameobject` reloaded.");
728 return true;
731 bool ChatHandler::HandleReloadLocalesItemCommand(const char* /*arg*/)
733 sLog.outString( "Re-Loading Locales Item ... ");
734 objmgr.LoadItemLocales();
735 SendGlobalSysMessage("DB table `locales_item` reloaded.");
736 return true;
739 bool ChatHandler::HandleReloadLocalesNpcTextCommand(const char* /*arg*/)
741 sLog.outString( "Re-Loading Locales NPC Text ... ");
742 objmgr.LoadNpcTextLocales();
743 SendGlobalSysMessage("DB table `locales_npc_text` reloaded.");
744 return true;
747 bool ChatHandler::HandleReloadLocalesPageTextCommand(const char* /*arg*/)
749 sLog.outString( "Re-Loading Locales Page Text ... ");
750 objmgr.LoadPageTextLocales();
751 SendGlobalSysMessage("DB table `locales_page_text` reloaded.");
752 return true;
755 bool ChatHandler::HandleReloadLocalesPointsOfInterestCommand(const char* /*arg*/)
757 sLog.outString( "Re-Loading Locales Points Of Interest ... ");
758 objmgr.LoadPointOfInterestLocales();
759 SendGlobalSysMessage("DB table `locales_points_of_interest` reloaded.");
760 return true;
763 bool ChatHandler::HandleReloadLocalesQuestCommand(const char* /*arg*/)
765 sLog.outString( "Re-Loading Locales Quest ... ");
766 objmgr.LoadQuestLocales();
767 SendGlobalSysMessage("DB table `locales_quest` reloaded.");
768 return true;
771 bool ChatHandler::HandleLoadScriptsCommand(const char* args)
773 if(!LoadScriptingModule(args)) return true;
775 sWorld.SendWorldText(LANG_SCRIPTS_RELOADED);
776 return true;
779 bool ChatHandler::HandleAccountSetGmLevelCommand(const char* args)
781 char* arg1 = strtok((char*)args, " ");
782 if( !arg1 )
783 return false;
785 /// must be NULL if targeted syntax and must be not nULL if not targeted
786 char* arg2 = strtok(NULL, " ");
788 std::string targetAccountName;
789 uint32 targetAccountId = 0;
791 /// only target player different from self allowed (if targetPlayer!=NULL then not console)
792 Player* targetPlayer = getSelectedPlayer();
793 if(targetPlayer && m_session->GetPlayer()!=targetPlayer)
795 /// wrong command syntax or unexpected targeting
796 if(arg2)
797 return false;
799 /// security level expected in arg2 after this if.
800 arg2 = arg1;
802 targetAccountId = targetPlayer->GetSession()->GetAccountId();
803 accmgr.GetName(targetAccountId, targetAccountName);
805 else
807 /// wrong command syntax (second arg expected)
808 if(!arg2)
809 return false;
811 targetAccountName = arg1;
812 if(!AccountMgr::normilizeString(targetAccountName))
814 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,targetAccountName.c_str());
815 SetSentErrorMessage(true);
816 return false;
819 targetAccountId = accmgr.GetId(targetAccountName);
820 if(!targetAccountId)
822 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,targetAccountName.c_str());
823 SetSentErrorMessage(true);
824 return false;
828 int32 gm = (int32)atoi(arg2);
829 if ( gm < SEC_PLAYER || gm > SEC_ADMINISTRATOR )
831 SendSysMessage(LANG_BAD_VALUE);
832 SetSentErrorMessage(true);
833 return false;
836 /// can set security level only for target with less security and to less security that we have
837 /// This will reject self apply by specify account name
838 if(HasLowerSecurityAccount(NULL,targetAccountId,true))
839 return false;
841 /// account can't set security to same or grater level, need more power GM or console
842 AccountTypes plSecurity = m_session ? m_session->GetSecurity() : SEC_CONSOLE;
843 if (AccountTypes(gm) >= plSecurity )
845 SendSysMessage(LANG_YOURS_SECURITY_IS_LOW);
846 SetSentErrorMessage(true);
847 return false;
850 // This will prevent self apply by self target or no target
851 if(targetPlayer && m_session->GetPlayer()!=targetPlayer)
853 ChatHandler(targetPlayer).PSendSysMessage(LANG_YOURS_SECURITY_CHANGED,GetNameLink().c_str(), gm);
854 targetPlayer->GetSession()->SetSecurity(AccountTypes(gm));
857 PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetAccountName.c_str(), gm);
858 loginDatabase.PExecute("UPDATE account SET gmlevel = '%i' WHERE id = '%u'", gm, targetAccountId);
860 return true;
863 /// Set password for account
864 bool ChatHandler::HandleAccountSetPasswordCommand(const char* args)
866 if(!*args)
867 return false;
869 ///- Get the command line arguments
870 char *szAccount = strtok ((char*)args," ");
871 char *szPassword1 = strtok (NULL," ");
872 char *szPassword2 = strtok (NULL," ");
874 if (!szAccount||!szPassword1 || !szPassword2)
875 return false;
877 std::string account_name = szAccount;
878 if(!AccountMgr::normilizeString(account_name))
880 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
881 SetSentErrorMessage(true);
882 return false;
885 uint32 targetAccountId = accmgr.GetId(account_name);
886 if (!targetAccountId)
888 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
889 SetSentErrorMessage(true);
890 return false;
893 /// can set password only for target with less security
894 /// This is also reject self apply in fact
895 if(HasLowerSecurityAccount (NULL,targetAccountId,true))
896 return false;
898 if (strcmp(szPassword1,szPassword2))
900 SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH);
901 SetSentErrorMessage (true);
902 return false;
905 AccountOpResult result = accmgr.ChangePassword(targetAccountId, szPassword1);
907 switch(result)
909 case AOR_OK:
910 SendSysMessage(LANG_COMMAND_PASSWORD);
911 break;
912 case AOR_NAME_NOT_EXIST:
913 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
914 SetSentErrorMessage(true);
915 return false;
916 case AOR_PASS_TOO_LONG:
917 SendSysMessage(LANG_PASSWORD_TOO_LONG);
918 SetSentErrorMessage(true);
919 return false;
920 default:
921 SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD);
922 SetSentErrorMessage(true);
923 return false;
926 return true;
929 bool ChatHandler::HandleMaxSkillCommand(const char* /*args*/)
931 Player* SelectedPlayer = getSelectedPlayer();
932 if(!SelectedPlayer)
934 SendSysMessage(LANG_NO_CHAR_SELECTED);
935 SetSentErrorMessage(true);
936 return false;
939 // each skills that have max skill value dependent from level seted to current level max skill value
940 SelectedPlayer->UpdateSkillsToMaxSkillsForLevel();
941 return true;
944 bool ChatHandler::HandleSetSkillCommand(const char* args)
946 // number or [name] Shift-click form |color|Hskill:skill_id|h[name]|h|r
947 char* skill_p = extractKeyFromLink((char*)args,"Hskill");
948 if(!skill_p)
949 return false;
951 char *level_p = strtok (NULL, " ");
953 if( !level_p)
954 return false;
956 char *max_p = strtok (NULL, " ");
958 int32 skill = atoi(skill_p);
959 if (skill <= 0)
961 PSendSysMessage(LANG_INVALID_SKILL_ID, skill);
962 SetSentErrorMessage(true);
963 return false;
966 int32 level = atol (level_p);
968 Player * target = getSelectedPlayer();
969 if(!target)
971 SendSysMessage(LANG_NO_CHAR_SELECTED);
972 SetSentErrorMessage(true);
973 return false;
976 SkillLineEntry const* sl = sSkillLineStore.LookupEntry(skill);
977 if(!sl)
979 PSendSysMessage(LANG_INVALID_SKILL_ID, skill);
980 SetSentErrorMessage(true);
981 return false;
984 std::string tNameLink = GetNameLink(target);
986 if(!target->GetSkillValue(skill))
988 PSendSysMessage(LANG_SET_SKILL_ERROR, tNameLink.c_str(), skill, sl->name[0]);
989 SetSentErrorMessage(true);
990 return false;
993 int32 max = max_p ? atol (max_p) : target->GetPureMaxSkillValue(skill);
995 if( level <= 0 || level > max || max <= 0 )
996 return false;
998 target->SetSkill(skill, level, max);
999 PSendSysMessage(LANG_SET_SKILL, skill, sl->name[0], tNameLink.c_str(), level, max);
1001 return true;
1004 bool ChatHandler::HandleUnLearnCommand(const char* args)
1006 if (!*args)
1007 return false;
1009 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
1010 uint32 spell_id = extractSpellIdFromLink((char*)args);
1011 if(!spell_id)
1012 return false;
1014 char const* allStr = strtok(NULL," ");
1015 bool allRanks = allStr ? (strncmp(allStr, "all", strlen(allStr)) == 0) : false;
1017 Player* target = getSelectedPlayer();
1018 if(!target)
1020 SendSysMessage(LANG_NO_CHAR_SELECTED);
1021 SetSentErrorMessage(true);
1022 return false;
1025 if(allRanks)
1026 spell_id = spellmgr.GetFirstSpellInChain (spell_id);
1028 if (target->HasSpell(spell_id))
1029 target->removeSpell(spell_id,false,!allRanks);
1030 else
1031 SendSysMessage(LANG_FORGET_SPELL);
1033 return true;
1036 bool ChatHandler::HandleCooldownCommand(const char* args)
1038 Player* target = getSelectedPlayer();
1039 if(!target)
1041 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1042 SetSentErrorMessage(true);
1043 return false;
1046 std::string tNameLink = GetNameLink(target);
1048 if (!*args)
1050 target->RemoveAllSpellCooldown();
1051 PSendSysMessage(LANG_REMOVEALL_COOLDOWN, tNameLink.c_str());
1053 else
1055 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1056 uint32 spell_id = extractSpellIdFromLink((char*)args);
1057 if(!spell_id)
1058 return false;
1060 if(!sSpellStore.LookupEntry(spell_id))
1062 PSendSysMessage(LANG_UNKNOWN_SPELL, target==m_session->GetPlayer() ? GetMangosString(LANG_YOU) : tNameLink.c_str());
1063 SetSentErrorMessage(true);
1064 return false;
1067 WorldPacket data( SMSG_CLEAR_COOLDOWN, (4+8) );
1068 data << uint32(spell_id);
1069 data << uint64(target->GetGUID());
1070 target->GetSession()->SendPacket(&data);
1071 target->RemoveSpellCooldown(spell_id);
1072 PSendSysMessage(LANG_REMOVE_COOLDOWN, spell_id, target==m_session->GetPlayer() ? GetMangosString(LANG_YOU) : tNameLink.c_str());
1074 return true;
1077 bool ChatHandler::HandleLearnAllCommand(const char* /*args*/)
1079 static const char *allSpellList[] =
1081 "3365",
1082 "6233",
1083 "6247",
1084 "6246",
1085 "6477",
1086 "6478",
1087 "22810",
1088 "8386",
1089 "21651",
1090 "21652",
1091 "522",
1092 "7266",
1093 "8597",
1094 "2479",
1095 "22027",
1096 "6603",
1097 "5019",
1098 "133",
1099 "168",
1100 "227",
1101 "5009",
1102 "9078",
1103 "668",
1104 "203",
1105 "20599",
1106 "20600",
1107 "81",
1108 "20597",
1109 "20598",
1110 "20864",
1111 "1459",
1112 "5504",
1113 "587",
1114 "5143",
1115 "118",
1116 "5505",
1117 "597",
1118 "604",
1119 "1449",
1120 "1460",
1121 "2855",
1122 "1008",
1123 "475",
1124 "5506",
1125 "1463",
1126 "12824",
1127 "8437",
1128 "990",
1129 "5145",
1130 "8450",
1131 "1461",
1132 "759",
1133 "8494",
1134 "8455",
1135 "8438",
1136 "6127",
1137 "8416",
1138 "6129",
1139 "8451",
1140 "8495",
1141 "8439",
1142 "3552",
1143 "8417",
1144 "10138",
1145 "12825",
1146 "10169",
1147 "10156",
1148 "10144",
1149 "10191",
1150 "10201",
1151 "10211",
1152 "10053",
1153 "10173",
1154 "10139",
1155 "10145",
1156 "10192",
1157 "10170",
1158 "10202",
1159 "10054",
1160 "10174",
1161 "10193",
1162 "12826",
1163 "2136",
1164 "143",
1165 "145",
1166 "2137",
1167 "2120",
1168 "3140",
1169 "543",
1170 "2138",
1171 "2948",
1172 "8400",
1173 "2121",
1174 "8444",
1175 "8412",
1176 "8457",
1177 "8401",
1178 "8422",
1179 "8445",
1180 "8402",
1181 "8413",
1182 "8458",
1183 "8423",
1184 "8446",
1185 "10148",
1186 "10197",
1187 "10205",
1188 "10149",
1189 "10215",
1190 "10223",
1191 "10206",
1192 "10199",
1193 "10150",
1194 "10216",
1195 "10207",
1196 "10225",
1197 "10151",
1198 "116",
1199 "205",
1200 "7300",
1201 "122",
1202 "837",
1203 "10",
1204 "7301",
1205 "7322",
1206 "6143",
1207 "120",
1208 "865",
1209 "8406",
1210 "6141",
1211 "7302",
1212 "8461",
1213 "8407",
1214 "8492",
1215 "8427",
1216 "8408",
1217 "6131",
1218 "7320",
1219 "10159",
1220 "8462",
1221 "10185",
1222 "10179",
1223 "10160",
1224 "10180",
1225 "10219",
1226 "10186",
1227 "10177",
1228 "10230",
1229 "10181",
1230 "10161",
1231 "10187",
1232 "10220",
1233 "2018",
1234 "2663",
1235 "12260",
1236 "2660",
1237 "3115",
1238 "3326",
1239 "2665",
1240 "3116",
1241 "2738",
1242 "3293",
1243 "2661",
1244 "3319",
1245 "2662",
1246 "9983",
1247 "8880",
1248 "2737",
1249 "2739",
1250 "7408",
1251 "3320",
1252 "2666",
1253 "3323",
1254 "3324",
1255 "3294",
1256 "22723",
1257 "23219",
1258 "23220",
1259 "23221",
1260 "23228",
1261 "23338",
1262 "10788",
1263 "10790",
1264 "5611",
1265 "5016",
1266 "5609",
1267 "2060",
1268 "10963",
1269 "10964",
1270 "10965",
1271 "22593",
1272 "22594",
1273 "596",
1274 "996",
1275 "499",
1276 "768",
1277 "17002",
1278 "1448",
1279 "1082",
1280 "16979",
1281 "1079",
1282 "5215",
1283 "20484",
1284 "5221",
1285 "15590",
1286 "17007",
1287 "6795",
1288 "6807",
1289 "5487",
1290 "1446",
1291 "1066",
1292 "5421",
1293 "3139",
1294 "779",
1295 "6811",
1296 "6808",
1297 "1445",
1298 "5216",
1299 "1737",
1300 "5222",
1301 "5217",
1302 "1432",
1303 "6812",
1304 "9492",
1305 "5210",
1306 "3030",
1307 "1441",
1308 "783",
1309 "6801",
1310 "20739",
1311 "8944",
1312 "9491",
1313 "22569",
1314 "5226",
1315 "6786",
1316 "1433",
1317 "8973",
1318 "1828",
1319 "9495",
1320 "9006",
1321 "6794",
1322 "8993",
1323 "5203",
1324 "16914",
1325 "6784",
1326 "9635",
1327 "22830",
1328 "20722",
1329 "9748",
1330 "6790",
1331 "9753",
1332 "9493",
1333 "9752",
1334 "9831",
1335 "9825",
1336 "9822",
1337 "5204",
1338 "5401",
1339 "22831",
1340 "6793",
1341 "9845",
1342 "17401",
1343 "9882",
1344 "9868",
1345 "20749",
1346 "9893",
1347 "9899",
1348 "9895",
1349 "9832",
1350 "9902",
1351 "9909",
1352 "22832",
1353 "9828",
1354 "9851",
1355 "9883",
1356 "9869",
1357 "17406",
1358 "17402",
1359 "9914",
1360 "20750",
1361 "9897",
1362 "9848",
1363 "3127",
1364 "107",
1365 "204",
1366 "9116",
1367 "2457",
1368 "78",
1369 "18848",
1370 "331",
1371 "403",
1372 "2098",
1373 "1752",
1374 "11278",
1375 "11288",
1376 "11284",
1377 "6461",
1378 "2344",
1379 "2345",
1380 "6463",
1381 "2346",
1382 "2352",
1383 "775",
1384 "1434",
1385 "1612",
1386 "71",
1387 "2468",
1388 "2458",
1389 "2467",
1390 "7164",
1391 "7178",
1392 "7367",
1393 "7376",
1394 "7381",
1395 "21156",
1396 "5209",
1397 "3029",
1398 "5201",
1399 "9849",
1400 "9850",
1401 "20719",
1402 "22568",
1403 "22827",
1404 "22828",
1405 "22829",
1406 "6809",
1407 "8972",
1408 "9005",
1409 "9823",
1410 "9827",
1411 "6783",
1412 "9913",
1413 "6785",
1414 "6787",
1415 "9866",
1416 "9867",
1417 "9894",
1418 "9896",
1419 "6800",
1420 "8992",
1421 "9829",
1422 "9830",
1423 "780",
1424 "769",
1425 "6749",
1426 "6750",
1427 "9755",
1428 "9754",
1429 "9908",
1430 "20745",
1431 "20742",
1432 "20747",
1433 "20748",
1434 "9746",
1435 "9745",
1436 "9880",
1437 "9881",
1438 "5391",
1439 "842",
1440 "3025",
1441 "3031",
1442 "3287",
1443 "3329",
1444 "1945",
1445 "3559",
1446 "4933",
1447 "4934",
1448 "4935",
1449 "4936",
1450 "5142",
1451 "5390",
1452 "5392",
1453 "5404",
1454 "5420",
1455 "6405",
1456 "7293",
1457 "7965",
1458 "8041",
1459 "8153",
1460 "9033",
1461 "9034",
1462 //"9036", problems with ghost state
1463 "16421",
1464 "21653",
1465 "22660",
1466 "5225",
1467 "9846",
1468 "2426",
1469 "5916",
1470 "6634",
1471 //"6718", phasing stealth, annoying for learn all case.
1472 "6719",
1473 "8822",
1474 "9591",
1475 "9590",
1476 "10032",
1477 "17746",
1478 "17747",
1479 "8203",
1480 "11392",
1481 "12495",
1482 "16380",
1483 "23452",
1484 "4079",
1485 "4996",
1486 "4997",
1487 "4998",
1488 "4999",
1489 "5000",
1490 "6348",
1491 "6349",
1492 "6481",
1493 "6482",
1494 "6483",
1495 "6484",
1496 "11362",
1497 "11410",
1498 "11409",
1499 "12510",
1500 "12509",
1501 "12885",
1502 "13142",
1503 "21463",
1504 "23460",
1505 "11421",
1506 "11416",
1507 "11418",
1508 "1851",
1509 "10059",
1510 "11423",
1511 "11417",
1512 "11422",
1513 "11419",
1514 "11424",
1515 "11420",
1516 "27",
1517 "31",
1518 "33",
1519 "34",
1520 "35",
1521 "15125",
1522 "21127",
1523 "22950",
1524 "1180",
1525 "201",
1526 "12593",
1527 "12842",
1528 "16770",
1529 "6057",
1530 "12051",
1531 "18468",
1532 "12606",
1533 "12605",
1534 "18466",
1535 "12502",
1536 "12043",
1537 "15060",
1538 "12042",
1539 "12341",
1540 "12848",
1541 "12344",
1542 "12353",
1543 "18460",
1544 "11366",
1545 "12350",
1546 "12352",
1547 "13043",
1548 "11368",
1549 "11113",
1550 "12400",
1551 "11129",
1552 "16766",
1553 "12573",
1554 "15053",
1555 "12580",
1556 "12475",
1557 "12472",
1558 "12953",
1559 "12488",
1560 "11189",
1561 "12985",
1562 "12519",
1563 "16758",
1564 "11958",
1565 "12490",
1566 "11426",
1567 "3565",
1568 "3562",
1569 "18960",
1570 "3567",
1571 "3561",
1572 "3566",
1573 "3563",
1574 "1953",
1575 "2139",
1576 "12505",
1577 "13018",
1578 "12522",
1579 "12523",
1580 "5146",
1581 "5144",
1582 "5148",
1583 "8419",
1584 "8418",
1585 "10213",
1586 "10212",
1587 "10157",
1588 "12524",
1589 "13019",
1590 "12525",
1591 "13020",
1592 "12526",
1593 "13021",
1594 "18809",
1595 "13031",
1596 "13032",
1597 "13033",
1598 "4036",
1599 "3920",
1600 "3919",
1601 "3918",
1602 "7430",
1603 "3922",
1604 "3923",
1605 "7411",
1606 "7418",
1607 "7421",
1608 "13262",
1609 "7412",
1610 "7415",
1611 "7413",
1612 "7416",
1613 "13920",
1614 "13921",
1615 "7745",
1616 "7779",
1617 "7428",
1618 "7457",
1619 "7857",
1620 "7748",
1621 "7426",
1622 "13421",
1623 "7454",
1624 "13378",
1625 "7788",
1626 "14807",
1627 "14293",
1628 "7795",
1629 "6296",
1630 "20608",
1631 "755",
1632 "444",
1633 "427",
1634 "428",
1635 "442",
1636 "447",
1637 "3578",
1638 "3581",
1639 "19027",
1640 "3580",
1641 "665",
1642 "3579",
1643 "3577",
1644 "6755",
1645 "3576",
1646 "2575",
1647 "2577",
1648 "2578",
1649 "2579",
1650 "2580",
1651 "2656",
1652 "2657",
1653 "2576",
1654 "3564",
1655 "10248",
1656 "8388",
1657 "2659",
1658 "14891",
1659 "3308",
1660 "3307",
1661 "10097",
1662 "2658",
1663 "3569",
1664 "16153",
1665 "3304",
1666 "10098",
1667 "4037",
1668 "3929",
1669 "3931",
1670 "3926",
1671 "3924",
1672 "3930",
1673 "3977",
1674 "3925",
1675 "136",
1676 "228",
1677 "5487",
1678 "43",
1679 "202",
1683 int loop = 0;
1684 while(strcmp(allSpellList[loop], "0"))
1686 uint32 spell = atol((char*)allSpellList[loop++]);
1688 if (m_session->GetPlayer()->HasSpell(spell))
1689 continue;
1691 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
1692 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
1694 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
1695 continue;
1698 m_session->GetPlayer()->learnSpell(spell,false);
1701 SendSysMessage(LANG_COMMAND_LEARN_MANY_SPELLS);
1703 return true;
1706 bool ChatHandler::HandleLearnAllGMCommand(const char* /*args*/)
1708 static const char *gmSpellList[] =
1710 "24347", // Become A Fish, No Breath Bar
1711 "35132", // Visual Boom
1712 "38488", // Attack 4000-8000 AOE
1713 "38795", // Attack 2000 AOE + Slow Down 90%
1714 "15712", // Attack 200
1715 "1852", // GM Spell Silence
1716 "31899", // Kill
1717 "31924", // Kill
1718 "29878", // Kill My Self
1719 "26644", // More Kill
1721 "28550", //Invisible 24
1722 "23452", //Invisible + Target
1726 uint16 gmSpellIter = 0;
1727 while( strcmp(gmSpellList[gmSpellIter], "0") )
1729 uint32 spell = atol((char*)gmSpellList[gmSpellIter++]);
1731 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
1732 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
1734 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
1735 continue;
1738 m_session->GetPlayer()->learnSpell(spell,false);
1741 SendSysMessage(LANG_LEARNING_GM_SKILLS);
1742 return true;
1745 bool ChatHandler::HandleLearnAllMyClassCommand(const char* /*args*/)
1747 HandleLearnAllMySpellsCommand("");
1748 HandleLearnAllMyTalentsCommand("");
1749 return true;
1752 bool ChatHandler::HandleLearnAllMySpellsCommand(const char* /*args*/)
1754 ChrClassesEntry const* clsEntry = sChrClassesStore.LookupEntry(m_session->GetPlayer()->getClass());
1755 if(!clsEntry)
1756 return true;
1757 uint32 family = clsEntry->spellfamily;
1759 for (uint32 i = 0; i < sSpellStore.GetNumRows(); ++i)
1761 SpellEntry const *spellInfo = sSpellStore.LookupEntry(i);
1762 if(!spellInfo)
1763 continue;
1765 // skip server-side/triggered spells
1766 if(spellInfo->spellLevel==0)
1767 continue;
1769 // skip wrong class/race skills
1770 if(!m_session->GetPlayer()->IsSpellFitByClassAndRace(spellInfo->Id))
1771 continue;
1773 // skip other spell families
1774 if( spellInfo->SpellFamilyName != family)
1775 continue;
1777 // skip spells with first rank learned as talent (and all talents then also)
1778 uint32 first_rank = spellmgr.GetFirstSpellInChain(spellInfo->Id);
1779 if(GetTalentSpellCost(first_rank) > 0 )
1780 continue;
1782 // skip broken spells
1783 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
1784 continue;
1786 m_session->GetPlayer()->learnSpell(i,false);
1789 SendSysMessage(LANG_COMMAND_LEARN_CLASS_SPELLS);
1790 return true;
1793 bool ChatHandler::HandleLearnAllMyTalentsCommand(const char* /*args*/)
1795 Player* player = m_session->GetPlayer();
1796 uint32 classMask = player->getClassMask();
1798 for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i)
1800 TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
1801 if(!talentInfo)
1802 continue;
1804 TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentInfo->TalentTab );
1805 if(!talentTabInfo)
1806 continue;
1808 if( (classMask & talentTabInfo->ClassMask) == 0 )
1809 continue;
1811 // search highest talent rank
1812 uint32 spellid = 0;
1814 for(int rank = MAX_TALENT_RANK-1; rank >= 0; --rank)
1816 if(talentInfo->RankID[rank]!=0)
1818 spellid = talentInfo->RankID[rank];
1819 break;
1823 if(!spellid) // ??? none spells in talent
1824 continue;
1826 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellid);
1827 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
1828 continue;
1830 // learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
1831 player->learnSpellHighRank(spellid);
1834 SendSysMessage(LANG_COMMAND_LEARN_CLASS_TALENTS);
1835 return true;
1838 bool ChatHandler::HandleLearnAllMyPetTalentsCommand(const char* /*args*/)
1840 Player* player = m_session->GetPlayer();
1842 Pet* pet = player->GetPet();
1843 if(!pet)
1845 SendSysMessage(LANG_NO_PET_FOUND);
1846 SetSentErrorMessage(true);
1847 return false;
1850 CreatureInfo const *ci = pet->GetCreatureInfo();
1851 if(!ci)
1853 SendSysMessage(LANG_WRONG_PET_TYPE);
1854 SetSentErrorMessage(true);
1855 return false;
1858 CreatureFamilyEntry const *pet_family = sCreatureFamilyStore.LookupEntry(ci->family);
1859 if(!pet_family)
1861 SendSysMessage(LANG_WRONG_PET_TYPE);
1862 SetSentErrorMessage(true);
1863 return false;
1866 if(pet_family->petTalentType < 0) // not hunter pet
1868 SendSysMessage(LANG_WRONG_PET_TYPE);
1869 SetSentErrorMessage(true);
1870 return false;
1873 for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i)
1875 TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
1876 if(!talentInfo)
1877 continue;
1879 TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentInfo->TalentTab );
1880 if(!talentTabInfo)
1881 continue;
1883 // prevent learn talent for different family (cheating)
1884 if(((1 << pet_family->petTalentType) & talentTabInfo->petTalentMask)==0)
1885 continue;
1887 // search highest talent rank
1888 uint32 spellid = 0;
1890 for(int rank = MAX_TALENT_RANK-1; rank >= 0; --rank)
1892 if(talentInfo->RankID[rank]!=0)
1894 spellid = talentInfo->RankID[rank];
1895 break;
1899 if(!spellid) // ??? none spells in talent
1900 continue;
1902 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellid);
1903 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
1904 continue;
1906 // learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
1907 pet->learnSpellHighRank(spellid);
1910 SendSysMessage(LANG_COMMAND_LEARN_PET_TALENTS);
1911 return true;
1914 bool ChatHandler::HandleLearnAllLangCommand(const char* /*args*/)
1916 // skipping UNIVERSAL language (0)
1917 for(int i = 1; i < LANGUAGES_COUNT; ++i)
1918 m_session->GetPlayer()->learnSpell(lang_description[i].spell_id,false);
1920 SendSysMessage(LANG_COMMAND_LEARN_ALL_LANG);
1921 return true;
1924 bool ChatHandler::HandleLearnAllDefaultCommand(const char* args)
1926 Player *player = NULL;
1927 if (*args)
1929 std::string name = extractPlayerNameFromLink((char*)args);
1930 if(name.empty())
1932 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1933 SetSentErrorMessage(true);
1934 return false;
1937 player = objmgr.GetPlayer(name.c_str());
1939 else
1940 player = getSelectedPlayer();
1942 if(!player)
1944 SendSysMessage(LANG_NO_CHAR_SELECTED);
1945 SetSentErrorMessage(true);
1946 return false;
1949 player->learnDefaultSpells();
1950 player->learnQuestRewardedSpells();
1952 PSendSysMessage(LANG_COMMAND_LEARN_ALL_DEFAULT_AND_QUEST,GetNameLink(player).c_str());
1953 return true;
1956 bool ChatHandler::HandleLearnCommand(const char* args)
1958 Player* targetPlayer = getSelectedPlayer();
1960 if(!targetPlayer)
1962 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1963 SetSentErrorMessage(true);
1964 return false;
1967 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1968 uint32 spell = extractSpellIdFromLink((char*)args);
1969 if(!spell || !sSpellStore.LookupEntry(spell))
1970 return false;
1972 char const* allStr = strtok(NULL," ");
1973 bool allRanks = allStr ? (strncmp(allStr, "all", strlen(allStr)) == 0) : false;
1975 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
1976 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
1978 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
1979 SetSentErrorMessage(true);
1980 return false;
1983 if (!allRanks && targetPlayer->HasSpell(spell))
1985 if(targetPlayer == m_session->GetPlayer())
1986 SendSysMessage(LANG_YOU_KNOWN_SPELL);
1987 else
1988 PSendSysMessage(LANG_TARGET_KNOWN_SPELL,GetNameLink(targetPlayer).c_str());
1989 SetSentErrorMessage(true);
1990 return false;
1993 if(allRanks)
1994 targetPlayer->learnSpellHighRank(spell);
1995 else
1996 targetPlayer->learnSpell(spell,false);
1998 return true;
2001 bool ChatHandler::HandleAddItemCommand(const char* args)
2003 if (!*args)
2004 return false;
2006 uint32 itemId = 0;
2008 if(args[0]=='[') // [name] manual form
2010 char* citemName = strtok((char*)args, "]");
2012 if(citemName && citemName[0])
2014 std::string itemName = citemName+1;
2015 WorldDatabase.escape_string(itemName);
2016 QueryResult *result = WorldDatabase.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName.c_str());
2017 if (!result)
2019 PSendSysMessage(LANG_COMMAND_COULDNOTFIND, citemName+1);
2020 SetSentErrorMessage(true);
2021 return false;
2023 itemId = result->Fetch()->GetUInt16();
2024 delete result;
2026 else
2027 return false;
2029 else // item_id or [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r
2031 char* cId = extractKeyFromLink((char*)args,"Hitem");
2032 if(!cId)
2033 return false;
2034 itemId = atol(cId);
2037 char* ccount = strtok(NULL, " ");
2039 int32 count = 1;
2041 if (ccount)
2042 count = strtol(ccount, NULL, 10);
2044 if (count == 0)
2045 count = 1;
2047 Player* pl = m_session->GetPlayer();
2048 Player* plTarget = getSelectedPlayer();
2049 if(!plTarget)
2050 plTarget = pl;
2052 sLog.outDetail(GetMangosString(LANG_ADDITEM), itemId, count);
2054 ItemPrototype const *pProto = objmgr.GetItemPrototype(itemId);
2055 if(!pProto)
2057 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, itemId);
2058 SetSentErrorMessage(true);
2059 return false;
2062 //Subtract
2063 if (count < 0)
2065 plTarget->DestroyItemCount(itemId, -count, true, false);
2066 PSendSysMessage(LANG_REMOVEITEM, itemId, -count, GetNameLink(plTarget).c_str());
2067 return true;
2070 //Adding items
2071 uint32 noSpaceForCount = 0;
2073 // check space and find places
2074 ItemPosCountVec dest;
2075 uint8 msg = plTarget->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, itemId, count, &noSpaceForCount );
2076 if( msg != EQUIP_ERR_OK ) // convert to possible store amount
2077 count -= noSpaceForCount;
2079 if( count == 0 || dest.empty()) // can't add any
2081 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount );
2082 SetSentErrorMessage(true);
2083 return false;
2086 Item* item = plTarget->StoreNewItem( dest, itemId, true, Item::GenerateItemRandomPropertyId(itemId));
2088 // remove binding (let GM give it to another player later)
2089 if(pl==plTarget)
2090 for(ItemPosCountVec::const_iterator itr = dest.begin(); itr != dest.end(); ++itr)
2091 if(Item* item1 = pl->GetItemByPos(itr->pos))
2092 item1->SetBinding( false );
2094 if(count > 0 && item)
2096 pl->SendNewItem(item,count,false,true);
2097 if(pl!=plTarget)
2098 plTarget->SendNewItem(item,count,true,false);
2101 if(noSpaceForCount > 0)
2102 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount);
2104 return true;
2107 bool ChatHandler::HandleAddItemSetCommand(const char* args)
2109 if (!*args)
2110 return false;
2112 char* cId = extractKeyFromLink((char*)args,"Hitemset"); // number or [name] Shift-click form |color|Hitemset:itemset_id|h[name]|h|r
2113 if (!cId)
2114 return false;
2116 uint32 itemsetId = atol(cId);
2118 // prevent generation all items with itemset field value '0'
2119 if (itemsetId == 0)
2121 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND,itemsetId);
2122 SetSentErrorMessage(true);
2123 return false;
2126 Player* pl = m_session->GetPlayer();
2127 Player* plTarget = getSelectedPlayer();
2128 if(!plTarget)
2129 plTarget = pl;
2131 sLog.outDetail(GetMangosString(LANG_ADDITEMSET), itemsetId);
2133 bool found = false;
2134 for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
2136 ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype>(id);
2137 if (!pProto)
2138 continue;
2140 if (pProto->ItemSet == itemsetId)
2142 found = true;
2143 ItemPosCountVec dest;
2144 uint8 msg = plTarget->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, pProto->ItemId, 1 );
2145 if (msg == EQUIP_ERR_OK)
2147 Item* item = plTarget->StoreNewItem( dest, pProto->ItemId, true);
2149 // remove binding (let GM give it to another player later)
2150 if (pl==plTarget)
2151 item->SetBinding( false );
2153 pl->SendNewItem(item,1,false,true);
2154 if (pl!=plTarget)
2155 plTarget->SendNewItem(item,1,true,false);
2157 else
2159 pl->SendEquipError( msg, NULL, NULL );
2160 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, pProto->ItemId, 1);
2165 if (!found)
2167 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND,itemsetId);
2169 SetSentErrorMessage(true);
2170 return false;
2173 return true;
2176 bool ChatHandler::HandleListItemCommand(const char* args)
2178 if(!*args)
2179 return false;
2181 char* cId = extractKeyFromLink((char*)args,"Hitem");
2182 if(!cId)
2183 return false;
2185 uint32 item_id = atol(cId);
2186 if(!item_id)
2188 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
2189 SetSentErrorMessage(true);
2190 return false;
2193 ItemPrototype const* itemProto = objmgr.GetItemPrototype(item_id);
2194 if(!itemProto)
2196 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
2197 SetSentErrorMessage(true);
2198 return false;
2201 char* c_count = strtok(NULL, " ");
2202 int count = c_count ? atol(c_count) : 10;
2204 if(count < 0)
2205 return false;
2207 QueryResult *result;
2209 // inventory case
2210 uint32 inv_count = 0;
2211 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM character_inventory WHERE item_template='%u'",item_id);
2212 if(result)
2214 inv_count = (*result)[0].GetUInt32();
2215 delete result;
2218 result=CharacterDatabase.PQuery(
2219 // 0 1 2 3 4 5
2220 "SELECT ci.item, cibag.slot AS bag, ci.slot, ci.guid, characters.account,characters.name "
2221 "FROM character_inventory AS ci LEFT JOIN character_inventory AS cibag ON (cibag.item=ci.bag),characters "
2222 "WHERE ci.item_template='%u' AND ci.guid = characters.guid LIMIT %u ",
2223 item_id,uint32(count));
2225 if(result)
2229 Field *fields = result->Fetch();
2230 uint32 item_guid = fields[0].GetUInt32();
2231 uint32 item_bag = fields[1].GetUInt32();
2232 uint32 item_slot = fields[2].GetUInt32();
2233 uint32 owner_guid = fields[3].GetUInt32();
2234 uint32 owner_acc = fields[4].GetUInt32();
2235 std::string owner_name = fields[5].GetCppString();
2237 char const* item_pos = 0;
2238 if(Player::IsEquipmentPos(item_bag,item_slot))
2239 item_pos = "[equipped]";
2240 else if(Player::IsInventoryPos(item_bag,item_slot))
2241 item_pos = "[in inventory]";
2242 else if(Player::IsBankPos(item_bag,item_slot))
2243 item_pos = "[in bank]";
2244 else
2245 item_pos = "";
2247 PSendSysMessage(LANG_ITEMLIST_SLOT,
2248 item_guid,owner_name.c_str(),owner_guid,owner_acc,item_pos);
2249 } while (result->NextRow());
2251 int64 res_count = result->GetRowCount();
2253 delete result;
2255 if(count > res_count)
2256 count-=res_count;
2257 else if(count)
2258 count = 0;
2261 // mail case
2262 uint32 mail_count = 0;
2263 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM mail_items WHERE item_template='%u'", item_id);
2264 if(result)
2266 mail_count = (*result)[0].GetUInt32();
2267 delete result;
2270 if(count > 0)
2272 result=CharacterDatabase.PQuery(
2273 // 0 1 2 3 4 5 6
2274 "SELECT mail_items.item_guid, mail.sender, mail.receiver, char_s.account, char_s.name, char_r.account, char_r.name "
2275 "FROM mail,mail_items,characters as char_s,characters as char_r "
2276 "WHERE mail_items.item_template='%u' AND char_s.guid = mail.sender AND char_r.guid = mail.receiver AND mail.id=mail_items.mail_id LIMIT %u",
2277 item_id,uint32(count));
2279 else
2280 result = NULL;
2282 if(result)
2286 Field *fields = result->Fetch();
2287 uint32 item_guid = fields[0].GetUInt32();
2288 uint32 item_s = fields[1].GetUInt32();
2289 uint32 item_r = fields[2].GetUInt32();
2290 uint32 item_s_acc = fields[3].GetUInt32();
2291 std::string item_s_name = fields[4].GetCppString();
2292 uint32 item_r_acc = fields[5].GetUInt32();
2293 std::string item_r_name = fields[6].GetCppString();
2295 char const* item_pos = "[in mail]";
2297 PSendSysMessage(LANG_ITEMLIST_MAIL,
2298 item_guid,item_s_name.c_str(),item_s,item_s_acc,item_r_name.c_str(),item_r,item_r_acc,item_pos);
2299 } while (result->NextRow());
2301 int64 res_count = result->GetRowCount();
2303 delete result;
2305 if(count > res_count)
2306 count-=res_count;
2307 else if(count)
2308 count = 0;
2311 // auction case
2312 uint32 auc_count = 0;
2313 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM auctionhouse WHERE item_template='%u'",item_id);
2314 if(result)
2316 auc_count = (*result)[0].GetUInt32();
2317 delete result;
2320 if(count > 0)
2322 result=CharacterDatabase.PQuery(
2323 // 0 1 2 3
2324 "SELECT auctionhouse.itemguid, auctionhouse.itemowner, characters.account, characters.name "
2325 "FROM auctionhouse,characters WHERE auctionhouse.item_template='%u' AND characters.guid = auctionhouse.itemowner LIMIT %u",
2326 item_id,uint32(count));
2328 else
2329 result = NULL;
2331 if(result)
2335 Field *fields = result->Fetch();
2336 uint32 item_guid = fields[0].GetUInt32();
2337 uint32 owner = fields[1].GetUInt32();
2338 uint32 owner_acc = fields[2].GetUInt32();
2339 std::string owner_name = fields[3].GetCppString();
2341 char const* item_pos = "[in auction]";
2343 PSendSysMessage(LANG_ITEMLIST_AUCTION, item_guid, owner_name.c_str(), owner, owner_acc,item_pos);
2344 } while (result->NextRow());
2346 delete result;
2349 // guild bank case
2350 uint32 guild_count = 0;
2351 result=CharacterDatabase.PQuery("SELECT COUNT(item_entry) FROM guild_bank_item WHERE item_entry='%u'",item_id);
2352 if(result)
2354 guild_count = (*result)[0].GetUInt32();
2355 delete result;
2358 result=CharacterDatabase.PQuery(
2359 // 0 1 2
2360 "SELECT gi.item_guid, gi.guildid, guild.name "
2361 "FROM guild_bank_item AS gi, guild WHERE gi.item_entry='%u' AND gi.guildid = guild.guildid LIMIT %u ",
2362 item_id,uint32(count));
2364 if(result)
2368 Field *fields = result->Fetch();
2369 uint32 item_guid = fields[0].GetUInt32();
2370 uint32 guild_guid = fields[1].GetUInt32();
2371 std::string guild_name = fields[2].GetCppString();
2373 char const* item_pos = "[in guild bank]";
2375 PSendSysMessage(LANG_ITEMLIST_GUILD,item_guid,guild_name.c_str(),guild_guid,item_pos);
2376 } while (result->NextRow());
2378 int64 res_count = result->GetRowCount();
2380 delete result;
2382 if(count > res_count)
2383 count-=res_count;
2384 else if(count)
2385 count = 0;
2388 if(inv_count+mail_count+auc_count+guild_count == 0)
2390 SendSysMessage(LANG_COMMAND_NOITEMFOUND);
2391 SetSentErrorMessage(true);
2392 return false;
2395 PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE,item_id,inv_count+mail_count+auc_count+guild_count,inv_count,mail_count,auc_count,guild_count);
2397 return true;
2400 bool ChatHandler::HandleListObjectCommand(const char* args)
2402 if(!*args)
2403 return false;
2405 // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2406 char* cId = extractKeyFromLink((char*)args,"Hgameobject_entry");
2407 if(!cId)
2408 return false;
2410 uint32 go_id = atol(cId);
2411 if(!go_id)
2413 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, go_id);
2414 SetSentErrorMessage(true);
2415 return false;
2418 GameObjectInfo const * gInfo = objmgr.GetGameObjectInfo(go_id);
2419 if(!gInfo)
2421 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, go_id);
2422 SetSentErrorMessage(true);
2423 return false;
2426 char* c_count = strtok(NULL, " ");
2427 int count = c_count ? atol(c_count) : 10;
2429 if(count < 0)
2430 return false;
2432 QueryResult *result;
2434 uint32 obj_count = 0;
2435 result=WorldDatabase.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'",go_id);
2436 if(result)
2438 obj_count = (*result)[0].GetUInt32();
2439 delete result;
2442 if(m_session)
2444 Player* pl = m_session->GetPlayer();
2445 result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map, (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ FROM gameobject WHERE id = '%u' ORDER BY order_ ASC LIMIT %u",
2446 pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(),go_id,uint32(count));
2448 else
2449 result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map FROM gameobject WHERE id = '%u' LIMIT %u",
2450 go_id,uint32(count));
2452 if (result)
2456 Field *fields = result->Fetch();
2457 uint32 guid = fields[0].GetUInt32();
2458 float x = fields[1].GetFloat();
2459 float y = fields[2].GetFloat();
2460 float z = fields[3].GetFloat();
2461 int mapid = fields[4].GetUInt16();
2463 if (m_session)
2464 PSendSysMessage(LANG_GO_LIST_CHAT, guid, guid, gInfo->name, x, y, z, mapid);
2465 else
2466 PSendSysMessage(LANG_GO_LIST_CONSOLE, guid, gInfo->name, x, y, z, mapid);
2467 } while (result->NextRow());
2469 delete result;
2472 PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE,go_id,obj_count);
2473 return true;
2476 bool ChatHandler::HandleListCreatureCommand(const char* args)
2478 if(!*args)
2479 return false;
2481 // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
2482 char* cId = extractKeyFromLink((char*)args,"Hcreature_entry");
2483 if(!cId)
2484 return false;
2486 uint32 cr_id = atol(cId);
2487 if(!cr_id)
2489 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, cr_id);
2490 SetSentErrorMessage(true);
2491 return false;
2494 CreatureInfo const* cInfo = objmgr.GetCreatureTemplate(cr_id);
2495 if(!cInfo)
2497 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, cr_id);
2498 SetSentErrorMessage(true);
2499 return false;
2502 char* c_count = strtok(NULL, " ");
2503 int count = c_count ? atol(c_count) : 10;
2505 if(count < 0)
2506 return false;
2508 QueryResult *result;
2510 uint32 cr_count = 0;
2511 result=WorldDatabase.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'",cr_id);
2512 if(result)
2514 cr_count = (*result)[0].GetUInt32();
2515 delete result;
2518 if(m_session)
2520 Player* pl = m_session->GetPlayer();
2521 result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map, (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ FROM creature WHERE id = '%u' ORDER BY order_ ASC LIMIT %u",
2522 pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(), cr_id,uint32(count));
2524 else
2525 result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '%u' LIMIT %u",
2526 cr_id,uint32(count));
2528 if (result)
2532 Field *fields = result->Fetch();
2533 uint32 guid = fields[0].GetUInt32();
2534 float x = fields[1].GetFloat();
2535 float y = fields[2].GetFloat();
2536 float z = fields[3].GetFloat();
2537 int mapid = fields[4].GetUInt16();
2539 if (m_session)
2540 PSendSysMessage(LANG_CREATURE_LIST_CHAT, guid, guid, cInfo->Name, x, y, z, mapid);
2541 else
2542 PSendSysMessage(LANG_CREATURE_LIST_CONSOLE, guid, cInfo->Name, x, y, z, mapid);
2543 } while (result->NextRow());
2545 delete result;
2548 PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE,cr_id,cr_count);
2549 return true;
2552 bool ChatHandler::HandleLookupItemCommand(const char* args)
2554 if(!*args)
2555 return false;
2557 std::string namepart = args;
2558 std::wstring wnamepart;
2560 // converting string that we try to find to lower case
2561 if(!Utf8toWStr(namepart,wnamepart))
2562 return false;
2564 wstrToLower(wnamepart);
2566 uint32 counter = 0;
2568 // Search in `item_template`
2569 for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
2571 ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype >(id);
2572 if(!pProto)
2573 continue;
2575 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
2576 if ( loc_idx >= 0 )
2578 ItemLocale const *il = objmgr.GetItemLocale(pProto->ItemId);
2579 if (il)
2581 if (il->Name.size() > loc_idx && !il->Name[loc_idx].empty())
2583 std::string name = il->Name[loc_idx];
2585 if (Utf8FitTo(name, wnamepart))
2587 if (m_session)
2588 PSendSysMessage(LANG_ITEM_LIST_CHAT, id, id, name.c_str());
2589 else
2590 PSendSysMessage(LANG_ITEM_LIST_CONSOLE, id, name.c_str());
2591 ++counter;
2592 continue;
2598 std::string name = pProto->Name1;
2599 if(name.empty())
2600 continue;
2602 if (Utf8FitTo(name, wnamepart))
2604 if (m_session)
2605 PSendSysMessage(LANG_ITEM_LIST_CHAT, id, id, name.c_str());
2606 else
2607 PSendSysMessage(LANG_ITEM_LIST_CONSOLE, id, name.c_str());
2608 ++counter;
2612 if (counter==0)
2613 SendSysMessage(LANG_COMMAND_NOITEMFOUND);
2615 return true;
2618 bool ChatHandler::HandleLookupItemSetCommand(const char* args)
2620 if(!*args)
2621 return false;
2623 std::string namepart = args;
2624 std::wstring wnamepart;
2626 if(!Utf8toWStr(namepart,wnamepart))
2627 return false;
2629 // converting string that we try to find to lower case
2630 wstrToLower( wnamepart );
2632 uint32 counter = 0; // Counter for figure out that we found smth.
2634 // Search in ItemSet.dbc
2635 for (uint32 id = 0; id < sItemSetStore.GetNumRows(); id++)
2637 ItemSetEntry const *set = sItemSetStore.LookupEntry(id);
2638 if(set)
2640 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
2641 std::string name = set->name[loc];
2642 if(name.empty())
2643 continue;
2645 if (!Utf8FitTo(name, wnamepart))
2647 loc = 0;
2648 for(; loc < MAX_LOCALE; ++loc)
2650 if(m_session && loc==m_session->GetSessionDbcLocale())
2651 continue;
2653 name = set->name[loc];
2654 if(name.empty())
2655 continue;
2657 if (Utf8FitTo(name, wnamepart))
2658 break;
2662 if(loc < MAX_LOCALE)
2664 // send item set in "id - [namedlink locale]" format
2665 if (m_session)
2666 PSendSysMessage(LANG_ITEMSET_LIST_CHAT,id,id,name.c_str(),localeNames[loc]);
2667 else
2668 PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE,id,name.c_str(),localeNames[loc]);
2669 ++counter;
2673 if (counter == 0) // if counter == 0 then we found nth
2674 SendSysMessage(LANG_COMMAND_NOITEMSETFOUND);
2675 return true;
2678 bool ChatHandler::HandleLookupSkillCommand(const char* args)
2680 if(!*args)
2681 return false;
2683 // can be NULL in console call
2684 Player* target = getSelectedPlayer();
2686 std::string namepart = args;
2687 std::wstring wnamepart;
2689 if(!Utf8toWStr(namepart,wnamepart))
2690 return false;
2692 // converting string that we try to find to lower case
2693 wstrToLower( wnamepart );
2695 uint32 counter = 0; // Counter for figure out that we found smth.
2697 // Search in SkillLine.dbc
2698 for (uint32 id = 0; id < sSkillLineStore.GetNumRows(); id++)
2700 SkillLineEntry const *skillInfo = sSkillLineStore.LookupEntry(id);
2701 if(skillInfo)
2703 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
2704 std::string name = skillInfo->name[loc];
2705 if(name.empty())
2706 continue;
2708 if (!Utf8FitTo(name, wnamepart))
2710 loc = 0;
2711 for(; loc < MAX_LOCALE; ++loc)
2713 if(m_session && loc==m_session->GetSessionDbcLocale())
2714 continue;
2716 name = skillInfo->name[loc];
2717 if(name.empty())
2718 continue;
2720 if (Utf8FitTo(name, wnamepart))
2721 break;
2725 if(loc < MAX_LOCALE)
2727 char valStr[50] = "";
2728 char const* knownStr = "";
2729 if(target && target->HasSkill(id))
2731 knownStr = GetMangosString(LANG_KNOWN);
2732 uint32 curValue = target->GetPureSkillValue(id);
2733 uint32 maxValue = target->GetPureMaxSkillValue(id);
2734 uint32 permValue = target->GetSkillPermBonusValue(id);
2735 uint32 tempValue = target->GetSkillTempBonusValue(id);
2737 char const* valFormat = GetMangosString(LANG_SKILL_VALUES);
2738 snprintf(valStr,50,valFormat,curValue,maxValue,permValue,tempValue);
2741 // send skill in "id - [namedlink locale]" format
2742 if (m_session)
2743 PSendSysMessage(LANG_SKILL_LIST_CHAT,id,id,name.c_str(),localeNames[loc],knownStr,valStr);
2744 else
2745 PSendSysMessage(LANG_SKILL_LIST_CONSOLE,id,name.c_str(),localeNames[loc],knownStr,valStr);
2747 ++counter;
2751 if (counter == 0) // if counter == 0 then we found nth
2752 SendSysMessage(LANG_COMMAND_NOSKILLFOUND);
2753 return true;
2756 bool ChatHandler::HandleLookupSpellCommand(const char* args)
2758 if(!*args)
2759 return false;
2761 // can be NULL at console call
2762 Player* target = getSelectedPlayer();
2764 std::string namepart = args;
2765 std::wstring wnamepart;
2767 if(!Utf8toWStr(namepart,wnamepart))
2768 return false;
2770 // converting string that we try to find to lower case
2771 wstrToLower( wnamepart );
2773 uint32 counter = 0; // Counter for figure out that we found smth.
2775 // Search in Spell.dbc
2776 for (uint32 id = 0; id < sSpellStore.GetNumRows(); id++)
2778 SpellEntry const *spellInfo = sSpellStore.LookupEntry(id);
2779 if(spellInfo)
2781 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
2782 std::string name = spellInfo->SpellName[loc];
2783 if(name.empty())
2784 continue;
2786 if (!Utf8FitTo(name, wnamepart))
2788 loc = 0;
2789 for(; loc < MAX_LOCALE; ++loc)
2791 if(m_session && loc==m_session->GetSessionDbcLocale())
2792 continue;
2794 name = spellInfo->SpellName[loc];
2795 if(name.empty())
2796 continue;
2798 if (Utf8FitTo(name, wnamepart))
2799 break;
2803 if(loc < MAX_LOCALE)
2805 bool known = target && target->HasSpell(id);
2806 bool learn = (spellInfo->Effect[0] == SPELL_EFFECT_LEARN_SPELL);
2808 uint32 talentCost = GetTalentSpellCost(id);
2810 bool talent = (talentCost > 0);
2811 bool passive = IsPassiveSpell(id);
2812 bool active = target && target->HasAura(id);
2814 // unit32 used to prevent interpreting uint8 as char at output
2815 // find rank of learned spell for learning spell, or talent rank
2816 uint32 rank = talentCost ? talentCost : spellmgr.GetSpellRank(learn ? spellInfo->EffectTriggerSpell[0] : id);
2818 // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
2819 std::ostringstream ss;
2820 if (m_session)
2821 ss << id << " - |cffffffff|Hspell:" << id << "|h[" << name;
2822 else
2823 ss << id << " - " << name;
2825 // include rank in link name
2826 if(rank)
2827 ss << GetMangosString(LANG_SPELL_RANK) << rank;
2829 if (m_session)
2830 ss << " " << localeNames[loc] << "]|h|r";
2831 else
2832 ss << " " << localeNames[loc];
2834 if(talent)
2835 ss << GetMangosString(LANG_TALENT);
2836 if(passive)
2837 ss << GetMangosString(LANG_PASSIVE);
2838 if(learn)
2839 ss << GetMangosString(LANG_LEARN);
2840 if(known)
2841 ss << GetMangosString(LANG_KNOWN);
2842 if(active)
2843 ss << GetMangosString(LANG_ACTIVE);
2845 SendSysMessage(ss.str().c_str());
2847 ++counter;
2851 if (counter == 0) // if counter == 0 then we found nth
2852 SendSysMessage(LANG_COMMAND_NOSPELLFOUND);
2853 return true;
2856 bool ChatHandler::HandleLookupQuestCommand(const char* args)
2858 if(!*args)
2859 return false;
2861 // can be NULL at console call
2862 Player* target = getSelectedPlayer();
2864 std::string namepart = args;
2865 std::wstring wnamepart;
2867 // converting string that we try to find to lower case
2868 if(!Utf8toWStr(namepart,wnamepart))
2869 return false;
2871 wstrToLower(wnamepart);
2873 uint32 counter = 0 ;
2875 ObjectMgr::QuestMap const& qTemplates = objmgr.GetQuestTemplates();
2876 for (ObjectMgr::QuestMap::const_iterator iter = qTemplates.begin(); iter != qTemplates.end(); ++iter)
2878 Quest * qinfo = iter->second;
2880 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
2881 if ( loc_idx >= 0 )
2883 QuestLocale const *il = objmgr.GetQuestLocale(qinfo->GetQuestId());
2884 if (il)
2886 if (il->Title.size() > loc_idx && !il->Title[loc_idx].empty())
2888 std::string title = il->Title[loc_idx];
2890 if (Utf8FitTo(title, wnamepart))
2892 char const* statusStr = "";
2894 if(target)
2896 QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId());
2898 if(status == QUEST_STATUS_COMPLETE)
2900 if(target->GetQuestRewardStatus(qinfo->GetQuestId()))
2901 statusStr = GetMangosString(LANG_COMMAND_QUEST_REWARDED);
2902 else
2903 statusStr = GetMangosString(LANG_COMMAND_QUEST_COMPLETE);
2905 else if(status == QUEST_STATUS_INCOMPLETE)
2906 statusStr = GetMangosString(LANG_COMMAND_QUEST_ACTIVE);
2909 if (m_session)
2910 PSendSysMessage(LANG_QUEST_LIST_CHAT,qinfo->GetQuestId(),qinfo->GetQuestId(),title.c_str(),statusStr);
2911 else
2912 PSendSysMessage(LANG_QUEST_LIST_CONSOLE,qinfo->GetQuestId(),title.c_str(),statusStr);
2913 ++counter;
2914 continue;
2920 std::string title = qinfo->GetTitle();
2921 if(title.empty())
2922 continue;
2924 if (Utf8FitTo(title, wnamepart))
2926 char const* statusStr = "";
2928 if(target)
2930 QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId());
2932 if(status == QUEST_STATUS_COMPLETE)
2934 if(target->GetQuestRewardStatus(qinfo->GetQuestId()))
2935 statusStr = GetMangosString(LANG_COMMAND_QUEST_REWARDED);
2936 else
2937 statusStr = GetMangosString(LANG_COMMAND_QUEST_COMPLETE);
2939 else if(status == QUEST_STATUS_INCOMPLETE)
2940 statusStr = GetMangosString(LANG_COMMAND_QUEST_ACTIVE);
2943 if (m_session)
2944 PSendSysMessage(LANG_QUEST_LIST_CHAT,qinfo->GetQuestId(),qinfo->GetQuestId(),title.c_str(),statusStr);
2945 else
2946 PSendSysMessage(LANG_QUEST_LIST_CONSOLE,qinfo->GetQuestId(),title.c_str(),statusStr);
2948 ++counter;
2952 if (counter==0)
2953 SendSysMessage(LANG_COMMAND_NOQUESTFOUND);
2955 return true;
2958 bool ChatHandler::HandleLookupCreatureCommand(const char* args)
2960 if (!*args)
2961 return false;
2963 std::string namepart = args;
2964 std::wstring wnamepart;
2966 // converting string that we try to find to lower case
2967 if (!Utf8toWStr (namepart,wnamepart))
2968 return false;
2970 wstrToLower (wnamepart);
2972 uint32 counter = 0;
2974 for (uint32 id = 0; id< sCreatureStorage.MaxEntry; ++id)
2976 CreatureInfo const* cInfo = sCreatureStorage.LookupEntry<CreatureInfo> (id);
2977 if(!cInfo)
2978 continue;
2980 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
2981 if (loc_idx >= 0)
2983 CreatureLocale const *cl = objmgr.GetCreatureLocale (id);
2984 if (cl)
2986 if (cl->Name.size() > loc_idx && !cl->Name[loc_idx].empty ())
2988 std::string name = cl->Name[loc_idx];
2990 if (Utf8FitTo (name, wnamepart))
2992 if (m_session)
2993 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str ());
2994 else
2995 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE, id, name.c_str ());
2996 ++counter;
2997 continue;
3003 std::string name = cInfo->Name;
3004 if (name.empty ())
3005 continue;
3007 if (Utf8FitTo(name, wnamepart))
3009 if (m_session)
3010 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str ());
3011 else
3012 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE, id, name.c_str ());
3013 ++counter;
3017 if (counter==0)
3018 SendSysMessage (LANG_COMMAND_NOCREATUREFOUND);
3020 return true;
3023 bool ChatHandler::HandleLookupObjectCommand(const char* args)
3025 if(!*args)
3026 return false;
3028 std::string namepart = args;
3029 std::wstring wnamepart;
3031 // converting string that we try to find to lower case
3032 if(!Utf8toWStr(namepart,wnamepart))
3033 return false;
3035 wstrToLower(wnamepart);
3037 uint32 counter = 0;
3039 for (uint32 id = 0; id< sGOStorage.MaxEntry; id++ )
3041 GameObjectInfo const* gInfo = sGOStorage.LookupEntry<GameObjectInfo>(id);
3042 if(!gInfo)
3043 continue;
3045 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
3046 if ( loc_idx >= 0 )
3048 GameObjectLocale const *gl = objmgr.GetGameObjectLocale(id);
3049 if (gl)
3051 if (gl->Name.size() > loc_idx && !gl->Name[loc_idx].empty())
3053 std::string name = gl->Name[loc_idx];
3055 if (Utf8FitTo(name, wnamepart))
3057 if (m_session)
3058 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, id, id, name.c_str());
3059 else
3060 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, id, name.c_str());
3061 ++counter;
3062 continue;
3068 std::string name = gInfo->name;
3069 if(name.empty())
3070 continue;
3072 if(Utf8FitTo(name, wnamepart))
3074 if (m_session)
3075 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, id, id, name.c_str());
3076 else
3077 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, id, name.c_str());
3078 ++counter;
3082 if(counter==0)
3083 SendSysMessage(LANG_COMMAND_NOGAMEOBJECTFOUND);
3085 return true;
3088 bool ChatHandler::HandleLookupTaxiNodeCommand(const char * args)
3090 if(!*args)
3091 return false;
3093 std::string namepart = args;
3094 std::wstring wnamepart;
3096 if(!Utf8toWStr(namepart,wnamepart))
3097 return false;
3099 // converting string that we try to find to lower case
3100 wstrToLower( wnamepart );
3102 uint32 counter = 0; // Counter for figure out that we found smth.
3104 // Search in TaxiNodes.dbc
3105 for (uint32 id = 0; id < sTaxiNodesStore.GetNumRows(); id++)
3107 TaxiNodesEntry const *nodeEntry = sTaxiNodesStore.LookupEntry(id);
3108 if(nodeEntry)
3110 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
3111 std::string name = nodeEntry->name[loc];
3112 if(name.empty())
3113 continue;
3115 if (!Utf8FitTo(name, wnamepart))
3117 loc = 0;
3118 for(; loc < MAX_LOCALE; ++loc)
3120 if(m_session && loc==m_session->GetSessionDbcLocale())
3121 continue;
3123 name = nodeEntry->name[loc];
3124 if(name.empty())
3125 continue;
3127 if (Utf8FitTo(name, wnamepart))
3128 break;
3132 if(loc < MAX_LOCALE)
3134 // send taxinode in "id - [name] (Map:m X:x Y:y Z:z)" format
3135 if (m_session)
3136 PSendSysMessage (LANG_TAXINODE_ENTRY_LIST_CHAT, id, id, name.c_str(),localeNames[loc],
3137 nodeEntry->map_id,nodeEntry->x,nodeEntry->y,nodeEntry->z);
3138 else
3139 PSendSysMessage (LANG_TAXINODE_ENTRY_LIST_CONSOLE, id, name.c_str(), localeNames[loc],
3140 nodeEntry->map_id,nodeEntry->x,nodeEntry->y,nodeEntry->z);
3141 ++counter;
3145 if (counter == 0) // if counter == 0 then we found nth
3146 SendSysMessage(LANG_COMMAND_NOSPELLFOUND);
3147 return true;
3150 /** \brief GM command level 3 - Create a guild.
3152 * This command allows a GM (level 3) to create a guild.
3154 * The "args" parameter contains the name of the guild leader
3155 * and then the name of the guild.
3158 bool ChatHandler::HandleGuildCreateCommand(const char* args)
3161 if (!*args)
3162 return false;
3164 char *lname = strtok ((char*)args, " ");
3165 char *gname = strtok (NULL, "");
3167 if (!lname)
3168 return false;
3170 if (!gname)
3172 SendSysMessage (LANG_INSERT_GUILD_NAME);
3173 SetSentErrorMessage (true);
3174 return false;
3177 std::string guildname = gname;
3179 Player* player = ObjectAccessor::Instance ().FindPlayerByName (lname);
3180 if (!player)
3182 SendSysMessage (LANG_PLAYER_NOT_FOUND);
3183 SetSentErrorMessage (true);
3184 return false;
3187 if (player->GetGuildId())
3189 SendSysMessage (LANG_PLAYER_IN_GUILD);
3190 return true;
3193 Guild *guild = new Guild;
3194 if (!guild->create (player,guildname))
3196 delete guild;
3197 SendSysMessage (LANG_GUILD_NOT_CREATED);
3198 SetSentErrorMessage (true);
3199 return false;
3202 objmgr.AddGuild (guild);
3203 return true;
3206 bool ChatHandler::HandleGuildInviteCommand(const char *args)
3208 if (!*args)
3209 return false;
3211 char* par1 = strtok ((char*)args, " ");
3212 char* par2 = strtok (NULL, "");
3213 if(!par1 || !par2)
3214 return false;
3216 std::string glName = par2;
3217 Guild* targetGuild = objmgr.GetGuildByName (glName);
3218 if (!targetGuild)
3219 return false;
3221 std::string plName = extractPlayerNameFromLink(par1);
3222 if(plName.empty())
3224 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3225 SetSentErrorMessage(true);
3226 return false;
3229 uint64 plGuid = 0;
3230 if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3231 plGuid = targetPlayer->GetGUID ();
3232 else
3233 plGuid = objmgr.GetPlayerGUIDByName (plName);
3235 if (!plGuid)
3236 return false;
3238 // player's guild membership checked in AddMember before add
3239 if (!targetGuild->AddMember (plGuid,targetGuild->GetLowestRank ()))
3240 return false;
3242 return true;
3245 bool ChatHandler::HandleGuildUninviteCommand(const char *args)
3247 if (!*args)
3248 return false;
3250 char* par1 = strtok ((char*)args, " ");
3251 if(!par1)
3252 return false;
3254 std::string plName = extractPlayerNameFromLink(par1);
3255 if(plName.empty())
3257 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3258 SetSentErrorMessage(true);
3259 return false;
3262 uint64 plGuid = 0;
3263 uint32 glId = 0;
3264 if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3266 plGuid = targetPlayer->GetGUID ();
3267 glId = targetPlayer->GetGuildId ();
3269 else
3271 plGuid = objmgr.GetPlayerGUIDByName (plName);
3272 glId = Player::GetGuildIdFromDB (plGuid);
3275 if (!plGuid || !glId)
3276 return false;
3278 Guild* targetGuild = objmgr.GetGuildById (glId);
3279 if (!targetGuild)
3280 return false;
3282 targetGuild->DelMember (plGuid);
3284 return true;
3287 bool ChatHandler::HandleGuildRankCommand(const char *args)
3289 if (!*args)
3290 return false;
3292 char* par1 = strtok ((char*)args, " ");
3293 char* par2 = strtok (NULL, " ");
3294 if (!par1 || !par2)
3295 return false;
3297 std::string plName = extractPlayerNameFromLink(par1);
3298 if(plName.empty())
3300 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3301 SetSentErrorMessage(true);
3302 return false;
3306 uint64 plGuid = 0;
3307 uint32 glId = 0;
3308 if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3310 plGuid = targetPlayer->GetGUID ();
3311 glId = targetPlayer->GetGuildId ();
3313 else
3315 plGuid = objmgr.GetPlayerGUIDByName (plName);
3316 glId = Player::GetGuildIdFromDB (plGuid);
3319 if (!plGuid || !glId)
3320 return false;
3322 Guild* targetGuild = objmgr.GetGuildById (glId);
3323 if (!targetGuild)
3324 return false;
3326 uint32 newrank = uint32 (atoi (par2));
3327 if (newrank > targetGuild->GetLowestRank ())
3328 return false;
3330 targetGuild->ChangeRank (plGuid,newrank);
3332 return true;
3335 bool ChatHandler::HandleGuildDeleteCommand(const char* args)
3337 if (!*args)
3338 return false;
3340 char* par1 = strtok ((char*)args, " ");
3341 if (!par1)
3342 return false;
3344 std::string gld = par1;
3346 Guild* targetGuild = objmgr.GetGuildByName (gld);
3347 if (!targetGuild)
3348 return false;
3350 targetGuild->Disband ();
3352 return true;
3355 bool ChatHandler::HandleGetDistanceCommand(const char* args)
3357 WorldObject* obj = NULL;
3359 if (*args)
3361 uint64 guid = extractGuidFromLink((char*)args);
3362 if(guid)
3363 obj = (WorldObject*)ObjectAccessor::GetObjectByTypeMask(*m_session->GetPlayer(),guid,TYPEMASK_UNIT|TYPEMASK_GAMEOBJECT);
3365 if(!obj)
3367 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3368 SetSentErrorMessage(true);
3369 return false;
3372 else
3374 obj = getSelectedUnit();
3376 if(!obj)
3378 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3379 SetSentErrorMessage(true);
3380 return false;
3384 PSendSysMessage(LANG_DISTANCE, m_session->GetPlayer()->GetDistance(obj),m_session->GetPlayer()->GetDistance2d(obj));
3386 return true;
3389 bool ChatHandler::HandleDieCommand(const char* /*args*/)
3391 Unit* target = getSelectedUnit();
3393 if(!target || !m_session->GetPlayer()->GetSelection())
3395 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3396 SetSentErrorMessage(true);
3397 return false;
3400 if(target->GetTypeId()==TYPEID_PLAYER)
3402 if(HasLowerSecurity((Player*)target,0,false))
3403 return false;
3406 if( target->isAlive() )
3408 m_session->GetPlayer()->DealDamage(target, target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
3411 return true;
3414 bool ChatHandler::HandleDamageCommand(const char * args)
3416 if (!*args)
3417 return false;
3419 Unit* target = getSelectedUnit();
3421 if(!target || !m_session->GetPlayer()->GetSelection())
3423 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3424 SetSentErrorMessage(true);
3425 return false;
3428 if( !target->isAlive() )
3429 return true;
3431 char* damageStr = strtok((char*)args, " ");
3432 if(!damageStr)
3433 return false;
3435 int32 damage = atoi((char*)damageStr);
3436 if(damage <=0)
3437 return true;
3439 char* schoolStr = strtok((char*)NULL, " ");
3441 // flat melee damage without resistence/etc reduction
3442 if(!schoolStr)
3444 m_session->GetPlayer()->DealDamage(target, damage, NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
3445 m_session->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2, target, 1, SPELL_SCHOOL_MASK_NORMAL, damage, 0, 0, VICTIMSTATE_NORMAL, 0);
3446 return true;
3449 uint32 school = schoolStr ? atoi((char*)schoolStr) : SPELL_SCHOOL_NORMAL;
3450 if(school >= MAX_SPELL_SCHOOL)
3451 return false;
3453 SpellSchoolMask schoolmask = SpellSchoolMask(1 << school);
3455 if ( schoolmask & SPELL_SCHOOL_MASK_NORMAL )
3456 damage = m_session->GetPlayer()->CalcArmorReducedDamage(target, damage);
3458 char* spellStr = strtok((char*)NULL, " ");
3460 // melee damage by specific school
3461 if(!spellStr)
3463 uint32 absorb = 0;
3464 uint32 resist = 0;
3466 m_session->GetPlayer()->CalcAbsorbResist(target,schoolmask, SPELL_DIRECT_DAMAGE, damage, &absorb, &resist);
3468 if (damage <= absorb + resist)
3469 return true;
3471 damage -= absorb + resist;
3473 m_session->GetPlayer()->DealDamage(target, damage, NULL, DIRECT_DAMAGE, schoolmask, NULL, false);
3474 m_session->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2, target, 1, schoolmask, damage, absorb, resist, VICTIMSTATE_NORMAL, 0);
3475 return true;
3478 // non-melee damage
3480 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3481 uint32 spellid = extractSpellIdFromLink((char*)args);
3482 if(!spellid || !sSpellStore.LookupEntry(spellid))
3483 return false;
3485 m_session->GetPlayer()->SpellNonMeleeDamageLog(target, spellid, damage);
3486 return true;
3489 bool ChatHandler::HandleModifyArenaCommand(const char * args)
3491 if (!*args)
3492 return false;
3494 Player *target = getSelectedPlayer();
3495 if(!target)
3497 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3498 SetSentErrorMessage(true);
3499 return false;
3502 int32 amount = (uint32)atoi(args);
3504 target->ModifyArenaPoints(amount);
3506 PSendSysMessage(LANG_COMMAND_MODIFY_ARENA, GetNameLink(target).c_str(), target->GetArenaPoints());
3508 return true;
3511 bool ChatHandler::HandleReviveCommand(const char* args)
3513 Player* player = NULL;
3514 uint64 player_guid = 0;
3516 if (*args)
3518 std::string name = extractPlayerNameFromLink((char*)args);
3519 if (name.empty())
3521 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3522 SetSentErrorMessage(true);
3523 return false;
3526 player = objmgr.GetPlayer(name.c_str());
3527 if (!player)
3528 player_guid = objmgr.GetPlayerGUIDByName(name);
3530 else
3531 player = getSelectedPlayer();
3533 if (player)
3535 player->ResurrectPlayer(0.5f);
3536 player->SpawnCorpseBones();
3537 player->SaveToDB();
3539 else if (player_guid)
3541 // will resurrected at login without corpse
3542 ObjectAccessor::Instance().ConvertCorpseForPlayer(player_guid);
3544 else
3546 SendSysMessage(LANG_NO_CHAR_SELECTED);
3547 SetSentErrorMessage(true);
3548 return false;
3551 return true;
3554 bool ChatHandler::HandleAuraCommand(const char* args)
3556 Unit *target = getSelectedUnit();
3557 if(!target)
3559 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3560 SetSentErrorMessage(true);
3561 return false;
3564 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3565 uint32 spellID = extractSpellIdFromLink((char*)args);
3567 SpellEntry const *spellInfo = sSpellStore.LookupEntry( spellID );
3568 if(spellInfo)
3570 for(uint32 i = 0;i<3;++i)
3572 uint8 eff = spellInfo->Effect[i];
3573 if (eff>=TOTAL_SPELL_EFFECTS)
3574 continue;
3575 if( IsAreaAuraEffect(eff) ||
3576 eff == SPELL_EFFECT_APPLY_AURA ||
3577 eff == SPELL_EFFECT_PERSISTENT_AREA_AURA )
3579 Aura *Aur = CreateAura(spellInfo, i, NULL, target);
3580 target->AddAura(Aur);
3585 return true;
3588 bool ChatHandler::HandleUnAuraCommand(const char* args)
3590 Unit *target = getSelectedUnit();
3591 if(!target)
3593 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3594 SetSentErrorMessage(true);
3595 return false;
3598 std::string argstr = args;
3599 if (argstr == "all")
3601 target->RemoveAllAuras();
3602 return true;
3605 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3606 uint32 spellID = extractSpellIdFromLink((char*)args);
3607 if(!spellID)
3608 return false;
3610 target->RemoveAurasDueToSpell(spellID);
3612 return true;
3615 bool ChatHandler::HandleLinkGraveCommand(const char* args)
3617 if(!*args)
3618 return false;
3620 char* px = strtok((char*)args, " ");
3621 if (!px)
3622 return false;
3624 uint32 g_id = (uint32)atoi(px);
3626 uint32 g_team;
3628 char* px2 = strtok(NULL, " ");
3630 if (!px2)
3631 g_team = 0;
3632 else if (strncmp(px2,"horde",6)==0)
3633 g_team = HORDE;
3634 else if (strncmp(px2,"alliance",9)==0)
3635 g_team = ALLIANCE;
3636 else
3637 return false;
3639 WorldSafeLocsEntry const* graveyard = sWorldSafeLocsStore.LookupEntry(g_id);
3641 if(!graveyard )
3643 PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST, g_id);
3644 SetSentErrorMessage(true);
3645 return false;
3648 Player* player = m_session->GetPlayer();
3650 uint32 zoneId = player->GetZoneId();
3652 AreaTableEntry const *areaEntry = GetAreaEntryByAreaID(zoneId);
3653 if(!areaEntry || areaEntry->zone !=0 )
3655 PSendSysMessage(LANG_COMMAND_GRAVEYARDWRONGZONE, g_id,zoneId);
3656 SetSentErrorMessage(true);
3657 return false;
3660 if(objmgr.AddGraveYardLink(g_id,zoneId,g_team))
3661 PSendSysMessage(LANG_COMMAND_GRAVEYARDLINKED, g_id,zoneId);
3662 else
3663 PSendSysMessage(LANG_COMMAND_GRAVEYARDALRLINKED, g_id,zoneId);
3665 return true;
3668 bool ChatHandler::HandleNearGraveCommand(const char* args)
3670 uint32 g_team;
3672 size_t argslen = strlen(args);
3674 if(!*args)
3675 g_team = 0;
3676 else if (strncmp((char*)args,"horde",argslen)==0)
3677 g_team = HORDE;
3678 else if (strncmp((char*)args,"alliance",argslen)==0)
3679 g_team = ALLIANCE;
3680 else
3681 return false;
3683 Player* player = m_session->GetPlayer();
3684 uint32 zone_id = player->GetZoneId();
3686 WorldSafeLocsEntry const* graveyard = objmgr.GetClosestGraveYard(
3687 player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(),player->GetMapId(),g_team);
3689 if(graveyard)
3691 uint32 g_id = graveyard->ID;
3693 GraveYardData const* data = objmgr.FindGraveYardData(g_id,zone_id);
3694 if (!data)
3696 PSendSysMessage(LANG_COMMAND_GRAVEYARDERROR,g_id);
3697 SetSentErrorMessage(true);
3698 return false;
3701 g_team = data->team;
3703 std::string team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_NOTEAM);
3705 if(g_team == 0)
3706 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ANY);
3707 else if(g_team == HORDE)
3708 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE);
3709 else if(g_team == ALLIANCE)
3710 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE);
3712 PSendSysMessage(LANG_COMMAND_GRAVEYARDNEAREST, g_id,team_name.c_str(),zone_id);
3714 else
3716 std::string team_name;
3718 if(g_team == 0)
3719 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ANY);
3720 else if(g_team == HORDE)
3721 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE);
3722 else if(g_team == ALLIANCE)
3723 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE);
3725 if(g_team == ~uint32(0))
3726 PSendSysMessage(LANG_COMMAND_ZONENOGRAVEYARDS, zone_id);
3727 else
3728 PSendSysMessage(LANG_COMMAND_ZONENOGRAFACTION, zone_id,team_name.c_str());
3731 return true;
3734 //-----------------------Npc Commands-----------------------
3735 bool ChatHandler::HandleNpcAllowMovementCommand(const char* /*args*/)
3737 if(sWorld.getAllowMovement())
3739 sWorld.SetAllowMovement(false);
3740 SendSysMessage(LANG_CREATURE_MOVE_DISABLED);
3742 else
3744 sWorld.SetAllowMovement(true);
3745 SendSysMessage(LANG_CREATURE_MOVE_ENABLED);
3747 return true;
3750 bool ChatHandler::HandleNpcChangeEntryCommand(const char *args)
3752 if (!*args)
3753 return false;
3755 uint32 newEntryNum = atoi(args);
3756 if(!newEntryNum)
3757 return false;
3759 Unit* unit = getSelectedUnit();
3760 if(!unit || unit->GetTypeId() != TYPEID_UNIT)
3762 SendSysMessage(LANG_SELECT_CREATURE);
3763 SetSentErrorMessage(true);
3764 return false;
3766 Creature* creature = (Creature*)unit;
3767 if(creature->UpdateEntry(newEntryNum))
3768 SendSysMessage(LANG_DONE);
3769 else
3770 SendSysMessage(LANG_ERROR);
3771 return true;
3774 bool ChatHandler::HandleNpcInfoCommand(const char* /*args*/)
3776 Creature* target = getSelectedCreature();
3778 if(!target)
3780 SendSysMessage(LANG_SELECT_CREATURE);
3781 SetSentErrorMessage(true);
3782 return false;
3785 uint32 faction = target->getFaction();
3786 uint32 npcflags = target->GetUInt32Value(UNIT_NPC_FLAGS);
3787 uint32 displayid = target->GetDisplayId();
3788 uint32 nativeid = target->GetNativeDisplayId();
3789 uint32 Entry = target->GetEntry();
3790 CreatureInfo const* cInfo = target->GetCreatureInfo();
3792 int32 curRespawnDelay = target->GetRespawnTimeEx()-time(NULL);
3793 if(curRespawnDelay < 0)
3794 curRespawnDelay = 0;
3795 std::string curRespawnDelayStr = secsToTimeString(curRespawnDelay,true);
3796 std::string defRespawnDelayStr = secsToTimeString(target->GetRespawnDelay(),true);
3798 PSendSysMessage(LANG_NPCINFO_CHAR, target->GetDBTableGUIDLow(), faction, npcflags, Entry, displayid, nativeid);
3799 PSendSysMessage(LANG_NPCINFO_LEVEL, target->getLevel());
3800 PSendSysMessage(LANG_NPCINFO_HEALTH,target->GetCreateHealth(), target->GetMaxHealth(), target->GetHealth());
3801 PSendSysMessage(LANG_NPCINFO_FLAGS, target->GetUInt32Value(UNIT_FIELD_FLAGS), target->GetUInt32Value(UNIT_DYNAMIC_FLAGS), target->getFaction());
3802 PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES, defRespawnDelayStr.c_str(),curRespawnDelayStr.c_str());
3803 PSendSysMessage(LANG_NPCINFO_LOOT, cInfo->lootid,cInfo->pickpocketLootId,cInfo->SkinLootId);
3804 PSendSysMessage(LANG_NPCINFO_DUNGEON_ID, target->GetInstanceId());
3805 PSendSysMessage(LANG_NPCINFO_POSITION,float(target->GetPositionX()), float(target->GetPositionY()), float(target->GetPositionZ()));
3807 if ((npcflags & UNIT_NPC_FLAG_VENDOR) )
3809 SendSysMessage(LANG_NPCINFO_VENDOR);
3811 if ((npcflags & UNIT_NPC_FLAG_TRAINER) )
3813 SendSysMessage(LANG_NPCINFO_TRAINER);
3816 return true;
3819 //play npc emote
3820 bool ChatHandler::HandleNpcPlayEmoteCommand(const char* args)
3822 uint32 emote = atoi((char*)args);
3824 Creature* target = getSelectedCreature();
3825 if(!target)
3827 SendSysMessage(LANG_SELECT_CREATURE);
3828 SetSentErrorMessage(true);
3829 return false;
3832 target->SetUInt32Value(UNIT_NPC_EMOTESTATE,emote);
3834 return true;
3837 //TODO: NpcCommands that needs to be fixed :
3839 bool ChatHandler::HandleNpcAddWeaponCommand(const char* /*args*/)
3841 /*if (!*args)
3842 return false;
3844 uint64 guid = m_session->GetPlayer()->GetSelection();
3845 if (guid == 0)
3847 SendSysMessage(LANG_NO_SELECTION);
3848 return true;
3851 Creature *pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
3853 if(!pCreature)
3855 SendSysMessage(LANG_SELECT_CREATURE);
3856 return true;
3859 char* pSlotID = strtok((char*)args, " ");
3860 if (!pSlotID)
3861 return false;
3863 char* pItemID = strtok(NULL, " ");
3864 if (!pItemID)
3865 return false;
3867 uint32 ItemID = atoi(pItemID);
3868 uint32 SlotID = atoi(pSlotID);
3870 ItemPrototype* tmpItem = objmgr.GetItemPrototype(ItemID);
3872 bool added = false;
3873 if(tmpItem)
3875 switch(SlotID)
3877 case 1:
3878 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID);
3879 added = true;
3880 break;
3881 case 2:
3882 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID);
3883 added = true;
3884 break;
3885 case 3:
3886 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID);
3887 added = true;
3888 break;
3889 default:
3890 PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST,SlotID);
3891 added = false;
3892 break;
3895 if(added)
3896 PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT,ItemID,tmpItem->Name1,SlotID);
3898 else
3900 PSendSysMessage(LANG_ITEM_NOT_FOUND,ItemID);
3901 return true;
3904 return true;
3906 //----------------------------------------------------------
3908 bool ChatHandler::HandleExploreCheatCommand(const char* args)
3910 if (!*args)
3911 return false;
3913 int flag = atoi((char*)args);
3915 Player *chr = getSelectedPlayer();
3916 if (chr == NULL)
3918 SendSysMessage(LANG_NO_CHAR_SELECTED);
3919 SetSentErrorMessage(true);
3920 return false;
3923 if (flag != 0)
3925 PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL, GetNameLink(chr).c_str());
3926 if (needReportToTarget(chr))
3927 ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_ALL,GetNameLink().c_str());
3929 else
3931 PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING, GetNameLink(chr).c_str());
3932 if (needReportToTarget(chr))
3933 ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_NOTHING,GetNameLink().c_str());
3936 for (uint8 i=0; i<128; ++i)
3938 if (flag != 0)
3940 m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1+i,0xFFFFFFFF);
3942 else
3944 m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1+i,0);
3948 return true;
3951 bool ChatHandler::HandleHoverCommand(const char* args)
3953 char* px = strtok((char*)args, " ");
3954 uint32 flag;
3955 if (!px)
3956 flag = 1;
3957 else
3958 flag = atoi(px);
3960 m_session->GetPlayer()->SetHover(flag);
3962 if (flag)
3963 SendSysMessage(LANG_HOVER_ENABLED);
3964 else
3965 SendSysMessage(LANG_HOVER_DISABLED);
3967 return true;
3970 void ChatHandler::HandleCharacterLevel(Player* player, uint64 player_guid, uint32 oldlevel, uint32 newlevel)
3972 if(player)
3974 player->GiveLevel(newlevel);
3975 player->InitTalentForLevel();
3976 player->SetUInt32Value(PLAYER_XP,0);
3978 if(needReportToTarget(player))
3980 if(oldlevel == newlevel)
3981 ChatHandler(player).PSendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET,GetNameLink().c_str());
3982 else if(oldlevel < newlevel)
3983 ChatHandler(player).PSendSysMessage(LANG_YOURS_LEVEL_UP,GetNameLink().c_str(),newlevel);
3984 else // if(oldlevel > newlevel)
3985 ChatHandler(player).PSendSysMessage(LANG_YOURS_LEVEL_DOWN,GetNameLink().c_str(),newlevel);
3988 else
3990 // update level and XP at level, all other will be updated at loading
3991 Tokens values;
3992 Player::LoadValuesArrayFromDB(values,player_guid);
3993 Player::SetUInt32ValueInArray(values,UNIT_FIELD_LEVEL,newlevel);
3994 Player::SetUInt32ValueInArray(values,PLAYER_XP,0);
3995 Player::SaveValuesArrayInDB(values,player_guid);
3999 bool ChatHandler::HandleCharacterLevelCommand(const char* args)
4001 char* px = strtok((char*)args, " ");
4002 char* py = strtok((char*)NULL, " ");
4004 // command format parsing
4005 char* pname = (char*)NULL;
4006 int32 newlevel = 0;
4008 if(px && py) // .character level $name #level
4010 newlevel = atoi(py);
4011 pname = px;
4013 else if(px && !py) // .character level $name OR .character level #level
4015 if(isalpha(px[0])) // .character level $name
4016 pname = px;
4017 else // .character level #level
4018 newlevel = atoi(px);
4020 // // .character level - progress reset
4022 if(newlevel < 1)
4023 return false; // invalid level
4025 if(newlevel > STRONG_MAX_LEVEL) // hardcoded maximum level
4026 newlevel = STRONG_MAX_LEVEL;
4028 // player
4029 Player *chr = NULL;
4030 uint64 chr_guid = 0;
4032 std::string name;
4034 if(pname) // player by name
4036 name = extractPlayerNameFromLink(pname);
4037 if(name.empty())
4039 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4040 SetSentErrorMessage(true);
4041 return false;
4044 chr = objmgr.GetPlayer(name.c_str());
4045 if(!chr) // not in game
4047 chr_guid = objmgr.GetPlayerGUIDByName(name);
4048 if (chr_guid == 0)
4050 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4051 SetSentErrorMessage(true);
4052 return false;
4056 else // player by selection
4058 chr = getSelectedPlayer();
4060 if (chr == NULL)
4062 SendSysMessage(LANG_NO_CHAR_SELECTED);
4063 SetSentErrorMessage(true);
4064 return false;
4067 name = chr->GetName();
4070 assert(chr || chr_guid);
4072 int32 oldlevel = chr ? chr->getLevel() : Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL,chr_guid);
4074 if(!px && !py) // .character level - progress reset
4075 newlevel = oldlevel;
4077 HandleCharacterLevel(chr,chr_guid,oldlevel,newlevel);
4079 if(m_session && m_session->GetPlayer() != chr) // including player==NULL
4081 std::string nameLink = playerLink(name);
4082 PSendSysMessage(LANG_YOU_CHANGE_LVL,nameLink.c_str(),newlevel);
4085 return true;
4088 bool ChatHandler::HandleLevelUpCommand(const char* args)
4090 char* px = strtok((char*)args, " ");
4091 char* py = strtok((char*)NULL, " ");
4093 // command format parsing
4094 char* pname = (char*)NULL;
4095 int addlevel = 1;
4097 if(px && py) // .levelup name level
4099 addlevel = atoi(py);
4100 pname = px;
4102 else if(px && !py) // .levelup name OR .levelup level
4104 if(isalpha(px[0])) // .levelup name
4105 pname = px;
4106 else // .levelup level
4107 addlevel = atoi(px);
4109 // else .levelup - nothing do for preparing
4111 // player
4112 Player *chr = NULL;
4113 uint64 chr_guid = 0;
4115 std::string name;
4117 if(pname) // player by name
4119 name = extractPlayerNameFromLink(pname);
4120 if(name.empty())
4122 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4123 SetSentErrorMessage(true);
4124 return false;
4127 chr = objmgr.GetPlayer(name.c_str());
4128 if(!chr) // not in game
4130 chr_guid = objmgr.GetPlayerGUIDByName(name);
4131 if (chr_guid == 0)
4133 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4134 SetSentErrorMessage(true);
4135 return false;
4139 else // player by selection
4141 chr = getSelectedPlayer();
4143 if (chr == NULL)
4145 SendSysMessage(LANG_NO_CHAR_SELECTED);
4146 SetSentErrorMessage(true);
4147 return false;
4150 name = chr->GetName();
4153 assert(chr || chr_guid);
4155 int32 oldlevel = chr ? chr->getLevel() : Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL,chr_guid);
4156 int32 newlevel = oldlevel + addlevel;
4157 if(newlevel < 1)
4158 newlevel = 1;
4159 if(newlevel > STRONG_MAX_LEVEL) // hardcoded maximum level
4160 newlevel = STRONG_MAX_LEVEL;
4162 HandleCharacterLevel(chr,chr_guid,oldlevel,newlevel);
4164 if(m_session && m_session->GetPlayer() != chr) // including chr==NULL
4166 std::string nameLink = playerLink(name);
4167 PSendSysMessage(LANG_YOU_CHANGE_LVL,nameLink.c_str(),newlevel);
4170 return true;
4173 bool ChatHandler::HandleShowAreaCommand(const char* args)
4175 if (!*args)
4176 return false;
4178 Player *chr = getSelectedPlayer();
4179 if (chr == NULL)
4181 SendSysMessage(LANG_NO_CHAR_SELECTED);
4182 SetSentErrorMessage(true);
4183 return false;
4186 int area = GetAreaFlagByAreaID(atoi((char*)args));
4187 int offset = area / 32;
4188 uint32 val = (uint32)(1 << (area % 32));
4190 if(area<0 || offset >= 128)
4192 SendSysMessage(LANG_BAD_VALUE);
4193 SetSentErrorMessage(true);
4194 return false;
4197 uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
4198 chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields | val));
4200 SendSysMessage(LANG_EXPLORE_AREA);
4201 return true;
4204 bool ChatHandler::HandleHideAreaCommand(const char* args)
4206 if (!*args)
4207 return false;
4209 Player *chr = getSelectedPlayer();
4210 if (chr == NULL)
4212 SendSysMessage(LANG_NO_CHAR_SELECTED);
4213 SetSentErrorMessage(true);
4214 return false;
4217 int area = GetAreaFlagByAreaID(atoi((char*)args));
4218 int offset = area / 32;
4219 uint32 val = (uint32)(1 << (area % 32));
4221 if(area<0 || offset >= 128)
4223 SendSysMessage(LANG_BAD_VALUE);
4224 SetSentErrorMessage(true);
4225 return false;
4228 uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
4229 chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields ^ val));
4231 SendSysMessage(LANG_UNEXPLORE_AREA);
4232 return true;
4235 bool ChatHandler::HandleDebugUpdate(const char* args)
4237 if(!*args)
4238 return false;
4240 uint32 updateIndex;
4241 uint32 value;
4243 char* pUpdateIndex = strtok((char*)args, " ");
4245 Unit* chr = getSelectedUnit();
4246 if (chr == NULL)
4248 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4249 SetSentErrorMessage(true);
4250 return false;
4253 if(!pUpdateIndex)
4255 return true;
4257 updateIndex = atoi(pUpdateIndex);
4258 //check updateIndex
4259 if(chr->GetTypeId() == TYPEID_PLAYER)
4261 if (updateIndex>=PLAYER_END) return true;
4263 else
4265 if (updateIndex>=UNIT_END) return true;
4268 char* pvalue = strtok(NULL, " ");
4269 if (!pvalue)
4271 value=chr->GetUInt32Value(updateIndex);
4273 PSendSysMessage(LANG_UPDATE, chr->GetGUIDLow(),updateIndex,value);
4274 return true;
4277 value=atoi(pvalue);
4279 PSendSysMessage(LANG_UPDATE_CHANGE, chr->GetGUIDLow(),updateIndex,value);
4281 chr->SetUInt32Value(updateIndex,value);
4283 return true;
4286 bool ChatHandler::HandleBankCommand(const char* /*args*/)
4288 m_session->SendShowBank( m_session->GetPlayer()->GetGUID() );
4290 return true;
4293 bool ChatHandler::HandleChangeWeather(const char* args)
4295 if(!*args)
4296 return false;
4298 //Weather is OFF
4299 if (!sWorld.getConfig(CONFIG_WEATHER))
4301 SendSysMessage(LANG_WEATHER_DISABLED);
4302 SetSentErrorMessage(true);
4303 return false;
4306 //*Change the weather of a cell
4307 char* px = strtok((char*)args, " ");
4308 char* py = strtok(NULL, " ");
4310 if (!px || !py)
4311 return false;
4313 uint32 type = (uint32)atoi(px); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
4314 float grade = (float)atof(py); //0 to 1, sending -1 is instand good weather
4316 Player *player = m_session->GetPlayer();
4317 uint32 zoneid = player->GetZoneId();
4319 Weather* wth = sWorld.FindWeather(zoneid);
4321 if(!wth)
4322 wth = sWorld.AddWeather(zoneid);
4323 if(!wth)
4325 SendSysMessage(LANG_NO_WEATHER);
4326 SetSentErrorMessage(true);
4327 return false;
4330 wth->SetWeather(WeatherType(type), grade);
4332 return true;
4335 bool ChatHandler::HandleDebugSetValue(const char* args)
4337 if(!*args)
4338 return false;
4340 char* px = strtok((char*)args, " ");
4341 char* py = strtok(NULL, " ");
4342 char* pz = strtok(NULL, " ");
4344 if (!px || !py)
4345 return false;
4347 Unit* target = getSelectedUnit();
4348 if(!target)
4350 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4351 SetSentErrorMessage(true);
4352 return false;
4355 uint64 guid = target->GetGUID();
4357 uint32 Opcode = (uint32)atoi(px);
4358 if(Opcode >= target->GetValuesCount())
4360 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, GUID_LOPART(guid), target->GetValuesCount());
4361 return false;
4363 uint32 iValue;
4364 float fValue;
4365 bool isint32 = true;
4366 if(pz)
4367 isint32 = (bool)atoi(pz);
4368 if(isint32)
4370 iValue = (uint32)atoi(py);
4371 sLog.outDebug(GetMangosString(LANG_SET_UINT), GUID_LOPART(guid), Opcode, iValue);
4372 target->SetUInt32Value( Opcode , iValue );
4373 PSendSysMessage(LANG_SET_UINT_FIELD, GUID_LOPART(guid), Opcode,iValue);
4375 else
4377 fValue = (float)atof(py);
4378 sLog.outDebug(GetMangosString(LANG_SET_FLOAT), GUID_LOPART(guid), Opcode, fValue);
4379 target->SetFloatValue( Opcode , fValue );
4380 PSendSysMessage(LANG_SET_FLOAT_FIELD, GUID_LOPART(guid), Opcode,fValue);
4383 return true;
4386 bool ChatHandler::HandleDebugGetValue(const char* args)
4388 if(!*args)
4389 return false;
4391 char* px = strtok((char*)args, " ");
4392 char* pz = strtok(NULL, " ");
4394 if (!px)
4395 return false;
4397 Unit* target = getSelectedUnit();
4398 if(!target)
4400 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4401 SetSentErrorMessage(true);
4402 return false;
4405 uint64 guid = target->GetGUID();
4407 uint32 Opcode = (uint32)atoi(px);
4408 if(Opcode >= target->GetValuesCount())
4410 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, GUID_LOPART(guid), target->GetValuesCount());
4411 return false;
4413 uint32 iValue;
4414 float fValue;
4415 bool isint32 = true;
4416 if(pz)
4417 isint32 = (bool)atoi(pz);
4419 if(isint32)
4421 iValue = target->GetUInt32Value( Opcode );
4422 sLog.outDebug(GetMangosString(LANG_GET_UINT), GUID_LOPART(guid), Opcode, iValue);
4423 PSendSysMessage(LANG_GET_UINT_FIELD, GUID_LOPART(guid), Opcode, iValue);
4425 else
4427 fValue = target->GetFloatValue( Opcode );
4428 sLog.outDebug(GetMangosString(LANG_GET_FLOAT), GUID_LOPART(guid), Opcode, fValue);
4429 PSendSysMessage(LANG_GET_FLOAT_FIELD, GUID_LOPART(guid), Opcode, fValue);
4432 return true;
4435 bool ChatHandler::HandleSet32Bit(const char* args)
4437 if(!*args)
4438 return false;
4440 char* px = strtok((char*)args, " ");
4441 char* py = strtok(NULL, " ");
4443 if (!px || !py)
4444 return false;
4446 uint32 Opcode = (uint32)atoi(px);
4447 uint32 Value = (uint32)atoi(py);
4448 if (Value > 32) //uint32 = 32 bits
4449 return false;
4451 sLog.outDebug(GetMangosString(LANG_SET_32BIT), Opcode, Value);
4453 m_session->GetPlayer( )->SetUInt32Value( Opcode , 2^Value );
4455 PSendSysMessage(LANG_SET_32BIT_FIELD, Opcode,1);
4456 return true;
4459 bool ChatHandler::HandleDebugMod32Value(const char* args)
4461 if(!*args)
4462 return false;
4464 char* px = strtok((char*)args, " ");
4465 char* py = strtok(NULL, " ");
4467 if (!px || !py)
4468 return false;
4470 uint32 Opcode = (uint32)atoi(px);
4471 int Value = atoi(py);
4473 if(Opcode >= m_session->GetPlayer()->GetValuesCount())
4475 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, m_session->GetPlayer()->GetGUIDLow(), m_session->GetPlayer( )->GetValuesCount());
4476 return false;
4479 sLog.outDebug(GetMangosString(LANG_CHANGE_32BIT), Opcode, Value);
4481 int CurrentValue = (int)m_session->GetPlayer( )->GetUInt32Value( Opcode );
4483 CurrentValue += Value;
4484 m_session->GetPlayer( )->SetUInt32Value( Opcode , (uint32)CurrentValue );
4486 PSendSysMessage(LANG_CHANGE_32BIT_FIELD, Opcode,CurrentValue);
4488 return true;
4491 bool ChatHandler::HandleTeleAddCommand(const char * args)
4493 if(!*args)
4494 return false;
4496 Player *player=m_session->GetPlayer();
4497 if (!player)
4498 return false;
4500 std::string name = args;
4502 if(objmgr.GetGameTele(name))
4504 SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST);
4505 SetSentErrorMessage(true);
4506 return false;
4509 GameTele tele;
4510 tele.position_x = player->GetPositionX();
4511 tele.position_y = player->GetPositionY();
4512 tele.position_z = player->GetPositionZ();
4513 tele.orientation = player->GetOrientation();
4514 tele.mapId = player->GetMapId();
4515 tele.name = name;
4517 if(objmgr.AddGameTele(tele))
4519 SendSysMessage(LANG_COMMAND_TP_ADDED);
4521 else
4523 SendSysMessage(LANG_COMMAND_TP_ADDEDERR);
4524 SetSentErrorMessage(true);
4525 return false;
4528 return true;
4531 bool ChatHandler::HandleTeleDelCommand(const char * args)
4533 if(!*args)
4534 return false;
4536 std::string name = args;
4538 if(!objmgr.DeleteGameTele(name))
4540 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
4541 SetSentErrorMessage(true);
4542 return false;
4545 SendSysMessage(LANG_COMMAND_TP_DELETED);
4546 return true;
4549 bool ChatHandler::HandleListAurasCommand (const char * /*args*/)
4551 Unit *unit = getSelectedUnit();
4552 if(!unit)
4554 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4555 SetSentErrorMessage(true);
4556 return false;
4559 char const* talentStr = GetMangosString(LANG_TALENT);
4560 char const* passiveStr = GetMangosString(LANG_PASSIVE);
4562 Unit::AuraMap const& uAuras = unit->GetAuras();
4563 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS, uAuras.size());
4564 for (Unit::AuraMap::const_iterator itr = uAuras.begin(); itr != uAuras.end(); ++itr)
4566 bool talent = GetTalentSpellCost(itr->second->GetId()) > 0;
4568 char const* name = itr->second->GetSpellProto()->SpellName[m_session->GetSessionDbcLocale()];
4570 if (m_session)
4572 std::ostringstream ss_name;
4573 ss_name << "|cffffffff|Hspell:" << itr->second->GetId() << "|h[" << name << "]|h|r";
4575 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL, itr->second->GetId(), itr->second->GetEffIndex(),
4576 itr->second->GetModifier()->m_auraname, itr->second->GetAuraDuration(), itr->second->GetAuraMaxDuration(),
4577 ss_name.str().c_str(),
4578 (itr->second->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4579 IS_PLAYER_GUID(itr->second->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr->second->GetCasterGUID()));
4581 else
4583 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL, itr->second->GetId(), itr->second->GetEffIndex(),
4584 itr->second->GetModifier()->m_auraname, itr->second->GetAuraDuration(), itr->second->GetAuraMaxDuration(),
4585 name,
4586 (itr->second->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4587 IS_PLAYER_GUID(itr->second->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr->second->GetCasterGUID()));
4590 for (int i = 0; i < TOTAL_AURAS; ++i)
4592 Unit::AuraList const& uAuraList = unit->GetAurasByType(AuraType(i));
4593 if (uAuraList.empty()) continue;
4594 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE, uAuraList.size(), i);
4595 for (Unit::AuraList::const_iterator itr = uAuraList.begin(); itr != uAuraList.end(); ++itr)
4597 bool talent = GetTalentSpellCost((*itr)->GetId()) > 0;
4599 char const* name = (*itr)->GetSpellProto()->SpellName[m_session->GetSessionDbcLocale()];
4601 if (m_session)
4603 std::ostringstream ss_name;
4604 ss_name << "|cffffffff|Hspell:" << (*itr)->GetId() << "|h[" << name << "]|h|r";
4606 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE, (*itr)->GetId(), (*itr)->GetEffIndex(),
4607 ss_name.str().c_str(),((*itr)->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4608 IS_PLAYER_GUID((*itr)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr)->GetCasterGUID()));
4610 else
4612 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE, (*itr)->GetId(), (*itr)->GetEffIndex(),
4613 name,((*itr)->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4614 IS_PLAYER_GUID((*itr)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr)->GetCasterGUID()));
4618 return true;
4621 bool ChatHandler::HandleResetAchievementsCommand (const char * args)
4623 char* pName = strtok((char*)args, "");
4624 Player *player = NULL;
4625 uint64 guid = 0;
4626 if (pName)
4628 std::string name = extractPlayerNameFromLink(pName);
4629 if(name.empty())
4631 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4632 SetSentErrorMessage(true);
4633 return false;
4636 guid = objmgr.GetPlayerGUIDByName(name);
4637 player = objmgr.GetPlayer(guid);
4639 else
4641 player = getSelectedPlayer();
4642 if(player)
4643 guid = player->GetGUID();
4646 if(!player && !guid)
4648 SendSysMessage(LANG_NO_CHAR_SELECTED);
4649 return true;
4652 if(player)
4653 player->GetAchievementMgr().Reset();
4654 else if(guid)
4655 AchievementMgr::DeleteFromDB(GUID_LOPART(guid));
4657 return true;
4660 bool ChatHandler::HandleResetHonorCommand (const char * args)
4662 char* pName = strtok((char*)args, "");
4663 Player *player = NULL;
4664 if (pName)
4666 std::string name = extractPlayerNameFromLink(pName);
4667 if(name.empty())
4669 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4670 SetSentErrorMessage(true);
4671 return false;
4674 uint64 guid = objmgr.GetPlayerGUIDByName(name);
4675 player = objmgr.GetPlayer(guid);
4677 else
4678 player = getSelectedPlayer();
4680 if(!player)
4682 SendSysMessage(LANG_NO_CHAR_SELECTED);
4683 return true;
4686 player->SetUInt32Value(PLAYER_FIELD_KILLS, 0);
4687 player->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS, 0);
4688 player->SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY, 0);
4689 player->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION, 0);
4690 player->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION, 0);
4692 player->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_EARN_HONORABLE_KILL);
4694 return true;
4697 static bool HandleResetStatsOrLevelHelper(Player* player)
4699 PlayerInfo const *info = objmgr.GetPlayerInfo(player->getRace(), player->getClass());
4700 if(!info) return false;
4702 ChrClassesEntry const* cEntry = sChrClassesStore.LookupEntry(player->getClass());
4703 if(!cEntry)
4705 sLog.outError("Class %u not found in DBC (Wrong DBC files?)",player->getClass());
4706 return false;
4709 uint8 powertype = cEntry->powerType;
4711 // reset m_form if no aura
4712 if(!player->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT))
4713 player->m_form = FORM_NONE;
4715 player->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, DEFAULT_WORLD_OBJECT_SIZE );
4716 player->SetFloatValue(UNIT_FIELD_COMBATREACH, 1.5f );
4718 player->setFactionForRace(player->getRace());
4720 player->SetUInt32Value(UNIT_FIELD_BYTES_0, ( ( player->getRace() ) | ( player->getClass() << 8 ) | ( player->getGender() << 16 ) | ( powertype << 24 ) ) );
4722 // reset only if player not in some form;
4723 if(player->m_form==FORM_NONE)
4725 switch(player->getGender())
4727 case GENDER_FEMALE:
4728 player->SetDisplayId(info->displayId_f);
4729 player->SetNativeDisplayId(info->displayId_f);
4730 break;
4731 case GENDER_MALE:
4732 player->SetDisplayId(info->displayId_m);
4733 player->SetNativeDisplayId(info->displayId_m);
4734 break;
4735 default:
4736 break;
4740 player->SetByteValue(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_PVP );
4741 player->SetByteValue(UNIT_FIELD_BYTES_2, 3, player->m_form);
4743 player->SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
4745 //-1 is default value
4746 player->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX, uint32(-1));
4748 //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000 );
4749 return true;
4752 bool ChatHandler::HandleResetLevelCommand(const char * args)
4754 char* pName = strtok((char*)args, "");
4755 Player *player = NULL;
4756 if (pName)
4758 std::string name = extractPlayerNameFromLink(pName);
4759 if(name.empty())
4761 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4762 SetSentErrorMessage(true);
4763 return false;
4766 uint64 guid = objmgr.GetPlayerGUIDByName(name);
4767 player = objmgr.GetPlayer(guid);
4769 else
4770 player = getSelectedPlayer();
4772 if(!player)
4774 SendSysMessage(LANG_NO_CHAR_SELECTED);
4775 SetSentErrorMessage(true);
4776 return false;
4779 if(!HandleResetStatsOrLevelHelper(player))
4780 return false;
4782 // set starting level
4783 uint32 start_level = player->getClass() != CLASS_DEATH_KNIGHT
4784 ? sWorld.getConfig(CONFIG_START_PLAYER_LEVEL)
4785 : sWorld.getConfig(CONFIG_START_HEROIC_PLAYER_LEVEL);
4787 player->SetLevel(start_level);
4788 player->InitRunes();
4789 player->InitStatsForLevel(true);
4790 player->InitTaxiNodesForLevel();
4791 player->InitGlyphsForLevel();
4792 player->InitTalentForLevel();
4793 player->SetUInt32Value(PLAYER_XP,0);
4795 // reset level to summoned pet
4796 Pet* pet = player->GetPet();
4797 if(pet && pet->getPetType()==SUMMON_PET)
4799 pet->InitStatsForLevel(1);
4800 pet->InitTalentForLevel();
4802 return true;
4805 bool ChatHandler::HandleResetStatsCommand(const char * args)
4807 char* pName = strtok((char*)args, "");
4808 Player *player = NULL;
4809 if (pName)
4811 std::string name = extractPlayerNameFromLink(pName);
4812 if(name.empty())
4814 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4815 SetSentErrorMessage(true);
4816 return false;
4819 uint64 guid = objmgr.GetPlayerGUIDByName(name);
4820 player = objmgr.GetPlayer(guid);
4822 else
4823 player = getSelectedPlayer();
4825 if(!player)
4827 SendSysMessage(LANG_NO_CHAR_SELECTED);
4828 SetSentErrorMessage(true);
4829 return false;
4832 if(!HandleResetStatsOrLevelHelper(player))
4833 return false;
4835 player->InitRunes();
4836 player->InitStatsForLevel(true);
4837 player->InitTaxiNodesForLevel();
4838 player->InitGlyphsForLevel();
4839 player->InitTalentForLevel();
4841 return true;
4844 bool ChatHandler::HandleResetSpellsCommand(const char * args)
4846 char* pName = strtok((char*)args, "");
4847 Player *player = NULL;
4848 uint64 playerGUID = 0;
4849 if (pName)
4851 std::string name = extractPlayerNameFromLink(pName);
4852 if(name.empty())
4854 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4855 SetSentErrorMessage(true);
4856 return false;
4859 player = objmgr.GetPlayer(name.c_str());
4860 if(!player)
4861 playerGUID = objmgr.GetPlayerGUIDByName(name);
4863 else
4864 player = getSelectedPlayer();
4866 if(!player && !playerGUID)
4868 SendSysMessage(LANG_NO_CHAR_SELECTED);
4869 SetSentErrorMessage(true);
4870 return false;
4873 if(player)
4875 player->resetSpells();
4877 ChatHandler(player).SendSysMessage(LANG_RESET_SPELLS);
4878 if(m_session->GetPlayer()!=player)
4879 PSendSysMessage(LANG_RESET_SPELLS_ONLINE,GetNameLink(player).c_str());
4881 else
4883 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS), GUID_LOPART(playerGUID));
4884 PSendSysMessage(LANG_RESET_SPELLS_OFFLINE,pName);
4887 return true;
4890 bool ChatHandler::HandleResetTalentsCommand(const char * args)
4892 char* pName = strtok((char*)args, "");
4893 Player *player = NULL;
4894 uint64 playerGUID = 0;
4895 if (pName)
4897 std::string name = extractPlayerNameFromLink(pName);
4898 if(name.empty())
4900 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4901 SetSentErrorMessage(true);
4902 return false;
4905 player = objmgr.GetPlayer(name.c_str());
4906 if(!player)
4907 playerGUID = objmgr.GetPlayerGUIDByName(name);
4909 else
4910 player = getSelectedPlayer();
4912 if(player)
4914 player->resetTalents(true);
4916 ChatHandler(player).SendSysMessage(LANG_RESET_TALENTS);
4917 if(m_session->GetPlayer()!=player)
4918 PSendSysMessage(LANG_RESET_TALENTS_ONLINE,GetNameLink(player).c_str());
4920 return true;
4922 else if (playerGUID)
4924 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_TALENTS), GUID_LOPART(playerGUID) );
4925 std::string nameLink = playerLink(pName);
4926 PSendSysMessage(LANG_RESET_TALENTS_OFFLINE,nameLink.c_str());
4927 return true;
4929 // Try reset talenents as Hunter Pet
4930 Creature* creature = getSelectedCreature();
4931 if (creature && creature->isPet() && ((Pet *)creature)->getPetType() == HUNTER_PET)
4933 ((Pet *)creature)->resetTalents(true);
4934 Unit *owner = creature->GetOwner();
4935 if (owner && owner->GetTypeId() == TYPEID_PLAYER)
4937 player = (Player *)owner;
4938 ChatHandler(player).SendSysMessage(LANG_RESET_PET_TALENTS);
4939 if(m_session->GetPlayer()!=player)
4940 PSendSysMessage(LANG_RESET_PET_TALENTS_ONLINE,GetNameLink(player).c_str());
4942 return true;
4945 SendSysMessage(LANG_NO_CHAR_SELECTED);
4946 SetSentErrorMessage(true);
4947 return false;
4950 bool ChatHandler::HandleResetAllCommand(const char * args)
4952 if(!*args)
4953 return false;
4955 std::string casename = args;
4957 AtLoginFlags atLogin;
4959 // Command specially created as single command to prevent using short case names
4960 if(casename=="spells")
4962 atLogin = AT_LOGIN_RESET_SPELLS;
4963 sWorld.SendWorldText(LANG_RESETALL_SPELLS);
4965 else if(casename=="talents")
4967 atLogin = AT_LOGIN_RESET_TALENTS;
4968 sWorld.SendWorldText(LANG_RESETALL_TALENTS);
4970 else
4972 PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE,args);
4973 SetSentErrorMessage(true);
4974 return false;
4977 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE (at_login & '%u') = '0'",atLogin,atLogin);
4978 HashMapHolder<Player>::MapType const& plist = ObjectAccessor::Instance().GetPlayers();
4979 for(HashMapHolder<Player>::MapType::const_iterator itr = plist.begin(); itr != plist.end(); ++itr)
4980 itr->second->SetAtLoginFlag(atLogin);
4982 return true;
4985 bool ChatHandler::HandleServerShutDownCancelCommand(const char* /*args*/)
4987 sWorld.ShutdownCancel();
4988 return true;
4991 bool ChatHandler::HandleServerShutDownCommand(const char* args)
4993 if(!*args)
4994 return false;
4996 char* time_str = strtok ((char*) args, " ");
4997 char* exitcode_str = strtok (NULL, "");
4999 int32 time = atoi (time_str);
5001 ///- Prevent interpret wrong arg value as 0 secs shutdown time
5002 if ((time == 0 && (time_str[0]!='0' || time_str[1]!='\0')) || time < 0)
5003 return false;
5005 if (exitcode_str)
5007 int32 exitcode = atoi (exitcode_str);
5009 // Handle atoi() errors
5010 if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
5011 return false;
5013 // Exit code should be in range of 0-125, 126-255 is used
5014 // in many shells for their own return codes and code > 255
5015 // is not supported in many others
5016 if (exitcode < 0 || exitcode > 125)
5017 return false;
5019 sWorld.ShutdownServ (time, 0, exitcode);
5021 else
5022 sWorld.ShutdownServ(time,0,SHUTDOWN_EXIT_CODE);
5023 return true;
5026 bool ChatHandler::HandleServerRestartCommand(const char* args)
5028 if(!*args)
5029 return false;
5031 char* time_str = strtok ((char*) args, " ");
5032 char* exitcode_str = strtok (NULL, "");
5034 int32 time = atoi (time_str);
5036 ///- Prevent interpret wrong arg value as 0 secs shutdown time
5037 if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0)
5038 return false;
5040 if (exitcode_str)
5042 int32 exitcode = atoi (exitcode_str);
5044 // Handle atoi() errors
5045 if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
5046 return false;
5048 // Exit code should be in range of 0-125, 126-255 is used
5049 // in many shells for their own return codes and code > 255
5050 // is not supported in many others
5051 if (exitcode < 0 || exitcode > 125)
5052 return false;
5054 sWorld.ShutdownServ (time, SHUTDOWN_MASK_RESTART, exitcode);
5056 else
5057 sWorld.ShutdownServ(time, SHUTDOWN_MASK_RESTART, RESTART_EXIT_CODE);
5058 return true;
5061 bool ChatHandler::HandleServerIdleRestartCommand(const char* args)
5063 if(!*args)
5064 return false;
5066 char* time_str = strtok ((char*) args, " ");
5067 char* exitcode_str = strtok (NULL, "");
5069 int32 time = atoi (time_str);
5071 ///- Prevent interpret wrong arg value as 0 secs shutdown time
5072 if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0)
5073 return false;
5075 if (exitcode_str)
5077 int32 exitcode = atoi (exitcode_str);
5079 // Handle atoi() errors
5080 if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
5081 return false;
5083 // Exit code should be in range of 0-125, 126-255 is used
5084 // in many shells for their own return codes and code > 255
5085 // is not supported in many others
5086 if (exitcode < 0 || exitcode > 125)
5087 return false;
5089 sWorld.ShutdownServ (time, SHUTDOWN_MASK_RESTART|SHUTDOWN_MASK_IDLE, exitcode);
5091 else
5092 sWorld.ShutdownServ(time,SHUTDOWN_MASK_RESTART|SHUTDOWN_MASK_IDLE,RESTART_EXIT_CODE);
5093 return true;
5096 bool ChatHandler::HandleServerIdleShutDownCommand(const char* args)
5098 if(!*args)
5099 return false;
5101 char* time_str = strtok ((char*) args, " ");
5102 char* exitcode_str = strtok (NULL, "");
5104 int32 time = atoi (time_str);
5106 ///- Prevent interpret wrong arg value as 0 secs shutdown time
5107 if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0)
5108 return false;
5110 if (exitcode_str)
5112 int32 exitcode = atoi (exitcode_str);
5114 // Handle atoi() errors
5115 if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
5116 return false;
5118 // Exit code should be in range of 0-125, 126-255 is used
5119 // in many shells for their own return codes and code > 255
5120 // is not supported in many others
5121 if (exitcode < 0 || exitcode > 125)
5122 return false;
5124 sWorld.ShutdownServ (time, SHUTDOWN_MASK_IDLE, exitcode);
5126 else
5127 sWorld.ShutdownServ(time,SHUTDOWN_MASK_IDLE,SHUTDOWN_EXIT_CODE);
5128 return true;
5131 bool ChatHandler::HandleQuestAdd(const char* args)
5133 Player* player = getSelectedPlayer();
5134 if(!player)
5136 SendSysMessage(LANG_NO_CHAR_SELECTED);
5137 SetSentErrorMessage(true);
5138 return false;
5141 // .addquest #entry'
5142 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
5143 char* cId = extractKeyFromLink((char*)args,"Hquest");
5144 if(!cId)
5145 return false;
5147 uint32 entry = atol(cId);
5149 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
5151 if(!pQuest)
5153 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND,entry);
5154 SetSentErrorMessage(true);
5155 return false;
5158 // check item starting quest (it can work incorrectly if added without item in inventory)
5159 for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
5161 ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype>(id);
5162 if (!pProto)
5163 continue;
5165 if (pProto->StartQuest == entry)
5167 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, entry, pProto->ItemId);
5168 SetSentErrorMessage(true);
5169 return false;
5173 // ok, normal (creature/GO starting) quest
5174 if( player->CanAddQuest( pQuest, true ) )
5176 player->AddQuest( pQuest, NULL );
5178 if ( player->CanCompleteQuest( entry ) )
5179 player->CompleteQuest( entry );
5182 return true;
5185 bool ChatHandler::HandleQuestRemove(const char* args)
5187 Player* player = getSelectedPlayer();
5188 if(!player)
5190 SendSysMessage(LANG_NO_CHAR_SELECTED);
5191 SetSentErrorMessage(true);
5192 return false;
5195 // .removequest #entry'
5196 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
5197 char* cId = extractKeyFromLink((char*)args,"Hquest");
5198 if(!cId)
5199 return false;
5201 uint32 entry = atol(cId);
5203 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
5205 if(!pQuest)
5207 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
5208 SetSentErrorMessage(true);
5209 return false;
5212 // remove all quest entries for 'entry' from quest log
5213 for(uint8 slot = 0; slot < MAX_QUEST_LOG_SIZE; ++slot )
5215 uint32 quest = player->GetQuestSlotQuestId(slot);
5216 if(quest==entry)
5218 player->SetQuestSlot(slot,0);
5220 // we ignore unequippable quest items in this case, its' still be equipped
5221 player->TakeQuestSourceItem( quest, false );
5225 // set quest status to not started (will updated in DB at next save)
5226 player->SetQuestStatus( entry, QUEST_STATUS_NONE);
5228 // reset rewarded for restart repeatable quest
5229 player->getQuestStatusMap()[entry].m_rewarded = false;
5231 SendSysMessage(LANG_COMMAND_QUEST_REMOVED);
5232 return true;
5235 bool ChatHandler::HandleQuestComplete(const char* args)
5237 Player* player = getSelectedPlayer();
5238 if(!player)
5240 SendSysMessage(LANG_NO_CHAR_SELECTED);
5241 SetSentErrorMessage(true);
5242 return false;
5245 // .quest complete #entry
5246 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
5247 char* cId = extractKeyFromLink((char*)args,"Hquest");
5248 if(!cId)
5249 return false;
5251 uint32 entry = atol(cId);
5253 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
5255 // If player doesn't have the quest
5256 if(!pQuest || player->GetQuestStatus(entry) == QUEST_STATUS_NONE)
5258 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
5259 SetSentErrorMessage(true);
5260 return false;
5263 // Add quest items for quests that require items
5264 for(uint8 x = 0; x < QUEST_OBJECTIVES_COUNT; ++x)
5266 uint32 id = pQuest->ReqItemId[x];
5267 uint32 count = pQuest->ReqItemCount[x];
5268 if(!id || !count)
5269 continue;
5271 uint32 curItemCount = player->GetItemCount(id,true);
5273 ItemPosCountVec dest;
5274 uint8 msg = player->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, id, count-curItemCount );
5275 if( msg == EQUIP_ERR_OK )
5277 Item* item = player->StoreNewItem( dest, id, true);
5278 player->SendNewItem(item,count-curItemCount,true,false);
5282 // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
5283 for(uint8 i = 0; i < QUEST_OBJECTIVES_COUNT; ++i)
5285 uint32 creature = pQuest->ReqCreatureOrGOId[i];
5286 uint32 creaturecount = pQuest->ReqCreatureOrGOCount[i];
5288 if(uint32 spell_id = pQuest->ReqSpell[i])
5290 for(uint16 z = 0; z < creaturecount; ++z)
5291 player->CastedCreatureOrGO(creature,0,spell_id);
5293 else if(creature > 0)
5295 for(uint16 z = 0; z < creaturecount; ++z)
5296 player->KilledMonster(creature,0);
5298 else if(creature < 0)
5300 for(uint16 z = 0; z < creaturecount; ++z)
5301 player->CastedCreatureOrGO(creature,0,0);
5305 // If the quest requires reputation to complete
5306 if(uint32 repFaction = pQuest->GetRepObjectiveFaction())
5308 uint32 repValue = pQuest->GetRepObjectiveValue();
5309 uint32 curRep = player->GetReputationMgr().GetReputation(repFaction);
5310 if(curRep < repValue)
5311 if(FactionEntry const *factionEntry = sFactionStore.LookupEntry(repFaction))
5312 player->GetReputationMgr().SetReputation(factionEntry,repValue);
5315 // If the quest requires money
5316 int32 ReqOrRewMoney = pQuest->GetRewOrReqMoney();
5317 if(ReqOrRewMoney < 0)
5318 player->ModifyMoney(-ReqOrRewMoney);
5320 player->CompleteQuest(entry);
5321 return true;
5324 bool ChatHandler::HandleBanAccountCommand(const char* args)
5326 return HandleBanHelper(BAN_ACCOUNT,args);
5329 bool ChatHandler::HandleBanCharacterCommand(const char* args)
5331 return HandleBanHelper(BAN_CHARACTER,args);
5334 bool ChatHandler::HandleBanIPCommand(const char* args)
5336 return HandleBanHelper(BAN_IP,args);
5339 bool ChatHandler::HandleBanHelper(BanMode mode, const char* args)
5341 if (!*args)
5342 return false;
5344 char* cnameOrIP = strtok ((char*)args, " ");
5345 if (!cnameOrIP)
5346 return false;
5348 std::string nameOrIP = cnameOrIP;
5350 char* duration = strtok (NULL," ");
5351 if(!duration || !atoi(duration))
5352 return false;
5354 char* reason = strtok (NULL,"");
5355 if(!reason)
5356 return false;
5358 switch(mode)
5360 case BAN_ACCOUNT:
5361 if(!AccountMgr::normilizeString(nameOrIP))
5363 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str());
5364 SetSentErrorMessage(true);
5365 return false;
5367 break;
5368 case BAN_CHARACTER:
5369 if(!normalizePlayerName(nameOrIP))
5371 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5372 SetSentErrorMessage(true);
5373 return false;
5375 break;
5376 case BAN_IP:
5377 if(!IsIPAddress(nameOrIP.c_str()))
5378 return false;
5379 break;
5382 switch(sWorld.BanAccount(mode, nameOrIP, duration, reason,m_session ? m_session->GetPlayerName() : ""))
5384 case BAN_SUCCESS:
5385 if(atoi(duration)>0)
5386 PSendSysMessage(LANG_BAN_YOUBANNED,nameOrIP.c_str(),secsToTimeString(TimeStringToSecs(duration),true).c_str(),reason);
5387 else
5388 PSendSysMessage(LANG_BAN_YOUPERMBANNED,nameOrIP.c_str(),reason);
5389 break;
5390 case BAN_SYNTAX_ERROR:
5391 return false;
5392 case BAN_NOTFOUND:
5393 switch(mode)
5395 default:
5396 PSendSysMessage(LANG_BAN_NOTFOUND,"account",nameOrIP.c_str());
5397 break;
5398 case BAN_CHARACTER:
5399 PSendSysMessage(LANG_BAN_NOTFOUND,"character",nameOrIP.c_str());
5400 break;
5401 case BAN_IP:
5402 PSendSysMessage(LANG_BAN_NOTFOUND,"ip",nameOrIP.c_str());
5403 break;
5405 SetSentErrorMessage(true);
5406 return false;
5409 return true;
5412 bool ChatHandler::HandleUnBanAccountCommand(const char* args)
5414 return HandleUnBanHelper(BAN_ACCOUNT,args);
5417 bool ChatHandler::HandleUnBanCharacterCommand(const char* args)
5419 return HandleUnBanHelper(BAN_CHARACTER,args);
5422 bool ChatHandler::HandleUnBanIPCommand(const char* args)
5424 return HandleUnBanHelper(BAN_IP,args);
5427 bool ChatHandler::HandleUnBanHelper(BanMode mode, const char* args)
5429 if (!*args)
5430 return false;
5432 char* cnameOrIP = strtok ((char*)args, " ");
5433 if(!cnameOrIP)
5434 return false;
5436 std::string nameOrIP = cnameOrIP;
5438 switch(mode)
5440 case BAN_ACCOUNT:
5441 if(!AccountMgr::normilizeString(nameOrIP))
5443 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str());
5444 SetSentErrorMessage(true);
5445 return false;
5447 break;
5448 case BAN_CHARACTER:
5449 if(!normalizePlayerName(nameOrIP))
5451 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5452 SetSentErrorMessage(true);
5453 return false;
5455 break;
5456 case BAN_IP:
5457 if(!IsIPAddress(nameOrIP.c_str()))
5458 return false;
5459 break;
5462 if(sWorld.RemoveBanAccount(mode,nameOrIP))
5463 PSendSysMessage(LANG_UNBAN_UNBANNED,nameOrIP.c_str());
5464 else
5465 PSendSysMessage(LANG_UNBAN_ERROR,nameOrIP.c_str());
5467 return true;
5470 bool ChatHandler::HandleBanInfoAccountCommand(const char* args)
5472 if (!*args)
5473 return false;
5475 char* cname = strtok((char*)args, "");
5476 if(!cname)
5477 return false;
5479 std::string account_name = cname;
5480 if(!AccountMgr::normilizeString(account_name))
5482 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5483 SetSentErrorMessage(true);
5484 return false;
5487 uint32 accountid = accmgr.GetId(account_name);
5488 if(!accountid)
5490 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5491 return true;
5494 return HandleBanInfoHelper(accountid,account_name.c_str());
5497 bool ChatHandler::HandleBanInfoCharacterCommand(const char* args)
5499 if (!*args)
5500 return false;
5502 std::string name = extractPlayerNameFromLink((char*)args);
5503 if(name.empty())
5505 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5506 SetSentErrorMessage(true);
5507 return false;
5510 uint32 accountid = objmgr.GetPlayerAccountIdByPlayerName(name);
5511 if(!accountid)
5513 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5514 SetSentErrorMessage(true);
5515 return false;
5518 std::string accountname;
5519 if(!accmgr.GetName(accountid,accountname))
5521 PSendSysMessage(LANG_BANINFO_NOCHARACTER);
5522 return true;
5525 return HandleBanInfoHelper(accountid,accountname.c_str());
5528 bool ChatHandler::HandleBanInfoHelper(uint32 accountid, char const* accountname)
5530 QueryResult *result = loginDatabase.PQuery("SELECT FROM_UNIXTIME(bandate), unbandate-bandate, active, unbandate,banreason,bannedby FROM account_banned WHERE id = '%u' ORDER BY bandate ASC",accountid);
5531 if(!result)
5533 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN, accountname);
5534 return true;
5537 PSendSysMessage(LANG_BANINFO_BANHISTORY,accountname);
5540 Field* fields = result->Fetch();
5542 time_t unbandate = time_t(fields[3].GetUInt64());
5543 bool active = false;
5544 if(fields[2].GetBool() && (fields[1].GetUInt64() == (uint64)0 ||unbandate >= time(NULL)) )
5545 active = true;
5546 bool permanent = (fields[1].GetUInt64() == (uint64)0);
5547 std::string bantime = permanent?GetMangosString(LANG_BANINFO_INFINITE):secsToTimeString(fields[1].GetUInt64(), true);
5548 PSendSysMessage(LANG_BANINFO_HISTORYENTRY,
5549 fields[0].GetString(), bantime.c_str(), active ? GetMangosString(LANG_BANINFO_YES):GetMangosString(LANG_BANINFO_NO), fields[4].GetString(), fields[5].GetString());
5550 }while (result->NextRow());
5552 delete result;
5553 return true;
5556 bool ChatHandler::HandleBanInfoIPCommand(const char* args)
5558 if (!*args)
5559 return false;
5561 char* cIP = strtok ((char*)args, "");
5562 if(!cIP)
5563 return false;
5565 if (!IsIPAddress(cIP))
5566 return false;
5568 std::string IP = cIP;
5570 loginDatabase.escape_string(IP);
5571 QueryResult *result = loginDatabase.PQuery("SELECT ip, FROM_UNIXTIME(bandate), FROM_UNIXTIME(unbandate), unbandate-UNIX_TIMESTAMP(), banreason,bannedby,unbandate-bandate FROM ip_banned WHERE ip = '%s'",IP.c_str());
5572 if(!result)
5574 PSendSysMessage(LANG_BANINFO_NOIP);
5575 return true;
5578 Field *fields = result->Fetch();
5579 bool permanent = !fields[6].GetUInt64();
5580 PSendSysMessage(LANG_BANINFO_IPENTRY,
5581 fields[0].GetString(), fields[1].GetString(), permanent ? GetMangosString(LANG_BANINFO_NEVER):fields[2].GetString(),
5582 permanent ? GetMangosString(LANG_BANINFO_INFINITE):secsToTimeString(fields[3].GetUInt64(), true).c_str(), fields[4].GetString(), fields[5].GetString());
5583 delete result;
5584 return true;
5587 bool ChatHandler::HandleBanListCharacterCommand(const char* args)
5589 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5591 char* cFilter = strtok ((char*)args, " ");
5592 if(!cFilter)
5593 return false;
5595 std::string filter = cFilter;
5596 loginDatabase.escape_string(filter);
5597 QueryResult* result = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'"),filter.c_str());
5598 if (!result)
5600 PSendSysMessage(LANG_BANLIST_NOCHARACTER);
5601 return true;
5604 return HandleBanListHelper(result);
5607 bool ChatHandler::HandleBanListAccountCommand(const char* args)
5609 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5611 char* cFilter = strtok((char*)args, " ");
5612 std::string filter = cFilter ? cFilter : "";
5613 loginDatabase.escape_string(filter);
5615 QueryResult* result;
5617 if(filter.empty())
5619 result = loginDatabase.Query("SELECT account.id, username FROM account, account_banned"
5620 " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
5622 else
5624 result = loginDatabase.PQuery("SELECT account.id, username FROM account, account_banned"
5625 " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
5626 filter.c_str());
5629 if (!result)
5631 PSendSysMessage(LANG_BANLIST_NOACCOUNT);
5632 return true;
5635 return HandleBanListHelper(result);
5638 bool ChatHandler::HandleBanListHelper(QueryResult* result)
5640 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT);
5642 // Chat short output
5643 if(m_session)
5647 Field* fields = result->Fetch();
5648 uint32 accountid = fields[0].GetUInt32();
5650 QueryResult* banresult = loginDatabase.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid);
5651 if(banresult)
5653 Field* fields2 = banresult->Fetch();
5654 PSendSysMessage("%s",fields2[0].GetString());
5655 delete banresult;
5657 } while (result->NextRow());
5659 // Console wide output
5660 else
5662 SendSysMessage(LANG_BANLIST_ACCOUNTS);
5663 SendSysMessage("===============================================================================");
5664 SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER);
5667 SendSysMessage("-------------------------------------------------------------------------------");
5668 Field *fields = result->Fetch();
5669 uint32 account_id = fields[0].GetUInt32 ();
5671 std::string account_name;
5673 // "account" case, name can be get in same query
5674 if(result->GetFieldCount() > 1)
5675 account_name = fields[1].GetCppString();
5676 // "character" case, name need extract from another DB
5677 else
5678 accmgr.GetName (account_id,account_name);
5680 // No SQL injection. id is uint32.
5681 QueryResult *banInfo = loginDatabase.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id);
5682 if (banInfo)
5684 Field *fields2 = banInfo->Fetch();
5687 time_t t_ban = fields2[0].GetUInt64();
5688 tm* aTm_ban = localtime(&t_ban);
5690 if (fields2[0].GetUInt64() == fields2[1].GetUInt64())
5692 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5693 account_name.c_str(),aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min,
5694 fields2[2].GetString(),fields2[3].GetString());
5696 else
5698 time_t t_unban = fields2[1].GetUInt64();
5699 tm* aTm_unban = localtime(&t_unban);
5700 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5701 account_name.c_str(),aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min,
5702 aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
5703 fields2[2].GetString(),fields2[3].GetString());
5705 }while ( banInfo->NextRow() );
5706 delete banInfo;
5708 }while( result->NextRow() );
5709 SendSysMessage("===============================================================================");
5712 delete result;
5713 return true;
5716 bool ChatHandler::HandleBanListIPCommand(const char* args)
5718 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5720 char* cFilter = strtok((char*)args, " ");
5721 std::string filter = cFilter ? cFilter : "";
5722 loginDatabase.escape_string(filter);
5724 QueryResult* result;
5726 if(filter.empty())
5728 result = loginDatabase.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5729 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
5730 " ORDER BY unbandate" );
5732 else
5734 result = loginDatabase.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5735 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")
5736 " ORDER BY unbandate",filter.c_str() );
5739 if(!result)
5741 PSendSysMessage(LANG_BANLIST_NOIP);
5742 return true;
5745 PSendSysMessage(LANG_BANLIST_MATCHINGIP);
5746 // Chat short output
5747 if(m_session)
5751 Field* fields = result->Fetch();
5752 PSendSysMessage("%s",fields[0].GetString());
5753 } while (result->NextRow());
5755 // Console wide output
5756 else
5758 SendSysMessage(LANG_BANLIST_IPS);
5759 SendSysMessage("===============================================================================");
5760 SendSysMessage(LANG_BANLIST_IPS_HEADER);
5763 SendSysMessage("-------------------------------------------------------------------------------");
5764 Field *fields = result->Fetch();
5765 time_t t_ban = fields[1].GetUInt64();
5766 tm* aTm_ban = localtime(&t_ban);
5767 if ( fields[1].GetUInt64() == fields[2].GetUInt64() )
5769 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5770 fields[0].GetString(), aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min,
5771 fields[3].GetString(), fields[4].GetString());
5773 else
5775 time_t t_unban = fields[2].GetUInt64();
5776 tm* aTm_unban = localtime(&t_unban);
5777 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5778 fields[0].GetString(), aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min,
5779 aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
5780 fields[3].GetString(), fields[4].GetString());
5782 }while( result->NextRow() );
5783 SendSysMessage("===============================================================================");
5786 delete result;
5787 return true;
5790 bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
5792 Player* pl = m_session->GetPlayer();
5794 // accept only explicitly selected target (not implicitly self targeting case)
5795 Unit* target = getSelectedUnit();
5796 if(pl->GetSelection() && target)
5798 if(target->GetTypeId()!=TYPEID_UNIT)
5800 SendSysMessage(LANG_SELECT_CREATURE);
5801 SetSentErrorMessage(true);
5802 return false;
5805 if(target->isDead())
5806 ((Creature*)target)->Respawn();
5807 return true;
5810 CellPair p(MaNGOS::ComputeCellPair(pl->GetPositionX(), pl->GetPositionY()));
5811 Cell cell(p);
5812 cell.data.Part.reserved = ALL_DISTRICT;
5813 cell.SetNoCreate();
5815 MaNGOS::RespawnDo u_do;
5816 MaNGOS::WorldObjectWorker<MaNGOS::RespawnDo> worker(pl,u_do);
5818 TypeContainerVisitor<MaNGOS::WorldObjectWorker<MaNGOS::RespawnDo>, GridTypeMapContainer > obj_worker(worker);
5819 CellLock<GridReadGuard> cell_lock(cell, p);
5820 cell_lock->Visit(cell_lock, obj_worker, *pl->GetMap());
5822 return true;
5825 bool ChatHandler::HandleGMFlyCommand(const char* args)
5827 if (!*args)
5828 return false;
5830 Player *target = getSelectedPlayer();
5831 if (!target)
5832 target = m_session->GetPlayer();
5834 WorldPacket data(12);
5835 if (strncmp(args, "on", 3) == 0)
5836 data.SetOpcode(SMSG_MOVE_SET_CAN_FLY);
5837 else if (strncmp(args, "off", 4) == 0)
5838 data.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY);
5839 else
5841 SendSysMessage(LANG_USE_BOL);
5842 return false;
5844 data.append(target->GetPackGUID());
5845 data << uint32(0); // unknown
5846 target->SendMessageToSet(&data, true);
5847 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS, GetNameLink(target).c_str(), args);
5848 return true;
5851 bool ChatHandler::HandlePDumpLoadCommand(const char *args)
5853 if (!*args)
5854 return false;
5856 char * file = strtok((char*)args, " ");
5857 if(!file)
5858 return false;
5860 char * account = strtok(NULL, " ");
5861 if(!account)
5862 return false;
5864 std::string account_name = account;
5865 if(!AccountMgr::normilizeString(account_name))
5867 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5868 SetSentErrorMessage(true);
5869 return false;
5872 uint32 account_id = accmgr.GetId(account_name);
5873 if(!account_id)
5875 account_id = atoi(account); // use original string
5876 if(!account_id)
5878 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5879 SetSentErrorMessage(true);
5880 return false;
5884 if(!accmgr.GetName(account_id,account_name))
5886 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5887 SetSentErrorMessage(true);
5888 return false;
5891 char* guid_str = NULL;
5892 char* name_str = strtok(NULL, " ");
5894 std::string name;
5895 if(name_str)
5897 name = name_str;
5898 // normalize the name if specified and check if it exists
5899 if(!normalizePlayerName(name))
5901 PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
5902 SetSentErrorMessage(true);
5903 return false;
5906 if(!ObjectMgr::IsValidName(name,true))
5908 PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
5909 SetSentErrorMessage(true);
5910 return false;
5913 guid_str = strtok(NULL, " ");
5916 uint32 guid = 0;
5918 if(guid_str)
5920 guid = atoi(guid_str);
5921 if(!guid)
5923 PSendSysMessage(LANG_INVALID_CHARACTER_GUID);
5924 SetSentErrorMessage(true);
5925 return false;
5928 if(objmgr.GetPlayerAccountIdByGUID(guid))
5930 PSendSysMessage(LANG_CHARACTER_GUID_IN_USE,guid);
5931 SetSentErrorMessage(true);
5932 return false;
5936 switch(PlayerDumpReader().LoadDump(file, account_id, name, guid))
5938 case DUMP_SUCCESS:
5939 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS);
5940 break;
5941 case DUMP_FILE_OPEN_ERROR:
5942 PSendSysMessage(LANG_FILE_OPEN_FAIL,file);
5943 SetSentErrorMessage(true);
5944 return false;
5945 case DUMP_FILE_BROKEN:
5946 PSendSysMessage(LANG_DUMP_BROKEN,file);
5947 SetSentErrorMessage(true);
5948 return false;
5949 case DUMP_TOO_MANY_CHARS:
5950 PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL,account_name.c_str(),account_id);
5951 SetSentErrorMessage(true);
5952 return false;
5953 default:
5954 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED);
5955 SetSentErrorMessage(true);
5956 return false;
5959 return true;
5962 bool ChatHandler::HandlePDumpWriteCommand(const char *args)
5964 if (!*args)
5965 return false;
5967 char* file = strtok((char*)args, " ");
5968 char* p2 = strtok(NULL, " ");
5970 if(!file || !p2)
5971 return false;
5973 uint32 guid;
5974 // character name can't start from number
5975 if (isNumeric(p2[0]))
5976 guid = atoi(p2);
5977 else
5979 std::string name = extractPlayerNameFromLink(p2);
5980 if(name.empty())
5982 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5983 SetSentErrorMessage(true);
5984 return false;
5987 guid = objmgr.GetPlayerGUIDByName(name);
5990 if(!objmgr.GetPlayerAccountIdByGUID(guid))
5992 PSendSysMessage(LANG_PLAYER_NOT_FOUND);
5993 SetSentErrorMessage(true);
5994 return false;
5997 switch(PlayerDumpWriter().WriteDump(file, guid))
5999 case DUMP_SUCCESS:
6000 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS);
6001 break;
6002 case DUMP_FILE_OPEN_ERROR:
6003 PSendSysMessage(LANG_FILE_OPEN_FAIL,file);
6004 SetSentErrorMessage(true);
6005 return false;
6006 default:
6007 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED);
6008 SetSentErrorMessage(true);
6009 return false;
6012 return true;
6015 bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
6017 Unit* unit = getSelectedUnit();
6018 if(!unit)
6020 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
6021 SetSentErrorMessage(true);
6022 return false;
6025 PSendSysMessage(LANG_MOVEGENS_LIST,(unit->GetTypeId()==TYPEID_PLAYER ? "Player" : "Creature" ),unit->GetGUIDLow());
6027 MotionMaster* mm = unit->GetMotionMaster();
6028 for(MotionMaster::const_iterator itr = mm->begin(); itr != mm->end(); ++itr)
6030 switch((*itr)->GetMovementGeneratorType())
6032 case IDLE_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_IDLE); break;
6033 case RANDOM_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_RANDOM); break;
6034 case WAYPOINT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_WAYPOINT); break;
6035 case ANIMAL_RANDOM_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_ANIMAL_RANDOM); break;
6036 case CONFUSED_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_CONFUSED); break;
6037 case TARGETED_MOTION_TYPE:
6039 if(unit->GetTypeId()==TYPEID_PLAYER)
6041 TargetedMovementGenerator<Player> const* mgen = static_cast<TargetedMovementGenerator<Player> const*>(*itr);
6042 Unit* target = mgen->GetTarget();
6043 if(target)
6044 PSendSysMessage(LANG_MOVEGENS_TARGETED_PLAYER,target->GetName(),target->GetGUIDLow());
6045 else
6046 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL);
6048 else
6050 TargetedMovementGenerator<Creature> const* mgen = static_cast<TargetedMovementGenerator<Creature> const*>(*itr);
6051 Unit* target = mgen->GetTarget();
6052 if(target)
6053 PSendSysMessage(LANG_MOVEGENS_TARGETED_CREATURE,target->GetName(),target->GetGUIDLow());
6054 else
6055 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL);
6057 break;
6059 case HOME_MOTION_TYPE:
6060 if(unit->GetTypeId()==TYPEID_UNIT)
6062 float x,y,z;
6063 (*itr)->GetDestination(x,y,z);
6064 PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE,x,y,z);
6066 else
6067 SendSysMessage(LANG_MOVEGENS_HOME_PLAYER);
6068 break;
6069 case FLIGHT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FLIGHT); break;
6070 case POINT_MOTION_TYPE:
6072 float x,y,z;
6073 (*itr)->GetDestination(x,y,z);
6074 PSendSysMessage(LANG_MOVEGENS_POINT,x,y,z);
6075 break;
6077 case FLEEING_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FEAR); break;
6078 case DISTRACT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_DISTRACT); break;
6079 default:
6080 PSendSysMessage(LANG_MOVEGENS_UNKNOWN,(*itr)->GetMovementGeneratorType());
6081 break;
6084 return true;
6087 bool ChatHandler::HandleServerPLimitCommand(const char *args)
6089 if(*args)
6091 char* param = strtok((char*)args, " ");
6092 if(!param)
6093 return false;
6095 int l = strlen(param);
6097 if( strncmp(param,"player",l) == 0 )
6098 sWorld.SetPlayerLimit(-SEC_PLAYER);
6099 else if(strncmp(param,"moderator",l) == 0 )
6100 sWorld.SetPlayerLimit(-SEC_MODERATOR);
6101 else if(strncmp(param,"gamemaster",l) == 0 )
6102 sWorld.SetPlayerLimit(-SEC_GAMEMASTER);
6103 else if(strncmp(param,"administrator",l) == 0 )
6104 sWorld.SetPlayerLimit(-SEC_ADMINISTRATOR);
6105 else if(strncmp(param,"reset",l) == 0 )
6106 sWorld.SetPlayerLimit( sConfig.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT) );
6107 else
6109 int val = atoi(param);
6110 if(val < -SEC_ADMINISTRATOR) val = -SEC_ADMINISTRATOR;
6112 sWorld.SetPlayerLimit(val);
6115 // kick all low security level players
6116 if(sWorld.GetPlayerAmountLimit() > SEC_PLAYER)
6117 sWorld.KickAllLess(sWorld.GetPlayerSecurityLimit());
6120 uint32 pLimit = sWorld.GetPlayerAmountLimit();
6121 AccountTypes allowedAccountType = sWorld.GetPlayerSecurityLimit();
6122 char const* secName = "";
6123 switch(allowedAccountType)
6125 case SEC_PLAYER: secName = "Player"; break;
6126 case SEC_MODERATOR: secName = "Moderator"; break;
6127 case SEC_GAMEMASTER: secName = "Gamemaster"; break;
6128 case SEC_ADMINISTRATOR: secName = "Administrator"; break;
6129 default: secName = "<unknown>"; break;
6132 PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit,secName);
6134 return true;
6137 bool ChatHandler::HandleCastCommand(const char* args)
6139 if(!*args)
6140 return false;
6142 Unit* target = getSelectedUnit();
6144 if(!target)
6146 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
6147 SetSentErrorMessage(true);
6148 return false;
6151 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6152 uint32 spell = extractSpellIdFromLink((char*)args);
6153 if(!spell)
6154 return false;
6156 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
6157 if(!spellInfo)
6158 return false;
6160 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
6162 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
6163 SetSentErrorMessage(true);
6164 return false;
6167 char* trig_str = strtok(NULL, " ");
6168 if(trig_str)
6170 int l = strlen(trig_str);
6171 if(strncmp(trig_str,"triggered",l) != 0 )
6172 return false;
6175 bool triggered = (trig_str != NULL);
6177 m_session->GetPlayer()->CastSpell(target,spell,triggered);
6179 return true;
6182 bool ChatHandler::HandleCastBackCommand(const char* args)
6184 Creature* caster = getSelectedCreature();
6186 if(!caster)
6188 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
6189 SetSentErrorMessage(true);
6190 return false;
6193 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
6194 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6195 uint32 spell = extractSpellIdFromLink((char*)args);
6196 if(!spell || !sSpellStore.LookupEntry(spell))
6197 return false;
6199 char* trig_str = strtok(NULL, " ");
6200 if(trig_str)
6202 int l = strlen(trig_str);
6203 if(strncmp(trig_str,"triggered",l) != 0 )
6204 return false;
6207 bool triggered = (trig_str != NULL);
6209 // update orientation at server
6210 caster->SetOrientation(caster->GetAngle(m_session->GetPlayer()));
6212 // and client
6213 WorldPacket data;
6214 caster->BuildHeartBeatMsg(&data);
6215 caster->SendMessageToSet(&data,true);
6217 caster->CastSpell(m_session->GetPlayer(),spell,triggered);
6219 return true;
6222 bool ChatHandler::HandleCastDistCommand(const char* args)
6224 if(!*args)
6225 return false;
6227 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6228 uint32 spell = extractSpellIdFromLink((char*)args);
6229 if(!spell)
6230 return false;
6232 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
6233 if(!spellInfo)
6234 return false;
6236 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
6238 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
6239 SetSentErrorMessage(true);
6240 return false;
6243 char *distStr = strtok(NULL, " ");
6245 float dist = 0;
6247 if(distStr)
6248 sscanf(distStr, "%f", &dist);
6250 char* trig_str = strtok(NULL, " ");
6251 if(trig_str)
6253 int l = strlen(trig_str);
6254 if(strncmp(trig_str,"triggered",l) != 0 )
6255 return false;
6258 bool triggered = (trig_str != NULL);
6260 float x,y,z;
6261 m_session->GetPlayer()->GetClosePoint(x,y,z,dist);
6263 m_session->GetPlayer()->CastSpell(x,y,z,spell,triggered);
6264 return true;
6267 bool ChatHandler::HandleCastTargetCommand(const char* args)
6269 Creature* caster = getSelectedCreature();
6271 if(!caster)
6273 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
6274 SetSentErrorMessage(true);
6275 return false;
6278 if(!caster->getVictim())
6280 SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM);
6281 SetSentErrorMessage(true);
6282 return false;
6285 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6286 uint32 spell = extractSpellIdFromLink((char*)args);
6287 if(!spell || !sSpellStore.LookupEntry(spell))
6288 return false;
6290 char* trig_str = strtok(NULL, " ");
6291 if(trig_str)
6293 int l = strlen(trig_str);
6294 if(strncmp(trig_str,"triggered",l) != 0 )
6295 return false;
6298 bool triggered = (trig_str != NULL);
6300 // update orientation at server
6301 caster->SetOrientation(caster->GetAngle(m_session->GetPlayer()));
6303 // and client
6304 WorldPacket data;
6305 caster->BuildHeartBeatMsg(&data);
6306 caster->SendMessageToSet(&data,true);
6308 caster->CastSpell(caster->getVictim(),spell,triggered);
6310 return true;
6314 ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
6315 Without this function 3rd party scripting library will get linking errors (unresolved external)
6316 when attempting to use the PointMovementGenerator
6318 bool ChatHandler::HandleComeToMeCommand(const char *args)
6320 Creature* caster = getSelectedCreature();
6322 if(!caster)
6324 SendSysMessage(LANG_SELECT_CREATURE);
6325 SetSentErrorMessage(true);
6326 return false;
6329 char* newFlagStr = strtok((char*)args, " ");
6331 if(!newFlagStr)
6332 return false;
6334 uint32 newFlags = atoi(newFlagStr);
6336 caster->SetUnitMovementFlags(newFlags);
6338 Player* pl = m_session->GetPlayer();
6340 caster->GetMotionMaster()->MovePoint(0, pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ());
6341 return true;
6344 bool ChatHandler::HandleCastSelfCommand(const char* args)
6346 if(!*args)
6347 return false;
6349 Unit* target = getSelectedUnit();
6351 if(!target)
6353 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
6354 SetSentErrorMessage(true);
6355 return false;
6358 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6359 uint32 spell = extractSpellIdFromLink((char*)args);
6360 if(!spell)
6361 return false;
6363 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
6364 if(!spellInfo)
6365 return false;
6367 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
6369 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
6370 SetSentErrorMessage(true);
6371 return false;
6374 target->CastSpell(target,spell,false);
6376 return true;
6379 std::string GetTimeString(uint32 time)
6381 uint16 days = time / DAY, hours = (time % DAY) / HOUR, minute = (time % HOUR) / MINUTE;
6382 std::ostringstream ss;
6383 if(days) ss << days << "d ";
6384 if(hours) ss << hours << "h ";
6385 ss << minute << "m";
6386 return ss.str();
6389 bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
6391 Player* player = getSelectedPlayer();
6392 if (!player) player = m_session->GetPlayer();
6393 uint32 counter = 0;
6394 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; ++i)
6396 Player::BoundInstancesMap &binds = player->GetBoundInstances(i);
6397 for(Player::BoundInstancesMap::const_iterator itr = binds.begin(); itr != binds.end(); ++itr)
6399 InstanceSave *save = itr->second.save;
6400 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
6401 PSendSysMessage("map: %d inst: %d perm: %s diff: %s canReset: %s TTR: %s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty() == DIFFICULTY_NORMAL ? "normal" : "heroic", save->CanReset() ? "yes" : "no", timeleft.c_str());
6402 counter++;
6405 PSendSysMessage("player binds: %d", counter);
6406 counter = 0;
6407 Group *group = player->GetGroup();
6408 if(group)
6410 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; ++i)
6412 Group::BoundInstancesMap &binds = group->GetBoundInstances(i);
6413 for(Group::BoundInstancesMap::const_iterator itr = binds.begin(); itr != binds.end(); ++itr)
6415 InstanceSave *save = itr->second.save;
6416 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
6417 PSendSysMessage("map: %d inst: %d perm: %s diff: %s canReset: %s TTR: %s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty() == DIFFICULTY_NORMAL ? "normal" : "heroic", save->CanReset() ? "yes" : "no", timeleft.c_str());
6418 counter++;
6422 PSendSysMessage("group binds: %d", counter);
6424 return true;
6427 bool ChatHandler::HandleInstanceUnbindCommand(const char* args)
6429 if(!*args)
6430 return false;
6432 std::string cmd = args;
6433 if(cmd == "all")
6435 Player* player = getSelectedPlayer();
6436 if (!player) player = m_session->GetPlayer();
6437 uint32 counter = 0;
6438 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; ++i)
6440 Player::BoundInstancesMap &binds = player->GetBoundInstances(i);
6441 for(Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end();)
6443 if(itr->first != player->GetMapId())
6445 InstanceSave *save = itr->second.save;
6446 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
6447 PSendSysMessage("unbinding map: %d inst: %d perm: %s diff: %s canReset: %s TTR: %s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty() == DIFFICULTY_NORMAL ? "normal" : "heroic", save->CanReset() ? "yes" : "no", timeleft.c_str());
6448 player->UnbindInstance(itr, i);
6449 counter++;
6451 else
6452 ++itr;
6455 PSendSysMessage("instances unbound: %d", counter);
6457 return true;
6460 bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
6462 PSendSysMessage("instances loaded: %d", MapManager::Instance().GetNumInstances());
6463 PSendSysMessage("players in instances: %d", MapManager::Instance().GetNumPlayersInInstances());
6464 PSendSysMessage("instance saves: %d", sInstanceSaveManager.GetNumInstanceSaves());
6465 PSendSysMessage("players bound: %d", sInstanceSaveManager.GetNumBoundPlayersTotal());
6466 PSendSysMessage("groups bound: %d", sInstanceSaveManager.GetNumBoundGroupsTotal());
6467 return true;
6470 bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
6472 Player* pl = m_session->GetPlayer();
6474 Map* map = pl->GetMap();
6475 if (!map->IsDungeon())
6477 PSendSysMessage("Map is not a dungeon.");
6478 SetSentErrorMessage(true);
6479 return false;
6482 if (!((InstanceMap*)map)->GetInstanceData())
6484 PSendSysMessage("Map has no instance data.");
6485 SetSentErrorMessage(true);
6486 return false;
6489 ((InstanceMap*)map)->GetInstanceData()->SaveToDB();
6490 return true;
6493 /// Display the list of GMs
6494 bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
6496 ///- Get the accounts with GM Level >0
6497 QueryResult *result = loginDatabase.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
6498 if(result)
6500 SendSysMessage(LANG_GMLIST);
6501 SendSysMessage("========================");
6502 SendSysMessage(LANG_GMLIST_HEADER);
6503 SendSysMessage("========================");
6505 ///- Circle through them. Display username and GM level
6508 Field *fields = result->Fetch();
6509 PSendSysMessage("|%15s|%6s|", fields[0].GetString(),fields[1].GetString());
6510 }while( result->NextRow() );
6512 PSendSysMessage("========================");
6513 delete result;
6515 else
6516 PSendSysMessage(LANG_GMLIST_EMPTY);
6517 return true;
6520 /// Define the 'Message of the day' for the realm
6521 bool ChatHandler::HandleServerSetMotdCommand(const char* args)
6523 sWorld.SetMotd(args);
6524 PSendSysMessage(LANG_MOTD_NEW, args);
6525 return true;
6528 /// Set/Unset the expansion level for an account
6529 bool ChatHandler::HandleAccountSetAddonCommand(const char* args)
6531 ///- Get the command line arguments
6532 char *szAcc = strtok((char*)args," ");
6533 char *szExp = strtok(NULL," ");
6535 if(!szAcc)
6536 return false;
6538 std::string account_name;
6539 uint32 account_id;
6541 if(!szExp)
6543 Player* player = getSelectedPlayer();
6544 if(!player)
6545 return false;
6547 account_id = player->GetSession()->GetAccountId();
6548 accmgr.GetName(account_id,account_name);
6549 szExp = szAcc;
6551 else
6553 ///- Convert Account name to Upper Format
6554 account_name = szAcc;
6555 if(!AccountMgr::normilizeString(account_name))
6557 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
6558 SetSentErrorMessage(true);
6559 return false;
6562 account_id = accmgr.GetId(account_name);
6563 if(!account_id)
6565 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
6566 SetSentErrorMessage(true);
6567 return false;
6572 // Let set addon state only for lesser (strong) security level
6573 // or to self account
6574 if (m_session && m_session->GetAccountId () != account_id &&
6575 HasLowerSecurityAccount (NULL,account_id,true))
6576 return false;
6578 int lev=atoi(szExp); //get int anyway (0 if error)
6579 if(lev < 0)
6580 return false;
6582 // No SQL injection
6583 loginDatabase.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev,account_id);
6584 PSendSysMessage(LANG_ACCOUNT_SETADDON,account_name.c_str(),account_id,lev);
6585 return true;
6588 //Send items by mail
6589 bool ChatHandler::HandleSendItemsCommand(const char* args)
6591 if(!*args)
6592 return false;
6594 // format: name "subject text" "mail text" item1[:count1] item2[:count2] ... item12[:count12]
6596 std::string name = extractPlayerNameFromLink((char*)args);
6597 if(name.empty())
6599 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6600 SetSentErrorMessage(true);
6601 return false;
6604 char* tail1 = strtok(NULL, "");
6605 if(!tail1)
6606 return false;
6608 char* msgSubject;
6609 if(*tail1=='"')
6610 msgSubject = strtok(tail1+1, "\"");
6611 else
6613 char* space = strtok(tail1, "\"");
6614 if(!space)
6615 return false;
6616 msgSubject = strtok(NULL, "\"");
6619 if (!msgSubject)
6620 return false;
6622 char* tail2 = strtok(NULL, "");
6623 if(!tail2)
6624 return false;
6626 char* msgText;
6627 if(*tail2=='"')
6628 msgText = strtok(tail2+1, "\"");
6629 else
6631 char* space = strtok(tail2, "\"");
6632 if(!space)
6633 return false;
6634 msgText = strtok(NULL, "\"");
6637 if (!msgText)
6638 return false;
6640 // msgSubject, msgText isn't NUL after prev. check
6641 std::string subject = msgSubject;
6642 std::string text = msgText;
6644 // extract items
6645 typedef std::pair<uint32,uint32> ItemPair;
6646 typedef std::list< ItemPair > ItemPairs;
6647 ItemPairs items;
6649 // get all tail string
6650 char* tail = strtok(NULL, "");
6652 // get from tail next item str
6653 while(char* itemStr = strtok(tail, " "))
6655 // and get new tail
6656 tail = strtok(NULL, "");
6658 // parse item str
6659 char* itemIdStr = strtok(itemStr, ":");
6660 char* itemCountStr = strtok(NULL, " ");
6662 uint32 item_id = atoi(itemIdStr);
6663 if(!item_id)
6664 return false;
6666 ItemPrototype const* item_proto = objmgr.GetItemPrototype(item_id);
6667 if(!item_proto)
6669 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
6670 SetSentErrorMessage(true);
6671 return false;
6674 uint32 item_count = itemCountStr ? atoi(itemCountStr) : 1;
6675 if(item_count < 1 || item_proto->MaxCount > 0 && item_count > uint32(item_proto->MaxCount))
6677 PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT, item_count,item_id);
6678 SetSentErrorMessage(true);
6679 return false;
6682 while(item_count > item_proto->GetMaxStackSize())
6684 items.push_back(ItemPair(item_id,item_proto->GetMaxStackSize()));
6685 item_count -= item_proto->GetMaxStackSize();
6688 items.push_back(ItemPair(item_id,item_count));
6690 if(items.size() > MAX_MAIL_ITEMS)
6692 PSendSysMessage(LANG_COMMAND_MAIL_ITEMS_LIMIT, MAX_MAIL_ITEMS);
6693 SetSentErrorMessage(true);
6694 return false;
6698 uint64 receiver_guid = objmgr.GetPlayerGUIDByName(name);
6699 if(!receiver_guid)
6701 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6702 SetSentErrorMessage(true);
6703 return false;
6706 // from console show not existed sender
6707 uint32 sender_guidlo = m_session ? m_session->GetPlayer()->GetGUIDLow() : 0;
6709 uint32 messagetype = MAIL_NORMAL;
6710 uint32 stationery = MAIL_STATIONERY_GM;
6711 uint32 itemTextId = !text.empty() ? objmgr.CreateItemText( text ) : 0;
6713 Player *receiver = objmgr.GetPlayer(receiver_guid);
6715 // fill mail
6716 MailItemsInfo mi; // item list preparing
6718 for(ItemPairs::const_iterator itr = items.begin(); itr != items.end(); ++itr)
6720 if(Item* item = Item::CreateItem(itr->first,itr->second,m_session ? m_session->GetPlayer() : 0))
6722 item->SaveToDB(); // save for prevent lost at next mail load, if send fail then item will deleted
6723 mi.AddItem(item->GetGUIDLow(), item->GetEntry(), item);
6727 WorldSession::SendMailTo(receiver,messagetype, stationery, sender_guidlo, GUID_LOPART(receiver_guid), subject, itemTextId, &mi, 0, 0, MAIL_CHECK_MASK_NONE);
6729 std::string nameLink = playerLink(name);
6730 PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
6731 return true;
6734 ///Send money by mail
6735 bool ChatHandler::HandleSendMoneyCommand(const char* args)
6737 if (!*args)
6738 return false;
6740 /// format: name "subject text" "mail text" money
6742 std::string name = extractPlayerNameFromLink((char*)args);
6743 if(name.empty())
6745 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6746 SetSentErrorMessage(true);
6747 return false;
6750 char* tail1 = strtok(NULL, "");
6751 if (!tail1)
6752 return false;
6754 char* msgSubject;
6755 if (*tail1=='"')
6756 msgSubject = strtok(tail1+1, "\"");
6757 else
6759 char* space = strtok(tail1, "\"");
6760 if (!space)
6761 return false;
6762 msgSubject = strtok(NULL, "\"");
6765 if (!msgSubject)
6766 return false;
6768 char* tail2 = strtok(NULL, "");
6769 if (!tail2)
6770 return false;
6772 char* msgText;
6773 if (*tail2=='"')
6774 msgText = strtok(tail2+1, "\"");
6775 else
6777 char* space = strtok(tail2, "\"");
6778 if (!space)
6779 return false;
6780 msgText = strtok(NULL, "\"");
6783 if (!msgText)
6784 return false;
6786 char* money_str = strtok(NULL, "");
6787 int32 money = money_str ? atoi(money_str) : 0;
6788 if (money <= 0)
6789 return false;
6791 // msgSubject, msgText isn't NUL after prev. check
6792 std::string subject = msgSubject;
6793 std::string text = msgText;
6795 uint64 receiver_guid = objmgr.GetPlayerGUIDByName(name);
6796 if (!receiver_guid)
6798 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6799 SetSentErrorMessage(true);
6800 return false;
6803 // from console show not existed sender
6804 uint32 sender_guidlo = m_session ? m_session->GetPlayer()->GetGUIDLow() : 0;
6806 uint32 messagetype = MAIL_NORMAL;
6807 uint32 stationery = MAIL_STATIONERY_GM;
6808 uint32 itemTextId = !text.empty() ? objmgr.CreateItemText( text ) : 0;
6810 Player *receiver = objmgr.GetPlayer(receiver_guid);
6812 WorldSession::SendMailTo(receiver,messagetype, stationery, sender_guidlo, GUID_LOPART(receiver_guid), subject, itemTextId, NULL, money, 0, MAIL_CHECK_MASK_NONE);
6814 std::string nameLink = playerLink(name);
6815 PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
6816 return true;
6819 /// Send a message to a player in game
6820 bool ChatHandler::HandleSendMessageCommand(const char* args)
6822 ///- Get the command line arguments
6823 std::string name = extractPlayerNameFromLink((char*)args);
6824 if(name.empty())
6826 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6827 SetSentErrorMessage(true);
6828 return false;
6831 char* msg_str = strtok(NULL, "");
6832 if(!msg_str)
6833 return false;
6835 ///- Find the player and check that he is not logging out.
6836 Player *rPlayer = objmgr.GetPlayer(name.c_str());
6837 if(!rPlayer)
6839 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6840 SetSentErrorMessage(true);
6841 return false;
6844 if(rPlayer->GetSession()->isLogingOut())
6846 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6847 SetSentErrorMessage(true);
6848 return false;
6851 ///- Send the message
6852 //Use SendAreaTriggerMessage for fastest delivery.
6853 rPlayer->GetSession()->SendAreaTriggerMessage("%s", msg_str);
6854 rPlayer->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
6856 //Confirmation message
6857 std::string nameLink = playerLink(name);
6858 PSendSysMessage(LANG_SENDMESSAGE,nameLink.c_str(),msg_str);
6859 return true;
6862 bool ChatHandler::HandleFlushArenaPointsCommand(const char * /*args*/)
6864 sBattleGroundMgr.DistributeArenaPoints();
6865 return true;
6868 bool ChatHandler::HandleModifyGenderCommand(const char *args)
6870 if(!*args)
6871 return false;
6873 Player *player = getSelectedPlayer();
6875 if(!player)
6877 PSendSysMessage(LANG_PLAYER_NOT_FOUND);
6878 SetSentErrorMessage(true);
6879 return false;
6882 PlayerInfo const* info = objmgr.GetPlayerInfo(player->getRace(), player->getClass());
6883 if(!info)
6884 return false;
6886 char const* gender_str = (char*)args;
6887 int gender_len = strlen(gender_str);
6889 Gender gender;
6891 if(!strncmp(gender_str, "male", gender_len)) // MALE
6893 if(player->getGender() == GENDER_MALE)
6894 return true;
6896 gender = GENDER_MALE;
6898 else if (!strncmp(gender_str, "female", gender_len)) // FEMALE
6900 if(player->getGender() == GENDER_FEMALE)
6901 return true;
6903 gender = GENDER_FEMALE;
6905 else
6907 SendSysMessage(LANG_MUST_MALE_OR_FEMALE);
6908 SetSentErrorMessage(true);
6909 return false;
6912 // Set gender
6913 player->SetByteValue(UNIT_FIELD_BYTES_0, 2, gender);
6914 player->SetByteValue(PLAYER_BYTES_3, 0, gender);
6916 // Change display ID
6917 player->SetDisplayId(gender ? info->displayId_f : info->displayId_m);
6918 player->SetNativeDisplayId(gender ? info->displayId_f : info->displayId_m);
6920 char const* gender_full = gender ? "female" : "male";
6922 PSendSysMessage(LANG_YOU_CHANGE_GENDER, GetNameLink(player).c_str(), gender_full);
6924 if (needReportToTarget(player))
6925 ChatHandler(player).PSendSysMessage(LANG_YOUR_GENDER_CHANGED, gender_full, GetNameLink().c_str());
6927 return true;