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 "ScriptCalls.h"
38 #include "GridNotifiersImpl.h"
41 #include "PointMovementGenerator.h"
42 #include "TargetedMovementGenerator.h"
43 #include "SkillDiscovery.h"
44 #include "SkillExtraItems.h"
45 #include "SystemConfig.h"
46 #include "Config/ConfigEnv.h"
48 #include "ItemEnchantmentMgr.h"
49 #include "BattleGroundMgr.h"
50 #include "InstanceSaveMgr.h"
51 #include "InstanceData.h"
54 bool ChatHandler::HandleReloadAllCommand(const char*)
56 HandleReloadSkillFishingBaseLevelCommand("");
58 HandleReloadAllAreaCommand("");
59 HandleReloadAllLootCommand("");
60 HandleReloadAllNpcCommand("");
61 HandleReloadAllQuestCommand("");
62 HandleReloadAllSpellCommand("");
63 HandleReloadAllItemCommand("");
64 HandleReloadAllLocalesCommand("");
66 HandleReloadCommandCommand("");
67 HandleReloadReservedNameCommand("");
68 HandleReloadMangosStringCommand("");
69 HandleReloadGameTeleCommand("");
73 bool ChatHandler::HandleReloadAllAreaCommand(const char*)
75 //HandleReloadQuestAreaTriggersCommand(""); -- reloaded in HandleReloadAllQuestCommand
76 HandleReloadAreaTriggerTeleportCommand("");
77 HandleReloadAreaTriggerTavernCommand("");
78 HandleReloadGameGraveyardZoneCommand("");
82 bool ChatHandler::HandleReloadAllLootCommand(const char*)
84 sLog
.outString( "Re-Loading Loot Tables..." );
86 SendGlobalSysMessage("DB tables `*_loot_template` reloaded.");
90 bool ChatHandler::HandleReloadAllNpcCommand(const char* /*args*/)
92 HandleReloadNpcGossipCommand("a");
93 HandleReloadNpcOptionCommand("a");
94 HandleReloadNpcTrainerCommand("a");
95 HandleReloadNpcVendorCommand("a");
96 HandleReloadPointsOfInterestCommand("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 HandleReloadSpellAreaCommand("a");
137 HandleReloadSpellChainCommand("a");
138 HandleReloadSpellElixirCommand("a");
139 HandleReloadSpellLearnSpellCommand("a");
140 HandleReloadSpellProcEventCommand("a");
141 HandleReloadSpellBonusesCommand("a");
142 HandleReloadSpellScriptTargetCommand("a");
143 HandleReloadSpellTargetPositionCommand("a");
144 HandleReloadSpellThreatsCommand("a");
145 HandleReloadSpellPetAurasCommand("a");
149 bool ChatHandler::HandleReloadAllItemCommand(const char*)
151 HandleReloadPageTextsCommand("a");
152 HandleReloadItemEnchantementsCommand("a");
156 bool ChatHandler::HandleReloadAllLocalesCommand(const char* /*args*/)
158 HandleReloadLocalesCreatureCommand("a");
159 HandleReloadLocalesGameobjectCommand("a");
160 HandleReloadLocalesItemCommand("a");
161 HandleReloadLocalesNpcTextCommand("a");
162 HandleReloadLocalesPageTextCommand("a");
163 HandleReloadLocalesPointsOfInterestCommand("a");
164 HandleReloadLocalesQuestCommand("a");
168 bool ChatHandler::HandleReloadConfigCommand(const char* /*args*/)
170 sLog
.outString( "Re-Loading config settings..." );
171 sWorld
.LoadConfigSettings(true);
172 SendGlobalSysMessage("World config settings reloaded.");
176 bool ChatHandler::HandleReloadAreaTriggerTavernCommand(const char*)
178 sLog
.outString( "Re-Loading Tavern Area Triggers..." );
179 objmgr
.LoadTavernAreaTriggers();
180 SendGlobalSysMessage("DB table `areatrigger_tavern` reloaded.");
184 bool ChatHandler::HandleReloadAreaTriggerTeleportCommand(const char*)
186 sLog
.outString( "Re-Loading AreaTrigger teleport definitions..." );
187 objmgr
.LoadAreaTriggerTeleports();
188 SendGlobalSysMessage("DB table `areatrigger_teleport` reloaded.");
192 bool ChatHandler::HandleReloadCommandCommand(const char*)
194 load_command_table
= true;
195 SendGlobalSysMessage("DB table `command` will be reloaded at next chat command use.");
199 bool ChatHandler::HandleReloadCreatureQuestRelationsCommand(const char*)
201 sLog
.outString( "Loading Quests Relations... (`creature_questrelation`)" );
202 objmgr
.LoadCreatureQuestRelations();
203 SendGlobalSysMessage("DB table `creature_questrelation` (creature quest givers) reloaded.");
207 bool ChatHandler::HandleReloadCreatureQuestInvRelationsCommand(const char*)
209 sLog
.outString( "Loading Quests Relations... (`creature_involvedrelation`)" );
210 objmgr
.LoadCreatureInvolvedRelations();
211 SendGlobalSysMessage("DB table `creature_involvedrelation` (creature quest takers) reloaded.");
215 bool ChatHandler::HandleReloadGOQuestRelationsCommand(const char*)
217 sLog
.outString( "Loading Quests Relations... (`gameobject_questrelation`)" );
218 objmgr
.LoadGameobjectQuestRelations();
219 SendGlobalSysMessage("DB table `gameobject_questrelation` (gameobject quest givers) reloaded.");
223 bool ChatHandler::HandleReloadGOQuestInvRelationsCommand(const char*)
225 sLog
.outString( "Loading Quests Relations... (`gameobject_involvedrelation`)" );
226 objmgr
.LoadGameobjectInvolvedRelations();
227 SendGlobalSysMessage("DB table `gameobject_involvedrelation` (gameobject quest takers) reloaded.");
231 bool ChatHandler::HandleReloadQuestAreaTriggersCommand(const char*)
233 sLog
.outString( "Re-Loading Quest Area Triggers..." );
234 objmgr
.LoadQuestAreaTriggers();
235 SendGlobalSysMessage("DB table `areatrigger_involvedrelation` (quest area triggers) reloaded.");
239 bool ChatHandler::HandleReloadQuestTemplateCommand(const char*)
241 sLog
.outString( "Re-Loading Quest Templates..." );
243 SendGlobalSysMessage("DB table `quest_template` (quest definitions) reloaded.");
245 /// dependent also from `gameobject` but this table not reloaded anyway
246 sLog
.outString( "Re-Loading GameObjects for quests..." );
247 objmgr
.LoadGameObjectForQuests();
248 SendGlobalSysMessage("Data GameObjects for quests reloaded.");
252 bool ChatHandler::HandleReloadLootTemplatesCreatureCommand(const char*)
254 sLog
.outString( "Re-Loading Loot Tables... (`creature_loot_template`)" );
255 LoadLootTemplates_Creature();
256 LootTemplates_Creature
.CheckLootRefs();
257 SendGlobalSysMessage("DB table `creature_loot_template` reloaded.");
261 bool ChatHandler::HandleReloadLootTemplatesDisenchantCommand(const char*)
263 sLog
.outString( "Re-Loading Loot Tables... (`disenchant_loot_template`)" );
264 LoadLootTemplates_Disenchant();
265 LootTemplates_Disenchant
.CheckLootRefs();
266 SendGlobalSysMessage("DB table `disenchant_loot_template` reloaded.");
270 bool ChatHandler::HandleReloadLootTemplatesFishingCommand(const char*)
272 sLog
.outString( "Re-Loading Loot Tables... (`fishing_loot_template`)" );
273 LoadLootTemplates_Fishing();
274 LootTemplates_Fishing
.CheckLootRefs();
275 SendGlobalSysMessage("DB table `fishing_loot_template` reloaded.");
279 bool ChatHandler::HandleReloadLootTemplatesGameobjectCommand(const char*)
281 sLog
.outString( "Re-Loading Loot Tables... (`gameobject_loot_template`)" );
282 LoadLootTemplates_Gameobject();
283 LootTemplates_Gameobject
.CheckLootRefs();
284 SendGlobalSysMessage("DB table `gameobject_loot_template` reloaded.");
288 bool ChatHandler::HandleReloadLootTemplatesItemCommand(const char*)
290 sLog
.outString( "Re-Loading Loot Tables... (`item_loot_template`)" );
291 LoadLootTemplates_Item();
292 LootTemplates_Item
.CheckLootRefs();
293 SendGlobalSysMessage("DB table `item_loot_template` reloaded.");
297 bool ChatHandler::HandleReloadLootTemplatesMillingCommand(const char*)
299 sLog
.outString( "Re-Loading Loot Tables... (`milling_loot_template`)" );
300 LoadLootTemplates_Milling();
301 LootTemplates_Milling
.CheckLootRefs();
302 SendGlobalSysMessage("DB table `milling_loot_template` reloaded.");
306 bool ChatHandler::HandleReloadLootTemplatesPickpocketingCommand(const char*)
308 sLog
.outString( "Re-Loading Loot Tables... (`pickpocketing_loot_template`)" );
309 LoadLootTemplates_Pickpocketing();
310 LootTemplates_Pickpocketing
.CheckLootRefs();
311 SendGlobalSysMessage("DB table `pickpocketing_loot_template` reloaded.");
315 bool ChatHandler::HandleReloadLootTemplatesProspectingCommand(const char*)
317 sLog
.outString( "Re-Loading Loot Tables... (`prospecting_loot_template`)" );
318 LoadLootTemplates_Prospecting();
319 LootTemplates_Prospecting
.CheckLootRefs();
320 SendGlobalSysMessage("DB table `prospecting_loot_template` reloaded.");
324 bool ChatHandler::HandleReloadLootTemplatesQuestMailCommand(const char*)
326 sLog
.outString( "Re-Loading Loot Tables... (`quest_mail_loot_template`)" );
327 LoadLootTemplates_QuestMail();
328 LootTemplates_QuestMail
.CheckLootRefs();
329 SendGlobalSysMessage("DB table `quest_mail_loot_template` reloaded.");
333 bool ChatHandler::HandleReloadLootTemplatesReferenceCommand(const char*)
335 sLog
.outString( "Re-Loading Loot Tables... (`reference_loot_template`)" );
336 LoadLootTemplates_Reference();
337 SendGlobalSysMessage("DB table `reference_loot_template` reloaded.");
341 bool ChatHandler::HandleReloadLootTemplatesSkinningCommand(const char*)
343 sLog
.outString( "Re-Loading Loot Tables... (`skinning_loot_template`)" );
344 LoadLootTemplates_Skinning();
345 LootTemplates_Skinning
.CheckLootRefs();
346 SendGlobalSysMessage("DB table `skinning_loot_template` reloaded.");
350 bool ChatHandler::HandleReloadLootTemplatesSpellCommand(const char*)
352 sLog
.outString( "Re-Loading Loot Tables... (`spell_loot_template`)" );
353 LoadLootTemplates_Spell();
354 LootTemplates_Spell
.CheckLootRefs();
355 SendGlobalSysMessage("DB table `spell_loot_template` reloaded.");
359 bool ChatHandler::HandleReloadMangosStringCommand(const char*)
361 sLog
.outString( "Re-Loading mangos_string Table!" );
362 objmgr
.LoadMangosStrings();
363 SendGlobalSysMessage("DB table `mangos_string` reloaded.");
367 bool ChatHandler::HandleReloadNpcOptionCommand(const char*)
369 sLog
.outString( "Re-Loading `npc_option` Table!" );
370 objmgr
.LoadNpcOptions();
371 SendGlobalSysMessage("DB table `npc_option` reloaded.");
375 bool ChatHandler::HandleReloadNpcGossipCommand(const char*)
377 sLog
.outString( "Re-Loading `npc_gossip` Table!" );
378 objmgr
.LoadNpcTextId();
379 SendGlobalSysMessage("DB table `npc_gossip` reloaded.");
383 bool ChatHandler::HandleReloadNpcTrainerCommand(const char*)
385 sLog
.outString( "Re-Loading `npc_trainer` Table!" );
386 objmgr
.LoadTrainerSpell();
387 SendGlobalSysMessage("DB table `npc_trainer` reloaded.");
391 bool ChatHandler::HandleReloadNpcVendorCommand(const char*)
393 sLog
.outString( "Re-Loading `npc_vendor` Table!" );
394 objmgr
.LoadVendors();
395 SendGlobalSysMessage("DB table `npc_vendor` reloaded.");
399 bool ChatHandler::HandleReloadPointsOfInterestCommand(const char*)
401 sLog
.outString( "Re-Loading `points_of_interest` Table!" );
402 objmgr
.LoadPointsOfInterest();
403 SendGlobalSysMessage("DB table `points_of_interest` reloaded.");
407 bool ChatHandler::HandleReloadReservedNameCommand(const char*)
409 sLog
.outString( "Loading ReservedNames... (`reserved_name`)" );
410 objmgr
.LoadReservedPlayersNames();
411 SendGlobalSysMessage("DB table `reserved_name` (player reserved names) reloaded.");
415 bool ChatHandler::HandleReloadSkillDiscoveryTemplateCommand(const char* /*args*/)
417 sLog
.outString( "Re-Loading Skill Discovery Table..." );
418 LoadSkillDiscoveryTable();
419 SendGlobalSysMessage("DB table `skill_discovery_template` (recipes discovered at crafting) reloaded.");
423 bool ChatHandler::HandleReloadSkillExtraItemTemplateCommand(const char* /*args*/)
425 sLog
.outString( "Re-Loading Skill Extra Item Table..." );
426 LoadSkillExtraItemTable();
427 SendGlobalSysMessage("DB table `skill_extra_item_template` (extra item creation when crafting) reloaded.");
431 bool ChatHandler::HandleReloadSkillFishingBaseLevelCommand(const char* /*args*/)
433 sLog
.outString( "Re-Loading Skill Fishing base level requirements..." );
434 objmgr
.LoadFishingBaseSkillLevel();
435 SendGlobalSysMessage("DB table `skill_fishing_base_level` (fishing base level for zone/subzone) reloaded.");
439 bool ChatHandler::HandleReloadSpellAffectCommand(const char*)
441 sLog
.outString( "Re-Loading SpellAffect definitions..." );
442 spellmgr
.LoadSpellAffects();
443 SendGlobalSysMessage("DB table `spell_affect` (spell mods apply requirements) reloaded.");
447 bool ChatHandler::HandleReloadSpellAreaCommand(const char*)
449 sLog
.outString( "Re-Loading SpellArea Data..." );
450 spellmgr
.LoadSpellAreas();
451 SendGlobalSysMessage("DB table `spell_area` (spell dependences from area/quest/auras state) reloaded.");
455 bool ChatHandler::HandleReloadSpellChainCommand(const char*)
457 sLog
.outString( "Re-Loading Spell Chain Data... " );
458 spellmgr
.LoadSpellChains();
459 SendGlobalSysMessage("DB table `spell_chain` (spell ranks) reloaded.");
463 bool ChatHandler::HandleReloadSpellElixirCommand(const char*)
465 sLog
.outString( "Re-Loading Spell Elixir types..." );
466 spellmgr
.LoadSpellElixirs();
467 SendGlobalSysMessage("DB table `spell_elixir` (spell elixir types) reloaded.");
471 bool ChatHandler::HandleReloadSpellLearnSpellCommand(const char*)
473 sLog
.outString( "Re-Loading Spell Learn Spells..." );
474 spellmgr
.LoadSpellLearnSpells();
475 SendGlobalSysMessage("DB table `spell_learn_spell` reloaded.");
479 bool ChatHandler::HandleReloadSpellProcEventCommand(const char*)
481 sLog
.outString( "Re-Loading Spell Proc Event conditions..." );
482 spellmgr
.LoadSpellProcEvents();
483 SendGlobalSysMessage("DB table `spell_proc_event` (spell proc trigger requirements) reloaded.");
487 bool ChatHandler::HandleReloadSpellBonusesCommand(const char*)
489 sLog
.outString( "Re-Loading Spell Bonus Data..." );
490 spellmgr
.LoadSpellBonusess();
491 SendGlobalSysMessage("DB table `spell_bonus_data` (spell damage/healing coefficients) reloaded.");
495 bool ChatHandler::HandleReloadSpellScriptTargetCommand(const char*)
497 sLog
.outString( "Re-Loading SpellsScriptTarget..." );
498 spellmgr
.LoadSpellScriptTarget();
499 SendGlobalSysMessage("DB table `spell_script_target` (spell targets selection in case specific creature/GO requirements) reloaded.");
503 bool ChatHandler::HandleReloadSpellTargetPositionCommand(const char*)
505 sLog
.outString( "Re-Loading Spell target coordinates..." );
506 spellmgr
.LoadSpellTargetPositions();
507 SendGlobalSysMessage("DB table `spell_target_position` (destination coordinates for spell targets) reloaded.");
511 bool ChatHandler::HandleReloadSpellThreatsCommand(const char*)
513 sLog
.outString( "Re-Loading Aggro Spells Definitions...");
514 spellmgr
.LoadSpellThreats();
515 SendGlobalSysMessage("DB table `spell_threat` (spell aggro definitions) reloaded.");
519 bool ChatHandler::HandleReloadSpellPetAurasCommand(const char*)
521 sLog
.outString( "Re-Loading Spell pet auras...");
522 spellmgr
.LoadSpellPetAuras();
523 SendGlobalSysMessage("DB table `spell_pet_auras` reloaded.");
527 bool ChatHandler::HandleReloadPageTextsCommand(const char*)
529 sLog
.outString( "Re-Loading Page Texts..." );
530 objmgr
.LoadPageTexts();
531 SendGlobalSysMessage("DB table `page_texts` reloaded.");
535 bool ChatHandler::HandleReloadItemEnchantementsCommand(const char*)
537 sLog
.outString( "Re-Loading Item Random Enchantments Table..." );
538 LoadRandomEnchantmentsTable();
539 SendGlobalSysMessage("DB table `item_enchantment_template` reloaded.");
543 bool ChatHandler::HandleReloadGameObjectScriptsCommand(const char* arg
)
545 if(sWorld
.IsScriptScheduled())
547 SendSysMessage("DB scripts used currently, please attempt reload later.");
548 SetSentErrorMessage(true);
553 sLog
.outString( "Re-Loading Scripts from `gameobject_scripts`...");
555 objmgr
.LoadGameObjectScripts();
558 SendGlobalSysMessage("DB table `gameobject_scripts` reloaded.");
563 bool ChatHandler::HandleReloadEventScriptsCommand(const char* arg
)
565 if(sWorld
.IsScriptScheduled())
567 SendSysMessage("DB scripts used currently, please attempt reload later.");
568 SetSentErrorMessage(true);
573 sLog
.outString( "Re-Loading Scripts from `event_scripts`...");
575 objmgr
.LoadEventScripts();
578 SendGlobalSysMessage("DB table `event_scripts` reloaded.");
583 bool ChatHandler::HandleReloadQuestEndScriptsCommand(const char* arg
)
585 if(sWorld
.IsScriptScheduled())
587 SendSysMessage("DB scripts used currently, please attempt reload later.");
588 SetSentErrorMessage(true);
593 sLog
.outString( "Re-Loading Scripts from `quest_end_scripts`...");
595 objmgr
.LoadQuestEndScripts();
598 SendGlobalSysMessage("DB table `quest_end_scripts` reloaded.");
603 bool ChatHandler::HandleReloadQuestStartScriptsCommand(const char* arg
)
605 if(sWorld
.IsScriptScheduled())
607 SendSysMessage("DB scripts used currently, please attempt reload later.");
608 SetSentErrorMessage(true);
613 sLog
.outString( "Re-Loading Scripts from `quest_start_scripts`...");
615 objmgr
.LoadQuestStartScripts();
618 SendGlobalSysMessage("DB table `quest_start_scripts` reloaded.");
623 bool ChatHandler::HandleReloadSpellScriptsCommand(const char* arg
)
625 if(sWorld
.IsScriptScheduled())
627 SendSysMessage("DB scripts used currently, please attempt reload later.");
628 SetSentErrorMessage(true);
633 sLog
.outString( "Re-Loading Scripts from `spell_scripts`...");
635 objmgr
.LoadSpellScripts();
638 SendGlobalSysMessage("DB table `spell_scripts` reloaded.");
643 bool ChatHandler::HandleReloadDbScriptStringCommand(const char* arg
)
645 sLog
.outString( "Re-Loading Script strings from `db_script_string`...");
646 objmgr
.LoadDbScriptStrings();
647 SendGlobalSysMessage("DB table `db_script_string` reloaded.");
651 bool ChatHandler::HandleReloadGameGraveyardZoneCommand(const char* /*arg*/)
653 sLog
.outString( "Re-Loading Graveyard-zone links...");
655 objmgr
.LoadGraveyardZones();
657 SendGlobalSysMessage("DB table `game_graveyard_zone` reloaded.");
662 bool ChatHandler::HandleReloadGameTeleCommand(const char* /*arg*/)
664 sLog
.outString( "Re-Loading Game Tele coordinates...");
666 objmgr
.LoadGameTele();
668 SendGlobalSysMessage("DB table `game_tele` reloaded.");
673 bool ChatHandler::HandleReloadLocalesCreatureCommand(const char* /*arg*/)
675 sLog
.outString( "Re-Loading Locales Creature ...");
676 objmgr
.LoadCreatureLocales();
677 SendGlobalSysMessage("DB table `locales_creature` reloaded.");
681 bool ChatHandler::HandleReloadLocalesGameobjectCommand(const char* /*arg*/)
683 sLog
.outString( "Re-Loading Locales Gameobject ... ");
684 objmgr
.LoadGameObjectLocales();
685 SendGlobalSysMessage("DB table `locales_gameobject` reloaded.");
689 bool ChatHandler::HandleReloadLocalesItemCommand(const char* /*arg*/)
691 sLog
.outString( "Re-Loading Locales Item ... ");
692 objmgr
.LoadItemLocales();
693 SendGlobalSysMessage("DB table `locales_item` reloaded.");
697 bool ChatHandler::HandleReloadLocalesNpcTextCommand(const char* /*arg*/)
699 sLog
.outString( "Re-Loading Locales NPC Text ... ");
700 objmgr
.LoadNpcTextLocales();
701 SendGlobalSysMessage("DB table `locales_npc_text` reloaded.");
705 bool ChatHandler::HandleReloadLocalesPageTextCommand(const char* /*arg*/)
707 sLog
.outString( "Re-Loading Locales Page Text ... ");
708 objmgr
.LoadPageTextLocales();
709 SendGlobalSysMessage("DB table `locales_page_text` reloaded.");
713 bool ChatHandler::HandleReloadLocalesPointsOfInterestCommand(const char* /*arg*/)
715 sLog
.outString( "Re-Loading Locales Points Of Interest ... ");
716 objmgr
.LoadPointOfInterestLocales();
717 SendGlobalSysMessage("DB table `locales_points_of_interest` reloaded.");
721 bool ChatHandler::HandleReloadLocalesQuestCommand(const char* /*arg*/)
723 sLog
.outString( "Re-Loading Locales Quest ... ");
724 objmgr
.LoadQuestLocales();
725 SendGlobalSysMessage("DB table `locales_quest` reloaded.");
729 bool ChatHandler::HandleLoadScriptsCommand(const char* args
)
731 if(!LoadScriptingModule(args
)) return true;
733 sWorld
.SendWorldText(LANG_SCRIPTS_RELOADED
);
737 bool ChatHandler::HandleAccountSetGmLevelCommand(const char* args
)
739 char* arg1
= strtok((char*)args
, " ");
743 /// must be NULL if targeted syntax and must be not nULL if not targeted
744 char* arg2
= strtok(NULL
, " ");
746 std::string targetAccountName
;
747 uint32 targetAccountId
= 0;
749 /// only target player different from self allowed (if targetPlayer!=NULL then not console)
750 Player
* targetPlayer
= getSelectedPlayer();
751 if(targetPlayer
&& m_session
->GetPlayer()!=targetPlayer
)
753 /// wrong command syntax or unexpected targeting
757 /// security level expected in arg2 after this if.
760 targetAccountId
= targetPlayer
->GetSession()->GetAccountId();
761 accmgr
.GetName(targetAccountId
, targetAccountName
);
765 /// wrong command syntax (second arg expected)
769 targetAccountName
= arg1
;
770 if(!AccountMgr::normilizeString(targetAccountName
))
772 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,targetAccountName
.c_str());
773 SetSentErrorMessage(true);
777 targetAccountId
= accmgr
.GetId(targetAccountName
);
780 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,targetAccountName
.c_str());
781 SetSentErrorMessage(true);
786 int32 gm
= (int32
)atoi(arg2
);
787 if ( gm
< SEC_PLAYER
|| gm
> SEC_ADMINISTRATOR
)
789 SendSysMessage(LANG_BAD_VALUE
);
790 SetSentErrorMessage(true);
794 /// can set security level only for target with less security and to less security that we have
795 /// This will reject self apply by specify account name
796 if(HasLowerSecurityAccount(NULL
,targetAccountId
,true))
799 /// account can't set security to same or grater level, need more power GM or console
800 uint32 plSecurity
= m_session
? m_session
->GetSecurity() : SEC_CONSOLE
;
801 if (uint32(gm
) >= plSecurity
)
803 SendSysMessage(LANG_YOURS_SECURITY_IS_LOW
);
804 SetSentErrorMessage(true);
808 // This will prevent self apply by self target or no target
809 if(targetPlayer
&& m_session
->GetPlayer()!=targetPlayer
)
811 ChatHandler(targetPlayer
).PSendSysMessage(LANG_YOURS_SECURITY_CHANGED
,GetNameLink().c_str(), gm
);
812 targetPlayer
->GetSession()->SetSecurity(gm
);
815 PSendSysMessage(LANG_YOU_CHANGE_SECURITY
, targetAccountName
.c_str(), gm
);
816 loginDatabase
.PExecute("UPDATE account SET gmlevel = '%i' WHERE id = '%u'", gm
, targetAccountId
);
821 /// Set password for account
822 bool ChatHandler::HandleAccountSetPasswordCommand(const char* args
)
827 ///- Get the command line arguments
828 char *szAccount
= strtok ((char*)args
," ");
829 char *szPassword1
= strtok (NULL
," ");
830 char *szPassword2
= strtok (NULL
," ");
832 if (!szAccount
||!szPassword1
|| !szPassword2
)
835 std::string account_name
= szAccount
;
836 if(!AccountMgr::normilizeString(account_name
))
838 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
839 SetSentErrorMessage(true);
843 uint32 targetAccountId
= accmgr
.GetId(account_name
);
844 if (!targetAccountId
)
846 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
847 SetSentErrorMessage(true);
851 /// can set password only for target with less security
852 /// This is also reject self apply in fact
853 if(HasLowerSecurityAccount (NULL
,targetAccountId
,true))
856 if (strcmp(szPassword1
,szPassword2
))
858 SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH
);
859 SetSentErrorMessage (true);
863 AccountOpResult result
= accmgr
.ChangePassword(targetAccountId
, szPassword1
);
868 SendSysMessage(LANG_COMMAND_PASSWORD
);
870 case AOR_NAME_NOT_EXIST
:
871 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
872 SetSentErrorMessage(true);
874 case AOR_PASS_TOO_LONG
:
875 SendSysMessage(LANG_PASSWORD_TOO_LONG
);
876 SetSentErrorMessage(true);
879 SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD
);
880 SetSentErrorMessage(true);
887 bool ChatHandler::HandleMaxSkillCommand(const char* /*args*/)
889 Player
* SelectedPlayer
= getSelectedPlayer();
892 SendSysMessage(LANG_NO_CHAR_SELECTED
);
893 SetSentErrorMessage(true);
897 // each skills that have max skill value dependent from level seted to current level max skill value
898 SelectedPlayer
->UpdateSkillsToMaxSkillsForLevel();
902 bool ChatHandler::HandleSetSkillCommand(const char* args
)
904 // number or [name] Shift-click form |color|Hskill:skill_id|h[name]|h|r
905 char* skill_p
= extractKeyFromLink((char*)args
,"Hskill");
909 char *level_p
= strtok (NULL
, " ");
914 char *max_p
= strtok (NULL
, " ");
916 int32 skill
= atoi(skill_p
);
919 PSendSysMessage(LANG_INVALID_SKILL_ID
, skill
);
920 SetSentErrorMessage(true);
924 int32 level
= atol (level_p
);
926 Player
* target
= getSelectedPlayer();
929 SendSysMessage(LANG_NO_CHAR_SELECTED
);
930 SetSentErrorMessage(true);
934 SkillLineEntry
const* sl
= sSkillLineStore
.LookupEntry(skill
);
937 PSendSysMessage(LANG_INVALID_SKILL_ID
, skill
);
938 SetSentErrorMessage(true);
942 std::string tNameLink
= GetNameLink(target
);
944 if(!target
->GetSkillValue(skill
))
946 PSendSysMessage(LANG_SET_SKILL_ERROR
, tNameLink
.c_str(), skill
, sl
->name
[0]);
947 SetSentErrorMessage(true);
951 int32 max
= max_p
? atol (max_p
) : target
->GetPureMaxSkillValue(skill
);
953 if( level
<= 0 || level
> max
|| max
<= 0 )
956 target
->SetSkill(skill
, level
, max
);
957 PSendSysMessage(LANG_SET_SKILL
, skill
, sl
->name
[0], tNameLink
.c_str(), level
, max
);
962 bool ChatHandler::HandleUnLearnCommand(const char* args
)
967 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
968 uint32 spell_id
= extractSpellIdFromLink((char*)args
);
972 char const* allStr
= strtok(NULL
," ");
973 bool allRanks
= allStr
? (strncmp(allStr
, "all", strlen(allStr
)) == 0) : false;
975 Player
* target
= getSelectedPlayer();
978 SendSysMessage(LANG_NO_CHAR_SELECTED
);
979 SetSentErrorMessage(true);
984 spell_id
= spellmgr
.GetFirstSpellInChain (spell_id
);
986 if (target
->HasSpell(spell_id
))
987 target
->removeSpell(spell_id
,false,!allRanks
);
989 SendSysMessage(LANG_FORGET_SPELL
);
994 bool ChatHandler::HandleCooldownCommand(const char* args
)
996 Player
* target
= getSelectedPlayer();
999 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1000 SetSentErrorMessage(true);
1004 std::string tNameLink
= GetNameLink(target
);
1008 target
->RemoveAllSpellCooldown();
1009 PSendSysMessage(LANG_REMOVEALL_COOLDOWN
, tNameLink
.c_str());
1013 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1014 uint32 spell_id
= extractSpellIdFromLink((char*)args
);
1018 if(!sSpellStore
.LookupEntry(spell_id
))
1020 PSendSysMessage(LANG_UNKNOWN_SPELL
, target
==m_session
->GetPlayer() ? GetMangosString(LANG_YOU
) : tNameLink
.c_str());
1021 SetSentErrorMessage(true);
1025 WorldPacket
data( SMSG_CLEAR_COOLDOWN
, (4+8) );
1026 data
<< uint32(spell_id
);
1027 data
<< uint64(target
->GetGUID());
1028 target
->GetSession()->SendPacket(&data
);
1029 target
->RemoveSpellCooldown(spell_id
);
1030 PSendSysMessage(LANG_REMOVE_COOLDOWN
, spell_id
, target
==m_session
->GetPlayer() ? GetMangosString(LANG_YOU
) : tNameLink
.c_str());
1035 bool ChatHandler::HandleLearnAllCommand(const char* /*args*/)
1037 static const char *allSpellList
[] =
1420 //"9036", problems with ghost state
1429 //"6718", phasing stealth, annoying for learn all case.
1642 while(strcmp(allSpellList
[loop
], "0"))
1644 uint32 spell
= atol((char*)allSpellList
[loop
++]);
1646 if (m_session
->GetPlayer()->HasSpell(spell
))
1649 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1650 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1652 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1656 m_session
->GetPlayer()->learnSpell(spell
,false);
1659 SendSysMessage(LANG_COMMAND_LEARN_MANY_SPELLS
);
1664 bool ChatHandler::HandleLearnAllGMCommand(const char* /*args*/)
1666 static const char *gmSpellList
[] =
1668 "24347", // Become A Fish, No Breath Bar
1669 "35132", // Visual Boom
1670 "38488", // Attack 4000-8000 AOE
1671 "38795", // Attack 2000 AOE + Slow Down 90%
1672 "15712", // Attack 200
1673 "1852", // GM Spell Silence
1676 "29878", // Kill My Self
1677 "26644", // More Kill
1679 "28550", //Invisible 24
1680 "23452", //Invisible + Target
1684 uint16 gmSpellIter
= 0;
1685 while( strcmp(gmSpellList
[gmSpellIter
], "0") )
1687 uint32 spell
= atol((char*)gmSpellList
[gmSpellIter
++]);
1689 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1690 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1692 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1696 m_session
->GetPlayer()->learnSpell(spell
,false);
1699 SendSysMessage(LANG_LEARNING_GM_SKILLS
);
1703 bool ChatHandler::HandleLearnAllMyClassCommand(const char* /*args*/)
1705 HandleLearnAllMySpellsCommand("");
1706 HandleLearnAllMyTalentsCommand("");
1710 bool ChatHandler::HandleLearnAllMySpellsCommand(const char* /*args*/)
1712 ChrClassesEntry
const* clsEntry
= sChrClassesStore
.LookupEntry(m_session
->GetPlayer()->getClass());
1715 uint32 family
= clsEntry
->spellfamily
;
1717 for (uint32 i
= 0; i
< sSpellStore
.GetNumRows(); i
++)
1719 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(i
);
1723 // skip server-side/triggered spells
1724 if(spellInfo
->spellLevel
==0)
1727 // skip wrong class/race skills
1728 if(!m_session
->GetPlayer()->IsSpellFitByClassAndRace(spellInfo
->Id
))
1731 // skip other spell families
1732 if( spellInfo
->SpellFamilyName
!= family
)
1735 // skip spells with first rank learned as talent (and all talents then also)
1736 uint32 first_rank
= spellmgr
.GetFirstSpellInChain(spellInfo
->Id
);
1737 if(GetTalentSpellCost(first_rank
) > 0 )
1740 // skip broken spells
1741 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1744 m_session
->GetPlayer()->learnSpell(i
,false);
1747 SendSysMessage(LANG_COMMAND_LEARN_CLASS_SPELLS
);
1751 bool ChatHandler::HandleLearnAllMyTalentsCommand(const char* /*args*/)
1753 Player
* player
= m_session
->GetPlayer();
1754 uint32 classMask
= player
->getClassMask();
1756 for (uint32 i
= 0; i
< sTalentStore
.GetNumRows(); i
++)
1758 TalentEntry
const *talentInfo
= sTalentStore
.LookupEntry(i
);
1762 TalentTabEntry
const *talentTabInfo
= sTalentTabStore
.LookupEntry( talentInfo
->TalentTab
);
1766 if( (classMask
& talentTabInfo
->ClassMask
) == 0 )
1769 // search highest talent rank
1772 for(int rank
= MAX_TALENT_RANK
-1; rank
>= 0; --rank
)
1774 if(talentInfo
->RankID
[rank
]!=0)
1776 spellid
= talentInfo
->RankID
[rank
];
1781 if(!spellid
) // ??? none spells in talent
1784 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spellid
);
1785 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1788 // learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
1789 player
->learnSpellHighRank(spellid
);
1792 SendSysMessage(LANG_COMMAND_LEARN_CLASS_TALENTS
);
1796 bool ChatHandler::HandleLearnAllMyPetTalentsCommand(const char* /*args*/)
1798 Player
* player
= m_session
->GetPlayer();
1800 Pet
* pet
= player
->GetPet();
1803 SendSysMessage(LANG_NO_PET_FOUND
);
1804 SetSentErrorMessage(true);
1808 CreatureInfo
const *ci
= pet
->GetCreatureInfo();
1811 SendSysMessage(LANG_WRONG_PET_TYPE
);
1812 SetSentErrorMessage(true);
1816 CreatureFamilyEntry
const *pet_family
= sCreatureFamilyStore
.LookupEntry(ci
->family
);
1819 SendSysMessage(LANG_WRONG_PET_TYPE
);
1820 SetSentErrorMessage(true);
1824 if(pet_family
->petTalentType
< 0) // not hunter pet
1826 SendSysMessage(LANG_WRONG_PET_TYPE
);
1827 SetSentErrorMessage(true);
1831 for (uint32 i
= 0; i
< sTalentStore
.GetNumRows(); i
++)
1833 TalentEntry
const *talentInfo
= sTalentStore
.LookupEntry(i
);
1837 TalentTabEntry
const *talentTabInfo
= sTalentTabStore
.LookupEntry( talentInfo
->TalentTab
);
1841 // prevent learn talent for different family (cheating)
1842 if(((1 << pet_family
->petTalentType
) & talentTabInfo
->petTalentMask
)==0)
1845 // search highest talent rank
1848 for(int rank
= MAX_TALENT_RANK
-1; rank
>= 0; --rank
)
1850 if(talentInfo
->RankID
[rank
]!=0)
1852 spellid
= talentInfo
->RankID
[rank
];
1857 if(!spellid
) // ??? none spells in talent
1860 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spellid
);
1861 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1864 // learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
1865 pet
->learnSpellHighRank(spellid
);
1868 SendSysMessage(LANG_COMMAND_LEARN_PET_TALENTS
);
1872 bool ChatHandler::HandleLearnAllLangCommand(const char* /*args*/)
1874 // skipping UNIVERSAL language (0)
1875 for(int i
= 1; i
< LANGUAGES_COUNT
; ++i
)
1876 m_session
->GetPlayer()->learnSpell(lang_description
[i
].spell_id
,false);
1878 SendSysMessage(LANG_COMMAND_LEARN_ALL_LANG
);
1882 bool ChatHandler::HandleLearnAllDefaultCommand(const char* args
)
1884 Player
*player
= NULL
;
1887 std::string name
= extractPlayerNameFromLink((char*)args
);
1890 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1891 SetSentErrorMessage(true);
1895 player
= objmgr
.GetPlayer(name
.c_str());
1898 player
= getSelectedPlayer();
1902 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1903 SetSentErrorMessage(true);
1907 player
->learnDefaultSpells();
1908 player
->learnQuestRewardedSpells();
1910 PSendSysMessage(LANG_COMMAND_LEARN_ALL_DEFAULT_AND_QUEST
,GetNameLink(player
).c_str());
1914 bool ChatHandler::HandleLearnCommand(const char* args
)
1916 Player
* targetPlayer
= getSelectedPlayer();
1920 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1921 SetSentErrorMessage(true);
1925 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1926 uint32 spell
= extractSpellIdFromLink((char*)args
);
1927 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
1930 char const* allStr
= strtok(NULL
," ");
1931 bool allRanks
= allStr
? (strncmp(allStr
, "all", strlen(allStr
)) == 0) : false;
1933 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1934 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1936 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1937 SetSentErrorMessage(true);
1941 if (!allRanks
&& targetPlayer
->HasSpell(spell
))
1943 if(targetPlayer
== m_session
->GetPlayer())
1944 SendSysMessage(LANG_YOU_KNOWN_SPELL
);
1946 PSendSysMessage(LANG_TARGET_KNOWN_SPELL
,GetNameLink(targetPlayer
).c_str());
1947 SetSentErrorMessage(true);
1952 targetPlayer
->learnSpellHighRank(spell
);
1954 targetPlayer
->learnSpell(spell
,false);
1959 bool ChatHandler::HandleAddItemCommand(const char* args
)
1966 if(args
[0]=='[') // [name] manual form
1968 char* citemName
= citemName
= strtok((char*)args
, "]");
1970 if(citemName
&& citemName
[0])
1972 std::string itemName
= citemName
+1;
1973 WorldDatabase
.escape_string(itemName
);
1974 QueryResult
*result
= WorldDatabase
.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName
.c_str());
1977 PSendSysMessage(LANG_COMMAND_COULDNOTFIND
, citemName
+1);
1978 SetSentErrorMessage(true);
1981 itemId
= result
->Fetch()->GetUInt16();
1987 else // item_id or [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r
1989 char* cId
= extractKeyFromLink((char*)args
,"Hitem");
1995 char* ccount
= strtok(NULL
, " ");
2000 count
= strtol(ccount
, NULL
, 10);
2005 Player
* pl
= m_session
->GetPlayer();
2006 Player
* plTarget
= getSelectedPlayer();
2010 sLog
.outDetail(GetMangosString(LANG_ADDITEM
), itemId
, count
);
2012 ItemPrototype
const *pProto
= objmgr
.GetItemPrototype(itemId
);
2015 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, itemId
);
2016 SetSentErrorMessage(true);
2023 plTarget
->DestroyItemCount(itemId
, -count
, true, false);
2024 PSendSysMessage(LANG_REMOVEITEM
, itemId
, -count
, GetNameLink(plTarget
).c_str());
2029 uint32 noSpaceForCount
= 0;
2031 // check space and find places
2032 ItemPosCountVec dest
;
2033 uint8 msg
= plTarget
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, itemId
, count
, &noSpaceForCount
);
2034 if( msg
!= EQUIP_ERR_OK
) // convert to possible store amount
2035 count
-= noSpaceForCount
;
2037 if( count
== 0 || dest
.empty()) // can't add any
2039 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, itemId
, noSpaceForCount
);
2040 SetSentErrorMessage(true);
2044 Item
* item
= plTarget
->StoreNewItem( dest
, itemId
, true, Item::GenerateItemRandomPropertyId(itemId
));
2046 // remove binding (let GM give it to another player later)
2048 for(ItemPosCountVec::const_iterator itr
= dest
.begin(); itr
!= dest
.end(); ++itr
)
2049 if(Item
* item1
= pl
->GetItemByPos(itr
->pos
))
2050 item1
->SetBinding( false );
2052 if(count
> 0 && item
)
2054 pl
->SendNewItem(item
,count
,false,true);
2056 plTarget
->SendNewItem(item
,count
,true,false);
2059 if(noSpaceForCount
> 0)
2060 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, itemId
, noSpaceForCount
);
2065 bool ChatHandler::HandleAddItemSetCommand(const char* args
)
2070 char* cId
= extractKeyFromLink((char*)args
,"Hitemset"); // number or [name] Shift-click form |color|Hitemset:itemset_id|h[name]|h|r
2074 uint32 itemsetId
= atol(cId
);
2076 // prevent generation all items with itemset field value '0'
2079 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND
,itemsetId
);
2080 SetSentErrorMessage(true);
2084 Player
* pl
= m_session
->GetPlayer();
2085 Player
* plTarget
= getSelectedPlayer();
2089 sLog
.outDetail(GetMangosString(LANG_ADDITEMSET
), itemsetId
);
2092 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
2094 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
2098 if (pProto
->ItemSet
== itemsetId
)
2101 ItemPosCountVec dest
;
2102 uint8 msg
= plTarget
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, pProto
->ItemId
, 1 );
2103 if (msg
== EQUIP_ERR_OK
)
2105 Item
* item
= plTarget
->StoreNewItem( dest
, pProto
->ItemId
, true);
2107 // remove binding (let GM give it to another player later)
2109 item
->SetBinding( false );
2111 pl
->SendNewItem(item
,1,false,true);
2113 plTarget
->SendNewItem(item
,1,true,false);
2117 pl
->SendEquipError( msg
, NULL
, NULL
);
2118 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, pProto
->ItemId
, 1);
2125 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND
,itemsetId
);
2127 SetSentErrorMessage(true);
2134 bool ChatHandler::HandleListItemCommand(const char* args
)
2139 char* cId
= extractKeyFromLink((char*)args
,"Hitem");
2143 uint32 item_id
= atol(cId
);
2146 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
2147 SetSentErrorMessage(true);
2151 ItemPrototype
const* itemProto
= objmgr
.GetItemPrototype(item_id
);
2154 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
2155 SetSentErrorMessage(true);
2159 char* c_count
= strtok(NULL
, " ");
2160 int count
= c_count
? atol(c_count
) : 10;
2165 QueryResult
*result
;
2168 uint32 inv_count
= 0;
2169 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM character_inventory WHERE item_template='%u'",item_id
);
2172 inv_count
= (*result
)[0].GetUInt32();
2176 result
=CharacterDatabase
.PQuery(
2178 "SELECT ci.item, cibag.slot AS bag, ci.slot, ci.guid, characters.account,characters.name "
2179 "FROM character_inventory AS ci LEFT JOIN character_inventory AS cibag ON (cibag.item=ci.bag),characters "
2180 "WHERE ci.item_template='%u' AND ci.guid = characters.guid LIMIT %u ",
2181 item_id
,uint32(count
));
2187 Field
*fields
= result
->Fetch();
2188 uint32 item_guid
= fields
[0].GetUInt32();
2189 uint32 item_bag
= fields
[1].GetUInt32();
2190 uint32 item_slot
= fields
[2].GetUInt32();
2191 uint32 owner_guid
= fields
[3].GetUInt32();
2192 uint32 owner_acc
= fields
[4].GetUInt32();
2193 std::string owner_name
= fields
[5].GetCppString();
2195 char const* item_pos
= 0;
2196 if(Player::IsEquipmentPos(item_bag
,item_slot
))
2197 item_pos
= "[equipped]";
2198 else if(Player::IsInventoryPos(item_bag
,item_slot
))
2199 item_pos
= "[in inventory]";
2200 else if(Player::IsBankPos(item_bag
,item_slot
))
2201 item_pos
= "[in bank]";
2205 PSendSysMessage(LANG_ITEMLIST_SLOT
,
2206 item_guid
,owner_name
.c_str(),owner_guid
,owner_acc
,item_pos
);
2207 } while (result
->NextRow());
2209 int64 res_count
= result
->GetRowCount();
2213 if(count
> res_count
)
2220 uint32 mail_count
= 0;
2221 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM mail_items WHERE item_template='%u'", item_id
);
2224 mail_count
= (*result
)[0].GetUInt32();
2230 result
=CharacterDatabase
.PQuery(
2232 "SELECT mail_items.item_guid, mail.sender, mail.receiver, char_s.account, char_s.name, char_r.account, char_r.name "
2233 "FROM mail,mail_items,characters as char_s,characters as char_r "
2234 "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",
2235 item_id
,uint32(count
));
2244 Field
*fields
= result
->Fetch();
2245 uint32 item_guid
= fields
[0].GetUInt32();
2246 uint32 item_s
= fields
[1].GetUInt32();
2247 uint32 item_r
= fields
[2].GetUInt32();
2248 uint32 item_s_acc
= fields
[3].GetUInt32();
2249 std::string item_s_name
= fields
[4].GetCppString();
2250 uint32 item_r_acc
= fields
[5].GetUInt32();
2251 std::string item_r_name
= fields
[6].GetCppString();
2253 char const* item_pos
= "[in mail]";
2255 PSendSysMessage(LANG_ITEMLIST_MAIL
,
2256 item_guid
,item_s_name
.c_str(),item_s
,item_s_acc
,item_r_name
.c_str(),item_r
,item_r_acc
,item_pos
);
2257 } while (result
->NextRow());
2259 int64 res_count
= result
->GetRowCount();
2263 if(count
> res_count
)
2270 uint32 auc_count
= 0;
2271 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM auctionhouse WHERE item_template='%u'",item_id
);
2274 auc_count
= (*result
)[0].GetUInt32();
2280 result
=CharacterDatabase
.PQuery(
2282 "SELECT auctionhouse.itemguid, auctionhouse.itemowner, characters.account, characters.name "
2283 "FROM auctionhouse,characters WHERE auctionhouse.item_template='%u' AND characters.guid = auctionhouse.itemowner LIMIT %u",
2284 item_id
,uint32(count
));
2293 Field
*fields
= result
->Fetch();
2294 uint32 item_guid
= fields
[0].GetUInt32();
2295 uint32 owner
= fields
[1].GetUInt32();
2296 uint32 owner_acc
= fields
[2].GetUInt32();
2297 std::string owner_name
= fields
[3].GetCppString();
2299 char const* item_pos
= "[in auction]";
2301 PSendSysMessage(LANG_ITEMLIST_AUCTION
, item_guid
, owner_name
.c_str(), owner
, owner_acc
,item_pos
);
2302 } while (result
->NextRow());
2308 uint32 guild_count
= 0;
2309 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_entry) FROM guild_bank_item WHERE item_entry='%u'",item_id
);
2312 guild_count
= (*result
)[0].GetUInt32();
2316 result
=CharacterDatabase
.PQuery(
2318 "SELECT gi.item_guid, gi.guildid, guild.name "
2319 "FROM guild_bank_item AS gi, guild WHERE gi.item_entry='%u' AND gi.guildid = guild.guildid LIMIT %u ",
2320 item_id
,uint32(count
));
2326 Field
*fields
= result
->Fetch();
2327 uint32 item_guid
= fields
[0].GetUInt32();
2328 uint32 guild_guid
= fields
[1].GetUInt32();
2329 std::string guild_name
= fields
[2].GetCppString();
2331 char const* item_pos
= "[in guild bank]";
2333 PSendSysMessage(LANG_ITEMLIST_GUILD
,item_guid
,guild_name
.c_str(),guild_guid
,item_pos
);
2334 } while (result
->NextRow());
2336 int64 res_count
= result
->GetRowCount();
2340 if(count
> res_count
)
2346 if(inv_count
+mail_count
+auc_count
+guild_count
== 0)
2348 SendSysMessage(LANG_COMMAND_NOITEMFOUND
);
2349 SetSentErrorMessage(true);
2353 PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE
,item_id
,inv_count
+mail_count
+auc_count
+guild_count
,inv_count
,mail_count
,auc_count
,guild_count
);
2358 bool ChatHandler::HandleListObjectCommand(const char* args
)
2363 // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2364 char* cId
= extractKeyFromLink((char*)args
,"Hgameobject_entry");
2368 uint32 go_id
= atol(cId
);
2371 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID
, go_id
);
2372 SetSentErrorMessage(true);
2376 GameObjectInfo
const * gInfo
= objmgr
.GetGameObjectInfo(go_id
);
2379 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID
, go_id
);
2380 SetSentErrorMessage(true);
2384 char* c_count
= strtok(NULL
, " ");
2385 int count
= c_count
? atol(c_count
) : 10;
2390 QueryResult
*result
;
2392 uint32 obj_count
= 0;
2393 result
=WorldDatabase
.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'",go_id
);
2396 obj_count
= (*result
)[0].GetUInt32();
2402 Player
* pl
= m_session
->GetPlayer();
2403 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",
2404 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(),go_id
,uint32(count
));
2407 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map FROM gameobject WHERE id = '%u' LIMIT %u",
2408 go_id
,uint32(count
));
2414 Field
*fields
= result
->Fetch();
2415 uint32 guid
= fields
[0].GetUInt32();
2416 float x
= fields
[1].GetFloat();
2417 float y
= fields
[2].GetFloat();
2418 float z
= fields
[3].GetFloat();
2419 int mapid
= fields
[4].GetUInt16();
2422 PSendSysMessage(LANG_GO_LIST_CHAT
, guid
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2424 PSendSysMessage(LANG_GO_LIST_CONSOLE
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2425 } while (result
->NextRow());
2430 PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE
,go_id
,obj_count
);
2434 bool ChatHandler::HandleListCreatureCommand(const char* args
)
2439 // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
2440 char* cId
= extractKeyFromLink((char*)args
,"Hcreature_entry");
2444 uint32 cr_id
= atol(cId
);
2447 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID
, cr_id
);
2448 SetSentErrorMessage(true);
2452 CreatureInfo
const* cInfo
= objmgr
.GetCreatureTemplate(cr_id
);
2455 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID
, cr_id
);
2456 SetSentErrorMessage(true);
2460 char* c_count
= strtok(NULL
, " ");
2461 int count
= c_count
? atol(c_count
) : 10;
2466 QueryResult
*result
;
2468 uint32 cr_count
= 0;
2469 result
=WorldDatabase
.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'",cr_id
);
2472 cr_count
= (*result
)[0].GetUInt32();
2478 Player
* pl
= m_session
->GetPlayer();
2479 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",
2480 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(), cr_id
,uint32(count
));
2483 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '%u' LIMIT %u",
2484 cr_id
,uint32(count
));
2490 Field
*fields
= result
->Fetch();
2491 uint32 guid
= fields
[0].GetUInt32();
2492 float x
= fields
[1].GetFloat();
2493 float y
= fields
[2].GetFloat();
2494 float z
= fields
[3].GetFloat();
2495 int mapid
= fields
[4].GetUInt16();
2498 PSendSysMessage(LANG_CREATURE_LIST_CHAT
, guid
, guid
, cInfo
->Name
, x
, y
, z
, mapid
);
2500 PSendSysMessage(LANG_CREATURE_LIST_CONSOLE
, guid
, cInfo
->Name
, x
, y
, z
, mapid
);
2501 } while (result
->NextRow());
2506 PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE
,cr_id
,cr_count
);
2510 bool ChatHandler::HandleLookupItemCommand(const char* args
)
2515 std::string namepart
= args
;
2516 std::wstring wnamepart
;
2518 // converting string that we try to find to lower case
2519 if(!Utf8toWStr(namepart
,wnamepart
))
2522 wstrToLower(wnamepart
);
2526 // Search in `item_template`
2527 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
2529 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
2533 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2536 ItemLocale
const *il
= objmgr
.GetItemLocale(pProto
->ItemId
);
2539 if (il
->Name
.size() > loc_idx
&& !il
->Name
[loc_idx
].empty())
2541 std::string name
= il
->Name
[loc_idx
];
2543 if (Utf8FitTo(name
, wnamepart
))
2546 PSendSysMessage(LANG_ITEM_LIST_CHAT
, id
, id
, name
.c_str());
2548 PSendSysMessage(LANG_ITEM_LIST_CONSOLE
, id
, name
.c_str());
2556 std::string name
= pProto
->Name1
;
2560 if (Utf8FitTo(name
, wnamepart
))
2563 PSendSysMessage(LANG_ITEM_LIST_CHAT
, id
, id
, name
.c_str());
2565 PSendSysMessage(LANG_ITEM_LIST_CONSOLE
, id
, name
.c_str());
2571 SendSysMessage(LANG_COMMAND_NOITEMFOUND
);
2576 bool ChatHandler::HandleLookupItemSetCommand(const char* args
)
2581 std::string namepart
= args
;
2582 std::wstring wnamepart
;
2584 if(!Utf8toWStr(namepart
,wnamepart
))
2587 // converting string that we try to find to lower case
2588 wstrToLower( wnamepart
);
2590 uint32 counter
= 0; // Counter for figure out that we found smth.
2592 // Search in ItemSet.dbc
2593 for (uint32 id
= 0; id
< sItemSetStore
.GetNumRows(); id
++)
2595 ItemSetEntry
const *set
= sItemSetStore
.LookupEntry(id
);
2598 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
2599 std::string name
= set
->name
[loc
];
2603 if (!Utf8FitTo(name
, wnamepart
))
2606 for(; loc
< MAX_LOCALE
; ++loc
)
2608 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
2611 name
= set
->name
[loc
];
2615 if (Utf8FitTo(name
, wnamepart
))
2620 if(loc
< MAX_LOCALE
)
2622 // send item set in "id - [namedlink locale]" format
2624 PSendSysMessage(LANG_ITEMSET_LIST_CHAT
,id
,id
,name
.c_str(),localeNames
[loc
]);
2626 PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE
,id
,name
.c_str(),localeNames
[loc
]);
2631 if (counter
== 0) // if counter == 0 then we found nth
2632 SendSysMessage(LANG_COMMAND_NOITEMSETFOUND
);
2636 bool ChatHandler::HandleLookupSkillCommand(const char* args
)
2641 // can be NULL in console call
2642 Player
* target
= getSelectedPlayer();
2644 std::string namepart
= args
;
2645 std::wstring wnamepart
;
2647 if(!Utf8toWStr(namepart
,wnamepart
))
2650 // converting string that we try to find to lower case
2651 wstrToLower( wnamepart
);
2653 uint32 counter
= 0; // Counter for figure out that we found smth.
2655 // Search in SkillLine.dbc
2656 for (uint32 id
= 0; id
< sSkillLineStore
.GetNumRows(); id
++)
2658 SkillLineEntry
const *skillInfo
= sSkillLineStore
.LookupEntry(id
);
2661 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
2662 std::string name
= skillInfo
->name
[loc
];
2666 if (!Utf8FitTo(name
, wnamepart
))
2669 for(; loc
< MAX_LOCALE
; ++loc
)
2671 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
2674 name
= skillInfo
->name
[loc
];
2678 if (Utf8FitTo(name
, wnamepart
))
2683 if(loc
< MAX_LOCALE
)
2685 char valStr
[50] = "";
2686 char const* knownStr
= "";
2687 if(target
&& target
->HasSkill(id
))
2689 knownStr
= GetMangosString(LANG_KNOWN
);
2690 uint32 curValue
= target
->GetPureSkillValue(id
);
2691 uint32 maxValue
= target
->GetPureMaxSkillValue(id
);
2692 uint32 permValue
= target
->GetSkillPermBonusValue(id
);
2693 uint32 tempValue
= target
->GetSkillTempBonusValue(id
);
2695 char const* valFormat
= GetMangosString(LANG_SKILL_VALUES
);
2696 snprintf(valStr
,50,valFormat
,curValue
,maxValue
,permValue
,tempValue
);
2699 // send skill in "id - [namedlink locale]" format
2701 PSendSysMessage(LANG_SKILL_LIST_CHAT
,id
,id
,name
.c_str(),localeNames
[loc
],knownStr
,valStr
);
2703 PSendSysMessage(LANG_SKILL_LIST_CONSOLE
,id
,name
.c_str(),localeNames
[loc
],knownStr
,valStr
);
2709 if (counter
== 0) // if counter == 0 then we found nth
2710 SendSysMessage(LANG_COMMAND_NOSKILLFOUND
);
2714 bool ChatHandler::HandleLookupSpellCommand(const char* args
)
2719 // can be NULL at console call
2720 Player
* target
= getSelectedPlayer();
2722 std::string namepart
= args
;
2723 std::wstring wnamepart
;
2725 if(!Utf8toWStr(namepart
,wnamepart
))
2728 // converting string that we try to find to lower case
2729 wstrToLower( wnamepart
);
2731 uint32 counter
= 0; // Counter for figure out that we found smth.
2733 // Search in Spell.dbc
2734 for (uint32 id
= 0; id
< sSpellStore
.GetNumRows(); id
++)
2736 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(id
);
2739 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
2740 std::string name
= spellInfo
->SpellName
[loc
];
2744 if (!Utf8FitTo(name
, wnamepart
))
2747 for(; loc
< MAX_LOCALE
; ++loc
)
2749 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
2752 name
= spellInfo
->SpellName
[loc
];
2756 if (Utf8FitTo(name
, wnamepart
))
2761 if(loc
< MAX_LOCALE
)
2763 bool known
= target
&& target
->HasSpell(id
);
2764 bool learn
= (spellInfo
->Effect
[0] == SPELL_EFFECT_LEARN_SPELL
);
2766 uint32 talentCost
= GetTalentSpellCost(id
);
2768 bool talent
= (talentCost
> 0);
2769 bool passive
= IsPassiveSpell(id
);
2770 bool active
= target
&& target
->HasAura(id
);
2772 // unit32 used to prevent interpreting uint8 as char at output
2773 // find rank of learned spell for learning spell, or talent rank
2774 uint32 rank
= talentCost
? talentCost
: spellmgr
.GetSpellRank(learn
? spellInfo
->EffectTriggerSpell
[0] : id
);
2776 // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
2777 std::ostringstream ss
;
2779 ss
<< id
<< " - |cffffffff|Hspell:" << id
<< "|h[" << name
;
2781 ss
<< id
<< " - " << name
;
2783 // include rank in link name
2785 ss
<< GetMangosString(LANG_SPELL_RANK
) << rank
;
2788 ss
<< " " << localeNames
[loc
] << "]|h|r";
2790 ss
<< " " << localeNames
[loc
];
2793 ss
<< GetMangosString(LANG_TALENT
);
2795 ss
<< GetMangosString(LANG_PASSIVE
);
2797 ss
<< GetMangosString(LANG_LEARN
);
2799 ss
<< GetMangosString(LANG_KNOWN
);
2801 ss
<< GetMangosString(LANG_ACTIVE
);
2803 SendSysMessage(ss
.str().c_str());
2809 if (counter
== 0) // if counter == 0 then we found nth
2810 SendSysMessage(LANG_COMMAND_NOSPELLFOUND
);
2814 bool ChatHandler::HandleLookupQuestCommand(const char* args
)
2819 // can be NULL at console call
2820 Player
* target
= getSelectedPlayer();
2822 std::string namepart
= args
;
2823 std::wstring wnamepart
;
2825 // converting string that we try to find to lower case
2826 if(!Utf8toWStr(namepart
,wnamepart
))
2829 wstrToLower(wnamepart
);
2831 uint32 counter
= 0 ;
2833 ObjectMgr::QuestMap
const& qTemplates
= objmgr
.GetQuestTemplates();
2834 for (ObjectMgr::QuestMap::const_iterator iter
= qTemplates
.begin(); iter
!= qTemplates
.end(); ++iter
)
2836 Quest
* qinfo
= iter
->second
;
2838 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2841 QuestLocale
const *il
= objmgr
.GetQuestLocale(qinfo
->GetQuestId());
2844 if (il
->Title
.size() > loc_idx
&& !il
->Title
[loc_idx
].empty())
2846 std::string title
= il
->Title
[loc_idx
];
2848 if (Utf8FitTo(title
, wnamepart
))
2850 char const* statusStr
= "";
2854 QuestStatus status
= target
->GetQuestStatus(qinfo
->GetQuestId());
2856 if(status
== QUEST_STATUS_COMPLETE
)
2858 if(target
->GetQuestRewardStatus(qinfo
->GetQuestId()))
2859 statusStr
= GetMangosString(LANG_COMMAND_QUEST_REWARDED
);
2861 statusStr
= GetMangosString(LANG_COMMAND_QUEST_COMPLETE
);
2863 else if(status
== QUEST_STATUS_INCOMPLETE
)
2864 statusStr
= GetMangosString(LANG_COMMAND_QUEST_ACTIVE
);
2868 PSendSysMessage(LANG_QUEST_LIST_CHAT
,qinfo
->GetQuestId(),qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2870 PSendSysMessage(LANG_QUEST_LIST_CONSOLE
,qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2878 std::string title
= qinfo
->GetTitle();
2882 if (Utf8FitTo(title
, wnamepart
))
2884 char const* statusStr
= "";
2888 QuestStatus status
= target
->GetQuestStatus(qinfo
->GetQuestId());
2890 if(status
== QUEST_STATUS_COMPLETE
)
2892 if(target
->GetQuestRewardStatus(qinfo
->GetQuestId()))
2893 statusStr
= GetMangosString(LANG_COMMAND_QUEST_REWARDED
);
2895 statusStr
= GetMangosString(LANG_COMMAND_QUEST_COMPLETE
);
2897 else if(status
== QUEST_STATUS_INCOMPLETE
)
2898 statusStr
= GetMangosString(LANG_COMMAND_QUEST_ACTIVE
);
2902 PSendSysMessage(LANG_QUEST_LIST_CHAT
,qinfo
->GetQuestId(),qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2904 PSendSysMessage(LANG_QUEST_LIST_CONSOLE
,qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2911 SendSysMessage(LANG_COMMAND_NOQUESTFOUND
);
2916 bool ChatHandler::HandleLookupCreatureCommand(const char* args
)
2921 std::string namepart
= args
;
2922 std::wstring wnamepart
;
2924 // converting string that we try to find to lower case
2925 if (!Utf8toWStr (namepart
,wnamepart
))
2928 wstrToLower (wnamepart
);
2932 for (uint32 id
= 0; id
< sCreatureStorage
.MaxEntry
; ++id
)
2934 CreatureInfo
const* cInfo
= sCreatureStorage
.LookupEntry
<CreatureInfo
> (id
);
2938 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2941 CreatureLocale
const *cl
= objmgr
.GetCreatureLocale (id
);
2944 if (cl
->Name
.size() > loc_idx
&& !cl
->Name
[loc_idx
].empty ())
2946 std::string name
= cl
->Name
[loc_idx
];
2948 if (Utf8FitTo (name
, wnamepart
))
2951 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str ());
2953 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE
, id
, name
.c_str ());
2961 std::string name
= cInfo
->Name
;
2965 if (Utf8FitTo(name
, wnamepart
))
2968 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str ());
2970 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE
, id
, name
.c_str ());
2976 SendSysMessage (LANG_COMMAND_NOCREATUREFOUND
);
2981 bool ChatHandler::HandleLookupObjectCommand(const char* args
)
2986 std::string namepart
= args
;
2987 std::wstring wnamepart
;
2989 // converting string that we try to find to lower case
2990 if(!Utf8toWStr(namepart
,wnamepart
))
2993 wstrToLower(wnamepart
);
2997 for (uint32 id
= 0; id
< sGOStorage
.MaxEntry
; id
++ )
2999 GameObjectInfo
const* gInfo
= sGOStorage
.LookupEntry
<GameObjectInfo
>(id
);
3003 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
3006 GameObjectLocale
const *gl
= objmgr
.GetGameObjectLocale(id
);
3009 if (gl
->Name
.size() > loc_idx
&& !gl
->Name
[loc_idx
].empty())
3011 std::string name
= gl
->Name
[loc_idx
];
3013 if (Utf8FitTo(name
, wnamepart
))
3016 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT
, id
, id
, name
.c_str());
3018 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE
, id
, name
.c_str());
3026 std::string name
= gInfo
->name
;
3030 if(Utf8FitTo(name
, wnamepart
))
3033 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT
, id
, id
, name
.c_str());
3035 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE
, id
, name
.c_str());
3041 SendSysMessage(LANG_COMMAND_NOGAMEOBJECTFOUND
);
3046 /** \brief GM command level 3 - Create a guild.
3048 * This command allows a GM (level 3) to create a guild.
3050 * The "args" parameter contains the name of the guild leader
3051 * and then the name of the guild.
3054 bool ChatHandler::HandleGuildCreateCommand(const char* args
)
3060 char *lname
= strtok ((char*)args
, " ");
3061 char *gname
= strtok (NULL
, "");
3068 SendSysMessage (LANG_INSERT_GUILD_NAME
);
3069 SetSentErrorMessage (true);
3073 std::string guildname
= gname
;
3075 Player
* player
= ObjectAccessor::Instance ().FindPlayerByName (lname
);
3078 SendSysMessage (LANG_PLAYER_NOT_FOUND
);
3079 SetSentErrorMessage (true);
3083 if (player
->GetGuildId())
3085 SendSysMessage (LANG_PLAYER_IN_GUILD
);
3089 Guild
*guild
= new Guild
;
3090 if (!guild
->create (player
,guildname
))
3093 SendSysMessage (LANG_GUILD_NOT_CREATED
);
3094 SetSentErrorMessage (true);
3098 objmgr
.AddGuild (guild
);
3102 bool ChatHandler::HandleGuildInviteCommand(const char *args
)
3107 char* par1
= strtok ((char*)args
, " ");
3108 char* par2
= strtok (NULL
, "");
3112 std::string glName
= par2
;
3113 Guild
* targetGuild
= objmgr
.GetGuildByName (glName
);
3117 std::string plName
= extractPlayerNameFromLink(par1
);
3120 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3121 SetSentErrorMessage(true);
3126 if (Player
* targetPlayer
= ObjectAccessor::Instance ().FindPlayerByName (plName
.c_str ()))
3127 plGuid
= targetPlayer
->GetGUID ();
3129 plGuid
= objmgr
.GetPlayerGUIDByName (plName
);
3134 // player's guild membership checked in AddMember before add
3135 if (!targetGuild
->AddMember (plGuid
,targetGuild
->GetLowestRank ()))
3141 bool ChatHandler::HandleGuildUninviteCommand(const char *args
)
3146 char* par1
= strtok ((char*)args
, " ");
3150 std::string plName
= extractPlayerNameFromLink(par1
);
3153 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3154 SetSentErrorMessage(true);
3160 if (Player
* targetPlayer
= ObjectAccessor::Instance ().FindPlayerByName (plName
.c_str ()))
3162 plGuid
= targetPlayer
->GetGUID ();
3163 glId
= targetPlayer
->GetGuildId ();
3167 plGuid
= objmgr
.GetPlayerGUIDByName (plName
);
3168 glId
= Player::GetGuildIdFromDB (plGuid
);
3171 if (!plGuid
|| !glId
)
3174 Guild
* targetGuild
= objmgr
.GetGuildById (glId
);
3178 targetGuild
->DelMember (plGuid
);
3183 bool ChatHandler::HandleGuildRankCommand(const char *args
)
3188 char* par1
= strtok ((char*)args
, " ");
3189 char* par2
= strtok (NULL
, " ");
3193 std::string plName
= extractPlayerNameFromLink(par1
);
3196 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3197 SetSentErrorMessage(true);
3204 if (Player
* targetPlayer
= ObjectAccessor::Instance ().FindPlayerByName (plName
.c_str ()))
3206 plGuid
= targetPlayer
->GetGUID ();
3207 glId
= targetPlayer
->GetGuildId ();
3211 plGuid
= objmgr
.GetPlayerGUIDByName (plName
);
3212 glId
= Player::GetGuildIdFromDB (plGuid
);
3215 if (!plGuid
|| !glId
)
3218 Guild
* targetGuild
= objmgr
.GetGuildById (glId
);
3222 uint32 newrank
= uint32 (atoi (par2
));
3223 if (newrank
> targetGuild
->GetLowestRank ())
3226 targetGuild
->ChangeRank (plGuid
,newrank
);
3231 bool ChatHandler::HandleGuildDeleteCommand(const char* args
)
3236 char* par1
= strtok ((char*)args
, " ");
3240 std::string gld
= par1
;
3242 Guild
* targetGuild
= objmgr
.GetGuildByName (gld
);
3246 targetGuild
->Disband ();
3251 bool ChatHandler::HandleGetDistanceCommand(const char* args
)
3253 WorldObject
* obj
= NULL
;
3257 uint64 guid
= extractGuidFromLink((char*)args
);
3259 obj
= (WorldObject
*)ObjectAccessor::GetObjectByTypeMask(*m_session
->GetPlayer(),guid
,TYPEMASK_UNIT
|TYPEMASK_GAMEOBJECT
);
3263 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3264 SetSentErrorMessage(true);
3270 obj
= getSelectedUnit();
3274 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3275 SetSentErrorMessage(true);
3280 PSendSysMessage(LANG_DISTANCE
, m_session
->GetPlayer()->GetDistance(obj
),m_session
->GetPlayer()->GetDistance2d(obj
));
3285 bool ChatHandler::HandleDieCommand(const char* /*args*/)
3287 Unit
* target
= getSelectedUnit();
3289 if(!target
|| !m_session
->GetPlayer()->GetSelection())
3291 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3292 SetSentErrorMessage(true);
3296 if(target
->GetTypeId()==TYPEID_PLAYER
)
3298 if(HasLowerSecurity((Player
*)target
,0,false))
3302 if( target
->isAlive() )
3304 m_session
->GetPlayer()->DealDamage(target
, target
->GetHealth(), NULL
, DIRECT_DAMAGE
, SPELL_SCHOOL_MASK_NORMAL
, NULL
, false);
3310 bool ChatHandler::HandleDamageCommand(const char * args
)
3315 Unit
* target
= getSelectedUnit();
3317 if(!target
|| !m_session
->GetPlayer()->GetSelection())
3319 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3320 SetSentErrorMessage(true);
3324 if( !target
->isAlive() )
3327 char* damageStr
= strtok((char*)args
, " ");
3331 int32 damage
= atoi((char*)damageStr
);
3335 char* schoolStr
= strtok((char*)NULL
, " ");
3337 // flat melee damage without resistence/etc reduction
3340 m_session
->GetPlayer()->DealDamage(target
, damage
, NULL
, DIRECT_DAMAGE
, SPELL_SCHOOL_MASK_NORMAL
, NULL
, false);
3341 m_session
->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2
, target
, 1, SPELL_SCHOOL_MASK_NORMAL
, damage
, 0, 0, VICTIMSTATE_NORMAL
, 0);
3345 uint32 school
= schoolStr
? atoi((char*)schoolStr
) : SPELL_SCHOOL_NORMAL
;
3346 if(school
>= MAX_SPELL_SCHOOL
)
3349 SpellSchoolMask schoolmask
= SpellSchoolMask(1 << school
);
3351 if ( schoolmask
& SPELL_SCHOOL_MASK_NORMAL
)
3352 damage
= m_session
->GetPlayer()->CalcArmorReducedDamage(target
, damage
);
3354 char* spellStr
= strtok((char*)NULL
, " ");
3356 // melee damage by specific school
3362 m_session
->GetPlayer()->CalcAbsorbResist(target
,schoolmask
, SPELL_DIRECT_DAMAGE
, damage
, &absorb
, &resist
);
3364 if (damage
<= absorb
+ resist
)
3367 damage
-= absorb
+ resist
;
3369 m_session
->GetPlayer()->DealDamage(target
, damage
, NULL
, DIRECT_DAMAGE
, schoolmask
, NULL
, false);
3370 m_session
->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2
, target
, 1, schoolmask
, damage
, absorb
, resist
, VICTIMSTATE_NORMAL
, 0);
3376 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3377 uint32 spellid
= extractSpellIdFromLink((char*)args
);
3378 if(!spellid
|| !sSpellStore
.LookupEntry(spellid
))
3381 m_session
->GetPlayer()->SpellNonMeleeDamageLog(target
, spellid
, damage
, false);
3385 bool ChatHandler::HandleModifyArenaCommand(const char * args
)
3390 Player
*target
= getSelectedPlayer();
3393 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3394 SetSentErrorMessage(true);
3398 int32 amount
= (uint32
)atoi(args
);
3400 target
->ModifyArenaPoints(amount
);
3402 PSendSysMessage(LANG_COMMAND_MODIFY_ARENA
, GetNameLink(target
).c_str(), target
->GetArenaPoints());
3407 bool ChatHandler::HandleReviveCommand(const char* args
)
3409 Player
* SelectedPlayer
= NULL
;
3413 std::string name
= extractPlayerNameFromLink((char*)args
);
3416 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3417 SetSentErrorMessage(true);
3421 SelectedPlayer
= objmgr
.GetPlayer(name
.c_str());
3424 SelectedPlayer
= getSelectedPlayer();
3428 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3429 SetSentErrorMessage(true);
3433 SelectedPlayer
->ResurrectPlayer(0.5f
);
3434 SelectedPlayer
->SpawnCorpseBones();
3435 SelectedPlayer
->SaveToDB();
3439 bool ChatHandler::HandleAuraCommand(const char* args
)
3441 Unit
*target
= getSelectedUnit();
3444 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3445 SetSentErrorMessage(true);
3449 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3450 uint32 spellID
= extractSpellIdFromLink((char*)args
);
3452 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry( spellID
);
3455 for(uint32 i
= 0;i
<3;i
++)
3457 uint8 eff
= spellInfo
->Effect
[i
];
3458 if (eff
>=TOTAL_SPELL_EFFECTS
)
3460 if( IsAreaAuraEffect(eff
) ||
3461 eff
== SPELL_EFFECT_APPLY_AURA
||
3462 eff
== SPELL_EFFECT_PERSISTENT_AREA_AURA
)
3464 Aura
*Aur
= CreateAura(spellInfo
, i
, NULL
, target
);
3465 target
->AddAura(Aur
);
3473 bool ChatHandler::HandleUnAuraCommand(const char* args
)
3475 Unit
*target
= getSelectedUnit();
3478 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3479 SetSentErrorMessage(true);
3483 std::string argstr
= args
;
3484 if (argstr
== "all")
3486 target
->RemoveAllAuras();
3490 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3491 uint32 spellID
= extractSpellIdFromLink((char*)args
);
3495 target
->RemoveAurasDueToSpell(spellID
);
3500 bool ChatHandler::HandleLinkGraveCommand(const char* args
)
3505 char* px
= strtok((char*)args
, " ");
3509 uint32 g_id
= (uint32
)atoi(px
);
3513 char* px2
= strtok(NULL
, " ");
3517 else if (strncmp(px2
,"horde",6)==0)
3519 else if (strncmp(px2
,"alliance",9)==0)
3524 WorldSafeLocsEntry
const* graveyard
= sWorldSafeLocsStore
.LookupEntry(g_id
);
3528 PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST
, g_id
);
3529 SetSentErrorMessage(true);
3533 Player
* player
= m_session
->GetPlayer();
3535 uint32 zoneId
= player
->GetZoneId();
3537 AreaTableEntry
const *areaEntry
= GetAreaEntryByAreaID(zoneId
);
3538 if(!areaEntry
|| areaEntry
->zone
!=0 )
3540 PSendSysMessage(LANG_COMMAND_GRAVEYARDWRONGZONE
, g_id
,zoneId
);
3541 SetSentErrorMessage(true);
3545 if(objmgr
.AddGraveYardLink(g_id
,zoneId
,g_team
))
3546 PSendSysMessage(LANG_COMMAND_GRAVEYARDLINKED
, g_id
,zoneId
);
3548 PSendSysMessage(LANG_COMMAND_GRAVEYARDALRLINKED
, g_id
,zoneId
);
3553 bool ChatHandler::HandleNearGraveCommand(const char* args
)
3557 size_t argslen
= strlen(args
);
3561 else if (strncmp((char*)args
,"horde",argslen
)==0)
3563 else if (strncmp((char*)args
,"alliance",argslen
)==0)
3568 Player
* player
= m_session
->GetPlayer();
3569 uint32 zone_id
= player
->GetZoneId();
3571 WorldSafeLocsEntry
const* graveyard
= objmgr
.GetClosestGraveYard(
3572 player
->GetPositionX(), player
->GetPositionY(), player
->GetPositionZ(),player
->GetMapId(),g_team
);
3576 uint32 g_id
= graveyard
->ID
;
3578 GraveYardData
const* data
= objmgr
.FindGraveYardData(g_id
,zone_id
);
3581 PSendSysMessage(LANG_COMMAND_GRAVEYARDERROR
,g_id
);
3582 SetSentErrorMessage(true);
3586 g_team
= data
->team
;
3588 std::string team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_NOTEAM
);
3591 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ANY
);
3592 else if(g_team
== HORDE
)
3593 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE
);
3594 else if(g_team
== ALLIANCE
)
3595 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE
);
3597 PSendSysMessage(LANG_COMMAND_GRAVEYARDNEAREST
, g_id
,team_name
.c_str(),zone_id
);
3601 std::string team_name
;
3604 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ANY
);
3605 else if(g_team
== HORDE
)
3606 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE
);
3607 else if(g_team
== ALLIANCE
)
3608 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE
);
3610 if(g_team
== ~uint32(0))
3611 PSendSysMessage(LANG_COMMAND_ZONENOGRAVEYARDS
, zone_id
);
3613 PSendSysMessage(LANG_COMMAND_ZONENOGRAFACTION
, zone_id
,team_name
.c_str());
3619 //-----------------------Npc Commands-----------------------
3620 bool ChatHandler::HandleNpcAllowMovementCommand(const char* /*args*/)
3622 if(sWorld
.getAllowMovement())
3624 sWorld
.SetAllowMovement(false);
3625 SendSysMessage(LANG_CREATURE_MOVE_DISABLED
);
3629 sWorld
.SetAllowMovement(true);
3630 SendSysMessage(LANG_CREATURE_MOVE_ENABLED
);
3635 bool ChatHandler::HandleNpcChangeEntryCommand(const char *args
)
3640 uint32 newEntryNum
= atoi(args
);
3644 Unit
* unit
= getSelectedUnit();
3645 if(!unit
|| unit
->GetTypeId() != TYPEID_UNIT
)
3647 SendSysMessage(LANG_SELECT_CREATURE
);
3648 SetSentErrorMessage(true);
3651 Creature
* creature
= (Creature
*)unit
;
3652 if(creature
->UpdateEntry(newEntryNum
))
3653 SendSysMessage(LANG_DONE
);
3655 SendSysMessage(LANG_ERROR
);
3659 bool ChatHandler::HandleNpcInfoCommand(const char* /*args*/)
3661 Creature
* target
= getSelectedCreature();
3665 SendSysMessage(LANG_SELECT_CREATURE
);
3666 SetSentErrorMessage(true);
3670 uint32 faction
= target
->getFaction();
3671 uint32 npcflags
= target
->GetUInt32Value(UNIT_NPC_FLAGS
);
3672 uint32 displayid
= target
->GetDisplayId();
3673 uint32 nativeid
= target
->GetNativeDisplayId();
3674 uint32 Entry
= target
->GetEntry();
3675 CreatureInfo
const* cInfo
= target
->GetCreatureInfo();
3677 int32 curRespawnDelay
= target
->GetRespawnTimeEx()-time(NULL
);
3678 if(curRespawnDelay
< 0)
3679 curRespawnDelay
= 0;
3680 std::string curRespawnDelayStr
= secsToTimeString(curRespawnDelay
,true);
3681 std::string defRespawnDelayStr
= secsToTimeString(target
->GetRespawnDelay(),true);
3683 PSendSysMessage(LANG_NPCINFO_CHAR
, target
->GetDBTableGUIDLow(), faction
, npcflags
, Entry
, displayid
, nativeid
);
3684 PSendSysMessage(LANG_NPCINFO_LEVEL
, target
->getLevel());
3685 PSendSysMessage(LANG_NPCINFO_HEALTH
,target
->GetCreateHealth(), target
->GetMaxHealth(), target
->GetHealth());
3686 PSendSysMessage(LANG_NPCINFO_FLAGS
, target
->GetUInt32Value(UNIT_FIELD_FLAGS
), target
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
), target
->getFaction());
3687 PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES
, defRespawnDelayStr
.c_str(),curRespawnDelayStr
.c_str());
3688 PSendSysMessage(LANG_NPCINFO_LOOT
, cInfo
->lootid
,cInfo
->pickpocketLootId
,cInfo
->SkinLootId
);
3689 PSendSysMessage(LANG_NPCINFO_DUNGEON_ID
, target
->GetInstanceId());
3690 PSendSysMessage(LANG_NPCINFO_POSITION
,float(target
->GetPositionX()), float(target
->GetPositionY()), float(target
->GetPositionZ()));
3692 if ((npcflags
& UNIT_NPC_FLAG_VENDOR
) )
3694 SendSysMessage(LANG_NPCINFO_VENDOR
);
3696 if ((npcflags
& UNIT_NPC_FLAG_TRAINER
) )
3698 SendSysMessage(LANG_NPCINFO_TRAINER
);
3705 bool ChatHandler::HandleNpcPlayEmoteCommand(const char* args
)
3707 uint32 emote
= atoi((char*)args
);
3709 Creature
* target
= getSelectedCreature();
3712 SendSysMessage(LANG_SELECT_CREATURE
);
3713 SetSentErrorMessage(true);
3717 target
->SetUInt32Value(UNIT_NPC_EMOTESTATE
,emote
);
3722 //TODO: NpcCommands that needs to be fixed :
3724 bool ChatHandler::HandleNpcAddWeaponCommand(const char* /*args*/)
3729 uint64 guid = m_session->GetPlayer()->GetSelection();
3732 SendSysMessage(LANG_NO_SELECTION);
3736 Creature *pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
3740 SendSysMessage(LANG_SELECT_CREATURE);
3744 char* pSlotID = strtok((char*)args, " ");
3748 char* pItemID = strtok(NULL, " ");
3752 uint32 ItemID = atoi(pItemID);
3753 uint32 SlotID = atoi(pSlotID);
3755 ItemPrototype* tmpItem = objmgr.GetItemPrototype(ItemID);
3763 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID);
3767 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID);
3771 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID);
3775 PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST,SlotID);
3781 PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT,ItemID,tmpItem->Name1,SlotID);
3785 PSendSysMessage(LANG_ITEM_NOT_FOUND,ItemID);
3791 //----------------------------------------------------------
3793 bool ChatHandler::HandleExploreCheatCommand(const char* args
)
3798 int flag
= atoi((char*)args
);
3800 Player
*chr
= getSelectedPlayer();
3803 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3804 SetSentErrorMessage(true);
3810 PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL
, GetNameLink(chr
).c_str());
3811 if (needReportToTarget(chr
))
3812 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_EXPLORE_SET_ALL
,GetNameLink().c_str());
3816 PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING
, GetNameLink(chr
).c_str());
3817 if (needReportToTarget(chr
))
3818 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_EXPLORE_SET_NOTHING
,GetNameLink().c_str());
3821 for (uint8 i
=0; i
<128; i
++)
3825 m_session
->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1
+i
,0xFFFFFFFF);
3829 m_session
->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1
+i
,0);
3836 bool ChatHandler::HandleHoverCommand(const char* args
)
3838 char* px
= strtok((char*)args
, " ");
3845 m_session
->GetPlayer()->SetHover(flag
);
3848 SendSysMessage(LANG_HOVER_ENABLED
);
3850 SendSysMessage(LANG_HOVER_DISABLED
);
3855 bool ChatHandler::HandleLevelUpCommand(const char* args
)
3857 char* px
= strtok((char*)args
, " ");
3858 char* py
= strtok((char*)NULL
, " ");
3860 // command format parsing
3861 char* pname
= (char*)NULL
;
3864 if(px
&& py
) // .levelup name level
3866 addlevel
= atoi(py
);
3869 else if(px
&& !py
) // .levelup name OR .levelup level
3871 if(isalpha(px
[0])) // .levelup name
3873 else // .levelup level
3874 addlevel
= atoi(px
);
3876 // else .levelup - nothing do for preparing
3880 uint64 chr_guid
= 0;
3884 if(pname
) // player by name
3886 name
= extractPlayerNameFromLink(pname
);
3889 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3890 SetSentErrorMessage(true);
3894 chr
= objmgr
.GetPlayer(name
.c_str());
3895 if(!chr
) // not in game
3897 chr_guid
= objmgr
.GetPlayerGUIDByName(name
);
3900 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3901 SetSentErrorMessage(true);
3906 else // player by selection
3908 chr
= getSelectedPlayer();
3912 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3913 SetSentErrorMessage(true);
3917 name
= chr
->GetName();
3920 assert(chr
|| chr_guid
);
3922 int32 oldlevel
= chr
? chr
->getLevel() : Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL
,chr_guid
);
3923 int32 newlevel
= oldlevel
+ addlevel
;
3926 if(newlevel
> STRONG_MAX_LEVEL
) // hardcoded maximum level
3927 newlevel
= STRONG_MAX_LEVEL
;
3931 chr
->GiveLevel(newlevel
);
3932 chr
->InitTalentForLevel();
3933 chr
->SetUInt32Value(PLAYER_XP
,0);
3935 if(oldlevel
== newlevel
)
3936 ChatHandler(chr
).SendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET
);
3938 if(oldlevel
< newlevel
)
3939 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_LEVEL_UP
,newlevel
-oldlevel
);
3941 if(oldlevel
> newlevel
)
3942 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_LEVEL_DOWN
,newlevel
-oldlevel
);
3946 // update level and XP at level, all other will be updated at loading
3948 Player::LoadValuesArrayFromDB(values
,chr_guid
);
3949 Player::SetUInt32ValueInArray(values
,UNIT_FIELD_LEVEL
,newlevel
);
3950 Player::SetUInt32ValueInArray(values
,PLAYER_XP
,0);
3951 Player::SaveValuesArrayInDB(values
,chr_guid
);
3954 if(m_session
->GetPlayer() != chr
) // including chr==NULL
3956 std::string nameLink
= playerLink(name
);
3957 PSendSysMessage(LANG_YOU_CHANGE_LVL
,nameLink
.c_str(),newlevel
);
3962 bool ChatHandler::HandleShowAreaCommand(const char* args
)
3967 Player
*chr
= getSelectedPlayer();
3970 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3971 SetSentErrorMessage(true);
3975 int area
= GetAreaFlagByAreaID(atoi((char*)args
));
3976 int offset
= area
/ 32;
3977 uint32 val
= (uint32
)(1 << (area
% 32));
3979 if(area
<0 || offset
>= 128)
3981 SendSysMessage(LANG_BAD_VALUE
);
3982 SetSentErrorMessage(true);
3986 uint32 currFields
= chr
->GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
3987 chr
->SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
| val
));
3989 SendSysMessage(LANG_EXPLORE_AREA
);
3993 bool ChatHandler::HandleHideAreaCommand(const char* args
)
3998 Player
*chr
= getSelectedPlayer();
4001 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4002 SetSentErrorMessage(true);
4006 int area
= GetAreaFlagByAreaID(atoi((char*)args
));
4007 int offset
= area
/ 32;
4008 uint32 val
= (uint32
)(1 << (area
% 32));
4010 if(area
<0 || offset
>= 128)
4012 SendSysMessage(LANG_BAD_VALUE
);
4013 SetSentErrorMessage(true);
4017 uint32 currFields
= chr
->GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
4018 chr
->SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
^ val
));
4020 SendSysMessage(LANG_UNEXPLORE_AREA
);
4024 bool ChatHandler::HandleDebugUpdate(const char* args
)
4032 char* pUpdateIndex
= strtok((char*)args
, " ");
4034 Unit
* chr
= getSelectedUnit();
4037 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4038 SetSentErrorMessage(true);
4046 updateIndex
= atoi(pUpdateIndex
);
4048 if(chr
->GetTypeId() == TYPEID_PLAYER
)
4050 if (updateIndex
>=PLAYER_END
) return true;
4054 if (updateIndex
>=UNIT_END
) return true;
4057 char* pvalue
= strtok(NULL
, " ");
4060 value
=chr
->GetUInt32Value(updateIndex
);
4062 PSendSysMessage(LANG_UPDATE
, chr
->GetGUIDLow(),updateIndex
,value
);
4068 PSendSysMessage(LANG_UPDATE_CHANGE
, chr
->GetGUIDLow(),updateIndex
,value
);
4070 chr
->SetUInt32Value(updateIndex
,value
);
4075 bool ChatHandler::HandleBankCommand(const char* /*args*/)
4077 m_session
->SendShowBank( m_session
->GetPlayer()->GetGUID() );
4082 bool ChatHandler::HandleChangeWeather(const char* args
)
4088 if (!sWorld
.getConfig(CONFIG_WEATHER
))
4090 SendSysMessage(LANG_WEATHER_DISABLED
);
4091 SetSentErrorMessage(true);
4095 //*Change the weather of a cell
4096 char* px
= strtok((char*)args
, " ");
4097 char* py
= strtok(NULL
, " ");
4102 uint32 type
= (uint32
)atoi(px
); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
4103 float grade
= (float)atof(py
); //0 to 1, sending -1 is instand good weather
4105 Player
*player
= m_session
->GetPlayer();
4106 uint32 zoneid
= player
->GetZoneId();
4108 Weather
* wth
= sWorld
.FindWeather(zoneid
);
4111 wth
= sWorld
.AddWeather(zoneid
);
4114 SendSysMessage(LANG_NO_WEATHER
);
4115 SetSentErrorMessage(true);
4119 wth
->SetWeather(WeatherType(type
), grade
);
4124 bool ChatHandler::HandleDebugSetValue(const char* args
)
4129 char* px
= strtok((char*)args
, " ");
4130 char* py
= strtok(NULL
, " ");
4131 char* pz
= strtok(NULL
, " ");
4136 Unit
* target
= getSelectedUnit();
4139 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4140 SetSentErrorMessage(true);
4144 uint64 guid
= target
->GetGUID();
4146 uint32 Opcode
= (uint32
)atoi(px
);
4147 if(Opcode
>= target
->GetValuesCount())
4149 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, GUID_LOPART(guid
), target
->GetValuesCount());
4154 bool isint32
= true;
4156 isint32
= (bool)atoi(pz
);
4159 iValue
= (uint32
)atoi(py
);
4160 sLog
.outDebug(GetMangosString(LANG_SET_UINT
), GUID_LOPART(guid
), Opcode
, iValue
);
4161 target
->SetUInt32Value( Opcode
, iValue
);
4162 PSendSysMessage(LANG_SET_UINT_FIELD
, GUID_LOPART(guid
), Opcode
,iValue
);
4166 fValue
= (float)atof(py
);
4167 sLog
.outDebug(GetMangosString(LANG_SET_FLOAT
), GUID_LOPART(guid
), Opcode
, fValue
);
4168 target
->SetFloatValue( Opcode
, fValue
);
4169 PSendSysMessage(LANG_SET_FLOAT_FIELD
, GUID_LOPART(guid
), Opcode
,fValue
);
4175 bool ChatHandler::HandleDebugGetValue(const char* args
)
4180 char* px
= strtok((char*)args
, " ");
4181 char* pz
= strtok(NULL
, " ");
4186 Unit
* target
= getSelectedUnit();
4189 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4190 SetSentErrorMessage(true);
4194 uint64 guid
= target
->GetGUID();
4196 uint32 Opcode
= (uint32
)atoi(px
);
4197 if(Opcode
>= target
->GetValuesCount())
4199 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, GUID_LOPART(guid
), target
->GetValuesCount());
4204 bool isint32
= true;
4206 isint32
= (bool)atoi(pz
);
4210 iValue
= target
->GetUInt32Value( Opcode
);
4211 sLog
.outDebug(GetMangosString(LANG_GET_UINT
), GUID_LOPART(guid
), Opcode
, iValue
);
4212 PSendSysMessage(LANG_GET_UINT_FIELD
, GUID_LOPART(guid
), Opcode
, iValue
);
4216 fValue
= target
->GetFloatValue( Opcode
);
4217 sLog
.outDebug(GetMangosString(LANG_GET_FLOAT
), GUID_LOPART(guid
), Opcode
, fValue
);
4218 PSendSysMessage(LANG_GET_FLOAT_FIELD
, GUID_LOPART(guid
), Opcode
, fValue
);
4224 bool ChatHandler::HandleSet32Bit(const char* args
)
4229 char* px
= strtok((char*)args
, " ");
4230 char* py
= strtok(NULL
, " ");
4235 uint32 Opcode
= (uint32
)atoi(px
);
4236 uint32 Value
= (uint32
)atoi(py
);
4237 if (Value
> 32) //uint32 = 32 bits
4240 sLog
.outDebug(GetMangosString(LANG_SET_32BIT
), Opcode
, Value
);
4242 m_session
->GetPlayer( )->SetUInt32Value( Opcode
, 2^Value
);
4244 PSendSysMessage(LANG_SET_32BIT_FIELD
, Opcode
,1);
4248 bool ChatHandler::HandleDebugMod32Value(const char* args
)
4253 char* px
= strtok((char*)args
, " ");
4254 char* py
= strtok(NULL
, " ");
4259 uint32 Opcode
= (uint32
)atoi(px
);
4260 int Value
= atoi(py
);
4262 if(Opcode
>= m_session
->GetPlayer()->GetValuesCount())
4264 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, m_session
->GetPlayer()->GetGUIDLow(), m_session
->GetPlayer( )->GetValuesCount());
4268 sLog
.outDebug(GetMangosString(LANG_CHANGE_32BIT
), Opcode
, Value
);
4270 int CurrentValue
= (int)m_session
->GetPlayer( )->GetUInt32Value( Opcode
);
4272 CurrentValue
+= Value
;
4273 m_session
->GetPlayer( )->SetUInt32Value( Opcode
, (uint32
)CurrentValue
);
4275 PSendSysMessage(LANG_CHANGE_32BIT_FIELD
, Opcode
,CurrentValue
);
4280 bool ChatHandler::HandleTeleAddCommand(const char * args
)
4285 Player
*player
=m_session
->GetPlayer();
4289 std::string name
= args
;
4291 if(objmgr
.GetGameTele(name
))
4293 SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST
);
4294 SetSentErrorMessage(true);
4299 tele
.position_x
= player
->GetPositionX();
4300 tele
.position_y
= player
->GetPositionY();
4301 tele
.position_z
= player
->GetPositionZ();
4302 tele
.orientation
= player
->GetOrientation();
4303 tele
.mapId
= player
->GetMapId();
4306 if(objmgr
.AddGameTele(tele
))
4308 SendSysMessage(LANG_COMMAND_TP_ADDED
);
4312 SendSysMessage(LANG_COMMAND_TP_ADDEDERR
);
4313 SetSentErrorMessage(true);
4320 bool ChatHandler::HandleTeleDelCommand(const char * args
)
4325 std::string name
= args
;
4327 if(!objmgr
.DeleteGameTele(name
))
4329 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
4330 SetSentErrorMessage(true);
4334 SendSysMessage(LANG_COMMAND_TP_DELETED
);
4338 bool ChatHandler::HandleListAurasCommand (const char * /*args*/)
4340 Unit
*unit
= getSelectedUnit();
4343 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4344 SetSentErrorMessage(true);
4348 char const* talentStr
= GetMangosString(LANG_TALENT
);
4349 char const* passiveStr
= GetMangosString(LANG_PASSIVE
);
4351 Unit::AuraMap
const& uAuras
= unit
->GetAuras();
4352 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS
, uAuras
.size());
4353 for (Unit::AuraMap::const_iterator itr
= uAuras
.begin(); itr
!= uAuras
.end(); ++itr
)
4355 bool talent
= GetTalentSpellCost(itr
->second
->GetId()) > 0;
4357 char const* name
= itr
->second
->GetSpellProto()->SpellName
[m_session
->GetSessionDbcLocale()];
4361 std::ostringstream ss_name
;
4362 ss_name
<< "|cffffffff|Hspell:" << itr
->second
->GetId() << "|h[" << name
<< "]|h|r";
4364 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL
, itr
->second
->GetId(), itr
->second
->GetEffIndex(),
4365 itr
->second
->GetModifier()->m_auraname
, itr
->second
->GetAuraDuration(), itr
->second
->GetAuraMaxDuration(),
4366 ss_name
.str().c_str(),
4367 (itr
->second
->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4368 IS_PLAYER_GUID(itr
->second
->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr
->second
->GetCasterGUID()));
4372 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL
, itr
->second
->GetId(), itr
->second
->GetEffIndex(),
4373 itr
->second
->GetModifier()->m_auraname
, itr
->second
->GetAuraDuration(), itr
->second
->GetAuraMaxDuration(),
4375 (itr
->second
->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4376 IS_PLAYER_GUID(itr
->second
->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr
->second
->GetCasterGUID()));
4379 for (int i
= 0; i
< TOTAL_AURAS
; i
++)
4381 Unit::AuraList
const& uAuraList
= unit
->GetAurasByType(AuraType(i
));
4382 if (uAuraList
.empty()) continue;
4383 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE
, uAuraList
.size(), i
);
4384 for (Unit::AuraList::const_iterator itr
= uAuraList
.begin(); itr
!= uAuraList
.end(); ++itr
)
4386 bool talent
= GetTalentSpellCost((*itr
)->GetId()) > 0;
4388 char const* name
= (*itr
)->GetSpellProto()->SpellName
[m_session
->GetSessionDbcLocale()];
4392 std::ostringstream ss_name
;
4393 ss_name
<< "|cffffffff|Hspell:" << (*itr
)->GetId() << "|h[" << name
<< "]|h|r";
4395 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE
, (*itr
)->GetId(), (*itr
)->GetEffIndex(),
4396 ss_name
.str().c_str(),((*itr
)->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4397 IS_PLAYER_GUID((*itr
)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr
)->GetCasterGUID()));
4401 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE
, (*itr
)->GetId(), (*itr
)->GetEffIndex(),
4402 name
,((*itr
)->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4403 IS_PLAYER_GUID((*itr
)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr
)->GetCasterGUID()));
4410 bool ChatHandler::HandleResetAchievementsCommand (const char * args
)
4412 char* pName
= strtok((char*)args
, "");
4413 Player
*player
= NULL
;
4417 std::string name
= extractPlayerNameFromLink(pName
);
4420 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4421 SetSentErrorMessage(true);
4425 guid
= objmgr
.GetPlayerGUIDByName(name
);
4426 player
= objmgr
.GetPlayer(guid
);
4430 player
= getSelectedPlayer();
4432 guid
= player
->GetGUID();
4435 if(!player
&& !guid
)
4437 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4442 player
->GetAchievementMgr().Reset();
4444 AchievementMgr::DeleteFromDB(GUID_LOPART(guid
));
4449 bool ChatHandler::HandleResetHonorCommand (const char * args
)
4451 char* pName
= strtok((char*)args
, "");
4452 Player
*player
= NULL
;
4455 std::string name
= extractPlayerNameFromLink(pName
);
4458 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4459 SetSentErrorMessage(true);
4463 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
);
4464 player
= objmgr
.GetPlayer(guid
);
4467 player
= getSelectedPlayer();
4471 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4475 player
->SetUInt32Value(PLAYER_FIELD_KILLS
, 0);
4476 player
->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS
, 0);
4477 player
->SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY
, 0);
4478 player
->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION
, 0);
4479 player
->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION
, 0);
4484 static bool HandleResetStatsOrLevelHelper(Player
* player
)
4486 PlayerInfo
const *info
= objmgr
.GetPlayerInfo(player
->getRace(), player
->getClass());
4487 if(!info
) return false;
4489 ChrClassesEntry
const* cEntry
= sChrClassesStore
.LookupEntry(player
->getClass());
4492 sLog
.outError("Class %u not found in DBC (Wrong DBC files?)",player
->getClass());
4496 uint8 powertype
= cEntry
->powerType
;
4498 // reset m_form if no aura
4499 if(!player
->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT
))
4500 player
->m_form
= FORM_NONE
;
4502 player
->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS
, DEFAULT_WORLD_OBJECT_SIZE
);
4503 player
->SetFloatValue(UNIT_FIELD_COMBATREACH
, 1.5f
);
4505 player
->setFactionForRace(player
->getRace());
4507 player
->SetUInt32Value(UNIT_FIELD_BYTES_0
, ( ( player
->getRace() ) | ( player
->getClass() << 8 ) | ( player
->getGender() << 16 ) | ( powertype
<< 24 ) ) );
4509 // reset only if player not in some form;
4510 if(player
->m_form
==FORM_NONE
)
4512 switch(player
->getGender())
4515 player
->SetDisplayId(info
->displayId_f
);
4516 player
->SetNativeDisplayId(info
->displayId_f
);
4519 player
->SetDisplayId(info
->displayId_m
);
4520 player
->SetNativeDisplayId(info
->displayId_m
);
4527 player
->SetByteValue(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_PVP
);
4528 player
->SetByteValue(UNIT_FIELD_BYTES_2
, 3, player
->m_form
);
4530 player
->SetUInt32Value(UNIT_FIELD_FLAGS
, UNIT_FLAG_PVP_ATTACKABLE
);
4532 //-1 is default value
4533 player
->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX
, uint32(-1));
4535 //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000 );
4539 bool ChatHandler::HandleResetLevelCommand(const char * args
)
4541 char* pName
= strtok((char*)args
, "");
4542 Player
*player
= NULL
;
4545 std::string name
= extractPlayerNameFromLink(pName
);
4548 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4549 SetSentErrorMessage(true);
4553 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
);
4554 player
= objmgr
.GetPlayer(guid
);
4557 player
= getSelectedPlayer();
4561 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4562 SetSentErrorMessage(true);
4566 if(!HandleResetStatsOrLevelHelper(player
))
4569 // set starting level
4570 uint32 start_level
= player
->getClass() != CLASS_DEATH_KNIGHT
4571 ? sWorld
.getConfig(CONFIG_START_PLAYER_LEVEL
)
4572 : sWorld
.getConfig(CONFIG_START_HEROIC_PLAYER_LEVEL
);
4574 player
->SetLevel(start_level
);
4575 player
->InitRunes();
4576 player
->InitStatsForLevel(true);
4577 player
->InitTaxiNodesForLevel();
4578 player
->InitGlyphsForLevel();
4579 player
->InitTalentForLevel();
4580 player
->SetUInt32Value(PLAYER_XP
,0);
4582 // reset level to summoned pet
4583 Pet
* pet
= player
->GetPet();
4584 if(pet
&& pet
->getPetType()==SUMMON_PET
)
4586 pet
->InitStatsForLevel(1);
4587 pet
->InitTalentForLevel();
4592 bool ChatHandler::HandleResetStatsCommand(const char * args
)
4594 char* pName
= strtok((char*)args
, "");
4595 Player
*player
= NULL
;
4598 std::string name
= extractPlayerNameFromLink(pName
);
4601 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4602 SetSentErrorMessage(true);
4606 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
);
4607 player
= objmgr
.GetPlayer(guid
);
4610 player
= getSelectedPlayer();
4614 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4615 SetSentErrorMessage(true);
4619 if(!HandleResetStatsOrLevelHelper(player
))
4622 player
->InitRunes();
4623 player
->InitStatsForLevel(true);
4624 player
->InitTaxiNodesForLevel();
4625 player
->InitGlyphsForLevel();
4626 player
->InitTalentForLevel();
4631 bool ChatHandler::HandleResetSpellsCommand(const char * args
)
4633 char* pName
= strtok((char*)args
, "");
4634 Player
*player
= NULL
;
4635 uint64 playerGUID
= 0;
4638 std::string name
= extractPlayerNameFromLink(pName
);
4641 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4642 SetSentErrorMessage(true);
4646 player
= objmgr
.GetPlayer(name
.c_str());
4648 playerGUID
= objmgr
.GetPlayerGUIDByName(name
);
4651 player
= getSelectedPlayer();
4653 if(!player
&& !playerGUID
)
4655 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4656 SetSentErrorMessage(true);
4662 player
->resetSpells();
4664 ChatHandler(player
).SendSysMessage(LANG_RESET_SPELLS
);
4665 if(m_session
->GetPlayer()!=player
)
4666 PSendSysMessage(LANG_RESET_SPELLS_ONLINE
,GetNameLink(player
).c_str());
4670 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS
), GUID_LOPART(playerGUID
));
4671 PSendSysMessage(LANG_RESET_SPELLS_OFFLINE
,pName
);
4677 bool ChatHandler::HandleResetTalentsCommand(const char * args
)
4679 char* pName
= strtok((char*)args
, "");
4680 Player
*player
= NULL
;
4681 uint64 playerGUID
= 0;
4684 std::string name
= extractPlayerNameFromLink(pName
);
4687 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4688 SetSentErrorMessage(true);
4692 player
= objmgr
.GetPlayer(name
.c_str());
4694 playerGUID
= objmgr
.GetPlayerGUIDByName(name
);
4697 player
= getSelectedPlayer();
4701 player
->resetTalents(true);
4703 ChatHandler(player
).SendSysMessage(LANG_RESET_TALENTS
);
4704 if(m_session
->GetPlayer()!=player
)
4705 PSendSysMessage(LANG_RESET_TALENTS_ONLINE
,GetNameLink(player
).c_str());
4709 else if (playerGUID
)
4711 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_TALENTS
), GUID_LOPART(playerGUID
) );
4712 std::string nameLink
= playerLink(pName
);
4713 PSendSysMessage(LANG_RESET_TALENTS_OFFLINE
,nameLink
.c_str());
4716 // Try reset talenents as Hunter Pet
4717 Creature
* creature
= getSelectedCreature();
4718 if (creature
&& creature
->isPet() && ((Pet
*)creature
)->getPetType() == HUNTER_PET
)
4720 ((Pet
*)creature
)->resetTalents(true);
4721 Unit
*owner
= creature
->GetOwner();
4722 if (owner
&& owner
->GetTypeId() == TYPEID_PLAYER
)
4724 player
= (Player
*)owner
;
4725 ChatHandler(player
).SendSysMessage(LANG_RESET_PET_TALENTS
);
4726 if(m_session
->GetPlayer()!=player
)
4727 PSendSysMessage(LANG_RESET_PET_TALENTS_ONLINE
,GetNameLink(player
).c_str());
4732 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4733 SetSentErrorMessage(true);
4737 bool ChatHandler::HandleResetAllCommand(const char * args
)
4742 std::string casename
= args
;
4744 AtLoginFlags atLogin
;
4746 // Command specially created as single command to prevent using short case names
4747 if(casename
=="spells")
4749 atLogin
= AT_LOGIN_RESET_SPELLS
;
4750 sWorld
.SendWorldText(LANG_RESETALL_SPELLS
);
4752 else if(casename
=="talents")
4754 atLogin
= AT_LOGIN_RESET_TALENTS
;
4755 sWorld
.SendWorldText(LANG_RESETALL_TALENTS
);
4759 PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE
,args
);
4760 SetSentErrorMessage(true);
4764 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE (at_login & '%u') = '0'",atLogin
,atLogin
);
4765 HashMapHolder
<Player
>::MapType
const& plist
= ObjectAccessor::Instance().GetPlayers();
4766 for(HashMapHolder
<Player
>::MapType::const_iterator itr
= plist
.begin(); itr
!= plist
.end(); ++itr
)
4767 itr
->second
->SetAtLoginFlag(atLogin
);
4772 bool ChatHandler::HandleServerShutDownCancelCommand(const char* args
)
4774 sWorld
.ShutdownCancel();
4778 bool ChatHandler::HandleServerShutDownCommand(const char* args
)
4783 char* time_str
= strtok ((char*) args
, " ");
4784 char* exitcode_str
= strtok (NULL
, "");
4786 int32 time
= atoi (time_str
);
4788 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4789 if(time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0') || time
< 0)
4794 int32 exitcode
= atoi (exitcode_str
);
4796 // Handle atoi() errors
4797 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4800 // Exit code should be in range of 0-125, 126-255 is used
4801 // in many shells for their own return codes and code > 255
4802 // is not supported in many others
4803 if (exitcode
< 0 || exitcode
> 125)
4806 sWorld
.ShutdownServ (time
, 0, exitcode
);
4809 sWorld
.ShutdownServ(time
,0,SHUTDOWN_EXIT_CODE
);
4813 bool ChatHandler::HandleServerRestartCommand(const char* args
)
4818 char* time_str
= strtok ((char*) args
, " ");
4819 char* exitcode_str
= strtok (NULL
, "");
4821 int32 time
= atoi (time_str
);
4823 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4824 if(time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0') || time
< 0)
4829 int32 exitcode
= atoi (exitcode_str
);
4831 // Handle atoi() errors
4832 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4835 // Exit code should be in range of 0-125, 126-255 is used
4836 // in many shells for their own return codes and code > 255
4837 // is not supported in many others
4838 if (exitcode
< 0 || exitcode
> 125)
4841 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_RESTART
, exitcode
);
4844 sWorld
.ShutdownServ(time
, SHUTDOWN_MASK_RESTART
, RESTART_EXIT_CODE
);
4848 bool ChatHandler::HandleServerIdleRestartCommand(const char* args
)
4853 char* time_str
= strtok ((char*) args
, " ");
4854 char* exitcode_str
= strtok (NULL
, "");
4856 int32 time
= atoi (time_str
);
4858 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4859 if(time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0') || time
< 0)
4864 int32 exitcode
= atoi (exitcode_str
);
4866 // Handle atoi() errors
4867 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4870 // Exit code should be in range of 0-125, 126-255 is used
4871 // in many shells for their own return codes and code > 255
4872 // is not supported in many others
4873 if (exitcode
< 0 || exitcode
> 125)
4876 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_RESTART
|SHUTDOWN_MASK_IDLE
, exitcode
);
4879 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_RESTART
|SHUTDOWN_MASK_IDLE
,RESTART_EXIT_CODE
);
4883 bool ChatHandler::HandleServerIdleShutDownCommand(const char* args
)
4888 char* time_str
= strtok ((char*) args
, " ");
4889 char* exitcode_str
= strtok (NULL
, "");
4891 int32 time
= atoi (time_str
);
4893 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4894 if(time
== 0 && (time_str
[0]!='0' || time_str
[1]!='\0') || time
< 0)
4899 int32 exitcode
= atoi (exitcode_str
);
4901 // Handle atoi() errors
4902 if (exitcode
== 0 && (exitcode_str
[0] != '0' || exitcode_str
[1] != '\0'))
4905 // Exit code should be in range of 0-125, 126-255 is used
4906 // in many shells for their own return codes and code > 255
4907 // is not supported in many others
4908 if (exitcode
< 0 || exitcode
> 125)
4911 sWorld
.ShutdownServ (time
, SHUTDOWN_MASK_IDLE
, exitcode
);
4914 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_IDLE
,SHUTDOWN_EXIT_CODE
);
4918 bool ChatHandler::HandleQuestAdd(const char* args
)
4920 Player
* player
= getSelectedPlayer();
4923 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4924 SetSentErrorMessage(true);
4928 // .addquest #entry'
4929 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4930 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4934 uint32 entry
= atol(cId
);
4936 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
4940 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
,entry
);
4941 SetSentErrorMessage(true);
4945 // check item starting quest (it can work incorrectly if added without item in inventory)
4946 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
4948 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
4952 if (pProto
->StartQuest
== entry
)
4954 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM
, entry
, pProto
->ItemId
);
4955 SetSentErrorMessage(true);
4960 // ok, normal (creature/GO starting) quest
4961 if( player
->CanAddQuest( pQuest
, true ) )
4963 player
->AddQuest( pQuest
, NULL
);
4965 if ( player
->CanCompleteQuest( entry
) )
4966 player
->CompleteQuest( entry
);
4972 bool ChatHandler::HandleQuestRemove(const char* args
)
4974 Player
* player
= getSelectedPlayer();
4977 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4978 SetSentErrorMessage(true);
4982 // .removequest #entry'
4983 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4984 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4988 uint32 entry
= atol(cId
);
4990 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
4994 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
4995 SetSentErrorMessage(true);
4999 // remove all quest entries for 'entry' from quest log
5000 for(uint8 slot
= 0; slot
< MAX_QUEST_LOG_SIZE
; ++slot
)
5002 uint32 quest
= player
->GetQuestSlotQuestId(slot
);
5005 player
->SetQuestSlot(slot
,0);
5007 // we ignore unequippable quest items in this case, its' still be equipped
5008 player
->TakeQuestSourceItem( quest
, false );
5012 // set quest status to not started (will updated in DB at next save)
5013 player
->SetQuestStatus( entry
, QUEST_STATUS_NONE
);
5015 // reset rewarded for restart repeatable quest
5016 player
->getQuestStatusMap()[entry
].m_rewarded
= false;
5018 SendSysMessage(LANG_COMMAND_QUEST_REMOVED
);
5022 bool ChatHandler::HandleQuestComplete(const char* args
)
5024 Player
* player
= getSelectedPlayer();
5027 SendSysMessage(LANG_NO_CHAR_SELECTED
);
5028 SetSentErrorMessage(true);
5032 // .quest complete #entry
5033 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
5034 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
5038 uint32 entry
= atol(cId
);
5040 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
5042 // If player doesn't have the quest
5043 if(!pQuest
|| player
->GetQuestStatus(entry
) == QUEST_STATUS_NONE
)
5045 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
5046 SetSentErrorMessage(true);
5050 // Add quest items for quests that require items
5051 for(uint8 x
= 0; x
< QUEST_OBJECTIVES_COUNT
; ++x
)
5053 uint32 id
= pQuest
->ReqItemId
[x
];
5054 uint32 count
= pQuest
->ReqItemCount
[x
];
5058 uint32 curItemCount
= player
->GetItemCount(id
,true);
5060 ItemPosCountVec dest
;
5061 uint8 msg
= player
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, id
, count
-curItemCount
);
5062 if( msg
== EQUIP_ERR_OK
)
5064 Item
* item
= player
->StoreNewItem( dest
, id
, true);
5065 player
->SendNewItem(item
,count
-curItemCount
,true,false);
5069 // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
5070 for(uint8 i
= 0; i
< QUEST_OBJECTIVES_COUNT
; i
++)
5072 uint32 creature
= pQuest
->ReqCreatureOrGOId
[i
];
5073 uint32 creaturecount
= pQuest
->ReqCreatureOrGOCount
[i
];
5075 if(uint32 spell_id
= pQuest
->ReqSpell
[i
])
5077 for(uint16 z
= 0; z
< creaturecount
; ++z
)
5078 player
->CastedCreatureOrGO(creature
,0,spell_id
);
5080 else if(creature
> 0)
5082 for(uint16 z
= 0; z
< creaturecount
; ++z
)
5083 player
->KilledMonster(creature
,0);
5085 else if(creature
< 0)
5087 for(uint16 z
= 0; z
< creaturecount
; ++z
)
5088 player
->CastedCreatureOrGO(creature
,0,0);
5092 // If the quest requires reputation to complete
5093 if(uint32 repFaction
= pQuest
->GetRepObjectiveFaction())
5095 uint32 repValue
= pQuest
->GetRepObjectiveValue();
5096 uint32 curRep
= player
->GetReputationMgr().GetReputation(repFaction
);
5097 if(curRep
< repValue
)
5098 if(FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry(repFaction
))
5099 player
->GetReputationMgr().SetReputation(factionEntry
,repValue
);
5102 // If the quest requires money
5103 int32 ReqOrRewMoney
= pQuest
->GetRewOrReqMoney();
5104 if(ReqOrRewMoney
< 0)
5105 player
->ModifyMoney(-ReqOrRewMoney
);
5107 player
->CompleteQuest(entry
);
5111 bool ChatHandler::HandleBanAccountCommand(const char* args
)
5113 return HandleBanHelper(BAN_ACCOUNT
,args
);
5116 bool ChatHandler::HandleBanCharacterCommand(const char* args
)
5118 return HandleBanHelper(BAN_CHARACTER
,args
);
5121 bool ChatHandler::HandleBanIPCommand(const char* args
)
5123 return HandleBanHelper(BAN_IP
,args
);
5126 bool ChatHandler::HandleBanHelper(BanMode mode
, const char* args
)
5131 char* cnameOrIP
= strtok ((char*)args
, " ");
5135 std::string nameOrIP
= cnameOrIP
;
5137 char* duration
= strtok (NULL
," ");
5138 if(!duration
|| !atoi(duration
))
5141 char* reason
= strtok (NULL
,"");
5148 if(!AccountMgr::normilizeString(nameOrIP
))
5150 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
5151 SetSentErrorMessage(true);
5156 if(!normalizePlayerName(nameOrIP
))
5158 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5159 SetSentErrorMessage(true);
5164 if(!IsIPAddress(nameOrIP
.c_str()))
5169 switch(sWorld
.BanAccount(mode
, nameOrIP
, duration
, reason
,m_session
? m_session
->GetPlayerName() : ""))
5172 if(atoi(duration
)>0)
5173 PSendSysMessage(LANG_BAN_YOUBANNED
,nameOrIP
.c_str(),secsToTimeString(TimeStringToSecs(duration
),true).c_str(),reason
);
5175 PSendSysMessage(LANG_BAN_YOUPERMBANNED
,nameOrIP
.c_str(),reason
);
5177 case BAN_SYNTAX_ERROR
:
5183 PSendSysMessage(LANG_BAN_NOTFOUND
,"account",nameOrIP
.c_str());
5186 PSendSysMessage(LANG_BAN_NOTFOUND
,"character",nameOrIP
.c_str());
5189 PSendSysMessage(LANG_BAN_NOTFOUND
,"ip",nameOrIP
.c_str());
5192 SetSentErrorMessage(true);
5199 bool ChatHandler::HandleUnBanAccountCommand(const char* args
)
5201 return HandleUnBanHelper(BAN_ACCOUNT
,args
);
5204 bool ChatHandler::HandleUnBanCharacterCommand(const char* args
)
5206 return HandleUnBanHelper(BAN_CHARACTER
,args
);
5209 bool ChatHandler::HandleUnBanIPCommand(const char* args
)
5211 return HandleUnBanHelper(BAN_IP
,args
);
5214 bool ChatHandler::HandleUnBanHelper(BanMode mode
, const char* args
)
5219 char* cnameOrIP
= strtok ((char*)args
, " ");
5223 std::string nameOrIP
= cnameOrIP
;
5228 if(!AccountMgr::normilizeString(nameOrIP
))
5230 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
5231 SetSentErrorMessage(true);
5236 if(!normalizePlayerName(nameOrIP
))
5238 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5239 SetSentErrorMessage(true);
5244 if(!IsIPAddress(nameOrIP
.c_str()))
5249 if(sWorld
.RemoveBanAccount(mode
,nameOrIP
))
5250 PSendSysMessage(LANG_UNBAN_UNBANNED
,nameOrIP
.c_str());
5252 PSendSysMessage(LANG_UNBAN_ERROR
,nameOrIP
.c_str());
5257 bool ChatHandler::HandleBanInfoAccountCommand(const char* args
)
5262 char* cname
= strtok((char*)args
, "");
5266 std::string account_name
= cname
;
5267 if(!AccountMgr::normilizeString(account_name
))
5269 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5270 SetSentErrorMessage(true);
5274 uint32 accountid
= accmgr
.GetId(account_name
);
5277 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5281 return HandleBanInfoHelper(accountid
,account_name
.c_str());
5284 bool ChatHandler::HandleBanInfoCharacterCommand(const char* args
)
5289 std::string name
= extractPlayerNameFromLink((char*)args
);
5292 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5293 SetSentErrorMessage(true);
5297 uint32 accountid
= objmgr
.GetPlayerAccountIdByPlayerName(name
);
5300 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5301 SetSentErrorMessage(true);
5305 std::string accountname
;
5306 if(!accmgr
.GetName(accountid
,accountname
))
5308 PSendSysMessage(LANG_BANINFO_NOCHARACTER
);
5312 return HandleBanInfoHelper(accountid
,accountname
.c_str());
5315 bool ChatHandler::HandleBanInfoHelper(uint32 accountid
, char const* accountname
)
5317 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
);
5320 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN
, accountname
);
5324 PSendSysMessage(LANG_BANINFO_BANHISTORY
,accountname
);
5327 Field
* fields
= result
->Fetch();
5329 time_t unbandate
= time_t(fields
[3].GetUInt64());
5330 bool active
= false;
5331 if(fields
[2].GetBool() && (fields
[1].GetUInt64() == (uint64
)0 ||unbandate
>= time(NULL
)) )
5333 bool permanent
= (fields
[1].GetUInt64() == (uint64
)0);
5334 std::string bantime
= permanent
?GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[1].GetUInt64(), true);
5335 PSendSysMessage(LANG_BANINFO_HISTORYENTRY
,
5336 fields
[0].GetString(), bantime
.c_str(), active
? GetMangosString(LANG_BANINFO_YES
):GetMangosString(LANG_BANINFO_NO
), fields
[4].GetString(), fields
[5].GetString());
5337 }while (result
->NextRow());
5343 bool ChatHandler::HandleBanInfoIPCommand(const char* args
)
5348 char* cIP
= strtok ((char*)args
, "");
5352 if (!IsIPAddress(cIP
))
5355 std::string IP
= cIP
;
5357 loginDatabase
.escape_string(IP
);
5358 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());
5361 PSendSysMessage(LANG_BANINFO_NOIP
);
5365 Field
*fields
= result
->Fetch();
5366 bool permanent
= !fields
[6].GetUInt64();
5367 PSendSysMessage(LANG_BANINFO_IPENTRY
,
5368 fields
[0].GetString(), fields
[1].GetString(), permanent
? GetMangosString(LANG_BANINFO_NEVER
):fields
[2].GetString(),
5369 permanent
? GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[3].GetUInt64(), true).c_str(), fields
[4].GetString(), fields
[5].GetString());
5374 bool ChatHandler::HandleBanListCharacterCommand(const char* args
)
5376 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5378 char* cFilter
= strtok ((char*)args
, " ");
5382 std::string filter
= cFilter
;
5383 loginDatabase
.escape_string(filter
);
5384 QueryResult
* result
= CharacterDatabase
.PQuery("SELECT account FROM characters WHERE name "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'"),filter
.c_str());
5387 PSendSysMessage(LANG_BANLIST_NOCHARACTER
);
5391 return HandleBanListHelper(result
);
5394 bool ChatHandler::HandleBanListAccountCommand(const char* args
)
5396 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5398 char* cFilter
= strtok((char*)args
, " ");
5399 std::string filter
= cFilter
? cFilter
: "";
5400 loginDatabase
.escape_string(filter
);
5402 QueryResult
* result
;
5406 result
= loginDatabase
.Query("SELECT account.id, username FROM account, account_banned"
5407 " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
5411 result
= loginDatabase
.PQuery("SELECT account.id, username FROM account, account_banned"
5412 " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
5418 PSendSysMessage(LANG_BANLIST_NOACCOUNT
);
5422 return HandleBanListHelper(result
);
5425 bool ChatHandler::HandleBanListHelper(QueryResult
* result
)
5427 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT
);
5429 // Chat short output
5434 Field
* fields
= result
->Fetch();
5435 uint32 accountid
= fields
[0].GetUInt32();
5437 QueryResult
* banresult
= loginDatabase
.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid
);
5440 Field
* fields2
= banresult
->Fetch();
5441 PSendSysMessage("%s",fields2
[0].GetString());
5444 } while (result
->NextRow());
5446 // Console wide output
5449 SendSysMessage(LANG_BANLIST_ACCOUNTS
);
5450 SendSysMessage("===============================================================================");
5451 SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER
);
5454 SendSysMessage("-------------------------------------------------------------------------------");
5455 Field
*fields
= result
->Fetch();
5456 uint32 account_id
= fields
[0].GetUInt32 ();
5458 std::string account_name
;
5460 // "account" case, name can be get in same query
5461 if(result
->GetFieldCount() > 1)
5462 account_name
= fields
[1].GetCppString();
5463 // "character" case, name need extract from another DB
5465 accmgr
.GetName (account_id
,account_name
);
5467 // No SQL injection. id is uint32.
5468 QueryResult
*banInfo
= loginDatabase
.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id
);
5471 Field
*fields2
= banInfo
->Fetch();
5474 time_t t_ban
= fields2
[0].GetUInt64();
5475 tm
* aTm_ban
= localtime(&t_ban
);
5477 if (fields2
[0].GetUInt64() == fields2
[1].GetUInt64())
5479 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5480 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
,
5481 fields2
[2].GetString(),fields2
[3].GetString());
5485 time_t t_unban
= fields2
[1].GetUInt64();
5486 tm
* aTm_unban
= localtime(&t_unban
);
5487 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5488 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
,
5489 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5490 fields2
[2].GetString(),fields2
[3].GetString());
5492 }while ( banInfo
->NextRow() );
5495 }while( result
->NextRow() );
5496 SendSysMessage("===============================================================================");
5503 bool ChatHandler::HandleBanListIPCommand(const char* args
)
5505 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5507 char* cFilter
= strtok((char*)args
, " ");
5508 std::string filter
= cFilter
? cFilter
: "";
5509 loginDatabase
.escape_string(filter
);
5511 QueryResult
* result
;
5515 result
= loginDatabase
.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5516 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
5517 " ORDER BY unbandate" );
5521 result
= loginDatabase
.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5522 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")
5523 " ORDER BY unbandate",filter
.c_str() );
5528 PSendSysMessage(LANG_BANLIST_NOIP
);
5532 PSendSysMessage(LANG_BANLIST_MATCHINGIP
);
5533 // Chat short output
5538 Field
* fields
= result
->Fetch();
5539 PSendSysMessage("%s",fields
[0].GetString());
5540 } while (result
->NextRow());
5542 // Console wide output
5545 SendSysMessage(LANG_BANLIST_IPS
);
5546 SendSysMessage("===============================================================================");
5547 SendSysMessage(LANG_BANLIST_IPS_HEADER
);
5550 SendSysMessage("-------------------------------------------------------------------------------");
5551 Field
*fields
= result
->Fetch();
5552 time_t t_ban
= fields
[1].GetUInt64();
5553 tm
* aTm_ban
= localtime(&t_ban
);
5554 if ( fields
[1].GetUInt64() == fields
[2].GetUInt64() )
5556 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5557 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
,
5558 fields
[3].GetString(), fields
[4].GetString());
5562 time_t t_unban
= fields
[2].GetUInt64();
5563 tm
* aTm_unban
= localtime(&t_unban
);
5564 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5565 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
,
5566 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5567 fields
[3].GetString(), fields
[4].GetString());
5569 }while( result
->NextRow() );
5570 SendSysMessage("===============================================================================");
5577 bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
5579 Player
* pl
= m_session
->GetPlayer();
5581 // accept only explicitly selected target (not implicitly self targeting case)
5582 Unit
* target
= getSelectedUnit();
5583 if(pl
->GetSelection() && target
)
5585 if(target
->GetTypeId()!=TYPEID_UNIT
)
5587 SendSysMessage(LANG_SELECT_CREATURE
);
5588 SetSentErrorMessage(true);
5592 if(target
->isDead())
5593 ((Creature
*)target
)->Respawn();
5597 CellPair
p(MaNGOS::ComputeCellPair(pl
->GetPositionX(), pl
->GetPositionY()));
5599 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
5602 MaNGOS::RespawnDo u_do
;
5603 MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
> worker(pl
,u_do
);
5605 TypeContainerVisitor
<MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
>, GridTypeMapContainer
> obj_worker(worker
);
5606 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
5607 cell_lock
->Visit(cell_lock
, obj_worker
, *pl
->GetMap());
5612 bool ChatHandler::HandleGMFlyModeCommand(const char* args
)
5617 Player
*target
= getSelectedPlayer();
5619 target
= m_session
->GetPlayer();
5621 WorldPacket
data(12);
5622 if (strncmp(args
, "on", 3) == 0)
5623 data
.SetOpcode(SMSG_MOVE_SET_CAN_FLY
);
5624 else if (strncmp(args
, "off", 4) == 0)
5625 data
.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY
);
5628 SendSysMessage(LANG_USE_BOL
);
5631 data
.append(target
->GetPackGUID());
5632 data
<< uint32(0); // unknown
5633 target
->SendMessageToSet(&data
, true);
5634 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS
, GetNameLink(target
).c_str(), args
);
5638 bool ChatHandler::HandlePDumpLoadCommand(const char *args
)
5643 char * file
= strtok((char*)args
, " ");
5647 char * account
= strtok(NULL
, " ");
5651 std::string account_name
= account
;
5652 if(!AccountMgr::normilizeString(account_name
))
5654 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5655 SetSentErrorMessage(true);
5659 uint32 account_id
= accmgr
.GetId(account_name
);
5662 account_id
= atoi(account
); // use original string
5665 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5666 SetSentErrorMessage(true);
5671 if(!accmgr
.GetName(account_id
,account_name
))
5673 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5674 SetSentErrorMessage(true);
5678 char* guid_str
= NULL
;
5679 char* name_str
= strtok(NULL
, " ");
5685 // normalize the name if specified and check if it exists
5686 if(!normalizePlayerName(name
))
5688 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5689 SetSentErrorMessage(true);
5693 if(!ObjectMgr::IsValidName(name
,true))
5695 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5696 SetSentErrorMessage(true);
5700 guid_str
= strtok(NULL
, " ");
5707 guid
= atoi(guid_str
);
5710 PSendSysMessage(LANG_INVALID_CHARACTER_GUID
);
5711 SetSentErrorMessage(true);
5715 if(objmgr
.GetPlayerAccountIdByGUID(guid
))
5717 PSendSysMessage(LANG_CHARACTER_GUID_IN_USE
,guid
);
5718 SetSentErrorMessage(true);
5723 switch(PlayerDumpReader().LoadDump(file
, account_id
, name
, guid
))
5726 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS
);
5728 case DUMP_FILE_OPEN_ERROR
:
5729 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
5730 SetSentErrorMessage(true);
5732 case DUMP_FILE_BROKEN
:
5733 PSendSysMessage(LANG_DUMP_BROKEN
,file
);
5734 SetSentErrorMessage(true);
5736 case DUMP_TOO_MANY_CHARS
:
5737 PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL
,account_name
.c_str(),account_id
);
5738 SetSentErrorMessage(true);
5741 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED
);
5742 SetSentErrorMessage(true);
5749 bool ChatHandler::HandlePDumpWriteCommand(const char *args
)
5754 char* file
= strtok((char*)args
, " ");
5755 char* p2
= strtok(NULL
, " ");
5761 // character name can't start from number
5762 if (isNumeric(p2
[0]))
5766 std::string name
= extractPlayerNameFromLink(p2
);
5769 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5770 SetSentErrorMessage(true);
5774 guid
= objmgr
.GetPlayerGUIDByName(name
);
5777 if(!objmgr
.GetPlayerAccountIdByGUID(guid
))
5779 PSendSysMessage(LANG_PLAYER_NOT_FOUND
);
5780 SetSentErrorMessage(true);
5784 switch(PlayerDumpWriter().WriteDump(file
, guid
))
5787 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS
);
5789 case DUMP_FILE_OPEN_ERROR
:
5790 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
5791 SetSentErrorMessage(true);
5794 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED
);
5795 SetSentErrorMessage(true);
5802 bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
5804 Unit
* unit
= getSelectedUnit();
5807 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5808 SetSentErrorMessage(true);
5812 PSendSysMessage(LANG_MOVEGENS_LIST
,(unit
->GetTypeId()==TYPEID_PLAYER
? "Player" : "Creature" ),unit
->GetGUIDLow());
5814 MotionMaster
* mm
= unit
->GetMotionMaster();
5815 for(MotionMaster::const_iterator itr
= mm
->begin(); itr
!= mm
->end(); ++itr
)
5817 switch((*itr
)->GetMovementGeneratorType())
5819 case IDLE_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_IDLE
); break;
5820 case RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_RANDOM
); break;
5821 case WAYPOINT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_WAYPOINT
); break;
5822 case ANIMAL_RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_ANIMAL_RANDOM
); break;
5823 case CONFUSED_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_CONFUSED
); break;
5824 case TARGETED_MOTION_TYPE
:
5826 if(unit
->GetTypeId()==TYPEID_PLAYER
)
5828 TargetedMovementGenerator
<Player
> const* mgen
= static_cast<TargetedMovementGenerator
<Player
> const*>(*itr
);
5829 Unit
* target
= mgen
->GetTarget();
5831 PSendSysMessage(LANG_MOVEGENS_TARGETED_PLAYER
,target
->GetName(),target
->GetGUIDLow());
5833 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL
);
5837 TargetedMovementGenerator
<Creature
> const* mgen
= static_cast<TargetedMovementGenerator
<Creature
> const*>(*itr
);
5838 Unit
* target
= mgen
->GetTarget();
5840 PSendSysMessage(LANG_MOVEGENS_TARGETED_CREATURE
,target
->GetName(),target
->GetGUIDLow());
5842 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL
);
5846 case HOME_MOTION_TYPE
:
5847 if(unit
->GetTypeId()==TYPEID_UNIT
)
5850 (*itr
)->GetDestination(x
,y
,z
);
5851 PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE
,x
,y
,z
);
5854 SendSysMessage(LANG_MOVEGENS_HOME_PLAYER
);
5856 case FLIGHT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FLIGHT
); break;
5857 case POINT_MOTION_TYPE
:
5860 (*itr
)->GetDestination(x
,y
,z
);
5861 PSendSysMessage(LANG_MOVEGENS_POINT
,x
,y
,z
);
5864 case FLEEING_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FEAR
); break;
5865 case DISTRACT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_DISTRACT
); break;
5867 PSendSysMessage(LANG_MOVEGENS_UNKNOWN
,(*itr
)->GetMovementGeneratorType());
5874 bool ChatHandler::HandlePLimitCommand(const char *args
)
5878 char* param
= strtok((char*)args
, " ");
5882 int l
= strlen(param
);
5884 if( strncmp(param
,"player",l
) == 0 )
5885 sWorld
.SetPlayerLimit(-SEC_PLAYER
);
5886 else if(strncmp(param
,"moderator",l
) == 0 )
5887 sWorld
.SetPlayerLimit(-SEC_MODERATOR
);
5888 else if(strncmp(param
,"gamemaster",l
) == 0 )
5889 sWorld
.SetPlayerLimit(-SEC_GAMEMASTER
);
5890 else if(strncmp(param
,"administrator",l
) == 0 )
5891 sWorld
.SetPlayerLimit(-SEC_ADMINISTRATOR
);
5892 else if(strncmp(param
,"reset",l
) == 0 )
5893 sWorld
.SetPlayerLimit( sConfig
.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT
) );
5896 int val
= atoi(param
);
5897 if(val
< -SEC_ADMINISTRATOR
) val
= -SEC_ADMINISTRATOR
;
5899 sWorld
.SetPlayerLimit(val
);
5902 // kick all low security level players
5903 if(sWorld
.GetPlayerAmountLimit() > SEC_PLAYER
)
5904 sWorld
.KickAllLess(sWorld
.GetPlayerSecurityLimit());
5907 uint32 pLimit
= sWorld
.GetPlayerAmountLimit();
5908 AccountTypes allowedAccountType
= sWorld
.GetPlayerSecurityLimit();
5909 char const* secName
= "";
5910 switch(allowedAccountType
)
5912 case SEC_PLAYER
: secName
= "Player"; break;
5913 case SEC_MODERATOR
: secName
= "Moderator"; break;
5914 case SEC_GAMEMASTER
: secName
= "Gamemaster"; break;
5915 case SEC_ADMINISTRATOR
: secName
= "Administrator"; break;
5916 default: secName
= "<unknown>"; break;
5919 PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit
,secName
);
5924 bool ChatHandler::HandleCastCommand(const char* args
)
5929 Unit
* target
= getSelectedUnit();
5933 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5934 SetSentErrorMessage(true);
5938 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5939 uint32 spell
= extractSpellIdFromLink((char*)args
);
5943 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5947 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5949 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5950 SetSentErrorMessage(true);
5954 char* trig_str
= strtok(NULL
, " ");
5957 int l
= strlen(trig_str
);
5958 if(strncmp(trig_str
,"triggered",l
) != 0 )
5962 bool triggered
= (trig_str
!= NULL
);
5964 m_session
->GetPlayer()->CastSpell(target
,spell
,triggered
);
5969 bool ChatHandler::HandleCastBackCommand(const char* args
)
5971 Creature
* caster
= getSelectedCreature();
5975 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5976 SetSentErrorMessage(true);
5980 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
5981 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5982 uint32 spell
= extractSpellIdFromLink((char*)args
);
5983 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
5986 char* trig_str
= strtok(NULL
, " ");
5989 int l
= strlen(trig_str
);
5990 if(strncmp(trig_str
,"triggered",l
) != 0 )
5994 bool triggered
= (trig_str
!= NULL
);
5996 // update orientation at server
5997 caster
->SetOrientation(caster
->GetAngle(m_session
->GetPlayer()));
6001 caster
->BuildHeartBeatMsg(&data
);
6002 caster
->SendMessageToSet(&data
,true);
6004 caster
->CastSpell(m_session
->GetPlayer(),spell
,triggered
);
6009 bool ChatHandler::HandleCastDistCommand(const char* args
)
6014 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6015 uint32 spell
= extractSpellIdFromLink((char*)args
);
6019 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
6023 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
6025 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
6026 SetSentErrorMessage(true);
6030 char *distStr
= strtok(NULL
, " ");
6035 sscanf(distStr
, "%f", &dist
);
6037 char* trig_str
= strtok(NULL
, " ");
6040 int l
= strlen(trig_str
);
6041 if(strncmp(trig_str
,"triggered",l
) != 0 )
6045 bool triggered
= (trig_str
!= NULL
);
6048 m_session
->GetPlayer()->GetClosePoint(x
,y
,z
,dist
);
6050 m_session
->GetPlayer()->CastSpell(x
,y
,z
,spell
,triggered
);
6054 bool ChatHandler::HandleCastTargetCommand(const char* args
)
6056 Creature
* caster
= getSelectedCreature();
6060 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
6061 SetSentErrorMessage(true);
6065 if(!caster
->getVictim())
6067 SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM
);
6068 SetSentErrorMessage(true);
6072 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6073 uint32 spell
= extractSpellIdFromLink((char*)args
);
6074 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
6077 char* trig_str
= strtok(NULL
, " ");
6080 int l
= strlen(trig_str
);
6081 if(strncmp(trig_str
,"triggered",l
) != 0 )
6085 bool triggered
= (trig_str
!= NULL
);
6087 // update orientation at server
6088 caster
->SetOrientation(caster
->GetAngle(m_session
->GetPlayer()));
6092 caster
->BuildHeartBeatMsg(&data
);
6093 caster
->SendMessageToSet(&data
,true);
6095 caster
->CastSpell(caster
->getVictim(),spell
,triggered
);
6101 ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
6102 Without this function 3rd party scripting library will get linking errors (unresolved external)
6103 when attempting to use the PointMovementGenerator
6105 bool ChatHandler::HandleComeToMeCommand(const char *args
)
6107 Creature
* caster
= getSelectedCreature();
6111 SendSysMessage(LANG_SELECT_CREATURE
);
6112 SetSentErrorMessage(true);
6116 char* newFlagStr
= strtok((char*)args
, " ");
6121 uint32 newFlags
= atoi(newFlagStr
);
6123 caster
->SetUnitMovementFlags(newFlags
);
6125 Player
* pl
= m_session
->GetPlayer();
6127 caster
->GetMotionMaster()->MovePoint(0, pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ());
6131 bool ChatHandler::HandleCastSelfCommand(const char* args
)
6136 Unit
* target
= getSelectedUnit();
6140 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
6141 SetSentErrorMessage(true);
6145 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6146 uint32 spell
= extractSpellIdFromLink((char*)args
);
6150 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
6154 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
6156 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
6157 SetSentErrorMessage(true);
6161 target
->CastSpell(target
,spell
,false);
6166 std::string
GetTimeString(uint32 time
)
6168 uint16 days
= time
/ DAY
, hours
= (time
% DAY
) / HOUR
, minute
= (time
% HOUR
) / MINUTE
;
6169 std::ostringstream ss
;
6170 if(days
) ss
<< days
<< "d ";
6171 if(hours
) ss
<< hours
<< "h ";
6172 ss
<< minute
<< "m";
6176 bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
6178 Player
* player
= getSelectedPlayer();
6179 if (!player
) player
= m_session
->GetPlayer();
6181 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
6183 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(i
);
6184 for(Player::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
6186 InstanceSave
*save
= itr
->second
.save
;
6187 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
6188 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());
6192 PSendSysMessage("player binds: %d", counter
);
6194 Group
*group
= player
->GetGroup();
6197 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
6199 Group::BoundInstancesMap
&binds
= group
->GetBoundInstances(i
);
6200 for(Group::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
6202 InstanceSave
*save
= itr
->second
.save
;
6203 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
6204 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());
6209 PSendSysMessage("group binds: %d", counter
);
6214 bool ChatHandler::HandleInstanceUnbindCommand(const char* args
)
6219 std::string cmd
= args
;
6222 Player
* player
= getSelectedPlayer();
6223 if (!player
) player
= m_session
->GetPlayer();
6225 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
6227 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(i
);
6228 for(Player::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end();)
6230 if(itr
->first
!= player
->GetMapId())
6232 InstanceSave
*save
= itr
->second
.save
;
6233 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
6234 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());
6235 player
->UnbindInstance(itr
, i
);
6242 PSendSysMessage("instances unbound: %d", counter
);
6247 bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
6249 PSendSysMessage("instances loaded: %d", MapManager::Instance().GetNumInstances());
6250 PSendSysMessage("players in instances: %d", MapManager::Instance().GetNumPlayersInInstances());
6251 PSendSysMessage("instance saves: %d", sInstanceSaveManager
.GetNumInstanceSaves());
6252 PSendSysMessage("players bound: %d", sInstanceSaveManager
.GetNumBoundPlayersTotal());
6253 PSendSysMessage("groups bound: %d", sInstanceSaveManager
.GetNumBoundGroupsTotal());
6257 bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
6259 Player
* pl
= m_session
->GetPlayer();
6261 Map
* map
= pl
->GetMap();
6262 if (!map
->IsDungeon())
6264 PSendSysMessage("Map is not a dungeon.");
6265 SetSentErrorMessage(true);
6269 if (!((InstanceMap
*)map
)->GetInstanceData())
6271 PSendSysMessage("Map has no instance data.");
6272 SetSentErrorMessage(true);
6276 ((InstanceMap
*)map
)->GetInstanceData()->SaveToDB();
6280 /// Display the list of GMs
6281 bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
6283 ///- Get the accounts with GM Level >0
6284 QueryResult
*result
= loginDatabase
.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
6287 SendSysMessage(LANG_GMLIST
);
6288 SendSysMessage("========================");
6289 SendSysMessage(LANG_GMLIST_HEADER
);
6290 SendSysMessage("========================");
6292 ///- Circle through them. Display username and GM level
6295 Field
*fields
= result
->Fetch();
6296 PSendSysMessage("|%15s|%6s|", fields
[0].GetString(),fields
[1].GetString());
6297 }while( result
->NextRow() );
6299 PSendSysMessage("========================");
6303 PSendSysMessage(LANG_GMLIST_EMPTY
);
6307 /// Define the 'Message of the day' for the realm
6308 bool ChatHandler::HandleServerSetMotdCommand(const char* args
)
6310 sWorld
.SetMotd(args
);
6311 PSendSysMessage(LANG_MOTD_NEW
, args
);
6315 /// Set/Unset the expansion level for an account
6316 bool ChatHandler::HandleAccountSetAddonCommand(const char* args
)
6318 ///- Get the command line arguments
6319 char *szAcc
= strtok((char*)args
," ");
6320 char *szExp
= strtok(NULL
," ");
6325 std::string account_name
;
6330 Player
* player
= getSelectedPlayer();
6334 account_id
= player
->GetSession()->GetAccountId();
6335 accmgr
.GetName(account_id
,account_name
);
6340 ///- Convert Account name to Upper Format
6341 account_name
= szAcc
;
6342 if(!AccountMgr::normilizeString(account_name
))
6344 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
6345 SetSentErrorMessage(true);
6349 account_id
= accmgr
.GetId(account_name
);
6352 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
6353 SetSentErrorMessage(true);
6359 // Let set addon state only for lesser (strong) security level
6360 // or to self account
6361 if (m_session
&& m_session
->GetAccountId () != account_id
&&
6362 HasLowerSecurityAccount (NULL
,account_id
,true))
6365 int lev
=atoi(szExp
); //get int anyway (0 if error)
6370 loginDatabase
.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev
,account_id
);
6371 PSendSysMessage(LANG_ACCOUNT_SETADDON
,account_name
.c_str(),account_id
,lev
);
6375 //Send items by mail
6376 bool ChatHandler::HandleSendItemsCommand(const char* args
)
6381 // format: name "subject text" "mail text" item1[:count1] item2[:count2] ... item12[:count12]
6383 std::string name
= extractPlayerNameFromLink((char*)args
);
6386 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6387 SetSentErrorMessage(true);
6391 char* tail1
= strtok(NULL
, "");
6397 msgSubject
= strtok(tail1
+1, "\"");
6400 char* space
= strtok(tail1
, "\"");
6403 msgSubject
= strtok(NULL
, "\"");
6409 char* tail2
= strtok(NULL
, "");
6415 msgText
= strtok(tail2
+1, "\"");
6418 char* space
= strtok(tail2
, "\"");
6421 msgText
= strtok(NULL
, "\"");
6427 // msgSubject, msgText isn't NUL after prev. check
6428 std::string subject
= msgSubject
;
6429 std::string text
= msgText
;
6432 typedef std::pair
<uint32
,uint32
> ItemPair
;
6433 typedef std::list
< ItemPair
> ItemPairs
;
6436 // get all tail string
6437 char* tail
= strtok(NULL
, "");
6439 // get from tail next item str
6440 while(char* itemStr
= strtok(tail
, " "))
6443 tail
= strtok(NULL
, "");
6446 char* itemIdStr
= strtok(itemStr
, ":");
6447 char* itemCountStr
= strtok(NULL
, " ");
6449 uint32 item_id
= atoi(itemIdStr
);
6453 ItemPrototype
const* item_proto
= objmgr
.GetItemPrototype(item_id
);
6456 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
6457 SetSentErrorMessage(true);
6461 uint32 item_count
= itemCountStr
? atoi(itemCountStr
) : 1;
6462 if(item_count
< 1 || item_proto
->MaxCount
> 0 && item_count
> uint32(item_proto
->MaxCount
))
6464 PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT
, item_count
,item_id
);
6465 SetSentErrorMessage(true);
6469 while(item_count
> item_proto
->GetMaxStackSize())
6471 items
.push_back(ItemPair(item_id
,item_proto
->GetMaxStackSize()));
6472 item_count
-= item_proto
->GetMaxStackSize();
6475 items
.push_back(ItemPair(item_id
,item_count
));
6477 if(items
.size() > MAX_MAIL_ITEMS
)
6479 PSendSysMessage(LANG_COMMAND_MAIL_ITEMS_LIMIT
, MAX_MAIL_ITEMS
);
6480 SetSentErrorMessage(true);
6485 uint64 receiver_guid
= objmgr
.GetPlayerGUIDByName(name
);
6488 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6489 SetSentErrorMessage(true);
6493 // from console show not existed sender
6494 uint32 sender_guidlo
= m_session
? m_session
->GetPlayer()->GetGUIDLow() : 0;
6496 uint32 messagetype
= MAIL_NORMAL
;
6497 uint32 stationery
= MAIL_STATIONERY_GM
;
6498 uint32 itemTextId
= !text
.empty() ? objmgr
.CreateItemText( text
) : 0;
6500 Player
*receiver
= objmgr
.GetPlayer(receiver_guid
);
6503 MailItemsInfo mi
; // item list preparing
6505 for(ItemPairs::const_iterator itr
= items
.begin(); itr
!= items
.end(); ++itr
)
6507 if(Item
* item
= Item::CreateItem(itr
->first
,itr
->second
,m_session
? m_session
->GetPlayer() : 0))
6509 item
->SaveToDB(); // save for prevent lost at next mail load, if send fail then item will deleted
6510 mi
.AddItem(item
->GetGUIDLow(), item
->GetEntry(), item
);
6514 WorldSession::SendMailTo(receiver
,messagetype
, stationery
, sender_guidlo
, GUID_LOPART(receiver_guid
), subject
, itemTextId
, &mi
, 0, 0, MAIL_CHECK_MASK_NONE
);
6516 std::string nameLink
= playerLink(name
);
6517 PSendSysMessage(LANG_MAIL_SENT
, nameLink
.c_str());
6521 ///Send money by mail
6522 bool ChatHandler::HandleSendMoneyCommand(const char* args
)
6527 /// format: name "subject text" "mail text" money
6529 std::string name
= extractPlayerNameFromLink((char*)args
);
6532 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6533 SetSentErrorMessage(true);
6537 char* tail1
= strtok(NULL
, "");
6543 msgSubject
= strtok(tail1
+1, "\"");
6546 char* space
= strtok(tail1
, "\"");
6549 msgSubject
= strtok(NULL
, "\"");
6555 char* tail2
= strtok(NULL
, "");
6561 msgText
= strtok(tail2
+1, "\"");
6564 char* space
= strtok(tail2
, "\"");
6567 msgText
= strtok(NULL
, "\"");
6573 char* money_str
= strtok(NULL
, "");
6574 int32 money
= money_str
? atoi(money_str
) : 0;
6578 // msgSubject, msgText isn't NUL after prev. check
6579 std::string subject
= msgSubject
;
6580 std::string text
= msgText
;
6582 uint64 receiver_guid
= objmgr
.GetPlayerGUIDByName(name
);
6585 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6586 SetSentErrorMessage(true);
6590 // from console show not existed sender
6591 uint32 sender_guidlo
= m_session
? m_session
->GetPlayer()->GetGUIDLow() : 0;
6593 uint32 messagetype
= MAIL_NORMAL
;
6594 uint32 stationery
= MAIL_STATIONERY_GM
;
6595 uint32 itemTextId
= !text
.empty() ? objmgr
.CreateItemText( text
) : 0;
6597 Player
*receiver
= objmgr
.GetPlayer(receiver_guid
);
6599 WorldSession::SendMailTo(receiver
,messagetype
, stationery
, sender_guidlo
, GUID_LOPART(receiver_guid
), subject
, itemTextId
, NULL
, money
, 0, MAIL_CHECK_MASK_NONE
);
6601 std::string nameLink
= playerLink(name
);
6602 PSendSysMessage(LANG_MAIL_SENT
, nameLink
.c_str());
6606 /// Send a message to a player in game
6607 bool ChatHandler::HandleSendMessageCommand(const char* args
)
6609 ///- Get the command line arguments
6610 std::string name
= extractPlayerNameFromLink((char*)args
);
6613 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6614 SetSentErrorMessage(true);
6618 char* msg_str
= strtok(NULL
, "");
6622 ///- Find the player and check that he is not logging out.
6623 Player
*rPlayer
= objmgr
.GetPlayer(name
.c_str());
6626 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6627 SetSentErrorMessage(true);
6631 if(rPlayer
->GetSession()->isLogingOut())
6633 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6634 SetSentErrorMessage(true);
6638 ///- Send the message
6639 //Use SendAreaTriggerMessage for fastest delivery.
6640 rPlayer
->GetSession()->SendAreaTriggerMessage("%s", msg_str
);
6641 rPlayer
->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
6643 //Confirmation message
6644 std::string nameLink
= playerLink(name
);
6645 PSendSysMessage(LANG_SENDMESSAGE
,nameLink
.c_str(),msg_str
);
6649 bool ChatHandler::HandleFlushArenaPointsCommand(const char * /*args*/)
6651 sBattleGroundMgr
.DistributeArenaPoints();
6655 bool ChatHandler::HandleModifyGenderCommand(const char *args
)
6660 Player
*player
= getSelectedPlayer();
6664 PSendSysMessage(LANG_NO_PLAYER
);
6665 SetSentErrorMessage(true);
6669 PlayerInfo
const* info
= objmgr
.GetPlayerInfo(player
->getRace(), player
->getClass());
6673 char const* gender_str
= (char*)args
;
6674 int gender_len
= strlen(gender_str
);
6678 if(!strncmp(gender_str
, "male", gender_len
)) // MALE
6680 if(player
->getGender() == GENDER_MALE
)
6683 gender
= GENDER_MALE
;
6685 else if (!strncmp(gender_str
, "female", gender_len
)) // FEMALE
6687 if(player
->getGender() == GENDER_FEMALE
)
6690 gender
= GENDER_FEMALE
;
6694 SendSysMessage(LANG_MUST_MALE_OR_FEMALE
);
6695 SetSentErrorMessage(true);
6700 player
->SetByteValue(UNIT_FIELD_BYTES_0
, 2, gender
);
6701 player
->SetByteValue(PLAYER_BYTES_3
, 0, gender
);
6703 // Change display ID
6704 player
->SetDisplayId(gender
? info
->displayId_f
: info
->displayId_m
);
6705 player
->SetNativeDisplayId(gender
? info
->displayId_f
: info
->displayId_m
);
6707 char const* gender_full
= gender
? "female" : "male";
6709 PSendSysMessage(LANG_YOU_CHANGE_GENDER
, GetNameLink(player
).c_str(), gender_full
);
6711 if (needReportToTarget(player
))
6712 ChatHandler(player
).PSendSysMessage(LANG_YOUR_GENDER_CHANGED
, gender_full
, GetNameLink().c_str());