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::HandleReloadMangosStringCommand(const char*)
344 sLog
.outString( "Re-Loading mangos_string Table!" );
345 objmgr
.LoadMangosStrings();
346 SendGlobalSysMessage("DB table `mangos_string` reloaded.");
350 bool ChatHandler::HandleReloadNpcOptionCommand(const char*)
352 sLog
.outString( "Re-Loading `npc_option` Table!" );
353 objmgr
.LoadNpcOptions();
354 SendGlobalSysMessage("DB table `npc_option` reloaded.");
358 bool ChatHandler::HandleReloadNpcGossipCommand(const char*)
360 sLog
.outString( "Re-Loading `npc_gossip` Table!" );
361 objmgr
.LoadNpcTextId();
362 SendGlobalSysMessage("DB table `npc_gossip` reloaded.");
366 bool ChatHandler::HandleReloadNpcTrainerCommand(const char*)
368 sLog
.outString( "Re-Loading `npc_trainer` Table!" );
369 objmgr
.LoadTrainerSpell();
370 SendGlobalSysMessage("DB table `npc_trainer` reloaded.");
374 bool ChatHandler::HandleReloadNpcVendorCommand(const char*)
376 sLog
.outString( "Re-Loading `npc_vendor` Table!" );
377 objmgr
.LoadVendors();
378 SendGlobalSysMessage("DB table `npc_vendor` reloaded.");
382 bool ChatHandler::HandleReloadReservedNameCommand(const char*)
384 sLog
.outString( "Loading ReservedNames... (`reserved_name`)" );
385 objmgr
.LoadReservedPlayersNames();
386 SendGlobalSysMessage("DB table `reserved_name` (player reserved names) reloaded.");
390 bool ChatHandler::HandleReloadSkillDiscoveryTemplateCommand(const char* /*args*/)
392 sLog
.outString( "Re-Loading Skill Discovery Table..." );
393 LoadSkillDiscoveryTable();
394 SendGlobalSysMessage("DB table `skill_discovery_template` (recipes discovered at crafting) reloaded.");
398 bool ChatHandler::HandleReloadSkillExtraItemTemplateCommand(const char* /*args*/)
400 sLog
.outString( "Re-Loading Skill Extra Item Table..." );
401 LoadSkillExtraItemTable();
402 SendGlobalSysMessage("DB table `skill_extra_item_template` (extra item creation when crafting) reloaded.");
406 bool ChatHandler::HandleReloadSkillFishingBaseLevelCommand(const char* /*args*/)
408 sLog
.outString( "Re-Loading Skill Fishing base level requirements..." );
409 objmgr
.LoadFishingBaseSkillLevel();
410 SendGlobalSysMessage("DB table `skill_fishing_base_level` (fishing base level for zone/subzone) reloaded.");
414 bool ChatHandler::HandleReloadSpellAffectCommand(const char*)
416 sLog
.outString( "Re-Loading SpellAffect definitions..." );
417 spellmgr
.LoadSpellAffects();
418 SendGlobalSysMessage("DB table `spell_affect` (spell mods apply requirements) reloaded.");
422 bool ChatHandler::HandleReloadSpellChainCommand(const char*)
424 sLog
.outString( "Re-Loading Spell Chain Data... " );
425 spellmgr
.LoadSpellChains();
426 SendGlobalSysMessage("DB table `spell_chain` (spell ranks) reloaded.");
430 bool ChatHandler::HandleReloadSpellElixirCommand(const char*)
432 sLog
.outString( "Re-Loading Spell Elixir types..." );
433 spellmgr
.LoadSpellElixirs();
434 SendGlobalSysMessage("DB table `spell_elixir` (spell elixir types) reloaded.");
438 bool ChatHandler::HandleReloadSpellLearnSpellCommand(const char*)
440 sLog
.outString( "Re-Loading Spell Learn Spells..." );
441 spellmgr
.LoadSpellLearnSpells();
442 SendGlobalSysMessage("DB table `spell_learn_spell` reloaded.");
446 bool ChatHandler::HandleReloadSpellProcEventCommand(const char*)
448 sLog
.outString( "Re-Loading Spell Proc Event conditions..." );
449 spellmgr
.LoadSpellProcEvents();
450 SendGlobalSysMessage("DB table `spell_proc_event` (spell proc trigger requirements) reloaded.");
454 bool ChatHandler::HandleReloadSpellScriptTargetCommand(const char*)
456 sLog
.outString( "Re-Loading SpellsScriptTarget..." );
457 spellmgr
.LoadSpellScriptTarget();
458 SendGlobalSysMessage("DB table `spell_script_target` (spell targets selection in case specific creature/GO requirements) reloaded.");
462 bool ChatHandler::HandleReloadSpellTargetPositionCommand(const char*)
464 sLog
.outString( "Re-Loading Spell target coordinates..." );
465 spellmgr
.LoadSpellTargetPositions();
466 SendGlobalSysMessage("DB table `spell_target_position` (destination coordinates for spell targets) reloaded.");
470 bool ChatHandler::HandleReloadSpellThreatsCommand(const char*)
472 sLog
.outString( "Re-Loading Aggro Spells Definitions...");
473 spellmgr
.LoadSpellThreats();
474 SendGlobalSysMessage("DB table `spell_threat` (spell aggro definitions) reloaded.");
478 bool ChatHandler::HandleReloadSpellPetAurasCommand(const char*)
480 sLog
.outString( "Re-Loading Spell pet auras...");
481 spellmgr
.LoadSpellPetAuras();
482 SendGlobalSysMessage("DB table `spell_pet_auras` reloaded.");
486 bool ChatHandler::HandleReloadPageTextsCommand(const char*)
488 sLog
.outString( "Re-Loading Page Texts..." );
489 objmgr
.LoadPageTexts();
490 SendGlobalSysMessage("DB table `page_texts` reloaded.");
494 bool ChatHandler::HandleReloadItemEnchantementsCommand(const char*)
496 sLog
.outString( "Re-Loading Item Random Enchantments Table..." );
497 LoadRandomEnchantmentsTable();
498 SendGlobalSysMessage("DB table `item_enchantment_template` reloaded.");
502 bool ChatHandler::HandleReloadGameObjectScriptsCommand(const char* arg
)
504 if(sWorld
.IsScriptScheduled())
506 SendSysMessage("DB scripts used currently, please attempt reload later.");
507 SetSentErrorMessage(true);
512 sLog
.outString( "Re-Loading Scripts from `gameobject_scripts`...");
514 objmgr
.LoadGameObjectScripts();
517 SendGlobalSysMessage("DB table `gameobject_scripts` reloaded.");
522 bool ChatHandler::HandleReloadEventScriptsCommand(const char* arg
)
524 if(sWorld
.IsScriptScheduled())
526 SendSysMessage("DB scripts used currently, please attempt reload later.");
527 SetSentErrorMessage(true);
532 sLog
.outString( "Re-Loading Scripts from `event_scripts`...");
534 objmgr
.LoadEventScripts();
537 SendGlobalSysMessage("DB table `event_scripts` reloaded.");
542 bool ChatHandler::HandleReloadQuestEndScriptsCommand(const char* arg
)
544 if(sWorld
.IsScriptScheduled())
546 SendSysMessage("DB scripts used currently, please attempt reload later.");
547 SetSentErrorMessage(true);
552 sLog
.outString( "Re-Loading Scripts from `quest_end_scripts`...");
554 objmgr
.LoadQuestEndScripts();
557 SendGlobalSysMessage("DB table `quest_end_scripts` reloaded.");
562 bool ChatHandler::HandleReloadQuestStartScriptsCommand(const char* arg
)
564 if(sWorld
.IsScriptScheduled())
566 SendSysMessage("DB scripts used currently, please attempt reload later.");
567 SetSentErrorMessage(true);
572 sLog
.outString( "Re-Loading Scripts from `quest_start_scripts`...");
574 objmgr
.LoadQuestStartScripts();
577 SendGlobalSysMessage("DB table `quest_start_scripts` reloaded.");
582 bool ChatHandler::HandleReloadSpellScriptsCommand(const char* arg
)
584 if(sWorld
.IsScriptScheduled())
586 SendSysMessage("DB scripts used currently, please attempt reload later.");
587 SetSentErrorMessage(true);
592 sLog
.outString( "Re-Loading Scripts from `spell_scripts`...");
594 objmgr
.LoadSpellScripts();
597 SendGlobalSysMessage("DB table `spell_scripts` reloaded.");
602 bool ChatHandler::HandleReloadDbScriptStringCommand(const char* arg
)
604 sLog
.outString( "Re-Loading Script strings from `db_script_string`...");
605 objmgr
.LoadDbScriptStrings();
606 SendGlobalSysMessage("DB table `db_script_string` reloaded.");
610 bool ChatHandler::HandleReloadGameGraveyardZoneCommand(const char* /*arg*/)
612 sLog
.outString( "Re-Loading Graveyard-zone links...");
614 objmgr
.LoadGraveyardZones();
616 SendGlobalSysMessage("DB table `game_graveyard_zone` reloaded.");
621 bool ChatHandler::HandleReloadGameTeleCommand(const char* /*arg*/)
623 sLog
.outString( "Re-Loading Game Tele coordinates...");
625 objmgr
.LoadGameTele();
627 SendGlobalSysMessage("DB table `game_tele` reloaded.");
632 bool ChatHandler::HandleReloadLocalesCreatureCommand(const char* /*arg*/)
634 sLog
.outString( "Re-Loading Locales Creature ...");
635 objmgr
.LoadCreatureLocales();
636 SendGlobalSysMessage("DB table `locales_creature` reloaded.");
640 bool ChatHandler::HandleReloadLocalesGameobjectCommand(const char* /*arg*/)
642 sLog
.outString( "Re-Loading Locales Gameobject ... ");
643 objmgr
.LoadGameObjectLocales();
644 SendGlobalSysMessage("DB table `locales_gameobject` reloaded.");
648 bool ChatHandler::HandleReloadLocalesItemCommand(const char* /*arg*/)
650 sLog
.outString( "Re-Loading Locales Item ... ");
651 objmgr
.LoadItemLocales();
652 SendGlobalSysMessage("DB table `locales_item` reloaded.");
656 bool ChatHandler::HandleReloadLocalesNpcTextCommand(const char* /*arg*/)
658 sLog
.outString( "Re-Loading Locales NPC Text ... ");
659 objmgr
.LoadNpcTextLocales();
660 SendGlobalSysMessage("DB table `locales_npc_text` reloaded.");
664 bool ChatHandler::HandleReloadLocalesPageTextCommand(const char* /*arg*/)
666 sLog
.outString( "Re-Loading Locales Page Text ... ");
667 objmgr
.LoadPageTextLocales();
668 SendGlobalSysMessage("DB table `locales_page_text` reloaded.");
672 bool ChatHandler::HandleReloadLocalesQuestCommand(const char* /*arg*/)
674 sLog
.outString( "Re-Loading Locales Quest ... ");
675 objmgr
.LoadQuestLocales();
676 SendGlobalSysMessage("DB table `locales_quest` reloaded.");
680 bool ChatHandler::HandleLoadScriptsCommand(const char* args
)
682 if(!LoadScriptingModule(args
)) return true;
684 sWorld
.SendWorldText(LANG_SCRIPTS_RELOADED
);
688 bool ChatHandler::HandleAccountSetGmLevelCommand(const char* args
)
690 char* arg1
= strtok((char*)args
, " ");
694 /// must be NULL if targeted syntax and must be not nULL if not targeted
695 char* arg2
= strtok(NULL
, " ");
697 std::string targetAccountName
;
698 uint32 targetAccountId
= 0;
700 /// only target player different from self allowed (if targetPlayer!=NULL then not console)
701 Player
* targetPlayer
= getSelectedPlayer();
702 if(targetPlayer
&& m_session
->GetPlayer()!=targetPlayer
)
704 /// wrong command syntax or unexpected targeting
708 /// security level expected in arg2 after this if.
711 targetAccountId
= targetPlayer
->GetSession()->GetAccountId();
715 /// wrong command syntax (second arg expected)
719 targetAccountName
= arg1
;
720 if(!AccountMgr::normilizeString(targetAccountName
))
722 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,targetAccountName
.c_str());
723 SetSentErrorMessage(true);
727 targetAccountId
= accmgr
.GetId(targetAccountName
);
730 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,targetAccountName
.c_str());
731 SetSentErrorMessage(true);
736 int32 gm
= (int32
)atoi(arg2
);
737 if ( gm
< SEC_PLAYER
|| gm
> SEC_ADMINISTRATOR
)
739 SendSysMessage(LANG_BAD_VALUE
);
740 SetSentErrorMessage(true);
744 /// can set security level only for target with less security and to less security that we have
745 /// This is also reject self apply in fact
746 if(HasLowerSecurityAccount(NULL
,targetAccountId
,true))
749 /// account can't set security to same or grater level, need more power GM or console
750 uint32 plSecurity
= m_session
? m_session
->GetSecurity() : SEC_CONSOLE
;
751 if (uint32(gm
) >= plSecurity
)
753 SendSysMessage(LANG_YOURS_SECURITY_IS_LOW
);
754 SetSentErrorMessage(true);
760 ChatHandler(targetPlayer
).PSendSysMessage(LANG_YOURS_SECURITY_CHANGED
,GetName(), gm
);
761 targetPlayer
->GetSession()->SetSecurity(gm
);
764 PSendSysMessage(LANG_YOU_CHANGE_SECURITY
, targetAccountName
.c_str(), gm
);
765 loginDatabase
.PExecute("UPDATE account SET gmlevel = '%i' WHERE id = '%u'", gm
, targetAccountId
);
770 /// Set password for account
771 bool ChatHandler::HandleAccountSetPasswordCommand(const char* args
)
776 ///- Get the command line arguments
777 char *szAccount
= strtok ((char*)args
," ");
778 char *szPassword1
= strtok (NULL
," ");
779 char *szPassword2
= strtok (NULL
," ");
781 if (!szAccount
||!szPassword1
|| !szPassword2
)
784 std::string account_name
= szAccount
;
785 if(!AccountMgr::normilizeString(account_name
))
787 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
788 SetSentErrorMessage(true);
792 uint32 targetAccountId
= accmgr
.GetId(account_name
);
793 if (!targetAccountId
)
795 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
796 SetSentErrorMessage(true);
800 /// can set password only for target with less security
801 /// This is also reject self apply in fact
802 if(HasLowerSecurityAccount (NULL
,targetAccountId
,true))
805 if (strcmp(szPassword1
,szPassword2
))
807 SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH
);
808 SetSentErrorMessage (true);
812 AccountOpResult result
= accmgr
.ChangePassword(targetAccountId
, szPassword1
);
817 SendSysMessage(LANG_COMMAND_PASSWORD
);
819 case AOR_NAME_NOT_EXIST
:
820 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
821 SetSentErrorMessage(true);
823 case AOR_PASS_TOO_LONG
:
824 SendSysMessage(LANG_PASSWORD_TOO_LONG
);
825 SetSentErrorMessage(true);
828 SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD
);
829 SetSentErrorMessage(true);
836 bool ChatHandler::HandleAllowMovementCommand(const char* /*args*/)
838 if(sWorld
.getAllowMovement())
840 sWorld
.SetAllowMovement(false);
841 SendSysMessage(LANG_CREATURE_MOVE_DISABLED
);
845 sWorld
.SetAllowMovement(true);
846 SendSysMessage(LANG_CREATURE_MOVE_ENABLED
);
851 bool ChatHandler::HandleMaxSkillCommand(const char* /*args*/)
853 Player
* SelectedPlayer
= getSelectedPlayer();
856 SendSysMessage(LANG_NO_CHAR_SELECTED
);
857 SetSentErrorMessage(true);
861 // each skills that have max skill value dependent from level seted to current level max skill value
862 SelectedPlayer
->UpdateSkillsToMaxSkillsForLevel();
866 bool ChatHandler::HandleSetSkillCommand(const char* args
)
868 // number or [name] Shift-click form |color|Hskill:skill_id|h[name]|h|r
869 char* skill_p
= extractKeyFromLink((char*)args
,"Hskill");
873 char *level_p
= strtok (NULL
, " ");
878 char *max_p
= strtok (NULL
, " ");
880 int32 skill
= atoi(skill_p
);
884 PSendSysMessage(LANG_INVALID_SKILL_ID
, skill
);
885 SetSentErrorMessage(true);
889 int32 level
= atol (level_p
);
891 Player
* target
= getSelectedPlayer();
894 SendSysMessage(LANG_NO_CHAR_SELECTED
);
895 SetSentErrorMessage(true);
899 SkillLineEntry
const* sl
= sSkillLineStore
.LookupEntry(skill
);
902 PSendSysMessage(LANG_INVALID_SKILL_ID
, skill
);
903 SetSentErrorMessage(true);
907 if(!target
->GetSkillValue(skill
))
909 PSendSysMessage(LANG_SET_SKILL_ERROR
, target
->GetName(), skill
, sl
->name
[0]);
910 SetSentErrorMessage(true);
914 int32 max
= max_p
? atol (max_p
) : target
->GetPureMaxSkillValue(skill
);
916 if( level
<= 0 || level
> max
|| max
<= 0 )
919 target
->SetSkill(skill
, level
, max
);
920 PSendSysMessage(LANG_SET_SKILL
, skill
, sl
->name
[0], target
->GetName(), level
, max
);
925 bool ChatHandler::HandleUnLearnCommand(const char* args
)
930 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
931 uint32 min_id
= extractSpellIdFromLink((char*)args
);
935 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
936 char* tail
= strtok(NULL
,"");
938 uint32 max_id
= extractSpellIdFromLink(tail
);
942 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
948 std::swap(min_id
,max_id
);
953 Player
* target
= getSelectedPlayer();
956 SendSysMessage(LANG_NO_CHAR_SELECTED
);
957 SetSentErrorMessage(true);
961 for(uint32 spell
=min_id
;spell
<max_id
;spell
++)
963 if (target
->HasSpell(spell
))
964 target
->removeSpell(spell
);
966 SendSysMessage(LANG_FORGET_SPELL
);
972 bool ChatHandler::HandleCooldownCommand(const char* args
)
974 Player
* target
= getSelectedPlayer();
977 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
978 SetSentErrorMessage(true);
984 target
->RemoveAllSpellCooldown();
985 PSendSysMessage(LANG_REMOVEALL_COOLDOWN
, target
->GetName());
989 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
990 uint32 spell_id
= extractSpellIdFromLink((char*)args
);
994 if(!sSpellStore
.LookupEntry(spell_id
))
996 PSendSysMessage(LANG_UNKNOWN_SPELL
, target
==m_session
->GetPlayer() ? GetMangosString(LANG_YOU
) : target
->GetName());
997 SetSentErrorMessage(true);
1001 WorldPacket
data( SMSG_CLEAR_COOLDOWN
, (4+8) );
1002 data
<< uint32(spell_id
);
1003 data
<< uint64(target
->GetGUID());
1004 target
->GetSession()->SendPacket(&data
);
1005 target
->RemoveSpellCooldown(spell_id
);
1006 PSendSysMessage(LANG_REMOVE_COOLDOWN
, spell_id
, target
==m_session
->GetPlayer() ? GetMangosString(LANG_YOU
) : target
->GetName());
1011 bool ChatHandler::HandleLearnAllCommand(const char* /*args*/)
1013 static const char *allSpellList
[] =
1396 //"9036", problems with ghost state
1405 //"6718", phasing stealth, annoying for learn all case.
1618 while(strcmp(allSpellList
[loop
], "0"))
1620 uint32 spell
= atol((char*)allSpellList
[loop
++]);
1622 if (m_session
->GetPlayer()->HasSpell(spell
))
1625 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1626 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1628 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1632 m_session
->GetPlayer()->learnSpell(spell
);
1635 SendSysMessage(LANG_COMMAND_LEARN_MANY_SPELLS
);
1640 bool ChatHandler::HandleLearnAllGMCommand(const char* /*args*/)
1642 static const char *gmSpellList
[] =
1644 "24347", // Become A Fish, No Breath Bar
1645 "35132", // Visual Boom
1646 "38488", // Attack 4000-8000 AOE
1647 "38795", // Attack 2000 AOE + Slow Down 90%
1648 "15712", // Attack 200
1649 "1852", // GM Spell Silence
1652 "29878", // Kill My Self
1653 "26644", // More Kill
1655 "28550", //Invisible 24
1656 "23452", //Invisible + Target
1660 uint16 gmSpellIter
= 0;
1661 while( strcmp(gmSpellList
[gmSpellIter
], "0") )
1663 uint32 spell
= atol((char*)gmSpellList
[gmSpellIter
++]);
1665 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1666 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1668 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1672 m_session
->GetPlayer()->learnSpell(spell
);
1675 SendSysMessage(LANG_LEARNING_GM_SKILLS
);
1679 bool ChatHandler::HandleLearnAllMyClassCommand(const char* /*args*/)
1681 HandleLearnAllMySpellsCommand("");
1682 HandleLearnAllMyTalentsCommand("");
1686 bool ChatHandler::HandleLearnAllMySpellsCommand(const char* /*args*/)
1688 ChrClassesEntry
const* clsEntry
= sChrClassesStore
.LookupEntry(m_session
->GetPlayer()->getClass());
1691 uint32 family
= clsEntry
->spellfamily
;
1693 for (uint32 i
= 0; i
< sSpellStore
.GetNumRows(); i
++)
1695 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(i
);
1699 // skip server-side/triggered spells
1700 if(spellInfo
->spellLevel
==0)
1703 // skip wrong class/race skills
1704 if(!m_session
->GetPlayer()->IsSpellFitByClassAndRace(spellInfo
->Id
))
1707 // skip other spell families
1708 if( spellInfo
->SpellFamilyName
!= family
)
1711 // skip spells with first rank learned as talent (and all talents then also)
1712 uint32 first_rank
= spellmgr
.GetFirstSpellInChain(spellInfo
->Id
);
1713 if(GetTalentSpellCost(first_rank
) > 0 )
1716 // skip broken spells
1717 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1720 m_session
->GetPlayer()->learnSpell(i
);
1723 SendSysMessage(LANG_COMMAND_LEARN_CLASS_SPELLS
);
1727 static void learnAllHighRanks(Player
* player
, uint32 spellid
)
1729 SpellChainMapNext
const& nextMap
= spellmgr
.GetSpellChainNext();
1730 for(SpellChainMapNext::const_iterator itr
= nextMap
.lower_bound(spellid
); itr
!= nextMap
.upper_bound(spellid
); ++itr
)
1732 player
->learnSpell(itr
->second
);
1733 learnAllHighRanks(player
,itr
->second
);
1737 bool ChatHandler::HandleLearnAllMyTalentsCommand(const char* /*args*/)
1739 Player
* player
= m_session
->GetPlayer();
1740 uint32 classMask
= player
->getClassMask();
1742 for (uint32 i
= 0; i
< sTalentStore
.GetNumRows(); i
++)
1744 TalentEntry
const *talentInfo
= sTalentStore
.LookupEntry(i
);
1748 TalentTabEntry
const *talentTabInfo
= sTalentTabStore
.LookupEntry( talentInfo
->TalentTab
);
1752 if( (classMask
& talentTabInfo
->ClassMask
) == 0 )
1755 // search highest talent rank
1758 for(; rank
>= 0; --rank
)
1760 if(talentInfo
->RankID
[rank
]!=0)
1762 spellid
= talentInfo
->RankID
[rank
];
1767 if(!spellid
) // ??? none spells in talent
1770 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spellid
);
1771 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1774 // learn highest rank of talent
1775 player
->learnSpell(spellid
);
1777 // and learn all non-talent spell ranks (recursive by tree)
1778 learnAllHighRanks(player
,spellid
);
1781 SendSysMessage(LANG_COMMAND_LEARN_CLASS_TALENTS
);
1785 bool ChatHandler::HandleLearnAllLangCommand(const char* /*args*/)
1787 // skipping UNIVERSAL language (0)
1788 for(int i
= 1; i
< LANGUAGES_COUNT
; ++i
)
1789 m_session
->GetPlayer()->learnSpell(lang_description
[i
].spell_id
);
1791 SendSysMessage(LANG_COMMAND_LEARN_ALL_LANG
);
1795 bool ChatHandler::HandleLearnAllDefaultCommand(const char* args
)
1797 char* pName
= strtok((char*)args
, "");
1798 Player
*player
= NULL
;
1801 std::string name
= pName
;
1803 if(!normalizePlayerName(name
))
1805 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1806 SetSentErrorMessage(true);
1810 player
= objmgr
.GetPlayer(name
.c_str());
1813 player
= getSelectedPlayer();
1817 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1818 SetSentErrorMessage(true);
1822 player
->learnDefaultSpells();
1823 player
->learnQuestRewardedSpells();
1825 PSendSysMessage(LANG_COMMAND_LEARN_ALL_DEFAULT_AND_QUEST
,player
->GetName());
1829 bool ChatHandler::HandleLearnCommand(const char* args
)
1831 Player
* targetPlayer
= getSelectedPlayer();
1835 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1836 SetSentErrorMessage(true);
1840 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1841 uint32 spell
= extractSpellIdFromLink((char*)args
);
1842 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
1845 if (targetPlayer
->HasSpell(spell
))
1847 if(targetPlayer
== m_session
->GetPlayer())
1848 SendSysMessage(LANG_YOU_KNOWN_SPELL
);
1850 PSendSysMessage(LANG_TARGET_KNOWN_SPELL
,targetPlayer
->GetName());
1851 SetSentErrorMessage(true);
1855 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1856 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1858 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1859 SetSentErrorMessage(true);
1863 targetPlayer
->learnSpell(spell
);
1868 bool ChatHandler::HandleAddItemCommand(const char* args
)
1875 if(args
[0]=='[') // [name] manual form
1877 char* citemName
= citemName
= strtok((char*)args
, "]");
1879 if(citemName
&& citemName
[0])
1881 std::string itemName
= citemName
+1;
1882 WorldDatabase
.escape_string(itemName
);
1883 QueryResult
*result
= WorldDatabase
.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName
.c_str());
1886 PSendSysMessage(LANG_COMMAND_COULDNOTFIND
, citemName
+1);
1887 SetSentErrorMessage(true);
1890 itemId
= result
->Fetch()->GetUInt16();
1896 else // item_id or [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r
1898 char* cId
= extractKeyFromLink((char*)args
,"Hitem");
1904 char* ccount
= strtok(NULL
, " ");
1909 count
= strtol(ccount
, NULL
, 10);
1914 Player
* pl
= m_session
->GetPlayer();
1915 Player
* plTarget
= getSelectedPlayer();
1919 sLog
.outDetail(GetMangosString(LANG_ADDITEM
), itemId
, count
);
1921 ItemPrototype
const *pProto
= objmgr
.GetItemPrototype(itemId
);
1924 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, itemId
);
1925 SetSentErrorMessage(true);
1932 plTarget
->DestroyItemCount(itemId
, -count
, true, false);
1933 PSendSysMessage(LANG_REMOVEITEM
, itemId
, -count
, plTarget
->GetName());
1938 uint32 noSpaceForCount
= 0;
1940 // check space and find places
1941 ItemPosCountVec dest
;
1942 uint8 msg
= plTarget
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, itemId
, count
, &noSpaceForCount
);
1943 if( msg
!= EQUIP_ERR_OK
) // convert to possible store amount
1944 count
-= noSpaceForCount
;
1946 if( count
== 0 || dest
.empty()) // can't add any
1948 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, itemId
, noSpaceForCount
);
1949 SetSentErrorMessage(true);
1953 Item
* item
= plTarget
->StoreNewItem( dest
, itemId
, true, Item::GenerateItemRandomPropertyId(itemId
));
1955 // remove binding (let GM give it to another player later)
1957 for(ItemPosCountVec::const_iterator itr
= dest
.begin(); itr
!= dest
.end(); ++itr
)
1958 if(Item
* item1
= pl
->GetItemByPos(itr
->pos
))
1959 item1
->SetBinding( false );
1961 if(count
> 0 && item
)
1963 pl
->SendNewItem(item
,count
,false,true);
1965 plTarget
->SendNewItem(item
,count
,true,false);
1968 if(noSpaceForCount
> 0)
1969 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, itemId
, noSpaceForCount
);
1974 bool ChatHandler::HandleAddItemSetCommand(const char* args
)
1979 char* cId
= extractKeyFromLink((char*)args
,"Hitemset"); // number or [name] Shift-click form |color|Hitemset:itemset_id|h[name]|h|r
1983 uint32 itemsetId
= atol(cId
);
1985 // prevent generation all items with itemset field value '0'
1988 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND
,itemsetId
);
1989 SetSentErrorMessage(true);
1993 Player
* pl
= m_session
->GetPlayer();
1994 Player
* plTarget
= getSelectedPlayer();
1998 sLog
.outDetail(GetMangosString(LANG_ADDITEMSET
), itemsetId
);
2001 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
2003 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
2007 if (pProto
->ItemSet
== itemsetId
)
2010 ItemPosCountVec dest
;
2011 uint8 msg
= plTarget
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, pProto
->ItemId
, 1 );
2012 if (msg
== EQUIP_ERR_OK
)
2014 Item
* item
= plTarget
->StoreNewItem( dest
, pProto
->ItemId
, true);
2016 // remove binding (let GM give it to another player later)
2018 item
->SetBinding( false );
2020 pl
->SendNewItem(item
,1,false,true);
2022 plTarget
->SendNewItem(item
,1,true,false);
2026 pl
->SendEquipError( msg
, NULL
, NULL
);
2027 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, pProto
->ItemId
, 1);
2034 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND
,itemsetId
);
2036 SetSentErrorMessage(true);
2043 bool ChatHandler::HandleListItemCommand(const char* args
)
2048 char* cId
= extractKeyFromLink((char*)args
,"Hitem");
2052 uint32 item_id
= atol(cId
);
2055 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
2056 SetSentErrorMessage(true);
2060 ItemPrototype
const* itemProto
= objmgr
.GetItemPrototype(item_id
);
2063 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
2064 SetSentErrorMessage(true);
2068 char* c_count
= strtok(NULL
, " ");
2069 int count
= c_count
? atol(c_count
) : 10;
2074 QueryResult
*result
;
2077 uint32 inv_count
= 0;
2078 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM character_inventory WHERE item_template='%u'",item_id
);
2081 inv_count
= (*result
)[0].GetUInt32();
2085 result
=CharacterDatabase
.PQuery(
2087 "SELECT ci.item, cibag.slot AS bag, ci.slot, ci.guid, characters.account,characters.name "
2088 "FROM character_inventory AS ci LEFT JOIN character_inventory AS cibag ON (cibag.item=ci.bag),characters "
2089 "WHERE ci.item_template='%u' AND ci.guid = characters.guid LIMIT %u ",
2090 item_id
,uint32(count
));
2096 Field
*fields
= result
->Fetch();
2097 uint32 item_guid
= fields
[0].GetUInt32();
2098 uint32 item_bag
= fields
[1].GetUInt32();
2099 uint32 item_slot
= fields
[2].GetUInt32();
2100 uint32 owner_guid
= fields
[3].GetUInt32();
2101 uint32 owner_acc
= fields
[4].GetUInt32();
2102 std::string owner_name
= fields
[5].GetCppString();
2104 char const* item_pos
= 0;
2105 if(Player::IsEquipmentPos(item_bag
,item_slot
))
2106 item_pos
= "[equipped]";
2107 else if(Player::IsInventoryPos(item_bag
,item_slot
))
2108 item_pos
= "[in inventory]";
2109 else if(Player::IsBankPos(item_bag
,item_slot
))
2110 item_pos
= "[in bank]";
2114 PSendSysMessage(LANG_ITEMLIST_SLOT
,
2115 item_guid
,owner_name
.c_str(),owner_guid
,owner_acc
,item_pos
);
2116 } while (result
->NextRow());
2118 int64 res_count
= result
->GetRowCount();
2122 if(count
> res_count
)
2129 uint32 mail_count
= 0;
2130 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM mail_items WHERE item_template='%u'", item_id
);
2133 mail_count
= (*result
)[0].GetUInt32();
2139 result
=CharacterDatabase
.PQuery(
2141 "SELECT mail_items.item_guid, mail.sender, mail.receiver, char_s.account, char_s.name, char_r.account, char_r.name "
2142 "FROM mail,mail_items,characters as char_s,characters as char_r "
2143 "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",
2144 item_id
,uint32(count
));
2153 Field
*fields
= result
->Fetch();
2154 uint32 item_guid
= fields
[0].GetUInt32();
2155 uint32 item_s
= fields
[1].GetUInt32();
2156 uint32 item_r
= fields
[2].GetUInt32();
2157 uint32 item_s_acc
= fields
[3].GetUInt32();
2158 std::string item_s_name
= fields
[4].GetCppString();
2159 uint32 item_r_acc
= fields
[5].GetUInt32();
2160 std::string item_r_name
= fields
[6].GetCppString();
2162 char const* item_pos
= "[in mail]";
2164 PSendSysMessage(LANG_ITEMLIST_MAIL
,
2165 item_guid
,item_s_name
.c_str(),item_s
,item_s_acc
,item_r_name
.c_str(),item_r
,item_r_acc
,item_pos
);
2166 } while (result
->NextRow());
2168 int64 res_count
= result
->GetRowCount();
2172 if(count
> res_count
)
2179 uint32 auc_count
= 0;
2180 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM auctionhouse WHERE item_template='%u'",item_id
);
2183 auc_count
= (*result
)[0].GetUInt32();
2189 result
=CharacterDatabase
.PQuery(
2191 "SELECT auctionhouse.itemguid, auctionhouse.itemowner, characters.account, characters.name "
2192 "FROM auctionhouse,characters WHERE auctionhouse.item_template='%u' AND characters.guid = auctionhouse.itemowner LIMIT %u",
2193 item_id
,uint32(count
));
2202 Field
*fields
= result
->Fetch();
2203 uint32 item_guid
= fields
[0].GetUInt32();
2204 uint32 owner
= fields
[1].GetUInt32();
2205 uint32 owner_acc
= fields
[2].GetUInt32();
2206 std::string owner_name
= fields
[3].GetCppString();
2208 char const* item_pos
= "[in auction]";
2210 PSendSysMessage(LANG_ITEMLIST_AUCTION
, item_guid
, owner_name
.c_str(), owner
, owner_acc
,item_pos
);
2211 } while (result
->NextRow());
2217 uint32 guild_count
= 0;
2218 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_entry) FROM guild_bank_item WHERE item_entry='%u'",item_id
);
2221 guild_count
= (*result
)[0].GetUInt32();
2225 result
=CharacterDatabase
.PQuery(
2227 "SELECT gi.item_guid, gi.guildid, guild.name "
2228 "FROM guild_bank_item AS gi, guild WHERE gi.item_entry='%u' AND gi.guildid = guild.guildid LIMIT %u ",
2229 item_id
,uint32(count
));
2235 Field
*fields
= result
->Fetch();
2236 uint32 item_guid
= fields
[0].GetUInt32();
2237 uint32 guild_guid
= fields
[1].GetUInt32();
2238 std::string guild_name
= fields
[2].GetCppString();
2240 char const* item_pos
= "[in guild bank]";
2242 PSendSysMessage(LANG_ITEMLIST_GUILD
,item_guid
,guild_name
.c_str(),guild_guid
,item_pos
);
2243 } while (result
->NextRow());
2245 int64 res_count
= result
->GetRowCount();
2249 if(count
> res_count
)
2255 if(inv_count
+mail_count
+auc_count
+guild_count
== 0)
2257 SendSysMessage(LANG_COMMAND_NOITEMFOUND
);
2258 SetSentErrorMessage(true);
2262 PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE
,item_id
,inv_count
+mail_count
+auc_count
+guild_count
,inv_count
,mail_count
,auc_count
,guild_count
);
2267 bool ChatHandler::HandleListObjectCommand(const char* args
)
2272 // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2273 char* cId
= extractKeyFromLink((char*)args
,"Hgameobject_entry");
2277 uint32 go_id
= atol(cId
);
2280 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID
, go_id
);
2281 SetSentErrorMessage(true);
2285 GameObjectInfo
const * gInfo
= objmgr
.GetGameObjectInfo(go_id
);
2288 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID
, go_id
);
2289 SetSentErrorMessage(true);
2293 char* c_count
= strtok(NULL
, " ");
2294 int count
= c_count
? atol(c_count
) : 10;
2299 QueryResult
*result
;
2301 uint32 obj_count
= 0;
2302 result
=WorldDatabase
.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'",go_id
);
2305 obj_count
= (*result
)[0].GetUInt32();
2311 Player
* pl
= m_session
->GetPlayer();
2312 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",
2313 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(),go_id
,uint32(count
));
2316 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map FROM gameobject WHERE id = '%u' LIMIT %u",
2317 go_id
,uint32(count
));
2323 Field
*fields
= result
->Fetch();
2324 uint32 guid
= fields
[0].GetUInt32();
2325 float x
= fields
[1].GetFloat();
2326 float y
= fields
[2].GetFloat();
2327 float z
= fields
[3].GetFloat();
2328 int mapid
= fields
[4].GetUInt16();
2331 PSendSysMessage(LANG_GO_LIST_CHAT
, guid
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2333 PSendSysMessage(LANG_GO_LIST_CONSOLE
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2334 } while (result
->NextRow());
2339 PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE
,go_id
,obj_count
);
2343 bool ChatHandler::HandleNearObjectCommand(const char* args
)
2345 float distance
= (!*args
) ? 10 : atol(args
);
2348 Player
* pl
= m_session
->GetPlayer();
2349 QueryResult
*result
= WorldDatabase
.PQuery("SELECT guid, id, position_x, position_y, position_z, map, "
2350 "(POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ "
2351 "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_",
2352 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(),
2353 pl
->GetMapId(),pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(),distance
*distance
);
2359 Field
*fields
= result
->Fetch();
2360 uint32 guid
= fields
[0].GetUInt32();
2361 uint32 entry
= fields
[1].GetUInt32();
2362 float x
= fields
[2].GetFloat();
2363 float y
= fields
[3].GetFloat();
2364 float z
= fields
[4].GetFloat();
2365 int mapid
= fields
[5].GetUInt16();
2367 GameObjectInfo
const * gInfo
= objmgr
.GetGameObjectInfo(entry
);
2372 PSendSysMessage(LANG_GO_LIST_CHAT
, guid
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2375 } while (result
->NextRow());
2380 PSendSysMessage(LANG_COMMAND_NEAROBJMESSAGE
,distance
,count
);
2384 bool ChatHandler::HandleListCreatureCommand(const char* args
)
2389 // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
2390 char* cId
= extractKeyFromLink((char*)args
,"Hcreature_entry");
2394 uint32 cr_id
= atol(cId
);
2397 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID
, cr_id
);
2398 SetSentErrorMessage(true);
2402 CreatureInfo
const* cInfo
= objmgr
.GetCreatureTemplate(cr_id
);
2405 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID
, cr_id
);
2406 SetSentErrorMessage(true);
2410 char* c_count
= strtok(NULL
, " ");
2411 int count
= c_count
? atol(c_count
) : 10;
2416 QueryResult
*result
;
2418 uint32 cr_count
= 0;
2419 result
=WorldDatabase
.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'",cr_id
);
2422 cr_count
= (*result
)[0].GetUInt32();
2428 Player
* pl
= m_session
->GetPlayer();
2429 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",
2430 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(), cr_id
,uint32(count
));
2433 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '%u' LIMIT %u",
2434 cr_id
,uint32(count
));
2440 Field
*fields
= result
->Fetch();
2441 uint32 guid
= fields
[0].GetUInt32();
2442 float x
= fields
[1].GetFloat();
2443 float y
= fields
[2].GetFloat();
2444 float z
= fields
[3].GetFloat();
2445 int mapid
= fields
[4].GetUInt16();
2448 PSendSysMessage(LANG_CREATURE_LIST_CHAT
, guid
, guid
, cInfo
->Name
, x
, y
, z
, mapid
);
2450 PSendSysMessage(LANG_CREATURE_LIST_CONSOLE
, guid
, cInfo
->Name
, x
, y
, z
, mapid
);
2451 } while (result
->NextRow());
2456 PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE
,cr_id
,cr_count
);
2460 bool ChatHandler::HandleLookupItemCommand(const char* args
)
2465 std::string namepart
= args
;
2466 std::wstring wnamepart
;
2468 // converting string that we try to find to lower case
2469 if(!Utf8toWStr(namepart
,wnamepart
))
2472 wstrToLower(wnamepart
);
2476 // Search in `item_template`
2477 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
2479 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
2483 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2486 ItemLocale
const *il
= objmgr
.GetItemLocale(pProto
->ItemId
);
2489 if (il
->Name
.size() > loc_idx
&& !il
->Name
[loc_idx
].empty())
2491 std::string name
= il
->Name
[loc_idx
];
2493 if (Utf8FitTo(name
, wnamepart
))
2496 PSendSysMessage(LANG_ITEM_LIST_CHAT
, id
, id
, name
.c_str());
2498 PSendSysMessage(LANG_ITEM_LIST_CONSOLE
, id
, name
.c_str());
2506 std::string name
= pProto
->Name1
;
2510 if (Utf8FitTo(name
, wnamepart
))
2513 PSendSysMessage(LANG_ITEM_LIST_CHAT
, id
, id
, name
.c_str());
2515 PSendSysMessage(LANG_ITEM_LIST_CONSOLE
, id
, name
.c_str());
2521 SendSysMessage(LANG_COMMAND_NOITEMFOUND
);
2526 bool ChatHandler::HandleLookupItemSetCommand(const char* args
)
2531 std::string namepart
= args
;
2532 std::wstring wnamepart
;
2534 if(!Utf8toWStr(namepart
,wnamepart
))
2537 // converting string that we try to find to lower case
2538 wstrToLower( wnamepart
);
2540 uint32 counter
= 0; // Counter for figure out that we found smth.
2542 // Search in ItemSet.dbc
2543 for (uint32 id
= 0; id
< sItemSetStore
.GetNumRows(); id
++)
2545 ItemSetEntry
const *set
= sItemSetStore
.LookupEntry(id
);
2548 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
2549 std::string name
= set
->name
[loc
];
2553 if (!Utf8FitTo(name
, wnamepart
))
2556 for(; loc
< MAX_LOCALE
; ++loc
)
2558 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
2561 name
= set
->name
[loc
];
2565 if (Utf8FitTo(name
, wnamepart
))
2570 if(loc
< MAX_LOCALE
)
2572 // send item set in "id - [namedlink locale]" format
2574 PSendSysMessage(LANG_ITEMSET_LIST_CHAT
,id
,id
,name
.c_str(),localeNames
[loc
]);
2576 PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE
,id
,name
.c_str(),localeNames
[loc
]);
2581 if (counter
== 0) // if counter == 0 then we found nth
2582 SendSysMessage(LANG_COMMAND_NOITEMSETFOUND
);
2586 bool ChatHandler::HandleLookupSkillCommand(const char* args
)
2591 // can be NULL in console call
2592 Player
* target
= getSelectedPlayer();
2594 std::string namepart
= args
;
2595 std::wstring wnamepart
;
2597 if(!Utf8toWStr(namepart
,wnamepart
))
2600 // converting string that we try to find to lower case
2601 wstrToLower( wnamepart
);
2603 uint32 counter
= 0; // Counter for figure out that we found smth.
2605 // Search in SkillLine.dbc
2606 for (uint32 id
= 0; id
< sSkillLineStore
.GetNumRows(); id
++)
2608 SkillLineEntry
const *skillInfo
= sSkillLineStore
.LookupEntry(id
);
2611 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
2612 std::string name
= skillInfo
->name
[loc
];
2616 if (!Utf8FitTo(name
, wnamepart
))
2619 for(; loc
< MAX_LOCALE
; ++loc
)
2621 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
2624 name
= skillInfo
->name
[loc
];
2628 if (Utf8FitTo(name
, wnamepart
))
2633 if(loc
< MAX_LOCALE
)
2635 char const* knownStr
= "";
2636 if(target
&& target
->HasSkill(id
))
2637 knownStr
= GetMangosString(LANG_KNOWN
);
2639 // send skill in "id - [namedlink locale]" format
2641 PSendSysMessage(LANG_SKILL_LIST_CHAT
,id
,id
,name
.c_str(),localeNames
[loc
],knownStr
);
2643 PSendSysMessage(LANG_SKILL_LIST_CONSOLE
,id
,name
.c_str(),localeNames
[loc
],knownStr
);
2649 if (counter
== 0) // if counter == 0 then we found nth
2650 SendSysMessage(LANG_COMMAND_NOSKILLFOUND
);
2654 bool ChatHandler::HandleLookupSpellCommand(const char* args
)
2659 // can be NULL at console call
2660 Player
* target
= getSelectedPlayer();
2662 std::string namepart
= args
;
2663 std::wstring wnamepart
;
2665 if(!Utf8toWStr(namepart
,wnamepart
))
2668 // converting string that we try to find to lower case
2669 wstrToLower( wnamepart
);
2671 uint32 counter
= 0; // Counter for figure out that we found smth.
2673 // Search in Spell.dbc
2674 for (uint32 id
= 0; id
< sSpellStore
.GetNumRows(); id
++)
2676 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(id
);
2679 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
2680 std::string name
= spellInfo
->SpellName
[loc
];
2684 if (!Utf8FitTo(name
, wnamepart
))
2687 for(; loc
< MAX_LOCALE
; ++loc
)
2689 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
2692 name
= spellInfo
->SpellName
[loc
];
2696 if (Utf8FitTo(name
, wnamepart
))
2701 if(loc
< MAX_LOCALE
)
2703 bool known
= target
&& target
->HasSpell(id
);
2704 bool learn
= (spellInfo
->Effect
[0] == SPELL_EFFECT_LEARN_SPELL
);
2706 uint32 talentCost
= GetTalentSpellCost(id
);
2708 bool talent
= (talentCost
> 0);
2709 bool passive
= IsPassiveSpell(id
);
2710 bool active
= target
&& target
->HasAura(id
);
2712 // unit32 used to prevent interpreting uint8 as char at output
2713 // find rank of learned spell for learning spell, or talent rank
2714 uint32 rank
= talentCost
? talentCost
: spellmgr
.GetSpellRank(learn
? spellInfo
->EffectTriggerSpell
[0] : id
);
2716 // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
2717 std::ostringstream ss
;
2719 ss
<< id
<< " - |cffffffff|Hspell:" << id
<< "|h[" << name
;
2721 ss
<< id
<< " - " << name
;
2723 // include rank in link name
2725 ss
<< GetMangosString(LANG_SPELL_RANK
) << rank
;
2728 ss
<< " " << localeNames
[loc
] << "]|h|r";
2730 ss
<< " " << localeNames
[loc
];
2733 ss
<< GetMangosString(LANG_TALENT
);
2735 ss
<< GetMangosString(LANG_PASSIVE
);
2737 ss
<< GetMangosString(LANG_LEARN
);
2739 ss
<< GetMangosString(LANG_KNOWN
);
2741 ss
<< GetMangosString(LANG_ACTIVE
);
2743 SendSysMessage(ss
.str().c_str());
2749 if (counter
== 0) // if counter == 0 then we found nth
2750 SendSysMessage(LANG_COMMAND_NOSPELLFOUND
);
2754 bool ChatHandler::HandleLookupQuestCommand(const char* args
)
2759 // can be NULL at console call
2760 Player
* target
= getSelectedPlayer();
2762 std::string namepart
= args
;
2763 std::wstring wnamepart
;
2765 // converting string that we try to find to lower case
2766 if(!Utf8toWStr(namepart
,wnamepart
))
2769 wstrToLower(wnamepart
);
2771 uint32 counter
= 0 ;
2773 ObjectMgr::QuestMap
const& qTemplates
= objmgr
.GetQuestTemplates();
2774 for (ObjectMgr::QuestMap::const_iterator iter
= qTemplates
.begin(); iter
!= qTemplates
.end(); ++iter
)
2776 Quest
* qinfo
= iter
->second
;
2778 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2781 QuestLocale
const *il
= objmgr
.GetQuestLocale(qinfo
->GetQuestId());
2784 if (il
->Title
.size() > loc_idx
&& !il
->Title
[loc_idx
].empty())
2786 std::string title
= il
->Title
[loc_idx
];
2788 if (Utf8FitTo(title
, wnamepart
))
2790 char const* statusStr
= "";
2794 QuestStatus status
= target
->GetQuestStatus(qinfo
->GetQuestId());
2796 if(status
== QUEST_STATUS_COMPLETE
)
2798 if(target
->GetQuestRewardStatus(qinfo
->GetQuestId()))
2799 statusStr
= GetMangosString(LANG_COMMAND_QUEST_REWARDED
);
2801 statusStr
= GetMangosString(LANG_COMMAND_QUEST_COMPLETE
);
2803 else if(status
== QUEST_STATUS_INCOMPLETE
)
2804 statusStr
= GetMangosString(LANG_COMMAND_QUEST_ACTIVE
);
2808 PSendSysMessage(LANG_QUEST_LIST_CHAT
,qinfo
->GetQuestId(),qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2810 PSendSysMessage(LANG_QUEST_LIST_CONSOLE
,qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2818 std::string title
= qinfo
->GetTitle();
2822 if (Utf8FitTo(title
, wnamepart
))
2824 char const* statusStr
= "";
2828 QuestStatus status
= target
->GetQuestStatus(qinfo
->GetQuestId());
2830 if(status
== QUEST_STATUS_COMPLETE
)
2832 if(target
->GetQuestRewardStatus(qinfo
->GetQuestId()))
2833 statusStr
= GetMangosString(LANG_COMMAND_QUEST_REWARDED
);
2835 statusStr
= GetMangosString(LANG_COMMAND_QUEST_COMPLETE
);
2837 else if(status
== QUEST_STATUS_INCOMPLETE
)
2838 statusStr
= GetMangosString(LANG_COMMAND_QUEST_ACTIVE
);
2842 PSendSysMessage(LANG_QUEST_LIST_CHAT
,qinfo
->GetQuestId(),qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2844 PSendSysMessage(LANG_QUEST_LIST_CONSOLE
,qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2851 SendSysMessage(LANG_COMMAND_NOQUESTFOUND
);
2856 bool ChatHandler::HandleLookupCreatureCommand(const char* args
)
2861 std::string namepart
= args
;
2862 std::wstring wnamepart
;
2864 // converting string that we try to find to lower case
2865 if (!Utf8toWStr (namepart
,wnamepart
))
2868 wstrToLower (wnamepart
);
2872 for (uint32 id
= 0; id
< sCreatureStorage
.MaxEntry
; ++id
)
2874 CreatureInfo
const* cInfo
= sCreatureStorage
.LookupEntry
<CreatureInfo
> (id
);
2878 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2881 CreatureLocale
const *cl
= objmgr
.GetCreatureLocale (id
);
2884 if (cl
->Name
.size() > loc_idx
&& !cl
->Name
[loc_idx
].empty ())
2886 std::string name
= cl
->Name
[loc_idx
];
2888 if (Utf8FitTo (name
, wnamepart
))
2891 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str ());
2893 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE
, id
, name
.c_str ());
2901 std::string name
= cInfo
->Name
;
2905 if (Utf8FitTo(name
, wnamepart
))
2908 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str ());
2910 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE
, id
, name
.c_str ());
2916 SendSysMessage (LANG_COMMAND_NOCREATUREFOUND
);
2921 bool ChatHandler::HandleLookupObjectCommand(const char* args
)
2926 std::string namepart
= args
;
2927 std::wstring wnamepart
;
2929 // converting string that we try to find to lower case
2930 if(!Utf8toWStr(namepart
,wnamepart
))
2933 wstrToLower(wnamepart
);
2937 for (uint32 id
= 0; id
< sGOStorage
.MaxEntry
; id
++ )
2939 GameObjectInfo
const* gInfo
= sGOStorage
.LookupEntry
<GameObjectInfo
>(id
);
2943 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2946 GameObjectLocale
const *gl
= objmgr
.GetGameObjectLocale(id
);
2949 if (gl
->Name
.size() > loc_idx
&& !gl
->Name
[loc_idx
].empty())
2951 std::string name
= gl
->Name
[loc_idx
];
2953 if (Utf8FitTo(name
, wnamepart
))
2956 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT
, id
, id
, name
.c_str());
2958 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE
, id
, name
.c_str());
2966 std::string name
= gInfo
->name
;
2970 if(Utf8FitTo(name
, wnamepart
))
2973 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT
, id
, id
, name
.c_str());
2975 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE
, id
, name
.c_str());
2981 SendSysMessage(LANG_COMMAND_NOGAMEOBJECTFOUND
);
2986 /** \brief GM command level 3 - Create a guild.
2988 * This command allows a GM (level 3) to create a guild.
2990 * The "args" parameter contains the name of the guild leader
2991 * and then the name of the guild.
2994 bool ChatHandler::HandleGuildCreateCommand(const char* args
)
3000 char *lname
= strtok ((char*)args
, " ");
3001 char *gname
= strtok (NULL
, "");
3008 SendSysMessage (LANG_INSERT_GUILD_NAME
);
3009 SetSentErrorMessage (true);
3013 std::string guildname
= gname
;
3015 Player
* player
= ObjectAccessor::Instance ().FindPlayerByName (lname
);
3018 SendSysMessage (LANG_PLAYER_NOT_FOUND
);
3019 SetSentErrorMessage (true);
3023 if (player
->GetGuildId())
3025 SendSysMessage (LANG_PLAYER_IN_GUILD
);
3029 Guild
*guild
= new Guild
;
3030 if (!guild
->create (player
->GetGUID (),guildname
))
3033 SendSysMessage (LANG_GUILD_NOT_CREATED
);
3034 SetSentErrorMessage (true);
3038 objmgr
.AddGuild (guild
);
3042 bool ChatHandler::HandleGuildInviteCommand(const char *args
)
3047 char* par1
= strtok ((char*)args
, " ");
3048 char* par2
= strtok (NULL
, "");
3052 std::string glName
= par2
;
3053 Guild
* targetGuild
= objmgr
.GetGuildByName (glName
);
3057 std::string plName
= par1
;
3058 if (!normalizePlayerName (plName
))
3060 SendSysMessage (LANG_PLAYER_NOT_FOUND
);
3061 SetSentErrorMessage (true);
3066 if (Player
* targetPlayer
= ObjectAccessor::Instance ().FindPlayerByName (plName
.c_str ()))
3067 plGuid
= targetPlayer
->GetGUID ();
3069 plGuid
= objmgr
.GetPlayerGUIDByName (plName
.c_str ());
3074 // player's guild membership checked in AddMember before add
3075 if (!targetGuild
->AddMember (plGuid
,targetGuild
->GetLowestRank ()))
3081 bool ChatHandler::HandleGuildUninviteCommand(const char *args
)
3086 char* par1
= strtok ((char*)args
, " ");
3090 std::string plName
= par1
;
3091 if (!normalizePlayerName (plName
))
3093 SendSysMessage (LANG_PLAYER_NOT_FOUND
);
3094 SetSentErrorMessage (true);
3100 if (Player
* targetPlayer
= ObjectAccessor::Instance ().FindPlayerByName (plName
.c_str ()))
3102 plGuid
= targetPlayer
->GetGUID ();
3103 glId
= targetPlayer
->GetGuildId ();
3107 plGuid
= objmgr
.GetPlayerGUIDByName (plName
.c_str ());
3108 glId
= Player::GetGuildIdFromDB (plGuid
);
3111 if (!plGuid
|| !glId
)
3114 Guild
* targetGuild
= objmgr
.GetGuildById (glId
);
3118 targetGuild
->DelMember (plGuid
);
3123 bool ChatHandler::HandleGuildRankCommand(const char *args
)
3128 char* par1
= strtok ((char*)args
, " ");
3129 char* par2
= strtok (NULL
, " ");
3132 std::string plName
= par1
;
3133 if (!normalizePlayerName (plName
))
3135 SendSysMessage (LANG_PLAYER_NOT_FOUND
);
3136 SetSentErrorMessage (true);
3142 if (Player
* targetPlayer
= ObjectAccessor::Instance ().FindPlayerByName (plName
.c_str ()))
3144 plGuid
= targetPlayer
->GetGUID ();
3145 glId
= targetPlayer
->GetGuildId ();
3149 plGuid
= objmgr
.GetPlayerGUIDByName (plName
.c_str ());
3150 glId
= Player::GetGuildIdFromDB (plGuid
);
3153 if (!plGuid
|| !glId
)
3156 Guild
* targetGuild
= objmgr
.GetGuildById (glId
);
3160 uint32 newrank
= uint32 (atoi (par2
));
3161 if (newrank
> targetGuild
->GetLowestRank ())
3164 targetGuild
->ChangeRank (plGuid
,newrank
);
3169 bool ChatHandler::HandleGuildDeleteCommand(const char* args
)
3174 char* par1
= strtok ((char*)args
, " ");
3178 std::string gld
= par1
;
3180 Guild
* targetGuild
= objmgr
.GetGuildByName (gld
);
3184 targetGuild
->Disband ();
3189 bool ChatHandler::HandleGetDistanceCommand(const char* /*args*/)
3191 Unit
* pUnit
= getSelectedUnit();
3195 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3196 SetSentErrorMessage(true);
3200 PSendSysMessage(LANG_DISTANCE
, m_session
->GetPlayer()->GetDistance(pUnit
),m_session
->GetPlayer()->GetDistance2d(pUnit
));
3207 bool ChatHandler::HandleAddWeaponCommand(const char* /*args*/)
3212 uint64 guid = m_session->GetPlayer()->GetSelection();
3215 SendSysMessage(LANG_NO_SELECTION);
3219 Creature *pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
3223 SendSysMessage(LANG_SELECT_CREATURE);
3227 char* pSlotID = strtok((char*)args, " ");
3231 char* pItemID = strtok(NULL, " ");
3235 uint32 ItemID = atoi(pItemID);
3236 uint32 SlotID = atoi(pSlotID);
3238 ItemPrototype* tmpItem = objmgr.GetItemPrototype(ItemID);
3246 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID);
3250 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID);
3254 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID);
3258 PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST,SlotID);
3264 PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT,ItemID,tmpItem->Name1,SlotID);
3269 PSendSysMessage(LANG_ITEM_NOT_FOUND,ItemID);
3276 bool ChatHandler::HandleDieCommand(const char* /*args*/)
3278 Unit
* target
= getSelectedUnit();
3280 if(!target
|| !m_session
->GetPlayer()->GetSelection())
3282 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3283 SetSentErrorMessage(true);
3287 if( target
->isAlive() )
3289 m_session
->GetPlayer()->DealDamage(target
, target
->GetHealth(), NULL
, DIRECT_DAMAGE
, SPELL_SCHOOL_MASK_NORMAL
, NULL
, false);
3295 bool ChatHandler::HandleDamageCommand(const char * args
)
3300 Unit
* target
= getSelectedUnit();
3302 if(!target
|| !m_session
->GetPlayer()->GetSelection())
3304 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3305 SetSentErrorMessage(true);
3309 if( !target
->isAlive() )
3312 char* damageStr
= strtok((char*)args
, " ");
3316 int32 damage
= atoi((char*)damageStr
);
3320 char* schoolStr
= strtok((char*)NULL
, " ");
3322 // flat melee damage without resistence/etc reduction
3325 m_session
->GetPlayer()->DealDamage(target
, damage
, NULL
, DIRECT_DAMAGE
, SPELL_SCHOOL_MASK_NORMAL
, NULL
, false);
3326 m_session
->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2
, target
, 1, SPELL_SCHOOL_MASK_NORMAL
, damage
, 0, 0, VICTIMSTATE_NORMAL
, 0);
3330 uint32 school
= schoolStr
? atoi((char*)schoolStr
) : SPELL_SCHOOL_NORMAL
;
3331 if(school
>= MAX_SPELL_SCHOOL
)
3334 SpellSchoolMask schoolmask
= SpellSchoolMask(1 << school
);
3336 if ( schoolmask
& SPELL_SCHOOL_MASK_NORMAL
)
3337 damage
= m_session
->GetPlayer()->CalcArmorReducedDamage(target
, damage
);
3339 char* spellStr
= strtok((char*)NULL
, " ");
3341 // melee damage by specific school
3347 m_session
->GetPlayer()->CalcAbsorbResist(target
,schoolmask
, SPELL_DIRECT_DAMAGE
, damage
, &absorb
, &resist
);
3349 if (damage
<= absorb
+ resist
)
3352 damage
-= absorb
+ resist
;
3354 m_session
->GetPlayer()->DealDamage(target
, damage
, NULL
, DIRECT_DAMAGE
, schoolmask
, NULL
, false);
3355 m_session
->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2
, target
, 1, schoolmask
, damage
, absorb
, resist
, VICTIMSTATE_NORMAL
, 0);
3361 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3362 uint32 spellid
= extractSpellIdFromLink((char*)args
);
3363 if(!spellid
|| !sSpellStore
.LookupEntry(spellid
))
3366 m_session
->GetPlayer()->SpellNonMeleeDamageLog(target
, spellid
, damage
, false);
3370 bool ChatHandler::HandleModifyArenaCommand(const char * args
)
3375 Player
*target
= getSelectedPlayer();
3378 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3379 SetSentErrorMessage(true);
3383 int32 amount
= (uint32
)atoi(args
);
3385 target
->ModifyArenaPoints(amount
);
3387 PSendSysMessage(LANG_COMMAND_MODIFY_ARENA
, target
->GetName(), target
->GetArenaPoints());
3392 bool ChatHandler::HandleReviveCommand(const char* args
)
3394 Player
* SelectedPlayer
= NULL
;
3398 std::string name
= args
;
3399 if(!normalizePlayerName(name
))
3401 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3402 SetSentErrorMessage(true);
3406 SelectedPlayer
= objmgr
.GetPlayer(name
.c_str());
3409 SelectedPlayer
= getSelectedPlayer();
3413 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3414 SetSentErrorMessage(true);
3418 SelectedPlayer
->ResurrectPlayer(0.5f
);
3419 SelectedPlayer
->SpawnCorpseBones();
3420 SelectedPlayer
->SaveToDB();
3424 bool ChatHandler::HandleAuraCommand(const char* args
)
3426 char* px
= strtok((char*)args
, " ");
3430 Unit
*target
= getSelectedUnit();
3433 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3434 SetSentErrorMessage(true);
3438 uint32 spellID
= (uint32
)atoi(px
);
3439 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry( spellID
);
3442 for(uint32 i
= 0;i
<3;i
++)
3444 uint8 eff
= spellInfo
->Effect
[i
];
3445 if (eff
>=TOTAL_SPELL_EFFECTS
)
3447 if( IsAreaAuraEffect(eff
) ||
3448 eff
== SPELL_EFFECT_APPLY_AURA
||
3449 eff
== SPELL_EFFECT_PERSISTENT_AREA_AURA
)
3451 Aura
*Aur
= CreateAura(spellInfo
, i
, NULL
, target
);
3452 target
->AddAura(Aur
);
3460 bool ChatHandler::HandleUnAuraCommand(const char* args
)
3462 char* px
= strtok((char*)args
, " ");
3466 Unit
*target
= getSelectedUnit();
3469 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3470 SetSentErrorMessage(true);
3474 std::string argstr
= args
;
3475 if (argstr
== "all")
3477 target
->RemoveAllAuras();
3481 uint32 spellID
= (uint32
)atoi(px
);
3482 target
->RemoveAurasDueToSpell(spellID
);
3487 bool ChatHandler::HandleLinkGraveCommand(const char* args
)
3492 char* px
= strtok((char*)args
, " ");
3496 uint32 g_id
= (uint32
)atoi(px
);
3500 char* px2
= strtok(NULL
, " ");
3504 else if (strncmp(px2
,"horde",6)==0)
3506 else if (strncmp(px2
,"alliance",9)==0)
3511 WorldSafeLocsEntry
const* graveyard
= sWorldSafeLocsStore
.LookupEntry(g_id
);
3515 PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST
, g_id
);
3516 SetSentErrorMessage(true);
3520 Player
* player
= m_session
->GetPlayer();
3522 uint32 zoneId
= player
->GetZoneId();
3524 AreaTableEntry
const *areaEntry
= GetAreaEntryByAreaID(zoneId
);
3525 if(!areaEntry
|| areaEntry
->zone
!=0 )
3527 PSendSysMessage(LANG_COMMAND_GRAVEYARDWRONGZONE
, g_id
,zoneId
);
3528 SetSentErrorMessage(true);
3532 if(objmgr
.AddGraveYardLink(g_id
,player
->GetZoneId(),g_team
))
3533 PSendSysMessage(LANG_COMMAND_GRAVEYARDLINKED
, g_id
,zoneId
);
3535 PSendSysMessage(LANG_COMMAND_GRAVEYARDALRLINKED
, g_id
,zoneId
);
3540 bool ChatHandler::HandleNearGraveCommand(const char* args
)
3544 size_t argslen
= strlen(args
);
3548 else if (strncmp((char*)args
,"horde",argslen
)==0)
3550 else if (strncmp((char*)args
,"alliance",argslen
)==0)
3555 Player
* player
= m_session
->GetPlayer();
3557 WorldSafeLocsEntry
const* graveyard
= objmgr
.GetClosestGraveYard(
3558 player
->GetPositionX(), player
->GetPositionY(), player
->GetPositionZ(),player
->GetMapId(),g_team
);
3562 uint32 g_id
= graveyard
->ID
;
3564 GraveYardData
const* data
= objmgr
.FindGraveYardData(g_id
,player
->GetZoneId());
3567 PSendSysMessage(LANG_COMMAND_GRAVEYARDERROR
,g_id
);
3568 SetSentErrorMessage(true);
3572 g_team
= data
->team
;
3574 std::string team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_NOTEAM
);
3577 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ANY
);
3578 else if(g_team
== HORDE
)
3579 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE
);
3580 else if(g_team
== ALLIANCE
)
3581 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE
);
3583 PSendSysMessage(LANG_COMMAND_GRAVEYARDNEAREST
, g_id
,team_name
.c_str(),player
->GetZoneId());
3587 std::string team_name
;
3590 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ANY
);
3591 else if(g_team
== HORDE
)
3592 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE
);
3593 else if(g_team
== ALLIANCE
)
3594 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE
);
3596 if(g_team
== ~uint32(0))
3597 PSendSysMessage(LANG_COMMAND_ZONENOGRAVEYARDS
, player
->GetZoneId());
3599 PSendSysMessage(LANG_COMMAND_ZONENOGRAFACTION
, player
->GetZoneId(),team_name
.c_str());
3606 bool ChatHandler::HandleNpcPlayEmoteCommand(const char* args
)
3608 uint32 emote
= atoi((char*)args
);
3610 Creature
* target
= getSelectedCreature();
3613 SendSysMessage(LANG_SELECT_CREATURE
);
3614 SetSentErrorMessage(true);
3618 target
->SetUInt32Value(UNIT_NPC_EMOTESTATE
,emote
);
3623 bool ChatHandler::HandleNpcInfoCommand(const char* /*args*/)
3625 Creature
* target
= getSelectedCreature();
3629 SendSysMessage(LANG_SELECT_CREATURE
);
3630 SetSentErrorMessage(true);
3634 uint32 faction
= target
->getFaction();
3635 uint32 npcflags
= target
->GetUInt32Value(UNIT_NPC_FLAGS
);
3636 uint32 displayid
= target
->GetDisplayId();
3637 uint32 nativeid
= target
->GetNativeDisplayId();
3638 uint32 Entry
= target
->GetEntry();
3639 CreatureInfo
const* cInfo
= target
->GetCreatureInfo();
3641 int32 curRespawnDelay
= target
->GetRespawnTimeEx()-time(NULL
);
3642 if(curRespawnDelay
< 0)
3643 curRespawnDelay
= 0;
3644 std::string curRespawnDelayStr
= secsToTimeString(curRespawnDelay
,true);
3645 std::string defRespawnDelayStr
= secsToTimeString(target
->GetRespawnDelay(),true);
3647 PSendSysMessage(LANG_NPCINFO_CHAR
, target
->GetDBTableGUIDLow(), faction
, npcflags
, Entry
, displayid
, nativeid
);
3648 PSendSysMessage(LANG_NPCINFO_LEVEL
, target
->getLevel());
3649 PSendSysMessage(LANG_NPCINFO_HEALTH
,target
->GetCreateHealth(), target
->GetMaxHealth(), target
->GetHealth());
3650 PSendSysMessage(LANG_NPCINFO_FLAGS
, target
->GetUInt32Value(UNIT_FIELD_FLAGS
), target
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
), target
->getFaction());
3651 PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES
, defRespawnDelayStr
.c_str(),curRespawnDelayStr
.c_str());
3652 PSendSysMessage(LANG_NPCINFO_LOOT
, cInfo
->lootid
,cInfo
->pickpocketLootId
,cInfo
->SkinLootId
);
3653 PSendSysMessage(LANG_NPCINFO_DUNGEON_ID
, target
->GetInstanceId());
3654 PSendSysMessage(LANG_NPCINFO_POSITION
,float(target
->GetPositionX()), float(target
->GetPositionY()), float(target
->GetPositionZ()));
3656 if ((npcflags
& UNIT_NPC_FLAG_VENDOR
) )
3658 SendSysMessage(LANG_NPCINFO_VENDOR
);
3660 if ((npcflags
& UNIT_NPC_FLAG_TRAINER
) )
3662 SendSysMessage(LANG_NPCINFO_TRAINER
);
3668 bool ChatHandler::HandleExploreCheatCommand(const char* args
)
3673 int flag
= atoi((char*)args
);
3675 Player
*chr
= getSelectedPlayer();
3678 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3679 SetSentErrorMessage(true);
3685 PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL
, chr
->GetName());
3686 if (needReportToTarget(chr
))
3687 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_EXPLORE_SET_ALL
,GetName());
3691 PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING
, chr
->GetName());
3692 if (needReportToTarget(chr
))
3693 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_EXPLORE_SET_NOTHING
,GetName());
3696 for (uint8 i
=0; i
<128; i
++)
3700 m_session
->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1
+i
,0xFFFFFFFF);
3704 m_session
->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1
+i
,0);
3711 bool ChatHandler::HandleHoverCommand(const char* args
)
3713 char* px
= strtok((char*)args
, " ");
3720 m_session
->GetPlayer()->SetHover(flag
);
3723 SendSysMessage(LANG_HOVER_ENABLED
);
3725 SendSysMessage(LANG_HOVER_DISABLED
);
3730 bool ChatHandler::HandleLevelUpCommand(const char* args
)
3732 char* px
= strtok((char*)args
, " ");
3733 char* py
= strtok((char*)NULL
, " ");
3735 // command format parsing
3736 char* pname
= (char*)NULL
;
3739 if(px
&& py
) // .levelup name level
3741 addlevel
= atoi(py
);
3744 else if(px
&& !py
) // .levelup name OR .levelup level
3746 if(isalpha(px
[0])) // .levelup name
3748 else // .levelup level
3749 addlevel
= atoi(px
);
3751 // else .levelup - nothing do for preparing
3755 uint64 chr_guid
= 0;
3759 if(pname
) // player by name
3762 if(!normalizePlayerName(name
))
3764 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3765 SetSentErrorMessage(true);
3769 chr
= objmgr
.GetPlayer(name
.c_str());
3770 if(!chr
) // not in game
3772 chr_guid
= objmgr
.GetPlayerGUIDByName(name
);
3775 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3776 SetSentErrorMessage(true);
3781 else // player by selection
3783 chr
= getSelectedPlayer();
3787 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3788 SetSentErrorMessage(true);
3792 name
= chr
->GetName();
3795 assert(chr
|| chr_guid
);
3797 int32 oldlevel
= chr
? chr
->getLevel() : Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL
,chr_guid
);
3798 int32 newlevel
= oldlevel
+ addlevel
;
3801 if(newlevel
> STRONG_MAX_LEVEL
) // hardcoded maximum level
3802 newlevel
= STRONG_MAX_LEVEL
;
3806 chr
->GiveLevel(newlevel
);
3807 chr
->InitTalentForLevel();
3808 chr
->SetUInt32Value(PLAYER_XP
,0);
3810 if(oldlevel
== newlevel
)
3811 ChatHandler(chr
).SendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET
);
3813 if(oldlevel
< newlevel
)
3814 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_LEVEL_UP
,newlevel
-oldlevel
);
3816 if(oldlevel
> newlevel
)
3817 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_LEVEL_DOWN
,newlevel
-oldlevel
);
3821 // update level and XP at level, all other will be updated at loading
3823 Player::LoadValuesArrayFromDB(values
,chr_guid
);
3824 Player::SetUInt32ValueInArray(values
,UNIT_FIELD_LEVEL
,newlevel
);
3825 Player::SetUInt32ValueInArray(values
,PLAYER_XP
,0);
3826 Player::SaveValuesArrayInDB(values
,chr_guid
);
3829 if(m_session
->GetPlayer() != chr
) // including chr==NULL
3830 PSendSysMessage(LANG_YOU_CHANGE_LVL
,name
.c_str(),newlevel
);
3834 bool ChatHandler::HandleShowAreaCommand(const char* args
)
3839 Player
*chr
= getSelectedPlayer();
3842 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3843 SetSentErrorMessage(true);
3847 int area
= GetAreaFlagByAreaID(atoi((char*)args
));
3848 int offset
= area
/ 32;
3849 uint32 val
= (uint32
)(1 << (area
% 32));
3851 if(area
<0 || offset
>= 128)
3853 SendSysMessage(LANG_BAD_VALUE
);
3854 SetSentErrorMessage(true);
3858 uint32 currFields
= chr
->GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
3859 chr
->SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
| val
));
3861 SendSysMessage(LANG_EXPLORE_AREA
);
3865 bool ChatHandler::HandleHideAreaCommand(const char* args
)
3870 Player
*chr
= getSelectedPlayer();
3873 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3874 SetSentErrorMessage(true);
3878 int area
= GetAreaFlagByAreaID(atoi((char*)args
));
3879 int offset
= area
/ 32;
3880 uint32 val
= (uint32
)(1 << (area
% 32));
3882 if(area
<0 || offset
>= 128)
3884 SendSysMessage(LANG_BAD_VALUE
);
3885 SetSentErrorMessage(true);
3889 uint32 currFields
= chr
->GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
3890 chr
->SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
^ val
));
3892 SendSysMessage(LANG_UNEXPLORE_AREA
);
3896 bool ChatHandler::HandleUpdate(const char* args
)
3904 char* pUpdateIndex
= strtok((char*)args
, " ");
3906 Unit
* chr
= getSelectedUnit();
3909 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3910 SetSentErrorMessage(true);
3918 updateIndex
= atoi(pUpdateIndex
);
3920 if(chr
->GetTypeId() == TYPEID_PLAYER
)
3922 if (updateIndex
>=PLAYER_END
) return true;
3926 if (updateIndex
>=UNIT_END
) return true;
3929 char* pvalue
= strtok(NULL
, " ");
3932 value
=chr
->GetUInt32Value(updateIndex
);
3934 PSendSysMessage(LANG_UPDATE
, chr
->GetGUIDLow(),updateIndex
,value
);
3940 PSendSysMessage(LANG_UPDATE_CHANGE
, chr
->GetGUIDLow(),updateIndex
,value
);
3942 chr
->SetUInt32Value(updateIndex
,value
);
3947 bool ChatHandler::HandleBankCommand(const char* /*args*/)
3949 m_session
->SendShowBank( m_session
->GetPlayer()->GetGUID() );
3954 bool ChatHandler::HandleChangeWeather(const char* args
)
3960 if (!sWorld
.getConfig(CONFIG_WEATHER
))
3962 SendSysMessage(LANG_WEATHER_DISABLED
);
3963 SetSentErrorMessage(true);
3967 //*Change the weather of a cell
3968 char* px
= strtok((char*)args
, " ");
3969 char* py
= strtok(NULL
, " ");
3974 uint32 type
= (uint32
)atoi(px
); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
3975 float grade
= (float)atof(py
); //0 to 1, sending -1 is instand good weather
3977 Player
*player
= m_session
->GetPlayer();
3978 uint32 zoneid
= player
->GetZoneId();
3980 Weather
* wth
= sWorld
.FindWeather(zoneid
);
3983 wth
= sWorld
.AddWeather(zoneid
);
3986 SendSysMessage(LANG_NO_WEATHER
);
3987 SetSentErrorMessage(true);
3991 wth
->SetWeather(WeatherType(type
), grade
);
3996 bool ChatHandler::HandleSetValue(const char* args
)
4001 char* px
= strtok((char*)args
, " ");
4002 char* py
= strtok(NULL
, " ");
4003 char* pz
= strtok(NULL
, " ");
4008 Unit
* target
= getSelectedUnit();
4011 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4012 SetSentErrorMessage(true);
4016 uint64 guid
= target
->GetGUID();
4018 uint32 Opcode
= (uint32
)atoi(px
);
4019 if(Opcode
>= target
->GetValuesCount())
4021 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, GUID_LOPART(guid
), target
->GetValuesCount());
4026 bool isint32
= true;
4028 isint32
= (bool)atoi(pz
);
4031 iValue
= (uint32
)atoi(py
);
4032 sLog
.outDebug(GetMangosString(LANG_SET_UINT
), GUID_LOPART(guid
), Opcode
, iValue
);
4033 target
->SetUInt32Value( Opcode
, iValue
);
4034 PSendSysMessage(LANG_SET_UINT_FIELD
, GUID_LOPART(guid
), Opcode
,iValue
);
4038 fValue
= (float)atof(py
);
4039 sLog
.outDebug(GetMangosString(LANG_SET_FLOAT
), GUID_LOPART(guid
), Opcode
, fValue
);
4040 target
->SetFloatValue( Opcode
, fValue
);
4041 PSendSysMessage(LANG_SET_FLOAT_FIELD
, GUID_LOPART(guid
), Opcode
,fValue
);
4047 bool ChatHandler::HandleGetValue(const char* args
)
4052 char* px
= strtok((char*)args
, " ");
4053 char* pz
= strtok(NULL
, " ");
4058 Unit
* target
= getSelectedUnit();
4061 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4062 SetSentErrorMessage(true);
4066 uint64 guid
= target
->GetGUID();
4068 uint32 Opcode
= (uint32
)atoi(px
);
4069 if(Opcode
>= target
->GetValuesCount())
4071 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, GUID_LOPART(guid
), target
->GetValuesCount());
4076 bool isint32
= true;
4078 isint32
= (bool)atoi(pz
);
4082 iValue
= target
->GetUInt32Value( Opcode
);
4083 sLog
.outDebug(GetMangosString(LANG_GET_UINT
), GUID_LOPART(guid
), Opcode
, iValue
);
4084 PSendSysMessage(LANG_GET_UINT_FIELD
, GUID_LOPART(guid
), Opcode
, iValue
);
4088 fValue
= target
->GetFloatValue( Opcode
);
4089 sLog
.outDebug(GetMangosString(LANG_GET_FLOAT
), GUID_LOPART(guid
), Opcode
, fValue
);
4090 PSendSysMessage(LANG_GET_FLOAT_FIELD
, GUID_LOPART(guid
), Opcode
, fValue
);
4096 bool ChatHandler::HandleSet32Bit(const char* args
)
4101 char* px
= strtok((char*)args
, " ");
4102 char* py
= strtok(NULL
, " ");
4107 uint32 Opcode
= (uint32
)atoi(px
);
4108 uint32 Value
= (uint32
)atoi(py
);
4109 if (Value
> 32) //uint32 = 32 bits
4112 sLog
.outDebug(GetMangosString(LANG_SET_32BIT
), Opcode
, Value
);
4114 m_session
->GetPlayer( )->SetUInt32Value( Opcode
, 2^Value
);
4116 PSendSysMessage(LANG_SET_32BIT_FIELD
, Opcode
,1);
4120 bool ChatHandler::HandleMod32Value(const char* args
)
4125 char* px
= strtok((char*)args
, " ");
4126 char* py
= strtok(NULL
, " ");
4131 uint32 Opcode
= (uint32
)atoi(px
);
4132 int Value
= atoi(py
);
4134 if(Opcode
>= m_session
->GetPlayer()->GetValuesCount())
4136 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, m_session
->GetPlayer()->GetGUIDLow(), m_session
->GetPlayer( )->GetValuesCount());
4140 sLog
.outDebug(GetMangosString(LANG_CHANGE_32BIT
), Opcode
, Value
);
4142 int CurrentValue
= (int)m_session
->GetPlayer( )->GetUInt32Value( Opcode
);
4144 CurrentValue
+= Value
;
4145 m_session
->GetPlayer( )->SetUInt32Value( Opcode
, (uint32
)CurrentValue
);
4147 PSendSysMessage(LANG_CHANGE_32BIT_FIELD
, Opcode
,CurrentValue
);
4152 bool ChatHandler::HandleAddTeleCommand(const char * args
)
4157 Player
*player
=m_session
->GetPlayer();
4161 std::string name
= args
;
4163 if(objmgr
.GetGameTele(name
))
4165 SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST
);
4166 SetSentErrorMessage(true);
4171 tele
.position_x
= player
->GetPositionX();
4172 tele
.position_y
= player
->GetPositionY();
4173 tele
.position_z
= player
->GetPositionZ();
4174 tele
.orientation
= player
->GetOrientation();
4175 tele
.mapId
= player
->GetMapId();
4178 if(objmgr
.AddGameTele(tele
))
4180 SendSysMessage(LANG_COMMAND_TP_ADDED
);
4184 SendSysMessage(LANG_COMMAND_TP_ADDEDERR
);
4185 SetSentErrorMessage(true);
4192 bool ChatHandler::HandleDelTeleCommand(const char * args
)
4197 std::string name
= args
;
4199 if(!objmgr
.DeleteGameTele(name
))
4201 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
4202 SetSentErrorMessage(true);
4206 SendSysMessage(LANG_COMMAND_TP_DELETED
);
4210 bool ChatHandler::HandleListAurasCommand (const char * /*args*/)
4212 Unit
*unit
= getSelectedUnit();
4215 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4216 SetSentErrorMessage(true);
4220 char const* talentStr
= GetMangosString(LANG_TALENT
);
4221 char const* passiveStr
= GetMangosString(LANG_PASSIVE
);
4223 Unit::AuraMap
const& uAuras
= unit
->GetAuras();
4224 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS
, uAuras
.size());
4225 for (Unit::AuraMap::const_iterator itr
= uAuras
.begin(); itr
!= uAuras
.end(); ++itr
)
4227 bool talent
= GetTalentSpellCost(itr
->second
->GetId()) > 0;
4228 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL
, itr
->second
->GetId(), itr
->second
->GetEffIndex(),
4229 itr
->second
->GetModifier()->m_auraname
, itr
->second
->GetAuraDuration(), itr
->second
->GetAuraMaxDuration(),
4230 itr
->second
->GetSpellProto()->SpellName
[m_session
->GetSessionDbcLocale()],
4231 (itr
->second
->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4232 IS_PLAYER_GUID(itr
->second
->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr
->second
->GetCasterGUID()));
4234 for (int i
= 0; i
< TOTAL_AURAS
; i
++)
4236 Unit::AuraList
const& uAuraList
= unit
->GetAurasByType(AuraType(i
));
4237 if (uAuraList
.empty()) continue;
4238 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE
, uAuraList
.size(), i
);
4239 for (Unit::AuraList::const_iterator itr
= uAuraList
.begin(); itr
!= uAuraList
.end(); ++itr
)
4241 bool talent
= GetTalentSpellCost((*itr
)->GetId()) > 0;
4242 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE
, (*itr
)->GetId(), (*itr
)->GetEffIndex(),
4243 (*itr
)->GetSpellProto()->SpellName
[m_session
->GetSessionDbcLocale()],((*itr
)->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4244 IS_PLAYER_GUID((*itr
)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr
)->GetCasterGUID()));
4250 bool ChatHandler::HandleResetHonorCommand (const char * args
)
4252 char* pName
= strtok((char*)args
, "");
4253 Player
*player
= NULL
;
4256 std::string name
= pName
;
4257 if(!normalizePlayerName(name
))
4259 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4260 SetSentErrorMessage(true);
4264 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4265 player
= objmgr
.GetPlayer(guid
);
4268 player
= getSelectedPlayer();
4272 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4276 player
->SetUInt32Value(PLAYER_FIELD_KILLS
, 0);
4277 player
->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS
, 0);
4278 player
->SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY
, 0);
4279 player
->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION
, 0);
4280 player
->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION
, 0);
4285 static bool HandleResetStatsOrLevelHelper(Player
* player
)
4287 PlayerInfo
const *info
= objmgr
.GetPlayerInfo(player
->getRace(), player
->getClass());
4288 if(!info
) return false;
4290 ChrClassesEntry
const* cEntry
= sChrClassesStore
.LookupEntry(player
->getClass());
4293 sLog
.outError("Class %u not found in DBC (Wrong DBC files?)",player
->getClass());
4297 uint8 powertype
= cEntry
->powerType
;
4300 if(powertype
== POWER_RAGE
)
4301 unitfield
= 0x1100EE00;
4302 else if(powertype
== POWER_ENERGY
)
4303 unitfield
= 0x00000000;
4304 else if(powertype
== POWER_MANA
)
4305 unitfield
= 0x0000EE00;
4308 sLog
.outError("Invalid default powertype %u for player (class %u)",powertype
,player
->getClass());
4312 // reset m_form if no aura
4313 if(!player
->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT
))
4314 player
->m_form
= FORM_NONE
;
4316 player
->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS
, DEFAULT_WORLD_OBJECT_SIZE
);
4317 player
->SetFloatValue(UNIT_FIELD_COMBATREACH
, 1.5f
);
4319 player
->setFactionForRace(player
->getRace());
4321 player
->SetUInt32Value(UNIT_FIELD_BYTES_0
, ( ( player
->getRace() ) | ( player
->getClass() << 8 ) | ( player
->getGender() << 16 ) | ( powertype
<< 24 ) ) );
4323 // reset only if player not in some form;
4324 if(player
->m_form
==FORM_NONE
)
4326 switch(player
->getGender())
4329 player
->SetDisplayId(info
->displayId_f
);
4330 player
->SetNativeDisplayId(info
->displayId_f
);
4333 player
->SetDisplayId(info
->displayId_m
);
4334 player
->SetNativeDisplayId(info
->displayId_m
);
4341 // set UNIT_FIELD_BYTES_1 to init state but preserve m_form value
4342 player
->SetUInt32Value(UNIT_FIELD_BYTES_1
, unitfield
);
4343 player
->SetByteValue(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_PVP
);
4344 player
->SetByteValue(UNIT_FIELD_BYTES_2
, 3, player
->m_form
);
4346 player
->SetUInt32Value(UNIT_FIELD_FLAGS
, UNIT_FLAG_PVP_ATTACKABLE
);
4348 //-1 is default value
4349 player
->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX
, uint32(-1));
4351 //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000 );
4355 bool ChatHandler::HandleResetLevelCommand(const char * args
)
4357 char* pName
= strtok((char*)args
, "");
4358 Player
*player
= NULL
;
4361 std::string name
= pName
;
4362 if(!normalizePlayerName(name
))
4364 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4365 SetSentErrorMessage(true);
4369 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4370 player
= objmgr
.GetPlayer(guid
);
4373 player
= getSelectedPlayer();
4377 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4378 SetSentErrorMessage(true);
4382 if(!HandleResetStatsOrLevelHelper(player
))
4385 player
->SetLevel(1);
4386 player
->InitStatsForLevel(true);
4387 player
->InitTaxiNodesForLevel();
4388 player
->InitGlyphsForLevel();
4389 player
->InitTalentForLevel();
4390 player
->SetUInt32Value(PLAYER_XP
,0);
4392 // reset level to summoned pet
4393 Pet
* pet
= player
->GetPet();
4394 if(pet
&& pet
->getPetType()==SUMMON_PET
)
4395 pet
->InitStatsForLevel(1);
4400 bool ChatHandler::HandleResetStatsCommand(const char * args
)
4402 char* pName
= strtok((char*)args
, "");
4403 Player
*player
= NULL
;
4406 std::string name
= pName
;
4407 if(!normalizePlayerName(name
))
4409 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4410 SetSentErrorMessage(true);
4414 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4415 player
= objmgr
.GetPlayer(guid
);
4418 player
= getSelectedPlayer();
4422 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4423 SetSentErrorMessage(true);
4427 if(!HandleResetStatsOrLevelHelper(player
))
4430 player
->InitStatsForLevel(true);
4431 player
->InitTaxiNodesForLevel();
4432 player
->InitGlyphsForLevel();
4433 player
->InitTalentForLevel();
4438 bool ChatHandler::HandleResetSpellsCommand(const char * args
)
4440 char* pName
= strtok((char*)args
, "");
4441 Player
*player
= NULL
;
4442 uint64 playerGUID
= 0;
4445 std::string name
= pName
;
4447 if(!normalizePlayerName(name
))
4449 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4450 SetSentErrorMessage(true);
4454 player
= objmgr
.GetPlayer(name
.c_str());
4456 playerGUID
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4459 player
= getSelectedPlayer();
4461 if(!player
&& !playerGUID
)
4463 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4464 SetSentErrorMessage(true);
4470 player
->resetSpells();
4472 ChatHandler(player
).SendSysMessage(LANG_RESET_SPELLS
);
4474 if(m_session
->GetPlayer()!=player
)
4475 PSendSysMessage(LANG_RESET_SPELLS_ONLINE
,player
->GetName());
4479 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS
), GUID_LOPART(playerGUID
));
4480 PSendSysMessage(LANG_RESET_SPELLS_OFFLINE
,pName
);
4486 bool ChatHandler::HandleResetTalentsCommand(const char * args
)
4488 char* pName
= strtok((char*)args
, "");
4489 Player
*player
= NULL
;
4490 uint64 playerGUID
= 0;
4493 std::string name
= pName
;
4494 if(!normalizePlayerName(name
))
4496 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4497 SetSentErrorMessage(true);
4501 player
= objmgr
.GetPlayer(name
.c_str());
4503 playerGUID
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4506 player
= getSelectedPlayer();
4508 if(!player
&& !playerGUID
)
4510 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4511 SetSentErrorMessage(true);
4517 player
->resetTalents(true);
4519 ChatHandler(player
).SendSysMessage(LANG_RESET_TALENTS
);
4521 if(m_session
->GetPlayer()!=player
)
4522 PSendSysMessage(LANG_RESET_TALENTS_ONLINE
,player
->GetName());
4526 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_TALENTS
), GUID_LOPART(playerGUID
) );
4527 PSendSysMessage(LANG_RESET_TALENTS_OFFLINE
,pName
);
4533 bool ChatHandler::HandleResetAllCommand(const char * args
)
4538 std::string casename
= args
;
4540 AtLoginFlags atLogin
;
4542 // Command specially created as single command to prevent using short case names
4543 if(casename
=="spells")
4545 atLogin
= AT_LOGIN_RESET_SPELLS
;
4546 sWorld
.SendWorldText(LANG_RESETALL_SPELLS
);
4548 else if(casename
=="talents")
4550 atLogin
= AT_LOGIN_RESET_TALENTS
;
4551 sWorld
.SendWorldText(LANG_RESETALL_TALENTS
);
4555 PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE
,args
);
4556 SetSentErrorMessage(true);
4560 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE (at_login & '%u') = '0'",atLogin
,atLogin
);
4561 HashMapHolder
<Player
>::MapType
const& plist
= ObjectAccessor::Instance().GetPlayers();
4562 for(HashMapHolder
<Player
>::MapType::const_iterator itr
= plist
.begin(); itr
!= plist
.end(); ++itr
)
4563 itr
->second
->SetAtLoginFlag(atLogin
);
4568 bool ChatHandler::HandleServerShutDownCancelCommand(const char* args
)
4570 sWorld
.ShutdownCancel();
4574 bool ChatHandler::HandleServerShutDownCommand(const char* args
)
4579 char* time_str
= strtok ((char*) args
, " ");
4580 char* exitcode_str
= strtok (NULL
, "");
4582 int32 time
= atoi (time_str
);
4584 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4585 if(time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0') || time
< 0)
4590 int32 exitcode
= atoi (exitcode_str
);
4592 // Handle atoi() errors
4593 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4596 // Exit code should be in range of 0-125, 126-255 is used
4597 // in many shells for their own return codes and code > 255
4598 // is not supported in many others
4599 if (exitcode
< 0 || exitcode
> 125)
4602 sWorld
.ShutdownServ (time
, 0, exitcode
);
4605 sWorld
.ShutdownServ(time
,0,SHUTDOWN_EXIT_CODE
);
4609 bool ChatHandler::HandleServerRestartCommand(const char* args
)
4614 char* time_str
= strtok ((char*) args
, " ");
4615 char* exitcode_str
= strtok (NULL
, "");
4617 int32 time
= atoi (time_str
);
4619 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4620 if(time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0') || time
< 0)
4625 int32 exitcode
= atoi (exitcode_str
);
4627 // Handle atoi() errors
4628 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4631 // Exit code should be in range of 0-125, 126-255 is used
4632 // in many shells for their own return codes and code > 255
4633 // is not supported in many others
4634 if (exitcode
< 0 || exitcode
> 125)
4637 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_RESTART
, exitcode
);
4640 sWorld
.ShutdownServ(time
, SHUTDOWN_MASK_RESTART
, RESTART_EXIT_CODE
);
4644 bool ChatHandler::HandleServerIdleRestartCommand(const char* args
)
4649 char* time_str
= strtok ((char*) args
, " ");
4650 char* exitcode_str
= strtok (NULL
, "");
4652 int32 time
= atoi (time_str
);
4654 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4655 if(time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0') || time
< 0)
4660 int32 exitcode
= atoi (exitcode_str
);
4662 // Handle atoi() errors
4663 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4666 // Exit code should be in range of 0-125, 126-255 is used
4667 // in many shells for their own return codes and code > 255
4668 // is not supported in many others
4669 if (exitcode
< 0 || exitcode
> 125)
4672 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_RESTART
|SHUTDOWN_MASK_IDLE
, exitcode
);
4675 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_RESTART
|SHUTDOWN_MASK_IDLE
,RESTART_EXIT_CODE
);
4679 bool ChatHandler::HandleServerIdleShutDownCommand(const char* args
)
4684 char* time_str
= strtok ((char*) args
, " ");
4685 char* exitcode_str
= strtok (NULL
, "");
4687 int32 time
= atoi (time_str
);
4689 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4690 if(time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0') || time
< 0)
4695 int32 exitcode
= atoi (exitcode_str
);
4697 // Handle atoi() errors
4698 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4701 // Exit code should be in range of 0-125, 126-255 is used
4702 // in many shells for their own return codes and code > 255
4703 // is not supported in many others
4704 if (exitcode
< 0 || exitcode
> 125)
4707 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_IDLE
, exitcode
);
4710 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_IDLE
,SHUTDOWN_EXIT_CODE
);
4714 bool ChatHandler::HandleAddQuest(const char* args
)
4716 Player
* player
= getSelectedPlayer();
4719 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4720 SetSentErrorMessage(true);
4724 // .addquest #entry'
4725 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4726 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4730 uint32 entry
= atol(cId
);
4732 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
4736 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
,entry
);
4737 SetSentErrorMessage(true);
4741 // check item starting quest (it can work incorrectly if added without item in inventory)
4742 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
4744 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
4748 if (pProto
->StartQuest
== entry
)
4750 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM
, entry
, pProto
->ItemId
);
4751 SetSentErrorMessage(true);
4756 // ok, normal (creature/GO starting) quest
4757 if( player
->CanAddQuest( pQuest
, true ) )
4759 player
->AddQuest( pQuest
, NULL
);
4761 if ( player
->CanCompleteQuest( entry
) )
4762 player
->CompleteQuest( entry
);
4768 bool ChatHandler::HandleRemoveQuest(const char* args
)
4770 Player
* player
= getSelectedPlayer();
4773 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4774 SetSentErrorMessage(true);
4778 // .removequest #entry'
4779 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4780 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4784 uint32 entry
= atol(cId
);
4786 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
4790 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
4791 SetSentErrorMessage(true);
4795 // remove all quest entries for 'entry' from quest log
4796 for(uint8 slot
= 0; slot
< MAX_QUEST_LOG_SIZE
; ++slot
)
4798 uint32 quest
= player
->GetQuestSlotQuestId(slot
);
4801 player
->SetQuestSlot(slot
,0);
4803 // we ignore unequippable quest items in this case, its' still be equipped
4804 player
->TakeQuestSourceItem( quest
, false );
4808 // set quest status to not started (will updated in DB at next save)
4809 player
->SetQuestStatus( entry
, QUEST_STATUS_NONE
);
4811 // reset rewarded for restart repeatable quest
4812 player
->getQuestStatusMap()[entry
].m_rewarded
= false;
4814 SendSysMessage(LANG_COMMAND_QUEST_REMOVED
);
4818 bool ChatHandler::HandleCompleteQuest(const char* args
)
4820 Player
* player
= getSelectedPlayer();
4823 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4824 SetSentErrorMessage(true);
4828 // .quest complete #entry
4829 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4830 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4834 uint32 entry
= atol(cId
);
4836 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
4838 // If player doesn't have the quest
4839 if(!pQuest
|| player
->GetQuestStatus(entry
) == QUEST_STATUS_NONE
)
4841 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
4842 SetSentErrorMessage(true);
4846 // Add quest items for quests that require items
4847 for(uint8 x
= 0; x
< QUEST_OBJECTIVES_COUNT
; ++x
)
4849 uint32 id
= pQuest
->ReqItemId
[x
];
4850 uint32 count
= pQuest
->ReqItemCount
[x
];
4854 uint32 curItemCount
= player
->GetItemCount(id
,true);
4856 ItemPosCountVec dest
;
4857 uint8 msg
= player
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, id
, count
-curItemCount
);
4858 if( msg
== EQUIP_ERR_OK
)
4860 Item
* item
= player
->StoreNewItem( dest
, id
, true);
4861 player
->SendNewItem(item
,count
-curItemCount
,true,false);
4865 // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
4866 for(uint8 i
= 0; i
< QUEST_OBJECTIVES_COUNT
; i
++)
4868 uint32 creature
= pQuest
->ReqCreatureOrGOId
[i
];
4869 uint32 creaturecount
= pQuest
->ReqCreatureOrGOCount
[i
];
4871 if(uint32 spell_id
= pQuest
->ReqSpell
[i
])
4873 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4874 player
->CastedCreatureOrGO(creature
,0,spell_id
);
4876 else if(creature
> 0)
4878 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4879 player
->KilledMonster(creature
,0);
4881 else if(creature
< 0)
4883 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4884 player
->CastedCreatureOrGO(creature
,0,0);
4888 // If the quest requires reputation to complete
4889 if(uint32 repFaction
= pQuest
->GetRepObjectiveFaction())
4891 uint32 repValue
= pQuest
->GetRepObjectiveValue();
4892 uint32 curRep
= player
->GetReputation(repFaction
);
4893 if(curRep
< repValue
)
4895 FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry(repFaction
);
4896 player
->SetFactionReputation(factionEntry
,repValue
);
4900 // If the quest requires money
4901 int32 ReqOrRewMoney
= pQuest
->GetRewOrReqMoney();
4902 if(ReqOrRewMoney
< 0)
4903 player
->ModifyMoney(-ReqOrRewMoney
);
4905 player
->CompleteQuest(entry
);
4909 bool ChatHandler::HandleBanAccountCommand(const char* args
)
4911 return HandleBanHelper(BAN_ACCOUNT
,args
);
4914 bool ChatHandler::HandleBanCharacterCommand(const char* args
)
4916 return HandleBanHelper(BAN_CHARACTER
,args
);
4919 bool ChatHandler::HandleBanIPCommand(const char* args
)
4921 return HandleBanHelper(BAN_IP
,args
);
4924 bool ChatHandler::HandleBanHelper(BanMode mode
, const char* args
)
4929 char* cnameOrIP
= strtok ((char*)args
, " ");
4933 std::string nameOrIP
= cnameOrIP
;
4935 char* duration
= strtok (NULL
," ");
4936 if(!duration
|| !atoi(duration
))
4939 char* reason
= strtok (NULL
,"");
4946 if(!AccountMgr::normilizeString(nameOrIP
))
4948 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
4949 SetSentErrorMessage(true);
4954 if(!normalizePlayerName(nameOrIP
))
4956 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4957 SetSentErrorMessage(true);
4962 if(!IsIPAddress(nameOrIP
.c_str()))
4967 switch(sWorld
.BanAccount(mode
, nameOrIP
, duration
, reason
,m_session
? m_session
->GetPlayerName() : ""))
4970 if(atoi(duration
)>0)
4971 PSendSysMessage(LANG_BAN_YOUBANNED
,nameOrIP
.c_str(),secsToTimeString(TimeStringToSecs(duration
),true).c_str(),reason
);
4973 PSendSysMessage(LANG_BAN_YOUPERMBANNED
,nameOrIP
.c_str(),reason
);
4975 case BAN_SYNTAX_ERROR
:
4981 PSendSysMessage(LANG_BAN_NOTFOUND
,"account",nameOrIP
.c_str());
4984 PSendSysMessage(LANG_BAN_NOTFOUND
,"character",nameOrIP
.c_str());
4987 PSendSysMessage(LANG_BAN_NOTFOUND
,"ip",nameOrIP
.c_str());
4990 SetSentErrorMessage(true);
4997 bool ChatHandler::HandleUnBanAccountCommand(const char* args
)
4999 return HandleUnBanHelper(BAN_ACCOUNT
,args
);
5002 bool ChatHandler::HandleUnBanCharacterCommand(const char* args
)
5004 return HandleUnBanHelper(BAN_CHARACTER
,args
);
5007 bool ChatHandler::HandleUnBanIPCommand(const char* args
)
5009 return HandleUnBanHelper(BAN_IP
,args
);
5012 bool ChatHandler::HandleUnBanHelper(BanMode mode
, const char* args
)
5017 char* cnameOrIP
= strtok ((char*)args
, " ");
5021 std::string nameOrIP
= cnameOrIP
;
5026 if(!AccountMgr::normilizeString(nameOrIP
))
5028 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
5029 SetSentErrorMessage(true);
5034 if(!normalizePlayerName(nameOrIP
))
5036 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5037 SetSentErrorMessage(true);
5042 if(!IsIPAddress(nameOrIP
.c_str()))
5047 if(sWorld
.RemoveBanAccount(mode
,nameOrIP
))
5048 PSendSysMessage(LANG_UNBAN_UNBANNED
,nameOrIP
.c_str());
5050 PSendSysMessage(LANG_UNBAN_ERROR
,nameOrIP
.c_str());
5055 bool ChatHandler::HandleBanInfoAccountCommand(const char* args
)
5060 char* cname
= strtok((char*)args
, "");
5064 std::string account_name
= cname
;
5065 if(!AccountMgr::normilizeString(account_name
))
5067 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5068 SetSentErrorMessage(true);
5072 uint32 accountid
= accmgr
.GetId(account_name
);
5075 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5079 return HandleBanInfoHelper(accountid
,account_name
.c_str());
5082 bool ChatHandler::HandleBanInfoCharacterCommand(const char* args
)
5087 char* cname
= strtok ((char*)args
, "");
5091 std::string name
= cname
;
5092 if(!normalizePlayerName(name
))
5094 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5095 SetSentErrorMessage(true);
5099 uint32 accountid
= objmgr
.GetPlayerAccountIdByPlayerName(name
);
5102 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5103 SetSentErrorMessage(true);
5107 std::string accountname
;
5108 if(!accmgr
.GetName(accountid
,accountname
))
5110 PSendSysMessage(LANG_BANINFO_NOCHARACTER
);
5114 return HandleBanInfoHelper(accountid
,accountname
.c_str());
5117 bool ChatHandler::HandleBanInfoHelper(uint32 accountid
, char const* accountname
)
5119 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
);
5122 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN
, accountname
);
5126 PSendSysMessage(LANG_BANINFO_BANHISTORY
,accountname
);
5129 Field
* fields
= result
->Fetch();
5131 time_t unbandate
= time_t(fields
[3].GetUInt64());
5132 bool active
= false;
5133 if(fields
[2].GetBool() && (fields
[1].GetUInt64() == (uint64
)0 ||unbandate
>= time(NULL
)) )
5135 bool permanent
= (fields
[1].GetUInt64() == (uint64
)0);
5136 std::string bantime
= permanent
?GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[1].GetUInt64(), true);
5137 PSendSysMessage(LANG_BANINFO_HISTORYENTRY
,
5138 fields
[0].GetString(), bantime
.c_str(), active
? GetMangosString(LANG_BANINFO_YES
):GetMangosString(LANG_BANINFO_NO
), fields
[4].GetString(), fields
[5].GetString());
5139 }while (result
->NextRow());
5145 bool ChatHandler::HandleBanInfoIPCommand(const char* args
)
5150 char* cIP
= strtok ((char*)args
, "");
5154 if (!IsIPAddress(cIP
))
5157 std::string IP
= cIP
;
5159 loginDatabase
.escape_string(IP
);
5160 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());
5163 PSendSysMessage(LANG_BANINFO_NOIP
);
5167 Field
*fields
= result
->Fetch();
5168 bool permanent
= !fields
[6].GetUInt64();
5169 PSendSysMessage(LANG_BANINFO_IPENTRY
,
5170 fields
[0].GetString(), fields
[1].GetString(), permanent
? GetMangosString(LANG_BANINFO_NEVER
):fields
[2].GetString(),
5171 permanent
? GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[3].GetUInt64(), true).c_str(), fields
[4].GetString(), fields
[5].GetString());
5176 bool ChatHandler::HandleBanListCharacterCommand(const char* args
)
5178 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5180 char* cFilter
= strtok ((char*)args
, " ");
5184 std::string filter
= cFilter
;
5185 loginDatabase
.escape_string(filter
);
5186 QueryResult
* result
= CharacterDatabase
.PQuery("SELECT account FROM characters WHERE name "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'"),filter
.c_str());
5189 PSendSysMessage(LANG_BANLIST_NOCHARACTER
);
5193 return HandleBanListHelper(result
);
5196 bool ChatHandler::HandleBanListAccountCommand(const char* args
)
5198 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5200 char* cFilter
= strtok((char*)args
, " ");
5201 std::string filter
= cFilter
? cFilter
: "";
5202 loginDatabase
.escape_string(filter
);
5204 QueryResult
* result
;
5208 result
= loginDatabase
.Query("SELECT account.id, username FROM account, account_banned"
5209 " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
5213 result
= loginDatabase
.PQuery("SELECT account.id, username FROM account, account_banned"
5214 " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
5220 PSendSysMessage(LANG_BANLIST_NOACCOUNT
);
5224 return HandleBanListHelper(result
);
5227 bool ChatHandler::HandleBanListHelper(QueryResult
* result
)
5229 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT
);
5231 // Chat short output
5236 Field
* fields
= result
->Fetch();
5237 uint32 accountid
= fields
[0].GetUInt32();
5239 QueryResult
* banresult
= loginDatabase
.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid
);
5242 Field
* fields2
= banresult
->Fetch();
5243 PSendSysMessage("%s",fields2
[0].GetString());
5246 } while (result
->NextRow());
5248 // Console wide output
5251 SendSysMessage(LANG_BANLIST_ACCOUNTS
);
5252 SendSysMessage("===============================================================================");
5253 SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER
);
5256 SendSysMessage("-------------------------------------------------------------------------------");
5257 Field
*fields
= result
->Fetch();
5258 uint32 account_id
= fields
[0].GetUInt32 ();
5260 std::string account_name
;
5262 // "account" case, name can be get in same query
5263 if(result
->GetFieldCount() > 1)
5264 account_name
= fields
[1].GetCppString();
5265 // "character" case, name need extract from another DB
5267 accmgr
.GetName (account_id
,account_name
);
5269 // No SQL injection. id is uint32.
5270 QueryResult
*banInfo
= loginDatabase
.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id
);
5273 Field
*fields2
= banInfo
->Fetch();
5276 time_t t_ban
= fields2
[0].GetUInt64();
5277 tm
* aTm_ban
= localtime(&t_ban
);
5279 if (fields2
[0].GetUInt64() == fields2
[1].GetUInt64())
5281 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5282 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
,
5283 fields2
[2].GetString(),fields2
[3].GetString());
5287 time_t t_unban
= fields2
[1].GetUInt64();
5288 tm
* aTm_unban
= localtime(&t_unban
);
5289 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5290 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
,
5291 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5292 fields2
[2].GetString(),fields2
[3].GetString());
5294 }while ( banInfo
->NextRow() );
5297 }while( result
->NextRow() );
5298 SendSysMessage("===============================================================================");
5305 bool ChatHandler::HandleBanListIPCommand(const char* args
)
5307 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5309 char* cFilter
= strtok((char*)args
, " ");
5310 std::string filter
= cFilter
? cFilter
: "";
5311 loginDatabase
.escape_string(filter
);
5313 QueryResult
* result
;
5317 result
= loginDatabase
.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5318 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
5319 " ORDER BY unbandate" );
5323 result
= loginDatabase
.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5324 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")
5325 " ORDER BY unbandate",filter
.c_str() );
5330 PSendSysMessage(LANG_BANLIST_NOIP
);
5334 PSendSysMessage(LANG_BANLIST_MATCHINGIP
);
5335 // Chat short output
5340 Field
* fields
= result
->Fetch();
5341 PSendSysMessage("%s",fields
[0].GetString());
5342 } while (result
->NextRow());
5344 // Console wide output
5347 SendSysMessage(LANG_BANLIST_IPS
);
5348 SendSysMessage("===============================================================================");
5349 SendSysMessage(LANG_BANLIST_IPS_HEADER
);
5352 SendSysMessage("-------------------------------------------------------------------------------");
5353 Field
*fields
= result
->Fetch();
5354 time_t t_ban
= fields
[1].GetUInt64();
5355 tm
* aTm_ban
= localtime(&t_ban
);
5356 if ( fields
[1].GetUInt64() == fields
[2].GetUInt64() )
5358 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5359 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
,
5360 fields
[3].GetString(), fields
[4].GetString());
5364 time_t t_unban
= fields
[2].GetUInt64();
5365 tm
* aTm_unban
= localtime(&t_unban
);
5366 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5367 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
,
5368 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5369 fields
[3].GetString(), fields
[4].GetString());
5371 }while( result
->NextRow() );
5372 SendSysMessage("===============================================================================");
5379 bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
5381 Player
* pl
= m_session
->GetPlayer();
5383 // accept only explicitly selected target (not implicitly self targeting case)
5384 Unit
* target
= getSelectedUnit();
5385 if(pl
->GetSelection() && target
)
5387 if(target
->GetTypeId()!=TYPEID_UNIT
)
5389 SendSysMessage(LANG_SELECT_CREATURE
);
5390 SetSentErrorMessage(true);
5394 if(target
->isDead())
5395 ((Creature
*)target
)->Respawn();
5399 CellPair
p(MaNGOS::ComputeCellPair(pl
->GetPositionX(), pl
->GetPositionY()));
5401 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
5404 MaNGOS::RespawnDo u_do
;
5405 MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
> worker(u_do
);
5407 TypeContainerVisitor
<MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
>, GridTypeMapContainer
> obj_worker(worker
);
5408 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
5409 cell_lock
->Visit(cell_lock
, obj_worker
, *pl
->GetMap());
5414 bool ChatHandler::HandleFlyModeCommand(const char* args
)
5419 Unit
*unit
= getSelectedUnit();
5420 if (!unit
|| (unit
->GetTypeId() != TYPEID_PLAYER
))
5421 unit
= m_session
->GetPlayer();
5423 WorldPacket
data(12);
5424 if (strncmp(args
, "on", 3) == 0)
5425 data
.SetOpcode(SMSG_MOVE_SET_CAN_FLY
);
5426 else if (strncmp(args
, "off", 4) == 0)
5427 data
.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY
);
5430 SendSysMessage(LANG_USE_BOL
);
5433 data
.append(unit
->GetPackGUID());
5434 data
<< uint32(0); // unknown
5435 unit
->SendMessageToSet(&data
, true);
5436 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS
, unit
->GetName(), args
);
5440 bool ChatHandler::HandleLoadPDumpCommand(const char *args
)
5445 char * file
= strtok((char*)args
, " ");
5449 char * account
= strtok(NULL
, " ");
5453 std::string account_name
= account
;
5454 if(!AccountMgr::normilizeString(account_name
))
5456 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5457 SetSentErrorMessage(true);
5461 uint32 account_id
= accmgr
.GetId(account_name
);
5464 account_id
= atoi(account
); // use original string
5467 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5468 SetSentErrorMessage(true);
5473 if(!accmgr
.GetName(account_id
,account_name
))
5475 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5476 SetSentErrorMessage(true);
5480 char* guid_str
= NULL
;
5481 char* name_str
= strtok(NULL
, " ");
5487 // normalize the name if specified and check if it exists
5488 if(!normalizePlayerName(name
))
5490 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5491 SetSentErrorMessage(true);
5495 if(!ObjectMgr::IsValidName(name
,true))
5497 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5498 SetSentErrorMessage(true);
5502 guid_str
= strtok(NULL
, " ");
5509 guid
= atoi(guid_str
);
5512 PSendSysMessage(LANG_INVALID_CHARACTER_GUID
);
5513 SetSentErrorMessage(true);
5517 if(objmgr
.GetPlayerAccountIdByGUID(guid
))
5519 PSendSysMessage(LANG_CHARACTER_GUID_IN_USE
,guid
);
5520 SetSentErrorMessage(true);
5525 switch(PlayerDumpReader().LoadDump(file
, account_id
, name
, guid
))
5528 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS
);
5530 case DUMP_FILE_OPEN_ERROR
:
5531 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
5532 SetSentErrorMessage(true);
5534 case DUMP_FILE_BROKEN
:
5535 PSendSysMessage(LANG_DUMP_BROKEN
,file
);
5536 SetSentErrorMessage(true);
5538 case DUMP_TOO_MANY_CHARS
:
5539 PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL
,account_name
.c_str(),account_id
);
5540 SetSentErrorMessage(true);
5543 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED
);
5544 SetSentErrorMessage(true);
5551 bool ChatHandler::HandleNpcChangeEntryCommand(const char *args
)
5556 uint32 newEntryNum
= atoi(args
);
5560 Unit
* unit
= getSelectedUnit();
5561 if(!unit
|| unit
->GetTypeId() != TYPEID_UNIT
)
5563 SendSysMessage(LANG_SELECT_CREATURE
);
5564 SetSentErrorMessage(true);
5567 Creature
* creature
= (Creature
*)unit
;
5568 if(creature
->UpdateEntry(newEntryNum
))
5569 SendSysMessage(LANG_DONE
);
5571 SendSysMessage(LANG_ERROR
);
5575 bool ChatHandler::HandleWritePDumpCommand(const char *args
)
5580 char* file
= strtok((char*)args
, " ");
5581 char* p2
= strtok(NULL
, " ");
5587 // character name can't start from number
5588 if (isNumeric(p2
[0]))
5592 std::string name
= p2
;
5594 if (!normalizePlayerName (name
))
5596 SendSysMessage (LANG_PLAYER_NOT_FOUND
);
5597 SetSentErrorMessage (true);
5601 guid
= objmgr
.GetPlayerGUIDByName(name
);
5604 if(!objmgr
.GetPlayerAccountIdByGUID(guid
))
5606 PSendSysMessage(LANG_PLAYER_NOT_FOUND
);
5607 SetSentErrorMessage(true);
5611 switch(PlayerDumpWriter().WriteDump(file
, guid
))
5614 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS
);
5616 case DUMP_FILE_OPEN_ERROR
:
5617 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
5618 SetSentErrorMessage(true);
5621 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED
);
5622 SetSentErrorMessage(true);
5629 bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
5631 Unit
* unit
= getSelectedUnit();
5634 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5635 SetSentErrorMessage(true);
5639 PSendSysMessage(LANG_MOVEGENS_LIST
,(unit
->GetTypeId()==TYPEID_PLAYER
? "Player" : "Creature" ),unit
->GetGUIDLow());
5641 MotionMaster
* mm
= unit
->GetMotionMaster();
5642 for(MotionMaster::const_iterator itr
= mm
->begin(); itr
!= mm
->end(); ++itr
)
5644 switch((*itr
)->GetMovementGeneratorType())
5646 case IDLE_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_IDLE
); break;
5647 case RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_RANDOM
); break;
5648 case WAYPOINT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_WAYPOINT
); break;
5649 case ANIMAL_RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_ANIMAL_RANDOM
); break;
5650 case CONFUSED_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_CONFUSED
); break;
5651 case TARGETED_MOTION_TYPE
:
5653 if(unit
->GetTypeId()==TYPEID_PLAYER
)
5655 TargetedMovementGenerator
<Player
> const* mgen
= static_cast<TargetedMovementGenerator
<Player
> const*>(*itr
);
5656 Unit
* target
= mgen
->GetTarget();
5658 PSendSysMessage(LANG_MOVEGENS_TARGETED_PLAYER
,target
->GetName(),target
->GetGUIDLow());
5660 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL
);
5664 TargetedMovementGenerator
<Creature
> const* mgen
= static_cast<TargetedMovementGenerator
<Creature
> const*>(*itr
);
5665 Unit
* target
= mgen
->GetTarget();
5667 PSendSysMessage(LANG_MOVEGENS_TARGETED_CREATURE
,target
->GetName(),target
->GetGUIDLow());
5669 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL
);
5673 case HOME_MOTION_TYPE
:
5674 if(unit
->GetTypeId()==TYPEID_UNIT
)
5677 (*itr
)->GetDestination(x
,y
,z
);
5678 PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE
,x
,y
,z
);
5681 SendSysMessage(LANG_MOVEGENS_HOME_PLAYER
);
5683 case FLIGHT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FLIGHT
); break;
5684 case POINT_MOTION_TYPE
:
5687 (*itr
)->GetDestination(x
,y
,z
);
5688 PSendSysMessage(LANG_MOVEGENS_POINT
,x
,y
,z
);
5691 case FLEEING_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FEAR
); break;
5692 case DISTRACT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_DISTRACT
); break;
5694 PSendSysMessage(LANG_MOVEGENS_UNKNOWN
,(*itr
)->GetMovementGeneratorType());
5701 bool ChatHandler::HandlePLimitCommand(const char *args
)
5705 char* param
= strtok((char*)args
, " ");
5709 int l
= strlen(param
);
5711 if( strncmp(param
,"player",l
) == 0 )
5712 sWorld
.SetPlayerLimit(-SEC_PLAYER
);
5713 else if(strncmp(param
,"moderator",l
) == 0 )
5714 sWorld
.SetPlayerLimit(-SEC_MODERATOR
);
5715 else if(strncmp(param
,"gamemaster",l
) == 0 )
5716 sWorld
.SetPlayerLimit(-SEC_GAMEMASTER
);
5717 else if(strncmp(param
,"administrator",l
) == 0 )
5718 sWorld
.SetPlayerLimit(-SEC_ADMINISTRATOR
);
5719 else if(strncmp(param
,"reset",l
) == 0 )
5720 sWorld
.SetPlayerLimit( sConfig
.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT
) );
5723 int val
= atoi(param
);
5724 if(val
< -SEC_ADMINISTRATOR
) val
= -SEC_ADMINISTRATOR
;
5726 sWorld
.SetPlayerLimit(val
);
5729 // kick all low security level players
5730 if(sWorld
.GetPlayerAmountLimit() > SEC_PLAYER
)
5731 sWorld
.KickAllLess(sWorld
.GetPlayerSecurityLimit());
5734 uint32 pLimit
= sWorld
.GetPlayerAmountLimit();
5735 AccountTypes allowedAccountType
= sWorld
.GetPlayerSecurityLimit();
5736 char const* secName
= "";
5737 switch(allowedAccountType
)
5739 case SEC_PLAYER
: secName
= "Player"; break;
5740 case SEC_MODERATOR
: secName
= "Moderator"; break;
5741 case SEC_GAMEMASTER
: secName
= "Gamemaster"; break;
5742 case SEC_ADMINISTRATOR
: secName
= "Administrator"; break;
5743 default: secName
= "<unknown>"; break;
5746 PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit
,secName
);
5751 bool ChatHandler::HandleCastCommand(const char* args
)
5756 Unit
* target
= getSelectedUnit();
5760 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5761 SetSentErrorMessage(true);
5765 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5766 uint32 spell
= extractSpellIdFromLink((char*)args
);
5770 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5774 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5776 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5777 SetSentErrorMessage(true);
5781 char* trig_str
= strtok(NULL
, " ");
5784 int l
= strlen(trig_str
);
5785 if(strncmp(trig_str
,"triggered",l
) != 0 )
5789 bool triggered
= (trig_str
!= NULL
);
5791 m_session
->GetPlayer()->CastSpell(target
,spell
,triggered
);
5796 bool ChatHandler::HandleCastBackCommand(const char* args
)
5798 Creature
* caster
= getSelectedCreature();
5802 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5803 SetSentErrorMessage(true);
5807 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
5808 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5809 uint32 spell
= extractSpellIdFromLink((char*)args
);
5810 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
5813 char* trig_str
= strtok(NULL
, " ");
5816 int l
= strlen(trig_str
);
5817 if(strncmp(trig_str
,"triggered",l
) != 0 )
5821 bool triggered
= (trig_str
!= NULL
);
5823 // update orientation at server
5824 caster
->SetOrientation(caster
->GetAngle(m_session
->GetPlayer()));
5828 caster
->BuildHeartBeatMsg(&data
);
5829 caster
->SendMessageToSet(&data
,true);
5831 caster
->CastSpell(m_session
->GetPlayer(),spell
,triggered
);
5836 bool ChatHandler::HandleCastDistCommand(const char* args
)
5841 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5842 uint32 spell
= extractSpellIdFromLink((char*)args
);
5846 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5850 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5852 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5853 SetSentErrorMessage(true);
5857 char *distStr
= strtok(NULL
, " ");
5862 sscanf(distStr
, "%f", &dist
);
5864 char* trig_str
= strtok(NULL
, " ");
5867 int l
= strlen(trig_str
);
5868 if(strncmp(trig_str
,"triggered",l
) != 0 )
5872 bool triggered
= (trig_str
!= NULL
);
5875 m_session
->GetPlayer()->GetClosePoint(x
,y
,z
,dist
);
5877 m_session
->GetPlayer()->CastSpell(x
,y
,z
,spell
,triggered
);
5881 bool ChatHandler::HandleCastTargetCommand(const char* args
)
5883 Creature
* caster
= getSelectedCreature();
5887 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5888 SetSentErrorMessage(true);
5892 if(!caster
->getVictim())
5894 SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM
);
5895 SetSentErrorMessage(true);
5899 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5900 uint32 spell
= extractSpellIdFromLink((char*)args
);
5901 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
5904 char* trig_str
= strtok(NULL
, " ");
5907 int l
= strlen(trig_str
);
5908 if(strncmp(trig_str
,"triggered",l
) != 0 )
5912 bool triggered
= (trig_str
!= NULL
);
5914 // update orientation at server
5915 caster
->SetOrientation(caster
->GetAngle(m_session
->GetPlayer()));
5919 caster
->BuildHeartBeatMsg(&data
);
5920 caster
->SendMessageToSet(&data
,true);
5922 caster
->CastSpell(caster
->getVictim(),spell
,triggered
);
5928 ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
5929 Without this function 3rd party scripting library will get linking errors (unresolved external)
5930 when attempting to use the PointMovementGenerator
5932 bool ChatHandler::HandleComeToMeCommand(const char *args
)
5934 Creature
* caster
= getSelectedCreature();
5938 SendSysMessage(LANG_SELECT_CREATURE
);
5939 SetSentErrorMessage(true);
5943 char* newFlagStr
= strtok((char*)args
, " ");
5948 uint32 newFlags
= atoi(newFlagStr
);
5950 caster
->SetUnitMovementFlags(newFlags
);
5952 Player
* pl
= m_session
->GetPlayer();
5954 caster
->GetMotionMaster()->MovePoint(0, pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ());
5958 bool ChatHandler::HandleCastSelfCommand(const char* args
)
5963 Unit
* target
= getSelectedUnit();
5967 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5968 SetSentErrorMessage(true);
5972 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5973 uint32 spell
= extractSpellIdFromLink((char*)args
);
5977 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5981 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5983 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5984 SetSentErrorMessage(true);
5988 target
->CastSpell(target
,spell
,false);
5993 std::string
GetTimeString(uint32 time
)
5995 uint16 days
= time
/ DAY
, hours
= (time
% DAY
) / HOUR
, minute
= (time
% HOUR
) / MINUTE
;
5996 std::ostringstream ss
;
5997 if(days
) ss
<< days
<< "d ";
5998 if(hours
) ss
<< hours
<< "h ";
5999 ss
<< minute
<< "m";
6003 bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
6005 Player
* player
= getSelectedPlayer();
6006 if (!player
) player
= m_session
->GetPlayer();
6008 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
6010 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(i
);
6011 for(Player::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
6013 InstanceSave
*save
= itr
->second
.save
;
6014 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
6015 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());
6019 PSendSysMessage("player binds: %d", counter
);
6021 Group
*group
= player
->GetGroup();
6024 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
6026 Group::BoundInstancesMap
&binds
= group
->GetBoundInstances(i
);
6027 for(Group::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
6029 InstanceSave
*save
= itr
->second
.save
;
6030 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
6031 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());
6036 PSendSysMessage("group binds: %d", counter
);
6041 bool ChatHandler::HandleInstanceUnbindCommand(const char* args
)
6046 std::string cmd
= args
;
6049 Player
* player
= getSelectedPlayer();
6050 if (!player
) player
= m_session
->GetPlayer();
6052 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
6054 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(i
);
6055 for(Player::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end();)
6057 if(itr
->first
!= player
->GetMapId())
6059 InstanceSave
*save
= itr
->second
.save
;
6060 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
6061 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());
6062 player
->UnbindInstance(itr
, i
);
6069 PSendSysMessage("instances unbound: %d", counter
);
6074 bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
6076 PSendSysMessage("instances loaded: %d", MapManager::Instance().GetNumInstances());
6077 PSendSysMessage("players in instances: %d", MapManager::Instance().GetNumPlayersInInstances());
6078 PSendSysMessage("instance saves: %d", sInstanceSaveManager
.GetNumInstanceSaves());
6079 PSendSysMessage("players bound: %d", sInstanceSaveManager
.GetNumBoundPlayersTotal());
6080 PSendSysMessage("groups bound: %d", sInstanceSaveManager
.GetNumBoundGroupsTotal());
6084 bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
6086 Player
* pl
= m_session
->GetPlayer();
6088 Map
* map
= pl
->GetMap();
6089 if (!map
->IsDungeon())
6091 PSendSysMessage("Map is not a dungeon.");
6092 SetSentErrorMessage(true);
6096 if (!((InstanceMap
*)map
)->GetInstanceData())
6098 PSendSysMessage("Map has no instance data.");
6099 SetSentErrorMessage(true);
6103 ((InstanceMap
*)map
)->GetInstanceData()->SaveToDB();
6107 /// Display the list of GMs
6108 bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
6110 ///- Get the accounts with GM Level >0
6111 QueryResult
*result
= loginDatabase
.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
6114 SendSysMessage(LANG_GMLIST
);
6115 SendSysMessage("========================");
6116 SendSysMessage(LANG_GMLIST_HEADER
);
6117 SendSysMessage("========================");
6119 ///- Circle through them. Display username and GM level
6122 Field
*fields
= result
->Fetch();
6123 PSendSysMessage("|%15s|%6s|", fields
[0].GetString(),fields
[1].GetString());
6124 }while( result
->NextRow() );
6126 PSendSysMessage("========================");
6130 PSendSysMessage(LANG_GMLIST_EMPTY
);
6134 /// Define the 'Message of the day' for the realm
6135 bool ChatHandler::HandleServerSetMotdCommand(const char* args
)
6137 sWorld
.SetMotd(args
);
6138 PSendSysMessage(LANG_MOTD_NEW
, args
);
6142 /// Set/Unset the expansion level for an account
6143 bool ChatHandler::HandleAccountSetAddonCommand(const char* args
)
6145 ///- Get the command line arguments
6146 char *szAcc
= strtok((char*)args
," ");
6147 char *szExp
= strtok(NULL
," ");
6152 std::string account_name
;
6157 Player
* player
= getSelectedPlayer();
6161 account_id
= player
->GetSession()->GetAccountId();
6162 accmgr
.GetName(account_id
,account_name
);
6167 ///- Convert Account name to Upper Format
6168 account_name
= szAcc
;
6169 if(!AccountMgr::normilizeString(account_name
))
6171 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
6172 SetSentErrorMessage(true);
6176 account_id
= accmgr
.GetId(account_name
);
6179 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
6180 SetSentErrorMessage(true);
6186 // Let set addon state only for lesser (strong) security level
6187 // or to self account
6188 if (m_session
&& m_session
->GetAccountId () != account_id
&&
6189 HasLowerSecurityAccount (NULL
,account_id
,true))
6192 int lev
=atoi(szExp
); //get int anyway (0 if error)
6197 loginDatabase
.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev
,account_id
);
6198 PSendSysMessage(LANG_ACCOUNT_SETADDON
,account_name
.c_str(),account_id
,lev
);
6202 //Send items by mail
6203 bool ChatHandler::HandleSendItemsCommand(const char* args
)
6208 // format: name "subject text" "mail text" item1[:count1] item2[:count2] ... item12[:count12]
6210 char* pName
= strtok((char*)args
, " ");
6214 char* tail1
= strtok(NULL
, "");
6220 msgSubject
= strtok(tail1
+1, "\"");
6223 char* space
= strtok(tail1
, "\"");
6226 msgSubject
= strtok(NULL
, "\"");
6232 char* tail2
= strtok(NULL
, "");
6238 msgText
= strtok(tail2
+1, "\"");
6241 char* space
= strtok(tail2
, "\"");
6244 msgText
= strtok(NULL
, "\"");
6250 // pName, msgSubject, msgText isn't NUL after prev. check
6251 std::string name
= pName
;
6252 std::string subject
= msgSubject
;
6253 std::string text
= msgText
;
6256 typedef std::pair
<uint32
,uint32
> ItemPair
;
6257 typedef std::list
< ItemPair
> ItemPairs
;
6260 // get all tail string
6261 char* tail
= strtok(NULL
, "");
6263 // get from tail next item str
6264 while(char* itemStr
= strtok(tail
, " "))
6267 tail
= strtok(NULL
, "");
6270 char* itemIdStr
= strtok(itemStr
, ":");
6271 char* itemCountStr
= strtok(NULL
, " ");
6273 uint32 item_id
= atoi(itemIdStr
);
6277 ItemPrototype
const* item_proto
= objmgr
.GetItemPrototype(item_id
);
6280 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
6281 SetSentErrorMessage(true);
6285 uint32 item_count
= itemCountStr
? atoi(itemCountStr
) : 1;
6286 if(item_count
< 1 || item_proto
->MaxCount
> 0 && item_count
> uint32(item_proto
->MaxCount
))
6288 PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT
, item_count
,item_id
);
6289 SetSentErrorMessage(true);
6293 while(item_count
> item_proto
->GetMaxStackSize())
6295 items
.push_back(ItemPair(item_id
,item_proto
->GetMaxStackSize()));
6296 item_count
-= item_proto
->GetMaxStackSize();
6299 items
.push_back(ItemPair(item_id
,item_count
));
6301 if(items
.size() > MAX_MAIL_ITEMS
)
6303 PSendSysMessage(LANG_COMMAND_MAIL_ITEMS_LIMIT
, MAX_MAIL_ITEMS
);
6304 SetSentErrorMessage(true);
6309 if(!normalizePlayerName(name
))
6311 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6312 SetSentErrorMessage(true);
6316 uint64 receiver_guid
= objmgr
.GetPlayerGUIDByName(name
);
6319 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6320 SetSentErrorMessage(true);
6324 // from console show not existed sender
6325 uint32 sender_guidlo
= m_session
? m_session
->GetPlayer()->GetGUIDLow() : 0;
6327 uint32 messagetype
= MAIL_NORMAL
;
6328 uint32 stationery
= MAIL_STATIONERY_GM
;
6329 uint32 itemTextId
= !text
.empty() ? objmgr
.CreateItemText( text
) : 0;
6331 Player
*receiver
= objmgr
.GetPlayer(receiver_guid
);
6334 MailItemsInfo mi
; // item list preparing
6336 for(ItemPairs::const_iterator itr
= items
.begin(); itr
!= items
.end(); ++itr
)
6338 if(Item
* item
= Item::CreateItem(itr
->first
,itr
->second
,m_session
? m_session
->GetPlayer() : 0))
6340 item
->SaveToDB(); // save for prevent lost at next mail load, if send fail then item will deleted
6341 mi
.AddItem(item
->GetGUIDLow(), item
->GetEntry(), item
);
6345 WorldSession::SendMailTo(receiver
,messagetype
, stationery
, sender_guidlo
, GUID_LOPART(receiver_guid
), subject
, itemTextId
, &mi
, 0, 0, MAIL_CHECK_MASK_NONE
);
6347 PSendSysMessage(LANG_MAIL_SENT
, name
.c_str());
6351 ///Send money by mail
6352 bool ChatHandler::HandleSendMoneyCommand(const char* args
)
6357 /// format: name "subject text" "mail text" money
6359 char* pName
= strtok((char*)args
, " ");
6363 char* tail1
= strtok(NULL
, "");
6369 msgSubject
= strtok(tail1
+1, "\"");
6372 char* space
= strtok(tail1
, "\"");
6375 msgSubject
= strtok(NULL
, "\"");
6381 char* tail2
= strtok(NULL
, "");
6387 msgText
= strtok(tail2
+1, "\"");
6390 char* space
= strtok(tail2
, "\"");
6393 msgText
= strtok(NULL
, "\"");
6399 char* money_str
= strtok(NULL
, "");
6400 int32 money
= money_str
? atoi(money_str
) : 0;
6404 // pName, msgSubject, msgText isn't NUL after prev. check
6405 std::string name
= pName
;
6406 std::string subject
= msgSubject
;
6407 std::string text
= msgText
;
6409 if (!normalizePlayerName(name
))
6411 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6412 SetSentErrorMessage(true);
6416 uint64 receiver_guid
= objmgr
.GetPlayerGUIDByName(name
);
6419 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6420 SetSentErrorMessage(true);
6424 uint32 mailId
= objmgr
.GenerateMailID();
6426 // from console show not existed sender
6427 uint32 sender_guidlo
= m_session
? m_session
->GetPlayer()->GetGUIDLow() : 0;
6429 uint32 messagetype
= MAIL_NORMAL
;
6430 uint32 stationery
= MAIL_STATIONERY_GM
;
6431 uint32 itemTextId
= !text
.empty() ? objmgr
.CreateItemText( text
) : 0;
6433 Player
*receiver
= objmgr
.GetPlayer(receiver_guid
);
6435 WorldSession::SendMailTo(receiver
,messagetype
, stationery
, sender_guidlo
, GUID_LOPART(receiver_guid
), subject
, itemTextId
, NULL
, money
, 0, MAIL_CHECK_MASK_NONE
);
6437 PSendSysMessage(LANG_MAIL_SENT
, name
.c_str());
6441 /// Send a message to a player in game
6442 bool ChatHandler::HandleSendMessageCommand(const char* args
)
6444 ///- Get the command line arguments
6445 char* name_str
= strtok((char*)args
, " ");
6446 char* msg_str
= strtok(NULL
, "");
6448 if(!name_str
|| !msg_str
)
6451 std::string name
= name_str
;
6453 if(!normalizePlayerName(name
))
6456 ///- Find the player and check that he is not logging out.
6457 Player
*rPlayer
= objmgr
.GetPlayer(name
.c_str());
6460 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6461 SetSentErrorMessage(true);
6465 if(rPlayer
->GetSession()->isLogingOut())
6467 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6468 SetSentErrorMessage(true);
6472 ///- Send the message
6473 //Use SendAreaTriggerMessage for fastest delivery.
6474 rPlayer
->GetSession()->SendAreaTriggerMessage("%s", msg_str
);
6475 rPlayer
->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
6477 //Confirmation message
6478 PSendSysMessage(LANG_SENDMESSAGE
,name
.c_str(),msg_str
);
6482 bool ChatHandler::HandleFlushArenaPointsCommand(const char * /*args*/)
6484 sBattleGroundMgr
.DistributeArenaPoints();
6488 bool ChatHandler::HandleModifyGenderCommand(const char *args
)
6493 Player
*player
= getSelectedPlayer();
6497 PSendSysMessage(LANG_NO_PLAYER
);
6498 SetSentErrorMessage(true);
6502 PlayerInfo
const* info
= objmgr
.GetPlayerInfo(player
->getRace(), player
->getClass());
6506 char const* gender_str
= (char*)args
;
6507 int gender_len
= strlen(gender_str
);
6511 if(!strncmp(gender_str
, "male", gender_len
)) // MALE
6513 if(player
->getGender() == GENDER_MALE
)
6516 gender
= GENDER_MALE
;
6518 else if (!strncmp(gender_str
, "female", gender_len
)) // FEMALE
6520 if(player
->getGender() == GENDER_FEMALE
)
6523 gender
= GENDER_FEMALE
;
6527 SendSysMessage(LANG_MUST_MALE_OR_FEMALE
);
6528 SetSentErrorMessage(true);
6533 player
->SetByteValue(UNIT_FIELD_BYTES_0
, 2, gender
);
6534 player
->SetByteValue(PLAYER_BYTES_3
, 0, gender
);
6536 // Change display ID
6537 player
->SetDisplayId(gender
? info
->displayId_f
: info
->displayId_m
);
6538 player
->SetNativeDisplayId(gender
? info
->displayId_f
: info
->displayId_m
);
6540 char const* gender_full
= gender
? "female" : "male";
6542 PSendSysMessage(LANG_YOU_CHANGE_GENDER
, player
->GetName(), gender_full
);
6544 if (needReportToTarget(player
))
6545 ChatHandler(player
).PSendSysMessage(LANG_YOUR_GENDER_CHANGED
, gender_full
, GetName());