[9290] Some cleanups in realmd, no functional changes
[getmangos.git] / src / game / Level3.cpp
blobf319cf05f22897582d31f33e11f3375ee22f8226
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/ConfigEnv.h"
47 #include "Util.h"
48 #include "ItemEnchantmentMgr.h"
49 #include "BattleGroundMgr.h"
50 #include "InstanceSaveMgr.h"
51 #include "InstanceData.h"
52 #include "CreatureEventAIMgr.h"
53 #include "DBCEnums.h"
55 //reload commands
56 bool ChatHandler::HandleReloadAllCommand(const char*)
58 HandleReloadSkillFishingBaseLevelCommand("");
60 HandleReloadAllAchievementCommand("");
61 HandleReloadAllAreaCommand("");
62 HandleReloadAllEventAICommand("");
63 HandleReloadAllLootCommand("");
64 HandleReloadAllNpcCommand("");
65 HandleReloadAllQuestCommand("");
66 HandleReloadAllSpellCommand("");
67 HandleReloadAllItemCommand("");
68 HandleReloadAllLocalesCommand("");
70 HandleReloadMailLevelRewardCommand("");
71 HandleReloadCommandCommand("");
72 HandleReloadReservedNameCommand("");
73 HandleReloadMangosStringCommand("");
74 HandleReloadGameTeleCommand("");
75 return true;
78 bool ChatHandler::HandleReloadAllAchievementCommand(const char*)
80 HandleReloadAchievementCriteriaRequirementCommand("");
81 HandleReloadAchievementRewardCommand("");
82 return true;
85 bool ChatHandler::HandleReloadAllAreaCommand(const char*)
87 //HandleReloadQuestAreaTriggersCommand(""); -- reloaded in HandleReloadAllQuestCommand
88 HandleReloadAreaTriggerTeleportCommand("");
89 HandleReloadAreaTriggerTavernCommand("");
90 HandleReloadGameGraveyardZoneCommand("");
91 return true;
94 bool ChatHandler::HandleReloadAllLootCommand(const char*)
96 sLog.outString( "Re-Loading Loot Tables..." );
97 LoadLootTables();
98 SendGlobalSysMessage("DB tables `*_loot_template` reloaded.");
99 return true;
102 bool ChatHandler::HandleReloadAllNpcCommand(const char* /*args*/)
104 HandleReloadNpcGossipCommand("a");
105 HandleReloadNpcTrainerCommand("a");
106 HandleReloadNpcVendorCommand("a");
107 HandleReloadPointsOfInterestCommand("a");
108 HandleReloadSpellClickSpellsCommand("a");
109 return true;
112 bool ChatHandler::HandleReloadAllQuestCommand(const char* /*args*/)
114 HandleReloadQuestAreaTriggersCommand("a");
115 HandleReloadQuestTemplateCommand("a");
117 sLog.outString( "Re-Loading Quests Relations..." );
118 sObjectMgr.LoadQuestRelations();
119 SendGlobalSysMessage("DB tables `*_questrelation` and `*_involvedrelation` reloaded.");
120 return true;
123 bool ChatHandler::HandleReloadAllScriptsCommand(const char*)
125 if(sWorld.IsScriptScheduled())
127 PSendSysMessage("DB scripts used currently, please attempt reload later.");
128 SetSentErrorMessage(true);
129 return false;
132 sLog.outString( "Re-Loading Scripts..." );
133 HandleReloadGameObjectScriptsCommand("a");
134 HandleReloadGossipScriptsCommand("a");
135 HandleReloadEventScriptsCommand("a");
136 HandleReloadQuestEndScriptsCommand("a");
137 HandleReloadQuestStartScriptsCommand("a");
138 HandleReloadSpellScriptsCommand("a");
139 SendGlobalSysMessage("DB tables `*_scripts` reloaded.");
140 HandleReloadDbScriptStringCommand("a");
141 return true;
144 bool ChatHandler::HandleReloadAllEventAICommand(const char*)
146 HandleReloadEventAITextsCommand("a");
147 HandleReloadEventAISummonsCommand("a");
148 HandleReloadEventAIScriptsCommand("a");
149 return true;
152 bool ChatHandler::HandleReloadAllSpellCommand(const char*)
154 HandleReloadSkillDiscoveryTemplateCommand("a");
155 HandleReloadSkillExtraItemTemplateCommand("a");
156 HandleReloadSpellAreaCommand("a");
157 HandleReloadSpellChainCommand("a");
158 HandleReloadSpellElixirCommand("a");
159 HandleReloadSpellLearnSpellCommand("a");
160 HandleReloadSpellProcEventCommand("a");
161 HandleReloadSpellBonusesCommand("a");
162 HandleReloadSpellProcItemEnchantCommand("a");
163 HandleReloadSpellScriptTargetCommand("a");
164 HandleReloadSpellTargetPositionCommand("a");
165 HandleReloadSpellThreatsCommand("a");
166 HandleReloadSpellPetAurasCommand("a");
167 return true;
170 bool ChatHandler::HandleReloadAllItemCommand(const char*)
172 HandleReloadPageTextsCommand("a");
173 HandleReloadItemEnchantementsCommand("a");
174 HandleReloadItemRequiredTragetCommand("a");
175 return true;
178 bool ChatHandler::HandleReloadAllLocalesCommand(const char* /*args*/)
180 HandleReloadLocalesAchievementRewardCommand("a");
181 HandleReloadLocalesCreatureCommand("a");
182 HandleReloadLocalesGameobjectCommand("a");
183 HandleReloadLocalesGossipMenuOptionCommand("a");
184 HandleReloadLocalesItemCommand("a");
185 HandleReloadLocalesNpcTextCommand("a");
186 HandleReloadLocalesPageTextCommand("a");
187 HandleReloadLocalesPointsOfInterestCommand("a");
188 HandleReloadLocalesQuestCommand("a");
189 return true;
192 bool ChatHandler::HandleReloadConfigCommand(const char* /*args*/)
194 sLog.outString( "Re-Loading config settings..." );
195 sWorld.LoadConfigSettings(true);
196 sMapMgr.InitializeVisibilityDistanceInfo();
197 SendGlobalSysMessage("World config settings reloaded.");
198 return true;
201 bool ChatHandler::HandleReloadAchievementCriteriaRequirementCommand(const char*)
203 sLog.outString( "Re-Loading Additional Achievement Criteria Requirements Data..." );
204 sAchievementMgr.LoadAchievementCriteriaRequirements();
205 SendGlobalSysMessage("DB table `achievement_criteria_requirement` reloaded.");
206 return true;
209 bool ChatHandler::HandleReloadAchievementRewardCommand(const char*)
211 sLog.outString( "Re-Loading Achievement Reward Data..." );
212 sAchievementMgr.LoadRewards();
213 SendGlobalSysMessage("DB table `achievement_reward` reloaded.");
214 return true;
217 bool ChatHandler::HandleReloadAreaTriggerTavernCommand(const char*)
219 sLog.outString( "Re-Loading Tavern Area Triggers..." );
220 sObjectMgr.LoadTavernAreaTriggers();
221 SendGlobalSysMessage("DB table `areatrigger_tavern` reloaded.");
222 return true;
225 bool ChatHandler::HandleReloadAreaTriggerTeleportCommand(const char*)
227 sLog.outString( "Re-Loading AreaTrigger teleport definitions..." );
228 sObjectMgr.LoadAreaTriggerTeleports();
229 SendGlobalSysMessage("DB table `areatrigger_teleport` reloaded.");
230 return true;
233 bool ChatHandler::HandleReloadCommandCommand(const char*)
235 load_command_table = true;
236 SendGlobalSysMessage("DB table `command` will be reloaded at next chat command use.");
237 return true;
240 bool ChatHandler::HandleReloadCreatureQuestRelationsCommand(const char*)
242 sLog.outString( "Loading Quests Relations... (`creature_questrelation`)" );
243 sObjectMgr.LoadCreatureQuestRelations();
244 SendGlobalSysMessage("DB table `creature_questrelation` (creature quest givers) reloaded.");
245 return true;
248 bool ChatHandler::HandleReloadCreatureQuestInvRelationsCommand(const char*)
250 sLog.outString( "Loading Quests Relations... (`creature_involvedrelation`)" );
251 sObjectMgr.LoadCreatureInvolvedRelations();
252 SendGlobalSysMessage("DB table `creature_involvedrelation` (creature quest takers) reloaded.");
253 return true;
256 bool ChatHandler::HandleReloadGossipMenuCommand(const char*)
258 sLog.outString( "Re-Loading `gossip_menu` Table!" );
259 sObjectMgr.LoadGossipMenu();
260 SendGlobalSysMessage("DB table `gossip_menu` reloaded.");
261 return true;
264 bool ChatHandler::HandleReloadGossipMenuOptionCommand(const char*)
266 sLog.outString( "Re-Loading `gossip_menu_option` Table!" );
267 sObjectMgr.LoadGossipMenuItems();
268 SendGlobalSysMessage("DB table `gossip_menu_option` reloaded.");
269 return true;
272 bool ChatHandler::HandleReloadGossipScriptsCommand(const char* arg)
274 if(sWorld.IsScriptScheduled())
276 SendSysMessage("DB scripts used currently, please attempt reload later.");
277 SetSentErrorMessage(true);
278 return false;
281 if(*arg!='a')
282 sLog.outString( "Re-Loading Scripts from `gossip_scripts`...");
284 sObjectMgr.LoadGossipScripts();
286 if(*arg!='a')
287 SendGlobalSysMessage("DB table `gossip_scripts` reloaded.");
289 return true;
292 bool ChatHandler::HandleReloadGOQuestRelationsCommand(const char*)
294 sLog.outString( "Loading Quests Relations... (`gameobject_questrelation`)" );
295 sObjectMgr.LoadGameobjectQuestRelations();
296 SendGlobalSysMessage("DB table `gameobject_questrelation` (gameobject quest givers) reloaded.");
297 return true;
300 bool ChatHandler::HandleReloadGOQuestInvRelationsCommand(const char*)
302 sLog.outString( "Loading Quests Relations... (`gameobject_involvedrelation`)" );
303 sObjectMgr.LoadGameobjectInvolvedRelations();
304 SendGlobalSysMessage("DB table `gameobject_involvedrelation` (gameobject quest takers) reloaded.");
305 return true;
308 bool ChatHandler::HandleReloadQuestAreaTriggersCommand(const char*)
310 sLog.outString( "Re-Loading Quest Area Triggers..." );
311 sObjectMgr.LoadQuestAreaTriggers();
312 SendGlobalSysMessage("DB table `areatrigger_involvedrelation` (quest area triggers) reloaded.");
313 return true;
316 bool ChatHandler::HandleReloadQuestTemplateCommand(const char*)
318 sLog.outString( "Re-Loading Quest Templates..." );
319 sObjectMgr.LoadQuests();
320 SendGlobalSysMessage("DB table `quest_template` (quest definitions) reloaded.");
322 /// dependent also from `gameobject` but this table not reloaded anyway
323 sLog.outString( "Re-Loading GameObjects for quests..." );
324 sObjectMgr.LoadGameObjectForQuests();
325 SendGlobalSysMessage("Data GameObjects for quests reloaded.");
326 return true;
329 bool ChatHandler::HandleReloadLootTemplatesCreatureCommand(const char*)
331 sLog.outString( "Re-Loading Loot Tables... (`creature_loot_template`)" );
332 LoadLootTemplates_Creature();
333 LootTemplates_Creature.CheckLootRefs();
334 SendGlobalSysMessage("DB table `creature_loot_template` reloaded.");
335 return true;
338 bool ChatHandler::HandleReloadLootTemplatesDisenchantCommand(const char*)
340 sLog.outString( "Re-Loading Loot Tables... (`disenchant_loot_template`)" );
341 LoadLootTemplates_Disenchant();
342 LootTemplates_Disenchant.CheckLootRefs();
343 SendGlobalSysMessage("DB table `disenchant_loot_template` reloaded.");
344 return true;
347 bool ChatHandler::HandleReloadLootTemplatesFishingCommand(const char*)
349 sLog.outString( "Re-Loading Loot Tables... (`fishing_loot_template`)" );
350 LoadLootTemplates_Fishing();
351 LootTemplates_Fishing.CheckLootRefs();
352 SendGlobalSysMessage("DB table `fishing_loot_template` reloaded.");
353 return true;
356 bool ChatHandler::HandleReloadLootTemplatesGameobjectCommand(const char*)
358 sLog.outString( "Re-Loading Loot Tables... (`gameobject_loot_template`)" );
359 LoadLootTemplates_Gameobject();
360 LootTemplates_Gameobject.CheckLootRefs();
361 SendGlobalSysMessage("DB table `gameobject_loot_template` reloaded.");
362 return true;
365 bool ChatHandler::HandleReloadLootTemplatesItemCommand(const char*)
367 sLog.outString( "Re-Loading Loot Tables... (`item_loot_template`)" );
368 LoadLootTemplates_Item();
369 LootTemplates_Item.CheckLootRefs();
370 SendGlobalSysMessage("DB table `item_loot_template` reloaded.");
371 return true;
374 bool ChatHandler::HandleReloadLootTemplatesMillingCommand(const char*)
376 sLog.outString( "Re-Loading Loot Tables... (`milling_loot_template`)" );
377 LoadLootTemplates_Milling();
378 LootTemplates_Milling.CheckLootRefs();
379 SendGlobalSysMessage("DB table `milling_loot_template` reloaded.");
380 return true;
383 bool ChatHandler::HandleReloadLootTemplatesPickpocketingCommand(const char*)
385 sLog.outString( "Re-Loading Loot Tables... (`pickpocketing_loot_template`)" );
386 LoadLootTemplates_Pickpocketing();
387 LootTemplates_Pickpocketing.CheckLootRefs();
388 SendGlobalSysMessage("DB table `pickpocketing_loot_template` reloaded.");
389 return true;
392 bool ChatHandler::HandleReloadLootTemplatesProspectingCommand(const char*)
394 sLog.outString( "Re-Loading Loot Tables... (`prospecting_loot_template`)" );
395 LoadLootTemplates_Prospecting();
396 LootTemplates_Prospecting.CheckLootRefs();
397 SendGlobalSysMessage("DB table `prospecting_loot_template` reloaded.");
398 return true;
401 bool ChatHandler::HandleReloadLootTemplatesMailCommand(const char*)
403 sLog.outString( "Re-Loading Loot Tables... (`mail_loot_template`)" );
404 LoadLootTemplates_Mail();
405 LootTemplates_Mail.CheckLootRefs();
406 SendGlobalSysMessage("DB table `mail_loot_template` reloaded.");
407 return true;
410 bool ChatHandler::HandleReloadLootTemplatesReferenceCommand(const char*)
412 sLog.outString( "Re-Loading Loot Tables... (`reference_loot_template`)" );
413 LoadLootTemplates_Reference();
414 SendGlobalSysMessage("DB table `reference_loot_template` reloaded.");
415 return true;
418 bool ChatHandler::HandleReloadLootTemplatesSkinningCommand(const char*)
420 sLog.outString( "Re-Loading Loot Tables... (`skinning_loot_template`)" );
421 LoadLootTemplates_Skinning();
422 LootTemplates_Skinning.CheckLootRefs();
423 SendGlobalSysMessage("DB table `skinning_loot_template` reloaded.");
424 return true;
427 bool ChatHandler::HandleReloadLootTemplatesSpellCommand(const char*)
429 sLog.outString( "Re-Loading Loot Tables... (`spell_loot_template`)" );
430 LoadLootTemplates_Spell();
431 LootTemplates_Spell.CheckLootRefs();
432 SendGlobalSysMessage("DB table `spell_loot_template` reloaded.");
433 return true;
436 bool ChatHandler::HandleReloadMangosStringCommand(const char*)
438 sLog.outString( "Re-Loading mangos_string Table!" );
439 sObjectMgr.LoadMangosStrings();
440 SendGlobalSysMessage("DB table `mangos_string` reloaded.");
441 return true;
444 bool ChatHandler::HandleReloadNpcGossipCommand(const char*)
446 sLog.outString( "Re-Loading `npc_gossip` Table!" );
447 sObjectMgr.LoadNpcTextId();
448 SendGlobalSysMessage("DB table `npc_gossip` reloaded.");
449 return true;
452 bool ChatHandler::HandleReloadNpcTrainerCommand(const char*)
454 sLog.outString( "Re-Loading `npc_trainer` Table!" );
455 sObjectMgr.LoadTrainerSpell();
456 SendGlobalSysMessage("DB table `npc_trainer` reloaded.");
457 return true;
460 bool ChatHandler::HandleReloadNpcVendorCommand(const char*)
462 sLog.outString( "Re-Loading `npc_vendor` Table!" );
463 sObjectMgr.LoadVendors();
464 SendGlobalSysMessage("DB table `npc_vendor` reloaded.");
465 return true;
468 bool ChatHandler::HandleReloadPointsOfInterestCommand(const char*)
470 sLog.outString( "Re-Loading `points_of_interest` Table!" );
471 sObjectMgr.LoadPointsOfInterest();
472 SendGlobalSysMessage("DB table `points_of_interest` reloaded.");
473 return true;
476 bool ChatHandler::HandleReloadSpellClickSpellsCommand(const char*)
478 sLog.outString( "Re-Loading `npc_spellclick_spells` Table!" );
479 sObjectMgr.LoadNPCSpellClickSpells();
480 SendGlobalSysMessage("DB table `npc_spellclick_spells` reloaded.");
481 return true;
484 bool ChatHandler::HandleReloadReservedNameCommand(const char*)
486 sLog.outString( "Loading ReservedNames... (`reserved_name`)" );
487 sObjectMgr.LoadReservedPlayersNames();
488 SendGlobalSysMessage("DB table `reserved_name` (player reserved names) reloaded.");
489 return true;
492 bool ChatHandler::HandleReloadSkillDiscoveryTemplateCommand(const char* /*args*/)
494 sLog.outString( "Re-Loading Skill Discovery Table..." );
495 LoadSkillDiscoveryTable();
496 SendGlobalSysMessage("DB table `skill_discovery_template` (recipes discovered at crafting) reloaded.");
497 return true;
500 bool ChatHandler::HandleReloadSkillExtraItemTemplateCommand(const char* /*args*/)
502 sLog.outString( "Re-Loading Skill Extra Item Table..." );
503 LoadSkillExtraItemTable();
504 SendGlobalSysMessage("DB table `skill_extra_item_template` (extra item creation when crafting) reloaded.");
505 return true;
508 bool ChatHandler::HandleReloadSkillFishingBaseLevelCommand(const char* /*args*/)
510 sLog.outString( "Re-Loading Skill Fishing base level requirements..." );
511 sObjectMgr.LoadFishingBaseSkillLevel();
512 SendGlobalSysMessage("DB table `skill_fishing_base_level` (fishing base level for zone/subzone) reloaded.");
513 return true;
516 bool ChatHandler::HandleReloadSpellAreaCommand(const char*)
518 sLog.outString( "Re-Loading SpellArea Data..." );
519 sSpellMgr.LoadSpellAreas();
520 SendGlobalSysMessage("DB table `spell_area` (spell dependences from area/quest/auras state) reloaded.");
521 return true;
524 bool ChatHandler::HandleReloadSpellChainCommand(const char*)
526 sLog.outString( "Re-Loading Spell Chain Data... " );
527 sSpellMgr.LoadSpellChains();
528 SendGlobalSysMessage("DB table `spell_chain` (spell ranks) reloaded.");
529 return true;
532 bool ChatHandler::HandleReloadSpellElixirCommand(const char*)
534 sLog.outString( "Re-Loading Spell Elixir types..." );
535 sSpellMgr.LoadSpellElixirs();
536 SendGlobalSysMessage("DB table `spell_elixir` (spell elixir types) reloaded.");
537 return true;
540 bool ChatHandler::HandleReloadSpellLearnSpellCommand(const char*)
542 sLog.outString( "Re-Loading Spell Learn Spells..." );
543 sSpellMgr.LoadSpellLearnSpells();
544 SendGlobalSysMessage("DB table `spell_learn_spell` reloaded.");
545 return true;
548 bool ChatHandler::HandleReloadSpellProcEventCommand(const char*)
550 sLog.outString( "Re-Loading Spell Proc Event conditions..." );
551 sSpellMgr.LoadSpellProcEvents();
552 SendGlobalSysMessage("DB table `spell_proc_event` (spell proc trigger requirements) reloaded.");
553 return true;
556 bool ChatHandler::HandleReloadSpellBonusesCommand(const char*)
558 sLog.outString( "Re-Loading Spell Bonus Data..." );
559 sSpellMgr.LoadSpellBonusess();
560 SendGlobalSysMessage("DB table `spell_bonus_data` (spell damage/healing coefficients) reloaded.");
561 return true;
564 bool ChatHandler::HandleReloadSpellProcItemEnchantCommand(const char*)
566 sLog.outString( "Re-Loading Spell Proc Item Enchant..." );
567 sSpellMgr.LoadSpellProcItemEnchant();
568 SendGlobalSysMessage("DB table `spell_proc_item_enchant` (item enchantment ppm) reloaded.");
569 return true;
572 bool ChatHandler::HandleReloadSpellScriptTargetCommand(const char*)
574 sLog.outString( "Re-Loading SpellsScriptTarget..." );
575 sSpellMgr.LoadSpellScriptTarget();
576 SendGlobalSysMessage("DB table `spell_script_target` (spell targets selection in case specific creature/GO requirements) reloaded.");
577 return true;
580 bool ChatHandler::HandleReloadSpellTargetPositionCommand(const char*)
582 sLog.outString( "Re-Loading Spell target coordinates..." );
583 sSpellMgr.LoadSpellTargetPositions();
584 SendGlobalSysMessage("DB table `spell_target_position` (destination coordinates for spell targets) reloaded.");
585 return true;
588 bool ChatHandler::HandleReloadSpellThreatsCommand(const char*)
590 sLog.outString( "Re-Loading Aggro Spells Definitions...");
591 sSpellMgr.LoadSpellThreats();
592 SendGlobalSysMessage("DB table `spell_threat` (spell aggro definitions) reloaded.");
593 return true;
596 bool ChatHandler::HandleReloadSpellPetAurasCommand(const char*)
598 sLog.outString( "Re-Loading Spell pet auras...");
599 sSpellMgr.LoadSpellPetAuras();
600 SendGlobalSysMessage("DB table `spell_pet_auras` reloaded.");
601 return true;
604 bool ChatHandler::HandleReloadPageTextsCommand(const char*)
606 sLog.outString( "Re-Loading Page Texts..." );
607 sObjectMgr.LoadPageTexts();
608 SendGlobalSysMessage("DB table `page_texts` reloaded.");
609 return true;
612 bool ChatHandler::HandleReloadItemEnchantementsCommand(const char*)
614 sLog.outString( "Re-Loading Item Random Enchantments Table..." );
615 LoadRandomEnchantmentsTable();
616 SendGlobalSysMessage("DB table `item_enchantment_template` reloaded.");
617 return true;
620 bool ChatHandler::HandleReloadItemRequiredTragetCommand(const char*)
622 sLog.outString( "Re-Loading Item Required Targets Table..." );
623 sObjectMgr.LoadItemRequiredTarget();
624 SendGlobalSysMessage("DB table `item_required_target` reloaded.");
625 return true;
628 bool ChatHandler::HandleReloadBattleEventCommand(const char*)
630 sLog.outString( "Re-Loading BattleGround Eventindexes..." );
631 sBattleGroundMgr.LoadBattleEventIndexes();
632 SendGlobalSysMessage("DB table `gameobject_battleground` and `creature_battleground` reloaded.");
633 return true;
636 bool ChatHandler::HandleReloadGameObjectScriptsCommand(const char* arg)
638 if(sWorld.IsScriptScheduled())
640 SendSysMessage("DB scripts used currently, please attempt reload later.");
641 SetSentErrorMessage(true);
642 return false;
645 if(*arg!='a')
646 sLog.outString( "Re-Loading Scripts from `gameobject_scripts`...");
648 sObjectMgr.LoadGameObjectScripts();
650 if(*arg!='a')
651 SendGlobalSysMessage("DB table `gameobject_scripts` reloaded.");
653 return true;
656 bool ChatHandler::HandleReloadEventScriptsCommand(const char* arg)
658 if(sWorld.IsScriptScheduled())
660 SendSysMessage("DB scripts used currently, please attempt reload later.");
661 SetSentErrorMessage(true);
662 return false;
665 if(*arg!='a')
666 sLog.outString( "Re-Loading Scripts from `event_scripts`...");
668 sObjectMgr.LoadEventScripts();
670 if(*arg!='a')
671 SendGlobalSysMessage("DB table `event_scripts` reloaded.");
673 return true;
676 bool ChatHandler::HandleReloadEventAITextsCommand(const char* arg)
679 sLog.outString( "Re-Loading Texts from `creature_ai_texts`...");
680 sEventAIMgr.LoadCreatureEventAI_Texts(true);
681 SendGlobalSysMessage("DB table `creature_ai_texts` reloaded.");
682 return true;
685 bool ChatHandler::HandleReloadEventAISummonsCommand(const char* arg)
687 sLog.outString( "Re-Loading Summons from `creature_ai_summons`...");
688 sEventAIMgr.LoadCreatureEventAI_Summons(true);
689 SendGlobalSysMessage("DB table `creature_ai_summons` reloaded.");
690 return true;
693 bool ChatHandler::HandleReloadEventAIScriptsCommand(const char* arg)
695 sLog.outString( "Re-Loading Scripts from `creature_ai_scripts`...");
696 sEventAIMgr.LoadCreatureEventAI_Scripts();
697 SendGlobalSysMessage("DB table `creature_ai_scripts` reloaded.");
698 return true;
701 bool ChatHandler::HandleReloadQuestEndScriptsCommand(const char* arg)
703 if(sWorld.IsScriptScheduled())
705 SendSysMessage("DB scripts used currently, please attempt reload later.");
706 SetSentErrorMessage(true);
707 return false;
710 if(*arg!='a')
711 sLog.outString( "Re-Loading Scripts from `quest_end_scripts`...");
713 sObjectMgr.LoadQuestEndScripts();
715 if(*arg!='a')
716 SendGlobalSysMessage("DB table `quest_end_scripts` reloaded.");
718 return true;
721 bool ChatHandler::HandleReloadQuestStartScriptsCommand(const char* arg)
723 if(sWorld.IsScriptScheduled())
725 SendSysMessage("DB scripts used currently, please attempt reload later.");
726 SetSentErrorMessage(true);
727 return false;
730 if(*arg!='a')
731 sLog.outString( "Re-Loading Scripts from `quest_start_scripts`...");
733 sObjectMgr.LoadQuestStartScripts();
735 if(*arg!='a')
736 SendGlobalSysMessage("DB table `quest_start_scripts` reloaded.");
738 return true;
741 bool ChatHandler::HandleReloadSpellScriptsCommand(const char* arg)
743 if(sWorld.IsScriptScheduled())
745 SendSysMessage("DB scripts used currently, please attempt reload later.");
746 SetSentErrorMessage(true);
747 return false;
750 if(*arg!='a')
751 sLog.outString( "Re-Loading Scripts from `spell_scripts`...");
753 sObjectMgr.LoadSpellScripts();
755 if(*arg!='a')
756 SendGlobalSysMessage("DB table `spell_scripts` reloaded.");
758 return true;
761 bool ChatHandler::HandleReloadDbScriptStringCommand(const char* /*arg*/)
763 sLog.outString( "Re-Loading Script strings from `db_script_string`...");
764 sObjectMgr.LoadDbScriptStrings();
765 SendGlobalSysMessage("DB table `db_script_string` reloaded.");
766 return true;
769 bool ChatHandler::HandleReloadGameGraveyardZoneCommand(const char* /*arg*/)
771 sLog.outString( "Re-Loading Graveyard-zone links...");
773 sObjectMgr.LoadGraveyardZones();
775 SendGlobalSysMessage("DB table `game_graveyard_zone` reloaded.");
777 return true;
780 bool ChatHandler::HandleReloadGameTeleCommand(const char* /*arg*/)
782 sLog.outString( "Re-Loading Game Tele coordinates...");
784 sObjectMgr.LoadGameTele();
786 SendGlobalSysMessage("DB table `game_tele` reloaded.");
788 return true;
791 bool ChatHandler::HandleReloadLocalesAchievementRewardCommand(const char*)
793 sLog.outString( "Re-Loading Locales Achievement Reward Data..." );
794 sAchievementMgr.LoadRewardLocales();
795 SendGlobalSysMessage("DB table `locales_achievement_reward` reloaded.");
796 return true;
799 bool ChatHandler::HandleReloadLocalesCreatureCommand(const char* /*arg*/)
801 sLog.outString( "Re-Loading Locales Creature ...");
802 sObjectMgr.LoadCreatureLocales();
803 SendGlobalSysMessage("DB table `locales_creature` reloaded.");
804 return true;
807 bool ChatHandler::HandleReloadLocalesGameobjectCommand(const char* /*arg*/)
809 sLog.outString( "Re-Loading Locales Gameobject ... ");
810 sObjectMgr.LoadGameObjectLocales();
811 SendGlobalSysMessage("DB table `locales_gameobject` reloaded.");
812 return true;
815 bool ChatHandler::HandleReloadLocalesGossipMenuOptionCommand(const char* /*arg*/)
817 sLog.outString( "Re-Loading Locales Gossip Menu Option ... ");
818 sObjectMgr.LoadGossipMenuItemsLocales();
819 SendGlobalSysMessage("DB table `locales_gossip_menu_option` reloaded.");
820 return true;
823 bool ChatHandler::HandleReloadLocalesItemCommand(const char* /*arg*/)
825 sLog.outString( "Re-Loading Locales Item ... ");
826 sObjectMgr.LoadItemLocales();
827 SendGlobalSysMessage("DB table `locales_item` reloaded.");
828 return true;
831 bool ChatHandler::HandleReloadLocalesNpcTextCommand(const char* /*arg*/)
833 sLog.outString( "Re-Loading Locales NPC Text ... ");
834 sObjectMgr.LoadNpcTextLocales();
835 SendGlobalSysMessage("DB table `locales_npc_text` reloaded.");
836 return true;
839 bool ChatHandler::HandleReloadLocalesPageTextCommand(const char* /*arg*/)
841 sLog.outString( "Re-Loading Locales Page Text ... ");
842 sObjectMgr.LoadPageTextLocales();
843 SendGlobalSysMessage("DB table `locales_page_text` reloaded.");
844 return true;
847 bool ChatHandler::HandleReloadLocalesPointsOfInterestCommand(const char* /*arg*/)
849 sLog.outString( "Re-Loading Locales Points Of Interest ... ");
850 sObjectMgr.LoadPointOfInterestLocales();
851 SendGlobalSysMessage("DB table `locales_points_of_interest` reloaded.");
852 return true;
855 bool ChatHandler::HandleReloadLocalesQuestCommand(const char* /*arg*/)
857 sLog.outString( "Re-Loading Locales Quest ... ");
858 sObjectMgr.LoadQuestLocales();
859 SendGlobalSysMessage("DB table `locales_quest` reloaded.");
860 return true;
863 bool ChatHandler::HandleReloadMailLevelRewardCommand(const char* /*arg*/)
865 sLog.outString( "Re-Loading Player level dependent mail rewards..." );
866 sObjectMgr.LoadMailLevelRewards();
867 SendGlobalSysMessage("DB table `mail_level_reward` reloaded.");
868 return true;
871 bool ChatHandler::HandleLoadScriptsCommand(const char* args)
873 if(!LoadScriptingModule(args)) return true;
875 sWorld.SendWorldText(LANG_SCRIPTS_RELOADED);
876 return true;
879 bool ChatHandler::HandleAccountSetGmLevelCommand(const char* args)
881 char* arg1 = strtok((char*)args, " ");
882 if( !arg1 )
883 return false;
885 /// must be NULL if targeted syntax and must be not nULL if not targeted
886 char* arg2 = strtok(NULL, " ");
888 std::string targetAccountName;
889 uint32 targetAccountId = 0;
891 /// only target player different from self allowed (if targetPlayer!=NULL then not console)
892 Player* targetPlayer = getSelectedPlayer();
893 if(targetPlayer && m_session->GetPlayer()!=targetPlayer)
895 /// wrong command syntax or unexpected targeting
896 if(arg2)
897 return false;
899 /// security level expected in arg2 after this if.
900 arg2 = arg1;
902 targetAccountId = targetPlayer->GetSession()->GetAccountId();
903 sAccountMgr.GetName(targetAccountId, targetAccountName);
905 else
907 /// wrong command syntax (second arg expected)
908 if(!arg2)
909 return false;
911 targetAccountName = arg1;
912 if (!AccountMgr::normalizeString(targetAccountName))
914 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,targetAccountName.c_str());
915 SetSentErrorMessage(true);
916 return false;
919 targetAccountId = sAccountMgr.GetId(targetAccountName);
920 if(!targetAccountId)
922 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,targetAccountName.c_str());
923 SetSentErrorMessage(true);
924 return false;
928 int32 gm = (int32)atoi(arg2);
929 if ( gm < SEC_PLAYER || gm > SEC_ADMINISTRATOR )
931 SendSysMessage(LANG_BAD_VALUE);
932 SetSentErrorMessage(true);
933 return false;
936 /// can set security level only for target with less security and to less security that we have
937 /// This will reject self apply by specify account name
938 if(HasLowerSecurityAccount(NULL,targetAccountId,true))
939 return false;
941 /// account can't set security to same or grater level, need more power GM or console
942 AccountTypes plSecurity = m_session ? m_session->GetSecurity() : SEC_CONSOLE;
943 if (AccountTypes(gm) >= plSecurity )
945 SendSysMessage(LANG_YOURS_SECURITY_IS_LOW);
946 SetSentErrorMessage(true);
947 return false;
950 // This will prevent self apply by self target or no target
951 if(targetPlayer && m_session->GetPlayer()!=targetPlayer)
953 ChatHandler(targetPlayer).PSendSysMessage(LANG_YOURS_SECURITY_CHANGED,GetNameLink().c_str(), gm);
954 targetPlayer->GetSession()->SetSecurity(AccountTypes(gm));
957 PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetAccountName.c_str(), gm);
958 loginDatabase.PExecute("UPDATE account SET gmlevel = '%i' WHERE id = '%u'", gm, targetAccountId);
960 return true;
963 /// Set password for account
964 bool ChatHandler::HandleAccountSetPasswordCommand(const char* args)
966 if(!*args)
967 return false;
969 ///- Get the command line arguments
970 char *szAccount = strtok ((char*)args," ");
971 char *szPassword1 = strtok (NULL," ");
972 char *szPassword2 = strtok (NULL," ");
974 if (!szAccount||!szPassword1 || !szPassword2)
975 return false;
977 std::string account_name = szAccount;
978 if (!AccountMgr::normalizeString(account_name))
980 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
981 SetSentErrorMessage(true);
982 return false;
985 uint32 targetAccountId = sAccountMgr.GetId(account_name);
986 if (!targetAccountId)
988 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
989 SetSentErrorMessage(true);
990 return false;
993 /// can set password only for target with less security
994 /// This is also reject self apply in fact
995 if(HasLowerSecurityAccount (NULL,targetAccountId,true))
996 return false;
998 if (strcmp(szPassword1,szPassword2))
1000 SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH);
1001 SetSentErrorMessage (true);
1002 return false;
1005 AccountOpResult result = sAccountMgr.ChangePassword(targetAccountId, szPassword1);
1007 switch(result)
1009 case AOR_OK:
1010 SendSysMessage(LANG_COMMAND_PASSWORD);
1011 break;
1012 case AOR_NAME_NOT_EXIST:
1013 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
1014 SetSentErrorMessage(true);
1015 return false;
1016 case AOR_PASS_TOO_LONG:
1017 SendSysMessage(LANG_PASSWORD_TOO_LONG);
1018 SetSentErrorMessage(true);
1019 return false;
1020 default:
1021 SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD);
1022 SetSentErrorMessage(true);
1023 return false;
1026 return true;
1029 bool ChatHandler::HandleMaxSkillCommand(const char* /*args*/)
1031 Player* SelectedPlayer = getSelectedPlayer();
1032 if(!SelectedPlayer)
1034 SendSysMessage(LANG_NO_CHAR_SELECTED);
1035 SetSentErrorMessage(true);
1036 return false;
1039 // each skills that have max skill value dependent from level seted to current level max skill value
1040 SelectedPlayer->UpdateSkillsToMaxSkillsForLevel();
1041 return true;
1044 bool ChatHandler::HandleSetSkillCommand(const char* args)
1046 // number or [name] Shift-click form |color|Hskill:skill_id|h[name]|h|r
1047 char* skill_p = extractKeyFromLink((char*)args,"Hskill");
1048 if(!skill_p)
1049 return false;
1051 char *level_p = strtok (NULL, " ");
1053 if( !level_p)
1054 return false;
1056 char *max_p = strtok (NULL, " ");
1058 int32 skill = atoi(skill_p);
1059 if (skill <= 0)
1061 PSendSysMessage(LANG_INVALID_SKILL_ID, skill);
1062 SetSentErrorMessage(true);
1063 return false;
1066 int32 level = atol (level_p);
1068 Player * target = getSelectedPlayer();
1069 if(!target)
1071 SendSysMessage(LANG_NO_CHAR_SELECTED);
1072 SetSentErrorMessage(true);
1073 return false;
1076 SkillLineEntry const* sl = sSkillLineStore.LookupEntry(skill);
1077 if(!sl)
1079 PSendSysMessage(LANG_INVALID_SKILL_ID, skill);
1080 SetSentErrorMessage(true);
1081 return false;
1084 std::string tNameLink = GetNameLink(target);
1086 if(!target->GetSkillValue(skill))
1088 PSendSysMessage(LANG_SET_SKILL_ERROR, tNameLink.c_str(), skill, sl->name[GetSessionDbcLocale()]);
1089 SetSentErrorMessage(true);
1090 return false;
1093 int32 max = max_p ? atol (max_p) : target->GetPureMaxSkillValue(skill);
1095 if( level <= 0 || level > max || max <= 0 )
1096 return false;
1098 target->SetSkill(skill, level, max);
1099 PSendSysMessage(LANG_SET_SKILL, skill, sl->name[GetSessionDbcLocale()], tNameLink.c_str(), level, max);
1101 return true;
1104 bool ChatHandler::HandleUnLearnCommand(const char* args)
1106 if (!*args)
1107 return false;
1109 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
1110 uint32 spell_id = extractSpellIdFromLink((char*)args);
1111 if(!spell_id)
1112 return false;
1114 char const* allStr = strtok(NULL," ");
1115 bool allRanks = allStr ? (strncmp(allStr, "all", strlen(allStr)) == 0) : false;
1117 Player* target = getSelectedPlayer();
1118 if(!target)
1120 SendSysMessage(LANG_NO_CHAR_SELECTED);
1121 SetSentErrorMessage(true);
1122 return false;
1125 if(allRanks)
1126 spell_id = sSpellMgr.GetFirstSpellInChain (spell_id);
1128 if (target->HasSpell(spell_id))
1129 target->removeSpell(spell_id,false,!allRanks);
1130 else
1131 SendSysMessage(LANG_FORGET_SPELL);
1133 if(GetTalentSpellCost(spell_id))
1134 target->SendTalentsInfoData(false);
1136 return true;
1139 bool ChatHandler::HandleCooldownCommand(const char* args)
1141 Player* target = getSelectedPlayer();
1142 if(!target)
1144 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1145 SetSentErrorMessage(true);
1146 return false;
1149 std::string tNameLink = GetNameLink(target);
1151 if (!*args)
1153 target->RemoveAllSpellCooldown();
1154 PSendSysMessage(LANG_REMOVEALL_COOLDOWN, tNameLink.c_str());
1156 else
1158 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1159 uint32 spell_id = extractSpellIdFromLink((char*)args);
1160 if(!spell_id)
1161 return false;
1163 if(!sSpellStore.LookupEntry(spell_id))
1165 PSendSysMessage(LANG_UNKNOWN_SPELL, target==m_session->GetPlayer() ? GetMangosString(LANG_YOU) : tNameLink.c_str());
1166 SetSentErrorMessage(true);
1167 return false;
1170 target->RemoveSpellCooldown(spell_id,true);
1171 PSendSysMessage(LANG_REMOVE_COOLDOWN, spell_id, target==m_session->GetPlayer() ? GetMangosString(LANG_YOU) : tNameLink.c_str());
1173 return true;
1176 bool ChatHandler::HandleLearnAllCommand(const char* /*args*/)
1178 static const char *allSpellList[] =
1180 "3365",
1181 "6233",
1182 "6247",
1183 "6246",
1184 "6477",
1185 "6478",
1186 "22810",
1187 "8386",
1188 "21651",
1189 "21652",
1190 "522",
1191 "7266",
1192 "8597",
1193 "2479",
1194 "22027",
1195 "6603",
1196 "5019",
1197 "133",
1198 "168",
1199 "227",
1200 "5009",
1201 "9078",
1202 "668",
1203 "203",
1204 "20599",
1205 "20600",
1206 "81",
1207 "20597",
1208 "20598",
1209 "20864",
1210 "1459",
1211 "5504",
1212 "587",
1213 "5143",
1214 "118",
1215 "5505",
1216 "597",
1217 "604",
1218 "1449",
1219 "1460",
1220 "2855",
1221 "1008",
1222 "475",
1223 "5506",
1224 "1463",
1225 "12824",
1226 "8437",
1227 "990",
1228 "5145",
1229 "8450",
1230 "1461",
1231 "759",
1232 "8494",
1233 "8455",
1234 "8438",
1235 "6127",
1236 "8416",
1237 "6129",
1238 "8451",
1239 "8495",
1240 "8439",
1241 "3552",
1242 "8417",
1243 "10138",
1244 "12825",
1245 "10169",
1246 "10156",
1247 "10144",
1248 "10191",
1249 "10201",
1250 "10211",
1251 "10053",
1252 "10173",
1253 "10139",
1254 "10145",
1255 "10192",
1256 "10170",
1257 "10202",
1258 "10054",
1259 "10174",
1260 "10193",
1261 "12826",
1262 "2136",
1263 "143",
1264 "145",
1265 "2137",
1266 "2120",
1267 "3140",
1268 "543",
1269 "2138",
1270 "2948",
1271 "8400",
1272 "2121",
1273 "8444",
1274 "8412",
1275 "8457",
1276 "8401",
1277 "8422",
1278 "8445",
1279 "8402",
1280 "8413",
1281 "8458",
1282 "8423",
1283 "8446",
1284 "10148",
1285 "10197",
1286 "10205",
1287 "10149",
1288 "10215",
1289 "10223",
1290 "10206",
1291 "10199",
1292 "10150",
1293 "10216",
1294 "10207",
1295 "10225",
1296 "10151",
1297 "116",
1298 "205",
1299 "7300",
1300 "122",
1301 "837",
1302 "10",
1303 "7301",
1304 "7322",
1305 "6143",
1306 "120",
1307 "865",
1308 "8406",
1309 "6141",
1310 "7302",
1311 "8461",
1312 "8407",
1313 "8492",
1314 "8427",
1315 "8408",
1316 "6131",
1317 "7320",
1318 "10159",
1319 "8462",
1320 "10185",
1321 "10179",
1322 "10160",
1323 "10180",
1324 "10219",
1325 "10186",
1326 "10177",
1327 "10230",
1328 "10181",
1329 "10161",
1330 "10187",
1331 "10220",
1332 "2018",
1333 "2663",
1334 "12260",
1335 "2660",
1336 "3115",
1337 "3326",
1338 "2665",
1339 "3116",
1340 "2738",
1341 "3293",
1342 "2661",
1343 "3319",
1344 "2662",
1345 "9983",
1346 "8880",
1347 "2737",
1348 "2739",
1349 "7408",
1350 "3320",
1351 "2666",
1352 "3323",
1353 "3324",
1354 "3294",
1355 "22723",
1356 "23219",
1357 "23220",
1358 "23221",
1359 "23228",
1360 "23338",
1361 "10788",
1362 "10790",
1363 "5611",
1364 "5016",
1365 "5609",
1366 "2060",
1367 "10963",
1368 "10964",
1369 "10965",
1370 "22593",
1371 "22594",
1372 "596",
1373 "996",
1374 "499",
1375 "768",
1376 "17002",
1377 "1448",
1378 "1082",
1379 "16979",
1380 "1079",
1381 "5215",
1382 "20484",
1383 "5221",
1384 "15590",
1385 "17007",
1386 "6795",
1387 "6807",
1388 "5487",
1389 "1446",
1390 "1066",
1391 "5421",
1392 "3139",
1393 "779",
1394 "6811",
1395 "6808",
1396 "1445",
1397 "5216",
1398 "1737",
1399 "5222",
1400 "5217",
1401 "1432",
1402 "6812",
1403 "9492",
1404 "5210",
1405 "3030",
1406 "1441",
1407 "783",
1408 "6801",
1409 "20739",
1410 "8944",
1411 "9491",
1412 "22569",
1413 "5226",
1414 "6786",
1415 "1433",
1416 "8973",
1417 "1828",
1418 "9495",
1419 "9006",
1420 "6794",
1421 "8993",
1422 "5203",
1423 "16914",
1424 "6784",
1425 "9635",
1426 "22830",
1427 "20722",
1428 "9748",
1429 "6790",
1430 "9753",
1431 "9493",
1432 "9752",
1433 "9831",
1434 "9825",
1435 "9822",
1436 "5204",
1437 "5401",
1438 "22831",
1439 "6793",
1440 "9845",
1441 "17401",
1442 "9882",
1443 "9868",
1444 "20749",
1445 "9893",
1446 "9899",
1447 "9895",
1448 "9832",
1449 "9902",
1450 "9909",
1451 "22832",
1452 "9828",
1453 "9851",
1454 "9883",
1455 "9869",
1456 "17406",
1457 "17402",
1458 "9914",
1459 "20750",
1460 "9897",
1461 "9848",
1462 "3127",
1463 "107",
1464 "204",
1465 "9116",
1466 "2457",
1467 "78",
1468 "18848",
1469 "331",
1470 "403",
1471 "2098",
1472 "1752",
1473 "11278",
1474 "11288",
1475 "11284",
1476 "6461",
1477 "2344",
1478 "2345",
1479 "6463",
1480 "2346",
1481 "2352",
1482 "775",
1483 "1434",
1484 "1612",
1485 "71",
1486 "2468",
1487 "2458",
1488 "2467",
1489 "7164",
1490 "7178",
1491 "7367",
1492 "7376",
1493 "7381",
1494 "21156",
1495 "5209",
1496 "3029",
1497 "5201",
1498 "9849",
1499 "9850",
1500 "20719",
1501 "22568",
1502 "22827",
1503 "22828",
1504 "22829",
1505 "6809",
1506 "8972",
1507 "9005",
1508 "9823",
1509 "9827",
1510 "6783",
1511 "9913",
1512 "6785",
1513 "6787",
1514 "9866",
1515 "9867",
1516 "9894",
1517 "9896",
1518 "6800",
1519 "8992",
1520 "9829",
1521 "9830",
1522 "780",
1523 "769",
1524 "6749",
1525 "6750",
1526 "9755",
1527 "9754",
1528 "9908",
1529 "20745",
1530 "20742",
1531 "20747",
1532 "20748",
1533 "9746",
1534 "9745",
1535 "9880",
1536 "9881",
1537 "5391",
1538 "842",
1539 "3025",
1540 "3031",
1541 "3287",
1542 "3329",
1543 "1945",
1544 "3559",
1545 "4933",
1546 "4934",
1547 "4935",
1548 "4936",
1549 "5142",
1550 "5390",
1551 "5392",
1552 "5404",
1553 "5420",
1554 "6405",
1555 "7293",
1556 "7965",
1557 "8041",
1558 "8153",
1559 "9033",
1560 "9034",
1561 //"9036", problems with ghost state
1562 "16421",
1563 "21653",
1564 "22660",
1565 "5225",
1566 "9846",
1567 "2426",
1568 "5916",
1569 "6634",
1570 //"6718", phasing stealth, annoying for learn all case.
1571 "6719",
1572 "8822",
1573 "9591",
1574 "9590",
1575 "10032",
1576 "17746",
1577 "17747",
1578 "8203",
1579 "11392",
1580 "12495",
1581 "16380",
1582 "23452",
1583 "4079",
1584 "4996",
1585 "4997",
1586 "4998",
1587 "4999",
1588 "5000",
1589 "6348",
1590 "6349",
1591 "6481",
1592 "6482",
1593 "6483",
1594 "6484",
1595 "11362",
1596 "11410",
1597 "11409",
1598 "12510",
1599 "12509",
1600 "12885",
1601 "13142",
1602 "21463",
1603 "23460",
1604 "11421",
1605 "11416",
1606 "11418",
1607 "1851",
1608 "10059",
1609 "11423",
1610 "11417",
1611 "11422",
1612 "11419",
1613 "11424",
1614 "11420",
1615 "27",
1616 "31",
1617 "33",
1618 "34",
1619 "35",
1620 "15125",
1621 "21127",
1622 "22950",
1623 "1180",
1624 "201",
1625 "12593",
1626 "12842",
1627 "16770",
1628 "6057",
1629 "12051",
1630 "18468",
1631 "12606",
1632 "12605",
1633 "18466",
1634 "12502",
1635 "12043",
1636 "15060",
1637 "12042",
1638 "12341",
1639 "12848",
1640 "12344",
1641 "12353",
1642 "18460",
1643 "11366",
1644 "12350",
1645 "12352",
1646 "13043",
1647 "11368",
1648 "11113",
1649 "12400",
1650 "11129",
1651 "16766",
1652 "12573",
1653 "15053",
1654 "12580",
1655 "12475",
1656 "12472",
1657 "12953",
1658 "12488",
1659 "11189",
1660 "12985",
1661 "12519",
1662 "16758",
1663 "11958",
1664 "12490",
1665 "11426",
1666 "3565",
1667 "3562",
1668 "18960",
1669 "3567",
1670 "3561",
1671 "3566",
1672 "3563",
1673 "1953",
1674 "2139",
1675 "12505",
1676 "13018",
1677 "12522",
1678 "12523",
1679 "5146",
1680 "5144",
1681 "5148",
1682 "8419",
1683 "8418",
1684 "10213",
1685 "10212",
1686 "10157",
1687 "12524",
1688 "13019",
1689 "12525",
1690 "13020",
1691 "12526",
1692 "13021",
1693 "18809",
1694 "13031",
1695 "13032",
1696 "13033",
1697 "4036",
1698 "3920",
1699 "3919",
1700 "3918",
1701 "7430",
1702 "3922",
1703 "3923",
1704 "7411",
1705 "7418",
1706 "7421",
1707 "13262",
1708 "7412",
1709 "7415",
1710 "7413",
1711 "7416",
1712 "13920",
1713 "13921",
1714 "7745",
1715 "7779",
1716 "7428",
1717 "7457",
1718 "7857",
1719 "7748",
1720 "7426",
1721 "13421",
1722 "7454",
1723 "13378",
1724 "7788",
1725 "14807",
1726 "14293",
1727 "7795",
1728 "6296",
1729 "20608",
1730 "755",
1731 "444",
1732 "427",
1733 "428",
1734 "442",
1735 "447",
1736 "3578",
1737 "3581",
1738 "19027",
1739 "3580",
1740 "665",
1741 "3579",
1742 "3577",
1743 "6755",
1744 "3576",
1745 "2575",
1746 "2577",
1747 "2578",
1748 "2579",
1749 "2580",
1750 "2656",
1751 "2657",
1752 "2576",
1753 "3564",
1754 "10248",
1755 "8388",
1756 "2659",
1757 "14891",
1758 "3308",
1759 "3307",
1760 "10097",
1761 "2658",
1762 "3569",
1763 "16153",
1764 "3304",
1765 "10098",
1766 "4037",
1767 "3929",
1768 "3931",
1769 "3926",
1770 "3924",
1771 "3930",
1772 "3977",
1773 "3925",
1774 "136",
1775 "228",
1776 "5487",
1777 "43",
1778 "202",
1782 int loop = 0;
1783 while(strcmp(allSpellList[loop], "0"))
1785 uint32 spell = atol((char*)allSpellList[loop++]);
1787 if (m_session->GetPlayer()->HasSpell(spell))
1788 continue;
1790 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
1791 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
1793 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
1794 continue;
1797 m_session->GetPlayer()->learnSpell(spell,false);
1800 SendSysMessage(LANG_COMMAND_LEARN_MANY_SPELLS);
1802 return true;
1805 bool ChatHandler::HandleLearnAllGMCommand(const char* /*args*/)
1807 static const char *gmSpellList[] =
1809 "24347", // Become A Fish, No Breath Bar
1810 "35132", // Visual Boom
1811 "38488", // Attack 4000-8000 AOE
1812 "38795", // Attack 2000 AOE + Slow Down 90%
1813 "15712", // Attack 200
1814 "1852", // GM Spell Silence
1815 "31899", // Kill
1816 "31924", // Kill
1817 "29878", // Kill My Self
1818 "26644", // More Kill
1820 "28550", //Invisible 24
1821 "23452", //Invisible + Target
1825 uint16 gmSpellIter = 0;
1826 while( strcmp(gmSpellList[gmSpellIter], "0") )
1828 uint32 spell = atol((char*)gmSpellList[gmSpellIter++]);
1830 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
1831 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
1833 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
1834 continue;
1837 m_session->GetPlayer()->learnSpell(spell,false);
1840 SendSysMessage(LANG_LEARNING_GM_SKILLS);
1841 return true;
1844 bool ChatHandler::HandleLearnAllMyClassCommand(const char* /*args*/)
1846 HandleLearnAllMySpellsCommand("");
1847 HandleLearnAllMyTalentsCommand("");
1848 return true;
1851 bool ChatHandler::HandleLearnAllMySpellsCommand(const char* /*args*/)
1853 ChrClassesEntry const* clsEntry = sChrClassesStore.LookupEntry(m_session->GetPlayer()->getClass());
1854 if(!clsEntry)
1855 return true;
1856 uint32 family = clsEntry->spellfamily;
1858 for (uint32 i = 0; i < sSpellStore.GetNumRows(); ++i)
1860 SpellEntry const *spellInfo = sSpellStore.LookupEntry(i);
1861 if(!spellInfo)
1862 continue;
1864 // skip server-side/triggered spells
1865 if(spellInfo->spellLevel==0)
1866 continue;
1868 // skip wrong class/race skills
1869 if(!m_session->GetPlayer()->IsSpellFitByClassAndRace(spellInfo->Id))
1870 continue;
1872 // skip other spell families
1873 if( spellInfo->SpellFamilyName != family)
1874 continue;
1876 // skip spells with first rank learned as talent (and all talents then also)
1877 uint32 first_rank = sSpellMgr.GetFirstSpellInChain(spellInfo->Id);
1878 if(GetTalentSpellCost(first_rank) > 0 )
1879 continue;
1881 // skip broken spells
1882 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
1883 continue;
1885 m_session->GetPlayer()->learnSpell(i,false);
1888 SendSysMessage(LANG_COMMAND_LEARN_CLASS_SPELLS);
1889 return true;
1892 bool ChatHandler::HandleLearnAllMyTalentsCommand(const char* /*args*/)
1894 Player* player = m_session->GetPlayer();
1895 uint32 classMask = player->getClassMask();
1897 for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i)
1899 TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
1900 if(!talentInfo)
1901 continue;
1903 TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentInfo->TalentTab );
1904 if(!talentTabInfo)
1905 continue;
1907 if( (classMask & talentTabInfo->ClassMask) == 0 )
1908 continue;
1910 // search highest talent rank
1911 uint32 spellid = 0;
1913 for(int rank = MAX_TALENT_RANK-1; rank >= 0; --rank)
1915 if(talentInfo->RankID[rank]!=0)
1917 spellid = talentInfo->RankID[rank];
1918 break;
1922 if(!spellid) // ??? none spells in talent
1923 continue;
1925 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellid);
1926 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
1927 continue;
1929 // learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
1930 player->learnSpellHighRank(spellid);
1933 SendSysMessage(LANG_COMMAND_LEARN_CLASS_TALENTS);
1934 return true;
1937 bool ChatHandler::HandleLearnAllMyPetTalentsCommand(const char* /*args*/)
1939 Player* player = m_session->GetPlayer();
1941 Pet* pet = player->GetPet();
1942 if(!pet)
1944 SendSysMessage(LANG_NO_PET_FOUND);
1945 SetSentErrorMessage(true);
1946 return false;
1949 CreatureInfo const *ci = pet->GetCreatureInfo();
1950 if(!ci)
1952 SendSysMessage(LANG_WRONG_PET_TYPE);
1953 SetSentErrorMessage(true);
1954 return false;
1957 CreatureFamilyEntry const *pet_family = sCreatureFamilyStore.LookupEntry(ci->family);
1958 if(!pet_family)
1960 SendSysMessage(LANG_WRONG_PET_TYPE);
1961 SetSentErrorMessage(true);
1962 return false;
1965 if(pet_family->petTalentType < 0) // not hunter pet
1967 SendSysMessage(LANG_WRONG_PET_TYPE);
1968 SetSentErrorMessage(true);
1969 return false;
1972 for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i)
1974 TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
1975 if(!talentInfo)
1976 continue;
1978 TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentInfo->TalentTab );
1979 if(!talentTabInfo)
1980 continue;
1982 // prevent learn talent for different family (cheating)
1983 if(((1 << pet_family->petTalentType) & talentTabInfo->petTalentMask)==0)
1984 continue;
1986 // search highest talent rank
1987 uint32 spellid = 0;
1989 for(int rank = MAX_TALENT_RANK-1; rank >= 0; --rank)
1991 if(talentInfo->RankID[rank]!=0)
1993 spellid = talentInfo->RankID[rank];
1994 break;
1998 if(!spellid) // ??? none spells in talent
1999 continue;
2001 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellid);
2002 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
2003 continue;
2005 // learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
2006 pet->learnSpellHighRank(spellid);
2009 SendSysMessage(LANG_COMMAND_LEARN_PET_TALENTS);
2010 return true;
2013 bool ChatHandler::HandleLearnAllLangCommand(const char* /*args*/)
2015 // skipping UNIVERSAL language (0)
2016 for(int i = 1; i < LANGUAGES_COUNT; ++i)
2017 m_session->GetPlayer()->learnSpell(lang_description[i].spell_id,false);
2019 SendSysMessage(LANG_COMMAND_LEARN_ALL_LANG);
2020 return true;
2023 bool ChatHandler::HandleLearnAllDefaultCommand(const char* args)
2025 Player* target;
2026 if(!extractPlayerTarget((char*)args,&target))
2027 return false;
2029 target->learnDefaultSpells();
2030 target->learnQuestRewardedSpells();
2032 PSendSysMessage(LANG_COMMAND_LEARN_ALL_DEFAULT_AND_QUEST,GetNameLink(target).c_str());
2033 return true;
2036 bool ChatHandler::HandleLearnCommand(const char* args)
2038 Player* targetPlayer = getSelectedPlayer();
2040 if(!targetPlayer)
2042 SendSysMessage(LANG_PLAYER_NOT_FOUND);
2043 SetSentErrorMessage(true);
2044 return false;
2047 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
2048 uint32 spell = extractSpellIdFromLink((char*)args);
2049 if(!spell || !sSpellStore.LookupEntry(spell))
2050 return false;
2052 char const* allStr = strtok(NULL," ");
2053 bool allRanks = allStr ? (strncmp(allStr, "all", strlen(allStr)) == 0) : false;
2055 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
2056 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
2058 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
2059 SetSentErrorMessage(true);
2060 return false;
2063 if (!allRanks && targetPlayer->HasSpell(spell))
2065 if(targetPlayer == m_session->GetPlayer())
2066 SendSysMessage(LANG_YOU_KNOWN_SPELL);
2067 else
2068 PSendSysMessage(LANG_TARGET_KNOWN_SPELL,GetNameLink(targetPlayer).c_str());
2069 SetSentErrorMessage(true);
2070 return false;
2073 if(allRanks)
2074 targetPlayer->learnSpellHighRank(spell);
2075 else
2076 targetPlayer->learnSpell(spell,false);
2078 uint32 first_spell = sSpellMgr.GetFirstSpellInChain(spell);
2079 if(GetTalentSpellCost(first_spell))
2080 targetPlayer->SendTalentsInfoData(false);
2082 return true;
2085 bool ChatHandler::HandleAddItemCommand(const char* args)
2087 if (!*args)
2088 return false;
2090 uint32 itemId = 0;
2092 if(args[0]=='[') // [name] manual form
2094 char* citemName = strtok((char*)args, "]");
2096 if(citemName && citemName[0])
2098 std::string itemName = citemName+1;
2099 WorldDatabase.escape_string(itemName);
2100 QueryResult *result = WorldDatabase.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName.c_str());
2101 if (!result)
2103 PSendSysMessage(LANG_COMMAND_COULDNOTFIND, citemName+1);
2104 SetSentErrorMessage(true);
2105 return false;
2107 itemId = result->Fetch()->GetUInt16();
2108 delete result;
2110 else
2111 return false;
2113 else // item_id or [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r
2115 char* cId = extractKeyFromLink((char*)args,"Hitem");
2116 if(!cId)
2117 return false;
2118 itemId = atol(cId);
2121 char* ccount = strtok(NULL, " ");
2123 int32 count = 1;
2125 if (ccount)
2126 count = strtol(ccount, NULL, 10);
2128 if (count == 0)
2129 count = 1;
2131 Player* pl = m_session->GetPlayer();
2132 Player* plTarget = getSelectedPlayer();
2133 if(!plTarget)
2134 plTarget = pl;
2136 sLog.outDetail(GetMangosString(LANG_ADDITEM), itemId, count);
2138 ItemPrototype const *pProto = ObjectMgr::GetItemPrototype(itemId);
2139 if(!pProto)
2141 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, itemId);
2142 SetSentErrorMessage(true);
2143 return false;
2146 //Subtract
2147 if (count < 0)
2149 plTarget->DestroyItemCount(itemId, -count, true, false);
2150 PSendSysMessage(LANG_REMOVEITEM, itemId, -count, GetNameLink(plTarget).c_str());
2151 return true;
2154 //Adding items
2155 uint32 noSpaceForCount = 0;
2157 // check space and find places
2158 ItemPosCountVec dest;
2159 uint8 msg = plTarget->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, itemId, count, &noSpaceForCount );
2160 if( msg != EQUIP_ERR_OK ) // convert to possible store amount
2161 count -= noSpaceForCount;
2163 if( count == 0 || dest.empty()) // can't add any
2165 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount );
2166 SetSentErrorMessage(true);
2167 return false;
2170 Item* item = plTarget->StoreNewItem( dest, itemId, true, Item::GenerateItemRandomPropertyId(itemId));
2172 // remove binding (let GM give it to another player later)
2173 if(pl==plTarget)
2174 for(ItemPosCountVec::const_iterator itr = dest.begin(); itr != dest.end(); ++itr)
2175 if(Item* item1 = pl->GetItemByPos(itr->pos))
2176 item1->SetBinding( false );
2178 if(count > 0 && item)
2180 pl->SendNewItem(item,count,false,true);
2181 if(pl!=plTarget)
2182 plTarget->SendNewItem(item,count,true,false);
2185 if(noSpaceForCount > 0)
2186 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount);
2188 return true;
2191 bool ChatHandler::HandleAddItemSetCommand(const char* args)
2193 if (!*args)
2194 return false;
2196 char* cId = extractKeyFromLink((char*)args,"Hitemset"); // number or [name] Shift-click form |color|Hitemset:itemset_id|h[name]|h|r
2197 if (!cId)
2198 return false;
2200 uint32 itemsetId = atol(cId);
2202 // prevent generation all items with itemset field value '0'
2203 if (itemsetId == 0)
2205 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND,itemsetId);
2206 SetSentErrorMessage(true);
2207 return false;
2210 Player* pl = m_session->GetPlayer();
2211 Player* plTarget = getSelectedPlayer();
2212 if(!plTarget)
2213 plTarget = pl;
2215 sLog.outDetail(GetMangosString(LANG_ADDITEMSET), itemsetId);
2217 bool found = false;
2218 for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
2220 ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype>(id);
2221 if (!pProto)
2222 continue;
2224 if (pProto->ItemSet == itemsetId)
2226 found = true;
2227 ItemPosCountVec dest;
2228 uint8 msg = plTarget->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, pProto->ItemId, 1 );
2229 if (msg == EQUIP_ERR_OK)
2231 Item* item = plTarget->StoreNewItem( dest, pProto->ItemId, true);
2233 // remove binding (let GM give it to another player later)
2234 if (pl==plTarget)
2235 item->SetBinding( false );
2237 pl->SendNewItem(item,1,false,true);
2238 if (pl!=plTarget)
2239 plTarget->SendNewItem(item,1,true,false);
2241 else
2243 pl->SendEquipError( msg, NULL, NULL );
2244 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, pProto->ItemId, 1);
2249 if (!found)
2251 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND,itemsetId);
2253 SetSentErrorMessage(true);
2254 return false;
2257 return true;
2260 bool ChatHandler::HandleListItemCommand(const char* args)
2262 if(!*args)
2263 return false;
2265 char* cId = extractKeyFromLink((char*)args,"Hitem");
2266 if(!cId)
2267 return false;
2269 uint32 item_id = atol(cId);
2270 if(!item_id)
2272 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
2273 SetSentErrorMessage(true);
2274 return false;
2277 ItemPrototype const* itemProto = ObjectMgr::GetItemPrototype(item_id);
2278 if(!itemProto)
2280 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
2281 SetSentErrorMessage(true);
2282 return false;
2285 char* c_count = strtok(NULL, " ");
2286 int count = c_count ? atol(c_count) : 10;
2288 if(count < 0)
2289 return false;
2291 QueryResult *result;
2293 // inventory case
2294 uint32 inv_count = 0;
2295 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM character_inventory WHERE item_template='%u'",item_id);
2296 if(result)
2298 inv_count = (*result)[0].GetUInt32();
2299 delete result;
2302 result=CharacterDatabase.PQuery(
2303 // 0 1 2 3 4 5
2304 "SELECT ci.item, cibag.slot AS bag, ci.slot, ci.guid, characters.account,characters.name "
2305 "FROM character_inventory AS ci LEFT JOIN character_inventory AS cibag ON (cibag.item=ci.bag),characters "
2306 "WHERE ci.item_template='%u' AND ci.guid = characters.guid LIMIT %u ",
2307 item_id,uint32(count));
2309 if(result)
2313 Field *fields = result->Fetch();
2314 uint32 item_guid = fields[0].GetUInt32();
2315 uint32 item_bag = fields[1].GetUInt32();
2316 uint32 item_slot = fields[2].GetUInt32();
2317 uint32 owner_guid = fields[3].GetUInt32();
2318 uint32 owner_acc = fields[4].GetUInt32();
2319 std::string owner_name = fields[5].GetCppString();
2321 char const* item_pos = 0;
2322 if(Player::IsEquipmentPos(item_bag,item_slot))
2323 item_pos = "[equipped]";
2324 else if(Player::IsInventoryPos(item_bag,item_slot))
2325 item_pos = "[in inventory]";
2326 else if(Player::IsBankPos(item_bag,item_slot))
2327 item_pos = "[in bank]";
2328 else
2329 item_pos = "";
2331 PSendSysMessage(LANG_ITEMLIST_SLOT,
2332 item_guid,owner_name.c_str(),owner_guid,owner_acc,item_pos);
2333 } while (result->NextRow());
2335 int64 res_count = result->GetRowCount();
2337 delete result;
2339 if(count > res_count)
2340 count-=res_count;
2341 else if(count)
2342 count = 0;
2345 // mail case
2346 uint32 mail_count = 0;
2347 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM mail_items WHERE item_template='%u'", item_id);
2348 if(result)
2350 mail_count = (*result)[0].GetUInt32();
2351 delete result;
2354 if(count > 0)
2356 result=CharacterDatabase.PQuery(
2357 // 0 1 2 3 4 5 6
2358 "SELECT mail_items.item_guid, mail.sender, mail.receiver, char_s.account, char_s.name, char_r.account, char_r.name "
2359 "FROM mail,mail_items,characters as char_s,characters as char_r "
2360 "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",
2361 item_id,uint32(count));
2363 else
2364 result = NULL;
2366 if(result)
2370 Field *fields = result->Fetch();
2371 uint32 item_guid = fields[0].GetUInt32();
2372 uint32 item_s = fields[1].GetUInt32();
2373 uint32 item_r = fields[2].GetUInt32();
2374 uint32 item_s_acc = fields[3].GetUInt32();
2375 std::string item_s_name = fields[4].GetCppString();
2376 uint32 item_r_acc = fields[5].GetUInt32();
2377 std::string item_r_name = fields[6].GetCppString();
2379 char const* item_pos = "[in mail]";
2381 PSendSysMessage(LANG_ITEMLIST_MAIL,
2382 item_guid,item_s_name.c_str(),item_s,item_s_acc,item_r_name.c_str(),item_r,item_r_acc,item_pos);
2383 } while (result->NextRow());
2385 int64 res_count = result->GetRowCount();
2387 delete result;
2389 if(count > res_count)
2390 count-=res_count;
2391 else if(count)
2392 count = 0;
2395 // auction case
2396 uint32 auc_count = 0;
2397 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM auctionhouse WHERE item_template='%u'",item_id);
2398 if(result)
2400 auc_count = (*result)[0].GetUInt32();
2401 delete result;
2404 if(count > 0)
2406 result=CharacterDatabase.PQuery(
2407 // 0 1 2 3
2408 "SELECT auctionhouse.itemguid, auctionhouse.itemowner, characters.account, characters.name "
2409 "FROM auctionhouse,characters WHERE auctionhouse.item_template='%u' AND characters.guid = auctionhouse.itemowner LIMIT %u",
2410 item_id,uint32(count));
2412 else
2413 result = NULL;
2415 if(result)
2419 Field *fields = result->Fetch();
2420 uint32 item_guid = fields[0].GetUInt32();
2421 uint32 owner = fields[1].GetUInt32();
2422 uint32 owner_acc = fields[2].GetUInt32();
2423 std::string owner_name = fields[3].GetCppString();
2425 char const* item_pos = "[in auction]";
2427 PSendSysMessage(LANG_ITEMLIST_AUCTION, item_guid, owner_name.c_str(), owner, owner_acc,item_pos);
2428 } while (result->NextRow());
2430 delete result;
2433 // guild bank case
2434 uint32 guild_count = 0;
2435 result=CharacterDatabase.PQuery("SELECT COUNT(item_entry) FROM guild_bank_item WHERE item_entry='%u'",item_id);
2436 if(result)
2438 guild_count = (*result)[0].GetUInt32();
2439 delete result;
2442 result=CharacterDatabase.PQuery(
2443 // 0 1 2
2444 "SELECT gi.item_guid, gi.guildid, guild.name "
2445 "FROM guild_bank_item AS gi, guild WHERE gi.item_entry='%u' AND gi.guildid = guild.guildid LIMIT %u ",
2446 item_id,uint32(count));
2448 if(result)
2452 Field *fields = result->Fetch();
2453 uint32 item_guid = fields[0].GetUInt32();
2454 uint32 guild_guid = fields[1].GetUInt32();
2455 std::string guild_name = fields[2].GetCppString();
2457 char const* item_pos = "[in guild bank]";
2459 PSendSysMessage(LANG_ITEMLIST_GUILD,item_guid,guild_name.c_str(),guild_guid,item_pos);
2460 } while (result->NextRow());
2462 int64 res_count = result->GetRowCount();
2464 delete result;
2466 if(count > res_count)
2467 count-=res_count;
2468 else if(count)
2469 count = 0;
2472 if(inv_count+mail_count+auc_count+guild_count == 0)
2474 SendSysMessage(LANG_COMMAND_NOITEMFOUND);
2475 SetSentErrorMessage(true);
2476 return false;
2479 PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE,item_id,inv_count+mail_count+auc_count+guild_count,inv_count,mail_count,auc_count,guild_count);
2481 return true;
2484 bool ChatHandler::HandleListObjectCommand(const char* args)
2486 if(!*args)
2487 return false;
2489 // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2490 char* cId = extractKeyFromLink((char*)args,"Hgameobject_entry");
2491 if(!cId)
2492 return false;
2494 uint32 go_id = atol(cId);
2495 if(!go_id)
2497 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, go_id);
2498 SetSentErrorMessage(true);
2499 return false;
2502 GameObjectInfo const * gInfo = ObjectMgr::GetGameObjectInfo(go_id);
2503 if(!gInfo)
2505 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, go_id);
2506 SetSentErrorMessage(true);
2507 return false;
2510 char* c_count = strtok(NULL, " ");
2511 int count = c_count ? atol(c_count) : 10;
2513 if(count < 0)
2514 return false;
2516 QueryResult *result;
2518 uint32 obj_count = 0;
2519 result=WorldDatabase.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'",go_id);
2520 if(result)
2522 obj_count = (*result)[0].GetUInt32();
2523 delete result;
2526 if(m_session)
2528 Player* pl = m_session->GetPlayer();
2529 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",
2530 pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(),go_id,uint32(count));
2532 else
2533 result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map FROM gameobject WHERE id = '%u' LIMIT %u",
2534 go_id,uint32(count));
2536 if (result)
2540 Field *fields = result->Fetch();
2541 uint32 guid = fields[0].GetUInt32();
2542 float x = fields[1].GetFloat();
2543 float y = fields[2].GetFloat();
2544 float z = fields[3].GetFloat();
2545 int mapid = fields[4].GetUInt16();
2547 if (m_session)
2548 PSendSysMessage(LANG_GO_LIST_CHAT, guid, guid, gInfo->name, x, y, z, mapid);
2549 else
2550 PSendSysMessage(LANG_GO_LIST_CONSOLE, guid, gInfo->name, x, y, z, mapid);
2551 } while (result->NextRow());
2553 delete result;
2556 PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE,go_id,obj_count);
2557 return true;
2560 bool ChatHandler::HandleListCreatureCommand(const char* args)
2562 if(!*args)
2563 return false;
2565 // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
2566 char* cId = extractKeyFromLink((char*)args,"Hcreature_entry");
2567 if(!cId)
2568 return false;
2570 uint32 cr_id = atol(cId);
2571 if(!cr_id)
2573 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, cr_id);
2574 SetSentErrorMessage(true);
2575 return false;
2578 CreatureInfo const* cInfo = ObjectMgr::GetCreatureTemplate(cr_id);
2579 if(!cInfo)
2581 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, cr_id);
2582 SetSentErrorMessage(true);
2583 return false;
2586 char* c_count = strtok(NULL, " ");
2587 int count = c_count ? atol(c_count) : 10;
2589 if(count < 0)
2590 return false;
2592 QueryResult *result;
2594 uint32 cr_count = 0;
2595 result=WorldDatabase.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'",cr_id);
2596 if(result)
2598 cr_count = (*result)[0].GetUInt32();
2599 delete result;
2602 if(m_session)
2604 Player* pl = m_session->GetPlayer();
2605 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",
2606 pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(), cr_id,uint32(count));
2608 else
2609 result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '%u' LIMIT %u",
2610 cr_id,uint32(count));
2612 if (result)
2616 Field *fields = result->Fetch();
2617 uint32 guid = fields[0].GetUInt32();
2618 float x = fields[1].GetFloat();
2619 float y = fields[2].GetFloat();
2620 float z = fields[3].GetFloat();
2621 int mapid = fields[4].GetUInt16();
2623 if (m_session)
2624 PSendSysMessage(LANG_CREATURE_LIST_CHAT, guid, guid, cInfo->Name, x, y, z, mapid);
2625 else
2626 PSendSysMessage(LANG_CREATURE_LIST_CONSOLE, guid, cInfo->Name, x, y, z, mapid);
2627 } while (result->NextRow());
2629 delete result;
2632 PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE,cr_id,cr_count);
2633 return true;
2636 bool ChatHandler::HandleLookupItemCommand(const char* args)
2638 if(!*args)
2639 return false;
2641 std::string namepart = args;
2642 std::wstring wnamepart;
2644 // converting string that we try to find to lower case
2645 if(!Utf8toWStr(namepart,wnamepart))
2646 return false;
2648 wstrToLower(wnamepart);
2650 uint32 counter = 0;
2652 // Search in `item_template`
2653 for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
2655 ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype >(id);
2656 if(!pProto)
2657 continue;
2659 int loc_idx = GetSessionDbLocaleIndex();
2660 if ( loc_idx >= 0 )
2662 ItemLocale const *il = sObjectMgr.GetItemLocale(pProto->ItemId);
2663 if (il)
2665 if (il->Name.size() > loc_idx && !il->Name[loc_idx].empty())
2667 std::string name = il->Name[loc_idx];
2669 if (Utf8FitTo(name, wnamepart))
2671 if (m_session)
2672 PSendSysMessage(LANG_ITEM_LIST_CHAT, id, id, name.c_str());
2673 else
2674 PSendSysMessage(LANG_ITEM_LIST_CONSOLE, id, name.c_str());
2675 ++counter;
2676 continue;
2682 std::string name = pProto->Name1;
2683 if(name.empty())
2684 continue;
2686 if (Utf8FitTo(name, wnamepart))
2688 if (m_session)
2689 PSendSysMessage(LANG_ITEM_LIST_CHAT, id, id, name.c_str());
2690 else
2691 PSendSysMessage(LANG_ITEM_LIST_CONSOLE, id, name.c_str());
2692 ++counter;
2696 if (counter==0)
2697 SendSysMessage(LANG_COMMAND_NOITEMFOUND);
2699 return true;
2702 bool ChatHandler::HandleLookupItemSetCommand(const char* args)
2704 if(!*args)
2705 return false;
2707 std::string namepart = args;
2708 std::wstring wnamepart;
2710 if(!Utf8toWStr(namepart,wnamepart))
2711 return false;
2713 // converting string that we try to find to lower case
2714 wstrToLower( wnamepart );
2716 uint32 counter = 0; // Counter for figure out that we found smth.
2718 // Search in ItemSet.dbc
2719 for (uint32 id = 0; id < sItemSetStore.GetNumRows(); id++)
2721 ItemSetEntry const *set = sItemSetStore.LookupEntry(id);
2722 if(set)
2724 int loc = GetSessionDbcLocale();
2725 std::string name = set->name[loc];
2726 if(name.empty())
2727 continue;
2729 if (!Utf8FitTo(name, wnamepart))
2731 loc = 0;
2732 for(; loc < MAX_LOCALE; ++loc)
2734 if(loc==GetSessionDbcLocale())
2735 continue;
2737 name = set->name[loc];
2738 if(name.empty())
2739 continue;
2741 if (Utf8FitTo(name, wnamepart))
2742 break;
2746 if(loc < MAX_LOCALE)
2748 // send item set in "id - [namedlink locale]" format
2749 if (m_session)
2750 PSendSysMessage(LANG_ITEMSET_LIST_CHAT,id,id,name.c_str(),localeNames[loc]);
2751 else
2752 PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE,id,name.c_str(),localeNames[loc]);
2753 ++counter;
2757 if (counter == 0) // if counter == 0 then we found nth
2758 SendSysMessage(LANG_COMMAND_NOITEMSETFOUND);
2759 return true;
2762 bool ChatHandler::HandleLookupSkillCommand(const char* args)
2764 if(!*args)
2765 return false;
2767 // can be NULL in console call
2768 Player* target = getSelectedPlayer();
2770 std::string namepart = args;
2771 std::wstring wnamepart;
2773 if(!Utf8toWStr(namepart,wnamepart))
2774 return false;
2776 // converting string that we try to find to lower case
2777 wstrToLower( wnamepart );
2779 uint32 counter = 0; // Counter for figure out that we found smth.
2781 // Search in SkillLine.dbc
2782 for (uint32 id = 0; id < sSkillLineStore.GetNumRows(); id++)
2784 SkillLineEntry const *skillInfo = sSkillLineStore.LookupEntry(id);
2785 if(skillInfo)
2787 int loc = GetSessionDbcLocale();
2788 std::string name = skillInfo->name[loc];
2789 if(name.empty())
2790 continue;
2792 if (!Utf8FitTo(name, wnamepart))
2794 loc = 0;
2795 for(; loc < MAX_LOCALE; ++loc)
2797 if(loc==GetSessionDbcLocale())
2798 continue;
2800 name = skillInfo->name[loc];
2801 if(name.empty())
2802 continue;
2804 if (Utf8FitTo(name, wnamepart))
2805 break;
2809 if(loc < MAX_LOCALE)
2811 char valStr[50] = "";
2812 char const* knownStr = "";
2813 if(target && target->HasSkill(id))
2815 knownStr = GetMangosString(LANG_KNOWN);
2816 uint32 curValue = target->GetPureSkillValue(id);
2817 uint32 maxValue = target->GetPureMaxSkillValue(id);
2818 uint32 permValue = target->GetSkillPermBonusValue(id);
2819 uint32 tempValue = target->GetSkillTempBonusValue(id);
2821 char const* valFormat = GetMangosString(LANG_SKILL_VALUES);
2822 snprintf(valStr,50,valFormat,curValue,maxValue,permValue,tempValue);
2825 // send skill in "id - [namedlink locale]" format
2826 if (m_session)
2827 PSendSysMessage(LANG_SKILL_LIST_CHAT,id,id,name.c_str(),localeNames[loc],knownStr,valStr);
2828 else
2829 PSendSysMessage(LANG_SKILL_LIST_CONSOLE,id,name.c_str(),localeNames[loc],knownStr,valStr);
2831 ++counter;
2835 if (counter == 0) // if counter == 0 then we found nth
2836 SendSysMessage(LANG_COMMAND_NOSKILLFOUND);
2837 return true;
2840 bool ChatHandler::HandleLookupSpellCommand(const char* args)
2842 if(!*args)
2843 return false;
2845 // can be NULL at console call
2846 Player* target = getSelectedPlayer();
2848 std::string namepart = args;
2849 std::wstring wnamepart;
2851 if(!Utf8toWStr(namepart,wnamepart))
2852 return false;
2854 // converting string that we try to find to lower case
2855 wstrToLower( wnamepart );
2857 uint32 counter = 0; // Counter for figure out that we found smth.
2859 // Search in Spell.dbc
2860 for (uint32 id = 0; id < sSpellStore.GetNumRows(); id++)
2862 SpellEntry const *spellInfo = sSpellStore.LookupEntry(id);
2863 if(spellInfo)
2865 int loc = GetSessionDbcLocale();
2866 std::string name = spellInfo->SpellName[loc];
2867 if(name.empty())
2868 continue;
2870 if (!Utf8FitTo(name, wnamepart))
2872 loc = 0;
2873 for(; loc < MAX_LOCALE; ++loc)
2875 if(loc==GetSessionDbcLocale())
2876 continue;
2878 name = spellInfo->SpellName[loc];
2879 if(name.empty())
2880 continue;
2882 if (Utf8FitTo(name, wnamepart))
2883 break;
2887 if(loc < MAX_LOCALE)
2889 bool known = target && target->HasSpell(id);
2890 bool learn = (spellInfo->Effect[0] == SPELL_EFFECT_LEARN_SPELL);
2892 uint32 talentCost = GetTalentSpellCost(id);
2894 bool talent = (talentCost > 0);
2895 bool passive = IsPassiveSpell(id);
2896 bool active = target && target->HasAura(id);
2898 // unit32 used to prevent interpreting uint8 as char at output
2899 // find rank of learned spell for learning spell, or talent rank
2900 uint32 rank = talentCost ? talentCost : sSpellMgr.GetSpellRank(learn ? spellInfo->EffectTriggerSpell[0] : id);
2902 // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
2903 std::ostringstream ss;
2904 if (m_session)
2905 ss << id << " - |cffffffff|Hspell:" << id << "|h[" << name;
2906 else
2907 ss << id << " - " << name;
2909 // include rank in link name
2910 if(rank)
2911 ss << GetMangosString(LANG_SPELL_RANK) << rank;
2913 if (m_session)
2914 ss << " " << localeNames[loc] << "]|h|r";
2915 else
2916 ss << " " << localeNames[loc];
2918 if(talent)
2919 ss << GetMangosString(LANG_TALENT);
2920 if(passive)
2921 ss << GetMangosString(LANG_PASSIVE);
2922 if(learn)
2923 ss << GetMangosString(LANG_LEARN);
2924 if(known)
2925 ss << GetMangosString(LANG_KNOWN);
2926 if(active)
2927 ss << GetMangosString(LANG_ACTIVE);
2929 SendSysMessage(ss.str().c_str());
2931 ++counter;
2935 if (counter == 0) // if counter == 0 then we found nth
2936 SendSysMessage(LANG_COMMAND_NOSPELLFOUND);
2937 return true;
2940 bool ChatHandler::HandleLookupQuestCommand(const char* args)
2942 if(!*args)
2943 return false;
2945 // can be NULL at console call
2946 Player* target = getSelectedPlayer();
2948 std::string namepart = args;
2949 std::wstring wnamepart;
2951 // converting string that we try to find to lower case
2952 if(!Utf8toWStr(namepart,wnamepart))
2953 return false;
2955 wstrToLower(wnamepart);
2957 uint32 counter = 0 ;
2959 ObjectMgr::QuestMap const& qTemplates = sObjectMgr.GetQuestTemplates();
2960 for (ObjectMgr::QuestMap::const_iterator iter = qTemplates.begin(); iter != qTemplates.end(); ++iter)
2962 Quest * qinfo = iter->second;
2964 int loc_idx = GetSessionDbLocaleIndex();
2965 if ( loc_idx >= 0 )
2967 QuestLocale const *il = sObjectMgr.GetQuestLocale(qinfo->GetQuestId());
2968 if (il)
2970 if (il->Title.size() > loc_idx && !il->Title[loc_idx].empty())
2972 std::string title = il->Title[loc_idx];
2974 if (Utf8FitTo(title, wnamepart))
2976 char const* statusStr = "";
2978 if(target)
2980 QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId());
2982 if(status == QUEST_STATUS_COMPLETE)
2984 if(target->GetQuestRewardStatus(qinfo->GetQuestId()))
2985 statusStr = GetMangosString(LANG_COMMAND_QUEST_REWARDED);
2986 else
2987 statusStr = GetMangosString(LANG_COMMAND_QUEST_COMPLETE);
2989 else if(status == QUEST_STATUS_INCOMPLETE)
2990 statusStr = GetMangosString(LANG_COMMAND_QUEST_ACTIVE);
2993 if (m_session)
2994 PSendSysMessage(LANG_QUEST_LIST_CHAT,qinfo->GetQuestId(),qinfo->GetQuestId(),qinfo->GetQuestLevel(),title.c_str(),statusStr);
2995 else
2996 PSendSysMessage(LANG_QUEST_LIST_CONSOLE,qinfo->GetQuestId(),title.c_str(),statusStr);
2997 ++counter;
2998 continue;
3004 std::string title = qinfo->GetTitle();
3005 if(title.empty())
3006 continue;
3008 if (Utf8FitTo(title, wnamepart))
3010 char const* statusStr = "";
3012 if(target)
3014 QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId());
3016 if(status == QUEST_STATUS_COMPLETE)
3018 if(target->GetQuestRewardStatus(qinfo->GetQuestId()))
3019 statusStr = GetMangosString(LANG_COMMAND_QUEST_REWARDED);
3020 else
3021 statusStr = GetMangosString(LANG_COMMAND_QUEST_COMPLETE);
3023 else if(status == QUEST_STATUS_INCOMPLETE)
3024 statusStr = GetMangosString(LANG_COMMAND_QUEST_ACTIVE);
3027 if (m_session)
3028 PSendSysMessage(LANG_QUEST_LIST_CHAT,qinfo->GetQuestId(),qinfo->GetQuestId(),qinfo->GetQuestLevel(),title.c_str(),statusStr);
3029 else
3030 PSendSysMessage(LANG_QUEST_LIST_CONSOLE,qinfo->GetQuestId(),title.c_str(),statusStr);
3032 ++counter;
3036 if (counter==0)
3037 SendSysMessage(LANG_COMMAND_NOQUESTFOUND);
3039 return true;
3042 bool ChatHandler::HandleLookupCreatureCommand(const char* args)
3044 if (!*args)
3045 return false;
3047 std::string namepart = args;
3048 std::wstring wnamepart;
3050 // converting string that we try to find to lower case
3051 if (!Utf8toWStr (namepart,wnamepart))
3052 return false;
3054 wstrToLower (wnamepart);
3056 uint32 counter = 0;
3058 for (uint32 id = 0; id< sCreatureStorage.MaxEntry; ++id)
3060 CreatureInfo const* cInfo = sCreatureStorage.LookupEntry<CreatureInfo> (id);
3061 if(!cInfo)
3062 continue;
3064 int loc_idx = GetSessionDbLocaleIndex();
3065 if (loc_idx >= 0)
3067 CreatureLocale const *cl = sObjectMgr.GetCreatureLocale (id);
3068 if (cl)
3070 if (cl->Name.size() > loc_idx && !cl->Name[loc_idx].empty ())
3072 std::string name = cl->Name[loc_idx];
3074 if (Utf8FitTo (name, wnamepart))
3076 if (m_session)
3077 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str ());
3078 else
3079 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE, id, name.c_str ());
3080 ++counter;
3081 continue;
3087 std::string name = cInfo->Name;
3088 if (name.empty ())
3089 continue;
3091 if (Utf8FitTo(name, wnamepart))
3093 if (m_session)
3094 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str ());
3095 else
3096 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE, id, name.c_str ());
3097 ++counter;
3101 if (counter==0)
3102 SendSysMessage (LANG_COMMAND_NOCREATUREFOUND);
3104 return true;
3107 bool ChatHandler::HandleLookupObjectCommand(const char* args)
3109 if(!*args)
3110 return false;
3112 std::string namepart = args;
3113 std::wstring wnamepart;
3115 // converting string that we try to find to lower case
3116 if(!Utf8toWStr(namepart,wnamepart))
3117 return false;
3119 wstrToLower(wnamepart);
3121 uint32 counter = 0;
3123 for (uint32 id = 0; id< sGOStorage.MaxEntry; id++ )
3125 GameObjectInfo const* gInfo = sGOStorage.LookupEntry<GameObjectInfo>(id);
3126 if(!gInfo)
3127 continue;
3129 int loc_idx = GetSessionDbLocaleIndex();
3130 if ( loc_idx >= 0 )
3132 GameObjectLocale const *gl = sObjectMgr.GetGameObjectLocale(id);
3133 if (gl)
3135 if (gl->Name.size() > loc_idx && !gl->Name[loc_idx].empty())
3137 std::string name = gl->Name[loc_idx];
3139 if (Utf8FitTo(name, wnamepart))
3141 if (m_session)
3142 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, id, id, name.c_str());
3143 else
3144 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, id, name.c_str());
3145 ++counter;
3146 continue;
3152 std::string name = gInfo->name;
3153 if(name.empty())
3154 continue;
3156 if(Utf8FitTo(name, wnamepart))
3158 if (m_session)
3159 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, id, id, name.c_str());
3160 else
3161 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, id, name.c_str());
3162 ++counter;
3166 if(counter==0)
3167 SendSysMessage(LANG_COMMAND_NOGAMEOBJECTFOUND);
3169 return true;
3172 bool ChatHandler::HandleLookupTaxiNodeCommand(const char * args)
3174 if(!*args)
3175 return false;
3177 std::string namepart = args;
3178 std::wstring wnamepart;
3180 if(!Utf8toWStr(namepart,wnamepart))
3181 return false;
3183 // converting string that we try to find to lower case
3184 wstrToLower( wnamepart );
3186 uint32 counter = 0; // Counter for figure out that we found smth.
3188 // Search in TaxiNodes.dbc
3189 for (uint32 id = 0; id < sTaxiNodesStore.GetNumRows(); id++)
3191 TaxiNodesEntry const *nodeEntry = sTaxiNodesStore.LookupEntry(id);
3192 if(nodeEntry)
3194 int loc = GetSessionDbcLocale();
3195 std::string name = nodeEntry->name[loc];
3196 if(name.empty())
3197 continue;
3199 if (!Utf8FitTo(name, wnamepart))
3201 loc = 0;
3202 for(; loc < MAX_LOCALE; ++loc)
3204 if(loc==GetSessionDbcLocale())
3205 continue;
3207 name = nodeEntry->name[loc];
3208 if(name.empty())
3209 continue;
3211 if (Utf8FitTo(name, wnamepart))
3212 break;
3216 if(loc < MAX_LOCALE)
3218 // send taxinode in "id - [name] (Map:m X:x Y:y Z:z)" format
3219 if (m_session)
3220 PSendSysMessage (LANG_TAXINODE_ENTRY_LIST_CHAT, id, id, name.c_str(),localeNames[loc],
3221 nodeEntry->map_id,nodeEntry->x,nodeEntry->y,nodeEntry->z);
3222 else
3223 PSendSysMessage (LANG_TAXINODE_ENTRY_LIST_CONSOLE, id, name.c_str(), localeNames[loc],
3224 nodeEntry->map_id,nodeEntry->x,nodeEntry->y,nodeEntry->z);
3225 ++counter;
3229 if (counter == 0) // if counter == 0 then we found nth
3230 SendSysMessage(LANG_COMMAND_NOTAXINODEFOUND);
3231 return true;
3234 /** \brief GM command level 3 - Create a guild.
3236 * This command allows a GM (level 3) to create a guild.
3238 * The "args" parameter contains the name of the guild leader
3239 * and then the name of the guild.
3242 bool ChatHandler::HandleGuildCreateCommand(const char* args)
3244 if(!*args)
3245 return false;
3247 // if not guild name only (in "") then player name
3248 Player* target;
3249 if(!extractPlayerTarget(*args!='"' ? (char*)args : NULL, &target))
3250 return false;
3252 char* tailStr = *args!='"' ? strtok(NULL, "") : (char*)args;
3253 if(!tailStr)
3254 return false;
3256 char* guildStr = extractQuotedArg(tailStr);
3257 if(!guildStr)
3258 return false;
3260 std::string guildname = guildStr;
3262 if (target->GetGuildId())
3264 SendSysMessage (LANG_PLAYER_IN_GUILD);
3265 return true;
3268 Guild *guild = new Guild;
3269 if (!guild->Create (target,guildname))
3271 delete guild;
3272 SendSysMessage (LANG_GUILD_NOT_CREATED);
3273 SetSentErrorMessage (true);
3274 return false;
3277 sObjectMgr.AddGuild (guild);
3278 return true;
3281 bool ChatHandler::HandleGuildInviteCommand(const char *args)
3283 if(!*args)
3284 return false;
3286 // if not guild name only (in "") then player name
3287 uint64 target_guid;
3288 if(!extractPlayerTarget(*args!='"' ? (char*)args : NULL, NULL, &target_guid))
3289 return false;
3291 char* tailStr = *args!='"' ? strtok(NULL, "") : (char*)args;
3292 if(!tailStr)
3293 return false;
3295 char* guildStr = extractQuotedArg(tailStr);
3296 if(!guildStr)
3297 return false;
3299 std::string glName = guildStr;
3300 Guild* targetGuild = sObjectMgr.GetGuildByName (glName);
3301 if (!targetGuild)
3302 return false;
3304 // player's guild membership checked in AddMember before add
3305 if (!targetGuild->AddMember (target_guid,targetGuild->GetLowestRank ()))
3306 return false;
3308 return true;
3311 bool ChatHandler::HandleGuildUninviteCommand(const char *args)
3313 Player* target;
3314 uint64 target_guid;
3315 if(!extractPlayerTarget((char*)args,&target,&target_guid))
3316 return false;
3318 uint32 glId = target ? target->GetGuildId () : Player::GetGuildIdFromDB (target_guid);
3319 if (!glId)
3320 return false;
3322 Guild* targetGuild = sObjectMgr.GetGuildById (glId);
3323 if (!targetGuild)
3324 return false;
3326 targetGuild->DelMember (target_guid);
3327 return true;
3330 bool ChatHandler::HandleGuildRankCommand(const char *args)
3332 char* nameStr;
3333 char* rankStr;
3334 extractOptFirstArg((char*)args,&nameStr,&rankStr);
3335 if(!rankStr)
3336 return false;
3338 Player* target;
3339 uint64 target_guid;
3340 std::string target_name;
3341 if(!extractPlayerTarget(nameStr,&target,&target_guid,&target_name))
3342 return false;
3344 uint32 glId = target ? target->GetGuildId () : Player::GetGuildIdFromDB (target_guid);
3345 if (!glId)
3346 return false;
3348 Guild* targetGuild = sObjectMgr.GetGuildById (glId);
3349 if (!targetGuild)
3350 return false;
3352 uint32 newrank = uint32 (atoi (rankStr));
3353 if (newrank > targetGuild->GetLowestRank ())
3354 return false;
3356 targetGuild->ChangeRank (target_guid,newrank);
3357 return true;
3360 bool ChatHandler::HandleGuildDeleteCommand(const char* args)
3362 if (!*args)
3363 return false;
3365 char* guildStr = extractQuotedArg((char*)args);
3366 if(!guildStr)
3367 return false;
3369 std::string gld = guildStr;
3371 Guild* targetGuild = sObjectMgr.GetGuildByName (gld);
3372 if (!targetGuild)
3373 return false;
3375 targetGuild->Disband ();
3377 return true;
3380 bool ChatHandler::HandleGetDistanceCommand(const char* args)
3382 WorldObject* obj = NULL;
3384 if (*args)
3386 uint64 guid = extractGuidFromLink((char*)args);
3387 if(guid)
3388 obj = (WorldObject*)ObjectAccessor::GetObjectByTypeMask(*m_session->GetPlayer(),guid,TYPEMASK_UNIT|TYPEMASK_GAMEOBJECT);
3390 if(!obj)
3392 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3393 SetSentErrorMessage(true);
3394 return false;
3397 else
3399 obj = getSelectedUnit();
3401 if(!obj)
3403 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3404 SetSentErrorMessage(true);
3405 return false;
3409 PSendSysMessage(LANG_DISTANCE, m_session->GetPlayer()->GetDistance(obj),m_session->GetPlayer()->GetDistance2d(obj));
3411 return true;
3414 bool ChatHandler::HandleDieCommand(const char* /*args*/)
3416 Unit* target = getSelectedUnit();
3418 if(!target || !m_session->GetPlayer()->GetSelection())
3420 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3421 SetSentErrorMessage(true);
3422 return false;
3425 if(target->GetTypeId()==TYPEID_PLAYER)
3427 if(HasLowerSecurity((Player*)target,0,false))
3428 return false;
3431 if( target->isAlive() )
3433 m_session->GetPlayer()->DealDamage(target, target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
3436 return true;
3439 bool ChatHandler::HandleDamageCommand(const char * args)
3441 if (!*args)
3442 return false;
3444 Unit* target = getSelectedUnit();
3446 if (!target || !m_session->GetPlayer()->GetSelection())
3448 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3449 SetSentErrorMessage(true);
3450 return false;
3453 if (!target->isAlive())
3454 return true;
3456 char* damageStr = strtok((char*)args, " ");
3457 if (!damageStr)
3458 return false;
3460 int32 damage_int = atoi((char*)damageStr);
3461 if(damage_int <=0)
3462 return true;
3464 uint32 damage = damage_int;
3466 char* schoolStr = strtok((char*)NULL, " ");
3468 // flat melee damage without resistence/etc reduction
3469 if (!schoolStr)
3471 m_session->GetPlayer()->DealDamage(target, damage, NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
3472 if (target != m_session->GetPlayer())
3473 m_session->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2, target, 1, SPELL_SCHOOL_MASK_NORMAL, damage, 0, 0, VICTIMSTATE_NORMAL, 0);
3474 return true;
3477 uint32 school = schoolStr ? atoi((char*)schoolStr) : SPELL_SCHOOL_NORMAL;
3478 if(school >= MAX_SPELL_SCHOOL)
3479 return false;
3481 SpellSchoolMask schoolmask = SpellSchoolMask(1 << school);
3483 if ( schoolmask & SPELL_SCHOOL_MASK_NORMAL )
3484 damage = m_session->GetPlayer()->CalcArmorReducedDamage(target, damage);
3486 char* spellStr = strtok((char*)NULL, " ");
3488 // melee damage by specific school
3489 if (!spellStr)
3491 uint32 absorb = 0;
3492 uint32 resist = 0;
3494 m_session->GetPlayer()->CalcAbsorbResist(target,schoolmask, SPELL_DIRECT_DAMAGE, damage, &absorb, &resist);
3496 if (damage <= absorb + resist)
3497 return true;
3499 damage -= absorb + resist;
3501 m_session->GetPlayer()->DealDamageMods(target,damage,&absorb);
3502 m_session->GetPlayer()->DealDamage(target, damage, NULL, DIRECT_DAMAGE, schoolmask, NULL, false);
3503 m_session->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2, target, 1, schoolmask, damage, absorb, resist, VICTIMSTATE_NORMAL, 0);
3504 return true;
3507 // non-melee damage
3509 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3510 uint32 spellid = extractSpellIdFromLink((char*)args);
3511 if (!spellid || !sSpellStore.LookupEntry(spellid))
3512 return false;
3514 m_session->GetPlayer()->SpellNonMeleeDamageLog(target, spellid, damage);
3515 return true;
3518 bool ChatHandler::HandleModifyArenaCommand(const char * args)
3520 if (!*args)
3521 return false;
3523 Player *target = getSelectedPlayer();
3524 if(!target)
3526 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3527 SetSentErrorMessage(true);
3528 return false;
3531 int32 amount = (uint32)atoi(args);
3533 target->ModifyArenaPoints(amount);
3535 PSendSysMessage(LANG_COMMAND_MODIFY_ARENA, GetNameLink(target).c_str(), target->GetArenaPoints());
3537 return true;
3540 bool ChatHandler::HandleReviveCommand(const char* args)
3542 Player* target;
3543 uint64 target_guid;
3544 if(!extractPlayerTarget((char*)args,&target,&target_guid))
3545 return false;
3547 if (target)
3549 target->ResurrectPlayer(0.5f);
3550 target->SpawnCorpseBones();
3552 else
3553 // will resurrected at login without corpse
3554 sObjectAccessor.ConvertCorpseForPlayer(target_guid);
3556 return true;
3559 bool ChatHandler::HandleAuraCommand(const char* args)
3561 Unit *target = getSelectedUnit();
3562 if(!target)
3564 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3565 SetSentErrorMessage(true);
3566 return false;
3569 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3570 uint32 spellID = extractSpellIdFromLink((char*)args);
3572 SpellEntry const *spellInfo = sSpellStore.LookupEntry( spellID );
3573 if(spellInfo)
3575 for(uint32 i = 0;i<3;++i)
3577 uint8 eff = spellInfo->Effect[i];
3578 if (eff>=TOTAL_SPELL_EFFECTS)
3579 continue;
3580 if( IsAreaAuraEffect(eff) ||
3581 eff == SPELL_EFFECT_APPLY_AURA ||
3582 eff == SPELL_EFFECT_PERSISTENT_AREA_AURA )
3584 Aura *Aur = CreateAura(spellInfo, i, NULL, target);
3585 target->AddAura(Aur);
3590 return true;
3593 bool ChatHandler::HandleUnAuraCommand(const char* args)
3595 Unit *target = getSelectedUnit();
3596 if(!target)
3598 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3599 SetSentErrorMessage(true);
3600 return false;
3603 std::string argstr = args;
3604 if (argstr == "all")
3606 target->RemoveAllAuras();
3607 return true;
3610 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3611 uint32 spellID = extractSpellIdFromLink((char*)args);
3612 if(!spellID)
3613 return false;
3615 target->RemoveAurasDueToSpell(spellID);
3617 return true;
3620 bool ChatHandler::HandleLinkGraveCommand(const char* args)
3622 if(!*args)
3623 return false;
3625 char* px = strtok((char*)args, " ");
3626 if (!px)
3627 return false;
3629 uint32 g_id = (uint32)atoi(px);
3631 uint32 g_team;
3633 char* px2 = strtok(NULL, " ");
3635 if (!px2)
3636 g_team = 0;
3637 else if (strncmp(px2,"horde",6)==0)
3638 g_team = HORDE;
3639 else if (strncmp(px2,"alliance",9)==0)
3640 g_team = ALLIANCE;
3641 else
3642 return false;
3644 WorldSafeLocsEntry const* graveyard = sWorldSafeLocsStore.LookupEntry(g_id);
3646 if(!graveyard )
3648 PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST, g_id);
3649 SetSentErrorMessage(true);
3650 return false;
3653 Player* player = m_session->GetPlayer();
3655 uint32 zoneId = player->GetZoneId();
3657 AreaTableEntry const *areaEntry = GetAreaEntryByAreaID(zoneId);
3658 if(!areaEntry || areaEntry->zone !=0 )
3660 PSendSysMessage(LANG_COMMAND_GRAVEYARDWRONGZONE, g_id,zoneId);
3661 SetSentErrorMessage(true);
3662 return false;
3665 if(sObjectMgr.AddGraveYardLink(g_id,zoneId,g_team))
3666 PSendSysMessage(LANG_COMMAND_GRAVEYARDLINKED, g_id,zoneId);
3667 else
3668 PSendSysMessage(LANG_COMMAND_GRAVEYARDALRLINKED, g_id,zoneId);
3670 return true;
3673 bool ChatHandler::HandleNearGraveCommand(const char* args)
3675 uint32 g_team;
3677 size_t argslen = strlen(args);
3679 if(!*args)
3680 g_team = 0;
3681 else if (strncmp((char*)args,"horde",argslen)==0)
3682 g_team = HORDE;
3683 else if (strncmp((char*)args,"alliance",argslen)==0)
3684 g_team = ALLIANCE;
3685 else
3686 return false;
3688 Player* player = m_session->GetPlayer();
3689 uint32 zone_id = player->GetZoneId();
3691 WorldSafeLocsEntry const* graveyard = sObjectMgr.GetClosestGraveYard(
3692 player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(),player->GetMapId(),g_team);
3694 if(graveyard)
3696 uint32 g_id = graveyard->ID;
3698 GraveYardData const* data = sObjectMgr.FindGraveYardData(g_id,zone_id);
3699 if (!data)
3701 PSendSysMessage(LANG_COMMAND_GRAVEYARDERROR,g_id);
3702 SetSentErrorMessage(true);
3703 return false;
3706 g_team = data->team;
3708 std::string team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_NOTEAM);
3710 if(g_team == 0)
3711 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ANY);
3712 else if(g_team == HORDE)
3713 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE);
3714 else if(g_team == ALLIANCE)
3715 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE);
3717 PSendSysMessage(LANG_COMMAND_GRAVEYARDNEAREST, g_id,team_name.c_str(),zone_id);
3719 else
3721 std::string team_name;
3723 if(g_team == 0)
3724 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ANY);
3725 else if(g_team == HORDE)
3726 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE);
3727 else if(g_team == ALLIANCE)
3728 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE);
3730 if(g_team == ~uint32(0))
3731 PSendSysMessage(LANG_COMMAND_ZONENOGRAVEYARDS, zone_id);
3732 else
3733 PSendSysMessage(LANG_COMMAND_ZONENOGRAFACTION, zone_id,team_name.c_str());
3736 return true;
3739 //-----------------------Npc Commands-----------------------
3740 bool ChatHandler::HandleNpcAllowMovementCommand(const char* /*args*/)
3742 if(sWorld.getAllowMovement())
3744 sWorld.SetAllowMovement(false);
3745 SendSysMessage(LANG_CREATURE_MOVE_DISABLED);
3747 else
3749 sWorld.SetAllowMovement(true);
3750 SendSysMessage(LANG_CREATURE_MOVE_ENABLED);
3752 return true;
3755 bool ChatHandler::HandleNpcChangeEntryCommand(const char *args)
3757 if (!*args)
3758 return false;
3760 uint32 newEntryNum = atoi(args);
3761 if(!newEntryNum)
3762 return false;
3764 Unit* unit = getSelectedUnit();
3765 if(!unit || unit->GetTypeId() != TYPEID_UNIT)
3767 SendSysMessage(LANG_SELECT_CREATURE);
3768 SetSentErrorMessage(true);
3769 return false;
3771 Creature* creature = (Creature*)unit;
3772 if(creature->UpdateEntry(newEntryNum))
3773 SendSysMessage(LANG_DONE);
3774 else
3775 SendSysMessage(LANG_ERROR);
3776 return true;
3779 bool ChatHandler::HandleNpcInfoCommand(const char* /*args*/)
3781 Creature* target = getSelectedCreature();
3783 if(!target)
3785 SendSysMessage(LANG_SELECT_CREATURE);
3786 SetSentErrorMessage(true);
3787 return false;
3790 uint32 faction = target->getFaction();
3791 uint32 npcflags = target->GetUInt32Value(UNIT_NPC_FLAGS);
3792 uint32 displayid = target->GetDisplayId();
3793 uint32 nativeid = target->GetNativeDisplayId();
3794 uint32 Entry = target->GetEntry();
3795 CreatureInfo const* cInfo = target->GetCreatureInfo();
3797 int32 curRespawnDelay = target->GetRespawnTimeEx()-time(NULL);
3798 if(curRespawnDelay < 0)
3799 curRespawnDelay = 0;
3800 std::string curRespawnDelayStr = secsToTimeString(curRespawnDelay,true);
3801 std::string defRespawnDelayStr = secsToTimeString(target->GetRespawnDelay(),true);
3803 PSendSysMessage(LANG_NPCINFO_CHAR, target->GetDBTableGUIDLow(), faction, npcflags, Entry, displayid, nativeid);
3804 PSendSysMessage(LANG_NPCINFO_LEVEL, target->getLevel());
3805 PSendSysMessage(LANG_NPCINFO_HEALTH,target->GetCreateHealth(), target->GetMaxHealth(), target->GetHealth());
3806 PSendSysMessage(LANG_NPCINFO_FLAGS, target->GetUInt32Value(UNIT_FIELD_FLAGS), target->GetUInt32Value(UNIT_DYNAMIC_FLAGS), target->getFaction());
3807 PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES, defRespawnDelayStr.c_str(),curRespawnDelayStr.c_str());
3808 PSendSysMessage(LANG_NPCINFO_LOOT, cInfo->lootid,cInfo->pickpocketLootId,cInfo->SkinLootId);
3809 PSendSysMessage(LANG_NPCINFO_DUNGEON_ID, target->GetInstanceId());
3810 PSendSysMessage(LANG_NPCINFO_POSITION,float(target->GetPositionX()), float(target->GetPositionY()), float(target->GetPositionZ()));
3812 if ((npcflags & UNIT_NPC_FLAG_VENDOR) )
3814 SendSysMessage(LANG_NPCINFO_VENDOR);
3816 if ((npcflags & UNIT_NPC_FLAG_TRAINER) )
3818 SendSysMessage(LANG_NPCINFO_TRAINER);
3821 return true;
3824 //play npc emote
3825 bool ChatHandler::HandleNpcPlayEmoteCommand(const char* args)
3827 uint32 emote = atoi((char*)args);
3829 Creature* target = getSelectedCreature();
3830 if(!target)
3832 SendSysMessage(LANG_SELECT_CREATURE);
3833 SetSentErrorMessage(true);
3834 return false;
3837 target->SetUInt32Value(UNIT_NPC_EMOTESTATE,emote);
3839 return true;
3842 //TODO: NpcCommands that needs to be fixed :
3844 bool ChatHandler::HandleNpcAddWeaponCommand(const char* /*args*/)
3846 /*if (!*args)
3847 return false;
3849 uint64 guid = m_session->GetPlayer()->GetSelection();
3850 if (guid == 0)
3852 SendSysMessage(LANG_NO_SELECTION);
3853 return true;
3856 Creature *pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
3858 if(!pCreature)
3860 SendSysMessage(LANG_SELECT_CREATURE);
3861 return true;
3864 char* pSlotID = strtok((char*)args, " ");
3865 if (!pSlotID)
3866 return false;
3868 char* pItemID = strtok(NULL, " ");
3869 if (!pItemID)
3870 return false;
3872 uint32 ItemID = atoi(pItemID);
3873 uint32 SlotID = atoi(pSlotID);
3875 ItemPrototype* tmpItem = ObjectMgr::GetItemPrototype(ItemID);
3877 bool added = false;
3878 if(tmpItem)
3880 switch(SlotID)
3882 case 1:
3883 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID);
3884 added = true;
3885 break;
3886 case 2:
3887 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID);
3888 added = true;
3889 break;
3890 case 3:
3891 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID);
3892 added = true;
3893 break;
3894 default:
3895 PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST,SlotID);
3896 added = false;
3897 break;
3900 if(added)
3901 PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT,ItemID,tmpItem->Name1,SlotID);
3903 else
3905 PSendSysMessage(LANG_ITEM_NOT_FOUND,ItemID);
3906 return true;
3909 return true;
3911 //----------------------------------------------------------
3913 bool ChatHandler::HandleExploreCheatCommand(const char* args)
3915 if (!*args)
3916 return false;
3918 int flag = atoi((char*)args);
3920 Player *chr = getSelectedPlayer();
3921 if (chr == NULL)
3923 SendSysMessage(LANG_NO_CHAR_SELECTED);
3924 SetSentErrorMessage(true);
3925 return false;
3928 if (flag != 0)
3930 PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL, GetNameLink(chr).c_str());
3931 if (needReportToTarget(chr))
3932 ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_ALL,GetNameLink().c_str());
3934 else
3936 PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING, GetNameLink(chr).c_str());
3937 if (needReportToTarget(chr))
3938 ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_NOTHING,GetNameLink().c_str());
3941 for (uint8 i=0; i<128; ++i)
3943 if (flag != 0)
3945 m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1+i,0xFFFFFFFF);
3947 else
3949 m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1+i,0);
3953 return true;
3956 bool ChatHandler::HandleHoverCommand(const char* args)
3958 char* px = strtok((char*)args, " ");
3959 uint32 flag;
3960 if (!px)
3961 flag = 1;
3962 else
3963 flag = atoi(px);
3965 m_session->GetPlayer()->SetHover(flag);
3967 if (flag)
3968 SendSysMessage(LANG_HOVER_ENABLED);
3969 else
3970 SendSysMessage(LANG_HOVER_DISABLED);
3972 return true;
3975 void ChatHandler::HandleCharacterLevel(Player* player, uint64 player_guid, uint32 oldlevel, uint32 newlevel)
3977 if(player)
3979 player->GiveLevel(newlevel);
3980 player->InitTalentForLevel();
3981 player->SetUInt32Value(PLAYER_XP,0);
3983 if(needReportToTarget(player))
3985 if(oldlevel == newlevel)
3986 ChatHandler(player).PSendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET,GetNameLink().c_str());
3987 else if(oldlevel < newlevel)
3988 ChatHandler(player).PSendSysMessage(LANG_YOURS_LEVEL_UP,GetNameLink().c_str(),newlevel);
3989 else // if(oldlevel > newlevel)
3990 ChatHandler(player).PSendSysMessage(LANG_YOURS_LEVEL_DOWN,GetNameLink().c_str(),newlevel);
3993 else
3995 // update level and XP at level, all other will be updated at loading
3996 CharacterDatabase.PExecute("UPDATE characters SET level = '%u', xp = 0 WHERE guid = '%u'", newlevel, GUID_LOPART(player_guid));
4000 bool ChatHandler::HandleCharacterLevelCommand(const char* args)
4002 char* nameStr;
4003 char* levelStr;
4004 extractOptFirstArg((char*)args,&nameStr,&levelStr);
4005 if(!levelStr)
4006 return false;
4008 // exception opt second arg: .character level $name
4009 if(isalpha(levelStr[0]))
4011 nameStr = levelStr;
4012 levelStr = NULL; // current level will used
4015 Player* target;
4016 uint64 target_guid;
4017 std::string target_name;
4018 if(!extractPlayerTarget(nameStr,&target,&target_guid,&target_name))
4019 return false;
4021 int32 oldlevel = target ? target->getLevel() : Player::GetLevelFromDB(target_guid);
4022 int32 newlevel = levelStr ? atoi(levelStr) : oldlevel;
4024 if(newlevel < 1)
4025 return false; // invalid level
4027 if(newlevel > STRONG_MAX_LEVEL) // hardcoded maximum level
4028 newlevel = STRONG_MAX_LEVEL;
4030 HandleCharacterLevel(target,target_guid,oldlevel,newlevel);
4032 if(!m_session || m_session->GetPlayer() != target) // including player==NULL
4034 std::string nameLink = playerLink(target_name);
4035 PSendSysMessage(LANG_YOU_CHANGE_LVL,nameLink.c_str(),newlevel);
4038 return true;
4041 bool ChatHandler::HandleLevelUpCommand(const char* args)
4043 char* nameStr;
4044 char* levelStr;
4045 extractOptFirstArg((char*)args,&nameStr,&levelStr);
4047 // exception opt second arg: .character level $name
4048 if(levelStr && isalpha(levelStr[0]))
4050 nameStr = levelStr;
4051 levelStr = NULL; // current level will used
4054 Player* target;
4055 uint64 target_guid;
4056 std::string target_name;
4057 if(!extractPlayerTarget(nameStr,&target,&target_guid,&target_name))
4058 return false;
4060 int32 oldlevel = target ? target->getLevel() : Player::GetLevelFromDB(target_guid);
4061 int32 addlevel = levelStr ? atoi(levelStr) : 1;
4062 int32 newlevel = oldlevel + addlevel;
4064 if(newlevel < 1)
4065 newlevel = 1;
4067 if(newlevel > STRONG_MAX_LEVEL) // hardcoded maximum level
4068 newlevel = STRONG_MAX_LEVEL;
4070 HandleCharacterLevel(target,target_guid,oldlevel,newlevel);
4072 if(!m_session || m_session->GetPlayer() != target) // including chr==NULL
4074 std::string nameLink = playerLink(target_name);
4075 PSendSysMessage(LANG_YOU_CHANGE_LVL,nameLink.c_str(),newlevel);
4078 return true;
4081 bool ChatHandler::HandleShowAreaCommand(const char* args)
4083 if (!*args)
4084 return false;
4086 Player *chr = getSelectedPlayer();
4087 if (chr == NULL)
4089 SendSysMessage(LANG_NO_CHAR_SELECTED);
4090 SetSentErrorMessage(true);
4091 return false;
4094 int area = GetAreaFlagByAreaID(atoi((char*)args));
4095 int offset = area / 32;
4096 uint32 val = (uint32)(1 << (area % 32));
4098 if(area<0 || offset >= 128)
4100 SendSysMessage(LANG_BAD_VALUE);
4101 SetSentErrorMessage(true);
4102 return false;
4105 uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
4106 chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields | val));
4108 SendSysMessage(LANG_EXPLORE_AREA);
4109 return true;
4112 bool ChatHandler::HandleHideAreaCommand(const char* args)
4114 if (!*args)
4115 return false;
4117 Player *chr = getSelectedPlayer();
4118 if (chr == NULL)
4120 SendSysMessage(LANG_NO_CHAR_SELECTED);
4121 SetSentErrorMessage(true);
4122 return false;
4125 int area = GetAreaFlagByAreaID(atoi((char*)args));
4126 int offset = area / 32;
4127 uint32 val = (uint32)(1 << (area % 32));
4129 if(area<0 || offset >= 128)
4131 SendSysMessage(LANG_BAD_VALUE);
4132 SetSentErrorMessage(true);
4133 return false;
4136 uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
4137 chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields ^ val));
4139 SendSysMessage(LANG_UNEXPLORE_AREA);
4140 return true;
4143 bool ChatHandler::HandleBankCommand(const char* /*args*/)
4145 m_session->SendShowBank( m_session->GetPlayer()->GetGUID() );
4147 return true;
4150 bool ChatHandler::HandleChangeWeather(const char* args)
4152 if(!*args)
4153 return false;
4155 //Weather is OFF
4156 if (!sWorld.getConfig(CONFIG_WEATHER))
4158 SendSysMessage(LANG_WEATHER_DISABLED);
4159 SetSentErrorMessage(true);
4160 return false;
4163 //*Change the weather of a cell
4164 char* px = strtok((char*)args, " ");
4165 char* py = strtok(NULL, " ");
4167 if (!px || !py)
4168 return false;
4170 uint32 type = (uint32)atoi(px); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
4171 float grade = (float)atof(py); //0 to 1, sending -1 is instand good weather
4173 Player *player = m_session->GetPlayer();
4174 uint32 zoneid = player->GetZoneId();
4176 Weather* wth = sWorld.FindWeather(zoneid);
4178 if(!wth)
4179 wth = sWorld.AddWeather(zoneid);
4180 if(!wth)
4182 SendSysMessage(LANG_NO_WEATHER);
4183 SetSentErrorMessage(true);
4184 return false;
4187 wth->SetWeather(WeatherType(type), grade);
4189 return true;
4192 bool ChatHandler::HandleTeleAddCommand(const char * args)
4194 if(!*args)
4195 return false;
4197 Player *player=m_session->GetPlayer();
4198 if (!player)
4199 return false;
4201 std::string name = args;
4203 if(sObjectMgr.GetGameTele(name))
4205 SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST);
4206 SetSentErrorMessage(true);
4207 return false;
4210 GameTele tele;
4211 tele.position_x = player->GetPositionX();
4212 tele.position_y = player->GetPositionY();
4213 tele.position_z = player->GetPositionZ();
4214 tele.orientation = player->GetOrientation();
4215 tele.mapId = player->GetMapId();
4216 tele.name = name;
4218 if(sObjectMgr.AddGameTele(tele))
4220 SendSysMessage(LANG_COMMAND_TP_ADDED);
4222 else
4224 SendSysMessage(LANG_COMMAND_TP_ADDEDERR);
4225 SetSentErrorMessage(true);
4226 return false;
4229 return true;
4232 bool ChatHandler::HandleTeleDelCommand(const char * args)
4234 if(!*args)
4235 return false;
4237 std::string name = args;
4239 if(!sObjectMgr.DeleteGameTele(name))
4241 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
4242 SetSentErrorMessage(true);
4243 return false;
4246 SendSysMessage(LANG_COMMAND_TP_DELETED);
4247 return true;
4250 bool ChatHandler::HandleListAurasCommand (const char * /*args*/)
4252 Unit *unit = getSelectedUnit();
4253 if(!unit)
4255 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4256 SetSentErrorMessage(true);
4257 return false;
4260 char const* talentStr = GetMangosString(LANG_TALENT);
4261 char const* passiveStr = GetMangosString(LANG_PASSIVE);
4263 Unit::AuraMap const& uAuras = unit->GetAuras();
4264 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS, uAuras.size());
4265 for (Unit::AuraMap::const_iterator itr = uAuras.begin(); itr != uAuras.end(); ++itr)
4267 bool talent = GetTalentSpellCost(itr->second->GetId()) > 0;
4269 char const* name = itr->second->GetSpellProto()->SpellName[GetSessionDbcLocale()];
4271 if (m_session)
4273 std::ostringstream ss_name;
4274 ss_name << "|cffffffff|Hspell:" << itr->second->GetId() << "|h[" << name << "]|h|r";
4276 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL, itr->second->GetId(), itr->second->GetEffIndex(),
4277 itr->second->GetModifier()->m_auraname, itr->second->GetAuraDuration(), itr->second->GetAuraMaxDuration(),
4278 ss_name.str().c_str(),
4279 (itr->second->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4280 IS_PLAYER_GUID(itr->second->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr->second->GetCasterGUID()));
4282 else
4284 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL, itr->second->GetId(), itr->second->GetEffIndex(),
4285 itr->second->GetModifier()->m_auraname, itr->second->GetAuraDuration(), itr->second->GetAuraMaxDuration(),
4286 name,
4287 (itr->second->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4288 IS_PLAYER_GUID(itr->second->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr->second->GetCasterGUID()));
4291 for (int i = 0; i < TOTAL_AURAS; ++i)
4293 Unit::AuraList const& uAuraList = unit->GetAurasByType(AuraType(i));
4294 if (uAuraList.empty()) continue;
4295 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE, uAuraList.size(), i);
4296 for (Unit::AuraList::const_iterator itr = uAuraList.begin(); itr != uAuraList.end(); ++itr)
4298 bool talent = GetTalentSpellCost((*itr)->GetId()) > 0;
4300 char const* name = (*itr)->GetSpellProto()->SpellName[GetSessionDbcLocale()];
4302 if (m_session)
4304 std::ostringstream ss_name;
4305 ss_name << "|cffffffff|Hspell:" << (*itr)->GetId() << "|h[" << name << "]|h|r";
4307 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE, (*itr)->GetId(), (*itr)->GetEffIndex(),
4308 ss_name.str().c_str(),((*itr)->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4309 IS_PLAYER_GUID((*itr)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr)->GetCasterGUID()));
4311 else
4313 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE, (*itr)->GetId(), (*itr)->GetEffIndex(),
4314 name,((*itr)->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4315 IS_PLAYER_GUID((*itr)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr)->GetCasterGUID()));
4319 return true;
4322 bool ChatHandler::HandleResetAchievementsCommand (const char * args)
4324 Player* target;
4325 uint64 target_guid;
4326 if (!extractPlayerTarget((char*)args,&target,&target_guid))
4327 return false;
4329 if(target)
4330 target->GetAchievementMgr().Reset();
4331 else
4332 AchievementMgr::DeleteFromDB(GUID_LOPART(target_guid));
4334 return true;
4337 bool ChatHandler::HandleResetHonorCommand (const char * args)
4339 Player* target;
4340 if (!extractPlayerTarget((char*)args,&target))
4341 return false;
4343 target->SetUInt32Value(PLAYER_FIELD_KILLS, 0);
4344 target->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS, 0);
4345 target->SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY, 0);
4346 target->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION, 0);
4347 target->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION, 0);
4348 target->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_EARN_HONORABLE_KILL);
4350 return true;
4353 static bool HandleResetStatsOrLevelHelper(Player* player)
4355 ChrClassesEntry const* cEntry = sChrClassesStore.LookupEntry(player->getClass());
4356 if(!cEntry)
4358 sLog.outError("Class %u not found in DBC (Wrong DBC files?)",player->getClass());
4359 return false;
4362 uint8 powertype = cEntry->powerType;
4364 // reset m_form if no aura
4365 if(!player->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT))
4366 player->m_form = FORM_NONE;
4368 player->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, DEFAULT_WORLD_OBJECT_SIZE );
4369 player->SetFloatValue(UNIT_FIELD_COMBATREACH, 1.5f );
4371 player->setFactionForRace(player->getRace());
4373 player->SetUInt32Value(UNIT_FIELD_BYTES_0, ( ( player->getRace() ) | ( player->getClass() << 8 ) | ( player->getGender() << 16 ) | ( powertype << 24 ) ) );
4375 // reset only if player not in some form;
4376 if(player->m_form==FORM_NONE)
4377 player->InitDisplayIds();
4379 player->SetByteValue(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_PVP );
4380 player->SetByteValue(UNIT_FIELD_BYTES_2, 3, player->m_form);
4382 player->SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
4384 //-1 is default value
4385 player->SetInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX, -1);
4387 //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000 );
4388 return true;
4391 bool ChatHandler::HandleResetLevelCommand(const char * args)
4393 Player* target;
4394 if(!extractPlayerTarget((char*)args,&target))
4395 return false;
4397 if(!HandleResetStatsOrLevelHelper(target))
4398 return false;
4400 // set starting level
4401 uint32 start_level = target->getClass() != CLASS_DEATH_KNIGHT
4402 ? sWorld.getConfig(CONFIG_START_PLAYER_LEVEL)
4403 : sWorld.getConfig(CONFIG_START_HEROIC_PLAYER_LEVEL);
4405 target->_ApplyAllLevelScaleItemMods(false);
4407 target->SetLevel(start_level);
4408 target->InitRunes();
4409 target->InitStatsForLevel(true);
4410 target->InitTaxiNodesForLevel();
4411 target->InitGlyphsForLevel();
4412 target->InitTalentForLevel();
4413 target->SetUInt32Value(PLAYER_XP,0);
4415 target->_ApplyAllLevelScaleItemMods(true);
4417 // reset level for pet
4418 if(Pet* pet = target->GetPet())
4419 pet->SynchronizeLevelWithOwner();
4421 return true;
4424 bool ChatHandler::HandleResetStatsCommand(const char * args)
4426 Player* target;
4427 if (!extractPlayerTarget((char*)args,&target))
4428 return false;
4430 if (!HandleResetStatsOrLevelHelper(target))
4431 return false;
4433 target->InitRunes();
4434 target->InitStatsForLevel(true);
4435 target->InitTaxiNodesForLevel();
4436 target->InitGlyphsForLevel();
4437 target->InitTalentForLevel();
4439 return true;
4442 bool ChatHandler::HandleResetSpellsCommand(const char * args)
4444 Player* target;
4445 uint64 target_guid;
4446 std::string target_name;
4447 if(!extractPlayerTarget((char*)args,&target,&target_guid,&target_name))
4448 return false;
4450 if(target)
4452 target->resetSpells();
4454 ChatHandler(target).SendSysMessage(LANG_RESET_SPELLS);
4455 if(!m_session || m_session->GetPlayer()!=target)
4456 PSendSysMessage(LANG_RESET_SPELLS_ONLINE,GetNameLink(target).c_str());
4458 else
4460 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS), GUID_LOPART(target_guid));
4461 PSendSysMessage(LANG_RESET_SPELLS_OFFLINE,target_name.c_str());
4464 return true;
4467 bool ChatHandler::HandleResetTalentsCommand(const char * args)
4469 Player* target;
4470 uint64 target_guid;
4471 std::string target_name;
4472 if (!extractPlayerTarget((char*)args,&target,&target_guid,&target_name))
4474 // Try reset talents as Hunter Pet
4475 Creature* creature = getSelectedCreature();
4476 if (!*args && creature && creature->isPet())
4478 Unit *owner = creature->GetOwner();
4479 if(owner && owner->GetTypeId() == TYPEID_PLAYER && ((Pet *)creature)->IsPermanentPetFor((Player*)owner))
4481 ((Pet *)creature)->resetTalents(true);
4482 ((Player*)owner)->SendTalentsInfoData(true);
4484 ChatHandler((Player*)owner).SendSysMessage(LANG_RESET_PET_TALENTS);
4485 if(!m_session || m_session->GetPlayer()!=((Player*)owner))
4486 PSendSysMessage(LANG_RESET_PET_TALENTS_ONLINE,GetNameLink((Player*)owner).c_str());
4488 return true;
4491 SendSysMessage(LANG_NO_CHAR_SELECTED);
4492 SetSentErrorMessage(true);
4493 return false;
4496 if (target)
4498 target->resetTalents(true);
4499 target->SendTalentsInfoData(false);
4500 ChatHandler(target).SendSysMessage(LANG_RESET_TALENTS);
4501 if (!m_session || m_session->GetPlayer()!=target)
4502 PSendSysMessage(LANG_RESET_TALENTS_ONLINE,GetNameLink(target).c_str());
4504 Pet* pet = target->GetPet();
4505 Pet::resetTalentsForAllPetsOf(target,pet);
4506 if(pet)
4507 target->SendTalentsInfoData(true);
4508 return true;
4510 else if (target_guid)
4512 uint32 at_flags = AT_LOGIN_NONE | AT_LOGIN_RESET_PET_TALENTS;
4513 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",at_flags, GUID_LOPART(target_guid) );
4514 std::string nameLink = playerLink(target_name);
4515 PSendSysMessage(LANG_RESET_TALENTS_OFFLINE,nameLink.c_str());
4516 return true;
4519 SendSysMessage(LANG_NO_CHAR_SELECTED);
4520 SetSentErrorMessage(true);
4521 return false;
4524 bool ChatHandler::HandleResetAllCommand(const char * args)
4526 if(!*args)
4527 return false;
4529 std::string casename = args;
4531 AtLoginFlags atLogin;
4533 // Command specially created as single command to prevent using short case names
4534 if(casename=="spells")
4536 atLogin = AT_LOGIN_RESET_SPELLS;
4537 sWorld.SendWorldText(LANG_RESETALL_SPELLS);
4538 if(!m_session)
4539 SendSysMessage(LANG_RESETALL_SPELLS);
4541 else if(casename=="talents")
4543 atLogin = AtLoginFlags(AT_LOGIN_RESET_TALENTS | AT_LOGIN_RESET_PET_TALENTS);
4544 sWorld.SendWorldText(LANG_RESETALL_TALENTS);
4545 if(!m_session)
4546 SendSysMessage(LANG_RESETALL_TALENTS);
4548 else
4550 PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE,args);
4551 SetSentErrorMessage(true);
4552 return false;
4555 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE (at_login & '%u') = '0'",atLogin,atLogin);
4556 HashMapHolder<Player>::MapType const& plist = sObjectAccessor.GetPlayers();
4557 for(HashMapHolder<Player>::MapType::const_iterator itr = plist.begin(); itr != plist.end(); ++itr)
4558 itr->second->SetAtLoginFlag(atLogin);
4560 return true;
4563 bool ChatHandler::HandleServerShutDownCancelCommand(const char* /*args*/)
4565 sWorld.ShutdownCancel();
4566 return true;
4569 bool ChatHandler::HandleServerShutDownCommand(const char* args)
4571 if(!*args)
4572 return false;
4574 char* time_str = strtok ((char*) args, " ");
4575 char* exitcode_str = strtok (NULL, "");
4577 int32 time = atoi (time_str);
4579 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4580 if ((time == 0 && (time_str[0]!='0' || time_str[1]!='\0')) || time < 0)
4581 return false;
4583 if (exitcode_str)
4585 int32 exitcode = atoi (exitcode_str);
4587 // Handle atoi() errors
4588 if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
4589 return false;
4591 // Exit code should be in range of 0-125, 126-255 is used
4592 // in many shells for their own return codes and code > 255
4593 // is not supported in many others
4594 if (exitcode < 0 || exitcode > 125)
4595 return false;
4597 sWorld.ShutdownServ (time, 0, exitcode);
4599 else
4600 sWorld.ShutdownServ(time,0,SHUTDOWN_EXIT_CODE);
4601 return true;
4604 bool ChatHandler::HandleServerRestartCommand(const char* args)
4606 if(!*args)
4607 return false;
4609 char* time_str = strtok ((char*) args, " ");
4610 char* exitcode_str = strtok (NULL, "");
4612 int32 time = atoi (time_str);
4614 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4615 if ((time == 0 && (time_str[0]!='0' || time_str[1]!='\0')) || time < 0)
4616 return false;
4618 if (exitcode_str)
4620 int32 exitcode = atoi (exitcode_str);
4622 // Handle atoi() errors
4623 if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
4624 return false;
4626 // Exit code should be in range of 0-125, 126-255 is used
4627 // in many shells for their own return codes and code > 255
4628 // is not supported in many others
4629 if (exitcode < 0 || exitcode > 125)
4630 return false;
4632 sWorld.ShutdownServ (time, SHUTDOWN_MASK_RESTART, exitcode);
4634 else
4635 sWorld.ShutdownServ(time, SHUTDOWN_MASK_RESTART, RESTART_EXIT_CODE);
4636 return true;
4639 bool ChatHandler::HandleServerIdleRestartCommand(const char* args)
4641 if(!*args)
4642 return false;
4644 char* time_str = strtok ((char*) args, " ");
4645 char* exitcode_str = strtok (NULL, "");
4647 int32 time = atoi (time_str);
4649 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4650 if ((time == 0 && (time_str[0]!='0' || time_str[1]!='\0')) || time < 0)
4651 return false;
4653 if (exitcode_str)
4655 int32 exitcode = atoi (exitcode_str);
4657 // Handle atoi() errors
4658 if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
4659 return false;
4661 // Exit code should be in range of 0-125, 126-255 is used
4662 // in many shells for their own return codes and code > 255
4663 // is not supported in many others
4664 if (exitcode < 0 || exitcode > 125)
4665 return false;
4667 sWorld.ShutdownServ (time, SHUTDOWN_MASK_RESTART|SHUTDOWN_MASK_IDLE, exitcode);
4669 else
4670 sWorld.ShutdownServ(time,SHUTDOWN_MASK_RESTART|SHUTDOWN_MASK_IDLE,RESTART_EXIT_CODE);
4671 return true;
4674 bool ChatHandler::HandleServerIdleShutDownCommand(const char* args)
4676 if(!*args)
4677 return false;
4679 char* time_str = strtok ((char*) args, " ");
4680 char* exitcode_str = strtok (NULL, "");
4682 int32 time = atoi (time_str);
4684 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4685 if ((time == 0 && (time_str[0]!='0' || time_str[1]!='\0')) || time < 0)
4686 return false;
4688 if (exitcode_str)
4690 int32 exitcode = atoi (exitcode_str);
4692 // Handle atoi() errors
4693 if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
4694 return false;
4696 // Exit code should be in range of 0-125, 126-255 is used
4697 // in many shells for their own return codes and code > 255
4698 // is not supported in many others
4699 if (exitcode < 0 || exitcode > 125)
4700 return false;
4702 sWorld.ShutdownServ (time, SHUTDOWN_MASK_IDLE, exitcode);
4704 else
4705 sWorld.ShutdownServ(time,SHUTDOWN_MASK_IDLE,SHUTDOWN_EXIT_CODE);
4706 return true;
4709 bool ChatHandler::HandleQuestAdd(const char* args)
4711 Player* player = getSelectedPlayer();
4712 if(!player)
4714 SendSysMessage(LANG_NO_CHAR_SELECTED);
4715 SetSentErrorMessage(true);
4716 return false;
4719 // .addquest #entry'
4720 // number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
4721 char* cId = extractKeyFromLink((char*)args,"Hquest");
4722 if(!cId)
4723 return false;
4725 uint32 entry = atol(cId);
4727 Quest const* pQuest = sObjectMgr.GetQuestTemplate(entry);
4729 if(!pQuest)
4731 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND,entry);
4732 SetSentErrorMessage(true);
4733 return false;
4736 // check item starting quest (it can work incorrectly if added without item in inventory)
4737 for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
4739 ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype>(id);
4740 if (!pProto)
4741 continue;
4743 if (pProto->StartQuest == entry)
4745 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, entry, pProto->ItemId);
4746 SetSentErrorMessage(true);
4747 return false;
4751 // ok, normal (creature/GO starting) quest
4752 if( player->CanAddQuest( pQuest, true ) )
4754 player->AddQuest( pQuest, NULL );
4756 if ( player->CanCompleteQuest( entry ) )
4757 player->CompleteQuest( entry );
4760 return true;
4763 bool ChatHandler::HandleQuestRemove(const char* args)
4765 Player* player = getSelectedPlayer();
4766 if(!player)
4768 SendSysMessage(LANG_NO_CHAR_SELECTED);
4769 SetSentErrorMessage(true);
4770 return false;
4773 // .removequest #entry'
4774 // number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
4775 char* cId = extractKeyFromLink((char*)args,"Hquest");
4776 if(!cId)
4777 return false;
4779 uint32 entry = atol(cId);
4781 Quest const* pQuest = sObjectMgr.GetQuestTemplate(entry);
4783 if(!pQuest)
4785 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
4786 SetSentErrorMessage(true);
4787 return false;
4790 // remove all quest entries for 'entry' from quest log
4791 for(uint8 slot = 0; slot < MAX_QUEST_LOG_SIZE; ++slot )
4793 uint32 quest = player->GetQuestSlotQuestId(slot);
4794 if(quest==entry)
4796 player->SetQuestSlot(slot,0);
4798 // we ignore unequippable quest items in this case, its' still be equipped
4799 player->TakeQuestSourceItem( quest, false );
4803 // set quest status to not started (will updated in DB at next save)
4804 player->SetQuestStatus( entry, QUEST_STATUS_NONE);
4806 // reset rewarded for restart repeatable quest
4807 player->getQuestStatusMap()[entry].m_rewarded = false;
4809 SendSysMessage(LANG_COMMAND_QUEST_REMOVED);
4810 return true;
4813 bool ChatHandler::HandleQuestComplete(const char* args)
4815 Player* player = getSelectedPlayer();
4816 if(!player)
4818 SendSysMessage(LANG_NO_CHAR_SELECTED);
4819 SetSentErrorMessage(true);
4820 return false;
4823 // .quest complete #entry
4824 // number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
4825 char* cId = extractKeyFromLink((char*)args,"Hquest");
4826 if(!cId)
4827 return false;
4829 uint32 entry = atol(cId);
4831 Quest const* pQuest = sObjectMgr.GetQuestTemplate(entry);
4833 // If player doesn't have the quest
4834 if(!pQuest || player->GetQuestStatus(entry) == QUEST_STATUS_NONE)
4836 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
4837 SetSentErrorMessage(true);
4838 return false;
4841 // Add quest items for quests that require items
4842 for(uint8 x = 0; x < QUEST_ITEM_OBJECTIVES_COUNT; ++x)
4844 uint32 id = pQuest->ReqItemId[x];
4845 uint32 count = pQuest->ReqItemCount[x];
4846 if(!id || !count)
4847 continue;
4849 uint32 curItemCount = player->GetItemCount(id,true);
4851 ItemPosCountVec dest;
4852 uint8 msg = player->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, id, count - curItemCount );
4853 if( msg == EQUIP_ERR_OK )
4855 Item* item = player->StoreNewItem( dest, id, true);
4856 player->SendNewItem(item,count-curItemCount, true, false);
4860 // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
4861 for(uint8 i = 0; i < QUEST_OBJECTIVES_COUNT; ++i)
4863 uint32 creature = pQuest->ReqCreatureOrGOId[i];
4864 uint32 creaturecount = pQuest->ReqCreatureOrGOCount[i];
4866 if(uint32 spell_id = pQuest->ReqSpell[i])
4868 for(uint16 z = 0; z < creaturecount; ++z)
4869 player->CastedCreatureOrGO(creature,0,spell_id);
4871 else if(creature > 0)
4873 if(CreatureInfo const* cInfo = ObjectMgr::GetCreatureTemplate(creature))
4874 for(uint16 z = 0; z < creaturecount; ++z)
4875 player->KilledMonster(cInfo,0);
4877 else if(creature < 0)
4879 for(uint16 z = 0; z < creaturecount; ++z)
4880 player->CastedCreatureOrGO(creature,0,0);
4884 // If the quest requires reputation to complete
4885 if(uint32 repFaction = pQuest->GetRepObjectiveFaction())
4887 uint32 repValue = pQuest->GetRepObjectiveValue();
4888 uint32 curRep = player->GetReputationMgr().GetReputation(repFaction);
4889 if(curRep < repValue)
4890 if(FactionEntry const *factionEntry = sFactionStore.LookupEntry(repFaction))
4891 player->GetReputationMgr().SetReputation(factionEntry,repValue);
4894 // If the quest requires money
4895 int32 ReqOrRewMoney = pQuest->GetRewOrReqMoney();
4896 if(ReqOrRewMoney < 0)
4897 player->ModifyMoney(-ReqOrRewMoney);
4899 player->CompleteQuest(entry);
4900 return true;
4903 bool ChatHandler::HandleBanAccountCommand(const char* args)
4905 return HandleBanHelper(BAN_ACCOUNT,args);
4908 bool ChatHandler::HandleBanCharacterCommand(const char* args)
4910 return HandleBanHelper(BAN_CHARACTER,args);
4913 bool ChatHandler::HandleBanIPCommand(const char* args)
4915 return HandleBanHelper(BAN_IP,args);
4918 bool ChatHandler::HandleBanHelper(BanMode mode, const char* args)
4920 if (!*args)
4921 return false;
4923 char* cnameOrIP = strtok ((char*)args, " ");
4924 if (!cnameOrIP)
4925 return false;
4927 std::string nameOrIP = cnameOrIP;
4929 char* duration = strtok (NULL," ");
4930 if(!duration || !atoi(duration))
4931 return false;
4933 char* reason = strtok (NULL,"");
4934 if(!reason)
4935 return false;
4937 switch(mode)
4939 case BAN_ACCOUNT:
4940 if (!AccountMgr::normalizeString(nameOrIP))
4942 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str());
4943 SetSentErrorMessage(true);
4944 return false;
4946 break;
4947 case BAN_CHARACTER:
4948 if(!normalizePlayerName(nameOrIP))
4950 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4951 SetSentErrorMessage(true);
4952 return false;
4954 break;
4955 case BAN_IP:
4956 if(!IsIPAddress(nameOrIP.c_str()))
4957 return false;
4958 break;
4961 switch(sWorld.BanAccount(mode, nameOrIP, duration, reason,m_session ? m_session->GetPlayerName() : ""))
4963 case BAN_SUCCESS:
4964 if(atoi(duration)>0)
4965 PSendSysMessage(LANG_BAN_YOUBANNED,nameOrIP.c_str(),secsToTimeString(TimeStringToSecs(duration),true).c_str(),reason);
4966 else
4967 PSendSysMessage(LANG_BAN_YOUPERMBANNED,nameOrIP.c_str(),reason);
4968 break;
4969 case BAN_SYNTAX_ERROR:
4970 return false;
4971 case BAN_NOTFOUND:
4972 switch(mode)
4974 default:
4975 PSendSysMessage(LANG_BAN_NOTFOUND,"account",nameOrIP.c_str());
4976 break;
4977 case BAN_CHARACTER:
4978 PSendSysMessage(LANG_BAN_NOTFOUND,"character",nameOrIP.c_str());
4979 break;
4980 case BAN_IP:
4981 PSendSysMessage(LANG_BAN_NOTFOUND,"ip",nameOrIP.c_str());
4982 break;
4984 SetSentErrorMessage(true);
4985 return false;
4988 return true;
4991 bool ChatHandler::HandleUnBanAccountCommand(const char* args)
4993 return HandleUnBanHelper(BAN_ACCOUNT,args);
4996 bool ChatHandler::HandleUnBanCharacterCommand(const char* args)
4998 return HandleUnBanHelper(BAN_CHARACTER,args);
5001 bool ChatHandler::HandleUnBanIPCommand(const char* args)
5003 return HandleUnBanHelper(BAN_IP,args);
5006 bool ChatHandler::HandleUnBanHelper(BanMode mode, const char* args)
5008 if (!*args)
5009 return false;
5011 char* cnameOrIP = strtok ((char*)args, " ");
5012 if(!cnameOrIP)
5013 return false;
5015 std::string nameOrIP = cnameOrIP;
5017 switch(mode)
5019 case BAN_ACCOUNT:
5020 if (!AccountMgr::normalizeString(nameOrIP))
5022 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str());
5023 SetSentErrorMessage(true);
5024 return false;
5026 break;
5027 case BAN_CHARACTER:
5028 if(!normalizePlayerName(nameOrIP))
5030 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5031 SetSentErrorMessage(true);
5032 return false;
5034 break;
5035 case BAN_IP:
5036 if(!IsIPAddress(nameOrIP.c_str()))
5037 return false;
5038 break;
5041 if(sWorld.RemoveBanAccount(mode,nameOrIP))
5042 PSendSysMessage(LANG_UNBAN_UNBANNED,nameOrIP.c_str());
5043 else
5044 PSendSysMessage(LANG_UNBAN_ERROR,nameOrIP.c_str());
5046 return true;
5049 bool ChatHandler::HandleBanInfoAccountCommand(const char* args)
5051 if (!*args)
5052 return false;
5054 char* cname = strtok((char*)args, "");
5055 if (!cname)
5056 return false;
5058 std::string account_name = cname;
5059 if (!AccountMgr::normalizeString(account_name))
5061 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5062 SetSentErrorMessage(true);
5063 return false;
5066 uint32 accountid = sAccountMgr.GetId(account_name);
5067 if (!accountid)
5069 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5070 return true;
5073 return HandleBanInfoHelper(accountid,account_name.c_str());
5076 bool ChatHandler::HandleBanInfoCharacterCommand(const char* args)
5078 Player* target;
5079 uint64 target_guid;
5080 if (!extractPlayerTarget((char*)args,&target,&target_guid))
5081 return false;
5083 uint32 accountid = target ? target->GetSession()->GetAccountId() : sObjectMgr.GetPlayerAccountIdByGUID(target_guid);
5085 std::string accountname;
5086 if (!sAccountMgr.GetName(accountid,accountname))
5088 PSendSysMessage(LANG_BANINFO_NOCHARACTER);
5089 return true;
5092 return HandleBanInfoHelper(accountid,accountname.c_str());
5095 bool ChatHandler::HandleBanInfoHelper(uint32 accountid, char const* accountname)
5097 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);
5098 if(!result)
5100 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN, accountname);
5101 return true;
5104 PSendSysMessage(LANG_BANINFO_BANHISTORY,accountname);
5107 Field* fields = result->Fetch();
5109 time_t unbandate = time_t(fields[3].GetUInt64());
5110 bool active = false;
5111 if(fields[2].GetBool() && (fields[1].GetUInt64() == (uint64)0 ||unbandate >= time(NULL)) )
5112 active = true;
5113 bool permanent = (fields[1].GetUInt64() == (uint64)0);
5114 std::string bantime = permanent?GetMangosString(LANG_BANINFO_INFINITE):secsToTimeString(fields[1].GetUInt64(), true);
5115 PSendSysMessage(LANG_BANINFO_HISTORYENTRY,
5116 fields[0].GetString(), bantime.c_str(), active ? GetMangosString(LANG_BANINFO_YES):GetMangosString(LANG_BANINFO_NO), fields[4].GetString(), fields[5].GetString());
5117 }while (result->NextRow());
5119 delete result;
5120 return true;
5123 bool ChatHandler::HandleBanInfoIPCommand(const char* args)
5125 if (!*args)
5126 return false;
5128 char* cIP = strtok ((char*)args, "");
5129 if(!cIP)
5130 return false;
5132 if (!IsIPAddress(cIP))
5133 return false;
5135 std::string IP = cIP;
5137 loginDatabase.escape_string(IP);
5138 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());
5139 if(!result)
5141 PSendSysMessage(LANG_BANINFO_NOIP);
5142 return true;
5145 Field *fields = result->Fetch();
5146 bool permanent = !fields[6].GetUInt64();
5147 PSendSysMessage(LANG_BANINFO_IPENTRY,
5148 fields[0].GetString(), fields[1].GetString(), permanent ? GetMangosString(LANG_BANINFO_NEVER):fields[2].GetString(),
5149 permanent ? GetMangosString(LANG_BANINFO_INFINITE):secsToTimeString(fields[3].GetUInt64(), true).c_str(), fields[4].GetString(), fields[5].GetString());
5150 delete result;
5151 return true;
5154 bool ChatHandler::HandleBanListCharacterCommand(const char* args)
5156 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5158 char* cFilter = strtok ((char*)args, " ");
5159 if(!cFilter)
5160 return false;
5162 std::string filter = cFilter;
5163 loginDatabase.escape_string(filter);
5164 QueryResult* result = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'"),filter.c_str());
5165 if (!result)
5167 PSendSysMessage(LANG_BANLIST_NOCHARACTER);
5168 return true;
5171 return HandleBanListHelper(result);
5174 bool ChatHandler::HandleBanListAccountCommand(const char* args)
5176 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5178 char* cFilter = strtok((char*)args, " ");
5179 std::string filter = cFilter ? cFilter : "";
5180 loginDatabase.escape_string(filter);
5182 QueryResult* result;
5184 if(filter.empty())
5186 result = loginDatabase.Query("SELECT account.id, username FROM account, account_banned"
5187 " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
5189 else
5191 result = loginDatabase.PQuery("SELECT account.id, username FROM account, account_banned"
5192 " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
5193 filter.c_str());
5196 if (!result)
5198 PSendSysMessage(LANG_BANLIST_NOACCOUNT);
5199 return true;
5202 return HandleBanListHelper(result);
5205 bool ChatHandler::HandleBanListHelper(QueryResult* result)
5207 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT);
5209 // Chat short output
5210 if(m_session)
5214 Field* fields = result->Fetch();
5215 uint32 accountid = fields[0].GetUInt32();
5217 QueryResult* banresult = loginDatabase.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid);
5218 if(banresult)
5220 Field* fields2 = banresult->Fetch();
5221 PSendSysMessage("%s",fields2[0].GetString());
5222 delete banresult;
5224 } while (result->NextRow());
5226 // Console wide output
5227 else
5229 SendSysMessage(LANG_BANLIST_ACCOUNTS);
5230 SendSysMessage("===============================================================================");
5231 SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER);
5234 SendSysMessage("-------------------------------------------------------------------------------");
5235 Field *fields = result->Fetch();
5236 uint32 account_id = fields[0].GetUInt32 ();
5238 std::string account_name;
5240 // "account" case, name can be get in same query
5241 if(result->GetFieldCount() > 1)
5242 account_name = fields[1].GetCppString();
5243 // "character" case, name need extract from another DB
5244 else
5245 sAccountMgr.GetName (account_id,account_name);
5247 // No SQL injection. id is uint32.
5248 QueryResult *banInfo = loginDatabase.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id);
5249 if (banInfo)
5251 Field *fields2 = banInfo->Fetch();
5254 time_t t_ban = fields2[0].GetUInt64();
5255 tm* aTm_ban = localtime(&t_ban);
5257 if (fields2[0].GetUInt64() == fields2[1].GetUInt64())
5259 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5260 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,
5261 fields2[2].GetString(),fields2[3].GetString());
5263 else
5265 time_t t_unban = fields2[1].GetUInt64();
5266 tm* aTm_unban = localtime(&t_unban);
5267 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5268 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,
5269 aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
5270 fields2[2].GetString(),fields2[3].GetString());
5272 }while ( banInfo->NextRow() );
5273 delete banInfo;
5275 }while( result->NextRow() );
5276 SendSysMessage("===============================================================================");
5279 delete result;
5280 return true;
5283 bool ChatHandler::HandleBanListIPCommand(const char* args)
5285 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5287 char* cFilter = strtok((char*)args, " ");
5288 std::string filter = cFilter ? cFilter : "";
5289 loginDatabase.escape_string(filter);
5291 QueryResult* result;
5293 if(filter.empty())
5295 result = loginDatabase.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5296 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
5297 " ORDER BY unbandate" );
5299 else
5301 result = loginDatabase.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5302 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")
5303 " ORDER BY unbandate",filter.c_str() );
5306 if(!result)
5308 PSendSysMessage(LANG_BANLIST_NOIP);
5309 return true;
5312 PSendSysMessage(LANG_BANLIST_MATCHINGIP);
5313 // Chat short output
5314 if(m_session)
5318 Field* fields = result->Fetch();
5319 PSendSysMessage("%s",fields[0].GetString());
5320 } while (result->NextRow());
5322 // Console wide output
5323 else
5325 SendSysMessage(LANG_BANLIST_IPS);
5326 SendSysMessage("===============================================================================");
5327 SendSysMessage(LANG_BANLIST_IPS_HEADER);
5330 SendSysMessage("-------------------------------------------------------------------------------");
5331 Field *fields = result->Fetch();
5332 time_t t_ban = fields[1].GetUInt64();
5333 tm* aTm_ban = localtime(&t_ban);
5334 if ( fields[1].GetUInt64() == fields[2].GetUInt64() )
5336 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5337 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,
5338 fields[3].GetString(), fields[4].GetString());
5340 else
5342 time_t t_unban = fields[2].GetUInt64();
5343 tm* aTm_unban = localtime(&t_unban);
5344 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5345 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,
5346 aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
5347 fields[3].GetString(), fields[4].GetString());
5349 }while( result->NextRow() );
5350 SendSysMessage("===============================================================================");
5353 delete result;
5354 return true;
5357 bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
5359 Player* pl = m_session->GetPlayer();
5361 // accept only explicitly selected target (not implicitly self targeting case)
5362 Unit* target = getSelectedUnit();
5363 if(pl->GetSelection() && target)
5365 if(target->GetTypeId()!=TYPEID_UNIT)
5367 SendSysMessage(LANG_SELECT_CREATURE);
5368 SetSentErrorMessage(true);
5369 return false;
5372 if(target->isDead())
5373 ((Creature*)target)->Respawn();
5374 return true;
5377 CellPair p(MaNGOS::ComputeCellPair(pl->GetPositionX(), pl->GetPositionY()));
5378 Cell cell(p);
5379 cell.data.Part.reserved = ALL_DISTRICT;
5380 cell.SetNoCreate();
5382 MaNGOS::RespawnDo u_do;
5383 MaNGOS::WorldObjectWorker<MaNGOS::RespawnDo> worker(pl,u_do);
5385 TypeContainerVisitor<MaNGOS::WorldObjectWorker<MaNGOS::RespawnDo>, GridTypeMapContainer > obj_worker(worker);
5386 cell.Visit(p, obj_worker, *pl->GetMap());
5388 return true;
5391 bool ChatHandler::HandleGMFlyCommand(const char* args)
5393 if (!*args)
5394 return false;
5396 Player *target = getSelectedPlayer();
5397 if (!target)
5398 target = m_session->GetPlayer();
5400 WorldPacket data(12);
5401 if (strncmp(args, "on", 3) == 0)
5402 data.SetOpcode(SMSG_MOVE_SET_CAN_FLY);
5403 else if (strncmp(args, "off", 4) == 0)
5404 data.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY);
5405 else
5407 SendSysMessage(LANG_USE_BOL);
5408 return false;
5410 data.append(target->GetPackGUID());
5411 data << uint32(0); // unknown
5412 target->SendMessageToSet(&data, true);
5413 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS, GetNameLink(target).c_str(), args);
5414 return true;
5417 bool ChatHandler::HandlePDumpLoadCommand(const char *args)
5419 if (!*args)
5420 return false;
5422 char * file = strtok((char*)args, " ");
5423 if (!file)
5424 return false;
5426 char * account = strtok(NULL, " ");
5427 if (!account)
5428 return false;
5430 std::string account_name = account;
5431 if (!AccountMgr::normalizeString(account_name))
5433 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5434 SetSentErrorMessage(true);
5435 return false;
5438 uint32 account_id = sAccountMgr.GetId(account_name);
5439 if (!account_id)
5441 account_id = atoi(account); // use original string
5442 if (!account_id)
5444 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5445 SetSentErrorMessage(true);
5446 return false;
5450 if (!sAccountMgr.GetName(account_id,account_name))
5452 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5453 SetSentErrorMessage(true);
5454 return false;
5457 char* guid_str = NULL;
5458 char* name_str = strtok(NULL, " ");
5460 std::string name;
5461 if (name_str)
5463 name = name_str;
5464 // normalize the name if specified and check if it exists
5465 if (!normalizePlayerName(name))
5467 PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
5468 SetSentErrorMessage(true);
5469 return false;
5472 if (ObjectMgr::CheckPlayerName(name,true) != CHAR_NAME_SUCCESS)
5474 PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
5475 SetSentErrorMessage(true);
5476 return false;
5479 guid_str = strtok(NULL, " ");
5482 uint32 guid = 0;
5484 if (guid_str)
5486 guid = atoi(guid_str);
5487 if (!guid)
5489 PSendSysMessage(LANG_INVALID_CHARACTER_GUID);
5490 SetSentErrorMessage(true);
5491 return false;
5494 if (sObjectMgr.GetPlayerAccountIdByGUID(guid))
5496 PSendSysMessage(LANG_CHARACTER_GUID_IN_USE,guid);
5497 SetSentErrorMessage(true);
5498 return false;
5502 switch(PlayerDumpReader().LoadDump(file, account_id, name, guid))
5504 case DUMP_SUCCESS:
5505 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS);
5506 break;
5507 case DUMP_FILE_OPEN_ERROR:
5508 PSendSysMessage(LANG_FILE_OPEN_FAIL,file);
5509 SetSentErrorMessage(true);
5510 return false;
5511 case DUMP_FILE_BROKEN:
5512 PSendSysMessage(LANG_DUMP_BROKEN,file);
5513 SetSentErrorMessage(true);
5514 return false;
5515 case DUMP_TOO_MANY_CHARS:
5516 PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL,account_name.c_str(),account_id);
5517 SetSentErrorMessage(true);
5518 return false;
5519 default:
5520 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED);
5521 SetSentErrorMessage(true);
5522 return false;
5525 return true;
5528 bool ChatHandler::HandlePDumpWriteCommand(const char *args)
5530 if (!*args)
5531 return false;
5533 char* file = strtok((char*)args, " ");
5534 char* p2 = strtok(NULL, " ");
5536 if(!file || !p2)
5537 return false;
5539 uint32 guid;
5540 // character name can't start from number
5541 if (isNumeric(p2[0]))
5542 guid = atoi(p2);
5543 else
5545 std::string name = extractPlayerNameFromLink(p2);
5546 if(name.empty())
5548 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5549 SetSentErrorMessage(true);
5550 return false;
5553 guid = sObjectMgr.GetPlayerGUIDByName(name);
5556 if(!sObjectMgr.GetPlayerAccountIdByGUID(guid))
5558 PSendSysMessage(LANG_PLAYER_NOT_FOUND);
5559 SetSentErrorMessage(true);
5560 return false;
5563 switch(PlayerDumpWriter().WriteDump(file, guid))
5565 case DUMP_SUCCESS:
5566 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS);
5567 break;
5568 case DUMP_FILE_OPEN_ERROR:
5569 PSendSysMessage(LANG_FILE_OPEN_FAIL,file);
5570 SetSentErrorMessage(true);
5571 return false;
5572 default:
5573 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED);
5574 SetSentErrorMessage(true);
5575 return false;
5578 return true;
5581 bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
5583 Unit* unit = getSelectedUnit();
5584 if(!unit)
5586 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5587 SetSentErrorMessage(true);
5588 return false;
5591 PSendSysMessage(LANG_MOVEGENS_LIST,(unit->GetTypeId()==TYPEID_PLAYER ? "Player" : "Creature" ),unit->GetGUIDLow());
5593 MotionMaster* mm = unit->GetMotionMaster();
5594 for(MotionMaster::const_iterator itr = mm->begin(); itr != mm->end(); ++itr)
5596 switch((*itr)->GetMovementGeneratorType())
5598 case IDLE_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_IDLE); break;
5599 case RANDOM_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_RANDOM); break;
5600 case WAYPOINT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_WAYPOINT); break;
5601 case ANIMAL_RANDOM_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_ANIMAL_RANDOM); break;
5602 case CONFUSED_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_CONFUSED); break;
5603 case CHASE_MOTION_TYPE:
5605 Unit* target = NULL;
5606 if(unit->GetTypeId()==TYPEID_PLAYER)
5607 target = static_cast<ChaseMovementGenerator<Player> const*>(*itr)->GetTarget();
5608 else
5609 target = static_cast<ChaseMovementGenerator<Creature> const*>(*itr)->GetTarget();
5611 if (!target)
5612 SendSysMessage(LANG_MOVEGENS_CHASE_NULL);
5613 else if (target->GetTypeId()==TYPEID_PLAYER)
5614 PSendSysMessage(LANG_MOVEGENS_CHASE_PLAYER,target->GetName(),target->GetGUIDLow());
5615 else
5616 PSendSysMessage(LANG_MOVEGENS_CHASE_CREATURE,target->GetName(),target->GetGUIDLow());
5617 break;
5619 case FOLLOW_MOTION_TYPE:
5621 Unit* target = NULL;
5622 if(unit->GetTypeId()==TYPEID_PLAYER)
5623 target = static_cast<FollowMovementGenerator<Player> const*>(*itr)->GetTarget();
5624 else
5625 target = static_cast<FollowMovementGenerator<Creature> const*>(*itr)->GetTarget();
5627 if (!target)
5628 SendSysMessage(LANG_MOVEGENS_FOLLOW_NULL);
5629 else if (target->GetTypeId()==TYPEID_PLAYER)
5630 PSendSysMessage(LANG_MOVEGENS_FOLLOW_PLAYER,target->GetName(),target->GetGUIDLow());
5631 else
5632 PSendSysMessage(LANG_MOVEGENS_FOLLOW_CREATURE,target->GetName(),target->GetGUIDLow());
5633 break;
5635 case HOME_MOTION_TYPE:
5636 if(unit->GetTypeId()==TYPEID_UNIT)
5638 float x,y,z;
5639 (*itr)->GetDestination(x,y,z);
5640 PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE,x,y,z);
5642 else
5643 SendSysMessage(LANG_MOVEGENS_HOME_PLAYER);
5644 break;
5645 case FLIGHT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FLIGHT); break;
5646 case POINT_MOTION_TYPE:
5648 float x,y,z;
5649 (*itr)->GetDestination(x,y,z);
5650 PSendSysMessage(LANG_MOVEGENS_POINT,x,y,z);
5651 break;
5653 case FLEEING_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FEAR); break;
5654 case DISTRACT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_DISTRACT); break;
5655 default:
5656 PSendSysMessage(LANG_MOVEGENS_UNKNOWN,(*itr)->GetMovementGeneratorType());
5657 break;
5660 return true;
5663 bool ChatHandler::HandleServerPLimitCommand(const char *args)
5665 if(*args)
5667 char* param = strtok((char*)args, " ");
5668 if(!param)
5669 return false;
5671 int l = strlen(param);
5673 if( strncmp(param,"player",l) == 0 )
5674 sWorld.SetPlayerLimit(-SEC_PLAYER);
5675 else if(strncmp(param,"moderator",l) == 0 )
5676 sWorld.SetPlayerLimit(-SEC_MODERATOR);
5677 else if(strncmp(param,"gamemaster",l) == 0 )
5678 sWorld.SetPlayerLimit(-SEC_GAMEMASTER);
5679 else if(strncmp(param,"administrator",l) == 0 )
5680 sWorld.SetPlayerLimit(-SEC_ADMINISTRATOR);
5681 else if(strncmp(param,"reset",l) == 0 )
5682 sWorld.SetPlayerLimit( sConfig.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT) );
5683 else
5685 int val = atoi(param);
5686 if(val < -SEC_ADMINISTRATOR) val = -SEC_ADMINISTRATOR;
5688 sWorld.SetPlayerLimit(val);
5691 // kick all low security level players
5692 if(sWorld.GetPlayerAmountLimit() > SEC_PLAYER)
5693 sWorld.KickAllLess(sWorld.GetPlayerSecurityLimit());
5696 uint32 pLimit = sWorld.GetPlayerAmountLimit();
5697 AccountTypes allowedAccountType = sWorld.GetPlayerSecurityLimit();
5698 char const* secName = "";
5699 switch(allowedAccountType)
5701 case SEC_PLAYER: secName = "Player"; break;
5702 case SEC_MODERATOR: secName = "Moderator"; break;
5703 case SEC_GAMEMASTER: secName = "Gamemaster"; break;
5704 case SEC_ADMINISTRATOR: secName = "Administrator"; break;
5705 default: secName = "<unknown>"; break;
5708 PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit,secName);
5710 return true;
5713 bool ChatHandler::HandleCastCommand(const char* args)
5715 if(!*args)
5716 return false;
5718 Unit* target = getSelectedUnit();
5720 if(!target)
5722 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5723 SetSentErrorMessage(true);
5724 return false;
5727 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5728 uint32 spell = extractSpellIdFromLink((char*)args);
5729 if(!spell)
5730 return false;
5732 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
5733 if(!spellInfo)
5734 return false;
5736 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
5738 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
5739 SetSentErrorMessage(true);
5740 return false;
5743 char* trig_str = strtok(NULL, " ");
5744 if(trig_str)
5746 int l = strlen(trig_str);
5747 if(strncmp(trig_str,"triggered",l) != 0 )
5748 return false;
5751 bool triggered = (trig_str != NULL);
5753 m_session->GetPlayer()->CastSpell(target,spell,triggered);
5755 return true;
5758 bool ChatHandler::HandleCastBackCommand(const char* args)
5760 Creature* caster = getSelectedCreature();
5762 if(!caster)
5764 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5765 SetSentErrorMessage(true);
5766 return false;
5769 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
5770 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5771 uint32 spell = extractSpellIdFromLink((char*)args);
5772 if(!spell || !sSpellStore.LookupEntry(spell))
5773 return false;
5775 char* trig_str = strtok(NULL, " ");
5776 if(trig_str)
5778 int l = strlen(trig_str);
5779 if(strncmp(trig_str,"triggered",l) != 0 )
5780 return false;
5783 bool triggered = (trig_str != NULL);
5785 caster->SetFacingToObject(m_session->GetPlayer());
5787 caster->CastSpell(m_session->GetPlayer(),spell,triggered);
5789 return true;
5792 bool ChatHandler::HandleCastDistCommand(const char* args)
5794 if(!*args)
5795 return false;
5797 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5798 uint32 spell = extractSpellIdFromLink((char*)args);
5799 if(!spell)
5800 return false;
5802 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
5803 if(!spellInfo)
5804 return false;
5806 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
5808 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
5809 SetSentErrorMessage(true);
5810 return false;
5813 char *distStr = strtok(NULL, " ");
5815 float dist = 0;
5817 if(distStr)
5818 sscanf(distStr, "%f", &dist);
5820 char* trig_str = strtok(NULL, " ");
5821 if(trig_str)
5823 int l = strlen(trig_str);
5824 if(strncmp(trig_str,"triggered",l) != 0 )
5825 return false;
5828 bool triggered = (trig_str != NULL);
5830 float x,y,z;
5831 m_session->GetPlayer()->GetClosePoint(x,y,z,dist);
5833 m_session->GetPlayer()->CastSpell(x,y,z,spell,triggered);
5834 return true;
5837 bool ChatHandler::HandleCastTargetCommand(const char* args)
5839 Creature* caster = getSelectedCreature();
5841 if(!caster)
5843 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5844 SetSentErrorMessage(true);
5845 return false;
5848 if(!caster->getVictim())
5850 SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM);
5851 SetSentErrorMessage(true);
5852 return false;
5855 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5856 uint32 spell = extractSpellIdFromLink((char*)args);
5857 if(!spell || !sSpellStore.LookupEntry(spell))
5858 return false;
5860 char* trig_str = strtok(NULL, " ");
5861 if(trig_str)
5863 int l = strlen(trig_str);
5864 if(strncmp(trig_str,"triggered",l) != 0 )
5865 return false;
5868 bool triggered = (trig_str != NULL);
5870 caster->SetFacingToObject(m_session->GetPlayer());
5872 caster->CastSpell(caster->getVictim(),spell,triggered);
5874 return true;
5878 ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
5879 Without this function 3rd party scripting library will get linking errors (unresolved external)
5880 when attempting to use the PointMovementGenerator
5882 bool ChatHandler::HandleComeToMeCommand(const char *args)
5884 Creature* caster = getSelectedCreature();
5886 if(!caster)
5888 SendSysMessage(LANG_SELECT_CREATURE);
5889 SetSentErrorMessage(true);
5890 return false;
5893 char* newFlagStr = strtok((char*)args, " ");
5895 if(!newFlagStr)
5896 return false;
5898 uint32 newFlags = atoi(newFlagStr);
5900 caster->SetMonsterMoveFlags(MonsterMovementFlags(newFlags));
5902 Player* pl = m_session->GetPlayer();
5904 caster->GetMotionMaster()->MovePoint(0, pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ());
5905 return true;
5908 bool ChatHandler::HandleCastSelfCommand(const char* args)
5910 if(!*args)
5911 return false;
5913 Unit* target = getSelectedUnit();
5915 if(!target)
5917 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5918 SetSentErrorMessage(true);
5919 return false;
5922 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5923 uint32 spell = extractSpellIdFromLink((char*)args);
5924 if(!spell)
5925 return false;
5927 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
5928 if(!spellInfo)
5929 return false;
5931 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
5933 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
5934 SetSentErrorMessage(true);
5935 return false;
5938 target->CastSpell(target,spell,false);
5940 return true;
5943 std::string GetTimeString(uint32 time)
5945 uint16 days = time / DAY, hours = (time % DAY) / HOUR, minute = (time % HOUR) / MINUTE;
5946 std::ostringstream ss;
5947 if(days) ss << days << "d ";
5948 if(hours) ss << hours << "h ";
5949 ss << minute << "m";
5950 return ss.str();
5953 bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
5955 Player* player = getSelectedPlayer();
5956 if (!player) player = m_session->GetPlayer();
5957 uint32 counter = 0;
5958 for(uint8 i = 0; i < MAX_DIFFICULTY; ++i)
5960 Player::BoundInstancesMap &binds = player->GetBoundInstances(Difficulty(i));
5961 for(Player::BoundInstancesMap::const_iterator itr = binds.begin(); itr != binds.end(); ++itr)
5963 InstanceSave *save = itr->second.save;
5964 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
5965 if (const MapEntry* entry = sMapStore.LookupEntry(itr->first))
5967 PSendSysMessage("map: %d (%s) inst: %d perm: %s diff: %d canReset: %s TTR: %s",
5968 itr->first, entry->name[m_session->GetSessionDbcLocale()], save->GetInstanceId(), itr->second.perm ? "yes" : "no",
5969 save->GetDifficulty(), save->CanReset() ? "yes" : "no", timeleft.c_str());
5971 else
5972 PSendSysMessage("bound for a nonexistant map %u", itr->first);
5973 counter++;
5976 PSendSysMessage("player binds: %d", counter);
5977 counter = 0;
5978 Group *group = player->GetGroup();
5979 if(group)
5981 for(uint8 i = 0; i < MAX_DIFFICULTY; ++i)
5983 Group::BoundInstancesMap &binds = group->GetBoundInstances(Difficulty(i));
5984 for(Group::BoundInstancesMap::const_iterator itr = binds.begin(); itr != binds.end(); ++itr)
5986 InstanceSave *save = itr->second.save;
5987 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
5988 if (const MapEntry* entry = sMapStore.LookupEntry(itr->first))
5990 PSendSysMessage("map: %d (%s) inst: %d perm: %s diff: %d canReset: %s TTR: %s",
5991 itr->first, entry->name[m_session->GetSessionDbcLocale()], save->GetInstanceId(), itr->second.perm ? "yes" : "no",
5992 save->GetDifficulty(), save->CanReset() ? "yes" : "no", timeleft.c_str());
5994 else
5995 PSendSysMessage("bound for a nonexistant map %u", itr->first);
5996 counter++;
6000 PSendSysMessage("group binds: %d", counter);
6002 return true;
6005 bool ChatHandler::HandleInstanceUnbindCommand(const char* args)
6007 if(!*args)
6008 return false;
6010 Player* player = getSelectedPlayer();
6011 if (!player)
6012 player = m_session->GetPlayer();
6013 uint32 counter = 0;
6014 uint32 mapid = 0;
6015 bool got_map = false;
6017 if (strncmp(args,"all",strlen(args)) != 0)
6019 if(!isNumeric(args[0]))
6020 return false;
6022 got_map = true;
6023 mapid = atoi(args);
6026 for(uint8 i = 0; i < MAX_DIFFICULTY; ++i)
6028 Player::BoundInstancesMap &binds = player->GetBoundInstances(Difficulty(i));
6029 for(Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end();)
6031 if (got_map && mapid != itr->first)
6033 ++itr;
6034 continue;
6036 if(itr->first != player->GetMapId())
6038 InstanceSave *save = itr->second.save;
6039 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
6041 if (const MapEntry* entry = sMapStore.LookupEntry(itr->first))
6043 PSendSysMessage("unbinding map: %d (%s) inst: %d perm: %s diff: %d canReset: %s TTR: %s",
6044 itr->first, entry->name[m_session->GetSessionDbcLocale()], save->GetInstanceId(), itr->second.perm ? "yes" : "no",
6045 save->GetDifficulty(), save->CanReset() ? "yes" : "no", timeleft.c_str());
6047 else
6048 PSendSysMessage("bound for a nonexistant map %u", itr->first);
6049 player->UnbindInstance(itr, Difficulty(i));
6050 counter++;
6052 else
6053 ++itr;
6056 PSendSysMessage("instances unbound: %d", counter);
6057 return true;
6060 bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
6062 PSendSysMessage("instances loaded: %d", sMapMgr.GetNumInstances());
6063 PSendSysMessage("players in instances: %d", sMapMgr.GetNumPlayersInInstances());
6064 PSendSysMessage("instance saves: %d", sInstanceSaveMgr.GetNumInstanceSaves());
6065 PSendSysMessage("players bound: %d", sInstanceSaveMgr.GetNumBoundPlayersTotal());
6066 PSendSysMessage("groups bound: %d", sInstanceSaveMgr.GetNumBoundGroupsTotal());
6067 return true;
6070 bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
6072 Player* pl = m_session->GetPlayer();
6074 Map* map = pl->GetMap();
6075 if (!map->IsDungeon())
6077 PSendSysMessage("Map is not a dungeon.");
6078 SetSentErrorMessage(true);
6079 return false;
6082 if (!((InstanceMap*)map)->GetInstanceData())
6084 PSendSysMessage("Map has no instance data.");
6085 SetSentErrorMessage(true);
6086 return false;
6089 ((InstanceMap*)map)->GetInstanceData()->SaveToDB();
6090 return true;
6093 /// Display the list of GMs
6094 bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
6096 ///- Get the accounts with GM Level >0
6097 QueryResult *result = loginDatabase.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
6098 if(result)
6100 SendSysMessage(LANG_GMLIST);
6101 SendSysMessage("========================");
6102 SendSysMessage(LANG_GMLIST_HEADER);
6103 SendSysMessage("========================");
6105 ///- Circle through them. Display username and GM level
6108 Field *fields = result->Fetch();
6109 PSendSysMessage("|%15s|%6s|", fields[0].GetString(),fields[1].GetString());
6110 }while( result->NextRow() );
6112 PSendSysMessage("========================");
6113 delete result;
6115 else
6116 PSendSysMessage(LANG_GMLIST_EMPTY);
6117 return true;
6120 /// Define the 'Message of the day' for the realm
6121 bool ChatHandler::HandleServerSetMotdCommand(const char* args)
6123 sWorld.SetMotd(args);
6124 PSendSysMessage(LANG_MOTD_NEW, args);
6125 return true;
6128 /// Set/Unset the expansion level for an account
6129 bool ChatHandler::HandleAccountSetAddonCommand(const char* args)
6131 ///- Get the command line arguments
6132 char *szAcc = strtok((char*)args," ");
6133 char *szExp = strtok(NULL," ");
6135 if(!szAcc)
6136 return false;
6138 std::string account_name;
6139 uint32 account_id;
6141 if (!szExp)
6143 Player* player = getSelectedPlayer();
6144 if (!player)
6145 return false;
6147 account_id = player->GetSession()->GetAccountId();
6148 sAccountMgr.GetName(account_id,account_name);
6149 szExp = szAcc;
6151 else
6153 ///- Convert Account name to Upper Format
6154 account_name = szAcc;
6155 if (!AccountMgr::normalizeString(account_name))
6157 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
6158 SetSentErrorMessage(true);
6159 return false;
6162 account_id = sAccountMgr.GetId(account_name);
6163 if (!account_id)
6165 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
6166 SetSentErrorMessage(true);
6167 return false;
6172 // Let set addon state only for lesser (strong) security level
6173 // or to self account
6174 if (m_session && m_session->GetAccountId () != account_id &&
6175 HasLowerSecurityAccount (NULL,account_id,true))
6176 return false;
6178 int lev=atoi(szExp); //get int anyway (0 if error)
6179 if(lev < 0)
6180 return false;
6182 // No SQL injection
6183 loginDatabase.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev,account_id);
6184 PSendSysMessage(LANG_ACCOUNT_SETADDON,account_name.c_str(),account_id,lev);
6185 return true;
6188 //Send items by mail
6189 bool ChatHandler::HandleSendItemsCommand(const char* args)
6191 // format: name "subject text" "mail text" item1[:count1] item2[:count2] ... item12[:count12]
6192 Player* receiver;
6193 uint64 receiver_guid;
6194 std::string receiver_name;
6195 if(!extractPlayerTarget((char*)args,&receiver,&receiver_guid,&receiver_name))
6196 return false;
6198 char* tail1 = strtok(NULL, "");
6199 if(!tail1)
6200 return false;
6202 char* msgSubject = extractQuotedArg(tail1);
6203 if (!msgSubject)
6204 return false;
6206 char* tail2 = strtok(NULL, "");
6207 if(!tail2)
6208 return false;
6210 char* msgText = extractQuotedArg(tail2);
6211 if (!msgText)
6212 return false;
6214 // msgSubject, msgText isn't NUL after prev. check
6215 std::string subject = msgSubject;
6216 std::string text = msgText;
6218 // extract items
6219 typedef std::pair<uint32,uint32> ItemPair;
6220 typedef std::list< ItemPair > ItemPairs;
6221 ItemPairs items;
6223 // get all tail string
6224 char* tail = strtok(NULL, "");
6226 // get from tail next item str
6227 while(char* itemStr = strtok(tail, " "))
6229 // and get new tail
6230 tail = strtok(NULL, "");
6232 // parse item str
6233 char* itemIdStr = strtok(itemStr, ":");
6234 char* itemCountStr = strtok(NULL, " ");
6236 uint32 item_id = atoi(itemIdStr);
6237 if(!item_id)
6238 return false;
6240 ItemPrototype const* item_proto = ObjectMgr::GetItemPrototype(item_id);
6241 if(!item_proto)
6243 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
6244 SetSentErrorMessage(true);
6245 return false;
6248 uint32 item_count = itemCountStr ? atoi(itemCountStr) : 1;
6249 if (item_count < 1 || (item_proto->MaxCount > 0 && item_count > uint32(item_proto->MaxCount)))
6251 PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT, item_count,item_id);
6252 SetSentErrorMessage(true);
6253 return false;
6256 while(item_count > item_proto->GetMaxStackSize())
6258 items.push_back(ItemPair(item_id,item_proto->GetMaxStackSize()));
6259 item_count -= item_proto->GetMaxStackSize();
6262 items.push_back(ItemPair(item_id,item_count));
6264 if(items.size() > MAX_MAIL_ITEMS)
6266 PSendSysMessage(LANG_COMMAND_MAIL_ITEMS_LIMIT, MAX_MAIL_ITEMS);
6267 SetSentErrorMessage(true);
6268 return false;
6272 // from console show not existed sender
6273 MailSender sender(MAIL_NORMAL,m_session ? m_session->GetPlayer()->GetGUIDLow() : 0, MAIL_STATIONERY_GM);
6275 uint32 itemTextId = !text.empty() ? sObjectMgr.CreateItemText( text ) : 0;
6277 // fill mail
6278 MailDraft draft(subject, itemTextId);
6280 for(ItemPairs::const_iterator itr = items.begin(); itr != items.end(); ++itr)
6282 if(Item* item = Item::CreateItem(itr->first,itr->second,m_session ? m_session->GetPlayer() : 0))
6284 item->SaveToDB(); // save for prevent lost at next mail load, if send fail then item will deleted
6285 draft.AddItem(item);
6289 draft.SendMailTo(MailReceiver(receiver,GUID_LOPART(receiver_guid)), sender);
6291 std::string nameLink = playerLink(receiver_name);
6292 PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
6293 return true;
6296 ///Send money by mail
6297 bool ChatHandler::HandleSendMoneyCommand(const char* args)
6299 /// format: name "subject text" "mail text" money
6301 Player* receiver;
6302 uint64 receiver_guid;
6303 std::string receiver_name;
6304 if(!extractPlayerTarget((char*)args,&receiver,&receiver_guid,&receiver_name))
6305 return false;
6307 char* tail1 = strtok(NULL, "");
6308 if (!tail1)
6309 return false;
6311 char* msgSubject = extractQuotedArg(tail1);
6312 if (!msgSubject)
6313 return false;
6315 char* tail2 = strtok(NULL, "");
6316 if (!tail2)
6317 return false;
6319 char* msgText = extractQuotedArg(tail2);
6320 if (!msgText)
6321 return false;
6323 char* money_str = strtok(NULL, "");
6324 int32 money = money_str ? atoi(money_str) : 0;
6325 if (money <= 0)
6326 return false;
6328 // msgSubject, msgText isn't NUL after prev. check
6329 std::string subject = msgSubject;
6330 std::string text = msgText;
6332 // from console show not existed sender
6333 MailSender sender(MAIL_NORMAL,m_session ? m_session->GetPlayer()->GetGUIDLow() : 0, MAIL_STATIONERY_GM);
6335 uint32 itemTextId = !text.empty() ? sObjectMgr.CreateItemText( text ) : 0;
6337 MailDraft(subject, itemTextId)
6338 .AddMoney(money)
6339 .SendMailTo(MailReceiver(receiver,GUID_LOPART(receiver_guid)),sender);
6341 std::string nameLink = playerLink(receiver_name);
6342 PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
6343 return true;
6346 /// Send a message to a player in game
6347 bool ChatHandler::HandleSendMessageCommand(const char* args)
6349 ///- Find the player
6350 Player *rPlayer;
6351 if(!extractPlayerTarget((char*)args,&rPlayer))
6352 return false;
6354 char* msg_str = strtok(NULL, "");
6355 if(!msg_str)
6356 return false;
6358 ///- Check that he is not logging out.
6359 if(rPlayer->GetSession()->isLogingOut())
6361 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6362 SetSentErrorMessage(true);
6363 return false;
6366 ///- Send the message
6367 //Use SendAreaTriggerMessage for fastest delivery.
6368 rPlayer->GetSession()->SendAreaTriggerMessage("%s", msg_str);
6369 rPlayer->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
6371 //Confirmation message
6372 std::string nameLink = GetNameLink(rPlayer);
6373 PSendSysMessage(LANG_SENDMESSAGE,nameLink.c_str(),msg_str);
6374 return true;
6377 bool ChatHandler::HandleFlushArenaPointsCommand(const char * /*args*/)
6379 sBattleGroundMgr.DistributeArenaPoints();
6380 return true;
6383 bool ChatHandler::HandleModifyGenderCommand(const char *args)
6385 if(!*args)
6386 return false;
6388 Player *player = getSelectedPlayer();
6390 if(!player)
6392 PSendSysMessage(LANG_PLAYER_NOT_FOUND);
6393 SetSentErrorMessage(true);
6394 return false;
6397 PlayerInfo const* info = sObjectMgr.GetPlayerInfo(player->getRace(), player->getClass());
6398 if(!info)
6399 return false;
6401 char const* gender_str = (char*)args;
6402 int gender_len = strlen(gender_str);
6404 Gender gender;
6406 if(!strncmp(gender_str, "male", gender_len)) // MALE
6408 if(player->getGender() == GENDER_MALE)
6409 return true;
6411 gender = GENDER_MALE;
6413 else if (!strncmp(gender_str, "female", gender_len)) // FEMALE
6415 if(player->getGender() == GENDER_FEMALE)
6416 return true;
6418 gender = GENDER_FEMALE;
6420 else
6422 SendSysMessage(LANG_MUST_MALE_OR_FEMALE);
6423 SetSentErrorMessage(true);
6424 return false;
6427 // Set gender
6428 player->SetByteValue(UNIT_FIELD_BYTES_0, 2, gender);
6429 player->SetByteValue(PLAYER_BYTES_3, 0, gender);
6431 // Change display ID
6432 player->InitDisplayIds();
6434 char const* gender_full = gender ? "female" : "male";
6436 PSendSysMessage(LANG_YOU_CHANGE_GENDER, GetNameLink(player).c_str(), gender_full);
6438 if (needReportToTarget(player))
6439 ChatHandler(player).PSendSysMessage(LANG_YOUR_GENDER_CHANGED, gender_full, GetNameLink().c_str());
6441 return true;