[10082] Drop now unused dotconfpp lib code.
[getmangos.git] / src / game / Level3.cpp
blobe6abfb8b29c44a3d2a43fefa572e7e7f256448a6
1 /*
2 * Copyright (C) 2005-2010 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/Config.h"
47 #include "Mail.h"
48 #include "Util.h"
49 #include "ItemEnchantmentMgr.h"
50 #include "BattleGroundMgr.h"
51 #include "InstanceSaveMgr.h"
52 #include "InstanceData.h"
53 #include "CreatureEventAIMgr.h"
54 #include "DBCEnums.h"
56 //reload commands
57 bool ChatHandler::HandleReloadAllCommand(const char*)
59 HandleReloadSkillFishingBaseLevelCommand("");
61 HandleReloadAllAchievementCommand("");
62 HandleReloadAllAreaCommand("");
63 HandleReloadAllEventAICommand("");
64 HandleReloadAllLootCommand("");
65 HandleReloadAllNpcCommand("");
66 HandleReloadAllQuestCommand("");
67 HandleReloadAllSpellCommand("");
68 HandleReloadAllItemCommand("");
69 HandleReloadAllGossipsCommand("");
70 HandleReloadAllLocalesCommand("");
72 HandleReloadMailLevelRewardCommand("");
73 HandleReloadCommandCommand("");
74 HandleReloadReservedNameCommand("");
75 HandleReloadMangosStringCommand("");
76 HandleReloadGameTeleCommand("");
77 return true;
80 bool ChatHandler::HandleReloadAllAchievementCommand(const char*)
82 HandleReloadAchievementCriteriaRequirementCommand("");
83 HandleReloadAchievementRewardCommand("");
84 return true;
87 bool ChatHandler::HandleReloadAllAreaCommand(const char*)
89 //HandleReloadQuestAreaTriggersCommand(""); -- reloaded in HandleReloadAllQuestCommand
90 HandleReloadAreaTriggerTeleportCommand("");
91 HandleReloadAreaTriggerTavernCommand("");
92 HandleReloadGameGraveyardZoneCommand("");
93 return true;
96 bool ChatHandler::HandleReloadAllLootCommand(const char*)
98 sLog.outString( "Re-Loading Loot Tables..." );
99 LoadLootTables();
100 SendGlobalSysMessage("DB tables `*_loot_template` reloaded.");
101 return true;
104 bool ChatHandler::HandleReloadAllNpcCommand(const char* args)
106 if(*args!='a') // will be reloaded from all_gossips
107 HandleReloadNpcGossipCommand("a");
108 HandleReloadNpcTrainerCommand("a");
109 HandleReloadNpcVendorCommand("a");
110 HandleReloadPointsOfInterestCommand("a");
111 HandleReloadSpellClickSpellsCommand("a");
112 return true;
115 bool ChatHandler::HandleReloadAllQuestCommand(const char* /*args*/)
117 HandleReloadQuestAreaTriggersCommand("a");
118 HandleReloadQuestPOICommand("a");
119 HandleReloadQuestTemplateCommand("a");
121 sLog.outString( "Re-Loading Quests Relations..." );
122 sObjectMgr.LoadQuestRelations();
123 SendGlobalSysMessage("DB tables `*_questrelation` and `*_involvedrelation` reloaded.");
124 return true;
127 bool ChatHandler::HandleReloadAllScriptsCommand(const char*)
129 if(sWorld.IsScriptScheduled())
131 PSendSysMessage("DB scripts used currently, please attempt reload later.");
132 SetSentErrorMessage(true);
133 return false;
136 sLog.outString( "Re-Loading Scripts..." );
137 HandleReloadGameObjectScriptsCommand("a");
138 HandleReloadGossipScriptsCommand("a");
139 HandleReloadEventScriptsCommand("a");
140 HandleReloadQuestEndScriptsCommand("a");
141 HandleReloadQuestStartScriptsCommand("a");
142 HandleReloadSpellScriptsCommand("a");
143 SendGlobalSysMessage("DB tables `*_scripts` reloaded.");
144 HandleReloadDbScriptStringCommand("a");
145 return true;
148 bool ChatHandler::HandleReloadAllEventAICommand(const char*)
150 HandleReloadEventAITextsCommand("a");
151 HandleReloadEventAISummonsCommand("a");
152 HandleReloadEventAIScriptsCommand("a");
153 return true;
156 bool ChatHandler::HandleReloadAllSpellCommand(const char*)
158 HandleReloadSkillDiscoveryTemplateCommand("a");
159 HandleReloadSkillExtraItemTemplateCommand("a");
160 HandleReloadSpellAreaCommand("a");
161 HandleReloadSpellChainCommand("a");
162 HandleReloadSpellElixirCommand("a");
163 HandleReloadSpellLearnSpellCommand("a");
164 HandleReloadSpellProcEventCommand("a");
165 HandleReloadSpellBonusesCommand("a");
166 HandleReloadSpellProcItemEnchantCommand("a");
167 HandleReloadSpellScriptTargetCommand("a");
168 HandleReloadSpellTargetPositionCommand("a");
169 HandleReloadSpellThreatsCommand("a");
170 HandleReloadSpellPetAurasCommand("a");
171 return true;
174 bool ChatHandler::HandleReloadAllGossipsCommand(const char* args)
176 HandleReloadGossipMenuCommand("a");
177 HandleReloadGossipMenuOptionCommand("a");
178 if(*args!='a') // already reload from all_scripts
179 HandleReloadGossipScriptsCommand("a");
180 HandleReloadNpcGossipCommand("a");
181 HandleReloadPointsOfInterestCommand("a");
182 return true;
185 bool ChatHandler::HandleReloadAllItemCommand(const char*)
187 HandleReloadPageTextsCommand("a");
188 HandleReloadItemEnchantementsCommand("a");
189 HandleReloadItemRequiredTragetCommand("a");
190 return true;
193 bool ChatHandler::HandleReloadAllLocalesCommand(const char* /*args*/)
195 HandleReloadLocalesAchievementRewardCommand("a");
196 HandleReloadLocalesCreatureCommand("a");
197 HandleReloadLocalesGameobjectCommand("a");
198 HandleReloadLocalesGossipMenuOptionCommand("a");
199 HandleReloadLocalesItemCommand("a");
200 HandleReloadLocalesNpcTextCommand("a");
201 HandleReloadLocalesPageTextCommand("a");
202 HandleReloadLocalesPointsOfInterestCommand("a");
203 HandleReloadLocalesQuestCommand("a");
204 return true;
207 bool ChatHandler::HandleReloadConfigCommand(const char* /*args*/)
209 sLog.outString( "Re-Loading config settings..." );
210 sWorld.LoadConfigSettings(true);
211 sMapMgr.InitializeVisibilityDistanceInfo();
212 SendGlobalSysMessage("World config settings reloaded.");
213 return true;
216 bool ChatHandler::HandleReloadAchievementCriteriaRequirementCommand(const char*)
218 sLog.outString( "Re-Loading Additional Achievement Criteria Requirements Data..." );
219 sAchievementMgr.LoadAchievementCriteriaRequirements();
220 SendGlobalSysMessage("DB table `achievement_criteria_requirement` reloaded.");
221 return true;
224 bool ChatHandler::HandleReloadAchievementRewardCommand(const char*)
226 sLog.outString( "Re-Loading Achievement Reward Data..." );
227 sAchievementMgr.LoadRewards();
228 SendGlobalSysMessage("DB table `achievement_reward` reloaded.");
229 return true;
232 bool ChatHandler::HandleReloadAreaTriggerTavernCommand(const char*)
234 sLog.outString( "Re-Loading Tavern Area Triggers..." );
235 sObjectMgr.LoadTavernAreaTriggers();
236 SendGlobalSysMessage("DB table `areatrigger_tavern` reloaded.");
237 return true;
240 bool ChatHandler::HandleReloadAreaTriggerTeleportCommand(const char*)
242 sLog.outString( "Re-Loading AreaTrigger teleport definitions..." );
243 sObjectMgr.LoadAreaTriggerTeleports();
244 SendGlobalSysMessage("DB table `areatrigger_teleport` reloaded.");
245 return true;
248 bool ChatHandler::HandleReloadCommandCommand(const char*)
250 load_command_table = true;
251 SendGlobalSysMessage("DB table `command` will be reloaded at next chat command use.");
252 return true;
255 bool ChatHandler::HandleReloadCreatureQuestRelationsCommand(const char*)
257 sLog.outString( "Loading Quests Relations... (`creature_questrelation`)" );
258 sObjectMgr.LoadCreatureQuestRelations();
259 SendGlobalSysMessage("DB table `creature_questrelation` (creature quest givers) reloaded.");
260 return true;
263 bool ChatHandler::HandleReloadCreatureQuestInvRelationsCommand(const char*)
265 sLog.outString( "Loading Quests Relations... (`creature_involvedrelation`)" );
266 sObjectMgr.LoadCreatureInvolvedRelations();
267 SendGlobalSysMessage("DB table `creature_involvedrelation` (creature quest takers) reloaded.");
268 return true;
271 bool ChatHandler::HandleReloadGossipMenuCommand(const char*)
273 sLog.outString( "Re-Loading `gossip_menu` Table!" );
274 sObjectMgr.LoadGossipMenu();
275 SendGlobalSysMessage("DB table `gossip_menu` reloaded.");
276 return true;
279 bool ChatHandler::HandleReloadGossipMenuOptionCommand(const char*)
281 sLog.outString( "Re-Loading `gossip_menu_option` Table!" );
282 sObjectMgr.LoadGossipMenuItems();
283 SendGlobalSysMessage("DB table `gossip_menu_option` reloaded.");
284 return true;
287 bool ChatHandler::HandleReloadGossipScriptsCommand(const char* arg)
289 if(sWorld.IsScriptScheduled())
291 SendSysMessage("DB scripts used currently, please attempt reload later.");
292 SetSentErrorMessage(true);
293 return false;
296 if(*arg!='a')
297 sLog.outString( "Re-Loading Scripts from `gossip_scripts`...");
299 sObjectMgr.LoadGossipScripts();
301 if(*arg!='a')
302 SendGlobalSysMessage("DB table `gossip_scripts` reloaded.");
304 return true;
307 bool ChatHandler::HandleReloadGOQuestRelationsCommand(const char*)
309 sLog.outString( "Loading Quests Relations... (`gameobject_questrelation`)" );
310 sObjectMgr.LoadGameobjectQuestRelations();
311 SendGlobalSysMessage("DB table `gameobject_questrelation` (gameobject quest givers) reloaded.");
312 return true;
315 bool ChatHandler::HandleReloadGOQuestInvRelationsCommand(const char*)
317 sLog.outString( "Loading Quests Relations... (`gameobject_involvedrelation`)" );
318 sObjectMgr.LoadGameobjectInvolvedRelations();
319 SendGlobalSysMessage("DB table `gameobject_involvedrelation` (gameobject quest takers) reloaded.");
320 return true;
323 bool ChatHandler::HandleReloadQuestAreaTriggersCommand(const char*)
325 sLog.outString( "Re-Loading Quest Area Triggers..." );
326 sObjectMgr.LoadQuestAreaTriggers();
327 SendGlobalSysMessage("DB table `areatrigger_involvedrelation` (quest area triggers) reloaded.");
328 return true;
331 bool ChatHandler::HandleReloadQuestTemplateCommand(const char*)
333 sLog.outString( "Re-Loading Quest Templates..." );
334 sObjectMgr.LoadQuests();
335 SendGlobalSysMessage("DB table `quest_template` (quest definitions) reloaded.");
337 /// dependent also from `gameobject` but this table not reloaded anyway
338 sLog.outString( "Re-Loading GameObjects for quests..." );
339 sObjectMgr.LoadGameObjectForQuests();
340 SendGlobalSysMessage("Data GameObjects for quests reloaded.");
341 return true;
344 bool ChatHandler::HandleReloadLootTemplatesCreatureCommand(const char*)
346 sLog.outString( "Re-Loading Loot Tables... (`creature_loot_template`)" );
347 LoadLootTemplates_Creature();
348 LootTemplates_Creature.CheckLootRefs();
349 SendGlobalSysMessage("DB table `creature_loot_template` reloaded.");
350 return true;
353 bool ChatHandler::HandleReloadLootTemplatesDisenchantCommand(const char*)
355 sLog.outString( "Re-Loading Loot Tables... (`disenchant_loot_template`)" );
356 LoadLootTemplates_Disenchant();
357 LootTemplates_Disenchant.CheckLootRefs();
358 SendGlobalSysMessage("DB table `disenchant_loot_template` reloaded.");
359 return true;
362 bool ChatHandler::HandleReloadLootTemplatesFishingCommand(const char*)
364 sLog.outString( "Re-Loading Loot Tables... (`fishing_loot_template`)" );
365 LoadLootTemplates_Fishing();
366 LootTemplates_Fishing.CheckLootRefs();
367 SendGlobalSysMessage("DB table `fishing_loot_template` reloaded.");
368 return true;
371 bool ChatHandler::HandleReloadLootTemplatesGameobjectCommand(const char*)
373 sLog.outString( "Re-Loading Loot Tables... (`gameobject_loot_template`)" );
374 LoadLootTemplates_Gameobject();
375 LootTemplates_Gameobject.CheckLootRefs();
376 SendGlobalSysMessage("DB table `gameobject_loot_template` reloaded.");
377 return true;
380 bool ChatHandler::HandleReloadLootTemplatesItemCommand(const char*)
382 sLog.outString( "Re-Loading Loot Tables... (`item_loot_template`)" );
383 LoadLootTemplates_Item();
384 LootTemplates_Item.CheckLootRefs();
385 SendGlobalSysMessage("DB table `item_loot_template` reloaded.");
386 return true;
389 bool ChatHandler::HandleReloadLootTemplatesMillingCommand(const char*)
391 sLog.outString( "Re-Loading Loot Tables... (`milling_loot_template`)" );
392 LoadLootTemplates_Milling();
393 LootTemplates_Milling.CheckLootRefs();
394 SendGlobalSysMessage("DB table `milling_loot_template` reloaded.");
395 return true;
398 bool ChatHandler::HandleReloadLootTemplatesPickpocketingCommand(const char*)
400 sLog.outString( "Re-Loading Loot Tables... (`pickpocketing_loot_template`)" );
401 LoadLootTemplates_Pickpocketing();
402 LootTemplates_Pickpocketing.CheckLootRefs();
403 SendGlobalSysMessage("DB table `pickpocketing_loot_template` reloaded.");
404 return true;
407 bool ChatHandler::HandleReloadLootTemplatesProspectingCommand(const char*)
409 sLog.outString( "Re-Loading Loot Tables... (`prospecting_loot_template`)" );
410 LoadLootTemplates_Prospecting();
411 LootTemplates_Prospecting.CheckLootRefs();
412 SendGlobalSysMessage("DB table `prospecting_loot_template` reloaded.");
413 return true;
416 bool ChatHandler::HandleReloadLootTemplatesMailCommand(const char*)
418 sLog.outString( "Re-Loading Loot Tables... (`mail_loot_template`)" );
419 LoadLootTemplates_Mail();
420 LootTemplates_Mail.CheckLootRefs();
421 SendGlobalSysMessage("DB table `mail_loot_template` reloaded.");
422 return true;
425 bool ChatHandler::HandleReloadLootTemplatesReferenceCommand(const char*)
427 sLog.outString( "Re-Loading Loot Tables... (`reference_loot_template`)" );
428 LoadLootTemplates_Reference();
429 SendGlobalSysMessage("DB table `reference_loot_template` reloaded.");
430 return true;
433 bool ChatHandler::HandleReloadLootTemplatesSkinningCommand(const char*)
435 sLog.outString( "Re-Loading Loot Tables... (`skinning_loot_template`)" );
436 LoadLootTemplates_Skinning();
437 LootTemplates_Skinning.CheckLootRefs();
438 SendGlobalSysMessage("DB table `skinning_loot_template` reloaded.");
439 return true;
442 bool ChatHandler::HandleReloadLootTemplatesSpellCommand(const char*)
444 sLog.outString( "Re-Loading Loot Tables... (`spell_loot_template`)" );
445 LoadLootTemplates_Spell();
446 LootTemplates_Spell.CheckLootRefs();
447 SendGlobalSysMessage("DB table `spell_loot_template` reloaded.");
448 return true;
451 bool ChatHandler::HandleReloadMangosStringCommand(const char*)
453 sLog.outString( "Re-Loading mangos_string Table!" );
454 sObjectMgr.LoadMangosStrings();
455 SendGlobalSysMessage("DB table `mangos_string` reloaded.");
456 return true;
459 bool ChatHandler::HandleReloadNpcGossipCommand(const char*)
461 sLog.outString( "Re-Loading `npc_gossip` Table!" );
462 sObjectMgr.LoadNpcTextId();
463 SendGlobalSysMessage("DB table `npc_gossip` reloaded.");
464 return true;
467 bool ChatHandler::HandleReloadNpcTrainerCommand(const char*)
469 sLog.outString( "Re-Loading `npc_trainer` Table!" );
470 sObjectMgr.LoadTrainerSpell();
471 SendGlobalSysMessage("DB table `npc_trainer` reloaded.");
472 return true;
475 bool ChatHandler::HandleReloadNpcVendorCommand(const char*)
477 sLog.outString( "Re-Loading `npc_vendor` Table!" );
478 sObjectMgr.LoadVendors();
479 SendGlobalSysMessage("DB table `npc_vendor` reloaded.");
480 return true;
483 bool ChatHandler::HandleReloadPointsOfInterestCommand(const char*)
485 sLog.outString( "Re-Loading `points_of_interest` Table!" );
486 sObjectMgr.LoadPointsOfInterest();
487 SendGlobalSysMessage("DB table `points_of_interest` reloaded.");
488 return true;
491 bool ChatHandler::HandleReloadQuestPOICommand(const char*)
493 sLog.outString( "Re-Loading `quest_poi` and `quest_poi_points` Tables!" );
494 sObjectMgr.LoadQuestPOI();
495 SendGlobalSysMessage("DB Table `quest_poi` and `quest_poi_points` reloaded.");
496 return true;
499 bool ChatHandler::HandleReloadSpellClickSpellsCommand(const char*)
501 sLog.outString( "Re-Loading `npc_spellclick_spells` Table!" );
502 sObjectMgr.LoadNPCSpellClickSpells();
503 SendGlobalSysMessage("DB table `npc_spellclick_spells` reloaded.");
504 return true;
507 bool ChatHandler::HandleReloadReservedNameCommand(const char*)
509 sLog.outString( "Loading ReservedNames... (`reserved_name`)" );
510 sObjectMgr.LoadReservedPlayersNames();
511 SendGlobalSysMessage("DB table `reserved_name` (player reserved names) reloaded.");
512 return true;
515 bool ChatHandler::HandleReloadSkillDiscoveryTemplateCommand(const char* /*args*/)
517 sLog.outString( "Re-Loading Skill Discovery Table..." );
518 LoadSkillDiscoveryTable();
519 SendGlobalSysMessage("DB table `skill_discovery_template` (recipes discovered at crafting) reloaded.");
520 return true;
523 bool ChatHandler::HandleReloadSkillExtraItemTemplateCommand(const char* /*args*/)
525 sLog.outString( "Re-Loading Skill Extra Item Table..." );
526 LoadSkillExtraItemTable();
527 SendGlobalSysMessage("DB table `skill_extra_item_template` (extra item creation when crafting) reloaded.");
528 return true;
531 bool ChatHandler::HandleReloadSkillFishingBaseLevelCommand(const char* /*args*/)
533 sLog.outString( "Re-Loading Skill Fishing base level requirements..." );
534 sObjectMgr.LoadFishingBaseSkillLevel();
535 SendGlobalSysMessage("DB table `skill_fishing_base_level` (fishing base level for zone/subzone) reloaded.");
536 return true;
539 bool ChatHandler::HandleReloadSpellAreaCommand(const char*)
541 sLog.outString( "Re-Loading SpellArea Data..." );
542 sSpellMgr.LoadSpellAreas();
543 SendGlobalSysMessage("DB table `spell_area` (spell dependences from area/quest/auras state) reloaded.");
544 return true;
547 bool ChatHandler::HandleReloadSpellChainCommand(const char*)
549 sLog.outString( "Re-Loading Spell Chain Data... " );
550 sSpellMgr.LoadSpellChains();
551 SendGlobalSysMessage("DB table `spell_chain` (spell ranks) reloaded.");
552 return true;
555 bool ChatHandler::HandleReloadSpellElixirCommand(const char*)
557 sLog.outString( "Re-Loading Spell Elixir types..." );
558 sSpellMgr.LoadSpellElixirs();
559 SendGlobalSysMessage("DB table `spell_elixir` (spell elixir types) reloaded.");
560 return true;
563 bool ChatHandler::HandleReloadSpellLearnSpellCommand(const char*)
565 sLog.outString( "Re-Loading Spell Learn Spells..." );
566 sSpellMgr.LoadSpellLearnSpells();
567 SendGlobalSysMessage("DB table `spell_learn_spell` reloaded.");
568 return true;
571 bool ChatHandler::HandleReloadSpellProcEventCommand(const char*)
573 sLog.outString( "Re-Loading Spell Proc Event conditions..." );
574 sSpellMgr.LoadSpellProcEvents();
575 SendGlobalSysMessage("DB table `spell_proc_event` (spell proc trigger requirements) reloaded.");
576 return true;
579 bool ChatHandler::HandleReloadSpellBonusesCommand(const char*)
581 sLog.outString( "Re-Loading Spell Bonus Data..." );
582 sSpellMgr.LoadSpellBonuses();
583 SendGlobalSysMessage("DB table `spell_bonus_data` (spell damage/healing coefficients) reloaded.");
584 return true;
587 bool ChatHandler::HandleReloadSpellProcItemEnchantCommand(const char*)
589 sLog.outString( "Re-Loading Spell Proc Item Enchant..." );
590 sSpellMgr.LoadSpellProcItemEnchant();
591 SendGlobalSysMessage("DB table `spell_proc_item_enchant` (item enchantment ppm) reloaded.");
592 return true;
595 bool ChatHandler::HandleReloadSpellScriptTargetCommand(const char*)
597 sLog.outString( "Re-Loading SpellsScriptTarget..." );
598 sSpellMgr.LoadSpellScriptTarget();
599 SendGlobalSysMessage("DB table `spell_script_target` (spell targets selection in case specific creature/GO requirements) reloaded.");
600 return true;
603 bool ChatHandler::HandleReloadSpellTargetPositionCommand(const char*)
605 sLog.outString( "Re-Loading Spell target coordinates..." );
606 sSpellMgr.LoadSpellTargetPositions();
607 SendGlobalSysMessage("DB table `spell_target_position` (destination coordinates for spell targets) reloaded.");
608 return true;
611 bool ChatHandler::HandleReloadSpellThreatsCommand(const char*)
613 sLog.outString( "Re-Loading Aggro Spells Definitions...");
614 sSpellMgr.LoadSpellThreats();
615 SendGlobalSysMessage("DB table `spell_threat` (spell aggro definitions) reloaded.");
616 return true;
619 bool ChatHandler::HandleReloadSpellPetAurasCommand(const char*)
621 sLog.outString( "Re-Loading Spell pet auras...");
622 sSpellMgr.LoadSpellPetAuras();
623 SendGlobalSysMessage("DB table `spell_pet_auras` reloaded.");
624 return true;
627 bool ChatHandler::HandleReloadPageTextsCommand(const char*)
629 sLog.outString( "Re-Loading Page Texts..." );
630 sObjectMgr.LoadPageTexts();
631 SendGlobalSysMessage("DB table `page_texts` reloaded.");
632 return true;
635 bool ChatHandler::HandleReloadItemEnchantementsCommand(const char*)
637 sLog.outString( "Re-Loading Item Random Enchantments Table..." );
638 LoadRandomEnchantmentsTable();
639 SendGlobalSysMessage("DB table `item_enchantment_template` reloaded.");
640 return true;
643 bool ChatHandler::HandleReloadItemRequiredTragetCommand(const char*)
645 sLog.outString( "Re-Loading Item Required Targets Table..." );
646 sObjectMgr.LoadItemRequiredTarget();
647 SendGlobalSysMessage("DB table `item_required_target` reloaded.");
648 return true;
651 bool ChatHandler::HandleReloadBattleEventCommand(const char*)
653 sLog.outString( "Re-Loading BattleGround Eventindexes..." );
654 sBattleGroundMgr.LoadBattleEventIndexes();
655 SendGlobalSysMessage("DB table `gameobject_battleground` and `creature_battleground` reloaded.");
656 return true;
659 bool ChatHandler::HandleReloadGameObjectScriptsCommand(const char* arg)
661 if(sWorld.IsScriptScheduled())
663 SendSysMessage("DB scripts used currently, please attempt reload later.");
664 SetSentErrorMessage(true);
665 return false;
668 if(*arg!='a')
669 sLog.outString( "Re-Loading Scripts from `gameobject_scripts`...");
671 sObjectMgr.LoadGameObjectScripts();
673 if(*arg!='a')
674 SendGlobalSysMessage("DB table `gameobject_scripts` reloaded.");
676 return true;
679 bool ChatHandler::HandleReloadEventScriptsCommand(const char* arg)
681 if(sWorld.IsScriptScheduled())
683 SendSysMessage("DB scripts used currently, please attempt reload later.");
684 SetSentErrorMessage(true);
685 return false;
688 if(*arg!='a')
689 sLog.outString( "Re-Loading Scripts from `event_scripts`...");
691 sObjectMgr.LoadEventScripts();
693 if(*arg!='a')
694 SendGlobalSysMessage("DB table `event_scripts` reloaded.");
696 return true;
699 bool ChatHandler::HandleReloadEventAITextsCommand(const char* /*arg*/)
702 sLog.outString( "Re-Loading Texts from `creature_ai_texts`...");
703 sEventAIMgr.LoadCreatureEventAI_Texts(true);
704 SendGlobalSysMessage("DB table `creature_ai_texts` reloaded.");
705 return true;
708 bool ChatHandler::HandleReloadEventAISummonsCommand(const char* /*arg*/)
710 sLog.outString( "Re-Loading Summons from `creature_ai_summons`...");
711 sEventAIMgr.LoadCreatureEventAI_Summons(true);
712 SendGlobalSysMessage("DB table `creature_ai_summons` reloaded.");
713 return true;
716 bool ChatHandler::HandleReloadEventAIScriptsCommand(const char* /*arg*/)
718 sLog.outString( "Re-Loading Scripts from `creature_ai_scripts`...");
719 sEventAIMgr.LoadCreatureEventAI_Scripts();
720 SendGlobalSysMessage("DB table `creature_ai_scripts` reloaded.");
721 return true;
724 bool ChatHandler::HandleReloadQuestEndScriptsCommand(const char* arg)
726 if(sWorld.IsScriptScheduled())
728 SendSysMessage("DB scripts used currently, please attempt reload later.");
729 SetSentErrorMessage(true);
730 return false;
733 if(*arg!='a')
734 sLog.outString( "Re-Loading Scripts from `quest_end_scripts`...");
736 sObjectMgr.LoadQuestEndScripts();
738 if(*arg!='a')
739 SendGlobalSysMessage("DB table `quest_end_scripts` reloaded.");
741 return true;
744 bool ChatHandler::HandleReloadQuestStartScriptsCommand(const char* arg)
746 if(sWorld.IsScriptScheduled())
748 SendSysMessage("DB scripts used currently, please attempt reload later.");
749 SetSentErrorMessage(true);
750 return false;
753 if(*arg!='a')
754 sLog.outString( "Re-Loading Scripts from `quest_start_scripts`...");
756 sObjectMgr.LoadQuestStartScripts();
758 if(*arg!='a')
759 SendGlobalSysMessage("DB table `quest_start_scripts` reloaded.");
761 return true;
764 bool ChatHandler::HandleReloadSpellScriptsCommand(const char* arg)
766 if(sWorld.IsScriptScheduled())
768 SendSysMessage("DB scripts used currently, please attempt reload later.");
769 SetSentErrorMessage(true);
770 return false;
773 if(*arg!='a')
774 sLog.outString( "Re-Loading Scripts from `spell_scripts`...");
776 sObjectMgr.LoadSpellScripts();
778 if(*arg!='a')
779 SendGlobalSysMessage("DB table `spell_scripts` reloaded.");
781 return true;
784 bool ChatHandler::HandleReloadDbScriptStringCommand(const char* /*arg*/)
786 sLog.outString( "Re-Loading Script strings from `db_script_string`...");
787 sObjectMgr.LoadDbScriptStrings();
788 SendGlobalSysMessage("DB table `db_script_string` reloaded.");
789 return true;
792 bool ChatHandler::HandleReloadGameGraveyardZoneCommand(const char* /*arg*/)
794 sLog.outString( "Re-Loading Graveyard-zone links...");
796 sObjectMgr.LoadGraveyardZones();
798 SendGlobalSysMessage("DB table `game_graveyard_zone` reloaded.");
800 return true;
803 bool ChatHandler::HandleReloadGameTeleCommand(const char* /*arg*/)
805 sLog.outString( "Re-Loading Game Tele coordinates...");
807 sObjectMgr.LoadGameTele();
809 SendGlobalSysMessage("DB table `game_tele` reloaded.");
811 return true;
814 bool ChatHandler::HandleReloadLocalesAchievementRewardCommand(const char*)
816 sLog.outString( "Re-Loading Locales Achievement Reward Data..." );
817 sAchievementMgr.LoadRewardLocales();
818 SendGlobalSysMessage("DB table `locales_achievement_reward` reloaded.");
819 return true;
822 bool ChatHandler::HandleReloadLocalesCreatureCommand(const char* /*arg*/)
824 sLog.outString( "Re-Loading Locales Creature ...");
825 sObjectMgr.LoadCreatureLocales();
826 SendGlobalSysMessage("DB table `locales_creature` reloaded.");
827 return true;
830 bool ChatHandler::HandleReloadLocalesGameobjectCommand(const char* /*arg*/)
832 sLog.outString( "Re-Loading Locales Gameobject ... ");
833 sObjectMgr.LoadGameObjectLocales();
834 SendGlobalSysMessage("DB table `locales_gameobject` reloaded.");
835 return true;
838 bool ChatHandler::HandleReloadLocalesGossipMenuOptionCommand(const char* /*arg*/)
840 sLog.outString( "Re-Loading Locales Gossip Menu Option ... ");
841 sObjectMgr.LoadGossipMenuItemsLocales();
842 SendGlobalSysMessage("DB table `locales_gossip_menu_option` reloaded.");
843 return true;
846 bool ChatHandler::HandleReloadLocalesItemCommand(const char* /*arg*/)
848 sLog.outString( "Re-Loading Locales Item ... ");
849 sObjectMgr.LoadItemLocales();
850 SendGlobalSysMessage("DB table `locales_item` reloaded.");
851 return true;
854 bool ChatHandler::HandleReloadLocalesNpcTextCommand(const char* /*arg*/)
856 sLog.outString( "Re-Loading Locales NPC Text ... ");
857 sObjectMgr.LoadNpcTextLocales();
858 SendGlobalSysMessage("DB table `locales_npc_text` reloaded.");
859 return true;
862 bool ChatHandler::HandleReloadLocalesPageTextCommand(const char* /*arg*/)
864 sLog.outString( "Re-Loading Locales Page Text ... ");
865 sObjectMgr.LoadPageTextLocales();
866 SendGlobalSysMessage("DB table `locales_page_text` reloaded.");
867 return true;
870 bool ChatHandler::HandleReloadLocalesPointsOfInterestCommand(const char* /*arg*/)
872 sLog.outString( "Re-Loading Locales Points Of Interest ... ");
873 sObjectMgr.LoadPointOfInterestLocales();
874 SendGlobalSysMessage("DB table `locales_points_of_interest` reloaded.");
875 return true;
878 bool ChatHandler::HandleReloadLocalesQuestCommand(const char* /*arg*/)
880 sLog.outString( "Re-Loading Locales Quest ... ");
881 sObjectMgr.LoadQuestLocales();
882 SendGlobalSysMessage("DB table `locales_quest` reloaded.");
883 return true;
886 bool ChatHandler::HandleReloadMailLevelRewardCommand(const char* /*arg*/)
888 sLog.outString( "Re-Loading Player level dependent mail rewards..." );
889 sObjectMgr.LoadMailLevelRewards();
890 SendGlobalSysMessage("DB table `mail_level_reward` reloaded.");
891 return true;
894 bool ChatHandler::HandleLoadScriptsCommand(const char* args)
896 if(!LoadScriptingModule(args)) return true;
898 sWorld.SendWorldText(LANG_SCRIPTS_RELOADED);
899 return true;
902 bool ChatHandler::HandleAccountSetGmLevelCommand(const char* args)
904 char* arg1;
905 char* arg2;
907 extractOptFirstArg((char*)args, &arg1, &arg2);
909 std::string targetAccountName;
910 Player* targetPlayer = NULL;
911 uint32 targetAccountId = extractAccountId(arg1,&targetAccountName,&targetPlayer);
912 if (!targetAccountId)
913 return false;
915 /// only target player different from self allowed
916 if (GetAccountId() == targetAccountId)
917 return false;
919 int32 gm = (int32)atoi(arg2);
920 if ( gm < SEC_PLAYER || gm > SEC_ADMINISTRATOR )
922 SendSysMessage(LANG_BAD_VALUE);
923 SetSentErrorMessage(true);
924 return false;
927 /// can set security level only for target with less security and to less security that we have
928 /// This will reject self apply by specify account name
929 if(HasLowerSecurityAccount(NULL,targetAccountId,true))
930 return false;
932 /// account can't set security to same or grater level, need more power GM or console
933 AccountTypes plSecurity = GetAccessLevel();
934 if (AccountTypes(gm) >= plSecurity )
936 SendSysMessage(LANG_YOURS_SECURITY_IS_LOW);
937 SetSentErrorMessage(true);
938 return false;
941 if (targetPlayer)
943 ChatHandler(targetPlayer).PSendSysMessage(LANG_YOURS_SECURITY_CHANGED,GetNameLink().c_str(), gm);
944 targetPlayer->GetSession()->SetSecurity(AccountTypes(gm));
947 PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetAccountName.c_str(), gm);
948 loginDatabase.PExecute("UPDATE account SET gmlevel = '%i' WHERE id = '%u'", gm, targetAccountId);
950 return true;
953 /// Set password for account
954 bool ChatHandler::HandleAccountSetPasswordCommand(const char* args)
956 if(!*args)
957 return false;
959 ///- Get the command line arguments
960 std::string account_name;
961 uint32 targetAccountId = extractAccountId((char*)args, &account_name);
962 if (!targetAccountId)
963 return false;
965 char *szPassword1 = strtok (NULL," ");
966 char *szPassword2 = strtok (NULL," ");
967 if (!szPassword1 || !szPassword2)
968 return false;
970 /// can set password only for target with less security
971 /// This is also reject self apply in fact
972 if(HasLowerSecurityAccount (NULL,targetAccountId,true))
973 return false;
975 if (strcmp(szPassword1,szPassword2))
977 SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH);
978 SetSentErrorMessage (true);
979 return false;
982 AccountOpResult result = sAccountMgr.ChangePassword(targetAccountId, szPassword1);
984 switch(result)
986 case AOR_OK:
987 SendSysMessage(LANG_COMMAND_PASSWORD);
988 break;
989 case AOR_NAME_NOT_EXIST:
990 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
991 SetSentErrorMessage(true);
992 return false;
993 case AOR_PASS_TOO_LONG:
994 SendSysMessage(LANG_PASSWORD_TOO_LONG);
995 SetSentErrorMessage(true);
996 return false;
997 default:
998 SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD);
999 SetSentErrorMessage(true);
1000 return false;
1003 return true;
1006 bool ChatHandler::HandleMaxSkillCommand(const char* /*args*/)
1008 Player* SelectedPlayer = getSelectedPlayer();
1009 if(!SelectedPlayer)
1011 SendSysMessage(LANG_NO_CHAR_SELECTED);
1012 SetSentErrorMessage(true);
1013 return false;
1016 // each skills that have max skill value dependent from level seted to current level max skill value
1017 SelectedPlayer->UpdateSkillsToMaxSkillsForLevel();
1018 return true;
1021 bool ChatHandler::HandleSetSkillCommand(const char* args)
1023 // number or [name] Shift-click form |color|Hskill:skill_id|h[name]|h|r
1024 char* skill_p = extractKeyFromLink((char*)args,"Hskill");
1025 if(!skill_p)
1026 return false;
1028 char *level_p = strtok (NULL, " ");
1030 if( !level_p)
1031 return false;
1033 char *max_p = strtok (NULL, " ");
1035 int32 skill = atoi(skill_p);
1036 if (skill <= 0)
1038 PSendSysMessage(LANG_INVALID_SKILL_ID, skill);
1039 SetSentErrorMessage(true);
1040 return false;
1043 int32 level = atol (level_p);
1045 Player * target = getSelectedPlayer();
1046 if(!target)
1048 SendSysMessage(LANG_NO_CHAR_SELECTED);
1049 SetSentErrorMessage(true);
1050 return false;
1053 SkillLineEntry const* sl = sSkillLineStore.LookupEntry(skill);
1054 if(!sl)
1056 PSendSysMessage(LANG_INVALID_SKILL_ID, skill);
1057 SetSentErrorMessage(true);
1058 return false;
1061 std::string tNameLink = GetNameLink(target);
1063 if(!target->GetSkillValue(skill))
1065 PSendSysMessage(LANG_SET_SKILL_ERROR, tNameLink.c_str(), skill, sl->name[GetSessionDbcLocale()]);
1066 SetSentErrorMessage(true);
1067 return false;
1070 int32 max = max_p ? atol (max_p) : target->GetPureMaxSkillValue(skill);
1072 if( level <= 0 || level > max || max <= 0 )
1073 return false;
1075 target->SetSkill(skill, level, max);
1076 PSendSysMessage(LANG_SET_SKILL, skill, sl->name[GetSessionDbcLocale()], tNameLink.c_str(), level, max);
1078 return true;
1081 bool ChatHandler::HandleUnLearnCommand(const char* args)
1083 if (!*args)
1084 return false;
1086 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
1087 uint32 spell_id = extractSpellIdFromLink((char*)args);
1088 if(!spell_id)
1089 return false;
1091 char const* allStr = strtok(NULL," ");
1092 bool allRanks = allStr ? (strncmp(allStr, "all", strlen(allStr)) == 0) : false;
1094 Player* target = getSelectedPlayer();
1095 if(!target)
1097 SendSysMessage(LANG_NO_CHAR_SELECTED);
1098 SetSentErrorMessage(true);
1099 return false;
1102 if(allRanks)
1103 spell_id = sSpellMgr.GetFirstSpellInChain (spell_id);
1105 if (target->HasSpell(spell_id))
1106 target->removeSpell(spell_id,false,!allRanks);
1107 else
1108 SendSysMessage(LANG_FORGET_SPELL);
1110 if(GetTalentSpellCost(spell_id))
1111 target->SendTalentsInfoData(false);
1113 return true;
1116 bool ChatHandler::HandleCooldownCommand(const char* args)
1118 Player* target = getSelectedPlayer();
1119 if(!target)
1121 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1122 SetSentErrorMessage(true);
1123 return false;
1126 std::string tNameLink = GetNameLink(target);
1128 if (!*args)
1130 target->RemoveAllSpellCooldown();
1131 PSendSysMessage(LANG_REMOVEALL_COOLDOWN, tNameLink.c_str());
1133 else
1135 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1136 uint32 spell_id = extractSpellIdFromLink((char*)args);
1137 if(!spell_id)
1138 return false;
1140 if(!sSpellStore.LookupEntry(spell_id))
1142 PSendSysMessage(LANG_UNKNOWN_SPELL, target==m_session->GetPlayer() ? GetMangosString(LANG_YOU) : tNameLink.c_str());
1143 SetSentErrorMessage(true);
1144 return false;
1147 target->RemoveSpellCooldown(spell_id,true);
1148 PSendSysMessage(LANG_REMOVE_COOLDOWN, spell_id, target==m_session->GetPlayer() ? GetMangosString(LANG_YOU) : tNameLink.c_str());
1150 return true;
1153 bool ChatHandler::HandleLearnAllCommand(const char* /*args*/)
1155 static const char *allSpellList[] =
1157 "3365",
1158 "6233",
1159 "6247",
1160 "6246",
1161 "6477",
1162 "6478",
1163 "22810",
1164 "8386",
1165 "21651",
1166 "21652",
1167 "522",
1168 "7266",
1169 "8597",
1170 "2479",
1171 "22027",
1172 "6603",
1173 "5019",
1174 "133",
1175 "168",
1176 "227",
1177 "5009",
1178 "9078",
1179 "668",
1180 "203",
1181 "20599",
1182 "20600",
1183 "81",
1184 "20597",
1185 "20598",
1186 "20864",
1187 "1459",
1188 "5504",
1189 "587",
1190 "5143",
1191 "118",
1192 "5505",
1193 "597",
1194 "604",
1195 "1449",
1196 "1460",
1197 "2855",
1198 "1008",
1199 "475",
1200 "5506",
1201 "1463",
1202 "12824",
1203 "8437",
1204 "990",
1205 "5145",
1206 "8450",
1207 "1461",
1208 "759",
1209 "8494",
1210 "8455",
1211 "8438",
1212 "6127",
1213 "8416",
1214 "6129",
1215 "8451",
1216 "8495",
1217 "8439",
1218 "3552",
1219 "8417",
1220 "10138",
1221 "12825",
1222 "10169",
1223 "10156",
1224 "10144",
1225 "10191",
1226 "10201",
1227 "10211",
1228 "10053",
1229 "10173",
1230 "10139",
1231 "10145",
1232 "10192",
1233 "10170",
1234 "10202",
1235 "10054",
1236 "10174",
1237 "10193",
1238 "12826",
1239 "2136",
1240 "143",
1241 "145",
1242 "2137",
1243 "2120",
1244 "3140",
1245 "543",
1246 "2138",
1247 "2948",
1248 "8400",
1249 "2121",
1250 "8444",
1251 "8412",
1252 "8457",
1253 "8401",
1254 "8422",
1255 "8445",
1256 "8402",
1257 "8413",
1258 "8458",
1259 "8423",
1260 "8446",
1261 "10148",
1262 "10197",
1263 "10205",
1264 "10149",
1265 "10215",
1266 "10223",
1267 "10206",
1268 "10199",
1269 "10150",
1270 "10216",
1271 "10207",
1272 "10225",
1273 "10151",
1274 "116",
1275 "205",
1276 "7300",
1277 "122",
1278 "837",
1279 "10",
1280 "7301",
1281 "7322",
1282 "6143",
1283 "120",
1284 "865",
1285 "8406",
1286 "6141",
1287 "7302",
1288 "8461",
1289 "8407",
1290 "8492",
1291 "8427",
1292 "8408",
1293 "6131",
1294 "7320",
1295 "10159",
1296 "8462",
1297 "10185",
1298 "10179",
1299 "10160",
1300 "10180",
1301 "10219",
1302 "10186",
1303 "10177",
1304 "10230",
1305 "10181",
1306 "10161",
1307 "10187",
1308 "10220",
1309 "2018",
1310 "2663",
1311 "12260",
1312 "2660",
1313 "3115",
1314 "3326",
1315 "2665",
1316 "3116",
1317 "2738",
1318 "3293",
1319 "2661",
1320 "3319",
1321 "2662",
1322 "9983",
1323 "8880",
1324 "2737",
1325 "2739",
1326 "7408",
1327 "3320",
1328 "2666",
1329 "3323",
1330 "3324",
1331 "3294",
1332 "22723",
1333 "23219",
1334 "23220",
1335 "23221",
1336 "23228",
1337 "23338",
1338 "10788",
1339 "10790",
1340 "5611",
1341 "5016",
1342 "5609",
1343 "2060",
1344 "10963",
1345 "10964",
1346 "10965",
1347 "22593",
1348 "22594",
1349 "596",
1350 "996",
1351 "499",
1352 "768",
1353 "17002",
1354 "1448",
1355 "1082",
1356 "16979",
1357 "1079",
1358 "5215",
1359 "20484",
1360 "5221",
1361 "15590",
1362 "17007",
1363 "6795",
1364 "6807",
1365 "5487",
1366 "1446",
1367 "1066",
1368 "5421",
1369 "3139",
1370 "779",
1371 "6811",
1372 "6808",
1373 "1445",
1374 "5216",
1375 "1737",
1376 "5222",
1377 "5217",
1378 "1432",
1379 "6812",
1380 "9492",
1381 "5210",
1382 "3030",
1383 "1441",
1384 "783",
1385 "6801",
1386 "20739",
1387 "8944",
1388 "9491",
1389 "22569",
1390 "5226",
1391 "6786",
1392 "1433",
1393 "8973",
1394 "1828",
1395 "9495",
1396 "9006",
1397 "6794",
1398 "8993",
1399 "5203",
1400 "16914",
1401 "6784",
1402 "9635",
1403 "22830",
1404 "20722",
1405 "9748",
1406 "6790",
1407 "9753",
1408 "9493",
1409 "9752",
1410 "9831",
1411 "9825",
1412 "9822",
1413 "5204",
1414 "5401",
1415 "22831",
1416 "6793",
1417 "9845",
1418 "17401",
1419 "9882",
1420 "9868",
1421 "20749",
1422 "9893",
1423 "9899",
1424 "9895",
1425 "9832",
1426 "9902",
1427 "9909",
1428 "22832",
1429 "9828",
1430 "9851",
1431 "9883",
1432 "9869",
1433 "17406",
1434 "17402",
1435 "9914",
1436 "20750",
1437 "9897",
1438 "9848",
1439 "3127",
1440 "107",
1441 "204",
1442 "9116",
1443 "2457",
1444 "78",
1445 "18848",
1446 "331",
1447 "403",
1448 "2098",
1449 "1752",
1450 "11278",
1451 "11288",
1452 "11284",
1453 "6461",
1454 "2344",
1455 "2345",
1456 "6463",
1457 "2346",
1458 "2352",
1459 "775",
1460 "1434",
1461 "1612",
1462 "71",
1463 "2468",
1464 "2458",
1465 "2467",
1466 "7164",
1467 "7178",
1468 "7367",
1469 "7376",
1470 "7381",
1471 "21156",
1472 "5209",
1473 "3029",
1474 "5201",
1475 "9849",
1476 "9850",
1477 "20719",
1478 "22568",
1479 "22827",
1480 "22828",
1481 "22829",
1482 "6809",
1483 "8972",
1484 "9005",
1485 "9823",
1486 "9827",
1487 "6783",
1488 "9913",
1489 "6785",
1490 "6787",
1491 "9866",
1492 "9867",
1493 "9894",
1494 "9896",
1495 "6800",
1496 "8992",
1497 "9829",
1498 "9830",
1499 "780",
1500 "769",
1501 "6749",
1502 "6750",
1503 "9755",
1504 "9754",
1505 "9908",
1506 "20745",
1507 "20742",
1508 "20747",
1509 "20748",
1510 "9746",
1511 "9745",
1512 "9880",
1513 "9881",
1514 "5391",
1515 "842",
1516 "3025",
1517 "3031",
1518 "3287",
1519 "3329",
1520 "1945",
1521 "3559",
1522 "4933",
1523 "4934",
1524 "4935",
1525 "4936",
1526 "5142",
1527 "5390",
1528 "5392",
1529 "5404",
1530 "5420",
1531 "6405",
1532 "7293",
1533 "7965",
1534 "8041",
1535 "8153",
1536 "9033",
1537 "9034",
1538 //"9036", problems with ghost state
1539 "16421",
1540 "21653",
1541 "22660",
1542 "5225",
1543 "9846",
1544 "2426",
1545 "5916",
1546 "6634",
1547 //"6718", phasing stealth, annoying for learn all case.
1548 "6719",
1549 "8822",
1550 "9591",
1551 "9590",
1552 "10032",
1553 "17746",
1554 "17747",
1555 "8203",
1556 "11392",
1557 "12495",
1558 "16380",
1559 "23452",
1560 "4079",
1561 "4996",
1562 "4997",
1563 "4998",
1564 "4999",
1565 "5000",
1566 "6348",
1567 "6349",
1568 "6481",
1569 "6482",
1570 "6483",
1571 "6484",
1572 "11362",
1573 "11410",
1574 "11409",
1575 "12510",
1576 "12509",
1577 "12885",
1578 "13142",
1579 "21463",
1580 "23460",
1581 "11421",
1582 "11416",
1583 "11418",
1584 "1851",
1585 "10059",
1586 "11423",
1587 "11417",
1588 "11422",
1589 "11419",
1590 "11424",
1591 "11420",
1592 "27",
1593 "31",
1594 "33",
1595 "34",
1596 "35",
1597 "15125",
1598 "21127",
1599 "22950",
1600 "1180",
1601 "201",
1602 "12593",
1603 "12842",
1604 "16770",
1605 "6057",
1606 "12051",
1607 "18468",
1608 "12606",
1609 "12605",
1610 "18466",
1611 "12502",
1612 "12043",
1613 "15060",
1614 "12042",
1615 "12341",
1616 "12848",
1617 "12344",
1618 "12353",
1619 "18460",
1620 "11366",
1621 "12350",
1622 "12352",
1623 "13043",
1624 "11368",
1625 "11113",
1626 "12400",
1627 "11129",
1628 "16766",
1629 "12573",
1630 "15053",
1631 "12580",
1632 "12475",
1633 "12472",
1634 "12953",
1635 "12488",
1636 "11189",
1637 "12985",
1638 "12519",
1639 "16758",
1640 "11958",
1641 "12490",
1642 "11426",
1643 "3565",
1644 "3562",
1645 "18960",
1646 "3567",
1647 "3561",
1648 "3566",
1649 "3563",
1650 "1953",
1651 "2139",
1652 "12505",
1653 "13018",
1654 "12522",
1655 "12523",
1656 "5146",
1657 "5144",
1658 "5148",
1659 "8419",
1660 "8418",
1661 "10213",
1662 "10212",
1663 "10157",
1664 "12524",
1665 "13019",
1666 "12525",
1667 "13020",
1668 "12526",
1669 "13021",
1670 "18809",
1671 "13031",
1672 "13032",
1673 "13033",
1674 "4036",
1675 "3920",
1676 "3919",
1677 "3918",
1678 "7430",
1679 "3922",
1680 "3923",
1681 "7411",
1682 "7418",
1683 "7421",
1684 "13262",
1685 "7412",
1686 "7415",
1687 "7413",
1688 "7416",
1689 "13920",
1690 "13921",
1691 "7745",
1692 "7779",
1693 "7428",
1694 "7457",
1695 "7857",
1696 "7748",
1697 "7426",
1698 "13421",
1699 "7454",
1700 "13378",
1701 "7788",
1702 "14807",
1703 "14293",
1704 "7795",
1705 "6296",
1706 "20608",
1707 "755",
1708 "444",
1709 "427",
1710 "428",
1711 "442",
1712 "447",
1713 "3578",
1714 "3581",
1715 "19027",
1716 "3580",
1717 "665",
1718 "3579",
1719 "3577",
1720 "6755",
1721 "3576",
1722 "2575",
1723 "2577",
1724 "2578",
1725 "2579",
1726 "2580",
1727 "2656",
1728 "2657",
1729 "2576",
1730 "3564",
1731 "10248",
1732 "8388",
1733 "2659",
1734 "14891",
1735 "3308",
1736 "3307",
1737 "10097",
1738 "2658",
1739 "3569",
1740 "16153",
1741 "3304",
1742 "10098",
1743 "4037",
1744 "3929",
1745 "3931",
1746 "3926",
1747 "3924",
1748 "3930",
1749 "3977",
1750 "3925",
1751 "136",
1752 "228",
1753 "5487",
1754 "43",
1755 "202",
1759 int loop = 0;
1760 while(strcmp(allSpellList[loop], "0"))
1762 uint32 spell = atol((char*)allSpellList[loop++]);
1764 if (m_session->GetPlayer()->HasSpell(spell))
1765 continue;
1767 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
1768 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
1770 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
1771 continue;
1774 m_session->GetPlayer()->learnSpell(spell, false);
1777 SendSysMessage(LANG_COMMAND_LEARN_MANY_SPELLS);
1779 return true;
1782 bool ChatHandler::HandleLearnAllGMCommand(const char* /*args*/)
1784 static const char *gmSpellList[] =
1786 "24347", // Become A Fish, No Breath Bar
1787 "35132", // Visual Boom
1788 "38488", // Attack 4000-8000 AOE
1789 "38795", // Attack 2000 AOE + Slow Down 90%
1790 "15712", // Attack 200
1791 "1852", // GM Spell Silence
1792 "31899", // Kill
1793 "31924", // Kill
1794 "29878", // Kill My Self
1795 "26644", // More Kill
1797 "28550", //Invisible 24
1798 "23452", //Invisible + Target
1802 uint16 gmSpellIter = 0;
1803 while( strcmp(gmSpellList[gmSpellIter], "0") )
1805 uint32 spell = atol((char*)gmSpellList[gmSpellIter++]);
1807 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
1808 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
1810 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
1811 continue;
1814 m_session->GetPlayer()->learnSpell(spell, false);
1817 SendSysMessage(LANG_LEARNING_GM_SKILLS);
1818 return true;
1821 bool ChatHandler::HandleLearnAllMyClassCommand(const char* /*args*/)
1823 HandleLearnAllMySpellsCommand("");
1824 HandleLearnAllMyTalentsCommand("");
1825 return true;
1828 bool ChatHandler::HandleLearnAllMySpellsCommand(const char* /*args*/)
1830 ChrClassesEntry const* clsEntry = sChrClassesStore.LookupEntry(m_session->GetPlayer()->getClass());
1831 if(!clsEntry)
1832 return true;
1833 uint32 family = clsEntry->spellfamily;
1835 for (uint32 i = 0; i < sSkillLineAbilityStore.GetNumRows(); ++i)
1837 SkillLineAbilityEntry const *entry = sSkillLineAbilityStore.LookupEntry(i);
1838 if (!entry)
1839 continue;
1841 SpellEntry const *spellInfo = sSpellStore.LookupEntry(entry->spellId);
1842 if(!spellInfo)
1843 continue;
1845 // skip server-side/triggered spells
1846 if(spellInfo->spellLevel==0)
1847 continue;
1849 // skip wrong class/race skills
1850 if(!m_session->GetPlayer()->IsSpellFitByClassAndRace(spellInfo->Id))
1851 continue;
1853 // skip other spell families
1854 if( spellInfo->SpellFamilyName != family)
1855 continue;
1857 // skip spells with first rank learned as talent (and all talents then also)
1858 uint32 first_rank = sSpellMgr.GetFirstSpellInChain(spellInfo->Id);
1859 if(GetTalentSpellCost(first_rank) > 0 )
1860 continue;
1862 // skip broken spells
1863 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
1864 continue;
1866 m_session->GetPlayer()->learnSpell(spellInfo->Id, false);
1869 SendSysMessage(LANG_COMMAND_LEARN_CLASS_SPELLS);
1870 return true;
1873 bool ChatHandler::HandleLearnAllMyTalentsCommand(const char* /*args*/)
1875 Player* player = m_session->GetPlayer();
1876 uint32 classMask = player->getClassMask();
1878 for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i)
1880 TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
1881 if(!talentInfo)
1882 continue;
1884 TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentInfo->TalentTab );
1885 if(!talentTabInfo)
1886 continue;
1888 if( (classMask & talentTabInfo->ClassMask) == 0 )
1889 continue;
1891 // search highest talent rank
1892 uint32 spellid = 0;
1894 for(int rank = MAX_TALENT_RANK-1; rank >= 0; --rank)
1896 if(talentInfo->RankID[rank]!=0)
1898 spellid = talentInfo->RankID[rank];
1899 break;
1903 if(!spellid) // ??? none spells in talent
1904 continue;
1906 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellid);
1907 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
1908 continue;
1910 // learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
1911 player->learnSpellHighRank(spellid);
1914 player->SendTalentsInfoData(false);
1916 SendSysMessage(LANG_COMMAND_LEARN_CLASS_TALENTS);
1917 return true;
1920 bool ChatHandler::HandleLearnAllMyPetTalentsCommand(const char* /*args*/)
1922 Player* player = m_session->GetPlayer();
1924 Pet* pet = player->GetPet();
1925 if(!pet)
1927 SendSysMessage(LANG_NO_PET_FOUND);
1928 SetSentErrorMessage(true);
1929 return false;
1932 CreatureInfo const *ci = pet->GetCreatureInfo();
1933 if(!ci)
1935 SendSysMessage(LANG_WRONG_PET_TYPE);
1936 SetSentErrorMessage(true);
1937 return false;
1940 CreatureFamilyEntry const *pet_family = sCreatureFamilyStore.LookupEntry(ci->family);
1941 if(!pet_family)
1943 SendSysMessage(LANG_WRONG_PET_TYPE);
1944 SetSentErrorMessage(true);
1945 return false;
1948 if(pet_family->petTalentType < 0) // not hunter pet
1950 SendSysMessage(LANG_WRONG_PET_TYPE);
1951 SetSentErrorMessage(true);
1952 return false;
1955 for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i)
1957 TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
1958 if(!talentInfo)
1959 continue;
1961 TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentInfo->TalentTab );
1962 if(!talentTabInfo)
1963 continue;
1965 // prevent learn talent for different family (cheating)
1966 if(((1 << pet_family->petTalentType) & talentTabInfo->petTalentMask)==0)
1967 continue;
1969 // search highest talent rank
1970 uint32 spellid = 0;
1972 for(int rank = MAX_TALENT_RANK-1; rank >= 0; --rank)
1974 if(talentInfo->RankID[rank]!=0)
1976 spellid = talentInfo->RankID[rank];
1977 break;
1981 if(!spellid) // ??? none spells in talent
1982 continue;
1984 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellid);
1985 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
1986 continue;
1988 // learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
1989 pet->learnSpellHighRank(spellid);
1992 player->SendTalentsInfoData(true);
1994 SendSysMessage(LANG_COMMAND_LEARN_PET_TALENTS);
1995 return true;
1998 bool ChatHandler::HandleLearnAllLangCommand(const char* /*args*/)
2000 // skipping UNIVERSAL language (0)
2001 for(int i = 1; i < LANGUAGES_COUNT; ++i)
2002 m_session->GetPlayer()->learnSpell(lang_description[i].spell_id, false);
2004 SendSysMessage(LANG_COMMAND_LEARN_ALL_LANG);
2005 return true;
2008 bool ChatHandler::HandleLearnAllDefaultCommand(const char* args)
2010 Player* target;
2011 if(!extractPlayerTarget((char*)args,&target))
2012 return false;
2014 target->learnDefaultSpells();
2015 target->learnQuestRewardedSpells();
2017 PSendSysMessage(LANG_COMMAND_LEARN_ALL_DEFAULT_AND_QUEST,GetNameLink(target).c_str());
2018 return true;
2021 bool ChatHandler::HandleLearnCommand(const char* args)
2023 Player* targetPlayer = getSelectedPlayer();
2025 if(!targetPlayer)
2027 SendSysMessage(LANG_PLAYER_NOT_FOUND);
2028 SetSentErrorMessage(true);
2029 return false;
2032 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
2033 uint32 spell = extractSpellIdFromLink((char*)args);
2034 if(!spell || !sSpellStore.LookupEntry(spell))
2035 return false;
2037 char const* allStr = strtok(NULL," ");
2038 bool allRanks = allStr ? (strncmp(allStr, "all", strlen(allStr)) == 0) : false;
2040 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
2041 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
2043 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
2044 SetSentErrorMessage(true);
2045 return false;
2048 if (!allRanks && targetPlayer->HasSpell(spell))
2050 if(targetPlayer == m_session->GetPlayer())
2051 SendSysMessage(LANG_YOU_KNOWN_SPELL);
2052 else
2053 PSendSysMessage(LANG_TARGET_KNOWN_SPELL,GetNameLink(targetPlayer).c_str());
2054 SetSentErrorMessage(true);
2055 return false;
2058 if(allRanks)
2059 targetPlayer->learnSpellHighRank(spell);
2060 else
2061 targetPlayer->learnSpell(spell, false);
2063 uint32 first_spell = sSpellMgr.GetFirstSpellInChain(spell);
2064 if(GetTalentSpellCost(first_spell))
2065 targetPlayer->SendTalentsInfoData(false);
2067 return true;
2070 bool ChatHandler::HandleAddItemCommand(const char* args)
2072 if (!*args)
2073 return false;
2075 uint32 itemId = 0;
2077 if(args[0]=='[') // [name] manual form
2079 char* citemName = strtok((char*)args, "]");
2081 if(citemName && citemName[0])
2083 std::string itemName = citemName+1;
2084 WorldDatabase.escape_string(itemName);
2085 QueryResult *result = WorldDatabase.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName.c_str());
2086 if (!result)
2088 PSendSysMessage(LANG_COMMAND_COULDNOTFIND, citemName+1);
2089 SetSentErrorMessage(true);
2090 return false;
2092 itemId = result->Fetch()->GetUInt16();
2093 delete result;
2095 else
2096 return false;
2098 else // item_id or [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r
2100 char* cId = extractKeyFromLink((char*)args,"Hitem");
2101 if(!cId)
2102 return false;
2103 itemId = atol(cId);
2106 char* ccount = strtok(NULL, " ");
2108 int32 count = 1;
2110 if (ccount)
2111 count = strtol(ccount, NULL, 10);
2113 if (count == 0)
2114 count = 1;
2116 Player* pl = m_session->GetPlayer();
2117 Player* plTarget = getSelectedPlayer();
2118 if(!plTarget)
2119 plTarget = pl;
2121 DETAIL_LOG(GetMangosString(LANG_ADDITEM), itemId, count);
2123 ItemPrototype const *pProto = ObjectMgr::GetItemPrototype(itemId);
2124 if(!pProto)
2126 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, itemId);
2127 SetSentErrorMessage(true);
2128 return false;
2131 //Subtract
2132 if (count < 0)
2134 plTarget->DestroyItemCount(itemId, -count, true, false);
2135 PSendSysMessage(LANG_REMOVEITEM, itemId, -count, GetNameLink(plTarget).c_str());
2136 return true;
2139 //Adding items
2140 uint32 noSpaceForCount = 0;
2142 // check space and find places
2143 ItemPosCountVec dest;
2144 uint8 msg = plTarget->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, itemId, count, &noSpaceForCount );
2145 if( msg != EQUIP_ERR_OK ) // convert to possible store amount
2146 count -= noSpaceForCount;
2148 if( count == 0 || dest.empty()) // can't add any
2150 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount );
2151 SetSentErrorMessage(true);
2152 return false;
2155 Item* item = plTarget->StoreNewItem( dest, itemId, true, Item::GenerateItemRandomPropertyId(itemId));
2157 // remove binding (let GM give it to another player later)
2158 if(pl==plTarget)
2159 for(ItemPosCountVec::const_iterator itr = dest.begin(); itr != dest.end(); ++itr)
2160 if(Item* item1 = pl->GetItemByPos(itr->pos))
2161 item1->SetBinding( false );
2163 if(count > 0 && item)
2165 pl->SendNewItem(item,count,false,true);
2166 if(pl!=plTarget)
2167 plTarget->SendNewItem(item,count,true,false);
2170 if(noSpaceForCount > 0)
2171 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount);
2173 return true;
2176 bool ChatHandler::HandleAddItemSetCommand(const char* args)
2178 if (!*args)
2179 return false;
2181 char* cId = extractKeyFromLink((char*)args,"Hitemset"); // number or [name] Shift-click form |color|Hitemset:itemset_id|h[name]|h|r
2182 if (!cId)
2183 return false;
2185 uint32 itemsetId = atol(cId);
2187 // prevent generation all items with itemset field value '0'
2188 if (itemsetId == 0)
2190 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND,itemsetId);
2191 SetSentErrorMessage(true);
2192 return false;
2195 Player* pl = m_session->GetPlayer();
2196 Player* plTarget = getSelectedPlayer();
2197 if(!plTarget)
2198 plTarget = pl;
2200 DETAIL_LOG(GetMangosString(LANG_ADDITEMSET), itemsetId);
2202 bool found = false;
2203 for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
2205 ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype>(id);
2206 if (!pProto)
2207 continue;
2209 if (pProto->ItemSet == itemsetId)
2211 found = true;
2212 ItemPosCountVec dest;
2213 uint8 msg = plTarget->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, pProto->ItemId, 1 );
2214 if (msg == EQUIP_ERR_OK)
2216 Item* item = plTarget->StoreNewItem( dest, pProto->ItemId, true);
2218 // remove binding (let GM give it to another player later)
2219 if (pl==plTarget)
2220 item->SetBinding( false );
2222 pl->SendNewItem(item,1,false,true);
2223 if (pl!=plTarget)
2224 plTarget->SendNewItem(item,1,true,false);
2226 else
2228 pl->SendEquipError( msg, NULL, NULL, pProto->ItemId );
2229 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, pProto->ItemId, 1);
2234 if (!found)
2236 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND,itemsetId);
2238 SetSentErrorMessage(true);
2239 return false;
2242 return true;
2245 bool ChatHandler::HandleListItemCommand(const char* args)
2247 if(!*args)
2248 return false;
2250 char* cId = extractKeyFromLink((char*)args,"Hitem");
2251 if(!cId)
2252 return false;
2254 uint32 item_id = atol(cId);
2255 if(!item_id)
2257 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
2258 SetSentErrorMessage(true);
2259 return false;
2262 ItemPrototype const* itemProto = ObjectMgr::GetItemPrototype(item_id);
2263 if(!itemProto)
2265 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
2266 SetSentErrorMessage(true);
2267 return false;
2270 char* c_count = strtok(NULL, " ");
2271 int count = c_count ? atol(c_count) : 10;
2273 if(count < 0)
2274 return false;
2276 QueryResult *result;
2278 // inventory case
2279 uint32 inv_count = 0;
2280 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM character_inventory WHERE item_template='%u'",item_id);
2281 if(result)
2283 inv_count = (*result)[0].GetUInt32();
2284 delete result;
2287 result=CharacterDatabase.PQuery(
2288 // 0 1 2 3 4 5
2289 "SELECT ci.item, cibag.slot AS bag, ci.slot, ci.guid, characters.account,characters.name "
2290 "FROM character_inventory AS ci LEFT JOIN character_inventory AS cibag ON (cibag.item=ci.bag),characters "
2291 "WHERE ci.item_template='%u' AND ci.guid = characters.guid LIMIT %u ",
2292 item_id,uint32(count));
2294 if(result)
2298 Field *fields = result->Fetch();
2299 uint32 item_guid = fields[0].GetUInt32();
2300 uint32 item_bag = fields[1].GetUInt32();
2301 uint32 item_slot = fields[2].GetUInt32();
2302 uint32 owner_guid = fields[3].GetUInt32();
2303 uint32 owner_acc = fields[4].GetUInt32();
2304 std::string owner_name = fields[5].GetCppString();
2306 char const* item_pos = 0;
2307 if(Player::IsEquipmentPos(item_bag,item_slot))
2308 item_pos = "[equipped]";
2309 else if(Player::IsInventoryPos(item_bag,item_slot))
2310 item_pos = "[in inventory]";
2311 else if(Player::IsBankPos(item_bag,item_slot))
2312 item_pos = "[in bank]";
2313 else
2314 item_pos = "";
2316 PSendSysMessage(LANG_ITEMLIST_SLOT,
2317 item_guid,owner_name.c_str(),owner_guid,owner_acc,item_pos);
2318 } while (result->NextRow());
2320 int res_count = (int)result->GetRowCount();
2322 delete result;
2324 if(count > res_count)
2325 count-=res_count;
2326 else if(count)
2327 count = 0;
2330 // mail case
2331 uint32 mail_count = 0;
2332 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM mail_items WHERE item_template='%u'", item_id);
2333 if(result)
2335 mail_count = (*result)[0].GetUInt32();
2336 delete result;
2339 if(count > 0)
2341 result=CharacterDatabase.PQuery(
2342 // 0 1 2 3 4 5 6
2343 "SELECT mail_items.item_guid, mail.sender, mail.receiver, char_s.account, char_s.name, char_r.account, char_r.name "
2344 "FROM mail,mail_items,characters as char_s,characters as char_r "
2345 "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",
2346 item_id,uint32(count));
2348 else
2349 result = NULL;
2351 if(result)
2355 Field *fields = result->Fetch();
2356 uint32 item_guid = fields[0].GetUInt32();
2357 uint32 item_s = fields[1].GetUInt32();
2358 uint32 item_r = fields[2].GetUInt32();
2359 uint32 item_s_acc = fields[3].GetUInt32();
2360 std::string item_s_name = fields[4].GetCppString();
2361 uint32 item_r_acc = fields[5].GetUInt32();
2362 std::string item_r_name = fields[6].GetCppString();
2364 char const* item_pos = "[in mail]";
2366 PSendSysMessage(LANG_ITEMLIST_MAIL,
2367 item_guid,item_s_name.c_str(),item_s,item_s_acc,item_r_name.c_str(),item_r,item_r_acc,item_pos);
2368 } while (result->NextRow());
2370 int res_count = (int)result->GetRowCount();
2372 delete result;
2374 if(count > res_count)
2375 count-=res_count;
2376 else if(count)
2377 count = 0;
2380 // auction case
2381 uint32 auc_count = 0;
2382 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM auctionhouse WHERE item_template='%u'",item_id);
2383 if(result)
2385 auc_count = (*result)[0].GetUInt32();
2386 delete result;
2389 if(count > 0)
2391 result=CharacterDatabase.PQuery(
2392 // 0 1 2 3
2393 "SELECT auctionhouse.itemguid, auctionhouse.itemowner, characters.account, characters.name "
2394 "FROM auctionhouse,characters WHERE auctionhouse.item_template='%u' AND characters.guid = auctionhouse.itemowner LIMIT %u",
2395 item_id,uint32(count));
2397 else
2398 result = NULL;
2400 if(result)
2404 Field *fields = result->Fetch();
2405 uint32 item_guid = fields[0].GetUInt32();
2406 uint32 owner = fields[1].GetUInt32();
2407 uint32 owner_acc = fields[2].GetUInt32();
2408 std::string owner_name = fields[3].GetCppString();
2410 char const* item_pos = "[in auction]";
2412 PSendSysMessage(LANG_ITEMLIST_AUCTION, item_guid, owner_name.c_str(), owner, owner_acc,item_pos);
2413 } while (result->NextRow());
2415 delete result;
2418 // guild bank case
2419 uint32 guild_count = 0;
2420 result=CharacterDatabase.PQuery("SELECT COUNT(item_entry) FROM guild_bank_item WHERE item_entry='%u'",item_id);
2421 if(result)
2423 guild_count = (*result)[0].GetUInt32();
2424 delete result;
2427 result=CharacterDatabase.PQuery(
2428 // 0 1 2
2429 "SELECT gi.item_guid, gi.guildid, guild.name "
2430 "FROM guild_bank_item AS gi, guild WHERE gi.item_entry='%u' AND gi.guildid = guild.guildid LIMIT %u ",
2431 item_id,uint32(count));
2433 if(result)
2437 Field *fields = result->Fetch();
2438 uint32 item_guid = fields[0].GetUInt32();
2439 uint32 guild_guid = fields[1].GetUInt32();
2440 std::string guild_name = fields[2].GetCppString();
2442 char const* item_pos = "[in guild bank]";
2444 PSendSysMessage(LANG_ITEMLIST_GUILD,item_guid,guild_name.c_str(),guild_guid,item_pos);
2445 } while (result->NextRow());
2447 int res_count = (int)result->GetRowCount();
2449 delete result;
2451 if(count > res_count)
2452 count-=res_count;
2453 else if(count)
2454 count = 0;
2457 if(inv_count+mail_count+auc_count+guild_count == 0)
2459 SendSysMessage(LANG_COMMAND_NOITEMFOUND);
2460 SetSentErrorMessage(true);
2461 return false;
2464 PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE,item_id,inv_count+mail_count+auc_count+guild_count,inv_count,mail_count,auc_count,guild_count);
2466 return true;
2469 bool ChatHandler::HandleListObjectCommand(const char* args)
2471 if(!*args)
2472 return false;
2474 // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2475 char* cId = extractKeyFromLink((char*)args,"Hgameobject_entry");
2476 if(!cId)
2477 return false;
2479 uint32 go_id = atol(cId);
2480 if(!go_id)
2482 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, go_id);
2483 SetSentErrorMessage(true);
2484 return false;
2487 GameObjectInfo const * gInfo = ObjectMgr::GetGameObjectInfo(go_id);
2488 if(!gInfo)
2490 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, go_id);
2491 SetSentErrorMessage(true);
2492 return false;
2495 char* c_count = strtok(NULL, " ");
2496 int count = c_count ? atol(c_count) : 10;
2498 if(count < 0)
2499 return false;
2501 QueryResult *result;
2503 uint32 obj_count = 0;
2504 result=WorldDatabase.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'",go_id);
2505 if(result)
2507 obj_count = (*result)[0].GetUInt32();
2508 delete result;
2511 if(m_session)
2513 Player* pl = m_session->GetPlayer();
2514 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",
2515 pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(),go_id,uint32(count));
2517 else
2518 result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map FROM gameobject WHERE id = '%u' LIMIT %u",
2519 go_id,uint32(count));
2521 if (result)
2525 Field *fields = result->Fetch();
2526 uint32 guid = fields[0].GetUInt32();
2527 float x = fields[1].GetFloat();
2528 float y = fields[2].GetFloat();
2529 float z = fields[3].GetFloat();
2530 int mapid = fields[4].GetUInt16();
2532 if (m_session)
2533 PSendSysMessage(LANG_GO_LIST_CHAT, guid, guid, gInfo->name, x, y, z, mapid);
2534 else
2535 PSendSysMessage(LANG_GO_LIST_CONSOLE, guid, gInfo->name, x, y, z, mapid);
2536 } while (result->NextRow());
2538 delete result;
2541 PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE,go_id,obj_count);
2542 return true;
2545 bool ChatHandler::HandleListCreatureCommand(const char* args)
2547 if(!*args)
2548 return false;
2550 // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
2551 char* cId = extractKeyFromLink((char*)args,"Hcreature_entry");
2552 if(!cId)
2553 return false;
2555 uint32 cr_id = atol(cId);
2556 if(!cr_id)
2558 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, cr_id);
2559 SetSentErrorMessage(true);
2560 return false;
2563 CreatureInfo const* cInfo = ObjectMgr::GetCreatureTemplate(cr_id);
2564 if(!cInfo)
2566 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, cr_id);
2567 SetSentErrorMessage(true);
2568 return false;
2571 char* c_count = strtok(NULL, " ");
2572 int count = c_count ? atol(c_count) : 10;
2574 if(count < 0)
2575 return false;
2577 QueryResult *result;
2579 uint32 cr_count = 0;
2580 result=WorldDatabase.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'",cr_id);
2581 if(result)
2583 cr_count = (*result)[0].GetUInt32();
2584 delete result;
2587 if(m_session)
2589 Player* pl = m_session->GetPlayer();
2590 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",
2591 pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(), cr_id,uint32(count));
2593 else
2594 result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '%u' LIMIT %u",
2595 cr_id,uint32(count));
2597 if (result)
2601 Field *fields = result->Fetch();
2602 uint32 guid = fields[0].GetUInt32();
2603 float x = fields[1].GetFloat();
2604 float y = fields[2].GetFloat();
2605 float z = fields[3].GetFloat();
2606 int mapid = fields[4].GetUInt16();
2608 if (m_session)
2609 PSendSysMessage(LANG_CREATURE_LIST_CHAT, guid, guid, cInfo->Name, x, y, z, mapid);
2610 else
2611 PSendSysMessage(LANG_CREATURE_LIST_CONSOLE, guid, cInfo->Name, x, y, z, mapid);
2612 } while (result->NextRow());
2614 delete result;
2617 PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE,cr_id,cr_count);
2618 return true;
2621 bool ChatHandler::HandleLookupItemCommand(const char* args)
2623 if(!*args)
2624 return false;
2626 std::string namepart = args;
2627 std::wstring wnamepart;
2629 // converting string that we try to find to lower case
2630 if(!Utf8toWStr(namepart,wnamepart))
2631 return false;
2633 wstrToLower(wnamepart);
2635 uint32 counter = 0;
2637 // Search in `item_template`
2638 for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
2640 ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype >(id);
2641 if(!pProto)
2642 continue;
2644 int loc_idx = GetSessionDbLocaleIndex();
2645 if ( loc_idx >= 0 )
2647 ItemLocale const *il = sObjectMgr.GetItemLocale(pProto->ItemId);
2648 if (il)
2650 if ((int32)il->Name.size() > loc_idx && !il->Name[loc_idx].empty())
2652 std::string name = il->Name[loc_idx];
2654 if (Utf8FitTo(name, wnamepart))
2656 if (m_session)
2657 PSendSysMessage(LANG_ITEM_LIST_CHAT, id, id, name.c_str());
2658 else
2659 PSendSysMessage(LANG_ITEM_LIST_CONSOLE, id, name.c_str());
2660 ++counter;
2661 continue;
2667 std::string name = pProto->Name1;
2668 if(name.empty())
2669 continue;
2671 if (Utf8FitTo(name, wnamepart))
2673 if (m_session)
2674 PSendSysMessage(LANG_ITEM_LIST_CHAT, id, id, name.c_str());
2675 else
2676 PSendSysMessage(LANG_ITEM_LIST_CONSOLE, id, name.c_str());
2677 ++counter;
2681 if (counter==0)
2682 SendSysMessage(LANG_COMMAND_NOITEMFOUND);
2684 return true;
2687 bool ChatHandler::HandleLookupItemSetCommand(const char* args)
2689 if(!*args)
2690 return false;
2692 std::string namepart = args;
2693 std::wstring wnamepart;
2695 if(!Utf8toWStr(namepart,wnamepart))
2696 return false;
2698 // converting string that we try to find to lower case
2699 wstrToLower( wnamepart );
2701 uint32 counter = 0; // Counter for figure out that we found smth.
2703 // Search in ItemSet.dbc
2704 for (uint32 id = 0; id < sItemSetStore.GetNumRows(); id++)
2706 ItemSetEntry const *set = sItemSetStore.LookupEntry(id);
2707 if(set)
2709 int loc = GetSessionDbcLocale();
2710 std::string name = set->name[loc];
2711 if(name.empty())
2712 continue;
2714 if (!Utf8FitTo(name, wnamepart))
2716 loc = 0;
2717 for(; loc < MAX_LOCALE; ++loc)
2719 if(loc==GetSessionDbcLocale())
2720 continue;
2722 name = set->name[loc];
2723 if(name.empty())
2724 continue;
2726 if (Utf8FitTo(name, wnamepart))
2727 break;
2731 if(loc < MAX_LOCALE)
2733 // send item set in "id - [namedlink locale]" format
2734 if (m_session)
2735 PSendSysMessage(LANG_ITEMSET_LIST_CHAT,id,id,name.c_str(),localeNames[loc]);
2736 else
2737 PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE,id,name.c_str(),localeNames[loc]);
2738 ++counter;
2742 if (counter == 0) // if counter == 0 then we found nth
2743 SendSysMessage(LANG_COMMAND_NOITEMSETFOUND);
2744 return true;
2747 bool ChatHandler::HandleLookupSkillCommand(const char* args)
2749 if(!*args)
2750 return false;
2752 // can be NULL in console call
2753 Player* target = getSelectedPlayer();
2755 std::string namepart = args;
2756 std::wstring wnamepart;
2758 if(!Utf8toWStr(namepart,wnamepart))
2759 return false;
2761 // converting string that we try to find to lower case
2762 wstrToLower( wnamepart );
2764 uint32 counter = 0; // Counter for figure out that we found smth.
2766 // Search in SkillLine.dbc
2767 for (uint32 id = 0; id < sSkillLineStore.GetNumRows(); id++)
2769 SkillLineEntry const *skillInfo = sSkillLineStore.LookupEntry(id);
2770 if(skillInfo)
2772 int loc = GetSessionDbcLocale();
2773 std::string name = skillInfo->name[loc];
2774 if(name.empty())
2775 continue;
2777 if (!Utf8FitTo(name, wnamepart))
2779 loc = 0;
2780 for(; loc < MAX_LOCALE; ++loc)
2782 if(loc==GetSessionDbcLocale())
2783 continue;
2785 name = skillInfo->name[loc];
2786 if(name.empty())
2787 continue;
2789 if (Utf8FitTo(name, wnamepart))
2790 break;
2794 if(loc < MAX_LOCALE)
2796 char valStr[50] = "";
2797 char const* knownStr = "";
2798 if(target && target->HasSkill(id))
2800 knownStr = GetMangosString(LANG_KNOWN);
2801 uint32 curValue = target->GetPureSkillValue(id);
2802 uint32 maxValue = target->GetPureMaxSkillValue(id);
2803 uint32 permValue = target->GetSkillPermBonusValue(id);
2804 uint32 tempValue = target->GetSkillTempBonusValue(id);
2806 char const* valFormat = GetMangosString(LANG_SKILL_VALUES);
2807 snprintf(valStr,50,valFormat,curValue,maxValue,permValue,tempValue);
2810 // send skill in "id - [namedlink locale]" format
2811 if (m_session)
2812 PSendSysMessage(LANG_SKILL_LIST_CHAT,id,id,name.c_str(),localeNames[loc],knownStr,valStr);
2813 else
2814 PSendSysMessage(LANG_SKILL_LIST_CONSOLE,id,name.c_str(),localeNames[loc],knownStr,valStr);
2816 ++counter;
2820 if (counter == 0) // if counter == 0 then we found nth
2821 SendSysMessage(LANG_COMMAND_NOSKILLFOUND);
2822 return true;
2825 void ChatHandler::ShowSpellListHelper(Player* target, SpellEntry const* spellInfo, LocaleConstant loc)
2827 uint32 id = spellInfo->Id;
2829 bool known = target && target->HasSpell(id);
2830 bool learn = (spellInfo->Effect[EFFECT_INDEX_0] == SPELL_EFFECT_LEARN_SPELL);
2832 uint32 talentCost = GetTalentSpellCost(id);
2834 bool talent = (talentCost > 0);
2835 bool passive = IsPassiveSpell(spellInfo);
2836 bool active = target && target->HasAura(id);
2838 // unit32 used to prevent interpreting uint8 as char at output
2839 // find rank of learned spell for learning spell, or talent rank
2840 uint32 rank = talentCost ? talentCost : sSpellMgr.GetSpellRank(learn ? spellInfo->EffectTriggerSpell[EFFECT_INDEX_0] : id);
2842 // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
2843 std::ostringstream ss;
2844 if (m_session)
2845 ss << id << " - |cffffffff|Hspell:" << id << "|h[" << spellInfo->SpellName[loc];
2846 else
2847 ss << id << " - " << spellInfo->SpellName[loc];
2849 // include rank in link name
2850 if(rank)
2851 ss << GetMangosString(LANG_SPELL_RANK) << rank;
2853 if (m_session)
2854 ss << " " << localeNames[loc] << "]|h|r";
2855 else
2856 ss << " " << localeNames[loc];
2858 if(talent)
2859 ss << GetMangosString(LANG_TALENT);
2860 if(passive)
2861 ss << GetMangosString(LANG_PASSIVE);
2862 if(learn)
2863 ss << GetMangosString(LANG_LEARN);
2864 if(known)
2865 ss << GetMangosString(LANG_KNOWN);
2866 if(active)
2867 ss << GetMangosString(LANG_ACTIVE);
2869 SendSysMessage(ss.str().c_str());
2872 bool ChatHandler::HandleLookupSpellCommand(const char* args)
2874 if(!*args)
2875 return false;
2877 // can be NULL at console call
2878 Player* target = getSelectedPlayer();
2880 std::string namepart = args;
2881 std::wstring wnamepart;
2883 if(!Utf8toWStr(namepart,wnamepart))
2884 return false;
2886 // converting string that we try to find to lower case
2887 wstrToLower( wnamepart );
2889 uint32 counter = 0; // Counter for figure out that we found smth.
2891 // Search in Spell.dbc
2892 for (uint32 id = 0; id < sSpellStore.GetNumRows(); id++)
2894 SpellEntry const *spellInfo = sSpellStore.LookupEntry(id);
2895 if(spellInfo)
2897 int loc = GetSessionDbcLocale();
2898 std::string name = spellInfo->SpellName[loc];
2899 if(name.empty())
2900 continue;
2902 if (!Utf8FitTo(name, wnamepart))
2904 loc = 0;
2905 for(; loc < MAX_LOCALE; ++loc)
2907 if(loc==GetSessionDbcLocale())
2908 continue;
2910 name = spellInfo->SpellName[loc];
2911 if(name.empty())
2912 continue;
2914 if (Utf8FitTo(name, wnamepart))
2915 break;
2919 if(loc < MAX_LOCALE)
2921 ShowSpellListHelper(target, spellInfo, LocaleConstant(loc));
2922 ++counter;
2926 if (counter == 0) // if counter == 0 then we found nth
2927 SendSysMessage(LANG_COMMAND_NOSPELLFOUND);
2928 return true;
2931 bool ChatHandler::HandleLookupQuestCommand(const char* args)
2933 if(!*args)
2934 return false;
2936 // can be NULL at console call
2937 Player* target = getSelectedPlayer();
2939 std::string namepart = args;
2940 std::wstring wnamepart;
2942 // converting string that we try to find to lower case
2943 if(!Utf8toWStr(namepart,wnamepart))
2944 return false;
2946 wstrToLower(wnamepart);
2948 uint32 counter = 0 ;
2950 ObjectMgr::QuestMap const& qTemplates = sObjectMgr.GetQuestTemplates();
2951 for (ObjectMgr::QuestMap::const_iterator iter = qTemplates.begin(); iter != qTemplates.end(); ++iter)
2953 Quest * qinfo = iter->second;
2955 int loc_idx = GetSessionDbLocaleIndex();
2956 if ( loc_idx >= 0 )
2958 QuestLocale const *il = sObjectMgr.GetQuestLocale(qinfo->GetQuestId());
2959 if (il)
2961 if ((int32)il->Title.size() > loc_idx && !il->Title[loc_idx].empty())
2963 std::string title = il->Title[loc_idx];
2965 if (Utf8FitTo(title, wnamepart))
2967 char const* statusStr = "";
2969 if(target)
2971 QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId());
2973 if(status == QUEST_STATUS_COMPLETE)
2975 if(target->GetQuestRewardStatus(qinfo->GetQuestId()))
2976 statusStr = GetMangosString(LANG_COMMAND_QUEST_REWARDED);
2977 else
2978 statusStr = GetMangosString(LANG_COMMAND_QUEST_COMPLETE);
2980 else if(status == QUEST_STATUS_INCOMPLETE)
2981 statusStr = GetMangosString(LANG_COMMAND_QUEST_ACTIVE);
2984 if (m_session)
2985 PSendSysMessage(LANG_QUEST_LIST_CHAT,qinfo->GetQuestId(),qinfo->GetQuestId(),qinfo->GetQuestLevel(),title.c_str(),statusStr);
2986 else
2987 PSendSysMessage(LANG_QUEST_LIST_CONSOLE,qinfo->GetQuestId(),title.c_str(),statusStr);
2988 ++counter;
2989 continue;
2995 std::string title = qinfo->GetTitle();
2996 if(title.empty())
2997 continue;
2999 if (Utf8FitTo(title, wnamepart))
3001 char const* statusStr = "";
3003 if(target)
3005 QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId());
3007 if(status == QUEST_STATUS_COMPLETE)
3009 if(target->GetQuestRewardStatus(qinfo->GetQuestId()))
3010 statusStr = GetMangosString(LANG_COMMAND_QUEST_REWARDED);
3011 else
3012 statusStr = GetMangosString(LANG_COMMAND_QUEST_COMPLETE);
3014 else if(status == QUEST_STATUS_INCOMPLETE)
3015 statusStr = GetMangosString(LANG_COMMAND_QUEST_ACTIVE);
3018 if (m_session)
3019 PSendSysMessage(LANG_QUEST_LIST_CHAT,qinfo->GetQuestId(),qinfo->GetQuestId(),qinfo->GetQuestLevel(),title.c_str(),statusStr);
3020 else
3021 PSendSysMessage(LANG_QUEST_LIST_CONSOLE,qinfo->GetQuestId(),title.c_str(),statusStr);
3023 ++counter;
3027 if (counter==0)
3028 SendSysMessage(LANG_COMMAND_NOQUESTFOUND);
3030 return true;
3033 bool ChatHandler::HandleLookupCreatureCommand(const char* args)
3035 if (!*args)
3036 return false;
3038 std::string namepart = args;
3039 std::wstring wnamepart;
3041 // converting string that we try to find to lower case
3042 if (!Utf8toWStr (namepart,wnamepart))
3043 return false;
3045 wstrToLower (wnamepart);
3047 uint32 counter = 0;
3049 for (uint32 id = 0; id< sCreatureStorage.MaxEntry; ++id)
3051 CreatureInfo const* cInfo = sCreatureStorage.LookupEntry<CreatureInfo> (id);
3052 if(!cInfo)
3053 continue;
3055 int loc_idx = GetSessionDbLocaleIndex();
3056 if (loc_idx >= 0)
3058 CreatureLocale const *cl = sObjectMgr.GetCreatureLocale (id);
3059 if (cl)
3061 if ((int32)cl->Name.size() > loc_idx && !cl->Name[loc_idx].empty ())
3063 std::string name = cl->Name[loc_idx];
3065 if (Utf8FitTo (name, wnamepart))
3067 if (m_session)
3068 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str ());
3069 else
3070 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE, id, name.c_str ());
3071 ++counter;
3072 continue;
3078 std::string name = cInfo->Name;
3079 if (name.empty ())
3080 continue;
3082 if (Utf8FitTo(name, wnamepart))
3084 if (m_session)
3085 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str ());
3086 else
3087 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE, id, name.c_str ());
3088 ++counter;
3092 if (counter==0)
3093 SendSysMessage (LANG_COMMAND_NOCREATUREFOUND);
3095 return true;
3098 bool ChatHandler::HandleLookupObjectCommand(const char* args)
3100 if(!*args)
3101 return false;
3103 std::string namepart = args;
3104 std::wstring wnamepart;
3106 // converting string that we try to find to lower case
3107 if(!Utf8toWStr(namepart,wnamepart))
3108 return false;
3110 wstrToLower(wnamepart);
3112 uint32 counter = 0;
3114 for (uint32 id = 0; id< sGOStorage.MaxEntry; id++ )
3116 GameObjectInfo const* gInfo = sGOStorage.LookupEntry<GameObjectInfo>(id);
3117 if(!gInfo)
3118 continue;
3120 int loc_idx = GetSessionDbLocaleIndex();
3121 if ( loc_idx >= 0 )
3123 GameObjectLocale const *gl = sObjectMgr.GetGameObjectLocale(id);
3124 if (gl)
3126 if ((int32)gl->Name.size() > loc_idx && !gl->Name[loc_idx].empty())
3128 std::string name = gl->Name[loc_idx];
3130 if (Utf8FitTo(name, wnamepart))
3132 if (m_session)
3133 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, id, id, name.c_str());
3134 else
3135 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, id, name.c_str());
3136 ++counter;
3137 continue;
3143 std::string name = gInfo->name;
3144 if(name.empty())
3145 continue;
3147 if(Utf8FitTo(name, wnamepart))
3149 if (m_session)
3150 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, id, id, name.c_str());
3151 else
3152 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, id, name.c_str());
3153 ++counter;
3157 if(counter==0)
3158 SendSysMessage(LANG_COMMAND_NOGAMEOBJECTFOUND);
3160 return true;
3163 bool ChatHandler::HandleLookupTaxiNodeCommand(const char * args)
3165 if(!*args)
3166 return false;
3168 std::string namepart = args;
3169 std::wstring wnamepart;
3171 if(!Utf8toWStr(namepart,wnamepart))
3172 return false;
3174 // converting string that we try to find to lower case
3175 wstrToLower( wnamepart );
3177 uint32 counter = 0; // Counter for figure out that we found smth.
3179 // Search in TaxiNodes.dbc
3180 for (uint32 id = 0; id < sTaxiNodesStore.GetNumRows(); id++)
3182 TaxiNodesEntry const *nodeEntry = sTaxiNodesStore.LookupEntry(id);
3183 if(nodeEntry)
3185 int loc = GetSessionDbcLocale();
3186 std::string name = nodeEntry->name[loc];
3187 if(name.empty())
3188 continue;
3190 if (!Utf8FitTo(name, wnamepart))
3192 loc = 0;
3193 for(; loc < MAX_LOCALE; ++loc)
3195 if(loc==GetSessionDbcLocale())
3196 continue;
3198 name = nodeEntry->name[loc];
3199 if(name.empty())
3200 continue;
3202 if (Utf8FitTo(name, wnamepart))
3203 break;
3207 if(loc < MAX_LOCALE)
3209 // send taxinode in "id - [name] (Map:m X:x Y:y Z:z)" format
3210 if (m_session)
3211 PSendSysMessage (LANG_TAXINODE_ENTRY_LIST_CHAT, id, id, name.c_str(),localeNames[loc],
3212 nodeEntry->map_id,nodeEntry->x,nodeEntry->y,nodeEntry->z);
3213 else
3214 PSendSysMessage (LANG_TAXINODE_ENTRY_LIST_CONSOLE, id, name.c_str(), localeNames[loc],
3215 nodeEntry->map_id,nodeEntry->x,nodeEntry->y,nodeEntry->z);
3216 ++counter;
3220 if (counter == 0) // if counter == 0 then we found nth
3221 SendSysMessage(LANG_COMMAND_NOTAXINODEFOUND);
3222 return true;
3225 /** \brief GM command level 3 - Create a guild.
3227 * This command allows a GM (level 3) to create a guild.
3229 * The "args" parameter contains the name of the guild leader
3230 * and then the name of the guild.
3233 bool ChatHandler::HandleGuildCreateCommand(const char* args)
3235 if(!*args)
3236 return false;
3238 // if not guild name only (in "") then player name
3239 Player* target;
3240 if(!extractPlayerTarget(*args!='"' ? (char*)args : NULL, &target))
3241 return false;
3243 char* tailStr = *args!='"' ? strtok(NULL, "") : (char*)args;
3244 if(!tailStr)
3245 return false;
3247 char* guildStr = extractQuotedArg(tailStr);
3248 if(!guildStr)
3249 return false;
3251 std::string guildname = guildStr;
3253 if (target->GetGuildId())
3255 SendSysMessage (LANG_PLAYER_IN_GUILD);
3256 return true;
3259 Guild *guild = new Guild;
3260 if (!guild->Create (target,guildname))
3262 delete guild;
3263 SendSysMessage (LANG_GUILD_NOT_CREATED);
3264 SetSentErrorMessage (true);
3265 return false;
3268 sObjectMgr.AddGuild (guild);
3269 return true;
3272 bool ChatHandler::HandleGuildInviteCommand(const char *args)
3274 if(!*args)
3275 return false;
3277 // if not guild name only (in "") then player name
3278 uint64 target_guid;
3279 if(!extractPlayerTarget(*args!='"' ? (char*)args : NULL, NULL, &target_guid))
3280 return false;
3282 char* tailStr = *args!='"' ? strtok(NULL, "") : (char*)args;
3283 if(!tailStr)
3284 return false;
3286 char* guildStr = extractQuotedArg(tailStr);
3287 if(!guildStr)
3288 return false;
3290 std::string glName = guildStr;
3291 Guild* targetGuild = sObjectMgr.GetGuildByName (glName);
3292 if (!targetGuild)
3293 return false;
3295 // player's guild membership checked in AddMember before add
3296 if (!targetGuild->AddMember (target_guid,targetGuild->GetLowestRank ()))
3297 return false;
3299 return true;
3302 bool ChatHandler::HandleGuildUninviteCommand(const char *args)
3304 Player* target;
3305 uint64 target_guid;
3306 if(!extractPlayerTarget((char*)args,&target,&target_guid))
3307 return false;
3309 uint32 glId = target ? target->GetGuildId () : Player::GetGuildIdFromDB (target_guid);
3310 if (!glId)
3311 return false;
3313 Guild* targetGuild = sObjectMgr.GetGuildById (glId);
3314 if (!targetGuild)
3315 return false;
3317 targetGuild->DelMember (target_guid);
3318 return true;
3321 bool ChatHandler::HandleGuildRankCommand(const char *args)
3323 char* nameStr;
3324 char* rankStr;
3325 extractOptFirstArg((char*)args,&nameStr,&rankStr);
3326 if(!rankStr)
3327 return false;
3329 Player* target;
3330 uint64 target_guid;
3331 std::string target_name;
3332 if(!extractPlayerTarget(nameStr,&target,&target_guid,&target_name))
3333 return false;
3335 uint32 glId = target ? target->GetGuildId () : Player::GetGuildIdFromDB (target_guid);
3336 if (!glId)
3337 return false;
3339 Guild* targetGuild = sObjectMgr.GetGuildById (glId);
3340 if (!targetGuild)
3341 return false;
3343 uint32 newrank = uint32 (atoi (rankStr));
3344 if (newrank > targetGuild->GetLowestRank ())
3345 return false;
3347 targetGuild->ChangeRank (target_guid,newrank);
3348 return true;
3351 bool ChatHandler::HandleGuildDeleteCommand(const char* args)
3353 if (!*args)
3354 return false;
3356 char* guildStr = extractQuotedArg((char*)args);
3357 if(!guildStr)
3358 return false;
3360 std::string gld = guildStr;
3362 Guild* targetGuild = sObjectMgr.GetGuildByName (gld);
3363 if (!targetGuild)
3364 return false;
3366 targetGuild->Disband ();
3368 return true;
3371 bool ChatHandler::HandleGetDistanceCommand(const char* args)
3373 WorldObject* obj = NULL;
3375 if (*args)
3377 uint64 guid = extractGuidFromLink((char*)args);
3378 if(guid)
3379 obj = (WorldObject*)m_session->GetPlayer()->GetObjectByTypeMask(guid, TYPEMASK_CREATURE_OR_GAMEOBJECT);
3381 if(!obj)
3383 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3384 SetSentErrorMessage(true);
3385 return false;
3388 else
3390 obj = getSelectedUnit();
3392 if(!obj)
3394 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3395 SetSentErrorMessage(true);
3396 return false;
3400 PSendSysMessage(LANG_DISTANCE, m_session->GetPlayer()->GetDistance(obj),m_session->GetPlayer()->GetDistance2d(obj));
3402 return true;
3405 bool ChatHandler::HandleDieCommand(const char* /*args*/)
3407 Unit* target = getSelectedUnit();
3409 if(!target || !m_session->GetPlayer()->GetSelection())
3411 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3412 SetSentErrorMessage(true);
3413 return false;
3416 if(target->GetTypeId()==TYPEID_PLAYER)
3418 if(HasLowerSecurity((Player*)target,0,false))
3419 return false;
3422 if( target->isAlive() )
3424 m_session->GetPlayer()->DealDamage(target, target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
3427 return true;
3430 bool ChatHandler::HandleDamageCommand(const char * args)
3432 if (!*args)
3433 return false;
3435 Unit* target = getSelectedUnit();
3437 if (!target || !m_session->GetPlayer()->GetSelection())
3439 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3440 SetSentErrorMessage(true);
3441 return false;
3444 if (!target->isAlive())
3445 return true;
3447 char* damageStr = strtok((char*)args, " ");
3448 if (!damageStr)
3449 return false;
3451 int32 damage_int = atoi((char*)damageStr);
3452 if(damage_int <=0)
3453 return true;
3455 uint32 damage = damage_int;
3457 char* schoolStr = strtok((char*)NULL, " ");
3459 // flat melee damage without resistence/etc reduction
3460 if (!schoolStr)
3462 m_session->GetPlayer()->DealDamage(target, damage, NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
3463 if (target != m_session->GetPlayer())
3464 m_session->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2, target, 1, SPELL_SCHOOL_MASK_NORMAL, damage, 0, 0, VICTIMSTATE_NORMAL, 0);
3465 return true;
3468 uint32 school = schoolStr ? atoi((char*)schoolStr) : SPELL_SCHOOL_NORMAL;
3469 if(school >= MAX_SPELL_SCHOOL)
3470 return false;
3472 SpellSchoolMask schoolmask = SpellSchoolMask(1 << school);
3474 if ( schoolmask & SPELL_SCHOOL_MASK_NORMAL )
3475 damage = m_session->GetPlayer()->CalcArmorReducedDamage(target, damage);
3477 char* spellStr = strtok((char*)NULL, " ");
3479 // melee damage by specific school
3480 if (!spellStr)
3482 uint32 absorb = 0;
3483 uint32 resist = 0;
3485 target->CalculateAbsorbAndResist(m_session->GetPlayer(),schoolmask, SPELL_DIRECT_DAMAGE, damage, &absorb, &resist);
3487 if (damage <= absorb + resist)
3488 return true;
3490 damage -= absorb + resist;
3492 m_session->GetPlayer()->DealDamageMods(target,damage,&absorb);
3493 m_session->GetPlayer()->DealDamage(target, damage, NULL, DIRECT_DAMAGE, schoolmask, NULL, false);
3494 m_session->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2, target, 1, schoolmask, damage, absorb, resist, VICTIMSTATE_NORMAL, 0);
3495 return true;
3498 // non-melee damage
3500 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3501 uint32 spellid = extractSpellIdFromLink((char*)args);
3502 if (!spellid || !sSpellStore.LookupEntry(spellid))
3503 return false;
3505 m_session->GetPlayer()->SpellNonMeleeDamageLog(target, spellid, damage);
3506 return true;
3509 bool ChatHandler::HandleModifyArenaCommand(const char * args)
3511 if (!*args)
3512 return false;
3514 Player *target = getSelectedPlayer();
3515 if(!target)
3517 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3518 SetSentErrorMessage(true);
3519 return false;
3522 int32 amount = (uint32)atoi(args);
3524 target->ModifyArenaPoints(amount);
3526 PSendSysMessage(LANG_COMMAND_MODIFY_ARENA, GetNameLink(target).c_str(), target->GetArenaPoints());
3528 return true;
3531 bool ChatHandler::HandleReviveCommand(const char* args)
3533 Player* target;
3534 uint64 target_guid;
3535 if(!extractPlayerTarget((char*)args,&target,&target_guid))
3536 return false;
3538 if (target)
3540 target->ResurrectPlayer(0.5f);
3541 target->SpawnCorpseBones();
3543 else
3544 // will resurrected at login without corpse
3545 sObjectAccessor.ConvertCorpseForPlayer(target_guid);
3547 return true;
3550 bool ChatHandler::HandleAuraCommand(const char* args)
3552 Unit *target = getSelectedUnit();
3553 if(!target)
3555 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3556 SetSentErrorMessage(true);
3557 return false;
3560 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3561 uint32 spellID = extractSpellIdFromLink((char*)args);
3563 SpellEntry const *spellInfo = sSpellStore.LookupEntry( spellID );
3564 if(spellInfo)
3566 for(uint32 i = 0; i < MAX_EFFECT_INDEX; ++i)
3568 uint8 eff = spellInfo->Effect[i];
3569 if (eff>=TOTAL_SPELL_EFFECTS)
3570 continue;
3571 if( IsAreaAuraEffect(eff) ||
3572 eff == SPELL_EFFECT_APPLY_AURA ||
3573 eff == SPELL_EFFECT_PERSISTENT_AREA_AURA )
3575 Aura *Aur = CreateAura(spellInfo, SpellEffectIndex(i), NULL, target);
3576 target->AddAura(Aur);
3581 return true;
3584 bool ChatHandler::HandleUnAuraCommand(const char* args)
3586 Unit *target = getSelectedUnit();
3587 if(!target)
3589 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3590 SetSentErrorMessage(true);
3591 return false;
3594 std::string argstr = args;
3595 if (argstr == "all")
3597 target->RemoveAllAuras();
3598 return true;
3601 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3602 uint32 spellID = extractSpellIdFromLink((char*)args);
3603 if(!spellID)
3604 return false;
3606 target->RemoveAurasDueToSpell(spellID);
3608 return true;
3611 bool ChatHandler::HandleLinkGraveCommand(const char* args)
3613 if(!*args)
3614 return false;
3616 char* px = strtok((char*)args, " ");
3617 if (!px)
3618 return false;
3620 uint32 g_id = (uint32)atoi(px);
3622 uint32 g_team;
3624 char* px2 = strtok(NULL, " ");
3626 if (!px2)
3627 g_team = 0;
3628 else if (strncmp(px2,"horde",6)==0)
3629 g_team = HORDE;
3630 else if (strncmp(px2,"alliance",9)==0)
3631 g_team = ALLIANCE;
3632 else
3633 return false;
3635 WorldSafeLocsEntry const* graveyard = sWorldSafeLocsStore.LookupEntry(g_id);
3637 if(!graveyard )
3639 PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST, g_id);
3640 SetSentErrorMessage(true);
3641 return false;
3644 Player* player = m_session->GetPlayer();
3646 uint32 zoneId = player->GetZoneId();
3648 AreaTableEntry const *areaEntry = GetAreaEntryByAreaID(zoneId);
3649 if(!areaEntry || areaEntry->zone !=0 )
3651 PSendSysMessage(LANG_COMMAND_GRAVEYARDWRONGZONE, g_id,zoneId);
3652 SetSentErrorMessage(true);
3653 return false;
3656 if(sObjectMgr.AddGraveYardLink(g_id,zoneId,g_team))
3657 PSendSysMessage(LANG_COMMAND_GRAVEYARDLINKED, g_id,zoneId);
3658 else
3659 PSendSysMessage(LANG_COMMAND_GRAVEYARDALRLINKED, g_id,zoneId);
3661 return true;
3664 bool ChatHandler::HandleNearGraveCommand(const char* args)
3666 uint32 g_team;
3668 size_t argslen = strlen(args);
3670 if(!*args)
3671 g_team = 0;
3672 else if (strncmp((char*)args,"horde",argslen)==0)
3673 g_team = HORDE;
3674 else if (strncmp((char*)args,"alliance",argslen)==0)
3675 g_team = ALLIANCE;
3676 else
3677 return false;
3679 Player* player = m_session->GetPlayer();
3680 uint32 zone_id = player->GetZoneId();
3682 WorldSafeLocsEntry const* graveyard = sObjectMgr.GetClosestGraveYard(
3683 player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(),player->GetMapId(),g_team);
3685 if(graveyard)
3687 uint32 g_id = graveyard->ID;
3689 GraveYardData const* data = sObjectMgr.FindGraveYardData(g_id,zone_id);
3690 if (!data)
3692 PSendSysMessage(LANG_COMMAND_GRAVEYARDERROR,g_id);
3693 SetSentErrorMessage(true);
3694 return false;
3697 g_team = data->team;
3699 std::string team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_NOTEAM);
3701 if(g_team == 0)
3702 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ANY);
3703 else if(g_team == HORDE)
3704 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE);
3705 else if(g_team == ALLIANCE)
3706 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE);
3708 PSendSysMessage(LANG_COMMAND_GRAVEYARDNEAREST, g_id,team_name.c_str(),zone_id);
3710 else
3712 std::string team_name;
3714 if(g_team == 0)
3715 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ANY);
3716 else if(g_team == HORDE)
3717 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE);
3718 else if(g_team == ALLIANCE)
3719 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE);
3721 if(g_team == ~uint32(0))
3722 PSendSysMessage(LANG_COMMAND_ZONENOGRAVEYARDS, zone_id);
3723 else
3724 PSendSysMessage(LANG_COMMAND_ZONENOGRAFACTION, zone_id,team_name.c_str());
3727 return true;
3730 //-----------------------Npc Commands-----------------------
3731 bool ChatHandler::HandleNpcAllowMovementCommand(const char* /*args*/)
3733 if(sWorld.getAllowMovement())
3735 sWorld.SetAllowMovement(false);
3736 SendSysMessage(LANG_CREATURE_MOVE_DISABLED);
3738 else
3740 sWorld.SetAllowMovement(true);
3741 SendSysMessage(LANG_CREATURE_MOVE_ENABLED);
3743 return true;
3746 bool ChatHandler::HandleNpcChangeEntryCommand(const char *args)
3748 if (!*args)
3749 return false;
3751 uint32 newEntryNum = atoi(args);
3752 if(!newEntryNum)
3753 return false;
3755 Unit* unit = getSelectedUnit();
3756 if(!unit || unit->GetTypeId() != TYPEID_UNIT)
3758 SendSysMessage(LANG_SELECT_CREATURE);
3759 SetSentErrorMessage(true);
3760 return false;
3762 Creature* creature = (Creature*)unit;
3763 if(creature->UpdateEntry(newEntryNum))
3764 SendSysMessage(LANG_DONE);
3765 else
3766 SendSysMessage(LANG_ERROR);
3767 return true;
3770 bool ChatHandler::HandleNpcInfoCommand(const char* /*args*/)
3772 Creature* target = getSelectedCreature();
3774 if(!target)
3776 SendSysMessage(LANG_SELECT_CREATURE);
3777 SetSentErrorMessage(true);
3778 return false;
3781 uint32 faction = target->getFaction();
3782 uint32 npcflags = target->GetUInt32Value(UNIT_NPC_FLAGS);
3783 uint32 displayid = target->GetDisplayId();
3784 uint32 nativeid = target->GetNativeDisplayId();
3785 uint32 Entry = target->GetEntry();
3786 CreatureInfo const* cInfo = target->GetCreatureInfo();
3788 time_t curRespawnDelay = target->GetRespawnTimeEx()-time(NULL);
3789 if(curRespawnDelay < 0)
3790 curRespawnDelay = 0;
3791 std::string curRespawnDelayStr = secsToTimeString(curRespawnDelay,true);
3792 std::string defRespawnDelayStr = secsToTimeString(target->GetRespawnDelay(),true);
3794 PSendSysMessage(LANG_NPCINFO_CHAR, target->GetDBTableGUIDLow(), faction, npcflags, Entry, displayid, nativeid);
3795 PSendSysMessage(LANG_NPCINFO_LEVEL, target->getLevel());
3796 PSendSysMessage(LANG_NPCINFO_HEALTH,target->GetCreateHealth(), target->GetMaxHealth(), target->GetHealth());
3797 PSendSysMessage(LANG_NPCINFO_FLAGS, target->GetUInt32Value(UNIT_FIELD_FLAGS), target->GetUInt32Value(UNIT_DYNAMIC_FLAGS), target->getFaction());
3798 PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES, defRespawnDelayStr.c_str(),curRespawnDelayStr.c_str());
3799 PSendSysMessage(LANG_NPCINFO_LOOT, cInfo->lootid,cInfo->pickpocketLootId,cInfo->SkinLootId);
3800 PSendSysMessage(LANG_NPCINFO_DUNGEON_ID, target->GetInstanceId());
3801 PSendSysMessage(LANG_NPCINFO_POSITION,float(target->GetPositionX()), float(target->GetPositionY()), float(target->GetPositionZ()));
3803 if ((npcflags & UNIT_NPC_FLAG_VENDOR) )
3805 SendSysMessage(LANG_NPCINFO_VENDOR);
3807 if ((npcflags & UNIT_NPC_FLAG_TRAINER) )
3809 SendSysMessage(LANG_NPCINFO_TRAINER);
3812 return true;
3815 //play npc emote
3816 bool ChatHandler::HandleNpcPlayEmoteCommand(const char* args)
3818 uint32 emote = atoi((char*)args);
3820 Creature* target = getSelectedCreature();
3821 if(!target)
3823 SendSysMessage(LANG_SELECT_CREATURE);
3824 SetSentErrorMessage(true);
3825 return false;
3828 target->HandleEmote(emote);
3830 return true;
3833 //TODO: NpcCommands that needs to be fixed :
3835 bool ChatHandler::HandleNpcAddWeaponCommand(const char* /*args*/)
3837 /*if (!*args)
3838 return false;
3840 uint64 guid = m_session->GetPlayer()->GetSelection();
3841 if (guid == 0)
3843 SendSysMessage(LANG_NO_SELECTION);
3844 return true;
3847 Creature *pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
3849 if(!pCreature)
3851 SendSysMessage(LANG_SELECT_CREATURE);
3852 return true;
3855 char* pSlotID = strtok((char*)args, " ");
3856 if (!pSlotID)
3857 return false;
3859 char* pItemID = strtok(NULL, " ");
3860 if (!pItemID)
3861 return false;
3863 uint32 ItemID = atoi(pItemID);
3864 uint32 SlotID = atoi(pSlotID);
3866 ItemPrototype* tmpItem = ObjectMgr::GetItemPrototype(ItemID);
3868 bool added = false;
3869 if(tmpItem)
3871 switch(SlotID)
3873 case 1:
3874 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID);
3875 added = true;
3876 break;
3877 case 2:
3878 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID);
3879 added = true;
3880 break;
3881 case 3:
3882 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID);
3883 added = true;
3884 break;
3885 default:
3886 PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST,SlotID);
3887 added = false;
3888 break;
3891 if(added)
3892 PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT,ItemID,tmpItem->Name1,SlotID);
3894 else
3896 PSendSysMessage(LANG_ITEM_NOT_FOUND,ItemID);
3897 return true;
3900 return true;
3902 //----------------------------------------------------------
3904 bool ChatHandler::HandleExploreCheatCommand(const char* args)
3906 if (!*args)
3907 return false;
3909 int flag = atoi((char*)args);
3911 Player *chr = getSelectedPlayer();
3912 if (chr == NULL)
3914 SendSysMessage(LANG_NO_CHAR_SELECTED);
3915 SetSentErrorMessage(true);
3916 return false;
3919 if (flag != 0)
3921 PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL, GetNameLink(chr).c_str());
3922 if (needReportToTarget(chr))
3923 ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_ALL,GetNameLink().c_str());
3925 else
3927 PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING, GetNameLink(chr).c_str());
3928 if (needReportToTarget(chr))
3929 ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_NOTHING,GetNameLink().c_str());
3932 for (uint8 i=0; i<PLAYER_EXPLORED_ZONES_SIZE; ++i)
3934 if (flag != 0)
3936 m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1+i,0xFFFFFFFF);
3938 else
3940 m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1+i,0);
3944 return true;
3947 bool ChatHandler::HandleHoverCommand(const char* args)
3949 char* px = strtok((char*)args, " ");
3950 uint32 flag;
3951 if (!px)
3952 flag = 1;
3953 else
3954 flag = atoi(px);
3956 m_session->GetPlayer()->SetHover(flag);
3958 if (flag)
3959 SendSysMessage(LANG_HOVER_ENABLED);
3960 else
3961 SendSysMessage(LANG_HOVER_DISABLED);
3963 return true;
3966 void ChatHandler::HandleCharacterLevel(Player* player, uint64 player_guid, uint32 oldlevel, uint32 newlevel)
3968 if(player)
3970 player->GiveLevel(newlevel);
3971 player->InitTalentForLevel();
3972 player->SetUInt32Value(PLAYER_XP,0);
3974 if(needReportToTarget(player))
3976 if(oldlevel == newlevel)
3977 ChatHandler(player).PSendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET,GetNameLink().c_str());
3978 else if(oldlevel < newlevel)
3979 ChatHandler(player).PSendSysMessage(LANG_YOURS_LEVEL_UP,GetNameLink().c_str(),newlevel);
3980 else // if(oldlevel > newlevel)
3981 ChatHandler(player).PSendSysMessage(LANG_YOURS_LEVEL_DOWN,GetNameLink().c_str(),newlevel);
3984 else
3986 // update level and XP at level, all other will be updated at loading
3987 CharacterDatabase.PExecute("UPDATE characters SET level = '%u', xp = 0 WHERE guid = '%u'", newlevel, GUID_LOPART(player_guid));
3991 bool ChatHandler::HandleCharacterLevelCommand(const char* args)
3993 char* nameStr;
3994 char* levelStr;
3995 extractOptFirstArg((char*)args,&nameStr,&levelStr);
3996 if(!levelStr)
3997 return false;
3999 // exception opt second arg: .character level $name
4000 if(isalpha(levelStr[0]))
4002 nameStr = levelStr;
4003 levelStr = NULL; // current level will used
4006 Player* target;
4007 uint64 target_guid;
4008 std::string target_name;
4009 if(!extractPlayerTarget(nameStr,&target,&target_guid,&target_name))
4010 return false;
4012 int32 oldlevel = target ? target->getLevel() : Player::GetLevelFromDB(target_guid);
4013 int32 newlevel = levelStr ? atoi(levelStr) : oldlevel;
4015 if(newlevel < 1)
4016 return false; // invalid level
4018 if(newlevel > STRONG_MAX_LEVEL) // hardcoded maximum level
4019 newlevel = STRONG_MAX_LEVEL;
4021 HandleCharacterLevel(target,target_guid,oldlevel,newlevel);
4023 if(!m_session || m_session->GetPlayer() != target) // including player==NULL
4025 std::string nameLink = playerLink(target_name);
4026 PSendSysMessage(LANG_YOU_CHANGE_LVL,nameLink.c_str(),newlevel);
4029 return true;
4032 bool ChatHandler::HandleLevelUpCommand(const char* args)
4034 char* nameStr;
4035 char* levelStr;
4036 extractOptFirstArg((char*)args,&nameStr,&levelStr);
4038 // exception opt second arg: .character level $name
4039 if(levelStr && isalpha(levelStr[0]))
4041 nameStr = levelStr;
4042 levelStr = NULL; // current level will used
4045 Player* target;
4046 uint64 target_guid;
4047 std::string target_name;
4048 if(!extractPlayerTarget(nameStr,&target,&target_guid,&target_name))
4049 return false;
4051 int32 oldlevel = target ? target->getLevel() : Player::GetLevelFromDB(target_guid);
4052 int32 addlevel = levelStr ? atoi(levelStr) : 1;
4053 int32 newlevel = oldlevel + addlevel;
4055 if(newlevel < 1)
4056 newlevel = 1;
4058 if(newlevel > STRONG_MAX_LEVEL) // hardcoded maximum level
4059 newlevel = STRONG_MAX_LEVEL;
4061 HandleCharacterLevel(target,target_guid,oldlevel,newlevel);
4063 if(!m_session || m_session->GetPlayer() != target) // including chr==NULL
4065 std::string nameLink = playerLink(target_name);
4066 PSendSysMessage(LANG_YOU_CHANGE_LVL,nameLink.c_str(),newlevel);
4069 return true;
4072 bool ChatHandler::HandleShowAreaCommand(const char* args)
4074 if (!*args)
4075 return false;
4077 Player *chr = getSelectedPlayer();
4078 if (chr == NULL)
4080 SendSysMessage(LANG_NO_CHAR_SELECTED);
4081 SetSentErrorMessage(true);
4082 return false;
4085 int area = GetAreaFlagByAreaID(atoi((char*)args));
4086 int offset = area / 32;
4087 uint32 val = (uint32)(1 << (area % 32));
4089 if(area<0 || offset >= PLAYER_EXPLORED_ZONES_SIZE)
4091 SendSysMessage(LANG_BAD_VALUE);
4092 SetSentErrorMessage(true);
4093 return false;
4096 uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
4097 chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields | val));
4099 SendSysMessage(LANG_EXPLORE_AREA);
4100 return true;
4103 bool ChatHandler::HandleHideAreaCommand(const char* args)
4105 if (!*args)
4106 return false;
4108 Player *chr = getSelectedPlayer();
4109 if (chr == NULL)
4111 SendSysMessage(LANG_NO_CHAR_SELECTED);
4112 SetSentErrorMessage(true);
4113 return false;
4116 int area = GetAreaFlagByAreaID(atoi((char*)args));
4117 int offset = area / 32;
4118 uint32 val = (uint32)(1 << (area % 32));
4120 if(area<0 || offset >= PLAYER_EXPLORED_ZONES_SIZE)
4122 SendSysMessage(LANG_BAD_VALUE);
4123 SetSentErrorMessage(true);
4124 return false;
4127 uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
4128 chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields ^ val));
4130 SendSysMessage(LANG_UNEXPLORE_AREA);
4131 return true;
4134 bool ChatHandler::HandleBankCommand(const char* /*args*/)
4136 m_session->SendShowBank( m_session->GetPlayer()->GetGUID() );
4138 return true;
4141 bool ChatHandler::HandleChangeWeather(const char* args)
4143 if(!*args)
4144 return false;
4146 //Weather is OFF
4147 if (!sWorld.getConfig(CONFIG_BOOL_WEATHER))
4149 SendSysMessage(LANG_WEATHER_DISABLED);
4150 SetSentErrorMessage(true);
4151 return false;
4154 //*Change the weather of a cell
4155 char* px = strtok((char*)args, " ");
4156 char* py = strtok(NULL, " ");
4158 if (!px || !py)
4159 return false;
4161 uint32 type = (uint32)atoi(px); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
4162 float grade = (float)atof(py); //0 to 1, sending -1 is instand good weather
4164 Player *player = m_session->GetPlayer();
4165 uint32 zoneid = player->GetZoneId();
4167 Weather* wth = sWorld.FindWeather(zoneid);
4169 if(!wth)
4170 wth = sWorld.AddWeather(zoneid);
4171 if(!wth)
4173 SendSysMessage(LANG_NO_WEATHER);
4174 SetSentErrorMessage(true);
4175 return false;
4178 wth->SetWeather(WeatherType(type), grade);
4180 return true;
4183 bool ChatHandler::HandleTeleAddCommand(const char * args)
4185 if(!*args)
4186 return false;
4188 Player *player=m_session->GetPlayer();
4189 if (!player)
4190 return false;
4192 std::string name = args;
4194 if(sObjectMgr.GetGameTele(name))
4196 SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST);
4197 SetSentErrorMessage(true);
4198 return false;
4201 GameTele tele;
4202 tele.position_x = player->GetPositionX();
4203 tele.position_y = player->GetPositionY();
4204 tele.position_z = player->GetPositionZ();
4205 tele.orientation = player->GetOrientation();
4206 tele.mapId = player->GetMapId();
4207 tele.name = name;
4209 if(sObjectMgr.AddGameTele(tele))
4211 SendSysMessage(LANG_COMMAND_TP_ADDED);
4213 else
4215 SendSysMessage(LANG_COMMAND_TP_ADDEDERR);
4216 SetSentErrorMessage(true);
4217 return false;
4220 return true;
4223 bool ChatHandler::HandleTeleDelCommand(const char * args)
4225 if(!*args)
4226 return false;
4228 std::string name = args;
4230 if(!sObjectMgr.DeleteGameTele(name))
4232 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
4233 SetSentErrorMessage(true);
4234 return false;
4237 SendSysMessage(LANG_COMMAND_TP_DELETED);
4238 return true;
4241 bool ChatHandler::HandleListAurasCommand (const char * /*args*/)
4243 Unit *unit = getSelectedUnit();
4244 if(!unit)
4246 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4247 SetSentErrorMessage(true);
4248 return false;
4251 char const* talentStr = GetMangosString(LANG_TALENT);
4252 char const* passiveStr = GetMangosString(LANG_PASSIVE);
4254 Unit::AuraMap const& uAuras = unit->GetAuras();
4255 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS, uAuras.size());
4256 for (Unit::AuraMap::const_iterator itr = uAuras.begin(); itr != uAuras.end(); ++itr)
4258 bool talent = GetTalentSpellCost(itr->second->GetId()) > 0;
4260 char const* name = itr->second->GetSpellProto()->SpellName[GetSessionDbcLocale()];
4262 if (m_session)
4264 std::ostringstream ss_name;
4265 ss_name << "|cffffffff|Hspell:" << itr->second->GetId() << "|h[" << name << "]|h|r";
4267 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL, itr->second->GetId(), itr->second->GetEffIndex(),
4268 itr->second->GetModifier()->m_auraname, itr->second->GetAuraDuration(), itr->second->GetAuraMaxDuration(),
4269 ss_name.str().c_str(),
4270 (itr->second->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4271 IS_PLAYER_GUID(itr->second->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr->second->GetCasterGUID()));
4273 else
4275 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL, itr->second->GetId(), itr->second->GetEffIndex(),
4276 itr->second->GetModifier()->m_auraname, itr->second->GetAuraDuration(), itr->second->GetAuraMaxDuration(),
4277 name,
4278 (itr->second->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4279 IS_PLAYER_GUID(itr->second->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr->second->GetCasterGUID()));
4282 for (int i = 0; i < TOTAL_AURAS; ++i)
4284 Unit::AuraList const& uAuraList = unit->GetAurasByType(AuraType(i));
4285 if (uAuraList.empty()) continue;
4286 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE, uAuraList.size(), i);
4287 for (Unit::AuraList::const_iterator itr = uAuraList.begin(); itr != uAuraList.end(); ++itr)
4289 bool talent = GetTalentSpellCost((*itr)->GetId()) > 0;
4291 char const* name = (*itr)->GetSpellProto()->SpellName[GetSessionDbcLocale()];
4293 if (m_session)
4295 std::ostringstream ss_name;
4296 ss_name << "|cffffffff|Hspell:" << (*itr)->GetId() << "|h[" << name << "]|h|r";
4298 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE, (*itr)->GetId(), (*itr)->GetEffIndex(),
4299 ss_name.str().c_str(),((*itr)->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4300 IS_PLAYER_GUID((*itr)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr)->GetCasterGUID()));
4302 else
4304 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE, (*itr)->GetId(), (*itr)->GetEffIndex(),
4305 name,((*itr)->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4306 IS_PLAYER_GUID((*itr)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr)->GetCasterGUID()));
4310 return true;
4313 bool ChatHandler::HandleListTalentsCommand (const char * /*args*/)
4315 Player *player = getSelectedPlayer();
4316 if (!player)
4318 SendSysMessage(LANG_NO_CHAR_SELECTED);
4319 SetSentErrorMessage(true);
4320 return false;
4323 SendSysMessage(LANG_LIST_TALENTS_TITLE);
4324 uint32 count = 0;
4325 uint32 cost = 0;
4326 PlayerSpellMap const& uSpells = player->GetSpellMap();
4327 for (PlayerSpellMap::const_iterator itr = uSpells.begin(); itr != uSpells.end(); ++itr)
4329 if (itr->second.state == PLAYERSPELL_REMOVED || itr->second.disabled)
4330 continue;
4332 uint32 cost_itr = GetTalentSpellCost(itr->first);
4334 if (cost_itr == 0)
4335 continue;
4337 SpellEntry const* spellEntry = sSpellStore.LookupEntry(itr->first);
4338 if (!spellEntry)
4339 continue;
4341 ShowSpellListHelper(player, spellEntry, GetSessionDbcLocale());
4342 ++count;
4343 cost += cost_itr;
4345 PSendSysMessage(LANG_LIST_TALENTS_COUNT, count, cost);
4347 return true;
4350 bool ChatHandler::HandleResetAchievementsCommand (const char * args)
4352 Player* target;
4353 uint64 target_guid;
4354 if (!extractPlayerTarget((char*)args,&target,&target_guid))
4355 return false;
4357 if(target)
4358 target->GetAchievementMgr().Reset();
4359 else
4360 AchievementMgr::DeleteFromDB(GUID_LOPART(target_guid));
4362 return true;
4365 bool ChatHandler::HandleResetHonorCommand (const char * args)
4367 Player* target;
4368 if (!extractPlayerTarget((char*)args,&target))
4369 return false;
4371 target->SetUInt32Value(PLAYER_FIELD_KILLS, 0);
4372 target->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS, 0);
4373 target->SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY, 0);
4374 target->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION, 0);
4375 target->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION, 0);
4376 target->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_EARN_HONORABLE_KILL);
4378 return true;
4381 static bool HandleResetStatsOrLevelHelper(Player* player)
4383 ChrClassesEntry const* cEntry = sChrClassesStore.LookupEntry(player->getClass());
4384 if(!cEntry)
4386 sLog.outError("Class %u not found in DBC (Wrong DBC files?)",player->getClass());
4387 return false;
4390 uint8 powertype = cEntry->powerType;
4392 // reset m_form if no aura
4393 if(!player->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT))
4394 player->m_form = FORM_NONE;
4396 player->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, DEFAULT_WORLD_OBJECT_SIZE );
4397 player->SetFloatValue(UNIT_FIELD_COMBATREACH, 1.5f );
4399 player->setFactionForRace(player->getRace());
4401 player->SetUInt32Value(UNIT_FIELD_BYTES_0, ( ( player->getRace() ) | ( player->getClass() << 8 ) | ( player->getGender() << 16 ) | ( powertype << 24 ) ) );
4403 // reset only if player not in some form;
4404 if(player->m_form==FORM_NONE)
4405 player->InitDisplayIds();
4407 player->SetByteValue(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_PVP );
4408 player->SetByteValue(UNIT_FIELD_BYTES_2, 3, player->m_form);
4410 player->SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
4412 //-1 is default value
4413 player->SetInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX, -1);
4415 //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000 );
4416 return true;
4419 bool ChatHandler::HandleResetLevelCommand(const char * args)
4421 Player* target;
4422 if(!extractPlayerTarget((char*)args,&target))
4423 return false;
4425 if(!HandleResetStatsOrLevelHelper(target))
4426 return false;
4428 // set starting level
4429 uint32 start_level = target->getClass() != CLASS_DEATH_KNIGHT
4430 ? sWorld.getConfig(CONFIG_UINT32_START_PLAYER_LEVEL)
4431 : sWorld.getConfig(CONFIG_UINT32_START_HEROIC_PLAYER_LEVEL);
4433 target->_ApplyAllLevelScaleItemMods(false);
4435 target->SetLevel(start_level);
4436 target->InitRunes();
4437 target->InitStatsForLevel(true);
4438 target->InitTaxiNodesForLevel();
4439 target->InitGlyphsForLevel();
4440 target->InitTalentForLevel();
4441 target->SetUInt32Value(PLAYER_XP,0);
4443 target->_ApplyAllLevelScaleItemMods(true);
4445 // reset level for pet
4446 if(Pet* pet = target->GetPet())
4447 pet->SynchronizeLevelWithOwner();
4449 return true;
4452 bool ChatHandler::HandleResetStatsCommand(const char * args)
4454 Player* target;
4455 if (!extractPlayerTarget((char*)args,&target))
4456 return false;
4458 if (!HandleResetStatsOrLevelHelper(target))
4459 return false;
4461 target->InitRunes();
4462 target->InitStatsForLevel(true);
4463 target->InitTaxiNodesForLevel();
4464 target->InitGlyphsForLevel();
4465 target->InitTalentForLevel();
4467 return true;
4470 bool ChatHandler::HandleResetSpellsCommand(const char * args)
4472 Player* target;
4473 uint64 target_guid;
4474 std::string target_name;
4475 if(!extractPlayerTarget((char*)args, &target, &target_guid, &target_name))
4476 return false;
4478 if(target)
4480 target->resetSpells();
4482 ChatHandler(target).SendSysMessage(LANG_RESET_SPELLS);
4483 if(!m_session || m_session->GetPlayer()!=target)
4484 PSendSysMessage(LANG_RESET_SPELLS_ONLINE,GetNameLink(target).c_str());
4486 else
4488 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS), GUID_LOPART(target_guid));
4489 PSendSysMessage(LANG_RESET_SPELLS_OFFLINE,target_name.c_str());
4492 return true;
4495 bool ChatHandler::HandleResetSpecsCommand(const char * args)
4497 Player* target;
4498 uint64 target_guid;
4499 std::string target_name;
4500 if (!extractPlayerTarget((char*)args, &target, &target_guid, &target_name))
4501 return false;
4503 if (target)
4505 target->resetTalents(true,true);
4506 target->SendTalentsInfoData(false);
4507 ChatHandler(target).SendSysMessage(LANG_RESET_TALENTS);
4508 if (!m_session || m_session->GetPlayer() != target)
4509 PSendSysMessage(LANG_RESET_TALENTS_ONLINE,GetNameLink(target).c_str());
4511 Pet* pet = target->GetPet();
4512 Pet::resetTalentsForAllPetsOf(target, pet);
4513 if(pet)
4514 target->SendTalentsInfoData(true);
4515 return true;
4517 else if (target_guid)
4519 uint32 at_flags = AT_LOGIN_RESET_TALENTS | AT_LOGIN_RESET_PET_TALENTS;
4520 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'", at_flags, GUID_LOPART(target_guid) );
4521 std::string nameLink = playerLink(target_name);
4522 PSendSysMessage(LANG_RESET_TALENTS_OFFLINE, nameLink.c_str());
4523 return true;
4526 SendSysMessage(LANG_NO_CHAR_SELECTED);
4527 SetSentErrorMessage(true);
4528 return false;
4531 bool ChatHandler::HandleResetTalentsCommand(const char * args)
4533 Player* target;
4534 std::string target_name;
4535 if (!extractPlayerTarget((char*)args, &target, NULL, &target_name))
4537 // Try reset talents as Hunter Pet
4538 Creature* creature = getSelectedCreature();
4539 if (!*args && creature && creature->isPet())
4541 Unit *owner = creature->GetOwner();
4542 if(owner && owner->GetTypeId() == TYPEID_PLAYER && ((Pet *)creature)->IsPermanentPetFor((Player*)owner))
4544 ((Pet *)creature)->resetTalents(true);
4545 ((Player*)owner)->SendTalentsInfoData(true);
4547 ChatHandler((Player*)owner).SendSysMessage(LANG_RESET_PET_TALENTS);
4548 if(!m_session || m_session->GetPlayer() != ((Player*)owner))
4549 PSendSysMessage(LANG_RESET_PET_TALENTS_ONLINE,GetNameLink((Player*)owner).c_str());
4551 return true;
4554 SendSysMessage(LANG_NO_CHAR_SELECTED);
4555 SetSentErrorMessage(true);
4556 return false;
4559 if (target)
4561 target->resetTalents(true);
4562 target->SendTalentsInfoData(false);
4563 ChatHandler(target).SendSysMessage(LANG_RESET_TALENTS);
4564 if (!m_session || m_session->GetPlayer() != target)
4565 PSendSysMessage(LANG_RESET_TALENTS_ONLINE,GetNameLink(target).c_str());
4567 Pet* pet = target->GetPet();
4568 Pet::resetTalentsForAllPetsOf(target, pet);
4569 if(pet)
4570 target->SendTalentsInfoData(true);
4571 return true;
4574 SendSysMessage(LANG_NO_CHAR_SELECTED);
4575 SetSentErrorMessage(true);
4576 return false;
4579 bool ChatHandler::HandleResetAllCommand(const char * args)
4581 if(!*args)
4582 return false;
4584 std::string casename = args;
4586 AtLoginFlags atLogin;
4588 // Command specially created as single command to prevent using short case names
4589 if(casename=="spells")
4591 atLogin = AT_LOGIN_RESET_SPELLS;
4592 sWorld.SendWorldText(LANG_RESETALL_SPELLS);
4593 if(!m_session)
4594 SendSysMessage(LANG_RESETALL_SPELLS);
4596 else if(casename=="talents")
4598 atLogin = AtLoginFlags(AT_LOGIN_RESET_TALENTS | AT_LOGIN_RESET_PET_TALENTS);
4599 sWorld.SendWorldText(LANG_RESETALL_TALENTS);
4600 if(!m_session)
4601 SendSysMessage(LANG_RESETALL_TALENTS);
4603 else
4605 PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE,args);
4606 SetSentErrorMessage(true);
4607 return false;
4610 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE (at_login & '%u') = '0'",atLogin,atLogin);
4611 HashMapHolder<Player>::MapType const& plist = sObjectAccessor.GetPlayers();
4612 for(HashMapHolder<Player>::MapType::const_iterator itr = plist.begin(); itr != plist.end(); ++itr)
4613 itr->second->SetAtLoginFlag(atLogin);
4615 return true;
4618 bool ChatHandler::HandleServerShutDownCancelCommand(const char* /*args*/)
4620 sWorld.ShutdownCancel();
4621 return true;
4624 bool ChatHandler::HandleServerShutDownCommand(const char* args)
4626 if(!*args)
4627 return false;
4629 char* time_str = strtok ((char*) args, " ");
4630 char* exitcode_str = strtok (NULL, "");
4632 int32 time = atoi (time_str);
4634 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4635 if ((time == 0 && (time_str[0]!='0' || time_str[1]!='\0')) || time < 0)
4636 return false;
4638 if (exitcode_str)
4640 int32 exitcode = atoi (exitcode_str);
4642 // Handle atoi() errors
4643 if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
4644 return false;
4646 // Exit code should be in range of 0-125, 126-255 is used
4647 // in many shells for their own return codes and code > 255
4648 // is not supported in many others
4649 if (exitcode < 0 || exitcode > 125)
4650 return false;
4652 sWorld.ShutdownServ (time, 0, exitcode);
4654 else
4655 sWorld.ShutdownServ(time,0,SHUTDOWN_EXIT_CODE);
4656 return true;
4659 bool ChatHandler::HandleServerRestartCommand(const char* args)
4661 if(!*args)
4662 return false;
4664 char* time_str = strtok ((char*) args, " ");
4665 char* exitcode_str = strtok (NULL, "");
4667 int32 time = atoi (time_str);
4669 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4670 if ((time == 0 && (time_str[0]!='0' || time_str[1]!='\0')) || time < 0)
4671 return false;
4673 if (exitcode_str)
4675 int32 exitcode = atoi (exitcode_str);
4677 // Handle atoi() errors
4678 if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
4679 return false;
4681 // Exit code should be in range of 0-125, 126-255 is used
4682 // in many shells for their own return codes and code > 255
4683 // is not supported in many others
4684 if (exitcode < 0 || exitcode > 125)
4685 return false;
4687 sWorld.ShutdownServ (time, SHUTDOWN_MASK_RESTART, exitcode);
4689 else
4690 sWorld.ShutdownServ(time, SHUTDOWN_MASK_RESTART, RESTART_EXIT_CODE);
4691 return true;
4694 bool ChatHandler::HandleServerIdleRestartCommand(const char* args)
4696 if(!*args)
4697 return false;
4699 char* time_str = strtok ((char*) args, " ");
4700 char* exitcode_str = strtok (NULL, "");
4702 int32 time = atoi (time_str);
4704 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4705 if ((time == 0 && (time_str[0]!='0' || time_str[1]!='\0')) || time < 0)
4706 return false;
4708 if (exitcode_str)
4710 int32 exitcode = atoi (exitcode_str);
4712 // Handle atoi() errors
4713 if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
4714 return false;
4716 // Exit code should be in range of 0-125, 126-255 is used
4717 // in many shells for their own return codes and code > 255
4718 // is not supported in many others
4719 if (exitcode < 0 || exitcode > 125)
4720 return false;
4722 sWorld.ShutdownServ (time, SHUTDOWN_MASK_RESTART|SHUTDOWN_MASK_IDLE, exitcode);
4724 else
4725 sWorld.ShutdownServ(time,SHUTDOWN_MASK_RESTART|SHUTDOWN_MASK_IDLE,RESTART_EXIT_CODE);
4726 return true;
4729 bool ChatHandler::HandleServerIdleShutDownCommand(const char* args)
4731 if(!*args)
4732 return false;
4734 char* time_str = strtok ((char*) args, " ");
4735 char* exitcode_str = strtok (NULL, "");
4737 int32 time = atoi (time_str);
4739 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4740 if ((time == 0 && (time_str[0]!='0' || time_str[1]!='\0')) || time < 0)
4741 return false;
4743 if (exitcode_str)
4745 int32 exitcode = atoi (exitcode_str);
4747 // Handle atoi() errors
4748 if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
4749 return false;
4751 // Exit code should be in range of 0-125, 126-255 is used
4752 // in many shells for their own return codes and code > 255
4753 // is not supported in many others
4754 if (exitcode < 0 || exitcode > 125)
4755 return false;
4757 sWorld.ShutdownServ (time, SHUTDOWN_MASK_IDLE, exitcode);
4759 else
4760 sWorld.ShutdownServ(time,SHUTDOWN_MASK_IDLE,SHUTDOWN_EXIT_CODE);
4761 return true;
4764 bool ChatHandler::HandleQuestAdd(const char* args)
4766 Player* player = getSelectedPlayer();
4767 if(!player)
4769 SendSysMessage(LANG_NO_CHAR_SELECTED);
4770 SetSentErrorMessage(true);
4771 return false;
4774 // .addquest #entry'
4775 // number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
4776 char* cId = extractKeyFromLink((char*)args,"Hquest");
4777 if(!cId)
4778 return false;
4780 uint32 entry = atol(cId);
4782 Quest const* pQuest = sObjectMgr.GetQuestTemplate(entry);
4784 if(!pQuest)
4786 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND,entry);
4787 SetSentErrorMessage(true);
4788 return false;
4791 // check item starting quest (it can work incorrectly if added without item in inventory)
4792 for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
4794 ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype>(id);
4795 if (!pProto)
4796 continue;
4798 if (pProto->StartQuest == entry)
4800 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, entry, pProto->ItemId);
4801 SetSentErrorMessage(true);
4802 return false;
4806 // ok, normal (creature/GO starting) quest
4807 if( player->CanAddQuest( pQuest, true ) )
4809 player->AddQuest( pQuest, NULL );
4811 if ( player->CanCompleteQuest( entry ) )
4812 player->CompleteQuest( entry );
4815 return true;
4818 bool ChatHandler::HandleQuestRemove(const char* args)
4820 Player* player = getSelectedPlayer();
4821 if(!player)
4823 SendSysMessage(LANG_NO_CHAR_SELECTED);
4824 SetSentErrorMessage(true);
4825 return false;
4828 // .removequest #entry'
4829 // number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
4830 char* cId = extractKeyFromLink((char*)args,"Hquest");
4831 if(!cId)
4832 return false;
4834 uint32 entry = atol(cId);
4836 Quest const* pQuest = sObjectMgr.GetQuestTemplate(entry);
4838 if(!pQuest)
4840 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
4841 SetSentErrorMessage(true);
4842 return false;
4845 // remove all quest entries for 'entry' from quest log
4846 for(uint8 slot = 0; slot < MAX_QUEST_LOG_SIZE; ++slot )
4848 uint32 quest = player->GetQuestSlotQuestId(slot);
4849 if(quest==entry)
4851 player->SetQuestSlot(slot,0);
4853 // we ignore unequippable quest items in this case, its' still be equipped
4854 player->TakeQuestSourceItem( quest, false );
4858 // set quest status to not started (will updated in DB at next save)
4859 player->SetQuestStatus( entry, QUEST_STATUS_NONE);
4861 // reset rewarded for restart repeatable quest
4862 player->getQuestStatusMap()[entry].m_rewarded = false;
4864 SendSysMessage(LANG_COMMAND_QUEST_REMOVED);
4865 return true;
4868 bool ChatHandler::HandleQuestComplete(const char* args)
4870 Player* player = getSelectedPlayer();
4871 if(!player)
4873 SendSysMessage(LANG_NO_CHAR_SELECTED);
4874 SetSentErrorMessage(true);
4875 return false;
4878 // .quest complete #entry
4879 // number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
4880 char* cId = extractKeyFromLink((char*)args,"Hquest");
4881 if(!cId)
4882 return false;
4884 uint32 entry = atol(cId);
4886 Quest const* pQuest = sObjectMgr.GetQuestTemplate(entry);
4888 // If player doesn't have the quest
4889 if(!pQuest || player->GetQuestStatus(entry) == QUEST_STATUS_NONE)
4891 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
4892 SetSentErrorMessage(true);
4893 return false;
4896 // Add quest items for quests that require items
4897 for(uint8 x = 0; x < QUEST_ITEM_OBJECTIVES_COUNT; ++x)
4899 uint32 id = pQuest->ReqItemId[x];
4900 uint32 count = pQuest->ReqItemCount[x];
4901 if(!id || !count)
4902 continue;
4904 uint32 curItemCount = player->GetItemCount(id,true);
4906 ItemPosCountVec dest;
4907 uint8 msg = player->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, id, count - curItemCount );
4908 if( msg == EQUIP_ERR_OK )
4910 Item* item = player->StoreNewItem( dest, id, true);
4911 player->SendNewItem(item,count-curItemCount, true, false);
4915 // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
4916 for(uint8 i = 0; i < QUEST_OBJECTIVES_COUNT; ++i)
4918 int32 creature = pQuest->ReqCreatureOrGOId[i];
4919 uint32 creaturecount = pQuest->ReqCreatureOrGOCount[i];
4921 if(uint32 spell_id = pQuest->ReqSpell[i])
4923 for(uint16 z = 0; z < creaturecount; ++z)
4924 player->CastedCreatureOrGO(creature, ObjectGuid(), spell_id);
4926 else if(creature > 0)
4928 if(CreatureInfo const* cInfo = ObjectMgr::GetCreatureTemplate(creature))
4929 for(uint16 z = 0; z < creaturecount; ++z)
4930 player->KilledMonster(cInfo, ObjectGuid());
4932 else if(creature < 0)
4934 for(uint16 z = 0; z < creaturecount; ++z)
4935 player->CastedCreatureOrGO(-creature, ObjectGuid(), 0);
4939 // If the quest requires reputation to complete
4940 if(uint32 repFaction = pQuest->GetRepObjectiveFaction())
4942 uint32 repValue = pQuest->GetRepObjectiveValue();
4943 uint32 curRep = player->GetReputationMgr().GetReputation(repFaction);
4944 if(curRep < repValue)
4945 if(FactionEntry const *factionEntry = sFactionStore.LookupEntry(repFaction))
4946 player->GetReputationMgr().SetReputation(factionEntry,repValue);
4949 // If the quest requires money
4950 int32 ReqOrRewMoney = pQuest->GetRewOrReqMoney();
4951 if(ReqOrRewMoney < 0)
4952 player->ModifyMoney(-ReqOrRewMoney);
4954 player->CompleteQuest(entry);
4955 return true;
4958 bool ChatHandler::HandleBanAccountCommand(const char* args)
4960 return HandleBanHelper(BAN_ACCOUNT,args);
4963 bool ChatHandler::HandleBanCharacterCommand(const char* args)
4965 return HandleBanHelper(BAN_CHARACTER,args);
4968 bool ChatHandler::HandleBanIPCommand(const char* args)
4970 return HandleBanHelper(BAN_IP,args);
4973 bool ChatHandler::HandleBanHelper(BanMode mode, const char* args)
4975 if (!*args)
4976 return false;
4978 char* cnameOrIP = strtok ((char*)args, " ");
4979 if (!cnameOrIP)
4980 return false;
4982 std::string nameOrIP = cnameOrIP;
4984 char* duration = strtok (NULL," ");
4985 if(!duration || !atoi(duration))
4986 return false;
4988 char* reason = strtok (NULL,"");
4989 if(!reason)
4990 return false;
4992 switch(mode)
4994 case BAN_ACCOUNT:
4995 if (!AccountMgr::normalizeString(nameOrIP))
4997 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str());
4998 SetSentErrorMessage(true);
4999 return false;
5001 break;
5002 case BAN_CHARACTER:
5003 if(!normalizePlayerName(nameOrIP))
5005 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5006 SetSentErrorMessage(true);
5007 return false;
5009 break;
5010 case BAN_IP:
5011 if(!IsIPAddress(nameOrIP.c_str()))
5012 return false;
5013 break;
5016 switch(sWorld.BanAccount(mode, nameOrIP, duration, reason,m_session ? m_session->GetPlayerName() : ""))
5018 case BAN_SUCCESS:
5019 if(atoi(duration)>0)
5020 PSendSysMessage(LANG_BAN_YOUBANNED,nameOrIP.c_str(),secsToTimeString(TimeStringToSecs(duration),true).c_str(),reason);
5021 else
5022 PSendSysMessage(LANG_BAN_YOUPERMBANNED,nameOrIP.c_str(),reason);
5023 break;
5024 case BAN_SYNTAX_ERROR:
5025 return false;
5026 case BAN_NOTFOUND:
5027 switch(mode)
5029 default:
5030 PSendSysMessage(LANG_BAN_NOTFOUND,"account",nameOrIP.c_str());
5031 break;
5032 case BAN_CHARACTER:
5033 PSendSysMessage(LANG_BAN_NOTFOUND,"character",nameOrIP.c_str());
5034 break;
5035 case BAN_IP:
5036 PSendSysMessage(LANG_BAN_NOTFOUND,"ip",nameOrIP.c_str());
5037 break;
5039 SetSentErrorMessage(true);
5040 return false;
5043 return true;
5046 bool ChatHandler::HandleUnBanAccountCommand(const char* args)
5048 return HandleUnBanHelper(BAN_ACCOUNT,args);
5051 bool ChatHandler::HandleUnBanCharacterCommand(const char* args)
5053 return HandleUnBanHelper(BAN_CHARACTER,args);
5056 bool ChatHandler::HandleUnBanIPCommand(const char* args)
5058 return HandleUnBanHelper(BAN_IP,args);
5061 bool ChatHandler::HandleUnBanHelper(BanMode mode, const char* args)
5063 if (!*args)
5064 return false;
5066 char* cnameOrIP = strtok ((char*)args, " ");
5067 if(!cnameOrIP)
5068 return false;
5070 std::string nameOrIP = cnameOrIP;
5072 switch(mode)
5074 case BAN_ACCOUNT:
5075 if (!AccountMgr::normalizeString(nameOrIP))
5077 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str());
5078 SetSentErrorMessage(true);
5079 return false;
5081 break;
5082 case BAN_CHARACTER:
5083 if(!normalizePlayerName(nameOrIP))
5085 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5086 SetSentErrorMessage(true);
5087 return false;
5089 break;
5090 case BAN_IP:
5091 if(!IsIPAddress(nameOrIP.c_str()))
5092 return false;
5093 break;
5096 if(sWorld.RemoveBanAccount(mode,nameOrIP))
5097 PSendSysMessage(LANG_UNBAN_UNBANNED,nameOrIP.c_str());
5098 else
5099 PSendSysMessage(LANG_UNBAN_ERROR,nameOrIP.c_str());
5101 return true;
5104 bool ChatHandler::HandleBanInfoAccountCommand(const char* args)
5106 if (!*args)
5107 return false;
5109 std::string account_name;
5110 uint32 accountid = extractAccountId((char*)args, &account_name);
5111 if (!accountid)
5112 return false;
5114 return HandleBanInfoHelper(accountid,account_name.c_str());
5117 bool ChatHandler::HandleBanInfoCharacterCommand(const char* args)
5119 Player* target;
5120 uint64 target_guid;
5121 if (!extractPlayerTarget((char*)args,&target,&target_guid))
5122 return false;
5124 uint32 accountid = target ? target->GetSession()->GetAccountId() : sObjectMgr.GetPlayerAccountIdByGUID(target_guid);
5126 std::string accountname;
5127 if (!sAccountMgr.GetName(accountid,accountname))
5129 PSendSysMessage(LANG_BANINFO_NOCHARACTER);
5130 return true;
5133 return HandleBanInfoHelper(accountid,accountname.c_str());
5136 bool ChatHandler::HandleBanInfoHelper(uint32 accountid, char const* accountname)
5138 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);
5139 if(!result)
5141 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN, accountname);
5142 return true;
5145 PSendSysMessage(LANG_BANINFO_BANHISTORY,accountname);
5148 Field* fields = result->Fetch();
5150 time_t unbandate = time_t(fields[3].GetUInt64());
5151 bool active = false;
5152 if(fields[2].GetBool() && (fields[1].GetUInt64() == (uint64)0 ||unbandate >= time(NULL)) )
5153 active = true;
5154 bool permanent = (fields[1].GetUInt64() == (uint64)0);
5155 std::string bantime = permanent?GetMangosString(LANG_BANINFO_INFINITE):secsToTimeString(fields[1].GetUInt64(), true);
5156 PSendSysMessage(LANG_BANINFO_HISTORYENTRY,
5157 fields[0].GetString(), bantime.c_str(), active ? GetMangosString(LANG_BANINFO_YES):GetMangosString(LANG_BANINFO_NO), fields[4].GetString(), fields[5].GetString());
5158 }while (result->NextRow());
5160 delete result;
5161 return true;
5164 bool ChatHandler::HandleBanInfoIPCommand(const char* args)
5166 if (!*args)
5167 return false;
5169 char* cIP = strtok ((char*)args, "");
5170 if(!cIP)
5171 return false;
5173 if (!IsIPAddress(cIP))
5174 return false;
5176 std::string IP = cIP;
5178 loginDatabase.escape_string(IP);
5179 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());
5180 if(!result)
5182 PSendSysMessage(LANG_BANINFO_NOIP);
5183 return true;
5186 Field *fields = result->Fetch();
5187 bool permanent = !fields[6].GetUInt64();
5188 PSendSysMessage(LANG_BANINFO_IPENTRY,
5189 fields[0].GetString(), fields[1].GetString(), permanent ? GetMangosString(LANG_BANINFO_NEVER):fields[2].GetString(),
5190 permanent ? GetMangosString(LANG_BANINFO_INFINITE):secsToTimeString(fields[3].GetUInt64(), true).c_str(), fields[4].GetString(), fields[5].GetString());
5191 delete result;
5192 return true;
5195 bool ChatHandler::HandleBanListCharacterCommand(const char* args)
5197 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5199 char* cFilter = strtok ((char*)args, " ");
5200 if(!cFilter)
5201 return false;
5203 std::string filter = cFilter;
5204 loginDatabase.escape_string(filter);
5205 QueryResult* result = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'"),filter.c_str());
5206 if (!result)
5208 PSendSysMessage(LANG_BANLIST_NOCHARACTER);
5209 return true;
5212 return HandleBanListHelper(result);
5215 bool ChatHandler::HandleBanListAccountCommand(const char* args)
5217 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5219 char* cFilter = strtok((char*)args, " ");
5220 std::string filter = cFilter ? cFilter : "";
5221 loginDatabase.escape_string(filter);
5223 QueryResult* result;
5225 if(filter.empty())
5227 result = loginDatabase.Query("SELECT account.id, username FROM account, account_banned"
5228 " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
5230 else
5232 result = loginDatabase.PQuery("SELECT account.id, username FROM account, account_banned"
5233 " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
5234 filter.c_str());
5237 if (!result)
5239 PSendSysMessage(LANG_BANLIST_NOACCOUNT);
5240 return true;
5243 return HandleBanListHelper(result);
5246 bool ChatHandler::HandleBanListHelper(QueryResult* result)
5248 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT);
5250 // Chat short output
5251 if(m_session)
5255 Field* fields = result->Fetch();
5256 uint32 accountid = fields[0].GetUInt32();
5258 QueryResult* banresult = loginDatabase.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid);
5259 if(banresult)
5261 Field* fields2 = banresult->Fetch();
5262 PSendSysMessage("%s",fields2[0].GetString());
5263 delete banresult;
5265 } while (result->NextRow());
5267 // Console wide output
5268 else
5270 SendSysMessage(LANG_BANLIST_ACCOUNTS);
5271 SendSysMessage("===============================================================================");
5272 SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER);
5275 SendSysMessage("-------------------------------------------------------------------------------");
5276 Field *fields = result->Fetch();
5277 uint32 account_id = fields[0].GetUInt32 ();
5279 std::string account_name;
5281 // "account" case, name can be get in same query
5282 if(result->GetFieldCount() > 1)
5283 account_name = fields[1].GetCppString();
5284 // "character" case, name need extract from another DB
5285 else
5286 sAccountMgr.GetName (account_id,account_name);
5288 // No SQL injection. id is uint32.
5289 QueryResult *banInfo = loginDatabase.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id);
5290 if (banInfo)
5292 Field *fields2 = banInfo->Fetch();
5295 time_t t_ban = fields2[0].GetUInt64();
5296 tm* aTm_ban = localtime(&t_ban);
5298 if (fields2[0].GetUInt64() == fields2[1].GetUInt64())
5300 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5301 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,
5302 fields2[2].GetString(),fields2[3].GetString());
5304 else
5306 time_t t_unban = fields2[1].GetUInt64();
5307 tm* aTm_unban = localtime(&t_unban);
5308 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5309 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,
5310 aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
5311 fields2[2].GetString(),fields2[3].GetString());
5313 }while ( banInfo->NextRow() );
5314 delete banInfo;
5316 }while( result->NextRow() );
5317 SendSysMessage("===============================================================================");
5320 delete result;
5321 return true;
5324 bool ChatHandler::HandleBanListIPCommand(const char* args)
5326 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5328 char* cFilter = strtok((char*)args, " ");
5329 std::string filter = cFilter ? cFilter : "";
5330 loginDatabase.escape_string(filter);
5332 QueryResult* result;
5334 if(filter.empty())
5336 result = loginDatabase.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5337 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
5338 " ORDER BY unbandate" );
5340 else
5342 result = loginDatabase.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5343 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")
5344 " ORDER BY unbandate",filter.c_str() );
5347 if(!result)
5349 PSendSysMessage(LANG_BANLIST_NOIP);
5350 return true;
5353 PSendSysMessage(LANG_BANLIST_MATCHINGIP);
5354 // Chat short output
5355 if(m_session)
5359 Field* fields = result->Fetch();
5360 PSendSysMessage("%s",fields[0].GetString());
5361 } while (result->NextRow());
5363 // Console wide output
5364 else
5366 SendSysMessage(LANG_BANLIST_IPS);
5367 SendSysMessage("===============================================================================");
5368 SendSysMessage(LANG_BANLIST_IPS_HEADER);
5371 SendSysMessage("-------------------------------------------------------------------------------");
5372 Field *fields = result->Fetch();
5373 time_t t_ban = fields[1].GetUInt64();
5374 tm* aTm_ban = localtime(&t_ban);
5375 if ( fields[1].GetUInt64() == fields[2].GetUInt64() )
5377 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5378 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,
5379 fields[3].GetString(), fields[4].GetString());
5381 else
5383 time_t t_unban = fields[2].GetUInt64();
5384 tm* aTm_unban = localtime(&t_unban);
5385 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5386 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,
5387 aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
5388 fields[3].GetString(), fields[4].GetString());
5390 }while( result->NextRow() );
5391 SendSysMessage("===============================================================================");
5394 delete result;
5395 return true;
5398 bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
5400 Player* pl = m_session->GetPlayer();
5402 // accept only explicitly selected target (not implicitly self targeting case)
5403 Unit* target = getSelectedUnit();
5404 if(pl->GetSelection() && target)
5406 if(target->GetTypeId()!=TYPEID_UNIT)
5408 SendSysMessage(LANG_SELECT_CREATURE);
5409 SetSentErrorMessage(true);
5410 return false;
5413 if(target->isDead())
5414 ((Creature*)target)->Respawn();
5415 return true;
5418 MaNGOS::RespawnDo u_do;
5419 MaNGOS::WorldObjectWorker<MaNGOS::RespawnDo> worker(pl,u_do);
5420 Cell::VisitGridObjects(pl, worker, pl->GetMap()->GetVisibilityDistance());
5421 return true;
5424 bool ChatHandler::HandleGMFlyCommand(const char* args)
5426 if (!*args)
5427 return false;
5429 Player *target = getSelectedPlayer();
5430 if (!target)
5431 target = m_session->GetPlayer();
5433 WorldPacket data(12);
5434 if (strncmp(args, "on", 3) == 0)
5435 data.SetOpcode(SMSG_MOVE_SET_CAN_FLY);
5436 else if (strncmp(args, "off", 4) == 0)
5437 data.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY);
5438 else
5440 SendSysMessage(LANG_USE_BOL);
5441 return false;
5443 data << target->GetPackGUID();
5444 data << uint32(0); // unknown
5445 target->SendMessageToSet(&data, true);
5446 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS, GetNameLink(target).c_str(), args);
5447 return true;
5450 bool ChatHandler::HandlePDumpLoadCommand(const char *args)
5452 if (!*args)
5453 return false;
5455 char* file = strtok((char*)args, " ");
5456 if (!file)
5457 return false;
5459 char* account = strtok(NULL, " ");
5460 if (!account)
5461 return false;
5463 char* name_str = strtok(NULL, " ");
5465 std::string account_name;
5466 uint32 account_id = extractAccountId(account, &account_name);
5467 if (!account_id)
5468 return false;
5470 char* guid_str = NULL;
5472 std::string name;
5473 if (name_str)
5475 name = name_str;
5476 // normalize the name if specified and check if it exists
5477 if (!normalizePlayerName(name))
5479 PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
5480 SetSentErrorMessage(true);
5481 return false;
5484 if (ObjectMgr::CheckPlayerName(name,true) != CHAR_NAME_SUCCESS)
5486 PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
5487 SetSentErrorMessage(true);
5488 return false;
5491 guid_str = strtok(NULL, " ");
5494 uint32 guid = 0;
5496 if (guid_str)
5498 guid = atoi(guid_str);
5499 if (!guid)
5501 PSendSysMessage(LANG_INVALID_CHARACTER_GUID);
5502 SetSentErrorMessage(true);
5503 return false;
5506 if (sObjectMgr.GetPlayerAccountIdByGUID(guid))
5508 PSendSysMessage(LANG_CHARACTER_GUID_IN_USE,guid);
5509 SetSentErrorMessage(true);
5510 return false;
5514 switch(PlayerDumpReader().LoadDump(file, account_id, name, guid))
5516 case DUMP_SUCCESS:
5517 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS);
5518 break;
5519 case DUMP_FILE_OPEN_ERROR:
5520 PSendSysMessage(LANG_FILE_OPEN_FAIL,file);
5521 SetSentErrorMessage(true);
5522 return false;
5523 case DUMP_FILE_BROKEN:
5524 PSendSysMessage(LANG_DUMP_BROKEN,file);
5525 SetSentErrorMessage(true);
5526 return false;
5527 case DUMP_TOO_MANY_CHARS:
5528 PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL,account_name.c_str(),account_id);
5529 SetSentErrorMessage(true);
5530 return false;
5531 default:
5532 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED);
5533 SetSentErrorMessage(true);
5534 return false;
5537 return true;
5540 bool ChatHandler::HandlePDumpWriteCommand(const char *args)
5542 if (!*args)
5543 return false;
5545 char* file = strtok((char*)args, " ");
5546 char* p2 = strtok(NULL, " ");
5548 if(!file || !p2)
5549 return false;
5551 uint32 guid;
5552 // character name can't start from number
5553 if (isNumeric(p2))
5554 guid = atoi(p2);
5555 else
5557 std::string name = extractPlayerNameFromLink(p2);
5558 if(name.empty())
5560 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5561 SetSentErrorMessage(true);
5562 return false;
5565 guid = GUID_LOPART(sObjectMgr.GetPlayerGUIDByName(name));
5568 if(!sObjectMgr.GetPlayerAccountIdByGUID(guid))
5570 PSendSysMessage(LANG_PLAYER_NOT_FOUND);
5571 SetSentErrorMessage(true);
5572 return false;
5575 switch(PlayerDumpWriter().WriteDump(file, guid))
5577 case DUMP_SUCCESS:
5578 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS);
5579 break;
5580 case DUMP_FILE_OPEN_ERROR:
5581 PSendSysMessage(LANG_FILE_OPEN_FAIL,file);
5582 SetSentErrorMessage(true);
5583 return false;
5584 default:
5585 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED);
5586 SetSentErrorMessage(true);
5587 return false;
5590 return true;
5593 bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
5595 Unit* unit = getSelectedUnit();
5596 if(!unit)
5598 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5599 SetSentErrorMessage(true);
5600 return false;
5603 PSendSysMessage(LANG_MOVEGENS_LIST,(unit->GetTypeId()==TYPEID_PLAYER ? "Player" : "Creature" ),unit->GetGUIDLow());
5605 MotionMaster* mm = unit->GetMotionMaster();
5606 for(MotionMaster::const_iterator itr = mm->begin(); itr != mm->end(); ++itr)
5608 switch((*itr)->GetMovementGeneratorType())
5610 case IDLE_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_IDLE); break;
5611 case RANDOM_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_RANDOM); break;
5612 case WAYPOINT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_WAYPOINT); break;
5613 case CONFUSED_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_CONFUSED); break;
5614 case CHASE_MOTION_TYPE:
5616 Unit* target = NULL;
5617 if(unit->GetTypeId()==TYPEID_PLAYER)
5618 target = static_cast<ChaseMovementGenerator<Player> const*>(*itr)->GetTarget();
5619 else
5620 target = static_cast<ChaseMovementGenerator<Creature> const*>(*itr)->GetTarget();
5622 if (!target)
5623 SendSysMessage(LANG_MOVEGENS_CHASE_NULL);
5624 else if (target->GetTypeId()==TYPEID_PLAYER)
5625 PSendSysMessage(LANG_MOVEGENS_CHASE_PLAYER,target->GetName(),target->GetGUIDLow());
5626 else
5627 PSendSysMessage(LANG_MOVEGENS_CHASE_CREATURE,target->GetName(),target->GetGUIDLow());
5628 break;
5630 case FOLLOW_MOTION_TYPE:
5632 Unit* target = NULL;
5633 if(unit->GetTypeId()==TYPEID_PLAYER)
5634 target = static_cast<FollowMovementGenerator<Player> const*>(*itr)->GetTarget();
5635 else
5636 target = static_cast<FollowMovementGenerator<Creature> const*>(*itr)->GetTarget();
5638 if (!target)
5639 SendSysMessage(LANG_MOVEGENS_FOLLOW_NULL);
5640 else if (target->GetTypeId()==TYPEID_PLAYER)
5641 PSendSysMessage(LANG_MOVEGENS_FOLLOW_PLAYER,target->GetName(),target->GetGUIDLow());
5642 else
5643 PSendSysMessage(LANG_MOVEGENS_FOLLOW_CREATURE,target->GetName(),target->GetGUIDLow());
5644 break;
5646 case HOME_MOTION_TYPE:
5647 if(unit->GetTypeId()==TYPEID_UNIT)
5649 float x,y,z;
5650 (*itr)->GetDestination(x,y,z);
5651 PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE,x,y,z);
5653 else
5654 SendSysMessage(LANG_MOVEGENS_HOME_PLAYER);
5655 break;
5656 case FLIGHT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FLIGHT); break;
5657 case POINT_MOTION_TYPE:
5659 float x,y,z;
5660 (*itr)->GetDestination(x,y,z);
5661 PSendSysMessage(LANG_MOVEGENS_POINT,x,y,z);
5662 break;
5664 case FLEEING_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FEAR); break;
5665 case DISTRACT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_DISTRACT); break;
5666 default:
5667 PSendSysMessage(LANG_MOVEGENS_UNKNOWN,(*itr)->GetMovementGeneratorType());
5668 break;
5671 return true;
5674 bool ChatHandler::HandleServerPLimitCommand(const char *args)
5676 if(*args)
5678 char* param = strtok((char*)args, " ");
5679 if(!param)
5680 return false;
5682 int l = strlen(param);
5684 if( strncmp(param,"player",l) == 0 )
5685 sWorld.SetPlayerLimit(-SEC_PLAYER);
5686 else if(strncmp(param,"moderator",l) == 0 )
5687 sWorld.SetPlayerLimit(-SEC_MODERATOR);
5688 else if(strncmp(param,"gamemaster",l) == 0 )
5689 sWorld.SetPlayerLimit(-SEC_GAMEMASTER);
5690 else if(strncmp(param,"administrator",l) == 0 )
5691 sWorld.SetPlayerLimit(-SEC_ADMINISTRATOR);
5692 else if(strncmp(param,"reset",l) == 0 )
5693 sWorld.SetPlayerLimit( sConfig.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT) );
5694 else
5696 int val = atoi(param);
5697 if(val < -SEC_ADMINISTRATOR) val = -SEC_ADMINISTRATOR;
5699 sWorld.SetPlayerLimit(val);
5702 // kick all low security level players
5703 if(sWorld.GetPlayerAmountLimit() > SEC_PLAYER)
5704 sWorld.KickAllLess(sWorld.GetPlayerSecurityLimit());
5707 uint32 pLimit = sWorld.GetPlayerAmountLimit();
5708 AccountTypes allowedAccountType = sWorld.GetPlayerSecurityLimit();
5709 char const* secName = "";
5710 switch(allowedAccountType)
5712 case SEC_PLAYER: secName = "Player"; break;
5713 case SEC_MODERATOR: secName = "Moderator"; break;
5714 case SEC_GAMEMASTER: secName = "Gamemaster"; break;
5715 case SEC_ADMINISTRATOR: secName = "Administrator"; break;
5716 default: secName = "<unknown>"; break;
5719 PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit,secName);
5721 return true;
5724 bool ChatHandler::HandleCastCommand(const char* args)
5726 if(!*args)
5727 return false;
5729 Unit* target = getSelectedUnit();
5731 if(!target)
5733 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5734 SetSentErrorMessage(true);
5735 return false;
5738 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5739 uint32 spell = extractSpellIdFromLink((char*)args);
5740 if(!spell)
5741 return false;
5743 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
5744 if(!spellInfo)
5745 return false;
5747 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
5749 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
5750 SetSentErrorMessage(true);
5751 return false;
5754 char* trig_str = strtok(NULL, " ");
5755 if(trig_str)
5757 int l = strlen(trig_str);
5758 if(strncmp(trig_str,"triggered",l) != 0 )
5759 return false;
5762 bool triggered = (trig_str != NULL);
5764 m_session->GetPlayer()->CastSpell(target,spell,triggered);
5766 return true;
5769 bool ChatHandler::HandleCastBackCommand(const char* args)
5771 Creature* caster = getSelectedCreature();
5773 if(!caster)
5775 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5776 SetSentErrorMessage(true);
5777 return false;
5780 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
5781 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5782 uint32 spell = extractSpellIdFromLink((char*)args);
5783 if(!spell || !sSpellStore.LookupEntry(spell))
5784 return false;
5786 char* trig_str = strtok(NULL, " ");
5787 if(trig_str)
5789 int l = strlen(trig_str);
5790 if(strncmp(trig_str,"triggered",l) != 0 )
5791 return false;
5794 bool triggered = (trig_str != NULL);
5796 caster->SetFacingToObject(m_session->GetPlayer());
5798 caster->CastSpell(m_session->GetPlayer(),spell,triggered);
5800 return true;
5803 bool ChatHandler::HandleCastDistCommand(const char* args)
5805 if(!*args)
5806 return false;
5808 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5809 uint32 spell = extractSpellIdFromLink((char*)args);
5810 if(!spell)
5811 return false;
5813 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
5814 if(!spellInfo)
5815 return false;
5817 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
5819 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
5820 SetSentErrorMessage(true);
5821 return false;
5824 char *distStr = strtok(NULL, " ");
5826 float dist = 0;
5828 if(distStr)
5829 sscanf(distStr, "%f", &dist);
5831 char* trig_str = strtok(NULL, " ");
5832 if(trig_str)
5834 int l = strlen(trig_str);
5835 if(strncmp(trig_str,"triggered",l) != 0 )
5836 return false;
5839 bool triggered = (trig_str != NULL);
5841 float x,y,z;
5842 m_session->GetPlayer()->GetClosePoint(x,y,z,dist);
5844 m_session->GetPlayer()->CastSpell(x,y,z,spell,triggered);
5845 return true;
5848 bool ChatHandler::HandleCastTargetCommand(const char* args)
5850 Creature* caster = getSelectedCreature();
5852 if(!caster)
5854 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5855 SetSentErrorMessage(true);
5856 return false;
5859 if(!caster->getVictim())
5861 SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM);
5862 SetSentErrorMessage(true);
5863 return false;
5866 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5867 uint32 spell = extractSpellIdFromLink((char*)args);
5868 if(!spell || !sSpellStore.LookupEntry(spell))
5869 return false;
5871 char* trig_str = strtok(NULL, " ");
5872 if(trig_str)
5874 int l = strlen(trig_str);
5875 if(strncmp(trig_str,"triggered",l) != 0 )
5876 return false;
5879 bool triggered = (trig_str != NULL);
5881 caster->SetFacingToObject(m_session->GetPlayer());
5883 caster->CastSpell(caster->getVictim(),spell,triggered);
5885 return true;
5889 ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
5890 Without this function 3rd party scripting library will get linking errors (unresolved external)
5891 when attempting to use the PointMovementGenerator
5893 bool ChatHandler::HandleComeToMeCommand(const char *args)
5895 Creature* caster = getSelectedCreature();
5897 if(!caster)
5899 SendSysMessage(LANG_SELECT_CREATURE);
5900 SetSentErrorMessage(true);
5901 return false;
5904 char* newFlagStr = strtok((char*)args, " ");
5906 if(!newFlagStr)
5907 return false;
5909 uint32 newFlags = atoi(newFlagStr);
5911 caster->SetSplineFlags(SplineFlags(newFlags));
5913 Player* pl = m_session->GetPlayer();
5915 caster->GetMotionMaster()->MovePoint(0, pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ());
5916 return true;
5919 bool ChatHandler::HandleCastSelfCommand(const char* args)
5921 if(!*args)
5922 return false;
5924 Unit* target = getSelectedUnit();
5926 if(!target)
5928 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5929 SetSentErrorMessage(true);
5930 return false;
5933 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5934 uint32 spell = extractSpellIdFromLink((char*)args);
5935 if(!spell)
5936 return false;
5938 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
5939 if(!spellInfo)
5940 return false;
5942 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
5944 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
5945 SetSentErrorMessage(true);
5946 return false;
5949 target->CastSpell(target,spell,false);
5951 return true;
5954 std::string GetTimeString(time_t time)
5956 time_t days = time / DAY;
5957 time_t hours = (time % DAY) / HOUR;
5958 time_t minute = (time % HOUR) / MINUTE;
5959 std::ostringstream ss;
5960 if(days)
5961 ss << days << "d ";
5962 if(hours)
5963 ss << hours << "h ";
5964 ss << minute << "m";
5965 return ss.str();
5968 bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
5970 Player* player = getSelectedPlayer();
5971 if (!player) player = m_session->GetPlayer();
5972 uint32 counter = 0;
5973 for(uint8 i = 0; i < MAX_DIFFICULTY; ++i)
5975 Player::BoundInstancesMap &binds = player->GetBoundInstances(Difficulty(i));
5976 for(Player::BoundInstancesMap::const_iterator itr = binds.begin(); itr != binds.end(); ++itr)
5978 InstanceSave *save = itr->second.save;
5979 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
5980 if (const MapEntry* entry = sMapStore.LookupEntry(itr->first))
5982 PSendSysMessage("map: %d (%s) inst: %d perm: %s diff: %d canReset: %s TTR: %s",
5983 itr->first, entry->name[GetSessionDbcLocale()], save->GetInstanceId(), itr->second.perm ? "yes" : "no",
5984 save->GetDifficulty(), save->CanReset() ? "yes" : "no", timeleft.c_str());
5986 else
5987 PSendSysMessage("bound for a nonexistant map %u", itr->first);
5988 counter++;
5991 PSendSysMessage("player binds: %d", counter);
5992 counter = 0;
5993 Group *group = player->GetGroup();
5994 if(group)
5996 for(uint8 i = 0; i < MAX_DIFFICULTY; ++i)
5998 Group::BoundInstancesMap &binds = group->GetBoundInstances(Difficulty(i));
5999 for(Group::BoundInstancesMap::const_iterator itr = binds.begin(); itr != binds.end(); ++itr)
6001 InstanceSave *save = itr->second.save;
6002 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
6003 if (const MapEntry* entry = sMapStore.LookupEntry(itr->first))
6005 PSendSysMessage("map: %d (%s) inst: %d perm: %s diff: %d canReset: %s TTR: %s",
6006 itr->first, entry->name[GetSessionDbcLocale()], save->GetInstanceId(), itr->second.perm ? "yes" : "no",
6007 save->GetDifficulty(), save->CanReset() ? "yes" : "no", timeleft.c_str());
6009 else
6010 PSendSysMessage("bound for a nonexistant map %u", itr->first);
6011 counter++;
6015 PSendSysMessage("group binds: %d", counter);
6017 return true;
6020 bool ChatHandler::HandleInstanceUnbindCommand(const char* args)
6022 if(!*args)
6023 return false;
6025 Player* player = getSelectedPlayer();
6026 if (!player)
6027 player = m_session->GetPlayer();
6028 uint32 counter = 0;
6029 uint32 mapid = 0;
6030 bool got_map = false;
6032 if (strncmp(args,"all",strlen(args)) != 0)
6034 if(!isNumeric(args[0]))
6035 return false;
6037 got_map = true;
6038 mapid = atoi(args);
6041 for(uint8 i = 0; i < MAX_DIFFICULTY; ++i)
6043 Player::BoundInstancesMap &binds = player->GetBoundInstances(Difficulty(i));
6044 for(Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end();)
6046 if (got_map && mapid != itr->first)
6048 ++itr;
6049 continue;
6051 if(itr->first != player->GetMapId())
6053 InstanceSave *save = itr->second.save;
6054 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
6056 if (const MapEntry* entry = sMapStore.LookupEntry(itr->first))
6058 PSendSysMessage("unbinding map: %d (%s) inst: %d perm: %s diff: %d canReset: %s TTR: %s",
6059 itr->first, entry->name[GetSessionDbcLocale()], save->GetInstanceId(), itr->second.perm ? "yes" : "no",
6060 save->GetDifficulty(), save->CanReset() ? "yes" : "no", timeleft.c_str());
6062 else
6063 PSendSysMessage("bound for a nonexistant map %u", itr->first);
6064 player->UnbindInstance(itr, Difficulty(i));
6065 counter++;
6067 else
6068 ++itr;
6071 PSendSysMessage("instances unbound: %d", counter);
6072 return true;
6075 bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
6077 PSendSysMessage("instances loaded: %d", sMapMgr.GetNumInstances());
6078 PSendSysMessage("players in instances: %d", sMapMgr.GetNumPlayersInInstances());
6079 PSendSysMessage("instance saves: %d", sInstanceSaveMgr.GetNumInstanceSaves());
6080 PSendSysMessage("players bound: %d", sInstanceSaveMgr.GetNumBoundPlayersTotal());
6081 PSendSysMessage("groups bound: %d", sInstanceSaveMgr.GetNumBoundGroupsTotal());
6082 return true;
6085 bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
6087 Player* pl = m_session->GetPlayer();
6089 Map* map = pl->GetMap();
6090 if (!map->IsDungeon())
6092 PSendSysMessage("Map is not a dungeon.");
6093 SetSentErrorMessage(true);
6094 return false;
6097 if (!((InstanceMap*)map)->GetInstanceData())
6099 PSendSysMessage("Map has no instance data.");
6100 SetSentErrorMessage(true);
6101 return false;
6104 ((InstanceMap*)map)->GetInstanceData()->SaveToDB();
6105 return true;
6108 /// Display the list of GMs
6109 bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
6111 ///- Get the accounts with GM Level >0
6112 QueryResult *result = loginDatabase.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
6113 if(result)
6115 SendSysMessage(LANG_GMLIST);
6116 SendSysMessage("========================");
6117 SendSysMessage(LANG_GMLIST_HEADER);
6118 SendSysMessage("========================");
6120 ///- Circle through them. Display username and GM level
6123 Field *fields = result->Fetch();
6124 PSendSysMessage("|%15s|%6s|", fields[0].GetString(),fields[1].GetString());
6125 }while( result->NextRow() );
6127 PSendSysMessage("========================");
6128 delete result;
6130 else
6131 PSendSysMessage(LANG_GMLIST_EMPTY);
6132 return true;
6135 /// Define the 'Message of the day' for the realm
6136 bool ChatHandler::HandleServerSetMotdCommand(const char* args)
6138 sWorld.SetMotd(args);
6139 PSendSysMessage(LANG_MOTD_NEW, args);
6140 return true;
6143 bool ChatHandler::ShowPlayerListHelper(QueryResult* result, uint32* limit, bool title, bool error)
6145 if (!result)
6147 if (error)
6149 PSendSysMessage(LANG_NO_PLAYERS_FOUND);
6150 SetSentErrorMessage(true);
6152 return false;
6155 if (!m_session && title)
6157 SendSysMessage(LANG_CHARACTERS_LIST_BAR);
6158 SendSysMessage(LANG_CHARACTERS_LIST_HEADER);
6159 SendSysMessage(LANG_CHARACTERS_LIST_BAR);
6162 if (result)
6164 ///- Circle through them. Display username and GM level
6167 // check limit
6168 if (limit)
6170 if(*limit == 0)
6171 break;
6172 --*limit;
6175 Field *fields = result->Fetch();
6176 uint32 guid = fields[0].GetUInt32();
6177 std::string name = fields[1].GetCppString();
6178 uint8 race = fields[2].GetUInt8();
6179 uint8 class_ = fields[3].GetUInt8();
6180 uint32 level = fields[4].GetUInt32();
6182 ChrRacesEntry const* raceEntry = sChrRacesStore.LookupEntry(race);
6183 ChrClassesEntry const* classEntry = sChrClassesStore.LookupEntry(class_);
6185 char const* race_name = raceEntry ? raceEntry->name[GetSessionDbcLocale()] : "<?>";
6186 char const* class_name = classEntry ? classEntry->name[GetSessionDbcLocale()] : "<?>";
6188 if (!m_session)
6189 PSendSysMessage(LANG_CHARACTERS_LIST_LINE_CONSOLE, guid, name.c_str(), race_name, class_name, level);
6190 else
6191 PSendSysMessage(LANG_CHARACTERS_LIST_LINE_CHAT, guid, name.c_str(), name.c_str(), race_name, class_name, level);
6193 }while( result->NextRow() );
6195 delete result;
6198 if (!m_session)
6199 SendSysMessage(LANG_CHARACTERS_LIST_BAR);
6201 return true;
6205 /// Output list of character for account
6206 bool ChatHandler::HandleAccountCharactersCommand(const char* args)
6208 ///- Get the command line arguments
6209 std::string account_name;
6210 Player* target = NULL; // only for triggering use targeted player account
6211 uint32 account_id = extractAccountId((char*)args, &account_name, &target);
6212 if (!account_id )
6213 return false;
6215 ///- Get the characters for account id
6216 QueryResult *result = CharacterDatabase.PQuery( "SELECT guid, name, race, class, level FROM characters WHERE account = %u", account_id);
6218 return ShowPlayerListHelper(result);
6221 /// Set/Unset the expansion level for an account
6222 bool ChatHandler::HandleAccountSetAddonCommand(const char* args)
6224 ///- Get the command line arguments
6225 char* arg1;
6226 char* arg2;
6228 extractOptFirstArg((char*)args, &arg1, &arg2);
6230 std::string account_name;
6231 uint32 account_id = extractAccountId(arg1, &account_name);
6232 if (!account_id )
6233 return false;
6235 // Let set addon state only for lesser (strong) security level
6236 // or to self account
6237 if (GetAccountId() && GetAccountId () != account_id &&
6238 HasLowerSecurityAccount (NULL,account_id,true))
6239 return false;
6241 int lev=atoi(arg2); //get int anyway (0 if error)
6242 if (lev < 0)
6243 return false;
6245 // No SQL injection
6246 loginDatabase.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev,account_id);
6247 PSendSysMessage(LANG_ACCOUNT_SETADDON,account_name.c_str(),account_id,lev);
6248 return true;
6251 //Send items by mail
6252 bool ChatHandler::HandleSendItemsCommand(const char* args)
6254 // format: name "subject text" "mail text" item1[:count1] item2[:count2] ... item12[:count12]
6255 Player* receiver;
6256 uint64 receiver_guid;
6257 std::string receiver_name;
6258 if(!extractPlayerTarget((char*)args,&receiver,&receiver_guid,&receiver_name))
6259 return false;
6261 char* tail1 = strtok(NULL, "");
6262 if(!tail1)
6263 return false;
6265 char* msgSubject = extractQuotedArg(tail1);
6266 if (!msgSubject)
6267 return false;
6269 char* tail2 = strtok(NULL, "");
6270 if(!tail2)
6271 return false;
6273 char* msgText = extractQuotedArg(tail2);
6274 if (!msgText)
6275 return false;
6277 // msgSubject, msgText isn't NUL after prev. check
6278 std::string subject = msgSubject;
6279 std::string text = msgText;
6281 // extract items
6282 typedef std::pair<uint32,uint32> ItemPair;
6283 typedef std::list< ItemPair > ItemPairs;
6284 ItemPairs items;
6286 // get all tail string
6287 char* tail = strtok(NULL, "");
6289 // get from tail next item str
6290 while(char* itemStr = strtok(tail, " "))
6292 // and get new tail
6293 tail = strtok(NULL, "");
6295 // parse item str
6296 char* itemIdStr = strtok(itemStr, ":");
6297 char* itemCountStr = strtok(NULL, " ");
6299 uint32 item_id = atoi(itemIdStr);
6300 if(!item_id)
6301 return false;
6303 ItemPrototype const* item_proto = ObjectMgr::GetItemPrototype(item_id);
6304 if(!item_proto)
6306 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
6307 SetSentErrorMessage(true);
6308 return false;
6311 uint32 item_count = itemCountStr ? atoi(itemCountStr) : 1;
6312 if (item_count < 1 || (item_proto->MaxCount > 0 && item_count > uint32(item_proto->MaxCount)))
6314 PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT, item_count,item_id);
6315 SetSentErrorMessage(true);
6316 return false;
6319 while(item_count > item_proto->GetMaxStackSize())
6321 items.push_back(ItemPair(item_id,item_proto->GetMaxStackSize()));
6322 item_count -= item_proto->GetMaxStackSize();
6325 items.push_back(ItemPair(item_id,item_count));
6327 if(items.size() > MAX_MAIL_ITEMS)
6329 PSendSysMessage(LANG_COMMAND_MAIL_ITEMS_LIMIT, MAX_MAIL_ITEMS);
6330 SetSentErrorMessage(true);
6331 return false;
6335 // from console show not existed sender
6336 MailSender sender(MAIL_NORMAL,m_session ? m_session->GetPlayer()->GetGUIDLow() : 0, MAIL_STATIONERY_GM);
6338 // fill mail
6339 MailDraft draft(subject, text);
6341 for(ItemPairs::const_iterator itr = items.begin(); itr != items.end(); ++itr)
6343 if(Item* item = Item::CreateItem(itr->first,itr->second,m_session ? m_session->GetPlayer() : 0))
6345 item->SaveToDB(); // save for prevent lost at next mail load, if send fail then item will deleted
6346 draft.AddItem(item);
6350 draft.SendMailTo(MailReceiver(receiver,GUID_LOPART(receiver_guid)), sender);
6352 std::string nameLink = playerLink(receiver_name);
6353 PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
6354 return true;
6357 ///Send money by mail
6358 bool ChatHandler::HandleSendMoneyCommand(const char* args)
6360 /// format: name "subject text" "mail text" money
6362 Player* receiver;
6363 uint64 receiver_guid;
6364 std::string receiver_name;
6365 if(!extractPlayerTarget((char*)args,&receiver,&receiver_guid,&receiver_name))
6366 return false;
6368 char* tail1 = strtok(NULL, "");
6369 if (!tail1)
6370 return false;
6372 char* msgSubject = extractQuotedArg(tail1);
6373 if (!msgSubject)
6374 return false;
6376 char* tail2 = strtok(NULL, "");
6377 if (!tail2)
6378 return false;
6380 char* msgText = extractQuotedArg(tail2);
6381 if (!msgText)
6382 return false;
6384 char* money_str = strtok(NULL, "");
6385 int32 money = money_str ? atoi(money_str) : 0;
6386 if (money <= 0)
6387 return false;
6389 // msgSubject, msgText isn't NUL after prev. check
6390 std::string subject = msgSubject;
6391 std::string text = msgText;
6393 // from console show not existed sender
6394 MailSender sender(MAIL_NORMAL,m_session ? m_session->GetPlayer()->GetGUIDLow() : 0, MAIL_STATIONERY_GM);
6396 MailDraft(subject, text)
6397 .AddMoney(money)
6398 .SendMailTo(MailReceiver(receiver,GUID_LOPART(receiver_guid)),sender);
6400 std::string nameLink = playerLink(receiver_name);
6401 PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
6402 return true;
6405 /// Send a message to a player in game
6406 bool ChatHandler::HandleSendMessageCommand(const char* args)
6408 ///- Find the player
6409 Player *rPlayer;
6410 if(!extractPlayerTarget((char*)args,&rPlayer))
6411 return false;
6413 char* msg_str = strtok(NULL, "");
6414 if(!msg_str)
6415 return false;
6417 ///- Check that he is not logging out.
6418 if(rPlayer->GetSession()->isLogingOut())
6420 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6421 SetSentErrorMessage(true);
6422 return false;
6425 ///- Send the message
6426 //Use SendAreaTriggerMessage for fastest delivery.
6427 rPlayer->GetSession()->SendAreaTriggerMessage("%s", msg_str);
6428 rPlayer->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
6430 //Confirmation message
6431 std::string nameLink = GetNameLink(rPlayer);
6432 PSendSysMessage(LANG_SENDMESSAGE,nameLink.c_str(),msg_str);
6433 return true;
6436 bool ChatHandler::HandleFlushArenaPointsCommand(const char * /*args*/)
6438 sBattleGroundMgr.DistributeArenaPoints();
6439 return true;
6442 bool ChatHandler::HandleModifyGenderCommand(const char *args)
6444 if(!*args)
6445 return false;
6447 Player *player = getSelectedPlayer();
6449 if(!player)
6451 PSendSysMessage(LANG_PLAYER_NOT_FOUND);
6452 SetSentErrorMessage(true);
6453 return false;
6456 PlayerInfo const* info = sObjectMgr.GetPlayerInfo(player->getRace(), player->getClass());
6457 if(!info)
6458 return false;
6460 char const* gender_str = (char*)args;
6461 int gender_len = strlen(gender_str);
6463 Gender gender;
6465 if(!strncmp(gender_str, "male", gender_len)) // MALE
6467 if(player->getGender() == GENDER_MALE)
6468 return true;
6470 gender = GENDER_MALE;
6472 else if (!strncmp(gender_str, "female", gender_len)) // FEMALE
6474 if(player->getGender() == GENDER_FEMALE)
6475 return true;
6477 gender = GENDER_FEMALE;
6479 else
6481 SendSysMessage(LANG_MUST_MALE_OR_FEMALE);
6482 SetSentErrorMessage(true);
6483 return false;
6486 // Set gender
6487 player->SetByteValue(UNIT_FIELD_BYTES_0, 2, gender);
6488 player->SetByteValue(PLAYER_BYTES_3, 0, gender);
6490 // Change display ID
6491 player->InitDisplayIds();
6493 char const* gender_full = gender ? "female" : "male";
6495 PSendSysMessage(LANG_YOU_CHANGE_GENDER, GetNameLink(player).c_str(), gender_full);
6497 if (needReportToTarget(player))
6498 ChatHandler(player).PSendSysMessage(LANG_YOUR_GENDER_CHANGED, gender_full, GetNameLink().c_str());
6500 return true;