2 * Copyright (C) 2005-2009 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 "BattleGroundMgr.h"
51 #include "InstanceSaveMgr.h"
52 #include "InstanceData.h"
55 bool ChatHandler::HandleReloadAllCommand(const char*)
57 HandleReloadSkillFishingBaseLevelCommand("");
59 HandleReloadAllAreaCommand("");
60 HandleReloadAllLootCommand("");
61 HandleReloadAllNpcCommand("");
62 HandleReloadAllQuestCommand("");
63 HandleReloadAllSpellCommand("");
64 HandleReloadAllItemCommand("");
65 HandleReloadAllLocalesCommand("");
67 HandleReloadCommandCommand("");
68 HandleReloadReservedNameCommand("");
69 HandleReloadMangosStringCommand("");
70 HandleReloadGameTeleCommand("");
74 bool ChatHandler::HandleReloadAllAreaCommand(const char*)
76 //HandleReloadQuestAreaTriggersCommand(""); -- reloaded in HandleReloadAllQuestCommand
77 HandleReloadAreaTriggerTeleportCommand("");
78 HandleReloadAreaTriggerTavernCommand("");
79 HandleReloadGameGraveyardZoneCommand("");
83 bool ChatHandler::HandleReloadAllLootCommand(const char*)
85 sLog
.outString( "Re-Loading Loot Tables..." );
87 SendGlobalSysMessage("DB tables `*_loot_template` reloaded.");
91 bool ChatHandler::HandleReloadAllNpcCommand(const char* /*args*/)
93 HandleReloadNpcGossipCommand("a");
94 HandleReloadNpcOptionCommand("a");
95 HandleReloadNpcTrainerCommand("a");
96 HandleReloadNpcVendorCommand("a");
100 bool ChatHandler::HandleReloadAllQuestCommand(const char* /*args*/)
102 HandleReloadQuestAreaTriggersCommand("a");
103 HandleReloadQuestTemplateCommand("a");
105 sLog
.outString( "Re-Loading Quests Relations..." );
106 objmgr
.LoadQuestRelations();
107 SendGlobalSysMessage("DB tables `*_questrelation` and `*_involvedrelation` reloaded.");
111 bool ChatHandler::HandleReloadAllScriptsCommand(const char*)
113 if(sWorld
.IsScriptScheduled())
115 PSendSysMessage("DB scripts used currently, please attempt reload later.");
116 SetSentErrorMessage(true);
120 sLog
.outString( "Re-Loading Scripts..." );
121 HandleReloadGameObjectScriptsCommand("a");
122 HandleReloadEventScriptsCommand("a");
123 HandleReloadQuestEndScriptsCommand("a");
124 HandleReloadQuestStartScriptsCommand("a");
125 HandleReloadSpellScriptsCommand("a");
126 SendGlobalSysMessage("DB tables `*_scripts` reloaded.");
127 HandleReloadDbScriptStringCommand("a");
131 bool ChatHandler::HandleReloadAllSpellCommand(const char*)
133 HandleReloadSkillDiscoveryTemplateCommand("a");
134 HandleReloadSkillExtraItemTemplateCommand("a");
135 HandleReloadSpellAffectCommand("a");
136 HandleReloadSpellChainCommand("a");
137 HandleReloadSpellElixirCommand("a");
138 HandleReloadSpellLearnSpellCommand("a");
139 HandleReloadSpellProcEventCommand("a");
140 HandleReloadSpellScriptTargetCommand("a");
141 HandleReloadSpellTargetPositionCommand("a");
142 HandleReloadSpellThreatsCommand("a");
143 HandleReloadSpellPetAurasCommand("a");
147 bool ChatHandler::HandleReloadAllItemCommand(const char*)
149 HandleReloadPageTextsCommand("a");
150 HandleReloadItemEnchantementsCommand("a");
154 bool ChatHandler::HandleReloadAllLocalesCommand(const char* /*args*/)
156 HandleReloadLocalesCreatureCommand("a");
157 HandleReloadLocalesGameobjectCommand("a");
158 HandleReloadLocalesItemCommand("a");
159 HandleReloadLocalesNpcTextCommand("a");
160 HandleReloadLocalesPageTextCommand("a");
161 HandleReloadLocalesQuestCommand("a");
165 bool ChatHandler::HandleReloadConfigCommand(const char* /*args*/)
167 sLog
.outString( "Re-Loading config settings..." );
168 sWorld
.LoadConfigSettings(true);
169 SendGlobalSysMessage("World config settings reloaded.");
173 bool ChatHandler::HandleReloadAreaTriggerTavernCommand(const char*)
175 sLog
.outString( "Re-Loading Tavern Area Triggers..." );
176 objmgr
.LoadTavernAreaTriggers();
177 SendGlobalSysMessage("DB table `areatrigger_tavern` reloaded.");
181 bool ChatHandler::HandleReloadAreaTriggerTeleportCommand(const char*)
183 sLog
.outString( "Re-Loading AreaTrigger teleport definitions..." );
184 objmgr
.LoadAreaTriggerTeleports();
185 SendGlobalSysMessage("DB table `areatrigger_teleport` reloaded.");
189 bool ChatHandler::HandleReloadCommandCommand(const char*)
191 load_command_table
= true;
192 SendGlobalSysMessage("DB table `command` will be reloaded at next chat command use.");
196 bool ChatHandler::HandleReloadCreatureQuestRelationsCommand(const char*)
198 sLog
.outString( "Loading Quests Relations... (`creature_questrelation`)" );
199 objmgr
.LoadCreatureQuestRelations();
200 SendGlobalSysMessage("DB table `creature_questrelation` (creature quest givers) reloaded.");
204 bool ChatHandler::HandleReloadCreatureQuestInvRelationsCommand(const char*)
206 sLog
.outString( "Loading Quests Relations... (`creature_involvedrelation`)" );
207 objmgr
.LoadCreatureInvolvedRelations();
208 SendGlobalSysMessage("DB table `creature_involvedrelation` (creature quest takers) reloaded.");
212 bool ChatHandler::HandleReloadGOQuestRelationsCommand(const char*)
214 sLog
.outString( "Loading Quests Relations... (`gameobject_questrelation`)" );
215 objmgr
.LoadGameobjectQuestRelations();
216 SendGlobalSysMessage("DB table `gameobject_questrelation` (gameobject quest givers) reloaded.");
220 bool ChatHandler::HandleReloadGOQuestInvRelationsCommand(const char*)
222 sLog
.outString( "Loading Quests Relations... (`gameobject_involvedrelation`)" );
223 objmgr
.LoadGameobjectInvolvedRelations();
224 SendGlobalSysMessage("DB table `gameobject_involvedrelation` (gameobject quest takers) reloaded.");
228 bool ChatHandler::HandleReloadQuestAreaTriggersCommand(const char*)
230 sLog
.outString( "Re-Loading Quest Area Triggers..." );
231 objmgr
.LoadQuestAreaTriggers();
232 SendGlobalSysMessage("DB table `areatrigger_involvedrelation` (quest area triggers) reloaded.");
236 bool ChatHandler::HandleReloadQuestTemplateCommand(const char*)
238 sLog
.outString( "Re-Loading Quest Templates..." );
240 SendGlobalSysMessage("DB table `quest_template` (quest definitions) reloaded.");
244 bool ChatHandler::HandleReloadLootTemplatesCreatureCommand(const char*)
246 sLog
.outString( "Re-Loading Loot Tables... (`creature_loot_template`)" );
247 LoadLootTemplates_Creature();
248 LootTemplates_Creature
.CheckLootRefs();
249 SendGlobalSysMessage("DB table `creature_loot_template` reloaded.");
253 bool ChatHandler::HandleReloadLootTemplatesDisenchantCommand(const char*)
255 sLog
.outString( "Re-Loading Loot Tables... (`disenchant_loot_template`)" );
256 LoadLootTemplates_Disenchant();
257 LootTemplates_Disenchant
.CheckLootRefs();
258 SendGlobalSysMessage("DB table `disenchant_loot_template` reloaded.");
262 bool ChatHandler::HandleReloadLootTemplatesFishingCommand(const char*)
264 sLog
.outString( "Re-Loading Loot Tables... (`fishing_loot_template`)" );
265 LoadLootTemplates_Fishing();
266 LootTemplates_Fishing
.CheckLootRefs();
267 SendGlobalSysMessage("DB table `fishing_loot_template` reloaded.");
271 bool ChatHandler::HandleReloadLootTemplatesGameobjectCommand(const char*)
273 sLog
.outString( "Re-Loading Loot Tables... (`gameobject_loot_template`)" );
274 LoadLootTemplates_Gameobject();
275 LootTemplates_Gameobject
.CheckLootRefs();
276 SendGlobalSysMessage("DB table `gameobject_loot_template` reloaded.");
280 bool ChatHandler::HandleReloadLootTemplatesItemCommand(const char*)
282 sLog
.outString( "Re-Loading Loot Tables... (`item_loot_template`)" );
283 LoadLootTemplates_Item();
284 LootTemplates_Item
.CheckLootRefs();
285 SendGlobalSysMessage("DB table `item_loot_template` reloaded.");
289 bool ChatHandler::HandleReloadLootTemplatesMillingCommand(const char*)
291 sLog
.outString( "Re-Loading Loot Tables... (`milling_loot_template`)" );
292 LoadLootTemplates_Milling();
293 LootTemplates_Milling
.CheckLootRefs();
294 SendGlobalSysMessage("DB table `milling_loot_template` reloaded.");
298 bool ChatHandler::HandleReloadLootTemplatesPickpocketingCommand(const char*)
300 sLog
.outString( "Re-Loading Loot Tables... (`pickpocketing_loot_template`)" );
301 LoadLootTemplates_Pickpocketing();
302 LootTemplates_Pickpocketing
.CheckLootRefs();
303 SendGlobalSysMessage("DB table `pickpocketing_loot_template` reloaded.");
307 bool ChatHandler::HandleReloadLootTemplatesProspectingCommand(const char*)
309 sLog
.outString( "Re-Loading Loot Tables... (`prospecting_loot_template`)" );
310 LoadLootTemplates_Prospecting();
311 LootTemplates_Prospecting
.CheckLootRefs();
312 SendGlobalSysMessage("DB table `prospecting_loot_template` reloaded.");
316 bool ChatHandler::HandleReloadLootTemplatesQuestMailCommand(const char*)
318 sLog
.outString( "Re-Loading Loot Tables... (`quest_mail_loot_template`)" );
319 LoadLootTemplates_QuestMail();
320 LootTemplates_QuestMail
.CheckLootRefs();
321 SendGlobalSysMessage("DB table `quest_mail_loot_template` reloaded.");
325 bool ChatHandler::HandleReloadLootTemplatesReferenceCommand(const char*)
327 sLog
.outString( "Re-Loading Loot Tables... (`reference_loot_template`)" );
328 LoadLootTemplates_Reference();
329 SendGlobalSysMessage("DB table `reference_loot_template` reloaded.");
333 bool ChatHandler::HandleReloadLootTemplatesSkinningCommand(const char*)
335 sLog
.outString( "Re-Loading Loot Tables... (`skinning_loot_template`)" );
336 LoadLootTemplates_Skinning();
337 LootTemplates_Skinning
.CheckLootRefs();
338 SendGlobalSysMessage("DB table `skinning_loot_template` reloaded.");
342 bool ChatHandler::HandleReloadLootTemplatesSpellCommand(const char*)
344 sLog
.outString( "Re-Loading Loot Tables... (`spell_loot_template`)" );
345 LoadLootTemplates_Spell();
346 LootTemplates_Spell
.CheckLootRefs();
347 SendGlobalSysMessage("DB table `spell_loot_template` reloaded.");
351 bool ChatHandler::HandleReloadMangosStringCommand(const char*)
353 sLog
.outString( "Re-Loading mangos_string Table!" );
354 objmgr
.LoadMangosStrings();
355 SendGlobalSysMessage("DB table `mangos_string` reloaded.");
359 bool ChatHandler::HandleReloadNpcOptionCommand(const char*)
361 sLog
.outString( "Re-Loading `npc_option` Table!" );
362 objmgr
.LoadNpcOptions();
363 SendGlobalSysMessage("DB table `npc_option` reloaded.");
367 bool ChatHandler::HandleReloadNpcGossipCommand(const char*)
369 sLog
.outString( "Re-Loading `npc_gossip` Table!" );
370 objmgr
.LoadNpcTextId();
371 SendGlobalSysMessage("DB table `npc_gossip` reloaded.");
375 bool ChatHandler::HandleReloadNpcTrainerCommand(const char*)
377 sLog
.outString( "Re-Loading `npc_trainer` Table!" );
378 objmgr
.LoadTrainerSpell();
379 SendGlobalSysMessage("DB table `npc_trainer` reloaded.");
383 bool ChatHandler::HandleReloadNpcVendorCommand(const char*)
385 sLog
.outString( "Re-Loading `npc_vendor` Table!" );
386 objmgr
.LoadVendors();
387 SendGlobalSysMessage("DB table `npc_vendor` reloaded.");
391 bool ChatHandler::HandleReloadReservedNameCommand(const char*)
393 sLog
.outString( "Loading ReservedNames... (`reserved_name`)" );
394 objmgr
.LoadReservedPlayersNames();
395 SendGlobalSysMessage("DB table `reserved_name` (player reserved names) reloaded.");
399 bool ChatHandler::HandleReloadSkillDiscoveryTemplateCommand(const char* /*args*/)
401 sLog
.outString( "Re-Loading Skill Discovery Table..." );
402 LoadSkillDiscoveryTable();
403 SendGlobalSysMessage("DB table `skill_discovery_template` (recipes discovered at crafting) reloaded.");
407 bool ChatHandler::HandleReloadSkillExtraItemTemplateCommand(const char* /*args*/)
409 sLog
.outString( "Re-Loading Skill Extra Item Table..." );
410 LoadSkillExtraItemTable();
411 SendGlobalSysMessage("DB table `skill_extra_item_template` (extra item creation when crafting) reloaded.");
415 bool ChatHandler::HandleReloadSkillFishingBaseLevelCommand(const char* /*args*/)
417 sLog
.outString( "Re-Loading Skill Fishing base level requirements..." );
418 objmgr
.LoadFishingBaseSkillLevel();
419 SendGlobalSysMessage("DB table `skill_fishing_base_level` (fishing base level for zone/subzone) reloaded.");
423 bool ChatHandler::HandleReloadSpellAffectCommand(const char*)
425 sLog
.outString( "Re-Loading SpellAffect definitions..." );
426 spellmgr
.LoadSpellAffects();
427 SendGlobalSysMessage("DB table `spell_affect` (spell mods apply requirements) reloaded.");
431 bool ChatHandler::HandleReloadSpellChainCommand(const char*)
433 sLog
.outString( "Re-Loading Spell Chain Data... " );
434 spellmgr
.LoadSpellChains();
435 SendGlobalSysMessage("DB table `spell_chain` (spell ranks) reloaded.");
439 bool ChatHandler::HandleReloadSpellElixirCommand(const char*)
441 sLog
.outString( "Re-Loading Spell Elixir types..." );
442 spellmgr
.LoadSpellElixirs();
443 SendGlobalSysMessage("DB table `spell_elixir` (spell elixir types) reloaded.");
447 bool ChatHandler::HandleReloadSpellLearnSpellCommand(const char*)
449 sLog
.outString( "Re-Loading Spell Learn Spells..." );
450 spellmgr
.LoadSpellLearnSpells();
451 SendGlobalSysMessage("DB table `spell_learn_spell` reloaded.");
455 bool ChatHandler::HandleReloadSpellProcEventCommand(const char*)
457 sLog
.outString( "Re-Loading Spell Proc Event conditions..." );
458 spellmgr
.LoadSpellProcEvents();
459 SendGlobalSysMessage("DB table `spell_proc_event` (spell proc trigger requirements) reloaded.");
463 bool ChatHandler::HandleReloadSpellScriptTargetCommand(const char*)
465 sLog
.outString( "Re-Loading SpellsScriptTarget..." );
466 spellmgr
.LoadSpellScriptTarget();
467 SendGlobalSysMessage("DB table `spell_script_target` (spell targets selection in case specific creature/GO requirements) reloaded.");
471 bool ChatHandler::HandleReloadSpellTargetPositionCommand(const char*)
473 sLog
.outString( "Re-Loading Spell target coordinates..." );
474 spellmgr
.LoadSpellTargetPositions();
475 SendGlobalSysMessage("DB table `spell_target_position` (destination coordinates for spell targets) reloaded.");
479 bool ChatHandler::HandleReloadSpellThreatsCommand(const char*)
481 sLog
.outString( "Re-Loading Aggro Spells Definitions...");
482 spellmgr
.LoadSpellThreats();
483 SendGlobalSysMessage("DB table `spell_threat` (spell aggro definitions) reloaded.");
487 bool ChatHandler::HandleReloadSpellPetAurasCommand(const char*)
489 sLog
.outString( "Re-Loading Spell pet auras...");
490 spellmgr
.LoadSpellPetAuras();
491 SendGlobalSysMessage("DB table `spell_pet_auras` reloaded.");
495 bool ChatHandler::HandleReloadPageTextsCommand(const char*)
497 sLog
.outString( "Re-Loading Page Texts..." );
498 objmgr
.LoadPageTexts();
499 SendGlobalSysMessage("DB table `page_texts` reloaded.");
503 bool ChatHandler::HandleReloadItemEnchantementsCommand(const char*)
505 sLog
.outString( "Re-Loading Item Random Enchantments Table..." );
506 LoadRandomEnchantmentsTable();
507 SendGlobalSysMessage("DB table `item_enchantment_template` reloaded.");
511 bool ChatHandler::HandleReloadGameObjectScriptsCommand(const char* arg
)
513 if(sWorld
.IsScriptScheduled())
515 SendSysMessage("DB scripts used currently, please attempt reload later.");
516 SetSentErrorMessage(true);
521 sLog
.outString( "Re-Loading Scripts from `gameobject_scripts`...");
523 objmgr
.LoadGameObjectScripts();
526 SendGlobalSysMessage("DB table `gameobject_scripts` reloaded.");
531 bool ChatHandler::HandleReloadEventScriptsCommand(const char* arg
)
533 if(sWorld
.IsScriptScheduled())
535 SendSysMessage("DB scripts used currently, please attempt reload later.");
536 SetSentErrorMessage(true);
541 sLog
.outString( "Re-Loading Scripts from `event_scripts`...");
543 objmgr
.LoadEventScripts();
546 SendGlobalSysMessage("DB table `event_scripts` reloaded.");
551 bool ChatHandler::HandleReloadQuestEndScriptsCommand(const char* arg
)
553 if(sWorld
.IsScriptScheduled())
555 SendSysMessage("DB scripts used currently, please attempt reload later.");
556 SetSentErrorMessage(true);
561 sLog
.outString( "Re-Loading Scripts from `quest_end_scripts`...");
563 objmgr
.LoadQuestEndScripts();
566 SendGlobalSysMessage("DB table `quest_end_scripts` reloaded.");
571 bool ChatHandler::HandleReloadQuestStartScriptsCommand(const char* arg
)
573 if(sWorld
.IsScriptScheduled())
575 SendSysMessage("DB scripts used currently, please attempt reload later.");
576 SetSentErrorMessage(true);
581 sLog
.outString( "Re-Loading Scripts from `quest_start_scripts`...");
583 objmgr
.LoadQuestStartScripts();
586 SendGlobalSysMessage("DB table `quest_start_scripts` reloaded.");
591 bool ChatHandler::HandleReloadSpellScriptsCommand(const char* arg
)
593 if(sWorld
.IsScriptScheduled())
595 SendSysMessage("DB scripts used currently, please attempt reload later.");
596 SetSentErrorMessage(true);
601 sLog
.outString( "Re-Loading Scripts from `spell_scripts`...");
603 objmgr
.LoadSpellScripts();
606 SendGlobalSysMessage("DB table `spell_scripts` reloaded.");
611 bool ChatHandler::HandleReloadDbScriptStringCommand(const char* arg
)
613 sLog
.outString( "Re-Loading Script strings from `db_script_string`...");
614 objmgr
.LoadDbScriptStrings();
615 SendGlobalSysMessage("DB table `db_script_string` reloaded.");
619 bool ChatHandler::HandleReloadGameGraveyardZoneCommand(const char* /*arg*/)
621 sLog
.outString( "Re-Loading Graveyard-zone links...");
623 objmgr
.LoadGraveyardZones();
625 SendGlobalSysMessage("DB table `game_graveyard_zone` reloaded.");
630 bool ChatHandler::HandleReloadGameTeleCommand(const char* /*arg*/)
632 sLog
.outString( "Re-Loading Game Tele coordinates...");
634 objmgr
.LoadGameTele();
636 SendGlobalSysMessage("DB table `game_tele` reloaded.");
641 bool ChatHandler::HandleReloadLocalesCreatureCommand(const char* /*arg*/)
643 sLog
.outString( "Re-Loading Locales Creature ...");
644 objmgr
.LoadCreatureLocales();
645 SendGlobalSysMessage("DB table `locales_creature` reloaded.");
649 bool ChatHandler::HandleReloadLocalesGameobjectCommand(const char* /*arg*/)
651 sLog
.outString( "Re-Loading Locales Gameobject ... ");
652 objmgr
.LoadGameObjectLocales();
653 SendGlobalSysMessage("DB table `locales_gameobject` reloaded.");
657 bool ChatHandler::HandleReloadLocalesItemCommand(const char* /*arg*/)
659 sLog
.outString( "Re-Loading Locales Item ... ");
660 objmgr
.LoadItemLocales();
661 SendGlobalSysMessage("DB table `locales_item` reloaded.");
665 bool ChatHandler::HandleReloadLocalesNpcTextCommand(const char* /*arg*/)
667 sLog
.outString( "Re-Loading Locales NPC Text ... ");
668 objmgr
.LoadNpcTextLocales();
669 SendGlobalSysMessage("DB table `locales_npc_text` reloaded.");
673 bool ChatHandler::HandleReloadLocalesPageTextCommand(const char* /*arg*/)
675 sLog
.outString( "Re-Loading Locales Page Text ... ");
676 objmgr
.LoadPageTextLocales();
677 SendGlobalSysMessage("DB table `locales_page_text` reloaded.");
681 bool ChatHandler::HandleReloadLocalesQuestCommand(const char* /*arg*/)
683 sLog
.outString( "Re-Loading Locales Quest ... ");
684 objmgr
.LoadQuestLocales();
685 SendGlobalSysMessage("DB table `locales_quest` reloaded.");
689 bool ChatHandler::HandleLoadScriptsCommand(const char* args
)
691 if(!LoadScriptingModule(args
)) return true;
693 sWorld
.SendWorldText(LANG_SCRIPTS_RELOADED
);
697 bool ChatHandler::HandleAccountSetGmLevelCommand(const char* args
)
699 char* arg1
= strtok((char*)args
, " ");
703 /// must be NULL if targeted syntax and must be not nULL if not targeted
704 char* arg2
= strtok(NULL
, " ");
706 std::string targetAccountName
;
707 uint32 targetAccountId
= 0;
709 /// only target player different from self allowed (if targetPlayer!=NULL then not console)
710 Player
* targetPlayer
= getSelectedPlayer();
711 if(targetPlayer
&& m_session
->GetPlayer()!=targetPlayer
)
713 /// wrong command syntax or unexpected targeting
717 /// security level expected in arg2 after this if.
720 targetAccountId
= targetPlayer
->GetSession()->GetAccountId();
724 /// wrong command syntax (second arg expected)
728 targetAccountName
= arg1
;
729 if(!AccountMgr::normilizeString(targetAccountName
))
731 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,targetAccountName
.c_str());
732 SetSentErrorMessage(true);
736 targetAccountId
= accmgr
.GetId(targetAccountName
);
739 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,targetAccountName
.c_str());
740 SetSentErrorMessage(true);
745 int32 gm
= (int32
)atoi(arg2
);
746 if ( gm
< SEC_PLAYER
|| gm
> SEC_ADMINISTRATOR
)
748 SendSysMessage(LANG_BAD_VALUE
);
749 SetSentErrorMessage(true);
753 /// can set security level only for target with less security and to less security that we have
754 /// This is also reject self apply in fact
755 if(HasLowerSecurityAccount(NULL
,targetAccountId
,true))
758 /// account can't set security to same or grater level, need more power GM or console
759 uint32 plSecurity
= m_session
? m_session
->GetSecurity() : SEC_CONSOLE
;
760 if (uint32(gm
) >= plSecurity
)
762 SendSysMessage(LANG_YOURS_SECURITY_IS_LOW
);
763 SetSentErrorMessage(true);
769 ChatHandler(targetPlayer
).PSendSysMessage(LANG_YOURS_SECURITY_CHANGED
,GetName(), gm
);
770 targetPlayer
->GetSession()->SetSecurity(gm
);
773 PSendSysMessage(LANG_YOU_CHANGE_SECURITY
, targetAccountName
.c_str(), gm
);
774 loginDatabase
.PExecute("UPDATE account SET gmlevel = '%i' WHERE id = '%u'", gm
, targetAccountId
);
779 /// Set password for account
780 bool ChatHandler::HandleAccountSetPasswordCommand(const char* args
)
785 ///- Get the command line arguments
786 char *szAccount
= strtok ((char*)args
," ");
787 char *szPassword1
= strtok (NULL
," ");
788 char *szPassword2
= strtok (NULL
," ");
790 if (!szAccount
||!szPassword1
|| !szPassword2
)
793 std::string account_name
= szAccount
;
794 if(!AccountMgr::normilizeString(account_name
))
796 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
797 SetSentErrorMessage(true);
801 uint32 targetAccountId
= accmgr
.GetId(account_name
);
802 if (!targetAccountId
)
804 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
805 SetSentErrorMessage(true);
809 /// can set password only for target with less security
810 /// This is also reject self apply in fact
811 if(HasLowerSecurityAccount (NULL
,targetAccountId
,true))
814 if (strcmp(szPassword1
,szPassword2
))
816 SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH
);
817 SetSentErrorMessage (true);
821 AccountOpResult result
= accmgr
.ChangePassword(targetAccountId
, szPassword1
);
826 SendSysMessage(LANG_COMMAND_PASSWORD
);
828 case AOR_NAME_NOT_EXIST
:
829 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
830 SetSentErrorMessage(true);
832 case AOR_PASS_TOO_LONG
:
833 SendSysMessage(LANG_PASSWORD_TOO_LONG
);
834 SetSentErrorMessage(true);
837 SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD
);
838 SetSentErrorMessage(true);
845 bool ChatHandler::HandleAllowMovementCommand(const char* /*args*/)
847 if(sWorld
.getAllowMovement())
849 sWorld
.SetAllowMovement(false);
850 SendSysMessage(LANG_CREATURE_MOVE_DISABLED
);
854 sWorld
.SetAllowMovement(true);
855 SendSysMessage(LANG_CREATURE_MOVE_ENABLED
);
860 bool ChatHandler::HandleMaxSkillCommand(const char* /*args*/)
862 Player
* SelectedPlayer
= getSelectedPlayer();
865 SendSysMessage(LANG_NO_CHAR_SELECTED
);
866 SetSentErrorMessage(true);
870 // each skills that have max skill value dependent from level seted to current level max skill value
871 SelectedPlayer
->UpdateSkillsToMaxSkillsForLevel();
875 bool ChatHandler::HandleSetSkillCommand(const char* args
)
877 // number or [name] Shift-click form |color|Hskill:skill_id|h[name]|h|r
878 char* skill_p
= extractKeyFromLink((char*)args
,"Hskill");
882 char *level_p
= strtok (NULL
, " ");
887 char *max_p
= strtok (NULL
, " ");
889 int32 skill
= atoi(skill_p
);
893 PSendSysMessage(LANG_INVALID_SKILL_ID
, skill
);
894 SetSentErrorMessage(true);
898 int32 level
= atol (level_p
);
900 Player
* target
= getSelectedPlayer();
903 SendSysMessage(LANG_NO_CHAR_SELECTED
);
904 SetSentErrorMessage(true);
908 SkillLineEntry
const* sl
= sSkillLineStore
.LookupEntry(skill
);
911 PSendSysMessage(LANG_INVALID_SKILL_ID
, skill
);
912 SetSentErrorMessage(true);
916 if(!target
->GetSkillValue(skill
))
918 PSendSysMessage(LANG_SET_SKILL_ERROR
, target
->GetName(), skill
, sl
->name
[0]);
919 SetSentErrorMessage(true);
923 int32 max
= max_p
? atol (max_p
) : target
->GetPureMaxSkillValue(skill
);
925 if( level
<= 0 || level
> max
|| max
<= 0 )
928 target
->SetSkill(skill
, level
, max
);
929 PSendSysMessage(LANG_SET_SKILL
, skill
, sl
->name
[0], target
->GetName(), level
, max
);
934 bool ChatHandler::HandleUnLearnCommand(const char* args
)
939 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
940 uint32 min_id
= extractSpellIdFromLink((char*)args
);
944 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
945 char* tail
= strtok(NULL
,"");
947 uint32 max_id
= extractSpellIdFromLink(tail
);
951 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
957 std::swap(min_id
,max_id
);
962 Player
* target
= getSelectedPlayer();
965 SendSysMessage(LANG_NO_CHAR_SELECTED
);
966 SetSentErrorMessage(true);
970 for(uint32 spell
=min_id
;spell
<max_id
;spell
++)
972 if (target
->HasSpell(spell
))
973 target
->removeSpell(spell
);
975 SendSysMessage(LANG_FORGET_SPELL
);
981 bool ChatHandler::HandleCooldownCommand(const char* args
)
983 Player
* target
= getSelectedPlayer();
986 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
987 SetSentErrorMessage(true);
993 target
->RemoveAllSpellCooldown();
994 PSendSysMessage(LANG_REMOVEALL_COOLDOWN
, target
->GetName());
998 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
999 uint32 spell_id
= extractSpellIdFromLink((char*)args
);
1003 if(!sSpellStore
.LookupEntry(spell_id
))
1005 PSendSysMessage(LANG_UNKNOWN_SPELL
, target
==m_session
->GetPlayer() ? GetMangosString(LANG_YOU
) : target
->GetName());
1006 SetSentErrorMessage(true);
1010 WorldPacket
data( SMSG_CLEAR_COOLDOWN
, (4+8) );
1011 data
<< uint32(spell_id
);
1012 data
<< uint64(target
->GetGUID());
1013 target
->GetSession()->SendPacket(&data
);
1014 target
->RemoveSpellCooldown(spell_id
);
1015 PSendSysMessage(LANG_REMOVE_COOLDOWN
, spell_id
, target
==m_session
->GetPlayer() ? GetMangosString(LANG_YOU
) : target
->GetName());
1020 bool ChatHandler::HandleLearnAllCommand(const char* /*args*/)
1022 static const char *allSpellList
[] =
1405 //"9036", problems with ghost state
1414 //"6718", phasing stealth, annoying for learn all case.
1627 while(strcmp(allSpellList
[loop
], "0"))
1629 uint32 spell
= atol((char*)allSpellList
[loop
++]);
1631 if (m_session
->GetPlayer()->HasSpell(spell
))
1634 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1635 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1637 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1641 m_session
->GetPlayer()->learnSpell(spell
,false);
1644 SendSysMessage(LANG_COMMAND_LEARN_MANY_SPELLS
);
1649 bool ChatHandler::HandleLearnAllGMCommand(const char* /*args*/)
1651 static const char *gmSpellList
[] =
1653 "24347", // Become A Fish, No Breath Bar
1654 "35132", // Visual Boom
1655 "38488", // Attack 4000-8000 AOE
1656 "38795", // Attack 2000 AOE + Slow Down 90%
1657 "15712", // Attack 200
1658 "1852", // GM Spell Silence
1661 "29878", // Kill My Self
1662 "26644", // More Kill
1664 "28550", //Invisible 24
1665 "23452", //Invisible + Target
1669 uint16 gmSpellIter
= 0;
1670 while( strcmp(gmSpellList
[gmSpellIter
], "0") )
1672 uint32 spell
= atol((char*)gmSpellList
[gmSpellIter
++]);
1674 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1675 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1677 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1681 m_session
->GetPlayer()->learnSpell(spell
,false);
1684 SendSysMessage(LANG_LEARNING_GM_SKILLS
);
1688 bool ChatHandler::HandleLearnAllMyClassCommand(const char* /*args*/)
1690 HandleLearnAllMySpellsCommand("");
1691 HandleLearnAllMyTalentsCommand("");
1695 bool ChatHandler::HandleLearnAllMySpellsCommand(const char* /*args*/)
1697 ChrClassesEntry
const* clsEntry
= sChrClassesStore
.LookupEntry(m_session
->GetPlayer()->getClass());
1700 uint32 family
= clsEntry
->spellfamily
;
1702 for (uint32 i
= 0; i
< sSpellStore
.GetNumRows(); i
++)
1704 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(i
);
1708 // skip server-side/triggered spells
1709 if(spellInfo
->spellLevel
==0)
1712 // skip wrong class/race skills
1713 if(!m_session
->GetPlayer()->IsSpellFitByClassAndRace(spellInfo
->Id
))
1716 // skip other spell families
1717 if( spellInfo
->SpellFamilyName
!= family
)
1720 // skip spells with first rank learned as talent (and all talents then also)
1721 uint32 first_rank
= spellmgr
.GetFirstSpellInChain(spellInfo
->Id
);
1722 if(GetTalentSpellCost(first_rank
) > 0 )
1725 // skip broken spells
1726 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1729 m_session
->GetPlayer()->learnSpell(i
,false);
1732 SendSysMessage(LANG_COMMAND_LEARN_CLASS_SPELLS
);
1736 static void learnAllHighRanks(Player
* player
, uint32 spellid
)
1738 SpellChainMapNext
const& nextMap
= spellmgr
.GetSpellChainNext();
1739 for(SpellChainMapNext::const_iterator itr
= nextMap
.lower_bound(spellid
); itr
!= nextMap
.upper_bound(spellid
); ++itr
)
1741 player
->learnSpell(itr
->second
,false);
1742 learnAllHighRanks(player
,itr
->second
);
1746 bool ChatHandler::HandleLearnAllMyTalentsCommand(const char* /*args*/)
1748 Player
* player
= m_session
->GetPlayer();
1749 uint32 classMask
= player
->getClassMask();
1751 for (uint32 i
= 0; i
< sTalentStore
.GetNumRows(); i
++)
1753 TalentEntry
const *talentInfo
= sTalentStore
.LookupEntry(i
);
1757 TalentTabEntry
const *talentTabInfo
= sTalentTabStore
.LookupEntry( talentInfo
->TalentTab
);
1761 if( (classMask
& talentTabInfo
->ClassMask
) == 0 )
1764 // search highest talent rank
1767 for(; rank
>= 0; --rank
)
1769 if(talentInfo
->RankID
[rank
]!=0)
1771 spellid
= talentInfo
->RankID
[rank
];
1776 if(!spellid
) // ??? none spells in talent
1779 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spellid
);
1780 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1783 // learn highest rank of talent
1784 player
->learnSpell(spellid
,false);
1786 // and learn all non-talent spell ranks (recursive by tree)
1787 learnAllHighRanks(player
,spellid
);
1790 SendSysMessage(LANG_COMMAND_LEARN_CLASS_TALENTS
);
1794 bool ChatHandler::HandleLearnAllLangCommand(const char* /*args*/)
1796 // skipping UNIVERSAL language (0)
1797 for(int i
= 1; i
< LANGUAGES_COUNT
; ++i
)
1798 m_session
->GetPlayer()->learnSpell(lang_description
[i
].spell_id
,false);
1800 SendSysMessage(LANG_COMMAND_LEARN_ALL_LANG
);
1804 bool ChatHandler::HandleLearnAllDefaultCommand(const char* args
)
1806 char* pName
= strtok((char*)args
, "");
1807 Player
*player
= NULL
;
1810 std::string name
= pName
;
1812 if(!normalizePlayerName(name
))
1814 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1815 SetSentErrorMessage(true);
1819 player
= objmgr
.GetPlayer(name
.c_str());
1822 player
= getSelectedPlayer();
1826 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1827 SetSentErrorMessage(true);
1831 player
->learnDefaultSpells();
1832 player
->learnQuestRewardedSpells();
1834 PSendSysMessage(LANG_COMMAND_LEARN_ALL_DEFAULT_AND_QUEST
,player
->GetName());
1838 bool ChatHandler::HandleLearnCommand(const char* args
)
1840 Player
* targetPlayer
= getSelectedPlayer();
1844 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1845 SetSentErrorMessage(true);
1849 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1850 uint32 spell
= extractSpellIdFromLink((char*)args
);
1851 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
1854 if (targetPlayer
->HasSpell(spell
))
1856 if(targetPlayer
== m_session
->GetPlayer())
1857 SendSysMessage(LANG_YOU_KNOWN_SPELL
);
1859 PSendSysMessage(LANG_TARGET_KNOWN_SPELL
,targetPlayer
->GetName());
1860 SetSentErrorMessage(true);
1864 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1865 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1867 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1868 SetSentErrorMessage(true);
1872 targetPlayer
->learnSpell(spell
,false);
1877 bool ChatHandler::HandleAddItemCommand(const char* args
)
1884 if(args
[0]=='[') // [name] manual form
1886 char* citemName
= citemName
= strtok((char*)args
, "]");
1888 if(citemName
&& citemName
[0])
1890 std::string itemName
= citemName
+1;
1891 WorldDatabase
.escape_string(itemName
);
1892 QueryResult
*result
= WorldDatabase
.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName
.c_str());
1895 PSendSysMessage(LANG_COMMAND_COULDNOTFIND
, citemName
+1);
1896 SetSentErrorMessage(true);
1899 itemId
= result
->Fetch()->GetUInt16();
1905 else // item_id or [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r
1907 char* cId
= extractKeyFromLink((char*)args
,"Hitem");
1913 char* ccount
= strtok(NULL
, " ");
1918 count
= strtol(ccount
, NULL
, 10);
1923 Player
* pl
= m_session
->GetPlayer();
1924 Player
* plTarget
= getSelectedPlayer();
1928 sLog
.outDetail(GetMangosString(LANG_ADDITEM
), itemId
, count
);
1930 ItemPrototype
const *pProto
= objmgr
.GetItemPrototype(itemId
);
1933 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, itemId
);
1934 SetSentErrorMessage(true);
1941 plTarget
->DestroyItemCount(itemId
, -count
, true, false);
1942 PSendSysMessage(LANG_REMOVEITEM
, itemId
, -count
, plTarget
->GetName());
1947 uint32 noSpaceForCount
= 0;
1949 // check space and find places
1950 ItemPosCountVec dest
;
1951 uint8 msg
= plTarget
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, itemId
, count
, &noSpaceForCount
);
1952 if( msg
!= EQUIP_ERR_OK
) // convert to possible store amount
1953 count
-= noSpaceForCount
;
1955 if( count
== 0 || dest
.empty()) // can't add any
1957 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, itemId
, noSpaceForCount
);
1958 SetSentErrorMessage(true);
1962 Item
* item
= plTarget
->StoreNewItem( dest
, itemId
, true, Item::GenerateItemRandomPropertyId(itemId
));
1964 // remove binding (let GM give it to another player later)
1966 for(ItemPosCountVec::const_iterator itr
= dest
.begin(); itr
!= dest
.end(); ++itr
)
1967 if(Item
* item1
= pl
->GetItemByPos(itr
->pos
))
1968 item1
->SetBinding( false );
1970 if(count
> 0 && item
)
1972 pl
->SendNewItem(item
,count
,false,true);
1974 plTarget
->SendNewItem(item
,count
,true,false);
1977 if(noSpaceForCount
> 0)
1978 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, itemId
, noSpaceForCount
);
1983 bool ChatHandler::HandleAddItemSetCommand(const char* args
)
1988 char* cId
= extractKeyFromLink((char*)args
,"Hitemset"); // number or [name] Shift-click form |color|Hitemset:itemset_id|h[name]|h|r
1992 uint32 itemsetId
= atol(cId
);
1994 // prevent generation all items with itemset field value '0'
1997 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND
,itemsetId
);
1998 SetSentErrorMessage(true);
2002 Player
* pl
= m_session
->GetPlayer();
2003 Player
* plTarget
= getSelectedPlayer();
2007 sLog
.outDetail(GetMangosString(LANG_ADDITEMSET
), itemsetId
);
2010 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
2012 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
2016 if (pProto
->ItemSet
== itemsetId
)
2019 ItemPosCountVec dest
;
2020 uint8 msg
= plTarget
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, pProto
->ItemId
, 1 );
2021 if (msg
== EQUIP_ERR_OK
)
2023 Item
* item
= plTarget
->StoreNewItem( dest
, pProto
->ItemId
, true);
2025 // remove binding (let GM give it to another player later)
2027 item
->SetBinding( false );
2029 pl
->SendNewItem(item
,1,false,true);
2031 plTarget
->SendNewItem(item
,1,true,false);
2035 pl
->SendEquipError( msg
, NULL
, NULL
);
2036 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, pProto
->ItemId
, 1);
2043 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND
,itemsetId
);
2045 SetSentErrorMessage(true);
2052 bool ChatHandler::HandleListItemCommand(const char* args
)
2057 char* cId
= extractKeyFromLink((char*)args
,"Hitem");
2061 uint32 item_id
= atol(cId
);
2064 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
2065 SetSentErrorMessage(true);
2069 ItemPrototype
const* itemProto
= objmgr
.GetItemPrototype(item_id
);
2072 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
2073 SetSentErrorMessage(true);
2077 char* c_count
= strtok(NULL
, " ");
2078 int count
= c_count
? atol(c_count
) : 10;
2083 QueryResult
*result
;
2086 uint32 inv_count
= 0;
2087 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM character_inventory WHERE item_template='%u'",item_id
);
2090 inv_count
= (*result
)[0].GetUInt32();
2094 result
=CharacterDatabase
.PQuery(
2096 "SELECT ci.item, cibag.slot AS bag, ci.slot, ci.guid, characters.account,characters.name "
2097 "FROM character_inventory AS ci LEFT JOIN character_inventory AS cibag ON (cibag.item=ci.bag),characters "
2098 "WHERE ci.item_template='%u' AND ci.guid = characters.guid LIMIT %u ",
2099 item_id
,uint32(count
));
2105 Field
*fields
= result
->Fetch();
2106 uint32 item_guid
= fields
[0].GetUInt32();
2107 uint32 item_bag
= fields
[1].GetUInt32();
2108 uint32 item_slot
= fields
[2].GetUInt32();
2109 uint32 owner_guid
= fields
[3].GetUInt32();
2110 uint32 owner_acc
= fields
[4].GetUInt32();
2111 std::string owner_name
= fields
[5].GetCppString();
2113 char const* item_pos
= 0;
2114 if(Player::IsEquipmentPos(item_bag
,item_slot
))
2115 item_pos
= "[equipped]";
2116 else if(Player::IsInventoryPos(item_bag
,item_slot
))
2117 item_pos
= "[in inventory]";
2118 else if(Player::IsBankPos(item_bag
,item_slot
))
2119 item_pos
= "[in bank]";
2123 PSendSysMessage(LANG_ITEMLIST_SLOT
,
2124 item_guid
,owner_name
.c_str(),owner_guid
,owner_acc
,item_pos
);
2125 } while (result
->NextRow());
2127 int64 res_count
= result
->GetRowCount();
2131 if(count
> res_count
)
2138 uint32 mail_count
= 0;
2139 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM mail_items WHERE item_template='%u'", item_id
);
2142 mail_count
= (*result
)[0].GetUInt32();
2148 result
=CharacterDatabase
.PQuery(
2150 "SELECT mail_items.item_guid, mail.sender, mail.receiver, char_s.account, char_s.name, char_r.account, char_r.name "
2151 "FROM mail,mail_items,characters as char_s,characters as char_r "
2152 "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",
2153 item_id
,uint32(count
));
2162 Field
*fields
= result
->Fetch();
2163 uint32 item_guid
= fields
[0].GetUInt32();
2164 uint32 item_s
= fields
[1].GetUInt32();
2165 uint32 item_r
= fields
[2].GetUInt32();
2166 uint32 item_s_acc
= fields
[3].GetUInt32();
2167 std::string item_s_name
= fields
[4].GetCppString();
2168 uint32 item_r_acc
= fields
[5].GetUInt32();
2169 std::string item_r_name
= fields
[6].GetCppString();
2171 char const* item_pos
= "[in mail]";
2173 PSendSysMessage(LANG_ITEMLIST_MAIL
,
2174 item_guid
,item_s_name
.c_str(),item_s
,item_s_acc
,item_r_name
.c_str(),item_r
,item_r_acc
,item_pos
);
2175 } while (result
->NextRow());
2177 int64 res_count
= result
->GetRowCount();
2181 if(count
> res_count
)
2188 uint32 auc_count
= 0;
2189 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM auctionhouse WHERE item_template='%u'",item_id
);
2192 auc_count
= (*result
)[0].GetUInt32();
2198 result
=CharacterDatabase
.PQuery(
2200 "SELECT auctionhouse.itemguid, auctionhouse.itemowner, characters.account, characters.name "
2201 "FROM auctionhouse,characters WHERE auctionhouse.item_template='%u' AND characters.guid = auctionhouse.itemowner LIMIT %u",
2202 item_id
,uint32(count
));
2211 Field
*fields
= result
->Fetch();
2212 uint32 item_guid
= fields
[0].GetUInt32();
2213 uint32 owner
= fields
[1].GetUInt32();
2214 uint32 owner_acc
= fields
[2].GetUInt32();
2215 std::string owner_name
= fields
[3].GetCppString();
2217 char const* item_pos
= "[in auction]";
2219 PSendSysMessage(LANG_ITEMLIST_AUCTION
, item_guid
, owner_name
.c_str(), owner
, owner_acc
,item_pos
);
2220 } while (result
->NextRow());
2226 uint32 guild_count
= 0;
2227 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_entry) FROM guild_bank_item WHERE item_entry='%u'",item_id
);
2230 guild_count
= (*result
)[0].GetUInt32();
2234 result
=CharacterDatabase
.PQuery(
2236 "SELECT gi.item_guid, gi.guildid, guild.name "
2237 "FROM guild_bank_item AS gi, guild WHERE gi.item_entry='%u' AND gi.guildid = guild.guildid LIMIT %u ",
2238 item_id
,uint32(count
));
2244 Field
*fields
= result
->Fetch();
2245 uint32 item_guid
= fields
[0].GetUInt32();
2246 uint32 guild_guid
= fields
[1].GetUInt32();
2247 std::string guild_name
= fields
[2].GetCppString();
2249 char const* item_pos
= "[in guild bank]";
2251 PSendSysMessage(LANG_ITEMLIST_GUILD
,item_guid
,guild_name
.c_str(),guild_guid
,item_pos
);
2252 } while (result
->NextRow());
2254 int64 res_count
= result
->GetRowCount();
2258 if(count
> res_count
)
2264 if(inv_count
+mail_count
+auc_count
+guild_count
== 0)
2266 SendSysMessage(LANG_COMMAND_NOITEMFOUND
);
2267 SetSentErrorMessage(true);
2271 PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE
,item_id
,inv_count
+mail_count
+auc_count
+guild_count
,inv_count
,mail_count
,auc_count
,guild_count
);
2276 bool ChatHandler::HandleListObjectCommand(const char* args
)
2281 // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2282 char* cId
= extractKeyFromLink((char*)args
,"Hgameobject_entry");
2286 uint32 go_id
= atol(cId
);
2289 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID
, go_id
);
2290 SetSentErrorMessage(true);
2294 GameObjectInfo
const * gInfo
= objmgr
.GetGameObjectInfo(go_id
);
2297 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID
, go_id
);
2298 SetSentErrorMessage(true);
2302 char* c_count
= strtok(NULL
, " ");
2303 int count
= c_count
? atol(c_count
) : 10;
2308 QueryResult
*result
;
2310 uint32 obj_count
= 0;
2311 result
=WorldDatabase
.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'",go_id
);
2314 obj_count
= (*result
)[0].GetUInt32();
2320 Player
* pl
= m_session
->GetPlayer();
2321 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",
2322 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(),go_id
,uint32(count
));
2325 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map FROM gameobject WHERE id = '%u' LIMIT %u",
2326 go_id
,uint32(count
));
2332 Field
*fields
= result
->Fetch();
2333 uint32 guid
= fields
[0].GetUInt32();
2334 float x
= fields
[1].GetFloat();
2335 float y
= fields
[2].GetFloat();
2336 float z
= fields
[3].GetFloat();
2337 int mapid
= fields
[4].GetUInt16();
2340 PSendSysMessage(LANG_GO_LIST_CHAT
, guid
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2342 PSendSysMessage(LANG_GO_LIST_CONSOLE
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2343 } while (result
->NextRow());
2348 PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE
,go_id
,obj_count
);
2352 bool ChatHandler::HandleNearObjectCommand(const char* args
)
2354 float distance
= (!*args
) ? 10 : atol(args
);
2357 Player
* pl
= m_session
->GetPlayer();
2358 QueryResult
*result
= WorldDatabase
.PQuery("SELECT guid, id, position_x, position_y, position_z, map, "
2359 "(POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ "
2360 "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_",
2361 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(),
2362 pl
->GetMapId(),pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(),distance
*distance
);
2368 Field
*fields
= result
->Fetch();
2369 uint32 guid
= fields
[0].GetUInt32();
2370 uint32 entry
= fields
[1].GetUInt32();
2371 float x
= fields
[2].GetFloat();
2372 float y
= fields
[3].GetFloat();
2373 float z
= fields
[4].GetFloat();
2374 int mapid
= fields
[5].GetUInt16();
2376 GameObjectInfo
const * gInfo
= objmgr
.GetGameObjectInfo(entry
);
2381 PSendSysMessage(LANG_GO_LIST_CHAT
, guid
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2384 } while (result
->NextRow());
2389 PSendSysMessage(LANG_COMMAND_NEAROBJMESSAGE
,distance
,count
);
2393 bool ChatHandler::HandleListCreatureCommand(const char* args
)
2398 // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
2399 char* cId
= extractKeyFromLink((char*)args
,"Hcreature_entry");
2403 uint32 cr_id
= atol(cId
);
2406 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID
, cr_id
);
2407 SetSentErrorMessage(true);
2411 CreatureInfo
const* cInfo
= objmgr
.GetCreatureTemplate(cr_id
);
2414 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID
, cr_id
);
2415 SetSentErrorMessage(true);
2419 char* c_count
= strtok(NULL
, " ");
2420 int count
= c_count
? atol(c_count
) : 10;
2425 QueryResult
*result
;
2427 uint32 cr_count
= 0;
2428 result
=WorldDatabase
.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'",cr_id
);
2431 cr_count
= (*result
)[0].GetUInt32();
2437 Player
* pl
= m_session
->GetPlayer();
2438 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",
2439 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(), cr_id
,uint32(count
));
2442 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '%u' LIMIT %u",
2443 cr_id
,uint32(count
));
2449 Field
*fields
= result
->Fetch();
2450 uint32 guid
= fields
[0].GetUInt32();
2451 float x
= fields
[1].GetFloat();
2452 float y
= fields
[2].GetFloat();
2453 float z
= fields
[3].GetFloat();
2454 int mapid
= fields
[4].GetUInt16();
2457 PSendSysMessage(LANG_CREATURE_LIST_CHAT
, guid
, guid
, cInfo
->Name
, x
, y
, z
, mapid
);
2459 PSendSysMessage(LANG_CREATURE_LIST_CONSOLE
, guid
, cInfo
->Name
, x
, y
, z
, mapid
);
2460 } while (result
->NextRow());
2465 PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE
,cr_id
,cr_count
);
2469 bool ChatHandler::HandleLookupItemCommand(const char* args
)
2474 std::string namepart
= args
;
2475 std::wstring wnamepart
;
2477 // converting string that we try to find to lower case
2478 if(!Utf8toWStr(namepart
,wnamepart
))
2481 wstrToLower(wnamepart
);
2485 // Search in `item_template`
2486 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
2488 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
2492 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2495 ItemLocale
const *il
= objmgr
.GetItemLocale(pProto
->ItemId
);
2498 if (il
->Name
.size() > loc_idx
&& !il
->Name
[loc_idx
].empty())
2500 std::string name
= il
->Name
[loc_idx
];
2502 if (Utf8FitTo(name
, wnamepart
))
2505 PSendSysMessage(LANG_ITEM_LIST_CHAT
, id
, id
, name
.c_str());
2507 PSendSysMessage(LANG_ITEM_LIST_CONSOLE
, id
, name
.c_str());
2515 std::string name
= pProto
->Name1
;
2519 if (Utf8FitTo(name
, wnamepart
))
2522 PSendSysMessage(LANG_ITEM_LIST_CHAT
, id
, id
, name
.c_str());
2524 PSendSysMessage(LANG_ITEM_LIST_CONSOLE
, id
, name
.c_str());
2530 SendSysMessage(LANG_COMMAND_NOITEMFOUND
);
2535 bool ChatHandler::HandleLookupItemSetCommand(const char* args
)
2540 std::string namepart
= args
;
2541 std::wstring wnamepart
;
2543 if(!Utf8toWStr(namepart
,wnamepart
))
2546 // converting string that we try to find to lower case
2547 wstrToLower( wnamepart
);
2549 uint32 counter
= 0; // Counter for figure out that we found smth.
2551 // Search in ItemSet.dbc
2552 for (uint32 id
= 0; id
< sItemSetStore
.GetNumRows(); id
++)
2554 ItemSetEntry
const *set
= sItemSetStore
.LookupEntry(id
);
2557 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
2558 std::string name
= set
->name
[loc
];
2562 if (!Utf8FitTo(name
, wnamepart
))
2565 for(; loc
< MAX_LOCALE
; ++loc
)
2567 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
2570 name
= set
->name
[loc
];
2574 if (Utf8FitTo(name
, wnamepart
))
2579 if(loc
< MAX_LOCALE
)
2581 // send item set in "id - [namedlink locale]" format
2583 PSendSysMessage(LANG_ITEMSET_LIST_CHAT
,id
,id
,name
.c_str(),localeNames
[loc
]);
2585 PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE
,id
,name
.c_str(),localeNames
[loc
]);
2590 if (counter
== 0) // if counter == 0 then we found nth
2591 SendSysMessage(LANG_COMMAND_NOITEMSETFOUND
);
2595 bool ChatHandler::HandleLookupSkillCommand(const char* args
)
2600 // can be NULL in console call
2601 Player
* target
= getSelectedPlayer();
2603 std::string namepart
= args
;
2604 std::wstring wnamepart
;
2606 if(!Utf8toWStr(namepart
,wnamepart
))
2609 // converting string that we try to find to lower case
2610 wstrToLower( wnamepart
);
2612 uint32 counter
= 0; // Counter for figure out that we found smth.
2614 // Search in SkillLine.dbc
2615 for (uint32 id
= 0; id
< sSkillLineStore
.GetNumRows(); id
++)
2617 SkillLineEntry
const *skillInfo
= sSkillLineStore
.LookupEntry(id
);
2620 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
2621 std::string name
= skillInfo
->name
[loc
];
2625 if (!Utf8FitTo(name
, wnamepart
))
2628 for(; loc
< MAX_LOCALE
; ++loc
)
2630 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
2633 name
= skillInfo
->name
[loc
];
2637 if (Utf8FitTo(name
, wnamepart
))
2642 if(loc
< MAX_LOCALE
)
2644 char valStr
[50] = "";
2645 char const* knownStr
= "";
2646 if(target
&& target
->HasSkill(id
))
2648 knownStr
= GetMangosString(LANG_KNOWN
);
2649 uint32 curValue
= target
->GetPureSkillValue(id
);
2650 uint32 maxValue
= target
->GetPureMaxSkillValue(id
);
2651 uint32 permValue
= target
->GetSkillPermBonusValue(id
);
2652 uint32 tempValue
= target
->GetSkillTempBonusValue(id
);
2654 char const* valFormat
= GetMangosString(LANG_SKILL_VALUES
);
2655 snprintf(valStr
,50,valFormat
,curValue
,maxValue
,permValue
,tempValue
);
2658 // send skill in "id - [namedlink locale]" format
2660 PSendSysMessage(LANG_SKILL_LIST_CHAT
,id
,id
,name
.c_str(),localeNames
[loc
],knownStr
,valStr
);
2662 PSendSysMessage(LANG_SKILL_LIST_CONSOLE
,id
,name
.c_str(),localeNames
[loc
],knownStr
,valStr
);
2668 if (counter
== 0) // if counter == 0 then we found nth
2669 SendSysMessage(LANG_COMMAND_NOSKILLFOUND
);
2673 bool ChatHandler::HandleLookupSpellCommand(const char* args
)
2678 // can be NULL at console call
2679 Player
* target
= getSelectedPlayer();
2681 std::string namepart
= args
;
2682 std::wstring wnamepart
;
2684 if(!Utf8toWStr(namepart
,wnamepart
))
2687 // converting string that we try to find to lower case
2688 wstrToLower( wnamepart
);
2690 uint32 counter
= 0; // Counter for figure out that we found smth.
2692 // Search in Spell.dbc
2693 for (uint32 id
= 0; id
< sSpellStore
.GetNumRows(); id
++)
2695 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(id
);
2698 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
2699 std::string name
= spellInfo
->SpellName
[loc
];
2703 if (!Utf8FitTo(name
, wnamepart
))
2706 for(; loc
< MAX_LOCALE
; ++loc
)
2708 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
2711 name
= spellInfo
->SpellName
[loc
];
2715 if (Utf8FitTo(name
, wnamepart
))
2720 if(loc
< MAX_LOCALE
)
2722 bool known
= target
&& target
->HasSpell(id
);
2723 bool learn
= (spellInfo
->Effect
[0] == SPELL_EFFECT_LEARN_SPELL
);
2725 uint32 talentCost
= GetTalentSpellCost(id
);
2727 bool talent
= (talentCost
> 0);
2728 bool passive
= IsPassiveSpell(id
);
2729 bool active
= target
&& target
->HasAura(id
);
2731 // unit32 used to prevent interpreting uint8 as char at output
2732 // find rank of learned spell for learning spell, or talent rank
2733 uint32 rank
= talentCost
? talentCost
: spellmgr
.GetSpellRank(learn
? spellInfo
->EffectTriggerSpell
[0] : id
);
2735 // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
2736 std::ostringstream ss
;
2738 ss
<< id
<< " - |cffffffff|Hspell:" << id
<< "|h[" << name
;
2740 ss
<< id
<< " - " << name
;
2742 // include rank in link name
2744 ss
<< GetMangosString(LANG_SPELL_RANK
) << rank
;
2747 ss
<< " " << localeNames
[loc
] << "]|h|r";
2749 ss
<< " " << localeNames
[loc
];
2752 ss
<< GetMangosString(LANG_TALENT
);
2754 ss
<< GetMangosString(LANG_PASSIVE
);
2756 ss
<< GetMangosString(LANG_LEARN
);
2758 ss
<< GetMangosString(LANG_KNOWN
);
2760 ss
<< GetMangosString(LANG_ACTIVE
);
2762 SendSysMessage(ss
.str().c_str());
2768 if (counter
== 0) // if counter == 0 then we found nth
2769 SendSysMessage(LANG_COMMAND_NOSPELLFOUND
);
2773 bool ChatHandler::HandleLookupQuestCommand(const char* args
)
2778 // can be NULL at console call
2779 Player
* target
= getSelectedPlayer();
2781 std::string namepart
= args
;
2782 std::wstring wnamepart
;
2784 // converting string that we try to find to lower case
2785 if(!Utf8toWStr(namepart
,wnamepart
))
2788 wstrToLower(wnamepart
);
2790 uint32 counter
= 0 ;
2792 ObjectMgr::QuestMap
const& qTemplates
= objmgr
.GetQuestTemplates();
2793 for (ObjectMgr::QuestMap::const_iterator iter
= qTemplates
.begin(); iter
!= qTemplates
.end(); ++iter
)
2795 Quest
* qinfo
= iter
->second
;
2797 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2800 QuestLocale
const *il
= objmgr
.GetQuestLocale(qinfo
->GetQuestId());
2803 if (il
->Title
.size() > loc_idx
&& !il
->Title
[loc_idx
].empty())
2805 std::string title
= il
->Title
[loc_idx
];
2807 if (Utf8FitTo(title
, wnamepart
))
2809 char const* statusStr
= "";
2813 QuestStatus status
= target
->GetQuestStatus(qinfo
->GetQuestId());
2815 if(status
== QUEST_STATUS_COMPLETE
)
2817 if(target
->GetQuestRewardStatus(qinfo
->GetQuestId()))
2818 statusStr
= GetMangosString(LANG_COMMAND_QUEST_REWARDED
);
2820 statusStr
= GetMangosString(LANG_COMMAND_QUEST_COMPLETE
);
2822 else if(status
== QUEST_STATUS_INCOMPLETE
)
2823 statusStr
= GetMangosString(LANG_COMMAND_QUEST_ACTIVE
);
2827 PSendSysMessage(LANG_QUEST_LIST_CHAT
,qinfo
->GetQuestId(),qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2829 PSendSysMessage(LANG_QUEST_LIST_CONSOLE
,qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2837 std::string title
= qinfo
->GetTitle();
2841 if (Utf8FitTo(title
, wnamepart
))
2843 char const* statusStr
= "";
2847 QuestStatus status
= target
->GetQuestStatus(qinfo
->GetQuestId());
2849 if(status
== QUEST_STATUS_COMPLETE
)
2851 if(target
->GetQuestRewardStatus(qinfo
->GetQuestId()))
2852 statusStr
= GetMangosString(LANG_COMMAND_QUEST_REWARDED
);
2854 statusStr
= GetMangosString(LANG_COMMAND_QUEST_COMPLETE
);
2856 else if(status
== QUEST_STATUS_INCOMPLETE
)
2857 statusStr
= GetMangosString(LANG_COMMAND_QUEST_ACTIVE
);
2861 PSendSysMessage(LANG_QUEST_LIST_CHAT
,qinfo
->GetQuestId(),qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2863 PSendSysMessage(LANG_QUEST_LIST_CONSOLE
,qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2870 SendSysMessage(LANG_COMMAND_NOQUESTFOUND
);
2875 bool ChatHandler::HandleLookupCreatureCommand(const char* args
)
2880 std::string namepart
= args
;
2881 std::wstring wnamepart
;
2883 // converting string that we try to find to lower case
2884 if (!Utf8toWStr (namepart
,wnamepart
))
2887 wstrToLower (wnamepart
);
2891 for (uint32 id
= 0; id
< sCreatureStorage
.MaxEntry
; ++id
)
2893 CreatureInfo
const* cInfo
= sCreatureStorage
.LookupEntry
<CreatureInfo
> (id
);
2897 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2900 CreatureLocale
const *cl
= objmgr
.GetCreatureLocale (id
);
2903 if (cl
->Name
.size() > loc_idx
&& !cl
->Name
[loc_idx
].empty ())
2905 std::string name
= cl
->Name
[loc_idx
];
2907 if (Utf8FitTo (name
, wnamepart
))
2910 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str ());
2912 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE
, id
, name
.c_str ());
2920 std::string name
= cInfo
->Name
;
2924 if (Utf8FitTo(name
, wnamepart
))
2927 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str ());
2929 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE
, id
, name
.c_str ());
2935 SendSysMessage (LANG_COMMAND_NOCREATUREFOUND
);
2940 bool ChatHandler::HandleLookupObjectCommand(const char* args
)
2945 std::string namepart
= args
;
2946 std::wstring wnamepart
;
2948 // converting string that we try to find to lower case
2949 if(!Utf8toWStr(namepart
,wnamepart
))
2952 wstrToLower(wnamepart
);
2956 for (uint32 id
= 0; id
< sGOStorage
.MaxEntry
; id
++ )
2958 GameObjectInfo
const* gInfo
= sGOStorage
.LookupEntry
<GameObjectInfo
>(id
);
2962 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2965 GameObjectLocale
const *gl
= objmgr
.GetGameObjectLocale(id
);
2968 if (gl
->Name
.size() > loc_idx
&& !gl
->Name
[loc_idx
].empty())
2970 std::string name
= gl
->Name
[loc_idx
];
2972 if (Utf8FitTo(name
, wnamepart
))
2975 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT
, id
, id
, name
.c_str());
2977 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE
, id
, name
.c_str());
2985 std::string name
= gInfo
->name
;
2989 if(Utf8FitTo(name
, wnamepart
))
2992 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT
, id
, id
, name
.c_str());
2994 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE
, id
, name
.c_str());
3000 SendSysMessage(LANG_COMMAND_NOGAMEOBJECTFOUND
);
3005 /** \brief GM command level 3 - Create a guild.
3007 * This command allows a GM (level 3) to create a guild.
3009 * The "args" parameter contains the name of the guild leader
3010 * and then the name of the guild.
3013 bool ChatHandler::HandleGuildCreateCommand(const char* args
)
3019 char *lname
= strtok ((char*)args
, " ");
3020 char *gname
= strtok (NULL
, "");
3027 SendSysMessage (LANG_INSERT_GUILD_NAME
);
3028 SetSentErrorMessage (true);
3032 std::string guildname
= gname
;
3034 Player
* player
= ObjectAccessor::Instance ().FindPlayerByName (lname
);
3037 SendSysMessage (LANG_PLAYER_NOT_FOUND
);
3038 SetSentErrorMessage (true);
3042 if (player
->GetGuildId())
3044 SendSysMessage (LANG_PLAYER_IN_GUILD
);
3048 Guild
*guild
= new Guild
;
3049 if (!guild
->create (player
->GetGUID (),guildname
))
3052 SendSysMessage (LANG_GUILD_NOT_CREATED
);
3053 SetSentErrorMessage (true);
3057 objmgr
.AddGuild (guild
);
3061 bool ChatHandler::HandleGuildInviteCommand(const char *args
)
3066 char* par1
= strtok ((char*)args
, " ");
3067 char* par2
= strtok (NULL
, "");
3071 std::string glName
= par2
;
3072 Guild
* targetGuild
= objmgr
.GetGuildByName (glName
);
3076 std::string plName
= par1
;
3077 if (!normalizePlayerName (plName
))
3079 SendSysMessage (LANG_PLAYER_NOT_FOUND
);
3080 SetSentErrorMessage (true);
3085 if (Player
* targetPlayer
= ObjectAccessor::Instance ().FindPlayerByName (plName
.c_str ()))
3086 plGuid
= targetPlayer
->GetGUID ();
3088 plGuid
= objmgr
.GetPlayerGUIDByName (plName
.c_str ());
3093 // player's guild membership checked in AddMember before add
3094 if (!targetGuild
->AddMember (plGuid
,targetGuild
->GetLowestRank ()))
3100 bool ChatHandler::HandleGuildUninviteCommand(const char *args
)
3105 char* par1
= strtok ((char*)args
, " ");
3109 std::string plName
= par1
;
3110 if (!normalizePlayerName (plName
))
3112 SendSysMessage (LANG_PLAYER_NOT_FOUND
);
3113 SetSentErrorMessage (true);
3119 if (Player
* targetPlayer
= ObjectAccessor::Instance ().FindPlayerByName (plName
.c_str ()))
3121 plGuid
= targetPlayer
->GetGUID ();
3122 glId
= targetPlayer
->GetGuildId ();
3126 plGuid
= objmgr
.GetPlayerGUIDByName (plName
.c_str ());
3127 glId
= Player::GetGuildIdFromDB (plGuid
);
3130 if (!plGuid
|| !glId
)
3133 Guild
* targetGuild
= objmgr
.GetGuildById (glId
);
3137 targetGuild
->DelMember (plGuid
);
3142 bool ChatHandler::HandleGuildRankCommand(const char *args
)
3147 char* par1
= strtok ((char*)args
, " ");
3148 char* par2
= strtok (NULL
, " ");
3151 std::string plName
= par1
;
3152 if (!normalizePlayerName (plName
))
3154 SendSysMessage (LANG_PLAYER_NOT_FOUND
);
3155 SetSentErrorMessage (true);
3161 if (Player
* targetPlayer
= ObjectAccessor::Instance ().FindPlayerByName (plName
.c_str ()))
3163 plGuid
= targetPlayer
->GetGUID ();
3164 glId
= targetPlayer
->GetGuildId ();
3168 plGuid
= objmgr
.GetPlayerGUIDByName (plName
.c_str ());
3169 glId
= Player::GetGuildIdFromDB (plGuid
);
3172 if (!plGuid
|| !glId
)
3175 Guild
* targetGuild
= objmgr
.GetGuildById (glId
);
3179 uint32 newrank
= uint32 (atoi (par2
));
3180 if (newrank
> targetGuild
->GetLowestRank ())
3183 targetGuild
->ChangeRank (plGuid
,newrank
);
3188 bool ChatHandler::HandleGuildDeleteCommand(const char* args
)
3193 char* par1
= strtok ((char*)args
, " ");
3197 std::string gld
= par1
;
3199 Guild
* targetGuild
= objmgr
.GetGuildByName (gld
);
3203 targetGuild
->Disband ();
3208 bool ChatHandler::HandleGetDistanceCommand(const char* /*args*/)
3210 Unit
* pUnit
= getSelectedUnit();
3214 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3215 SetSentErrorMessage(true);
3219 PSendSysMessage(LANG_DISTANCE
, m_session
->GetPlayer()->GetDistance(pUnit
),m_session
->GetPlayer()->GetDistance2d(pUnit
));
3226 bool ChatHandler::HandleAddWeaponCommand(const char* /*args*/)
3231 uint64 guid = m_session->GetPlayer()->GetSelection();
3234 SendSysMessage(LANG_NO_SELECTION);
3238 Creature *pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
3242 SendSysMessage(LANG_SELECT_CREATURE);
3246 char* pSlotID = strtok((char*)args, " ");
3250 char* pItemID = strtok(NULL, " ");
3254 uint32 ItemID = atoi(pItemID);
3255 uint32 SlotID = atoi(pSlotID);
3257 ItemPrototype* tmpItem = objmgr.GetItemPrototype(ItemID);
3265 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID);
3269 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID);
3273 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID);
3277 PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST,SlotID);
3283 PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT,ItemID,tmpItem->Name1,SlotID);
3288 PSendSysMessage(LANG_ITEM_NOT_FOUND,ItemID);
3295 bool ChatHandler::HandleDieCommand(const char* /*args*/)
3297 Unit
* target
= getSelectedUnit();
3299 if(!target
|| !m_session
->GetPlayer()->GetSelection())
3301 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3302 SetSentErrorMessage(true);
3306 if( target
->isAlive() )
3308 m_session
->GetPlayer()->DealDamage(target
, target
->GetHealth(), NULL
, DIRECT_DAMAGE
, SPELL_SCHOOL_MASK_NORMAL
, NULL
, false);
3314 bool ChatHandler::HandleDamageCommand(const char * args
)
3319 Unit
* target
= getSelectedUnit();
3321 if(!target
|| !m_session
->GetPlayer()->GetSelection())
3323 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3324 SetSentErrorMessage(true);
3328 if( !target
->isAlive() )
3331 char* damageStr
= strtok((char*)args
, " ");
3335 int32 damage
= atoi((char*)damageStr
);
3339 char* schoolStr
= strtok((char*)NULL
, " ");
3341 // flat melee damage without resistence/etc reduction
3344 m_session
->GetPlayer()->DealDamage(target
, damage
, NULL
, DIRECT_DAMAGE
, SPELL_SCHOOL_MASK_NORMAL
, NULL
, false);
3345 m_session
->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2
, target
, 1, SPELL_SCHOOL_MASK_NORMAL
, damage
, 0, 0, VICTIMSTATE_NORMAL
, 0);
3349 uint32 school
= schoolStr
? atoi((char*)schoolStr
) : SPELL_SCHOOL_NORMAL
;
3350 if(school
>= MAX_SPELL_SCHOOL
)
3353 SpellSchoolMask schoolmask
= SpellSchoolMask(1 << school
);
3355 if ( schoolmask
& SPELL_SCHOOL_MASK_NORMAL
)
3356 damage
= m_session
->GetPlayer()->CalcArmorReducedDamage(target
, damage
);
3358 char* spellStr
= strtok((char*)NULL
, " ");
3360 // melee damage by specific school
3366 m_session
->GetPlayer()->CalcAbsorbResist(target
,schoolmask
, SPELL_DIRECT_DAMAGE
, damage
, &absorb
, &resist
);
3368 if (damage
<= absorb
+ resist
)
3371 damage
-= absorb
+ resist
;
3373 m_session
->GetPlayer()->DealDamage(target
, damage
, NULL
, DIRECT_DAMAGE
, schoolmask
, NULL
, false);
3374 m_session
->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2
, target
, 1, schoolmask
, damage
, absorb
, resist
, VICTIMSTATE_NORMAL
, 0);
3380 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3381 uint32 spellid
= extractSpellIdFromLink((char*)args
);
3382 if(!spellid
|| !sSpellStore
.LookupEntry(spellid
))
3385 m_session
->GetPlayer()->SpellNonMeleeDamageLog(target
, spellid
, damage
, false);
3389 bool ChatHandler::HandleModifyArenaCommand(const char * args
)
3394 Player
*target
= getSelectedPlayer();
3397 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3398 SetSentErrorMessage(true);
3402 int32 amount
= (uint32
)atoi(args
);
3404 target
->ModifyArenaPoints(amount
);
3406 PSendSysMessage(LANG_COMMAND_MODIFY_ARENA
, target
->GetName(), target
->GetArenaPoints());
3411 bool ChatHandler::HandleReviveCommand(const char* args
)
3413 Player
* SelectedPlayer
= NULL
;
3417 std::string name
= args
;
3418 if(!normalizePlayerName(name
))
3420 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3421 SetSentErrorMessage(true);
3425 SelectedPlayer
= objmgr
.GetPlayer(name
.c_str());
3428 SelectedPlayer
= getSelectedPlayer();
3432 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3433 SetSentErrorMessage(true);
3437 SelectedPlayer
->ResurrectPlayer(0.5f
);
3438 SelectedPlayer
->SpawnCorpseBones();
3439 SelectedPlayer
->SaveToDB();
3443 bool ChatHandler::HandleAuraCommand(const char* args
)
3445 char* px
= strtok((char*)args
, " ");
3449 Unit
*target
= getSelectedUnit();
3452 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3453 SetSentErrorMessage(true);
3457 uint32 spellID
= (uint32
)atoi(px
);
3458 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry( spellID
);
3461 for(uint32 i
= 0;i
<3;i
++)
3463 uint8 eff
= spellInfo
->Effect
[i
];
3464 if (eff
>=TOTAL_SPELL_EFFECTS
)
3466 if( IsAreaAuraEffect(eff
) ||
3467 eff
== SPELL_EFFECT_APPLY_AURA
||
3468 eff
== SPELL_EFFECT_PERSISTENT_AREA_AURA
)
3470 Aura
*Aur
= CreateAura(spellInfo
, i
, NULL
, target
);
3471 target
->AddAura(Aur
);
3479 bool ChatHandler::HandleUnAuraCommand(const char* args
)
3481 char* px
= strtok((char*)args
, " ");
3485 Unit
*target
= getSelectedUnit();
3488 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3489 SetSentErrorMessage(true);
3493 std::string argstr
= args
;
3494 if (argstr
== "all")
3496 target
->RemoveAllAuras();
3500 uint32 spellID
= (uint32
)atoi(px
);
3501 target
->RemoveAurasDueToSpell(spellID
);
3506 bool ChatHandler::HandleLinkGraveCommand(const char* args
)
3511 char* px
= strtok((char*)args
, " ");
3515 uint32 g_id
= (uint32
)atoi(px
);
3519 char* px2
= strtok(NULL
, " ");
3523 else if (strncmp(px2
,"horde",6)==0)
3525 else if (strncmp(px2
,"alliance",9)==0)
3530 WorldSafeLocsEntry
const* graveyard
= sWorldSafeLocsStore
.LookupEntry(g_id
);
3534 PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST
, g_id
);
3535 SetSentErrorMessage(true);
3539 Player
* player
= m_session
->GetPlayer();
3541 uint32 zoneId
= player
->GetZoneId();
3543 AreaTableEntry
const *areaEntry
= GetAreaEntryByAreaID(zoneId
);
3544 if(!areaEntry
|| areaEntry
->zone
!=0 )
3546 PSendSysMessage(LANG_COMMAND_GRAVEYARDWRONGZONE
, g_id
,zoneId
);
3547 SetSentErrorMessage(true);
3551 if(objmgr
.AddGraveYardLink(g_id
,player
->GetZoneId(),g_team
))
3552 PSendSysMessage(LANG_COMMAND_GRAVEYARDLINKED
, g_id
,zoneId
);
3554 PSendSysMessage(LANG_COMMAND_GRAVEYARDALRLINKED
, g_id
,zoneId
);
3559 bool ChatHandler::HandleNearGraveCommand(const char* args
)
3563 size_t argslen
= strlen(args
);
3567 else if (strncmp((char*)args
,"horde",argslen
)==0)
3569 else if (strncmp((char*)args
,"alliance",argslen
)==0)
3574 Player
* player
= m_session
->GetPlayer();
3576 WorldSafeLocsEntry
const* graveyard
= objmgr
.GetClosestGraveYard(
3577 player
->GetPositionX(), player
->GetPositionY(), player
->GetPositionZ(),player
->GetMapId(),g_team
);
3581 uint32 g_id
= graveyard
->ID
;
3583 GraveYardData
const* data
= objmgr
.FindGraveYardData(g_id
,player
->GetZoneId());
3586 PSendSysMessage(LANG_COMMAND_GRAVEYARDERROR
,g_id
);
3587 SetSentErrorMessage(true);
3591 g_team
= data
->team
;
3593 std::string team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_NOTEAM
);
3596 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ANY
);
3597 else if(g_team
== HORDE
)
3598 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE
);
3599 else if(g_team
== ALLIANCE
)
3600 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE
);
3602 PSendSysMessage(LANG_COMMAND_GRAVEYARDNEAREST
, g_id
,team_name
.c_str(),player
->GetZoneId());
3606 std::string team_name
;
3609 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ANY
);
3610 else if(g_team
== HORDE
)
3611 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE
);
3612 else if(g_team
== ALLIANCE
)
3613 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE
);
3615 if(g_team
== ~uint32(0))
3616 PSendSysMessage(LANG_COMMAND_ZONENOGRAVEYARDS
, player
->GetZoneId());
3618 PSendSysMessage(LANG_COMMAND_ZONENOGRAFACTION
, player
->GetZoneId(),team_name
.c_str());
3625 bool ChatHandler::HandleNpcPlayEmoteCommand(const char* args
)
3627 uint32 emote
= atoi((char*)args
);
3629 Creature
* target
= getSelectedCreature();
3632 SendSysMessage(LANG_SELECT_CREATURE
);
3633 SetSentErrorMessage(true);
3637 target
->SetUInt32Value(UNIT_NPC_EMOTESTATE
,emote
);
3642 bool ChatHandler::HandleNpcInfoCommand(const char* /*args*/)
3644 Creature
* target
= getSelectedCreature();
3648 SendSysMessage(LANG_SELECT_CREATURE
);
3649 SetSentErrorMessage(true);
3653 uint32 faction
= target
->getFaction();
3654 uint32 npcflags
= target
->GetUInt32Value(UNIT_NPC_FLAGS
);
3655 uint32 displayid
= target
->GetDisplayId();
3656 uint32 nativeid
= target
->GetNativeDisplayId();
3657 uint32 Entry
= target
->GetEntry();
3658 CreatureInfo
const* cInfo
= target
->GetCreatureInfo();
3660 int32 curRespawnDelay
= target
->GetRespawnTimeEx()-time(NULL
);
3661 if(curRespawnDelay
< 0)
3662 curRespawnDelay
= 0;
3663 std::string curRespawnDelayStr
= secsToTimeString(curRespawnDelay
,true);
3664 std::string defRespawnDelayStr
= secsToTimeString(target
->GetRespawnDelay(),true);
3666 PSendSysMessage(LANG_NPCINFO_CHAR
, target
->GetDBTableGUIDLow(), faction
, npcflags
, Entry
, displayid
, nativeid
);
3667 PSendSysMessage(LANG_NPCINFO_LEVEL
, target
->getLevel());
3668 PSendSysMessage(LANG_NPCINFO_HEALTH
,target
->GetCreateHealth(), target
->GetMaxHealth(), target
->GetHealth());
3669 PSendSysMessage(LANG_NPCINFO_FLAGS
, target
->GetUInt32Value(UNIT_FIELD_FLAGS
), target
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
), target
->getFaction());
3670 PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES
, defRespawnDelayStr
.c_str(),curRespawnDelayStr
.c_str());
3671 PSendSysMessage(LANG_NPCINFO_LOOT
, cInfo
->lootid
,cInfo
->pickpocketLootId
,cInfo
->SkinLootId
);
3672 PSendSysMessage(LANG_NPCINFO_DUNGEON_ID
, target
->GetInstanceId());
3673 PSendSysMessage(LANG_NPCINFO_POSITION
,float(target
->GetPositionX()), float(target
->GetPositionY()), float(target
->GetPositionZ()));
3675 if ((npcflags
& UNIT_NPC_FLAG_VENDOR
) )
3677 SendSysMessage(LANG_NPCINFO_VENDOR
);
3679 if ((npcflags
& UNIT_NPC_FLAG_TRAINER
) )
3681 SendSysMessage(LANG_NPCINFO_TRAINER
);
3687 bool ChatHandler::HandleExploreCheatCommand(const char* args
)
3692 int flag
= atoi((char*)args
);
3694 Player
*chr
= getSelectedPlayer();
3697 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3698 SetSentErrorMessage(true);
3704 PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL
, chr
->GetName());
3705 if (needReportToTarget(chr
))
3706 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_EXPLORE_SET_ALL
,GetName());
3710 PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING
, chr
->GetName());
3711 if (needReportToTarget(chr
))
3712 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_EXPLORE_SET_NOTHING
,GetName());
3715 for (uint8 i
=0; i
<128; i
++)
3719 m_session
->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1
+i
,0xFFFFFFFF);
3723 m_session
->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1
+i
,0);
3730 bool ChatHandler::HandleHoverCommand(const char* args
)
3732 char* px
= strtok((char*)args
, " ");
3739 m_session
->GetPlayer()->SetHover(flag
);
3742 SendSysMessage(LANG_HOVER_ENABLED
);
3744 SendSysMessage(LANG_HOVER_DISABLED
);
3749 bool ChatHandler::HandleLevelUpCommand(const char* args
)
3751 char* px
= strtok((char*)args
, " ");
3752 char* py
= strtok((char*)NULL
, " ");
3754 // command format parsing
3755 char* pname
= (char*)NULL
;
3758 if(px
&& py
) // .levelup name level
3760 addlevel
= atoi(py
);
3763 else if(px
&& !py
) // .levelup name OR .levelup level
3765 if(isalpha(px
[0])) // .levelup name
3767 else // .levelup level
3768 addlevel
= atoi(px
);
3770 // else .levelup - nothing do for preparing
3774 uint64 chr_guid
= 0;
3778 if(pname
) // player by name
3781 if(!normalizePlayerName(name
))
3783 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3784 SetSentErrorMessage(true);
3788 chr
= objmgr
.GetPlayer(name
.c_str());
3789 if(!chr
) // not in game
3791 chr_guid
= objmgr
.GetPlayerGUIDByName(name
);
3794 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3795 SetSentErrorMessage(true);
3800 else // player by selection
3802 chr
= getSelectedPlayer();
3806 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3807 SetSentErrorMessage(true);
3811 name
= chr
->GetName();
3814 assert(chr
|| chr_guid
);
3816 int32 oldlevel
= chr
? chr
->getLevel() : Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL
,chr_guid
);
3817 int32 newlevel
= oldlevel
+ addlevel
;
3820 if(newlevel
> STRONG_MAX_LEVEL
) // hardcoded maximum level
3821 newlevel
= STRONG_MAX_LEVEL
;
3825 chr
->GiveLevel(newlevel
);
3826 chr
->InitTalentForLevel();
3827 chr
->SetUInt32Value(PLAYER_XP
,0);
3829 if(oldlevel
== newlevel
)
3830 ChatHandler(chr
).SendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET
);
3832 if(oldlevel
< newlevel
)
3833 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_LEVEL_UP
,newlevel
-oldlevel
);
3835 if(oldlevel
> newlevel
)
3836 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_LEVEL_DOWN
,newlevel
-oldlevel
);
3840 // update level and XP at level, all other will be updated at loading
3842 Player::LoadValuesArrayFromDB(values
,chr_guid
);
3843 Player::SetUInt32ValueInArray(values
,UNIT_FIELD_LEVEL
,newlevel
);
3844 Player::SetUInt32ValueInArray(values
,PLAYER_XP
,0);
3845 Player::SaveValuesArrayInDB(values
,chr_guid
);
3848 if(m_session
->GetPlayer() != chr
) // including chr==NULL
3849 PSendSysMessage(LANG_YOU_CHANGE_LVL
,name
.c_str(),newlevel
);
3853 bool ChatHandler::HandleShowAreaCommand(const char* args
)
3858 Player
*chr
= getSelectedPlayer();
3861 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3862 SetSentErrorMessage(true);
3866 int area
= GetAreaFlagByAreaID(atoi((char*)args
));
3867 int offset
= area
/ 32;
3868 uint32 val
= (uint32
)(1 << (area
% 32));
3870 if(area
<0 || offset
>= 128)
3872 SendSysMessage(LANG_BAD_VALUE
);
3873 SetSentErrorMessage(true);
3877 uint32 currFields
= chr
->GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
3878 chr
->SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
| val
));
3880 SendSysMessage(LANG_EXPLORE_AREA
);
3884 bool ChatHandler::HandleHideAreaCommand(const char* args
)
3889 Player
*chr
= getSelectedPlayer();
3892 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3893 SetSentErrorMessage(true);
3897 int area
= GetAreaFlagByAreaID(atoi((char*)args
));
3898 int offset
= area
/ 32;
3899 uint32 val
= (uint32
)(1 << (area
% 32));
3901 if(area
<0 || offset
>= 128)
3903 SendSysMessage(LANG_BAD_VALUE
);
3904 SetSentErrorMessage(true);
3908 uint32 currFields
= chr
->GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
3909 chr
->SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
^ val
));
3911 SendSysMessage(LANG_UNEXPLORE_AREA
);
3915 bool ChatHandler::HandleUpdate(const char* args
)
3923 char* pUpdateIndex
= strtok((char*)args
, " ");
3925 Unit
* chr
= getSelectedUnit();
3928 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3929 SetSentErrorMessage(true);
3937 updateIndex
= atoi(pUpdateIndex
);
3939 if(chr
->GetTypeId() == TYPEID_PLAYER
)
3941 if (updateIndex
>=PLAYER_END
) return true;
3945 if (updateIndex
>=UNIT_END
) return true;
3948 char* pvalue
= strtok(NULL
, " ");
3951 value
=chr
->GetUInt32Value(updateIndex
);
3953 PSendSysMessage(LANG_UPDATE
, chr
->GetGUIDLow(),updateIndex
,value
);
3959 PSendSysMessage(LANG_UPDATE_CHANGE
, chr
->GetGUIDLow(),updateIndex
,value
);
3961 chr
->SetUInt32Value(updateIndex
,value
);
3966 bool ChatHandler::HandleBankCommand(const char* /*args*/)
3968 m_session
->SendShowBank( m_session
->GetPlayer()->GetGUID() );
3973 bool ChatHandler::HandleChangeWeather(const char* args
)
3979 if (!sWorld
.getConfig(CONFIG_WEATHER
))
3981 SendSysMessage(LANG_WEATHER_DISABLED
);
3982 SetSentErrorMessage(true);
3986 //*Change the weather of a cell
3987 char* px
= strtok((char*)args
, " ");
3988 char* py
= strtok(NULL
, " ");
3993 uint32 type
= (uint32
)atoi(px
); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
3994 float grade
= (float)atof(py
); //0 to 1, sending -1 is instand good weather
3996 Player
*player
= m_session
->GetPlayer();
3997 uint32 zoneid
= player
->GetZoneId();
3999 Weather
* wth
= sWorld
.FindWeather(zoneid
);
4002 wth
= sWorld
.AddWeather(zoneid
);
4005 SendSysMessage(LANG_NO_WEATHER
);
4006 SetSentErrorMessage(true);
4010 wth
->SetWeather(WeatherType(type
), grade
);
4015 bool ChatHandler::HandleSetValue(const char* args
)
4020 char* px
= strtok((char*)args
, " ");
4021 char* py
= strtok(NULL
, " ");
4022 char* pz
= strtok(NULL
, " ");
4027 Unit
* target
= getSelectedUnit();
4030 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4031 SetSentErrorMessage(true);
4035 uint64 guid
= target
->GetGUID();
4037 uint32 Opcode
= (uint32
)atoi(px
);
4038 if(Opcode
>= target
->GetValuesCount())
4040 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, GUID_LOPART(guid
), target
->GetValuesCount());
4045 bool isint32
= true;
4047 isint32
= (bool)atoi(pz
);
4050 iValue
= (uint32
)atoi(py
);
4051 sLog
.outDebug(GetMangosString(LANG_SET_UINT
), GUID_LOPART(guid
), Opcode
, iValue
);
4052 target
->SetUInt32Value( Opcode
, iValue
);
4053 PSendSysMessage(LANG_SET_UINT_FIELD
, GUID_LOPART(guid
), Opcode
,iValue
);
4057 fValue
= (float)atof(py
);
4058 sLog
.outDebug(GetMangosString(LANG_SET_FLOAT
), GUID_LOPART(guid
), Opcode
, fValue
);
4059 target
->SetFloatValue( Opcode
, fValue
);
4060 PSendSysMessage(LANG_SET_FLOAT_FIELD
, GUID_LOPART(guid
), Opcode
,fValue
);
4066 bool ChatHandler::HandleGetValue(const char* args
)
4071 char* px
= strtok((char*)args
, " ");
4072 char* pz
= strtok(NULL
, " ");
4077 Unit
* target
= getSelectedUnit();
4080 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4081 SetSentErrorMessage(true);
4085 uint64 guid
= target
->GetGUID();
4087 uint32 Opcode
= (uint32
)atoi(px
);
4088 if(Opcode
>= target
->GetValuesCount())
4090 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, GUID_LOPART(guid
), target
->GetValuesCount());
4095 bool isint32
= true;
4097 isint32
= (bool)atoi(pz
);
4101 iValue
= target
->GetUInt32Value( Opcode
);
4102 sLog
.outDebug(GetMangosString(LANG_GET_UINT
), GUID_LOPART(guid
), Opcode
, iValue
);
4103 PSendSysMessage(LANG_GET_UINT_FIELD
, GUID_LOPART(guid
), Opcode
, iValue
);
4107 fValue
= target
->GetFloatValue( Opcode
);
4108 sLog
.outDebug(GetMangosString(LANG_GET_FLOAT
), GUID_LOPART(guid
), Opcode
, fValue
);
4109 PSendSysMessage(LANG_GET_FLOAT_FIELD
, GUID_LOPART(guid
), Opcode
, fValue
);
4115 bool ChatHandler::HandleSet32Bit(const char* args
)
4120 char* px
= strtok((char*)args
, " ");
4121 char* py
= strtok(NULL
, " ");
4126 uint32 Opcode
= (uint32
)atoi(px
);
4127 uint32 Value
= (uint32
)atoi(py
);
4128 if (Value
> 32) //uint32 = 32 bits
4131 sLog
.outDebug(GetMangosString(LANG_SET_32BIT
), Opcode
, Value
);
4133 m_session
->GetPlayer( )->SetUInt32Value( Opcode
, 2^Value
);
4135 PSendSysMessage(LANG_SET_32BIT_FIELD
, Opcode
,1);
4139 bool ChatHandler::HandleMod32Value(const char* args
)
4144 char* px
= strtok((char*)args
, " ");
4145 char* py
= strtok(NULL
, " ");
4150 uint32 Opcode
= (uint32
)atoi(px
);
4151 int Value
= atoi(py
);
4153 if(Opcode
>= m_session
->GetPlayer()->GetValuesCount())
4155 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, m_session
->GetPlayer()->GetGUIDLow(), m_session
->GetPlayer( )->GetValuesCount());
4159 sLog
.outDebug(GetMangosString(LANG_CHANGE_32BIT
), Opcode
, Value
);
4161 int CurrentValue
= (int)m_session
->GetPlayer( )->GetUInt32Value( Opcode
);
4163 CurrentValue
+= Value
;
4164 m_session
->GetPlayer( )->SetUInt32Value( Opcode
, (uint32
)CurrentValue
);
4166 PSendSysMessage(LANG_CHANGE_32BIT_FIELD
, Opcode
,CurrentValue
);
4171 bool ChatHandler::HandleAddTeleCommand(const char * args
)
4176 Player
*player
=m_session
->GetPlayer();
4180 std::string name
= args
;
4182 if(objmgr
.GetGameTele(name
))
4184 SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST
);
4185 SetSentErrorMessage(true);
4190 tele
.position_x
= player
->GetPositionX();
4191 tele
.position_y
= player
->GetPositionY();
4192 tele
.position_z
= player
->GetPositionZ();
4193 tele
.orientation
= player
->GetOrientation();
4194 tele
.mapId
= player
->GetMapId();
4197 if(objmgr
.AddGameTele(tele
))
4199 SendSysMessage(LANG_COMMAND_TP_ADDED
);
4203 SendSysMessage(LANG_COMMAND_TP_ADDEDERR
);
4204 SetSentErrorMessage(true);
4211 bool ChatHandler::HandleDelTeleCommand(const char * args
)
4216 std::string name
= args
;
4218 if(!objmgr
.DeleteGameTele(name
))
4220 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
4221 SetSentErrorMessage(true);
4225 SendSysMessage(LANG_COMMAND_TP_DELETED
);
4229 bool ChatHandler::HandleListAurasCommand (const char * /*args*/)
4231 Unit
*unit
= getSelectedUnit();
4234 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4235 SetSentErrorMessage(true);
4239 char const* talentStr
= GetMangosString(LANG_TALENT
);
4240 char const* passiveStr
= GetMangosString(LANG_PASSIVE
);
4242 Unit::AuraMap
const& uAuras
= unit
->GetAuras();
4243 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS
, uAuras
.size());
4244 for (Unit::AuraMap::const_iterator itr
= uAuras
.begin(); itr
!= uAuras
.end(); ++itr
)
4246 bool talent
= GetTalentSpellCost(itr
->second
->GetId()) > 0;
4247 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL
, itr
->second
->GetId(), itr
->second
->GetEffIndex(),
4248 itr
->second
->GetModifier()->m_auraname
, itr
->second
->GetAuraDuration(), itr
->second
->GetAuraMaxDuration(),
4249 itr
->second
->GetSpellProto()->SpellName
[m_session
->GetSessionDbcLocale()],
4250 (itr
->second
->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4251 IS_PLAYER_GUID(itr
->second
->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr
->second
->GetCasterGUID()));
4253 for (int i
= 0; i
< TOTAL_AURAS
; i
++)
4255 Unit::AuraList
const& uAuraList
= unit
->GetAurasByType(AuraType(i
));
4256 if (uAuraList
.empty()) continue;
4257 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE
, uAuraList
.size(), i
);
4258 for (Unit::AuraList::const_iterator itr
= uAuraList
.begin(); itr
!= uAuraList
.end(); ++itr
)
4260 bool talent
= GetTalentSpellCost((*itr
)->GetId()) > 0;
4261 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE
, (*itr
)->GetId(), (*itr
)->GetEffIndex(),
4262 (*itr
)->GetSpellProto()->SpellName
[m_session
->GetSessionDbcLocale()],((*itr
)->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4263 IS_PLAYER_GUID((*itr
)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr
)->GetCasterGUID()));
4269 bool ChatHandler::HandleResetHonorCommand (const char * args
)
4271 char* pName
= strtok((char*)args
, "");
4272 Player
*player
= NULL
;
4275 std::string name
= pName
;
4276 if(!normalizePlayerName(name
))
4278 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4279 SetSentErrorMessage(true);
4283 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4284 player
= objmgr
.GetPlayer(guid
);
4287 player
= getSelectedPlayer();
4291 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4295 player
->SetUInt32Value(PLAYER_FIELD_KILLS
, 0);
4296 player
->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS
, 0);
4297 player
->SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY
, 0);
4298 player
->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION
, 0);
4299 player
->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION
, 0);
4304 static bool HandleResetStatsOrLevelHelper(Player
* player
)
4306 PlayerInfo
const *info
= objmgr
.GetPlayerInfo(player
->getRace(), player
->getClass());
4307 if(!info
) return false;
4309 ChrClassesEntry
const* cEntry
= sChrClassesStore
.LookupEntry(player
->getClass());
4312 sLog
.outError("Class %u not found in DBC (Wrong DBC files?)",player
->getClass());
4316 uint8 powertype
= cEntry
->powerType
;
4319 if(powertype
== POWER_RAGE
)
4320 unitfield
= 0x1100EE00;
4321 else if(powertype
== POWER_ENERGY
)
4322 unitfield
= 0x00000000;
4323 else if(powertype
== POWER_MANA
)
4324 unitfield
= 0x0000EE00;
4327 sLog
.outError("Invalid default powertype %u for player (class %u)",powertype
,player
->getClass());
4331 // reset m_form if no aura
4332 if(!player
->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT
))
4333 player
->m_form
= FORM_NONE
;
4335 player
->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS
, DEFAULT_WORLD_OBJECT_SIZE
);
4336 player
->SetFloatValue(UNIT_FIELD_COMBATREACH
, 1.5f
);
4338 player
->setFactionForRace(player
->getRace());
4340 player
->SetUInt32Value(UNIT_FIELD_BYTES_0
, ( ( player
->getRace() ) | ( player
->getClass() << 8 ) | ( player
->getGender() << 16 ) | ( powertype
<< 24 ) ) );
4342 // reset only if player not in some form;
4343 if(player
->m_form
==FORM_NONE
)
4345 switch(player
->getGender())
4348 player
->SetDisplayId(info
->displayId_f
);
4349 player
->SetNativeDisplayId(info
->displayId_f
);
4352 player
->SetDisplayId(info
->displayId_m
);
4353 player
->SetNativeDisplayId(info
->displayId_m
);
4360 // set UNIT_FIELD_BYTES_1 to init state but preserve m_form value
4361 player
->SetUInt32Value(UNIT_FIELD_BYTES_1
, unitfield
);
4362 player
->SetByteValue(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_PVP
);
4363 player
->SetByteValue(UNIT_FIELD_BYTES_2
, 3, player
->m_form
);
4365 player
->SetUInt32Value(UNIT_FIELD_FLAGS
, UNIT_FLAG_PVP_ATTACKABLE
);
4367 //-1 is default value
4368 player
->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX
, uint32(-1));
4370 //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000 );
4374 bool ChatHandler::HandleResetLevelCommand(const char * args
)
4376 char* pName
= strtok((char*)args
, "");
4377 Player
*player
= NULL
;
4380 std::string name
= pName
;
4381 if(!normalizePlayerName(name
))
4383 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4384 SetSentErrorMessage(true);
4388 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4389 player
= objmgr
.GetPlayer(guid
);
4392 player
= getSelectedPlayer();
4396 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4397 SetSentErrorMessage(true);
4401 if(!HandleResetStatsOrLevelHelper(player
))
4404 player
->SetLevel(1);
4405 player
->InitStatsForLevel(true);
4406 player
->InitTaxiNodesForLevel();
4407 player
->InitGlyphsForLevel();
4408 player
->InitTalentForLevel();
4409 player
->SetUInt32Value(PLAYER_XP
,0);
4411 // reset level to summoned pet
4412 Pet
* pet
= player
->GetPet();
4413 if(pet
&& pet
->getPetType()==SUMMON_PET
)
4415 pet
->InitStatsForLevel(1);
4416 pet
->InitTalentForLevel();
4421 bool ChatHandler::HandleResetStatsCommand(const char * args
)
4423 char* pName
= strtok((char*)args
, "");
4424 Player
*player
= NULL
;
4427 std::string name
= pName
;
4428 if(!normalizePlayerName(name
))
4430 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4431 SetSentErrorMessage(true);
4435 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4436 player
= objmgr
.GetPlayer(guid
);
4439 player
= getSelectedPlayer();
4443 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4444 SetSentErrorMessage(true);
4448 if(!HandleResetStatsOrLevelHelper(player
))
4451 player
->InitStatsForLevel(true);
4452 player
->InitTaxiNodesForLevel();
4453 player
->InitGlyphsForLevel();
4454 player
->InitTalentForLevel();
4459 bool ChatHandler::HandleResetSpellsCommand(const char * args
)
4461 char* pName
= strtok((char*)args
, "");
4462 Player
*player
= NULL
;
4463 uint64 playerGUID
= 0;
4466 std::string name
= pName
;
4468 if(!normalizePlayerName(name
))
4470 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4471 SetSentErrorMessage(true);
4475 player
= objmgr
.GetPlayer(name
.c_str());
4477 playerGUID
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4480 player
= getSelectedPlayer();
4482 if(!player
&& !playerGUID
)
4484 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4485 SetSentErrorMessage(true);
4491 player
->resetSpells();
4493 ChatHandler(player
).SendSysMessage(LANG_RESET_SPELLS
);
4495 if(m_session
->GetPlayer()!=player
)
4496 PSendSysMessage(LANG_RESET_SPELLS_ONLINE
,player
->GetName());
4500 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS
), GUID_LOPART(playerGUID
));
4501 PSendSysMessage(LANG_RESET_SPELLS_OFFLINE
,pName
);
4507 bool ChatHandler::HandleResetTalentsCommand(const char * args
)
4509 char* pName
= strtok((char*)args
, "");
4510 Player
*player
= NULL
;
4511 uint64 playerGUID
= 0;
4514 std::string name
= pName
;
4515 if(!normalizePlayerName(name
))
4517 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4518 SetSentErrorMessage(true);
4522 player
= objmgr
.GetPlayer(name
.c_str());
4524 playerGUID
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4527 player
= getSelectedPlayer();
4531 player
->resetTalents(true);
4533 ChatHandler(player
).SendSysMessage(LANG_RESET_TALENTS
);
4535 if(m_session
->GetPlayer()!=player
)
4536 PSendSysMessage(LANG_RESET_TALENTS_ONLINE
,player
->GetName());
4539 else if (playerGUID
)
4541 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_TALENTS
), GUID_LOPART(playerGUID
) );
4542 PSendSysMessage(LANG_RESET_TALENTS_OFFLINE
,pName
);
4545 // Try reset talenents as Hunter Pet
4546 Creature
* creature
= getSelectedCreature();
4547 if (creature
&& creature
->isPet() && ((Pet
*)creature
)->getPetType() == HUNTER_PET
)
4549 ((Pet
*)creature
)->resetTalents(true);
4550 Unit
*owner
= creature
->GetOwner();
4551 if (owner
&& owner
->GetTypeId() == TYPEID_PLAYER
)
4553 player
= (Player
*)owner
;
4554 ChatHandler(player
).SendSysMessage(LANG_RESET_TALENTS
);
4555 if(m_session
->GetPlayer()!=player
)
4556 PSendSysMessage(LANG_RESET_TALENTS_ONLINE
,player
->GetName());
4561 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4562 SetSentErrorMessage(true);
4566 bool ChatHandler::HandleResetAllCommand(const char * args
)
4571 std::string casename
= args
;
4573 AtLoginFlags atLogin
;
4575 // Command specially created as single command to prevent using short case names
4576 if(casename
=="spells")
4578 atLogin
= AT_LOGIN_RESET_SPELLS
;
4579 sWorld
.SendWorldText(LANG_RESETALL_SPELLS
);
4581 else if(casename
=="talents")
4583 atLogin
= AT_LOGIN_RESET_TALENTS
;
4584 sWorld
.SendWorldText(LANG_RESETALL_TALENTS
);
4588 PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE
,args
);
4589 SetSentErrorMessage(true);
4593 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE (at_login & '%u') = '0'",atLogin
,atLogin
);
4594 HashMapHolder
<Player
>::MapType
const& plist
= ObjectAccessor::Instance().GetPlayers();
4595 for(HashMapHolder
<Player
>::MapType::const_iterator itr
= plist
.begin(); itr
!= plist
.end(); ++itr
)
4596 itr
->second
->SetAtLoginFlag(atLogin
);
4601 bool ChatHandler::HandleServerShutDownCancelCommand(const char* args
)
4603 sWorld
.ShutdownCancel();
4607 bool ChatHandler::HandleServerShutDownCommand(const char* args
)
4612 char* time_str
= strtok ((char*) args
, " ");
4613 char* exitcode_str
= strtok (NULL
, "");
4615 int32 time
= atoi (time_str
);
4617 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4618 if(time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0') || time
< 0)
4623 int32 exitcode
= atoi (exitcode_str
);
4625 // Handle atoi() errors
4626 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4629 // Exit code should be in range of 0-125, 126-255 is used
4630 // in many shells for their own return codes and code > 255
4631 // is not supported in many others
4632 if (exitcode
< 0 || exitcode
> 125)
4635 sWorld
.ShutdownServ (time
, 0, exitcode
);
4638 sWorld
.ShutdownServ(time
,0,SHUTDOWN_EXIT_CODE
);
4642 bool ChatHandler::HandleServerRestartCommand(const char* args
)
4647 char* time_str
= strtok ((char*) args
, " ");
4648 char* exitcode_str
= strtok (NULL
, "");
4650 int32 time
= atoi (time_str
);
4652 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4653 if(time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0') || time
< 0)
4658 int32 exitcode
= atoi (exitcode_str
);
4660 // Handle atoi() errors
4661 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4664 // Exit code should be in range of 0-125, 126-255 is used
4665 // in many shells for their own return codes and code > 255
4666 // is not supported in many others
4667 if (exitcode
< 0 || exitcode
> 125)
4670 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_RESTART
, exitcode
);
4673 sWorld
.ShutdownServ(time
, SHUTDOWN_MASK_RESTART
, RESTART_EXIT_CODE
);
4677 bool ChatHandler::HandleServerIdleRestartCommand(const char* args
)
4682 char* time_str
= strtok ((char*) args
, " ");
4683 char* exitcode_str
= strtok (NULL
, "");
4685 int32 time
= atoi (time_str
);
4687 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4688 if(time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0') || time
< 0)
4693 int32 exitcode
= atoi (exitcode_str
);
4695 // Handle atoi() errors
4696 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4699 // Exit code should be in range of 0-125, 126-255 is used
4700 // in many shells for their own return codes and code > 255
4701 // is not supported in many others
4702 if (exitcode
< 0 || exitcode
> 125)
4705 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_RESTART
|SHUTDOWN_MASK_IDLE
, exitcode
);
4708 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_RESTART
|SHUTDOWN_MASK_IDLE
,RESTART_EXIT_CODE
);
4712 bool ChatHandler::HandleServerIdleShutDownCommand(const char* args
)
4717 char* time_str
= strtok ((char*) args
, " ");
4718 char* exitcode_str
= strtok (NULL
, "");
4720 int32 time
= atoi (time_str
);
4722 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4723 if(time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0') || time
< 0)
4728 int32 exitcode
= atoi (exitcode_str
);
4730 // Handle atoi() errors
4731 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4734 // Exit code should be in range of 0-125, 126-255 is used
4735 // in many shells for their own return codes and code > 255
4736 // is not supported in many others
4737 if (exitcode
< 0 || exitcode
> 125)
4740 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_IDLE
, exitcode
);
4743 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_IDLE
,SHUTDOWN_EXIT_CODE
);
4747 bool ChatHandler::HandleAddQuest(const char* args
)
4749 Player
* player
= getSelectedPlayer();
4752 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4753 SetSentErrorMessage(true);
4757 // .addquest #entry'
4758 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4759 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4763 uint32 entry
= atol(cId
);
4765 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
4769 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
,entry
);
4770 SetSentErrorMessage(true);
4774 // check item starting quest (it can work incorrectly if added without item in inventory)
4775 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
4777 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
4781 if (pProto
->StartQuest
== entry
)
4783 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM
, entry
, pProto
->ItemId
);
4784 SetSentErrorMessage(true);
4789 // ok, normal (creature/GO starting) quest
4790 if( player
->CanAddQuest( pQuest
, true ) )
4792 player
->AddQuest( pQuest
, NULL
);
4794 if ( player
->CanCompleteQuest( entry
) )
4795 player
->CompleteQuest( entry
);
4801 bool ChatHandler::HandleRemoveQuest(const char* args
)
4803 Player
* player
= getSelectedPlayer();
4806 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4807 SetSentErrorMessage(true);
4811 // .removequest #entry'
4812 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4813 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4817 uint32 entry
= atol(cId
);
4819 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
4823 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
4824 SetSentErrorMessage(true);
4828 // remove all quest entries for 'entry' from quest log
4829 for(uint8 slot
= 0; slot
< MAX_QUEST_LOG_SIZE
; ++slot
)
4831 uint32 quest
= player
->GetQuestSlotQuestId(slot
);
4834 player
->SetQuestSlot(slot
,0);
4836 // we ignore unequippable quest items in this case, its' still be equipped
4837 player
->TakeQuestSourceItem( quest
, false );
4841 // set quest status to not started (will updated in DB at next save)
4842 player
->SetQuestStatus( entry
, QUEST_STATUS_NONE
);
4844 // reset rewarded for restart repeatable quest
4845 player
->getQuestStatusMap()[entry
].m_rewarded
= false;
4847 SendSysMessage(LANG_COMMAND_QUEST_REMOVED
);
4851 bool ChatHandler::HandleCompleteQuest(const char* args
)
4853 Player
* player
= getSelectedPlayer();
4856 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4857 SetSentErrorMessage(true);
4861 // .quest complete #entry
4862 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4863 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4867 uint32 entry
= atol(cId
);
4869 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
4871 // If player doesn't have the quest
4872 if(!pQuest
|| player
->GetQuestStatus(entry
) == QUEST_STATUS_NONE
)
4874 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
4875 SetSentErrorMessage(true);
4879 // Add quest items for quests that require items
4880 for(uint8 x
= 0; x
< QUEST_OBJECTIVES_COUNT
; ++x
)
4882 uint32 id
= pQuest
->ReqItemId
[x
];
4883 uint32 count
= pQuest
->ReqItemCount
[x
];
4887 uint32 curItemCount
= player
->GetItemCount(id
,true);
4889 ItemPosCountVec dest
;
4890 uint8 msg
= player
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, id
, count
-curItemCount
);
4891 if( msg
== EQUIP_ERR_OK
)
4893 Item
* item
= player
->StoreNewItem( dest
, id
, true);
4894 player
->SendNewItem(item
,count
-curItemCount
,true,false);
4898 // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
4899 for(uint8 i
= 0; i
< QUEST_OBJECTIVES_COUNT
; i
++)
4901 uint32 creature
= pQuest
->ReqCreatureOrGOId
[i
];
4902 uint32 creaturecount
= pQuest
->ReqCreatureOrGOCount
[i
];
4904 if(uint32 spell_id
= pQuest
->ReqSpell
[i
])
4906 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4907 player
->CastedCreatureOrGO(creature
,0,spell_id
);
4909 else if(creature
> 0)
4911 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4912 player
->KilledMonster(creature
,0);
4914 else if(creature
< 0)
4916 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4917 player
->CastedCreatureOrGO(creature
,0,0);
4921 // If the quest requires reputation to complete
4922 if(uint32 repFaction
= pQuest
->GetRepObjectiveFaction())
4924 uint32 repValue
= pQuest
->GetRepObjectiveValue();
4925 uint32 curRep
= player
->GetReputation(repFaction
);
4926 if(curRep
< repValue
)
4928 FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry(repFaction
);
4929 player
->SetFactionReputation(factionEntry
,repValue
);
4933 // If the quest requires money
4934 int32 ReqOrRewMoney
= pQuest
->GetRewOrReqMoney();
4935 if(ReqOrRewMoney
< 0)
4936 player
->ModifyMoney(-ReqOrRewMoney
);
4938 player
->CompleteQuest(entry
);
4942 bool ChatHandler::HandleBanAccountCommand(const char* args
)
4944 return HandleBanHelper(BAN_ACCOUNT
,args
);
4947 bool ChatHandler::HandleBanCharacterCommand(const char* args
)
4949 return HandleBanHelper(BAN_CHARACTER
,args
);
4952 bool ChatHandler::HandleBanIPCommand(const char* args
)
4954 return HandleBanHelper(BAN_IP
,args
);
4957 bool ChatHandler::HandleBanHelper(BanMode mode
, const char* args
)
4962 char* cnameOrIP
= strtok ((char*)args
, " ");
4966 std::string nameOrIP
= cnameOrIP
;
4968 char* duration
= strtok (NULL
," ");
4969 if(!duration
|| !atoi(duration
))
4972 char* reason
= strtok (NULL
,"");
4979 if(!AccountMgr::normilizeString(nameOrIP
))
4981 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
4982 SetSentErrorMessage(true);
4987 if(!normalizePlayerName(nameOrIP
))
4989 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4990 SetSentErrorMessage(true);
4995 if(!IsIPAddress(nameOrIP
.c_str()))
5000 switch(sWorld
.BanAccount(mode
, nameOrIP
, duration
, reason
,m_session
? m_session
->GetPlayerName() : ""))
5003 if(atoi(duration
)>0)
5004 PSendSysMessage(LANG_BAN_YOUBANNED
,nameOrIP
.c_str(),secsToTimeString(TimeStringToSecs(duration
),true).c_str(),reason
);
5006 PSendSysMessage(LANG_BAN_YOUPERMBANNED
,nameOrIP
.c_str(),reason
);
5008 case BAN_SYNTAX_ERROR
:
5014 PSendSysMessage(LANG_BAN_NOTFOUND
,"account",nameOrIP
.c_str());
5017 PSendSysMessage(LANG_BAN_NOTFOUND
,"character",nameOrIP
.c_str());
5020 PSendSysMessage(LANG_BAN_NOTFOUND
,"ip",nameOrIP
.c_str());
5023 SetSentErrorMessage(true);
5030 bool ChatHandler::HandleUnBanAccountCommand(const char* args
)
5032 return HandleUnBanHelper(BAN_ACCOUNT
,args
);
5035 bool ChatHandler::HandleUnBanCharacterCommand(const char* args
)
5037 return HandleUnBanHelper(BAN_CHARACTER
,args
);
5040 bool ChatHandler::HandleUnBanIPCommand(const char* args
)
5042 return HandleUnBanHelper(BAN_IP
,args
);
5045 bool ChatHandler::HandleUnBanHelper(BanMode mode
, const char* args
)
5050 char* cnameOrIP
= strtok ((char*)args
, " ");
5054 std::string nameOrIP
= cnameOrIP
;
5059 if(!AccountMgr::normilizeString(nameOrIP
))
5061 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
5062 SetSentErrorMessage(true);
5067 if(!normalizePlayerName(nameOrIP
))
5069 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5070 SetSentErrorMessage(true);
5075 if(!IsIPAddress(nameOrIP
.c_str()))
5080 if(sWorld
.RemoveBanAccount(mode
,nameOrIP
))
5081 PSendSysMessage(LANG_UNBAN_UNBANNED
,nameOrIP
.c_str());
5083 PSendSysMessage(LANG_UNBAN_ERROR
,nameOrIP
.c_str());
5088 bool ChatHandler::HandleBanInfoAccountCommand(const char* args
)
5093 char* cname
= strtok((char*)args
, "");
5097 std::string account_name
= cname
;
5098 if(!AccountMgr::normilizeString(account_name
))
5100 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5101 SetSentErrorMessage(true);
5105 uint32 accountid
= accmgr
.GetId(account_name
);
5108 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5112 return HandleBanInfoHelper(accountid
,account_name
.c_str());
5115 bool ChatHandler::HandleBanInfoCharacterCommand(const char* args
)
5120 char* cname
= strtok ((char*)args
, "");
5124 std::string name
= cname
;
5125 if(!normalizePlayerName(name
))
5127 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5128 SetSentErrorMessage(true);
5132 uint32 accountid
= objmgr
.GetPlayerAccountIdByPlayerName(name
);
5135 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5136 SetSentErrorMessage(true);
5140 std::string accountname
;
5141 if(!accmgr
.GetName(accountid
,accountname
))
5143 PSendSysMessage(LANG_BANINFO_NOCHARACTER
);
5147 return HandleBanInfoHelper(accountid
,accountname
.c_str());
5150 bool ChatHandler::HandleBanInfoHelper(uint32 accountid
, char const* accountname
)
5152 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
);
5155 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN
, accountname
);
5159 PSendSysMessage(LANG_BANINFO_BANHISTORY
,accountname
);
5162 Field
* fields
= result
->Fetch();
5164 time_t unbandate
= time_t(fields
[3].GetUInt64());
5165 bool active
= false;
5166 if(fields
[2].GetBool() && (fields
[1].GetUInt64() == (uint64
)0 ||unbandate
>= time(NULL
)) )
5168 bool permanent
= (fields
[1].GetUInt64() == (uint64
)0);
5169 std::string bantime
= permanent
?GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[1].GetUInt64(), true);
5170 PSendSysMessage(LANG_BANINFO_HISTORYENTRY
,
5171 fields
[0].GetString(), bantime
.c_str(), active
? GetMangosString(LANG_BANINFO_YES
):GetMangosString(LANG_BANINFO_NO
), fields
[4].GetString(), fields
[5].GetString());
5172 }while (result
->NextRow());
5178 bool ChatHandler::HandleBanInfoIPCommand(const char* args
)
5183 char* cIP
= strtok ((char*)args
, "");
5187 if (!IsIPAddress(cIP
))
5190 std::string IP
= cIP
;
5192 loginDatabase
.escape_string(IP
);
5193 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());
5196 PSendSysMessage(LANG_BANINFO_NOIP
);
5200 Field
*fields
= result
->Fetch();
5201 bool permanent
= !fields
[6].GetUInt64();
5202 PSendSysMessage(LANG_BANINFO_IPENTRY
,
5203 fields
[0].GetString(), fields
[1].GetString(), permanent
? GetMangosString(LANG_BANINFO_NEVER
):fields
[2].GetString(),
5204 permanent
? GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[3].GetUInt64(), true).c_str(), fields
[4].GetString(), fields
[5].GetString());
5209 bool ChatHandler::HandleBanListCharacterCommand(const char* args
)
5211 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5213 char* cFilter
= strtok ((char*)args
, " ");
5217 std::string filter
= cFilter
;
5218 loginDatabase
.escape_string(filter
);
5219 QueryResult
* result
= CharacterDatabase
.PQuery("SELECT account FROM characters WHERE name "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'"),filter
.c_str());
5222 PSendSysMessage(LANG_BANLIST_NOCHARACTER
);
5226 return HandleBanListHelper(result
);
5229 bool ChatHandler::HandleBanListAccountCommand(const char* args
)
5231 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5233 char* cFilter
= strtok((char*)args
, " ");
5234 std::string filter
= cFilter
? cFilter
: "";
5235 loginDatabase
.escape_string(filter
);
5237 QueryResult
* result
;
5241 result
= loginDatabase
.Query("SELECT account.id, username FROM account, account_banned"
5242 " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
5246 result
= loginDatabase
.PQuery("SELECT account.id, username FROM account, account_banned"
5247 " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
5253 PSendSysMessage(LANG_BANLIST_NOACCOUNT
);
5257 return HandleBanListHelper(result
);
5260 bool ChatHandler::HandleBanListHelper(QueryResult
* result
)
5262 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT
);
5264 // Chat short output
5269 Field
* fields
= result
->Fetch();
5270 uint32 accountid
= fields
[0].GetUInt32();
5272 QueryResult
* banresult
= loginDatabase
.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid
);
5275 Field
* fields2
= banresult
->Fetch();
5276 PSendSysMessage("%s",fields2
[0].GetString());
5279 } while (result
->NextRow());
5281 // Console wide output
5284 SendSysMessage(LANG_BANLIST_ACCOUNTS
);
5285 SendSysMessage("===============================================================================");
5286 SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER
);
5289 SendSysMessage("-------------------------------------------------------------------------------");
5290 Field
*fields
= result
->Fetch();
5291 uint32 account_id
= fields
[0].GetUInt32 ();
5293 std::string account_name
;
5295 // "account" case, name can be get in same query
5296 if(result
->GetFieldCount() > 1)
5297 account_name
= fields
[1].GetCppString();
5298 // "character" case, name need extract from another DB
5300 accmgr
.GetName (account_id
,account_name
);
5302 // No SQL injection. id is uint32.
5303 QueryResult
*banInfo
= loginDatabase
.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id
);
5306 Field
*fields2
= banInfo
->Fetch();
5309 time_t t_ban
= fields2
[0].GetUInt64();
5310 tm
* aTm_ban
= localtime(&t_ban
);
5312 if (fields2
[0].GetUInt64() == fields2
[1].GetUInt64())
5314 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5315 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
,
5316 fields2
[2].GetString(),fields2
[3].GetString());
5320 time_t t_unban
= fields2
[1].GetUInt64();
5321 tm
* aTm_unban
= localtime(&t_unban
);
5322 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5323 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
,
5324 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5325 fields2
[2].GetString(),fields2
[3].GetString());
5327 }while ( banInfo
->NextRow() );
5330 }while( result
->NextRow() );
5331 SendSysMessage("===============================================================================");
5338 bool ChatHandler::HandleBanListIPCommand(const char* args
)
5340 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5342 char* cFilter
= strtok((char*)args
, " ");
5343 std::string filter
= cFilter
? cFilter
: "";
5344 loginDatabase
.escape_string(filter
);
5346 QueryResult
* result
;
5350 result
= loginDatabase
.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5351 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
5352 " ORDER BY unbandate" );
5356 result
= loginDatabase
.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5357 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")
5358 " ORDER BY unbandate",filter
.c_str() );
5363 PSendSysMessage(LANG_BANLIST_NOIP
);
5367 PSendSysMessage(LANG_BANLIST_MATCHINGIP
);
5368 // Chat short output
5373 Field
* fields
= result
->Fetch();
5374 PSendSysMessage("%s",fields
[0].GetString());
5375 } while (result
->NextRow());
5377 // Console wide output
5380 SendSysMessage(LANG_BANLIST_IPS
);
5381 SendSysMessage("===============================================================================");
5382 SendSysMessage(LANG_BANLIST_IPS_HEADER
);
5385 SendSysMessage("-------------------------------------------------------------------------------");
5386 Field
*fields
= result
->Fetch();
5387 time_t t_ban
= fields
[1].GetUInt64();
5388 tm
* aTm_ban
= localtime(&t_ban
);
5389 if ( fields
[1].GetUInt64() == fields
[2].GetUInt64() )
5391 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5392 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
,
5393 fields
[3].GetString(), fields
[4].GetString());
5397 time_t t_unban
= fields
[2].GetUInt64();
5398 tm
* aTm_unban
= localtime(&t_unban
);
5399 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5400 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
,
5401 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5402 fields
[3].GetString(), fields
[4].GetString());
5404 }while( result
->NextRow() );
5405 SendSysMessage("===============================================================================");
5412 bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
5414 Player
* pl
= m_session
->GetPlayer();
5416 // accept only explicitly selected target (not implicitly self targeting case)
5417 Unit
* target
= getSelectedUnit();
5418 if(pl
->GetSelection() && target
)
5420 if(target
->GetTypeId()!=TYPEID_UNIT
)
5422 SendSysMessage(LANG_SELECT_CREATURE
);
5423 SetSentErrorMessage(true);
5427 if(target
->isDead())
5428 ((Creature
*)target
)->Respawn();
5432 CellPair
p(MaNGOS::ComputeCellPair(pl
->GetPositionX(), pl
->GetPositionY()));
5434 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
5437 MaNGOS::RespawnDo u_do
;
5438 MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
> worker(u_do
);
5440 TypeContainerVisitor
<MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
>, GridTypeMapContainer
> obj_worker(worker
);
5441 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
5442 cell_lock
->Visit(cell_lock
, obj_worker
, *pl
->GetMap());
5447 bool ChatHandler::HandleFlyModeCommand(const char* args
)
5452 Unit
*unit
= getSelectedUnit();
5453 if (!unit
|| (unit
->GetTypeId() != TYPEID_PLAYER
))
5454 unit
= m_session
->GetPlayer();
5456 WorldPacket
data(12);
5457 if (strncmp(args
, "on", 3) == 0)
5458 data
.SetOpcode(SMSG_MOVE_SET_CAN_FLY
);
5459 else if (strncmp(args
, "off", 4) == 0)
5460 data
.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY
);
5463 SendSysMessage(LANG_USE_BOL
);
5466 data
.append(unit
->GetPackGUID());
5467 data
<< uint32(0); // unknown
5468 unit
->SendMessageToSet(&data
, true);
5469 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS
, unit
->GetName(), args
);
5473 bool ChatHandler::HandleLoadPDumpCommand(const char *args
)
5478 char * file
= strtok((char*)args
, " ");
5482 char * account
= strtok(NULL
, " ");
5486 std::string account_name
= account
;
5487 if(!AccountMgr::normilizeString(account_name
))
5489 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5490 SetSentErrorMessage(true);
5494 uint32 account_id
= accmgr
.GetId(account_name
);
5497 account_id
= atoi(account
); // use original string
5500 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5501 SetSentErrorMessage(true);
5506 if(!accmgr
.GetName(account_id
,account_name
))
5508 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5509 SetSentErrorMessage(true);
5513 char* guid_str
= NULL
;
5514 char* name_str
= strtok(NULL
, " ");
5520 // normalize the name if specified and check if it exists
5521 if(!normalizePlayerName(name
))
5523 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5524 SetSentErrorMessage(true);
5528 if(!ObjectMgr::IsValidName(name
,true))
5530 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5531 SetSentErrorMessage(true);
5535 guid_str
= strtok(NULL
, " ");
5542 guid
= atoi(guid_str
);
5545 PSendSysMessage(LANG_INVALID_CHARACTER_GUID
);
5546 SetSentErrorMessage(true);
5550 if(objmgr
.GetPlayerAccountIdByGUID(guid
))
5552 PSendSysMessage(LANG_CHARACTER_GUID_IN_USE
,guid
);
5553 SetSentErrorMessage(true);
5558 switch(PlayerDumpReader().LoadDump(file
, account_id
, name
, guid
))
5561 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS
);
5563 case DUMP_FILE_OPEN_ERROR
:
5564 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
5565 SetSentErrorMessage(true);
5567 case DUMP_FILE_BROKEN
:
5568 PSendSysMessage(LANG_DUMP_BROKEN
,file
);
5569 SetSentErrorMessage(true);
5571 case DUMP_TOO_MANY_CHARS
:
5572 PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL
,account_name
.c_str(),account_id
);
5573 SetSentErrorMessage(true);
5576 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED
);
5577 SetSentErrorMessage(true);
5584 bool ChatHandler::HandleNpcChangeEntryCommand(const char *args
)
5589 uint32 newEntryNum
= atoi(args
);
5593 Unit
* unit
= getSelectedUnit();
5594 if(!unit
|| unit
->GetTypeId() != TYPEID_UNIT
)
5596 SendSysMessage(LANG_SELECT_CREATURE
);
5597 SetSentErrorMessage(true);
5600 Creature
* creature
= (Creature
*)unit
;
5601 if(creature
->UpdateEntry(newEntryNum
))
5602 SendSysMessage(LANG_DONE
);
5604 SendSysMessage(LANG_ERROR
);
5608 bool ChatHandler::HandleWritePDumpCommand(const char *args
)
5613 char* file
= strtok((char*)args
, " ");
5614 char* p2
= strtok(NULL
, " ");
5620 // character name can't start from number
5621 if (isNumeric(p2
[0]))
5625 std::string name
= p2
;
5627 if (!normalizePlayerName (name
))
5629 SendSysMessage (LANG_PLAYER_NOT_FOUND
);
5630 SetSentErrorMessage (true);
5634 guid
= objmgr
.GetPlayerGUIDByName(name
);
5637 if(!objmgr
.GetPlayerAccountIdByGUID(guid
))
5639 PSendSysMessage(LANG_PLAYER_NOT_FOUND
);
5640 SetSentErrorMessage(true);
5644 switch(PlayerDumpWriter().WriteDump(file
, guid
))
5647 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS
);
5649 case DUMP_FILE_OPEN_ERROR
:
5650 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
5651 SetSentErrorMessage(true);
5654 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED
);
5655 SetSentErrorMessage(true);
5662 bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
5664 Unit
* unit
= getSelectedUnit();
5667 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5668 SetSentErrorMessage(true);
5672 PSendSysMessage(LANG_MOVEGENS_LIST
,(unit
->GetTypeId()==TYPEID_PLAYER
? "Player" : "Creature" ),unit
->GetGUIDLow());
5674 MotionMaster
* mm
= unit
->GetMotionMaster();
5675 for(MotionMaster::const_iterator itr
= mm
->begin(); itr
!= mm
->end(); ++itr
)
5677 switch((*itr
)->GetMovementGeneratorType())
5679 case IDLE_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_IDLE
); break;
5680 case RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_RANDOM
); break;
5681 case WAYPOINT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_WAYPOINT
); break;
5682 case ANIMAL_RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_ANIMAL_RANDOM
); break;
5683 case CONFUSED_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_CONFUSED
); break;
5684 case TARGETED_MOTION_TYPE
:
5686 if(unit
->GetTypeId()==TYPEID_PLAYER
)
5688 TargetedMovementGenerator
<Player
> const* mgen
= static_cast<TargetedMovementGenerator
<Player
> const*>(*itr
);
5689 Unit
* target
= mgen
->GetTarget();
5691 PSendSysMessage(LANG_MOVEGENS_TARGETED_PLAYER
,target
->GetName(),target
->GetGUIDLow());
5693 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL
);
5697 TargetedMovementGenerator
<Creature
> const* mgen
= static_cast<TargetedMovementGenerator
<Creature
> const*>(*itr
);
5698 Unit
* target
= mgen
->GetTarget();
5700 PSendSysMessage(LANG_MOVEGENS_TARGETED_CREATURE
,target
->GetName(),target
->GetGUIDLow());
5702 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL
);
5706 case HOME_MOTION_TYPE
:
5707 if(unit
->GetTypeId()==TYPEID_UNIT
)
5710 (*itr
)->GetDestination(x
,y
,z
);
5711 PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE
,x
,y
,z
);
5714 SendSysMessage(LANG_MOVEGENS_HOME_PLAYER
);
5716 case FLIGHT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FLIGHT
); break;
5717 case POINT_MOTION_TYPE
:
5720 (*itr
)->GetDestination(x
,y
,z
);
5721 PSendSysMessage(LANG_MOVEGENS_POINT
,x
,y
,z
);
5724 case FLEEING_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FEAR
); break;
5725 case DISTRACT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_DISTRACT
); break;
5727 PSendSysMessage(LANG_MOVEGENS_UNKNOWN
,(*itr
)->GetMovementGeneratorType());
5734 bool ChatHandler::HandlePLimitCommand(const char *args
)
5738 char* param
= strtok((char*)args
, " ");
5742 int l
= strlen(param
);
5744 if( strncmp(param
,"player",l
) == 0 )
5745 sWorld
.SetPlayerLimit(-SEC_PLAYER
);
5746 else if(strncmp(param
,"moderator",l
) == 0 )
5747 sWorld
.SetPlayerLimit(-SEC_MODERATOR
);
5748 else if(strncmp(param
,"gamemaster",l
) == 0 )
5749 sWorld
.SetPlayerLimit(-SEC_GAMEMASTER
);
5750 else if(strncmp(param
,"administrator",l
) == 0 )
5751 sWorld
.SetPlayerLimit(-SEC_ADMINISTRATOR
);
5752 else if(strncmp(param
,"reset",l
) == 0 )
5753 sWorld
.SetPlayerLimit( sConfig
.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT
) );
5756 int val
= atoi(param
);
5757 if(val
< -SEC_ADMINISTRATOR
) val
= -SEC_ADMINISTRATOR
;
5759 sWorld
.SetPlayerLimit(val
);
5762 // kick all low security level players
5763 if(sWorld
.GetPlayerAmountLimit() > SEC_PLAYER
)
5764 sWorld
.KickAllLess(sWorld
.GetPlayerSecurityLimit());
5767 uint32 pLimit
= sWorld
.GetPlayerAmountLimit();
5768 AccountTypes allowedAccountType
= sWorld
.GetPlayerSecurityLimit();
5769 char const* secName
= "";
5770 switch(allowedAccountType
)
5772 case SEC_PLAYER
: secName
= "Player"; break;
5773 case SEC_MODERATOR
: secName
= "Moderator"; break;
5774 case SEC_GAMEMASTER
: secName
= "Gamemaster"; break;
5775 case SEC_ADMINISTRATOR
: secName
= "Administrator"; break;
5776 default: secName
= "<unknown>"; break;
5779 PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit
,secName
);
5784 bool ChatHandler::HandleCastCommand(const char* args
)
5789 Unit
* target
= getSelectedUnit();
5793 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5794 SetSentErrorMessage(true);
5798 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5799 uint32 spell
= extractSpellIdFromLink((char*)args
);
5803 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5807 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5809 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5810 SetSentErrorMessage(true);
5814 char* trig_str
= strtok(NULL
, " ");
5817 int l
= strlen(trig_str
);
5818 if(strncmp(trig_str
,"triggered",l
) != 0 )
5822 bool triggered
= (trig_str
!= NULL
);
5824 m_session
->GetPlayer()->CastSpell(target
,spell
,triggered
);
5829 bool ChatHandler::HandleCastBackCommand(const char* args
)
5831 Creature
* caster
= getSelectedCreature();
5835 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5836 SetSentErrorMessage(true);
5840 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
5841 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5842 uint32 spell
= extractSpellIdFromLink((char*)args
);
5843 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
5846 char* trig_str
= strtok(NULL
, " ");
5849 int l
= strlen(trig_str
);
5850 if(strncmp(trig_str
,"triggered",l
) != 0 )
5854 bool triggered
= (trig_str
!= NULL
);
5856 // update orientation at server
5857 caster
->SetOrientation(caster
->GetAngle(m_session
->GetPlayer()));
5861 caster
->BuildHeartBeatMsg(&data
);
5862 caster
->SendMessageToSet(&data
,true);
5864 caster
->CastSpell(m_session
->GetPlayer(),spell
,triggered
);
5869 bool ChatHandler::HandleCastDistCommand(const char* args
)
5874 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5875 uint32 spell
= extractSpellIdFromLink((char*)args
);
5879 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5883 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5885 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5886 SetSentErrorMessage(true);
5890 char *distStr
= strtok(NULL
, " ");
5895 sscanf(distStr
, "%f", &dist
);
5897 char* trig_str
= strtok(NULL
, " ");
5900 int l
= strlen(trig_str
);
5901 if(strncmp(trig_str
,"triggered",l
) != 0 )
5905 bool triggered
= (trig_str
!= NULL
);
5908 m_session
->GetPlayer()->GetClosePoint(x
,y
,z
,dist
);
5910 m_session
->GetPlayer()->CastSpell(x
,y
,z
,spell
,triggered
);
5914 bool ChatHandler::HandleCastTargetCommand(const char* args
)
5916 Creature
* caster
= getSelectedCreature();
5920 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5921 SetSentErrorMessage(true);
5925 if(!caster
->getVictim())
5927 SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM
);
5928 SetSentErrorMessage(true);
5932 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5933 uint32 spell
= extractSpellIdFromLink((char*)args
);
5934 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
5937 char* trig_str
= strtok(NULL
, " ");
5940 int l
= strlen(trig_str
);
5941 if(strncmp(trig_str
,"triggered",l
) != 0 )
5945 bool triggered
= (trig_str
!= NULL
);
5947 // update orientation at server
5948 caster
->SetOrientation(caster
->GetAngle(m_session
->GetPlayer()));
5952 caster
->BuildHeartBeatMsg(&data
);
5953 caster
->SendMessageToSet(&data
,true);
5955 caster
->CastSpell(caster
->getVictim(),spell
,triggered
);
5961 ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
5962 Without this function 3rd party scripting library will get linking errors (unresolved external)
5963 when attempting to use the PointMovementGenerator
5965 bool ChatHandler::HandleComeToMeCommand(const char *args
)
5967 Creature
* caster
= getSelectedCreature();
5971 SendSysMessage(LANG_SELECT_CREATURE
);
5972 SetSentErrorMessage(true);
5976 char* newFlagStr
= strtok((char*)args
, " ");
5981 uint32 newFlags
= atoi(newFlagStr
);
5983 caster
->SetUnitMovementFlags(newFlags
);
5985 Player
* pl
= m_session
->GetPlayer();
5987 caster
->GetMotionMaster()->MovePoint(0, pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ());
5991 bool ChatHandler::HandleCastSelfCommand(const char* args
)
5996 Unit
* target
= getSelectedUnit();
6000 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
6001 SetSentErrorMessage(true);
6005 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6006 uint32 spell
= extractSpellIdFromLink((char*)args
);
6010 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
6014 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
6016 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
6017 SetSentErrorMessage(true);
6021 target
->CastSpell(target
,spell
,false);
6026 std::string
GetTimeString(uint32 time
)
6028 uint16 days
= time
/ DAY
, hours
= (time
% DAY
) / HOUR
, minute
= (time
% HOUR
) / MINUTE
;
6029 std::ostringstream ss
;
6030 if(days
) ss
<< days
<< "d ";
6031 if(hours
) ss
<< hours
<< "h ";
6032 ss
<< minute
<< "m";
6036 bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
6038 Player
* player
= getSelectedPlayer();
6039 if (!player
) player
= m_session
->GetPlayer();
6041 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
6043 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(i
);
6044 for(Player::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
6046 InstanceSave
*save
= itr
->second
.save
;
6047 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
6048 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());
6052 PSendSysMessage("player binds: %d", counter
);
6054 Group
*group
= player
->GetGroup();
6057 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
6059 Group::BoundInstancesMap
&binds
= group
->GetBoundInstances(i
);
6060 for(Group::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
6062 InstanceSave
*save
= itr
->second
.save
;
6063 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
6064 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());
6069 PSendSysMessage("group binds: %d", counter
);
6074 bool ChatHandler::HandleInstanceUnbindCommand(const char* args
)
6079 std::string cmd
= args
;
6082 Player
* player
= getSelectedPlayer();
6083 if (!player
) player
= m_session
->GetPlayer();
6085 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
6087 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(i
);
6088 for(Player::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end();)
6090 if(itr
->first
!= player
->GetMapId())
6092 InstanceSave
*save
= itr
->second
.save
;
6093 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
6094 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());
6095 player
->UnbindInstance(itr
, i
);
6102 PSendSysMessage("instances unbound: %d", counter
);
6107 bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
6109 PSendSysMessage("instances loaded: %d", MapManager::Instance().GetNumInstances());
6110 PSendSysMessage("players in instances: %d", MapManager::Instance().GetNumPlayersInInstances());
6111 PSendSysMessage("instance saves: %d", sInstanceSaveManager
.GetNumInstanceSaves());
6112 PSendSysMessage("players bound: %d", sInstanceSaveManager
.GetNumBoundPlayersTotal());
6113 PSendSysMessage("groups bound: %d", sInstanceSaveManager
.GetNumBoundGroupsTotal());
6117 bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
6119 Player
* pl
= m_session
->GetPlayer();
6121 Map
* map
= pl
->GetMap();
6122 if (!map
->IsDungeon())
6124 PSendSysMessage("Map is not a dungeon.");
6125 SetSentErrorMessage(true);
6129 if (!((InstanceMap
*)map
)->GetInstanceData())
6131 PSendSysMessage("Map has no instance data.");
6132 SetSentErrorMessage(true);
6136 ((InstanceMap
*)map
)->GetInstanceData()->SaveToDB();
6140 /// Display the list of GMs
6141 bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
6143 ///- Get the accounts with GM Level >0
6144 QueryResult
*result
= loginDatabase
.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
6147 SendSysMessage(LANG_GMLIST
);
6148 SendSysMessage("========================");
6149 SendSysMessage(LANG_GMLIST_HEADER
);
6150 SendSysMessage("========================");
6152 ///- Circle through them. Display username and GM level
6155 Field
*fields
= result
->Fetch();
6156 PSendSysMessage("|%15s|%6s|", fields
[0].GetString(),fields
[1].GetString());
6157 }while( result
->NextRow() );
6159 PSendSysMessage("========================");
6163 PSendSysMessage(LANG_GMLIST_EMPTY
);
6167 /// Define the 'Message of the day' for the realm
6168 bool ChatHandler::HandleServerSetMotdCommand(const char* args
)
6170 sWorld
.SetMotd(args
);
6171 PSendSysMessage(LANG_MOTD_NEW
, args
);
6175 /// Set/Unset the expansion level for an account
6176 bool ChatHandler::HandleAccountSetAddonCommand(const char* args
)
6178 ///- Get the command line arguments
6179 char *szAcc
= strtok((char*)args
," ");
6180 char *szExp
= strtok(NULL
," ");
6185 std::string account_name
;
6190 Player
* player
= getSelectedPlayer();
6194 account_id
= player
->GetSession()->GetAccountId();
6195 accmgr
.GetName(account_id
,account_name
);
6200 ///- Convert Account name to Upper Format
6201 account_name
= szAcc
;
6202 if(!AccountMgr::normilizeString(account_name
))
6204 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
6205 SetSentErrorMessage(true);
6209 account_id
= accmgr
.GetId(account_name
);
6212 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
6213 SetSentErrorMessage(true);
6219 // Let set addon state only for lesser (strong) security level
6220 // or to self account
6221 if (m_session
&& m_session
->GetAccountId () != account_id
&&
6222 HasLowerSecurityAccount (NULL
,account_id
,true))
6225 int lev
=atoi(szExp
); //get int anyway (0 if error)
6230 loginDatabase
.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev
,account_id
);
6231 PSendSysMessage(LANG_ACCOUNT_SETADDON
,account_name
.c_str(),account_id
,lev
);
6235 //Send items by mail
6236 bool ChatHandler::HandleSendItemsCommand(const char* args
)
6241 // format: name "subject text" "mail text" item1[:count1] item2[:count2] ... item12[:count12]
6243 char* pName
= strtok((char*)args
, " ");
6247 char* tail1
= strtok(NULL
, "");
6253 msgSubject
= strtok(tail1
+1, "\"");
6256 char* space
= strtok(tail1
, "\"");
6259 msgSubject
= strtok(NULL
, "\"");
6265 char* tail2
= strtok(NULL
, "");
6271 msgText
= strtok(tail2
+1, "\"");
6274 char* space
= strtok(tail2
, "\"");
6277 msgText
= strtok(NULL
, "\"");
6283 // pName, msgSubject, msgText isn't NUL after prev. check
6284 std::string name
= pName
;
6285 std::string subject
= msgSubject
;
6286 std::string text
= msgText
;
6289 typedef std::pair
<uint32
,uint32
> ItemPair
;
6290 typedef std::list
< ItemPair
> ItemPairs
;
6293 // get all tail string
6294 char* tail
= strtok(NULL
, "");
6296 // get from tail next item str
6297 while(char* itemStr
= strtok(tail
, " "))
6300 tail
= strtok(NULL
, "");
6303 char* itemIdStr
= strtok(itemStr
, ":");
6304 char* itemCountStr
= strtok(NULL
, " ");
6306 uint32 item_id
= atoi(itemIdStr
);
6310 ItemPrototype
const* item_proto
= objmgr
.GetItemPrototype(item_id
);
6313 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
6314 SetSentErrorMessage(true);
6318 uint32 item_count
= itemCountStr
? atoi(itemCountStr
) : 1;
6319 if(item_count
< 1 || item_proto
->MaxCount
> 0 && item_count
> uint32(item_proto
->MaxCount
))
6321 PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT
, item_count
,item_id
);
6322 SetSentErrorMessage(true);
6326 while(item_count
> item_proto
->GetMaxStackSize())
6328 items
.push_back(ItemPair(item_id
,item_proto
->GetMaxStackSize()));
6329 item_count
-= item_proto
->GetMaxStackSize();
6332 items
.push_back(ItemPair(item_id
,item_count
));
6334 if(items
.size() > MAX_MAIL_ITEMS
)
6336 PSendSysMessage(LANG_COMMAND_MAIL_ITEMS_LIMIT
, MAX_MAIL_ITEMS
);
6337 SetSentErrorMessage(true);
6342 if(!normalizePlayerName(name
))
6344 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6345 SetSentErrorMessage(true);
6349 uint64 receiver_guid
= objmgr
.GetPlayerGUIDByName(name
);
6352 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6353 SetSentErrorMessage(true);
6357 // from console show not existed sender
6358 uint32 sender_guidlo
= m_session
? m_session
->GetPlayer()->GetGUIDLow() : 0;
6360 uint32 messagetype
= MAIL_NORMAL
;
6361 uint32 stationery
= MAIL_STATIONERY_GM
;
6362 uint32 itemTextId
= !text
.empty() ? objmgr
.CreateItemText( text
) : 0;
6364 Player
*receiver
= objmgr
.GetPlayer(receiver_guid
);
6367 MailItemsInfo mi
; // item list preparing
6369 for(ItemPairs::const_iterator itr
= items
.begin(); itr
!= items
.end(); ++itr
)
6371 if(Item
* item
= Item::CreateItem(itr
->first
,itr
->second
,m_session
? m_session
->GetPlayer() : 0))
6373 item
->SaveToDB(); // save for prevent lost at next mail load, if send fail then item will deleted
6374 mi
.AddItem(item
->GetGUIDLow(), item
->GetEntry(), item
);
6378 WorldSession::SendMailTo(receiver
,messagetype
, stationery
, sender_guidlo
, GUID_LOPART(receiver_guid
), subject
, itemTextId
, &mi
, 0, 0, MAIL_CHECK_MASK_NONE
);
6380 PSendSysMessage(LANG_MAIL_SENT
, name
.c_str());
6384 ///Send money by mail
6385 bool ChatHandler::HandleSendMoneyCommand(const char* args
)
6390 /// format: name "subject text" "mail text" money
6392 char* pName
= strtok((char*)args
, " ");
6396 char* tail1
= strtok(NULL
, "");
6402 msgSubject
= strtok(tail1
+1, "\"");
6405 char* space
= strtok(tail1
, "\"");
6408 msgSubject
= strtok(NULL
, "\"");
6414 char* tail2
= strtok(NULL
, "");
6420 msgText
= strtok(tail2
+1, "\"");
6423 char* space
= strtok(tail2
, "\"");
6426 msgText
= strtok(NULL
, "\"");
6432 char* money_str
= strtok(NULL
, "");
6433 int32 money
= money_str
? atoi(money_str
) : 0;
6437 // pName, msgSubject, msgText isn't NUL after prev. check
6438 std::string name
= pName
;
6439 std::string subject
= msgSubject
;
6440 std::string text
= msgText
;
6442 if (!normalizePlayerName(name
))
6444 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6445 SetSentErrorMessage(true);
6449 uint64 receiver_guid
= objmgr
.GetPlayerGUIDByName(name
);
6452 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6453 SetSentErrorMessage(true);
6457 uint32 mailId
= objmgr
.GenerateMailID();
6459 // from console show not existed sender
6460 uint32 sender_guidlo
= m_session
? m_session
->GetPlayer()->GetGUIDLow() : 0;
6462 uint32 messagetype
= MAIL_NORMAL
;
6463 uint32 stationery
= MAIL_STATIONERY_GM
;
6464 uint32 itemTextId
= !text
.empty() ? objmgr
.CreateItemText( text
) : 0;
6466 Player
*receiver
= objmgr
.GetPlayer(receiver_guid
);
6468 WorldSession::SendMailTo(receiver
,messagetype
, stationery
, sender_guidlo
, GUID_LOPART(receiver_guid
), subject
, itemTextId
, NULL
, money
, 0, MAIL_CHECK_MASK_NONE
);
6470 PSendSysMessage(LANG_MAIL_SENT
, name
.c_str());
6474 /// Send a message to a player in game
6475 bool ChatHandler::HandleSendMessageCommand(const char* args
)
6477 ///- Get the command line arguments
6478 char* name_str
= strtok((char*)args
, " ");
6479 char* msg_str
= strtok(NULL
, "");
6481 if(!name_str
|| !msg_str
)
6484 std::string name
= name_str
;
6486 if(!normalizePlayerName(name
))
6489 ///- Find the player and check that he is not logging out.
6490 Player
*rPlayer
= objmgr
.GetPlayer(name
.c_str());
6493 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6494 SetSentErrorMessage(true);
6498 if(rPlayer
->GetSession()->isLogingOut())
6500 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6501 SetSentErrorMessage(true);
6505 ///- Send the message
6506 //Use SendAreaTriggerMessage for fastest delivery.
6507 rPlayer
->GetSession()->SendAreaTriggerMessage("%s", msg_str
);
6508 rPlayer
->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
6510 //Confirmation message
6511 PSendSysMessage(LANG_SENDMESSAGE
,name
.c_str(),msg_str
);
6515 bool ChatHandler::HandleFlushArenaPointsCommand(const char * /*args*/)
6517 sBattleGroundMgr
.DistributeArenaPoints();
6521 bool ChatHandler::HandleModifyGenderCommand(const char *args
)
6526 Player
*player
= getSelectedPlayer();
6530 PSendSysMessage(LANG_NO_PLAYER
);
6531 SetSentErrorMessage(true);
6535 PlayerInfo
const* info
= objmgr
.GetPlayerInfo(player
->getRace(), player
->getClass());
6539 char const* gender_str
= (char*)args
;
6540 int gender_len
= strlen(gender_str
);
6544 if(!strncmp(gender_str
, "male", gender_len
)) // MALE
6546 if(player
->getGender() == GENDER_MALE
)
6549 gender
= GENDER_MALE
;
6551 else if (!strncmp(gender_str
, "female", gender_len
)) // FEMALE
6553 if(player
->getGender() == GENDER_FEMALE
)
6556 gender
= GENDER_FEMALE
;
6560 SendSysMessage(LANG_MUST_MALE_OR_FEMALE
);
6561 SetSentErrorMessage(true);
6566 player
->SetByteValue(UNIT_FIELD_BYTES_0
, 2, gender
);
6567 player
->SetByteValue(PLAYER_BYTES_3
, 0, gender
);
6569 // Change display ID
6570 player
->SetDisplayId(gender
? info
->displayId_f
: info
->displayId_m
);
6571 player
->SetNativeDisplayId(gender
? info
->displayId_f
: info
->displayId_m
);
6573 char const* gender_full
= gender
? "female" : "male";
6575 PSendSysMessage(LANG_YOU_CHANGE_GENDER
, player
->GetName(), gender_full
);
6577 if (needReportToTarget(player
))
6578 ChatHandler(player
).PSendSysMessage(LANG_YOUR_GENDER_CHANGED
, gender_full
, GetName());