[7838] More fixes in pet's levelup spells.
[getmangos.git] / src / game / Level3.cpp
blob9a147e5a5a6ece0862e6a186e32019f089e21e28
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 target->RemoveSpellCooldown(spell_id,true);
1068 PSendSysMessage(LANG_REMOVE_COOLDOWN, spell_id, target==m_session->GetPlayer() ? GetMangosString(LANG_YOU) : tNameLink.c_str());
1070 return true;
1073 bool ChatHandler::HandleLearnAllCommand(const char* /*args*/)
1075 static const char *allSpellList[] =
1077 "3365",
1078 "6233",
1079 "6247",
1080 "6246",
1081 "6477",
1082 "6478",
1083 "22810",
1084 "8386",
1085 "21651",
1086 "21652",
1087 "522",
1088 "7266",
1089 "8597",
1090 "2479",
1091 "22027",
1092 "6603",
1093 "5019",
1094 "133",
1095 "168",
1096 "227",
1097 "5009",
1098 "9078",
1099 "668",
1100 "203",
1101 "20599",
1102 "20600",
1103 "81",
1104 "20597",
1105 "20598",
1106 "20864",
1107 "1459",
1108 "5504",
1109 "587",
1110 "5143",
1111 "118",
1112 "5505",
1113 "597",
1114 "604",
1115 "1449",
1116 "1460",
1117 "2855",
1118 "1008",
1119 "475",
1120 "5506",
1121 "1463",
1122 "12824",
1123 "8437",
1124 "990",
1125 "5145",
1126 "8450",
1127 "1461",
1128 "759",
1129 "8494",
1130 "8455",
1131 "8438",
1132 "6127",
1133 "8416",
1134 "6129",
1135 "8451",
1136 "8495",
1137 "8439",
1138 "3552",
1139 "8417",
1140 "10138",
1141 "12825",
1142 "10169",
1143 "10156",
1144 "10144",
1145 "10191",
1146 "10201",
1147 "10211",
1148 "10053",
1149 "10173",
1150 "10139",
1151 "10145",
1152 "10192",
1153 "10170",
1154 "10202",
1155 "10054",
1156 "10174",
1157 "10193",
1158 "12826",
1159 "2136",
1160 "143",
1161 "145",
1162 "2137",
1163 "2120",
1164 "3140",
1165 "543",
1166 "2138",
1167 "2948",
1168 "8400",
1169 "2121",
1170 "8444",
1171 "8412",
1172 "8457",
1173 "8401",
1174 "8422",
1175 "8445",
1176 "8402",
1177 "8413",
1178 "8458",
1179 "8423",
1180 "8446",
1181 "10148",
1182 "10197",
1183 "10205",
1184 "10149",
1185 "10215",
1186 "10223",
1187 "10206",
1188 "10199",
1189 "10150",
1190 "10216",
1191 "10207",
1192 "10225",
1193 "10151",
1194 "116",
1195 "205",
1196 "7300",
1197 "122",
1198 "837",
1199 "10",
1200 "7301",
1201 "7322",
1202 "6143",
1203 "120",
1204 "865",
1205 "8406",
1206 "6141",
1207 "7302",
1208 "8461",
1209 "8407",
1210 "8492",
1211 "8427",
1212 "8408",
1213 "6131",
1214 "7320",
1215 "10159",
1216 "8462",
1217 "10185",
1218 "10179",
1219 "10160",
1220 "10180",
1221 "10219",
1222 "10186",
1223 "10177",
1224 "10230",
1225 "10181",
1226 "10161",
1227 "10187",
1228 "10220",
1229 "2018",
1230 "2663",
1231 "12260",
1232 "2660",
1233 "3115",
1234 "3326",
1235 "2665",
1236 "3116",
1237 "2738",
1238 "3293",
1239 "2661",
1240 "3319",
1241 "2662",
1242 "9983",
1243 "8880",
1244 "2737",
1245 "2739",
1246 "7408",
1247 "3320",
1248 "2666",
1249 "3323",
1250 "3324",
1251 "3294",
1252 "22723",
1253 "23219",
1254 "23220",
1255 "23221",
1256 "23228",
1257 "23338",
1258 "10788",
1259 "10790",
1260 "5611",
1261 "5016",
1262 "5609",
1263 "2060",
1264 "10963",
1265 "10964",
1266 "10965",
1267 "22593",
1268 "22594",
1269 "596",
1270 "996",
1271 "499",
1272 "768",
1273 "17002",
1274 "1448",
1275 "1082",
1276 "16979",
1277 "1079",
1278 "5215",
1279 "20484",
1280 "5221",
1281 "15590",
1282 "17007",
1283 "6795",
1284 "6807",
1285 "5487",
1286 "1446",
1287 "1066",
1288 "5421",
1289 "3139",
1290 "779",
1291 "6811",
1292 "6808",
1293 "1445",
1294 "5216",
1295 "1737",
1296 "5222",
1297 "5217",
1298 "1432",
1299 "6812",
1300 "9492",
1301 "5210",
1302 "3030",
1303 "1441",
1304 "783",
1305 "6801",
1306 "20739",
1307 "8944",
1308 "9491",
1309 "22569",
1310 "5226",
1311 "6786",
1312 "1433",
1313 "8973",
1314 "1828",
1315 "9495",
1316 "9006",
1317 "6794",
1318 "8993",
1319 "5203",
1320 "16914",
1321 "6784",
1322 "9635",
1323 "22830",
1324 "20722",
1325 "9748",
1326 "6790",
1327 "9753",
1328 "9493",
1329 "9752",
1330 "9831",
1331 "9825",
1332 "9822",
1333 "5204",
1334 "5401",
1335 "22831",
1336 "6793",
1337 "9845",
1338 "17401",
1339 "9882",
1340 "9868",
1341 "20749",
1342 "9893",
1343 "9899",
1344 "9895",
1345 "9832",
1346 "9902",
1347 "9909",
1348 "22832",
1349 "9828",
1350 "9851",
1351 "9883",
1352 "9869",
1353 "17406",
1354 "17402",
1355 "9914",
1356 "20750",
1357 "9897",
1358 "9848",
1359 "3127",
1360 "107",
1361 "204",
1362 "9116",
1363 "2457",
1364 "78",
1365 "18848",
1366 "331",
1367 "403",
1368 "2098",
1369 "1752",
1370 "11278",
1371 "11288",
1372 "11284",
1373 "6461",
1374 "2344",
1375 "2345",
1376 "6463",
1377 "2346",
1378 "2352",
1379 "775",
1380 "1434",
1381 "1612",
1382 "71",
1383 "2468",
1384 "2458",
1385 "2467",
1386 "7164",
1387 "7178",
1388 "7367",
1389 "7376",
1390 "7381",
1391 "21156",
1392 "5209",
1393 "3029",
1394 "5201",
1395 "9849",
1396 "9850",
1397 "20719",
1398 "22568",
1399 "22827",
1400 "22828",
1401 "22829",
1402 "6809",
1403 "8972",
1404 "9005",
1405 "9823",
1406 "9827",
1407 "6783",
1408 "9913",
1409 "6785",
1410 "6787",
1411 "9866",
1412 "9867",
1413 "9894",
1414 "9896",
1415 "6800",
1416 "8992",
1417 "9829",
1418 "9830",
1419 "780",
1420 "769",
1421 "6749",
1422 "6750",
1423 "9755",
1424 "9754",
1425 "9908",
1426 "20745",
1427 "20742",
1428 "20747",
1429 "20748",
1430 "9746",
1431 "9745",
1432 "9880",
1433 "9881",
1434 "5391",
1435 "842",
1436 "3025",
1437 "3031",
1438 "3287",
1439 "3329",
1440 "1945",
1441 "3559",
1442 "4933",
1443 "4934",
1444 "4935",
1445 "4936",
1446 "5142",
1447 "5390",
1448 "5392",
1449 "5404",
1450 "5420",
1451 "6405",
1452 "7293",
1453 "7965",
1454 "8041",
1455 "8153",
1456 "9033",
1457 "9034",
1458 //"9036", problems with ghost state
1459 "16421",
1460 "21653",
1461 "22660",
1462 "5225",
1463 "9846",
1464 "2426",
1465 "5916",
1466 "6634",
1467 //"6718", phasing stealth, annoying for learn all case.
1468 "6719",
1469 "8822",
1470 "9591",
1471 "9590",
1472 "10032",
1473 "17746",
1474 "17747",
1475 "8203",
1476 "11392",
1477 "12495",
1478 "16380",
1479 "23452",
1480 "4079",
1481 "4996",
1482 "4997",
1483 "4998",
1484 "4999",
1485 "5000",
1486 "6348",
1487 "6349",
1488 "6481",
1489 "6482",
1490 "6483",
1491 "6484",
1492 "11362",
1493 "11410",
1494 "11409",
1495 "12510",
1496 "12509",
1497 "12885",
1498 "13142",
1499 "21463",
1500 "23460",
1501 "11421",
1502 "11416",
1503 "11418",
1504 "1851",
1505 "10059",
1506 "11423",
1507 "11417",
1508 "11422",
1509 "11419",
1510 "11424",
1511 "11420",
1512 "27",
1513 "31",
1514 "33",
1515 "34",
1516 "35",
1517 "15125",
1518 "21127",
1519 "22950",
1520 "1180",
1521 "201",
1522 "12593",
1523 "12842",
1524 "16770",
1525 "6057",
1526 "12051",
1527 "18468",
1528 "12606",
1529 "12605",
1530 "18466",
1531 "12502",
1532 "12043",
1533 "15060",
1534 "12042",
1535 "12341",
1536 "12848",
1537 "12344",
1538 "12353",
1539 "18460",
1540 "11366",
1541 "12350",
1542 "12352",
1543 "13043",
1544 "11368",
1545 "11113",
1546 "12400",
1547 "11129",
1548 "16766",
1549 "12573",
1550 "15053",
1551 "12580",
1552 "12475",
1553 "12472",
1554 "12953",
1555 "12488",
1556 "11189",
1557 "12985",
1558 "12519",
1559 "16758",
1560 "11958",
1561 "12490",
1562 "11426",
1563 "3565",
1564 "3562",
1565 "18960",
1566 "3567",
1567 "3561",
1568 "3566",
1569 "3563",
1570 "1953",
1571 "2139",
1572 "12505",
1573 "13018",
1574 "12522",
1575 "12523",
1576 "5146",
1577 "5144",
1578 "5148",
1579 "8419",
1580 "8418",
1581 "10213",
1582 "10212",
1583 "10157",
1584 "12524",
1585 "13019",
1586 "12525",
1587 "13020",
1588 "12526",
1589 "13021",
1590 "18809",
1591 "13031",
1592 "13032",
1593 "13033",
1594 "4036",
1595 "3920",
1596 "3919",
1597 "3918",
1598 "7430",
1599 "3922",
1600 "3923",
1601 "7411",
1602 "7418",
1603 "7421",
1604 "13262",
1605 "7412",
1606 "7415",
1607 "7413",
1608 "7416",
1609 "13920",
1610 "13921",
1611 "7745",
1612 "7779",
1613 "7428",
1614 "7457",
1615 "7857",
1616 "7748",
1617 "7426",
1618 "13421",
1619 "7454",
1620 "13378",
1621 "7788",
1622 "14807",
1623 "14293",
1624 "7795",
1625 "6296",
1626 "20608",
1627 "755",
1628 "444",
1629 "427",
1630 "428",
1631 "442",
1632 "447",
1633 "3578",
1634 "3581",
1635 "19027",
1636 "3580",
1637 "665",
1638 "3579",
1639 "3577",
1640 "6755",
1641 "3576",
1642 "2575",
1643 "2577",
1644 "2578",
1645 "2579",
1646 "2580",
1647 "2656",
1648 "2657",
1649 "2576",
1650 "3564",
1651 "10248",
1652 "8388",
1653 "2659",
1654 "14891",
1655 "3308",
1656 "3307",
1657 "10097",
1658 "2658",
1659 "3569",
1660 "16153",
1661 "3304",
1662 "10098",
1663 "4037",
1664 "3929",
1665 "3931",
1666 "3926",
1667 "3924",
1668 "3930",
1669 "3977",
1670 "3925",
1671 "136",
1672 "228",
1673 "5487",
1674 "43",
1675 "202",
1679 int loop = 0;
1680 while(strcmp(allSpellList[loop], "0"))
1682 uint32 spell = atol((char*)allSpellList[loop++]);
1684 if (m_session->GetPlayer()->HasSpell(spell))
1685 continue;
1687 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
1688 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
1690 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
1691 continue;
1694 m_session->GetPlayer()->learnSpell(spell,false);
1697 SendSysMessage(LANG_COMMAND_LEARN_MANY_SPELLS);
1699 return true;
1702 bool ChatHandler::HandleLearnAllGMCommand(const char* /*args*/)
1704 static const char *gmSpellList[] =
1706 "24347", // Become A Fish, No Breath Bar
1707 "35132", // Visual Boom
1708 "38488", // Attack 4000-8000 AOE
1709 "38795", // Attack 2000 AOE + Slow Down 90%
1710 "15712", // Attack 200
1711 "1852", // GM Spell Silence
1712 "31899", // Kill
1713 "31924", // Kill
1714 "29878", // Kill My Self
1715 "26644", // More Kill
1717 "28550", //Invisible 24
1718 "23452", //Invisible + Target
1722 uint16 gmSpellIter = 0;
1723 while( strcmp(gmSpellList[gmSpellIter], "0") )
1725 uint32 spell = atol((char*)gmSpellList[gmSpellIter++]);
1727 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
1728 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
1730 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
1731 continue;
1734 m_session->GetPlayer()->learnSpell(spell,false);
1737 SendSysMessage(LANG_LEARNING_GM_SKILLS);
1738 return true;
1741 bool ChatHandler::HandleLearnAllMyClassCommand(const char* /*args*/)
1743 HandleLearnAllMySpellsCommand("");
1744 HandleLearnAllMyTalentsCommand("");
1745 return true;
1748 bool ChatHandler::HandleLearnAllMySpellsCommand(const char* /*args*/)
1750 ChrClassesEntry const* clsEntry = sChrClassesStore.LookupEntry(m_session->GetPlayer()->getClass());
1751 if(!clsEntry)
1752 return true;
1753 uint32 family = clsEntry->spellfamily;
1755 for (uint32 i = 0; i < sSpellStore.GetNumRows(); ++i)
1757 SpellEntry const *spellInfo = sSpellStore.LookupEntry(i);
1758 if(!spellInfo)
1759 continue;
1761 // skip server-side/triggered spells
1762 if(spellInfo->spellLevel==0)
1763 continue;
1765 // skip wrong class/race skills
1766 if(!m_session->GetPlayer()->IsSpellFitByClassAndRace(spellInfo->Id))
1767 continue;
1769 // skip other spell families
1770 if( spellInfo->SpellFamilyName != family)
1771 continue;
1773 // skip spells with first rank learned as talent (and all talents then also)
1774 uint32 first_rank = spellmgr.GetFirstSpellInChain(spellInfo->Id);
1775 if(GetTalentSpellCost(first_rank) > 0 )
1776 continue;
1778 // skip broken spells
1779 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
1780 continue;
1782 m_session->GetPlayer()->learnSpell(i,false);
1785 SendSysMessage(LANG_COMMAND_LEARN_CLASS_SPELLS);
1786 return true;
1789 bool ChatHandler::HandleLearnAllMyTalentsCommand(const char* /*args*/)
1791 Player* player = m_session->GetPlayer();
1792 uint32 classMask = player->getClassMask();
1794 for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i)
1796 TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
1797 if(!talentInfo)
1798 continue;
1800 TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentInfo->TalentTab );
1801 if(!talentTabInfo)
1802 continue;
1804 if( (classMask & talentTabInfo->ClassMask) == 0 )
1805 continue;
1807 // search highest talent rank
1808 uint32 spellid = 0;
1810 for(int rank = MAX_TALENT_RANK-1; rank >= 0; --rank)
1812 if(talentInfo->RankID[rank]!=0)
1814 spellid = talentInfo->RankID[rank];
1815 break;
1819 if(!spellid) // ??? none spells in talent
1820 continue;
1822 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellid);
1823 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
1824 continue;
1826 // learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
1827 player->learnSpellHighRank(spellid);
1830 SendSysMessage(LANG_COMMAND_LEARN_CLASS_TALENTS);
1831 return true;
1834 bool ChatHandler::HandleLearnAllMyPetTalentsCommand(const char* /*args*/)
1836 Player* player = m_session->GetPlayer();
1838 Pet* pet = player->GetPet();
1839 if(!pet)
1841 SendSysMessage(LANG_NO_PET_FOUND);
1842 SetSentErrorMessage(true);
1843 return false;
1846 CreatureInfo const *ci = pet->GetCreatureInfo();
1847 if(!ci)
1849 SendSysMessage(LANG_WRONG_PET_TYPE);
1850 SetSentErrorMessage(true);
1851 return false;
1854 CreatureFamilyEntry const *pet_family = sCreatureFamilyStore.LookupEntry(ci->family);
1855 if(!pet_family)
1857 SendSysMessage(LANG_WRONG_PET_TYPE);
1858 SetSentErrorMessage(true);
1859 return false;
1862 if(pet_family->petTalentType < 0) // not hunter pet
1864 SendSysMessage(LANG_WRONG_PET_TYPE);
1865 SetSentErrorMessage(true);
1866 return false;
1869 for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i)
1871 TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
1872 if(!talentInfo)
1873 continue;
1875 TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentInfo->TalentTab );
1876 if(!talentTabInfo)
1877 continue;
1879 // prevent learn talent for different family (cheating)
1880 if(((1 << pet_family->petTalentType) & talentTabInfo->petTalentMask)==0)
1881 continue;
1883 // search highest talent rank
1884 uint32 spellid = 0;
1886 for(int rank = MAX_TALENT_RANK-1; rank >= 0; --rank)
1888 if(talentInfo->RankID[rank]!=0)
1890 spellid = talentInfo->RankID[rank];
1891 break;
1895 if(!spellid) // ??? none spells in talent
1896 continue;
1898 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellid);
1899 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
1900 continue;
1902 // learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
1903 pet->learnSpellHighRank(spellid);
1906 SendSysMessage(LANG_COMMAND_LEARN_PET_TALENTS);
1907 return true;
1910 bool ChatHandler::HandleLearnAllLangCommand(const char* /*args*/)
1912 // skipping UNIVERSAL language (0)
1913 for(int i = 1; i < LANGUAGES_COUNT; ++i)
1914 m_session->GetPlayer()->learnSpell(lang_description[i].spell_id,false);
1916 SendSysMessage(LANG_COMMAND_LEARN_ALL_LANG);
1917 return true;
1920 bool ChatHandler::HandleLearnAllDefaultCommand(const char* args)
1922 Player *player = NULL;
1923 if (*args)
1925 std::string name = extractPlayerNameFromLink((char*)args);
1926 if(name.empty())
1928 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1929 SetSentErrorMessage(true);
1930 return false;
1933 player = objmgr.GetPlayer(name.c_str());
1935 else
1936 player = getSelectedPlayer();
1938 if(!player)
1940 SendSysMessage(LANG_NO_CHAR_SELECTED);
1941 SetSentErrorMessage(true);
1942 return false;
1945 player->learnDefaultSpells();
1946 player->learnQuestRewardedSpells();
1948 PSendSysMessage(LANG_COMMAND_LEARN_ALL_DEFAULT_AND_QUEST,GetNameLink(player).c_str());
1949 return true;
1952 bool ChatHandler::HandleLearnCommand(const char* args)
1954 Player* targetPlayer = getSelectedPlayer();
1956 if(!targetPlayer)
1958 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1959 SetSentErrorMessage(true);
1960 return false;
1963 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1964 uint32 spell = extractSpellIdFromLink((char*)args);
1965 if(!spell || !sSpellStore.LookupEntry(spell))
1966 return false;
1968 char const* allStr = strtok(NULL," ");
1969 bool allRanks = allStr ? (strncmp(allStr, "all", strlen(allStr)) == 0) : false;
1971 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
1972 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
1974 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
1975 SetSentErrorMessage(true);
1976 return false;
1979 if (!allRanks && targetPlayer->HasSpell(spell))
1981 if(targetPlayer == m_session->GetPlayer())
1982 SendSysMessage(LANG_YOU_KNOWN_SPELL);
1983 else
1984 PSendSysMessage(LANG_TARGET_KNOWN_SPELL,GetNameLink(targetPlayer).c_str());
1985 SetSentErrorMessage(true);
1986 return false;
1989 if(allRanks)
1990 targetPlayer->learnSpellHighRank(spell);
1991 else
1992 targetPlayer->learnSpell(spell,false);
1994 return true;
1997 bool ChatHandler::HandleAddItemCommand(const char* args)
1999 if (!*args)
2000 return false;
2002 uint32 itemId = 0;
2004 if(args[0]=='[') // [name] manual form
2006 char* citemName = strtok((char*)args, "]");
2008 if(citemName && citemName[0])
2010 std::string itemName = citemName+1;
2011 WorldDatabase.escape_string(itemName);
2012 QueryResult *result = WorldDatabase.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName.c_str());
2013 if (!result)
2015 PSendSysMessage(LANG_COMMAND_COULDNOTFIND, citemName+1);
2016 SetSentErrorMessage(true);
2017 return false;
2019 itemId = result->Fetch()->GetUInt16();
2020 delete result;
2022 else
2023 return false;
2025 else // item_id or [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r
2027 char* cId = extractKeyFromLink((char*)args,"Hitem");
2028 if(!cId)
2029 return false;
2030 itemId = atol(cId);
2033 char* ccount = strtok(NULL, " ");
2035 int32 count = 1;
2037 if (ccount)
2038 count = strtol(ccount, NULL, 10);
2040 if (count == 0)
2041 count = 1;
2043 Player* pl = m_session->GetPlayer();
2044 Player* plTarget = getSelectedPlayer();
2045 if(!plTarget)
2046 plTarget = pl;
2048 sLog.outDetail(GetMangosString(LANG_ADDITEM), itemId, count);
2050 ItemPrototype const *pProto = objmgr.GetItemPrototype(itemId);
2051 if(!pProto)
2053 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, itemId);
2054 SetSentErrorMessage(true);
2055 return false;
2058 //Subtract
2059 if (count < 0)
2061 plTarget->DestroyItemCount(itemId, -count, true, false);
2062 PSendSysMessage(LANG_REMOVEITEM, itemId, -count, GetNameLink(plTarget).c_str());
2063 return true;
2066 //Adding items
2067 uint32 noSpaceForCount = 0;
2069 // check space and find places
2070 ItemPosCountVec dest;
2071 uint8 msg = plTarget->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, itemId, count, &noSpaceForCount );
2072 if( msg != EQUIP_ERR_OK ) // convert to possible store amount
2073 count -= noSpaceForCount;
2075 if( count == 0 || dest.empty()) // can't add any
2077 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount );
2078 SetSentErrorMessage(true);
2079 return false;
2082 Item* item = plTarget->StoreNewItem( dest, itemId, true, Item::GenerateItemRandomPropertyId(itemId));
2084 // remove binding (let GM give it to another player later)
2085 if(pl==plTarget)
2086 for(ItemPosCountVec::const_iterator itr = dest.begin(); itr != dest.end(); ++itr)
2087 if(Item* item1 = pl->GetItemByPos(itr->pos))
2088 item1->SetBinding( false );
2090 if(count > 0 && item)
2092 pl->SendNewItem(item,count,false,true);
2093 if(pl!=plTarget)
2094 plTarget->SendNewItem(item,count,true,false);
2097 if(noSpaceForCount > 0)
2098 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount);
2100 return true;
2103 bool ChatHandler::HandleAddItemSetCommand(const char* args)
2105 if (!*args)
2106 return false;
2108 char* cId = extractKeyFromLink((char*)args,"Hitemset"); // number or [name] Shift-click form |color|Hitemset:itemset_id|h[name]|h|r
2109 if (!cId)
2110 return false;
2112 uint32 itemsetId = atol(cId);
2114 // prevent generation all items with itemset field value '0'
2115 if (itemsetId == 0)
2117 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND,itemsetId);
2118 SetSentErrorMessage(true);
2119 return false;
2122 Player* pl = m_session->GetPlayer();
2123 Player* plTarget = getSelectedPlayer();
2124 if(!plTarget)
2125 plTarget = pl;
2127 sLog.outDetail(GetMangosString(LANG_ADDITEMSET), itemsetId);
2129 bool found = false;
2130 for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
2132 ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype>(id);
2133 if (!pProto)
2134 continue;
2136 if (pProto->ItemSet == itemsetId)
2138 found = true;
2139 ItemPosCountVec dest;
2140 uint8 msg = plTarget->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, pProto->ItemId, 1 );
2141 if (msg == EQUIP_ERR_OK)
2143 Item* item = plTarget->StoreNewItem( dest, pProto->ItemId, true);
2145 // remove binding (let GM give it to another player later)
2146 if (pl==plTarget)
2147 item->SetBinding( false );
2149 pl->SendNewItem(item,1,false,true);
2150 if (pl!=plTarget)
2151 plTarget->SendNewItem(item,1,true,false);
2153 else
2155 pl->SendEquipError( msg, NULL, NULL );
2156 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, pProto->ItemId, 1);
2161 if (!found)
2163 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND,itemsetId);
2165 SetSentErrorMessage(true);
2166 return false;
2169 return true;
2172 bool ChatHandler::HandleListItemCommand(const char* args)
2174 if(!*args)
2175 return false;
2177 char* cId = extractKeyFromLink((char*)args,"Hitem");
2178 if(!cId)
2179 return false;
2181 uint32 item_id = atol(cId);
2182 if(!item_id)
2184 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
2185 SetSentErrorMessage(true);
2186 return false;
2189 ItemPrototype const* itemProto = objmgr.GetItemPrototype(item_id);
2190 if(!itemProto)
2192 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
2193 SetSentErrorMessage(true);
2194 return false;
2197 char* c_count = strtok(NULL, " ");
2198 int count = c_count ? atol(c_count) : 10;
2200 if(count < 0)
2201 return false;
2203 QueryResult *result;
2205 // inventory case
2206 uint32 inv_count = 0;
2207 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM character_inventory WHERE item_template='%u'",item_id);
2208 if(result)
2210 inv_count = (*result)[0].GetUInt32();
2211 delete result;
2214 result=CharacterDatabase.PQuery(
2215 // 0 1 2 3 4 5
2216 "SELECT ci.item, cibag.slot AS bag, ci.slot, ci.guid, characters.account,characters.name "
2217 "FROM character_inventory AS ci LEFT JOIN character_inventory AS cibag ON (cibag.item=ci.bag),characters "
2218 "WHERE ci.item_template='%u' AND ci.guid = characters.guid LIMIT %u ",
2219 item_id,uint32(count));
2221 if(result)
2225 Field *fields = result->Fetch();
2226 uint32 item_guid = fields[0].GetUInt32();
2227 uint32 item_bag = fields[1].GetUInt32();
2228 uint32 item_slot = fields[2].GetUInt32();
2229 uint32 owner_guid = fields[3].GetUInt32();
2230 uint32 owner_acc = fields[4].GetUInt32();
2231 std::string owner_name = fields[5].GetCppString();
2233 char const* item_pos = 0;
2234 if(Player::IsEquipmentPos(item_bag,item_slot))
2235 item_pos = "[equipped]";
2236 else if(Player::IsInventoryPos(item_bag,item_slot))
2237 item_pos = "[in inventory]";
2238 else if(Player::IsBankPos(item_bag,item_slot))
2239 item_pos = "[in bank]";
2240 else
2241 item_pos = "";
2243 PSendSysMessage(LANG_ITEMLIST_SLOT,
2244 item_guid,owner_name.c_str(),owner_guid,owner_acc,item_pos);
2245 } while (result->NextRow());
2247 int64 res_count = result->GetRowCount();
2249 delete result;
2251 if(count > res_count)
2252 count-=res_count;
2253 else if(count)
2254 count = 0;
2257 // mail case
2258 uint32 mail_count = 0;
2259 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM mail_items WHERE item_template='%u'", item_id);
2260 if(result)
2262 mail_count = (*result)[0].GetUInt32();
2263 delete result;
2266 if(count > 0)
2268 result=CharacterDatabase.PQuery(
2269 // 0 1 2 3 4 5 6
2270 "SELECT mail_items.item_guid, mail.sender, mail.receiver, char_s.account, char_s.name, char_r.account, char_r.name "
2271 "FROM mail,mail_items,characters as char_s,characters as char_r "
2272 "WHERE mail_items.item_template='%u' AND char_s.guid = mail.sender AND char_r.guid = mail.receiver AND mail.id=mail_items.mail_id LIMIT %u",
2273 item_id,uint32(count));
2275 else
2276 result = NULL;
2278 if(result)
2282 Field *fields = result->Fetch();
2283 uint32 item_guid = fields[0].GetUInt32();
2284 uint32 item_s = fields[1].GetUInt32();
2285 uint32 item_r = fields[2].GetUInt32();
2286 uint32 item_s_acc = fields[3].GetUInt32();
2287 std::string item_s_name = fields[4].GetCppString();
2288 uint32 item_r_acc = fields[5].GetUInt32();
2289 std::string item_r_name = fields[6].GetCppString();
2291 char const* item_pos = "[in mail]";
2293 PSendSysMessage(LANG_ITEMLIST_MAIL,
2294 item_guid,item_s_name.c_str(),item_s,item_s_acc,item_r_name.c_str(),item_r,item_r_acc,item_pos);
2295 } while (result->NextRow());
2297 int64 res_count = result->GetRowCount();
2299 delete result;
2301 if(count > res_count)
2302 count-=res_count;
2303 else if(count)
2304 count = 0;
2307 // auction case
2308 uint32 auc_count = 0;
2309 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM auctionhouse WHERE item_template='%u'",item_id);
2310 if(result)
2312 auc_count = (*result)[0].GetUInt32();
2313 delete result;
2316 if(count > 0)
2318 result=CharacterDatabase.PQuery(
2319 // 0 1 2 3
2320 "SELECT auctionhouse.itemguid, auctionhouse.itemowner, characters.account, characters.name "
2321 "FROM auctionhouse,characters WHERE auctionhouse.item_template='%u' AND characters.guid = auctionhouse.itemowner LIMIT %u",
2322 item_id,uint32(count));
2324 else
2325 result = NULL;
2327 if(result)
2331 Field *fields = result->Fetch();
2332 uint32 item_guid = fields[0].GetUInt32();
2333 uint32 owner = fields[1].GetUInt32();
2334 uint32 owner_acc = fields[2].GetUInt32();
2335 std::string owner_name = fields[3].GetCppString();
2337 char const* item_pos = "[in auction]";
2339 PSendSysMessage(LANG_ITEMLIST_AUCTION, item_guid, owner_name.c_str(), owner, owner_acc,item_pos);
2340 } while (result->NextRow());
2342 delete result;
2345 // guild bank case
2346 uint32 guild_count = 0;
2347 result=CharacterDatabase.PQuery("SELECT COUNT(item_entry) FROM guild_bank_item WHERE item_entry='%u'",item_id);
2348 if(result)
2350 guild_count = (*result)[0].GetUInt32();
2351 delete result;
2354 result=CharacterDatabase.PQuery(
2355 // 0 1 2
2356 "SELECT gi.item_guid, gi.guildid, guild.name "
2357 "FROM guild_bank_item AS gi, guild WHERE gi.item_entry='%u' AND gi.guildid = guild.guildid LIMIT %u ",
2358 item_id,uint32(count));
2360 if(result)
2364 Field *fields = result->Fetch();
2365 uint32 item_guid = fields[0].GetUInt32();
2366 uint32 guild_guid = fields[1].GetUInt32();
2367 std::string guild_name = fields[2].GetCppString();
2369 char const* item_pos = "[in guild bank]";
2371 PSendSysMessage(LANG_ITEMLIST_GUILD,item_guid,guild_name.c_str(),guild_guid,item_pos);
2372 } while (result->NextRow());
2374 int64 res_count = result->GetRowCount();
2376 delete result;
2378 if(count > res_count)
2379 count-=res_count;
2380 else if(count)
2381 count = 0;
2384 if(inv_count+mail_count+auc_count+guild_count == 0)
2386 SendSysMessage(LANG_COMMAND_NOITEMFOUND);
2387 SetSentErrorMessage(true);
2388 return false;
2391 PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE,item_id,inv_count+mail_count+auc_count+guild_count,inv_count,mail_count,auc_count,guild_count);
2393 return true;
2396 bool ChatHandler::HandleListObjectCommand(const char* args)
2398 if(!*args)
2399 return false;
2401 // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2402 char* cId = extractKeyFromLink((char*)args,"Hgameobject_entry");
2403 if(!cId)
2404 return false;
2406 uint32 go_id = atol(cId);
2407 if(!go_id)
2409 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, go_id);
2410 SetSentErrorMessage(true);
2411 return false;
2414 GameObjectInfo const * gInfo = objmgr.GetGameObjectInfo(go_id);
2415 if(!gInfo)
2417 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, go_id);
2418 SetSentErrorMessage(true);
2419 return false;
2422 char* c_count = strtok(NULL, " ");
2423 int count = c_count ? atol(c_count) : 10;
2425 if(count < 0)
2426 return false;
2428 QueryResult *result;
2430 uint32 obj_count = 0;
2431 result=WorldDatabase.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'",go_id);
2432 if(result)
2434 obj_count = (*result)[0].GetUInt32();
2435 delete result;
2438 if(m_session)
2440 Player* pl = m_session->GetPlayer();
2441 result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map, (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ FROM gameobject WHERE id = '%u' ORDER BY order_ ASC LIMIT %u",
2442 pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(),go_id,uint32(count));
2444 else
2445 result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map FROM gameobject WHERE id = '%u' LIMIT %u",
2446 go_id,uint32(count));
2448 if (result)
2452 Field *fields = result->Fetch();
2453 uint32 guid = fields[0].GetUInt32();
2454 float x = fields[1].GetFloat();
2455 float y = fields[2].GetFloat();
2456 float z = fields[3].GetFloat();
2457 int mapid = fields[4].GetUInt16();
2459 if (m_session)
2460 PSendSysMessage(LANG_GO_LIST_CHAT, guid, guid, gInfo->name, x, y, z, mapid);
2461 else
2462 PSendSysMessage(LANG_GO_LIST_CONSOLE, guid, gInfo->name, x, y, z, mapid);
2463 } while (result->NextRow());
2465 delete result;
2468 PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE,go_id,obj_count);
2469 return true;
2472 bool ChatHandler::HandleListCreatureCommand(const char* args)
2474 if(!*args)
2475 return false;
2477 // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
2478 char* cId = extractKeyFromLink((char*)args,"Hcreature_entry");
2479 if(!cId)
2480 return false;
2482 uint32 cr_id = atol(cId);
2483 if(!cr_id)
2485 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, cr_id);
2486 SetSentErrorMessage(true);
2487 return false;
2490 CreatureInfo const* cInfo = objmgr.GetCreatureTemplate(cr_id);
2491 if(!cInfo)
2493 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, cr_id);
2494 SetSentErrorMessage(true);
2495 return false;
2498 char* c_count = strtok(NULL, " ");
2499 int count = c_count ? atol(c_count) : 10;
2501 if(count < 0)
2502 return false;
2504 QueryResult *result;
2506 uint32 cr_count = 0;
2507 result=WorldDatabase.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'",cr_id);
2508 if(result)
2510 cr_count = (*result)[0].GetUInt32();
2511 delete result;
2514 if(m_session)
2516 Player* pl = m_session->GetPlayer();
2517 result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map, (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ FROM creature WHERE id = '%u' ORDER BY order_ ASC LIMIT %u",
2518 pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(), cr_id,uint32(count));
2520 else
2521 result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '%u' LIMIT %u",
2522 cr_id,uint32(count));
2524 if (result)
2528 Field *fields = result->Fetch();
2529 uint32 guid = fields[0].GetUInt32();
2530 float x = fields[1].GetFloat();
2531 float y = fields[2].GetFloat();
2532 float z = fields[3].GetFloat();
2533 int mapid = fields[4].GetUInt16();
2535 if (m_session)
2536 PSendSysMessage(LANG_CREATURE_LIST_CHAT, guid, guid, cInfo->Name, x, y, z, mapid);
2537 else
2538 PSendSysMessage(LANG_CREATURE_LIST_CONSOLE, guid, cInfo->Name, x, y, z, mapid);
2539 } while (result->NextRow());
2541 delete result;
2544 PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE,cr_id,cr_count);
2545 return true;
2548 bool ChatHandler::HandleLookupItemCommand(const char* args)
2550 if(!*args)
2551 return false;
2553 std::string namepart = args;
2554 std::wstring wnamepart;
2556 // converting string that we try to find to lower case
2557 if(!Utf8toWStr(namepart,wnamepart))
2558 return false;
2560 wstrToLower(wnamepart);
2562 uint32 counter = 0;
2564 // Search in `item_template`
2565 for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
2567 ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype >(id);
2568 if(!pProto)
2569 continue;
2571 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
2572 if ( loc_idx >= 0 )
2574 ItemLocale const *il = objmgr.GetItemLocale(pProto->ItemId);
2575 if (il)
2577 if (il->Name.size() > loc_idx && !il->Name[loc_idx].empty())
2579 std::string name = il->Name[loc_idx];
2581 if (Utf8FitTo(name, wnamepart))
2583 if (m_session)
2584 PSendSysMessage(LANG_ITEM_LIST_CHAT, id, id, name.c_str());
2585 else
2586 PSendSysMessage(LANG_ITEM_LIST_CONSOLE, id, name.c_str());
2587 ++counter;
2588 continue;
2594 std::string name = pProto->Name1;
2595 if(name.empty())
2596 continue;
2598 if (Utf8FitTo(name, wnamepart))
2600 if (m_session)
2601 PSendSysMessage(LANG_ITEM_LIST_CHAT, id, id, name.c_str());
2602 else
2603 PSendSysMessage(LANG_ITEM_LIST_CONSOLE, id, name.c_str());
2604 ++counter;
2608 if (counter==0)
2609 SendSysMessage(LANG_COMMAND_NOITEMFOUND);
2611 return true;
2614 bool ChatHandler::HandleLookupItemSetCommand(const char* args)
2616 if(!*args)
2617 return false;
2619 std::string namepart = args;
2620 std::wstring wnamepart;
2622 if(!Utf8toWStr(namepart,wnamepart))
2623 return false;
2625 // converting string that we try to find to lower case
2626 wstrToLower( wnamepart );
2628 uint32 counter = 0; // Counter for figure out that we found smth.
2630 // Search in ItemSet.dbc
2631 for (uint32 id = 0; id < sItemSetStore.GetNumRows(); id++)
2633 ItemSetEntry const *set = sItemSetStore.LookupEntry(id);
2634 if(set)
2636 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
2637 std::string name = set->name[loc];
2638 if(name.empty())
2639 continue;
2641 if (!Utf8FitTo(name, wnamepart))
2643 loc = 0;
2644 for(; loc < MAX_LOCALE; ++loc)
2646 if(m_session && loc==m_session->GetSessionDbcLocale())
2647 continue;
2649 name = set->name[loc];
2650 if(name.empty())
2651 continue;
2653 if (Utf8FitTo(name, wnamepart))
2654 break;
2658 if(loc < MAX_LOCALE)
2660 // send item set in "id - [namedlink locale]" format
2661 if (m_session)
2662 PSendSysMessage(LANG_ITEMSET_LIST_CHAT,id,id,name.c_str(),localeNames[loc]);
2663 else
2664 PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE,id,name.c_str(),localeNames[loc]);
2665 ++counter;
2669 if (counter == 0) // if counter == 0 then we found nth
2670 SendSysMessage(LANG_COMMAND_NOITEMSETFOUND);
2671 return true;
2674 bool ChatHandler::HandleLookupSkillCommand(const char* args)
2676 if(!*args)
2677 return false;
2679 // can be NULL in console call
2680 Player* target = getSelectedPlayer();
2682 std::string namepart = args;
2683 std::wstring wnamepart;
2685 if(!Utf8toWStr(namepart,wnamepart))
2686 return false;
2688 // converting string that we try to find to lower case
2689 wstrToLower( wnamepart );
2691 uint32 counter = 0; // Counter for figure out that we found smth.
2693 // Search in SkillLine.dbc
2694 for (uint32 id = 0; id < sSkillLineStore.GetNumRows(); id++)
2696 SkillLineEntry const *skillInfo = sSkillLineStore.LookupEntry(id);
2697 if(skillInfo)
2699 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
2700 std::string name = skillInfo->name[loc];
2701 if(name.empty())
2702 continue;
2704 if (!Utf8FitTo(name, wnamepart))
2706 loc = 0;
2707 for(; loc < MAX_LOCALE; ++loc)
2709 if(m_session && loc==m_session->GetSessionDbcLocale())
2710 continue;
2712 name = skillInfo->name[loc];
2713 if(name.empty())
2714 continue;
2716 if (Utf8FitTo(name, wnamepart))
2717 break;
2721 if(loc < MAX_LOCALE)
2723 char valStr[50] = "";
2724 char const* knownStr = "";
2725 if(target && target->HasSkill(id))
2727 knownStr = GetMangosString(LANG_KNOWN);
2728 uint32 curValue = target->GetPureSkillValue(id);
2729 uint32 maxValue = target->GetPureMaxSkillValue(id);
2730 uint32 permValue = target->GetSkillPermBonusValue(id);
2731 uint32 tempValue = target->GetSkillTempBonusValue(id);
2733 char const* valFormat = GetMangosString(LANG_SKILL_VALUES);
2734 snprintf(valStr,50,valFormat,curValue,maxValue,permValue,tempValue);
2737 // send skill in "id - [namedlink locale]" format
2738 if (m_session)
2739 PSendSysMessage(LANG_SKILL_LIST_CHAT,id,id,name.c_str(),localeNames[loc],knownStr,valStr);
2740 else
2741 PSendSysMessage(LANG_SKILL_LIST_CONSOLE,id,name.c_str(),localeNames[loc],knownStr,valStr);
2743 ++counter;
2747 if (counter == 0) // if counter == 0 then we found nth
2748 SendSysMessage(LANG_COMMAND_NOSKILLFOUND);
2749 return true;
2752 bool ChatHandler::HandleLookupSpellCommand(const char* args)
2754 if(!*args)
2755 return false;
2757 // can be NULL at console call
2758 Player* target = getSelectedPlayer();
2760 std::string namepart = args;
2761 std::wstring wnamepart;
2763 if(!Utf8toWStr(namepart,wnamepart))
2764 return false;
2766 // converting string that we try to find to lower case
2767 wstrToLower( wnamepart );
2769 uint32 counter = 0; // Counter for figure out that we found smth.
2771 // Search in Spell.dbc
2772 for (uint32 id = 0; id < sSpellStore.GetNumRows(); id++)
2774 SpellEntry const *spellInfo = sSpellStore.LookupEntry(id);
2775 if(spellInfo)
2777 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
2778 std::string name = spellInfo->SpellName[loc];
2779 if(name.empty())
2780 continue;
2782 if (!Utf8FitTo(name, wnamepart))
2784 loc = 0;
2785 for(; loc < MAX_LOCALE; ++loc)
2787 if(m_session && loc==m_session->GetSessionDbcLocale())
2788 continue;
2790 name = spellInfo->SpellName[loc];
2791 if(name.empty())
2792 continue;
2794 if (Utf8FitTo(name, wnamepart))
2795 break;
2799 if(loc < MAX_LOCALE)
2801 bool known = target && target->HasSpell(id);
2802 bool learn = (spellInfo->Effect[0] == SPELL_EFFECT_LEARN_SPELL);
2804 uint32 talentCost = GetTalentSpellCost(id);
2806 bool talent = (talentCost > 0);
2807 bool passive = IsPassiveSpell(id);
2808 bool active = target && target->HasAura(id);
2810 // unit32 used to prevent interpreting uint8 as char at output
2811 // find rank of learned spell for learning spell, or talent rank
2812 uint32 rank = talentCost ? talentCost : spellmgr.GetSpellRank(learn ? spellInfo->EffectTriggerSpell[0] : id);
2814 // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
2815 std::ostringstream ss;
2816 if (m_session)
2817 ss << id << " - |cffffffff|Hspell:" << id << "|h[" << name;
2818 else
2819 ss << id << " - " << name;
2821 // include rank in link name
2822 if(rank)
2823 ss << GetMangosString(LANG_SPELL_RANK) << rank;
2825 if (m_session)
2826 ss << " " << localeNames[loc] << "]|h|r";
2827 else
2828 ss << " " << localeNames[loc];
2830 if(talent)
2831 ss << GetMangosString(LANG_TALENT);
2832 if(passive)
2833 ss << GetMangosString(LANG_PASSIVE);
2834 if(learn)
2835 ss << GetMangosString(LANG_LEARN);
2836 if(known)
2837 ss << GetMangosString(LANG_KNOWN);
2838 if(active)
2839 ss << GetMangosString(LANG_ACTIVE);
2841 SendSysMessage(ss.str().c_str());
2843 ++counter;
2847 if (counter == 0) // if counter == 0 then we found nth
2848 SendSysMessage(LANG_COMMAND_NOSPELLFOUND);
2849 return true;
2852 bool ChatHandler::HandleLookupQuestCommand(const char* args)
2854 if(!*args)
2855 return false;
2857 // can be NULL at console call
2858 Player* target = getSelectedPlayer();
2860 std::string namepart = args;
2861 std::wstring wnamepart;
2863 // converting string that we try to find to lower case
2864 if(!Utf8toWStr(namepart,wnamepart))
2865 return false;
2867 wstrToLower(wnamepart);
2869 uint32 counter = 0 ;
2871 ObjectMgr::QuestMap const& qTemplates = objmgr.GetQuestTemplates();
2872 for (ObjectMgr::QuestMap::const_iterator iter = qTemplates.begin(); iter != qTemplates.end(); ++iter)
2874 Quest * qinfo = iter->second;
2876 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
2877 if ( loc_idx >= 0 )
2879 QuestLocale const *il = objmgr.GetQuestLocale(qinfo->GetQuestId());
2880 if (il)
2882 if (il->Title.size() > loc_idx && !il->Title[loc_idx].empty())
2884 std::string title = il->Title[loc_idx];
2886 if (Utf8FitTo(title, wnamepart))
2888 char const* statusStr = "";
2890 if(target)
2892 QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId());
2894 if(status == QUEST_STATUS_COMPLETE)
2896 if(target->GetQuestRewardStatus(qinfo->GetQuestId()))
2897 statusStr = GetMangosString(LANG_COMMAND_QUEST_REWARDED);
2898 else
2899 statusStr = GetMangosString(LANG_COMMAND_QUEST_COMPLETE);
2901 else if(status == QUEST_STATUS_INCOMPLETE)
2902 statusStr = GetMangosString(LANG_COMMAND_QUEST_ACTIVE);
2905 if (m_session)
2906 PSendSysMessage(LANG_QUEST_LIST_CHAT,qinfo->GetQuestId(),qinfo->GetQuestId(),title.c_str(),statusStr);
2907 else
2908 PSendSysMessage(LANG_QUEST_LIST_CONSOLE,qinfo->GetQuestId(),title.c_str(),statusStr);
2909 ++counter;
2910 continue;
2916 std::string title = qinfo->GetTitle();
2917 if(title.empty())
2918 continue;
2920 if (Utf8FitTo(title, wnamepart))
2922 char const* statusStr = "";
2924 if(target)
2926 QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId());
2928 if(status == QUEST_STATUS_COMPLETE)
2930 if(target->GetQuestRewardStatus(qinfo->GetQuestId()))
2931 statusStr = GetMangosString(LANG_COMMAND_QUEST_REWARDED);
2932 else
2933 statusStr = GetMangosString(LANG_COMMAND_QUEST_COMPLETE);
2935 else if(status == QUEST_STATUS_INCOMPLETE)
2936 statusStr = GetMangosString(LANG_COMMAND_QUEST_ACTIVE);
2939 if (m_session)
2940 PSendSysMessage(LANG_QUEST_LIST_CHAT,qinfo->GetQuestId(),qinfo->GetQuestId(),title.c_str(),statusStr);
2941 else
2942 PSendSysMessage(LANG_QUEST_LIST_CONSOLE,qinfo->GetQuestId(),title.c_str(),statusStr);
2944 ++counter;
2948 if (counter==0)
2949 SendSysMessage(LANG_COMMAND_NOQUESTFOUND);
2951 return true;
2954 bool ChatHandler::HandleLookupCreatureCommand(const char* args)
2956 if (!*args)
2957 return false;
2959 std::string namepart = args;
2960 std::wstring wnamepart;
2962 // converting string that we try to find to lower case
2963 if (!Utf8toWStr (namepart,wnamepart))
2964 return false;
2966 wstrToLower (wnamepart);
2968 uint32 counter = 0;
2970 for (uint32 id = 0; id< sCreatureStorage.MaxEntry; ++id)
2972 CreatureInfo const* cInfo = sCreatureStorage.LookupEntry<CreatureInfo> (id);
2973 if(!cInfo)
2974 continue;
2976 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
2977 if (loc_idx >= 0)
2979 CreatureLocale const *cl = objmgr.GetCreatureLocale (id);
2980 if (cl)
2982 if (cl->Name.size() > loc_idx && !cl->Name[loc_idx].empty ())
2984 std::string name = cl->Name[loc_idx];
2986 if (Utf8FitTo (name, wnamepart))
2988 if (m_session)
2989 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str ());
2990 else
2991 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE, id, name.c_str ());
2992 ++counter;
2993 continue;
2999 std::string name = cInfo->Name;
3000 if (name.empty ())
3001 continue;
3003 if (Utf8FitTo(name, wnamepart))
3005 if (m_session)
3006 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str ());
3007 else
3008 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE, id, name.c_str ());
3009 ++counter;
3013 if (counter==0)
3014 SendSysMessage (LANG_COMMAND_NOCREATUREFOUND);
3016 return true;
3019 bool ChatHandler::HandleLookupObjectCommand(const char* args)
3021 if(!*args)
3022 return false;
3024 std::string namepart = args;
3025 std::wstring wnamepart;
3027 // converting string that we try to find to lower case
3028 if(!Utf8toWStr(namepart,wnamepart))
3029 return false;
3031 wstrToLower(wnamepart);
3033 uint32 counter = 0;
3035 for (uint32 id = 0; id< sGOStorage.MaxEntry; id++ )
3037 GameObjectInfo const* gInfo = sGOStorage.LookupEntry<GameObjectInfo>(id);
3038 if(!gInfo)
3039 continue;
3041 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
3042 if ( loc_idx >= 0 )
3044 GameObjectLocale const *gl = objmgr.GetGameObjectLocale(id);
3045 if (gl)
3047 if (gl->Name.size() > loc_idx && !gl->Name[loc_idx].empty())
3049 std::string name = gl->Name[loc_idx];
3051 if (Utf8FitTo(name, wnamepart))
3053 if (m_session)
3054 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, id, id, name.c_str());
3055 else
3056 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, id, name.c_str());
3057 ++counter;
3058 continue;
3064 std::string name = gInfo->name;
3065 if(name.empty())
3066 continue;
3068 if(Utf8FitTo(name, wnamepart))
3070 if (m_session)
3071 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, id, id, name.c_str());
3072 else
3073 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, id, name.c_str());
3074 ++counter;
3078 if(counter==0)
3079 SendSysMessage(LANG_COMMAND_NOGAMEOBJECTFOUND);
3081 return true;
3084 bool ChatHandler::HandleLookupTaxiNodeCommand(const char * args)
3086 if(!*args)
3087 return false;
3089 std::string namepart = args;
3090 std::wstring wnamepart;
3092 if(!Utf8toWStr(namepart,wnamepart))
3093 return false;
3095 // converting string that we try to find to lower case
3096 wstrToLower( wnamepart );
3098 uint32 counter = 0; // Counter for figure out that we found smth.
3100 // Search in TaxiNodes.dbc
3101 for (uint32 id = 0; id < sTaxiNodesStore.GetNumRows(); id++)
3103 TaxiNodesEntry const *nodeEntry = sTaxiNodesStore.LookupEntry(id);
3104 if(nodeEntry)
3106 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
3107 std::string name = nodeEntry->name[loc];
3108 if(name.empty())
3109 continue;
3111 if (!Utf8FitTo(name, wnamepart))
3113 loc = 0;
3114 for(; loc < MAX_LOCALE; ++loc)
3116 if(m_session && loc==m_session->GetSessionDbcLocale())
3117 continue;
3119 name = nodeEntry->name[loc];
3120 if(name.empty())
3121 continue;
3123 if (Utf8FitTo(name, wnamepart))
3124 break;
3128 if(loc < MAX_LOCALE)
3130 // send taxinode in "id - [name] (Map:m X:x Y:y Z:z)" format
3131 if (m_session)
3132 PSendSysMessage (LANG_TAXINODE_ENTRY_LIST_CHAT, id, id, name.c_str(),localeNames[loc],
3133 nodeEntry->map_id,nodeEntry->x,nodeEntry->y,nodeEntry->z);
3134 else
3135 PSendSysMessage (LANG_TAXINODE_ENTRY_LIST_CONSOLE, id, name.c_str(), localeNames[loc],
3136 nodeEntry->map_id,nodeEntry->x,nodeEntry->y,nodeEntry->z);
3137 ++counter;
3141 if (counter == 0) // if counter == 0 then we found nth
3142 SendSysMessage(LANG_COMMAND_NOSPELLFOUND);
3143 return true;
3146 /** \brief GM command level 3 - Create a guild.
3148 * This command allows a GM (level 3) to create a guild.
3150 * The "args" parameter contains the name of the guild leader
3151 * and then the name of the guild.
3154 bool ChatHandler::HandleGuildCreateCommand(const char* args)
3157 if (!*args)
3158 return false;
3160 char *lname = strtok ((char*)args, " ");
3161 char *gname = strtok (NULL, "");
3163 if (!lname)
3164 return false;
3166 if (!gname)
3168 SendSysMessage (LANG_INSERT_GUILD_NAME);
3169 SetSentErrorMessage (true);
3170 return false;
3173 std::string guildname = gname;
3175 Player* player = ObjectAccessor::Instance ().FindPlayerByName (lname);
3176 if (!player)
3178 SendSysMessage (LANG_PLAYER_NOT_FOUND);
3179 SetSentErrorMessage (true);
3180 return false;
3183 if (player->GetGuildId())
3185 SendSysMessage (LANG_PLAYER_IN_GUILD);
3186 return true;
3189 Guild *guild = new Guild;
3190 if (!guild->create (player,guildname))
3192 delete guild;
3193 SendSysMessage (LANG_GUILD_NOT_CREATED);
3194 SetSentErrorMessage (true);
3195 return false;
3198 objmgr.AddGuild (guild);
3199 return true;
3202 bool ChatHandler::HandleGuildInviteCommand(const char *args)
3204 if (!*args)
3205 return false;
3207 char* par1 = strtok ((char*)args, " ");
3208 char* par2 = strtok (NULL, "");
3209 if(!par1 || !par2)
3210 return false;
3212 std::string glName = par2;
3213 Guild* targetGuild = objmgr.GetGuildByName (glName);
3214 if (!targetGuild)
3215 return false;
3217 std::string plName = extractPlayerNameFromLink(par1);
3218 if(plName.empty())
3220 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3221 SetSentErrorMessage(true);
3222 return false;
3225 uint64 plGuid = 0;
3226 if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3227 plGuid = targetPlayer->GetGUID ();
3228 else
3229 plGuid = objmgr.GetPlayerGUIDByName (plName);
3231 if (!plGuid)
3232 return false;
3234 // player's guild membership checked in AddMember before add
3235 if (!targetGuild->AddMember (plGuid,targetGuild->GetLowestRank ()))
3236 return false;
3238 return true;
3241 bool ChatHandler::HandleGuildUninviteCommand(const char *args)
3243 if (!*args)
3244 return false;
3246 char* par1 = strtok ((char*)args, " ");
3247 if(!par1)
3248 return false;
3250 std::string plName = extractPlayerNameFromLink(par1);
3251 if(plName.empty())
3253 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3254 SetSentErrorMessage(true);
3255 return false;
3258 uint64 plGuid = 0;
3259 uint32 glId = 0;
3260 if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3262 plGuid = targetPlayer->GetGUID ();
3263 glId = targetPlayer->GetGuildId ();
3265 else
3267 plGuid = objmgr.GetPlayerGUIDByName (plName);
3268 glId = Player::GetGuildIdFromDB (plGuid);
3271 if (!plGuid || !glId)
3272 return false;
3274 Guild* targetGuild = objmgr.GetGuildById (glId);
3275 if (!targetGuild)
3276 return false;
3278 targetGuild->DelMember (plGuid);
3280 return true;
3283 bool ChatHandler::HandleGuildRankCommand(const char *args)
3285 if (!*args)
3286 return false;
3288 char* par1 = strtok ((char*)args, " ");
3289 char* par2 = strtok (NULL, " ");
3290 if (!par1 || !par2)
3291 return false;
3293 std::string plName = extractPlayerNameFromLink(par1);
3294 if(plName.empty())
3296 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3297 SetSentErrorMessage(true);
3298 return false;
3302 uint64 plGuid = 0;
3303 uint32 glId = 0;
3304 if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3306 plGuid = targetPlayer->GetGUID ();
3307 glId = targetPlayer->GetGuildId ();
3309 else
3311 plGuid = objmgr.GetPlayerGUIDByName (plName);
3312 glId = Player::GetGuildIdFromDB (plGuid);
3315 if (!plGuid || !glId)
3316 return false;
3318 Guild* targetGuild = objmgr.GetGuildById (glId);
3319 if (!targetGuild)
3320 return false;
3322 uint32 newrank = uint32 (atoi (par2));
3323 if (newrank > targetGuild->GetLowestRank ())
3324 return false;
3326 targetGuild->ChangeRank (plGuid,newrank);
3328 return true;
3331 bool ChatHandler::HandleGuildDeleteCommand(const char* args)
3333 if (!*args)
3334 return false;
3336 char* par1 = strtok ((char*)args, " ");
3337 if (!par1)
3338 return false;
3340 std::string gld = par1;
3342 Guild* targetGuild = objmgr.GetGuildByName (gld);
3343 if (!targetGuild)
3344 return false;
3346 targetGuild->Disband ();
3348 return true;
3351 bool ChatHandler::HandleGetDistanceCommand(const char* args)
3353 WorldObject* obj = NULL;
3355 if (*args)
3357 uint64 guid = extractGuidFromLink((char*)args);
3358 if(guid)
3359 obj = (WorldObject*)ObjectAccessor::GetObjectByTypeMask(*m_session->GetPlayer(),guid,TYPEMASK_UNIT|TYPEMASK_GAMEOBJECT);
3361 if(!obj)
3363 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3364 SetSentErrorMessage(true);
3365 return false;
3368 else
3370 obj = getSelectedUnit();
3372 if(!obj)
3374 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3375 SetSentErrorMessage(true);
3376 return false;
3380 PSendSysMessage(LANG_DISTANCE, m_session->GetPlayer()->GetDistance(obj),m_session->GetPlayer()->GetDistance2d(obj));
3382 return true;
3385 bool ChatHandler::HandleDieCommand(const char* /*args*/)
3387 Unit* target = getSelectedUnit();
3389 if(!target || !m_session->GetPlayer()->GetSelection())
3391 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3392 SetSentErrorMessage(true);
3393 return false;
3396 if(target->GetTypeId()==TYPEID_PLAYER)
3398 if(HasLowerSecurity((Player*)target,0,false))
3399 return false;
3402 if( target->isAlive() )
3404 m_session->GetPlayer()->DealDamage(target, target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
3407 return true;
3410 bool ChatHandler::HandleDamageCommand(const char * args)
3412 if (!*args)
3413 return false;
3415 Unit* target = getSelectedUnit();
3417 if (!target || !m_session->GetPlayer()->GetSelection())
3419 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3420 SetSentErrorMessage(true);
3421 return false;
3424 if (!target->isAlive())
3425 return true;
3427 char* damageStr = strtok((char*)args, " ");
3428 if (!damageStr)
3429 return false;
3431 int32 damage_int = atoi((char*)damageStr);
3432 if(damage_int <=0)
3433 return true;
3435 uint32 damage = damage_int;
3437 char* schoolStr = strtok((char*)NULL, " ");
3439 // flat melee damage without resistence/etc reduction
3440 if (!schoolStr)
3442 m_session->GetPlayer()->DealDamage(target, damage, NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
3443 if (target != m_session->GetPlayer())
3444 m_session->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2, target, 1, SPELL_SCHOOL_MASK_NORMAL, damage, 0, 0, VICTIMSTATE_NORMAL, 0);
3445 return true;
3448 uint32 school = schoolStr ? atoi((char*)schoolStr) : SPELL_SCHOOL_NORMAL;
3449 if(school >= MAX_SPELL_SCHOOL)
3450 return false;
3452 SpellSchoolMask schoolmask = SpellSchoolMask(1 << school);
3454 if ( schoolmask & SPELL_SCHOOL_MASK_NORMAL )
3455 damage = m_session->GetPlayer()->CalcArmorReducedDamage(target, damage);
3457 char* spellStr = strtok((char*)NULL, " ");
3459 // melee damage by specific school
3460 if (!spellStr)
3462 uint32 absorb = 0;
3463 uint32 resist = 0;
3465 m_session->GetPlayer()->CalcAbsorbResist(target,schoolmask, SPELL_DIRECT_DAMAGE, damage, &absorb, &resist);
3467 if (damage <= absorb + resist)
3468 return true;
3470 damage -= absorb + resist;
3472 m_session->GetPlayer()->DealDamageMods(target,damage,&absorb);
3473 m_session->GetPlayer()->DealDamage(target, damage, NULL, DIRECT_DAMAGE, schoolmask, NULL, false);
3474 m_session->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2, target, 1, schoolmask, damage, absorb, resist, VICTIMSTATE_NORMAL, 0);
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 for pet
4796 if(Pet* pet = player->GetPet())
4797 pet->SynchronizeLevelWithOwner();
4799 return true;
4802 bool ChatHandler::HandleResetStatsCommand(const char * args)
4804 char* pName = strtok((char*)args, "");
4805 Player *player = NULL;
4806 if (pName)
4808 std::string name = extractPlayerNameFromLink(pName);
4809 if(name.empty())
4811 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4812 SetSentErrorMessage(true);
4813 return false;
4816 uint64 guid = objmgr.GetPlayerGUIDByName(name);
4817 player = objmgr.GetPlayer(guid);
4819 else
4820 player = getSelectedPlayer();
4822 if(!player)
4824 SendSysMessage(LANG_NO_CHAR_SELECTED);
4825 SetSentErrorMessage(true);
4826 return false;
4829 if(!HandleResetStatsOrLevelHelper(player))
4830 return false;
4832 player->InitRunes();
4833 player->InitStatsForLevel(true);
4834 player->InitTaxiNodesForLevel();
4835 player->InitGlyphsForLevel();
4836 player->InitTalentForLevel();
4838 return true;
4841 bool ChatHandler::HandleResetSpellsCommand(const char * args)
4843 char* pName = strtok((char*)args, "");
4844 Player *player = NULL;
4845 uint64 playerGUID = 0;
4846 if (pName)
4848 std::string name = extractPlayerNameFromLink(pName);
4849 if(name.empty())
4851 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4852 SetSentErrorMessage(true);
4853 return false;
4856 player = objmgr.GetPlayer(name.c_str());
4857 if(!player)
4858 playerGUID = objmgr.GetPlayerGUIDByName(name);
4860 else
4861 player = getSelectedPlayer();
4863 if(!player && !playerGUID)
4865 SendSysMessage(LANG_NO_CHAR_SELECTED);
4866 SetSentErrorMessage(true);
4867 return false;
4870 if(player)
4872 player->resetSpells();
4874 ChatHandler(player).SendSysMessage(LANG_RESET_SPELLS);
4875 if(m_session->GetPlayer()!=player)
4876 PSendSysMessage(LANG_RESET_SPELLS_ONLINE,GetNameLink(player).c_str());
4878 else
4880 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS), GUID_LOPART(playerGUID));
4881 PSendSysMessage(LANG_RESET_SPELLS_OFFLINE,pName);
4884 return true;
4887 bool ChatHandler::HandleResetTalentsCommand(const char * args)
4889 char* pName = strtok((char*)args, "");
4890 Player *player = NULL;
4891 uint64 playerGUID = 0;
4892 if (pName)
4894 std::string name = extractPlayerNameFromLink(pName);
4895 if(name.empty())
4897 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4898 SetSentErrorMessage(true);
4899 return false;
4902 player = objmgr.GetPlayer(name.c_str());
4903 if(!player)
4904 playerGUID = objmgr.GetPlayerGUIDByName(name);
4906 else
4907 player = getSelectedPlayer();
4909 if(player)
4911 player->resetTalents(true);
4913 ChatHandler(player).SendSysMessage(LANG_RESET_TALENTS);
4914 if(m_session->GetPlayer()!=player)
4915 PSendSysMessage(LANG_RESET_TALENTS_ONLINE,GetNameLink(player).c_str());
4917 return true;
4919 else if (playerGUID)
4921 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_TALENTS), GUID_LOPART(playerGUID) );
4922 std::string nameLink = playerLink(pName);
4923 PSendSysMessage(LANG_RESET_TALENTS_OFFLINE,nameLink.c_str());
4924 return true;
4926 // Try reset talenents as Hunter Pet
4927 Creature* creature = getSelectedCreature();
4928 if (creature && creature->isPet() && ((Pet *)creature)->getPetType() == HUNTER_PET)
4930 ((Pet *)creature)->resetTalents(true);
4931 Unit *owner = creature->GetOwner();
4932 if (owner && owner->GetTypeId() == TYPEID_PLAYER)
4934 player = (Player *)owner;
4935 ChatHandler(player).SendSysMessage(LANG_RESET_PET_TALENTS);
4936 if(m_session->GetPlayer()!=player)
4937 PSendSysMessage(LANG_RESET_PET_TALENTS_ONLINE,GetNameLink(player).c_str());
4939 return true;
4942 SendSysMessage(LANG_NO_CHAR_SELECTED);
4943 SetSentErrorMessage(true);
4944 return false;
4947 bool ChatHandler::HandleResetAllCommand(const char * args)
4949 if(!*args)
4950 return false;
4952 std::string casename = args;
4954 AtLoginFlags atLogin;
4956 // Command specially created as single command to prevent using short case names
4957 if(casename=="spells")
4959 atLogin = AT_LOGIN_RESET_SPELLS;
4960 sWorld.SendWorldText(LANG_RESETALL_SPELLS);
4962 else if(casename=="talents")
4964 atLogin = AT_LOGIN_RESET_TALENTS;
4965 sWorld.SendWorldText(LANG_RESETALL_TALENTS);
4967 else
4969 PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE,args);
4970 SetSentErrorMessage(true);
4971 return false;
4974 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE (at_login & '%u') = '0'",atLogin,atLogin);
4975 HashMapHolder<Player>::MapType const& plist = ObjectAccessor::Instance().GetPlayers();
4976 for(HashMapHolder<Player>::MapType::const_iterator itr = plist.begin(); itr != plist.end(); ++itr)
4977 itr->second->SetAtLoginFlag(atLogin);
4979 return true;
4982 bool ChatHandler::HandleServerShutDownCancelCommand(const char* /*args*/)
4984 sWorld.ShutdownCancel();
4985 return true;
4988 bool ChatHandler::HandleServerShutDownCommand(const char* args)
4990 if(!*args)
4991 return false;
4993 char* time_str = strtok ((char*) args, " ");
4994 char* exitcode_str = strtok (NULL, "");
4996 int32 time = atoi (time_str);
4998 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4999 if ((time == 0 && (time_str[0]!='0' || time_str[1]!='\0')) || time < 0)
5000 return false;
5002 if (exitcode_str)
5004 int32 exitcode = atoi (exitcode_str);
5006 // Handle atoi() errors
5007 if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
5008 return false;
5010 // Exit code should be in range of 0-125, 126-255 is used
5011 // in many shells for their own return codes and code > 255
5012 // is not supported in many others
5013 if (exitcode < 0 || exitcode > 125)
5014 return false;
5016 sWorld.ShutdownServ (time, 0, exitcode);
5018 else
5019 sWorld.ShutdownServ(time,0,SHUTDOWN_EXIT_CODE);
5020 return true;
5023 bool ChatHandler::HandleServerRestartCommand(const char* args)
5025 if(!*args)
5026 return false;
5028 char* time_str = strtok ((char*) args, " ");
5029 char* exitcode_str = strtok (NULL, "");
5031 int32 time = atoi (time_str);
5033 ///- Prevent interpret wrong arg value as 0 secs shutdown time
5034 if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0)
5035 return false;
5037 if (exitcode_str)
5039 int32 exitcode = atoi (exitcode_str);
5041 // Handle atoi() errors
5042 if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
5043 return false;
5045 // Exit code should be in range of 0-125, 126-255 is used
5046 // in many shells for their own return codes and code > 255
5047 // is not supported in many others
5048 if (exitcode < 0 || exitcode > 125)
5049 return false;
5051 sWorld.ShutdownServ (time, SHUTDOWN_MASK_RESTART, exitcode);
5053 else
5054 sWorld.ShutdownServ(time, SHUTDOWN_MASK_RESTART, RESTART_EXIT_CODE);
5055 return true;
5058 bool ChatHandler::HandleServerIdleRestartCommand(const char* args)
5060 if(!*args)
5061 return false;
5063 char* time_str = strtok ((char*) args, " ");
5064 char* exitcode_str = strtok (NULL, "");
5066 int32 time = atoi (time_str);
5068 ///- Prevent interpret wrong arg value as 0 secs shutdown time
5069 if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0)
5070 return false;
5072 if (exitcode_str)
5074 int32 exitcode = atoi (exitcode_str);
5076 // Handle atoi() errors
5077 if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
5078 return false;
5080 // Exit code should be in range of 0-125, 126-255 is used
5081 // in many shells for their own return codes and code > 255
5082 // is not supported in many others
5083 if (exitcode < 0 || exitcode > 125)
5084 return false;
5086 sWorld.ShutdownServ (time, SHUTDOWN_MASK_RESTART|SHUTDOWN_MASK_IDLE, exitcode);
5088 else
5089 sWorld.ShutdownServ(time,SHUTDOWN_MASK_RESTART|SHUTDOWN_MASK_IDLE,RESTART_EXIT_CODE);
5090 return true;
5093 bool ChatHandler::HandleServerIdleShutDownCommand(const char* args)
5095 if(!*args)
5096 return false;
5098 char* time_str = strtok ((char*) args, " ");
5099 char* exitcode_str = strtok (NULL, "");
5101 int32 time = atoi (time_str);
5103 ///- Prevent interpret wrong arg value as 0 secs shutdown time
5104 if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0)
5105 return false;
5107 if (exitcode_str)
5109 int32 exitcode = atoi (exitcode_str);
5111 // Handle atoi() errors
5112 if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
5113 return false;
5115 // Exit code should be in range of 0-125, 126-255 is used
5116 // in many shells for their own return codes and code > 255
5117 // is not supported in many others
5118 if (exitcode < 0 || exitcode > 125)
5119 return false;
5121 sWorld.ShutdownServ (time, SHUTDOWN_MASK_IDLE, exitcode);
5123 else
5124 sWorld.ShutdownServ(time,SHUTDOWN_MASK_IDLE,SHUTDOWN_EXIT_CODE);
5125 return true;
5128 bool ChatHandler::HandleQuestAdd(const char* args)
5130 Player* player = getSelectedPlayer();
5131 if(!player)
5133 SendSysMessage(LANG_NO_CHAR_SELECTED);
5134 SetSentErrorMessage(true);
5135 return false;
5138 // .addquest #entry'
5139 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
5140 char* cId = extractKeyFromLink((char*)args,"Hquest");
5141 if(!cId)
5142 return false;
5144 uint32 entry = atol(cId);
5146 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
5148 if(!pQuest)
5150 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND,entry);
5151 SetSentErrorMessage(true);
5152 return false;
5155 // check item starting quest (it can work incorrectly if added without item in inventory)
5156 for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
5158 ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype>(id);
5159 if (!pProto)
5160 continue;
5162 if (pProto->StartQuest == entry)
5164 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, entry, pProto->ItemId);
5165 SetSentErrorMessage(true);
5166 return false;
5170 // ok, normal (creature/GO starting) quest
5171 if( player->CanAddQuest( pQuest, true ) )
5173 player->AddQuest( pQuest, NULL );
5175 if ( player->CanCompleteQuest( entry ) )
5176 player->CompleteQuest( entry );
5179 return true;
5182 bool ChatHandler::HandleQuestRemove(const char* args)
5184 Player* player = getSelectedPlayer();
5185 if(!player)
5187 SendSysMessage(LANG_NO_CHAR_SELECTED);
5188 SetSentErrorMessage(true);
5189 return false;
5192 // .removequest #entry'
5193 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
5194 char* cId = extractKeyFromLink((char*)args,"Hquest");
5195 if(!cId)
5196 return false;
5198 uint32 entry = atol(cId);
5200 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
5202 if(!pQuest)
5204 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
5205 SetSentErrorMessage(true);
5206 return false;
5209 // remove all quest entries for 'entry' from quest log
5210 for(uint8 slot = 0; slot < MAX_QUEST_LOG_SIZE; ++slot )
5212 uint32 quest = player->GetQuestSlotQuestId(slot);
5213 if(quest==entry)
5215 player->SetQuestSlot(slot,0);
5217 // we ignore unequippable quest items in this case, its' still be equipped
5218 player->TakeQuestSourceItem( quest, false );
5222 // set quest status to not started (will updated in DB at next save)
5223 player->SetQuestStatus( entry, QUEST_STATUS_NONE);
5225 // reset rewarded for restart repeatable quest
5226 player->getQuestStatusMap()[entry].m_rewarded = false;
5228 SendSysMessage(LANG_COMMAND_QUEST_REMOVED);
5229 return true;
5232 bool ChatHandler::HandleQuestComplete(const char* args)
5234 Player* player = getSelectedPlayer();
5235 if(!player)
5237 SendSysMessage(LANG_NO_CHAR_SELECTED);
5238 SetSentErrorMessage(true);
5239 return false;
5242 // .quest complete #entry
5243 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
5244 char* cId = extractKeyFromLink((char*)args,"Hquest");
5245 if(!cId)
5246 return false;
5248 uint32 entry = atol(cId);
5250 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
5252 // If player doesn't have the quest
5253 if(!pQuest || player->GetQuestStatus(entry) == QUEST_STATUS_NONE)
5255 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
5256 SetSentErrorMessage(true);
5257 return false;
5260 // Add quest items for quests that require items
5261 for(uint8 x = 0; x < QUEST_OBJECTIVES_COUNT; ++x)
5263 uint32 id = pQuest->ReqItemId[x];
5264 uint32 count = pQuest->ReqItemCount[x];
5265 if(!id || !count)
5266 continue;
5268 uint32 curItemCount = player->GetItemCount(id,true);
5270 ItemPosCountVec dest;
5271 uint8 msg = player->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, id, count-curItemCount );
5272 if( msg == EQUIP_ERR_OK )
5274 Item* item = player->StoreNewItem( dest, id, true);
5275 player->SendNewItem(item,count-curItemCount,true,false);
5279 // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
5280 for(uint8 i = 0; i < QUEST_OBJECTIVES_COUNT; ++i)
5282 uint32 creature = pQuest->ReqCreatureOrGOId[i];
5283 uint32 creaturecount = pQuest->ReqCreatureOrGOCount[i];
5285 if(uint32 spell_id = pQuest->ReqSpell[i])
5287 for(uint16 z = 0; z < creaturecount; ++z)
5288 player->CastedCreatureOrGO(creature,0,spell_id);
5290 else if(creature > 0)
5292 for(uint16 z = 0; z < creaturecount; ++z)
5293 player->KilledMonster(creature,0);
5295 else if(creature < 0)
5297 for(uint16 z = 0; z < creaturecount; ++z)
5298 player->CastedCreatureOrGO(creature,0,0);
5302 // If the quest requires reputation to complete
5303 if(uint32 repFaction = pQuest->GetRepObjectiveFaction())
5305 uint32 repValue = pQuest->GetRepObjectiveValue();
5306 uint32 curRep = player->GetReputationMgr().GetReputation(repFaction);
5307 if(curRep < repValue)
5308 if(FactionEntry const *factionEntry = sFactionStore.LookupEntry(repFaction))
5309 player->GetReputationMgr().SetReputation(factionEntry,repValue);
5312 // If the quest requires money
5313 int32 ReqOrRewMoney = pQuest->GetRewOrReqMoney();
5314 if(ReqOrRewMoney < 0)
5315 player->ModifyMoney(-ReqOrRewMoney);
5317 player->CompleteQuest(entry);
5318 return true;
5321 bool ChatHandler::HandleBanAccountCommand(const char* args)
5323 return HandleBanHelper(BAN_ACCOUNT,args);
5326 bool ChatHandler::HandleBanCharacterCommand(const char* args)
5328 return HandleBanHelper(BAN_CHARACTER,args);
5331 bool ChatHandler::HandleBanIPCommand(const char* args)
5333 return HandleBanHelper(BAN_IP,args);
5336 bool ChatHandler::HandleBanHelper(BanMode mode, const char* args)
5338 if (!*args)
5339 return false;
5341 char* cnameOrIP = strtok ((char*)args, " ");
5342 if (!cnameOrIP)
5343 return false;
5345 std::string nameOrIP = cnameOrIP;
5347 char* duration = strtok (NULL," ");
5348 if(!duration || !atoi(duration))
5349 return false;
5351 char* reason = strtok (NULL,"");
5352 if(!reason)
5353 return false;
5355 switch(mode)
5357 case BAN_ACCOUNT:
5358 if(!AccountMgr::normilizeString(nameOrIP))
5360 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str());
5361 SetSentErrorMessage(true);
5362 return false;
5364 break;
5365 case BAN_CHARACTER:
5366 if(!normalizePlayerName(nameOrIP))
5368 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5369 SetSentErrorMessage(true);
5370 return false;
5372 break;
5373 case BAN_IP:
5374 if(!IsIPAddress(nameOrIP.c_str()))
5375 return false;
5376 break;
5379 switch(sWorld.BanAccount(mode, nameOrIP, duration, reason,m_session ? m_session->GetPlayerName() : ""))
5381 case BAN_SUCCESS:
5382 if(atoi(duration)>0)
5383 PSendSysMessage(LANG_BAN_YOUBANNED,nameOrIP.c_str(),secsToTimeString(TimeStringToSecs(duration),true).c_str(),reason);
5384 else
5385 PSendSysMessage(LANG_BAN_YOUPERMBANNED,nameOrIP.c_str(),reason);
5386 break;
5387 case BAN_SYNTAX_ERROR:
5388 return false;
5389 case BAN_NOTFOUND:
5390 switch(mode)
5392 default:
5393 PSendSysMessage(LANG_BAN_NOTFOUND,"account",nameOrIP.c_str());
5394 break;
5395 case BAN_CHARACTER:
5396 PSendSysMessage(LANG_BAN_NOTFOUND,"character",nameOrIP.c_str());
5397 break;
5398 case BAN_IP:
5399 PSendSysMessage(LANG_BAN_NOTFOUND,"ip",nameOrIP.c_str());
5400 break;
5402 SetSentErrorMessage(true);
5403 return false;
5406 return true;
5409 bool ChatHandler::HandleUnBanAccountCommand(const char* args)
5411 return HandleUnBanHelper(BAN_ACCOUNT,args);
5414 bool ChatHandler::HandleUnBanCharacterCommand(const char* args)
5416 return HandleUnBanHelper(BAN_CHARACTER,args);
5419 bool ChatHandler::HandleUnBanIPCommand(const char* args)
5421 return HandleUnBanHelper(BAN_IP,args);
5424 bool ChatHandler::HandleUnBanHelper(BanMode mode, const char* args)
5426 if (!*args)
5427 return false;
5429 char* cnameOrIP = strtok ((char*)args, " ");
5430 if(!cnameOrIP)
5431 return false;
5433 std::string nameOrIP = cnameOrIP;
5435 switch(mode)
5437 case BAN_ACCOUNT:
5438 if(!AccountMgr::normilizeString(nameOrIP))
5440 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str());
5441 SetSentErrorMessage(true);
5442 return false;
5444 break;
5445 case BAN_CHARACTER:
5446 if(!normalizePlayerName(nameOrIP))
5448 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5449 SetSentErrorMessage(true);
5450 return false;
5452 break;
5453 case BAN_IP:
5454 if(!IsIPAddress(nameOrIP.c_str()))
5455 return false;
5456 break;
5459 if(sWorld.RemoveBanAccount(mode,nameOrIP))
5460 PSendSysMessage(LANG_UNBAN_UNBANNED,nameOrIP.c_str());
5461 else
5462 PSendSysMessage(LANG_UNBAN_ERROR,nameOrIP.c_str());
5464 return true;
5467 bool ChatHandler::HandleBanInfoAccountCommand(const char* args)
5469 if (!*args)
5470 return false;
5472 char* cname = strtok((char*)args, "");
5473 if(!cname)
5474 return false;
5476 std::string account_name = cname;
5477 if(!AccountMgr::normilizeString(account_name))
5479 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5480 SetSentErrorMessage(true);
5481 return false;
5484 uint32 accountid = accmgr.GetId(account_name);
5485 if(!accountid)
5487 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5488 return true;
5491 return HandleBanInfoHelper(accountid,account_name.c_str());
5494 bool ChatHandler::HandleBanInfoCharacterCommand(const char* args)
5496 if (!*args)
5497 return false;
5499 std::string name = extractPlayerNameFromLink((char*)args);
5500 if(name.empty())
5502 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5503 SetSentErrorMessage(true);
5504 return false;
5507 uint32 accountid = objmgr.GetPlayerAccountIdByPlayerName(name);
5508 if(!accountid)
5510 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5511 SetSentErrorMessage(true);
5512 return false;
5515 std::string accountname;
5516 if(!accmgr.GetName(accountid,accountname))
5518 PSendSysMessage(LANG_BANINFO_NOCHARACTER);
5519 return true;
5522 return HandleBanInfoHelper(accountid,accountname.c_str());
5525 bool ChatHandler::HandleBanInfoHelper(uint32 accountid, char const* accountname)
5527 QueryResult *result = loginDatabase.PQuery("SELECT FROM_UNIXTIME(bandate), unbandate-bandate, active, unbandate,banreason,bannedby FROM account_banned WHERE id = '%u' ORDER BY bandate ASC",accountid);
5528 if(!result)
5530 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN, accountname);
5531 return true;
5534 PSendSysMessage(LANG_BANINFO_BANHISTORY,accountname);
5537 Field* fields = result->Fetch();
5539 time_t unbandate = time_t(fields[3].GetUInt64());
5540 bool active = false;
5541 if(fields[2].GetBool() && (fields[1].GetUInt64() == (uint64)0 ||unbandate >= time(NULL)) )
5542 active = true;
5543 bool permanent = (fields[1].GetUInt64() == (uint64)0);
5544 std::string bantime = permanent?GetMangosString(LANG_BANINFO_INFINITE):secsToTimeString(fields[1].GetUInt64(), true);
5545 PSendSysMessage(LANG_BANINFO_HISTORYENTRY,
5546 fields[0].GetString(), bantime.c_str(), active ? GetMangosString(LANG_BANINFO_YES):GetMangosString(LANG_BANINFO_NO), fields[4].GetString(), fields[5].GetString());
5547 }while (result->NextRow());
5549 delete result;
5550 return true;
5553 bool ChatHandler::HandleBanInfoIPCommand(const char* args)
5555 if (!*args)
5556 return false;
5558 char* cIP = strtok ((char*)args, "");
5559 if(!cIP)
5560 return false;
5562 if (!IsIPAddress(cIP))
5563 return false;
5565 std::string IP = cIP;
5567 loginDatabase.escape_string(IP);
5568 QueryResult *result = loginDatabase.PQuery("SELECT ip, FROM_UNIXTIME(bandate), FROM_UNIXTIME(unbandate), unbandate-UNIX_TIMESTAMP(), banreason,bannedby,unbandate-bandate FROM ip_banned WHERE ip = '%s'",IP.c_str());
5569 if(!result)
5571 PSendSysMessage(LANG_BANINFO_NOIP);
5572 return true;
5575 Field *fields = result->Fetch();
5576 bool permanent = !fields[6].GetUInt64();
5577 PSendSysMessage(LANG_BANINFO_IPENTRY,
5578 fields[0].GetString(), fields[1].GetString(), permanent ? GetMangosString(LANG_BANINFO_NEVER):fields[2].GetString(),
5579 permanent ? GetMangosString(LANG_BANINFO_INFINITE):secsToTimeString(fields[3].GetUInt64(), true).c_str(), fields[4].GetString(), fields[5].GetString());
5580 delete result;
5581 return true;
5584 bool ChatHandler::HandleBanListCharacterCommand(const char* args)
5586 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5588 char* cFilter = strtok ((char*)args, " ");
5589 if(!cFilter)
5590 return false;
5592 std::string filter = cFilter;
5593 loginDatabase.escape_string(filter);
5594 QueryResult* result = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'"),filter.c_str());
5595 if (!result)
5597 PSendSysMessage(LANG_BANLIST_NOCHARACTER);
5598 return true;
5601 return HandleBanListHelper(result);
5604 bool ChatHandler::HandleBanListAccountCommand(const char* args)
5606 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5608 char* cFilter = strtok((char*)args, " ");
5609 std::string filter = cFilter ? cFilter : "";
5610 loginDatabase.escape_string(filter);
5612 QueryResult* result;
5614 if(filter.empty())
5616 result = loginDatabase.Query("SELECT account.id, username FROM account, account_banned"
5617 " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
5619 else
5621 result = loginDatabase.PQuery("SELECT account.id, username FROM account, account_banned"
5622 " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
5623 filter.c_str());
5626 if (!result)
5628 PSendSysMessage(LANG_BANLIST_NOACCOUNT);
5629 return true;
5632 return HandleBanListHelper(result);
5635 bool ChatHandler::HandleBanListHelper(QueryResult* result)
5637 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT);
5639 // Chat short output
5640 if(m_session)
5644 Field* fields = result->Fetch();
5645 uint32 accountid = fields[0].GetUInt32();
5647 QueryResult* banresult = loginDatabase.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid);
5648 if(banresult)
5650 Field* fields2 = banresult->Fetch();
5651 PSendSysMessage("%s",fields2[0].GetString());
5652 delete banresult;
5654 } while (result->NextRow());
5656 // Console wide output
5657 else
5659 SendSysMessage(LANG_BANLIST_ACCOUNTS);
5660 SendSysMessage("===============================================================================");
5661 SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER);
5664 SendSysMessage("-------------------------------------------------------------------------------");
5665 Field *fields = result->Fetch();
5666 uint32 account_id = fields[0].GetUInt32 ();
5668 std::string account_name;
5670 // "account" case, name can be get in same query
5671 if(result->GetFieldCount() > 1)
5672 account_name = fields[1].GetCppString();
5673 // "character" case, name need extract from another DB
5674 else
5675 accmgr.GetName (account_id,account_name);
5677 // No SQL injection. id is uint32.
5678 QueryResult *banInfo = loginDatabase.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id);
5679 if (banInfo)
5681 Field *fields2 = banInfo->Fetch();
5684 time_t t_ban = fields2[0].GetUInt64();
5685 tm* aTm_ban = localtime(&t_ban);
5687 if (fields2[0].GetUInt64() == fields2[1].GetUInt64())
5689 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5690 account_name.c_str(),aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min,
5691 fields2[2].GetString(),fields2[3].GetString());
5693 else
5695 time_t t_unban = fields2[1].GetUInt64();
5696 tm* aTm_unban = localtime(&t_unban);
5697 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5698 account_name.c_str(),aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min,
5699 aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
5700 fields2[2].GetString(),fields2[3].GetString());
5702 }while ( banInfo->NextRow() );
5703 delete banInfo;
5705 }while( result->NextRow() );
5706 SendSysMessage("===============================================================================");
5709 delete result;
5710 return true;
5713 bool ChatHandler::HandleBanListIPCommand(const char* args)
5715 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5717 char* cFilter = strtok((char*)args, " ");
5718 std::string filter = cFilter ? cFilter : "";
5719 loginDatabase.escape_string(filter);
5721 QueryResult* result;
5723 if(filter.empty())
5725 result = loginDatabase.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5726 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
5727 " ORDER BY unbandate" );
5729 else
5731 result = loginDatabase.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5732 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")
5733 " ORDER BY unbandate",filter.c_str() );
5736 if(!result)
5738 PSendSysMessage(LANG_BANLIST_NOIP);
5739 return true;
5742 PSendSysMessage(LANG_BANLIST_MATCHINGIP);
5743 // Chat short output
5744 if(m_session)
5748 Field* fields = result->Fetch();
5749 PSendSysMessage("%s",fields[0].GetString());
5750 } while (result->NextRow());
5752 // Console wide output
5753 else
5755 SendSysMessage(LANG_BANLIST_IPS);
5756 SendSysMessage("===============================================================================");
5757 SendSysMessage(LANG_BANLIST_IPS_HEADER);
5760 SendSysMessage("-------------------------------------------------------------------------------");
5761 Field *fields = result->Fetch();
5762 time_t t_ban = fields[1].GetUInt64();
5763 tm* aTm_ban = localtime(&t_ban);
5764 if ( fields[1].GetUInt64() == fields[2].GetUInt64() )
5766 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5767 fields[0].GetString(), aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min,
5768 fields[3].GetString(), fields[4].GetString());
5770 else
5772 time_t t_unban = fields[2].GetUInt64();
5773 tm* aTm_unban = localtime(&t_unban);
5774 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5775 fields[0].GetString(), aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min,
5776 aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
5777 fields[3].GetString(), fields[4].GetString());
5779 }while( result->NextRow() );
5780 SendSysMessage("===============================================================================");
5783 delete result;
5784 return true;
5787 bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
5789 Player* pl = m_session->GetPlayer();
5791 // accept only explicitly selected target (not implicitly self targeting case)
5792 Unit* target = getSelectedUnit();
5793 if(pl->GetSelection() && target)
5795 if(target->GetTypeId()!=TYPEID_UNIT)
5797 SendSysMessage(LANG_SELECT_CREATURE);
5798 SetSentErrorMessage(true);
5799 return false;
5802 if(target->isDead())
5803 ((Creature*)target)->Respawn();
5804 return true;
5807 CellPair p(MaNGOS::ComputeCellPair(pl->GetPositionX(), pl->GetPositionY()));
5808 Cell cell(p);
5809 cell.data.Part.reserved = ALL_DISTRICT;
5810 cell.SetNoCreate();
5812 MaNGOS::RespawnDo u_do;
5813 MaNGOS::WorldObjectWorker<MaNGOS::RespawnDo> worker(pl,u_do);
5815 TypeContainerVisitor<MaNGOS::WorldObjectWorker<MaNGOS::RespawnDo>, GridTypeMapContainer > obj_worker(worker);
5816 CellLock<GridReadGuard> cell_lock(cell, p);
5817 cell_lock->Visit(cell_lock, obj_worker, *pl->GetMap());
5819 return true;
5822 bool ChatHandler::HandleGMFlyCommand(const char* args)
5824 if (!*args)
5825 return false;
5827 Player *target = getSelectedPlayer();
5828 if (!target)
5829 target = m_session->GetPlayer();
5831 WorldPacket data(12);
5832 if (strncmp(args, "on", 3) == 0)
5833 data.SetOpcode(SMSG_MOVE_SET_CAN_FLY);
5834 else if (strncmp(args, "off", 4) == 0)
5835 data.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY);
5836 else
5838 SendSysMessage(LANG_USE_BOL);
5839 return false;
5841 data.append(target->GetPackGUID());
5842 data << uint32(0); // unknown
5843 target->SendMessageToSet(&data, true);
5844 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS, GetNameLink(target).c_str(), args);
5845 return true;
5848 bool ChatHandler::HandlePDumpLoadCommand(const char *args)
5850 if (!*args)
5851 return false;
5853 char * file = strtok((char*)args, " ");
5854 if(!file)
5855 return false;
5857 char * account = strtok(NULL, " ");
5858 if(!account)
5859 return false;
5861 std::string account_name = account;
5862 if(!AccountMgr::normilizeString(account_name))
5864 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5865 SetSentErrorMessage(true);
5866 return false;
5869 uint32 account_id = accmgr.GetId(account_name);
5870 if(!account_id)
5872 account_id = atoi(account); // use original string
5873 if(!account_id)
5875 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5876 SetSentErrorMessage(true);
5877 return false;
5881 if(!accmgr.GetName(account_id,account_name))
5883 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5884 SetSentErrorMessage(true);
5885 return false;
5888 char* guid_str = NULL;
5889 char* name_str = strtok(NULL, " ");
5891 std::string name;
5892 if(name_str)
5894 name = name_str;
5895 // normalize the name if specified and check if it exists
5896 if(!normalizePlayerName(name))
5898 PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
5899 SetSentErrorMessage(true);
5900 return false;
5903 if(!ObjectMgr::IsValidName(name,true))
5905 PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
5906 SetSentErrorMessage(true);
5907 return false;
5910 guid_str = strtok(NULL, " ");
5913 uint32 guid = 0;
5915 if(guid_str)
5917 guid = atoi(guid_str);
5918 if(!guid)
5920 PSendSysMessage(LANG_INVALID_CHARACTER_GUID);
5921 SetSentErrorMessage(true);
5922 return false;
5925 if(objmgr.GetPlayerAccountIdByGUID(guid))
5927 PSendSysMessage(LANG_CHARACTER_GUID_IN_USE,guid);
5928 SetSentErrorMessage(true);
5929 return false;
5933 switch(PlayerDumpReader().LoadDump(file, account_id, name, guid))
5935 case DUMP_SUCCESS:
5936 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS);
5937 break;
5938 case DUMP_FILE_OPEN_ERROR:
5939 PSendSysMessage(LANG_FILE_OPEN_FAIL,file);
5940 SetSentErrorMessage(true);
5941 return false;
5942 case DUMP_FILE_BROKEN:
5943 PSendSysMessage(LANG_DUMP_BROKEN,file);
5944 SetSentErrorMessage(true);
5945 return false;
5946 case DUMP_TOO_MANY_CHARS:
5947 PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL,account_name.c_str(),account_id);
5948 SetSentErrorMessage(true);
5949 return false;
5950 default:
5951 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED);
5952 SetSentErrorMessage(true);
5953 return false;
5956 return true;
5959 bool ChatHandler::HandlePDumpWriteCommand(const char *args)
5961 if (!*args)
5962 return false;
5964 char* file = strtok((char*)args, " ");
5965 char* p2 = strtok(NULL, " ");
5967 if(!file || !p2)
5968 return false;
5970 uint32 guid;
5971 // character name can't start from number
5972 if (isNumeric(p2[0]))
5973 guid = atoi(p2);
5974 else
5976 std::string name = extractPlayerNameFromLink(p2);
5977 if(name.empty())
5979 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5980 SetSentErrorMessage(true);
5981 return false;
5984 guid = objmgr.GetPlayerGUIDByName(name);
5987 if(!objmgr.GetPlayerAccountIdByGUID(guid))
5989 PSendSysMessage(LANG_PLAYER_NOT_FOUND);
5990 SetSentErrorMessage(true);
5991 return false;
5994 switch(PlayerDumpWriter().WriteDump(file, guid))
5996 case DUMP_SUCCESS:
5997 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS);
5998 break;
5999 case DUMP_FILE_OPEN_ERROR:
6000 PSendSysMessage(LANG_FILE_OPEN_FAIL,file);
6001 SetSentErrorMessage(true);
6002 return false;
6003 default:
6004 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED);
6005 SetSentErrorMessage(true);
6006 return false;
6009 return true;
6012 bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
6014 Unit* unit = getSelectedUnit();
6015 if(!unit)
6017 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
6018 SetSentErrorMessage(true);
6019 return false;
6022 PSendSysMessage(LANG_MOVEGENS_LIST,(unit->GetTypeId()==TYPEID_PLAYER ? "Player" : "Creature" ),unit->GetGUIDLow());
6024 MotionMaster* mm = unit->GetMotionMaster();
6025 for(MotionMaster::const_iterator itr = mm->begin(); itr != mm->end(); ++itr)
6027 switch((*itr)->GetMovementGeneratorType())
6029 case IDLE_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_IDLE); break;
6030 case RANDOM_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_RANDOM); break;
6031 case WAYPOINT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_WAYPOINT); break;
6032 case ANIMAL_RANDOM_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_ANIMAL_RANDOM); break;
6033 case CONFUSED_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_CONFUSED); break;
6034 case TARGETED_MOTION_TYPE:
6036 if(unit->GetTypeId()==TYPEID_PLAYER)
6038 TargetedMovementGenerator<Player> const* mgen = static_cast<TargetedMovementGenerator<Player> const*>(*itr);
6039 Unit* target = mgen->GetTarget();
6040 if(target)
6041 PSendSysMessage(LANG_MOVEGENS_TARGETED_PLAYER,target->GetName(),target->GetGUIDLow());
6042 else
6043 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL);
6045 else
6047 TargetedMovementGenerator<Creature> const* mgen = static_cast<TargetedMovementGenerator<Creature> const*>(*itr);
6048 Unit* target = mgen->GetTarget();
6049 if(target)
6050 PSendSysMessage(LANG_MOVEGENS_TARGETED_CREATURE,target->GetName(),target->GetGUIDLow());
6051 else
6052 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL);
6054 break;
6056 case HOME_MOTION_TYPE:
6057 if(unit->GetTypeId()==TYPEID_UNIT)
6059 float x,y,z;
6060 (*itr)->GetDestination(x,y,z);
6061 PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE,x,y,z);
6063 else
6064 SendSysMessage(LANG_MOVEGENS_HOME_PLAYER);
6065 break;
6066 case FLIGHT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FLIGHT); break;
6067 case POINT_MOTION_TYPE:
6069 float x,y,z;
6070 (*itr)->GetDestination(x,y,z);
6071 PSendSysMessage(LANG_MOVEGENS_POINT,x,y,z);
6072 break;
6074 case FLEEING_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FEAR); break;
6075 case DISTRACT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_DISTRACT); break;
6076 default:
6077 PSendSysMessage(LANG_MOVEGENS_UNKNOWN,(*itr)->GetMovementGeneratorType());
6078 break;
6081 return true;
6084 bool ChatHandler::HandleServerPLimitCommand(const char *args)
6086 if(*args)
6088 char* param = strtok((char*)args, " ");
6089 if(!param)
6090 return false;
6092 int l = strlen(param);
6094 if( strncmp(param,"player",l) == 0 )
6095 sWorld.SetPlayerLimit(-SEC_PLAYER);
6096 else if(strncmp(param,"moderator",l) == 0 )
6097 sWorld.SetPlayerLimit(-SEC_MODERATOR);
6098 else if(strncmp(param,"gamemaster",l) == 0 )
6099 sWorld.SetPlayerLimit(-SEC_GAMEMASTER);
6100 else if(strncmp(param,"administrator",l) == 0 )
6101 sWorld.SetPlayerLimit(-SEC_ADMINISTRATOR);
6102 else if(strncmp(param,"reset",l) == 0 )
6103 sWorld.SetPlayerLimit( sConfig.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT) );
6104 else
6106 int val = atoi(param);
6107 if(val < -SEC_ADMINISTRATOR) val = -SEC_ADMINISTRATOR;
6109 sWorld.SetPlayerLimit(val);
6112 // kick all low security level players
6113 if(sWorld.GetPlayerAmountLimit() > SEC_PLAYER)
6114 sWorld.KickAllLess(sWorld.GetPlayerSecurityLimit());
6117 uint32 pLimit = sWorld.GetPlayerAmountLimit();
6118 AccountTypes allowedAccountType = sWorld.GetPlayerSecurityLimit();
6119 char const* secName = "";
6120 switch(allowedAccountType)
6122 case SEC_PLAYER: secName = "Player"; break;
6123 case SEC_MODERATOR: secName = "Moderator"; break;
6124 case SEC_GAMEMASTER: secName = "Gamemaster"; break;
6125 case SEC_ADMINISTRATOR: secName = "Administrator"; break;
6126 default: secName = "<unknown>"; break;
6129 PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit,secName);
6131 return true;
6134 bool ChatHandler::HandleCastCommand(const char* args)
6136 if(!*args)
6137 return false;
6139 Unit* target = getSelectedUnit();
6141 if(!target)
6143 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
6144 SetSentErrorMessage(true);
6145 return false;
6148 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6149 uint32 spell = extractSpellIdFromLink((char*)args);
6150 if(!spell)
6151 return false;
6153 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
6154 if(!spellInfo)
6155 return false;
6157 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
6159 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
6160 SetSentErrorMessage(true);
6161 return false;
6164 char* trig_str = strtok(NULL, " ");
6165 if(trig_str)
6167 int l = strlen(trig_str);
6168 if(strncmp(trig_str,"triggered",l) != 0 )
6169 return false;
6172 bool triggered = (trig_str != NULL);
6174 m_session->GetPlayer()->CastSpell(target,spell,triggered);
6176 return true;
6179 bool ChatHandler::HandleCastBackCommand(const char* args)
6181 Creature* caster = getSelectedCreature();
6183 if(!caster)
6185 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
6186 SetSentErrorMessage(true);
6187 return false;
6190 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
6191 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6192 uint32 spell = extractSpellIdFromLink((char*)args);
6193 if(!spell || !sSpellStore.LookupEntry(spell))
6194 return false;
6196 char* trig_str = strtok(NULL, " ");
6197 if(trig_str)
6199 int l = strlen(trig_str);
6200 if(strncmp(trig_str,"triggered",l) != 0 )
6201 return false;
6204 bool triggered = (trig_str != NULL);
6206 // update orientation at server
6207 caster->SetOrientation(caster->GetAngle(m_session->GetPlayer()));
6209 // and client
6210 WorldPacket data;
6211 caster->BuildHeartBeatMsg(&data);
6212 caster->SendMessageToSet(&data,true);
6214 caster->CastSpell(m_session->GetPlayer(),spell,triggered);
6216 return true;
6219 bool ChatHandler::HandleCastDistCommand(const char* args)
6221 if(!*args)
6222 return false;
6224 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6225 uint32 spell = extractSpellIdFromLink((char*)args);
6226 if(!spell)
6227 return false;
6229 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
6230 if(!spellInfo)
6231 return false;
6233 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
6235 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
6236 SetSentErrorMessage(true);
6237 return false;
6240 char *distStr = strtok(NULL, " ");
6242 float dist = 0;
6244 if(distStr)
6245 sscanf(distStr, "%f", &dist);
6247 char* trig_str = strtok(NULL, " ");
6248 if(trig_str)
6250 int l = strlen(trig_str);
6251 if(strncmp(trig_str,"triggered",l) != 0 )
6252 return false;
6255 bool triggered = (trig_str != NULL);
6257 float x,y,z;
6258 m_session->GetPlayer()->GetClosePoint(x,y,z,dist);
6260 m_session->GetPlayer()->CastSpell(x,y,z,spell,triggered);
6261 return true;
6264 bool ChatHandler::HandleCastTargetCommand(const char* args)
6266 Creature* caster = getSelectedCreature();
6268 if(!caster)
6270 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
6271 SetSentErrorMessage(true);
6272 return false;
6275 if(!caster->getVictim())
6277 SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM);
6278 SetSentErrorMessage(true);
6279 return false;
6282 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6283 uint32 spell = extractSpellIdFromLink((char*)args);
6284 if(!spell || !sSpellStore.LookupEntry(spell))
6285 return false;
6287 char* trig_str = strtok(NULL, " ");
6288 if(trig_str)
6290 int l = strlen(trig_str);
6291 if(strncmp(trig_str,"triggered",l) != 0 )
6292 return false;
6295 bool triggered = (trig_str != NULL);
6297 // update orientation at server
6298 caster->SetOrientation(caster->GetAngle(m_session->GetPlayer()));
6300 // and client
6301 WorldPacket data;
6302 caster->BuildHeartBeatMsg(&data);
6303 caster->SendMessageToSet(&data,true);
6305 caster->CastSpell(caster->getVictim(),spell,triggered);
6307 return true;
6311 ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
6312 Without this function 3rd party scripting library will get linking errors (unresolved external)
6313 when attempting to use the PointMovementGenerator
6315 bool ChatHandler::HandleComeToMeCommand(const char *args)
6317 Creature* caster = getSelectedCreature();
6319 if(!caster)
6321 SendSysMessage(LANG_SELECT_CREATURE);
6322 SetSentErrorMessage(true);
6323 return false;
6326 char* newFlagStr = strtok((char*)args, " ");
6328 if(!newFlagStr)
6329 return false;
6331 uint32 newFlags = atoi(newFlagStr);
6333 caster->SetUnitMovementFlags(newFlags);
6335 Player* pl = m_session->GetPlayer();
6337 caster->GetMotionMaster()->MovePoint(0, pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ());
6338 return true;
6341 bool ChatHandler::HandleCastSelfCommand(const char* args)
6343 if(!*args)
6344 return false;
6346 Unit* target = getSelectedUnit();
6348 if(!target)
6350 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
6351 SetSentErrorMessage(true);
6352 return false;
6355 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6356 uint32 spell = extractSpellIdFromLink((char*)args);
6357 if(!spell)
6358 return false;
6360 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
6361 if(!spellInfo)
6362 return false;
6364 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
6366 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
6367 SetSentErrorMessage(true);
6368 return false;
6371 target->CastSpell(target,spell,false);
6373 return true;
6376 std::string GetTimeString(uint32 time)
6378 uint16 days = time / DAY, hours = (time % DAY) / HOUR, minute = (time % HOUR) / MINUTE;
6379 std::ostringstream ss;
6380 if(days) ss << days << "d ";
6381 if(hours) ss << hours << "h ";
6382 ss << minute << "m";
6383 return ss.str();
6386 bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
6388 Player* player = getSelectedPlayer();
6389 if (!player) player = m_session->GetPlayer();
6390 uint32 counter = 0;
6391 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; ++i)
6393 Player::BoundInstancesMap &binds = player->GetBoundInstances(i);
6394 for(Player::BoundInstancesMap::const_iterator itr = binds.begin(); itr != binds.end(); ++itr)
6396 InstanceSave *save = itr->second.save;
6397 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
6398 PSendSysMessage("map: %d inst: %d perm: %s diff: %s canReset: %s TTR: %s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty() == DIFFICULTY_NORMAL ? "normal" : "heroic", save->CanReset() ? "yes" : "no", timeleft.c_str());
6399 counter++;
6402 PSendSysMessage("player binds: %d", counter);
6403 counter = 0;
6404 Group *group = player->GetGroup();
6405 if(group)
6407 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; ++i)
6409 Group::BoundInstancesMap &binds = group->GetBoundInstances(i);
6410 for(Group::BoundInstancesMap::const_iterator itr = binds.begin(); itr != binds.end(); ++itr)
6412 InstanceSave *save = itr->second.save;
6413 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
6414 PSendSysMessage("map: %d inst: %d perm: %s diff: %s canReset: %s TTR: %s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty() == DIFFICULTY_NORMAL ? "normal" : "heroic", save->CanReset() ? "yes" : "no", timeleft.c_str());
6415 counter++;
6419 PSendSysMessage("group binds: %d", counter);
6421 return true;
6424 bool ChatHandler::HandleInstanceUnbindCommand(const char* args)
6426 if(!*args)
6427 return false;
6429 std::string cmd = args;
6430 if(cmd == "all")
6432 Player* player = getSelectedPlayer();
6433 if (!player) player = m_session->GetPlayer();
6434 uint32 counter = 0;
6435 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; ++i)
6437 Player::BoundInstancesMap &binds = player->GetBoundInstances(i);
6438 for(Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end();)
6440 if(itr->first != player->GetMapId())
6442 InstanceSave *save = itr->second.save;
6443 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
6444 PSendSysMessage("unbinding map: %d inst: %d perm: %s diff: %s canReset: %s TTR: %s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty() == DIFFICULTY_NORMAL ? "normal" : "heroic", save->CanReset() ? "yes" : "no", timeleft.c_str());
6445 player->UnbindInstance(itr, i);
6446 counter++;
6448 else
6449 ++itr;
6452 PSendSysMessage("instances unbound: %d", counter);
6454 return true;
6457 bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
6459 PSendSysMessage("instances loaded: %d", MapManager::Instance().GetNumInstances());
6460 PSendSysMessage("players in instances: %d", MapManager::Instance().GetNumPlayersInInstances());
6461 PSendSysMessage("instance saves: %d", sInstanceSaveManager.GetNumInstanceSaves());
6462 PSendSysMessage("players bound: %d", sInstanceSaveManager.GetNumBoundPlayersTotal());
6463 PSendSysMessage("groups bound: %d", sInstanceSaveManager.GetNumBoundGroupsTotal());
6464 return true;
6467 bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
6469 Player* pl = m_session->GetPlayer();
6471 Map* map = pl->GetMap();
6472 if (!map->IsDungeon())
6474 PSendSysMessage("Map is not a dungeon.");
6475 SetSentErrorMessage(true);
6476 return false;
6479 if (!((InstanceMap*)map)->GetInstanceData())
6481 PSendSysMessage("Map has no instance data.");
6482 SetSentErrorMessage(true);
6483 return false;
6486 ((InstanceMap*)map)->GetInstanceData()->SaveToDB();
6487 return true;
6490 /// Display the list of GMs
6491 bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
6493 ///- Get the accounts with GM Level >0
6494 QueryResult *result = loginDatabase.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
6495 if(result)
6497 SendSysMessage(LANG_GMLIST);
6498 SendSysMessage("========================");
6499 SendSysMessage(LANG_GMLIST_HEADER);
6500 SendSysMessage("========================");
6502 ///- Circle through them. Display username and GM level
6505 Field *fields = result->Fetch();
6506 PSendSysMessage("|%15s|%6s|", fields[0].GetString(),fields[1].GetString());
6507 }while( result->NextRow() );
6509 PSendSysMessage("========================");
6510 delete result;
6512 else
6513 PSendSysMessage(LANG_GMLIST_EMPTY);
6514 return true;
6517 /// Define the 'Message of the day' for the realm
6518 bool ChatHandler::HandleServerSetMotdCommand(const char* args)
6520 sWorld.SetMotd(args);
6521 PSendSysMessage(LANG_MOTD_NEW, args);
6522 return true;
6525 /// Set/Unset the expansion level for an account
6526 bool ChatHandler::HandleAccountSetAddonCommand(const char* args)
6528 ///- Get the command line arguments
6529 char *szAcc = strtok((char*)args," ");
6530 char *szExp = strtok(NULL," ");
6532 if(!szAcc)
6533 return false;
6535 std::string account_name;
6536 uint32 account_id;
6538 if(!szExp)
6540 Player* player = getSelectedPlayer();
6541 if(!player)
6542 return false;
6544 account_id = player->GetSession()->GetAccountId();
6545 accmgr.GetName(account_id,account_name);
6546 szExp = szAcc;
6548 else
6550 ///- Convert Account name to Upper Format
6551 account_name = szAcc;
6552 if(!AccountMgr::normilizeString(account_name))
6554 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
6555 SetSentErrorMessage(true);
6556 return false;
6559 account_id = accmgr.GetId(account_name);
6560 if(!account_id)
6562 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
6563 SetSentErrorMessage(true);
6564 return false;
6569 // Let set addon state only for lesser (strong) security level
6570 // or to self account
6571 if (m_session && m_session->GetAccountId () != account_id &&
6572 HasLowerSecurityAccount (NULL,account_id,true))
6573 return false;
6575 int lev=atoi(szExp); //get int anyway (0 if error)
6576 if(lev < 0)
6577 return false;
6579 // No SQL injection
6580 loginDatabase.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev,account_id);
6581 PSendSysMessage(LANG_ACCOUNT_SETADDON,account_name.c_str(),account_id,lev);
6582 return true;
6585 //Send items by mail
6586 bool ChatHandler::HandleSendItemsCommand(const char* args)
6588 if(!*args)
6589 return false;
6591 // format: name "subject text" "mail text" item1[:count1] item2[:count2] ... item12[:count12]
6593 std::string name = extractPlayerNameFromLink((char*)args);
6594 if(name.empty())
6596 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6597 SetSentErrorMessage(true);
6598 return false;
6601 char* tail1 = strtok(NULL, "");
6602 if(!tail1)
6603 return false;
6605 char* msgSubject;
6606 if(*tail1=='"')
6607 msgSubject = strtok(tail1+1, "\"");
6608 else
6610 char* space = strtok(tail1, "\"");
6611 if(!space)
6612 return false;
6613 msgSubject = strtok(NULL, "\"");
6616 if (!msgSubject)
6617 return false;
6619 char* tail2 = strtok(NULL, "");
6620 if(!tail2)
6621 return false;
6623 char* msgText;
6624 if(*tail2=='"')
6625 msgText = strtok(tail2+1, "\"");
6626 else
6628 char* space = strtok(tail2, "\"");
6629 if(!space)
6630 return false;
6631 msgText = strtok(NULL, "\"");
6634 if (!msgText)
6635 return false;
6637 // msgSubject, msgText isn't NUL after prev. check
6638 std::string subject = msgSubject;
6639 std::string text = msgText;
6641 // extract items
6642 typedef std::pair<uint32,uint32> ItemPair;
6643 typedef std::list< ItemPair > ItemPairs;
6644 ItemPairs items;
6646 // get all tail string
6647 char* tail = strtok(NULL, "");
6649 // get from tail next item str
6650 while(char* itemStr = strtok(tail, " "))
6652 // and get new tail
6653 tail = strtok(NULL, "");
6655 // parse item str
6656 char* itemIdStr = strtok(itemStr, ":");
6657 char* itemCountStr = strtok(NULL, " ");
6659 uint32 item_id = atoi(itemIdStr);
6660 if(!item_id)
6661 return false;
6663 ItemPrototype const* item_proto = objmgr.GetItemPrototype(item_id);
6664 if(!item_proto)
6666 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
6667 SetSentErrorMessage(true);
6668 return false;
6671 uint32 item_count = itemCountStr ? atoi(itemCountStr) : 1;
6672 if(item_count < 1 || item_proto->MaxCount > 0 && item_count > uint32(item_proto->MaxCount))
6674 PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT, item_count,item_id);
6675 SetSentErrorMessage(true);
6676 return false;
6679 while(item_count > item_proto->GetMaxStackSize())
6681 items.push_back(ItemPair(item_id,item_proto->GetMaxStackSize()));
6682 item_count -= item_proto->GetMaxStackSize();
6685 items.push_back(ItemPair(item_id,item_count));
6687 if(items.size() > MAX_MAIL_ITEMS)
6689 PSendSysMessage(LANG_COMMAND_MAIL_ITEMS_LIMIT, MAX_MAIL_ITEMS);
6690 SetSentErrorMessage(true);
6691 return false;
6695 uint64 receiver_guid = objmgr.GetPlayerGUIDByName(name);
6696 if(!receiver_guid)
6698 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6699 SetSentErrorMessage(true);
6700 return false;
6703 // from console show not existed sender
6704 uint32 sender_guidlo = m_session ? m_session->GetPlayer()->GetGUIDLow() : 0;
6706 uint32 messagetype = MAIL_NORMAL;
6707 uint32 stationery = MAIL_STATIONERY_GM;
6708 uint32 itemTextId = !text.empty() ? objmgr.CreateItemText( text ) : 0;
6710 Player *receiver = objmgr.GetPlayer(receiver_guid);
6712 // fill mail
6713 MailItemsInfo mi; // item list preparing
6715 for(ItemPairs::const_iterator itr = items.begin(); itr != items.end(); ++itr)
6717 if(Item* item = Item::CreateItem(itr->first,itr->second,m_session ? m_session->GetPlayer() : 0))
6719 item->SaveToDB(); // save for prevent lost at next mail load, if send fail then item will deleted
6720 mi.AddItem(item->GetGUIDLow(), item->GetEntry(), item);
6724 WorldSession::SendMailTo(receiver,messagetype, stationery, sender_guidlo, GUID_LOPART(receiver_guid), subject, itemTextId, &mi, 0, 0, MAIL_CHECK_MASK_NONE);
6726 std::string nameLink = playerLink(name);
6727 PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
6728 return true;
6731 ///Send money by mail
6732 bool ChatHandler::HandleSendMoneyCommand(const char* args)
6734 if (!*args)
6735 return false;
6737 /// format: name "subject text" "mail text" money
6739 std::string name = extractPlayerNameFromLink((char*)args);
6740 if(name.empty())
6742 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6743 SetSentErrorMessage(true);
6744 return false;
6747 char* tail1 = strtok(NULL, "");
6748 if (!tail1)
6749 return false;
6751 char* msgSubject;
6752 if (*tail1=='"')
6753 msgSubject = strtok(tail1+1, "\"");
6754 else
6756 char* space = strtok(tail1, "\"");
6757 if (!space)
6758 return false;
6759 msgSubject = strtok(NULL, "\"");
6762 if (!msgSubject)
6763 return false;
6765 char* tail2 = strtok(NULL, "");
6766 if (!tail2)
6767 return false;
6769 char* msgText;
6770 if (*tail2=='"')
6771 msgText = strtok(tail2+1, "\"");
6772 else
6774 char* space = strtok(tail2, "\"");
6775 if (!space)
6776 return false;
6777 msgText = strtok(NULL, "\"");
6780 if (!msgText)
6781 return false;
6783 char* money_str = strtok(NULL, "");
6784 int32 money = money_str ? atoi(money_str) : 0;
6785 if (money <= 0)
6786 return false;
6788 // msgSubject, msgText isn't NUL after prev. check
6789 std::string subject = msgSubject;
6790 std::string text = msgText;
6792 uint64 receiver_guid = objmgr.GetPlayerGUIDByName(name);
6793 if (!receiver_guid)
6795 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6796 SetSentErrorMessage(true);
6797 return false;
6800 // from console show not existed sender
6801 uint32 sender_guidlo = m_session ? m_session->GetPlayer()->GetGUIDLow() : 0;
6803 uint32 messagetype = MAIL_NORMAL;
6804 uint32 stationery = MAIL_STATIONERY_GM;
6805 uint32 itemTextId = !text.empty() ? objmgr.CreateItemText( text ) : 0;
6807 Player *receiver = objmgr.GetPlayer(receiver_guid);
6809 WorldSession::SendMailTo(receiver,messagetype, stationery, sender_guidlo, GUID_LOPART(receiver_guid), subject, itemTextId, NULL, money, 0, MAIL_CHECK_MASK_NONE);
6811 std::string nameLink = playerLink(name);
6812 PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
6813 return true;
6816 /// Send a message to a player in game
6817 bool ChatHandler::HandleSendMessageCommand(const char* args)
6819 ///- Get the command line arguments
6820 std::string name = extractPlayerNameFromLink((char*)args);
6821 if(name.empty())
6823 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6824 SetSentErrorMessage(true);
6825 return false;
6828 char* msg_str = strtok(NULL, "");
6829 if(!msg_str)
6830 return false;
6832 ///- Find the player and check that he is not logging out.
6833 Player *rPlayer = objmgr.GetPlayer(name.c_str());
6834 if(!rPlayer)
6836 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6837 SetSentErrorMessage(true);
6838 return false;
6841 if(rPlayer->GetSession()->isLogingOut())
6843 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6844 SetSentErrorMessage(true);
6845 return false;
6848 ///- Send the message
6849 //Use SendAreaTriggerMessage for fastest delivery.
6850 rPlayer->GetSession()->SendAreaTriggerMessage("%s", msg_str);
6851 rPlayer->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
6853 //Confirmation message
6854 std::string nameLink = playerLink(name);
6855 PSendSysMessage(LANG_SENDMESSAGE,nameLink.c_str(),msg_str);
6856 return true;
6859 bool ChatHandler::HandleFlushArenaPointsCommand(const char * /*args*/)
6861 sBattleGroundMgr.DistributeArenaPoints();
6862 return true;
6865 bool ChatHandler::HandleModifyGenderCommand(const char *args)
6867 if(!*args)
6868 return false;
6870 Player *player = getSelectedPlayer();
6872 if(!player)
6874 PSendSysMessage(LANG_PLAYER_NOT_FOUND);
6875 SetSentErrorMessage(true);
6876 return false;
6879 PlayerInfo const* info = objmgr.GetPlayerInfo(player->getRace(), player->getClass());
6880 if(!info)
6881 return false;
6883 char const* gender_str = (char*)args;
6884 int gender_len = strlen(gender_str);
6886 Gender gender;
6888 if(!strncmp(gender_str, "male", gender_len)) // MALE
6890 if(player->getGender() == GENDER_MALE)
6891 return true;
6893 gender = GENDER_MALE;
6895 else if (!strncmp(gender_str, "female", gender_len)) // FEMALE
6897 if(player->getGender() == GENDER_FEMALE)
6898 return true;
6900 gender = GENDER_FEMALE;
6902 else
6904 SendSysMessage(LANG_MUST_MALE_OR_FEMALE);
6905 SetSentErrorMessage(true);
6906 return false;
6909 // Set gender
6910 player->SetByteValue(UNIT_FIELD_BYTES_0, 2, gender);
6911 player->SetByteValue(PLAYER_BYTES_3, 0, gender);
6913 // Change display ID
6914 player->SetDisplayId(gender ? info->displayId_f : info->displayId_m);
6915 player->SetNativeDisplayId(gender ? info->displayId_f : info->displayId_m);
6917 char const* gender_full = gender ? "female" : "male";
6919 PSendSysMessage(LANG_YOU_CHANGE_GENDER, GetNameLink(player).c_str(), gender_full);
6921 if (needReportToTarget(player))
6922 ChatHandler(player).PSendSysMessage(LANG_YOUR_GENDER_CHANGED, gender_full, GetNameLink().c_str());
6924 return true;