[7706] Rename command .plimit -> .server plimit
[AHbot.git] / src / game / Level3.cpp
blob4f904a0d4fc9c9ff6cffba02e04da1d6c7b58501
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* player = NULL;
3443 uint64 player_guid = 0;
3445 if (*args)
3447 std::string name = extractPlayerNameFromLink((char*)args);
3448 if (name.empty())
3450 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3451 SetSentErrorMessage(true);
3452 return false;
3455 player = objmgr.GetPlayer(name.c_str());
3456 if (!player)
3457 player_guid = objmgr.GetPlayerGUIDByName(name);
3459 else
3460 player = getSelectedPlayer();
3462 if (player)
3464 player->ResurrectPlayer(0.5f);
3465 player->SpawnCorpseBones();
3466 player->SaveToDB();
3468 else if (player_guid)
3470 // will resurrected at login without corpse
3471 ObjectAccessor::Instance().ConvertCorpseForPlayer(player_guid);
3473 else
3475 SendSysMessage(LANG_NO_CHAR_SELECTED);
3476 SetSentErrorMessage(true);
3477 return false;
3480 return true;
3483 bool ChatHandler::HandleAuraCommand(const char* args)
3485 Unit *target = getSelectedUnit();
3486 if(!target)
3488 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3489 SetSentErrorMessage(true);
3490 return false;
3493 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3494 uint32 spellID = extractSpellIdFromLink((char*)args);
3496 SpellEntry const *spellInfo = sSpellStore.LookupEntry( spellID );
3497 if(spellInfo)
3499 for(uint32 i = 0;i<3;i++)
3501 uint8 eff = spellInfo->Effect[i];
3502 if (eff>=TOTAL_SPELL_EFFECTS)
3503 continue;
3504 if( IsAreaAuraEffect(eff) ||
3505 eff == SPELL_EFFECT_APPLY_AURA ||
3506 eff == SPELL_EFFECT_PERSISTENT_AREA_AURA )
3508 Aura *Aur = CreateAura(spellInfo, i, NULL, target);
3509 target->AddAura(Aur);
3514 return true;
3517 bool ChatHandler::HandleUnAuraCommand(const char* args)
3519 Unit *target = getSelectedUnit();
3520 if(!target)
3522 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3523 SetSentErrorMessage(true);
3524 return false;
3527 std::string argstr = args;
3528 if (argstr == "all")
3530 target->RemoveAllAuras();
3531 return true;
3534 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3535 uint32 spellID = extractSpellIdFromLink((char*)args);
3536 if(!spellID)
3537 return false;
3539 target->RemoveAurasDueToSpell(spellID);
3541 return true;
3544 bool ChatHandler::HandleLinkGraveCommand(const char* args)
3546 if(!*args)
3547 return false;
3549 char* px = strtok((char*)args, " ");
3550 if (!px)
3551 return false;
3553 uint32 g_id = (uint32)atoi(px);
3555 uint32 g_team;
3557 char* px2 = strtok(NULL, " ");
3559 if (!px2)
3560 g_team = 0;
3561 else if (strncmp(px2,"horde",6)==0)
3562 g_team = HORDE;
3563 else if (strncmp(px2,"alliance",9)==0)
3564 g_team = ALLIANCE;
3565 else
3566 return false;
3568 WorldSafeLocsEntry const* graveyard = sWorldSafeLocsStore.LookupEntry(g_id);
3570 if(!graveyard )
3572 PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST, g_id);
3573 SetSentErrorMessage(true);
3574 return false;
3577 Player* player = m_session->GetPlayer();
3579 uint32 zoneId = player->GetZoneId();
3581 AreaTableEntry const *areaEntry = GetAreaEntryByAreaID(zoneId);
3582 if(!areaEntry || areaEntry->zone !=0 )
3584 PSendSysMessage(LANG_COMMAND_GRAVEYARDWRONGZONE, g_id,zoneId);
3585 SetSentErrorMessage(true);
3586 return false;
3589 if(objmgr.AddGraveYardLink(g_id,zoneId,g_team))
3590 PSendSysMessage(LANG_COMMAND_GRAVEYARDLINKED, g_id,zoneId);
3591 else
3592 PSendSysMessage(LANG_COMMAND_GRAVEYARDALRLINKED, g_id,zoneId);
3594 return true;
3597 bool ChatHandler::HandleNearGraveCommand(const char* args)
3599 uint32 g_team;
3601 size_t argslen = strlen(args);
3603 if(!*args)
3604 g_team = 0;
3605 else if (strncmp((char*)args,"horde",argslen)==0)
3606 g_team = HORDE;
3607 else if (strncmp((char*)args,"alliance",argslen)==0)
3608 g_team = ALLIANCE;
3609 else
3610 return false;
3612 Player* player = m_session->GetPlayer();
3613 uint32 zone_id = player->GetZoneId();
3615 WorldSafeLocsEntry const* graveyard = objmgr.GetClosestGraveYard(
3616 player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(),player->GetMapId(),g_team);
3618 if(graveyard)
3620 uint32 g_id = graveyard->ID;
3622 GraveYardData const* data = objmgr.FindGraveYardData(g_id,zone_id);
3623 if (!data)
3625 PSendSysMessage(LANG_COMMAND_GRAVEYARDERROR,g_id);
3626 SetSentErrorMessage(true);
3627 return false;
3630 g_team = data->team;
3632 std::string team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_NOTEAM);
3634 if(g_team == 0)
3635 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ANY);
3636 else if(g_team == HORDE)
3637 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE);
3638 else if(g_team == ALLIANCE)
3639 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE);
3641 PSendSysMessage(LANG_COMMAND_GRAVEYARDNEAREST, g_id,team_name.c_str(),zone_id);
3643 else
3645 std::string team_name;
3647 if(g_team == 0)
3648 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ANY);
3649 else if(g_team == HORDE)
3650 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE);
3651 else if(g_team == ALLIANCE)
3652 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE);
3654 if(g_team == ~uint32(0))
3655 PSendSysMessage(LANG_COMMAND_ZONENOGRAVEYARDS, zone_id);
3656 else
3657 PSendSysMessage(LANG_COMMAND_ZONENOGRAFACTION, zone_id,team_name.c_str());
3660 return true;
3663 //-----------------------Npc Commands-----------------------
3664 bool ChatHandler::HandleNpcAllowMovementCommand(const char* /*args*/)
3666 if(sWorld.getAllowMovement())
3668 sWorld.SetAllowMovement(false);
3669 SendSysMessage(LANG_CREATURE_MOVE_DISABLED);
3671 else
3673 sWorld.SetAllowMovement(true);
3674 SendSysMessage(LANG_CREATURE_MOVE_ENABLED);
3676 return true;
3679 bool ChatHandler::HandleNpcChangeEntryCommand(const char *args)
3681 if (!*args)
3682 return false;
3684 uint32 newEntryNum = atoi(args);
3685 if(!newEntryNum)
3686 return false;
3688 Unit* unit = getSelectedUnit();
3689 if(!unit || unit->GetTypeId() != TYPEID_UNIT)
3691 SendSysMessage(LANG_SELECT_CREATURE);
3692 SetSentErrorMessage(true);
3693 return false;
3695 Creature* creature = (Creature*)unit;
3696 if(creature->UpdateEntry(newEntryNum))
3697 SendSysMessage(LANG_DONE);
3698 else
3699 SendSysMessage(LANG_ERROR);
3700 return true;
3703 bool ChatHandler::HandleNpcInfoCommand(const char* /*args*/)
3705 Creature* target = getSelectedCreature();
3707 if(!target)
3709 SendSysMessage(LANG_SELECT_CREATURE);
3710 SetSentErrorMessage(true);
3711 return false;
3714 uint32 faction = target->getFaction();
3715 uint32 npcflags = target->GetUInt32Value(UNIT_NPC_FLAGS);
3716 uint32 displayid = target->GetDisplayId();
3717 uint32 nativeid = target->GetNativeDisplayId();
3718 uint32 Entry = target->GetEntry();
3719 CreatureInfo const* cInfo = target->GetCreatureInfo();
3721 int32 curRespawnDelay = target->GetRespawnTimeEx()-time(NULL);
3722 if(curRespawnDelay < 0)
3723 curRespawnDelay = 0;
3724 std::string curRespawnDelayStr = secsToTimeString(curRespawnDelay,true);
3725 std::string defRespawnDelayStr = secsToTimeString(target->GetRespawnDelay(),true);
3727 PSendSysMessage(LANG_NPCINFO_CHAR, target->GetDBTableGUIDLow(), faction, npcflags, Entry, displayid, nativeid);
3728 PSendSysMessage(LANG_NPCINFO_LEVEL, target->getLevel());
3729 PSendSysMessage(LANG_NPCINFO_HEALTH,target->GetCreateHealth(), target->GetMaxHealth(), target->GetHealth());
3730 PSendSysMessage(LANG_NPCINFO_FLAGS, target->GetUInt32Value(UNIT_FIELD_FLAGS), target->GetUInt32Value(UNIT_DYNAMIC_FLAGS), target->getFaction());
3731 PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES, defRespawnDelayStr.c_str(),curRespawnDelayStr.c_str());
3732 PSendSysMessage(LANG_NPCINFO_LOOT, cInfo->lootid,cInfo->pickpocketLootId,cInfo->SkinLootId);
3733 PSendSysMessage(LANG_NPCINFO_DUNGEON_ID, target->GetInstanceId());
3734 PSendSysMessage(LANG_NPCINFO_POSITION,float(target->GetPositionX()), float(target->GetPositionY()), float(target->GetPositionZ()));
3736 if ((npcflags & UNIT_NPC_FLAG_VENDOR) )
3738 SendSysMessage(LANG_NPCINFO_VENDOR);
3740 if ((npcflags & UNIT_NPC_FLAG_TRAINER) )
3742 SendSysMessage(LANG_NPCINFO_TRAINER);
3745 return true;
3748 //play npc emote
3749 bool ChatHandler::HandleNpcPlayEmoteCommand(const char* args)
3751 uint32 emote = atoi((char*)args);
3753 Creature* target = getSelectedCreature();
3754 if(!target)
3756 SendSysMessage(LANG_SELECT_CREATURE);
3757 SetSentErrorMessage(true);
3758 return false;
3761 target->SetUInt32Value(UNIT_NPC_EMOTESTATE,emote);
3763 return true;
3766 //TODO: NpcCommands that needs to be fixed :
3768 bool ChatHandler::HandleNpcAddWeaponCommand(const char* /*args*/)
3770 /*if (!*args)
3771 return false;
3773 uint64 guid = m_session->GetPlayer()->GetSelection();
3774 if (guid == 0)
3776 SendSysMessage(LANG_NO_SELECTION);
3777 return true;
3780 Creature *pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
3782 if(!pCreature)
3784 SendSysMessage(LANG_SELECT_CREATURE);
3785 return true;
3788 char* pSlotID = strtok((char*)args, " ");
3789 if (!pSlotID)
3790 return false;
3792 char* pItemID = strtok(NULL, " ");
3793 if (!pItemID)
3794 return false;
3796 uint32 ItemID = atoi(pItemID);
3797 uint32 SlotID = atoi(pSlotID);
3799 ItemPrototype* tmpItem = objmgr.GetItemPrototype(ItemID);
3801 bool added = false;
3802 if(tmpItem)
3804 switch(SlotID)
3806 case 1:
3807 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID);
3808 added = true;
3809 break;
3810 case 2:
3811 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID);
3812 added = true;
3813 break;
3814 case 3:
3815 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID);
3816 added = true;
3817 break;
3818 default:
3819 PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST,SlotID);
3820 added = false;
3821 break;
3824 if(added)
3825 PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT,ItemID,tmpItem->Name1,SlotID);
3827 else
3829 PSendSysMessage(LANG_ITEM_NOT_FOUND,ItemID);
3830 return true;
3833 return true;
3835 //----------------------------------------------------------
3837 bool ChatHandler::HandleExploreCheatCommand(const char* args)
3839 if (!*args)
3840 return false;
3842 int flag = atoi((char*)args);
3844 Player *chr = getSelectedPlayer();
3845 if (chr == NULL)
3847 SendSysMessage(LANG_NO_CHAR_SELECTED);
3848 SetSentErrorMessage(true);
3849 return false;
3852 if (flag != 0)
3854 PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL, GetNameLink(chr).c_str());
3855 if (needReportToTarget(chr))
3856 ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_ALL,GetNameLink().c_str());
3858 else
3860 PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING, GetNameLink(chr).c_str());
3861 if (needReportToTarget(chr))
3862 ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_NOTHING,GetNameLink().c_str());
3865 for (uint8 i=0; i<128; i++)
3867 if (flag != 0)
3869 m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1+i,0xFFFFFFFF);
3871 else
3873 m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1+i,0);
3877 return true;
3880 bool ChatHandler::HandleHoverCommand(const char* args)
3882 char* px = strtok((char*)args, " ");
3883 uint32 flag;
3884 if (!px)
3885 flag = 1;
3886 else
3887 flag = atoi(px);
3889 m_session->GetPlayer()->SetHover(flag);
3891 if (flag)
3892 SendSysMessage(LANG_HOVER_ENABLED);
3893 else
3894 SendSysMessage(LANG_HOVER_DISABLED);
3896 return true;
3899 bool ChatHandler::HandleLevelUpCommand(const char* args)
3901 char* px = strtok((char*)args, " ");
3902 char* py = strtok((char*)NULL, " ");
3904 // command format parsing
3905 char* pname = (char*)NULL;
3906 int addlevel = 1;
3908 if(px && py) // .levelup name level
3910 addlevel = atoi(py);
3911 pname = px;
3913 else if(px && !py) // .levelup name OR .levelup level
3915 if(isalpha(px[0])) // .levelup name
3916 pname = px;
3917 else // .levelup level
3918 addlevel = atoi(px);
3920 // else .levelup - nothing do for preparing
3922 // player
3923 Player *chr = NULL;
3924 uint64 chr_guid = 0;
3926 std::string name;
3928 if(pname) // player by name
3930 name = extractPlayerNameFromLink(pname);
3931 if(name.empty())
3933 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3934 SetSentErrorMessage(true);
3935 return false;
3938 chr = objmgr.GetPlayer(name.c_str());
3939 if(!chr) // not in game
3941 chr_guid = objmgr.GetPlayerGUIDByName(name);
3942 if (chr_guid == 0)
3944 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3945 SetSentErrorMessage(true);
3946 return false;
3950 else // player by selection
3952 chr = getSelectedPlayer();
3954 if (chr == NULL)
3956 SendSysMessage(LANG_NO_CHAR_SELECTED);
3957 SetSentErrorMessage(true);
3958 return false;
3961 name = chr->GetName();
3964 assert(chr || chr_guid);
3966 int32 oldlevel = chr ? chr->getLevel() : Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL,chr_guid);
3967 int32 newlevel = oldlevel + addlevel;
3968 if(newlevel < 1)
3969 newlevel = 1;
3970 if(newlevel > STRONG_MAX_LEVEL) // hardcoded maximum level
3971 newlevel = STRONG_MAX_LEVEL;
3973 if(chr)
3975 chr->GiveLevel(newlevel);
3976 chr->InitTalentForLevel();
3977 chr->SetUInt32Value(PLAYER_XP,0);
3979 if(oldlevel == newlevel)
3980 ChatHandler(chr).SendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET);
3981 else
3982 if(oldlevel < newlevel)
3983 ChatHandler(chr).PSendSysMessage(LANG_YOURS_LEVEL_UP,newlevel-oldlevel);
3984 else
3985 if(oldlevel > newlevel)
3986 ChatHandler(chr).PSendSysMessage(LANG_YOURS_LEVEL_DOWN,newlevel-oldlevel);
3988 else
3990 // update level and XP at level, all other will be updated at loading
3991 Tokens values;
3992 Player::LoadValuesArrayFromDB(values,chr_guid);
3993 Player::SetUInt32ValueInArray(values,UNIT_FIELD_LEVEL,newlevel);
3994 Player::SetUInt32ValueInArray(values,PLAYER_XP,0);
3995 Player::SaveValuesArrayInDB(values,chr_guid);
3998 if(m_session->GetPlayer() != chr) // including chr==NULL
4000 std::string nameLink = playerLink(name);
4001 PSendSysMessage(LANG_YOU_CHANGE_LVL,nameLink.c_str(),newlevel);
4003 return true;
4006 bool ChatHandler::HandleShowAreaCommand(const char* args)
4008 if (!*args)
4009 return false;
4011 Player *chr = getSelectedPlayer();
4012 if (chr == NULL)
4014 SendSysMessage(LANG_NO_CHAR_SELECTED);
4015 SetSentErrorMessage(true);
4016 return false;
4019 int area = GetAreaFlagByAreaID(atoi((char*)args));
4020 int offset = area / 32;
4021 uint32 val = (uint32)(1 << (area % 32));
4023 if(area<0 || offset >= 128)
4025 SendSysMessage(LANG_BAD_VALUE);
4026 SetSentErrorMessage(true);
4027 return false;
4030 uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
4031 chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields | val));
4033 SendSysMessage(LANG_EXPLORE_AREA);
4034 return true;
4037 bool ChatHandler::HandleHideAreaCommand(const char* args)
4039 if (!*args)
4040 return false;
4042 Player *chr = getSelectedPlayer();
4043 if (chr == NULL)
4045 SendSysMessage(LANG_NO_CHAR_SELECTED);
4046 SetSentErrorMessage(true);
4047 return false;
4050 int area = GetAreaFlagByAreaID(atoi((char*)args));
4051 int offset = area / 32;
4052 uint32 val = (uint32)(1 << (area % 32));
4054 if(area<0 || offset >= 128)
4056 SendSysMessage(LANG_BAD_VALUE);
4057 SetSentErrorMessage(true);
4058 return false;
4061 uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
4062 chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields ^ val));
4064 SendSysMessage(LANG_UNEXPLORE_AREA);
4065 return true;
4068 bool ChatHandler::HandleDebugUpdate(const char* args)
4070 if(!*args)
4071 return false;
4073 uint32 updateIndex;
4074 uint32 value;
4076 char* pUpdateIndex = strtok((char*)args, " ");
4078 Unit* chr = getSelectedUnit();
4079 if (chr == NULL)
4081 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4082 SetSentErrorMessage(true);
4083 return false;
4086 if(!pUpdateIndex)
4088 return true;
4090 updateIndex = atoi(pUpdateIndex);
4091 //check updateIndex
4092 if(chr->GetTypeId() == TYPEID_PLAYER)
4094 if (updateIndex>=PLAYER_END) return true;
4096 else
4098 if (updateIndex>=UNIT_END) return true;
4101 char* pvalue = strtok(NULL, " ");
4102 if (!pvalue)
4104 value=chr->GetUInt32Value(updateIndex);
4106 PSendSysMessage(LANG_UPDATE, chr->GetGUIDLow(),updateIndex,value);
4107 return true;
4110 value=atoi(pvalue);
4112 PSendSysMessage(LANG_UPDATE_CHANGE, chr->GetGUIDLow(),updateIndex,value);
4114 chr->SetUInt32Value(updateIndex,value);
4116 return true;
4119 bool ChatHandler::HandleBankCommand(const char* /*args*/)
4121 m_session->SendShowBank( m_session->GetPlayer()->GetGUID() );
4123 return true;
4126 bool ChatHandler::HandleChangeWeather(const char* args)
4128 if(!*args)
4129 return false;
4131 //Weather is OFF
4132 if (!sWorld.getConfig(CONFIG_WEATHER))
4134 SendSysMessage(LANG_WEATHER_DISABLED);
4135 SetSentErrorMessage(true);
4136 return false;
4139 //*Change the weather of a cell
4140 char* px = strtok((char*)args, " ");
4141 char* py = strtok(NULL, " ");
4143 if (!px || !py)
4144 return false;
4146 uint32 type = (uint32)atoi(px); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
4147 float grade = (float)atof(py); //0 to 1, sending -1 is instand good weather
4149 Player *player = m_session->GetPlayer();
4150 uint32 zoneid = player->GetZoneId();
4152 Weather* wth = sWorld.FindWeather(zoneid);
4154 if(!wth)
4155 wth = sWorld.AddWeather(zoneid);
4156 if(!wth)
4158 SendSysMessage(LANG_NO_WEATHER);
4159 SetSentErrorMessage(true);
4160 return false;
4163 wth->SetWeather(WeatherType(type), grade);
4165 return true;
4168 bool ChatHandler::HandleDebugSetValue(const char* args)
4170 if(!*args)
4171 return false;
4173 char* px = strtok((char*)args, " ");
4174 char* py = strtok(NULL, " ");
4175 char* pz = strtok(NULL, " ");
4177 if (!px || !py)
4178 return false;
4180 Unit* target = getSelectedUnit();
4181 if(!target)
4183 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4184 SetSentErrorMessage(true);
4185 return false;
4188 uint64 guid = target->GetGUID();
4190 uint32 Opcode = (uint32)atoi(px);
4191 if(Opcode >= target->GetValuesCount())
4193 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, GUID_LOPART(guid), target->GetValuesCount());
4194 return false;
4196 uint32 iValue;
4197 float fValue;
4198 bool isint32 = true;
4199 if(pz)
4200 isint32 = (bool)atoi(pz);
4201 if(isint32)
4203 iValue = (uint32)atoi(py);
4204 sLog.outDebug(GetMangosString(LANG_SET_UINT), GUID_LOPART(guid), Opcode, iValue);
4205 target->SetUInt32Value( Opcode , iValue );
4206 PSendSysMessage(LANG_SET_UINT_FIELD, GUID_LOPART(guid), Opcode,iValue);
4208 else
4210 fValue = (float)atof(py);
4211 sLog.outDebug(GetMangosString(LANG_SET_FLOAT), GUID_LOPART(guid), Opcode, fValue);
4212 target->SetFloatValue( Opcode , fValue );
4213 PSendSysMessage(LANG_SET_FLOAT_FIELD, GUID_LOPART(guid), Opcode,fValue);
4216 return true;
4219 bool ChatHandler::HandleDebugGetValue(const char* args)
4221 if(!*args)
4222 return false;
4224 char* px = strtok((char*)args, " ");
4225 char* pz = strtok(NULL, " ");
4227 if (!px)
4228 return false;
4230 Unit* target = getSelectedUnit();
4231 if(!target)
4233 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4234 SetSentErrorMessage(true);
4235 return false;
4238 uint64 guid = target->GetGUID();
4240 uint32 Opcode = (uint32)atoi(px);
4241 if(Opcode >= target->GetValuesCount())
4243 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, GUID_LOPART(guid), target->GetValuesCount());
4244 return false;
4246 uint32 iValue;
4247 float fValue;
4248 bool isint32 = true;
4249 if(pz)
4250 isint32 = (bool)atoi(pz);
4252 if(isint32)
4254 iValue = target->GetUInt32Value( Opcode );
4255 sLog.outDebug(GetMangosString(LANG_GET_UINT), GUID_LOPART(guid), Opcode, iValue);
4256 PSendSysMessage(LANG_GET_UINT_FIELD, GUID_LOPART(guid), Opcode, iValue);
4258 else
4260 fValue = target->GetFloatValue( Opcode );
4261 sLog.outDebug(GetMangosString(LANG_GET_FLOAT), GUID_LOPART(guid), Opcode, fValue);
4262 PSendSysMessage(LANG_GET_FLOAT_FIELD, GUID_LOPART(guid), Opcode, fValue);
4265 return true;
4268 bool ChatHandler::HandleSet32Bit(const char* args)
4270 if(!*args)
4271 return false;
4273 char* px = strtok((char*)args, " ");
4274 char* py = strtok(NULL, " ");
4276 if (!px || !py)
4277 return false;
4279 uint32 Opcode = (uint32)atoi(px);
4280 uint32 Value = (uint32)atoi(py);
4281 if (Value > 32) //uint32 = 32 bits
4282 return false;
4284 sLog.outDebug(GetMangosString(LANG_SET_32BIT), Opcode, Value);
4286 m_session->GetPlayer( )->SetUInt32Value( Opcode , 2^Value );
4288 PSendSysMessage(LANG_SET_32BIT_FIELD, Opcode,1);
4289 return true;
4292 bool ChatHandler::HandleDebugMod32Value(const char* args)
4294 if(!*args)
4295 return false;
4297 char* px = strtok((char*)args, " ");
4298 char* py = strtok(NULL, " ");
4300 if (!px || !py)
4301 return false;
4303 uint32 Opcode = (uint32)atoi(px);
4304 int Value = atoi(py);
4306 if(Opcode >= m_session->GetPlayer()->GetValuesCount())
4308 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, m_session->GetPlayer()->GetGUIDLow(), m_session->GetPlayer( )->GetValuesCount());
4309 return false;
4312 sLog.outDebug(GetMangosString(LANG_CHANGE_32BIT), Opcode, Value);
4314 int CurrentValue = (int)m_session->GetPlayer( )->GetUInt32Value( Opcode );
4316 CurrentValue += Value;
4317 m_session->GetPlayer( )->SetUInt32Value( Opcode , (uint32)CurrentValue );
4319 PSendSysMessage(LANG_CHANGE_32BIT_FIELD, Opcode,CurrentValue);
4321 return true;
4324 bool ChatHandler::HandleTeleAddCommand(const char * args)
4326 if(!*args)
4327 return false;
4329 Player *player=m_session->GetPlayer();
4330 if (!player)
4331 return false;
4333 std::string name = args;
4335 if(objmgr.GetGameTele(name))
4337 SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST);
4338 SetSentErrorMessage(true);
4339 return false;
4342 GameTele tele;
4343 tele.position_x = player->GetPositionX();
4344 tele.position_y = player->GetPositionY();
4345 tele.position_z = player->GetPositionZ();
4346 tele.orientation = player->GetOrientation();
4347 tele.mapId = player->GetMapId();
4348 tele.name = name;
4350 if(objmgr.AddGameTele(tele))
4352 SendSysMessage(LANG_COMMAND_TP_ADDED);
4354 else
4356 SendSysMessage(LANG_COMMAND_TP_ADDEDERR);
4357 SetSentErrorMessage(true);
4358 return false;
4361 return true;
4364 bool ChatHandler::HandleTeleDelCommand(const char * args)
4366 if(!*args)
4367 return false;
4369 std::string name = args;
4371 if(!objmgr.DeleteGameTele(name))
4373 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
4374 SetSentErrorMessage(true);
4375 return false;
4378 SendSysMessage(LANG_COMMAND_TP_DELETED);
4379 return true;
4382 bool ChatHandler::HandleListAurasCommand (const char * /*args*/)
4384 Unit *unit = getSelectedUnit();
4385 if(!unit)
4387 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4388 SetSentErrorMessage(true);
4389 return false;
4392 char const* talentStr = GetMangosString(LANG_TALENT);
4393 char const* passiveStr = GetMangosString(LANG_PASSIVE);
4395 Unit::AuraMap const& uAuras = unit->GetAuras();
4396 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS, uAuras.size());
4397 for (Unit::AuraMap::const_iterator itr = uAuras.begin(); itr != uAuras.end(); ++itr)
4399 bool talent = GetTalentSpellCost(itr->second->GetId()) > 0;
4401 char const* name = itr->second->GetSpellProto()->SpellName[m_session->GetSessionDbcLocale()];
4403 if (m_session)
4405 std::ostringstream ss_name;
4406 ss_name << "|cffffffff|Hspell:" << itr->second->GetId() << "|h[" << name << "]|h|r";
4408 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL, itr->second->GetId(), itr->second->GetEffIndex(),
4409 itr->second->GetModifier()->m_auraname, itr->second->GetAuraDuration(), itr->second->GetAuraMaxDuration(),
4410 ss_name.str().c_str(),
4411 (itr->second->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4412 IS_PLAYER_GUID(itr->second->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr->second->GetCasterGUID()));
4414 else
4416 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL, itr->second->GetId(), itr->second->GetEffIndex(),
4417 itr->second->GetModifier()->m_auraname, itr->second->GetAuraDuration(), itr->second->GetAuraMaxDuration(),
4418 name,
4419 (itr->second->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4420 IS_PLAYER_GUID(itr->second->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr->second->GetCasterGUID()));
4423 for (int i = 0; i < TOTAL_AURAS; i++)
4425 Unit::AuraList const& uAuraList = unit->GetAurasByType(AuraType(i));
4426 if (uAuraList.empty()) continue;
4427 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE, uAuraList.size(), i);
4428 for (Unit::AuraList::const_iterator itr = uAuraList.begin(); itr != uAuraList.end(); ++itr)
4430 bool talent = GetTalentSpellCost((*itr)->GetId()) > 0;
4432 char const* name = (*itr)->GetSpellProto()->SpellName[m_session->GetSessionDbcLocale()];
4434 if (m_session)
4436 std::ostringstream ss_name;
4437 ss_name << "|cffffffff|Hspell:" << (*itr)->GetId() << "|h[" << name << "]|h|r";
4439 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE, (*itr)->GetId(), (*itr)->GetEffIndex(),
4440 ss_name.str().c_str(),((*itr)->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4441 IS_PLAYER_GUID((*itr)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr)->GetCasterGUID()));
4443 else
4445 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE, (*itr)->GetId(), (*itr)->GetEffIndex(),
4446 name,((*itr)->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4447 IS_PLAYER_GUID((*itr)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr)->GetCasterGUID()));
4451 return true;
4454 bool ChatHandler::HandleResetAchievementsCommand (const char * args)
4456 char* pName = strtok((char*)args, "");
4457 Player *player = NULL;
4458 uint64 guid = 0;
4459 if (pName)
4461 std::string name = extractPlayerNameFromLink(pName);
4462 if(name.empty())
4464 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4465 SetSentErrorMessage(true);
4466 return false;
4469 guid = objmgr.GetPlayerGUIDByName(name);
4470 player = objmgr.GetPlayer(guid);
4472 else
4474 player = getSelectedPlayer();
4475 if(player)
4476 guid = player->GetGUID();
4479 if(!player && !guid)
4481 SendSysMessage(LANG_NO_CHAR_SELECTED);
4482 return true;
4485 if(player)
4486 player->GetAchievementMgr().Reset();
4487 else if(guid)
4488 AchievementMgr::DeleteFromDB(GUID_LOPART(guid));
4490 return true;
4493 bool ChatHandler::HandleResetHonorCommand (const char * args)
4495 char* pName = strtok((char*)args, "");
4496 Player *player = NULL;
4497 if (pName)
4499 std::string name = extractPlayerNameFromLink(pName);
4500 if(name.empty())
4502 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4503 SetSentErrorMessage(true);
4504 return false;
4507 uint64 guid = objmgr.GetPlayerGUIDByName(name);
4508 player = objmgr.GetPlayer(guid);
4510 else
4511 player = getSelectedPlayer();
4513 if(!player)
4515 SendSysMessage(LANG_NO_CHAR_SELECTED);
4516 return true;
4519 player->SetUInt32Value(PLAYER_FIELD_KILLS, 0);
4520 player->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS, 0);
4521 player->SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY, 0);
4522 player->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION, 0);
4523 player->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION, 0);
4525 player->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_EARN_HONORABLE_KILL);
4527 return true;
4530 static bool HandleResetStatsOrLevelHelper(Player* player)
4532 PlayerInfo const *info = objmgr.GetPlayerInfo(player->getRace(), player->getClass());
4533 if(!info) return false;
4535 ChrClassesEntry const* cEntry = sChrClassesStore.LookupEntry(player->getClass());
4536 if(!cEntry)
4538 sLog.outError("Class %u not found in DBC (Wrong DBC files?)",player->getClass());
4539 return false;
4542 uint8 powertype = cEntry->powerType;
4544 // reset m_form if no aura
4545 if(!player->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT))
4546 player->m_form = FORM_NONE;
4548 player->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, DEFAULT_WORLD_OBJECT_SIZE );
4549 player->SetFloatValue(UNIT_FIELD_COMBATREACH, 1.5f );
4551 player->setFactionForRace(player->getRace());
4553 player->SetUInt32Value(UNIT_FIELD_BYTES_0, ( ( player->getRace() ) | ( player->getClass() << 8 ) | ( player->getGender() << 16 ) | ( powertype << 24 ) ) );
4555 // reset only if player not in some form;
4556 if(player->m_form==FORM_NONE)
4558 switch(player->getGender())
4560 case GENDER_FEMALE:
4561 player->SetDisplayId(info->displayId_f);
4562 player->SetNativeDisplayId(info->displayId_f);
4563 break;
4564 case GENDER_MALE:
4565 player->SetDisplayId(info->displayId_m);
4566 player->SetNativeDisplayId(info->displayId_m);
4567 break;
4568 default:
4569 break;
4573 player->SetByteValue(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_PVP );
4574 player->SetByteValue(UNIT_FIELD_BYTES_2, 3, player->m_form);
4576 player->SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
4578 //-1 is default value
4579 player->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX, uint32(-1));
4581 //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000 );
4582 return true;
4585 bool ChatHandler::HandleResetLevelCommand(const char * args)
4587 char* pName = strtok((char*)args, "");
4588 Player *player = NULL;
4589 if (pName)
4591 std::string name = extractPlayerNameFromLink(pName);
4592 if(name.empty())
4594 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4595 SetSentErrorMessage(true);
4596 return false;
4599 uint64 guid = objmgr.GetPlayerGUIDByName(name);
4600 player = objmgr.GetPlayer(guid);
4602 else
4603 player = getSelectedPlayer();
4605 if(!player)
4607 SendSysMessage(LANG_NO_CHAR_SELECTED);
4608 SetSentErrorMessage(true);
4609 return false;
4612 if(!HandleResetStatsOrLevelHelper(player))
4613 return false;
4615 // set starting level
4616 uint32 start_level = player->getClass() != CLASS_DEATH_KNIGHT
4617 ? sWorld.getConfig(CONFIG_START_PLAYER_LEVEL)
4618 : sWorld.getConfig(CONFIG_START_HEROIC_PLAYER_LEVEL);
4620 player->SetLevel(start_level);
4621 player->InitRunes();
4622 player->InitStatsForLevel(true);
4623 player->InitTaxiNodesForLevel();
4624 player->InitGlyphsForLevel();
4625 player->InitTalentForLevel();
4626 player->SetUInt32Value(PLAYER_XP,0);
4628 // reset level to summoned pet
4629 Pet* pet = player->GetPet();
4630 if(pet && pet->getPetType()==SUMMON_PET)
4632 pet->InitStatsForLevel(1);
4633 pet->InitTalentForLevel();
4635 return true;
4638 bool ChatHandler::HandleResetStatsCommand(const char * args)
4640 char* pName = strtok((char*)args, "");
4641 Player *player = NULL;
4642 if (pName)
4644 std::string name = extractPlayerNameFromLink(pName);
4645 if(name.empty())
4647 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4648 SetSentErrorMessage(true);
4649 return false;
4652 uint64 guid = objmgr.GetPlayerGUIDByName(name);
4653 player = objmgr.GetPlayer(guid);
4655 else
4656 player = getSelectedPlayer();
4658 if(!player)
4660 SendSysMessage(LANG_NO_CHAR_SELECTED);
4661 SetSentErrorMessage(true);
4662 return false;
4665 if(!HandleResetStatsOrLevelHelper(player))
4666 return false;
4668 player->InitRunes();
4669 player->InitStatsForLevel(true);
4670 player->InitTaxiNodesForLevel();
4671 player->InitGlyphsForLevel();
4672 player->InitTalentForLevel();
4674 return true;
4677 bool ChatHandler::HandleResetSpellsCommand(const char * args)
4679 char* pName = strtok((char*)args, "");
4680 Player *player = NULL;
4681 uint64 playerGUID = 0;
4682 if (pName)
4684 std::string name = extractPlayerNameFromLink(pName);
4685 if(name.empty())
4687 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4688 SetSentErrorMessage(true);
4689 return false;
4692 player = objmgr.GetPlayer(name.c_str());
4693 if(!player)
4694 playerGUID = objmgr.GetPlayerGUIDByName(name);
4696 else
4697 player = getSelectedPlayer();
4699 if(!player && !playerGUID)
4701 SendSysMessage(LANG_NO_CHAR_SELECTED);
4702 SetSentErrorMessage(true);
4703 return false;
4706 if(player)
4708 player->resetSpells();
4710 ChatHandler(player).SendSysMessage(LANG_RESET_SPELLS);
4711 if(m_session->GetPlayer()!=player)
4712 PSendSysMessage(LANG_RESET_SPELLS_ONLINE,GetNameLink(player).c_str());
4714 else
4716 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS), GUID_LOPART(playerGUID));
4717 PSendSysMessage(LANG_RESET_SPELLS_OFFLINE,pName);
4720 return true;
4723 bool ChatHandler::HandleResetTalentsCommand(const char * args)
4725 char* pName = strtok((char*)args, "");
4726 Player *player = NULL;
4727 uint64 playerGUID = 0;
4728 if (pName)
4730 std::string name = extractPlayerNameFromLink(pName);
4731 if(name.empty())
4733 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4734 SetSentErrorMessage(true);
4735 return false;
4738 player = objmgr.GetPlayer(name.c_str());
4739 if(!player)
4740 playerGUID = objmgr.GetPlayerGUIDByName(name);
4742 else
4743 player = getSelectedPlayer();
4745 if(player)
4747 player->resetTalents(true);
4749 ChatHandler(player).SendSysMessage(LANG_RESET_TALENTS);
4750 if(m_session->GetPlayer()!=player)
4751 PSendSysMessage(LANG_RESET_TALENTS_ONLINE,GetNameLink(player).c_str());
4753 return true;
4755 else if (playerGUID)
4757 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_TALENTS), GUID_LOPART(playerGUID) );
4758 std::string nameLink = playerLink(pName);
4759 PSendSysMessage(LANG_RESET_TALENTS_OFFLINE,nameLink.c_str());
4760 return true;
4762 // Try reset talenents as Hunter Pet
4763 Creature* creature = getSelectedCreature();
4764 if (creature && creature->isPet() && ((Pet *)creature)->getPetType() == HUNTER_PET)
4766 ((Pet *)creature)->resetTalents(true);
4767 Unit *owner = creature->GetOwner();
4768 if (owner && owner->GetTypeId() == TYPEID_PLAYER)
4770 player = (Player *)owner;
4771 ChatHandler(player).SendSysMessage(LANG_RESET_PET_TALENTS);
4772 if(m_session->GetPlayer()!=player)
4773 PSendSysMessage(LANG_RESET_PET_TALENTS_ONLINE,GetNameLink(player).c_str());
4775 return true;
4778 SendSysMessage(LANG_NO_CHAR_SELECTED);
4779 SetSentErrorMessage(true);
4780 return false;
4783 bool ChatHandler::HandleResetAllCommand(const char * args)
4785 if(!*args)
4786 return false;
4788 std::string casename = args;
4790 AtLoginFlags atLogin;
4792 // Command specially created as single command to prevent using short case names
4793 if(casename=="spells")
4795 atLogin = AT_LOGIN_RESET_SPELLS;
4796 sWorld.SendWorldText(LANG_RESETALL_SPELLS);
4798 else if(casename=="talents")
4800 atLogin = AT_LOGIN_RESET_TALENTS;
4801 sWorld.SendWorldText(LANG_RESETALL_TALENTS);
4803 else
4805 PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE,args);
4806 SetSentErrorMessage(true);
4807 return false;
4810 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE (at_login & '%u') = '0'",atLogin,atLogin);
4811 HashMapHolder<Player>::MapType const& plist = ObjectAccessor::Instance().GetPlayers();
4812 for(HashMapHolder<Player>::MapType::const_iterator itr = plist.begin(); itr != plist.end(); ++itr)
4813 itr->second->SetAtLoginFlag(atLogin);
4815 return true;
4818 bool ChatHandler::HandleServerShutDownCancelCommand(const char* args)
4820 sWorld.ShutdownCancel();
4821 return true;
4824 bool ChatHandler::HandleServerShutDownCommand(const char* args)
4826 if(!*args)
4827 return false;
4829 char* time_str = strtok ((char*) args, " ");
4830 char* exitcode_str = strtok (NULL, "");
4832 int32 time = atoi (time_str);
4834 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4835 if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0)
4836 return false;
4838 if (exitcode_str)
4840 int32 exitcode = atoi (exitcode_str);
4842 // Handle atoi() errors
4843 if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
4844 return false;
4846 // Exit code should be in range of 0-125, 126-255 is used
4847 // in many shells for their own return codes and code > 255
4848 // is not supported in many others
4849 if (exitcode < 0 || exitcode > 125)
4850 return false;
4852 sWorld.ShutdownServ (time, 0, exitcode);
4854 else
4855 sWorld.ShutdownServ(time,0,SHUTDOWN_EXIT_CODE);
4856 return true;
4859 bool ChatHandler::HandleServerRestartCommand(const char* args)
4861 if(!*args)
4862 return false;
4864 char* time_str = strtok ((char*) args, " ");
4865 char* exitcode_str = strtok (NULL, "");
4867 int32 time = atoi (time_str);
4869 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4870 if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0)
4871 return false;
4873 if (exitcode_str)
4875 int32 exitcode = atoi (exitcode_str);
4877 // Handle atoi() errors
4878 if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
4879 return false;
4881 // Exit code should be in range of 0-125, 126-255 is used
4882 // in many shells for their own return codes and code > 255
4883 // is not supported in many others
4884 if (exitcode < 0 || exitcode > 125)
4885 return false;
4887 sWorld.ShutdownServ (time, SHUTDOWN_MASK_RESTART, exitcode);
4889 else
4890 sWorld.ShutdownServ(time, SHUTDOWN_MASK_RESTART, RESTART_EXIT_CODE);
4891 return true;
4894 bool ChatHandler::HandleServerIdleRestartCommand(const char* args)
4896 if(!*args)
4897 return false;
4899 char* time_str = strtok ((char*) args, " ");
4900 char* exitcode_str = strtok (NULL, "");
4902 int32 time = atoi (time_str);
4904 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4905 if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0)
4906 return false;
4908 if (exitcode_str)
4910 int32 exitcode = atoi (exitcode_str);
4912 // Handle atoi() errors
4913 if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
4914 return false;
4916 // Exit code should be in range of 0-125, 126-255 is used
4917 // in many shells for their own return codes and code > 255
4918 // is not supported in many others
4919 if (exitcode < 0 || exitcode > 125)
4920 return false;
4922 sWorld.ShutdownServ (time, SHUTDOWN_MASK_RESTART|SHUTDOWN_MASK_IDLE, exitcode);
4924 else
4925 sWorld.ShutdownServ(time,SHUTDOWN_MASK_RESTART|SHUTDOWN_MASK_IDLE,RESTART_EXIT_CODE);
4926 return true;
4929 bool ChatHandler::HandleServerIdleShutDownCommand(const char* args)
4931 if(!*args)
4932 return false;
4934 char* time_str = strtok ((char*) args, " ");
4935 char* exitcode_str = strtok (NULL, "");
4937 int32 time = atoi (time_str);
4939 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4940 if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0)
4941 return false;
4943 if (exitcode_str)
4945 int32 exitcode = atoi (exitcode_str);
4947 // Handle atoi() errors
4948 if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
4949 return false;
4951 // Exit code should be in range of 0-125, 126-255 is used
4952 // in many shells for their own return codes and code > 255
4953 // is not supported in many others
4954 if (exitcode < 0 || exitcode > 125)
4955 return false;
4957 sWorld.ShutdownServ (time, SHUTDOWN_MASK_IDLE, exitcode);
4959 else
4960 sWorld.ShutdownServ(time,SHUTDOWN_MASK_IDLE,SHUTDOWN_EXIT_CODE);
4961 return true;
4964 bool ChatHandler::HandleQuestAdd(const char* args)
4966 Player* player = getSelectedPlayer();
4967 if(!player)
4969 SendSysMessage(LANG_NO_CHAR_SELECTED);
4970 SetSentErrorMessage(true);
4971 return false;
4974 // .addquest #entry'
4975 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4976 char* cId = extractKeyFromLink((char*)args,"Hquest");
4977 if(!cId)
4978 return false;
4980 uint32 entry = atol(cId);
4982 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
4984 if(!pQuest)
4986 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND,entry);
4987 SetSentErrorMessage(true);
4988 return false;
4991 // check item starting quest (it can work incorrectly if added without item in inventory)
4992 for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
4994 ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype>(id);
4995 if (!pProto)
4996 continue;
4998 if (pProto->StartQuest == entry)
5000 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, entry, pProto->ItemId);
5001 SetSentErrorMessage(true);
5002 return false;
5006 // ok, normal (creature/GO starting) quest
5007 if( player->CanAddQuest( pQuest, true ) )
5009 player->AddQuest( pQuest, NULL );
5011 if ( player->CanCompleteQuest( entry ) )
5012 player->CompleteQuest( entry );
5015 return true;
5018 bool ChatHandler::HandleQuestRemove(const char* args)
5020 Player* player = getSelectedPlayer();
5021 if(!player)
5023 SendSysMessage(LANG_NO_CHAR_SELECTED);
5024 SetSentErrorMessage(true);
5025 return false;
5028 // .removequest #entry'
5029 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
5030 char* cId = extractKeyFromLink((char*)args,"Hquest");
5031 if(!cId)
5032 return false;
5034 uint32 entry = atol(cId);
5036 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
5038 if(!pQuest)
5040 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
5041 SetSentErrorMessage(true);
5042 return false;
5045 // remove all quest entries for 'entry' from quest log
5046 for(uint8 slot = 0; slot < MAX_QUEST_LOG_SIZE; ++slot )
5048 uint32 quest = player->GetQuestSlotQuestId(slot);
5049 if(quest==entry)
5051 player->SetQuestSlot(slot,0);
5053 // we ignore unequippable quest items in this case, its' still be equipped
5054 player->TakeQuestSourceItem( quest, false );
5058 // set quest status to not started (will updated in DB at next save)
5059 player->SetQuestStatus( entry, QUEST_STATUS_NONE);
5061 // reset rewarded for restart repeatable quest
5062 player->getQuestStatusMap()[entry].m_rewarded = false;
5064 SendSysMessage(LANG_COMMAND_QUEST_REMOVED);
5065 return true;
5068 bool ChatHandler::HandleQuestComplete(const char* args)
5070 Player* player = getSelectedPlayer();
5071 if(!player)
5073 SendSysMessage(LANG_NO_CHAR_SELECTED);
5074 SetSentErrorMessage(true);
5075 return false;
5078 // .quest complete #entry
5079 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
5080 char* cId = extractKeyFromLink((char*)args,"Hquest");
5081 if(!cId)
5082 return false;
5084 uint32 entry = atol(cId);
5086 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
5088 // If player doesn't have the quest
5089 if(!pQuest || player->GetQuestStatus(entry) == QUEST_STATUS_NONE)
5091 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
5092 SetSentErrorMessage(true);
5093 return false;
5096 // Add quest items for quests that require items
5097 for(uint8 x = 0; x < QUEST_OBJECTIVES_COUNT; ++x)
5099 uint32 id = pQuest->ReqItemId[x];
5100 uint32 count = pQuest->ReqItemCount[x];
5101 if(!id || !count)
5102 continue;
5104 uint32 curItemCount = player->GetItemCount(id,true);
5106 ItemPosCountVec dest;
5107 uint8 msg = player->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, id, count-curItemCount );
5108 if( msg == EQUIP_ERR_OK )
5110 Item* item = player->StoreNewItem( dest, id, true);
5111 player->SendNewItem(item,count-curItemCount,true,false);
5115 // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
5116 for(uint8 i = 0; i < QUEST_OBJECTIVES_COUNT; i++)
5118 uint32 creature = pQuest->ReqCreatureOrGOId[i];
5119 uint32 creaturecount = pQuest->ReqCreatureOrGOCount[i];
5121 if(uint32 spell_id = pQuest->ReqSpell[i])
5123 for(uint16 z = 0; z < creaturecount; ++z)
5124 player->CastedCreatureOrGO(creature,0,spell_id);
5126 else if(creature > 0)
5128 for(uint16 z = 0; z < creaturecount; ++z)
5129 player->KilledMonster(creature,0);
5131 else if(creature < 0)
5133 for(uint16 z = 0; z < creaturecount; ++z)
5134 player->CastedCreatureOrGO(creature,0,0);
5138 // If the quest requires reputation to complete
5139 if(uint32 repFaction = pQuest->GetRepObjectiveFaction())
5141 uint32 repValue = pQuest->GetRepObjectiveValue();
5142 uint32 curRep = player->GetReputationMgr().GetReputation(repFaction);
5143 if(curRep < repValue)
5144 if(FactionEntry const *factionEntry = sFactionStore.LookupEntry(repFaction))
5145 player->GetReputationMgr().SetReputation(factionEntry,repValue);
5148 // If the quest requires money
5149 int32 ReqOrRewMoney = pQuest->GetRewOrReqMoney();
5150 if(ReqOrRewMoney < 0)
5151 player->ModifyMoney(-ReqOrRewMoney);
5153 player->CompleteQuest(entry);
5154 return true;
5157 bool ChatHandler::HandleBanAccountCommand(const char* args)
5159 return HandleBanHelper(BAN_ACCOUNT,args);
5162 bool ChatHandler::HandleBanCharacterCommand(const char* args)
5164 return HandleBanHelper(BAN_CHARACTER,args);
5167 bool ChatHandler::HandleBanIPCommand(const char* args)
5169 return HandleBanHelper(BAN_IP,args);
5172 bool ChatHandler::HandleBanHelper(BanMode mode, const char* args)
5174 if (!*args)
5175 return false;
5177 char* cnameOrIP = strtok ((char*)args, " ");
5178 if (!cnameOrIP)
5179 return false;
5181 std::string nameOrIP = cnameOrIP;
5183 char* duration = strtok (NULL," ");
5184 if(!duration || !atoi(duration))
5185 return false;
5187 char* reason = strtok (NULL,"");
5188 if(!reason)
5189 return false;
5191 switch(mode)
5193 case BAN_ACCOUNT:
5194 if(!AccountMgr::normilizeString(nameOrIP))
5196 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str());
5197 SetSentErrorMessage(true);
5198 return false;
5200 break;
5201 case BAN_CHARACTER:
5202 if(!normalizePlayerName(nameOrIP))
5204 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5205 SetSentErrorMessage(true);
5206 return false;
5208 break;
5209 case BAN_IP:
5210 if(!IsIPAddress(nameOrIP.c_str()))
5211 return false;
5212 break;
5215 switch(sWorld.BanAccount(mode, nameOrIP, duration, reason,m_session ? m_session->GetPlayerName() : ""))
5217 case BAN_SUCCESS:
5218 if(atoi(duration)>0)
5219 PSendSysMessage(LANG_BAN_YOUBANNED,nameOrIP.c_str(),secsToTimeString(TimeStringToSecs(duration),true).c_str(),reason);
5220 else
5221 PSendSysMessage(LANG_BAN_YOUPERMBANNED,nameOrIP.c_str(),reason);
5222 break;
5223 case BAN_SYNTAX_ERROR:
5224 return false;
5225 case BAN_NOTFOUND:
5226 switch(mode)
5228 default:
5229 PSendSysMessage(LANG_BAN_NOTFOUND,"account",nameOrIP.c_str());
5230 break;
5231 case BAN_CHARACTER:
5232 PSendSysMessage(LANG_BAN_NOTFOUND,"character",nameOrIP.c_str());
5233 break;
5234 case BAN_IP:
5235 PSendSysMessage(LANG_BAN_NOTFOUND,"ip",nameOrIP.c_str());
5236 break;
5238 SetSentErrorMessage(true);
5239 return false;
5242 return true;
5245 bool ChatHandler::HandleUnBanAccountCommand(const char* args)
5247 return HandleUnBanHelper(BAN_ACCOUNT,args);
5250 bool ChatHandler::HandleUnBanCharacterCommand(const char* args)
5252 return HandleUnBanHelper(BAN_CHARACTER,args);
5255 bool ChatHandler::HandleUnBanIPCommand(const char* args)
5257 return HandleUnBanHelper(BAN_IP,args);
5260 bool ChatHandler::HandleUnBanHelper(BanMode mode, const char* args)
5262 if (!*args)
5263 return false;
5265 char* cnameOrIP = strtok ((char*)args, " ");
5266 if(!cnameOrIP)
5267 return false;
5269 std::string nameOrIP = cnameOrIP;
5271 switch(mode)
5273 case BAN_ACCOUNT:
5274 if(!AccountMgr::normilizeString(nameOrIP))
5276 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str());
5277 SetSentErrorMessage(true);
5278 return false;
5280 break;
5281 case BAN_CHARACTER:
5282 if(!normalizePlayerName(nameOrIP))
5284 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5285 SetSentErrorMessage(true);
5286 return false;
5288 break;
5289 case BAN_IP:
5290 if(!IsIPAddress(nameOrIP.c_str()))
5291 return false;
5292 break;
5295 if(sWorld.RemoveBanAccount(mode,nameOrIP))
5296 PSendSysMessage(LANG_UNBAN_UNBANNED,nameOrIP.c_str());
5297 else
5298 PSendSysMessage(LANG_UNBAN_ERROR,nameOrIP.c_str());
5300 return true;
5303 bool ChatHandler::HandleBanInfoAccountCommand(const char* args)
5305 if (!*args)
5306 return false;
5308 char* cname = strtok((char*)args, "");
5309 if(!cname)
5310 return false;
5312 std::string account_name = cname;
5313 if(!AccountMgr::normilizeString(account_name))
5315 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5316 SetSentErrorMessage(true);
5317 return false;
5320 uint32 accountid = accmgr.GetId(account_name);
5321 if(!accountid)
5323 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5324 return true;
5327 return HandleBanInfoHelper(accountid,account_name.c_str());
5330 bool ChatHandler::HandleBanInfoCharacterCommand(const char* args)
5332 if (!*args)
5333 return false;
5335 std::string name = extractPlayerNameFromLink((char*)args);
5336 if(name.empty())
5338 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5339 SetSentErrorMessage(true);
5340 return false;
5343 uint32 accountid = objmgr.GetPlayerAccountIdByPlayerName(name);
5344 if(!accountid)
5346 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5347 SetSentErrorMessage(true);
5348 return false;
5351 std::string accountname;
5352 if(!accmgr.GetName(accountid,accountname))
5354 PSendSysMessage(LANG_BANINFO_NOCHARACTER);
5355 return true;
5358 return HandleBanInfoHelper(accountid,accountname.c_str());
5361 bool ChatHandler::HandleBanInfoHelper(uint32 accountid, char const* accountname)
5363 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);
5364 if(!result)
5366 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN, accountname);
5367 return true;
5370 PSendSysMessage(LANG_BANINFO_BANHISTORY,accountname);
5373 Field* fields = result->Fetch();
5375 time_t unbandate = time_t(fields[3].GetUInt64());
5376 bool active = false;
5377 if(fields[2].GetBool() && (fields[1].GetUInt64() == (uint64)0 ||unbandate >= time(NULL)) )
5378 active = true;
5379 bool permanent = (fields[1].GetUInt64() == (uint64)0);
5380 std::string bantime = permanent?GetMangosString(LANG_BANINFO_INFINITE):secsToTimeString(fields[1].GetUInt64(), true);
5381 PSendSysMessage(LANG_BANINFO_HISTORYENTRY,
5382 fields[0].GetString(), bantime.c_str(), active ? GetMangosString(LANG_BANINFO_YES):GetMangosString(LANG_BANINFO_NO), fields[4].GetString(), fields[5].GetString());
5383 }while (result->NextRow());
5385 delete result;
5386 return true;
5389 bool ChatHandler::HandleBanInfoIPCommand(const char* args)
5391 if (!*args)
5392 return false;
5394 char* cIP = strtok ((char*)args, "");
5395 if(!cIP)
5396 return false;
5398 if (!IsIPAddress(cIP))
5399 return false;
5401 std::string IP = cIP;
5403 loginDatabase.escape_string(IP);
5404 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());
5405 if(!result)
5407 PSendSysMessage(LANG_BANINFO_NOIP);
5408 return true;
5411 Field *fields = result->Fetch();
5412 bool permanent = !fields[6].GetUInt64();
5413 PSendSysMessage(LANG_BANINFO_IPENTRY,
5414 fields[0].GetString(), fields[1].GetString(), permanent ? GetMangosString(LANG_BANINFO_NEVER):fields[2].GetString(),
5415 permanent ? GetMangosString(LANG_BANINFO_INFINITE):secsToTimeString(fields[3].GetUInt64(), true).c_str(), fields[4].GetString(), fields[5].GetString());
5416 delete result;
5417 return true;
5420 bool ChatHandler::HandleBanListCharacterCommand(const char* args)
5422 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5424 char* cFilter = strtok ((char*)args, " ");
5425 if(!cFilter)
5426 return false;
5428 std::string filter = cFilter;
5429 loginDatabase.escape_string(filter);
5430 QueryResult* result = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'"),filter.c_str());
5431 if (!result)
5433 PSendSysMessage(LANG_BANLIST_NOCHARACTER);
5434 return true;
5437 return HandleBanListHelper(result);
5440 bool ChatHandler::HandleBanListAccountCommand(const char* args)
5442 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5444 char* cFilter = strtok((char*)args, " ");
5445 std::string filter = cFilter ? cFilter : "";
5446 loginDatabase.escape_string(filter);
5448 QueryResult* result;
5450 if(filter.empty())
5452 result = loginDatabase.Query("SELECT account.id, username FROM account, account_banned"
5453 " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
5455 else
5457 result = loginDatabase.PQuery("SELECT account.id, username FROM account, account_banned"
5458 " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
5459 filter.c_str());
5462 if (!result)
5464 PSendSysMessage(LANG_BANLIST_NOACCOUNT);
5465 return true;
5468 return HandleBanListHelper(result);
5471 bool ChatHandler::HandleBanListHelper(QueryResult* result)
5473 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT);
5475 // Chat short output
5476 if(m_session)
5480 Field* fields = result->Fetch();
5481 uint32 accountid = fields[0].GetUInt32();
5483 QueryResult* banresult = loginDatabase.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid);
5484 if(banresult)
5486 Field* fields2 = banresult->Fetch();
5487 PSendSysMessage("%s",fields2[0].GetString());
5488 delete banresult;
5490 } while (result->NextRow());
5492 // Console wide output
5493 else
5495 SendSysMessage(LANG_BANLIST_ACCOUNTS);
5496 SendSysMessage("===============================================================================");
5497 SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER);
5500 SendSysMessage("-------------------------------------------------------------------------------");
5501 Field *fields = result->Fetch();
5502 uint32 account_id = fields[0].GetUInt32 ();
5504 std::string account_name;
5506 // "account" case, name can be get in same query
5507 if(result->GetFieldCount() > 1)
5508 account_name = fields[1].GetCppString();
5509 // "character" case, name need extract from another DB
5510 else
5511 accmgr.GetName (account_id,account_name);
5513 // No SQL injection. id is uint32.
5514 QueryResult *banInfo = loginDatabase.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id);
5515 if (banInfo)
5517 Field *fields2 = banInfo->Fetch();
5520 time_t t_ban = fields2[0].GetUInt64();
5521 tm* aTm_ban = localtime(&t_ban);
5523 if (fields2[0].GetUInt64() == fields2[1].GetUInt64())
5525 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5526 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,
5527 fields2[2].GetString(),fields2[3].GetString());
5529 else
5531 time_t t_unban = fields2[1].GetUInt64();
5532 tm* aTm_unban = localtime(&t_unban);
5533 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5534 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,
5535 aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
5536 fields2[2].GetString(),fields2[3].GetString());
5538 }while ( banInfo->NextRow() );
5539 delete banInfo;
5541 }while( result->NextRow() );
5542 SendSysMessage("===============================================================================");
5545 delete result;
5546 return true;
5549 bool ChatHandler::HandleBanListIPCommand(const char* args)
5551 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5553 char* cFilter = strtok((char*)args, " ");
5554 std::string filter = cFilter ? cFilter : "";
5555 loginDatabase.escape_string(filter);
5557 QueryResult* result;
5559 if(filter.empty())
5561 result = loginDatabase.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5562 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
5563 " ORDER BY unbandate" );
5565 else
5567 result = loginDatabase.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5568 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")
5569 " ORDER BY unbandate",filter.c_str() );
5572 if(!result)
5574 PSendSysMessage(LANG_BANLIST_NOIP);
5575 return true;
5578 PSendSysMessage(LANG_BANLIST_MATCHINGIP);
5579 // Chat short output
5580 if(m_session)
5584 Field* fields = result->Fetch();
5585 PSendSysMessage("%s",fields[0].GetString());
5586 } while (result->NextRow());
5588 // Console wide output
5589 else
5591 SendSysMessage(LANG_BANLIST_IPS);
5592 SendSysMessage("===============================================================================");
5593 SendSysMessage(LANG_BANLIST_IPS_HEADER);
5596 SendSysMessage("-------------------------------------------------------------------------------");
5597 Field *fields = result->Fetch();
5598 time_t t_ban = fields[1].GetUInt64();
5599 tm* aTm_ban = localtime(&t_ban);
5600 if ( fields[1].GetUInt64() == fields[2].GetUInt64() )
5602 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5603 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,
5604 fields[3].GetString(), fields[4].GetString());
5606 else
5608 time_t t_unban = fields[2].GetUInt64();
5609 tm* aTm_unban = localtime(&t_unban);
5610 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5611 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,
5612 aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
5613 fields[3].GetString(), fields[4].GetString());
5615 }while( result->NextRow() );
5616 SendSysMessage("===============================================================================");
5619 delete result;
5620 return true;
5623 bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
5625 Player* pl = m_session->GetPlayer();
5627 // accept only explicitly selected target (not implicitly self targeting case)
5628 Unit* target = getSelectedUnit();
5629 if(pl->GetSelection() && target)
5631 if(target->GetTypeId()!=TYPEID_UNIT)
5633 SendSysMessage(LANG_SELECT_CREATURE);
5634 SetSentErrorMessage(true);
5635 return false;
5638 if(target->isDead())
5639 ((Creature*)target)->Respawn();
5640 return true;
5643 CellPair p(MaNGOS::ComputeCellPair(pl->GetPositionX(), pl->GetPositionY()));
5644 Cell cell(p);
5645 cell.data.Part.reserved = ALL_DISTRICT;
5646 cell.SetNoCreate();
5648 MaNGOS::RespawnDo u_do;
5649 MaNGOS::WorldObjectWorker<MaNGOS::RespawnDo> worker(pl,u_do);
5651 TypeContainerVisitor<MaNGOS::WorldObjectWorker<MaNGOS::RespawnDo>, GridTypeMapContainer > obj_worker(worker);
5652 CellLock<GridReadGuard> cell_lock(cell, p);
5653 cell_lock->Visit(cell_lock, obj_worker, *pl->GetMap());
5655 return true;
5658 bool ChatHandler::HandleGMFlyCommand(const char* args)
5660 if (!*args)
5661 return false;
5663 Player *target = getSelectedPlayer();
5664 if (!target)
5665 target = m_session->GetPlayer();
5667 WorldPacket data(12);
5668 if (strncmp(args, "on", 3) == 0)
5669 data.SetOpcode(SMSG_MOVE_SET_CAN_FLY);
5670 else if (strncmp(args, "off", 4) == 0)
5671 data.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY);
5672 else
5674 SendSysMessage(LANG_USE_BOL);
5675 return false;
5677 data.append(target->GetPackGUID());
5678 data << uint32(0); // unknown
5679 target->SendMessageToSet(&data, true);
5680 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS, GetNameLink(target).c_str(), args);
5681 return true;
5684 bool ChatHandler::HandlePDumpLoadCommand(const char *args)
5686 if (!*args)
5687 return false;
5689 char * file = strtok((char*)args, " ");
5690 if(!file)
5691 return false;
5693 char * account = strtok(NULL, " ");
5694 if(!account)
5695 return false;
5697 std::string account_name = account;
5698 if(!AccountMgr::normilizeString(account_name))
5700 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5701 SetSentErrorMessage(true);
5702 return false;
5705 uint32 account_id = accmgr.GetId(account_name);
5706 if(!account_id)
5708 account_id = atoi(account); // use original string
5709 if(!account_id)
5711 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5712 SetSentErrorMessage(true);
5713 return false;
5717 if(!accmgr.GetName(account_id,account_name))
5719 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5720 SetSentErrorMessage(true);
5721 return false;
5724 char* guid_str = NULL;
5725 char* name_str = strtok(NULL, " ");
5727 std::string name;
5728 if(name_str)
5730 name = name_str;
5731 // normalize the name if specified and check if it exists
5732 if(!normalizePlayerName(name))
5734 PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
5735 SetSentErrorMessage(true);
5736 return false;
5739 if(!ObjectMgr::IsValidName(name,true))
5741 PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
5742 SetSentErrorMessage(true);
5743 return false;
5746 guid_str = strtok(NULL, " ");
5749 uint32 guid = 0;
5751 if(guid_str)
5753 guid = atoi(guid_str);
5754 if(!guid)
5756 PSendSysMessage(LANG_INVALID_CHARACTER_GUID);
5757 SetSentErrorMessage(true);
5758 return false;
5761 if(objmgr.GetPlayerAccountIdByGUID(guid))
5763 PSendSysMessage(LANG_CHARACTER_GUID_IN_USE,guid);
5764 SetSentErrorMessage(true);
5765 return false;
5769 switch(PlayerDumpReader().LoadDump(file, account_id, name, guid))
5771 case DUMP_SUCCESS:
5772 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS);
5773 break;
5774 case DUMP_FILE_OPEN_ERROR:
5775 PSendSysMessage(LANG_FILE_OPEN_FAIL,file);
5776 SetSentErrorMessage(true);
5777 return false;
5778 case DUMP_FILE_BROKEN:
5779 PSendSysMessage(LANG_DUMP_BROKEN,file);
5780 SetSentErrorMessage(true);
5781 return false;
5782 case DUMP_TOO_MANY_CHARS:
5783 PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL,account_name.c_str(),account_id);
5784 SetSentErrorMessage(true);
5785 return false;
5786 default:
5787 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED);
5788 SetSentErrorMessage(true);
5789 return false;
5792 return true;
5795 bool ChatHandler::HandlePDumpWriteCommand(const char *args)
5797 if (!*args)
5798 return false;
5800 char* file = strtok((char*)args, " ");
5801 char* p2 = strtok(NULL, " ");
5803 if(!file || !p2)
5804 return false;
5806 uint32 guid;
5807 // character name can't start from number
5808 if (isNumeric(p2[0]))
5809 guid = atoi(p2);
5810 else
5812 std::string name = extractPlayerNameFromLink(p2);
5813 if(name.empty())
5815 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5816 SetSentErrorMessage(true);
5817 return false;
5820 guid = objmgr.GetPlayerGUIDByName(name);
5823 if(!objmgr.GetPlayerAccountIdByGUID(guid))
5825 PSendSysMessage(LANG_PLAYER_NOT_FOUND);
5826 SetSentErrorMessage(true);
5827 return false;
5830 switch(PlayerDumpWriter().WriteDump(file, guid))
5832 case DUMP_SUCCESS:
5833 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS);
5834 break;
5835 case DUMP_FILE_OPEN_ERROR:
5836 PSendSysMessage(LANG_FILE_OPEN_FAIL,file);
5837 SetSentErrorMessage(true);
5838 return false;
5839 default:
5840 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED);
5841 SetSentErrorMessage(true);
5842 return false;
5845 return true;
5848 bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
5850 Unit* unit = getSelectedUnit();
5851 if(!unit)
5853 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5854 SetSentErrorMessage(true);
5855 return false;
5858 PSendSysMessage(LANG_MOVEGENS_LIST,(unit->GetTypeId()==TYPEID_PLAYER ? "Player" : "Creature" ),unit->GetGUIDLow());
5860 MotionMaster* mm = unit->GetMotionMaster();
5861 for(MotionMaster::const_iterator itr = mm->begin(); itr != mm->end(); ++itr)
5863 switch((*itr)->GetMovementGeneratorType())
5865 case IDLE_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_IDLE); break;
5866 case RANDOM_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_RANDOM); break;
5867 case WAYPOINT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_WAYPOINT); break;
5868 case ANIMAL_RANDOM_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_ANIMAL_RANDOM); break;
5869 case CONFUSED_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_CONFUSED); break;
5870 case TARGETED_MOTION_TYPE:
5872 if(unit->GetTypeId()==TYPEID_PLAYER)
5874 TargetedMovementGenerator<Player> const* mgen = static_cast<TargetedMovementGenerator<Player> const*>(*itr);
5875 Unit* target = mgen->GetTarget();
5876 if(target)
5877 PSendSysMessage(LANG_MOVEGENS_TARGETED_PLAYER,target->GetName(),target->GetGUIDLow());
5878 else
5879 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL);
5881 else
5883 TargetedMovementGenerator<Creature> const* mgen = static_cast<TargetedMovementGenerator<Creature> const*>(*itr);
5884 Unit* target = mgen->GetTarget();
5885 if(target)
5886 PSendSysMessage(LANG_MOVEGENS_TARGETED_CREATURE,target->GetName(),target->GetGUIDLow());
5887 else
5888 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL);
5890 break;
5892 case HOME_MOTION_TYPE:
5893 if(unit->GetTypeId()==TYPEID_UNIT)
5895 float x,y,z;
5896 (*itr)->GetDestination(x,y,z);
5897 PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE,x,y,z);
5899 else
5900 SendSysMessage(LANG_MOVEGENS_HOME_PLAYER);
5901 break;
5902 case FLIGHT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FLIGHT); break;
5903 case POINT_MOTION_TYPE:
5905 float x,y,z;
5906 (*itr)->GetDestination(x,y,z);
5907 PSendSysMessage(LANG_MOVEGENS_POINT,x,y,z);
5908 break;
5910 case FLEEING_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FEAR); break;
5911 case DISTRACT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_DISTRACT); break;
5912 default:
5913 PSendSysMessage(LANG_MOVEGENS_UNKNOWN,(*itr)->GetMovementGeneratorType());
5914 break;
5917 return true;
5920 bool ChatHandler::HandleServerPLimitCommand(const char *args)
5922 if(*args)
5924 char* param = strtok((char*)args, " ");
5925 if(!param)
5926 return false;
5928 int l = strlen(param);
5930 if( strncmp(param,"player",l) == 0 )
5931 sWorld.SetPlayerLimit(-SEC_PLAYER);
5932 else if(strncmp(param,"moderator",l) == 0 )
5933 sWorld.SetPlayerLimit(-SEC_MODERATOR);
5934 else if(strncmp(param,"gamemaster",l) == 0 )
5935 sWorld.SetPlayerLimit(-SEC_GAMEMASTER);
5936 else if(strncmp(param,"administrator",l) == 0 )
5937 sWorld.SetPlayerLimit(-SEC_ADMINISTRATOR);
5938 else if(strncmp(param,"reset",l) == 0 )
5939 sWorld.SetPlayerLimit( sConfig.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT) );
5940 else
5942 int val = atoi(param);
5943 if(val < -SEC_ADMINISTRATOR) val = -SEC_ADMINISTRATOR;
5945 sWorld.SetPlayerLimit(val);
5948 // kick all low security level players
5949 if(sWorld.GetPlayerAmountLimit() > SEC_PLAYER)
5950 sWorld.KickAllLess(sWorld.GetPlayerSecurityLimit());
5953 uint32 pLimit = sWorld.GetPlayerAmountLimit();
5954 AccountTypes allowedAccountType = sWorld.GetPlayerSecurityLimit();
5955 char const* secName = "";
5956 switch(allowedAccountType)
5958 case SEC_PLAYER: secName = "Player"; break;
5959 case SEC_MODERATOR: secName = "Moderator"; break;
5960 case SEC_GAMEMASTER: secName = "Gamemaster"; break;
5961 case SEC_ADMINISTRATOR: secName = "Administrator"; break;
5962 default: secName = "<unknown>"; break;
5965 PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit,secName);
5967 return true;
5970 bool ChatHandler::HandleCastCommand(const char* args)
5972 if(!*args)
5973 return false;
5975 Unit* target = getSelectedUnit();
5977 if(!target)
5979 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5980 SetSentErrorMessage(true);
5981 return false;
5984 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5985 uint32 spell = extractSpellIdFromLink((char*)args);
5986 if(!spell)
5987 return false;
5989 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
5990 if(!spellInfo)
5991 return false;
5993 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
5995 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
5996 SetSentErrorMessage(true);
5997 return false;
6000 char* trig_str = strtok(NULL, " ");
6001 if(trig_str)
6003 int l = strlen(trig_str);
6004 if(strncmp(trig_str,"triggered",l) != 0 )
6005 return false;
6008 bool triggered = (trig_str != NULL);
6010 m_session->GetPlayer()->CastSpell(target,spell,triggered);
6012 return true;
6015 bool ChatHandler::HandleCastBackCommand(const char* args)
6017 Creature* caster = getSelectedCreature();
6019 if(!caster)
6021 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
6022 SetSentErrorMessage(true);
6023 return false;
6026 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
6027 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6028 uint32 spell = extractSpellIdFromLink((char*)args);
6029 if(!spell || !sSpellStore.LookupEntry(spell))
6030 return false;
6032 char* trig_str = strtok(NULL, " ");
6033 if(trig_str)
6035 int l = strlen(trig_str);
6036 if(strncmp(trig_str,"triggered",l) != 0 )
6037 return false;
6040 bool triggered = (trig_str != NULL);
6042 // update orientation at server
6043 caster->SetOrientation(caster->GetAngle(m_session->GetPlayer()));
6045 // and client
6046 WorldPacket data;
6047 caster->BuildHeartBeatMsg(&data);
6048 caster->SendMessageToSet(&data,true);
6050 caster->CastSpell(m_session->GetPlayer(),spell,triggered);
6052 return true;
6055 bool ChatHandler::HandleCastDistCommand(const char* args)
6057 if(!*args)
6058 return false;
6060 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6061 uint32 spell = extractSpellIdFromLink((char*)args);
6062 if(!spell)
6063 return false;
6065 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
6066 if(!spellInfo)
6067 return false;
6069 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
6071 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
6072 SetSentErrorMessage(true);
6073 return false;
6076 char *distStr = strtok(NULL, " ");
6078 float dist = 0;
6080 if(distStr)
6081 sscanf(distStr, "%f", &dist);
6083 char* trig_str = strtok(NULL, " ");
6084 if(trig_str)
6086 int l = strlen(trig_str);
6087 if(strncmp(trig_str,"triggered",l) != 0 )
6088 return false;
6091 bool triggered = (trig_str != NULL);
6093 float x,y,z;
6094 m_session->GetPlayer()->GetClosePoint(x,y,z,dist);
6096 m_session->GetPlayer()->CastSpell(x,y,z,spell,triggered);
6097 return true;
6100 bool ChatHandler::HandleCastTargetCommand(const char* args)
6102 Creature* caster = getSelectedCreature();
6104 if(!caster)
6106 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
6107 SetSentErrorMessage(true);
6108 return false;
6111 if(!caster->getVictim())
6113 SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM);
6114 SetSentErrorMessage(true);
6115 return false;
6118 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6119 uint32 spell = extractSpellIdFromLink((char*)args);
6120 if(!spell || !sSpellStore.LookupEntry(spell))
6121 return false;
6123 char* trig_str = strtok(NULL, " ");
6124 if(trig_str)
6126 int l = strlen(trig_str);
6127 if(strncmp(trig_str,"triggered",l) != 0 )
6128 return false;
6131 bool triggered = (trig_str != NULL);
6133 // update orientation at server
6134 caster->SetOrientation(caster->GetAngle(m_session->GetPlayer()));
6136 // and client
6137 WorldPacket data;
6138 caster->BuildHeartBeatMsg(&data);
6139 caster->SendMessageToSet(&data,true);
6141 caster->CastSpell(caster->getVictim(),spell,triggered);
6143 return true;
6147 ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
6148 Without this function 3rd party scripting library will get linking errors (unresolved external)
6149 when attempting to use the PointMovementGenerator
6151 bool ChatHandler::HandleComeToMeCommand(const char *args)
6153 Creature* caster = getSelectedCreature();
6155 if(!caster)
6157 SendSysMessage(LANG_SELECT_CREATURE);
6158 SetSentErrorMessage(true);
6159 return false;
6162 char* newFlagStr = strtok((char*)args, " ");
6164 if(!newFlagStr)
6165 return false;
6167 uint32 newFlags = atoi(newFlagStr);
6169 caster->SetUnitMovementFlags(newFlags);
6171 Player* pl = m_session->GetPlayer();
6173 caster->GetMotionMaster()->MovePoint(0, pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ());
6174 return true;
6177 bool ChatHandler::HandleCastSelfCommand(const char* args)
6179 if(!*args)
6180 return false;
6182 Unit* target = getSelectedUnit();
6184 if(!target)
6186 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
6187 SetSentErrorMessage(true);
6188 return false;
6191 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6192 uint32 spell = extractSpellIdFromLink((char*)args);
6193 if(!spell)
6194 return false;
6196 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
6197 if(!spellInfo)
6198 return false;
6200 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
6202 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
6203 SetSentErrorMessage(true);
6204 return false;
6207 target->CastSpell(target,spell,false);
6209 return true;
6212 std::string GetTimeString(uint32 time)
6214 uint16 days = time / DAY, hours = (time % DAY) / HOUR, minute = (time % HOUR) / MINUTE;
6215 std::ostringstream ss;
6216 if(days) ss << days << "d ";
6217 if(hours) ss << hours << "h ";
6218 ss << minute << "m";
6219 return ss.str();
6222 bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
6224 Player* player = getSelectedPlayer();
6225 if (!player) player = m_session->GetPlayer();
6226 uint32 counter = 0;
6227 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; i++)
6229 Player::BoundInstancesMap &binds = player->GetBoundInstances(i);
6230 for(Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end(); ++itr)
6232 InstanceSave *save = itr->second.save;
6233 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
6234 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());
6235 counter++;
6238 PSendSysMessage("player binds: %d", counter);
6239 counter = 0;
6240 Group *group = player->GetGroup();
6241 if(group)
6243 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; i++)
6245 Group::BoundInstancesMap &binds = group->GetBoundInstances(i);
6246 for(Group::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end(); ++itr)
6248 InstanceSave *save = itr->second.save;
6249 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
6250 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());
6251 counter++;
6255 PSendSysMessage("group binds: %d", counter);
6257 return true;
6260 bool ChatHandler::HandleInstanceUnbindCommand(const char* args)
6262 if(!*args)
6263 return false;
6265 std::string cmd = args;
6266 if(cmd == "all")
6268 Player* player = getSelectedPlayer();
6269 if (!player) player = m_session->GetPlayer();
6270 uint32 counter = 0;
6271 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; i++)
6273 Player::BoundInstancesMap &binds = player->GetBoundInstances(i);
6274 for(Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end();)
6276 if(itr->first != player->GetMapId())
6278 InstanceSave *save = itr->second.save;
6279 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
6280 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());
6281 player->UnbindInstance(itr, i);
6282 counter++;
6284 else
6285 ++itr;
6288 PSendSysMessage("instances unbound: %d", counter);
6290 return true;
6293 bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
6295 PSendSysMessage("instances loaded: %d", MapManager::Instance().GetNumInstances());
6296 PSendSysMessage("players in instances: %d", MapManager::Instance().GetNumPlayersInInstances());
6297 PSendSysMessage("instance saves: %d", sInstanceSaveManager.GetNumInstanceSaves());
6298 PSendSysMessage("players bound: %d", sInstanceSaveManager.GetNumBoundPlayersTotal());
6299 PSendSysMessage("groups bound: %d", sInstanceSaveManager.GetNumBoundGroupsTotal());
6300 return true;
6303 bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
6305 Player* pl = m_session->GetPlayer();
6307 Map* map = pl->GetMap();
6308 if (!map->IsDungeon())
6310 PSendSysMessage("Map is not a dungeon.");
6311 SetSentErrorMessage(true);
6312 return false;
6315 if (!((InstanceMap*)map)->GetInstanceData())
6317 PSendSysMessage("Map has no instance data.");
6318 SetSentErrorMessage(true);
6319 return false;
6322 ((InstanceMap*)map)->GetInstanceData()->SaveToDB();
6323 return true;
6326 /// Display the list of GMs
6327 bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
6329 ///- Get the accounts with GM Level >0
6330 QueryResult *result = loginDatabase.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
6331 if(result)
6333 SendSysMessage(LANG_GMLIST);
6334 SendSysMessage("========================");
6335 SendSysMessage(LANG_GMLIST_HEADER);
6336 SendSysMessage("========================");
6338 ///- Circle through them. Display username and GM level
6341 Field *fields = result->Fetch();
6342 PSendSysMessage("|%15s|%6s|", fields[0].GetString(),fields[1].GetString());
6343 }while( result->NextRow() );
6345 PSendSysMessage("========================");
6346 delete result;
6348 else
6349 PSendSysMessage(LANG_GMLIST_EMPTY);
6350 return true;
6353 /// Define the 'Message of the day' for the realm
6354 bool ChatHandler::HandleServerSetMotdCommand(const char* args)
6356 sWorld.SetMotd(args);
6357 PSendSysMessage(LANG_MOTD_NEW, args);
6358 return true;
6361 /// Set/Unset the expansion level for an account
6362 bool ChatHandler::HandleAccountSetAddonCommand(const char* args)
6364 ///- Get the command line arguments
6365 char *szAcc = strtok((char*)args," ");
6366 char *szExp = strtok(NULL," ");
6368 if(!szAcc)
6369 return false;
6371 std::string account_name;
6372 uint32 account_id;
6374 if(!szExp)
6376 Player* player = getSelectedPlayer();
6377 if(!player)
6378 return false;
6380 account_id = player->GetSession()->GetAccountId();
6381 accmgr.GetName(account_id,account_name);
6382 szExp = szAcc;
6384 else
6386 ///- Convert Account name to Upper Format
6387 account_name = szAcc;
6388 if(!AccountMgr::normilizeString(account_name))
6390 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
6391 SetSentErrorMessage(true);
6392 return false;
6395 account_id = accmgr.GetId(account_name);
6396 if(!account_id)
6398 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
6399 SetSentErrorMessage(true);
6400 return false;
6405 // Let set addon state only for lesser (strong) security level
6406 // or to self account
6407 if (m_session && m_session->GetAccountId () != account_id &&
6408 HasLowerSecurityAccount (NULL,account_id,true))
6409 return false;
6411 int lev=atoi(szExp); //get int anyway (0 if error)
6412 if(lev < 0)
6413 return false;
6415 // No SQL injection
6416 loginDatabase.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev,account_id);
6417 PSendSysMessage(LANG_ACCOUNT_SETADDON,account_name.c_str(),account_id,lev);
6418 return true;
6421 //Send items by mail
6422 bool ChatHandler::HandleSendItemsCommand(const char* args)
6424 if(!*args)
6425 return false;
6427 // format: name "subject text" "mail text" item1[:count1] item2[:count2] ... item12[:count12]
6429 std::string name = extractPlayerNameFromLink((char*)args);
6430 if(name.empty())
6432 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6433 SetSentErrorMessage(true);
6434 return false;
6437 char* tail1 = strtok(NULL, "");
6438 if(!tail1)
6439 return false;
6441 char* msgSubject;
6442 if(*tail1=='"')
6443 msgSubject = strtok(tail1+1, "\"");
6444 else
6446 char* space = strtok(tail1, "\"");
6447 if(!space)
6448 return false;
6449 msgSubject = strtok(NULL, "\"");
6452 if (!msgSubject)
6453 return false;
6455 char* tail2 = strtok(NULL, "");
6456 if(!tail2)
6457 return false;
6459 char* msgText;
6460 if(*tail2=='"')
6461 msgText = strtok(tail2+1, "\"");
6462 else
6464 char* space = strtok(tail2, "\"");
6465 if(!space)
6466 return false;
6467 msgText = strtok(NULL, "\"");
6470 if (!msgText)
6471 return false;
6473 // msgSubject, msgText isn't NUL after prev. check
6474 std::string subject = msgSubject;
6475 std::string text = msgText;
6477 // extract items
6478 typedef std::pair<uint32,uint32> ItemPair;
6479 typedef std::list< ItemPair > ItemPairs;
6480 ItemPairs items;
6482 // get all tail string
6483 char* tail = strtok(NULL, "");
6485 // get from tail next item str
6486 while(char* itemStr = strtok(tail, " "))
6488 // and get new tail
6489 tail = strtok(NULL, "");
6491 // parse item str
6492 char* itemIdStr = strtok(itemStr, ":");
6493 char* itemCountStr = strtok(NULL, " ");
6495 uint32 item_id = atoi(itemIdStr);
6496 if(!item_id)
6497 return false;
6499 ItemPrototype const* item_proto = objmgr.GetItemPrototype(item_id);
6500 if(!item_proto)
6502 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
6503 SetSentErrorMessage(true);
6504 return false;
6507 uint32 item_count = itemCountStr ? atoi(itemCountStr) : 1;
6508 if(item_count < 1 || item_proto->MaxCount > 0 && item_count > uint32(item_proto->MaxCount))
6510 PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT, item_count,item_id);
6511 SetSentErrorMessage(true);
6512 return false;
6515 while(item_count > item_proto->GetMaxStackSize())
6517 items.push_back(ItemPair(item_id,item_proto->GetMaxStackSize()));
6518 item_count -= item_proto->GetMaxStackSize();
6521 items.push_back(ItemPair(item_id,item_count));
6523 if(items.size() > MAX_MAIL_ITEMS)
6525 PSendSysMessage(LANG_COMMAND_MAIL_ITEMS_LIMIT, MAX_MAIL_ITEMS);
6526 SetSentErrorMessage(true);
6527 return false;
6531 uint64 receiver_guid = objmgr.GetPlayerGUIDByName(name);
6532 if(!receiver_guid)
6534 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6535 SetSentErrorMessage(true);
6536 return false;
6539 // from console show not existed sender
6540 uint32 sender_guidlo = m_session ? m_session->GetPlayer()->GetGUIDLow() : 0;
6542 uint32 messagetype = MAIL_NORMAL;
6543 uint32 stationery = MAIL_STATIONERY_GM;
6544 uint32 itemTextId = !text.empty() ? objmgr.CreateItemText( text ) : 0;
6546 Player *receiver = objmgr.GetPlayer(receiver_guid);
6548 // fill mail
6549 MailItemsInfo mi; // item list preparing
6551 for(ItemPairs::const_iterator itr = items.begin(); itr != items.end(); ++itr)
6553 if(Item* item = Item::CreateItem(itr->first,itr->second,m_session ? m_session->GetPlayer() : 0))
6555 item->SaveToDB(); // save for prevent lost at next mail load, if send fail then item will deleted
6556 mi.AddItem(item->GetGUIDLow(), item->GetEntry(), item);
6560 WorldSession::SendMailTo(receiver,messagetype, stationery, sender_guidlo, GUID_LOPART(receiver_guid), subject, itemTextId, &mi, 0, 0, MAIL_CHECK_MASK_NONE);
6562 std::string nameLink = playerLink(name);
6563 PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
6564 return true;
6567 ///Send money by mail
6568 bool ChatHandler::HandleSendMoneyCommand(const char* args)
6570 if (!*args)
6571 return false;
6573 /// format: name "subject text" "mail text" money
6575 std::string name = extractPlayerNameFromLink((char*)args);
6576 if(name.empty())
6578 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6579 SetSentErrorMessage(true);
6580 return false;
6583 char* tail1 = strtok(NULL, "");
6584 if (!tail1)
6585 return false;
6587 char* msgSubject;
6588 if (*tail1=='"')
6589 msgSubject = strtok(tail1+1, "\"");
6590 else
6592 char* space = strtok(tail1, "\"");
6593 if (!space)
6594 return false;
6595 msgSubject = strtok(NULL, "\"");
6598 if (!msgSubject)
6599 return false;
6601 char* tail2 = strtok(NULL, "");
6602 if (!tail2)
6603 return false;
6605 char* msgText;
6606 if (*tail2=='"')
6607 msgText = strtok(tail2+1, "\"");
6608 else
6610 char* space = strtok(tail2, "\"");
6611 if (!space)
6612 return false;
6613 msgText = strtok(NULL, "\"");
6616 if (!msgText)
6617 return false;
6619 char* money_str = strtok(NULL, "");
6620 int32 money = money_str ? atoi(money_str) : 0;
6621 if (money <= 0)
6622 return false;
6624 // msgSubject, msgText isn't NUL after prev. check
6625 std::string subject = msgSubject;
6626 std::string text = msgText;
6628 uint64 receiver_guid = objmgr.GetPlayerGUIDByName(name);
6629 if (!receiver_guid)
6631 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6632 SetSentErrorMessage(true);
6633 return false;
6636 // from console show not existed sender
6637 uint32 sender_guidlo = m_session ? m_session->GetPlayer()->GetGUIDLow() : 0;
6639 uint32 messagetype = MAIL_NORMAL;
6640 uint32 stationery = MAIL_STATIONERY_GM;
6641 uint32 itemTextId = !text.empty() ? objmgr.CreateItemText( text ) : 0;
6643 Player *receiver = objmgr.GetPlayer(receiver_guid);
6645 WorldSession::SendMailTo(receiver,messagetype, stationery, sender_guidlo, GUID_LOPART(receiver_guid), subject, itemTextId, NULL, money, 0, MAIL_CHECK_MASK_NONE);
6647 std::string nameLink = playerLink(name);
6648 PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
6649 return true;
6652 /// Send a message to a player in game
6653 bool ChatHandler::HandleSendMessageCommand(const char* args)
6655 ///- Get the command line arguments
6656 std::string name = extractPlayerNameFromLink((char*)args);
6657 if(name.empty())
6659 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6660 SetSentErrorMessage(true);
6661 return false;
6664 char* msg_str = strtok(NULL, "");
6665 if(!msg_str)
6666 return false;
6668 ///- Find the player and check that he is not logging out.
6669 Player *rPlayer = objmgr.GetPlayer(name.c_str());
6670 if(!rPlayer)
6672 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6673 SetSentErrorMessage(true);
6674 return false;
6677 if(rPlayer->GetSession()->isLogingOut())
6679 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6680 SetSentErrorMessage(true);
6681 return false;
6684 ///- Send the message
6685 //Use SendAreaTriggerMessage for fastest delivery.
6686 rPlayer->GetSession()->SendAreaTriggerMessage("%s", msg_str);
6687 rPlayer->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
6689 //Confirmation message
6690 std::string nameLink = playerLink(name);
6691 PSendSysMessage(LANG_SENDMESSAGE,nameLink.c_str(),msg_str);
6692 return true;
6695 bool ChatHandler::HandleFlushArenaPointsCommand(const char * /*args*/)
6697 sBattleGroundMgr.DistributeArenaPoints();
6698 return true;
6701 bool ChatHandler::HandleModifyGenderCommand(const char *args)
6703 if(!*args)
6704 return false;
6706 Player *player = getSelectedPlayer();
6708 if(!player)
6710 PSendSysMessage(LANG_NO_PLAYER);
6711 SetSentErrorMessage(true);
6712 return false;
6715 PlayerInfo const* info = objmgr.GetPlayerInfo(player->getRace(), player->getClass());
6716 if(!info)
6717 return false;
6719 char const* gender_str = (char*)args;
6720 int gender_len = strlen(gender_str);
6722 Gender gender;
6724 if(!strncmp(gender_str, "male", gender_len)) // MALE
6726 if(player->getGender() == GENDER_MALE)
6727 return true;
6729 gender = GENDER_MALE;
6731 else if (!strncmp(gender_str, "female", gender_len)) // FEMALE
6733 if(player->getGender() == GENDER_FEMALE)
6734 return true;
6736 gender = GENDER_FEMALE;
6738 else
6740 SendSysMessage(LANG_MUST_MALE_OR_FEMALE);
6741 SetSentErrorMessage(true);
6742 return false;
6745 // Set gender
6746 player->SetByteValue(UNIT_FIELD_BYTES_0, 2, gender);
6747 player->SetByteValue(PLAYER_BYTES_3, 0, gender);
6749 // Change display ID
6750 player->SetDisplayId(gender ? info->displayId_f : info->displayId_m);
6751 player->SetNativeDisplayId(gender ? info->displayId_f : info->displayId_m);
6753 char const* gender_full = gender ? "female" : "male";
6755 PSendSysMessage(LANG_YOU_CHANGE_GENDER, GetNameLink(player).c_str(), gender_full);
6757 if (needReportToTarget(player))
6758 ChatHandler(player).PSendSysMessage(LANG_YOUR_GENDER_CHANGED, gender_full, GetNameLink().c_str());
6760 return true;