Add lost .c_str() call at send std::string content to ".pdump write" command output.
[auctionmangos.git] / src / game / Level3.cpp
blobfbf235738afb1c0883e602be8b86a8aae4ac183e
1 /*
2 * Copyright (C) 2005-2008 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 "SpellAuras.h"
37 #include "ScriptCalls.h"
38 #include "Language.h"
39 #include "GridNotifiersImpl.h"
40 #include "CellImpl.h"
41 #include "Weather.h"
42 #include "PointMovementGenerator.h"
43 #include "TargetedMovementGenerator.h"
44 #include "SkillDiscovery.h"
45 #include "SkillExtraItems.h"
46 #include "SystemConfig.h"
47 #include "Config/ConfigEnv.h"
48 #include "Util.h"
49 #include "ItemEnchantmentMgr.h"
50 #include "InstanceSaveMgr.h"
51 #include "InstanceData.h"
52 #include "AccountMgr.h"
54 //reload commands
55 bool ChatHandler::HandleReloadCommand(const char* arg)
57 // this is error catcher for wrong table name in .reload commands
58 PSendSysMessage("Db table with name starting from '%s' not found and can't be reloaded.",arg);
59 SetSentErrorMessage(true);
60 return false;
63 bool ChatHandler::HandleReloadAllCommand(const char*)
65 HandleReloadAreaTriggerTeleportCommand("");
66 HandleReloadSkillFishingBaseLevelCommand("");
68 HandleReloadAllAreaCommand("");
69 HandleReloadAllLootCommand("");
70 HandleReloadAllNpcCommand("");
71 HandleReloadAllQuestCommand("");
72 HandleReloadAllSpellCommand("");
73 HandleReloadAllItemCommand("");
74 HandleReloadAllLocalesCommand("");
76 HandleReloadCommandCommand("");
77 HandleReloadReservedNameCommand("");
78 HandleReloadMangosStringCommand("");
79 HandleReloadGameTeleCommand("");
80 return true;
83 bool ChatHandler::HandleReloadAllAreaCommand(const char*)
85 //HandleReloadQuestAreaTriggersCommand(""); -- reloaded in HandleReloadAllQuestCommand
86 HandleReloadAreaTriggerTeleportCommand("");
87 HandleReloadAreaTriggerTavernCommand("");
88 HandleReloadGameGraveyardZoneCommand("");
89 return true;
92 bool ChatHandler::HandleReloadAllLootCommand(const char*)
94 sLog.outString( "Re-Loading Loot Tables..." );
95 LoadLootTables();
96 SendGlobalSysMessage("DB tables `*_loot_template` reloaded.");
97 return true;
100 bool ChatHandler::HandleReloadAllNpcCommand(const char* /*args*/)
102 HandleReloadNpcGossipCommand("a");
103 HandleReloadNpcTrainerCommand("a");
104 HandleReloadNpcVendorCommand("a");
105 return true;
108 bool ChatHandler::HandleReloadAllQuestCommand(const char* /*args*/)
110 HandleReloadQuestAreaTriggersCommand("a");
111 HandleReloadQuestTemplateCommand("a");
113 sLog.outString( "Re-Loading Quests Relations..." );
114 objmgr.LoadQuestRelations();
115 SendGlobalSysMessage("DB tables `*_questrelation` and `*_involvedrelation` reloaded.");
116 return true;
119 bool ChatHandler::HandleReloadAllScriptsCommand(const char*)
121 if(sWorld.IsScriptScheduled())
123 PSendSysMessage("DB scripts used currently, please attempt reload later.");
124 SetSentErrorMessage(true);
125 return false;
128 sLog.outString( "Re-Loading Scripts..." );
129 HandleReloadGameObjectScriptsCommand("a");
130 HandleReloadEventScriptsCommand("a");
131 HandleReloadQuestEndScriptsCommand("a");
132 HandleReloadQuestStartScriptsCommand("a");
133 HandleReloadSpellScriptsCommand("a");
134 SendGlobalSysMessage("DB tables `*_scripts` reloaded.");
135 return true;
138 bool ChatHandler::HandleReloadAllSpellCommand(const char*)
140 HandleReloadSkillDiscoveryTemplateCommand("a");
141 HandleReloadSkillExtraItemTemplateCommand("a");
142 HandleReloadSpellAffectCommand("a");
143 HandleReloadSpellChainCommand("a");
144 HandleReloadSpellElixirCommand("a");
145 HandleReloadSpellLearnSpellCommand("a");
146 HandleReloadSpellProcEventCommand("a");
147 HandleReloadSpellScriptTargetCommand("a");
148 HandleReloadSpellTargetPositionCommand("a");
149 HandleReloadSpellThreatsCommand("a");
150 HandleReloadSpellPetAurasCommand("a");
151 return true;
154 bool ChatHandler::HandleReloadAllItemCommand(const char*)
156 HandleReloadPageTextsCommand("a");
157 HandleReloadItemEnchantementsCommand("a");
158 return true;
161 bool ChatHandler::HandleReloadAllLocalesCommand(const char* args)
163 HandleReloadLocalesCreatureCommand("a");
164 HandleReloadLocalesGameobjectCommand("a");
165 HandleReloadLocalesItemCommand("a");
166 HandleReloadLocalesNpcTextCommand("a");
167 HandleReloadLocalesPageTextCommand("a");
168 HandleReloadLocalesQuestCommand("a");
169 return true;
172 bool ChatHandler::HandleReloadConfigCommand(const char* arg)
174 sLog.outString( "Re-Loading config settings..." );
175 sWorld.LoadConfigSettings(true);
176 SendGlobalSysMessage("World config settings reloaded.");
177 return true;
180 bool ChatHandler::HandleReloadAreaTriggerTavernCommand(const char*)
182 sLog.outString( "Re-Loading Tavern Area Triggers..." );
183 objmgr.LoadTavernAreaTriggers();
184 SendGlobalSysMessage("DB table `areatrigger_tavern` reloaded.");
185 return true;
188 bool ChatHandler::HandleReloadAreaTriggerTeleportCommand(const char*)
190 sLog.outString( "Re-Loading AreaTrigger teleport definitions..." );
191 objmgr.LoadAreaTriggerTeleports();
192 SendGlobalSysMessage("DB table `areatrigger_teleport` reloaded.");
193 return true;
196 bool ChatHandler::HandleReloadCommandCommand(const char*)
198 load_command_table = true;
199 SendGlobalSysMessage("DB table `command` will be reloaded at next chat command use.");
200 return true;
203 bool ChatHandler::HandleReloadCreatureQuestRelationsCommand(const char*)
205 sLog.outString( "Loading Quests Relations... (`creature_questrelation`)" );
206 objmgr.LoadCreatureQuestRelations();
207 SendGlobalSysMessage("DB table `creature_questrelation` (creature quest givers) reloaded.");
208 return true;
211 bool ChatHandler::HandleReloadCreatureQuestInvRelationsCommand(const char*)
213 sLog.outString( "Loading Quests Relations... (`creature_involvedrelation`)" );
214 objmgr.LoadCreatureInvolvedRelations();
215 SendGlobalSysMessage("DB table `creature_involvedrelation` (creature quest takers) reloaded.");
216 return true;
219 bool ChatHandler::HandleReloadGOQuestRelationsCommand(const char*)
221 sLog.outString( "Loading Quests Relations... (`gameobject_questrelation`)" );
222 objmgr.LoadGameobjectQuestRelations();
223 SendGlobalSysMessage("DB table `gameobject_questrelation` (gameobject quest givers) reloaded.");
224 return true;
227 bool ChatHandler::HandleReloadGOQuestInvRelationsCommand(const char*)
229 sLog.outString( "Loading Quests Relations... (`gameobject_involvedrelation`)" );
230 objmgr.LoadGameobjectInvolvedRelations();
231 SendGlobalSysMessage("DB table `gameobject_involvedrelation` (gameobject quest takers) reloaded.");
232 return true;
235 bool ChatHandler::HandleReloadQuestAreaTriggersCommand(const char*)
237 sLog.outString( "Re-Loading Quest Area Triggers..." );
238 objmgr.LoadQuestAreaTriggers();
239 SendGlobalSysMessage("DB table `areatrigger_involvedrelation` (quest area triggers) reloaded.");
240 return true;
243 bool ChatHandler::HandleReloadQuestTemplateCommand(const char*)
245 sLog.outString( "Re-Loading Quest Templates..." );
246 objmgr.LoadQuests();
247 SendGlobalSysMessage("DB table `quest_template` (quest definitions) reloaded.");
248 return true;
251 bool ChatHandler::HandleReloadLootTemplatesCreatureCommand(const char*)
253 sLog.outString( "Re-Loading Loot Tables... (`creature_loot_template`)" );
254 LoadLootTemplates_Creature();
255 LootTemplates_Creature.CheckLootRefs();
256 SendGlobalSysMessage("DB table `creature_loot_template` reloaded.");
257 return true;
260 bool ChatHandler::HandleReloadLootTemplatesDisenchantCommand(const char*)
262 sLog.outString( "Re-Loading Loot Tables... (`disenchant_loot_template`)" );
263 LoadLootTemplates_Disenchant();
264 LootTemplates_Disenchant.CheckLootRefs();
265 SendGlobalSysMessage("DB table `disenchant_loot_template` reloaded.");
266 return true;
269 bool ChatHandler::HandleReloadLootTemplatesFishingCommand(const char*)
271 sLog.outString( "Re-Loading Loot Tables... (`fishing_loot_template`)" );
272 LoadLootTemplates_Fishing();
273 LootTemplates_Fishing.CheckLootRefs();
274 SendGlobalSysMessage("DB table `fishing_loot_template` reloaded.");
275 return true;
278 bool ChatHandler::HandleReloadLootTemplatesGameobjectCommand(const char*)
280 sLog.outString( "Re-Loading Loot Tables... (`gameobject_loot_template`)" );
281 LoadLootTemplates_Gameobject();
282 LootTemplates_Gameobject.CheckLootRefs();
283 SendGlobalSysMessage("DB table `gameobject_loot_template` reloaded.");
284 return true;
287 bool ChatHandler::HandleReloadLootTemplatesItemCommand(const char*)
289 sLog.outString( "Re-Loading Loot Tables... (`item_loot_template`)" );
290 LoadLootTemplates_Item();
291 LootTemplates_Item.CheckLootRefs();
292 SendGlobalSysMessage("DB table `item_loot_template` reloaded.");
293 return true;
296 bool ChatHandler::HandleReloadLootTemplatesPickpocketingCommand(const char*)
298 sLog.outString( "Re-Loading Loot Tables... (`pickpocketing_loot_template`)" );
299 LoadLootTemplates_Pickpocketing();
300 LootTemplates_Pickpocketing.CheckLootRefs();
301 SendGlobalSysMessage("DB table `pickpocketing_loot_template` reloaded.");
302 return true;
305 bool ChatHandler::HandleReloadLootTemplatesProspectingCommand(const char*)
307 sLog.outString( "Re-Loading Loot Tables... (`prospecting_loot_template`)" );
308 LoadLootTemplates_Prospecting();
309 LootTemplates_Prospecting.CheckLootRefs();
310 SendGlobalSysMessage("DB table `prospecting_loot_template` reloaded.");
311 return true;
314 bool ChatHandler::HandleReloadLootTemplatesQuestMailCommand(const char*)
316 sLog.outString( "Re-Loading Loot Tables... (`quest_mail_loot_template`)" );
317 LoadLootTemplates_QuestMail();
318 LootTemplates_QuestMail.CheckLootRefs();
319 SendGlobalSysMessage("DB table `quest_mail_loot_template` reloaded.");
320 return true;
323 bool ChatHandler::HandleReloadLootTemplatesReferenceCommand(const char*)
325 sLog.outString( "Re-Loading Loot Tables... (`reference_loot_template`)" );
326 LoadLootTemplates_Reference();
327 SendGlobalSysMessage("DB table `reference_loot_template` reloaded.");
328 return true;
331 bool ChatHandler::HandleReloadLootTemplatesSkinningCommand(const char*)
333 sLog.outString( "Re-Loading Loot Tables... (`skinning_loot_template`)" );
334 LoadLootTemplates_Skinning();
335 LootTemplates_Skinning.CheckLootRefs();
336 SendGlobalSysMessage("DB table `skinning_loot_template` reloaded.");
337 return true;
340 bool ChatHandler::HandleReloadMangosStringCommand(const char*)
342 sLog.outString( "Re-Loading mangos_string Table!" );
343 objmgr.LoadMangosStrings();
344 SendGlobalSysMessage("DB table `mangos_string` reloaded.");
345 return true;
348 bool ChatHandler::HandleReloadNpcGossipCommand(const char*)
350 sLog.outString( "Re-Loading `npc_gossip` Table!" );
351 objmgr.LoadNpcTextId();
352 SendGlobalSysMessage("DB table `npc_gossip` reloaded.");
353 return true;
356 bool ChatHandler::HandleReloadNpcTrainerCommand(const char*)
358 sLog.outString( "Re-Loading `npc_trainer` Table!" );
359 objmgr.LoadTrainerSpell();
360 SendGlobalSysMessage("DB table `npc_trainer` reloaded.");
361 return true;
364 bool ChatHandler::HandleReloadNpcVendorCommand(const char*)
366 sLog.outString( "Re-Loading `npc_vendor` Table!" );
367 objmgr.LoadVendors();
368 SendGlobalSysMessage("DB table `npc_vendor` reloaded.");
369 return true;
372 bool ChatHandler::HandleReloadReservedNameCommand(const char*)
374 sLog.outString( "Loading ReservedNames... (`reserved_name`)" );
375 objmgr.LoadReservedPlayersNames();
376 SendGlobalSysMessage("DB table `reserved_name` (player reserved names) reloaded.");
377 return true;
380 bool ChatHandler::HandleReloadSkillDiscoveryTemplateCommand(const char* /*args*/)
382 sLog.outString( "Re-Loading Skill Discovery Table..." );
383 LoadSkillDiscoveryTable();
384 SendGlobalSysMessage("DB table `skill_discovery_template` (recipes discovered at crafting) reloaded.");
385 return true;
388 bool ChatHandler::HandleReloadSkillExtraItemTemplateCommand(const char* /*args*/)
390 sLog.outString( "Re-Loading Skill Extra Item Table..." );
391 LoadSkillExtraItemTable();
392 SendGlobalSysMessage("DB table `skill_extra_item_template` (extra item creation when crafting) reloaded.");
393 return true;
396 bool ChatHandler::HandleReloadSkillFishingBaseLevelCommand(const char* /*args*/)
398 sLog.outString( "Re-Loading Skill Fishing base level requirements..." );
399 objmgr.LoadFishingBaseSkillLevel();
400 SendGlobalSysMessage("DB table `skill_fishing_base_level` (fishing base level for zone/subzone) reloaded.");
401 return true;
404 bool ChatHandler::HandleReloadSpellAffectCommand(const char*)
406 sLog.outString( "Re-Loading SpellAffect definitions..." );
407 spellmgr.LoadSpellAffects();
408 SendGlobalSysMessage("DB table `spell_affect` (spell mods apply requirements) reloaded.");
409 return true;
412 bool ChatHandler::HandleReloadSpellChainCommand(const char*)
414 sLog.outString( "Re-Loading Spell Chain Data... " );
415 spellmgr.LoadSpellChains();
416 SendGlobalSysMessage("DB table `spell_chain` (spell ranks) reloaded.");
417 return true;
420 bool ChatHandler::HandleReloadSpellElixirCommand(const char*)
422 sLog.outString( "Re-Loading Spell Elixir types..." );
423 spellmgr.LoadSpellElixirs();
424 SendGlobalSysMessage("DB table `spell_elixir` (spell exlixir types) reloaded.");
425 return true;
428 bool ChatHandler::HandleReloadSpellLearnSpellCommand(const char*)
430 sLog.outString( "Re-Loading Spell Learn Spells..." );
431 spellmgr.LoadSpellLearnSpells();
432 SendGlobalSysMessage("DB table `spell_learn_spell` reloaded.");
433 return true;
436 bool ChatHandler::HandleReloadSpellProcEventCommand(const char*)
438 sLog.outString( "Re-Loading Spell Proc Event conditions..." );
439 spellmgr.LoadSpellProcEvents();
440 SendGlobalSysMessage("DB table `spell_proc_event` (spell proc trigger requirements) reloaded.");
441 return true;
444 bool ChatHandler::HandleReloadSpellScriptTargetCommand(const char*)
446 sLog.outString( "Re-Loading SpellsScriptTarget..." );
447 spellmgr.LoadSpellScriptTarget();
448 SendGlobalSysMessage("DB table `spell_script_target` (spell targets selection in case specific creature/GO requirements) reloaded.");
449 return true;
452 bool ChatHandler::HandleReloadSpellTargetPositionCommand(const char*)
454 sLog.outString( "Re-Loading Spell target coordinates..." );
455 spellmgr.LoadSpellTargetPositions();
456 SendGlobalSysMessage("DB table `spell_target_position` (destination coordinates for spell targets) reloaded.");
457 return true;
460 bool ChatHandler::HandleReloadSpellThreatsCommand(const char*)
462 sLog.outString( "Re-Loading Aggro Spells Definitions...");
463 spellmgr.LoadSpellThreats();
464 SendGlobalSysMessage("DB table `spell_threat` (spell aggro definitions) reloaded.");
465 return true;
468 bool ChatHandler::HandleReloadSpellPetAurasCommand(const char*)
470 sLog.outString( "Re-Loading Spell pet auras...");
471 spellmgr.LoadSpellPetAuras();
472 SendGlobalSysMessage("DB table `spell_pet_auras` reloaded.");
473 return true;
476 bool ChatHandler::HandleReloadPageTextsCommand(const char*)
478 sLog.outString( "Re-Loading Page Texts..." );
479 objmgr.LoadPageTexts();
480 SendGlobalSysMessage("DB table `page_texts` reloaded.");
481 return true;
484 bool ChatHandler::HandleReloadItemEnchantementsCommand(const char*)
486 sLog.outString( "Re-Loading Item Random Enchantments Table..." );
487 LoadRandomEnchantmentsTable();
488 SendGlobalSysMessage("DB table `item_enchantment_template` reloaded.");
489 return true;
492 bool ChatHandler::HandleReloadGameObjectScriptsCommand(const char* arg)
494 if(sWorld.IsScriptScheduled())
496 SendSysMessage("DB scripts used currently, please attempt reload later.");
497 SetSentErrorMessage(true);
498 return false;
501 if(*arg!='a')
502 sLog.outString( "Re-Loading Scripts from `gameobject_scripts`...");
504 objmgr.LoadGameObjectScripts();
506 if(*arg!='a')
507 SendGlobalSysMessage("DB table `gameobject_scripts` reloaded.");
509 return true;
512 bool ChatHandler::HandleReloadEventScriptsCommand(const char* arg)
514 if(sWorld.IsScriptScheduled())
516 SendSysMessage("DB scripts used currently, please attempt reload later.");
517 SetSentErrorMessage(true);
518 return false;
521 if(*arg!='a')
522 sLog.outString( "Re-Loading Scripts from `event_scripts`...");
524 objmgr.LoadEventScripts();
526 if(*arg!='a')
527 SendGlobalSysMessage("DB table `event_scripts` reloaded.");
529 return true;
532 bool ChatHandler::HandleReloadQuestEndScriptsCommand(const char* arg)
534 if(sWorld.IsScriptScheduled())
536 SendSysMessage("DB scripts used currently, please attempt reload later.");
537 SetSentErrorMessage(true);
538 return false;
541 if(*arg!='a')
542 sLog.outString( "Re-Loading Scripts from `quest_end_scripts`...");
544 objmgr.LoadQuestEndScripts();
546 if(*arg!='a')
547 SendGlobalSysMessage("DB table `quest_end_scripts` reloaded.");
549 return true;
552 bool ChatHandler::HandleReloadQuestStartScriptsCommand(const char* arg)
554 if(sWorld.IsScriptScheduled())
556 SendSysMessage("DB scripts used currently, please attempt reload later.");
557 SetSentErrorMessage(true);
558 return false;
561 if(*arg!='a')
562 sLog.outString( "Re-Loading Scripts from `quest_start_scripts`...");
564 objmgr.LoadQuestStartScripts();
566 if(*arg!='a')
567 SendGlobalSysMessage("DB table `quest_start_scripts` reloaded.");
569 return true;
572 bool ChatHandler::HandleReloadSpellScriptsCommand(const char* arg)
574 if(sWorld.IsScriptScheduled())
576 SendSysMessage("DB scripts used currently, please attempt reload later.");
577 SetSentErrorMessage(true);
578 return false;
581 if(*arg!='a')
582 sLog.outString( "Re-Loading Scripts from `spell_scripts`...");
584 objmgr.LoadSpellScripts();
586 if(*arg!='a')
587 SendGlobalSysMessage("DB table `spell_scripts` reloaded.");
589 return true;
592 bool ChatHandler::HandleReloadGameGraveyardZoneCommand(const char* /*arg*/)
594 sLog.outString( "Re-Loading Graveyard-zone links...");
596 objmgr.LoadGraveyardZones();
598 SendGlobalSysMessage("DB table `game_graveyard_zone` reloaded.");
600 return true;
603 bool ChatHandler::HandleReloadGameTeleCommand(const char* /*arg*/)
605 sLog.outString( "Re-Loading Game Tele coordinates...");
607 objmgr.LoadGameTele();
609 SendGlobalSysMessage("DB table `game_tele` reloaded.");
611 return true;
614 bool ChatHandler::HandleReloadLocalesCreatureCommand(const char* /*arg*/)
616 sLog.outString( "Re-Loading Locales Creature ...");
617 objmgr.LoadCreatureLocales();
618 SendGlobalSysMessage("DB table `locales_creature` reloaded.");
619 return true;
622 bool ChatHandler::HandleReloadLocalesGameobjectCommand(const char* /*arg*/)
624 sLog.outString( "Re-Loading Locales Gameobject ... ");
625 objmgr.LoadGameObjectLocales();
626 SendGlobalSysMessage("DB table `locales_gameobject` reloaded.");
627 return true;
630 bool ChatHandler::HandleReloadLocalesItemCommand(const char* /*arg*/)
632 sLog.outString( "Re-Loading Locales Item ... ");
633 objmgr.LoadItemLocales();
634 SendGlobalSysMessage("DB table `locales_item` reloaded.");
635 return true;
638 bool ChatHandler::HandleReloadLocalesNpcTextCommand(const char* /*arg*/)
640 sLog.outString( "Re-Loading Locales NPC Text ... ");
641 objmgr.LoadNpcTextLocales();
642 SendGlobalSysMessage("DB table `locales_npc_text` reloaded.");
643 return true;
646 bool ChatHandler::HandleReloadLocalesPageTextCommand(const char* /*arg*/)
648 sLog.outString( "Re-Loading Locales Page Text ... ");
649 objmgr.LoadPageTextLocales();
650 SendGlobalSysMessage("DB table `locales_page_text` reloaded.");
651 return true;
654 bool ChatHandler::HandleReloadLocalesQuestCommand(const char* /*arg*/)
656 sLog.outString( "Re-Loading Locales Quest ... ");
657 objmgr.LoadQuestLocales();
658 SendGlobalSysMessage("DB table `locales_quest` reloaded.");
659 return true;
662 bool ChatHandler::HandleLoadScriptsCommand(const char* args)
664 if(!LoadScriptingModule(args)) return true;
666 sWorld.SendWorldText(LANG_SCRIPTS_RELOADED);
667 return true;
670 bool ChatHandler::HandleAccountSetGmLevelCommand(const char* args)
672 char* arg1 = strtok((char*)args, " ");
673 if( !arg1 )
674 return false;
676 char* arg2 = strtok(NULL, " ");
678 std::string targetAccountName;
679 uint32 targetAccountId = 0;
680 uint32 targetSecurity = 0;
682 /// only target player different from self allowed (if targetPlayer!=NULL then not console)
683 Player* targetPlayer = getSelectedPlayer();
684 if(targetPlayer && m_session->GetPlayer()!=targetPlayer)
686 /// wrong command syntax or unexpected targeting
687 if(arg2)
688 return false;
690 targetAccountId = targetPlayer->GetSession()->GetAccountId();
691 targetSecurity = targetPlayer->GetSession()->GetSecurity();
692 if(!accmgr.GetName(targetAccountId,targetAccountName))
694 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,targetAccountName.c_str());
695 SetSentErrorMessage(true);
696 return false;
699 else
701 targetAccountName = arg1;
702 if(!AccountMgr::normilizeString(targetAccountName))
704 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,targetAccountName.c_str());
705 SetSentErrorMessage(true);
706 return false;
709 targetAccountId = accmgr.GetId(targetAccountName);
710 targetSecurity = accmgr.GetSecurity(targetAccountId);
713 int32 gm = (int32)atoi(arg2);
714 if ( gm < SEC_PLAYER || gm > SEC_ADMINISTRATOR )
716 SendSysMessage(LANG_BAD_VALUE);
717 SetSentErrorMessage(true);
718 return false;
721 /// m_session==NULL only for console
722 uint32 plSecurity = m_session ? m_session->GetSecurity() : SEC_CONSOLE;
724 /// can set security level only for target with less security and to less security that we have
725 /// This is also reject self apply in fact
726 if(targetSecurity >= plSecurity || uint32(gm) >= plSecurity )
728 SendSysMessage(LANG_YOURS_SECURITY_IS_LOW);
729 SetSentErrorMessage(true);
730 return false;
733 if(targetPlayer)
735 ChatHandler(targetPlayer).PSendSysMessage(LANG_YOURS_SECURITY_CHANGED,m_session->GetPlayer()->GetName(), gm);
736 targetPlayer->GetSession()->SetSecurity(gm);
739 PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetAccountName.c_str(), gm);
740 loginDatabase.PExecute("UPDATE account SET gmlevel = '%i' WHERE id = '%u'", gm, targetAccountId);
742 return true;
745 /// Set password for account
746 bool ChatHandler::HandleAccountSetPasswordCommand(const char* args)
748 if(!*args)
749 return false;
751 ///- Get the command line arguments
752 char *szAccount = strtok ((char*)args," ");
753 char *szPassword1 = strtok (NULL," ");
754 char *szPassword2 = strtok (NULL," ");
756 if (!szAccount||!szPassword1 || !szPassword2)
757 return false;
759 std::string account_name = szAccount;
760 if(!AccountMgr::normilizeString(account_name))
762 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
763 SetSentErrorMessage(true);
764 return false;
767 uint32 targetAccountId = accmgr.GetId(account_name);
768 if (!targetAccountId)
770 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
771 SetSentErrorMessage(true);
772 return false;
775 uint32 targetSecurity = accmgr.GetSecurity(targetAccountId);
777 /// m_session==NULL only for console
778 uint32 plSecurity = m_session ? m_session->GetSecurity() : SEC_CONSOLE;
780 /// can set password only for target with less security
781 /// This is also reject self apply in fact
782 if (targetSecurity >= plSecurity)
784 SendSysMessage (LANG_YOURS_SECURITY_IS_LOW);
785 SetSentErrorMessage (true);
786 return false;
789 if (strcmp(szPassword1,szPassword2))
791 SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH);
792 SetSentErrorMessage (true);
793 return false;
796 AccountOpResult result = accmgr.ChangePassword(targetAccountId, szPassword1);
798 switch(result)
800 case AOR_OK:
801 SendSysMessage(LANG_COMMAND_PASSWORD);
802 break;
803 case AOR_NAME_NOT_EXIST:
804 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
805 SetSentErrorMessage(true);
806 return false;
807 case AOR_PASS_TOO_LONG:
808 SendSysMessage(LANG_PASSWORD_TOO_LONG);
809 SetSentErrorMessage(true);
810 return false;
811 default:
812 SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD);
813 SetSentErrorMessage(true);
814 return false;
817 return true;
820 bool ChatHandler::HandleAllowMovementCommand(const char* /*args*/)
822 if(sWorld.getAllowMovement())
824 sWorld.SetAllowMovement(false);
825 SendSysMessage(LANG_CREATURE_MOVE_DISABLED);
827 else
829 sWorld.SetAllowMovement(true);
830 SendSysMessage(LANG_CREATURE_MOVE_ENABLED);
832 return true;
835 bool ChatHandler::HandleMaxSkillCommand(const char* /*args*/)
837 Player* SelectedPlayer = getSelectedPlayer();
838 if(!SelectedPlayer)
840 SendSysMessage(LANG_NO_CHAR_SELECTED);
841 SetSentErrorMessage(true);
842 return false;
845 // each skills that have max skill value dependent from level seted to current level max skill value
846 SelectedPlayer->UpdateSkillsToMaxSkillsForLevel();
847 return true;
850 bool ChatHandler::HandleSetSkillCommand(const char* args)
852 // number or [name] Shift-click form |color|Hskill:skill_id|h[name]|h|r
853 char* skill_p = extractKeyFromLink((char*)args,"Hskill");
854 if(!skill_p)
855 return false;
857 char *level_p = strtok (NULL, " ");
859 if( !level_p)
860 return false;
862 char *max_p = strtok (NULL, " ");
864 int32 skill = atoi(skill_p);
866 if (skill <= 0)
868 PSendSysMessage(LANG_INVALID_SKILL_ID, skill);
869 SetSentErrorMessage(true);
870 return false;
873 int32 level = atol (level_p);
875 Player * target = getSelectedPlayer();
876 if(!target)
878 SendSysMessage(LANG_NO_CHAR_SELECTED);
879 SetSentErrorMessage(true);
880 return false;
883 SkillLineEntry const* sl = sSkillLineStore.LookupEntry(skill);
884 if(!sl)
886 PSendSysMessage(LANG_INVALID_SKILL_ID, skill);
887 SetSentErrorMessage(true);
888 return false;
891 if(!target->GetSkillValue(skill))
893 PSendSysMessage(LANG_SET_SKILL_ERROR, target->GetName(), skill, sl->name[0]);
894 SetSentErrorMessage(true);
895 return false;
898 int32 max = max_p ? atol (max_p) : target->GetPureMaxSkillValue(skill);
900 if( level <= 0 || level > max || max <= 0 )
901 return false;
903 target->SetSkill(skill, level, max);
904 PSendSysMessage(LANG_SET_SKILL, skill, sl->name[0], target->GetName(), level, max);
906 return true;
909 bool ChatHandler::HandleUnLearnCommand(const char* args)
911 if (!*args)
912 return false;
914 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
915 uint32 min_id = extractSpellIdFromLink((char*)args);
916 if(!min_id)
917 return false;
919 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
920 char* tail = strtok(NULL,"");
922 uint32 max_id = extractSpellIdFromLink(tail);
924 if (!max_id)
926 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
927 max_id = min_id+1;
929 else
931 if (max_id < min_id)
932 std::swap(min_id,max_id);
934 max_id=max_id+1;
937 Player* target = getSelectedPlayer();
938 if(!target)
940 SendSysMessage(LANG_NO_CHAR_SELECTED);
941 SetSentErrorMessage(true);
942 return false;
945 for(uint32 spell=min_id;spell<max_id;spell++)
947 if (target->HasSpell(spell))
948 target->removeSpell(spell);
949 else
950 SendSysMessage(LANG_FORGET_SPELL);
953 return true;
956 bool ChatHandler::HandleCooldownCommand(const char* args)
958 Player* target = getSelectedPlayer();
959 if(!target)
961 SendSysMessage(LANG_PLAYER_NOT_FOUND);
962 SetSentErrorMessage(true);
963 return false;
966 if (!*args)
968 target->RemoveAllSpellCooldown();
969 PSendSysMessage(LANG_REMOVEALL_COOLDOWN, target->GetName());
971 else
973 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
974 uint32 spell_id = extractSpellIdFromLink((char*)args);
975 if(!spell_id)
976 return false;
978 if(!sSpellStore.LookupEntry(spell_id))
980 PSendSysMessage(LANG_UNKNOWN_SPELL, target==m_session->GetPlayer() ? GetMangosString(LANG_YOU) : target->GetName());
981 SetSentErrorMessage(true);
982 return false;
985 WorldPacket data( SMSG_CLEAR_COOLDOWN, (4+8) );
986 data << uint32(spell_id);
987 data << uint64(target->GetGUID());
988 target->GetSession()->SendPacket(&data);
989 target->RemoveSpellCooldown(spell_id);
990 PSendSysMessage(LANG_REMOVE_COOLDOWN, spell_id, target==m_session->GetPlayer() ? GetMangosString(LANG_YOU) : target->GetName());
992 return true;
995 bool ChatHandler::HandleLearnAllCommand(const char* /*args*/)
997 static const char *allSpellList[] =
999 "3365",
1000 "6233",
1001 "6247",
1002 "6246",
1003 "6477",
1004 "6478",
1005 "22810",
1006 "8386",
1007 "21651",
1008 "21652",
1009 "522",
1010 "7266",
1011 "8597",
1012 "2479",
1013 "22027",
1014 "6603",
1015 "5019",
1016 "133",
1017 "168",
1018 "227",
1019 "5009",
1020 "9078",
1021 "668",
1022 "203",
1023 "20599",
1024 "20600",
1025 "81",
1026 "20597",
1027 "20598",
1028 "20864",
1029 "1459",
1030 "5504",
1031 "587",
1032 "5143",
1033 "118",
1034 "5505",
1035 "597",
1036 "604",
1037 "1449",
1038 "1460",
1039 "2855",
1040 "1008",
1041 "475",
1042 "5506",
1043 "1463",
1044 "12824",
1045 "8437",
1046 "990",
1047 "5145",
1048 "8450",
1049 "1461",
1050 "759",
1051 "8494",
1052 "8455",
1053 "8438",
1054 "6127",
1055 "8416",
1056 "6129",
1057 "8451",
1058 "8495",
1059 "8439",
1060 "3552",
1061 "8417",
1062 "10138",
1063 "12825",
1064 "10169",
1065 "10156",
1066 "10144",
1067 "10191",
1068 "10201",
1069 "10211",
1070 "10053",
1071 "10173",
1072 "10139",
1073 "10145",
1074 "10192",
1075 "10170",
1076 "10202",
1077 "10054",
1078 "10174",
1079 "10193",
1080 "12826",
1081 "2136",
1082 "143",
1083 "145",
1084 "2137",
1085 "2120",
1086 "3140",
1087 "543",
1088 "2138",
1089 "2948",
1090 "8400",
1091 "2121",
1092 "8444",
1093 "8412",
1094 "8457",
1095 "8401",
1096 "8422",
1097 "8445",
1098 "8402",
1099 "8413",
1100 "8458",
1101 "8423",
1102 "8446",
1103 "10148",
1104 "10197",
1105 "10205",
1106 "10149",
1107 "10215",
1108 "10223",
1109 "10206",
1110 "10199",
1111 "10150",
1112 "10216",
1113 "10207",
1114 "10225",
1115 "10151",
1116 "116",
1117 "205",
1118 "7300",
1119 "122",
1120 "837",
1121 "10",
1122 "7301",
1123 "7322",
1124 "6143",
1125 "120",
1126 "865",
1127 "8406",
1128 "6141",
1129 "7302",
1130 "8461",
1131 "8407",
1132 "8492",
1133 "8427",
1134 "8408",
1135 "6131",
1136 "7320",
1137 "10159",
1138 "8462",
1139 "10185",
1140 "10179",
1141 "10160",
1142 "10180",
1143 "10219",
1144 "10186",
1145 "10177",
1146 "10230",
1147 "10181",
1148 "10161",
1149 "10187",
1150 "10220",
1151 "2018",
1152 "2663",
1153 "12260",
1154 "2660",
1155 "3115",
1156 "3326",
1157 "2665",
1158 "3116",
1159 "2738",
1160 "3293",
1161 "2661",
1162 "3319",
1163 "2662",
1164 "9983",
1165 "8880",
1166 "2737",
1167 "2739",
1168 "7408",
1169 "3320",
1170 "2666",
1171 "3323",
1172 "3324",
1173 "3294",
1174 "22723",
1175 "23219",
1176 "23220",
1177 "23221",
1178 "23228",
1179 "23338",
1180 "10788",
1181 "10790",
1182 "5611",
1183 "5016",
1184 "5609",
1185 "2060",
1186 "10963",
1187 "10964",
1188 "10965",
1189 "22593",
1190 "22594",
1191 "596",
1192 "996",
1193 "499",
1194 "768",
1195 "17002",
1196 "1448",
1197 "1082",
1198 "16979",
1199 "1079",
1200 "5215",
1201 "20484",
1202 "5221",
1203 "15590",
1204 "17007",
1205 "6795",
1206 "6807",
1207 "5487",
1208 "1446",
1209 "1066",
1210 "5421",
1211 "3139",
1212 "779",
1213 "6811",
1214 "6808",
1215 "1445",
1216 "5216",
1217 "1737",
1218 "5222",
1219 "5217",
1220 "1432",
1221 "6812",
1222 "9492",
1223 "5210",
1224 "3030",
1225 "1441",
1226 "783",
1227 "6801",
1228 "20739",
1229 "8944",
1230 "9491",
1231 "22569",
1232 "5226",
1233 "6786",
1234 "1433",
1235 "8973",
1236 "1828",
1237 "9495",
1238 "9006",
1239 "6794",
1240 "8993",
1241 "5203",
1242 "16914",
1243 "6784",
1244 "9635",
1245 "22830",
1246 "20722",
1247 "9748",
1248 "6790",
1249 "9753",
1250 "9493",
1251 "9752",
1252 "9831",
1253 "9825",
1254 "9822",
1255 "5204",
1256 "5401",
1257 "22831",
1258 "6793",
1259 "9845",
1260 "17401",
1261 "9882",
1262 "9868",
1263 "20749",
1264 "9893",
1265 "9899",
1266 "9895",
1267 "9832",
1268 "9902",
1269 "9909",
1270 "22832",
1271 "9828",
1272 "9851",
1273 "9883",
1274 "9869",
1275 "17406",
1276 "17402",
1277 "9914",
1278 "20750",
1279 "9897",
1280 "9848",
1281 "3127",
1282 "107",
1283 "204",
1284 "9116",
1285 "2457",
1286 "78",
1287 "18848",
1288 "331",
1289 "403",
1290 "2098",
1291 "1752",
1292 "11278",
1293 "11288",
1294 "11284",
1295 "6461",
1296 "2344",
1297 "2345",
1298 "6463",
1299 "2346",
1300 "2352",
1301 "775",
1302 "1434",
1303 "1612",
1304 "71",
1305 "2468",
1306 "2458",
1307 "2467",
1308 "7164",
1309 "7178",
1310 "7367",
1311 "7376",
1312 "7381",
1313 "21156",
1314 "5209",
1315 "3029",
1316 "5201",
1317 "9849",
1318 "9850",
1319 "20719",
1320 "22568",
1321 "22827",
1322 "22828",
1323 "22829",
1324 "6809",
1325 "8972",
1326 "9005",
1327 "9823",
1328 "9827",
1329 "6783",
1330 "9913",
1331 "6785",
1332 "6787",
1333 "9866",
1334 "9867",
1335 "9894",
1336 "9896",
1337 "6800",
1338 "8992",
1339 "9829",
1340 "9830",
1341 "780",
1342 "769",
1343 "6749",
1344 "6750",
1345 "9755",
1346 "9754",
1347 "9908",
1348 "20745",
1349 "20742",
1350 "20747",
1351 "20748",
1352 "9746",
1353 "9745",
1354 "9880",
1355 "9881",
1356 "5391",
1357 "842",
1358 "3025",
1359 "3031",
1360 "3287",
1361 "3329",
1362 "1945",
1363 "3559",
1364 "4933",
1365 "4934",
1366 "4935",
1367 "4936",
1368 "5142",
1369 "5390",
1370 "5392",
1371 "5404",
1372 "5420",
1373 "6405",
1374 "7293",
1375 "7965",
1376 "8041",
1377 "8153",
1378 "9033",
1379 "9034",
1380 //"9036", problems with ghost state
1381 "16421",
1382 "21653",
1383 "22660",
1384 "5225",
1385 "9846",
1386 "2426",
1387 "5916",
1388 "6634",
1389 //"6718", phasing stealth, annoing for learn all case.
1390 "6719",
1391 "8822",
1392 "9591",
1393 "9590",
1394 "10032",
1395 "17746",
1396 "17747",
1397 "8203",
1398 "11392",
1399 "12495",
1400 "16380",
1401 "23452",
1402 "4079",
1403 "4996",
1404 "4997",
1405 "4998",
1406 "4999",
1407 "5000",
1408 "6348",
1409 "6349",
1410 "6481",
1411 "6482",
1412 "6483",
1413 "6484",
1414 "11362",
1415 "11410",
1416 "11409",
1417 "12510",
1418 "12509",
1419 "12885",
1420 "13142",
1421 "21463",
1422 "23460",
1423 "11421",
1424 "11416",
1425 "11418",
1426 "1851",
1427 "10059",
1428 "11423",
1429 "11417",
1430 "11422",
1431 "11419",
1432 "11424",
1433 "11420",
1434 "27",
1435 "31",
1436 "33",
1437 "34",
1438 "35",
1439 "15125",
1440 "21127",
1441 "22950",
1442 "1180",
1443 "201",
1444 "12593",
1445 "12842",
1446 "16770",
1447 "6057",
1448 "12051",
1449 "18468",
1450 "12606",
1451 "12605",
1452 "18466",
1453 "12502",
1454 "12043",
1455 "15060",
1456 "12042",
1457 "12341",
1458 "12848",
1459 "12344",
1460 "12353",
1461 "18460",
1462 "11366",
1463 "12350",
1464 "12352",
1465 "13043",
1466 "11368",
1467 "11113",
1468 "12400",
1469 "11129",
1470 "16766",
1471 "12573",
1472 "15053",
1473 "12580",
1474 "12475",
1475 "12472",
1476 "12953",
1477 "12488",
1478 "11189",
1479 "12985",
1480 "12519",
1481 "16758",
1482 "11958",
1483 "12490",
1484 "11426",
1485 "3565",
1486 "3562",
1487 "18960",
1488 "3567",
1489 "3561",
1490 "3566",
1491 "3563",
1492 "1953",
1493 "2139",
1494 "12505",
1495 "13018",
1496 "12522",
1497 "12523",
1498 "5146",
1499 "5144",
1500 "5148",
1501 "8419",
1502 "8418",
1503 "10213",
1504 "10212",
1505 "10157",
1506 "12524",
1507 "13019",
1508 "12525",
1509 "13020",
1510 "12526",
1511 "13021",
1512 "18809",
1513 "13031",
1514 "13032",
1515 "13033",
1516 "4036",
1517 "3920",
1518 "3919",
1519 "3918",
1520 "7430",
1521 "3922",
1522 "3923",
1523 "7411",
1524 "7418",
1525 "7421",
1526 "13262",
1527 "7412",
1528 "7415",
1529 "7413",
1530 "7416",
1531 "13920",
1532 "13921",
1533 "7745",
1534 "7779",
1535 "7428",
1536 "7457",
1537 "7857",
1538 "7748",
1539 "7426",
1540 "13421",
1541 "7454",
1542 "13378",
1543 "7788",
1544 "14807",
1545 "14293",
1546 "7795",
1547 "6296",
1548 "20608",
1549 "755",
1550 "444",
1551 "427",
1552 "428",
1553 "442",
1554 "447",
1555 "3578",
1556 "3581",
1557 "19027",
1558 "3580",
1559 "665",
1560 "3579",
1561 "3577",
1562 "6755",
1563 "3576",
1564 "2575",
1565 "2577",
1566 "2578",
1567 "2579",
1568 "2580",
1569 "2656",
1570 "2657",
1571 "2576",
1572 "3564",
1573 "10248",
1574 "8388",
1575 "2659",
1576 "14891",
1577 "3308",
1578 "3307",
1579 "10097",
1580 "2658",
1581 "3569",
1582 "16153",
1583 "3304",
1584 "10098",
1585 "4037",
1586 "3929",
1587 "3931",
1588 "3926",
1589 "3924",
1590 "3930",
1591 "3977",
1592 "3925",
1593 "136",
1594 "228",
1595 "5487",
1596 "43",
1597 "202",
1601 int loop = 0;
1602 while(strcmp(allSpellList[loop], "0"))
1604 uint32 spell = atol((char*)allSpellList[loop++]);
1606 if (m_session->GetPlayer()->HasSpell(spell))
1607 continue;
1609 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
1610 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
1612 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
1613 continue;
1616 m_session->GetPlayer()->learnSpell(spell);
1619 SendSysMessage(LANG_COMMAND_LEARN_MANY_SPELLS);
1621 return true;
1624 bool ChatHandler::HandleLearnAllGMCommand(const char* /*args*/)
1626 static const char *gmSpellList[] =
1628 "24347", // Become A Fish, No Breath Bar
1629 "35132", // Visual Boom
1630 "38488", // Attack 4000-8000 AOE
1631 "38795", // Attack 2000 AOE + Slow Down 90%
1632 "15712", // Attack 200
1633 "1852", // GM Spell Silence
1634 "31899", // Kill
1635 "31924", // Kill
1636 "29878", // Kill My Self
1637 "26644", // More Kill
1639 "28550", //Invisible 24
1640 "23452", //Invisible + Target
1644 uint16 gmSpellIter = 0;
1645 while( strcmp(gmSpellList[gmSpellIter], "0") )
1647 uint32 spell = atol((char*)gmSpellList[gmSpellIter++]);
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);
1659 SendSysMessage(LANG_LEARNING_GM_SKILLS);
1660 return true;
1663 bool ChatHandler::HandleLearnAllMyClassCommand(const char* /*args*/)
1665 HandleLearnAllMySpellsCommand("");
1666 HandleLearnAllMyTalentsCommand("");
1667 return true;
1670 bool ChatHandler::HandleLearnAllMySpellsCommand(const char* /*args*/)
1672 ChrClassesEntry const* clsEntry = sChrClassesStore.LookupEntry(m_session->GetPlayer()->getClass());
1673 if(!clsEntry)
1674 return true;
1675 uint32 family = clsEntry->spellfamily;
1677 for (uint32 i = 0; i < sSpellStore.GetNumRows(); i++)
1679 SpellEntry const *spellInfo = sSpellStore.LookupEntry(i);
1680 if(!spellInfo)
1681 continue;
1683 // skip wrong class/race skills
1684 if(!m_session->GetPlayer()->IsSpellFitByClassAndRace(spellInfo->Id))
1685 continue;
1687 // skip other spell families
1688 if( spellInfo->SpellFamilyName != family)
1689 continue;
1691 //TODO: skip triggered spells
1693 // skip spells with first rank learned as talent (and all talents then also)
1694 uint32 first_rank = spellmgr.GetFirstSpellInChain(spellInfo->Id);
1695 if(GetTalentSpellCost(first_rank) > 0 )
1696 continue;
1698 // skip broken spells
1699 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
1700 continue;
1702 m_session->GetPlayer()->learnSpell(i);
1705 SendSysMessage(LANG_COMMAND_LEARN_CLASS_SPELLS);
1706 return true;
1709 static void learnAllHighRanks(Player* player, uint32 spellid)
1711 SpellChainMapNext const& nextMap = spellmgr.GetSpellChainNext();
1712 for(SpellChainMapNext::const_iterator itr = nextMap.lower_bound(spellid); itr != nextMap.upper_bound(spellid); ++itr)
1714 player->learnSpell(itr->second);
1715 learnAllHighRanks(player,itr->second);
1719 bool ChatHandler::HandleLearnAllMyTalentsCommand(const char* /*args*/)
1721 Player* player = m_session->GetPlayer();
1722 uint32 classMask = player->getClassMask();
1724 for (uint32 i = 0; i < sTalentStore.GetNumRows(); i++)
1726 TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
1727 if(!talentInfo)
1728 continue;
1730 TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentInfo->TalentTab );
1731 if(!talentTabInfo)
1732 continue;
1734 if( (classMask & talentTabInfo->ClassMask) == 0 )
1735 continue;
1737 // search highest talent rank
1738 uint32 spellid = 0;
1739 int rank = 4;
1740 for(; rank >= 0; --rank)
1742 if(talentInfo->RankID[rank]!=0)
1744 spellid = talentInfo->RankID[rank];
1745 break;
1749 if(!spellid) // ??? none spells in telent
1750 continue;
1752 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellid);
1753 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
1754 continue;
1756 // learn highest rank of talent
1757 player->learnSpell(spellid);
1759 // and learn all non-talent spell ranks (recursive by tree)
1760 learnAllHighRanks(player,spellid);
1763 SendSysMessage(LANG_COMMAND_LEARN_CLASS_TALENTS);
1764 return true;
1767 bool ChatHandler::HandleLearnAllLangCommand(const char* /*args*/)
1769 // skipping UNIVERSAL language (0)
1770 for(int i = 1; i < LANGUAGES_COUNT; ++i)
1771 m_session->GetPlayer()->learnSpell(lang_description[i].spell_id);
1773 SendSysMessage(LANG_COMMAND_LEARN_ALL_LANG);
1774 return true;
1777 bool ChatHandler::HandleLearnAllDefaultCommand(const char* args)
1779 char* pName = strtok((char*)args, "");
1780 Player *player = NULL;
1781 if (pName)
1783 std::string name = pName;
1785 if(!normalizePlayerName(name))
1787 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1788 SetSentErrorMessage(true);
1789 return false;
1792 player = objmgr.GetPlayer(name.c_str());
1794 else
1795 player = getSelectedPlayer();
1797 if(!player)
1799 SendSysMessage(LANG_NO_CHAR_SELECTED);
1800 SetSentErrorMessage(true);
1801 return false;
1804 player->learnDefaultSpells();
1805 player->learnQuestRewardedSpells();
1807 PSendSysMessage(LANG_COMMAND_LEARN_ALL_DEFAULT_AND_QUEST,player->GetName());
1808 return true;
1811 bool ChatHandler::HandleLearnCommand(const char* args)
1813 Player* targetPlayer = getSelectedPlayer();
1815 if(!targetPlayer)
1817 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1818 SetSentErrorMessage(true);
1819 return false;
1822 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1823 uint32 spell = extractSpellIdFromLink((char*)args);
1824 if(!spell || !sSpellStore.LookupEntry(spell))
1825 return false;
1827 if (targetPlayer->HasSpell(spell))
1829 if(targetPlayer == m_session->GetPlayer())
1830 SendSysMessage(LANG_YOU_KNOWN_SPELL);
1831 else
1832 PSendSysMessage(LANG_TARGET_KNOWN_SPELL,targetPlayer->GetName());
1833 SetSentErrorMessage(true);
1834 return false;
1837 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
1838 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
1840 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
1841 SetSentErrorMessage(true);
1842 return false;
1845 targetPlayer->learnSpell(spell);
1847 return true;
1850 bool ChatHandler::HandleAddItemCommand(const char* args)
1852 if (!*args)
1853 return false;
1855 uint32 itemId = 0;
1857 if(args[0]=='[') // [name] manual form
1859 char* citemName = citemName = strtok((char*)args, "]");
1861 if(citemName && citemName[0])
1863 std::string itemName = citemName+1;
1864 WorldDatabase.escape_string(itemName);
1865 QueryResult *result = WorldDatabase.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName.c_str());
1866 if (!result)
1868 PSendSysMessage(LANG_COMMAND_COULDNOTFIND, citemName+1);
1869 SetSentErrorMessage(true);
1870 return false;
1872 itemId = result->Fetch()->GetUInt16();
1873 delete result;
1875 else
1876 return false;
1878 else // item_id or [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r
1880 char* cId = extractKeyFromLink((char*)args,"Hitem");
1881 if(!cId)
1882 return false;
1883 itemId = atol(cId);
1886 char* ccount = strtok(NULL, " ");
1888 int32 count = 1;
1890 if (ccount)
1891 count = strtol(ccount, NULL, 10);
1893 if (count == 0)
1894 count = 1;
1896 Player* pl = m_session->GetPlayer();
1897 Player* plTarget = getSelectedPlayer();
1898 if(!plTarget)
1899 plTarget = pl;
1901 sLog.outDetail(GetMangosString(LANG_ADDITEM), itemId, count);
1903 ItemPrototype const *pProto = objmgr.GetItemPrototype(itemId);
1904 if(!pProto)
1906 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, itemId);
1907 SetSentErrorMessage(true);
1908 return false;
1911 //Subtract
1912 if (count < 0)
1914 plTarget->DestroyItemCount(itemId, -count, true, false);
1915 PSendSysMessage(LANG_REMOVEITEM, itemId, -count, plTarget->GetName());
1916 return true;
1919 //Adding items
1920 uint32 noSpaceForCount = 0;
1922 // check space and find places
1923 ItemPosCountVec dest;
1924 uint8 msg = plTarget->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, itemId, count, &noSpaceForCount );
1925 if( msg != EQUIP_ERR_OK ) // convert to possible store amount
1926 count -= noSpaceForCount;
1928 if( count == 0 || dest.empty()) // can't add any
1930 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount );
1931 SetSentErrorMessage(true);
1932 return false;
1935 Item* item = plTarget->StoreNewItem( dest, itemId, true, Item::GenerateItemRandomPropertyId(itemId));
1937 // remove binding (let GM give it to another player later)
1938 if(pl==plTarget)
1939 for(ItemPosCountVec::const_iterator itr = dest.begin(); itr != dest.end(); ++itr)
1940 if(Item* item1 = pl->GetItemByPos(itr->pos))
1941 item1->SetBinding( false );
1943 if(count > 0 && item)
1945 pl->SendNewItem(item,count,false,true);
1946 if(pl!=plTarget)
1947 plTarget->SendNewItem(item,count,true,false);
1950 if(noSpaceForCount > 0)
1951 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount);
1953 return true;
1956 bool ChatHandler::HandleAddItemSetCommand(const char* args)
1958 if (!*args)
1959 return false;
1961 char* cId = extractKeyFromLink((char*)args,"Hitemset"); // number or [name] Shift-click form |color|Hitemset:itemset_id|h[name]|h|r
1962 if (!cId)
1963 return false;
1965 uint32 itemsetId = atol(cId);
1967 // prevent generation all items with itemset field value '0'
1968 if (itemsetId == 0)
1970 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND,itemsetId);
1971 SetSentErrorMessage(true);
1972 return false;
1975 Player* pl = m_session->GetPlayer();
1976 Player* plTarget = getSelectedPlayer();
1977 if(!plTarget)
1978 plTarget = pl;
1980 sLog.outDetail(GetMangosString(LANG_ADDITEMSET), itemsetId);
1982 QueryResult *result = WorldDatabase.PQuery("SELECT entry FROM item_template WHERE itemset = %u",itemsetId);
1984 if(!result)
1986 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND,itemsetId);
1988 SetSentErrorMessage(true);
1989 return false;
1994 Field *fields = result->Fetch();
1995 uint32 itemId = fields[0].GetUInt32();
1997 ItemPosCountVec dest;
1998 uint8 msg = plTarget->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, itemId, 1 );
1999 if( msg == EQUIP_ERR_OK )
2001 Item* item = plTarget->StoreNewItem( dest, itemId, true);
2003 // remove binding (let GM give it to another player later)
2004 if(pl==plTarget)
2005 item->SetBinding( false );
2007 pl->SendNewItem(item,1,false,true);
2008 if(pl!=plTarget)
2009 plTarget->SendNewItem(item,1,true,false);
2011 else
2013 pl->SendEquipError( msg, NULL, NULL );
2014 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, 1);
2017 }while( result->NextRow() );
2019 delete result;
2021 return true;
2024 bool ChatHandler::HandleListItemCommand(const char* args)
2026 if(!*args)
2027 return false;
2029 char* cId = extractKeyFromLink((char*)args,"Hitem");
2030 if(!cId)
2031 return false;
2033 uint32 item_id = atol(cId);
2034 if(!item_id)
2036 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
2037 SetSentErrorMessage(true);
2038 return false;
2041 ItemPrototype const* itemProto = objmgr.GetItemPrototype(item_id);
2042 if(!itemProto)
2044 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
2045 SetSentErrorMessage(true);
2046 return false;
2049 char* c_count = strtok(NULL, " ");
2050 int count = c_count ? atol(c_count) : 10;
2052 if(count < 0)
2053 return false;
2055 QueryResult *result;
2057 // inventory case
2058 uint32 inv_count = 0;
2059 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM character_inventory WHERE item_template='%u'",item_id);
2060 if(result)
2062 inv_count = (*result)[0].GetUInt32();
2063 delete result;
2066 result=CharacterDatabase.PQuery(
2067 // 0 1 2 3 4 5
2068 "SELECT ci.item, cibag.slot AS bag, ci.slot, ci.guid, characters.account,characters.name "
2069 "FROM character_inventory AS ci LEFT JOIN character_inventory AS cibag ON (cibag.item=ci.bag),characters "
2070 "WHERE ci.item_template='%u' AND ci.guid = characters.guid LIMIT %u ",
2071 item_id,uint32(count));
2073 if(result)
2077 Field *fields = result->Fetch();
2078 uint32 item_guid = fields[0].GetUInt32();
2079 uint32 item_bag = fields[1].GetUInt32();
2080 uint32 item_slot = fields[2].GetUInt32();
2081 uint32 owner_guid = fields[3].GetUInt32();
2082 uint32 owner_acc = fields[4].GetUInt32();
2083 std::string owner_name = fields[5].GetCppString();
2085 char const* item_pos = 0;
2086 if(Player::IsEquipmentPos(item_bag,item_slot))
2087 item_pos = "[equipped]";
2088 else if(Player::IsInventoryPos(item_bag,item_slot))
2089 item_pos = "[in inventory]";
2090 else if(Player::IsBankPos(item_bag,item_slot))
2091 item_pos = "[in bank]";
2092 else
2093 item_pos = "";
2095 PSendSysMessage(LANG_ITEMLIST_SLOT,
2096 item_guid,owner_name.c_str(),owner_guid,owner_acc,item_pos);
2097 } while (result->NextRow());
2099 int64 res_count = result->GetRowCount();
2101 delete result;
2103 if(count > res_count)
2104 count-=res_count;
2105 else if(count)
2106 count = 0;
2109 // mail case
2110 uint32 mail_count = 0;
2111 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM mail_items WHERE item_template='%u'", item_id);
2112 if(result)
2114 mail_count = (*result)[0].GetUInt32();
2115 delete result;
2118 if(count > 0)
2120 result=CharacterDatabase.PQuery(
2121 // 0 1 2 3 4 5 6
2122 "SELECT mail_items.item_guid, mail.sender, mail.receiver, char_s.account, char_s.name, char_r.account, char_r.name "
2123 "FROM mail,mail_items,characters as char_s,characters as char_r "
2124 "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",
2125 item_id,uint32(count));
2127 else
2128 result = NULL;
2130 if(result)
2134 Field *fields = result->Fetch();
2135 uint32 item_guid = fields[0].GetUInt32();
2136 uint32 item_s = fields[1].GetUInt32();
2137 uint32 item_r = fields[2].GetUInt32();
2138 uint32 item_s_acc = fields[3].GetUInt32();
2139 std::string item_s_name = fields[4].GetCppString();
2140 uint32 item_r_acc = fields[5].GetUInt32();
2141 std::string item_r_name = fields[6].GetCppString();
2143 char const* item_pos = "[in mail]";
2145 PSendSysMessage(LANG_ITEMLIST_MAIL,
2146 item_guid,item_s_name.c_str(),item_s,item_s_acc,item_r_name.c_str(),item_r,item_r_acc,item_pos);
2147 } while (result->NextRow());
2149 int64 res_count = result->GetRowCount();
2151 delete result;
2153 if(count > res_count)
2154 count-=res_count;
2155 else if(count)
2156 count = 0;
2159 // auction case
2160 uint32 auc_count = 0;
2161 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM auctionhouse WHERE item_template='%u'",item_id);
2162 if(result)
2164 auc_count = (*result)[0].GetUInt32();
2165 delete result;
2168 if(count > 0)
2170 result=CharacterDatabase.PQuery(
2171 // 0 1 2 3
2172 "SELECT auctionhouse.itemguid, auctionhouse.itemowner, characters.account, characters.name "
2173 "FROM auctionhouse,characters WHERE auctionhouse.item_template='%u' AND characters.guid = auctionhouse.itemowner LIMIT %u",
2174 item_id,uint32(count));
2176 else
2177 result = NULL;
2179 if(result)
2183 Field *fields = result->Fetch();
2184 uint32 item_guid = fields[0].GetUInt32();
2185 uint32 owner = fields[1].GetUInt32();
2186 uint32 owner_acc = fields[2].GetUInt32();
2187 std::string owner_name = fields[3].GetCppString();
2189 char const* item_pos = "[in auction]";
2191 PSendSysMessage(LANG_ITEMLIST_AUCTION, item_guid, owner_name.c_str(), owner, owner_acc,item_pos);
2192 } while (result->NextRow());
2194 delete result;
2197 // guild bank case
2198 uint32 guild_count = 0;
2199 result=CharacterDatabase.PQuery("SELECT COUNT(item_entry) FROM guild_bank_item WHERE item_entry='%u'",item_id);
2200 if(result)
2202 guild_count = (*result)[0].GetUInt32();
2203 delete result;
2206 result=CharacterDatabase.PQuery(
2207 // 0 1 2
2208 "SELECT gi.item_guid, gi.guildid, guild.name "
2209 "FROM guild_bank_item AS gi, guild WHERE gi.item_entry='%u' AND gi.guildid = guild.guildid LIMIT %u ",
2210 item_id,uint32(count));
2212 if(result)
2216 Field *fields = result->Fetch();
2217 uint32 item_guid = fields[0].GetUInt32();
2218 uint32 guild_guid = fields[1].GetUInt32();
2219 std::string guild_name = fields[2].GetCppString();
2221 char const* item_pos = "[in guild bank]";
2223 PSendSysMessage(LANG_ITEMLIST_GUILD,item_guid,guild_name.c_str(),guild_guid,item_pos);
2224 } while (result->NextRow());
2226 int64 res_count = result->GetRowCount();
2228 delete result;
2230 if(count > res_count)
2231 count-=res_count;
2232 else if(count)
2233 count = 0;
2236 if(inv_count+mail_count+auc_count+guild_count == 0)
2238 SendSysMessage(LANG_COMMAND_NOITEMFOUND);
2239 SetSentErrorMessage(true);
2240 return false;
2243 PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE,item_id,inv_count+mail_count+auc_count+guild_count,inv_count,mail_count,auc_count,guild_count);
2245 return true;
2248 bool ChatHandler::HandleListObjectCommand(const char* args)
2250 if(!*args)
2251 return false;
2253 // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2254 char* cId = extractKeyFromLink((char*)args,"Hgameobject_entry");
2255 if(!cId)
2256 return false;
2258 uint32 go_id = atol(cId);
2259 if(!go_id)
2261 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, go_id);
2262 SetSentErrorMessage(true);
2263 return false;
2266 GameObjectInfo const * gInfo = objmgr.GetGameObjectInfo(go_id);
2267 if(!gInfo)
2269 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, go_id);
2270 SetSentErrorMessage(true);
2271 return false;
2274 char* c_count = strtok(NULL, " ");
2275 int count = c_count ? atol(c_count) : 10;
2277 if(count < 0)
2278 return false;
2280 QueryResult *result;
2282 uint32 obj_count = 0;
2283 result=WorldDatabase.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'",go_id);
2284 if(result)
2286 obj_count = (*result)[0].GetUInt32();
2287 delete result;
2290 if(m_session)
2292 Player* pl = m_session->GetPlayer();
2293 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",
2294 pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(),go_id,uint32(count));
2296 else
2297 result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map FROM gameobject WHERE id = '%u' LIMIT %u",
2298 go_id,uint32(count));
2300 if (result)
2304 Field *fields = result->Fetch();
2305 uint32 guid = fields[0].GetUInt32();
2306 float x = fields[1].GetFloat();
2307 float y = fields[2].GetFloat();
2308 float z = fields[3].GetFloat();
2309 int mapid = fields[4].GetUInt16();
2311 if (m_session)
2312 PSendSysMessage(LANG_GO_LIST_CHAT, guid, guid, gInfo->name, x, y, z, mapid);
2313 else
2314 PSendSysMessage(LANG_GO_LIST_CONSOLE, guid, gInfo->name, x, y, z, mapid);
2315 } while (result->NextRow());
2317 delete result;
2320 PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE,go_id,obj_count);
2321 return true;
2324 bool ChatHandler::HandleNearObjectCommand(const char* args)
2326 float distance = (!*args) ? 10 : atol(args);
2327 uint32 count = 0;
2329 Player* pl = m_session->GetPlayer();
2330 QueryResult *result = WorldDatabase.PQuery("SELECT guid, id, position_x, position_y, position_z, map, "
2331 "(POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ "
2332 "FROM gameobject WHERE map='%u' AND (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) <= '%f' ORDER BY order_",
2333 pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(),
2334 pl->GetMapId(),pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(),distance*distance);
2336 if (result)
2340 Field *fields = result->Fetch();
2341 uint32 guid = fields[0].GetUInt32();
2342 uint32 entry = fields[1].GetUInt32();
2343 float x = fields[2].GetFloat();
2344 float y = fields[3].GetFloat();
2345 float z = fields[4].GetFloat();
2346 int mapid = fields[5].GetUInt16();
2348 GameObjectInfo const * gInfo = objmgr.GetGameObjectInfo(entry);
2350 if(!gInfo)
2351 continue;
2353 PSendSysMessage(LANG_GO_LIST_CHAT, guid, guid, gInfo->name, x, y, z, mapid);
2355 ++count;
2356 } while (result->NextRow());
2358 delete result;
2361 PSendSysMessage(LANG_COMMAND_NEAROBJMESSAGE,distance,count);
2362 return true;
2365 bool ChatHandler::HandleListCreatureCommand(const char* args)
2367 if(!*args)
2368 return false;
2370 // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
2371 char* cId = extractKeyFromLink((char*)args,"Hcreature_entry");
2372 if(!cId)
2373 return false;
2375 uint32 cr_id = atol(cId);
2376 if(!cr_id)
2378 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, cr_id);
2379 SetSentErrorMessage(true);
2380 return false;
2383 CreatureInfo const* cInfo = objmgr.GetCreatureTemplate(cr_id);
2384 if(!cInfo)
2386 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, cr_id);
2387 SetSentErrorMessage(true);
2388 return false;
2391 char* c_count = strtok(NULL, " ");
2392 int count = c_count ? atol(c_count) : 10;
2394 if(count < 0)
2395 return false;
2397 QueryResult *result;
2399 uint32 cr_count = 0;
2400 result=WorldDatabase.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'",cr_id);
2401 if(result)
2403 cr_count = (*result)[0].GetUInt32();
2404 delete result;
2407 if(m_session)
2409 Player* pl = m_session->GetPlayer();
2410 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",
2411 pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(), cr_id,uint32(count));
2413 else
2414 result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '%u' LIMIT %u",
2415 cr_id,uint32(count));
2417 if (result)
2421 Field *fields = result->Fetch();
2422 uint32 guid = fields[0].GetUInt32();
2423 float x = fields[1].GetFloat();
2424 float y = fields[2].GetFloat();
2425 float z = fields[3].GetFloat();
2426 int mapid = fields[4].GetUInt16();
2428 if (m_session)
2429 PSendSysMessage(LANG_CREATURE_LIST_CHAT, guid, guid, cInfo->Name, x, y, z, mapid);
2430 else
2431 PSendSysMessage(LANG_CREATURE_LIST_CONSOLE, guid, cInfo->Name, x, y, z, mapid);
2432 } while (result->NextRow());
2434 delete result;
2437 PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE,cr_id,cr_count);
2438 return true;
2441 bool ChatHandler::HandleLookupItemCommand(const char* args)
2443 if(!*args)
2444 return false;
2446 std::string namepart = args;
2447 std::wstring wnamepart;
2449 // converting string that we try to find to lower case
2450 if(!Utf8toWStr(namepart,wnamepart))
2451 return false;
2453 wstrToLower(wnamepart);
2455 uint32 counter = 0;
2457 // Search in `item_template`
2458 for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
2460 ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype >(id);
2461 if(!pProto)
2462 continue;
2464 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
2465 if ( loc_idx >= 0 )
2467 ItemLocale const *il = objmgr.GetItemLocale(pProto->ItemId);
2468 if (il)
2470 if (il->Name.size() > loc_idx && !il->Name[loc_idx].empty())
2472 std::string name = il->Name[loc_idx];
2474 if (Utf8FitTo(name, wnamepart))
2476 if (m_session)
2477 PSendSysMessage(LANG_ITEM_LIST_CHAT, id, id, name.c_str());
2478 else
2479 PSendSysMessage(LANG_ITEM_LIST_CONSOLE, id, name.c_str());
2480 ++counter;
2481 continue;
2487 std::string name = pProto->Name1;
2488 if(name.empty())
2489 continue;
2491 if (Utf8FitTo(name, wnamepart))
2493 if (m_session)
2494 PSendSysMessage(LANG_ITEM_LIST_CHAT, id, id, name.c_str());
2495 else
2496 PSendSysMessage(LANG_ITEM_LIST_CONSOLE, id, name.c_str());
2497 ++counter;
2501 if (counter==0)
2502 SendSysMessage(LANG_COMMAND_NOITEMFOUND);
2504 return true;
2507 bool ChatHandler::HandleLookupItemSetCommand(const char* args)
2509 if(!*args)
2510 return false;
2512 std::string namepart = args;
2513 std::wstring wnamepart;
2515 if(!Utf8toWStr(namepart,wnamepart))
2516 return false;
2518 // converting string that we try to find to lower case
2519 wstrToLower( wnamepart );
2521 uint32 counter = 0; // Counter for figure out that we found smth.
2523 // Search in ItemSet.dbc
2524 for (uint32 id = 0; id < sItemSetStore.GetNumRows(); id++)
2526 ItemSetEntry const *set = sItemSetStore.LookupEntry(id);
2527 if(set)
2529 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
2530 std::string name = set->name[loc];
2531 if(name.empty())
2532 continue;
2534 if (!Utf8FitTo(name, wnamepart))
2536 loc = 0;
2537 for(; loc < MAX_LOCALE; ++loc)
2539 if(m_session && loc==m_session->GetSessionDbcLocale())
2540 continue;
2542 name = set->name[loc];
2543 if(name.empty())
2544 continue;
2546 if (Utf8FitTo(name, wnamepart))
2547 break;
2551 if(loc < MAX_LOCALE)
2553 // send item set in "id - [namedlink locale]" format
2554 if (m_session)
2555 PSendSysMessage(LANG_ITEMSET_LIST_CHAT,id,id,name.c_str(),localeNames[loc]);
2556 else
2557 PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE,id,name.c_str(),localeNames[loc]);
2558 ++counter;
2562 if (counter == 0) // if counter == 0 then we found nth
2563 SendSysMessage(LANG_COMMAND_NOITEMSETFOUND);
2564 return true;
2567 bool ChatHandler::HandleLookupSkillCommand(const char* args)
2569 if(!*args)
2570 return false;
2572 // can be NULL in console call
2573 Player* target = getSelectedPlayer();
2575 std::string namepart = args;
2576 std::wstring wnamepart;
2578 if(!Utf8toWStr(namepart,wnamepart))
2579 return false;
2581 // converting string that we try to find to lower case
2582 wstrToLower( wnamepart );
2584 uint32 counter = 0; // Counter for figure out that we found smth.
2586 // Search in SkillLine.dbc
2587 for (uint32 id = 0; id < sSkillLineStore.GetNumRows(); id++)
2589 SkillLineEntry const *skillInfo = sSkillLineStore.LookupEntry(id);
2590 if(skillInfo)
2592 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
2593 std::string name = skillInfo->name[loc];
2594 if(name.empty())
2595 continue;
2597 if (!Utf8FitTo(name, wnamepart))
2599 loc = 0;
2600 for(; loc < MAX_LOCALE; ++loc)
2602 if(m_session && loc==m_session->GetSessionDbcLocale())
2603 continue;
2605 name = skillInfo->name[loc];
2606 if(name.empty())
2607 continue;
2609 if (Utf8FitTo(name, wnamepart))
2610 break;
2614 if(loc < MAX_LOCALE)
2616 char const* knownStr = "";
2617 if(target && target->HasSkill(id))
2618 knownStr = GetMangosString(LANG_KNOWN);
2620 // send skill in "id - [namedlink locale]" format
2621 if (m_session)
2622 PSendSysMessage(LANG_SKILL_LIST_CHAT,id,id,name.c_str(),localeNames[loc],knownStr);
2623 else
2624 PSendSysMessage(LANG_SKILL_LIST_CONSOLE,id,name.c_str(),localeNames[loc],knownStr);
2626 ++counter;
2630 if (counter == 0) // if counter == 0 then we found nth
2631 SendSysMessage(LANG_COMMAND_NOSKILLFOUND);
2632 return true;
2635 bool ChatHandler::HandleLookupSpellCommand(const char* args)
2637 if(!*args)
2638 return false;
2640 // can be NULL at console call
2641 Player* target = getSelectedPlayer();
2643 std::string namepart = args;
2644 std::wstring wnamepart;
2646 if(!Utf8toWStr(namepart,wnamepart))
2647 return false;
2649 // converting string that we try to find to lower case
2650 wstrToLower( wnamepart );
2652 uint32 counter = 0; // Counter for figure out that we found smth.
2654 // Search in Spell.dbc
2655 for (uint32 id = 0; id < sSpellStore.GetNumRows(); id++)
2657 SpellEntry const *spellInfo = sSpellStore.LookupEntry(id);
2658 if(spellInfo)
2660 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
2661 std::string name = spellInfo->SpellName[loc];
2662 if(name.empty())
2663 continue;
2665 if (!Utf8FitTo(name, wnamepart))
2667 loc = 0;
2668 for(; loc < MAX_LOCALE; ++loc)
2670 if(m_session && loc==m_session->GetSessionDbcLocale())
2671 continue;
2673 name = spellInfo->SpellName[loc];
2674 if(name.empty())
2675 continue;
2677 if (Utf8FitTo(name, wnamepart))
2678 break;
2682 if(loc < MAX_LOCALE)
2684 bool known = target && target->HasSpell(id);
2685 bool learn = (spellInfo->Effect[0] == SPELL_EFFECT_LEARN_SPELL);
2687 uint32 telentCost = GetTalentSpellCost(id);
2689 bool talent = (telentCost > 0);
2690 bool passive = IsPassiveSpell(id);
2691 bool active = target && (target->HasAura(id,0) || target->HasAura(id,1) || target->HasAura(id,2));
2693 // unit32 used to prevent interpreting uint8 as char at output
2694 // find rank of learned spell for learning spell, or talent rank
2695 uint32 rank = telentCost ? telentCost : spellmgr.GetSpellRank(learn ? spellInfo->EffectTriggerSpell[0] : id);
2697 // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
2698 std::ostringstream ss;
2699 if (m_session)
2700 ss << id << " - |cffffffff|Hspell:" << id << "|h[" << name;
2701 else
2702 ss << id << " - " << name;
2704 // include rank in link name
2705 if(rank)
2706 ss << GetMangosString(LANG_SPELL_RANK) << rank;
2708 if (m_session)
2709 ss << " " << localeNames[loc] << "]|h|r";
2710 else
2711 ss << " " << localeNames[loc];
2713 if(talent)
2714 ss << GetMangosString(LANG_TALENT);
2715 if(passive)
2716 ss << GetMangosString(LANG_PASSIVE);
2717 if(learn)
2718 ss << GetMangosString(LANG_LEARN);
2719 if(known)
2720 ss << GetMangosString(LANG_KNOWN);
2721 if(active)
2722 ss << GetMangosString(LANG_ACTIVE);
2724 SendSysMessage(ss.str().c_str());
2726 ++counter;
2730 if (counter == 0) // if counter == 0 then we found nth
2731 SendSysMessage(LANG_COMMAND_NOSPELLFOUND);
2732 return true;
2735 bool ChatHandler::HandleLookupQuestCommand(const char* args)
2737 if(!*args)
2738 return false;
2740 // can be NULL at console call
2741 Player* target = getSelectedPlayer();
2743 std::string namepart = args;
2744 std::wstring wnamepart;
2746 // converting string that we try to find to lower case
2747 if(!Utf8toWStr(namepart,wnamepart))
2748 return false;
2750 wstrToLower(wnamepart);
2752 uint32 counter = 0 ;
2754 ObjectMgr::QuestMap const& qTemplates = objmgr.GetQuestTemplates();
2755 for (ObjectMgr::QuestMap::const_iterator iter = qTemplates.begin(); iter != qTemplates.end(); ++iter)
2757 Quest * qinfo = iter->second;
2759 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
2760 if ( loc_idx >= 0 )
2762 QuestLocale const *il = objmgr.GetQuestLocale(qinfo->GetQuestId());
2763 if (il)
2765 if (il->Title.size() > loc_idx && !il->Title[loc_idx].empty())
2767 std::string title = il->Title[loc_idx];
2769 if (Utf8FitTo(title, wnamepart))
2771 char const* statusStr = "";
2773 if(target)
2775 QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId());
2777 if(status == QUEST_STATUS_COMPLETE)
2779 if(target->GetQuestRewardStatus(qinfo->GetQuestId()))
2780 statusStr = GetMangosString(LANG_COMMAND_QUEST_REWARDED);
2781 else
2782 statusStr = GetMangosString(LANG_COMMAND_QUEST_COMPLETE);
2784 else if(status == QUEST_STATUS_INCOMPLETE)
2785 statusStr = GetMangosString(LANG_COMMAND_QUEST_ACTIVE);
2788 if (m_session)
2789 PSendSysMessage(LANG_QUEST_LIST_CHAT,qinfo->GetQuestId(),qinfo->GetQuestId(),title.c_str(),statusStr);
2790 else
2791 PSendSysMessage(LANG_QUEST_LIST_CONSOLE,qinfo->GetQuestId(),title.c_str(),statusStr);
2792 ++counter;
2793 continue;
2799 std::string title = qinfo->GetTitle();
2800 if(title.empty())
2801 continue;
2803 if (Utf8FitTo(title, wnamepart))
2805 char const* statusStr = "";
2807 if(target)
2809 QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId());
2811 if(status == QUEST_STATUS_COMPLETE)
2813 if(target->GetQuestRewardStatus(qinfo->GetQuestId()))
2814 statusStr = GetMangosString(LANG_COMMAND_QUEST_REWARDED);
2815 else
2816 statusStr = GetMangosString(LANG_COMMAND_QUEST_COMPLETE);
2818 else if(status == QUEST_STATUS_INCOMPLETE)
2819 statusStr = GetMangosString(LANG_COMMAND_QUEST_ACTIVE);
2822 if (m_session)
2823 PSendSysMessage(LANG_QUEST_LIST_CHAT,qinfo->GetQuestId(),qinfo->GetQuestId(),title.c_str(),statusStr);
2824 else
2825 PSendSysMessage(LANG_QUEST_LIST_CONSOLE,qinfo->GetQuestId(),title.c_str(),statusStr);
2827 ++counter;
2831 if (counter==0)
2832 SendSysMessage(LANG_COMMAND_NOQUESTFOUND);
2834 return true;
2837 bool ChatHandler::HandleLookupCreatureCommand(const char* args)
2839 if (!*args)
2840 return false;
2842 std::string namepart = args;
2843 std::wstring wnamepart;
2845 // converting string that we try to find to lower case
2846 if (!Utf8toWStr (namepart,wnamepart))
2847 return false;
2849 wstrToLower (wnamepart);
2851 uint32 counter = 0;
2853 for (uint32 id = 0; id< sCreatureStorage.MaxEntry; ++id)
2855 CreatureInfo const* cInfo = sCreatureStorage.LookupEntry<CreatureInfo> (id);
2856 if(!cInfo)
2857 continue;
2859 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
2860 if (loc_idx >= 0)
2862 CreatureLocale const *cl = objmgr.GetCreatureLocale (id);
2863 if (cl)
2865 if (cl->Name.size() > loc_idx && !cl->Name[loc_idx].empty ())
2867 std::string name = cl->Name[loc_idx];
2869 if (Utf8FitTo (name, wnamepart))
2871 if (m_session)
2872 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str ());
2873 else
2874 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE, id, name.c_str ());
2875 ++counter;
2876 continue;
2882 std::string name = cInfo->Name;
2883 if (name.empty ())
2884 continue;
2886 if (Utf8FitTo(name, wnamepart))
2888 if (m_session)
2889 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str ());
2890 else
2891 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE, id, name.c_str ());
2892 ++counter;
2896 if (counter==0)
2897 SendSysMessage (LANG_COMMAND_NOCREATUREFOUND);
2899 return true;
2902 bool ChatHandler::HandleLookupObjectCommand(const char* args)
2904 if(!*args)
2905 return false;
2907 std::string namepart = args;
2908 std::wstring wnamepart;
2910 // converting string that we try to find to lower case
2911 if(!Utf8toWStr(namepart,wnamepart))
2912 return false;
2914 wstrToLower(wnamepart);
2916 uint32 counter = 0;
2918 for (uint32 id = 0; id< sGOStorage.MaxEntry; id++ )
2920 GameObjectInfo const* gInfo = sGOStorage.LookupEntry<GameObjectInfo>(id);
2921 if(!gInfo)
2922 continue;
2924 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
2925 if ( loc_idx >= 0 )
2927 GameObjectLocale const *gl = objmgr.GetGameObjectLocale(id);
2928 if (gl)
2930 if (gl->Name.size() > loc_idx && !gl->Name[loc_idx].empty())
2932 std::string name = gl->Name[loc_idx];
2934 if (Utf8FitTo(name, wnamepart))
2936 if (m_session)
2937 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, id, id, name.c_str());
2938 else
2939 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, id, name.c_str());
2940 ++counter;
2941 continue;
2947 std::string name = gInfo->name;
2948 if(name.empty())
2949 continue;
2951 if(Utf8FitTo(name, wnamepart))
2953 if (m_session)
2954 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, id, id, name.c_str());
2955 else
2956 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, id, name.c_str());
2957 ++counter;
2961 if(counter==0)
2962 SendSysMessage(LANG_COMMAND_NOGAMEOBJECTFOUND);
2964 return true;
2967 /** \brief GM command level 3 - Create a guild.
2969 * This command allows a GM (level 3) to create a guild.
2971 * The "args" parameter contains the name of the guild leader
2972 * and then the name of the guild.
2975 bool ChatHandler::HandleGuildCreateCommand(const char* args)
2978 if (!*args)
2979 return false;
2981 char *lname = strtok ((char*)args, " ");
2982 char *gname = strtok (NULL, "");
2984 if (!lname)
2985 return false;
2987 if (!gname)
2989 SendSysMessage (LANG_INSERT_GUILD_NAME);
2990 SetSentErrorMessage (true);
2991 return false;
2994 std::string guildname = gname;
2996 Player* player = ObjectAccessor::Instance ().FindPlayerByName (lname);
2997 if (!player)
2999 SendSysMessage (LANG_PLAYER_NOT_FOUND);
3000 SetSentErrorMessage (true);
3001 return false;
3004 if (player->GetGuildId())
3006 SendSysMessage (LANG_PLAYER_IN_GUILD);
3007 return true;
3010 Guild *guild = new Guild;
3011 if (!guild->create (player->GetGUID (),guildname))
3013 delete guild;
3014 SendSysMessage (LANG_GUILD_NOT_CREATED);
3015 SetSentErrorMessage (true);
3016 return false;
3019 objmgr.AddGuild (guild);
3020 return true;
3023 bool ChatHandler::HandleGuildInviteCommand(const char *args)
3025 if (!*args)
3026 return false;
3028 char* par1 = strtok ((char*)args, " ");
3029 char* par2 = strtok (NULL, "");
3030 if(!par1 || !par2)
3031 return false;
3033 std::string glName = par2;
3034 Guild* targetGuild = objmgr.GetGuildByName (glName);
3035 if (!targetGuild)
3036 return false;
3038 std::string plName = par1;
3039 if (!normalizePlayerName (plName))
3041 SendSysMessage (LANG_PLAYER_NOT_FOUND);
3042 SetSentErrorMessage (true);
3043 return false;
3046 uint64 plGuid = 0;
3047 if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3048 plGuid = targetPlayer->GetGUID ();
3049 else
3050 plGuid = objmgr.GetPlayerGUIDByName (plName.c_str ());
3052 if (!plGuid)
3053 false;
3055 // players's guild membership checked in AddMember before add
3056 if (!targetGuild->AddMember (plGuid,targetGuild->GetLowestRank ()))
3057 return false;
3059 return true;
3062 bool ChatHandler::HandleGuildUninviteCommand(const char *args)
3064 if (!*args)
3065 return false;
3067 char* par1 = strtok ((char*)args, " ");
3068 if(!par1)
3069 return false;
3071 std::string plName = par1;
3072 if (!normalizePlayerName (plName))
3074 SendSysMessage (LANG_PLAYER_NOT_FOUND);
3075 SetSentErrorMessage (true);
3076 return false;
3079 uint64 plGuid = 0;
3080 uint32 glId = 0;
3081 if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3083 plGuid = targetPlayer->GetGUID ();
3084 glId = targetPlayer->GetGuildId ();
3086 else
3088 plGuid = objmgr.GetPlayerGUIDByName (plName.c_str ());
3089 glId = Player::GetGuildIdFromDB (plGuid);
3092 if (!plGuid || !glId)
3093 return false;
3095 Guild* targetGuild = objmgr.GetGuildById (glId);
3096 if (!targetGuild)
3097 return false;
3099 targetGuild->DelMember (plGuid);
3101 return true;
3104 bool ChatHandler::HandleGuildRankCommand(const char *args)
3106 if (!*args)
3107 return false;
3109 char* par1 = strtok ((char*)args, " ");
3110 char* par2 = strtok (NULL, " ");
3111 if (!par1 || !par2)
3112 return false;
3113 std::string plName = par1;
3114 if (!normalizePlayerName (plName))
3116 SendSysMessage (LANG_PLAYER_NOT_FOUND);
3117 SetSentErrorMessage (true);
3118 return false;
3121 uint64 plGuid = 0;
3122 uint32 glId = 0;
3123 if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3125 plGuid = targetPlayer->GetGUID ();
3126 glId = targetPlayer->GetGuildId ();
3128 else
3130 plGuid = objmgr.GetPlayerGUIDByName (plName.c_str ());
3131 glId = Player::GetGuildIdFromDB (plGuid);
3134 if (!plGuid || !glId)
3135 return false;
3137 Guild* targetGuild = objmgr.GetGuildById (glId);
3138 if (!targetGuild)
3139 return false;
3141 uint32 newrank = uint32 (atoi (par2));
3142 if (newrank > targetGuild->GetLowestRank ())
3143 return false;
3145 targetGuild->ChangeRank (plGuid,newrank);
3147 return true;
3150 bool ChatHandler::HandleGuildDeleteCommand(const char* args)
3152 if (!*args)
3153 return false;
3155 char* par1 = strtok ((char*)args, " ");
3156 if (!par1)
3157 return false;
3159 std::string gld = par1;
3161 Guild* targetGuild = objmgr.GetGuildByName (gld);
3162 if (!targetGuild)
3163 return false;
3165 targetGuild->Disband ();
3167 return true;
3170 bool ChatHandler::HandleGetDistanceCommand(const char* /*args*/)
3172 Unit* pUnit = getSelectedUnit();
3174 if(!pUnit)
3176 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3177 SetSentErrorMessage(true);
3178 return false;
3181 PSendSysMessage(LANG_DISTANCE, m_session->GetPlayer()->GetDistance(pUnit),m_session->GetPlayer()->GetDistance2d(pUnit));
3183 return true;
3186 // FIX-ME!!!
3188 bool ChatHandler::HandleAddWeaponCommand(const char* /*args*/)
3190 /*if (!*args)
3191 return false;
3193 uint64 guid = m_session->GetPlayer()->GetSelection();
3194 if (guid == 0)
3196 SendSysMessage(LANG_NO_SELECTION);
3197 return true;
3200 Creature *pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
3202 if(!pCreature)
3204 SendSysMessage(LANG_SELECT_CREATURE);
3205 return true;
3208 char* pSlotID = strtok((char*)args, " ");
3209 if (!pSlotID)
3210 return false;
3212 char* pItemID = strtok(NULL, " ");
3213 if (!pItemID)
3214 return false;
3216 uint32 ItemID = atoi(pItemID);
3217 uint32 SlotID = atoi(pSlotID);
3219 ItemPrototype* tmpItem = objmgr.GetItemPrototype(ItemID);
3221 bool added = false;
3222 if(tmpItem)
3224 switch(SlotID)
3226 case 1:
3227 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID);
3228 added = true;
3229 break;
3230 case 2:
3231 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID);
3232 added = true;
3233 break;
3234 case 3:
3235 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID);
3236 added = true;
3237 break;
3238 default:
3239 PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST,SlotID);
3240 added = false;
3241 break;
3243 if(added)
3245 PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT,ItemID,tmpItem->Name1,SlotID);
3248 else
3250 PSendSysMessage(LANG_ITEM_NOT_FOUND,ItemID);
3251 return true;
3254 return true;
3257 bool ChatHandler::HandleDieCommand(const char* /*args*/)
3259 Unit* target = getSelectedUnit();
3261 if(!target || !m_session->GetPlayer()->GetSelection())
3263 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3264 SetSentErrorMessage(true);
3265 return false;
3268 if( target->isAlive() )
3270 m_session->GetPlayer()->DealDamage(target, target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
3273 return true;
3276 bool ChatHandler::HandleDamageCommand(const char * args)
3278 if (!*args)
3279 return false;
3281 Unit* target = getSelectedUnit();
3283 if(!target || !m_session->GetPlayer()->GetSelection())
3285 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3286 SetSentErrorMessage(true);
3287 return false;
3290 if( !target->isAlive() )
3291 return true;
3293 char* damageStr = strtok((char*)args, " ");
3294 if(!damageStr)
3295 return false;
3297 int32 damage = atoi((char*)damageStr);
3298 if(damage <=0)
3299 return true;
3301 char* schoolStr = strtok((char*)NULL, " ");
3303 // flat melee damage without resistence/etc reduction
3304 if(!schoolStr)
3306 m_session->GetPlayer()->DealDamage(target, damage, NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
3307 m_session->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2, target, 1, SPELL_SCHOOL_MASK_NORMAL, damage, 0, 0, VICTIMSTATE_NORMAL, 0);
3308 return true;
3311 uint32 school = schoolStr ? atoi((char*)schoolStr) : SPELL_SCHOOL_NORMAL;
3312 if(school >= MAX_SPELL_SCHOOL)
3313 return false;
3315 SpellSchoolMask schoolmask = SpellSchoolMask(1 << school);
3317 if ( schoolmask & SPELL_SCHOOL_MASK_NORMAL )
3318 damage = m_session->GetPlayer()->CalcArmorReducedDamage(target, damage);
3320 char* spellStr = strtok((char*)NULL, " ");
3322 // melee damage by specific school
3323 if(!spellStr)
3325 uint32 absorb = 0;
3326 uint32 resist = 0;
3328 m_session->GetPlayer()->CalcAbsorbResist(target,schoolmask, SPELL_DIRECT_DAMAGE, damage, &absorb, &resist);
3330 if (damage <= absorb + resist)
3331 return true;
3333 damage -= absorb + resist;
3335 m_session->GetPlayer()->DealDamage(target, damage, NULL, DIRECT_DAMAGE, schoolmask, NULL, false);
3336 m_session->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2, target, 1, schoolmask, damage, absorb, resist, VICTIMSTATE_NORMAL, 0);
3337 return true;
3340 // non-melee damage
3342 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3343 uint32 spellid = extractSpellIdFromLink((char*)args);
3344 if(!spellid || !sSpellStore.LookupEntry(spellid))
3345 return false;
3347 m_session->GetPlayer()->SpellNonMeleeDamageLog(target, spellid, damage, false);
3348 return true;
3351 bool ChatHandler::HandleModifyArenaCommand(const char * args)
3353 if (!*args)
3354 return false;
3356 Player *target = getSelectedPlayer();
3357 if(!target)
3359 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3360 SetSentErrorMessage(true);
3361 return false;
3364 int32 amount = (uint32)atoi(args);
3366 target->ModifyArenaPoints(amount);
3368 PSendSysMessage(LANG_COMMAND_MODIFY_ARENA, target->GetName(), target->GetArenaPoints());
3370 return true;
3373 bool ChatHandler::HandleReviveCommand(const char* args)
3375 Player* SelectedPlayer = NULL;
3377 if (*args)
3379 std::string name = args;
3380 if(!normalizePlayerName(name))
3382 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3383 SetSentErrorMessage(true);
3384 return false;
3387 SelectedPlayer = objmgr.GetPlayer(name.c_str());
3389 else
3390 SelectedPlayer = getSelectedPlayer();
3392 if(!SelectedPlayer)
3394 SendSysMessage(LANG_NO_CHAR_SELECTED);
3395 SetSentErrorMessage(true);
3396 return false;
3399 SelectedPlayer->ResurrectPlayer(0.5f);
3400 SelectedPlayer->SpawnCorpseBones();
3401 SelectedPlayer->SaveToDB();
3402 return true;
3405 bool ChatHandler::HandleAuraCommand(const char* args)
3407 char* px = strtok((char*)args, " ");
3408 if (!px)
3409 return false;
3411 Unit *target = getSelectedUnit();
3412 if(!target)
3414 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3415 SetSentErrorMessage(true);
3416 return false;
3419 uint32 spellID = (uint32)atoi(px);
3420 SpellEntry const *spellInfo = sSpellStore.LookupEntry( spellID );
3421 if(spellInfo)
3423 for(uint32 i = 0;i<3;i++)
3425 uint8 eff = spellInfo->Effect[i];
3426 if (eff>=TOTAL_SPELL_EFFECTS)
3427 continue;
3428 if( IsAreaAuraEffect(eff) ||
3429 eff == SPELL_EFFECT_APPLY_AURA ||
3430 eff == SPELL_EFFECT_PERSISTENT_AREA_AURA )
3432 Aura *Aur = CreateAura(spellInfo, i, NULL, target);
3433 target->AddAura(Aur);
3438 return true;
3441 bool ChatHandler::HandleUnAuraCommand(const char* args)
3443 char* px = strtok((char*)args, " ");
3444 if (!px)
3445 return false;
3447 Unit *target = getSelectedUnit();
3448 if(!target)
3450 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3451 SetSentErrorMessage(true);
3452 return false;
3455 std::string argstr = args;
3456 if (argstr == "all")
3458 target->RemoveAllAuras();
3459 return true;
3462 uint32 spellID = (uint32)atoi(px);
3463 target->RemoveAurasDueToSpell(spellID);
3465 return true;
3468 bool ChatHandler::HandleLinkGraveCommand(const char* args)
3470 if(!*args)
3471 return false;
3473 char* px = strtok((char*)args, " ");
3474 if (!px)
3475 return false;
3477 uint32 g_id = (uint32)atoi(px);
3479 uint32 g_team;
3481 char* px2 = strtok(NULL, " ");
3483 if (!px2)
3484 g_team = 0;
3485 else if (strncmp(px2,"horde",6)==0)
3486 g_team = HORDE;
3487 else if (strncmp(px2,"alliance",9)==0)
3488 g_team = ALLIANCE;
3489 else
3490 return false;
3492 WorldSafeLocsEntry const* graveyard = sWorldSafeLocsStore.LookupEntry(g_id);
3494 if(!graveyard )
3496 PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST, g_id);
3497 SetSentErrorMessage(true);
3498 return false;
3501 Player* player = m_session->GetPlayer();
3503 uint32 zoneId = player->GetZoneId();
3505 AreaTableEntry const *areaEntry = GetAreaEntryByAreaID(zoneId);
3506 if(!areaEntry || areaEntry->zone !=0 )
3508 PSendSysMessage(LANG_COMMAND_GRAVEYARDWRONGZONE, g_id,zoneId);
3509 SetSentErrorMessage(true);
3510 return false;
3513 if(graveyard->map_id != areaEntry->mapid && g_team != 0)
3515 SendSysMessage(LANG_COMMAND_GRAVEYARDWRONGTEAM);
3516 SetSentErrorMessage(true);
3517 return false;
3520 if(objmgr.AddGraveYardLink(g_id,player->GetZoneId(),g_team))
3521 PSendSysMessage(LANG_COMMAND_GRAVEYARDLINKED, g_id,zoneId);
3522 else
3523 PSendSysMessage(LANG_COMMAND_GRAVEYARDALRLINKED, g_id,zoneId);
3525 return true;
3528 bool ChatHandler::HandleNearGraveCommand(const char* args)
3530 uint32 g_team;
3532 size_t argslen = strlen(args);
3534 if(!*args)
3535 g_team = 0;
3536 else if (strncmp((char*)args,"horde",argslen)==0)
3537 g_team = HORDE;
3538 else if (strncmp((char*)args,"alliance",argslen)==0)
3539 g_team = ALLIANCE;
3540 else
3541 return false;
3543 Player* player = m_session->GetPlayer();
3545 WorldSafeLocsEntry const* graveyard = objmgr.GetClosestGraveYard(
3546 player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(),player->GetMapId(),g_team);
3548 if(graveyard)
3550 uint32 g_id = graveyard->ID;
3552 GraveYardData const* data = objmgr.FindGraveYardData(g_id,player->GetZoneId());
3553 if (!data)
3555 PSendSysMessage(LANG_COMMAND_GRAVEYARDERROR,g_id);
3556 SetSentErrorMessage(true);
3557 return false;
3560 g_team = data->team;
3562 std::string team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_NOTEAM);
3564 if(g_team == 0)
3565 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ANY);
3566 else if(g_team == HORDE)
3567 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE);
3568 else if(g_team == ALLIANCE)
3569 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE);
3571 PSendSysMessage(LANG_COMMAND_GRAVEYARDNEAREST, g_id,team_name.c_str(),player->GetZoneId());
3573 else
3575 std::string team_name;
3577 if(g_team == 0)
3578 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ANY);
3579 else if(g_team == HORDE)
3580 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE);
3581 else if(g_team == ALLIANCE)
3582 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE);
3584 if(g_team == ~uint32(0))
3585 PSendSysMessage(LANG_COMMAND_ZONENOGRAVEYARDS, player->GetZoneId());
3586 else
3587 PSendSysMessage(LANG_COMMAND_ZONENOGRAFACTION, player->GetZoneId(),team_name.c_str());
3590 return true;
3593 //play npc emote
3594 bool ChatHandler::HandlePlayEmoteCommand(const char* args)
3596 uint32 emote = atoi((char*)args);
3598 Creature* target = getSelectedCreature();
3599 if(!target)
3601 SendSysMessage(LANG_SELECT_CREATURE);
3602 SetSentErrorMessage(true);
3603 return false;
3606 target->SetUInt32Value(UNIT_NPC_EMOTESTATE,emote);
3608 return true;
3611 bool ChatHandler::HandleNpcInfoCommand(const char* /*args*/)
3613 Creature* target = getSelectedCreature();
3615 if(!target)
3617 SendSysMessage(LANG_SELECT_CREATURE);
3618 SetSentErrorMessage(true);
3619 return false;
3622 uint32 faction = target->getFaction();
3623 uint32 npcflags = target->GetUInt32Value(UNIT_NPC_FLAGS);
3624 uint32 displayid = target->GetDisplayId();
3625 uint32 nativeid = target->GetNativeDisplayId();
3626 uint32 Entry = target->GetEntry();
3627 CreatureInfo const* cInfo = target->GetCreatureInfo();
3629 int32 curRespawnDelay = target->GetRespawnTimeEx()-time(NULL);
3630 if(curRespawnDelay < 0)
3631 curRespawnDelay = 0;
3632 std::string curRespawnDelayStr = secsToTimeString(curRespawnDelay,true);
3633 std::string defRespawnDelayStr = secsToTimeString(target->GetRespawnDelay(),true);
3635 PSendSysMessage(LANG_NPCINFO_CHAR, target->GetDBTableGUIDLow(), faction, npcflags, Entry, displayid, nativeid);
3636 PSendSysMessage(LANG_NPCINFO_LEVEL, target->getLevel());
3637 PSendSysMessage(LANG_NPCINFO_HEALTH,target->GetCreateHealth(), target->GetMaxHealth(), target->GetHealth());
3638 PSendSysMessage(LANG_NPCINFO_FLAGS, target->GetUInt32Value(UNIT_FIELD_FLAGS), target->GetUInt32Value(UNIT_DYNAMIC_FLAGS), target->getFaction());
3639 PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES, defRespawnDelayStr.c_str(),curRespawnDelayStr.c_str());
3640 PSendSysMessage(LANG_NPCINFO_LOOT, cInfo->lootid,cInfo->pickpocketLootId,cInfo->SkinLootId);
3641 PSendSysMessage(LANG_NPCINFO_DUNGEON_ID, target->GetInstanceId());
3642 PSendSysMessage(LANG_NPCINFO_POSITION,float(target->GetPositionX()), float(target->GetPositionY()), float(target->GetPositionZ()));
3644 if ((npcflags & UNIT_NPC_FLAG_VENDOR) )
3646 SendSysMessage(LANG_NPCINFO_VENDOR);
3648 if ((npcflags & UNIT_NPC_FLAG_TRAINER) )
3650 SendSysMessage(LANG_NPCINFO_TRAINER);
3653 return true;
3656 bool ChatHandler::HandleExploreCheatCommand(const char* args)
3658 if (!*args)
3659 return false;
3661 int flag = atoi((char*)args);
3663 Player *chr = getSelectedPlayer();
3664 if (chr == NULL)
3666 SendSysMessage(LANG_NO_CHAR_SELECTED);
3667 SetSentErrorMessage(true);
3668 return false;
3671 if (flag != 0)
3673 PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL, chr->GetName());
3674 if(chr!=m_session->GetPlayer())
3675 ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_ALL,m_session->GetPlayer()->GetName());
3677 else
3679 PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING, chr->GetName());
3680 if(chr!=m_session->GetPlayer())
3681 ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_NOTHING,m_session->GetPlayer()->GetName());
3684 for (uint8 i=0; i<128; i++)
3686 if (flag != 0)
3688 m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1+i,0xFFFFFFFF);
3690 else
3692 m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1+i,0);
3696 return true;
3699 bool ChatHandler::HandleHoverCommand(const char* args)
3701 char* px = strtok((char*)args, " ");
3702 uint32 flag;
3703 if (!px)
3704 flag = 1;
3705 else
3706 flag = atoi(px);
3708 m_session->GetPlayer()->SetHover(flag);
3710 if (flag)
3711 SendSysMessage(LANG_HOVER_ENABLED);
3712 else
3713 SendSysMessage(LANG_HOVER_DISABLED);
3715 return true;
3718 bool ChatHandler::HandleLevelUpCommand(const char* args)
3720 char* px = strtok((char*)args, " ");
3721 char* py = strtok((char*)NULL, " ");
3723 // command format parsing
3724 char* pname = (char*)NULL;
3725 int addlevel = 1;
3727 if(px && py) // .levelup name level
3729 addlevel = atoi(py);
3730 pname = px;
3732 else if(px && !py) // .levelup name OR .levelup level
3734 if(isalpha(px[0])) // .levelup name
3735 pname = px;
3736 else // .levelup level
3737 addlevel = atoi(px);
3739 // else .levelup - nothing do for prepering
3741 // player
3742 Player *chr = NULL;
3743 uint64 chr_guid = 0;
3745 std::string name;
3747 if(pname) // player by name
3749 name = pname;
3750 if(!normalizePlayerName(name))
3752 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3753 SetSentErrorMessage(true);
3754 return false;
3757 chr = objmgr.GetPlayer(name.c_str());
3758 if(!chr) // not in game
3760 chr_guid = objmgr.GetPlayerGUIDByName(name);
3761 if (chr_guid == 0)
3763 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3764 SetSentErrorMessage(true);
3765 return false;
3769 else // player by selection
3771 chr = getSelectedPlayer();
3773 if (chr == NULL)
3775 SendSysMessage(LANG_NO_CHAR_SELECTED);
3776 SetSentErrorMessage(true);
3777 return false;
3780 name = chr->GetName();
3783 assert(chr || chr_guid);
3785 int32 oldlevel = chr ? chr->getLevel() : Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL,chr_guid);
3786 int32 newlevel = oldlevel + addlevel;
3787 if(newlevel < 1)
3788 newlevel = 1;
3789 if(newlevel > 255) // hardcoded maximum level
3790 newlevel = 255;
3792 if(chr)
3794 chr->GiveLevel(newlevel);
3795 chr->InitTalentForLevel();
3796 chr->SetUInt32Value(PLAYER_XP,0);
3798 if(oldlevel == newlevel)
3799 ChatHandler(chr).SendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET);
3800 else
3801 if(oldlevel < newlevel)
3802 ChatHandler(chr).PSendSysMessage(LANG_YOURS_LEVEL_UP,newlevel-oldlevel);
3803 else
3804 if(oldlevel > newlevel)
3805 ChatHandler(chr).PSendSysMessage(LANG_YOURS_LEVEL_DOWN,newlevel-oldlevel);
3807 else
3809 // update levle and XP at level, all other will be updated at loading
3810 Tokens values;
3811 Player::LoadValuesArrayFromDB(values,chr_guid);
3812 Player::SetUInt32ValueInArray(values,UNIT_FIELD_LEVEL,newlevel);
3813 Player::SetUInt32ValueInArray(values,PLAYER_XP,0);
3814 Player::SaveValuesArrayInDB(values,chr_guid);
3817 if(m_session->GetPlayer() != chr) // including chr==NULL
3818 PSendSysMessage(LANG_YOU_CHANGE_LVL,name.c_str(),newlevel);
3819 return true;
3822 bool ChatHandler::HandleShowAreaCommand(const char* args)
3824 if (!*args)
3825 return false;
3827 int area = atoi((char*)args);
3829 Player *chr = getSelectedPlayer();
3830 if (chr == NULL)
3832 SendSysMessage(LANG_NO_CHAR_SELECTED);
3833 SetSentErrorMessage(true);
3834 return false;
3837 int offset = area / 32;
3838 uint32 val = (uint32)(1 << (area % 32));
3840 if(offset >= 128)
3842 SendSysMessage(LANG_BAD_VALUE);
3843 SetSentErrorMessage(true);
3844 return false;
3847 uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
3848 chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields | val));
3850 SendSysMessage(LANG_EXPLORE_AREA);
3851 return true;
3854 bool ChatHandler::HandleHideAreaCommand(const char* args)
3856 if (!*args)
3857 return false;
3859 int area = atoi((char*)args);
3861 Player *chr = getSelectedPlayer();
3862 if (chr == NULL)
3864 SendSysMessage(LANG_NO_CHAR_SELECTED);
3865 SetSentErrorMessage(true);
3866 return false;
3869 int offset = area / 32;
3870 uint32 val = (uint32)(1 << (area % 32));
3872 if(offset >= 128)
3874 SendSysMessage(LANG_BAD_VALUE);
3875 SetSentErrorMessage(true);
3876 return false;
3879 uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
3880 chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields ^ val));
3882 SendSysMessage(LANG_UNEXPLORE_AREA);
3883 return true;
3886 bool ChatHandler::HandleUpdate(const char* args)
3888 if(!*args)
3889 return false;
3891 uint32 updateIndex;
3892 uint32 value;
3894 char* pUpdateIndex = strtok((char*)args, " ");
3896 Unit* chr = getSelectedUnit();
3897 if (chr == NULL)
3899 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3900 SetSentErrorMessage(true);
3901 return false;
3904 if(!pUpdateIndex)
3906 return true;
3908 updateIndex = atoi(pUpdateIndex);
3909 //check updateIndex
3910 if(chr->GetTypeId() == TYPEID_PLAYER)
3912 if (updateIndex>=PLAYER_END) return true;
3914 else
3916 if (updateIndex>=UNIT_END) return true;
3919 char* pvalue = strtok(NULL, " ");
3920 if (!pvalue)
3922 value=chr->GetUInt32Value(updateIndex);
3924 PSendSysMessage(LANG_UPDATE, chr->GetGUIDLow(),updateIndex,value);
3925 return true;
3928 value=atoi(pvalue);
3930 PSendSysMessage(LANG_UPDATE_CHANGE, chr->GetGUIDLow(),updateIndex,value);
3932 chr->SetUInt32Value(updateIndex,value);
3934 return true;
3937 bool ChatHandler::HandleBankCommand(const char* /*args*/)
3939 m_session->SendShowBank( m_session->GetPlayer()->GetGUID() );
3941 return true;
3944 bool ChatHandler::HandleChangeWeather(const char* args)
3946 if(!*args)
3947 return false;
3949 //Weather is OFF
3950 if (!sWorld.getConfig(CONFIG_WEATHER))
3952 SendSysMessage(LANG_WEATHER_DISABLED);
3953 SetSentErrorMessage(true);
3954 return false;
3957 //*Change the weather of a cell
3958 char* px = strtok((char*)args, " ");
3959 char* py = strtok(NULL, " ");
3961 if (!px || !py)
3962 return false;
3964 uint32 type = (uint32)atoi(px); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
3965 float grade = (float)atof(py); //0 to 1, sending -1 is instand good weather
3967 Player *player = m_session->GetPlayer();
3968 uint32 zoneid = player->GetZoneId();
3970 Weather* wth = sWorld.FindWeather(zoneid);
3972 if(!wth)
3973 wth = sWorld.AddWeather(zoneid);
3974 if(!wth)
3976 SendSysMessage(LANG_NO_WEATHER);
3977 SetSentErrorMessage(true);
3978 return false;
3981 wth->SetWeather(WeatherType(type), grade);
3983 return true;
3986 bool ChatHandler::HandleSetValue(const char* args)
3988 if(!*args)
3989 return false;
3991 char* px = strtok((char*)args, " ");
3992 char* py = strtok(NULL, " ");
3993 char* pz = strtok(NULL, " ");
3995 if (!px || !py)
3996 return false;
3998 Unit* target = getSelectedUnit();
3999 if(!target)
4001 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4002 SetSentErrorMessage(true);
4003 return false;
4006 uint64 guid = target->GetGUID();
4008 uint32 Opcode = (uint32)atoi(px);
4009 if(Opcode >= target->GetValuesCount())
4011 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, GUID_LOPART(guid), target->GetValuesCount());
4012 return false;
4014 uint32 iValue;
4015 float fValue;
4016 bool isint32 = true;
4017 if(pz)
4018 isint32 = (bool)atoi(pz);
4019 if(isint32)
4021 iValue = (uint32)atoi(py);
4022 sLog.outDebug(GetMangosString(LANG_SET_UINT), GUID_LOPART(guid), Opcode, iValue);
4023 target->SetUInt32Value( Opcode , iValue );
4024 PSendSysMessage(LANG_SET_UINT_FIELD, GUID_LOPART(guid), Opcode,iValue);
4026 else
4028 fValue = (float)atof(py);
4029 sLog.outDebug(GetMangosString(LANG_SET_FLOAT), GUID_LOPART(guid), Opcode, fValue);
4030 target->SetFloatValue( Opcode , fValue );
4031 PSendSysMessage(LANG_SET_FLOAT_FIELD, GUID_LOPART(guid), Opcode,fValue);
4034 return true;
4037 bool ChatHandler::HandleGetValue(const char* args)
4039 if(!*args)
4040 return false;
4042 char* px = strtok((char*)args, " ");
4043 char* pz = strtok(NULL, " ");
4045 if (!px)
4046 return false;
4048 Unit* target = getSelectedUnit();
4049 if(!target)
4051 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4052 SetSentErrorMessage(true);
4053 return false;
4056 uint64 guid = target->GetGUID();
4058 uint32 Opcode = (uint32)atoi(px);
4059 if(Opcode >= target->GetValuesCount())
4061 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, GUID_LOPART(guid), target->GetValuesCount());
4062 return false;
4064 uint32 iValue;
4065 float fValue;
4066 bool isint32 = true;
4067 if(pz)
4068 isint32 = (bool)atoi(pz);
4070 if(isint32)
4072 iValue = target->GetUInt32Value( Opcode );
4073 sLog.outDebug(GetMangosString(LANG_GET_UINT), GUID_LOPART(guid), Opcode, iValue);
4074 PSendSysMessage(LANG_GET_UINT_FIELD, GUID_LOPART(guid), Opcode, iValue);
4076 else
4078 fValue = target->GetFloatValue( Opcode );
4079 sLog.outDebug(GetMangosString(LANG_GET_FLOAT), GUID_LOPART(guid), Opcode, fValue);
4080 PSendSysMessage(LANG_GET_FLOAT_FIELD, GUID_LOPART(guid), Opcode, fValue);
4083 return true;
4086 bool ChatHandler::HandleSet32Bit(const char* args)
4088 if(!*args)
4089 return false;
4091 char* px = strtok((char*)args, " ");
4092 char* py = strtok(NULL, " ");
4094 if (!px || !py)
4095 return false;
4097 uint32 Opcode = (uint32)atoi(px);
4098 uint32 Value = (uint32)atoi(py);
4099 if (Value > 32) //uint32 = 32 bits
4100 return false;
4102 sLog.outDebug(GetMangosString(LANG_SET_32BIT), Opcode, Value);
4104 m_session->GetPlayer( )->SetUInt32Value( Opcode , 2^Value );
4106 PSendSysMessage(LANG_SET_32BIT_FIELD, Opcode,1);
4107 return true;
4110 bool ChatHandler::HandleMod32Value(const char* args)
4112 if(!*args)
4113 return false;
4115 char* px = strtok((char*)args, " ");
4116 char* py = strtok(NULL, " ");
4118 if (!px || !py)
4119 return false;
4121 uint32 Opcode = (uint32)atoi(px);
4122 int Value = atoi(py);
4124 if(Opcode >= m_session->GetPlayer()->GetValuesCount())
4126 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, m_session->GetPlayer()->GetGUIDLow(), m_session->GetPlayer( )->GetValuesCount());
4127 return false;
4130 sLog.outDebug(GetMangosString(LANG_CHANGE_32BIT), Opcode, Value);
4132 int CurrentValue = (int)m_session->GetPlayer( )->GetUInt32Value( Opcode );
4134 CurrentValue += Value;
4135 m_session->GetPlayer( )->SetUInt32Value( Opcode , (uint32)CurrentValue );
4137 PSendSysMessage(LANG_CHANGE_32BIT_FIELD, Opcode,CurrentValue);
4139 return true;
4142 bool ChatHandler::HandleAddTeleCommand(const char * args)
4144 if(!*args)
4145 return false;
4147 Player *player=m_session->GetPlayer();
4148 if (!player)
4149 return false;
4151 std::string name = args;
4153 if(objmgr.GetGameTele(name))
4155 SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST);
4156 SetSentErrorMessage(true);
4157 return false;
4160 GameTele tele;
4161 tele.position_x = player->GetPositionX();
4162 tele.position_y = player->GetPositionY();
4163 tele.position_z = player->GetPositionZ();
4164 tele.orientation = player->GetOrientation();
4165 tele.mapId = player->GetMapId();
4166 tele.name = name;
4168 if(objmgr.AddGameTele(tele))
4170 SendSysMessage(LANG_COMMAND_TP_ADDED);
4172 else
4174 SendSysMessage(LANG_COMMAND_TP_ADDEDERR);
4175 SetSentErrorMessage(true);
4176 return false;
4179 return true;
4182 bool ChatHandler::HandleDelTeleCommand(const char * args)
4184 if(!*args)
4185 return false;
4187 std::string name = args;
4189 if(!objmgr.DeleteGameTele(name))
4191 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
4192 SetSentErrorMessage(true);
4193 return false;
4196 SendSysMessage(LANG_COMMAND_TP_DELETED);
4197 return true;
4200 bool ChatHandler::HandleListAurasCommand (const char * /*args*/)
4202 Unit *unit = getSelectedUnit();
4203 if(!unit)
4205 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4206 SetSentErrorMessage(true);
4207 return false;
4210 char const* talentStr = GetMangosString(LANG_TALENT);
4211 char const* passiveStr = GetMangosString(LANG_PASSIVE);
4213 Unit::AuraMap const& uAuras = unit->GetAuras();
4214 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS, uAuras.size());
4215 for (Unit::AuraMap::const_iterator itr = uAuras.begin(); itr != uAuras.end(); ++itr)
4217 bool talent = GetTalentSpellCost(itr->second->GetId()) > 0;
4218 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL, itr->second->GetId(), itr->second->GetEffIndex(),
4219 itr->second->GetModifier()->m_auraname, itr->second->GetAuraDuration(), itr->second->GetAuraMaxDuration(),
4220 itr->second->GetSpellProto()->SpellName[m_session->GetSessionDbcLocale()],
4221 (itr->second->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4222 IS_PLAYER_GUID(itr->second->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr->second->GetCasterGUID()));
4224 for (int i = 0; i < TOTAL_AURAS; i++)
4226 Unit::AuraList const& uAuraList = unit->GetAurasByType(AuraType(i));
4227 if (uAuraList.empty()) continue;
4228 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE, uAuraList.size(), i);
4229 for (Unit::AuraList::const_iterator itr = uAuraList.begin(); itr != uAuraList.end(); ++itr)
4231 bool talent = GetTalentSpellCost((*itr)->GetId()) > 0;
4232 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE, (*itr)->GetId(), (*itr)->GetEffIndex(),
4233 (*itr)->GetSpellProto()->SpellName[m_session->GetSessionDbcLocale()],((*itr)->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4234 IS_PLAYER_GUID((*itr)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr)->GetCasterGUID()));
4237 return true;
4240 bool ChatHandler::HandleResetHonorCommand (const char * args)
4242 char* pName = strtok((char*)args, "");
4243 Player *player = NULL;
4244 if (pName)
4246 std::string name = pName;
4247 if(!normalizePlayerName(name))
4249 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4250 SetSentErrorMessage(true);
4251 return false;
4254 uint64 guid = objmgr.GetPlayerGUIDByName(name.c_str());
4255 player = objmgr.GetPlayer(guid);
4257 else
4258 player = getSelectedPlayer();
4260 if(!player)
4262 SendSysMessage(LANG_NO_CHAR_SELECTED);
4263 return true;
4266 player->SetUInt32Value(PLAYER_FIELD_KILLS, 0);
4267 player->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS, 0);
4268 player->SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY, 0);
4269 player->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION, 0);
4270 player->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION, 0);
4272 return true;
4275 static bool HandleResetStatsOrLevelHelper(Player* player)
4277 PlayerInfo const *info = objmgr.GetPlayerInfo(player->getRace(), player->getClass());
4278 if(!info) return false;
4280 ChrClassesEntry const* cEntry = sChrClassesStore.LookupEntry(player->getClass());
4281 if(!cEntry)
4283 sLog.outError("Class %u not found in DBC (Wrong DBC files?)",player->getClass());
4284 return false;
4287 uint8 powertype = cEntry->powerType;
4289 uint32 unitfield;
4290 if(powertype == POWER_RAGE)
4291 unitfield = 0x1100EE00;
4292 else if(powertype == POWER_ENERGY)
4293 unitfield = 0x00000000;
4294 else if(powertype == POWER_MANA)
4295 unitfield = 0x0000EE00;
4296 else
4298 sLog.outError("Invalid default powertype %u for player (class %u)",powertype,player->getClass());
4299 return false;
4302 // reset m_form if no aura
4303 if(!player->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT))
4304 player->m_form = FORM_NONE;
4306 player->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, DEFAULT_WORLD_OBJECT_SIZE );
4307 player->SetFloatValue(UNIT_FIELD_COMBATREACH, 1.5f );
4309 player->setFactionForRace(player->getRace());
4311 player->SetUInt32Value(UNIT_FIELD_BYTES_0, ( ( player->getRace() ) | ( player->getClass() << 8 ) | ( player->getGender() << 16 ) | ( powertype << 24 ) ) );
4313 // reset only if player not in some form;
4314 if(player->m_form==FORM_NONE)
4316 switch(player->getGender())
4318 case GENDER_FEMALE:
4319 player->SetDisplayId(info->displayId_f);
4320 player->SetNativeDisplayId(info->displayId_f);
4321 break;
4322 case GENDER_MALE:
4323 player->SetDisplayId(info->displayId_m);
4324 player->SetNativeDisplayId(info->displayId_m);
4325 break;
4326 default:
4327 break;
4331 // set UNIT_FIELD_BYTES_1 to init state but preserve m_form value
4332 player->SetUInt32Value(UNIT_FIELD_BYTES_1, unitfield);
4333 player->SetByteValue(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_UNK3 | UNIT_BYTE2_FLAG_UNK5 );
4334 player->SetByteValue(UNIT_FIELD_BYTES_2, 3, player->m_form);
4336 player->SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
4338 //-1 is default value
4339 player->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX, uint32(-1));
4341 //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000 );
4342 return true;
4345 bool ChatHandler::HandleResetLevelCommand(const char * args)
4347 char* pName = strtok((char*)args, "");
4348 Player *player = NULL;
4349 if (pName)
4351 std::string name = pName;
4352 if(!normalizePlayerName(name))
4354 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4355 SetSentErrorMessage(true);
4356 return false;
4359 uint64 guid = objmgr.GetPlayerGUIDByName(name.c_str());
4360 player = objmgr.GetPlayer(guid);
4362 else
4363 player = getSelectedPlayer();
4365 if(!player)
4367 SendSysMessage(LANG_NO_CHAR_SELECTED);
4368 SetSentErrorMessage(true);
4369 return false;
4372 if(!HandleResetStatsOrLevelHelper(player))
4373 return false;
4375 player->SetLevel(1);
4376 player->InitStatsForLevel(true);
4377 player->InitTaxiNodesForLevel();
4378 player->InitTalentForLevel();
4379 player->SetUInt32Value(PLAYER_XP,0);
4381 // reset level to summoned pet
4382 Pet* pet = player->GetPet();
4383 if(pet && pet->getPetType()==SUMMON_PET)
4384 pet->InitStatsForLevel(1);
4386 return true;
4389 bool ChatHandler::HandleResetStatsCommand(const char * args)
4391 char* pName = strtok((char*)args, "");
4392 Player *player = NULL;
4393 if (pName)
4395 std::string name = pName;
4396 if(!normalizePlayerName(name))
4398 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4399 SetSentErrorMessage(true);
4400 return false;
4403 uint64 guid = objmgr.GetPlayerGUIDByName(name.c_str());
4404 player = objmgr.GetPlayer(guid);
4406 else
4407 player = getSelectedPlayer();
4409 if(!player)
4411 SendSysMessage(LANG_NO_CHAR_SELECTED);
4412 SetSentErrorMessage(true);
4413 return false;
4416 if(!HandleResetStatsOrLevelHelper(player))
4417 return false;
4419 player->InitStatsForLevel(true);
4420 player->InitTaxiNodesForLevel();
4421 player->InitTalentForLevel();
4423 return true;
4426 bool ChatHandler::HandleResetSpellsCommand(const char * args)
4428 char* pName = strtok((char*)args, "");
4429 Player *player = NULL;
4430 uint64 playerGUID = 0;
4431 if (pName)
4433 std::string name = pName;
4435 if(!normalizePlayerName(name))
4437 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4438 SetSentErrorMessage(true);
4439 return false;
4442 player = objmgr.GetPlayer(name.c_str());
4443 if(!player)
4444 playerGUID = objmgr.GetPlayerGUIDByName(name.c_str());
4446 else
4447 player = getSelectedPlayer();
4449 if(!player && !playerGUID)
4451 SendSysMessage(LANG_NO_CHAR_SELECTED);
4452 SetSentErrorMessage(true);
4453 return false;
4456 if(player)
4458 player->resetSpells();
4460 ChatHandler(player).SendSysMessage(LANG_RESET_SPELLS);
4462 if(m_session->GetPlayer()!=player)
4463 PSendSysMessage(LANG_RESET_SPELLS_ONLINE,player->GetName());
4465 else
4467 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS), GUID_LOPART(playerGUID));
4468 PSendSysMessage(LANG_RESET_SPELLS_OFFLINE,pName);
4471 return true;
4474 bool ChatHandler::HandleResetTalentsCommand(const char * args)
4476 char* pName = strtok((char*)args, "");
4477 Player *player = NULL;
4478 uint64 playerGUID = 0;
4479 if (pName)
4481 std::string name = pName;
4482 if(!normalizePlayerName(name))
4484 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4485 SetSentErrorMessage(true);
4486 return false;
4489 player = objmgr.GetPlayer(name.c_str());
4490 if(!player)
4491 playerGUID = objmgr.GetPlayerGUIDByName(name.c_str());
4493 else
4494 player = getSelectedPlayer();
4496 if(!player && !playerGUID)
4498 SendSysMessage(LANG_NO_CHAR_SELECTED);
4499 SetSentErrorMessage(true);
4500 return false;
4503 if(player)
4505 player->resetTalents(true);
4507 ChatHandler(player).SendSysMessage(LANG_RESET_TALENTS);
4509 if(m_session->GetPlayer()!=player)
4510 PSendSysMessage(LANG_RESET_TALENTS_ONLINE,player->GetName());
4512 else
4514 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_TALENTS), GUID_LOPART(playerGUID) );
4515 PSendSysMessage(LANG_RESET_TALENTS_OFFLINE,pName);
4518 return true;
4521 bool ChatHandler::HandleResetAllCommand(const char * args)
4523 if(!*args)
4524 return false;
4526 std::string casename = args;
4528 AtLoginFlags atLogin;
4530 // Command specially created as single command to prevent using short case names
4531 if(casename=="spells")
4533 atLogin = AT_LOGIN_RESET_SPELLS;
4534 sWorld.SendWorldText(LANG_RESETALL_SPELLS);
4536 else if(casename=="talents")
4538 atLogin = AT_LOGIN_RESET_TALENTS;
4539 sWorld.SendWorldText(LANG_RESETALL_TALENTS);
4541 else
4543 PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE,args);
4544 SetSentErrorMessage(true);
4545 return false;
4548 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u'",atLogin);
4549 HashMapHolder<Player>::MapType const& plist = ObjectAccessor::Instance().GetPlayers();
4550 for(HashMapHolder<Player>::MapType::const_iterator itr = plist.begin(); itr != plist.end(); ++itr)
4551 itr->second->SetAtLoginFlag(atLogin);
4553 return true;
4556 bool ChatHandler::HandleShutDownCommand(const char* args)
4558 if(!*args)
4559 return false;
4561 if(std::string(args)=="cancel")
4563 sWorld.ShutdownCancel();
4565 else
4567 int32 time = atoi(args);
4569 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4570 if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
4571 return false;
4573 sWorld.ShutdownServ(time);
4575 return true;
4578 bool ChatHandler::HandleRestartCommand(const char* args)
4580 if(!*args)
4581 return false;
4583 if(std::string(args)=="cancel")
4585 sWorld.ShutdownCancel();
4587 else
4589 int32 time = atoi(args);
4591 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4592 if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
4593 return false;
4595 sWorld.ShutdownServ(time, SHUTDOWN_MASK_RESTART);
4597 return true;
4600 bool ChatHandler::HandleIdleRestartCommand(const char* args)
4602 if(!*args)
4603 return false;
4605 if(std::string(args)=="cancel")
4607 sWorld.ShutdownCancel();
4609 else
4611 int32 time = atoi(args);
4613 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4614 if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
4615 return false;
4617 sWorld.ShutdownServ(time,SHUTDOWN_MASK_RESTART+SHUTDOWN_MASK_IDLE);
4619 return true;
4622 bool ChatHandler::HandleIdleShutDownCommand(const char* args)
4624 if(!*args)
4625 return false;
4627 if(std::string(args)=="cancel")
4629 sWorld.ShutdownCancel();
4631 else
4633 int32 time = atoi(args);
4635 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4636 if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
4637 return false;
4639 sWorld.ShutdownServ(time,SHUTDOWN_MASK_IDLE);
4641 return true;
4644 bool ChatHandler::HandleAddQuest(const char* args)
4646 Player* player = getSelectedPlayer();
4647 if(!player)
4649 SendSysMessage(LANG_NO_CHAR_SELECTED);
4650 SetSentErrorMessage(true);
4651 return false;
4654 // .addquest #entry'
4655 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4656 char* cId = extractKeyFromLink((char*)args,"Hquest");
4657 if(!cId)
4658 return false;
4660 uint32 entry = atol(cId);
4662 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
4664 if(!pQuest)
4666 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND,entry);
4667 SetSentErrorMessage(true);
4668 return false;
4671 // check item starting quest (it can work incorrectly if added without item in inventory)
4672 QueryResult *result = WorldDatabase.PQuery("SELECT entry FROM item_template WHERE startquest = '%u' LIMIT 1",entry);
4673 if(result)
4675 Field* fields = result->Fetch();
4676 uint32 item_id = fields[0].GetUInt32();
4677 delete result;
4679 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, entry,item_id);
4680 SetSentErrorMessage(true);
4681 return false;
4684 // ok, normal (creature/GO starting) quest
4685 if( player->CanAddQuest( pQuest, true ) )
4687 player->AddQuest( pQuest, NULL );
4689 if ( player->CanCompleteQuest( entry ) )
4690 player->CompleteQuest( entry );
4693 return true;
4696 bool ChatHandler::HandleRemoveQuest(const char* args)
4698 Player* player = getSelectedPlayer();
4699 if(!player)
4701 SendSysMessage(LANG_NO_CHAR_SELECTED);
4702 SetSentErrorMessage(true);
4703 return false;
4706 // .removequest #entry'
4707 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4708 char* cId = extractKeyFromLink((char*)args,"Hquest");
4709 if(!cId)
4710 return false;
4712 uint32 entry = atol(cId);
4714 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
4716 if(!pQuest)
4718 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
4719 SetSentErrorMessage(true);
4720 return false;
4723 // remove all quest entries for 'entry' from quest log
4724 for(uint8 slot = 0; slot < MAX_QUEST_LOG_SIZE; ++slot )
4726 uint32 quest = player->GetQuestSlotQuestId(slot);
4727 if(quest==entry)
4729 player->SetQuestSlot(slot,0);
4731 // we ignore unequippable quest items in this case, its' still be equipped
4732 player->TakeQuestSourceItem( quest, false );
4736 // set quest status to not started (will updated in DB at next save)
4737 player->SetQuestStatus( entry, QUEST_STATUS_NONE);
4739 // reset rewarded for restart repeatable quest
4740 player->getQuestStatusMap()[entry].m_rewarded = false;
4742 SendSysMessage(LANG_COMMAND_QUEST_REMOVED);
4743 return true;
4746 bool ChatHandler::HandleCompleteQuest(const char* args)
4748 Player* player = getSelectedPlayer();
4749 if(!player)
4751 SendSysMessage(LANG_NO_CHAR_SELECTED);
4752 SetSentErrorMessage(true);
4753 return false;
4756 // .quest complete #entry
4757 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4758 char* cId = extractKeyFromLink((char*)args,"Hquest");
4759 if(!cId)
4760 return false;
4762 uint32 entry = atol(cId);
4764 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
4766 // If player doesn't have the quest
4767 if(!pQuest || player->GetQuestStatus(entry) == QUEST_STATUS_NONE)
4769 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
4770 SetSentErrorMessage(true);
4771 return false;
4774 // Add quest items for quests that require items
4775 for(uint8 x = 0; x < QUEST_OBJECTIVES_COUNT; ++x)
4777 uint32 id = pQuest->ReqItemId[x];
4778 uint32 count = pQuest->ReqItemCount[x];
4779 if(!id || !count)
4780 continue;
4782 uint32 curItemCount = player->GetItemCount(id,true);
4784 ItemPosCountVec dest;
4785 uint8 msg = player->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, id, count-curItemCount );
4786 if( msg == EQUIP_ERR_OK )
4788 Item* item = player->StoreNewItem( dest, id, true);
4789 player->SendNewItem(item,count-curItemCount,true,false);
4793 // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
4794 for(uint8 i = 0; i < QUEST_OBJECTIVES_COUNT; i++)
4796 uint32 creature = pQuest->ReqCreatureOrGOId[i];
4797 uint32 creaturecount = pQuest->ReqCreatureOrGOCount[i];
4799 if(uint32 spell_id = pQuest->ReqSpell[i])
4801 for(uint16 z = 0; z < creaturecount; ++z)
4802 player->CastedCreatureOrGO(creature,0,spell_id);
4804 else if(creature > 0)
4806 for(uint16 z = 0; z < creaturecount; ++z)
4807 player->KilledMonster(creature,0);
4809 else if(creature < 0)
4811 for(uint16 z = 0; z < creaturecount; ++z)
4812 player->CastedCreatureOrGO(creature,0,0);
4816 // If the quest requires reputation to complete
4817 if(uint32 repFaction = pQuest->GetRepObjectiveFaction())
4819 uint32 repValue = pQuest->GetRepObjectiveValue();
4820 uint32 curRep = player->GetReputation(repFaction);
4821 if(curRep < repValue)
4823 FactionEntry const *factionEntry = sFactionStore.LookupEntry(repFaction);
4824 player->SetFactionReputation(factionEntry,repValue);
4828 // If the quest requires money
4829 int32 ReqOrRewMoney = pQuest->GetRewOrReqMoney();
4830 if(ReqOrRewMoney < 0)
4831 player->ModifyMoney(-ReqOrRewMoney);
4833 player->CompleteQuest(entry);
4834 return true;
4837 bool ChatHandler::HandleBanAccountCommand(const char* args)
4839 return HandleBanHelper(BAN_ACCOUNT,args);
4842 bool ChatHandler::HandleBanCharacterCommand(const char* args)
4844 return HandleBanHelper(BAN_CHARACTER,args);
4847 bool ChatHandler::HandleBanIPCommand(const char* args)
4849 return HandleBanHelper(BAN_IP,args);
4852 bool ChatHandler::HandleBanHelper(BanMode mode, const char* args)
4854 if(!args)
4855 return false;
4857 char* cnameOrIP = strtok ((char*)args, " ");
4858 if (!cnameOrIP)
4859 return false;
4861 std::string nameOrIP = cnameOrIP;
4863 char* duration = strtok (NULL," ");
4864 if(!duration || !atoi(duration))
4865 return false;
4867 char* reason = strtok (NULL,"");
4868 if(!reason)
4869 return false;
4871 switch(mode)
4873 case BAN_ACCOUNT:
4874 if(!AccountMgr::normilizeString(nameOrIP))
4876 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str());
4877 SetSentErrorMessage(true);
4878 return false;
4880 break;
4881 case BAN_CHARACTER:
4882 if(!normalizePlayerName(nameOrIP))
4884 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4885 SetSentErrorMessage(true);
4886 return false;
4888 break;
4889 case BAN_IP:
4890 if(!IsIPAddress(nameOrIP.c_str()))
4891 return false;
4892 break;
4895 switch(sWorld.BanAccount(mode, nameOrIP, duration, reason,m_session ? m_session->GetPlayerName() : ""))
4897 case BAN_SUCCESS:
4898 if(atoi(duration)>0)
4899 PSendSysMessage(LANG_BAN_YOUBANNED,nameOrIP.c_str(),secsToTimeString(TimeStringToSecs(duration),true).c_str(),reason);
4900 else
4901 PSendSysMessage(LANG_BAN_YOUPERMBANNED,nameOrIP.c_str(),reason);
4902 break;
4903 case BAN_SYNTAX_ERROR:
4904 return false;
4905 case BAN_NOTFOUND:
4906 switch(mode)
4908 default:
4909 PSendSysMessage(LANG_BAN_NOTFOUND,"account",nameOrIP.c_str());
4910 break;
4911 case BAN_CHARACTER:
4912 PSendSysMessage(LANG_BAN_NOTFOUND,"character",nameOrIP.c_str());
4913 break;
4914 case BAN_IP:
4915 PSendSysMessage(LANG_BAN_NOTFOUND,"ip",nameOrIP.c_str());
4916 break;
4918 SetSentErrorMessage(true);
4919 return false;
4922 return true;
4925 bool ChatHandler::HandleUnBanAccountCommand(const char* args)
4927 return HandleUnBanHelper(BAN_ACCOUNT,args);
4930 bool ChatHandler::HandleUnBanCharacterCommand(const char* args)
4932 return HandleUnBanHelper(BAN_CHARACTER,args);
4935 bool ChatHandler::HandleUnBanIPCommand(const char* args)
4937 return HandleUnBanHelper(BAN_IP,args);
4940 bool ChatHandler::HandleUnBanHelper(BanMode mode, const char* args)
4942 if(!args)
4943 return false;
4945 char* cnameOrIP = strtok ((char*)args, " ");
4946 if(!cnameOrIP)
4947 return false;
4949 std::string nameOrIP = cnameOrIP;
4951 switch(mode)
4953 case BAN_ACCOUNT:
4954 if(!AccountMgr::normilizeString(nameOrIP))
4956 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str());
4957 SetSentErrorMessage(true);
4958 return false;
4960 break;
4961 case BAN_CHARACTER:
4962 if(!normalizePlayerName(nameOrIP))
4964 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4965 SetSentErrorMessage(true);
4966 return false;
4968 break;
4969 case BAN_IP:
4970 if(!IsIPAddress(nameOrIP.c_str()))
4971 return false;
4972 break;
4975 if(sWorld.RemoveBanAccount(mode,nameOrIP))
4976 PSendSysMessage(LANG_UNBAN_UNBANNED,nameOrIP.c_str());
4977 else
4978 PSendSysMessage(LANG_UNBAN_ERROR,nameOrIP.c_str());
4980 return true;
4983 bool ChatHandler::HandleBanInfoAccountCommand(const char* args)
4985 if(!args)
4986 return false;
4988 char* cname = strtok((char*)args, "");
4989 if(!cname)
4990 return false;
4992 std::string account_name = cname;
4993 if(!AccountMgr::normilizeString(account_name))
4995 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
4996 SetSentErrorMessage(true);
4997 return false;
5000 uint32 accountid = accmgr.GetId(account_name);
5001 if(!accountid)
5003 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5004 return true;
5007 return HandleBanInfoHelper(accountid,account_name.c_str());
5010 bool ChatHandler::HandleBanInfoCharacterCommand(const char* args)
5012 if(!args)
5013 return false;
5015 char* cname = strtok ((char*)args, "");
5016 if(!cname)
5017 return false;
5019 std::string name = cname;
5020 if(!normalizePlayerName(name))
5022 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5023 SetSentErrorMessage(true);
5024 return false;
5027 uint32 accountid = objmgr.GetPlayerAccountIdByPlayerName(name);
5028 if(!accountid)
5030 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5031 SetSentErrorMessage(true);
5032 return false;
5035 std::string accountname;
5036 if(!accmgr.GetName(accountid,accountname))
5038 PSendSysMessage(LANG_BANINFO_NOCHARACTER);
5039 return true;
5042 return HandleBanInfoHelper(accountid,accountname.c_str());
5045 bool ChatHandler::HandleBanInfoHelper(uint32 accountid, char const* accountname)
5047 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);
5048 if(!result)
5050 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN, accountname);
5051 return true;
5054 PSendSysMessage(LANG_BANINFO_BANHISTORY,accountname);
5057 Field* fields = result->Fetch();
5059 time_t unbandate = time_t(fields[3].GetUInt64());
5060 bool active = false;
5061 if(fields[2].GetBool() && (fields[1].GetUInt64() == (uint64)0 ||unbandate >= time(NULL)) )
5062 active = true;
5063 bool permanent = (fields[1].GetUInt64() == (uint64)0);
5064 std::string bantime = permanent?GetMangosString(LANG_BANINFO_INFINITE):secsToTimeString(fields[1].GetUInt64(), true);
5065 PSendSysMessage(LANG_BANINFO_HISTORYENTRY,
5066 fields[0].GetString(), bantime.c_str(), active ? GetMangosString(LANG_BANINFO_YES):GetMangosString(LANG_BANINFO_NO), fields[4].GetString(), fields[5].GetString());
5067 }while (result->NextRow());
5069 delete result;
5070 return true;
5073 bool ChatHandler::HandleBanInfoIPCommand(const char* args)
5075 if(!args)
5076 return false;
5078 char* cIP = strtok ((char*)args, "");
5079 if(!cIP)
5080 return false;
5082 if (!IsIPAddress(cIP))
5083 return false;
5085 std::string IP = cIP;
5087 loginDatabase.escape_string(IP);
5088 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());
5089 if(!result)
5091 PSendSysMessage(LANG_BANINFO_NOIP);
5092 return true;
5095 Field *fields = result->Fetch();
5096 bool permanent = !fields[6].GetUInt64();
5097 PSendSysMessage(LANG_BANINFO_IPENTRY,
5098 fields[0].GetString(), fields[1].GetString(), permanent ? GetMangosString(LANG_BANINFO_NEVER):fields[2].GetString(),
5099 permanent ? GetMangosString(LANG_BANINFO_INFINITE):secsToTimeString(fields[3].GetUInt64(), true).c_str(), fields[4].GetString(), fields[5].GetString());
5100 delete result;
5101 return true;
5104 bool ChatHandler::HandleBanListCharacterCommand(const char* args)
5106 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5108 char* cFilter = strtok ((char*)args, " ");
5109 if(!cFilter)
5110 return false;
5112 std::string filter = cFilter;
5113 loginDatabase.escape_string(filter);
5114 QueryResult* result = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'"),filter.c_str());
5115 if (!result)
5117 PSendSysMessage(LANG_BANLIST_NOCHARACTER);
5118 return true;
5121 return HandleBanListHelper(result);
5124 bool ChatHandler::HandleBanListAccountCommand(const char* args)
5126 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5128 char* cFilter = strtok((char*)args, " ");
5129 std::string filter = cFilter ? cFilter : "";
5130 loginDatabase.escape_string(filter);
5132 QueryResult* result;
5134 if(filter.empty())
5136 result = loginDatabase.Query("SELECT account.id, username FROM account, account_banned"
5137 " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
5139 else
5141 result = loginDatabase.PQuery("SELECT account.id, username FROM account, account_banned"
5142 " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
5143 filter.c_str());
5146 if (!result)
5148 PSendSysMessage(LANG_BANLIST_NOACCOUNT);
5149 return true;
5152 return HandleBanListHelper(result);
5155 bool ChatHandler::HandleBanListHelper(QueryResult* result)
5157 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT);
5159 // Chat short output
5160 if(m_session)
5164 Field* fields = result->Fetch();
5165 uint32 accountid = fields[0].GetUInt32();
5167 QueryResult* banresult = loginDatabase.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid);
5168 if(banresult)
5170 Field* fields2 = banresult->Fetch();
5171 PSendSysMessage("%s",fields2[0].GetString());
5172 delete banresult;
5174 } while (result->NextRow());
5176 // Console wide output
5177 else
5179 SendSysMessage(LANG_BANLIST_ACCOUNTS);
5180 SendSysMessage("===============================================================================");
5181 SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER);
5184 SendSysMessage("-------------------------------------------------------------------------------");
5185 Field *fields = result->Fetch();
5186 uint32 account_id = fields[0].GetUInt32 ();
5188 std::string account_name;
5190 // "account" case, name can be get in same quary
5191 if(result->GetFieldCount() > 1)
5192 account_name = fields[1].GetCppString();
5193 // "character" case, name need extract from another DB
5194 else
5195 accmgr.GetName (account_id,account_name);
5197 // No SQL injection. id is uint32.
5198 QueryResult *banInfo = loginDatabase.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id);
5199 if (banInfo)
5201 Field *fields2 = banInfo->Fetch();
5204 time_t t_ban = fields2[0].GetUInt64();
5205 tm* aTm_ban = localtime(&t_ban);
5207 if (fields2[0].GetUInt64() == fields2[1].GetUInt64())
5209 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5210 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,
5211 fields2[2].GetString(),fields2[3].GetString());
5213 else
5215 time_t t_unban = fields2[1].GetUInt64();
5216 tm* aTm_unban = localtime(&t_unban);
5217 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5218 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,
5219 aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
5220 fields2[2].GetString(),fields2[3].GetString());
5222 }while ( banInfo->NextRow() );
5223 delete banInfo;
5225 }while( result->NextRow() );
5226 SendSysMessage("===============================================================================");
5229 delete result;
5230 return true;
5233 bool ChatHandler::HandleBanListIPCommand(const char* args)
5235 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5237 char* cFilter = strtok((char*)args, " ");
5238 std::string filter = cFilter ? cFilter : "";
5239 loginDatabase.escape_string(filter);
5241 QueryResult* result;
5243 if(filter.empty())
5245 result = loginDatabase.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5246 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
5247 " ORDER BY unbandate" );
5249 else
5251 result = loginDatabase.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5252 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")
5253 " ORDER BY unbandate",filter.c_str() );
5256 if(!result)
5258 PSendSysMessage(LANG_BANLIST_NOIP);
5259 return true;
5262 PSendSysMessage(LANG_BANLIST_MATCHINGIP);
5263 // Chat short output
5264 if(m_session)
5268 Field* fields = result->Fetch();
5269 PSendSysMessage("%s",fields[0].GetString());
5270 } while (result->NextRow());
5272 // Console wide output
5273 else
5275 SendSysMessage(LANG_BANLIST_IPS);
5276 SendSysMessage("===============================================================================");
5277 SendSysMessage(LANG_BANLIST_IPS_HEADER);
5280 SendSysMessage("-------------------------------------------------------------------------------");
5281 Field *fields = result->Fetch();
5282 time_t t_ban = fields[1].GetUInt64();
5283 tm* aTm_ban = localtime(&t_ban);
5284 if ( fields[1].GetUInt64() == fields[2].GetUInt64() )
5286 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5287 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,
5288 fields[3].GetString(), fields[4].GetString());
5290 else
5292 time_t t_unban = fields[2].GetUInt64();
5293 tm* aTm_unban = localtime(&t_unban);
5294 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5295 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,
5296 aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
5297 fields[3].GetString(), fields[4].GetString());
5299 }while( result->NextRow() );
5300 SendSysMessage("===============================================================================");
5303 delete result;
5304 return true;
5307 bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
5309 Player* pl = m_session->GetPlayer();
5311 CellPair p(MaNGOS::ComputeCellPair(pl->GetPositionX(), pl->GetPositionY()));
5312 Cell cell(p);
5313 cell.data.Part.reserved = ALL_DISTRICT;
5314 cell.SetNoCreate();
5316 MaNGOS::RespawnDo u_do;
5317 MaNGOS::WorldObjectWorker<MaNGOS::RespawnDo> worker(u_do);
5319 TypeContainerVisitor<MaNGOS::WorldObjectWorker<MaNGOS::RespawnDo>, GridTypeMapContainer > obj_worker(worker);
5320 CellLock<GridReadGuard> cell_lock(cell, p);
5321 cell_lock->Visit(cell_lock, obj_worker, *MapManager::Instance().GetMap(pl->GetMapId(), pl));
5323 return true;
5326 bool ChatHandler::HandleFlyModeCommand(const char* args)
5328 if(!args)
5329 return false;
5331 Unit *unit = getSelectedUnit();
5332 if (!unit || (unit->GetTypeId() != TYPEID_PLAYER))
5333 unit = m_session->GetPlayer();
5335 WorldPacket data(12);
5336 if (strncmp(args, "on", 3) == 0)
5337 data.SetOpcode(SMSG_MOVE_SET_CAN_FLY);
5338 else if (strncmp(args, "off", 4) == 0)
5339 data.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY);
5340 else
5342 SendSysMessage(LANG_USE_BOL);
5343 return false;
5345 data.append(unit->GetPackGUID());
5346 data << uint32(0); // unknown
5347 unit->SendMessageToSet(&data, true);
5348 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS, unit->GetName(), args);
5349 return true;
5352 bool ChatHandler::HandleLoadPDumpCommand(const char *args)
5354 if(!args)
5355 return false;
5357 char * file = strtok((char*)args, " ");
5358 if(!file)
5359 return false;
5361 char * account = strtok(NULL, " ");
5362 if(!account)
5363 return false;
5365 std::string account_name = account;
5366 if(!AccountMgr::normilizeString(account_name))
5368 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5369 SetSentErrorMessage(true);
5370 return false;
5373 uint32 account_id = accmgr.GetId(account_name);
5374 if(!account_id)
5376 account_id = atoi(account); // use original string
5377 if(!account_id)
5379 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5380 SetSentErrorMessage(true);
5381 return false;
5385 if(!accmgr.GetName(account_id,account_name))
5387 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5388 SetSentErrorMessage(true);
5389 return false;
5392 char* guid_str = NULL;
5393 char* name_str = strtok(NULL, " ");
5395 std::string name;
5396 if(name_str)
5398 name = name_str;
5399 // normalize the name if specified and check if it exists
5400 if(!normalizePlayerName(name))
5402 PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
5403 SetSentErrorMessage(true);
5404 return false;
5407 if(!ObjectMgr::IsValidName(name,true))
5409 PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
5410 SetSentErrorMessage(true);
5411 return false;
5414 guid_str = strtok(NULL, " ");
5417 uint32 guid = 0;
5419 if(guid_str)
5421 guid = atoi(guid_str);
5422 if(!guid)
5424 PSendSysMessage(LANG_INVALID_CHARACTER_GUID);
5425 SetSentErrorMessage(true);
5426 return false;
5429 if(objmgr.GetPlayerAccountIdByGUID(guid))
5431 PSendSysMessage(LANG_CHARACTER_GUID_IN_USE,guid);
5432 SetSentErrorMessage(true);
5433 return false;
5437 switch(PlayerDumpReader().LoadDump(file, account_id, name, guid))
5439 case DUMP_SUCCESS:
5440 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS);
5441 break;
5442 case DUMP_FILE_OPEN_ERROR:
5443 PSendSysMessage(LANG_FILE_OPEN_FAIL,file);
5444 SetSentErrorMessage(true);
5445 return false;
5446 case DUMP_FILE_BROKEN:
5447 PSendSysMessage(LANG_DUMP_BROKEN,file);
5448 SetSentErrorMessage(true);
5449 return false;
5450 case DUMP_TOO_MANY_CHARS:
5451 PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL,account_name.c_str(),account_id);
5452 SetSentErrorMessage(true);
5453 return false;
5454 default:
5455 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED);
5456 SetSentErrorMessage(true);
5457 return false;
5460 return true;
5463 bool ChatHandler::HandleChangeEntryCommand(const char *args)
5465 if(!args)
5466 return false;
5468 uint32 newEntryNum = atoi(args);
5469 if(!newEntryNum)
5470 return false;
5472 Unit* unit = getSelectedUnit();
5473 if(!unit || unit->GetTypeId() != TYPEID_UNIT)
5475 SendSysMessage(LANG_SELECT_CREATURE);
5476 SetSentErrorMessage(true);
5477 return false;
5479 Creature* creature = (Creature*)unit;
5480 if(creature->UpdateEntry(newEntryNum))
5481 SendSysMessage(LANG_DONE);
5482 else
5483 SendSysMessage(LANG_ERROR);
5484 return true;
5487 bool ChatHandler::HandleWritePDumpCommand(const char *args)
5489 if(!args)
5490 return false;
5492 char* file = strtok((char*)args, " ");
5493 char* p2 = strtok(NULL, " ");
5495 if(!file || !p2)
5496 return false;
5498 uint32 guid = objmgr.GetPlayerGUIDByName(p2);
5499 if(!guid)
5500 guid = atoi(p2);
5502 if(!objmgr.GetPlayerAccountIdByGUID(guid))
5504 PSendSysMessage(LANG_PLAYER_NOT_FOUND);
5505 SetSentErrorMessage(true);
5506 return false;
5509 switch(PlayerDumpWriter().WriteDump(file, guid))
5511 case DUMP_SUCCESS:
5512 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS);
5513 break;
5514 case DUMP_FILE_OPEN_ERROR:
5515 PSendSysMessage(LANG_FILE_OPEN_FAIL,file);
5516 SetSentErrorMessage(true);
5517 return false;
5518 default:
5519 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED);
5520 SetSentErrorMessage(true);
5521 return false;
5524 return true;
5527 bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
5529 Unit* unit = getSelectedUnit();
5530 if(!unit)
5532 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5533 SetSentErrorMessage(true);
5534 return false;
5537 PSendSysMessage(LANG_MOVEGENS_LIST,(unit->GetTypeId()==TYPEID_PLAYER ? "Player" : "Creature" ),unit->GetGUIDLow());
5539 MotionMaster* mm = unit->GetMotionMaster();
5540 for(MotionMaster::const_iterator itr = mm->begin(); itr != mm->end(); ++itr)
5542 switch((*itr)->GetMovementGeneratorType())
5544 case IDLE_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_IDLE); break;
5545 case RANDOM_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_RANDOM); break;
5546 case WAYPOINT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_WAYPOINT); break;
5547 case ANIMAL_RANDOM_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_ANIMAL_RANDOM); break;
5548 case CONFUSED_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_CONFUSED); break;
5549 case TARGETED_MOTION_TYPE:
5551 if(unit->GetTypeId()==TYPEID_PLAYER)
5553 TargetedMovementGenerator<Player> const* mgen = static_cast<TargetedMovementGenerator<Player> const*>(*itr);
5554 Unit* target = mgen->GetTarget();
5555 if(target)
5556 PSendSysMessage(LANG_MOVEGENS_TARGETED_PLAYER,target->GetName(),target->GetGUIDLow());
5557 else
5558 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL);
5560 else
5562 TargetedMovementGenerator<Creature> const* mgen = static_cast<TargetedMovementGenerator<Creature> const*>(*itr);
5563 Unit* target = mgen->GetTarget();
5564 if(target)
5565 PSendSysMessage(LANG_MOVEGENS_TARGETED_CREATURE,target->GetName(),target->GetGUIDLow());
5566 else
5567 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL);
5569 break;
5571 case HOME_MOTION_TYPE:
5572 if(unit->GetTypeId()==TYPEID_UNIT)
5574 float x,y,z;
5575 (*itr)->GetDestination(x,y,z);
5576 PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE,x,y,z);
5578 else
5579 SendSysMessage(LANG_MOVEGENS_HOME_PLAYER);
5580 break;
5581 case FLIGHT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FLIGHT); break;
5582 case POINT_MOTION_TYPE:
5584 float x,y,z;
5585 (*itr)->GetDestination(x,y,z);
5586 PSendSysMessage(LANG_MOVEGENS_POINT,x,y,z);
5587 break;
5589 case FLEEING_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FEAR); break;
5590 case DISTRACT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_DISTRACT); break;
5591 default:
5592 PSendSysMessage(LANG_MOVEGENS_UNKNOWN,(*itr)->GetMovementGeneratorType());
5593 break;
5596 return true;
5599 bool ChatHandler::HandlePLimitCommand(const char *args)
5601 if(*args)
5603 char* param = strtok((char*)args, " ");
5604 if(!param)
5605 return false;
5607 int l = strlen(param);
5609 if( strncmp(param,"player",l) == 0 )
5610 sWorld.SetPlayerLimit(-SEC_PLAYER);
5611 else if(strncmp(param,"moderator",l) == 0 )
5612 sWorld.SetPlayerLimit(-SEC_MODERATOR);
5613 else if(strncmp(param,"gamemaster",l) == 0 )
5614 sWorld.SetPlayerLimit(-SEC_GAMEMASTER);
5615 else if(strncmp(param,"administrator",l) == 0 )
5616 sWorld.SetPlayerLimit(-SEC_ADMINISTRATOR);
5617 else if(strncmp(param,"reset",l) == 0 )
5618 sWorld.SetPlayerLimit( sConfig.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT) );
5619 else
5621 int val = atoi(param);
5622 if(val < -SEC_ADMINISTRATOR) val = -SEC_ADMINISTRATOR;
5624 sWorld.SetPlayerLimit(val);
5627 // kick all low security level players
5628 if(sWorld.GetPlayerAmountLimit() > SEC_PLAYER)
5629 sWorld.KickAllLess(sWorld.GetPlayerSecurityLimit());
5632 uint32 pLimit = sWorld.GetPlayerAmountLimit();
5633 AccountTypes allowedAccountType = sWorld.GetPlayerSecurityLimit();
5634 char const* secName = "";
5635 switch(allowedAccountType)
5637 case SEC_PLAYER: secName = "Player"; break;
5638 case SEC_MODERATOR: secName = "Moderator"; break;
5639 case SEC_GAMEMASTER: secName = "Gamemaster"; break;
5640 case SEC_ADMINISTRATOR: secName = "Administrator"; break;
5641 default: secName = "<unknown>"; break;
5644 PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit,secName);
5646 return true;
5649 bool ChatHandler::HandleCastCommand(const char* args)
5651 if(!*args)
5652 return false;
5654 Unit* target = getSelectedUnit();
5656 if(!target)
5658 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5659 SetSentErrorMessage(true);
5660 return false;
5663 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5664 uint32 spell = extractSpellIdFromLink((char*)args);
5665 if(!spell)
5666 return false;
5668 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
5669 if(!spellInfo)
5670 return false;
5672 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
5674 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
5675 SetSentErrorMessage(true);
5676 return false;
5679 char* trig_str = strtok(NULL, " ");
5680 if(trig_str)
5682 int l = strlen(trig_str);
5683 if(strncmp(trig_str,"triggered",l) != 0 )
5684 return false;
5687 bool triggered = (trig_str != NULL);
5689 m_session->GetPlayer()->CastSpell(target,spell,triggered);
5691 return true;
5694 bool ChatHandler::HandleCastBackCommand(const char* args)
5696 Creature* caster = getSelectedCreature();
5698 if(!caster)
5700 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5701 SetSentErrorMessage(true);
5702 return false;
5705 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
5706 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5707 uint32 spell = extractSpellIdFromLink((char*)args);
5708 if(!spell || !sSpellStore.LookupEntry(spell))
5709 return false;
5711 char* trig_str = strtok(NULL, " ");
5712 if(trig_str)
5714 int l = strlen(trig_str);
5715 if(strncmp(trig_str,"triggered",l) != 0 )
5716 return false;
5719 bool triggered = (trig_str != NULL);
5721 // update orientation at server
5722 caster->SetOrientation(caster->GetAngle(m_session->GetPlayer()));
5724 // and client
5725 WorldPacket data;
5726 caster->BuildHeartBeatMsg(&data);
5727 caster->SendMessageToSet(&data,true);
5729 caster->CastSpell(m_session->GetPlayer(),spell,false);
5731 return true;
5734 bool ChatHandler::HandleCastDistCommand(const char* args)
5736 if(!*args)
5737 return false;
5739 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5740 uint32 spell = extractSpellIdFromLink((char*)args);
5741 if(!spell)
5742 return false;
5744 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
5745 if(!spellInfo)
5746 return false;
5748 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
5750 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
5751 SetSentErrorMessage(true);
5752 return false;
5755 char *distStr = strtok(NULL, " ");
5757 float dist = 0;
5759 if(distStr)
5760 sscanf(distStr, "%f", &dist);
5762 char* trig_str = strtok(NULL, " ");
5763 if(trig_str)
5765 int l = strlen(trig_str);
5766 if(strncmp(trig_str,"triggered",l) != 0 )
5767 return false;
5770 bool triggered = (trig_str != NULL);
5772 float x,y,z;
5773 m_session->GetPlayer()->GetClosePoint(x,y,z,dist);
5775 m_session->GetPlayer()->CastSpell(x,y,z,spell,triggered);
5776 return true;
5779 bool ChatHandler::HandleCastTargetCommand(const char* args)
5781 Creature* caster = getSelectedCreature();
5783 if(!caster)
5785 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5786 SetSentErrorMessage(true);
5787 return false;
5790 if(!caster->getVictim())
5792 SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM);
5793 SetSentErrorMessage(true);
5794 return false;
5797 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5798 uint32 spell = extractSpellIdFromLink((char*)args);
5799 if(!spell || !sSpellStore.LookupEntry(spell))
5800 return false;
5802 char* trig_str = strtok(NULL, " ");
5803 if(trig_str)
5805 int l = strlen(trig_str);
5806 if(strncmp(trig_str,"triggered",l) != 0 )
5807 return false;
5810 bool triggered = (trig_str != NULL);
5812 // update orientation at server
5813 caster->SetOrientation(caster->GetAngle(m_session->GetPlayer()));
5815 // and client
5816 WorldPacket data;
5817 caster->BuildHeartBeatMsg(&data);
5818 caster->SendMessageToSet(&data,true);
5820 caster->CastSpell(caster->getVictim(),spell,false);
5822 return true;
5826 ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
5827 Without this function 3rd party scripting library will get linking errors (unresolved external)
5828 when attempting to use the PointMovementGenerator
5830 bool ChatHandler::HandleComeToMeCommand(const char *args)
5832 Creature* caster = getSelectedCreature();
5834 if(!caster)
5836 SendSysMessage(LANG_SELECT_CREATURE);
5837 SetSentErrorMessage(true);
5838 return false;
5841 char* newFlagStr = strtok((char*)args, " ");
5843 if(!newFlagStr)
5844 return false;
5846 uint32 newFlags = atoi(newFlagStr);
5848 caster->SetUnitMovementFlags(newFlags);
5850 Player* pl = m_session->GetPlayer();
5852 caster->GetMotionMaster()->MovePoint(0, pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ());
5853 return true;
5856 bool ChatHandler::HandleCastSelfCommand(const char* args)
5858 if(!*args)
5859 return false;
5861 Unit* target = getSelectedUnit();
5863 if(!target)
5865 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5866 SetSentErrorMessage(true);
5867 return false;
5870 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5871 uint32 spell = extractSpellIdFromLink((char*)args);
5872 if(!spell)
5873 return false;
5875 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
5876 if(!spellInfo)
5877 return false;
5879 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
5881 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
5882 SetSentErrorMessage(true);
5883 return false;
5886 target->CastSpell(target,spell,false);
5888 return true;
5891 std::string GetTimeString(uint32 time)
5893 uint16 days = time / DAY, hours = (time % DAY) / HOUR, minute = (time % HOUR) / MINUTE;
5894 std::ostringstream ss;
5895 if(days) ss << days << "d ";
5896 if(hours) ss << hours << "h ";
5897 ss << minute << "m";
5898 return ss.str();
5901 bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
5903 Player* player = getSelectedPlayer();
5904 if (!player) player = m_session->GetPlayer();
5905 uint32 counter = 0;
5906 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; i++)
5908 Player::BoundInstancesMap &binds = player->GetBoundInstances(i);
5909 for(Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end(); ++itr)
5911 InstanceSave *save = itr->second.save;
5912 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
5913 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());
5914 counter++;
5917 PSendSysMessage("player binds: %d", counter);
5918 counter = 0;
5919 Group *group = player->GetGroup();
5920 if(group)
5922 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; i++)
5924 Group::BoundInstancesMap &binds = group->GetBoundInstances(i);
5925 for(Group::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end(); ++itr)
5927 InstanceSave *save = itr->second.save;
5928 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
5929 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());
5930 counter++;
5934 PSendSysMessage("group binds: %d", counter);
5936 return true;
5939 bool ChatHandler::HandleInstanceUnbindCommand(const char* args)
5941 if(!*args)
5942 return false;
5944 std::string cmd = args;
5945 if(cmd == "all")
5947 Player* player = getSelectedPlayer();
5948 if (!player) player = m_session->GetPlayer();
5949 uint32 counter = 0;
5950 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; i++)
5952 Player::BoundInstancesMap &binds = player->GetBoundInstances(i);
5953 for(Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end();)
5955 if(itr->first != player->GetMapId())
5957 InstanceSave *save = itr->second.save;
5958 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
5959 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());
5960 player->UnbindInstance(itr, i);
5961 counter++;
5963 else
5964 ++itr;
5967 PSendSysMessage("instances unbound: %d", counter);
5969 return true;
5972 bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
5974 PSendSysMessage("instances loaded: %d", MapManager::Instance().GetNumInstances());
5975 PSendSysMessage("players in instances: %d", MapManager::Instance().GetNumPlayersInInstances());
5976 PSendSysMessage("instance saves: %d", sInstanceSaveManager.GetNumInstanceSaves());
5977 PSendSysMessage("players bound: %d", sInstanceSaveManager.GetNumBoundPlayersTotal());
5978 PSendSysMessage("groups bound: %d", sInstanceSaveManager.GetNumBoundGroupsTotal());
5979 return true;
5982 bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
5984 Player* pl = m_session->GetPlayer();
5986 Map* map = pl->GetMap();
5987 if (!map->IsDungeon())
5989 PSendSysMessage("Map is not a dungeon.");
5990 SetSentErrorMessage(true);
5991 return false;
5994 if (!((InstanceMap*)map)->GetInstanceData())
5996 PSendSysMessage("Map has no instance data.");
5997 SetSentErrorMessage(true);
5998 return false;
6001 ((InstanceMap*)map)->GetInstanceData()->SaveToDB();
6002 return true;
6005 /// Display the list of GMs
6006 bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
6008 ///- Get the accounts with GM Level >0
6009 QueryResult *result = loginDatabase.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
6010 if(result)
6012 SendSysMessage(LANG_GMLIST);
6013 SendSysMessage("========================");
6014 SendSysMessage(LANG_GMLIST_HEADER);
6015 SendSysMessage("========================");
6017 ///- Circle through them. Display username and GM level
6020 Field *fields = result->Fetch();
6021 PSendSysMessage("|%15s|%6s|", fields[0].GetString(),fields[1].GetString());
6022 }while( result->NextRow() );
6024 PSendSysMessage("========================");
6025 delete result;
6027 else
6028 PSendSysMessage(LANG_GMLIST_EMPTY);
6029 return true;
6032 /// Define the 'Message of the day' for the realm
6033 bool ChatHandler::HandleServerSetMotdCommand(const char* args)
6035 sWorld.SetMotd(args);
6036 PSendSysMessage(LANG_MOTD_NEW, args);
6037 return true;
6040 /// Set/Unset the expansion level for an account
6041 bool ChatHandler::HandleAccountSetAddonCommand(const char* args)
6043 ///- Get the command line arguments
6044 char *szAcc = strtok((char*)args," ");
6045 char *szExp = strtok(NULL," ");
6047 if(!szAcc)
6048 return false;
6050 std::string account_name;
6051 uint32 account_id;
6053 if(!szExp)
6055 Player* player = getSelectedPlayer();
6056 if(!player)
6057 return false;
6059 account_id = player->GetSession()->GetAccountId();
6060 accmgr.GetName(account_id,account_name);
6061 szExp = szAcc;
6063 else
6065 ///- Convert Account name to Upper Format
6066 account_name = szAcc;
6067 if(!AccountMgr::normilizeString(account_name))
6069 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
6070 SetSentErrorMessage(true);
6071 return false;
6074 account_id = accmgr.GetId(account_name);
6075 if(!account_id)
6077 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
6078 SetSentErrorMessage(true);
6079 return false;
6083 int lev=atoi(szExp); //get int anyway (0 if error)
6084 if(lev < 0)
6085 return false;
6087 // No SQL injection
6088 loginDatabase.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev,account_id);
6089 PSendSysMessage(LANG_ACCOUNT_SETADDON,account_name.c_str(),account_id,lev);
6090 return true;
6093 /// Send a message to a player in game
6094 bool ChatHandler::HandleSendMessageCommand(const char* args)
6096 ///- Get the command line arguments
6097 char* name_str = strtok((char*)args, " ");
6098 char* msg_str = strtok(NULL, "");
6100 if(!name_str || !msg_str)
6101 return false;
6103 std::string name = name_str;
6105 if(!normalizePlayerName(name))
6106 return false;
6108 ///- Find the player and check that he is not logging out.
6109 Player *rPlayer = objmgr.GetPlayer(name.c_str());
6110 if(!rPlayer)
6112 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6113 SetSentErrorMessage(true);
6114 return false;
6117 if(rPlayer->GetSession()->isLogingOut())
6119 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6120 SetSentErrorMessage(true);
6121 return false;
6124 ///- Send the message
6125 //Use SendAreaTriggerMessage for fastest delivery.
6126 rPlayer->GetSession()->SendAreaTriggerMessage("%s", msg_str);
6127 rPlayer->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
6129 //Confirmation message
6130 PSendSysMessage(LANG_SENDMESSAGE,name.c_str(),msg_str);
6131 return true;