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());
2197 if(inv_count
+mail_count
+auc_count
== 0)
2199 SendSysMessage(LANG_COMMAND_NOITEMFOUND
);
2200 SetSentErrorMessage(true);
2204 PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE
,item_id
,inv_count
+mail_count
+auc_count
,inv_count
,mail_count
,auc_count
);
2209 bool ChatHandler::HandleListObjectCommand(const char* args
)
2214 // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2215 char* cId
= extractKeyFromLink((char*)args
,"Hgameobject_entry");
2219 uint32 go_id
= atol(cId
);
2222 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID
, go_id
);
2223 SetSentErrorMessage(true);
2227 GameObjectInfo
const * gInfo
= objmgr
.GetGameObjectInfo(go_id
);
2230 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID
, go_id
);
2231 SetSentErrorMessage(true);
2235 char* c_count
= strtok(NULL
, " ");
2236 int count
= c_count
? atol(c_count
) : 10;
2241 QueryResult
*result
;
2243 uint32 obj_count
= 0;
2244 result
=WorldDatabase
.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'",go_id
);
2247 obj_count
= (*result
)[0].GetUInt32();
2253 Player
* pl
= m_session
->GetPlayer();
2254 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map, (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ FROM gameobject WHERE id = '%u' ORDER BY order_ ASC LIMIT %u",
2255 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(),go_id
,uint32(count
));
2258 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map FROM gameobject WHERE id = '%u' LIMIT %u",
2259 go_id
,uint32(count
));
2265 Field
*fields
= result
->Fetch();
2266 uint32 guid
= fields
[0].GetUInt32();
2267 float x
= fields
[1].GetFloat();
2268 float y
= fields
[2].GetFloat();
2269 float z
= fields
[3].GetFloat();
2270 int mapid
= fields
[4].GetUInt16();
2273 PSendSysMessage(LANG_GO_LIST_CHAT
, guid
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2275 PSendSysMessage(LANG_GO_LIST_CONSOLE
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2276 } while (result
->NextRow());
2281 PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE
,go_id
,obj_count
);
2285 bool ChatHandler::HandleNearObjectCommand(const char* args
)
2287 float distance
= (!*args
) ? 10 : atol(args
);
2290 Player
* pl
= m_session
->GetPlayer();
2291 QueryResult
*result
= WorldDatabase
.PQuery("SELECT guid, id, position_x, position_y, position_z, map, "
2292 "(POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ "
2293 "FROM gameobject WHERE map='%u' AND (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) <= '%f' ORDER BY order_",
2294 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(),
2295 pl
->GetMapId(),pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(),distance
*distance
);
2301 Field
*fields
= result
->Fetch();
2302 uint32 guid
= fields
[0].GetUInt32();
2303 uint32 entry
= fields
[1].GetUInt32();
2304 float x
= fields
[2].GetFloat();
2305 float y
= fields
[3].GetFloat();
2306 float z
= fields
[4].GetFloat();
2307 int mapid
= fields
[5].GetUInt16();
2309 GameObjectInfo
const * gInfo
= objmgr
.GetGameObjectInfo(entry
);
2314 PSendSysMessage(LANG_GO_LIST_CHAT
, guid
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2317 } while (result
->NextRow());
2322 PSendSysMessage(LANG_COMMAND_NEAROBJMESSAGE
,distance
,count
);
2326 bool ChatHandler::HandleListCreatureCommand(const char* args
)
2331 // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
2332 char* cId
= extractKeyFromLink((char*)args
,"Hcreature_entry");
2336 uint32 cr_id
= atol(cId
);
2339 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID
, cr_id
);
2340 SetSentErrorMessage(true);
2344 CreatureInfo
const* cInfo
= objmgr
.GetCreatureTemplate(cr_id
);
2347 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID
, cr_id
);
2348 SetSentErrorMessage(true);
2352 char* c_count
= strtok(NULL
, " ");
2353 int count
= c_count
? atol(c_count
) : 10;
2358 QueryResult
*result
;
2360 uint32 cr_count
= 0;
2361 result
=WorldDatabase
.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'",cr_id
);
2364 cr_count
= (*result
)[0].GetUInt32();
2370 Player
* pl
= m_session
->GetPlayer();
2371 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map, (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ FROM creature WHERE id = '%u' ORDER BY order_ ASC LIMIT %u",
2372 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(), cr_id
,uint32(count
));
2375 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '%u' LIMIT %u",
2376 cr_id
,uint32(count
));
2382 Field
*fields
= result
->Fetch();
2383 uint32 guid
= fields
[0].GetUInt32();
2384 float x
= fields
[1].GetFloat();
2385 float y
= fields
[2].GetFloat();
2386 float z
= fields
[3].GetFloat();
2387 int mapid
= fields
[4].GetUInt16();
2390 PSendSysMessage(LANG_CREATURE_LIST_CHAT
, guid
, guid
, cInfo
->Name
, x
, y
, z
, mapid
);
2392 PSendSysMessage(LANG_CREATURE_LIST_CONSOLE
, guid
, cInfo
->Name
, x
, y
, z
, mapid
);
2393 } while (result
->NextRow());
2398 PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE
,cr_id
,cr_count
);
2402 bool ChatHandler::HandleLookupItemCommand(const char* args
)
2407 std::string namepart
= args
;
2408 std::wstring wnamepart
;
2410 // converting string that we try to find to lower case
2411 if(!Utf8toWStr(namepart
,wnamepart
))
2414 wstrToLower(wnamepart
);
2418 // Search in `item_template`
2419 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
2421 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
2425 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2428 ItemLocale
const *il
= objmgr
.GetItemLocale(pProto
->ItemId
);
2431 if (il
->Name
.size() > loc_idx
&& !il
->Name
[loc_idx
].empty())
2433 std::string name
= il
->Name
[loc_idx
];
2435 if (Utf8FitTo(name
, wnamepart
))
2438 PSendSysMessage(LANG_ITEM_LIST_CHAT
, id
, id
, name
.c_str());
2440 PSendSysMessage(LANG_ITEM_LIST_CONSOLE
, id
, name
.c_str());
2448 std::string name
= pProto
->Name1
;
2452 if (Utf8FitTo(name
, wnamepart
))
2455 PSendSysMessage(LANG_ITEM_LIST_CHAT
, id
, id
, name
.c_str());
2457 PSendSysMessage(LANG_ITEM_LIST_CONSOLE
, id
, name
.c_str());
2463 SendSysMessage(LANG_COMMAND_NOITEMFOUND
);
2468 bool ChatHandler::HandleLookupItemSetCommand(const char* args
)
2473 std::string namepart
= args
;
2474 std::wstring wnamepart
;
2476 if(!Utf8toWStr(namepart
,wnamepart
))
2479 // converting string that we try to find to lower case
2480 wstrToLower( wnamepart
);
2482 uint32 counter
= 0; // Counter for figure out that we found smth.
2484 // Search in ItemSet.dbc
2485 for (uint32 id
= 0; id
< sItemSetStore
.GetNumRows(); id
++)
2487 ItemSetEntry
const *set
= sItemSetStore
.LookupEntry(id
);
2490 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
2491 std::string name
= set
->name
[loc
];
2495 if (!Utf8FitTo(name
, wnamepart
))
2498 for(; loc
< MAX_LOCALE
; ++loc
)
2500 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
2503 name
= set
->name
[loc
];
2507 if (Utf8FitTo(name
, wnamepart
))
2512 if(loc
< MAX_LOCALE
)
2514 // send item set in "id - [namedlink locale]" format
2516 PSendSysMessage(LANG_ITEMSET_LIST_CHAT
,id
,id
,name
.c_str(),localeNames
[loc
]);
2518 PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE
,id
,name
.c_str(),localeNames
[loc
]);
2523 if (counter
== 0) // if counter == 0 then we found nth
2524 SendSysMessage(LANG_COMMAND_NOITEMSETFOUND
);
2528 bool ChatHandler::HandleLookupSkillCommand(const char* args
)
2533 // can be NULL in console call
2534 Player
* target
= getSelectedPlayer();
2536 std::string namepart
= args
;
2537 std::wstring wnamepart
;
2539 if(!Utf8toWStr(namepart
,wnamepart
))
2542 // converting string that we try to find to lower case
2543 wstrToLower( wnamepart
);
2545 uint32 counter
= 0; // Counter for figure out that we found smth.
2547 // Search in SkillLine.dbc
2548 for (uint32 id
= 0; id
< sSkillLineStore
.GetNumRows(); id
++)
2550 SkillLineEntry
const *skillInfo
= sSkillLineStore
.LookupEntry(id
);
2553 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
2554 std::string name
= skillInfo
->name
[loc
];
2558 if (!Utf8FitTo(name
, wnamepart
))
2561 for(; loc
< MAX_LOCALE
; ++loc
)
2563 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
2566 name
= skillInfo
->name
[loc
];
2570 if (Utf8FitTo(name
, wnamepart
))
2575 if(loc
< MAX_LOCALE
)
2577 char const* knownStr
= "";
2578 if(target
&& target
->HasSkill(id
))
2579 knownStr
= GetMangosString(LANG_KNOWN
);
2581 // send skill in "id - [namedlink locale]" format
2583 PSendSysMessage(LANG_SKILL_LIST_CHAT
,id
,id
,name
.c_str(),localeNames
[loc
],knownStr
);
2585 PSendSysMessage(LANG_SKILL_LIST_CONSOLE
,id
,name
.c_str(),localeNames
[loc
],knownStr
);
2591 if (counter
== 0) // if counter == 0 then we found nth
2592 SendSysMessage(LANG_COMMAND_NOSKILLFOUND
);
2596 bool ChatHandler::HandleLookupSpellCommand(const char* args
)
2601 // can be NULL at console call
2602 Player
* target
= getSelectedPlayer();
2604 std::string namepart
= args
;
2605 std::wstring wnamepart
;
2607 if(!Utf8toWStr(namepart
,wnamepart
))
2610 // converting string that we try to find to lower case
2611 wstrToLower( wnamepart
);
2613 uint32 counter
= 0; // Counter for figure out that we found smth.
2615 // Search in Spell.dbc
2616 for (uint32 id
= 0; id
< sSpellStore
.GetNumRows(); id
++)
2618 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(id
);
2621 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
2622 std::string name
= spellInfo
->SpellName
[loc
];
2626 if (!Utf8FitTo(name
, wnamepart
))
2629 for(; loc
< MAX_LOCALE
; ++loc
)
2631 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
2634 name
= spellInfo
->SpellName
[loc
];
2638 if (Utf8FitTo(name
, wnamepart
))
2643 if(loc
< MAX_LOCALE
)
2645 bool known
= target
&& target
->HasSpell(id
);
2646 bool learn
= (spellInfo
->Effect
[0] == SPELL_EFFECT_LEARN_SPELL
);
2648 uint32 telentCost
= GetTalentSpellCost(id
);
2650 bool talent
= (telentCost
> 0);
2651 bool passive
= IsPassiveSpell(id
);
2652 bool active
= target
&& (target
->HasAura(id
,0) || target
->HasAura(id
,1) || target
->HasAura(id
,2));
2654 // unit32 used to prevent interpreting uint8 as char at output
2655 // find rank of learned spell for learning spell, or talent rank
2656 uint32 rank
= telentCost
? telentCost
: spellmgr
.GetSpellRank(learn
? spellInfo
->EffectTriggerSpell
[0] : id
);
2658 // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
2659 std::ostringstream ss
;
2661 ss
<< id
<< " - |cffffffff|Hspell:" << id
<< "|h[" << name
;
2663 ss
<< id
<< " - " << name
;
2665 // include rank in link name
2667 ss
<< GetMangosString(LANG_SPELL_RANK
) << rank
;
2670 ss
<< " " << localeNames
[loc
] << "]|h|r";
2672 ss
<< " " << localeNames
[loc
];
2675 ss
<< GetMangosString(LANG_TALENT
);
2677 ss
<< GetMangosString(LANG_PASSIVE
);
2679 ss
<< GetMangosString(LANG_LEARN
);
2681 ss
<< GetMangosString(LANG_KNOWN
);
2683 ss
<< GetMangosString(LANG_ACTIVE
);
2685 SendSysMessage(ss
.str().c_str());
2691 if (counter
== 0) // if counter == 0 then we found nth
2692 SendSysMessage(LANG_COMMAND_NOSPELLFOUND
);
2696 bool ChatHandler::HandleLookupQuestCommand(const char* args
)
2701 // can be NULL at console call
2702 Player
* target
= getSelectedPlayer();
2704 std::string namepart
= args
;
2705 std::wstring wnamepart
;
2707 // converting string that we try to find to lower case
2708 if(!Utf8toWStr(namepart
,wnamepart
))
2711 wstrToLower(wnamepart
);
2713 uint32 counter
= 0 ;
2715 ObjectMgr::QuestMap
const& qTemplates
= objmgr
.GetQuestTemplates();
2716 for (ObjectMgr::QuestMap::const_iterator iter
= qTemplates
.begin(); iter
!= qTemplates
.end(); ++iter
)
2718 Quest
* qinfo
= iter
->second
;
2720 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2723 QuestLocale
const *il
= objmgr
.GetQuestLocale(qinfo
->GetQuestId());
2726 if (il
->Title
.size() > loc_idx
&& !il
->Title
[loc_idx
].empty())
2728 std::string title
= il
->Title
[loc_idx
];
2730 if (Utf8FitTo(title
, wnamepart
))
2732 char const* statusStr
= "";
2736 QuestStatus status
= target
->GetQuestStatus(qinfo
->GetQuestId());
2738 if(status
== QUEST_STATUS_COMPLETE
)
2740 if(target
->GetQuestRewardStatus(qinfo
->GetQuestId()))
2741 statusStr
= GetMangosString(LANG_COMMAND_QUEST_REWARDED
);
2743 statusStr
= GetMangosString(LANG_COMMAND_QUEST_COMPLETE
);
2745 else if(status
== QUEST_STATUS_INCOMPLETE
)
2746 statusStr
= GetMangosString(LANG_COMMAND_QUEST_ACTIVE
);
2750 PSendSysMessage(LANG_QUEST_LIST_CHAT
,qinfo
->GetQuestId(),qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2752 PSendSysMessage(LANG_QUEST_LIST_CONSOLE
,qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2760 std::string title
= qinfo
->GetTitle();
2764 if (Utf8FitTo(title
, wnamepart
))
2766 char const* statusStr
= "";
2770 QuestStatus status
= target
->GetQuestStatus(qinfo
->GetQuestId());
2772 if(status
== QUEST_STATUS_COMPLETE
)
2774 if(target
->GetQuestRewardStatus(qinfo
->GetQuestId()))
2775 statusStr
= GetMangosString(LANG_COMMAND_QUEST_REWARDED
);
2777 statusStr
= GetMangosString(LANG_COMMAND_QUEST_COMPLETE
);
2779 else if(status
== QUEST_STATUS_INCOMPLETE
)
2780 statusStr
= GetMangosString(LANG_COMMAND_QUEST_ACTIVE
);
2784 PSendSysMessage(LANG_QUEST_LIST_CHAT
,qinfo
->GetQuestId(),qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2786 PSendSysMessage(LANG_QUEST_LIST_CONSOLE
,qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2793 SendSysMessage(LANG_COMMAND_NOQUESTFOUND
);
2798 bool ChatHandler::HandleLookupCreatureCommand(const char* args
)
2803 std::string namepart
= args
;
2804 std::wstring wnamepart
;
2806 // converting string that we try to find to lower case
2807 if (!Utf8toWStr (namepart
,wnamepart
))
2810 wstrToLower (wnamepart
);
2814 for (uint32 id
= 0; id
< sCreatureStorage
.MaxEntry
; ++id
)
2816 CreatureInfo
const* cInfo
= sCreatureStorage
.LookupEntry
<CreatureInfo
> (id
);
2820 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2823 CreatureLocale
const *cl
= objmgr
.GetCreatureLocale (id
);
2826 if (cl
->Name
.size() > loc_idx
&& !cl
->Name
[loc_idx
].empty ())
2828 std::string name
= cl
->Name
[loc_idx
];
2830 if (Utf8FitTo (name
, wnamepart
))
2833 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str ());
2835 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE
, id
, name
.c_str ());
2843 std::string name
= cInfo
->Name
;
2847 if (Utf8FitTo(name
, wnamepart
))
2850 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str ());
2852 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE
, id
, name
.c_str ());
2858 SendSysMessage (LANG_COMMAND_NOCREATUREFOUND
);
2863 bool ChatHandler::HandleLookupObjectCommand(const char* args
)
2868 std::string namepart
= args
;
2869 std::wstring wnamepart
;
2871 // converting string that we try to find to lower case
2872 if(!Utf8toWStr(namepart
,wnamepart
))
2875 wstrToLower(wnamepart
);
2879 for (uint32 id
= 0; id
< sGOStorage
.MaxEntry
; id
++ )
2881 GameObjectInfo
const* gInfo
= sGOStorage
.LookupEntry
<GameObjectInfo
>(id
);
2885 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2888 GameObjectLocale
const *gl
= objmgr
.GetGameObjectLocale(id
);
2891 if (gl
->Name
.size() > loc_idx
&& !gl
->Name
[loc_idx
].empty())
2893 std::string name
= gl
->Name
[loc_idx
];
2895 if (Utf8FitTo(name
, wnamepart
))
2898 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT
, id
, id
, name
.c_str());
2900 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE
, id
, name
.c_str());
2908 std::string name
= gInfo
->name
;
2912 if(Utf8FitTo(name
, wnamepart
))
2915 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT
, id
, id
, name
.c_str());
2917 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE
, id
, name
.c_str());
2923 SendSysMessage(LANG_COMMAND_NOGAMEOBJECTFOUND
);
2928 /** \brief GM command level 3 - Create a guild.
2930 * This command allows a GM (level 3) to create a guild.
2932 * The "args" parameter contains the name of the guild leader
2933 * and then the name of the guild.
2936 bool ChatHandler::HandleGuildCreateCommand(const char* args
)
2942 char *lname
= strtok ((char*)args
, " ");
2943 char *gname
= strtok (NULL
, "");
2950 SendSysMessage (LANG_INSERT_GUILD_NAME
);
2951 SetSentErrorMessage (true);
2955 std::string guildname
= gname
;
2957 Player
* player
= ObjectAccessor::Instance ().FindPlayerByName (lname
);
2960 SendSysMessage (LANG_PLAYER_NOT_FOUND
);
2961 SetSentErrorMessage (true);
2965 if (player
->GetGuildId())
2967 SendSysMessage (LANG_PLAYER_IN_GUILD
);
2971 Guild
*guild
= new Guild
;
2972 if (!guild
->create (player
->GetGUID (),guildname
))
2975 SendSysMessage (LANG_GUILD_NOT_CREATED
);
2976 SetSentErrorMessage (true);
2980 objmgr
.AddGuild (guild
);
2984 bool ChatHandler::HandleGuildInviteCommand(const char *args
)
2989 char* par1
= strtok ((char*)args
, " ");
2990 char* par2
= strtok (NULL
, "");
2994 std::string glName
= par2
;
2995 Guild
* targetGuild
= objmgr
.GetGuildByName (glName
);
2999 std::string plName
= par1
;
3000 if (!normalizePlayerName (plName
))
3002 SendSysMessage (LANG_PLAYER_NOT_FOUND
);
3003 SetSentErrorMessage (true);
3008 if (Player
* targetPlayer
= ObjectAccessor::Instance ().FindPlayerByName (plName
.c_str ()))
3009 plGuid
= targetPlayer
->GetGUID ();
3011 plGuid
= objmgr
.GetPlayerGUIDByName (plName
.c_str ());
3016 // players's guild membership checked in AddMember before add
3017 if (!targetGuild
->AddMember (plGuid
,targetGuild
->GetLowestRank ()))
3023 bool ChatHandler::HandleGuildUninviteCommand(const char *args
)
3028 char* par1
= strtok ((char*)args
, " ");
3032 std::string plName
= par1
;
3033 if (!normalizePlayerName (plName
))
3035 SendSysMessage (LANG_PLAYER_NOT_FOUND
);
3036 SetSentErrorMessage (true);
3042 if (Player
* targetPlayer
= ObjectAccessor::Instance ().FindPlayerByName (plName
.c_str ()))
3044 plGuid
= targetPlayer
->GetGUID ();
3045 glId
= targetPlayer
->GetGuildId ();
3049 plGuid
= objmgr
.GetPlayerGUIDByName (plName
.c_str ());
3050 glId
= Player::GetGuildIdFromDB (plGuid
);
3053 if (!plGuid
|| !glId
)
3056 Guild
* targetGuild
= objmgr
.GetGuildById (glId
);
3060 targetGuild
->DelMember (plGuid
);
3065 bool ChatHandler::HandleGuildRankCommand(const char *args
)
3070 char* par1
= strtok ((char*)args
, " ");
3071 char* par2
= strtok (NULL
, " ");
3074 std::string plName
= par1
;
3075 if (!normalizePlayerName (plName
))
3077 SendSysMessage (LANG_PLAYER_NOT_FOUND
);
3078 SetSentErrorMessage (true);
3084 if (Player
* targetPlayer
= ObjectAccessor::Instance ().FindPlayerByName (plName
.c_str ()))
3086 plGuid
= targetPlayer
->GetGUID ();
3087 glId
= targetPlayer
->GetGuildId ();
3091 plGuid
= objmgr
.GetPlayerGUIDByName (plName
.c_str ());
3092 glId
= Player::GetGuildIdFromDB (plGuid
);
3095 if (!plGuid
|| !glId
)
3098 Guild
* targetGuild
= objmgr
.GetGuildById (glId
);
3102 uint32 newrank
= uint32 (atoi (par2
));
3103 if (newrank
> targetGuild
->GetLowestRank ())
3106 targetGuild
->ChangeRank (plGuid
,newrank
);
3111 bool ChatHandler::HandleGuildDeleteCommand(const char* args
)
3116 char* par1
= strtok ((char*)args
, " ");
3120 std::string gld
= par1
;
3122 Guild
* targetGuild
= objmgr
.GetGuildByName (gld
);
3126 targetGuild
->Disband ();
3131 bool ChatHandler::HandleGetDistanceCommand(const char* /*args*/)
3133 Unit
* pUnit
= getSelectedUnit();
3137 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3138 SetSentErrorMessage(true);
3142 PSendSysMessage(LANG_DISTANCE
, m_session
->GetPlayer()->GetDistance(pUnit
),m_session
->GetPlayer()->GetDistance2d(pUnit
));
3149 bool ChatHandler::HandleAddWeaponCommand(const char* /*args*/)
3154 uint64 guid = m_session->GetPlayer()->GetSelection();
3157 SendSysMessage(LANG_NO_SELECTION);
3161 Creature *pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
3165 SendSysMessage(LANG_SELECT_CREATURE);
3169 char* pSlotID = strtok((char*)args, " ");
3173 char* pItemID = strtok(NULL, " ");
3177 uint32 ItemID = atoi(pItemID);
3178 uint32 SlotID = atoi(pSlotID);
3180 ItemPrototype* tmpItem = objmgr.GetItemPrototype(ItemID);
3188 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID);
3192 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID);
3196 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID);
3200 PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST,SlotID);
3206 PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT,ItemID,tmpItem->Name1,SlotID);
3211 PSendSysMessage(LANG_ITEM_NOT_FOUND,ItemID);
3218 bool ChatHandler::HandleDieCommand(const char* /*args*/)
3220 Unit
* target
= getSelectedUnit();
3222 if(!target
|| !m_session
->GetPlayer()->GetSelection())
3224 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3225 SetSentErrorMessage(true);
3229 if( target
->isAlive() )
3231 m_session
->GetPlayer()->DealDamage(target
, target
->GetHealth(), NULL
, DIRECT_DAMAGE
, SPELL_SCHOOL_MASK_NORMAL
, NULL
, false);
3237 bool ChatHandler::HandleDamageCommand(const char * args
)
3242 Unit
* target
= getSelectedUnit();
3244 if(!target
|| !m_session
->GetPlayer()->GetSelection())
3246 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3247 SetSentErrorMessage(true);
3251 if( !target
->isAlive() )
3254 char* damageStr
= strtok((char*)args
, " ");
3258 int32 damage
= atoi((char*)damageStr
);
3262 char* schoolStr
= strtok((char*)NULL
, " ");
3264 // flat melee damage without resistence/etc reduction
3267 m_session
->GetPlayer()->DealDamage(target
, damage
, NULL
, DIRECT_DAMAGE
, SPELL_SCHOOL_MASK_NORMAL
, NULL
, false);
3268 m_session
->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2
, target
, 1, SPELL_SCHOOL_MASK_NORMAL
, damage
, 0, 0, VICTIMSTATE_NORMAL
, 0);
3272 uint32 school
= schoolStr
? atoi((char*)schoolStr
) : SPELL_SCHOOL_NORMAL
;
3273 if(school
>= MAX_SPELL_SCHOOL
)
3276 SpellSchoolMask schoolmask
= SpellSchoolMask(1 << school
);
3278 if ( schoolmask
& SPELL_SCHOOL_MASK_NORMAL
)
3279 damage
= m_session
->GetPlayer()->CalcArmorReducedDamage(target
, damage
);
3281 char* spellStr
= strtok((char*)NULL
, " ");
3283 // melee damage by specific school
3289 m_session
->GetPlayer()->CalcAbsorbResist(target
,schoolmask
, SPELL_DIRECT_DAMAGE
, damage
, &absorb
, &resist
);
3291 if (damage
<= absorb
+ resist
)
3294 damage
-= absorb
+ resist
;
3296 m_session
->GetPlayer()->DealDamage(target
, damage
, NULL
, DIRECT_DAMAGE
, schoolmask
, NULL
, false);
3297 m_session
->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2
, target
, 1, schoolmask
, damage
, absorb
, resist
, VICTIMSTATE_NORMAL
, 0);
3303 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3304 uint32 spellid
= extractSpellIdFromLink((char*)args
);
3305 if(!spellid
|| !sSpellStore
.LookupEntry(spellid
))
3308 m_session
->GetPlayer()->SpellNonMeleeDamageLog(target
, spellid
, damage
, false);
3312 bool ChatHandler::HandleModifyArenaCommand(const char * args
)
3317 Player
*target
= getSelectedPlayer();
3320 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3321 SetSentErrorMessage(true);
3325 int32 amount
= (uint32
)atoi(args
);
3327 target
->ModifyArenaPoints(amount
);
3329 PSendSysMessage(LANG_COMMAND_MODIFY_ARENA
, target
->GetName(), target
->GetArenaPoints());
3334 bool ChatHandler::HandleReviveCommand(const char* args
)
3336 Player
* SelectedPlayer
= NULL
;
3340 std::string name
= args
;
3341 if(!normalizePlayerName(name
))
3343 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3344 SetSentErrorMessage(true);
3348 SelectedPlayer
= objmgr
.GetPlayer(name
.c_str());
3351 SelectedPlayer
= getSelectedPlayer();
3355 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3356 SetSentErrorMessage(true);
3360 SelectedPlayer
->ResurrectPlayer(0.5f
);
3361 SelectedPlayer
->SpawnCorpseBones();
3362 SelectedPlayer
->SaveToDB();
3366 bool ChatHandler::HandleAuraCommand(const char* args
)
3368 char* px
= strtok((char*)args
, " ");
3372 Unit
*target
= getSelectedUnit();
3375 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3376 SetSentErrorMessage(true);
3380 uint32 spellID
= (uint32
)atoi(px
);
3381 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry( spellID
);
3384 for(uint32 i
= 0;i
<3;i
++)
3386 uint8 eff
= spellInfo
->Effect
[i
];
3387 if (eff
>=TOTAL_SPELL_EFFECTS
)
3389 if( IsAreaAuraEffect(eff
) ||
3390 eff
== SPELL_EFFECT_APPLY_AURA
||
3391 eff
== SPELL_EFFECT_PERSISTENT_AREA_AURA
)
3393 Aura
*Aur
= CreateAura(spellInfo
, i
, NULL
, target
);
3394 target
->AddAura(Aur
);
3402 bool ChatHandler::HandleUnAuraCommand(const char* args
)
3404 char* px
= strtok((char*)args
, " ");
3408 Unit
*target
= getSelectedUnit();
3411 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3412 SetSentErrorMessage(true);
3416 std::string argstr
= args
;
3417 if (argstr
== "all")
3419 target
->RemoveAllAuras();
3423 uint32 spellID
= (uint32
)atoi(px
);
3424 target
->RemoveAurasDueToSpell(spellID
);
3429 bool ChatHandler::HandleLinkGraveCommand(const char* args
)
3434 char* px
= strtok((char*)args
, " ");
3438 uint32 g_id
= (uint32
)atoi(px
);
3442 char* px2
= strtok(NULL
, " ");
3446 else if (strncmp(px2
,"horde",6)==0)
3448 else if (strncmp(px2
,"alliance",9)==0)
3453 WorldSafeLocsEntry
const* graveyard
= sWorldSafeLocsStore
.LookupEntry(g_id
);
3457 PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST
, g_id
);
3458 SetSentErrorMessage(true);
3462 Player
* player
= m_session
->GetPlayer();
3464 uint32 zoneId
= player
->GetZoneId();
3466 AreaTableEntry
const *areaEntry
= GetAreaEntryByAreaID(zoneId
);
3467 if(!areaEntry
|| areaEntry
->zone
!=0 )
3469 PSendSysMessage(LANG_COMMAND_GRAVEYARDWRONGZONE
, g_id
,zoneId
);
3470 SetSentErrorMessage(true);
3474 if(graveyard
->map_id
!= areaEntry
->mapid
&& g_team
!= 0)
3476 SendSysMessage(LANG_COMMAND_GRAVEYARDWRONGTEAM
);
3477 SetSentErrorMessage(true);
3481 if(objmgr
.AddGraveYardLink(g_id
,player
->GetZoneId(),g_team
))
3482 PSendSysMessage(LANG_COMMAND_GRAVEYARDLINKED
, g_id
,zoneId
);
3484 PSendSysMessage(LANG_COMMAND_GRAVEYARDALRLINKED
, g_id
,zoneId
);
3489 bool ChatHandler::HandleNearGraveCommand(const char* args
)
3493 size_t argslen
= strlen(args
);
3497 else if (strncmp((char*)args
,"horde",argslen
)==0)
3499 else if (strncmp((char*)args
,"alliance",argslen
)==0)
3504 Player
* player
= m_session
->GetPlayer();
3506 WorldSafeLocsEntry
const* graveyard
= objmgr
.GetClosestGraveYard(
3507 player
->GetPositionX(), player
->GetPositionY(), player
->GetPositionZ(),player
->GetMapId(),g_team
);
3511 uint32 g_id
= graveyard
->ID
;
3513 GraveYardData
const* data
= objmgr
.FindGraveYardData(g_id
,player
->GetZoneId());
3516 PSendSysMessage(LANG_COMMAND_GRAVEYARDERROR
,g_id
);
3517 SetSentErrorMessage(true);
3521 g_team
= data
->team
;
3523 std::string team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_NOTEAM
);
3526 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ANY
);
3527 else if(g_team
== HORDE
)
3528 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE
);
3529 else if(g_team
== ALLIANCE
)
3530 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE
);
3532 PSendSysMessage(LANG_COMMAND_GRAVEYARDNEAREST
, g_id
,team_name
.c_str(),player
->GetZoneId());
3536 std::string team_name
;
3539 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ANY
);
3540 else if(g_team
== HORDE
)
3541 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE
);
3542 else if(g_team
== ALLIANCE
)
3543 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE
);
3545 if(g_team
== ~uint32(0))
3546 PSendSysMessage(LANG_COMMAND_ZONENOGRAVEYARDS
, player
->GetZoneId());
3548 PSendSysMessage(LANG_COMMAND_ZONENOGRAFACTION
, player
->GetZoneId(),team_name
.c_str());
3554 bool ChatHandler::HandleSpawnTransportCommand(const char* /*args*/)
3560 bool ChatHandler::HandlePlayEmoteCommand(const char* args
)
3562 uint32 emote
= atoi((char*)args
);
3564 Creature
* target
= getSelectedCreature();
3567 SendSysMessage(LANG_SELECT_CREATURE
);
3568 SetSentErrorMessage(true);
3572 target
->SetUInt32Value(UNIT_NPC_EMOTESTATE
,emote
);
3577 bool ChatHandler::HandleNpcInfoCommand(const char* /*args*/)
3579 Creature
* target
= getSelectedCreature();
3583 SendSysMessage(LANG_SELECT_CREATURE
);
3584 SetSentErrorMessage(true);
3588 uint32 faction
= target
->getFaction();
3589 uint32 npcflags
= target
->GetUInt32Value(UNIT_NPC_FLAGS
);
3590 uint32 displayid
= target
->GetDisplayId();
3591 uint32 nativeid
= target
->GetNativeDisplayId();
3592 uint32 Entry
= target
->GetEntry();
3593 CreatureInfo
const* cInfo
= target
->GetCreatureInfo();
3595 int32 curRespawnDelay
= target
->GetRespawnTimeEx()-time(NULL
);
3596 if(curRespawnDelay
< 0)
3597 curRespawnDelay
= 0;
3598 std::string curRespawnDelayStr
= secsToTimeString(curRespawnDelay
,true);
3599 std::string defRespawnDelayStr
= secsToTimeString(target
->GetRespawnDelay(),true);
3601 PSendSysMessage(LANG_NPCINFO_CHAR
, target
->GetDBTableGUIDLow(), faction
, npcflags
, Entry
, displayid
, nativeid
);
3602 PSendSysMessage(LANG_NPCINFO_LEVEL
, target
->getLevel());
3603 PSendSysMessage(LANG_NPCINFO_HEALTH
,target
->GetCreateHealth(), target
->GetMaxHealth(), target
->GetHealth());
3604 PSendSysMessage(LANG_NPCINFO_FLAGS
, target
->GetUInt32Value(UNIT_FIELD_FLAGS
), target
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
), target
->getFaction());
3605 PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES
, defRespawnDelayStr
.c_str(),curRespawnDelayStr
.c_str());
3606 PSendSysMessage(LANG_NPCINFO_LOOT
, cInfo
->lootid
,cInfo
->pickpocketLootId
,cInfo
->SkinLootId
);
3607 PSendSysMessage(LANG_NPCINFO_DUNGEON_ID
, target
->GetInstanceId());
3608 PSendSysMessage(LANG_NPCINFO_POSITION
,float(target
->GetPositionX()), float(target
->GetPositionY()), float(target
->GetPositionZ()));
3610 if ((npcflags
& UNIT_NPC_FLAG_VENDOR
) )
3612 SendSysMessage(LANG_NPCINFO_VENDOR
);
3614 if ((npcflags
& UNIT_NPC_FLAG_TRAINER
) )
3616 SendSysMessage(LANG_NPCINFO_TRAINER
);
3622 bool ChatHandler::HandleExploreCheatCommand(const char* args
)
3627 int flag
= atoi((char*)args
);
3629 Player
*chr
= getSelectedPlayer();
3632 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3633 SetSentErrorMessage(true);
3639 PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL
, chr
->GetName());
3640 if(chr
!=m_session
->GetPlayer())
3641 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_EXPLORE_SET_ALL
,m_session
->GetPlayer()->GetName());
3645 PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING
, chr
->GetName());
3646 if(chr
!=m_session
->GetPlayer())
3647 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_EXPLORE_SET_NOTHING
,m_session
->GetPlayer()->GetName());
3650 for (uint8 i
=0; i
<128; i
++)
3654 m_session
->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1
+i
,0xFFFFFFFF);
3658 m_session
->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1
+i
,0);
3665 bool ChatHandler::HandleHoverCommand(const char* args
)
3667 char* px
= strtok((char*)args
, " ");
3674 m_session
->GetPlayer()->SetHover(flag
);
3677 SendSysMessage(LANG_HOVER_ENABLED
);
3679 SendSysMessage(LANG_HOVER_DISABLED
);
3684 bool ChatHandler::HandleLevelUpCommand(const char* args
)
3686 char* px
= strtok((char*)args
, " ");
3687 char* py
= strtok((char*)NULL
, " ");
3689 // command format parsing
3690 char* pname
= (char*)NULL
;
3693 if(px
&& py
) // .levelup name level
3695 addlevel
= atoi(py
);
3698 else if(px
&& !py
) // .levelup name OR .levelup level
3700 if(isalpha(px
[0])) // .levelup name
3702 else // .levelup level
3703 addlevel
= atoi(px
);
3705 // else .levelup - nothing do for prepering
3709 uint64 chr_guid
= 0;
3713 if(pname
) // player by name
3716 if(!normalizePlayerName(name
))
3718 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3719 SetSentErrorMessage(true);
3723 chr
= objmgr
.GetPlayer(name
.c_str());
3724 if(!chr
) // not in game
3726 chr_guid
= objmgr
.GetPlayerGUIDByName(name
);
3729 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3730 SetSentErrorMessage(true);
3735 else // player by selection
3737 chr
= getSelectedPlayer();
3741 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3742 SetSentErrorMessage(true);
3746 name
= chr
->GetName();
3749 assert(chr
|| chr_guid
);
3751 int32 oldlevel
= chr
? chr
->getLevel() : Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL
,chr_guid
);
3752 int32 newlevel
= oldlevel
+ addlevel
;
3755 if(newlevel
> 255) // hardcoded maximum level
3760 chr
->GiveLevel(newlevel
);
3761 chr
->InitTalentForLevel();
3762 chr
->SetUInt32Value(PLAYER_XP
,0);
3764 if(oldlevel
== newlevel
)
3765 ChatHandler(chr
).SendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET
);
3767 if(oldlevel
< newlevel
)
3768 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_LEVEL_UP
,newlevel
-oldlevel
);
3770 if(oldlevel
> newlevel
)
3771 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_LEVEL_DOWN
,newlevel
-oldlevel
);
3775 // update levle and XP at level, all other will be updated at loading
3777 Player::LoadValuesArrayFromDB(values
,chr_guid
);
3778 Player::SetUInt32ValueInArray(values
,UNIT_FIELD_LEVEL
,newlevel
);
3779 Player::SetUInt32ValueInArray(values
,PLAYER_XP
,0);
3780 Player::SaveValuesArrayInDB(values
,chr_guid
);
3783 if(m_session
->GetPlayer() != chr
) // including chr==NULL
3784 PSendSysMessage(LANG_YOU_CHANGE_LVL
,name
.c_str(),newlevel
);
3788 bool ChatHandler::HandleShowAreaCommand(const char* args
)
3793 int area
= atoi((char*)args
);
3795 Player
*chr
= getSelectedPlayer();
3798 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3799 SetSentErrorMessage(true);
3803 int offset
= area
/ 32;
3804 uint32 val
= (uint32
)(1 << (area
% 32));
3808 SendSysMessage(LANG_BAD_VALUE
);
3809 SetSentErrorMessage(true);
3813 uint32 currFields
= chr
->GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
3814 chr
->SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
| val
));
3816 SendSysMessage(LANG_EXPLORE_AREA
);
3820 bool ChatHandler::HandleHideAreaCommand(const char* args
)
3825 int area
= atoi((char*)args
);
3827 Player
*chr
= getSelectedPlayer();
3830 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3831 SetSentErrorMessage(true);
3835 int offset
= area
/ 32;
3836 uint32 val
= (uint32
)(1 << (area
% 32));
3840 SendSysMessage(LANG_BAD_VALUE
);
3841 SetSentErrorMessage(true);
3845 uint32 currFields
= chr
->GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
3846 chr
->SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
^ val
));
3848 SendSysMessage(LANG_UNEXPLORE_AREA
);
3852 bool ChatHandler::HandleUpdate(const char* args
)
3860 char* pUpdateIndex
= strtok((char*)args
, " ");
3862 Unit
* chr
= getSelectedUnit();
3865 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3866 SetSentErrorMessage(true);
3874 updateIndex
= atoi(pUpdateIndex
);
3876 if(chr
->GetTypeId() == TYPEID_PLAYER
)
3878 if (updateIndex
>=PLAYER_END
) return true;
3882 if (updateIndex
>=UNIT_END
) return true;
3885 char* pvalue
= strtok(NULL
, " ");
3888 value
=chr
->GetUInt32Value(updateIndex
);
3890 PSendSysMessage(LANG_UPDATE
, chr
->GetGUIDLow(),updateIndex
,value
);
3896 PSendSysMessage(LANG_UPDATE_CHANGE
, chr
->GetGUIDLow(),updateIndex
,value
);
3898 chr
->SetUInt32Value(updateIndex
,value
);
3903 bool ChatHandler::HandleBankCommand(const char* /*args*/)
3905 m_session
->SendShowBank( m_session
->GetPlayer()->GetGUID() );
3910 bool ChatHandler::HandleChangeWeather(const char* args
)
3916 if (!sWorld
.getConfig(CONFIG_WEATHER
))
3918 SendSysMessage(LANG_WEATHER_DISABLED
);
3919 SetSentErrorMessage(true);
3923 //*Change the weather of a cell
3924 char* px
= strtok((char*)args
, " ");
3925 char* py
= strtok(NULL
, " ");
3930 uint32 type
= (uint32
)atoi(px
); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
3931 float grade
= (float)atof(py
); //0 to 1, sending -1 is instand good weather
3933 Player
*player
= m_session
->GetPlayer();
3934 uint32 zoneid
= player
->GetZoneId();
3936 Weather
* wth
= sWorld
.FindWeather(zoneid
);
3939 wth
= sWorld
.AddWeather(zoneid
);
3942 SendSysMessage(LANG_NO_WEATHER
);
3943 SetSentErrorMessage(true);
3947 wth
->SetWeather(WeatherType(type
), grade
);
3952 bool ChatHandler::HandleSetValue(const char* args
)
3957 char* px
= strtok((char*)args
, " ");
3958 char* py
= strtok(NULL
, " ");
3959 char* pz
= strtok(NULL
, " ");
3964 Unit
* target
= getSelectedUnit();
3967 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3968 SetSentErrorMessage(true);
3972 uint64 guid
= target
->GetGUID();
3974 uint32 Opcode
= (uint32
)atoi(px
);
3975 if(Opcode
>= target
->GetValuesCount())
3977 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, GUID_LOPART(guid
), target
->GetValuesCount());
3982 bool isint32
= true;
3984 isint32
= (bool)atoi(pz
);
3987 iValue
= (uint32
)atoi(py
);
3988 sLog
.outDebug(GetMangosString(LANG_SET_UINT
), GUID_LOPART(guid
), Opcode
, iValue
);
3989 target
->SetUInt32Value( Opcode
, iValue
);
3990 PSendSysMessage(LANG_SET_UINT_FIELD
, GUID_LOPART(guid
), Opcode
,iValue
);
3994 fValue
= (float)atof(py
);
3995 sLog
.outDebug(GetMangosString(LANG_SET_FLOAT
), GUID_LOPART(guid
), Opcode
, fValue
);
3996 target
->SetFloatValue( Opcode
, fValue
);
3997 PSendSysMessage(LANG_SET_FLOAT_FIELD
, GUID_LOPART(guid
), Opcode
,fValue
);
4003 bool ChatHandler::HandleGetValue(const char* args
)
4008 char* px
= strtok((char*)args
, " ");
4009 char* pz
= strtok(NULL
, " ");
4014 Unit
* target
= getSelectedUnit();
4017 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4018 SetSentErrorMessage(true);
4022 uint64 guid
= target
->GetGUID();
4024 uint32 Opcode
= (uint32
)atoi(px
);
4025 if(Opcode
>= target
->GetValuesCount())
4027 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, GUID_LOPART(guid
), target
->GetValuesCount());
4032 bool isint32
= true;
4034 isint32
= (bool)atoi(pz
);
4038 iValue
= target
->GetUInt32Value( Opcode
);
4039 sLog
.outDebug(GetMangosString(LANG_GET_UINT
), GUID_LOPART(guid
), Opcode
, iValue
);
4040 PSendSysMessage(LANG_GET_UINT_FIELD
, GUID_LOPART(guid
), Opcode
, iValue
);
4044 fValue
= target
->GetFloatValue( Opcode
);
4045 sLog
.outDebug(GetMangosString(LANG_GET_FLOAT
), GUID_LOPART(guid
), Opcode
, fValue
);
4046 PSendSysMessage(LANG_GET_FLOAT_FIELD
, GUID_LOPART(guid
), Opcode
, fValue
);
4052 bool ChatHandler::HandleSet32Bit(const char* args
)
4057 char* px
= strtok((char*)args
, " ");
4058 char* py
= strtok(NULL
, " ");
4063 uint32 Opcode
= (uint32
)atoi(px
);
4064 uint32 Value
= (uint32
)atoi(py
);
4065 if (Value
> 32) //uint32 = 32 bits
4068 sLog
.outDebug(GetMangosString(LANG_SET_32BIT
), Opcode
, Value
);
4070 m_session
->GetPlayer( )->SetUInt32Value( Opcode
, 2^Value
);
4072 PSendSysMessage(LANG_SET_32BIT_FIELD
, Opcode
,1);
4076 bool ChatHandler::HandleMod32Value(const char* args
)
4081 char* px
= strtok((char*)args
, " ");
4082 char* py
= strtok(NULL
, " ");
4087 uint32 Opcode
= (uint32
)atoi(px
);
4088 int Value
= atoi(py
);
4090 if(Opcode
>= m_session
->GetPlayer()->GetValuesCount())
4092 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, m_session
->GetPlayer()->GetGUIDLow(), m_session
->GetPlayer( )->GetValuesCount());
4096 sLog
.outDebug(GetMangosString(LANG_CHANGE_32BIT
), Opcode
, Value
);
4098 int CurrentValue
= (int)m_session
->GetPlayer( )->GetUInt32Value( Opcode
);
4100 CurrentValue
+= Value
;
4101 m_session
->GetPlayer( )->SetUInt32Value( Opcode
, (uint32
)CurrentValue
);
4103 PSendSysMessage(LANG_CHANGE_32BIT_FIELD
, Opcode
,CurrentValue
);
4108 bool ChatHandler::HandleAddTeleCommand(const char * args
)
4113 Player
*player
=m_session
->GetPlayer();
4117 std::string name
= args
;
4119 if(objmgr
.GetGameTele(name
))
4121 SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST
);
4122 SetSentErrorMessage(true);
4127 tele
.position_x
= player
->GetPositionX();
4128 tele
.position_y
= player
->GetPositionY();
4129 tele
.position_z
= player
->GetPositionZ();
4130 tele
.orientation
= player
->GetOrientation();
4131 tele
.mapId
= player
->GetMapId();
4134 if(objmgr
.AddGameTele(tele
))
4136 SendSysMessage(LANG_COMMAND_TP_ADDED
);
4140 SendSysMessage(LANG_COMMAND_TP_ADDEDERR
);
4141 SetSentErrorMessage(true);
4148 bool ChatHandler::HandleDelTeleCommand(const char * args
)
4153 std::string name
= args
;
4155 if(!objmgr
.DeleteGameTele(name
))
4157 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
4158 SetSentErrorMessage(true);
4162 SendSysMessage(LANG_COMMAND_TP_DELETED
);
4166 bool ChatHandler::HandleListAurasCommand (const char * /*args*/)
4168 Unit
*unit
= getSelectedUnit();
4171 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4172 SetSentErrorMessage(true);
4176 char const* talentStr
= GetMangosString(LANG_TALENT
);
4177 char const* passiveStr
= GetMangosString(LANG_PASSIVE
);
4179 Unit::AuraMap
const& uAuras
= unit
->GetAuras();
4180 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS
, uAuras
.size());
4181 for (Unit::AuraMap::const_iterator itr
= uAuras
.begin(); itr
!= uAuras
.end(); ++itr
)
4183 bool talent
= GetTalentSpellCost(itr
->second
->GetId()) > 0;
4184 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL
, itr
->second
->GetId(), itr
->second
->GetEffIndex(),
4185 itr
->second
->GetModifier()->m_auraname
, itr
->second
->GetAuraDuration(), itr
->second
->GetAuraMaxDuration(),
4186 itr
->second
->GetSpellProto()->SpellName
[m_session
->GetSessionDbcLocale()],
4187 (itr
->second
->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4188 IS_PLAYER_GUID(itr
->second
->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr
->second
->GetCasterGUID()));
4190 for (int i
= 0; i
< TOTAL_AURAS
; i
++)
4192 Unit::AuraList
const& uAuraList
= unit
->GetAurasByType(AuraType(i
));
4193 if (uAuraList
.empty()) continue;
4194 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE
, uAuraList
.size(), i
);
4195 for (Unit::AuraList::const_iterator itr
= uAuraList
.begin(); itr
!= uAuraList
.end(); ++itr
)
4197 bool talent
= GetTalentSpellCost((*itr
)->GetId()) > 0;
4198 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE
, (*itr
)->GetId(), (*itr
)->GetEffIndex(),
4199 (*itr
)->GetSpellProto()->SpellName
[m_session
->GetSessionDbcLocale()],((*itr
)->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4200 IS_PLAYER_GUID((*itr
)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr
)->GetCasterGUID()));
4206 bool ChatHandler::HandleResetHonorCommand (const char * args
)
4208 char* pName
= strtok((char*)args
, "");
4209 Player
*player
= NULL
;
4212 std::string name
= pName
;
4213 if(!normalizePlayerName(name
))
4215 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4216 SetSentErrorMessage(true);
4220 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4221 player
= objmgr
.GetPlayer(guid
);
4224 player
= getSelectedPlayer();
4228 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4232 player
->SetUInt32Value(PLAYER_FIELD_KILLS
, 0);
4233 player
->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS
, 0);
4234 player
->SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY
, 0);
4235 player
->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION
, 0);
4236 player
->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION
, 0);
4241 static bool HandleResetStatsOrLevelHelper(Player
* player
)
4243 PlayerInfo
const *info
= objmgr
.GetPlayerInfo(player
->getRace(), player
->getClass());
4244 if(!info
) return false;
4246 ChrClassesEntry
const* cEntry
= sChrClassesStore
.LookupEntry(player
->getClass());
4249 sLog
.outError("Class %u not found in DBC (Wrong DBC files?)",player
->getClass());
4253 uint8 powertype
= cEntry
->powerType
;
4256 if(powertype
== POWER_RAGE
)
4257 unitfield
= 0x1100EE00;
4258 else if(powertype
== POWER_ENERGY
)
4259 unitfield
= 0x00000000;
4260 else if(powertype
== POWER_MANA
)
4261 unitfield
= 0x0000EE00;
4264 sLog
.outError("Invalid default powertype %u for player (class %u)",powertype
,player
->getClass());
4268 // reset m_form if no aura
4269 if(!player
->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT
))
4270 player
->m_form
= FORM_NONE
;
4272 player
->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS
, DEFAULT_WORLD_OBJECT_SIZE
);
4273 player
->SetFloatValue(UNIT_FIELD_COMBATREACH
, 1.5f
);
4275 player
->setFactionForRace(player
->getRace());
4277 player
->SetUInt32Value(UNIT_FIELD_BYTES_0
, ( ( player
->getRace() ) | ( player
->getClass() << 8 ) | ( player
->getGender() << 16 ) | ( powertype
<< 24 ) ) );
4279 // reset only if player not in some form;
4280 if(player
->m_form
==FORM_NONE
)
4282 switch(player
->getGender())
4285 player
->SetDisplayId(info
->displayId_f
);
4286 player
->SetNativeDisplayId(info
->displayId_f
);
4289 player
->SetDisplayId(info
->displayId_m
);
4290 player
->SetNativeDisplayId(info
->displayId_m
);
4297 // set UNIT_FIELD_BYTES_1 to init state but preserve m_form value
4298 player
->SetUInt32Value(UNIT_FIELD_BYTES_1
, unitfield
);
4299 player
->SetByteValue(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_UNK3
| UNIT_BYTE2_FLAG_UNK5
);
4300 player
->SetByteValue(UNIT_FIELD_BYTES_2
, 3, player
->m_form
);
4302 player
->SetUInt32Value(UNIT_FIELD_FLAGS
, UNIT_FLAG_PVP_ATTACKABLE
);
4304 //-1 is default value
4305 player
->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX
, uint32(-1));
4307 //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000 );
4311 bool ChatHandler::HandleResetLevelCommand(const char * args
)
4313 char* pName
= strtok((char*)args
, "");
4314 Player
*player
= NULL
;
4317 std::string name
= pName
;
4318 if(!normalizePlayerName(name
))
4320 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4321 SetSentErrorMessage(true);
4325 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4326 player
= objmgr
.GetPlayer(guid
);
4329 player
= getSelectedPlayer();
4333 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4334 SetSentErrorMessage(true);
4338 if(!HandleResetStatsOrLevelHelper(player
))
4341 player
->SetLevel(1);
4342 player
->InitStatsForLevel(true);
4343 player
->InitTaxiNodesForLevel();
4344 player
->InitTalentForLevel();
4345 player
->SetUInt32Value(PLAYER_XP
,0);
4347 // reset level to summoned pet
4348 Pet
* pet
= player
->GetPet();
4349 if(pet
&& pet
->getPetType()==SUMMON_PET
)
4350 pet
->InitStatsForLevel(1);
4355 bool ChatHandler::HandleResetStatsCommand(const char * args
)
4357 char* pName
= strtok((char*)args
, "");
4358 Player
*player
= NULL
;
4361 std::string name
= pName
;
4362 if(!normalizePlayerName(name
))
4364 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4365 SetSentErrorMessage(true);
4369 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4370 player
= objmgr
.GetPlayer(guid
);
4373 player
= getSelectedPlayer();
4377 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4378 SetSentErrorMessage(true);
4382 if(!HandleResetStatsOrLevelHelper(player
))
4385 player
->InitStatsForLevel(true);
4386 player
->InitTaxiNodesForLevel();
4387 player
->InitTalentForLevel();
4392 bool ChatHandler::HandleResetSpellsCommand(const char * args
)
4394 char* pName
= strtok((char*)args
, "");
4395 Player
*player
= NULL
;
4396 uint64 playerGUID
= 0;
4399 std::string name
= pName
;
4401 if(!normalizePlayerName(name
))
4403 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4404 SetSentErrorMessage(true);
4408 player
= objmgr
.GetPlayer(name
.c_str());
4410 playerGUID
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4413 player
= getSelectedPlayer();
4415 if(!player
&& !playerGUID
)
4417 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4418 SetSentErrorMessage(true);
4424 player
->resetSpells();
4426 ChatHandler(player
).SendSysMessage(LANG_RESET_SPELLS
);
4428 if(m_session
->GetPlayer()!=player
)
4429 PSendSysMessage(LANG_RESET_SPELLS_ONLINE
,player
->GetName());
4433 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS
), GUID_LOPART(playerGUID
));
4434 PSendSysMessage(LANG_RESET_SPELLS_OFFLINE
,pName
);
4440 bool ChatHandler::HandleResetTalentsCommand(const char * args
)
4442 char* pName
= strtok((char*)args
, "");
4443 Player
*player
= NULL
;
4444 uint64 playerGUID
= 0;
4447 std::string name
= pName
;
4448 if(!normalizePlayerName(name
))
4450 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4451 SetSentErrorMessage(true);
4455 player
= objmgr
.GetPlayer(name
.c_str());
4457 playerGUID
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4460 player
= getSelectedPlayer();
4462 if(!player
&& !playerGUID
)
4464 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4465 SetSentErrorMessage(true);
4471 player
->resetTalents(true);
4473 ChatHandler(player
).SendSysMessage(LANG_RESET_TALENTS
);
4475 if(m_session
->GetPlayer()!=player
)
4476 PSendSysMessage(LANG_RESET_TALENTS_ONLINE
,player
->GetName());
4480 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_TALENTS
), GUID_LOPART(playerGUID
) );
4481 PSendSysMessage(LANG_RESET_TALENTS_OFFLINE
,pName
);
4487 bool ChatHandler::HandleResetAllCommand(const char * args
)
4492 std::string casename
= args
;
4494 AtLoginFlags atLogin
;
4496 // Command specially created as single command to prevent using short case names
4497 if(casename
=="spells")
4499 atLogin
= AT_LOGIN_RESET_SPELLS
;
4500 sWorld
.SendWorldText(LANG_RESETALL_SPELLS
);
4502 else if(casename
=="talents")
4504 atLogin
= AT_LOGIN_RESET_TALENTS
;
4505 sWorld
.SendWorldText(LANG_RESETALL_TALENTS
);
4509 PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE
,args
);
4510 SetSentErrorMessage(true);
4514 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u'",atLogin
);
4515 HashMapHolder
<Player
>::MapType
const& plist
= ObjectAccessor::Instance().GetPlayers();
4516 for(HashMapHolder
<Player
>::MapType::const_iterator itr
= plist
.begin(); itr
!= plist
.end(); ++itr
)
4517 itr
->second
->SetAtLoginFlag(atLogin
);
4522 bool ChatHandler::HandleShutDownCommand(const char* args
)
4527 if(std::string(args
)=="cancel")
4529 sWorld
.ShutdownCancel();
4533 int32 time
= atoi(args
);
4535 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4536 if(time
== 0 && (args
[0]!='0' || args
[1]!='\0') || time
< 0)
4539 sWorld
.ShutdownServ(time
);
4544 bool ChatHandler::HandleRestartCommand(const char* args
)
4549 if(std::string(args
)=="cancel")
4551 sWorld
.ShutdownCancel();
4555 int32 time
= atoi(args
);
4557 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4558 if(time
== 0 && (args
[0]!='0' || args
[1]!='\0') || time
< 0)
4561 sWorld
.ShutdownServ(time
, SHUTDOWN_MASK_RESTART
);
4566 bool ChatHandler::HandleIdleRestartCommand(const char* args
)
4571 if(std::string(args
)=="cancel")
4573 sWorld
.ShutdownCancel();
4577 int32 time
= atoi(args
);
4579 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4580 if(time
== 0 && (args
[0]!='0' || args
[1]!='\0') || time
< 0)
4583 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_RESTART
+SHUTDOWN_MASK_IDLE
);
4588 bool ChatHandler::HandleIdleShutDownCommand(const char* args
)
4593 if(std::string(args
)=="cancel")
4595 sWorld
.ShutdownCancel();
4599 int32 time
= atoi(args
);
4601 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4602 if(time
== 0 && (args
[0]!='0' || args
[1]!='\0') || time
< 0)
4605 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_IDLE
);
4610 bool ChatHandler::HandleAddQuest(const char* args
)
4612 Player
* player
= getSelectedPlayer();
4615 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4616 SetSentErrorMessage(true);
4620 // .addquest #entry'
4621 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4622 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4626 uint32 entry
= atol(cId
);
4628 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
4632 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
,entry
);
4633 SetSentErrorMessage(true);
4637 // check item starting quest (it can work incorrectly if added without item in inventory)
4638 QueryResult
*result
= WorldDatabase
.PQuery("SELECT entry FROM item_template WHERE startquest = '%u' LIMIT 1",entry
);
4641 Field
* fields
= result
->Fetch();
4642 uint32 item_id
= fields
[0].GetUInt32();
4645 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM
, entry
,item_id
);
4646 SetSentErrorMessage(true);
4650 // ok, normal (creature/GO starting) quest
4651 if( player
->CanAddQuest( pQuest
, true ) )
4653 player
->AddQuest( pQuest
, NULL
);
4655 if ( player
->CanCompleteQuest( entry
) )
4656 player
->CompleteQuest( entry
);
4662 bool ChatHandler::HandleRemoveQuest(const char* args
)
4664 Player
* player
= getSelectedPlayer();
4667 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4668 SetSentErrorMessage(true);
4672 // .removequest #entry'
4673 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4674 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4678 uint32 entry
= atol(cId
);
4680 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
4684 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
4685 SetSentErrorMessage(true);
4689 // remove all quest entries for 'entry' from quest log
4690 for(uint8 slot
= 0; slot
< MAX_QUEST_LOG_SIZE
; ++slot
)
4692 uint32 quest
= player
->GetQuestSlotQuestId(slot
);
4695 player
->SetQuestSlot(slot
,0);
4697 // we ignore unequippable quest items in this case, its' still be equipped
4698 player
->TakeQuestSourceItem( quest
, false );
4702 // set quest status to not started (will updated in DB at next save)
4703 player
->SetQuestStatus( entry
, QUEST_STATUS_NONE
);
4705 // reset rewarded for restart repeatable quest
4706 player
->getQuestStatusMap()[entry
].m_rewarded
= false;
4708 SendSysMessage(LANG_COMMAND_QUEST_REMOVED
);
4712 bool ChatHandler::HandleCompleteQuest(const char* args
)
4714 Player
* player
= getSelectedPlayer();
4717 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4718 SetSentErrorMessage(true);
4722 // .quest complete #entry
4723 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4724 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4728 uint32 entry
= atol(cId
);
4730 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
4732 // If player doesn't have the quest
4733 if(!pQuest
|| player
->GetQuestStatus(entry
) == QUEST_STATUS_NONE
)
4735 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
4736 SetSentErrorMessage(true);
4740 // Add quest items for quests that require items
4741 for(uint8 x
= 0; x
< QUEST_OBJECTIVES_COUNT
; ++x
)
4743 uint32 id
= pQuest
->ReqItemId
[x
];
4744 uint32 count
= pQuest
->ReqItemCount
[x
];
4748 uint32 curItemCount
= player
->GetItemCount(id
,true);
4750 ItemPosCountVec dest
;
4751 uint8 msg
= player
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, id
, count
-curItemCount
);
4752 if( msg
== EQUIP_ERR_OK
)
4754 Item
* item
= player
->StoreNewItem( dest
, id
, true);
4755 player
->SendNewItem(item
,count
-curItemCount
,true,false);
4759 // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
4760 for(uint8 i
= 0; i
< QUEST_OBJECTIVES_COUNT
; i
++)
4762 uint32 creature
= pQuest
->ReqCreatureOrGOId
[i
];
4763 uint32 creaturecount
= pQuest
->ReqCreatureOrGOCount
[i
];
4765 if(uint32 spell_id
= pQuest
->ReqSpell
[i
])
4767 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4768 player
->CastedCreatureOrGO(creature
,0,spell_id
);
4770 else if(creature
> 0)
4772 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4773 player
->KilledMonster(creature
,0);
4775 else if(creature
< 0)
4777 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4778 player
->CastedCreatureOrGO(creature
,0,0);
4782 // If the quest requires reputation to complete
4783 if(uint32 repFaction
= pQuest
->GetRepObjectiveFaction())
4785 uint32 repValue
= pQuest
->GetRepObjectiveValue();
4786 uint32 curRep
= player
->GetReputation(repFaction
);
4787 if(curRep
< repValue
)
4789 FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry(repFaction
);
4790 player
->SetFactionReputation(factionEntry
,repValue
);
4794 // If the quest requires money
4795 int32 ReqOrRewMoney
= pQuest
->GetRewOrReqMoney();
4796 if(ReqOrRewMoney
< 0)
4797 player
->ModifyMoney(-ReqOrRewMoney
);
4799 player
->CompleteQuest(entry
);
4803 bool ChatHandler::HandleBanAccountCommand(const char* args
)
4805 return HandleBanHelper(BAN_ACCOUNT
,args
);
4808 bool ChatHandler::HandleBanCharacterCommand(const char* args
)
4810 return HandleBanHelper(BAN_CHARACTER
,args
);
4813 bool ChatHandler::HandleBanIPCommand(const char* args
)
4815 return HandleBanHelper(BAN_IP
,args
);
4818 bool ChatHandler::HandleBanHelper(BanMode mode
, const char* args
)
4823 char* cnameOrIP
= strtok ((char*)args
, " ");
4827 std::string nameOrIP
= cnameOrIP
;
4829 char* duration
= strtok (NULL
," ");
4830 if(!duration
|| !atoi(duration
))
4833 char* reason
= strtok (NULL
,"");
4840 if(!AccountMgr::normilizeString(nameOrIP
))
4842 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
4843 SetSentErrorMessage(true);
4848 if(!normalizePlayerName(nameOrIP
))
4850 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4851 SetSentErrorMessage(true);
4856 if(!IsIPAddress(nameOrIP
.c_str()))
4861 switch(sWorld
.BanAccount(mode
, nameOrIP
, duration
, reason
,m_session
? m_session
->GetPlayerName() : ""))
4864 if(atoi(duration
)>0)
4865 PSendSysMessage(LANG_BAN_YOUBANNED
,nameOrIP
.c_str(),secsToTimeString(TimeStringToSecs(duration
),true).c_str(),reason
);
4867 PSendSysMessage(LANG_BAN_YOUPERMBANNED
,nameOrIP
.c_str(),reason
);
4869 case BAN_SYNTAX_ERROR
:
4875 PSendSysMessage(LANG_BAN_NOTFOUND
,"account",nameOrIP
.c_str());
4878 PSendSysMessage(LANG_BAN_NOTFOUND
,"character",nameOrIP
.c_str());
4881 PSendSysMessage(LANG_BAN_NOTFOUND
,"ip",nameOrIP
.c_str());
4884 SetSentErrorMessage(true);
4891 bool ChatHandler::HandleUnBanAccountCommand(const char* args
)
4893 return HandleUnBanHelper(BAN_ACCOUNT
,args
);
4896 bool ChatHandler::HandleUnBanCharacterCommand(const char* args
)
4898 return HandleUnBanHelper(BAN_CHARACTER
,args
);
4901 bool ChatHandler::HandleUnBanIPCommand(const char* args
)
4903 return HandleUnBanHelper(BAN_IP
,args
);
4906 bool ChatHandler::HandleUnBanHelper(BanMode mode
, const char* args
)
4911 char* cnameOrIP
= strtok ((char*)args
, " ");
4915 std::string nameOrIP
= cnameOrIP
;
4920 if(!AccountMgr::normilizeString(nameOrIP
))
4922 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
4923 SetSentErrorMessage(true);
4928 if(!normalizePlayerName(nameOrIP
))
4930 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4931 SetSentErrorMessage(true);
4936 if(!IsIPAddress(nameOrIP
.c_str()))
4941 if(sWorld
.RemoveBanAccount(mode
,nameOrIP
))
4942 PSendSysMessage(LANG_UNBAN_UNBANNED
,nameOrIP
.c_str());
4944 PSendSysMessage(LANG_UNBAN_ERROR
,nameOrIP
.c_str());
4949 bool ChatHandler::HandleBanInfoAccountCommand(const char* args
)
4954 char* cname
= strtok((char*)args
, "");
4958 std::string account_name
= cname
;
4959 if(!AccountMgr::normilizeString(account_name
))
4961 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
4962 SetSentErrorMessage(true);
4966 uint32 accountid
= accmgr
.GetId(account_name
);
4969 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
4973 return HandleBanInfoHelper(accountid
,account_name
.c_str());
4976 bool ChatHandler::HandleBanInfoCharacterCommand(const char* args
)
4981 char* cname
= strtok ((char*)args
, "");
4985 std::string name
= cname
;
4986 if(!normalizePlayerName(name
))
4988 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4989 SetSentErrorMessage(true);
4993 uint32 accountid
= objmgr
.GetPlayerAccountIdByPlayerName(name
);
4996 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4997 SetSentErrorMessage(true);
5001 std::string accountname
;
5002 if(!accmgr
.GetName(accountid
,accountname
))
5004 PSendSysMessage(LANG_BANINFO_NOCHARACTER
);
5008 return HandleBanInfoHelper(accountid
,accountname
.c_str());
5011 bool ChatHandler::HandleBanInfoHelper(uint32 accountid
, char const* accountname
)
5013 QueryResult
*result
= loginDatabase
.PQuery("SELECT FROM_UNIXTIME(bandate), unbandate-bandate, active, unbandate,banreason,bannedby FROM account_banned WHERE id = '%u' ORDER BY bandate ASC",accountid
);
5016 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN
, accountname
);
5020 PSendSysMessage(LANG_BANINFO_BANHISTORY
,accountname
);
5023 Field
* fields
= result
->Fetch();
5025 time_t unbandate
= time_t(fields
[3].GetUInt64());
5026 bool active
= false;
5027 if(fields
[2].GetBool() && (fields
[1].GetUInt64() == (uint64
)0 ||unbandate
>= time(NULL
)) )
5029 bool permanent
= (fields
[1].GetUInt64() == (uint64
)0);
5030 std::string bantime
= permanent
?GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[1].GetUInt64(), true);
5031 PSendSysMessage(LANG_BANINFO_HISTORYENTRY
,
5032 fields
[0].GetString(), bantime
.c_str(), active
? GetMangosString(LANG_BANINFO_YES
):GetMangosString(LANG_BANINFO_NO
), fields
[4].GetString(), fields
[5].GetString());
5033 }while (result
->NextRow());
5039 bool ChatHandler::HandleBanInfoIPCommand(const char* args
)
5044 char* cIP
= strtok ((char*)args
, "");
5048 if (!IsIPAddress(cIP
))
5051 std::string IP
= cIP
;
5053 loginDatabase
.escape_string(IP
);
5054 QueryResult
*result
= loginDatabase
.PQuery("SELECT ip, FROM_UNIXTIME(bandate), FROM_UNIXTIME(unbandate), unbandate-UNIX_TIMESTAMP(), banreason,bannedby,unbandate-bandate FROM ip_banned WHERE ip = '%s'",IP
.c_str());
5057 PSendSysMessage(LANG_BANINFO_NOIP
);
5061 Field
*fields
= result
->Fetch();
5062 bool permanent
= !fields
[6].GetUInt64();
5063 PSendSysMessage(LANG_BANINFO_IPENTRY
,
5064 fields
[0].GetString(), fields
[1].GetString(), permanent
? GetMangosString(LANG_BANINFO_NEVER
):fields
[2].GetString(),
5065 permanent
? GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[3].GetUInt64(), true).c_str(), fields
[4].GetString(), fields
[5].GetString());
5070 bool ChatHandler::HandleBanListCharacterCommand(const char* args
)
5072 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5074 char* cFilter
= strtok ((char*)args
, " ");
5078 std::string filter
= cFilter
;
5079 loginDatabase
.escape_string(filter
);
5080 QueryResult
* result
= CharacterDatabase
.PQuery("SELECT account FROM characters WHERE name "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'"),filter
.c_str());
5083 PSendSysMessage(LANG_BANLIST_NOCHARACTER
);
5087 return HandleBanListHelper(result
);
5090 bool ChatHandler::HandleBanListAccountCommand(const char* args
)
5092 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5094 char* cFilter
= strtok((char*)args
, " ");
5095 std::string filter
= cFilter
? cFilter
: "";
5096 loginDatabase
.escape_string(filter
);
5098 QueryResult
* result
;
5102 result
= loginDatabase
.Query("SELECT account.id, username FROM account, account_banned"
5103 " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
5107 result
= loginDatabase
.PQuery("SELECT account.id, username FROM account, account_banned"
5108 " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
5114 PSendSysMessage(LANG_BANLIST_NOACCOUNT
);
5118 return HandleBanListHelper(result
);
5121 bool ChatHandler::HandleBanListHelper(QueryResult
* result
)
5123 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT
);
5125 // Chat short output
5130 Field
* fields
= result
->Fetch();
5131 uint32 accountid
= fields
[0].GetUInt32();
5133 QueryResult
* banresult
= loginDatabase
.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid
);
5136 Field
* fields2
= banresult
->Fetch();
5137 PSendSysMessage("%s",fields2
[0].GetString());
5140 } while (result
->NextRow());
5142 // Console wide output
5145 SendSysMessage(LANG_BANLIST_ACCOUNTS
);
5146 SendSysMessage("===============================================================================");
5147 SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER
);
5150 SendSysMessage("-------------------------------------------------------------------------------");
5151 Field
*fields
= result
->Fetch();
5152 uint32 account_id
= fields
[0].GetUInt32 ();
5154 std::string account_name
;
5156 // "account" case, name can be get in same quary
5157 if(result
->GetFieldCount() > 1)
5158 account_name
= fields
[1].GetCppString();
5159 // "character" case, name need extract from another DB
5161 accmgr
.GetName (account_id
,account_name
);
5163 // No SQL injection. id is uint32.
5164 QueryResult
*banInfo
= loginDatabase
.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id
);
5167 Field
*fields2
= banInfo
->Fetch();
5170 time_t t_ban
= fields2
[0].GetUInt64();
5171 tm
* aTm_ban
= localtime(&t_ban
);
5173 if (fields2
[0].GetUInt64() == fields2
[1].GetUInt64())
5175 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5176 account_name
.c_str(),aTm_ban
->tm_year
%100, aTm_ban
->tm_mon
+1, aTm_ban
->tm_mday
, aTm_ban
->tm_hour
, aTm_ban
->tm_min
,
5177 fields2
[2].GetString(),fields2
[3].GetString());
5181 time_t t_unban
= fields2
[1].GetUInt64();
5182 tm
* aTm_unban
= localtime(&t_unban
);
5183 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5184 account_name
.c_str(),aTm_ban
->tm_year
%100, aTm_ban
->tm_mon
+1, aTm_ban
->tm_mday
, aTm_ban
->tm_hour
, aTm_ban
->tm_min
,
5185 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5186 fields2
[2].GetString(),fields2
[3].GetString());
5188 }while ( banInfo
->NextRow() );
5191 }while( result
->NextRow() );
5192 SendSysMessage("===============================================================================");
5199 bool ChatHandler::HandleBanListIPCommand(const char* args
)
5201 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5203 char* cFilter
= strtok((char*)args
, " ");
5204 std::string filter
= cFilter
? cFilter
: "";
5205 loginDatabase
.escape_string(filter
);
5207 QueryResult
* result
;
5211 result
= loginDatabase
.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5212 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
5213 " ORDER BY unbandate" );
5217 result
= loginDatabase
.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5218 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")
5219 " ORDER BY unbandate",filter
.c_str() );
5224 PSendSysMessage(LANG_BANLIST_NOIP
);
5228 PSendSysMessage(LANG_BANLIST_MATCHINGIP
);
5229 // Chat short output
5234 Field
* fields
= result
->Fetch();
5235 PSendSysMessage("%s",fields
[0].GetString());
5236 } while (result
->NextRow());
5238 // Console wide output
5241 SendSysMessage(LANG_BANLIST_IPS
);
5242 SendSysMessage("===============================================================================");
5243 SendSysMessage(LANG_BANLIST_IPS_HEADER
);
5246 SendSysMessage("-------------------------------------------------------------------------------");
5247 Field
*fields
= result
->Fetch();
5248 time_t t_ban
= fields
[1].GetUInt64();
5249 tm
* aTm_ban
= localtime(&t_ban
);
5250 if ( fields
[1].GetUInt64() == fields
[2].GetUInt64() )
5252 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5253 fields
[0].GetString(), aTm_ban
->tm_year
%100, aTm_ban
->tm_mon
+1, aTm_ban
->tm_mday
, aTm_ban
->tm_hour
, aTm_ban
->tm_min
,
5254 fields
[3].GetString(), fields
[4].GetString());
5258 time_t t_unban
= fields
[2].GetUInt64();
5259 tm
* aTm_unban
= localtime(&t_unban
);
5260 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5261 fields
[0].GetString(), aTm_ban
->tm_year
%100, aTm_ban
->tm_mon
+1, aTm_ban
->tm_mday
, aTm_ban
->tm_hour
, aTm_ban
->tm_min
,
5262 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5263 fields
[3].GetString(), fields
[4].GetString());
5265 }while( result
->NextRow() );
5266 SendSysMessage("===============================================================================");
5273 bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
5275 Player
* pl
= m_session
->GetPlayer();
5277 CellPair
p(MaNGOS::ComputeCellPair(pl
->GetPositionX(), pl
->GetPositionY()));
5279 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
5282 MaNGOS::RespawnDo u_do
;
5283 MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
> worker(u_do
);
5285 TypeContainerVisitor
<MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
>, GridTypeMapContainer
> obj_worker(worker
);
5286 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
5287 cell_lock
->Visit(cell_lock
, obj_worker
, *MapManager::Instance().GetMap(pl
->GetMapId(), pl
));
5292 bool ChatHandler::HandleFlyModeCommand(const char* args
)
5297 Unit
*unit
= getSelectedUnit();
5298 if (!unit
|| (unit
->GetTypeId() != TYPEID_PLAYER
))
5299 unit
= m_session
->GetPlayer();
5301 WorldPacket
data(12);
5302 if (strncmp(args
, "on", 3) == 0)
5303 data
.SetOpcode(SMSG_MOVE_SET_CAN_FLY
);
5304 else if (strncmp(args
, "off", 4) == 0)
5305 data
.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY
);
5308 SendSysMessage(LANG_USE_BOL
);
5311 data
.append(unit
->GetPackGUID());
5312 data
<< uint32(0); // unknown
5313 unit
->SendMessageToSet(&data
, true);
5314 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS
, unit
->GetName(), args
);
5318 bool ChatHandler::HandleLoadPDumpCommand(const char *args
)
5323 char * file
= strtok((char*)args
, " ");
5327 char * account
= strtok(NULL
, " ");
5331 std::string account_name
= account
;
5332 if(!AccountMgr::normilizeString(account_name
))
5334 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5335 SetSentErrorMessage(true);
5339 uint32 account_id
= accmgr
.GetId(account_name
);
5342 account_id
= atoi(account
); // use original string
5345 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5346 SetSentErrorMessage(true);
5351 if(!accmgr
.GetName(account_id
,account_name
))
5353 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5354 SetSentErrorMessage(true);
5358 char* guid_str
= NULL
;
5359 char* name_str
= strtok(NULL
, " ");
5365 // normalize the name if specified and check if it exists
5366 if(!normalizePlayerName(name
))
5368 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5369 SetSentErrorMessage(true);
5373 if(!ObjectMgr::IsValidName(name
,true))
5375 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5376 SetSentErrorMessage(true);
5380 guid_str
= strtok(NULL
, " ");
5387 guid
= atoi(guid_str
);
5390 PSendSysMessage(LANG_INVALID_CHARACTER_GUID
);
5391 SetSentErrorMessage(true);
5395 if(objmgr
.GetPlayerAccountIdByGUID(guid
))
5397 PSendSysMessage(LANG_CHARACTER_GUID_IN_USE
,guid
);
5398 SetSentErrorMessage(true);
5403 switch(PlayerDumpReader().LoadDump(file
, account_id
, name
, guid
))
5406 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS
);
5408 case DUMP_FILE_OPEN_ERROR
:
5409 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
5410 SetSentErrorMessage(true);
5412 case DUMP_FILE_BROKEN
:
5413 PSendSysMessage(LANG_DUMP_BROKEN
,file
);
5414 SetSentErrorMessage(true);
5416 case DUMP_TOO_MANY_CHARS
:
5417 PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL
,account_name
,account_id
);
5418 SetSentErrorMessage(true);
5421 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED
);
5422 SetSentErrorMessage(true);
5429 bool ChatHandler::HandleChangeEntryCommand(const char *args
)
5434 uint32 newEntryNum
= atoi(args
);
5438 Unit
* unit
= getSelectedUnit();
5439 if(!unit
|| unit
->GetTypeId() != TYPEID_UNIT
)
5441 SendSysMessage(LANG_SELECT_CREATURE
);
5442 SetSentErrorMessage(true);
5445 Creature
* creature
= (Creature
*)unit
;
5446 if(creature
->UpdateEntry(newEntryNum
))
5447 SendSysMessage(LANG_DONE
);
5449 SendSysMessage(LANG_ERROR
);
5453 bool ChatHandler::HandleWritePDumpCommand(const char *args
)
5458 char* file
= strtok((char*)args
, " ");
5459 char* p2
= strtok(NULL
, " ");
5464 uint32 guid
= objmgr
.GetPlayerGUIDByName(p2
);
5468 if(!objmgr
.GetPlayerAccountIdByGUID(guid
))
5470 PSendSysMessage(LANG_PLAYER_NOT_FOUND
);
5471 SetSentErrorMessage(true);
5475 switch(PlayerDumpWriter().WriteDump(file
, guid
))
5478 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS
);
5480 case DUMP_FILE_OPEN_ERROR
:
5481 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
5482 SetSentErrorMessage(true);
5485 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED
);
5486 SetSentErrorMessage(true);
5493 bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
5495 Unit
* unit
= getSelectedUnit();
5498 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5499 SetSentErrorMessage(true);
5503 PSendSysMessage(LANG_MOVEGENS_LIST
,(unit
->GetTypeId()==TYPEID_PLAYER
? "Player" : "Creature" ),unit
->GetGUIDLow());
5505 MotionMaster
* mm
= unit
->GetMotionMaster();
5506 for(MotionMaster::const_iterator itr
= mm
->begin(); itr
!= mm
->end(); ++itr
)
5508 switch((*itr
)->GetMovementGeneratorType())
5510 case IDLE_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_IDLE
); break;
5511 case RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_RANDOM
); break;
5512 case WAYPOINT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_WAYPOINT
); break;
5513 case ANIMAL_RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_ANIMAL_RANDOM
); break;
5514 case CONFUSED_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_CONFUSED
); break;
5515 case TARGETED_MOTION_TYPE
:
5517 if(unit
->GetTypeId()==TYPEID_PLAYER
)
5519 TargetedMovementGenerator
<Player
> const* mgen
= static_cast<TargetedMovementGenerator
<Player
> const*>(*itr
);
5520 Unit
* target
= mgen
->GetTarget();
5522 PSendSysMessage(LANG_MOVEGENS_TARGETED_PLAYER
,target
->GetName(),target
->GetGUIDLow());
5524 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL
);
5528 TargetedMovementGenerator
<Creature
> const* mgen
= static_cast<TargetedMovementGenerator
<Creature
> const*>(*itr
);
5529 Unit
* target
= mgen
->GetTarget();
5531 PSendSysMessage(LANG_MOVEGENS_TARGETED_CREATURE
,target
->GetName(),target
->GetGUIDLow());
5533 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL
);
5537 case HOME_MOTION_TYPE
:
5538 if(unit
->GetTypeId()==TYPEID_UNIT
)
5541 (*itr
)->GetDestination(x
,y
,z
);
5542 PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE
,x
,y
,z
);
5545 SendSysMessage(LANG_MOVEGENS_HOME_PLAYER
);
5547 case FLIGHT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FLIGHT
); break;
5548 case POINT_MOTION_TYPE
:
5551 (*itr
)->GetDestination(x
,y
,z
);
5552 PSendSysMessage(LANG_MOVEGENS_POINT
,x
,y
,z
);
5555 case FLEEING_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FEAR
); break;
5556 case DISTRACT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_DISTRACT
); break;
5558 PSendSysMessage(LANG_MOVEGENS_UNKNOWN
,(*itr
)->GetMovementGeneratorType());
5565 bool ChatHandler::HandlePLimitCommand(const char *args
)
5569 char* param
= strtok((char*)args
, " ");
5573 int l
= strlen(param
);
5575 if( strncmp(param
,"player",l
) == 0 )
5576 sWorld
.SetPlayerLimit(-SEC_PLAYER
);
5577 else if(strncmp(param
,"moderator",l
) == 0 )
5578 sWorld
.SetPlayerLimit(-SEC_MODERATOR
);
5579 else if(strncmp(param
,"gamemaster",l
) == 0 )
5580 sWorld
.SetPlayerLimit(-SEC_GAMEMASTER
);
5581 else if(strncmp(param
,"administrator",l
) == 0 )
5582 sWorld
.SetPlayerLimit(-SEC_ADMINISTRATOR
);
5583 else if(strncmp(param
,"reset",l
) == 0 )
5584 sWorld
.SetPlayerLimit( sConfig
.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT
) );
5587 int val
= atoi(param
);
5588 if(val
< -SEC_ADMINISTRATOR
) val
= -SEC_ADMINISTRATOR
;
5590 sWorld
.SetPlayerLimit(val
);
5593 // kick all low security level players
5594 if(sWorld
.GetPlayerAmountLimit() > SEC_PLAYER
)
5595 sWorld
.KickAllLess(sWorld
.GetPlayerSecurityLimit());
5598 uint32 pLimit
= sWorld
.GetPlayerAmountLimit();
5599 AccountTypes allowedAccountType
= sWorld
.GetPlayerSecurityLimit();
5600 char const* secName
= "";
5601 switch(allowedAccountType
)
5603 case SEC_PLAYER
: secName
= "Player"; break;
5604 case SEC_MODERATOR
: secName
= "Moderator"; break;
5605 case SEC_GAMEMASTER
: secName
= "Gamemaster"; break;
5606 case SEC_ADMINISTRATOR
: secName
= "Administrator"; break;
5607 default: secName
= "<unknown>"; break;
5610 PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit
,secName
);
5615 bool ChatHandler::HandleCastCommand(const char* args
)
5620 Unit
* target
= getSelectedUnit();
5624 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5625 SetSentErrorMessage(true);
5629 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5630 uint32 spell
= extractSpellIdFromLink((char*)args
);
5634 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5638 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5640 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5641 SetSentErrorMessage(true);
5645 char* trig_str
= strtok(NULL
, " ");
5648 int l
= strlen(trig_str
);
5649 if(strncmp(trig_str
,"triggered",l
) != 0 )
5653 bool triggered
= (trig_str
!= NULL
);
5655 m_session
->GetPlayer()->CastSpell(target
,spell
,triggered
);
5660 bool ChatHandler::HandleCastBackCommand(const char* args
)
5662 Creature
* caster
= getSelectedCreature();
5666 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5667 SetSentErrorMessage(true);
5671 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
5672 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5673 uint32 spell
= extractSpellIdFromLink((char*)args
);
5674 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
5677 char* trig_str
= strtok(NULL
, " ");
5680 int l
= strlen(trig_str
);
5681 if(strncmp(trig_str
,"triggered",l
) != 0 )
5685 bool triggered
= (trig_str
!= NULL
);
5687 // update orientation at server
5688 caster
->SetOrientation(caster
->GetAngle(m_session
->GetPlayer()));
5692 caster
->BuildHeartBeatMsg(&data
);
5693 caster
->SendMessageToSet(&data
,true);
5695 caster
->CastSpell(m_session
->GetPlayer(),spell
,false);
5700 bool ChatHandler::HandleCastDistCommand(const char* args
)
5705 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5706 uint32 spell
= extractSpellIdFromLink((char*)args
);
5710 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5714 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5716 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5717 SetSentErrorMessage(true);
5721 char *distStr
= strtok(NULL
, " ");
5726 sscanf(distStr
, "%f", &dist
);
5728 char* trig_str
= strtok(NULL
, " ");
5731 int l
= strlen(trig_str
);
5732 if(strncmp(trig_str
,"triggered",l
) != 0 )
5736 bool triggered
= (trig_str
!= NULL
);
5739 m_session
->GetPlayer()->GetClosePoint(x
,y
,z
,dist
);
5741 m_session
->GetPlayer()->CastSpell(x
,y
,z
,spell
,triggered
);
5745 bool ChatHandler::HandleCastTargetCommand(const char* args
)
5747 Creature
* caster
= getSelectedCreature();
5751 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5752 SetSentErrorMessage(true);
5756 if(!caster
->getVictim())
5758 SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM
);
5759 SetSentErrorMessage(true);
5763 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5764 uint32 spell
= extractSpellIdFromLink((char*)args
);
5765 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
5768 char* trig_str
= strtok(NULL
, " ");
5771 int l
= strlen(trig_str
);
5772 if(strncmp(trig_str
,"triggered",l
) != 0 )
5776 bool triggered
= (trig_str
!= NULL
);
5778 // update orientation at server
5779 caster
->SetOrientation(caster
->GetAngle(m_session
->GetPlayer()));
5783 caster
->BuildHeartBeatMsg(&data
);
5784 caster
->SendMessageToSet(&data
,true);
5786 caster
->CastSpell(caster
->getVictim(),spell
,false);
5792 ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
5793 Without this function 3rd party scripting library will get linking errors (unresolved external)
5794 when attempting to use the PointMovementGenerator
5796 bool ChatHandler::HandleComeToMeCommand(const char *args
)
5798 Creature
* caster
= getSelectedCreature();
5802 SendSysMessage(LANG_SELECT_CREATURE
);
5803 SetSentErrorMessage(true);
5807 char* newFlagStr
= strtok((char*)args
, " ");
5812 uint32 newFlags
= atoi(newFlagStr
);
5814 caster
->SetUnitMovementFlags(newFlags
);
5816 Player
* pl
= m_session
->GetPlayer();
5818 caster
->GetMotionMaster()->MovePoint(0, pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ());
5822 bool ChatHandler::HandleCastSelfCommand(const char* args
)
5827 Unit
* target
= getSelectedUnit();
5831 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5832 SetSentErrorMessage(true);
5836 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5837 uint32 spell
= extractSpellIdFromLink((char*)args
);
5841 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5845 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5847 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5848 SetSentErrorMessage(true);
5852 target
->CastSpell(target
,spell
,false);
5857 std::string
GetTimeString(uint32 time
)
5859 uint16 days
= time
/ DAY
, hours
= (time
% DAY
) / HOUR
, minute
= (time
% HOUR
) / MINUTE
;
5860 std::ostringstream ss
;
5861 if(days
) ss
<< days
<< "d ";
5862 if(hours
) ss
<< hours
<< "h ";
5863 ss
<< minute
<< "m";
5867 bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
5869 Player
* player
= getSelectedPlayer();
5870 if (!player
) player
= m_session
->GetPlayer();
5872 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
5874 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(i
);
5875 for(Player::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
5877 InstanceSave
*save
= itr
->second
.save
;
5878 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
5879 PSendSysMessage("map: %d inst: %d perm: %s diff: %s canReset: %s TTR: %s", itr
->first
, save
->GetInstanceId(), itr
->second
.perm
? "yes" : "no", save
->GetDifficulty() == DIFFICULTY_NORMAL
? "normal" : "heroic", save
->CanReset() ? "yes" : "no", timeleft
.c_str());
5883 PSendSysMessage("player binds: %d", counter
);
5885 Group
*group
= player
->GetGroup();
5888 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
5890 Group::BoundInstancesMap
&binds
= group
->GetBoundInstances(i
);
5891 for(Group::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
5893 InstanceSave
*save
= itr
->second
.save
;
5894 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
5895 PSendSysMessage("map: %d inst: %d perm: %s diff: %s canReset: %s TTR: %s", itr
->first
, save
->GetInstanceId(), itr
->second
.perm
? "yes" : "no", save
->GetDifficulty() == DIFFICULTY_NORMAL
? "normal" : "heroic", save
->CanReset() ? "yes" : "no", timeleft
.c_str());
5900 PSendSysMessage("group binds: %d", counter
);
5905 bool ChatHandler::HandleInstanceUnbindCommand(const char* args
)
5910 std::string cmd
= args
;
5913 Player
* player
= getSelectedPlayer();
5914 if (!player
) player
= m_session
->GetPlayer();
5916 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
5918 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(i
);
5919 for(Player::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end();)
5921 if(itr
->first
!= player
->GetMapId())
5923 InstanceSave
*save
= itr
->second
.save
;
5924 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
5925 PSendSysMessage("unbinding map: %d inst: %d perm: %s diff: %s canReset: %s TTR: %s", itr
->first
, save
->GetInstanceId(), itr
->second
.perm
? "yes" : "no", save
->GetDifficulty() == DIFFICULTY_NORMAL
? "normal" : "heroic", save
->CanReset() ? "yes" : "no", timeleft
.c_str());
5926 player
->UnbindInstance(itr
, i
);
5933 PSendSysMessage("instances unbound: %d", counter
);
5938 bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
5940 PSendSysMessage("instances loaded: %d", MapManager::Instance().GetNumInstances());
5941 PSendSysMessage("players in instances: %d", MapManager::Instance().GetNumPlayersInInstances());
5942 PSendSysMessage("instance saves: %d", sInstanceSaveManager
.GetNumInstanceSaves());
5943 PSendSysMessage("players bound: %d", sInstanceSaveManager
.GetNumBoundPlayersTotal());
5944 PSendSysMessage("groups bound: %d", sInstanceSaveManager
.GetNumBoundGroupsTotal());
5948 bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
5950 Player
* pl
= m_session
->GetPlayer();
5952 Map
* map
= pl
->GetMap();
5953 if (!map
->IsDungeon())
5955 PSendSysMessage("Map is not a dungeon.");
5956 SetSentErrorMessage(true);
5960 if (!((InstanceMap
*)map
)->GetInstanceData())
5962 PSendSysMessage("Map has no instance data.");
5963 SetSentErrorMessage(true);
5967 ((InstanceMap
*)map
)->GetInstanceData()->SaveToDB();
5971 /// Display the list of GMs
5972 bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
5974 ///- Get the accounts with GM Level >0
5975 QueryResult
*result
= loginDatabase
.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
5978 SendSysMessage(LANG_GMLIST
);
5979 SendSysMessage("========================");
5980 SendSysMessage(LANG_GMLIST_HEADER
);
5981 SendSysMessage("========================");
5983 ///- Circle through them. Display username and GM level
5986 Field
*fields
= result
->Fetch();
5987 PSendSysMessage("|%15s|%6s|", fields
[0].GetString(),fields
[1].GetString());
5988 }while( result
->NextRow() );
5990 PSendSysMessage("========================");
5994 PSendSysMessage(LANG_GMLIST_EMPTY
);
5998 /// Define the 'Message of the day' for the realm
5999 bool ChatHandler::HandleServerSetMotdCommand(const char* args
)
6001 sWorld
.SetMotd(args
);
6002 PSendSysMessage(LANG_MOTD_NEW
, args
);
6006 /// Set/Unset the expansion level for an account
6007 bool ChatHandler::HandleAccountSetAddonCommand(const char* args
)
6009 ///- Get the command line arguments
6010 char *szAcc
= strtok((char*)args
," ");
6011 char *szExp
= strtok(NULL
," ");
6016 std::string account_name
;
6021 Player
* player
= getSelectedPlayer();
6025 account_id
= player
->GetSession()->GetAccountId();
6026 accmgr
.GetName(account_id
,account_name
);
6031 ///- Convert Account name to Upper Format
6032 account_name
= szAcc
;
6033 if(!AccountMgr::normilizeString(account_name
))
6035 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
6036 SetSentErrorMessage(true);
6040 account_id
= accmgr
.GetId(account_name
);
6043 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
6044 SetSentErrorMessage(true);
6049 int lev
=atoi(szExp
); //get int anyway (0 if error)
6054 loginDatabase
.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev
,account_id
);
6055 PSendSysMessage(LANG_ACCOUNT_SETADDON
,account_name
.c_str(),account_id
,lev
);
6059 /// Send a message to a player in game
6060 bool ChatHandler::HandleSendMessageCommand(const char* args
)
6062 ///- Get the command line arguments
6063 char* name_str
= strtok((char*)args
, " ");
6064 char* msg_str
= strtok(NULL
, "");
6066 if(!name_str
|| !msg_str
)
6069 std::string name
= name_str
;
6071 if(!normalizePlayerName(name
))
6074 ///- Find the player and check that he is not logging out.
6075 Player
*rPlayer
= objmgr
.GetPlayer(name
.c_str());
6078 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6079 SetSentErrorMessage(true);
6083 if(rPlayer
->GetSession()->isLogingOut())
6085 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6086 SetSentErrorMessage(true);
6090 ///- Send the message
6091 //Use SendAreaTriggerMessage for fastest delivery.
6092 rPlayer
->GetSession()->SendAreaTriggerMessage("%s", msg_str
);
6093 rPlayer
->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
6095 //Confirmation message
6096 PSendSysMessage(LANG_SENDMESSAGE
,name
.c_str(),msg_str
);