[sql/updates/2008_10_23_01_mangos_command.sql sql/updates/2008_10_23_02_mangos_mangos...
[auctionmangos.git] / src / game / Level3.cpp
blobde6a10072ff1ccb003eff375f8b45fafa3189fc0
1 /*
2 * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "Common.h"
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
23 #include "World.h"
24 #include "ObjectMgr.h"
25 #include "AccountMgr.h"
26 #include "PlayerDump.h"
27 #include "SpellMgr.h"
28 #include "Player.h"
29 #include "Opcodes.h"
30 #include "GameObject.h"
31 #include "Chat.h"
32 #include "Log.h"
33 #include "Guild.h"
34 #include "ObjectAccessor.h"
35 #include "MapManager.h"
36 #include "SpellAuras.h"
37 #include "ScriptCalls.h"
38 #include "Language.h"
39 #include "GridNotifiersImpl.h"
40 #include "CellImpl.h"
41 #include "Weather.h"
42 #include "PointMovementGenerator.h"
43 #include "TargetedMovementGenerator.h"
44 #include "SkillDiscovery.h"
45 #include "SkillExtraItems.h"
46 #include "SystemConfig.h"
47 #include "Config/ConfigEnv.h"
48 #include "Util.h"
49 #include "ItemEnchantmentMgr.h"
50 #include "InstanceSaveMgr.h"
51 #include "InstanceData.h"
52 #include "AccountMgr.h"
54 //reload commands
55 bool ChatHandler::HandleReloadCommand(const char* arg)
57 // this is error catcher for wrong table name in .reload commands
58 PSendSysMessage("Db table with name starting from '%s' not found and can't be reloaded.",arg);
59 SetSentErrorMessage(true);
60 return false;
63 bool ChatHandler::HandleReloadAllCommand(const char*)
65 HandleReloadAreaTriggerTeleportCommand("");
66 HandleReloadSkillFishingBaseLevelCommand("");
68 HandleReloadAllAreaCommand("");
69 HandleReloadAllLootCommand("");
70 HandleReloadAllNpcCommand("");
71 HandleReloadAllQuestCommand("");
72 HandleReloadAllSpellCommand("");
73 HandleReloadAllItemCommand("");
74 HandleReloadAllLocalesCommand("");
76 HandleReloadCommandCommand("");
77 HandleReloadReservedNameCommand("");
78 HandleReloadMangosStringCommand("");
79 HandleReloadGameTeleCommand("");
80 return true;
83 bool ChatHandler::HandleReloadAllAreaCommand(const char*)
85 //HandleReloadQuestAreaTriggersCommand(""); -- reloaded in HandleReloadAllQuestCommand
86 HandleReloadAreaTriggerTeleportCommand("");
87 HandleReloadAreaTriggerTavernCommand("");
88 HandleReloadGameGraveyardZoneCommand("");
89 return true;
92 bool ChatHandler::HandleReloadAllLootCommand(const char*)
94 sLog.outString( "Re-Loading Loot Tables..." );
95 LoadLootTables();
96 SendGlobalSysMessage("DB tables `*_loot_template` reloaded.");
97 return true;
100 bool ChatHandler::HandleReloadAllNpcCommand(const char* /*args*/)
102 HandleReloadNpcGossipCommand("a");
103 HandleReloadNpcTrainerCommand("a");
104 HandleReloadNpcVendorCommand("a");
105 return true;
108 bool ChatHandler::HandleReloadAllQuestCommand(const char* /*args*/)
110 HandleReloadQuestAreaTriggersCommand("a");
111 HandleReloadQuestTemplateCommand("a");
113 sLog.outString( "Re-Loading Quests Relations..." );
114 objmgr.LoadQuestRelations();
115 SendGlobalSysMessage("DB tables `*_questrelation` and `*_involvedrelation` reloaded.");
116 return true;
119 bool ChatHandler::HandleReloadAllScriptsCommand(const char*)
121 if(sWorld.IsScriptScheduled())
123 PSendSysMessage("DB scripts used currently, please attempt reload later.");
124 SetSentErrorMessage(true);
125 return false;
128 sLog.outString( "Re-Loading Scripts..." );
129 HandleReloadGameObjectScriptsCommand("a");
130 HandleReloadEventScriptsCommand("a");
131 HandleReloadQuestEndScriptsCommand("a");
132 HandleReloadQuestStartScriptsCommand("a");
133 HandleReloadSpellScriptsCommand("a");
134 SendGlobalSysMessage("DB tables `*_scripts` reloaded.");
135 return true;
138 bool ChatHandler::HandleReloadAllSpellCommand(const char*)
140 HandleReloadSkillDiscoveryTemplateCommand("a");
141 HandleReloadSkillExtraItemTemplateCommand("a");
142 HandleReloadSpellAffectCommand("a");
143 HandleReloadSpellChainCommand("a");
144 HandleReloadSpellElixirCommand("a");
145 HandleReloadSpellLearnSpellCommand("a");
146 HandleReloadSpellProcEventCommand("a");
147 HandleReloadSpellScriptTargetCommand("a");
148 HandleReloadSpellTargetPositionCommand("a");
149 HandleReloadSpellThreatsCommand("a");
150 HandleReloadSpellPetAurasCommand("a");
151 return true;
154 bool ChatHandler::HandleReloadAllItemCommand(const char*)
156 HandleReloadPageTextsCommand("a");
157 HandleReloadItemEnchantementsCommand("a");
158 return true;
161 bool ChatHandler::HandleReloadAllLocalesCommand(const char* args)
163 HandleReloadLocalesCreatureCommand("a");
164 HandleReloadLocalesGameobjectCommand("a");
165 HandleReloadLocalesItemCommand("a");
166 HandleReloadLocalesNpcTextCommand("a");
167 HandleReloadLocalesPageTextCommand("a");
168 HandleReloadLocalesQuestCommand("a");
169 return true;
172 bool ChatHandler::HandleReloadConfigCommand(const char* arg)
174 sLog.outString( "Re-Loading config settings..." );
175 sWorld.LoadConfigSettings(true);
176 SendGlobalSysMessage("World config settings reloaded.");
177 return true;
180 bool ChatHandler::HandleReloadAreaTriggerTavernCommand(const char*)
182 sLog.outString( "Re-Loading Tavern Area Triggers..." );
183 objmgr.LoadTavernAreaTriggers();
184 SendGlobalSysMessage("DB table `areatrigger_tavern` reloaded.");
185 return true;
188 bool ChatHandler::HandleReloadAreaTriggerTeleportCommand(const char*)
190 sLog.outString( "Re-Loading AreaTrigger teleport definitions..." );
191 objmgr.LoadAreaTriggerTeleports();
192 SendGlobalSysMessage("DB table `areatrigger_teleport` reloaded.");
193 return true;
196 bool ChatHandler::HandleReloadCommandCommand(const char*)
198 load_command_table = true;
199 SendGlobalSysMessage("DB table `command` will be reloaded at next chat command use.");
200 return true;
203 bool ChatHandler::HandleReloadCreatureQuestRelationsCommand(const char*)
205 sLog.outString( "Loading Quests Relations... (`creature_questrelation`)" );
206 objmgr.LoadCreatureQuestRelations();
207 SendGlobalSysMessage("DB table `creature_questrelation` (creature quest givers) reloaded.");
208 return true;
211 bool ChatHandler::HandleReloadCreatureQuestInvRelationsCommand(const char*)
213 sLog.outString( "Loading Quests Relations... (`creature_involvedrelation`)" );
214 objmgr.LoadCreatureInvolvedRelations();
215 SendGlobalSysMessage("DB table `creature_involvedrelation` (creature quest takers) reloaded.");
216 return true;
219 bool ChatHandler::HandleReloadGOQuestRelationsCommand(const char*)
221 sLog.outString( "Loading Quests Relations... (`gameobject_questrelation`)" );
222 objmgr.LoadGameobjectQuestRelations();
223 SendGlobalSysMessage("DB table `gameobject_questrelation` (gameobject quest givers) reloaded.");
224 return true;
227 bool ChatHandler::HandleReloadGOQuestInvRelationsCommand(const char*)
229 sLog.outString( "Loading Quests Relations... (`gameobject_involvedrelation`)" );
230 objmgr.LoadGameobjectInvolvedRelations();
231 SendGlobalSysMessage("DB table `gameobject_involvedrelation` (gameobject quest takers) reloaded.");
232 return true;
235 bool ChatHandler::HandleReloadQuestAreaTriggersCommand(const char*)
237 sLog.outString( "Re-Loading Quest Area Triggers..." );
238 objmgr.LoadQuestAreaTriggers();
239 SendGlobalSysMessage("DB table `areatrigger_involvedrelation` (quest area triggers) reloaded.");
240 return true;
243 bool ChatHandler::HandleReloadQuestTemplateCommand(const char*)
245 sLog.outString( "Re-Loading Quest Templates..." );
246 objmgr.LoadQuests();
247 SendGlobalSysMessage("DB table `quest_template` (quest definitions) reloaded.");
248 return true;
251 bool ChatHandler::HandleReloadLootTemplatesCreatureCommand(const char*)
253 sLog.outString( "Re-Loading Loot Tables... (`creature_loot_template`)" );
254 LoadLootTemplates_Creature();
255 LootTemplates_Creature.CheckLootRefs();
256 SendGlobalSysMessage("DB table `creature_loot_template` reloaded.");
257 return true;
260 bool ChatHandler::HandleReloadLootTemplatesDisenchantCommand(const char*)
262 sLog.outString( "Re-Loading Loot Tables... (`disenchant_loot_template`)" );
263 LoadLootTemplates_Disenchant();
264 LootTemplates_Disenchant.CheckLootRefs();
265 SendGlobalSysMessage("DB table `disenchant_loot_template` reloaded.");
266 return true;
269 bool ChatHandler::HandleReloadLootTemplatesFishingCommand(const char*)
271 sLog.outString( "Re-Loading Loot Tables... (`fishing_loot_template`)" );
272 LoadLootTemplates_Fishing();
273 LootTemplates_Fishing.CheckLootRefs();
274 SendGlobalSysMessage("DB table `fishing_loot_template` reloaded.");
275 return true;
278 bool ChatHandler::HandleReloadLootTemplatesGameobjectCommand(const char*)
280 sLog.outString( "Re-Loading Loot Tables... (`gameobject_loot_template`)" );
281 LoadLootTemplates_Gameobject();
282 LootTemplates_Gameobject.CheckLootRefs();
283 SendGlobalSysMessage("DB table `gameobject_loot_template` reloaded.");
284 return true;
287 bool ChatHandler::HandleReloadLootTemplatesItemCommand(const char*)
289 sLog.outString( "Re-Loading Loot Tables... (`item_loot_template`)" );
290 LoadLootTemplates_Item();
291 LootTemplates_Item.CheckLootRefs();
292 SendGlobalSysMessage("DB table `item_loot_template` reloaded.");
293 return true;
296 bool ChatHandler::HandleReloadLootTemplatesPickpocketingCommand(const char*)
298 sLog.outString( "Re-Loading Loot Tables... (`pickpocketing_loot_template`)" );
299 LoadLootTemplates_Pickpocketing();
300 LootTemplates_Pickpocketing.CheckLootRefs();
301 SendGlobalSysMessage("DB table `pickpocketing_loot_template` reloaded.");
302 return true;
305 bool ChatHandler::HandleReloadLootTemplatesProspectingCommand(const char*)
307 sLog.outString( "Re-Loading Loot Tables... (`prospecting_loot_template`)" );
308 LoadLootTemplates_Prospecting();
309 LootTemplates_Prospecting.CheckLootRefs();
310 SendGlobalSysMessage("DB table `prospecting_loot_template` reloaded.");
311 return true;
314 bool ChatHandler::HandleReloadLootTemplatesQuestMailCommand(const char*)
316 sLog.outString( "Re-Loading Loot Tables... (`quest_mail_loot_template`)" );
317 LoadLootTemplates_QuestMail();
318 LootTemplates_QuestMail.CheckLootRefs();
319 SendGlobalSysMessage("DB table `quest_mail_loot_template` reloaded.");
320 return true;
323 bool ChatHandler::HandleReloadLootTemplatesReferenceCommand(const char*)
325 sLog.outString( "Re-Loading Loot Tables... (`reference_loot_template`)" );
326 LoadLootTemplates_Reference();
327 SendGlobalSysMessage("DB table `reference_loot_template` reloaded.");
328 return true;
331 bool ChatHandler::HandleReloadLootTemplatesSkinningCommand(const char*)
333 sLog.outString( "Re-Loading Loot Tables... (`skinning_loot_template`)" );
334 LoadLootTemplates_Skinning();
335 LootTemplates_Skinning.CheckLootRefs();
336 SendGlobalSysMessage("DB table `skinning_loot_template` reloaded.");
337 return true;
340 bool ChatHandler::HandleReloadMangosStringCommand(const char*)
342 sLog.outString( "Re-Loading mangos_string Table!" );
343 objmgr.LoadMangosStrings();
344 SendGlobalSysMessage("DB table `mangos_string` reloaded.");
345 return true;
348 bool ChatHandler::HandleReloadNpcGossipCommand(const char*)
350 sLog.outString( "Re-Loading `npc_gossip` Table!" );
351 objmgr.LoadNpcTextId();
352 SendGlobalSysMessage("DB table `npc_gossip` reloaded.");
353 return true;
356 bool ChatHandler::HandleReloadNpcTrainerCommand(const char*)
358 sLog.outString( "Re-Loading `npc_trainer` Table!" );
359 objmgr.LoadTrainerSpell();
360 SendGlobalSysMessage("DB table `npc_trainer` reloaded.");
361 return true;
364 bool ChatHandler::HandleReloadNpcVendorCommand(const char*)
366 sLog.outString( "Re-Loading `npc_vendor` Table!" );
367 objmgr.LoadVendors();
368 SendGlobalSysMessage("DB table `npc_vendor` reloaded.");
369 return true;
372 bool ChatHandler::HandleReloadReservedNameCommand(const char*)
374 sLog.outString( "Loading ReservedNames... (`reserved_name`)" );
375 objmgr.LoadReservedPlayersNames();
376 SendGlobalSysMessage("DB table `reserved_name` (player reserved names) reloaded.");
377 return true;
380 bool ChatHandler::HandleReloadSkillDiscoveryTemplateCommand(const char* /*args*/)
382 sLog.outString( "Re-Loading Skill Discovery Table..." );
383 LoadSkillDiscoveryTable();
384 SendGlobalSysMessage("DB table `skill_discovery_template` (recipes discovered at crafting) reloaded.");
385 return true;
388 bool ChatHandler::HandleReloadSkillExtraItemTemplateCommand(const char* /*args*/)
390 sLog.outString( "Re-Loading Skill Extra Item Table..." );
391 LoadSkillExtraItemTable();
392 SendGlobalSysMessage("DB table `skill_extra_item_template` (extra item creation when crafting) reloaded.");
393 return true;
396 bool ChatHandler::HandleReloadSkillFishingBaseLevelCommand(const char* /*args*/)
398 sLog.outString( "Re-Loading Skill Fishing base level requirements..." );
399 objmgr.LoadFishingBaseSkillLevel();
400 SendGlobalSysMessage("DB table `skill_fishing_base_level` (fishing base level for zone/subzone) reloaded.");
401 return true;
404 bool ChatHandler::HandleReloadSpellAffectCommand(const char*)
406 sLog.outString( "Re-Loading SpellAffect definitions..." );
407 spellmgr.LoadSpellAffects();
408 SendGlobalSysMessage("DB table `spell_affect` (spell mods apply requirements) reloaded.");
409 return true;
412 bool ChatHandler::HandleReloadSpellChainCommand(const char*)
414 sLog.outString( "Re-Loading Spell Chain Data... " );
415 spellmgr.LoadSpellChains();
416 SendGlobalSysMessage("DB table `spell_chain` (spell ranks) reloaded.");
417 return true;
420 bool ChatHandler::HandleReloadSpellElixirCommand(const char*)
422 sLog.outString( "Re-Loading Spell Elixir types..." );
423 spellmgr.LoadSpellElixirs();
424 SendGlobalSysMessage("DB table `spell_elixir` (spell exlixir types) reloaded.");
425 return true;
428 bool ChatHandler::HandleReloadSpellLearnSpellCommand(const char*)
430 sLog.outString( "Re-Loading Spell Learn Spells..." );
431 spellmgr.LoadSpellLearnSpells();
432 SendGlobalSysMessage("DB table `spell_learn_spell` reloaded.");
433 return true;
436 bool ChatHandler::HandleReloadSpellProcEventCommand(const char*)
438 sLog.outString( "Re-Loading Spell Proc Event conditions..." );
439 spellmgr.LoadSpellProcEvents();
440 SendGlobalSysMessage("DB table `spell_proc_event` (spell proc trigger requirements) reloaded.");
441 return true;
444 bool ChatHandler::HandleReloadSpellScriptTargetCommand(const char*)
446 sLog.outString( "Re-Loading SpellsScriptTarget..." );
447 spellmgr.LoadSpellScriptTarget();
448 SendGlobalSysMessage("DB table `spell_script_target` (spell targets selection in case specific creature/GO requirements) reloaded.");
449 return true;
452 bool ChatHandler::HandleReloadSpellTargetPositionCommand(const char*)
454 sLog.outString( "Re-Loading Spell target coordinates..." );
455 spellmgr.LoadSpellTargetPositions();
456 SendGlobalSysMessage("DB table `spell_target_position` (destination coordinates for spell targets) reloaded.");
457 return true;
460 bool ChatHandler::HandleReloadSpellThreatsCommand(const char*)
462 sLog.outString( "Re-Loading Aggro Spells Definitions...");
463 spellmgr.LoadSpellThreats();
464 SendGlobalSysMessage("DB table `spell_threat` (spell aggro definitions) reloaded.");
465 return true;
468 bool ChatHandler::HandleReloadSpellPetAurasCommand(const char*)
470 sLog.outString( "Re-Loading Spell pet auras...");
471 spellmgr.LoadSpellPetAuras();
472 SendGlobalSysMessage("DB table `spell_pet_auras` reloaded.");
473 return true;
476 bool ChatHandler::HandleReloadPageTextsCommand(const char*)
478 sLog.outString( "Re-Loading Page Texts..." );
479 objmgr.LoadPageTexts();
480 SendGlobalSysMessage("DB table `page_texts` reloaded.");
481 return true;
484 bool ChatHandler::HandleReloadItemEnchantementsCommand(const char*)
486 sLog.outString( "Re-Loading Item Random Enchantments Table..." );
487 LoadRandomEnchantmentsTable();
488 SendGlobalSysMessage("DB table `item_enchantment_template` reloaded.");
489 return true;
492 bool ChatHandler::HandleReloadGameObjectScriptsCommand(const char* arg)
494 if(sWorld.IsScriptScheduled())
496 SendSysMessage("DB scripts used currently, please attempt reload later.");
497 SetSentErrorMessage(true);
498 return false;
501 if(*arg!='a')
502 sLog.outString( "Re-Loading Scripts from `gameobject_scripts`...");
504 objmgr.LoadGameObjectScripts();
506 if(*arg!='a')
507 SendGlobalSysMessage("DB table `gameobject_scripts` reloaded.");
509 return true;
512 bool ChatHandler::HandleReloadEventScriptsCommand(const char* arg)
514 if(sWorld.IsScriptScheduled())
516 SendSysMessage("DB scripts used currently, please attempt reload later.");
517 SetSentErrorMessage(true);
518 return false;
521 if(*arg!='a')
522 sLog.outString( "Re-Loading Scripts from `event_scripts`...");
524 objmgr.LoadEventScripts();
526 if(*arg!='a')
527 SendGlobalSysMessage("DB table `event_scripts` reloaded.");
529 return true;
532 bool ChatHandler::HandleReloadQuestEndScriptsCommand(const char* arg)
534 if(sWorld.IsScriptScheduled())
536 SendSysMessage("DB scripts used currently, please attempt reload later.");
537 SetSentErrorMessage(true);
538 return false;
541 if(*arg!='a')
542 sLog.outString( "Re-Loading Scripts from `quest_end_scripts`...");
544 objmgr.LoadQuestEndScripts();
546 if(*arg!='a')
547 SendGlobalSysMessage("DB table `quest_end_scripts` reloaded.");
549 return true;
552 bool ChatHandler::HandleReloadQuestStartScriptsCommand(const char* arg)
554 if(sWorld.IsScriptScheduled())
556 SendSysMessage("DB scripts used currently, please attempt reload later.");
557 SetSentErrorMessage(true);
558 return false;
561 if(*arg!='a')
562 sLog.outString( "Re-Loading Scripts from `quest_start_scripts`...");
564 objmgr.LoadQuestStartScripts();
566 if(*arg!='a')
567 SendGlobalSysMessage("DB table `quest_start_scripts` reloaded.");
569 return true;
572 bool ChatHandler::HandleReloadSpellScriptsCommand(const char* arg)
574 if(sWorld.IsScriptScheduled())
576 SendSysMessage("DB scripts used currently, please attempt reload later.");
577 SetSentErrorMessage(true);
578 return false;
581 if(*arg!='a')
582 sLog.outString( "Re-Loading Scripts from `spell_scripts`...");
584 objmgr.LoadSpellScripts();
586 if(*arg!='a')
587 SendGlobalSysMessage("DB table `spell_scripts` reloaded.");
589 return true;
592 bool ChatHandler::HandleReloadGameGraveyardZoneCommand(const char* /*arg*/)
594 sLog.outString( "Re-Loading Graveyard-zone links...");
596 objmgr.LoadGraveyardZones();
598 SendGlobalSysMessage("DB table `game_graveyard_zone` reloaded.");
600 return true;
603 bool ChatHandler::HandleReloadGameTeleCommand(const char* /*arg*/)
605 sLog.outString( "Re-Loading Game Tele coordinates...");
607 objmgr.LoadGameTele();
609 SendGlobalSysMessage("DB table `game_tele` reloaded.");
611 return true;
614 bool ChatHandler::HandleReloadLocalesCreatureCommand(const char* /*arg*/)
616 sLog.outString( "Re-Loading Locales Creature ...");
617 objmgr.LoadCreatureLocales();
618 SendGlobalSysMessage("DB table `locales_creature` reloaded.");
619 return true;
622 bool ChatHandler::HandleReloadLocalesGameobjectCommand(const char* /*arg*/)
624 sLog.outString( "Re-Loading Locales Gameobject ... ");
625 objmgr.LoadGameObjectLocales();
626 SendGlobalSysMessage("DB table `locales_gameobject` reloaded.");
627 return true;
630 bool ChatHandler::HandleReloadLocalesItemCommand(const char* /*arg*/)
632 sLog.outString( "Re-Loading Locales Item ... ");
633 objmgr.LoadItemLocales();
634 SendGlobalSysMessage("DB table `locales_item` reloaded.");
635 return true;
638 bool ChatHandler::HandleReloadLocalesNpcTextCommand(const char* /*arg*/)
640 sLog.outString( "Re-Loading Locales NPC Text ... ");
641 objmgr.LoadNpcTextLocales();
642 SendGlobalSysMessage("DB table `locales_npc_text` reloaded.");
643 return true;
646 bool ChatHandler::HandleReloadLocalesPageTextCommand(const char* /*arg*/)
648 sLog.outString( "Re-Loading Locales Page Text ... ");
649 objmgr.LoadPageTextLocales();
650 SendGlobalSysMessage("DB table `locales_page_text` reloaded.");
651 return true;
654 bool ChatHandler::HandleReloadLocalesQuestCommand(const char* /*arg*/)
656 sLog.outString( "Re-Loading Locales Quest ... ");
657 objmgr.LoadQuestLocales();
658 SendGlobalSysMessage("DB table `locales_quest` reloaded.");
659 return true;
662 bool ChatHandler::HandleLoadScriptsCommand(const char* args)
664 if(!LoadScriptingModule(args)) return true;
666 sWorld.SendWorldText(LANG_SCRIPTS_RELOADED);
667 return true;
670 bool ChatHandler::HandleAccountSetGmLevelCommand(const char* args)
672 char* arg1 = strtok((char*)args, " ");
673 if( !arg1 )
674 return false;
676 char* arg2 = strtok(NULL, " ");
678 std::string targetAccountName;
679 uint32 targetAccountId = 0;
680 uint32 targetSecurity = 0;
682 /// only target player different from self allowed (if targetPlayer!=NULL then not console)
683 Player* targetPlayer = getSelectedPlayer();
684 if(targetPlayer && m_session->GetPlayer()!=targetPlayer)
686 /// wrong command syntax or unexpected targeting
687 if(arg2)
688 return false;
690 targetAccountId = targetPlayer->GetSession()->GetAccountId();
691 targetSecurity = targetPlayer->GetSession()->GetSecurity();
692 if(!accmgr.GetName(targetAccountId,targetAccountName))
694 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,targetAccountName.c_str());
695 SetSentErrorMessage(true);
696 return false;
699 else
701 targetAccountName = arg1;
702 if(!AccountMgr::normilizeString(targetAccountName))
704 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,targetAccountName.c_str());
705 SetSentErrorMessage(true);
706 return false;
709 targetAccountId = accmgr.GetId(targetAccountName);
710 targetSecurity = accmgr.GetSecurity(targetAccountId);
713 int32 gm = (int32)atoi(arg2);
714 if ( gm < SEC_PLAYER || gm > SEC_ADMINISTRATOR )
716 SendSysMessage(LANG_BAD_VALUE);
717 SetSentErrorMessage(true);
718 return false;
721 /// m_session==NULL only for console
722 uint32 plSecurity = m_session ? m_session->GetSecurity() : SEC_CONSOLE;
724 /// can set security level only for target with less security and to less security that we have
725 /// This is also reject self apply in fact
726 if(targetSecurity >= plSecurity || uint32(gm) >= plSecurity )
728 SendSysMessage(LANG_YOURS_SECURITY_IS_LOW);
729 SetSentErrorMessage(true);
730 return false;
733 if(targetPlayer)
735 ChatHandler(targetPlayer).PSendSysMessage(LANG_YOURS_SECURITY_CHANGED,m_session->GetPlayer()->GetName(), gm);
736 targetPlayer->GetSession()->SetSecurity(gm);
739 PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetAccountName.c_str(), gm);
740 loginDatabase.PExecute("UPDATE account SET gmlevel = '%i' WHERE id = '%u'", gm, targetAccountId);
742 return true;
745 /// Set password for account
746 bool ChatHandler::HandleAccountSetPasswordCommand(const char* args)
748 if(!*args)
749 return false;
751 ///- Get the command line arguments
752 char *szAccount = strtok ((char*)args," ");
753 char *szPassword1 = strtok (NULL," ");
754 char *szPassword2 = strtok (NULL," ");
756 if (!szAccount||!szPassword1 || !szPassword2)
757 return false;
759 std::string account_name = szAccount;
760 if(!AccountMgr::normilizeString(account_name))
762 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
763 SetSentErrorMessage(true);
764 return false;
767 uint32 targetAccountId = accmgr.GetId(account_name);
768 if (!targetAccountId)
770 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
771 SetSentErrorMessage(true);
772 return false;
775 uint32 targetSecurity = accmgr.GetSecurity(targetAccountId);
777 /// m_session==NULL only for console
778 uint32 plSecurity = m_session ? m_session->GetSecurity() : SEC_CONSOLE;
780 /// can set password only for target with less security
781 /// This is also reject self apply in fact
782 if (targetSecurity >= plSecurity)
784 SendSysMessage (LANG_YOURS_SECURITY_IS_LOW);
785 SetSentErrorMessage (true);
786 return false;
789 if (strcmp(szPassword1,szPassword2))
791 SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH);
792 SetSentErrorMessage (true);
793 return false;
796 AccountOpResult result = accmgr.ChangePassword(targetAccountId, szPassword1);
798 switch(result)
800 case AOR_OK:
801 SendSysMessage(LANG_COMMAND_PASSWORD);
802 break;
803 case AOR_NAME_NOT_EXIST:
804 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
805 SetSentErrorMessage(true);
806 return false;
807 case AOR_PASS_TOO_LONG:
808 SendSysMessage(LANG_PASSWORD_TOO_LONG);
809 SetSentErrorMessage(true);
810 return false;
811 default:
812 SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD);
813 SetSentErrorMessage(true);
814 return false;
817 return true;
820 bool ChatHandler::HandleAllowMovementCommand(const char* /*args*/)
822 if(sWorld.getAllowMovement())
824 sWorld.SetAllowMovement(false);
825 SendSysMessage(LANG_CREATURE_MOVE_DISABLED);
827 else
829 sWorld.SetAllowMovement(true);
830 SendSysMessage(LANG_CREATURE_MOVE_ENABLED);
832 return true;
835 bool ChatHandler::HandleMaxSkillCommand(const char* /*args*/)
837 Player* SelectedPlayer = getSelectedPlayer();
838 if(!SelectedPlayer)
840 SendSysMessage(LANG_NO_CHAR_SELECTED);
841 SetSentErrorMessage(true);
842 return false;
845 // each skills that have max skill value dependent from level seted to current level max skill value
846 SelectedPlayer->UpdateSkillsToMaxSkillsForLevel();
847 return true;
850 bool ChatHandler::HandleSetSkillCommand(const char* args)
852 // number or [name] Shift-click form |color|Hskill:skill_id|h[name]|h|r
853 char* skill_p = extractKeyFromLink((char*)args,"Hskill");
854 if(!skill_p)
855 return false;
857 char *level_p = strtok (NULL, " ");
859 if( !level_p)
860 return false;
862 char *max_p = strtok (NULL, " ");
864 int32 skill = atoi(skill_p);
866 if (skill <= 0)
868 PSendSysMessage(LANG_INVALID_SKILL_ID, skill);
869 SetSentErrorMessage(true);
870 return false;
873 int32 level = atol (level_p);
875 Player * target = getSelectedPlayer();
876 if(!target)
878 SendSysMessage(LANG_NO_CHAR_SELECTED);
879 SetSentErrorMessage(true);
880 return false;
883 SkillLineEntry const* sl = sSkillLineStore.LookupEntry(skill);
884 if(!sl)
886 PSendSysMessage(LANG_INVALID_SKILL_ID, skill);
887 SetSentErrorMessage(true);
888 return false;
891 if(!target->GetSkillValue(skill))
893 PSendSysMessage(LANG_SET_SKILL_ERROR, target->GetName(), skill, sl->name[0]);
894 SetSentErrorMessage(true);
895 return false;
898 int32 max = max_p ? atol (max_p) : target->GetPureMaxSkillValue(skill);
900 if( level <= 0 || level > max || max <= 0 )
901 return false;
903 target->SetSkill(skill, level, max);
904 PSendSysMessage(LANG_SET_SKILL, skill, sl->name[0], target->GetName(), level, max);
906 return true;
909 bool ChatHandler::HandleUnLearnCommand(const char* args)
911 if (!*args)
912 return false;
914 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
915 uint32 min_id = extractSpellIdFromLink((char*)args);
916 if(!min_id)
917 return false;
919 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
920 char* tail = strtok(NULL,"");
922 uint32 max_id = extractSpellIdFromLink(tail);
924 if (!max_id)
926 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
927 max_id = min_id+1;
929 else
931 if (max_id < min_id)
932 std::swap(min_id,max_id);
934 max_id=max_id+1;
937 Player* target = getSelectedPlayer();
938 if(!target)
940 SendSysMessage(LANG_NO_CHAR_SELECTED);
941 SetSentErrorMessage(true);
942 return false;
945 for(uint32 spell=min_id;spell<max_id;spell++)
947 if (target->HasSpell(spell))
948 target->removeSpell(spell);
949 else
950 SendSysMessage(LANG_FORGET_SPELL);
953 return true;
956 bool ChatHandler::HandleCooldownCommand(const char* args)
958 Player* target = getSelectedPlayer();
959 if(!target)
961 SendSysMessage(LANG_PLAYER_NOT_FOUND);
962 SetSentErrorMessage(true);
963 return false;
966 if (!*args)
968 target->RemoveAllSpellCooldown();
969 PSendSysMessage(LANG_REMOVEALL_COOLDOWN, target->GetName());
971 else
973 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
974 uint32 spell_id = extractSpellIdFromLink((char*)args);
975 if(!spell_id)
976 return false;
978 if(!sSpellStore.LookupEntry(spell_id))
980 PSendSysMessage(LANG_UNKNOWN_SPELL, target==m_session->GetPlayer() ? GetMangosString(LANG_YOU) : target->GetName());
981 SetSentErrorMessage(true);
982 return false;
985 WorldPacket data( SMSG_CLEAR_COOLDOWN, (4+8) );
986 data << uint32(spell_id);
987 data << uint64(target->GetGUID());
988 target->GetSession()->SendPacket(&data);
989 target->RemoveSpellCooldown(spell_id);
990 PSendSysMessage(LANG_REMOVE_COOLDOWN, spell_id, target==m_session->GetPlayer() ? GetMangosString(LANG_YOU) : target->GetName());
992 return true;
995 bool ChatHandler::HandleLearnAllCommand(const char* /*args*/)
997 static const char *allSpellList[] =
999 "3365",
1000 "6233",
1001 "6247",
1002 "6246",
1003 "6477",
1004 "6478",
1005 "22810",
1006 "8386",
1007 "21651",
1008 "21652",
1009 "522",
1010 "7266",
1011 "8597",
1012 "2479",
1013 "22027",
1014 "6603",
1015 "5019",
1016 "133",
1017 "168",
1018 "227",
1019 "5009",
1020 "9078",
1021 "668",
1022 "203",
1023 "20599",
1024 "20600",
1025 "81",
1026 "20597",
1027 "20598",
1028 "20864",
1029 "1459",
1030 "5504",
1031 "587",
1032 "5143",
1033 "118",
1034 "5505",
1035 "597",
1036 "604",
1037 "1449",
1038 "1460",
1039 "2855",
1040 "1008",
1041 "475",
1042 "5506",
1043 "1463",
1044 "12824",
1045 "8437",
1046 "990",
1047 "5145",
1048 "8450",
1049 "1461",
1050 "759",
1051 "8494",
1052 "8455",
1053 "8438",
1054 "6127",
1055 "8416",
1056 "6129",
1057 "8451",
1058 "8495",
1059 "8439",
1060 "3552",
1061 "8417",
1062 "10138",
1063 "12825",
1064 "10169",
1065 "10156",
1066 "10144",
1067 "10191",
1068 "10201",
1069 "10211",
1070 "10053",
1071 "10173",
1072 "10139",
1073 "10145",
1074 "10192",
1075 "10170",
1076 "10202",
1077 "10054",
1078 "10174",
1079 "10193",
1080 "12826",
1081 "2136",
1082 "143",
1083 "145",
1084 "2137",
1085 "2120",
1086 "3140",
1087 "543",
1088 "2138",
1089 "2948",
1090 "8400",
1091 "2121",
1092 "8444",
1093 "8412",
1094 "8457",
1095 "8401",
1096 "8422",
1097 "8445",
1098 "8402",
1099 "8413",
1100 "8458",
1101 "8423",
1102 "8446",
1103 "10148",
1104 "10197",
1105 "10205",
1106 "10149",
1107 "10215",
1108 "10223",
1109 "10206",
1110 "10199",
1111 "10150",
1112 "10216",
1113 "10207",
1114 "10225",
1115 "10151",
1116 "116",
1117 "205",
1118 "7300",
1119 "122",
1120 "837",
1121 "10",
1122 "7301",
1123 "7322",
1124 "6143",
1125 "120",
1126 "865",
1127 "8406",
1128 "6141",
1129 "7302",
1130 "8461",
1131 "8407",
1132 "8492",
1133 "8427",
1134 "8408",
1135 "6131",
1136 "7320",
1137 "10159",
1138 "8462",
1139 "10185",
1140 "10179",
1141 "10160",
1142 "10180",
1143 "10219",
1144 "10186",
1145 "10177",
1146 "10230",
1147 "10181",
1148 "10161",
1149 "10187",
1150 "10220",
1151 "2018",
1152 "2663",
1153 "12260",
1154 "2660",
1155 "3115",
1156 "3326",
1157 "2665",
1158 "3116",
1159 "2738",
1160 "3293",
1161 "2661",
1162 "3319",
1163 "2662",
1164 "9983",
1165 "8880",
1166 "2737",
1167 "2739",
1168 "7408",
1169 "3320",
1170 "2666",
1171 "3323",
1172 "3324",
1173 "3294",
1174 "22723",
1175 "23219",
1176 "23220",
1177 "23221",
1178 "23228",
1179 "23338",
1180 "10788",
1181 "10790",
1182 "5611",
1183 "5016",
1184 "5609",
1185 "2060",
1186 "10963",
1187 "10964",
1188 "10965",
1189 "22593",
1190 "22594",
1191 "596",
1192 "996",
1193 "499",
1194 "768",
1195 "17002",
1196 "1448",
1197 "1082",
1198 "16979",
1199 "1079",
1200 "5215",
1201 "20484",
1202 "5221",
1203 "15590",
1204 "17007",
1205 "6795",
1206 "6807",
1207 "5487",
1208 "1446",
1209 "1066",
1210 "5421",
1211 "3139",
1212 "779",
1213 "6811",
1214 "6808",
1215 "1445",
1216 "5216",
1217 "1737",
1218 "5222",
1219 "5217",
1220 "1432",
1221 "6812",
1222 "9492",
1223 "5210",
1224 "3030",
1225 "1441",
1226 "783",
1227 "6801",
1228 "20739",
1229 "8944",
1230 "9491",
1231 "22569",
1232 "5226",
1233 "6786",
1234 "1433",
1235 "8973",
1236 "1828",
1237 "9495",
1238 "9006",
1239 "6794",
1240 "8993",
1241 "5203",
1242 "16914",
1243 "6784",
1244 "9635",
1245 "22830",
1246 "20722",
1247 "9748",
1248 "6790",
1249 "9753",
1250 "9493",
1251 "9752",
1252 "9831",
1253 "9825",
1254 "9822",
1255 "5204",
1256 "5401",
1257 "22831",
1258 "6793",
1259 "9845",
1260 "17401",
1261 "9882",
1262 "9868",
1263 "20749",
1264 "9893",
1265 "9899",
1266 "9895",
1267 "9832",
1268 "9902",
1269 "9909",
1270 "22832",
1271 "9828",
1272 "9851",
1273 "9883",
1274 "9869",
1275 "17406",
1276 "17402",
1277 "9914",
1278 "20750",
1279 "9897",
1280 "9848",
1281 "3127",
1282 "107",
1283 "204",
1284 "9116",
1285 "2457",
1286 "78",
1287 "18848",
1288 "331",
1289 "403",
1290 "2098",
1291 "1752",
1292 "11278",
1293 "11288",
1294 "11284",
1295 "6461",
1296 "2344",
1297 "2345",
1298 "6463",
1299 "2346",
1300 "2352",
1301 "775",
1302 "1434",
1303 "1612",
1304 "71",
1305 "2468",
1306 "2458",
1307 "2467",
1308 "7164",
1309 "7178",
1310 "7367",
1311 "7376",
1312 "7381",
1313 "21156",
1314 "5209",
1315 "3029",
1316 "5201",
1317 "9849",
1318 "9850",
1319 "20719",
1320 "22568",
1321 "22827",
1322 "22828",
1323 "22829",
1324 "6809",
1325 "8972",
1326 "9005",
1327 "9823",
1328 "9827",
1329 "6783",
1330 "9913",
1331 "6785",
1332 "6787",
1333 "9866",
1334 "9867",
1335 "9894",
1336 "9896",
1337 "6800",
1338 "8992",
1339 "9829",
1340 "9830",
1341 "780",
1342 "769",
1343 "6749",
1344 "6750",
1345 "9755",
1346 "9754",
1347 "9908",
1348 "20745",
1349 "20742",
1350 "20747",
1351 "20748",
1352 "9746",
1353 "9745",
1354 "9880",
1355 "9881",
1356 "5391",
1357 "842",
1358 "3025",
1359 "3031",
1360 "3287",
1361 "3329",
1362 "1945",
1363 "3559",
1364 "4933",
1365 "4934",
1366 "4935",
1367 "4936",
1368 "5142",
1369 "5390",
1370 "5392",
1371 "5404",
1372 "5420",
1373 "6405",
1374 "7293",
1375 "7965",
1376 "8041",
1377 "8153",
1378 "9033",
1379 "9034",
1380 //"9036", problems with ghost state
1381 "16421",
1382 "21653",
1383 "22660",
1384 "5225",
1385 "9846",
1386 "2426",
1387 "5916",
1388 "6634",
1389 //"6718", phasing stealth, annoing for learn all case.
1390 "6719",
1391 "8822",
1392 "9591",
1393 "9590",
1394 "10032",
1395 "17746",
1396 "17747",
1397 "8203",
1398 "11392",
1399 "12495",
1400 "16380",
1401 "23452",
1402 "4079",
1403 "4996",
1404 "4997",
1405 "4998",
1406 "4999",
1407 "5000",
1408 "6348",
1409 "6349",
1410 "6481",
1411 "6482",
1412 "6483",
1413 "6484",
1414 "11362",
1415 "11410",
1416 "11409",
1417 "12510",
1418 "12509",
1419 "12885",
1420 "13142",
1421 "21463",
1422 "23460",
1423 "11421",
1424 "11416",
1425 "11418",
1426 "1851",
1427 "10059",
1428 "11423",
1429 "11417",
1430 "11422",
1431 "11419",
1432 "11424",
1433 "11420",
1434 "27",
1435 "31",
1436 "33",
1437 "34",
1438 "35",
1439 "15125",
1440 "21127",
1441 "22950",
1442 "1180",
1443 "201",
1444 "12593",
1445 "12842",
1446 "16770",
1447 "6057",
1448 "12051",
1449 "18468",
1450 "12606",
1451 "12605",
1452 "18466",
1453 "12502",
1454 "12043",
1455 "15060",
1456 "12042",
1457 "12341",
1458 "12848",
1459 "12344",
1460 "12353",
1461 "18460",
1462 "11366",
1463 "12350",
1464 "12352",
1465 "13043",
1466 "11368",
1467 "11113",
1468 "12400",
1469 "11129",
1470 "16766",
1471 "12573",
1472 "15053",
1473 "12580",
1474 "12475",
1475 "12472",
1476 "12953",
1477 "12488",
1478 "11189",
1479 "12985",
1480 "12519",
1481 "16758",
1482 "11958",
1483 "12490",
1484 "11426",
1485 "3565",
1486 "3562",
1487 "18960",
1488 "3567",
1489 "3561",
1490 "3566",
1491 "3563",
1492 "1953",
1493 "2139",
1494 "12505",
1495 "13018",
1496 "12522",
1497 "12523",
1498 "5146",
1499 "5144",
1500 "5148",
1501 "8419",
1502 "8418",
1503 "10213",
1504 "10212",
1505 "10157",
1506 "12524",
1507 "13019",
1508 "12525",
1509 "13020",
1510 "12526",
1511 "13021",
1512 "18809",
1513 "13031",
1514 "13032",
1515 "13033",
1516 "4036",
1517 "3920",
1518 "3919",
1519 "3918",
1520 "7430",
1521 "3922",
1522 "3923",
1523 "7411",
1524 "7418",
1525 "7421",
1526 "13262",
1527 "7412",
1528 "7415",
1529 "7413",
1530 "7416",
1531 "13920",
1532 "13921",
1533 "7745",
1534 "7779",
1535 "7428",
1536 "7457",
1537 "7857",
1538 "7748",
1539 "7426",
1540 "13421",
1541 "7454",
1542 "13378",
1543 "7788",
1544 "14807",
1545 "14293",
1546 "7795",
1547 "6296",
1548 "20608",
1549 "755",
1550 "444",
1551 "427",
1552 "428",
1553 "442",
1554 "447",
1555 "3578",
1556 "3581",
1557 "19027",
1558 "3580",
1559 "665",
1560 "3579",
1561 "3577",
1562 "6755",
1563 "3576",
1564 "2575",
1565 "2577",
1566 "2578",
1567 "2579",
1568 "2580",
1569 "2656",
1570 "2657",
1571 "2576",
1572 "3564",
1573 "10248",
1574 "8388",
1575 "2659",
1576 "14891",
1577 "3308",
1578 "3307",
1579 "10097",
1580 "2658",
1581 "3569",
1582 "16153",
1583 "3304",
1584 "10098",
1585 "4037",
1586 "3929",
1587 "3931",
1588 "3926",
1589 "3924",
1590 "3930",
1591 "3977",
1592 "3925",
1593 "136",
1594 "228",
1595 "5487",
1596 "43",
1597 "202",
1601 int loop = 0;
1602 while(strcmp(allSpellList[loop], "0"))
1604 uint32 spell = atol((char*)allSpellList[loop++]);
1606 if (m_session->GetPlayer()->HasSpell(spell))
1607 continue;
1609 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
1610 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
1612 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
1613 continue;
1616 m_session->GetPlayer()->learnSpell(spell);
1619 SendSysMessage(LANG_COMMAND_LEARN_MANY_SPELLS);
1621 return true;
1624 bool ChatHandler::HandleLearnAllGMCommand(const char* /*args*/)
1626 static const char *gmSpellList[] =
1628 "24347", // Become A Fish, No Breath Bar
1629 "35132", // Visual Boom
1630 "38488", // Attack 4000-8000 AOE
1631 "38795", // Attack 2000 AOE + Slow Down 90%
1632 "15712", // Attack 200
1633 "1852", // GM Spell Silence
1634 "31899", // Kill
1635 "31924", // Kill
1636 "29878", // Kill My Self
1637 "26644", // More Kill
1639 "28550", //Invisible 24
1640 "23452", //Invisible + Target
1644 uint16 gmSpellIter = 0;
1645 while( strcmp(gmSpellList[gmSpellIter], "0") )
1647 uint32 spell = atol((char*)gmSpellList[gmSpellIter++]);
1649 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
1650 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
1652 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
1653 continue;
1656 m_session->GetPlayer()->learnSpell(spell);
1659 SendSysMessage(LANG_LEARNING_GM_SKILLS);
1660 return true;
1663 bool ChatHandler::HandleLearnAllMyClassCommand(const char* /*args*/)
1665 HandleLearnAllMySpellsCommand("");
1666 HandleLearnAllMyTalentsCommand("");
1667 return true;
1670 bool ChatHandler::HandleLearnAllMySpellsCommand(const char* /*args*/)
1672 ChrClassesEntry const* clsEntry = sChrClassesStore.LookupEntry(m_session->GetPlayer()->getClass());
1673 if(!clsEntry)
1674 return true;
1675 uint32 family = clsEntry->spellfamily;
1677 for (uint32 i = 0; i < sSpellStore.GetNumRows(); i++)
1679 SpellEntry const *spellInfo = sSpellStore.LookupEntry(i);
1680 if(!spellInfo)
1681 continue;
1683 // skip wrong class/race skills
1684 if(!m_session->GetPlayer()->IsSpellFitByClassAndRace(spellInfo->Id))
1685 continue;
1687 // skip other spell families
1688 if( spellInfo->SpellFamilyName != family)
1689 continue;
1691 //TODO: skip triggered spells
1693 // skip spells with first rank learned as talent (and all talents then also)
1694 uint32 first_rank = spellmgr.GetFirstSpellInChain(spellInfo->Id);
1695 if(GetTalentSpellCost(first_rank) > 0 )
1696 continue;
1698 // skip broken spells
1699 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
1700 continue;
1702 m_session->GetPlayer()->learnSpell(i);
1705 SendSysMessage(LANG_COMMAND_LEARN_CLASS_SPELLS);
1706 return true;
1709 static void learnAllHighRanks(Player* player, uint32 spellid)
1711 SpellChainMapNext const& nextMap = spellmgr.GetSpellChainNext();
1712 for(SpellChainMapNext::const_iterator itr = nextMap.lower_bound(spellid); itr != nextMap.upper_bound(spellid); ++itr)
1714 player->learnSpell(itr->second);
1715 learnAllHighRanks(player,itr->second);
1719 bool ChatHandler::HandleLearnAllMyTalentsCommand(const char* /*args*/)
1721 Player* player = m_session->GetPlayer();
1722 uint32 classMask = player->getClassMask();
1724 for (uint32 i = 0; i < sTalentStore.GetNumRows(); i++)
1726 TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
1727 if(!talentInfo)
1728 continue;
1730 TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentInfo->TalentTab );
1731 if(!talentTabInfo)
1732 continue;
1734 if( (classMask & talentTabInfo->ClassMask) == 0 )
1735 continue;
1737 // search highest talent rank
1738 uint32 spellid = 0;
1739 int rank = 4;
1740 for(; rank >= 0; --rank)
1742 if(talentInfo->RankID[rank]!=0)
1744 spellid = talentInfo->RankID[rank];
1745 break;
1749 if(!spellid) // ??? none spells in telent
1750 continue;
1752 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellid);
1753 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
1754 continue;
1756 // learn highest rank of talent
1757 player->learnSpell(spellid);
1759 // and learn all non-talent spell ranks (recursive by tree)
1760 learnAllHighRanks(player,spellid);
1763 SendSysMessage(LANG_COMMAND_LEARN_CLASS_TALENTS);
1764 return true;
1767 bool ChatHandler::HandleLearnAllLangCommand(const char* /*args*/)
1769 // skipping UNIVERSAL language (0)
1770 for(int i = 1; i < LANGUAGES_COUNT; ++i)
1771 m_session->GetPlayer()->learnSpell(lang_description[i].spell_id);
1773 SendSysMessage(LANG_COMMAND_LEARN_ALL_LANG);
1774 return true;
1777 bool ChatHandler::HandleLearnAllDefaultCommand(const char* args)
1779 char* pName = strtok((char*)args, "");
1780 Player *player = NULL;
1781 if (pName)
1783 std::string name = pName;
1785 if(!normalizePlayerName(name))
1787 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1788 SetSentErrorMessage(true);
1789 return false;
1792 player = objmgr.GetPlayer(name.c_str());
1794 else
1795 player = getSelectedPlayer();
1797 if(!player)
1799 SendSysMessage(LANG_NO_CHAR_SELECTED);
1800 SetSentErrorMessage(true);
1801 return false;
1804 player->learnDefaultSpells();
1805 player->learnQuestRewardedSpells();
1807 PSendSysMessage(LANG_COMMAND_LEARN_ALL_DEFAULT_AND_QUEST,player->GetName());
1808 return true;
1811 bool ChatHandler::HandleLearnCommand(const char* args)
1813 Player* targetPlayer = getSelectedPlayer();
1815 if(!targetPlayer)
1817 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1818 SetSentErrorMessage(true);
1819 return false;
1822 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1823 uint32 spell = extractSpellIdFromLink((char*)args);
1824 if(!spell || !sSpellStore.LookupEntry(spell))
1825 return false;
1827 if (targetPlayer->HasSpell(spell))
1829 if(targetPlayer == m_session->GetPlayer())
1830 SendSysMessage(LANG_YOU_KNOWN_SPELL);
1831 else
1832 PSendSysMessage(LANG_TARGET_KNOWN_SPELL,targetPlayer->GetName());
1833 SetSentErrorMessage(true);
1834 return false;
1837 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
1838 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
1840 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
1841 SetSentErrorMessage(true);
1842 return false;
1845 targetPlayer->learnSpell(spell);
1847 return true;
1850 bool ChatHandler::HandleAddItemCommand(const char* args)
1852 if (!*args)
1853 return false;
1855 uint32 itemId = 0;
1857 if(args[0]=='[') // [name] manual form
1859 char* citemName = citemName = strtok((char*)args, "]");
1861 if(citemName && citemName[0])
1863 std::string itemName = citemName+1;
1864 WorldDatabase.escape_string(itemName);
1865 QueryResult *result = WorldDatabase.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName.c_str());
1866 if (!result)
1868 PSendSysMessage(LANG_COMMAND_COULDNOTFIND, citemName+1);
1869 SetSentErrorMessage(true);
1870 return false;
1872 itemId = result->Fetch()->GetUInt16();
1873 delete result;
1875 else
1876 return false;
1878 else // item_id or [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r
1880 char* cId = extractKeyFromLink((char*)args,"Hitem");
1881 if(!cId)
1882 return false;
1883 itemId = atol(cId);
1886 char* ccount = strtok(NULL, " ");
1888 int32 count = 1;
1890 if (ccount)
1891 count = strtol(ccount, NULL, 10);
1893 if (count == 0)
1894 count = 1;
1896 Player* pl = m_session->GetPlayer();
1897 Player* plTarget = getSelectedPlayer();
1898 if(!plTarget)
1899 plTarget = pl;
1901 sLog.outDetail(GetMangosString(LANG_ADDITEM), itemId, count);
1903 ItemPrototype const *pProto = objmgr.GetItemPrototype(itemId);
1904 if(!pProto)
1906 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, itemId);
1907 SetSentErrorMessage(true);
1908 return false;
1911 //Subtract
1912 if (count < 0)
1914 plTarget->DestroyItemCount(itemId, -count, true, false);
1915 PSendSysMessage(LANG_REMOVEITEM, itemId, -count, plTarget->GetName());
1916 return true;
1919 //Adding items
1920 uint32 noSpaceForCount = 0;
1922 // check space and find places
1923 ItemPosCountVec dest;
1924 uint8 msg = plTarget->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, itemId, count, &noSpaceForCount );
1925 if( msg != EQUIP_ERR_OK ) // convert to possible store amount
1926 count -= noSpaceForCount;
1928 if( count == 0 || dest.empty()) // can't add any
1930 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount );
1931 SetSentErrorMessage(true);
1932 return false;
1935 Item* item = plTarget->StoreNewItem( dest, itemId, true, Item::GenerateItemRandomPropertyId(itemId));
1937 // remove binding (let GM give it to another player later)
1938 if(pl==plTarget)
1939 for(ItemPosCountVec::const_iterator itr = dest.begin(); itr != dest.end(); ++itr)
1940 if(Item* item1 = pl->GetItemByPos(itr->pos))
1941 item1->SetBinding( false );
1943 if(count > 0 && item)
1945 pl->SendNewItem(item,count,false,true);
1946 if(pl!=plTarget)
1947 plTarget->SendNewItem(item,count,true,false);
1950 if(noSpaceForCount > 0)
1951 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount);
1953 return true;
1956 bool ChatHandler::HandleAddItemSetCommand(const char* args)
1958 if (!*args)
1959 return false;
1961 char* cId = extractKeyFromLink((char*)args,"Hitemset"); // number or [name] Shift-click form |color|Hitemset:itemset_id|h[name]|h|r
1962 if (!cId)
1963 return false;
1965 uint32 itemsetId = atol(cId);
1967 // prevent generation all items with itemset field value '0'
1968 if (itemsetId == 0)
1970 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND,itemsetId);
1971 SetSentErrorMessage(true);
1972 return false;
1975 Player* pl = m_session->GetPlayer();
1976 Player* plTarget = getSelectedPlayer();
1977 if(!plTarget)
1978 plTarget = pl;
1980 sLog.outDetail(GetMangosString(LANG_ADDITEMSET), itemsetId);
1982 QueryResult *result = WorldDatabase.PQuery("SELECT entry FROM item_template WHERE itemset = %u",itemsetId);
1984 if(!result)
1986 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND,itemsetId);
1988 SetSentErrorMessage(true);
1989 return false;
1994 Field *fields = result->Fetch();
1995 uint32 itemId = fields[0].GetUInt32();
1997 ItemPosCountVec dest;
1998 uint8 msg = plTarget->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, itemId, 1 );
1999 if( msg == EQUIP_ERR_OK )
2001 Item* item = plTarget->StoreNewItem( dest, itemId, true);
2003 // remove binding (let GM give it to another player later)
2004 if(pl==plTarget)
2005 item->SetBinding( false );
2007 pl->SendNewItem(item,1,false,true);
2008 if(pl!=plTarget)
2009 plTarget->SendNewItem(item,1,true,false);
2011 else
2013 pl->SendEquipError( msg, NULL, NULL );
2014 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, 1);
2017 }while( result->NextRow() );
2019 delete result;
2021 return true;
2024 bool ChatHandler::HandleListItemCommand(const char* args)
2026 if(!*args)
2027 return false;
2029 char* cId = extractKeyFromLink((char*)args,"Hitem");
2030 if(!cId)
2031 return false;
2033 uint32 item_id = atol(cId);
2034 if(!item_id)
2036 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
2037 SetSentErrorMessage(true);
2038 return false;
2041 ItemPrototype const* itemProto = objmgr.GetItemPrototype(item_id);
2042 if(!itemProto)
2044 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
2045 SetSentErrorMessage(true);
2046 return false;
2049 char* c_count = strtok(NULL, " ");
2050 int count = c_count ? atol(c_count) : 10;
2052 if(count < 0)
2053 return false;
2055 QueryResult *result;
2057 // inventory case
2058 uint32 inv_count = 0;
2059 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM character_inventory WHERE item_template='%u'",item_id);
2060 if(result)
2062 inv_count = (*result)[0].GetUInt32();
2063 delete result;
2066 result=CharacterDatabase.PQuery(
2067 // 0 1 2 3 4 5
2068 "SELECT ci.item, cibag.slot AS bag, ci.slot, ci.guid, characters.account,characters.name "
2069 "FROM character_inventory AS ci LEFT JOIN character_inventory AS cibag ON (cibag.item=ci.bag),characters "
2070 "WHERE ci.item_template='%u' AND ci.guid = characters.guid LIMIT %u ",
2071 item_id,uint32(count));
2073 if(result)
2077 Field *fields = result->Fetch();
2078 uint32 item_guid = fields[0].GetUInt32();
2079 uint32 item_bag = fields[1].GetUInt32();
2080 uint32 item_slot = fields[2].GetUInt32();
2081 uint32 owner_guid = fields[3].GetUInt32();
2082 uint32 owner_acc = fields[4].GetUInt32();
2083 std::string owner_name = fields[5].GetCppString();
2085 char const* item_pos = 0;
2086 if(Player::IsEquipmentPos(item_bag,item_slot))
2087 item_pos = "[equipped]";
2088 else if(Player::IsInventoryPos(item_bag,item_slot))
2089 item_pos = "[in inventory]";
2090 else if(Player::IsBankPos(item_bag,item_slot))
2091 item_pos = "[in bank]";
2092 else
2093 item_pos = "";
2095 PSendSysMessage(LANG_ITEMLIST_SLOT,
2096 item_guid,owner_name.c_str(),owner_guid,owner_acc,item_pos);
2097 } while (result->NextRow());
2099 int64 res_count = result->GetRowCount();
2101 delete result;
2103 if(count > res_count)
2104 count-=res_count;
2105 else if(count)
2106 count = 0;
2109 // mail case
2110 uint32 mail_count = 0;
2111 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM mail_items WHERE item_template='%u'", item_id);
2112 if(result)
2114 mail_count = (*result)[0].GetUInt32();
2115 delete result;
2118 if(count > 0)
2120 result=CharacterDatabase.PQuery(
2121 // 0 1 2 3 4 5 6
2122 "SELECT mail_items.item_guid, mail.sender, mail.receiver, char_s.account, char_s.name, char_r.account, char_r.name "
2123 "FROM mail,mail_items,characters as char_s,characters as char_r "
2124 "WHERE mail_items.item_template='%u' AND char_s.guid = mail.sender AND char_r.guid = mail.receiver AND mail.id=mail_items.mail_id LIMIT %u",
2125 item_id,uint32(count));
2127 else
2128 result = NULL;
2130 if(result)
2134 Field *fields = result->Fetch();
2135 uint32 item_guid = fields[0].GetUInt32();
2136 uint32 item_s = fields[1].GetUInt32();
2137 uint32 item_r = fields[2].GetUInt32();
2138 uint32 item_s_acc = fields[3].GetUInt32();
2139 std::string item_s_name = fields[4].GetCppString();
2140 uint32 item_r_acc = fields[5].GetUInt32();
2141 std::string item_r_name = fields[6].GetCppString();
2143 char const* item_pos = "[in mail]";
2145 PSendSysMessage(LANG_ITEMLIST_MAIL,
2146 item_guid,item_s_name.c_str(),item_s,item_s_acc,item_r_name.c_str(),item_r,item_r_acc,item_pos);
2147 } while (result->NextRow());
2149 int64 res_count = result->GetRowCount();
2151 delete result;
2153 if(count > res_count)
2154 count-=res_count;
2155 else if(count)
2156 count = 0;
2159 // auction case
2160 uint32 auc_count = 0;
2161 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM auctionhouse WHERE item_template='%u'",item_id);
2162 if(result)
2164 auc_count = (*result)[0].GetUInt32();
2165 delete result;
2168 if(count > 0)
2170 result=CharacterDatabase.PQuery(
2171 // 0 1 2 3
2172 "SELECT auctionhouse.itemguid, auctionhouse.itemowner, characters.account, characters.name "
2173 "FROM auctionhouse,characters WHERE auctionhouse.item_template='%u' AND characters.guid = auctionhouse.itemowner LIMIT %u",
2174 item_id,uint32(count));
2176 else
2177 result = NULL;
2179 if(result)
2183 Field *fields = result->Fetch();
2184 uint32 item_guid = fields[0].GetUInt32();
2185 uint32 owner = fields[1].GetUInt32();
2186 uint32 owner_acc = fields[2].GetUInt32();
2187 std::string owner_name = fields[3].GetCppString();
2189 char const* item_pos = "[in auction]";
2191 PSendSysMessage(LANG_ITEMLIST_AUCTION, item_guid, owner_name.c_str(), owner, owner_acc,item_pos);
2192 } while (result->NextRow());
2194 delete result;
2197 if(inv_count+mail_count+auc_count == 0)
2199 SendSysMessage(LANG_COMMAND_NOITEMFOUND);
2200 SetSentErrorMessage(true);
2201 return false;
2204 PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE,item_id,inv_count+mail_count+auc_count,inv_count,mail_count,auc_count);
2206 return true;
2209 bool ChatHandler::HandleListObjectCommand(const char* args)
2211 if(!*args)
2212 return false;
2214 // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2215 char* cId = extractKeyFromLink((char*)args,"Hgameobject_entry");
2216 if(!cId)
2217 return false;
2219 uint32 go_id = atol(cId);
2220 if(!go_id)
2222 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, go_id);
2223 SetSentErrorMessage(true);
2224 return false;
2227 GameObjectInfo const * gInfo = objmgr.GetGameObjectInfo(go_id);
2228 if(!gInfo)
2230 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, go_id);
2231 SetSentErrorMessage(true);
2232 return false;
2235 char* c_count = strtok(NULL, " ");
2236 int count = c_count ? atol(c_count) : 10;
2238 if(count < 0)
2239 return false;
2241 QueryResult *result;
2243 uint32 obj_count = 0;
2244 result=WorldDatabase.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'",go_id);
2245 if(result)
2247 obj_count = (*result)[0].GetUInt32();
2248 delete result;
2251 if(m_session)
2253 Player* pl = m_session->GetPlayer();
2254 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",
2255 pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(),go_id,uint32(count));
2257 else
2258 result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map FROM gameobject WHERE id = '%u' LIMIT %u",
2259 go_id,uint32(count));
2261 if (result)
2265 Field *fields = result->Fetch();
2266 uint32 guid = fields[0].GetUInt32();
2267 float x = fields[1].GetFloat();
2268 float y = fields[2].GetFloat();
2269 float z = fields[3].GetFloat();
2270 int mapid = fields[4].GetUInt16();
2272 if (m_session)
2273 PSendSysMessage(LANG_GO_LIST_CHAT, guid, guid, gInfo->name, x, y, z, mapid);
2274 else
2275 PSendSysMessage(LANG_GO_LIST_CONSOLE, guid, gInfo->name, x, y, z, mapid);
2276 } while (result->NextRow());
2278 delete result;
2281 PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE,go_id,obj_count);
2282 return true;
2285 bool ChatHandler::HandleNearObjectCommand(const char* args)
2287 float distance = (!*args) ? 10 : atol(args);
2288 uint32 count = 0;
2290 Player* pl = m_session->GetPlayer();
2291 QueryResult *result = WorldDatabase.PQuery("SELECT guid, id, position_x, position_y, position_z, map, "
2292 "(POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ "
2293 "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_",
2294 pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(),
2295 pl->GetMapId(),pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(),distance*distance);
2297 if (result)
2301 Field *fields = result->Fetch();
2302 uint32 guid = fields[0].GetUInt32();
2303 uint32 entry = fields[1].GetUInt32();
2304 float x = fields[2].GetFloat();
2305 float y = fields[3].GetFloat();
2306 float z = fields[4].GetFloat();
2307 int mapid = fields[5].GetUInt16();
2309 GameObjectInfo const * gInfo = objmgr.GetGameObjectInfo(entry);
2311 if(!gInfo)
2312 continue;
2314 PSendSysMessage(LANG_GO_LIST_CHAT, guid, guid, gInfo->name, x, y, z, mapid);
2316 ++count;
2317 } while (result->NextRow());
2319 delete result;
2322 PSendSysMessage(LANG_COMMAND_NEAROBJMESSAGE,distance,count);
2323 return true;
2326 bool ChatHandler::HandleListCreatureCommand(const char* args)
2328 if(!*args)
2329 return false;
2331 // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
2332 char* cId = extractKeyFromLink((char*)args,"Hcreature_entry");
2333 if(!cId)
2334 return false;
2336 uint32 cr_id = atol(cId);
2337 if(!cr_id)
2339 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, cr_id);
2340 SetSentErrorMessage(true);
2341 return false;
2344 CreatureInfo const* cInfo = objmgr.GetCreatureTemplate(cr_id);
2345 if(!cInfo)
2347 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, cr_id);
2348 SetSentErrorMessage(true);
2349 return false;
2352 char* c_count = strtok(NULL, " ");
2353 int count = c_count ? atol(c_count) : 10;
2355 if(count < 0)
2356 return false;
2358 QueryResult *result;
2360 uint32 cr_count = 0;
2361 result=WorldDatabase.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'",cr_id);
2362 if(result)
2364 cr_count = (*result)[0].GetUInt32();
2365 delete result;
2368 if(m_session)
2370 Player* pl = m_session->GetPlayer();
2371 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",
2372 pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(), cr_id,uint32(count));
2374 else
2375 result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '%u' LIMIT %u",
2376 cr_id,uint32(count));
2378 if (result)
2382 Field *fields = result->Fetch();
2383 uint32 guid = fields[0].GetUInt32();
2384 float x = fields[1].GetFloat();
2385 float y = fields[2].GetFloat();
2386 float z = fields[3].GetFloat();
2387 int mapid = fields[4].GetUInt16();
2389 if (m_session)
2390 PSendSysMessage(LANG_CREATURE_LIST_CHAT, guid, guid, cInfo->Name, x, y, z, mapid);
2391 else
2392 PSendSysMessage(LANG_CREATURE_LIST_CONSOLE, guid, cInfo->Name, x, y, z, mapid);
2393 } while (result->NextRow());
2395 delete result;
2398 PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE,cr_id,cr_count);
2399 return true;
2402 bool ChatHandler::HandleLookupItemCommand(const char* args)
2404 if(!*args)
2405 return false;
2407 std::string namepart = args;
2408 std::wstring wnamepart;
2410 // converting string that we try to find to lower case
2411 if(!Utf8toWStr(namepart,wnamepart))
2412 return false;
2414 wstrToLower(wnamepart);
2416 uint32 counter = 0;
2418 // Search in `item_template`
2419 for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
2421 ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype >(id);
2422 if(!pProto)
2423 continue;
2425 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
2426 if ( loc_idx >= 0 )
2428 ItemLocale const *il = objmgr.GetItemLocale(pProto->ItemId);
2429 if (il)
2431 if (il->Name.size() > loc_idx && !il->Name[loc_idx].empty())
2433 std::string name = il->Name[loc_idx];
2435 if (Utf8FitTo(name, wnamepart))
2437 if (m_session)
2438 PSendSysMessage(LANG_ITEM_LIST_CHAT, id, id, name.c_str());
2439 else
2440 PSendSysMessage(LANG_ITEM_LIST_CONSOLE, id, name.c_str());
2441 ++counter;
2442 continue;
2448 std::string name = pProto->Name1;
2449 if(name.empty())
2450 continue;
2452 if (Utf8FitTo(name, wnamepart))
2454 if (m_session)
2455 PSendSysMessage(LANG_ITEM_LIST_CHAT, id, id, name.c_str());
2456 else
2457 PSendSysMessage(LANG_ITEM_LIST_CONSOLE, id, name.c_str());
2458 ++counter;
2462 if (counter==0)
2463 SendSysMessage(LANG_COMMAND_NOITEMFOUND);
2465 return true;
2468 bool ChatHandler::HandleLookupItemSetCommand(const char* args)
2470 if(!*args)
2471 return false;
2473 std::string namepart = args;
2474 std::wstring wnamepart;
2476 if(!Utf8toWStr(namepart,wnamepart))
2477 return false;
2479 // converting string that we try to find to lower case
2480 wstrToLower( wnamepart );
2482 uint32 counter = 0; // Counter for figure out that we found smth.
2484 // Search in ItemSet.dbc
2485 for (uint32 id = 0; id < sItemSetStore.GetNumRows(); id++)
2487 ItemSetEntry const *set = sItemSetStore.LookupEntry(id);
2488 if(set)
2490 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
2491 std::string name = set->name[loc];
2492 if(name.empty())
2493 continue;
2495 if (!Utf8FitTo(name, wnamepart))
2497 loc = 0;
2498 for(; loc < MAX_LOCALE; ++loc)
2500 if(m_session && loc==m_session->GetSessionDbcLocale())
2501 continue;
2503 name = set->name[loc];
2504 if(name.empty())
2505 continue;
2507 if (Utf8FitTo(name, wnamepart))
2508 break;
2512 if(loc < MAX_LOCALE)
2514 // send item set in "id - [namedlink locale]" format
2515 if (m_session)
2516 PSendSysMessage(LANG_ITEMSET_LIST_CHAT,id,id,name.c_str(),localeNames[loc]);
2517 else
2518 PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE,id,name.c_str(),localeNames[loc]);
2519 ++counter;
2523 if (counter == 0) // if counter == 0 then we found nth
2524 SendSysMessage(LANG_COMMAND_NOITEMSETFOUND);
2525 return true;
2528 bool ChatHandler::HandleLookupSkillCommand(const char* args)
2530 if(!*args)
2531 return false;
2533 // can be NULL in console call
2534 Player* target = getSelectedPlayer();
2536 std::string namepart = args;
2537 std::wstring wnamepart;
2539 if(!Utf8toWStr(namepart,wnamepart))
2540 return false;
2542 // converting string that we try to find to lower case
2543 wstrToLower( wnamepart );
2545 uint32 counter = 0; // Counter for figure out that we found smth.
2547 // Search in SkillLine.dbc
2548 for (uint32 id = 0; id < sSkillLineStore.GetNumRows(); id++)
2550 SkillLineEntry const *skillInfo = sSkillLineStore.LookupEntry(id);
2551 if(skillInfo)
2553 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
2554 std::string name = skillInfo->name[loc];
2555 if(name.empty())
2556 continue;
2558 if (!Utf8FitTo(name, wnamepart))
2560 loc = 0;
2561 for(; loc < MAX_LOCALE; ++loc)
2563 if(m_session && loc==m_session->GetSessionDbcLocale())
2564 continue;
2566 name = skillInfo->name[loc];
2567 if(name.empty())
2568 continue;
2570 if (Utf8FitTo(name, wnamepart))
2571 break;
2575 if(loc < MAX_LOCALE)
2577 char const* knownStr = "";
2578 if(target && target->HasSkill(id))
2579 knownStr = GetMangosString(LANG_KNOWN);
2581 // send skill in "id - [namedlink locale]" format
2582 if (m_session)
2583 PSendSysMessage(LANG_SKILL_LIST_CHAT,id,id,name.c_str(),localeNames[loc],knownStr);
2584 else
2585 PSendSysMessage(LANG_SKILL_LIST_CONSOLE,id,name.c_str(),localeNames[loc],knownStr);
2587 ++counter;
2591 if (counter == 0) // if counter == 0 then we found nth
2592 SendSysMessage(LANG_COMMAND_NOSKILLFOUND);
2593 return true;
2596 bool ChatHandler::HandleLookupSpellCommand(const char* args)
2598 if(!*args)
2599 return false;
2601 // can be NULL at console call
2602 Player* target = getSelectedPlayer();
2604 std::string namepart = args;
2605 std::wstring wnamepart;
2607 if(!Utf8toWStr(namepart,wnamepart))
2608 return false;
2610 // converting string that we try to find to lower case
2611 wstrToLower( wnamepart );
2613 uint32 counter = 0; // Counter for figure out that we found smth.
2615 // Search in Spell.dbc
2616 for (uint32 id = 0; id < sSpellStore.GetNumRows(); id++)
2618 SpellEntry const *spellInfo = sSpellStore.LookupEntry(id);
2619 if(spellInfo)
2621 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
2622 std::string name = spellInfo->SpellName[loc];
2623 if(name.empty())
2624 continue;
2626 if (!Utf8FitTo(name, wnamepart))
2628 loc = 0;
2629 for(; loc < MAX_LOCALE; ++loc)
2631 if(m_session && loc==m_session->GetSessionDbcLocale())
2632 continue;
2634 name = spellInfo->SpellName[loc];
2635 if(name.empty())
2636 continue;
2638 if (Utf8FitTo(name, wnamepart))
2639 break;
2643 if(loc < MAX_LOCALE)
2645 bool known = target && target->HasSpell(id);
2646 bool learn = (spellInfo->Effect[0] == SPELL_EFFECT_LEARN_SPELL);
2648 uint32 telentCost = GetTalentSpellCost(id);
2650 bool talent = (telentCost > 0);
2651 bool passive = IsPassiveSpell(id);
2652 bool active = target && (target->HasAura(id,0) || target->HasAura(id,1) || target->HasAura(id,2));
2654 // unit32 used to prevent interpreting uint8 as char at output
2655 // find rank of learned spell for learning spell, or talent rank
2656 uint32 rank = telentCost ? telentCost : spellmgr.GetSpellRank(learn ? spellInfo->EffectTriggerSpell[0] : id);
2658 // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
2659 std::ostringstream ss;
2660 if (m_session)
2661 ss << id << " - |cffffffff|Hspell:" << id << "|h[" << name;
2662 else
2663 ss << id << " - " << name;
2665 // include rank in link name
2666 if(rank)
2667 ss << GetMangosString(LANG_SPELL_RANK) << rank;
2669 if (m_session)
2670 ss << " " << localeNames[loc] << "]|h|r";
2671 else
2672 ss << " " << localeNames[loc];
2674 if(talent)
2675 ss << GetMangosString(LANG_TALENT);
2676 if(passive)
2677 ss << GetMangosString(LANG_PASSIVE);
2678 if(learn)
2679 ss << GetMangosString(LANG_LEARN);
2680 if(known)
2681 ss << GetMangosString(LANG_KNOWN);
2682 if(active)
2683 ss << GetMangosString(LANG_ACTIVE);
2685 SendSysMessage(ss.str().c_str());
2687 ++counter;
2691 if (counter == 0) // if counter == 0 then we found nth
2692 SendSysMessage(LANG_COMMAND_NOSPELLFOUND);
2693 return true;
2696 bool ChatHandler::HandleLookupQuestCommand(const char* args)
2698 if(!*args)
2699 return false;
2701 // can be NULL at console call
2702 Player* target = getSelectedPlayer();
2704 std::string namepart = args;
2705 std::wstring wnamepart;
2707 // converting string that we try to find to lower case
2708 if(!Utf8toWStr(namepart,wnamepart))
2709 return false;
2711 wstrToLower(wnamepart);
2713 uint32 counter = 0 ;
2715 ObjectMgr::QuestMap const& qTemplates = objmgr.GetQuestTemplates();
2716 for (ObjectMgr::QuestMap::const_iterator iter = qTemplates.begin(); iter != qTemplates.end(); ++iter)
2718 Quest * qinfo = iter->second;
2720 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
2721 if ( loc_idx >= 0 )
2723 QuestLocale const *il = objmgr.GetQuestLocale(qinfo->GetQuestId());
2724 if (il)
2726 if (il->Title.size() > loc_idx && !il->Title[loc_idx].empty())
2728 std::string title = il->Title[loc_idx];
2730 if (Utf8FitTo(title, wnamepart))
2732 char const* statusStr = "";
2734 if(target)
2736 QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId());
2738 if(status == QUEST_STATUS_COMPLETE)
2740 if(target->GetQuestRewardStatus(qinfo->GetQuestId()))
2741 statusStr = GetMangosString(LANG_COMMAND_QUEST_REWARDED);
2742 else
2743 statusStr = GetMangosString(LANG_COMMAND_QUEST_COMPLETE);
2745 else if(status == QUEST_STATUS_INCOMPLETE)
2746 statusStr = GetMangosString(LANG_COMMAND_QUEST_ACTIVE);
2749 if (m_session)
2750 PSendSysMessage(LANG_QUEST_LIST_CHAT,qinfo->GetQuestId(),qinfo->GetQuestId(),title.c_str(),statusStr);
2751 else
2752 PSendSysMessage(LANG_QUEST_LIST_CONSOLE,qinfo->GetQuestId(),title.c_str(),statusStr);
2753 ++counter;
2754 continue;
2760 std::string title = qinfo->GetTitle();
2761 if(title.empty())
2762 continue;
2764 if (Utf8FitTo(title, wnamepart))
2766 char const* statusStr = "";
2768 if(target)
2770 QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId());
2772 if(status == QUEST_STATUS_COMPLETE)
2774 if(target->GetQuestRewardStatus(qinfo->GetQuestId()))
2775 statusStr = GetMangosString(LANG_COMMAND_QUEST_REWARDED);
2776 else
2777 statusStr = GetMangosString(LANG_COMMAND_QUEST_COMPLETE);
2779 else if(status == QUEST_STATUS_INCOMPLETE)
2780 statusStr = GetMangosString(LANG_COMMAND_QUEST_ACTIVE);
2783 if (m_session)
2784 PSendSysMessage(LANG_QUEST_LIST_CHAT,qinfo->GetQuestId(),qinfo->GetQuestId(),title.c_str(),statusStr);
2785 else
2786 PSendSysMessage(LANG_QUEST_LIST_CONSOLE,qinfo->GetQuestId(),title.c_str(),statusStr);
2788 ++counter;
2792 if (counter==0)
2793 SendSysMessage(LANG_COMMAND_NOQUESTFOUND);
2795 return true;
2798 bool ChatHandler::HandleLookupCreatureCommand(const char* args)
2800 if (!*args)
2801 return false;
2803 std::string namepart = args;
2804 std::wstring wnamepart;
2806 // converting string that we try to find to lower case
2807 if (!Utf8toWStr (namepart,wnamepart))
2808 return false;
2810 wstrToLower (wnamepart);
2812 uint32 counter = 0;
2814 for (uint32 id = 0; id< sCreatureStorage.MaxEntry; ++id)
2816 CreatureInfo const* cInfo = sCreatureStorage.LookupEntry<CreatureInfo> (id);
2817 if(!cInfo)
2818 continue;
2820 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
2821 if (loc_idx >= 0)
2823 CreatureLocale const *cl = objmgr.GetCreatureLocale (id);
2824 if (cl)
2826 if (cl->Name.size() > loc_idx && !cl->Name[loc_idx].empty ())
2828 std::string name = cl->Name[loc_idx];
2830 if (Utf8FitTo (name, wnamepart))
2832 if (m_session)
2833 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str ());
2834 else
2835 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE, id, name.c_str ());
2836 ++counter;
2837 continue;
2843 std::string name = cInfo->Name;
2844 if (name.empty ())
2845 continue;
2847 if (Utf8FitTo(name, wnamepart))
2849 if (m_session)
2850 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str ());
2851 else
2852 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE, id, name.c_str ());
2853 ++counter;
2857 if (counter==0)
2858 SendSysMessage (LANG_COMMAND_NOCREATUREFOUND);
2860 return true;
2863 bool ChatHandler::HandleLookupObjectCommand(const char* args)
2865 if(!*args)
2866 return false;
2868 std::string namepart = args;
2869 std::wstring wnamepart;
2871 // converting string that we try to find to lower case
2872 if(!Utf8toWStr(namepart,wnamepart))
2873 return false;
2875 wstrToLower(wnamepart);
2877 uint32 counter = 0;
2879 for (uint32 id = 0; id< sGOStorage.MaxEntry; id++ )
2881 GameObjectInfo const* gInfo = sGOStorage.LookupEntry<GameObjectInfo>(id);
2882 if(!gInfo)
2883 continue;
2885 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
2886 if ( loc_idx >= 0 )
2888 GameObjectLocale const *gl = objmgr.GetGameObjectLocale(id);
2889 if (gl)
2891 if (gl->Name.size() > loc_idx && !gl->Name[loc_idx].empty())
2893 std::string name = gl->Name[loc_idx];
2895 if (Utf8FitTo(name, wnamepart))
2897 if (m_session)
2898 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, id, id, name.c_str());
2899 else
2900 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, id, name.c_str());
2901 ++counter;
2902 continue;
2908 std::string name = gInfo->name;
2909 if(name.empty())
2910 continue;
2912 if(Utf8FitTo(name, wnamepart))
2914 if (m_session)
2915 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, id, id, name.c_str());
2916 else
2917 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, id, name.c_str());
2918 ++counter;
2922 if(counter==0)
2923 SendSysMessage(LANG_COMMAND_NOGAMEOBJECTFOUND);
2925 return true;
2928 /** \brief GM command level 3 - Create a guild.
2930 * This command allows a GM (level 3) to create a guild.
2932 * The "args" parameter contains the name of the guild leader
2933 * and then the name of the guild.
2936 bool ChatHandler::HandleGuildCreateCommand(const char* args)
2939 if (!*args)
2940 return false;
2942 char *lname = strtok ((char*)args, " ");
2943 char *gname = strtok (NULL, "");
2945 if (!lname)
2946 return false;
2948 if (!gname)
2950 SendSysMessage (LANG_INSERT_GUILD_NAME);
2951 SetSentErrorMessage (true);
2952 return false;
2955 std::string guildname = gname;
2957 Player* player = ObjectAccessor::Instance ().FindPlayerByName (lname);
2958 if (!player)
2960 SendSysMessage (LANG_PLAYER_NOT_FOUND);
2961 SetSentErrorMessage (true);
2962 return false;
2965 if (player->GetGuildId())
2967 SendSysMessage (LANG_PLAYER_IN_GUILD);
2968 return true;
2971 Guild *guild = new Guild;
2972 if (!guild->create (player->GetGUID (),guildname))
2974 delete guild;
2975 SendSysMessage (LANG_GUILD_NOT_CREATED);
2976 SetSentErrorMessage (true);
2977 return false;
2980 objmgr.AddGuild (guild);
2981 return true;
2984 bool ChatHandler::HandleGuildInviteCommand(const char *args)
2986 if (!*args)
2987 return false;
2989 char* par1 = strtok ((char*)args, " ");
2990 char* par2 = strtok (NULL, "");
2991 if(!par1 || !par2)
2992 return false;
2994 std::string glName = par2;
2995 Guild* targetGuild = objmgr.GetGuildByName (glName);
2996 if (!targetGuild)
2997 return false;
2999 std::string plName = par1;
3000 if (!normalizePlayerName (plName))
3002 SendSysMessage (LANG_PLAYER_NOT_FOUND);
3003 SetSentErrorMessage (true);
3004 return false;
3007 uint64 plGuid = 0;
3008 if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3009 plGuid = targetPlayer->GetGUID ();
3010 else
3011 plGuid = objmgr.GetPlayerGUIDByName (plName.c_str ());
3013 if (!plGuid)
3014 false;
3016 // players's guild membership checked in AddMember before add
3017 if (!targetGuild->AddMember (plGuid,targetGuild->GetLowestRank ()))
3018 return false;
3020 return true;
3023 bool ChatHandler::HandleGuildUninviteCommand(const char *args)
3025 if (!*args)
3026 return false;
3028 char* par1 = strtok ((char*)args, " ");
3029 if(!par1)
3030 return false;
3032 std::string plName = par1;
3033 if (!normalizePlayerName (plName))
3035 SendSysMessage (LANG_PLAYER_NOT_FOUND);
3036 SetSentErrorMessage (true);
3037 return false;
3040 uint64 plGuid = 0;
3041 uint32 glId = 0;
3042 if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3044 plGuid = targetPlayer->GetGUID ();
3045 glId = targetPlayer->GetGuildId ();
3047 else
3049 plGuid = objmgr.GetPlayerGUIDByName (plName.c_str ());
3050 glId = Player::GetGuildIdFromDB (plGuid);
3053 if (!plGuid || !glId)
3054 return false;
3056 Guild* targetGuild = objmgr.GetGuildById (glId);
3057 if (!targetGuild)
3058 return false;
3060 targetGuild->DelMember (plGuid);
3062 return true;
3065 bool ChatHandler::HandleGuildRankCommand(const char *args)
3067 if (!*args)
3068 return false;
3070 char* par1 = strtok ((char*)args, " ");
3071 char* par2 = strtok (NULL, " ");
3072 if (!par1 || !par2)
3073 return false;
3074 std::string plName = par1;
3075 if (!normalizePlayerName (plName))
3077 SendSysMessage (LANG_PLAYER_NOT_FOUND);
3078 SetSentErrorMessage (true);
3079 return false;
3082 uint64 plGuid = 0;
3083 uint32 glId = 0;
3084 if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3086 plGuid = targetPlayer->GetGUID ();
3087 glId = targetPlayer->GetGuildId ();
3089 else
3091 plGuid = objmgr.GetPlayerGUIDByName (plName.c_str ());
3092 glId = Player::GetGuildIdFromDB (plGuid);
3095 if (!plGuid || !glId)
3096 return false;
3098 Guild* targetGuild = objmgr.GetGuildById (glId);
3099 if (!targetGuild)
3100 return false;
3102 uint32 newrank = uint32 (atoi (par2));
3103 if (newrank > targetGuild->GetLowestRank ())
3104 return false;
3106 targetGuild->ChangeRank (plGuid,newrank);
3108 return true;
3111 bool ChatHandler::HandleGuildDeleteCommand(const char* args)
3113 if (!*args)
3114 return false;
3116 char* par1 = strtok ((char*)args, " ");
3117 if (!par1)
3118 return false;
3120 std::string gld = par1;
3122 Guild* targetGuild = objmgr.GetGuildByName (gld);
3123 if (!targetGuild)
3124 return false;
3126 targetGuild->Disband ();
3128 return true;
3131 bool ChatHandler::HandleGetDistanceCommand(const char* /*args*/)
3133 Unit* pUnit = getSelectedUnit();
3135 if(!pUnit)
3137 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3138 SetSentErrorMessage(true);
3139 return false;
3142 PSendSysMessage(LANG_DISTANCE, m_session->GetPlayer()->GetDistance(pUnit),m_session->GetPlayer()->GetDistance2d(pUnit));
3144 return true;
3147 // FIX-ME!!!
3149 bool ChatHandler::HandleAddWeaponCommand(const char* /*args*/)
3151 /*if (!*args)
3152 return false;
3154 uint64 guid = m_session->GetPlayer()->GetSelection();
3155 if (guid == 0)
3157 SendSysMessage(LANG_NO_SELECTION);
3158 return true;
3161 Creature *pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
3163 if(!pCreature)
3165 SendSysMessage(LANG_SELECT_CREATURE);
3166 return true;
3169 char* pSlotID = strtok((char*)args, " ");
3170 if (!pSlotID)
3171 return false;
3173 char* pItemID = strtok(NULL, " ");
3174 if (!pItemID)
3175 return false;
3177 uint32 ItemID = atoi(pItemID);
3178 uint32 SlotID = atoi(pSlotID);
3180 ItemPrototype* tmpItem = objmgr.GetItemPrototype(ItemID);
3182 bool added = false;
3183 if(tmpItem)
3185 switch(SlotID)
3187 case 1:
3188 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID);
3189 added = true;
3190 break;
3191 case 2:
3192 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID);
3193 added = true;
3194 break;
3195 case 3:
3196 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID);
3197 added = true;
3198 break;
3199 default:
3200 PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST,SlotID);
3201 added = false;
3202 break;
3204 if(added)
3206 PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT,ItemID,tmpItem->Name1,SlotID);
3209 else
3211 PSendSysMessage(LANG_ITEM_NOT_FOUND,ItemID);
3212 return true;
3215 return true;
3218 bool ChatHandler::HandleDieCommand(const char* /*args*/)
3220 Unit* target = getSelectedUnit();
3222 if(!target || !m_session->GetPlayer()->GetSelection())
3224 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3225 SetSentErrorMessage(true);
3226 return false;
3229 if( target->isAlive() )
3231 m_session->GetPlayer()->DealDamage(target, target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
3234 return true;
3237 bool ChatHandler::HandleDamageCommand(const char * args)
3239 if (!*args)
3240 return false;
3242 Unit* target = getSelectedUnit();
3244 if(!target || !m_session->GetPlayer()->GetSelection())
3246 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3247 SetSentErrorMessage(true);
3248 return false;
3251 if( !target->isAlive() )
3252 return true;
3254 char* damageStr = strtok((char*)args, " ");
3255 if(!damageStr)
3256 return false;
3258 int32 damage = atoi((char*)damageStr);
3259 if(damage <=0)
3260 return true;
3262 char* schoolStr = strtok((char*)NULL, " ");
3264 // flat melee damage without resistence/etc reduction
3265 if(!schoolStr)
3267 m_session->GetPlayer()->DealDamage(target, damage, NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
3268 m_session->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2, target, 1, SPELL_SCHOOL_MASK_NORMAL, damage, 0, 0, VICTIMSTATE_NORMAL, 0);
3269 return true;
3272 uint32 school = schoolStr ? atoi((char*)schoolStr) : SPELL_SCHOOL_NORMAL;
3273 if(school >= MAX_SPELL_SCHOOL)
3274 return false;
3276 SpellSchoolMask schoolmask = SpellSchoolMask(1 << school);
3278 if ( schoolmask & SPELL_SCHOOL_MASK_NORMAL )
3279 damage = m_session->GetPlayer()->CalcArmorReducedDamage(target, damage);
3281 char* spellStr = strtok((char*)NULL, " ");
3283 // melee damage by specific school
3284 if(!spellStr)
3286 uint32 absorb = 0;
3287 uint32 resist = 0;
3289 m_session->GetPlayer()->CalcAbsorbResist(target,schoolmask, SPELL_DIRECT_DAMAGE, damage, &absorb, &resist);
3291 if (damage <= absorb + resist)
3292 return true;
3294 damage -= absorb + resist;
3296 m_session->GetPlayer()->DealDamage(target, damage, NULL, DIRECT_DAMAGE, schoolmask, NULL, false);
3297 m_session->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2, target, 1, schoolmask, damage, absorb, resist, VICTIMSTATE_NORMAL, 0);
3298 return true;
3301 // non-melee damage
3303 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3304 uint32 spellid = extractSpellIdFromLink((char*)args);
3305 if(!spellid || !sSpellStore.LookupEntry(spellid))
3306 return false;
3308 m_session->GetPlayer()->SpellNonMeleeDamageLog(target, spellid, damage, false);
3309 return true;
3312 bool ChatHandler::HandleModifyArenaCommand(const char * args)
3314 if (!*args)
3315 return false;
3317 Player *target = getSelectedPlayer();
3318 if(!target)
3320 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3321 SetSentErrorMessage(true);
3322 return false;
3325 int32 amount = (uint32)atoi(args);
3327 target->ModifyArenaPoints(amount);
3329 PSendSysMessage(LANG_COMMAND_MODIFY_ARENA, target->GetName(), target->GetArenaPoints());
3331 return true;
3334 bool ChatHandler::HandleReviveCommand(const char* args)
3336 Player* SelectedPlayer = NULL;
3338 if (*args)
3340 std::string name = args;
3341 if(!normalizePlayerName(name))
3343 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3344 SetSentErrorMessage(true);
3345 return false;
3348 SelectedPlayer = objmgr.GetPlayer(name.c_str());
3350 else
3351 SelectedPlayer = getSelectedPlayer();
3353 if(!SelectedPlayer)
3355 SendSysMessage(LANG_NO_CHAR_SELECTED);
3356 SetSentErrorMessage(true);
3357 return false;
3360 SelectedPlayer->ResurrectPlayer(0.5f);
3361 SelectedPlayer->SpawnCorpseBones();
3362 SelectedPlayer->SaveToDB();
3363 return true;
3366 bool ChatHandler::HandleAuraCommand(const char* args)
3368 char* px = strtok((char*)args, " ");
3369 if (!px)
3370 return false;
3372 Unit *target = getSelectedUnit();
3373 if(!target)
3375 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3376 SetSentErrorMessage(true);
3377 return false;
3380 uint32 spellID = (uint32)atoi(px);
3381 SpellEntry const *spellInfo = sSpellStore.LookupEntry( spellID );
3382 if(spellInfo)
3384 for(uint32 i = 0;i<3;i++)
3386 uint8 eff = spellInfo->Effect[i];
3387 if (eff>=TOTAL_SPELL_EFFECTS)
3388 continue;
3389 if( IsAreaAuraEffect(eff) ||
3390 eff == SPELL_EFFECT_APPLY_AURA ||
3391 eff == SPELL_EFFECT_PERSISTENT_AREA_AURA )
3393 Aura *Aur = CreateAura(spellInfo, i, NULL, target);
3394 target->AddAura(Aur);
3399 return true;
3402 bool ChatHandler::HandleUnAuraCommand(const char* args)
3404 char* px = strtok((char*)args, " ");
3405 if (!px)
3406 return false;
3408 Unit *target = getSelectedUnit();
3409 if(!target)
3411 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3412 SetSentErrorMessage(true);
3413 return false;
3416 std::string argstr = args;
3417 if (argstr == "all")
3419 target->RemoveAllAuras();
3420 return true;
3423 uint32 spellID = (uint32)atoi(px);
3424 target->RemoveAurasDueToSpell(spellID);
3426 return true;
3429 bool ChatHandler::HandleLinkGraveCommand(const char* args)
3431 if(!*args)
3432 return false;
3434 char* px = strtok((char*)args, " ");
3435 if (!px)
3436 return false;
3438 uint32 g_id = (uint32)atoi(px);
3440 uint32 g_team;
3442 char* px2 = strtok(NULL, " ");
3444 if (!px2)
3445 g_team = 0;
3446 else if (strncmp(px2,"horde",6)==0)
3447 g_team = HORDE;
3448 else if (strncmp(px2,"alliance",9)==0)
3449 g_team = ALLIANCE;
3450 else
3451 return false;
3453 WorldSafeLocsEntry const* graveyard = sWorldSafeLocsStore.LookupEntry(g_id);
3455 if(!graveyard )
3457 PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST, g_id);
3458 SetSentErrorMessage(true);
3459 return false;
3462 Player* player = m_session->GetPlayer();
3464 uint32 zoneId = player->GetZoneId();
3466 AreaTableEntry const *areaEntry = GetAreaEntryByAreaID(zoneId);
3467 if(!areaEntry || areaEntry->zone !=0 )
3469 PSendSysMessage(LANG_COMMAND_GRAVEYARDWRONGZONE, g_id,zoneId);
3470 SetSentErrorMessage(true);
3471 return false;
3474 if(graveyard->map_id != areaEntry->mapid && g_team != 0)
3476 SendSysMessage(LANG_COMMAND_GRAVEYARDWRONGTEAM);
3477 SetSentErrorMessage(true);
3478 return false;
3481 if(objmgr.AddGraveYardLink(g_id,player->GetZoneId(),g_team))
3482 PSendSysMessage(LANG_COMMAND_GRAVEYARDLINKED, g_id,zoneId);
3483 else
3484 PSendSysMessage(LANG_COMMAND_GRAVEYARDALRLINKED, g_id,zoneId);
3486 return true;
3489 bool ChatHandler::HandleNearGraveCommand(const char* args)
3491 uint32 g_team;
3493 size_t argslen = strlen(args);
3495 if(!*args)
3496 g_team = 0;
3497 else if (strncmp((char*)args,"horde",argslen)==0)
3498 g_team = HORDE;
3499 else if (strncmp((char*)args,"alliance",argslen)==0)
3500 g_team = ALLIANCE;
3501 else
3502 return false;
3504 Player* player = m_session->GetPlayer();
3506 WorldSafeLocsEntry const* graveyard = objmgr.GetClosestGraveYard(
3507 player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(),player->GetMapId(),g_team);
3509 if(graveyard)
3511 uint32 g_id = graveyard->ID;
3513 GraveYardData const* data = objmgr.FindGraveYardData(g_id,player->GetZoneId());
3514 if (!data)
3516 PSendSysMessage(LANG_COMMAND_GRAVEYARDERROR,g_id);
3517 SetSentErrorMessage(true);
3518 return false;
3521 g_team = data->team;
3523 std::string team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_NOTEAM);
3525 if(g_team == 0)
3526 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ANY);
3527 else if(g_team == HORDE)
3528 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE);
3529 else if(g_team == ALLIANCE)
3530 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE);
3532 PSendSysMessage(LANG_COMMAND_GRAVEYARDNEAREST, g_id,team_name.c_str(),player->GetZoneId());
3534 else
3536 std::string team_name;
3538 if(g_team == 0)
3539 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ANY);
3540 else if(g_team == HORDE)
3541 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE);
3542 else if(g_team == ALLIANCE)
3543 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE);
3545 if(g_team == ~uint32(0))
3546 PSendSysMessage(LANG_COMMAND_ZONENOGRAVEYARDS, player->GetZoneId());
3547 else
3548 PSendSysMessage(LANG_COMMAND_ZONENOGRAFACTION, player->GetZoneId(),team_name.c_str());
3551 return true;
3554 bool ChatHandler::HandleSpawnTransportCommand(const char* /*args*/)
3556 return true;
3559 //play npc emote
3560 bool ChatHandler::HandlePlayEmoteCommand(const char* args)
3562 uint32 emote = atoi((char*)args);
3564 Creature* target = getSelectedCreature();
3565 if(!target)
3567 SendSysMessage(LANG_SELECT_CREATURE);
3568 SetSentErrorMessage(true);
3569 return false;
3572 target->SetUInt32Value(UNIT_NPC_EMOTESTATE,emote);
3574 return true;
3577 bool ChatHandler::HandleNpcInfoCommand(const char* /*args*/)
3579 Creature* target = getSelectedCreature();
3581 if(!target)
3583 SendSysMessage(LANG_SELECT_CREATURE);
3584 SetSentErrorMessage(true);
3585 return false;
3588 uint32 faction = target->getFaction();
3589 uint32 npcflags = target->GetUInt32Value(UNIT_NPC_FLAGS);
3590 uint32 displayid = target->GetDisplayId();
3591 uint32 nativeid = target->GetNativeDisplayId();
3592 uint32 Entry = target->GetEntry();
3593 CreatureInfo const* cInfo = target->GetCreatureInfo();
3595 int32 curRespawnDelay = target->GetRespawnTimeEx()-time(NULL);
3596 if(curRespawnDelay < 0)
3597 curRespawnDelay = 0;
3598 std::string curRespawnDelayStr = secsToTimeString(curRespawnDelay,true);
3599 std::string defRespawnDelayStr = secsToTimeString(target->GetRespawnDelay(),true);
3601 PSendSysMessage(LANG_NPCINFO_CHAR, target->GetDBTableGUIDLow(), faction, npcflags, Entry, displayid, nativeid);
3602 PSendSysMessage(LANG_NPCINFO_LEVEL, target->getLevel());
3603 PSendSysMessage(LANG_NPCINFO_HEALTH,target->GetCreateHealth(), target->GetMaxHealth(), target->GetHealth());
3604 PSendSysMessage(LANG_NPCINFO_FLAGS, target->GetUInt32Value(UNIT_FIELD_FLAGS), target->GetUInt32Value(UNIT_DYNAMIC_FLAGS), target->getFaction());
3605 PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES, defRespawnDelayStr.c_str(),curRespawnDelayStr.c_str());
3606 PSendSysMessage(LANG_NPCINFO_LOOT, cInfo->lootid,cInfo->pickpocketLootId,cInfo->SkinLootId);
3607 PSendSysMessage(LANG_NPCINFO_DUNGEON_ID, target->GetInstanceId());
3608 PSendSysMessage(LANG_NPCINFO_POSITION,float(target->GetPositionX()), float(target->GetPositionY()), float(target->GetPositionZ()));
3610 if ((npcflags & UNIT_NPC_FLAG_VENDOR) )
3612 SendSysMessage(LANG_NPCINFO_VENDOR);
3614 if ((npcflags & UNIT_NPC_FLAG_TRAINER) )
3616 SendSysMessage(LANG_NPCINFO_TRAINER);
3619 return true;
3622 bool ChatHandler::HandleExploreCheatCommand(const char* args)
3624 if (!*args)
3625 return false;
3627 int flag = atoi((char*)args);
3629 Player *chr = getSelectedPlayer();
3630 if (chr == NULL)
3632 SendSysMessage(LANG_NO_CHAR_SELECTED);
3633 SetSentErrorMessage(true);
3634 return false;
3637 if (flag != 0)
3639 PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL, chr->GetName());
3640 if(chr!=m_session->GetPlayer())
3641 ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_ALL,m_session->GetPlayer()->GetName());
3643 else
3645 PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING, chr->GetName());
3646 if(chr!=m_session->GetPlayer())
3647 ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_NOTHING,m_session->GetPlayer()->GetName());
3650 for (uint8 i=0; i<128; i++)
3652 if (flag != 0)
3654 m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1+i,0xFFFFFFFF);
3656 else
3658 m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1+i,0);
3662 return true;
3665 bool ChatHandler::HandleHoverCommand(const char* args)
3667 char* px = strtok((char*)args, " ");
3668 uint32 flag;
3669 if (!px)
3670 flag = 1;
3671 else
3672 flag = atoi(px);
3674 m_session->GetPlayer()->SetHover(flag);
3676 if (flag)
3677 SendSysMessage(LANG_HOVER_ENABLED);
3678 else
3679 SendSysMessage(LANG_HOVER_DISABLED);
3681 return true;
3684 bool ChatHandler::HandleLevelUpCommand(const char* args)
3686 char* px = strtok((char*)args, " ");
3687 char* py = strtok((char*)NULL, " ");
3689 // command format parsing
3690 char* pname = (char*)NULL;
3691 int addlevel = 1;
3693 if(px && py) // .levelup name level
3695 addlevel = atoi(py);
3696 pname = px;
3698 else if(px && !py) // .levelup name OR .levelup level
3700 if(isalpha(px[0])) // .levelup name
3701 pname = px;
3702 else // .levelup level
3703 addlevel = atoi(px);
3705 // else .levelup - nothing do for prepering
3707 // player
3708 Player *chr = NULL;
3709 uint64 chr_guid = 0;
3711 std::string name;
3713 if(pname) // player by name
3715 name = pname;
3716 if(!normalizePlayerName(name))
3718 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3719 SetSentErrorMessage(true);
3720 return false;
3723 chr = objmgr.GetPlayer(name.c_str());
3724 if(!chr) // not in game
3726 chr_guid = objmgr.GetPlayerGUIDByName(name);
3727 if (chr_guid == 0)
3729 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3730 SetSentErrorMessage(true);
3731 return false;
3735 else // player by selection
3737 chr = getSelectedPlayer();
3739 if (chr == NULL)
3741 SendSysMessage(LANG_NO_CHAR_SELECTED);
3742 SetSentErrorMessage(true);
3743 return false;
3746 name = chr->GetName();
3749 assert(chr || chr_guid);
3751 int32 oldlevel = chr ? chr->getLevel() : Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL,chr_guid);
3752 int32 newlevel = oldlevel + addlevel;
3753 if(newlevel < 1)
3754 newlevel = 1;
3755 if(newlevel > 255) // hardcoded maximum level
3756 newlevel = 255;
3758 if(chr)
3760 chr->GiveLevel(newlevel);
3761 chr->InitTalentForLevel();
3762 chr->SetUInt32Value(PLAYER_XP,0);
3764 if(oldlevel == newlevel)
3765 ChatHandler(chr).SendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET);
3766 else
3767 if(oldlevel < newlevel)
3768 ChatHandler(chr).PSendSysMessage(LANG_YOURS_LEVEL_UP,newlevel-oldlevel);
3769 else
3770 if(oldlevel > newlevel)
3771 ChatHandler(chr).PSendSysMessage(LANG_YOURS_LEVEL_DOWN,newlevel-oldlevel);
3773 else
3775 // update levle and XP at level, all other will be updated at loading
3776 Tokens values;
3777 Player::LoadValuesArrayFromDB(values,chr_guid);
3778 Player::SetUInt32ValueInArray(values,UNIT_FIELD_LEVEL,newlevel);
3779 Player::SetUInt32ValueInArray(values,PLAYER_XP,0);
3780 Player::SaveValuesArrayInDB(values,chr_guid);
3783 if(m_session->GetPlayer() != chr) // including chr==NULL
3784 PSendSysMessage(LANG_YOU_CHANGE_LVL,name.c_str(),newlevel);
3785 return true;
3788 bool ChatHandler::HandleShowAreaCommand(const char* args)
3790 if (!*args)
3791 return false;
3793 int area = atoi((char*)args);
3795 Player *chr = getSelectedPlayer();
3796 if (chr == NULL)
3798 SendSysMessage(LANG_NO_CHAR_SELECTED);
3799 SetSentErrorMessage(true);
3800 return false;
3803 int offset = area / 32;
3804 uint32 val = (uint32)(1 << (area % 32));
3806 if(offset >= 128)
3808 SendSysMessage(LANG_BAD_VALUE);
3809 SetSentErrorMessage(true);
3810 return false;
3813 uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
3814 chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields | val));
3816 SendSysMessage(LANG_EXPLORE_AREA);
3817 return true;
3820 bool ChatHandler::HandleHideAreaCommand(const char* args)
3822 if (!*args)
3823 return false;
3825 int area = atoi((char*)args);
3827 Player *chr = getSelectedPlayer();
3828 if (chr == NULL)
3830 SendSysMessage(LANG_NO_CHAR_SELECTED);
3831 SetSentErrorMessage(true);
3832 return false;
3835 int offset = area / 32;
3836 uint32 val = (uint32)(1 << (area % 32));
3838 if(offset >= 128)
3840 SendSysMessage(LANG_BAD_VALUE);
3841 SetSentErrorMessage(true);
3842 return false;
3845 uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
3846 chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields ^ val));
3848 SendSysMessage(LANG_UNEXPLORE_AREA);
3849 return true;
3852 bool ChatHandler::HandleUpdate(const char* args)
3854 if(!*args)
3855 return false;
3857 uint32 updateIndex;
3858 uint32 value;
3860 char* pUpdateIndex = strtok((char*)args, " ");
3862 Unit* chr = getSelectedUnit();
3863 if (chr == NULL)
3865 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3866 SetSentErrorMessage(true);
3867 return false;
3870 if(!pUpdateIndex)
3872 return true;
3874 updateIndex = atoi(pUpdateIndex);
3875 //check updateIndex
3876 if(chr->GetTypeId() == TYPEID_PLAYER)
3878 if (updateIndex>=PLAYER_END) return true;
3880 else
3882 if (updateIndex>=UNIT_END) return true;
3885 char* pvalue = strtok(NULL, " ");
3886 if (!pvalue)
3888 value=chr->GetUInt32Value(updateIndex);
3890 PSendSysMessage(LANG_UPDATE, chr->GetGUIDLow(),updateIndex,value);
3891 return true;
3894 value=atoi(pvalue);
3896 PSendSysMessage(LANG_UPDATE_CHANGE, chr->GetGUIDLow(),updateIndex,value);
3898 chr->SetUInt32Value(updateIndex,value);
3900 return true;
3903 bool ChatHandler::HandleBankCommand(const char* /*args*/)
3905 m_session->SendShowBank( m_session->GetPlayer()->GetGUID() );
3907 return true;
3910 bool ChatHandler::HandleChangeWeather(const char* args)
3912 if(!*args)
3913 return false;
3915 //Weather is OFF
3916 if (!sWorld.getConfig(CONFIG_WEATHER))
3918 SendSysMessage(LANG_WEATHER_DISABLED);
3919 SetSentErrorMessage(true);
3920 return false;
3923 //*Change the weather of a cell
3924 char* px = strtok((char*)args, " ");
3925 char* py = strtok(NULL, " ");
3927 if (!px || !py)
3928 return false;
3930 uint32 type = (uint32)atoi(px); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
3931 float grade = (float)atof(py); //0 to 1, sending -1 is instand good weather
3933 Player *player = m_session->GetPlayer();
3934 uint32 zoneid = player->GetZoneId();
3936 Weather* wth = sWorld.FindWeather(zoneid);
3938 if(!wth)
3939 wth = sWorld.AddWeather(zoneid);
3940 if(!wth)
3942 SendSysMessage(LANG_NO_WEATHER);
3943 SetSentErrorMessage(true);
3944 return false;
3947 wth->SetWeather(WeatherType(type), grade);
3949 return true;
3952 bool ChatHandler::HandleSetValue(const char* args)
3954 if(!*args)
3955 return false;
3957 char* px = strtok((char*)args, " ");
3958 char* py = strtok(NULL, " ");
3959 char* pz = strtok(NULL, " ");
3961 if (!px || !py)
3962 return false;
3964 Unit* target = getSelectedUnit();
3965 if(!target)
3967 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3968 SetSentErrorMessage(true);
3969 return false;
3972 uint64 guid = target->GetGUID();
3974 uint32 Opcode = (uint32)atoi(px);
3975 if(Opcode >= target->GetValuesCount())
3977 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, GUID_LOPART(guid), target->GetValuesCount());
3978 return false;
3980 uint32 iValue;
3981 float fValue;
3982 bool isint32 = true;
3983 if(pz)
3984 isint32 = (bool)atoi(pz);
3985 if(isint32)
3987 iValue = (uint32)atoi(py);
3988 sLog.outDebug(GetMangosString(LANG_SET_UINT), GUID_LOPART(guid), Opcode, iValue);
3989 target->SetUInt32Value( Opcode , iValue );
3990 PSendSysMessage(LANG_SET_UINT_FIELD, GUID_LOPART(guid), Opcode,iValue);
3992 else
3994 fValue = (float)atof(py);
3995 sLog.outDebug(GetMangosString(LANG_SET_FLOAT), GUID_LOPART(guid), Opcode, fValue);
3996 target->SetFloatValue( Opcode , fValue );
3997 PSendSysMessage(LANG_SET_FLOAT_FIELD, GUID_LOPART(guid), Opcode,fValue);
4000 return true;
4003 bool ChatHandler::HandleGetValue(const char* args)
4005 if(!*args)
4006 return false;
4008 char* px = strtok((char*)args, " ");
4009 char* pz = strtok(NULL, " ");
4011 if (!px)
4012 return false;
4014 Unit* target = getSelectedUnit();
4015 if(!target)
4017 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4018 SetSentErrorMessage(true);
4019 return false;
4022 uint64 guid = target->GetGUID();
4024 uint32 Opcode = (uint32)atoi(px);
4025 if(Opcode >= target->GetValuesCount())
4027 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, GUID_LOPART(guid), target->GetValuesCount());
4028 return false;
4030 uint32 iValue;
4031 float fValue;
4032 bool isint32 = true;
4033 if(pz)
4034 isint32 = (bool)atoi(pz);
4036 if(isint32)
4038 iValue = target->GetUInt32Value( Opcode );
4039 sLog.outDebug(GetMangosString(LANG_GET_UINT), GUID_LOPART(guid), Opcode, iValue);
4040 PSendSysMessage(LANG_GET_UINT_FIELD, GUID_LOPART(guid), Opcode, iValue);
4042 else
4044 fValue = target->GetFloatValue( Opcode );
4045 sLog.outDebug(GetMangosString(LANG_GET_FLOAT), GUID_LOPART(guid), Opcode, fValue);
4046 PSendSysMessage(LANG_GET_FLOAT_FIELD, GUID_LOPART(guid), Opcode, fValue);
4049 return true;
4052 bool ChatHandler::HandleSet32Bit(const char* args)
4054 if(!*args)
4055 return false;
4057 char* px = strtok((char*)args, " ");
4058 char* py = strtok(NULL, " ");
4060 if (!px || !py)
4061 return false;
4063 uint32 Opcode = (uint32)atoi(px);
4064 uint32 Value = (uint32)atoi(py);
4065 if (Value > 32) //uint32 = 32 bits
4066 return false;
4068 sLog.outDebug(GetMangosString(LANG_SET_32BIT), Opcode, Value);
4070 m_session->GetPlayer( )->SetUInt32Value( Opcode , 2^Value );
4072 PSendSysMessage(LANG_SET_32BIT_FIELD, Opcode,1);
4073 return true;
4076 bool ChatHandler::HandleMod32Value(const char* args)
4078 if(!*args)
4079 return false;
4081 char* px = strtok((char*)args, " ");
4082 char* py = strtok(NULL, " ");
4084 if (!px || !py)
4085 return false;
4087 uint32 Opcode = (uint32)atoi(px);
4088 int Value = atoi(py);
4090 if(Opcode >= m_session->GetPlayer()->GetValuesCount())
4092 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, m_session->GetPlayer()->GetGUIDLow(), m_session->GetPlayer( )->GetValuesCount());
4093 return false;
4096 sLog.outDebug(GetMangosString(LANG_CHANGE_32BIT), Opcode, Value);
4098 int CurrentValue = (int)m_session->GetPlayer( )->GetUInt32Value( Opcode );
4100 CurrentValue += Value;
4101 m_session->GetPlayer( )->SetUInt32Value( Opcode , (uint32)CurrentValue );
4103 PSendSysMessage(LANG_CHANGE_32BIT_FIELD, Opcode,CurrentValue);
4105 return true;
4108 bool ChatHandler::HandleAddTeleCommand(const char * args)
4110 if(!*args)
4111 return false;
4113 Player *player=m_session->GetPlayer();
4114 if (!player)
4115 return false;
4117 std::string name = args;
4119 if(objmgr.GetGameTele(name))
4121 SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST);
4122 SetSentErrorMessage(true);
4123 return false;
4126 GameTele tele;
4127 tele.position_x = player->GetPositionX();
4128 tele.position_y = player->GetPositionY();
4129 tele.position_z = player->GetPositionZ();
4130 tele.orientation = player->GetOrientation();
4131 tele.mapId = player->GetMapId();
4132 tele.name = name;
4134 if(objmgr.AddGameTele(tele))
4136 SendSysMessage(LANG_COMMAND_TP_ADDED);
4138 else
4140 SendSysMessage(LANG_COMMAND_TP_ADDEDERR);
4141 SetSentErrorMessage(true);
4142 return false;
4145 return true;
4148 bool ChatHandler::HandleDelTeleCommand(const char * args)
4150 if(!*args)
4151 return false;
4153 std::string name = args;
4155 if(!objmgr.DeleteGameTele(name))
4157 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
4158 SetSentErrorMessage(true);
4159 return false;
4162 SendSysMessage(LANG_COMMAND_TP_DELETED);
4163 return true;
4166 bool ChatHandler::HandleListAurasCommand (const char * /*args*/)
4168 Unit *unit = getSelectedUnit();
4169 if(!unit)
4171 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4172 SetSentErrorMessage(true);
4173 return false;
4176 char const* talentStr = GetMangosString(LANG_TALENT);
4177 char const* passiveStr = GetMangosString(LANG_PASSIVE);
4179 Unit::AuraMap const& uAuras = unit->GetAuras();
4180 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS, uAuras.size());
4181 for (Unit::AuraMap::const_iterator itr = uAuras.begin(); itr != uAuras.end(); ++itr)
4183 bool talent = GetTalentSpellCost(itr->second->GetId()) > 0;
4184 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL, itr->second->GetId(), itr->second->GetEffIndex(),
4185 itr->second->GetModifier()->m_auraname, itr->second->GetAuraDuration(), itr->second->GetAuraMaxDuration(),
4186 itr->second->GetSpellProto()->SpellName[m_session->GetSessionDbcLocale()],
4187 (itr->second->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4188 IS_PLAYER_GUID(itr->second->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr->second->GetCasterGUID()));
4190 for (int i = 0; i < TOTAL_AURAS; i++)
4192 Unit::AuraList const& uAuraList = unit->GetAurasByType(AuraType(i));
4193 if (uAuraList.empty()) continue;
4194 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE, uAuraList.size(), i);
4195 for (Unit::AuraList::const_iterator itr = uAuraList.begin(); itr != uAuraList.end(); ++itr)
4197 bool talent = GetTalentSpellCost((*itr)->GetId()) > 0;
4198 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE, (*itr)->GetId(), (*itr)->GetEffIndex(),
4199 (*itr)->GetSpellProto()->SpellName[m_session->GetSessionDbcLocale()],((*itr)->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4200 IS_PLAYER_GUID((*itr)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr)->GetCasterGUID()));
4203 return true;
4206 bool ChatHandler::HandleResetHonorCommand (const char * args)
4208 char* pName = strtok((char*)args, "");
4209 Player *player = NULL;
4210 if (pName)
4212 std::string name = pName;
4213 if(!normalizePlayerName(name))
4215 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4216 SetSentErrorMessage(true);
4217 return false;
4220 uint64 guid = objmgr.GetPlayerGUIDByName(name.c_str());
4221 player = objmgr.GetPlayer(guid);
4223 else
4224 player = getSelectedPlayer();
4226 if(!player)
4228 SendSysMessage(LANG_NO_CHAR_SELECTED);
4229 return true;
4232 player->SetUInt32Value(PLAYER_FIELD_KILLS, 0);
4233 player->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS, 0);
4234 player->SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY, 0);
4235 player->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION, 0);
4236 player->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION, 0);
4238 return true;
4241 static bool HandleResetStatsOrLevelHelper(Player* player)
4243 PlayerInfo const *info = objmgr.GetPlayerInfo(player->getRace(), player->getClass());
4244 if(!info) return false;
4246 ChrClassesEntry const* cEntry = sChrClassesStore.LookupEntry(player->getClass());
4247 if(!cEntry)
4249 sLog.outError("Class %u not found in DBC (Wrong DBC files?)",player->getClass());
4250 return false;
4253 uint8 powertype = cEntry->powerType;
4255 uint32 unitfield;
4256 if(powertype == POWER_RAGE)
4257 unitfield = 0x1100EE00;
4258 else if(powertype == POWER_ENERGY)
4259 unitfield = 0x00000000;
4260 else if(powertype == POWER_MANA)
4261 unitfield = 0x0000EE00;
4262 else
4264 sLog.outError("Invalid default powertype %u for player (class %u)",powertype,player->getClass());
4265 return false;
4268 // reset m_form if no aura
4269 if(!player->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT))
4270 player->m_form = FORM_NONE;
4272 player->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, DEFAULT_WORLD_OBJECT_SIZE );
4273 player->SetFloatValue(UNIT_FIELD_COMBATREACH, 1.5f );
4275 player->setFactionForRace(player->getRace());
4277 player->SetUInt32Value(UNIT_FIELD_BYTES_0, ( ( player->getRace() ) | ( player->getClass() << 8 ) | ( player->getGender() << 16 ) | ( powertype << 24 ) ) );
4279 // reset only if player not in some form;
4280 if(player->m_form==FORM_NONE)
4282 switch(player->getGender())
4284 case GENDER_FEMALE:
4285 player->SetDisplayId(info->displayId_f);
4286 player->SetNativeDisplayId(info->displayId_f);
4287 break;
4288 case GENDER_MALE:
4289 player->SetDisplayId(info->displayId_m);
4290 player->SetNativeDisplayId(info->displayId_m);
4291 break;
4292 default:
4293 break;
4297 // set UNIT_FIELD_BYTES_1 to init state but preserve m_form value
4298 player->SetUInt32Value(UNIT_FIELD_BYTES_1, unitfield);
4299 player->SetByteValue(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_UNK3 | UNIT_BYTE2_FLAG_UNK5 );
4300 player->SetByteValue(UNIT_FIELD_BYTES_2, 3, player->m_form);
4302 player->SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
4304 //-1 is default value
4305 player->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX, uint32(-1));
4307 //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000 );
4308 return true;
4311 bool ChatHandler::HandleResetLevelCommand(const char * args)
4313 char* pName = strtok((char*)args, "");
4314 Player *player = NULL;
4315 if (pName)
4317 std::string name = pName;
4318 if(!normalizePlayerName(name))
4320 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4321 SetSentErrorMessage(true);
4322 return false;
4325 uint64 guid = objmgr.GetPlayerGUIDByName(name.c_str());
4326 player = objmgr.GetPlayer(guid);
4328 else
4329 player = getSelectedPlayer();
4331 if(!player)
4333 SendSysMessage(LANG_NO_CHAR_SELECTED);
4334 SetSentErrorMessage(true);
4335 return false;
4338 if(!HandleResetStatsOrLevelHelper(player))
4339 return false;
4341 player->SetLevel(1);
4342 player->InitStatsForLevel(true);
4343 player->InitTaxiNodesForLevel();
4344 player->InitTalentForLevel();
4345 player->SetUInt32Value(PLAYER_XP,0);
4347 // reset level to summoned pet
4348 Pet* pet = player->GetPet();
4349 if(pet && pet->getPetType()==SUMMON_PET)
4350 pet->InitStatsForLevel(1);
4352 return true;
4355 bool ChatHandler::HandleResetStatsCommand(const char * args)
4357 char* pName = strtok((char*)args, "");
4358 Player *player = NULL;
4359 if (pName)
4361 std::string name = pName;
4362 if(!normalizePlayerName(name))
4364 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4365 SetSentErrorMessage(true);
4366 return false;
4369 uint64 guid = objmgr.GetPlayerGUIDByName(name.c_str());
4370 player = objmgr.GetPlayer(guid);
4372 else
4373 player = getSelectedPlayer();
4375 if(!player)
4377 SendSysMessage(LANG_NO_CHAR_SELECTED);
4378 SetSentErrorMessage(true);
4379 return false;
4382 if(!HandleResetStatsOrLevelHelper(player))
4383 return false;
4385 player->InitStatsForLevel(true);
4386 player->InitTaxiNodesForLevel();
4387 player->InitTalentForLevel();
4389 return true;
4392 bool ChatHandler::HandleResetSpellsCommand(const char * args)
4394 char* pName = strtok((char*)args, "");
4395 Player *player = NULL;
4396 uint64 playerGUID = 0;
4397 if (pName)
4399 std::string name = pName;
4401 if(!normalizePlayerName(name))
4403 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4404 SetSentErrorMessage(true);
4405 return false;
4408 player = objmgr.GetPlayer(name.c_str());
4409 if(!player)
4410 playerGUID = objmgr.GetPlayerGUIDByName(name.c_str());
4412 else
4413 player = getSelectedPlayer();
4415 if(!player && !playerGUID)
4417 SendSysMessage(LANG_NO_CHAR_SELECTED);
4418 SetSentErrorMessage(true);
4419 return false;
4422 if(player)
4424 player->resetSpells();
4426 ChatHandler(player).SendSysMessage(LANG_RESET_SPELLS);
4428 if(m_session->GetPlayer()!=player)
4429 PSendSysMessage(LANG_RESET_SPELLS_ONLINE,player->GetName());
4431 else
4433 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS), GUID_LOPART(playerGUID));
4434 PSendSysMessage(LANG_RESET_SPELLS_OFFLINE,pName);
4437 return true;
4440 bool ChatHandler::HandleResetTalentsCommand(const char * args)
4442 char* pName = strtok((char*)args, "");
4443 Player *player = NULL;
4444 uint64 playerGUID = 0;
4445 if (pName)
4447 std::string name = pName;
4448 if(!normalizePlayerName(name))
4450 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4451 SetSentErrorMessage(true);
4452 return false;
4455 player = objmgr.GetPlayer(name.c_str());
4456 if(!player)
4457 playerGUID = objmgr.GetPlayerGUIDByName(name.c_str());
4459 else
4460 player = getSelectedPlayer();
4462 if(!player && !playerGUID)
4464 SendSysMessage(LANG_NO_CHAR_SELECTED);
4465 SetSentErrorMessage(true);
4466 return false;
4469 if(player)
4471 player->resetTalents(true);
4473 ChatHandler(player).SendSysMessage(LANG_RESET_TALENTS);
4475 if(m_session->GetPlayer()!=player)
4476 PSendSysMessage(LANG_RESET_TALENTS_ONLINE,player->GetName());
4478 else
4480 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_TALENTS), GUID_LOPART(playerGUID) );
4481 PSendSysMessage(LANG_RESET_TALENTS_OFFLINE,pName);
4484 return true;
4487 bool ChatHandler::HandleResetAllCommand(const char * args)
4489 if(!*args)
4490 return false;
4492 std::string casename = args;
4494 AtLoginFlags atLogin;
4496 // Command specially created as single command to prevent using short case names
4497 if(casename=="spells")
4499 atLogin = AT_LOGIN_RESET_SPELLS;
4500 sWorld.SendWorldText(LANG_RESETALL_SPELLS);
4502 else if(casename=="talents")
4504 atLogin = AT_LOGIN_RESET_TALENTS;
4505 sWorld.SendWorldText(LANG_RESETALL_TALENTS);
4507 else
4509 PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE,args);
4510 SetSentErrorMessage(true);
4511 return false;
4514 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u'",atLogin);
4515 HashMapHolder<Player>::MapType const& plist = ObjectAccessor::Instance().GetPlayers();
4516 for(HashMapHolder<Player>::MapType::const_iterator itr = plist.begin(); itr != plist.end(); ++itr)
4517 itr->second->SetAtLoginFlag(atLogin);
4519 return true;
4522 bool ChatHandler::HandleShutDownCommand(const char* args)
4524 if(!*args)
4525 return false;
4527 if(std::string(args)=="cancel")
4529 sWorld.ShutdownCancel();
4531 else
4533 int32 time = atoi(args);
4535 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4536 if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
4537 return false;
4539 sWorld.ShutdownServ(time);
4541 return true;
4544 bool ChatHandler::HandleRestartCommand(const char* args)
4546 if(!*args)
4547 return false;
4549 if(std::string(args)=="cancel")
4551 sWorld.ShutdownCancel();
4553 else
4555 int32 time = atoi(args);
4557 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4558 if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
4559 return false;
4561 sWorld.ShutdownServ(time, SHUTDOWN_MASK_RESTART);
4563 return true;
4566 bool ChatHandler::HandleIdleRestartCommand(const char* args)
4568 if(!*args)
4569 return false;
4571 if(std::string(args)=="cancel")
4573 sWorld.ShutdownCancel();
4575 else
4577 int32 time = atoi(args);
4579 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4580 if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
4581 return false;
4583 sWorld.ShutdownServ(time,SHUTDOWN_MASK_RESTART+SHUTDOWN_MASK_IDLE);
4585 return true;
4588 bool ChatHandler::HandleIdleShutDownCommand(const char* args)
4590 if(!*args)
4591 return false;
4593 if(std::string(args)=="cancel")
4595 sWorld.ShutdownCancel();
4597 else
4599 int32 time = atoi(args);
4601 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4602 if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
4603 return false;
4605 sWorld.ShutdownServ(time,SHUTDOWN_MASK_IDLE);
4607 return true;
4610 bool ChatHandler::HandleAddQuest(const char* args)
4612 Player* player = getSelectedPlayer();
4613 if(!player)
4615 SendSysMessage(LANG_NO_CHAR_SELECTED);
4616 SetSentErrorMessage(true);
4617 return false;
4620 // .addquest #entry'
4621 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4622 char* cId = extractKeyFromLink((char*)args,"Hquest");
4623 if(!cId)
4624 return false;
4626 uint32 entry = atol(cId);
4628 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
4630 if(!pQuest)
4632 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND,entry);
4633 SetSentErrorMessage(true);
4634 return false;
4637 // check item starting quest (it can work incorrectly if added without item in inventory)
4638 QueryResult *result = WorldDatabase.PQuery("SELECT entry FROM item_template WHERE startquest = '%u' LIMIT 1",entry);
4639 if(result)
4641 Field* fields = result->Fetch();
4642 uint32 item_id = fields[0].GetUInt32();
4643 delete result;
4645 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, entry,item_id);
4646 SetSentErrorMessage(true);
4647 return false;
4650 // ok, normal (creature/GO starting) quest
4651 if( player->CanAddQuest( pQuest, true ) )
4653 player->AddQuest( pQuest, NULL );
4655 if ( player->CanCompleteQuest( entry ) )
4656 player->CompleteQuest( entry );
4659 return true;
4662 bool ChatHandler::HandleRemoveQuest(const char* args)
4664 Player* player = getSelectedPlayer();
4665 if(!player)
4667 SendSysMessage(LANG_NO_CHAR_SELECTED);
4668 SetSentErrorMessage(true);
4669 return false;
4672 // .removequest #entry'
4673 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4674 char* cId = extractKeyFromLink((char*)args,"Hquest");
4675 if(!cId)
4676 return false;
4678 uint32 entry = atol(cId);
4680 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
4682 if(!pQuest)
4684 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
4685 SetSentErrorMessage(true);
4686 return false;
4689 // remove all quest entries for 'entry' from quest log
4690 for(uint8 slot = 0; slot < MAX_QUEST_LOG_SIZE; ++slot )
4692 uint32 quest = player->GetQuestSlotQuestId(slot);
4693 if(quest==entry)
4695 player->SetQuestSlot(slot,0);
4697 // we ignore unequippable quest items in this case, its' still be equipped
4698 player->TakeQuestSourceItem( quest, false );
4702 // set quest status to not started (will updated in DB at next save)
4703 player->SetQuestStatus( entry, QUEST_STATUS_NONE);
4705 // reset rewarded for restart repeatable quest
4706 player->getQuestStatusMap()[entry].m_rewarded = false;
4708 SendSysMessage(LANG_COMMAND_QUEST_REMOVED);
4709 return true;
4712 bool ChatHandler::HandleCompleteQuest(const char* args)
4714 Player* player = getSelectedPlayer();
4715 if(!player)
4717 SendSysMessage(LANG_NO_CHAR_SELECTED);
4718 SetSentErrorMessage(true);
4719 return false;
4722 // .quest complete #entry
4723 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4724 char* cId = extractKeyFromLink((char*)args,"Hquest");
4725 if(!cId)
4726 return false;
4728 uint32 entry = atol(cId);
4730 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
4732 // If player doesn't have the quest
4733 if(!pQuest || player->GetQuestStatus(entry) == QUEST_STATUS_NONE)
4735 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
4736 SetSentErrorMessage(true);
4737 return false;
4740 // Add quest items for quests that require items
4741 for(uint8 x = 0; x < QUEST_OBJECTIVES_COUNT; ++x)
4743 uint32 id = pQuest->ReqItemId[x];
4744 uint32 count = pQuest->ReqItemCount[x];
4745 if(!id || !count)
4746 continue;
4748 uint32 curItemCount = player->GetItemCount(id,true);
4750 ItemPosCountVec dest;
4751 uint8 msg = player->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, id, count-curItemCount );
4752 if( msg == EQUIP_ERR_OK )
4754 Item* item = player->StoreNewItem( dest, id, true);
4755 player->SendNewItem(item,count-curItemCount,true,false);
4759 // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
4760 for(uint8 i = 0; i < QUEST_OBJECTIVES_COUNT; i++)
4762 uint32 creature = pQuest->ReqCreatureOrGOId[i];
4763 uint32 creaturecount = pQuest->ReqCreatureOrGOCount[i];
4765 if(uint32 spell_id = pQuest->ReqSpell[i])
4767 for(uint16 z = 0; z < creaturecount; ++z)
4768 player->CastedCreatureOrGO(creature,0,spell_id);
4770 else if(creature > 0)
4772 for(uint16 z = 0; z < creaturecount; ++z)
4773 player->KilledMonster(creature,0);
4775 else if(creature < 0)
4777 for(uint16 z = 0; z < creaturecount; ++z)
4778 player->CastedCreatureOrGO(creature,0,0);
4782 // If the quest requires reputation to complete
4783 if(uint32 repFaction = pQuest->GetRepObjectiveFaction())
4785 uint32 repValue = pQuest->GetRepObjectiveValue();
4786 uint32 curRep = player->GetReputation(repFaction);
4787 if(curRep < repValue)
4789 FactionEntry const *factionEntry = sFactionStore.LookupEntry(repFaction);
4790 player->SetFactionReputation(factionEntry,repValue);
4794 // If the quest requires money
4795 int32 ReqOrRewMoney = pQuest->GetRewOrReqMoney();
4796 if(ReqOrRewMoney < 0)
4797 player->ModifyMoney(-ReqOrRewMoney);
4799 player->CompleteQuest(entry);
4800 return true;
4803 bool ChatHandler::HandleBanAccountCommand(const char* args)
4805 return HandleBanHelper(BAN_ACCOUNT,args);
4808 bool ChatHandler::HandleBanCharacterCommand(const char* args)
4810 return HandleBanHelper(BAN_CHARACTER,args);
4813 bool ChatHandler::HandleBanIPCommand(const char* args)
4815 return HandleBanHelper(BAN_IP,args);
4818 bool ChatHandler::HandleBanHelper(BanMode mode, const char* args)
4820 if(!args)
4821 return false;
4823 char* cnameOrIP = strtok ((char*)args, " ");
4824 if (!cnameOrIP)
4825 return false;
4827 std::string nameOrIP = cnameOrIP;
4829 char* duration = strtok (NULL," ");
4830 if(!duration || !atoi(duration))
4831 return false;
4833 char* reason = strtok (NULL,"");
4834 if(!reason)
4835 return false;
4837 switch(mode)
4839 case BAN_ACCOUNT:
4840 if(!AccountMgr::normilizeString(nameOrIP))
4842 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str());
4843 SetSentErrorMessage(true);
4844 return false;
4846 break;
4847 case BAN_CHARACTER:
4848 if(!normalizePlayerName(nameOrIP))
4850 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4851 SetSentErrorMessage(true);
4852 return false;
4854 break;
4855 case BAN_IP:
4856 if(!IsIPAddress(nameOrIP.c_str()))
4857 return false;
4858 break;
4861 switch(sWorld.BanAccount(mode, nameOrIP, duration, reason,m_session ? m_session->GetPlayerName() : ""))
4863 case BAN_SUCCESS:
4864 if(atoi(duration)>0)
4865 PSendSysMessage(LANG_BAN_YOUBANNED,nameOrIP.c_str(),secsToTimeString(TimeStringToSecs(duration),true).c_str(),reason);
4866 else
4867 PSendSysMessage(LANG_BAN_YOUPERMBANNED,nameOrIP.c_str(),reason);
4868 break;
4869 case BAN_SYNTAX_ERROR:
4870 return false;
4871 case BAN_NOTFOUND:
4872 switch(mode)
4874 default:
4875 PSendSysMessage(LANG_BAN_NOTFOUND,"account",nameOrIP.c_str());
4876 break;
4877 case BAN_CHARACTER:
4878 PSendSysMessage(LANG_BAN_NOTFOUND,"character",nameOrIP.c_str());
4879 break;
4880 case BAN_IP:
4881 PSendSysMessage(LANG_BAN_NOTFOUND,"ip",nameOrIP.c_str());
4882 break;
4884 SetSentErrorMessage(true);
4885 return false;
4888 return true;
4891 bool ChatHandler::HandleUnBanAccountCommand(const char* args)
4893 return HandleUnBanHelper(BAN_ACCOUNT,args);
4896 bool ChatHandler::HandleUnBanCharacterCommand(const char* args)
4898 return HandleUnBanHelper(BAN_CHARACTER,args);
4901 bool ChatHandler::HandleUnBanIPCommand(const char* args)
4903 return HandleUnBanHelper(BAN_IP,args);
4906 bool ChatHandler::HandleUnBanHelper(BanMode mode, const char* args)
4908 if(!args)
4909 return false;
4911 char* cnameOrIP = strtok ((char*)args, " ");
4912 if(!cnameOrIP)
4913 return false;
4915 std::string nameOrIP = cnameOrIP;
4917 switch(mode)
4919 case BAN_ACCOUNT:
4920 if(!AccountMgr::normilizeString(nameOrIP))
4922 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str());
4923 SetSentErrorMessage(true);
4924 return false;
4926 break;
4927 case BAN_CHARACTER:
4928 if(!normalizePlayerName(nameOrIP))
4930 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4931 SetSentErrorMessage(true);
4932 return false;
4934 break;
4935 case BAN_IP:
4936 if(!IsIPAddress(nameOrIP.c_str()))
4937 return false;
4938 break;
4941 if(sWorld.RemoveBanAccount(mode,nameOrIP))
4942 PSendSysMessage(LANG_UNBAN_UNBANNED,nameOrIP.c_str());
4943 else
4944 PSendSysMessage(LANG_UNBAN_ERROR,nameOrIP.c_str());
4946 return true;
4949 bool ChatHandler::HandleBanInfoAccountCommand(const char* args)
4951 if(!args)
4952 return false;
4954 char* cname = strtok((char*)args, "");
4955 if(!cname)
4956 return false;
4958 std::string account_name = cname;
4959 if(!AccountMgr::normilizeString(account_name))
4961 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
4962 SetSentErrorMessage(true);
4963 return false;
4966 uint32 accountid = accmgr.GetId(account_name);
4967 if(!accountid)
4969 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
4970 return true;
4973 return HandleBanInfoHelper(accountid,account_name.c_str());
4976 bool ChatHandler::HandleBanInfoCharacterCommand(const char* args)
4978 if(!args)
4979 return false;
4981 char* cname = strtok ((char*)args, "");
4982 if(!cname)
4983 return false;
4985 std::string name = cname;
4986 if(!normalizePlayerName(name))
4988 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4989 SetSentErrorMessage(true);
4990 return false;
4993 uint32 accountid = objmgr.GetPlayerAccountIdByPlayerName(name);
4994 if(!accountid)
4996 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4997 SetSentErrorMessage(true);
4998 return false;
5001 std::string accountname;
5002 if(!accmgr.GetName(accountid,accountname))
5004 PSendSysMessage(LANG_BANINFO_NOCHARACTER);
5005 return true;
5008 return HandleBanInfoHelper(accountid,accountname.c_str());
5011 bool ChatHandler::HandleBanInfoHelper(uint32 accountid, char const* accountname)
5013 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);
5014 if(!result)
5016 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN, accountname);
5017 return true;
5020 PSendSysMessage(LANG_BANINFO_BANHISTORY,accountname);
5023 Field* fields = result->Fetch();
5025 time_t unbandate = time_t(fields[3].GetUInt64());
5026 bool active = false;
5027 if(fields[2].GetBool() && (fields[1].GetUInt64() == (uint64)0 ||unbandate >= time(NULL)) )
5028 active = true;
5029 bool permanent = (fields[1].GetUInt64() == (uint64)0);
5030 std::string bantime = permanent?GetMangosString(LANG_BANINFO_INFINITE):secsToTimeString(fields[1].GetUInt64(), true);
5031 PSendSysMessage(LANG_BANINFO_HISTORYENTRY,
5032 fields[0].GetString(), bantime.c_str(), active ? GetMangosString(LANG_BANINFO_YES):GetMangosString(LANG_BANINFO_NO), fields[4].GetString(), fields[5].GetString());
5033 }while (result->NextRow());
5035 delete result;
5036 return true;
5039 bool ChatHandler::HandleBanInfoIPCommand(const char* args)
5041 if(!args)
5042 return false;
5044 char* cIP = strtok ((char*)args, "");
5045 if(!cIP)
5046 return false;
5048 if (!IsIPAddress(cIP))
5049 return false;
5051 std::string IP = cIP;
5053 loginDatabase.escape_string(IP);
5054 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());
5055 if(!result)
5057 PSendSysMessage(LANG_BANINFO_NOIP);
5058 return true;
5061 Field *fields = result->Fetch();
5062 bool permanent = !fields[6].GetUInt64();
5063 PSendSysMessage(LANG_BANINFO_IPENTRY,
5064 fields[0].GetString(), fields[1].GetString(), permanent ? GetMangosString(LANG_BANINFO_NEVER):fields[2].GetString(),
5065 permanent ? GetMangosString(LANG_BANINFO_INFINITE):secsToTimeString(fields[3].GetUInt64(), true).c_str(), fields[4].GetString(), fields[5].GetString());
5066 delete result;
5067 return true;
5070 bool ChatHandler::HandleBanListCharacterCommand(const char* args)
5072 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5074 char* cFilter = strtok ((char*)args, " ");
5075 if(!cFilter)
5076 return false;
5078 std::string filter = cFilter;
5079 loginDatabase.escape_string(filter);
5080 QueryResult* result = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'"),filter.c_str());
5081 if (!result)
5083 PSendSysMessage(LANG_BANLIST_NOCHARACTER);
5084 return true;
5087 return HandleBanListHelper(result);
5090 bool ChatHandler::HandleBanListAccountCommand(const char* args)
5092 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5094 char* cFilter = strtok((char*)args, " ");
5095 std::string filter = cFilter ? cFilter : "";
5096 loginDatabase.escape_string(filter);
5098 QueryResult* result;
5100 if(filter.empty())
5102 result = loginDatabase.Query("SELECT account.id, username FROM account, account_banned"
5103 " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
5105 else
5107 result = loginDatabase.PQuery("SELECT account.id, username FROM account, account_banned"
5108 " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
5109 filter.c_str());
5112 if (!result)
5114 PSendSysMessage(LANG_BANLIST_NOACCOUNT);
5115 return true;
5118 return HandleBanListHelper(result);
5121 bool ChatHandler::HandleBanListHelper(QueryResult* result)
5123 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT);
5125 // Chat short output
5126 if(m_session)
5130 Field* fields = result->Fetch();
5131 uint32 accountid = fields[0].GetUInt32();
5133 QueryResult* banresult = loginDatabase.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid);
5134 if(banresult)
5136 Field* fields2 = banresult->Fetch();
5137 PSendSysMessage("%s",fields2[0].GetString());
5138 delete banresult;
5140 } while (result->NextRow());
5142 // Console wide output
5143 else
5145 SendSysMessage(LANG_BANLIST_ACCOUNTS);
5146 SendSysMessage("===============================================================================");
5147 SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER);
5150 SendSysMessage("-------------------------------------------------------------------------------");
5151 Field *fields = result->Fetch();
5152 uint32 account_id = fields[0].GetUInt32 ();
5154 std::string account_name;
5156 // "account" case, name can be get in same quary
5157 if(result->GetFieldCount() > 1)
5158 account_name = fields[1].GetCppString();
5159 // "character" case, name need extract from another DB
5160 else
5161 accmgr.GetName (account_id,account_name);
5163 // No SQL injection. id is uint32.
5164 QueryResult *banInfo = loginDatabase.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id);
5165 if (banInfo)
5167 Field *fields2 = banInfo->Fetch();
5170 time_t t_ban = fields2[0].GetUInt64();
5171 tm* aTm_ban = localtime(&t_ban);
5173 if (fields2[0].GetUInt64() == fields2[1].GetUInt64())
5175 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5176 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,
5177 fields2[2].GetString(),fields2[3].GetString());
5179 else
5181 time_t t_unban = fields2[1].GetUInt64();
5182 tm* aTm_unban = localtime(&t_unban);
5183 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5184 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,
5185 aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
5186 fields2[2].GetString(),fields2[3].GetString());
5188 }while ( banInfo->NextRow() );
5189 delete banInfo;
5191 }while( result->NextRow() );
5192 SendSysMessage("===============================================================================");
5195 delete result;
5196 return true;
5199 bool ChatHandler::HandleBanListIPCommand(const char* args)
5201 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5203 char* cFilter = strtok((char*)args, " ");
5204 std::string filter = cFilter ? cFilter : "";
5205 loginDatabase.escape_string(filter);
5207 QueryResult* result;
5209 if(filter.empty())
5211 result = loginDatabase.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5212 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
5213 " ORDER BY unbandate" );
5215 else
5217 result = loginDatabase.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5218 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")
5219 " ORDER BY unbandate",filter.c_str() );
5222 if(!result)
5224 PSendSysMessage(LANG_BANLIST_NOIP);
5225 return true;
5228 PSendSysMessage(LANG_BANLIST_MATCHINGIP);
5229 // Chat short output
5230 if(m_session)
5234 Field* fields = result->Fetch();
5235 PSendSysMessage("%s",fields[0].GetString());
5236 } while (result->NextRow());
5238 // Console wide output
5239 else
5241 SendSysMessage(LANG_BANLIST_IPS);
5242 SendSysMessage("===============================================================================");
5243 SendSysMessage(LANG_BANLIST_IPS_HEADER);
5246 SendSysMessage("-------------------------------------------------------------------------------");
5247 Field *fields = result->Fetch();
5248 time_t t_ban = fields[1].GetUInt64();
5249 tm* aTm_ban = localtime(&t_ban);
5250 if ( fields[1].GetUInt64() == fields[2].GetUInt64() )
5252 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5253 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,
5254 fields[3].GetString(), fields[4].GetString());
5256 else
5258 time_t t_unban = fields[2].GetUInt64();
5259 tm* aTm_unban = localtime(&t_unban);
5260 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5261 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,
5262 aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
5263 fields[3].GetString(), fields[4].GetString());
5265 }while( result->NextRow() );
5266 SendSysMessage("===============================================================================");
5269 delete result;
5270 return true;
5273 bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
5275 Player* pl = m_session->GetPlayer();
5277 CellPair p(MaNGOS::ComputeCellPair(pl->GetPositionX(), pl->GetPositionY()));
5278 Cell cell(p);
5279 cell.data.Part.reserved = ALL_DISTRICT;
5280 cell.SetNoCreate();
5282 MaNGOS::RespawnDo u_do;
5283 MaNGOS::WorldObjectWorker<MaNGOS::RespawnDo> worker(u_do);
5285 TypeContainerVisitor<MaNGOS::WorldObjectWorker<MaNGOS::RespawnDo>, GridTypeMapContainer > obj_worker(worker);
5286 CellLock<GridReadGuard> cell_lock(cell, p);
5287 cell_lock->Visit(cell_lock, obj_worker, *MapManager::Instance().GetMap(pl->GetMapId(), pl));
5289 return true;
5292 bool ChatHandler::HandleFlyModeCommand(const char* args)
5294 if(!args)
5295 return false;
5297 Unit *unit = getSelectedUnit();
5298 if (!unit || (unit->GetTypeId() != TYPEID_PLAYER))
5299 unit = m_session->GetPlayer();
5301 WorldPacket data(12);
5302 if (strncmp(args, "on", 3) == 0)
5303 data.SetOpcode(SMSG_MOVE_SET_CAN_FLY);
5304 else if (strncmp(args, "off", 4) == 0)
5305 data.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY);
5306 else
5308 SendSysMessage(LANG_USE_BOL);
5309 return false;
5311 data.append(unit->GetPackGUID());
5312 data << uint32(0); // unknown
5313 unit->SendMessageToSet(&data, true);
5314 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS, unit->GetName(), args);
5315 return true;
5318 bool ChatHandler::HandleLoadPDumpCommand(const char *args)
5320 if(!args)
5321 return false;
5323 char * file = strtok((char*)args, " ");
5324 if(!file)
5325 return false;
5327 char * account = strtok(NULL, " ");
5328 if(!account)
5329 return false;
5331 std::string account_name = account;
5332 if(!AccountMgr::normilizeString(account_name))
5334 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5335 SetSentErrorMessage(true);
5336 return false;
5339 uint32 account_id = accmgr.GetId(account_name);
5340 if(!account_id)
5342 account_id = atoi(account); // use original string
5343 if(!account_id)
5345 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5346 SetSentErrorMessage(true);
5347 return false;
5351 if(!accmgr.GetName(account_id,account_name))
5353 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5354 SetSentErrorMessage(true);
5355 return false;
5358 char* guid_str = NULL;
5359 char* name_str = strtok(NULL, " ");
5361 std::string name;
5362 if(name_str)
5364 name = name_str;
5365 // normalize the name if specified and check if it exists
5366 if(!normalizePlayerName(name))
5368 PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
5369 SetSentErrorMessage(true);
5370 return false;
5373 if(!ObjectMgr::IsValidName(name,true))
5375 PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
5376 SetSentErrorMessage(true);
5377 return false;
5380 guid_str = strtok(NULL, " ");
5383 uint32 guid = 0;
5385 if(guid_str)
5387 guid = atoi(guid_str);
5388 if(!guid)
5390 PSendSysMessage(LANG_INVALID_CHARACTER_GUID);
5391 SetSentErrorMessage(true);
5392 return false;
5395 if(objmgr.GetPlayerAccountIdByGUID(guid))
5397 PSendSysMessage(LANG_CHARACTER_GUID_IN_USE,guid);
5398 SetSentErrorMessage(true);
5399 return false;
5403 switch(PlayerDumpReader().LoadDump(file, account_id, name, guid))
5405 case DUMP_SUCCESS:
5406 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS);
5407 break;
5408 case DUMP_FILE_OPEN_ERROR:
5409 PSendSysMessage(LANG_FILE_OPEN_FAIL,file);
5410 SetSentErrorMessage(true);
5411 return false;
5412 case DUMP_FILE_BROKEN:
5413 PSendSysMessage(LANG_DUMP_BROKEN,file);
5414 SetSentErrorMessage(true);
5415 return false;
5416 case DUMP_TOO_MANY_CHARS:
5417 PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL,account_name,account_id);
5418 SetSentErrorMessage(true);
5419 return false;
5420 default:
5421 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED);
5422 SetSentErrorMessage(true);
5423 return false;
5426 return true;
5429 bool ChatHandler::HandleChangeEntryCommand(const char *args)
5431 if(!args)
5432 return false;
5434 uint32 newEntryNum = atoi(args);
5435 if(!newEntryNum)
5436 return false;
5438 Unit* unit = getSelectedUnit();
5439 if(!unit || unit->GetTypeId() != TYPEID_UNIT)
5441 SendSysMessage(LANG_SELECT_CREATURE);
5442 SetSentErrorMessage(true);
5443 return false;
5445 Creature* creature = (Creature*)unit;
5446 if(creature->UpdateEntry(newEntryNum))
5447 SendSysMessage(LANG_DONE);
5448 else
5449 SendSysMessage(LANG_ERROR);
5450 return true;
5453 bool ChatHandler::HandleWritePDumpCommand(const char *args)
5455 if(!args)
5456 return false;
5458 char* file = strtok((char*)args, " ");
5459 char* p2 = strtok(NULL, " ");
5461 if(!file || !p2)
5462 return false;
5464 uint32 guid = objmgr.GetPlayerGUIDByName(p2);
5465 if(!guid)
5466 guid = atoi(p2);
5468 if(!objmgr.GetPlayerAccountIdByGUID(guid))
5470 PSendSysMessage(LANG_PLAYER_NOT_FOUND);
5471 SetSentErrorMessage(true);
5472 return false;
5475 switch(PlayerDumpWriter().WriteDump(file, guid))
5477 case DUMP_SUCCESS:
5478 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS);
5479 break;
5480 case DUMP_FILE_OPEN_ERROR:
5481 PSendSysMessage(LANG_FILE_OPEN_FAIL,file);
5482 SetSentErrorMessage(true);
5483 return false;
5484 default:
5485 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED);
5486 SetSentErrorMessage(true);
5487 return false;
5490 return true;
5493 bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
5495 Unit* unit = getSelectedUnit();
5496 if(!unit)
5498 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5499 SetSentErrorMessage(true);
5500 return false;
5503 PSendSysMessage(LANG_MOVEGENS_LIST,(unit->GetTypeId()==TYPEID_PLAYER ? "Player" : "Creature" ),unit->GetGUIDLow());
5505 MotionMaster* mm = unit->GetMotionMaster();
5506 for(MotionMaster::const_iterator itr = mm->begin(); itr != mm->end(); ++itr)
5508 switch((*itr)->GetMovementGeneratorType())
5510 case IDLE_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_IDLE); break;
5511 case RANDOM_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_RANDOM); break;
5512 case WAYPOINT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_WAYPOINT); break;
5513 case ANIMAL_RANDOM_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_ANIMAL_RANDOM); break;
5514 case CONFUSED_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_CONFUSED); break;
5515 case TARGETED_MOTION_TYPE:
5517 if(unit->GetTypeId()==TYPEID_PLAYER)
5519 TargetedMovementGenerator<Player> const* mgen = static_cast<TargetedMovementGenerator<Player> const*>(*itr);
5520 Unit* target = mgen->GetTarget();
5521 if(target)
5522 PSendSysMessage(LANG_MOVEGENS_TARGETED_PLAYER,target->GetName(),target->GetGUIDLow());
5523 else
5524 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL);
5526 else
5528 TargetedMovementGenerator<Creature> const* mgen = static_cast<TargetedMovementGenerator<Creature> const*>(*itr);
5529 Unit* target = mgen->GetTarget();
5530 if(target)
5531 PSendSysMessage(LANG_MOVEGENS_TARGETED_CREATURE,target->GetName(),target->GetGUIDLow());
5532 else
5533 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL);
5535 break;
5537 case HOME_MOTION_TYPE:
5538 if(unit->GetTypeId()==TYPEID_UNIT)
5540 float x,y,z;
5541 (*itr)->GetDestination(x,y,z);
5542 PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE,x,y,z);
5544 else
5545 SendSysMessage(LANG_MOVEGENS_HOME_PLAYER);
5546 break;
5547 case FLIGHT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FLIGHT); break;
5548 case POINT_MOTION_TYPE:
5550 float x,y,z;
5551 (*itr)->GetDestination(x,y,z);
5552 PSendSysMessage(LANG_MOVEGENS_POINT,x,y,z);
5553 break;
5555 case FLEEING_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FEAR); break;
5556 case DISTRACT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_DISTRACT); break;
5557 default:
5558 PSendSysMessage(LANG_MOVEGENS_UNKNOWN,(*itr)->GetMovementGeneratorType());
5559 break;
5562 return true;
5565 bool ChatHandler::HandlePLimitCommand(const char *args)
5567 if(*args)
5569 char* param = strtok((char*)args, " ");
5570 if(!param)
5571 return false;
5573 int l = strlen(param);
5575 if( strncmp(param,"player",l) == 0 )
5576 sWorld.SetPlayerLimit(-SEC_PLAYER);
5577 else if(strncmp(param,"moderator",l) == 0 )
5578 sWorld.SetPlayerLimit(-SEC_MODERATOR);
5579 else if(strncmp(param,"gamemaster",l) == 0 )
5580 sWorld.SetPlayerLimit(-SEC_GAMEMASTER);
5581 else if(strncmp(param,"administrator",l) == 0 )
5582 sWorld.SetPlayerLimit(-SEC_ADMINISTRATOR);
5583 else if(strncmp(param,"reset",l) == 0 )
5584 sWorld.SetPlayerLimit( sConfig.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT) );
5585 else
5587 int val = atoi(param);
5588 if(val < -SEC_ADMINISTRATOR) val = -SEC_ADMINISTRATOR;
5590 sWorld.SetPlayerLimit(val);
5593 // kick all low security level players
5594 if(sWorld.GetPlayerAmountLimit() > SEC_PLAYER)
5595 sWorld.KickAllLess(sWorld.GetPlayerSecurityLimit());
5598 uint32 pLimit = sWorld.GetPlayerAmountLimit();
5599 AccountTypes allowedAccountType = sWorld.GetPlayerSecurityLimit();
5600 char const* secName = "";
5601 switch(allowedAccountType)
5603 case SEC_PLAYER: secName = "Player"; break;
5604 case SEC_MODERATOR: secName = "Moderator"; break;
5605 case SEC_GAMEMASTER: secName = "Gamemaster"; break;
5606 case SEC_ADMINISTRATOR: secName = "Administrator"; break;
5607 default: secName = "<unknown>"; break;
5610 PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit,secName);
5612 return true;
5615 bool ChatHandler::HandleCastCommand(const char* args)
5617 if(!*args)
5618 return false;
5620 Unit* target = getSelectedUnit();
5622 if(!target)
5624 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5625 SetSentErrorMessage(true);
5626 return false;
5629 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5630 uint32 spell = extractSpellIdFromLink((char*)args);
5631 if(!spell)
5632 return false;
5634 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
5635 if(!spellInfo)
5636 return false;
5638 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
5640 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
5641 SetSentErrorMessage(true);
5642 return false;
5645 char* trig_str = strtok(NULL, " ");
5646 if(trig_str)
5648 int l = strlen(trig_str);
5649 if(strncmp(trig_str,"triggered",l) != 0 )
5650 return false;
5653 bool triggered = (trig_str != NULL);
5655 m_session->GetPlayer()->CastSpell(target,spell,triggered);
5657 return true;
5660 bool ChatHandler::HandleCastBackCommand(const char* args)
5662 Creature* caster = getSelectedCreature();
5664 if(!caster)
5666 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5667 SetSentErrorMessage(true);
5668 return false;
5671 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
5672 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5673 uint32 spell = extractSpellIdFromLink((char*)args);
5674 if(!spell || !sSpellStore.LookupEntry(spell))
5675 return false;
5677 char* trig_str = strtok(NULL, " ");
5678 if(trig_str)
5680 int l = strlen(trig_str);
5681 if(strncmp(trig_str,"triggered",l) != 0 )
5682 return false;
5685 bool triggered = (trig_str != NULL);
5687 // update orientation at server
5688 caster->SetOrientation(caster->GetAngle(m_session->GetPlayer()));
5690 // and client
5691 WorldPacket data;
5692 caster->BuildHeartBeatMsg(&data);
5693 caster->SendMessageToSet(&data,true);
5695 caster->CastSpell(m_session->GetPlayer(),spell,false);
5697 return true;
5700 bool ChatHandler::HandleCastDistCommand(const char* args)
5702 if(!*args)
5703 return false;
5705 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5706 uint32 spell = extractSpellIdFromLink((char*)args);
5707 if(!spell)
5708 return false;
5710 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
5711 if(!spellInfo)
5712 return false;
5714 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
5716 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
5717 SetSentErrorMessage(true);
5718 return false;
5721 char *distStr = strtok(NULL, " ");
5723 float dist = 0;
5725 if(distStr)
5726 sscanf(distStr, "%f", &dist);
5728 char* trig_str = strtok(NULL, " ");
5729 if(trig_str)
5731 int l = strlen(trig_str);
5732 if(strncmp(trig_str,"triggered",l) != 0 )
5733 return false;
5736 bool triggered = (trig_str != NULL);
5738 float x,y,z;
5739 m_session->GetPlayer()->GetClosePoint(x,y,z,dist);
5741 m_session->GetPlayer()->CastSpell(x,y,z,spell,triggered);
5742 return true;
5745 bool ChatHandler::HandleCastTargetCommand(const char* args)
5747 Creature* caster = getSelectedCreature();
5749 if(!caster)
5751 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5752 SetSentErrorMessage(true);
5753 return false;
5756 if(!caster->getVictim())
5758 SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM);
5759 SetSentErrorMessage(true);
5760 return false;
5763 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5764 uint32 spell = extractSpellIdFromLink((char*)args);
5765 if(!spell || !sSpellStore.LookupEntry(spell))
5766 return false;
5768 char* trig_str = strtok(NULL, " ");
5769 if(trig_str)
5771 int l = strlen(trig_str);
5772 if(strncmp(trig_str,"triggered",l) != 0 )
5773 return false;
5776 bool triggered = (trig_str != NULL);
5778 // update orientation at server
5779 caster->SetOrientation(caster->GetAngle(m_session->GetPlayer()));
5781 // and client
5782 WorldPacket data;
5783 caster->BuildHeartBeatMsg(&data);
5784 caster->SendMessageToSet(&data,true);
5786 caster->CastSpell(caster->getVictim(),spell,false);
5788 return true;
5792 ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
5793 Without this function 3rd party scripting library will get linking errors (unresolved external)
5794 when attempting to use the PointMovementGenerator
5796 bool ChatHandler::HandleComeToMeCommand(const char *args)
5798 Creature* caster = getSelectedCreature();
5800 if(!caster)
5802 SendSysMessage(LANG_SELECT_CREATURE);
5803 SetSentErrorMessage(true);
5804 return false;
5807 char* newFlagStr = strtok((char*)args, " ");
5809 if(!newFlagStr)
5810 return false;
5812 uint32 newFlags = atoi(newFlagStr);
5814 caster->SetUnitMovementFlags(newFlags);
5816 Player* pl = m_session->GetPlayer();
5818 caster->GetMotionMaster()->MovePoint(0, pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ());
5819 return true;
5822 bool ChatHandler::HandleCastSelfCommand(const char* args)
5824 if(!*args)
5825 return false;
5827 Unit* target = getSelectedUnit();
5829 if(!target)
5831 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5832 SetSentErrorMessage(true);
5833 return false;
5836 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5837 uint32 spell = extractSpellIdFromLink((char*)args);
5838 if(!spell)
5839 return false;
5841 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
5842 if(!spellInfo)
5843 return false;
5845 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
5847 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
5848 SetSentErrorMessage(true);
5849 return false;
5852 target->CastSpell(target,spell,false);
5854 return true;
5857 std::string GetTimeString(uint32 time)
5859 uint16 days = time / DAY, hours = (time % DAY) / HOUR, minute = (time % HOUR) / MINUTE;
5860 std::ostringstream ss;
5861 if(days) ss << days << "d ";
5862 if(hours) ss << hours << "h ";
5863 ss << minute << "m";
5864 return ss.str();
5867 bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
5869 Player* player = getSelectedPlayer();
5870 if (!player) player = m_session->GetPlayer();
5871 uint32 counter = 0;
5872 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; i++)
5874 Player::BoundInstancesMap &binds = player->GetBoundInstances(i);
5875 for(Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end(); ++itr)
5877 InstanceSave *save = itr->second.save;
5878 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
5879 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());
5880 counter++;
5883 PSendSysMessage("player binds: %d", counter);
5884 counter = 0;
5885 Group *group = player->GetGroup();
5886 if(group)
5888 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; i++)
5890 Group::BoundInstancesMap &binds = group->GetBoundInstances(i);
5891 for(Group::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end(); ++itr)
5893 InstanceSave *save = itr->second.save;
5894 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
5895 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());
5896 counter++;
5900 PSendSysMessage("group binds: %d", counter);
5902 return true;
5905 bool ChatHandler::HandleInstanceUnbindCommand(const char* args)
5907 if(!*args)
5908 return false;
5910 std::string cmd = args;
5911 if(cmd == "all")
5913 Player* player = getSelectedPlayer();
5914 if (!player) player = m_session->GetPlayer();
5915 uint32 counter = 0;
5916 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; i++)
5918 Player::BoundInstancesMap &binds = player->GetBoundInstances(i);
5919 for(Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end();)
5921 if(itr->first != player->GetMapId())
5923 InstanceSave *save = itr->second.save;
5924 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
5925 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());
5926 player->UnbindInstance(itr, i);
5927 counter++;
5929 else
5930 ++itr;
5933 PSendSysMessage("instances unbound: %d", counter);
5935 return true;
5938 bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
5940 PSendSysMessage("instances loaded: %d", MapManager::Instance().GetNumInstances());
5941 PSendSysMessage("players in instances: %d", MapManager::Instance().GetNumPlayersInInstances());
5942 PSendSysMessage("instance saves: %d", sInstanceSaveManager.GetNumInstanceSaves());
5943 PSendSysMessage("players bound: %d", sInstanceSaveManager.GetNumBoundPlayersTotal());
5944 PSendSysMessage("groups bound: %d", sInstanceSaveManager.GetNumBoundGroupsTotal());
5945 return true;
5948 bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
5950 Player* pl = m_session->GetPlayer();
5952 Map* map = pl->GetMap();
5953 if (!map->IsDungeon())
5955 PSendSysMessage("Map is not a dungeon.");
5956 SetSentErrorMessage(true);
5957 return false;
5960 if (!((InstanceMap*)map)->GetInstanceData())
5962 PSendSysMessage("Map has no instance data.");
5963 SetSentErrorMessage(true);
5964 return false;
5967 ((InstanceMap*)map)->GetInstanceData()->SaveToDB();
5968 return true;
5971 /// Display the list of GMs
5972 bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
5974 ///- Get the accounts with GM Level >0
5975 QueryResult *result = loginDatabase.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
5976 if(result)
5978 SendSysMessage(LANG_GMLIST);
5979 SendSysMessage("========================");
5980 SendSysMessage(LANG_GMLIST_HEADER);
5981 SendSysMessage("========================");
5983 ///- Circle through them. Display username and GM level
5986 Field *fields = result->Fetch();
5987 PSendSysMessage("|%15s|%6s|", fields[0].GetString(),fields[1].GetString());
5988 }while( result->NextRow() );
5990 PSendSysMessage("========================");
5991 delete result;
5993 else
5994 PSendSysMessage(LANG_GMLIST_EMPTY);
5995 return true;
5998 /// Define the 'Message of the day' for the realm
5999 bool ChatHandler::HandleServerSetMotdCommand(const char* args)
6001 sWorld.SetMotd(args);
6002 PSendSysMessage(LANG_MOTD_NEW, args);
6003 return true;
6006 /// Set/Unset the expansion level for an account
6007 bool ChatHandler::HandleAccountSetAddonCommand(const char* args)
6009 ///- Get the command line arguments
6010 char *szAcc = strtok((char*)args," ");
6011 char *szExp = strtok(NULL," ");
6013 if(!szAcc)
6014 return false;
6016 std::string account_name;
6017 uint32 account_id;
6019 if(!szExp)
6021 Player* player = getSelectedPlayer();
6022 if(!player)
6023 return false;
6025 account_id = player->GetSession()->GetAccountId();
6026 accmgr.GetName(account_id,account_name);
6027 szExp = szAcc;
6029 else
6031 ///- Convert Account name to Upper Format
6032 account_name = szAcc;
6033 if(!AccountMgr::normilizeString(account_name))
6035 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
6036 SetSentErrorMessage(true);
6037 return false;
6040 account_id = accmgr.GetId(account_name);
6041 if(!account_id)
6043 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
6044 SetSentErrorMessage(true);
6045 return false;
6049 int lev=atoi(szExp); //get int anyway (0 if error)
6050 if(lev < 0)
6051 return false;
6053 // No SQL injection
6054 loginDatabase.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev,account_id);
6055 PSendSysMessage(LANG_ACCOUNT_SETADDON,account_name.c_str(),account_id,lev);
6056 return true;
6059 /// Send a message to a player in game
6060 bool ChatHandler::HandleSendMessageCommand(const char* args)
6062 ///- Get the command line arguments
6063 char* name_str = strtok((char*)args, " ");
6064 char* msg_str = strtok(NULL, "");
6066 if(!name_str || !msg_str)
6067 return false;
6069 std::string name = name_str;
6071 if(!normalizePlayerName(name))
6072 return false;
6074 ///- Find the player and check that he is not logging out.
6075 Player *rPlayer = objmgr.GetPlayer(name.c_str());
6076 if(!rPlayer)
6078 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6079 SetSentErrorMessage(true);
6080 return false;
6083 if(rPlayer->GetSession()->isLogingOut())
6085 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6086 SetSentErrorMessage(true);
6087 return false;
6090 ///- Send the message
6091 //Use SendAreaTriggerMessage for fastest delivery.
6092 rPlayer->GetSession()->SendAreaTriggerMessage("%s", msg_str);
6093 rPlayer->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
6095 //Confirmation message
6096 PSendSysMessage(LANG_SENDMESSAGE,name.c_str(),msg_str);
6097 return true;