Fixed pvp flag (once again), crash fix
[getmangos.git] / src / game / Level3.cpp
blob42c4beb8b071e623bc7c1af54c01d2a723b52bc9
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::HandlePlayEmoteCommand(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_PVP );
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->InitGlyphsForLevel();
4388 player->InitTalentForLevel();
4389 player->SetUInt32Value(PLAYER_XP,0);
4391 // reset level to summoned pet
4392 Pet* pet = player->GetPet();
4393 if(pet && pet->getPetType()==SUMMON_PET)
4394 pet->InitStatsForLevel(1);
4396 return true;
4399 bool ChatHandler::HandleResetStatsCommand(const char * args)
4401 char* pName = strtok((char*)args, "");
4402 Player *player = NULL;
4403 if (pName)
4405 std::string name = pName;
4406 if(!normalizePlayerName(name))
4408 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4409 SetSentErrorMessage(true);
4410 return false;
4413 uint64 guid = objmgr.GetPlayerGUIDByName(name.c_str());
4414 player = objmgr.GetPlayer(guid);
4416 else
4417 player = getSelectedPlayer();
4419 if(!player)
4421 SendSysMessage(LANG_NO_CHAR_SELECTED);
4422 SetSentErrorMessage(true);
4423 return false;
4426 if(!HandleResetStatsOrLevelHelper(player))
4427 return false;
4429 player->InitStatsForLevel(true);
4430 player->InitTaxiNodesForLevel();
4431 player->InitGlyphsForLevel();
4432 player->InitTalentForLevel();
4434 return true;
4437 bool ChatHandler::HandleResetSpellsCommand(const char * args)
4439 char* pName = strtok((char*)args, "");
4440 Player *player = NULL;
4441 uint64 playerGUID = 0;
4442 if (pName)
4444 std::string name = pName;
4446 if(!normalizePlayerName(name))
4448 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4449 SetSentErrorMessage(true);
4450 return false;
4453 player = objmgr.GetPlayer(name.c_str());
4454 if(!player)
4455 playerGUID = objmgr.GetPlayerGUIDByName(name.c_str());
4457 else
4458 player = getSelectedPlayer();
4460 if(!player && !playerGUID)
4462 SendSysMessage(LANG_NO_CHAR_SELECTED);
4463 SetSentErrorMessage(true);
4464 return false;
4467 if(player)
4469 player->resetSpells();
4471 ChatHandler(player).SendSysMessage(LANG_RESET_SPELLS);
4473 if(m_session->GetPlayer()!=player)
4474 PSendSysMessage(LANG_RESET_SPELLS_ONLINE,player->GetName());
4476 else
4478 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS), GUID_LOPART(playerGUID));
4479 PSendSysMessage(LANG_RESET_SPELLS_OFFLINE,pName);
4482 return true;
4485 bool ChatHandler::HandleResetTalentsCommand(const char * args)
4487 char* pName = strtok((char*)args, "");
4488 Player *player = NULL;
4489 uint64 playerGUID = 0;
4490 if (pName)
4492 std::string name = pName;
4493 if(!normalizePlayerName(name))
4495 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4496 SetSentErrorMessage(true);
4497 return false;
4500 player = objmgr.GetPlayer(name.c_str());
4501 if(!player)
4502 playerGUID = objmgr.GetPlayerGUIDByName(name.c_str());
4504 else
4505 player = getSelectedPlayer();
4507 if(!player && !playerGUID)
4509 SendSysMessage(LANG_NO_CHAR_SELECTED);
4510 SetSentErrorMessage(true);
4511 return false;
4514 if(player)
4516 player->resetTalents(true);
4518 ChatHandler(player).SendSysMessage(LANG_RESET_TALENTS);
4520 if(m_session->GetPlayer()!=player)
4521 PSendSysMessage(LANG_RESET_TALENTS_ONLINE,player->GetName());
4523 else
4525 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_TALENTS), GUID_LOPART(playerGUID) );
4526 PSendSysMessage(LANG_RESET_TALENTS_OFFLINE,pName);
4529 return true;
4532 bool ChatHandler::HandleResetAllCommand(const char * args)
4534 if(!*args)
4535 return false;
4537 std::string casename = args;
4539 AtLoginFlags atLogin;
4541 // Command specially created as single command to prevent using short case names
4542 if(casename=="spells")
4544 atLogin = AT_LOGIN_RESET_SPELLS;
4545 sWorld.SendWorldText(LANG_RESETALL_SPELLS);
4547 else if(casename=="talents")
4549 atLogin = AT_LOGIN_RESET_TALENTS;
4550 sWorld.SendWorldText(LANG_RESETALL_TALENTS);
4552 else
4554 PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE,args);
4555 SetSentErrorMessage(true);
4556 return false;
4559 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u'",atLogin);
4560 HashMapHolder<Player>::MapType const& plist = ObjectAccessor::Instance().GetPlayers();
4561 for(HashMapHolder<Player>::MapType::const_iterator itr = plist.begin(); itr != plist.end(); ++itr)
4562 itr->second->SetAtLoginFlag(atLogin);
4564 return true;
4567 bool ChatHandler::HandleShutDownCommand(const char* args)
4569 if(!*args)
4570 return false;
4572 if(std::string(args)=="cancel")
4574 sWorld.ShutdownCancel();
4576 else
4578 int32 time = atoi(args);
4580 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4581 if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
4582 return false;
4584 sWorld.ShutdownServ(time);
4586 return true;
4589 bool ChatHandler::HandleRestartCommand(const char* args)
4591 if(!*args)
4592 return false;
4594 if(std::string(args)=="cancel")
4596 sWorld.ShutdownCancel();
4598 else
4600 int32 time = atoi(args);
4602 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4603 if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
4604 return false;
4606 sWorld.ShutdownServ(time, SHUTDOWN_MASK_RESTART);
4608 return true;
4611 bool ChatHandler::HandleIdleRestartCommand(const char* args)
4613 if(!*args)
4614 return false;
4616 if(std::string(args)=="cancel")
4618 sWorld.ShutdownCancel();
4620 else
4622 int32 time = atoi(args);
4624 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4625 if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
4626 return false;
4628 sWorld.ShutdownServ(time,SHUTDOWN_MASK_RESTART+SHUTDOWN_MASK_IDLE);
4630 return true;
4633 bool ChatHandler::HandleIdleShutDownCommand(const char* args)
4635 if(!*args)
4636 return false;
4638 if(std::string(args)=="cancel")
4640 sWorld.ShutdownCancel();
4642 else
4644 int32 time = atoi(args);
4646 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4647 if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
4648 return false;
4650 sWorld.ShutdownServ(time,SHUTDOWN_MASK_IDLE);
4652 return true;
4655 bool ChatHandler::HandleAddQuest(const char* args)
4657 Player* player = getSelectedPlayer();
4658 if(!player)
4660 SendSysMessage(LANG_NO_CHAR_SELECTED);
4661 SetSentErrorMessage(true);
4662 return false;
4665 // .addquest #entry'
4666 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4667 char* cId = extractKeyFromLink((char*)args,"Hquest");
4668 if(!cId)
4669 return false;
4671 uint32 entry = atol(cId);
4673 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
4675 if(!pQuest)
4677 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND,entry);
4678 SetSentErrorMessage(true);
4679 return false;
4682 // check item starting quest (it can work incorrectly if added without item in inventory)
4683 QueryResult *result = WorldDatabase.PQuery("SELECT entry FROM item_template WHERE startquest = '%u' LIMIT 1",entry);
4684 if(result)
4686 Field* fields = result->Fetch();
4687 uint32 item_id = fields[0].GetUInt32();
4688 delete result;
4690 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, entry,item_id);
4691 SetSentErrorMessage(true);
4692 return false;
4695 // ok, normal (creature/GO starting) quest
4696 if( player->CanAddQuest( pQuest, true ) )
4698 player->AddQuest( pQuest, NULL );
4700 if ( player->CanCompleteQuest( entry ) )
4701 player->CompleteQuest( entry );
4704 return true;
4707 bool ChatHandler::HandleRemoveQuest(const char* args)
4709 Player* player = getSelectedPlayer();
4710 if(!player)
4712 SendSysMessage(LANG_NO_CHAR_SELECTED);
4713 SetSentErrorMessage(true);
4714 return false;
4717 // .removequest #entry'
4718 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4719 char* cId = extractKeyFromLink((char*)args,"Hquest");
4720 if(!cId)
4721 return false;
4723 uint32 entry = atol(cId);
4725 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
4727 if(!pQuest)
4729 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
4730 SetSentErrorMessage(true);
4731 return false;
4734 // remove all quest entries for 'entry' from quest log
4735 for(uint8 slot = 0; slot < MAX_QUEST_LOG_SIZE; ++slot )
4737 uint32 quest = player->GetQuestSlotQuestId(slot);
4738 if(quest==entry)
4740 player->SetQuestSlot(slot,0);
4742 // we ignore unequippable quest items in this case, its' still be equipped
4743 player->TakeQuestSourceItem( quest, false );
4747 // set quest status to not started (will updated in DB at next save)
4748 player->SetQuestStatus( entry, QUEST_STATUS_NONE);
4750 // reset rewarded for restart repeatable quest
4751 player->getQuestStatusMap()[entry].m_rewarded = false;
4753 SendSysMessage(LANG_COMMAND_QUEST_REMOVED);
4754 return true;
4757 bool ChatHandler::HandleCompleteQuest(const char* args)
4759 Player* player = getSelectedPlayer();
4760 if(!player)
4762 SendSysMessage(LANG_NO_CHAR_SELECTED);
4763 SetSentErrorMessage(true);
4764 return false;
4767 // .quest complete #entry
4768 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4769 char* cId = extractKeyFromLink((char*)args,"Hquest");
4770 if(!cId)
4771 return false;
4773 uint32 entry = atol(cId);
4775 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
4777 // If player doesn't have the quest
4778 if(!pQuest || player->GetQuestStatus(entry) == QUEST_STATUS_NONE)
4780 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
4781 SetSentErrorMessage(true);
4782 return false;
4785 // Add quest items for quests that require items
4786 for(uint8 x = 0; x < QUEST_OBJECTIVES_COUNT; ++x)
4788 uint32 id = pQuest->ReqItemId[x];
4789 uint32 count = pQuest->ReqItemCount[x];
4790 if(!id || !count)
4791 continue;
4793 uint32 curItemCount = player->GetItemCount(id,true);
4795 ItemPosCountVec dest;
4796 uint8 msg = player->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, id, count-curItemCount );
4797 if( msg == EQUIP_ERR_OK )
4799 Item* item = player->StoreNewItem( dest, id, true);
4800 player->SendNewItem(item,count-curItemCount,true,false);
4804 // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
4805 for(uint8 i = 0; i < QUEST_OBJECTIVES_COUNT; i++)
4807 uint32 creature = pQuest->ReqCreatureOrGOId[i];
4808 uint32 creaturecount = pQuest->ReqCreatureOrGOCount[i];
4810 if(uint32 spell_id = pQuest->ReqSpell[i])
4812 for(uint16 z = 0; z < creaturecount; ++z)
4813 player->CastedCreatureOrGO(creature,0,spell_id);
4815 else if(creature > 0)
4817 for(uint16 z = 0; z < creaturecount; ++z)
4818 player->KilledMonster(creature,0);
4820 else if(creature < 0)
4822 for(uint16 z = 0; z < creaturecount; ++z)
4823 player->CastedCreatureOrGO(creature,0,0);
4827 // If the quest requires reputation to complete
4828 if(uint32 repFaction = pQuest->GetRepObjectiveFaction())
4830 uint32 repValue = pQuest->GetRepObjectiveValue();
4831 uint32 curRep = player->GetReputation(repFaction);
4832 if(curRep < repValue)
4834 FactionEntry const *factionEntry = sFactionStore.LookupEntry(repFaction);
4835 player->SetFactionReputation(factionEntry,repValue);
4839 // If the quest requires money
4840 int32 ReqOrRewMoney = pQuest->GetRewOrReqMoney();
4841 if(ReqOrRewMoney < 0)
4842 player->ModifyMoney(-ReqOrRewMoney);
4844 player->CompleteQuest(entry);
4845 return true;
4848 bool ChatHandler::HandleBanAccountCommand(const char* args)
4850 return HandleBanHelper(BAN_ACCOUNT,args);
4853 bool ChatHandler::HandleBanCharacterCommand(const char* args)
4855 return HandleBanHelper(BAN_CHARACTER,args);
4858 bool ChatHandler::HandleBanIPCommand(const char* args)
4860 return HandleBanHelper(BAN_IP,args);
4863 bool ChatHandler::HandleBanHelper(BanMode mode, const char* args)
4865 if(!args)
4866 return false;
4868 char* cnameOrIP = strtok ((char*)args, " ");
4869 if (!cnameOrIP)
4870 return false;
4872 std::string nameOrIP = cnameOrIP;
4874 char* duration = strtok (NULL," ");
4875 if(!duration || !atoi(duration))
4876 return false;
4878 char* reason = strtok (NULL,"");
4879 if(!reason)
4880 return false;
4882 switch(mode)
4884 case BAN_ACCOUNT:
4885 if(!AccountMgr::normilizeString(nameOrIP))
4887 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str());
4888 SetSentErrorMessage(true);
4889 return false;
4891 break;
4892 case BAN_CHARACTER:
4893 if(!normalizePlayerName(nameOrIP))
4895 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4896 SetSentErrorMessage(true);
4897 return false;
4899 break;
4900 case BAN_IP:
4901 if(!IsIPAddress(nameOrIP.c_str()))
4902 return false;
4903 break;
4906 switch(sWorld.BanAccount(mode, nameOrIP, duration, reason,m_session ? m_session->GetPlayerName() : ""))
4908 case BAN_SUCCESS:
4909 if(atoi(duration)>0)
4910 PSendSysMessage(LANG_BAN_YOUBANNED,nameOrIP.c_str(),secsToTimeString(TimeStringToSecs(duration),true).c_str(),reason);
4911 else
4912 PSendSysMessage(LANG_BAN_YOUPERMBANNED,nameOrIP.c_str(),reason);
4913 break;
4914 case BAN_SYNTAX_ERROR:
4915 return false;
4916 case BAN_NOTFOUND:
4917 switch(mode)
4919 default:
4920 PSendSysMessage(LANG_BAN_NOTFOUND,"account",nameOrIP.c_str());
4921 break;
4922 case BAN_CHARACTER:
4923 PSendSysMessage(LANG_BAN_NOTFOUND,"character",nameOrIP.c_str());
4924 break;
4925 case BAN_IP:
4926 PSendSysMessage(LANG_BAN_NOTFOUND,"ip",nameOrIP.c_str());
4927 break;
4929 SetSentErrorMessage(true);
4930 return false;
4933 return true;
4936 bool ChatHandler::HandleUnBanAccountCommand(const char* args)
4938 return HandleUnBanHelper(BAN_ACCOUNT,args);
4941 bool ChatHandler::HandleUnBanCharacterCommand(const char* args)
4943 return HandleUnBanHelper(BAN_CHARACTER,args);
4946 bool ChatHandler::HandleUnBanIPCommand(const char* args)
4948 return HandleUnBanHelper(BAN_IP,args);
4951 bool ChatHandler::HandleUnBanHelper(BanMode mode, const char* args)
4953 if(!args)
4954 return false;
4956 char* cnameOrIP = strtok ((char*)args, " ");
4957 if(!cnameOrIP)
4958 return false;
4960 std::string nameOrIP = cnameOrIP;
4962 switch(mode)
4964 case BAN_ACCOUNT:
4965 if(!AccountMgr::normilizeString(nameOrIP))
4967 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str());
4968 SetSentErrorMessage(true);
4969 return false;
4971 break;
4972 case BAN_CHARACTER:
4973 if(!normalizePlayerName(nameOrIP))
4975 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4976 SetSentErrorMessage(true);
4977 return false;
4979 break;
4980 case BAN_IP:
4981 if(!IsIPAddress(nameOrIP.c_str()))
4982 return false;
4983 break;
4986 if(sWorld.RemoveBanAccount(mode,nameOrIP))
4987 PSendSysMessage(LANG_UNBAN_UNBANNED,nameOrIP.c_str());
4988 else
4989 PSendSysMessage(LANG_UNBAN_ERROR,nameOrIP.c_str());
4991 return true;
4994 bool ChatHandler::HandleBanInfoAccountCommand(const char* args)
4996 if(!args)
4997 return false;
4999 char* cname = strtok((char*)args, "");
5000 if(!cname)
5001 return false;
5003 std::string account_name = cname;
5004 if(!AccountMgr::normilizeString(account_name))
5006 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5007 SetSentErrorMessage(true);
5008 return false;
5011 uint32 accountid = accmgr.GetId(account_name);
5012 if(!accountid)
5014 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5015 return true;
5018 return HandleBanInfoHelper(accountid,account_name.c_str());
5021 bool ChatHandler::HandleBanInfoCharacterCommand(const char* args)
5023 if(!args)
5024 return false;
5026 char* cname = strtok ((char*)args, "");
5027 if(!cname)
5028 return false;
5030 std::string name = cname;
5031 if(!normalizePlayerName(name))
5033 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5034 SetSentErrorMessage(true);
5035 return false;
5038 uint32 accountid = objmgr.GetPlayerAccountIdByPlayerName(name);
5039 if(!accountid)
5041 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5042 SetSentErrorMessage(true);
5043 return false;
5046 std::string accountname;
5047 if(!accmgr.GetName(accountid,accountname))
5049 PSendSysMessage(LANG_BANINFO_NOCHARACTER);
5050 return true;
5053 return HandleBanInfoHelper(accountid,accountname.c_str());
5056 bool ChatHandler::HandleBanInfoHelper(uint32 accountid, char const* accountname)
5058 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);
5059 if(!result)
5061 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN, accountname);
5062 return true;
5065 PSendSysMessage(LANG_BANINFO_BANHISTORY,accountname);
5068 Field* fields = result->Fetch();
5070 time_t unbandate = time_t(fields[3].GetUInt64());
5071 bool active = false;
5072 if(fields[2].GetBool() && (fields[1].GetUInt64() == (uint64)0 ||unbandate >= time(NULL)) )
5073 active = true;
5074 bool permanent = (fields[1].GetUInt64() == (uint64)0);
5075 std::string bantime = permanent?GetMangosString(LANG_BANINFO_INFINITE):secsToTimeString(fields[1].GetUInt64(), true);
5076 PSendSysMessage(LANG_BANINFO_HISTORYENTRY,
5077 fields[0].GetString(), bantime.c_str(), active ? GetMangosString(LANG_BANINFO_YES):GetMangosString(LANG_BANINFO_NO), fields[4].GetString(), fields[5].GetString());
5078 }while (result->NextRow());
5080 delete result;
5081 return true;
5084 bool ChatHandler::HandleBanInfoIPCommand(const char* args)
5086 if(!args)
5087 return false;
5089 char* cIP = strtok ((char*)args, "");
5090 if(!cIP)
5091 return false;
5093 if (!IsIPAddress(cIP))
5094 return false;
5096 std::string IP = cIP;
5098 loginDatabase.escape_string(IP);
5099 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());
5100 if(!result)
5102 PSendSysMessage(LANG_BANINFO_NOIP);
5103 return true;
5106 Field *fields = result->Fetch();
5107 bool permanent = !fields[6].GetUInt64();
5108 PSendSysMessage(LANG_BANINFO_IPENTRY,
5109 fields[0].GetString(), fields[1].GetString(), permanent ? GetMangosString(LANG_BANINFO_NEVER):fields[2].GetString(),
5110 permanent ? GetMangosString(LANG_BANINFO_INFINITE):secsToTimeString(fields[3].GetUInt64(), true).c_str(), fields[4].GetString(), fields[5].GetString());
5111 delete result;
5112 return true;
5115 bool ChatHandler::HandleBanListCharacterCommand(const char* args)
5117 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5119 char* cFilter = strtok ((char*)args, " ");
5120 if(!cFilter)
5121 return false;
5123 std::string filter = cFilter;
5124 loginDatabase.escape_string(filter);
5125 QueryResult* result = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'"),filter.c_str());
5126 if (!result)
5128 PSendSysMessage(LANG_BANLIST_NOCHARACTER);
5129 return true;
5132 return HandleBanListHelper(result);
5135 bool ChatHandler::HandleBanListAccountCommand(const char* args)
5137 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5139 char* cFilter = strtok((char*)args, " ");
5140 std::string filter = cFilter ? cFilter : "";
5141 loginDatabase.escape_string(filter);
5143 QueryResult* result;
5145 if(filter.empty())
5147 result = loginDatabase.Query("SELECT account.id, username FROM account, account_banned"
5148 " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
5150 else
5152 result = loginDatabase.PQuery("SELECT account.id, username FROM account, account_banned"
5153 " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
5154 filter.c_str());
5157 if (!result)
5159 PSendSysMessage(LANG_BANLIST_NOACCOUNT);
5160 return true;
5163 return HandleBanListHelper(result);
5166 bool ChatHandler::HandleBanListHelper(QueryResult* result)
5168 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT);
5170 // Chat short output
5171 if(m_session)
5175 Field* fields = result->Fetch();
5176 uint32 accountid = fields[0].GetUInt32();
5178 QueryResult* banresult = loginDatabase.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid);
5179 if(banresult)
5181 Field* fields2 = banresult->Fetch();
5182 PSendSysMessage("%s",fields2[0].GetString());
5183 delete banresult;
5185 } while (result->NextRow());
5187 // Console wide output
5188 else
5190 SendSysMessage(LANG_BANLIST_ACCOUNTS);
5191 SendSysMessage("===============================================================================");
5192 SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER);
5195 SendSysMessage("-------------------------------------------------------------------------------");
5196 Field *fields = result->Fetch();
5197 uint32 account_id = fields[0].GetUInt32 ();
5199 std::string account_name;
5201 // "account" case, name can be get in same quary
5202 if(result->GetFieldCount() > 1)
5203 account_name = fields[1].GetCppString();
5204 // "character" case, name need extract from another DB
5205 else
5206 accmgr.GetName (account_id,account_name);
5208 // No SQL injection. id is uint32.
5209 QueryResult *banInfo = loginDatabase.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id);
5210 if (banInfo)
5212 Field *fields2 = banInfo->Fetch();
5215 time_t t_ban = fields2[0].GetUInt64();
5216 tm* aTm_ban = localtime(&t_ban);
5218 if (fields2[0].GetUInt64() == fields2[1].GetUInt64())
5220 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5221 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,
5222 fields2[2].GetString(),fields2[3].GetString());
5224 else
5226 time_t t_unban = fields2[1].GetUInt64();
5227 tm* aTm_unban = localtime(&t_unban);
5228 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5229 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,
5230 aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
5231 fields2[2].GetString(),fields2[3].GetString());
5233 }while ( banInfo->NextRow() );
5234 delete banInfo;
5236 }while( result->NextRow() );
5237 SendSysMessage("===============================================================================");
5240 delete result;
5241 return true;
5244 bool ChatHandler::HandleBanListIPCommand(const char* args)
5246 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5248 char* cFilter = strtok((char*)args, " ");
5249 std::string filter = cFilter ? cFilter : "";
5250 loginDatabase.escape_string(filter);
5252 QueryResult* result;
5254 if(filter.empty())
5256 result = loginDatabase.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5257 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
5258 " ORDER BY unbandate" );
5260 else
5262 result = loginDatabase.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5263 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")
5264 " ORDER BY unbandate",filter.c_str() );
5267 if(!result)
5269 PSendSysMessage(LANG_BANLIST_NOIP);
5270 return true;
5273 PSendSysMessage(LANG_BANLIST_MATCHINGIP);
5274 // Chat short output
5275 if(m_session)
5279 Field* fields = result->Fetch();
5280 PSendSysMessage("%s",fields[0].GetString());
5281 } while (result->NextRow());
5283 // Console wide output
5284 else
5286 SendSysMessage(LANG_BANLIST_IPS);
5287 SendSysMessage("===============================================================================");
5288 SendSysMessage(LANG_BANLIST_IPS_HEADER);
5291 SendSysMessage("-------------------------------------------------------------------------------");
5292 Field *fields = result->Fetch();
5293 time_t t_ban = fields[1].GetUInt64();
5294 tm* aTm_ban = localtime(&t_ban);
5295 if ( fields[1].GetUInt64() == fields[2].GetUInt64() )
5297 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5298 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,
5299 fields[3].GetString(), fields[4].GetString());
5301 else
5303 time_t t_unban = fields[2].GetUInt64();
5304 tm* aTm_unban = localtime(&t_unban);
5305 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5306 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,
5307 aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
5308 fields[3].GetString(), fields[4].GetString());
5310 }while( result->NextRow() );
5311 SendSysMessage("===============================================================================");
5314 delete result;
5315 return true;
5318 bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
5320 Unit* target = getSelectedUnit();
5322 if(target)
5324 if(target->GetTypeId()!=TYPEID_UNIT)
5326 SendSysMessage(LANG_SELECT_CREATURE);
5327 SetSentErrorMessage(true);
5328 return false;
5331 if(target->isDead())
5332 ((Creature*)target)->Respawn();
5333 return true;
5336 Player* pl = m_session->GetPlayer();
5338 CellPair p(MaNGOS::ComputeCellPair(pl->GetPositionX(), pl->GetPositionY()));
5339 Cell cell(p);
5340 cell.data.Part.reserved = ALL_DISTRICT;
5341 cell.SetNoCreate();
5343 MaNGOS::RespawnDo u_do;
5344 MaNGOS::WorldObjectWorker<MaNGOS::RespawnDo> worker(u_do);
5346 TypeContainerVisitor<MaNGOS::WorldObjectWorker<MaNGOS::RespawnDo>, GridTypeMapContainer > obj_worker(worker);
5347 CellLock<GridReadGuard> cell_lock(cell, p);
5348 cell_lock->Visit(cell_lock, obj_worker, *MapManager::Instance().GetMap(pl->GetMapId(), pl));
5350 return true;
5353 bool ChatHandler::HandleFlyModeCommand(const char* args)
5355 if(!args)
5356 return false;
5358 Unit *unit = getSelectedUnit();
5359 if (!unit || (unit->GetTypeId() != TYPEID_PLAYER))
5360 unit = m_session->GetPlayer();
5362 WorldPacket data(12);
5363 if (strncmp(args, "on", 3) == 0)
5364 data.SetOpcode(SMSG_MOVE_SET_CAN_FLY);
5365 else if (strncmp(args, "off", 4) == 0)
5366 data.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY);
5367 else
5369 SendSysMessage(LANG_USE_BOL);
5370 return false;
5372 data.append(unit->GetPackGUID());
5373 data << uint32(0); // unknown
5374 unit->SendMessageToSet(&data, true);
5375 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS, unit->GetName(), args);
5376 return true;
5379 bool ChatHandler::HandleLoadPDumpCommand(const char *args)
5381 if(!args)
5382 return false;
5384 char * file = strtok((char*)args, " ");
5385 if(!file)
5386 return false;
5388 char * account = strtok(NULL, " ");
5389 if(!account)
5390 return false;
5392 std::string account_name = account;
5393 if(!AccountMgr::normilizeString(account_name))
5395 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5396 SetSentErrorMessage(true);
5397 return false;
5400 uint32 account_id = accmgr.GetId(account_name);
5401 if(!account_id)
5403 account_id = atoi(account); // use original string
5404 if(!account_id)
5406 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5407 SetSentErrorMessage(true);
5408 return false;
5412 if(!accmgr.GetName(account_id,account_name))
5414 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5415 SetSentErrorMessage(true);
5416 return false;
5419 char* guid_str = NULL;
5420 char* name_str = strtok(NULL, " ");
5422 std::string name;
5423 if(name_str)
5425 name = name_str;
5426 // normalize the name if specified and check if it exists
5427 if(!normalizePlayerName(name))
5429 PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
5430 SetSentErrorMessage(true);
5431 return false;
5434 if(!ObjectMgr::IsValidName(name,true))
5436 PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
5437 SetSentErrorMessage(true);
5438 return false;
5441 guid_str = strtok(NULL, " ");
5444 uint32 guid = 0;
5446 if(guid_str)
5448 guid = atoi(guid_str);
5449 if(!guid)
5451 PSendSysMessage(LANG_INVALID_CHARACTER_GUID);
5452 SetSentErrorMessage(true);
5453 return false;
5456 if(objmgr.GetPlayerAccountIdByGUID(guid))
5458 PSendSysMessage(LANG_CHARACTER_GUID_IN_USE,guid);
5459 SetSentErrorMessage(true);
5460 return false;
5464 switch(PlayerDumpReader().LoadDump(file, account_id, name, guid))
5466 case DUMP_SUCCESS:
5467 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS);
5468 break;
5469 case DUMP_FILE_OPEN_ERROR:
5470 PSendSysMessage(LANG_FILE_OPEN_FAIL,file);
5471 SetSentErrorMessage(true);
5472 return false;
5473 case DUMP_FILE_BROKEN:
5474 PSendSysMessage(LANG_DUMP_BROKEN,file);
5475 SetSentErrorMessage(true);
5476 return false;
5477 case DUMP_TOO_MANY_CHARS:
5478 PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL,account_name.c_str(),account_id);
5479 SetSentErrorMessage(true);
5480 return false;
5481 default:
5482 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED);
5483 SetSentErrorMessage(true);
5484 return false;
5487 return true;
5490 bool ChatHandler::HandleChangeEntryCommand(const char *args)
5492 if(!args)
5493 return false;
5495 uint32 newEntryNum = atoi(args);
5496 if(!newEntryNum)
5497 return false;
5499 Unit* unit = getSelectedUnit();
5500 if(!unit || unit->GetTypeId() != TYPEID_UNIT)
5502 SendSysMessage(LANG_SELECT_CREATURE);
5503 SetSentErrorMessage(true);
5504 return false;
5506 Creature* creature = (Creature*)unit;
5507 if(creature->UpdateEntry(newEntryNum))
5508 SendSysMessage(LANG_DONE);
5509 else
5510 SendSysMessage(LANG_ERROR);
5511 return true;
5514 bool ChatHandler::HandleWritePDumpCommand(const char *args)
5516 if(!args)
5517 return false;
5519 char* file = strtok((char*)args, " ");
5520 char* p2 = strtok(NULL, " ");
5522 if(!file || !p2)
5523 return false;
5525 uint32 guid = objmgr.GetPlayerGUIDByName(p2);
5526 if(!guid)
5527 guid = atoi(p2);
5529 if(!objmgr.GetPlayerAccountIdByGUID(guid))
5531 PSendSysMessage(LANG_PLAYER_NOT_FOUND);
5532 SetSentErrorMessage(true);
5533 return false;
5536 switch(PlayerDumpWriter().WriteDump(file, guid))
5538 case DUMP_SUCCESS:
5539 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS);
5540 break;
5541 case DUMP_FILE_OPEN_ERROR:
5542 PSendSysMessage(LANG_FILE_OPEN_FAIL,file);
5543 SetSentErrorMessage(true);
5544 return false;
5545 default:
5546 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED);
5547 SetSentErrorMessage(true);
5548 return false;
5551 return true;
5554 bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
5556 Unit* unit = getSelectedUnit();
5557 if(!unit)
5559 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5560 SetSentErrorMessage(true);
5561 return false;
5564 PSendSysMessage(LANG_MOVEGENS_LIST,(unit->GetTypeId()==TYPEID_PLAYER ? "Player" : "Creature" ),unit->GetGUIDLow());
5566 MotionMaster* mm = unit->GetMotionMaster();
5567 for(MotionMaster::const_iterator itr = mm->begin(); itr != mm->end(); ++itr)
5569 switch((*itr)->GetMovementGeneratorType())
5571 case IDLE_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_IDLE); break;
5572 case RANDOM_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_RANDOM); break;
5573 case WAYPOINT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_WAYPOINT); break;
5574 case ANIMAL_RANDOM_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_ANIMAL_RANDOM); break;
5575 case CONFUSED_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_CONFUSED); break;
5576 case TARGETED_MOTION_TYPE:
5578 if(unit->GetTypeId()==TYPEID_PLAYER)
5580 TargetedMovementGenerator<Player> const* mgen = static_cast<TargetedMovementGenerator<Player> const*>(*itr);
5581 Unit* target = mgen->GetTarget();
5582 if(target)
5583 PSendSysMessage(LANG_MOVEGENS_TARGETED_PLAYER,target->GetName(),target->GetGUIDLow());
5584 else
5585 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL);
5587 else
5589 TargetedMovementGenerator<Creature> const* mgen = static_cast<TargetedMovementGenerator<Creature> const*>(*itr);
5590 Unit* target = mgen->GetTarget();
5591 if(target)
5592 PSendSysMessage(LANG_MOVEGENS_TARGETED_CREATURE,target->GetName(),target->GetGUIDLow());
5593 else
5594 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL);
5596 break;
5598 case HOME_MOTION_TYPE:
5599 if(unit->GetTypeId()==TYPEID_UNIT)
5601 float x,y,z;
5602 (*itr)->GetDestination(x,y,z);
5603 PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE,x,y,z);
5605 else
5606 SendSysMessage(LANG_MOVEGENS_HOME_PLAYER);
5607 break;
5608 case FLIGHT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FLIGHT); break;
5609 case POINT_MOTION_TYPE:
5611 float x,y,z;
5612 (*itr)->GetDestination(x,y,z);
5613 PSendSysMessage(LANG_MOVEGENS_POINT,x,y,z);
5614 break;
5616 case FLEEING_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FEAR); break;
5617 case DISTRACT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_DISTRACT); break;
5618 default:
5619 PSendSysMessage(LANG_MOVEGENS_UNKNOWN,(*itr)->GetMovementGeneratorType());
5620 break;
5623 return true;
5626 bool ChatHandler::HandlePLimitCommand(const char *args)
5628 if(*args)
5630 char* param = strtok((char*)args, " ");
5631 if(!param)
5632 return false;
5634 int l = strlen(param);
5636 if( strncmp(param,"player",l) == 0 )
5637 sWorld.SetPlayerLimit(-SEC_PLAYER);
5638 else if(strncmp(param,"moderator",l) == 0 )
5639 sWorld.SetPlayerLimit(-SEC_MODERATOR);
5640 else if(strncmp(param,"gamemaster",l) == 0 )
5641 sWorld.SetPlayerLimit(-SEC_GAMEMASTER);
5642 else if(strncmp(param,"administrator",l) == 0 )
5643 sWorld.SetPlayerLimit(-SEC_ADMINISTRATOR);
5644 else if(strncmp(param,"reset",l) == 0 )
5645 sWorld.SetPlayerLimit( sConfig.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT) );
5646 else
5648 int val = atoi(param);
5649 if(val < -SEC_ADMINISTRATOR) val = -SEC_ADMINISTRATOR;
5651 sWorld.SetPlayerLimit(val);
5654 // kick all low security level players
5655 if(sWorld.GetPlayerAmountLimit() > SEC_PLAYER)
5656 sWorld.KickAllLess(sWorld.GetPlayerSecurityLimit());
5659 uint32 pLimit = sWorld.GetPlayerAmountLimit();
5660 AccountTypes allowedAccountType = sWorld.GetPlayerSecurityLimit();
5661 char const* secName = "";
5662 switch(allowedAccountType)
5664 case SEC_PLAYER: secName = "Player"; break;
5665 case SEC_MODERATOR: secName = "Moderator"; break;
5666 case SEC_GAMEMASTER: secName = "Gamemaster"; break;
5667 case SEC_ADMINISTRATOR: secName = "Administrator"; break;
5668 default: secName = "<unknown>"; break;
5671 PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit,secName);
5673 return true;
5676 bool ChatHandler::HandleCastCommand(const char* args)
5678 if(!*args)
5679 return false;
5681 Unit* target = getSelectedUnit();
5683 if(!target)
5685 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5686 SetSentErrorMessage(true);
5687 return false;
5690 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5691 uint32 spell = extractSpellIdFromLink((char*)args);
5692 if(!spell)
5693 return false;
5695 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
5696 if(!spellInfo)
5697 return false;
5699 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
5701 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
5702 SetSentErrorMessage(true);
5703 return false;
5706 char* trig_str = strtok(NULL, " ");
5707 if(trig_str)
5709 int l = strlen(trig_str);
5710 if(strncmp(trig_str,"triggered",l) != 0 )
5711 return false;
5714 bool triggered = (trig_str != NULL);
5716 m_session->GetPlayer()->CastSpell(target,spell,triggered);
5718 return true;
5721 bool ChatHandler::HandleCastBackCommand(const char* args)
5723 Creature* caster = getSelectedCreature();
5725 if(!caster)
5727 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5728 SetSentErrorMessage(true);
5729 return false;
5732 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
5733 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5734 uint32 spell = extractSpellIdFromLink((char*)args);
5735 if(!spell || !sSpellStore.LookupEntry(spell))
5736 return false;
5738 char* trig_str = strtok(NULL, " ");
5739 if(trig_str)
5741 int l = strlen(trig_str);
5742 if(strncmp(trig_str,"triggered",l) != 0 )
5743 return false;
5746 bool triggered = (trig_str != NULL);
5748 // update orientation at server
5749 caster->SetOrientation(caster->GetAngle(m_session->GetPlayer()));
5751 // and client
5752 WorldPacket data;
5753 caster->BuildHeartBeatMsg(&data);
5754 caster->SendMessageToSet(&data,true);
5756 caster->CastSpell(m_session->GetPlayer(),spell,false);
5758 return true;
5761 bool ChatHandler::HandleCastDistCommand(const char* args)
5763 if(!*args)
5764 return false;
5766 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5767 uint32 spell = extractSpellIdFromLink((char*)args);
5768 if(!spell)
5769 return false;
5771 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
5772 if(!spellInfo)
5773 return false;
5775 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
5777 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
5778 SetSentErrorMessage(true);
5779 return false;
5782 char *distStr = strtok(NULL, " ");
5784 float dist = 0;
5786 if(distStr)
5787 sscanf(distStr, "%f", &dist);
5789 char* trig_str = strtok(NULL, " ");
5790 if(trig_str)
5792 int l = strlen(trig_str);
5793 if(strncmp(trig_str,"triggered",l) != 0 )
5794 return false;
5797 bool triggered = (trig_str != NULL);
5799 float x,y,z;
5800 m_session->GetPlayer()->GetClosePoint(x,y,z,dist);
5802 m_session->GetPlayer()->CastSpell(x,y,z,spell,triggered);
5803 return true;
5806 bool ChatHandler::HandleCastTargetCommand(const char* args)
5808 Creature* caster = getSelectedCreature();
5810 if(!caster)
5812 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5813 SetSentErrorMessage(true);
5814 return false;
5817 if(!caster->getVictim())
5819 SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM);
5820 SetSentErrorMessage(true);
5821 return false;
5824 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5825 uint32 spell = extractSpellIdFromLink((char*)args);
5826 if(!spell || !sSpellStore.LookupEntry(spell))
5827 return false;
5829 char* trig_str = strtok(NULL, " ");
5830 if(trig_str)
5832 int l = strlen(trig_str);
5833 if(strncmp(trig_str,"triggered",l) != 0 )
5834 return false;
5837 bool triggered = (trig_str != NULL);
5839 // update orientation at server
5840 caster->SetOrientation(caster->GetAngle(m_session->GetPlayer()));
5842 // and client
5843 WorldPacket data;
5844 caster->BuildHeartBeatMsg(&data);
5845 caster->SendMessageToSet(&data,true);
5847 caster->CastSpell(caster->getVictim(),spell,false);
5849 return true;
5853 ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
5854 Without this function 3rd party scripting library will get linking errors (unresolved external)
5855 when attempting to use the PointMovementGenerator
5857 bool ChatHandler::HandleComeToMeCommand(const char *args)
5859 Creature* caster = getSelectedCreature();
5861 if(!caster)
5863 SendSysMessage(LANG_SELECT_CREATURE);
5864 SetSentErrorMessage(true);
5865 return false;
5868 char* newFlagStr = strtok((char*)args, " ");
5870 if(!newFlagStr)
5871 return false;
5873 uint32 newFlags = atoi(newFlagStr);
5875 caster->SetUnitMovementFlags(newFlags);
5877 Player* pl = m_session->GetPlayer();
5879 caster->GetMotionMaster()->MovePoint(0, pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ());
5880 return true;
5883 bool ChatHandler::HandleCastSelfCommand(const char* args)
5885 if(!*args)
5886 return false;
5888 Unit* target = getSelectedUnit();
5890 if(!target)
5892 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5893 SetSentErrorMessage(true);
5894 return false;
5897 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5898 uint32 spell = extractSpellIdFromLink((char*)args);
5899 if(!spell)
5900 return false;
5902 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
5903 if(!spellInfo)
5904 return false;
5906 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
5908 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
5909 SetSentErrorMessage(true);
5910 return false;
5913 target->CastSpell(target,spell,false);
5915 return true;
5918 std::string GetTimeString(uint32 time)
5920 uint16 days = time / DAY, hours = (time % DAY) / HOUR, minute = (time % HOUR) / MINUTE;
5921 std::ostringstream ss;
5922 if(days) ss << days << "d ";
5923 if(hours) ss << hours << "h ";
5924 ss << minute << "m";
5925 return ss.str();
5928 bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
5930 Player* player = getSelectedPlayer();
5931 if (!player) player = m_session->GetPlayer();
5932 uint32 counter = 0;
5933 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; i++)
5935 Player::BoundInstancesMap &binds = player->GetBoundInstances(i);
5936 for(Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end(); ++itr)
5938 InstanceSave *save = itr->second.save;
5939 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
5940 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());
5941 counter++;
5944 PSendSysMessage("player binds: %d", counter);
5945 counter = 0;
5946 Group *group = player->GetGroup();
5947 if(group)
5949 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; i++)
5951 Group::BoundInstancesMap &binds = group->GetBoundInstances(i);
5952 for(Group::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end(); ++itr)
5954 InstanceSave *save = itr->second.save;
5955 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
5956 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());
5957 counter++;
5961 PSendSysMessage("group binds: %d", counter);
5963 return true;
5966 bool ChatHandler::HandleInstanceUnbindCommand(const char* args)
5968 if(!*args)
5969 return false;
5971 std::string cmd = args;
5972 if(cmd == "all")
5974 Player* player = getSelectedPlayer();
5975 if (!player) player = m_session->GetPlayer();
5976 uint32 counter = 0;
5977 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; i++)
5979 Player::BoundInstancesMap &binds = player->GetBoundInstances(i);
5980 for(Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end();)
5982 if(itr->first != player->GetMapId())
5984 InstanceSave *save = itr->second.save;
5985 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
5986 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());
5987 player->UnbindInstance(itr, i);
5988 counter++;
5990 else
5991 ++itr;
5994 PSendSysMessage("instances unbound: %d", counter);
5996 return true;
5999 bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
6001 PSendSysMessage("instances loaded: %d", MapManager::Instance().GetNumInstances());
6002 PSendSysMessage("players in instances: %d", MapManager::Instance().GetNumPlayersInInstances());
6003 PSendSysMessage("instance saves: %d", sInstanceSaveManager.GetNumInstanceSaves());
6004 PSendSysMessage("players bound: %d", sInstanceSaveManager.GetNumBoundPlayersTotal());
6005 PSendSysMessage("groups bound: %d", sInstanceSaveManager.GetNumBoundGroupsTotal());
6006 return true;
6009 bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
6011 Player* pl = m_session->GetPlayer();
6013 Map* map = pl->GetMap();
6014 if (!map->IsDungeon())
6016 PSendSysMessage("Map is not a dungeon.");
6017 SetSentErrorMessage(true);
6018 return false;
6021 if (!((InstanceMap*)map)->GetInstanceData())
6023 PSendSysMessage("Map has no instance data.");
6024 SetSentErrorMessage(true);
6025 return false;
6028 ((InstanceMap*)map)->GetInstanceData()->SaveToDB();
6029 return true;
6032 /// Display the list of GMs
6033 bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
6035 ///- Get the accounts with GM Level >0
6036 QueryResult *result = loginDatabase.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
6037 if(result)
6039 SendSysMessage(LANG_GMLIST);
6040 SendSysMessage("========================");
6041 SendSysMessage(LANG_GMLIST_HEADER);
6042 SendSysMessage("========================");
6044 ///- Circle through them. Display username and GM level
6047 Field *fields = result->Fetch();
6048 PSendSysMessage("|%15s|%6s|", fields[0].GetString(),fields[1].GetString());
6049 }while( result->NextRow() );
6051 PSendSysMessage("========================");
6052 delete result;
6054 else
6055 PSendSysMessage(LANG_GMLIST_EMPTY);
6056 return true;
6059 /// Define the 'Message of the day' for the realm
6060 bool ChatHandler::HandleServerSetMotdCommand(const char* args)
6062 sWorld.SetMotd(args);
6063 PSendSysMessage(LANG_MOTD_NEW, args);
6064 return true;
6067 /// Set/Unset the expansion level for an account
6068 bool ChatHandler::HandleAccountSetAddonCommand(const char* args)
6070 ///- Get the command line arguments
6071 char *szAcc = strtok((char*)args," ");
6072 char *szExp = strtok(NULL," ");
6074 if(!szAcc)
6075 return false;
6077 std::string account_name;
6078 uint32 account_id;
6080 if(!szExp)
6082 Player* player = getSelectedPlayer();
6083 if(!player)
6084 return false;
6086 account_id = player->GetSession()->GetAccountId();
6087 accmgr.GetName(account_id,account_name);
6088 szExp = szAcc;
6090 else
6092 ///- Convert Account name to Upper Format
6093 account_name = szAcc;
6094 if(!AccountMgr::normilizeString(account_name))
6096 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
6097 SetSentErrorMessage(true);
6098 return false;
6101 account_id = accmgr.GetId(account_name);
6102 if(!account_id)
6104 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
6105 SetSentErrorMessage(true);
6106 return false;
6110 int lev=atoi(szExp); //get int anyway (0 if error)
6111 if(lev < 0)
6112 return false;
6114 // No SQL injection
6115 loginDatabase.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev,account_id);
6116 PSendSysMessage(LANG_ACCOUNT_SETADDON,account_name.c_str(),account_id,lev);
6117 return true;
6120 /// Send a message to a player in game
6121 bool ChatHandler::HandleSendMessageCommand(const char* args)
6123 ///- Get the command line arguments
6124 char* name_str = strtok((char*)args, " ");
6125 char* msg_str = strtok(NULL, "");
6127 if(!name_str || !msg_str)
6128 return false;
6130 std::string name = name_str;
6132 if(!normalizePlayerName(name))
6133 return false;
6135 ///- Find the player and check that he is not logging out.
6136 Player *rPlayer = objmgr.GetPlayer(name.c_str());
6137 if(!rPlayer)
6139 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6140 SetSentErrorMessage(true);
6141 return false;
6144 if(rPlayer->GetSession()->isLogingOut())
6146 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6147 SetSentErrorMessage(true);
6148 return false;
6151 ///- Send the message
6152 //Use SendAreaTriggerMessage for fastest delivery.
6153 rPlayer->GetSession()->SendAreaTriggerMessage("%s", msg_str);
6154 rPlayer->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
6156 //Confirmation message
6157 PSendSysMessage(LANG_SENDMESSAGE,name.c_str(),msg_str);
6158 return true;