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::HandlePlayEmoteCommand(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_PVP
);
4343 player
->SetByteValue(UNIT_FIELD_BYTES_2
, 3, player
->m_form
);
4345 player
->SetUInt32Value(UNIT_FIELD_FLAGS
, UNIT_FLAG_PVP_ATTACKABLE
);
4347 //-1 is default value
4348 player
->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX
, uint32(-1));
4350 //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000 );
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
->InitGlyphsForLevel();
4388 player
->InitTalentForLevel();
4389 player
->SetUInt32Value(PLAYER_XP
,0);
4391 // reset level to summoned pet
4392 Pet
* pet
= player
->GetPet();
4393 if(pet
&& pet
->getPetType()==SUMMON_PET
)
4394 pet
->InitStatsForLevel(1);
4399 bool ChatHandler::HandleResetStatsCommand(const char * args
)
4401 char* pName
= strtok((char*)args
, "");
4402 Player
*player
= NULL
;
4405 std::string name
= pName
;
4406 if(!normalizePlayerName(name
))
4408 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4409 SetSentErrorMessage(true);
4413 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4414 player
= objmgr
.GetPlayer(guid
);
4417 player
= getSelectedPlayer();
4421 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4422 SetSentErrorMessage(true);
4426 if(!HandleResetStatsOrLevelHelper(player
))
4429 player
->InitStatsForLevel(true);
4430 player
->InitTaxiNodesForLevel();
4431 player
->InitGlyphsForLevel();
4432 player
->InitTalentForLevel();
4437 bool ChatHandler::HandleResetSpellsCommand(const char * args
)
4439 char* pName
= strtok((char*)args
, "");
4440 Player
*player
= NULL
;
4441 uint64 playerGUID
= 0;
4444 std::string name
= pName
;
4446 if(!normalizePlayerName(name
))
4448 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4449 SetSentErrorMessage(true);
4453 player
= objmgr
.GetPlayer(name
.c_str());
4455 playerGUID
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4458 player
= getSelectedPlayer();
4460 if(!player
&& !playerGUID
)
4462 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4463 SetSentErrorMessage(true);
4469 player
->resetSpells();
4471 ChatHandler(player
).SendSysMessage(LANG_RESET_SPELLS
);
4473 if(m_session
->GetPlayer()!=player
)
4474 PSendSysMessage(LANG_RESET_SPELLS_ONLINE
,player
->GetName());
4478 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS
), GUID_LOPART(playerGUID
));
4479 PSendSysMessage(LANG_RESET_SPELLS_OFFLINE
,pName
);
4485 bool ChatHandler::HandleResetTalentsCommand(const char * args
)
4487 char* pName
= strtok((char*)args
, "");
4488 Player
*player
= NULL
;
4489 uint64 playerGUID
= 0;
4492 std::string name
= pName
;
4493 if(!normalizePlayerName(name
))
4495 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4496 SetSentErrorMessage(true);
4500 player
= objmgr
.GetPlayer(name
.c_str());
4502 playerGUID
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4505 player
= getSelectedPlayer();
4507 if(!player
&& !playerGUID
)
4509 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4510 SetSentErrorMessage(true);
4516 player
->resetTalents(true);
4518 ChatHandler(player
).SendSysMessage(LANG_RESET_TALENTS
);
4520 if(m_session
->GetPlayer()!=player
)
4521 PSendSysMessage(LANG_RESET_TALENTS_ONLINE
,player
->GetName());
4525 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_TALENTS
), GUID_LOPART(playerGUID
) );
4526 PSendSysMessage(LANG_RESET_TALENTS_OFFLINE
,pName
);
4532 bool ChatHandler::HandleResetAllCommand(const char * args
)
4537 std::string casename
= args
;
4539 AtLoginFlags atLogin
;
4541 // Command specially created as single command to prevent using short case names
4542 if(casename
=="spells")
4544 atLogin
= AT_LOGIN_RESET_SPELLS
;
4545 sWorld
.SendWorldText(LANG_RESETALL_SPELLS
);
4547 else if(casename
=="talents")
4549 atLogin
= AT_LOGIN_RESET_TALENTS
;
4550 sWorld
.SendWorldText(LANG_RESETALL_TALENTS
);
4554 PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE
,args
);
4555 SetSentErrorMessage(true);
4559 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u'",atLogin
);
4560 HashMapHolder
<Player
>::MapType
const& plist
= ObjectAccessor::Instance().GetPlayers();
4561 for(HashMapHolder
<Player
>::MapType::const_iterator itr
= plist
.begin(); itr
!= plist
.end(); ++itr
)
4562 itr
->second
->SetAtLoginFlag(atLogin
);
4567 bool ChatHandler::HandleShutDownCommand(const char* args
)
4572 if(std::string(args
)=="cancel")
4574 sWorld
.ShutdownCancel();
4578 int32 time
= atoi(args
);
4580 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4581 if(time
== 0 && (args
[0]!='0' || args
[1]!='\0') || time
< 0)
4584 sWorld
.ShutdownServ(time
);
4589 bool ChatHandler::HandleRestartCommand(const char* args
)
4594 if(std::string(args
)=="cancel")
4596 sWorld
.ShutdownCancel();
4600 int32 time
= atoi(args
);
4602 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4603 if(time
== 0 && (args
[0]!='0' || args
[1]!='\0') || time
< 0)
4606 sWorld
.ShutdownServ(time
, SHUTDOWN_MASK_RESTART
);
4611 bool ChatHandler::HandleIdleRestartCommand(const char* args
)
4616 if(std::string(args
)=="cancel")
4618 sWorld
.ShutdownCancel();
4622 int32 time
= atoi(args
);
4624 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4625 if(time
== 0 && (args
[0]!='0' || args
[1]!='\0') || time
< 0)
4628 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_RESTART
+SHUTDOWN_MASK_IDLE
);
4633 bool ChatHandler::HandleIdleShutDownCommand(const char* args
)
4638 if(std::string(args
)=="cancel")
4640 sWorld
.ShutdownCancel();
4644 int32 time
= atoi(args
);
4646 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4647 if(time
== 0 && (args
[0]!='0' || args
[1]!='\0') || time
< 0)
4650 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_IDLE
);
4655 bool ChatHandler::HandleAddQuest(const char* args
)
4657 Player
* player
= getSelectedPlayer();
4660 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4661 SetSentErrorMessage(true);
4665 // .addquest #entry'
4666 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4667 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4671 uint32 entry
= atol(cId
);
4673 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
4677 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
,entry
);
4678 SetSentErrorMessage(true);
4682 // check item starting quest (it can work incorrectly if added without item in inventory)
4683 QueryResult
*result
= WorldDatabase
.PQuery("SELECT entry FROM item_template WHERE startquest = '%u' LIMIT 1",entry
);
4686 Field
* fields
= result
->Fetch();
4687 uint32 item_id
= fields
[0].GetUInt32();
4690 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM
, entry
,item_id
);
4691 SetSentErrorMessage(true);
4695 // ok, normal (creature/GO starting) quest
4696 if( player
->CanAddQuest( pQuest
, true ) )
4698 player
->AddQuest( pQuest
, NULL
);
4700 if ( player
->CanCompleteQuest( entry
) )
4701 player
->CompleteQuest( entry
);
4707 bool ChatHandler::HandleRemoveQuest(const char* args
)
4709 Player
* player
= getSelectedPlayer();
4712 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4713 SetSentErrorMessage(true);
4717 // .removequest #entry'
4718 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4719 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4723 uint32 entry
= atol(cId
);
4725 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
4729 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
4730 SetSentErrorMessage(true);
4734 // remove all quest entries for 'entry' from quest log
4735 for(uint8 slot
= 0; slot
< MAX_QUEST_LOG_SIZE
; ++slot
)
4737 uint32 quest
= player
->GetQuestSlotQuestId(slot
);
4740 player
->SetQuestSlot(slot
,0);
4742 // we ignore unequippable quest items in this case, its' still be equipped
4743 player
->TakeQuestSourceItem( quest
, false );
4747 // set quest status to not started (will updated in DB at next save)
4748 player
->SetQuestStatus( entry
, QUEST_STATUS_NONE
);
4750 // reset rewarded for restart repeatable quest
4751 player
->getQuestStatusMap()[entry
].m_rewarded
= false;
4753 SendSysMessage(LANG_COMMAND_QUEST_REMOVED
);
4757 bool ChatHandler::HandleCompleteQuest(const char* args
)
4759 Player
* player
= getSelectedPlayer();
4762 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4763 SetSentErrorMessage(true);
4767 // .quest complete #entry
4768 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4769 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4773 uint32 entry
= atol(cId
);
4775 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
4777 // If player doesn't have the quest
4778 if(!pQuest
|| player
->GetQuestStatus(entry
) == QUEST_STATUS_NONE
)
4780 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
4781 SetSentErrorMessage(true);
4785 // Add quest items for quests that require items
4786 for(uint8 x
= 0; x
< QUEST_OBJECTIVES_COUNT
; ++x
)
4788 uint32 id
= pQuest
->ReqItemId
[x
];
4789 uint32 count
= pQuest
->ReqItemCount
[x
];
4793 uint32 curItemCount
= player
->GetItemCount(id
,true);
4795 ItemPosCountVec dest
;
4796 uint8 msg
= player
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, id
, count
-curItemCount
);
4797 if( msg
== EQUIP_ERR_OK
)
4799 Item
* item
= player
->StoreNewItem( dest
, id
, true);
4800 player
->SendNewItem(item
,count
-curItemCount
,true,false);
4804 // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
4805 for(uint8 i
= 0; i
< QUEST_OBJECTIVES_COUNT
; i
++)
4807 uint32 creature
= pQuest
->ReqCreatureOrGOId
[i
];
4808 uint32 creaturecount
= pQuest
->ReqCreatureOrGOCount
[i
];
4810 if(uint32 spell_id
= pQuest
->ReqSpell
[i
])
4812 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4813 player
->CastedCreatureOrGO(creature
,0,spell_id
);
4815 else if(creature
> 0)
4817 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4818 player
->KilledMonster(creature
,0);
4820 else if(creature
< 0)
4822 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4823 player
->CastedCreatureOrGO(creature
,0,0);
4827 // If the quest requires reputation to complete
4828 if(uint32 repFaction
= pQuest
->GetRepObjectiveFaction())
4830 uint32 repValue
= pQuest
->GetRepObjectiveValue();
4831 uint32 curRep
= player
->GetReputation(repFaction
);
4832 if(curRep
< repValue
)
4834 FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry(repFaction
);
4835 player
->SetFactionReputation(factionEntry
,repValue
);
4839 // If the quest requires money
4840 int32 ReqOrRewMoney
= pQuest
->GetRewOrReqMoney();
4841 if(ReqOrRewMoney
< 0)
4842 player
->ModifyMoney(-ReqOrRewMoney
);
4844 player
->CompleteQuest(entry
);
4848 bool ChatHandler::HandleBanAccountCommand(const char* args
)
4850 return HandleBanHelper(BAN_ACCOUNT
,args
);
4853 bool ChatHandler::HandleBanCharacterCommand(const char* args
)
4855 return HandleBanHelper(BAN_CHARACTER
,args
);
4858 bool ChatHandler::HandleBanIPCommand(const char* args
)
4860 return HandleBanHelper(BAN_IP
,args
);
4863 bool ChatHandler::HandleBanHelper(BanMode mode
, const char* args
)
4868 char* cnameOrIP
= strtok ((char*)args
, " ");
4872 std::string nameOrIP
= cnameOrIP
;
4874 char* duration
= strtok (NULL
," ");
4875 if(!duration
|| !atoi(duration
))
4878 char* reason
= strtok (NULL
,"");
4885 if(!AccountMgr::normilizeString(nameOrIP
))
4887 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
4888 SetSentErrorMessage(true);
4893 if(!normalizePlayerName(nameOrIP
))
4895 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4896 SetSentErrorMessage(true);
4901 if(!IsIPAddress(nameOrIP
.c_str()))
4906 switch(sWorld
.BanAccount(mode
, nameOrIP
, duration
, reason
,m_session
? m_session
->GetPlayerName() : ""))
4909 if(atoi(duration
)>0)
4910 PSendSysMessage(LANG_BAN_YOUBANNED
,nameOrIP
.c_str(),secsToTimeString(TimeStringToSecs(duration
),true).c_str(),reason
);
4912 PSendSysMessage(LANG_BAN_YOUPERMBANNED
,nameOrIP
.c_str(),reason
);
4914 case BAN_SYNTAX_ERROR
:
4920 PSendSysMessage(LANG_BAN_NOTFOUND
,"account",nameOrIP
.c_str());
4923 PSendSysMessage(LANG_BAN_NOTFOUND
,"character",nameOrIP
.c_str());
4926 PSendSysMessage(LANG_BAN_NOTFOUND
,"ip",nameOrIP
.c_str());
4929 SetSentErrorMessage(true);
4936 bool ChatHandler::HandleUnBanAccountCommand(const char* args
)
4938 return HandleUnBanHelper(BAN_ACCOUNT
,args
);
4941 bool ChatHandler::HandleUnBanCharacterCommand(const char* args
)
4943 return HandleUnBanHelper(BAN_CHARACTER
,args
);
4946 bool ChatHandler::HandleUnBanIPCommand(const char* args
)
4948 return HandleUnBanHelper(BAN_IP
,args
);
4951 bool ChatHandler::HandleUnBanHelper(BanMode mode
, const char* args
)
4956 char* cnameOrIP
= strtok ((char*)args
, " ");
4960 std::string nameOrIP
= cnameOrIP
;
4965 if(!AccountMgr::normilizeString(nameOrIP
))
4967 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
4968 SetSentErrorMessage(true);
4973 if(!normalizePlayerName(nameOrIP
))
4975 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4976 SetSentErrorMessage(true);
4981 if(!IsIPAddress(nameOrIP
.c_str()))
4986 if(sWorld
.RemoveBanAccount(mode
,nameOrIP
))
4987 PSendSysMessage(LANG_UNBAN_UNBANNED
,nameOrIP
.c_str());
4989 PSendSysMessage(LANG_UNBAN_ERROR
,nameOrIP
.c_str());
4994 bool ChatHandler::HandleBanInfoAccountCommand(const char* args
)
4999 char* cname
= strtok((char*)args
, "");
5003 std::string account_name
= cname
;
5004 if(!AccountMgr::normilizeString(account_name
))
5006 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5007 SetSentErrorMessage(true);
5011 uint32 accountid
= accmgr
.GetId(account_name
);
5014 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5018 return HandleBanInfoHelper(accountid
,account_name
.c_str());
5021 bool ChatHandler::HandleBanInfoCharacterCommand(const char* args
)
5026 char* cname
= strtok ((char*)args
, "");
5030 std::string name
= cname
;
5031 if(!normalizePlayerName(name
))
5033 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5034 SetSentErrorMessage(true);
5038 uint32 accountid
= objmgr
.GetPlayerAccountIdByPlayerName(name
);
5041 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5042 SetSentErrorMessage(true);
5046 std::string accountname
;
5047 if(!accmgr
.GetName(accountid
,accountname
))
5049 PSendSysMessage(LANG_BANINFO_NOCHARACTER
);
5053 return HandleBanInfoHelper(accountid
,accountname
.c_str());
5056 bool ChatHandler::HandleBanInfoHelper(uint32 accountid
, char const* accountname
)
5058 QueryResult
*result
= loginDatabase
.PQuery("SELECT FROM_UNIXTIME(bandate), unbandate-bandate, active, unbandate,banreason,bannedby FROM account_banned WHERE id = '%u' ORDER BY bandate ASC",accountid
);
5061 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN
, accountname
);
5065 PSendSysMessage(LANG_BANINFO_BANHISTORY
,accountname
);
5068 Field
* fields
= result
->Fetch();
5070 time_t unbandate
= time_t(fields
[3].GetUInt64());
5071 bool active
= false;
5072 if(fields
[2].GetBool() && (fields
[1].GetUInt64() == (uint64
)0 ||unbandate
>= time(NULL
)) )
5074 bool permanent
= (fields
[1].GetUInt64() == (uint64
)0);
5075 std::string bantime
= permanent
?GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[1].GetUInt64(), true);
5076 PSendSysMessage(LANG_BANINFO_HISTORYENTRY
,
5077 fields
[0].GetString(), bantime
.c_str(), active
? GetMangosString(LANG_BANINFO_YES
):GetMangosString(LANG_BANINFO_NO
), fields
[4].GetString(), fields
[5].GetString());
5078 }while (result
->NextRow());
5084 bool ChatHandler::HandleBanInfoIPCommand(const char* args
)
5089 char* cIP
= strtok ((char*)args
, "");
5093 if (!IsIPAddress(cIP
))
5096 std::string IP
= cIP
;
5098 loginDatabase
.escape_string(IP
);
5099 QueryResult
*result
= loginDatabase
.PQuery("SELECT ip, FROM_UNIXTIME(bandate), FROM_UNIXTIME(unbandate), unbandate-UNIX_TIMESTAMP(), banreason,bannedby,unbandate-bandate FROM ip_banned WHERE ip = '%s'",IP
.c_str());
5102 PSendSysMessage(LANG_BANINFO_NOIP
);
5106 Field
*fields
= result
->Fetch();
5107 bool permanent
= !fields
[6].GetUInt64();
5108 PSendSysMessage(LANG_BANINFO_IPENTRY
,
5109 fields
[0].GetString(), fields
[1].GetString(), permanent
? GetMangosString(LANG_BANINFO_NEVER
):fields
[2].GetString(),
5110 permanent
? GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[3].GetUInt64(), true).c_str(), fields
[4].GetString(), fields
[5].GetString());
5115 bool ChatHandler::HandleBanListCharacterCommand(const char* args
)
5117 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5119 char* cFilter
= strtok ((char*)args
, " ");
5123 std::string filter
= cFilter
;
5124 loginDatabase
.escape_string(filter
);
5125 QueryResult
* result
= CharacterDatabase
.PQuery("SELECT account FROM characters WHERE name "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'"),filter
.c_str());
5128 PSendSysMessage(LANG_BANLIST_NOCHARACTER
);
5132 return HandleBanListHelper(result
);
5135 bool ChatHandler::HandleBanListAccountCommand(const char* args
)
5137 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5139 char* cFilter
= strtok((char*)args
, " ");
5140 std::string filter
= cFilter
? cFilter
: "";
5141 loginDatabase
.escape_string(filter
);
5143 QueryResult
* result
;
5147 result
= loginDatabase
.Query("SELECT account.id, username FROM account, account_banned"
5148 " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
5152 result
= loginDatabase
.PQuery("SELECT account.id, username FROM account, account_banned"
5153 " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
5159 PSendSysMessage(LANG_BANLIST_NOACCOUNT
);
5163 return HandleBanListHelper(result
);
5166 bool ChatHandler::HandleBanListHelper(QueryResult
* result
)
5168 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT
);
5170 // Chat short output
5175 Field
* fields
= result
->Fetch();
5176 uint32 accountid
= fields
[0].GetUInt32();
5178 QueryResult
* banresult
= loginDatabase
.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid
);
5181 Field
* fields2
= banresult
->Fetch();
5182 PSendSysMessage("%s",fields2
[0].GetString());
5185 } while (result
->NextRow());
5187 // Console wide output
5190 SendSysMessage(LANG_BANLIST_ACCOUNTS
);
5191 SendSysMessage("===============================================================================");
5192 SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER
);
5195 SendSysMessage("-------------------------------------------------------------------------------");
5196 Field
*fields
= result
->Fetch();
5197 uint32 account_id
= fields
[0].GetUInt32 ();
5199 std::string account_name
;
5201 // "account" case, name can be get in same quary
5202 if(result
->GetFieldCount() > 1)
5203 account_name
= fields
[1].GetCppString();
5204 // "character" case, name need extract from another DB
5206 accmgr
.GetName (account_id
,account_name
);
5208 // No SQL injection. id is uint32.
5209 QueryResult
*banInfo
= loginDatabase
.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id
);
5212 Field
*fields2
= banInfo
->Fetch();
5215 time_t t_ban
= fields2
[0].GetUInt64();
5216 tm
* aTm_ban
= localtime(&t_ban
);
5218 if (fields2
[0].GetUInt64() == fields2
[1].GetUInt64())
5220 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5221 account_name
.c_str(),aTm_ban
->tm_year
%100, aTm_ban
->tm_mon
+1, aTm_ban
->tm_mday
, aTm_ban
->tm_hour
, aTm_ban
->tm_min
,
5222 fields2
[2].GetString(),fields2
[3].GetString());
5226 time_t t_unban
= fields2
[1].GetUInt64();
5227 tm
* aTm_unban
= localtime(&t_unban
);
5228 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5229 account_name
.c_str(),aTm_ban
->tm_year
%100, aTm_ban
->tm_mon
+1, aTm_ban
->tm_mday
, aTm_ban
->tm_hour
, aTm_ban
->tm_min
,
5230 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5231 fields2
[2].GetString(),fields2
[3].GetString());
5233 }while ( banInfo
->NextRow() );
5236 }while( result
->NextRow() );
5237 SendSysMessage("===============================================================================");
5244 bool ChatHandler::HandleBanListIPCommand(const char* args
)
5246 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5248 char* cFilter
= strtok((char*)args
, " ");
5249 std::string filter
= cFilter
? cFilter
: "";
5250 loginDatabase
.escape_string(filter
);
5252 QueryResult
* result
;
5256 result
= loginDatabase
.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5257 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
5258 " ORDER BY unbandate" );
5262 result
= loginDatabase
.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5263 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")
5264 " ORDER BY unbandate",filter
.c_str() );
5269 PSendSysMessage(LANG_BANLIST_NOIP
);
5273 PSendSysMessage(LANG_BANLIST_MATCHINGIP
);
5274 // Chat short output
5279 Field
* fields
= result
->Fetch();
5280 PSendSysMessage("%s",fields
[0].GetString());
5281 } while (result
->NextRow());
5283 // Console wide output
5286 SendSysMessage(LANG_BANLIST_IPS
);
5287 SendSysMessage("===============================================================================");
5288 SendSysMessage(LANG_BANLIST_IPS_HEADER
);
5291 SendSysMessage("-------------------------------------------------------------------------------");
5292 Field
*fields
= result
->Fetch();
5293 time_t t_ban
= fields
[1].GetUInt64();
5294 tm
* aTm_ban
= localtime(&t_ban
);
5295 if ( fields
[1].GetUInt64() == fields
[2].GetUInt64() )
5297 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5298 fields
[0].GetString(), aTm_ban
->tm_year
%100, aTm_ban
->tm_mon
+1, aTm_ban
->tm_mday
, aTm_ban
->tm_hour
, aTm_ban
->tm_min
,
5299 fields
[3].GetString(), fields
[4].GetString());
5303 time_t t_unban
= fields
[2].GetUInt64();
5304 tm
* aTm_unban
= localtime(&t_unban
);
5305 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5306 fields
[0].GetString(), aTm_ban
->tm_year
%100, aTm_ban
->tm_mon
+1, aTm_ban
->tm_mday
, aTm_ban
->tm_hour
, aTm_ban
->tm_min
,
5307 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5308 fields
[3].GetString(), fields
[4].GetString());
5310 }while( result
->NextRow() );
5311 SendSysMessage("===============================================================================");
5318 bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
5320 Unit
* target
= getSelectedUnit();
5324 if(target
->GetTypeId()!=TYPEID_UNIT
)
5326 SendSysMessage(LANG_SELECT_CREATURE
);
5327 SetSentErrorMessage(true);
5331 if(target
->isDead())
5332 ((Creature
*)target
)->Respawn();
5336 Player
* pl
= m_session
->GetPlayer();
5338 CellPair
p(MaNGOS::ComputeCellPair(pl
->GetPositionX(), pl
->GetPositionY()));
5340 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
5343 MaNGOS::RespawnDo u_do
;
5344 MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
> worker(u_do
);
5346 TypeContainerVisitor
<MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
>, GridTypeMapContainer
> obj_worker(worker
);
5347 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
5348 cell_lock
->Visit(cell_lock
, obj_worker
, *MapManager::Instance().GetMap(pl
->GetMapId(), pl
));
5353 bool ChatHandler::HandleFlyModeCommand(const char* args
)
5358 Unit
*unit
= getSelectedUnit();
5359 if (!unit
|| (unit
->GetTypeId() != TYPEID_PLAYER
))
5360 unit
= m_session
->GetPlayer();
5362 WorldPacket
data(12);
5363 if (strncmp(args
, "on", 3) == 0)
5364 data
.SetOpcode(SMSG_MOVE_SET_CAN_FLY
);
5365 else if (strncmp(args
, "off", 4) == 0)
5366 data
.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY
);
5369 SendSysMessage(LANG_USE_BOL
);
5372 data
.append(unit
->GetPackGUID());
5373 data
<< uint32(0); // unknown
5374 unit
->SendMessageToSet(&data
, true);
5375 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS
, unit
->GetName(), args
);
5379 bool ChatHandler::HandleLoadPDumpCommand(const char *args
)
5384 char * file
= strtok((char*)args
, " ");
5388 char * account
= strtok(NULL
, " ");
5392 std::string account_name
= account
;
5393 if(!AccountMgr::normilizeString(account_name
))
5395 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5396 SetSentErrorMessage(true);
5400 uint32 account_id
= accmgr
.GetId(account_name
);
5403 account_id
= atoi(account
); // use original string
5406 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5407 SetSentErrorMessage(true);
5412 if(!accmgr
.GetName(account_id
,account_name
))
5414 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5415 SetSentErrorMessage(true);
5419 char* guid_str
= NULL
;
5420 char* name_str
= strtok(NULL
, " ");
5426 // normalize the name if specified and check if it exists
5427 if(!normalizePlayerName(name
))
5429 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5430 SetSentErrorMessage(true);
5434 if(!ObjectMgr::IsValidName(name
,true))
5436 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5437 SetSentErrorMessage(true);
5441 guid_str
= strtok(NULL
, " ");
5448 guid
= atoi(guid_str
);
5451 PSendSysMessage(LANG_INVALID_CHARACTER_GUID
);
5452 SetSentErrorMessage(true);
5456 if(objmgr
.GetPlayerAccountIdByGUID(guid
))
5458 PSendSysMessage(LANG_CHARACTER_GUID_IN_USE
,guid
);
5459 SetSentErrorMessage(true);
5464 switch(PlayerDumpReader().LoadDump(file
, account_id
, name
, guid
))
5467 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS
);
5469 case DUMP_FILE_OPEN_ERROR
:
5470 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
5471 SetSentErrorMessage(true);
5473 case DUMP_FILE_BROKEN
:
5474 PSendSysMessage(LANG_DUMP_BROKEN
,file
);
5475 SetSentErrorMessage(true);
5477 case DUMP_TOO_MANY_CHARS
:
5478 PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL
,account_name
.c_str(),account_id
);
5479 SetSentErrorMessage(true);
5482 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED
);
5483 SetSentErrorMessage(true);
5490 bool ChatHandler::HandleChangeEntryCommand(const char *args
)
5495 uint32 newEntryNum
= atoi(args
);
5499 Unit
* unit
= getSelectedUnit();
5500 if(!unit
|| unit
->GetTypeId() != TYPEID_UNIT
)
5502 SendSysMessage(LANG_SELECT_CREATURE
);
5503 SetSentErrorMessage(true);
5506 Creature
* creature
= (Creature
*)unit
;
5507 if(creature
->UpdateEntry(newEntryNum
))
5508 SendSysMessage(LANG_DONE
);
5510 SendSysMessage(LANG_ERROR
);
5514 bool ChatHandler::HandleWritePDumpCommand(const char *args
)
5519 char* file
= strtok((char*)args
, " ");
5520 char* p2
= strtok(NULL
, " ");
5525 uint32 guid
= objmgr
.GetPlayerGUIDByName(p2
);
5529 if(!objmgr
.GetPlayerAccountIdByGUID(guid
))
5531 PSendSysMessage(LANG_PLAYER_NOT_FOUND
);
5532 SetSentErrorMessage(true);
5536 switch(PlayerDumpWriter().WriteDump(file
, guid
))
5539 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS
);
5541 case DUMP_FILE_OPEN_ERROR
:
5542 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
5543 SetSentErrorMessage(true);
5546 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED
);
5547 SetSentErrorMessage(true);
5554 bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
5556 Unit
* unit
= getSelectedUnit();
5559 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5560 SetSentErrorMessage(true);
5564 PSendSysMessage(LANG_MOVEGENS_LIST
,(unit
->GetTypeId()==TYPEID_PLAYER
? "Player" : "Creature" ),unit
->GetGUIDLow());
5566 MotionMaster
* mm
= unit
->GetMotionMaster();
5567 for(MotionMaster::const_iterator itr
= mm
->begin(); itr
!= mm
->end(); ++itr
)
5569 switch((*itr
)->GetMovementGeneratorType())
5571 case IDLE_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_IDLE
); break;
5572 case RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_RANDOM
); break;
5573 case WAYPOINT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_WAYPOINT
); break;
5574 case ANIMAL_RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_ANIMAL_RANDOM
); break;
5575 case CONFUSED_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_CONFUSED
); break;
5576 case TARGETED_MOTION_TYPE
:
5578 if(unit
->GetTypeId()==TYPEID_PLAYER
)
5580 TargetedMovementGenerator
<Player
> const* mgen
= static_cast<TargetedMovementGenerator
<Player
> const*>(*itr
);
5581 Unit
* target
= mgen
->GetTarget();
5583 PSendSysMessage(LANG_MOVEGENS_TARGETED_PLAYER
,target
->GetName(),target
->GetGUIDLow());
5585 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL
);
5589 TargetedMovementGenerator
<Creature
> const* mgen
= static_cast<TargetedMovementGenerator
<Creature
> const*>(*itr
);
5590 Unit
* target
= mgen
->GetTarget();
5592 PSendSysMessage(LANG_MOVEGENS_TARGETED_CREATURE
,target
->GetName(),target
->GetGUIDLow());
5594 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL
);
5598 case HOME_MOTION_TYPE
:
5599 if(unit
->GetTypeId()==TYPEID_UNIT
)
5602 (*itr
)->GetDestination(x
,y
,z
);
5603 PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE
,x
,y
,z
);
5606 SendSysMessage(LANG_MOVEGENS_HOME_PLAYER
);
5608 case FLIGHT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FLIGHT
); break;
5609 case POINT_MOTION_TYPE
:
5612 (*itr
)->GetDestination(x
,y
,z
);
5613 PSendSysMessage(LANG_MOVEGENS_POINT
,x
,y
,z
);
5616 case FLEEING_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FEAR
); break;
5617 case DISTRACT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_DISTRACT
); break;
5619 PSendSysMessage(LANG_MOVEGENS_UNKNOWN
,(*itr
)->GetMovementGeneratorType());
5626 bool ChatHandler::HandlePLimitCommand(const char *args
)
5630 char* param
= strtok((char*)args
, " ");
5634 int l
= strlen(param
);
5636 if( strncmp(param
,"player",l
) == 0 )
5637 sWorld
.SetPlayerLimit(-SEC_PLAYER
);
5638 else if(strncmp(param
,"moderator",l
) == 0 )
5639 sWorld
.SetPlayerLimit(-SEC_MODERATOR
);
5640 else if(strncmp(param
,"gamemaster",l
) == 0 )
5641 sWorld
.SetPlayerLimit(-SEC_GAMEMASTER
);
5642 else if(strncmp(param
,"administrator",l
) == 0 )
5643 sWorld
.SetPlayerLimit(-SEC_ADMINISTRATOR
);
5644 else if(strncmp(param
,"reset",l
) == 0 )
5645 sWorld
.SetPlayerLimit( sConfig
.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT
) );
5648 int val
= atoi(param
);
5649 if(val
< -SEC_ADMINISTRATOR
) val
= -SEC_ADMINISTRATOR
;
5651 sWorld
.SetPlayerLimit(val
);
5654 // kick all low security level players
5655 if(sWorld
.GetPlayerAmountLimit() > SEC_PLAYER
)
5656 sWorld
.KickAllLess(sWorld
.GetPlayerSecurityLimit());
5659 uint32 pLimit
= sWorld
.GetPlayerAmountLimit();
5660 AccountTypes allowedAccountType
= sWorld
.GetPlayerSecurityLimit();
5661 char const* secName
= "";
5662 switch(allowedAccountType
)
5664 case SEC_PLAYER
: secName
= "Player"; break;
5665 case SEC_MODERATOR
: secName
= "Moderator"; break;
5666 case SEC_GAMEMASTER
: secName
= "Gamemaster"; break;
5667 case SEC_ADMINISTRATOR
: secName
= "Administrator"; break;
5668 default: secName
= "<unknown>"; break;
5671 PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit
,secName
);
5676 bool ChatHandler::HandleCastCommand(const char* args
)
5681 Unit
* target
= getSelectedUnit();
5685 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5686 SetSentErrorMessage(true);
5690 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5691 uint32 spell
= extractSpellIdFromLink((char*)args
);
5695 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5699 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5701 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5702 SetSentErrorMessage(true);
5706 char* trig_str
= strtok(NULL
, " ");
5709 int l
= strlen(trig_str
);
5710 if(strncmp(trig_str
,"triggered",l
) != 0 )
5714 bool triggered
= (trig_str
!= NULL
);
5716 m_session
->GetPlayer()->CastSpell(target
,spell
,triggered
);
5721 bool ChatHandler::HandleCastBackCommand(const char* args
)
5723 Creature
* caster
= getSelectedCreature();
5727 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5728 SetSentErrorMessage(true);
5732 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
5733 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5734 uint32 spell
= extractSpellIdFromLink((char*)args
);
5735 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
5738 char* trig_str
= strtok(NULL
, " ");
5741 int l
= strlen(trig_str
);
5742 if(strncmp(trig_str
,"triggered",l
) != 0 )
5746 bool triggered
= (trig_str
!= NULL
);
5748 // update orientation at server
5749 caster
->SetOrientation(caster
->GetAngle(m_session
->GetPlayer()));
5753 caster
->BuildHeartBeatMsg(&data
);
5754 caster
->SendMessageToSet(&data
,true);
5756 caster
->CastSpell(m_session
->GetPlayer(),spell
,false);
5761 bool ChatHandler::HandleCastDistCommand(const char* args
)
5766 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5767 uint32 spell
= extractSpellIdFromLink((char*)args
);
5771 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5775 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5777 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5778 SetSentErrorMessage(true);
5782 char *distStr
= strtok(NULL
, " ");
5787 sscanf(distStr
, "%f", &dist
);
5789 char* trig_str
= strtok(NULL
, " ");
5792 int l
= strlen(trig_str
);
5793 if(strncmp(trig_str
,"triggered",l
) != 0 )
5797 bool triggered
= (trig_str
!= NULL
);
5800 m_session
->GetPlayer()->GetClosePoint(x
,y
,z
,dist
);
5802 m_session
->GetPlayer()->CastSpell(x
,y
,z
,spell
,triggered
);
5806 bool ChatHandler::HandleCastTargetCommand(const char* args
)
5808 Creature
* caster
= getSelectedCreature();
5812 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5813 SetSentErrorMessage(true);
5817 if(!caster
->getVictim())
5819 SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM
);
5820 SetSentErrorMessage(true);
5824 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5825 uint32 spell
= extractSpellIdFromLink((char*)args
);
5826 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
5829 char* trig_str
= strtok(NULL
, " ");
5832 int l
= strlen(trig_str
);
5833 if(strncmp(trig_str
,"triggered",l
) != 0 )
5837 bool triggered
= (trig_str
!= NULL
);
5839 // update orientation at server
5840 caster
->SetOrientation(caster
->GetAngle(m_session
->GetPlayer()));
5844 caster
->BuildHeartBeatMsg(&data
);
5845 caster
->SendMessageToSet(&data
,true);
5847 caster
->CastSpell(caster
->getVictim(),spell
,false);
5853 ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
5854 Without this function 3rd party scripting library will get linking errors (unresolved external)
5855 when attempting to use the PointMovementGenerator
5857 bool ChatHandler::HandleComeToMeCommand(const char *args
)
5859 Creature
* caster
= getSelectedCreature();
5863 SendSysMessage(LANG_SELECT_CREATURE
);
5864 SetSentErrorMessage(true);
5868 char* newFlagStr
= strtok((char*)args
, " ");
5873 uint32 newFlags
= atoi(newFlagStr
);
5875 caster
->SetUnitMovementFlags(newFlags
);
5877 Player
* pl
= m_session
->GetPlayer();
5879 caster
->GetMotionMaster()->MovePoint(0, pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ());
5883 bool ChatHandler::HandleCastSelfCommand(const char* args
)
5888 Unit
* target
= getSelectedUnit();
5892 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5893 SetSentErrorMessage(true);
5897 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5898 uint32 spell
= extractSpellIdFromLink((char*)args
);
5902 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5906 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5908 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5909 SetSentErrorMessage(true);
5913 target
->CastSpell(target
,spell
,false);
5918 std::string
GetTimeString(uint32 time
)
5920 uint16 days
= time
/ DAY
, hours
= (time
% DAY
) / HOUR
, minute
= (time
% HOUR
) / MINUTE
;
5921 std::ostringstream ss
;
5922 if(days
) ss
<< days
<< "d ";
5923 if(hours
) ss
<< hours
<< "h ";
5924 ss
<< minute
<< "m";
5928 bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
5930 Player
* player
= getSelectedPlayer();
5931 if (!player
) player
= m_session
->GetPlayer();
5933 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
5935 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(i
);
5936 for(Player::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
5938 InstanceSave
*save
= itr
->second
.save
;
5939 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
5940 PSendSysMessage("map: %d inst: %d perm: %s diff: %s canReset: %s TTR: %s", itr
->first
, save
->GetInstanceId(), itr
->second
.perm
? "yes" : "no", save
->GetDifficulty() == DIFFICULTY_NORMAL
? "normal" : "heroic", save
->CanReset() ? "yes" : "no", timeleft
.c_str());
5944 PSendSysMessage("player binds: %d", counter
);
5946 Group
*group
= player
->GetGroup();
5949 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
5951 Group::BoundInstancesMap
&binds
= group
->GetBoundInstances(i
);
5952 for(Group::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
5954 InstanceSave
*save
= itr
->second
.save
;
5955 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
5956 PSendSysMessage("map: %d inst: %d perm: %s diff: %s canReset: %s TTR: %s", itr
->first
, save
->GetInstanceId(), itr
->second
.perm
? "yes" : "no", save
->GetDifficulty() == DIFFICULTY_NORMAL
? "normal" : "heroic", save
->CanReset() ? "yes" : "no", timeleft
.c_str());
5961 PSendSysMessage("group binds: %d", counter
);
5966 bool ChatHandler::HandleInstanceUnbindCommand(const char* args
)
5971 std::string cmd
= args
;
5974 Player
* player
= getSelectedPlayer();
5975 if (!player
) player
= m_session
->GetPlayer();
5977 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
5979 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(i
);
5980 for(Player::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end();)
5982 if(itr
->first
!= player
->GetMapId())
5984 InstanceSave
*save
= itr
->second
.save
;
5985 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
5986 PSendSysMessage("unbinding map: %d inst: %d perm: %s diff: %s canReset: %s TTR: %s", itr
->first
, save
->GetInstanceId(), itr
->second
.perm
? "yes" : "no", save
->GetDifficulty() == DIFFICULTY_NORMAL
? "normal" : "heroic", save
->CanReset() ? "yes" : "no", timeleft
.c_str());
5987 player
->UnbindInstance(itr
, i
);
5994 PSendSysMessage("instances unbound: %d", counter
);
5999 bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
6001 PSendSysMessage("instances loaded: %d", MapManager::Instance().GetNumInstances());
6002 PSendSysMessage("players in instances: %d", MapManager::Instance().GetNumPlayersInInstances());
6003 PSendSysMessage("instance saves: %d", sInstanceSaveManager
.GetNumInstanceSaves());
6004 PSendSysMessage("players bound: %d", sInstanceSaveManager
.GetNumBoundPlayersTotal());
6005 PSendSysMessage("groups bound: %d", sInstanceSaveManager
.GetNumBoundGroupsTotal());
6009 bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
6011 Player
* pl
= m_session
->GetPlayer();
6013 Map
* map
= pl
->GetMap();
6014 if (!map
->IsDungeon())
6016 PSendSysMessage("Map is not a dungeon.");
6017 SetSentErrorMessage(true);
6021 if (!((InstanceMap
*)map
)->GetInstanceData())
6023 PSendSysMessage("Map has no instance data.");
6024 SetSentErrorMessage(true);
6028 ((InstanceMap
*)map
)->GetInstanceData()->SaveToDB();
6032 /// Display the list of GMs
6033 bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
6035 ///- Get the accounts with GM Level >0
6036 QueryResult
*result
= loginDatabase
.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
6039 SendSysMessage(LANG_GMLIST
);
6040 SendSysMessage("========================");
6041 SendSysMessage(LANG_GMLIST_HEADER
);
6042 SendSysMessage("========================");
6044 ///- Circle through them. Display username and GM level
6047 Field
*fields
= result
->Fetch();
6048 PSendSysMessage("|%15s|%6s|", fields
[0].GetString(),fields
[1].GetString());
6049 }while( result
->NextRow() );
6051 PSendSysMessage("========================");
6055 PSendSysMessage(LANG_GMLIST_EMPTY
);
6059 /// Define the 'Message of the day' for the realm
6060 bool ChatHandler::HandleServerSetMotdCommand(const char* args
)
6062 sWorld
.SetMotd(args
);
6063 PSendSysMessage(LANG_MOTD_NEW
, args
);
6067 /// Set/Unset the expansion level for an account
6068 bool ChatHandler::HandleAccountSetAddonCommand(const char* args
)
6070 ///- Get the command line arguments
6071 char *szAcc
= strtok((char*)args
," ");
6072 char *szExp
= strtok(NULL
," ");
6077 std::string account_name
;
6082 Player
* player
= getSelectedPlayer();
6086 account_id
= player
->GetSession()->GetAccountId();
6087 accmgr
.GetName(account_id
,account_name
);
6092 ///- Convert Account name to Upper Format
6093 account_name
= szAcc
;
6094 if(!AccountMgr::normilizeString(account_name
))
6096 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
6097 SetSentErrorMessage(true);
6101 account_id
= accmgr
.GetId(account_name
);
6104 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
6105 SetSentErrorMessage(true);
6110 int lev
=atoi(szExp
); //get int anyway (0 if error)
6115 loginDatabase
.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev
,account_id
);
6116 PSendSysMessage(LANG_ACCOUNT_SETADDON
,account_name
.c_str(),account_id
,lev
);
6120 /// Send a message to a player in game
6121 bool ChatHandler::HandleSendMessageCommand(const char* args
)
6123 ///- Get the command line arguments
6124 char* name_str
= strtok((char*)args
, " ");
6125 char* msg_str
= strtok(NULL
, "");
6127 if(!name_str
|| !msg_str
)
6130 std::string name
= name_str
;
6132 if(!normalizePlayerName(name
))
6135 ///- Find the player and check that he is not logging out.
6136 Player
*rPlayer
= objmgr
.GetPlayer(name
.c_str());
6139 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6140 SetSentErrorMessage(true);
6144 if(rPlayer
->GetSession()->isLogingOut())
6146 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6147 SetSentErrorMessage(true);
6151 ///- Send the message
6152 //Use SendAreaTriggerMessage for fastest delivery.
6153 rPlayer
->GetSession()->SendAreaTriggerMessage("%s", msg_str
);
6154 rPlayer
->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
6156 //Confirmation message
6157 PSendSysMessage(LANG_SENDMESSAGE
,name
.c_str(),msg_str
);