[7645] Fixed problems wit temporary unsummoned pets and cleanup code.
[AHbot.git] / src / game / Level3.cpp
blob95a26dde51e950ee6d2edc2077304e635aed15ba
1 /*
2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "Common.h"
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
23 #include "World.h"
24 #include "ObjectMgr.h"
25 #include "AccountMgr.h"
26 #include "PlayerDump.h"
27 #include "SpellMgr.h"
28 #include "Player.h"
29 #include "Opcodes.h"
30 #include "GameObject.h"
31 #include "Chat.h"
32 #include "Log.h"
33 #include "Guild.h"
34 #include "ObjectAccessor.h"
35 #include "MapManager.h"
36 #include "ScriptCalls.h"
37 #include "Language.h"
38 #include "GridNotifiersImpl.h"
39 #include "CellImpl.h"
40 #include "Weather.h"
41 #include "PointMovementGenerator.h"
42 #include "TargetedMovementGenerator.h"
43 #include "SkillDiscovery.h"
44 #include "SkillExtraItems.h"
45 #include "SystemConfig.h"
46 #include "Config/ConfigEnv.h"
47 #include "Util.h"
48 #include "ItemEnchantmentMgr.h"
49 #include "BattleGroundMgr.h"
50 #include "InstanceSaveMgr.h"
51 #include "InstanceData.h"
53 //reload commands
54 bool ChatHandler::HandleReloadAllCommand(const char*)
56 HandleReloadSkillFishingBaseLevelCommand("");
58 HandleReloadAllAchievementCommand("");
59 HandleReloadAllAreaCommand("");
60 HandleReloadAllLootCommand("");
61 HandleReloadAllNpcCommand("");
62 HandleReloadAllQuestCommand("");
63 HandleReloadAllSpellCommand("");
64 HandleReloadAllItemCommand("");
65 HandleReloadAllLocalesCommand("");
67 HandleReloadCommandCommand("");
68 HandleReloadReservedNameCommand("");
69 HandleReloadMangosStringCommand("");
70 HandleReloadGameTeleCommand("");
71 return true;
74 bool ChatHandler::HandleReloadAllAchievementCommand(const char*)
76 HandleReloadAchievementCriteriaDataCommand("");
77 HandleReloadAchievementRewardCommand("");
78 return true;
81 bool ChatHandler::HandleReloadAllAreaCommand(const char*)
83 //HandleReloadQuestAreaTriggersCommand(""); -- reloaded in HandleReloadAllQuestCommand
84 HandleReloadAreaTriggerTeleportCommand("");
85 HandleReloadAreaTriggerTavernCommand("");
86 HandleReloadGameGraveyardZoneCommand("");
87 return true;
90 bool ChatHandler::HandleReloadAllLootCommand(const char*)
92 sLog.outString( "Re-Loading Loot Tables..." );
93 LoadLootTables();
94 SendGlobalSysMessage("DB tables `*_loot_template` reloaded.");
95 return true;
98 bool ChatHandler::HandleReloadAllNpcCommand(const char* /*args*/)
100 HandleReloadNpcGossipCommand("a");
101 HandleReloadNpcOptionCommand("a");
102 HandleReloadNpcTrainerCommand("a");
103 HandleReloadNpcVendorCommand("a");
104 HandleReloadPointsOfInterestCommand("a");
105 return true;
108 bool ChatHandler::HandleReloadAllQuestCommand(const char* /*args*/)
110 HandleReloadQuestAreaTriggersCommand("a");
111 HandleReloadQuestTemplateCommand("a");
113 sLog.outString( "Re-Loading Quests Relations..." );
114 objmgr.LoadQuestRelations();
115 SendGlobalSysMessage("DB tables `*_questrelation` and `*_involvedrelation` reloaded.");
116 return true;
119 bool ChatHandler::HandleReloadAllScriptsCommand(const char*)
121 if(sWorld.IsScriptScheduled())
123 PSendSysMessage("DB scripts used currently, please attempt reload later.");
124 SetSentErrorMessage(true);
125 return false;
128 sLog.outString( "Re-Loading Scripts..." );
129 HandleReloadGameObjectScriptsCommand("a");
130 HandleReloadEventScriptsCommand("a");
131 HandleReloadQuestEndScriptsCommand("a");
132 HandleReloadQuestStartScriptsCommand("a");
133 HandleReloadSpellScriptsCommand("a");
134 SendGlobalSysMessage("DB tables `*_scripts` reloaded.");
135 HandleReloadDbScriptStringCommand("a");
136 return true;
139 bool ChatHandler::HandleReloadAllSpellCommand(const char*)
141 HandleReloadSkillDiscoveryTemplateCommand("a");
142 HandleReloadSkillExtraItemTemplateCommand("a");
143 HandleReloadSpellAffectCommand("a");
144 HandleReloadSpellAreaCommand("a");
145 HandleReloadSpellChainCommand("a");
146 HandleReloadSpellElixirCommand("a");
147 HandleReloadSpellLearnSpellCommand("a");
148 HandleReloadSpellProcEventCommand("a");
149 HandleReloadSpellBonusesCommand("a");
150 HandleReloadSpellScriptTargetCommand("a");
151 HandleReloadSpellTargetPositionCommand("a");
152 HandleReloadSpellThreatsCommand("a");
153 HandleReloadSpellPetAurasCommand("a");
154 return true;
157 bool ChatHandler::HandleReloadAllItemCommand(const char*)
159 HandleReloadPageTextsCommand("a");
160 HandleReloadItemEnchantementsCommand("a");
161 return true;
164 bool ChatHandler::HandleReloadAllLocalesCommand(const char* /*args*/)
166 HandleReloadLocalesAchievementRewardCommand("a");
167 HandleReloadLocalesCreatureCommand("a");
168 HandleReloadLocalesGameobjectCommand("a");
169 HandleReloadLocalesItemCommand("a");
170 HandleReloadLocalesNpcTextCommand("a");
171 HandleReloadLocalesPageTextCommand("a");
172 HandleReloadLocalesPointsOfInterestCommand("a");
173 HandleReloadLocalesQuestCommand("a");
174 return true;
177 bool ChatHandler::HandleReloadConfigCommand(const char* /*args*/)
179 sLog.outString( "Re-Loading config settings..." );
180 sWorld.LoadConfigSettings(true);
181 SendGlobalSysMessage("World config settings reloaded.");
182 return true;
185 bool ChatHandler::HandleReloadAchievementCriteriaDataCommand(const char*)
187 sLog.outString( "Re-Loading Additional Achievement Criteria Data..." );
188 achievementmgr.LoadAchievementCriteriaData();
189 SendGlobalSysMessage("DB table `achievement_criteria_data` reloaded.");
190 return true;
193 bool ChatHandler::HandleReloadAchievementRewardCommand(const char*)
195 sLog.outString( "Re-Loading Achievement Reward Data..." );
196 achievementmgr.LoadRewards();
197 SendGlobalSysMessage("DB table `achievement_reward` reloaded.");
198 return true;
201 bool ChatHandler::HandleReloadAreaTriggerTavernCommand(const char*)
203 sLog.outString( "Re-Loading Tavern Area Triggers..." );
204 objmgr.LoadTavernAreaTriggers();
205 SendGlobalSysMessage("DB table `areatrigger_tavern` reloaded.");
206 return true;
209 bool ChatHandler::HandleReloadAreaTriggerTeleportCommand(const char*)
211 sLog.outString( "Re-Loading AreaTrigger teleport definitions..." );
212 objmgr.LoadAreaTriggerTeleports();
213 SendGlobalSysMessage("DB table `areatrigger_teleport` reloaded.");
214 return true;
217 bool ChatHandler::HandleReloadCommandCommand(const char*)
219 load_command_table = true;
220 SendGlobalSysMessage("DB table `command` will be reloaded at next chat command use.");
221 return true;
224 bool ChatHandler::HandleReloadCreatureQuestRelationsCommand(const char*)
226 sLog.outString( "Loading Quests Relations... (`creature_questrelation`)" );
227 objmgr.LoadCreatureQuestRelations();
228 SendGlobalSysMessage("DB table `creature_questrelation` (creature quest givers) reloaded.");
229 return true;
232 bool ChatHandler::HandleReloadCreatureQuestInvRelationsCommand(const char*)
234 sLog.outString( "Loading Quests Relations... (`creature_involvedrelation`)" );
235 objmgr.LoadCreatureInvolvedRelations();
236 SendGlobalSysMessage("DB table `creature_involvedrelation` (creature quest takers) reloaded.");
237 return true;
240 bool ChatHandler::HandleReloadGOQuestRelationsCommand(const char*)
242 sLog.outString( "Loading Quests Relations... (`gameobject_questrelation`)" );
243 objmgr.LoadGameobjectQuestRelations();
244 SendGlobalSysMessage("DB table `gameobject_questrelation` (gameobject quest givers) reloaded.");
245 return true;
248 bool ChatHandler::HandleReloadGOQuestInvRelationsCommand(const char*)
250 sLog.outString( "Loading Quests Relations... (`gameobject_involvedrelation`)" );
251 objmgr.LoadGameobjectInvolvedRelations();
252 SendGlobalSysMessage("DB table `gameobject_involvedrelation` (gameobject quest takers) reloaded.");
253 return true;
256 bool ChatHandler::HandleReloadQuestAreaTriggersCommand(const char*)
258 sLog.outString( "Re-Loading Quest Area Triggers..." );
259 objmgr.LoadQuestAreaTriggers();
260 SendGlobalSysMessage("DB table `areatrigger_involvedrelation` (quest area triggers) reloaded.");
261 return true;
264 bool ChatHandler::HandleReloadQuestTemplateCommand(const char*)
266 sLog.outString( "Re-Loading Quest Templates..." );
267 objmgr.LoadQuests();
268 SendGlobalSysMessage("DB table `quest_template` (quest definitions) reloaded.");
270 /// dependent also from `gameobject` but this table not reloaded anyway
271 sLog.outString( "Re-Loading GameObjects for quests..." );
272 objmgr.LoadGameObjectForQuests();
273 SendGlobalSysMessage("Data GameObjects for quests reloaded.");
274 return true;
277 bool ChatHandler::HandleReloadLootTemplatesCreatureCommand(const char*)
279 sLog.outString( "Re-Loading Loot Tables... (`creature_loot_template`)" );
280 LoadLootTemplates_Creature();
281 LootTemplates_Creature.CheckLootRefs();
282 SendGlobalSysMessage("DB table `creature_loot_template` reloaded.");
283 return true;
286 bool ChatHandler::HandleReloadLootTemplatesDisenchantCommand(const char*)
288 sLog.outString( "Re-Loading Loot Tables... (`disenchant_loot_template`)" );
289 LoadLootTemplates_Disenchant();
290 LootTemplates_Disenchant.CheckLootRefs();
291 SendGlobalSysMessage("DB table `disenchant_loot_template` reloaded.");
292 return true;
295 bool ChatHandler::HandleReloadLootTemplatesFishingCommand(const char*)
297 sLog.outString( "Re-Loading Loot Tables... (`fishing_loot_template`)" );
298 LoadLootTemplates_Fishing();
299 LootTemplates_Fishing.CheckLootRefs();
300 SendGlobalSysMessage("DB table `fishing_loot_template` reloaded.");
301 return true;
304 bool ChatHandler::HandleReloadLootTemplatesGameobjectCommand(const char*)
306 sLog.outString( "Re-Loading Loot Tables... (`gameobject_loot_template`)" );
307 LoadLootTemplates_Gameobject();
308 LootTemplates_Gameobject.CheckLootRefs();
309 SendGlobalSysMessage("DB table `gameobject_loot_template` reloaded.");
310 return true;
313 bool ChatHandler::HandleReloadLootTemplatesItemCommand(const char*)
315 sLog.outString( "Re-Loading Loot Tables... (`item_loot_template`)" );
316 LoadLootTemplates_Item();
317 LootTemplates_Item.CheckLootRefs();
318 SendGlobalSysMessage("DB table `item_loot_template` reloaded.");
319 return true;
322 bool ChatHandler::HandleReloadLootTemplatesMillingCommand(const char*)
324 sLog.outString( "Re-Loading Loot Tables... (`milling_loot_template`)" );
325 LoadLootTemplates_Milling();
326 LootTemplates_Milling.CheckLootRefs();
327 SendGlobalSysMessage("DB table `milling_loot_template` reloaded.");
328 return true;
331 bool ChatHandler::HandleReloadLootTemplatesPickpocketingCommand(const char*)
333 sLog.outString( "Re-Loading Loot Tables... (`pickpocketing_loot_template`)" );
334 LoadLootTemplates_Pickpocketing();
335 LootTemplates_Pickpocketing.CheckLootRefs();
336 SendGlobalSysMessage("DB table `pickpocketing_loot_template` reloaded.");
337 return true;
340 bool ChatHandler::HandleReloadLootTemplatesProspectingCommand(const char*)
342 sLog.outString( "Re-Loading Loot Tables... (`prospecting_loot_template`)" );
343 LoadLootTemplates_Prospecting();
344 LootTemplates_Prospecting.CheckLootRefs();
345 SendGlobalSysMessage("DB table `prospecting_loot_template` reloaded.");
346 return true;
349 bool ChatHandler::HandleReloadLootTemplatesQuestMailCommand(const char*)
351 sLog.outString( "Re-Loading Loot Tables... (`quest_mail_loot_template`)" );
352 LoadLootTemplates_QuestMail();
353 LootTemplates_QuestMail.CheckLootRefs();
354 SendGlobalSysMessage("DB table `quest_mail_loot_template` reloaded.");
355 return true;
358 bool ChatHandler::HandleReloadLootTemplatesReferenceCommand(const char*)
360 sLog.outString( "Re-Loading Loot Tables... (`reference_loot_template`)" );
361 LoadLootTemplates_Reference();
362 SendGlobalSysMessage("DB table `reference_loot_template` reloaded.");
363 return true;
366 bool ChatHandler::HandleReloadLootTemplatesSkinningCommand(const char*)
368 sLog.outString( "Re-Loading Loot Tables... (`skinning_loot_template`)" );
369 LoadLootTemplates_Skinning();
370 LootTemplates_Skinning.CheckLootRefs();
371 SendGlobalSysMessage("DB table `skinning_loot_template` reloaded.");
372 return true;
375 bool ChatHandler::HandleReloadLootTemplatesSpellCommand(const char*)
377 sLog.outString( "Re-Loading Loot Tables... (`spell_loot_template`)" );
378 LoadLootTemplates_Spell();
379 LootTemplates_Spell.CheckLootRefs();
380 SendGlobalSysMessage("DB table `spell_loot_template` reloaded.");
381 return true;
384 bool ChatHandler::HandleReloadMangosStringCommand(const char*)
386 sLog.outString( "Re-Loading mangos_string Table!" );
387 objmgr.LoadMangosStrings();
388 SendGlobalSysMessage("DB table `mangos_string` reloaded.");
389 return true;
392 bool ChatHandler::HandleReloadNpcOptionCommand(const char*)
394 sLog.outString( "Re-Loading `npc_option` Table!" );
395 objmgr.LoadNpcOptions();
396 SendGlobalSysMessage("DB table `npc_option` reloaded.");
397 return true;
400 bool ChatHandler::HandleReloadNpcGossipCommand(const char*)
402 sLog.outString( "Re-Loading `npc_gossip` Table!" );
403 objmgr.LoadNpcTextId();
404 SendGlobalSysMessage("DB table `npc_gossip` reloaded.");
405 return true;
408 bool ChatHandler::HandleReloadNpcTrainerCommand(const char*)
410 sLog.outString( "Re-Loading `npc_trainer` Table!" );
411 objmgr.LoadTrainerSpell();
412 SendGlobalSysMessage("DB table `npc_trainer` reloaded.");
413 return true;
416 bool ChatHandler::HandleReloadNpcVendorCommand(const char*)
418 sLog.outString( "Re-Loading `npc_vendor` Table!" );
419 objmgr.LoadVendors();
420 SendGlobalSysMessage("DB table `npc_vendor` reloaded.");
421 return true;
424 bool ChatHandler::HandleReloadPointsOfInterestCommand(const char*)
426 sLog.outString( "Re-Loading `points_of_interest` Table!" );
427 objmgr.LoadPointsOfInterest();
428 SendGlobalSysMessage("DB table `points_of_interest` reloaded.");
429 return true;
432 bool ChatHandler::HandleReloadReservedNameCommand(const char*)
434 sLog.outString( "Loading ReservedNames... (`reserved_name`)" );
435 objmgr.LoadReservedPlayersNames();
436 SendGlobalSysMessage("DB table `reserved_name` (player reserved names) reloaded.");
437 return true;
440 bool ChatHandler::HandleReloadSkillDiscoveryTemplateCommand(const char* /*args*/)
442 sLog.outString( "Re-Loading Skill Discovery Table..." );
443 LoadSkillDiscoveryTable();
444 SendGlobalSysMessage("DB table `skill_discovery_template` (recipes discovered at crafting) reloaded.");
445 return true;
448 bool ChatHandler::HandleReloadSkillExtraItemTemplateCommand(const char* /*args*/)
450 sLog.outString( "Re-Loading Skill Extra Item Table..." );
451 LoadSkillExtraItemTable();
452 SendGlobalSysMessage("DB table `skill_extra_item_template` (extra item creation when crafting) reloaded.");
453 return true;
456 bool ChatHandler::HandleReloadSkillFishingBaseLevelCommand(const char* /*args*/)
458 sLog.outString( "Re-Loading Skill Fishing base level requirements..." );
459 objmgr.LoadFishingBaseSkillLevel();
460 SendGlobalSysMessage("DB table `skill_fishing_base_level` (fishing base level for zone/subzone) reloaded.");
461 return true;
464 bool ChatHandler::HandleReloadSpellAffectCommand(const char*)
466 sLog.outString( "Re-Loading SpellAffect definitions..." );
467 spellmgr.LoadSpellAffects();
468 SendGlobalSysMessage("DB table `spell_affect` (spell mods apply requirements) reloaded.");
469 return true;
472 bool ChatHandler::HandleReloadSpellAreaCommand(const char*)
474 sLog.outString( "Re-Loading SpellArea Data..." );
475 spellmgr.LoadSpellAreas();
476 SendGlobalSysMessage("DB table `spell_area` (spell dependences from area/quest/auras state) reloaded.");
477 return true;
480 bool ChatHandler::HandleReloadSpellChainCommand(const char*)
482 sLog.outString( "Re-Loading Spell Chain Data... " );
483 spellmgr.LoadSpellChains();
484 SendGlobalSysMessage("DB table `spell_chain` (spell ranks) reloaded.");
485 return true;
488 bool ChatHandler::HandleReloadSpellElixirCommand(const char*)
490 sLog.outString( "Re-Loading Spell Elixir types..." );
491 spellmgr.LoadSpellElixirs();
492 SendGlobalSysMessage("DB table `spell_elixir` (spell elixir types) reloaded.");
493 return true;
496 bool ChatHandler::HandleReloadSpellLearnSpellCommand(const char*)
498 sLog.outString( "Re-Loading Spell Learn Spells..." );
499 spellmgr.LoadSpellLearnSpells();
500 SendGlobalSysMessage("DB table `spell_learn_spell` reloaded.");
501 return true;
504 bool ChatHandler::HandleReloadSpellProcEventCommand(const char*)
506 sLog.outString( "Re-Loading Spell Proc Event conditions..." );
507 spellmgr.LoadSpellProcEvents();
508 SendGlobalSysMessage("DB table `spell_proc_event` (spell proc trigger requirements) reloaded.");
509 return true;
512 bool ChatHandler::HandleReloadSpellBonusesCommand(const char*)
514 sLog.outString( "Re-Loading Spell Bonus Data..." );
515 spellmgr.LoadSpellBonusess();
516 SendGlobalSysMessage("DB table `spell_bonus_data` (spell damage/healing coefficients) reloaded.");
517 return true;
520 bool ChatHandler::HandleReloadSpellScriptTargetCommand(const char*)
522 sLog.outString( "Re-Loading SpellsScriptTarget..." );
523 spellmgr.LoadSpellScriptTarget();
524 SendGlobalSysMessage("DB table `spell_script_target` (spell targets selection in case specific creature/GO requirements) reloaded.");
525 return true;
528 bool ChatHandler::HandleReloadSpellTargetPositionCommand(const char*)
530 sLog.outString( "Re-Loading Spell target coordinates..." );
531 spellmgr.LoadSpellTargetPositions();
532 SendGlobalSysMessage("DB table `spell_target_position` (destination coordinates for spell targets) reloaded.");
533 return true;
536 bool ChatHandler::HandleReloadSpellThreatsCommand(const char*)
538 sLog.outString( "Re-Loading Aggro Spells Definitions...");
539 spellmgr.LoadSpellThreats();
540 SendGlobalSysMessage("DB table `spell_threat` (spell aggro definitions) reloaded.");
541 return true;
544 bool ChatHandler::HandleReloadSpellPetAurasCommand(const char*)
546 sLog.outString( "Re-Loading Spell pet auras...");
547 spellmgr.LoadSpellPetAuras();
548 SendGlobalSysMessage("DB table `spell_pet_auras` reloaded.");
549 return true;
552 bool ChatHandler::HandleReloadPageTextsCommand(const char*)
554 sLog.outString( "Re-Loading Page Texts..." );
555 objmgr.LoadPageTexts();
556 SendGlobalSysMessage("DB table `page_texts` reloaded.");
557 return true;
560 bool ChatHandler::HandleReloadItemEnchantementsCommand(const char*)
562 sLog.outString( "Re-Loading Item Random Enchantments Table..." );
563 LoadRandomEnchantmentsTable();
564 SendGlobalSysMessage("DB table `item_enchantment_template` reloaded.");
565 return true;
568 bool ChatHandler::HandleReloadGameObjectScriptsCommand(const char* arg)
570 if(sWorld.IsScriptScheduled())
572 SendSysMessage("DB scripts used currently, please attempt reload later.");
573 SetSentErrorMessage(true);
574 return false;
577 if(*arg!='a')
578 sLog.outString( "Re-Loading Scripts from `gameobject_scripts`...");
580 objmgr.LoadGameObjectScripts();
582 if(*arg!='a')
583 SendGlobalSysMessage("DB table `gameobject_scripts` reloaded.");
585 return true;
588 bool ChatHandler::HandleReloadEventScriptsCommand(const char* arg)
590 if(sWorld.IsScriptScheduled())
592 SendSysMessage("DB scripts used currently, please attempt reload later.");
593 SetSentErrorMessage(true);
594 return false;
597 if(*arg!='a')
598 sLog.outString( "Re-Loading Scripts from `event_scripts`...");
600 objmgr.LoadEventScripts();
602 if(*arg!='a')
603 SendGlobalSysMessage("DB table `event_scripts` reloaded.");
605 return true;
608 bool ChatHandler::HandleReloadQuestEndScriptsCommand(const char* arg)
610 if(sWorld.IsScriptScheduled())
612 SendSysMessage("DB scripts used currently, please attempt reload later.");
613 SetSentErrorMessage(true);
614 return false;
617 if(*arg!='a')
618 sLog.outString( "Re-Loading Scripts from `quest_end_scripts`...");
620 objmgr.LoadQuestEndScripts();
622 if(*arg!='a')
623 SendGlobalSysMessage("DB table `quest_end_scripts` reloaded.");
625 return true;
628 bool ChatHandler::HandleReloadQuestStartScriptsCommand(const char* arg)
630 if(sWorld.IsScriptScheduled())
632 SendSysMessage("DB scripts used currently, please attempt reload later.");
633 SetSentErrorMessage(true);
634 return false;
637 if(*arg!='a')
638 sLog.outString( "Re-Loading Scripts from `quest_start_scripts`...");
640 objmgr.LoadQuestStartScripts();
642 if(*arg!='a')
643 SendGlobalSysMessage("DB table `quest_start_scripts` reloaded.");
645 return true;
648 bool ChatHandler::HandleReloadSpellScriptsCommand(const char* arg)
650 if(sWorld.IsScriptScheduled())
652 SendSysMessage("DB scripts used currently, please attempt reload later.");
653 SetSentErrorMessage(true);
654 return false;
657 if(*arg!='a')
658 sLog.outString( "Re-Loading Scripts from `spell_scripts`...");
660 objmgr.LoadSpellScripts();
662 if(*arg!='a')
663 SendGlobalSysMessage("DB table `spell_scripts` reloaded.");
665 return true;
668 bool ChatHandler::HandleReloadDbScriptStringCommand(const char* arg)
670 sLog.outString( "Re-Loading Script strings from `db_script_string`...");
671 objmgr.LoadDbScriptStrings();
672 SendGlobalSysMessage("DB table `db_script_string` reloaded.");
673 return true;
676 bool ChatHandler::HandleReloadGameGraveyardZoneCommand(const char* /*arg*/)
678 sLog.outString( "Re-Loading Graveyard-zone links...");
680 objmgr.LoadGraveyardZones();
682 SendGlobalSysMessage("DB table `game_graveyard_zone` reloaded.");
684 return true;
687 bool ChatHandler::HandleReloadGameTeleCommand(const char* /*arg*/)
689 sLog.outString( "Re-Loading Game Tele coordinates...");
691 objmgr.LoadGameTele();
693 SendGlobalSysMessage("DB table `game_tele` reloaded.");
695 return true;
698 bool ChatHandler::HandleReloadLocalesAchievementRewardCommand(const char*)
700 sLog.outString( "Re-Loading Locales Achievement Reward Data..." );
701 achievementmgr.LoadRewardLocales();
702 SendGlobalSysMessage("DB table `locales_achievement_reward` reloaded.");
703 return true;
706 bool ChatHandler::HandleReloadLocalesCreatureCommand(const char* /*arg*/)
708 sLog.outString( "Re-Loading Locales Creature ...");
709 objmgr.LoadCreatureLocales();
710 SendGlobalSysMessage("DB table `locales_creature` reloaded.");
711 return true;
714 bool ChatHandler::HandleReloadLocalesGameobjectCommand(const char* /*arg*/)
716 sLog.outString( "Re-Loading Locales Gameobject ... ");
717 objmgr.LoadGameObjectLocales();
718 SendGlobalSysMessage("DB table `locales_gameobject` reloaded.");
719 return true;
722 bool ChatHandler::HandleReloadLocalesItemCommand(const char* /*arg*/)
724 sLog.outString( "Re-Loading Locales Item ... ");
725 objmgr.LoadItemLocales();
726 SendGlobalSysMessage("DB table `locales_item` reloaded.");
727 return true;
730 bool ChatHandler::HandleReloadLocalesNpcTextCommand(const char* /*arg*/)
732 sLog.outString( "Re-Loading Locales NPC Text ... ");
733 objmgr.LoadNpcTextLocales();
734 SendGlobalSysMessage("DB table `locales_npc_text` reloaded.");
735 return true;
738 bool ChatHandler::HandleReloadLocalesPageTextCommand(const char* /*arg*/)
740 sLog.outString( "Re-Loading Locales Page Text ... ");
741 objmgr.LoadPageTextLocales();
742 SendGlobalSysMessage("DB table `locales_page_text` reloaded.");
743 return true;
746 bool ChatHandler::HandleReloadLocalesPointsOfInterestCommand(const char* /*arg*/)
748 sLog.outString( "Re-Loading Locales Points Of Interest ... ");
749 objmgr.LoadPointOfInterestLocales();
750 SendGlobalSysMessage("DB table `locales_points_of_interest` reloaded.");
751 return true;
754 bool ChatHandler::HandleReloadLocalesQuestCommand(const char* /*arg*/)
756 sLog.outString( "Re-Loading Locales Quest ... ");
757 objmgr.LoadQuestLocales();
758 SendGlobalSysMessage("DB table `locales_quest` reloaded.");
759 return true;
762 bool ChatHandler::HandleLoadScriptsCommand(const char* args)
764 if(!LoadScriptingModule(args)) return true;
766 sWorld.SendWorldText(LANG_SCRIPTS_RELOADED);
767 return true;
770 bool ChatHandler::HandleAccountSetGmLevelCommand(const char* args)
772 char* arg1 = strtok((char*)args, " ");
773 if( !arg1 )
774 return false;
776 /// must be NULL if targeted syntax and must be not nULL if not targeted
777 char* arg2 = strtok(NULL, " ");
779 std::string targetAccountName;
780 uint32 targetAccountId = 0;
782 /// only target player different from self allowed (if targetPlayer!=NULL then not console)
783 Player* targetPlayer = getSelectedPlayer();
784 if(targetPlayer && m_session->GetPlayer()!=targetPlayer)
786 /// wrong command syntax or unexpected targeting
787 if(arg2)
788 return false;
790 /// security level expected in arg2 after this if.
791 arg2 = arg1;
793 targetAccountId = targetPlayer->GetSession()->GetAccountId();
794 accmgr.GetName(targetAccountId, targetAccountName);
796 else
798 /// wrong command syntax (second arg expected)
799 if(!arg2)
800 return false;
802 targetAccountName = arg1;
803 if(!AccountMgr::normilizeString(targetAccountName))
805 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,targetAccountName.c_str());
806 SetSentErrorMessage(true);
807 return false;
810 targetAccountId = accmgr.GetId(targetAccountName);
811 if(!targetAccountId)
813 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,targetAccountName.c_str());
814 SetSentErrorMessage(true);
815 return false;
819 int32 gm = (int32)atoi(arg2);
820 if ( gm < SEC_PLAYER || gm > SEC_ADMINISTRATOR )
822 SendSysMessage(LANG_BAD_VALUE);
823 SetSentErrorMessage(true);
824 return false;
827 /// can set security level only for target with less security and to less security that we have
828 /// This will reject self apply by specify account name
829 if(HasLowerSecurityAccount(NULL,targetAccountId,true))
830 return false;
832 /// account can't set security to same or grater level, need more power GM or console
833 uint32 plSecurity = m_session ? m_session->GetSecurity() : SEC_CONSOLE;
834 if (uint32(gm) >= plSecurity )
836 SendSysMessage(LANG_YOURS_SECURITY_IS_LOW);
837 SetSentErrorMessage(true);
838 return false;
841 // This will prevent self apply by self target or no target
842 if(targetPlayer && m_session->GetPlayer()!=targetPlayer)
844 ChatHandler(targetPlayer).PSendSysMessage(LANG_YOURS_SECURITY_CHANGED,GetNameLink().c_str(), gm);
845 targetPlayer->GetSession()->SetSecurity(gm);
848 PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetAccountName.c_str(), gm);
849 loginDatabase.PExecute("UPDATE account SET gmlevel = '%i' WHERE id = '%u'", gm, targetAccountId);
851 return true;
854 /// Set password for account
855 bool ChatHandler::HandleAccountSetPasswordCommand(const char* args)
857 if(!*args)
858 return false;
860 ///- Get the command line arguments
861 char *szAccount = strtok ((char*)args," ");
862 char *szPassword1 = strtok (NULL," ");
863 char *szPassword2 = strtok (NULL," ");
865 if (!szAccount||!szPassword1 || !szPassword2)
866 return false;
868 std::string account_name = szAccount;
869 if(!AccountMgr::normilizeString(account_name))
871 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
872 SetSentErrorMessage(true);
873 return false;
876 uint32 targetAccountId = accmgr.GetId(account_name);
877 if (!targetAccountId)
879 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
880 SetSentErrorMessage(true);
881 return false;
884 /// can set password only for target with less security
885 /// This is also reject self apply in fact
886 if(HasLowerSecurityAccount (NULL,targetAccountId,true))
887 return false;
889 if (strcmp(szPassword1,szPassword2))
891 SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH);
892 SetSentErrorMessage (true);
893 return false;
896 AccountOpResult result = accmgr.ChangePassword(targetAccountId, szPassword1);
898 switch(result)
900 case AOR_OK:
901 SendSysMessage(LANG_COMMAND_PASSWORD);
902 break;
903 case AOR_NAME_NOT_EXIST:
904 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
905 SetSentErrorMessage(true);
906 return false;
907 case AOR_PASS_TOO_LONG:
908 SendSysMessage(LANG_PASSWORD_TOO_LONG);
909 SetSentErrorMessage(true);
910 return false;
911 default:
912 SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD);
913 SetSentErrorMessage(true);
914 return false;
917 return true;
920 bool ChatHandler::HandleMaxSkillCommand(const char* /*args*/)
922 Player* SelectedPlayer = getSelectedPlayer();
923 if(!SelectedPlayer)
925 SendSysMessage(LANG_NO_CHAR_SELECTED);
926 SetSentErrorMessage(true);
927 return false;
930 // each skills that have max skill value dependent from level seted to current level max skill value
931 SelectedPlayer->UpdateSkillsToMaxSkillsForLevel();
932 return true;
935 bool ChatHandler::HandleSetSkillCommand(const char* args)
937 // number or [name] Shift-click form |color|Hskill:skill_id|h[name]|h|r
938 char* skill_p = extractKeyFromLink((char*)args,"Hskill");
939 if(!skill_p)
940 return false;
942 char *level_p = strtok (NULL, " ");
944 if( !level_p)
945 return false;
947 char *max_p = strtok (NULL, " ");
949 int32 skill = atoi(skill_p);
950 if (skill <= 0)
952 PSendSysMessage(LANG_INVALID_SKILL_ID, skill);
953 SetSentErrorMessage(true);
954 return false;
957 int32 level = atol (level_p);
959 Player * target = getSelectedPlayer();
960 if(!target)
962 SendSysMessage(LANG_NO_CHAR_SELECTED);
963 SetSentErrorMessage(true);
964 return false;
967 SkillLineEntry const* sl = sSkillLineStore.LookupEntry(skill);
968 if(!sl)
970 PSendSysMessage(LANG_INVALID_SKILL_ID, skill);
971 SetSentErrorMessage(true);
972 return false;
975 std::string tNameLink = GetNameLink(target);
977 if(!target->GetSkillValue(skill))
979 PSendSysMessage(LANG_SET_SKILL_ERROR, tNameLink.c_str(), skill, sl->name[0]);
980 SetSentErrorMessage(true);
981 return false;
984 int32 max = max_p ? atol (max_p) : target->GetPureMaxSkillValue(skill);
986 if( level <= 0 || level > max || max <= 0 )
987 return false;
989 target->SetSkill(skill, level, max);
990 PSendSysMessage(LANG_SET_SKILL, skill, sl->name[0], tNameLink.c_str(), level, max);
992 return true;
995 bool ChatHandler::HandleUnLearnCommand(const char* args)
997 if (!*args)
998 return false;
1000 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
1001 uint32 spell_id = extractSpellIdFromLink((char*)args);
1002 if(!spell_id)
1003 return false;
1005 char const* allStr = strtok(NULL," ");
1006 bool allRanks = allStr ? (strncmp(allStr, "all", strlen(allStr)) == 0) : false;
1008 Player* target = getSelectedPlayer();
1009 if(!target)
1011 SendSysMessage(LANG_NO_CHAR_SELECTED);
1012 SetSentErrorMessage(true);
1013 return false;
1016 if(allRanks)
1017 spell_id = spellmgr.GetFirstSpellInChain (spell_id);
1019 if (target->HasSpell(spell_id))
1020 target->removeSpell(spell_id,false,!allRanks);
1021 else
1022 SendSysMessage(LANG_FORGET_SPELL);
1024 return true;
1027 bool ChatHandler::HandleCooldownCommand(const char* args)
1029 Player* target = getSelectedPlayer();
1030 if(!target)
1032 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1033 SetSentErrorMessage(true);
1034 return false;
1037 std::string tNameLink = GetNameLink(target);
1039 if (!*args)
1041 target->RemoveAllSpellCooldown();
1042 PSendSysMessage(LANG_REMOVEALL_COOLDOWN, tNameLink.c_str());
1044 else
1046 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1047 uint32 spell_id = extractSpellIdFromLink((char*)args);
1048 if(!spell_id)
1049 return false;
1051 if(!sSpellStore.LookupEntry(spell_id))
1053 PSendSysMessage(LANG_UNKNOWN_SPELL, target==m_session->GetPlayer() ? GetMangosString(LANG_YOU) : tNameLink.c_str());
1054 SetSentErrorMessage(true);
1055 return false;
1058 WorldPacket data( SMSG_CLEAR_COOLDOWN, (4+8) );
1059 data << uint32(spell_id);
1060 data << uint64(target->GetGUID());
1061 target->GetSession()->SendPacket(&data);
1062 target->RemoveSpellCooldown(spell_id);
1063 PSendSysMessage(LANG_REMOVE_COOLDOWN, spell_id, target==m_session->GetPlayer() ? GetMangosString(LANG_YOU) : tNameLink.c_str());
1065 return true;
1068 bool ChatHandler::HandleLearnAllCommand(const char* /*args*/)
1070 static const char *allSpellList[] =
1072 "3365",
1073 "6233",
1074 "6247",
1075 "6246",
1076 "6477",
1077 "6478",
1078 "22810",
1079 "8386",
1080 "21651",
1081 "21652",
1082 "522",
1083 "7266",
1084 "8597",
1085 "2479",
1086 "22027",
1087 "6603",
1088 "5019",
1089 "133",
1090 "168",
1091 "227",
1092 "5009",
1093 "9078",
1094 "668",
1095 "203",
1096 "20599",
1097 "20600",
1098 "81",
1099 "20597",
1100 "20598",
1101 "20864",
1102 "1459",
1103 "5504",
1104 "587",
1105 "5143",
1106 "118",
1107 "5505",
1108 "597",
1109 "604",
1110 "1449",
1111 "1460",
1112 "2855",
1113 "1008",
1114 "475",
1115 "5506",
1116 "1463",
1117 "12824",
1118 "8437",
1119 "990",
1120 "5145",
1121 "8450",
1122 "1461",
1123 "759",
1124 "8494",
1125 "8455",
1126 "8438",
1127 "6127",
1128 "8416",
1129 "6129",
1130 "8451",
1131 "8495",
1132 "8439",
1133 "3552",
1134 "8417",
1135 "10138",
1136 "12825",
1137 "10169",
1138 "10156",
1139 "10144",
1140 "10191",
1141 "10201",
1142 "10211",
1143 "10053",
1144 "10173",
1145 "10139",
1146 "10145",
1147 "10192",
1148 "10170",
1149 "10202",
1150 "10054",
1151 "10174",
1152 "10193",
1153 "12826",
1154 "2136",
1155 "143",
1156 "145",
1157 "2137",
1158 "2120",
1159 "3140",
1160 "543",
1161 "2138",
1162 "2948",
1163 "8400",
1164 "2121",
1165 "8444",
1166 "8412",
1167 "8457",
1168 "8401",
1169 "8422",
1170 "8445",
1171 "8402",
1172 "8413",
1173 "8458",
1174 "8423",
1175 "8446",
1176 "10148",
1177 "10197",
1178 "10205",
1179 "10149",
1180 "10215",
1181 "10223",
1182 "10206",
1183 "10199",
1184 "10150",
1185 "10216",
1186 "10207",
1187 "10225",
1188 "10151",
1189 "116",
1190 "205",
1191 "7300",
1192 "122",
1193 "837",
1194 "10",
1195 "7301",
1196 "7322",
1197 "6143",
1198 "120",
1199 "865",
1200 "8406",
1201 "6141",
1202 "7302",
1203 "8461",
1204 "8407",
1205 "8492",
1206 "8427",
1207 "8408",
1208 "6131",
1209 "7320",
1210 "10159",
1211 "8462",
1212 "10185",
1213 "10179",
1214 "10160",
1215 "10180",
1216 "10219",
1217 "10186",
1218 "10177",
1219 "10230",
1220 "10181",
1221 "10161",
1222 "10187",
1223 "10220",
1224 "2018",
1225 "2663",
1226 "12260",
1227 "2660",
1228 "3115",
1229 "3326",
1230 "2665",
1231 "3116",
1232 "2738",
1233 "3293",
1234 "2661",
1235 "3319",
1236 "2662",
1237 "9983",
1238 "8880",
1239 "2737",
1240 "2739",
1241 "7408",
1242 "3320",
1243 "2666",
1244 "3323",
1245 "3324",
1246 "3294",
1247 "22723",
1248 "23219",
1249 "23220",
1250 "23221",
1251 "23228",
1252 "23338",
1253 "10788",
1254 "10790",
1255 "5611",
1256 "5016",
1257 "5609",
1258 "2060",
1259 "10963",
1260 "10964",
1261 "10965",
1262 "22593",
1263 "22594",
1264 "596",
1265 "996",
1266 "499",
1267 "768",
1268 "17002",
1269 "1448",
1270 "1082",
1271 "16979",
1272 "1079",
1273 "5215",
1274 "20484",
1275 "5221",
1276 "15590",
1277 "17007",
1278 "6795",
1279 "6807",
1280 "5487",
1281 "1446",
1282 "1066",
1283 "5421",
1284 "3139",
1285 "779",
1286 "6811",
1287 "6808",
1288 "1445",
1289 "5216",
1290 "1737",
1291 "5222",
1292 "5217",
1293 "1432",
1294 "6812",
1295 "9492",
1296 "5210",
1297 "3030",
1298 "1441",
1299 "783",
1300 "6801",
1301 "20739",
1302 "8944",
1303 "9491",
1304 "22569",
1305 "5226",
1306 "6786",
1307 "1433",
1308 "8973",
1309 "1828",
1310 "9495",
1311 "9006",
1312 "6794",
1313 "8993",
1314 "5203",
1315 "16914",
1316 "6784",
1317 "9635",
1318 "22830",
1319 "20722",
1320 "9748",
1321 "6790",
1322 "9753",
1323 "9493",
1324 "9752",
1325 "9831",
1326 "9825",
1327 "9822",
1328 "5204",
1329 "5401",
1330 "22831",
1331 "6793",
1332 "9845",
1333 "17401",
1334 "9882",
1335 "9868",
1336 "20749",
1337 "9893",
1338 "9899",
1339 "9895",
1340 "9832",
1341 "9902",
1342 "9909",
1343 "22832",
1344 "9828",
1345 "9851",
1346 "9883",
1347 "9869",
1348 "17406",
1349 "17402",
1350 "9914",
1351 "20750",
1352 "9897",
1353 "9848",
1354 "3127",
1355 "107",
1356 "204",
1357 "9116",
1358 "2457",
1359 "78",
1360 "18848",
1361 "331",
1362 "403",
1363 "2098",
1364 "1752",
1365 "11278",
1366 "11288",
1367 "11284",
1368 "6461",
1369 "2344",
1370 "2345",
1371 "6463",
1372 "2346",
1373 "2352",
1374 "775",
1375 "1434",
1376 "1612",
1377 "71",
1378 "2468",
1379 "2458",
1380 "2467",
1381 "7164",
1382 "7178",
1383 "7367",
1384 "7376",
1385 "7381",
1386 "21156",
1387 "5209",
1388 "3029",
1389 "5201",
1390 "9849",
1391 "9850",
1392 "20719",
1393 "22568",
1394 "22827",
1395 "22828",
1396 "22829",
1397 "6809",
1398 "8972",
1399 "9005",
1400 "9823",
1401 "9827",
1402 "6783",
1403 "9913",
1404 "6785",
1405 "6787",
1406 "9866",
1407 "9867",
1408 "9894",
1409 "9896",
1410 "6800",
1411 "8992",
1412 "9829",
1413 "9830",
1414 "780",
1415 "769",
1416 "6749",
1417 "6750",
1418 "9755",
1419 "9754",
1420 "9908",
1421 "20745",
1422 "20742",
1423 "20747",
1424 "20748",
1425 "9746",
1426 "9745",
1427 "9880",
1428 "9881",
1429 "5391",
1430 "842",
1431 "3025",
1432 "3031",
1433 "3287",
1434 "3329",
1435 "1945",
1436 "3559",
1437 "4933",
1438 "4934",
1439 "4935",
1440 "4936",
1441 "5142",
1442 "5390",
1443 "5392",
1444 "5404",
1445 "5420",
1446 "6405",
1447 "7293",
1448 "7965",
1449 "8041",
1450 "8153",
1451 "9033",
1452 "9034",
1453 //"9036", problems with ghost state
1454 "16421",
1455 "21653",
1456 "22660",
1457 "5225",
1458 "9846",
1459 "2426",
1460 "5916",
1461 "6634",
1462 //"6718", phasing stealth, annoying for learn all case.
1463 "6719",
1464 "8822",
1465 "9591",
1466 "9590",
1467 "10032",
1468 "17746",
1469 "17747",
1470 "8203",
1471 "11392",
1472 "12495",
1473 "16380",
1474 "23452",
1475 "4079",
1476 "4996",
1477 "4997",
1478 "4998",
1479 "4999",
1480 "5000",
1481 "6348",
1482 "6349",
1483 "6481",
1484 "6482",
1485 "6483",
1486 "6484",
1487 "11362",
1488 "11410",
1489 "11409",
1490 "12510",
1491 "12509",
1492 "12885",
1493 "13142",
1494 "21463",
1495 "23460",
1496 "11421",
1497 "11416",
1498 "11418",
1499 "1851",
1500 "10059",
1501 "11423",
1502 "11417",
1503 "11422",
1504 "11419",
1505 "11424",
1506 "11420",
1507 "27",
1508 "31",
1509 "33",
1510 "34",
1511 "35",
1512 "15125",
1513 "21127",
1514 "22950",
1515 "1180",
1516 "201",
1517 "12593",
1518 "12842",
1519 "16770",
1520 "6057",
1521 "12051",
1522 "18468",
1523 "12606",
1524 "12605",
1525 "18466",
1526 "12502",
1527 "12043",
1528 "15060",
1529 "12042",
1530 "12341",
1531 "12848",
1532 "12344",
1533 "12353",
1534 "18460",
1535 "11366",
1536 "12350",
1537 "12352",
1538 "13043",
1539 "11368",
1540 "11113",
1541 "12400",
1542 "11129",
1543 "16766",
1544 "12573",
1545 "15053",
1546 "12580",
1547 "12475",
1548 "12472",
1549 "12953",
1550 "12488",
1551 "11189",
1552 "12985",
1553 "12519",
1554 "16758",
1555 "11958",
1556 "12490",
1557 "11426",
1558 "3565",
1559 "3562",
1560 "18960",
1561 "3567",
1562 "3561",
1563 "3566",
1564 "3563",
1565 "1953",
1566 "2139",
1567 "12505",
1568 "13018",
1569 "12522",
1570 "12523",
1571 "5146",
1572 "5144",
1573 "5148",
1574 "8419",
1575 "8418",
1576 "10213",
1577 "10212",
1578 "10157",
1579 "12524",
1580 "13019",
1581 "12525",
1582 "13020",
1583 "12526",
1584 "13021",
1585 "18809",
1586 "13031",
1587 "13032",
1588 "13033",
1589 "4036",
1590 "3920",
1591 "3919",
1592 "3918",
1593 "7430",
1594 "3922",
1595 "3923",
1596 "7411",
1597 "7418",
1598 "7421",
1599 "13262",
1600 "7412",
1601 "7415",
1602 "7413",
1603 "7416",
1604 "13920",
1605 "13921",
1606 "7745",
1607 "7779",
1608 "7428",
1609 "7457",
1610 "7857",
1611 "7748",
1612 "7426",
1613 "13421",
1614 "7454",
1615 "13378",
1616 "7788",
1617 "14807",
1618 "14293",
1619 "7795",
1620 "6296",
1621 "20608",
1622 "755",
1623 "444",
1624 "427",
1625 "428",
1626 "442",
1627 "447",
1628 "3578",
1629 "3581",
1630 "19027",
1631 "3580",
1632 "665",
1633 "3579",
1634 "3577",
1635 "6755",
1636 "3576",
1637 "2575",
1638 "2577",
1639 "2578",
1640 "2579",
1641 "2580",
1642 "2656",
1643 "2657",
1644 "2576",
1645 "3564",
1646 "10248",
1647 "8388",
1648 "2659",
1649 "14891",
1650 "3308",
1651 "3307",
1652 "10097",
1653 "2658",
1654 "3569",
1655 "16153",
1656 "3304",
1657 "10098",
1658 "4037",
1659 "3929",
1660 "3931",
1661 "3926",
1662 "3924",
1663 "3930",
1664 "3977",
1665 "3925",
1666 "136",
1667 "228",
1668 "5487",
1669 "43",
1670 "202",
1674 int loop = 0;
1675 while(strcmp(allSpellList[loop], "0"))
1677 uint32 spell = atol((char*)allSpellList[loop++]);
1679 if (m_session->GetPlayer()->HasSpell(spell))
1680 continue;
1682 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
1683 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
1685 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
1686 continue;
1689 m_session->GetPlayer()->learnSpell(spell,false);
1692 SendSysMessage(LANG_COMMAND_LEARN_MANY_SPELLS);
1694 return true;
1697 bool ChatHandler::HandleLearnAllGMCommand(const char* /*args*/)
1699 static const char *gmSpellList[] =
1701 "24347", // Become A Fish, No Breath Bar
1702 "35132", // Visual Boom
1703 "38488", // Attack 4000-8000 AOE
1704 "38795", // Attack 2000 AOE + Slow Down 90%
1705 "15712", // Attack 200
1706 "1852", // GM Spell Silence
1707 "31899", // Kill
1708 "31924", // Kill
1709 "29878", // Kill My Self
1710 "26644", // More Kill
1712 "28550", //Invisible 24
1713 "23452", //Invisible + Target
1717 uint16 gmSpellIter = 0;
1718 while( strcmp(gmSpellList[gmSpellIter], "0") )
1720 uint32 spell = atol((char*)gmSpellList[gmSpellIter++]);
1722 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
1723 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
1725 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
1726 continue;
1729 m_session->GetPlayer()->learnSpell(spell,false);
1732 SendSysMessage(LANG_LEARNING_GM_SKILLS);
1733 return true;
1736 bool ChatHandler::HandleLearnAllMyClassCommand(const char* /*args*/)
1738 HandleLearnAllMySpellsCommand("");
1739 HandleLearnAllMyTalentsCommand("");
1740 return true;
1743 bool ChatHandler::HandleLearnAllMySpellsCommand(const char* /*args*/)
1745 ChrClassesEntry const* clsEntry = sChrClassesStore.LookupEntry(m_session->GetPlayer()->getClass());
1746 if(!clsEntry)
1747 return true;
1748 uint32 family = clsEntry->spellfamily;
1750 for (uint32 i = 0; i < sSpellStore.GetNumRows(); i++)
1752 SpellEntry const *spellInfo = sSpellStore.LookupEntry(i);
1753 if(!spellInfo)
1754 continue;
1756 // skip server-side/triggered spells
1757 if(spellInfo->spellLevel==0)
1758 continue;
1760 // skip wrong class/race skills
1761 if(!m_session->GetPlayer()->IsSpellFitByClassAndRace(spellInfo->Id))
1762 continue;
1764 // skip other spell families
1765 if( spellInfo->SpellFamilyName != family)
1766 continue;
1768 // skip spells with first rank learned as talent (and all talents then also)
1769 uint32 first_rank = spellmgr.GetFirstSpellInChain(spellInfo->Id);
1770 if(GetTalentSpellCost(first_rank) > 0 )
1771 continue;
1773 // skip broken spells
1774 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
1775 continue;
1777 m_session->GetPlayer()->learnSpell(i,false);
1780 SendSysMessage(LANG_COMMAND_LEARN_CLASS_SPELLS);
1781 return true;
1784 bool ChatHandler::HandleLearnAllMyTalentsCommand(const char* /*args*/)
1786 Player* player = m_session->GetPlayer();
1787 uint32 classMask = player->getClassMask();
1789 for (uint32 i = 0; i < sTalentStore.GetNumRows(); i++)
1791 TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
1792 if(!talentInfo)
1793 continue;
1795 TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentInfo->TalentTab );
1796 if(!talentTabInfo)
1797 continue;
1799 if( (classMask & talentTabInfo->ClassMask) == 0 )
1800 continue;
1802 // search highest talent rank
1803 uint32 spellid = 0;
1805 for(int rank = MAX_TALENT_RANK-1; rank >= 0; --rank)
1807 if(talentInfo->RankID[rank]!=0)
1809 spellid = talentInfo->RankID[rank];
1810 break;
1814 if(!spellid) // ??? none spells in talent
1815 continue;
1817 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellid);
1818 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
1819 continue;
1821 // learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
1822 player->learnSpellHighRank(spellid);
1825 SendSysMessage(LANG_COMMAND_LEARN_CLASS_TALENTS);
1826 return true;
1829 bool ChatHandler::HandleLearnAllMyPetTalentsCommand(const char* /*args*/)
1831 Player* player = m_session->GetPlayer();
1833 Pet* pet = player->GetPet();
1834 if(!pet)
1836 SendSysMessage(LANG_NO_PET_FOUND);
1837 SetSentErrorMessage(true);
1838 return false;
1841 CreatureInfo const *ci = pet->GetCreatureInfo();
1842 if(!ci)
1844 SendSysMessage(LANG_WRONG_PET_TYPE);
1845 SetSentErrorMessage(true);
1846 return false;
1849 CreatureFamilyEntry const *pet_family = sCreatureFamilyStore.LookupEntry(ci->family);
1850 if(!pet_family)
1852 SendSysMessage(LANG_WRONG_PET_TYPE);
1853 SetSentErrorMessage(true);
1854 return false;
1857 if(pet_family->petTalentType < 0) // not hunter pet
1859 SendSysMessage(LANG_WRONG_PET_TYPE);
1860 SetSentErrorMessage(true);
1861 return false;
1864 for (uint32 i = 0; i < sTalentStore.GetNumRows(); i++)
1866 TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
1867 if(!talentInfo)
1868 continue;
1870 TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentInfo->TalentTab );
1871 if(!talentTabInfo)
1872 continue;
1874 // prevent learn talent for different family (cheating)
1875 if(((1 << pet_family->petTalentType) & talentTabInfo->petTalentMask)==0)
1876 continue;
1878 // search highest talent rank
1879 uint32 spellid = 0;
1881 for(int rank = MAX_TALENT_RANK-1; rank >= 0; --rank)
1883 if(talentInfo->RankID[rank]!=0)
1885 spellid = talentInfo->RankID[rank];
1886 break;
1890 if(!spellid) // ??? none spells in talent
1891 continue;
1893 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellid);
1894 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
1895 continue;
1897 // learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
1898 pet->learnSpellHighRank(spellid);
1901 SendSysMessage(LANG_COMMAND_LEARN_PET_TALENTS);
1902 return true;
1905 bool ChatHandler::HandleLearnAllLangCommand(const char* /*args*/)
1907 // skipping UNIVERSAL language (0)
1908 for(int i = 1; i < LANGUAGES_COUNT; ++i)
1909 m_session->GetPlayer()->learnSpell(lang_description[i].spell_id,false);
1911 SendSysMessage(LANG_COMMAND_LEARN_ALL_LANG);
1912 return true;
1915 bool ChatHandler::HandleLearnAllDefaultCommand(const char* args)
1917 Player *player = NULL;
1918 if (*args)
1920 std::string name = extractPlayerNameFromLink((char*)args);
1921 if(name.empty())
1923 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1924 SetSentErrorMessage(true);
1925 return false;
1928 player = objmgr.GetPlayer(name.c_str());
1930 else
1931 player = getSelectedPlayer();
1933 if(!player)
1935 SendSysMessage(LANG_NO_CHAR_SELECTED);
1936 SetSentErrorMessage(true);
1937 return false;
1940 player->learnDefaultSpells();
1941 player->learnQuestRewardedSpells();
1943 PSendSysMessage(LANG_COMMAND_LEARN_ALL_DEFAULT_AND_QUEST,GetNameLink(player).c_str());
1944 return true;
1947 bool ChatHandler::HandleLearnCommand(const char* args)
1949 Player* targetPlayer = getSelectedPlayer();
1951 if(!targetPlayer)
1953 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1954 SetSentErrorMessage(true);
1955 return false;
1958 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1959 uint32 spell = extractSpellIdFromLink((char*)args);
1960 if(!spell || !sSpellStore.LookupEntry(spell))
1961 return false;
1963 char const* allStr = strtok(NULL," ");
1964 bool allRanks = allStr ? (strncmp(allStr, "all", strlen(allStr)) == 0) : false;
1966 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
1967 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
1969 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
1970 SetSentErrorMessage(true);
1971 return false;
1974 if (!allRanks && targetPlayer->HasSpell(spell))
1976 if(targetPlayer == m_session->GetPlayer())
1977 SendSysMessage(LANG_YOU_KNOWN_SPELL);
1978 else
1979 PSendSysMessage(LANG_TARGET_KNOWN_SPELL,GetNameLink(targetPlayer).c_str());
1980 SetSentErrorMessage(true);
1981 return false;
1984 if(allRanks)
1985 targetPlayer->learnSpellHighRank(spell);
1986 else
1987 targetPlayer->learnSpell(spell,false);
1989 return true;
1992 bool ChatHandler::HandleAddItemCommand(const char* args)
1994 if (!*args)
1995 return false;
1997 uint32 itemId = 0;
1999 if(args[0]=='[') // [name] manual form
2001 char* citemName = citemName = strtok((char*)args, "]");
2003 if(citemName && citemName[0])
2005 std::string itemName = citemName+1;
2006 WorldDatabase.escape_string(itemName);
2007 QueryResult *result = WorldDatabase.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName.c_str());
2008 if (!result)
2010 PSendSysMessage(LANG_COMMAND_COULDNOTFIND, citemName+1);
2011 SetSentErrorMessage(true);
2012 return false;
2014 itemId = result->Fetch()->GetUInt16();
2015 delete result;
2017 else
2018 return false;
2020 else // item_id or [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r
2022 char* cId = extractKeyFromLink((char*)args,"Hitem");
2023 if(!cId)
2024 return false;
2025 itemId = atol(cId);
2028 char* ccount = strtok(NULL, " ");
2030 int32 count = 1;
2032 if (ccount)
2033 count = strtol(ccount, NULL, 10);
2035 if (count == 0)
2036 count = 1;
2038 Player* pl = m_session->GetPlayer();
2039 Player* plTarget = getSelectedPlayer();
2040 if(!plTarget)
2041 plTarget = pl;
2043 sLog.outDetail(GetMangosString(LANG_ADDITEM), itemId, count);
2045 ItemPrototype const *pProto = objmgr.GetItemPrototype(itemId);
2046 if(!pProto)
2048 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, itemId);
2049 SetSentErrorMessage(true);
2050 return false;
2053 //Subtract
2054 if (count < 0)
2056 plTarget->DestroyItemCount(itemId, -count, true, false);
2057 PSendSysMessage(LANG_REMOVEITEM, itemId, -count, GetNameLink(plTarget).c_str());
2058 return true;
2061 //Adding items
2062 uint32 noSpaceForCount = 0;
2064 // check space and find places
2065 ItemPosCountVec dest;
2066 uint8 msg = plTarget->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, itemId, count, &noSpaceForCount );
2067 if( msg != EQUIP_ERR_OK ) // convert to possible store amount
2068 count -= noSpaceForCount;
2070 if( count == 0 || dest.empty()) // can't add any
2072 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount );
2073 SetSentErrorMessage(true);
2074 return false;
2077 Item* item = plTarget->StoreNewItem( dest, itemId, true, Item::GenerateItemRandomPropertyId(itemId));
2079 // remove binding (let GM give it to another player later)
2080 if(pl==plTarget)
2081 for(ItemPosCountVec::const_iterator itr = dest.begin(); itr != dest.end(); ++itr)
2082 if(Item* item1 = pl->GetItemByPos(itr->pos))
2083 item1->SetBinding( false );
2085 if(count > 0 && item)
2087 pl->SendNewItem(item,count,false,true);
2088 if(pl!=plTarget)
2089 plTarget->SendNewItem(item,count,true,false);
2092 if(noSpaceForCount > 0)
2093 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount);
2095 return true;
2098 bool ChatHandler::HandleAddItemSetCommand(const char* args)
2100 if (!*args)
2101 return false;
2103 char* cId = extractKeyFromLink((char*)args,"Hitemset"); // number or [name] Shift-click form |color|Hitemset:itemset_id|h[name]|h|r
2104 if (!cId)
2105 return false;
2107 uint32 itemsetId = atol(cId);
2109 // prevent generation all items with itemset field value '0'
2110 if (itemsetId == 0)
2112 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND,itemsetId);
2113 SetSentErrorMessage(true);
2114 return false;
2117 Player* pl = m_session->GetPlayer();
2118 Player* plTarget = getSelectedPlayer();
2119 if(!plTarget)
2120 plTarget = pl;
2122 sLog.outDetail(GetMangosString(LANG_ADDITEMSET), itemsetId);
2124 bool found = false;
2125 for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
2127 ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype>(id);
2128 if (!pProto)
2129 continue;
2131 if (pProto->ItemSet == itemsetId)
2133 found = true;
2134 ItemPosCountVec dest;
2135 uint8 msg = plTarget->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, pProto->ItemId, 1 );
2136 if (msg == EQUIP_ERR_OK)
2138 Item* item = plTarget->StoreNewItem( dest, pProto->ItemId, true);
2140 // remove binding (let GM give it to another player later)
2141 if (pl==plTarget)
2142 item->SetBinding( false );
2144 pl->SendNewItem(item,1,false,true);
2145 if (pl!=plTarget)
2146 plTarget->SendNewItem(item,1,true,false);
2148 else
2150 pl->SendEquipError( msg, NULL, NULL );
2151 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, pProto->ItemId, 1);
2156 if (!found)
2158 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND,itemsetId);
2160 SetSentErrorMessage(true);
2161 return false;
2164 return true;
2167 bool ChatHandler::HandleListItemCommand(const char* args)
2169 if(!*args)
2170 return false;
2172 char* cId = extractKeyFromLink((char*)args,"Hitem");
2173 if(!cId)
2174 return false;
2176 uint32 item_id = atol(cId);
2177 if(!item_id)
2179 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
2180 SetSentErrorMessage(true);
2181 return false;
2184 ItemPrototype const* itemProto = objmgr.GetItemPrototype(item_id);
2185 if(!itemProto)
2187 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
2188 SetSentErrorMessage(true);
2189 return false;
2192 char* c_count = strtok(NULL, " ");
2193 int count = c_count ? atol(c_count) : 10;
2195 if(count < 0)
2196 return false;
2198 QueryResult *result;
2200 // inventory case
2201 uint32 inv_count = 0;
2202 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM character_inventory WHERE item_template='%u'",item_id);
2203 if(result)
2205 inv_count = (*result)[0].GetUInt32();
2206 delete result;
2209 result=CharacterDatabase.PQuery(
2210 // 0 1 2 3 4 5
2211 "SELECT ci.item, cibag.slot AS bag, ci.slot, ci.guid, characters.account,characters.name "
2212 "FROM character_inventory AS ci LEFT JOIN character_inventory AS cibag ON (cibag.item=ci.bag),characters "
2213 "WHERE ci.item_template='%u' AND ci.guid = characters.guid LIMIT %u ",
2214 item_id,uint32(count));
2216 if(result)
2220 Field *fields = result->Fetch();
2221 uint32 item_guid = fields[0].GetUInt32();
2222 uint32 item_bag = fields[1].GetUInt32();
2223 uint32 item_slot = fields[2].GetUInt32();
2224 uint32 owner_guid = fields[3].GetUInt32();
2225 uint32 owner_acc = fields[4].GetUInt32();
2226 std::string owner_name = fields[5].GetCppString();
2228 char const* item_pos = 0;
2229 if(Player::IsEquipmentPos(item_bag,item_slot))
2230 item_pos = "[equipped]";
2231 else if(Player::IsInventoryPos(item_bag,item_slot))
2232 item_pos = "[in inventory]";
2233 else if(Player::IsBankPos(item_bag,item_slot))
2234 item_pos = "[in bank]";
2235 else
2236 item_pos = "";
2238 PSendSysMessage(LANG_ITEMLIST_SLOT,
2239 item_guid,owner_name.c_str(),owner_guid,owner_acc,item_pos);
2240 } while (result->NextRow());
2242 int64 res_count = result->GetRowCount();
2244 delete result;
2246 if(count > res_count)
2247 count-=res_count;
2248 else if(count)
2249 count = 0;
2252 // mail case
2253 uint32 mail_count = 0;
2254 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM mail_items WHERE item_template='%u'", item_id);
2255 if(result)
2257 mail_count = (*result)[0].GetUInt32();
2258 delete result;
2261 if(count > 0)
2263 result=CharacterDatabase.PQuery(
2264 // 0 1 2 3 4 5 6
2265 "SELECT mail_items.item_guid, mail.sender, mail.receiver, char_s.account, char_s.name, char_r.account, char_r.name "
2266 "FROM mail,mail_items,characters as char_s,characters as char_r "
2267 "WHERE mail_items.item_template='%u' AND char_s.guid = mail.sender AND char_r.guid = mail.receiver AND mail.id=mail_items.mail_id LIMIT %u",
2268 item_id,uint32(count));
2270 else
2271 result = NULL;
2273 if(result)
2277 Field *fields = result->Fetch();
2278 uint32 item_guid = fields[0].GetUInt32();
2279 uint32 item_s = fields[1].GetUInt32();
2280 uint32 item_r = fields[2].GetUInt32();
2281 uint32 item_s_acc = fields[3].GetUInt32();
2282 std::string item_s_name = fields[4].GetCppString();
2283 uint32 item_r_acc = fields[5].GetUInt32();
2284 std::string item_r_name = fields[6].GetCppString();
2286 char const* item_pos = "[in mail]";
2288 PSendSysMessage(LANG_ITEMLIST_MAIL,
2289 item_guid,item_s_name.c_str(),item_s,item_s_acc,item_r_name.c_str(),item_r,item_r_acc,item_pos);
2290 } while (result->NextRow());
2292 int64 res_count = result->GetRowCount();
2294 delete result;
2296 if(count > res_count)
2297 count-=res_count;
2298 else if(count)
2299 count = 0;
2302 // auction case
2303 uint32 auc_count = 0;
2304 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM auctionhouse WHERE item_template='%u'",item_id);
2305 if(result)
2307 auc_count = (*result)[0].GetUInt32();
2308 delete result;
2311 if(count > 0)
2313 result=CharacterDatabase.PQuery(
2314 // 0 1 2 3
2315 "SELECT auctionhouse.itemguid, auctionhouse.itemowner, characters.account, characters.name "
2316 "FROM auctionhouse,characters WHERE auctionhouse.item_template='%u' AND characters.guid = auctionhouse.itemowner LIMIT %u",
2317 item_id,uint32(count));
2319 else
2320 result = NULL;
2322 if(result)
2326 Field *fields = result->Fetch();
2327 uint32 item_guid = fields[0].GetUInt32();
2328 uint32 owner = fields[1].GetUInt32();
2329 uint32 owner_acc = fields[2].GetUInt32();
2330 std::string owner_name = fields[3].GetCppString();
2332 char const* item_pos = "[in auction]";
2334 PSendSysMessage(LANG_ITEMLIST_AUCTION, item_guid, owner_name.c_str(), owner, owner_acc,item_pos);
2335 } while (result->NextRow());
2337 delete result;
2340 // guild bank case
2341 uint32 guild_count = 0;
2342 result=CharacterDatabase.PQuery("SELECT COUNT(item_entry) FROM guild_bank_item WHERE item_entry='%u'",item_id);
2343 if(result)
2345 guild_count = (*result)[0].GetUInt32();
2346 delete result;
2349 result=CharacterDatabase.PQuery(
2350 // 0 1 2
2351 "SELECT gi.item_guid, gi.guildid, guild.name "
2352 "FROM guild_bank_item AS gi, guild WHERE gi.item_entry='%u' AND gi.guildid = guild.guildid LIMIT %u ",
2353 item_id,uint32(count));
2355 if(result)
2359 Field *fields = result->Fetch();
2360 uint32 item_guid = fields[0].GetUInt32();
2361 uint32 guild_guid = fields[1].GetUInt32();
2362 std::string guild_name = fields[2].GetCppString();
2364 char const* item_pos = "[in guild bank]";
2366 PSendSysMessage(LANG_ITEMLIST_GUILD,item_guid,guild_name.c_str(),guild_guid,item_pos);
2367 } while (result->NextRow());
2369 int64 res_count = result->GetRowCount();
2371 delete result;
2373 if(count > res_count)
2374 count-=res_count;
2375 else if(count)
2376 count = 0;
2379 if(inv_count+mail_count+auc_count+guild_count == 0)
2381 SendSysMessage(LANG_COMMAND_NOITEMFOUND);
2382 SetSentErrorMessage(true);
2383 return false;
2386 PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE,item_id,inv_count+mail_count+auc_count+guild_count,inv_count,mail_count,auc_count,guild_count);
2388 return true;
2391 bool ChatHandler::HandleListObjectCommand(const char* args)
2393 if(!*args)
2394 return false;
2396 // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2397 char* cId = extractKeyFromLink((char*)args,"Hgameobject_entry");
2398 if(!cId)
2399 return false;
2401 uint32 go_id = atol(cId);
2402 if(!go_id)
2404 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, go_id);
2405 SetSentErrorMessage(true);
2406 return false;
2409 GameObjectInfo const * gInfo = objmgr.GetGameObjectInfo(go_id);
2410 if(!gInfo)
2412 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, go_id);
2413 SetSentErrorMessage(true);
2414 return false;
2417 char* c_count = strtok(NULL, " ");
2418 int count = c_count ? atol(c_count) : 10;
2420 if(count < 0)
2421 return false;
2423 QueryResult *result;
2425 uint32 obj_count = 0;
2426 result=WorldDatabase.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'",go_id);
2427 if(result)
2429 obj_count = (*result)[0].GetUInt32();
2430 delete result;
2433 if(m_session)
2435 Player* pl = m_session->GetPlayer();
2436 result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map, (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ FROM gameobject WHERE id = '%u' ORDER BY order_ ASC LIMIT %u",
2437 pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(),go_id,uint32(count));
2439 else
2440 result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map FROM gameobject WHERE id = '%u' LIMIT %u",
2441 go_id,uint32(count));
2443 if (result)
2447 Field *fields = result->Fetch();
2448 uint32 guid = fields[0].GetUInt32();
2449 float x = fields[1].GetFloat();
2450 float y = fields[2].GetFloat();
2451 float z = fields[3].GetFloat();
2452 int mapid = fields[4].GetUInt16();
2454 if (m_session)
2455 PSendSysMessage(LANG_GO_LIST_CHAT, guid, guid, gInfo->name, x, y, z, mapid);
2456 else
2457 PSendSysMessage(LANG_GO_LIST_CONSOLE, guid, gInfo->name, x, y, z, mapid);
2458 } while (result->NextRow());
2460 delete result;
2463 PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE,go_id,obj_count);
2464 return true;
2467 bool ChatHandler::HandleListCreatureCommand(const char* args)
2469 if(!*args)
2470 return false;
2472 // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
2473 char* cId = extractKeyFromLink((char*)args,"Hcreature_entry");
2474 if(!cId)
2475 return false;
2477 uint32 cr_id = atol(cId);
2478 if(!cr_id)
2480 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, cr_id);
2481 SetSentErrorMessage(true);
2482 return false;
2485 CreatureInfo const* cInfo = objmgr.GetCreatureTemplate(cr_id);
2486 if(!cInfo)
2488 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, cr_id);
2489 SetSentErrorMessage(true);
2490 return false;
2493 char* c_count = strtok(NULL, " ");
2494 int count = c_count ? atol(c_count) : 10;
2496 if(count < 0)
2497 return false;
2499 QueryResult *result;
2501 uint32 cr_count = 0;
2502 result=WorldDatabase.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'",cr_id);
2503 if(result)
2505 cr_count = (*result)[0].GetUInt32();
2506 delete result;
2509 if(m_session)
2511 Player* pl = m_session->GetPlayer();
2512 result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map, (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ FROM creature WHERE id = '%u' ORDER BY order_ ASC LIMIT %u",
2513 pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(), cr_id,uint32(count));
2515 else
2516 result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '%u' LIMIT %u",
2517 cr_id,uint32(count));
2519 if (result)
2523 Field *fields = result->Fetch();
2524 uint32 guid = fields[0].GetUInt32();
2525 float x = fields[1].GetFloat();
2526 float y = fields[2].GetFloat();
2527 float z = fields[3].GetFloat();
2528 int mapid = fields[4].GetUInt16();
2530 if (m_session)
2531 PSendSysMessage(LANG_CREATURE_LIST_CHAT, guid, guid, cInfo->Name, x, y, z, mapid);
2532 else
2533 PSendSysMessage(LANG_CREATURE_LIST_CONSOLE, guid, cInfo->Name, x, y, z, mapid);
2534 } while (result->NextRow());
2536 delete result;
2539 PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE,cr_id,cr_count);
2540 return true;
2543 bool ChatHandler::HandleLookupItemCommand(const char* args)
2545 if(!*args)
2546 return false;
2548 std::string namepart = args;
2549 std::wstring wnamepart;
2551 // converting string that we try to find to lower case
2552 if(!Utf8toWStr(namepart,wnamepart))
2553 return false;
2555 wstrToLower(wnamepart);
2557 uint32 counter = 0;
2559 // Search in `item_template`
2560 for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
2562 ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype >(id);
2563 if(!pProto)
2564 continue;
2566 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
2567 if ( loc_idx >= 0 )
2569 ItemLocale const *il = objmgr.GetItemLocale(pProto->ItemId);
2570 if (il)
2572 if (il->Name.size() > loc_idx && !il->Name[loc_idx].empty())
2574 std::string name = il->Name[loc_idx];
2576 if (Utf8FitTo(name, wnamepart))
2578 if (m_session)
2579 PSendSysMessage(LANG_ITEM_LIST_CHAT, id, id, name.c_str());
2580 else
2581 PSendSysMessage(LANG_ITEM_LIST_CONSOLE, id, name.c_str());
2582 ++counter;
2583 continue;
2589 std::string name = pProto->Name1;
2590 if(name.empty())
2591 continue;
2593 if (Utf8FitTo(name, wnamepart))
2595 if (m_session)
2596 PSendSysMessage(LANG_ITEM_LIST_CHAT, id, id, name.c_str());
2597 else
2598 PSendSysMessage(LANG_ITEM_LIST_CONSOLE, id, name.c_str());
2599 ++counter;
2603 if (counter==0)
2604 SendSysMessage(LANG_COMMAND_NOITEMFOUND);
2606 return true;
2609 bool ChatHandler::HandleLookupItemSetCommand(const char* args)
2611 if(!*args)
2612 return false;
2614 std::string namepart = args;
2615 std::wstring wnamepart;
2617 if(!Utf8toWStr(namepart,wnamepart))
2618 return false;
2620 // converting string that we try to find to lower case
2621 wstrToLower( wnamepart );
2623 uint32 counter = 0; // Counter for figure out that we found smth.
2625 // Search in ItemSet.dbc
2626 for (uint32 id = 0; id < sItemSetStore.GetNumRows(); id++)
2628 ItemSetEntry const *set = sItemSetStore.LookupEntry(id);
2629 if(set)
2631 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
2632 std::string name = set->name[loc];
2633 if(name.empty())
2634 continue;
2636 if (!Utf8FitTo(name, wnamepart))
2638 loc = 0;
2639 for(; loc < MAX_LOCALE; ++loc)
2641 if(m_session && loc==m_session->GetSessionDbcLocale())
2642 continue;
2644 name = set->name[loc];
2645 if(name.empty())
2646 continue;
2648 if (Utf8FitTo(name, wnamepart))
2649 break;
2653 if(loc < MAX_LOCALE)
2655 // send item set in "id - [namedlink locale]" format
2656 if (m_session)
2657 PSendSysMessage(LANG_ITEMSET_LIST_CHAT,id,id,name.c_str(),localeNames[loc]);
2658 else
2659 PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE,id,name.c_str(),localeNames[loc]);
2660 ++counter;
2664 if (counter == 0) // if counter == 0 then we found nth
2665 SendSysMessage(LANG_COMMAND_NOITEMSETFOUND);
2666 return true;
2669 bool ChatHandler::HandleLookupSkillCommand(const char* args)
2671 if(!*args)
2672 return false;
2674 // can be NULL in console call
2675 Player* target = getSelectedPlayer();
2677 std::string namepart = args;
2678 std::wstring wnamepart;
2680 if(!Utf8toWStr(namepart,wnamepart))
2681 return false;
2683 // converting string that we try to find to lower case
2684 wstrToLower( wnamepart );
2686 uint32 counter = 0; // Counter for figure out that we found smth.
2688 // Search in SkillLine.dbc
2689 for (uint32 id = 0; id < sSkillLineStore.GetNumRows(); id++)
2691 SkillLineEntry const *skillInfo = sSkillLineStore.LookupEntry(id);
2692 if(skillInfo)
2694 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
2695 std::string name = skillInfo->name[loc];
2696 if(name.empty())
2697 continue;
2699 if (!Utf8FitTo(name, wnamepart))
2701 loc = 0;
2702 for(; loc < MAX_LOCALE; ++loc)
2704 if(m_session && loc==m_session->GetSessionDbcLocale())
2705 continue;
2707 name = skillInfo->name[loc];
2708 if(name.empty())
2709 continue;
2711 if (Utf8FitTo(name, wnamepart))
2712 break;
2716 if(loc < MAX_LOCALE)
2718 char valStr[50] = "";
2719 char const* knownStr = "";
2720 if(target && target->HasSkill(id))
2722 knownStr = GetMangosString(LANG_KNOWN);
2723 uint32 curValue = target->GetPureSkillValue(id);
2724 uint32 maxValue = target->GetPureMaxSkillValue(id);
2725 uint32 permValue = target->GetSkillPermBonusValue(id);
2726 uint32 tempValue = target->GetSkillTempBonusValue(id);
2728 char const* valFormat = GetMangosString(LANG_SKILL_VALUES);
2729 snprintf(valStr,50,valFormat,curValue,maxValue,permValue,tempValue);
2732 // send skill in "id - [namedlink locale]" format
2733 if (m_session)
2734 PSendSysMessage(LANG_SKILL_LIST_CHAT,id,id,name.c_str(),localeNames[loc],knownStr,valStr);
2735 else
2736 PSendSysMessage(LANG_SKILL_LIST_CONSOLE,id,name.c_str(),localeNames[loc],knownStr,valStr);
2738 ++counter;
2742 if (counter == 0) // if counter == 0 then we found nth
2743 SendSysMessage(LANG_COMMAND_NOSKILLFOUND);
2744 return true;
2747 bool ChatHandler::HandleLookupSpellCommand(const char* args)
2749 if(!*args)
2750 return false;
2752 // can be NULL at console call
2753 Player* target = getSelectedPlayer();
2755 std::string namepart = args;
2756 std::wstring wnamepart;
2758 if(!Utf8toWStr(namepart,wnamepart))
2759 return false;
2761 // converting string that we try to find to lower case
2762 wstrToLower( wnamepart );
2764 uint32 counter = 0; // Counter for figure out that we found smth.
2766 // Search in Spell.dbc
2767 for (uint32 id = 0; id < sSpellStore.GetNumRows(); id++)
2769 SpellEntry const *spellInfo = sSpellStore.LookupEntry(id);
2770 if(spellInfo)
2772 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
2773 std::string name = spellInfo->SpellName[loc];
2774 if(name.empty())
2775 continue;
2777 if (!Utf8FitTo(name, wnamepart))
2779 loc = 0;
2780 for(; loc < MAX_LOCALE; ++loc)
2782 if(m_session && loc==m_session->GetSessionDbcLocale())
2783 continue;
2785 name = spellInfo->SpellName[loc];
2786 if(name.empty())
2787 continue;
2789 if (Utf8FitTo(name, wnamepart))
2790 break;
2794 if(loc < MAX_LOCALE)
2796 bool known = target && target->HasSpell(id);
2797 bool learn = (spellInfo->Effect[0] == SPELL_EFFECT_LEARN_SPELL);
2799 uint32 talentCost = GetTalentSpellCost(id);
2801 bool talent = (talentCost > 0);
2802 bool passive = IsPassiveSpell(id);
2803 bool active = target && target->HasAura(id);
2805 // unit32 used to prevent interpreting uint8 as char at output
2806 // find rank of learned spell for learning spell, or talent rank
2807 uint32 rank = talentCost ? talentCost : spellmgr.GetSpellRank(learn ? spellInfo->EffectTriggerSpell[0] : id);
2809 // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
2810 std::ostringstream ss;
2811 if (m_session)
2812 ss << id << " - |cffffffff|Hspell:" << id << "|h[" << name;
2813 else
2814 ss << id << " - " << name;
2816 // include rank in link name
2817 if(rank)
2818 ss << GetMangosString(LANG_SPELL_RANK) << rank;
2820 if (m_session)
2821 ss << " " << localeNames[loc] << "]|h|r";
2822 else
2823 ss << " " << localeNames[loc];
2825 if(talent)
2826 ss << GetMangosString(LANG_TALENT);
2827 if(passive)
2828 ss << GetMangosString(LANG_PASSIVE);
2829 if(learn)
2830 ss << GetMangosString(LANG_LEARN);
2831 if(known)
2832 ss << GetMangosString(LANG_KNOWN);
2833 if(active)
2834 ss << GetMangosString(LANG_ACTIVE);
2836 SendSysMessage(ss.str().c_str());
2838 ++counter;
2842 if (counter == 0) // if counter == 0 then we found nth
2843 SendSysMessage(LANG_COMMAND_NOSPELLFOUND);
2844 return true;
2847 bool ChatHandler::HandleLookupQuestCommand(const char* args)
2849 if(!*args)
2850 return false;
2852 // can be NULL at console call
2853 Player* target = getSelectedPlayer();
2855 std::string namepart = args;
2856 std::wstring wnamepart;
2858 // converting string that we try to find to lower case
2859 if(!Utf8toWStr(namepart,wnamepart))
2860 return false;
2862 wstrToLower(wnamepart);
2864 uint32 counter = 0 ;
2866 ObjectMgr::QuestMap const& qTemplates = objmgr.GetQuestTemplates();
2867 for (ObjectMgr::QuestMap::const_iterator iter = qTemplates.begin(); iter != qTemplates.end(); ++iter)
2869 Quest * qinfo = iter->second;
2871 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
2872 if ( loc_idx >= 0 )
2874 QuestLocale const *il = objmgr.GetQuestLocale(qinfo->GetQuestId());
2875 if (il)
2877 if (il->Title.size() > loc_idx && !il->Title[loc_idx].empty())
2879 std::string title = il->Title[loc_idx];
2881 if (Utf8FitTo(title, wnamepart))
2883 char const* statusStr = "";
2885 if(target)
2887 QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId());
2889 if(status == QUEST_STATUS_COMPLETE)
2891 if(target->GetQuestRewardStatus(qinfo->GetQuestId()))
2892 statusStr = GetMangosString(LANG_COMMAND_QUEST_REWARDED);
2893 else
2894 statusStr = GetMangosString(LANG_COMMAND_QUEST_COMPLETE);
2896 else if(status == QUEST_STATUS_INCOMPLETE)
2897 statusStr = GetMangosString(LANG_COMMAND_QUEST_ACTIVE);
2900 if (m_session)
2901 PSendSysMessage(LANG_QUEST_LIST_CHAT,qinfo->GetQuestId(),qinfo->GetQuestId(),title.c_str(),statusStr);
2902 else
2903 PSendSysMessage(LANG_QUEST_LIST_CONSOLE,qinfo->GetQuestId(),title.c_str(),statusStr);
2904 ++counter;
2905 continue;
2911 std::string title = qinfo->GetTitle();
2912 if(title.empty())
2913 continue;
2915 if (Utf8FitTo(title, wnamepart))
2917 char const* statusStr = "";
2919 if(target)
2921 QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId());
2923 if(status == QUEST_STATUS_COMPLETE)
2925 if(target->GetQuestRewardStatus(qinfo->GetQuestId()))
2926 statusStr = GetMangosString(LANG_COMMAND_QUEST_REWARDED);
2927 else
2928 statusStr = GetMangosString(LANG_COMMAND_QUEST_COMPLETE);
2930 else if(status == QUEST_STATUS_INCOMPLETE)
2931 statusStr = GetMangosString(LANG_COMMAND_QUEST_ACTIVE);
2934 if (m_session)
2935 PSendSysMessage(LANG_QUEST_LIST_CHAT,qinfo->GetQuestId(),qinfo->GetQuestId(),title.c_str(),statusStr);
2936 else
2937 PSendSysMessage(LANG_QUEST_LIST_CONSOLE,qinfo->GetQuestId(),title.c_str(),statusStr);
2939 ++counter;
2943 if (counter==0)
2944 SendSysMessage(LANG_COMMAND_NOQUESTFOUND);
2946 return true;
2949 bool ChatHandler::HandleLookupCreatureCommand(const char* args)
2951 if (!*args)
2952 return false;
2954 std::string namepart = args;
2955 std::wstring wnamepart;
2957 // converting string that we try to find to lower case
2958 if (!Utf8toWStr (namepart,wnamepart))
2959 return false;
2961 wstrToLower (wnamepart);
2963 uint32 counter = 0;
2965 for (uint32 id = 0; id< sCreatureStorage.MaxEntry; ++id)
2967 CreatureInfo const* cInfo = sCreatureStorage.LookupEntry<CreatureInfo> (id);
2968 if(!cInfo)
2969 continue;
2971 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
2972 if (loc_idx >= 0)
2974 CreatureLocale const *cl = objmgr.GetCreatureLocale (id);
2975 if (cl)
2977 if (cl->Name.size() > loc_idx && !cl->Name[loc_idx].empty ())
2979 std::string name = cl->Name[loc_idx];
2981 if (Utf8FitTo (name, wnamepart))
2983 if (m_session)
2984 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str ());
2985 else
2986 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE, id, name.c_str ());
2987 ++counter;
2988 continue;
2994 std::string name = cInfo->Name;
2995 if (name.empty ())
2996 continue;
2998 if (Utf8FitTo(name, wnamepart))
3000 if (m_session)
3001 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str ());
3002 else
3003 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE, id, name.c_str ());
3004 ++counter;
3008 if (counter==0)
3009 SendSysMessage (LANG_COMMAND_NOCREATUREFOUND);
3011 return true;
3014 bool ChatHandler::HandleLookupObjectCommand(const char* args)
3016 if(!*args)
3017 return false;
3019 std::string namepart = args;
3020 std::wstring wnamepart;
3022 // converting string that we try to find to lower case
3023 if(!Utf8toWStr(namepart,wnamepart))
3024 return false;
3026 wstrToLower(wnamepart);
3028 uint32 counter = 0;
3030 for (uint32 id = 0; id< sGOStorage.MaxEntry; id++ )
3032 GameObjectInfo const* gInfo = sGOStorage.LookupEntry<GameObjectInfo>(id);
3033 if(!gInfo)
3034 continue;
3036 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
3037 if ( loc_idx >= 0 )
3039 GameObjectLocale const *gl = objmgr.GetGameObjectLocale(id);
3040 if (gl)
3042 if (gl->Name.size() > loc_idx && !gl->Name[loc_idx].empty())
3044 std::string name = gl->Name[loc_idx];
3046 if (Utf8FitTo(name, wnamepart))
3048 if (m_session)
3049 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, id, id, name.c_str());
3050 else
3051 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, id, name.c_str());
3052 ++counter;
3053 continue;
3059 std::string name = gInfo->name;
3060 if(name.empty())
3061 continue;
3063 if(Utf8FitTo(name, wnamepart))
3065 if (m_session)
3066 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, id, id, name.c_str());
3067 else
3068 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, id, name.c_str());
3069 ++counter;
3073 if(counter==0)
3074 SendSysMessage(LANG_COMMAND_NOGAMEOBJECTFOUND);
3076 return true;
3079 /** \brief GM command level 3 - Create a guild.
3081 * This command allows a GM (level 3) to create a guild.
3083 * The "args" parameter contains the name of the guild leader
3084 * and then the name of the guild.
3087 bool ChatHandler::HandleGuildCreateCommand(const char* args)
3090 if (!*args)
3091 return false;
3093 char *lname = strtok ((char*)args, " ");
3094 char *gname = strtok (NULL, "");
3096 if (!lname)
3097 return false;
3099 if (!gname)
3101 SendSysMessage (LANG_INSERT_GUILD_NAME);
3102 SetSentErrorMessage (true);
3103 return false;
3106 std::string guildname = gname;
3108 Player* player = ObjectAccessor::Instance ().FindPlayerByName (lname);
3109 if (!player)
3111 SendSysMessage (LANG_PLAYER_NOT_FOUND);
3112 SetSentErrorMessage (true);
3113 return false;
3116 if (player->GetGuildId())
3118 SendSysMessage (LANG_PLAYER_IN_GUILD);
3119 return true;
3122 Guild *guild = new Guild;
3123 if (!guild->create (player,guildname))
3125 delete guild;
3126 SendSysMessage (LANG_GUILD_NOT_CREATED);
3127 SetSentErrorMessage (true);
3128 return false;
3131 objmgr.AddGuild (guild);
3132 return true;
3135 bool ChatHandler::HandleGuildInviteCommand(const char *args)
3137 if (!*args)
3138 return false;
3140 char* par1 = strtok ((char*)args, " ");
3141 char* par2 = strtok (NULL, "");
3142 if(!par1 || !par2)
3143 return false;
3145 std::string glName = par2;
3146 Guild* targetGuild = objmgr.GetGuildByName (glName);
3147 if (!targetGuild)
3148 return false;
3150 std::string plName = extractPlayerNameFromLink(par1);
3151 if(plName.empty())
3153 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3154 SetSentErrorMessage(true);
3155 return false;
3158 uint64 plGuid = 0;
3159 if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3160 plGuid = targetPlayer->GetGUID ();
3161 else
3162 plGuid = objmgr.GetPlayerGUIDByName (plName);
3164 if (!plGuid)
3165 return false;
3167 // player's guild membership checked in AddMember before add
3168 if (!targetGuild->AddMember (plGuid,targetGuild->GetLowestRank ()))
3169 return false;
3171 return true;
3174 bool ChatHandler::HandleGuildUninviteCommand(const char *args)
3176 if (!*args)
3177 return false;
3179 char* par1 = strtok ((char*)args, " ");
3180 if(!par1)
3181 return false;
3183 std::string plName = extractPlayerNameFromLink(par1);
3184 if(plName.empty())
3186 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3187 SetSentErrorMessage(true);
3188 return false;
3191 uint64 plGuid = 0;
3192 uint32 glId = 0;
3193 if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3195 plGuid = targetPlayer->GetGUID ();
3196 glId = targetPlayer->GetGuildId ();
3198 else
3200 plGuid = objmgr.GetPlayerGUIDByName (plName);
3201 glId = Player::GetGuildIdFromDB (plGuid);
3204 if (!plGuid || !glId)
3205 return false;
3207 Guild* targetGuild = objmgr.GetGuildById (glId);
3208 if (!targetGuild)
3209 return false;
3211 targetGuild->DelMember (plGuid);
3213 return true;
3216 bool ChatHandler::HandleGuildRankCommand(const char *args)
3218 if (!*args)
3219 return false;
3221 char* par1 = strtok ((char*)args, " ");
3222 char* par2 = strtok (NULL, " ");
3223 if (!par1 || !par2)
3224 return false;
3226 std::string plName = extractPlayerNameFromLink(par1);
3227 if(plName.empty())
3229 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3230 SetSentErrorMessage(true);
3231 return false;
3235 uint64 plGuid = 0;
3236 uint32 glId = 0;
3237 if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3239 plGuid = targetPlayer->GetGUID ();
3240 glId = targetPlayer->GetGuildId ();
3242 else
3244 plGuid = objmgr.GetPlayerGUIDByName (plName);
3245 glId = Player::GetGuildIdFromDB (plGuid);
3248 if (!plGuid || !glId)
3249 return false;
3251 Guild* targetGuild = objmgr.GetGuildById (glId);
3252 if (!targetGuild)
3253 return false;
3255 uint32 newrank = uint32 (atoi (par2));
3256 if (newrank > targetGuild->GetLowestRank ())
3257 return false;
3259 targetGuild->ChangeRank (plGuid,newrank);
3261 return true;
3264 bool ChatHandler::HandleGuildDeleteCommand(const char* args)
3266 if (!*args)
3267 return false;
3269 char* par1 = strtok ((char*)args, " ");
3270 if (!par1)
3271 return false;
3273 std::string gld = par1;
3275 Guild* targetGuild = objmgr.GetGuildByName (gld);
3276 if (!targetGuild)
3277 return false;
3279 targetGuild->Disband ();
3281 return true;
3284 bool ChatHandler::HandleGetDistanceCommand(const char* args)
3286 WorldObject* obj = NULL;
3288 if (*args)
3290 uint64 guid = extractGuidFromLink((char*)args);
3291 if(guid)
3292 obj = (WorldObject*)ObjectAccessor::GetObjectByTypeMask(*m_session->GetPlayer(),guid,TYPEMASK_UNIT|TYPEMASK_GAMEOBJECT);
3294 if(!obj)
3296 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3297 SetSentErrorMessage(true);
3298 return false;
3301 else
3303 obj = getSelectedUnit();
3305 if(!obj)
3307 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3308 SetSentErrorMessage(true);
3309 return false;
3313 PSendSysMessage(LANG_DISTANCE, m_session->GetPlayer()->GetDistance(obj),m_session->GetPlayer()->GetDistance2d(obj));
3315 return true;
3318 bool ChatHandler::HandleDieCommand(const char* /*args*/)
3320 Unit* target = getSelectedUnit();
3322 if(!target || !m_session->GetPlayer()->GetSelection())
3324 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3325 SetSentErrorMessage(true);
3326 return false;
3329 if(target->GetTypeId()==TYPEID_PLAYER)
3331 if(HasLowerSecurity((Player*)target,0,false))
3332 return false;
3335 if( target->isAlive() )
3337 m_session->GetPlayer()->DealDamage(target, target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
3340 return true;
3343 bool ChatHandler::HandleDamageCommand(const char * args)
3345 if (!*args)
3346 return false;
3348 Unit* target = getSelectedUnit();
3350 if(!target || !m_session->GetPlayer()->GetSelection())
3352 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3353 SetSentErrorMessage(true);
3354 return false;
3357 if( !target->isAlive() )
3358 return true;
3360 char* damageStr = strtok((char*)args, " ");
3361 if(!damageStr)
3362 return false;
3364 int32 damage = atoi((char*)damageStr);
3365 if(damage <=0)
3366 return true;
3368 char* schoolStr = strtok((char*)NULL, " ");
3370 // flat melee damage without resistence/etc reduction
3371 if(!schoolStr)
3373 m_session->GetPlayer()->DealDamage(target, damage, NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
3374 m_session->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2, target, 1, SPELL_SCHOOL_MASK_NORMAL, damage, 0, 0, VICTIMSTATE_NORMAL, 0);
3375 return true;
3378 uint32 school = schoolStr ? atoi((char*)schoolStr) : SPELL_SCHOOL_NORMAL;
3379 if(school >= MAX_SPELL_SCHOOL)
3380 return false;
3382 SpellSchoolMask schoolmask = SpellSchoolMask(1 << school);
3384 if ( schoolmask & SPELL_SCHOOL_MASK_NORMAL )
3385 damage = m_session->GetPlayer()->CalcArmorReducedDamage(target, damage);
3387 char* spellStr = strtok((char*)NULL, " ");
3389 // melee damage by specific school
3390 if(!spellStr)
3392 uint32 absorb = 0;
3393 uint32 resist = 0;
3395 m_session->GetPlayer()->CalcAbsorbResist(target,schoolmask, SPELL_DIRECT_DAMAGE, damage, &absorb, &resist);
3397 if (damage <= absorb + resist)
3398 return true;
3400 damage -= absorb + resist;
3402 m_session->GetPlayer()->DealDamage(target, damage, NULL, DIRECT_DAMAGE, schoolmask, NULL, false);
3403 m_session->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2, target, 1, schoolmask, damage, absorb, resist, VICTIMSTATE_NORMAL, 0);
3404 return true;
3407 // non-melee damage
3409 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3410 uint32 spellid = extractSpellIdFromLink((char*)args);
3411 if(!spellid || !sSpellStore.LookupEntry(spellid))
3412 return false;
3414 m_session->GetPlayer()->SpellNonMeleeDamageLog(target, spellid, damage, false);
3415 return true;
3418 bool ChatHandler::HandleModifyArenaCommand(const char * args)
3420 if (!*args)
3421 return false;
3423 Player *target = getSelectedPlayer();
3424 if(!target)
3426 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3427 SetSentErrorMessage(true);
3428 return false;
3431 int32 amount = (uint32)atoi(args);
3433 target->ModifyArenaPoints(amount);
3435 PSendSysMessage(LANG_COMMAND_MODIFY_ARENA, GetNameLink(target).c_str(), target->GetArenaPoints());
3437 return true;
3440 bool ChatHandler::HandleReviveCommand(const char* args)
3442 Player* SelectedPlayer = NULL;
3444 if (*args)
3446 std::string name = extractPlayerNameFromLink((char*)args);
3447 if(name.empty())
3449 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3450 SetSentErrorMessage(true);
3451 return false;
3454 SelectedPlayer = objmgr.GetPlayer(name.c_str());
3456 else
3457 SelectedPlayer = getSelectedPlayer();
3459 if(!SelectedPlayer)
3461 SendSysMessage(LANG_NO_CHAR_SELECTED);
3462 SetSentErrorMessage(true);
3463 return false;
3466 SelectedPlayer->ResurrectPlayer(0.5f);
3467 SelectedPlayer->SpawnCorpseBones();
3468 SelectedPlayer->SaveToDB();
3469 return true;
3472 bool ChatHandler::HandleAuraCommand(const char* args)
3474 Unit *target = getSelectedUnit();
3475 if(!target)
3477 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3478 SetSentErrorMessage(true);
3479 return false;
3482 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3483 uint32 spellID = extractSpellIdFromLink((char*)args);
3485 SpellEntry const *spellInfo = sSpellStore.LookupEntry( spellID );
3486 if(spellInfo)
3488 for(uint32 i = 0;i<3;i++)
3490 uint8 eff = spellInfo->Effect[i];
3491 if (eff>=TOTAL_SPELL_EFFECTS)
3492 continue;
3493 if( IsAreaAuraEffect(eff) ||
3494 eff == SPELL_EFFECT_APPLY_AURA ||
3495 eff == SPELL_EFFECT_PERSISTENT_AREA_AURA )
3497 Aura *Aur = CreateAura(spellInfo, i, NULL, target);
3498 target->AddAura(Aur);
3503 return true;
3506 bool ChatHandler::HandleUnAuraCommand(const char* args)
3508 Unit *target = getSelectedUnit();
3509 if(!target)
3511 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3512 SetSentErrorMessage(true);
3513 return false;
3516 std::string argstr = args;
3517 if (argstr == "all")
3519 target->RemoveAllAuras();
3520 return true;
3523 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3524 uint32 spellID = extractSpellIdFromLink((char*)args);
3525 if(!spellID)
3526 return false;
3528 target->RemoveAurasDueToSpell(spellID);
3530 return true;
3533 bool ChatHandler::HandleLinkGraveCommand(const char* args)
3535 if(!*args)
3536 return false;
3538 char* px = strtok((char*)args, " ");
3539 if (!px)
3540 return false;
3542 uint32 g_id = (uint32)atoi(px);
3544 uint32 g_team;
3546 char* px2 = strtok(NULL, " ");
3548 if (!px2)
3549 g_team = 0;
3550 else if (strncmp(px2,"horde",6)==0)
3551 g_team = HORDE;
3552 else if (strncmp(px2,"alliance",9)==0)
3553 g_team = ALLIANCE;
3554 else
3555 return false;
3557 WorldSafeLocsEntry const* graveyard = sWorldSafeLocsStore.LookupEntry(g_id);
3559 if(!graveyard )
3561 PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST, g_id);
3562 SetSentErrorMessage(true);
3563 return false;
3566 Player* player = m_session->GetPlayer();
3568 uint32 zoneId = player->GetZoneId();
3570 AreaTableEntry const *areaEntry = GetAreaEntryByAreaID(zoneId);
3571 if(!areaEntry || areaEntry->zone !=0 )
3573 PSendSysMessage(LANG_COMMAND_GRAVEYARDWRONGZONE, g_id,zoneId);
3574 SetSentErrorMessage(true);
3575 return false;
3578 if(objmgr.AddGraveYardLink(g_id,zoneId,g_team))
3579 PSendSysMessage(LANG_COMMAND_GRAVEYARDLINKED, g_id,zoneId);
3580 else
3581 PSendSysMessage(LANG_COMMAND_GRAVEYARDALRLINKED, g_id,zoneId);
3583 return true;
3586 bool ChatHandler::HandleNearGraveCommand(const char* args)
3588 uint32 g_team;
3590 size_t argslen = strlen(args);
3592 if(!*args)
3593 g_team = 0;
3594 else if (strncmp((char*)args,"horde",argslen)==0)
3595 g_team = HORDE;
3596 else if (strncmp((char*)args,"alliance",argslen)==0)
3597 g_team = ALLIANCE;
3598 else
3599 return false;
3601 Player* player = m_session->GetPlayer();
3602 uint32 zone_id = player->GetZoneId();
3604 WorldSafeLocsEntry const* graveyard = objmgr.GetClosestGraveYard(
3605 player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(),player->GetMapId(),g_team);
3607 if(graveyard)
3609 uint32 g_id = graveyard->ID;
3611 GraveYardData const* data = objmgr.FindGraveYardData(g_id,zone_id);
3612 if (!data)
3614 PSendSysMessage(LANG_COMMAND_GRAVEYARDERROR,g_id);
3615 SetSentErrorMessage(true);
3616 return false;
3619 g_team = data->team;
3621 std::string team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_NOTEAM);
3623 if(g_team == 0)
3624 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ANY);
3625 else if(g_team == HORDE)
3626 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE);
3627 else if(g_team == ALLIANCE)
3628 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE);
3630 PSendSysMessage(LANG_COMMAND_GRAVEYARDNEAREST, g_id,team_name.c_str(),zone_id);
3632 else
3634 std::string team_name;
3636 if(g_team == 0)
3637 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ANY);
3638 else if(g_team == HORDE)
3639 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE);
3640 else if(g_team == ALLIANCE)
3641 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE);
3643 if(g_team == ~uint32(0))
3644 PSendSysMessage(LANG_COMMAND_ZONENOGRAVEYARDS, zone_id);
3645 else
3646 PSendSysMessage(LANG_COMMAND_ZONENOGRAFACTION, zone_id,team_name.c_str());
3649 return true;
3652 //-----------------------Npc Commands-----------------------
3653 bool ChatHandler::HandleNpcAllowMovementCommand(const char* /*args*/)
3655 if(sWorld.getAllowMovement())
3657 sWorld.SetAllowMovement(false);
3658 SendSysMessage(LANG_CREATURE_MOVE_DISABLED);
3660 else
3662 sWorld.SetAllowMovement(true);
3663 SendSysMessage(LANG_CREATURE_MOVE_ENABLED);
3665 return true;
3668 bool ChatHandler::HandleNpcChangeEntryCommand(const char *args)
3670 if (!*args)
3671 return false;
3673 uint32 newEntryNum = atoi(args);
3674 if(!newEntryNum)
3675 return false;
3677 Unit* unit = getSelectedUnit();
3678 if(!unit || unit->GetTypeId() != TYPEID_UNIT)
3680 SendSysMessage(LANG_SELECT_CREATURE);
3681 SetSentErrorMessage(true);
3682 return false;
3684 Creature* creature = (Creature*)unit;
3685 if(creature->UpdateEntry(newEntryNum))
3686 SendSysMessage(LANG_DONE);
3687 else
3688 SendSysMessage(LANG_ERROR);
3689 return true;
3692 bool ChatHandler::HandleNpcInfoCommand(const char* /*args*/)
3694 Creature* target = getSelectedCreature();
3696 if(!target)
3698 SendSysMessage(LANG_SELECT_CREATURE);
3699 SetSentErrorMessage(true);
3700 return false;
3703 uint32 faction = target->getFaction();
3704 uint32 npcflags = target->GetUInt32Value(UNIT_NPC_FLAGS);
3705 uint32 displayid = target->GetDisplayId();
3706 uint32 nativeid = target->GetNativeDisplayId();
3707 uint32 Entry = target->GetEntry();
3708 CreatureInfo const* cInfo = target->GetCreatureInfo();
3710 int32 curRespawnDelay = target->GetRespawnTimeEx()-time(NULL);
3711 if(curRespawnDelay < 0)
3712 curRespawnDelay = 0;
3713 std::string curRespawnDelayStr = secsToTimeString(curRespawnDelay,true);
3714 std::string defRespawnDelayStr = secsToTimeString(target->GetRespawnDelay(),true);
3716 PSendSysMessage(LANG_NPCINFO_CHAR, target->GetDBTableGUIDLow(), faction, npcflags, Entry, displayid, nativeid);
3717 PSendSysMessage(LANG_NPCINFO_LEVEL, target->getLevel());
3718 PSendSysMessage(LANG_NPCINFO_HEALTH,target->GetCreateHealth(), target->GetMaxHealth(), target->GetHealth());
3719 PSendSysMessage(LANG_NPCINFO_FLAGS, target->GetUInt32Value(UNIT_FIELD_FLAGS), target->GetUInt32Value(UNIT_DYNAMIC_FLAGS), target->getFaction());
3720 PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES, defRespawnDelayStr.c_str(),curRespawnDelayStr.c_str());
3721 PSendSysMessage(LANG_NPCINFO_LOOT, cInfo->lootid,cInfo->pickpocketLootId,cInfo->SkinLootId);
3722 PSendSysMessage(LANG_NPCINFO_DUNGEON_ID, target->GetInstanceId());
3723 PSendSysMessage(LANG_NPCINFO_POSITION,float(target->GetPositionX()), float(target->GetPositionY()), float(target->GetPositionZ()));
3725 if ((npcflags & UNIT_NPC_FLAG_VENDOR) )
3727 SendSysMessage(LANG_NPCINFO_VENDOR);
3729 if ((npcflags & UNIT_NPC_FLAG_TRAINER) )
3731 SendSysMessage(LANG_NPCINFO_TRAINER);
3734 return true;
3737 //play npc emote
3738 bool ChatHandler::HandleNpcPlayEmoteCommand(const char* args)
3740 uint32 emote = atoi((char*)args);
3742 Creature* target = getSelectedCreature();
3743 if(!target)
3745 SendSysMessage(LANG_SELECT_CREATURE);
3746 SetSentErrorMessage(true);
3747 return false;
3750 target->SetUInt32Value(UNIT_NPC_EMOTESTATE,emote);
3752 return true;
3755 //TODO: NpcCommands that needs to be fixed :
3757 bool ChatHandler::HandleNpcAddWeaponCommand(const char* /*args*/)
3759 /*if (!*args)
3760 return false;
3762 uint64 guid = m_session->GetPlayer()->GetSelection();
3763 if (guid == 0)
3765 SendSysMessage(LANG_NO_SELECTION);
3766 return true;
3769 Creature *pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
3771 if(!pCreature)
3773 SendSysMessage(LANG_SELECT_CREATURE);
3774 return true;
3777 char* pSlotID = strtok((char*)args, " ");
3778 if (!pSlotID)
3779 return false;
3781 char* pItemID = strtok(NULL, " ");
3782 if (!pItemID)
3783 return false;
3785 uint32 ItemID = atoi(pItemID);
3786 uint32 SlotID = atoi(pSlotID);
3788 ItemPrototype* tmpItem = objmgr.GetItemPrototype(ItemID);
3790 bool added = false;
3791 if(tmpItem)
3793 switch(SlotID)
3795 case 1:
3796 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID);
3797 added = true;
3798 break;
3799 case 2:
3800 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID);
3801 added = true;
3802 break;
3803 case 3:
3804 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID);
3805 added = true;
3806 break;
3807 default:
3808 PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST,SlotID);
3809 added = false;
3810 break;
3813 if(added)
3814 PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT,ItemID,tmpItem->Name1,SlotID);
3816 else
3818 PSendSysMessage(LANG_ITEM_NOT_FOUND,ItemID);
3819 return true;
3822 return true;
3824 //----------------------------------------------------------
3826 bool ChatHandler::HandleExploreCheatCommand(const char* args)
3828 if (!*args)
3829 return false;
3831 int flag = atoi((char*)args);
3833 Player *chr = getSelectedPlayer();
3834 if (chr == NULL)
3836 SendSysMessage(LANG_NO_CHAR_SELECTED);
3837 SetSentErrorMessage(true);
3838 return false;
3841 if (flag != 0)
3843 PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL, GetNameLink(chr).c_str());
3844 if (needReportToTarget(chr))
3845 ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_ALL,GetNameLink().c_str());
3847 else
3849 PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING, GetNameLink(chr).c_str());
3850 if (needReportToTarget(chr))
3851 ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_NOTHING,GetNameLink().c_str());
3854 for (uint8 i=0; i<128; i++)
3856 if (flag != 0)
3858 m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1+i,0xFFFFFFFF);
3860 else
3862 m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1+i,0);
3866 return true;
3869 bool ChatHandler::HandleHoverCommand(const char* args)
3871 char* px = strtok((char*)args, " ");
3872 uint32 flag;
3873 if (!px)
3874 flag = 1;
3875 else
3876 flag = atoi(px);
3878 m_session->GetPlayer()->SetHover(flag);
3880 if (flag)
3881 SendSysMessage(LANG_HOVER_ENABLED);
3882 else
3883 SendSysMessage(LANG_HOVER_DISABLED);
3885 return true;
3888 bool ChatHandler::HandleLevelUpCommand(const char* args)
3890 char* px = strtok((char*)args, " ");
3891 char* py = strtok((char*)NULL, " ");
3893 // command format parsing
3894 char* pname = (char*)NULL;
3895 int addlevel = 1;
3897 if(px && py) // .levelup name level
3899 addlevel = atoi(py);
3900 pname = px;
3902 else if(px && !py) // .levelup name OR .levelup level
3904 if(isalpha(px[0])) // .levelup name
3905 pname = px;
3906 else // .levelup level
3907 addlevel = atoi(px);
3909 // else .levelup - nothing do for preparing
3911 // player
3912 Player *chr = NULL;
3913 uint64 chr_guid = 0;
3915 std::string name;
3917 if(pname) // player by name
3919 name = extractPlayerNameFromLink(pname);
3920 if(name.empty())
3922 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3923 SetSentErrorMessage(true);
3924 return false;
3927 chr = objmgr.GetPlayer(name.c_str());
3928 if(!chr) // not in game
3930 chr_guid = objmgr.GetPlayerGUIDByName(name);
3931 if (chr_guid == 0)
3933 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3934 SetSentErrorMessage(true);
3935 return false;
3939 else // player by selection
3941 chr = getSelectedPlayer();
3943 if (chr == NULL)
3945 SendSysMessage(LANG_NO_CHAR_SELECTED);
3946 SetSentErrorMessage(true);
3947 return false;
3950 name = chr->GetName();
3953 assert(chr || chr_guid);
3955 int32 oldlevel = chr ? chr->getLevel() : Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL,chr_guid);
3956 int32 newlevel = oldlevel + addlevel;
3957 if(newlevel < 1)
3958 newlevel = 1;
3959 if(newlevel > STRONG_MAX_LEVEL) // hardcoded maximum level
3960 newlevel = STRONG_MAX_LEVEL;
3962 if(chr)
3964 chr->GiveLevel(newlevel);
3965 chr->InitTalentForLevel();
3966 chr->SetUInt32Value(PLAYER_XP,0);
3968 if(oldlevel == newlevel)
3969 ChatHandler(chr).SendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET);
3970 else
3971 if(oldlevel < newlevel)
3972 ChatHandler(chr).PSendSysMessage(LANG_YOURS_LEVEL_UP,newlevel-oldlevel);
3973 else
3974 if(oldlevel > newlevel)
3975 ChatHandler(chr).PSendSysMessage(LANG_YOURS_LEVEL_DOWN,newlevel-oldlevel);
3977 else
3979 // update level and XP at level, all other will be updated at loading
3980 Tokens values;
3981 Player::LoadValuesArrayFromDB(values,chr_guid);
3982 Player::SetUInt32ValueInArray(values,UNIT_FIELD_LEVEL,newlevel);
3983 Player::SetUInt32ValueInArray(values,PLAYER_XP,0);
3984 Player::SaveValuesArrayInDB(values,chr_guid);
3987 if(m_session->GetPlayer() != chr) // including chr==NULL
3989 std::string nameLink = playerLink(name);
3990 PSendSysMessage(LANG_YOU_CHANGE_LVL,nameLink.c_str(),newlevel);
3992 return true;
3995 bool ChatHandler::HandleShowAreaCommand(const char* args)
3997 if (!*args)
3998 return false;
4000 Player *chr = getSelectedPlayer();
4001 if (chr == NULL)
4003 SendSysMessage(LANG_NO_CHAR_SELECTED);
4004 SetSentErrorMessage(true);
4005 return false;
4008 int area = GetAreaFlagByAreaID(atoi((char*)args));
4009 int offset = area / 32;
4010 uint32 val = (uint32)(1 << (area % 32));
4012 if(area<0 || offset >= 128)
4014 SendSysMessage(LANG_BAD_VALUE);
4015 SetSentErrorMessage(true);
4016 return false;
4019 uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
4020 chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields | val));
4022 SendSysMessage(LANG_EXPLORE_AREA);
4023 return true;
4026 bool ChatHandler::HandleHideAreaCommand(const char* args)
4028 if (!*args)
4029 return false;
4031 Player *chr = getSelectedPlayer();
4032 if (chr == NULL)
4034 SendSysMessage(LANG_NO_CHAR_SELECTED);
4035 SetSentErrorMessage(true);
4036 return false;
4039 int area = GetAreaFlagByAreaID(atoi((char*)args));
4040 int offset = area / 32;
4041 uint32 val = (uint32)(1 << (area % 32));
4043 if(area<0 || offset >= 128)
4045 SendSysMessage(LANG_BAD_VALUE);
4046 SetSentErrorMessage(true);
4047 return false;
4050 uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
4051 chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields ^ val));
4053 SendSysMessage(LANG_UNEXPLORE_AREA);
4054 return true;
4057 bool ChatHandler::HandleDebugUpdate(const char* args)
4059 if(!*args)
4060 return false;
4062 uint32 updateIndex;
4063 uint32 value;
4065 char* pUpdateIndex = strtok((char*)args, " ");
4067 Unit* chr = getSelectedUnit();
4068 if (chr == NULL)
4070 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4071 SetSentErrorMessage(true);
4072 return false;
4075 if(!pUpdateIndex)
4077 return true;
4079 updateIndex = atoi(pUpdateIndex);
4080 //check updateIndex
4081 if(chr->GetTypeId() == TYPEID_PLAYER)
4083 if (updateIndex>=PLAYER_END) return true;
4085 else
4087 if (updateIndex>=UNIT_END) return true;
4090 char* pvalue = strtok(NULL, " ");
4091 if (!pvalue)
4093 value=chr->GetUInt32Value(updateIndex);
4095 PSendSysMessage(LANG_UPDATE, chr->GetGUIDLow(),updateIndex,value);
4096 return true;
4099 value=atoi(pvalue);
4101 PSendSysMessage(LANG_UPDATE_CHANGE, chr->GetGUIDLow(),updateIndex,value);
4103 chr->SetUInt32Value(updateIndex,value);
4105 return true;
4108 bool ChatHandler::HandleBankCommand(const char* /*args*/)
4110 m_session->SendShowBank( m_session->GetPlayer()->GetGUID() );
4112 return true;
4115 bool ChatHandler::HandleChangeWeather(const char* args)
4117 if(!*args)
4118 return false;
4120 //Weather is OFF
4121 if (!sWorld.getConfig(CONFIG_WEATHER))
4123 SendSysMessage(LANG_WEATHER_DISABLED);
4124 SetSentErrorMessage(true);
4125 return false;
4128 //*Change the weather of a cell
4129 char* px = strtok((char*)args, " ");
4130 char* py = strtok(NULL, " ");
4132 if (!px || !py)
4133 return false;
4135 uint32 type = (uint32)atoi(px); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
4136 float grade = (float)atof(py); //0 to 1, sending -1 is instand good weather
4138 Player *player = m_session->GetPlayer();
4139 uint32 zoneid = player->GetZoneId();
4141 Weather* wth = sWorld.FindWeather(zoneid);
4143 if(!wth)
4144 wth = sWorld.AddWeather(zoneid);
4145 if(!wth)
4147 SendSysMessage(LANG_NO_WEATHER);
4148 SetSentErrorMessage(true);
4149 return false;
4152 wth->SetWeather(WeatherType(type), grade);
4154 return true;
4157 bool ChatHandler::HandleDebugSetValue(const char* args)
4159 if(!*args)
4160 return false;
4162 char* px = strtok((char*)args, " ");
4163 char* py = strtok(NULL, " ");
4164 char* pz = strtok(NULL, " ");
4166 if (!px || !py)
4167 return false;
4169 Unit* target = getSelectedUnit();
4170 if(!target)
4172 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4173 SetSentErrorMessage(true);
4174 return false;
4177 uint64 guid = target->GetGUID();
4179 uint32 Opcode = (uint32)atoi(px);
4180 if(Opcode >= target->GetValuesCount())
4182 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, GUID_LOPART(guid), target->GetValuesCount());
4183 return false;
4185 uint32 iValue;
4186 float fValue;
4187 bool isint32 = true;
4188 if(pz)
4189 isint32 = (bool)atoi(pz);
4190 if(isint32)
4192 iValue = (uint32)atoi(py);
4193 sLog.outDebug(GetMangosString(LANG_SET_UINT), GUID_LOPART(guid), Opcode, iValue);
4194 target->SetUInt32Value( Opcode , iValue );
4195 PSendSysMessage(LANG_SET_UINT_FIELD, GUID_LOPART(guid), Opcode,iValue);
4197 else
4199 fValue = (float)atof(py);
4200 sLog.outDebug(GetMangosString(LANG_SET_FLOAT), GUID_LOPART(guid), Opcode, fValue);
4201 target->SetFloatValue( Opcode , fValue );
4202 PSendSysMessage(LANG_SET_FLOAT_FIELD, GUID_LOPART(guid), Opcode,fValue);
4205 return true;
4208 bool ChatHandler::HandleDebugGetValue(const char* args)
4210 if(!*args)
4211 return false;
4213 char* px = strtok((char*)args, " ");
4214 char* pz = strtok(NULL, " ");
4216 if (!px)
4217 return false;
4219 Unit* target = getSelectedUnit();
4220 if(!target)
4222 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4223 SetSentErrorMessage(true);
4224 return false;
4227 uint64 guid = target->GetGUID();
4229 uint32 Opcode = (uint32)atoi(px);
4230 if(Opcode >= target->GetValuesCount())
4232 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, GUID_LOPART(guid), target->GetValuesCount());
4233 return false;
4235 uint32 iValue;
4236 float fValue;
4237 bool isint32 = true;
4238 if(pz)
4239 isint32 = (bool)atoi(pz);
4241 if(isint32)
4243 iValue = target->GetUInt32Value( Opcode );
4244 sLog.outDebug(GetMangosString(LANG_GET_UINT), GUID_LOPART(guid), Opcode, iValue);
4245 PSendSysMessage(LANG_GET_UINT_FIELD, GUID_LOPART(guid), Opcode, iValue);
4247 else
4249 fValue = target->GetFloatValue( Opcode );
4250 sLog.outDebug(GetMangosString(LANG_GET_FLOAT), GUID_LOPART(guid), Opcode, fValue);
4251 PSendSysMessage(LANG_GET_FLOAT_FIELD, GUID_LOPART(guid), Opcode, fValue);
4254 return true;
4257 bool ChatHandler::HandleSet32Bit(const char* args)
4259 if(!*args)
4260 return false;
4262 char* px = strtok((char*)args, " ");
4263 char* py = strtok(NULL, " ");
4265 if (!px || !py)
4266 return false;
4268 uint32 Opcode = (uint32)atoi(px);
4269 uint32 Value = (uint32)atoi(py);
4270 if (Value > 32) //uint32 = 32 bits
4271 return false;
4273 sLog.outDebug(GetMangosString(LANG_SET_32BIT), Opcode, Value);
4275 m_session->GetPlayer( )->SetUInt32Value( Opcode , 2^Value );
4277 PSendSysMessage(LANG_SET_32BIT_FIELD, Opcode,1);
4278 return true;
4281 bool ChatHandler::HandleDebugMod32Value(const char* args)
4283 if(!*args)
4284 return false;
4286 char* px = strtok((char*)args, " ");
4287 char* py = strtok(NULL, " ");
4289 if (!px || !py)
4290 return false;
4292 uint32 Opcode = (uint32)atoi(px);
4293 int Value = atoi(py);
4295 if(Opcode >= m_session->GetPlayer()->GetValuesCount())
4297 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, m_session->GetPlayer()->GetGUIDLow(), m_session->GetPlayer( )->GetValuesCount());
4298 return false;
4301 sLog.outDebug(GetMangosString(LANG_CHANGE_32BIT), Opcode, Value);
4303 int CurrentValue = (int)m_session->GetPlayer( )->GetUInt32Value( Opcode );
4305 CurrentValue += Value;
4306 m_session->GetPlayer( )->SetUInt32Value( Opcode , (uint32)CurrentValue );
4308 PSendSysMessage(LANG_CHANGE_32BIT_FIELD, Opcode,CurrentValue);
4310 return true;
4313 bool ChatHandler::HandleTeleAddCommand(const char * args)
4315 if(!*args)
4316 return false;
4318 Player *player=m_session->GetPlayer();
4319 if (!player)
4320 return false;
4322 std::string name = args;
4324 if(objmgr.GetGameTele(name))
4326 SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST);
4327 SetSentErrorMessage(true);
4328 return false;
4331 GameTele tele;
4332 tele.position_x = player->GetPositionX();
4333 tele.position_y = player->GetPositionY();
4334 tele.position_z = player->GetPositionZ();
4335 tele.orientation = player->GetOrientation();
4336 tele.mapId = player->GetMapId();
4337 tele.name = name;
4339 if(objmgr.AddGameTele(tele))
4341 SendSysMessage(LANG_COMMAND_TP_ADDED);
4343 else
4345 SendSysMessage(LANG_COMMAND_TP_ADDEDERR);
4346 SetSentErrorMessage(true);
4347 return false;
4350 return true;
4353 bool ChatHandler::HandleTeleDelCommand(const char * args)
4355 if(!*args)
4356 return false;
4358 std::string name = args;
4360 if(!objmgr.DeleteGameTele(name))
4362 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
4363 SetSentErrorMessage(true);
4364 return false;
4367 SendSysMessage(LANG_COMMAND_TP_DELETED);
4368 return true;
4371 bool ChatHandler::HandleListAurasCommand (const char * /*args*/)
4373 Unit *unit = getSelectedUnit();
4374 if(!unit)
4376 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4377 SetSentErrorMessage(true);
4378 return false;
4381 char const* talentStr = GetMangosString(LANG_TALENT);
4382 char const* passiveStr = GetMangosString(LANG_PASSIVE);
4384 Unit::AuraMap const& uAuras = unit->GetAuras();
4385 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS, uAuras.size());
4386 for (Unit::AuraMap::const_iterator itr = uAuras.begin(); itr != uAuras.end(); ++itr)
4388 bool talent = GetTalentSpellCost(itr->second->GetId()) > 0;
4390 char const* name = itr->second->GetSpellProto()->SpellName[m_session->GetSessionDbcLocale()];
4392 if (m_session)
4394 std::ostringstream ss_name;
4395 ss_name << "|cffffffff|Hspell:" << itr->second->GetId() << "|h[" << name << "]|h|r";
4397 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL, itr->second->GetId(), itr->second->GetEffIndex(),
4398 itr->second->GetModifier()->m_auraname, itr->second->GetAuraDuration(), itr->second->GetAuraMaxDuration(),
4399 ss_name.str().c_str(),
4400 (itr->second->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4401 IS_PLAYER_GUID(itr->second->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr->second->GetCasterGUID()));
4403 else
4405 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL, itr->second->GetId(), itr->second->GetEffIndex(),
4406 itr->second->GetModifier()->m_auraname, itr->second->GetAuraDuration(), itr->second->GetAuraMaxDuration(),
4407 name,
4408 (itr->second->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4409 IS_PLAYER_GUID(itr->second->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr->second->GetCasterGUID()));
4412 for (int i = 0; i < TOTAL_AURAS; i++)
4414 Unit::AuraList const& uAuraList = unit->GetAurasByType(AuraType(i));
4415 if (uAuraList.empty()) continue;
4416 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE, uAuraList.size(), i);
4417 for (Unit::AuraList::const_iterator itr = uAuraList.begin(); itr != uAuraList.end(); ++itr)
4419 bool talent = GetTalentSpellCost((*itr)->GetId()) > 0;
4421 char const* name = (*itr)->GetSpellProto()->SpellName[m_session->GetSessionDbcLocale()];
4423 if (m_session)
4425 std::ostringstream ss_name;
4426 ss_name << "|cffffffff|Hspell:" << (*itr)->GetId() << "|h[" << name << "]|h|r";
4428 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE, (*itr)->GetId(), (*itr)->GetEffIndex(),
4429 ss_name.str().c_str(),((*itr)->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4430 IS_PLAYER_GUID((*itr)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr)->GetCasterGUID()));
4432 else
4434 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE, (*itr)->GetId(), (*itr)->GetEffIndex(),
4435 name,((*itr)->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4436 IS_PLAYER_GUID((*itr)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr)->GetCasterGUID()));
4440 return true;
4443 bool ChatHandler::HandleResetAchievementsCommand (const char * args)
4445 char* pName = strtok((char*)args, "");
4446 Player *player = NULL;
4447 uint64 guid = 0;
4448 if (pName)
4450 std::string name = extractPlayerNameFromLink(pName);
4451 if(name.empty())
4453 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4454 SetSentErrorMessage(true);
4455 return false;
4458 guid = objmgr.GetPlayerGUIDByName(name);
4459 player = objmgr.GetPlayer(guid);
4461 else
4463 player = getSelectedPlayer();
4464 if(player)
4465 guid = player->GetGUID();
4468 if(!player && !guid)
4470 SendSysMessage(LANG_NO_CHAR_SELECTED);
4471 return true;
4474 if(player)
4475 player->GetAchievementMgr().Reset();
4476 else if(guid)
4477 AchievementMgr::DeleteFromDB(GUID_LOPART(guid));
4479 return true;
4482 bool ChatHandler::HandleResetHonorCommand (const char * args)
4484 char* pName = strtok((char*)args, "");
4485 Player *player = NULL;
4486 if (pName)
4488 std::string name = extractPlayerNameFromLink(pName);
4489 if(name.empty())
4491 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4492 SetSentErrorMessage(true);
4493 return false;
4496 uint64 guid = objmgr.GetPlayerGUIDByName(name);
4497 player = objmgr.GetPlayer(guid);
4499 else
4500 player = getSelectedPlayer();
4502 if(!player)
4504 SendSysMessage(LANG_NO_CHAR_SELECTED);
4505 return true;
4508 player->SetUInt32Value(PLAYER_FIELD_KILLS, 0);
4509 player->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS, 0);
4510 player->SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY, 0);
4511 player->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION, 0);
4512 player->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION, 0);
4514 return true;
4517 static bool HandleResetStatsOrLevelHelper(Player* player)
4519 PlayerInfo const *info = objmgr.GetPlayerInfo(player->getRace(), player->getClass());
4520 if(!info) return false;
4522 ChrClassesEntry const* cEntry = sChrClassesStore.LookupEntry(player->getClass());
4523 if(!cEntry)
4525 sLog.outError("Class %u not found in DBC (Wrong DBC files?)",player->getClass());
4526 return false;
4529 uint8 powertype = cEntry->powerType;
4531 // reset m_form if no aura
4532 if(!player->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT))
4533 player->m_form = FORM_NONE;
4535 player->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, DEFAULT_WORLD_OBJECT_SIZE );
4536 player->SetFloatValue(UNIT_FIELD_COMBATREACH, 1.5f );
4538 player->setFactionForRace(player->getRace());
4540 player->SetUInt32Value(UNIT_FIELD_BYTES_0, ( ( player->getRace() ) | ( player->getClass() << 8 ) | ( player->getGender() << 16 ) | ( powertype << 24 ) ) );
4542 // reset only if player not in some form;
4543 if(player->m_form==FORM_NONE)
4545 switch(player->getGender())
4547 case GENDER_FEMALE:
4548 player->SetDisplayId(info->displayId_f);
4549 player->SetNativeDisplayId(info->displayId_f);
4550 break;
4551 case GENDER_MALE:
4552 player->SetDisplayId(info->displayId_m);
4553 player->SetNativeDisplayId(info->displayId_m);
4554 break;
4555 default:
4556 break;
4560 player->SetByteValue(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_PVP );
4561 player->SetByteValue(UNIT_FIELD_BYTES_2, 3, player->m_form);
4563 player->SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
4565 //-1 is default value
4566 player->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX, uint32(-1));
4568 //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000 );
4569 return true;
4572 bool ChatHandler::HandleResetLevelCommand(const char * args)
4574 char* pName = strtok((char*)args, "");
4575 Player *player = NULL;
4576 if (pName)
4578 std::string name = extractPlayerNameFromLink(pName);
4579 if(name.empty())
4581 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4582 SetSentErrorMessage(true);
4583 return false;
4586 uint64 guid = objmgr.GetPlayerGUIDByName(name);
4587 player = objmgr.GetPlayer(guid);
4589 else
4590 player = getSelectedPlayer();
4592 if(!player)
4594 SendSysMessage(LANG_NO_CHAR_SELECTED);
4595 SetSentErrorMessage(true);
4596 return false;
4599 if(!HandleResetStatsOrLevelHelper(player))
4600 return false;
4602 // set starting level
4603 uint32 start_level = player->getClass() != CLASS_DEATH_KNIGHT
4604 ? sWorld.getConfig(CONFIG_START_PLAYER_LEVEL)
4605 : sWorld.getConfig(CONFIG_START_HEROIC_PLAYER_LEVEL);
4607 player->SetLevel(start_level);
4608 player->InitRunes();
4609 player->InitStatsForLevel(true);
4610 player->InitTaxiNodesForLevel();
4611 player->InitGlyphsForLevel();
4612 player->InitTalentForLevel();
4613 player->SetUInt32Value(PLAYER_XP,0);
4615 // reset level to summoned pet
4616 Pet* pet = player->GetPet();
4617 if(pet && pet->getPetType()==SUMMON_PET)
4619 pet->InitStatsForLevel(1);
4620 pet->InitTalentForLevel();
4622 return true;
4625 bool ChatHandler::HandleResetStatsCommand(const char * args)
4627 char* pName = strtok((char*)args, "");
4628 Player *player = NULL;
4629 if (pName)
4631 std::string name = extractPlayerNameFromLink(pName);
4632 if(name.empty())
4634 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4635 SetSentErrorMessage(true);
4636 return false;
4639 uint64 guid = objmgr.GetPlayerGUIDByName(name);
4640 player = objmgr.GetPlayer(guid);
4642 else
4643 player = getSelectedPlayer();
4645 if(!player)
4647 SendSysMessage(LANG_NO_CHAR_SELECTED);
4648 SetSentErrorMessage(true);
4649 return false;
4652 if(!HandleResetStatsOrLevelHelper(player))
4653 return false;
4655 player->InitRunes();
4656 player->InitStatsForLevel(true);
4657 player->InitTaxiNodesForLevel();
4658 player->InitGlyphsForLevel();
4659 player->InitTalentForLevel();
4661 return true;
4664 bool ChatHandler::HandleResetSpellsCommand(const char * args)
4666 char* pName = strtok((char*)args, "");
4667 Player *player = NULL;
4668 uint64 playerGUID = 0;
4669 if (pName)
4671 std::string name = extractPlayerNameFromLink(pName);
4672 if(name.empty())
4674 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4675 SetSentErrorMessage(true);
4676 return false;
4679 player = objmgr.GetPlayer(name.c_str());
4680 if(!player)
4681 playerGUID = objmgr.GetPlayerGUIDByName(name);
4683 else
4684 player = getSelectedPlayer();
4686 if(!player && !playerGUID)
4688 SendSysMessage(LANG_NO_CHAR_SELECTED);
4689 SetSentErrorMessage(true);
4690 return false;
4693 if(player)
4695 player->resetSpells();
4697 ChatHandler(player).SendSysMessage(LANG_RESET_SPELLS);
4698 if(m_session->GetPlayer()!=player)
4699 PSendSysMessage(LANG_RESET_SPELLS_ONLINE,GetNameLink(player).c_str());
4701 else
4703 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS), GUID_LOPART(playerGUID));
4704 PSendSysMessage(LANG_RESET_SPELLS_OFFLINE,pName);
4707 return true;
4710 bool ChatHandler::HandleResetTalentsCommand(const char * args)
4712 char* pName = strtok((char*)args, "");
4713 Player *player = NULL;
4714 uint64 playerGUID = 0;
4715 if (pName)
4717 std::string name = extractPlayerNameFromLink(pName);
4718 if(name.empty())
4720 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4721 SetSentErrorMessage(true);
4722 return false;
4725 player = objmgr.GetPlayer(name.c_str());
4726 if(!player)
4727 playerGUID = objmgr.GetPlayerGUIDByName(name);
4729 else
4730 player = getSelectedPlayer();
4732 if(player)
4734 player->resetTalents(true);
4736 ChatHandler(player).SendSysMessage(LANG_RESET_TALENTS);
4737 if(m_session->GetPlayer()!=player)
4738 PSendSysMessage(LANG_RESET_TALENTS_ONLINE,GetNameLink(player).c_str());
4740 return true;
4742 else if (playerGUID)
4744 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_TALENTS), GUID_LOPART(playerGUID) );
4745 std::string nameLink = playerLink(pName);
4746 PSendSysMessage(LANG_RESET_TALENTS_OFFLINE,nameLink.c_str());
4747 return true;
4749 // Try reset talenents as Hunter Pet
4750 Creature* creature = getSelectedCreature();
4751 if (creature && creature->isPet() && ((Pet *)creature)->getPetType() == HUNTER_PET)
4753 ((Pet *)creature)->resetTalents(true);
4754 Unit *owner = creature->GetOwner();
4755 if (owner && owner->GetTypeId() == TYPEID_PLAYER)
4757 player = (Player *)owner;
4758 ChatHandler(player).SendSysMessage(LANG_RESET_PET_TALENTS);
4759 if(m_session->GetPlayer()!=player)
4760 PSendSysMessage(LANG_RESET_PET_TALENTS_ONLINE,GetNameLink(player).c_str());
4762 return true;
4765 SendSysMessage(LANG_NO_CHAR_SELECTED);
4766 SetSentErrorMessage(true);
4767 return false;
4770 bool ChatHandler::HandleResetAllCommand(const char * args)
4772 if(!*args)
4773 return false;
4775 std::string casename = args;
4777 AtLoginFlags atLogin;
4779 // Command specially created as single command to prevent using short case names
4780 if(casename=="spells")
4782 atLogin = AT_LOGIN_RESET_SPELLS;
4783 sWorld.SendWorldText(LANG_RESETALL_SPELLS);
4785 else if(casename=="talents")
4787 atLogin = AT_LOGIN_RESET_TALENTS;
4788 sWorld.SendWorldText(LANG_RESETALL_TALENTS);
4790 else
4792 PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE,args);
4793 SetSentErrorMessage(true);
4794 return false;
4797 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE (at_login & '%u') = '0'",atLogin,atLogin);
4798 HashMapHolder<Player>::MapType const& plist = ObjectAccessor::Instance().GetPlayers();
4799 for(HashMapHolder<Player>::MapType::const_iterator itr = plist.begin(); itr != plist.end(); ++itr)
4800 itr->second->SetAtLoginFlag(atLogin);
4802 return true;
4805 bool ChatHandler::HandleServerShutDownCancelCommand(const char* args)
4807 sWorld.ShutdownCancel();
4808 return true;
4811 bool ChatHandler::HandleServerShutDownCommand(const char* args)
4813 if(!*args)
4814 return false;
4816 char* time_str = strtok ((char*) args, " ");
4817 char* exitcode_str = strtok (NULL, "");
4819 int32 time = atoi (time_str);
4821 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4822 if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0)
4823 return false;
4825 if (exitcode_str)
4827 int32 exitcode = atoi (exitcode_str);
4829 // Handle atoi() errors
4830 if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
4831 return false;
4833 // Exit code should be in range of 0-125, 126-255 is used
4834 // in many shells for their own return codes and code > 255
4835 // is not supported in many others
4836 if (exitcode < 0 || exitcode > 125)
4837 return false;
4839 sWorld.ShutdownServ (time, 0, exitcode);
4841 else
4842 sWorld.ShutdownServ(time,0,SHUTDOWN_EXIT_CODE);
4843 return true;
4846 bool ChatHandler::HandleServerRestartCommand(const char* args)
4848 if(!*args)
4849 return false;
4851 char* time_str = strtok ((char*) args, " ");
4852 char* exitcode_str = strtok (NULL, "");
4854 int32 time = atoi (time_str);
4856 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4857 if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0)
4858 return false;
4860 if (exitcode_str)
4862 int32 exitcode = atoi (exitcode_str);
4864 // Handle atoi() errors
4865 if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
4866 return false;
4868 // Exit code should be in range of 0-125, 126-255 is used
4869 // in many shells for their own return codes and code > 255
4870 // is not supported in many others
4871 if (exitcode < 0 || exitcode > 125)
4872 return false;
4874 sWorld.ShutdownServ (time, SHUTDOWN_MASK_RESTART, exitcode);
4876 else
4877 sWorld.ShutdownServ(time, SHUTDOWN_MASK_RESTART, RESTART_EXIT_CODE);
4878 return true;
4881 bool ChatHandler::HandleServerIdleRestartCommand(const char* args)
4883 if(!*args)
4884 return false;
4886 char* time_str = strtok ((char*) args, " ");
4887 char* exitcode_str = strtok (NULL, "");
4889 int32 time = atoi (time_str);
4891 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4892 if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0)
4893 return false;
4895 if (exitcode_str)
4897 int32 exitcode = atoi (exitcode_str);
4899 // Handle atoi() errors
4900 if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
4901 return false;
4903 // Exit code should be in range of 0-125, 126-255 is used
4904 // in many shells for their own return codes and code > 255
4905 // is not supported in many others
4906 if (exitcode < 0 || exitcode > 125)
4907 return false;
4909 sWorld.ShutdownServ (time, SHUTDOWN_MASK_RESTART|SHUTDOWN_MASK_IDLE, exitcode);
4911 else
4912 sWorld.ShutdownServ(time,SHUTDOWN_MASK_RESTART|SHUTDOWN_MASK_IDLE,RESTART_EXIT_CODE);
4913 return true;
4916 bool ChatHandler::HandleServerIdleShutDownCommand(const char* args)
4918 if(!*args)
4919 return false;
4921 char* time_str = strtok ((char*) args, " ");
4922 char* exitcode_str = strtok (NULL, "");
4924 int32 time = atoi (time_str);
4926 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4927 if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0)
4928 return false;
4930 if (exitcode_str)
4932 int32 exitcode = atoi (exitcode_str);
4934 // Handle atoi() errors
4935 if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
4936 return false;
4938 // Exit code should be in range of 0-125, 126-255 is used
4939 // in many shells for their own return codes and code > 255
4940 // is not supported in many others
4941 if (exitcode < 0 || exitcode > 125)
4942 return false;
4944 sWorld.ShutdownServ (time, SHUTDOWN_MASK_IDLE, exitcode);
4946 else
4947 sWorld.ShutdownServ(time,SHUTDOWN_MASK_IDLE,SHUTDOWN_EXIT_CODE);
4948 return true;
4951 bool ChatHandler::HandleQuestAdd(const char* args)
4953 Player* player = getSelectedPlayer();
4954 if(!player)
4956 SendSysMessage(LANG_NO_CHAR_SELECTED);
4957 SetSentErrorMessage(true);
4958 return false;
4961 // .addquest #entry'
4962 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4963 char* cId = extractKeyFromLink((char*)args,"Hquest");
4964 if(!cId)
4965 return false;
4967 uint32 entry = atol(cId);
4969 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
4971 if(!pQuest)
4973 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND,entry);
4974 SetSentErrorMessage(true);
4975 return false;
4978 // check item starting quest (it can work incorrectly if added without item in inventory)
4979 for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
4981 ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype>(id);
4982 if (!pProto)
4983 continue;
4985 if (pProto->StartQuest == entry)
4987 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, entry, pProto->ItemId);
4988 SetSentErrorMessage(true);
4989 return false;
4993 // ok, normal (creature/GO starting) quest
4994 if( player->CanAddQuest( pQuest, true ) )
4996 player->AddQuest( pQuest, NULL );
4998 if ( player->CanCompleteQuest( entry ) )
4999 player->CompleteQuest( entry );
5002 return true;
5005 bool ChatHandler::HandleQuestRemove(const char* args)
5007 Player* player = getSelectedPlayer();
5008 if(!player)
5010 SendSysMessage(LANG_NO_CHAR_SELECTED);
5011 SetSentErrorMessage(true);
5012 return false;
5015 // .removequest #entry'
5016 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
5017 char* cId = extractKeyFromLink((char*)args,"Hquest");
5018 if(!cId)
5019 return false;
5021 uint32 entry = atol(cId);
5023 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
5025 if(!pQuest)
5027 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
5028 SetSentErrorMessage(true);
5029 return false;
5032 // remove all quest entries for 'entry' from quest log
5033 for(uint8 slot = 0; slot < MAX_QUEST_LOG_SIZE; ++slot )
5035 uint32 quest = player->GetQuestSlotQuestId(slot);
5036 if(quest==entry)
5038 player->SetQuestSlot(slot,0);
5040 // we ignore unequippable quest items in this case, its' still be equipped
5041 player->TakeQuestSourceItem( quest, false );
5045 // set quest status to not started (will updated in DB at next save)
5046 player->SetQuestStatus( entry, QUEST_STATUS_NONE);
5048 // reset rewarded for restart repeatable quest
5049 player->getQuestStatusMap()[entry].m_rewarded = false;
5051 SendSysMessage(LANG_COMMAND_QUEST_REMOVED);
5052 return true;
5055 bool ChatHandler::HandleQuestComplete(const char* args)
5057 Player* player = getSelectedPlayer();
5058 if(!player)
5060 SendSysMessage(LANG_NO_CHAR_SELECTED);
5061 SetSentErrorMessage(true);
5062 return false;
5065 // .quest complete #entry
5066 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
5067 char* cId = extractKeyFromLink((char*)args,"Hquest");
5068 if(!cId)
5069 return false;
5071 uint32 entry = atol(cId);
5073 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
5075 // If player doesn't have the quest
5076 if(!pQuest || player->GetQuestStatus(entry) == QUEST_STATUS_NONE)
5078 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
5079 SetSentErrorMessage(true);
5080 return false;
5083 // Add quest items for quests that require items
5084 for(uint8 x = 0; x < QUEST_OBJECTIVES_COUNT; ++x)
5086 uint32 id = pQuest->ReqItemId[x];
5087 uint32 count = pQuest->ReqItemCount[x];
5088 if(!id || !count)
5089 continue;
5091 uint32 curItemCount = player->GetItemCount(id,true);
5093 ItemPosCountVec dest;
5094 uint8 msg = player->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, id, count-curItemCount );
5095 if( msg == EQUIP_ERR_OK )
5097 Item* item = player->StoreNewItem( dest, id, true);
5098 player->SendNewItem(item,count-curItemCount,true,false);
5102 // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
5103 for(uint8 i = 0; i < QUEST_OBJECTIVES_COUNT; i++)
5105 uint32 creature = pQuest->ReqCreatureOrGOId[i];
5106 uint32 creaturecount = pQuest->ReqCreatureOrGOCount[i];
5108 if(uint32 spell_id = pQuest->ReqSpell[i])
5110 for(uint16 z = 0; z < creaturecount; ++z)
5111 player->CastedCreatureOrGO(creature,0,spell_id);
5113 else if(creature > 0)
5115 for(uint16 z = 0; z < creaturecount; ++z)
5116 player->KilledMonster(creature,0);
5118 else if(creature < 0)
5120 for(uint16 z = 0; z < creaturecount; ++z)
5121 player->CastedCreatureOrGO(creature,0,0);
5125 // If the quest requires reputation to complete
5126 if(uint32 repFaction = pQuest->GetRepObjectiveFaction())
5128 uint32 repValue = pQuest->GetRepObjectiveValue();
5129 uint32 curRep = player->GetReputationMgr().GetReputation(repFaction);
5130 if(curRep < repValue)
5131 if(FactionEntry const *factionEntry = sFactionStore.LookupEntry(repFaction))
5132 player->GetReputationMgr().SetReputation(factionEntry,repValue);
5135 // If the quest requires money
5136 int32 ReqOrRewMoney = pQuest->GetRewOrReqMoney();
5137 if(ReqOrRewMoney < 0)
5138 player->ModifyMoney(-ReqOrRewMoney);
5140 player->CompleteQuest(entry);
5141 return true;
5144 bool ChatHandler::HandleBanAccountCommand(const char* args)
5146 return HandleBanHelper(BAN_ACCOUNT,args);
5149 bool ChatHandler::HandleBanCharacterCommand(const char* args)
5151 return HandleBanHelper(BAN_CHARACTER,args);
5154 bool ChatHandler::HandleBanIPCommand(const char* args)
5156 return HandleBanHelper(BAN_IP,args);
5159 bool ChatHandler::HandleBanHelper(BanMode mode, const char* args)
5161 if (!*args)
5162 return false;
5164 char* cnameOrIP = strtok ((char*)args, " ");
5165 if (!cnameOrIP)
5166 return false;
5168 std::string nameOrIP = cnameOrIP;
5170 char* duration = strtok (NULL," ");
5171 if(!duration || !atoi(duration))
5172 return false;
5174 char* reason = strtok (NULL,"");
5175 if(!reason)
5176 return false;
5178 switch(mode)
5180 case BAN_ACCOUNT:
5181 if(!AccountMgr::normilizeString(nameOrIP))
5183 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str());
5184 SetSentErrorMessage(true);
5185 return false;
5187 break;
5188 case BAN_CHARACTER:
5189 if(!normalizePlayerName(nameOrIP))
5191 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5192 SetSentErrorMessage(true);
5193 return false;
5195 break;
5196 case BAN_IP:
5197 if(!IsIPAddress(nameOrIP.c_str()))
5198 return false;
5199 break;
5202 switch(sWorld.BanAccount(mode, nameOrIP, duration, reason,m_session ? m_session->GetPlayerName() : ""))
5204 case BAN_SUCCESS:
5205 if(atoi(duration)>0)
5206 PSendSysMessage(LANG_BAN_YOUBANNED,nameOrIP.c_str(),secsToTimeString(TimeStringToSecs(duration),true).c_str(),reason);
5207 else
5208 PSendSysMessage(LANG_BAN_YOUPERMBANNED,nameOrIP.c_str(),reason);
5209 break;
5210 case BAN_SYNTAX_ERROR:
5211 return false;
5212 case BAN_NOTFOUND:
5213 switch(mode)
5215 default:
5216 PSendSysMessage(LANG_BAN_NOTFOUND,"account",nameOrIP.c_str());
5217 break;
5218 case BAN_CHARACTER:
5219 PSendSysMessage(LANG_BAN_NOTFOUND,"character",nameOrIP.c_str());
5220 break;
5221 case BAN_IP:
5222 PSendSysMessage(LANG_BAN_NOTFOUND,"ip",nameOrIP.c_str());
5223 break;
5225 SetSentErrorMessage(true);
5226 return false;
5229 return true;
5232 bool ChatHandler::HandleUnBanAccountCommand(const char* args)
5234 return HandleUnBanHelper(BAN_ACCOUNT,args);
5237 bool ChatHandler::HandleUnBanCharacterCommand(const char* args)
5239 return HandleUnBanHelper(BAN_CHARACTER,args);
5242 bool ChatHandler::HandleUnBanIPCommand(const char* args)
5244 return HandleUnBanHelper(BAN_IP,args);
5247 bool ChatHandler::HandleUnBanHelper(BanMode mode, const char* args)
5249 if (!*args)
5250 return false;
5252 char* cnameOrIP = strtok ((char*)args, " ");
5253 if(!cnameOrIP)
5254 return false;
5256 std::string nameOrIP = cnameOrIP;
5258 switch(mode)
5260 case BAN_ACCOUNT:
5261 if(!AccountMgr::normilizeString(nameOrIP))
5263 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str());
5264 SetSentErrorMessage(true);
5265 return false;
5267 break;
5268 case BAN_CHARACTER:
5269 if(!normalizePlayerName(nameOrIP))
5271 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5272 SetSentErrorMessage(true);
5273 return false;
5275 break;
5276 case BAN_IP:
5277 if(!IsIPAddress(nameOrIP.c_str()))
5278 return false;
5279 break;
5282 if(sWorld.RemoveBanAccount(mode,nameOrIP))
5283 PSendSysMessage(LANG_UNBAN_UNBANNED,nameOrIP.c_str());
5284 else
5285 PSendSysMessage(LANG_UNBAN_ERROR,nameOrIP.c_str());
5287 return true;
5290 bool ChatHandler::HandleBanInfoAccountCommand(const char* args)
5292 if (!*args)
5293 return false;
5295 char* cname = strtok((char*)args, "");
5296 if(!cname)
5297 return false;
5299 std::string account_name = cname;
5300 if(!AccountMgr::normilizeString(account_name))
5302 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5303 SetSentErrorMessage(true);
5304 return false;
5307 uint32 accountid = accmgr.GetId(account_name);
5308 if(!accountid)
5310 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5311 return true;
5314 return HandleBanInfoHelper(accountid,account_name.c_str());
5317 bool ChatHandler::HandleBanInfoCharacterCommand(const char* args)
5319 if (!*args)
5320 return false;
5322 std::string name = extractPlayerNameFromLink((char*)args);
5323 if(name.empty())
5325 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5326 SetSentErrorMessage(true);
5327 return false;
5330 uint32 accountid = objmgr.GetPlayerAccountIdByPlayerName(name);
5331 if(!accountid)
5333 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5334 SetSentErrorMessage(true);
5335 return false;
5338 std::string accountname;
5339 if(!accmgr.GetName(accountid,accountname))
5341 PSendSysMessage(LANG_BANINFO_NOCHARACTER);
5342 return true;
5345 return HandleBanInfoHelper(accountid,accountname.c_str());
5348 bool ChatHandler::HandleBanInfoHelper(uint32 accountid, char const* accountname)
5350 QueryResult *result = loginDatabase.PQuery("SELECT FROM_UNIXTIME(bandate), unbandate-bandate, active, unbandate,banreason,bannedby FROM account_banned WHERE id = '%u' ORDER BY bandate ASC",accountid);
5351 if(!result)
5353 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN, accountname);
5354 return true;
5357 PSendSysMessage(LANG_BANINFO_BANHISTORY,accountname);
5360 Field* fields = result->Fetch();
5362 time_t unbandate = time_t(fields[3].GetUInt64());
5363 bool active = false;
5364 if(fields[2].GetBool() && (fields[1].GetUInt64() == (uint64)0 ||unbandate >= time(NULL)) )
5365 active = true;
5366 bool permanent = (fields[1].GetUInt64() == (uint64)0);
5367 std::string bantime = permanent?GetMangosString(LANG_BANINFO_INFINITE):secsToTimeString(fields[1].GetUInt64(), true);
5368 PSendSysMessage(LANG_BANINFO_HISTORYENTRY,
5369 fields[0].GetString(), bantime.c_str(), active ? GetMangosString(LANG_BANINFO_YES):GetMangosString(LANG_BANINFO_NO), fields[4].GetString(), fields[5].GetString());
5370 }while (result->NextRow());
5372 delete result;
5373 return true;
5376 bool ChatHandler::HandleBanInfoIPCommand(const char* args)
5378 if (!*args)
5379 return false;
5381 char* cIP = strtok ((char*)args, "");
5382 if(!cIP)
5383 return false;
5385 if (!IsIPAddress(cIP))
5386 return false;
5388 std::string IP = cIP;
5390 loginDatabase.escape_string(IP);
5391 QueryResult *result = loginDatabase.PQuery("SELECT ip, FROM_UNIXTIME(bandate), FROM_UNIXTIME(unbandate), unbandate-UNIX_TIMESTAMP(), banreason,bannedby,unbandate-bandate FROM ip_banned WHERE ip = '%s'",IP.c_str());
5392 if(!result)
5394 PSendSysMessage(LANG_BANINFO_NOIP);
5395 return true;
5398 Field *fields = result->Fetch();
5399 bool permanent = !fields[6].GetUInt64();
5400 PSendSysMessage(LANG_BANINFO_IPENTRY,
5401 fields[0].GetString(), fields[1].GetString(), permanent ? GetMangosString(LANG_BANINFO_NEVER):fields[2].GetString(),
5402 permanent ? GetMangosString(LANG_BANINFO_INFINITE):secsToTimeString(fields[3].GetUInt64(), true).c_str(), fields[4].GetString(), fields[5].GetString());
5403 delete result;
5404 return true;
5407 bool ChatHandler::HandleBanListCharacterCommand(const char* args)
5409 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5411 char* cFilter = strtok ((char*)args, " ");
5412 if(!cFilter)
5413 return false;
5415 std::string filter = cFilter;
5416 loginDatabase.escape_string(filter);
5417 QueryResult* result = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'"),filter.c_str());
5418 if (!result)
5420 PSendSysMessage(LANG_BANLIST_NOCHARACTER);
5421 return true;
5424 return HandleBanListHelper(result);
5427 bool ChatHandler::HandleBanListAccountCommand(const char* args)
5429 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5431 char* cFilter = strtok((char*)args, " ");
5432 std::string filter = cFilter ? cFilter : "";
5433 loginDatabase.escape_string(filter);
5435 QueryResult* result;
5437 if(filter.empty())
5439 result = loginDatabase.Query("SELECT account.id, username FROM account, account_banned"
5440 " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
5442 else
5444 result = loginDatabase.PQuery("SELECT account.id, username FROM account, account_banned"
5445 " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
5446 filter.c_str());
5449 if (!result)
5451 PSendSysMessage(LANG_BANLIST_NOACCOUNT);
5452 return true;
5455 return HandleBanListHelper(result);
5458 bool ChatHandler::HandleBanListHelper(QueryResult* result)
5460 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT);
5462 // Chat short output
5463 if(m_session)
5467 Field* fields = result->Fetch();
5468 uint32 accountid = fields[0].GetUInt32();
5470 QueryResult* banresult = loginDatabase.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid);
5471 if(banresult)
5473 Field* fields2 = banresult->Fetch();
5474 PSendSysMessage("%s",fields2[0].GetString());
5475 delete banresult;
5477 } while (result->NextRow());
5479 // Console wide output
5480 else
5482 SendSysMessage(LANG_BANLIST_ACCOUNTS);
5483 SendSysMessage("===============================================================================");
5484 SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER);
5487 SendSysMessage("-------------------------------------------------------------------------------");
5488 Field *fields = result->Fetch();
5489 uint32 account_id = fields[0].GetUInt32 ();
5491 std::string account_name;
5493 // "account" case, name can be get in same query
5494 if(result->GetFieldCount() > 1)
5495 account_name = fields[1].GetCppString();
5496 // "character" case, name need extract from another DB
5497 else
5498 accmgr.GetName (account_id,account_name);
5500 // No SQL injection. id is uint32.
5501 QueryResult *banInfo = loginDatabase.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id);
5502 if (banInfo)
5504 Field *fields2 = banInfo->Fetch();
5507 time_t t_ban = fields2[0].GetUInt64();
5508 tm* aTm_ban = localtime(&t_ban);
5510 if (fields2[0].GetUInt64() == fields2[1].GetUInt64())
5512 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5513 account_name.c_str(),aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min,
5514 fields2[2].GetString(),fields2[3].GetString());
5516 else
5518 time_t t_unban = fields2[1].GetUInt64();
5519 tm* aTm_unban = localtime(&t_unban);
5520 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5521 account_name.c_str(),aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min,
5522 aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
5523 fields2[2].GetString(),fields2[3].GetString());
5525 }while ( banInfo->NextRow() );
5526 delete banInfo;
5528 }while( result->NextRow() );
5529 SendSysMessage("===============================================================================");
5532 delete result;
5533 return true;
5536 bool ChatHandler::HandleBanListIPCommand(const char* args)
5538 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5540 char* cFilter = strtok((char*)args, " ");
5541 std::string filter = cFilter ? cFilter : "";
5542 loginDatabase.escape_string(filter);
5544 QueryResult* result;
5546 if(filter.empty())
5548 result = loginDatabase.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5549 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
5550 " ORDER BY unbandate" );
5552 else
5554 result = loginDatabase.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5555 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")
5556 " ORDER BY unbandate",filter.c_str() );
5559 if(!result)
5561 PSendSysMessage(LANG_BANLIST_NOIP);
5562 return true;
5565 PSendSysMessage(LANG_BANLIST_MATCHINGIP);
5566 // Chat short output
5567 if(m_session)
5571 Field* fields = result->Fetch();
5572 PSendSysMessage("%s",fields[0].GetString());
5573 } while (result->NextRow());
5575 // Console wide output
5576 else
5578 SendSysMessage(LANG_BANLIST_IPS);
5579 SendSysMessage("===============================================================================");
5580 SendSysMessage(LANG_BANLIST_IPS_HEADER);
5583 SendSysMessage("-------------------------------------------------------------------------------");
5584 Field *fields = result->Fetch();
5585 time_t t_ban = fields[1].GetUInt64();
5586 tm* aTm_ban = localtime(&t_ban);
5587 if ( fields[1].GetUInt64() == fields[2].GetUInt64() )
5589 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5590 fields[0].GetString(), aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min,
5591 fields[3].GetString(), fields[4].GetString());
5593 else
5595 time_t t_unban = fields[2].GetUInt64();
5596 tm* aTm_unban = localtime(&t_unban);
5597 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5598 fields[0].GetString(), aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min,
5599 aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
5600 fields[3].GetString(), fields[4].GetString());
5602 }while( result->NextRow() );
5603 SendSysMessage("===============================================================================");
5606 delete result;
5607 return true;
5610 bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
5612 Player* pl = m_session->GetPlayer();
5614 // accept only explicitly selected target (not implicitly self targeting case)
5615 Unit* target = getSelectedUnit();
5616 if(pl->GetSelection() && target)
5618 if(target->GetTypeId()!=TYPEID_UNIT)
5620 SendSysMessage(LANG_SELECT_CREATURE);
5621 SetSentErrorMessage(true);
5622 return false;
5625 if(target->isDead())
5626 ((Creature*)target)->Respawn();
5627 return true;
5630 CellPair p(MaNGOS::ComputeCellPair(pl->GetPositionX(), pl->GetPositionY()));
5631 Cell cell(p);
5632 cell.data.Part.reserved = ALL_DISTRICT;
5633 cell.SetNoCreate();
5635 MaNGOS::RespawnDo u_do;
5636 MaNGOS::WorldObjectWorker<MaNGOS::RespawnDo> worker(pl,u_do);
5638 TypeContainerVisitor<MaNGOS::WorldObjectWorker<MaNGOS::RespawnDo>, GridTypeMapContainer > obj_worker(worker);
5639 CellLock<GridReadGuard> cell_lock(cell, p);
5640 cell_lock->Visit(cell_lock, obj_worker, *pl->GetMap());
5642 return true;
5645 bool ChatHandler::HandleGMFlyCommand(const char* args)
5647 if (!*args)
5648 return false;
5650 Player *target = getSelectedPlayer();
5651 if (!target)
5652 target = m_session->GetPlayer();
5654 WorldPacket data(12);
5655 if (strncmp(args, "on", 3) == 0)
5656 data.SetOpcode(SMSG_MOVE_SET_CAN_FLY);
5657 else if (strncmp(args, "off", 4) == 0)
5658 data.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY);
5659 else
5661 SendSysMessage(LANG_USE_BOL);
5662 return false;
5664 data.append(target->GetPackGUID());
5665 data << uint32(0); // unknown
5666 target->SendMessageToSet(&data, true);
5667 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS, GetNameLink(target).c_str(), args);
5668 return true;
5671 bool ChatHandler::HandlePDumpLoadCommand(const char *args)
5673 if (!*args)
5674 return false;
5676 char * file = strtok((char*)args, " ");
5677 if(!file)
5678 return false;
5680 char * account = strtok(NULL, " ");
5681 if(!account)
5682 return false;
5684 std::string account_name = account;
5685 if(!AccountMgr::normilizeString(account_name))
5687 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5688 SetSentErrorMessage(true);
5689 return false;
5692 uint32 account_id = accmgr.GetId(account_name);
5693 if(!account_id)
5695 account_id = atoi(account); // use original string
5696 if(!account_id)
5698 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5699 SetSentErrorMessage(true);
5700 return false;
5704 if(!accmgr.GetName(account_id,account_name))
5706 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5707 SetSentErrorMessage(true);
5708 return false;
5711 char* guid_str = NULL;
5712 char* name_str = strtok(NULL, " ");
5714 std::string name;
5715 if(name_str)
5717 name = name_str;
5718 // normalize the name if specified and check if it exists
5719 if(!normalizePlayerName(name))
5721 PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
5722 SetSentErrorMessage(true);
5723 return false;
5726 if(!ObjectMgr::IsValidName(name,true))
5728 PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
5729 SetSentErrorMessage(true);
5730 return false;
5733 guid_str = strtok(NULL, " ");
5736 uint32 guid = 0;
5738 if(guid_str)
5740 guid = atoi(guid_str);
5741 if(!guid)
5743 PSendSysMessage(LANG_INVALID_CHARACTER_GUID);
5744 SetSentErrorMessage(true);
5745 return false;
5748 if(objmgr.GetPlayerAccountIdByGUID(guid))
5750 PSendSysMessage(LANG_CHARACTER_GUID_IN_USE,guid);
5751 SetSentErrorMessage(true);
5752 return false;
5756 switch(PlayerDumpReader().LoadDump(file, account_id, name, guid))
5758 case DUMP_SUCCESS:
5759 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS);
5760 break;
5761 case DUMP_FILE_OPEN_ERROR:
5762 PSendSysMessage(LANG_FILE_OPEN_FAIL,file);
5763 SetSentErrorMessage(true);
5764 return false;
5765 case DUMP_FILE_BROKEN:
5766 PSendSysMessage(LANG_DUMP_BROKEN,file);
5767 SetSentErrorMessage(true);
5768 return false;
5769 case DUMP_TOO_MANY_CHARS:
5770 PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL,account_name.c_str(),account_id);
5771 SetSentErrorMessage(true);
5772 return false;
5773 default:
5774 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED);
5775 SetSentErrorMessage(true);
5776 return false;
5779 return true;
5782 bool ChatHandler::HandlePDumpWriteCommand(const char *args)
5784 if (!*args)
5785 return false;
5787 char* file = strtok((char*)args, " ");
5788 char* p2 = strtok(NULL, " ");
5790 if(!file || !p2)
5791 return false;
5793 uint32 guid;
5794 // character name can't start from number
5795 if (isNumeric(p2[0]))
5796 guid = atoi(p2);
5797 else
5799 std::string name = extractPlayerNameFromLink(p2);
5800 if(name.empty())
5802 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5803 SetSentErrorMessage(true);
5804 return false;
5807 guid = objmgr.GetPlayerGUIDByName(name);
5810 if(!objmgr.GetPlayerAccountIdByGUID(guid))
5812 PSendSysMessage(LANG_PLAYER_NOT_FOUND);
5813 SetSentErrorMessage(true);
5814 return false;
5817 switch(PlayerDumpWriter().WriteDump(file, guid))
5819 case DUMP_SUCCESS:
5820 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS);
5821 break;
5822 case DUMP_FILE_OPEN_ERROR:
5823 PSendSysMessage(LANG_FILE_OPEN_FAIL,file);
5824 SetSentErrorMessage(true);
5825 return false;
5826 default:
5827 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED);
5828 SetSentErrorMessage(true);
5829 return false;
5832 return true;
5835 bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
5837 Unit* unit = getSelectedUnit();
5838 if(!unit)
5840 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5841 SetSentErrorMessage(true);
5842 return false;
5845 PSendSysMessage(LANG_MOVEGENS_LIST,(unit->GetTypeId()==TYPEID_PLAYER ? "Player" : "Creature" ),unit->GetGUIDLow());
5847 MotionMaster* mm = unit->GetMotionMaster();
5848 for(MotionMaster::const_iterator itr = mm->begin(); itr != mm->end(); ++itr)
5850 switch((*itr)->GetMovementGeneratorType())
5852 case IDLE_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_IDLE); break;
5853 case RANDOM_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_RANDOM); break;
5854 case WAYPOINT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_WAYPOINT); break;
5855 case ANIMAL_RANDOM_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_ANIMAL_RANDOM); break;
5856 case CONFUSED_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_CONFUSED); break;
5857 case TARGETED_MOTION_TYPE:
5859 if(unit->GetTypeId()==TYPEID_PLAYER)
5861 TargetedMovementGenerator<Player> const* mgen = static_cast<TargetedMovementGenerator<Player> const*>(*itr);
5862 Unit* target = mgen->GetTarget();
5863 if(target)
5864 PSendSysMessage(LANG_MOVEGENS_TARGETED_PLAYER,target->GetName(),target->GetGUIDLow());
5865 else
5866 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL);
5868 else
5870 TargetedMovementGenerator<Creature> const* mgen = static_cast<TargetedMovementGenerator<Creature> const*>(*itr);
5871 Unit* target = mgen->GetTarget();
5872 if(target)
5873 PSendSysMessage(LANG_MOVEGENS_TARGETED_CREATURE,target->GetName(),target->GetGUIDLow());
5874 else
5875 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL);
5877 break;
5879 case HOME_MOTION_TYPE:
5880 if(unit->GetTypeId()==TYPEID_UNIT)
5882 float x,y,z;
5883 (*itr)->GetDestination(x,y,z);
5884 PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE,x,y,z);
5886 else
5887 SendSysMessage(LANG_MOVEGENS_HOME_PLAYER);
5888 break;
5889 case FLIGHT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FLIGHT); break;
5890 case POINT_MOTION_TYPE:
5892 float x,y,z;
5893 (*itr)->GetDestination(x,y,z);
5894 PSendSysMessage(LANG_MOVEGENS_POINT,x,y,z);
5895 break;
5897 case FLEEING_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FEAR); break;
5898 case DISTRACT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_DISTRACT); break;
5899 default:
5900 PSendSysMessage(LANG_MOVEGENS_UNKNOWN,(*itr)->GetMovementGeneratorType());
5901 break;
5904 return true;
5907 bool ChatHandler::HandlePLimitCommand(const char *args)
5909 if(*args)
5911 char* param = strtok((char*)args, " ");
5912 if(!param)
5913 return false;
5915 int l = strlen(param);
5917 if( strncmp(param,"player",l) == 0 )
5918 sWorld.SetPlayerLimit(-SEC_PLAYER);
5919 else if(strncmp(param,"moderator",l) == 0 )
5920 sWorld.SetPlayerLimit(-SEC_MODERATOR);
5921 else if(strncmp(param,"gamemaster",l) == 0 )
5922 sWorld.SetPlayerLimit(-SEC_GAMEMASTER);
5923 else if(strncmp(param,"administrator",l) == 0 )
5924 sWorld.SetPlayerLimit(-SEC_ADMINISTRATOR);
5925 else if(strncmp(param,"reset",l) == 0 )
5926 sWorld.SetPlayerLimit( sConfig.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT) );
5927 else
5929 int val = atoi(param);
5930 if(val < -SEC_ADMINISTRATOR) val = -SEC_ADMINISTRATOR;
5932 sWorld.SetPlayerLimit(val);
5935 // kick all low security level players
5936 if(sWorld.GetPlayerAmountLimit() > SEC_PLAYER)
5937 sWorld.KickAllLess(sWorld.GetPlayerSecurityLimit());
5940 uint32 pLimit = sWorld.GetPlayerAmountLimit();
5941 AccountTypes allowedAccountType = sWorld.GetPlayerSecurityLimit();
5942 char const* secName = "";
5943 switch(allowedAccountType)
5945 case SEC_PLAYER: secName = "Player"; break;
5946 case SEC_MODERATOR: secName = "Moderator"; break;
5947 case SEC_GAMEMASTER: secName = "Gamemaster"; break;
5948 case SEC_ADMINISTRATOR: secName = "Administrator"; break;
5949 default: secName = "<unknown>"; break;
5952 PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit,secName);
5954 return true;
5957 bool ChatHandler::HandleCastCommand(const char* args)
5959 if(!*args)
5960 return false;
5962 Unit* target = getSelectedUnit();
5964 if(!target)
5966 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5967 SetSentErrorMessage(true);
5968 return false;
5971 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5972 uint32 spell = extractSpellIdFromLink((char*)args);
5973 if(!spell)
5974 return false;
5976 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
5977 if(!spellInfo)
5978 return false;
5980 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
5982 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
5983 SetSentErrorMessage(true);
5984 return false;
5987 char* trig_str = strtok(NULL, " ");
5988 if(trig_str)
5990 int l = strlen(trig_str);
5991 if(strncmp(trig_str,"triggered",l) != 0 )
5992 return false;
5995 bool triggered = (trig_str != NULL);
5997 m_session->GetPlayer()->CastSpell(target,spell,triggered);
5999 return true;
6002 bool ChatHandler::HandleCastBackCommand(const char* args)
6004 Creature* caster = getSelectedCreature();
6006 if(!caster)
6008 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
6009 SetSentErrorMessage(true);
6010 return false;
6013 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
6014 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6015 uint32 spell = extractSpellIdFromLink((char*)args);
6016 if(!spell || !sSpellStore.LookupEntry(spell))
6017 return false;
6019 char* trig_str = strtok(NULL, " ");
6020 if(trig_str)
6022 int l = strlen(trig_str);
6023 if(strncmp(trig_str,"triggered",l) != 0 )
6024 return false;
6027 bool triggered = (trig_str != NULL);
6029 // update orientation at server
6030 caster->SetOrientation(caster->GetAngle(m_session->GetPlayer()));
6032 // and client
6033 WorldPacket data;
6034 caster->BuildHeartBeatMsg(&data);
6035 caster->SendMessageToSet(&data,true);
6037 caster->CastSpell(m_session->GetPlayer(),spell,triggered);
6039 return true;
6042 bool ChatHandler::HandleCastDistCommand(const char* args)
6044 if(!*args)
6045 return false;
6047 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6048 uint32 spell = extractSpellIdFromLink((char*)args);
6049 if(!spell)
6050 return false;
6052 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
6053 if(!spellInfo)
6054 return false;
6056 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
6058 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
6059 SetSentErrorMessage(true);
6060 return false;
6063 char *distStr = strtok(NULL, " ");
6065 float dist = 0;
6067 if(distStr)
6068 sscanf(distStr, "%f", &dist);
6070 char* trig_str = strtok(NULL, " ");
6071 if(trig_str)
6073 int l = strlen(trig_str);
6074 if(strncmp(trig_str,"triggered",l) != 0 )
6075 return false;
6078 bool triggered = (trig_str != NULL);
6080 float x,y,z;
6081 m_session->GetPlayer()->GetClosePoint(x,y,z,dist);
6083 m_session->GetPlayer()->CastSpell(x,y,z,spell,triggered);
6084 return true;
6087 bool ChatHandler::HandleCastTargetCommand(const char* args)
6089 Creature* caster = getSelectedCreature();
6091 if(!caster)
6093 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
6094 SetSentErrorMessage(true);
6095 return false;
6098 if(!caster->getVictim())
6100 SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM);
6101 SetSentErrorMessage(true);
6102 return false;
6105 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6106 uint32 spell = extractSpellIdFromLink((char*)args);
6107 if(!spell || !sSpellStore.LookupEntry(spell))
6108 return false;
6110 char* trig_str = strtok(NULL, " ");
6111 if(trig_str)
6113 int l = strlen(trig_str);
6114 if(strncmp(trig_str,"triggered",l) != 0 )
6115 return false;
6118 bool triggered = (trig_str != NULL);
6120 // update orientation at server
6121 caster->SetOrientation(caster->GetAngle(m_session->GetPlayer()));
6123 // and client
6124 WorldPacket data;
6125 caster->BuildHeartBeatMsg(&data);
6126 caster->SendMessageToSet(&data,true);
6128 caster->CastSpell(caster->getVictim(),spell,triggered);
6130 return true;
6134 ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
6135 Without this function 3rd party scripting library will get linking errors (unresolved external)
6136 when attempting to use the PointMovementGenerator
6138 bool ChatHandler::HandleComeToMeCommand(const char *args)
6140 Creature* caster = getSelectedCreature();
6142 if(!caster)
6144 SendSysMessage(LANG_SELECT_CREATURE);
6145 SetSentErrorMessage(true);
6146 return false;
6149 char* newFlagStr = strtok((char*)args, " ");
6151 if(!newFlagStr)
6152 return false;
6154 uint32 newFlags = atoi(newFlagStr);
6156 caster->SetUnitMovementFlags(newFlags);
6158 Player* pl = m_session->GetPlayer();
6160 caster->GetMotionMaster()->MovePoint(0, pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ());
6161 return true;
6164 bool ChatHandler::HandleCastSelfCommand(const char* args)
6166 if(!*args)
6167 return false;
6169 Unit* target = getSelectedUnit();
6171 if(!target)
6173 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
6174 SetSentErrorMessage(true);
6175 return false;
6178 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6179 uint32 spell = extractSpellIdFromLink((char*)args);
6180 if(!spell)
6181 return false;
6183 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
6184 if(!spellInfo)
6185 return false;
6187 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
6189 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
6190 SetSentErrorMessage(true);
6191 return false;
6194 target->CastSpell(target,spell,false);
6196 return true;
6199 std::string GetTimeString(uint32 time)
6201 uint16 days = time / DAY, hours = (time % DAY) / HOUR, minute = (time % HOUR) / MINUTE;
6202 std::ostringstream ss;
6203 if(days) ss << days << "d ";
6204 if(hours) ss << hours << "h ";
6205 ss << minute << "m";
6206 return ss.str();
6209 bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
6211 Player* player = getSelectedPlayer();
6212 if (!player) player = m_session->GetPlayer();
6213 uint32 counter = 0;
6214 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; i++)
6216 Player::BoundInstancesMap &binds = player->GetBoundInstances(i);
6217 for(Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end(); ++itr)
6219 InstanceSave *save = itr->second.save;
6220 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
6221 PSendSysMessage("map: %d inst: %d perm: %s diff: %s canReset: %s TTR: %s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty() == DIFFICULTY_NORMAL ? "normal" : "heroic", save->CanReset() ? "yes" : "no", timeleft.c_str());
6222 counter++;
6225 PSendSysMessage("player binds: %d", counter);
6226 counter = 0;
6227 Group *group = player->GetGroup();
6228 if(group)
6230 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; i++)
6232 Group::BoundInstancesMap &binds = group->GetBoundInstances(i);
6233 for(Group::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end(); ++itr)
6235 InstanceSave *save = itr->second.save;
6236 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
6237 PSendSysMessage("map: %d inst: %d perm: %s diff: %s canReset: %s TTR: %s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty() == DIFFICULTY_NORMAL ? "normal" : "heroic", save->CanReset() ? "yes" : "no", timeleft.c_str());
6238 counter++;
6242 PSendSysMessage("group binds: %d", counter);
6244 return true;
6247 bool ChatHandler::HandleInstanceUnbindCommand(const char* args)
6249 if(!*args)
6250 return false;
6252 std::string cmd = args;
6253 if(cmd == "all")
6255 Player* player = getSelectedPlayer();
6256 if (!player) player = m_session->GetPlayer();
6257 uint32 counter = 0;
6258 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; i++)
6260 Player::BoundInstancesMap &binds = player->GetBoundInstances(i);
6261 for(Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end();)
6263 if(itr->first != player->GetMapId())
6265 InstanceSave *save = itr->second.save;
6266 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
6267 PSendSysMessage("unbinding map: %d inst: %d perm: %s diff: %s canReset: %s TTR: %s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty() == DIFFICULTY_NORMAL ? "normal" : "heroic", save->CanReset() ? "yes" : "no", timeleft.c_str());
6268 player->UnbindInstance(itr, i);
6269 counter++;
6271 else
6272 ++itr;
6275 PSendSysMessage("instances unbound: %d", counter);
6277 return true;
6280 bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
6282 PSendSysMessage("instances loaded: %d", MapManager::Instance().GetNumInstances());
6283 PSendSysMessage("players in instances: %d", MapManager::Instance().GetNumPlayersInInstances());
6284 PSendSysMessage("instance saves: %d", sInstanceSaveManager.GetNumInstanceSaves());
6285 PSendSysMessage("players bound: %d", sInstanceSaveManager.GetNumBoundPlayersTotal());
6286 PSendSysMessage("groups bound: %d", sInstanceSaveManager.GetNumBoundGroupsTotal());
6287 return true;
6290 bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
6292 Player* pl = m_session->GetPlayer();
6294 Map* map = pl->GetMap();
6295 if (!map->IsDungeon())
6297 PSendSysMessage("Map is not a dungeon.");
6298 SetSentErrorMessage(true);
6299 return false;
6302 if (!((InstanceMap*)map)->GetInstanceData())
6304 PSendSysMessage("Map has no instance data.");
6305 SetSentErrorMessage(true);
6306 return false;
6309 ((InstanceMap*)map)->GetInstanceData()->SaveToDB();
6310 return true;
6313 /// Display the list of GMs
6314 bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
6316 ///- Get the accounts with GM Level >0
6317 QueryResult *result = loginDatabase.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
6318 if(result)
6320 SendSysMessage(LANG_GMLIST);
6321 SendSysMessage("========================");
6322 SendSysMessage(LANG_GMLIST_HEADER);
6323 SendSysMessage("========================");
6325 ///- Circle through them. Display username and GM level
6328 Field *fields = result->Fetch();
6329 PSendSysMessage("|%15s|%6s|", fields[0].GetString(),fields[1].GetString());
6330 }while( result->NextRow() );
6332 PSendSysMessage("========================");
6333 delete result;
6335 else
6336 PSendSysMessage(LANG_GMLIST_EMPTY);
6337 return true;
6340 /// Define the 'Message of the day' for the realm
6341 bool ChatHandler::HandleServerSetMotdCommand(const char* args)
6343 sWorld.SetMotd(args);
6344 PSendSysMessage(LANG_MOTD_NEW, args);
6345 return true;
6348 /// Set/Unset the expansion level for an account
6349 bool ChatHandler::HandleAccountSetAddonCommand(const char* args)
6351 ///- Get the command line arguments
6352 char *szAcc = strtok((char*)args," ");
6353 char *szExp = strtok(NULL," ");
6355 if(!szAcc)
6356 return false;
6358 std::string account_name;
6359 uint32 account_id;
6361 if(!szExp)
6363 Player* player = getSelectedPlayer();
6364 if(!player)
6365 return false;
6367 account_id = player->GetSession()->GetAccountId();
6368 accmgr.GetName(account_id,account_name);
6369 szExp = szAcc;
6371 else
6373 ///- Convert Account name to Upper Format
6374 account_name = szAcc;
6375 if(!AccountMgr::normilizeString(account_name))
6377 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
6378 SetSentErrorMessage(true);
6379 return false;
6382 account_id = accmgr.GetId(account_name);
6383 if(!account_id)
6385 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
6386 SetSentErrorMessage(true);
6387 return false;
6392 // Let set addon state only for lesser (strong) security level
6393 // or to self account
6394 if (m_session && m_session->GetAccountId () != account_id &&
6395 HasLowerSecurityAccount (NULL,account_id,true))
6396 return false;
6398 int lev=atoi(szExp); //get int anyway (0 if error)
6399 if(lev < 0)
6400 return false;
6402 // No SQL injection
6403 loginDatabase.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev,account_id);
6404 PSendSysMessage(LANG_ACCOUNT_SETADDON,account_name.c_str(),account_id,lev);
6405 return true;
6408 //Send items by mail
6409 bool ChatHandler::HandleSendItemsCommand(const char* args)
6411 if(!*args)
6412 return false;
6414 // format: name "subject text" "mail text" item1[:count1] item2[:count2] ... item12[:count12]
6416 std::string name = extractPlayerNameFromLink((char*)args);
6417 if(name.empty())
6419 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6420 SetSentErrorMessage(true);
6421 return false;
6424 char* tail1 = strtok(NULL, "");
6425 if(!tail1)
6426 return false;
6428 char* msgSubject;
6429 if(*tail1=='"')
6430 msgSubject = strtok(tail1+1, "\"");
6431 else
6433 char* space = strtok(tail1, "\"");
6434 if(!space)
6435 return false;
6436 msgSubject = strtok(NULL, "\"");
6439 if (!msgSubject)
6440 return false;
6442 char* tail2 = strtok(NULL, "");
6443 if(!tail2)
6444 return false;
6446 char* msgText;
6447 if(*tail2=='"')
6448 msgText = strtok(tail2+1, "\"");
6449 else
6451 char* space = strtok(tail2, "\"");
6452 if(!space)
6453 return false;
6454 msgText = strtok(NULL, "\"");
6457 if (!msgText)
6458 return false;
6460 // msgSubject, msgText isn't NUL after prev. check
6461 std::string subject = msgSubject;
6462 std::string text = msgText;
6464 // extract items
6465 typedef std::pair<uint32,uint32> ItemPair;
6466 typedef std::list< ItemPair > ItemPairs;
6467 ItemPairs items;
6469 // get all tail string
6470 char* tail = strtok(NULL, "");
6472 // get from tail next item str
6473 while(char* itemStr = strtok(tail, " "))
6475 // and get new tail
6476 tail = strtok(NULL, "");
6478 // parse item str
6479 char* itemIdStr = strtok(itemStr, ":");
6480 char* itemCountStr = strtok(NULL, " ");
6482 uint32 item_id = atoi(itemIdStr);
6483 if(!item_id)
6484 return false;
6486 ItemPrototype const* item_proto = objmgr.GetItemPrototype(item_id);
6487 if(!item_proto)
6489 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
6490 SetSentErrorMessage(true);
6491 return false;
6494 uint32 item_count = itemCountStr ? atoi(itemCountStr) : 1;
6495 if(item_count < 1 || item_proto->MaxCount > 0 && item_count > uint32(item_proto->MaxCount))
6497 PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT, item_count,item_id);
6498 SetSentErrorMessage(true);
6499 return false;
6502 while(item_count > item_proto->GetMaxStackSize())
6504 items.push_back(ItemPair(item_id,item_proto->GetMaxStackSize()));
6505 item_count -= item_proto->GetMaxStackSize();
6508 items.push_back(ItemPair(item_id,item_count));
6510 if(items.size() > MAX_MAIL_ITEMS)
6512 PSendSysMessage(LANG_COMMAND_MAIL_ITEMS_LIMIT, MAX_MAIL_ITEMS);
6513 SetSentErrorMessage(true);
6514 return false;
6518 uint64 receiver_guid = objmgr.GetPlayerGUIDByName(name);
6519 if(!receiver_guid)
6521 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6522 SetSentErrorMessage(true);
6523 return false;
6526 // from console show not existed sender
6527 uint32 sender_guidlo = m_session ? m_session->GetPlayer()->GetGUIDLow() : 0;
6529 uint32 messagetype = MAIL_NORMAL;
6530 uint32 stationery = MAIL_STATIONERY_GM;
6531 uint32 itemTextId = !text.empty() ? objmgr.CreateItemText( text ) : 0;
6533 Player *receiver = objmgr.GetPlayer(receiver_guid);
6535 // fill mail
6536 MailItemsInfo mi; // item list preparing
6538 for(ItemPairs::const_iterator itr = items.begin(); itr != items.end(); ++itr)
6540 if(Item* item = Item::CreateItem(itr->first,itr->second,m_session ? m_session->GetPlayer() : 0))
6542 item->SaveToDB(); // save for prevent lost at next mail load, if send fail then item will deleted
6543 mi.AddItem(item->GetGUIDLow(), item->GetEntry(), item);
6547 WorldSession::SendMailTo(receiver,messagetype, stationery, sender_guidlo, GUID_LOPART(receiver_guid), subject, itemTextId, &mi, 0, 0, MAIL_CHECK_MASK_NONE);
6549 std::string nameLink = playerLink(name);
6550 PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
6551 return true;
6554 ///Send money by mail
6555 bool ChatHandler::HandleSendMoneyCommand(const char* args)
6557 if (!*args)
6558 return false;
6560 /// format: name "subject text" "mail text" money
6562 std::string name = extractPlayerNameFromLink((char*)args);
6563 if(name.empty())
6565 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6566 SetSentErrorMessage(true);
6567 return false;
6570 char* tail1 = strtok(NULL, "");
6571 if (!tail1)
6572 return false;
6574 char* msgSubject;
6575 if (*tail1=='"')
6576 msgSubject = strtok(tail1+1, "\"");
6577 else
6579 char* space = strtok(tail1, "\"");
6580 if (!space)
6581 return false;
6582 msgSubject = strtok(NULL, "\"");
6585 if (!msgSubject)
6586 return false;
6588 char* tail2 = strtok(NULL, "");
6589 if (!tail2)
6590 return false;
6592 char* msgText;
6593 if (*tail2=='"')
6594 msgText = strtok(tail2+1, "\"");
6595 else
6597 char* space = strtok(tail2, "\"");
6598 if (!space)
6599 return false;
6600 msgText = strtok(NULL, "\"");
6603 if (!msgText)
6604 return false;
6606 char* money_str = strtok(NULL, "");
6607 int32 money = money_str ? atoi(money_str) : 0;
6608 if (money <= 0)
6609 return false;
6611 // msgSubject, msgText isn't NUL after prev. check
6612 std::string subject = msgSubject;
6613 std::string text = msgText;
6615 uint64 receiver_guid = objmgr.GetPlayerGUIDByName(name);
6616 if (!receiver_guid)
6618 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6619 SetSentErrorMessage(true);
6620 return false;
6623 // from console show not existed sender
6624 uint32 sender_guidlo = m_session ? m_session->GetPlayer()->GetGUIDLow() : 0;
6626 uint32 messagetype = MAIL_NORMAL;
6627 uint32 stationery = MAIL_STATIONERY_GM;
6628 uint32 itemTextId = !text.empty() ? objmgr.CreateItemText( text ) : 0;
6630 Player *receiver = objmgr.GetPlayer(receiver_guid);
6632 WorldSession::SendMailTo(receiver,messagetype, stationery, sender_guidlo, GUID_LOPART(receiver_guid), subject, itemTextId, NULL, money, 0, MAIL_CHECK_MASK_NONE);
6634 std::string nameLink = playerLink(name);
6635 PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
6636 return true;
6639 /// Send a message to a player in game
6640 bool ChatHandler::HandleSendMessageCommand(const char* args)
6642 ///- Get the command line arguments
6643 std::string name = extractPlayerNameFromLink((char*)args);
6644 if(name.empty())
6646 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6647 SetSentErrorMessage(true);
6648 return false;
6651 char* msg_str = strtok(NULL, "");
6652 if(!msg_str)
6653 return false;
6655 ///- Find the player and check that he is not logging out.
6656 Player *rPlayer = objmgr.GetPlayer(name.c_str());
6657 if(!rPlayer)
6659 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6660 SetSentErrorMessage(true);
6661 return false;
6664 if(rPlayer->GetSession()->isLogingOut())
6666 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6667 SetSentErrorMessage(true);
6668 return false;
6671 ///- Send the message
6672 //Use SendAreaTriggerMessage for fastest delivery.
6673 rPlayer->GetSession()->SendAreaTriggerMessage("%s", msg_str);
6674 rPlayer->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
6676 //Confirmation message
6677 std::string nameLink = playerLink(name);
6678 PSendSysMessage(LANG_SENDMESSAGE,nameLink.c_str(),msg_str);
6679 return true;
6682 bool ChatHandler::HandleFlushArenaPointsCommand(const char * /*args*/)
6684 sBattleGroundMgr.DistributeArenaPoints();
6685 return true;
6688 bool ChatHandler::HandleModifyGenderCommand(const char *args)
6690 if(!*args)
6691 return false;
6693 Player *player = getSelectedPlayer();
6695 if(!player)
6697 PSendSysMessage(LANG_NO_PLAYER);
6698 SetSentErrorMessage(true);
6699 return false;
6702 PlayerInfo const* info = objmgr.GetPlayerInfo(player->getRace(), player->getClass());
6703 if(!info)
6704 return false;
6706 char const* gender_str = (char*)args;
6707 int gender_len = strlen(gender_str);
6709 Gender gender;
6711 if(!strncmp(gender_str, "male", gender_len)) // MALE
6713 if(player->getGender() == GENDER_MALE)
6714 return true;
6716 gender = GENDER_MALE;
6718 else if (!strncmp(gender_str, "female", gender_len)) // FEMALE
6720 if(player->getGender() == GENDER_FEMALE)
6721 return true;
6723 gender = GENDER_FEMALE;
6725 else
6727 SendSysMessage(LANG_MUST_MALE_OR_FEMALE);
6728 SetSentErrorMessage(true);
6729 return false;
6732 // Set gender
6733 player->SetByteValue(UNIT_FIELD_BYTES_0, 2, gender);
6734 player->SetByteValue(PLAYER_BYTES_3, 0, gender);
6736 // Change display ID
6737 player->SetDisplayId(gender ? info->displayId_f : info->displayId_m);
6738 player->SetNativeDisplayId(gender ? info->displayId_f : info->displayId_m);
6740 char const* gender_full = gender ? "female" : "male";
6742 PSendSysMessage(LANG_YOU_CHANGE_GENDER, GetNameLink(player).c_str(), gender_full);
6744 if (needReportToTarget(player))
6745 ChatHandler(player).PSendSysMessage(LANG_YOUR_GENDER_CHANGED, gender_full, GetNameLink().c_str());
6747 return true;