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
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
24 #include "ObjectMgr.h"
25 #include "AccountMgr.h"
26 #include "PlayerDump.h"
30 #include "GameObject.h"
34 #include "ObjectAccessor.h"
35 #include "MapManager.h"
36 #include "SpellAuras.h"
37 #include "ScriptCalls.h"
39 #include "GridNotifiersImpl.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"
49 #include "ItemEnchantmentMgr.h"
50 #include "InstanceSaveMgr.h"
51 #include "InstanceData.h"
52 #include "AccountMgr.h"
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);
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("");
83 bool ChatHandler::HandleReloadAllAreaCommand(const char*)
85 //HandleReloadQuestAreaTriggersCommand(""); -- reloaded in HandleReloadAllQuestCommand
86 HandleReloadAreaTriggerTeleportCommand("");
87 HandleReloadAreaTriggerTavernCommand("");
88 HandleReloadGameGraveyardZoneCommand("");
92 bool ChatHandler::HandleReloadAllLootCommand(const char*)
94 sLog
.outString( "Re-Loading Loot Tables..." );
96 SendGlobalSysMessage("DB tables `*_loot_template` reloaded.");
100 bool ChatHandler::HandleReloadAllNpcCommand(const char* /*args*/)
102 HandleReloadNpcGossipCommand("a");
103 HandleReloadNpcOptionCommand("a");
104 HandleReloadNpcTrainerCommand("a");
105 HandleReloadNpcVendorCommand("a");
109 bool ChatHandler::HandleReloadAllQuestCommand(const char* /*args*/)
111 HandleReloadQuestAreaTriggersCommand("a");
112 HandleReloadQuestTemplateCommand("a");
114 sLog
.outString( "Re-Loading Quests Relations..." );
115 objmgr
.LoadQuestRelations();
116 SendGlobalSysMessage("DB tables `*_questrelation` and `*_involvedrelation` reloaded.");
120 bool ChatHandler::HandleReloadAllScriptsCommand(const char*)
122 if(sWorld
.IsScriptScheduled())
124 PSendSysMessage("DB scripts used currently, please attempt reload later.");
125 SetSentErrorMessage(true);
129 sLog
.outString( "Re-Loading Scripts..." );
130 HandleReloadGameObjectScriptsCommand("a");
131 HandleReloadEventScriptsCommand("a");
132 HandleReloadQuestEndScriptsCommand("a");
133 HandleReloadQuestStartScriptsCommand("a");
134 HandleReloadSpellScriptsCommand("a");
135 SendGlobalSysMessage("DB tables `*_scripts` reloaded.");
139 bool ChatHandler::HandleReloadAllSpellCommand(const char*)
141 HandleReloadSkillDiscoveryTemplateCommand("a");
142 HandleReloadSkillExtraItemTemplateCommand("a");
143 HandleReloadSpellAffectCommand("a");
144 HandleReloadSpellChainCommand("a");
145 HandleReloadSpellElixirCommand("a");
146 HandleReloadSpellLearnSpellCommand("a");
147 HandleReloadSpellProcEventCommand("a");
148 HandleReloadSpellScriptTargetCommand("a");
149 HandleReloadSpellTargetPositionCommand("a");
150 HandleReloadSpellThreatsCommand("a");
151 HandleReloadSpellPetAurasCommand("a");
155 bool ChatHandler::HandleReloadAllItemCommand(const char*)
157 HandleReloadPageTextsCommand("a");
158 HandleReloadItemEnchantementsCommand("a");
162 bool ChatHandler::HandleReloadAllLocalesCommand(const char* args
)
164 HandleReloadLocalesCreatureCommand("a");
165 HandleReloadLocalesGameobjectCommand("a");
166 HandleReloadLocalesItemCommand("a");
167 HandleReloadLocalesNpcTextCommand("a");
168 HandleReloadLocalesPageTextCommand("a");
169 HandleReloadLocalesQuestCommand("a");
173 bool ChatHandler::HandleReloadConfigCommand(const char* arg
)
175 sLog
.outString( "Re-Loading config settings..." );
176 sWorld
.LoadConfigSettings(true);
177 SendGlobalSysMessage("World config settings reloaded.");
181 bool ChatHandler::HandleReloadAreaTriggerTavernCommand(const char*)
183 sLog
.outString( "Re-Loading Tavern Area Triggers..." );
184 objmgr
.LoadTavernAreaTriggers();
185 SendGlobalSysMessage("DB table `areatrigger_tavern` reloaded.");
189 bool ChatHandler::HandleReloadAreaTriggerTeleportCommand(const char*)
191 sLog
.outString( "Re-Loading AreaTrigger teleport definitions..." );
192 objmgr
.LoadAreaTriggerTeleports();
193 SendGlobalSysMessage("DB table `areatrigger_teleport` reloaded.");
197 bool ChatHandler::HandleReloadCommandCommand(const char*)
199 load_command_table
= true;
200 SendGlobalSysMessage("DB table `command` will be reloaded at next chat command use.");
204 bool ChatHandler::HandleReloadCreatureQuestRelationsCommand(const char*)
206 sLog
.outString( "Loading Quests Relations... (`creature_questrelation`)" );
207 objmgr
.LoadCreatureQuestRelations();
208 SendGlobalSysMessage("DB table `creature_questrelation` (creature quest givers) reloaded.");
212 bool ChatHandler::HandleReloadCreatureQuestInvRelationsCommand(const char*)
214 sLog
.outString( "Loading Quests Relations... (`creature_involvedrelation`)" );
215 objmgr
.LoadCreatureInvolvedRelations();
216 SendGlobalSysMessage("DB table `creature_involvedrelation` (creature quest takers) reloaded.");
220 bool ChatHandler::HandleReloadGOQuestRelationsCommand(const char*)
222 sLog
.outString( "Loading Quests Relations... (`gameobject_questrelation`)" );
223 objmgr
.LoadGameobjectQuestRelations();
224 SendGlobalSysMessage("DB table `gameobject_questrelation` (gameobject quest givers) reloaded.");
228 bool ChatHandler::HandleReloadGOQuestInvRelationsCommand(const char*)
230 sLog
.outString( "Loading Quests Relations... (`gameobject_involvedrelation`)" );
231 objmgr
.LoadGameobjectInvolvedRelations();
232 SendGlobalSysMessage("DB table `gameobject_involvedrelation` (gameobject quest takers) reloaded.");
236 bool ChatHandler::HandleReloadQuestAreaTriggersCommand(const char*)
238 sLog
.outString( "Re-Loading Quest Area Triggers..." );
239 objmgr
.LoadQuestAreaTriggers();
240 SendGlobalSysMessage("DB table `areatrigger_involvedrelation` (quest area triggers) reloaded.");
244 bool ChatHandler::HandleReloadQuestTemplateCommand(const char*)
246 sLog
.outString( "Re-Loading Quest Templates..." );
248 SendGlobalSysMessage("DB table `quest_template` (quest definitions) reloaded.");
252 bool ChatHandler::HandleReloadLootTemplatesCreatureCommand(const char*)
254 sLog
.outString( "Re-Loading Loot Tables... (`creature_loot_template`)" );
255 LoadLootTemplates_Creature();
256 LootTemplates_Creature
.CheckLootRefs();
257 SendGlobalSysMessage("DB table `creature_loot_template` reloaded.");
261 bool ChatHandler::HandleReloadLootTemplatesDisenchantCommand(const char*)
263 sLog
.outString( "Re-Loading Loot Tables... (`disenchant_loot_template`)" );
264 LoadLootTemplates_Disenchant();
265 LootTemplates_Disenchant
.CheckLootRefs();
266 SendGlobalSysMessage("DB table `disenchant_loot_template` reloaded.");
270 bool ChatHandler::HandleReloadLootTemplatesFishingCommand(const char*)
272 sLog
.outString( "Re-Loading Loot Tables... (`fishing_loot_template`)" );
273 LoadLootTemplates_Fishing();
274 LootTemplates_Fishing
.CheckLootRefs();
275 SendGlobalSysMessage("DB table `fishing_loot_template` reloaded.");
279 bool ChatHandler::HandleReloadLootTemplatesGameobjectCommand(const char*)
281 sLog
.outString( "Re-Loading Loot Tables... (`gameobject_loot_template`)" );
282 LoadLootTemplates_Gameobject();
283 LootTemplates_Gameobject
.CheckLootRefs();
284 SendGlobalSysMessage("DB table `gameobject_loot_template` reloaded.");
288 bool ChatHandler::HandleReloadLootTemplatesItemCommand(const char*)
290 sLog
.outString( "Re-Loading Loot Tables... (`item_loot_template`)" );
291 LoadLootTemplates_Item();
292 LootTemplates_Item
.CheckLootRefs();
293 SendGlobalSysMessage("DB table `item_loot_template` reloaded.");
297 bool ChatHandler::HandleReloadLootTemplatesPickpocketingCommand(const char*)
299 sLog
.outString( "Re-Loading Loot Tables... (`pickpocketing_loot_template`)" );
300 LoadLootTemplates_Pickpocketing();
301 LootTemplates_Pickpocketing
.CheckLootRefs();
302 SendGlobalSysMessage("DB table `pickpocketing_loot_template` reloaded.");
306 bool ChatHandler::HandleReloadLootTemplatesProspectingCommand(const char*)
308 sLog
.outString( "Re-Loading Loot Tables... (`prospecting_loot_template`)" );
309 LoadLootTemplates_Prospecting();
310 LootTemplates_Prospecting
.CheckLootRefs();
311 SendGlobalSysMessage("DB table `prospecting_loot_template` reloaded.");
315 bool ChatHandler::HandleReloadLootTemplatesQuestMailCommand(const char*)
317 sLog
.outString( "Re-Loading Loot Tables... (`quest_mail_loot_template`)" );
318 LoadLootTemplates_QuestMail();
319 LootTemplates_QuestMail
.CheckLootRefs();
320 SendGlobalSysMessage("DB table `quest_mail_loot_template` reloaded.");
324 bool ChatHandler::HandleReloadLootTemplatesReferenceCommand(const char*)
326 sLog
.outString( "Re-Loading Loot Tables... (`reference_loot_template`)" );
327 LoadLootTemplates_Reference();
328 SendGlobalSysMessage("DB table `reference_loot_template` reloaded.");
332 bool ChatHandler::HandleReloadLootTemplatesSkinningCommand(const char*)
334 sLog
.outString( "Re-Loading Loot Tables... (`skinning_loot_template`)" );
335 LoadLootTemplates_Skinning();
336 LootTemplates_Skinning
.CheckLootRefs();
337 SendGlobalSysMessage("DB table `skinning_loot_template` reloaded.");
341 bool ChatHandler::HandleReloadMangosStringCommand(const char*)
343 sLog
.outString( "Re-Loading mangos_string Table!" );
344 objmgr
.LoadMangosStrings();
345 SendGlobalSysMessage("DB table `mangos_string` reloaded.");
349 bool ChatHandler::HandleReloadNpcOptionCommand(const char*)
351 sLog
.outString( "Re-Loading `npc_option` Table!" );
352 objmgr
.LoadNpcOptions();
353 SendGlobalSysMessage("DB table `npc_option` reloaded.");
357 bool ChatHandler::HandleReloadNpcGossipCommand(const char*)
359 sLog
.outString( "Re-Loading `npc_gossip` Table!" );
360 objmgr
.LoadNpcTextId();
361 SendGlobalSysMessage("DB table `npc_gossip` reloaded.");
365 bool ChatHandler::HandleReloadNpcTrainerCommand(const char*)
367 sLog
.outString( "Re-Loading `npc_trainer` Table!" );
368 objmgr
.LoadTrainerSpell();
369 SendGlobalSysMessage("DB table `npc_trainer` reloaded.");
373 bool ChatHandler::HandleReloadNpcVendorCommand(const char*)
375 sLog
.outString( "Re-Loading `npc_vendor` Table!" );
376 objmgr
.LoadVendors();
377 SendGlobalSysMessage("DB table `npc_vendor` reloaded.");
381 bool ChatHandler::HandleReloadReservedNameCommand(const char*)
383 sLog
.outString( "Loading ReservedNames... (`reserved_name`)" );
384 objmgr
.LoadReservedPlayersNames();
385 SendGlobalSysMessage("DB table `reserved_name` (player reserved names) reloaded.");
389 bool ChatHandler::HandleReloadSkillDiscoveryTemplateCommand(const char* /*args*/)
391 sLog
.outString( "Re-Loading Skill Discovery Table..." );
392 LoadSkillDiscoveryTable();
393 SendGlobalSysMessage("DB table `skill_discovery_template` (recipes discovered at crafting) reloaded.");
397 bool ChatHandler::HandleReloadSkillExtraItemTemplateCommand(const char* /*args*/)
399 sLog
.outString( "Re-Loading Skill Extra Item Table..." );
400 LoadSkillExtraItemTable();
401 SendGlobalSysMessage("DB table `skill_extra_item_template` (extra item creation when crafting) reloaded.");
405 bool ChatHandler::HandleReloadSkillFishingBaseLevelCommand(const char* /*args*/)
407 sLog
.outString( "Re-Loading Skill Fishing base level requirements..." );
408 objmgr
.LoadFishingBaseSkillLevel();
409 SendGlobalSysMessage("DB table `skill_fishing_base_level` (fishing base level for zone/subzone) reloaded.");
413 bool ChatHandler::HandleReloadSpellAffectCommand(const char*)
415 sLog
.outString( "Re-Loading SpellAffect definitions..." );
416 spellmgr
.LoadSpellAffects();
417 SendGlobalSysMessage("DB table `spell_affect` (spell mods apply requirements) reloaded.");
421 bool ChatHandler::HandleReloadSpellChainCommand(const char*)
423 sLog
.outString( "Re-Loading Spell Chain Data... " );
424 spellmgr
.LoadSpellChains();
425 SendGlobalSysMessage("DB table `spell_chain` (spell ranks) reloaded.");
429 bool ChatHandler::HandleReloadSpellElixirCommand(const char*)
431 sLog
.outString( "Re-Loading Spell Elixir types..." );
432 spellmgr
.LoadSpellElixirs();
433 SendGlobalSysMessage("DB table `spell_elixir` (spell exlixir types) reloaded.");
437 bool ChatHandler::HandleReloadSpellLearnSpellCommand(const char*)
439 sLog
.outString( "Re-Loading Spell Learn Spells..." );
440 spellmgr
.LoadSpellLearnSpells();
441 SendGlobalSysMessage("DB table `spell_learn_spell` reloaded.");
445 bool ChatHandler::HandleReloadSpellProcEventCommand(const char*)
447 sLog
.outString( "Re-Loading Spell Proc Event conditions..." );
448 spellmgr
.LoadSpellProcEvents();
449 SendGlobalSysMessage("DB table `spell_proc_event` (spell proc trigger requirements) reloaded.");
453 bool ChatHandler::HandleReloadSpellScriptTargetCommand(const char*)
455 sLog
.outString( "Re-Loading SpellsScriptTarget..." );
456 spellmgr
.LoadSpellScriptTarget();
457 SendGlobalSysMessage("DB table `spell_script_target` (spell targets selection in case specific creature/GO requirements) reloaded.");
461 bool ChatHandler::HandleReloadSpellTargetPositionCommand(const char*)
463 sLog
.outString( "Re-Loading Spell target coordinates..." );
464 spellmgr
.LoadSpellTargetPositions();
465 SendGlobalSysMessage("DB table `spell_target_position` (destination coordinates for spell targets) reloaded.");
469 bool ChatHandler::HandleReloadSpellThreatsCommand(const char*)
471 sLog
.outString( "Re-Loading Aggro Spells Definitions...");
472 spellmgr
.LoadSpellThreats();
473 SendGlobalSysMessage("DB table `spell_threat` (spell aggro definitions) reloaded.");
477 bool ChatHandler::HandleReloadSpellPetAurasCommand(const char*)
479 sLog
.outString( "Re-Loading Spell pet auras...");
480 spellmgr
.LoadSpellPetAuras();
481 SendGlobalSysMessage("DB table `spell_pet_auras` reloaded.");
485 bool ChatHandler::HandleReloadPageTextsCommand(const char*)
487 sLog
.outString( "Re-Loading Page Texts..." );
488 objmgr
.LoadPageTexts();
489 SendGlobalSysMessage("DB table `page_texts` reloaded.");
493 bool ChatHandler::HandleReloadItemEnchantementsCommand(const char*)
495 sLog
.outString( "Re-Loading Item Random Enchantments Table..." );
496 LoadRandomEnchantmentsTable();
497 SendGlobalSysMessage("DB table `item_enchantment_template` reloaded.");
501 bool ChatHandler::HandleReloadGameObjectScriptsCommand(const char* arg
)
503 if(sWorld
.IsScriptScheduled())
505 SendSysMessage("DB scripts used currently, please attempt reload later.");
506 SetSentErrorMessage(true);
511 sLog
.outString( "Re-Loading Scripts from `gameobject_scripts`...");
513 objmgr
.LoadGameObjectScripts();
516 SendGlobalSysMessage("DB table `gameobject_scripts` reloaded.");
521 bool ChatHandler::HandleReloadEventScriptsCommand(const char* arg
)
523 if(sWorld
.IsScriptScheduled())
525 SendSysMessage("DB scripts used currently, please attempt reload later.");
526 SetSentErrorMessage(true);
531 sLog
.outString( "Re-Loading Scripts from `event_scripts`...");
533 objmgr
.LoadEventScripts();
536 SendGlobalSysMessage("DB table `event_scripts` reloaded.");
541 bool ChatHandler::HandleReloadQuestEndScriptsCommand(const char* arg
)
543 if(sWorld
.IsScriptScheduled())
545 SendSysMessage("DB scripts used currently, please attempt reload later.");
546 SetSentErrorMessage(true);
551 sLog
.outString( "Re-Loading Scripts from `quest_end_scripts`...");
553 objmgr
.LoadQuestEndScripts();
556 SendGlobalSysMessage("DB table `quest_end_scripts` reloaded.");
561 bool ChatHandler::HandleReloadQuestStartScriptsCommand(const char* arg
)
563 if(sWorld
.IsScriptScheduled())
565 SendSysMessage("DB scripts used currently, please attempt reload later.");
566 SetSentErrorMessage(true);
571 sLog
.outString( "Re-Loading Scripts from `quest_start_scripts`...");
573 objmgr
.LoadQuestStartScripts();
576 SendGlobalSysMessage("DB table `quest_start_scripts` reloaded.");
581 bool ChatHandler::HandleReloadSpellScriptsCommand(const char* arg
)
583 if(sWorld
.IsScriptScheduled())
585 SendSysMessage("DB scripts used currently, please attempt reload later.");
586 SetSentErrorMessage(true);
591 sLog
.outString( "Re-Loading Scripts from `spell_scripts`...");
593 objmgr
.LoadSpellScripts();
596 SendGlobalSysMessage("DB table `spell_scripts` reloaded.");
601 bool ChatHandler::HandleReloadGameGraveyardZoneCommand(const char* /*arg*/)
603 sLog
.outString( "Re-Loading Graveyard-zone links...");
605 objmgr
.LoadGraveyardZones();
607 SendGlobalSysMessage("DB table `game_graveyard_zone` reloaded.");
612 bool ChatHandler::HandleReloadGameTeleCommand(const char* /*arg*/)
614 sLog
.outString( "Re-Loading Game Tele coordinates...");
616 objmgr
.LoadGameTele();
618 SendGlobalSysMessage("DB table `game_tele` reloaded.");
623 bool ChatHandler::HandleReloadLocalesCreatureCommand(const char* /*arg*/)
625 sLog
.outString( "Re-Loading Locales Creature ...");
626 objmgr
.LoadCreatureLocales();
627 SendGlobalSysMessage("DB table `locales_creature` reloaded.");
631 bool ChatHandler::HandleReloadLocalesGameobjectCommand(const char* /*arg*/)
633 sLog
.outString( "Re-Loading Locales Gameobject ... ");
634 objmgr
.LoadGameObjectLocales();
635 SendGlobalSysMessage("DB table `locales_gameobject` reloaded.");
639 bool ChatHandler::HandleReloadLocalesItemCommand(const char* /*arg*/)
641 sLog
.outString( "Re-Loading Locales Item ... ");
642 objmgr
.LoadItemLocales();
643 SendGlobalSysMessage("DB table `locales_item` reloaded.");
647 bool ChatHandler::HandleReloadLocalesNpcTextCommand(const char* /*arg*/)
649 sLog
.outString( "Re-Loading Locales NPC Text ... ");
650 objmgr
.LoadNpcTextLocales();
651 SendGlobalSysMessage("DB table `locales_npc_text` reloaded.");
655 bool ChatHandler::HandleReloadLocalesPageTextCommand(const char* /*arg*/)
657 sLog
.outString( "Re-Loading Locales Page Text ... ");
658 objmgr
.LoadPageTextLocales();
659 SendGlobalSysMessage("DB table `locales_page_text` reloaded.");
663 bool ChatHandler::HandleReloadLocalesQuestCommand(const char* /*arg*/)
665 sLog
.outString( "Re-Loading Locales Quest ... ");
666 objmgr
.LoadQuestLocales();
667 SendGlobalSysMessage("DB table `locales_quest` reloaded.");
671 bool ChatHandler::HandleLoadScriptsCommand(const char* args
)
673 if(!LoadScriptingModule(args
)) return true;
675 sWorld
.SendWorldText(LANG_SCRIPTS_RELOADED
);
679 bool ChatHandler::HandleAccountSetGmLevelCommand(const char* args
)
681 char* arg1
= strtok((char*)args
, " ");
685 char* arg2
= strtok(NULL
, " ");
687 std::string targetAccountName
;
688 uint32 targetAccountId
= 0;
689 uint32 targetSecurity
= 0;
691 /// only target player different from self allowed (if targetPlayer!=NULL then not console)
692 Player
* targetPlayer
= getSelectedPlayer();
693 if(targetPlayer
&& m_session
->GetPlayer()!=targetPlayer
)
695 /// wrong command syntax or unexpected targeting
699 targetAccountId
= targetPlayer
->GetSession()->GetAccountId();
700 targetSecurity
= targetPlayer
->GetSession()->GetSecurity();
701 if(!accmgr
.GetName(targetAccountId
,targetAccountName
))
703 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,targetAccountName
.c_str());
704 SetSentErrorMessage(true);
710 targetAccountName
= arg1
;
711 if(!AccountMgr::normilizeString(targetAccountName
))
713 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,targetAccountName
.c_str());
714 SetSentErrorMessage(true);
718 targetAccountId
= accmgr
.GetId(targetAccountName
);
719 targetSecurity
= accmgr
.GetSecurity(targetAccountId
);
722 int32 gm
= (int32
)atoi(arg2
);
723 if ( gm
< SEC_PLAYER
|| gm
> SEC_ADMINISTRATOR
)
725 SendSysMessage(LANG_BAD_VALUE
);
726 SetSentErrorMessage(true);
730 /// m_session==NULL only for console
731 uint32 plSecurity
= m_session
? m_session
->GetSecurity() : SEC_CONSOLE
;
733 /// can set security level only for target with less security and to less security that we have
734 /// This is also reject self apply in fact
735 if(targetSecurity
>= plSecurity
|| uint32(gm
) >= plSecurity
)
737 SendSysMessage(LANG_YOURS_SECURITY_IS_LOW
);
738 SetSentErrorMessage(true);
744 ChatHandler(targetPlayer
).PSendSysMessage(LANG_YOURS_SECURITY_CHANGED
,GetName(), gm
);
745 targetPlayer
->GetSession()->SetSecurity(gm
);
748 PSendSysMessage(LANG_YOU_CHANGE_SECURITY
, targetAccountName
.c_str(), gm
);
749 loginDatabase
.PExecute("UPDATE account SET gmlevel = '%i' WHERE id = '%u'", gm
, targetAccountId
);
754 /// Set password for account
755 bool ChatHandler::HandleAccountSetPasswordCommand(const char* args
)
760 ///- Get the command line arguments
761 char *szAccount
= strtok ((char*)args
," ");
762 char *szPassword1
= strtok (NULL
," ");
763 char *szPassword2
= strtok (NULL
," ");
765 if (!szAccount
||!szPassword1
|| !szPassword2
)
768 std::string account_name
= szAccount
;
769 if(!AccountMgr::normilizeString(account_name
))
771 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
772 SetSentErrorMessage(true);
776 uint32 targetAccountId
= accmgr
.GetId(account_name
);
777 if (!targetAccountId
)
779 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
780 SetSentErrorMessage(true);
784 uint32 targetSecurity
= accmgr
.GetSecurity(targetAccountId
);
786 /// m_session==NULL only for console
787 uint32 plSecurity
= m_session
? m_session
->GetSecurity() : SEC_CONSOLE
;
789 /// can set password only for target with less security
790 /// This is also reject self apply in fact
791 if (targetSecurity
>= plSecurity
)
793 SendSysMessage (LANG_YOURS_SECURITY_IS_LOW
);
794 SetSentErrorMessage (true);
798 if (strcmp(szPassword1
,szPassword2
))
800 SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH
);
801 SetSentErrorMessage (true);
805 AccountOpResult result
= accmgr
.ChangePassword(targetAccountId
, szPassword1
);
810 SendSysMessage(LANG_COMMAND_PASSWORD
);
812 case AOR_NAME_NOT_EXIST
:
813 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
814 SetSentErrorMessage(true);
816 case AOR_PASS_TOO_LONG
:
817 SendSysMessage(LANG_PASSWORD_TOO_LONG
);
818 SetSentErrorMessage(true);
821 SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD
);
822 SetSentErrorMessage(true);
829 bool ChatHandler::HandleAllowMovementCommand(const char* /*args*/)
831 if(sWorld
.getAllowMovement())
833 sWorld
.SetAllowMovement(false);
834 SendSysMessage(LANG_CREATURE_MOVE_DISABLED
);
838 sWorld
.SetAllowMovement(true);
839 SendSysMessage(LANG_CREATURE_MOVE_ENABLED
);
844 bool ChatHandler::HandleMaxSkillCommand(const char* /*args*/)
846 Player
* SelectedPlayer
= getSelectedPlayer();
849 SendSysMessage(LANG_NO_CHAR_SELECTED
);
850 SetSentErrorMessage(true);
854 // each skills that have max skill value dependent from level seted to current level max skill value
855 SelectedPlayer
->UpdateSkillsToMaxSkillsForLevel();
859 bool ChatHandler::HandleSetSkillCommand(const char* args
)
861 // number or [name] Shift-click form |color|Hskill:skill_id|h[name]|h|r
862 char* skill_p
= extractKeyFromLink((char*)args
,"Hskill");
866 char *level_p
= strtok (NULL
, " ");
871 char *max_p
= strtok (NULL
, " ");
873 int32 skill
= atoi(skill_p
);
877 PSendSysMessage(LANG_INVALID_SKILL_ID
, skill
);
878 SetSentErrorMessage(true);
882 int32 level
= atol (level_p
);
884 Player
* target
= getSelectedPlayer();
887 SendSysMessage(LANG_NO_CHAR_SELECTED
);
888 SetSentErrorMessage(true);
892 SkillLineEntry
const* sl
= sSkillLineStore
.LookupEntry(skill
);
895 PSendSysMessage(LANG_INVALID_SKILL_ID
, skill
);
896 SetSentErrorMessage(true);
900 if(!target
->GetSkillValue(skill
))
902 PSendSysMessage(LANG_SET_SKILL_ERROR
, target
->GetName(), skill
, sl
->name
[0]);
903 SetSentErrorMessage(true);
907 int32 max
= max_p
? atol (max_p
) : target
->GetPureMaxSkillValue(skill
);
909 if( level
<= 0 || level
> max
|| max
<= 0 )
912 target
->SetSkill(skill
, level
, max
);
913 PSendSysMessage(LANG_SET_SKILL
, skill
, sl
->name
[0], target
->GetName(), level
, max
);
918 bool ChatHandler::HandleUnLearnCommand(const char* args
)
923 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
924 uint32 min_id
= extractSpellIdFromLink((char*)args
);
928 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
929 char* tail
= strtok(NULL
,"");
931 uint32 max_id
= extractSpellIdFromLink(tail
);
935 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
941 std::swap(min_id
,max_id
);
946 Player
* target
= getSelectedPlayer();
949 SendSysMessage(LANG_NO_CHAR_SELECTED
);
950 SetSentErrorMessage(true);
954 for(uint32 spell
=min_id
;spell
<max_id
;spell
++)
956 if (target
->HasSpell(spell
))
957 target
->removeSpell(spell
);
959 SendSysMessage(LANG_FORGET_SPELL
);
965 bool ChatHandler::HandleCooldownCommand(const char* args
)
967 Player
* target
= getSelectedPlayer();
970 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
971 SetSentErrorMessage(true);
977 target
->RemoveAllSpellCooldown();
978 PSendSysMessage(LANG_REMOVEALL_COOLDOWN
, target
->GetName());
982 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
983 uint32 spell_id
= extractSpellIdFromLink((char*)args
);
987 if(!sSpellStore
.LookupEntry(spell_id
))
989 PSendSysMessage(LANG_UNKNOWN_SPELL
, target
==m_session
->GetPlayer() ? GetMangosString(LANG_YOU
) : target
->GetName());
990 SetSentErrorMessage(true);
994 WorldPacket
data( SMSG_CLEAR_COOLDOWN
, (4+8) );
995 data
<< uint32(spell_id
);
996 data
<< uint64(target
->GetGUID());
997 target
->GetSession()->SendPacket(&data
);
998 target
->RemoveSpellCooldown(spell_id
);
999 PSendSysMessage(LANG_REMOVE_COOLDOWN
, spell_id
, target
==m_session
->GetPlayer() ? GetMangosString(LANG_YOU
) : target
->GetName());
1004 bool ChatHandler::HandleLearnAllCommand(const char* /*args*/)
1006 static const char *allSpellList
[] =
1389 //"9036", problems with ghost state
1398 //"6718", phasing stealth, annoing for learn all case.
1611 while(strcmp(allSpellList
[loop
], "0"))
1613 uint32 spell
= atol((char*)allSpellList
[loop
++]);
1615 if (m_session
->GetPlayer()->HasSpell(spell
))
1618 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1619 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1621 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1625 m_session
->GetPlayer()->learnSpell(spell
);
1628 SendSysMessage(LANG_COMMAND_LEARN_MANY_SPELLS
);
1633 bool ChatHandler::HandleLearnAllGMCommand(const char* /*args*/)
1635 static const char *gmSpellList
[] =
1637 "24347", // Become A Fish, No Breath Bar
1638 "35132", // Visual Boom
1639 "38488", // Attack 4000-8000 AOE
1640 "38795", // Attack 2000 AOE + Slow Down 90%
1641 "15712", // Attack 200
1642 "1852", // GM Spell Silence
1645 "29878", // Kill My Self
1646 "26644", // More Kill
1648 "28550", //Invisible 24
1649 "23452", //Invisible + Target
1653 uint16 gmSpellIter
= 0;
1654 while( strcmp(gmSpellList
[gmSpellIter
], "0") )
1656 uint32 spell
= atol((char*)gmSpellList
[gmSpellIter
++]);
1658 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1659 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1661 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1665 m_session
->GetPlayer()->learnSpell(spell
);
1668 SendSysMessage(LANG_LEARNING_GM_SKILLS
);
1672 bool ChatHandler::HandleLearnAllMyClassCommand(const char* /*args*/)
1674 HandleLearnAllMySpellsCommand("");
1675 HandleLearnAllMyTalentsCommand("");
1679 bool ChatHandler::HandleLearnAllMySpellsCommand(const char* /*args*/)
1681 ChrClassesEntry
const* clsEntry
= sChrClassesStore
.LookupEntry(m_session
->GetPlayer()->getClass());
1684 uint32 family
= clsEntry
->spellfamily
;
1686 for (uint32 i
= 0; i
< sSpellStore
.GetNumRows(); i
++)
1688 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(i
);
1692 // skip wrong class/race skills
1693 if(!m_session
->GetPlayer()->IsSpellFitByClassAndRace(spellInfo
->Id
))
1696 // skip other spell families
1697 if( spellInfo
->SpellFamilyName
!= family
)
1700 //TODO: skip triggered spells
1702 // skip spells with first rank learned as talent (and all talents then also)
1703 uint32 first_rank
= spellmgr
.GetFirstSpellInChain(spellInfo
->Id
);
1704 if(GetTalentSpellCost(first_rank
) > 0 )
1707 // skip broken spells
1708 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1711 m_session
->GetPlayer()->learnSpell(i
);
1714 SendSysMessage(LANG_COMMAND_LEARN_CLASS_SPELLS
);
1718 static void learnAllHighRanks(Player
* player
, uint32 spellid
)
1720 SpellChainMapNext
const& nextMap
= spellmgr
.GetSpellChainNext();
1721 for(SpellChainMapNext::const_iterator itr
= nextMap
.lower_bound(spellid
); itr
!= nextMap
.upper_bound(spellid
); ++itr
)
1723 player
->learnSpell(itr
->second
);
1724 learnAllHighRanks(player
,itr
->second
);
1728 bool ChatHandler::HandleLearnAllMyTalentsCommand(const char* /*args*/)
1730 Player
* player
= m_session
->GetPlayer();
1731 uint32 classMask
= player
->getClassMask();
1733 for (uint32 i
= 0; i
< sTalentStore
.GetNumRows(); i
++)
1735 TalentEntry
const *talentInfo
= sTalentStore
.LookupEntry(i
);
1739 TalentTabEntry
const *talentTabInfo
= sTalentTabStore
.LookupEntry( talentInfo
->TalentTab
);
1743 if( (classMask
& talentTabInfo
->ClassMask
) == 0 )
1746 // search highest talent rank
1749 for(; rank
>= 0; --rank
)
1751 if(talentInfo
->RankID
[rank
]!=0)
1753 spellid
= talentInfo
->RankID
[rank
];
1758 if(!spellid
) // ??? none spells in telent
1761 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spellid
);
1762 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1765 // learn highest rank of talent
1766 player
->learnSpell(spellid
);
1768 // and learn all non-talent spell ranks (recursive by tree)
1769 learnAllHighRanks(player
,spellid
);
1772 SendSysMessage(LANG_COMMAND_LEARN_CLASS_TALENTS
);
1776 bool ChatHandler::HandleLearnAllLangCommand(const char* /*args*/)
1778 // skipping UNIVERSAL language (0)
1779 for(int i
= 1; i
< LANGUAGES_COUNT
; ++i
)
1780 m_session
->GetPlayer()->learnSpell(lang_description
[i
].spell_id
);
1782 SendSysMessage(LANG_COMMAND_LEARN_ALL_LANG
);
1786 bool ChatHandler::HandleLearnAllDefaultCommand(const char* args
)
1788 char* pName
= strtok((char*)args
, "");
1789 Player
*player
= NULL
;
1792 std::string name
= pName
;
1794 if(!normalizePlayerName(name
))
1796 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1797 SetSentErrorMessage(true);
1801 player
= objmgr
.GetPlayer(name
.c_str());
1804 player
= getSelectedPlayer();
1808 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1809 SetSentErrorMessage(true);
1813 player
->learnDefaultSpells();
1814 player
->learnQuestRewardedSpells();
1816 PSendSysMessage(LANG_COMMAND_LEARN_ALL_DEFAULT_AND_QUEST
,player
->GetName());
1820 bool ChatHandler::HandleLearnCommand(const char* args
)
1822 Player
* targetPlayer
= getSelectedPlayer();
1826 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1827 SetSentErrorMessage(true);
1831 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1832 uint32 spell
= extractSpellIdFromLink((char*)args
);
1833 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
1836 if (targetPlayer
->HasSpell(spell
))
1838 if(targetPlayer
== m_session
->GetPlayer())
1839 SendSysMessage(LANG_YOU_KNOWN_SPELL
);
1841 PSendSysMessage(LANG_TARGET_KNOWN_SPELL
,targetPlayer
->GetName());
1842 SetSentErrorMessage(true);
1846 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1847 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1849 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1850 SetSentErrorMessage(true);
1854 targetPlayer
->learnSpell(spell
);
1859 bool ChatHandler::HandleAddItemCommand(const char* args
)
1866 if(args
[0]=='[') // [name] manual form
1868 char* citemName
= citemName
= strtok((char*)args
, "]");
1870 if(citemName
&& citemName
[0])
1872 std::string itemName
= citemName
+1;
1873 WorldDatabase
.escape_string(itemName
);
1874 QueryResult
*result
= WorldDatabase
.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName
.c_str());
1877 PSendSysMessage(LANG_COMMAND_COULDNOTFIND
, citemName
+1);
1878 SetSentErrorMessage(true);
1881 itemId
= result
->Fetch()->GetUInt16();
1887 else // item_id or [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r
1889 char* cId
= extractKeyFromLink((char*)args
,"Hitem");
1895 char* ccount
= strtok(NULL
, " ");
1900 count
= strtol(ccount
, NULL
, 10);
1905 Player
* pl
= m_session
->GetPlayer();
1906 Player
* plTarget
= getSelectedPlayer();
1910 sLog
.outDetail(GetMangosString(LANG_ADDITEM
), itemId
, count
);
1912 ItemPrototype
const *pProto
= objmgr
.GetItemPrototype(itemId
);
1915 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, itemId
);
1916 SetSentErrorMessage(true);
1923 plTarget
->DestroyItemCount(itemId
, -count
, true, false);
1924 PSendSysMessage(LANG_REMOVEITEM
, itemId
, -count
, plTarget
->GetName());
1929 uint32 noSpaceForCount
= 0;
1931 // check space and find places
1932 ItemPosCountVec dest
;
1933 uint8 msg
= plTarget
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, itemId
, count
, &noSpaceForCount
);
1934 if( msg
!= EQUIP_ERR_OK
) // convert to possible store amount
1935 count
-= noSpaceForCount
;
1937 if( count
== 0 || dest
.empty()) // can't add any
1939 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, itemId
, noSpaceForCount
);
1940 SetSentErrorMessage(true);
1944 Item
* item
= plTarget
->StoreNewItem( dest
, itemId
, true, Item::GenerateItemRandomPropertyId(itemId
));
1946 // remove binding (let GM give it to another player later)
1948 for(ItemPosCountVec::const_iterator itr
= dest
.begin(); itr
!= dest
.end(); ++itr
)
1949 if(Item
* item1
= pl
->GetItemByPos(itr
->pos
))
1950 item1
->SetBinding( false );
1952 if(count
> 0 && item
)
1954 pl
->SendNewItem(item
,count
,false,true);
1956 plTarget
->SendNewItem(item
,count
,true,false);
1959 if(noSpaceForCount
> 0)
1960 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, itemId
, noSpaceForCount
);
1965 bool ChatHandler::HandleAddItemSetCommand(const char* args
)
1970 char* cId
= extractKeyFromLink((char*)args
,"Hitemset"); // number or [name] Shift-click form |color|Hitemset:itemset_id|h[name]|h|r
1974 uint32 itemsetId
= atol(cId
);
1976 // prevent generation all items with itemset field value '0'
1979 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND
,itemsetId
);
1980 SetSentErrorMessage(true);
1984 Player
* pl
= m_session
->GetPlayer();
1985 Player
* plTarget
= getSelectedPlayer();
1989 sLog
.outDetail(GetMangosString(LANG_ADDITEMSET
), itemsetId
);
1991 QueryResult
*result
= WorldDatabase
.PQuery("SELECT entry FROM item_template WHERE itemset = %u",itemsetId
);
1995 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND
,itemsetId
);
1997 SetSentErrorMessage(true);
2003 Field
*fields
= result
->Fetch();
2004 uint32 itemId
= fields
[0].GetUInt32();
2006 ItemPosCountVec dest
;
2007 uint8 msg
= plTarget
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, itemId
, 1 );
2008 if( msg
== EQUIP_ERR_OK
)
2010 Item
* item
= plTarget
->StoreNewItem( dest
, itemId
, true);
2012 // remove binding (let GM give it to another player later)
2014 item
->SetBinding( false );
2016 pl
->SendNewItem(item
,1,false,true);
2018 plTarget
->SendNewItem(item
,1,true,false);
2022 pl
->SendEquipError( msg
, NULL
, NULL
);
2023 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, itemId
, 1);
2026 }while( result
->NextRow() );
2033 bool ChatHandler::HandleListItemCommand(const char* args
)
2038 char* cId
= extractKeyFromLink((char*)args
,"Hitem");
2042 uint32 item_id
= atol(cId
);
2045 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
2046 SetSentErrorMessage(true);
2050 ItemPrototype
const* itemProto
= objmgr
.GetItemPrototype(item_id
);
2053 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
2054 SetSentErrorMessage(true);
2058 char* c_count
= strtok(NULL
, " ");
2059 int count
= c_count
? atol(c_count
) : 10;
2064 QueryResult
*result
;
2067 uint32 inv_count
= 0;
2068 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM character_inventory WHERE item_template='%u'",item_id
);
2071 inv_count
= (*result
)[0].GetUInt32();
2075 result
=CharacterDatabase
.PQuery(
2077 "SELECT ci.item, cibag.slot AS bag, ci.slot, ci.guid, characters.account,characters.name "
2078 "FROM character_inventory AS ci LEFT JOIN character_inventory AS cibag ON (cibag.item=ci.bag),characters "
2079 "WHERE ci.item_template='%u' AND ci.guid = characters.guid LIMIT %u ",
2080 item_id
,uint32(count
));
2086 Field
*fields
= result
->Fetch();
2087 uint32 item_guid
= fields
[0].GetUInt32();
2088 uint32 item_bag
= fields
[1].GetUInt32();
2089 uint32 item_slot
= fields
[2].GetUInt32();
2090 uint32 owner_guid
= fields
[3].GetUInt32();
2091 uint32 owner_acc
= fields
[4].GetUInt32();
2092 std::string owner_name
= fields
[5].GetCppString();
2094 char const* item_pos
= 0;
2095 if(Player::IsEquipmentPos(item_bag
,item_slot
))
2096 item_pos
= "[equipped]";
2097 else if(Player::IsInventoryPos(item_bag
,item_slot
))
2098 item_pos
= "[in inventory]";
2099 else if(Player::IsBankPos(item_bag
,item_slot
))
2100 item_pos
= "[in bank]";
2104 PSendSysMessage(LANG_ITEMLIST_SLOT
,
2105 item_guid
,owner_name
.c_str(),owner_guid
,owner_acc
,item_pos
);
2106 } while (result
->NextRow());
2108 int64 res_count
= result
->GetRowCount();
2112 if(count
> res_count
)
2119 uint32 mail_count
= 0;
2120 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM mail_items WHERE item_template='%u'", item_id
);
2123 mail_count
= (*result
)[0].GetUInt32();
2129 result
=CharacterDatabase
.PQuery(
2131 "SELECT mail_items.item_guid, mail.sender, mail.receiver, char_s.account, char_s.name, char_r.account, char_r.name "
2132 "FROM mail,mail_items,characters as char_s,characters as char_r "
2133 "WHERE mail_items.item_template='%u' AND char_s.guid = mail.sender AND char_r.guid = mail.receiver AND mail.id=mail_items.mail_id LIMIT %u",
2134 item_id
,uint32(count
));
2143 Field
*fields
= result
->Fetch();
2144 uint32 item_guid
= fields
[0].GetUInt32();
2145 uint32 item_s
= fields
[1].GetUInt32();
2146 uint32 item_r
= fields
[2].GetUInt32();
2147 uint32 item_s_acc
= fields
[3].GetUInt32();
2148 std::string item_s_name
= fields
[4].GetCppString();
2149 uint32 item_r_acc
= fields
[5].GetUInt32();
2150 std::string item_r_name
= fields
[6].GetCppString();
2152 char const* item_pos
= "[in mail]";
2154 PSendSysMessage(LANG_ITEMLIST_MAIL
,
2155 item_guid
,item_s_name
.c_str(),item_s
,item_s_acc
,item_r_name
.c_str(),item_r
,item_r_acc
,item_pos
);
2156 } while (result
->NextRow());
2158 int64 res_count
= result
->GetRowCount();
2162 if(count
> res_count
)
2169 uint32 auc_count
= 0;
2170 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM auctionhouse WHERE item_template='%u'",item_id
);
2173 auc_count
= (*result
)[0].GetUInt32();
2179 result
=CharacterDatabase
.PQuery(
2181 "SELECT auctionhouse.itemguid, auctionhouse.itemowner, characters.account, characters.name "
2182 "FROM auctionhouse,characters WHERE auctionhouse.item_template='%u' AND characters.guid = auctionhouse.itemowner LIMIT %u",
2183 item_id
,uint32(count
));
2192 Field
*fields
= result
->Fetch();
2193 uint32 item_guid
= fields
[0].GetUInt32();
2194 uint32 owner
= fields
[1].GetUInt32();
2195 uint32 owner_acc
= fields
[2].GetUInt32();
2196 std::string owner_name
= fields
[3].GetCppString();
2198 char const* item_pos
= "[in auction]";
2200 PSendSysMessage(LANG_ITEMLIST_AUCTION
, item_guid
, owner_name
.c_str(), owner
, owner_acc
,item_pos
);
2201 } while (result
->NextRow());
2207 uint32 guild_count
= 0;
2208 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_entry) FROM guild_bank_item WHERE item_entry='%u'",item_id
);
2211 guild_count
= (*result
)[0].GetUInt32();
2215 result
=CharacterDatabase
.PQuery(
2217 "SELECT gi.item_guid, gi.guildid, guild.name "
2218 "FROM guild_bank_item AS gi, guild WHERE gi.item_entry='%u' AND gi.guildid = guild.guildid LIMIT %u ",
2219 item_id
,uint32(count
));
2225 Field
*fields
= result
->Fetch();
2226 uint32 item_guid
= fields
[0].GetUInt32();
2227 uint32 guild_guid
= fields
[1].GetUInt32();
2228 std::string guild_name
= fields
[2].GetCppString();
2230 char const* item_pos
= "[in guild bank]";
2232 PSendSysMessage(LANG_ITEMLIST_GUILD
,item_guid
,guild_name
.c_str(),guild_guid
,item_pos
);
2233 } while (result
->NextRow());
2235 int64 res_count
= result
->GetRowCount();
2239 if(count
> res_count
)
2245 if(inv_count
+mail_count
+auc_count
+guild_count
== 0)
2247 SendSysMessage(LANG_COMMAND_NOITEMFOUND
);
2248 SetSentErrorMessage(true);
2252 PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE
,item_id
,inv_count
+mail_count
+auc_count
+guild_count
,inv_count
,mail_count
,auc_count
,guild_count
);
2257 bool ChatHandler::HandleListObjectCommand(const char* args
)
2262 // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2263 char* cId
= extractKeyFromLink((char*)args
,"Hgameobject_entry");
2267 uint32 go_id
= atol(cId
);
2270 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID
, go_id
);
2271 SetSentErrorMessage(true);
2275 GameObjectInfo
const * gInfo
= objmgr
.GetGameObjectInfo(go_id
);
2278 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID
, go_id
);
2279 SetSentErrorMessage(true);
2283 char* c_count
= strtok(NULL
, " ");
2284 int count
= c_count
? atol(c_count
) : 10;
2289 QueryResult
*result
;
2291 uint32 obj_count
= 0;
2292 result
=WorldDatabase
.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'",go_id
);
2295 obj_count
= (*result
)[0].GetUInt32();
2301 Player
* pl
= m_session
->GetPlayer();
2302 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map, (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ FROM gameobject WHERE id = '%u' ORDER BY order_ ASC LIMIT %u",
2303 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(),go_id
,uint32(count
));
2306 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map FROM gameobject WHERE id = '%u' LIMIT %u",
2307 go_id
,uint32(count
));
2313 Field
*fields
= result
->Fetch();
2314 uint32 guid
= fields
[0].GetUInt32();
2315 float x
= fields
[1].GetFloat();
2316 float y
= fields
[2].GetFloat();
2317 float z
= fields
[3].GetFloat();
2318 int mapid
= fields
[4].GetUInt16();
2321 PSendSysMessage(LANG_GO_LIST_CHAT
, guid
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2323 PSendSysMessage(LANG_GO_LIST_CONSOLE
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2324 } while (result
->NextRow());
2329 PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE
,go_id
,obj_count
);
2333 bool ChatHandler::HandleNearObjectCommand(const char* args
)
2335 float distance
= (!*args
) ? 10 : atol(args
);
2338 Player
* pl
= m_session
->GetPlayer();
2339 QueryResult
*result
= WorldDatabase
.PQuery("SELECT guid, id, position_x, position_y, position_z, map, "
2340 "(POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ "
2341 "FROM gameobject WHERE map='%u' AND (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) <= '%f' ORDER BY order_",
2342 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(),
2343 pl
->GetMapId(),pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(),distance
*distance
);
2349 Field
*fields
= result
->Fetch();
2350 uint32 guid
= fields
[0].GetUInt32();
2351 uint32 entry
= fields
[1].GetUInt32();
2352 float x
= fields
[2].GetFloat();
2353 float y
= fields
[3].GetFloat();
2354 float z
= fields
[4].GetFloat();
2355 int mapid
= fields
[5].GetUInt16();
2357 GameObjectInfo
const * gInfo
= objmgr
.GetGameObjectInfo(entry
);
2362 PSendSysMessage(LANG_GO_LIST_CHAT
, guid
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2365 } while (result
->NextRow());
2370 PSendSysMessage(LANG_COMMAND_NEAROBJMESSAGE
,distance
,count
);
2374 bool ChatHandler::HandleListCreatureCommand(const char* args
)
2379 // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
2380 char* cId
= extractKeyFromLink((char*)args
,"Hcreature_entry");
2384 uint32 cr_id
= atol(cId
);
2387 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID
, cr_id
);
2388 SetSentErrorMessage(true);
2392 CreatureInfo
const* cInfo
= objmgr
.GetCreatureTemplate(cr_id
);
2395 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID
, cr_id
);
2396 SetSentErrorMessage(true);
2400 char* c_count
= strtok(NULL
, " ");
2401 int count
= c_count
? atol(c_count
) : 10;
2406 QueryResult
*result
;
2408 uint32 cr_count
= 0;
2409 result
=WorldDatabase
.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'",cr_id
);
2412 cr_count
= (*result
)[0].GetUInt32();
2418 Player
* pl
= m_session
->GetPlayer();
2419 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map, (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ FROM creature WHERE id = '%u' ORDER BY order_ ASC LIMIT %u",
2420 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(), cr_id
,uint32(count
));
2423 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '%u' LIMIT %u",
2424 cr_id
,uint32(count
));
2430 Field
*fields
= result
->Fetch();
2431 uint32 guid
= fields
[0].GetUInt32();
2432 float x
= fields
[1].GetFloat();
2433 float y
= fields
[2].GetFloat();
2434 float z
= fields
[3].GetFloat();
2435 int mapid
= fields
[4].GetUInt16();
2438 PSendSysMessage(LANG_CREATURE_LIST_CHAT
, guid
, guid
, cInfo
->Name
, x
, y
, z
, mapid
);
2440 PSendSysMessage(LANG_CREATURE_LIST_CONSOLE
, guid
, cInfo
->Name
, x
, y
, z
, mapid
);
2441 } while (result
->NextRow());
2446 PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE
,cr_id
,cr_count
);
2450 bool ChatHandler::HandleLookupItemCommand(const char* args
)
2455 std::string namepart
= args
;
2456 std::wstring wnamepart
;
2458 // converting string that we try to find to lower case
2459 if(!Utf8toWStr(namepart
,wnamepart
))
2462 wstrToLower(wnamepart
);
2466 // Search in `item_template`
2467 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
2469 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
2473 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2476 ItemLocale
const *il
= objmgr
.GetItemLocale(pProto
->ItemId
);
2479 if (il
->Name
.size() > loc_idx
&& !il
->Name
[loc_idx
].empty())
2481 std::string name
= il
->Name
[loc_idx
];
2483 if (Utf8FitTo(name
, wnamepart
))
2486 PSendSysMessage(LANG_ITEM_LIST_CHAT
, id
, id
, name
.c_str());
2488 PSendSysMessage(LANG_ITEM_LIST_CONSOLE
, id
, name
.c_str());
2496 std::string name
= pProto
->Name1
;
2500 if (Utf8FitTo(name
, wnamepart
))
2503 PSendSysMessage(LANG_ITEM_LIST_CHAT
, id
, id
, name
.c_str());
2505 PSendSysMessage(LANG_ITEM_LIST_CONSOLE
, id
, name
.c_str());
2511 SendSysMessage(LANG_COMMAND_NOITEMFOUND
);
2516 bool ChatHandler::HandleLookupItemSetCommand(const char* args
)
2521 std::string namepart
= args
;
2522 std::wstring wnamepart
;
2524 if(!Utf8toWStr(namepart
,wnamepart
))
2527 // converting string that we try to find to lower case
2528 wstrToLower( wnamepart
);
2530 uint32 counter
= 0; // Counter for figure out that we found smth.
2532 // Search in ItemSet.dbc
2533 for (uint32 id
= 0; id
< sItemSetStore
.GetNumRows(); id
++)
2535 ItemSetEntry
const *set
= sItemSetStore
.LookupEntry(id
);
2538 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
2539 std::string name
= set
->name
[loc
];
2543 if (!Utf8FitTo(name
, wnamepart
))
2546 for(; loc
< MAX_LOCALE
; ++loc
)
2548 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
2551 name
= set
->name
[loc
];
2555 if (Utf8FitTo(name
, wnamepart
))
2560 if(loc
< MAX_LOCALE
)
2562 // send item set in "id - [namedlink locale]" format
2564 PSendSysMessage(LANG_ITEMSET_LIST_CHAT
,id
,id
,name
.c_str(),localeNames
[loc
]);
2566 PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE
,id
,name
.c_str(),localeNames
[loc
]);
2571 if (counter
== 0) // if counter == 0 then we found nth
2572 SendSysMessage(LANG_COMMAND_NOITEMSETFOUND
);
2576 bool ChatHandler::HandleLookupSkillCommand(const char* args
)
2581 // can be NULL in console call
2582 Player
* target
= getSelectedPlayer();
2584 std::string namepart
= args
;
2585 std::wstring wnamepart
;
2587 if(!Utf8toWStr(namepart
,wnamepart
))
2590 // converting string that we try to find to lower case
2591 wstrToLower( wnamepart
);
2593 uint32 counter
= 0; // Counter for figure out that we found smth.
2595 // Search in SkillLine.dbc
2596 for (uint32 id
= 0; id
< sSkillLineStore
.GetNumRows(); id
++)
2598 SkillLineEntry
const *skillInfo
= sSkillLineStore
.LookupEntry(id
);
2601 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
2602 std::string name
= skillInfo
->name
[loc
];
2606 if (!Utf8FitTo(name
, wnamepart
))
2609 for(; loc
< MAX_LOCALE
; ++loc
)
2611 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
2614 name
= skillInfo
->name
[loc
];
2618 if (Utf8FitTo(name
, wnamepart
))
2623 if(loc
< MAX_LOCALE
)
2625 char const* knownStr
= "";
2626 if(target
&& target
->HasSkill(id
))
2627 knownStr
= GetMangosString(LANG_KNOWN
);
2629 // send skill in "id - [namedlink locale]" format
2631 PSendSysMessage(LANG_SKILL_LIST_CHAT
,id
,id
,name
.c_str(),localeNames
[loc
],knownStr
);
2633 PSendSysMessage(LANG_SKILL_LIST_CONSOLE
,id
,name
.c_str(),localeNames
[loc
],knownStr
);
2639 if (counter
== 0) // if counter == 0 then we found nth
2640 SendSysMessage(LANG_COMMAND_NOSKILLFOUND
);
2644 bool ChatHandler::HandleLookupSpellCommand(const char* args
)
2649 // can be NULL at console call
2650 Player
* target
= getSelectedPlayer();
2652 std::string namepart
= args
;
2653 std::wstring wnamepart
;
2655 if(!Utf8toWStr(namepart
,wnamepart
))
2658 // converting string that we try to find to lower case
2659 wstrToLower( wnamepart
);
2661 uint32 counter
= 0; // Counter for figure out that we found smth.
2663 // Search in Spell.dbc
2664 for (uint32 id
= 0; id
< sSpellStore
.GetNumRows(); id
++)
2666 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(id
);
2669 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
2670 std::string name
= spellInfo
->SpellName
[loc
];
2674 if (!Utf8FitTo(name
, wnamepart
))
2677 for(; loc
< MAX_LOCALE
; ++loc
)
2679 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
2682 name
= spellInfo
->SpellName
[loc
];
2686 if (Utf8FitTo(name
, wnamepart
))
2691 if(loc
< MAX_LOCALE
)
2693 bool known
= target
&& target
->HasSpell(id
);
2694 bool learn
= (spellInfo
->Effect
[0] == SPELL_EFFECT_LEARN_SPELL
);
2696 uint32 telentCost
= GetTalentSpellCost(id
);
2698 bool talent
= (telentCost
> 0);
2699 bool passive
= IsPassiveSpell(id
);
2700 bool active
= target
&& (target
->HasAura(id
,0) || target
->HasAura(id
,1) || target
->HasAura(id
,2));
2702 // unit32 used to prevent interpreting uint8 as char at output
2703 // find rank of learned spell for learning spell, or talent rank
2704 uint32 rank
= telentCost
? telentCost
: spellmgr
.GetSpellRank(learn
? spellInfo
->EffectTriggerSpell
[0] : id
);
2706 // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
2707 std::ostringstream ss
;
2709 ss
<< id
<< " - |cffffffff|Hspell:" << id
<< "|h[" << name
;
2711 ss
<< id
<< " - " << name
;
2713 // include rank in link name
2715 ss
<< GetMangosString(LANG_SPELL_RANK
) << rank
;
2718 ss
<< " " << localeNames
[loc
] << "]|h|r";
2720 ss
<< " " << localeNames
[loc
];
2723 ss
<< GetMangosString(LANG_TALENT
);
2725 ss
<< GetMangosString(LANG_PASSIVE
);
2727 ss
<< GetMangosString(LANG_LEARN
);
2729 ss
<< GetMangosString(LANG_KNOWN
);
2731 ss
<< GetMangosString(LANG_ACTIVE
);
2733 SendSysMessage(ss
.str().c_str());
2739 if (counter
== 0) // if counter == 0 then we found nth
2740 SendSysMessage(LANG_COMMAND_NOSPELLFOUND
);
2744 bool ChatHandler::HandleLookupQuestCommand(const char* args
)
2749 // can be NULL at console call
2750 Player
* target
= getSelectedPlayer();
2752 std::string namepart
= args
;
2753 std::wstring wnamepart
;
2755 // converting string that we try to find to lower case
2756 if(!Utf8toWStr(namepart
,wnamepart
))
2759 wstrToLower(wnamepart
);
2761 uint32 counter
= 0 ;
2763 ObjectMgr::QuestMap
const& qTemplates
= objmgr
.GetQuestTemplates();
2764 for (ObjectMgr::QuestMap::const_iterator iter
= qTemplates
.begin(); iter
!= qTemplates
.end(); ++iter
)
2766 Quest
* qinfo
= iter
->second
;
2768 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2771 QuestLocale
const *il
= objmgr
.GetQuestLocale(qinfo
->GetQuestId());
2774 if (il
->Title
.size() > loc_idx
&& !il
->Title
[loc_idx
].empty())
2776 std::string title
= il
->Title
[loc_idx
];
2778 if (Utf8FitTo(title
, wnamepart
))
2780 char const* statusStr
= "";
2784 QuestStatus status
= target
->GetQuestStatus(qinfo
->GetQuestId());
2786 if(status
== QUEST_STATUS_COMPLETE
)
2788 if(target
->GetQuestRewardStatus(qinfo
->GetQuestId()))
2789 statusStr
= GetMangosString(LANG_COMMAND_QUEST_REWARDED
);
2791 statusStr
= GetMangosString(LANG_COMMAND_QUEST_COMPLETE
);
2793 else if(status
== QUEST_STATUS_INCOMPLETE
)
2794 statusStr
= GetMangosString(LANG_COMMAND_QUEST_ACTIVE
);
2798 PSendSysMessage(LANG_QUEST_LIST_CHAT
,qinfo
->GetQuestId(),qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2800 PSendSysMessage(LANG_QUEST_LIST_CONSOLE
,qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2808 std::string title
= qinfo
->GetTitle();
2812 if (Utf8FitTo(title
, wnamepart
))
2814 char const* statusStr
= "";
2818 QuestStatus status
= target
->GetQuestStatus(qinfo
->GetQuestId());
2820 if(status
== QUEST_STATUS_COMPLETE
)
2822 if(target
->GetQuestRewardStatus(qinfo
->GetQuestId()))
2823 statusStr
= GetMangosString(LANG_COMMAND_QUEST_REWARDED
);
2825 statusStr
= GetMangosString(LANG_COMMAND_QUEST_COMPLETE
);
2827 else if(status
== QUEST_STATUS_INCOMPLETE
)
2828 statusStr
= GetMangosString(LANG_COMMAND_QUEST_ACTIVE
);
2832 PSendSysMessage(LANG_QUEST_LIST_CHAT
,qinfo
->GetQuestId(),qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2834 PSendSysMessage(LANG_QUEST_LIST_CONSOLE
,qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2841 SendSysMessage(LANG_COMMAND_NOQUESTFOUND
);
2846 bool ChatHandler::HandleLookupCreatureCommand(const char* args
)
2851 std::string namepart
= args
;
2852 std::wstring wnamepart
;
2854 // converting string that we try to find to lower case
2855 if (!Utf8toWStr (namepart
,wnamepart
))
2858 wstrToLower (wnamepart
);
2862 for (uint32 id
= 0; id
< sCreatureStorage
.MaxEntry
; ++id
)
2864 CreatureInfo
const* cInfo
= sCreatureStorage
.LookupEntry
<CreatureInfo
> (id
);
2868 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2871 CreatureLocale
const *cl
= objmgr
.GetCreatureLocale (id
);
2874 if (cl
->Name
.size() > loc_idx
&& !cl
->Name
[loc_idx
].empty ())
2876 std::string name
= cl
->Name
[loc_idx
];
2878 if (Utf8FitTo (name
, wnamepart
))
2881 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str ());
2883 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE
, id
, name
.c_str ());
2891 std::string name
= cInfo
->Name
;
2895 if (Utf8FitTo(name
, wnamepart
))
2898 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str ());
2900 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE
, id
, name
.c_str ());
2906 SendSysMessage (LANG_COMMAND_NOCREATUREFOUND
);
2911 bool ChatHandler::HandleLookupObjectCommand(const char* args
)
2916 std::string namepart
= args
;
2917 std::wstring wnamepart
;
2919 // converting string that we try to find to lower case
2920 if(!Utf8toWStr(namepart
,wnamepart
))
2923 wstrToLower(wnamepart
);
2927 for (uint32 id
= 0; id
< sGOStorage
.MaxEntry
; id
++ )
2929 GameObjectInfo
const* gInfo
= sGOStorage
.LookupEntry
<GameObjectInfo
>(id
);
2933 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2936 GameObjectLocale
const *gl
= objmgr
.GetGameObjectLocale(id
);
2939 if (gl
->Name
.size() > loc_idx
&& !gl
->Name
[loc_idx
].empty())
2941 std::string name
= gl
->Name
[loc_idx
];
2943 if (Utf8FitTo(name
, wnamepart
))
2946 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT
, id
, id
, name
.c_str());
2948 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE
, id
, name
.c_str());
2956 std::string name
= gInfo
->name
;
2960 if(Utf8FitTo(name
, wnamepart
))
2963 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT
, id
, id
, name
.c_str());
2965 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE
, id
, name
.c_str());
2971 SendSysMessage(LANG_COMMAND_NOGAMEOBJECTFOUND
);
2976 /** \brief GM command level 3 - Create a guild.
2978 * This command allows a GM (level 3) to create a guild.
2980 * The "args" parameter contains the name of the guild leader
2981 * and then the name of the guild.
2984 bool ChatHandler::HandleGuildCreateCommand(const char* args
)
2990 char *lname
= strtok ((char*)args
, " ");
2991 char *gname
= strtok (NULL
, "");
2998 SendSysMessage (LANG_INSERT_GUILD_NAME
);
2999 SetSentErrorMessage (true);
3003 std::string guildname
= gname
;
3005 Player
* player
= ObjectAccessor::Instance ().FindPlayerByName (lname
);
3008 SendSysMessage (LANG_PLAYER_NOT_FOUND
);
3009 SetSentErrorMessage (true);
3013 if (player
->GetGuildId())
3015 SendSysMessage (LANG_PLAYER_IN_GUILD
);
3019 Guild
*guild
= new Guild
;
3020 if (!guild
->create (player
->GetGUID (),guildname
))
3023 SendSysMessage (LANG_GUILD_NOT_CREATED
);
3024 SetSentErrorMessage (true);
3028 objmgr
.AddGuild (guild
);
3032 bool ChatHandler::HandleGuildInviteCommand(const char *args
)
3037 char* par1
= strtok ((char*)args
, " ");
3038 char* par2
= strtok (NULL
, "");
3042 std::string glName
= par2
;
3043 Guild
* targetGuild
= objmgr
.GetGuildByName (glName
);
3047 std::string plName
= par1
;
3048 if (!normalizePlayerName (plName
))
3050 SendSysMessage (LANG_PLAYER_NOT_FOUND
);
3051 SetSentErrorMessage (true);
3056 if (Player
* targetPlayer
= ObjectAccessor::Instance ().FindPlayerByName (plName
.c_str ()))
3057 plGuid
= targetPlayer
->GetGUID ();
3059 plGuid
= objmgr
.GetPlayerGUIDByName (plName
.c_str ());
3064 // players's guild membership checked in AddMember before add
3065 if (!targetGuild
->AddMember (plGuid
,targetGuild
->GetLowestRank ()))
3071 bool ChatHandler::HandleGuildUninviteCommand(const char *args
)
3076 char* par1
= strtok ((char*)args
, " ");
3080 std::string plName
= par1
;
3081 if (!normalizePlayerName (plName
))
3083 SendSysMessage (LANG_PLAYER_NOT_FOUND
);
3084 SetSentErrorMessage (true);
3090 if (Player
* targetPlayer
= ObjectAccessor::Instance ().FindPlayerByName (plName
.c_str ()))
3092 plGuid
= targetPlayer
->GetGUID ();
3093 glId
= targetPlayer
->GetGuildId ();
3097 plGuid
= objmgr
.GetPlayerGUIDByName (plName
.c_str ());
3098 glId
= Player::GetGuildIdFromDB (plGuid
);
3101 if (!plGuid
|| !glId
)
3104 Guild
* targetGuild
= objmgr
.GetGuildById (glId
);
3108 targetGuild
->DelMember (plGuid
);
3113 bool ChatHandler::HandleGuildRankCommand(const char *args
)
3118 char* par1
= strtok ((char*)args
, " ");
3119 char* par2
= strtok (NULL
, " ");
3122 std::string plName
= par1
;
3123 if (!normalizePlayerName (plName
))
3125 SendSysMessage (LANG_PLAYER_NOT_FOUND
);
3126 SetSentErrorMessage (true);
3132 if (Player
* targetPlayer
= ObjectAccessor::Instance ().FindPlayerByName (plName
.c_str ()))
3134 plGuid
= targetPlayer
->GetGUID ();
3135 glId
= targetPlayer
->GetGuildId ();
3139 plGuid
= objmgr
.GetPlayerGUIDByName (plName
.c_str ());
3140 glId
= Player::GetGuildIdFromDB (plGuid
);
3143 if (!plGuid
|| !glId
)
3146 Guild
* targetGuild
= objmgr
.GetGuildById (glId
);
3150 uint32 newrank
= uint32 (atoi (par2
));
3151 if (newrank
> targetGuild
->GetLowestRank ())
3154 targetGuild
->ChangeRank (plGuid
,newrank
);
3159 bool ChatHandler::HandleGuildDeleteCommand(const char* args
)
3164 char* par1
= strtok ((char*)args
, " ");
3168 std::string gld
= par1
;
3170 Guild
* targetGuild
= objmgr
.GetGuildByName (gld
);
3174 targetGuild
->Disband ();
3179 bool ChatHandler::HandleGetDistanceCommand(const char* /*args*/)
3181 Unit
* pUnit
= getSelectedUnit();
3185 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3186 SetSentErrorMessage(true);
3190 PSendSysMessage(LANG_DISTANCE
, m_session
->GetPlayer()->GetDistance(pUnit
),m_session
->GetPlayer()->GetDistance2d(pUnit
));
3197 bool ChatHandler::HandleAddWeaponCommand(const char* /*args*/)
3202 uint64 guid = m_session->GetPlayer()->GetSelection();
3205 SendSysMessage(LANG_NO_SELECTION);
3209 Creature *pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
3213 SendSysMessage(LANG_SELECT_CREATURE);
3217 char* pSlotID = strtok((char*)args, " ");
3221 char* pItemID = strtok(NULL, " ");
3225 uint32 ItemID = atoi(pItemID);
3226 uint32 SlotID = atoi(pSlotID);
3228 ItemPrototype* tmpItem = objmgr.GetItemPrototype(ItemID);
3236 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID);
3240 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID);
3244 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID);
3248 PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST,SlotID);
3254 PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT,ItemID,tmpItem->Name1,SlotID);
3259 PSendSysMessage(LANG_ITEM_NOT_FOUND,ItemID);
3266 bool ChatHandler::HandleDieCommand(const char* /*args*/)
3268 Unit
* target
= getSelectedUnit();
3270 if(!target
|| !m_session
->GetPlayer()->GetSelection())
3272 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3273 SetSentErrorMessage(true);
3277 if( target
->isAlive() )
3279 m_session
->GetPlayer()->DealDamage(target
, target
->GetHealth(), NULL
, DIRECT_DAMAGE
, SPELL_SCHOOL_MASK_NORMAL
, NULL
, false);
3285 bool ChatHandler::HandleDamageCommand(const char * args
)
3290 Unit
* target
= getSelectedUnit();
3292 if(!target
|| !m_session
->GetPlayer()->GetSelection())
3294 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3295 SetSentErrorMessage(true);
3299 if( !target
->isAlive() )
3302 char* damageStr
= strtok((char*)args
, " ");
3306 int32 damage
= atoi((char*)damageStr
);
3310 char* schoolStr
= strtok((char*)NULL
, " ");
3312 // flat melee damage without resistence/etc reduction
3315 m_session
->GetPlayer()->DealDamage(target
, damage
, NULL
, DIRECT_DAMAGE
, SPELL_SCHOOL_MASK_NORMAL
, NULL
, false);
3316 m_session
->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2
, target
, 1, SPELL_SCHOOL_MASK_NORMAL
, damage
, 0, 0, VICTIMSTATE_NORMAL
, 0);
3320 uint32 school
= schoolStr
? atoi((char*)schoolStr
) : SPELL_SCHOOL_NORMAL
;
3321 if(school
>= MAX_SPELL_SCHOOL
)
3324 SpellSchoolMask schoolmask
= SpellSchoolMask(1 << school
);
3326 if ( schoolmask
& SPELL_SCHOOL_MASK_NORMAL
)
3327 damage
= m_session
->GetPlayer()->CalcArmorReducedDamage(target
, damage
);
3329 char* spellStr
= strtok((char*)NULL
, " ");
3331 // melee damage by specific school
3337 m_session
->GetPlayer()->CalcAbsorbResist(target
,schoolmask
, SPELL_DIRECT_DAMAGE
, damage
, &absorb
, &resist
);
3339 if (damage
<= absorb
+ resist
)
3342 damage
-= absorb
+ resist
;
3344 m_session
->GetPlayer()->DealDamage(target
, damage
, NULL
, DIRECT_DAMAGE
, schoolmask
, NULL
, false);
3345 m_session
->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2
, target
, 1, schoolmask
, damage
, absorb
, resist
, VICTIMSTATE_NORMAL
, 0);
3351 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3352 uint32 spellid
= extractSpellIdFromLink((char*)args
);
3353 if(!spellid
|| !sSpellStore
.LookupEntry(spellid
))
3356 m_session
->GetPlayer()->SpellNonMeleeDamageLog(target
, spellid
, damage
, false);
3360 bool ChatHandler::HandleModifyArenaCommand(const char * args
)
3365 Player
*target
= getSelectedPlayer();
3368 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3369 SetSentErrorMessage(true);
3373 int32 amount
= (uint32
)atoi(args
);
3375 target
->ModifyArenaPoints(amount
);
3377 PSendSysMessage(LANG_COMMAND_MODIFY_ARENA
, target
->GetName(), target
->GetArenaPoints());
3382 bool ChatHandler::HandleReviveCommand(const char* args
)
3384 Player
* SelectedPlayer
= NULL
;
3388 std::string name
= args
;
3389 if(!normalizePlayerName(name
))
3391 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3392 SetSentErrorMessage(true);
3396 SelectedPlayer
= objmgr
.GetPlayer(name
.c_str());
3399 SelectedPlayer
= getSelectedPlayer();
3403 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3404 SetSentErrorMessage(true);
3408 SelectedPlayer
->ResurrectPlayer(0.5f
);
3409 SelectedPlayer
->SpawnCorpseBones();
3410 SelectedPlayer
->SaveToDB();
3414 bool ChatHandler::HandleAuraCommand(const char* args
)
3416 char* px
= strtok((char*)args
, " ");
3420 Unit
*target
= getSelectedUnit();
3423 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3424 SetSentErrorMessage(true);
3428 uint32 spellID
= (uint32
)atoi(px
);
3429 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry( spellID
);
3432 for(uint32 i
= 0;i
<3;i
++)
3434 uint8 eff
= spellInfo
->Effect
[i
];
3435 if (eff
>=TOTAL_SPELL_EFFECTS
)
3437 if( IsAreaAuraEffect(eff
) ||
3438 eff
== SPELL_EFFECT_APPLY_AURA
||
3439 eff
== SPELL_EFFECT_PERSISTENT_AREA_AURA
)
3441 Aura
*Aur
= CreateAura(spellInfo
, i
, NULL
, target
);
3442 target
->AddAura(Aur
);
3450 bool ChatHandler::HandleUnAuraCommand(const char* args
)
3452 char* px
= strtok((char*)args
, " ");
3456 Unit
*target
= getSelectedUnit();
3459 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3460 SetSentErrorMessage(true);
3464 std::string argstr
= args
;
3465 if (argstr
== "all")
3467 target
->RemoveAllAuras();
3471 uint32 spellID
= (uint32
)atoi(px
);
3472 target
->RemoveAurasDueToSpell(spellID
);
3477 bool ChatHandler::HandleLinkGraveCommand(const char* args
)
3482 char* px
= strtok((char*)args
, " ");
3486 uint32 g_id
= (uint32
)atoi(px
);
3490 char* px2
= strtok(NULL
, " ");
3494 else if (strncmp(px2
,"horde",6)==0)
3496 else if (strncmp(px2
,"alliance",9)==0)
3501 WorldSafeLocsEntry
const* graveyard
= sWorldSafeLocsStore
.LookupEntry(g_id
);
3505 PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST
, g_id
);
3506 SetSentErrorMessage(true);
3510 Player
* player
= m_session
->GetPlayer();
3512 uint32 zoneId
= player
->GetZoneId();
3514 AreaTableEntry
const *areaEntry
= GetAreaEntryByAreaID(zoneId
);
3515 if(!areaEntry
|| areaEntry
->zone
!=0 )
3517 PSendSysMessage(LANG_COMMAND_GRAVEYARDWRONGZONE
, g_id
,zoneId
);
3518 SetSentErrorMessage(true);
3522 if(graveyard
->map_id
!= areaEntry
->mapid
&& g_team
!= 0)
3524 SendSysMessage(LANG_COMMAND_GRAVEYARDWRONGTEAM
);
3525 SetSentErrorMessage(true);
3529 if(objmgr
.AddGraveYardLink(g_id
,player
->GetZoneId(),g_team
))
3530 PSendSysMessage(LANG_COMMAND_GRAVEYARDLINKED
, g_id
,zoneId
);
3532 PSendSysMessage(LANG_COMMAND_GRAVEYARDALRLINKED
, g_id
,zoneId
);
3537 bool ChatHandler::HandleNearGraveCommand(const char* args
)
3541 size_t argslen
= strlen(args
);
3545 else if (strncmp((char*)args
,"horde",argslen
)==0)
3547 else if (strncmp((char*)args
,"alliance",argslen
)==0)
3552 Player
* player
= m_session
->GetPlayer();
3554 WorldSafeLocsEntry
const* graveyard
= objmgr
.GetClosestGraveYard(
3555 player
->GetPositionX(), player
->GetPositionY(), player
->GetPositionZ(),player
->GetMapId(),g_team
);
3559 uint32 g_id
= graveyard
->ID
;
3561 GraveYardData
const* data
= objmgr
.FindGraveYardData(g_id
,player
->GetZoneId());
3564 PSendSysMessage(LANG_COMMAND_GRAVEYARDERROR
,g_id
);
3565 SetSentErrorMessage(true);
3569 g_team
= data
->team
;
3571 std::string team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_NOTEAM
);
3574 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ANY
);
3575 else if(g_team
== HORDE
)
3576 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE
);
3577 else if(g_team
== ALLIANCE
)
3578 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE
);
3580 PSendSysMessage(LANG_COMMAND_GRAVEYARDNEAREST
, g_id
,team_name
.c_str(),player
->GetZoneId());
3584 std::string team_name
;
3587 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ANY
);
3588 else if(g_team
== HORDE
)
3589 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE
);
3590 else if(g_team
== ALLIANCE
)
3591 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE
);
3593 if(g_team
== ~uint32(0))
3594 PSendSysMessage(LANG_COMMAND_ZONENOGRAVEYARDS
, player
->GetZoneId());
3596 PSendSysMessage(LANG_COMMAND_ZONENOGRAFACTION
, player
->GetZoneId(),team_name
.c_str());
3603 bool ChatHandler::HandleNpcPlayEmoteCommand(const char* args
)
3605 uint32 emote
= atoi((char*)args
);
3607 Creature
* target
= getSelectedCreature();
3610 SendSysMessage(LANG_SELECT_CREATURE
);
3611 SetSentErrorMessage(true);
3615 target
->SetUInt32Value(UNIT_NPC_EMOTESTATE
,emote
);
3620 bool ChatHandler::HandleNpcInfoCommand(const char* /*args*/)
3622 Creature
* target
= getSelectedCreature();
3626 SendSysMessage(LANG_SELECT_CREATURE
);
3627 SetSentErrorMessage(true);
3631 uint32 faction
= target
->getFaction();
3632 uint32 npcflags
= target
->GetUInt32Value(UNIT_NPC_FLAGS
);
3633 uint32 displayid
= target
->GetDisplayId();
3634 uint32 nativeid
= target
->GetNativeDisplayId();
3635 uint32 Entry
= target
->GetEntry();
3636 CreatureInfo
const* cInfo
= target
->GetCreatureInfo();
3638 int32 curRespawnDelay
= target
->GetRespawnTimeEx()-time(NULL
);
3639 if(curRespawnDelay
< 0)
3640 curRespawnDelay
= 0;
3641 std::string curRespawnDelayStr
= secsToTimeString(curRespawnDelay
,true);
3642 std::string defRespawnDelayStr
= secsToTimeString(target
->GetRespawnDelay(),true);
3644 PSendSysMessage(LANG_NPCINFO_CHAR
, target
->GetDBTableGUIDLow(), faction
, npcflags
, Entry
, displayid
, nativeid
);
3645 PSendSysMessage(LANG_NPCINFO_LEVEL
, target
->getLevel());
3646 PSendSysMessage(LANG_NPCINFO_HEALTH
,target
->GetCreateHealth(), target
->GetMaxHealth(), target
->GetHealth());
3647 PSendSysMessage(LANG_NPCINFO_FLAGS
, target
->GetUInt32Value(UNIT_FIELD_FLAGS
), target
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
), target
->getFaction());
3648 PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES
, defRespawnDelayStr
.c_str(),curRespawnDelayStr
.c_str());
3649 PSendSysMessage(LANG_NPCINFO_LOOT
, cInfo
->lootid
,cInfo
->pickpocketLootId
,cInfo
->SkinLootId
);
3650 PSendSysMessage(LANG_NPCINFO_DUNGEON_ID
, target
->GetInstanceId());
3651 PSendSysMessage(LANG_NPCINFO_POSITION
,float(target
->GetPositionX()), float(target
->GetPositionY()), float(target
->GetPositionZ()));
3653 if ((npcflags
& UNIT_NPC_FLAG_VENDOR
) )
3655 SendSysMessage(LANG_NPCINFO_VENDOR
);
3657 if ((npcflags
& UNIT_NPC_FLAG_TRAINER
) )
3659 SendSysMessage(LANG_NPCINFO_TRAINER
);
3665 bool ChatHandler::HandleExploreCheatCommand(const char* args
)
3670 int flag
= atoi((char*)args
);
3672 Player
*chr
= getSelectedPlayer();
3675 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3676 SetSentErrorMessage(true);
3682 PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL
, chr
->GetName());
3683 if (needReportToTarget(chr
))
3684 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_EXPLORE_SET_ALL
,GetName());
3688 PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING
, chr
->GetName());
3689 if (needReportToTarget(chr
))
3690 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_EXPLORE_SET_NOTHING
,GetName());
3693 for (uint8 i
=0; i
<128; i
++)
3697 m_session
->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1
+i
,0xFFFFFFFF);
3701 m_session
->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1
+i
,0);
3708 bool ChatHandler::HandleHoverCommand(const char* args
)
3710 char* px
= strtok((char*)args
, " ");
3717 m_session
->GetPlayer()->SetHover(flag
);
3720 SendSysMessage(LANG_HOVER_ENABLED
);
3722 SendSysMessage(LANG_HOVER_DISABLED
);
3727 bool ChatHandler::HandleLevelUpCommand(const char* args
)
3729 char* px
= strtok((char*)args
, " ");
3730 char* py
= strtok((char*)NULL
, " ");
3732 // command format parsing
3733 char* pname
= (char*)NULL
;
3736 if(px
&& py
) // .levelup name level
3738 addlevel
= atoi(py
);
3741 else if(px
&& !py
) // .levelup name OR .levelup level
3743 if(isalpha(px
[0])) // .levelup name
3745 else // .levelup level
3746 addlevel
= atoi(px
);
3748 // else .levelup - nothing do for prepering
3752 uint64 chr_guid
= 0;
3756 if(pname
) // player by name
3759 if(!normalizePlayerName(name
))
3761 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3762 SetSentErrorMessage(true);
3766 chr
= objmgr
.GetPlayer(name
.c_str());
3767 if(!chr
) // not in game
3769 chr_guid
= objmgr
.GetPlayerGUIDByName(name
);
3772 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3773 SetSentErrorMessage(true);
3778 else // player by selection
3780 chr
= getSelectedPlayer();
3784 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3785 SetSentErrorMessage(true);
3789 name
= chr
->GetName();
3792 assert(chr
|| chr_guid
);
3794 int32 oldlevel
= chr
? chr
->getLevel() : Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL
,chr_guid
);
3795 int32 newlevel
= oldlevel
+ addlevel
;
3798 if(newlevel
> 255) // hardcoded maximum level
3803 chr
->GiveLevel(newlevel
);
3804 chr
->InitTalentForLevel();
3805 chr
->SetUInt32Value(PLAYER_XP
,0);
3807 if(oldlevel
== newlevel
)
3808 ChatHandler(chr
).SendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET
);
3810 if(oldlevel
< newlevel
)
3811 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_LEVEL_UP
,newlevel
-oldlevel
);
3813 if(oldlevel
> newlevel
)
3814 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_LEVEL_DOWN
,newlevel
-oldlevel
);
3818 // update levle and XP at level, all other will be updated at loading
3820 Player::LoadValuesArrayFromDB(values
,chr_guid
);
3821 Player::SetUInt32ValueInArray(values
,UNIT_FIELD_LEVEL
,newlevel
);
3822 Player::SetUInt32ValueInArray(values
,PLAYER_XP
,0);
3823 Player::SaveValuesArrayInDB(values
,chr_guid
);
3826 if(m_session
->GetPlayer() != chr
) // including chr==NULL
3827 PSendSysMessage(LANG_YOU_CHANGE_LVL
,name
.c_str(),newlevel
);
3831 bool ChatHandler::HandleShowAreaCommand(const char* args
)
3836 int area
= atoi((char*)args
);
3838 Player
*chr
= getSelectedPlayer();
3841 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3842 SetSentErrorMessage(true);
3846 int offset
= area
/ 32;
3847 uint32 val
= (uint32
)(1 << (area
% 32));
3851 SendSysMessage(LANG_BAD_VALUE
);
3852 SetSentErrorMessage(true);
3856 uint32 currFields
= chr
->GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
3857 chr
->SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
| val
));
3859 SendSysMessage(LANG_EXPLORE_AREA
);
3863 bool ChatHandler::HandleHideAreaCommand(const char* args
)
3868 int area
= atoi((char*)args
);
3870 Player
*chr
= getSelectedPlayer();
3873 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3874 SetSentErrorMessage(true);
3878 int offset
= area
/ 32;
3879 uint32 val
= (uint32
)(1 << (area
% 32));
3883 SendSysMessage(LANG_BAD_VALUE
);
3884 SetSentErrorMessage(true);
3888 uint32 currFields
= chr
->GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
3889 chr
->SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
^ val
));
3891 SendSysMessage(LANG_UNEXPLORE_AREA
);
3895 bool ChatHandler::HandleUpdate(const char* args
)
3903 char* pUpdateIndex
= strtok((char*)args
, " ");
3905 Unit
* chr
= getSelectedUnit();
3908 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3909 SetSentErrorMessage(true);
3917 updateIndex
= atoi(pUpdateIndex
);
3919 if(chr
->GetTypeId() == TYPEID_PLAYER
)
3921 if (updateIndex
>=PLAYER_END
) return true;
3925 if (updateIndex
>=UNIT_END
) return true;
3928 char* pvalue
= strtok(NULL
, " ");
3931 value
=chr
->GetUInt32Value(updateIndex
);
3933 PSendSysMessage(LANG_UPDATE
, chr
->GetGUIDLow(),updateIndex
,value
);
3939 PSendSysMessage(LANG_UPDATE_CHANGE
, chr
->GetGUIDLow(),updateIndex
,value
);
3941 chr
->SetUInt32Value(updateIndex
,value
);
3946 bool ChatHandler::HandleBankCommand(const char* /*args*/)
3948 m_session
->SendShowBank( m_session
->GetPlayer()->GetGUID() );
3953 bool ChatHandler::HandleChangeWeather(const char* args
)
3959 if (!sWorld
.getConfig(CONFIG_WEATHER
))
3961 SendSysMessage(LANG_WEATHER_DISABLED
);
3962 SetSentErrorMessage(true);
3966 //*Change the weather of a cell
3967 char* px
= strtok((char*)args
, " ");
3968 char* py
= strtok(NULL
, " ");
3973 uint32 type
= (uint32
)atoi(px
); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
3974 float grade
= (float)atof(py
); //0 to 1, sending -1 is instand good weather
3976 Player
*player
= m_session
->GetPlayer();
3977 uint32 zoneid
= player
->GetZoneId();
3979 Weather
* wth
= sWorld
.FindWeather(zoneid
);
3982 wth
= sWorld
.AddWeather(zoneid
);
3985 SendSysMessage(LANG_NO_WEATHER
);
3986 SetSentErrorMessage(true);
3990 wth
->SetWeather(WeatherType(type
), grade
);
3995 bool ChatHandler::HandleSetValue(const char* args
)
4000 char* px
= strtok((char*)args
, " ");
4001 char* py
= strtok(NULL
, " ");
4002 char* pz
= strtok(NULL
, " ");
4007 Unit
* target
= getSelectedUnit();
4010 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4011 SetSentErrorMessage(true);
4015 uint64 guid
= target
->GetGUID();
4017 uint32 Opcode
= (uint32
)atoi(px
);
4018 if(Opcode
>= target
->GetValuesCount())
4020 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, GUID_LOPART(guid
), target
->GetValuesCount());
4025 bool isint32
= true;
4027 isint32
= (bool)atoi(pz
);
4030 iValue
= (uint32
)atoi(py
);
4031 sLog
.outDebug(GetMangosString(LANG_SET_UINT
), GUID_LOPART(guid
), Opcode
, iValue
);
4032 target
->SetUInt32Value( Opcode
, iValue
);
4033 PSendSysMessage(LANG_SET_UINT_FIELD
, GUID_LOPART(guid
), Opcode
,iValue
);
4037 fValue
= (float)atof(py
);
4038 sLog
.outDebug(GetMangosString(LANG_SET_FLOAT
), GUID_LOPART(guid
), Opcode
, fValue
);
4039 target
->SetFloatValue( Opcode
, fValue
);
4040 PSendSysMessage(LANG_SET_FLOAT_FIELD
, GUID_LOPART(guid
), Opcode
,fValue
);
4046 bool ChatHandler::HandleGetValue(const char* args
)
4051 char* px
= strtok((char*)args
, " ");
4052 char* pz
= strtok(NULL
, " ");
4057 Unit
* target
= getSelectedUnit();
4060 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4061 SetSentErrorMessage(true);
4065 uint64 guid
= target
->GetGUID();
4067 uint32 Opcode
= (uint32
)atoi(px
);
4068 if(Opcode
>= target
->GetValuesCount())
4070 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, GUID_LOPART(guid
), target
->GetValuesCount());
4075 bool isint32
= true;
4077 isint32
= (bool)atoi(pz
);
4081 iValue
= target
->GetUInt32Value( Opcode
);
4082 sLog
.outDebug(GetMangosString(LANG_GET_UINT
), GUID_LOPART(guid
), Opcode
, iValue
);
4083 PSendSysMessage(LANG_GET_UINT_FIELD
, GUID_LOPART(guid
), Opcode
, iValue
);
4087 fValue
= target
->GetFloatValue( Opcode
);
4088 sLog
.outDebug(GetMangosString(LANG_GET_FLOAT
), GUID_LOPART(guid
), Opcode
, fValue
);
4089 PSendSysMessage(LANG_GET_FLOAT_FIELD
, GUID_LOPART(guid
), Opcode
, fValue
);
4095 bool ChatHandler::HandleSet32Bit(const char* args
)
4100 char* px
= strtok((char*)args
, " ");
4101 char* py
= strtok(NULL
, " ");
4106 uint32 Opcode
= (uint32
)atoi(px
);
4107 uint32 Value
= (uint32
)atoi(py
);
4108 if (Value
> 32) //uint32 = 32 bits
4111 sLog
.outDebug(GetMangosString(LANG_SET_32BIT
), Opcode
, Value
);
4113 m_session
->GetPlayer( )->SetUInt32Value( Opcode
, 2^Value
);
4115 PSendSysMessage(LANG_SET_32BIT_FIELD
, Opcode
,1);
4119 bool ChatHandler::HandleMod32Value(const char* args
)
4124 char* px
= strtok((char*)args
, " ");
4125 char* py
= strtok(NULL
, " ");
4130 uint32 Opcode
= (uint32
)atoi(px
);
4131 int Value
= atoi(py
);
4133 if(Opcode
>= m_session
->GetPlayer()->GetValuesCount())
4135 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, m_session
->GetPlayer()->GetGUIDLow(), m_session
->GetPlayer( )->GetValuesCount());
4139 sLog
.outDebug(GetMangosString(LANG_CHANGE_32BIT
), Opcode
, Value
);
4141 int CurrentValue
= (int)m_session
->GetPlayer( )->GetUInt32Value( Opcode
);
4143 CurrentValue
+= Value
;
4144 m_session
->GetPlayer( )->SetUInt32Value( Opcode
, (uint32
)CurrentValue
);
4146 PSendSysMessage(LANG_CHANGE_32BIT_FIELD
, Opcode
,CurrentValue
);
4151 bool ChatHandler::HandleAddTeleCommand(const char * args
)
4156 Player
*player
=m_session
->GetPlayer();
4160 std::string name
= args
;
4162 if(objmgr
.GetGameTele(name
))
4164 SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST
);
4165 SetSentErrorMessage(true);
4170 tele
.position_x
= player
->GetPositionX();
4171 tele
.position_y
= player
->GetPositionY();
4172 tele
.position_z
= player
->GetPositionZ();
4173 tele
.orientation
= player
->GetOrientation();
4174 tele
.mapId
= player
->GetMapId();
4177 if(objmgr
.AddGameTele(tele
))
4179 SendSysMessage(LANG_COMMAND_TP_ADDED
);
4183 SendSysMessage(LANG_COMMAND_TP_ADDEDERR
);
4184 SetSentErrorMessage(true);
4191 bool ChatHandler::HandleDelTeleCommand(const char * args
)
4196 std::string name
= args
;
4198 if(!objmgr
.DeleteGameTele(name
))
4200 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
4201 SetSentErrorMessage(true);
4205 SendSysMessage(LANG_COMMAND_TP_DELETED
);
4209 bool ChatHandler::HandleListAurasCommand (const char * /*args*/)
4211 Unit
*unit
= getSelectedUnit();
4214 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4215 SetSentErrorMessage(true);
4219 char const* talentStr
= GetMangosString(LANG_TALENT
);
4220 char const* passiveStr
= GetMangosString(LANG_PASSIVE
);
4222 Unit::AuraMap
const& uAuras
= unit
->GetAuras();
4223 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS
, uAuras
.size());
4224 for (Unit::AuraMap::const_iterator itr
= uAuras
.begin(); itr
!= uAuras
.end(); ++itr
)
4226 bool talent
= GetTalentSpellCost(itr
->second
->GetId()) > 0;
4227 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL
, itr
->second
->GetId(), itr
->second
->GetEffIndex(),
4228 itr
->second
->GetModifier()->m_auraname
, itr
->second
->GetAuraDuration(), itr
->second
->GetAuraMaxDuration(),
4229 itr
->second
->GetSpellProto()->SpellName
[m_session
->GetSessionDbcLocale()],
4230 (itr
->second
->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4231 IS_PLAYER_GUID(itr
->second
->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr
->second
->GetCasterGUID()));
4233 for (int i
= 0; i
< TOTAL_AURAS
; i
++)
4235 Unit::AuraList
const& uAuraList
= unit
->GetAurasByType(AuraType(i
));
4236 if (uAuraList
.empty()) continue;
4237 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE
, uAuraList
.size(), i
);
4238 for (Unit::AuraList::const_iterator itr
= uAuraList
.begin(); itr
!= uAuraList
.end(); ++itr
)
4240 bool talent
= GetTalentSpellCost((*itr
)->GetId()) > 0;
4241 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE
, (*itr
)->GetId(), (*itr
)->GetEffIndex(),
4242 (*itr
)->GetSpellProto()->SpellName
[m_session
->GetSessionDbcLocale()],((*itr
)->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4243 IS_PLAYER_GUID((*itr
)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr
)->GetCasterGUID()));
4249 bool ChatHandler::HandleResetHonorCommand (const char * args
)
4251 char* pName
= strtok((char*)args
, "");
4252 Player
*player
= NULL
;
4255 std::string name
= pName
;
4256 if(!normalizePlayerName(name
))
4258 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4259 SetSentErrorMessage(true);
4263 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4264 player
= objmgr
.GetPlayer(guid
);
4267 player
= getSelectedPlayer();
4271 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4275 player
->SetUInt32Value(PLAYER_FIELD_KILLS
, 0);
4276 player
->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS
, 0);
4277 player
->SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY
, 0);
4278 player
->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION
, 0);
4279 player
->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION
, 0);
4284 static bool HandleResetStatsOrLevelHelper(Player
* player
)
4286 PlayerInfo
const *info
= objmgr
.GetPlayerInfo(player
->getRace(), player
->getClass());
4287 if(!info
) return false;
4289 ChrClassesEntry
const* cEntry
= sChrClassesStore
.LookupEntry(player
->getClass());
4292 sLog
.outError("Class %u not found in DBC (Wrong DBC files?)",player
->getClass());
4296 uint8 powertype
= cEntry
->powerType
;
4299 if(powertype
== POWER_RAGE
)
4300 unitfield
= 0x1100EE00;
4301 else if(powertype
== POWER_ENERGY
)
4302 unitfield
= 0x00000000;
4303 else if(powertype
== POWER_MANA
)
4304 unitfield
= 0x0000EE00;
4307 sLog
.outError("Invalid default powertype %u for player (class %u)",powertype
,player
->getClass());
4311 // reset m_form if no aura
4312 if(!player
->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT
))
4313 player
->m_form
= FORM_NONE
;
4315 player
->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS
, DEFAULT_WORLD_OBJECT_SIZE
);
4316 player
->SetFloatValue(UNIT_FIELD_COMBATREACH
, 1.5f
);
4318 player
->setFactionForRace(player
->getRace());
4320 player
->SetUInt32Value(UNIT_FIELD_BYTES_0
, ( ( player
->getRace() ) | ( player
->getClass() << 8 ) | ( player
->getGender() << 16 ) | ( powertype
<< 24 ) ) );
4322 // reset only if player not in some form;
4323 if(player
->m_form
==FORM_NONE
)
4325 switch(player
->getGender())
4328 player
->SetDisplayId(info
->displayId_f
);
4329 player
->SetNativeDisplayId(info
->displayId_f
);
4332 player
->SetDisplayId(info
->displayId_m
);
4333 player
->SetNativeDisplayId(info
->displayId_m
);
4340 // set UNIT_FIELD_BYTES_1 to init state but preserve m_form value
4341 player
->SetUInt32Value(UNIT_FIELD_BYTES_1
, unitfield
);
4342 player
->SetByteValue(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_UNK3
| UNIT_BYTE2_FLAG_UNK5
);
4343 player
->SetByteValue(UNIT_FIELD_BYTES_2
, 3, player
->m_form
);
4345 player
->SetUInt32Value(UNIT_FIELD_FLAGS
, UNIT_FLAG_PVP_ATTACKABLE
);
4347 //-1 is default value
4348 player
->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX
, uint32(-1));
4350 //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000 );
4354 bool ChatHandler::HandleResetLevelCommand(const char * args
)
4356 char* pName
= strtok((char*)args
, "");
4357 Player
*player
= NULL
;
4360 std::string name
= pName
;
4361 if(!normalizePlayerName(name
))
4363 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4364 SetSentErrorMessage(true);
4368 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4369 player
= objmgr
.GetPlayer(guid
);
4372 player
= getSelectedPlayer();
4376 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4377 SetSentErrorMessage(true);
4381 if(!HandleResetStatsOrLevelHelper(player
))
4384 player
->SetLevel(1);
4385 player
->InitStatsForLevel(true);
4386 player
->InitTaxiNodesForLevel();
4387 player
->InitTalentForLevel();
4388 player
->SetUInt32Value(PLAYER_XP
,0);
4390 // reset level to summoned pet
4391 Pet
* pet
= player
->GetPet();
4392 if(pet
&& pet
->getPetType()==SUMMON_PET
)
4393 pet
->InitStatsForLevel(1);
4398 bool ChatHandler::HandleResetStatsCommand(const char * args
)
4400 char* pName
= strtok((char*)args
, "");
4401 Player
*player
= NULL
;
4404 std::string name
= pName
;
4405 if(!normalizePlayerName(name
))
4407 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4408 SetSentErrorMessage(true);
4412 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4413 player
= objmgr
.GetPlayer(guid
);
4416 player
= getSelectedPlayer();
4420 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4421 SetSentErrorMessage(true);
4425 if(!HandleResetStatsOrLevelHelper(player
))
4428 player
->InitStatsForLevel(true);
4429 player
->InitTaxiNodesForLevel();
4430 player
->InitTalentForLevel();
4435 bool ChatHandler::HandleResetSpellsCommand(const char * args
)
4437 char* pName
= strtok((char*)args
, "");
4438 Player
*player
= NULL
;
4439 uint64 playerGUID
= 0;
4442 std::string name
= pName
;
4444 if(!normalizePlayerName(name
))
4446 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4447 SetSentErrorMessage(true);
4451 player
= objmgr
.GetPlayer(name
.c_str());
4453 playerGUID
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4456 player
= getSelectedPlayer();
4458 if(!player
&& !playerGUID
)
4460 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4461 SetSentErrorMessage(true);
4467 player
->resetSpells();
4469 ChatHandler(player
).SendSysMessage(LANG_RESET_SPELLS
);
4471 if(m_session
->GetPlayer()!=player
)
4472 PSendSysMessage(LANG_RESET_SPELLS_ONLINE
,player
->GetName());
4476 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS
), GUID_LOPART(playerGUID
));
4477 PSendSysMessage(LANG_RESET_SPELLS_OFFLINE
,pName
);
4483 bool ChatHandler::HandleResetTalentsCommand(const char * args
)
4485 char* pName
= strtok((char*)args
, "");
4486 Player
*player
= NULL
;
4487 uint64 playerGUID
= 0;
4490 std::string name
= pName
;
4491 if(!normalizePlayerName(name
))
4493 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4494 SetSentErrorMessage(true);
4498 player
= objmgr
.GetPlayer(name
.c_str());
4500 playerGUID
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4503 player
= getSelectedPlayer();
4505 if(!player
&& !playerGUID
)
4507 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4508 SetSentErrorMessage(true);
4514 player
->resetTalents(true);
4516 ChatHandler(player
).SendSysMessage(LANG_RESET_TALENTS
);
4518 if(m_session
->GetPlayer()!=player
)
4519 PSendSysMessage(LANG_RESET_TALENTS_ONLINE
,player
->GetName());
4523 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_TALENTS
), GUID_LOPART(playerGUID
) );
4524 PSendSysMessage(LANG_RESET_TALENTS_OFFLINE
,pName
);
4530 bool ChatHandler::HandleResetAllCommand(const char * args
)
4535 std::string casename
= args
;
4537 AtLoginFlags atLogin
;
4539 // Command specially created as single command to prevent using short case names
4540 if(casename
=="spells")
4542 atLogin
= AT_LOGIN_RESET_SPELLS
;
4543 sWorld
.SendWorldText(LANG_RESETALL_SPELLS
);
4545 else if(casename
=="talents")
4547 atLogin
= AT_LOGIN_RESET_TALENTS
;
4548 sWorld
.SendWorldText(LANG_RESETALL_TALENTS
);
4552 PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE
,args
);
4553 SetSentErrorMessage(true);
4557 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u'",atLogin
);
4558 HashMapHolder
<Player
>::MapType
const& plist
= ObjectAccessor::Instance().GetPlayers();
4559 for(HashMapHolder
<Player
>::MapType::const_iterator itr
= plist
.begin(); itr
!= plist
.end(); ++itr
)
4560 itr
->second
->SetAtLoginFlag(atLogin
);
4565 bool ChatHandler::HandleShutDownCommand(const char* args
)
4570 if(std::string(args
)=="cancel")
4572 sWorld
.ShutdownCancel();
4576 int32 time
= atoi(args
);
4578 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4579 if(time
== 0 && (args
[0]!='0' || args
[1]!='\0') || time
< 0)
4582 sWorld
.ShutdownServ(time
);
4587 bool ChatHandler::HandleRestartCommand(const char* args
)
4592 if(std::string(args
)=="cancel")
4594 sWorld
.ShutdownCancel();
4598 int32 time
= atoi(args
);
4600 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4601 if(time
== 0 && (args
[0]!='0' || args
[1]!='\0') || time
< 0)
4604 sWorld
.ShutdownServ(time
, SHUTDOWN_MASK_RESTART
);
4609 bool ChatHandler::HandleIdleRestartCommand(const char* args
)
4614 if(std::string(args
)=="cancel")
4616 sWorld
.ShutdownCancel();
4620 int32 time
= atoi(args
);
4622 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4623 if(time
== 0 && (args
[0]!='0' || args
[1]!='\0') || time
< 0)
4626 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_RESTART
+SHUTDOWN_MASK_IDLE
);
4631 bool ChatHandler::HandleIdleShutDownCommand(const char* args
)
4636 if(std::string(args
)=="cancel")
4638 sWorld
.ShutdownCancel();
4642 int32 time
= atoi(args
);
4644 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4645 if(time
== 0 && (args
[0]!='0' || args
[1]!='\0') || time
< 0)
4648 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_IDLE
);
4653 bool ChatHandler::HandleAddQuest(const char* args
)
4655 Player
* player
= getSelectedPlayer();
4658 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4659 SetSentErrorMessage(true);
4663 // .addquest #entry'
4664 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4665 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4669 uint32 entry
= atol(cId
);
4671 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
4675 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
,entry
);
4676 SetSentErrorMessage(true);
4680 // check item starting quest (it can work incorrectly if added without item in inventory)
4681 QueryResult
*result
= WorldDatabase
.PQuery("SELECT entry FROM item_template WHERE startquest = '%u' LIMIT 1",entry
);
4684 Field
* fields
= result
->Fetch();
4685 uint32 item_id
= fields
[0].GetUInt32();
4688 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM
, entry
,item_id
);
4689 SetSentErrorMessage(true);
4693 // ok, normal (creature/GO starting) quest
4694 if( player
->CanAddQuest( pQuest
, true ) )
4696 player
->AddQuest( pQuest
, NULL
);
4698 if ( player
->CanCompleteQuest( entry
) )
4699 player
->CompleteQuest( entry
);
4705 bool ChatHandler::HandleRemoveQuest(const char* args
)
4707 Player
* player
= getSelectedPlayer();
4710 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4711 SetSentErrorMessage(true);
4715 // .removequest #entry'
4716 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4717 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4721 uint32 entry
= atol(cId
);
4723 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
4727 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
4728 SetSentErrorMessage(true);
4732 // remove all quest entries for 'entry' from quest log
4733 for(uint8 slot
= 0; slot
< MAX_QUEST_LOG_SIZE
; ++slot
)
4735 uint32 quest
= player
->GetQuestSlotQuestId(slot
);
4738 player
->SetQuestSlot(slot
,0);
4740 // we ignore unequippable quest items in this case, its' still be equipped
4741 player
->TakeQuestSourceItem( quest
, false );
4745 // set quest status to not started (will updated in DB at next save)
4746 player
->SetQuestStatus( entry
, QUEST_STATUS_NONE
);
4748 // reset rewarded for restart repeatable quest
4749 player
->getQuestStatusMap()[entry
].m_rewarded
= false;
4751 SendSysMessage(LANG_COMMAND_QUEST_REMOVED
);
4755 bool ChatHandler::HandleCompleteQuest(const char* args
)
4757 Player
* player
= getSelectedPlayer();
4760 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4761 SetSentErrorMessage(true);
4765 // .quest complete #entry
4766 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4767 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4771 uint32 entry
= atol(cId
);
4773 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
4775 // If player doesn't have the quest
4776 if(!pQuest
|| player
->GetQuestStatus(entry
) == QUEST_STATUS_NONE
)
4778 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
4779 SetSentErrorMessage(true);
4783 // Add quest items for quests that require items
4784 for(uint8 x
= 0; x
< QUEST_OBJECTIVES_COUNT
; ++x
)
4786 uint32 id
= pQuest
->ReqItemId
[x
];
4787 uint32 count
= pQuest
->ReqItemCount
[x
];
4791 uint32 curItemCount
= player
->GetItemCount(id
,true);
4793 ItemPosCountVec dest
;
4794 uint8 msg
= player
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, id
, count
-curItemCount
);
4795 if( msg
== EQUIP_ERR_OK
)
4797 Item
* item
= player
->StoreNewItem( dest
, id
, true);
4798 player
->SendNewItem(item
,count
-curItemCount
,true,false);
4802 // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
4803 for(uint8 i
= 0; i
< QUEST_OBJECTIVES_COUNT
; i
++)
4805 uint32 creature
= pQuest
->ReqCreatureOrGOId
[i
];
4806 uint32 creaturecount
= pQuest
->ReqCreatureOrGOCount
[i
];
4808 if(uint32 spell_id
= pQuest
->ReqSpell
[i
])
4810 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4811 player
->CastedCreatureOrGO(creature
,0,spell_id
);
4813 else if(creature
> 0)
4815 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4816 player
->KilledMonster(creature
,0);
4818 else if(creature
< 0)
4820 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4821 player
->CastedCreatureOrGO(creature
,0,0);
4825 // If the quest requires reputation to complete
4826 if(uint32 repFaction
= pQuest
->GetRepObjectiveFaction())
4828 uint32 repValue
= pQuest
->GetRepObjectiveValue();
4829 uint32 curRep
= player
->GetReputation(repFaction
);
4830 if(curRep
< repValue
)
4832 FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry(repFaction
);
4833 player
->SetFactionReputation(factionEntry
,repValue
);
4837 // If the quest requires money
4838 int32 ReqOrRewMoney
= pQuest
->GetRewOrReqMoney();
4839 if(ReqOrRewMoney
< 0)
4840 player
->ModifyMoney(-ReqOrRewMoney
);
4842 player
->CompleteQuest(entry
);
4846 bool ChatHandler::HandleBanAccountCommand(const char* args
)
4848 return HandleBanHelper(BAN_ACCOUNT
,args
);
4851 bool ChatHandler::HandleBanCharacterCommand(const char* args
)
4853 return HandleBanHelper(BAN_CHARACTER
,args
);
4856 bool ChatHandler::HandleBanIPCommand(const char* args
)
4858 return HandleBanHelper(BAN_IP
,args
);
4861 bool ChatHandler::HandleBanHelper(BanMode mode
, const char* args
)
4866 char* cnameOrIP
= strtok ((char*)args
, " ");
4870 std::string nameOrIP
= cnameOrIP
;
4872 char* duration
= strtok (NULL
," ");
4873 if(!duration
|| !atoi(duration
))
4876 char* reason
= strtok (NULL
,"");
4883 if(!AccountMgr::normilizeString(nameOrIP
))
4885 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
4886 SetSentErrorMessage(true);
4891 if(!normalizePlayerName(nameOrIP
))
4893 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4894 SetSentErrorMessage(true);
4899 if(!IsIPAddress(nameOrIP
.c_str()))
4904 switch(sWorld
.BanAccount(mode
, nameOrIP
, duration
, reason
,m_session
? m_session
->GetPlayerName() : ""))
4907 if(atoi(duration
)>0)
4908 PSendSysMessage(LANG_BAN_YOUBANNED
,nameOrIP
.c_str(),secsToTimeString(TimeStringToSecs(duration
),true).c_str(),reason
);
4910 PSendSysMessage(LANG_BAN_YOUPERMBANNED
,nameOrIP
.c_str(),reason
);
4912 case BAN_SYNTAX_ERROR
:
4918 PSendSysMessage(LANG_BAN_NOTFOUND
,"account",nameOrIP
.c_str());
4921 PSendSysMessage(LANG_BAN_NOTFOUND
,"character",nameOrIP
.c_str());
4924 PSendSysMessage(LANG_BAN_NOTFOUND
,"ip",nameOrIP
.c_str());
4927 SetSentErrorMessage(true);
4934 bool ChatHandler::HandleUnBanAccountCommand(const char* args
)
4936 return HandleUnBanHelper(BAN_ACCOUNT
,args
);
4939 bool ChatHandler::HandleUnBanCharacterCommand(const char* args
)
4941 return HandleUnBanHelper(BAN_CHARACTER
,args
);
4944 bool ChatHandler::HandleUnBanIPCommand(const char* args
)
4946 return HandleUnBanHelper(BAN_IP
,args
);
4949 bool ChatHandler::HandleUnBanHelper(BanMode mode
, const char* args
)
4954 char* cnameOrIP
= strtok ((char*)args
, " ");
4958 std::string nameOrIP
= cnameOrIP
;
4963 if(!AccountMgr::normilizeString(nameOrIP
))
4965 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
4966 SetSentErrorMessage(true);
4971 if(!normalizePlayerName(nameOrIP
))
4973 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4974 SetSentErrorMessage(true);
4979 if(!IsIPAddress(nameOrIP
.c_str()))
4984 if(sWorld
.RemoveBanAccount(mode
,nameOrIP
))
4985 PSendSysMessage(LANG_UNBAN_UNBANNED
,nameOrIP
.c_str());
4987 PSendSysMessage(LANG_UNBAN_ERROR
,nameOrIP
.c_str());
4992 bool ChatHandler::HandleBanInfoAccountCommand(const char* args
)
4997 char* cname
= strtok((char*)args
, "");
5001 std::string account_name
= cname
;
5002 if(!AccountMgr::normilizeString(account_name
))
5004 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5005 SetSentErrorMessage(true);
5009 uint32 accountid
= accmgr
.GetId(account_name
);
5012 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5016 return HandleBanInfoHelper(accountid
,account_name
.c_str());
5019 bool ChatHandler::HandleBanInfoCharacterCommand(const char* args
)
5024 char* cname
= strtok ((char*)args
, "");
5028 std::string name
= cname
;
5029 if(!normalizePlayerName(name
))
5031 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5032 SetSentErrorMessage(true);
5036 uint32 accountid
= objmgr
.GetPlayerAccountIdByPlayerName(name
);
5039 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5040 SetSentErrorMessage(true);
5044 std::string accountname
;
5045 if(!accmgr
.GetName(accountid
,accountname
))
5047 PSendSysMessage(LANG_BANINFO_NOCHARACTER
);
5051 return HandleBanInfoHelper(accountid
,accountname
.c_str());
5054 bool ChatHandler::HandleBanInfoHelper(uint32 accountid
, char const* accountname
)
5056 QueryResult
*result
= loginDatabase
.PQuery("SELECT FROM_UNIXTIME(bandate), unbandate-bandate, active, unbandate,banreason,bannedby FROM account_banned WHERE id = '%u' ORDER BY bandate ASC",accountid
);
5059 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN
, accountname
);
5063 PSendSysMessage(LANG_BANINFO_BANHISTORY
,accountname
);
5066 Field
* fields
= result
->Fetch();
5068 time_t unbandate
= time_t(fields
[3].GetUInt64());
5069 bool active
= false;
5070 if(fields
[2].GetBool() && (fields
[1].GetUInt64() == (uint64
)0 ||unbandate
>= time(NULL
)) )
5072 bool permanent
= (fields
[1].GetUInt64() == (uint64
)0);
5073 std::string bantime
= permanent
?GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[1].GetUInt64(), true);
5074 PSendSysMessage(LANG_BANINFO_HISTORYENTRY
,
5075 fields
[0].GetString(), bantime
.c_str(), active
? GetMangosString(LANG_BANINFO_YES
):GetMangosString(LANG_BANINFO_NO
), fields
[4].GetString(), fields
[5].GetString());
5076 }while (result
->NextRow());
5082 bool ChatHandler::HandleBanInfoIPCommand(const char* args
)
5087 char* cIP
= strtok ((char*)args
, "");
5091 if (!IsIPAddress(cIP
))
5094 std::string IP
= cIP
;
5096 loginDatabase
.escape_string(IP
);
5097 QueryResult
*result
= loginDatabase
.PQuery("SELECT ip, FROM_UNIXTIME(bandate), FROM_UNIXTIME(unbandate), unbandate-UNIX_TIMESTAMP(), banreason,bannedby,unbandate-bandate FROM ip_banned WHERE ip = '%s'",IP
.c_str());
5100 PSendSysMessage(LANG_BANINFO_NOIP
);
5104 Field
*fields
= result
->Fetch();
5105 bool permanent
= !fields
[6].GetUInt64();
5106 PSendSysMessage(LANG_BANINFO_IPENTRY
,
5107 fields
[0].GetString(), fields
[1].GetString(), permanent
? GetMangosString(LANG_BANINFO_NEVER
):fields
[2].GetString(),
5108 permanent
? GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[3].GetUInt64(), true).c_str(), fields
[4].GetString(), fields
[5].GetString());
5113 bool ChatHandler::HandleBanListCharacterCommand(const char* args
)
5115 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5117 char* cFilter
= strtok ((char*)args
, " ");
5121 std::string filter
= cFilter
;
5122 loginDatabase
.escape_string(filter
);
5123 QueryResult
* result
= CharacterDatabase
.PQuery("SELECT account FROM characters WHERE name "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'"),filter
.c_str());
5126 PSendSysMessage(LANG_BANLIST_NOCHARACTER
);
5130 return HandleBanListHelper(result
);
5133 bool ChatHandler::HandleBanListAccountCommand(const char* args
)
5135 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5137 char* cFilter
= strtok((char*)args
, " ");
5138 std::string filter
= cFilter
? cFilter
: "";
5139 loginDatabase
.escape_string(filter
);
5141 QueryResult
* result
;
5145 result
= loginDatabase
.Query("SELECT account.id, username FROM account, account_banned"
5146 " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
5150 result
= loginDatabase
.PQuery("SELECT account.id, username FROM account, account_banned"
5151 " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
5157 PSendSysMessage(LANG_BANLIST_NOACCOUNT
);
5161 return HandleBanListHelper(result
);
5164 bool ChatHandler::HandleBanListHelper(QueryResult
* result
)
5166 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT
);
5168 // Chat short output
5173 Field
* fields
= result
->Fetch();
5174 uint32 accountid
= fields
[0].GetUInt32();
5176 QueryResult
* banresult
= loginDatabase
.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid
);
5179 Field
* fields2
= banresult
->Fetch();
5180 PSendSysMessage("%s",fields2
[0].GetString());
5183 } while (result
->NextRow());
5185 // Console wide output
5188 SendSysMessage(LANG_BANLIST_ACCOUNTS
);
5189 SendSysMessage("===============================================================================");
5190 SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER
);
5193 SendSysMessage("-------------------------------------------------------------------------------");
5194 Field
*fields
= result
->Fetch();
5195 uint32 account_id
= fields
[0].GetUInt32 ();
5197 std::string account_name
;
5199 // "account" case, name can be get in same quary
5200 if(result
->GetFieldCount() > 1)
5201 account_name
= fields
[1].GetCppString();
5202 // "character" case, name need extract from another DB
5204 accmgr
.GetName (account_id
,account_name
);
5206 // No SQL injection. id is uint32.
5207 QueryResult
*banInfo
= loginDatabase
.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id
);
5210 Field
*fields2
= banInfo
->Fetch();
5213 time_t t_ban
= fields2
[0].GetUInt64();
5214 tm
* aTm_ban
= localtime(&t_ban
);
5216 if (fields2
[0].GetUInt64() == fields2
[1].GetUInt64())
5218 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5219 account_name
.c_str(),aTm_ban
->tm_year
%100, aTm_ban
->tm_mon
+1, aTm_ban
->tm_mday
, aTm_ban
->tm_hour
, aTm_ban
->tm_min
,
5220 fields2
[2].GetString(),fields2
[3].GetString());
5224 time_t t_unban
= fields2
[1].GetUInt64();
5225 tm
* aTm_unban
= localtime(&t_unban
);
5226 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5227 account_name
.c_str(),aTm_ban
->tm_year
%100, aTm_ban
->tm_mon
+1, aTm_ban
->tm_mday
, aTm_ban
->tm_hour
, aTm_ban
->tm_min
,
5228 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5229 fields2
[2].GetString(),fields2
[3].GetString());
5231 }while ( banInfo
->NextRow() );
5234 }while( result
->NextRow() );
5235 SendSysMessage("===============================================================================");
5242 bool ChatHandler::HandleBanListIPCommand(const char* args
)
5244 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5246 char* cFilter
= strtok((char*)args
, " ");
5247 std::string filter
= cFilter
? cFilter
: "";
5248 loginDatabase
.escape_string(filter
);
5250 QueryResult
* result
;
5254 result
= loginDatabase
.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5255 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
5256 " ORDER BY unbandate" );
5260 result
= loginDatabase
.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5261 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")
5262 " ORDER BY unbandate",filter
.c_str() );
5267 PSendSysMessage(LANG_BANLIST_NOIP
);
5271 PSendSysMessage(LANG_BANLIST_MATCHINGIP
);
5272 // Chat short output
5277 Field
* fields
= result
->Fetch();
5278 PSendSysMessage("%s",fields
[0].GetString());
5279 } while (result
->NextRow());
5281 // Console wide output
5284 SendSysMessage(LANG_BANLIST_IPS
);
5285 SendSysMessage("===============================================================================");
5286 SendSysMessage(LANG_BANLIST_IPS_HEADER
);
5289 SendSysMessage("-------------------------------------------------------------------------------");
5290 Field
*fields
= result
->Fetch();
5291 time_t t_ban
= fields
[1].GetUInt64();
5292 tm
* aTm_ban
= localtime(&t_ban
);
5293 if ( fields
[1].GetUInt64() == fields
[2].GetUInt64() )
5295 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5296 fields
[0].GetString(), aTm_ban
->tm_year
%100, aTm_ban
->tm_mon
+1, aTm_ban
->tm_mday
, aTm_ban
->tm_hour
, aTm_ban
->tm_min
,
5297 fields
[3].GetString(), fields
[4].GetString());
5301 time_t t_unban
= fields
[2].GetUInt64();
5302 tm
* aTm_unban
= localtime(&t_unban
);
5303 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5304 fields
[0].GetString(), aTm_ban
->tm_year
%100, aTm_ban
->tm_mon
+1, aTm_ban
->tm_mday
, aTm_ban
->tm_hour
, aTm_ban
->tm_min
,
5305 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5306 fields
[3].GetString(), fields
[4].GetString());
5308 }while( result
->NextRow() );
5309 SendSysMessage("===============================================================================");
5316 bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
5318 Unit
* target
= getSelectedUnit();
5322 if(target
->GetTypeId()!=TYPEID_UNIT
)
5324 SendSysMessage(LANG_SELECT_CREATURE
);
5325 SetSentErrorMessage(true);
5329 if(target
->isDead())
5330 ((Creature
*)target
)->Respawn();
5334 Player
* pl
= m_session
->GetPlayer();
5336 CellPair
p(MaNGOS::ComputeCellPair(pl
->GetPositionX(), pl
->GetPositionY()));
5338 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
5341 MaNGOS::RespawnDo u_do
;
5342 MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
> worker(u_do
);
5344 TypeContainerVisitor
<MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
>, GridTypeMapContainer
> obj_worker(worker
);
5345 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
5346 cell_lock
->Visit(cell_lock
, obj_worker
, *MapManager::Instance().GetMap(pl
->GetMapId(), pl
));
5351 bool ChatHandler::HandleFlyModeCommand(const char* args
)
5356 Unit
*unit
= getSelectedUnit();
5357 if (!unit
|| (unit
->GetTypeId() != TYPEID_PLAYER
))
5358 unit
= m_session
->GetPlayer();
5360 WorldPacket
data(12);
5361 if (strncmp(args
, "on", 3) == 0)
5362 data
.SetOpcode(SMSG_MOVE_SET_CAN_FLY
);
5363 else if (strncmp(args
, "off", 4) == 0)
5364 data
.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY
);
5367 SendSysMessage(LANG_USE_BOL
);
5370 data
.append(unit
->GetPackGUID());
5371 data
<< uint32(0); // unknown
5372 unit
->SendMessageToSet(&data
, true);
5373 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS
, unit
->GetName(), args
);
5377 bool ChatHandler::HandleLoadPDumpCommand(const char *args
)
5382 char * file
= strtok((char*)args
, " ");
5386 char * account
= strtok(NULL
, " ");
5390 std::string account_name
= account
;
5391 if(!AccountMgr::normilizeString(account_name
))
5393 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5394 SetSentErrorMessage(true);
5398 uint32 account_id
= accmgr
.GetId(account_name
);
5401 account_id
= atoi(account
); // use original string
5404 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5405 SetSentErrorMessage(true);
5410 if(!accmgr
.GetName(account_id
,account_name
))
5412 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5413 SetSentErrorMessage(true);
5417 char* guid_str
= NULL
;
5418 char* name_str
= strtok(NULL
, " ");
5424 // normalize the name if specified and check if it exists
5425 if(!normalizePlayerName(name
))
5427 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5428 SetSentErrorMessage(true);
5432 if(!ObjectMgr::IsValidName(name
,true))
5434 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5435 SetSentErrorMessage(true);
5439 guid_str
= strtok(NULL
, " ");
5446 guid
= atoi(guid_str
);
5449 PSendSysMessage(LANG_INVALID_CHARACTER_GUID
);
5450 SetSentErrorMessage(true);
5454 if(objmgr
.GetPlayerAccountIdByGUID(guid
))
5456 PSendSysMessage(LANG_CHARACTER_GUID_IN_USE
,guid
);
5457 SetSentErrorMessage(true);
5462 switch(PlayerDumpReader().LoadDump(file
, account_id
, name
, guid
))
5465 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS
);
5467 case DUMP_FILE_OPEN_ERROR
:
5468 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
5469 SetSentErrorMessage(true);
5471 case DUMP_FILE_BROKEN
:
5472 PSendSysMessage(LANG_DUMP_BROKEN
,file
);
5473 SetSentErrorMessage(true);
5475 case DUMP_TOO_MANY_CHARS
:
5476 PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL
,account_name
.c_str(),account_id
);
5477 SetSentErrorMessage(true);
5480 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED
);
5481 SetSentErrorMessage(true);
5488 bool ChatHandler::HandleNpcChangeEntryCommand(const char *args
)
5493 uint32 newEntryNum
= atoi(args
);
5497 Unit
* unit
= getSelectedUnit();
5498 if(!unit
|| unit
->GetTypeId() != TYPEID_UNIT
)
5500 SendSysMessage(LANG_SELECT_CREATURE
);
5501 SetSentErrorMessage(true);
5504 Creature
* creature
= (Creature
*)unit
;
5505 if(creature
->UpdateEntry(newEntryNum
))
5506 SendSysMessage(LANG_DONE
);
5508 SendSysMessage(LANG_ERROR
);
5512 bool ChatHandler::HandleWritePDumpCommand(const char *args
)
5517 char* file
= strtok((char*)args
, " ");
5518 char* p2
= strtok(NULL
, " ");
5523 uint32 guid
= objmgr
.GetPlayerGUIDByName(p2
);
5527 if(!objmgr
.GetPlayerAccountIdByGUID(guid
))
5529 PSendSysMessage(LANG_PLAYER_NOT_FOUND
);
5530 SetSentErrorMessage(true);
5534 switch(PlayerDumpWriter().WriteDump(file
, guid
))
5537 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS
);
5539 case DUMP_FILE_OPEN_ERROR
:
5540 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
5541 SetSentErrorMessage(true);
5544 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED
);
5545 SetSentErrorMessage(true);
5552 bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
5554 Unit
* unit
= getSelectedUnit();
5557 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5558 SetSentErrorMessage(true);
5562 PSendSysMessage(LANG_MOVEGENS_LIST
,(unit
->GetTypeId()==TYPEID_PLAYER
? "Player" : "Creature" ),unit
->GetGUIDLow());
5564 MotionMaster
* mm
= unit
->GetMotionMaster();
5565 for(MotionMaster::const_iterator itr
= mm
->begin(); itr
!= mm
->end(); ++itr
)
5567 switch((*itr
)->GetMovementGeneratorType())
5569 case IDLE_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_IDLE
); break;
5570 case RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_RANDOM
); break;
5571 case WAYPOINT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_WAYPOINT
); break;
5572 case ANIMAL_RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_ANIMAL_RANDOM
); break;
5573 case CONFUSED_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_CONFUSED
); break;
5574 case TARGETED_MOTION_TYPE
:
5576 if(unit
->GetTypeId()==TYPEID_PLAYER
)
5578 TargetedMovementGenerator
<Player
> const* mgen
= static_cast<TargetedMovementGenerator
<Player
> const*>(*itr
);
5579 Unit
* target
= mgen
->GetTarget();
5581 PSendSysMessage(LANG_MOVEGENS_TARGETED_PLAYER
,target
->GetName(),target
->GetGUIDLow());
5583 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL
);
5587 TargetedMovementGenerator
<Creature
> const* mgen
= static_cast<TargetedMovementGenerator
<Creature
> const*>(*itr
);
5588 Unit
* target
= mgen
->GetTarget();
5590 PSendSysMessage(LANG_MOVEGENS_TARGETED_CREATURE
,target
->GetName(),target
->GetGUIDLow());
5592 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL
);
5596 case HOME_MOTION_TYPE
:
5597 if(unit
->GetTypeId()==TYPEID_UNIT
)
5600 (*itr
)->GetDestination(x
,y
,z
);
5601 PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE
,x
,y
,z
);
5604 SendSysMessage(LANG_MOVEGENS_HOME_PLAYER
);
5606 case FLIGHT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FLIGHT
); break;
5607 case POINT_MOTION_TYPE
:
5610 (*itr
)->GetDestination(x
,y
,z
);
5611 PSendSysMessage(LANG_MOVEGENS_POINT
,x
,y
,z
);
5614 case FLEEING_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FEAR
); break;
5615 case DISTRACT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_DISTRACT
); break;
5617 PSendSysMessage(LANG_MOVEGENS_UNKNOWN
,(*itr
)->GetMovementGeneratorType());
5624 bool ChatHandler::HandlePLimitCommand(const char *args
)
5628 char* param
= strtok((char*)args
, " ");
5632 int l
= strlen(param
);
5634 if( strncmp(param
,"player",l
) == 0 )
5635 sWorld
.SetPlayerLimit(-SEC_PLAYER
);
5636 else if(strncmp(param
,"moderator",l
) == 0 )
5637 sWorld
.SetPlayerLimit(-SEC_MODERATOR
);
5638 else if(strncmp(param
,"gamemaster",l
) == 0 )
5639 sWorld
.SetPlayerLimit(-SEC_GAMEMASTER
);
5640 else if(strncmp(param
,"administrator",l
) == 0 )
5641 sWorld
.SetPlayerLimit(-SEC_ADMINISTRATOR
);
5642 else if(strncmp(param
,"reset",l
) == 0 )
5643 sWorld
.SetPlayerLimit( sConfig
.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT
) );
5646 int val
= atoi(param
);
5647 if(val
< -SEC_ADMINISTRATOR
) val
= -SEC_ADMINISTRATOR
;
5649 sWorld
.SetPlayerLimit(val
);
5652 // kick all low security level players
5653 if(sWorld
.GetPlayerAmountLimit() > SEC_PLAYER
)
5654 sWorld
.KickAllLess(sWorld
.GetPlayerSecurityLimit());
5657 uint32 pLimit
= sWorld
.GetPlayerAmountLimit();
5658 AccountTypes allowedAccountType
= sWorld
.GetPlayerSecurityLimit();
5659 char const* secName
= "";
5660 switch(allowedAccountType
)
5662 case SEC_PLAYER
: secName
= "Player"; break;
5663 case SEC_MODERATOR
: secName
= "Moderator"; break;
5664 case SEC_GAMEMASTER
: secName
= "Gamemaster"; break;
5665 case SEC_ADMINISTRATOR
: secName
= "Administrator"; break;
5666 default: secName
= "<unknown>"; break;
5669 PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit
,secName
);
5674 bool ChatHandler::HandleCastCommand(const char* args
)
5679 Unit
* target
= getSelectedUnit();
5683 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5684 SetSentErrorMessage(true);
5688 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5689 uint32 spell
= extractSpellIdFromLink((char*)args
);
5693 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5697 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5699 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5700 SetSentErrorMessage(true);
5704 char* trig_str
= strtok(NULL
, " ");
5707 int l
= strlen(trig_str
);
5708 if(strncmp(trig_str
,"triggered",l
) != 0 )
5712 bool triggered
= (trig_str
!= NULL
);
5714 m_session
->GetPlayer()->CastSpell(target
,spell
,triggered
);
5719 bool ChatHandler::HandleCastBackCommand(const char* args
)
5721 Creature
* caster
= getSelectedCreature();
5725 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5726 SetSentErrorMessage(true);
5730 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
5731 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5732 uint32 spell
= extractSpellIdFromLink((char*)args
);
5733 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
5736 char* trig_str
= strtok(NULL
, " ");
5739 int l
= strlen(trig_str
);
5740 if(strncmp(trig_str
,"triggered",l
) != 0 )
5744 bool triggered
= (trig_str
!= NULL
);
5746 // update orientation at server
5747 caster
->SetOrientation(caster
->GetAngle(m_session
->GetPlayer()));
5751 caster
->BuildHeartBeatMsg(&data
);
5752 caster
->SendMessageToSet(&data
,true);
5754 caster
->CastSpell(m_session
->GetPlayer(),spell
,false);
5759 bool ChatHandler::HandleCastDistCommand(const char* args
)
5764 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5765 uint32 spell
= extractSpellIdFromLink((char*)args
);
5769 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5773 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5775 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5776 SetSentErrorMessage(true);
5780 char *distStr
= strtok(NULL
, " ");
5785 sscanf(distStr
, "%f", &dist
);
5787 char* trig_str
= strtok(NULL
, " ");
5790 int l
= strlen(trig_str
);
5791 if(strncmp(trig_str
,"triggered",l
) != 0 )
5795 bool triggered
= (trig_str
!= NULL
);
5798 m_session
->GetPlayer()->GetClosePoint(x
,y
,z
,dist
);
5800 m_session
->GetPlayer()->CastSpell(x
,y
,z
,spell
,triggered
);
5804 bool ChatHandler::HandleCastTargetCommand(const char* args
)
5806 Creature
* caster
= getSelectedCreature();
5810 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5811 SetSentErrorMessage(true);
5815 if(!caster
->getVictim())
5817 SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM
);
5818 SetSentErrorMessage(true);
5822 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5823 uint32 spell
= extractSpellIdFromLink((char*)args
);
5824 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
5827 char* trig_str
= strtok(NULL
, " ");
5830 int l
= strlen(trig_str
);
5831 if(strncmp(trig_str
,"triggered",l
) != 0 )
5835 bool triggered
= (trig_str
!= NULL
);
5837 // update orientation at server
5838 caster
->SetOrientation(caster
->GetAngle(m_session
->GetPlayer()));
5842 caster
->BuildHeartBeatMsg(&data
);
5843 caster
->SendMessageToSet(&data
,true);
5845 caster
->CastSpell(caster
->getVictim(),spell
,false);
5851 ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
5852 Without this function 3rd party scripting library will get linking errors (unresolved external)
5853 when attempting to use the PointMovementGenerator
5855 bool ChatHandler::HandleComeToMeCommand(const char *args
)
5857 Creature
* caster
= getSelectedCreature();
5861 SendSysMessage(LANG_SELECT_CREATURE
);
5862 SetSentErrorMessage(true);
5866 char* newFlagStr
= strtok((char*)args
, " ");
5871 uint32 newFlags
= atoi(newFlagStr
);
5873 caster
->SetUnitMovementFlags(newFlags
);
5875 Player
* pl
= m_session
->GetPlayer();
5877 caster
->GetMotionMaster()->MovePoint(0, pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ());
5881 bool ChatHandler::HandleCastSelfCommand(const char* args
)
5886 Unit
* target
= getSelectedUnit();
5890 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5891 SetSentErrorMessage(true);
5895 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5896 uint32 spell
= extractSpellIdFromLink((char*)args
);
5900 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5904 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5906 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5907 SetSentErrorMessage(true);
5911 target
->CastSpell(target
,spell
,false);
5916 std::string
GetTimeString(uint32 time
)
5918 uint16 days
= time
/ DAY
, hours
= (time
% DAY
) / HOUR
, minute
= (time
% HOUR
) / MINUTE
;
5919 std::ostringstream ss
;
5920 if(days
) ss
<< days
<< "d ";
5921 if(hours
) ss
<< hours
<< "h ";
5922 ss
<< minute
<< "m";
5926 bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
5928 Player
* player
= getSelectedPlayer();
5929 if (!player
) player
= m_session
->GetPlayer();
5931 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
5933 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(i
);
5934 for(Player::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
5936 InstanceSave
*save
= itr
->second
.save
;
5937 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
5938 PSendSysMessage("map: %d inst: %d perm: %s diff: %s canReset: %s TTR: %s", itr
->first
, save
->GetInstanceId(), itr
->second
.perm
? "yes" : "no", save
->GetDifficulty() == DIFFICULTY_NORMAL
? "normal" : "heroic", save
->CanReset() ? "yes" : "no", timeleft
.c_str());
5942 PSendSysMessage("player binds: %d", counter
);
5944 Group
*group
= player
->GetGroup();
5947 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
5949 Group::BoundInstancesMap
&binds
= group
->GetBoundInstances(i
);
5950 for(Group::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
5952 InstanceSave
*save
= itr
->second
.save
;
5953 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
5954 PSendSysMessage("map: %d inst: %d perm: %s diff: %s canReset: %s TTR: %s", itr
->first
, save
->GetInstanceId(), itr
->second
.perm
? "yes" : "no", save
->GetDifficulty() == DIFFICULTY_NORMAL
? "normal" : "heroic", save
->CanReset() ? "yes" : "no", timeleft
.c_str());
5959 PSendSysMessage("group binds: %d", counter
);
5964 bool ChatHandler::HandleInstanceUnbindCommand(const char* args
)
5969 std::string cmd
= args
;
5972 Player
* player
= getSelectedPlayer();
5973 if (!player
) player
= m_session
->GetPlayer();
5975 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
5977 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(i
);
5978 for(Player::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end();)
5980 if(itr
->first
!= player
->GetMapId())
5982 InstanceSave
*save
= itr
->second
.save
;
5983 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
5984 PSendSysMessage("unbinding map: %d inst: %d perm: %s diff: %s canReset: %s TTR: %s", itr
->first
, save
->GetInstanceId(), itr
->second
.perm
? "yes" : "no", save
->GetDifficulty() == DIFFICULTY_NORMAL
? "normal" : "heroic", save
->CanReset() ? "yes" : "no", timeleft
.c_str());
5985 player
->UnbindInstance(itr
, i
);
5992 PSendSysMessage("instances unbound: %d", counter
);
5997 bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
5999 PSendSysMessage("instances loaded: %d", MapManager::Instance().GetNumInstances());
6000 PSendSysMessage("players in instances: %d", MapManager::Instance().GetNumPlayersInInstances());
6001 PSendSysMessage("instance saves: %d", sInstanceSaveManager
.GetNumInstanceSaves());
6002 PSendSysMessage("players bound: %d", sInstanceSaveManager
.GetNumBoundPlayersTotal());
6003 PSendSysMessage("groups bound: %d", sInstanceSaveManager
.GetNumBoundGroupsTotal());
6007 bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
6009 Player
* pl
= m_session
->GetPlayer();
6011 Map
* map
= pl
->GetMap();
6012 if (!map
->IsDungeon())
6014 PSendSysMessage("Map is not a dungeon.");
6015 SetSentErrorMessage(true);
6019 if (!((InstanceMap
*)map
)->GetInstanceData())
6021 PSendSysMessage("Map has no instance data.");
6022 SetSentErrorMessage(true);
6026 ((InstanceMap
*)map
)->GetInstanceData()->SaveToDB();
6030 /// Display the list of GMs
6031 bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
6033 ///- Get the accounts with GM Level >0
6034 QueryResult
*result
= loginDatabase
.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
6037 SendSysMessage(LANG_GMLIST
);
6038 SendSysMessage("========================");
6039 SendSysMessage(LANG_GMLIST_HEADER
);
6040 SendSysMessage("========================");
6042 ///- Circle through them. Display username and GM level
6045 Field
*fields
= result
->Fetch();
6046 PSendSysMessage("|%15s|%6s|", fields
[0].GetString(),fields
[1].GetString());
6047 }while( result
->NextRow() );
6049 PSendSysMessage("========================");
6053 PSendSysMessage(LANG_GMLIST_EMPTY
);
6057 /// Define the 'Message of the day' for the realm
6058 bool ChatHandler::HandleServerSetMotdCommand(const char* args
)
6060 sWorld
.SetMotd(args
);
6061 PSendSysMessage(LANG_MOTD_NEW
, args
);
6065 /// Set/Unset the expansion level for an account
6066 bool ChatHandler::HandleAccountSetAddonCommand(const char* args
)
6068 ///- Get the command line arguments
6069 char *szAcc
= strtok((char*)args
," ");
6070 char *szExp
= strtok(NULL
," ");
6075 std::string account_name
;
6080 Player
* player
= getSelectedPlayer();
6084 account_id
= player
->GetSession()->GetAccountId();
6085 accmgr
.GetName(account_id
,account_name
);
6090 ///- Convert Account name to Upper Format
6091 account_name
= szAcc
;
6092 if(!AccountMgr::normilizeString(account_name
))
6094 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
6095 SetSentErrorMessage(true);
6099 account_id
= accmgr
.GetId(account_name
);
6102 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
6103 SetSentErrorMessage(true);
6108 int lev
=atoi(szExp
); //get int anyway (0 if error)
6113 loginDatabase
.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev
,account_id
);
6114 PSendSysMessage(LANG_ACCOUNT_SETADDON
,account_name
.c_str(),account_id
,lev
);
6118 /// Send a message to a player in game
6119 bool ChatHandler::HandleSendMessageCommand(const char* args
)
6121 ///- Get the command line arguments
6122 char* name_str
= strtok((char*)args
, " ");
6123 char* msg_str
= strtok(NULL
, "");
6125 if(!name_str
|| !msg_str
)
6128 std::string name
= name_str
;
6130 if(!normalizePlayerName(name
))
6133 ///- Find the player and check that he is not logging out.
6134 Player
*rPlayer
= objmgr
.GetPlayer(name
.c_str());
6137 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6138 SetSentErrorMessage(true);
6142 if(rPlayer
->GetSession()->isLogingOut())
6144 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6145 SetSentErrorMessage(true);
6149 ///- Send the message
6150 //Use SendAreaTriggerMessage for fastest delivery.
6151 rPlayer
->GetSession()->SendAreaTriggerMessage("%s", msg_str
);
6152 rPlayer
->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
6154 //Confirmation message
6155 PSendSysMessage(LANG_SENDMESSAGE
,name
.c_str(),msg_str
);