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 HandleReloadNpcTrainerCommand("a");
104 HandleReloadNpcVendorCommand("a");
108 bool ChatHandler::HandleReloadAllQuestCommand(const char* /*args*/)
110 HandleReloadQuestAreaTriggersCommand("a");
111 HandleReloadQuestTemplateCommand("a");
113 sLog
.outString( "Re-Loading Quests Relations..." );
114 objmgr
.LoadQuestRelations();
115 SendGlobalSysMessage("DB tables `*_questrelation` and `*_involvedrelation` reloaded.");
119 bool ChatHandler::HandleReloadAllScriptsCommand(const char*)
121 if(sWorld
.IsScriptScheduled())
123 PSendSysMessage("DB scripts used currently, please attempt reload later.");
124 SetSentErrorMessage(true);
128 sLog
.outString( "Re-Loading Scripts..." );
129 HandleReloadGameObjectScriptsCommand("a");
130 HandleReloadEventScriptsCommand("a");
131 HandleReloadQuestEndScriptsCommand("a");
132 HandleReloadQuestStartScriptsCommand("a");
133 HandleReloadSpellScriptsCommand("a");
134 SendGlobalSysMessage("DB tables `*_scripts` reloaded.");
138 bool ChatHandler::HandleReloadAllSpellCommand(const char*)
140 HandleReloadSkillDiscoveryTemplateCommand("a");
141 HandleReloadSkillExtraItemTemplateCommand("a");
142 HandleReloadSpellAffectCommand("a");
143 HandleReloadSpellChainCommand("a");
144 HandleReloadSpellElixirCommand("a");
145 HandleReloadSpellLearnSpellCommand("a");
146 HandleReloadSpellProcEventCommand("a");
147 HandleReloadSpellScriptTargetCommand("a");
148 HandleReloadSpellTargetPositionCommand("a");
149 HandleReloadSpellThreatsCommand("a");
150 HandleReloadSpellPetAurasCommand("a");
154 bool ChatHandler::HandleReloadAllItemCommand(const char*)
156 HandleReloadPageTextsCommand("a");
157 HandleReloadItemEnchantementsCommand("a");
161 bool ChatHandler::HandleReloadAllLocalesCommand(const char* args
)
163 HandleReloadLocalesCreatureCommand("a");
164 HandleReloadLocalesGameobjectCommand("a");
165 HandleReloadLocalesItemCommand("a");
166 HandleReloadLocalesNpcTextCommand("a");
167 HandleReloadLocalesPageTextCommand("a");
168 HandleReloadLocalesQuestCommand("a");
172 bool ChatHandler::HandleReloadConfigCommand(const char* arg
)
174 sLog
.outString( "Re-Loading config settings..." );
175 sWorld
.LoadConfigSettings(true);
176 SendGlobalSysMessage("World config settings reloaded.");
180 bool ChatHandler::HandleReloadAreaTriggerTavernCommand(const char*)
182 sLog
.outString( "Re-Loading Tavern Area Triggers..." );
183 objmgr
.LoadTavernAreaTriggers();
184 SendGlobalSysMessage("DB table `areatrigger_tavern` reloaded.");
188 bool ChatHandler::HandleReloadAreaTriggerTeleportCommand(const char*)
190 sLog
.outString( "Re-Loading AreaTrigger teleport definitions..." );
191 objmgr
.LoadAreaTriggerTeleports();
192 SendGlobalSysMessage("DB table `areatrigger_teleport` reloaded.");
196 bool ChatHandler::HandleReloadCommandCommand(const char*)
198 load_command_table
= true;
199 SendGlobalSysMessage("DB table `command` will be reloaded at next chat command use.");
203 bool ChatHandler::HandleReloadCreatureQuestRelationsCommand(const char*)
205 sLog
.outString( "Loading Quests Relations... (`creature_questrelation`)" );
206 objmgr
.LoadCreatureQuestRelations();
207 SendGlobalSysMessage("DB table `creature_questrelation` (creature quest givers) reloaded.");
211 bool ChatHandler::HandleReloadCreatureQuestInvRelationsCommand(const char*)
213 sLog
.outString( "Loading Quests Relations... (`creature_involvedrelation`)" );
214 objmgr
.LoadCreatureInvolvedRelations();
215 SendGlobalSysMessage("DB table `creature_involvedrelation` (creature quest takers) reloaded.");
219 bool ChatHandler::HandleReloadGOQuestRelationsCommand(const char*)
221 sLog
.outString( "Loading Quests Relations... (`gameobject_questrelation`)" );
222 objmgr
.LoadGameobjectQuestRelations();
223 SendGlobalSysMessage("DB table `gameobject_questrelation` (gameobject quest givers) reloaded.");
227 bool ChatHandler::HandleReloadGOQuestInvRelationsCommand(const char*)
229 sLog
.outString( "Loading Quests Relations... (`gameobject_involvedrelation`)" );
230 objmgr
.LoadGameobjectInvolvedRelations();
231 SendGlobalSysMessage("DB table `gameobject_involvedrelation` (gameobject quest takers) reloaded.");
235 bool ChatHandler::HandleReloadQuestAreaTriggersCommand(const char*)
237 sLog
.outString( "Re-Loading Quest Area Triggers..." );
238 objmgr
.LoadQuestAreaTriggers();
239 SendGlobalSysMessage("DB table `areatrigger_involvedrelation` (quest area triggers) reloaded.");
243 bool ChatHandler::HandleReloadQuestTemplateCommand(const char*)
245 sLog
.outString( "Re-Loading Quest Templates..." );
247 SendGlobalSysMessage("DB table `quest_template` (quest definitions) reloaded.");
251 bool ChatHandler::HandleReloadLootTemplatesCreatureCommand(const char*)
253 sLog
.outString( "Re-Loading Loot Tables... (`creature_loot_template`)" );
254 LoadLootTemplates_Creature();
255 LootTemplates_Creature
.CheckLootRefs();
256 SendGlobalSysMessage("DB table `creature_loot_template` reloaded.");
260 bool ChatHandler::HandleReloadLootTemplatesDisenchantCommand(const char*)
262 sLog
.outString( "Re-Loading Loot Tables... (`disenchant_loot_template`)" );
263 LoadLootTemplates_Disenchant();
264 LootTemplates_Disenchant
.CheckLootRefs();
265 SendGlobalSysMessage("DB table `disenchant_loot_template` reloaded.");
269 bool ChatHandler::HandleReloadLootTemplatesFishingCommand(const char*)
271 sLog
.outString( "Re-Loading Loot Tables... (`fishing_loot_template`)" );
272 LoadLootTemplates_Fishing();
273 LootTemplates_Fishing
.CheckLootRefs();
274 SendGlobalSysMessage("DB table `fishing_loot_template` reloaded.");
278 bool ChatHandler::HandleReloadLootTemplatesGameobjectCommand(const char*)
280 sLog
.outString( "Re-Loading Loot Tables... (`gameobject_loot_template`)" );
281 LoadLootTemplates_Gameobject();
282 LootTemplates_Gameobject
.CheckLootRefs();
283 SendGlobalSysMessage("DB table `gameobject_loot_template` reloaded.");
287 bool ChatHandler::HandleReloadLootTemplatesItemCommand(const char*)
289 sLog
.outString( "Re-Loading Loot Tables... (`item_loot_template`)" );
290 LoadLootTemplates_Item();
291 LootTemplates_Item
.CheckLootRefs();
292 SendGlobalSysMessage("DB table `item_loot_template` reloaded.");
296 bool ChatHandler::HandleReloadLootTemplatesPickpocketingCommand(const char*)
298 sLog
.outString( "Re-Loading Loot Tables... (`pickpocketing_loot_template`)" );
299 LoadLootTemplates_Pickpocketing();
300 LootTemplates_Pickpocketing
.CheckLootRefs();
301 SendGlobalSysMessage("DB table `pickpocketing_loot_template` reloaded.");
305 bool ChatHandler::HandleReloadLootTemplatesProspectingCommand(const char*)
307 sLog
.outString( "Re-Loading Loot Tables... (`prospecting_loot_template`)" );
308 LoadLootTemplates_Prospecting();
309 LootTemplates_Prospecting
.CheckLootRefs();
310 SendGlobalSysMessage("DB table `prospecting_loot_template` reloaded.");
314 bool ChatHandler::HandleReloadLootTemplatesQuestMailCommand(const char*)
316 sLog
.outString( "Re-Loading Loot Tables... (`quest_mail_loot_template`)" );
317 LoadLootTemplates_QuestMail();
318 LootTemplates_QuestMail
.CheckLootRefs();
319 SendGlobalSysMessage("DB table `quest_mail_loot_template` reloaded.");
323 bool ChatHandler::HandleReloadLootTemplatesReferenceCommand(const char*)
325 sLog
.outString( "Re-Loading Loot Tables... (`reference_loot_template`)" );
326 LoadLootTemplates_Reference();
327 SendGlobalSysMessage("DB table `reference_loot_template` reloaded.");
331 bool ChatHandler::HandleReloadLootTemplatesSkinningCommand(const char*)
333 sLog
.outString( "Re-Loading Loot Tables... (`skinning_loot_template`)" );
334 LoadLootTemplates_Skinning();
335 LootTemplates_Skinning
.CheckLootRefs();
336 SendGlobalSysMessage("DB table `skinning_loot_template` reloaded.");
340 bool ChatHandler::HandleReloadMangosStringCommand(const char*)
342 sLog
.outString( "Re-Loading mangos_string Table!" );
343 objmgr
.LoadMangosStrings();
344 SendGlobalSysMessage("DB table `mangos_string` reloaded.");
348 bool ChatHandler::HandleReloadNpcGossipCommand(const char*)
350 sLog
.outString( "Re-Loading `npc_gossip` Table!" );
351 objmgr
.LoadNpcTextId();
352 SendGlobalSysMessage("DB table `npc_gossip` reloaded.");
356 bool ChatHandler::HandleReloadNpcTrainerCommand(const char*)
358 sLog
.outString( "Re-Loading `npc_trainer` Table!" );
359 objmgr
.LoadTrainerSpell();
360 SendGlobalSysMessage("DB table `npc_trainer` reloaded.");
364 bool ChatHandler::HandleReloadNpcVendorCommand(const char*)
366 sLog
.outString( "Re-Loading `npc_vendor` Table!" );
367 objmgr
.LoadVendors();
368 SendGlobalSysMessage("DB table `npc_vendor` reloaded.");
372 bool ChatHandler::HandleReloadReservedNameCommand(const char*)
374 sLog
.outString( "Loading ReservedNames... (`reserved_name`)" );
375 objmgr
.LoadReservedPlayersNames();
376 SendGlobalSysMessage("DB table `reserved_name` (player reserved names) reloaded.");
380 bool ChatHandler::HandleReloadSkillDiscoveryTemplateCommand(const char* /*args*/)
382 sLog
.outString( "Re-Loading Skill Discovery Table..." );
383 LoadSkillDiscoveryTable();
384 SendGlobalSysMessage("DB table `skill_discovery_template` (recipes discovered at crafting) reloaded.");
388 bool ChatHandler::HandleReloadSkillExtraItemTemplateCommand(const char* /*args*/)
390 sLog
.outString( "Re-Loading Skill Extra Item Table..." );
391 LoadSkillExtraItemTable();
392 SendGlobalSysMessage("DB table `skill_extra_item_template` (extra item creation when crafting) reloaded.");
396 bool ChatHandler::HandleReloadSkillFishingBaseLevelCommand(const char* /*args*/)
398 sLog
.outString( "Re-Loading Skill Fishing base level requirements..." );
399 objmgr
.LoadFishingBaseSkillLevel();
400 SendGlobalSysMessage("DB table `skill_fishing_base_level` (fishing base level for zone/subzone) reloaded.");
404 bool ChatHandler::HandleReloadSpellAffectCommand(const char*)
406 sLog
.outString( "Re-Loading SpellAffect definitions..." );
407 spellmgr
.LoadSpellAffects();
408 SendGlobalSysMessage("DB table `spell_affect` (spell mods apply requirements) reloaded.");
412 bool ChatHandler::HandleReloadSpellChainCommand(const char*)
414 sLog
.outString( "Re-Loading Spell Chain Data... " );
415 spellmgr
.LoadSpellChains();
416 SendGlobalSysMessage("DB table `spell_chain` (spell ranks) reloaded.");
420 bool ChatHandler::HandleReloadSpellElixirCommand(const char*)
422 sLog
.outString( "Re-Loading Spell Elixir types..." );
423 spellmgr
.LoadSpellElixirs();
424 SendGlobalSysMessage("DB table `spell_elixir` (spell exlixir types) reloaded.");
428 bool ChatHandler::HandleReloadSpellLearnSpellCommand(const char*)
430 sLog
.outString( "Re-Loading Spell Learn Spells..." );
431 spellmgr
.LoadSpellLearnSpells();
432 SendGlobalSysMessage("DB table `spell_learn_spell` reloaded.");
436 bool ChatHandler::HandleReloadSpellProcEventCommand(const char*)
438 sLog
.outString( "Re-Loading Spell Proc Event conditions..." );
439 spellmgr
.LoadSpellProcEvents();
440 SendGlobalSysMessage("DB table `spell_proc_event` (spell proc trigger requirements) reloaded.");
444 bool ChatHandler::HandleReloadSpellScriptTargetCommand(const char*)
446 sLog
.outString( "Re-Loading SpellsScriptTarget..." );
447 spellmgr
.LoadSpellScriptTarget();
448 SendGlobalSysMessage("DB table `spell_script_target` (spell targets selection in case specific creature/GO requirements) reloaded.");
452 bool ChatHandler::HandleReloadSpellTargetPositionCommand(const char*)
454 sLog
.outString( "Re-Loading Spell target coordinates..." );
455 spellmgr
.LoadSpellTargetPositions();
456 SendGlobalSysMessage("DB table `spell_target_position` (destination coordinates for spell targets) reloaded.");
460 bool ChatHandler::HandleReloadSpellThreatsCommand(const char*)
462 sLog
.outString( "Re-Loading Aggro Spells Definitions...");
463 spellmgr
.LoadSpellThreats();
464 SendGlobalSysMessage("DB table `spell_threat` (spell aggro definitions) reloaded.");
468 bool ChatHandler::HandleReloadSpellPetAurasCommand(const char*)
470 sLog
.outString( "Re-Loading Spell pet auras...");
471 spellmgr
.LoadSpellPetAuras();
472 SendGlobalSysMessage("DB table `spell_pet_auras` reloaded.");
476 bool ChatHandler::HandleReloadPageTextsCommand(const char*)
478 sLog
.outString( "Re-Loading Page Texts..." );
479 objmgr
.LoadPageTexts();
480 SendGlobalSysMessage("DB table `page_texts` reloaded.");
484 bool ChatHandler::HandleReloadItemEnchantementsCommand(const char*)
486 sLog
.outString( "Re-Loading Item Random Enchantments Table..." );
487 LoadRandomEnchantmentsTable();
488 SendGlobalSysMessage("DB table `item_enchantment_template` reloaded.");
492 bool ChatHandler::HandleReloadGameObjectScriptsCommand(const char* arg
)
494 if(sWorld
.IsScriptScheduled())
496 SendSysMessage("DB scripts used currently, please attempt reload later.");
497 SetSentErrorMessage(true);
502 sLog
.outString( "Re-Loading Scripts from `gameobject_scripts`...");
504 objmgr
.LoadGameObjectScripts();
507 SendGlobalSysMessage("DB table `gameobject_scripts` reloaded.");
512 bool ChatHandler::HandleReloadEventScriptsCommand(const char* arg
)
514 if(sWorld
.IsScriptScheduled())
516 SendSysMessage("DB scripts used currently, please attempt reload later.");
517 SetSentErrorMessage(true);
522 sLog
.outString( "Re-Loading Scripts from `event_scripts`...");
524 objmgr
.LoadEventScripts();
527 SendGlobalSysMessage("DB table `event_scripts` reloaded.");
532 bool ChatHandler::HandleReloadQuestEndScriptsCommand(const char* arg
)
534 if(sWorld
.IsScriptScheduled())
536 SendSysMessage("DB scripts used currently, please attempt reload later.");
537 SetSentErrorMessage(true);
542 sLog
.outString( "Re-Loading Scripts from `quest_end_scripts`...");
544 objmgr
.LoadQuestEndScripts();
547 SendGlobalSysMessage("DB table `quest_end_scripts` reloaded.");
552 bool ChatHandler::HandleReloadQuestStartScriptsCommand(const char* arg
)
554 if(sWorld
.IsScriptScheduled())
556 SendSysMessage("DB scripts used currently, please attempt reload later.");
557 SetSentErrorMessage(true);
562 sLog
.outString( "Re-Loading Scripts from `quest_start_scripts`...");
564 objmgr
.LoadQuestStartScripts();
567 SendGlobalSysMessage("DB table `quest_start_scripts` reloaded.");
572 bool ChatHandler::HandleReloadSpellScriptsCommand(const char* arg
)
574 if(sWorld
.IsScriptScheduled())
576 SendSysMessage("DB scripts used currently, please attempt reload later.");
577 SetSentErrorMessage(true);
582 sLog
.outString( "Re-Loading Scripts from `spell_scripts`...");
584 objmgr
.LoadSpellScripts();
587 SendGlobalSysMessage("DB table `spell_scripts` reloaded.");
592 bool ChatHandler::HandleReloadGameGraveyardZoneCommand(const char* /*arg*/)
594 sLog
.outString( "Re-Loading Graveyard-zone links...");
596 objmgr
.LoadGraveyardZones();
598 SendGlobalSysMessage("DB table `game_graveyard_zone` reloaded.");
603 bool ChatHandler::HandleReloadGameTeleCommand(const char* /*arg*/)
605 sLog
.outString( "Re-Loading Game Tele coordinates...");
607 objmgr
.LoadGameTele();
609 SendGlobalSysMessage("DB table `game_tele` reloaded.");
614 bool ChatHandler::HandleReloadLocalesCreatureCommand(const char* /*arg*/)
616 sLog
.outString( "Re-Loading Locales Creature ...");
617 objmgr
.LoadCreatureLocales();
618 SendGlobalSysMessage("DB table `locales_creature` reloaded.");
622 bool ChatHandler::HandleReloadLocalesGameobjectCommand(const char* /*arg*/)
624 sLog
.outString( "Re-Loading Locales Gameobject ... ");
625 objmgr
.LoadGameObjectLocales();
626 SendGlobalSysMessage("DB table `locales_gameobject` reloaded.");
630 bool ChatHandler::HandleReloadLocalesItemCommand(const char* /*arg*/)
632 sLog
.outString( "Re-Loading Locales Item ... ");
633 objmgr
.LoadItemLocales();
634 SendGlobalSysMessage("DB table `locales_item` reloaded.");
638 bool ChatHandler::HandleReloadLocalesNpcTextCommand(const char* /*arg*/)
640 sLog
.outString( "Re-Loading Locales NPC Text ... ");
641 objmgr
.LoadNpcTextLocales();
642 SendGlobalSysMessage("DB table `locales_npc_text` reloaded.");
646 bool ChatHandler::HandleReloadLocalesPageTextCommand(const char* /*arg*/)
648 sLog
.outString( "Re-Loading Locales Page Text ... ");
649 objmgr
.LoadPageTextLocales();
650 SendGlobalSysMessage("DB table `locales_page_text` reloaded.");
654 bool ChatHandler::HandleReloadLocalesQuestCommand(const char* /*arg*/)
656 sLog
.outString( "Re-Loading Locales Quest ... ");
657 objmgr
.LoadQuestLocales();
658 SendGlobalSysMessage("DB table `locales_quest` reloaded.");
662 bool ChatHandler::HandleLoadScriptsCommand(const char* args
)
664 if(!LoadScriptingModule(args
)) return true;
666 sWorld
.SendWorldText(LANG_SCRIPTS_RELOADED
);
670 bool ChatHandler::HandleAccountSetGmLevelCommand(const char* args
)
672 char* arg1
= strtok((char*)args
, " ");
676 char* arg2
= strtok(NULL
, " ");
678 std::string targetAccountName
;
679 uint32 targetAccountId
= 0;
680 uint32 targetSecurity
= 0;
682 /// only target player different from self allowed (if targetPlayer!=NULL then not console)
683 Player
* targetPlayer
= getSelectedPlayer();
684 if(targetPlayer
&& m_session
->GetPlayer()!=targetPlayer
)
686 /// wrong command syntax or unexpected targeting
690 targetAccountId
= targetPlayer
->GetSession()->GetAccountId();
691 targetSecurity
= targetPlayer
->GetSession()->GetSecurity();
692 if(!accmgr
.GetName(targetAccountId
,targetAccountName
))
694 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,targetAccountName
.c_str());
695 SetSentErrorMessage(true);
701 targetAccountName
= arg1
;
702 if(!AccountMgr::normilizeString(targetAccountName
))
704 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,targetAccountName
.c_str());
705 SetSentErrorMessage(true);
709 targetAccountId
= accmgr
.GetId(targetAccountName
);
710 targetSecurity
= accmgr
.GetSecurity(targetAccountId
);
713 int32 gm
= (int32
)atoi(arg2
);
714 if ( gm
< SEC_PLAYER
|| gm
> SEC_ADMINISTRATOR
)
716 SendSysMessage(LANG_BAD_VALUE
);
717 SetSentErrorMessage(true);
721 /// m_session==NULL only for console
722 uint32 plSecurity
= m_session
? m_session
->GetSecurity() : SEC_CONSOLE
;
724 /// can set security level only for target with less security and to less security that we have
725 /// This is also reject self apply in fact
726 if(targetSecurity
>= plSecurity
|| uint32(gm
) >= plSecurity
)
728 SendSysMessage(LANG_YOURS_SECURITY_IS_LOW
);
729 SetSentErrorMessage(true);
735 ChatHandler(targetPlayer
).PSendSysMessage(LANG_YOURS_SECURITY_CHANGED
,m_session
->GetPlayer()->GetName(), gm
);
736 targetPlayer
->GetSession()->SetSecurity(gm
);
739 PSendSysMessage(LANG_YOU_CHANGE_SECURITY
, targetAccountName
.c_str(), gm
);
740 loginDatabase
.PExecute("UPDATE account SET gmlevel = '%i' WHERE id = '%u'", gm
, targetAccountId
);
745 /// Set password for account
746 bool ChatHandler::HandleAccountSetPasswordCommand(const char* args
)
751 ///- Get the command line arguments
752 char *szAccount
= strtok ((char*)args
," ");
753 char *szPassword1
= strtok (NULL
," ");
754 char *szPassword2
= strtok (NULL
," ");
756 if (!szAccount
||!szPassword1
|| !szPassword2
)
759 std::string account_name
= szAccount
;
760 if(!AccountMgr::normilizeString(account_name
))
762 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
763 SetSentErrorMessage(true);
767 uint32 targetAccountId
= accmgr
.GetId(account_name
);
768 if (!targetAccountId
)
770 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
771 SetSentErrorMessage(true);
775 uint32 targetSecurity
= accmgr
.GetSecurity(targetAccountId
);
777 /// m_session==NULL only for console
778 uint32 plSecurity
= m_session
? m_session
->GetSecurity() : SEC_CONSOLE
;
780 /// can set password only for target with less security
781 /// This is also reject self apply in fact
782 if (targetSecurity
>= plSecurity
)
784 SendSysMessage (LANG_YOURS_SECURITY_IS_LOW
);
785 SetSentErrorMessage (true);
789 if (strcmp(szPassword1
,szPassword2
))
791 SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH
);
792 SetSentErrorMessage (true);
796 AccountOpResult result
= accmgr
.ChangePassword(targetAccountId
, szPassword1
);
801 SendSysMessage(LANG_COMMAND_PASSWORD
);
803 case AOR_NAME_NOT_EXIST
:
804 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
805 SetSentErrorMessage(true);
807 case AOR_PASS_TOO_LONG
:
808 SendSysMessage(LANG_PASSWORD_TOO_LONG
);
809 SetSentErrorMessage(true);
812 SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD
);
813 SetSentErrorMessage(true);
820 bool ChatHandler::HandleAllowMovementCommand(const char* /*args*/)
822 if(sWorld
.getAllowMovement())
824 sWorld
.SetAllowMovement(false);
825 SendSysMessage(LANG_CREATURE_MOVE_DISABLED
);
829 sWorld
.SetAllowMovement(true);
830 SendSysMessage(LANG_CREATURE_MOVE_ENABLED
);
835 bool ChatHandler::HandleMaxSkillCommand(const char* /*args*/)
837 Player
* SelectedPlayer
= getSelectedPlayer();
840 SendSysMessage(LANG_NO_CHAR_SELECTED
);
841 SetSentErrorMessage(true);
845 // each skills that have max skill value dependent from level seted to current level max skill value
846 SelectedPlayer
->UpdateSkillsToMaxSkillsForLevel();
850 bool ChatHandler::HandleSetSkillCommand(const char* args
)
852 // number or [name] Shift-click form |color|Hskill:skill_id|h[name]|h|r
853 char* skill_p
= extractKeyFromLink((char*)args
,"Hskill");
857 char *level_p
= strtok (NULL
, " ");
862 char *max_p
= strtok (NULL
, " ");
864 int32 skill
= atoi(skill_p
);
868 PSendSysMessage(LANG_INVALID_SKILL_ID
, skill
);
869 SetSentErrorMessage(true);
873 int32 level
= atol (level_p
);
875 Player
* target
= getSelectedPlayer();
878 SendSysMessage(LANG_NO_CHAR_SELECTED
);
879 SetSentErrorMessage(true);
883 SkillLineEntry
const* sl
= sSkillLineStore
.LookupEntry(skill
);
886 PSendSysMessage(LANG_INVALID_SKILL_ID
, skill
);
887 SetSentErrorMessage(true);
891 if(!target
->GetSkillValue(skill
))
893 PSendSysMessage(LANG_SET_SKILL_ERROR
, target
->GetName(), skill
, sl
->name
[0]);
894 SetSentErrorMessage(true);
898 int32 max
= max_p
? atol (max_p
) : target
->GetPureMaxSkillValue(skill
);
900 if( level
<= 0 || level
> max
|| max
<= 0 )
903 target
->SetSkill(skill
, level
, max
);
904 PSendSysMessage(LANG_SET_SKILL
, skill
, sl
->name
[0], target
->GetName(), level
, max
);
909 bool ChatHandler::HandleUnLearnCommand(const char* args
)
914 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
915 uint32 min_id
= extractSpellIdFromLink((char*)args
);
919 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
920 char* tail
= strtok(NULL
,"");
922 uint32 max_id
= extractSpellIdFromLink(tail
);
926 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
932 std::swap(min_id
,max_id
);
937 Player
* target
= getSelectedPlayer();
940 SendSysMessage(LANG_NO_CHAR_SELECTED
);
941 SetSentErrorMessage(true);
945 for(uint32 spell
=min_id
;spell
<max_id
;spell
++)
947 if (target
->HasSpell(spell
))
948 target
->removeSpell(spell
);
950 SendSysMessage(LANG_FORGET_SPELL
);
956 bool ChatHandler::HandleCooldownCommand(const char* args
)
958 Player
* target
= getSelectedPlayer();
961 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
962 SetSentErrorMessage(true);
968 target
->RemoveAllSpellCooldown();
969 PSendSysMessage(LANG_REMOVEALL_COOLDOWN
, target
->GetName());
973 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
974 uint32 spell_id
= extractSpellIdFromLink((char*)args
);
978 if(!sSpellStore
.LookupEntry(spell_id
))
980 PSendSysMessage(LANG_UNKNOWN_SPELL
, target
==m_session
->GetPlayer() ? GetMangosString(LANG_YOU
) : target
->GetName());
981 SetSentErrorMessage(true);
985 WorldPacket
data( SMSG_CLEAR_COOLDOWN
, (4+8) );
986 data
<< uint32(spell_id
);
987 data
<< uint64(target
->GetGUID());
988 target
->GetSession()->SendPacket(&data
);
989 target
->RemoveSpellCooldown(spell_id
);
990 PSendSysMessage(LANG_REMOVE_COOLDOWN
, spell_id
, target
==m_session
->GetPlayer() ? GetMangosString(LANG_YOU
) : target
->GetName());
995 bool ChatHandler::HandleLearnAllCommand(const char* /*args*/)
997 static const char *allSpellList
[] =
1380 //"9036", problems with ghost state
1389 //"6718", phasing stealth, annoing for learn all case.
1602 while(strcmp(allSpellList
[loop
], "0"))
1604 uint32 spell
= atol((char*)allSpellList
[loop
++]);
1606 if (m_session
->GetPlayer()->HasSpell(spell
))
1609 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1610 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1612 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1616 m_session
->GetPlayer()->learnSpell(spell
);
1619 SendSysMessage(LANG_COMMAND_LEARN_MANY_SPELLS
);
1624 bool ChatHandler::HandleLearnAllGMCommand(const char* /*args*/)
1626 static const char *gmSpellList
[] =
1628 "24347", // Become A Fish, No Breath Bar
1629 "35132", // Visual Boom
1630 "38488", // Attack 4000-8000 AOE
1631 "38795", // Attack 2000 AOE + Slow Down 90%
1632 "15712", // Attack 200
1633 "1852", // GM Spell Silence
1636 "29878", // Kill My Self
1637 "26644", // More Kill
1639 "28550", //Invisible 24
1640 "23452", //Invisible + Target
1644 uint16 gmSpellIter
= 0;
1645 while( strcmp(gmSpellList
[gmSpellIter
], "0") )
1647 uint32 spell
= atol((char*)gmSpellList
[gmSpellIter
++]);
1649 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1650 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1652 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1656 m_session
->GetPlayer()->learnSpell(spell
);
1659 SendSysMessage(LANG_LEARNING_GM_SKILLS
);
1663 bool ChatHandler::HandleLearnAllMyClassCommand(const char* /*args*/)
1665 HandleLearnAllMySpellsCommand("");
1666 HandleLearnAllMyTalentsCommand("");
1670 bool ChatHandler::HandleLearnAllMySpellsCommand(const char* /*args*/)
1672 ChrClassesEntry
const* clsEntry
= sChrClassesStore
.LookupEntry(m_session
->GetPlayer()->getClass());
1675 uint32 family
= clsEntry
->spellfamily
;
1677 for (uint32 i
= 0; i
< sSpellStore
.GetNumRows(); i
++)
1679 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(i
);
1683 // skip wrong class/race skills
1684 if(!m_session
->GetPlayer()->IsSpellFitByClassAndRace(spellInfo
->Id
))
1687 // skip other spell families
1688 if( spellInfo
->SpellFamilyName
!= family
)
1691 //TODO: skip triggered spells
1693 // skip spells with first rank learned as talent (and all talents then also)
1694 uint32 first_rank
= spellmgr
.GetFirstSpellInChain(spellInfo
->Id
);
1695 if(GetTalentSpellCost(first_rank
) > 0 )
1698 // skip broken spells
1699 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1702 m_session
->GetPlayer()->learnSpell(i
);
1705 SendSysMessage(LANG_COMMAND_LEARN_CLASS_SPELLS
);
1709 static void learnAllHighRanks(Player
* player
, uint32 spellid
)
1711 SpellChainMapNext
const& nextMap
= spellmgr
.GetSpellChainNext();
1712 for(SpellChainMapNext::const_iterator itr
= nextMap
.lower_bound(spellid
); itr
!= nextMap
.upper_bound(spellid
); ++itr
)
1714 player
->learnSpell(itr
->second
);
1715 learnAllHighRanks(player
,itr
->second
);
1719 bool ChatHandler::HandleLearnAllMyTalentsCommand(const char* /*args*/)
1721 Player
* player
= m_session
->GetPlayer();
1722 uint32 classMask
= player
->getClassMask();
1724 for (uint32 i
= 0; i
< sTalentStore
.GetNumRows(); i
++)
1726 TalentEntry
const *talentInfo
= sTalentStore
.LookupEntry(i
);
1730 TalentTabEntry
const *talentTabInfo
= sTalentTabStore
.LookupEntry( talentInfo
->TalentTab
);
1734 if( (classMask
& talentTabInfo
->ClassMask
) == 0 )
1737 // search highest talent rank
1740 for(; rank
>= 0; --rank
)
1742 if(talentInfo
->RankID
[rank
]!=0)
1744 spellid
= talentInfo
->RankID
[rank
];
1749 if(!spellid
) // ??? none spells in telent
1752 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spellid
);
1753 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1756 // learn highest rank of talent
1757 player
->learnSpell(spellid
);
1759 // and learn all non-talent spell ranks (recursive by tree)
1760 learnAllHighRanks(player
,spellid
);
1763 SendSysMessage(LANG_COMMAND_LEARN_CLASS_TALENTS
);
1767 bool ChatHandler::HandleLearnAllLangCommand(const char* /*args*/)
1769 // skipping UNIVERSAL language (0)
1770 for(int i
= 1; i
< LANGUAGES_COUNT
; ++i
)
1771 m_session
->GetPlayer()->learnSpell(lang_description
[i
].spell_id
);
1773 SendSysMessage(LANG_COMMAND_LEARN_ALL_LANG
);
1777 bool ChatHandler::HandleLearnAllDefaultCommand(const char* args
)
1779 char* pName
= strtok((char*)args
, "");
1780 Player
*player
= NULL
;
1783 std::string name
= pName
;
1785 if(!normalizePlayerName(name
))
1787 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1788 SetSentErrorMessage(true);
1792 player
= objmgr
.GetPlayer(name
.c_str());
1795 player
= getSelectedPlayer();
1799 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1800 SetSentErrorMessage(true);
1804 player
->learnDefaultSpells();
1805 player
->learnQuestRewardedSpells();
1807 PSendSysMessage(LANG_COMMAND_LEARN_ALL_DEFAULT_AND_QUEST
,player
->GetName());
1811 bool ChatHandler::HandleLearnCommand(const char* args
)
1813 Player
* targetPlayer
= getSelectedPlayer();
1817 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1818 SetSentErrorMessage(true);
1822 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1823 uint32 spell
= extractSpellIdFromLink((char*)args
);
1824 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
1827 if (targetPlayer
->HasSpell(spell
))
1829 if(targetPlayer
== m_session
->GetPlayer())
1830 SendSysMessage(LANG_YOU_KNOWN_SPELL
);
1832 PSendSysMessage(LANG_TARGET_KNOWN_SPELL
,targetPlayer
->GetName());
1833 SetSentErrorMessage(true);
1837 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1838 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1840 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1841 SetSentErrorMessage(true);
1845 targetPlayer
->learnSpell(spell
);
1850 bool ChatHandler::HandleAddItemCommand(const char* args
)
1857 if(args
[0]=='[') // [name] manual form
1859 char* citemName
= citemName
= strtok((char*)args
, "]");
1861 if(citemName
&& citemName
[0])
1863 std::string itemName
= citemName
+1;
1864 WorldDatabase
.escape_string(itemName
);
1865 QueryResult
*result
= WorldDatabase
.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName
.c_str());
1868 PSendSysMessage(LANG_COMMAND_COULDNOTFIND
, citemName
+1);
1869 SetSentErrorMessage(true);
1872 itemId
= result
->Fetch()->GetUInt16();
1878 else // item_id or [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r
1880 char* cId
= extractKeyFromLink((char*)args
,"Hitem");
1886 char* ccount
= strtok(NULL
, " ");
1891 count
= strtol(ccount
, NULL
, 10);
1896 Player
* pl
= m_session
->GetPlayer();
1897 Player
* plTarget
= getSelectedPlayer();
1901 sLog
.outDetail(GetMangosString(LANG_ADDITEM
), itemId
, count
);
1903 ItemPrototype
const *pProto
= objmgr
.GetItemPrototype(itemId
);
1906 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, itemId
);
1907 SetSentErrorMessage(true);
1914 plTarget
->DestroyItemCount(itemId
, -count
, true, false);
1915 PSendSysMessage(LANG_REMOVEITEM
, itemId
, -count
, plTarget
->GetName());
1920 uint32 noSpaceForCount
= 0;
1922 // check space and find places
1923 ItemPosCountVec dest
;
1924 uint8 msg
= plTarget
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, itemId
, count
, &noSpaceForCount
);
1925 if( msg
!= EQUIP_ERR_OK
) // convert to possible store amount
1926 count
-= noSpaceForCount
;
1928 if( count
== 0 || dest
.empty()) // can't add any
1930 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, itemId
, noSpaceForCount
);
1931 SetSentErrorMessage(true);
1935 Item
* item
= plTarget
->StoreNewItem( dest
, itemId
, true, Item::GenerateItemRandomPropertyId(itemId
));
1937 // remove binding (let GM give it to another player later)
1939 for(ItemPosCountVec::const_iterator itr
= dest
.begin(); itr
!= dest
.end(); ++itr
)
1940 if(Item
* item1
= pl
->GetItemByPos(itr
->pos
))
1941 item1
->SetBinding( false );
1943 if(count
> 0 && item
)
1945 pl
->SendNewItem(item
,count
,false,true);
1947 plTarget
->SendNewItem(item
,count
,true,false);
1950 if(noSpaceForCount
> 0)
1951 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, itemId
, noSpaceForCount
);
1956 bool ChatHandler::HandleAddItemSetCommand(const char* args
)
1961 char* cId
= extractKeyFromLink((char*)args
,"Hitemset"); // number or [name] Shift-click form |color|Hitemset:itemset_id|h[name]|h|r
1965 uint32 itemsetId
= atol(cId
);
1967 // prevent generation all items with itemset field value '0'
1970 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND
,itemsetId
);
1971 SetSentErrorMessage(true);
1975 Player
* pl
= m_session
->GetPlayer();
1976 Player
* plTarget
= getSelectedPlayer();
1980 sLog
.outDetail(GetMangosString(LANG_ADDITEMSET
), itemsetId
);
1982 QueryResult
*result
= WorldDatabase
.PQuery("SELECT entry FROM item_template WHERE itemset = %u",itemsetId
);
1986 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND
,itemsetId
);
1988 SetSentErrorMessage(true);
1994 Field
*fields
= result
->Fetch();
1995 uint32 itemId
= fields
[0].GetUInt32();
1997 ItemPosCountVec dest
;
1998 uint8 msg
= plTarget
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, itemId
, 1 );
1999 if( msg
== EQUIP_ERR_OK
)
2001 Item
* item
= plTarget
->StoreNewItem( dest
, itemId
, true);
2003 // remove binding (let GM give it to another player later)
2005 item
->SetBinding( false );
2007 pl
->SendNewItem(item
,1,false,true);
2009 plTarget
->SendNewItem(item
,1,true,false);
2013 pl
->SendEquipError( msg
, NULL
, NULL
);
2014 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, itemId
, 1);
2017 }while( result
->NextRow() );
2024 bool ChatHandler::HandleListItemCommand(const char* args
)
2029 char* cId
= extractKeyFromLink((char*)args
,"Hitem");
2033 uint32 item_id
= atol(cId
);
2036 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
2037 SetSentErrorMessage(true);
2041 ItemPrototype
const* itemProto
= objmgr
.GetItemPrototype(item_id
);
2044 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
2045 SetSentErrorMessage(true);
2049 char* c_count
= strtok(NULL
, " ");
2050 int count
= c_count
? atol(c_count
) : 10;
2055 QueryResult
*result
;
2058 uint32 inv_count
= 0;
2059 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM character_inventory WHERE item_template='%u'",item_id
);
2062 inv_count
= (*result
)[0].GetUInt32();
2066 result
=CharacterDatabase
.PQuery(
2068 "SELECT ci.item, cibag.slot AS bag, ci.slot, ci.guid, characters.account,characters.name "
2069 "FROM character_inventory AS ci LEFT JOIN character_inventory AS cibag ON (cibag.item=ci.bag),characters "
2070 "WHERE ci.item_template='%u' AND ci.guid = characters.guid LIMIT %u ",
2071 item_id
,uint32(count
));
2077 Field
*fields
= result
->Fetch();
2078 uint32 item_guid
= fields
[0].GetUInt32();
2079 uint32 item_bag
= fields
[1].GetUInt32();
2080 uint32 item_slot
= fields
[2].GetUInt32();
2081 uint32 owner_guid
= fields
[3].GetUInt32();
2082 uint32 owner_acc
= fields
[4].GetUInt32();
2083 std::string owner_name
= fields
[5].GetCppString();
2085 char const* item_pos
= 0;
2086 if(Player::IsEquipmentPos(item_bag
,item_slot
))
2087 item_pos
= "[equipped]";
2088 else if(Player::IsInventoryPos(item_bag
,item_slot
))
2089 item_pos
= "[in inventory]";
2090 else if(Player::IsBankPos(item_bag
,item_slot
))
2091 item_pos
= "[in bank]";
2095 PSendSysMessage(LANG_ITEMLIST_SLOT
,
2096 item_guid
,owner_name
.c_str(),owner_guid
,owner_acc
,item_pos
);
2097 } while (result
->NextRow());
2099 int64 res_count
= result
->GetRowCount();
2103 if(count
> res_count
)
2110 uint32 mail_count
= 0;
2111 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM mail_items WHERE item_template='%u'", item_id
);
2114 mail_count
= (*result
)[0].GetUInt32();
2120 result
=CharacterDatabase
.PQuery(
2122 "SELECT mail_items.item_guid, mail.sender, mail.receiver, char_s.account, char_s.name, char_r.account, char_r.name "
2123 "FROM mail,mail_items,characters as char_s,characters as char_r "
2124 "WHERE mail_items.item_template='%u' AND char_s.guid = mail.sender AND char_r.guid = mail.receiver AND mail.id=mail_items.mail_id LIMIT %u",
2125 item_id
,uint32(count
));
2134 Field
*fields
= result
->Fetch();
2135 uint32 item_guid
= fields
[0].GetUInt32();
2136 uint32 item_s
= fields
[1].GetUInt32();
2137 uint32 item_r
= fields
[2].GetUInt32();
2138 uint32 item_s_acc
= fields
[3].GetUInt32();
2139 std::string item_s_name
= fields
[4].GetCppString();
2140 uint32 item_r_acc
= fields
[5].GetUInt32();
2141 std::string item_r_name
= fields
[6].GetCppString();
2143 char const* item_pos
= "[in mail]";
2145 PSendSysMessage(LANG_ITEMLIST_MAIL
,
2146 item_guid
,item_s_name
.c_str(),item_s
,item_s_acc
,item_r_name
.c_str(),item_r
,item_r_acc
,item_pos
);
2147 } while (result
->NextRow());
2149 int64 res_count
= result
->GetRowCount();
2153 if(count
> res_count
)
2160 uint32 auc_count
= 0;
2161 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM auctionhouse WHERE item_template='%u'",item_id
);
2164 auc_count
= (*result
)[0].GetUInt32();
2170 result
=CharacterDatabase
.PQuery(
2172 "SELECT auctionhouse.itemguid, auctionhouse.itemowner, characters.account, characters.name "
2173 "FROM auctionhouse,characters WHERE auctionhouse.item_template='%u' AND characters.guid = auctionhouse.itemowner LIMIT %u",
2174 item_id
,uint32(count
));
2183 Field
*fields
= result
->Fetch();
2184 uint32 item_guid
= fields
[0].GetUInt32();
2185 uint32 owner
= fields
[1].GetUInt32();
2186 uint32 owner_acc
= fields
[2].GetUInt32();
2187 std::string owner_name
= fields
[3].GetCppString();
2189 char const* item_pos
= "[in auction]";
2191 PSendSysMessage(LANG_ITEMLIST_AUCTION
, item_guid
, owner_name
.c_str(), owner
, owner_acc
,item_pos
);
2192 } while (result
->NextRow());
2198 uint32 guild_count
= 0;
2199 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_entry) FROM guild_bank_item WHERE item_entry='%u'",item_id
);
2202 guild_count
= (*result
)[0].GetUInt32();
2206 result
=CharacterDatabase
.PQuery(
2208 "SELECT gi.item_guid, gi.guildid, guild.name "
2209 "FROM guild_bank_item AS gi, guild WHERE gi.item_entry='%u' AND gi.guildid = guild.guildid LIMIT %u ",
2210 item_id
,uint32(count
));
2216 Field
*fields
= result
->Fetch();
2217 uint32 item_guid
= fields
[0].GetUInt32();
2218 uint32 guild_guid
= fields
[1].GetUInt32();
2219 std::string guild_name
= fields
[2].GetCppString();
2221 char const* item_pos
= "[in guild bank]";
2223 PSendSysMessage(LANG_ITEMLIST_GUILD
,item_guid
,guild_name
.c_str(),guild_guid
,item_pos
);
2224 } while (result
->NextRow());
2226 int64 res_count
= result
->GetRowCount();
2230 if(count
> res_count
)
2236 if(inv_count
+mail_count
+auc_count
+guild_count
== 0)
2238 SendSysMessage(LANG_COMMAND_NOITEMFOUND
);
2239 SetSentErrorMessage(true);
2243 PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE
,item_id
,inv_count
+mail_count
+auc_count
+guild_count
,inv_count
,mail_count
,auc_count
,guild_count
);
2248 bool ChatHandler::HandleListObjectCommand(const char* args
)
2253 // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2254 char* cId
= extractKeyFromLink((char*)args
,"Hgameobject_entry");
2258 uint32 go_id
= atol(cId
);
2261 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID
, go_id
);
2262 SetSentErrorMessage(true);
2266 GameObjectInfo
const * gInfo
= objmgr
.GetGameObjectInfo(go_id
);
2269 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID
, go_id
);
2270 SetSentErrorMessage(true);
2274 char* c_count
= strtok(NULL
, " ");
2275 int count
= c_count
? atol(c_count
) : 10;
2280 QueryResult
*result
;
2282 uint32 obj_count
= 0;
2283 result
=WorldDatabase
.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'",go_id
);
2286 obj_count
= (*result
)[0].GetUInt32();
2292 Player
* pl
= m_session
->GetPlayer();
2293 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",
2294 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(),go_id
,uint32(count
));
2297 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map FROM gameobject WHERE id = '%u' LIMIT %u",
2298 go_id
,uint32(count
));
2304 Field
*fields
= result
->Fetch();
2305 uint32 guid
= fields
[0].GetUInt32();
2306 float x
= fields
[1].GetFloat();
2307 float y
= fields
[2].GetFloat();
2308 float z
= fields
[3].GetFloat();
2309 int mapid
= fields
[4].GetUInt16();
2312 PSendSysMessage(LANG_GO_LIST_CHAT
, guid
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2314 PSendSysMessage(LANG_GO_LIST_CONSOLE
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2315 } while (result
->NextRow());
2320 PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE
,go_id
,obj_count
);
2324 bool ChatHandler::HandleNearObjectCommand(const char* args
)
2326 float distance
= (!*args
) ? 10 : atol(args
);
2329 Player
* pl
= m_session
->GetPlayer();
2330 QueryResult
*result
= WorldDatabase
.PQuery("SELECT guid, id, position_x, position_y, position_z, map, "
2331 "(POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ "
2332 "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_",
2333 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(),
2334 pl
->GetMapId(),pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(),distance
*distance
);
2340 Field
*fields
= result
->Fetch();
2341 uint32 guid
= fields
[0].GetUInt32();
2342 uint32 entry
= fields
[1].GetUInt32();
2343 float x
= fields
[2].GetFloat();
2344 float y
= fields
[3].GetFloat();
2345 float z
= fields
[4].GetFloat();
2346 int mapid
= fields
[5].GetUInt16();
2348 GameObjectInfo
const * gInfo
= objmgr
.GetGameObjectInfo(entry
);
2353 PSendSysMessage(LANG_GO_LIST_CHAT
, guid
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2356 } while (result
->NextRow());
2361 PSendSysMessage(LANG_COMMAND_NEAROBJMESSAGE
,distance
,count
);
2365 bool ChatHandler::HandleListCreatureCommand(const char* args
)
2370 // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
2371 char* cId
= extractKeyFromLink((char*)args
,"Hcreature_entry");
2375 uint32 cr_id
= atol(cId
);
2378 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID
, cr_id
);
2379 SetSentErrorMessage(true);
2383 CreatureInfo
const* cInfo
= objmgr
.GetCreatureTemplate(cr_id
);
2386 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID
, cr_id
);
2387 SetSentErrorMessage(true);
2391 char* c_count
= strtok(NULL
, " ");
2392 int count
= c_count
? atol(c_count
) : 10;
2397 QueryResult
*result
;
2399 uint32 cr_count
= 0;
2400 result
=WorldDatabase
.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'",cr_id
);
2403 cr_count
= (*result
)[0].GetUInt32();
2409 Player
* pl
= m_session
->GetPlayer();
2410 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",
2411 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(), cr_id
,uint32(count
));
2414 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '%u' LIMIT %u",
2415 cr_id
,uint32(count
));
2421 Field
*fields
= result
->Fetch();
2422 uint32 guid
= fields
[0].GetUInt32();
2423 float x
= fields
[1].GetFloat();
2424 float y
= fields
[2].GetFloat();
2425 float z
= fields
[3].GetFloat();
2426 int mapid
= fields
[4].GetUInt16();
2429 PSendSysMessage(LANG_CREATURE_LIST_CHAT
, guid
, guid
, cInfo
->Name
, x
, y
, z
, mapid
);
2431 PSendSysMessage(LANG_CREATURE_LIST_CONSOLE
, guid
, cInfo
->Name
, x
, y
, z
, mapid
);
2432 } while (result
->NextRow());
2437 PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE
,cr_id
,cr_count
);
2441 bool ChatHandler::HandleLookupItemCommand(const char* args
)
2446 std::string namepart
= args
;
2447 std::wstring wnamepart
;
2449 // converting string that we try to find to lower case
2450 if(!Utf8toWStr(namepart
,wnamepart
))
2453 wstrToLower(wnamepart
);
2457 // Search in `item_template`
2458 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
2460 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
2464 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2467 ItemLocale
const *il
= objmgr
.GetItemLocale(pProto
->ItemId
);
2470 if (il
->Name
.size() > loc_idx
&& !il
->Name
[loc_idx
].empty())
2472 std::string name
= il
->Name
[loc_idx
];
2474 if (Utf8FitTo(name
, wnamepart
))
2477 PSendSysMessage(LANG_ITEM_LIST_CHAT
, id
, id
, name
.c_str());
2479 PSendSysMessage(LANG_ITEM_LIST_CONSOLE
, id
, name
.c_str());
2487 std::string name
= pProto
->Name1
;
2491 if (Utf8FitTo(name
, wnamepart
))
2494 PSendSysMessage(LANG_ITEM_LIST_CHAT
, id
, id
, name
.c_str());
2496 PSendSysMessage(LANG_ITEM_LIST_CONSOLE
, id
, name
.c_str());
2502 SendSysMessage(LANG_COMMAND_NOITEMFOUND
);
2507 bool ChatHandler::HandleLookupItemSetCommand(const char* args
)
2512 std::string namepart
= args
;
2513 std::wstring wnamepart
;
2515 if(!Utf8toWStr(namepart
,wnamepart
))
2518 // converting string that we try to find to lower case
2519 wstrToLower( wnamepart
);
2521 uint32 counter
= 0; // Counter for figure out that we found smth.
2523 // Search in ItemSet.dbc
2524 for (uint32 id
= 0; id
< sItemSetStore
.GetNumRows(); id
++)
2526 ItemSetEntry
const *set
= sItemSetStore
.LookupEntry(id
);
2529 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
2530 std::string name
= set
->name
[loc
];
2534 if (!Utf8FitTo(name
, wnamepart
))
2537 for(; loc
< MAX_LOCALE
; ++loc
)
2539 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
2542 name
= set
->name
[loc
];
2546 if (Utf8FitTo(name
, wnamepart
))
2551 if(loc
< MAX_LOCALE
)
2553 // send item set in "id - [namedlink locale]" format
2555 PSendSysMessage(LANG_ITEMSET_LIST_CHAT
,id
,id
,name
.c_str(),localeNames
[loc
]);
2557 PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE
,id
,name
.c_str(),localeNames
[loc
]);
2562 if (counter
== 0) // if counter == 0 then we found nth
2563 SendSysMessage(LANG_COMMAND_NOITEMSETFOUND
);
2567 bool ChatHandler::HandleLookupSkillCommand(const char* args
)
2572 // can be NULL in console call
2573 Player
* target
= getSelectedPlayer();
2575 std::string namepart
= args
;
2576 std::wstring wnamepart
;
2578 if(!Utf8toWStr(namepart
,wnamepart
))
2581 // converting string that we try to find to lower case
2582 wstrToLower( wnamepart
);
2584 uint32 counter
= 0; // Counter for figure out that we found smth.
2586 // Search in SkillLine.dbc
2587 for (uint32 id
= 0; id
< sSkillLineStore
.GetNumRows(); id
++)
2589 SkillLineEntry
const *skillInfo
= sSkillLineStore
.LookupEntry(id
);
2592 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
2593 std::string name
= skillInfo
->name
[loc
];
2597 if (!Utf8FitTo(name
, wnamepart
))
2600 for(; loc
< MAX_LOCALE
; ++loc
)
2602 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
2605 name
= skillInfo
->name
[loc
];
2609 if (Utf8FitTo(name
, wnamepart
))
2614 if(loc
< MAX_LOCALE
)
2616 char const* knownStr
= "";
2617 if(target
&& target
->HasSkill(id
))
2618 knownStr
= GetMangosString(LANG_KNOWN
);
2620 // send skill in "id - [namedlink locale]" format
2622 PSendSysMessage(LANG_SKILL_LIST_CHAT
,id
,id
,name
.c_str(),localeNames
[loc
],knownStr
);
2624 PSendSysMessage(LANG_SKILL_LIST_CONSOLE
,id
,name
.c_str(),localeNames
[loc
],knownStr
);
2630 if (counter
== 0) // if counter == 0 then we found nth
2631 SendSysMessage(LANG_COMMAND_NOSKILLFOUND
);
2635 bool ChatHandler::HandleLookupSpellCommand(const char* args
)
2640 // can be NULL at console call
2641 Player
* target
= getSelectedPlayer();
2643 std::string namepart
= args
;
2644 std::wstring wnamepart
;
2646 if(!Utf8toWStr(namepart
,wnamepart
))
2649 // converting string that we try to find to lower case
2650 wstrToLower( wnamepart
);
2652 uint32 counter
= 0; // Counter for figure out that we found smth.
2654 // Search in Spell.dbc
2655 for (uint32 id
= 0; id
< sSpellStore
.GetNumRows(); id
++)
2657 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(id
);
2660 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
2661 std::string name
= spellInfo
->SpellName
[loc
];
2665 if (!Utf8FitTo(name
, wnamepart
))
2668 for(; loc
< MAX_LOCALE
; ++loc
)
2670 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
2673 name
= spellInfo
->SpellName
[loc
];
2677 if (Utf8FitTo(name
, wnamepart
))
2682 if(loc
< MAX_LOCALE
)
2684 bool known
= target
&& target
->HasSpell(id
);
2685 bool learn
= (spellInfo
->Effect
[0] == SPELL_EFFECT_LEARN_SPELL
);
2687 uint32 telentCost
= GetTalentSpellCost(id
);
2689 bool talent
= (telentCost
> 0);
2690 bool passive
= IsPassiveSpell(id
);
2691 bool active
= target
&& (target
->HasAura(id
,0) || target
->HasAura(id
,1) || target
->HasAura(id
,2));
2693 // unit32 used to prevent interpreting uint8 as char at output
2694 // find rank of learned spell for learning spell, or talent rank
2695 uint32 rank
= telentCost
? telentCost
: spellmgr
.GetSpellRank(learn
? spellInfo
->EffectTriggerSpell
[0] : id
);
2697 // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
2698 std::ostringstream ss
;
2700 ss
<< id
<< " - |cffffffff|Hspell:" << id
<< "|h[" << name
;
2702 ss
<< id
<< " - " << name
;
2704 // include rank in link name
2706 ss
<< GetMangosString(LANG_SPELL_RANK
) << rank
;
2709 ss
<< " " << localeNames
[loc
] << "]|h|r";
2711 ss
<< " " << localeNames
[loc
];
2714 ss
<< GetMangosString(LANG_TALENT
);
2716 ss
<< GetMangosString(LANG_PASSIVE
);
2718 ss
<< GetMangosString(LANG_LEARN
);
2720 ss
<< GetMangosString(LANG_KNOWN
);
2722 ss
<< GetMangosString(LANG_ACTIVE
);
2724 SendSysMessage(ss
.str().c_str());
2730 if (counter
== 0) // if counter == 0 then we found nth
2731 SendSysMessage(LANG_COMMAND_NOSPELLFOUND
);
2735 bool ChatHandler::HandleLookupQuestCommand(const char* args
)
2740 // can be NULL at console call
2741 Player
* target
= getSelectedPlayer();
2743 std::string namepart
= args
;
2744 std::wstring wnamepart
;
2746 // converting string that we try to find to lower case
2747 if(!Utf8toWStr(namepart
,wnamepart
))
2750 wstrToLower(wnamepart
);
2752 uint32 counter
= 0 ;
2754 ObjectMgr::QuestMap
const& qTemplates
= objmgr
.GetQuestTemplates();
2755 for (ObjectMgr::QuestMap::const_iterator iter
= qTemplates
.begin(); iter
!= qTemplates
.end(); ++iter
)
2757 Quest
* qinfo
= iter
->second
;
2759 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2762 QuestLocale
const *il
= objmgr
.GetQuestLocale(qinfo
->GetQuestId());
2765 if (il
->Title
.size() > loc_idx
&& !il
->Title
[loc_idx
].empty())
2767 std::string title
= il
->Title
[loc_idx
];
2769 if (Utf8FitTo(title
, wnamepart
))
2771 char const* statusStr
= "";
2775 QuestStatus status
= target
->GetQuestStatus(qinfo
->GetQuestId());
2777 if(status
== QUEST_STATUS_COMPLETE
)
2779 if(target
->GetQuestRewardStatus(qinfo
->GetQuestId()))
2780 statusStr
= GetMangosString(LANG_COMMAND_QUEST_REWARDED
);
2782 statusStr
= GetMangosString(LANG_COMMAND_QUEST_COMPLETE
);
2784 else if(status
== QUEST_STATUS_INCOMPLETE
)
2785 statusStr
= GetMangosString(LANG_COMMAND_QUEST_ACTIVE
);
2789 PSendSysMessage(LANG_QUEST_LIST_CHAT
,qinfo
->GetQuestId(),qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2791 PSendSysMessage(LANG_QUEST_LIST_CONSOLE
,qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2799 std::string title
= qinfo
->GetTitle();
2803 if (Utf8FitTo(title
, wnamepart
))
2805 char const* statusStr
= "";
2809 QuestStatus status
= target
->GetQuestStatus(qinfo
->GetQuestId());
2811 if(status
== QUEST_STATUS_COMPLETE
)
2813 if(target
->GetQuestRewardStatus(qinfo
->GetQuestId()))
2814 statusStr
= GetMangosString(LANG_COMMAND_QUEST_REWARDED
);
2816 statusStr
= GetMangosString(LANG_COMMAND_QUEST_COMPLETE
);
2818 else if(status
== QUEST_STATUS_INCOMPLETE
)
2819 statusStr
= GetMangosString(LANG_COMMAND_QUEST_ACTIVE
);
2823 PSendSysMessage(LANG_QUEST_LIST_CHAT
,qinfo
->GetQuestId(),qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2825 PSendSysMessage(LANG_QUEST_LIST_CONSOLE
,qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2832 SendSysMessage(LANG_COMMAND_NOQUESTFOUND
);
2837 bool ChatHandler::HandleLookupCreatureCommand(const char* args
)
2842 std::string namepart
= args
;
2843 std::wstring wnamepart
;
2845 // converting string that we try to find to lower case
2846 if (!Utf8toWStr (namepart
,wnamepart
))
2849 wstrToLower (wnamepart
);
2853 for (uint32 id
= 0; id
< sCreatureStorage
.MaxEntry
; ++id
)
2855 CreatureInfo
const* cInfo
= sCreatureStorage
.LookupEntry
<CreatureInfo
> (id
);
2859 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2862 CreatureLocale
const *cl
= objmgr
.GetCreatureLocale (id
);
2865 if (cl
->Name
.size() > loc_idx
&& !cl
->Name
[loc_idx
].empty ())
2867 std::string name
= cl
->Name
[loc_idx
];
2869 if (Utf8FitTo (name
, wnamepart
))
2872 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str ());
2874 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE
, id
, name
.c_str ());
2882 std::string name
= cInfo
->Name
;
2886 if (Utf8FitTo(name
, wnamepart
))
2889 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str ());
2891 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE
, id
, name
.c_str ());
2897 SendSysMessage (LANG_COMMAND_NOCREATUREFOUND
);
2902 bool ChatHandler::HandleLookupObjectCommand(const char* args
)
2907 std::string namepart
= args
;
2908 std::wstring wnamepart
;
2910 // converting string that we try to find to lower case
2911 if(!Utf8toWStr(namepart
,wnamepart
))
2914 wstrToLower(wnamepart
);
2918 for (uint32 id
= 0; id
< sGOStorage
.MaxEntry
; id
++ )
2920 GameObjectInfo
const* gInfo
= sGOStorage
.LookupEntry
<GameObjectInfo
>(id
);
2924 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2927 GameObjectLocale
const *gl
= objmgr
.GetGameObjectLocale(id
);
2930 if (gl
->Name
.size() > loc_idx
&& !gl
->Name
[loc_idx
].empty())
2932 std::string name
= gl
->Name
[loc_idx
];
2934 if (Utf8FitTo(name
, wnamepart
))
2937 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT
, id
, id
, name
.c_str());
2939 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE
, id
, name
.c_str());
2947 std::string name
= gInfo
->name
;
2951 if(Utf8FitTo(name
, wnamepart
))
2954 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT
, id
, id
, name
.c_str());
2956 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE
, id
, name
.c_str());
2962 SendSysMessage(LANG_COMMAND_NOGAMEOBJECTFOUND
);
2967 /** \brief GM command level 3 - Create a guild.
2969 * This command allows a GM (level 3) to create a guild.
2971 * The "args" parameter contains the name of the guild leader
2972 * and then the name of the guild.
2975 bool ChatHandler::HandleGuildCreateCommand(const char* args
)
2981 char *lname
= strtok ((char*)args
, " ");
2982 char *gname
= strtok (NULL
, "");
2989 SendSysMessage (LANG_INSERT_GUILD_NAME
);
2990 SetSentErrorMessage (true);
2994 std::string guildname
= gname
;
2996 Player
* player
= ObjectAccessor::Instance ().FindPlayerByName (lname
);
2999 SendSysMessage (LANG_PLAYER_NOT_FOUND
);
3000 SetSentErrorMessage (true);
3004 if (player
->GetGuildId())
3006 SendSysMessage (LANG_PLAYER_IN_GUILD
);
3010 Guild
*guild
= new Guild
;
3011 if (!guild
->create (player
->GetGUID (),guildname
))
3014 SendSysMessage (LANG_GUILD_NOT_CREATED
);
3015 SetSentErrorMessage (true);
3019 objmgr
.AddGuild (guild
);
3023 bool ChatHandler::HandleGuildInviteCommand(const char *args
)
3028 char* par1
= strtok ((char*)args
, " ");
3029 char* par2
= strtok (NULL
, "");
3033 std::string glName
= par2
;
3034 Guild
* targetGuild
= objmgr
.GetGuildByName (glName
);
3038 std::string plName
= par1
;
3039 if (!normalizePlayerName (plName
))
3041 SendSysMessage (LANG_PLAYER_NOT_FOUND
);
3042 SetSentErrorMessage (true);
3047 if (Player
* targetPlayer
= ObjectAccessor::Instance ().FindPlayerByName (plName
.c_str ()))
3048 plGuid
= targetPlayer
->GetGUID ();
3050 plGuid
= objmgr
.GetPlayerGUIDByName (plName
.c_str ());
3055 // players's guild membership checked in AddMember before add
3056 if (!targetGuild
->AddMember (plGuid
,targetGuild
->GetLowestRank ()))
3062 bool ChatHandler::HandleGuildUninviteCommand(const char *args
)
3067 char* par1
= strtok ((char*)args
, " ");
3071 std::string plName
= par1
;
3072 if (!normalizePlayerName (plName
))
3074 SendSysMessage (LANG_PLAYER_NOT_FOUND
);
3075 SetSentErrorMessage (true);
3081 if (Player
* targetPlayer
= ObjectAccessor::Instance ().FindPlayerByName (plName
.c_str ()))
3083 plGuid
= targetPlayer
->GetGUID ();
3084 glId
= targetPlayer
->GetGuildId ();
3088 plGuid
= objmgr
.GetPlayerGUIDByName (plName
.c_str ());
3089 glId
= Player::GetGuildIdFromDB (plGuid
);
3092 if (!plGuid
|| !glId
)
3095 Guild
* targetGuild
= objmgr
.GetGuildById (glId
);
3099 targetGuild
->DelMember (plGuid
);
3104 bool ChatHandler::HandleGuildRankCommand(const char *args
)
3109 char* par1
= strtok ((char*)args
, " ");
3110 char* par2
= strtok (NULL
, " ");
3113 std::string plName
= par1
;
3114 if (!normalizePlayerName (plName
))
3116 SendSysMessage (LANG_PLAYER_NOT_FOUND
);
3117 SetSentErrorMessage (true);
3123 if (Player
* targetPlayer
= ObjectAccessor::Instance ().FindPlayerByName (plName
.c_str ()))
3125 plGuid
= targetPlayer
->GetGUID ();
3126 glId
= targetPlayer
->GetGuildId ();
3130 plGuid
= objmgr
.GetPlayerGUIDByName (plName
.c_str ());
3131 glId
= Player::GetGuildIdFromDB (plGuid
);
3134 if (!plGuid
|| !glId
)
3137 Guild
* targetGuild
= objmgr
.GetGuildById (glId
);
3141 uint32 newrank
= uint32 (atoi (par2
));
3142 if (newrank
> targetGuild
->GetLowestRank ())
3145 targetGuild
->ChangeRank (plGuid
,newrank
);
3150 bool ChatHandler::HandleGuildDeleteCommand(const char* args
)
3155 char* par1
= strtok ((char*)args
, " ");
3159 std::string gld
= par1
;
3161 Guild
* targetGuild
= objmgr
.GetGuildByName (gld
);
3165 targetGuild
->Disband ();
3170 bool ChatHandler::HandleGetDistanceCommand(const char* /*args*/)
3172 Unit
* pUnit
= getSelectedUnit();
3176 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3177 SetSentErrorMessage(true);
3181 PSendSysMessage(LANG_DISTANCE
, m_session
->GetPlayer()->GetDistance(pUnit
),m_session
->GetPlayer()->GetDistance2d(pUnit
));
3188 bool ChatHandler::HandleAddWeaponCommand(const char* /*args*/)
3193 uint64 guid = m_session->GetPlayer()->GetSelection();
3196 SendSysMessage(LANG_NO_SELECTION);
3200 Creature *pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
3204 SendSysMessage(LANG_SELECT_CREATURE);
3208 char* pSlotID = strtok((char*)args, " ");
3212 char* pItemID = strtok(NULL, " ");
3216 uint32 ItemID = atoi(pItemID);
3217 uint32 SlotID = atoi(pSlotID);
3219 ItemPrototype* tmpItem = objmgr.GetItemPrototype(ItemID);
3227 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID);
3231 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID);
3235 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID);
3239 PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST,SlotID);
3245 PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT,ItemID,tmpItem->Name1,SlotID);
3250 PSendSysMessage(LANG_ITEM_NOT_FOUND,ItemID);
3257 bool ChatHandler::HandleDieCommand(const char* /*args*/)
3259 Unit
* target
= getSelectedUnit();
3261 if(!target
|| !m_session
->GetPlayer()->GetSelection())
3263 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3264 SetSentErrorMessage(true);
3268 if( target
->isAlive() )
3270 m_session
->GetPlayer()->DealDamage(target
, target
->GetHealth(), NULL
, DIRECT_DAMAGE
, SPELL_SCHOOL_MASK_NORMAL
, NULL
, false);
3276 bool ChatHandler::HandleDamageCommand(const char * args
)
3281 Unit
* target
= getSelectedUnit();
3283 if(!target
|| !m_session
->GetPlayer()->GetSelection())
3285 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3286 SetSentErrorMessage(true);
3290 if( !target
->isAlive() )
3293 char* damageStr
= strtok((char*)args
, " ");
3297 int32 damage
= atoi((char*)damageStr
);
3301 char* schoolStr
= strtok((char*)NULL
, " ");
3303 // flat melee damage without resistence/etc reduction
3306 m_session
->GetPlayer()->DealDamage(target
, damage
, NULL
, DIRECT_DAMAGE
, SPELL_SCHOOL_MASK_NORMAL
, NULL
, false);
3307 m_session
->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2
, target
, 1, SPELL_SCHOOL_MASK_NORMAL
, damage
, 0, 0, VICTIMSTATE_NORMAL
, 0);
3311 uint32 school
= schoolStr
? atoi((char*)schoolStr
) : SPELL_SCHOOL_NORMAL
;
3312 if(school
>= MAX_SPELL_SCHOOL
)
3315 SpellSchoolMask schoolmask
= SpellSchoolMask(1 << school
);
3317 if ( schoolmask
& SPELL_SCHOOL_MASK_NORMAL
)
3318 damage
= m_session
->GetPlayer()->CalcArmorReducedDamage(target
, damage
);
3320 char* spellStr
= strtok((char*)NULL
, " ");
3322 // melee damage by specific school
3328 m_session
->GetPlayer()->CalcAbsorbResist(target
,schoolmask
, SPELL_DIRECT_DAMAGE
, damage
, &absorb
, &resist
);
3330 if (damage
<= absorb
+ resist
)
3333 damage
-= absorb
+ resist
;
3335 m_session
->GetPlayer()->DealDamage(target
, damage
, NULL
, DIRECT_DAMAGE
, schoolmask
, NULL
, false);
3336 m_session
->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2
, target
, 1, schoolmask
, damage
, absorb
, resist
, VICTIMSTATE_NORMAL
, 0);
3342 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3343 uint32 spellid
= extractSpellIdFromLink((char*)args
);
3344 if(!spellid
|| !sSpellStore
.LookupEntry(spellid
))
3347 m_session
->GetPlayer()->SpellNonMeleeDamageLog(target
, spellid
, damage
, false);
3351 bool ChatHandler::HandleModifyArenaCommand(const char * args
)
3356 Player
*target
= getSelectedPlayer();
3359 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3360 SetSentErrorMessage(true);
3364 int32 amount
= (uint32
)atoi(args
);
3366 target
->ModifyArenaPoints(amount
);
3368 PSendSysMessage(LANG_COMMAND_MODIFY_ARENA
, target
->GetName(), target
->GetArenaPoints());
3373 bool ChatHandler::HandleReviveCommand(const char* args
)
3375 Player
* SelectedPlayer
= NULL
;
3379 std::string name
= args
;
3380 if(!normalizePlayerName(name
))
3382 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3383 SetSentErrorMessage(true);
3387 SelectedPlayer
= objmgr
.GetPlayer(name
.c_str());
3390 SelectedPlayer
= getSelectedPlayer();
3394 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3395 SetSentErrorMessage(true);
3399 SelectedPlayer
->ResurrectPlayer(0.5f
);
3400 SelectedPlayer
->SpawnCorpseBones();
3401 SelectedPlayer
->SaveToDB();
3405 bool ChatHandler::HandleAuraCommand(const char* args
)
3407 char* px
= strtok((char*)args
, " ");
3411 Unit
*target
= getSelectedUnit();
3414 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3415 SetSentErrorMessage(true);
3419 uint32 spellID
= (uint32
)atoi(px
);
3420 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry( spellID
);
3423 for(uint32 i
= 0;i
<3;i
++)
3425 uint8 eff
= spellInfo
->Effect
[i
];
3426 if (eff
>=TOTAL_SPELL_EFFECTS
)
3428 if( IsAreaAuraEffect(eff
) ||
3429 eff
== SPELL_EFFECT_APPLY_AURA
||
3430 eff
== SPELL_EFFECT_PERSISTENT_AREA_AURA
)
3432 Aura
*Aur
= CreateAura(spellInfo
, i
, NULL
, target
);
3433 target
->AddAura(Aur
);
3441 bool ChatHandler::HandleUnAuraCommand(const char* args
)
3443 char* px
= strtok((char*)args
, " ");
3447 Unit
*target
= getSelectedUnit();
3450 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3451 SetSentErrorMessage(true);
3455 std::string argstr
= args
;
3456 if (argstr
== "all")
3458 target
->RemoveAllAuras();
3462 uint32 spellID
= (uint32
)atoi(px
);
3463 target
->RemoveAurasDueToSpell(spellID
);
3468 bool ChatHandler::HandleLinkGraveCommand(const char* args
)
3473 char* px
= strtok((char*)args
, " ");
3477 uint32 g_id
= (uint32
)atoi(px
);
3481 char* px2
= strtok(NULL
, " ");
3485 else if (strncmp(px2
,"horde",6)==0)
3487 else if (strncmp(px2
,"alliance",9)==0)
3492 WorldSafeLocsEntry
const* graveyard
= sWorldSafeLocsStore
.LookupEntry(g_id
);
3496 PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST
, g_id
);
3497 SetSentErrorMessage(true);
3501 Player
* player
= m_session
->GetPlayer();
3503 uint32 zoneId
= player
->GetZoneId();
3505 AreaTableEntry
const *areaEntry
= GetAreaEntryByAreaID(zoneId
);
3506 if(!areaEntry
|| areaEntry
->zone
!=0 )
3508 PSendSysMessage(LANG_COMMAND_GRAVEYARDWRONGZONE
, g_id
,zoneId
);
3509 SetSentErrorMessage(true);
3513 if(graveyard
->map_id
!= areaEntry
->mapid
&& g_team
!= 0)
3515 SendSysMessage(LANG_COMMAND_GRAVEYARDWRONGTEAM
);
3516 SetSentErrorMessage(true);
3520 if(objmgr
.AddGraveYardLink(g_id
,player
->GetZoneId(),g_team
))
3521 PSendSysMessage(LANG_COMMAND_GRAVEYARDLINKED
, g_id
,zoneId
);
3523 PSendSysMessage(LANG_COMMAND_GRAVEYARDALRLINKED
, g_id
,zoneId
);
3528 bool ChatHandler::HandleNearGraveCommand(const char* args
)
3532 size_t argslen
= strlen(args
);
3536 else if (strncmp((char*)args
,"horde",argslen
)==0)
3538 else if (strncmp((char*)args
,"alliance",argslen
)==0)
3543 Player
* player
= m_session
->GetPlayer();
3545 WorldSafeLocsEntry
const* graveyard
= objmgr
.GetClosestGraveYard(
3546 player
->GetPositionX(), player
->GetPositionY(), player
->GetPositionZ(),player
->GetMapId(),g_team
);
3550 uint32 g_id
= graveyard
->ID
;
3552 GraveYardData
const* data
= objmgr
.FindGraveYardData(g_id
,player
->GetZoneId());
3555 PSendSysMessage(LANG_COMMAND_GRAVEYARDERROR
,g_id
);
3556 SetSentErrorMessage(true);
3560 g_team
= data
->team
;
3562 std::string team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_NOTEAM
);
3565 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ANY
);
3566 else if(g_team
== HORDE
)
3567 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE
);
3568 else if(g_team
== ALLIANCE
)
3569 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE
);
3571 PSendSysMessage(LANG_COMMAND_GRAVEYARDNEAREST
, g_id
,team_name
.c_str(),player
->GetZoneId());
3575 std::string team_name
;
3578 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ANY
);
3579 else if(g_team
== HORDE
)
3580 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE
);
3581 else if(g_team
== ALLIANCE
)
3582 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE
);
3584 if(g_team
== ~uint32(0))
3585 PSendSysMessage(LANG_COMMAND_ZONENOGRAVEYARDS
, player
->GetZoneId());
3587 PSendSysMessage(LANG_COMMAND_ZONENOGRAFACTION
, player
->GetZoneId(),team_name
.c_str());
3594 bool ChatHandler::HandlePlayEmoteCommand(const char* args
)
3596 uint32 emote
= atoi((char*)args
);
3598 Creature
* target
= getSelectedCreature();
3601 SendSysMessage(LANG_SELECT_CREATURE
);
3602 SetSentErrorMessage(true);
3606 target
->SetUInt32Value(UNIT_NPC_EMOTESTATE
,emote
);
3611 bool ChatHandler::HandleNpcInfoCommand(const char* /*args*/)
3613 Creature
* target
= getSelectedCreature();
3617 SendSysMessage(LANG_SELECT_CREATURE
);
3618 SetSentErrorMessage(true);
3622 uint32 faction
= target
->getFaction();
3623 uint32 npcflags
= target
->GetUInt32Value(UNIT_NPC_FLAGS
);
3624 uint32 displayid
= target
->GetDisplayId();
3625 uint32 nativeid
= target
->GetNativeDisplayId();
3626 uint32 Entry
= target
->GetEntry();
3627 CreatureInfo
const* cInfo
= target
->GetCreatureInfo();
3629 int32 curRespawnDelay
= target
->GetRespawnTimeEx()-time(NULL
);
3630 if(curRespawnDelay
< 0)
3631 curRespawnDelay
= 0;
3632 std::string curRespawnDelayStr
= secsToTimeString(curRespawnDelay
,true);
3633 std::string defRespawnDelayStr
= secsToTimeString(target
->GetRespawnDelay(),true);
3635 PSendSysMessage(LANG_NPCINFO_CHAR
, target
->GetDBTableGUIDLow(), faction
, npcflags
, Entry
, displayid
, nativeid
);
3636 PSendSysMessage(LANG_NPCINFO_LEVEL
, target
->getLevel());
3637 PSendSysMessage(LANG_NPCINFO_HEALTH
,target
->GetCreateHealth(), target
->GetMaxHealth(), target
->GetHealth());
3638 PSendSysMessage(LANG_NPCINFO_FLAGS
, target
->GetUInt32Value(UNIT_FIELD_FLAGS
), target
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
), target
->getFaction());
3639 PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES
, defRespawnDelayStr
.c_str(),curRespawnDelayStr
.c_str());
3640 PSendSysMessage(LANG_NPCINFO_LOOT
, cInfo
->lootid
,cInfo
->pickpocketLootId
,cInfo
->SkinLootId
);
3641 PSendSysMessage(LANG_NPCINFO_DUNGEON_ID
, target
->GetInstanceId());
3642 PSendSysMessage(LANG_NPCINFO_POSITION
,float(target
->GetPositionX()), float(target
->GetPositionY()), float(target
->GetPositionZ()));
3644 if ((npcflags
& UNIT_NPC_FLAG_VENDOR
) )
3646 SendSysMessage(LANG_NPCINFO_VENDOR
);
3648 if ((npcflags
& UNIT_NPC_FLAG_TRAINER
) )
3650 SendSysMessage(LANG_NPCINFO_TRAINER
);
3656 bool ChatHandler::HandleExploreCheatCommand(const char* args
)
3661 int flag
= atoi((char*)args
);
3663 Player
*chr
= getSelectedPlayer();
3666 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3667 SetSentErrorMessage(true);
3673 PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL
, chr
->GetName());
3674 if(chr
!=m_session
->GetPlayer())
3675 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_EXPLORE_SET_ALL
,m_session
->GetPlayer()->GetName());
3679 PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING
, chr
->GetName());
3680 if(chr
!=m_session
->GetPlayer())
3681 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_EXPLORE_SET_NOTHING
,m_session
->GetPlayer()->GetName());
3684 for (uint8 i
=0; i
<128; i
++)
3688 m_session
->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1
+i
,0xFFFFFFFF);
3692 m_session
->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1
+i
,0);
3699 bool ChatHandler::HandleHoverCommand(const char* args
)
3701 char* px
= strtok((char*)args
, " ");
3708 m_session
->GetPlayer()->SetHover(flag
);
3711 SendSysMessage(LANG_HOVER_ENABLED
);
3713 SendSysMessage(LANG_HOVER_DISABLED
);
3718 bool ChatHandler::HandleLevelUpCommand(const char* args
)
3720 char* px
= strtok((char*)args
, " ");
3721 char* py
= strtok((char*)NULL
, " ");
3723 // command format parsing
3724 char* pname
= (char*)NULL
;
3727 if(px
&& py
) // .levelup name level
3729 addlevel
= atoi(py
);
3732 else if(px
&& !py
) // .levelup name OR .levelup level
3734 if(isalpha(px
[0])) // .levelup name
3736 else // .levelup level
3737 addlevel
= atoi(px
);
3739 // else .levelup - nothing do for prepering
3743 uint64 chr_guid
= 0;
3747 if(pname
) // player by name
3750 if(!normalizePlayerName(name
))
3752 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3753 SetSentErrorMessage(true);
3757 chr
= objmgr
.GetPlayer(name
.c_str());
3758 if(!chr
) // not in game
3760 chr_guid
= objmgr
.GetPlayerGUIDByName(name
);
3763 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3764 SetSentErrorMessage(true);
3769 else // player by selection
3771 chr
= getSelectedPlayer();
3775 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3776 SetSentErrorMessage(true);
3780 name
= chr
->GetName();
3783 assert(chr
|| chr_guid
);
3785 int32 oldlevel
= chr
? chr
->getLevel() : Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL
,chr_guid
);
3786 int32 newlevel
= oldlevel
+ addlevel
;
3789 if(newlevel
> 255) // hardcoded maximum level
3794 chr
->GiveLevel(newlevel
);
3795 chr
->InitTalentForLevel();
3796 chr
->SetUInt32Value(PLAYER_XP
,0);
3798 if(oldlevel
== newlevel
)
3799 ChatHandler(chr
).SendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET
);
3801 if(oldlevel
< newlevel
)
3802 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_LEVEL_UP
,newlevel
-oldlevel
);
3804 if(oldlevel
> newlevel
)
3805 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_LEVEL_DOWN
,newlevel
-oldlevel
);
3809 // update levle and XP at level, all other will be updated at loading
3811 Player::LoadValuesArrayFromDB(values
,chr_guid
);
3812 Player::SetUInt32ValueInArray(values
,UNIT_FIELD_LEVEL
,newlevel
);
3813 Player::SetUInt32ValueInArray(values
,PLAYER_XP
,0);
3814 Player::SaveValuesArrayInDB(values
,chr_guid
);
3817 if(m_session
->GetPlayer() != chr
) // including chr==NULL
3818 PSendSysMessage(LANG_YOU_CHANGE_LVL
,name
.c_str(),newlevel
);
3822 bool ChatHandler::HandleShowAreaCommand(const char* args
)
3827 int area
= atoi((char*)args
);
3829 Player
*chr
= getSelectedPlayer();
3832 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3833 SetSentErrorMessage(true);
3837 int offset
= area
/ 32;
3838 uint32 val
= (uint32
)(1 << (area
% 32));
3842 SendSysMessage(LANG_BAD_VALUE
);
3843 SetSentErrorMessage(true);
3847 uint32 currFields
= chr
->GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
3848 chr
->SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
| val
));
3850 SendSysMessage(LANG_EXPLORE_AREA
);
3854 bool ChatHandler::HandleHideAreaCommand(const char* args
)
3859 int area
= atoi((char*)args
);
3861 Player
*chr
= getSelectedPlayer();
3864 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3865 SetSentErrorMessage(true);
3869 int offset
= area
/ 32;
3870 uint32 val
= (uint32
)(1 << (area
% 32));
3874 SendSysMessage(LANG_BAD_VALUE
);
3875 SetSentErrorMessage(true);
3879 uint32 currFields
= chr
->GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
3880 chr
->SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
^ val
));
3882 SendSysMessage(LANG_UNEXPLORE_AREA
);
3886 bool ChatHandler::HandleUpdate(const char* args
)
3894 char* pUpdateIndex
= strtok((char*)args
, " ");
3896 Unit
* chr
= getSelectedUnit();
3899 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3900 SetSentErrorMessage(true);
3908 updateIndex
= atoi(pUpdateIndex
);
3910 if(chr
->GetTypeId() == TYPEID_PLAYER
)
3912 if (updateIndex
>=PLAYER_END
) return true;
3916 if (updateIndex
>=UNIT_END
) return true;
3919 char* pvalue
= strtok(NULL
, " ");
3922 value
=chr
->GetUInt32Value(updateIndex
);
3924 PSendSysMessage(LANG_UPDATE
, chr
->GetGUIDLow(),updateIndex
,value
);
3930 PSendSysMessage(LANG_UPDATE_CHANGE
, chr
->GetGUIDLow(),updateIndex
,value
);
3932 chr
->SetUInt32Value(updateIndex
,value
);
3937 bool ChatHandler::HandleBankCommand(const char* /*args*/)
3939 m_session
->SendShowBank( m_session
->GetPlayer()->GetGUID() );
3944 bool ChatHandler::HandleChangeWeather(const char* args
)
3950 if (!sWorld
.getConfig(CONFIG_WEATHER
))
3952 SendSysMessage(LANG_WEATHER_DISABLED
);
3953 SetSentErrorMessage(true);
3957 //*Change the weather of a cell
3958 char* px
= strtok((char*)args
, " ");
3959 char* py
= strtok(NULL
, " ");
3964 uint32 type
= (uint32
)atoi(px
); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
3965 float grade
= (float)atof(py
); //0 to 1, sending -1 is instand good weather
3967 Player
*player
= m_session
->GetPlayer();
3968 uint32 zoneid
= player
->GetZoneId();
3970 Weather
* wth
= sWorld
.FindWeather(zoneid
);
3973 wth
= sWorld
.AddWeather(zoneid
);
3976 SendSysMessage(LANG_NO_WEATHER
);
3977 SetSentErrorMessage(true);
3981 wth
->SetWeather(WeatherType(type
), grade
);
3986 bool ChatHandler::HandleSetValue(const char* args
)
3991 char* px
= strtok((char*)args
, " ");
3992 char* py
= strtok(NULL
, " ");
3993 char* pz
= strtok(NULL
, " ");
3998 Unit
* target
= getSelectedUnit();
4001 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4002 SetSentErrorMessage(true);
4006 uint64 guid
= target
->GetGUID();
4008 uint32 Opcode
= (uint32
)atoi(px
);
4009 if(Opcode
>= target
->GetValuesCount())
4011 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, GUID_LOPART(guid
), target
->GetValuesCount());
4016 bool isint32
= true;
4018 isint32
= (bool)atoi(pz
);
4021 iValue
= (uint32
)atoi(py
);
4022 sLog
.outDebug(GetMangosString(LANG_SET_UINT
), GUID_LOPART(guid
), Opcode
, iValue
);
4023 target
->SetUInt32Value( Opcode
, iValue
);
4024 PSendSysMessage(LANG_SET_UINT_FIELD
, GUID_LOPART(guid
), Opcode
,iValue
);
4028 fValue
= (float)atof(py
);
4029 sLog
.outDebug(GetMangosString(LANG_SET_FLOAT
), GUID_LOPART(guid
), Opcode
, fValue
);
4030 target
->SetFloatValue( Opcode
, fValue
);
4031 PSendSysMessage(LANG_SET_FLOAT_FIELD
, GUID_LOPART(guid
), Opcode
,fValue
);
4037 bool ChatHandler::HandleGetValue(const char* args
)
4042 char* px
= strtok((char*)args
, " ");
4043 char* pz
= strtok(NULL
, " ");
4048 Unit
* target
= getSelectedUnit();
4051 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4052 SetSentErrorMessage(true);
4056 uint64 guid
= target
->GetGUID();
4058 uint32 Opcode
= (uint32
)atoi(px
);
4059 if(Opcode
>= target
->GetValuesCount())
4061 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, GUID_LOPART(guid
), target
->GetValuesCount());
4066 bool isint32
= true;
4068 isint32
= (bool)atoi(pz
);
4072 iValue
= target
->GetUInt32Value( Opcode
);
4073 sLog
.outDebug(GetMangosString(LANG_GET_UINT
), GUID_LOPART(guid
), Opcode
, iValue
);
4074 PSendSysMessage(LANG_GET_UINT_FIELD
, GUID_LOPART(guid
), Opcode
, iValue
);
4078 fValue
= target
->GetFloatValue( Opcode
);
4079 sLog
.outDebug(GetMangosString(LANG_GET_FLOAT
), GUID_LOPART(guid
), Opcode
, fValue
);
4080 PSendSysMessage(LANG_GET_FLOAT_FIELD
, GUID_LOPART(guid
), Opcode
, fValue
);
4086 bool ChatHandler::HandleSet32Bit(const char* args
)
4091 char* px
= strtok((char*)args
, " ");
4092 char* py
= strtok(NULL
, " ");
4097 uint32 Opcode
= (uint32
)atoi(px
);
4098 uint32 Value
= (uint32
)atoi(py
);
4099 if (Value
> 32) //uint32 = 32 bits
4102 sLog
.outDebug(GetMangosString(LANG_SET_32BIT
), Opcode
, Value
);
4104 m_session
->GetPlayer( )->SetUInt32Value( Opcode
, 2^Value
);
4106 PSendSysMessage(LANG_SET_32BIT_FIELD
, Opcode
,1);
4110 bool ChatHandler::HandleMod32Value(const char* args
)
4115 char* px
= strtok((char*)args
, " ");
4116 char* py
= strtok(NULL
, " ");
4121 uint32 Opcode
= (uint32
)atoi(px
);
4122 int Value
= atoi(py
);
4124 if(Opcode
>= m_session
->GetPlayer()->GetValuesCount())
4126 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, m_session
->GetPlayer()->GetGUIDLow(), m_session
->GetPlayer( )->GetValuesCount());
4130 sLog
.outDebug(GetMangosString(LANG_CHANGE_32BIT
), Opcode
, Value
);
4132 int CurrentValue
= (int)m_session
->GetPlayer( )->GetUInt32Value( Opcode
);
4134 CurrentValue
+= Value
;
4135 m_session
->GetPlayer( )->SetUInt32Value( Opcode
, (uint32
)CurrentValue
);
4137 PSendSysMessage(LANG_CHANGE_32BIT_FIELD
, Opcode
,CurrentValue
);
4142 bool ChatHandler::HandleAddTeleCommand(const char * args
)
4147 Player
*player
=m_session
->GetPlayer();
4151 std::string name
= args
;
4153 if(objmgr
.GetGameTele(name
))
4155 SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST
);
4156 SetSentErrorMessage(true);
4161 tele
.position_x
= player
->GetPositionX();
4162 tele
.position_y
= player
->GetPositionY();
4163 tele
.position_z
= player
->GetPositionZ();
4164 tele
.orientation
= player
->GetOrientation();
4165 tele
.mapId
= player
->GetMapId();
4168 if(objmgr
.AddGameTele(tele
))
4170 SendSysMessage(LANG_COMMAND_TP_ADDED
);
4174 SendSysMessage(LANG_COMMAND_TP_ADDEDERR
);
4175 SetSentErrorMessage(true);
4182 bool ChatHandler::HandleDelTeleCommand(const char * args
)
4187 std::string name
= args
;
4189 if(!objmgr
.DeleteGameTele(name
))
4191 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
4192 SetSentErrorMessage(true);
4196 SendSysMessage(LANG_COMMAND_TP_DELETED
);
4200 bool ChatHandler::HandleListAurasCommand (const char * /*args*/)
4202 Unit
*unit
= getSelectedUnit();
4205 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4206 SetSentErrorMessage(true);
4210 char const* talentStr
= GetMangosString(LANG_TALENT
);
4211 char const* passiveStr
= GetMangosString(LANG_PASSIVE
);
4213 Unit::AuraMap
const& uAuras
= unit
->GetAuras();
4214 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS
, uAuras
.size());
4215 for (Unit::AuraMap::const_iterator itr
= uAuras
.begin(); itr
!= uAuras
.end(); ++itr
)
4217 bool talent
= GetTalentSpellCost(itr
->second
->GetId()) > 0;
4218 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL
, itr
->second
->GetId(), itr
->second
->GetEffIndex(),
4219 itr
->second
->GetModifier()->m_auraname
, itr
->second
->GetAuraDuration(), itr
->second
->GetAuraMaxDuration(),
4220 itr
->second
->GetSpellProto()->SpellName
[m_session
->GetSessionDbcLocale()],
4221 (itr
->second
->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4222 IS_PLAYER_GUID(itr
->second
->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr
->second
->GetCasterGUID()));
4224 for (int i
= 0; i
< TOTAL_AURAS
; i
++)
4226 Unit::AuraList
const& uAuraList
= unit
->GetAurasByType(AuraType(i
));
4227 if (uAuraList
.empty()) continue;
4228 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE
, uAuraList
.size(), i
);
4229 for (Unit::AuraList::const_iterator itr
= uAuraList
.begin(); itr
!= uAuraList
.end(); ++itr
)
4231 bool talent
= GetTalentSpellCost((*itr
)->GetId()) > 0;
4232 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE
, (*itr
)->GetId(), (*itr
)->GetEffIndex(),
4233 (*itr
)->GetSpellProto()->SpellName
[m_session
->GetSessionDbcLocale()],((*itr
)->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4234 IS_PLAYER_GUID((*itr
)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr
)->GetCasterGUID()));
4240 bool ChatHandler::HandleResetHonorCommand (const char * args
)
4242 char* pName
= strtok((char*)args
, "");
4243 Player
*player
= NULL
;
4246 std::string name
= pName
;
4247 if(!normalizePlayerName(name
))
4249 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4250 SetSentErrorMessage(true);
4254 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4255 player
= objmgr
.GetPlayer(guid
);
4258 player
= getSelectedPlayer();
4262 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4266 player
->SetUInt32Value(PLAYER_FIELD_KILLS
, 0);
4267 player
->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS
, 0);
4268 player
->SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY
, 0);
4269 player
->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION
, 0);
4270 player
->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION
, 0);
4275 static bool HandleResetStatsOrLevelHelper(Player
* player
)
4277 PlayerInfo
const *info
= objmgr
.GetPlayerInfo(player
->getRace(), player
->getClass());
4278 if(!info
) return false;
4280 ChrClassesEntry
const* cEntry
= sChrClassesStore
.LookupEntry(player
->getClass());
4283 sLog
.outError("Class %u not found in DBC (Wrong DBC files?)",player
->getClass());
4287 uint8 powertype
= cEntry
->powerType
;
4290 if(powertype
== POWER_RAGE
)
4291 unitfield
= 0x1100EE00;
4292 else if(powertype
== POWER_ENERGY
)
4293 unitfield
= 0x00000000;
4294 else if(powertype
== POWER_MANA
)
4295 unitfield
= 0x0000EE00;
4298 sLog
.outError("Invalid default powertype %u for player (class %u)",powertype
,player
->getClass());
4302 // reset m_form if no aura
4303 if(!player
->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT
))
4304 player
->m_form
= FORM_NONE
;
4306 player
->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS
, DEFAULT_WORLD_OBJECT_SIZE
);
4307 player
->SetFloatValue(UNIT_FIELD_COMBATREACH
, 1.5f
);
4309 player
->setFactionForRace(player
->getRace());
4311 player
->SetUInt32Value(UNIT_FIELD_BYTES_0
, ( ( player
->getRace() ) | ( player
->getClass() << 8 ) | ( player
->getGender() << 16 ) | ( powertype
<< 24 ) ) );
4313 // reset only if player not in some form;
4314 if(player
->m_form
==FORM_NONE
)
4316 switch(player
->getGender())
4319 player
->SetDisplayId(info
->displayId_f
);
4320 player
->SetNativeDisplayId(info
->displayId_f
);
4323 player
->SetDisplayId(info
->displayId_m
);
4324 player
->SetNativeDisplayId(info
->displayId_m
);
4331 // set UNIT_FIELD_BYTES_1 to init state but preserve m_form value
4332 player
->SetUInt32Value(UNIT_FIELD_BYTES_1
, unitfield
);
4333 player
->SetByteValue(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_UNK3
| UNIT_BYTE2_FLAG_UNK5
);
4334 player
->SetByteValue(UNIT_FIELD_BYTES_2
, 3, player
->m_form
);
4336 player
->SetUInt32Value(UNIT_FIELD_FLAGS
, UNIT_FLAG_PVP_ATTACKABLE
);
4338 //-1 is default value
4339 player
->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX
, uint32(-1));
4341 //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000 );
4345 bool ChatHandler::HandleResetLevelCommand(const char * args
)
4347 char* pName
= strtok((char*)args
, "");
4348 Player
*player
= NULL
;
4351 std::string name
= pName
;
4352 if(!normalizePlayerName(name
))
4354 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4355 SetSentErrorMessage(true);
4359 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4360 player
= objmgr
.GetPlayer(guid
);
4363 player
= getSelectedPlayer();
4367 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4368 SetSentErrorMessage(true);
4372 if(!HandleResetStatsOrLevelHelper(player
))
4375 player
->SetLevel(1);
4376 player
->InitStatsForLevel(true);
4377 player
->InitTaxiNodesForLevel();
4378 player
->InitTalentForLevel();
4379 player
->SetUInt32Value(PLAYER_XP
,0);
4381 // reset level to summoned pet
4382 Pet
* pet
= player
->GetPet();
4383 if(pet
&& pet
->getPetType()==SUMMON_PET
)
4384 pet
->InitStatsForLevel(1);
4389 bool ChatHandler::HandleResetStatsCommand(const char * args
)
4391 char* pName
= strtok((char*)args
, "");
4392 Player
*player
= NULL
;
4395 std::string name
= pName
;
4396 if(!normalizePlayerName(name
))
4398 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4399 SetSentErrorMessage(true);
4403 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4404 player
= objmgr
.GetPlayer(guid
);
4407 player
= getSelectedPlayer();
4411 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4412 SetSentErrorMessage(true);
4416 if(!HandleResetStatsOrLevelHelper(player
))
4419 player
->InitStatsForLevel(true);
4420 player
->InitTaxiNodesForLevel();
4421 player
->InitTalentForLevel();
4426 bool ChatHandler::HandleResetSpellsCommand(const char * args
)
4428 char* pName
= strtok((char*)args
, "");
4429 Player
*player
= NULL
;
4430 uint64 playerGUID
= 0;
4433 std::string name
= pName
;
4435 if(!normalizePlayerName(name
))
4437 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4438 SetSentErrorMessage(true);
4442 player
= objmgr
.GetPlayer(name
.c_str());
4444 playerGUID
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4447 player
= getSelectedPlayer();
4449 if(!player
&& !playerGUID
)
4451 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4452 SetSentErrorMessage(true);
4458 player
->resetSpells();
4460 ChatHandler(player
).SendSysMessage(LANG_RESET_SPELLS
);
4462 if(m_session
->GetPlayer()!=player
)
4463 PSendSysMessage(LANG_RESET_SPELLS_ONLINE
,player
->GetName());
4467 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS
), GUID_LOPART(playerGUID
));
4468 PSendSysMessage(LANG_RESET_SPELLS_OFFLINE
,pName
);
4474 bool ChatHandler::HandleResetTalentsCommand(const char * args
)
4476 char* pName
= strtok((char*)args
, "");
4477 Player
*player
= NULL
;
4478 uint64 playerGUID
= 0;
4481 std::string name
= pName
;
4482 if(!normalizePlayerName(name
))
4484 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4485 SetSentErrorMessage(true);
4489 player
= objmgr
.GetPlayer(name
.c_str());
4491 playerGUID
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4494 player
= getSelectedPlayer();
4496 if(!player
&& !playerGUID
)
4498 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4499 SetSentErrorMessage(true);
4505 player
->resetTalents(true);
4507 ChatHandler(player
).SendSysMessage(LANG_RESET_TALENTS
);
4509 if(m_session
->GetPlayer()!=player
)
4510 PSendSysMessage(LANG_RESET_TALENTS_ONLINE
,player
->GetName());
4514 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_TALENTS
), GUID_LOPART(playerGUID
) );
4515 PSendSysMessage(LANG_RESET_TALENTS_OFFLINE
,pName
);
4521 bool ChatHandler::HandleResetAllCommand(const char * args
)
4526 std::string casename
= args
;
4528 AtLoginFlags atLogin
;
4530 // Command specially created as single command to prevent using short case names
4531 if(casename
=="spells")
4533 atLogin
= AT_LOGIN_RESET_SPELLS
;
4534 sWorld
.SendWorldText(LANG_RESETALL_SPELLS
);
4536 else if(casename
=="talents")
4538 atLogin
= AT_LOGIN_RESET_TALENTS
;
4539 sWorld
.SendWorldText(LANG_RESETALL_TALENTS
);
4543 PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE
,args
);
4544 SetSentErrorMessage(true);
4548 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u'",atLogin
);
4549 HashMapHolder
<Player
>::MapType
const& plist
= ObjectAccessor::Instance().GetPlayers();
4550 for(HashMapHolder
<Player
>::MapType::const_iterator itr
= plist
.begin(); itr
!= plist
.end(); ++itr
)
4551 itr
->second
->SetAtLoginFlag(atLogin
);
4556 bool ChatHandler::HandleShutDownCommand(const char* args
)
4561 if(std::string(args
)=="cancel")
4563 sWorld
.ShutdownCancel();
4567 int32 time
= atoi(args
);
4569 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4570 if(time
== 0 && (args
[0]!='0' || args
[1]!='\0') || time
< 0)
4573 sWorld
.ShutdownServ(time
);
4578 bool ChatHandler::HandleRestartCommand(const char* args
)
4583 if(std::string(args
)=="cancel")
4585 sWorld
.ShutdownCancel();
4589 int32 time
= atoi(args
);
4591 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4592 if(time
== 0 && (args
[0]!='0' || args
[1]!='\0') || time
< 0)
4595 sWorld
.ShutdownServ(time
, SHUTDOWN_MASK_RESTART
);
4600 bool ChatHandler::HandleIdleRestartCommand(const char* args
)
4605 if(std::string(args
)=="cancel")
4607 sWorld
.ShutdownCancel();
4611 int32 time
= atoi(args
);
4613 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4614 if(time
== 0 && (args
[0]!='0' || args
[1]!='\0') || time
< 0)
4617 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_RESTART
+SHUTDOWN_MASK_IDLE
);
4622 bool ChatHandler::HandleIdleShutDownCommand(const char* args
)
4627 if(std::string(args
)=="cancel")
4629 sWorld
.ShutdownCancel();
4633 int32 time
= atoi(args
);
4635 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4636 if(time
== 0 && (args
[0]!='0' || args
[1]!='\0') || time
< 0)
4639 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_IDLE
);
4644 bool ChatHandler::HandleAddQuest(const char* args
)
4646 Player
* player
= getSelectedPlayer();
4649 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4650 SetSentErrorMessage(true);
4654 // .addquest #entry'
4655 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4656 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4660 uint32 entry
= atol(cId
);
4662 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
4666 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
,entry
);
4667 SetSentErrorMessage(true);
4671 // check item starting quest (it can work incorrectly if added without item in inventory)
4672 QueryResult
*result
= WorldDatabase
.PQuery("SELECT entry FROM item_template WHERE startquest = '%u' LIMIT 1",entry
);
4675 Field
* fields
= result
->Fetch();
4676 uint32 item_id
= fields
[0].GetUInt32();
4679 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM
, entry
,item_id
);
4680 SetSentErrorMessage(true);
4684 // ok, normal (creature/GO starting) quest
4685 if( player
->CanAddQuest( pQuest
, true ) )
4687 player
->AddQuest( pQuest
, NULL
);
4689 if ( player
->CanCompleteQuest( entry
) )
4690 player
->CompleteQuest( entry
);
4696 bool ChatHandler::HandleRemoveQuest(const char* args
)
4698 Player
* player
= getSelectedPlayer();
4701 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4702 SetSentErrorMessage(true);
4706 // .removequest #entry'
4707 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4708 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4712 uint32 entry
= atol(cId
);
4714 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
4718 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
4719 SetSentErrorMessage(true);
4723 // remove all quest entries for 'entry' from quest log
4724 for(uint8 slot
= 0; slot
< MAX_QUEST_LOG_SIZE
; ++slot
)
4726 uint32 quest
= player
->GetQuestSlotQuestId(slot
);
4729 player
->SetQuestSlot(slot
,0);
4731 // we ignore unequippable quest items in this case, its' still be equipped
4732 player
->TakeQuestSourceItem( quest
, false );
4736 // set quest status to not started (will updated in DB at next save)
4737 player
->SetQuestStatus( entry
, QUEST_STATUS_NONE
);
4739 // reset rewarded for restart repeatable quest
4740 player
->getQuestStatusMap()[entry
].m_rewarded
= false;
4742 SendSysMessage(LANG_COMMAND_QUEST_REMOVED
);
4746 bool ChatHandler::HandleCompleteQuest(const char* args
)
4748 Player
* player
= getSelectedPlayer();
4751 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4752 SetSentErrorMessage(true);
4756 // .quest complete #entry
4757 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4758 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4762 uint32 entry
= atol(cId
);
4764 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
4766 // If player doesn't have the quest
4767 if(!pQuest
|| player
->GetQuestStatus(entry
) == QUEST_STATUS_NONE
)
4769 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
4770 SetSentErrorMessage(true);
4774 // Add quest items for quests that require items
4775 for(uint8 x
= 0; x
< QUEST_OBJECTIVES_COUNT
; ++x
)
4777 uint32 id
= pQuest
->ReqItemId
[x
];
4778 uint32 count
= pQuest
->ReqItemCount
[x
];
4782 uint32 curItemCount
= player
->GetItemCount(id
,true);
4784 ItemPosCountVec dest
;
4785 uint8 msg
= player
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, id
, count
-curItemCount
);
4786 if( msg
== EQUIP_ERR_OK
)
4788 Item
* item
= player
->StoreNewItem( dest
, id
, true);
4789 player
->SendNewItem(item
,count
-curItemCount
,true,false);
4793 // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
4794 for(uint8 i
= 0; i
< QUEST_OBJECTIVES_COUNT
; i
++)
4796 uint32 creature
= pQuest
->ReqCreatureOrGOId
[i
];
4797 uint32 creaturecount
= pQuest
->ReqCreatureOrGOCount
[i
];
4799 if(uint32 spell_id
= pQuest
->ReqSpell
[i
])
4801 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4802 player
->CastedCreatureOrGO(creature
,0,spell_id
);
4804 else if(creature
> 0)
4806 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4807 player
->KilledMonster(creature
,0);
4809 else if(creature
< 0)
4811 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4812 player
->CastedCreatureOrGO(creature
,0,0);
4816 // If the quest requires reputation to complete
4817 if(uint32 repFaction
= pQuest
->GetRepObjectiveFaction())
4819 uint32 repValue
= pQuest
->GetRepObjectiveValue();
4820 uint32 curRep
= player
->GetReputation(repFaction
);
4821 if(curRep
< repValue
)
4823 FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry(repFaction
);
4824 player
->SetFactionReputation(factionEntry
,repValue
);
4828 // If the quest requires money
4829 int32 ReqOrRewMoney
= pQuest
->GetRewOrReqMoney();
4830 if(ReqOrRewMoney
< 0)
4831 player
->ModifyMoney(-ReqOrRewMoney
);
4833 player
->CompleteQuest(entry
);
4837 bool ChatHandler::HandleBanAccountCommand(const char* args
)
4839 return HandleBanHelper(BAN_ACCOUNT
,args
);
4842 bool ChatHandler::HandleBanCharacterCommand(const char* args
)
4844 return HandleBanHelper(BAN_CHARACTER
,args
);
4847 bool ChatHandler::HandleBanIPCommand(const char* args
)
4849 return HandleBanHelper(BAN_IP
,args
);
4852 bool ChatHandler::HandleBanHelper(BanMode mode
, const char* args
)
4857 char* cnameOrIP
= strtok ((char*)args
, " ");
4861 std::string nameOrIP
= cnameOrIP
;
4863 char* duration
= strtok (NULL
," ");
4864 if(!duration
|| !atoi(duration
))
4867 char* reason
= strtok (NULL
,"");
4874 if(!AccountMgr::normilizeString(nameOrIP
))
4876 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
4877 SetSentErrorMessage(true);
4882 if(!normalizePlayerName(nameOrIP
))
4884 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4885 SetSentErrorMessage(true);
4890 if(!IsIPAddress(nameOrIP
.c_str()))
4895 switch(sWorld
.BanAccount(mode
, nameOrIP
, duration
, reason
,m_session
? m_session
->GetPlayerName() : ""))
4898 if(atoi(duration
)>0)
4899 PSendSysMessage(LANG_BAN_YOUBANNED
,nameOrIP
.c_str(),secsToTimeString(TimeStringToSecs(duration
),true).c_str(),reason
);
4901 PSendSysMessage(LANG_BAN_YOUPERMBANNED
,nameOrIP
.c_str(),reason
);
4903 case BAN_SYNTAX_ERROR
:
4909 PSendSysMessage(LANG_BAN_NOTFOUND
,"account",nameOrIP
.c_str());
4912 PSendSysMessage(LANG_BAN_NOTFOUND
,"character",nameOrIP
.c_str());
4915 PSendSysMessage(LANG_BAN_NOTFOUND
,"ip",nameOrIP
.c_str());
4918 SetSentErrorMessage(true);
4925 bool ChatHandler::HandleUnBanAccountCommand(const char* args
)
4927 return HandleUnBanHelper(BAN_ACCOUNT
,args
);
4930 bool ChatHandler::HandleUnBanCharacterCommand(const char* args
)
4932 return HandleUnBanHelper(BAN_CHARACTER
,args
);
4935 bool ChatHandler::HandleUnBanIPCommand(const char* args
)
4937 return HandleUnBanHelper(BAN_IP
,args
);
4940 bool ChatHandler::HandleUnBanHelper(BanMode mode
, const char* args
)
4945 char* cnameOrIP
= strtok ((char*)args
, " ");
4949 std::string nameOrIP
= cnameOrIP
;
4954 if(!AccountMgr::normilizeString(nameOrIP
))
4956 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
4957 SetSentErrorMessage(true);
4962 if(!normalizePlayerName(nameOrIP
))
4964 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4965 SetSentErrorMessage(true);
4970 if(!IsIPAddress(nameOrIP
.c_str()))
4975 if(sWorld
.RemoveBanAccount(mode
,nameOrIP
))
4976 PSendSysMessage(LANG_UNBAN_UNBANNED
,nameOrIP
.c_str());
4978 PSendSysMessage(LANG_UNBAN_ERROR
,nameOrIP
.c_str());
4983 bool ChatHandler::HandleBanInfoAccountCommand(const char* args
)
4988 char* cname
= strtok((char*)args
, "");
4992 std::string account_name
= cname
;
4993 if(!AccountMgr::normilizeString(account_name
))
4995 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
4996 SetSentErrorMessage(true);
5000 uint32 accountid
= accmgr
.GetId(account_name
);
5003 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5007 return HandleBanInfoHelper(accountid
,account_name
.c_str());
5010 bool ChatHandler::HandleBanInfoCharacterCommand(const char* args
)
5015 char* cname
= strtok ((char*)args
, "");
5019 std::string name
= cname
;
5020 if(!normalizePlayerName(name
))
5022 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5023 SetSentErrorMessage(true);
5027 uint32 accountid
= objmgr
.GetPlayerAccountIdByPlayerName(name
);
5030 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5031 SetSentErrorMessage(true);
5035 std::string accountname
;
5036 if(!accmgr
.GetName(accountid
,accountname
))
5038 PSendSysMessage(LANG_BANINFO_NOCHARACTER
);
5042 return HandleBanInfoHelper(accountid
,accountname
.c_str());
5045 bool ChatHandler::HandleBanInfoHelper(uint32 accountid
, char const* accountname
)
5047 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
);
5050 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN
, accountname
);
5054 PSendSysMessage(LANG_BANINFO_BANHISTORY
,accountname
);
5057 Field
* fields
= result
->Fetch();
5059 time_t unbandate
= time_t(fields
[3].GetUInt64());
5060 bool active
= false;
5061 if(fields
[2].GetBool() && (fields
[1].GetUInt64() == (uint64
)0 ||unbandate
>= time(NULL
)) )
5063 bool permanent
= (fields
[1].GetUInt64() == (uint64
)0);
5064 std::string bantime
= permanent
?GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[1].GetUInt64(), true);
5065 PSendSysMessage(LANG_BANINFO_HISTORYENTRY
,
5066 fields
[0].GetString(), bantime
.c_str(), active
? GetMangosString(LANG_BANINFO_YES
):GetMangosString(LANG_BANINFO_NO
), fields
[4].GetString(), fields
[5].GetString());
5067 }while (result
->NextRow());
5073 bool ChatHandler::HandleBanInfoIPCommand(const char* args
)
5078 char* cIP
= strtok ((char*)args
, "");
5082 if (!IsIPAddress(cIP
))
5085 std::string IP
= cIP
;
5087 loginDatabase
.escape_string(IP
);
5088 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());
5091 PSendSysMessage(LANG_BANINFO_NOIP
);
5095 Field
*fields
= result
->Fetch();
5096 bool permanent
= !fields
[6].GetUInt64();
5097 PSendSysMessage(LANG_BANINFO_IPENTRY
,
5098 fields
[0].GetString(), fields
[1].GetString(), permanent
? GetMangosString(LANG_BANINFO_NEVER
):fields
[2].GetString(),
5099 permanent
? GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[3].GetUInt64(), true).c_str(), fields
[4].GetString(), fields
[5].GetString());
5104 bool ChatHandler::HandleBanListCharacterCommand(const char* args
)
5106 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5108 char* cFilter
= strtok ((char*)args
, " ");
5112 std::string filter
= cFilter
;
5113 loginDatabase
.escape_string(filter
);
5114 QueryResult
* result
= CharacterDatabase
.PQuery("SELECT account FROM characters WHERE name "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'"),filter
.c_str());
5117 PSendSysMessage(LANG_BANLIST_NOCHARACTER
);
5121 return HandleBanListHelper(result
);
5124 bool ChatHandler::HandleBanListAccountCommand(const char* args
)
5126 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5128 char* cFilter
= strtok((char*)args
, " ");
5129 std::string filter
= cFilter
? cFilter
: "";
5130 loginDatabase
.escape_string(filter
);
5132 QueryResult
* result
;
5136 result
= loginDatabase
.Query("SELECT account.id, username FROM account, account_banned"
5137 " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
5141 result
= loginDatabase
.PQuery("SELECT account.id, username FROM account, account_banned"
5142 " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
5148 PSendSysMessage(LANG_BANLIST_NOACCOUNT
);
5152 return HandleBanListHelper(result
);
5155 bool ChatHandler::HandleBanListHelper(QueryResult
* result
)
5157 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT
);
5159 // Chat short output
5164 Field
* fields
= result
->Fetch();
5165 uint32 accountid
= fields
[0].GetUInt32();
5167 QueryResult
* banresult
= loginDatabase
.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid
);
5170 Field
* fields2
= banresult
->Fetch();
5171 PSendSysMessage("%s",fields2
[0].GetString());
5174 } while (result
->NextRow());
5176 // Console wide output
5179 SendSysMessage(LANG_BANLIST_ACCOUNTS
);
5180 SendSysMessage("===============================================================================");
5181 SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER
);
5184 SendSysMessage("-------------------------------------------------------------------------------");
5185 Field
*fields
= result
->Fetch();
5186 uint32 account_id
= fields
[0].GetUInt32 ();
5188 std::string account_name
;
5190 // "account" case, name can be get in same quary
5191 if(result
->GetFieldCount() > 1)
5192 account_name
= fields
[1].GetCppString();
5193 // "character" case, name need extract from another DB
5195 accmgr
.GetName (account_id
,account_name
);
5197 // No SQL injection. id is uint32.
5198 QueryResult
*banInfo
= loginDatabase
.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id
);
5201 Field
*fields2
= banInfo
->Fetch();
5204 time_t t_ban
= fields2
[0].GetUInt64();
5205 tm
* aTm_ban
= localtime(&t_ban
);
5207 if (fields2
[0].GetUInt64() == fields2
[1].GetUInt64())
5209 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5210 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
,
5211 fields2
[2].GetString(),fields2
[3].GetString());
5215 time_t t_unban
= fields2
[1].GetUInt64();
5216 tm
* aTm_unban
= localtime(&t_unban
);
5217 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5218 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
,
5219 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5220 fields2
[2].GetString(),fields2
[3].GetString());
5222 }while ( banInfo
->NextRow() );
5225 }while( result
->NextRow() );
5226 SendSysMessage("===============================================================================");
5233 bool ChatHandler::HandleBanListIPCommand(const char* args
)
5235 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5237 char* cFilter
= strtok((char*)args
, " ");
5238 std::string filter
= cFilter
? cFilter
: "";
5239 loginDatabase
.escape_string(filter
);
5241 QueryResult
* result
;
5245 result
= loginDatabase
.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5246 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
5247 " ORDER BY unbandate" );
5251 result
= loginDatabase
.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5252 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")
5253 " ORDER BY unbandate",filter
.c_str() );
5258 PSendSysMessage(LANG_BANLIST_NOIP
);
5262 PSendSysMessage(LANG_BANLIST_MATCHINGIP
);
5263 // Chat short output
5268 Field
* fields
= result
->Fetch();
5269 PSendSysMessage("%s",fields
[0].GetString());
5270 } while (result
->NextRow());
5272 // Console wide output
5275 SendSysMessage(LANG_BANLIST_IPS
);
5276 SendSysMessage("===============================================================================");
5277 SendSysMessage(LANG_BANLIST_IPS_HEADER
);
5280 SendSysMessage("-------------------------------------------------------------------------------");
5281 Field
*fields
= result
->Fetch();
5282 time_t t_ban
= fields
[1].GetUInt64();
5283 tm
* aTm_ban
= localtime(&t_ban
);
5284 if ( fields
[1].GetUInt64() == fields
[2].GetUInt64() )
5286 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5287 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
,
5288 fields
[3].GetString(), fields
[4].GetString());
5292 time_t t_unban
= fields
[2].GetUInt64();
5293 tm
* aTm_unban
= localtime(&t_unban
);
5294 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5295 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
,
5296 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5297 fields
[3].GetString(), fields
[4].GetString());
5299 }while( result
->NextRow() );
5300 SendSysMessage("===============================================================================");
5307 bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
5309 Player
* pl
= m_session
->GetPlayer();
5311 CellPair
p(MaNGOS::ComputeCellPair(pl
->GetPositionX(), pl
->GetPositionY()));
5313 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
5316 MaNGOS::RespawnDo u_do
;
5317 MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
> worker(u_do
);
5319 TypeContainerVisitor
<MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
>, GridTypeMapContainer
> obj_worker(worker
);
5320 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
5321 cell_lock
->Visit(cell_lock
, obj_worker
, *MapManager::Instance().GetMap(pl
->GetMapId(), pl
));
5326 bool ChatHandler::HandleFlyModeCommand(const char* args
)
5331 Unit
*unit
= getSelectedUnit();
5332 if (!unit
|| (unit
->GetTypeId() != TYPEID_PLAYER
))
5333 unit
= m_session
->GetPlayer();
5335 WorldPacket
data(12);
5336 if (strncmp(args
, "on", 3) == 0)
5337 data
.SetOpcode(SMSG_MOVE_SET_CAN_FLY
);
5338 else if (strncmp(args
, "off", 4) == 0)
5339 data
.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY
);
5342 SendSysMessage(LANG_USE_BOL
);
5345 data
.append(unit
->GetPackGUID());
5346 data
<< uint32(0); // unknown
5347 unit
->SendMessageToSet(&data
, true);
5348 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS
, unit
->GetName(), args
);
5352 bool ChatHandler::HandleLoadPDumpCommand(const char *args
)
5357 char * file
= strtok((char*)args
, " ");
5361 char * account
= strtok(NULL
, " ");
5365 std::string account_name
= account
;
5366 if(!AccountMgr::normilizeString(account_name
))
5368 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5369 SetSentErrorMessage(true);
5373 uint32 account_id
= accmgr
.GetId(account_name
);
5376 account_id
= atoi(account
); // use original string
5379 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5380 SetSentErrorMessage(true);
5385 if(!accmgr
.GetName(account_id
,account_name
))
5387 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5388 SetSentErrorMessage(true);
5392 char* guid_str
= NULL
;
5393 char* name_str
= strtok(NULL
, " ");
5399 // normalize the name if specified and check if it exists
5400 if(!normalizePlayerName(name
))
5402 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5403 SetSentErrorMessage(true);
5407 if(!ObjectMgr::IsValidName(name
,true))
5409 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5410 SetSentErrorMessage(true);
5414 guid_str
= strtok(NULL
, " ");
5421 guid
= atoi(guid_str
);
5424 PSendSysMessage(LANG_INVALID_CHARACTER_GUID
);
5425 SetSentErrorMessage(true);
5429 if(objmgr
.GetPlayerAccountIdByGUID(guid
))
5431 PSendSysMessage(LANG_CHARACTER_GUID_IN_USE
,guid
);
5432 SetSentErrorMessage(true);
5437 switch(PlayerDumpReader().LoadDump(file
, account_id
, name
, guid
))
5440 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS
);
5442 case DUMP_FILE_OPEN_ERROR
:
5443 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
5444 SetSentErrorMessage(true);
5446 case DUMP_FILE_BROKEN
:
5447 PSendSysMessage(LANG_DUMP_BROKEN
,file
);
5448 SetSentErrorMessage(true);
5450 case DUMP_TOO_MANY_CHARS
:
5451 PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL
,account_name
.c_str(),account_id
);
5452 SetSentErrorMessage(true);
5455 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED
);
5456 SetSentErrorMessage(true);
5463 bool ChatHandler::HandleChangeEntryCommand(const char *args
)
5468 uint32 newEntryNum
= atoi(args
);
5472 Unit
* unit
= getSelectedUnit();
5473 if(!unit
|| unit
->GetTypeId() != TYPEID_UNIT
)
5475 SendSysMessage(LANG_SELECT_CREATURE
);
5476 SetSentErrorMessage(true);
5479 Creature
* creature
= (Creature
*)unit
;
5480 if(creature
->UpdateEntry(newEntryNum
))
5481 SendSysMessage(LANG_DONE
);
5483 SendSysMessage(LANG_ERROR
);
5487 bool ChatHandler::HandleWritePDumpCommand(const char *args
)
5492 char* file
= strtok((char*)args
, " ");
5493 char* p2
= strtok(NULL
, " ");
5498 uint32 guid
= objmgr
.GetPlayerGUIDByName(p2
);
5502 if(!objmgr
.GetPlayerAccountIdByGUID(guid
))
5504 PSendSysMessage(LANG_PLAYER_NOT_FOUND
);
5505 SetSentErrorMessage(true);
5509 switch(PlayerDumpWriter().WriteDump(file
, guid
))
5512 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS
);
5514 case DUMP_FILE_OPEN_ERROR
:
5515 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
5516 SetSentErrorMessage(true);
5519 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED
);
5520 SetSentErrorMessage(true);
5527 bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
5529 Unit
* unit
= getSelectedUnit();
5532 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5533 SetSentErrorMessage(true);
5537 PSendSysMessage(LANG_MOVEGENS_LIST
,(unit
->GetTypeId()==TYPEID_PLAYER
? "Player" : "Creature" ),unit
->GetGUIDLow());
5539 MotionMaster
* mm
= unit
->GetMotionMaster();
5540 for(MotionMaster::const_iterator itr
= mm
->begin(); itr
!= mm
->end(); ++itr
)
5542 switch((*itr
)->GetMovementGeneratorType())
5544 case IDLE_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_IDLE
); break;
5545 case RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_RANDOM
); break;
5546 case WAYPOINT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_WAYPOINT
); break;
5547 case ANIMAL_RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_ANIMAL_RANDOM
); break;
5548 case CONFUSED_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_CONFUSED
); break;
5549 case TARGETED_MOTION_TYPE
:
5551 if(unit
->GetTypeId()==TYPEID_PLAYER
)
5553 TargetedMovementGenerator
<Player
> const* mgen
= static_cast<TargetedMovementGenerator
<Player
> const*>(*itr
);
5554 Unit
* target
= mgen
->GetTarget();
5556 PSendSysMessage(LANG_MOVEGENS_TARGETED_PLAYER
,target
->GetName(),target
->GetGUIDLow());
5558 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL
);
5562 TargetedMovementGenerator
<Creature
> const* mgen
= static_cast<TargetedMovementGenerator
<Creature
> const*>(*itr
);
5563 Unit
* target
= mgen
->GetTarget();
5565 PSendSysMessage(LANG_MOVEGENS_TARGETED_CREATURE
,target
->GetName(),target
->GetGUIDLow());
5567 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL
);
5571 case HOME_MOTION_TYPE
:
5572 if(unit
->GetTypeId()==TYPEID_UNIT
)
5575 (*itr
)->GetDestination(x
,y
,z
);
5576 PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE
,x
,y
,z
);
5579 SendSysMessage(LANG_MOVEGENS_HOME_PLAYER
);
5581 case FLIGHT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FLIGHT
); break;
5582 case POINT_MOTION_TYPE
:
5585 (*itr
)->GetDestination(x
,y
,z
);
5586 PSendSysMessage(LANG_MOVEGENS_POINT
,x
,y
,z
);
5589 case FLEEING_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FEAR
); break;
5590 case DISTRACT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_DISTRACT
); break;
5592 PSendSysMessage(LANG_MOVEGENS_UNKNOWN
,(*itr
)->GetMovementGeneratorType());
5599 bool ChatHandler::HandlePLimitCommand(const char *args
)
5603 char* param
= strtok((char*)args
, " ");
5607 int l
= strlen(param
);
5609 if( strncmp(param
,"player",l
) == 0 )
5610 sWorld
.SetPlayerLimit(-SEC_PLAYER
);
5611 else if(strncmp(param
,"moderator",l
) == 0 )
5612 sWorld
.SetPlayerLimit(-SEC_MODERATOR
);
5613 else if(strncmp(param
,"gamemaster",l
) == 0 )
5614 sWorld
.SetPlayerLimit(-SEC_GAMEMASTER
);
5615 else if(strncmp(param
,"administrator",l
) == 0 )
5616 sWorld
.SetPlayerLimit(-SEC_ADMINISTRATOR
);
5617 else if(strncmp(param
,"reset",l
) == 0 )
5618 sWorld
.SetPlayerLimit( sConfig
.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT
) );
5621 int val
= atoi(param
);
5622 if(val
< -SEC_ADMINISTRATOR
) val
= -SEC_ADMINISTRATOR
;
5624 sWorld
.SetPlayerLimit(val
);
5627 // kick all low security level players
5628 if(sWorld
.GetPlayerAmountLimit() > SEC_PLAYER
)
5629 sWorld
.KickAllLess(sWorld
.GetPlayerSecurityLimit());
5632 uint32 pLimit
= sWorld
.GetPlayerAmountLimit();
5633 AccountTypes allowedAccountType
= sWorld
.GetPlayerSecurityLimit();
5634 char const* secName
= "";
5635 switch(allowedAccountType
)
5637 case SEC_PLAYER
: secName
= "Player"; break;
5638 case SEC_MODERATOR
: secName
= "Moderator"; break;
5639 case SEC_GAMEMASTER
: secName
= "Gamemaster"; break;
5640 case SEC_ADMINISTRATOR
: secName
= "Administrator"; break;
5641 default: secName
= "<unknown>"; break;
5644 PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit
,secName
);
5649 bool ChatHandler::HandleCastCommand(const char* args
)
5654 Unit
* target
= getSelectedUnit();
5658 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5659 SetSentErrorMessage(true);
5663 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5664 uint32 spell
= extractSpellIdFromLink((char*)args
);
5668 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5672 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5674 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5675 SetSentErrorMessage(true);
5679 char* trig_str
= strtok(NULL
, " ");
5682 int l
= strlen(trig_str
);
5683 if(strncmp(trig_str
,"triggered",l
) != 0 )
5687 bool triggered
= (trig_str
!= NULL
);
5689 m_session
->GetPlayer()->CastSpell(target
,spell
,triggered
);
5694 bool ChatHandler::HandleCastBackCommand(const char* args
)
5696 Creature
* caster
= getSelectedCreature();
5700 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5701 SetSentErrorMessage(true);
5705 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
5706 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5707 uint32 spell
= extractSpellIdFromLink((char*)args
);
5708 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
5711 char* trig_str
= strtok(NULL
, " ");
5714 int l
= strlen(trig_str
);
5715 if(strncmp(trig_str
,"triggered",l
) != 0 )
5719 bool triggered
= (trig_str
!= NULL
);
5721 // update orientation at server
5722 caster
->SetOrientation(caster
->GetAngle(m_session
->GetPlayer()));
5726 caster
->BuildHeartBeatMsg(&data
);
5727 caster
->SendMessageToSet(&data
,true);
5729 caster
->CastSpell(m_session
->GetPlayer(),spell
,false);
5734 bool ChatHandler::HandleCastDistCommand(const char* args
)
5739 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5740 uint32 spell
= extractSpellIdFromLink((char*)args
);
5744 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5748 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5750 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5751 SetSentErrorMessage(true);
5755 char *distStr
= strtok(NULL
, " ");
5760 sscanf(distStr
, "%f", &dist
);
5762 char* trig_str
= strtok(NULL
, " ");
5765 int l
= strlen(trig_str
);
5766 if(strncmp(trig_str
,"triggered",l
) != 0 )
5770 bool triggered
= (trig_str
!= NULL
);
5773 m_session
->GetPlayer()->GetClosePoint(x
,y
,z
,dist
);
5775 m_session
->GetPlayer()->CastSpell(x
,y
,z
,spell
,triggered
);
5779 bool ChatHandler::HandleCastTargetCommand(const char* args
)
5781 Creature
* caster
= getSelectedCreature();
5785 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5786 SetSentErrorMessage(true);
5790 if(!caster
->getVictim())
5792 SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM
);
5793 SetSentErrorMessage(true);
5797 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5798 uint32 spell
= extractSpellIdFromLink((char*)args
);
5799 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
5802 char* trig_str
= strtok(NULL
, " ");
5805 int l
= strlen(trig_str
);
5806 if(strncmp(trig_str
,"triggered",l
) != 0 )
5810 bool triggered
= (trig_str
!= NULL
);
5812 // update orientation at server
5813 caster
->SetOrientation(caster
->GetAngle(m_session
->GetPlayer()));
5817 caster
->BuildHeartBeatMsg(&data
);
5818 caster
->SendMessageToSet(&data
,true);
5820 caster
->CastSpell(caster
->getVictim(),spell
,false);
5826 ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
5827 Without this function 3rd party scripting library will get linking errors (unresolved external)
5828 when attempting to use the PointMovementGenerator
5830 bool ChatHandler::HandleComeToMeCommand(const char *args
)
5832 Creature
* caster
= getSelectedCreature();
5836 SendSysMessage(LANG_SELECT_CREATURE
);
5837 SetSentErrorMessage(true);
5841 char* newFlagStr
= strtok((char*)args
, " ");
5846 uint32 newFlags
= atoi(newFlagStr
);
5848 caster
->SetUnitMovementFlags(newFlags
);
5850 Player
* pl
= m_session
->GetPlayer();
5852 caster
->GetMotionMaster()->MovePoint(0, pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ());
5856 bool ChatHandler::HandleCastSelfCommand(const char* args
)
5861 Unit
* target
= getSelectedUnit();
5865 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5866 SetSentErrorMessage(true);
5870 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5871 uint32 spell
= extractSpellIdFromLink((char*)args
);
5875 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5879 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5881 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5882 SetSentErrorMessage(true);
5886 target
->CastSpell(target
,spell
,false);
5891 std::string
GetTimeString(uint32 time
)
5893 uint16 days
= time
/ DAY
, hours
= (time
% DAY
) / HOUR
, minute
= (time
% HOUR
) / MINUTE
;
5894 std::ostringstream ss
;
5895 if(days
) ss
<< days
<< "d ";
5896 if(hours
) ss
<< hours
<< "h ";
5897 ss
<< minute
<< "m";
5901 bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
5903 Player
* player
= getSelectedPlayer();
5904 if (!player
) player
= m_session
->GetPlayer();
5906 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
5908 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(i
);
5909 for(Player::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
5911 InstanceSave
*save
= itr
->second
.save
;
5912 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
5913 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());
5917 PSendSysMessage("player binds: %d", counter
);
5919 Group
*group
= player
->GetGroup();
5922 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
5924 Group::BoundInstancesMap
&binds
= group
->GetBoundInstances(i
);
5925 for(Group::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
5927 InstanceSave
*save
= itr
->second
.save
;
5928 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
5929 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());
5934 PSendSysMessage("group binds: %d", counter
);
5939 bool ChatHandler::HandleInstanceUnbindCommand(const char* args
)
5944 std::string cmd
= args
;
5947 Player
* player
= getSelectedPlayer();
5948 if (!player
) player
= m_session
->GetPlayer();
5950 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
5952 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(i
);
5953 for(Player::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end();)
5955 if(itr
->first
!= player
->GetMapId())
5957 InstanceSave
*save
= itr
->second
.save
;
5958 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
5959 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());
5960 player
->UnbindInstance(itr
, i
);
5967 PSendSysMessage("instances unbound: %d", counter
);
5972 bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
5974 PSendSysMessage("instances loaded: %d", MapManager::Instance().GetNumInstances());
5975 PSendSysMessage("players in instances: %d", MapManager::Instance().GetNumPlayersInInstances());
5976 PSendSysMessage("instance saves: %d", sInstanceSaveManager
.GetNumInstanceSaves());
5977 PSendSysMessage("players bound: %d", sInstanceSaveManager
.GetNumBoundPlayersTotal());
5978 PSendSysMessage("groups bound: %d", sInstanceSaveManager
.GetNumBoundGroupsTotal());
5982 bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
5984 Player
* pl
= m_session
->GetPlayer();
5986 Map
* map
= pl
->GetMap();
5987 if (!map
->IsDungeon())
5989 PSendSysMessage("Map is not a dungeon.");
5990 SetSentErrorMessage(true);
5994 if (!((InstanceMap
*)map
)->GetInstanceData())
5996 PSendSysMessage("Map has no instance data.");
5997 SetSentErrorMessage(true);
6001 ((InstanceMap
*)map
)->GetInstanceData()->SaveToDB();
6005 /// Display the list of GMs
6006 bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
6008 ///- Get the accounts with GM Level >0
6009 QueryResult
*result
= loginDatabase
.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
6012 SendSysMessage(LANG_GMLIST
);
6013 SendSysMessage("========================");
6014 SendSysMessage(LANG_GMLIST_HEADER
);
6015 SendSysMessage("========================");
6017 ///- Circle through them. Display username and GM level
6020 Field
*fields
= result
->Fetch();
6021 PSendSysMessage("|%15s|%6s|", fields
[0].GetString(),fields
[1].GetString());
6022 }while( result
->NextRow() );
6024 PSendSysMessage("========================");
6028 PSendSysMessage(LANG_GMLIST_EMPTY
);
6032 /// Define the 'Message of the day' for the realm
6033 bool ChatHandler::HandleServerSetMotdCommand(const char* args
)
6035 sWorld
.SetMotd(args
);
6036 PSendSysMessage(LANG_MOTD_NEW
, args
);
6040 /// Set/Unset the expansion level for an account
6041 bool ChatHandler::HandleAccountSetAddonCommand(const char* args
)
6043 ///- Get the command line arguments
6044 char *szAcc
= strtok((char*)args
," ");
6045 char *szExp
= strtok(NULL
," ");
6050 std::string account_name
;
6055 Player
* player
= getSelectedPlayer();
6059 account_id
= player
->GetSession()->GetAccountId();
6060 accmgr
.GetName(account_id
,account_name
);
6065 ///- Convert Account name to Upper Format
6066 account_name
= szAcc
;
6067 if(!AccountMgr::normilizeString(account_name
))
6069 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
6070 SetSentErrorMessage(true);
6074 account_id
= accmgr
.GetId(account_name
);
6077 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
6078 SetSentErrorMessage(true);
6083 int lev
=atoi(szExp
); //get int anyway (0 if error)
6088 loginDatabase
.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev
,account_id
);
6089 PSendSysMessage(LANG_ACCOUNT_SETADDON
,account_name
.c_str(),account_id
,lev
);
6093 /// Send a message to a player in game
6094 bool ChatHandler::HandleSendMessageCommand(const char* args
)
6096 ///- Get the command line arguments
6097 char* name_str
= strtok((char*)args
, " ");
6098 char* msg_str
= strtok(NULL
, "");
6100 if(!name_str
|| !msg_str
)
6103 std::string name
= name_str
;
6105 if(!normalizePlayerName(name
))
6108 ///- Find the player and check that he is not logging out.
6109 Player
*rPlayer
= objmgr
.GetPlayer(name
.c_str());
6112 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6113 SetSentErrorMessage(true);
6117 if(rPlayer
->GetSession()->isLogingOut())
6119 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6120 SetSentErrorMessage(true);
6124 ///- Send the message
6125 //Use SendAreaTriggerMessage for fastest delivery.
6126 rPlayer
->GetSession()->SendAreaTriggerMessage("%s", msg_str
);
6127 rPlayer
->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
6129 //Confirmation message
6130 PSendSysMessage(LANG_SENDMESSAGE
,name
.c_str(),msg_str
);