[7607] Improvements in support some generic achievement classes
[AHbot.git] / src / game / Level3.cpp
blob575762c86ec01554e22e0831024101276691f149
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 HandleReloadAllAreaCommand("");
59 HandleReloadAllLootCommand("");
60 HandleReloadAllNpcCommand("");
61 HandleReloadAllQuestCommand("");
62 HandleReloadAllSpellCommand("");
63 HandleReloadAllItemCommand("");
64 HandleReloadAllLocalesCommand("");
66 HandleReloadCommandCommand("");
67 HandleReloadReservedNameCommand("");
68 HandleReloadMangosStringCommand("");
69 HandleReloadGameTeleCommand("");
70 return true;
73 bool ChatHandler::HandleReloadAllAreaCommand(const char*)
75 //HandleReloadQuestAreaTriggersCommand(""); -- reloaded in HandleReloadAllQuestCommand
76 HandleReloadAreaTriggerTeleportCommand("");
77 HandleReloadAreaTriggerTavernCommand("");
78 HandleReloadGameGraveyardZoneCommand("");
79 return true;
82 bool ChatHandler::HandleReloadAllLootCommand(const char*)
84 sLog.outString( "Re-Loading Loot Tables..." );
85 LoadLootTables();
86 SendGlobalSysMessage("DB tables `*_loot_template` reloaded.");
87 return true;
90 bool ChatHandler::HandleReloadAllNpcCommand(const char* /*args*/)
92 HandleReloadNpcGossipCommand("a");
93 HandleReloadNpcOptionCommand("a");
94 HandleReloadNpcTrainerCommand("a");
95 HandleReloadNpcVendorCommand("a");
96 HandleReloadPointsOfInterestCommand("a");
97 return true;
100 bool ChatHandler::HandleReloadAllQuestCommand(const char* /*args*/)
102 HandleReloadQuestAreaTriggersCommand("a");
103 HandleReloadQuestTemplateCommand("a");
105 sLog.outString( "Re-Loading Quests Relations..." );
106 objmgr.LoadQuestRelations();
107 SendGlobalSysMessage("DB tables `*_questrelation` and `*_involvedrelation` reloaded.");
108 return true;
111 bool ChatHandler::HandleReloadAllScriptsCommand(const char*)
113 if(sWorld.IsScriptScheduled())
115 PSendSysMessage("DB scripts used currently, please attempt reload later.");
116 SetSentErrorMessage(true);
117 return false;
120 sLog.outString( "Re-Loading Scripts..." );
121 HandleReloadGameObjectScriptsCommand("a");
122 HandleReloadEventScriptsCommand("a");
123 HandleReloadQuestEndScriptsCommand("a");
124 HandleReloadQuestStartScriptsCommand("a");
125 HandleReloadSpellScriptsCommand("a");
126 SendGlobalSysMessage("DB tables `*_scripts` reloaded.");
127 HandleReloadDbScriptStringCommand("a");
128 return true;
131 bool ChatHandler::HandleReloadAllSpellCommand(const char*)
133 HandleReloadSkillDiscoveryTemplateCommand("a");
134 HandleReloadSkillExtraItemTemplateCommand("a");
135 HandleReloadSpellAffectCommand("a");
136 HandleReloadSpellAreaCommand("a");
137 HandleReloadSpellChainCommand("a");
138 HandleReloadSpellElixirCommand("a");
139 HandleReloadSpellLearnSpellCommand("a");
140 HandleReloadSpellProcEventCommand("a");
141 HandleReloadSpellBonusesCommand("a");
142 HandleReloadSpellScriptTargetCommand("a");
143 HandleReloadSpellTargetPositionCommand("a");
144 HandleReloadSpellThreatsCommand("a");
145 HandleReloadSpellPetAurasCommand("a");
146 return true;
149 bool ChatHandler::HandleReloadAllItemCommand(const char*)
151 HandleReloadPageTextsCommand("a");
152 HandleReloadItemEnchantementsCommand("a");
153 return true;
156 bool ChatHandler::HandleReloadAllLocalesCommand(const char* /*args*/)
158 HandleReloadLocalesCreatureCommand("a");
159 HandleReloadLocalesGameobjectCommand("a");
160 HandleReloadLocalesItemCommand("a");
161 HandleReloadLocalesNpcTextCommand("a");
162 HandleReloadLocalesPageTextCommand("a");
163 HandleReloadLocalesPointsOfInterestCommand("a");
164 HandleReloadLocalesQuestCommand("a");
165 return true;
168 bool ChatHandler::HandleReloadConfigCommand(const char* /*args*/)
170 sLog.outString( "Re-Loading config settings..." );
171 sWorld.LoadConfigSettings(true);
172 SendGlobalSysMessage("World config settings reloaded.");
173 return true;
176 bool ChatHandler::HandleReloadAreaTriggerTavernCommand(const char*)
178 sLog.outString( "Re-Loading Tavern Area Triggers..." );
179 objmgr.LoadTavernAreaTriggers();
180 SendGlobalSysMessage("DB table `areatrigger_tavern` reloaded.");
181 return true;
184 bool ChatHandler::HandleReloadAreaTriggerTeleportCommand(const char*)
186 sLog.outString( "Re-Loading AreaTrigger teleport definitions..." );
187 objmgr.LoadAreaTriggerTeleports();
188 SendGlobalSysMessage("DB table `areatrigger_teleport` reloaded.");
189 return true;
192 bool ChatHandler::HandleReloadCommandCommand(const char*)
194 load_command_table = true;
195 SendGlobalSysMessage("DB table `command` will be reloaded at next chat command use.");
196 return true;
199 bool ChatHandler::HandleReloadCreatureQuestRelationsCommand(const char*)
201 sLog.outString( "Loading Quests Relations... (`creature_questrelation`)" );
202 objmgr.LoadCreatureQuestRelations();
203 SendGlobalSysMessage("DB table `creature_questrelation` (creature quest givers) reloaded.");
204 return true;
207 bool ChatHandler::HandleReloadCreatureQuestInvRelationsCommand(const char*)
209 sLog.outString( "Loading Quests Relations... (`creature_involvedrelation`)" );
210 objmgr.LoadCreatureInvolvedRelations();
211 SendGlobalSysMessage("DB table `creature_involvedrelation` (creature quest takers) reloaded.");
212 return true;
215 bool ChatHandler::HandleReloadGOQuestRelationsCommand(const char*)
217 sLog.outString( "Loading Quests Relations... (`gameobject_questrelation`)" );
218 objmgr.LoadGameobjectQuestRelations();
219 SendGlobalSysMessage("DB table `gameobject_questrelation` (gameobject quest givers) reloaded.");
220 return true;
223 bool ChatHandler::HandleReloadGOQuestInvRelationsCommand(const char*)
225 sLog.outString( "Loading Quests Relations... (`gameobject_involvedrelation`)" );
226 objmgr.LoadGameobjectInvolvedRelations();
227 SendGlobalSysMessage("DB table `gameobject_involvedrelation` (gameobject quest takers) reloaded.");
228 return true;
231 bool ChatHandler::HandleReloadQuestAreaTriggersCommand(const char*)
233 sLog.outString( "Re-Loading Quest Area Triggers..." );
234 objmgr.LoadQuestAreaTriggers();
235 SendGlobalSysMessage("DB table `areatrigger_involvedrelation` (quest area triggers) reloaded.");
236 return true;
239 bool ChatHandler::HandleReloadQuestTemplateCommand(const char*)
241 sLog.outString( "Re-Loading Quest Templates..." );
242 objmgr.LoadQuests();
243 SendGlobalSysMessage("DB table `quest_template` (quest definitions) reloaded.");
245 /// dependent also from `gameobject` but this table not reloaded anyway
246 sLog.outString( "Re-Loading GameObjects for quests..." );
247 objmgr.LoadGameObjectForQuests();
248 SendGlobalSysMessage("Data GameObjects for quests reloaded.");
249 return true;
252 bool ChatHandler::HandleReloadLootTemplatesCreatureCommand(const char*)
254 sLog.outString( "Re-Loading Loot Tables... (`creature_loot_template`)" );
255 LoadLootTemplates_Creature();
256 LootTemplates_Creature.CheckLootRefs();
257 SendGlobalSysMessage("DB table `creature_loot_template` reloaded.");
258 return true;
261 bool ChatHandler::HandleReloadLootTemplatesDisenchantCommand(const char*)
263 sLog.outString( "Re-Loading Loot Tables... (`disenchant_loot_template`)" );
264 LoadLootTemplates_Disenchant();
265 LootTemplates_Disenchant.CheckLootRefs();
266 SendGlobalSysMessage("DB table `disenchant_loot_template` reloaded.");
267 return true;
270 bool ChatHandler::HandleReloadLootTemplatesFishingCommand(const char*)
272 sLog.outString( "Re-Loading Loot Tables... (`fishing_loot_template`)" );
273 LoadLootTemplates_Fishing();
274 LootTemplates_Fishing.CheckLootRefs();
275 SendGlobalSysMessage("DB table `fishing_loot_template` reloaded.");
276 return true;
279 bool ChatHandler::HandleReloadLootTemplatesGameobjectCommand(const char*)
281 sLog.outString( "Re-Loading Loot Tables... (`gameobject_loot_template`)" );
282 LoadLootTemplates_Gameobject();
283 LootTemplates_Gameobject.CheckLootRefs();
284 SendGlobalSysMessage("DB table `gameobject_loot_template` reloaded.");
285 return true;
288 bool ChatHandler::HandleReloadLootTemplatesItemCommand(const char*)
290 sLog.outString( "Re-Loading Loot Tables... (`item_loot_template`)" );
291 LoadLootTemplates_Item();
292 LootTemplates_Item.CheckLootRefs();
293 SendGlobalSysMessage("DB table `item_loot_template` reloaded.");
294 return true;
297 bool ChatHandler::HandleReloadLootTemplatesMillingCommand(const char*)
299 sLog.outString( "Re-Loading Loot Tables... (`milling_loot_template`)" );
300 LoadLootTemplates_Milling();
301 LootTemplates_Milling.CheckLootRefs();
302 SendGlobalSysMessage("DB table `milling_loot_template` reloaded.");
303 return true;
306 bool ChatHandler::HandleReloadLootTemplatesPickpocketingCommand(const char*)
308 sLog.outString( "Re-Loading Loot Tables... (`pickpocketing_loot_template`)" );
309 LoadLootTemplates_Pickpocketing();
310 LootTemplates_Pickpocketing.CheckLootRefs();
311 SendGlobalSysMessage("DB table `pickpocketing_loot_template` reloaded.");
312 return true;
315 bool ChatHandler::HandleReloadLootTemplatesProspectingCommand(const char*)
317 sLog.outString( "Re-Loading Loot Tables... (`prospecting_loot_template`)" );
318 LoadLootTemplates_Prospecting();
319 LootTemplates_Prospecting.CheckLootRefs();
320 SendGlobalSysMessage("DB table `prospecting_loot_template` reloaded.");
321 return true;
324 bool ChatHandler::HandleReloadLootTemplatesQuestMailCommand(const char*)
326 sLog.outString( "Re-Loading Loot Tables... (`quest_mail_loot_template`)" );
327 LoadLootTemplates_QuestMail();
328 LootTemplates_QuestMail.CheckLootRefs();
329 SendGlobalSysMessage("DB table `quest_mail_loot_template` reloaded.");
330 return true;
333 bool ChatHandler::HandleReloadLootTemplatesReferenceCommand(const char*)
335 sLog.outString( "Re-Loading Loot Tables... (`reference_loot_template`)" );
336 LoadLootTemplates_Reference();
337 SendGlobalSysMessage("DB table `reference_loot_template` reloaded.");
338 return true;
341 bool ChatHandler::HandleReloadLootTemplatesSkinningCommand(const char*)
343 sLog.outString( "Re-Loading Loot Tables... (`skinning_loot_template`)" );
344 LoadLootTemplates_Skinning();
345 LootTemplates_Skinning.CheckLootRefs();
346 SendGlobalSysMessage("DB table `skinning_loot_template` reloaded.");
347 return true;
350 bool ChatHandler::HandleReloadLootTemplatesSpellCommand(const char*)
352 sLog.outString( "Re-Loading Loot Tables... (`spell_loot_template`)" );
353 LoadLootTemplates_Spell();
354 LootTemplates_Spell.CheckLootRefs();
355 SendGlobalSysMessage("DB table `spell_loot_template` reloaded.");
356 return true;
359 bool ChatHandler::HandleReloadMangosStringCommand(const char*)
361 sLog.outString( "Re-Loading mangos_string Table!" );
362 objmgr.LoadMangosStrings();
363 SendGlobalSysMessage("DB table `mangos_string` reloaded.");
364 return true;
367 bool ChatHandler::HandleReloadNpcOptionCommand(const char*)
369 sLog.outString( "Re-Loading `npc_option` Table!" );
370 objmgr.LoadNpcOptions();
371 SendGlobalSysMessage("DB table `npc_option` reloaded.");
372 return true;
375 bool ChatHandler::HandleReloadNpcGossipCommand(const char*)
377 sLog.outString( "Re-Loading `npc_gossip` Table!" );
378 objmgr.LoadNpcTextId();
379 SendGlobalSysMessage("DB table `npc_gossip` reloaded.");
380 return true;
383 bool ChatHandler::HandleReloadNpcTrainerCommand(const char*)
385 sLog.outString( "Re-Loading `npc_trainer` Table!" );
386 objmgr.LoadTrainerSpell();
387 SendGlobalSysMessage("DB table `npc_trainer` reloaded.");
388 return true;
391 bool ChatHandler::HandleReloadNpcVendorCommand(const char*)
393 sLog.outString( "Re-Loading `npc_vendor` Table!" );
394 objmgr.LoadVendors();
395 SendGlobalSysMessage("DB table `npc_vendor` reloaded.");
396 return true;
399 bool ChatHandler::HandleReloadPointsOfInterestCommand(const char*)
401 sLog.outString( "Re-Loading `points_of_interest` Table!" );
402 objmgr.LoadPointsOfInterest();
403 SendGlobalSysMessage("DB table `points_of_interest` reloaded.");
404 return true;
407 bool ChatHandler::HandleReloadReservedNameCommand(const char*)
409 sLog.outString( "Loading ReservedNames... (`reserved_name`)" );
410 objmgr.LoadReservedPlayersNames();
411 SendGlobalSysMessage("DB table `reserved_name` (player reserved names) reloaded.");
412 return true;
415 bool ChatHandler::HandleReloadSkillDiscoveryTemplateCommand(const char* /*args*/)
417 sLog.outString( "Re-Loading Skill Discovery Table..." );
418 LoadSkillDiscoveryTable();
419 SendGlobalSysMessage("DB table `skill_discovery_template` (recipes discovered at crafting) reloaded.");
420 return true;
423 bool ChatHandler::HandleReloadSkillExtraItemTemplateCommand(const char* /*args*/)
425 sLog.outString( "Re-Loading Skill Extra Item Table..." );
426 LoadSkillExtraItemTable();
427 SendGlobalSysMessage("DB table `skill_extra_item_template` (extra item creation when crafting) reloaded.");
428 return true;
431 bool ChatHandler::HandleReloadSkillFishingBaseLevelCommand(const char* /*args*/)
433 sLog.outString( "Re-Loading Skill Fishing base level requirements..." );
434 objmgr.LoadFishingBaseSkillLevel();
435 SendGlobalSysMessage("DB table `skill_fishing_base_level` (fishing base level for zone/subzone) reloaded.");
436 return true;
439 bool ChatHandler::HandleReloadSpellAffectCommand(const char*)
441 sLog.outString( "Re-Loading SpellAffect definitions..." );
442 spellmgr.LoadSpellAffects();
443 SendGlobalSysMessage("DB table `spell_affect` (spell mods apply requirements) reloaded.");
444 return true;
447 bool ChatHandler::HandleReloadSpellAreaCommand(const char*)
449 sLog.outString( "Re-Loading SpellArea Data..." );
450 spellmgr.LoadSpellAreas();
451 SendGlobalSysMessage("DB table `spell_area` (spell dependences from area/quest/auras state) reloaded.");
452 return true;
455 bool ChatHandler::HandleReloadSpellChainCommand(const char*)
457 sLog.outString( "Re-Loading Spell Chain Data... " );
458 spellmgr.LoadSpellChains();
459 SendGlobalSysMessage("DB table `spell_chain` (spell ranks) reloaded.");
460 return true;
463 bool ChatHandler::HandleReloadSpellElixirCommand(const char*)
465 sLog.outString( "Re-Loading Spell Elixir types..." );
466 spellmgr.LoadSpellElixirs();
467 SendGlobalSysMessage("DB table `spell_elixir` (spell elixir types) reloaded.");
468 return true;
471 bool ChatHandler::HandleReloadSpellLearnSpellCommand(const char*)
473 sLog.outString( "Re-Loading Spell Learn Spells..." );
474 spellmgr.LoadSpellLearnSpells();
475 SendGlobalSysMessage("DB table `spell_learn_spell` reloaded.");
476 return true;
479 bool ChatHandler::HandleReloadSpellProcEventCommand(const char*)
481 sLog.outString( "Re-Loading Spell Proc Event conditions..." );
482 spellmgr.LoadSpellProcEvents();
483 SendGlobalSysMessage("DB table `spell_proc_event` (spell proc trigger requirements) reloaded.");
484 return true;
487 bool ChatHandler::HandleReloadSpellBonusesCommand(const char*)
489 sLog.outString( "Re-Loading Spell Bonus Data..." );
490 spellmgr.LoadSpellBonusess();
491 SendGlobalSysMessage("DB table `spell_bonus_data` (spell damage/healing coefficients) reloaded.");
492 return true;
495 bool ChatHandler::HandleReloadSpellScriptTargetCommand(const char*)
497 sLog.outString( "Re-Loading SpellsScriptTarget..." );
498 spellmgr.LoadSpellScriptTarget();
499 SendGlobalSysMessage("DB table `spell_script_target` (spell targets selection in case specific creature/GO requirements) reloaded.");
500 return true;
503 bool ChatHandler::HandleReloadSpellTargetPositionCommand(const char*)
505 sLog.outString( "Re-Loading Spell target coordinates..." );
506 spellmgr.LoadSpellTargetPositions();
507 SendGlobalSysMessage("DB table `spell_target_position` (destination coordinates for spell targets) reloaded.");
508 return true;
511 bool ChatHandler::HandleReloadSpellThreatsCommand(const char*)
513 sLog.outString( "Re-Loading Aggro Spells Definitions...");
514 spellmgr.LoadSpellThreats();
515 SendGlobalSysMessage("DB table `spell_threat` (spell aggro definitions) reloaded.");
516 return true;
519 bool ChatHandler::HandleReloadSpellPetAurasCommand(const char*)
521 sLog.outString( "Re-Loading Spell pet auras...");
522 spellmgr.LoadSpellPetAuras();
523 SendGlobalSysMessage("DB table `spell_pet_auras` reloaded.");
524 return true;
527 bool ChatHandler::HandleReloadPageTextsCommand(const char*)
529 sLog.outString( "Re-Loading Page Texts..." );
530 objmgr.LoadPageTexts();
531 SendGlobalSysMessage("DB table `page_texts` reloaded.");
532 return true;
535 bool ChatHandler::HandleReloadItemEnchantementsCommand(const char*)
537 sLog.outString( "Re-Loading Item Random Enchantments Table..." );
538 LoadRandomEnchantmentsTable();
539 SendGlobalSysMessage("DB table `item_enchantment_template` reloaded.");
540 return true;
543 bool ChatHandler::HandleReloadGameObjectScriptsCommand(const char* arg)
545 if(sWorld.IsScriptScheduled())
547 SendSysMessage("DB scripts used currently, please attempt reload later.");
548 SetSentErrorMessage(true);
549 return false;
552 if(*arg!='a')
553 sLog.outString( "Re-Loading Scripts from `gameobject_scripts`...");
555 objmgr.LoadGameObjectScripts();
557 if(*arg!='a')
558 SendGlobalSysMessage("DB table `gameobject_scripts` reloaded.");
560 return true;
563 bool ChatHandler::HandleReloadEventScriptsCommand(const char* arg)
565 if(sWorld.IsScriptScheduled())
567 SendSysMessage("DB scripts used currently, please attempt reload later.");
568 SetSentErrorMessage(true);
569 return false;
572 if(*arg!='a')
573 sLog.outString( "Re-Loading Scripts from `event_scripts`...");
575 objmgr.LoadEventScripts();
577 if(*arg!='a')
578 SendGlobalSysMessage("DB table `event_scripts` reloaded.");
580 return true;
583 bool ChatHandler::HandleReloadQuestEndScriptsCommand(const char* arg)
585 if(sWorld.IsScriptScheduled())
587 SendSysMessage("DB scripts used currently, please attempt reload later.");
588 SetSentErrorMessage(true);
589 return false;
592 if(*arg!='a')
593 sLog.outString( "Re-Loading Scripts from `quest_end_scripts`...");
595 objmgr.LoadQuestEndScripts();
597 if(*arg!='a')
598 SendGlobalSysMessage("DB table `quest_end_scripts` reloaded.");
600 return true;
603 bool ChatHandler::HandleReloadQuestStartScriptsCommand(const char* arg)
605 if(sWorld.IsScriptScheduled())
607 SendSysMessage("DB scripts used currently, please attempt reload later.");
608 SetSentErrorMessage(true);
609 return false;
612 if(*arg!='a')
613 sLog.outString( "Re-Loading Scripts from `quest_start_scripts`...");
615 objmgr.LoadQuestStartScripts();
617 if(*arg!='a')
618 SendGlobalSysMessage("DB table `quest_start_scripts` reloaded.");
620 return true;
623 bool ChatHandler::HandleReloadSpellScriptsCommand(const char* arg)
625 if(sWorld.IsScriptScheduled())
627 SendSysMessage("DB scripts used currently, please attempt reload later.");
628 SetSentErrorMessage(true);
629 return false;
632 if(*arg!='a')
633 sLog.outString( "Re-Loading Scripts from `spell_scripts`...");
635 objmgr.LoadSpellScripts();
637 if(*arg!='a')
638 SendGlobalSysMessage("DB table `spell_scripts` reloaded.");
640 return true;
643 bool ChatHandler::HandleReloadDbScriptStringCommand(const char* arg)
645 sLog.outString( "Re-Loading Script strings from `db_script_string`...");
646 objmgr.LoadDbScriptStrings();
647 SendGlobalSysMessage("DB table `db_script_string` reloaded.");
648 return true;
651 bool ChatHandler::HandleReloadGameGraveyardZoneCommand(const char* /*arg*/)
653 sLog.outString( "Re-Loading Graveyard-zone links...");
655 objmgr.LoadGraveyardZones();
657 SendGlobalSysMessage("DB table `game_graveyard_zone` reloaded.");
659 return true;
662 bool ChatHandler::HandleReloadGameTeleCommand(const char* /*arg*/)
664 sLog.outString( "Re-Loading Game Tele coordinates...");
666 objmgr.LoadGameTele();
668 SendGlobalSysMessage("DB table `game_tele` reloaded.");
670 return true;
673 bool ChatHandler::HandleReloadLocalesCreatureCommand(const char* /*arg*/)
675 sLog.outString( "Re-Loading Locales Creature ...");
676 objmgr.LoadCreatureLocales();
677 SendGlobalSysMessage("DB table `locales_creature` reloaded.");
678 return true;
681 bool ChatHandler::HandleReloadLocalesGameobjectCommand(const char* /*arg*/)
683 sLog.outString( "Re-Loading Locales Gameobject ... ");
684 objmgr.LoadGameObjectLocales();
685 SendGlobalSysMessage("DB table `locales_gameobject` reloaded.");
686 return true;
689 bool ChatHandler::HandleReloadLocalesItemCommand(const char* /*arg*/)
691 sLog.outString( "Re-Loading Locales Item ... ");
692 objmgr.LoadItemLocales();
693 SendGlobalSysMessage("DB table `locales_item` reloaded.");
694 return true;
697 bool ChatHandler::HandleReloadLocalesNpcTextCommand(const char* /*arg*/)
699 sLog.outString( "Re-Loading Locales NPC Text ... ");
700 objmgr.LoadNpcTextLocales();
701 SendGlobalSysMessage("DB table `locales_npc_text` reloaded.");
702 return true;
705 bool ChatHandler::HandleReloadLocalesPageTextCommand(const char* /*arg*/)
707 sLog.outString( "Re-Loading Locales Page Text ... ");
708 objmgr.LoadPageTextLocales();
709 SendGlobalSysMessage("DB table `locales_page_text` reloaded.");
710 return true;
713 bool ChatHandler::HandleReloadLocalesPointsOfInterestCommand(const char* /*arg*/)
715 sLog.outString( "Re-Loading Locales Points Of Interest ... ");
716 objmgr.LoadPointOfInterestLocales();
717 SendGlobalSysMessage("DB table `locales_points_of_interest` reloaded.");
718 return true;
721 bool ChatHandler::HandleReloadLocalesQuestCommand(const char* /*arg*/)
723 sLog.outString( "Re-Loading Locales Quest ... ");
724 objmgr.LoadQuestLocales();
725 SendGlobalSysMessage("DB table `locales_quest` reloaded.");
726 return true;
729 bool ChatHandler::HandleLoadScriptsCommand(const char* args)
731 if(!LoadScriptingModule(args)) return true;
733 sWorld.SendWorldText(LANG_SCRIPTS_RELOADED);
734 return true;
737 bool ChatHandler::HandleAccountSetGmLevelCommand(const char* args)
739 char* arg1 = strtok((char*)args, " ");
740 if( !arg1 )
741 return false;
743 /// must be NULL if targeted syntax and must be not nULL if not targeted
744 char* arg2 = strtok(NULL, " ");
746 std::string targetAccountName;
747 uint32 targetAccountId = 0;
749 /// only target player different from self allowed (if targetPlayer!=NULL then not console)
750 Player* targetPlayer = getSelectedPlayer();
751 if(targetPlayer && m_session->GetPlayer()!=targetPlayer)
753 /// wrong command syntax or unexpected targeting
754 if(arg2)
755 return false;
757 /// security level expected in arg2 after this if.
758 arg2 = arg1;
760 targetAccountId = targetPlayer->GetSession()->GetAccountId();
761 accmgr.GetName(targetAccountId, targetAccountName);
763 else
765 /// wrong command syntax (second arg expected)
766 if(!arg2)
767 return false;
769 targetAccountName = arg1;
770 if(!AccountMgr::normilizeString(targetAccountName))
772 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,targetAccountName.c_str());
773 SetSentErrorMessage(true);
774 return false;
777 targetAccountId = accmgr.GetId(targetAccountName);
778 if(!targetAccountId)
780 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,targetAccountName.c_str());
781 SetSentErrorMessage(true);
782 return false;
786 int32 gm = (int32)atoi(arg2);
787 if ( gm < SEC_PLAYER || gm > SEC_ADMINISTRATOR )
789 SendSysMessage(LANG_BAD_VALUE);
790 SetSentErrorMessage(true);
791 return false;
794 /// can set security level only for target with less security and to less security that we have
795 /// This will reject self apply by specify account name
796 if(HasLowerSecurityAccount(NULL,targetAccountId,true))
797 return false;
799 /// account can't set security to same or grater level, need more power GM or console
800 uint32 plSecurity = m_session ? m_session->GetSecurity() : SEC_CONSOLE;
801 if (uint32(gm) >= plSecurity )
803 SendSysMessage(LANG_YOURS_SECURITY_IS_LOW);
804 SetSentErrorMessage(true);
805 return false;
808 // This will prevent self apply by self target or no target
809 if(targetPlayer && m_session->GetPlayer()!=targetPlayer)
811 ChatHandler(targetPlayer).PSendSysMessage(LANG_YOURS_SECURITY_CHANGED,GetNameLink().c_str(), gm);
812 targetPlayer->GetSession()->SetSecurity(gm);
815 PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetAccountName.c_str(), gm);
816 loginDatabase.PExecute("UPDATE account SET gmlevel = '%i' WHERE id = '%u'", gm, targetAccountId);
818 return true;
821 /// Set password for account
822 bool ChatHandler::HandleAccountSetPasswordCommand(const char* args)
824 if(!*args)
825 return false;
827 ///- Get the command line arguments
828 char *szAccount = strtok ((char*)args," ");
829 char *szPassword1 = strtok (NULL," ");
830 char *szPassword2 = strtok (NULL," ");
832 if (!szAccount||!szPassword1 || !szPassword2)
833 return false;
835 std::string account_name = szAccount;
836 if(!AccountMgr::normilizeString(account_name))
838 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
839 SetSentErrorMessage(true);
840 return false;
843 uint32 targetAccountId = accmgr.GetId(account_name);
844 if (!targetAccountId)
846 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
847 SetSentErrorMessage(true);
848 return false;
851 /// can set password only for target with less security
852 /// This is also reject self apply in fact
853 if(HasLowerSecurityAccount (NULL,targetAccountId,true))
854 return false;
856 if (strcmp(szPassword1,szPassword2))
858 SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH);
859 SetSentErrorMessage (true);
860 return false;
863 AccountOpResult result = accmgr.ChangePassword(targetAccountId, szPassword1);
865 switch(result)
867 case AOR_OK:
868 SendSysMessage(LANG_COMMAND_PASSWORD);
869 break;
870 case AOR_NAME_NOT_EXIST:
871 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
872 SetSentErrorMessage(true);
873 return false;
874 case AOR_PASS_TOO_LONG:
875 SendSysMessage(LANG_PASSWORD_TOO_LONG);
876 SetSentErrorMessage(true);
877 return false;
878 default:
879 SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD);
880 SetSentErrorMessage(true);
881 return false;
884 return true;
887 bool ChatHandler::HandleMaxSkillCommand(const char* /*args*/)
889 Player* SelectedPlayer = getSelectedPlayer();
890 if(!SelectedPlayer)
892 SendSysMessage(LANG_NO_CHAR_SELECTED);
893 SetSentErrorMessage(true);
894 return false;
897 // each skills that have max skill value dependent from level seted to current level max skill value
898 SelectedPlayer->UpdateSkillsToMaxSkillsForLevel();
899 return true;
902 bool ChatHandler::HandleSetSkillCommand(const char* args)
904 // number or [name] Shift-click form |color|Hskill:skill_id|h[name]|h|r
905 char* skill_p = extractKeyFromLink((char*)args,"Hskill");
906 if(!skill_p)
907 return false;
909 char *level_p = strtok (NULL, " ");
911 if( !level_p)
912 return false;
914 char *max_p = strtok (NULL, " ");
916 int32 skill = atoi(skill_p);
917 if (skill <= 0)
919 PSendSysMessage(LANG_INVALID_SKILL_ID, skill);
920 SetSentErrorMessage(true);
921 return false;
924 int32 level = atol (level_p);
926 Player * target = getSelectedPlayer();
927 if(!target)
929 SendSysMessage(LANG_NO_CHAR_SELECTED);
930 SetSentErrorMessage(true);
931 return false;
934 SkillLineEntry const* sl = sSkillLineStore.LookupEntry(skill);
935 if(!sl)
937 PSendSysMessage(LANG_INVALID_SKILL_ID, skill);
938 SetSentErrorMessage(true);
939 return false;
942 std::string tNameLink = GetNameLink(target);
944 if(!target->GetSkillValue(skill))
946 PSendSysMessage(LANG_SET_SKILL_ERROR, tNameLink.c_str(), skill, sl->name[0]);
947 SetSentErrorMessage(true);
948 return false;
951 int32 max = max_p ? atol (max_p) : target->GetPureMaxSkillValue(skill);
953 if( level <= 0 || level > max || max <= 0 )
954 return false;
956 target->SetSkill(skill, level, max);
957 PSendSysMessage(LANG_SET_SKILL, skill, sl->name[0], tNameLink.c_str(), level, max);
959 return true;
962 bool ChatHandler::HandleUnLearnCommand(const char* args)
964 if (!*args)
965 return false;
967 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
968 uint32 spell_id = extractSpellIdFromLink((char*)args);
969 if(!spell_id)
970 return false;
972 char const* allStr = strtok(NULL," ");
973 bool allRanks = allStr ? (strncmp(allStr, "all", strlen(allStr)) == 0) : false;
975 Player* target = getSelectedPlayer();
976 if(!target)
978 SendSysMessage(LANG_NO_CHAR_SELECTED);
979 SetSentErrorMessage(true);
980 return false;
983 if(allRanks)
984 spell_id = spellmgr.GetFirstSpellInChain (spell_id);
986 if (target->HasSpell(spell_id))
987 target->removeSpell(spell_id,false,!allRanks);
988 else
989 SendSysMessage(LANG_FORGET_SPELL);
991 return true;
994 bool ChatHandler::HandleCooldownCommand(const char* args)
996 Player* target = getSelectedPlayer();
997 if(!target)
999 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1000 SetSentErrorMessage(true);
1001 return false;
1004 std::string tNameLink = GetNameLink(target);
1006 if (!*args)
1008 target->RemoveAllSpellCooldown();
1009 PSendSysMessage(LANG_REMOVEALL_COOLDOWN, tNameLink.c_str());
1011 else
1013 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1014 uint32 spell_id = extractSpellIdFromLink((char*)args);
1015 if(!spell_id)
1016 return false;
1018 if(!sSpellStore.LookupEntry(spell_id))
1020 PSendSysMessage(LANG_UNKNOWN_SPELL, target==m_session->GetPlayer() ? GetMangosString(LANG_YOU) : tNameLink.c_str());
1021 SetSentErrorMessage(true);
1022 return false;
1025 WorldPacket data( SMSG_CLEAR_COOLDOWN, (4+8) );
1026 data << uint32(spell_id);
1027 data << uint64(target->GetGUID());
1028 target->GetSession()->SendPacket(&data);
1029 target->RemoveSpellCooldown(spell_id);
1030 PSendSysMessage(LANG_REMOVE_COOLDOWN, spell_id, target==m_session->GetPlayer() ? GetMangosString(LANG_YOU) : tNameLink.c_str());
1032 return true;
1035 bool ChatHandler::HandleLearnAllCommand(const char* /*args*/)
1037 static const char *allSpellList[] =
1039 "3365",
1040 "6233",
1041 "6247",
1042 "6246",
1043 "6477",
1044 "6478",
1045 "22810",
1046 "8386",
1047 "21651",
1048 "21652",
1049 "522",
1050 "7266",
1051 "8597",
1052 "2479",
1053 "22027",
1054 "6603",
1055 "5019",
1056 "133",
1057 "168",
1058 "227",
1059 "5009",
1060 "9078",
1061 "668",
1062 "203",
1063 "20599",
1064 "20600",
1065 "81",
1066 "20597",
1067 "20598",
1068 "20864",
1069 "1459",
1070 "5504",
1071 "587",
1072 "5143",
1073 "118",
1074 "5505",
1075 "597",
1076 "604",
1077 "1449",
1078 "1460",
1079 "2855",
1080 "1008",
1081 "475",
1082 "5506",
1083 "1463",
1084 "12824",
1085 "8437",
1086 "990",
1087 "5145",
1088 "8450",
1089 "1461",
1090 "759",
1091 "8494",
1092 "8455",
1093 "8438",
1094 "6127",
1095 "8416",
1096 "6129",
1097 "8451",
1098 "8495",
1099 "8439",
1100 "3552",
1101 "8417",
1102 "10138",
1103 "12825",
1104 "10169",
1105 "10156",
1106 "10144",
1107 "10191",
1108 "10201",
1109 "10211",
1110 "10053",
1111 "10173",
1112 "10139",
1113 "10145",
1114 "10192",
1115 "10170",
1116 "10202",
1117 "10054",
1118 "10174",
1119 "10193",
1120 "12826",
1121 "2136",
1122 "143",
1123 "145",
1124 "2137",
1125 "2120",
1126 "3140",
1127 "543",
1128 "2138",
1129 "2948",
1130 "8400",
1131 "2121",
1132 "8444",
1133 "8412",
1134 "8457",
1135 "8401",
1136 "8422",
1137 "8445",
1138 "8402",
1139 "8413",
1140 "8458",
1141 "8423",
1142 "8446",
1143 "10148",
1144 "10197",
1145 "10205",
1146 "10149",
1147 "10215",
1148 "10223",
1149 "10206",
1150 "10199",
1151 "10150",
1152 "10216",
1153 "10207",
1154 "10225",
1155 "10151",
1156 "116",
1157 "205",
1158 "7300",
1159 "122",
1160 "837",
1161 "10",
1162 "7301",
1163 "7322",
1164 "6143",
1165 "120",
1166 "865",
1167 "8406",
1168 "6141",
1169 "7302",
1170 "8461",
1171 "8407",
1172 "8492",
1173 "8427",
1174 "8408",
1175 "6131",
1176 "7320",
1177 "10159",
1178 "8462",
1179 "10185",
1180 "10179",
1181 "10160",
1182 "10180",
1183 "10219",
1184 "10186",
1185 "10177",
1186 "10230",
1187 "10181",
1188 "10161",
1189 "10187",
1190 "10220",
1191 "2018",
1192 "2663",
1193 "12260",
1194 "2660",
1195 "3115",
1196 "3326",
1197 "2665",
1198 "3116",
1199 "2738",
1200 "3293",
1201 "2661",
1202 "3319",
1203 "2662",
1204 "9983",
1205 "8880",
1206 "2737",
1207 "2739",
1208 "7408",
1209 "3320",
1210 "2666",
1211 "3323",
1212 "3324",
1213 "3294",
1214 "22723",
1215 "23219",
1216 "23220",
1217 "23221",
1218 "23228",
1219 "23338",
1220 "10788",
1221 "10790",
1222 "5611",
1223 "5016",
1224 "5609",
1225 "2060",
1226 "10963",
1227 "10964",
1228 "10965",
1229 "22593",
1230 "22594",
1231 "596",
1232 "996",
1233 "499",
1234 "768",
1235 "17002",
1236 "1448",
1237 "1082",
1238 "16979",
1239 "1079",
1240 "5215",
1241 "20484",
1242 "5221",
1243 "15590",
1244 "17007",
1245 "6795",
1246 "6807",
1247 "5487",
1248 "1446",
1249 "1066",
1250 "5421",
1251 "3139",
1252 "779",
1253 "6811",
1254 "6808",
1255 "1445",
1256 "5216",
1257 "1737",
1258 "5222",
1259 "5217",
1260 "1432",
1261 "6812",
1262 "9492",
1263 "5210",
1264 "3030",
1265 "1441",
1266 "783",
1267 "6801",
1268 "20739",
1269 "8944",
1270 "9491",
1271 "22569",
1272 "5226",
1273 "6786",
1274 "1433",
1275 "8973",
1276 "1828",
1277 "9495",
1278 "9006",
1279 "6794",
1280 "8993",
1281 "5203",
1282 "16914",
1283 "6784",
1284 "9635",
1285 "22830",
1286 "20722",
1287 "9748",
1288 "6790",
1289 "9753",
1290 "9493",
1291 "9752",
1292 "9831",
1293 "9825",
1294 "9822",
1295 "5204",
1296 "5401",
1297 "22831",
1298 "6793",
1299 "9845",
1300 "17401",
1301 "9882",
1302 "9868",
1303 "20749",
1304 "9893",
1305 "9899",
1306 "9895",
1307 "9832",
1308 "9902",
1309 "9909",
1310 "22832",
1311 "9828",
1312 "9851",
1313 "9883",
1314 "9869",
1315 "17406",
1316 "17402",
1317 "9914",
1318 "20750",
1319 "9897",
1320 "9848",
1321 "3127",
1322 "107",
1323 "204",
1324 "9116",
1325 "2457",
1326 "78",
1327 "18848",
1328 "331",
1329 "403",
1330 "2098",
1331 "1752",
1332 "11278",
1333 "11288",
1334 "11284",
1335 "6461",
1336 "2344",
1337 "2345",
1338 "6463",
1339 "2346",
1340 "2352",
1341 "775",
1342 "1434",
1343 "1612",
1344 "71",
1345 "2468",
1346 "2458",
1347 "2467",
1348 "7164",
1349 "7178",
1350 "7367",
1351 "7376",
1352 "7381",
1353 "21156",
1354 "5209",
1355 "3029",
1356 "5201",
1357 "9849",
1358 "9850",
1359 "20719",
1360 "22568",
1361 "22827",
1362 "22828",
1363 "22829",
1364 "6809",
1365 "8972",
1366 "9005",
1367 "9823",
1368 "9827",
1369 "6783",
1370 "9913",
1371 "6785",
1372 "6787",
1373 "9866",
1374 "9867",
1375 "9894",
1376 "9896",
1377 "6800",
1378 "8992",
1379 "9829",
1380 "9830",
1381 "780",
1382 "769",
1383 "6749",
1384 "6750",
1385 "9755",
1386 "9754",
1387 "9908",
1388 "20745",
1389 "20742",
1390 "20747",
1391 "20748",
1392 "9746",
1393 "9745",
1394 "9880",
1395 "9881",
1396 "5391",
1397 "842",
1398 "3025",
1399 "3031",
1400 "3287",
1401 "3329",
1402 "1945",
1403 "3559",
1404 "4933",
1405 "4934",
1406 "4935",
1407 "4936",
1408 "5142",
1409 "5390",
1410 "5392",
1411 "5404",
1412 "5420",
1413 "6405",
1414 "7293",
1415 "7965",
1416 "8041",
1417 "8153",
1418 "9033",
1419 "9034",
1420 //"9036", problems with ghost state
1421 "16421",
1422 "21653",
1423 "22660",
1424 "5225",
1425 "9846",
1426 "2426",
1427 "5916",
1428 "6634",
1429 //"6718", phasing stealth, annoying for learn all case.
1430 "6719",
1431 "8822",
1432 "9591",
1433 "9590",
1434 "10032",
1435 "17746",
1436 "17747",
1437 "8203",
1438 "11392",
1439 "12495",
1440 "16380",
1441 "23452",
1442 "4079",
1443 "4996",
1444 "4997",
1445 "4998",
1446 "4999",
1447 "5000",
1448 "6348",
1449 "6349",
1450 "6481",
1451 "6482",
1452 "6483",
1453 "6484",
1454 "11362",
1455 "11410",
1456 "11409",
1457 "12510",
1458 "12509",
1459 "12885",
1460 "13142",
1461 "21463",
1462 "23460",
1463 "11421",
1464 "11416",
1465 "11418",
1466 "1851",
1467 "10059",
1468 "11423",
1469 "11417",
1470 "11422",
1471 "11419",
1472 "11424",
1473 "11420",
1474 "27",
1475 "31",
1476 "33",
1477 "34",
1478 "35",
1479 "15125",
1480 "21127",
1481 "22950",
1482 "1180",
1483 "201",
1484 "12593",
1485 "12842",
1486 "16770",
1487 "6057",
1488 "12051",
1489 "18468",
1490 "12606",
1491 "12605",
1492 "18466",
1493 "12502",
1494 "12043",
1495 "15060",
1496 "12042",
1497 "12341",
1498 "12848",
1499 "12344",
1500 "12353",
1501 "18460",
1502 "11366",
1503 "12350",
1504 "12352",
1505 "13043",
1506 "11368",
1507 "11113",
1508 "12400",
1509 "11129",
1510 "16766",
1511 "12573",
1512 "15053",
1513 "12580",
1514 "12475",
1515 "12472",
1516 "12953",
1517 "12488",
1518 "11189",
1519 "12985",
1520 "12519",
1521 "16758",
1522 "11958",
1523 "12490",
1524 "11426",
1525 "3565",
1526 "3562",
1527 "18960",
1528 "3567",
1529 "3561",
1530 "3566",
1531 "3563",
1532 "1953",
1533 "2139",
1534 "12505",
1535 "13018",
1536 "12522",
1537 "12523",
1538 "5146",
1539 "5144",
1540 "5148",
1541 "8419",
1542 "8418",
1543 "10213",
1544 "10212",
1545 "10157",
1546 "12524",
1547 "13019",
1548 "12525",
1549 "13020",
1550 "12526",
1551 "13021",
1552 "18809",
1553 "13031",
1554 "13032",
1555 "13033",
1556 "4036",
1557 "3920",
1558 "3919",
1559 "3918",
1560 "7430",
1561 "3922",
1562 "3923",
1563 "7411",
1564 "7418",
1565 "7421",
1566 "13262",
1567 "7412",
1568 "7415",
1569 "7413",
1570 "7416",
1571 "13920",
1572 "13921",
1573 "7745",
1574 "7779",
1575 "7428",
1576 "7457",
1577 "7857",
1578 "7748",
1579 "7426",
1580 "13421",
1581 "7454",
1582 "13378",
1583 "7788",
1584 "14807",
1585 "14293",
1586 "7795",
1587 "6296",
1588 "20608",
1589 "755",
1590 "444",
1591 "427",
1592 "428",
1593 "442",
1594 "447",
1595 "3578",
1596 "3581",
1597 "19027",
1598 "3580",
1599 "665",
1600 "3579",
1601 "3577",
1602 "6755",
1603 "3576",
1604 "2575",
1605 "2577",
1606 "2578",
1607 "2579",
1608 "2580",
1609 "2656",
1610 "2657",
1611 "2576",
1612 "3564",
1613 "10248",
1614 "8388",
1615 "2659",
1616 "14891",
1617 "3308",
1618 "3307",
1619 "10097",
1620 "2658",
1621 "3569",
1622 "16153",
1623 "3304",
1624 "10098",
1625 "4037",
1626 "3929",
1627 "3931",
1628 "3926",
1629 "3924",
1630 "3930",
1631 "3977",
1632 "3925",
1633 "136",
1634 "228",
1635 "5487",
1636 "43",
1637 "202",
1641 int loop = 0;
1642 while(strcmp(allSpellList[loop], "0"))
1644 uint32 spell = atol((char*)allSpellList[loop++]);
1646 if (m_session->GetPlayer()->HasSpell(spell))
1647 continue;
1649 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
1650 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
1652 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
1653 continue;
1656 m_session->GetPlayer()->learnSpell(spell,false);
1659 SendSysMessage(LANG_COMMAND_LEARN_MANY_SPELLS);
1661 return true;
1664 bool ChatHandler::HandleLearnAllGMCommand(const char* /*args*/)
1666 static const char *gmSpellList[] =
1668 "24347", // Become A Fish, No Breath Bar
1669 "35132", // Visual Boom
1670 "38488", // Attack 4000-8000 AOE
1671 "38795", // Attack 2000 AOE + Slow Down 90%
1672 "15712", // Attack 200
1673 "1852", // GM Spell Silence
1674 "31899", // Kill
1675 "31924", // Kill
1676 "29878", // Kill My Self
1677 "26644", // More Kill
1679 "28550", //Invisible 24
1680 "23452", //Invisible + Target
1684 uint16 gmSpellIter = 0;
1685 while( strcmp(gmSpellList[gmSpellIter], "0") )
1687 uint32 spell = atol((char*)gmSpellList[gmSpellIter++]);
1689 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
1690 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
1692 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
1693 continue;
1696 m_session->GetPlayer()->learnSpell(spell,false);
1699 SendSysMessage(LANG_LEARNING_GM_SKILLS);
1700 return true;
1703 bool ChatHandler::HandleLearnAllMyClassCommand(const char* /*args*/)
1705 HandleLearnAllMySpellsCommand("");
1706 HandleLearnAllMyTalentsCommand("");
1707 return true;
1710 bool ChatHandler::HandleLearnAllMySpellsCommand(const char* /*args*/)
1712 ChrClassesEntry const* clsEntry = sChrClassesStore.LookupEntry(m_session->GetPlayer()->getClass());
1713 if(!clsEntry)
1714 return true;
1715 uint32 family = clsEntry->spellfamily;
1717 for (uint32 i = 0; i < sSpellStore.GetNumRows(); i++)
1719 SpellEntry const *spellInfo = sSpellStore.LookupEntry(i);
1720 if(!spellInfo)
1721 continue;
1723 // skip server-side/triggered spells
1724 if(spellInfo->spellLevel==0)
1725 continue;
1727 // skip wrong class/race skills
1728 if(!m_session->GetPlayer()->IsSpellFitByClassAndRace(spellInfo->Id))
1729 continue;
1731 // skip other spell families
1732 if( spellInfo->SpellFamilyName != family)
1733 continue;
1735 // skip spells with first rank learned as talent (and all talents then also)
1736 uint32 first_rank = spellmgr.GetFirstSpellInChain(spellInfo->Id);
1737 if(GetTalentSpellCost(first_rank) > 0 )
1738 continue;
1740 // skip broken spells
1741 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
1742 continue;
1744 m_session->GetPlayer()->learnSpell(i,false);
1747 SendSysMessage(LANG_COMMAND_LEARN_CLASS_SPELLS);
1748 return true;
1751 bool ChatHandler::HandleLearnAllMyTalentsCommand(const char* /*args*/)
1753 Player* player = m_session->GetPlayer();
1754 uint32 classMask = player->getClassMask();
1756 for (uint32 i = 0; i < sTalentStore.GetNumRows(); i++)
1758 TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
1759 if(!talentInfo)
1760 continue;
1762 TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentInfo->TalentTab );
1763 if(!talentTabInfo)
1764 continue;
1766 if( (classMask & talentTabInfo->ClassMask) == 0 )
1767 continue;
1769 // search highest talent rank
1770 uint32 spellid = 0;
1772 for(int rank = MAX_TALENT_RANK-1; rank >= 0; --rank)
1774 if(talentInfo->RankID[rank]!=0)
1776 spellid = talentInfo->RankID[rank];
1777 break;
1781 if(!spellid) // ??? none spells in talent
1782 continue;
1784 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellid);
1785 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
1786 continue;
1788 // learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
1789 player->learnSpellHighRank(spellid);
1792 SendSysMessage(LANG_COMMAND_LEARN_CLASS_TALENTS);
1793 return true;
1796 bool ChatHandler::HandleLearnAllMyPetTalentsCommand(const char* /*args*/)
1798 Player* player = m_session->GetPlayer();
1800 Pet* pet = player->GetPet();
1801 if(!pet)
1803 SendSysMessage(LANG_NO_PET_FOUND);
1804 SetSentErrorMessage(true);
1805 return false;
1808 CreatureInfo const *ci = pet->GetCreatureInfo();
1809 if(!ci)
1811 SendSysMessage(LANG_WRONG_PET_TYPE);
1812 SetSentErrorMessage(true);
1813 return false;
1816 CreatureFamilyEntry const *pet_family = sCreatureFamilyStore.LookupEntry(ci->family);
1817 if(!pet_family)
1819 SendSysMessage(LANG_WRONG_PET_TYPE);
1820 SetSentErrorMessage(true);
1821 return false;
1824 if(pet_family->petTalentType < 0) // not hunter pet
1826 SendSysMessage(LANG_WRONG_PET_TYPE);
1827 SetSentErrorMessage(true);
1828 return false;
1831 for (uint32 i = 0; i < sTalentStore.GetNumRows(); i++)
1833 TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
1834 if(!talentInfo)
1835 continue;
1837 TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentInfo->TalentTab );
1838 if(!talentTabInfo)
1839 continue;
1841 // prevent learn talent for different family (cheating)
1842 if(((1 << pet_family->petTalentType) & talentTabInfo->petTalentMask)==0)
1843 continue;
1845 // search highest talent rank
1846 uint32 spellid = 0;
1848 for(int rank = MAX_TALENT_RANK-1; rank >= 0; --rank)
1850 if(talentInfo->RankID[rank]!=0)
1852 spellid = talentInfo->RankID[rank];
1853 break;
1857 if(!spellid) // ??? none spells in talent
1858 continue;
1860 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellid);
1861 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
1862 continue;
1864 // learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
1865 pet->learnSpellHighRank(spellid);
1868 SendSysMessage(LANG_COMMAND_LEARN_PET_TALENTS);
1869 return true;
1872 bool ChatHandler::HandleLearnAllLangCommand(const char* /*args*/)
1874 // skipping UNIVERSAL language (0)
1875 for(int i = 1; i < LANGUAGES_COUNT; ++i)
1876 m_session->GetPlayer()->learnSpell(lang_description[i].spell_id,false);
1878 SendSysMessage(LANG_COMMAND_LEARN_ALL_LANG);
1879 return true;
1882 bool ChatHandler::HandleLearnAllDefaultCommand(const char* args)
1884 Player *player = NULL;
1885 if (*args)
1887 std::string name = extractPlayerNameFromLink((char*)args);
1888 if(name.empty())
1890 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1891 SetSentErrorMessage(true);
1892 return false;
1895 player = objmgr.GetPlayer(name.c_str());
1897 else
1898 player = getSelectedPlayer();
1900 if(!player)
1902 SendSysMessage(LANG_NO_CHAR_SELECTED);
1903 SetSentErrorMessage(true);
1904 return false;
1907 player->learnDefaultSpells();
1908 player->learnQuestRewardedSpells();
1910 PSendSysMessage(LANG_COMMAND_LEARN_ALL_DEFAULT_AND_QUEST,GetNameLink(player).c_str());
1911 return true;
1914 bool ChatHandler::HandleLearnCommand(const char* args)
1916 Player* targetPlayer = getSelectedPlayer();
1918 if(!targetPlayer)
1920 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1921 SetSentErrorMessage(true);
1922 return false;
1925 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1926 uint32 spell = extractSpellIdFromLink((char*)args);
1927 if(!spell || !sSpellStore.LookupEntry(spell))
1928 return false;
1930 char const* allStr = strtok(NULL," ");
1931 bool allRanks = allStr ? (strncmp(allStr, "all", strlen(allStr)) == 0) : false;
1933 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
1934 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
1936 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
1937 SetSentErrorMessage(true);
1938 return false;
1941 if (!allRanks && targetPlayer->HasSpell(spell))
1943 if(targetPlayer == m_session->GetPlayer())
1944 SendSysMessage(LANG_YOU_KNOWN_SPELL);
1945 else
1946 PSendSysMessage(LANG_TARGET_KNOWN_SPELL,GetNameLink(targetPlayer).c_str());
1947 SetSentErrorMessage(true);
1948 return false;
1951 if(allRanks)
1952 targetPlayer->learnSpellHighRank(spell);
1953 else
1954 targetPlayer->learnSpell(spell,false);
1956 return true;
1959 bool ChatHandler::HandleAddItemCommand(const char* args)
1961 if (!*args)
1962 return false;
1964 uint32 itemId = 0;
1966 if(args[0]=='[') // [name] manual form
1968 char* citemName = citemName = strtok((char*)args, "]");
1970 if(citemName && citemName[0])
1972 std::string itemName = citemName+1;
1973 WorldDatabase.escape_string(itemName);
1974 QueryResult *result = WorldDatabase.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName.c_str());
1975 if (!result)
1977 PSendSysMessage(LANG_COMMAND_COULDNOTFIND, citemName+1);
1978 SetSentErrorMessage(true);
1979 return false;
1981 itemId = result->Fetch()->GetUInt16();
1982 delete result;
1984 else
1985 return false;
1987 else // item_id or [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r
1989 char* cId = extractKeyFromLink((char*)args,"Hitem");
1990 if(!cId)
1991 return false;
1992 itemId = atol(cId);
1995 char* ccount = strtok(NULL, " ");
1997 int32 count = 1;
1999 if (ccount)
2000 count = strtol(ccount, NULL, 10);
2002 if (count == 0)
2003 count = 1;
2005 Player* pl = m_session->GetPlayer();
2006 Player* plTarget = getSelectedPlayer();
2007 if(!plTarget)
2008 plTarget = pl;
2010 sLog.outDetail(GetMangosString(LANG_ADDITEM), itemId, count);
2012 ItemPrototype const *pProto = objmgr.GetItemPrototype(itemId);
2013 if(!pProto)
2015 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, itemId);
2016 SetSentErrorMessage(true);
2017 return false;
2020 //Subtract
2021 if (count < 0)
2023 plTarget->DestroyItemCount(itemId, -count, true, false);
2024 PSendSysMessage(LANG_REMOVEITEM, itemId, -count, GetNameLink(plTarget).c_str());
2025 return true;
2028 //Adding items
2029 uint32 noSpaceForCount = 0;
2031 // check space and find places
2032 ItemPosCountVec dest;
2033 uint8 msg = plTarget->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, itemId, count, &noSpaceForCount );
2034 if( msg != EQUIP_ERR_OK ) // convert to possible store amount
2035 count -= noSpaceForCount;
2037 if( count == 0 || dest.empty()) // can't add any
2039 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount );
2040 SetSentErrorMessage(true);
2041 return false;
2044 Item* item = plTarget->StoreNewItem( dest, itemId, true, Item::GenerateItemRandomPropertyId(itemId));
2046 // remove binding (let GM give it to another player later)
2047 if(pl==plTarget)
2048 for(ItemPosCountVec::const_iterator itr = dest.begin(); itr != dest.end(); ++itr)
2049 if(Item* item1 = pl->GetItemByPos(itr->pos))
2050 item1->SetBinding( false );
2052 if(count > 0 && item)
2054 pl->SendNewItem(item,count,false,true);
2055 if(pl!=plTarget)
2056 plTarget->SendNewItem(item,count,true,false);
2059 if(noSpaceForCount > 0)
2060 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount);
2062 return true;
2065 bool ChatHandler::HandleAddItemSetCommand(const char* args)
2067 if (!*args)
2068 return false;
2070 char* cId = extractKeyFromLink((char*)args,"Hitemset"); // number or [name] Shift-click form |color|Hitemset:itemset_id|h[name]|h|r
2071 if (!cId)
2072 return false;
2074 uint32 itemsetId = atol(cId);
2076 // prevent generation all items with itemset field value '0'
2077 if (itemsetId == 0)
2079 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND,itemsetId);
2080 SetSentErrorMessage(true);
2081 return false;
2084 Player* pl = m_session->GetPlayer();
2085 Player* plTarget = getSelectedPlayer();
2086 if(!plTarget)
2087 plTarget = pl;
2089 sLog.outDetail(GetMangosString(LANG_ADDITEMSET), itemsetId);
2091 bool found = false;
2092 for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
2094 ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype>(id);
2095 if (!pProto)
2096 continue;
2098 if (pProto->ItemSet == itemsetId)
2100 found = true;
2101 ItemPosCountVec dest;
2102 uint8 msg = plTarget->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, pProto->ItemId, 1 );
2103 if (msg == EQUIP_ERR_OK)
2105 Item* item = plTarget->StoreNewItem( dest, pProto->ItemId, true);
2107 // remove binding (let GM give it to another player later)
2108 if (pl==plTarget)
2109 item->SetBinding( false );
2111 pl->SendNewItem(item,1,false,true);
2112 if (pl!=plTarget)
2113 plTarget->SendNewItem(item,1,true,false);
2115 else
2117 pl->SendEquipError( msg, NULL, NULL );
2118 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, pProto->ItemId, 1);
2123 if (!found)
2125 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND,itemsetId);
2127 SetSentErrorMessage(true);
2128 return false;
2131 return true;
2134 bool ChatHandler::HandleListItemCommand(const char* args)
2136 if(!*args)
2137 return false;
2139 char* cId = extractKeyFromLink((char*)args,"Hitem");
2140 if(!cId)
2141 return false;
2143 uint32 item_id = atol(cId);
2144 if(!item_id)
2146 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
2147 SetSentErrorMessage(true);
2148 return false;
2151 ItemPrototype const* itemProto = objmgr.GetItemPrototype(item_id);
2152 if(!itemProto)
2154 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
2155 SetSentErrorMessage(true);
2156 return false;
2159 char* c_count = strtok(NULL, " ");
2160 int count = c_count ? atol(c_count) : 10;
2162 if(count < 0)
2163 return false;
2165 QueryResult *result;
2167 // inventory case
2168 uint32 inv_count = 0;
2169 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM character_inventory WHERE item_template='%u'",item_id);
2170 if(result)
2172 inv_count = (*result)[0].GetUInt32();
2173 delete result;
2176 result=CharacterDatabase.PQuery(
2177 // 0 1 2 3 4 5
2178 "SELECT ci.item, cibag.slot AS bag, ci.slot, ci.guid, characters.account,characters.name "
2179 "FROM character_inventory AS ci LEFT JOIN character_inventory AS cibag ON (cibag.item=ci.bag),characters "
2180 "WHERE ci.item_template='%u' AND ci.guid = characters.guid LIMIT %u ",
2181 item_id,uint32(count));
2183 if(result)
2187 Field *fields = result->Fetch();
2188 uint32 item_guid = fields[0].GetUInt32();
2189 uint32 item_bag = fields[1].GetUInt32();
2190 uint32 item_slot = fields[2].GetUInt32();
2191 uint32 owner_guid = fields[3].GetUInt32();
2192 uint32 owner_acc = fields[4].GetUInt32();
2193 std::string owner_name = fields[5].GetCppString();
2195 char const* item_pos = 0;
2196 if(Player::IsEquipmentPos(item_bag,item_slot))
2197 item_pos = "[equipped]";
2198 else if(Player::IsInventoryPos(item_bag,item_slot))
2199 item_pos = "[in inventory]";
2200 else if(Player::IsBankPos(item_bag,item_slot))
2201 item_pos = "[in bank]";
2202 else
2203 item_pos = "";
2205 PSendSysMessage(LANG_ITEMLIST_SLOT,
2206 item_guid,owner_name.c_str(),owner_guid,owner_acc,item_pos);
2207 } while (result->NextRow());
2209 int64 res_count = result->GetRowCount();
2211 delete result;
2213 if(count > res_count)
2214 count-=res_count;
2215 else if(count)
2216 count = 0;
2219 // mail case
2220 uint32 mail_count = 0;
2221 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM mail_items WHERE item_template='%u'", item_id);
2222 if(result)
2224 mail_count = (*result)[0].GetUInt32();
2225 delete result;
2228 if(count > 0)
2230 result=CharacterDatabase.PQuery(
2231 // 0 1 2 3 4 5 6
2232 "SELECT mail_items.item_guid, mail.sender, mail.receiver, char_s.account, char_s.name, char_r.account, char_r.name "
2233 "FROM mail,mail_items,characters as char_s,characters as char_r "
2234 "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",
2235 item_id,uint32(count));
2237 else
2238 result = NULL;
2240 if(result)
2244 Field *fields = result->Fetch();
2245 uint32 item_guid = fields[0].GetUInt32();
2246 uint32 item_s = fields[1].GetUInt32();
2247 uint32 item_r = fields[2].GetUInt32();
2248 uint32 item_s_acc = fields[3].GetUInt32();
2249 std::string item_s_name = fields[4].GetCppString();
2250 uint32 item_r_acc = fields[5].GetUInt32();
2251 std::string item_r_name = fields[6].GetCppString();
2253 char const* item_pos = "[in mail]";
2255 PSendSysMessage(LANG_ITEMLIST_MAIL,
2256 item_guid,item_s_name.c_str(),item_s,item_s_acc,item_r_name.c_str(),item_r,item_r_acc,item_pos);
2257 } while (result->NextRow());
2259 int64 res_count = result->GetRowCount();
2261 delete result;
2263 if(count > res_count)
2264 count-=res_count;
2265 else if(count)
2266 count = 0;
2269 // auction case
2270 uint32 auc_count = 0;
2271 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM auctionhouse WHERE item_template='%u'",item_id);
2272 if(result)
2274 auc_count = (*result)[0].GetUInt32();
2275 delete result;
2278 if(count > 0)
2280 result=CharacterDatabase.PQuery(
2281 // 0 1 2 3
2282 "SELECT auctionhouse.itemguid, auctionhouse.itemowner, characters.account, characters.name "
2283 "FROM auctionhouse,characters WHERE auctionhouse.item_template='%u' AND characters.guid = auctionhouse.itemowner LIMIT %u",
2284 item_id,uint32(count));
2286 else
2287 result = NULL;
2289 if(result)
2293 Field *fields = result->Fetch();
2294 uint32 item_guid = fields[0].GetUInt32();
2295 uint32 owner = fields[1].GetUInt32();
2296 uint32 owner_acc = fields[2].GetUInt32();
2297 std::string owner_name = fields[3].GetCppString();
2299 char const* item_pos = "[in auction]";
2301 PSendSysMessage(LANG_ITEMLIST_AUCTION, item_guid, owner_name.c_str(), owner, owner_acc,item_pos);
2302 } while (result->NextRow());
2304 delete result;
2307 // guild bank case
2308 uint32 guild_count = 0;
2309 result=CharacterDatabase.PQuery("SELECT COUNT(item_entry) FROM guild_bank_item WHERE item_entry='%u'",item_id);
2310 if(result)
2312 guild_count = (*result)[0].GetUInt32();
2313 delete result;
2316 result=CharacterDatabase.PQuery(
2317 // 0 1 2
2318 "SELECT gi.item_guid, gi.guildid, guild.name "
2319 "FROM guild_bank_item AS gi, guild WHERE gi.item_entry='%u' AND gi.guildid = guild.guildid LIMIT %u ",
2320 item_id,uint32(count));
2322 if(result)
2326 Field *fields = result->Fetch();
2327 uint32 item_guid = fields[0].GetUInt32();
2328 uint32 guild_guid = fields[1].GetUInt32();
2329 std::string guild_name = fields[2].GetCppString();
2331 char const* item_pos = "[in guild bank]";
2333 PSendSysMessage(LANG_ITEMLIST_GUILD,item_guid,guild_name.c_str(),guild_guid,item_pos);
2334 } while (result->NextRow());
2336 int64 res_count = result->GetRowCount();
2338 delete result;
2340 if(count > res_count)
2341 count-=res_count;
2342 else if(count)
2343 count = 0;
2346 if(inv_count+mail_count+auc_count+guild_count == 0)
2348 SendSysMessage(LANG_COMMAND_NOITEMFOUND);
2349 SetSentErrorMessage(true);
2350 return false;
2353 PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE,item_id,inv_count+mail_count+auc_count+guild_count,inv_count,mail_count,auc_count,guild_count);
2355 return true;
2358 bool ChatHandler::HandleListObjectCommand(const char* args)
2360 if(!*args)
2361 return false;
2363 // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2364 char* cId = extractKeyFromLink((char*)args,"Hgameobject_entry");
2365 if(!cId)
2366 return false;
2368 uint32 go_id = atol(cId);
2369 if(!go_id)
2371 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, go_id);
2372 SetSentErrorMessage(true);
2373 return false;
2376 GameObjectInfo const * gInfo = objmgr.GetGameObjectInfo(go_id);
2377 if(!gInfo)
2379 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, go_id);
2380 SetSentErrorMessage(true);
2381 return false;
2384 char* c_count = strtok(NULL, " ");
2385 int count = c_count ? atol(c_count) : 10;
2387 if(count < 0)
2388 return false;
2390 QueryResult *result;
2392 uint32 obj_count = 0;
2393 result=WorldDatabase.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'",go_id);
2394 if(result)
2396 obj_count = (*result)[0].GetUInt32();
2397 delete result;
2400 if(m_session)
2402 Player* pl = m_session->GetPlayer();
2403 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",
2404 pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(),go_id,uint32(count));
2406 else
2407 result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map FROM gameobject WHERE id = '%u' LIMIT %u",
2408 go_id,uint32(count));
2410 if (result)
2414 Field *fields = result->Fetch();
2415 uint32 guid = fields[0].GetUInt32();
2416 float x = fields[1].GetFloat();
2417 float y = fields[2].GetFloat();
2418 float z = fields[3].GetFloat();
2419 int mapid = fields[4].GetUInt16();
2421 if (m_session)
2422 PSendSysMessage(LANG_GO_LIST_CHAT, guid, guid, gInfo->name, x, y, z, mapid);
2423 else
2424 PSendSysMessage(LANG_GO_LIST_CONSOLE, guid, gInfo->name, x, y, z, mapid);
2425 } while (result->NextRow());
2427 delete result;
2430 PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE,go_id,obj_count);
2431 return true;
2434 bool ChatHandler::HandleListCreatureCommand(const char* args)
2436 if(!*args)
2437 return false;
2439 // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
2440 char* cId = extractKeyFromLink((char*)args,"Hcreature_entry");
2441 if(!cId)
2442 return false;
2444 uint32 cr_id = atol(cId);
2445 if(!cr_id)
2447 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, cr_id);
2448 SetSentErrorMessage(true);
2449 return false;
2452 CreatureInfo const* cInfo = objmgr.GetCreatureTemplate(cr_id);
2453 if(!cInfo)
2455 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, cr_id);
2456 SetSentErrorMessage(true);
2457 return false;
2460 char* c_count = strtok(NULL, " ");
2461 int count = c_count ? atol(c_count) : 10;
2463 if(count < 0)
2464 return false;
2466 QueryResult *result;
2468 uint32 cr_count = 0;
2469 result=WorldDatabase.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'",cr_id);
2470 if(result)
2472 cr_count = (*result)[0].GetUInt32();
2473 delete result;
2476 if(m_session)
2478 Player* pl = m_session->GetPlayer();
2479 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",
2480 pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(), cr_id,uint32(count));
2482 else
2483 result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '%u' LIMIT %u",
2484 cr_id,uint32(count));
2486 if (result)
2490 Field *fields = result->Fetch();
2491 uint32 guid = fields[0].GetUInt32();
2492 float x = fields[1].GetFloat();
2493 float y = fields[2].GetFloat();
2494 float z = fields[3].GetFloat();
2495 int mapid = fields[4].GetUInt16();
2497 if (m_session)
2498 PSendSysMessage(LANG_CREATURE_LIST_CHAT, guid, guid, cInfo->Name, x, y, z, mapid);
2499 else
2500 PSendSysMessage(LANG_CREATURE_LIST_CONSOLE, guid, cInfo->Name, x, y, z, mapid);
2501 } while (result->NextRow());
2503 delete result;
2506 PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE,cr_id,cr_count);
2507 return true;
2510 bool ChatHandler::HandleLookupItemCommand(const char* args)
2512 if(!*args)
2513 return false;
2515 std::string namepart = args;
2516 std::wstring wnamepart;
2518 // converting string that we try to find to lower case
2519 if(!Utf8toWStr(namepart,wnamepart))
2520 return false;
2522 wstrToLower(wnamepart);
2524 uint32 counter = 0;
2526 // Search in `item_template`
2527 for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
2529 ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype >(id);
2530 if(!pProto)
2531 continue;
2533 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
2534 if ( loc_idx >= 0 )
2536 ItemLocale const *il = objmgr.GetItemLocale(pProto->ItemId);
2537 if (il)
2539 if (il->Name.size() > loc_idx && !il->Name[loc_idx].empty())
2541 std::string name = il->Name[loc_idx];
2543 if (Utf8FitTo(name, wnamepart))
2545 if (m_session)
2546 PSendSysMessage(LANG_ITEM_LIST_CHAT, id, id, name.c_str());
2547 else
2548 PSendSysMessage(LANG_ITEM_LIST_CONSOLE, id, name.c_str());
2549 ++counter;
2550 continue;
2556 std::string name = pProto->Name1;
2557 if(name.empty())
2558 continue;
2560 if (Utf8FitTo(name, wnamepart))
2562 if (m_session)
2563 PSendSysMessage(LANG_ITEM_LIST_CHAT, id, id, name.c_str());
2564 else
2565 PSendSysMessage(LANG_ITEM_LIST_CONSOLE, id, name.c_str());
2566 ++counter;
2570 if (counter==0)
2571 SendSysMessage(LANG_COMMAND_NOITEMFOUND);
2573 return true;
2576 bool ChatHandler::HandleLookupItemSetCommand(const char* args)
2578 if(!*args)
2579 return false;
2581 std::string namepart = args;
2582 std::wstring wnamepart;
2584 if(!Utf8toWStr(namepart,wnamepart))
2585 return false;
2587 // converting string that we try to find to lower case
2588 wstrToLower( wnamepart );
2590 uint32 counter = 0; // Counter for figure out that we found smth.
2592 // Search in ItemSet.dbc
2593 for (uint32 id = 0; id < sItemSetStore.GetNumRows(); id++)
2595 ItemSetEntry const *set = sItemSetStore.LookupEntry(id);
2596 if(set)
2598 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
2599 std::string name = set->name[loc];
2600 if(name.empty())
2601 continue;
2603 if (!Utf8FitTo(name, wnamepart))
2605 loc = 0;
2606 for(; loc < MAX_LOCALE; ++loc)
2608 if(m_session && loc==m_session->GetSessionDbcLocale())
2609 continue;
2611 name = set->name[loc];
2612 if(name.empty())
2613 continue;
2615 if (Utf8FitTo(name, wnamepart))
2616 break;
2620 if(loc < MAX_LOCALE)
2622 // send item set in "id - [namedlink locale]" format
2623 if (m_session)
2624 PSendSysMessage(LANG_ITEMSET_LIST_CHAT,id,id,name.c_str(),localeNames[loc]);
2625 else
2626 PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE,id,name.c_str(),localeNames[loc]);
2627 ++counter;
2631 if (counter == 0) // if counter == 0 then we found nth
2632 SendSysMessage(LANG_COMMAND_NOITEMSETFOUND);
2633 return true;
2636 bool ChatHandler::HandleLookupSkillCommand(const char* args)
2638 if(!*args)
2639 return false;
2641 // can be NULL in console call
2642 Player* target = getSelectedPlayer();
2644 std::string namepart = args;
2645 std::wstring wnamepart;
2647 if(!Utf8toWStr(namepart,wnamepart))
2648 return false;
2650 // converting string that we try to find to lower case
2651 wstrToLower( wnamepart );
2653 uint32 counter = 0; // Counter for figure out that we found smth.
2655 // Search in SkillLine.dbc
2656 for (uint32 id = 0; id < sSkillLineStore.GetNumRows(); id++)
2658 SkillLineEntry const *skillInfo = sSkillLineStore.LookupEntry(id);
2659 if(skillInfo)
2661 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
2662 std::string name = skillInfo->name[loc];
2663 if(name.empty())
2664 continue;
2666 if (!Utf8FitTo(name, wnamepart))
2668 loc = 0;
2669 for(; loc < MAX_LOCALE; ++loc)
2671 if(m_session && loc==m_session->GetSessionDbcLocale())
2672 continue;
2674 name = skillInfo->name[loc];
2675 if(name.empty())
2676 continue;
2678 if (Utf8FitTo(name, wnamepart))
2679 break;
2683 if(loc < MAX_LOCALE)
2685 char valStr[50] = "";
2686 char const* knownStr = "";
2687 if(target && target->HasSkill(id))
2689 knownStr = GetMangosString(LANG_KNOWN);
2690 uint32 curValue = target->GetPureSkillValue(id);
2691 uint32 maxValue = target->GetPureMaxSkillValue(id);
2692 uint32 permValue = target->GetSkillPermBonusValue(id);
2693 uint32 tempValue = target->GetSkillTempBonusValue(id);
2695 char const* valFormat = GetMangosString(LANG_SKILL_VALUES);
2696 snprintf(valStr,50,valFormat,curValue,maxValue,permValue,tempValue);
2699 // send skill in "id - [namedlink locale]" format
2700 if (m_session)
2701 PSendSysMessage(LANG_SKILL_LIST_CHAT,id,id,name.c_str(),localeNames[loc],knownStr,valStr);
2702 else
2703 PSendSysMessage(LANG_SKILL_LIST_CONSOLE,id,name.c_str(),localeNames[loc],knownStr,valStr);
2705 ++counter;
2709 if (counter == 0) // if counter == 0 then we found nth
2710 SendSysMessage(LANG_COMMAND_NOSKILLFOUND);
2711 return true;
2714 bool ChatHandler::HandleLookupSpellCommand(const char* args)
2716 if(!*args)
2717 return false;
2719 // can be NULL at console call
2720 Player* target = getSelectedPlayer();
2722 std::string namepart = args;
2723 std::wstring wnamepart;
2725 if(!Utf8toWStr(namepart,wnamepart))
2726 return false;
2728 // converting string that we try to find to lower case
2729 wstrToLower( wnamepart );
2731 uint32 counter = 0; // Counter for figure out that we found smth.
2733 // Search in Spell.dbc
2734 for (uint32 id = 0; id < sSpellStore.GetNumRows(); id++)
2736 SpellEntry const *spellInfo = sSpellStore.LookupEntry(id);
2737 if(spellInfo)
2739 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
2740 std::string name = spellInfo->SpellName[loc];
2741 if(name.empty())
2742 continue;
2744 if (!Utf8FitTo(name, wnamepart))
2746 loc = 0;
2747 for(; loc < MAX_LOCALE; ++loc)
2749 if(m_session && loc==m_session->GetSessionDbcLocale())
2750 continue;
2752 name = spellInfo->SpellName[loc];
2753 if(name.empty())
2754 continue;
2756 if (Utf8FitTo(name, wnamepart))
2757 break;
2761 if(loc < MAX_LOCALE)
2763 bool known = target && target->HasSpell(id);
2764 bool learn = (spellInfo->Effect[0] == SPELL_EFFECT_LEARN_SPELL);
2766 uint32 talentCost = GetTalentSpellCost(id);
2768 bool talent = (talentCost > 0);
2769 bool passive = IsPassiveSpell(id);
2770 bool active = target && target->HasAura(id);
2772 // unit32 used to prevent interpreting uint8 as char at output
2773 // find rank of learned spell for learning spell, or talent rank
2774 uint32 rank = talentCost ? talentCost : spellmgr.GetSpellRank(learn ? spellInfo->EffectTriggerSpell[0] : id);
2776 // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
2777 std::ostringstream ss;
2778 if (m_session)
2779 ss << id << " - |cffffffff|Hspell:" << id << "|h[" << name;
2780 else
2781 ss << id << " - " << name;
2783 // include rank in link name
2784 if(rank)
2785 ss << GetMangosString(LANG_SPELL_RANK) << rank;
2787 if (m_session)
2788 ss << " " << localeNames[loc] << "]|h|r";
2789 else
2790 ss << " " << localeNames[loc];
2792 if(talent)
2793 ss << GetMangosString(LANG_TALENT);
2794 if(passive)
2795 ss << GetMangosString(LANG_PASSIVE);
2796 if(learn)
2797 ss << GetMangosString(LANG_LEARN);
2798 if(known)
2799 ss << GetMangosString(LANG_KNOWN);
2800 if(active)
2801 ss << GetMangosString(LANG_ACTIVE);
2803 SendSysMessage(ss.str().c_str());
2805 ++counter;
2809 if (counter == 0) // if counter == 0 then we found nth
2810 SendSysMessage(LANG_COMMAND_NOSPELLFOUND);
2811 return true;
2814 bool ChatHandler::HandleLookupQuestCommand(const char* args)
2816 if(!*args)
2817 return false;
2819 // can be NULL at console call
2820 Player* target = getSelectedPlayer();
2822 std::string namepart = args;
2823 std::wstring wnamepart;
2825 // converting string that we try to find to lower case
2826 if(!Utf8toWStr(namepart,wnamepart))
2827 return false;
2829 wstrToLower(wnamepart);
2831 uint32 counter = 0 ;
2833 ObjectMgr::QuestMap const& qTemplates = objmgr.GetQuestTemplates();
2834 for (ObjectMgr::QuestMap::const_iterator iter = qTemplates.begin(); iter != qTemplates.end(); ++iter)
2836 Quest * qinfo = iter->second;
2838 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
2839 if ( loc_idx >= 0 )
2841 QuestLocale const *il = objmgr.GetQuestLocale(qinfo->GetQuestId());
2842 if (il)
2844 if (il->Title.size() > loc_idx && !il->Title[loc_idx].empty())
2846 std::string title = il->Title[loc_idx];
2848 if (Utf8FitTo(title, wnamepart))
2850 char const* statusStr = "";
2852 if(target)
2854 QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId());
2856 if(status == QUEST_STATUS_COMPLETE)
2858 if(target->GetQuestRewardStatus(qinfo->GetQuestId()))
2859 statusStr = GetMangosString(LANG_COMMAND_QUEST_REWARDED);
2860 else
2861 statusStr = GetMangosString(LANG_COMMAND_QUEST_COMPLETE);
2863 else if(status == QUEST_STATUS_INCOMPLETE)
2864 statusStr = GetMangosString(LANG_COMMAND_QUEST_ACTIVE);
2867 if (m_session)
2868 PSendSysMessage(LANG_QUEST_LIST_CHAT,qinfo->GetQuestId(),qinfo->GetQuestId(),title.c_str(),statusStr);
2869 else
2870 PSendSysMessage(LANG_QUEST_LIST_CONSOLE,qinfo->GetQuestId(),title.c_str(),statusStr);
2871 ++counter;
2872 continue;
2878 std::string title = qinfo->GetTitle();
2879 if(title.empty())
2880 continue;
2882 if (Utf8FitTo(title, wnamepart))
2884 char const* statusStr = "";
2886 if(target)
2888 QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId());
2890 if(status == QUEST_STATUS_COMPLETE)
2892 if(target->GetQuestRewardStatus(qinfo->GetQuestId()))
2893 statusStr = GetMangosString(LANG_COMMAND_QUEST_REWARDED);
2894 else
2895 statusStr = GetMangosString(LANG_COMMAND_QUEST_COMPLETE);
2897 else if(status == QUEST_STATUS_INCOMPLETE)
2898 statusStr = GetMangosString(LANG_COMMAND_QUEST_ACTIVE);
2901 if (m_session)
2902 PSendSysMessage(LANG_QUEST_LIST_CHAT,qinfo->GetQuestId(),qinfo->GetQuestId(),title.c_str(),statusStr);
2903 else
2904 PSendSysMessage(LANG_QUEST_LIST_CONSOLE,qinfo->GetQuestId(),title.c_str(),statusStr);
2906 ++counter;
2910 if (counter==0)
2911 SendSysMessage(LANG_COMMAND_NOQUESTFOUND);
2913 return true;
2916 bool ChatHandler::HandleLookupCreatureCommand(const char* args)
2918 if (!*args)
2919 return false;
2921 std::string namepart = args;
2922 std::wstring wnamepart;
2924 // converting string that we try to find to lower case
2925 if (!Utf8toWStr (namepart,wnamepart))
2926 return false;
2928 wstrToLower (wnamepart);
2930 uint32 counter = 0;
2932 for (uint32 id = 0; id< sCreatureStorage.MaxEntry; ++id)
2934 CreatureInfo const* cInfo = sCreatureStorage.LookupEntry<CreatureInfo> (id);
2935 if(!cInfo)
2936 continue;
2938 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
2939 if (loc_idx >= 0)
2941 CreatureLocale const *cl = objmgr.GetCreatureLocale (id);
2942 if (cl)
2944 if (cl->Name.size() > loc_idx && !cl->Name[loc_idx].empty ())
2946 std::string name = cl->Name[loc_idx];
2948 if (Utf8FitTo (name, wnamepart))
2950 if (m_session)
2951 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str ());
2952 else
2953 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE, id, name.c_str ());
2954 ++counter;
2955 continue;
2961 std::string name = cInfo->Name;
2962 if (name.empty ())
2963 continue;
2965 if (Utf8FitTo(name, wnamepart))
2967 if (m_session)
2968 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str ());
2969 else
2970 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE, id, name.c_str ());
2971 ++counter;
2975 if (counter==0)
2976 SendSysMessage (LANG_COMMAND_NOCREATUREFOUND);
2978 return true;
2981 bool ChatHandler::HandleLookupObjectCommand(const char* args)
2983 if(!*args)
2984 return false;
2986 std::string namepart = args;
2987 std::wstring wnamepart;
2989 // converting string that we try to find to lower case
2990 if(!Utf8toWStr(namepart,wnamepart))
2991 return false;
2993 wstrToLower(wnamepart);
2995 uint32 counter = 0;
2997 for (uint32 id = 0; id< sGOStorage.MaxEntry; id++ )
2999 GameObjectInfo const* gInfo = sGOStorage.LookupEntry<GameObjectInfo>(id);
3000 if(!gInfo)
3001 continue;
3003 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
3004 if ( loc_idx >= 0 )
3006 GameObjectLocale const *gl = objmgr.GetGameObjectLocale(id);
3007 if (gl)
3009 if (gl->Name.size() > loc_idx && !gl->Name[loc_idx].empty())
3011 std::string name = gl->Name[loc_idx];
3013 if (Utf8FitTo(name, wnamepart))
3015 if (m_session)
3016 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, id, id, name.c_str());
3017 else
3018 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, id, name.c_str());
3019 ++counter;
3020 continue;
3026 std::string name = gInfo->name;
3027 if(name.empty())
3028 continue;
3030 if(Utf8FitTo(name, wnamepart))
3032 if (m_session)
3033 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, id, id, name.c_str());
3034 else
3035 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, id, name.c_str());
3036 ++counter;
3040 if(counter==0)
3041 SendSysMessage(LANG_COMMAND_NOGAMEOBJECTFOUND);
3043 return true;
3046 /** \brief GM command level 3 - Create a guild.
3048 * This command allows a GM (level 3) to create a guild.
3050 * The "args" parameter contains the name of the guild leader
3051 * and then the name of the guild.
3054 bool ChatHandler::HandleGuildCreateCommand(const char* args)
3057 if (!*args)
3058 return false;
3060 char *lname = strtok ((char*)args, " ");
3061 char *gname = strtok (NULL, "");
3063 if (!lname)
3064 return false;
3066 if (!gname)
3068 SendSysMessage (LANG_INSERT_GUILD_NAME);
3069 SetSentErrorMessage (true);
3070 return false;
3073 std::string guildname = gname;
3075 Player* player = ObjectAccessor::Instance ().FindPlayerByName (lname);
3076 if (!player)
3078 SendSysMessage (LANG_PLAYER_NOT_FOUND);
3079 SetSentErrorMessage (true);
3080 return false;
3083 if (player->GetGuildId())
3085 SendSysMessage (LANG_PLAYER_IN_GUILD);
3086 return true;
3089 Guild *guild = new Guild;
3090 if (!guild->create (player,guildname))
3092 delete guild;
3093 SendSysMessage (LANG_GUILD_NOT_CREATED);
3094 SetSentErrorMessage (true);
3095 return false;
3098 objmgr.AddGuild (guild);
3099 return true;
3102 bool ChatHandler::HandleGuildInviteCommand(const char *args)
3104 if (!*args)
3105 return false;
3107 char* par1 = strtok ((char*)args, " ");
3108 char* par2 = strtok (NULL, "");
3109 if(!par1 || !par2)
3110 return false;
3112 std::string glName = par2;
3113 Guild* targetGuild = objmgr.GetGuildByName (glName);
3114 if (!targetGuild)
3115 return false;
3117 std::string plName = extractPlayerNameFromLink(par1);
3118 if(plName.empty())
3120 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3121 SetSentErrorMessage(true);
3122 return false;
3125 uint64 plGuid = 0;
3126 if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3127 plGuid = targetPlayer->GetGUID ();
3128 else
3129 plGuid = objmgr.GetPlayerGUIDByName (plName);
3131 if (!plGuid)
3132 return false;
3134 // player's guild membership checked in AddMember before add
3135 if (!targetGuild->AddMember (plGuid,targetGuild->GetLowestRank ()))
3136 return false;
3138 return true;
3141 bool ChatHandler::HandleGuildUninviteCommand(const char *args)
3143 if (!*args)
3144 return false;
3146 char* par1 = strtok ((char*)args, " ");
3147 if(!par1)
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 uint32 glId = 0;
3160 if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3162 plGuid = targetPlayer->GetGUID ();
3163 glId = targetPlayer->GetGuildId ();
3165 else
3167 plGuid = objmgr.GetPlayerGUIDByName (plName);
3168 glId = Player::GetGuildIdFromDB (plGuid);
3171 if (!plGuid || !glId)
3172 return false;
3174 Guild* targetGuild = objmgr.GetGuildById (glId);
3175 if (!targetGuild)
3176 return false;
3178 targetGuild->DelMember (plGuid);
3180 return true;
3183 bool ChatHandler::HandleGuildRankCommand(const char *args)
3185 if (!*args)
3186 return false;
3188 char* par1 = strtok ((char*)args, " ");
3189 char* par2 = strtok (NULL, " ");
3190 if (!par1 || !par2)
3191 return false;
3193 std::string plName = extractPlayerNameFromLink(par1);
3194 if(plName.empty())
3196 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3197 SetSentErrorMessage(true);
3198 return false;
3202 uint64 plGuid = 0;
3203 uint32 glId = 0;
3204 if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3206 plGuid = targetPlayer->GetGUID ();
3207 glId = targetPlayer->GetGuildId ();
3209 else
3211 plGuid = objmgr.GetPlayerGUIDByName (plName);
3212 glId = Player::GetGuildIdFromDB (plGuid);
3215 if (!plGuid || !glId)
3216 return false;
3218 Guild* targetGuild = objmgr.GetGuildById (glId);
3219 if (!targetGuild)
3220 return false;
3222 uint32 newrank = uint32 (atoi (par2));
3223 if (newrank > targetGuild->GetLowestRank ())
3224 return false;
3226 targetGuild->ChangeRank (plGuid,newrank);
3228 return true;
3231 bool ChatHandler::HandleGuildDeleteCommand(const char* args)
3233 if (!*args)
3234 return false;
3236 char* par1 = strtok ((char*)args, " ");
3237 if (!par1)
3238 return false;
3240 std::string gld = par1;
3242 Guild* targetGuild = objmgr.GetGuildByName (gld);
3243 if (!targetGuild)
3244 return false;
3246 targetGuild->Disband ();
3248 return true;
3251 bool ChatHandler::HandleGetDistanceCommand(const char* args)
3253 WorldObject* obj = NULL;
3255 if (*args)
3257 uint64 guid = extractGuidFromLink((char*)args);
3258 if(guid)
3259 obj = (WorldObject*)ObjectAccessor::GetObjectByTypeMask(*m_session->GetPlayer(),guid,TYPEMASK_UNIT|TYPEMASK_GAMEOBJECT);
3261 if(!obj)
3263 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3264 SetSentErrorMessage(true);
3265 return false;
3268 else
3270 obj = getSelectedUnit();
3272 if(!obj)
3274 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3275 SetSentErrorMessage(true);
3276 return false;
3280 PSendSysMessage(LANG_DISTANCE, m_session->GetPlayer()->GetDistance(obj),m_session->GetPlayer()->GetDistance2d(obj));
3282 return true;
3285 bool ChatHandler::HandleDieCommand(const char* /*args*/)
3287 Unit* target = getSelectedUnit();
3289 if(!target || !m_session->GetPlayer()->GetSelection())
3291 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3292 SetSentErrorMessage(true);
3293 return false;
3296 if(target->GetTypeId()==TYPEID_PLAYER)
3298 if(HasLowerSecurity((Player*)target,0,false))
3299 return false;
3302 if( target->isAlive() )
3304 m_session->GetPlayer()->DealDamage(target, target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
3307 return true;
3310 bool ChatHandler::HandleDamageCommand(const char * args)
3312 if (!*args)
3313 return false;
3315 Unit* target = getSelectedUnit();
3317 if(!target || !m_session->GetPlayer()->GetSelection())
3319 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3320 SetSentErrorMessage(true);
3321 return false;
3324 if( !target->isAlive() )
3325 return true;
3327 char* damageStr = strtok((char*)args, " ");
3328 if(!damageStr)
3329 return false;
3331 int32 damage = atoi((char*)damageStr);
3332 if(damage <=0)
3333 return true;
3335 char* schoolStr = strtok((char*)NULL, " ");
3337 // flat melee damage without resistence/etc reduction
3338 if(!schoolStr)
3340 m_session->GetPlayer()->DealDamage(target, damage, NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
3341 m_session->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2, target, 1, SPELL_SCHOOL_MASK_NORMAL, damage, 0, 0, VICTIMSTATE_NORMAL, 0);
3342 return true;
3345 uint32 school = schoolStr ? atoi((char*)schoolStr) : SPELL_SCHOOL_NORMAL;
3346 if(school >= MAX_SPELL_SCHOOL)
3347 return false;
3349 SpellSchoolMask schoolmask = SpellSchoolMask(1 << school);
3351 if ( schoolmask & SPELL_SCHOOL_MASK_NORMAL )
3352 damage = m_session->GetPlayer()->CalcArmorReducedDamage(target, damage);
3354 char* spellStr = strtok((char*)NULL, " ");
3356 // melee damage by specific school
3357 if(!spellStr)
3359 uint32 absorb = 0;
3360 uint32 resist = 0;
3362 m_session->GetPlayer()->CalcAbsorbResist(target,schoolmask, SPELL_DIRECT_DAMAGE, damage, &absorb, &resist);
3364 if (damage <= absorb + resist)
3365 return true;
3367 damage -= absorb + resist;
3369 m_session->GetPlayer()->DealDamage(target, damage, NULL, DIRECT_DAMAGE, schoolmask, NULL, false);
3370 m_session->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2, target, 1, schoolmask, damage, absorb, resist, VICTIMSTATE_NORMAL, 0);
3371 return true;
3374 // non-melee damage
3376 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3377 uint32 spellid = extractSpellIdFromLink((char*)args);
3378 if(!spellid || !sSpellStore.LookupEntry(spellid))
3379 return false;
3381 m_session->GetPlayer()->SpellNonMeleeDamageLog(target, spellid, damage, false);
3382 return true;
3385 bool ChatHandler::HandleModifyArenaCommand(const char * args)
3387 if (!*args)
3388 return false;
3390 Player *target = getSelectedPlayer();
3391 if(!target)
3393 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3394 SetSentErrorMessage(true);
3395 return false;
3398 int32 amount = (uint32)atoi(args);
3400 target->ModifyArenaPoints(amount);
3402 PSendSysMessage(LANG_COMMAND_MODIFY_ARENA, GetNameLink(target).c_str(), target->GetArenaPoints());
3404 return true;
3407 bool ChatHandler::HandleReviveCommand(const char* args)
3409 Player* SelectedPlayer = NULL;
3411 if (*args)
3413 std::string name = extractPlayerNameFromLink((char*)args);
3414 if(name.empty())
3416 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3417 SetSentErrorMessage(true);
3418 return false;
3421 SelectedPlayer = objmgr.GetPlayer(name.c_str());
3423 else
3424 SelectedPlayer = getSelectedPlayer();
3426 if(!SelectedPlayer)
3428 SendSysMessage(LANG_NO_CHAR_SELECTED);
3429 SetSentErrorMessage(true);
3430 return false;
3433 SelectedPlayer->ResurrectPlayer(0.5f);
3434 SelectedPlayer->SpawnCorpseBones();
3435 SelectedPlayer->SaveToDB();
3436 return true;
3439 bool ChatHandler::HandleAuraCommand(const char* args)
3441 Unit *target = getSelectedUnit();
3442 if(!target)
3444 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3445 SetSentErrorMessage(true);
3446 return false;
3449 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3450 uint32 spellID = extractSpellIdFromLink((char*)args);
3452 SpellEntry const *spellInfo = sSpellStore.LookupEntry( spellID );
3453 if(spellInfo)
3455 for(uint32 i = 0;i<3;i++)
3457 uint8 eff = spellInfo->Effect[i];
3458 if (eff>=TOTAL_SPELL_EFFECTS)
3459 continue;
3460 if( IsAreaAuraEffect(eff) ||
3461 eff == SPELL_EFFECT_APPLY_AURA ||
3462 eff == SPELL_EFFECT_PERSISTENT_AREA_AURA )
3464 Aura *Aur = CreateAura(spellInfo, i, NULL, target);
3465 target->AddAura(Aur);
3470 return true;
3473 bool ChatHandler::HandleUnAuraCommand(const char* args)
3475 Unit *target = getSelectedUnit();
3476 if(!target)
3478 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3479 SetSentErrorMessage(true);
3480 return false;
3483 std::string argstr = args;
3484 if (argstr == "all")
3486 target->RemoveAllAuras();
3487 return true;
3490 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3491 uint32 spellID = extractSpellIdFromLink((char*)args);
3492 if(!spellID)
3493 return false;
3495 target->RemoveAurasDueToSpell(spellID);
3497 return true;
3500 bool ChatHandler::HandleLinkGraveCommand(const char* args)
3502 if(!*args)
3503 return false;
3505 char* px = strtok((char*)args, " ");
3506 if (!px)
3507 return false;
3509 uint32 g_id = (uint32)atoi(px);
3511 uint32 g_team;
3513 char* px2 = strtok(NULL, " ");
3515 if (!px2)
3516 g_team = 0;
3517 else if (strncmp(px2,"horde",6)==0)
3518 g_team = HORDE;
3519 else if (strncmp(px2,"alliance",9)==0)
3520 g_team = ALLIANCE;
3521 else
3522 return false;
3524 WorldSafeLocsEntry const* graveyard = sWorldSafeLocsStore.LookupEntry(g_id);
3526 if(!graveyard )
3528 PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST, g_id);
3529 SetSentErrorMessage(true);
3530 return false;
3533 Player* player = m_session->GetPlayer();
3535 uint32 zoneId = player->GetZoneId();
3537 AreaTableEntry const *areaEntry = GetAreaEntryByAreaID(zoneId);
3538 if(!areaEntry || areaEntry->zone !=0 )
3540 PSendSysMessage(LANG_COMMAND_GRAVEYARDWRONGZONE, g_id,zoneId);
3541 SetSentErrorMessage(true);
3542 return false;
3545 if(objmgr.AddGraveYardLink(g_id,zoneId,g_team))
3546 PSendSysMessage(LANG_COMMAND_GRAVEYARDLINKED, g_id,zoneId);
3547 else
3548 PSendSysMessage(LANG_COMMAND_GRAVEYARDALRLINKED, g_id,zoneId);
3550 return true;
3553 bool ChatHandler::HandleNearGraveCommand(const char* args)
3555 uint32 g_team;
3557 size_t argslen = strlen(args);
3559 if(!*args)
3560 g_team = 0;
3561 else if (strncmp((char*)args,"horde",argslen)==0)
3562 g_team = HORDE;
3563 else if (strncmp((char*)args,"alliance",argslen)==0)
3564 g_team = ALLIANCE;
3565 else
3566 return false;
3568 Player* player = m_session->GetPlayer();
3569 uint32 zone_id = player->GetZoneId();
3571 WorldSafeLocsEntry const* graveyard = objmgr.GetClosestGraveYard(
3572 player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(),player->GetMapId(),g_team);
3574 if(graveyard)
3576 uint32 g_id = graveyard->ID;
3578 GraveYardData const* data = objmgr.FindGraveYardData(g_id,zone_id);
3579 if (!data)
3581 PSendSysMessage(LANG_COMMAND_GRAVEYARDERROR,g_id);
3582 SetSentErrorMessage(true);
3583 return false;
3586 g_team = data->team;
3588 std::string team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_NOTEAM);
3590 if(g_team == 0)
3591 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ANY);
3592 else if(g_team == HORDE)
3593 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE);
3594 else if(g_team == ALLIANCE)
3595 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE);
3597 PSendSysMessage(LANG_COMMAND_GRAVEYARDNEAREST, g_id,team_name.c_str(),zone_id);
3599 else
3601 std::string team_name;
3603 if(g_team == 0)
3604 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ANY);
3605 else if(g_team == HORDE)
3606 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE);
3607 else if(g_team == ALLIANCE)
3608 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE);
3610 if(g_team == ~uint32(0))
3611 PSendSysMessage(LANG_COMMAND_ZONENOGRAVEYARDS, zone_id);
3612 else
3613 PSendSysMessage(LANG_COMMAND_ZONENOGRAFACTION, zone_id,team_name.c_str());
3616 return true;
3619 //-----------------------Npc Commands-----------------------
3620 bool ChatHandler::HandleNpcAllowMovementCommand(const char* /*args*/)
3622 if(sWorld.getAllowMovement())
3624 sWorld.SetAllowMovement(false);
3625 SendSysMessage(LANG_CREATURE_MOVE_DISABLED);
3627 else
3629 sWorld.SetAllowMovement(true);
3630 SendSysMessage(LANG_CREATURE_MOVE_ENABLED);
3632 return true;
3635 bool ChatHandler::HandleNpcChangeEntryCommand(const char *args)
3637 if (!*args)
3638 return false;
3640 uint32 newEntryNum = atoi(args);
3641 if(!newEntryNum)
3642 return false;
3644 Unit* unit = getSelectedUnit();
3645 if(!unit || unit->GetTypeId() != TYPEID_UNIT)
3647 SendSysMessage(LANG_SELECT_CREATURE);
3648 SetSentErrorMessage(true);
3649 return false;
3651 Creature* creature = (Creature*)unit;
3652 if(creature->UpdateEntry(newEntryNum))
3653 SendSysMessage(LANG_DONE);
3654 else
3655 SendSysMessage(LANG_ERROR);
3656 return true;
3659 bool ChatHandler::HandleNpcInfoCommand(const char* /*args*/)
3661 Creature* target = getSelectedCreature();
3663 if(!target)
3665 SendSysMessage(LANG_SELECT_CREATURE);
3666 SetSentErrorMessage(true);
3667 return false;
3670 uint32 faction = target->getFaction();
3671 uint32 npcflags = target->GetUInt32Value(UNIT_NPC_FLAGS);
3672 uint32 displayid = target->GetDisplayId();
3673 uint32 nativeid = target->GetNativeDisplayId();
3674 uint32 Entry = target->GetEntry();
3675 CreatureInfo const* cInfo = target->GetCreatureInfo();
3677 int32 curRespawnDelay = target->GetRespawnTimeEx()-time(NULL);
3678 if(curRespawnDelay < 0)
3679 curRespawnDelay = 0;
3680 std::string curRespawnDelayStr = secsToTimeString(curRespawnDelay,true);
3681 std::string defRespawnDelayStr = secsToTimeString(target->GetRespawnDelay(),true);
3683 PSendSysMessage(LANG_NPCINFO_CHAR, target->GetDBTableGUIDLow(), faction, npcflags, Entry, displayid, nativeid);
3684 PSendSysMessage(LANG_NPCINFO_LEVEL, target->getLevel());
3685 PSendSysMessage(LANG_NPCINFO_HEALTH,target->GetCreateHealth(), target->GetMaxHealth(), target->GetHealth());
3686 PSendSysMessage(LANG_NPCINFO_FLAGS, target->GetUInt32Value(UNIT_FIELD_FLAGS), target->GetUInt32Value(UNIT_DYNAMIC_FLAGS), target->getFaction());
3687 PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES, defRespawnDelayStr.c_str(),curRespawnDelayStr.c_str());
3688 PSendSysMessage(LANG_NPCINFO_LOOT, cInfo->lootid,cInfo->pickpocketLootId,cInfo->SkinLootId);
3689 PSendSysMessage(LANG_NPCINFO_DUNGEON_ID, target->GetInstanceId());
3690 PSendSysMessage(LANG_NPCINFO_POSITION,float(target->GetPositionX()), float(target->GetPositionY()), float(target->GetPositionZ()));
3692 if ((npcflags & UNIT_NPC_FLAG_VENDOR) )
3694 SendSysMessage(LANG_NPCINFO_VENDOR);
3696 if ((npcflags & UNIT_NPC_FLAG_TRAINER) )
3698 SendSysMessage(LANG_NPCINFO_TRAINER);
3701 return true;
3704 //play npc emote
3705 bool ChatHandler::HandleNpcPlayEmoteCommand(const char* args)
3707 uint32 emote = atoi((char*)args);
3709 Creature* target = getSelectedCreature();
3710 if(!target)
3712 SendSysMessage(LANG_SELECT_CREATURE);
3713 SetSentErrorMessage(true);
3714 return false;
3717 target->SetUInt32Value(UNIT_NPC_EMOTESTATE,emote);
3719 return true;
3722 //TODO: NpcCommands that needs to be fixed :
3724 bool ChatHandler::HandleNpcAddWeaponCommand(const char* /*args*/)
3726 /*if (!*args)
3727 return false;
3729 uint64 guid = m_session->GetPlayer()->GetSelection();
3730 if (guid == 0)
3732 SendSysMessage(LANG_NO_SELECTION);
3733 return true;
3736 Creature *pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
3738 if(!pCreature)
3740 SendSysMessage(LANG_SELECT_CREATURE);
3741 return true;
3744 char* pSlotID = strtok((char*)args, " ");
3745 if (!pSlotID)
3746 return false;
3748 char* pItemID = strtok(NULL, " ");
3749 if (!pItemID)
3750 return false;
3752 uint32 ItemID = atoi(pItemID);
3753 uint32 SlotID = atoi(pSlotID);
3755 ItemPrototype* tmpItem = objmgr.GetItemPrototype(ItemID);
3757 bool added = false;
3758 if(tmpItem)
3760 switch(SlotID)
3762 case 1:
3763 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID);
3764 added = true;
3765 break;
3766 case 2:
3767 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID);
3768 added = true;
3769 break;
3770 case 3:
3771 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID);
3772 added = true;
3773 break;
3774 default:
3775 PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST,SlotID);
3776 added = false;
3777 break;
3780 if(added)
3781 PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT,ItemID,tmpItem->Name1,SlotID);
3783 else
3785 PSendSysMessage(LANG_ITEM_NOT_FOUND,ItemID);
3786 return true;
3789 return true;
3791 //----------------------------------------------------------
3793 bool ChatHandler::HandleExploreCheatCommand(const char* args)
3795 if (!*args)
3796 return false;
3798 int flag = atoi((char*)args);
3800 Player *chr = getSelectedPlayer();
3801 if (chr == NULL)
3803 SendSysMessage(LANG_NO_CHAR_SELECTED);
3804 SetSentErrorMessage(true);
3805 return false;
3808 if (flag != 0)
3810 PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL, GetNameLink(chr).c_str());
3811 if (needReportToTarget(chr))
3812 ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_ALL,GetNameLink().c_str());
3814 else
3816 PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING, GetNameLink(chr).c_str());
3817 if (needReportToTarget(chr))
3818 ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_NOTHING,GetNameLink().c_str());
3821 for (uint8 i=0; i<128; i++)
3823 if (flag != 0)
3825 m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1+i,0xFFFFFFFF);
3827 else
3829 m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1+i,0);
3833 return true;
3836 bool ChatHandler::HandleHoverCommand(const char* args)
3838 char* px = strtok((char*)args, " ");
3839 uint32 flag;
3840 if (!px)
3841 flag = 1;
3842 else
3843 flag = atoi(px);
3845 m_session->GetPlayer()->SetHover(flag);
3847 if (flag)
3848 SendSysMessage(LANG_HOVER_ENABLED);
3849 else
3850 SendSysMessage(LANG_HOVER_DISABLED);
3852 return true;
3855 bool ChatHandler::HandleLevelUpCommand(const char* args)
3857 char* px = strtok((char*)args, " ");
3858 char* py = strtok((char*)NULL, " ");
3860 // command format parsing
3861 char* pname = (char*)NULL;
3862 int addlevel = 1;
3864 if(px && py) // .levelup name level
3866 addlevel = atoi(py);
3867 pname = px;
3869 else if(px && !py) // .levelup name OR .levelup level
3871 if(isalpha(px[0])) // .levelup name
3872 pname = px;
3873 else // .levelup level
3874 addlevel = atoi(px);
3876 // else .levelup - nothing do for preparing
3878 // player
3879 Player *chr = NULL;
3880 uint64 chr_guid = 0;
3882 std::string name;
3884 if(pname) // player by name
3886 name = extractPlayerNameFromLink(pname);
3887 if(name.empty())
3889 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3890 SetSentErrorMessage(true);
3891 return false;
3894 chr = objmgr.GetPlayer(name.c_str());
3895 if(!chr) // not in game
3897 chr_guid = objmgr.GetPlayerGUIDByName(name);
3898 if (chr_guid == 0)
3900 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3901 SetSentErrorMessage(true);
3902 return false;
3906 else // player by selection
3908 chr = getSelectedPlayer();
3910 if (chr == NULL)
3912 SendSysMessage(LANG_NO_CHAR_SELECTED);
3913 SetSentErrorMessage(true);
3914 return false;
3917 name = chr->GetName();
3920 assert(chr || chr_guid);
3922 int32 oldlevel = chr ? chr->getLevel() : Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL,chr_guid);
3923 int32 newlevel = oldlevel + addlevel;
3924 if(newlevel < 1)
3925 newlevel = 1;
3926 if(newlevel > STRONG_MAX_LEVEL) // hardcoded maximum level
3927 newlevel = STRONG_MAX_LEVEL;
3929 if(chr)
3931 chr->GiveLevel(newlevel);
3932 chr->InitTalentForLevel();
3933 chr->SetUInt32Value(PLAYER_XP,0);
3935 if(oldlevel == newlevel)
3936 ChatHandler(chr).SendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET);
3937 else
3938 if(oldlevel < newlevel)
3939 ChatHandler(chr).PSendSysMessage(LANG_YOURS_LEVEL_UP,newlevel-oldlevel);
3940 else
3941 if(oldlevel > newlevel)
3942 ChatHandler(chr).PSendSysMessage(LANG_YOURS_LEVEL_DOWN,newlevel-oldlevel);
3944 else
3946 // update level and XP at level, all other will be updated at loading
3947 Tokens values;
3948 Player::LoadValuesArrayFromDB(values,chr_guid);
3949 Player::SetUInt32ValueInArray(values,UNIT_FIELD_LEVEL,newlevel);
3950 Player::SetUInt32ValueInArray(values,PLAYER_XP,0);
3951 Player::SaveValuesArrayInDB(values,chr_guid);
3954 if(m_session->GetPlayer() != chr) // including chr==NULL
3956 std::string nameLink = playerLink(name);
3957 PSendSysMessage(LANG_YOU_CHANGE_LVL,nameLink.c_str(),newlevel);
3959 return true;
3962 bool ChatHandler::HandleShowAreaCommand(const char* args)
3964 if (!*args)
3965 return false;
3967 Player *chr = getSelectedPlayer();
3968 if (chr == NULL)
3970 SendSysMessage(LANG_NO_CHAR_SELECTED);
3971 SetSentErrorMessage(true);
3972 return false;
3975 int area = GetAreaFlagByAreaID(atoi((char*)args));
3976 int offset = area / 32;
3977 uint32 val = (uint32)(1 << (area % 32));
3979 if(area<0 || offset >= 128)
3981 SendSysMessage(LANG_BAD_VALUE);
3982 SetSentErrorMessage(true);
3983 return false;
3986 uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
3987 chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields | val));
3989 SendSysMessage(LANG_EXPLORE_AREA);
3990 return true;
3993 bool ChatHandler::HandleHideAreaCommand(const char* args)
3995 if (!*args)
3996 return false;
3998 Player *chr = getSelectedPlayer();
3999 if (chr == NULL)
4001 SendSysMessage(LANG_NO_CHAR_SELECTED);
4002 SetSentErrorMessage(true);
4003 return false;
4006 int area = GetAreaFlagByAreaID(atoi((char*)args));
4007 int offset = area / 32;
4008 uint32 val = (uint32)(1 << (area % 32));
4010 if(area<0 || offset >= 128)
4012 SendSysMessage(LANG_BAD_VALUE);
4013 SetSentErrorMessage(true);
4014 return false;
4017 uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
4018 chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields ^ val));
4020 SendSysMessage(LANG_UNEXPLORE_AREA);
4021 return true;
4024 bool ChatHandler::HandleDebugUpdate(const char* args)
4026 if(!*args)
4027 return false;
4029 uint32 updateIndex;
4030 uint32 value;
4032 char* pUpdateIndex = strtok((char*)args, " ");
4034 Unit* chr = getSelectedUnit();
4035 if (chr == NULL)
4037 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4038 SetSentErrorMessage(true);
4039 return false;
4042 if(!pUpdateIndex)
4044 return true;
4046 updateIndex = atoi(pUpdateIndex);
4047 //check updateIndex
4048 if(chr->GetTypeId() == TYPEID_PLAYER)
4050 if (updateIndex>=PLAYER_END) return true;
4052 else
4054 if (updateIndex>=UNIT_END) return true;
4057 char* pvalue = strtok(NULL, " ");
4058 if (!pvalue)
4060 value=chr->GetUInt32Value(updateIndex);
4062 PSendSysMessage(LANG_UPDATE, chr->GetGUIDLow(),updateIndex,value);
4063 return true;
4066 value=atoi(pvalue);
4068 PSendSysMessage(LANG_UPDATE_CHANGE, chr->GetGUIDLow(),updateIndex,value);
4070 chr->SetUInt32Value(updateIndex,value);
4072 return true;
4075 bool ChatHandler::HandleBankCommand(const char* /*args*/)
4077 m_session->SendShowBank( m_session->GetPlayer()->GetGUID() );
4079 return true;
4082 bool ChatHandler::HandleChangeWeather(const char* args)
4084 if(!*args)
4085 return false;
4087 //Weather is OFF
4088 if (!sWorld.getConfig(CONFIG_WEATHER))
4090 SendSysMessage(LANG_WEATHER_DISABLED);
4091 SetSentErrorMessage(true);
4092 return false;
4095 //*Change the weather of a cell
4096 char* px = strtok((char*)args, " ");
4097 char* py = strtok(NULL, " ");
4099 if (!px || !py)
4100 return false;
4102 uint32 type = (uint32)atoi(px); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
4103 float grade = (float)atof(py); //0 to 1, sending -1 is instand good weather
4105 Player *player = m_session->GetPlayer();
4106 uint32 zoneid = player->GetZoneId();
4108 Weather* wth = sWorld.FindWeather(zoneid);
4110 if(!wth)
4111 wth = sWorld.AddWeather(zoneid);
4112 if(!wth)
4114 SendSysMessage(LANG_NO_WEATHER);
4115 SetSentErrorMessage(true);
4116 return false;
4119 wth->SetWeather(WeatherType(type), grade);
4121 return true;
4124 bool ChatHandler::HandleDebugSetValue(const char* args)
4126 if(!*args)
4127 return false;
4129 char* px = strtok((char*)args, " ");
4130 char* py = strtok(NULL, " ");
4131 char* pz = strtok(NULL, " ");
4133 if (!px || !py)
4134 return false;
4136 Unit* target = getSelectedUnit();
4137 if(!target)
4139 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4140 SetSentErrorMessage(true);
4141 return false;
4144 uint64 guid = target->GetGUID();
4146 uint32 Opcode = (uint32)atoi(px);
4147 if(Opcode >= target->GetValuesCount())
4149 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, GUID_LOPART(guid), target->GetValuesCount());
4150 return false;
4152 uint32 iValue;
4153 float fValue;
4154 bool isint32 = true;
4155 if(pz)
4156 isint32 = (bool)atoi(pz);
4157 if(isint32)
4159 iValue = (uint32)atoi(py);
4160 sLog.outDebug(GetMangosString(LANG_SET_UINT), GUID_LOPART(guid), Opcode, iValue);
4161 target->SetUInt32Value( Opcode , iValue );
4162 PSendSysMessage(LANG_SET_UINT_FIELD, GUID_LOPART(guid), Opcode,iValue);
4164 else
4166 fValue = (float)atof(py);
4167 sLog.outDebug(GetMangosString(LANG_SET_FLOAT), GUID_LOPART(guid), Opcode, fValue);
4168 target->SetFloatValue( Opcode , fValue );
4169 PSendSysMessage(LANG_SET_FLOAT_FIELD, GUID_LOPART(guid), Opcode,fValue);
4172 return true;
4175 bool ChatHandler::HandleDebugGetValue(const char* args)
4177 if(!*args)
4178 return false;
4180 char* px = strtok((char*)args, " ");
4181 char* pz = strtok(NULL, " ");
4183 if (!px)
4184 return false;
4186 Unit* target = getSelectedUnit();
4187 if(!target)
4189 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4190 SetSentErrorMessage(true);
4191 return false;
4194 uint64 guid = target->GetGUID();
4196 uint32 Opcode = (uint32)atoi(px);
4197 if(Opcode >= target->GetValuesCount())
4199 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, GUID_LOPART(guid), target->GetValuesCount());
4200 return false;
4202 uint32 iValue;
4203 float fValue;
4204 bool isint32 = true;
4205 if(pz)
4206 isint32 = (bool)atoi(pz);
4208 if(isint32)
4210 iValue = target->GetUInt32Value( Opcode );
4211 sLog.outDebug(GetMangosString(LANG_GET_UINT), GUID_LOPART(guid), Opcode, iValue);
4212 PSendSysMessage(LANG_GET_UINT_FIELD, GUID_LOPART(guid), Opcode, iValue);
4214 else
4216 fValue = target->GetFloatValue( Opcode );
4217 sLog.outDebug(GetMangosString(LANG_GET_FLOAT), GUID_LOPART(guid), Opcode, fValue);
4218 PSendSysMessage(LANG_GET_FLOAT_FIELD, GUID_LOPART(guid), Opcode, fValue);
4221 return true;
4224 bool ChatHandler::HandleSet32Bit(const char* args)
4226 if(!*args)
4227 return false;
4229 char* px = strtok((char*)args, " ");
4230 char* py = strtok(NULL, " ");
4232 if (!px || !py)
4233 return false;
4235 uint32 Opcode = (uint32)atoi(px);
4236 uint32 Value = (uint32)atoi(py);
4237 if (Value > 32) //uint32 = 32 bits
4238 return false;
4240 sLog.outDebug(GetMangosString(LANG_SET_32BIT), Opcode, Value);
4242 m_session->GetPlayer( )->SetUInt32Value( Opcode , 2^Value );
4244 PSendSysMessage(LANG_SET_32BIT_FIELD, Opcode,1);
4245 return true;
4248 bool ChatHandler::HandleDebugMod32Value(const char* args)
4250 if(!*args)
4251 return false;
4253 char* px = strtok((char*)args, " ");
4254 char* py = strtok(NULL, " ");
4256 if (!px || !py)
4257 return false;
4259 uint32 Opcode = (uint32)atoi(px);
4260 int Value = atoi(py);
4262 if(Opcode >= m_session->GetPlayer()->GetValuesCount())
4264 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, m_session->GetPlayer()->GetGUIDLow(), m_session->GetPlayer( )->GetValuesCount());
4265 return false;
4268 sLog.outDebug(GetMangosString(LANG_CHANGE_32BIT), Opcode, Value);
4270 int CurrentValue = (int)m_session->GetPlayer( )->GetUInt32Value( Opcode );
4272 CurrentValue += Value;
4273 m_session->GetPlayer( )->SetUInt32Value( Opcode , (uint32)CurrentValue );
4275 PSendSysMessage(LANG_CHANGE_32BIT_FIELD, Opcode,CurrentValue);
4277 return true;
4280 bool ChatHandler::HandleTeleAddCommand(const char * args)
4282 if(!*args)
4283 return false;
4285 Player *player=m_session->GetPlayer();
4286 if (!player)
4287 return false;
4289 std::string name = args;
4291 if(objmgr.GetGameTele(name))
4293 SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST);
4294 SetSentErrorMessage(true);
4295 return false;
4298 GameTele tele;
4299 tele.position_x = player->GetPositionX();
4300 tele.position_y = player->GetPositionY();
4301 tele.position_z = player->GetPositionZ();
4302 tele.orientation = player->GetOrientation();
4303 tele.mapId = player->GetMapId();
4304 tele.name = name;
4306 if(objmgr.AddGameTele(tele))
4308 SendSysMessage(LANG_COMMAND_TP_ADDED);
4310 else
4312 SendSysMessage(LANG_COMMAND_TP_ADDEDERR);
4313 SetSentErrorMessage(true);
4314 return false;
4317 return true;
4320 bool ChatHandler::HandleTeleDelCommand(const char * args)
4322 if(!*args)
4323 return false;
4325 std::string name = args;
4327 if(!objmgr.DeleteGameTele(name))
4329 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
4330 SetSentErrorMessage(true);
4331 return false;
4334 SendSysMessage(LANG_COMMAND_TP_DELETED);
4335 return true;
4338 bool ChatHandler::HandleListAurasCommand (const char * /*args*/)
4340 Unit *unit = getSelectedUnit();
4341 if(!unit)
4343 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4344 SetSentErrorMessage(true);
4345 return false;
4348 char const* talentStr = GetMangosString(LANG_TALENT);
4349 char const* passiveStr = GetMangosString(LANG_PASSIVE);
4351 Unit::AuraMap const& uAuras = unit->GetAuras();
4352 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS, uAuras.size());
4353 for (Unit::AuraMap::const_iterator itr = uAuras.begin(); itr != uAuras.end(); ++itr)
4355 bool talent = GetTalentSpellCost(itr->second->GetId()) > 0;
4357 char const* name = itr->second->GetSpellProto()->SpellName[m_session->GetSessionDbcLocale()];
4359 if (m_session)
4361 std::ostringstream ss_name;
4362 ss_name << "|cffffffff|Hspell:" << itr->second->GetId() << "|h[" << name << "]|h|r";
4364 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL, itr->second->GetId(), itr->second->GetEffIndex(),
4365 itr->second->GetModifier()->m_auraname, itr->second->GetAuraDuration(), itr->second->GetAuraMaxDuration(),
4366 ss_name.str().c_str(),
4367 (itr->second->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4368 IS_PLAYER_GUID(itr->second->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr->second->GetCasterGUID()));
4370 else
4372 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL, itr->second->GetId(), itr->second->GetEffIndex(),
4373 itr->second->GetModifier()->m_auraname, itr->second->GetAuraDuration(), itr->second->GetAuraMaxDuration(),
4374 name,
4375 (itr->second->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4376 IS_PLAYER_GUID(itr->second->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr->second->GetCasterGUID()));
4379 for (int i = 0; i < TOTAL_AURAS; i++)
4381 Unit::AuraList const& uAuraList = unit->GetAurasByType(AuraType(i));
4382 if (uAuraList.empty()) continue;
4383 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE, uAuraList.size(), i);
4384 for (Unit::AuraList::const_iterator itr = uAuraList.begin(); itr != uAuraList.end(); ++itr)
4386 bool talent = GetTalentSpellCost((*itr)->GetId()) > 0;
4388 char const* name = (*itr)->GetSpellProto()->SpellName[m_session->GetSessionDbcLocale()];
4390 if (m_session)
4392 std::ostringstream ss_name;
4393 ss_name << "|cffffffff|Hspell:" << (*itr)->GetId() << "|h[" << name << "]|h|r";
4395 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE, (*itr)->GetId(), (*itr)->GetEffIndex(),
4396 ss_name.str().c_str(),((*itr)->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4397 IS_PLAYER_GUID((*itr)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr)->GetCasterGUID()));
4399 else
4401 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE, (*itr)->GetId(), (*itr)->GetEffIndex(),
4402 name,((*itr)->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4403 IS_PLAYER_GUID((*itr)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr)->GetCasterGUID()));
4407 return true;
4410 bool ChatHandler::HandleResetAchievementsCommand (const char * args)
4412 char* pName = strtok((char*)args, "");
4413 Player *player = NULL;
4414 uint64 guid = 0;
4415 if (pName)
4417 std::string name = extractPlayerNameFromLink(pName);
4418 if(name.empty())
4420 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4421 SetSentErrorMessage(true);
4422 return false;
4425 guid = objmgr.GetPlayerGUIDByName(name);
4426 player = objmgr.GetPlayer(guid);
4428 else
4430 player = getSelectedPlayer();
4431 if(player)
4432 guid = player->GetGUID();
4435 if(!player && !guid)
4437 SendSysMessage(LANG_NO_CHAR_SELECTED);
4438 return true;
4441 if(player)
4442 player->GetAchievementMgr().Reset();
4443 else if(guid)
4444 AchievementMgr::DeleteFromDB(GUID_LOPART(guid));
4446 return true;
4449 bool ChatHandler::HandleResetHonorCommand (const char * args)
4451 char* pName = strtok((char*)args, "");
4452 Player *player = NULL;
4453 if (pName)
4455 std::string name = extractPlayerNameFromLink(pName);
4456 if(name.empty())
4458 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4459 SetSentErrorMessage(true);
4460 return false;
4463 uint64 guid = objmgr.GetPlayerGUIDByName(name);
4464 player = objmgr.GetPlayer(guid);
4466 else
4467 player = getSelectedPlayer();
4469 if(!player)
4471 SendSysMessage(LANG_NO_CHAR_SELECTED);
4472 return true;
4475 player->SetUInt32Value(PLAYER_FIELD_KILLS, 0);
4476 player->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS, 0);
4477 player->SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY, 0);
4478 player->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION, 0);
4479 player->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION, 0);
4481 return true;
4484 static bool HandleResetStatsOrLevelHelper(Player* player)
4486 PlayerInfo const *info = objmgr.GetPlayerInfo(player->getRace(), player->getClass());
4487 if(!info) return false;
4489 ChrClassesEntry const* cEntry = sChrClassesStore.LookupEntry(player->getClass());
4490 if(!cEntry)
4492 sLog.outError("Class %u not found in DBC (Wrong DBC files?)",player->getClass());
4493 return false;
4496 uint8 powertype = cEntry->powerType;
4498 // reset m_form if no aura
4499 if(!player->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT))
4500 player->m_form = FORM_NONE;
4502 player->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, DEFAULT_WORLD_OBJECT_SIZE );
4503 player->SetFloatValue(UNIT_FIELD_COMBATREACH, 1.5f );
4505 player->setFactionForRace(player->getRace());
4507 player->SetUInt32Value(UNIT_FIELD_BYTES_0, ( ( player->getRace() ) | ( player->getClass() << 8 ) | ( player->getGender() << 16 ) | ( powertype << 24 ) ) );
4509 // reset only if player not in some form;
4510 if(player->m_form==FORM_NONE)
4512 switch(player->getGender())
4514 case GENDER_FEMALE:
4515 player->SetDisplayId(info->displayId_f);
4516 player->SetNativeDisplayId(info->displayId_f);
4517 break;
4518 case GENDER_MALE:
4519 player->SetDisplayId(info->displayId_m);
4520 player->SetNativeDisplayId(info->displayId_m);
4521 break;
4522 default:
4523 break;
4527 player->SetByteValue(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_PVP );
4528 player->SetByteValue(UNIT_FIELD_BYTES_2, 3, player->m_form);
4530 player->SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
4532 //-1 is default value
4533 player->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX, uint32(-1));
4535 //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000 );
4536 return true;
4539 bool ChatHandler::HandleResetLevelCommand(const char * args)
4541 char* pName = strtok((char*)args, "");
4542 Player *player = NULL;
4543 if (pName)
4545 std::string name = extractPlayerNameFromLink(pName);
4546 if(name.empty())
4548 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4549 SetSentErrorMessage(true);
4550 return false;
4553 uint64 guid = objmgr.GetPlayerGUIDByName(name);
4554 player = objmgr.GetPlayer(guid);
4556 else
4557 player = getSelectedPlayer();
4559 if(!player)
4561 SendSysMessage(LANG_NO_CHAR_SELECTED);
4562 SetSentErrorMessage(true);
4563 return false;
4566 if(!HandleResetStatsOrLevelHelper(player))
4567 return false;
4569 // set starting level
4570 uint32 start_level = player->getClass() != CLASS_DEATH_KNIGHT
4571 ? sWorld.getConfig(CONFIG_START_PLAYER_LEVEL)
4572 : sWorld.getConfig(CONFIG_START_HEROIC_PLAYER_LEVEL);
4574 player->SetLevel(start_level);
4575 player->InitRunes();
4576 player->InitStatsForLevel(true);
4577 player->InitTaxiNodesForLevel();
4578 player->InitGlyphsForLevel();
4579 player->InitTalentForLevel();
4580 player->SetUInt32Value(PLAYER_XP,0);
4582 // reset level to summoned pet
4583 Pet* pet = player->GetPet();
4584 if(pet && pet->getPetType()==SUMMON_PET)
4586 pet->InitStatsForLevel(1);
4587 pet->InitTalentForLevel();
4589 return true;
4592 bool ChatHandler::HandleResetStatsCommand(const char * args)
4594 char* pName = strtok((char*)args, "");
4595 Player *player = NULL;
4596 if (pName)
4598 std::string name = extractPlayerNameFromLink(pName);
4599 if(name.empty())
4601 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4602 SetSentErrorMessage(true);
4603 return false;
4606 uint64 guid = objmgr.GetPlayerGUIDByName(name);
4607 player = objmgr.GetPlayer(guid);
4609 else
4610 player = getSelectedPlayer();
4612 if(!player)
4614 SendSysMessage(LANG_NO_CHAR_SELECTED);
4615 SetSentErrorMessage(true);
4616 return false;
4619 if(!HandleResetStatsOrLevelHelper(player))
4620 return false;
4622 player->InitRunes();
4623 player->InitStatsForLevel(true);
4624 player->InitTaxiNodesForLevel();
4625 player->InitGlyphsForLevel();
4626 player->InitTalentForLevel();
4628 return true;
4631 bool ChatHandler::HandleResetSpellsCommand(const char * args)
4633 char* pName = strtok((char*)args, "");
4634 Player *player = NULL;
4635 uint64 playerGUID = 0;
4636 if (pName)
4638 std::string name = extractPlayerNameFromLink(pName);
4639 if(name.empty())
4641 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4642 SetSentErrorMessage(true);
4643 return false;
4646 player = objmgr.GetPlayer(name.c_str());
4647 if(!player)
4648 playerGUID = objmgr.GetPlayerGUIDByName(name);
4650 else
4651 player = getSelectedPlayer();
4653 if(!player && !playerGUID)
4655 SendSysMessage(LANG_NO_CHAR_SELECTED);
4656 SetSentErrorMessage(true);
4657 return false;
4660 if(player)
4662 player->resetSpells();
4664 ChatHandler(player).SendSysMessage(LANG_RESET_SPELLS);
4665 if(m_session->GetPlayer()!=player)
4666 PSendSysMessage(LANG_RESET_SPELLS_ONLINE,GetNameLink(player).c_str());
4668 else
4670 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS), GUID_LOPART(playerGUID));
4671 PSendSysMessage(LANG_RESET_SPELLS_OFFLINE,pName);
4674 return true;
4677 bool ChatHandler::HandleResetTalentsCommand(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)
4701 player->resetTalents(true);
4703 ChatHandler(player).SendSysMessage(LANG_RESET_TALENTS);
4704 if(m_session->GetPlayer()!=player)
4705 PSendSysMessage(LANG_RESET_TALENTS_ONLINE,GetNameLink(player).c_str());
4707 return true;
4709 else if (playerGUID)
4711 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_TALENTS), GUID_LOPART(playerGUID) );
4712 std::string nameLink = playerLink(pName);
4713 PSendSysMessage(LANG_RESET_TALENTS_OFFLINE,nameLink.c_str());
4714 return true;
4716 // Try reset talenents as Hunter Pet
4717 Creature* creature = getSelectedCreature();
4718 if (creature && creature->isPet() && ((Pet *)creature)->getPetType() == HUNTER_PET)
4720 ((Pet *)creature)->resetTalents(true);
4721 Unit *owner = creature->GetOwner();
4722 if (owner && owner->GetTypeId() == TYPEID_PLAYER)
4724 player = (Player *)owner;
4725 ChatHandler(player).SendSysMessage(LANG_RESET_PET_TALENTS);
4726 if(m_session->GetPlayer()!=player)
4727 PSendSysMessage(LANG_RESET_PET_TALENTS_ONLINE,GetNameLink(player).c_str());
4729 return true;
4732 SendSysMessage(LANG_NO_CHAR_SELECTED);
4733 SetSentErrorMessage(true);
4734 return false;
4737 bool ChatHandler::HandleResetAllCommand(const char * args)
4739 if(!*args)
4740 return false;
4742 std::string casename = args;
4744 AtLoginFlags atLogin;
4746 // Command specially created as single command to prevent using short case names
4747 if(casename=="spells")
4749 atLogin = AT_LOGIN_RESET_SPELLS;
4750 sWorld.SendWorldText(LANG_RESETALL_SPELLS);
4752 else if(casename=="talents")
4754 atLogin = AT_LOGIN_RESET_TALENTS;
4755 sWorld.SendWorldText(LANG_RESETALL_TALENTS);
4757 else
4759 PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE,args);
4760 SetSentErrorMessage(true);
4761 return false;
4764 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE (at_login & '%u') = '0'",atLogin,atLogin);
4765 HashMapHolder<Player>::MapType const& plist = ObjectAccessor::Instance().GetPlayers();
4766 for(HashMapHolder<Player>::MapType::const_iterator itr = plist.begin(); itr != plist.end(); ++itr)
4767 itr->second->SetAtLoginFlag(atLogin);
4769 return true;
4772 bool ChatHandler::HandleServerShutDownCancelCommand(const char* args)
4774 sWorld.ShutdownCancel();
4775 return true;
4778 bool ChatHandler::HandleServerShutDownCommand(const char* args)
4780 if(!*args)
4781 return false;
4783 char* time_str = strtok ((char*) args, " ");
4784 char* exitcode_str = strtok (NULL, "");
4786 int32 time = atoi (time_str);
4788 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4789 if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0)
4790 return false;
4792 if (exitcode_str)
4794 int32 exitcode = atoi (exitcode_str);
4796 // Handle atoi() errors
4797 if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
4798 return false;
4800 // Exit code should be in range of 0-125, 126-255 is used
4801 // in many shells for their own return codes and code > 255
4802 // is not supported in many others
4803 if (exitcode < 0 || exitcode > 125)
4804 return false;
4806 sWorld.ShutdownServ (time, 0, exitcode);
4808 else
4809 sWorld.ShutdownServ(time,0,SHUTDOWN_EXIT_CODE);
4810 return true;
4813 bool ChatHandler::HandleServerRestartCommand(const char* args)
4815 if(!*args)
4816 return false;
4818 char* time_str = strtok ((char*) args, " ");
4819 char* exitcode_str = strtok (NULL, "");
4821 int32 time = atoi (time_str);
4823 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4824 if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0)
4825 return false;
4827 if (exitcode_str)
4829 int32 exitcode = atoi (exitcode_str);
4831 // Handle atoi() errors
4832 if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
4833 return false;
4835 // Exit code should be in range of 0-125, 126-255 is used
4836 // in many shells for their own return codes and code > 255
4837 // is not supported in many others
4838 if (exitcode < 0 || exitcode > 125)
4839 return false;
4841 sWorld.ShutdownServ (time, SHUTDOWN_MASK_RESTART, exitcode);
4843 else
4844 sWorld.ShutdownServ(time, SHUTDOWN_MASK_RESTART, RESTART_EXIT_CODE);
4845 return true;
4848 bool ChatHandler::HandleServerIdleRestartCommand(const char* args)
4850 if(!*args)
4851 return false;
4853 char* time_str = strtok ((char*) args, " ");
4854 char* exitcode_str = strtok (NULL, "");
4856 int32 time = atoi (time_str);
4858 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4859 if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0)
4860 return false;
4862 if (exitcode_str)
4864 int32 exitcode = atoi (exitcode_str);
4866 // Handle atoi() errors
4867 if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
4868 return false;
4870 // Exit code should be in range of 0-125, 126-255 is used
4871 // in many shells for their own return codes and code > 255
4872 // is not supported in many others
4873 if (exitcode < 0 || exitcode > 125)
4874 return false;
4876 sWorld.ShutdownServ (time, SHUTDOWN_MASK_RESTART|SHUTDOWN_MASK_IDLE, exitcode);
4878 else
4879 sWorld.ShutdownServ(time,SHUTDOWN_MASK_RESTART|SHUTDOWN_MASK_IDLE,RESTART_EXIT_CODE);
4880 return true;
4883 bool ChatHandler::HandleServerIdleShutDownCommand(const char* args)
4885 if(!*args)
4886 return false;
4888 char* time_str = strtok ((char*) args, " ");
4889 char* exitcode_str = strtok (NULL, "");
4891 int32 time = atoi (time_str);
4893 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4894 if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0)
4895 return false;
4897 if (exitcode_str)
4899 int32 exitcode = atoi (exitcode_str);
4901 // Handle atoi() errors
4902 if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
4903 return false;
4905 // Exit code should be in range of 0-125, 126-255 is used
4906 // in many shells for their own return codes and code > 255
4907 // is not supported in many others
4908 if (exitcode < 0 || exitcode > 125)
4909 return false;
4911 sWorld.ShutdownServ (time, SHUTDOWN_MASK_IDLE, exitcode);
4913 else
4914 sWorld.ShutdownServ(time,SHUTDOWN_MASK_IDLE,SHUTDOWN_EXIT_CODE);
4915 return true;
4918 bool ChatHandler::HandleQuestAdd(const char* args)
4920 Player* player = getSelectedPlayer();
4921 if(!player)
4923 SendSysMessage(LANG_NO_CHAR_SELECTED);
4924 SetSentErrorMessage(true);
4925 return false;
4928 // .addquest #entry'
4929 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4930 char* cId = extractKeyFromLink((char*)args,"Hquest");
4931 if(!cId)
4932 return false;
4934 uint32 entry = atol(cId);
4936 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
4938 if(!pQuest)
4940 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND,entry);
4941 SetSentErrorMessage(true);
4942 return false;
4945 // check item starting quest (it can work incorrectly if added without item in inventory)
4946 for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
4948 ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype>(id);
4949 if (!pProto)
4950 continue;
4952 if (pProto->StartQuest == entry)
4954 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, entry, pProto->ItemId);
4955 SetSentErrorMessage(true);
4956 return false;
4960 // ok, normal (creature/GO starting) quest
4961 if( player->CanAddQuest( pQuest, true ) )
4963 player->AddQuest( pQuest, NULL );
4965 if ( player->CanCompleteQuest( entry ) )
4966 player->CompleteQuest( entry );
4969 return true;
4972 bool ChatHandler::HandleQuestRemove(const char* args)
4974 Player* player = getSelectedPlayer();
4975 if(!player)
4977 SendSysMessage(LANG_NO_CHAR_SELECTED);
4978 SetSentErrorMessage(true);
4979 return false;
4982 // .removequest #entry'
4983 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4984 char* cId = extractKeyFromLink((char*)args,"Hquest");
4985 if(!cId)
4986 return false;
4988 uint32 entry = atol(cId);
4990 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
4992 if(!pQuest)
4994 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
4995 SetSentErrorMessage(true);
4996 return false;
4999 // remove all quest entries for 'entry' from quest log
5000 for(uint8 slot = 0; slot < MAX_QUEST_LOG_SIZE; ++slot )
5002 uint32 quest = player->GetQuestSlotQuestId(slot);
5003 if(quest==entry)
5005 player->SetQuestSlot(slot,0);
5007 // we ignore unequippable quest items in this case, its' still be equipped
5008 player->TakeQuestSourceItem( quest, false );
5012 // set quest status to not started (will updated in DB at next save)
5013 player->SetQuestStatus( entry, QUEST_STATUS_NONE);
5015 // reset rewarded for restart repeatable quest
5016 player->getQuestStatusMap()[entry].m_rewarded = false;
5018 SendSysMessage(LANG_COMMAND_QUEST_REMOVED);
5019 return true;
5022 bool ChatHandler::HandleQuestComplete(const char* args)
5024 Player* player = getSelectedPlayer();
5025 if(!player)
5027 SendSysMessage(LANG_NO_CHAR_SELECTED);
5028 SetSentErrorMessage(true);
5029 return false;
5032 // .quest complete #entry
5033 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
5034 char* cId = extractKeyFromLink((char*)args,"Hquest");
5035 if(!cId)
5036 return false;
5038 uint32 entry = atol(cId);
5040 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
5042 // If player doesn't have the quest
5043 if(!pQuest || player->GetQuestStatus(entry) == QUEST_STATUS_NONE)
5045 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
5046 SetSentErrorMessage(true);
5047 return false;
5050 // Add quest items for quests that require items
5051 for(uint8 x = 0; x < QUEST_OBJECTIVES_COUNT; ++x)
5053 uint32 id = pQuest->ReqItemId[x];
5054 uint32 count = pQuest->ReqItemCount[x];
5055 if(!id || !count)
5056 continue;
5058 uint32 curItemCount = player->GetItemCount(id,true);
5060 ItemPosCountVec dest;
5061 uint8 msg = player->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, id, count-curItemCount );
5062 if( msg == EQUIP_ERR_OK )
5064 Item* item = player->StoreNewItem( dest, id, true);
5065 player->SendNewItem(item,count-curItemCount,true,false);
5069 // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
5070 for(uint8 i = 0; i < QUEST_OBJECTIVES_COUNT; i++)
5072 uint32 creature = pQuest->ReqCreatureOrGOId[i];
5073 uint32 creaturecount = pQuest->ReqCreatureOrGOCount[i];
5075 if(uint32 spell_id = pQuest->ReqSpell[i])
5077 for(uint16 z = 0; z < creaturecount; ++z)
5078 player->CastedCreatureOrGO(creature,0,spell_id);
5080 else if(creature > 0)
5082 for(uint16 z = 0; z < creaturecount; ++z)
5083 player->KilledMonster(creature,0);
5085 else if(creature < 0)
5087 for(uint16 z = 0; z < creaturecount; ++z)
5088 player->CastedCreatureOrGO(creature,0,0);
5092 // If the quest requires reputation to complete
5093 if(uint32 repFaction = pQuest->GetRepObjectiveFaction())
5095 uint32 repValue = pQuest->GetRepObjectiveValue();
5096 uint32 curRep = player->GetReputationMgr().GetReputation(repFaction);
5097 if(curRep < repValue)
5098 if(FactionEntry const *factionEntry = sFactionStore.LookupEntry(repFaction))
5099 player->GetReputationMgr().SetReputation(factionEntry,repValue);
5102 // If the quest requires money
5103 int32 ReqOrRewMoney = pQuest->GetRewOrReqMoney();
5104 if(ReqOrRewMoney < 0)
5105 player->ModifyMoney(-ReqOrRewMoney);
5107 player->CompleteQuest(entry);
5108 return true;
5111 bool ChatHandler::HandleBanAccountCommand(const char* args)
5113 return HandleBanHelper(BAN_ACCOUNT,args);
5116 bool ChatHandler::HandleBanCharacterCommand(const char* args)
5118 return HandleBanHelper(BAN_CHARACTER,args);
5121 bool ChatHandler::HandleBanIPCommand(const char* args)
5123 return HandleBanHelper(BAN_IP,args);
5126 bool ChatHandler::HandleBanHelper(BanMode mode, const char* args)
5128 if (!*args)
5129 return false;
5131 char* cnameOrIP = strtok ((char*)args, " ");
5132 if (!cnameOrIP)
5133 return false;
5135 std::string nameOrIP = cnameOrIP;
5137 char* duration = strtok (NULL," ");
5138 if(!duration || !atoi(duration))
5139 return false;
5141 char* reason = strtok (NULL,"");
5142 if(!reason)
5143 return false;
5145 switch(mode)
5147 case BAN_ACCOUNT:
5148 if(!AccountMgr::normilizeString(nameOrIP))
5150 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str());
5151 SetSentErrorMessage(true);
5152 return false;
5154 break;
5155 case BAN_CHARACTER:
5156 if(!normalizePlayerName(nameOrIP))
5158 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5159 SetSentErrorMessage(true);
5160 return false;
5162 break;
5163 case BAN_IP:
5164 if(!IsIPAddress(nameOrIP.c_str()))
5165 return false;
5166 break;
5169 switch(sWorld.BanAccount(mode, nameOrIP, duration, reason,m_session ? m_session->GetPlayerName() : ""))
5171 case BAN_SUCCESS:
5172 if(atoi(duration)>0)
5173 PSendSysMessage(LANG_BAN_YOUBANNED,nameOrIP.c_str(),secsToTimeString(TimeStringToSecs(duration),true).c_str(),reason);
5174 else
5175 PSendSysMessage(LANG_BAN_YOUPERMBANNED,nameOrIP.c_str(),reason);
5176 break;
5177 case BAN_SYNTAX_ERROR:
5178 return false;
5179 case BAN_NOTFOUND:
5180 switch(mode)
5182 default:
5183 PSendSysMessage(LANG_BAN_NOTFOUND,"account",nameOrIP.c_str());
5184 break;
5185 case BAN_CHARACTER:
5186 PSendSysMessage(LANG_BAN_NOTFOUND,"character",nameOrIP.c_str());
5187 break;
5188 case BAN_IP:
5189 PSendSysMessage(LANG_BAN_NOTFOUND,"ip",nameOrIP.c_str());
5190 break;
5192 SetSentErrorMessage(true);
5193 return false;
5196 return true;
5199 bool ChatHandler::HandleUnBanAccountCommand(const char* args)
5201 return HandleUnBanHelper(BAN_ACCOUNT,args);
5204 bool ChatHandler::HandleUnBanCharacterCommand(const char* args)
5206 return HandleUnBanHelper(BAN_CHARACTER,args);
5209 bool ChatHandler::HandleUnBanIPCommand(const char* args)
5211 return HandleUnBanHelper(BAN_IP,args);
5214 bool ChatHandler::HandleUnBanHelper(BanMode mode, const char* args)
5216 if (!*args)
5217 return false;
5219 char* cnameOrIP = strtok ((char*)args, " ");
5220 if(!cnameOrIP)
5221 return false;
5223 std::string nameOrIP = cnameOrIP;
5225 switch(mode)
5227 case BAN_ACCOUNT:
5228 if(!AccountMgr::normilizeString(nameOrIP))
5230 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str());
5231 SetSentErrorMessage(true);
5232 return false;
5234 break;
5235 case BAN_CHARACTER:
5236 if(!normalizePlayerName(nameOrIP))
5238 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5239 SetSentErrorMessage(true);
5240 return false;
5242 break;
5243 case BAN_IP:
5244 if(!IsIPAddress(nameOrIP.c_str()))
5245 return false;
5246 break;
5249 if(sWorld.RemoveBanAccount(mode,nameOrIP))
5250 PSendSysMessage(LANG_UNBAN_UNBANNED,nameOrIP.c_str());
5251 else
5252 PSendSysMessage(LANG_UNBAN_ERROR,nameOrIP.c_str());
5254 return true;
5257 bool ChatHandler::HandleBanInfoAccountCommand(const char* args)
5259 if (!*args)
5260 return false;
5262 char* cname = strtok((char*)args, "");
5263 if(!cname)
5264 return false;
5266 std::string account_name = cname;
5267 if(!AccountMgr::normilizeString(account_name))
5269 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5270 SetSentErrorMessage(true);
5271 return false;
5274 uint32 accountid = accmgr.GetId(account_name);
5275 if(!accountid)
5277 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5278 return true;
5281 return HandleBanInfoHelper(accountid,account_name.c_str());
5284 bool ChatHandler::HandleBanInfoCharacterCommand(const char* args)
5286 if (!*args)
5287 return false;
5289 std::string name = extractPlayerNameFromLink((char*)args);
5290 if(name.empty())
5292 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5293 SetSentErrorMessage(true);
5294 return false;
5297 uint32 accountid = objmgr.GetPlayerAccountIdByPlayerName(name);
5298 if(!accountid)
5300 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5301 SetSentErrorMessage(true);
5302 return false;
5305 std::string accountname;
5306 if(!accmgr.GetName(accountid,accountname))
5308 PSendSysMessage(LANG_BANINFO_NOCHARACTER);
5309 return true;
5312 return HandleBanInfoHelper(accountid,accountname.c_str());
5315 bool ChatHandler::HandleBanInfoHelper(uint32 accountid, char const* accountname)
5317 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);
5318 if(!result)
5320 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN, accountname);
5321 return true;
5324 PSendSysMessage(LANG_BANINFO_BANHISTORY,accountname);
5327 Field* fields = result->Fetch();
5329 time_t unbandate = time_t(fields[3].GetUInt64());
5330 bool active = false;
5331 if(fields[2].GetBool() && (fields[1].GetUInt64() == (uint64)0 ||unbandate >= time(NULL)) )
5332 active = true;
5333 bool permanent = (fields[1].GetUInt64() == (uint64)0);
5334 std::string bantime = permanent?GetMangosString(LANG_BANINFO_INFINITE):secsToTimeString(fields[1].GetUInt64(), true);
5335 PSendSysMessage(LANG_BANINFO_HISTORYENTRY,
5336 fields[0].GetString(), bantime.c_str(), active ? GetMangosString(LANG_BANINFO_YES):GetMangosString(LANG_BANINFO_NO), fields[4].GetString(), fields[5].GetString());
5337 }while (result->NextRow());
5339 delete result;
5340 return true;
5343 bool ChatHandler::HandleBanInfoIPCommand(const char* args)
5345 if (!*args)
5346 return false;
5348 char* cIP = strtok ((char*)args, "");
5349 if(!cIP)
5350 return false;
5352 if (!IsIPAddress(cIP))
5353 return false;
5355 std::string IP = cIP;
5357 loginDatabase.escape_string(IP);
5358 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());
5359 if(!result)
5361 PSendSysMessage(LANG_BANINFO_NOIP);
5362 return true;
5365 Field *fields = result->Fetch();
5366 bool permanent = !fields[6].GetUInt64();
5367 PSendSysMessage(LANG_BANINFO_IPENTRY,
5368 fields[0].GetString(), fields[1].GetString(), permanent ? GetMangosString(LANG_BANINFO_NEVER):fields[2].GetString(),
5369 permanent ? GetMangosString(LANG_BANINFO_INFINITE):secsToTimeString(fields[3].GetUInt64(), true).c_str(), fields[4].GetString(), fields[5].GetString());
5370 delete result;
5371 return true;
5374 bool ChatHandler::HandleBanListCharacterCommand(const char* args)
5376 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5378 char* cFilter = strtok ((char*)args, " ");
5379 if(!cFilter)
5380 return false;
5382 std::string filter = cFilter;
5383 loginDatabase.escape_string(filter);
5384 QueryResult* result = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'"),filter.c_str());
5385 if (!result)
5387 PSendSysMessage(LANG_BANLIST_NOCHARACTER);
5388 return true;
5391 return HandleBanListHelper(result);
5394 bool ChatHandler::HandleBanListAccountCommand(const char* args)
5396 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5398 char* cFilter = strtok((char*)args, " ");
5399 std::string filter = cFilter ? cFilter : "";
5400 loginDatabase.escape_string(filter);
5402 QueryResult* result;
5404 if(filter.empty())
5406 result = loginDatabase.Query("SELECT account.id, username FROM account, account_banned"
5407 " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
5409 else
5411 result = loginDatabase.PQuery("SELECT account.id, username FROM account, account_banned"
5412 " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
5413 filter.c_str());
5416 if (!result)
5418 PSendSysMessage(LANG_BANLIST_NOACCOUNT);
5419 return true;
5422 return HandleBanListHelper(result);
5425 bool ChatHandler::HandleBanListHelper(QueryResult* result)
5427 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT);
5429 // Chat short output
5430 if(m_session)
5434 Field* fields = result->Fetch();
5435 uint32 accountid = fields[0].GetUInt32();
5437 QueryResult* banresult = loginDatabase.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid);
5438 if(banresult)
5440 Field* fields2 = banresult->Fetch();
5441 PSendSysMessage("%s",fields2[0].GetString());
5442 delete banresult;
5444 } while (result->NextRow());
5446 // Console wide output
5447 else
5449 SendSysMessage(LANG_BANLIST_ACCOUNTS);
5450 SendSysMessage("===============================================================================");
5451 SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER);
5454 SendSysMessage("-------------------------------------------------------------------------------");
5455 Field *fields = result->Fetch();
5456 uint32 account_id = fields[0].GetUInt32 ();
5458 std::string account_name;
5460 // "account" case, name can be get in same query
5461 if(result->GetFieldCount() > 1)
5462 account_name = fields[1].GetCppString();
5463 // "character" case, name need extract from another DB
5464 else
5465 accmgr.GetName (account_id,account_name);
5467 // No SQL injection. id is uint32.
5468 QueryResult *banInfo = loginDatabase.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id);
5469 if (banInfo)
5471 Field *fields2 = banInfo->Fetch();
5474 time_t t_ban = fields2[0].GetUInt64();
5475 tm* aTm_ban = localtime(&t_ban);
5477 if (fields2[0].GetUInt64() == fields2[1].GetUInt64())
5479 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5480 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,
5481 fields2[2].GetString(),fields2[3].GetString());
5483 else
5485 time_t t_unban = fields2[1].GetUInt64();
5486 tm* aTm_unban = localtime(&t_unban);
5487 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5488 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,
5489 aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
5490 fields2[2].GetString(),fields2[3].GetString());
5492 }while ( banInfo->NextRow() );
5493 delete banInfo;
5495 }while( result->NextRow() );
5496 SendSysMessage("===============================================================================");
5499 delete result;
5500 return true;
5503 bool ChatHandler::HandleBanListIPCommand(const char* args)
5505 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5507 char* cFilter = strtok((char*)args, " ");
5508 std::string filter = cFilter ? cFilter : "";
5509 loginDatabase.escape_string(filter);
5511 QueryResult* result;
5513 if(filter.empty())
5515 result = loginDatabase.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5516 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
5517 " ORDER BY unbandate" );
5519 else
5521 result = loginDatabase.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5522 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")
5523 " ORDER BY unbandate",filter.c_str() );
5526 if(!result)
5528 PSendSysMessage(LANG_BANLIST_NOIP);
5529 return true;
5532 PSendSysMessage(LANG_BANLIST_MATCHINGIP);
5533 // Chat short output
5534 if(m_session)
5538 Field* fields = result->Fetch();
5539 PSendSysMessage("%s",fields[0].GetString());
5540 } while (result->NextRow());
5542 // Console wide output
5543 else
5545 SendSysMessage(LANG_BANLIST_IPS);
5546 SendSysMessage("===============================================================================");
5547 SendSysMessage(LANG_BANLIST_IPS_HEADER);
5550 SendSysMessage("-------------------------------------------------------------------------------");
5551 Field *fields = result->Fetch();
5552 time_t t_ban = fields[1].GetUInt64();
5553 tm* aTm_ban = localtime(&t_ban);
5554 if ( fields[1].GetUInt64() == fields[2].GetUInt64() )
5556 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5557 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,
5558 fields[3].GetString(), fields[4].GetString());
5560 else
5562 time_t t_unban = fields[2].GetUInt64();
5563 tm* aTm_unban = localtime(&t_unban);
5564 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5565 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,
5566 aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
5567 fields[3].GetString(), fields[4].GetString());
5569 }while( result->NextRow() );
5570 SendSysMessage("===============================================================================");
5573 delete result;
5574 return true;
5577 bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
5579 Player* pl = m_session->GetPlayer();
5581 // accept only explicitly selected target (not implicitly self targeting case)
5582 Unit* target = getSelectedUnit();
5583 if(pl->GetSelection() && target)
5585 if(target->GetTypeId()!=TYPEID_UNIT)
5587 SendSysMessage(LANG_SELECT_CREATURE);
5588 SetSentErrorMessage(true);
5589 return false;
5592 if(target->isDead())
5593 ((Creature*)target)->Respawn();
5594 return true;
5597 CellPair p(MaNGOS::ComputeCellPair(pl->GetPositionX(), pl->GetPositionY()));
5598 Cell cell(p);
5599 cell.data.Part.reserved = ALL_DISTRICT;
5600 cell.SetNoCreate();
5602 MaNGOS::RespawnDo u_do;
5603 MaNGOS::WorldObjectWorker<MaNGOS::RespawnDo> worker(pl,u_do);
5605 TypeContainerVisitor<MaNGOS::WorldObjectWorker<MaNGOS::RespawnDo>, GridTypeMapContainer > obj_worker(worker);
5606 CellLock<GridReadGuard> cell_lock(cell, p);
5607 cell_lock->Visit(cell_lock, obj_worker, *pl->GetMap());
5609 return true;
5612 bool ChatHandler::HandleGMFlyModeCommand(const char* args)
5614 if (!*args)
5615 return false;
5617 Player *target = getSelectedPlayer();
5618 if (!target)
5619 target = m_session->GetPlayer();
5621 WorldPacket data(12);
5622 if (strncmp(args, "on", 3) == 0)
5623 data.SetOpcode(SMSG_MOVE_SET_CAN_FLY);
5624 else if (strncmp(args, "off", 4) == 0)
5625 data.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY);
5626 else
5628 SendSysMessage(LANG_USE_BOL);
5629 return false;
5631 data.append(target->GetPackGUID());
5632 data << uint32(0); // unknown
5633 target->SendMessageToSet(&data, true);
5634 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS, GetNameLink(target).c_str(), args);
5635 return true;
5638 bool ChatHandler::HandlePDumpLoadCommand(const char *args)
5640 if (!*args)
5641 return false;
5643 char * file = strtok((char*)args, " ");
5644 if(!file)
5645 return false;
5647 char * account = strtok(NULL, " ");
5648 if(!account)
5649 return false;
5651 std::string account_name = account;
5652 if(!AccountMgr::normilizeString(account_name))
5654 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5655 SetSentErrorMessage(true);
5656 return false;
5659 uint32 account_id = accmgr.GetId(account_name);
5660 if(!account_id)
5662 account_id = atoi(account); // use original string
5663 if(!account_id)
5665 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5666 SetSentErrorMessage(true);
5667 return false;
5671 if(!accmgr.GetName(account_id,account_name))
5673 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5674 SetSentErrorMessage(true);
5675 return false;
5678 char* guid_str = NULL;
5679 char* name_str = strtok(NULL, " ");
5681 std::string name;
5682 if(name_str)
5684 name = name_str;
5685 // normalize the name if specified and check if it exists
5686 if(!normalizePlayerName(name))
5688 PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
5689 SetSentErrorMessage(true);
5690 return false;
5693 if(!ObjectMgr::IsValidName(name,true))
5695 PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
5696 SetSentErrorMessage(true);
5697 return false;
5700 guid_str = strtok(NULL, " ");
5703 uint32 guid = 0;
5705 if(guid_str)
5707 guid = atoi(guid_str);
5708 if(!guid)
5710 PSendSysMessage(LANG_INVALID_CHARACTER_GUID);
5711 SetSentErrorMessage(true);
5712 return false;
5715 if(objmgr.GetPlayerAccountIdByGUID(guid))
5717 PSendSysMessage(LANG_CHARACTER_GUID_IN_USE,guid);
5718 SetSentErrorMessage(true);
5719 return false;
5723 switch(PlayerDumpReader().LoadDump(file, account_id, name, guid))
5725 case DUMP_SUCCESS:
5726 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS);
5727 break;
5728 case DUMP_FILE_OPEN_ERROR:
5729 PSendSysMessage(LANG_FILE_OPEN_FAIL,file);
5730 SetSentErrorMessage(true);
5731 return false;
5732 case DUMP_FILE_BROKEN:
5733 PSendSysMessage(LANG_DUMP_BROKEN,file);
5734 SetSentErrorMessage(true);
5735 return false;
5736 case DUMP_TOO_MANY_CHARS:
5737 PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL,account_name.c_str(),account_id);
5738 SetSentErrorMessage(true);
5739 return false;
5740 default:
5741 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED);
5742 SetSentErrorMessage(true);
5743 return false;
5746 return true;
5749 bool ChatHandler::HandlePDumpWriteCommand(const char *args)
5751 if (!*args)
5752 return false;
5754 char* file = strtok((char*)args, " ");
5755 char* p2 = strtok(NULL, " ");
5757 if(!file || !p2)
5758 return false;
5760 uint32 guid;
5761 // character name can't start from number
5762 if (isNumeric(p2[0]))
5763 guid = atoi(p2);
5764 else
5766 std::string name = extractPlayerNameFromLink(p2);
5767 if(name.empty())
5769 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5770 SetSentErrorMessage(true);
5771 return false;
5774 guid = objmgr.GetPlayerGUIDByName(name);
5777 if(!objmgr.GetPlayerAccountIdByGUID(guid))
5779 PSendSysMessage(LANG_PLAYER_NOT_FOUND);
5780 SetSentErrorMessage(true);
5781 return false;
5784 switch(PlayerDumpWriter().WriteDump(file, guid))
5786 case DUMP_SUCCESS:
5787 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS);
5788 break;
5789 case DUMP_FILE_OPEN_ERROR:
5790 PSendSysMessage(LANG_FILE_OPEN_FAIL,file);
5791 SetSentErrorMessage(true);
5792 return false;
5793 default:
5794 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED);
5795 SetSentErrorMessage(true);
5796 return false;
5799 return true;
5802 bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
5804 Unit* unit = getSelectedUnit();
5805 if(!unit)
5807 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5808 SetSentErrorMessage(true);
5809 return false;
5812 PSendSysMessage(LANG_MOVEGENS_LIST,(unit->GetTypeId()==TYPEID_PLAYER ? "Player" : "Creature" ),unit->GetGUIDLow());
5814 MotionMaster* mm = unit->GetMotionMaster();
5815 for(MotionMaster::const_iterator itr = mm->begin(); itr != mm->end(); ++itr)
5817 switch((*itr)->GetMovementGeneratorType())
5819 case IDLE_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_IDLE); break;
5820 case RANDOM_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_RANDOM); break;
5821 case WAYPOINT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_WAYPOINT); break;
5822 case ANIMAL_RANDOM_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_ANIMAL_RANDOM); break;
5823 case CONFUSED_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_CONFUSED); break;
5824 case TARGETED_MOTION_TYPE:
5826 if(unit->GetTypeId()==TYPEID_PLAYER)
5828 TargetedMovementGenerator<Player> const* mgen = static_cast<TargetedMovementGenerator<Player> const*>(*itr);
5829 Unit* target = mgen->GetTarget();
5830 if(target)
5831 PSendSysMessage(LANG_MOVEGENS_TARGETED_PLAYER,target->GetName(),target->GetGUIDLow());
5832 else
5833 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL);
5835 else
5837 TargetedMovementGenerator<Creature> const* mgen = static_cast<TargetedMovementGenerator<Creature> const*>(*itr);
5838 Unit* target = mgen->GetTarget();
5839 if(target)
5840 PSendSysMessage(LANG_MOVEGENS_TARGETED_CREATURE,target->GetName(),target->GetGUIDLow());
5841 else
5842 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL);
5844 break;
5846 case HOME_MOTION_TYPE:
5847 if(unit->GetTypeId()==TYPEID_UNIT)
5849 float x,y,z;
5850 (*itr)->GetDestination(x,y,z);
5851 PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE,x,y,z);
5853 else
5854 SendSysMessage(LANG_MOVEGENS_HOME_PLAYER);
5855 break;
5856 case FLIGHT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FLIGHT); break;
5857 case POINT_MOTION_TYPE:
5859 float x,y,z;
5860 (*itr)->GetDestination(x,y,z);
5861 PSendSysMessage(LANG_MOVEGENS_POINT,x,y,z);
5862 break;
5864 case FLEEING_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FEAR); break;
5865 case DISTRACT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_DISTRACT); break;
5866 default:
5867 PSendSysMessage(LANG_MOVEGENS_UNKNOWN,(*itr)->GetMovementGeneratorType());
5868 break;
5871 return true;
5874 bool ChatHandler::HandlePLimitCommand(const char *args)
5876 if(*args)
5878 char* param = strtok((char*)args, " ");
5879 if(!param)
5880 return false;
5882 int l = strlen(param);
5884 if( strncmp(param,"player",l) == 0 )
5885 sWorld.SetPlayerLimit(-SEC_PLAYER);
5886 else if(strncmp(param,"moderator",l) == 0 )
5887 sWorld.SetPlayerLimit(-SEC_MODERATOR);
5888 else if(strncmp(param,"gamemaster",l) == 0 )
5889 sWorld.SetPlayerLimit(-SEC_GAMEMASTER);
5890 else if(strncmp(param,"administrator",l) == 0 )
5891 sWorld.SetPlayerLimit(-SEC_ADMINISTRATOR);
5892 else if(strncmp(param,"reset",l) == 0 )
5893 sWorld.SetPlayerLimit( sConfig.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT) );
5894 else
5896 int val = atoi(param);
5897 if(val < -SEC_ADMINISTRATOR) val = -SEC_ADMINISTRATOR;
5899 sWorld.SetPlayerLimit(val);
5902 // kick all low security level players
5903 if(sWorld.GetPlayerAmountLimit() > SEC_PLAYER)
5904 sWorld.KickAllLess(sWorld.GetPlayerSecurityLimit());
5907 uint32 pLimit = sWorld.GetPlayerAmountLimit();
5908 AccountTypes allowedAccountType = sWorld.GetPlayerSecurityLimit();
5909 char const* secName = "";
5910 switch(allowedAccountType)
5912 case SEC_PLAYER: secName = "Player"; break;
5913 case SEC_MODERATOR: secName = "Moderator"; break;
5914 case SEC_GAMEMASTER: secName = "Gamemaster"; break;
5915 case SEC_ADMINISTRATOR: secName = "Administrator"; break;
5916 default: secName = "<unknown>"; break;
5919 PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit,secName);
5921 return true;
5924 bool ChatHandler::HandleCastCommand(const char* args)
5926 if(!*args)
5927 return false;
5929 Unit* target = getSelectedUnit();
5931 if(!target)
5933 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5934 SetSentErrorMessage(true);
5935 return false;
5938 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5939 uint32 spell = extractSpellIdFromLink((char*)args);
5940 if(!spell)
5941 return false;
5943 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
5944 if(!spellInfo)
5945 return false;
5947 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
5949 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
5950 SetSentErrorMessage(true);
5951 return false;
5954 char* trig_str = strtok(NULL, " ");
5955 if(trig_str)
5957 int l = strlen(trig_str);
5958 if(strncmp(trig_str,"triggered",l) != 0 )
5959 return false;
5962 bool triggered = (trig_str != NULL);
5964 m_session->GetPlayer()->CastSpell(target,spell,triggered);
5966 return true;
5969 bool ChatHandler::HandleCastBackCommand(const char* args)
5971 Creature* caster = getSelectedCreature();
5973 if(!caster)
5975 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5976 SetSentErrorMessage(true);
5977 return false;
5980 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
5981 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5982 uint32 spell = extractSpellIdFromLink((char*)args);
5983 if(!spell || !sSpellStore.LookupEntry(spell))
5984 return false;
5986 char* trig_str = strtok(NULL, " ");
5987 if(trig_str)
5989 int l = strlen(trig_str);
5990 if(strncmp(trig_str,"triggered",l) != 0 )
5991 return false;
5994 bool triggered = (trig_str != NULL);
5996 // update orientation at server
5997 caster->SetOrientation(caster->GetAngle(m_session->GetPlayer()));
5999 // and client
6000 WorldPacket data;
6001 caster->BuildHeartBeatMsg(&data);
6002 caster->SendMessageToSet(&data,true);
6004 caster->CastSpell(m_session->GetPlayer(),spell,triggered);
6006 return true;
6009 bool ChatHandler::HandleCastDistCommand(const char* args)
6011 if(!*args)
6012 return false;
6014 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6015 uint32 spell = extractSpellIdFromLink((char*)args);
6016 if(!spell)
6017 return false;
6019 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
6020 if(!spellInfo)
6021 return false;
6023 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
6025 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
6026 SetSentErrorMessage(true);
6027 return false;
6030 char *distStr = strtok(NULL, " ");
6032 float dist = 0;
6034 if(distStr)
6035 sscanf(distStr, "%f", &dist);
6037 char* trig_str = strtok(NULL, " ");
6038 if(trig_str)
6040 int l = strlen(trig_str);
6041 if(strncmp(trig_str,"triggered",l) != 0 )
6042 return false;
6045 bool triggered = (trig_str != NULL);
6047 float x,y,z;
6048 m_session->GetPlayer()->GetClosePoint(x,y,z,dist);
6050 m_session->GetPlayer()->CastSpell(x,y,z,spell,triggered);
6051 return true;
6054 bool ChatHandler::HandleCastTargetCommand(const char* args)
6056 Creature* caster = getSelectedCreature();
6058 if(!caster)
6060 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
6061 SetSentErrorMessage(true);
6062 return false;
6065 if(!caster->getVictim())
6067 SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM);
6068 SetSentErrorMessage(true);
6069 return false;
6072 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6073 uint32 spell = extractSpellIdFromLink((char*)args);
6074 if(!spell || !sSpellStore.LookupEntry(spell))
6075 return false;
6077 char* trig_str = strtok(NULL, " ");
6078 if(trig_str)
6080 int l = strlen(trig_str);
6081 if(strncmp(trig_str,"triggered",l) != 0 )
6082 return false;
6085 bool triggered = (trig_str != NULL);
6087 // update orientation at server
6088 caster->SetOrientation(caster->GetAngle(m_session->GetPlayer()));
6090 // and client
6091 WorldPacket data;
6092 caster->BuildHeartBeatMsg(&data);
6093 caster->SendMessageToSet(&data,true);
6095 caster->CastSpell(caster->getVictim(),spell,triggered);
6097 return true;
6101 ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
6102 Without this function 3rd party scripting library will get linking errors (unresolved external)
6103 when attempting to use the PointMovementGenerator
6105 bool ChatHandler::HandleComeToMeCommand(const char *args)
6107 Creature* caster = getSelectedCreature();
6109 if(!caster)
6111 SendSysMessage(LANG_SELECT_CREATURE);
6112 SetSentErrorMessage(true);
6113 return false;
6116 char* newFlagStr = strtok((char*)args, " ");
6118 if(!newFlagStr)
6119 return false;
6121 uint32 newFlags = atoi(newFlagStr);
6123 caster->SetUnitMovementFlags(newFlags);
6125 Player* pl = m_session->GetPlayer();
6127 caster->GetMotionMaster()->MovePoint(0, pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ());
6128 return true;
6131 bool ChatHandler::HandleCastSelfCommand(const char* args)
6133 if(!*args)
6134 return false;
6136 Unit* target = getSelectedUnit();
6138 if(!target)
6140 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
6141 SetSentErrorMessage(true);
6142 return false;
6145 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6146 uint32 spell = extractSpellIdFromLink((char*)args);
6147 if(!spell)
6148 return false;
6150 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
6151 if(!spellInfo)
6152 return false;
6154 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
6156 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
6157 SetSentErrorMessage(true);
6158 return false;
6161 target->CastSpell(target,spell,false);
6163 return true;
6166 std::string GetTimeString(uint32 time)
6168 uint16 days = time / DAY, hours = (time % DAY) / HOUR, minute = (time % HOUR) / MINUTE;
6169 std::ostringstream ss;
6170 if(days) ss << days << "d ";
6171 if(hours) ss << hours << "h ";
6172 ss << minute << "m";
6173 return ss.str();
6176 bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
6178 Player* player = getSelectedPlayer();
6179 if (!player) player = m_session->GetPlayer();
6180 uint32 counter = 0;
6181 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; i++)
6183 Player::BoundInstancesMap &binds = player->GetBoundInstances(i);
6184 for(Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end(); ++itr)
6186 InstanceSave *save = itr->second.save;
6187 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
6188 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());
6189 counter++;
6192 PSendSysMessage("player binds: %d", counter);
6193 counter = 0;
6194 Group *group = player->GetGroup();
6195 if(group)
6197 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; i++)
6199 Group::BoundInstancesMap &binds = group->GetBoundInstances(i);
6200 for(Group::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end(); ++itr)
6202 InstanceSave *save = itr->second.save;
6203 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
6204 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());
6205 counter++;
6209 PSendSysMessage("group binds: %d", counter);
6211 return true;
6214 bool ChatHandler::HandleInstanceUnbindCommand(const char* args)
6216 if(!*args)
6217 return false;
6219 std::string cmd = args;
6220 if(cmd == "all")
6222 Player* player = getSelectedPlayer();
6223 if (!player) player = m_session->GetPlayer();
6224 uint32 counter = 0;
6225 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; i++)
6227 Player::BoundInstancesMap &binds = player->GetBoundInstances(i);
6228 for(Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end();)
6230 if(itr->first != player->GetMapId())
6232 InstanceSave *save = itr->second.save;
6233 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
6234 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());
6235 player->UnbindInstance(itr, i);
6236 counter++;
6238 else
6239 ++itr;
6242 PSendSysMessage("instances unbound: %d", counter);
6244 return true;
6247 bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
6249 PSendSysMessage("instances loaded: %d", MapManager::Instance().GetNumInstances());
6250 PSendSysMessage("players in instances: %d", MapManager::Instance().GetNumPlayersInInstances());
6251 PSendSysMessage("instance saves: %d", sInstanceSaveManager.GetNumInstanceSaves());
6252 PSendSysMessage("players bound: %d", sInstanceSaveManager.GetNumBoundPlayersTotal());
6253 PSendSysMessage("groups bound: %d", sInstanceSaveManager.GetNumBoundGroupsTotal());
6254 return true;
6257 bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
6259 Player* pl = m_session->GetPlayer();
6261 Map* map = pl->GetMap();
6262 if (!map->IsDungeon())
6264 PSendSysMessage("Map is not a dungeon.");
6265 SetSentErrorMessage(true);
6266 return false;
6269 if (!((InstanceMap*)map)->GetInstanceData())
6271 PSendSysMessage("Map has no instance data.");
6272 SetSentErrorMessage(true);
6273 return false;
6276 ((InstanceMap*)map)->GetInstanceData()->SaveToDB();
6277 return true;
6280 /// Display the list of GMs
6281 bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
6283 ///- Get the accounts with GM Level >0
6284 QueryResult *result = loginDatabase.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
6285 if(result)
6287 SendSysMessage(LANG_GMLIST);
6288 SendSysMessage("========================");
6289 SendSysMessage(LANG_GMLIST_HEADER);
6290 SendSysMessage("========================");
6292 ///- Circle through them. Display username and GM level
6295 Field *fields = result->Fetch();
6296 PSendSysMessage("|%15s|%6s|", fields[0].GetString(),fields[1].GetString());
6297 }while( result->NextRow() );
6299 PSendSysMessage("========================");
6300 delete result;
6302 else
6303 PSendSysMessage(LANG_GMLIST_EMPTY);
6304 return true;
6307 /// Define the 'Message of the day' for the realm
6308 bool ChatHandler::HandleServerSetMotdCommand(const char* args)
6310 sWorld.SetMotd(args);
6311 PSendSysMessage(LANG_MOTD_NEW, args);
6312 return true;
6315 /// Set/Unset the expansion level for an account
6316 bool ChatHandler::HandleAccountSetAddonCommand(const char* args)
6318 ///- Get the command line arguments
6319 char *szAcc = strtok((char*)args," ");
6320 char *szExp = strtok(NULL," ");
6322 if(!szAcc)
6323 return false;
6325 std::string account_name;
6326 uint32 account_id;
6328 if(!szExp)
6330 Player* player = getSelectedPlayer();
6331 if(!player)
6332 return false;
6334 account_id = player->GetSession()->GetAccountId();
6335 accmgr.GetName(account_id,account_name);
6336 szExp = szAcc;
6338 else
6340 ///- Convert Account name to Upper Format
6341 account_name = szAcc;
6342 if(!AccountMgr::normilizeString(account_name))
6344 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
6345 SetSentErrorMessage(true);
6346 return false;
6349 account_id = accmgr.GetId(account_name);
6350 if(!account_id)
6352 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
6353 SetSentErrorMessage(true);
6354 return false;
6359 // Let set addon state only for lesser (strong) security level
6360 // or to self account
6361 if (m_session && m_session->GetAccountId () != account_id &&
6362 HasLowerSecurityAccount (NULL,account_id,true))
6363 return false;
6365 int lev=atoi(szExp); //get int anyway (0 if error)
6366 if(lev < 0)
6367 return false;
6369 // No SQL injection
6370 loginDatabase.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev,account_id);
6371 PSendSysMessage(LANG_ACCOUNT_SETADDON,account_name.c_str(),account_id,lev);
6372 return true;
6375 //Send items by mail
6376 bool ChatHandler::HandleSendItemsCommand(const char* args)
6378 if(!*args)
6379 return false;
6381 // format: name "subject text" "mail text" item1[:count1] item2[:count2] ... item12[:count12]
6383 std::string name = extractPlayerNameFromLink((char*)args);
6384 if(name.empty())
6386 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6387 SetSentErrorMessage(true);
6388 return false;
6391 char* tail1 = strtok(NULL, "");
6392 if(!tail1)
6393 return false;
6395 char* msgSubject;
6396 if(*tail1=='"')
6397 msgSubject = strtok(tail1+1, "\"");
6398 else
6400 char* space = strtok(tail1, "\"");
6401 if(!space)
6402 return false;
6403 msgSubject = strtok(NULL, "\"");
6406 if (!msgSubject)
6407 return false;
6409 char* tail2 = strtok(NULL, "");
6410 if(!tail2)
6411 return false;
6413 char* msgText;
6414 if(*tail2=='"')
6415 msgText = strtok(tail2+1, "\"");
6416 else
6418 char* space = strtok(tail2, "\"");
6419 if(!space)
6420 return false;
6421 msgText = strtok(NULL, "\"");
6424 if (!msgText)
6425 return false;
6427 // msgSubject, msgText isn't NUL after prev. check
6428 std::string subject = msgSubject;
6429 std::string text = msgText;
6431 // extract items
6432 typedef std::pair<uint32,uint32> ItemPair;
6433 typedef std::list< ItemPair > ItemPairs;
6434 ItemPairs items;
6436 // get all tail string
6437 char* tail = strtok(NULL, "");
6439 // get from tail next item str
6440 while(char* itemStr = strtok(tail, " "))
6442 // and get new tail
6443 tail = strtok(NULL, "");
6445 // parse item str
6446 char* itemIdStr = strtok(itemStr, ":");
6447 char* itemCountStr = strtok(NULL, " ");
6449 uint32 item_id = atoi(itemIdStr);
6450 if(!item_id)
6451 return false;
6453 ItemPrototype const* item_proto = objmgr.GetItemPrototype(item_id);
6454 if(!item_proto)
6456 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
6457 SetSentErrorMessage(true);
6458 return false;
6461 uint32 item_count = itemCountStr ? atoi(itemCountStr) : 1;
6462 if(item_count < 1 || item_proto->MaxCount > 0 && item_count > uint32(item_proto->MaxCount))
6464 PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT, item_count,item_id);
6465 SetSentErrorMessage(true);
6466 return false;
6469 while(item_count > item_proto->GetMaxStackSize())
6471 items.push_back(ItemPair(item_id,item_proto->GetMaxStackSize()));
6472 item_count -= item_proto->GetMaxStackSize();
6475 items.push_back(ItemPair(item_id,item_count));
6477 if(items.size() > MAX_MAIL_ITEMS)
6479 PSendSysMessage(LANG_COMMAND_MAIL_ITEMS_LIMIT, MAX_MAIL_ITEMS);
6480 SetSentErrorMessage(true);
6481 return false;
6485 uint64 receiver_guid = objmgr.GetPlayerGUIDByName(name);
6486 if(!receiver_guid)
6488 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6489 SetSentErrorMessage(true);
6490 return false;
6493 // from console show not existed sender
6494 uint32 sender_guidlo = m_session ? m_session->GetPlayer()->GetGUIDLow() : 0;
6496 uint32 messagetype = MAIL_NORMAL;
6497 uint32 stationery = MAIL_STATIONERY_GM;
6498 uint32 itemTextId = !text.empty() ? objmgr.CreateItemText( text ) : 0;
6500 Player *receiver = objmgr.GetPlayer(receiver_guid);
6502 // fill mail
6503 MailItemsInfo mi; // item list preparing
6505 for(ItemPairs::const_iterator itr = items.begin(); itr != items.end(); ++itr)
6507 if(Item* item = Item::CreateItem(itr->first,itr->second,m_session ? m_session->GetPlayer() : 0))
6509 item->SaveToDB(); // save for prevent lost at next mail load, if send fail then item will deleted
6510 mi.AddItem(item->GetGUIDLow(), item->GetEntry(), item);
6514 WorldSession::SendMailTo(receiver,messagetype, stationery, sender_guidlo, GUID_LOPART(receiver_guid), subject, itemTextId, &mi, 0, 0, MAIL_CHECK_MASK_NONE);
6516 std::string nameLink = playerLink(name);
6517 PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
6518 return true;
6521 ///Send money by mail
6522 bool ChatHandler::HandleSendMoneyCommand(const char* args)
6524 if (!*args)
6525 return false;
6527 /// format: name "subject text" "mail text" money
6529 std::string name = extractPlayerNameFromLink((char*)args);
6530 if(name.empty())
6532 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6533 SetSentErrorMessage(true);
6534 return false;
6537 char* tail1 = strtok(NULL, "");
6538 if (!tail1)
6539 return false;
6541 char* msgSubject;
6542 if (*tail1=='"')
6543 msgSubject = strtok(tail1+1, "\"");
6544 else
6546 char* space = strtok(tail1, "\"");
6547 if (!space)
6548 return false;
6549 msgSubject = strtok(NULL, "\"");
6552 if (!msgSubject)
6553 return false;
6555 char* tail2 = strtok(NULL, "");
6556 if (!tail2)
6557 return false;
6559 char* msgText;
6560 if (*tail2=='"')
6561 msgText = strtok(tail2+1, "\"");
6562 else
6564 char* space = strtok(tail2, "\"");
6565 if (!space)
6566 return false;
6567 msgText = strtok(NULL, "\"");
6570 if (!msgText)
6571 return false;
6573 char* money_str = strtok(NULL, "");
6574 int32 money = money_str ? atoi(money_str) : 0;
6575 if (money <= 0)
6576 return false;
6578 // msgSubject, msgText isn't NUL after prev. check
6579 std::string subject = msgSubject;
6580 std::string text = msgText;
6582 uint64 receiver_guid = objmgr.GetPlayerGUIDByName(name);
6583 if (!receiver_guid)
6585 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6586 SetSentErrorMessage(true);
6587 return false;
6590 // from console show not existed sender
6591 uint32 sender_guidlo = m_session ? m_session->GetPlayer()->GetGUIDLow() : 0;
6593 uint32 messagetype = MAIL_NORMAL;
6594 uint32 stationery = MAIL_STATIONERY_GM;
6595 uint32 itemTextId = !text.empty() ? objmgr.CreateItemText( text ) : 0;
6597 Player *receiver = objmgr.GetPlayer(receiver_guid);
6599 WorldSession::SendMailTo(receiver,messagetype, stationery, sender_guidlo, GUID_LOPART(receiver_guid), subject, itemTextId, NULL, money, 0, MAIL_CHECK_MASK_NONE);
6601 std::string nameLink = playerLink(name);
6602 PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
6603 return true;
6606 /// Send a message to a player in game
6607 bool ChatHandler::HandleSendMessageCommand(const char* args)
6609 ///- Get the command line arguments
6610 std::string name = extractPlayerNameFromLink((char*)args);
6611 if(name.empty())
6613 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6614 SetSentErrorMessage(true);
6615 return false;
6618 char* msg_str = strtok(NULL, "");
6619 if(!msg_str)
6620 return false;
6622 ///- Find the player and check that he is not logging out.
6623 Player *rPlayer = objmgr.GetPlayer(name.c_str());
6624 if(!rPlayer)
6626 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6627 SetSentErrorMessage(true);
6628 return false;
6631 if(rPlayer->GetSession()->isLogingOut())
6633 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6634 SetSentErrorMessage(true);
6635 return false;
6638 ///- Send the message
6639 //Use SendAreaTriggerMessage for fastest delivery.
6640 rPlayer->GetSession()->SendAreaTriggerMessage("%s", msg_str);
6641 rPlayer->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
6643 //Confirmation message
6644 std::string nameLink = playerLink(name);
6645 PSendSysMessage(LANG_SENDMESSAGE,nameLink.c_str(),msg_str);
6646 return true;
6649 bool ChatHandler::HandleFlushArenaPointsCommand(const char * /*args*/)
6651 sBattleGroundMgr.DistributeArenaPoints();
6652 return true;
6655 bool ChatHandler::HandleModifyGenderCommand(const char *args)
6657 if(!*args)
6658 return false;
6660 Player *player = getSelectedPlayer();
6662 if(!player)
6664 PSendSysMessage(LANG_NO_PLAYER);
6665 SetSentErrorMessage(true);
6666 return false;
6669 PlayerInfo const* info = objmgr.GetPlayerInfo(player->getRace(), player->getClass());
6670 if(!info)
6671 return false;
6673 char const* gender_str = (char*)args;
6674 int gender_len = strlen(gender_str);
6676 Gender gender;
6678 if(!strncmp(gender_str, "male", gender_len)) // MALE
6680 if(player->getGender() == GENDER_MALE)
6681 return true;
6683 gender = GENDER_MALE;
6685 else if (!strncmp(gender_str, "female", gender_len)) // FEMALE
6687 if(player->getGender() == GENDER_FEMALE)
6688 return true;
6690 gender = GENDER_FEMALE;
6692 else
6694 SendSysMessage(LANG_MUST_MALE_OR_FEMALE);
6695 SetSentErrorMessage(true);
6696 return false;
6699 // Set gender
6700 player->SetByteValue(UNIT_FIELD_BYTES_0, 2, gender);
6701 player->SetByteValue(PLAYER_BYTES_3, 0, gender);
6703 // Change display ID
6704 player->SetDisplayId(gender ? info->displayId_f : info->displayId_m);
6705 player->SetNativeDisplayId(gender ? info->displayId_f : info->displayId_m);
6707 char const* gender_full = gender ? "female" : "male";
6709 PSendSysMessage(LANG_YOU_CHANGE_GENDER, GetNameLink(player).c_str(), gender_full);
6711 if (needReportToTarget(player))
6712 ChatHandler(player).PSendSysMessage(LANG_YOUR_GENDER_CHANGED, gender_full, GetNameLink().c_str());
6714 return true;