Some command handlers renames and declaration sorting.
[auctionmangos.git] / src / game / Level3.cpp
blob87f092a60ba83fe7dd5e48e9ae8e1906ee6a1a95
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 HandleReloadNpcOptionCommand("a");
104 HandleReloadNpcTrainerCommand("a");
105 HandleReloadNpcVendorCommand("a");
106 return true;
109 bool ChatHandler::HandleReloadAllQuestCommand(const char* /*args*/)
111 HandleReloadQuestAreaTriggersCommand("a");
112 HandleReloadQuestTemplateCommand("a");
114 sLog.outString( "Re-Loading Quests Relations..." );
115 objmgr.LoadQuestRelations();
116 SendGlobalSysMessage("DB tables `*_questrelation` and `*_involvedrelation` reloaded.");
117 return true;
120 bool ChatHandler::HandleReloadAllScriptsCommand(const char*)
122 if(sWorld.IsScriptScheduled())
124 PSendSysMessage("DB scripts used currently, please attempt reload later.");
125 SetSentErrorMessage(true);
126 return false;
129 sLog.outString( "Re-Loading Scripts..." );
130 HandleReloadGameObjectScriptsCommand("a");
131 HandleReloadEventScriptsCommand("a");
132 HandleReloadQuestEndScriptsCommand("a");
133 HandleReloadQuestStartScriptsCommand("a");
134 HandleReloadSpellScriptsCommand("a");
135 SendGlobalSysMessage("DB tables `*_scripts` reloaded.");
136 return true;
139 bool ChatHandler::HandleReloadAllSpellCommand(const char*)
141 HandleReloadSkillDiscoveryTemplateCommand("a");
142 HandleReloadSkillExtraItemTemplateCommand("a");
143 HandleReloadSpellAffectCommand("a");
144 HandleReloadSpellChainCommand("a");
145 HandleReloadSpellElixirCommand("a");
146 HandleReloadSpellLearnSpellCommand("a");
147 HandleReloadSpellProcEventCommand("a");
148 HandleReloadSpellScriptTargetCommand("a");
149 HandleReloadSpellTargetPositionCommand("a");
150 HandleReloadSpellThreatsCommand("a");
151 HandleReloadSpellPetAurasCommand("a");
152 return true;
155 bool ChatHandler::HandleReloadAllItemCommand(const char*)
157 HandleReloadPageTextsCommand("a");
158 HandleReloadItemEnchantementsCommand("a");
159 return true;
162 bool ChatHandler::HandleReloadAllLocalesCommand(const char* args)
164 HandleReloadLocalesCreatureCommand("a");
165 HandleReloadLocalesGameobjectCommand("a");
166 HandleReloadLocalesItemCommand("a");
167 HandleReloadLocalesNpcTextCommand("a");
168 HandleReloadLocalesPageTextCommand("a");
169 HandleReloadLocalesQuestCommand("a");
170 return true;
173 bool ChatHandler::HandleReloadConfigCommand(const char* arg)
175 sLog.outString( "Re-Loading config settings..." );
176 sWorld.LoadConfigSettings(true);
177 SendGlobalSysMessage("World config settings reloaded.");
178 return true;
181 bool ChatHandler::HandleReloadAreaTriggerTavernCommand(const char*)
183 sLog.outString( "Re-Loading Tavern Area Triggers..." );
184 objmgr.LoadTavernAreaTriggers();
185 SendGlobalSysMessage("DB table `areatrigger_tavern` reloaded.");
186 return true;
189 bool ChatHandler::HandleReloadAreaTriggerTeleportCommand(const char*)
191 sLog.outString( "Re-Loading AreaTrigger teleport definitions..." );
192 objmgr.LoadAreaTriggerTeleports();
193 SendGlobalSysMessage("DB table `areatrigger_teleport` reloaded.");
194 return true;
197 bool ChatHandler::HandleReloadCommandCommand(const char*)
199 load_command_table = true;
200 SendGlobalSysMessage("DB table `command` will be reloaded at next chat command use.");
201 return true;
204 bool ChatHandler::HandleReloadCreatureQuestRelationsCommand(const char*)
206 sLog.outString( "Loading Quests Relations... (`creature_questrelation`)" );
207 objmgr.LoadCreatureQuestRelations();
208 SendGlobalSysMessage("DB table `creature_questrelation` (creature quest givers) reloaded.");
209 return true;
212 bool ChatHandler::HandleReloadCreatureQuestInvRelationsCommand(const char*)
214 sLog.outString( "Loading Quests Relations... (`creature_involvedrelation`)" );
215 objmgr.LoadCreatureInvolvedRelations();
216 SendGlobalSysMessage("DB table `creature_involvedrelation` (creature quest takers) reloaded.");
217 return true;
220 bool ChatHandler::HandleReloadGOQuestRelationsCommand(const char*)
222 sLog.outString( "Loading Quests Relations... (`gameobject_questrelation`)" );
223 objmgr.LoadGameobjectQuestRelations();
224 SendGlobalSysMessage("DB table `gameobject_questrelation` (gameobject quest givers) reloaded.");
225 return true;
228 bool ChatHandler::HandleReloadGOQuestInvRelationsCommand(const char*)
230 sLog.outString( "Loading Quests Relations... (`gameobject_involvedrelation`)" );
231 objmgr.LoadGameobjectInvolvedRelations();
232 SendGlobalSysMessage("DB table `gameobject_involvedrelation` (gameobject quest takers) reloaded.");
233 return true;
236 bool ChatHandler::HandleReloadQuestAreaTriggersCommand(const char*)
238 sLog.outString( "Re-Loading Quest Area Triggers..." );
239 objmgr.LoadQuestAreaTriggers();
240 SendGlobalSysMessage("DB table `areatrigger_involvedrelation` (quest area triggers) reloaded.");
241 return true;
244 bool ChatHandler::HandleReloadQuestTemplateCommand(const char*)
246 sLog.outString( "Re-Loading Quest Templates..." );
247 objmgr.LoadQuests();
248 SendGlobalSysMessage("DB table `quest_template` (quest definitions) reloaded.");
249 return true;
252 bool ChatHandler::HandleReloadLootTemplatesCreatureCommand(const char*)
254 sLog.outString( "Re-Loading Loot Tables... (`creature_loot_template`)" );
255 LoadLootTemplates_Creature();
256 LootTemplates_Creature.CheckLootRefs();
257 SendGlobalSysMessage("DB table `creature_loot_template` reloaded.");
258 return true;
261 bool ChatHandler::HandleReloadLootTemplatesDisenchantCommand(const char*)
263 sLog.outString( "Re-Loading Loot Tables... (`disenchant_loot_template`)" );
264 LoadLootTemplates_Disenchant();
265 LootTemplates_Disenchant.CheckLootRefs();
266 SendGlobalSysMessage("DB table `disenchant_loot_template` reloaded.");
267 return true;
270 bool ChatHandler::HandleReloadLootTemplatesFishingCommand(const char*)
272 sLog.outString( "Re-Loading Loot Tables... (`fishing_loot_template`)" );
273 LoadLootTemplates_Fishing();
274 LootTemplates_Fishing.CheckLootRefs();
275 SendGlobalSysMessage("DB table `fishing_loot_template` reloaded.");
276 return true;
279 bool ChatHandler::HandleReloadLootTemplatesGameobjectCommand(const char*)
281 sLog.outString( "Re-Loading Loot Tables... (`gameobject_loot_template`)" );
282 LoadLootTemplates_Gameobject();
283 LootTemplates_Gameobject.CheckLootRefs();
284 SendGlobalSysMessage("DB table `gameobject_loot_template` reloaded.");
285 return true;
288 bool ChatHandler::HandleReloadLootTemplatesItemCommand(const char*)
290 sLog.outString( "Re-Loading Loot Tables... (`item_loot_template`)" );
291 LoadLootTemplates_Item();
292 LootTemplates_Item.CheckLootRefs();
293 SendGlobalSysMessage("DB table `item_loot_template` reloaded.");
294 return true;
297 bool ChatHandler::HandleReloadLootTemplatesPickpocketingCommand(const char*)
299 sLog.outString( "Re-Loading Loot Tables... (`pickpocketing_loot_template`)" );
300 LoadLootTemplates_Pickpocketing();
301 LootTemplates_Pickpocketing.CheckLootRefs();
302 SendGlobalSysMessage("DB table `pickpocketing_loot_template` reloaded.");
303 return true;
306 bool ChatHandler::HandleReloadLootTemplatesProspectingCommand(const char*)
308 sLog.outString( "Re-Loading Loot Tables... (`prospecting_loot_template`)" );
309 LoadLootTemplates_Prospecting();
310 LootTemplates_Prospecting.CheckLootRefs();
311 SendGlobalSysMessage("DB table `prospecting_loot_template` reloaded.");
312 return true;
315 bool ChatHandler::HandleReloadLootTemplatesQuestMailCommand(const char*)
317 sLog.outString( "Re-Loading Loot Tables... (`quest_mail_loot_template`)" );
318 LoadLootTemplates_QuestMail();
319 LootTemplates_QuestMail.CheckLootRefs();
320 SendGlobalSysMessage("DB table `quest_mail_loot_template` reloaded.");
321 return true;
324 bool ChatHandler::HandleReloadLootTemplatesReferenceCommand(const char*)
326 sLog.outString( "Re-Loading Loot Tables... (`reference_loot_template`)" );
327 LoadLootTemplates_Reference();
328 SendGlobalSysMessage("DB table `reference_loot_template` reloaded.");
329 return true;
332 bool ChatHandler::HandleReloadLootTemplatesSkinningCommand(const char*)
334 sLog.outString( "Re-Loading Loot Tables... (`skinning_loot_template`)" );
335 LoadLootTemplates_Skinning();
336 LootTemplates_Skinning.CheckLootRefs();
337 SendGlobalSysMessage("DB table `skinning_loot_template` reloaded.");
338 return true;
341 bool ChatHandler::HandleReloadMangosStringCommand(const char*)
343 sLog.outString( "Re-Loading mangos_string Table!" );
344 objmgr.LoadMangosStrings();
345 SendGlobalSysMessage("DB table `mangos_string` reloaded.");
346 return true;
349 bool ChatHandler::HandleReloadNpcOptionCommand(const char*)
351 sLog.outString( "Re-Loading `npc_option` Table!" );
352 objmgr.LoadNpcOptions();
353 SendGlobalSysMessage("DB table `npc_option` reloaded.");
354 return true;
357 bool ChatHandler::HandleReloadNpcGossipCommand(const char*)
359 sLog.outString( "Re-Loading `npc_gossip` Table!" );
360 objmgr.LoadNpcTextId();
361 SendGlobalSysMessage("DB table `npc_gossip` reloaded.");
362 return true;
365 bool ChatHandler::HandleReloadNpcTrainerCommand(const char*)
367 sLog.outString( "Re-Loading `npc_trainer` Table!" );
368 objmgr.LoadTrainerSpell();
369 SendGlobalSysMessage("DB table `npc_trainer` reloaded.");
370 return true;
373 bool ChatHandler::HandleReloadNpcVendorCommand(const char*)
375 sLog.outString( "Re-Loading `npc_vendor` Table!" );
376 objmgr.LoadVendors();
377 SendGlobalSysMessage("DB table `npc_vendor` reloaded.");
378 return true;
381 bool ChatHandler::HandleReloadReservedNameCommand(const char*)
383 sLog.outString( "Loading ReservedNames... (`reserved_name`)" );
384 objmgr.LoadReservedPlayersNames();
385 SendGlobalSysMessage("DB table `reserved_name` (player reserved names) reloaded.");
386 return true;
389 bool ChatHandler::HandleReloadSkillDiscoveryTemplateCommand(const char* /*args*/)
391 sLog.outString( "Re-Loading Skill Discovery Table..." );
392 LoadSkillDiscoveryTable();
393 SendGlobalSysMessage("DB table `skill_discovery_template` (recipes discovered at crafting) reloaded.");
394 return true;
397 bool ChatHandler::HandleReloadSkillExtraItemTemplateCommand(const char* /*args*/)
399 sLog.outString( "Re-Loading Skill Extra Item Table..." );
400 LoadSkillExtraItemTable();
401 SendGlobalSysMessage("DB table `skill_extra_item_template` (extra item creation when crafting) reloaded.");
402 return true;
405 bool ChatHandler::HandleReloadSkillFishingBaseLevelCommand(const char* /*args*/)
407 sLog.outString( "Re-Loading Skill Fishing base level requirements..." );
408 objmgr.LoadFishingBaseSkillLevel();
409 SendGlobalSysMessage("DB table `skill_fishing_base_level` (fishing base level for zone/subzone) reloaded.");
410 return true;
413 bool ChatHandler::HandleReloadSpellAffectCommand(const char*)
415 sLog.outString( "Re-Loading SpellAffect definitions..." );
416 spellmgr.LoadSpellAffects();
417 SendGlobalSysMessage("DB table `spell_affect` (spell mods apply requirements) reloaded.");
418 return true;
421 bool ChatHandler::HandleReloadSpellChainCommand(const char*)
423 sLog.outString( "Re-Loading Spell Chain Data... " );
424 spellmgr.LoadSpellChains();
425 SendGlobalSysMessage("DB table `spell_chain` (spell ranks) reloaded.");
426 return true;
429 bool ChatHandler::HandleReloadSpellElixirCommand(const char*)
431 sLog.outString( "Re-Loading Spell Elixir types..." );
432 spellmgr.LoadSpellElixirs();
433 SendGlobalSysMessage("DB table `spell_elixir` (spell exlixir types) reloaded.");
434 return true;
437 bool ChatHandler::HandleReloadSpellLearnSpellCommand(const char*)
439 sLog.outString( "Re-Loading Spell Learn Spells..." );
440 spellmgr.LoadSpellLearnSpells();
441 SendGlobalSysMessage("DB table `spell_learn_spell` reloaded.");
442 return true;
445 bool ChatHandler::HandleReloadSpellProcEventCommand(const char*)
447 sLog.outString( "Re-Loading Spell Proc Event conditions..." );
448 spellmgr.LoadSpellProcEvents();
449 SendGlobalSysMessage("DB table `spell_proc_event` (spell proc trigger requirements) reloaded.");
450 return true;
453 bool ChatHandler::HandleReloadSpellScriptTargetCommand(const char*)
455 sLog.outString( "Re-Loading SpellsScriptTarget..." );
456 spellmgr.LoadSpellScriptTarget();
457 SendGlobalSysMessage("DB table `spell_script_target` (spell targets selection in case specific creature/GO requirements) reloaded.");
458 return true;
461 bool ChatHandler::HandleReloadSpellTargetPositionCommand(const char*)
463 sLog.outString( "Re-Loading Spell target coordinates..." );
464 spellmgr.LoadSpellTargetPositions();
465 SendGlobalSysMessage("DB table `spell_target_position` (destination coordinates for spell targets) reloaded.");
466 return true;
469 bool ChatHandler::HandleReloadSpellThreatsCommand(const char*)
471 sLog.outString( "Re-Loading Aggro Spells Definitions...");
472 spellmgr.LoadSpellThreats();
473 SendGlobalSysMessage("DB table `spell_threat` (spell aggro definitions) reloaded.");
474 return true;
477 bool ChatHandler::HandleReloadSpellPetAurasCommand(const char*)
479 sLog.outString( "Re-Loading Spell pet auras...");
480 spellmgr.LoadSpellPetAuras();
481 SendGlobalSysMessage("DB table `spell_pet_auras` reloaded.");
482 return true;
485 bool ChatHandler::HandleReloadPageTextsCommand(const char*)
487 sLog.outString( "Re-Loading Page Texts..." );
488 objmgr.LoadPageTexts();
489 SendGlobalSysMessage("DB table `page_texts` reloaded.");
490 return true;
493 bool ChatHandler::HandleReloadItemEnchantementsCommand(const char*)
495 sLog.outString( "Re-Loading Item Random Enchantments Table..." );
496 LoadRandomEnchantmentsTable();
497 SendGlobalSysMessage("DB table `item_enchantment_template` reloaded.");
498 return true;
501 bool ChatHandler::HandleReloadGameObjectScriptsCommand(const char* arg)
503 if(sWorld.IsScriptScheduled())
505 SendSysMessage("DB scripts used currently, please attempt reload later.");
506 SetSentErrorMessage(true);
507 return false;
510 if(*arg!='a')
511 sLog.outString( "Re-Loading Scripts from `gameobject_scripts`...");
513 objmgr.LoadGameObjectScripts();
515 if(*arg!='a')
516 SendGlobalSysMessage("DB table `gameobject_scripts` reloaded.");
518 return true;
521 bool ChatHandler::HandleReloadEventScriptsCommand(const char* arg)
523 if(sWorld.IsScriptScheduled())
525 SendSysMessage("DB scripts used currently, please attempt reload later.");
526 SetSentErrorMessage(true);
527 return false;
530 if(*arg!='a')
531 sLog.outString( "Re-Loading Scripts from `event_scripts`...");
533 objmgr.LoadEventScripts();
535 if(*arg!='a')
536 SendGlobalSysMessage("DB table `event_scripts` reloaded.");
538 return true;
541 bool ChatHandler::HandleReloadQuestEndScriptsCommand(const char* arg)
543 if(sWorld.IsScriptScheduled())
545 SendSysMessage("DB scripts used currently, please attempt reload later.");
546 SetSentErrorMessage(true);
547 return false;
550 if(*arg!='a')
551 sLog.outString( "Re-Loading Scripts from `quest_end_scripts`...");
553 objmgr.LoadQuestEndScripts();
555 if(*arg!='a')
556 SendGlobalSysMessage("DB table `quest_end_scripts` reloaded.");
558 return true;
561 bool ChatHandler::HandleReloadQuestStartScriptsCommand(const char* arg)
563 if(sWorld.IsScriptScheduled())
565 SendSysMessage("DB scripts used currently, please attempt reload later.");
566 SetSentErrorMessage(true);
567 return false;
570 if(*arg!='a')
571 sLog.outString( "Re-Loading Scripts from `quest_start_scripts`...");
573 objmgr.LoadQuestStartScripts();
575 if(*arg!='a')
576 SendGlobalSysMessage("DB table `quest_start_scripts` reloaded.");
578 return true;
581 bool ChatHandler::HandleReloadSpellScriptsCommand(const char* arg)
583 if(sWorld.IsScriptScheduled())
585 SendSysMessage("DB scripts used currently, please attempt reload later.");
586 SetSentErrorMessage(true);
587 return false;
590 if(*arg!='a')
591 sLog.outString( "Re-Loading Scripts from `spell_scripts`...");
593 objmgr.LoadSpellScripts();
595 if(*arg!='a')
596 SendGlobalSysMessage("DB table `spell_scripts` reloaded.");
598 return true;
601 bool ChatHandler::HandleReloadGameGraveyardZoneCommand(const char* /*arg*/)
603 sLog.outString( "Re-Loading Graveyard-zone links...");
605 objmgr.LoadGraveyardZones();
607 SendGlobalSysMessage("DB table `game_graveyard_zone` reloaded.");
609 return true;
612 bool ChatHandler::HandleReloadGameTeleCommand(const char* /*arg*/)
614 sLog.outString( "Re-Loading Game Tele coordinates...");
616 objmgr.LoadGameTele();
618 SendGlobalSysMessage("DB table `game_tele` reloaded.");
620 return true;
623 bool ChatHandler::HandleReloadLocalesCreatureCommand(const char* /*arg*/)
625 sLog.outString( "Re-Loading Locales Creature ...");
626 objmgr.LoadCreatureLocales();
627 SendGlobalSysMessage("DB table `locales_creature` reloaded.");
628 return true;
631 bool ChatHandler::HandleReloadLocalesGameobjectCommand(const char* /*arg*/)
633 sLog.outString( "Re-Loading Locales Gameobject ... ");
634 objmgr.LoadGameObjectLocales();
635 SendGlobalSysMessage("DB table `locales_gameobject` reloaded.");
636 return true;
639 bool ChatHandler::HandleReloadLocalesItemCommand(const char* /*arg*/)
641 sLog.outString( "Re-Loading Locales Item ... ");
642 objmgr.LoadItemLocales();
643 SendGlobalSysMessage("DB table `locales_item` reloaded.");
644 return true;
647 bool ChatHandler::HandleReloadLocalesNpcTextCommand(const char* /*arg*/)
649 sLog.outString( "Re-Loading Locales NPC Text ... ");
650 objmgr.LoadNpcTextLocales();
651 SendGlobalSysMessage("DB table `locales_npc_text` reloaded.");
652 return true;
655 bool ChatHandler::HandleReloadLocalesPageTextCommand(const char* /*arg*/)
657 sLog.outString( "Re-Loading Locales Page Text ... ");
658 objmgr.LoadPageTextLocales();
659 SendGlobalSysMessage("DB table `locales_page_text` reloaded.");
660 return true;
663 bool ChatHandler::HandleReloadLocalesQuestCommand(const char* /*arg*/)
665 sLog.outString( "Re-Loading Locales Quest ... ");
666 objmgr.LoadQuestLocales();
667 SendGlobalSysMessage("DB table `locales_quest` reloaded.");
668 return true;
671 bool ChatHandler::HandleLoadScriptsCommand(const char* args)
673 if(!LoadScriptingModule(args)) return true;
675 sWorld.SendWorldText(LANG_SCRIPTS_RELOADED);
676 return true;
679 bool ChatHandler::HandleAccountSetGmLevelCommand(const char* args)
681 char* arg1 = strtok((char*)args, " ");
682 if( !arg1 )
683 return false;
685 char* arg2 = strtok(NULL, " ");
687 std::string targetAccountName;
688 uint32 targetAccountId = 0;
689 uint32 targetSecurity = 0;
691 /// only target player different from self allowed (if targetPlayer!=NULL then not console)
692 Player* targetPlayer = getSelectedPlayer();
693 if(targetPlayer && m_session->GetPlayer()!=targetPlayer)
695 /// wrong command syntax or unexpected targeting
696 if(arg2)
697 return false;
699 targetAccountId = targetPlayer->GetSession()->GetAccountId();
700 targetSecurity = targetPlayer->GetSession()->GetSecurity();
701 if(!accmgr.GetName(targetAccountId,targetAccountName))
703 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,targetAccountName.c_str());
704 SetSentErrorMessage(true);
705 return false;
708 else
710 targetAccountName = arg1;
711 if(!AccountMgr::normilizeString(targetAccountName))
713 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,targetAccountName.c_str());
714 SetSentErrorMessage(true);
715 return false;
718 targetAccountId = accmgr.GetId(targetAccountName);
719 targetSecurity = accmgr.GetSecurity(targetAccountId);
722 int32 gm = (int32)atoi(arg2);
723 if ( gm < SEC_PLAYER || gm > SEC_ADMINISTRATOR )
725 SendSysMessage(LANG_BAD_VALUE);
726 SetSentErrorMessage(true);
727 return false;
730 /// m_session==NULL only for console
731 uint32 plSecurity = m_session ? m_session->GetSecurity() : SEC_CONSOLE;
733 /// can set security level only for target with less security and to less security that we have
734 /// This is also reject self apply in fact
735 if(targetSecurity >= plSecurity || uint32(gm) >= plSecurity )
737 SendSysMessage(LANG_YOURS_SECURITY_IS_LOW);
738 SetSentErrorMessage(true);
739 return false;
742 if(targetPlayer)
744 ChatHandler(targetPlayer).PSendSysMessage(LANG_YOURS_SECURITY_CHANGED,GetName(), gm);
745 targetPlayer->GetSession()->SetSecurity(gm);
748 PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetAccountName.c_str(), gm);
749 loginDatabase.PExecute("UPDATE account SET gmlevel = '%i' WHERE id = '%u'", gm, targetAccountId);
751 return true;
754 /// Set password for account
755 bool ChatHandler::HandleAccountSetPasswordCommand(const char* args)
757 if(!*args)
758 return false;
760 ///- Get the command line arguments
761 char *szAccount = strtok ((char*)args," ");
762 char *szPassword1 = strtok (NULL," ");
763 char *szPassword2 = strtok (NULL," ");
765 if (!szAccount||!szPassword1 || !szPassword2)
766 return false;
768 std::string account_name = szAccount;
769 if(!AccountMgr::normilizeString(account_name))
771 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
772 SetSentErrorMessage(true);
773 return false;
776 uint32 targetAccountId = accmgr.GetId(account_name);
777 if (!targetAccountId)
779 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
780 SetSentErrorMessage(true);
781 return false;
784 uint32 targetSecurity = accmgr.GetSecurity(targetAccountId);
786 /// m_session==NULL only for console
787 uint32 plSecurity = m_session ? m_session->GetSecurity() : SEC_CONSOLE;
789 /// can set password only for target with less security
790 /// This is also reject self apply in fact
791 if (targetSecurity >= plSecurity)
793 SendSysMessage (LANG_YOURS_SECURITY_IS_LOW);
794 SetSentErrorMessage (true);
795 return false;
798 if (strcmp(szPassword1,szPassword2))
800 SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH);
801 SetSentErrorMessage (true);
802 return false;
805 AccountOpResult result = accmgr.ChangePassword(targetAccountId, szPassword1);
807 switch(result)
809 case AOR_OK:
810 SendSysMessage(LANG_COMMAND_PASSWORD);
811 break;
812 case AOR_NAME_NOT_EXIST:
813 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
814 SetSentErrorMessage(true);
815 return false;
816 case AOR_PASS_TOO_LONG:
817 SendSysMessage(LANG_PASSWORD_TOO_LONG);
818 SetSentErrorMessage(true);
819 return false;
820 default:
821 SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD);
822 SetSentErrorMessage(true);
823 return false;
826 return true;
829 bool ChatHandler::HandleAllowMovementCommand(const char* /*args*/)
831 if(sWorld.getAllowMovement())
833 sWorld.SetAllowMovement(false);
834 SendSysMessage(LANG_CREATURE_MOVE_DISABLED);
836 else
838 sWorld.SetAllowMovement(true);
839 SendSysMessage(LANG_CREATURE_MOVE_ENABLED);
841 return true;
844 bool ChatHandler::HandleMaxSkillCommand(const char* /*args*/)
846 Player* SelectedPlayer = getSelectedPlayer();
847 if(!SelectedPlayer)
849 SendSysMessage(LANG_NO_CHAR_SELECTED);
850 SetSentErrorMessage(true);
851 return false;
854 // each skills that have max skill value dependent from level seted to current level max skill value
855 SelectedPlayer->UpdateSkillsToMaxSkillsForLevel();
856 return true;
859 bool ChatHandler::HandleSetSkillCommand(const char* args)
861 // number or [name] Shift-click form |color|Hskill:skill_id|h[name]|h|r
862 char* skill_p = extractKeyFromLink((char*)args,"Hskill");
863 if(!skill_p)
864 return false;
866 char *level_p = strtok (NULL, " ");
868 if( !level_p)
869 return false;
871 char *max_p = strtok (NULL, " ");
873 int32 skill = atoi(skill_p);
875 if (skill <= 0)
877 PSendSysMessage(LANG_INVALID_SKILL_ID, skill);
878 SetSentErrorMessage(true);
879 return false;
882 int32 level = atol (level_p);
884 Player * target = getSelectedPlayer();
885 if(!target)
887 SendSysMessage(LANG_NO_CHAR_SELECTED);
888 SetSentErrorMessage(true);
889 return false;
892 SkillLineEntry const* sl = sSkillLineStore.LookupEntry(skill);
893 if(!sl)
895 PSendSysMessage(LANG_INVALID_SKILL_ID, skill);
896 SetSentErrorMessage(true);
897 return false;
900 if(!target->GetSkillValue(skill))
902 PSendSysMessage(LANG_SET_SKILL_ERROR, target->GetName(), skill, sl->name[0]);
903 SetSentErrorMessage(true);
904 return false;
907 int32 max = max_p ? atol (max_p) : target->GetPureMaxSkillValue(skill);
909 if( level <= 0 || level > max || max <= 0 )
910 return false;
912 target->SetSkill(skill, level, max);
913 PSendSysMessage(LANG_SET_SKILL, skill, sl->name[0], target->GetName(), level, max);
915 return true;
918 bool ChatHandler::HandleUnLearnCommand(const char* args)
920 if (!*args)
921 return false;
923 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
924 uint32 min_id = extractSpellIdFromLink((char*)args);
925 if(!min_id)
926 return false;
928 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
929 char* tail = strtok(NULL,"");
931 uint32 max_id = extractSpellIdFromLink(tail);
933 if (!max_id)
935 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
936 max_id = min_id+1;
938 else
940 if (max_id < min_id)
941 std::swap(min_id,max_id);
943 max_id=max_id+1;
946 Player* target = getSelectedPlayer();
947 if(!target)
949 SendSysMessage(LANG_NO_CHAR_SELECTED);
950 SetSentErrorMessage(true);
951 return false;
954 for(uint32 spell=min_id;spell<max_id;spell++)
956 if (target->HasSpell(spell))
957 target->removeSpell(spell);
958 else
959 SendSysMessage(LANG_FORGET_SPELL);
962 return true;
965 bool ChatHandler::HandleCooldownCommand(const char* args)
967 Player* target = getSelectedPlayer();
968 if(!target)
970 SendSysMessage(LANG_PLAYER_NOT_FOUND);
971 SetSentErrorMessage(true);
972 return false;
975 if (!*args)
977 target->RemoveAllSpellCooldown();
978 PSendSysMessage(LANG_REMOVEALL_COOLDOWN, target->GetName());
980 else
982 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
983 uint32 spell_id = extractSpellIdFromLink((char*)args);
984 if(!spell_id)
985 return false;
987 if(!sSpellStore.LookupEntry(spell_id))
989 PSendSysMessage(LANG_UNKNOWN_SPELL, target==m_session->GetPlayer() ? GetMangosString(LANG_YOU) : target->GetName());
990 SetSentErrorMessage(true);
991 return false;
994 WorldPacket data( SMSG_CLEAR_COOLDOWN, (4+8) );
995 data << uint32(spell_id);
996 data << uint64(target->GetGUID());
997 target->GetSession()->SendPacket(&data);
998 target->RemoveSpellCooldown(spell_id);
999 PSendSysMessage(LANG_REMOVE_COOLDOWN, spell_id, target==m_session->GetPlayer() ? GetMangosString(LANG_YOU) : target->GetName());
1001 return true;
1004 bool ChatHandler::HandleLearnAllCommand(const char* /*args*/)
1006 static const char *allSpellList[] =
1008 "3365",
1009 "6233",
1010 "6247",
1011 "6246",
1012 "6477",
1013 "6478",
1014 "22810",
1015 "8386",
1016 "21651",
1017 "21652",
1018 "522",
1019 "7266",
1020 "8597",
1021 "2479",
1022 "22027",
1023 "6603",
1024 "5019",
1025 "133",
1026 "168",
1027 "227",
1028 "5009",
1029 "9078",
1030 "668",
1031 "203",
1032 "20599",
1033 "20600",
1034 "81",
1035 "20597",
1036 "20598",
1037 "20864",
1038 "1459",
1039 "5504",
1040 "587",
1041 "5143",
1042 "118",
1043 "5505",
1044 "597",
1045 "604",
1046 "1449",
1047 "1460",
1048 "2855",
1049 "1008",
1050 "475",
1051 "5506",
1052 "1463",
1053 "12824",
1054 "8437",
1055 "990",
1056 "5145",
1057 "8450",
1058 "1461",
1059 "759",
1060 "8494",
1061 "8455",
1062 "8438",
1063 "6127",
1064 "8416",
1065 "6129",
1066 "8451",
1067 "8495",
1068 "8439",
1069 "3552",
1070 "8417",
1071 "10138",
1072 "12825",
1073 "10169",
1074 "10156",
1075 "10144",
1076 "10191",
1077 "10201",
1078 "10211",
1079 "10053",
1080 "10173",
1081 "10139",
1082 "10145",
1083 "10192",
1084 "10170",
1085 "10202",
1086 "10054",
1087 "10174",
1088 "10193",
1089 "12826",
1090 "2136",
1091 "143",
1092 "145",
1093 "2137",
1094 "2120",
1095 "3140",
1096 "543",
1097 "2138",
1098 "2948",
1099 "8400",
1100 "2121",
1101 "8444",
1102 "8412",
1103 "8457",
1104 "8401",
1105 "8422",
1106 "8445",
1107 "8402",
1108 "8413",
1109 "8458",
1110 "8423",
1111 "8446",
1112 "10148",
1113 "10197",
1114 "10205",
1115 "10149",
1116 "10215",
1117 "10223",
1118 "10206",
1119 "10199",
1120 "10150",
1121 "10216",
1122 "10207",
1123 "10225",
1124 "10151",
1125 "116",
1126 "205",
1127 "7300",
1128 "122",
1129 "837",
1130 "10",
1131 "7301",
1132 "7322",
1133 "6143",
1134 "120",
1135 "865",
1136 "8406",
1137 "6141",
1138 "7302",
1139 "8461",
1140 "8407",
1141 "8492",
1142 "8427",
1143 "8408",
1144 "6131",
1145 "7320",
1146 "10159",
1147 "8462",
1148 "10185",
1149 "10179",
1150 "10160",
1151 "10180",
1152 "10219",
1153 "10186",
1154 "10177",
1155 "10230",
1156 "10181",
1157 "10161",
1158 "10187",
1159 "10220",
1160 "2018",
1161 "2663",
1162 "12260",
1163 "2660",
1164 "3115",
1165 "3326",
1166 "2665",
1167 "3116",
1168 "2738",
1169 "3293",
1170 "2661",
1171 "3319",
1172 "2662",
1173 "9983",
1174 "8880",
1175 "2737",
1176 "2739",
1177 "7408",
1178 "3320",
1179 "2666",
1180 "3323",
1181 "3324",
1182 "3294",
1183 "22723",
1184 "23219",
1185 "23220",
1186 "23221",
1187 "23228",
1188 "23338",
1189 "10788",
1190 "10790",
1191 "5611",
1192 "5016",
1193 "5609",
1194 "2060",
1195 "10963",
1196 "10964",
1197 "10965",
1198 "22593",
1199 "22594",
1200 "596",
1201 "996",
1202 "499",
1203 "768",
1204 "17002",
1205 "1448",
1206 "1082",
1207 "16979",
1208 "1079",
1209 "5215",
1210 "20484",
1211 "5221",
1212 "15590",
1213 "17007",
1214 "6795",
1215 "6807",
1216 "5487",
1217 "1446",
1218 "1066",
1219 "5421",
1220 "3139",
1221 "779",
1222 "6811",
1223 "6808",
1224 "1445",
1225 "5216",
1226 "1737",
1227 "5222",
1228 "5217",
1229 "1432",
1230 "6812",
1231 "9492",
1232 "5210",
1233 "3030",
1234 "1441",
1235 "783",
1236 "6801",
1237 "20739",
1238 "8944",
1239 "9491",
1240 "22569",
1241 "5226",
1242 "6786",
1243 "1433",
1244 "8973",
1245 "1828",
1246 "9495",
1247 "9006",
1248 "6794",
1249 "8993",
1250 "5203",
1251 "16914",
1252 "6784",
1253 "9635",
1254 "22830",
1255 "20722",
1256 "9748",
1257 "6790",
1258 "9753",
1259 "9493",
1260 "9752",
1261 "9831",
1262 "9825",
1263 "9822",
1264 "5204",
1265 "5401",
1266 "22831",
1267 "6793",
1268 "9845",
1269 "17401",
1270 "9882",
1271 "9868",
1272 "20749",
1273 "9893",
1274 "9899",
1275 "9895",
1276 "9832",
1277 "9902",
1278 "9909",
1279 "22832",
1280 "9828",
1281 "9851",
1282 "9883",
1283 "9869",
1284 "17406",
1285 "17402",
1286 "9914",
1287 "20750",
1288 "9897",
1289 "9848",
1290 "3127",
1291 "107",
1292 "204",
1293 "9116",
1294 "2457",
1295 "78",
1296 "18848",
1297 "331",
1298 "403",
1299 "2098",
1300 "1752",
1301 "11278",
1302 "11288",
1303 "11284",
1304 "6461",
1305 "2344",
1306 "2345",
1307 "6463",
1308 "2346",
1309 "2352",
1310 "775",
1311 "1434",
1312 "1612",
1313 "71",
1314 "2468",
1315 "2458",
1316 "2467",
1317 "7164",
1318 "7178",
1319 "7367",
1320 "7376",
1321 "7381",
1322 "21156",
1323 "5209",
1324 "3029",
1325 "5201",
1326 "9849",
1327 "9850",
1328 "20719",
1329 "22568",
1330 "22827",
1331 "22828",
1332 "22829",
1333 "6809",
1334 "8972",
1335 "9005",
1336 "9823",
1337 "9827",
1338 "6783",
1339 "9913",
1340 "6785",
1341 "6787",
1342 "9866",
1343 "9867",
1344 "9894",
1345 "9896",
1346 "6800",
1347 "8992",
1348 "9829",
1349 "9830",
1350 "780",
1351 "769",
1352 "6749",
1353 "6750",
1354 "9755",
1355 "9754",
1356 "9908",
1357 "20745",
1358 "20742",
1359 "20747",
1360 "20748",
1361 "9746",
1362 "9745",
1363 "9880",
1364 "9881",
1365 "5391",
1366 "842",
1367 "3025",
1368 "3031",
1369 "3287",
1370 "3329",
1371 "1945",
1372 "3559",
1373 "4933",
1374 "4934",
1375 "4935",
1376 "4936",
1377 "5142",
1378 "5390",
1379 "5392",
1380 "5404",
1381 "5420",
1382 "6405",
1383 "7293",
1384 "7965",
1385 "8041",
1386 "8153",
1387 "9033",
1388 "9034",
1389 //"9036", problems with ghost state
1390 "16421",
1391 "21653",
1392 "22660",
1393 "5225",
1394 "9846",
1395 "2426",
1396 "5916",
1397 "6634",
1398 //"6718", phasing stealth, annoing for learn all case.
1399 "6719",
1400 "8822",
1401 "9591",
1402 "9590",
1403 "10032",
1404 "17746",
1405 "17747",
1406 "8203",
1407 "11392",
1408 "12495",
1409 "16380",
1410 "23452",
1411 "4079",
1412 "4996",
1413 "4997",
1414 "4998",
1415 "4999",
1416 "5000",
1417 "6348",
1418 "6349",
1419 "6481",
1420 "6482",
1421 "6483",
1422 "6484",
1423 "11362",
1424 "11410",
1425 "11409",
1426 "12510",
1427 "12509",
1428 "12885",
1429 "13142",
1430 "21463",
1431 "23460",
1432 "11421",
1433 "11416",
1434 "11418",
1435 "1851",
1436 "10059",
1437 "11423",
1438 "11417",
1439 "11422",
1440 "11419",
1441 "11424",
1442 "11420",
1443 "27",
1444 "31",
1445 "33",
1446 "34",
1447 "35",
1448 "15125",
1449 "21127",
1450 "22950",
1451 "1180",
1452 "201",
1453 "12593",
1454 "12842",
1455 "16770",
1456 "6057",
1457 "12051",
1458 "18468",
1459 "12606",
1460 "12605",
1461 "18466",
1462 "12502",
1463 "12043",
1464 "15060",
1465 "12042",
1466 "12341",
1467 "12848",
1468 "12344",
1469 "12353",
1470 "18460",
1471 "11366",
1472 "12350",
1473 "12352",
1474 "13043",
1475 "11368",
1476 "11113",
1477 "12400",
1478 "11129",
1479 "16766",
1480 "12573",
1481 "15053",
1482 "12580",
1483 "12475",
1484 "12472",
1485 "12953",
1486 "12488",
1487 "11189",
1488 "12985",
1489 "12519",
1490 "16758",
1491 "11958",
1492 "12490",
1493 "11426",
1494 "3565",
1495 "3562",
1496 "18960",
1497 "3567",
1498 "3561",
1499 "3566",
1500 "3563",
1501 "1953",
1502 "2139",
1503 "12505",
1504 "13018",
1505 "12522",
1506 "12523",
1507 "5146",
1508 "5144",
1509 "5148",
1510 "8419",
1511 "8418",
1512 "10213",
1513 "10212",
1514 "10157",
1515 "12524",
1516 "13019",
1517 "12525",
1518 "13020",
1519 "12526",
1520 "13021",
1521 "18809",
1522 "13031",
1523 "13032",
1524 "13033",
1525 "4036",
1526 "3920",
1527 "3919",
1528 "3918",
1529 "7430",
1530 "3922",
1531 "3923",
1532 "7411",
1533 "7418",
1534 "7421",
1535 "13262",
1536 "7412",
1537 "7415",
1538 "7413",
1539 "7416",
1540 "13920",
1541 "13921",
1542 "7745",
1543 "7779",
1544 "7428",
1545 "7457",
1546 "7857",
1547 "7748",
1548 "7426",
1549 "13421",
1550 "7454",
1551 "13378",
1552 "7788",
1553 "14807",
1554 "14293",
1555 "7795",
1556 "6296",
1557 "20608",
1558 "755",
1559 "444",
1560 "427",
1561 "428",
1562 "442",
1563 "447",
1564 "3578",
1565 "3581",
1566 "19027",
1567 "3580",
1568 "665",
1569 "3579",
1570 "3577",
1571 "6755",
1572 "3576",
1573 "2575",
1574 "2577",
1575 "2578",
1576 "2579",
1577 "2580",
1578 "2656",
1579 "2657",
1580 "2576",
1581 "3564",
1582 "10248",
1583 "8388",
1584 "2659",
1585 "14891",
1586 "3308",
1587 "3307",
1588 "10097",
1589 "2658",
1590 "3569",
1591 "16153",
1592 "3304",
1593 "10098",
1594 "4037",
1595 "3929",
1596 "3931",
1597 "3926",
1598 "3924",
1599 "3930",
1600 "3977",
1601 "3925",
1602 "136",
1603 "228",
1604 "5487",
1605 "43",
1606 "202",
1610 int loop = 0;
1611 while(strcmp(allSpellList[loop], "0"))
1613 uint32 spell = atol((char*)allSpellList[loop++]);
1615 if (m_session->GetPlayer()->HasSpell(spell))
1616 continue;
1618 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
1619 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
1621 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
1622 continue;
1625 m_session->GetPlayer()->learnSpell(spell);
1628 SendSysMessage(LANG_COMMAND_LEARN_MANY_SPELLS);
1630 return true;
1633 bool ChatHandler::HandleLearnAllGMCommand(const char* /*args*/)
1635 static const char *gmSpellList[] =
1637 "24347", // Become A Fish, No Breath Bar
1638 "35132", // Visual Boom
1639 "38488", // Attack 4000-8000 AOE
1640 "38795", // Attack 2000 AOE + Slow Down 90%
1641 "15712", // Attack 200
1642 "1852", // GM Spell Silence
1643 "31899", // Kill
1644 "31924", // Kill
1645 "29878", // Kill My Self
1646 "26644", // More Kill
1648 "28550", //Invisible 24
1649 "23452", //Invisible + Target
1653 uint16 gmSpellIter = 0;
1654 while( strcmp(gmSpellList[gmSpellIter], "0") )
1656 uint32 spell = atol((char*)gmSpellList[gmSpellIter++]);
1658 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
1659 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
1661 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
1662 continue;
1665 m_session->GetPlayer()->learnSpell(spell);
1668 SendSysMessage(LANG_LEARNING_GM_SKILLS);
1669 return true;
1672 bool ChatHandler::HandleLearnAllMyClassCommand(const char* /*args*/)
1674 HandleLearnAllMySpellsCommand("");
1675 HandleLearnAllMyTalentsCommand("");
1676 return true;
1679 bool ChatHandler::HandleLearnAllMySpellsCommand(const char* /*args*/)
1681 ChrClassesEntry const* clsEntry = sChrClassesStore.LookupEntry(m_session->GetPlayer()->getClass());
1682 if(!clsEntry)
1683 return true;
1684 uint32 family = clsEntry->spellfamily;
1686 for (uint32 i = 0; i < sSpellStore.GetNumRows(); i++)
1688 SpellEntry const *spellInfo = sSpellStore.LookupEntry(i);
1689 if(!spellInfo)
1690 continue;
1692 // skip wrong class/race skills
1693 if(!m_session->GetPlayer()->IsSpellFitByClassAndRace(spellInfo->Id))
1694 continue;
1696 // skip other spell families
1697 if( spellInfo->SpellFamilyName != family)
1698 continue;
1700 //TODO: skip triggered spells
1702 // skip spells with first rank learned as talent (and all talents then also)
1703 uint32 first_rank = spellmgr.GetFirstSpellInChain(spellInfo->Id);
1704 if(GetTalentSpellCost(first_rank) > 0 )
1705 continue;
1707 // skip broken spells
1708 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
1709 continue;
1711 m_session->GetPlayer()->learnSpell(i);
1714 SendSysMessage(LANG_COMMAND_LEARN_CLASS_SPELLS);
1715 return true;
1718 static void learnAllHighRanks(Player* player, uint32 spellid)
1720 SpellChainMapNext const& nextMap = spellmgr.GetSpellChainNext();
1721 for(SpellChainMapNext::const_iterator itr = nextMap.lower_bound(spellid); itr != nextMap.upper_bound(spellid); ++itr)
1723 player->learnSpell(itr->second);
1724 learnAllHighRanks(player,itr->second);
1728 bool ChatHandler::HandleLearnAllMyTalentsCommand(const char* /*args*/)
1730 Player* player = m_session->GetPlayer();
1731 uint32 classMask = player->getClassMask();
1733 for (uint32 i = 0; i < sTalentStore.GetNumRows(); i++)
1735 TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
1736 if(!talentInfo)
1737 continue;
1739 TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentInfo->TalentTab );
1740 if(!talentTabInfo)
1741 continue;
1743 if( (classMask & talentTabInfo->ClassMask) == 0 )
1744 continue;
1746 // search highest talent rank
1747 uint32 spellid = 0;
1748 int rank = 4;
1749 for(; rank >= 0; --rank)
1751 if(talentInfo->RankID[rank]!=0)
1753 spellid = talentInfo->RankID[rank];
1754 break;
1758 if(!spellid) // ??? none spells in telent
1759 continue;
1761 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellid);
1762 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
1763 continue;
1765 // learn highest rank of talent
1766 player->learnSpell(spellid);
1768 // and learn all non-talent spell ranks (recursive by tree)
1769 learnAllHighRanks(player,spellid);
1772 SendSysMessage(LANG_COMMAND_LEARN_CLASS_TALENTS);
1773 return true;
1776 bool ChatHandler::HandleLearnAllLangCommand(const char* /*args*/)
1778 // skipping UNIVERSAL language (0)
1779 for(int i = 1; i < LANGUAGES_COUNT; ++i)
1780 m_session->GetPlayer()->learnSpell(lang_description[i].spell_id);
1782 SendSysMessage(LANG_COMMAND_LEARN_ALL_LANG);
1783 return true;
1786 bool ChatHandler::HandleLearnAllDefaultCommand(const char* args)
1788 char* pName = strtok((char*)args, "");
1789 Player *player = NULL;
1790 if (pName)
1792 std::string name = pName;
1794 if(!normalizePlayerName(name))
1796 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1797 SetSentErrorMessage(true);
1798 return false;
1801 player = objmgr.GetPlayer(name.c_str());
1803 else
1804 player = getSelectedPlayer();
1806 if(!player)
1808 SendSysMessage(LANG_NO_CHAR_SELECTED);
1809 SetSentErrorMessage(true);
1810 return false;
1813 player->learnDefaultSpells();
1814 player->learnQuestRewardedSpells();
1816 PSendSysMessage(LANG_COMMAND_LEARN_ALL_DEFAULT_AND_QUEST,player->GetName());
1817 return true;
1820 bool ChatHandler::HandleLearnCommand(const char* args)
1822 Player* targetPlayer = getSelectedPlayer();
1824 if(!targetPlayer)
1826 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1827 SetSentErrorMessage(true);
1828 return false;
1831 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1832 uint32 spell = extractSpellIdFromLink((char*)args);
1833 if(!spell || !sSpellStore.LookupEntry(spell))
1834 return false;
1836 if (targetPlayer->HasSpell(spell))
1838 if(targetPlayer == m_session->GetPlayer())
1839 SendSysMessage(LANG_YOU_KNOWN_SPELL);
1840 else
1841 PSendSysMessage(LANG_TARGET_KNOWN_SPELL,targetPlayer->GetName());
1842 SetSentErrorMessage(true);
1843 return false;
1846 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
1847 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
1849 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
1850 SetSentErrorMessage(true);
1851 return false;
1854 targetPlayer->learnSpell(spell);
1856 return true;
1859 bool ChatHandler::HandleAddItemCommand(const char* args)
1861 if (!*args)
1862 return false;
1864 uint32 itemId = 0;
1866 if(args[0]=='[') // [name] manual form
1868 char* citemName = citemName = strtok((char*)args, "]");
1870 if(citemName && citemName[0])
1872 std::string itemName = citemName+1;
1873 WorldDatabase.escape_string(itemName);
1874 QueryResult *result = WorldDatabase.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName.c_str());
1875 if (!result)
1877 PSendSysMessage(LANG_COMMAND_COULDNOTFIND, citemName+1);
1878 SetSentErrorMessage(true);
1879 return false;
1881 itemId = result->Fetch()->GetUInt16();
1882 delete result;
1884 else
1885 return false;
1887 else // item_id or [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r
1889 char* cId = extractKeyFromLink((char*)args,"Hitem");
1890 if(!cId)
1891 return false;
1892 itemId = atol(cId);
1895 char* ccount = strtok(NULL, " ");
1897 int32 count = 1;
1899 if (ccount)
1900 count = strtol(ccount, NULL, 10);
1902 if (count == 0)
1903 count = 1;
1905 Player* pl = m_session->GetPlayer();
1906 Player* plTarget = getSelectedPlayer();
1907 if(!plTarget)
1908 plTarget = pl;
1910 sLog.outDetail(GetMangosString(LANG_ADDITEM), itemId, count);
1912 ItemPrototype const *pProto = objmgr.GetItemPrototype(itemId);
1913 if(!pProto)
1915 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, itemId);
1916 SetSentErrorMessage(true);
1917 return false;
1920 //Subtract
1921 if (count < 0)
1923 plTarget->DestroyItemCount(itemId, -count, true, false);
1924 PSendSysMessage(LANG_REMOVEITEM, itemId, -count, plTarget->GetName());
1925 return true;
1928 //Adding items
1929 uint32 noSpaceForCount = 0;
1931 // check space and find places
1932 ItemPosCountVec dest;
1933 uint8 msg = plTarget->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, itemId, count, &noSpaceForCount );
1934 if( msg != EQUIP_ERR_OK ) // convert to possible store amount
1935 count -= noSpaceForCount;
1937 if( count == 0 || dest.empty()) // can't add any
1939 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount );
1940 SetSentErrorMessage(true);
1941 return false;
1944 Item* item = plTarget->StoreNewItem( dest, itemId, true, Item::GenerateItemRandomPropertyId(itemId));
1946 // remove binding (let GM give it to another player later)
1947 if(pl==plTarget)
1948 for(ItemPosCountVec::const_iterator itr = dest.begin(); itr != dest.end(); ++itr)
1949 if(Item* item1 = pl->GetItemByPos(itr->pos))
1950 item1->SetBinding( false );
1952 if(count > 0 && item)
1954 pl->SendNewItem(item,count,false,true);
1955 if(pl!=plTarget)
1956 plTarget->SendNewItem(item,count,true,false);
1959 if(noSpaceForCount > 0)
1960 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount);
1962 return true;
1965 bool ChatHandler::HandleAddItemSetCommand(const char* args)
1967 if (!*args)
1968 return false;
1970 char* cId = extractKeyFromLink((char*)args,"Hitemset"); // number or [name] Shift-click form |color|Hitemset:itemset_id|h[name]|h|r
1971 if (!cId)
1972 return false;
1974 uint32 itemsetId = atol(cId);
1976 // prevent generation all items with itemset field value '0'
1977 if (itemsetId == 0)
1979 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND,itemsetId);
1980 SetSentErrorMessage(true);
1981 return false;
1984 Player* pl = m_session->GetPlayer();
1985 Player* plTarget = getSelectedPlayer();
1986 if(!plTarget)
1987 plTarget = pl;
1989 sLog.outDetail(GetMangosString(LANG_ADDITEMSET), itemsetId);
1991 QueryResult *result = WorldDatabase.PQuery("SELECT entry FROM item_template WHERE itemset = %u",itemsetId);
1993 if(!result)
1995 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND,itemsetId);
1997 SetSentErrorMessage(true);
1998 return false;
2003 Field *fields = result->Fetch();
2004 uint32 itemId = fields[0].GetUInt32();
2006 ItemPosCountVec dest;
2007 uint8 msg = plTarget->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, itemId, 1 );
2008 if( msg == EQUIP_ERR_OK )
2010 Item* item = plTarget->StoreNewItem( dest, itemId, true);
2012 // remove binding (let GM give it to another player later)
2013 if(pl==plTarget)
2014 item->SetBinding( false );
2016 pl->SendNewItem(item,1,false,true);
2017 if(pl!=plTarget)
2018 plTarget->SendNewItem(item,1,true,false);
2020 else
2022 pl->SendEquipError( msg, NULL, NULL );
2023 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, 1);
2026 }while( result->NextRow() );
2028 delete result;
2030 return true;
2033 bool ChatHandler::HandleListItemCommand(const char* args)
2035 if(!*args)
2036 return false;
2038 char* cId = extractKeyFromLink((char*)args,"Hitem");
2039 if(!cId)
2040 return false;
2042 uint32 item_id = atol(cId);
2043 if(!item_id)
2045 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
2046 SetSentErrorMessage(true);
2047 return false;
2050 ItemPrototype const* itemProto = objmgr.GetItemPrototype(item_id);
2051 if(!itemProto)
2053 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
2054 SetSentErrorMessage(true);
2055 return false;
2058 char* c_count = strtok(NULL, " ");
2059 int count = c_count ? atol(c_count) : 10;
2061 if(count < 0)
2062 return false;
2064 QueryResult *result;
2066 // inventory case
2067 uint32 inv_count = 0;
2068 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM character_inventory WHERE item_template='%u'",item_id);
2069 if(result)
2071 inv_count = (*result)[0].GetUInt32();
2072 delete result;
2075 result=CharacterDatabase.PQuery(
2076 // 0 1 2 3 4 5
2077 "SELECT ci.item, cibag.slot AS bag, ci.slot, ci.guid, characters.account,characters.name "
2078 "FROM character_inventory AS ci LEFT JOIN character_inventory AS cibag ON (cibag.item=ci.bag),characters "
2079 "WHERE ci.item_template='%u' AND ci.guid = characters.guid LIMIT %u ",
2080 item_id,uint32(count));
2082 if(result)
2086 Field *fields = result->Fetch();
2087 uint32 item_guid = fields[0].GetUInt32();
2088 uint32 item_bag = fields[1].GetUInt32();
2089 uint32 item_slot = fields[2].GetUInt32();
2090 uint32 owner_guid = fields[3].GetUInt32();
2091 uint32 owner_acc = fields[4].GetUInt32();
2092 std::string owner_name = fields[5].GetCppString();
2094 char const* item_pos = 0;
2095 if(Player::IsEquipmentPos(item_bag,item_slot))
2096 item_pos = "[equipped]";
2097 else if(Player::IsInventoryPos(item_bag,item_slot))
2098 item_pos = "[in inventory]";
2099 else if(Player::IsBankPos(item_bag,item_slot))
2100 item_pos = "[in bank]";
2101 else
2102 item_pos = "";
2104 PSendSysMessage(LANG_ITEMLIST_SLOT,
2105 item_guid,owner_name.c_str(),owner_guid,owner_acc,item_pos);
2106 } while (result->NextRow());
2108 int64 res_count = result->GetRowCount();
2110 delete result;
2112 if(count > res_count)
2113 count-=res_count;
2114 else if(count)
2115 count = 0;
2118 // mail case
2119 uint32 mail_count = 0;
2120 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM mail_items WHERE item_template='%u'", item_id);
2121 if(result)
2123 mail_count = (*result)[0].GetUInt32();
2124 delete result;
2127 if(count > 0)
2129 result=CharacterDatabase.PQuery(
2130 // 0 1 2 3 4 5 6
2131 "SELECT mail_items.item_guid, mail.sender, mail.receiver, char_s.account, char_s.name, char_r.account, char_r.name "
2132 "FROM mail,mail_items,characters as char_s,characters as char_r "
2133 "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",
2134 item_id,uint32(count));
2136 else
2137 result = NULL;
2139 if(result)
2143 Field *fields = result->Fetch();
2144 uint32 item_guid = fields[0].GetUInt32();
2145 uint32 item_s = fields[1].GetUInt32();
2146 uint32 item_r = fields[2].GetUInt32();
2147 uint32 item_s_acc = fields[3].GetUInt32();
2148 std::string item_s_name = fields[4].GetCppString();
2149 uint32 item_r_acc = fields[5].GetUInt32();
2150 std::string item_r_name = fields[6].GetCppString();
2152 char const* item_pos = "[in mail]";
2154 PSendSysMessage(LANG_ITEMLIST_MAIL,
2155 item_guid,item_s_name.c_str(),item_s,item_s_acc,item_r_name.c_str(),item_r,item_r_acc,item_pos);
2156 } while (result->NextRow());
2158 int64 res_count = result->GetRowCount();
2160 delete result;
2162 if(count > res_count)
2163 count-=res_count;
2164 else if(count)
2165 count = 0;
2168 // auction case
2169 uint32 auc_count = 0;
2170 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM auctionhouse WHERE item_template='%u'",item_id);
2171 if(result)
2173 auc_count = (*result)[0].GetUInt32();
2174 delete result;
2177 if(count > 0)
2179 result=CharacterDatabase.PQuery(
2180 // 0 1 2 3
2181 "SELECT auctionhouse.itemguid, auctionhouse.itemowner, characters.account, characters.name "
2182 "FROM auctionhouse,characters WHERE auctionhouse.item_template='%u' AND characters.guid = auctionhouse.itemowner LIMIT %u",
2183 item_id,uint32(count));
2185 else
2186 result = NULL;
2188 if(result)
2192 Field *fields = result->Fetch();
2193 uint32 item_guid = fields[0].GetUInt32();
2194 uint32 owner = fields[1].GetUInt32();
2195 uint32 owner_acc = fields[2].GetUInt32();
2196 std::string owner_name = fields[3].GetCppString();
2198 char const* item_pos = "[in auction]";
2200 PSendSysMessage(LANG_ITEMLIST_AUCTION, item_guid, owner_name.c_str(), owner, owner_acc,item_pos);
2201 } while (result->NextRow());
2203 delete result;
2206 // guild bank case
2207 uint32 guild_count = 0;
2208 result=CharacterDatabase.PQuery("SELECT COUNT(item_entry) FROM guild_bank_item WHERE item_entry='%u'",item_id);
2209 if(result)
2211 guild_count = (*result)[0].GetUInt32();
2212 delete result;
2215 result=CharacterDatabase.PQuery(
2216 // 0 1 2
2217 "SELECT gi.item_guid, gi.guildid, guild.name "
2218 "FROM guild_bank_item AS gi, guild WHERE gi.item_entry='%u' AND gi.guildid = guild.guildid LIMIT %u ",
2219 item_id,uint32(count));
2221 if(result)
2225 Field *fields = result->Fetch();
2226 uint32 item_guid = fields[0].GetUInt32();
2227 uint32 guild_guid = fields[1].GetUInt32();
2228 std::string guild_name = fields[2].GetCppString();
2230 char const* item_pos = "[in guild bank]";
2232 PSendSysMessage(LANG_ITEMLIST_GUILD,item_guid,guild_name.c_str(),guild_guid,item_pos);
2233 } while (result->NextRow());
2235 int64 res_count = result->GetRowCount();
2237 delete result;
2239 if(count > res_count)
2240 count-=res_count;
2241 else if(count)
2242 count = 0;
2245 if(inv_count+mail_count+auc_count+guild_count == 0)
2247 SendSysMessage(LANG_COMMAND_NOITEMFOUND);
2248 SetSentErrorMessage(true);
2249 return false;
2252 PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE,item_id,inv_count+mail_count+auc_count+guild_count,inv_count,mail_count,auc_count,guild_count);
2254 return true;
2257 bool ChatHandler::HandleListObjectCommand(const char* args)
2259 if(!*args)
2260 return false;
2262 // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2263 char* cId = extractKeyFromLink((char*)args,"Hgameobject_entry");
2264 if(!cId)
2265 return false;
2267 uint32 go_id = atol(cId);
2268 if(!go_id)
2270 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, go_id);
2271 SetSentErrorMessage(true);
2272 return false;
2275 GameObjectInfo const * gInfo = objmgr.GetGameObjectInfo(go_id);
2276 if(!gInfo)
2278 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, go_id);
2279 SetSentErrorMessage(true);
2280 return false;
2283 char* c_count = strtok(NULL, " ");
2284 int count = c_count ? atol(c_count) : 10;
2286 if(count < 0)
2287 return false;
2289 QueryResult *result;
2291 uint32 obj_count = 0;
2292 result=WorldDatabase.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'",go_id);
2293 if(result)
2295 obj_count = (*result)[0].GetUInt32();
2296 delete result;
2299 if(m_session)
2301 Player* pl = m_session->GetPlayer();
2302 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",
2303 pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(),go_id,uint32(count));
2305 else
2306 result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map FROM gameobject WHERE id = '%u' LIMIT %u",
2307 go_id,uint32(count));
2309 if (result)
2313 Field *fields = result->Fetch();
2314 uint32 guid = fields[0].GetUInt32();
2315 float x = fields[1].GetFloat();
2316 float y = fields[2].GetFloat();
2317 float z = fields[3].GetFloat();
2318 int mapid = fields[4].GetUInt16();
2320 if (m_session)
2321 PSendSysMessage(LANG_GO_LIST_CHAT, guid, guid, gInfo->name, x, y, z, mapid);
2322 else
2323 PSendSysMessage(LANG_GO_LIST_CONSOLE, guid, gInfo->name, x, y, z, mapid);
2324 } while (result->NextRow());
2326 delete result;
2329 PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE,go_id,obj_count);
2330 return true;
2333 bool ChatHandler::HandleNearObjectCommand(const char* args)
2335 float distance = (!*args) ? 10 : atol(args);
2336 uint32 count = 0;
2338 Player* pl = m_session->GetPlayer();
2339 QueryResult *result = WorldDatabase.PQuery("SELECT guid, id, position_x, position_y, position_z, map, "
2340 "(POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ "
2341 "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_",
2342 pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(),
2343 pl->GetMapId(),pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(),distance*distance);
2345 if (result)
2349 Field *fields = result->Fetch();
2350 uint32 guid = fields[0].GetUInt32();
2351 uint32 entry = fields[1].GetUInt32();
2352 float x = fields[2].GetFloat();
2353 float y = fields[3].GetFloat();
2354 float z = fields[4].GetFloat();
2355 int mapid = fields[5].GetUInt16();
2357 GameObjectInfo const * gInfo = objmgr.GetGameObjectInfo(entry);
2359 if(!gInfo)
2360 continue;
2362 PSendSysMessage(LANG_GO_LIST_CHAT, guid, guid, gInfo->name, x, y, z, mapid);
2364 ++count;
2365 } while (result->NextRow());
2367 delete result;
2370 PSendSysMessage(LANG_COMMAND_NEAROBJMESSAGE,distance,count);
2371 return true;
2374 bool ChatHandler::HandleListCreatureCommand(const char* args)
2376 if(!*args)
2377 return false;
2379 // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
2380 char* cId = extractKeyFromLink((char*)args,"Hcreature_entry");
2381 if(!cId)
2382 return false;
2384 uint32 cr_id = atol(cId);
2385 if(!cr_id)
2387 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, cr_id);
2388 SetSentErrorMessage(true);
2389 return false;
2392 CreatureInfo const* cInfo = objmgr.GetCreatureTemplate(cr_id);
2393 if(!cInfo)
2395 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, cr_id);
2396 SetSentErrorMessage(true);
2397 return false;
2400 char* c_count = strtok(NULL, " ");
2401 int count = c_count ? atol(c_count) : 10;
2403 if(count < 0)
2404 return false;
2406 QueryResult *result;
2408 uint32 cr_count = 0;
2409 result=WorldDatabase.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'",cr_id);
2410 if(result)
2412 cr_count = (*result)[0].GetUInt32();
2413 delete result;
2416 if(m_session)
2418 Player* pl = m_session->GetPlayer();
2419 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",
2420 pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(), cr_id,uint32(count));
2422 else
2423 result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '%u' LIMIT %u",
2424 cr_id,uint32(count));
2426 if (result)
2430 Field *fields = result->Fetch();
2431 uint32 guid = fields[0].GetUInt32();
2432 float x = fields[1].GetFloat();
2433 float y = fields[2].GetFloat();
2434 float z = fields[3].GetFloat();
2435 int mapid = fields[4].GetUInt16();
2437 if (m_session)
2438 PSendSysMessage(LANG_CREATURE_LIST_CHAT, guid, guid, cInfo->Name, x, y, z, mapid);
2439 else
2440 PSendSysMessage(LANG_CREATURE_LIST_CONSOLE, guid, cInfo->Name, x, y, z, mapid);
2441 } while (result->NextRow());
2443 delete result;
2446 PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE,cr_id,cr_count);
2447 return true;
2450 bool ChatHandler::HandleLookupItemCommand(const char* args)
2452 if(!*args)
2453 return false;
2455 std::string namepart = args;
2456 std::wstring wnamepart;
2458 // converting string that we try to find to lower case
2459 if(!Utf8toWStr(namepart,wnamepart))
2460 return false;
2462 wstrToLower(wnamepart);
2464 uint32 counter = 0;
2466 // Search in `item_template`
2467 for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
2469 ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype >(id);
2470 if(!pProto)
2471 continue;
2473 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
2474 if ( loc_idx >= 0 )
2476 ItemLocale const *il = objmgr.GetItemLocale(pProto->ItemId);
2477 if (il)
2479 if (il->Name.size() > loc_idx && !il->Name[loc_idx].empty())
2481 std::string name = il->Name[loc_idx];
2483 if (Utf8FitTo(name, wnamepart))
2485 if (m_session)
2486 PSendSysMessage(LANG_ITEM_LIST_CHAT, id, id, name.c_str());
2487 else
2488 PSendSysMessage(LANG_ITEM_LIST_CONSOLE, id, name.c_str());
2489 ++counter;
2490 continue;
2496 std::string name = pProto->Name1;
2497 if(name.empty())
2498 continue;
2500 if (Utf8FitTo(name, wnamepart))
2502 if (m_session)
2503 PSendSysMessage(LANG_ITEM_LIST_CHAT, id, id, name.c_str());
2504 else
2505 PSendSysMessage(LANG_ITEM_LIST_CONSOLE, id, name.c_str());
2506 ++counter;
2510 if (counter==0)
2511 SendSysMessage(LANG_COMMAND_NOITEMFOUND);
2513 return true;
2516 bool ChatHandler::HandleLookupItemSetCommand(const char* args)
2518 if(!*args)
2519 return false;
2521 std::string namepart = args;
2522 std::wstring wnamepart;
2524 if(!Utf8toWStr(namepart,wnamepart))
2525 return false;
2527 // converting string that we try to find to lower case
2528 wstrToLower( wnamepart );
2530 uint32 counter = 0; // Counter for figure out that we found smth.
2532 // Search in ItemSet.dbc
2533 for (uint32 id = 0; id < sItemSetStore.GetNumRows(); id++)
2535 ItemSetEntry const *set = sItemSetStore.LookupEntry(id);
2536 if(set)
2538 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
2539 std::string name = set->name[loc];
2540 if(name.empty())
2541 continue;
2543 if (!Utf8FitTo(name, wnamepart))
2545 loc = 0;
2546 for(; loc < MAX_LOCALE; ++loc)
2548 if(m_session && loc==m_session->GetSessionDbcLocale())
2549 continue;
2551 name = set->name[loc];
2552 if(name.empty())
2553 continue;
2555 if (Utf8FitTo(name, wnamepart))
2556 break;
2560 if(loc < MAX_LOCALE)
2562 // send item set in "id - [namedlink locale]" format
2563 if (m_session)
2564 PSendSysMessage(LANG_ITEMSET_LIST_CHAT,id,id,name.c_str(),localeNames[loc]);
2565 else
2566 PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE,id,name.c_str(),localeNames[loc]);
2567 ++counter;
2571 if (counter == 0) // if counter == 0 then we found nth
2572 SendSysMessage(LANG_COMMAND_NOITEMSETFOUND);
2573 return true;
2576 bool ChatHandler::HandleLookupSkillCommand(const char* args)
2578 if(!*args)
2579 return false;
2581 // can be NULL in console call
2582 Player* target = getSelectedPlayer();
2584 std::string namepart = args;
2585 std::wstring wnamepart;
2587 if(!Utf8toWStr(namepart,wnamepart))
2588 return false;
2590 // converting string that we try to find to lower case
2591 wstrToLower( wnamepart );
2593 uint32 counter = 0; // Counter for figure out that we found smth.
2595 // Search in SkillLine.dbc
2596 for (uint32 id = 0; id < sSkillLineStore.GetNumRows(); id++)
2598 SkillLineEntry const *skillInfo = sSkillLineStore.LookupEntry(id);
2599 if(skillInfo)
2601 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
2602 std::string name = skillInfo->name[loc];
2603 if(name.empty())
2604 continue;
2606 if (!Utf8FitTo(name, wnamepart))
2608 loc = 0;
2609 for(; loc < MAX_LOCALE; ++loc)
2611 if(m_session && loc==m_session->GetSessionDbcLocale())
2612 continue;
2614 name = skillInfo->name[loc];
2615 if(name.empty())
2616 continue;
2618 if (Utf8FitTo(name, wnamepart))
2619 break;
2623 if(loc < MAX_LOCALE)
2625 char const* knownStr = "";
2626 if(target && target->HasSkill(id))
2627 knownStr = GetMangosString(LANG_KNOWN);
2629 // send skill in "id - [namedlink locale]" format
2630 if (m_session)
2631 PSendSysMessage(LANG_SKILL_LIST_CHAT,id,id,name.c_str(),localeNames[loc],knownStr);
2632 else
2633 PSendSysMessage(LANG_SKILL_LIST_CONSOLE,id,name.c_str(),localeNames[loc],knownStr);
2635 ++counter;
2639 if (counter == 0) // if counter == 0 then we found nth
2640 SendSysMessage(LANG_COMMAND_NOSKILLFOUND);
2641 return true;
2644 bool ChatHandler::HandleLookupSpellCommand(const char* args)
2646 if(!*args)
2647 return false;
2649 // can be NULL at console call
2650 Player* target = getSelectedPlayer();
2652 std::string namepart = args;
2653 std::wstring wnamepart;
2655 if(!Utf8toWStr(namepart,wnamepart))
2656 return false;
2658 // converting string that we try to find to lower case
2659 wstrToLower( wnamepart );
2661 uint32 counter = 0; // Counter for figure out that we found smth.
2663 // Search in Spell.dbc
2664 for (uint32 id = 0; id < sSpellStore.GetNumRows(); id++)
2666 SpellEntry const *spellInfo = sSpellStore.LookupEntry(id);
2667 if(spellInfo)
2669 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
2670 std::string name = spellInfo->SpellName[loc];
2671 if(name.empty())
2672 continue;
2674 if (!Utf8FitTo(name, wnamepart))
2676 loc = 0;
2677 for(; loc < MAX_LOCALE; ++loc)
2679 if(m_session && loc==m_session->GetSessionDbcLocale())
2680 continue;
2682 name = spellInfo->SpellName[loc];
2683 if(name.empty())
2684 continue;
2686 if (Utf8FitTo(name, wnamepart))
2687 break;
2691 if(loc < MAX_LOCALE)
2693 bool known = target && target->HasSpell(id);
2694 bool learn = (spellInfo->Effect[0] == SPELL_EFFECT_LEARN_SPELL);
2696 uint32 telentCost = GetTalentSpellCost(id);
2698 bool talent = (telentCost > 0);
2699 bool passive = IsPassiveSpell(id);
2700 bool active = target && (target->HasAura(id,0) || target->HasAura(id,1) || target->HasAura(id,2));
2702 // unit32 used to prevent interpreting uint8 as char at output
2703 // find rank of learned spell for learning spell, or talent rank
2704 uint32 rank = telentCost ? telentCost : spellmgr.GetSpellRank(learn ? spellInfo->EffectTriggerSpell[0] : id);
2706 // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
2707 std::ostringstream ss;
2708 if (m_session)
2709 ss << id << " - |cffffffff|Hspell:" << id << "|h[" << name;
2710 else
2711 ss << id << " - " << name;
2713 // include rank in link name
2714 if(rank)
2715 ss << GetMangosString(LANG_SPELL_RANK) << rank;
2717 if (m_session)
2718 ss << " " << localeNames[loc] << "]|h|r";
2719 else
2720 ss << " " << localeNames[loc];
2722 if(talent)
2723 ss << GetMangosString(LANG_TALENT);
2724 if(passive)
2725 ss << GetMangosString(LANG_PASSIVE);
2726 if(learn)
2727 ss << GetMangosString(LANG_LEARN);
2728 if(known)
2729 ss << GetMangosString(LANG_KNOWN);
2730 if(active)
2731 ss << GetMangosString(LANG_ACTIVE);
2733 SendSysMessage(ss.str().c_str());
2735 ++counter;
2739 if (counter == 0) // if counter == 0 then we found nth
2740 SendSysMessage(LANG_COMMAND_NOSPELLFOUND);
2741 return true;
2744 bool ChatHandler::HandleLookupQuestCommand(const char* args)
2746 if(!*args)
2747 return false;
2749 // can be NULL at console call
2750 Player* target = getSelectedPlayer();
2752 std::string namepart = args;
2753 std::wstring wnamepart;
2755 // converting string that we try to find to lower case
2756 if(!Utf8toWStr(namepart,wnamepart))
2757 return false;
2759 wstrToLower(wnamepart);
2761 uint32 counter = 0 ;
2763 ObjectMgr::QuestMap const& qTemplates = objmgr.GetQuestTemplates();
2764 for (ObjectMgr::QuestMap::const_iterator iter = qTemplates.begin(); iter != qTemplates.end(); ++iter)
2766 Quest * qinfo = iter->second;
2768 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
2769 if ( loc_idx >= 0 )
2771 QuestLocale const *il = objmgr.GetQuestLocale(qinfo->GetQuestId());
2772 if (il)
2774 if (il->Title.size() > loc_idx && !il->Title[loc_idx].empty())
2776 std::string title = il->Title[loc_idx];
2778 if (Utf8FitTo(title, wnamepart))
2780 char const* statusStr = "";
2782 if(target)
2784 QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId());
2786 if(status == QUEST_STATUS_COMPLETE)
2788 if(target->GetQuestRewardStatus(qinfo->GetQuestId()))
2789 statusStr = GetMangosString(LANG_COMMAND_QUEST_REWARDED);
2790 else
2791 statusStr = GetMangosString(LANG_COMMAND_QUEST_COMPLETE);
2793 else if(status == QUEST_STATUS_INCOMPLETE)
2794 statusStr = GetMangosString(LANG_COMMAND_QUEST_ACTIVE);
2797 if (m_session)
2798 PSendSysMessage(LANG_QUEST_LIST_CHAT,qinfo->GetQuestId(),qinfo->GetQuestId(),title.c_str(),statusStr);
2799 else
2800 PSendSysMessage(LANG_QUEST_LIST_CONSOLE,qinfo->GetQuestId(),title.c_str(),statusStr);
2801 ++counter;
2802 continue;
2808 std::string title = qinfo->GetTitle();
2809 if(title.empty())
2810 continue;
2812 if (Utf8FitTo(title, wnamepart))
2814 char const* statusStr = "";
2816 if(target)
2818 QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId());
2820 if(status == QUEST_STATUS_COMPLETE)
2822 if(target->GetQuestRewardStatus(qinfo->GetQuestId()))
2823 statusStr = GetMangosString(LANG_COMMAND_QUEST_REWARDED);
2824 else
2825 statusStr = GetMangosString(LANG_COMMAND_QUEST_COMPLETE);
2827 else if(status == QUEST_STATUS_INCOMPLETE)
2828 statusStr = GetMangosString(LANG_COMMAND_QUEST_ACTIVE);
2831 if (m_session)
2832 PSendSysMessage(LANG_QUEST_LIST_CHAT,qinfo->GetQuestId(),qinfo->GetQuestId(),title.c_str(),statusStr);
2833 else
2834 PSendSysMessage(LANG_QUEST_LIST_CONSOLE,qinfo->GetQuestId(),title.c_str(),statusStr);
2836 ++counter;
2840 if (counter==0)
2841 SendSysMessage(LANG_COMMAND_NOQUESTFOUND);
2843 return true;
2846 bool ChatHandler::HandleLookupCreatureCommand(const char* args)
2848 if (!*args)
2849 return false;
2851 std::string namepart = args;
2852 std::wstring wnamepart;
2854 // converting string that we try to find to lower case
2855 if (!Utf8toWStr (namepart,wnamepart))
2856 return false;
2858 wstrToLower (wnamepart);
2860 uint32 counter = 0;
2862 for (uint32 id = 0; id< sCreatureStorage.MaxEntry; ++id)
2864 CreatureInfo const* cInfo = sCreatureStorage.LookupEntry<CreatureInfo> (id);
2865 if(!cInfo)
2866 continue;
2868 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
2869 if (loc_idx >= 0)
2871 CreatureLocale const *cl = objmgr.GetCreatureLocale (id);
2872 if (cl)
2874 if (cl->Name.size() > loc_idx && !cl->Name[loc_idx].empty ())
2876 std::string name = cl->Name[loc_idx];
2878 if (Utf8FitTo (name, wnamepart))
2880 if (m_session)
2881 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str ());
2882 else
2883 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE, id, name.c_str ());
2884 ++counter;
2885 continue;
2891 std::string name = cInfo->Name;
2892 if (name.empty ())
2893 continue;
2895 if (Utf8FitTo(name, wnamepart))
2897 if (m_session)
2898 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str ());
2899 else
2900 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE, id, name.c_str ());
2901 ++counter;
2905 if (counter==0)
2906 SendSysMessage (LANG_COMMAND_NOCREATUREFOUND);
2908 return true;
2911 bool ChatHandler::HandleLookupObjectCommand(const char* args)
2913 if(!*args)
2914 return false;
2916 std::string namepart = args;
2917 std::wstring wnamepart;
2919 // converting string that we try to find to lower case
2920 if(!Utf8toWStr(namepart,wnamepart))
2921 return false;
2923 wstrToLower(wnamepart);
2925 uint32 counter = 0;
2927 for (uint32 id = 0; id< sGOStorage.MaxEntry; id++ )
2929 GameObjectInfo const* gInfo = sGOStorage.LookupEntry<GameObjectInfo>(id);
2930 if(!gInfo)
2931 continue;
2933 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
2934 if ( loc_idx >= 0 )
2936 GameObjectLocale const *gl = objmgr.GetGameObjectLocale(id);
2937 if (gl)
2939 if (gl->Name.size() > loc_idx && !gl->Name[loc_idx].empty())
2941 std::string name = gl->Name[loc_idx];
2943 if (Utf8FitTo(name, wnamepart))
2945 if (m_session)
2946 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, id, id, name.c_str());
2947 else
2948 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, id, name.c_str());
2949 ++counter;
2950 continue;
2956 std::string name = gInfo->name;
2957 if(name.empty())
2958 continue;
2960 if(Utf8FitTo(name, wnamepart))
2962 if (m_session)
2963 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, id, id, name.c_str());
2964 else
2965 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, id, name.c_str());
2966 ++counter;
2970 if(counter==0)
2971 SendSysMessage(LANG_COMMAND_NOGAMEOBJECTFOUND);
2973 return true;
2976 /** \brief GM command level 3 - Create a guild.
2978 * This command allows a GM (level 3) to create a guild.
2980 * The "args" parameter contains the name of the guild leader
2981 * and then the name of the guild.
2984 bool ChatHandler::HandleGuildCreateCommand(const char* args)
2987 if (!*args)
2988 return false;
2990 char *lname = strtok ((char*)args, " ");
2991 char *gname = strtok (NULL, "");
2993 if (!lname)
2994 return false;
2996 if (!gname)
2998 SendSysMessage (LANG_INSERT_GUILD_NAME);
2999 SetSentErrorMessage (true);
3000 return false;
3003 std::string guildname = gname;
3005 Player* player = ObjectAccessor::Instance ().FindPlayerByName (lname);
3006 if (!player)
3008 SendSysMessage (LANG_PLAYER_NOT_FOUND);
3009 SetSentErrorMessage (true);
3010 return false;
3013 if (player->GetGuildId())
3015 SendSysMessage (LANG_PLAYER_IN_GUILD);
3016 return true;
3019 Guild *guild = new Guild;
3020 if (!guild->create (player->GetGUID (),guildname))
3022 delete guild;
3023 SendSysMessage (LANG_GUILD_NOT_CREATED);
3024 SetSentErrorMessage (true);
3025 return false;
3028 objmgr.AddGuild (guild);
3029 return true;
3032 bool ChatHandler::HandleGuildInviteCommand(const char *args)
3034 if (!*args)
3035 return false;
3037 char* par1 = strtok ((char*)args, " ");
3038 char* par2 = strtok (NULL, "");
3039 if(!par1 || !par2)
3040 return false;
3042 std::string glName = par2;
3043 Guild* targetGuild = objmgr.GetGuildByName (glName);
3044 if (!targetGuild)
3045 return false;
3047 std::string plName = par1;
3048 if (!normalizePlayerName (plName))
3050 SendSysMessage (LANG_PLAYER_NOT_FOUND);
3051 SetSentErrorMessage (true);
3052 return false;
3055 uint64 plGuid = 0;
3056 if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3057 plGuid = targetPlayer->GetGUID ();
3058 else
3059 plGuid = objmgr.GetPlayerGUIDByName (plName.c_str ());
3061 if (!plGuid)
3062 false;
3064 // players's guild membership checked in AddMember before add
3065 if (!targetGuild->AddMember (plGuid,targetGuild->GetLowestRank ()))
3066 return false;
3068 return true;
3071 bool ChatHandler::HandleGuildUninviteCommand(const char *args)
3073 if (!*args)
3074 return false;
3076 char* par1 = strtok ((char*)args, " ");
3077 if(!par1)
3078 return false;
3080 std::string plName = par1;
3081 if (!normalizePlayerName (plName))
3083 SendSysMessage (LANG_PLAYER_NOT_FOUND);
3084 SetSentErrorMessage (true);
3085 return false;
3088 uint64 plGuid = 0;
3089 uint32 glId = 0;
3090 if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3092 plGuid = targetPlayer->GetGUID ();
3093 glId = targetPlayer->GetGuildId ();
3095 else
3097 plGuid = objmgr.GetPlayerGUIDByName (plName.c_str ());
3098 glId = Player::GetGuildIdFromDB (plGuid);
3101 if (!plGuid || !glId)
3102 return false;
3104 Guild* targetGuild = objmgr.GetGuildById (glId);
3105 if (!targetGuild)
3106 return false;
3108 targetGuild->DelMember (plGuid);
3110 return true;
3113 bool ChatHandler::HandleGuildRankCommand(const char *args)
3115 if (!*args)
3116 return false;
3118 char* par1 = strtok ((char*)args, " ");
3119 char* par2 = strtok (NULL, " ");
3120 if (!par1 || !par2)
3121 return false;
3122 std::string plName = par1;
3123 if (!normalizePlayerName (plName))
3125 SendSysMessage (LANG_PLAYER_NOT_FOUND);
3126 SetSentErrorMessage (true);
3127 return false;
3130 uint64 plGuid = 0;
3131 uint32 glId = 0;
3132 if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3134 plGuid = targetPlayer->GetGUID ();
3135 glId = targetPlayer->GetGuildId ();
3137 else
3139 plGuid = objmgr.GetPlayerGUIDByName (plName.c_str ());
3140 glId = Player::GetGuildIdFromDB (plGuid);
3143 if (!plGuid || !glId)
3144 return false;
3146 Guild* targetGuild = objmgr.GetGuildById (glId);
3147 if (!targetGuild)
3148 return false;
3150 uint32 newrank = uint32 (atoi (par2));
3151 if (newrank > targetGuild->GetLowestRank ())
3152 return false;
3154 targetGuild->ChangeRank (plGuid,newrank);
3156 return true;
3159 bool ChatHandler::HandleGuildDeleteCommand(const char* args)
3161 if (!*args)
3162 return false;
3164 char* par1 = strtok ((char*)args, " ");
3165 if (!par1)
3166 return false;
3168 std::string gld = par1;
3170 Guild* targetGuild = objmgr.GetGuildByName (gld);
3171 if (!targetGuild)
3172 return false;
3174 targetGuild->Disband ();
3176 return true;
3179 bool ChatHandler::HandleGetDistanceCommand(const char* /*args*/)
3181 Unit* pUnit = getSelectedUnit();
3183 if(!pUnit)
3185 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3186 SetSentErrorMessage(true);
3187 return false;
3190 PSendSysMessage(LANG_DISTANCE, m_session->GetPlayer()->GetDistance(pUnit),m_session->GetPlayer()->GetDistance2d(pUnit));
3192 return true;
3195 // FIX-ME!!!
3197 bool ChatHandler::HandleAddWeaponCommand(const char* /*args*/)
3199 /*if (!*args)
3200 return false;
3202 uint64 guid = m_session->GetPlayer()->GetSelection();
3203 if (guid == 0)
3205 SendSysMessage(LANG_NO_SELECTION);
3206 return true;
3209 Creature *pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
3211 if(!pCreature)
3213 SendSysMessage(LANG_SELECT_CREATURE);
3214 return true;
3217 char* pSlotID = strtok((char*)args, " ");
3218 if (!pSlotID)
3219 return false;
3221 char* pItemID = strtok(NULL, " ");
3222 if (!pItemID)
3223 return false;
3225 uint32 ItemID = atoi(pItemID);
3226 uint32 SlotID = atoi(pSlotID);
3228 ItemPrototype* tmpItem = objmgr.GetItemPrototype(ItemID);
3230 bool added = false;
3231 if(tmpItem)
3233 switch(SlotID)
3235 case 1:
3236 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID);
3237 added = true;
3238 break;
3239 case 2:
3240 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID);
3241 added = true;
3242 break;
3243 case 3:
3244 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID);
3245 added = true;
3246 break;
3247 default:
3248 PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST,SlotID);
3249 added = false;
3250 break;
3252 if(added)
3254 PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT,ItemID,tmpItem->Name1,SlotID);
3257 else
3259 PSendSysMessage(LANG_ITEM_NOT_FOUND,ItemID);
3260 return true;
3263 return true;
3266 bool ChatHandler::HandleDieCommand(const char* /*args*/)
3268 Unit* target = getSelectedUnit();
3270 if(!target || !m_session->GetPlayer()->GetSelection())
3272 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3273 SetSentErrorMessage(true);
3274 return false;
3277 if( target->isAlive() )
3279 m_session->GetPlayer()->DealDamage(target, target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
3282 return true;
3285 bool ChatHandler::HandleDamageCommand(const char * args)
3287 if (!*args)
3288 return false;
3290 Unit* target = getSelectedUnit();
3292 if(!target || !m_session->GetPlayer()->GetSelection())
3294 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3295 SetSentErrorMessage(true);
3296 return false;
3299 if( !target->isAlive() )
3300 return true;
3302 char* damageStr = strtok((char*)args, " ");
3303 if(!damageStr)
3304 return false;
3306 int32 damage = atoi((char*)damageStr);
3307 if(damage <=0)
3308 return true;
3310 char* schoolStr = strtok((char*)NULL, " ");
3312 // flat melee damage without resistence/etc reduction
3313 if(!schoolStr)
3315 m_session->GetPlayer()->DealDamage(target, damage, NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
3316 m_session->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2, target, 1, SPELL_SCHOOL_MASK_NORMAL, damage, 0, 0, VICTIMSTATE_NORMAL, 0);
3317 return true;
3320 uint32 school = schoolStr ? atoi((char*)schoolStr) : SPELL_SCHOOL_NORMAL;
3321 if(school >= MAX_SPELL_SCHOOL)
3322 return false;
3324 SpellSchoolMask schoolmask = SpellSchoolMask(1 << school);
3326 if ( schoolmask & SPELL_SCHOOL_MASK_NORMAL )
3327 damage = m_session->GetPlayer()->CalcArmorReducedDamage(target, damage);
3329 char* spellStr = strtok((char*)NULL, " ");
3331 // melee damage by specific school
3332 if(!spellStr)
3334 uint32 absorb = 0;
3335 uint32 resist = 0;
3337 m_session->GetPlayer()->CalcAbsorbResist(target,schoolmask, SPELL_DIRECT_DAMAGE, damage, &absorb, &resist);
3339 if (damage <= absorb + resist)
3340 return true;
3342 damage -= absorb + resist;
3344 m_session->GetPlayer()->DealDamage(target, damage, NULL, DIRECT_DAMAGE, schoolmask, NULL, false);
3345 m_session->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2, target, 1, schoolmask, damage, absorb, resist, VICTIMSTATE_NORMAL, 0);
3346 return true;
3349 // non-melee damage
3351 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3352 uint32 spellid = extractSpellIdFromLink((char*)args);
3353 if(!spellid || !sSpellStore.LookupEntry(spellid))
3354 return false;
3356 m_session->GetPlayer()->SpellNonMeleeDamageLog(target, spellid, damage, false);
3357 return true;
3360 bool ChatHandler::HandleModifyArenaCommand(const char * args)
3362 if (!*args)
3363 return false;
3365 Player *target = getSelectedPlayer();
3366 if(!target)
3368 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3369 SetSentErrorMessage(true);
3370 return false;
3373 int32 amount = (uint32)atoi(args);
3375 target->ModifyArenaPoints(amount);
3377 PSendSysMessage(LANG_COMMAND_MODIFY_ARENA, target->GetName(), target->GetArenaPoints());
3379 return true;
3382 bool ChatHandler::HandleReviveCommand(const char* args)
3384 Player* SelectedPlayer = NULL;
3386 if (*args)
3388 std::string name = args;
3389 if(!normalizePlayerName(name))
3391 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3392 SetSentErrorMessage(true);
3393 return false;
3396 SelectedPlayer = objmgr.GetPlayer(name.c_str());
3398 else
3399 SelectedPlayer = getSelectedPlayer();
3401 if(!SelectedPlayer)
3403 SendSysMessage(LANG_NO_CHAR_SELECTED);
3404 SetSentErrorMessage(true);
3405 return false;
3408 SelectedPlayer->ResurrectPlayer(0.5f);
3409 SelectedPlayer->SpawnCorpseBones();
3410 SelectedPlayer->SaveToDB();
3411 return true;
3414 bool ChatHandler::HandleAuraCommand(const char* args)
3416 char* px = strtok((char*)args, " ");
3417 if (!px)
3418 return false;
3420 Unit *target = getSelectedUnit();
3421 if(!target)
3423 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3424 SetSentErrorMessage(true);
3425 return false;
3428 uint32 spellID = (uint32)atoi(px);
3429 SpellEntry const *spellInfo = sSpellStore.LookupEntry( spellID );
3430 if(spellInfo)
3432 for(uint32 i = 0;i<3;i++)
3434 uint8 eff = spellInfo->Effect[i];
3435 if (eff>=TOTAL_SPELL_EFFECTS)
3436 continue;
3437 if( IsAreaAuraEffect(eff) ||
3438 eff == SPELL_EFFECT_APPLY_AURA ||
3439 eff == SPELL_EFFECT_PERSISTENT_AREA_AURA )
3441 Aura *Aur = CreateAura(spellInfo, i, NULL, target);
3442 target->AddAura(Aur);
3447 return true;
3450 bool ChatHandler::HandleUnAuraCommand(const char* args)
3452 char* px = strtok((char*)args, " ");
3453 if (!px)
3454 return false;
3456 Unit *target = getSelectedUnit();
3457 if(!target)
3459 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3460 SetSentErrorMessage(true);
3461 return false;
3464 std::string argstr = args;
3465 if (argstr == "all")
3467 target->RemoveAllAuras();
3468 return true;
3471 uint32 spellID = (uint32)atoi(px);
3472 target->RemoveAurasDueToSpell(spellID);
3474 return true;
3477 bool ChatHandler::HandleLinkGraveCommand(const char* args)
3479 if(!*args)
3480 return false;
3482 char* px = strtok((char*)args, " ");
3483 if (!px)
3484 return false;
3486 uint32 g_id = (uint32)atoi(px);
3488 uint32 g_team;
3490 char* px2 = strtok(NULL, " ");
3492 if (!px2)
3493 g_team = 0;
3494 else if (strncmp(px2,"horde",6)==0)
3495 g_team = HORDE;
3496 else if (strncmp(px2,"alliance",9)==0)
3497 g_team = ALLIANCE;
3498 else
3499 return false;
3501 WorldSafeLocsEntry const* graveyard = sWorldSafeLocsStore.LookupEntry(g_id);
3503 if(!graveyard )
3505 PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST, g_id);
3506 SetSentErrorMessage(true);
3507 return false;
3510 Player* player = m_session->GetPlayer();
3512 uint32 zoneId = player->GetZoneId();
3514 AreaTableEntry const *areaEntry = GetAreaEntryByAreaID(zoneId);
3515 if(!areaEntry || areaEntry->zone !=0 )
3517 PSendSysMessage(LANG_COMMAND_GRAVEYARDWRONGZONE, g_id,zoneId);
3518 SetSentErrorMessage(true);
3519 return false;
3522 if(graveyard->map_id != areaEntry->mapid && g_team != 0)
3524 SendSysMessage(LANG_COMMAND_GRAVEYARDWRONGTEAM);
3525 SetSentErrorMessage(true);
3526 return false;
3529 if(objmgr.AddGraveYardLink(g_id,player->GetZoneId(),g_team))
3530 PSendSysMessage(LANG_COMMAND_GRAVEYARDLINKED, g_id,zoneId);
3531 else
3532 PSendSysMessage(LANG_COMMAND_GRAVEYARDALRLINKED, g_id,zoneId);
3534 return true;
3537 bool ChatHandler::HandleNearGraveCommand(const char* args)
3539 uint32 g_team;
3541 size_t argslen = strlen(args);
3543 if(!*args)
3544 g_team = 0;
3545 else if (strncmp((char*)args,"horde",argslen)==0)
3546 g_team = HORDE;
3547 else if (strncmp((char*)args,"alliance",argslen)==0)
3548 g_team = ALLIANCE;
3549 else
3550 return false;
3552 Player* player = m_session->GetPlayer();
3554 WorldSafeLocsEntry const* graveyard = objmgr.GetClosestGraveYard(
3555 player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(),player->GetMapId(),g_team);
3557 if(graveyard)
3559 uint32 g_id = graveyard->ID;
3561 GraveYardData const* data = objmgr.FindGraveYardData(g_id,player->GetZoneId());
3562 if (!data)
3564 PSendSysMessage(LANG_COMMAND_GRAVEYARDERROR,g_id);
3565 SetSentErrorMessage(true);
3566 return false;
3569 g_team = data->team;
3571 std::string team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_NOTEAM);
3573 if(g_team == 0)
3574 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ANY);
3575 else if(g_team == HORDE)
3576 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE);
3577 else if(g_team == ALLIANCE)
3578 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE);
3580 PSendSysMessage(LANG_COMMAND_GRAVEYARDNEAREST, g_id,team_name.c_str(),player->GetZoneId());
3582 else
3584 std::string team_name;
3586 if(g_team == 0)
3587 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ANY);
3588 else if(g_team == HORDE)
3589 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE);
3590 else if(g_team == ALLIANCE)
3591 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE);
3593 if(g_team == ~uint32(0))
3594 PSendSysMessage(LANG_COMMAND_ZONENOGRAVEYARDS, player->GetZoneId());
3595 else
3596 PSendSysMessage(LANG_COMMAND_ZONENOGRAFACTION, player->GetZoneId(),team_name.c_str());
3599 return true;
3602 //play npc emote
3603 bool ChatHandler::HandleNpcPlayEmoteCommand(const char* args)
3605 uint32 emote = atoi((char*)args);
3607 Creature* target = getSelectedCreature();
3608 if(!target)
3610 SendSysMessage(LANG_SELECT_CREATURE);
3611 SetSentErrorMessage(true);
3612 return false;
3615 target->SetUInt32Value(UNIT_NPC_EMOTESTATE,emote);
3617 return true;
3620 bool ChatHandler::HandleNpcInfoCommand(const char* /*args*/)
3622 Creature* target = getSelectedCreature();
3624 if(!target)
3626 SendSysMessage(LANG_SELECT_CREATURE);
3627 SetSentErrorMessage(true);
3628 return false;
3631 uint32 faction = target->getFaction();
3632 uint32 npcflags = target->GetUInt32Value(UNIT_NPC_FLAGS);
3633 uint32 displayid = target->GetDisplayId();
3634 uint32 nativeid = target->GetNativeDisplayId();
3635 uint32 Entry = target->GetEntry();
3636 CreatureInfo const* cInfo = target->GetCreatureInfo();
3638 int32 curRespawnDelay = target->GetRespawnTimeEx()-time(NULL);
3639 if(curRespawnDelay < 0)
3640 curRespawnDelay = 0;
3641 std::string curRespawnDelayStr = secsToTimeString(curRespawnDelay,true);
3642 std::string defRespawnDelayStr = secsToTimeString(target->GetRespawnDelay(),true);
3644 PSendSysMessage(LANG_NPCINFO_CHAR, target->GetDBTableGUIDLow(), faction, npcflags, Entry, displayid, nativeid);
3645 PSendSysMessage(LANG_NPCINFO_LEVEL, target->getLevel());
3646 PSendSysMessage(LANG_NPCINFO_HEALTH,target->GetCreateHealth(), target->GetMaxHealth(), target->GetHealth());
3647 PSendSysMessage(LANG_NPCINFO_FLAGS, target->GetUInt32Value(UNIT_FIELD_FLAGS), target->GetUInt32Value(UNIT_DYNAMIC_FLAGS), target->getFaction());
3648 PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES, defRespawnDelayStr.c_str(),curRespawnDelayStr.c_str());
3649 PSendSysMessage(LANG_NPCINFO_LOOT, cInfo->lootid,cInfo->pickpocketLootId,cInfo->SkinLootId);
3650 PSendSysMessage(LANG_NPCINFO_DUNGEON_ID, target->GetInstanceId());
3651 PSendSysMessage(LANG_NPCINFO_POSITION,float(target->GetPositionX()), float(target->GetPositionY()), float(target->GetPositionZ()));
3653 if ((npcflags & UNIT_NPC_FLAG_VENDOR) )
3655 SendSysMessage(LANG_NPCINFO_VENDOR);
3657 if ((npcflags & UNIT_NPC_FLAG_TRAINER) )
3659 SendSysMessage(LANG_NPCINFO_TRAINER);
3662 return true;
3665 bool ChatHandler::HandleExploreCheatCommand(const char* args)
3667 if (!*args)
3668 return false;
3670 int flag = atoi((char*)args);
3672 Player *chr = getSelectedPlayer();
3673 if (chr == NULL)
3675 SendSysMessage(LANG_NO_CHAR_SELECTED);
3676 SetSentErrorMessage(true);
3677 return false;
3680 if (flag != 0)
3682 PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL, chr->GetName());
3683 if (needReportToTarget(chr))
3684 ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_ALL,GetName());
3686 else
3688 PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING, chr->GetName());
3689 if (needReportToTarget(chr))
3690 ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_NOTHING,GetName());
3693 for (uint8 i=0; i<128; i++)
3695 if (flag != 0)
3697 m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1+i,0xFFFFFFFF);
3699 else
3701 m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1+i,0);
3705 return true;
3708 bool ChatHandler::HandleHoverCommand(const char* args)
3710 char* px = strtok((char*)args, " ");
3711 uint32 flag;
3712 if (!px)
3713 flag = 1;
3714 else
3715 flag = atoi(px);
3717 m_session->GetPlayer()->SetHover(flag);
3719 if (flag)
3720 SendSysMessage(LANG_HOVER_ENABLED);
3721 else
3722 SendSysMessage(LANG_HOVER_DISABLED);
3724 return true;
3727 bool ChatHandler::HandleLevelUpCommand(const char* args)
3729 char* px = strtok((char*)args, " ");
3730 char* py = strtok((char*)NULL, " ");
3732 // command format parsing
3733 char* pname = (char*)NULL;
3734 int addlevel = 1;
3736 if(px && py) // .levelup name level
3738 addlevel = atoi(py);
3739 pname = px;
3741 else if(px && !py) // .levelup name OR .levelup level
3743 if(isalpha(px[0])) // .levelup name
3744 pname = px;
3745 else // .levelup level
3746 addlevel = atoi(px);
3748 // else .levelup - nothing do for prepering
3750 // player
3751 Player *chr = NULL;
3752 uint64 chr_guid = 0;
3754 std::string name;
3756 if(pname) // player by name
3758 name = pname;
3759 if(!normalizePlayerName(name))
3761 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3762 SetSentErrorMessage(true);
3763 return false;
3766 chr = objmgr.GetPlayer(name.c_str());
3767 if(!chr) // not in game
3769 chr_guid = objmgr.GetPlayerGUIDByName(name);
3770 if (chr_guid == 0)
3772 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3773 SetSentErrorMessage(true);
3774 return false;
3778 else // player by selection
3780 chr = getSelectedPlayer();
3782 if (chr == NULL)
3784 SendSysMessage(LANG_NO_CHAR_SELECTED);
3785 SetSentErrorMessage(true);
3786 return false;
3789 name = chr->GetName();
3792 assert(chr || chr_guid);
3794 int32 oldlevel = chr ? chr->getLevel() : Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL,chr_guid);
3795 int32 newlevel = oldlevel + addlevel;
3796 if(newlevel < 1)
3797 newlevel = 1;
3798 if(newlevel > 255) // hardcoded maximum level
3799 newlevel = 255;
3801 if(chr)
3803 chr->GiveLevel(newlevel);
3804 chr->InitTalentForLevel();
3805 chr->SetUInt32Value(PLAYER_XP,0);
3807 if(oldlevel == newlevel)
3808 ChatHandler(chr).SendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET);
3809 else
3810 if(oldlevel < newlevel)
3811 ChatHandler(chr).PSendSysMessage(LANG_YOURS_LEVEL_UP,newlevel-oldlevel);
3812 else
3813 if(oldlevel > newlevel)
3814 ChatHandler(chr).PSendSysMessage(LANG_YOURS_LEVEL_DOWN,newlevel-oldlevel);
3816 else
3818 // update levle and XP at level, all other will be updated at loading
3819 Tokens values;
3820 Player::LoadValuesArrayFromDB(values,chr_guid);
3821 Player::SetUInt32ValueInArray(values,UNIT_FIELD_LEVEL,newlevel);
3822 Player::SetUInt32ValueInArray(values,PLAYER_XP,0);
3823 Player::SaveValuesArrayInDB(values,chr_guid);
3826 if(m_session->GetPlayer() != chr) // including chr==NULL
3827 PSendSysMessage(LANG_YOU_CHANGE_LVL,name.c_str(),newlevel);
3828 return true;
3831 bool ChatHandler::HandleShowAreaCommand(const char* args)
3833 if (!*args)
3834 return false;
3836 int area = atoi((char*)args);
3838 Player *chr = getSelectedPlayer();
3839 if (chr == NULL)
3841 SendSysMessage(LANG_NO_CHAR_SELECTED);
3842 SetSentErrorMessage(true);
3843 return false;
3846 int offset = area / 32;
3847 uint32 val = (uint32)(1 << (area % 32));
3849 if(offset >= 128)
3851 SendSysMessage(LANG_BAD_VALUE);
3852 SetSentErrorMessage(true);
3853 return false;
3856 uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
3857 chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields | val));
3859 SendSysMessage(LANG_EXPLORE_AREA);
3860 return true;
3863 bool ChatHandler::HandleHideAreaCommand(const char* args)
3865 if (!*args)
3866 return false;
3868 int area = atoi((char*)args);
3870 Player *chr = getSelectedPlayer();
3871 if (chr == NULL)
3873 SendSysMessage(LANG_NO_CHAR_SELECTED);
3874 SetSentErrorMessage(true);
3875 return false;
3878 int offset = area / 32;
3879 uint32 val = (uint32)(1 << (area % 32));
3881 if(offset >= 128)
3883 SendSysMessage(LANG_BAD_VALUE);
3884 SetSentErrorMessage(true);
3885 return false;
3888 uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
3889 chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields ^ val));
3891 SendSysMessage(LANG_UNEXPLORE_AREA);
3892 return true;
3895 bool ChatHandler::HandleUpdate(const char* args)
3897 if(!*args)
3898 return false;
3900 uint32 updateIndex;
3901 uint32 value;
3903 char* pUpdateIndex = strtok((char*)args, " ");
3905 Unit* chr = getSelectedUnit();
3906 if (chr == NULL)
3908 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3909 SetSentErrorMessage(true);
3910 return false;
3913 if(!pUpdateIndex)
3915 return true;
3917 updateIndex = atoi(pUpdateIndex);
3918 //check updateIndex
3919 if(chr->GetTypeId() == TYPEID_PLAYER)
3921 if (updateIndex>=PLAYER_END) return true;
3923 else
3925 if (updateIndex>=UNIT_END) return true;
3928 char* pvalue = strtok(NULL, " ");
3929 if (!pvalue)
3931 value=chr->GetUInt32Value(updateIndex);
3933 PSendSysMessage(LANG_UPDATE, chr->GetGUIDLow(),updateIndex,value);
3934 return true;
3937 value=atoi(pvalue);
3939 PSendSysMessage(LANG_UPDATE_CHANGE, chr->GetGUIDLow(),updateIndex,value);
3941 chr->SetUInt32Value(updateIndex,value);
3943 return true;
3946 bool ChatHandler::HandleBankCommand(const char* /*args*/)
3948 m_session->SendShowBank( m_session->GetPlayer()->GetGUID() );
3950 return true;
3953 bool ChatHandler::HandleChangeWeather(const char* args)
3955 if(!*args)
3956 return false;
3958 //Weather is OFF
3959 if (!sWorld.getConfig(CONFIG_WEATHER))
3961 SendSysMessage(LANG_WEATHER_DISABLED);
3962 SetSentErrorMessage(true);
3963 return false;
3966 //*Change the weather of a cell
3967 char* px = strtok((char*)args, " ");
3968 char* py = strtok(NULL, " ");
3970 if (!px || !py)
3971 return false;
3973 uint32 type = (uint32)atoi(px); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
3974 float grade = (float)atof(py); //0 to 1, sending -1 is instand good weather
3976 Player *player = m_session->GetPlayer();
3977 uint32 zoneid = player->GetZoneId();
3979 Weather* wth = sWorld.FindWeather(zoneid);
3981 if(!wth)
3982 wth = sWorld.AddWeather(zoneid);
3983 if(!wth)
3985 SendSysMessage(LANG_NO_WEATHER);
3986 SetSentErrorMessage(true);
3987 return false;
3990 wth->SetWeather(WeatherType(type), grade);
3992 return true;
3995 bool ChatHandler::HandleSetValue(const char* args)
3997 if(!*args)
3998 return false;
4000 char* px = strtok((char*)args, " ");
4001 char* py = strtok(NULL, " ");
4002 char* pz = strtok(NULL, " ");
4004 if (!px || !py)
4005 return false;
4007 Unit* target = getSelectedUnit();
4008 if(!target)
4010 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4011 SetSentErrorMessage(true);
4012 return false;
4015 uint64 guid = target->GetGUID();
4017 uint32 Opcode = (uint32)atoi(px);
4018 if(Opcode >= target->GetValuesCount())
4020 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, GUID_LOPART(guid), target->GetValuesCount());
4021 return false;
4023 uint32 iValue;
4024 float fValue;
4025 bool isint32 = true;
4026 if(pz)
4027 isint32 = (bool)atoi(pz);
4028 if(isint32)
4030 iValue = (uint32)atoi(py);
4031 sLog.outDebug(GetMangosString(LANG_SET_UINT), GUID_LOPART(guid), Opcode, iValue);
4032 target->SetUInt32Value( Opcode , iValue );
4033 PSendSysMessage(LANG_SET_UINT_FIELD, GUID_LOPART(guid), Opcode,iValue);
4035 else
4037 fValue = (float)atof(py);
4038 sLog.outDebug(GetMangosString(LANG_SET_FLOAT), GUID_LOPART(guid), Opcode, fValue);
4039 target->SetFloatValue( Opcode , fValue );
4040 PSendSysMessage(LANG_SET_FLOAT_FIELD, GUID_LOPART(guid), Opcode,fValue);
4043 return true;
4046 bool ChatHandler::HandleGetValue(const char* args)
4048 if(!*args)
4049 return false;
4051 char* px = strtok((char*)args, " ");
4052 char* pz = strtok(NULL, " ");
4054 if (!px)
4055 return false;
4057 Unit* target = getSelectedUnit();
4058 if(!target)
4060 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4061 SetSentErrorMessage(true);
4062 return false;
4065 uint64 guid = target->GetGUID();
4067 uint32 Opcode = (uint32)atoi(px);
4068 if(Opcode >= target->GetValuesCount())
4070 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, GUID_LOPART(guid), target->GetValuesCount());
4071 return false;
4073 uint32 iValue;
4074 float fValue;
4075 bool isint32 = true;
4076 if(pz)
4077 isint32 = (bool)atoi(pz);
4079 if(isint32)
4081 iValue = target->GetUInt32Value( Opcode );
4082 sLog.outDebug(GetMangosString(LANG_GET_UINT), GUID_LOPART(guid), Opcode, iValue);
4083 PSendSysMessage(LANG_GET_UINT_FIELD, GUID_LOPART(guid), Opcode, iValue);
4085 else
4087 fValue = target->GetFloatValue( Opcode );
4088 sLog.outDebug(GetMangosString(LANG_GET_FLOAT), GUID_LOPART(guid), Opcode, fValue);
4089 PSendSysMessage(LANG_GET_FLOAT_FIELD, GUID_LOPART(guid), Opcode, fValue);
4092 return true;
4095 bool ChatHandler::HandleSet32Bit(const char* args)
4097 if(!*args)
4098 return false;
4100 char* px = strtok((char*)args, " ");
4101 char* py = strtok(NULL, " ");
4103 if (!px || !py)
4104 return false;
4106 uint32 Opcode = (uint32)atoi(px);
4107 uint32 Value = (uint32)atoi(py);
4108 if (Value > 32) //uint32 = 32 bits
4109 return false;
4111 sLog.outDebug(GetMangosString(LANG_SET_32BIT), Opcode, Value);
4113 m_session->GetPlayer( )->SetUInt32Value( Opcode , 2^Value );
4115 PSendSysMessage(LANG_SET_32BIT_FIELD, Opcode,1);
4116 return true;
4119 bool ChatHandler::HandleMod32Value(const char* args)
4121 if(!*args)
4122 return false;
4124 char* px = strtok((char*)args, " ");
4125 char* py = strtok(NULL, " ");
4127 if (!px || !py)
4128 return false;
4130 uint32 Opcode = (uint32)atoi(px);
4131 int Value = atoi(py);
4133 if(Opcode >= m_session->GetPlayer()->GetValuesCount())
4135 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, m_session->GetPlayer()->GetGUIDLow(), m_session->GetPlayer( )->GetValuesCount());
4136 return false;
4139 sLog.outDebug(GetMangosString(LANG_CHANGE_32BIT), Opcode, Value);
4141 int CurrentValue = (int)m_session->GetPlayer( )->GetUInt32Value( Opcode );
4143 CurrentValue += Value;
4144 m_session->GetPlayer( )->SetUInt32Value( Opcode , (uint32)CurrentValue );
4146 PSendSysMessage(LANG_CHANGE_32BIT_FIELD, Opcode,CurrentValue);
4148 return true;
4151 bool ChatHandler::HandleAddTeleCommand(const char * args)
4153 if(!*args)
4154 return false;
4156 Player *player=m_session->GetPlayer();
4157 if (!player)
4158 return false;
4160 std::string name = args;
4162 if(objmgr.GetGameTele(name))
4164 SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST);
4165 SetSentErrorMessage(true);
4166 return false;
4169 GameTele tele;
4170 tele.position_x = player->GetPositionX();
4171 tele.position_y = player->GetPositionY();
4172 tele.position_z = player->GetPositionZ();
4173 tele.orientation = player->GetOrientation();
4174 tele.mapId = player->GetMapId();
4175 tele.name = name;
4177 if(objmgr.AddGameTele(tele))
4179 SendSysMessage(LANG_COMMAND_TP_ADDED);
4181 else
4183 SendSysMessage(LANG_COMMAND_TP_ADDEDERR);
4184 SetSentErrorMessage(true);
4185 return false;
4188 return true;
4191 bool ChatHandler::HandleDelTeleCommand(const char * args)
4193 if(!*args)
4194 return false;
4196 std::string name = args;
4198 if(!objmgr.DeleteGameTele(name))
4200 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
4201 SetSentErrorMessage(true);
4202 return false;
4205 SendSysMessage(LANG_COMMAND_TP_DELETED);
4206 return true;
4209 bool ChatHandler::HandleListAurasCommand (const char * /*args*/)
4211 Unit *unit = getSelectedUnit();
4212 if(!unit)
4214 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4215 SetSentErrorMessage(true);
4216 return false;
4219 char const* talentStr = GetMangosString(LANG_TALENT);
4220 char const* passiveStr = GetMangosString(LANG_PASSIVE);
4222 Unit::AuraMap const& uAuras = unit->GetAuras();
4223 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS, uAuras.size());
4224 for (Unit::AuraMap::const_iterator itr = uAuras.begin(); itr != uAuras.end(); ++itr)
4226 bool talent = GetTalentSpellCost(itr->second->GetId()) > 0;
4227 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL, itr->second->GetId(), itr->second->GetEffIndex(),
4228 itr->second->GetModifier()->m_auraname, itr->second->GetAuraDuration(), itr->second->GetAuraMaxDuration(),
4229 itr->second->GetSpellProto()->SpellName[m_session->GetSessionDbcLocale()],
4230 (itr->second->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4231 IS_PLAYER_GUID(itr->second->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr->second->GetCasterGUID()));
4233 for (int i = 0; i < TOTAL_AURAS; i++)
4235 Unit::AuraList const& uAuraList = unit->GetAurasByType(AuraType(i));
4236 if (uAuraList.empty()) continue;
4237 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE, uAuraList.size(), i);
4238 for (Unit::AuraList::const_iterator itr = uAuraList.begin(); itr != uAuraList.end(); ++itr)
4240 bool talent = GetTalentSpellCost((*itr)->GetId()) > 0;
4241 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE, (*itr)->GetId(), (*itr)->GetEffIndex(),
4242 (*itr)->GetSpellProto()->SpellName[m_session->GetSessionDbcLocale()],((*itr)->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4243 IS_PLAYER_GUID((*itr)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr)->GetCasterGUID()));
4246 return true;
4249 bool ChatHandler::HandleResetHonorCommand (const char * args)
4251 char* pName = strtok((char*)args, "");
4252 Player *player = NULL;
4253 if (pName)
4255 std::string name = pName;
4256 if(!normalizePlayerName(name))
4258 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4259 SetSentErrorMessage(true);
4260 return false;
4263 uint64 guid = objmgr.GetPlayerGUIDByName(name.c_str());
4264 player = objmgr.GetPlayer(guid);
4266 else
4267 player = getSelectedPlayer();
4269 if(!player)
4271 SendSysMessage(LANG_NO_CHAR_SELECTED);
4272 return true;
4275 player->SetUInt32Value(PLAYER_FIELD_KILLS, 0);
4276 player->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS, 0);
4277 player->SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY, 0);
4278 player->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION, 0);
4279 player->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION, 0);
4281 return true;
4284 static bool HandleResetStatsOrLevelHelper(Player* player)
4286 PlayerInfo const *info = objmgr.GetPlayerInfo(player->getRace(), player->getClass());
4287 if(!info) return false;
4289 ChrClassesEntry const* cEntry = sChrClassesStore.LookupEntry(player->getClass());
4290 if(!cEntry)
4292 sLog.outError("Class %u not found in DBC (Wrong DBC files?)",player->getClass());
4293 return false;
4296 uint8 powertype = cEntry->powerType;
4298 uint32 unitfield;
4299 if(powertype == POWER_RAGE)
4300 unitfield = 0x1100EE00;
4301 else if(powertype == POWER_ENERGY)
4302 unitfield = 0x00000000;
4303 else if(powertype == POWER_MANA)
4304 unitfield = 0x0000EE00;
4305 else
4307 sLog.outError("Invalid default powertype %u for player (class %u)",powertype,player->getClass());
4308 return false;
4311 // reset m_form if no aura
4312 if(!player->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT))
4313 player->m_form = FORM_NONE;
4315 player->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, DEFAULT_WORLD_OBJECT_SIZE );
4316 player->SetFloatValue(UNIT_FIELD_COMBATREACH, 1.5f );
4318 player->setFactionForRace(player->getRace());
4320 player->SetUInt32Value(UNIT_FIELD_BYTES_0, ( ( player->getRace() ) | ( player->getClass() << 8 ) | ( player->getGender() << 16 ) | ( powertype << 24 ) ) );
4322 // reset only if player not in some form;
4323 if(player->m_form==FORM_NONE)
4325 switch(player->getGender())
4327 case GENDER_FEMALE:
4328 player->SetDisplayId(info->displayId_f);
4329 player->SetNativeDisplayId(info->displayId_f);
4330 break;
4331 case GENDER_MALE:
4332 player->SetDisplayId(info->displayId_m);
4333 player->SetNativeDisplayId(info->displayId_m);
4334 break;
4335 default:
4336 break;
4340 // set UNIT_FIELD_BYTES_1 to init state but preserve m_form value
4341 player->SetUInt32Value(UNIT_FIELD_BYTES_1, unitfield);
4342 player->SetByteValue(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_UNK3 | UNIT_BYTE2_FLAG_UNK5 );
4343 player->SetByteValue(UNIT_FIELD_BYTES_2, 3, player->m_form);
4345 player->SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
4347 //-1 is default value
4348 player->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX, uint32(-1));
4350 //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000 );
4351 return true;
4354 bool ChatHandler::HandleResetLevelCommand(const char * args)
4356 char* pName = strtok((char*)args, "");
4357 Player *player = NULL;
4358 if (pName)
4360 std::string name = pName;
4361 if(!normalizePlayerName(name))
4363 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4364 SetSentErrorMessage(true);
4365 return false;
4368 uint64 guid = objmgr.GetPlayerGUIDByName(name.c_str());
4369 player = objmgr.GetPlayer(guid);
4371 else
4372 player = getSelectedPlayer();
4374 if(!player)
4376 SendSysMessage(LANG_NO_CHAR_SELECTED);
4377 SetSentErrorMessage(true);
4378 return false;
4381 if(!HandleResetStatsOrLevelHelper(player))
4382 return false;
4384 player->SetLevel(1);
4385 player->InitStatsForLevel(true);
4386 player->InitTaxiNodesForLevel();
4387 player->InitTalentForLevel();
4388 player->SetUInt32Value(PLAYER_XP,0);
4390 // reset level to summoned pet
4391 Pet* pet = player->GetPet();
4392 if(pet && pet->getPetType()==SUMMON_PET)
4393 pet->InitStatsForLevel(1);
4395 return true;
4398 bool ChatHandler::HandleResetStatsCommand(const char * args)
4400 char* pName = strtok((char*)args, "");
4401 Player *player = NULL;
4402 if (pName)
4404 std::string name = pName;
4405 if(!normalizePlayerName(name))
4407 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4408 SetSentErrorMessage(true);
4409 return false;
4412 uint64 guid = objmgr.GetPlayerGUIDByName(name.c_str());
4413 player = objmgr.GetPlayer(guid);
4415 else
4416 player = getSelectedPlayer();
4418 if(!player)
4420 SendSysMessage(LANG_NO_CHAR_SELECTED);
4421 SetSentErrorMessage(true);
4422 return false;
4425 if(!HandleResetStatsOrLevelHelper(player))
4426 return false;
4428 player->InitStatsForLevel(true);
4429 player->InitTaxiNodesForLevel();
4430 player->InitTalentForLevel();
4432 return true;
4435 bool ChatHandler::HandleResetSpellsCommand(const char * args)
4437 char* pName = strtok((char*)args, "");
4438 Player *player = NULL;
4439 uint64 playerGUID = 0;
4440 if (pName)
4442 std::string name = pName;
4444 if(!normalizePlayerName(name))
4446 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4447 SetSentErrorMessage(true);
4448 return false;
4451 player = objmgr.GetPlayer(name.c_str());
4452 if(!player)
4453 playerGUID = objmgr.GetPlayerGUIDByName(name.c_str());
4455 else
4456 player = getSelectedPlayer();
4458 if(!player && !playerGUID)
4460 SendSysMessage(LANG_NO_CHAR_SELECTED);
4461 SetSentErrorMessage(true);
4462 return false;
4465 if(player)
4467 player->resetSpells();
4469 ChatHandler(player).SendSysMessage(LANG_RESET_SPELLS);
4471 if(m_session->GetPlayer()!=player)
4472 PSendSysMessage(LANG_RESET_SPELLS_ONLINE,player->GetName());
4474 else
4476 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS), GUID_LOPART(playerGUID));
4477 PSendSysMessage(LANG_RESET_SPELLS_OFFLINE,pName);
4480 return true;
4483 bool ChatHandler::HandleResetTalentsCommand(const char * args)
4485 char* pName = strtok((char*)args, "");
4486 Player *player = NULL;
4487 uint64 playerGUID = 0;
4488 if (pName)
4490 std::string name = pName;
4491 if(!normalizePlayerName(name))
4493 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4494 SetSentErrorMessage(true);
4495 return false;
4498 player = objmgr.GetPlayer(name.c_str());
4499 if(!player)
4500 playerGUID = objmgr.GetPlayerGUIDByName(name.c_str());
4502 else
4503 player = getSelectedPlayer();
4505 if(!player && !playerGUID)
4507 SendSysMessage(LANG_NO_CHAR_SELECTED);
4508 SetSentErrorMessage(true);
4509 return false;
4512 if(player)
4514 player->resetTalents(true);
4516 ChatHandler(player).SendSysMessage(LANG_RESET_TALENTS);
4518 if(m_session->GetPlayer()!=player)
4519 PSendSysMessage(LANG_RESET_TALENTS_ONLINE,player->GetName());
4521 else
4523 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_TALENTS), GUID_LOPART(playerGUID) );
4524 PSendSysMessage(LANG_RESET_TALENTS_OFFLINE,pName);
4527 return true;
4530 bool ChatHandler::HandleResetAllCommand(const char * args)
4532 if(!*args)
4533 return false;
4535 std::string casename = args;
4537 AtLoginFlags atLogin;
4539 // Command specially created as single command to prevent using short case names
4540 if(casename=="spells")
4542 atLogin = AT_LOGIN_RESET_SPELLS;
4543 sWorld.SendWorldText(LANG_RESETALL_SPELLS);
4545 else if(casename=="talents")
4547 atLogin = AT_LOGIN_RESET_TALENTS;
4548 sWorld.SendWorldText(LANG_RESETALL_TALENTS);
4550 else
4552 PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE,args);
4553 SetSentErrorMessage(true);
4554 return false;
4557 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u'",atLogin);
4558 HashMapHolder<Player>::MapType const& plist = ObjectAccessor::Instance().GetPlayers();
4559 for(HashMapHolder<Player>::MapType::const_iterator itr = plist.begin(); itr != plist.end(); ++itr)
4560 itr->second->SetAtLoginFlag(atLogin);
4562 return true;
4565 bool ChatHandler::HandleShutDownCommand(const char* args)
4567 if(!*args)
4568 return false;
4570 if(std::string(args)=="cancel")
4572 sWorld.ShutdownCancel();
4574 else
4576 int32 time = atoi(args);
4578 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4579 if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
4580 return false;
4582 sWorld.ShutdownServ(time);
4584 return true;
4587 bool ChatHandler::HandleRestartCommand(const char* args)
4589 if(!*args)
4590 return false;
4592 if(std::string(args)=="cancel")
4594 sWorld.ShutdownCancel();
4596 else
4598 int32 time = atoi(args);
4600 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4601 if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
4602 return false;
4604 sWorld.ShutdownServ(time, SHUTDOWN_MASK_RESTART);
4606 return true;
4609 bool ChatHandler::HandleIdleRestartCommand(const char* args)
4611 if(!*args)
4612 return false;
4614 if(std::string(args)=="cancel")
4616 sWorld.ShutdownCancel();
4618 else
4620 int32 time = atoi(args);
4622 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4623 if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
4624 return false;
4626 sWorld.ShutdownServ(time,SHUTDOWN_MASK_RESTART+SHUTDOWN_MASK_IDLE);
4628 return true;
4631 bool ChatHandler::HandleIdleShutDownCommand(const char* args)
4633 if(!*args)
4634 return false;
4636 if(std::string(args)=="cancel")
4638 sWorld.ShutdownCancel();
4640 else
4642 int32 time = atoi(args);
4644 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4645 if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
4646 return false;
4648 sWorld.ShutdownServ(time,SHUTDOWN_MASK_IDLE);
4650 return true;
4653 bool ChatHandler::HandleAddQuest(const char* args)
4655 Player* player = getSelectedPlayer();
4656 if(!player)
4658 SendSysMessage(LANG_NO_CHAR_SELECTED);
4659 SetSentErrorMessage(true);
4660 return false;
4663 // .addquest #entry'
4664 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4665 char* cId = extractKeyFromLink((char*)args,"Hquest");
4666 if(!cId)
4667 return false;
4669 uint32 entry = atol(cId);
4671 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
4673 if(!pQuest)
4675 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND,entry);
4676 SetSentErrorMessage(true);
4677 return false;
4680 // check item starting quest (it can work incorrectly if added without item in inventory)
4681 QueryResult *result = WorldDatabase.PQuery("SELECT entry FROM item_template WHERE startquest = '%u' LIMIT 1",entry);
4682 if(result)
4684 Field* fields = result->Fetch();
4685 uint32 item_id = fields[0].GetUInt32();
4686 delete result;
4688 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, entry,item_id);
4689 SetSentErrorMessage(true);
4690 return false;
4693 // ok, normal (creature/GO starting) quest
4694 if( player->CanAddQuest( pQuest, true ) )
4696 player->AddQuest( pQuest, NULL );
4698 if ( player->CanCompleteQuest( entry ) )
4699 player->CompleteQuest( entry );
4702 return true;
4705 bool ChatHandler::HandleRemoveQuest(const char* args)
4707 Player* player = getSelectedPlayer();
4708 if(!player)
4710 SendSysMessage(LANG_NO_CHAR_SELECTED);
4711 SetSentErrorMessage(true);
4712 return false;
4715 // .removequest #entry'
4716 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4717 char* cId = extractKeyFromLink((char*)args,"Hquest");
4718 if(!cId)
4719 return false;
4721 uint32 entry = atol(cId);
4723 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
4725 if(!pQuest)
4727 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
4728 SetSentErrorMessage(true);
4729 return false;
4732 // remove all quest entries for 'entry' from quest log
4733 for(uint8 slot = 0; slot < MAX_QUEST_LOG_SIZE; ++slot )
4735 uint32 quest = player->GetQuestSlotQuestId(slot);
4736 if(quest==entry)
4738 player->SetQuestSlot(slot,0);
4740 // we ignore unequippable quest items in this case, its' still be equipped
4741 player->TakeQuestSourceItem( quest, false );
4745 // set quest status to not started (will updated in DB at next save)
4746 player->SetQuestStatus( entry, QUEST_STATUS_NONE);
4748 // reset rewarded for restart repeatable quest
4749 player->getQuestStatusMap()[entry].m_rewarded = false;
4751 SendSysMessage(LANG_COMMAND_QUEST_REMOVED);
4752 return true;
4755 bool ChatHandler::HandleCompleteQuest(const char* args)
4757 Player* player = getSelectedPlayer();
4758 if(!player)
4760 SendSysMessage(LANG_NO_CHAR_SELECTED);
4761 SetSentErrorMessage(true);
4762 return false;
4765 // .quest complete #entry
4766 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4767 char* cId = extractKeyFromLink((char*)args,"Hquest");
4768 if(!cId)
4769 return false;
4771 uint32 entry = atol(cId);
4773 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
4775 // If player doesn't have the quest
4776 if(!pQuest || player->GetQuestStatus(entry) == QUEST_STATUS_NONE)
4778 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
4779 SetSentErrorMessage(true);
4780 return false;
4783 // Add quest items for quests that require items
4784 for(uint8 x = 0; x < QUEST_OBJECTIVES_COUNT; ++x)
4786 uint32 id = pQuest->ReqItemId[x];
4787 uint32 count = pQuest->ReqItemCount[x];
4788 if(!id || !count)
4789 continue;
4791 uint32 curItemCount = player->GetItemCount(id,true);
4793 ItemPosCountVec dest;
4794 uint8 msg = player->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, id, count-curItemCount );
4795 if( msg == EQUIP_ERR_OK )
4797 Item* item = player->StoreNewItem( dest, id, true);
4798 player->SendNewItem(item,count-curItemCount,true,false);
4802 // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
4803 for(uint8 i = 0; i < QUEST_OBJECTIVES_COUNT; i++)
4805 uint32 creature = pQuest->ReqCreatureOrGOId[i];
4806 uint32 creaturecount = pQuest->ReqCreatureOrGOCount[i];
4808 if(uint32 spell_id = pQuest->ReqSpell[i])
4810 for(uint16 z = 0; z < creaturecount; ++z)
4811 player->CastedCreatureOrGO(creature,0,spell_id);
4813 else if(creature > 0)
4815 for(uint16 z = 0; z < creaturecount; ++z)
4816 player->KilledMonster(creature,0);
4818 else if(creature < 0)
4820 for(uint16 z = 0; z < creaturecount; ++z)
4821 player->CastedCreatureOrGO(creature,0,0);
4825 // If the quest requires reputation to complete
4826 if(uint32 repFaction = pQuest->GetRepObjectiveFaction())
4828 uint32 repValue = pQuest->GetRepObjectiveValue();
4829 uint32 curRep = player->GetReputation(repFaction);
4830 if(curRep < repValue)
4832 FactionEntry const *factionEntry = sFactionStore.LookupEntry(repFaction);
4833 player->SetFactionReputation(factionEntry,repValue);
4837 // If the quest requires money
4838 int32 ReqOrRewMoney = pQuest->GetRewOrReqMoney();
4839 if(ReqOrRewMoney < 0)
4840 player->ModifyMoney(-ReqOrRewMoney);
4842 player->CompleteQuest(entry);
4843 return true;
4846 bool ChatHandler::HandleBanAccountCommand(const char* args)
4848 return HandleBanHelper(BAN_ACCOUNT,args);
4851 bool ChatHandler::HandleBanCharacterCommand(const char* args)
4853 return HandleBanHelper(BAN_CHARACTER,args);
4856 bool ChatHandler::HandleBanIPCommand(const char* args)
4858 return HandleBanHelper(BAN_IP,args);
4861 bool ChatHandler::HandleBanHelper(BanMode mode, const char* args)
4863 if(!args)
4864 return false;
4866 char* cnameOrIP = strtok ((char*)args, " ");
4867 if (!cnameOrIP)
4868 return false;
4870 std::string nameOrIP = cnameOrIP;
4872 char* duration = strtok (NULL," ");
4873 if(!duration || !atoi(duration))
4874 return false;
4876 char* reason = strtok (NULL,"");
4877 if(!reason)
4878 return false;
4880 switch(mode)
4882 case BAN_ACCOUNT:
4883 if(!AccountMgr::normilizeString(nameOrIP))
4885 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str());
4886 SetSentErrorMessage(true);
4887 return false;
4889 break;
4890 case BAN_CHARACTER:
4891 if(!normalizePlayerName(nameOrIP))
4893 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4894 SetSentErrorMessage(true);
4895 return false;
4897 break;
4898 case BAN_IP:
4899 if(!IsIPAddress(nameOrIP.c_str()))
4900 return false;
4901 break;
4904 switch(sWorld.BanAccount(mode, nameOrIP, duration, reason,m_session ? m_session->GetPlayerName() : ""))
4906 case BAN_SUCCESS:
4907 if(atoi(duration)>0)
4908 PSendSysMessage(LANG_BAN_YOUBANNED,nameOrIP.c_str(),secsToTimeString(TimeStringToSecs(duration),true).c_str(),reason);
4909 else
4910 PSendSysMessage(LANG_BAN_YOUPERMBANNED,nameOrIP.c_str(),reason);
4911 break;
4912 case BAN_SYNTAX_ERROR:
4913 return false;
4914 case BAN_NOTFOUND:
4915 switch(mode)
4917 default:
4918 PSendSysMessage(LANG_BAN_NOTFOUND,"account",nameOrIP.c_str());
4919 break;
4920 case BAN_CHARACTER:
4921 PSendSysMessage(LANG_BAN_NOTFOUND,"character",nameOrIP.c_str());
4922 break;
4923 case BAN_IP:
4924 PSendSysMessage(LANG_BAN_NOTFOUND,"ip",nameOrIP.c_str());
4925 break;
4927 SetSentErrorMessage(true);
4928 return false;
4931 return true;
4934 bool ChatHandler::HandleUnBanAccountCommand(const char* args)
4936 return HandleUnBanHelper(BAN_ACCOUNT,args);
4939 bool ChatHandler::HandleUnBanCharacterCommand(const char* args)
4941 return HandleUnBanHelper(BAN_CHARACTER,args);
4944 bool ChatHandler::HandleUnBanIPCommand(const char* args)
4946 return HandleUnBanHelper(BAN_IP,args);
4949 bool ChatHandler::HandleUnBanHelper(BanMode mode, const char* args)
4951 if(!args)
4952 return false;
4954 char* cnameOrIP = strtok ((char*)args, " ");
4955 if(!cnameOrIP)
4956 return false;
4958 std::string nameOrIP = cnameOrIP;
4960 switch(mode)
4962 case BAN_ACCOUNT:
4963 if(!AccountMgr::normilizeString(nameOrIP))
4965 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str());
4966 SetSentErrorMessage(true);
4967 return false;
4969 break;
4970 case BAN_CHARACTER:
4971 if(!normalizePlayerName(nameOrIP))
4973 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4974 SetSentErrorMessage(true);
4975 return false;
4977 break;
4978 case BAN_IP:
4979 if(!IsIPAddress(nameOrIP.c_str()))
4980 return false;
4981 break;
4984 if(sWorld.RemoveBanAccount(mode,nameOrIP))
4985 PSendSysMessage(LANG_UNBAN_UNBANNED,nameOrIP.c_str());
4986 else
4987 PSendSysMessage(LANG_UNBAN_ERROR,nameOrIP.c_str());
4989 return true;
4992 bool ChatHandler::HandleBanInfoAccountCommand(const char* args)
4994 if(!args)
4995 return false;
4997 char* cname = strtok((char*)args, "");
4998 if(!cname)
4999 return false;
5001 std::string account_name = cname;
5002 if(!AccountMgr::normilizeString(account_name))
5004 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5005 SetSentErrorMessage(true);
5006 return false;
5009 uint32 accountid = accmgr.GetId(account_name);
5010 if(!accountid)
5012 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5013 return true;
5016 return HandleBanInfoHelper(accountid,account_name.c_str());
5019 bool ChatHandler::HandleBanInfoCharacterCommand(const char* args)
5021 if(!args)
5022 return false;
5024 char* cname = strtok ((char*)args, "");
5025 if(!cname)
5026 return false;
5028 std::string name = cname;
5029 if(!normalizePlayerName(name))
5031 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5032 SetSentErrorMessage(true);
5033 return false;
5036 uint32 accountid = objmgr.GetPlayerAccountIdByPlayerName(name);
5037 if(!accountid)
5039 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5040 SetSentErrorMessage(true);
5041 return false;
5044 std::string accountname;
5045 if(!accmgr.GetName(accountid,accountname))
5047 PSendSysMessage(LANG_BANINFO_NOCHARACTER);
5048 return true;
5051 return HandleBanInfoHelper(accountid,accountname.c_str());
5054 bool ChatHandler::HandleBanInfoHelper(uint32 accountid, char const* accountname)
5056 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);
5057 if(!result)
5059 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN, accountname);
5060 return true;
5063 PSendSysMessage(LANG_BANINFO_BANHISTORY,accountname);
5066 Field* fields = result->Fetch();
5068 time_t unbandate = time_t(fields[3].GetUInt64());
5069 bool active = false;
5070 if(fields[2].GetBool() && (fields[1].GetUInt64() == (uint64)0 ||unbandate >= time(NULL)) )
5071 active = true;
5072 bool permanent = (fields[1].GetUInt64() == (uint64)0);
5073 std::string bantime = permanent?GetMangosString(LANG_BANINFO_INFINITE):secsToTimeString(fields[1].GetUInt64(), true);
5074 PSendSysMessage(LANG_BANINFO_HISTORYENTRY,
5075 fields[0].GetString(), bantime.c_str(), active ? GetMangosString(LANG_BANINFO_YES):GetMangosString(LANG_BANINFO_NO), fields[4].GetString(), fields[5].GetString());
5076 }while (result->NextRow());
5078 delete result;
5079 return true;
5082 bool ChatHandler::HandleBanInfoIPCommand(const char* args)
5084 if(!args)
5085 return false;
5087 char* cIP = strtok ((char*)args, "");
5088 if(!cIP)
5089 return false;
5091 if (!IsIPAddress(cIP))
5092 return false;
5094 std::string IP = cIP;
5096 loginDatabase.escape_string(IP);
5097 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());
5098 if(!result)
5100 PSendSysMessage(LANG_BANINFO_NOIP);
5101 return true;
5104 Field *fields = result->Fetch();
5105 bool permanent = !fields[6].GetUInt64();
5106 PSendSysMessage(LANG_BANINFO_IPENTRY,
5107 fields[0].GetString(), fields[1].GetString(), permanent ? GetMangosString(LANG_BANINFO_NEVER):fields[2].GetString(),
5108 permanent ? GetMangosString(LANG_BANINFO_INFINITE):secsToTimeString(fields[3].GetUInt64(), true).c_str(), fields[4].GetString(), fields[5].GetString());
5109 delete result;
5110 return true;
5113 bool ChatHandler::HandleBanListCharacterCommand(const char* args)
5115 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5117 char* cFilter = strtok ((char*)args, " ");
5118 if(!cFilter)
5119 return false;
5121 std::string filter = cFilter;
5122 loginDatabase.escape_string(filter);
5123 QueryResult* result = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'"),filter.c_str());
5124 if (!result)
5126 PSendSysMessage(LANG_BANLIST_NOCHARACTER);
5127 return true;
5130 return HandleBanListHelper(result);
5133 bool ChatHandler::HandleBanListAccountCommand(const char* args)
5135 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5137 char* cFilter = strtok((char*)args, " ");
5138 std::string filter = cFilter ? cFilter : "";
5139 loginDatabase.escape_string(filter);
5141 QueryResult* result;
5143 if(filter.empty())
5145 result = loginDatabase.Query("SELECT account.id, username FROM account, account_banned"
5146 " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
5148 else
5150 result = loginDatabase.PQuery("SELECT account.id, username FROM account, account_banned"
5151 " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
5152 filter.c_str());
5155 if (!result)
5157 PSendSysMessage(LANG_BANLIST_NOACCOUNT);
5158 return true;
5161 return HandleBanListHelper(result);
5164 bool ChatHandler::HandleBanListHelper(QueryResult* result)
5166 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT);
5168 // Chat short output
5169 if(m_session)
5173 Field* fields = result->Fetch();
5174 uint32 accountid = fields[0].GetUInt32();
5176 QueryResult* banresult = loginDatabase.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid);
5177 if(banresult)
5179 Field* fields2 = banresult->Fetch();
5180 PSendSysMessage("%s",fields2[0].GetString());
5181 delete banresult;
5183 } while (result->NextRow());
5185 // Console wide output
5186 else
5188 SendSysMessage(LANG_BANLIST_ACCOUNTS);
5189 SendSysMessage("===============================================================================");
5190 SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER);
5193 SendSysMessage("-------------------------------------------------------------------------------");
5194 Field *fields = result->Fetch();
5195 uint32 account_id = fields[0].GetUInt32 ();
5197 std::string account_name;
5199 // "account" case, name can be get in same quary
5200 if(result->GetFieldCount() > 1)
5201 account_name = fields[1].GetCppString();
5202 // "character" case, name need extract from another DB
5203 else
5204 accmgr.GetName (account_id,account_name);
5206 // No SQL injection. id is uint32.
5207 QueryResult *banInfo = loginDatabase.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id);
5208 if (banInfo)
5210 Field *fields2 = banInfo->Fetch();
5213 time_t t_ban = fields2[0].GetUInt64();
5214 tm* aTm_ban = localtime(&t_ban);
5216 if (fields2[0].GetUInt64() == fields2[1].GetUInt64())
5218 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5219 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,
5220 fields2[2].GetString(),fields2[3].GetString());
5222 else
5224 time_t t_unban = fields2[1].GetUInt64();
5225 tm* aTm_unban = localtime(&t_unban);
5226 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5227 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,
5228 aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
5229 fields2[2].GetString(),fields2[3].GetString());
5231 }while ( banInfo->NextRow() );
5232 delete banInfo;
5234 }while( result->NextRow() );
5235 SendSysMessage("===============================================================================");
5238 delete result;
5239 return true;
5242 bool ChatHandler::HandleBanListIPCommand(const char* args)
5244 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5246 char* cFilter = strtok((char*)args, " ");
5247 std::string filter = cFilter ? cFilter : "";
5248 loginDatabase.escape_string(filter);
5250 QueryResult* result;
5252 if(filter.empty())
5254 result = loginDatabase.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5255 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
5256 " ORDER BY unbandate" );
5258 else
5260 result = loginDatabase.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5261 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")
5262 " ORDER BY unbandate",filter.c_str() );
5265 if(!result)
5267 PSendSysMessage(LANG_BANLIST_NOIP);
5268 return true;
5271 PSendSysMessage(LANG_BANLIST_MATCHINGIP);
5272 // Chat short output
5273 if(m_session)
5277 Field* fields = result->Fetch();
5278 PSendSysMessage("%s",fields[0].GetString());
5279 } while (result->NextRow());
5281 // Console wide output
5282 else
5284 SendSysMessage(LANG_BANLIST_IPS);
5285 SendSysMessage("===============================================================================");
5286 SendSysMessage(LANG_BANLIST_IPS_HEADER);
5289 SendSysMessage("-------------------------------------------------------------------------------");
5290 Field *fields = result->Fetch();
5291 time_t t_ban = fields[1].GetUInt64();
5292 tm* aTm_ban = localtime(&t_ban);
5293 if ( fields[1].GetUInt64() == fields[2].GetUInt64() )
5295 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5296 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,
5297 fields[3].GetString(), fields[4].GetString());
5299 else
5301 time_t t_unban = fields[2].GetUInt64();
5302 tm* aTm_unban = localtime(&t_unban);
5303 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5304 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,
5305 aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
5306 fields[3].GetString(), fields[4].GetString());
5308 }while( result->NextRow() );
5309 SendSysMessage("===============================================================================");
5312 delete result;
5313 return true;
5316 bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
5318 Unit* target = getSelectedUnit();
5320 if(target)
5322 if(target->GetTypeId()!=TYPEID_UNIT)
5324 SendSysMessage(LANG_SELECT_CREATURE);
5325 SetSentErrorMessage(true);
5326 return false;
5329 if(target->isDead())
5330 ((Creature*)target)->Respawn();
5331 return true;
5334 Player* pl = m_session->GetPlayer();
5336 CellPair p(MaNGOS::ComputeCellPair(pl->GetPositionX(), pl->GetPositionY()));
5337 Cell cell(p);
5338 cell.data.Part.reserved = ALL_DISTRICT;
5339 cell.SetNoCreate();
5341 MaNGOS::RespawnDo u_do;
5342 MaNGOS::WorldObjectWorker<MaNGOS::RespawnDo> worker(u_do);
5344 TypeContainerVisitor<MaNGOS::WorldObjectWorker<MaNGOS::RespawnDo>, GridTypeMapContainer > obj_worker(worker);
5345 CellLock<GridReadGuard> cell_lock(cell, p);
5346 cell_lock->Visit(cell_lock, obj_worker, *MapManager::Instance().GetMap(pl->GetMapId(), pl));
5348 return true;
5351 bool ChatHandler::HandleFlyModeCommand(const char* args)
5353 if(!args)
5354 return false;
5356 Unit *unit = getSelectedUnit();
5357 if (!unit || (unit->GetTypeId() != TYPEID_PLAYER))
5358 unit = m_session->GetPlayer();
5360 WorldPacket data(12);
5361 if (strncmp(args, "on", 3) == 0)
5362 data.SetOpcode(SMSG_MOVE_SET_CAN_FLY);
5363 else if (strncmp(args, "off", 4) == 0)
5364 data.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY);
5365 else
5367 SendSysMessage(LANG_USE_BOL);
5368 return false;
5370 data.append(unit->GetPackGUID());
5371 data << uint32(0); // unknown
5372 unit->SendMessageToSet(&data, true);
5373 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS, unit->GetName(), args);
5374 return true;
5377 bool ChatHandler::HandleLoadPDumpCommand(const char *args)
5379 if(!args)
5380 return false;
5382 char * file = strtok((char*)args, " ");
5383 if(!file)
5384 return false;
5386 char * account = strtok(NULL, " ");
5387 if(!account)
5388 return false;
5390 std::string account_name = account;
5391 if(!AccountMgr::normilizeString(account_name))
5393 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5394 SetSentErrorMessage(true);
5395 return false;
5398 uint32 account_id = accmgr.GetId(account_name);
5399 if(!account_id)
5401 account_id = atoi(account); // use original string
5402 if(!account_id)
5404 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5405 SetSentErrorMessage(true);
5406 return false;
5410 if(!accmgr.GetName(account_id,account_name))
5412 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5413 SetSentErrorMessage(true);
5414 return false;
5417 char* guid_str = NULL;
5418 char* name_str = strtok(NULL, " ");
5420 std::string name;
5421 if(name_str)
5423 name = name_str;
5424 // normalize the name if specified and check if it exists
5425 if(!normalizePlayerName(name))
5427 PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
5428 SetSentErrorMessage(true);
5429 return false;
5432 if(!ObjectMgr::IsValidName(name,true))
5434 PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
5435 SetSentErrorMessage(true);
5436 return false;
5439 guid_str = strtok(NULL, " ");
5442 uint32 guid = 0;
5444 if(guid_str)
5446 guid = atoi(guid_str);
5447 if(!guid)
5449 PSendSysMessage(LANG_INVALID_CHARACTER_GUID);
5450 SetSentErrorMessage(true);
5451 return false;
5454 if(objmgr.GetPlayerAccountIdByGUID(guid))
5456 PSendSysMessage(LANG_CHARACTER_GUID_IN_USE,guid);
5457 SetSentErrorMessage(true);
5458 return false;
5462 switch(PlayerDumpReader().LoadDump(file, account_id, name, guid))
5464 case DUMP_SUCCESS:
5465 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS);
5466 break;
5467 case DUMP_FILE_OPEN_ERROR:
5468 PSendSysMessage(LANG_FILE_OPEN_FAIL,file);
5469 SetSentErrorMessage(true);
5470 return false;
5471 case DUMP_FILE_BROKEN:
5472 PSendSysMessage(LANG_DUMP_BROKEN,file);
5473 SetSentErrorMessage(true);
5474 return false;
5475 case DUMP_TOO_MANY_CHARS:
5476 PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL,account_name.c_str(),account_id);
5477 SetSentErrorMessage(true);
5478 return false;
5479 default:
5480 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED);
5481 SetSentErrorMessage(true);
5482 return false;
5485 return true;
5488 bool ChatHandler::HandleNpcChangeEntryCommand(const char *args)
5490 if(!args)
5491 return false;
5493 uint32 newEntryNum = atoi(args);
5494 if(!newEntryNum)
5495 return false;
5497 Unit* unit = getSelectedUnit();
5498 if(!unit || unit->GetTypeId() != TYPEID_UNIT)
5500 SendSysMessage(LANG_SELECT_CREATURE);
5501 SetSentErrorMessage(true);
5502 return false;
5504 Creature* creature = (Creature*)unit;
5505 if(creature->UpdateEntry(newEntryNum))
5506 SendSysMessage(LANG_DONE);
5507 else
5508 SendSysMessage(LANG_ERROR);
5509 return true;
5512 bool ChatHandler::HandleWritePDumpCommand(const char *args)
5514 if(!args)
5515 return false;
5517 char* file = strtok((char*)args, " ");
5518 char* p2 = strtok(NULL, " ");
5520 if(!file || !p2)
5521 return false;
5523 uint32 guid = objmgr.GetPlayerGUIDByName(p2);
5524 if(!guid)
5525 guid = atoi(p2);
5527 if(!objmgr.GetPlayerAccountIdByGUID(guid))
5529 PSendSysMessage(LANG_PLAYER_NOT_FOUND);
5530 SetSentErrorMessage(true);
5531 return false;
5534 switch(PlayerDumpWriter().WriteDump(file, guid))
5536 case DUMP_SUCCESS:
5537 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS);
5538 break;
5539 case DUMP_FILE_OPEN_ERROR:
5540 PSendSysMessage(LANG_FILE_OPEN_FAIL,file);
5541 SetSentErrorMessage(true);
5542 return false;
5543 default:
5544 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED);
5545 SetSentErrorMessage(true);
5546 return false;
5549 return true;
5552 bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
5554 Unit* unit = getSelectedUnit();
5555 if(!unit)
5557 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5558 SetSentErrorMessage(true);
5559 return false;
5562 PSendSysMessage(LANG_MOVEGENS_LIST,(unit->GetTypeId()==TYPEID_PLAYER ? "Player" : "Creature" ),unit->GetGUIDLow());
5564 MotionMaster* mm = unit->GetMotionMaster();
5565 for(MotionMaster::const_iterator itr = mm->begin(); itr != mm->end(); ++itr)
5567 switch((*itr)->GetMovementGeneratorType())
5569 case IDLE_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_IDLE); break;
5570 case RANDOM_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_RANDOM); break;
5571 case WAYPOINT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_WAYPOINT); break;
5572 case ANIMAL_RANDOM_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_ANIMAL_RANDOM); break;
5573 case CONFUSED_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_CONFUSED); break;
5574 case TARGETED_MOTION_TYPE:
5576 if(unit->GetTypeId()==TYPEID_PLAYER)
5578 TargetedMovementGenerator<Player> const* mgen = static_cast<TargetedMovementGenerator<Player> const*>(*itr);
5579 Unit* target = mgen->GetTarget();
5580 if(target)
5581 PSendSysMessage(LANG_MOVEGENS_TARGETED_PLAYER,target->GetName(),target->GetGUIDLow());
5582 else
5583 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL);
5585 else
5587 TargetedMovementGenerator<Creature> const* mgen = static_cast<TargetedMovementGenerator<Creature> const*>(*itr);
5588 Unit* target = mgen->GetTarget();
5589 if(target)
5590 PSendSysMessage(LANG_MOVEGENS_TARGETED_CREATURE,target->GetName(),target->GetGUIDLow());
5591 else
5592 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL);
5594 break;
5596 case HOME_MOTION_TYPE:
5597 if(unit->GetTypeId()==TYPEID_UNIT)
5599 float x,y,z;
5600 (*itr)->GetDestination(x,y,z);
5601 PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE,x,y,z);
5603 else
5604 SendSysMessage(LANG_MOVEGENS_HOME_PLAYER);
5605 break;
5606 case FLIGHT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FLIGHT); break;
5607 case POINT_MOTION_TYPE:
5609 float x,y,z;
5610 (*itr)->GetDestination(x,y,z);
5611 PSendSysMessage(LANG_MOVEGENS_POINT,x,y,z);
5612 break;
5614 case FLEEING_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FEAR); break;
5615 case DISTRACT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_DISTRACT); break;
5616 default:
5617 PSendSysMessage(LANG_MOVEGENS_UNKNOWN,(*itr)->GetMovementGeneratorType());
5618 break;
5621 return true;
5624 bool ChatHandler::HandlePLimitCommand(const char *args)
5626 if(*args)
5628 char* param = strtok((char*)args, " ");
5629 if(!param)
5630 return false;
5632 int l = strlen(param);
5634 if( strncmp(param,"player",l) == 0 )
5635 sWorld.SetPlayerLimit(-SEC_PLAYER);
5636 else if(strncmp(param,"moderator",l) == 0 )
5637 sWorld.SetPlayerLimit(-SEC_MODERATOR);
5638 else if(strncmp(param,"gamemaster",l) == 0 )
5639 sWorld.SetPlayerLimit(-SEC_GAMEMASTER);
5640 else if(strncmp(param,"administrator",l) == 0 )
5641 sWorld.SetPlayerLimit(-SEC_ADMINISTRATOR);
5642 else if(strncmp(param,"reset",l) == 0 )
5643 sWorld.SetPlayerLimit( sConfig.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT) );
5644 else
5646 int val = atoi(param);
5647 if(val < -SEC_ADMINISTRATOR) val = -SEC_ADMINISTRATOR;
5649 sWorld.SetPlayerLimit(val);
5652 // kick all low security level players
5653 if(sWorld.GetPlayerAmountLimit() > SEC_PLAYER)
5654 sWorld.KickAllLess(sWorld.GetPlayerSecurityLimit());
5657 uint32 pLimit = sWorld.GetPlayerAmountLimit();
5658 AccountTypes allowedAccountType = sWorld.GetPlayerSecurityLimit();
5659 char const* secName = "";
5660 switch(allowedAccountType)
5662 case SEC_PLAYER: secName = "Player"; break;
5663 case SEC_MODERATOR: secName = "Moderator"; break;
5664 case SEC_GAMEMASTER: secName = "Gamemaster"; break;
5665 case SEC_ADMINISTRATOR: secName = "Administrator"; break;
5666 default: secName = "<unknown>"; break;
5669 PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit,secName);
5671 return true;
5674 bool ChatHandler::HandleCastCommand(const char* args)
5676 if(!*args)
5677 return false;
5679 Unit* target = getSelectedUnit();
5681 if(!target)
5683 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5684 SetSentErrorMessage(true);
5685 return false;
5688 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5689 uint32 spell = extractSpellIdFromLink((char*)args);
5690 if(!spell)
5691 return false;
5693 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
5694 if(!spellInfo)
5695 return false;
5697 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
5699 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
5700 SetSentErrorMessage(true);
5701 return false;
5704 char* trig_str = strtok(NULL, " ");
5705 if(trig_str)
5707 int l = strlen(trig_str);
5708 if(strncmp(trig_str,"triggered",l) != 0 )
5709 return false;
5712 bool triggered = (trig_str != NULL);
5714 m_session->GetPlayer()->CastSpell(target,spell,triggered);
5716 return true;
5719 bool ChatHandler::HandleCastBackCommand(const char* args)
5721 Creature* caster = getSelectedCreature();
5723 if(!caster)
5725 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5726 SetSentErrorMessage(true);
5727 return false;
5730 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
5731 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5732 uint32 spell = extractSpellIdFromLink((char*)args);
5733 if(!spell || !sSpellStore.LookupEntry(spell))
5734 return false;
5736 char* trig_str = strtok(NULL, " ");
5737 if(trig_str)
5739 int l = strlen(trig_str);
5740 if(strncmp(trig_str,"triggered",l) != 0 )
5741 return false;
5744 bool triggered = (trig_str != NULL);
5746 // update orientation at server
5747 caster->SetOrientation(caster->GetAngle(m_session->GetPlayer()));
5749 // and client
5750 WorldPacket data;
5751 caster->BuildHeartBeatMsg(&data);
5752 caster->SendMessageToSet(&data,true);
5754 caster->CastSpell(m_session->GetPlayer(),spell,false);
5756 return true;
5759 bool ChatHandler::HandleCastDistCommand(const char* args)
5761 if(!*args)
5762 return false;
5764 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5765 uint32 spell = extractSpellIdFromLink((char*)args);
5766 if(!spell)
5767 return false;
5769 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
5770 if(!spellInfo)
5771 return false;
5773 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
5775 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
5776 SetSentErrorMessage(true);
5777 return false;
5780 char *distStr = strtok(NULL, " ");
5782 float dist = 0;
5784 if(distStr)
5785 sscanf(distStr, "%f", &dist);
5787 char* trig_str = strtok(NULL, " ");
5788 if(trig_str)
5790 int l = strlen(trig_str);
5791 if(strncmp(trig_str,"triggered",l) != 0 )
5792 return false;
5795 bool triggered = (trig_str != NULL);
5797 float x,y,z;
5798 m_session->GetPlayer()->GetClosePoint(x,y,z,dist);
5800 m_session->GetPlayer()->CastSpell(x,y,z,spell,triggered);
5801 return true;
5804 bool ChatHandler::HandleCastTargetCommand(const char* args)
5806 Creature* caster = getSelectedCreature();
5808 if(!caster)
5810 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5811 SetSentErrorMessage(true);
5812 return false;
5815 if(!caster->getVictim())
5817 SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM);
5818 SetSentErrorMessage(true);
5819 return false;
5822 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5823 uint32 spell = extractSpellIdFromLink((char*)args);
5824 if(!spell || !sSpellStore.LookupEntry(spell))
5825 return false;
5827 char* trig_str = strtok(NULL, " ");
5828 if(trig_str)
5830 int l = strlen(trig_str);
5831 if(strncmp(trig_str,"triggered",l) != 0 )
5832 return false;
5835 bool triggered = (trig_str != NULL);
5837 // update orientation at server
5838 caster->SetOrientation(caster->GetAngle(m_session->GetPlayer()));
5840 // and client
5841 WorldPacket data;
5842 caster->BuildHeartBeatMsg(&data);
5843 caster->SendMessageToSet(&data,true);
5845 caster->CastSpell(caster->getVictim(),spell,false);
5847 return true;
5851 ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
5852 Without this function 3rd party scripting library will get linking errors (unresolved external)
5853 when attempting to use the PointMovementGenerator
5855 bool ChatHandler::HandleComeToMeCommand(const char *args)
5857 Creature* caster = getSelectedCreature();
5859 if(!caster)
5861 SendSysMessage(LANG_SELECT_CREATURE);
5862 SetSentErrorMessage(true);
5863 return false;
5866 char* newFlagStr = strtok((char*)args, " ");
5868 if(!newFlagStr)
5869 return false;
5871 uint32 newFlags = atoi(newFlagStr);
5873 caster->SetUnitMovementFlags(newFlags);
5875 Player* pl = m_session->GetPlayer();
5877 caster->GetMotionMaster()->MovePoint(0, pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ());
5878 return true;
5881 bool ChatHandler::HandleCastSelfCommand(const char* args)
5883 if(!*args)
5884 return false;
5886 Unit* target = getSelectedUnit();
5888 if(!target)
5890 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5891 SetSentErrorMessage(true);
5892 return false;
5895 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5896 uint32 spell = extractSpellIdFromLink((char*)args);
5897 if(!spell)
5898 return false;
5900 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
5901 if(!spellInfo)
5902 return false;
5904 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
5906 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
5907 SetSentErrorMessage(true);
5908 return false;
5911 target->CastSpell(target,spell,false);
5913 return true;
5916 std::string GetTimeString(uint32 time)
5918 uint16 days = time / DAY, hours = (time % DAY) / HOUR, minute = (time % HOUR) / MINUTE;
5919 std::ostringstream ss;
5920 if(days) ss << days << "d ";
5921 if(hours) ss << hours << "h ";
5922 ss << minute << "m";
5923 return ss.str();
5926 bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
5928 Player* player = getSelectedPlayer();
5929 if (!player) player = m_session->GetPlayer();
5930 uint32 counter = 0;
5931 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; i++)
5933 Player::BoundInstancesMap &binds = player->GetBoundInstances(i);
5934 for(Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end(); ++itr)
5936 InstanceSave *save = itr->second.save;
5937 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
5938 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());
5939 counter++;
5942 PSendSysMessage("player binds: %d", counter);
5943 counter = 0;
5944 Group *group = player->GetGroup();
5945 if(group)
5947 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; i++)
5949 Group::BoundInstancesMap &binds = group->GetBoundInstances(i);
5950 for(Group::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end(); ++itr)
5952 InstanceSave *save = itr->second.save;
5953 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
5954 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());
5955 counter++;
5959 PSendSysMessage("group binds: %d", counter);
5961 return true;
5964 bool ChatHandler::HandleInstanceUnbindCommand(const char* args)
5966 if(!*args)
5967 return false;
5969 std::string cmd = args;
5970 if(cmd == "all")
5972 Player* player = getSelectedPlayer();
5973 if (!player) player = m_session->GetPlayer();
5974 uint32 counter = 0;
5975 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; i++)
5977 Player::BoundInstancesMap &binds = player->GetBoundInstances(i);
5978 for(Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end();)
5980 if(itr->first != player->GetMapId())
5982 InstanceSave *save = itr->second.save;
5983 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
5984 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());
5985 player->UnbindInstance(itr, i);
5986 counter++;
5988 else
5989 ++itr;
5992 PSendSysMessage("instances unbound: %d", counter);
5994 return true;
5997 bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
5999 PSendSysMessage("instances loaded: %d", MapManager::Instance().GetNumInstances());
6000 PSendSysMessage("players in instances: %d", MapManager::Instance().GetNumPlayersInInstances());
6001 PSendSysMessage("instance saves: %d", sInstanceSaveManager.GetNumInstanceSaves());
6002 PSendSysMessage("players bound: %d", sInstanceSaveManager.GetNumBoundPlayersTotal());
6003 PSendSysMessage("groups bound: %d", sInstanceSaveManager.GetNumBoundGroupsTotal());
6004 return true;
6007 bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
6009 Player* pl = m_session->GetPlayer();
6011 Map* map = pl->GetMap();
6012 if (!map->IsDungeon())
6014 PSendSysMessage("Map is not a dungeon.");
6015 SetSentErrorMessage(true);
6016 return false;
6019 if (!((InstanceMap*)map)->GetInstanceData())
6021 PSendSysMessage("Map has no instance data.");
6022 SetSentErrorMessage(true);
6023 return false;
6026 ((InstanceMap*)map)->GetInstanceData()->SaveToDB();
6027 return true;
6030 /// Display the list of GMs
6031 bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
6033 ///- Get the accounts with GM Level >0
6034 QueryResult *result = loginDatabase.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
6035 if(result)
6037 SendSysMessage(LANG_GMLIST);
6038 SendSysMessage("========================");
6039 SendSysMessage(LANG_GMLIST_HEADER);
6040 SendSysMessage("========================");
6042 ///- Circle through them. Display username and GM level
6045 Field *fields = result->Fetch();
6046 PSendSysMessage("|%15s|%6s|", fields[0].GetString(),fields[1].GetString());
6047 }while( result->NextRow() );
6049 PSendSysMessage("========================");
6050 delete result;
6052 else
6053 PSendSysMessage(LANG_GMLIST_EMPTY);
6054 return true;
6057 /// Define the 'Message of the day' for the realm
6058 bool ChatHandler::HandleServerSetMotdCommand(const char* args)
6060 sWorld.SetMotd(args);
6061 PSendSysMessage(LANG_MOTD_NEW, args);
6062 return true;
6065 /// Set/Unset the expansion level for an account
6066 bool ChatHandler::HandleAccountSetAddonCommand(const char* args)
6068 ///- Get the command line arguments
6069 char *szAcc = strtok((char*)args," ");
6070 char *szExp = strtok(NULL," ");
6072 if(!szAcc)
6073 return false;
6075 std::string account_name;
6076 uint32 account_id;
6078 if(!szExp)
6080 Player* player = getSelectedPlayer();
6081 if(!player)
6082 return false;
6084 account_id = player->GetSession()->GetAccountId();
6085 accmgr.GetName(account_id,account_name);
6086 szExp = szAcc;
6088 else
6090 ///- Convert Account name to Upper Format
6091 account_name = szAcc;
6092 if(!AccountMgr::normilizeString(account_name))
6094 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
6095 SetSentErrorMessage(true);
6096 return false;
6099 account_id = accmgr.GetId(account_name);
6100 if(!account_id)
6102 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
6103 SetSentErrorMessage(true);
6104 return false;
6108 int lev=atoi(szExp); //get int anyway (0 if error)
6109 if(lev < 0)
6110 return false;
6112 // No SQL injection
6113 loginDatabase.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev,account_id);
6114 PSendSysMessage(LANG_ACCOUNT_SETADDON,account_name.c_str(),account_id,lev);
6115 return true;
6118 /// Send a message to a player in game
6119 bool ChatHandler::HandleSendMessageCommand(const char* args)
6121 ///- Get the command line arguments
6122 char* name_str = strtok((char*)args, " ");
6123 char* msg_str = strtok(NULL, "");
6125 if(!name_str || !msg_str)
6126 return false;
6128 std::string name = name_str;
6130 if(!normalizePlayerName(name))
6131 return false;
6133 ///- Find the player and check that he is not logging out.
6134 Player *rPlayer = objmgr.GetPlayer(name.c_str());
6135 if(!rPlayer)
6137 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6138 SetSentErrorMessage(true);
6139 return false;
6142 if(rPlayer->GetSession()->isLogingOut())
6144 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6145 SetSentErrorMessage(true);
6146 return false;
6149 ///- Send the message
6150 //Use SendAreaTriggerMessage for fastest delivery.
6151 rPlayer->GetSession()->SendAreaTriggerMessage("%s", msg_str);
6152 rPlayer->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
6154 //Confirmation message
6155 PSendSysMessage(LANG_SENDMESSAGE,name.c_str(),msg_str);
6156 return true;