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"
54 bool ChatHandler::HandleReloadCommand(const char* arg
)
56 // this is error catcher for wrong table name in .reload commands
57 PSendSysMessage("Db table with name starting from '%s' not found and can't be reloaded.",arg
);
58 SetSentErrorMessage(true);
62 bool ChatHandler::HandleReloadAllCommand(const char*)
64 HandleReloadAreaTriggerTeleportCommand("");
65 HandleReloadSkillFishingBaseLevelCommand("");
67 HandleReloadAllAreaCommand("");
68 HandleReloadAllLootCommand("");
69 HandleReloadAllNpcCommand("");
70 HandleReloadAllQuestCommand("");
71 HandleReloadAllSpellCommand("");
72 HandleReloadAllItemCommand("");
73 HandleReloadAllLocalesCommand("");
75 HandleReloadCommandCommand("");
76 HandleReloadReservedNameCommand("");
77 HandleReloadMangosStringCommand("");
78 HandleReloadGameTeleCommand("");
82 bool ChatHandler::HandleReloadAllAreaCommand(const char*)
84 //HandleReloadQuestAreaTriggersCommand(""); -- reloaded in HandleReloadAllQuestCommand
85 HandleReloadAreaTriggerTeleportCommand("");
86 HandleReloadAreaTriggerTavernCommand("");
87 HandleReloadGameGraveyardZoneCommand("");
91 bool ChatHandler::HandleReloadAllLootCommand(const char*)
93 sLog
.outString( "Re-Loading Loot Tables..." );
95 SendGlobalSysMessage("DB tables `*_loot_template` reloaded.");
99 bool ChatHandler::HandleReloadAllNpcCommand(const char* /*args*/)
101 HandleReloadNpcGossipCommand("a");
102 HandleReloadNpcOptionCommand("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* /*args*/)
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::HandleReloadNpcOptionCommand(const char*)
350 sLog
.outString( "Re-Loading `npc_option` Table!" );
351 objmgr
.LoadNpcOptions();
352 SendGlobalSysMessage("DB table `npc_option` reloaded.");
356 bool ChatHandler::HandleReloadNpcGossipCommand(const char*)
358 sLog
.outString( "Re-Loading `npc_gossip` Table!" );
359 objmgr
.LoadNpcTextId();
360 SendGlobalSysMessage("DB table `npc_gossip` reloaded.");
364 bool ChatHandler::HandleReloadNpcTrainerCommand(const char*)
366 sLog
.outString( "Re-Loading `npc_trainer` Table!" );
367 objmgr
.LoadTrainerSpell();
368 SendGlobalSysMessage("DB table `npc_trainer` reloaded.");
372 bool ChatHandler::HandleReloadNpcVendorCommand(const char*)
374 sLog
.outString( "Re-Loading `npc_vendor` Table!" );
375 objmgr
.LoadVendors();
376 SendGlobalSysMessage("DB table `npc_vendor` reloaded.");
380 bool ChatHandler::HandleReloadReservedNameCommand(const char*)
382 sLog
.outString( "Loading ReservedNames... (`reserved_name`)" );
383 objmgr
.LoadReservedPlayersNames();
384 SendGlobalSysMessage("DB table `reserved_name` (player reserved names) reloaded.");
388 bool ChatHandler::HandleReloadSkillDiscoveryTemplateCommand(const char* /*args*/)
390 sLog
.outString( "Re-Loading Skill Discovery Table..." );
391 LoadSkillDiscoveryTable();
392 SendGlobalSysMessage("DB table `skill_discovery_template` (recipes discovered at crafting) reloaded.");
396 bool ChatHandler::HandleReloadSkillExtraItemTemplateCommand(const char* /*args*/)
398 sLog
.outString( "Re-Loading Skill Extra Item Table..." );
399 LoadSkillExtraItemTable();
400 SendGlobalSysMessage("DB table `skill_extra_item_template` (extra item creation when crafting) reloaded.");
404 bool ChatHandler::HandleReloadSkillFishingBaseLevelCommand(const char* /*args*/)
406 sLog
.outString( "Re-Loading Skill Fishing base level requirements..." );
407 objmgr
.LoadFishingBaseSkillLevel();
408 SendGlobalSysMessage("DB table `skill_fishing_base_level` (fishing base level for zone/subzone) reloaded.");
412 bool ChatHandler::HandleReloadSpellAffectCommand(const char*)
414 sLog
.outString( "Re-Loading SpellAffect definitions..." );
415 spellmgr
.LoadSpellAffects();
416 SendGlobalSysMessage("DB table `spell_affect` (spell mods apply requirements) reloaded.");
420 bool ChatHandler::HandleReloadSpellChainCommand(const char*)
422 sLog
.outString( "Re-Loading Spell Chain Data... " );
423 spellmgr
.LoadSpellChains();
424 SendGlobalSysMessage("DB table `spell_chain` (spell ranks) reloaded.");
428 bool ChatHandler::HandleReloadSpellElixirCommand(const char*)
430 sLog
.outString( "Re-Loading Spell Elixir types..." );
431 spellmgr
.LoadSpellElixirs();
432 SendGlobalSysMessage("DB table `spell_elixir` (spell elixir types) reloaded.");
436 bool ChatHandler::HandleReloadSpellLearnSpellCommand(const char*)
438 sLog
.outString( "Re-Loading Spell Learn Spells..." );
439 spellmgr
.LoadSpellLearnSpells();
440 SendGlobalSysMessage("DB table `spell_learn_spell` reloaded.");
444 bool ChatHandler::HandleReloadSpellProcEventCommand(const char*)
446 sLog
.outString( "Re-Loading Spell Proc Event conditions..." );
447 spellmgr
.LoadSpellProcEvents();
448 SendGlobalSysMessage("DB table `spell_proc_event` (spell proc trigger requirements) reloaded.");
452 bool ChatHandler::HandleReloadSpellScriptTargetCommand(const char*)
454 sLog
.outString( "Re-Loading SpellsScriptTarget..." );
455 spellmgr
.LoadSpellScriptTarget();
456 SendGlobalSysMessage("DB table `spell_script_target` (spell targets selection in case specific creature/GO requirements) reloaded.");
460 bool ChatHandler::HandleReloadSpellTargetPositionCommand(const char*)
462 sLog
.outString( "Re-Loading Spell target coordinates..." );
463 spellmgr
.LoadSpellTargetPositions();
464 SendGlobalSysMessage("DB table `spell_target_position` (destination coordinates for spell targets) reloaded.");
468 bool ChatHandler::HandleReloadSpellThreatsCommand(const char*)
470 sLog
.outString( "Re-Loading Aggro Spells Definitions...");
471 spellmgr
.LoadSpellThreats();
472 SendGlobalSysMessage("DB table `spell_threat` (spell aggro definitions) reloaded.");
476 bool ChatHandler::HandleReloadSpellPetAurasCommand(const char*)
478 sLog
.outString( "Re-Loading Spell pet auras...");
479 spellmgr
.LoadSpellPetAuras();
480 SendGlobalSysMessage("DB table `spell_pet_auras` reloaded.");
484 bool ChatHandler::HandleReloadPageTextsCommand(const char*)
486 sLog
.outString( "Re-Loading Page Texts..." );
487 objmgr
.LoadPageTexts();
488 SendGlobalSysMessage("DB table `page_texts` reloaded.");
492 bool ChatHandler::HandleReloadItemEnchantementsCommand(const char*)
494 sLog
.outString( "Re-Loading Item Random Enchantments Table..." );
495 LoadRandomEnchantmentsTable();
496 SendGlobalSysMessage("DB table `item_enchantment_template` reloaded.");
500 bool ChatHandler::HandleReloadGameObjectScriptsCommand(const char* arg
)
502 if(sWorld
.IsScriptScheduled())
504 SendSysMessage("DB scripts used currently, please attempt reload later.");
505 SetSentErrorMessage(true);
510 sLog
.outString( "Re-Loading Scripts from `gameobject_scripts`...");
512 objmgr
.LoadGameObjectScripts();
515 SendGlobalSysMessage("DB table `gameobject_scripts` reloaded.");
520 bool ChatHandler::HandleReloadEventScriptsCommand(const char* arg
)
522 if(sWorld
.IsScriptScheduled())
524 SendSysMessage("DB scripts used currently, please attempt reload later.");
525 SetSentErrorMessage(true);
530 sLog
.outString( "Re-Loading Scripts from `event_scripts`...");
532 objmgr
.LoadEventScripts();
535 SendGlobalSysMessage("DB table `event_scripts` reloaded.");
540 bool ChatHandler::HandleReloadQuestEndScriptsCommand(const char* arg
)
542 if(sWorld
.IsScriptScheduled())
544 SendSysMessage("DB scripts used currently, please attempt reload later.");
545 SetSentErrorMessage(true);
550 sLog
.outString( "Re-Loading Scripts from `quest_end_scripts`...");
552 objmgr
.LoadQuestEndScripts();
555 SendGlobalSysMessage("DB table `quest_end_scripts` reloaded.");
560 bool ChatHandler::HandleReloadQuestStartScriptsCommand(const char* arg
)
562 if(sWorld
.IsScriptScheduled())
564 SendSysMessage("DB scripts used currently, please attempt reload later.");
565 SetSentErrorMessage(true);
570 sLog
.outString( "Re-Loading Scripts from `quest_start_scripts`...");
572 objmgr
.LoadQuestStartScripts();
575 SendGlobalSysMessage("DB table `quest_start_scripts` reloaded.");
580 bool ChatHandler::HandleReloadSpellScriptsCommand(const char* arg
)
582 if(sWorld
.IsScriptScheduled())
584 SendSysMessage("DB scripts used currently, please attempt reload later.");
585 SetSentErrorMessage(true);
590 sLog
.outString( "Re-Loading Scripts from `spell_scripts`...");
592 objmgr
.LoadSpellScripts();
595 SendGlobalSysMessage("DB table `spell_scripts` reloaded.");
600 bool ChatHandler::HandleReloadGameGraveyardZoneCommand(const char* /*arg*/)
602 sLog
.outString( "Re-Loading Graveyard-zone links...");
604 objmgr
.LoadGraveyardZones();
606 SendGlobalSysMessage("DB table `game_graveyard_zone` reloaded.");
611 bool ChatHandler::HandleReloadGameTeleCommand(const char* /*arg*/)
613 sLog
.outString( "Re-Loading Game Tele coordinates...");
615 objmgr
.LoadGameTele();
617 SendGlobalSysMessage("DB table `game_tele` reloaded.");
622 bool ChatHandler::HandleReloadLocalesCreatureCommand(const char* /*arg*/)
624 sLog
.outString( "Re-Loading Locales Creature ...");
625 objmgr
.LoadCreatureLocales();
626 SendGlobalSysMessage("DB table `locales_creature` reloaded.");
630 bool ChatHandler::HandleReloadLocalesGameobjectCommand(const char* /*arg*/)
632 sLog
.outString( "Re-Loading Locales Gameobject ... ");
633 objmgr
.LoadGameObjectLocales();
634 SendGlobalSysMessage("DB table `locales_gameobject` reloaded.");
638 bool ChatHandler::HandleReloadLocalesItemCommand(const char* /*arg*/)
640 sLog
.outString( "Re-Loading Locales Item ... ");
641 objmgr
.LoadItemLocales();
642 SendGlobalSysMessage("DB table `locales_item` reloaded.");
646 bool ChatHandler::HandleReloadLocalesNpcTextCommand(const char* /*arg*/)
648 sLog
.outString( "Re-Loading Locales NPC Text ... ");
649 objmgr
.LoadNpcTextLocales();
650 SendGlobalSysMessage("DB table `locales_npc_text` reloaded.");
654 bool ChatHandler::HandleReloadLocalesPageTextCommand(const char* /*arg*/)
656 sLog
.outString( "Re-Loading Locales Page Text ... ");
657 objmgr
.LoadPageTextLocales();
658 SendGlobalSysMessage("DB table `locales_page_text` reloaded.");
662 bool ChatHandler::HandleReloadLocalesQuestCommand(const char* /*arg*/)
664 sLog
.outString( "Re-Loading Locales Quest ... ");
665 objmgr
.LoadQuestLocales();
666 SendGlobalSysMessage("DB table `locales_quest` reloaded.");
670 bool ChatHandler::HandleLoadScriptsCommand(const char* args
)
672 if(!LoadScriptingModule(args
)) return true;
674 sWorld
.SendWorldText(LANG_SCRIPTS_RELOADED
);
678 bool ChatHandler::HandleAccountSetGmLevelCommand(const char* args
)
680 char* arg1
= strtok((char*)args
, " ");
684 /// must be NULL if targeted syntax and must be not nULL if not targeted
685 char* arg2
= strtok(NULL
, " ");
687 std::string targetAccountName
;
688 uint32 targetAccountId
= 0;
689 uint32 targetSecurity
= 0;
691 /// only target player different from self allowed (if targetPlayer!=NULL then not console)
692 Player
* targetPlayer
= getSelectedPlayer();
693 if(targetPlayer
&& m_session
->GetPlayer()!=targetPlayer
)
695 /// wrong command syntax or unexpected targeting
699 /// security level expected in arg2 after this if.
702 targetAccountId
= targetPlayer
->GetSession()->GetAccountId();
703 targetSecurity
= targetPlayer
->GetSession()->GetSecurity();
704 if(!accmgr
.GetName(targetAccountId
,targetAccountName
))
706 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,targetAccountName
.c_str());
707 SetSentErrorMessage(true);
713 /// wrong command syntax (second arg expected)
717 targetAccountName
= arg1
;
718 if(!AccountMgr::normilizeString(targetAccountName
))
720 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,targetAccountName
.c_str());
721 SetSentErrorMessage(true);
725 targetAccountId
= accmgr
.GetId(targetAccountName
);
726 targetSecurity
= accmgr
.GetSecurity(targetAccountId
);
729 int32 gm
= (int32
)atoi(arg2
);
730 if ( gm
< SEC_PLAYER
|| gm
> SEC_ADMINISTRATOR
)
732 SendSysMessage(LANG_BAD_VALUE
);
733 SetSentErrorMessage(true);
737 /// m_session==NULL only for console
738 uint32 plSecurity
= m_session
? m_session
->GetSecurity() : SEC_CONSOLE
;
740 /// can set security level only for target with less security and to less security that we have
741 /// This is also reject self apply in fact
742 if(targetSecurity
>= plSecurity
|| uint32(gm
) >= plSecurity
)
744 SendSysMessage(LANG_YOURS_SECURITY_IS_LOW
);
745 SetSentErrorMessage(true);
751 ChatHandler(targetPlayer
).PSendSysMessage(LANG_YOURS_SECURITY_CHANGED
,GetName(), gm
);
752 targetPlayer
->GetSession()->SetSecurity(gm
);
755 PSendSysMessage(LANG_YOU_CHANGE_SECURITY
, targetAccountName
.c_str(), gm
);
756 loginDatabase
.PExecute("UPDATE account SET gmlevel = '%i' WHERE id = '%u'", gm
, targetAccountId
);
761 /// Set password for account
762 bool ChatHandler::HandleAccountSetPasswordCommand(const char* args
)
767 ///- Get the command line arguments
768 char *szAccount
= strtok ((char*)args
," ");
769 char *szPassword1
= strtok (NULL
," ");
770 char *szPassword2
= strtok (NULL
," ");
772 if (!szAccount
||!szPassword1
|| !szPassword2
)
775 std::string account_name
= szAccount
;
776 if(!AccountMgr::normilizeString(account_name
))
778 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
779 SetSentErrorMessage(true);
783 uint32 targetAccountId
= accmgr
.GetId(account_name
);
784 if (!targetAccountId
)
786 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
787 SetSentErrorMessage(true);
791 uint32 targetSecurity
= accmgr
.GetSecurity(targetAccountId
);
793 /// m_session==NULL only for console
794 uint32 plSecurity
= m_session
? m_session
->GetSecurity() : SEC_CONSOLE
;
796 /// can set password only for target with less security
797 /// This is also reject self apply in fact
798 if (targetSecurity
>= plSecurity
)
800 SendSysMessage (LANG_YOURS_SECURITY_IS_LOW
);
801 SetSentErrorMessage (true);
805 if (strcmp(szPassword1
,szPassword2
))
807 SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH
);
808 SetSentErrorMessage (true);
812 AccountOpResult result
= accmgr
.ChangePassword(targetAccountId
, szPassword1
);
817 SendSysMessage(LANG_COMMAND_PASSWORD
);
819 case AOR_NAME_NOT_EXIST
:
820 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
821 SetSentErrorMessage(true);
823 case AOR_PASS_TOO_LONG
:
824 SendSysMessage(LANG_PASSWORD_TOO_LONG
);
825 SetSentErrorMessage(true);
828 SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD
);
829 SetSentErrorMessage(true);
836 bool ChatHandler::HandleAllowMovementCommand(const char* /*args*/)
838 if(sWorld
.getAllowMovement())
840 sWorld
.SetAllowMovement(false);
841 SendSysMessage(LANG_CREATURE_MOVE_DISABLED
);
845 sWorld
.SetAllowMovement(true);
846 SendSysMessage(LANG_CREATURE_MOVE_ENABLED
);
851 bool ChatHandler::HandleMaxSkillCommand(const char* /*args*/)
853 Player
* SelectedPlayer
= getSelectedPlayer();
856 SendSysMessage(LANG_NO_CHAR_SELECTED
);
857 SetSentErrorMessage(true);
861 // each skills that have max skill value dependent from level seted to current level max skill value
862 SelectedPlayer
->UpdateSkillsToMaxSkillsForLevel();
866 bool ChatHandler::HandleSetSkillCommand(const char* args
)
868 // number or [name] Shift-click form |color|Hskill:skill_id|h[name]|h|r
869 char* skill_p
= extractKeyFromLink((char*)args
,"Hskill");
873 char *level_p
= strtok (NULL
, " ");
878 char *max_p
= strtok (NULL
, " ");
880 int32 skill
= atoi(skill_p
);
884 PSendSysMessage(LANG_INVALID_SKILL_ID
, skill
);
885 SetSentErrorMessage(true);
889 int32 level
= atol (level_p
);
891 Player
* target
= getSelectedPlayer();
894 SendSysMessage(LANG_NO_CHAR_SELECTED
);
895 SetSentErrorMessage(true);
899 SkillLineEntry
const* sl
= sSkillLineStore
.LookupEntry(skill
);
902 PSendSysMessage(LANG_INVALID_SKILL_ID
, skill
);
903 SetSentErrorMessage(true);
907 if(!target
->GetSkillValue(skill
))
909 PSendSysMessage(LANG_SET_SKILL_ERROR
, target
->GetName(), skill
, sl
->name
[0]);
910 SetSentErrorMessage(true);
914 int32 max
= max_p
? atol (max_p
) : target
->GetPureMaxSkillValue(skill
);
916 if( level
<= 0 || level
> max
|| max
<= 0 )
919 target
->SetSkill(skill
, level
, max
);
920 PSendSysMessage(LANG_SET_SKILL
, skill
, sl
->name
[0], target
->GetName(), level
, max
);
925 bool ChatHandler::HandleUnLearnCommand(const char* args
)
930 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
931 uint32 min_id
= extractSpellIdFromLink((char*)args
);
935 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
936 char* tail
= strtok(NULL
,"");
938 uint32 max_id
= extractSpellIdFromLink(tail
);
942 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
948 std::swap(min_id
,max_id
);
953 Player
* target
= getSelectedPlayer();
956 SendSysMessage(LANG_NO_CHAR_SELECTED
);
957 SetSentErrorMessage(true);
961 for(uint32 spell
=min_id
;spell
<max_id
;spell
++)
963 if (target
->HasSpell(spell
))
964 target
->removeSpell(spell
);
966 SendSysMessage(LANG_FORGET_SPELL
);
972 bool ChatHandler::HandleCooldownCommand(const char* args
)
974 Player
* target
= getSelectedPlayer();
977 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
978 SetSentErrorMessage(true);
984 target
->RemoveAllSpellCooldown();
985 PSendSysMessage(LANG_REMOVEALL_COOLDOWN
, target
->GetName());
989 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
990 uint32 spell_id
= extractSpellIdFromLink((char*)args
);
994 if(!sSpellStore
.LookupEntry(spell_id
))
996 PSendSysMessage(LANG_UNKNOWN_SPELL
, target
==m_session
->GetPlayer() ? GetMangosString(LANG_YOU
) : target
->GetName());
997 SetSentErrorMessage(true);
1001 WorldPacket
data( SMSG_CLEAR_COOLDOWN
, (4+8) );
1002 data
<< uint32(spell_id
);
1003 data
<< uint64(target
->GetGUID());
1004 target
->GetSession()->SendPacket(&data
);
1005 target
->RemoveSpellCooldown(spell_id
);
1006 PSendSysMessage(LANG_REMOVE_COOLDOWN
, spell_id
, target
==m_session
->GetPlayer() ? GetMangosString(LANG_YOU
) : target
->GetName());
1011 bool ChatHandler::HandleLearnAllCommand(const char* /*args*/)
1013 static const char *allSpellList
[] =
1396 //"9036", problems with ghost state
1405 //"6718", phasing stealth, annoying for learn all case.
1618 while(strcmp(allSpellList
[loop
], "0"))
1620 uint32 spell
= atol((char*)allSpellList
[loop
++]);
1622 if (m_session
->GetPlayer()->HasSpell(spell
))
1625 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1626 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1628 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1632 m_session
->GetPlayer()->learnSpell(spell
);
1635 SendSysMessage(LANG_COMMAND_LEARN_MANY_SPELLS
);
1640 bool ChatHandler::HandleLearnAllGMCommand(const char* /*args*/)
1642 static const char *gmSpellList
[] =
1644 "24347", // Become A Fish, No Breath Bar
1645 "35132", // Visual Boom
1646 "38488", // Attack 4000-8000 AOE
1647 "38795", // Attack 2000 AOE + Slow Down 90%
1648 "15712", // Attack 200
1649 "1852", // GM Spell Silence
1652 "29878", // Kill My Self
1653 "26644", // More Kill
1655 "28550", //Invisible 24
1656 "23452", //Invisible + Target
1660 uint16 gmSpellIter
= 0;
1661 while( strcmp(gmSpellList
[gmSpellIter
], "0") )
1663 uint32 spell
= atol((char*)gmSpellList
[gmSpellIter
++]);
1665 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1666 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1668 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1672 m_session
->GetPlayer()->learnSpell(spell
);
1675 SendSysMessage(LANG_LEARNING_GM_SKILLS
);
1679 bool ChatHandler::HandleLearnAllMyClassCommand(const char* /*args*/)
1681 HandleLearnAllMySpellsCommand("");
1682 HandleLearnAllMyTalentsCommand("");
1686 bool ChatHandler::HandleLearnAllMySpellsCommand(const char* /*args*/)
1688 ChrClassesEntry
const* clsEntry
= sChrClassesStore
.LookupEntry(m_session
->GetPlayer()->getClass());
1691 uint32 family
= clsEntry
->spellfamily
;
1693 for (uint32 i
= 0; i
< sSpellStore
.GetNumRows(); i
++)
1695 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(i
);
1699 // skip wrong class/race skills
1700 if(!m_session
->GetPlayer()->IsSpellFitByClassAndRace(spellInfo
->Id
))
1703 // skip other spell families
1704 if( spellInfo
->SpellFamilyName
!= family
)
1707 //TODO: skip triggered spells
1709 // skip spells with first rank learned as talent (and all talents then also)
1710 uint32 first_rank
= spellmgr
.GetFirstSpellInChain(spellInfo
->Id
);
1711 if(GetTalentSpellCost(first_rank
) > 0 )
1714 // skip broken spells
1715 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1718 m_session
->GetPlayer()->learnSpell(i
);
1721 SendSysMessage(LANG_COMMAND_LEARN_CLASS_SPELLS
);
1725 static void learnAllHighRanks(Player
* player
, uint32 spellid
)
1727 SpellChainMapNext
const& nextMap
= spellmgr
.GetSpellChainNext();
1728 for(SpellChainMapNext::const_iterator itr
= nextMap
.lower_bound(spellid
); itr
!= nextMap
.upper_bound(spellid
); ++itr
)
1730 player
->learnSpell(itr
->second
);
1731 learnAllHighRanks(player
,itr
->second
);
1735 bool ChatHandler::HandleLearnAllMyTalentsCommand(const char* /*args*/)
1737 Player
* player
= m_session
->GetPlayer();
1738 uint32 classMask
= player
->getClassMask();
1740 for (uint32 i
= 0; i
< sTalentStore
.GetNumRows(); i
++)
1742 TalentEntry
const *talentInfo
= sTalentStore
.LookupEntry(i
);
1746 TalentTabEntry
const *talentTabInfo
= sTalentTabStore
.LookupEntry( talentInfo
->TalentTab
);
1750 if( (classMask
& talentTabInfo
->ClassMask
) == 0 )
1753 // search highest talent rank
1756 for(; rank
>= 0; --rank
)
1758 if(talentInfo
->RankID
[rank
]!=0)
1760 spellid
= talentInfo
->RankID
[rank
];
1765 if(!spellid
) // ??? none spells in talent
1768 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spellid
);
1769 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1772 // learn highest rank of talent
1773 player
->learnSpell(spellid
);
1775 // and learn all non-talent spell ranks (recursive by tree)
1776 learnAllHighRanks(player
,spellid
);
1779 SendSysMessage(LANG_COMMAND_LEARN_CLASS_TALENTS
);
1783 bool ChatHandler::HandleLearnAllLangCommand(const char* /*args*/)
1785 // skipping UNIVERSAL language (0)
1786 for(int i
= 1; i
< LANGUAGES_COUNT
; ++i
)
1787 m_session
->GetPlayer()->learnSpell(lang_description
[i
].spell_id
);
1789 SendSysMessage(LANG_COMMAND_LEARN_ALL_LANG
);
1793 bool ChatHandler::HandleLearnAllDefaultCommand(const char* args
)
1795 char* pName
= strtok((char*)args
, "");
1796 Player
*player
= NULL
;
1799 std::string name
= pName
;
1801 if(!normalizePlayerName(name
))
1803 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1804 SetSentErrorMessage(true);
1808 player
= objmgr
.GetPlayer(name
.c_str());
1811 player
= getSelectedPlayer();
1815 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1816 SetSentErrorMessage(true);
1820 player
->learnDefaultSpells();
1821 player
->learnQuestRewardedSpells();
1823 PSendSysMessage(LANG_COMMAND_LEARN_ALL_DEFAULT_AND_QUEST
,player
->GetName());
1827 bool ChatHandler::HandleLearnCommand(const char* args
)
1829 Player
* targetPlayer
= getSelectedPlayer();
1833 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1834 SetSentErrorMessage(true);
1838 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1839 uint32 spell
= extractSpellIdFromLink((char*)args
);
1840 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
1843 if (targetPlayer
->HasSpell(spell
))
1845 if(targetPlayer
== m_session
->GetPlayer())
1846 SendSysMessage(LANG_YOU_KNOWN_SPELL
);
1848 PSendSysMessage(LANG_TARGET_KNOWN_SPELL
,targetPlayer
->GetName());
1849 SetSentErrorMessage(true);
1853 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1854 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1856 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1857 SetSentErrorMessage(true);
1861 targetPlayer
->learnSpell(spell
);
1866 bool ChatHandler::HandleAddItemCommand(const char* args
)
1873 if(args
[0]=='[') // [name] manual form
1875 char* citemName
= citemName
= strtok((char*)args
, "]");
1877 if(citemName
&& citemName
[0])
1879 std::string itemName
= citemName
+1;
1880 WorldDatabase
.escape_string(itemName
);
1881 QueryResult
*result
= WorldDatabase
.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName
.c_str());
1884 PSendSysMessage(LANG_COMMAND_COULDNOTFIND
, citemName
+1);
1885 SetSentErrorMessage(true);
1888 itemId
= result
->Fetch()->GetUInt16();
1894 else // item_id or [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r
1896 char* cId
= extractKeyFromLink((char*)args
,"Hitem");
1902 char* ccount
= strtok(NULL
, " ");
1907 count
= strtol(ccount
, NULL
, 10);
1912 Player
* pl
= m_session
->GetPlayer();
1913 Player
* plTarget
= getSelectedPlayer();
1917 sLog
.outDetail(GetMangosString(LANG_ADDITEM
), itemId
, count
);
1919 ItemPrototype
const *pProto
= objmgr
.GetItemPrototype(itemId
);
1922 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, itemId
);
1923 SetSentErrorMessage(true);
1930 plTarget
->DestroyItemCount(itemId
, -count
, true, false);
1931 PSendSysMessage(LANG_REMOVEITEM
, itemId
, -count
, plTarget
->GetName());
1936 uint32 noSpaceForCount
= 0;
1938 // check space and find places
1939 ItemPosCountVec dest
;
1940 uint8 msg
= plTarget
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, itemId
, count
, &noSpaceForCount
);
1941 if( msg
!= EQUIP_ERR_OK
) // convert to possible store amount
1942 count
-= noSpaceForCount
;
1944 if( count
== 0 || dest
.empty()) // can't add any
1946 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, itemId
, noSpaceForCount
);
1947 SetSentErrorMessage(true);
1951 Item
* item
= plTarget
->StoreNewItem( dest
, itemId
, true, Item::GenerateItemRandomPropertyId(itemId
));
1953 // remove binding (let GM give it to another player later)
1955 for(ItemPosCountVec::const_iterator itr
= dest
.begin(); itr
!= dest
.end(); ++itr
)
1956 if(Item
* item1
= pl
->GetItemByPos(itr
->pos
))
1957 item1
->SetBinding( false );
1959 if(count
> 0 && item
)
1961 pl
->SendNewItem(item
,count
,false,true);
1963 plTarget
->SendNewItem(item
,count
,true,false);
1966 if(noSpaceForCount
> 0)
1967 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, itemId
, noSpaceForCount
);
1972 bool ChatHandler::HandleAddItemSetCommand(const char* args
)
1977 char* cId
= extractKeyFromLink((char*)args
,"Hitemset"); // number or [name] Shift-click form |color|Hitemset:itemset_id|h[name]|h|r
1981 uint32 itemsetId
= atol(cId
);
1983 // prevent generation all items with itemset field value '0'
1986 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND
,itemsetId
);
1987 SetSentErrorMessage(true);
1991 Player
* pl
= m_session
->GetPlayer();
1992 Player
* plTarget
= getSelectedPlayer();
1996 sLog
.outDetail(GetMangosString(LANG_ADDITEMSET
), itemsetId
);
1999 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
2001 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
2005 if (pProto
->ItemSet
== itemsetId
)
2008 ItemPosCountVec dest
;
2009 uint8 msg
= plTarget
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, pProto
->ItemId
, 1 );
2010 if (msg
== EQUIP_ERR_OK
)
2012 Item
* item
= plTarget
->StoreNewItem( dest
, pProto
->ItemId
, true);
2014 // remove binding (let GM give it to another player later)
2016 item
->SetBinding( false );
2018 pl
->SendNewItem(item
,1,false,true);
2020 plTarget
->SendNewItem(item
,1,true,false);
2024 pl
->SendEquipError( msg
, NULL
, NULL
);
2025 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, pProto
->ItemId
, 1);
2032 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND
,itemsetId
);
2034 SetSentErrorMessage(true);
2041 bool ChatHandler::HandleListItemCommand(const char* args
)
2046 char* cId
= extractKeyFromLink((char*)args
,"Hitem");
2050 uint32 item_id
= atol(cId
);
2053 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
2054 SetSentErrorMessage(true);
2058 ItemPrototype
const* itemProto
= objmgr
.GetItemPrototype(item_id
);
2061 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
2062 SetSentErrorMessage(true);
2066 char* c_count
= strtok(NULL
, " ");
2067 int count
= c_count
? atol(c_count
) : 10;
2072 QueryResult
*result
;
2075 uint32 inv_count
= 0;
2076 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM character_inventory WHERE item_template='%u'",item_id
);
2079 inv_count
= (*result
)[0].GetUInt32();
2083 result
=CharacterDatabase
.PQuery(
2085 "SELECT ci.item, cibag.slot AS bag, ci.slot, ci.guid, characters.account,characters.name "
2086 "FROM character_inventory AS ci LEFT JOIN character_inventory AS cibag ON (cibag.item=ci.bag),characters "
2087 "WHERE ci.item_template='%u' AND ci.guid = characters.guid LIMIT %u ",
2088 item_id
,uint32(count
));
2094 Field
*fields
= result
->Fetch();
2095 uint32 item_guid
= fields
[0].GetUInt32();
2096 uint32 item_bag
= fields
[1].GetUInt32();
2097 uint32 item_slot
= fields
[2].GetUInt32();
2098 uint32 owner_guid
= fields
[3].GetUInt32();
2099 uint32 owner_acc
= fields
[4].GetUInt32();
2100 std::string owner_name
= fields
[5].GetCppString();
2102 char const* item_pos
= 0;
2103 if(Player::IsEquipmentPos(item_bag
,item_slot
))
2104 item_pos
= "[equipped]";
2105 else if(Player::IsInventoryPos(item_bag
,item_slot
))
2106 item_pos
= "[in inventory]";
2107 else if(Player::IsBankPos(item_bag
,item_slot
))
2108 item_pos
= "[in bank]";
2112 PSendSysMessage(LANG_ITEMLIST_SLOT
,
2113 item_guid
,owner_name
.c_str(),owner_guid
,owner_acc
,item_pos
);
2114 } while (result
->NextRow());
2116 int64 res_count
= result
->GetRowCount();
2120 if(count
> res_count
)
2127 uint32 mail_count
= 0;
2128 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM mail_items WHERE item_template='%u'", item_id
);
2131 mail_count
= (*result
)[0].GetUInt32();
2137 result
=CharacterDatabase
.PQuery(
2139 "SELECT mail_items.item_guid, mail.sender, mail.receiver, char_s.account, char_s.name, char_r.account, char_r.name "
2140 "FROM mail,mail_items,characters as char_s,characters as char_r "
2141 "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",
2142 item_id
,uint32(count
));
2151 Field
*fields
= result
->Fetch();
2152 uint32 item_guid
= fields
[0].GetUInt32();
2153 uint32 item_s
= fields
[1].GetUInt32();
2154 uint32 item_r
= fields
[2].GetUInt32();
2155 uint32 item_s_acc
= fields
[3].GetUInt32();
2156 std::string item_s_name
= fields
[4].GetCppString();
2157 uint32 item_r_acc
= fields
[5].GetUInt32();
2158 std::string item_r_name
= fields
[6].GetCppString();
2160 char const* item_pos
= "[in mail]";
2162 PSendSysMessage(LANG_ITEMLIST_MAIL
,
2163 item_guid
,item_s_name
.c_str(),item_s
,item_s_acc
,item_r_name
.c_str(),item_r
,item_r_acc
,item_pos
);
2164 } while (result
->NextRow());
2166 int64 res_count
= result
->GetRowCount();
2170 if(count
> res_count
)
2177 uint32 auc_count
= 0;
2178 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM auctionhouse WHERE item_template='%u'",item_id
);
2181 auc_count
= (*result
)[0].GetUInt32();
2187 result
=CharacterDatabase
.PQuery(
2189 "SELECT auctionhouse.itemguid, auctionhouse.itemowner, characters.account, characters.name "
2190 "FROM auctionhouse,characters WHERE auctionhouse.item_template='%u' AND characters.guid = auctionhouse.itemowner LIMIT %u",
2191 item_id
,uint32(count
));
2200 Field
*fields
= result
->Fetch();
2201 uint32 item_guid
= fields
[0].GetUInt32();
2202 uint32 owner
= fields
[1].GetUInt32();
2203 uint32 owner_acc
= fields
[2].GetUInt32();
2204 std::string owner_name
= fields
[3].GetCppString();
2206 char const* item_pos
= "[in auction]";
2208 PSendSysMessage(LANG_ITEMLIST_AUCTION
, item_guid
, owner_name
.c_str(), owner
, owner_acc
,item_pos
);
2209 } while (result
->NextRow());
2215 uint32 guild_count
= 0;
2216 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_entry) FROM guild_bank_item WHERE item_entry='%u'",item_id
);
2219 guild_count
= (*result
)[0].GetUInt32();
2223 result
=CharacterDatabase
.PQuery(
2225 "SELECT gi.item_guid, gi.guildid, guild.name "
2226 "FROM guild_bank_item AS gi, guild WHERE gi.item_entry='%u' AND gi.guildid = guild.guildid LIMIT %u ",
2227 item_id
,uint32(count
));
2233 Field
*fields
= result
->Fetch();
2234 uint32 item_guid
= fields
[0].GetUInt32();
2235 uint32 guild_guid
= fields
[1].GetUInt32();
2236 std::string guild_name
= fields
[2].GetCppString();
2238 char const* item_pos
= "[in guild bank]";
2240 PSendSysMessage(LANG_ITEMLIST_GUILD
,item_guid
,guild_name
.c_str(),guild_guid
,item_pos
);
2241 } while (result
->NextRow());
2243 int64 res_count
= result
->GetRowCount();
2247 if(count
> res_count
)
2253 if(inv_count
+mail_count
+auc_count
+guild_count
== 0)
2255 SendSysMessage(LANG_COMMAND_NOITEMFOUND
);
2256 SetSentErrorMessage(true);
2260 PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE
,item_id
,inv_count
+mail_count
+auc_count
+guild_count
,inv_count
,mail_count
,auc_count
,guild_count
);
2265 bool ChatHandler::HandleListObjectCommand(const char* args
)
2270 // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2271 char* cId
= extractKeyFromLink((char*)args
,"Hgameobject_entry");
2275 uint32 go_id
= atol(cId
);
2278 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID
, go_id
);
2279 SetSentErrorMessage(true);
2283 GameObjectInfo
const * gInfo
= objmgr
.GetGameObjectInfo(go_id
);
2286 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID
, go_id
);
2287 SetSentErrorMessage(true);
2291 char* c_count
= strtok(NULL
, " ");
2292 int count
= c_count
? atol(c_count
) : 10;
2297 QueryResult
*result
;
2299 uint32 obj_count
= 0;
2300 result
=WorldDatabase
.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'",go_id
);
2303 obj_count
= (*result
)[0].GetUInt32();
2309 Player
* pl
= m_session
->GetPlayer();
2310 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",
2311 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(),go_id
,uint32(count
));
2314 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map FROM gameobject WHERE id = '%u' LIMIT %u",
2315 go_id
,uint32(count
));
2321 Field
*fields
= result
->Fetch();
2322 uint32 guid
= fields
[0].GetUInt32();
2323 float x
= fields
[1].GetFloat();
2324 float y
= fields
[2].GetFloat();
2325 float z
= fields
[3].GetFloat();
2326 int mapid
= fields
[4].GetUInt16();
2329 PSendSysMessage(LANG_GO_LIST_CHAT
, guid
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2331 PSendSysMessage(LANG_GO_LIST_CONSOLE
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2332 } while (result
->NextRow());
2337 PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE
,go_id
,obj_count
);
2341 bool ChatHandler::HandleNearObjectCommand(const char* args
)
2343 float distance
= (!*args
) ? 10 : atol(args
);
2346 Player
* pl
= m_session
->GetPlayer();
2347 QueryResult
*result
= WorldDatabase
.PQuery("SELECT guid, id, position_x, position_y, position_z, map, "
2348 "(POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ "
2349 "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_",
2350 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(),
2351 pl
->GetMapId(),pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(),distance
*distance
);
2357 Field
*fields
= result
->Fetch();
2358 uint32 guid
= fields
[0].GetUInt32();
2359 uint32 entry
= fields
[1].GetUInt32();
2360 float x
= fields
[2].GetFloat();
2361 float y
= fields
[3].GetFloat();
2362 float z
= fields
[4].GetFloat();
2363 int mapid
= fields
[5].GetUInt16();
2365 GameObjectInfo
const * gInfo
= objmgr
.GetGameObjectInfo(entry
);
2370 PSendSysMessage(LANG_GO_LIST_CHAT
, guid
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2373 } while (result
->NextRow());
2378 PSendSysMessage(LANG_COMMAND_NEAROBJMESSAGE
,distance
,count
);
2382 bool ChatHandler::HandleListCreatureCommand(const char* args
)
2387 // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
2388 char* cId
= extractKeyFromLink((char*)args
,"Hcreature_entry");
2392 uint32 cr_id
= atol(cId
);
2395 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID
, cr_id
);
2396 SetSentErrorMessage(true);
2400 CreatureInfo
const* cInfo
= objmgr
.GetCreatureTemplate(cr_id
);
2403 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID
, cr_id
);
2404 SetSentErrorMessage(true);
2408 char* c_count
= strtok(NULL
, " ");
2409 int count
= c_count
? atol(c_count
) : 10;
2414 QueryResult
*result
;
2416 uint32 cr_count
= 0;
2417 result
=WorldDatabase
.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'",cr_id
);
2420 cr_count
= (*result
)[0].GetUInt32();
2426 Player
* pl
= m_session
->GetPlayer();
2427 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",
2428 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(), cr_id
,uint32(count
));
2431 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '%u' LIMIT %u",
2432 cr_id
,uint32(count
));
2438 Field
*fields
= result
->Fetch();
2439 uint32 guid
= fields
[0].GetUInt32();
2440 float x
= fields
[1].GetFloat();
2441 float y
= fields
[2].GetFloat();
2442 float z
= fields
[3].GetFloat();
2443 int mapid
= fields
[4].GetUInt16();
2446 PSendSysMessage(LANG_CREATURE_LIST_CHAT
, guid
, guid
, cInfo
->Name
, x
, y
, z
, mapid
);
2448 PSendSysMessage(LANG_CREATURE_LIST_CONSOLE
, guid
, cInfo
->Name
, x
, y
, z
, mapid
);
2449 } while (result
->NextRow());
2454 PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE
,cr_id
,cr_count
);
2458 bool ChatHandler::HandleLookupItemCommand(const char* args
)
2463 std::string namepart
= args
;
2464 std::wstring wnamepart
;
2466 // converting string that we try to find to lower case
2467 if(!Utf8toWStr(namepart
,wnamepart
))
2470 wstrToLower(wnamepart
);
2474 // Search in `item_template`
2475 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
2477 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
2481 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2484 ItemLocale
const *il
= objmgr
.GetItemLocale(pProto
->ItemId
);
2487 if (il
->Name
.size() > loc_idx
&& !il
->Name
[loc_idx
].empty())
2489 std::string name
= il
->Name
[loc_idx
];
2491 if (Utf8FitTo(name
, wnamepart
))
2494 PSendSysMessage(LANG_ITEM_LIST_CHAT
, id
, id
, name
.c_str());
2496 PSendSysMessage(LANG_ITEM_LIST_CONSOLE
, id
, name
.c_str());
2504 std::string name
= pProto
->Name1
;
2508 if (Utf8FitTo(name
, wnamepart
))
2511 PSendSysMessage(LANG_ITEM_LIST_CHAT
, id
, id
, name
.c_str());
2513 PSendSysMessage(LANG_ITEM_LIST_CONSOLE
, id
, name
.c_str());
2519 SendSysMessage(LANG_COMMAND_NOITEMFOUND
);
2524 bool ChatHandler::HandleLookupItemSetCommand(const char* args
)
2529 std::string namepart
= args
;
2530 std::wstring wnamepart
;
2532 if(!Utf8toWStr(namepart
,wnamepart
))
2535 // converting string that we try to find to lower case
2536 wstrToLower( wnamepart
);
2538 uint32 counter
= 0; // Counter for figure out that we found smth.
2540 // Search in ItemSet.dbc
2541 for (uint32 id
= 0; id
< sItemSetStore
.GetNumRows(); id
++)
2543 ItemSetEntry
const *set
= sItemSetStore
.LookupEntry(id
);
2546 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
2547 std::string name
= set
->name
[loc
];
2551 if (!Utf8FitTo(name
, wnamepart
))
2554 for(; loc
< MAX_LOCALE
; ++loc
)
2556 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
2559 name
= set
->name
[loc
];
2563 if (Utf8FitTo(name
, wnamepart
))
2568 if(loc
< MAX_LOCALE
)
2570 // send item set in "id - [namedlink locale]" format
2572 PSendSysMessage(LANG_ITEMSET_LIST_CHAT
,id
,id
,name
.c_str(),localeNames
[loc
]);
2574 PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE
,id
,name
.c_str(),localeNames
[loc
]);
2579 if (counter
== 0) // if counter == 0 then we found nth
2580 SendSysMessage(LANG_COMMAND_NOITEMSETFOUND
);
2584 bool ChatHandler::HandleLookupSkillCommand(const char* args
)
2589 // can be NULL in console call
2590 Player
* target
= getSelectedPlayer();
2592 std::string namepart
= args
;
2593 std::wstring wnamepart
;
2595 if(!Utf8toWStr(namepart
,wnamepart
))
2598 // converting string that we try to find to lower case
2599 wstrToLower( wnamepart
);
2601 uint32 counter
= 0; // Counter for figure out that we found smth.
2603 // Search in SkillLine.dbc
2604 for (uint32 id
= 0; id
< sSkillLineStore
.GetNumRows(); id
++)
2606 SkillLineEntry
const *skillInfo
= sSkillLineStore
.LookupEntry(id
);
2609 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
2610 std::string name
= skillInfo
->name
[loc
];
2614 if (!Utf8FitTo(name
, wnamepart
))
2617 for(; loc
< MAX_LOCALE
; ++loc
)
2619 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
2622 name
= skillInfo
->name
[loc
];
2626 if (Utf8FitTo(name
, wnamepart
))
2631 if(loc
< MAX_LOCALE
)
2633 char const* knownStr
= "";
2634 if(target
&& target
->HasSkill(id
))
2635 knownStr
= GetMangosString(LANG_KNOWN
);
2637 // send skill in "id - [namedlink locale]" format
2639 PSendSysMessage(LANG_SKILL_LIST_CHAT
,id
,id
,name
.c_str(),localeNames
[loc
],knownStr
);
2641 PSendSysMessage(LANG_SKILL_LIST_CONSOLE
,id
,name
.c_str(),localeNames
[loc
],knownStr
);
2647 if (counter
== 0) // if counter == 0 then we found nth
2648 SendSysMessage(LANG_COMMAND_NOSKILLFOUND
);
2652 bool ChatHandler::HandleLookupSpellCommand(const char* args
)
2657 // can be NULL at console call
2658 Player
* target
= getSelectedPlayer();
2660 std::string namepart
= args
;
2661 std::wstring wnamepart
;
2663 if(!Utf8toWStr(namepart
,wnamepart
))
2666 // converting string that we try to find to lower case
2667 wstrToLower( wnamepart
);
2669 uint32 counter
= 0; // Counter for figure out that we found smth.
2671 // Search in Spell.dbc
2672 for (uint32 id
= 0; id
< sSpellStore
.GetNumRows(); id
++)
2674 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(id
);
2677 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
2678 std::string name
= spellInfo
->SpellName
[loc
];
2682 if (!Utf8FitTo(name
, wnamepart
))
2685 for(; loc
< MAX_LOCALE
; ++loc
)
2687 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
2690 name
= spellInfo
->SpellName
[loc
];
2694 if (Utf8FitTo(name
, wnamepart
))
2699 if(loc
< MAX_LOCALE
)
2701 bool known
= target
&& target
->HasSpell(id
);
2702 bool learn
= (spellInfo
->Effect
[0] == SPELL_EFFECT_LEARN_SPELL
);
2704 uint32 talentCost
= GetTalentSpellCost(id
);
2706 bool talent
= (talentCost
> 0);
2707 bool passive
= IsPassiveSpell(id
);
2708 bool active
= target
&& (target
->HasAura(id
,0) || target
->HasAura(id
,1) || target
->HasAura(id
,2));
2710 // unit32 used to prevent interpreting uint8 as char at output
2711 // find rank of learned spell for learning spell, or talent rank
2712 uint32 rank
= talentCost
? talentCost
: spellmgr
.GetSpellRank(learn
? spellInfo
->EffectTriggerSpell
[0] : id
);
2714 // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
2715 std::ostringstream ss
;
2717 ss
<< id
<< " - |cffffffff|Hspell:" << id
<< "|h[" << name
;
2719 ss
<< id
<< " - " << name
;
2721 // include rank in link name
2723 ss
<< GetMangosString(LANG_SPELL_RANK
) << rank
;
2726 ss
<< " " << localeNames
[loc
] << "]|h|r";
2728 ss
<< " " << localeNames
[loc
];
2731 ss
<< GetMangosString(LANG_TALENT
);
2733 ss
<< GetMangosString(LANG_PASSIVE
);
2735 ss
<< GetMangosString(LANG_LEARN
);
2737 ss
<< GetMangosString(LANG_KNOWN
);
2739 ss
<< GetMangosString(LANG_ACTIVE
);
2741 SendSysMessage(ss
.str().c_str());
2747 if (counter
== 0) // if counter == 0 then we found nth
2748 SendSysMessage(LANG_COMMAND_NOSPELLFOUND
);
2752 bool ChatHandler::HandleLookupQuestCommand(const char* args
)
2757 // can be NULL at console call
2758 Player
* target
= getSelectedPlayer();
2760 std::string namepart
= args
;
2761 std::wstring wnamepart
;
2763 // converting string that we try to find to lower case
2764 if(!Utf8toWStr(namepart
,wnamepart
))
2767 wstrToLower(wnamepart
);
2769 uint32 counter
= 0 ;
2771 ObjectMgr::QuestMap
const& qTemplates
= objmgr
.GetQuestTemplates();
2772 for (ObjectMgr::QuestMap::const_iterator iter
= qTemplates
.begin(); iter
!= qTemplates
.end(); ++iter
)
2774 Quest
* qinfo
= iter
->second
;
2776 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2779 QuestLocale
const *il
= objmgr
.GetQuestLocale(qinfo
->GetQuestId());
2782 if (il
->Title
.size() > loc_idx
&& !il
->Title
[loc_idx
].empty())
2784 std::string title
= il
->Title
[loc_idx
];
2786 if (Utf8FitTo(title
, wnamepart
))
2788 char const* statusStr
= "";
2792 QuestStatus status
= target
->GetQuestStatus(qinfo
->GetQuestId());
2794 if(status
== QUEST_STATUS_COMPLETE
)
2796 if(target
->GetQuestRewardStatus(qinfo
->GetQuestId()))
2797 statusStr
= GetMangosString(LANG_COMMAND_QUEST_REWARDED
);
2799 statusStr
= GetMangosString(LANG_COMMAND_QUEST_COMPLETE
);
2801 else if(status
== QUEST_STATUS_INCOMPLETE
)
2802 statusStr
= GetMangosString(LANG_COMMAND_QUEST_ACTIVE
);
2806 PSendSysMessage(LANG_QUEST_LIST_CHAT
,qinfo
->GetQuestId(),qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2808 PSendSysMessage(LANG_QUEST_LIST_CONSOLE
,qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2816 std::string title
= qinfo
->GetTitle();
2820 if (Utf8FitTo(title
, wnamepart
))
2822 char const* statusStr
= "";
2826 QuestStatus status
= target
->GetQuestStatus(qinfo
->GetQuestId());
2828 if(status
== QUEST_STATUS_COMPLETE
)
2830 if(target
->GetQuestRewardStatus(qinfo
->GetQuestId()))
2831 statusStr
= GetMangosString(LANG_COMMAND_QUEST_REWARDED
);
2833 statusStr
= GetMangosString(LANG_COMMAND_QUEST_COMPLETE
);
2835 else if(status
== QUEST_STATUS_INCOMPLETE
)
2836 statusStr
= GetMangosString(LANG_COMMAND_QUEST_ACTIVE
);
2840 PSendSysMessage(LANG_QUEST_LIST_CHAT
,qinfo
->GetQuestId(),qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2842 PSendSysMessage(LANG_QUEST_LIST_CONSOLE
,qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2849 SendSysMessage(LANG_COMMAND_NOQUESTFOUND
);
2854 bool ChatHandler::HandleLookupCreatureCommand(const char* args
)
2859 std::string namepart
= args
;
2860 std::wstring wnamepart
;
2862 // converting string that we try to find to lower case
2863 if (!Utf8toWStr (namepart
,wnamepart
))
2866 wstrToLower (wnamepart
);
2870 for (uint32 id
= 0; id
< sCreatureStorage
.MaxEntry
; ++id
)
2872 CreatureInfo
const* cInfo
= sCreatureStorage
.LookupEntry
<CreatureInfo
> (id
);
2876 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2879 CreatureLocale
const *cl
= objmgr
.GetCreatureLocale (id
);
2882 if (cl
->Name
.size() > loc_idx
&& !cl
->Name
[loc_idx
].empty ())
2884 std::string name
= cl
->Name
[loc_idx
];
2886 if (Utf8FitTo (name
, wnamepart
))
2889 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str ());
2891 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE
, id
, name
.c_str ());
2899 std::string name
= cInfo
->Name
;
2903 if (Utf8FitTo(name
, wnamepart
))
2906 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str ());
2908 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE
, id
, name
.c_str ());
2914 SendSysMessage (LANG_COMMAND_NOCREATUREFOUND
);
2919 bool ChatHandler::HandleLookupObjectCommand(const char* args
)
2924 std::string namepart
= args
;
2925 std::wstring wnamepart
;
2927 // converting string that we try to find to lower case
2928 if(!Utf8toWStr(namepart
,wnamepart
))
2931 wstrToLower(wnamepart
);
2935 for (uint32 id
= 0; id
< sGOStorage
.MaxEntry
; id
++ )
2937 GameObjectInfo
const* gInfo
= sGOStorage
.LookupEntry
<GameObjectInfo
>(id
);
2941 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2944 GameObjectLocale
const *gl
= objmgr
.GetGameObjectLocale(id
);
2947 if (gl
->Name
.size() > loc_idx
&& !gl
->Name
[loc_idx
].empty())
2949 std::string name
= gl
->Name
[loc_idx
];
2951 if (Utf8FitTo(name
, wnamepart
))
2954 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT
, id
, id
, name
.c_str());
2956 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE
, id
, name
.c_str());
2964 std::string name
= gInfo
->name
;
2968 if(Utf8FitTo(name
, wnamepart
))
2971 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT
, id
, id
, name
.c_str());
2973 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE
, id
, name
.c_str());
2979 SendSysMessage(LANG_COMMAND_NOGAMEOBJECTFOUND
);
2984 /** \brief GM command level 3 - Create a guild.
2986 * This command allows a GM (level 3) to create a guild.
2988 * The "args" parameter contains the name of the guild leader
2989 * and then the name of the guild.
2992 bool ChatHandler::HandleGuildCreateCommand(const char* args
)
2998 char *lname
= strtok ((char*)args
, " ");
2999 char *gname
= strtok (NULL
, "");
3006 SendSysMessage (LANG_INSERT_GUILD_NAME
);
3007 SetSentErrorMessage (true);
3011 std::string guildname
= gname
;
3013 Player
* player
= ObjectAccessor::Instance ().FindPlayerByName (lname
);
3016 SendSysMessage (LANG_PLAYER_NOT_FOUND
);
3017 SetSentErrorMessage (true);
3021 if (player
->GetGuildId())
3023 SendSysMessage (LANG_PLAYER_IN_GUILD
);
3027 Guild
*guild
= new Guild
;
3028 if (!guild
->create (player
->GetGUID (),guildname
))
3031 SendSysMessage (LANG_GUILD_NOT_CREATED
);
3032 SetSentErrorMessage (true);
3036 objmgr
.AddGuild (guild
);
3040 bool ChatHandler::HandleGuildInviteCommand(const char *args
)
3045 char* par1
= strtok ((char*)args
, " ");
3046 char* par2
= strtok (NULL
, "");
3050 std::string glName
= par2
;
3051 Guild
* targetGuild
= objmgr
.GetGuildByName (glName
);
3055 std::string plName
= par1
;
3056 if (!normalizePlayerName (plName
))
3058 SendSysMessage (LANG_PLAYER_NOT_FOUND
);
3059 SetSentErrorMessage (true);
3064 if (Player
* targetPlayer
= ObjectAccessor::Instance ().FindPlayerByName (plName
.c_str ()))
3065 plGuid
= targetPlayer
->GetGUID ();
3067 plGuid
= objmgr
.GetPlayerGUIDByName (plName
.c_str ());
3072 // player's guild membership checked in AddMember before add
3073 if (!targetGuild
->AddMember (plGuid
,targetGuild
->GetLowestRank ()))
3079 bool ChatHandler::HandleGuildUninviteCommand(const char *args
)
3084 char* par1
= strtok ((char*)args
, " ");
3088 std::string plName
= par1
;
3089 if (!normalizePlayerName (plName
))
3091 SendSysMessage (LANG_PLAYER_NOT_FOUND
);
3092 SetSentErrorMessage (true);
3098 if (Player
* targetPlayer
= ObjectAccessor::Instance ().FindPlayerByName (plName
.c_str ()))
3100 plGuid
= targetPlayer
->GetGUID ();
3101 glId
= targetPlayer
->GetGuildId ();
3105 plGuid
= objmgr
.GetPlayerGUIDByName (plName
.c_str ());
3106 glId
= Player::GetGuildIdFromDB (plGuid
);
3109 if (!plGuid
|| !glId
)
3112 Guild
* targetGuild
= objmgr
.GetGuildById (glId
);
3116 targetGuild
->DelMember (plGuid
);
3121 bool ChatHandler::HandleGuildRankCommand(const char *args
)
3126 char* par1
= strtok ((char*)args
, " ");
3127 char* par2
= strtok (NULL
, " ");
3130 std::string plName
= par1
;
3131 if (!normalizePlayerName (plName
))
3133 SendSysMessage (LANG_PLAYER_NOT_FOUND
);
3134 SetSentErrorMessage (true);
3140 if (Player
* targetPlayer
= ObjectAccessor::Instance ().FindPlayerByName (plName
.c_str ()))
3142 plGuid
= targetPlayer
->GetGUID ();
3143 glId
= targetPlayer
->GetGuildId ();
3147 plGuid
= objmgr
.GetPlayerGUIDByName (plName
.c_str ());
3148 glId
= Player::GetGuildIdFromDB (plGuid
);
3151 if (!plGuid
|| !glId
)
3154 Guild
* targetGuild
= objmgr
.GetGuildById (glId
);
3158 uint32 newrank
= uint32 (atoi (par2
));
3159 if (newrank
> targetGuild
->GetLowestRank ())
3162 targetGuild
->ChangeRank (plGuid
,newrank
);
3167 bool ChatHandler::HandleGuildDeleteCommand(const char* args
)
3172 char* par1
= strtok ((char*)args
, " ");
3176 std::string gld
= par1
;
3178 Guild
* targetGuild
= objmgr
.GetGuildByName (gld
);
3182 targetGuild
->Disband ();
3187 bool ChatHandler::HandleGetDistanceCommand(const char* /*args*/)
3189 Unit
* pUnit
= getSelectedUnit();
3193 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3194 SetSentErrorMessage(true);
3198 PSendSysMessage(LANG_DISTANCE
, m_session
->GetPlayer()->GetDistance(pUnit
),m_session
->GetPlayer()->GetDistance2d(pUnit
));
3205 bool ChatHandler::HandleAddWeaponCommand(const char* /*args*/)
3210 uint64 guid = m_session->GetPlayer()->GetSelection();
3213 SendSysMessage(LANG_NO_SELECTION);
3217 Creature *pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
3221 SendSysMessage(LANG_SELECT_CREATURE);
3225 char* pSlotID = strtok((char*)args, " ");
3229 char* pItemID = strtok(NULL, " ");
3233 uint32 ItemID = atoi(pItemID);
3234 uint32 SlotID = atoi(pSlotID);
3236 ItemPrototype* tmpItem = objmgr.GetItemPrototype(ItemID);
3244 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID);
3248 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID);
3252 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID);
3256 PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST,SlotID);
3262 PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT,ItemID,tmpItem->Name1,SlotID);
3267 PSendSysMessage(LANG_ITEM_NOT_FOUND,ItemID);
3274 bool ChatHandler::HandleDieCommand(const char* /*args*/)
3276 Unit
* target
= getSelectedUnit();
3278 if(!target
|| !m_session
->GetPlayer()->GetSelection())
3280 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3281 SetSentErrorMessage(true);
3285 if( target
->isAlive() )
3287 m_session
->GetPlayer()->DealDamage(target
, target
->GetHealth(), NULL
, DIRECT_DAMAGE
, SPELL_SCHOOL_MASK_NORMAL
, NULL
, false);
3293 bool ChatHandler::HandleDamageCommand(const char * args
)
3298 Unit
* target
= getSelectedUnit();
3300 if(!target
|| !m_session
->GetPlayer()->GetSelection())
3302 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3303 SetSentErrorMessage(true);
3307 if( !target
->isAlive() )
3310 char* damageStr
= strtok((char*)args
, " ");
3314 int32 damage
= atoi((char*)damageStr
);
3318 char* schoolStr
= strtok((char*)NULL
, " ");
3320 // flat melee damage without resistence/etc reduction
3323 m_session
->GetPlayer()->DealDamage(target
, damage
, NULL
, DIRECT_DAMAGE
, SPELL_SCHOOL_MASK_NORMAL
, NULL
, false);
3324 m_session
->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2
, target
, 1, SPELL_SCHOOL_MASK_NORMAL
, damage
, 0, 0, VICTIMSTATE_NORMAL
, 0);
3328 uint32 school
= schoolStr
? atoi((char*)schoolStr
) : SPELL_SCHOOL_NORMAL
;
3329 if(school
>= MAX_SPELL_SCHOOL
)
3332 SpellSchoolMask schoolmask
= SpellSchoolMask(1 << school
);
3334 if ( schoolmask
& SPELL_SCHOOL_MASK_NORMAL
)
3335 damage
= m_session
->GetPlayer()->CalcArmorReducedDamage(target
, damage
);
3337 char* spellStr
= strtok((char*)NULL
, " ");
3339 // melee damage by specific school
3345 m_session
->GetPlayer()->CalcAbsorbResist(target
,schoolmask
, SPELL_DIRECT_DAMAGE
, damage
, &absorb
, &resist
);
3347 if (damage
<= absorb
+ resist
)
3350 damage
-= absorb
+ resist
;
3352 m_session
->GetPlayer()->DealDamage(target
, damage
, NULL
, DIRECT_DAMAGE
, schoolmask
, NULL
, false);
3353 m_session
->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2
, target
, 1, schoolmask
, damage
, absorb
, resist
, VICTIMSTATE_NORMAL
, 0);
3359 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3360 uint32 spellid
= extractSpellIdFromLink((char*)args
);
3361 if(!spellid
|| !sSpellStore
.LookupEntry(spellid
))
3364 m_session
->GetPlayer()->SpellNonMeleeDamageLog(target
, spellid
, damage
, false);
3368 bool ChatHandler::HandleModifyArenaCommand(const char * args
)
3373 Player
*target
= getSelectedPlayer();
3376 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3377 SetSentErrorMessage(true);
3381 int32 amount
= (uint32
)atoi(args
);
3383 target
->ModifyArenaPoints(amount
);
3385 PSendSysMessage(LANG_COMMAND_MODIFY_ARENA
, target
->GetName(), target
->GetArenaPoints());
3390 bool ChatHandler::HandleReviveCommand(const char* args
)
3392 Player
* SelectedPlayer
= NULL
;
3396 std::string name
= args
;
3397 if(!normalizePlayerName(name
))
3399 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3400 SetSentErrorMessage(true);
3404 SelectedPlayer
= objmgr
.GetPlayer(name
.c_str());
3407 SelectedPlayer
= getSelectedPlayer();
3411 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3412 SetSentErrorMessage(true);
3416 SelectedPlayer
->ResurrectPlayer(0.5f
);
3417 SelectedPlayer
->SpawnCorpseBones();
3418 SelectedPlayer
->SaveToDB();
3422 bool ChatHandler::HandleAuraCommand(const char* args
)
3424 char* px
= strtok((char*)args
, " ");
3428 Unit
*target
= getSelectedUnit();
3431 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3432 SetSentErrorMessage(true);
3436 uint32 spellID
= (uint32
)atoi(px
);
3437 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry( spellID
);
3440 for(uint32 i
= 0;i
<3;i
++)
3442 uint8 eff
= spellInfo
->Effect
[i
];
3443 if (eff
>=TOTAL_SPELL_EFFECTS
)
3445 if( IsAreaAuraEffect(eff
) ||
3446 eff
== SPELL_EFFECT_APPLY_AURA
||
3447 eff
== SPELL_EFFECT_PERSISTENT_AREA_AURA
)
3449 Aura
*Aur
= CreateAura(spellInfo
, i
, NULL
, target
);
3450 target
->AddAura(Aur
);
3458 bool ChatHandler::HandleUnAuraCommand(const char* args
)
3460 char* px
= strtok((char*)args
, " ");
3464 Unit
*target
= getSelectedUnit();
3467 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3468 SetSentErrorMessage(true);
3472 std::string argstr
= args
;
3473 if (argstr
== "all")
3475 target
->RemoveAllAuras();
3479 uint32 spellID
= (uint32
)atoi(px
);
3480 target
->RemoveAurasDueToSpell(spellID
);
3485 bool ChatHandler::HandleLinkGraveCommand(const char* args
)
3490 char* px
= strtok((char*)args
, " ");
3494 uint32 g_id
= (uint32
)atoi(px
);
3498 char* px2
= strtok(NULL
, " ");
3502 else if (strncmp(px2
,"horde",6)==0)
3504 else if (strncmp(px2
,"alliance",9)==0)
3509 WorldSafeLocsEntry
const* graveyard
= sWorldSafeLocsStore
.LookupEntry(g_id
);
3513 PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST
, g_id
);
3514 SetSentErrorMessage(true);
3518 Player
* player
= m_session
->GetPlayer();
3520 uint32 zoneId
= player
->GetZoneId();
3522 AreaTableEntry
const *areaEntry
= GetAreaEntryByAreaID(zoneId
);
3523 if(!areaEntry
|| areaEntry
->zone
!=0 )
3525 PSendSysMessage(LANG_COMMAND_GRAVEYARDWRONGZONE
, g_id
,zoneId
);
3526 SetSentErrorMessage(true);
3530 if(graveyard
->map_id
!= areaEntry
->mapid
&& g_team
!= 0)
3532 SendSysMessage(LANG_COMMAND_GRAVEYARDWRONGTEAM
);
3533 SetSentErrorMessage(true);
3537 if(objmgr
.AddGraveYardLink(g_id
,player
->GetZoneId(),g_team
))
3538 PSendSysMessage(LANG_COMMAND_GRAVEYARDLINKED
, g_id
,zoneId
);
3540 PSendSysMessage(LANG_COMMAND_GRAVEYARDALRLINKED
, g_id
,zoneId
);
3545 bool ChatHandler::HandleNearGraveCommand(const char* args
)
3549 size_t argslen
= strlen(args
);
3553 else if (strncmp((char*)args
,"horde",argslen
)==0)
3555 else if (strncmp((char*)args
,"alliance",argslen
)==0)
3560 Player
* player
= m_session
->GetPlayer();
3562 WorldSafeLocsEntry
const* graveyard
= objmgr
.GetClosestGraveYard(
3563 player
->GetPositionX(), player
->GetPositionY(), player
->GetPositionZ(),player
->GetMapId(),g_team
);
3567 uint32 g_id
= graveyard
->ID
;
3569 GraveYardData
const* data
= objmgr
.FindGraveYardData(g_id
,player
->GetZoneId());
3572 PSendSysMessage(LANG_COMMAND_GRAVEYARDERROR
,g_id
);
3573 SetSentErrorMessage(true);
3577 g_team
= data
->team
;
3579 std::string team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_NOTEAM
);
3582 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ANY
);
3583 else if(g_team
== HORDE
)
3584 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE
);
3585 else if(g_team
== ALLIANCE
)
3586 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE
);
3588 PSendSysMessage(LANG_COMMAND_GRAVEYARDNEAREST
, g_id
,team_name
.c_str(),player
->GetZoneId());
3592 std::string team_name
;
3595 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ANY
);
3596 else if(g_team
== HORDE
)
3597 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE
);
3598 else if(g_team
== ALLIANCE
)
3599 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE
);
3601 if(g_team
== ~uint32(0))
3602 PSendSysMessage(LANG_COMMAND_ZONENOGRAVEYARDS
, player
->GetZoneId());
3604 PSendSysMessage(LANG_COMMAND_ZONENOGRAFACTION
, player
->GetZoneId(),team_name
.c_str());
3611 bool ChatHandler::HandleNpcPlayEmoteCommand(const char* args
)
3613 uint32 emote
= atoi((char*)args
);
3615 Creature
* target
= getSelectedCreature();
3618 SendSysMessage(LANG_SELECT_CREATURE
);
3619 SetSentErrorMessage(true);
3623 target
->SetUInt32Value(UNIT_NPC_EMOTESTATE
,emote
);
3628 bool ChatHandler::HandleNpcInfoCommand(const char* /*args*/)
3630 Creature
* target
= getSelectedCreature();
3634 SendSysMessage(LANG_SELECT_CREATURE
);
3635 SetSentErrorMessage(true);
3639 uint32 faction
= target
->getFaction();
3640 uint32 npcflags
= target
->GetUInt32Value(UNIT_NPC_FLAGS
);
3641 uint32 displayid
= target
->GetDisplayId();
3642 uint32 nativeid
= target
->GetNativeDisplayId();
3643 uint32 Entry
= target
->GetEntry();
3644 CreatureInfo
const* cInfo
= target
->GetCreatureInfo();
3646 int32 curRespawnDelay
= target
->GetRespawnTimeEx()-time(NULL
);
3647 if(curRespawnDelay
< 0)
3648 curRespawnDelay
= 0;
3649 std::string curRespawnDelayStr
= secsToTimeString(curRespawnDelay
,true);
3650 std::string defRespawnDelayStr
= secsToTimeString(target
->GetRespawnDelay(),true);
3652 PSendSysMessage(LANG_NPCINFO_CHAR
, target
->GetDBTableGUIDLow(), faction
, npcflags
, Entry
, displayid
, nativeid
);
3653 PSendSysMessage(LANG_NPCINFO_LEVEL
, target
->getLevel());
3654 PSendSysMessage(LANG_NPCINFO_HEALTH
,target
->GetCreateHealth(), target
->GetMaxHealth(), target
->GetHealth());
3655 PSendSysMessage(LANG_NPCINFO_FLAGS
, target
->GetUInt32Value(UNIT_FIELD_FLAGS
), target
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
), target
->getFaction());
3656 PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES
, defRespawnDelayStr
.c_str(),curRespawnDelayStr
.c_str());
3657 PSendSysMessage(LANG_NPCINFO_LOOT
, cInfo
->lootid
,cInfo
->pickpocketLootId
,cInfo
->SkinLootId
);
3658 PSendSysMessage(LANG_NPCINFO_DUNGEON_ID
, target
->GetInstanceId());
3659 PSendSysMessage(LANG_NPCINFO_POSITION
,float(target
->GetPositionX()), float(target
->GetPositionY()), float(target
->GetPositionZ()));
3661 if ((npcflags
& UNIT_NPC_FLAG_VENDOR
) )
3663 SendSysMessage(LANG_NPCINFO_VENDOR
);
3665 if ((npcflags
& UNIT_NPC_FLAG_TRAINER
) )
3667 SendSysMessage(LANG_NPCINFO_TRAINER
);
3673 bool ChatHandler::HandleExploreCheatCommand(const char* args
)
3678 int flag
= atoi((char*)args
);
3680 Player
*chr
= getSelectedPlayer();
3683 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3684 SetSentErrorMessage(true);
3690 PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL
, chr
->GetName());
3691 if (needReportToTarget(chr
))
3692 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_EXPLORE_SET_ALL
,GetName());
3696 PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING
, chr
->GetName());
3697 if (needReportToTarget(chr
))
3698 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_EXPLORE_SET_NOTHING
,GetName());
3701 for (uint8 i
=0; i
<128; i
++)
3705 m_session
->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1
+i
,0xFFFFFFFF);
3709 m_session
->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1
+i
,0);
3716 bool ChatHandler::HandleHoverCommand(const char* args
)
3718 char* px
= strtok((char*)args
, " ");
3725 m_session
->GetPlayer()->SetHover(flag
);
3728 SendSysMessage(LANG_HOVER_ENABLED
);
3730 SendSysMessage(LANG_HOVER_DISABLED
);
3735 bool ChatHandler::HandleLevelUpCommand(const char* args
)
3737 char* px
= strtok((char*)args
, " ");
3738 char* py
= strtok((char*)NULL
, " ");
3740 // command format parsing
3741 char* pname
= (char*)NULL
;
3744 if(px
&& py
) // .levelup name level
3746 addlevel
= atoi(py
);
3749 else if(px
&& !py
) // .levelup name OR .levelup level
3751 if(isalpha(px
[0])) // .levelup name
3753 else // .levelup level
3754 addlevel
= atoi(px
);
3756 // else .levelup - nothing do for preparing
3760 uint64 chr_guid
= 0;
3764 if(pname
) // player by name
3767 if(!normalizePlayerName(name
))
3769 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3770 SetSentErrorMessage(true);
3774 chr
= objmgr
.GetPlayer(name
.c_str());
3775 if(!chr
) // not in game
3777 chr_guid
= objmgr
.GetPlayerGUIDByName(name
);
3780 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3781 SetSentErrorMessage(true);
3786 else // player by selection
3788 chr
= getSelectedPlayer();
3792 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3793 SetSentErrorMessage(true);
3797 name
= chr
->GetName();
3800 assert(chr
|| chr_guid
);
3802 int32 oldlevel
= chr
? chr
->getLevel() : Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL
,chr_guid
);
3803 int32 newlevel
= oldlevel
+ addlevel
;
3806 if(newlevel
> 255) // hardcoded maximum level
3811 chr
->GiveLevel(newlevel
);
3812 chr
->InitTalentForLevel();
3813 chr
->SetUInt32Value(PLAYER_XP
,0);
3815 if(oldlevel
== newlevel
)
3816 ChatHandler(chr
).SendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET
);
3818 if(oldlevel
< newlevel
)
3819 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_LEVEL_UP
,newlevel
-oldlevel
);
3821 if(oldlevel
> newlevel
)
3822 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_LEVEL_DOWN
,newlevel
-oldlevel
);
3826 // update level and XP at level, all other will be updated at loading
3828 Player::LoadValuesArrayFromDB(values
,chr_guid
);
3829 Player::SetUInt32ValueInArray(values
,UNIT_FIELD_LEVEL
,newlevel
);
3830 Player::SetUInt32ValueInArray(values
,PLAYER_XP
,0);
3831 Player::SaveValuesArrayInDB(values
,chr_guid
);
3834 if(m_session
->GetPlayer() != chr
) // including chr==NULL
3835 PSendSysMessage(LANG_YOU_CHANGE_LVL
,name
.c_str(),newlevel
);
3839 bool ChatHandler::HandleShowAreaCommand(const char* args
)
3844 int area
= atoi((char*)args
);
3846 Player
*chr
= getSelectedPlayer();
3849 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3850 SetSentErrorMessage(true);
3854 int offset
= area
/ 32;
3855 uint32 val
= (uint32
)(1 << (area
% 32));
3859 SendSysMessage(LANG_BAD_VALUE
);
3860 SetSentErrorMessage(true);
3864 uint32 currFields
= chr
->GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
3865 chr
->SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
| val
));
3867 SendSysMessage(LANG_EXPLORE_AREA
);
3871 bool ChatHandler::HandleHideAreaCommand(const char* args
)
3876 int area
= atoi((char*)args
);
3878 Player
*chr
= getSelectedPlayer();
3881 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3882 SetSentErrorMessage(true);
3886 int offset
= area
/ 32;
3887 uint32 val
= (uint32
)(1 << (area
% 32));
3891 SendSysMessage(LANG_BAD_VALUE
);
3892 SetSentErrorMessage(true);
3896 uint32 currFields
= chr
->GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
3897 chr
->SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
^ val
));
3899 SendSysMessage(LANG_UNEXPLORE_AREA
);
3903 bool ChatHandler::HandleUpdate(const char* args
)
3911 char* pUpdateIndex
= strtok((char*)args
, " ");
3913 Unit
* chr
= getSelectedUnit();
3916 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3917 SetSentErrorMessage(true);
3925 updateIndex
= atoi(pUpdateIndex
);
3927 if(chr
->GetTypeId() == TYPEID_PLAYER
)
3929 if (updateIndex
>=PLAYER_END
) return true;
3933 if (updateIndex
>=UNIT_END
) return true;
3936 char* pvalue
= strtok(NULL
, " ");
3939 value
=chr
->GetUInt32Value(updateIndex
);
3941 PSendSysMessage(LANG_UPDATE
, chr
->GetGUIDLow(),updateIndex
,value
);
3947 PSendSysMessage(LANG_UPDATE_CHANGE
, chr
->GetGUIDLow(),updateIndex
,value
);
3949 chr
->SetUInt32Value(updateIndex
,value
);
3954 bool ChatHandler::HandleBankCommand(const char* /*args*/)
3956 m_session
->SendShowBank( m_session
->GetPlayer()->GetGUID() );
3961 bool ChatHandler::HandleChangeWeather(const char* args
)
3967 if (!sWorld
.getConfig(CONFIG_WEATHER
))
3969 SendSysMessage(LANG_WEATHER_DISABLED
);
3970 SetSentErrorMessage(true);
3974 //*Change the weather of a cell
3975 char* px
= strtok((char*)args
, " ");
3976 char* py
= strtok(NULL
, " ");
3981 uint32 type
= (uint32
)atoi(px
); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
3982 float grade
= (float)atof(py
); //0 to 1, sending -1 is instand good weather
3984 Player
*player
= m_session
->GetPlayer();
3985 uint32 zoneid
= player
->GetZoneId();
3987 Weather
* wth
= sWorld
.FindWeather(zoneid
);
3990 wth
= sWorld
.AddWeather(zoneid
);
3993 SendSysMessage(LANG_NO_WEATHER
);
3994 SetSentErrorMessage(true);
3998 wth
->SetWeather(WeatherType(type
), grade
);
4003 bool ChatHandler::HandleSetValue(const char* args
)
4008 char* px
= strtok((char*)args
, " ");
4009 char* py
= strtok(NULL
, " ");
4010 char* pz
= strtok(NULL
, " ");
4015 Unit
* target
= getSelectedUnit();
4018 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4019 SetSentErrorMessage(true);
4023 uint64 guid
= target
->GetGUID();
4025 uint32 Opcode
= (uint32
)atoi(px
);
4026 if(Opcode
>= target
->GetValuesCount())
4028 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, GUID_LOPART(guid
), target
->GetValuesCount());
4033 bool isint32
= true;
4035 isint32
= (bool)atoi(pz
);
4038 iValue
= (uint32
)atoi(py
);
4039 sLog
.outDebug(GetMangosString(LANG_SET_UINT
), GUID_LOPART(guid
), Opcode
, iValue
);
4040 target
->SetUInt32Value( Opcode
, iValue
);
4041 PSendSysMessage(LANG_SET_UINT_FIELD
, GUID_LOPART(guid
), Opcode
,iValue
);
4045 fValue
= (float)atof(py
);
4046 sLog
.outDebug(GetMangosString(LANG_SET_FLOAT
), GUID_LOPART(guid
), Opcode
, fValue
);
4047 target
->SetFloatValue( Opcode
, fValue
);
4048 PSendSysMessage(LANG_SET_FLOAT_FIELD
, GUID_LOPART(guid
), Opcode
,fValue
);
4054 bool ChatHandler::HandleGetValue(const char* args
)
4059 char* px
= strtok((char*)args
, " ");
4060 char* pz
= strtok(NULL
, " ");
4065 Unit
* target
= getSelectedUnit();
4068 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4069 SetSentErrorMessage(true);
4073 uint64 guid
= target
->GetGUID();
4075 uint32 Opcode
= (uint32
)atoi(px
);
4076 if(Opcode
>= target
->GetValuesCount())
4078 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, GUID_LOPART(guid
), target
->GetValuesCount());
4083 bool isint32
= true;
4085 isint32
= (bool)atoi(pz
);
4089 iValue
= target
->GetUInt32Value( Opcode
);
4090 sLog
.outDebug(GetMangosString(LANG_GET_UINT
), GUID_LOPART(guid
), Opcode
, iValue
);
4091 PSendSysMessage(LANG_GET_UINT_FIELD
, GUID_LOPART(guid
), Opcode
, iValue
);
4095 fValue
= target
->GetFloatValue( Opcode
);
4096 sLog
.outDebug(GetMangosString(LANG_GET_FLOAT
), GUID_LOPART(guid
), Opcode
, fValue
);
4097 PSendSysMessage(LANG_GET_FLOAT_FIELD
, GUID_LOPART(guid
), Opcode
, fValue
);
4103 bool ChatHandler::HandleSet32Bit(const char* args
)
4108 char* px
= strtok((char*)args
, " ");
4109 char* py
= strtok(NULL
, " ");
4114 uint32 Opcode
= (uint32
)atoi(px
);
4115 uint32 Value
= (uint32
)atoi(py
);
4116 if (Value
> 32) //uint32 = 32 bits
4119 sLog
.outDebug(GetMangosString(LANG_SET_32BIT
), Opcode
, Value
);
4121 m_session
->GetPlayer( )->SetUInt32Value( Opcode
, 2^Value
);
4123 PSendSysMessage(LANG_SET_32BIT_FIELD
, Opcode
,1);
4127 bool ChatHandler::HandleMod32Value(const char* args
)
4132 char* px
= strtok((char*)args
, " ");
4133 char* py
= strtok(NULL
, " ");
4138 uint32 Opcode
= (uint32
)atoi(px
);
4139 int Value
= atoi(py
);
4141 if(Opcode
>= m_session
->GetPlayer()->GetValuesCount())
4143 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, m_session
->GetPlayer()->GetGUIDLow(), m_session
->GetPlayer( )->GetValuesCount());
4147 sLog
.outDebug(GetMangosString(LANG_CHANGE_32BIT
), Opcode
, Value
);
4149 int CurrentValue
= (int)m_session
->GetPlayer( )->GetUInt32Value( Opcode
);
4151 CurrentValue
+= Value
;
4152 m_session
->GetPlayer( )->SetUInt32Value( Opcode
, (uint32
)CurrentValue
);
4154 PSendSysMessage(LANG_CHANGE_32BIT_FIELD
, Opcode
,CurrentValue
);
4159 bool ChatHandler::HandleAddTeleCommand(const char * args
)
4164 Player
*player
=m_session
->GetPlayer();
4168 std::string name
= args
;
4170 if(objmgr
.GetGameTele(name
))
4172 SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST
);
4173 SetSentErrorMessage(true);
4178 tele
.position_x
= player
->GetPositionX();
4179 tele
.position_y
= player
->GetPositionY();
4180 tele
.position_z
= player
->GetPositionZ();
4181 tele
.orientation
= player
->GetOrientation();
4182 tele
.mapId
= player
->GetMapId();
4185 if(objmgr
.AddGameTele(tele
))
4187 SendSysMessage(LANG_COMMAND_TP_ADDED
);
4191 SendSysMessage(LANG_COMMAND_TP_ADDEDERR
);
4192 SetSentErrorMessage(true);
4199 bool ChatHandler::HandleDelTeleCommand(const char * args
)
4204 std::string name
= args
;
4206 if(!objmgr
.DeleteGameTele(name
))
4208 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
4209 SetSentErrorMessage(true);
4213 SendSysMessage(LANG_COMMAND_TP_DELETED
);
4217 bool ChatHandler::HandleListAurasCommand (const char * /*args*/)
4219 Unit
*unit
= getSelectedUnit();
4222 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4223 SetSentErrorMessage(true);
4227 char const* talentStr
= GetMangosString(LANG_TALENT
);
4228 char const* passiveStr
= GetMangosString(LANG_PASSIVE
);
4230 Unit::AuraMap
const& uAuras
= unit
->GetAuras();
4231 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS
, uAuras
.size());
4232 for (Unit::AuraMap::const_iterator itr
= uAuras
.begin(); itr
!= uAuras
.end(); ++itr
)
4234 bool talent
= GetTalentSpellCost(itr
->second
->GetId()) > 0;
4235 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL
, itr
->second
->GetId(), itr
->second
->GetEffIndex(),
4236 itr
->second
->GetModifier()->m_auraname
, itr
->second
->GetAuraDuration(), itr
->second
->GetAuraMaxDuration(),
4237 itr
->second
->GetSpellProto()->SpellName
[m_session
->GetSessionDbcLocale()],
4238 (itr
->second
->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4239 IS_PLAYER_GUID(itr
->second
->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr
->second
->GetCasterGUID()));
4241 for (int i
= 0; i
< TOTAL_AURAS
; i
++)
4243 Unit::AuraList
const& uAuraList
= unit
->GetAurasByType(AuraType(i
));
4244 if (uAuraList
.empty()) continue;
4245 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE
, uAuraList
.size(), i
);
4246 for (Unit::AuraList::const_iterator itr
= uAuraList
.begin(); itr
!= uAuraList
.end(); ++itr
)
4248 bool talent
= GetTalentSpellCost((*itr
)->GetId()) > 0;
4249 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE
, (*itr
)->GetId(), (*itr
)->GetEffIndex(),
4250 (*itr
)->GetSpellProto()->SpellName
[m_session
->GetSessionDbcLocale()],((*itr
)->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4251 IS_PLAYER_GUID((*itr
)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr
)->GetCasterGUID()));
4257 bool ChatHandler::HandleResetHonorCommand (const char * args
)
4259 char* pName
= strtok((char*)args
, "");
4260 Player
*player
= NULL
;
4263 std::string name
= pName
;
4264 if(!normalizePlayerName(name
))
4266 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4267 SetSentErrorMessage(true);
4271 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4272 player
= objmgr
.GetPlayer(guid
);
4275 player
= getSelectedPlayer();
4279 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4283 player
->SetUInt32Value(PLAYER_FIELD_KILLS
, 0);
4284 player
->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS
, 0);
4285 player
->SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY
, 0);
4286 player
->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION
, 0);
4287 player
->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION
, 0);
4292 static bool HandleResetStatsOrLevelHelper(Player
* player
)
4294 PlayerInfo
const *info
= objmgr
.GetPlayerInfo(player
->getRace(), player
->getClass());
4295 if(!info
) return false;
4297 ChrClassesEntry
const* cEntry
= sChrClassesStore
.LookupEntry(player
->getClass());
4300 sLog
.outError("Class %u not found in DBC (Wrong DBC files?)",player
->getClass());
4304 uint8 powertype
= cEntry
->powerType
;
4307 if(powertype
== POWER_RAGE
)
4308 unitfield
= 0x1100EE00;
4309 else if(powertype
== POWER_ENERGY
)
4310 unitfield
= 0x00000000;
4311 else if(powertype
== POWER_MANA
)
4312 unitfield
= 0x0000EE00;
4315 sLog
.outError("Invalid default powertype %u for player (class %u)",powertype
,player
->getClass());
4319 // reset m_form if no aura
4320 if(!player
->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT
))
4321 player
->m_form
= FORM_NONE
;
4323 player
->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS
, DEFAULT_WORLD_OBJECT_SIZE
);
4324 player
->SetFloatValue(UNIT_FIELD_COMBATREACH
, 1.5f
);
4326 player
->setFactionForRace(player
->getRace());
4328 player
->SetUInt32Value(UNIT_FIELD_BYTES_0
, ( ( player
->getRace() ) | ( player
->getClass() << 8 ) | ( player
->getGender() << 16 ) | ( powertype
<< 24 ) ) );
4330 // reset only if player not in some form;
4331 if(player
->m_form
==FORM_NONE
)
4333 switch(player
->getGender())
4336 player
->SetDisplayId(info
->displayId_f
);
4337 player
->SetNativeDisplayId(info
->displayId_f
);
4340 player
->SetDisplayId(info
->displayId_m
);
4341 player
->SetNativeDisplayId(info
->displayId_m
);
4348 // set UNIT_FIELD_BYTES_1 to init state but preserve m_form value
4349 player
->SetUInt32Value(UNIT_FIELD_BYTES_1
, unitfield
);
4350 player
->SetByteValue(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_PVP
);
4351 player
->SetByteValue(UNIT_FIELD_BYTES_2
, 3, player
->m_form
);
4353 player
->SetUInt32Value(UNIT_FIELD_FLAGS
, UNIT_FLAG_PVP_ATTACKABLE
);
4355 //-1 is default value
4356 player
->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX
, uint32(-1));
4358 //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000 );
4362 bool ChatHandler::HandleResetLevelCommand(const char * args
)
4364 char* pName
= strtok((char*)args
, "");
4365 Player
*player
= NULL
;
4368 std::string name
= pName
;
4369 if(!normalizePlayerName(name
))
4371 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4372 SetSentErrorMessage(true);
4376 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4377 player
= objmgr
.GetPlayer(guid
);
4380 player
= getSelectedPlayer();
4384 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4385 SetSentErrorMessage(true);
4389 if(!HandleResetStatsOrLevelHelper(player
))
4392 player
->SetLevel(1);
4393 player
->InitStatsForLevel(true);
4394 player
->InitTaxiNodesForLevel();
4395 player
->InitGlyphsForLevel();
4396 player
->InitTalentForLevel();
4397 player
->SetUInt32Value(PLAYER_XP
,0);
4399 // reset level to summoned pet
4400 Pet
* pet
= player
->GetPet();
4401 if(pet
&& pet
->getPetType()==SUMMON_PET
)
4402 pet
->InitStatsForLevel(1);
4407 bool ChatHandler::HandleResetStatsCommand(const char * args
)
4409 char* pName
= strtok((char*)args
, "");
4410 Player
*player
= NULL
;
4413 std::string name
= pName
;
4414 if(!normalizePlayerName(name
))
4416 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4417 SetSentErrorMessage(true);
4421 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4422 player
= objmgr
.GetPlayer(guid
);
4425 player
= getSelectedPlayer();
4429 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4430 SetSentErrorMessage(true);
4434 if(!HandleResetStatsOrLevelHelper(player
))
4437 player
->InitStatsForLevel(true);
4438 player
->InitTaxiNodesForLevel();
4439 player
->InitGlyphsForLevel();
4440 player
->InitTalentForLevel();
4445 bool ChatHandler::HandleResetSpellsCommand(const char * args
)
4447 char* pName
= strtok((char*)args
, "");
4448 Player
*player
= NULL
;
4449 uint64 playerGUID
= 0;
4452 std::string name
= pName
;
4454 if(!normalizePlayerName(name
))
4456 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4457 SetSentErrorMessage(true);
4461 player
= objmgr
.GetPlayer(name
.c_str());
4463 playerGUID
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4466 player
= getSelectedPlayer();
4468 if(!player
&& !playerGUID
)
4470 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4471 SetSentErrorMessage(true);
4477 player
->resetSpells();
4479 ChatHandler(player
).SendSysMessage(LANG_RESET_SPELLS
);
4481 if(m_session
->GetPlayer()!=player
)
4482 PSendSysMessage(LANG_RESET_SPELLS_ONLINE
,player
->GetName());
4486 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS
), GUID_LOPART(playerGUID
));
4487 PSendSysMessage(LANG_RESET_SPELLS_OFFLINE
,pName
);
4493 bool ChatHandler::HandleResetTalentsCommand(const char * args
)
4495 char* pName
= strtok((char*)args
, "");
4496 Player
*player
= NULL
;
4497 uint64 playerGUID
= 0;
4500 std::string name
= pName
;
4501 if(!normalizePlayerName(name
))
4503 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4504 SetSentErrorMessage(true);
4508 player
= objmgr
.GetPlayer(name
.c_str());
4510 playerGUID
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4513 player
= getSelectedPlayer();
4515 if(!player
&& !playerGUID
)
4517 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4518 SetSentErrorMessage(true);
4524 player
->resetTalents(true);
4526 ChatHandler(player
).SendSysMessage(LANG_RESET_TALENTS
);
4528 if(m_session
->GetPlayer()!=player
)
4529 PSendSysMessage(LANG_RESET_TALENTS_ONLINE
,player
->GetName());
4533 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_TALENTS
), GUID_LOPART(playerGUID
) );
4534 PSendSysMessage(LANG_RESET_TALENTS_OFFLINE
,pName
);
4540 bool ChatHandler::HandleResetAllCommand(const char * args
)
4545 std::string casename
= args
;
4547 AtLoginFlags atLogin
;
4549 // Command specially created as single command to prevent using short case names
4550 if(casename
=="spells")
4552 atLogin
= AT_LOGIN_RESET_SPELLS
;
4553 sWorld
.SendWorldText(LANG_RESETALL_SPELLS
);
4555 else if(casename
=="talents")
4557 atLogin
= AT_LOGIN_RESET_TALENTS
;
4558 sWorld
.SendWorldText(LANG_RESETALL_TALENTS
);
4562 PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE
,args
);
4563 SetSentErrorMessage(true);
4567 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u'",atLogin
);
4568 HashMapHolder
<Player
>::MapType
const& plist
= ObjectAccessor::Instance().GetPlayers();
4569 for(HashMapHolder
<Player
>::MapType::const_iterator itr
= plist
.begin(); itr
!= plist
.end(); ++itr
)
4570 itr
->second
->SetAtLoginFlag(atLogin
);
4575 bool ChatHandler::HandleShutDownCommand(const char* args
)
4580 if(std::string(args
)=="cancel")
4582 sWorld
.ShutdownCancel();
4586 int32 time
= atoi(args
);
4588 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4589 if(time
== 0 && (args
[0]!='0' || args
[1]!='\0') || time
< 0)
4592 sWorld
.ShutdownServ(time
);
4597 bool ChatHandler::HandleRestartCommand(const char* args
)
4602 if(std::string(args
)=="cancel")
4604 sWorld
.ShutdownCancel();
4608 int32 time
= atoi(args
);
4610 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4611 if(time
== 0 && (args
[0]!='0' || args
[1]!='\0') || time
< 0)
4614 sWorld
.ShutdownServ(time
, SHUTDOWN_MASK_RESTART
);
4619 bool ChatHandler::HandleIdleRestartCommand(const char* args
)
4624 if(std::string(args
)=="cancel")
4626 sWorld
.ShutdownCancel();
4630 int32 time
= atoi(args
);
4632 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4633 if(time
== 0 && (args
[0]!='0' || args
[1]!='\0') || time
< 0)
4636 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_RESTART
+SHUTDOWN_MASK_IDLE
);
4641 bool ChatHandler::HandleIdleShutDownCommand(const char* args
)
4646 if(std::string(args
)=="cancel")
4648 sWorld
.ShutdownCancel();
4652 int32 time
= atoi(args
);
4654 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4655 if(time
== 0 && (args
[0]!='0' || args
[1]!='\0') || time
< 0)
4658 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_IDLE
);
4663 bool ChatHandler::HandleAddQuest(const char* args
)
4665 Player
* player
= getSelectedPlayer();
4668 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4669 SetSentErrorMessage(true);
4673 // .addquest #entry'
4674 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4675 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4679 uint32 entry
= atol(cId
);
4681 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
4685 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
,entry
);
4686 SetSentErrorMessage(true);
4690 // check item starting quest (it can work incorrectly if added without item in inventory)
4691 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
4693 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
4697 if (pProto
->StartQuest
== entry
)
4699 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM
, entry
, pProto
->ItemId
);
4700 SetSentErrorMessage(true);
4705 // ok, normal (creature/GO starting) quest
4706 if( player
->CanAddQuest( pQuest
, true ) )
4708 player
->AddQuest( pQuest
, NULL
);
4710 if ( player
->CanCompleteQuest( entry
) )
4711 player
->CompleteQuest( entry
);
4717 bool ChatHandler::HandleRemoveQuest(const char* args
)
4719 Player
* player
= getSelectedPlayer();
4722 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4723 SetSentErrorMessage(true);
4727 // .removequest #entry'
4728 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4729 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4733 uint32 entry
= atol(cId
);
4735 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
4739 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
4740 SetSentErrorMessage(true);
4744 // remove all quest entries for 'entry' from quest log
4745 for(uint8 slot
= 0; slot
< MAX_QUEST_LOG_SIZE
; ++slot
)
4747 uint32 quest
= player
->GetQuestSlotQuestId(slot
);
4750 player
->SetQuestSlot(slot
,0);
4752 // we ignore unequippable quest items in this case, its' still be equipped
4753 player
->TakeQuestSourceItem( quest
, false );
4757 // set quest status to not started (will updated in DB at next save)
4758 player
->SetQuestStatus( entry
, QUEST_STATUS_NONE
);
4760 // reset rewarded for restart repeatable quest
4761 player
->getQuestStatusMap()[entry
].m_rewarded
= false;
4763 SendSysMessage(LANG_COMMAND_QUEST_REMOVED
);
4767 bool ChatHandler::HandleCompleteQuest(const char* args
)
4769 Player
* player
= getSelectedPlayer();
4772 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4773 SetSentErrorMessage(true);
4777 // .quest complete #entry
4778 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4779 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4783 uint32 entry
= atol(cId
);
4785 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
4787 // If player doesn't have the quest
4788 if(!pQuest
|| player
->GetQuestStatus(entry
) == QUEST_STATUS_NONE
)
4790 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
4791 SetSentErrorMessage(true);
4795 // Add quest items for quests that require items
4796 for(uint8 x
= 0; x
< QUEST_OBJECTIVES_COUNT
; ++x
)
4798 uint32 id
= pQuest
->ReqItemId
[x
];
4799 uint32 count
= pQuest
->ReqItemCount
[x
];
4803 uint32 curItemCount
= player
->GetItemCount(id
,true);
4805 ItemPosCountVec dest
;
4806 uint8 msg
= player
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, id
, count
-curItemCount
);
4807 if( msg
== EQUIP_ERR_OK
)
4809 Item
* item
= player
->StoreNewItem( dest
, id
, true);
4810 player
->SendNewItem(item
,count
-curItemCount
,true,false);
4814 // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
4815 for(uint8 i
= 0; i
< QUEST_OBJECTIVES_COUNT
; i
++)
4817 uint32 creature
= pQuest
->ReqCreatureOrGOId
[i
];
4818 uint32 creaturecount
= pQuest
->ReqCreatureOrGOCount
[i
];
4820 if(uint32 spell_id
= pQuest
->ReqSpell
[i
])
4822 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4823 player
->CastedCreatureOrGO(creature
,0,spell_id
);
4825 else if(creature
> 0)
4827 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4828 player
->KilledMonster(creature
,0);
4830 else if(creature
< 0)
4832 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4833 player
->CastedCreatureOrGO(creature
,0,0);
4837 // If the quest requires reputation to complete
4838 if(uint32 repFaction
= pQuest
->GetRepObjectiveFaction())
4840 uint32 repValue
= pQuest
->GetRepObjectiveValue();
4841 uint32 curRep
= player
->GetReputation(repFaction
);
4842 if(curRep
< repValue
)
4844 FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry(repFaction
);
4845 player
->SetFactionReputation(factionEntry
,repValue
);
4849 // If the quest requires money
4850 int32 ReqOrRewMoney
= pQuest
->GetRewOrReqMoney();
4851 if(ReqOrRewMoney
< 0)
4852 player
->ModifyMoney(-ReqOrRewMoney
);
4854 player
->CompleteQuest(entry
);
4858 bool ChatHandler::HandleBanAccountCommand(const char* args
)
4860 return HandleBanHelper(BAN_ACCOUNT
,args
);
4863 bool ChatHandler::HandleBanCharacterCommand(const char* args
)
4865 return HandleBanHelper(BAN_CHARACTER
,args
);
4868 bool ChatHandler::HandleBanIPCommand(const char* args
)
4870 return HandleBanHelper(BAN_IP
,args
);
4873 bool ChatHandler::HandleBanHelper(BanMode mode
, const char* args
)
4878 char* cnameOrIP
= strtok ((char*)args
, " ");
4882 std::string nameOrIP
= cnameOrIP
;
4884 char* duration
= strtok (NULL
," ");
4885 if(!duration
|| !atoi(duration
))
4888 char* reason
= strtok (NULL
,"");
4895 if(!AccountMgr::normilizeString(nameOrIP
))
4897 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
4898 SetSentErrorMessage(true);
4903 if(!normalizePlayerName(nameOrIP
))
4905 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4906 SetSentErrorMessage(true);
4911 if(!IsIPAddress(nameOrIP
.c_str()))
4916 switch(sWorld
.BanAccount(mode
, nameOrIP
, duration
, reason
,m_session
? m_session
->GetPlayerName() : ""))
4919 if(atoi(duration
)>0)
4920 PSendSysMessage(LANG_BAN_YOUBANNED
,nameOrIP
.c_str(),secsToTimeString(TimeStringToSecs(duration
),true).c_str(),reason
);
4922 PSendSysMessage(LANG_BAN_YOUPERMBANNED
,nameOrIP
.c_str(),reason
);
4924 case BAN_SYNTAX_ERROR
:
4930 PSendSysMessage(LANG_BAN_NOTFOUND
,"account",nameOrIP
.c_str());
4933 PSendSysMessage(LANG_BAN_NOTFOUND
,"character",nameOrIP
.c_str());
4936 PSendSysMessage(LANG_BAN_NOTFOUND
,"ip",nameOrIP
.c_str());
4939 SetSentErrorMessage(true);
4946 bool ChatHandler::HandleUnBanAccountCommand(const char* args
)
4948 return HandleUnBanHelper(BAN_ACCOUNT
,args
);
4951 bool ChatHandler::HandleUnBanCharacterCommand(const char* args
)
4953 return HandleUnBanHelper(BAN_CHARACTER
,args
);
4956 bool ChatHandler::HandleUnBanIPCommand(const char* args
)
4958 return HandleUnBanHelper(BAN_IP
,args
);
4961 bool ChatHandler::HandleUnBanHelper(BanMode mode
, const char* args
)
4966 char* cnameOrIP
= strtok ((char*)args
, " ");
4970 std::string nameOrIP
= cnameOrIP
;
4975 if(!AccountMgr::normilizeString(nameOrIP
))
4977 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
4978 SetSentErrorMessage(true);
4983 if(!normalizePlayerName(nameOrIP
))
4985 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4986 SetSentErrorMessage(true);
4991 if(!IsIPAddress(nameOrIP
.c_str()))
4996 if(sWorld
.RemoveBanAccount(mode
,nameOrIP
))
4997 PSendSysMessage(LANG_UNBAN_UNBANNED
,nameOrIP
.c_str());
4999 PSendSysMessage(LANG_UNBAN_ERROR
,nameOrIP
.c_str());
5004 bool ChatHandler::HandleBanInfoAccountCommand(const char* args
)
5009 char* cname
= strtok((char*)args
, "");
5013 std::string account_name
= cname
;
5014 if(!AccountMgr::normilizeString(account_name
))
5016 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5017 SetSentErrorMessage(true);
5021 uint32 accountid
= accmgr
.GetId(account_name
);
5024 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5028 return HandleBanInfoHelper(accountid
,account_name
.c_str());
5031 bool ChatHandler::HandleBanInfoCharacterCommand(const char* args
)
5036 char* cname
= strtok ((char*)args
, "");
5040 std::string name
= cname
;
5041 if(!normalizePlayerName(name
))
5043 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5044 SetSentErrorMessage(true);
5048 uint32 accountid
= objmgr
.GetPlayerAccountIdByPlayerName(name
);
5051 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5052 SetSentErrorMessage(true);
5056 std::string accountname
;
5057 if(!accmgr
.GetName(accountid
,accountname
))
5059 PSendSysMessage(LANG_BANINFO_NOCHARACTER
);
5063 return HandleBanInfoHelper(accountid
,accountname
.c_str());
5066 bool ChatHandler::HandleBanInfoHelper(uint32 accountid
, char const* accountname
)
5068 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
);
5071 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN
, accountname
);
5075 PSendSysMessage(LANG_BANINFO_BANHISTORY
,accountname
);
5078 Field
* fields
= result
->Fetch();
5080 time_t unbandate
= time_t(fields
[3].GetUInt64());
5081 bool active
= false;
5082 if(fields
[2].GetBool() && (fields
[1].GetUInt64() == (uint64
)0 ||unbandate
>= time(NULL
)) )
5084 bool permanent
= (fields
[1].GetUInt64() == (uint64
)0);
5085 std::string bantime
= permanent
?GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[1].GetUInt64(), true);
5086 PSendSysMessage(LANG_BANINFO_HISTORYENTRY
,
5087 fields
[0].GetString(), bantime
.c_str(), active
? GetMangosString(LANG_BANINFO_YES
):GetMangosString(LANG_BANINFO_NO
), fields
[4].GetString(), fields
[5].GetString());
5088 }while (result
->NextRow());
5094 bool ChatHandler::HandleBanInfoIPCommand(const char* args
)
5099 char* cIP
= strtok ((char*)args
, "");
5103 if (!IsIPAddress(cIP
))
5106 std::string IP
= cIP
;
5108 loginDatabase
.escape_string(IP
);
5109 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());
5112 PSendSysMessage(LANG_BANINFO_NOIP
);
5116 Field
*fields
= result
->Fetch();
5117 bool permanent
= !fields
[6].GetUInt64();
5118 PSendSysMessage(LANG_BANINFO_IPENTRY
,
5119 fields
[0].GetString(), fields
[1].GetString(), permanent
? GetMangosString(LANG_BANINFO_NEVER
):fields
[2].GetString(),
5120 permanent
? GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[3].GetUInt64(), true).c_str(), fields
[4].GetString(), fields
[5].GetString());
5125 bool ChatHandler::HandleBanListCharacterCommand(const char* args
)
5127 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5129 char* cFilter
= strtok ((char*)args
, " ");
5133 std::string filter
= cFilter
;
5134 loginDatabase
.escape_string(filter
);
5135 QueryResult
* result
= CharacterDatabase
.PQuery("SELECT account FROM characters WHERE name "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'"),filter
.c_str());
5138 PSendSysMessage(LANG_BANLIST_NOCHARACTER
);
5142 return HandleBanListHelper(result
);
5145 bool ChatHandler::HandleBanListAccountCommand(const char* args
)
5147 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5149 char* cFilter
= strtok((char*)args
, " ");
5150 std::string filter
= cFilter
? cFilter
: "";
5151 loginDatabase
.escape_string(filter
);
5153 QueryResult
* result
;
5157 result
= loginDatabase
.Query("SELECT account.id, username FROM account, account_banned"
5158 " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
5162 result
= loginDatabase
.PQuery("SELECT account.id, username FROM account, account_banned"
5163 " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
5169 PSendSysMessage(LANG_BANLIST_NOACCOUNT
);
5173 return HandleBanListHelper(result
);
5176 bool ChatHandler::HandleBanListHelper(QueryResult
* result
)
5178 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT
);
5180 // Chat short output
5185 Field
* fields
= result
->Fetch();
5186 uint32 accountid
= fields
[0].GetUInt32();
5188 QueryResult
* banresult
= loginDatabase
.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid
);
5191 Field
* fields2
= banresult
->Fetch();
5192 PSendSysMessage("%s",fields2
[0].GetString());
5195 } while (result
->NextRow());
5197 // Console wide output
5200 SendSysMessage(LANG_BANLIST_ACCOUNTS
);
5201 SendSysMessage("===============================================================================");
5202 SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER
);
5205 SendSysMessage("-------------------------------------------------------------------------------");
5206 Field
*fields
= result
->Fetch();
5207 uint32 account_id
= fields
[0].GetUInt32 ();
5209 std::string account_name
;
5211 // "account" case, name can be get in same query
5212 if(result
->GetFieldCount() > 1)
5213 account_name
= fields
[1].GetCppString();
5214 // "character" case, name need extract from another DB
5216 accmgr
.GetName (account_id
,account_name
);
5218 // No SQL injection. id is uint32.
5219 QueryResult
*banInfo
= loginDatabase
.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id
);
5222 Field
*fields2
= banInfo
->Fetch();
5225 time_t t_ban
= fields2
[0].GetUInt64();
5226 tm
* aTm_ban
= localtime(&t_ban
);
5228 if (fields2
[0].GetUInt64() == fields2
[1].GetUInt64())
5230 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5231 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
,
5232 fields2
[2].GetString(),fields2
[3].GetString());
5236 time_t t_unban
= fields2
[1].GetUInt64();
5237 tm
* aTm_unban
= localtime(&t_unban
);
5238 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5239 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
,
5240 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5241 fields2
[2].GetString(),fields2
[3].GetString());
5243 }while ( banInfo
->NextRow() );
5246 }while( result
->NextRow() );
5247 SendSysMessage("===============================================================================");
5254 bool ChatHandler::HandleBanListIPCommand(const char* args
)
5256 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5258 char* cFilter
= strtok((char*)args
, " ");
5259 std::string filter
= cFilter
? cFilter
: "";
5260 loginDatabase
.escape_string(filter
);
5262 QueryResult
* result
;
5266 result
= loginDatabase
.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5267 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
5268 " ORDER BY unbandate" );
5272 result
= loginDatabase
.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5273 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")
5274 " ORDER BY unbandate",filter
.c_str() );
5279 PSendSysMessage(LANG_BANLIST_NOIP
);
5283 PSendSysMessage(LANG_BANLIST_MATCHINGIP
);
5284 // Chat short output
5289 Field
* fields
= result
->Fetch();
5290 PSendSysMessage("%s",fields
[0].GetString());
5291 } while (result
->NextRow());
5293 // Console wide output
5296 SendSysMessage(LANG_BANLIST_IPS
);
5297 SendSysMessage("===============================================================================");
5298 SendSysMessage(LANG_BANLIST_IPS_HEADER
);
5301 SendSysMessage("-------------------------------------------------------------------------------");
5302 Field
*fields
= result
->Fetch();
5303 time_t t_ban
= fields
[1].GetUInt64();
5304 tm
* aTm_ban
= localtime(&t_ban
);
5305 if ( fields
[1].GetUInt64() == fields
[2].GetUInt64() )
5307 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5308 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
,
5309 fields
[3].GetString(), fields
[4].GetString());
5313 time_t t_unban
= fields
[2].GetUInt64();
5314 tm
* aTm_unban
= localtime(&t_unban
);
5315 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5316 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
,
5317 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5318 fields
[3].GetString(), fields
[4].GetString());
5320 }while( result
->NextRow() );
5321 SendSysMessage("===============================================================================");
5328 bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
5330 Player
* pl
= m_session
->GetPlayer();
5332 // accept only explicitly selected target (not implicitly self targeting case)
5333 Unit
* target
= getSelectedUnit();
5334 if(pl
->GetSelection() && target
)
5336 if(target
->GetTypeId()!=TYPEID_UNIT
)
5338 SendSysMessage(LANG_SELECT_CREATURE
);
5339 SetSentErrorMessage(true);
5343 if(target
->isDead())
5344 ((Creature
*)target
)->Respawn();
5348 CellPair
p(MaNGOS::ComputeCellPair(pl
->GetPositionX(), pl
->GetPositionY()));
5350 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
5353 MaNGOS::RespawnDo u_do
;
5354 MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
> worker(u_do
);
5356 TypeContainerVisitor
<MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
>, GridTypeMapContainer
> obj_worker(worker
);
5357 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
5358 cell_lock
->Visit(cell_lock
, obj_worker
, *MapManager::Instance().GetMap(pl
->GetMapId(), pl
));
5363 bool ChatHandler::HandleFlyModeCommand(const char* args
)
5368 Unit
*unit
= getSelectedUnit();
5369 if (!unit
|| (unit
->GetTypeId() != TYPEID_PLAYER
))
5370 unit
= m_session
->GetPlayer();
5372 WorldPacket
data(12);
5373 if (strncmp(args
, "on", 3) == 0)
5374 data
.SetOpcode(SMSG_MOVE_SET_CAN_FLY
);
5375 else if (strncmp(args
, "off", 4) == 0)
5376 data
.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY
);
5379 SendSysMessage(LANG_USE_BOL
);
5382 data
.append(unit
->GetPackGUID());
5383 data
<< uint32(0); // unknown
5384 unit
->SendMessageToSet(&data
, true);
5385 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS
, unit
->GetName(), args
);
5389 bool ChatHandler::HandleLoadPDumpCommand(const char *args
)
5394 char * file
= strtok((char*)args
, " ");
5398 char * account
= strtok(NULL
, " ");
5402 std::string account_name
= account
;
5403 if(!AccountMgr::normilizeString(account_name
))
5405 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5406 SetSentErrorMessage(true);
5410 uint32 account_id
= accmgr
.GetId(account_name
);
5413 account_id
= atoi(account
); // use original string
5416 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5417 SetSentErrorMessage(true);
5422 if(!accmgr
.GetName(account_id
,account_name
))
5424 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5425 SetSentErrorMessage(true);
5429 char* guid_str
= NULL
;
5430 char* name_str
= strtok(NULL
, " ");
5436 // normalize the name if specified and check if it exists
5437 if(!normalizePlayerName(name
))
5439 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5440 SetSentErrorMessage(true);
5444 if(!ObjectMgr::IsValidName(name
,true))
5446 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5447 SetSentErrorMessage(true);
5451 guid_str
= strtok(NULL
, " ");
5458 guid
= atoi(guid_str
);
5461 PSendSysMessage(LANG_INVALID_CHARACTER_GUID
);
5462 SetSentErrorMessage(true);
5466 if(objmgr
.GetPlayerAccountIdByGUID(guid
))
5468 PSendSysMessage(LANG_CHARACTER_GUID_IN_USE
,guid
);
5469 SetSentErrorMessage(true);
5474 switch(PlayerDumpReader().LoadDump(file
, account_id
, name
, guid
))
5477 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS
);
5479 case DUMP_FILE_OPEN_ERROR
:
5480 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
5481 SetSentErrorMessage(true);
5483 case DUMP_FILE_BROKEN
:
5484 PSendSysMessage(LANG_DUMP_BROKEN
,file
);
5485 SetSentErrorMessage(true);
5487 case DUMP_TOO_MANY_CHARS
:
5488 PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL
,account_name
.c_str(),account_id
);
5489 SetSentErrorMessage(true);
5492 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED
);
5493 SetSentErrorMessage(true);
5500 bool ChatHandler::HandleNpcChangeEntryCommand(const char *args
)
5505 uint32 newEntryNum
= atoi(args
);
5509 Unit
* unit
= getSelectedUnit();
5510 if(!unit
|| unit
->GetTypeId() != TYPEID_UNIT
)
5512 SendSysMessage(LANG_SELECT_CREATURE
);
5513 SetSentErrorMessage(true);
5516 Creature
* creature
= (Creature
*)unit
;
5517 if(creature
->UpdateEntry(newEntryNum
))
5518 SendSysMessage(LANG_DONE
);
5520 SendSysMessage(LANG_ERROR
);
5524 bool ChatHandler::HandleWritePDumpCommand(const char *args
)
5529 char* file
= strtok((char*)args
, " ");
5530 char* p2
= strtok(NULL
, " ");
5535 uint32 guid
= objmgr
.GetPlayerGUIDByName(p2
);
5539 if(!objmgr
.GetPlayerAccountIdByGUID(guid
))
5541 PSendSysMessage(LANG_PLAYER_NOT_FOUND
);
5542 SetSentErrorMessage(true);
5546 switch(PlayerDumpWriter().WriteDump(file
, guid
))
5549 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS
);
5551 case DUMP_FILE_OPEN_ERROR
:
5552 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
5553 SetSentErrorMessage(true);
5556 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED
);
5557 SetSentErrorMessage(true);
5564 bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
5566 Unit
* unit
= getSelectedUnit();
5569 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5570 SetSentErrorMessage(true);
5574 PSendSysMessage(LANG_MOVEGENS_LIST
,(unit
->GetTypeId()==TYPEID_PLAYER
? "Player" : "Creature" ),unit
->GetGUIDLow());
5576 MotionMaster
* mm
= unit
->GetMotionMaster();
5577 for(MotionMaster::const_iterator itr
= mm
->begin(); itr
!= mm
->end(); ++itr
)
5579 switch((*itr
)->GetMovementGeneratorType())
5581 case IDLE_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_IDLE
); break;
5582 case RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_RANDOM
); break;
5583 case WAYPOINT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_WAYPOINT
); break;
5584 case ANIMAL_RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_ANIMAL_RANDOM
); break;
5585 case CONFUSED_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_CONFUSED
); break;
5586 case TARGETED_MOTION_TYPE
:
5588 if(unit
->GetTypeId()==TYPEID_PLAYER
)
5590 TargetedMovementGenerator
<Player
> const* mgen
= static_cast<TargetedMovementGenerator
<Player
> const*>(*itr
);
5591 Unit
* target
= mgen
->GetTarget();
5593 PSendSysMessage(LANG_MOVEGENS_TARGETED_PLAYER
,target
->GetName(),target
->GetGUIDLow());
5595 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL
);
5599 TargetedMovementGenerator
<Creature
> const* mgen
= static_cast<TargetedMovementGenerator
<Creature
> const*>(*itr
);
5600 Unit
* target
= mgen
->GetTarget();
5602 PSendSysMessage(LANG_MOVEGENS_TARGETED_CREATURE
,target
->GetName(),target
->GetGUIDLow());
5604 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL
);
5608 case HOME_MOTION_TYPE
:
5609 if(unit
->GetTypeId()==TYPEID_UNIT
)
5612 (*itr
)->GetDestination(x
,y
,z
);
5613 PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE
,x
,y
,z
);
5616 SendSysMessage(LANG_MOVEGENS_HOME_PLAYER
);
5618 case FLIGHT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FLIGHT
); break;
5619 case POINT_MOTION_TYPE
:
5622 (*itr
)->GetDestination(x
,y
,z
);
5623 PSendSysMessage(LANG_MOVEGENS_POINT
,x
,y
,z
);
5626 case FLEEING_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FEAR
); break;
5627 case DISTRACT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_DISTRACT
); break;
5629 PSendSysMessage(LANG_MOVEGENS_UNKNOWN
,(*itr
)->GetMovementGeneratorType());
5636 bool ChatHandler::HandlePLimitCommand(const char *args
)
5640 char* param
= strtok((char*)args
, " ");
5644 int l
= strlen(param
);
5646 if( strncmp(param
,"player",l
) == 0 )
5647 sWorld
.SetPlayerLimit(-SEC_PLAYER
);
5648 else if(strncmp(param
,"moderator",l
) == 0 )
5649 sWorld
.SetPlayerLimit(-SEC_MODERATOR
);
5650 else if(strncmp(param
,"gamemaster",l
) == 0 )
5651 sWorld
.SetPlayerLimit(-SEC_GAMEMASTER
);
5652 else if(strncmp(param
,"administrator",l
) == 0 )
5653 sWorld
.SetPlayerLimit(-SEC_ADMINISTRATOR
);
5654 else if(strncmp(param
,"reset",l
) == 0 )
5655 sWorld
.SetPlayerLimit( sConfig
.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT
) );
5658 int val
= atoi(param
);
5659 if(val
< -SEC_ADMINISTRATOR
) val
= -SEC_ADMINISTRATOR
;
5661 sWorld
.SetPlayerLimit(val
);
5664 // kick all low security level players
5665 if(sWorld
.GetPlayerAmountLimit() > SEC_PLAYER
)
5666 sWorld
.KickAllLess(sWorld
.GetPlayerSecurityLimit());
5669 uint32 pLimit
= sWorld
.GetPlayerAmountLimit();
5670 AccountTypes allowedAccountType
= sWorld
.GetPlayerSecurityLimit();
5671 char const* secName
= "";
5672 switch(allowedAccountType
)
5674 case SEC_PLAYER
: secName
= "Player"; break;
5675 case SEC_MODERATOR
: secName
= "Moderator"; break;
5676 case SEC_GAMEMASTER
: secName
= "Gamemaster"; break;
5677 case SEC_ADMINISTRATOR
: secName
= "Administrator"; break;
5678 default: secName
= "<unknown>"; break;
5681 PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit
,secName
);
5686 bool ChatHandler::HandleCastCommand(const char* args
)
5691 Unit
* target
= getSelectedUnit();
5695 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5696 SetSentErrorMessage(true);
5700 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5701 uint32 spell
= extractSpellIdFromLink((char*)args
);
5705 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5709 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5711 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5712 SetSentErrorMessage(true);
5716 char* trig_str
= strtok(NULL
, " ");
5719 int l
= strlen(trig_str
);
5720 if(strncmp(trig_str
,"triggered",l
) != 0 )
5724 bool triggered
= (trig_str
!= NULL
);
5726 m_session
->GetPlayer()->CastSpell(target
,spell
,triggered
);
5731 bool ChatHandler::HandleCastBackCommand(const char* args
)
5733 Creature
* caster
= getSelectedCreature();
5737 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5738 SetSentErrorMessage(true);
5742 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
5743 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5744 uint32 spell
= extractSpellIdFromLink((char*)args
);
5745 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
5748 char* trig_str
= strtok(NULL
, " ");
5751 int l
= strlen(trig_str
);
5752 if(strncmp(trig_str
,"triggered",l
) != 0 )
5756 bool triggered
= (trig_str
!= NULL
);
5758 // update orientation at server
5759 caster
->SetOrientation(caster
->GetAngle(m_session
->GetPlayer()));
5763 caster
->BuildHeartBeatMsg(&data
);
5764 caster
->SendMessageToSet(&data
,true);
5766 caster
->CastSpell(m_session
->GetPlayer(),spell
,triggered
);
5771 bool ChatHandler::HandleCastDistCommand(const char* args
)
5776 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5777 uint32 spell
= extractSpellIdFromLink((char*)args
);
5781 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5785 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5787 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5788 SetSentErrorMessage(true);
5792 char *distStr
= strtok(NULL
, " ");
5797 sscanf(distStr
, "%f", &dist
);
5799 char* trig_str
= strtok(NULL
, " ");
5802 int l
= strlen(trig_str
);
5803 if(strncmp(trig_str
,"triggered",l
) != 0 )
5807 bool triggered
= (trig_str
!= NULL
);
5810 m_session
->GetPlayer()->GetClosePoint(x
,y
,z
,dist
);
5812 m_session
->GetPlayer()->CastSpell(x
,y
,z
,spell
,triggered
);
5816 bool ChatHandler::HandleCastTargetCommand(const char* args
)
5818 Creature
* caster
= getSelectedCreature();
5822 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5823 SetSentErrorMessage(true);
5827 if(!caster
->getVictim())
5829 SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM
);
5830 SetSentErrorMessage(true);
5834 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5835 uint32 spell
= extractSpellIdFromLink((char*)args
);
5836 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
5839 char* trig_str
= strtok(NULL
, " ");
5842 int l
= strlen(trig_str
);
5843 if(strncmp(trig_str
,"triggered",l
) != 0 )
5847 bool triggered
= (trig_str
!= NULL
);
5849 // update orientation at server
5850 caster
->SetOrientation(caster
->GetAngle(m_session
->GetPlayer()));
5854 caster
->BuildHeartBeatMsg(&data
);
5855 caster
->SendMessageToSet(&data
,true);
5857 caster
->CastSpell(caster
->getVictim(),spell
,triggered
);
5863 ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
5864 Without this function 3rd party scripting library will get linking errors (unresolved external)
5865 when attempting to use the PointMovementGenerator
5867 bool ChatHandler::HandleComeToMeCommand(const char *args
)
5869 Creature
* caster
= getSelectedCreature();
5873 SendSysMessage(LANG_SELECT_CREATURE
);
5874 SetSentErrorMessage(true);
5878 char* newFlagStr
= strtok((char*)args
, " ");
5883 uint32 newFlags
= atoi(newFlagStr
);
5885 caster
->SetUnitMovementFlags(newFlags
);
5887 Player
* pl
= m_session
->GetPlayer();
5889 caster
->GetMotionMaster()->MovePoint(0, pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ());
5893 bool ChatHandler::HandleCastSelfCommand(const char* args
)
5898 Unit
* target
= getSelectedUnit();
5902 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5903 SetSentErrorMessage(true);
5907 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5908 uint32 spell
= extractSpellIdFromLink((char*)args
);
5912 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5916 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5918 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5919 SetSentErrorMessage(true);
5923 target
->CastSpell(target
,spell
,false);
5928 std::string
GetTimeString(uint32 time
)
5930 uint16 days
= time
/ DAY
, hours
= (time
% DAY
) / HOUR
, minute
= (time
% HOUR
) / MINUTE
;
5931 std::ostringstream ss
;
5932 if(days
) ss
<< days
<< "d ";
5933 if(hours
) ss
<< hours
<< "h ";
5934 ss
<< minute
<< "m";
5938 bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
5940 Player
* player
= getSelectedPlayer();
5941 if (!player
) player
= m_session
->GetPlayer();
5943 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
5945 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(i
);
5946 for(Player::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
5948 InstanceSave
*save
= itr
->second
.save
;
5949 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
5950 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());
5954 PSendSysMessage("player binds: %d", counter
);
5956 Group
*group
= player
->GetGroup();
5959 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
5961 Group::BoundInstancesMap
&binds
= group
->GetBoundInstances(i
);
5962 for(Group::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
5964 InstanceSave
*save
= itr
->second
.save
;
5965 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
5966 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());
5971 PSendSysMessage("group binds: %d", counter
);
5976 bool ChatHandler::HandleInstanceUnbindCommand(const char* args
)
5981 std::string cmd
= args
;
5984 Player
* player
= getSelectedPlayer();
5985 if (!player
) player
= m_session
->GetPlayer();
5987 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
5989 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(i
);
5990 for(Player::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end();)
5992 if(itr
->first
!= player
->GetMapId())
5994 InstanceSave
*save
= itr
->second
.save
;
5995 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
5996 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());
5997 player
->UnbindInstance(itr
, i
);
6004 PSendSysMessage("instances unbound: %d", counter
);
6009 bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
6011 PSendSysMessage("instances loaded: %d", MapManager::Instance().GetNumInstances());
6012 PSendSysMessage("players in instances: %d", MapManager::Instance().GetNumPlayersInInstances());
6013 PSendSysMessage("instance saves: %d", sInstanceSaveManager
.GetNumInstanceSaves());
6014 PSendSysMessage("players bound: %d", sInstanceSaveManager
.GetNumBoundPlayersTotal());
6015 PSendSysMessage("groups bound: %d", sInstanceSaveManager
.GetNumBoundGroupsTotal());
6019 bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
6021 Player
* pl
= m_session
->GetPlayer();
6023 Map
* map
= pl
->GetMap();
6024 if (!map
->IsDungeon())
6026 PSendSysMessage("Map is not a dungeon.");
6027 SetSentErrorMessage(true);
6031 if (!((InstanceMap
*)map
)->GetInstanceData())
6033 PSendSysMessage("Map has no instance data.");
6034 SetSentErrorMessage(true);
6038 ((InstanceMap
*)map
)->GetInstanceData()->SaveToDB();
6042 /// Display the list of GMs
6043 bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
6045 ///- Get the accounts with GM Level >0
6046 QueryResult
*result
= loginDatabase
.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
6049 SendSysMessage(LANG_GMLIST
);
6050 SendSysMessage("========================");
6051 SendSysMessage(LANG_GMLIST_HEADER
);
6052 SendSysMessage("========================");
6054 ///- Circle through them. Display username and GM level
6057 Field
*fields
= result
->Fetch();
6058 PSendSysMessage("|%15s|%6s|", fields
[0].GetString(),fields
[1].GetString());
6059 }while( result
->NextRow() );
6061 PSendSysMessage("========================");
6065 PSendSysMessage(LANG_GMLIST_EMPTY
);
6069 /// Define the 'Message of the day' for the realm
6070 bool ChatHandler::HandleServerSetMotdCommand(const char* args
)
6072 sWorld
.SetMotd(args
);
6073 PSendSysMessage(LANG_MOTD_NEW
, args
);
6077 /// Set/Unset the expansion level for an account
6078 bool ChatHandler::HandleAccountSetAddonCommand(const char* args
)
6080 ///- Get the command line arguments
6081 char *szAcc
= strtok((char*)args
," ");
6082 char *szExp
= strtok(NULL
," ");
6087 std::string account_name
;
6092 Player
* player
= getSelectedPlayer();
6096 account_id
= player
->GetSession()->GetAccountId();
6097 accmgr
.GetName(account_id
,account_name
);
6102 ///- Convert Account name to Upper Format
6103 account_name
= szAcc
;
6104 if(!AccountMgr::normilizeString(account_name
))
6106 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
6107 SetSentErrorMessage(true);
6111 account_id
= accmgr
.GetId(account_name
);
6114 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
6115 SetSentErrorMessage(true);
6120 int lev
=atoi(szExp
); //get int anyway (0 if error)
6125 loginDatabase
.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev
,account_id
);
6126 PSendSysMessage(LANG_ACCOUNT_SETADDON
,account_name
.c_str(),account_id
,lev
);
6130 /// Send a message to a player in game
6131 bool ChatHandler::HandleSendMessageCommand(const char* args
)
6133 ///- Get the command line arguments
6134 char* name_str
= strtok((char*)args
, " ");
6135 char* msg_str
= strtok(NULL
, "");
6137 if(!name_str
|| !msg_str
)
6140 std::string name
= name_str
;
6142 if(!normalizePlayerName(name
))
6145 ///- Find the player and check that he is not logging out.
6146 Player
*rPlayer
= objmgr
.GetPlayer(name
.c_str());
6149 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6150 SetSentErrorMessage(true);
6154 if(rPlayer
->GetSession()->isLogingOut())
6156 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6157 SetSentErrorMessage(true);
6161 ///- Send the message
6162 //Use SendAreaTriggerMessage for fastest delivery.
6163 rPlayer
->GetSession()->SendAreaTriggerMessage("%s", msg_str
);
6164 rPlayer
->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
6166 //Confirmation message
6167 PSendSysMessage(LANG_SENDMESSAGE
,name
.c_str(),msg_str
);
6171 bool ChatHandler::HandleModifyGenderCommand(const char *args
)
6176 Player
*player
= getSelectedPlayer();
6180 PSendSysMessage(LANG_NO_PLAYER
);
6181 SetSentErrorMessage(true);
6185 char const* gender_str
= (char*)args
;
6186 int gender_len
= strlen(gender_str
);
6188 uint32 displayId
= player
->GetNativeDisplayId();
6189 char const* gender_full
= NULL
;
6190 uint32 new_displayId
= displayId
;
6193 if(!strncmp(gender_str
,"male",gender_len
)) // MALE
6195 if(player
->getGender() == GENDER_MALE
)
6198 gender_full
= "male";
6199 new_displayId
= player
->getRace() == RACE_BLOODELF
? displayId
+1 : displayId
-1;
6200 gender
= GENDER_MALE
;
6202 else if (!strncmp(gender_str
,"female",gender_len
)) // FEMALE
6204 if(player
->getGender() == GENDER_FEMALE
)
6207 gender_full
= "female";
6208 new_displayId
= player
->getRace() == RACE_BLOODELF
? displayId
-1 : displayId
+1;
6209 gender
= GENDER_FEMALE
;
6213 SendSysMessage(LANG_MUST_MALE_OR_FEMALE
);
6214 SetSentErrorMessage(true);
6219 player
->SetByteValue(UNIT_FIELD_BYTES_0
, 2, gender
);
6221 // Change display ID
6222 player
->SetDisplayId(new_displayId
);
6223 player
->SetNativeDisplayId(new_displayId
);
6225 PSendSysMessage(LANG_YOU_CHANGE_GENDER
, player
->GetName(),gender_full
);
6226 if (needReportToTarget(player
))
6227 ChatHandler(player
).PSendSysMessage(LANG_YOUR_GENDER_CHANGED
, gender_full
,GetName());